OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/bluetooth/bluetooth_device_mac.h" | 5 #include "device/bluetooth/bluetooth_device_mac.h" |
6 | 6 |
7 #include <IOBluetooth/Bluetooth.h> | |
8 #import <IOBluetooth/objc/IOBluetoothDevice.h> | |
9 #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> | |
10 #import <IOBluetooth/objc/IOBluetoothSDPUUID.h> | |
11 | |
12 #include <string> | 7 #include <string> |
13 | 8 |
14 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
15 #include "base/hash.h" | 10 #include "base/hash.h" |
16 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
17 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
19 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
20 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 15 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
21 #include "device/bluetooth/bluetooth_profile_mac.h" | 16 #include "device/bluetooth/bluetooth_profile_mac.h" |
22 #include "device/bluetooth/bluetooth_service_record_mac.h" | 17 #include "device/bluetooth/bluetooth_service_record_mac.h" |
23 #include "device/bluetooth/bluetooth_socket_mac.h" | 18 #include "device/bluetooth/bluetooth_socket_mac.h" |
24 | 19 |
25 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 20 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
26 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 21 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
27 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 22 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
28 | 23 |
29 @interface IOBluetoothDevice (LionSDKDeclarations) | 24 @interface IOBluetoothDevice (LionSDKDeclarations) |
30 - (NSString*)addressString; | 25 - (NSString*)addressString; |
31 - (NSString*)name; | |
32 - (unsigned int)classOfDevice; | 26 - (unsigned int)classOfDevice; |
| 27 - (BluetoothConnectionHandle)connectionHandle; |
| 28 - (BluetoothHCIRSSIValue)rawRSSI; |
33 - (NSArray*)services; | 29 - (NSArray*)services; |
34 @end | 30 @end |
35 | 31 |
36 #endif // MAC_OS_X_VERSION_10_7 | 32 #endif // MAC_OS_X_VERSION_10_7 |
37 | 33 |
| 34 // Undocumented API for accessing the Bluetooth transmit power level. |
| 35 // Similar to the API defined here [ http://goo.gl/20Q5vE ]. |
| 36 @interface IOBluetoothHostController (UndocumentedAPI) |
| 37 - (IOReturn) |
| 38 BluetoothHCIReadTransmitPowerLevel:(BluetoothConnectionHandle)connection |
| 39 inType:(BluetoothHCITransmitPowerLevelType)type |
| 40 outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*)level; |
| 41 @end |
| 42 |
38 namespace device { | 43 namespace device { |
39 | 44 |
40 BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device) | 45 BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device) |
41 : device_([device retain]) { | 46 : device_([device retain]) { |
42 } | 47 } |
43 | 48 |
44 BluetoothDeviceMac::~BluetoothDeviceMac() { | 49 BluetoothDeviceMac::~BluetoothDeviceMac() { |
45 } | 50 } |
46 | 51 |
47 void BluetoothDeviceMac::AddObserver( | 52 void BluetoothDeviceMac::AddObserver( |
(...skipping 29 matching lines...) Expand all Loading... |
77 } | 82 } |
78 | 83 |
79 uint16 BluetoothDeviceMac::GetProductID() const { | 84 uint16 BluetoothDeviceMac::GetProductID() const { |
80 return 0; | 85 return 0; |
81 } | 86 } |
82 | 87 |
83 uint16 BluetoothDeviceMac::GetDeviceID() const { | 88 uint16 BluetoothDeviceMac::GetDeviceID() const { |
84 return 0; | 89 return 0; |
85 } | 90 } |
86 | 91 |
| 92 int BluetoothDeviceMac::GetRSSI() const { |
| 93 if (![device_ isConnected]) { |
| 94 NOTIMPLEMENTED(); |
| 95 return kUnknownPower; |
| 96 } |
| 97 |
| 98 int rssi = [device_ rawRSSI]; |
| 99 |
| 100 // The API guarantees that +127 is returned in case the RSSI is not readable: |
| 101 // http://goo.gl/bpURYv |
| 102 if (rssi == 127) |
| 103 return kUnknownPower; |
| 104 |
| 105 return rssi; |
| 106 } |
| 107 |
| 108 int BluetoothDeviceMac::GetCurrentHostTransmitPower() const { |
| 109 return GetHostTransmitPower(kReadCurrentTransmitPowerLevel); |
| 110 } |
| 111 |
| 112 int BluetoothDeviceMac::GetMaximumHostTransmitPower() const { |
| 113 return GetHostTransmitPower(kReadMaximumTransmitPowerLevel); |
| 114 } |
| 115 |
87 bool BluetoothDeviceMac::IsPaired() const { | 116 bool BluetoothDeviceMac::IsPaired() const { |
88 return [device_ isPaired]; | 117 return [device_ isPaired]; |
89 } | 118 } |
90 | 119 |
91 bool BluetoothDeviceMac::IsConnected() const { | 120 bool BluetoothDeviceMac::IsConnected() const { |
92 return [device_ isConnected]; | 121 return [device_ isConnected]; |
93 } | 122 } |
94 | 123 |
95 bool BluetoothDeviceMac::IsConnectable() const { | 124 bool BluetoothDeviceMac::IsConnectable() const { |
96 return false; | 125 return false; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 const ErrorCallback& error_callback) { | 205 const ErrorCallback& error_callback) { |
177 NOTIMPLEMENTED(); | 206 NOTIMPLEMENTED(); |
178 } | 207 } |
179 | 208 |
180 void BluetoothDeviceMac::ClearOutOfBandPairingData( | 209 void BluetoothDeviceMac::ClearOutOfBandPairingData( |
181 const base::Closure& callback, | 210 const base::Closure& callback, |
182 const ErrorCallback& error_callback) { | 211 const ErrorCallback& error_callback) { |
183 NOTIMPLEMENTED(); | 212 NOTIMPLEMENTED(); |
184 } | 213 } |
185 | 214 |
| 215 int BluetoothDeviceMac::GetHostTransmitPower( |
| 216 BluetoothHCITransmitPowerLevelType power_level_type) const { |
| 217 IOBluetoothHostController* controller = |
| 218 [IOBluetoothHostController defaultController]; |
| 219 |
| 220 // Bail if the undocumented API is unavailable on this machine. |
| 221 SEL selector = @selector( |
| 222 BluetoothHCIReadTransmitPowerLevel:inType:outTransmitPowerLevel:); |
| 223 if (![controller respondsToSelector:selector]) |
| 224 return kUnknownPower; |
| 225 |
| 226 BluetoothHCITransmitPowerLevel power_level; |
| 227 IOReturn result = |
| 228 [controller BluetoothHCIReadTransmitPowerLevel:[device_ connectionHandle] |
| 229 inType:power_level_type |
| 230 outTransmitPowerLevel:&power_level]; |
| 231 if (result != kIOReturnSuccess) |
| 232 return kUnknownPower; |
| 233 |
| 234 return power_level; |
| 235 } |
| 236 |
186 } // namespace device | 237 } // namespace device |
OLD | NEW |