1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_CLASSIC_DEVICE_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_CLASSIC_DEVICE_MAC_H_
7 
8 #import <IOBluetooth/IOBluetooth.h>
9 #include <stdint.h>
10 
11 #include <string>
12 
13 #include "base/mac/scoped_nsobject.h"
14 #include "base/macros.h"
15 #include "base/observer_list.h"
16 #include "base/optional.h"
17 #include "base/time/time.h"
18 #include "device/bluetooth/bluetooth_device_mac.h"
19 
20 @class IOBluetoothDevice;
21 
22 namespace device {
23 
24 class BluetoothAdapterMac;
25 class BluetoothUUID;
26 
27 class BluetoothClassicDeviceMac : public BluetoothDeviceMac {
28  public:
29   explicit BluetoothClassicDeviceMac(BluetoothAdapterMac* adapter,
30                                      IOBluetoothDevice* device);
31   ~BluetoothClassicDeviceMac() override;
32 
33   // BluetoothDevice override
34   uint32_t GetBluetoothClass() const override;
35   std::string GetAddress() const override;
36   VendorIDSource GetVendorIDSource() const override;
37   uint16_t GetVendorID() const override;
38   uint16_t GetProductID() const override;
39   uint16_t GetDeviceID() const override;
40   uint16_t GetAppearance() const override;
41   base::Optional<std::string> GetName() const override;
42   bool IsPaired() const override;
43   bool IsConnected() const override;
44   bool IsGattConnected() const override;
45   bool IsConnectable() const override;
46   bool IsConnecting() const override;
47   UUIDSet GetUUIDs() const override;
48   base::Optional<int8_t> GetInquiryRSSI() const override;
49   base::Optional<int8_t> GetInquiryTxPower() const override;
50   bool ExpectingPinCode() const override;
51   bool ExpectingPasskey() const override;
52   bool ExpectingConfirmation() const override;
53   void GetConnectionInfo(const ConnectionInfoCallback& callback) override;
54   void SetConnectionLatency(ConnectionLatency connection_latency,
55                             const base::Closure& callback,
56                             const ErrorCallback& error_callback) override;
57   void Connect(PairingDelegate* pairing_delegate,
58                base::OnceClosure callback,
59                ConnectErrorCallback error_callback) override;
60   void SetPinCode(const std::string& pincode) override;
61   void SetPasskey(uint32_t passkey) override;
62   void ConfirmPairing() override;
63   void RejectPairing() override;
64   void CancelPairing() override;
65   void Disconnect(const base::Closure& callback,
66                   const ErrorCallback& error_callback) override;
67   void Forget(const base::Closure& callback,
68               const ErrorCallback& error_callback) override;
69   void ConnectToService(
70       const BluetoothUUID& uuid,
71       const ConnectToServiceCallback& callback,
72       const ConnectToServiceErrorCallback& error_callback) override;
73   void ConnectToServiceInsecurely(
74       const BluetoothUUID& uuid,
75       const ConnectToServiceCallback& callback,
76       const ConnectToServiceErrorCallback& error_callback) override;
77 
78   base::Time GetLastUpdateTime() const override;
79 
80   // Returns the Bluetooth address for the |device|. The returned address has a
81   // normalized format (see below).
82   static std::string GetDeviceAddress(IOBluetoothDevice* device);
83 
84  protected:
85   // BluetoothDevice override
86   void CreateGattConnectionImpl(
87       base::Optional<BluetoothUUID> service_uuid) override;
88   void DisconnectGatt() override;
89 
90  private:
91   friend class BluetoothAdapterMac;
92 
93   // Implementation to read the host's transmit power level of type
94   // |power_level_type|.
95   int GetHostTransmitPower(
96       BluetoothHCITransmitPowerLevelType power_level_type) const;
97 
98   base::scoped_nsobject<IOBluetoothDevice> device_;
99 
100   DISALLOW_COPY_AND_ASSIGN(BluetoothClassicDeviceMac);
101 };
102 
103 }  // namespace device
104 
105 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_CLASSIC_DEVICE_MAC_H_
106