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.Ft int32_t 88.Fn sdp_register_service "void *xss" "uint16_t uuid" "bdaddr_p const bdaddr" "uint8_t const *data" "uint32_t datalen" "uint32_t *handle" 89.Ft int32_t 90.Fn sdp_unregister_service "void *xss" "uint32_t handle" 91.Ft int32_t 92.Fn sdp_change_service "void *xss" "uint32_t handle" "uint8_t const *data" "uint32_t datalen" 93.Sh DESCRIPTION 94The 95.Fn SDP_GET8 , 96.Fn SDP_GET16 , 97.Fn SDP_GET32 , 98.Fn SDP_GET64 99and 100.Fn SDP_GET128 101macros are used to get byte, short, long, long long and 128-bit integer 102from the buffer pointed by 103.Vt cp 104pointer. The pointer is automatically advanced. 105.Pp 106The 107.Fn SDP_PUT8 , 108.Fn SDP_PUT16 , 109.Fn SDP_PUT32 , 110.Fn SDP_PUT64 111and 112.Fn SDP_PUT128 113macros are used to put byte, short, long, long long and 128-bit integer 114into the buffer pointed by 115.Vt cp 116pointer. The pointer is automatically advanced. 117.Pp 118.Fn sdp_open 119and 120.Fn sdp_open_local 121functions each return a pointer to an opaque object describing SDP session. 122The 123.Vt l 124argument passed to 125.Fn sdp_open 126function should point to a source BD_ADDR. 127If source BD_ADDR is 128.Dv NULL 129then source address 130.Dv NG_HCI_BDADDR_ANY 131is used. 132The 133.Vt r 134argument passed to 135.Fn sdp_open 136function should point to a non 137.Dv NULL 138remote BD_ADDR. 139Remote BD_ADDR can not be 140.Dv NG_HCI_BDADDR_ANY . 141The 142.Fn sdp_open_local 143function takes path to the control socket and opens a connection to a local 144SDP server. 145If path to the control socket is 146.Dv NULL 147then default 148.Pa /var/run/sdp 149path will be used. 150.Pp 151The 152.Fn sdp_close 153function terminates active SDP session and deletes SDP session object. 154The 155.Vt xs 156parameter should point to a valid SDP session object created with 157.Fn sdp_open 158or 159.Fn sdp_open_local . 160.Pp 161The 162.Fn sdp_error 163function returns last error that is stored inside SDP session object. 164The 165.Vt xs 166parameter should point to a valid SDP session object created with 167.Fn sdp_open 168or 169.Fn sdp_open_local . 170The error value returned can be converted to a human readable message by 171calling 172.Xr strerror 3 173function. 174.Pp 175The 176.Fn sdp_search 177function is used to perform SDP Service Search Attribute Request. 178The 179.Vt xs 180parameter should point to a valid SDP session object created with 181.Fn sdp_open 182or 183.Fn sdp_open_local . 184The 185.Vt pp 186parameter is a Service Search Pattern - an array of one or more Service 187Class IDs. 188The maximum number of Service Class IDs in the array is 12. 189The 190.Vt plen 191parameter is the length of the Service Search pattern. 192The 193.Vt ap 194parameter is a Attribute ID Range List - an array of one or more SDP Attribute 195ID Range. Each attribute ID Range is encoded as a 32-bit unsigned integer data 196element, where the high order 16 bits are interpreted as the beginning 197attribute ID of the range and the low order 16 bits are interpreted as the 198ending attribute ID of the range. 199The attribute IDs contained in the Attribute ID Ranges List must be listed in 200ascending order without duplication of any attribute ID values. 201Note that all attributes may be requested by specifying a range of 2020x0000-0xFFFF. 203The 204.Vt alen 205parameter is the length of the Attribute ID Ranges List. 206The 207.Fn SDP_ATTR_RANGE "lo" "hi" 208macro can be used to prepare Attribute ID Range. 209The 210.Vt vp 211parameter should be an array of 212.Vt sdp_attr_t 213structures. 214Each 215.Vt sdp_attr_t 216structure describes single SDP attribute and defined as follows: 217.Bd -literal -offset indent 218struct sdp_attr { 219 uint16_t flags; 220#define SDP_ATTR_OK (0 << 0) 221#define SDP_ATTR_INVALID (1 << 0) 222#define SDP_ATTR_TRUNCATED (1 << 1) 223 uint16_t attr; /* SDP_ATTR_xxx */ 224 uint32_t vlen; /* length of the value[] in bytes */ 225 uint8_t *value; /* base pointer */ 226}; 227typedef struct sdp_attr sdp_attr_t; 228typedef struct sdp_attr * sdp_attr_p; 229.Ed 230.Pp 231The caller of the 232.Fn sdp_search 233function is expected to prepare the array of 234.Vt sdp_attr 235structures and for each element of the array both 236.Vt vlen 237and 238.Vt value 239must be set. 240The 241.Fn sdp_search 242function will fill each 243.Vt sdp_attr_t 244structure with attribute and value, i.e. it will set 245.Vt flags , 246.Vt attr 247and 248.Vt vlen 249fields. 250The actual value of the attribute will be copied into 251.Vt value 252buffer. 253Note: attributes are returned in the order they appear in the Service Search 254Attribute Response. 255SDP server could return several attributes for the same record. 256In this case the order of the attributes will be: all attributes for the first 257records, then all attributes for the secord record etc. 258.Pp 259The 260.Fn sdp_attr2desc 261and 262.Fn sdp_uuid2desc 263functions each take a numeric attribute ID/UUID value and convert it to a 264human readable description. 265.Pp 266The 267.Fn sdp_register_service 268is used to register service with the local SDP server. 269The 270.Vt xss 271parameter should point to a valid SDP session object obtained from 272.Fn sdp_open_local . 273The 274.Vt uuid 275parameter is a SDP Service Class ID for the service to be registered. 276The 277.Vt bdaddr 278parameter should point to a valid BD_ADDR. 279The service will be only advertised if request was received by the local device 280with 281.Vt bdaddr . 282If 283.Vt bdaddr 284is set to 285.Dv NG_HCI_BDADDR_ANY 286then the service will be advertised to any remote devices that queries for it. 287The 288.Vt data 289and 290.Vt datalen 291parameters specify data and size of the data for the service. 292Upon successful return 293.Fn sdp_register_service 294will populate 295.Vt handle 296with the SDP record handle. 297This parameter is optional and can be set to 298.Dv NULL . 299.Pp 300The 301.Fn sdp_unregister_service 302is used to unregister service with the local SDP server. 303The 304.Vt xss 305parameter should point to a valid SDP session object obtained from 306.Fn sdp_open_local . 307The 308.Vt handle 309parameter should contain a valid SDP record handle of the service to be 310unregistered. 311.Pp 312The 313.Fn sdp_change_service 314function is used to change data associated with the existing service on 315the local SDP server. 316The 317.Vt xss 318parameter should point to a valid SDP session object obtained from 319.Fn sdp_open_local . 320The 321.Vt handle 322parameter should contain a valid SDP record handle of the service to be changed. 323The 324.Vt data 325and 326.Vt datalen 327parameters specify data and size of the data for the service. 328.Sh CAVEAT 329When registering services with the local SDP server the application must 330keep the SDP session open. 331If SDP session is closed then the local SDP server will remove all services 332that were registered over the session. 333The application is allowed to change or unregister service if it was registered 334over the same session. 335.Sh EXAMPLES 336The following example shows how to get 337.Dv SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST 338attribute for the 339.Dv SDP_SERVICE_CLASS_SERIAL_PORT 340service from the remote device. 341.Bd -literal -offset indent 342bdaddr_t remote; 343uint8_t buffer[1024]; 344void *ss = NULL; 345uint16_t serv = SDP_SERVICE_CLASS_SERIAL_PORT; 346uint32_t attr = SDP_ATTR_RANGE( 347 SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, 348 SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST); 349sdp_attr_t proto = { SDP_ATTR_INVALID,0,sizeof(buffer),buffer }; 350 351/* Obtain/set remote BDADDR here */ 352 353if ((ss = sdp_open(NG_HCI_BDADDR_ANY, remote)) == NULL) 354 /* exit ENOMEM */ 355if (sdp_error(ss) != 0) 356 /* exit spd_error(ss) */ 357 358if (sdp_search(ss, 1, &serv, 1, &attr, 1, &proto) != 0) 359 /* exit sdp_error(ss) */ 360 361if (proto.flags != SDP_ATTR_OK) 362 /* exit see proto.flags for details */ 363 364/* If we got here then we have attribute value in proto.value */ 365.Ed 366.Sh DIAGNOSTICS 367Both 368.Fn sdp_open 369and 370.Fn sdp_open_local 371will return 372.Dv NULL 373if memory allocation for the new SDP session object fails. 374If the new SDP object was created then caller is still expected to call 375.Fn sdp_error 376to check if there was connection error. 377.Pp 378The 379.Fn sdp_search , 380.Fn sdp_register_service , 381.Fn sdp_unregister_service 382and 383.Fn sdp_change_service 384functions return non-zero value on error. 385The caller is expected to call 386.Fn sdp_error 387to find out more about error. 388.Sh SEE ALSO 389.Xr bluetooth 3 , 390.Xr strerror 3 , 391.Xr sdpcontrol 8 , 392.Xr sdpd 8 393.Sh BUGS 394Most likely. 395Please report bugs if found. 396.Sh AUTHORS 397.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com 398