blob: 5284800c8f5520dcf3126ca330c4e7e8cd32713f [file] [log] [blame]
Jakub Pawlowski6ecdb8c2016-07-13 11:53:55 -07001/*
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 Pawlowski6ecdb8c2016-07-13 11:53:55 -070017#ifndef ANDROID_INCLUDE_BLE_ADVERTISER_H
18#define ANDROID_INCLUDE_BLE_ADVERTISER_H
19
Jakub Pawlowski4a635282016-10-06 16:53:23 -070020#include <base/callback_forward.h>
Jakub Pawlowski6ecdb8c2016-07-13 11:53:55 -070021#include <stdint.h>
22#include <vector>
Jakub Pawlowski6ecdb8c2016-07-13 11:53:55 -070023#include "bt_common_types.h"
Jakub Pawlowski4a635282016-10-06 16:53:23 -070024#include "bt_gatt_types.h"
Jakub Pawlowski6ecdb8c2016-07-13 11:53:55 -070025
Jakub Pawlowskia90ebea2016-11-17 13:26:53 -080026struct AdvertiseParameters {
Jakub Pawlowski97902982016-12-05 11:49:52 -080027 uint16_t advertising_event_properties;
28 uint32_t min_interval;
29 uint32_t max_interval;
Jakub Pawlowskia90ebea2016-11-17 13:26:53 -080030 uint8_t channel_map;
Jakub Pawlowski97902982016-12-05 11:49:52 -080031 int8_t tx_power;
32 uint8_t primary_advertising_phy;
33 uint8_t secondary_advertising_phy;
34 uint8_t scan_request_notification_enable;
Jakub Pawlowskia90ebea2016-11-17 13:26:53 -080035};
36
Jakub Pawlowski0d0b7d12017-03-13 11:13:51 -070037struct PeriodicAdvertisingParameters {
38 uint8_t enable;
39 uint16_t min_interval;
40 uint16_t max_interval;
41 uint16_t periodic_advertising_properties;
42};
43
Jakub Pawlowski4a635282016-10-06 16:53:23 -070044class BleAdvertiserInterface {
45 public:
46 virtual ~BleAdvertiserInterface() = default;
Jakub Pawlowski6ecdb8c2016-07-13 11:53:55 -070047
Jakub Pawlowski555b8ae2016-11-04 12:05:37 -070048 /** Callback invoked when multi-adv operation has completed */
Jakub Pawlowski0d0b7d12017-03-13 11:13:51 -070049 using StatusCallback = base::Callback<void(uint8_t /* status */)>;
50 using IdStatusCallback =
51 base::Callback<void(uint8_t /* advertiser_id */, uint8_t /* status */)>;
Jakub Pawlowskia4bd8a62017-03-17 18:06:55 -070052 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 Pawlowski555b8ae2016-11-04 12:05:37 -070056
Jakub Pawlowski4a635282016-10-06 16:53:23 -070057 /** Registers an advertiser with the stack */
Jakub Pawlowski0d0b7d12017-03-13 11:13:51 -070058 virtual void RegisterAdvertiser(IdStatusCallback) = 0;
Jakub Pawlowskif82a2492016-10-31 11:14:05 -070059
Jakub Pawlowski5a852002017-06-24 17:33:20 -070060 using GetAddressCallback = base::Callback<void(uint8_t /* address_type*/, RawAddress /*address*/)>;
Jakub Pawlowski788847a2017-04-19 07:03:14 -070061 virtual void GetOwnAddress(uint8_t advertiser_id, GetAddressCallback cb) = 0;
62
Jakub Pawlowski4a635282016-10-06 16:53:23 -070063 /* Set the parameters as per spec, user manual specified values */
Jakub Pawlowskia4bd8a62017-03-17 18:06:55 -070064 virtual void SetParameters(uint8_t advertiser_id, AdvertiseParameters params,
65 ParametersCallback cb) = 0;
Jakub Pawlowski6ecdb8c2016-07-13 11:53:55 -070066
Jakub Pawlowski555b8ae2016-11-04 12:05:37 -070067 /* Setup the data */
68 virtual void SetData(int advertiser_id, bool set_scan_rsp,
Jakub Pawlowski0d0b7d12017-03-13 11:13:51 -070069 std::vector<uint8_t> data, StatusCallback cb) = 0;
Jakub Pawlowski6ecdb8c2016-07-13 11:53:55 -070070
Jakub Pawlowski555b8ae2016-11-04 12:05:37 -070071 /* Enable the advertising instance */
Jakub Pawlowski0d0b7d12017-03-13 11:13:51 -070072 virtual void Enable(uint8_t advertiser_id, bool enable, StatusCallback cb,
Jakub Pawlowskidd3e64f2017-03-30 20:51:00 -070073 uint16_t duration, uint8_t maxExtAdvEvents,
74 StatusCallback timeout_cb) = 0;
Jakub Pawlowski555b8ae2016-11-04 12:05:37 -070075
76 /* Unregisters an advertiser */
77 virtual void Unregister(uint8_t advertiser_id) = 0;
Jakub Pawlowskia90ebea2016-11-17 13:26:53 -080078
Jakub Pawlowski0d0b7d12017-03-13 11:13:51 -070079 virtual void StartAdvertising(uint8_t advertiser_id, StatusCallback cb,
Jakub Pawlowskia90ebea2016-11-17 13:26:53 -080080 AdvertiseParameters params,
81 std::vector<uint8_t> advertise_data,
82 std::vector<uint8_t> scan_response_data,
Jakub Pawlowski0d0b7d12017-03-13 11:13:51 -070083 int timeout_s, StatusCallback timeout_cb) = 0;
84
85 /** Start the advertising set. This include registering, setting all
86 * parameters and data, and enabling it. |register_cb| is called when the set
87 * is advertising. |timeout_cb| is called when the timeout_s have passed */
88 virtual void StartAdvertisingSet(
Jakub Pawlowskia4bd8a62017-03-17 18:06:55 -070089 IdTxPowerStatusCallback register_cb, AdvertiseParameters params,
Jakub Pawlowski0d0b7d12017-03-13 11:13:51 -070090 std::vector<uint8_t> advertise_data,
91 std::vector<uint8_t> scan_response_data,
92 PeriodicAdvertisingParameters periodic_params,
Jakub Pawlowskidd3e64f2017-03-30 20:51:00 -070093 std::vector<uint8_t> periodic_data, uint16_t duration,
94 uint8_t maxExtAdvEvents, IdStatusCallback timeout_cb) = 0;
Jakub Pawlowskia4bd8a62017-03-17 18:06:55 -070095
96 virtual void SetPeriodicAdvertisingParameters(
97 int advertiser_id, PeriodicAdvertisingParameters parameters,
98 StatusCallback cb) = 0;
99
100 virtual void SetPeriodicAdvertisingData(int advertiser_id,
101 std::vector<uint8_t> data,
102 StatusCallback cb) = 0;
103
104 virtual void SetPeriodicAdvertisingEnable(int advertiser_id, bool enable,
105 StatusCallback cb) = 0;
Jakub Pawlowski4a635282016-10-06 16:53:23 -0700106};
Jakub Pawlowski6ecdb8c2016-07-13 11:53:55 -0700107
108#endif /* ANDROID_INCLUDE_BLE_ADVERTISER_H */