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

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: 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
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 28 matching lines...) Expand all
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 const int kMinBtleVersion = 1;
49 const int kMinBtleNotifyVersion = 2;
ortuno 2016/06/21 23:23:06 enum { kMinBtleNotifyVersion = 2 }; Context: http
puthik_chromium 2016/06/23 02:53:34 Done.
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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 BluetoothRemoteGattDescriptor* descriptor) { 247 BluetoothRemoteGattDescriptor* descriptor) {
247 // Placeholder for GATT client functionality 248 // Placeholder for GATT client functionality
248 } 249 }
249 250
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(
ortuno 2016/06/21 20:21:29 FYI: this function gets called when reading values
puthik_chromium 2016/06/23 02:53:34 Android side is not expect that. But it should be
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 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 const RegisterForGattNotificationCallback& callback, 947 const RegisterForGattNotificationCallback& callback,
923 BluetoothGattService::GattErrorCode error_code) const { 948 BluetoothGattService::GattErrorCode error_code) const {
924 callback.Run(mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code)); 949 callback.Run(mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code));
925 } 950 }
926 951
927 void ArcBluetoothBridge::OnGattNotifyStopDone( 952 void ArcBluetoothBridge::OnGattNotifyStopDone(
928 const DeregisterForGattNotificationCallback& callback) const { 953 const DeregisterForGattNotificationCallback& callback) const {
929 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); 954 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
930 } 955 }
931 956
932 void ArcBluetoothBridge::RegisterForGattNotification( 957 void ArcBluetoothBridge::RegisterForGattNotification(
ortuno 2016/06/21 23:23:06 Does calling setCharacteristicNotification()[1] re
puthik_chromium 2016/06/23 02:53:34 Thank you for pointing this out. Since the CCC is
ortuno 2016/06/23 14:29:38 Developers will write to the CCC to stop notificat
puthik_chromium 2016/06/23 18:36:30 Q1 Developers will write to the CCC to stop notifi
ortuno 2016/06/23 19:13:54 Does this mean a call to setCharacteristicNotifica
933 mojom::BluetoothAddressPtr remote_addr, 958 mojom::BluetoothAddressPtr remote_addr,
934 mojom::BluetoothGattServiceIDPtr service_id, 959 mojom::BluetoothGattServiceIDPtr service_id,
935 mojom::BluetoothGattIDPtr char_id, 960 mojom::BluetoothGattIDPtr char_id,
936 const RegisterForGattNotificationCallback& callback) { 961 const RegisterForGattNotificationCallback& callback) {
937 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 962 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
938 std::move(remote_addr), std::move(service_id), std::move(char_id)); 963 std::move(remote_addr), std::move(service_id), std::move(char_id));
939 964
940 if (!characteristic) { 965 if (!characteristic) {
941 LOG(WARNING) << __func__ << " Characteristic is not existed."; 966 LOG(WARNING) << __func__ << " Characteristic is not existed.";
942 return; 967 return;
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 // to 1337 // to
1313 // make sure the bond state machine on Android is ready to take the 1338 // 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 1339 // pair-done event. Otherwise the pair-done event will be dropped as an
1315 // invalid change of paired status. 1340 // invalid change of paired status.
1316 OnPairing(addr->Clone()); 1341 OnPairing(addr->Clone());
1317 OnPairedDone(std::move(addr)); 1342 OnPairedDone(std::move(addr));
1318 } 1343 }
1319 } 1344 }
1320 1345
1321 } // namespace arc 1346 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | components/arc/common/bluetooth.mojom » ('j') | components/arc/common/bluetooth.mojom » ('J')

Powered by Google App Engine
This is Rietveld 408576698