ble_scanner.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ANDROID_INCLUDE_BLE_SCANNER_H
  17. #define ANDROID_INCLUDE_BLE_SCANNER_H
  18. #include <stdint.h>
  19. #include <vector>
  20. #include "bt_common_types.h"
  21. #include "bt_gatt_client.h"
  22. #include "bt_gatt_types.h"
  23. /** Callback invoked when batchscan reports are obtained */
  24. typedef void (*batchscan_reports_callback)(int client_if, int status,
  25. int report_format, int num_records,
  26. std::vector<uint8_t> data);
  27. /** Callback invoked when batchscan storage threshold limit is crossed */
  28. typedef void (*batchscan_threshold_callback)(int client_if);
  29. /** Track ADV VSE callback invoked when tracked device is found or lost */
  30. typedef void (*track_adv_event_callback)(
  31. btgatt_track_adv_info_t* p_track_adv_info);
  32. /** Callback for scan results */
  33. typedef void (*scan_result_callback)(uint16_t event_type, uint8_t addr_type,
  34. RawAddress* bda, uint8_t primary_phy,
  35. uint8_t secondary_phy,
  36. uint8_t advertising_sid, int8_t tx_power,
  37. int8_t rssi, uint16_t periodic_adv_int,
  38. std::vector<uint8_t> adv_data);
  39. typedef struct {
  40. scan_result_callback scan_result_cb;
  41. batchscan_reports_callback batchscan_reports_cb;
  42. batchscan_threshold_callback batchscan_threshold_cb;
  43. track_adv_event_callback track_adv_event_cb;
  44. } btgatt_scanner_callbacks_t;
  45. class BleScannerInterface {
  46. public:
  47. virtual ~BleScannerInterface() = default;
  48. using RegisterCallback =
  49. base::Callback<void(uint8_t /* scanner_id */, uint8_t /* status */)>;
  50. using Callback = base::Callback<void(uint8_t /* status */)>;
  51. using EnableCallback =
  52. base::Callback<void(uint8_t /* action */, uint8_t /* status */)>;
  53. using FilterParamSetupCallback =
  54. base::Callback<void(uint8_t /* avbl_space */, uint8_t /* action_type */,
  55. uint8_t /* status */)>;
  56. using FilterConfigCallback =
  57. base::Callback<void(uint8_t /* filt_type */, uint8_t /* avbl_space */,
  58. uint8_t /* action */, uint8_t /* status */)>;
  59. /** Registers a scanner with the stack */
  60. virtual void RegisterScanner(RegisterCallback) = 0;
  61. /** Unregister a scanner from the stack */
  62. virtual void Unregister(int scanner_id) = 0;
  63. /** Start or stop LE device scanning */
  64. virtual void Scan(bool start) = 0;
  65. /** Setup scan filter params */
  66. virtual void ScanFilterParamSetup(
  67. uint8_t client_if, uint8_t action, uint8_t filt_index,
  68. std::unique_ptr<btgatt_filt_param_setup_t> filt_param,
  69. FilterParamSetupCallback cb) = 0;
  70. /** Configure a scan filter condition */
  71. virtual void ScanFilterAdd(int filter_index, std::vector<ApcfCommand> filters,
  72. FilterConfigCallback cb) = 0;
  73. /** Clear all scan filter conditions for specific filter index*/
  74. virtual void ScanFilterClear(int filt_index, FilterConfigCallback cb) = 0;
  75. /** Enable / disable scan filter feature*/
  76. virtual void ScanFilterEnable(bool enable, EnableCallback cb) = 0;
  77. /** Sets the LE scan interval and window in units of N*0.625 msec */
  78. virtual void SetScanParameters(int scan_interval, int scan_window,
  79. Callback cb) = 0;
  80. /* Configure the batchscan storage */
  81. virtual void BatchscanConfigStorage(int client_if, int batch_scan_full_max,
  82. int batch_scan_trunc_max,
  83. int batch_scan_notify_threshold,
  84. Callback cb) = 0;
  85. /* Enable batchscan */
  86. virtual void BatchscanEnable(int scan_mode, int scan_interval,
  87. int scan_window, int addr_type, int discard_rule,
  88. Callback cb) = 0;
  89. /* Disable batchscan */
  90. virtual void BatchscanDisable(Callback cb) = 0;
  91. /* Read out batchscan reports */
  92. virtual void BatchscanReadReports(int client_if, int scan_mode) = 0;
  93. using StartSyncCb =
  94. base::Callback<void(uint8_t status, uint16_t sync_handle,
  95. uint8_t advertising_sid, uint8_t address_type,
  96. RawAddress address, uint8_t phy, uint16_t interval)>;
  97. using SyncReportCb =
  98. base::Callback<void(uint16_t sync_handle, int8_t tx_power, int8_t rssi,
  99. uint8_t status, std::vector<uint8_t> data)>;
  100. using SyncLostCb = base::Callback<void(uint16_t sync_handle)>;
  101. virtual void StartSync(uint8_t sid, RawAddress address, uint16_t skip,
  102. uint16_t timeout, StartSyncCb start_cb,
  103. SyncReportCb report_cb, SyncLostCb lost_cb) = 0;
  104. virtual void StopSync(uint16_t handle) = 0;
  105. };
  106. #endif /* ANDROID_INCLUDE_BLE_SCANNER_H */