1.\" Copyright (c) 2003 Maksim Yevmenkin <m_evmenkin@yahoo.com> 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $Id: sdp.3,v 1.1 2003/09/07 20:34:19 max Exp $ 26.\" $FreeBSD$ 27.\" 28.Dd September 7, 2003 29.Dt SDP 3 30.Os 31.Sh NAME 32.Nm SDP_GET8 , 33.Nm SDP_GET16 , 34.Nm SDP_GET32 , 35.Nm SDP_GET64 , 36.Nm SDP_GET128 37.Nd get SDP integer 38.Pp 39.Nm SDP_PUT8 , 40.Nm SDP_PUT16 , 41.Nm SDP_PUT32 , 42.Nm SDP_PUT64 , 43.Nm SDP_PUT128 44.Nd put SPD integer 45.Pp 46.Nm sdp_open , 47.Nm sdp_open_local , 48.Nm sdp_close 49.Nm sdp_error 50.Nd control SDP session 51.Pp 52.Nm sdp_search 53.Nd perform SDP query 54.Pp 55.Nm sdp_attr2desc , 56.Nm sdp_uuid2desc 57.Nd convert numeric SDP attribute/UUID value into human readable description 58.Sh LIBRARY 59.Lb libsdp 60.Sh SYNOPSIS 61.In bluetooth.h 62.In sdp.h 63.Fn SDP_GET8 "b" "cp" 64.Fn SDP_GET16 "s" "cp" 65.Fn SDP_GET32 "l" "cp" 66.Fn SDP_GET64 "l" "cp" 67.Fn SDP_GET128 "l" "cp" 68.Fn SDP_PUT8 "b" "cp" 69.Fn SDP_PUT16 "s" "cp" 70.Fn SDP_PUT32 "l" "cp" 71.Fn SDP_PUT64 "l" "cp" 72.Fn SDP_PUT128 "l" "cp" 73.Ft void * 74.Fn sdp_open "bdaddr_t const *l" "bdaddr_t const *r" 75.Ft void * 76.Fn sdp_open_local "char const *control" 77.Ft int32_t 78.Fn sdp_close "void *xs" 79.Ft int32_t 80.Fn sdp_error "void *xs" 81.Ft int32_t 82.Fn 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" 83.Ft char const * const 84.Fn sdp_attr2desc "uint16_t attr" 85.Ft char const * const 86.Fn sdp_uuid2desc "uint16_t uuid" 87.Sh DESCRIPTION 88The 89.Fn SDP_GET8 , 90.Fn SDP_GET16 , 91.Fn SDP_GET32 , 92.Fn SDP_GET64 93and 94.Fn SDP_GET128 95macros are used to get byte, short, long, long long and 128-bit integer 96from the buffer pointed by 97.Vt cp 98pointer. The pointer is automatically advanced. 99.Pp 100The 101.Fn SDP_PUT8 , 102.Fn SDP_PUT16 , 103.Fn SDP_PUT32 , 104.Fn SDP_PUT64 105and 106.Fn SDP_PUT128 107macros are used to put byte, short, long, long long and 128-bit integer 108into the buffer pointed by 109.Vt cp 110pointer. The pointer is automatically advanced. 111.Pp 112.Fn sdp_open 113and 114.Fn sdp_open_local 115functions each return a pointer to an opaque object describing SDP session. 116The 117.Vt l 118argument passed to 119.Fn sdp_open 120function should point to a source BD_ADDR. 121If source BD_ADDR is 122.Dv NULL 123then source address 124.Dv NG_HCI_BDADDR_ANY 125is used. 126The 127.Vt r 128argument passed to 129.Fn sdp_open 130function should point to a non 131.Dv NULL 132remote BD_ADDR. 133Remote BD_ADDR can not be 134.Dv NG_HCI_BDADDR_ANY . 135The 136.Fn sdp_open_local 137function takes path to the control socket and opens a connection to a local 138SDP server. 139If path to the control socket is 140.Dv NULL 141then default 142.Pa /var/run/sdp 143path will be used. 144.Pp 145The 146.Fn sdp_close 147function terminates active SDP session and deletes SDP session object. 148The 149.Vt xs 150parameter should point to a valid SDP session object created with 151.Fn sdp_open 152or 153.Fn sdp_open_local . 154.Pp 155The 156.Fn sdp_error 157function returns last error that is stored inside SDP session object. 158The 159.Vt xs 160parameter should point to a valid SDP session object created with 161.Fn sdp_open 162or 163.Fn sdp_open_local . 164The error value returned can be converted to a human readable message by 165calling 166.Xr strerror 3 167function. 168.Pp 169The 170.Fn sdp_search 171function is used to perform SDP Service Search Attribute Request. 172The 173.Vt xs 174parameter should point to a valid SDP session object created with 175.Fn sdp_open 176or 177.Fn sdp_open_local . 178The 179.Vt pp 180parameter is a Service Search Pattern - an array of one or more Service 181Class IDs. 182The maximum number of Service Class IDs in the array is 12. 183The 184.Vt plen 185parameter is the length of the Service Search pattern. 186The 187.Vt ap 188parameter is a Attribute ID Range List - an array of one or more SDP Attribute 189ID Range. Each attribute ID Range is encoded as a 32-bit unsigned integer data 190element, where the high order 16 bits are interpreted as the beginning 191attribute ID of the range and the low order 16 bits are interpreted as the 192ending attribute ID of the range. 193The attribute IDs contained in the Attribute ID Ranges List must be listed in 194ascending order without duplication of any attribute ID values. 195Note that all attributes may be requested by specifying a range of 1960x0000-0xFFFF. 197The 198.Vt alen 199parameter is the length of the Attribute ID Ranges List. 200The 201.Fn SDP_ATTR_RANGE "lo" "hi" 202macro can be used to prepare Attribute ID Range. 203The 204.Vt vp 205parameter should be an array of 206.Vt sdp_attr_t 207structures. 208Each 209.Vt sdp_attr_t 210structure describes single SDP attribute and defined as follows: 211.Bd -literal -offset indent 212struct sdp_attr { 213 uint16_t flags; 214#define SDP_ATTR_OK (0 << 0) 215#define SDP_ATTR_INVALID (1 << 0) 216#define SDP_ATTR_TRUNCATED (1 << 1) 217 uint16_t attr; /* SDP_ATTR_xxx */ 218 uint32_t vlen; /* length of the value[] in bytes */ 219 uint8_t *value; /* base pointer */ 220}; 221typedef struct sdp_attr sdp_attr_t; 222typedef struct sdp_attr * sdp_attr_p; 223.Ed 224.Pp 225The caller of the 226.Fn sdp_search 227function is expected to prepare the array of 228.Vt sdp_attr 229structures and for each element of the array both 230.Vt vlen 231and 232.Vt value 233must be set. 234The 235.Fn sdp_search 236function will fill each 237.Vt sdp_attr_t 238structure with attribute and value, i.e. it will set 239.Vt flags , 240.Vt attr 241and 242.Vt vlen 243fields. 244The actual value of the attribute will be copied into 245.Vt value 246buffer. 247Note: attributes are returned in the order they appear in the Service Search 248Attribute Response. 249SDP server could return several attributes for the same record. 250In this case the order of the attributes will be: all attributes for the first 251records, then all attributes for the secord record etc. 252.Pp 253The 254.Fn sdp_attr2desc 255and 256.Fn sdp_uuid2desc 257functions each take a numeric attribute ID/UUID value and convert it to a 258human readable description. 259.Sh EXAMPLES 260The following example shows how to get 261.Dv SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST 262attribute for the 263.Dv SDP_SERVICE_CLASS_SERIAL_PORT 264service from the remote device. 265.Bd -literal -offset indent 266bdaddr_t remote; 267uint8_t buffer[1024]; 268void *ss = NULL; 269uint16_t serv = SDP_SERVICE_CLASS_SERIAL_PORT; 270uint32_t attr = SDP_ATTR_RANGE( 271 SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, 272 SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST); 273sdp_attr_t proto = { SDP_ATTR_INVALID,0,sizeof(buffer),buffer }; 274 275/* Obtain/set remote BDADDR here */ 276 277if ((ss = sdp_open(NG_HCI_BDADDR_ANY, remote)) == NULL) 278 /* exit ENOMEM */ 279if (sdp_error(ss) != 0) 280 /* exit spd_error(ss) */ 281 282if (sdp_search(ss, 1, &serv, 1, &attr, 1, &proto) != 0) 283 /* exit sdp_error(ss) */ 284 285if (proto.flags != SDP_ATTR_OK) 286 /* exit see proto.flags for details */ 287 288/* If we got here then we have attribute value in proto.value */ 289.Ed 290.Sh DIAGNOSTICS 291Both 292.Fn sdp_open 293and 294.Fn sdp_open_local 295will return 296.Dv NULL 297if memory allocation for the new SDP session object fails. 298If the new SDP object was created then caller is still expected to call 299.Fn sdp_error 300to check if there was connection error. 301.Pp 302The 303.Fn sdp_search 304function returns non-zero value on error. 305The caller is expected to call 306.Fn sdp_error 307to find out more about error. 308.Sh SEE ALSO 309.Xr bluetooth 3 , 310.Xr strerror 3 311.Sh BUGS 312This is client only library for now. 313Please report bugs if found. 314.Sh AUTHORS 315.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com 316