Class ServiceRecord
- java.lang.Object
-
- totalcross.io.device.bluetooth.ServiceRecord
-
public class ServiceRecord extends java.lang.ObjectTheServiceRecordclass describes characteristics of a Bluetooth service. AServiceRecordcontains a set of service attributes, where each service attribute is an (ID, value) pair. A Bluetooth attribute ID is a 16-bit unsigned integer, and an attribute value is aDataElement.The structure and use of service records is specified by the Bluetooth specification in the Service Discovery Protocol (SDP) document. Most of the Bluetooth Profile specifications also describe the structure of the service records used by the Bluetooth services that conform to the profile.
An SDP Server maintains a Service Discovery Database (SDDB) of service records that describe the services on the local device. Remote SDP clients can use the SDP to query an SDP server for any service records of interest. A service record provides sufficient information to allow an SDP client to connect to the Bluetooth service on the SDP server's device.
ServiceRecordsare made available to a client application via an argument of theDiscoveryListener.servicesDiscovered(int, totalcross.io.device.bluetooth.ServiceRecord[])method of theDiscoveryListenerinterface.ServiceRecordsare available to server applications via the methodtotalcross.io.device.bluetooth.LocalDevice#getRecord(totalcross.io.Connection).There might be many service attributes in a service record, and the SDP protocol makes it possible to specify the subset of the service attributes that an SDP client wants to retrieve from a remote service record. The
ServiceRecordinterface treats certain service attribute IDs as default IDs, and, if present, these service attributes are automatically retrieved during service searches.The Bluetooth Assigned Numbers document ( http://www.bluetooth.org/assigned-numbers/sdp.htm) defines a large number of service attribute IDs. Here is a subset of the most common service attribute IDs and their types.
Attribute Name Attribute ID Attribute Value Type ServiceRecordHandle 0x0000 32-bit unsigned integer ServiceClassIDList 0x0001 DATSEQ of UUIDs ServiceRecordState 0x0002 32-bit unsigned integer ServiceID 0x0003 UUID ProtocolDescriptorList 0x0004 DATSEQ of DATSEQ of UUID and optional parameters BrowseGroupList 0x0005 DATSEQ of UUIDs LanguageBasedAttributeIDList 0x0006 DATSEQ of DATSEQ triples ServiceInfoTimeToLive 0x0007 32-bit unsigned integer ServiceAvailability 0x0008 8-bit unsigned integer BluetoothProfileDescriptorList 0x0009 DATSEQ of DATSEQ pairs DocumentationURL 0x000A URL ClientExecutableURL 0x000B URL IconURL 0x000C URL VersionNumberList 0x0200 DATSEQof 16-bit unsigned integersServiceDatabaseState 0x0201 32-bit unsigned integer The following table lists the common string-valued attribute ID offsets used in a
ServiceRecord. These offsets must be added to a base value to obtain the actual service ID. (For more information, see the Service Discovery Protocol Specification located in the Bluetooth Core Specification.Attribute Name Attribute ID Offset Attribute Value Type ServiceName 0x0000 String ServiceDescription 0x0001 String ProviderName 0x0002 String - Since:
- TotalCross 1.15
-
-
Field Summary
Fields Modifier and Type Field Description static intAUTHENTICATE_ENCRYPTAuthentication and encryption are required for connections to this service.static intAUTHENTICATE_NOENCRYPTAuthentication is required for connections to this service, but not encryption.static intNOAUTHENTICATE_NOENCRYPTAuthentication and encryption are not needed on a connection to this service.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataElementgetAttributeValue(int attrID)Returns the value of the service attribute ID provided it is present in the service record, otherwise this method returns null.java.lang.StringgetConnectionURL()Returns a string including optional parameters that can be used by a client to connect to the service described by this ServiceRecord.java.lang.StringgetConnectionURL(int requiredSecurity, boolean mustBeMaster)Returns a String including optional parameters that can be used by a client to connect to the service described by this ServiceRecord.RemoteDevicegetHostDevice()Returns the remote Bluetooth device that populated the service record with attribute values.
-
-
-
Field Detail
-
NOAUTHENTICATE_NOENCRYPT
public static final int NOAUTHENTICATE_NOENCRYPT
Authentication and encryption are not needed on a connection to this service. Used withgetConnectionURL()method.NOAUTHENTICATE_NOENCRYPTis set to the constant value 0x00 (0).- See Also:
- Constant Field Values
-
AUTHENTICATE_NOENCRYPT
public static final int AUTHENTICATE_NOENCRYPT
Authentication is required for connections to this service, but not encryption. It is OK for encryption to be either on or off for the connection. Used withgetConnectionURL()method.AUTHENTICATE_NOENCRYPTis set to the constant value 0x01 (1).- See Also:
- Constant Field Values
-
AUTHENTICATE_ENCRYPT
public static final int AUTHENTICATE_ENCRYPT
Authentication and encryption are required for connections to this service. Used withgetConnectionURL()method.AUTHENTICATE_ENCRYPTis set to the constant value 0x02 (2).- See Also:
- Constant Field Values
-
-
Method Detail
-
getHostDevice
public RemoteDevice getHostDevice()
Returns the remote Bluetooth device that populated the service record with attribute values. It is important to note that the Bluetooth device that provided the value might not be reachable anymore, since it can move, turn off, or change its security mode denying all further transactions.- Returns:
- the remote Bluetooth device that populated the service record, or null if the local device populated this ServiceRecord
- Since:
- TotalCross 1.27
-
getAttributeValue
public DataElement getAttributeValue(int attrID)
Returns the value of the service attribute ID provided it is present in the service record, otherwise this method returns null.- Parameters:
attrID- the attribute whose value is to be returned- Returns:
- the value of the attribute ID if present in the service record, otherwise null
- Throws:
java.lang.IllegalArgumentException- if attrID is negative or greater than or equal to 216- Since:
- TotalCross 1.27
-
getConnectionURL
public java.lang.String getConnectionURL()
Returns a string including optional parameters that can be used by a client to connect to the service described by this ServiceRecord. The return value can be used as the first argument to Connector.open(). In the case of a Serial Port service record, this string might look like "btspp://0050CD00321B:3;authenticate=true;encrypt=false;master=true", where "0050CD00321B" is the Bluetooth address of the device that provided this ServiceRecord, "3" is the RFCOMM server channel mentioned in this ServiceRecord, and there are three optional parameters related to security and master/slave roles.- Returns:
- a string that can be used to connect to the service or null if the ProtocolDescriptorList in this ServiceRecord is not formatted according to the Bluetooth specification
- Since:
- TotalCross 1.15
-
getConnectionURL
public java.lang.String getConnectionURL(int requiredSecurity, boolean mustBeMaster)Returns a String including optional parameters that can be used by a client to connect to the service described by this ServiceRecord. The return value can be used as the first argument to Connector.open(). In the case of a Serial Port service record, this string might look like "btspp://0050CD00321B:3;authenticate=true;encrypt=false;master=true", where "0050CD00321B" is the Bluetooth address of the device that provided this ServiceRecord, "3" is the RFCOMM server channel mentioned in this ServiceRecord, and there are three optional parameters related to security and master/slave roles.- Parameters:
requiredSecurity- determines whether authentication or encryption are required for a connectionmustBeMaster- true indicates that this device must play the role of master in connections to this service; false indicates that the local device is willing to be either the master or the slave- Returns:
- a string that can be used to connect to the service or null if the ProtocolDescriptorList in this ServiceRecord is not formatted according to the Bluetooth specification
- Throws:
java.lang.IllegalArgumentException- if requiredSecurity is not one of the constants NOAUTHENTICATE_NOENCRYPT, AUTHENTICATE_NOENCRYPT, or AUTHENTICATE_ENCRYPT- Since:
- TotalCross 1.27
- See Also:
NOAUTHENTICATE_NOENCRYPT
-
-