module bluetooth { interface LocalDevice { readonly attribute DOMString name; readonly attribute DOMString address; attribute unsigned long deviceClass setraises(SecurityError, DeviceAPIError); attribute unsigned long discoveryMode setraises(SecurityError, DeviceAPIError); readonly attribute RemoteDeviceArray cachedDevices; readonly attribute RemoteDeviceArray preknownDevices; readonly attribute RemoteDeviceArray trustedDevices; readonly attribute int l2cap_max_receiveMTU; readonly attribute boolean master_switch; readonly attribute int max_connected_devices; readonly attribute int sd_max; readonly attribute boolean connected_inquiry; readonly attribute boolean connected_inquiry_scan; readonly attribute boolean connected_page; readonly attribute boolean connected_page_scan; PendingOperation findDevices(in SuccessCallback successCallback, in ErrorCallback errorCallback, in DiscoveryListener listener, in Map connectOptions) raises(DeviceAPIError); PendingOperation findService(in ServiceSuccessCallback successCallback, in ErrorCallback errorCallback, in DOMString address, in DOMString uuid, in Map searchOptions, in Map connectOptions) raises(DeviceAPIError); PendingOperation connect(in SocketSuccessCallback successCallback, in ErrorCallback errorCallback, in ReadWriteCallback rwCallback, in DOMString uri, in Map connectOptions); PendingOperation listen(in SocketSuccessCallback successCallback, in ErrorCallback errorCallback, in ReadWriteCallback rwCallback, in DOMString uuid, in Map serviceOptions, in Map connectOptions); }; interface DiscoveryListener { const unsigned long NOT_DISCOVERABLE = 0; const unsigned long GIAC = 0x9E8B33; const unsigned long LIAC = 0x9E8B00; const unsigned long AC_START_RANGE = 0x9E8B00; const unsigned long AC_END_RANGE = 0x9E8B3F; void deviceDiscovered(in RemoteDevice device); }; [Callback=FunctionOnly, NoInterfaceObject] interface ServiceSuccessCallback { void onSuccess(in DOMString uri); }; [Callback=FunctionOnly, NoInterfaceObject] interface ReadWriteCallback { void recevied(in Socket socket); void sent(in Socket socket,in int len); void error(in Socket socket,in Object e); }; [Callback=FunctionOnly, NoInterfaceObject] interface SocketSuccessCallback { void onSuccess(in Socket uri); }; typedef sequence<RemoteDevice> RemoteDeviceArray; interface RemoteDevice { readonly attribute boolean trusted; readonly attribute DOMString name; readonly attribute DOMString address; readonly attribute unsigned long deviceClass; readonly attribute boolean authenticated; readonly attribute boolean authorized; readonly attribute boolean encrypted; }; interface Socket { readonly attribute RemoteDevice device; readonly attribute PendingOperation server; readonly attribute Stream stream; void close() raises(DeviceAPIError); }; interface Stream { readonly attribute boolean eof; readonly attribute unsigned long available; PendingOperation close(in SuccessCallback successCallback, in ErrorCallback errorCallback); PendingOperation flush(in SuccessCallback successCallback, in ErrorCallback errorCallback); ByteArray read(in unsigned long byteCount) raises(DeviceAPIError); PendingOperation write(in SuccessCallback successCallback, in ErrorCallback errorCallback, in ByteArray byteData) raises(DeviceAPIError); }; interface DeviceClass { const unsigned long SERVICE_MASK = 0xFFE000; const unsigned long SERVICE_POSITIONING = 0x10000; const unsigned long SERVICE_NETWORKING = 0x20000; const unsigned long SERVICE_RENDERING = 0x40000; const unsigned long SERVICE_CAPTURING = 0x80000; const unsigned long SERVICE_OBJECT_TRANSFER = 0x100000; const unsigned long SERVICE_AUDIO = 0x200000; const unsigned long SERVICE_TELEPHONY = 0x400000; const unsigned long SERVICE_INFORMATION = 0x800000; const unsigned long MAJOR_DEVICE_MASK = 0x1F00; const unsigned long MISCELLANEOUS_MAJOR_DEVICE = 0x000; const unsigned long COMPUTER_MAJOR_DEVICE = 0x100; const unsigned long PHONE_MAJOR_DEVICE = 0x200; const unsigned long NETWORKING_MAJOR_DEVICE = 0x300; const unsigned long AUDIO_VISUAL_MAJOR_DEVICE = 0x400; const unsigned long PERIPHERAL_MAJOR_DEVICE = 0x500; const unsigned long IMAGING_MAJOR_DEVICE = 0x600; const unsigned long WEARABLE_MAJOR_DEVICE = 0x700; const unsigned long TOY_MAJOR_DEVICE = 0x800; const unsigned long UNCATEGORIZED_MAJOR_DEVICE = 0x1F00; const unsigned long MINOR_DEVICE_MASK = 0xFC; }; }; BONDI bluetooth API.

