| 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 // Values representing the possible properties of a characteristic. | 10 // Values representing the possible properties of a characteristic. |
| 11 enum CharacteristicProperty {broadcast, read, writeWithoutResponse, write, | 11 // Characteristic permissions are inferred from these properties. |
| 12 notify, indicate, authenticatedSignedWrites, | 12 // Please see the Bluetooth 4.x spec to see the meaning of each individual |
| 13 extendedProperties, reliableWrite, | 13 // property. |
| 14 writableAuxiliaries}; | 14 enum CharacteristicProperty { |
| 15 broadcast, read, writeWithoutResponse, write, notify, indicate, |
| 16 authenticatedSignedWrites, extendedProperties, reliableWrite, |
| 17 writableAuxiliaries, encryptRead, encryptWrite, encryptAuthenticatedRead, |
| 18 encryptAuthenticatedWrite |
| 19 }; |
| 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 |
| 27 }; |
| 15 | 28 |
| 16 // Type of advertisement. If 'broadcast' is chosen, the sent advertisement | 29 // 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 | 30 // 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 | 31 // 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 | 32 // ADV_IND or ADV_SCAN_IND and the device will broadcast with real Bluetooth |
| 20 // Adapter's MAC Address. | 33 // Adapter's MAC Address. |
| 21 enum AdvertisementType {broadcast, peripheral}; | 34 enum AdvertisementType {broadcast, peripheral}; |
| 22 | 35 |
| 23 // Result of a register or unregister service call. | |
| 24 enum ServiceResult { | |
| 25 // The service operation was successful. | |
| 26 success, | |
| 27 // The service that is being registered is already regsitered. | |
| 28 alreadyRegistered, | |
| 29 // The service that is being unregistered is not regsitered. | |
| 30 notRegistered | |
| 31 }; | |
| 32 | |
| 33 // Represents a bluetooth central device that is connected to the local GATT | 36 // Represents a bluetooth central device that is connected to the local GATT |
| 34 // server. | 37 // server. |
| 35 dictionary Device { | 38 dictionary Device { |
| 36 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. | 39 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. |
| 37 DOMString address; | 40 DOMString address; |
| 38 | 41 |
| 39 // The human-readable name of the device. | 42 // The human-readable name of the device. |
| 40 DOMString? name; | 43 DOMString? name; |
| 41 | 44 |
| 42 // The class of the device, a bit-field defined by | 45 // 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 | 96 // Represents a GATT characteristic descriptor, which provides further |
| 94 // information about a characteristic's value. | 97 // information about a characteristic's value. |
| 95 dictionary Descriptor { | 98 dictionary Descriptor { |
| 96 // The UUID of the characteristic descriptor, e.g. | 99 // The UUID of the characteristic descriptor, e.g. |
| 97 // 00002902-0000-1000-8000-00805f9b34fb. | 100 // 00002902-0000-1000-8000-00805f9b34fb. |
| 98 DOMString uuid; | 101 DOMString uuid; |
| 99 | 102 |
| 100 // The GATT characteristic this descriptor belongs to. | 103 // The GATT characteristic this descriptor belongs to. |
| 101 Characteristic? characteristic; | 104 Characteristic? characteristic; |
| 102 | 105 |
| 106 // The permissions of this descriptor. |
| 107 DescriptorPermission[] permissions; |
| 108 |
| 103 // Returns the identifier assigned to this descriptor. Use the instance ID | 109 // Returns the identifier assigned to this descriptor. Use the instance ID |
| 104 // to distinguish between descriptors from a peripheral with the same UUID | 110 // to distinguish between descriptors from a peripheral with the same UUID |
| 105 // and to make function calls that take in a descriptor identifier. Present, | 111 // and to make function calls that take in a descriptor identifier. Present, |
| 106 // if this instance represents a remote characteristic. | 112 // if this instance represents a remote characteristic. |
| 107 DOMString? instanceId; | 113 DOMString? instanceId; |
| 108 | 114 |
| 109 // The currently cached descriptor value. This value gets updated when | 115 // The currently cached descriptor value. This value gets updated when |
| 110 // the value of the descriptor is read. | 116 // the value of the descriptor is read. |
| 111 ArrayBuffer? value; | 117 ArrayBuffer? value; |
| 112 }; | 118 }; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 dictionary Response { | 186 dictionary Response { |
| 181 // Id of the request this is a response to. | 187 // Id of the request this is a response to. |
| 182 long requestId; | 188 long requestId; |
| 183 // If this is an error response, this should be true. | 189 // If this is an error response, this should be true. |
| 184 boolean isError; | 190 boolean isError; |
| 185 // Response value. Write requests and error responses will ignore this | 191 // Response value. Write requests and error responses will ignore this |
| 186 // parameter. | 192 // parameter. |
| 187 ArrayBuffer? value; | 193 ArrayBuffer? value; |
| 188 }; | 194 }; |
| 189 | 195 |
| 196 // Represents a notification to be sent to a remote device. |
| 197 dictionary Notification { |
| 198 // New value of the characteristic. |
| 199 ArrayBuffer value; |
| 200 // Optional flag for sending an indication instead of a notification. |
| 201 boolean? shouldIndicate; |
| 202 }; |
| 203 |
| 190 callback CharacteristicCallback = void(Characteristic result); | 204 callback CharacteristicCallback = void(Characteristic result); |
| 191 callback CreateCharacteristicCallback = void(DOMString characteristicId); | 205 callback CreateCharacteristicCallback = void(DOMString characteristicId); |
| 192 callback CharacteristicsCallback = void(Characteristic[] result); | 206 callback CharacteristicsCallback = void(Characteristic[] result); |
| 193 callback DescriptorCallback = void(Descriptor result); | 207 callback DescriptorCallback = void(Descriptor result); |
| 194 callback CreateDescriptorCallback = void(DOMString descriptorId); | 208 callback CreateDescriptorCallback = void(DOMString descriptorId); |
| 195 callback DescriptorsCallback = void(Descriptor[] result); | 209 callback DescriptorsCallback = void(Descriptor[] result); |
| 196 callback ResultCallback = void(); | 210 callback ResultCallback = void(); |
| 197 callback ServiceCallback = void(Service result); | 211 callback ServiceCallback = void(Service result); |
| 198 callback CreateServiceCallback = void(DOMString serviceId); | 212 callback CreateServiceCallback = void(DOMString serviceId); |
| 199 callback ServicesCallback = void(Service[] result); | 213 callback ServicesCallback = void(Service[] result); |
| 200 callback ServiceResultCallback = void(ServiceResult result); | |
| 201 callback RegisterAdvertisementCallback = void (long advertisementId); | 214 callback RegisterAdvertisementCallback = void (long advertisementId); |
| 202 | 215 |
| 203 // These functions all report failures via chrome.runtime.lastError. | 216 // These functions all report failures via chrome.runtime.lastError. |
| 204 interface Functions { | 217 interface Functions { |
| 205 // Establishes a connection between the application and the device with the | 218 // Establishes a connection between the application and the device with the |
| 206 // given address. A device may be already connected and its GATT services | 219 // given address. A device may be already connected and its GATT services |
| 207 // available without calling <code>connect</code>, however, an app that | 220 // available without calling <code>connect</code>, however, an app that |
| 208 // wants to access GATT services of a device should call this function to | 221 // 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 | 222 // 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 | 223 // is not connected, all GATT services of the device will be discovered |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // Disable value notifications/indications from the specified | 362 // Disable value notifications/indications from the specified |
| 350 // characteristic. After a successful call, the application will stop | 363 // characteristic. After a successful call, the application will stop |
| 351 // receiving notifications/indications from this characteristic. | 364 // receiving notifications/indications from this characteristic. |
| 352 // |characteristicId|: The instance ID of the GATT characteristic on which | 365 // |characteristicId|: The instance ID of the GATT characteristic on which |
| 353 // this app's notification session should be stopped. | 366 // this app's notification session should be stopped. |
| 354 // |callback|: Called when the request has completed (optional). | 367 // |callback|: Called when the request has completed (optional). |
| 355 static void stopCharacteristicNotifications( | 368 static void stopCharacteristicNotifications( |
| 356 DOMString characteristicId, | 369 DOMString characteristicId, |
| 357 optional ResultCallback callback); | 370 optional ResultCallback callback); |
| 358 | 371 |
| 372 // Notify a remote device of a new value for a characteristic. If the |
| 373 // shouldIndicate flag in the notification object is true, an indication |
| 374 // will be sent instead of a notification. Note, the characteristic needs |
| 375 // to correctly set the 'notify' or 'indicate' property during creation for |
| 376 // this call to succeed. |
| 377 // This function is only available if the app has both the |
| 378 // bluetooth:low_energy and the bluetooth:peripheral permissions set to |
| 379 // true. The peripheral permission may not be available to all apps. |
| 380 // |characteristicId|: The characteristic to send the notication for. |
| 381 // |notifcation|: The notification to send. |
| 382 // |callback|: Callback called once the notification or indication has |
| 383 // been sent successfully. |
| 384 static void notifyCharacteristicValueChanged(DOMString characteristicId, |
| 385 Notification notification, |
| 386 ResultCallback callback); |
| 387 |
| 359 // Retrieve the value of a specified characteristic descriptor from a remote | 388 // Retrieve the value of a specified characteristic descriptor from a remote |
| 360 // peripheral. | 389 // peripheral. |
| 361 // |descriptorId|: The instance ID of the GATT characteristic descriptor | 390 // |descriptorId|: The instance ID of the GATT characteristic descriptor |
| 362 // whose value should be read from the remote device. | 391 // whose value should be read from the remote device. |
| 363 // |callback|: Called with the Descriptor object whose value was requested. | 392 // |callback|: Called with the Descriptor object whose value was requested. |
| 364 // The <code>value</code> field of the returned Descriptor object contains | 393 // The <code>value</code> field of the returned Descriptor object contains |
| 365 // the result of the read request. | 394 // the result of the read request. |
| 366 static void readDescriptorValue(DOMString descriptorId, | 395 static void readDescriptorValue(DOMString descriptorId, |
| 367 DescriptorCallback callback); | 396 DescriptorCallback callback); |
| 368 | 397 |
| 369 // Write the value of a specified characteristic descriptor from a remote | 398 // Write the value of a specified characteristic descriptor from a remote |
| 370 // peripheral. | 399 // peripheral. |
| 371 // |descriptorId|: The instance ID of the GATT characteristic descriptor | 400 // |descriptorId|: The instance ID of the GATT characteristic descriptor |
| 372 // whose value should be written to. | 401 // whose value should be written to. |
| 373 // |value|: The value that should be sent to the remote descriptor as part | 402 // |value|: The value that should be sent to the remote descriptor as part |
| 374 // of the write request. | 403 // of the write request. |
| 375 // |callback|: Called when the write request has completed. | 404 // |callback|: Called when the write request has completed. |
| 376 static void writeDescriptorValue(DOMString descriptorId, | 405 static void writeDescriptorValue(DOMString descriptorId, |
| 377 ArrayBuffer value, | 406 ArrayBuffer value, |
| 378 ResultCallback callback); | 407 ResultCallback callback); |
| 379 | 408 |
| 380 // Register the given service with the local GATT server. If the service | 409 // Register the given service with the local GATT server. If the service |
| 381 // ID is invalid, the lastError will be set. | 410 // ID is invalid, the lastError will be set. |
| 382 // This function is only available if the app has both the | 411 // This function is only available if the app has both the |
| 383 // bluetooth:low_energy and the bluetooth:peripheral permissions set to | 412 // bluetooth:low_energy and the bluetooth:peripheral permissions set to |
| 384 // true. The peripheral permission may not be available to all apps. | 413 // true. The peripheral permission may not be available to all apps. |
| 385 // |serviceId|: Unique ID of a created service. | 414 // |serviceId|: Unique ID of a created service. |
| 386 // |callback|: Callback with the result of the register operation. | 415 // |callback|: Callback with the result of the register operation. |
| 387 static void registerService( | 416 static void registerService( |
| 388 DOMString serviceId, ServiceResultCallback callback); | 417 DOMString serviceId, ResultCallback callback); |
| 389 | 418 |
| 390 // Unregister the given service with the local GATT server. If the service | 419 // Unregister the given service with the local GATT server. If the service |
| 391 // ID is invalid, the lastError will be set. | 420 // ID is invalid, the lastError will be set. |
| 392 // This function is only available if the app has both the | 421 // This function is only available if the app has both the |
| 393 // bluetooth:low_energy and the bluetooth:peripheral permissions set to | 422 // bluetooth:low_energy and the bluetooth:peripheral permissions set to |
| 394 // true. The peripheral permission may not be available to all apps. | 423 // true. The peripheral permission may not be available to all apps. |
| 395 // |serviceId|: Unique ID of a current registered service. | 424 // |serviceId|: Unique ID of a current registered service. |
| 396 // |callback|: Callback with the result of the register operation. | 425 // |callback|: Callback with the result of the register operation. |
| 397 static void unregisterService( | 426 static void unregisterService( |
| 398 DOMString serviceId, ServiceResultCallback callback); | 427 DOMString serviceId, ResultCallback callback); |
| 428 |
| 429 // Remove the specified service, unregistering it if it was registered. |
| 430 // If the service ID is invalid, the lastError will be set. |
| 431 // This function is only available if the app has both the |
| 432 // bluetooth:low_energy and the bluetooth:peripheral permissions set to |
| 433 // true. The peripheral permission may not be available to all apps. |
| 434 // |serviceId|: Unique ID of a current registered service. |
| 435 // |callback|: Callback called once the service is removed. |
| 436 static void removeService( |
| 437 DOMString serviceId, optional ResultCallback callback); |
| 399 | 438 |
| 400 // Create an advertisement and register it for advertising. To call this | 439 // Create an advertisement and register it for advertising. To call this |
| 401 // function, the app must have the bluetooth:low_energy and | 440 // function, the app must have the bluetooth:low_energy and |
| 402 // bluetooth:peripheral permissions set to true. Additionally this API | 441 // bluetooth:peripheral permissions set to true. Additionally this API |
| 403 // is only available to auto launched apps in Kiosk Mode of by setting | 442 // is only available to auto launched apps in Kiosk Mode of by setting |
| 404 // the 'enable-ble-advertising-in-apps' flag. | 443 // the 'enable-ble-advertising-in-apps' flag. |
| 405 // See https://developer.chrome.com/apps/manifest/bluetooth | 444 // See https://developer.chrome.com/apps/manifest/bluetooth |
| 406 // Note: On some hardware, central and peripheral modes at the same time is | 445 // 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 | 446 // 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 | 447 // will switch the device to peripheral mode. In the case of hardware which |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 // this request for a long time may lead to a disconnection. | 543 // this request for a long time may lead to a disconnection. |
| 505 // This event is only available if the app has both the | 544 // This event is only available if the app has both the |
| 506 // bluetooth:low_energy and the bluetooth:peripheral permissions set to | 545 // bluetooth:low_energy and the bluetooth:peripheral permissions set to |
| 507 // true. The peripheral permission may not be available to all apps. | 546 // true. The peripheral permission may not be available to all apps. |
| 508 // |request|: Request data for this request. | 547 // |request|: Request data for this request. |
| 509 // |descriptor|: The GATT descriptor whose value is being written. | 548 // |descriptor|: The GATT descriptor whose value is being written. |
| 510 static void onDescriptorWriteRequest( | 549 static void onDescriptorWriteRequest( |
| 511 Request request, DOMString descriptorId); | 550 Request request, DOMString descriptorId); |
| 512 }; | 551 }; |
| 513 }; | 552 }; |
| OLD | NEW |