1 // Copyright (c) 2012 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 // Use the <code>chrome.bluetooth</code> API to connect to a Bluetooth
8 dictionary AdapterState {
9 // The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'.
12 // The human-readable name of the adapter.
15 // Indicates whether or not the adapter has power.
18 // Indicates whether or not the adapter is available (i.e. enabled).
21 // Indicates whether or not the adapter is currently discovering.
26 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'.
29 // The human-readable name of the device.
32 // Indicates whether or not the device is paired with the system.
35 // Indicates whether the device is currently connected to the system.
40 // Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB
43 // Human-readable name of the Profile, e.g. "Health Device"
46 // The RFCOMM channel id, used when the profile is to be exported to remote
50 // The LS2CAP PSM number, used when the profile is to be exported to remote
54 // Specifies whether pairing (and encryption) is required to be able to
56 boolean? requireAuthentication;
58 // Specifies whether user authorization is required to be able to connect.
59 boolean? requireAuthorization;
61 // Specifies whether this profile will be automatically connected if any
62 // other profile of device also exporting this profile connects to the host.
65 // Specifies the implemented version of the profile.
68 // Specifies the profile-specific bit field of features the implementation
73 dictionary ServiceRecord {
74 // The name of the service.
77 // The UUID of the service.
82 // The remote Bluetooth device associated with this socket.
85 // The remote Bluetooth profile associated with this socket.
88 // An identifier for this socket that should be used with the
89 // read/write/disconnect methods.
93 dictionary OutOfBandPairingData {
94 // Simple Pairing Hash C.
95 // Always 16 octets long.
98 // Simple Pairing Randomizer R.
99 // Always 16 octets long.
100 ArrayBuffer randomizer;
103 callback AdapterStateCallback = void(AdapterState result);
104 callback AddressCallback = void (DOMString result);
105 callback BooleanCallback = void (boolean result);
106 callback DataCallback = void (optional ArrayBuffer result);
107 callback DeviceCallback = void (Device device);
108 callback DevicesCallback = void (Device[] result);
109 callback NameCallback = void (DOMString result);
110 callback OutOfBandPairingDataCallback = void (OutOfBandPairingData data);
111 callback ProfilesCallback = void(Profile[] result);
112 callback ResultCallback = void ();
113 callback ServicesCallback = void(ServiceRecord[] result);
114 callback SizeCallback = void (long result);
115 callback SocketCallback = void (Socket result);
117 // Options for the getDevices function. If |profile| is not provided, all
118 // devices known to the system are returned.
119 dictionary GetDevicesOptions {
120 // Only devices providing |profile| will be returned.
123 // Called for each matching device. Note that a service discovery request
124 // must be made to each non-matching device before it can be definitively
125 // excluded. This can take some time.
126 DeviceCallback deviceCallback;
129 // Options for the getProfiles function.
130 dictionary GetProfilesOptions {
131 // The remote Bluetooth device to retrieve the exported profiles list from.
135 // Options for the getServices function.
136 dictionary GetServicesOptions {
137 // The address of the device to inquire about. |deviceAddress| should be
138 // in the format 'XX:XX:XX:XX:XX:XX'.
139 DOMString deviceAddress;
142 // Options for the connect function.
143 dictionary ConnectOptions {
144 // The connection is made to |device|.
147 // The connection is made to |profile|.
151 // Options for the disconnect function.
152 dictionary DisconnectOptions {
153 // The socket to disconnect.
157 // Options for the read function.
158 dictionary ReadOptions {
159 // The socket to read from.
163 // Options for the write function.
164 dictionary WriteOptions {
165 // The socket to write to.
168 // The data to write.
172 // Options for the setOutOfBandPairingData function.
173 dictionary SetOutOfBandPairingDataOptions {
174 // The address of the remote device that the data should be associated
175 // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'.
178 // The Out Of Band Pairing Data. If this is omitted, the data for the
179 // device is cleared instead.
180 OutOfBandPairingData? data;
183 // Options for the startDiscovery function.
184 dictionary StartDiscoveryOptions {
185 // Called for each device that is discovered.
186 DeviceCallback deviceCallback;
189 // These functions all report failures via chrome.runtime.lastError.
190 interface Functions {
191 // Registers the JavaScript application as an implementation for the given
192 // Profile; if a channel or PSM is specified, the profile will be exported
193 // in the host's SDP and GATT tables and advertised to other devices.
194 static void addProfile(Profile profile, ResultCallback callback);
196 // Unregisters the JavaScript application as an implementation for the given
197 // Profile; only the uuid field of the Profile object is used.
198 static void removeProfile(Profile profile, ResultCallback callback);
200 // Get information about the Bluetooth adapter.
201 // |callback| : Called with an AdapterState object describing the adapter
203 static void getAdapterState(AdapterStateCallback callback);
205 // Get a bluetooth devices known to the system. Known devices are either
206 // currently paired, or have been paired in the past.
207 // |options| : Controls which devices are returned and provides
208 // |deviceCallback|, which is called for each matching device.
209 // |callback| : Called when the search is completed.
210 // |options.deviceCallback| will not be called after
211 // |callback| has been called.
212 static void getDevices(GetDevicesOptions options,
213 ResultCallback callback);
215 // Returns the set of exported profiles for the device specified in options.
216 // This function will not initiate a connection to the remote device.
217 static void getProfiles(GetProfilesOptions options,
218 ProfilesCallback callback);
220 // Get a list of services provided by a device.
221 static void getServices(GetServicesOptions options,
222 ServicesCallback callback);
224 // Connect to a service on a device.
225 // |options| : The options for the connection.
226 // |callback| : Called to indicate success or failure.
227 static void connect(ConnectOptions options,
228 ResultCallback callback);
230 // Close a Bluetooth connection.
231 // |options| : The options for this function.
232 // |callback| : Called to indicate success or failure.
233 static void disconnect(DisconnectOptions options,
234 optional ResultCallback callback);
236 // Read data from a Bluetooth connection.
237 // |options| : The options for this function.
238 // |callback| : Called with the data when it is available.
239 static void read(ReadOptions options,
240 DataCallback callback);
242 // Write data to a Bluetooth connection.
243 // |options| : The options for this function.
244 // |callback| : Called with the number of bytes written.
245 static void write(WriteOptions options,
246 optional SizeCallback callback);
248 // Get the local Out of Band Pairing data.
249 // |callback| : Called with the data.
250 static void getLocalOutOfBandPairingData(
251 OutOfBandPairingDataCallback callback);
253 // Set the Out of Band Pairing data for a remote device.
254 // Any previous Out Of Band Pairing Data for this device is overwritten.
255 // |options| : The options for this function.
256 // |callback| : Called to indicate success or failure.
257 static void setOutOfBandPairingData(SetOutOfBandPairingDataOptions options,
258 optional ResultCallback callback);
260 // Start discovery. Discovered devices will be returned via the
261 // |onDeviceDiscovered| callback. Discovery will fail to start if it is
262 // already in progress. Discovery can be resource intensive: stopDiscovery
263 // should be called as soon as possible.
264 // |options| : The options for this function.
265 // |callback| : Called to indicate success or failure.
266 static void startDiscovery(
267 StartDiscoveryOptions options,
268 optional ResultCallback callback);
271 // |callback| : Called to indicate success or failure.
272 static void stopDiscovery(
273 optional ResultCallback callback);
277 // Fired when the state of the Bluetooth adapter changes.
278 // |state| : The new state of the adapter.
279 static void onAdapterStateChanged(AdapterState state);
281 // Fired when a connection has been made for a registered profile.
282 // |socket| : The socket for the connection.
283 static void onConnection(Socket socket);