This API provides access to the bluetooth functionality. This set of interfaces provides a framework for short range device and service discovery of other bluetooth devices.

Once a service has been discovered it is then possible to connect to this service and exchange data.

Call to LocalDevice.findDevices,LocalDevice.findService Jim O'Leary <jim.oleary@rococosoft.com> 1.5
interface LocalDevice { readonly attribute DOMString name; readonly attribute DOMString address; attribute unsigned long deviceClass setraises(SecurityError, DeviceAPIError); attribute unsigned long discoveryMode setraises(SecurityError, DeviceAPIError); readonly attribute RemoteDeviceArray cachedDevices; readonly attribute RemoteDeviceArray preknownDevices; readonly attribute RemoteDeviceArray trustedDevices; readonly attribute int l2cap_max_receiveMTU; readonly attribute boolean master_switch; readonly attribute int max_connected_devices; readonly attribute int sd_max; readonly attribute boolean connected_inquiry; readonly attribute boolean connected_inquiry_scan; readonly attribute boolean connected_page; readonly attribute boolean connected_page_scan; PendingOperation findDevices(in SuccessCallback successCallback, in ErrorCallback errorCallback, in DiscoveryListener listener, in Map connectOptions) raises(DeviceAPIError); PendingOperation findService(in ServiceSuccessCallback successCallback, in ErrorCallback errorCallback, in DOMString address, in DOMString uuid, in Map searchOptions, in Map connectOptions) raises(DeviceAPIError); PendingOperation connect(in SocketSuccessCallback successCallback, in ErrorCallback errorCallback, in ReadWriteCallback rwCallback, in DOMString uri, in Map connectOptions); PendingOperation listen(in SocketSuccessCallback successCallback, in ErrorCallback errorCallback, in ReadWriteCallback rwCallback, in DOMString uuid, in Map serviceOptions, in Map connectOptions); }; Interface for the local bluetooth radio readonly attribute DOMString name; The local device friendly name alert("friendly name : " + bondi.bluetooth.name); readonly attribute DOMString address; The local device bluetooth address

The Bluetooth address will never be null. The Bluetooth address will be 12 characters long. Valid characters are 0-9 and A-F.

alert(bondi.bluetooth.LocalDevice.address);
attribute unsigned long deviceClass setraises(SecurityError, DeviceAPIError); The local device class

The Device Class consists of :
    service classes : e.g. poistioning, networking etc
    major device classes : e.g. computer , phone etc
    minor device classes : the meaning of these bits depends on the major device class

var serviceClass = bondi.bluetooth.deviceClass & 0xFFE000; var services = ""; if (serviceClass & bondi.bluetooth.DeviceClass.SERVICE_POSITIONING !== 0) { services += "Posiitioning"; } if (serviceClass & bondi.bluetooth.DeviceClass.SERVICE_NETWORKING !== 0) { services += "Networking"; } // and the rest alert("Local Device Supports the following services " + services);
attribute unsigned long discoveryMode setraises(SecurityError, DeviceAPIError); set the Local Devices discovery mode

