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 #include "module.h"
22 #include "neighbor/scan_parameters.h"
23 
24 namespace bluetooth {
25 namespace neighbor {
26 
27 using InquiryLength = uint8_t;  // Range: 0x01 to 0x30, 1.28 to 61.44s
28 using NumResponses = uint8_t;   // Range: 0x01 to 0xff, 0x00 is unlimited
29 using PeriodLength = uint16_t;  // Time = N * 1.28 s
30 
31 using InquiryResultCallback = std::function<void(hci::InquiryResultView view)>;
32 using InquiryResultWithRssiCallback = std::function<void(hci::InquiryResultWithRssiView view)>;
33 using ExtendedInquiryResultCallback = std::function<void(hci::ExtendedInquiryResultView view)>;
34 using InquiryCompleteCallback = std::function<void(hci::ErrorCode status)>;
35 
36 using InquiryCallbacks = struct {
37   InquiryResultCallback result;
38   InquiryResultWithRssiCallback result_with_rssi;
39   ExtendedInquiryResultCallback extended_result;
40   InquiryCompleteCallback complete;
41 };
42 
43 class InquiryModule : public bluetooth::Module {
44  public:
45   void RegisterCallbacks(InquiryCallbacks inquiry_callbacks);
46   void UnregisterCallbacks();
47 
48   void StartGeneralInquiry(InquiryLength inquiry_length, NumResponses num_responses);
49   void StartLimitedInquiry(InquiryLength inquiry_length, NumResponses num_responses);
50   void StopInquiry();
51 
52   void StartGeneralPeriodicInquiry(
53       InquiryLength inquiry_length, NumResponses num_responses, PeriodLength max_delay, PeriodLength min_delay);
54   void StartLimitedPeriodicInquiry(
55       InquiryLength inquiry_length, NumResponses num_responses, PeriodLength max_delay, PeriodLength min_delay);
56   void StopPeriodicInquiry();
57 
58   void SetScanActivity(ScanParameters parms);
59 
60   void SetInterlacedScan();
61   void SetStandardScan();
62 
63   void SetStandardInquiryResultMode();
64   void SetInquiryWithRssiResultMode();
65   void SetExtendedInquiryResultMode();
66 
67   static const ModuleFactory Factory;
68 
69   InquiryModule();
70   ~InquiryModule();
71 
72  protected:
73   void ListDependencies(ModuleList* list) override;
74   void Start() override;
75   void Stop() override;
76 
77  private:
78   struct impl;
79   std::unique_ptr<impl> pimpl_;
80 
81   DISALLOW_COPY_AND_ASSIGN(InquiryModule);
82 };
83 
84 }  // namespace neighbor
85 }  // namespace bluetooth
86