// 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. // TODO(bryeung): mark this API as ChromeOS only (see crbug.com/119398). [nodoc] namespace experimental.bluetooth { 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 { Device device; DOMString serviceUuid; 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 AddressCallback = void (DOMString result); callback BooleanCallback = void (boolean result); callback DataCallback = void (ArrayBuffer result); callback DeviceCallback = void (Device device); callback DevicesCallback = void (Device[] 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; }; // 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 { // Checks if the system has bluetooth support. // |callback| : Called with the boolean result. static void isAvailable(BooleanCallback callback); // Checks if the system's bluetooth module has power. // |callback| : Called with the boolean result. static void isPowered(BooleanCallback callback); // Get the bluetooth address of the system's bluetooth module. // |callback| : Called with the address, or null if there was an error. static void getAddress(AddressCallback callback); // Get a list of bluetooth devices. // |options| : Controls which devices are returned. // |callback| : Called with an array of Device objects. static void getDevices(GetDevicesOptions options, DevicesCallback 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. Note that discovery can be resource // intensive. stopDiscovery should be called as soon as is convenient. // |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 availability of bluetooth on the system changes. // |available| : True if bluetooth is available, false otherwise. static void onAvailabilityChanged(boolean available); // Fired when the power state of bluetooth on the system changes. // |powered| : True if bluetooth is powered, false otherwise. static void onPowerChanged(boolean has_power); // Used to return discovered devices to the extension. Users should not // add listeners to this event directly. static void onDeviceDiscovered_(Device device); }; };