The dicoverable mode of the device can be one of :
    DiscoveryAgent.NOT_DISCOVERABLE : the device cannot be found by other devices (i.e. it won't reposnd to inquiry scans)
    DiscoveryListener.GIAC : the device responds to General/Unlimited Inquiry Access Code inquiries, i.e. the device is discoverable for an indefinite amount of time
    DiscoveryListener.LIAC : the device responds to Limited Inquiry Access Code inquiries, i.e the device is discoverable for a limited amount of time (180 seconds).
    value in the range 0x9E8B00 to 0x9E8B3F
TODO :

bondi.bluetooth.discoveryMode = bondi.bluetooth.DiscoveryListener.LIAC;
readonly attribute RemoteDeviceArray cachedDevices; The cached devices.

A list of devices that were found in previous inquiries.

readonly attribute RemoteDeviceArray preknownDevices; The pre-known devices.

A list of pre-known devices.

readonly attribute RemoteDeviceArray trustedDevices; The trusted devices.

A list of trusted devices.

readonly attribute int l2cap_max_receiveMTU; the maiximum supported MTU alert(bondi.bluetooth.l2cap_max_receiveMTU); readonly attribute boolean master_switch; true if this device support role switch alert(bondi.bluetooth.master_switch); readonly attribute int max_connected_devices; The maximum number of connected device.

This value can be greater than 7 if parking is supported.

alert(bondi.bluetooth.max_connected_devices);
readonly attribute int sd_max; The maximum number of simultaneous service searches. alert(bondi.bluetooth.sd_max); readonly attribute boolean connected_inquiry; true if device discovery supported while connceted to another device. alert(bondi.bluetooth.connected_inquiry); readonly attribute boolean connected_inquiry_scan; true if this device will respond to a device discovery while connceted to another device. alert(bondi.bluetooth.connected_inquiry_scan); readonly attribute boolean connected_page; true if this device can do a page scan while connceted to another device.

page scanning is required to retrieve the friendly name of another device.

alert(bondi.bluetooth.connected_page);
readonly attribute boolean connected_page_scan; true if this device can respond a page scan while connceted to another device.

page scanning is required to retrieve the friendly name of another device. #*

alert(bondi.bluetooth.connected_page_scan);
PendingOperation findDevices(in SuccessCallback successCallback, in ErrorCallback errorCallback, in DiscoveryListener listener, in Map connectOptions) raises(DeviceAPIError); Search for devices in the area.

Start an inquiry in the specified mode. Use the listener to handle device and service discovery events.

TODO:

var listener = { discovered: {}, deviceDiscovered: function (device) { this.discovered[this.discovered.length] = device; } }; function errorCB(err) { alert("BONDI bluetooth API device discovery failed : " + err.message); } function successCB() { for (var i = 0; i < listener.devices.length; i++) { alert(listener.devices[i].name); } } bondi.bluetooth.findDevices(successCB, errorCB, listener); // find devices in LIAC mode for 60 seconds bondi.bluetooth.findDevices(successCB, errorCB, listener, {mode: bondi.bluetooth.DiscoveryAgent.LIAC}); // find devices for 12 seconds only bondi.bluetooth.findDevices(successCB, errorCB, listener, {timeout: 12000}); // find devices until operation is cancelled var operation = bondi.bluetooth.findDevices(successCB, errorCB, listener, {timeout: 0});

the callback interface

the callback interface

the discovery callback interface

a hash of other options, including

      * accessCode(unsigned long) : the inquiry type, either GIAC or LIAC or in the range 0x9E8B00
to 0x9E8B3F.defaults GIAC.
      * timeout(unsigned long) : the max amount of time (in millis) to spend searching. defaults 60 seconds,0 => forever.

INVALID_ARGUMENT_ERROR if the params are invalid (for example invalid accesss code, listener is undefined).

PendingOperation findService(in ServiceSuccessCallback successCallback, in ErrorCallback errorCallback, in DOMString address, in DOMString uuid, in Map searchOptions, in Map connectOptions) raises(DeviceAPIError); Find a matching service on a remote device.

search a device to determine if it hosts the service specified by the UUID. The uuid must be in the ServiceClassIDList on the remote host. This method will also search for the optional protocol UUID (defaults to rfcomm) and optional name. If multiple services match then the first service is returned.

function errorCB(err) { alert("BONDI bluetooth API device discovery failed : " + err.message); } function successCB(uri) { if (uri !== undefined) { alert("bondi.bluetooth : discovered service : " + uri); } else { alert("bondi.bluetooth : no such service"); } } // search for rfcomm service with 16 bit UUID "E205" var operation = bondi.bluetooth.findService(successCB, errorCB, "112233445566", "E205"); // 32 bit UUID, same search as above var operation = bondi.bluetooth.findService(successCB, errorCB, "112233445566", "000000E205"); // 128 bit UUID but same search as above var operation = bondi.bluetooth.findService(successCB, errorCB, "112233445566", "0000E205-0000-1000-8000-00805F9B34FB"); // search for an rfcomm service named "bondi" bondi.bluetooth.findService(successCB, errorCB, "112233445566", "E205", {name: "bondi"}); // search for an rfcomm connection, the generated uri specifies that the connection // must be encrypted bondi.bluetooth.findService(successCB, errorCB, "112233445566", "E205", {}, {encrypted: true});

a pending operation, which can be used to cancel the service search

the success callback

the error callback

the bluetooth address of the host to search (default to nil).

the uuid to search the ServiceClassIDList

a map of search related options

      * name : if a name is provided then the name must match then service name in the remote service record. If name is undefined (default) then the name is not checked.
      * protocol : the type of connection to search for. It must be one of :
           - btspp : Serial Port Profile (Rfcomm)the default
           - btgoep : Obbex Profile NOT SUPPORTED in this version
           - btl2cap : L2cap Profile NOT SUPPORTED in this version

a map of connection related options1

      * authenticate : does the service need to authenticated, defaults to false
      * encrypt : does the service need to encrypted, defaults to false
      * master : does the client need to be master. (defaults to undefined, which means dont care )). If set to true then the client must be master and will not accept a role switch (not recommended as it will limit the number of connections the server can accept and it might cause the connection to fail if the server wants to be the master). If set to false then the client doesn't care.

