Index: device/bluetooth/bluetooth_low_energy_win.cc |
diff --git a/device/bluetooth/bluetooth_low_energy_win.cc b/device/bluetooth/bluetooth_low_energy_win.cc |
index 3e2c7c2a900a0c387bcb73b261545dc5d2ba8037..e4e7ad2d7dc5afd7b3013fd67528cc75234edd03 100644 |
--- a/device/bluetooth/bluetooth_low_energy_win.cc |
+++ b/device/bluetooth/bluetooth_low_energy_win.cc |
@@ -794,5 +794,53 @@ HRESULT BluetoothLowEnergyWrapper::ReadDescriptorsOfACharacteristic( |
return hr; |
} |
+HRESULT BluetoothLowEnergyWrapper::ReadTheValueOfACharacteristic( |
+ base::FilePath& service_path, |
+ const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
+ scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>* out_value) { |
+ base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
+ if (!file.IsValid()) |
+ return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); |
+ |
+ USHORT required_length = 0; |
+ HRESULT hr = BluetoothGATTGetCharacteristicValue( |
+ file.GetPlatformFile(), characteristic, 0, NULL, &required_length, |
+ BLUETOOTH_GATT_FLAG_NONE); |
+ if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA)) |
+ return hr; |
+ |
+ out_value->reset( |
+ (PBTH_LE_GATT_CHARACTERISTIC_VALUE)(new UCHAR[required_length])); |
+ USHORT actual_length = required_length; |
+ hr = BluetoothGATTGetCharacteristicValue( |
+ file.GetPlatformFile(), characteristic, (ULONG)required_length, |
+ out_value->get(), &actual_length, BLUETOOTH_GATT_FLAG_NONE); |
+ if (SUCCEEDED(hr) && required_length != actual_length) { |
+ LOG(ERROR) << "Retrieved characteristic value size is not equal to expected" |
+ << " actual_length " << actual_length << " required_length " |
+ << required_length; |
+ hr = HRESULT_FROM_WIN32(ERROR_INVALID_USER_BUFFER); |
+ } |
+ |
+ if (FAILED(hr)) { |
+ out_value->reset(nullptr); |
+ } |
+ return hr; |
+} |
+ |
+HRESULT BluetoothLowEnergyWrapper::WriteTheValueOfACharacteristic( |
+ base::FilePath& service_path, |
+ const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
+ PBTH_LE_GATT_CHARACTERISTIC_VALUE new_value) { |
+ base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ | |
+ base::File::FLAG_WRITE); |
+ if (!file.IsValid()) |
+ return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); |
+ |
+ return BluetoothGATTSetCharacteristicValue(file.GetPlatformFile(), |
+ characteristic, new_value, NULL, |
+ BLUETOOTH_GATT_FLAG_NONE); |
+} |
+ |
} // namespace win |
} // namespace device |