1 // Copyright 2015 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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_
9 #import <CoreBluetooth/CoreBluetooth.h>
10 #else // !defined(OS_IOS)
11 #import <IOBluetooth/IOBluetooth.h>
12 #endif // defined(OS_IOS)
16 #include "base/mac/scoped_nsobject.h"
17 #include "base/mac/sdk_forward_declarations.h"
18 #include "crypto/sha2.h"
19 #include "device/bluetooth/bluetooth_device_mac.h"
23 class BluetoothLowEnergyDiscoverManagerMac
;
25 class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyDeviceMac
26 : public BluetoothDeviceMac
{
28 BluetoothLowEnergyDeviceMac(CBPeripheral
* peripheral
,
29 NSDictionary
* advertisement_data
,
31 ~BluetoothLowEnergyDeviceMac() override
;
35 // BluetoothDevice overrides.
36 std::string
GetIdentifier() const override
;
37 uint32
GetBluetoothClass() const override
;
38 std::string
GetAddress() const override
;
39 BluetoothDevice::VendorIDSource
GetVendorIDSource() const override
;
40 uint16
GetVendorID() const override
;
41 uint16
GetProductID() const override
;
42 uint16
GetDeviceID() const override
;
43 bool IsPaired() const override
;
44 bool IsConnected() const override
;
45 bool IsConnectable() const override
;
46 bool IsConnecting() const override
;
47 BluetoothDevice::UUIDList
GetUUIDs() const override
;
48 int16
GetInquiryRSSI() const override
;
49 int16
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 Connect(PairingDelegate
* pairing_delegate
,
55 const base::Closure
& callback
,
56 const ConnectErrorCallback
& error_callback
) override
;
57 void SetPinCode(const std::string
& pincode
) override
;
58 void SetPasskey(uint32 passkey
) override
;
59 void ConfirmPairing() override
;
60 void RejectPairing() override
;
61 void CancelPairing() override
;
62 void Disconnect(const base::Closure
& callback
,
63 const ErrorCallback
& error_callback
) override
;
64 void Forget(const ErrorCallback
& error_callback
) override
;
65 void ConnectToService(
66 const BluetoothUUID
& uuid
,
67 const ConnectToServiceCallback
& callback
,
68 const ConnectToServiceErrorCallback
& error_callback
) override
;
69 void ConnectToServiceInsecurely(
70 const device::BluetoothUUID
& uuid
,
71 const ConnectToServiceCallback
& callback
,
72 const ConnectToServiceErrorCallback
& error_callback
) override
;
73 void CreateGattConnection(
74 const GattConnectionCallback
& callback
,
75 const ConnectErrorCallback
& error_callback
) override
;
77 // BluetoothDeviceMac override.
78 NSDate
* GetLastUpdateTime() const override
;
81 // BluetoothDevice override.
82 std::string
GetDeviceName() const override
;
84 // Updates information about the device.
85 virtual void Update(CBPeripheral
* peripheral
,
86 NSDictionary
* advertisement_data
,
89 static std::string
GetPeripheralIdentifier(CBPeripheral
* peripheral
);
91 // Hashes and truncates the peripheral identifier to deterministically
92 // construct an address. The use of fake addresses is a temporary fix before
93 // we switch to using bluetooth identifiers throughout Chrome.
94 // http://crbug.com/507824
95 static std::string
GetPeripheralHashAddress(CBPeripheral
* peripheral
);
98 friend class BluetoothAdapterMac
;
99 friend class BluetoothAdapterMacTest
;
101 // Equivalent to [peripheral_ state]. Allows compilation on OS X 10.6.
102 CBPeripheralState
GetPeripheralState() const;
104 // CoreBluetooth data structure.
105 base::scoped_nsobject
<CBPeripheral
> peripheral_
;
110 // Whether the device is connectable.
113 // The peripheral's identifier, as returned by [CBPeripheral identifier].
114 std::string identifier_
;
116 // A local address for the device created by hashing the peripheral
118 std::string hash_address_
;
120 // Stores the time of the most recent call to Update().
121 base::scoped_nsobject
<NSDate
> last_update_time_
;
123 // The services (identified by UUIDs) that this device provides.
124 std::set
<BluetoothUUID
> advertised_uuids_
;
126 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac
);
129 } // namespace device
131 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_