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 17 #ifndef ANDROID_INCLUDE_BLE_ADVERTISER_H 18 #define ANDROID_INCLUDE_BLE_ADVERTISER_H 19 20 #include <base/callback_forward.h> 21 #include <stdint.h> 22 #include <vector> 23 #include "bt_common_types.h" 24 #include "bt_gatt_types.h" 25 26 struct AdvertiseParameters { 27 uint16_t advertising_event_properties; 28 uint32_t min_interval; 29 uint32_t max_interval; 30 uint8_t channel_map; 31 int8_t tx_power; 32 uint8_t primary_advertising_phy; 33 uint8_t secondary_advertising_phy; 34 uint8_t scan_request_notification_enable; 35 }; 36 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 44 class BleAdvertiserInterface { 45 public: 46 virtual ~BleAdvertiserInterface() = default; 47 48 /** Callback invoked when multi-adv operation has completed */ 49 using StatusCallback = base::Callback<void(uint8_t /* status */)>; 50 using IdStatusCallback = 51 base::Callback<void(uint8_t /* advertiser_id */, uint8_t /* status */)>; 52 using IdTxPowerStatusCallback = 53 base::Callback<void(uint8_t /* advertiser_id */, int8_t /* tx_power */, 54 uint8_t /* status */)>; 55 using ParametersCallback = 56 base::Callback<void(uint8_t /* status */, int8_t /* tx_power */)>; 57 58 /** Registers an advertiser with the stack */ 59 virtual void RegisterAdvertiser(IdStatusCallback) = 0; 60 61 using GetAddressCallback = 62 base::Callback<void(uint8_t /* address_type*/, RawAddress /*address*/)>; 63 virtual void GetOwnAddress(uint8_t advertiser_id, GetAddressCallback cb) = 0; 64 65 /* Set the parameters as per spec, user manual specified values */ 66 virtual void SetParameters(uint8_t advertiser_id, AdvertiseParameters params, 67 ParametersCallback cb) = 0; 68 69 /* Setup the data */ 70 virtual void SetData(int advertiser_id, bool set_scan_rsp, 71 std::vector<uint8_t> data, StatusCallback cb) = 0; 72 73 /* Enable the advertising instance */ 74 virtual void Enable(uint8_t advertiser_id, bool enable, StatusCallback cb, 75 uint16_t duration, uint8_t maxExtAdvEvents, 76 StatusCallback timeout_cb) = 0; 77 78 /* Unregisters an advertiser */ 79 virtual void Unregister(uint8_t advertiser_id) = 0; 80 81 virtual void StartAdvertising(uint8_t advertiser_id, StatusCallback cb, 82 AdvertiseParameters params, 83 std::vector<uint8_t> advertise_data, 84 std::vector<uint8_t> scan_response_data, 85 int timeout_s, StatusCallback timeout_cb) = 0; 86 87 /** Start the advertising set. This include registering, setting all 88 * parameters and data, and enabling it. |register_cb| is called when the set 89 * is advertising. |timeout_cb| is called when the timeout_s have passed */ 90 virtual void StartAdvertisingSet( 91 IdTxPowerStatusCallback register_cb, AdvertiseParameters params, 92 std::vector<uint8_t> advertise_data, 93 std::vector<uint8_t> scan_response_data, 94 PeriodicAdvertisingParameters periodic_params, 95 std::vector<uint8_t> periodic_data, uint16_t duration, 96 uint8_t maxExtAdvEvents, IdStatusCallback timeout_cb) = 0; 97 98 virtual void SetPeriodicAdvertisingParameters( 99 int advertiser_id, PeriodicAdvertisingParameters parameters, 100 StatusCallback cb) = 0; 101 102 virtual void SetPeriodicAdvertisingData(int advertiser_id, 103 std::vector<uint8_t> data, 104 StatusCallback cb) = 0; 105 106 virtual void SetPeriodicAdvertisingEnable(int advertiser_id, bool enable, 107 StatusCallback cb) = 0; 108 }; 109 110 #endif /* ANDROID_INCLUDE_BLE_ADVERTISER_H */ 111