Service record usage with the JABWT

Every service available on a Bluetooth device is described by a service record. A Bluetooth device maintains a Service Discovery DataBase (SDDB) containing service records for all services provided. When a client searches for services, the relevant service records from the SDDB is given to the client. The client may then explore the different attributes of the returned records to find out more about each service.

Note that in-depth knowledge about service records is not necessary to start developing JABWT applications. However, it is always nice to know what is going on "under the hood."

Data types for service record attributes

Attributes contain different data types such as integers or string values. The data is represented using a data element construct. The data element consist of two fields, a header field and a data field. The header field is composed of two parts, a type descriptor and a size descriptor. Since the data element itself contains information about the data type and the actual data, all attribute values in a service record is of the data element type.

Service records contain information about which protocols a service supports, which service classes it belongs to and which profile(s) the service conforms to. Each protocol, service class and profile is assigned its own number, enabling the use of integers when referring to protocols etc. A list of the assigned numbers is available on the Bluetooth Membership Site: https://www.bluetooth.org/foundry/assignnumb/document/assigned_numbers

The JABWT provides the DataElement class. When getting the value of a specific attribute, you will get a DataElement object returned.

Default attributes

Some service record attributes are automatically retrieved by JABWT: the ServiceRecordHandle (attribute ID 0x0000), ServiceClassIDList (attribute ID 0x0001), ServiceRecordState (attribute ID 0x0002), ServiceID (attribute ID 0x0003) and ProtocolDescriptorList (attribute ID 0x0004).

The ServiceRecordHandle attribute uniquely identifies the service record in the SDDB. It is similar to a primary key in an ordinary database. This makes it possible to run several instances of the same service.

The ServiceClassIDList attribute is a list of the serviceclasses the service belongs to. See the Bluetooth standard for more information.

The ServiceRecordState attribute is a counter which is updated every time the service record changes. This enables clients to confirm that a cached service record is still valid.

The ServiceID attribute is a 128 bit id identifying the service. If several servers run the same service, this ID is used to distinguish the service instances.

The ProtocolDescriptorList attribute is a list of protocols supported by your service. If your service supports RFCOMM this attribute will contain both L2CAP (0x0100) and RFCOMM (0x0003).

With these attributes in place a client has enough information to connect to a service. The getConnectionURL() method available in the ServiceRecord class will use the mandatory attributes to build a valid connection URL.

Optional attributes

In addition to the default attributes, several optional attributes may be used. Three interesting attributes are the ServiceName (attribute ID 0x100), ServiceDescription (attribute ID 0x101) and ProviderName (attribute ID 0x102), which are represented as strings. If they are present in the service record they may be retrieved quite easily. The following example shows how to retrieve the ServiceName attribute.

    	/*
    	 * ServiceRecord sr is obtained during service search,
    	 * now we just extract a value from it.
    	 */

    	String name = null;
    	
    	DataElement elm = sr.getAttributeValue(0x100);

    	/*
    	 * Always check for null here. If the attribute is not
    	 * set, null will be returned. Also check the datatype
    	 * set in the header of the DataElement to make sure that
    	 * the DataElement really contains a string.
    	 */

    	if (elm != null && elm.getDataType() == DataElement.STRING) {
    		name = (String) elm.getValue();
    	}

To get the ServiceDescription or ProviderName attributes, just switch the hex value attribute id used in this example.

This was a small and simple example. Check out the sourcecode of my Bluetooth Browser if you want to see how to handle more complex attributes.



This page was last updated 14. Jul. 2006

Comments and feedback are highly appreciated.

You can reach me at: klings (at) nowires (dot) org

Most pages on this site, in particular the How-To's, are available primarily for archival purposes.

Klings.NoWires.Code()

Home

J2ME CDC CLDC MIDP 1.0 MIDP 2.0 MIDlets JABWT

Bluetooth

BTBrowser BTBenchmark KlingsLib

Code Structure Inquiry Service
search
RFCOMM Pitfalls Service record usage Service record manipulation

Devices Developers

Tools Rococo IDEs WTK NDS Antenna

How-To Bluez OBEX Eclipse NetBeans JBuilder WAP

About me