• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #ifndef GD_RUST_TOPSHIM_BTIF_BTIF_SHIM_H
17 #define GD_RUST_TOPSHIM_BTIF_BTIF_SHIM_H
18 
19 #include <memory>
20 
21 #include "include/hardware/bluetooth.h"
22 #include "rust/cxx.h"
23 
24 namespace bluetooth {
25 namespace topshim {
26 namespace rust {
27 
28 struct RustCallbacks;
29 struct InitParams;
30 struct RustRawAddress;
31 struct BtProperty;
32 struct BtPinCode;
33 struct BtUuid;
34 
35 class BluetoothIntf {
36  public:
37   BluetoothIntf();
38   ~BluetoothIntf();
39 
40   bool Initialize(::rust::Box<RustCallbacks> callbacks, ::rust::Vec<::rust::String> initFlags);
41   void CleanUp() const;
42 
43   int Enable() const;
44   int Disable() const;
45 
46   int GetAdapterProperties() const;
47   int GetAdapterProperty(int prop_type) const;
48   int SetAdapterProperty(const BtProperty& prop) const;
49 
50   int GetRemoteDeviceProperties(const RustRawAddress& address) const;
51   int GetRemoteDeviceProperty(const RustRawAddress& address, int prop_type) const;
52   int SetRemoteDeviceProperty(const RustRawAddress& address, const BtProperty& prop) const;
53 
54   int GetRemoteServices(const RustRawAddress& address) const;
55 
56   int StartDiscovery() const;
57   int CancelDiscovery() const;
58 
59   int CreateBond(const RustRawAddress& address, int transport) const;
60   int RemoveBond(const RustRawAddress& address) const;
61   int CancelBond(const RustRawAddress& address) const;
62 
63   int GetConnectionState(const RustRawAddress& address) const;
64 
65   int PinReply(const RustRawAddress& address, uint8_t accept, uint8_t pin_len, const BtPinCode& code) const;
66   int SspReply(const RustRawAddress& address, int ssp_variant, uint8_t accept, uint32_t passkey) const;
67 
GetCallbacks()68   ::rust::Box<RustCallbacks>& GetCallbacks() {
69     return *callbacks_;
70   }
71 
72  private:
73   void ConvertFlags(::rust::Vec<::rust::String>& flags);
74 
75   std::unique_ptr<::rust::Box<RustCallbacks>> callbacks_;
76   bool init_;
77   const char** flags_;
78   const bt_interface_t* intf_;
79 };
80 
81 std::unique_ptr<BluetoothIntf> Load();
82 
83 }  // namespace rust
84 }  // namespace topshim
85 }  // namespace bluetooth
86 
87 #endif  // GD_RUST_TOPSHIM_BTIF_BTIF_SHIM_H
88