• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2016 The Android Open Source Project
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef BLE_ADVERTISER_HCI_INTERFACE_H
20 #define BLE_ADVERTISER_HCI_INTERFACE_H
21 
22 #include <base/callback.h>
23 
24 #include <vector>
25 
26 #include "stack/include/bt_types.h"
27 #include "types/raw_address.h"
28 
29 /* This class is an abstraction of HCI commands used for managing
30  * advertisements. Please see VSC HCI SPEC at
31  * https://static.googleusercontent.com/media/source.android.com/en//devices/Android-6.0-Bluetooth-HCI-Reqs.pdf
32  * and Bluetooth 5.0 "Advertising Extension" feature for more details  */
33 class BleAdvertiserHciInterface {
34  public:
35   using status_cb = base::Callback<void(uint8_t /* status */)>;
36   using parameters_cb =
37       base::Callback<void(uint8_t /* status */, int8_t /* tx_power */)>;
38 
39   static void Initialize();
40   static BleAdvertiserHciInterface* Get();
41   static void CleanUp();
42 
43   virtual ~BleAdvertiserHciInterface() = default;
44 
45   class AdvertisingEventObserver {
46    public:
47     virtual ~AdvertisingEventObserver() = default;
48     virtual void OnAdvertisingSetTerminated(
49         uint8_t status, uint8_t advertising_handle, uint16_t connection_handle,
50         uint8_t num_completed_extended_adv_events) = 0;
51   };
52 
53   virtual void SetAdvertisingEventObserver(
54       AdvertisingEventObserver* observer) = 0;
55   virtual void ReadInstanceCount(
56       base::Callback<void(uint8_t /* inst_cnt*/)> cb) = 0;
57   virtual void SetParameters(
58       uint8_t handle, uint16_t properties, uint32_t adv_int_min,
59       uint32_t adv_int_max, uint8_t channel_map, uint8_t own_address_type,
60       const RawAddress& own_address, uint8_t peer_address_type,
61       const RawAddress& peer_address, uint8_t filter_policy, int8_t tx_power,
62       uint8_t primary_phy, uint8_t secondary_max_skip, uint8_t secondary_phy,
63       uint8_t advertising_sid, uint8_t scan_request_notify_enable,
64       parameters_cb command_complete) = 0;
65   virtual void SetAdvertisingData(uint8_t handle, uint8_t operation,
66                                   uint8_t fragment_preference,
67                                   uint8_t data_length, uint8_t* data,
68                                   status_cb command_complete) = 0;
69   virtual void SetScanResponseData(uint8_t handle, uint8_t operation,
70                                    uint8_t fragment_preference,
71                                    uint8_t scan_response_data_length,
72                                    uint8_t* scan_response_data,
73                                    status_cb command_complete) = 0;
74   virtual void SetRandomAddress(uint8_t handle,
75                                 const RawAddress& random_address,
76                                 status_cb command_complete) = 0;
77 
78   struct SetEnableData {
79     uint8_t handle;
80     uint16_t duration;
81     uint8_t max_extended_advertising_events;
82   };
83   virtual void Enable(uint8_t enable, std::vector<SetEnableData> sets,
84                       status_cb command_complete) = 0;
85 
Enable(uint8_t enable,uint8_t handle,uint16_t duration,uint8_t max_extended_advertising_events,status_cb command_complete)86   void Enable(uint8_t enable, uint8_t handle, uint16_t duration,
87               uint8_t max_extended_advertising_events,
88               status_cb command_complete) {
89     std::vector<SetEnableData> enableData;
90     enableData.emplace_back(SetEnableData{
91         .handle = handle,
92         .duration = duration,
93         .max_extended_advertising_events = max_extended_advertising_events});
94     Enable(enable, enableData, command_complete);
95   };
96   virtual void SetPeriodicAdvertisingParameters(uint8_t handle,
97                                                 uint16_t periodic_adv_int_min,
98                                                 uint16_t periodic_adv_int_max,
99                                                 uint16_t periodic_properties,
100                                                 status_cb command_complete) = 0;
101   virtual void SetPeriodicAdvertisingData(uint8_t handle, uint8_t operation,
102                                           uint8_t adv_data_length,
103                                           uint8_t* adv_data,
104                                           status_cb command_complete) = 0;
105   virtual void SetPeriodicAdvertisingEnable(uint8_t enable, uint8_t handle,
106                                             status_cb command_complete) = 0;
107   virtual void RemoveAdvertisingSet(uint8_t handle,
108                                     status_cb command_complete) = 0;
109 
110   // Some implementation don't behave well when handle value 0 is used.
QuirkAdvertiserZeroHandle()111   virtual bool QuirkAdvertiserZeroHandle() { return 0; }
112 };
113 
114 #endif  // BLE_ADVERTISER_HCI_INTERFACE_H
115