Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/arc/bluetooth/arc_bluetooth_bridge.h" | 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iomanip> | 10 #include <iomanip> |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 using device::BluetoothGattNotifySession; | 38 using device::BluetoothGattNotifySession; |
| 39 using device::BluetoothGattCharacteristic; | 39 using device::BluetoothGattCharacteristic; |
| 40 using device::BluetoothGattDescriptor; | 40 using device::BluetoothGattDescriptor; |
| 41 using device::BluetoothGattService; | 41 using device::BluetoothGattService; |
| 42 using device::BluetoothRemoteGattCharacteristic; | 42 using device::BluetoothRemoteGattCharacteristic; |
| 43 using device::BluetoothRemoteGattDescriptor; | 43 using device::BluetoothRemoteGattDescriptor; |
| 44 using device::BluetoothRemoteGattService; | 44 using device::BluetoothRemoteGattService; |
| 45 using device::BluetoothUUID; | 45 using device::BluetoothUUID; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 const int kMinBtleVersion = 1; | 48 enum { kMinBtleVersion = 1 }; |
| 49 enum { kMinBtleNotifyVersion = 2 }; | |
| 49 const uint32_t kGattReadPermission = | 50 const uint32_t kGattReadPermission = |
| 50 BluetoothGattCharacteristic::Permission::PERMISSION_READ | | 51 BluetoothGattCharacteristic::Permission::PERMISSION_READ | |
| 51 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | | 52 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | |
| 52 BluetoothGattCharacteristic::Permission:: | 53 BluetoothGattCharacteristic::Permission:: |
| 53 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; | 54 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; |
| 54 const uint32_t kGattWritePermission = | 55 const uint32_t kGattWritePermission = |
| 55 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | | 56 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | |
| 56 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | | 57 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | |
| 57 BluetoothGattCharacteristic::Permission:: | 58 BluetoothGattCharacteristic::Permission:: |
| 58 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; | 59 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 void ArcBluetoothBridge::GattDescriptorRemoved( | 251 void ArcBluetoothBridge::GattDescriptorRemoved( |
| 251 BluetoothAdapter* adapter, | 252 BluetoothAdapter* adapter, |
| 252 BluetoothRemoteGattDescriptor* descriptor) { | 253 BluetoothRemoteGattDescriptor* descriptor) { |
| 253 // Placeholder for GATT client functionality | 254 // Placeholder for GATT client functionality |
| 254 } | 255 } |
| 255 | 256 |
| 256 void ArcBluetoothBridge::GattCharacteristicValueChanged( | 257 void ArcBluetoothBridge::GattCharacteristicValueChanged( |
| 257 BluetoothAdapter* adapter, | 258 BluetoothAdapter* adapter, |
| 258 BluetoothRemoteGattCharacteristic* characteristic, | 259 BluetoothRemoteGattCharacteristic* characteristic, |
| 259 const std::vector<uint8_t>& value) { | 260 const std::vector<uint8_t>& value) { |
| 260 // Placeholder for GATT client functionality | 261 if (!HasBluetoothInstance()) |
| 262 return; | |
| 263 | |
| 264 if (arc_bridge_service()->bluetooth_version() < kMinBtleNotifyVersion) { | |
| 265 LOG(WARNING) << "Bluetooth instance is too old and does not support notify"; | |
| 266 return; | |
| 267 } | |
| 268 BluetoothRemoteGattService* service = characteristic->GetService(); | |
| 269 BluetoothDevice* device = service->GetDevice(); | |
| 270 mojom::BluetoothAddressPtr address = | |
| 271 mojom::BluetoothAddress::From(device->GetAddress()); | |
| 272 mojom::BluetoothGattServiceIDPtr service_id = | |
| 273 mojom::BluetoothGattServiceID::New(); | |
| 274 service_id->is_primary = service->IsPrimary(); | |
| 275 service_id->id = mojom::BluetoothGattID::New(); | |
| 276 service_id->id->inst_id = ConvertGattIdentifierToId(service->GetIdentifier()); | |
| 277 service_id->id->uuid = mojom::BluetoothUUID::From(service->GetUUID()); | |
| 278 | |
| 279 mojom::BluetoothGattIDPtr char_id = mojom::BluetoothGattID::New(); | |
| 280 char_id->inst_id = ConvertGattIdentifierToId(characteristic->GetIdentifier()); | |
| 281 char_id->uuid = mojom::BluetoothUUID::From(characteristic->GetUUID()); | |
| 282 | |
| 283 arc_bridge_service()->bluetooth_instance()->OnGattNotify( | |
| 284 std::move(address), std::move(service_id), std::move(char_id), | |
| 285 true /* is_notify */, mojo::Array<uint8_t>::From(value)); | |
| 261 } | 286 } |
| 262 | 287 |
| 263 void ArcBluetoothBridge::GattDescriptorValueChanged( | 288 void ArcBluetoothBridge::GattDescriptorValueChanged( |
| 264 BluetoothAdapter* adapter, | 289 BluetoothAdapter* adapter, |
| 265 BluetoothRemoteGattDescriptor* descriptor, | 290 BluetoothRemoteGattDescriptor* descriptor, |
| 266 const std::vector<uint8_t>& value) { | 291 const std::vector<uint8_t>& value) { |
| 267 // Placeholder for GATT client functionality | 292 // Placeholder for GATT client functionality |
| 268 } | 293 } |
| 269 | 294 |
| 270 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) { | 295 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) { |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 mojom::BluetoothGattIDPtr char_id, | 920 mojom::BluetoothGattIDPtr char_id, |
| 896 mojom::BluetoothGattIDPtr desc_id, | 921 mojom::BluetoothGattIDPtr desc_id, |
| 897 mojom::BluetoothGattValuePtr value, | 922 mojom::BluetoothGattValuePtr value, |
| 898 const WriteGattDescriptorCallback& callback) { | 923 const WriteGattDescriptorCallback& callback) { |
| 899 BluetoothRemoteGattDescriptor* descriptor = | 924 BluetoothRemoteGattDescriptor* descriptor = |
| 900 FindGattDescriptor(std::move(remote_addr), std::move(service_id), | 925 FindGattDescriptor(std::move(remote_addr), std::move(service_id), |
| 901 std::move(char_id), std::move(desc_id)); | 926 std::move(char_id), std::move(desc_id)); |
| 902 DCHECK(descriptor); | 927 DCHECK(descriptor); |
| 903 DCHECK(descriptor->GetPermissions() & kGattWritePermission); | 928 DCHECK(descriptor->GetPermissions() & kGattWritePermission); |
| 904 | 929 |
| 930 // Chrome does not support writing to CCC Descriptor | |
| 931 // Always return success when encounter this. | |
| 932 if (descriptor->GetUUID() == | |
|
rkc
2016/06/23 19:36:38
This is definitely going to break behavior in some
| |
| 933 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()) { | |
| 934 OnGattWriteDone(callback); | |
| 935 return; | |
| 936 } | |
| 937 | |
| 905 descriptor->WriteRemoteDescriptor( | 938 descriptor->WriteRemoteDescriptor( |
| 906 value->value.To<std::vector<uint8_t>>(), | 939 value->value.To<std::vector<uint8_t>>(), |
| 907 base::Bind(&ArcBluetoothBridge::OnGattWriteDone, | 940 base::Bind(&ArcBluetoothBridge::OnGattWriteDone, |
| 908 weak_factory_.GetWeakPtr(), callback), | 941 weak_factory_.GetWeakPtr(), callback), |
| 909 base::Bind(&ArcBluetoothBridge::OnGattWriteError, | 942 base::Bind(&ArcBluetoothBridge::OnGattWriteError, |
| 910 weak_factory_.GetWeakPtr(), callback)); | 943 weak_factory_.GetWeakPtr(), callback)); |
| 911 } | 944 } |
| 912 | 945 |
| 913 void ArcBluetoothBridge::OnGattNotifyStartDone( | 946 void ArcBluetoothBridge::OnGattNotifyStartDone( |
| 914 const RegisterForGattNotificationCallback& callback, | 947 const RegisterForGattNotificationCallback& callback, |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1312 // to | 1345 // to |
| 1313 // make sure the bond state machine on Android is ready to take the | 1346 // make sure the bond state machine on Android is ready to take the |
| 1314 // pair-done event. Otherwise the pair-done event will be dropped as an | 1347 // pair-done event. Otherwise the pair-done event will be dropped as an |
| 1315 // invalid change of paired status. | 1348 // invalid change of paired status. |
| 1316 OnPairing(addr->Clone()); | 1349 OnPairing(addr->Clone()); |
| 1317 OnPairedDone(std::move(addr)); | 1350 OnPairedDone(std::move(addr)); |
| 1318 } | 1351 } |
| 1319 } | 1352 } |
| 1320 | 1353 |
| 1321 } // namespace arc | 1354 } // namespace arc |
| OLD | NEW |