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

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2085083002: arc: bluetooth: Implement Gatt notify (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Workaround CCC descriptor write issue. Created 4 years, 6 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 | « no previous file | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 };
50 const std::string kDescriptorCCCUUid = "2902";
49 const uint32_t kGattReadPermission = 51 const uint32_t kGattReadPermission =
50 BluetoothGattCharacteristic::Permission::PERMISSION_READ | 52 BluetoothGattCharacteristic::Permission::PERMISSION_READ |
51 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | 53 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED |
52 BluetoothGattCharacteristic::Permission:: 54 BluetoothGattCharacteristic::Permission::
53 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; 55 PERMISSION_READ_ENCRYPTED_AUTHENTICATED;
54 const uint32_t kGattWritePermission = 56 const uint32_t kGattWritePermission =
55 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | 57 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE |
56 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | 58 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED |
57 BluetoothGattCharacteristic::Permission:: 59 BluetoothGattCharacteristic::Permission::
58 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; 60 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 void ArcBluetoothBridge::GattDescriptorRemoved( 252 void ArcBluetoothBridge::GattDescriptorRemoved(
251 BluetoothAdapter* adapter, 253 BluetoothAdapter* adapter,
252 BluetoothRemoteGattDescriptor* descriptor) { 254 BluetoothRemoteGattDescriptor* descriptor) {
253 // Placeholder for GATT client functionality 255 // Placeholder for GATT client functionality
254 } 256 }
255 257
256 void ArcBluetoothBridge::GattCharacteristicValueChanged( 258 void ArcBluetoothBridge::GattCharacteristicValueChanged(
257 BluetoothAdapter* adapter, 259 BluetoothAdapter* adapter,
258 BluetoothRemoteGattCharacteristic* characteristic, 260 BluetoothRemoteGattCharacteristic* characteristic,
259 const std::vector<uint8_t>& value) { 261 const std::vector<uint8_t>& value) {
260 // Placeholder for GATT client functionality 262 if (!HasBluetoothInstance())
263 return;
264
265 if (arc_bridge_service()->bluetooth_version() < kMinBtleNotifyVersion) {
266 LOG(WARNING) << "Bluetooth instance is too old and does not support notify";
267 return;
268 }
269 BluetoothRemoteGattService* service = characteristic->GetService();
270 BluetoothDevice* device = service->GetDevice();
271 mojom::BluetoothAddressPtr address =
272 mojom::BluetoothAddress::From(device->GetAddress());
273 mojom::BluetoothGattServiceIDPtr service_id =
274 mojom::BluetoothGattServiceID::New();
275 service_id->is_primary = service->IsPrimary();
276 service_id->id = mojom::BluetoothGattID::New();
277 service_id->id->inst_id = ConvertGattIdentifierToId(service->GetIdentifier());
278 service_id->id->uuid = mojom::BluetoothUUID::From(service->GetUUID());
279
280 mojom::BluetoothGattIDPtr char_id = mojom::BluetoothGattID::New();
281 char_id->inst_id = ConvertGattIdentifierToId(characteristic->GetIdentifier());
282 char_id->uuid = mojom::BluetoothUUID::From(characteristic->GetUUID());
283
284 arc_bridge_service()->bluetooth_instance()->OnGattNotify(
285 std::move(address), std::move(service_id), std::move(char_id),
286 true /* is_notify */, mojo::Array<uint8_t>::From(value));
261 } 287 }
262 288
263 void ArcBluetoothBridge::GattDescriptorValueChanged( 289 void ArcBluetoothBridge::GattDescriptorValueChanged(
264 BluetoothAdapter* adapter, 290 BluetoothAdapter* adapter,
265 BluetoothRemoteGattDescriptor* descriptor, 291 BluetoothRemoteGattDescriptor* descriptor,
266 const std::vector<uint8_t>& value) { 292 const std::vector<uint8_t>& value) {
267 // Placeholder for GATT client functionality 293 // Placeholder for GATT client functionality
268 } 294 }
269 295
270 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) { 296 void ArcBluetoothBridge::EnableAdapter(const EnableAdapterCallback& callback) {
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 mojom::BluetoothGattIDPtr char_id, 921 mojom::BluetoothGattIDPtr char_id,
896 mojom::BluetoothGattIDPtr desc_id, 922 mojom::BluetoothGattIDPtr desc_id,
897 mojom::BluetoothGattValuePtr value, 923 mojom::BluetoothGattValuePtr value,
898 const WriteGattDescriptorCallback& callback) { 924 const WriteGattDescriptorCallback& callback) {
899 BluetoothRemoteGattDescriptor* descriptor = 925 BluetoothRemoteGattDescriptor* descriptor =
900 FindGattDescriptor(std::move(remote_addr), std::move(service_id), 926 FindGattDescriptor(std::move(remote_addr), std::move(service_id),
901 std::move(char_id), std::move(desc_id)); 927 std::move(char_id), std::move(desc_id));
902 DCHECK(descriptor); 928 DCHECK(descriptor);
903 DCHECK(descriptor->GetPermissions() & kGattWritePermission); 929 DCHECK(descriptor->GetPermissions() & kGattWritePermission);
904 930
931 // Chrome does not support writing to CCC Descriptor
932 // Always return success when encounter this.
933 // The descriptor UUID should match the format below for this.
934 // xxxx2902-xxxx-xxxx-xxxx-xxxxxxxxxxxx
935 if (descriptor->GetUUID().canonical_value().substr(4, 4) ==
ortuno 2016/06/23 14:29:38 nit: Also add this change to the description.
puthik_chromium 2016/06/23 18:36:31 Done.
936 kDescriptorCCCUUid) {
ortuno 2016/06/23 14:29:38 Use BluetoothRemoteGattDescriptor::ClientCharacter
puthik_chromium 2016/06/23 18:36:30 Done.
937 OnGattWriteDone(callback);
938 return;
939 }
940
905 descriptor->WriteRemoteDescriptor( 941 descriptor->WriteRemoteDescriptor(
906 value->value.To<std::vector<uint8_t>>(), 942 value->value.To<std::vector<uint8_t>>(),
907 base::Bind(&ArcBluetoothBridge::OnGattWriteDone, 943 base::Bind(&ArcBluetoothBridge::OnGattWriteDone,
908 weak_factory_.GetWeakPtr(), callback), 944 weak_factory_.GetWeakPtr(), callback),
909 base::Bind(&ArcBluetoothBridge::OnGattWriteError, 945 base::Bind(&ArcBluetoothBridge::OnGattWriteError,
910 weak_factory_.GetWeakPtr(), callback)); 946 weak_factory_.GetWeakPtr(), callback));
911 } 947 }
912 948
913 void ArcBluetoothBridge::OnGattNotifyStartDone( 949 void ArcBluetoothBridge::OnGattNotifyStartDone(
914 const RegisterForGattNotificationCallback& callback, 950 const RegisterForGattNotificationCallback& callback,
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 // to 1348 // to
1313 // make sure the bond state machine on Android is ready to take the 1349 // 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 1350 // pair-done event. Otherwise the pair-done event will be dropped as an
1315 // invalid change of paired status. 1351 // invalid change of paired status.
1316 OnPairing(addr->Clone()); 1352 OnPairing(addr->Clone());
1317 OnPairedDone(std::move(addr)); 1353 OnPairedDone(std::move(addr));
1318 } 1354 }
1319 } 1355 }
1320 1356
1321 } // namespace arc 1357 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698