I would appreciate any donations. Wishlist or send e-mail type donations to maekawa AT daemon-systems.org.

Thank you.

SDP_DATA(3) Library Functions Manual SDP_DATA(3)
NAMEsdp_match_uuid16sdp_get_datasdp_get_attrsdp_get_uuidsdp_get_boolsdp_get_seqsdp_get_altsdp_get_uintsdp_get_intsdp_get_strsdp_get_urlsdp_put_datasdp_put_attrsdp_put_uuidsdp_put_uuid16sdp_put_uuid32sdp_put_uuid128sdp_put_boolsdp_put_uintsdp_put_uint8sdp_put_uint16sdp_put_uint32sdp_put_uint64sdp_put_intsdp_put_int8sdp_put_int16sdp_put_int32sdp_put_int64sdp_put_seqsdp_put_altsdp_put_strsdp_put_urlsdp_set_boolsdp_set_uintsdp_set_intsdp_set_seqsdp_set_altsdp_data_sizesdp_data_typesdp_data_validsdp_data_print -- Service
Discovery Protocol data manipulation routines
LIBRARY
Bluetooth Library (libbluetooth, -lbluetooth)
SYNOPSIS#include<sdp.h>externconstuuid_tBLUETOOTH_BASE_UUID;
boolsdp_match_uuid16(sdp_data_t*data, uint16_tuuid);
boolsdp_get_data(sdp_data_t*data, sdp_data_t*value);
boolsdp_get_attr(sdp_data_t*data, uint16_t*attr, sdp_data_t*value);
boolsdp_get_uuid(sdp_data_t*data, uuid_t*uuid);
boolsdp_get_bool(sdp_data_t*data, bool*value);
boolsdp_get_seq(sdp_data_t*data, sdp_data_t*seq);
boolsdp_get_alt(sdp_data_t*data, sdp_data_t*alt);
boolsdp_get_uint(sdp_data_t*data, uintmax_t*value);
boolsdp_get_int(sdp_data_t*data, intmax_t*value);
boolsdp_get_str(sdp_data_t*data, char**str, size_t*length);
boolsdp_get_url(sdp_data_t*data, char**url, size_t*length);
boolsdp_put_data(sdp_data_t*data, sdp_data_t*value);
boolsdp_put_attr(sdp_data_t*data, uint16_tattr, sdp_data_t*value);
boolsdp_put_uuid(sdp_data_t*data, constuuid_t*value);
boolsdp_put_uuid16(sdp_data_t*data, uint16_tvalue);
boolsdp_put_uuid32(sdp_data_t*data, uint32_tvalue);
boolsdp_put_uuid128(sdp_data_t*data, constuuid_t*value);
boolsdp_put_bool(sdp_data_t*data, boolvalue);
boolsdp_put_uint(sdp_data_t*data, uintmax_tvalue);
boolsdp_put_uint8(sdp_data_t*data, uint8_tvalue);
boolsdp_put_uint16(sdp_data_t*data, uint16_tvalue);
boolsdp_put_uint32(sdp_data_t*data, uint32_tvalue);
boolsdp_put_uint64(sdp_data_t*data, uint64_tvalue);
boolsdp_put_int(sdp_data_t*data, intmax_tvalue);
boolsdp_put_int8(sdp_data_t*data, int8_tvalue);
boolsdp_put_int16(sdp_data_t*data, int16_tvalue);
boolsdp_put_int32(sdp_data_t*data, int32_tvalue);
boolsdp_put_int64(sdp_data_t*data, int64_tvalue);
boolsdp_put_seq(sdp_data_t*data, ssize_tlength);
boolsdp_put_alt(sdp_data_t*data, ssize_tlength);
boolsdp_put_str(sdp_data_t*data, constchar*str, ssize_tlength);
boolsdp_put_url(sdp_data_t*data, constchar*url, ssize_tlength);
boolsdp_set_bool(constsdp_data_t*data, boolvalue);
boolsdp_set_uint(constsdp_data_t*data, uintmax_tvalue);
boolsdp_set_int(constsdp_data_t*data, intmax_tvalue);
boolsdp_set_seq(constsdp_data_t*data, ssize_tlength);
ssize_tsdp_data_size(constsdp_data_t*data);
intsdp_data_type(constsdp_data_t*data);
boolsdp_data_valid(constsdp_data_t*data);
voidsdp_data_print(constsdp_data_t*data, intindent);
DESCRIPTION
These routines provide for the manipulation of Service Discovery Protocol
data buffers. An SDP data buffer type is defined as:
typedef struct {
uint8_t *next;
uint8_t *end;
} sdp_data_t;
Where next points to the next available byte, and end points to the first
address past end of the data area, such that "end = next + length".
The SDP data consists of byte streams describing data elements, where a
data element is a typed data representation consisting of a header field
and a data field. The header field consists of type and size
descriptors, and the data field is a sequence of bytes whose length is
specified in the size descriptor and whose content is specified by the
type descriptor. For instance, the byte sequence "0x09, 0x01, 0x00"
describes an 16-bit unsigned integer element (type 0x09) with value of
0x0100.
Data element types including signed and unsigned integers, boolean,
string, sequence and alternative lists are defined in the <sdp.h> include
file. See the "Service Discovery Protocol" chapters of the "Bluetooth
Core Specifications" for more information.
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", defined in the "Bluetooth Assigned Numbers"
document and declared in <sdp.h> as constuuid_tBLUETOOTH_BASE_UUID;
The data manipulation routines are arranged into major groups by
function:
The sdp_match_uuid16() routine examines the next data element in the data
buffer for an element of type UUID that matches the Bluetooth
short alias UUID with 16-bit value given. If the UUID matches,
the function will return true and the next field of the SDP data
buffer will be advanced to the next element. Otherwise false
will be returned.
The sdp_get_xxxx() routines examine the next data element in the data
buffer for an element of the given type. If the type matches,
the function will extract the typed value to the address given
and advance the next field of the SDP data buffer to the next
element then return true. Otherwise false will be returned.
Note, these functions will not modify the data argument unless
the correct type was found, and will update the data argument
first to allow discarding in the case where a sdp_data_t was
being returned.
The sdp_put_xxxx() routines will attempt to write a data element of the
given type and value to the data buffer. If the data buffer is
too small to contain the encoded data element, the function will
return false, otherwise true will be returned and the next field
of the SDP data pointer will be advanced. In the case of
sdp_put_seq() and sdp_put_alt(), the length argument may be -1,
in which case the generated sequence header will describe all the
remaining buffer space. For sdp_put_str() and sdp_put_url() the
length argument may be -1 in which case the string pointer is
treated as nul terminated.
The sdp_set_xxxx() routines examine the SDP data buffer for a data
element of the given type, and replace the content with the
passed value. If the next data element in the buffer is not of
the appropriate type, the function will return false, otherwise
true will be returned and the value updated. In the case of
sdp_set_seq() and sdp_set_alt(), the length argument may be -1,
in which case the sequence header will be adjusted to describe
the entire data space where possible.
The sdp_data_xxxx() routines include various functions to provide
information about the data stream such as sdp_data_size() to
return the size of the next data element, and sdp_data_type() to
return the type of the next data element. sdp_data_valid() can
be used to ensure that the entire data buffer contains valid SDP
data elements and that all of the elements are contained exactly
within the data buffer. Finally, sdp_data_print() will print the
data buffer in human readable format.
EXAMPLES
To parse a ServiceAttribute response obtained from a remote server using
sdp_service_attribute(3), examining various attribute values:
sdp_data_t rsp, val;
uint16_t attr;
uintmax_t handle;
/* rsp contains remote response */
while (sdp_get_attr(&rsp, &attr, &val)) {
switch(attr) {
case SDP_ATTR_SERVICE_RECORD_HANDLE:
sdp_get_uint(&val, &handle);
printf("ServiceRecordHandle: 0x%08x\n", handle);
break;
case SDP_ATTR_PROFILE_DESCRIPTOR_LIST:
printf("ProfileDescriptorList:\n");
sdp_data_print(&val, 0);
break;
default:
printf("uninteresting attribute 0x%04x\n", attr);
break;
}
}
The following code creates a ProtocolDataList attribute value for a
service using the L2CAP and RFCOMM protocols and illustrates how to
construct sequences of known and unknown length.
uint8_t buf[SIZE];
sdp_data_t seq;
uint16_t psm;
uint8_t channel;
seq.next = buf;
seq.end = buf + sizeof(buf);
sdp_put_seq(&seq, -1);
sdp_put_seq(&seq, 6);
sdp_put_uuid16(&seq, SDP_UUID_PROTOCOL_L2CAP);
sdp_put_uint16(&seq, psm);
sdp_put_seq(&seq, 5);
sdp_put_uuid16(&seq, SDP_UUID_PROTOCOL_RFCOMM);
sdp_put_uint8(&seq, channel);
seq.end = seq.next;
seq.next = buf;
sdp_set_seq(&seq, -1);
Note that although SIZE is assumed to be large enough to contain the
entire sequence in this case, the sdp_put_xxxx() routines will not
overflow the buffer area or write partial data.
The encoded data stream will be stored in a space efficient manner where
possible. In the above example, it is known that the data element
sequence containing the L2CAP UUID will be 8 bytes long overall since the
container length of 6 can be stored in a single byte. But, because the
value of SIZE is unknown, the overall length of the ProtocolDataList may
vary depending if 8, 16 or 32 bits were needed to represent the original
buffer size. sdp_seq_seq() will only modify the content, not the size of
the header.
SEEALSOsdpquery(1), bluetooth(3), sdp(3), uuid(3), sdpd(8)
The "Service Discovery Protocol" section of the Bluetooth Core
specifications, available at http://www.bluetooth.com/HISTORY
These SDP data parsing and manipulation functions first appeared in
NetBSD 6.0.
NetBSD 7.1.2 January 15, 2011 NetBSD 7.1.2