3.4. SDP API

The SDP API is divided into two pars: service client API and service provider API.

The Service client API is dedicated for clients to find out what services are available on a remote device, what attributes they have and how to connect and properly use a service.

The Service provider API is dedicated for services to register information about itself with SDP server. it allows for a client to find it and connect to it.

3.4.1. Service Attributes

Each service attribute describes a single characteristic of a service.

Universal attributes are defined in the SDP specification. Their definition and purpose are clearly stated and well understood, and are briefly described here.

ServiceRecordHandle is a unique service identifier (32 bits) valid only on the device that gave out the handle. The same service on two different devices would have different handles.

ServiceID is a universally unique service identifier (UUID) guaranteed to be the same on all devices where the service can be found.

ServiceClassIDSequence is a sequence of UUIDs representing the hierarchy (type) of service classes a service is known to conform to. Usually specified in the order "most specific" to "most generic".

AccessProtocols is one or more sequences of protocol descriptors. A protocol descriptor is a sequence of attributes - UUID of protocol, version number and port number, where a service can be accessed.

Bluetooth Profile Descriptor is a sequence of standard "Bluetooth Profile" descriptions that the service is known to conform to. Bluetooth profile description contains UUID of profile, its version number.

ServiceRecordState is a 32-bit integer provided to facilitate caching of service attributes. If this attribute is present in a service record, then it is guaranteed to change on any modification to the record.

ServiceInfoTimeToLive is a 32-bit integer that contains the number of seconds for which the service record is expected not to change, but not a guarantee. The time interval is measured from the time the attribute is received from the SDP server.

ServiceAvailability is an 8 bit unsigned integer that represents the measure of service's capability to handle more clients. 0x00 means completely unavailable and 0xff means maximum availability.

ServiceName, ServiceDescription and ServiceProviderName these are user visible strings conveying information about a service. These can be provided in one (universal) or more languages.

LanguageBasedAttributeIDList contains language specific attribute identifiers for user visible strings.

BrowseGroupList consists of a sequence of UUIDs representing the "browse group" the service belongs. Browse group is a hierarchy of service categories, facilitating service discovery without "a priori" information of any service.

ClientExecutableURL location of a client platform specific (Win, Unix, Palm) application that can use the service.

DocumentationURL location of additional service documentation.

IconURL location of an icon that can be used to represent the service.

ServiceDatabaseState is an attribute specific to the service discovery server itself. If this value changes, then the service repository was recently modified.

In addition to universal attributes, a service could have "service specific attributes". These attributes make sense only in the context of the said service. Dynamic attributes could be either basic attributes or constructed.

3.4.2. SDP data structures and generic API UUID

A UUID is a universally unique identifier that is guaranteed to be unique across all space and all time. UUIDs can be independently created in a distributed fashion. No central registry of assigned UUIDs is required. A UUID is a 128-bit value.

To reduce the burden of storing and transferring 128-bit UUID values, a range of UUID values has been pre-allocated for assignment to often-used, registered purposes. The first UUID in this pre-allocated range is known as the Bluetooth Base UUID and has the value 00000000-0000-1000-8000- 00805F9B34FB, from the Bluetooth Assigned Numbers document. UUID values in the pre-allocated range have aliases that are represented as 16-bit or 32-bit values. These aliases are often called 16-bit and 32-bit UUIDs, but it is important to note that each actually represents a 128-bit UUID value.

UUID object is used to store uuid, which can store 16, 32 or 128 bits uuid. To simplify interface to this object Affix provides set of functions to create UUID from a value and convert one type of UUID to another.

3.4.3. Service client SDP API

The client SDP API is used by a client to find services provided by a remote device and to find out what attributes they have. The overall function set is shown on the following table:

Table 3-11. Service client SDP API

int SDPInit(0);Initializes the SDP infrastructure.
SDPServerHandle SDPOpenServerConnection(struct sockaddr_affix *saddr);Opens a connection to the SDP server.
void SDPCloseServerConnection(SDPServerHandle srvHandle);Closes a connection to the SDP server.
int SDPServiceSearchRequest(SDPServerHandle srvHandle, slist_t *svcSearchList, uint16_t maxSvcRecordCount, slist_t **svcResponseList, uint16_t *handleCountInResponse);Makes a service search request to the SDP server and returns service handle list of the services that match to search pattern. Search pattern - list of service class identifiers.
int SDPServiceAttributeRequest(SDPServerHandle srvHandle, ServiceRecordHandle svcHandle, AttributeRequestType attrReqType, slist_t *attrIDList, uint16_t maxAttrIDByteCount, ServiceRecord **_svcRec, uint16_t *maxAttrResponseByteCount);Makes an attribute request of a service with a handle "svcHandle" and returns requested attribute list. "attrIDList" list defines attributes to return.
int SDPServiceSearchAttributeRequest(SDPServerHandle srvHandle, slist_t *svcSearchList, AttributeRequestType attrReqType, slist_t *attrIDList, uint16_t maxAttrByteCount, slist_t **svcResponseList, uint16_t *maxAttrResponseByteCount);Makes a service search request which returns attributes of all found services. Combines previous two functions.
int __SDPServiceXXX(struct sockaddr_affix *saddr, ...);These are variations of former three functions that take address to send request instead of ServerHandle. They open/close connection internally.
int getXXX(ServiceRecord *svcRec, ....)Template of functions: extracts individual attributes (XXX) from service record, e.g.: service name, access port, profile id, ... Service class identifier(s) and service attribute(s) based search

This request combines the service class identifier and the service attribute search request, thus minimizing the number of request/response pairs needed to find a service. The parameters contain a service search pattern and a list of attributes that need to be fetched, should a service record match the service search pattern.

First a service class match is done and for matching service, requested attributes are extracted.

As before the method returns E_OK on successful execution of request and an error code for failures.

3.4.4. Service provider SDP API

Bluetooth service developers can use the following API to register services with the "local" SDP server. The "on-the-wire" formats of service registrations mimic the SDP. However a key difference is that service registrations PDUs are never sent on Bluetooth channels, but done using TCP sockets. The service registration requests and responses do use the "reserved range" of SDP PDU Identifiers. There is no problem since it is not sent on BT channels. The following are the APIs available for service implementers to register their service with the SDP server on the device. For details, please read the attached header files.