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.
5 #include "device/bluetooth/bluetooth_service_record_mac.h"
7 #include <IOBluetooth/Bluetooth.h>
8 #import <IOBluetooth/IOBluetoothUtilities.h>
9 #import <IOBluetooth/objc/IOBluetoothDevice.h>
10 #import <IOBluetooth/objc/IOBluetoothSDPDataElement.h>
11 #import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
12 #import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
16 #include "base/basictypes.h"
17 #include "base/strings/stringprintf.h"
18 #include "base/strings/sys_string_conversions.h"
22 void ExtractUuid(IOBluetoothSDPDataElement* service_class_data,
24 NSArray* inner_elements = [service_class_data getArrayValue];
25 IOBluetoothSDPUUID* sdp_uuid = nil;
26 for (IOBluetoothSDPDataElement* inner_element in inner_elements) {
27 if ([inner_element getTypeDescriptor] == kBluetoothSDPDataElementTypeUUID) {
28 sdp_uuid = [[inner_element getUUIDValue] getUUIDWithLength:16];
32 if (sdp_uuid != nil) {
33 const uint8* uuid_bytes = reinterpret_cast<const uint8*>([sdp_uuid bytes]);
34 *uuid = base::StringPrintf(
35 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
36 uuid_bytes[0], uuid_bytes[1], uuid_bytes[2], uuid_bytes[3],
37 uuid_bytes[4], uuid_bytes[5], uuid_bytes[6], uuid_bytes[7],
38 uuid_bytes[8], uuid_bytes[9], uuid_bytes[10], uuid_bytes[11],
39 uuid_bytes[12], uuid_bytes[13], uuid_bytes[14], uuid_bytes[15]);
47 BluetoothServiceRecordMac::BluetoothServiceRecordMac(
48 IOBluetoothSDPServiceRecord* record)
49 : BluetoothServiceRecord() {
50 name_ = base::SysNSStringToUTF8([record getServiceName]);
51 device_ = [[record device] retain];
52 address_ = base::SysNSStringToUTF8(IOBluetoothNSStringFromDeviceAddress(
53 [device_ getAddress]));
55 // TODO(youngki): Extract these values from |record|.
56 supports_hid_ = false;
57 hid_reconnect_initiate_ = false;
58 hid_normally_connectable_ = false;
61 [record getRFCOMMChannelID:&rfcomm_channel_] == kIOReturnSuccess;
63 const BluetoothSDPServiceAttributeID service_class_id = 1;
65 IOBluetoothSDPDataElement* service_class_data =
66 [record getAttributeDataElement:service_class_id];
67 if ([service_class_data getTypeDescriptor] ==
68 kBluetoothSDPDataElementTypeDataElementSequence) {
69 ExtractUuid(service_class_data, &uuid_);
73 BluetoothServiceRecordMac::~BluetoothServiceRecordMac() {