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
3 // found in the LICENSE file.
5 // The <code>chrome.bluetoothLowEnergy</code> API is used to communicate with
6 // Bluetooth Smart (Low Energy) devices using the
7 // <a href="https://developer.bluetooth.org/TechnologyOverview/Pages/GATT.aspx">
8 // Generic Attribute Profile (GATT)</a>.
9 namespace bluetoothLowEnergy
{
10 // Values representing the possible properties of a characteristic.
11 enum CharacteristicProperty
{broadcast, read
, writeWithoutResponse
, write
,
12 notify
, indicate
, authenticatedSignedWrites
,
13 extendedProperties
, reliableWrite
,
16 // 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
18 // 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
20 // Adapter's MAC Address.
21 enum AdvertisementType
{broadcast, peripheral
};
23 // Represents a peripheral's Bluetooth GATT Service, a collection of
24 // characteristics and relationships to other services that encapsulate
25 // the behavior of part of a device.
27 // The UUID of the service, e.g. 0000180d-0000-1000-8000-00805f9b34fb.
30 // Indicates whether the type of this service is primary or secondary.
33 // Indicates whether this service represents a local service hosted by the
34 // application and available to other peripherals, or a remote service
35 // hosted and received from a remote peripheral.
36 [nodoc
] boolean isLocal
;
38 // Returns the identifier assigned to this service. Use the instance ID to
39 // distinguish between services from a peripheral with the same UUID and
40 // to make function calls that take in a service identifier. Present, if
41 // this instance represents a remote service.
42 DOMString? instanceId
;
44 // The device address of the remote peripheral that the GATT service belongs
45 // to. Present, if this instance represents a remote service.
46 DOMString? deviceAddress
;
49 // Represents a GATT characteristic, which is a basic data element that
50 // provides further information about a peripheral's service.
51 dictionary Characteristic
{
52 // The UUID of the characteristic, e.g.
53 // 00002a37-0000-1000-8000-00805f9b34fb.
56 // Indicates whether this characteristic represents a local characteristic
57 // hosted by the application and available to other peripherals, or a remote
58 // characteristic hosted and received from a remote peripheral.
59 [nodoc
] boolean isLocal
;
61 // The GATT service this characteristic belongs to.
64 // The properties of this characteristic.
65 CharacteristicProperty
[] properties
;
67 // Returns the identifier assigned to this characteristic. Use the instance
68 // ID to distinguish between characteristics from a peripheral with the same
69 // UUID and to make function calls that take in a characteristic identifier.
70 // Present, if this instance represents a remote characteristic.
71 DOMString? instanceId
;
73 // The currently cached characteristic value. This value gets updated when
74 // the value of the characteristic is read or updated via a notification
79 // Represents a GATT characteristic descriptor, which provides further
80 // information about a characteristic's value.
81 dictionary Descriptor
{
82 // The UUID of the characteristic descriptor, e.g.
83 // 00002902-0000-1000-8000-00805f9b34fb.
86 // Indicates whether this descriptor represents a local descriptor
87 // hosted by the application and available to other peripherals, or a remote
88 // descriptor hosted and received from a remote peripheral.
89 [nodoc
] boolean isLocal
;
91 // The GATT characteristic this descriptor belongs to.
92 Characteristic characteristic
;
94 // Returns the identifier assigned to this descriptor. Use the instance ID
95 // to distinguish between descriptors from a peripheral with the same UUID
96 // and to make function calls that take in a descriptor identifier. Present,
97 // if this instance represents a remote characteristic.
98 DOMString? instanceId
;
100 // The currently cached descriptor value. This value gets updated when
101 // the value of the descriptor is read.
105 // The connection properties specified during a call to $(ref:connect).
106 dictionary ConnectProperties
{
107 // Flag indicating whether a connection to the device is left open when the
108 // event page of the application is unloaded (see <a
109 // href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App
110 // Lifecycle</a>). The default value is <code>false.</code>
114 // Optional characteristic notification session properties specified during a
115 // call to $(ref:startCharacteristicNotifications).
116 dictionary NotificationProperties
{
117 // Flag indicating whether the app should receive notifications when the
118 // event page of the application is unloaded (see <a
119 // href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App
120 // Lifecycle</a>). The default value is <code>false</code>.
124 // Represents an entry of the "Manufacturer Specific Data" field of Bluetooth
125 // LE advertisement data.
126 dictionary ManufacturerData
{
131 // Represents an entry of the "Service Data" field of Bluetooth LE advertisement
133 dictionary ServiceData
{
138 // Represents a Bluetooth LE advertisement instance.
139 dictionary Advertisement
{
140 // Type of advertisement.
141 AdvertisementType type
;
143 // List of UUIDs to include in the "Service UUIDs" field of the Advertising
144 // Data. These UUIDs can be of the 16bit, 32bit or 128 formats.
145 DOMString
[]? serviceUuids
;
147 // List of manufacturer specific data to be included in "Manufacturer Specific
148 // Data" fields of the advertising data.
149 ManufacturerData
[]? manufacturerData
;
151 // List of UUIDs to include in the "Solicit UUIDs" field of the Advertising
152 // Data. These UUIDs can be of the 16bit, 32bit or 128 formats.
153 DOMString
[]? solicitUuids
;
155 // List of service data to be included in "Service Data" fields of the advertising
157 ServiceData
[]? serviceData
;
160 callback CharacteristicCallback
= void(Characteristic result
);
161 callback CharacteristicsCallback
= void(Characteristic
[] result
);
162 callback DescriptorCallback
= void(Descriptor result
);
163 callback DescriptorsCallback
= void(Descriptor
[] result
);
164 callback ResultCallback
= void();
165 callback ServiceCallback
= void(Service result
);
166 callback ServicesCallback
= void(Service
[] result
);
167 callback RegisterAdvertisementCallback
= void (long advertisementId
);
169 // These functions all report failures via chrome.runtime.lastError.
170 interface Functions
{
171 // Establishes a connection between the application and the device with the
172 // given address. A device may be already connected and its GATT services
173 // available without calling <code>connect</code>, however, an app that
174 // wants to access GATT services of a device should call this function to
175 // make sure that a connection to the device is maintained. If the device
176 // is not connected, all GATT services of the device will be discovered
177 // after a successful call to <code>connect</code>.
178 // |deviceAddress| : The Bluetooth address of the remote device to which a
179 // GATT connection should be opened.
180 // |properties| : Connection properties (optional).
181 // |callback| : Called when the connect request has completed.
182 static
void connect
(DOMString deviceAddress
,
183 optional ConnectProperties properties
,
184 ResultCallback
callback);
186 // Closes the app's connection to the device with the given address. Note
187 // that this will not always destroy the physical link itself, since there
188 // may be other apps with open connections.
189 // |deviceAddress| : The Bluetooth address of the remote device.
190 // |callback| : Called when the disconnect request has completed.
191 static
void disconnect
(DOMString deviceAddress
,
192 optional ResultCallback
callback);
194 // Get the GATT service with the given instance ID.
195 // |serviceId| : The instance ID of the requested GATT service.
196 // |callback| : Called with the requested Service object.
197 static
void getService
(DOMString serviceId
, ServiceCallback
callback);
199 // Get all the GATT services that were discovered on the remote device with
200 // the given device address.
201 // |deviceAddress| : The Bluetooth address of the remote device whose GATT
202 // services should be returned.
203 // |callback| : Called with the list of requested Service objects.
204 static
void getServices
(DOMString deviceAddress
, ServicesCallback
callback);
206 // Get the GATT characteristic with the given instance ID that belongs to
207 // the given GATT service, if the characteristic exists.
208 // |characteristicId| : The instance ID of the requested GATT
210 // |callback| : Called with the requested Characteristic object.
211 static
void getCharacteristic
(DOMString characteristicId
,
212 CharacteristicCallback
callback);
214 // Get a list of all discovered GATT characteristics that belong to the
216 // |serviceId| : The instance ID of the GATT service whose characteristics
217 // should be returned.
218 // |callback| : Called with the list of characteristics that belong to the
220 static
void getCharacteristics
(DOMString serviceId
,
221 CharacteristicsCallback
callback);
223 // Get a list of GATT services that are included by the given service.
224 // |serviceId| : The instance ID of the GATT service whose included
225 // services should be returned.
226 // |callback| : Called with the list of GATT services included from the
228 static
void getIncludedServices
(DOMString serviceId
,
229 ServicesCallback
callback);
231 // Get the GATT characteristic descriptor with the given instance ID.
232 // |descriptorId| : The instance ID of the requested GATT characteristic
234 // |callback| : Called with the requested Descriptor object.
235 static
void getDescriptor
(DOMString descriptorId
,
236 DescriptorCallback
callback);
238 // Get a list of GATT characteristic descriptors that belong to the given
240 // |characteristicId| : The instance ID of the GATT characteristic whose
241 // descriptors should be returned.
242 // |callback| : Called with the list of descriptors that belong to the given
244 static
void getDescriptors
(DOMString characteristicId
,
245 DescriptorsCallback
callback);
247 // Retrieve the value of a specified characteristic from a remote
249 // |characteristicId| : The instance ID of the GATT characteristic whose
250 // value should be read from the remote device.
251 // |callback| : Called with the Characteristic object whose value was
252 // requested. The <code>value</code> field of the returned Characteristic
253 // object contains the result of the read request.
254 static
void readCharacteristicValue
(DOMString characteristicId
,
255 CharacteristicCallback
callback);
257 // Write the value of a specified characteristic from a remote peripheral.
258 // |characteristicId| : The instance ID of the GATT characteristic whose
259 // value should be written to.
260 // |value| : The value that should be sent to the remote characteristic as
261 // part of the write request.
262 // |callback| : Called when the write request has completed.
263 static
void writeCharacteristicValue
(DOMString characteristicId
,
265 ResultCallback
callback);
267 // Enable value notifications/indications from the specified characteristic.
268 // Once enabled, an application can listen to notifications using the
269 // $(ref:onCharacteristicValueChanged) event.
270 // |characteristicId| : The instance ID of the GATT characteristic that
271 // notifications should be enabled on.
272 // |properties| : Notification session properties (optional).
273 // |callback| : Called when the request has completed.
274 static
void startCharacteristicNotifications
(
275 DOMString characteristicId
,
276 optional NotificationProperties properties
,
277 ResultCallback
callback);
279 // Disable value notifications/indications from the specified
280 // characteristic. After a successful call, the application will stop
281 // receiving notifications/indications from this characteristic.
282 // |characteristicId| : The instance ID of the GATT characteristic on which
283 // this app's notification session should be stopped.
284 // |callback| : Called when the request has completed (optional).
285 static
void stopCharacteristicNotifications
(
286 DOMString characteristicId
,
287 optional ResultCallback
callback);
289 // Retrieve the value of a specified characteristic descriptor from a remote
291 // |descriptorId| : The instance ID of the GATT characteristic descriptor
292 // whose value should be read from the remote device.
293 // |callback| : Called with the Descriptor object whose value was requested.
294 // The <code>value</code> field of the returned Descriptor object contains
295 // the result of the read request.
296 static
void readDescriptorValue
(DOMString descriptorId
,
297 DescriptorCallback
callback);
299 // Write the value of a specified characteristic descriptor from a remote
301 // |descriptorId| : The instance ID of the GATT characteristic descriptor
302 // whose value should be written to.
303 // |value| : The value that should be sent to the remote descriptor as part
304 // of the write request.
305 // |callback| : Called when the write request has completed.
306 static
void writeDescriptorValue
(DOMString descriptorId
,
308 ResultCallback
callback);
310 // Create an advertisement and register it for advertising. To call this
311 // function, the app must have the bluetooth:low_energy and
312 // bluetooth:peripheral permissions set to true. Additionally this API
313 // is only available to auto launched apps in Kiosk Mode of by setting
314 // the 'enable-ble-advertising-in-apps' flag.
315 // See https://developer.chrome.com/apps/manifest/bluetooth
316 // Note: On some hardware, central and peripheral modes at the same time is
317 // supported but on hardware that doesn't support this, making this call
318 // will switch the device to peripheral mode. In the case of hardware which
319 // does not support both central and peripheral mode, attempting to use the
320 // device in both modes will lead to undefined behavior or prevent other
321 // central-role applications from behaving correctly (including the
322 // discovery of Bluetooth Low Energy devices).
323 // |advertisement| : The advertisement to advertise.
324 // |callback| : Called once the registeration is done and we've started
325 // advertising. Returns the id of the created advertisement.
326 static
void registerAdvertisement
(
327 Advertisement advertisement
, RegisterAdvertisementCallback
callback);
329 // Unregisters an advertisement and stops its advertising. If the
330 // advertisement fails to unregister the only way to stop advertising
331 // might be to restart the device.
332 // |advertisementId| : Id of the advertisement to unregister.
333 // |callback| : Called once the advertisement is unregistered and is no
334 // longer being advertised.
335 static
void unregisterAdvertisement
(long advertisementId
,
336 ResultCallback
callback);
340 // Fired whan a new GATT service has been discovered on a remote device.
341 // |service| : The GATT service that was added.
342 static
void onServiceAdded
(Service service
);
344 // Fired when the state of a remote GATT service changes. This involves any
345 // characteristics and/or descriptors that get added or removed from the
346 // service, as well as "ServiceChanged" notifications from the remote
348 // |service| : The GATT service whose state has changed.
349 static
void onServiceChanged
(Service service
);
351 // Fired when a GATT service that was previously discovered on a remote
352 // device has been removed.
353 // |service| : The GATT service that was removed.
354 static
void onServiceRemoved
(Service service
);
356 // Fired when the value of a remote GATT characteristic changes, either as
357 // a result of a read request, or a value change notification/indication
358 // This event will only be sent if the app has enabled notifications by
359 // calling $(ref:startCharacteristicNotifications).
360 // |characteristic| : The GATT characteristic whose value has changed.
361 static
void onCharacteristicValueChanged
(Characteristic characteristic
);
363 // Fired when the value of a remote GATT characteristic descriptor changes,
364 // usually as a result of a read request. This event exists
365 // mostly for convenience and will always be sent after a successful
366 // call to $(ref:readDescriptorValue).
367 // |descriptor| : The GATT characteristic descriptor whose value has
369 static
void onDescriptorValueChanged
(Descriptor descriptor
);