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 BluetoothAdapterMac
;
24 class BluetoothLowEnergyDiscoverManagerMac
;
26 class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyDeviceMac
27 : public BluetoothDeviceMac
{
29 BluetoothLowEnergyDeviceMac(BluetoothAdapterMac
* adapter
,
30 CBPeripheral
* peripheral
,
31 NSDictionary
* advertisement_data
,
33 ~BluetoothLowEnergyDeviceMac() override
;
37 // BluetoothDevice overrides.
38 std::string
GetIdentifier() const override
;
39 uint32
GetBluetoothClass() const override
;
40 std::string
GetAddress() const override
;
41 BluetoothDevice::VendorIDSource
GetVendorIDSource() const override
;
42 uint16
GetVendorID() const override
;
43 uint16
GetProductID() const override
;
44 uint16
GetDeviceID() const override
;
45 bool IsPaired() const override
;
46 bool IsConnected() const override
;
47 bool IsGattConnected() const override
;
48 bool IsConnectable() const override
;
49 bool IsConnecting() const override
;
50 BluetoothDevice::UUIDList
GetUUIDs() const override
;
51 int16
GetInquiryRSSI() const override
;
52 int16
GetInquiryTxPower() const override
;
53 bool ExpectingPinCode() const override
;
54 bool ExpectingPasskey() const override
;
55 bool ExpectingConfirmation() const override
;
56 void GetConnectionInfo(const ConnectionInfoCallback
& callback
) override
;
57 void Connect(PairingDelegate
* pairing_delegate
,
58 const base::Closure
& callback
,
59 const ConnectErrorCallback
& error_callback
) override
;
60 void SetPinCode(const std::string
& pincode
) override
;
61 void SetPasskey(uint32 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 ErrorCallback
& error_callback
) override
;
68 void ConnectToService(
69 const BluetoothUUID
& uuid
,
70 const ConnectToServiceCallback
& callback
,
71 const ConnectToServiceErrorCallback
& error_callback
) override
;
72 void ConnectToServiceInsecurely(
73 const device::BluetoothUUID
& uuid
,
74 const ConnectToServiceCallback
& callback
,
75 const ConnectToServiceErrorCallback
& error_callback
) override
;
76 void CreateGattConnection(
77 const GattConnectionCallback
& callback
,
78 const ConnectErrorCallback
& error_callback
) override
;
80 // BluetoothDeviceMac override.
81 NSDate
* GetLastUpdateTime() const override
;
84 // BluetoothDevice override.
85 std::string
GetDeviceName() const override
;
86 void CreateGattConnectionImpl() override
;
87 void DisconnectGatt() override
;
89 // Updates information about the device.
90 virtual void Update(CBPeripheral
* peripheral
,
91 NSDictionary
* advertisement_data
,
94 static std::string
GetPeripheralIdentifier(CBPeripheral
* peripheral
);
96 // Hashes and truncates the peripheral identifier to deterministically
97 // construct an address. The use of fake addresses is a temporary fix before
98 // we switch to using bluetooth identifiers throughout Chrome.
99 // http://crbug.com/507824
100 static std::string
GetPeripheralHashAddress(CBPeripheral
* peripheral
);
103 friend class BluetoothAdapterMac
;
104 friend class BluetoothAdapterMacTest
;
106 // Equivalent to [peripheral_ state]. Allows compilation on OS X 10.6.
107 CBPeripheralState
GetPeripheralState() const;
109 // CoreBluetooth data structure.
110 base::scoped_nsobject
<CBPeripheral
> peripheral_
;
115 // Whether the device is connectable.
118 // The peripheral's identifier, as returned by [CBPeripheral identifier].
119 std::string identifier_
;
121 // A local address for the device created by hashing the peripheral
123 std::string hash_address_
;
125 // Stores the time of the most recent call to Update().
126 base::scoped_nsobject
<NSDate
> last_update_time_
;
128 // The services (identified by UUIDs) that this device provides.
129 std::set
<BluetoothUUID
> advertised_uuids_
;
131 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac
);
134 } // namespace device
136 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_