• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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 #pragma once
17 
18 #include <memory>
19 
20 #include "common/callback.h"
21 #include "hci/address_with_type.h"
22 #include "hci/hci_packets.h"
23 #include "hci/uuid.h"
24 
25 namespace bluetooth {
26 namespace hci {
27 
28 using ScannerId = uint8_t;
29 
30 class AdvertisingFilterOnFoundOnLostInfo {
31  public:
32   uint8_t scanner_id;
33   uint8_t filter_index;
34   uint8_t advertiser_state;
35   AdvtInfoPresent advertiser_info_present;
36   Address advertiser_address;
37   uint8_t advertiser_address_type;
38   uint8_t tx_power;
39   int8_t rssi;
40   uint16_t time_stamp;
41   std::vector<uint8_t> adv_packet;
42   std::vector<uint8_t> scan_response;
43 };
44 
45 class ScanningCallback {
46  public:
47   enum ScanningStatus {
48     SUCCESS,
49     NO_RESOURCES = 0x80,
50     INTERNAL_ERROR = 0x85,
51     ILLEGAL_PARAMETER = 0x87,
52   };
53 
54   virtual ~ScanningCallback() = default;
55   virtual void OnScannerRegistered(
56       const bluetooth::hci::Uuid app_uuid, ScannerId scanner_id, ScanningStatus status) = 0;
57   virtual void OnSetScannerParameterComplete(ScannerId scanner_id, ScanningStatus status) = 0;
58   virtual void OnScanResult(
59       uint16_t event_type,
60       uint8_t address_type,
61       Address address,
62       uint8_t primary_phy,
63       uint8_t secondary_phy,
64       uint8_t advertising_sid,
65       int8_t tx_power,
66       int8_t rssi,
67       uint16_t periodic_advertising_interval,
68       std::vector<uint8_t> advertising_data) = 0;
69   virtual void OnTrackAdvFoundLost(AdvertisingFilterOnFoundOnLostInfo on_found_on_lost_info) = 0;
70   virtual void OnBatchScanReports(
71       int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data) = 0;
72   virtual void OnBatchScanThresholdCrossed(int client_if) = 0;
73   virtual void OnTimeout() = 0;
74   virtual void OnFilterEnable(Enable enable, uint8_t status) = 0;
75   virtual void OnFilterParamSetup(uint8_t available_spaces, ApcfAction action, uint8_t status) = 0;
76   virtual void OnFilterConfigCallback(
77       ApcfFilterType filter_type, uint8_t available_spaces, ApcfAction action, uint8_t status) = 0;
78   virtual void OnPeriodicSyncStarted(
79       int request_id,
80       uint8_t status,
81       uint16_t sync_handle,
82       uint8_t advertising_sid,
83       AddressWithType address_with_type,
84       uint8_t phy,
85       uint16_t interval) = 0;
86   virtual void OnPeriodicSyncReport(
87       uint16_t sync_handle, int8_t tx_power, int8_t rssi, uint8_t status, std::vector<uint8_t> data) = 0;
88   virtual void OnPeriodicSyncLost(uint16_t sync_handle) = 0;
89   virtual void OnPeriodicSyncTransferred(int pa_source, uint8_t status, Address address) = 0;
90 };
91 
92 class AdvertisingPacketContentFilterCommand {
93  public:
94   ApcfFilterType filter_type;
95   Address address;
96   ApcfApplicationAddressType application_address_type;
97   Uuid uuid;
98   Uuid uuid_mask;
99   std::vector<uint8_t> name;
100   uint16_t company;
101   uint16_t company_mask;
102   uint8_t ad_type;
103   std::vector<uint8_t> data;
104   std::vector<uint8_t> data_mask;
105   std::array<uint8_t, 16> irk;
106 };
107 
108 class AdvertisingFilterParameter {
109  public:
110   uint16_t feature_selection;
111   uint16_t list_logic_type;
112   uint8_t filter_logic_type;
113   uint8_t rssi_high_thresh;
114   DeliveryMode delivery_mode;
115   uint16_t onfound_timeout;
116   uint8_t onfound_timeout_cnt;
117   uint8_t rssi_low_thresh;
118   uint16_t onlost_timeout;
119   uint16_t num_of_tracking_entries;
120 };
121 
122 }  // namespace hci
123 }  // namespace bluetooth
124