PendingOperation connect(in SocketSuccessCallback successCallback, in ErrorCallback errorCallback, in ReadWriteCallback rwCallback, in DOMString uri, in Map connectOptions); Create a socket and connect to the remote service for this bluetooth uri connector string.

Create a new (connected) socket representing the a connection to the remote service.

TODO:

var uri; // find the service first var operation; function successCB(socket) { if (socket.operation === undefined) { alert("bondi.bluetooth connection to " + socket.device.address); } else { alert("bondi.bluetooth connection from " + socket.device.address); } } function errorCB(err) { alert("BONDI bluetooth connection failed : " + err.message); } var dataHandler = { received : function (socket) { var len = socket.byteAvailable(); alert("bondi.bluetooth : " + len + " bytes available"); alert(socket.read().toString()); }, sent : function (socket, len) { alert("bondi.bluetooth : " + len + " bytes sent"); }, error : function (socket, e) { alert("bondi.bluetooth : error " + e.msg); } }; try { operation = bondi.bluetooth.connect(successCB, errorCB, uri); } catch (e) { alert(e.message); }

the callback interface

the callback interface

the data callback that is used to handle events on the sockets

the bluetooth connector string

a map of connection related options1

      -timeout : the amount o f time in millis to wait, -1 => forever this is the default

PendingOperation listen(in SocketSuccessCallback successCallback, in ErrorCallback errorCallback, in ReadWriteCallback rwCallback, in DOMString uuid, in Map serviceOptions, in Map connectOptions); Create a server socket for a service.

Create a new server socket representing a service called name with the specified uuid in the service class idl ist.

TODO:

var operation; function errorCB(err) { alert("BONDI bluetooth server connection failed : " + err.message); } function successCB(socket) { if (socket.operation === undefined) { alert("bondi.bluetooth connection to " + socket.device.address); } else { alert("bondi.bluetooth connection from " + socket.device.address); } } var dataHandler = { received : function (socket) { var len = socket.byteAvailable(); alert("bondi.bluetooth : " + len + " bytes available"); alert(socket.read().toString()); }, sent : function (socket, len) { alert("bondi.bluetooth : " + len + " bytes sent"); }, error : function (socket, e) { alert("bondi.bluetooth : error " + e.msg); } }; try { operation = bondi.bluetooth.listen(successCB, errorCB, dataHandler, "E205"); } catch (e) { alert(e.message); } // or a service with a name try { operation = bondi.bluetooth.listen(successCB, errorCB, dataHandler, "E205", {name: "bondi"}); } catch (e) { alert(e.message); } // or a service that must be encrypted try { operation = bondi.bluetooth.listen(successCB, errorCB, dataHandler, "E205", {}, {encrypted: true}); } catch (e) { alert(e.message); }

