| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/hash.h" | 10 #include "base/hash.h" |
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | |
| 15 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 16 #include "device/bluetooth/bluetooth_profile_mac.h" | 15 #include "device/bluetooth/bluetooth_profile_mac.h" |
| 17 #include "device/bluetooth/bluetooth_socket_mac.h" | 16 #include "device/bluetooth/bluetooth_socket_mac.h" |
| 18 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
| 19 | 18 |
| 20 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 19 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
| 21 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 20 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| 22 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 21 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| 23 | 22 |
| 24 @interface IOBluetoothDevice (LionSDKDeclarations) | 23 @interface IOBluetoothDevice (LionSDKDeclarations) |
| 25 - (NSString*)addressString; | 24 - (NSString*)addressString; |
| 26 - (unsigned int)classOfDevice; | 25 - (unsigned int)classOfDevice; |
| 27 - (BluetoothConnectionHandle)connectionHandle; | 26 - (BluetoothConnectionHandle)connectionHandle; |
| 28 - (BluetoothHCIRSSIValue)rawRSSI; | 27 - (BluetoothHCIRSSIValue)rawRSSI; |
| 29 - (NSArray*)services; | 28 - (NSArray*)services; |
| 30 @end | 29 @end |
| 31 | 30 |
| 32 #endif // MAC_OS_X_VERSION_10_7 | 31 #endif // MAC_OS_X_VERSION_10_7 |
| 33 | 32 |
| 34 // Undocumented API for accessing the Bluetooth transmit power level. | 33 // Undocumented API for accessing the Bluetooth transmit power level. |
| 35 // Similar to the API defined here [ http://goo.gl/20Q5vE ]. | 34 // Similar to the API defined here [ http://goo.gl/20Q5vE ]. |
| 36 @interface IOBluetoothHostController (UndocumentedAPI) | 35 @interface IOBluetoothHostController (UndocumentedAPI) |
| 37 - (IOReturn) | 36 - (IOReturn) |
| 38 BluetoothHCIReadTransmitPowerLevel:(BluetoothConnectionHandle)connection | 37 BluetoothHCIReadTransmitPowerLevel:(BluetoothConnectionHandle)connection |
| 39 inType:(BluetoothHCITransmitPowerLevelType)type | 38 inType:(BluetoothHCITransmitPowerLevelType)type |
| 40 outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*)level; | 39 outTransmitPowerLevel:(BluetoothHCITransmitPowerLevel*)level; |
| 41 @end | 40 @end |
| 42 | 41 |
| 42 namespace device { |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 void ExtractUuid(IOBluetoothSDPDataElement* service_class_data, | 45 // Returns the first (should be, only) UUID contained within the |
| 46 std::string* uuid) { | 46 // |service_class_data|. Returns an invalid (empty) UUID if none is found. |
| 47 BluetoothUUID ExtractUuid(IOBluetoothSDPDataElement* service_class_data) { |
| 47 NSArray* inner_elements = [service_class_data getArrayValue]; | 48 NSArray* inner_elements = [service_class_data getArrayValue]; |
| 48 IOBluetoothSDPUUID* sdp_uuid = nil; | 49 IOBluetoothSDPUUID* sdp_uuid = nil; |
| 49 for (IOBluetoothSDPDataElement* inner_element in inner_elements) { | 50 for (IOBluetoothSDPDataElement* inner_element in inner_elements) { |
| 50 if ([inner_element getTypeDescriptor] == kBluetoothSDPDataElementTypeUUID) { | 51 if ([inner_element getTypeDescriptor] == kBluetoothSDPDataElementTypeUUID) { |
| 51 sdp_uuid = [[inner_element getUUIDValue] getUUIDWithLength:16]; | 52 sdp_uuid = [[inner_element getUUIDValue] getUUIDWithLength:16]; |
| 52 break; | 53 break; |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 if (sdp_uuid != nil) { | 56 |
| 56 const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]); | 57 if (!sdp_uuid) |
| 57 *uuid = base::StringPrintf( | 58 return BluetoothUUID(); |
| 58 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", | 59 |
| 59 uuid_bytes[0], uuid_bytes[1], uuid_bytes[2], uuid_bytes[3], | 60 const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]); |
| 60 uuid_bytes[4], uuid_bytes[5], uuid_bytes[6], uuid_bytes[7], | 61 std::string uuid_str = base::HexEncode(uuid_bytes, 16); |
| 61 uuid_bytes[8], uuid_bytes[9], uuid_bytes[10], uuid_bytes[11], | 62 DCHECK_EQ(uuid_str.size(), 32U); |
| 62 uuid_bytes[12], uuid_bytes[13], uuid_bytes[14], uuid_bytes[15]); | 63 uuid_str.insert(8, "-"); |
| 63 } | 64 uuid_str.insert(13, "-"); |
| 65 uuid_str.insert(18, "-"); |
| 66 uuid_str.insert(23, "-"); |
| 67 return BluetoothUUID(uuid_str); |
| 64 } | 68 } |
| 65 | 69 |
| 66 } // namespace | 70 } // namespace |
| 67 | 71 |
| 68 namespace device { | |
| 69 | |
| 70 BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device) | 72 BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device) |
| 71 : device_([device retain]) { | 73 : device_([device retain]) { |
| 72 } | 74 } |
| 73 | 75 |
| 74 BluetoothDeviceMac::~BluetoothDeviceMac() { | 76 BluetoothDeviceMac::~BluetoothDeviceMac() { |
| 75 } | 77 } |
| 76 | 78 |
| 77 void BluetoothDeviceMac::AddObserver( | 79 void BluetoothDeviceMac::AddObserver( |
| 78 device::BluetoothDevice::Observer* observer) { | 80 device::BluetoothDevice::Observer* observer) { |
| 79 DCHECK(observer); | 81 DCHECK(observer); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 return false; | 152 return false; |
| 151 } | 153 } |
| 152 | 154 |
| 153 bool BluetoothDeviceMac::IsConnecting() const { | 155 bool BluetoothDeviceMac::IsConnecting() const { |
| 154 return false; | 156 return false; |
| 155 } | 157 } |
| 156 | 158 |
| 157 BluetoothDevice::UUIDList BluetoothDeviceMac::GetUUIDs() const { | 159 BluetoothDevice::UUIDList BluetoothDeviceMac::GetUUIDs() const { |
| 158 UUIDList uuids; | 160 UUIDList uuids; |
| 159 for (IOBluetoothSDPServiceRecord* service_record in [device_ services]) { | 161 for (IOBluetoothSDPServiceRecord* service_record in [device_ services]) { |
| 160 const BluetoothSDPServiceAttributeID service_class_id = 1; | |
| 161 IOBluetoothSDPDataElement* service_class_data = | 162 IOBluetoothSDPDataElement* service_class_data = |
| 162 [service_record getAttributeDataElement:service_class_id]; | 163 [service_record getAttributeDataElement: |
| 164 kBluetoothSDPAttributeIdentifierServiceClassIDList]; |
| 163 if ([service_class_data getTypeDescriptor] == | 165 if ([service_class_data getTypeDescriptor] == |
| 164 kBluetoothSDPDataElementTypeDataElementSequence) { | 166 kBluetoothSDPDataElementTypeDataElementSequence) { |
| 165 std::string uuid_str; | 167 BluetoothUUID uuid = ExtractUuid(service_class_data); |
| 166 ExtractUuid(service_class_data, &uuid_str); | 168 if (uuid.IsValid()) |
| 167 uuids.push_back(BluetoothUUID(uuid_str)); | 169 uuids.push_back(uuid); |
| 168 } | 170 } |
| 169 } | 171 } |
| 170 return uuids; | 172 return uuids; |
| 171 } | 173 } |
| 172 | 174 |
| 173 bool BluetoothDeviceMac::ExpectingPinCode() const { | 175 bool BluetoothDeviceMac::ExpectingPinCode() const { |
| 174 NOTIMPLEMENTED(); | 176 NOTIMPLEMENTED(); |
| 175 return false; | 177 return false; |
| 176 } | 178 } |
| 177 | 179 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 266 |
| 265 return power_level; | 267 return power_level; |
| 266 } | 268 } |
| 267 | 269 |
| 268 // static | 270 // static |
| 269 std::string BluetoothDeviceMac::GetDeviceAddress(IOBluetoothDevice* device) { | 271 std::string BluetoothDeviceMac::GetDeviceAddress(IOBluetoothDevice* device) { |
| 270 return CanonicalizeAddress(base::SysNSStringToUTF8([device addressString])); | 272 return CanonicalizeAddress(base::SysNSStringToUTF8([device addressString])); |
| 271 } | 273 } |
| 272 | 274 |
| 273 } // namespace device | 275 } // namespace device |
| OLD | NEW |