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

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: Add bug for CCC descriptor 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 };
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
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
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.
palmer 2016/06/27 19:25:42 These 2 comment lines don't seem to agree — it's u
puthik_chromium 2016/06/27 19:55:07 Done.
932 // TODO(http://crbug.com/622832)
933 if (descriptor->GetUUID() ==
934 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()) {
935 OnGattWriteDone(callback);
936 return;
937 }
938
905 descriptor->WriteRemoteDescriptor( 939 descriptor->WriteRemoteDescriptor(
906 value->value.To<std::vector<uint8_t>>(), 940 value->value.To<std::vector<uint8_t>>(),
907 base::Bind(&ArcBluetoothBridge::OnGattWriteDone, 941 base::Bind(&ArcBluetoothBridge::OnGattWriteDone,
908 weak_factory_.GetWeakPtr(), callback), 942 weak_factory_.GetWeakPtr(), callback),
909 base::Bind(&ArcBluetoothBridge::OnGattWriteError, 943 base::Bind(&ArcBluetoothBridge::OnGattWriteError,
910 weak_factory_.GetWeakPtr(), callback)); 944 weak_factory_.GetWeakPtr(), callback));
911 } 945 }
912 946
913 void ArcBluetoothBridge::OnGattNotifyStartDone( 947 void ArcBluetoothBridge::OnGattNotifyStartDone(
914 const RegisterForGattNotificationCallback& callback, 948 const RegisterForGattNotificationCallback& callback,
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 // to 1346 // to
1313 // make sure the bond state machine on Android is ready to take the 1347 // 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 1348 // pair-done event. Otherwise the pair-done event will be dropped as an
1315 // invalid change of paired status. 1349 // invalid change of paired status.
1316 OnPairing(addr->Clone()); 1350 OnPairing(addr->Clone());
1317 OnPairedDone(std::move(addr)); 1351 OnPairedDone(std::move(addr));
1318 } 1352 }
1319 } 1353 }
1320 1354
1321 } // namespace arc 1355 } // 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