a pending operation, which can be used to cancel the listen.

the success callback

the error callback

the data callback that is used to handle events on the sockets created by this listener

the uuid to register in the ServiceClassIDList

a map of service options, including
      - name : if a name is provided then it will be added to the service record and can be used to further narrow the client search criteria (defaults to nothing).
      - protocol : the type of connection to search for. It must be one of :            * btspp : Serial Port Profile (Rfcomm)the default
           *btgoep : Obbex Profile NOT SUPPORTED in this version
           *btl2cap : L2cap Profile NOT SUPPORTED in this version

a map of connection related options, including

      - authenticate : does the service need to authenticated, defaults to false
      - encrypt : does the service need to encrypted, defaults to false
      - master : does the client need to be master. master defaults to false. If set to true then the client must be master and will not accept a role switch (not recommended as it will limit the number of connections the server can accept and it might cause the connection to fail if the server wants/needs to be the master). If set to false then the client doesn't care.

interface DiscoveryListener { const unsigned long NOT_DISCOVERABLE = 0; const unsigned long GIAC = 0x9E8B33; const unsigned long LIAC = 0x9E8B00; const unsigned long AC_START_RANGE = 0x9E8B00; const unsigned long AC_END_RANGE = 0x9E8B3F; void deviceDiscovered(in RemoteDevice device); }; Discovery event listener class.

This listener defines methods to handle device discovery notifications. Note that it is possible that no device is found so this callback may never be called.

var listener = { discovered: [], deviceDiscovered: function (device) { this.discovered[this.discovered.length] = device; alert("Discovered device " + device.address); } }; function errorCB(err) { alert("BONDI bluetooth API device discovery failed : " + err.message); } function successCB(devices) { alert("discovery complete"); } bondi.bluetooth.findDevices(successCB, errorCB, listener);
const unsigned long NOT_DISCOVERABLE = 0; Takes the device out of discoverable mode. const unsigned long GIAC = 0x9E8B33; General/Unlimited Inquiry Access Code

This is used to specify the type of inquiry to complete or respond to.

const unsigned long LIAC = 0x9E8B00; Limited Dedicated Inquiry Access Code

This is used to specify the type of inquiry to complete or respond to.

const unsigned long AC_START_RANGE = 0x9E8B00; Access code range starting value. const unsigned long AC_END_RANGE = 0x9E8B3F; Access code range end value. void deviceDiscovered(in RemoteDevice device); Method invoked when a new device is discovered.

A new device is in range.

the device.

[Callback=FunctionOnly, NoInterfaceObject] interface ServiceSuccessCallback { void onSuccess(in DOMString uri); }; Success callback for service discovery.

If the service couldn't be found then the service uri may be undefined.

void onSuccess(in DOMString uri); Method invoked at the end of a successfull service search. var uuid = "E205"; var address = "112233445566"; function errorCB(err) { alert("BONDI bluetooth API device discovery failed : " + err.message); } function successCB(uri) { if (uri !== undefined) { alert("bondi.bluetooth : discovered service " + uri); } else { alert("bondi.bluetooth : no such service " + uuid + " on " + address); } } bondi.bluetooth.findService(successCB, errorCB, uuid, address);

the remote service connector string, will be undefined if no service found.

[Callback=FunctionOnly, NoInterfaceObject] interface ReadWriteCallback { void recevied(in Socket socket); void sent(in Socket socket,in int len); void error(in Socket socket,in Object e); }; Callback interface used to indicate when data is read or written var dataHandler = { name : function (socket) { return (socket.device.name === undefined ? socket.device.address : socket.device.name); }, received : function (socket) { var len, str; len = socket.byteAvailable(); str = "p class='read'>" + socket.read().toString() + "/p>"; alert("bondi.bluetooth : " + len + " bytes available from " + this.name(socket)); document.getElementById("content").innerHTML += str; }, sent : function (socket, len) { alert("bondi.bluetooth : " + len + " bytes sent to " + this.name(socket)); document.getElementById("sendBtn").className = "enabled"; } }; document.getElementById("sendBtn").className = "disabled"; try { bondi.bluetooth.connect(successCB, errorCB, dataHandler, uri); } catch (e) { alert("error connecting to remote device " + e); } document.getElementById("sendBtn").className = "enabled"; void recevied(in Socket socket); This method is invoked when data is available to read.

