1 /*
2  * Copyright 2019 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 "hci/hci_packets.h"
21 
22 namespace bluetooth::hci {
23 
24 class LeReport {
25  public:
LeReport(const LeAdvertisingReport & advertisement)26   explicit LeReport(const LeAdvertisingReport& advertisement)
27       : report_type_(ReportType::ADVERTISING_EVENT), advertising_event_type_(advertisement.event_type_),
28         address_(advertisement.address_), address_type_(advertisement.address_type_), rssi_(advertisement.rssi_),
29         gap_data_(advertisement.advertising_data_) {}
LeReport(const LeDirectedAdvertisingReport & advertisement)30   explicit LeReport(const LeDirectedAdvertisingReport& advertisement)
31       : report_type_(ReportType::DIRECTED_ADVERTISING_EVENT), address_(advertisement.address_),
32         rssi_(advertisement.rssi_) {}
LeReport(const LeExtendedAdvertisingReport & advertisement)33   explicit LeReport(const LeExtendedAdvertisingReport& advertisement)
34       : report_type_(ReportType::EXTENDED_ADVERTISING_EVENT), address_(advertisement.address_),
35         rssi_(advertisement.rssi_), gap_data_(advertisement.advertising_data_) {}
36   virtual ~LeReport() = default;
37 
38   enum class ReportType {
39     ADVERTISING_EVENT = 1,
40     DIRECTED_ADVERTISING_EVENT = 2,
41     EXTENDED_ADVERTISING_EVENT = 3,
42   };
43   const ReportType report_type_;
44 
GetReportType()45   ReportType GetReportType() const {
46     return report_type_;
47   }
48 
49   // Advertising Event
50   const AdvertisingEventType advertising_event_type_{};
51   const Address address_{};
52   const AddressType address_type_{};
53   const int8_t rssi_;
54   const std::vector<GapData> gap_data_{};
55 };
56 
57 class DirectedLeReport : public LeReport {
58  public:
DirectedLeReport(const LeDirectedAdvertisingReport & advertisement)59   explicit DirectedLeReport(const LeDirectedAdvertisingReport& advertisement)
60       : LeReport(advertisement), direct_address_type_(advertisement.address_type_),
61         direct_address_(advertisement.direct_address_) {}
DirectedLeReport(const LeExtendedAdvertisingReport & advertisement)62   explicit DirectedLeReport(const LeExtendedAdvertisingReport& advertisement)
63       : LeReport(advertisement), direct_address_type_(advertisement.address_type_),
64         direct_address_(advertisement.direct_address_) {}
65 
66   const DirectAdvertisingAddressType direct_address_type_{};
67   const Address direct_address_{};
68 };
69 
70 class ExtendedLeReport : public DirectedLeReport {
71  public:
ExtendedLeReport(const LeExtendedAdvertisingReport & advertisement)72   explicit ExtendedLeReport(const LeExtendedAdvertisingReport& advertisement)
73       : DirectedLeReport(advertisement), connectable_(advertisement.connectable_), scannable_(advertisement.scannable_),
74         directed_(advertisement.directed_), scan_response_(advertisement.scan_response_),
75         complete_(advertisement.data_status_ == DataStatus::COMPLETE),
76         truncated_(advertisement.data_status_ == DataStatus::TRUNCATED) {}
77 
78   // Extended
79   bool connectable_;
80   bool scannable_;
81   bool directed_;
82   bool scan_response_;
83   bool complete_;
84   bool truncated_;
85 };
86 }  // namespace bluetooth::hci