sdp_data(3) - NetBSD Manual Pages

SDP_DATA(3)             NetBSD Library Functions Manual            SDP_DATA(3)


NAME
sdp_match_uuid16 sdp_get_data sdp_get_attr sdp_get_uuid sdp_get_bool sdp_get_seq sdp_get_alt sdp_get_uint sdp_get_int sdp_get_str sdp_get_url sdp_put_data sdp_put_attr sdp_put_uuid sdp_put_uuid16 sdp_put_uuid32 sdp_put_uuid128 sdp_put_bool sdp_put_uint sdp_put_uint8 sdp_put_uint16 sdp_put_uint32 sdp_put_uint64 sdp_put_int sdp_put_int8 sdp_put_int16 sdp_put_int32 sdp_put_int64 sdp_put_seq sdp_put_alt sdp_put_str sdp_put_url sdp_set_bool sdp_set_uint sdp_set_int sdp_set_seq sdp_set_alt sdp_data_size sdp_data_type sdp_data_valid sdp_data_print -- Service Dis- covery Protocol data manipulation routines
LIBRARY
Bluetooth Library (libbluetooth, -lbluetooth)
SYNOPSIS
#include <sdp.h> 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);
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 descrip- tors, 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 func- tion: 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 ele- ment 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 infor- mation 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 ser- vice using the L2CAP and RFCOMM protocols and illustrates how to con- struct 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 over- flow 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.
SEE ALSO
sdpquery(1), bluetooth(3), sdp(3), uuid(3), sdpd(8) The "Service Discovery Protocol" section of the Bluetooth Core specifica- tions, available at "http://www.bluetooth.com/"
HISTORY
These SDP data parsing and manipulation functions first appeared in NetBSD 6.0. NetBSD 6.1.2 January 15, 2011 NetBSD 6.1.2

Powered by man-cgi (2024-08-26). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.