the socket that has data available

void sent(in Socket socket,in int len); This method is invoked when data was sent

the socket that sent the data

the amount of data sent

void error(in Socket socket,in Object e); This method is invoked when an error occurrs

the socket that sent the data

the error

[Callback=FunctionOnly, NoInterfaceObject] interface SocketSuccessCallback { void onSuccess(in Socket uri); }; Success callback for socket connections (both client and server). void onSuccess(in Socket uri); Method invoked when a connection is created (either through a call to create or a listen). function errorCB(err) { alert("BONDI bluetooth API device discovery failed : " + err.message); } function successCB(socket) { if (socket.operation === undefined) { alert("bondi.bluetooth : connection to " + socket.device.address); } else { alert("bondi.bluetooth : connection from " + socket.device.address); } } // service uri came from findSrvice call bondi.bluetooth.connect(successCB, errorCB, uri); // listen for incoming rfcomm connections from clients bondi.bluetooth.listen(successCB, errorCB, "E205");

the remote service connector string

typedef sequence<RemoteDevice> RemoteDeviceArray; Array of remote devices.

This array type is used to get cached, preknown and trusted devices.

interface RemoteDevice { readonly attribute boolean trusted; readonly attribute DOMString name; readonly attribute DOMString address; readonly attribute unsigned long deviceClass; readonly attribute boolean authenticated; readonly attribute boolean authorized; readonly attribute boolean encrypted; }; Interface representing a Remote Bluetooth device readonly attribute boolean trusted; Is this bluetooth device trusted readonly attribute DOMString name; Get the remote device friendly name

The remote device will only be contacted if the name isn't already known.

readonly attribute DOMString address; The local device bluetooth address

The Bluetooth address will never be null. The Bluetooth address will be 12 characters long. Valid characters are 0-9 and A-F.

var devices = bondi.bluetooth.preknownDevices; var str = "div id='title'>Pre Known Devices(" + devices.length + ")/div>"; str += "div id='preknown'>"; str += "table>"; var i; try { for (i = 0; i devices.length; i++) { var d = devices[i]; str += "tr>td>a href='javascript:displayDetails(" + d.address + ");'>" + d.name + "/a>/td>/tr>"; } } catch (e) { alert(e.message); } str += "/table>";
readonly attribute unsigned long deviceClass; Get the device class readonly attribute boolean authenticated; Is the connection to the remote device authenticated

Authentication is a means of verifying the identity of a remote device.

readonly attribute boolean authorized; Is this device authorized

Some Bluetooth systems may allow the user to permanently authorize a remote device for all local services. When a device is authorized in this way, it is known as a "trusted device".

readonly attribute boolean encrypted; Is data send or received from this device encrypted.

Note : encrypting any connection to a remote device (through the connectOptions on connect or listen) implies all data transfered between thee 2 devices is encrtypted.

interface Socket { readonly attribute RemoteDevice device; readonly attribute PendingOperation server; readonly attribute Stream stream; void close() raises(DeviceAPIError); }; Socket interface .

This interface represents a connection between the Local device and a Remote device.

readonly attribute RemoteDevice device; The device on the other end of the connection readonly attribute PendingOperation server; The pending operation for the listen.

This value is undefined if the socket is as a result of calling connect.

readonly attribute Stream stream; The stream. void close() raises(DeviceAPIError); Close the socket.
interface Stream { readonly attribute boolean eof; readonly attribute unsigned long available; PendingOperation close(in SuccessCallback successCallback, in ErrorCallback errorCallback); PendingOperation flush(in SuccessCallback successCallback, in ErrorCallback errorCallback); ByteArray read(in unsigned long byteCount) raises(DeviceAPIError); PendingOperation write(in SuccessCallback successCallback, in ErrorCallback errorCallback, in ByteArray byteData) raises(DeviceAPIError); }; Bluetooth Stream API.

