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 "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 hr = HRESULT_FROM_WIN32(ERROR_INVALID_USER_BUFFER); | 782 hr = HRESULT_FROM_WIN32(ERROR_INVALID_USER_BUFFER); |
783 } | 783 } |
784 | 784 |
785 if (FAILED(hr)) { | 785 if (FAILED(hr)) { |
786 out_included_descriptors->reset(nullptr); | 786 out_included_descriptors->reset(nullptr); |
787 *out_counts = 0; | 787 *out_counts = 0; |
788 } | 788 } |
789 return hr; | 789 return hr; |
790 } | 790 } |
791 | 791 |
| 792 HRESULT BluetoothLowEnergyWrapper::ReadCharacteristicValue( |
| 793 base::FilePath& service_path, |
| 794 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 795 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>* out_value) { |
| 796 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 797 if (!file.IsValid()) |
| 798 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); |
| 799 |
| 800 USHORT allocated_length = 0; |
| 801 HRESULT hr = BluetoothGATTGetCharacteristicValue( |
| 802 file.GetPlatformFile(), characteristic, 0, NULL, &allocated_length, |
| 803 BLUETOOTH_GATT_FLAG_NONE); |
| 804 if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA)) |
| 805 return hr; |
| 806 |
| 807 out_value->reset( |
| 808 (PBTH_LE_GATT_CHARACTERISTIC_VALUE)(new UCHAR[allocated_length])); |
| 809 USHORT out_length = 0; |
| 810 hr = BluetoothGATTGetCharacteristicValue( |
| 811 file.GetPlatformFile(), characteristic, (ULONG)allocated_length, |
| 812 out_value->get(), &out_length, BLUETOOTH_GATT_FLAG_NONE); |
| 813 if (SUCCEEDED(hr) && allocated_length != out_length) { |
| 814 LOG(ERROR) << "Retrieved characteristic value size is not equal to expected" |
| 815 << " allocated_length " << allocated_length << " got " |
| 816 << out_length; |
| 817 hr = HRESULT_FROM_WIN32(ERROR_INVALID_USER_BUFFER); |
| 818 } |
| 819 |
| 820 if (FAILED(hr)) { |
| 821 out_value->reset(nullptr); |
| 822 } |
| 823 return hr; |
| 824 } |
| 825 |
| 826 HRESULT BluetoothLowEnergyWrapper::WriteCharacteristicValue( |
| 827 base::FilePath& service_path, |
| 828 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 829 PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) { |
| 830 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 831 base::File::FLAG_WRITE); |
| 832 if (!file.IsValid()) |
| 833 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); |
| 834 |
| 835 return BluetoothGATTSetCharacteristicValue(file.GetPlatformFile(), |
| 836 characteristic, new_value, NULL, |
| 837 BLUETOOTH_GATT_FLAG_NONE); |
| 838 } |
| 839 |
792 } // namespace win | 840 } // namespace win |
793 } // namespace device | 841 } // namespace device |
OLD | NEW |