Jakub Pawlowski | 6ecdb8c | 2016-07-13 11:53:55 -0700 | [diff] [blame] | 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 | |
Jakub Pawlowski | 6ecdb8c | 2016-07-13 11:53:55 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_INCLUDE_BLE_ADVERTISER_H |
| 18 | #define ANDROID_INCLUDE_BLE_ADVERTISER_H |
| 19 | |
Jakub Pawlowski | 4a63528 | 2016-10-06 16:53:23 -0700 | [diff] [blame] | 20 | #include <base/callback_forward.h> |
Jakub Pawlowski | 6ecdb8c | 2016-07-13 11:53:55 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | #include <vector> |
Jakub Pawlowski | 6ecdb8c | 2016-07-13 11:53:55 -0700 | [diff] [blame] | 23 | #include "bt_common_types.h" |
Jakub Pawlowski | 4a63528 | 2016-10-06 16:53:23 -0700 | [diff] [blame] | 24 | #include "bt_gatt_types.h" |
Jakub Pawlowski | 6ecdb8c | 2016-07-13 11:53:55 -0700 | [diff] [blame] | 25 | |
Jakub Pawlowski | a90ebea | 2016-11-17 13:26:53 -0800 | [diff] [blame] | 26 | struct AdvertiseParameters { |
Jakub Pawlowski | 9790298 | 2016-12-05 11:49:52 -0800 | [diff] [blame] | 27 | uint16_t advertising_event_properties; |
| 28 | uint32_t min_interval; |
| 29 | uint32_t max_interval; |
Jakub Pawlowski | a90ebea | 2016-11-17 13:26:53 -0800 | [diff] [blame] | 30 | uint8_t channel_map; |
Jakub Pawlowski | 9790298 | 2016-12-05 11:49:52 -0800 | [diff] [blame] | 31 | int8_t tx_power; |
| 32 | uint8_t primary_advertising_phy; |
| 33 | uint8_t secondary_advertising_phy; |
| 34 | uint8_t scan_request_notification_enable; |
Jakub Pawlowski | a90ebea | 2016-11-17 13:26:53 -0800 | [diff] [blame] | 35 | }; |
| 36 | |
Jakub Pawlowski | 0d0b7d1 | 2017-03-13 11:13:51 -0700 | [diff] [blame] | 37 | struct PeriodicAdvertisingParameters { |
| 38 | uint8_t enable; |
| 39 | uint16_t min_interval; |
| 40 | uint16_t max_interval; |
| 41 | uint16_t periodic_advertising_properties; |
| 42 | }; |
| 43 | |
Jakub Pawlowski | 4a63528 | 2016-10-06 16:53:23 -0700 | [diff] [blame] | 44 | class BleAdvertiserInterface { |
| 45 | public: |
| 46 | virtual ~BleAdvertiserInterface() = default; |
Jakub Pawlowski | 6ecdb8c | 2016-07-13 11:53:55 -0700 | [diff] [blame] | 47 | |
Jakub Pawlowski | 555b8ae | 2016-11-04 12:05:37 -0700 | [diff] [blame] | 48 | /** Callback invoked when multi-adv operation has completed */ |
Jakub Pawlowski | 0d0b7d1 | 2017-03-13 11:13:51 -0700 | [diff] [blame] | 49 | using StatusCallback = base::Callback<void(uint8_t /* status */)>; |
| 50 | using IdStatusCallback = |
| 51 | base::Callback<void(uint8_t /* advertiser_id */, uint8_t /* status */)>; |
Jakub Pawlowski | a4bd8a6 | 2017-03-17 18:06:55 -0700 | [diff] [blame^] | 52 | using IdTxPowerStatusCallback = |
| 53 | base::Callback<void(uint8_t /* advertiser_id */, int8_t /* tx_power */, uint8_t /* status */)>; |
| 54 | using ParametersCallback = |
| 55 | base::Callback<void(uint8_t /* status */, int8_t /* tx_power */)>; |
Jakub Pawlowski | 555b8ae | 2016-11-04 12:05:37 -0700 | [diff] [blame] | 56 | |
Jakub Pawlowski | 4a63528 | 2016-10-06 16:53:23 -0700 | [diff] [blame] | 57 | /** Registers an advertiser with the stack */ |
Jakub Pawlowski | 0d0b7d1 | 2017-03-13 11:13:51 -0700 | [diff] [blame] | 58 | virtual void RegisterAdvertiser(IdStatusCallback) = 0; |
Jakub Pawlowski | f82a249 | 2016-10-31 11:14:05 -0700 | [diff] [blame] | 59 | |
Jakub Pawlowski | 4a63528 | 2016-10-06 16:53:23 -0700 | [diff] [blame] | 60 | /* Set the parameters as per spec, user manual specified values */ |
Jakub Pawlowski | a4bd8a6 | 2017-03-17 18:06:55 -0700 | [diff] [blame^] | 61 | virtual void SetParameters(uint8_t advertiser_id, AdvertiseParameters params, |
| 62 | ParametersCallback cb) = 0; |
Jakub Pawlowski | 6ecdb8c | 2016-07-13 11:53:55 -0700 | [diff] [blame] | 63 | |
Jakub Pawlowski | 555b8ae | 2016-11-04 12:05:37 -0700 | [diff] [blame] | 64 | /* Setup the data */ |
| 65 | virtual void SetData(int advertiser_id, bool set_scan_rsp, |
Jakub Pawlowski | 0d0b7d1 | 2017-03-13 11:13:51 -0700 | [diff] [blame] | 66 | std::vector<uint8_t> data, StatusCallback cb) = 0; |
Jakub Pawlowski | 6ecdb8c | 2016-07-13 11:53:55 -0700 | [diff] [blame] | 67 | |
Jakub Pawlowski | 555b8ae | 2016-11-04 12:05:37 -0700 | [diff] [blame] | 68 | /* Enable the advertising instance */ |
Jakub Pawlowski | 0d0b7d1 | 2017-03-13 11:13:51 -0700 | [diff] [blame] | 69 | virtual void Enable(uint8_t advertiser_id, bool enable, StatusCallback cb, |
| 70 | int timeout_s, StatusCallback timeout_cb) = 0; |
Jakub Pawlowski | 555b8ae | 2016-11-04 12:05:37 -0700 | [diff] [blame] | 71 | |
| 72 | /* Unregisters an advertiser */ |
| 73 | virtual void Unregister(uint8_t advertiser_id) = 0; |
Jakub Pawlowski | a90ebea | 2016-11-17 13:26:53 -0800 | [diff] [blame] | 74 | |
Jakub Pawlowski | 0d0b7d1 | 2017-03-13 11:13:51 -0700 | [diff] [blame] | 75 | virtual void StartAdvertising(uint8_t advertiser_id, StatusCallback cb, |
Jakub Pawlowski | a90ebea | 2016-11-17 13:26:53 -0800 | [diff] [blame] | 76 | AdvertiseParameters params, |
| 77 | std::vector<uint8_t> advertise_data, |
| 78 | std::vector<uint8_t> scan_response_data, |
Jakub Pawlowski | 0d0b7d1 | 2017-03-13 11:13:51 -0700 | [diff] [blame] | 79 | int timeout_s, StatusCallback timeout_cb) = 0; |
| 80 | |
| 81 | /** Start the advertising set. This include registering, setting all |
| 82 | * parameters and data, and enabling it. |register_cb| is called when the set |
| 83 | * is advertising. |timeout_cb| is called when the timeout_s have passed */ |
| 84 | virtual void StartAdvertisingSet( |
Jakub Pawlowski | a4bd8a6 | 2017-03-17 18:06:55 -0700 | [diff] [blame^] | 85 | IdTxPowerStatusCallback register_cb, AdvertiseParameters params, |
Jakub Pawlowski | 0d0b7d1 | 2017-03-13 11:13:51 -0700 | [diff] [blame] | 86 | std::vector<uint8_t> advertise_data, |
| 87 | std::vector<uint8_t> scan_response_data, |
| 88 | PeriodicAdvertisingParameters periodic_params, |
| 89 | std::vector<uint8_t> periodic_data, int timeout_s, |
| 90 | IdStatusCallback timeout_cb) = 0; |
Jakub Pawlowski | a4bd8a6 | 2017-03-17 18:06:55 -0700 | [diff] [blame^] | 91 | |
| 92 | virtual void SetPeriodicAdvertisingParameters( |
| 93 | int advertiser_id, PeriodicAdvertisingParameters parameters, |
| 94 | StatusCallback cb) = 0; |
| 95 | |
| 96 | virtual void SetPeriodicAdvertisingData(int advertiser_id, |
| 97 | std::vector<uint8_t> data, |
| 98 | StatusCallback cb) = 0; |
| 99 | |
| 100 | virtual void SetPeriodicAdvertisingEnable(int advertiser_id, bool enable, |
| 101 | StatusCallback cb) = 0; |
Jakub Pawlowski | 4a63528 | 2016-10-06 16:53:23 -0700 | [diff] [blame] | 102 | }; |
Jakub Pawlowski | 6ecdb8c | 2016-07-13 11:53:55 -0700 | [diff] [blame] | 103 | |
| 104 | #endif /* ANDROID_INCLUDE_BLE_ADVERTISER_H */ |