SDP_DATA(3) | Library Functions Manual | SDP_DATA(3) |
extern const uuid_t BLUETOOTH_BASE_UUID;
bool
sdp_match_uuid16(sdp_data_t *data, uint16_t uuid);
bool
sdp_get_data(sdp_data_t *data, sdp_data_t *value);
bool
sdp_get_attr(sdp_data_t *data, uint16_t *attr, sdp_data_t *value);
bool
sdp_get_uuid(sdp_data_t *data, uuid_t *uuid);
bool
sdp_get_bool(sdp_data_t *data, bool *value);
bool
sdp_get_seq(sdp_data_t *data, sdp_data_t *seq);
bool
sdp_get_alt(sdp_data_t *data, sdp_data_t *alt);
bool
sdp_get_uint(sdp_data_t *data, uintmax_t *value);
bool
sdp_get_int(sdp_data_t *data, intmax_t *value);
bool
sdp_get_str(sdp_data_t *data, char **str, size_t *length);
bool
sdp_get_url(sdp_data_t *data, char **url, size_t *length);
bool
sdp_put_data(sdp_data_t *data, sdp_data_t *value);
bool
sdp_put_attr(sdp_data_t *data, uint16_t attr, sdp_data_t *value);
bool
sdp_put_uuid(sdp_data_t *data, const uuid_t *value);
bool
sdp_put_uuid16(sdp_data_t *data, uint16_t value);
bool
sdp_put_uuid32(sdp_data_t *data, uint32_t value);
bool
sdp_put_uuid128(sdp_data_t *data, const uuid_t *value);
bool
sdp_put_bool(sdp_data_t *data, bool value);
bool
sdp_put_uint(sdp_data_t *data, uintmax_t value);
bool
sdp_put_uint8(sdp_data_t *data, uint8_t value);
bool
sdp_put_uint16(sdp_data_t *data, uint16_t value);
bool
sdp_put_uint32(sdp_data_t *data, uint32_t value);
bool
sdp_put_uint64(sdp_data_t *data, uint64_t value);
bool
sdp_put_int(sdp_data_t *data, intmax_t value);
bool
sdp_put_int8(sdp_data_t *data, int8_t value);
bool
sdp_put_int16(sdp_data_t *data, int16_t value);
bool
sdp_put_int32(sdp_data_t *data, int32_t value);
bool
sdp_put_int64(sdp_data_t *data, int64_t value);
bool
sdp_put_seq(sdp_data_t *data, ssize_t length);
bool
sdp_put_alt(sdp_data_t *data, ssize_t length);
bool
sdp_put_str(sdp_data_t *data, const char *str, ssize_t length);
bool
sdp_put_url(sdp_data_t *data, const char *url, ssize_t length);
bool
sdp_set_bool(const sdp_data_t *data, bool value);
bool
sdp_set_uint(const sdp_data_t *data, uintmax_t value);
bool
sdp_set_int(const sdp_data_t *data, intmax_t value);
bool
sdp_set_seq(const sdp_data_t *data, ssize_t length);
ssize_t
sdp_data_size(const sdp_data_t *data);
int
sdp_data_type(const sdp_data_t *data);
bool
sdp_data_valid(const sdp_data_t *data);
void
sdp_data_print(const sdp_data_t *data, int indent);
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 const uuid_t BLUETOOTH_BASE_UUID;
The data manipulation routines are arranged into major groups by function:
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.
The “Service Discovery Protocol” section of the Bluetooth Core specifications, available at “http://www.bluetooth.com/”
January 15, 2011 | NetBSD 6.1 |