OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_service_record_win.h" | 5 #include "device/bluetooth/bluetooth_service_record_win.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "device/bluetooth/bluetooth_init_win.h" | 12 #include "device/bluetooth/bluetooth_init_win.h" |
13 #include "device/bluetooth/bluetooth_uuid.h" | 13 #include "device/bluetooth/bluetooth_utils.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const uint16 kProtocolDescriptorListId = 4; | 17 const uint16 kProtocolDescriptorListId = 4; |
18 const uint16 kRfcommUuid = 3; | 18 const uint16 kRfcommUuid = 3; |
19 const uint16 kUuidId = 1; | 19 const uint16 kUuidId = 1; |
20 | 20 |
21 bool AdvanceToSdpType(const SDP_ELEMENT_DATA& sequence_data, | 21 bool AdvanceToSdpType(const SDP_ELEMENT_DATA& sequence_data, |
22 SDP_TYPE type, | 22 SDP_TYPE type, |
23 HBLUETOOTH_CONTAINER_ELEMENT* element, | 23 HBLUETOOTH_CONTAINER_ELEMENT* element, |
(...skipping 30 matching lines...) Expand all Loading... |
54 SDP_TYPE_UINT, | 54 SDP_TYPE_UINT, |
55 &inner_sequence_element, | 55 &inner_sequence_element, |
56 &inner_sequence_data) && | 56 &inner_sequence_data) && |
57 inner_sequence_data.specificType == SDP_ST_UINT8) { | 57 inner_sequence_data.specificType == SDP_ST_UINT8) { |
58 *rfcomm_channel = inner_sequence_data.data.uint8; | 58 *rfcomm_channel = inner_sequence_data.data.uint8; |
59 *supports_rfcomm = true; | 59 *supports_rfcomm = true; |
60 } | 60 } |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 void ExtractUuid(const SDP_ELEMENT_DATA& uuid_data, | 64 void ExtractUuid(const SDP_ELEMENT_DATA& uuid_data, std::string* uuid) { |
65 device::BluetoothUUID* uuid) { | |
66 HBLUETOOTH_CONTAINER_ELEMENT inner_uuid_element = NULL; | 65 HBLUETOOTH_CONTAINER_ELEMENT inner_uuid_element = NULL; |
67 SDP_ELEMENT_DATA inner_uuid_data; | 66 SDP_ELEMENT_DATA inner_uuid_data; |
68 if (AdvanceToSdpType(uuid_data, | 67 if (AdvanceToSdpType(uuid_data, |
69 SDP_TYPE_UUID, | 68 SDP_TYPE_UUID, |
70 &inner_uuid_element, | 69 &inner_uuid_element, |
71 &inner_uuid_data)) { | 70 &inner_uuid_data)) { |
72 if (inner_uuid_data.specificType == SDP_ST_UUID16) { | 71 if (inner_uuid_data.specificType == SDP_ST_UUID16) { |
73 std::string uuid_hex = | 72 std::string uuid_hex = |
74 base::StringPrintf("%04x", inner_uuid_data.data.uuid16); | 73 base::StringPrintf("%04x", inner_uuid_data.data.uuid16); |
75 *uuid = device::BluetoothUUID(uuid_hex); | 74 *uuid = device::bluetooth_utils::CanonicalUuid(uuid_hex); |
76 } else if (inner_uuid_data.specificType == SDP_ST_UUID32) { | 75 } else if (inner_uuid_data.specificType == SDP_ST_UUID32) { |
77 std::string uuid_hex = | 76 std::string uuid_hex = |
78 base::StringPrintf("%08x", inner_uuid_data.data.uuid32); | 77 base::StringPrintf("%08x", inner_uuid_data.data.uuid32); |
79 *uuid = device::BluetoothUUID(uuid_hex); | 78 *uuid = device::bluetooth_utils::CanonicalUuid(uuid_hex); |
80 } else if (inner_uuid_data.specificType == SDP_ST_UUID128) { | 79 } else if (inner_uuid_data.specificType == SDP_ST_UUID128) { |
81 *uuid = device::BluetoothUUID(base::StringPrintf( | 80 *uuid = base::StringPrintf( |
82 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", | 81 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
83 inner_uuid_data.data.uuid128.Data1, | 82 inner_uuid_data.data.uuid128.Data1, |
84 inner_uuid_data.data.uuid128.Data2, | 83 inner_uuid_data.data.uuid128.Data2, |
85 inner_uuid_data.data.uuid128.Data3, | 84 inner_uuid_data.data.uuid128.Data3, |
86 inner_uuid_data.data.uuid128.Data4[0], | 85 inner_uuid_data.data.uuid128.Data4[0], |
87 inner_uuid_data.data.uuid128.Data4[1], | 86 inner_uuid_data.data.uuid128.Data4[1], |
88 inner_uuid_data.data.uuid128.Data4[2], | 87 inner_uuid_data.data.uuid128.Data4[2], |
89 inner_uuid_data.data.uuid128.Data4[3], | 88 inner_uuid_data.data.uuid128.Data4[3], |
90 inner_uuid_data.data.uuid128.Data4[4], | 89 inner_uuid_data.data.uuid128.Data4[4], |
91 inner_uuid_data.data.uuid128.Data4[5], | 90 inner_uuid_data.data.uuid128.Data4[5], |
92 inner_uuid_data.data.uuid128.Data4[6], | 91 inner_uuid_data.data.uuid128.Data4[6], |
93 inner_uuid_data.data.uuid128.Data4[7])); | 92 inner_uuid_data.data.uuid128.Data4[7]); |
94 } else { | 93 } else { |
95 *uuid = device::BluetoothUUID(); | 94 uuid->clear(); |
96 } | 95 } |
97 } | 96 } |
98 } | 97 } |
99 | 98 |
100 BTH_ADDR ConvertToBthAddr(const std::string& address) { | 99 BTH_ADDR ConvertToBthAddr(const std::string& address) { |
101 BTH_ADDR bth_addr = 0; | 100 BTH_ADDR bth_addr = 0; |
102 std::string numbers_only; | 101 std::string numbers_only; |
103 for (int i = 0; i < 6; ++i) { | 102 for (int i = 0; i < 6; ++i) { |
104 numbers_only += address.substr(i * 3, 2); | 103 numbers_only += address.substr(i * 3, 2); |
105 } | 104 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 ExtractChannels(protocol_descriptor_list_data, | 136 ExtractChannels(protocol_descriptor_list_data, |
138 &supports_rfcomm_, | 137 &supports_rfcomm_, |
139 &rfcomm_channel_); | 138 &rfcomm_channel_); |
140 } | 139 } |
141 SDP_ELEMENT_DATA uuid_data; | 140 SDP_ELEMENT_DATA uuid_data; |
142 if (ERROR_SUCCESS == BluetoothSdpGetAttributeValue( | 141 if (ERROR_SUCCESS == BluetoothSdpGetAttributeValue( |
143 blob_data, | 142 blob_data, |
144 blob_size, | 143 blob_size, |
145 kUuidId, | 144 kUuidId, |
146 &uuid_data)) { | 145 &uuid_data)) { |
147 ExtractUuid(uuid_data, &uuid_); | 146 ExtractUuid(uuid_data, &uuid_); |
148 } | 147 } |
149 } | 148 } |
150 | 149 |
151 } // namespace device | 150 } // namespace device |
OLD | NEW |