| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Use the <code>chrome.bluetooth</code> API to connect to a Bluetooth | 5 // Use the <code>chrome.bluetooth</code> API to connect to a Bluetooth |
| 6 // device. All functions report failures via chrome.runtime.lastError. | 6 // device. All functions report failures via chrome.runtime.lastError. |
| 7 namespace bluetooth { | 7 namespace bluetooth { |
| 8 // Allocation authorities for Vendor IDs. | 8 // Allocation authorities for Vendor IDs. |
| 9 enum VendorIdSource {bluetooth, usb}; | 9 enum VendorIdSource {bluetooth, usb}; |
| 10 | 10 |
| 11 // Common device types recognized by Chrome. | 11 // Common device types recognized by Chrome. |
| 12 enum DeviceType {computer, phone, modem, audio, carAudio, video, peripheral, | 12 enum DeviceType {computer, phone, modem, audio, carAudio, video, peripheral, |
| 13 joystick, gamepad, keyboard, mouse, tablet, | 13 joystick, gamepad, keyboard, mouse, tablet, |
| 14 keyboardMouseCombo}; | 14 keyboardMouseCombo}; |
| 15 | 15 |
| 16 // Information about the state of the Bluetooth adapter. | |
| 17 dictionary AdapterState { | 16 dictionary AdapterState { |
| 18 // The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'. | 17 // The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'. |
| 19 DOMString address; | 18 DOMString address; |
| 20 | 19 |
| 21 // The human-readable name of the adapter. | 20 // The human-readable name of the adapter. |
| 22 DOMString name; | 21 DOMString name; |
| 23 | 22 |
| 24 // Indicates whether or not the adapter has power. | 23 // Indicates whether or not the adapter has power. |
| 25 boolean powered; | 24 boolean powered; |
| 26 | 25 |
| 27 // Indicates whether or not the adapter is available (i.e. enabled). | 26 // Indicates whether or not the adapter is available (i.e. enabled). |
| 28 boolean available; | 27 boolean available; |
| 29 | 28 |
| 30 // Indicates whether or not the adapter is currently discovering. | 29 // Indicates whether or not the adapter is currently discovering. |
| 31 boolean discovering; | 30 boolean discovering; |
| 32 }; | 31 }; |
| 33 | 32 |
| 34 // Information about the state of a known Bluetooth device. | |
| 35 dictionary Device { | 33 dictionary Device { |
| 36 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. | 34 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. |
| 37 DOMString address; | 35 DOMString address; |
| 38 | 36 |
| 39 // The human-readable name of the device. | 37 // The human-readable name of the device. |
| 40 DOMString? name; | 38 DOMString? name; |
| 41 | 39 |
| 42 // The class of the device, a bit-field defined by | 40 // The class of the device, a bit-field defined by |
| 43 // http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband. | 41 // http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband. |
| 44 long? deviceClass; | 42 long? deviceClass; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 62 boolean? connected; | 60 boolean? connected; |
| 63 | 61 |
| 64 // UUIDs of protocols, profiles and services advertised by the device. | 62 // UUIDs of protocols, profiles and services advertised by the device. |
| 65 // For classic Bluetooth devices, this list is obtained from EIR data and | 63 // For classic Bluetooth devices, this list is obtained from EIR data and |
| 66 // SDP tables. For Low Energy devices, this list is obtained from AD and | 64 // SDP tables. For Low Energy devices, this list is obtained from AD and |
| 67 // GATT primary services. For dual mode devices this may be obtained from | 65 // GATT primary services. For dual mode devices this may be obtained from |
| 68 // both. | 66 // both. |
| 69 DOMString[]? uuids; | 67 DOMString[]? uuids; |
| 70 }; | 68 }; |
| 71 | 69 |
| 72 // Information about a Bluetooth profile. | |
| 73 dictionary Profile { | 70 dictionary Profile { |
| 74 // Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB | 71 // Unique profile identifier, e.g. 00001401-0000-1000-8000-00805F9B23FB |
| 75 DOMString uuid; | 72 DOMString uuid; |
| 76 | 73 |
| 77 // Human-readable name of the Profile, e.g. "Health Device" | 74 // Human-readable name of the Profile, e.g. "Health Device" |
| 78 DOMString? name; | 75 DOMString? name; |
| 79 | 76 |
| 80 // The RFCOMM channel id, used when the profile is to be exported to remote | 77 // The RFCOMM channel id, used when the profile is to be exported to remote |
| 81 // devices. | 78 // devices. |
| 82 long? channel; | 79 long? channel; |
| 83 | 80 |
| 84 // The LS2CAP PSM number, used when the profile is to be exported to remote | 81 // The LS2CAP PSM number, used when the profile is to be exported to remote |
| 85 // devices. | 82 // deviecs. |
| 86 long? psm; | 83 long? psm; |
| 87 | 84 |
| 88 // Specifies whether pairing (and encryption) is required to be able to | 85 // Specifies whether pairing (and encryption) is required to be able to |
| 89 // connect. | 86 // connect. |
| 90 boolean? requireAuthentication; | 87 boolean? requireAuthentication; |
| 91 | 88 |
| 92 // Specifies whether user authorization is required to be able to connect. | 89 // Specifies whether user authorization is required to be able to connect. |
| 93 boolean? requireAuthorization; | 90 boolean? requireAuthorization; |
| 94 | 91 |
| 95 // Specifies whether this profile will be automatically connected if any | 92 // Specifies whether this profile will be automatically connected if any |
| 96 // other profile of device also exporting this profile connects to the host. | 93 // other profile of device also exporting this profile connects to the host. |
| 97 boolean? autoConnect; | 94 boolean? autoConnect; |
| 98 | 95 |
| 99 // Specifies the implemented version of the profile. | 96 // Specifies the implemented version of the profile. |
| 100 long? version; | 97 long? version; |
| 101 | 98 |
| 102 // Specifies the profile-specific bit field of features the implementation | 99 // Specifies the profile-specific bit field of features the implementation |
| 103 // supports. | 100 // supports. |
| 104 long? features; | 101 long? features; |
| 105 }; | 102 }; |
| 106 | 103 |
| 107 // The socket properties specified in the $ref:update function. Each property | 104 dictionary ServiceRecord { |
| 108 // is optional. If a property value is not specified, the existing value if | 105 // The name of the service. |
| 109 // preserved when calling $ref:update. | 106 DOMString name; |
| 110 dictionary SocketProperties { | |
| 111 // Flag indicating whether the socket is left open when the event page of | |
| 112 // the application is unloaded (see <a | |
| 113 // href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App | |
| 114 // Lifecycle</a>). The default value is <code>false.</code> When the | |
| 115 // application is loaded, any sockets previously opened with persistent=true | |
| 116 // can be fetched with $ref:getSockets. | |
| 117 boolean? persistent; | |
| 118 | 107 |
| 119 // An application-defined string associated with the socket. | 108 // The UUID of the service. |
| 120 DOMString? name; | 109 DOMString? uuid; |
| 121 | |
| 122 // The size of the buffer used to receive data. The default value is 4096. | |
| 123 long? bufferSize; | |
| 124 }; | 110 }; |
| 125 | 111 |
| 126 dictionary Socket { | 112 dictionary Socket { |
| 127 // The socket identifier. | |
| 128 long id; | |
| 129 | |
| 130 // The remote Bluetooth device associated with this socket. | 113 // The remote Bluetooth device associated with this socket. |
| 131 Device device; | 114 Device device; |
| 132 | 115 |
| 133 // The remote Bluetooth uuid associated with this socket. | 116 // The remote Bluetooth profile associated with this socket. |
| 134 DOMString uuid; | 117 Profile profile; |
| 135 | 118 |
| 136 // Flag indicating whether the socket is left open when the application is | 119 // An identifier for this socket that should be used with the |
| 137 // suspended (see <code>SocketProperties.persistent</code>). | 120 // read/write/disconnect methods. |
| 138 boolean persistent; | 121 long id; |
| 139 | |
| 140 // Application-defined string associated with the socket. | |
| 141 DOMString? name; | |
| 142 | |
| 143 // The size of the buffer used to receive data. If no buffer size has been | |
| 144 // specified explictly, the field is not provided. | |
| 145 long? bufferSize; | |
| 146 | |
| 147 // Flag indicating whether a connected socket blocks its peer from sending | |
| 148 // more data (see <code>setPaused</code>). | |
| 149 boolean paused; | |
| 150 }; | 122 }; |
| 151 | 123 |
| 152 dictionary OutOfBandPairingData { | 124 dictionary OutOfBandPairingData { |
| 153 // Simple Pairing Hash C. | 125 // Simple Pairing Hash C. |
| 154 // Always 16 octets long. | 126 // Always 16 octets long. |
| 155 ArrayBuffer hash; | 127 ArrayBuffer hash; |
| 156 | 128 |
| 157 // Simple Pairing Randomizer R. | 129 // Simple Pairing Randomizer R. |
| 158 // Always 16 octets long. | 130 // Always 16 octets long. |
| 159 ArrayBuffer randomizer; | 131 ArrayBuffer randomizer; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 175 dictionary ConnectOptions { | 147 dictionary ConnectOptions { |
| 176 // The connection is made to |device|. | 148 // The connection is made to |device|. |
| 177 Device device; | 149 Device device; |
| 178 | 150 |
| 179 // The connection is made to |profile|. | 151 // The connection is made to |profile|. |
| 180 Profile profile; | 152 Profile profile; |
| 181 }; | 153 }; |
| 182 | 154 |
| 183 // Options for the disconnect function. | 155 // Options for the disconnect function. |
| 184 dictionary DisconnectOptions { | 156 dictionary DisconnectOptions { |
| 185 // The socket identifier. | 157 // The socket to disconnect. |
| 186 long socketId; | 158 Socket socket; |
| 159 }; |
| 160 |
| 161 // Options for the read function. |
| 162 dictionary ReadOptions { |
| 163 // The socket to read from. |
| 164 Socket socket; |
| 165 }; |
| 166 |
| 167 // Options for the write function. |
| 168 dictionary WriteOptions { |
| 169 // The socket to write to. |
| 170 Socket socket; |
| 171 |
| 172 // The data to write. |
| 173 ArrayBuffer data; |
| 187 }; | 174 }; |
| 188 | 175 |
| 189 // Options for the setOutOfBandPairingData function. | 176 // Options for the setOutOfBandPairingData function. |
| 190 dictionary SetOutOfBandPairingDataOptions { | 177 dictionary SetOutOfBandPairingDataOptions { |
| 191 // The address of the remote device that the data should be associated | 178 // The address of the remote device that the data should be associated |
| 192 // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'. | 179 // with. |deviceAddress| should be in the format 'XX:XX:XX:XX:XX:XX'. |
| 193 DOMString address; | 180 DOMString address; |
| 194 | 181 |
| 195 // The Out Of Band Pairing Data. If this is omitted, the data for the | 182 // The Out Of Band Pairing Data. If this is omitted, the data for the |
| 196 // device is cleared instead. | 183 // device is cleared instead. |
| 197 OutOfBandPairingData? data; | 184 OutOfBandPairingData? data; |
| 198 }; | 185 }; |
| 199 | 186 |
| 200 // Callback from the <code>getSocket</code> method. | |
| 201 // |socket| : Object containing the socket information. | |
| 202 callback GetSocketCallback = void (Socket socket); | |
| 203 | |
| 204 // Callback from the <code>getSockets</code> method. | |
| 205 // |sockets| : Array of object containing socket information. | |
| 206 callback GetSocketsCallback = void (Socket[] sockets); | |
| 207 | |
| 208 // Data from an <code>onReceive</code> event. | |
| 209 dictionary ReceiveInfo { | |
| 210 // The socket identifier. | |
| 211 long socketId; | |
| 212 | |
| 213 // The data received, with a maximum size of <code>bufferSize</code>. | |
| 214 ArrayBuffer data; | |
| 215 }; | |
| 216 | |
| 217 enum ReceiveError { | |
| 218 // The connection was disconnected. | |
| 219 disconnected, | |
| 220 | |
| 221 // A system error occurred and the connection may be unrecoverable. | |
| 222 system_error | |
| 223 }; | |
| 224 | |
| 225 // Data from an <code>onReceiveError</code> event. | |
| 226 dictionary ReceiveErrorInfo { | |
| 227 // The socket identifier. | |
| 228 long socketId; | |
| 229 | |
| 230 // The error message. | |
| 231 DOMString errorMessage; | |
| 232 | |
| 233 // An error code indicating what went wrong. | |
| 234 ReceiveError error; | |
| 235 }; | |
| 236 | |
| 237 // These functions all report failures via chrome.runtime.lastError. | 187 // These functions all report failures via chrome.runtime.lastError. |
| 238 interface Functions { | 188 interface Functions { |
| 189 // Registers the JavaScript application as an implementation for the given |
| 190 // Profile; if a channel or PSM is specified, the profile will be exported |
| 191 // in the host's SDP and GATT tables and advertised to other devices. |
| 192 static void addProfile(Profile profile, ResultCallback callback); |
| 193 |
| 194 // Unregisters the JavaScript application as an implementation for the given |
| 195 // Profile; only the uuid field of the Profile object is used. |
| 196 static void removeProfile(Profile profile, ResultCallback callback); |
| 197 |
| 239 // Get information about the Bluetooth adapter. | 198 // Get information about the Bluetooth adapter. |
| 240 // |callback| : Called with an AdapterState object describing the adapter | 199 // |callback| : Called with an AdapterState object describing the adapter |
| 241 // state. | 200 // state. |
| 242 static void getAdapterState(AdapterStateCallback callback); | 201 static void getAdapterState(AdapterStateCallback callback); |
| 243 | 202 |
| 244 // Get a list of Bluetooth devices known to the system, including paired | 203 // Get a list of Bluetooth devices known to the system, including paired |
| 245 // and recently discovered devices. | 204 // and recently discovered devices. |
| 246 // |callback| : Called when the search is completed. | 205 // |callback| : Called when the search is completed. |
| 247 static void getDevices(DevicesCallback callback); | 206 static void getDevices(DevicesCallback callback); |
| 248 | 207 |
| 249 // Get information about a Bluetooth device known to the system. | 208 // Get information about a Bluetooth device known to the system. |
| 250 // |deviceAddress| : Address of device to get. | 209 // |deviceAddress| : Address of device to get. |
| 251 // |callback| : Called with the Device object describing the device. | 210 // |callback| : Called with the Device object describing the device. |
| 252 static void getDevice(DOMString deviceAddress, DeviceCallback callback); | 211 static void getDevice(DOMString deviceAddress, DeviceCallback callback); |
| 253 | 212 |
| 254 // Registers the JavaScript application as an implementation for the given | |
| 255 // Profile; if a channel or PSM is specified, the profile will be exported | |
| 256 // in the host's SDP and GATT tables and advertised to other devices. | |
| 257 static void addProfile(Profile profile, ResultCallback callback); | |
| 258 | |
| 259 // Unregisters the JavaScript application as an implementation for the given | |
| 260 // Profile; only the uuid field of the Profile object is used. | |
| 261 static void removeProfile(Profile profile, ResultCallback callback); | |
| 262 | |
| 263 // Connect to a service on a device. | 213 // Connect to a service on a device. |
| 264 // |options| : The options for the connection. | 214 // |options| : The options for the connection. |
| 265 // |callback| : Called to indicate success or failure. | 215 // |callback| : Called to indicate success or failure. |
| 266 static void connect(ConnectOptions options, | 216 static void connect(ConnectOptions options, |
| 267 ResultCallback callback); | 217 ResultCallback callback); |
| 268 | 218 |
| 269 // Closes a Bluetooth connection. | 219 // Close a Bluetooth connection. |
| 270 // |options| : The options for this function. | 220 // |options| : The options for this function. |
| 271 // |callback| : Called to indicate success or failure. | 221 // |callback| : Called to indicate success or failure. |
| 272 static void disconnect(DisconnectOptions options, | 222 static void disconnect(DisconnectOptions options, |
| 273 optional ResultCallback callback); | 223 optional ResultCallback callback); |
| 274 | 224 |
| 275 // Sends data to a Bluetooth connection. | 225 // Read data from a Bluetooth connection. The |callback| will be called |
| 276 // |socketId| : The socket identifier. | 226 // with the current data in the buffer even if it is empty. This function |
| 277 // |data| : The data to send. | 227 // should be polled to read incoming data. |
| 278 // |callback| : Called with the number of bytes sent. | 228 // |options| : The options for this function. |
| 279 static void send(long socketId, | 229 // |callback| : Called with the data read from the socket buffer. |
| 280 ArrayBuffer data, | 230 static void read(ReadOptions options, |
| 281 optional SizeCallback callback); | 231 DataCallback callback); |
| 282 | 232 |
| 283 // Updates the socket properties. | 233 // Write data to a Bluetooth connection. |
| 284 // |socketId| : The socket identifier. | 234 // |options| : The options for this function. |
| 285 // |properties| : The properties to update. | 235 // |callback| : Called with the number of bytes written. |
| 286 // |callback| : Called when the properties are updated. | 236 static void write(WriteOptions options, |
| 287 static void updateSocket(long socketId, | 237 optional SizeCallback callback); |
| 288 SocketProperties properties, | |
| 289 optional ResultCallback callback); | |
| 290 | |
| 291 // Enables or disables the application from receiving messages from its | |
| 292 // peer. The default value is <code>false</code>. Pausing a socket is | |
| 293 // typically used by an application to throttle data sent by its peer. When | |
| 294 // a socket is paused, no $ref:onReceive event is raised. When a socket is | |
| 295 // connected and un-paused, $ref:onReceive events are raised again when | |
| 296 // messages are received. | |
| 297 static void setSocketPaused(long socketId, | |
| 298 boolean paused, | |
| 299 optional ResultCallback callback); | |
| 300 | |
| 301 // Retrieves the state of the given socket. | |
| 302 // |socketId| : The socket identifier. | |
| 303 // |callback| : Called when the socket state is available. | |
| 304 static void getSocket(long socketId, | |
| 305 GetSocketCallback callback); | |
| 306 | |
| 307 // Retrieves the list of currently opened sockets owned by the application. | |
| 308 // |callback| : Called when the list of sockets is available. | |
| 309 static void getSockets(GetSocketsCallback callback); | |
| 310 | 238 |
| 311 // Get the local Out of Band Pairing data. | 239 // Get the local Out of Band Pairing data. |
| 312 // |callback| : Called with the data. | 240 // |callback| : Called with the data. |
| 313 static void getLocalOutOfBandPairingData( | 241 static void getLocalOutOfBandPairingData( |
| 314 OutOfBandPairingDataCallback callback); | 242 OutOfBandPairingDataCallback callback); |
| 315 | 243 |
| 316 // Set the Out of Band Pairing data for a remote device. | 244 // Set the Out of Band Pairing data for a remote device. |
| 317 // Any previous Out Of Band Pairing Data for this device is overwritten. | 245 // Any previous Out Of Band Pairing Data for this device is overwritten. |
| 318 // |options| : The options for this function. | 246 // |options| : The options for this function. |
| 319 // |callback| : Called to indicate success or failure. | 247 // |callback| : Called to indicate success or failure. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 350 static void onDeviceChanged(Device device); | 278 static void onDeviceChanged(Device device); |
| 351 | 279 |
| 352 // Fired when a Bluetooth device that was previously discovered has been | 280 // Fired when a Bluetooth device that was previously discovered has been |
| 353 // out of range for long enough to be considered unavailable again, and | 281 // out of range for long enough to be considered unavailable again, and |
| 354 // when a paired device is removed. | 282 // when a paired device is removed. |
| 355 static void onDeviceRemoved(Device device); | 283 static void onDeviceRemoved(Device device); |
| 356 | 284 |
| 357 // Fired when a connection has been made for a registered profile. | 285 // Fired when a connection has been made for a registered profile. |
| 358 // |socket| : The socket for the connection. | 286 // |socket| : The socket for the connection. |
| 359 static void onConnection(Socket socket); | 287 static void onConnection(Socket socket); |
| 360 | |
| 361 // Event raised when data has been received for a given socket. | |
| 362 // |info| : The event data. | |
| 363 static void onReceive(ReceiveInfo info); | |
| 364 | |
| 365 // Event raised when a network error occured while the runtime was waiting | |
| 366 // for data on the socket. Once this event is raised, the socket is set to | |
| 367 // <code>paused</code> and no more <code>onReceive</code> events are raised | |
| 368 // for this socket. | |
| 369 // |info| : The event data. | |
| 370 static void onReceiveError(ReceiveErrorInfo info); | |
| 371 }; | 288 }; |
| 372 }; | 289 }; |
| OLD | NEW |