---
name: "sdp"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/SDP_GET128"
---

# sdp(3)

Bluetooth SDP routines

Part of [SDP\_GET128(3)](/SDP_GET128/3.md).

## NAME

**SDP\_GET8**, **SDP\_GET16**, **SDP\_GET32**, **SDP\_GET64**, **SDP\_GET128**, **SDP\_GET\_UUID128**, **SDP\_PUT8**, **SDP\_PUT16**, **SDP\_PUT32**, **SDP\_PUT64**, **SDP\_PUT128**, **SDP\_PUT\_UUID128**, **sdp\_open**, **sdp\_open\_local**, **sdp\_close**, **sdp\_error**, **sdp\_get\_lcaddr**, **sdp\_search**, **sdp\_attr2desc**, **sdp\_uuid2desc** – Bluetooth SDP routines

## LIBRARY

library “libsdp”

## SYNOPSIS

**#include \<bluetooth.h\>**

**#include \<sdp.h\>**

**SDP\_GET8**(*b*, *cp*);

**SDP\_GET16**(*s*, *cp*);

**SDP\_GET32**(*l*, *cp*);

**SDP\_GET64**(*l*, *cp*);

**SDP\_GET128**(*l*, *cp*);

**SDP\_GET\_UUID128**(*l*, *cp*);

**SDP\_PUT8**(*b*, *cp*);

**SDP\_PUT16**(*s*, *cp*);

**SDP\_PUT32**(*l*, *cp*);

**SDP\_PUT64**(*l*, *cp*);

**SDP\_PUT128**(*l*, *cp*);

**SDP\_PUT\_UUID128**(*l*, *cp*);

*void \**\

**sdp\_open**(*bdaddr\_t const \*l*, *bdaddr\_t const \*r*);

*void \**\

**sdp\_open\_local**(*char const \*control*);

*int32\_t*\

**sdp\_close**(*void \*xs*);

*int32\_t*\

**sdp\_error**(*void \*xs*);

*int32\_t*\

**sdp\_get\_lcaddr**(*void \*xs*, *bdaddr\_t \*l*);

*int32\_t*\

**sdp\_search**(*void \*xs*, *uint32\_t plen*, *uint16\_t const \*pp*, *uint32\_t alen*, *uint32\_t const \*ap*, *uint32\_t vlen*, *sdp\_attr\_t \*vp*);

*char const \* const*\

**sdp\_attr2desc**(*uint16\_t attr*);

*char const \* const*\

**sdp\_uuid2desc**(*uint16\_t uuid*);

*int32\_t*\

**sdp\_register\_service**(*void \*xss*, *uint16\_t uuid*, *const bdaddr\_t \*bdaddr*, *uint8\_t const \*data*, *uint32\_t datalen*, *uint32\_t \*handle*);

*int32\_t*\

**sdp\_unregister\_service**(*void \*xss*, *uint32\_t handle*);

*int32\_t*\

**sdp\_change\_service**(*void \*xss*, *uint32\_t handle*, *uint8\_t const \*data*, *uint32\_t datalen*);

## DESCRIPTION

The **SDP\_GET8**(), **SDP\_GET16**(), **SDP\_GET32**(), **SDP\_GET64**() and **SDP\_GET128**() macros are used to get byte, short, long, long long and 128-bit integer from the buffer pointed by *cp* pointer. The pointer is automatically advanced.

The **SDP\_PUT8**(), **SDP\_PUT16**(), **SDP\_PUT32**(), **SDP\_PUT64**() and **SDP\_PUT128**() macros are used to put byte, short, long, long long and 128-bit integer into the buffer pointed by *cp* pointer. The pointer is automatically advanced.

**SDP\_GET\_UUID128**() and **SDP\_PUT\_UUID128**() macros are used to get and put 128-bit UUID into the buffer pointed by *cp* pointer. The pointer is automatically advanced.

The **sdp\_open**() and **sdp\_open\_local**() functions each return a pointer to an opaque object describing SDP session. The *l* argument passed to **sdp\_open**() function should point to a source BD\_ADDR. If source BD\_ADDR is NULL then source address NG\_HCI\_BDADDR\_ANY is used. The *r* argument passed to **sdp\_open**() function should point to a non-NULL remote BD\_ADDR. Remote BD\_ADDR cannot be NG\_HCI\_BDADDR\_ANY. The **sdp\_open\_local**() function takes path to the control socket and opens a connection to a local SDP server. If path to the control socket is NULL then default */var/run/sdp* path will be used.

The **sdp\_close**() function terminates active SDP session and deletes SDP session object. The *xs* parameter should point to a valid SDP session object created with **sdp\_open**() or **sdp\_open\_local**().

The **sdp\_error**() function returns last error that is stored inside SDP session object. The *xs* parameter should point to a valid SDP session object created with **sdp\_open**() or **sdp\_open\_local**(). The error value returned can be converted to a human readable message by calling [strerror(3)](/strerror/3.md) function.

The **sdp\_get\_lcaddr**() function returns the SDP session actual source BD\_ADDR. The *xs* parameter should point to a valid SDP session object created with **sdp\_open**(). The *l* parameter should point to a buffer in which the value for the requested BD\_ADDR is to be returned. **sdp\_get\_lcaddr**() function is useful if the current SDP session has been opened with the NG\_HCI\_BDADDR\_ANY value passed as a source address.

