• 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   // For MSFT-based advertisement events, the monitor handle associates every event with the monitor
33   // filter this event comes from.
34   uint8_t monitor_handle;
35   uint8_t scanner_id;
36   uint8_t filter_index;
37   uint8_t advertiser_state;
38   AdvtInfoPresent advertiser_info_present;
39   Address advertiser_address;
40   uint8_t advertiser_address_type;
41   uint8_t tx_power;
42   int8_t rssi;
43   uint16_t time_stamp;
44   std::vector<uint8_t> adv_packet;
45   std::vector<uint8_t> scan_response;
46 };
47 
48 class ScanningCallback {
49  public:
50   enum ScanningStatus {
51     SUCCESS,
52     NO_RESOURCES = 0x80,
53     INTERNAL_ERROR = 0x85,
54     ILLEGAL_PARAMETER = 0x87,
55   };
56 
57   virtual ~ScanningCallback() = default;
58   virtual void OnScannerRegistered(
59       const bluetooth::hci::Uuid app_uuid, ScannerId scanner_id, ScanningStatus status) = 0;
60   virtual void OnSetScannerParameterComplete(ScannerId scanner_id, ScanningStatus status) = 0;
61   virtual void OnScanResult(
62       uint16_t event_type,
63       uint8_t address_type,
64       Address address,
65       uint8_t primary_phy,
66       uint8_t secondary_phy,
67       uint8_t advertising_sid,
68       int8_t tx_power,
69       int8_t rssi,
70       uint16_t periodic_advertising_interval,
71       std::vector<uint8_t> advertising_data) = 0;
72   virtual void OnTrackAdvFoundLost(AdvertisingFilterOnFoundOnLostInfo on_found_on_lost_info) = 0;
73   virtual void OnBatchScanReports(
74       int client_if, int status, int report_format, int num_records, std::vector<uint8_t> data) = 0;
75   virtual void OnBatchScanThresholdCrossed(int client_if) = 0;
76   virtual void OnTimeout() = 0;
77   virtual void OnFilterEnable(Enable enable, uint8_t status) = 0;
78   virtual void OnFilterParamSetup(uint8_t available_spaces, ApcfAction action, uint8_t status) = 0;
79   virtual void OnFilterConfigCallback(
80       ApcfFilterType filter_type, uint8_t available_spaces, ApcfAction action, uint8_t status) = 0;
81   virtual void OnPeriodicSyncStarted(
82       int request_id,
83       uint8_t status,
84       uint16_t sync_handle,
85       uint8_t advertising_sid,
86       AddressWithType address_with_type,
87       uint8_t phy,
88       uint16_t interval) = 0;
89   virtual void OnPeriodicSyncReport(
90       uint16_t sync_handle, int8_t tx_power, int8_t rssi, uint8_t status, std::vector<uint8_t> data) = 0;
91   virtual void OnPeriodicSyncLost(uint16_t sync_handle) = 0;
92   virtual void OnPeriodicSyncTransferred(int pa_source, uint8_t status, Address address) = 0;
93   virtual void OnBigInfoReport(uint16_t sync_handle, bool encrypted) = 0;
94 };
95 
96 class AdvertisingPacketContentFilterCommand {
97  public:
98   ApcfFilterType filter_type;
99   Address address;
100   ApcfApplicationAddressType application_address_type;
101   Uuid uuid;
102   Uuid uuid_mask;
103   std::vector<uint8_t> name;
104   uint16_t company;
105   uint16_t company_mask;
106   uint8_t org_id;
107   uint8_t tds_flags;
108   uint8_t tds_flags_mask;
109   ApcfMetaDataType meta_data_type;
110   std::vector<uint8_t> meta_data;
111   uint8_t ad_type;
112   std::vector<uint8_t> data;
113   std::vector<uint8_t> data_mask;
114   std::array<uint8_t, 16> irk;
115 };
116 
117 class AdvertisingFilterParameter {
118  public:
119   uint16_t feature_selection;
120   uint16_t list_logic_type;
121   uint8_t filter_logic_type;
122   uint8_t rssi_high_thresh;
123   DeliveryMode delivery_mode;
124   uint16_t onfound_timeout;
125   uint8_t onfound_timeout_cnt;
126   uint8_t rssi_low_thresh;
127   uint16_t onlost_timeout;
128   uint16_t num_of_tracking_entries;
129 };
130 
131 }  // namespace hci
132 }  // namespace bluetooth
133