Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: device/bluetooth/bluetooth_task_manager_win.cc

Issue 395633003: Enumerate Bluetooth LE services and expose them to chrome.bluetooth API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix x64 build. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/bluetooth_task_manager_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_task_manager_win.h" 5 #include "device/bluetooth/bluetooth_task_manager_win.h"
6 6
7 #include <winsock2.h> 7 #include <winsock2.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 24 matching lines...) Expand all
35 std::string BluetoothAddressToString(const BLUETOOTH_ADDRESS& btha) { 35 std::string BluetoothAddressToString(const BLUETOOTH_ADDRESS& btha) {
36 return base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", 36 return base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X",
37 btha.rgBytes[5], 37 btha.rgBytes[5],
38 btha.rgBytes[4], 38 btha.rgBytes[4],
39 btha.rgBytes[3], 39 btha.rgBytes[3],
40 btha.rgBytes[2], 40 btha.rgBytes[2],
41 btha.rgBytes[1], 41 btha.rgBytes[1],
42 btha.rgBytes[0]); 42 btha.rgBytes[0]);
43 } 43 }
44 44
45 device::BluetoothUUID BluetoothLowEnergyUuidToUBluetoothUuid(
46 const BTH_LE_UUID& bth_le_uuid) {
47 if (bth_le_uuid.IsShortUuid) {
48 std::string uuid_hex =
49 base::StringPrintf("%04x", bth_le_uuid.Value.ShortUuid);
50 return device::BluetoothUUID(uuid_hex);
51 } else {
52 return device::BluetoothUUID(
53 base::StringPrintf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
54 bth_le_uuid.Value.LongUuid.Data1,
55 bth_le_uuid.Value.LongUuid.Data2,
56 bth_le_uuid.Value.LongUuid.Data3,
57 bth_le_uuid.Value.LongUuid.Data4[0],
58 bth_le_uuid.Value.LongUuid.Data4[1],
59 bth_le_uuid.Value.LongUuid.Data4[2],
60 bth_le_uuid.Value.LongUuid.Data4[3],
61 bth_le_uuid.Value.LongUuid.Data4[4],
62 bth_le_uuid.Value.LongUuid.Data4[5],
63 bth_le_uuid.Value.LongUuid.Data4[6],
64 bth_le_uuid.Value.LongUuid.Data4[7]));
65 }
66 }
67
45 // Populates bluetooth adapter state using adapter_handle. 68 // Populates bluetooth adapter state using adapter_handle.
46 void GetAdapterState(HANDLE adapter_handle, 69 void GetAdapterState(HANDLE adapter_handle,
47 device::BluetoothTaskManagerWin::AdapterState* state) { 70 device::BluetoothTaskManagerWin::AdapterState* state) {
48 std::string name; 71 std::string name;
49 std::string address; 72 std::string address;
50 bool powered = false; 73 bool powered = false;
51 BLUETOOTH_RADIO_INFO adapter_info = { sizeof(BLUETOOTH_RADIO_INFO), 0 }; 74 BLUETOOTH_RADIO_INFO adapter_info = { sizeof(BLUETOOTH_RADIO_INFO), 0 };
52 if (adapter_handle && 75 if (adapter_handle &&
53 ERROR_SUCCESS == BluetoothGetRadioInfo(adapter_handle, 76 ERROR_SUCCESS == BluetoothGetRadioInfo(adapter_handle,
54 &adapter_info)) { 77 &adapter_info)) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 while (true) { 120 while (true) {
98 DWORD sdp_buffer_size = sizeof(sdp_buffer); 121 DWORD sdp_buffer_size = sizeof(sdp_buffer);
99 if (ERROR_SUCCESS != 122 if (ERROR_SUCCESS !=
100 WSALookupServiceNext( 123 WSALookupServiceNext(
101 sdp_handle, LUP_RETURN_ALL, &sdp_buffer_size, sdp_result_data)) { 124 sdp_handle, LUP_RETURN_ALL, &sdp_buffer_size, sdp_result_data)) {
102 break; 125 break;
103 } 126 }
104 ServiceRecordState* service_record_state = new ServiceRecordState(); 127 ServiceRecordState* service_record_state = new ServiceRecordState();
105 service_record_state->name = 128 service_record_state->name =
106 base::SysWideToUTF8(sdp_result_data->lpszServiceInstanceName); 129 base::SysWideToUTF8(sdp_result_data->lpszServiceInstanceName);
107 service_record_state->address = device_address;
108 for (uint64 i = 0; i < sdp_result_data->lpBlob->cbSize; i++) { 130 for (uint64 i = 0; i < sdp_result_data->lpBlob->cbSize; i++) {
109 service_record_state->sdp_bytes.push_back( 131 service_record_state->sdp_bytes.push_back(
110 sdp_result_data->lpBlob->pBlobData[i]); 132 sdp_result_data->lpBlob->pBlobData[i]);
111 } 133 }
112 service_record_states->push_back(service_record_state); 134 service_record_states->push_back(service_record_state);
113 } 135 }
114 WSALookupServiceEnd(sdp_handle); 136 WSALookupServiceEnd(sdp_handle);
115 } 137 }
116 138
117 } // namespace 139 } // namespace
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 ++iter) { 425 ++iter) {
404 win::BluetoothLowEnergyDeviceInfo* device_info = (*iter); 426 win::BluetoothLowEnergyDeviceInfo* device_info = (*iter);
405 427
406 DeviceState* device_state = new DeviceState(); 428 DeviceState* device_state = new DeviceState();
407 device_state->name = device_info->friendly_name; 429 device_state->name = device_info->friendly_name;
408 device_state->address = BluetoothAddressToString(device_info->address); 430 device_state->address = BluetoothAddressToString(device_info->address);
409 device_state->visible = device_info->visible; 431 device_state->visible = device_info->visible;
410 device_state->authenticated = device_info->authenticated; 432 device_state->authenticated = device_info->authenticated;
411 device_state->connected = device_info->connected; 433 device_state->connected = device_info->connected;
412 device_state->path = device_info->path; 434 device_state->path = device_info->path;
435
436 ScopedVector<win::BluetoothLowEnergyServiceInfo> services;
437 success = win::EnumerateKnownBluetoothLowEnergyServices(
438 device_info, &services, &error);
439 if (success) {
440 for (ScopedVector<win::BluetoothLowEnergyServiceInfo>::iterator
441 iter2 = services.begin();
442 iter2 != services.end();
443 ++iter2) {
444 ServiceRecordState* service_state = new ServiceRecordState();
445 service_state->gatt_uuid =
446 BluetoothLowEnergyUuidToUBluetoothUuid((*iter2)->uuid);
447 device_state->service_record_states.push_back(service_state);
448 }
449 }
413 device_list->push_back(device_state); 450 device_list->push_back(device_state);
414 } 451 }
415 } 452 }
416 } 453 }
417 454
418 if (device_list->empty()) { 455 if (device_list->empty()) {
419 delete device_list; 456 delete device_list;
420 return; 457 return;
421 } 458 }
422 DiscoverServices(device_list); 459 DiscoverServices(device_list);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 const std::string device_address = (*iter)->address; 504 const std::string device_address = (*iter)->address;
468 ScopedVector<ServiceRecordState>* service_record_states = 505 ScopedVector<ServiceRecordState>* service_record_states =
469 &(*iter)->service_record_states; 506 &(*iter)->service_record_states;
470 507
471 DiscoverDeviceServices( 508 DiscoverDeviceServices(
472 device_address, L2CAP_PROTOCOL_UUID, service_record_states); 509 device_address, L2CAP_PROTOCOL_UUID, service_record_states);
473 } 510 }
474 } 511 }
475 512
476 } // namespace device 513 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_task_manager_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698