The **sdp\_search**() function is used to perform SDP Service Search Attribute Request. The *xs* parameter should point to a valid SDP session object created with **sdp\_open**() or **sdp\_open\_local**(). The *pp* parameter is a Service Search Pattern - an array of one or more Service Class IDs. The maximum number of Service Class IDs in the array is 12. The *plen* parameter is the length of the Service Search pattern. The *ap* parameter is an Attribute ID Range List - an array of one or more SDP Attribute ID Range. Each attribute ID Range is encoded as a 32-bit unsigned integer data element, where the high order 16 bits are interpreted as the beginning attribute ID of the range and the low order 16 bits are interpreted as the ending attribute ID of the range. The attribute IDs contained in the Attribute ID Ranges List must be listed in ascending order without duplication of any attribute ID values. Note that all attributes may be requested by specifying a range of 0x0000-0xFFFF. The *alen* parameter is the length of the Attribute ID Ranges List. The **SDP\_ATTR\_RANGE**(*lo*, *hi*) macro can be used to prepare Attribute ID Range. The *vp* parameter should be an array of *sdp\_attr\_t* structures. Each *sdp\_attr\_t* structure describes single SDP attribute and defined as follows:

```
struct sdp_attr {
        uint16_t        flags;
#define SDP_ATTR_OK             (0 << 0)
#define SDP_ATTR_INVALID        (1 << 0)
#define SDP_ATTR_TRUNCATED      (1 << 1)
        uint16_t        attr;  /* SDP_ATTR_xxx */
        uint32_t        vlen;  /* length of the value[] in bytes */
        uint8_t        *value; /* base pointer */
};
typedef struct sdp_attr         sdp_attr_t;
typedef struct sdp_attr *       sdp_attr_p;
```

The caller of the **sdp\_search**() function is expected to prepare the array of *sdp\_attr* structures and for each element of the array both *vlen* and *value* must be set. The **sdp\_search**() function will fill each *sdp\_attr\_t* structure with attribute and value, i.e., it will set *flags*, *attr* and *vlen* fields. The actual value of the attribute will be copied into *value* buffer. Note: attributes are returned in the order they appear in the Service Search Attribute Response. SDP server could return several attributes for the same record. In this case the order of the attributes will be: all attributes for the first records, then all attributes for the second record etc.

The **sdp\_attr2desc**() and **sdp\_uuid2desc**() functions each take a numeric attribute ID/UUID value and convert it to a human readable description.

The **sdp\_register\_service**() function is used to register service with the local SDP server. The *xss* parameter should point to a valid SDP session object obtained from **sdp\_open\_local**(). The *uuid* parameter is a SDP Service Class ID for the service to be registered. The *bdaddr* parameter should point to a valid BD\_ADDR. The service will be only advertised if request was received by the local device with *bdaddr*. If *bdaddr* is set to NG\_HCI\_BDADDR\_ANY then the service will be advertised to any remote devices that queries for it. The *data* and *datalen* parameters specify data and size of the data for the service. Upon successful return **sdp\_register\_service**() will populate *handle* with the SDP record handle. This parameter is optional and can be set to NULL.

The **sdp\_unregister\_service**() function is used to unregister service with the local SDP server. The *xss* parameter should point to a valid SDP session object obtained from **sdp\_open\_local**(). The *handle* parameter should contain a valid SDP record handle of the service to be unregistered.

The **sdp\_change\_service**() function is used to change data associated with the existing service on the local SDP server. The *xss* parameter should point to a valid SDP session object obtained from **sdp\_open\_local**(). The *handle* parameter should contain a valid SDP record handle of the service to be changed. The *data* and *datalen* parameters specify data and size of the data for the service.

## CAVEAT

When registering services with the local SDP server the application must keep the SDP session open. If SDP session is closed then the local SDP server will remove all services that were registered over the session. The application is allowed to change or unregister service if it was registered over the same session.

## EXAMPLES

The following example shows how to get SDP\_ATTR\_PROTOCOL\_DESCRIPTOR\_LIST attribute for the SDP\_SERVICE\_CLASS\_SERIAL\_PORT service from the remote device.

```
bdaddr_t       remote;
uint8_t        buffer[1024];
void          *ss    = NULL;
uint16_t       serv  = SDP_SERVICE_CLASS_SERIAL_PORT;
uint32_t       attr  = SDP_ATTR_RANGE(
                            SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
                            SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST);
sdp_attr_t     proto = { SDP_ATTR_INVALID,0,sizeof(buffer),buffer };
/* Obtain/set remote BDADDR here */
if ((ss = sdp_open(NG_HCI_BDADDR_ANY, remote)) == NULL)
        /* exit ENOMEM */
if (sdp_error(ss) != 0)
        /* exit sdp_error(ss) */
if (sdp_search(ss, 1, &serv, 1, &attr, 1, &proto) != 0)
        /* exit sdp_error(ss) */
if (proto.flags != SDP_ATTR_OK)
        /* exit see proto.flags for details */
/* If we got here then we have attribute value in proto.value */
```

## DIAGNOSTICS

Both **sdp\_open**() and **sdp\_open\_local**() will return NULL if memory allocation for the new SDP session object fails. If the new SDP object was created then caller is still expected to call **sdp\_error**() to check if there was connection error.

The **sdp\_get\_lcaddr**(), **sdp\_search**(), **sdp\_register\_service**(), **sdp\_unregister\_service**(), and **sdp\_change\_service**() functions return non-zero value on error. The caller is expected to call **sdp\_error**() to find out more about error.

## SEE ALSO

[bluetooth(3)](/bluetooth/3.md), [strerror(3)](/strerror/3.md), [sdpcontrol(8)](/sdpcontrol/8.md), [sdpd(8)](/sdpd/8.md)

## AUTHORS

Maksim Yevmenkin ⟨*m\_evmenkin@yahoo.com*⟩

## BUGS

Most likely. Please report bugs if found.
