Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // The <code>chrome.bluetoothLowEnergy</code> API is used to communicate with | 5 // The <code>chrome.bluetoothLowEnergy</code> API is used to communicate with |
| 6 // Bluetooth Smart (Low Energy) devices using the | 6 // Bluetooth Smart (Low Energy) devices using the |
| 7 // <a href="https://developer.bluetooth.org/TechnologyOverview/Pages/GATT.aspx"> | 7 // <a href="https://developer.bluetooth.org/TechnologyOverview/Pages/GATT.aspx"> |
| 8 // Generic Attribute Profile (GATT)</a>. | 8 // Generic Attribute Profile (GATT)</a>. |
| 9 namespace bluetoothLowEnergy { | 9 namespace bluetoothLowEnergy { |
| 10 | |
|
Devlin
2016/05/11 22:47:39
rm
rkc
2016/05/11 22:57:40
Done.
| |
| 10 // Values representing the possible properties of a characteristic. | 11 // Values representing the possible properties of a characteristic. |
| 11 enum CharacteristicProperty {broadcast, read, writeWithoutResponse, write, | 12 // Characteristic permissions are inferred from these properties. |
| 12 notify, indicate, authenticatedSignedWrites, | 13 // Please see the Bluetooth 4.x spec to see the meaning of each individual |
| 13 extendedProperties, reliableWrite, | 14 // property. |
| 14 writableAuxiliaries}; | 15 enum CharacteristicProperty { |
| 16 broadcast, read, writeWithoutResponse, write, notify, indicate, | |
| 17 authenticatedSignedWrites, extendedProperties, reliableWrite, | |
| 18 writableAuxiliaries, encryptRead, encryptWrite, encryptAuthenticatedRead, | |
| 19 encryptAuthenticatedWrite }; | |
|
Devlin
2016/05/11 22:47:39
put closing brace on newline (here and line 26)
rkc
2016/05/11 22:57:40
Done.
| |
| 20 | |
| 21 // Values representing possible permissions for a descriptor. | |
| 22 // Please see the Bluetooth 4.x spec to see the meaning of each individual | |
| 23 // permission. | |
| 24 enum DescriptorPermission { | |
| 25 read, write, encryptedRead, encryptedWrite, encryptedAuthenticatedRead, | |
| 26 encryptedAuthenticatedWrite }; | |
| 15 | 27 |
| 16 // Type of advertisement. If 'broadcast' is chosen, the sent advertisement | 28 // Type of advertisement. If 'broadcast' is chosen, the sent advertisement |
| 17 // type will be ADV_NONCONN_IND and the device will broadcast with a random | 29 // type will be ADV_NONCONN_IND and the device will broadcast with a random |
| 18 // MAC Address. If set to 'peripheral', the advertisement type will be | 30 // MAC Address. If set to 'peripheral', the advertisement type will be |
| 19 // ADV_IND or ADV_SCAN_IND and the device will broadcast with real Bluetooth | 31 // ADV_IND or ADV_SCAN_IND and the device will broadcast with real Bluetooth |
| 20 // Adapter's MAC Address. | 32 // Adapter's MAC Address. |
| 21 enum AdvertisementType {broadcast, peripheral}; | 33 enum AdvertisementType { broadcast, peripheral }; |
|
Devlin
2016/05/11 22:47:39
no need to do this
rkc
2016/05/11 22:57:40
Done.
| |
| 22 | 34 |
| 23 // Result of a register or unregister service call. | 35 // Result of a register or unregister service call. |
| 24 enum ServiceResult { | 36 enum ServiceResult { |
| 25 // The service operation was successful. | 37 // The service operation was successful. |
| 26 success, | 38 success, |
| 27 // The service that is being registered is already regsitered. | 39 // The service that is being registered is already regsitered. |
| 28 alreadyRegistered, | 40 alreadyRegistered, |
| 29 // The service that is being unregistered is not regsitered. | 41 // The service that is being unregistered is not regsitered. |
| 30 notRegistered | 42 notRegistered |
| 31 }; | 43 }; |
| 32 | 44 |
| 45 // Result of a character value changed notification request. | |
| 46 enum NotificationResult { | |
| 47 // The notification operation was successful. | |
| 48 success, | |
| 49 // This characteristic wasn't created with the notification property. | |
| 50 notifyPropertyNotSet, | |
|
Devlin
2016/05/11 22:47:39
Shouldn't these just be errors?
rkc
2016/05/11 22:57:40
Sure, no reason these have to be enums here.
Done.
| |
| 51 // The indicate flag was true but the property wasn't set on the | |
| 52 // characteristic. | |
| 53 indicatePropertyNotSet | |
| 54 }; | |
| 55 | |
| 33 // Represents a bluetooth central device that is connected to the local GATT | 56 // Represents a bluetooth central device that is connected to the local GATT |
| 34 // server. | 57 // server. |
| 35 dictionary Device { | 58 dictionary Device { |
| 36 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. | 59 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. |
| 37 DOMString address; | 60 DOMString address; |
| 38 | 61 |
| 39 // The human-readable name of the device. | 62 // The human-readable name of the device. |
| 40 DOMString? name; | 63 DOMString? name; |
| 41 | 64 |
| 42 // The class of the device, a bit-field defined by | 65 // The class of the device, a bit-field defined by |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 // Represents a GATT characteristic descriptor, which provides further | 116 // Represents a GATT characteristic descriptor, which provides further |
| 94 // information about a characteristic's value. | 117 // information about a characteristic's value. |
| 95 dictionary Descriptor { | 118 dictionary Descriptor { |
| 96 // The UUID of the characteristic descriptor, e.g. | 119 // The UUID of the characteristic descriptor, e.g. |
| 97 // 00002902-0000-1000-8000-00805f9b34fb. | 120 // 00002902-0000-1000-8000-00805f9b34fb. |
| 98 DOMString uuid; | 121 DOMString uuid; |
| 99 | 122 |
| 100 // The GATT characteristic this descriptor belongs to. | 123 // The GATT characteristic this descriptor belongs to. |
| 101 Characteristic? characteristic; | 124 Characteristic? characteristic; |
| 102 | 125 |
| 126 // The permissions of this descriptor. | |
| 127 DescriptorPermission[] permissions; | |
| 128 | |
| 103 // Returns the identifier assigned to this descriptor. Use the instance ID | 129 // Returns the identifier assigned to this descriptor. Use the instance ID |
| 104 // to distinguish between descriptors from a peripheral with the same UUID | 130 // to distinguish between descriptors from a peripheral with the same UUID |
| 105 // and to make function calls that take in a descriptor identifier. Present, | 131 // and to make function calls that take in a descriptor identifier. Present, |
| 106 // if this instance represents a remote characteristic. | 132 // if this instance represents a remote characteristic. |
| 107 DOMString? instanceId; | 133 DOMString? instanceId; |
| 108 | 134 |
| 109 // The currently cached descriptor value. This value gets updated when | 135 // The currently cached descriptor value. This value gets updated when |
| 110 // the value of the descriptor is read. | 136 // the value of the descriptor is read. |
| 111 ArrayBuffer? value; | 137 ArrayBuffer? value; |
| 112 }; | 138 }; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 callback CharacteristicsCallback = void(Characteristic[] result); | 218 callback CharacteristicsCallback = void(Characteristic[] result); |
| 193 callback DescriptorCallback = void(Descriptor result); | 219 callback DescriptorCallback = void(Descriptor result); |
| 194 callback CreateDescriptorCallback = void(DOMString descriptorId); | 220 callback CreateDescriptorCallback = void(DOMString descriptorId); |
| 195 callback DescriptorsCallback = void(Descriptor[] result); | 221 callback DescriptorsCallback = void(Descriptor[] result); |
| 196 callback ResultCallback = void(); | 222 callback ResultCallback = void(); |
| 197 callback ServiceCallback = void(Service result); | 223 callback ServiceCallback = void(Service result); |
| 198 callback CreateServiceCallback = void(DOMString serviceId); | 224 callback CreateServiceCallback = void(DOMString serviceId); |
| 199 callback ServicesCallback = void(Service[] result); | 225 callback ServicesCallback = void(Service[] result); |
| 200 callback ServiceResultCallback = void(ServiceResult result); | 226 callback ServiceResultCallback = void(ServiceResult result); |
| 201 callback RegisterAdvertisementCallback = void (long advertisementId); | 227 callback RegisterAdvertisementCallback = void (long advertisementId); |
| 228 callback NotificationCallback = void(NotificationResult result); | |
| 202 | 229 |
| 203 // These functions all report failures via chrome.runtime.lastError. | 230 // These functions all report failures via chrome.runtime.lastError. |
| 204 interface Functions { | 231 interface Functions { |
| 205 // Establishes a connection between the application and the device with the | 232 // Establishes a connection between the application and the device with the |
| 206 // given address. A device may be already connected and its GATT services | 233 // given address. A device may be already connected and its GATT services |
| 207 // available without calling <code>connect</code>, however, an app that | 234 // available without calling <code>connect</code>, however, an app that |
| 208 // wants to access GATT services of a device should call this function to | 235 // wants to access GATT services of a device should call this function to |
| 209 // make sure that a connection to the device is maintained. If the device | 236 // make sure that a connection to the device is maintained. If the device |
| 210 // is not connected, all GATT services of the device will be discovered | 237 // is not connected, all GATT services of the device will be discovered |
| 211 // after a successful call to <code>connect</code>. | 238 // after a successful call to <code>connect</code>. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 // Disable value notifications/indications from the specified | 376 // Disable value notifications/indications from the specified |
| 350 // characteristic. After a successful call, the application will stop | 377 // characteristic. After a successful call, the application will stop |
| 351 // receiving notifications/indications from this characteristic. | 378 // receiving notifications/indications from this characteristic. |
| 352 // |characteristicId|: The instance ID of the GATT characteristic on which | 379 // |characteristicId|: The instance ID of the GATT characteristic on which |
| 353 // this app's notification session should be stopped. | 380 // this app's notification session should be stopped. |
| 354 // |callback|: Called when the request has completed (optional). | 381 // |callback|: Called when the request has completed (optional). |
| 355 static void stopCharacteristicNotifications( | 382 static void stopCharacteristicNotifications( |
| 356 DOMString characteristicId, | 383 DOMString characteristicId, |
| 357 optional ResultCallback callback); | 384 optional ResultCallback callback); |
| 358 | 385 |
| 386 // Notify a remote device of a new value for a characteristic. If | |
| 387 // indicate is true, we will send an indication instead of a notification. | |
| 388 // Note, the characteristic needs to correctly set the notify/indicate | |
|
Devlin
2016/05/11 22:47:39
What is the |notify| property?
rkc
2016/05/11 22:57:41
It is a CharacteristicProperty that we specify whi
| |
| 389 // properties for this call to succeed. | |
| 390 // This function is only available if the app has both the | |
| 391 // bluetooth:low_energy and the bluetooth:peripheral permissions set to | |
| 392 // true. The peripheral permission may not be available to all apps. | |
| 393 // |characteristicId|: The characteristic to send the notication for. | |
| 394 // |value|: New value of the characteristic. | |
| 395 // |indicate|: Send a notification or an indication. | |
| 396 // |callback|: Callback called once the notification or indication has | |
| 397 // been sent successfully. | |
| 398 static void notifyCharacteristicValueChanged( | |
| 399 DOMString characteristicId, | |
| 400 ArrayBuffer value, | |
| 401 boolean indicate, | |
| 402 NotificationCallback callback); | |
| 403 | |
| 359 // Retrieve the value of a specified characteristic descriptor from a remote | 404 // Retrieve the value of a specified characteristic descriptor from a remote |
| 360 // peripheral. | 405 // peripheral. |
| 361 // |descriptorId|: The instance ID of the GATT characteristic descriptor | 406 // |descriptorId|: The instance ID of the GATT characteristic descriptor |
| 362 // whose value should be read from the remote device. | 407 // whose value should be read from the remote device. |
| 363 // |callback|: Called with the Descriptor object whose value was requested. | 408 // |callback|: Called with the Descriptor object whose value was requested. |
| 364 // The <code>value</code> field of the returned Descriptor object contains | 409 // The <code>value</code> field of the returned Descriptor object contains |
| 365 // the result of the read request. | 410 // the result of the read request. |
| 366 static void readDescriptorValue(DOMString descriptorId, | 411 static void readDescriptorValue(DOMString descriptorId, |
| 367 DescriptorCallback callback); | 412 DescriptorCallback callback); |
| 368 | 413 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 390 // Unregister the given service with the local GATT server. If the service | 435 // Unregister the given service with the local GATT server. If the service |
| 391 // ID is invalid, the lastError will be set. | 436 // ID is invalid, the lastError will be set. |
| 392 // This function is only available if the app has both the | 437 // This function is only available if the app has both the |
| 393 // bluetooth:low_energy and the bluetooth:peripheral permissions set to | 438 // bluetooth:low_energy and the bluetooth:peripheral permissions set to |
| 394 // true. The peripheral permission may not be available to all apps. | 439 // true. The peripheral permission may not be available to all apps. |
| 395 // |serviceId|: Unique ID of a current registered service. | 440 // |serviceId|: Unique ID of a current registered service. |
| 396 // |callback|: Callback with the result of the register operation. | 441 // |callback|: Callback with the result of the register operation. |
| 397 static void unregisterService( | 442 static void unregisterService( |
| 398 DOMString serviceId, ServiceResultCallback callback); | 443 DOMString serviceId, ServiceResultCallback callback); |
| 399 | 444 |
| 445 // Remove the specified service, unregistering it if it was registered. | |
| 446 // If the service ID is invalid, the lastError will be set. | |
| 447 // This function is only available if the app has both the | |
| 448 // bluetooth:low_energy and the bluetooth:peripheral permissions set to | |
| 449 // true. The peripheral permission may not be available to all apps. | |
| 450 // |serviceId|: Unique ID of a current registered service. | |
| 451 // |callback|: Callback called once the service is removed. | |
| 452 static void removeService( | |
| 453 DOMString serviceId, optional ResultCallback callback); | |
| 454 | |
| 400 // Create an advertisement and register it for advertising. To call this | 455 // Create an advertisement and register it for advertising. To call this |
| 401 // function, the app must have the bluetooth:low_energy and | 456 // function, the app must have the bluetooth:low_energy and |
| 402 // bluetooth:peripheral permissions set to true. Additionally this API | 457 // bluetooth:peripheral permissions set to true. Additionally this API |
| 403 // is only available to auto launched apps in Kiosk Mode of by setting | 458 // is only available to auto launched apps in Kiosk Mode of by setting |
| 404 // the 'enable-ble-advertising-in-apps' flag. | 459 // the 'enable-ble-advertising-in-apps' flag. |
| 405 // See https://developer.chrome.com/apps/manifest/bluetooth | 460 // See https://developer.chrome.com/apps/manifest/bluetooth |
| 406 // Note: On some hardware, central and peripheral modes at the same time is | 461 // Note: On some hardware, central and peripheral modes at the same time is |
| 407 // supported but on hardware that doesn't support this, making this call | 462 // supported but on hardware that doesn't support this, making this call |
| 408 // will switch the device to peripheral mode. In the case of hardware which | 463 // will switch the device to peripheral mode. In the case of hardware which |
| 409 // does not support both central and peripheral mode, attempting to use the | 464 // does not support both central and peripheral mode, attempting to use the |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 // this request for a long time may lead to a disconnection. | 559 // this request for a long time may lead to a disconnection. |
| 505 // This event is only available if the app has both the | 560 // This event is only available if the app has both the |
| 506 // bluetooth:low_energy and the bluetooth:peripheral permissions set to | 561 // bluetooth:low_energy and the bluetooth:peripheral permissions set to |
| 507 // true. The peripheral permission may not be available to all apps. | 562 // true. The peripheral permission may not be available to all apps. |
| 508 // |request|: Request data for this request. | 563 // |request|: Request data for this request. |
| 509 // |descriptor|: The GATT descriptor whose value is being written. | 564 // |descriptor|: The GATT descriptor whose value is being written. |
| 510 static void onDescriptorWriteRequest( | 565 static void onDescriptorWriteRequest( |
| 511 Request request, DOMString descriptorId); | 566 Request request, DOMString descriptorId); |
| 512 }; | 567 }; |
| 513 }; | 568 }; |
| OLD | NEW |