A Stream represents a handle to a connected service for read and/or write operations.

A series of read/write methods are available that permit both binary and text to be processed.

Once a stream is closed, any operation attempted on this stream will result in a normal JavaScript error.

readonly attribute boolean eof; Indicates whether or not the stream has been closed.

true if the stream was closed.

var stream; if (stream.eof) { // stream has been read completely }
readonly attribute unsigned long available; Returns the number of bytes that are available for reading from the stream.

The number of bytes available for reading is the maximum amount of bytes that can be read in the next read operation.

-1 if eof is true.

alert(stream.available); // displays the available bytes to be read
PendingOperation close(in SuccessCallback successCallback, in ErrorCallback errorCallback); Closes this Stream.

Flushes any pending buffered writes and closes the Stream. Always succeeds. Note that pending writes will not succeed.

function errorCB(err) { alert("bluetooth.bondi stream close failed " + err.message); } function successCB() { alert("bluetooth.bondi stream closed"); } // closes this stream, subsequent access to stream // throws exception stream.close(successCB, errorCB);

a pending operation, which can be used to cancel the service search

the success callback

the error callback

PendingOperation flush(in SuccessCallback successCallback, in ErrorCallback errorCallback); Flush the stream.

Flushes any pending writes.

function errorCB(err) { alert("bluetooth.bondi stream flush failed " + err.message); } function successCB() { alert("bluetooth.bondi stream flushed"); } stream.flush(successCB, errorCB);

a pending operation, which can be used to cancel the service search

the success callback

the error callback

ByteArray read(in unsigned long byteCount) raises(DeviceAPIError); Reads the specified number of bytes from this Stream.

If 0 is supplied it will read all available bytes in a single read operation.

// reads up to 256 bytes from the stream var raw = stream.readBytes(256); for (var i = 0; i < raw.length; i++) { // raw[i] contains the i-th byte of the current data chunk }

the result of read bytes as a byte (or number) array.

number of bytes being read. If 0(default value)it will read all the available data.

IO_ERROR if an error occurs during readBytes.

PendingOperation write(in SuccessCallback successCallback, in ErrorCallback errorCallback, in ByteArray byteData) raises(DeviceAPIError); Writes the specified bytes to this Stream. var stream; var bytes = stream.readBytes(256); function errorCB(err) { alert("bluetooth.bondi write failed " + err.message); } function successCB() { alert("bluetooth.bondi write completed"); } // writes the bytes read from in to out stream.writeBytes(successCB, errorCB, bytes);

the byte data array being written.

IO_ERROR if an error occurs during writeBytes.

interface DeviceClass { const unsigned long SERVICE_MASK = 0xFFE000; const unsigned long SERVICE_POSITIONING = 0x10000; const unsigned long SERVICE_NETWORKING = 0x20000; const unsigned long SERVICE_RENDERING = 0x40000; const unsigned long SERVICE_CAPTURING = 0x80000; const unsigned long SERVICE_OBJECT_TRANSFER = 0x100000; const unsigned long SERVICE_AUDIO = 0x200000; const unsigned long SERVICE_TELEPHONY = 0x400000; const unsigned long SERVICE_INFORMATION = 0x800000; const unsigned long MAJOR_DEVICE_MASK = 0x1F00; const unsigned long MISCELLANEOUS_MAJOR_DEVICE = 0x000; const unsigned long COMPUTER_MAJOR_DEVICE = 0x100; const unsigned long PHONE_MAJOR_DEVICE = 0x200; const unsigned long NETWORKING_MAJOR_DEVICE = 0x300; const unsigned long AUDIO_VISUAL_MAJOR_DEVICE = 0x400; const unsigned long PERIPHERAL_MAJOR_DEVICE = 0x500; const unsigned long IMAGING_MAJOR_DEVICE = 0x600; const unsigned long WEARABLE_MAJOR_DEVICE = 0x700; const unsigned long TOY_MAJOR_DEVICE = 0x800; const unsigned long UNCATEGORIZED_MAJOR_DEVICE = 0x1F00; const unsigned long MINOR_DEVICE_MASK = 0xFC; };

DeviceClass comprises of 3 components : Service Classes - The major service classes define the services available on a device, e.g. positioning , networking etc. The device can have MANY service classes, i.e. it can provide any number of services. Major Device class - A device can only have one major device class e.g. computer , phone etc. Minor Device class - the meaning of this value depends on the major device class. For example if the major device class is imaging then the minor device class then specifies whether the device is a camera, scanner, or printer etc.

const unsigned long SERVICE_MASK = 0xFFE000;

The mask to get the Service bits.

const unsigned long SERVICE_POSITIONING = 0x10000;

Represents the Positioning Major Service Class.

The value of SERVICE_POSITIONING is 0x10000 (65536).

const unsigned long SERVICE_NETWORKING = 0x20000;

Represents the Networking (LAN, Ad hoc, ...) Major Service Class.

The value of SERVICE_NETWORKING is 0x20000 (131072).

const unsigned long SERVICE_RENDERING = 0x40000;

Represents the Rendering (Printing, Speaker, ...) Major Service Class.

The value of SERVICE_RENDERING is 0x40000 (262144).

const unsigned long SERVICE_CAPTURING = 0x80000;

Represents the Capturing (Scanner, Microphone, ...) Major Service Class.

The value of SERVICE_CAPTURING is 0x80000 (524288).

const unsigned long SERVICE_OBJECT_TRANSFER = 0x100000;

Represents the Object Transfer (v-Inbox, v-Folder, ...) Major Service Class.

The value of SERVICE_OBJECT_TRANSFER is 0x100000 (1048576).

const unsigned long SERVICE_AUDIO = 0x200000;

Represents the Audio (Speaker, Microphone, Headset service, ...) Major Service Class.

The value of SERVICE_AUDIO is 0x200000 (2097152).

const unsigned long SERVICE_TELEPHONY = 0x400000;

Represents the Telephony (Cordless telephony, Modem, Headset service, ...) Major Service Class.

The value of SERVICE_TELEPHONY is 0x400000 (4194304).

const unsigned long SERVICE_INFORMATION = 0x800000;

Represents the Information (WEB-server, WAP-server, ...) Major Service Class.

The value of the SERVICE_INFORMATION is 0x800000 (8388608).

const unsigned long MAJOR_DEVICE_MASK = 0x1F00;

The mask to get the major device bits.

const unsigned long MISCELLANEOUS_MAJOR_DEVICE = 0x000;

Represents the Miscellaneous Major Device Class.

const unsigned long COMPUTER_MAJOR_DEVICE = 0x100;

Represents the Computer Major Device Class (e.g. laptop, desktop , PDA etc.).

const unsigned long PHONE_MAJOR_DEVICE = 0x200;

Represents the Phone Major Device Class (e.g. cell, cordless, smart phone etc.)

const unsigned long NETWORKING_MAJOR_DEVICE = 0x300;

Represents the LAN/Networking Major Device Class

const unsigned long AUDIO_VISUAL_MAJOR_DEVICE = 0x400;

Represents the Audio/Visual Major Device Class (e.g headset, handsfree etc.)

const unsigned long PERIPHERAL_MAJOR_DEVICE = 0x500;

Represents the Peripheral Major Device Class (e.g keyboard, mouse etc.)

const unsigned long IMAGING_MAJOR_DEVICE = 0x600;

Represents the Imaging Major Device Class (e.g display, camera, scanner etc.)

const unsigned long WEARABLE_MAJOR_DEVICE = 0x700;

Represents the Wearable Major Device Class (e.g wrist watch, pager, jacket etc.)

const unsigned long TOY_MAJOR_DEVICE = 0x800;

Represents the Toy Major Device Class (e.g robot , vehicle, doll/action figure etc.)

const unsigned long UNCATEGORIZED_MAJOR_DEVICE = 0x1F00;

Represents the Uncategorized Major Device Class

const unsigned long MINOR_DEVICE_MASK = 0xFC;

The mask to get the minor device bits. The exact meaning of these bits depends on the major device class. Please refer to http://www.bluetooth.org/assigned-numbers/ for more detail.