Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_low_energy_win.h" | 5 #include "device/bluetooth/bluetooth_low_energy_win.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 // Windows 8 exposes BLE devices only if they are visible and paired. This | 365 // Windows 8 exposes BLE devices only if they are visible and paired. This |
| 366 // might change in the future if Windows offers a public API for discovering | 366 // might change in the future if Windows offers a public API for discovering |
| 367 // and pairing BLE devices. | 367 // and pairing BLE devices. |
| 368 device_info->visible = true; | 368 device_info->visible = true; |
| 369 device_info->authenticated = true; | 369 device_info->authenticated = true; |
| 370 return true; | 370 return true; |
| 371 } | 371 } |
| 372 | 372 |
| 373 bool CollectBluetoothLowEnergyDeviceServices( | 373 bool CollectBluetoothLowEnergyDeviceServices( |
| 374 const base::FilePath& device_path, | 374 const base::FilePath& device_path, |
| 375 ScopedVector<BluetoothLowEnergyServiceInfo>* services, | 375 std::vector<std::unique_ptr<BluetoothLowEnergyServiceInfo>>* services, |
| 376 std::string* error) { | 376 std::string* error) { |
| 377 base::File file(device_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 377 base::File file(device_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 378 if (!file.IsValid()) { | 378 if (!file.IsValid()) { |
| 379 *error = file.ErrorToString(file.error_details()); | 379 *error = file.ErrorToString(file.error_details()); |
| 380 return false; | 380 return false; |
| 381 } | 381 } |
| 382 | 382 |
| 383 USHORT required_length; | 383 USHORT required_length; |
| 384 HRESULT hr = BluetoothGATTGetServices(file.GetPlatformFile(), | 384 HRESULT hr = BluetoothGATTGetServices(file.GetPlatformFile(), |
| 385 0, | 385 0, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 401 BLUETOOTH_GATT_FLAG_NONE); | 401 BLUETOOTH_GATT_FLAG_NONE); |
| 402 if (!CheckHResult(hr, kDeviceInfoError, error)) | 402 if (!CheckHResult(hr, kDeviceInfoError, error)) |
| 403 return false; | 403 return false; |
| 404 if (!CheckExpectedLength( | 404 if (!CheckExpectedLength( |
| 405 actual_length, required_length, kDeviceInfoError, error)) { | 405 actual_length, required_length, kDeviceInfoError, error)) { |
| 406 return false; | 406 return false; |
| 407 } | 407 } |
| 408 | 408 |
| 409 for (USHORT i = 0; i < actual_length; ++i) { | 409 for (USHORT i = 0; i < actual_length; ++i) { |
| 410 BTH_LE_GATT_SERVICE& gatt_service(gatt_services.get()[i]); | 410 BTH_LE_GATT_SERVICE& gatt_service(gatt_services.get()[i]); |
| 411 BluetoothLowEnergyServiceInfo* service_info = | 411 std::unique_ptr<BluetoothLowEnergyServiceInfo> service_info( |
| 412 new BluetoothLowEnergyServiceInfo(); | 412 new BluetoothLowEnergyServiceInfo()); |
| 413 service_info->uuid = gatt_service.ServiceUuid; | 413 service_info->uuid = gatt_service.ServiceUuid; |
| 414 service_info->attribute_handle = gatt_service.AttributeHandle; | 414 service_info->attribute_handle = gatt_service.AttributeHandle; |
| 415 services->push_back(service_info); | 415 services->push_back(std::move(service_info)); |
| 416 } | 416 } |
| 417 | 417 |
| 418 return true; | 418 return true; |
| 419 } | 419 } |
| 420 | 420 |
| 421 bool CollectBluetoothLowEnergyDeviceInfo( | 421 bool CollectBluetoothLowEnergyDeviceInfo( |
| 422 const ScopedDeviceInfoSetHandle& device_info_handle, | 422 const ScopedDeviceInfoSetHandle& device_info_handle, |
| 423 PSP_DEVICE_INTERFACE_DATA device_interface_data, | 423 PSP_DEVICE_INTERFACE_DATA device_interface_data, |
| 424 std::unique_ptr<device::win::BluetoothLowEnergyDeviceInfo>* device_info, | 424 std::unique_ptr<device::win::BluetoothLowEnergyDeviceInfo>* device_info, |
| 425 std::string* error) { | 425 std::string* error) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 } | 535 } |
| 536 | 536 |
| 537 // Enumerate known Bluetooth low energy devices or Bluetooth low energy GATT | 537 // Enumerate known Bluetooth low energy devices or Bluetooth low energy GATT |
| 538 // service devices according to |device_interface_guid|. | 538 // service devices according to |device_interface_guid|. |
| 539 // Note: |device_interface_guid| = GUID_BLUETOOTHLE_DEVICE_INTERFACE corresponds | 539 // Note: |device_interface_guid| = GUID_BLUETOOTHLE_DEVICE_INTERFACE corresponds |
| 540 // Bluetooth low energy devices. |device_interface_guid| = | 540 // Bluetooth low energy devices. |device_interface_guid| = |
| 541 // GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE corresponds Bluetooth low energy | 541 // GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE corresponds Bluetooth low energy |
| 542 // Gatt service devices. | 542 // Gatt service devices. |
| 543 bool EnumerateKnownBLEOrBLEGattServiceDevices( | 543 bool EnumerateKnownBLEOrBLEGattServiceDevices( |
| 544 GUID guid, | 544 GUID guid, |
| 545 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 545 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices, |
| 546 std::string* error) { | 546 std::string* error) { |
| 547 ScopedDeviceInfoSetHandle info_set_handle; | 547 ScopedDeviceInfoSetHandle info_set_handle; |
| 548 HRESULT hr = OpenBluetoothLowEnergyDevices(guid, &info_set_handle); | 548 HRESULT hr = OpenBluetoothLowEnergyDevices(guid, &info_set_handle); |
| 549 if (FAILED(hr)) { | 549 if (FAILED(hr)) { |
| 550 *error = FormatBluetoothError(kDeviceEnumError, hr); | 550 *error = FormatBluetoothError(kDeviceEnumError, hr); |
| 551 return false; | 551 return false; |
| 552 } | 552 } |
| 553 | 553 |
| 554 for (DWORD i = 0;; ++i) { | 554 for (DWORD i = 0;; ++i) { |
| 555 std::unique_ptr<BluetoothLowEnergyDeviceInfo> device_info; | 555 std::unique_ptr<BluetoothLowEnergyDeviceInfo> device_info; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 } | 671 } |
| 672 | 672 |
| 673 BluetoothLowEnergyWrapper::BluetoothLowEnergyWrapper() {} | 673 BluetoothLowEnergyWrapper::BluetoothLowEnergyWrapper() {} |
| 674 BluetoothLowEnergyWrapper::~BluetoothLowEnergyWrapper() {} | 674 BluetoothLowEnergyWrapper::~BluetoothLowEnergyWrapper() {} |
| 675 | 675 |
| 676 bool BluetoothLowEnergyWrapper::IsBluetoothLowEnergySupported() { | 676 bool BluetoothLowEnergyWrapper::IsBluetoothLowEnergySupported() { |
| 677 return base::win::GetVersion() >= base::win::VERSION_WIN8; | 677 return base::win::GetVersion() >= base::win::VERSION_WIN8; |
| 678 } | 678 } |
| 679 | 679 |
| 680 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyDevices( | 680 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyDevices( |
| 681 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 681 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices, |
| 682 | |
|
Reilly Grant (use Gerrit)
2016/12/21 22:25:14
stray newline?
dougt
2016/12/22 01:18:03
Done.
| |
| 682 std::string* error) { | 683 std::string* error) { |
| 683 if (!IsBluetoothLowEnergySupported()) { | 684 if (!IsBluetoothLowEnergySupported()) { |
| 684 *error = kPlatformNotSupported; | 685 *error = kPlatformNotSupported; |
| 685 return false; | 686 return false; |
| 686 } | 687 } |
| 687 | 688 |
| 688 return EnumerateKnownBLEOrBLEGattServiceDevices( | 689 return EnumerateKnownBLEOrBLEGattServiceDevices( |
| 689 GUID_BLUETOOTHLE_DEVICE_INTERFACE, devices, error); | 690 GUID_BLUETOOTHLE_DEVICE_INTERFACE, devices, error); |
| 690 } | 691 } |
| 691 | 692 |
| 692 bool BluetoothLowEnergyWrapper:: | 693 bool BluetoothLowEnergyWrapper:: |
| 693 EnumerateKnownBluetoothLowEnergyGattServiceDevices( | 694 EnumerateKnownBluetoothLowEnergyGattServiceDevices( |
| 694 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 695 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices, |
| 696 | |
|
Reilly Grant (use Gerrit)
2016/12/21 22:25:14
stray newline?
dougt
2016/12/22 01:18:03
Done.
| |
| 695 std::string* error) { | 697 std::string* error) { |
| 696 if (!IsBluetoothLowEnergySupported()) { | 698 if (!IsBluetoothLowEnergySupported()) { |
| 697 *error = kPlatformNotSupported; | 699 *error = kPlatformNotSupported; |
| 698 return false; | 700 return false; |
| 699 } | 701 } |
| 700 | 702 |
| 701 return EnumerateKnownBLEOrBLEGattServiceDevices( | 703 return EnumerateKnownBLEOrBLEGattServiceDevices( |
| 702 GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE, devices, error); | 704 GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE, devices, error); |
| 703 } | 705 } |
| 704 | 706 |
| 705 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyServices( | 707 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyServices( |
| 706 const base::FilePath& device_path, | 708 const base::FilePath& device_path, |
| 707 ScopedVector<BluetoothLowEnergyServiceInfo>* services, | 709 std::vector<std::unique_ptr<BluetoothLowEnergyServiceInfo>>* services, |
| 710 | |
|
Reilly Grant (use Gerrit)
2016/12/21 22:25:14
stray newline?
dougt
2016/12/22 01:18:03
Done.
| |
| 708 std::string* error) { | 711 std::string* error) { |
| 709 if (!IsBluetoothLowEnergySupported()) { | 712 if (!IsBluetoothLowEnergySupported()) { |
| 710 *error = kPlatformNotSupported; | 713 *error = kPlatformNotSupported; |
| 711 return false; | 714 return false; |
| 712 } | 715 } |
| 713 | 716 |
| 714 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error); | 717 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error); |
| 715 } | 718 } |
| 716 | 719 |
| 717 HRESULT BluetoothLowEnergyWrapper::ReadCharacteristicsOfAService( | 720 HRESULT BluetoothLowEnergyWrapper::ReadCharacteristicsOfAService( |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ | | 867 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 865 base::File::FLAG_WRITE); | 868 base::File::FLAG_WRITE); |
| 866 if (!file.IsValid()) | 869 if (!file.IsValid()) |
| 867 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); | 870 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); |
| 868 return BluetoothGATTSetDescriptorValue(file.GetPlatformFile(), descriptor, | 871 return BluetoothGATTSetDescriptorValue(file.GetPlatformFile(), descriptor, |
| 869 new_value, BLUETOOTH_GATT_FLAG_NONE); | 872 new_value, BLUETOOTH_GATT_FLAG_NONE); |
| 870 } | 873 } |
| 871 | 874 |
| 872 } // namespace win | 875 } // namespace win |
| 873 } // namespace device | 876 } // namespace device |
| OLD | NEW |