summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/api/bluetooth.idl
blob: cbc4414d762febcb32cffa3dc67e16157fb7f9db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Bluetooth API.

namespace bluetooth {
  dictionary AdapterState {
    // The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'.
    DOMString address;

    // The human-readable name of the adapter.
    DOMString name;

    // Indicates whether or not the adapter has power.
    boolean powered;

    // Indicates whether or not the adapter is available (i.e. enabled).
    boolean available;

    // Indicates whether or not the adapter is currently discovering.
    boolean discovering;
  };

  dictionary Device {
    // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'.
    DOMString address;

    // The human-readable name of the device.
    DOMString name;

    // Indicates whether or not the device is paired with the system.
    boolean paired;

    // Indicates whether or not the device is bonded with the system. A device
    // is bonded if it is paired and high-security link keys have been
    // exchanged so that connections may be encrypted.
    boolean bonded;

    // Indicates whether the device is currently connected to the system.
    boolean connected;
  };

  dictionary ServiceRecord {
    // The name of the service.
    DOMString name;

    // The UUID of the service.
    DOMString? uuid;
  };

  dictionary Socket {
    // The remote Bluetooth device associated with this socket.
    Device device;

    // The remote Bluetooth service associated with this socket.
    DOMString serviceUuid;

    // An identifier for this socket that should be used with the
    // read/write/disconnect methods.
    long id;
  };

  dictionary OutOfBandPairingData {
    // Simple Pairing Hash C.
    // Always 16 octets long.
    ArrayBuffer hash;

    // Simple Pairing Randomizer R.
    // Always 16 octets long.
    ArrayBuffer randomizer;
  };

  callback AdapterStateCallback = void(AdapterState result);
  callback AddressCallback = void (DOMString result);
  callback BooleanCallback = void (boolean result);
  callback DataCallback = void (optional ArrayBuffer result);
  callback DeviceCallback = void (Device device);
  callback DevicesCallback = void (Device[] result);
  callback NameCallback = void (DOMString result);
  callback OutOfBandPairingDataCallback = void (OutOfBandPairingData data);
  callback ResultCallback = void ();
  callback ServicesCallback = void(ServiceRecord[] result);
  callback SizeCallback = void (long result);
  callback SocketCallback = void (Socket result);

  // Options for the getDevices function. If neither |uuid| or |name| are
  // provided, all devices known to the system are returned.
  dictionary GetDevicesOptions {
    // Only devices providing a service with a UUID that matches |uuid| will be
    // returned.
    DOMString? uuid;

    // Only devices providing a service with a name that matches |name| will be
    // returned.
    DOMString? name;

    // Called for each matching device.  Note that a service discovery request
    // must be made to each non-matching device before it can be definitively
    // excluded.  This can take some time.
    DeviceCallback deviceCallback;
  };

  // Options for the getServices function.
  dictionary GetServicesOptions {
    // The address of the device to inquire about. |deviceAddress| should be
    // in the format 'XX:XX:XX:XX:XX:XX'.
    DOMString deviceAddress;
  };

  // Options for the connect function.
  dictionary ConnectOptions {
    // The connection is made to the device at |deviceAddress|.
    // |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'.
    DOMString deviceAddress;

    // The connection is made to the service with UUID |serviceUuid|.
    DOMString serviceUuid;
  };

  // Options for the disconnect function.
  dictionary DisconnectOptions {
    // The socket to disconnect.
    long socketId;
  };

  // Options for the read function.
  dictionary ReadOptions {
    // The socket to read from.
    long socketId;
  };

  // Options for the write function.
  dictionary WriteOptions {
    // The socket to write to.
    long socketId;

    // The data to write.
    ArrayBuffer data;
  };

  // Options for the setOutOfBandPairingData function.
  dictionary SetOutOfBandPairingDataOptions {
    // The address of the remote device that the data should be associated
    // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'.
    DOMString address;

    // The Out Of Band Pairing Data. If this is omitted, the data for the
    // device is cleared instead.
    OutOfBandPairingData? data;
  };

  // Options for the startDiscovery function.
  dictionary StartDiscoveryOptions {
    // Called for each device that is discovered.
    DeviceCallback deviceCallback;
  };

  // These functions all report failures via chrome.extension.lastError.
  interface Functions {
    // Get information about the Bluetooth adapter.
    // |callback| : Called with an AdapterState object describing the adapter
    //              state.
    static void getAdapterState(AdapterStateCallback callback);

    // Get a bluetooth devices known to the system.  Known devices are either
    // currently bonded, or have been bonded in the past.
    // |options|  : Controls which devices are returned and provides
    //              |deviceCallback|, which is called for each matching device.
    // |callback| : Called when the search is completed.
    //              |options.deviceCallback| will not be called after
    //              |callback| has been called.
    static void getDevices(GetDevicesOptions options,
                           ResultCallback callback);

    // Get a list of services provided by a device.
    static void getServices(GetServicesOptions options,
                            ServicesCallback callback);

    // Connect to a service on a device.
    // |options|  : The options for the connection.
    // |callback| : Called when the connection is established with a Socket
    //              that can be used to communicate with |device|.
    static void connect(ConnectOptions options,
                        SocketCallback callback);

    // Close a Bluetooth connection.
    // |options|  : The options for this function.
    // |callback| : Called to indicate success or failure.
    static void disconnect(DisconnectOptions options,
                           optional ResultCallback callback);

    // Read data from a Bluetooth connection.
    // |options|  : The options for this function.
    // |callback| : Called with the data when it is available.
    static void read(ReadOptions options,
                     DataCallback callback);

    // Write data to a Bluetooth connection.
    // |options|  : The options for this function.
    // |callback| : Called with the number of bytes written.
    static void write(WriteOptions options,
                      optional SizeCallback callback);

    // Get the local Out of Band Pairing data.
    // |callback| : Called with the data.
    static void getLocalOutOfBandPairingData(
        OutOfBandPairingDataCallback callback);

    // Set the Out of Band Pairing data for a remote device.
    // Any previous Out Of Band Pairing Data for this device is overwritten.
    // |options|  : The options for this function.
    // |callback| : Called to indicate success or failure.
    static void setOutOfBandPairingData(SetOutOfBandPairingDataOptions options,
                                        optional ResultCallback callback);

    // Start discovery. Discovered devices will be returned via the
    // |onDeviceDiscovered| callback.  Discovery will fail to start if it is
    // already in progress.  Discovery can be resource intensive: stopDiscovery
    // should be called as soon as possible.
    // |options|  : The options for this function.
    // |callback| : Called to indicate success or failure.
    static void startDiscovery(
        StartDiscoveryOptions options,
        optional ResultCallback callback);

    // Stop discovery.
    // |callback| : Called to indicate success or failure.
    static void stopDiscovery(
        optional ResultCallback callback);
  };

  interface Events {
    // Fired when the state of the Bluetooth adapter changes.
    // |state| : The new state of the adapter.
    static void onAdapterStateChanged(AdapterState state);
  };
};