| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * |
| 4 | * BlueZ - Bluetooth protocol stack for Linux |
| 5 | * |
| 6 | * Copyright (C) 2001-2002 Nokia Corporation |
| 7 | * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> |
| 8 | * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org> |
| 9 | * Copyright (C) 2002-2003 Stephen Crane <steve.crane@rococosoft.com> |
| 10 | * |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef __SDP_LIB_H |
| 15 | #define __SDP_LIB_H |
| 16 | |
| 17 | #include <sys/socket.h> |
| 18 | #include <bluetooth/bluetooth.h> |
| 19 | #include <bluetooth/hci.h> |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | /* |
| 26 | * SDP lists |
| 27 | */ |
| 28 | typedef void(*sdp_list_func_t)(void *, void *); |
| 29 | typedef void(*sdp_free_func_t)(void *); |
| 30 | typedef int (*sdp_comp_func_t)(const void *, const void *); |
| 31 | |
| 32 | sdp_list_t *sdp_list_append(sdp_list_t *list, void *d); |
| 33 | sdp_list_t *sdp_list_remove(sdp_list_t *list, void *d); |
| 34 | sdp_list_t *sdp_list_insert_sorted(sdp_list_t *list, void *data, sdp_comp_func_t f); |
| 35 | void sdp_list_free(sdp_list_t *list, sdp_free_func_t f); |
| 36 | |
| 37 | static inline int sdp_list_len(const sdp_list_t *list) |
| 38 | { |
| 39 | int n = 0; |
| 40 | for (; list; list = list->next) |
| 41 | n++; |
| 42 | return n; |
| 43 | } |
| 44 | |
| 45 | static inline sdp_list_t *sdp_list_find(sdp_list_t *list, void *u, sdp_comp_func_t f) |
| 46 | { |
| 47 | for (; list; list = list->next) |
| 48 | if (f(list->data, u) == 0) |
| 49 | return list; |
| 50 | return NULL; |
| 51 | } |
| 52 | |
| 53 | static inline void sdp_list_foreach(sdp_list_t *list, sdp_list_func_t f, void *u) |
| 54 | { |
| 55 | for (; list; list = list->next) |
| 56 | f(list->data, u); |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Values of the flags parameter to sdp_record_register |
| 61 | */ |
| 62 | #define SDP_RECORD_PERSIST 0x01 |
| 63 | #define SDP_DEVICE_RECORD 0x02 |
| 64 | |
| 65 | /* |
| 66 | * Values of the flags parameter to sdp_connect |
| 67 | */ |
| 68 | #define SDP_RETRY_IF_BUSY 0x01 |
| 69 | #define SDP_WAIT_ON_CLOSE 0x02 |
| 70 | #define SDP_NON_BLOCKING 0x04 |
| 71 | #define SDP_LARGE_MTU 0x08 |
| 72 | |
| 73 | /* |
| 74 | * a session with an SDP server |
| 75 | */ |
| 76 | typedef struct { |
| 77 | int sock; |
| 78 | int state; |
| 79 | int local; |
| 80 | int flags; |
| 81 | uint16_t tid; /* Current transaction ID */ |
| 82 | void *priv; |
| 83 | } sdp_session_t; |
| 84 | |
| 85 | typedef enum { |
| 86 | /* |
| 87 | * Attributes are specified as individual elements |
| 88 | */ |
| 89 | SDP_ATTR_REQ_INDIVIDUAL = 1, |
| 90 | /* |
| 91 | * Attributes are specified as a range |
| 92 | */ |
| 93 | SDP_ATTR_REQ_RANGE |
| 94 | } sdp_attrreq_type_t; |
| 95 | |
| 96 | /* |
| 97 | * When the pdu_id(type) is a sdp error response, check the status value |
| 98 | * to figure out the error reason. For status values 0x0001-0x0006 check |
| 99 | * Bluetooth SPEC. If the status is 0xffff, call sdp_get_error function |
| 100 | * to get the real reason: |
| 101 | * - wrong transaction ID(EPROTO) |
| 102 | * - wrong PDU id or(EPROTO) |
| 103 | * - I/O error |
| 104 | */ |
| 105 | typedef void sdp_callback_t(uint8_t type, uint16_t status, uint8_t *rsp, size_t size, void *udata); |
| 106 | |
| 107 | /* |
| 108 | * create an L2CAP connection to a Bluetooth device |
| 109 | * |
| 110 | * INPUT: |
| 111 | * |
| 112 | * bdaddr_t *src: |
| 113 | * Address of the local device to use to make the connection |
| 114 | * (or BDADDR_ANY) |
| 115 | * |
| 116 | * bdaddr_t *dst: |
| 117 | * Address of the SDP server device |
| 118 | */ |
| 119 | sdp_session_t *sdp_connect(const bdaddr_t *src, const bdaddr_t *dst, uint32_t flags); |
| 120 | int sdp_close(sdp_session_t *session); |
| 121 | int sdp_get_socket(const sdp_session_t *session); |
| 122 | |
| 123 | /* |
| 124 | * SDP transaction: functions for asynchronous search. |
| 125 | */ |
| 126 | sdp_session_t *sdp_create(int sk, uint32_t flags); |
| 127 | int sdp_get_error(sdp_session_t *session); |
| 128 | int sdp_process(sdp_session_t *session); |
| 129 | int sdp_set_notify(sdp_session_t *session, sdp_callback_t *func, void *udata); |
| 130 | |
| 131 | int sdp_service_search_async(sdp_session_t *session, const sdp_list_t *search, uint16_t max_rec_num); |
| 132 | int sdp_service_attr_async(sdp_session_t *session, uint32_t handle, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list); |
| 133 | int sdp_service_search_attr_async(sdp_session_t *session, const sdp_list_t *search, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list); |
| 134 | |
| 135 | uint16_t sdp_gen_tid(sdp_session_t *session); |
| 136 | |
| 137 | /* |
| 138 | * find all devices in the piconet |
| 139 | */ |
| 140 | int sdp_general_inquiry(inquiry_info *ii, int dev_num, int duration, uint8_t *found); |
| 141 | |
| 142 | /* flexible extraction of basic attributes - Jean II */ |
| 143 | int sdp_get_int_attr(const sdp_record_t *rec, uint16_t attr, int *value); |
| 144 | int sdp_get_string_attr(const sdp_record_t *rec, uint16_t attr, char *value, int valuelen); |
| 145 | |
| 146 | /* |
| 147 | * Basic sdp data functions |
| 148 | */ |
| 149 | sdp_data_t *sdp_data_alloc(uint8_t dtd, const void *value); |
| 150 | sdp_data_t *sdp_data_alloc_with_length(uint8_t dtd, const void *value, uint32_t length); |
| 151 | void sdp_data_free(sdp_data_t *data); |
| 152 | sdp_data_t *sdp_data_get(const sdp_record_t *rec, uint16_t attr_id); |
| 153 | |
| 154 | sdp_data_t *sdp_seq_alloc(void **dtds, void **values, int len); |
| 155 | sdp_data_t *sdp_seq_alloc_with_length(void **dtds, void **values, int *length, int len); |
| 156 | sdp_data_t *sdp_seq_append(sdp_data_t *seq, sdp_data_t *data); |
| 157 | |
| 158 | int sdp_attr_add(sdp_record_t *rec, uint16_t attr, sdp_data_t *data); |
| 159 | void sdp_attr_remove(sdp_record_t *rec, uint16_t attr); |
| 160 | void sdp_attr_replace(sdp_record_t *rec, uint16_t attr, sdp_data_t *data); |
| 161 | int sdp_set_uuidseq_attr(sdp_record_t *rec, uint16_t attr, sdp_list_t *seq); |
| 162 | int sdp_get_uuidseq_attr(const sdp_record_t *rec, uint16_t attr, sdp_list_t **seqp); |
| 163 | |
| 164 | /* |
| 165 | * NOTE that none of the functions below will update the SDP server, |
| 166 | * unless the {register, update}sdp_record_t() function is invoked. |
| 167 | * All functions which return an integer value, return 0 on success |
| 168 | * or -1 on failure. |
| 169 | */ |
| 170 | |
| 171 | /* |
| 172 | * Create an attribute and add it to the service record's attribute list. |
| 173 | * This consists of the data type descriptor of the attribute, |
| 174 | * the value of the attribute and the attribute identifier. |
| 175 | */ |
| 176 | int sdp_attr_add_new(sdp_record_t *rec, uint16_t attr, uint8_t dtd, const void *p); |
| 177 | |
| 178 | /* |
| 179 | * Set the information attributes of the service record. |
| 180 | * The set of attributes comprises service name, description |
| 181 | * and provider name |
| 182 | */ |
| 183 | void sdp_set_info_attr(sdp_record_t *rec, const char *name, const char *prov, const char *desc); |
| 184 | |
| 185 | /* |
| 186 | * Set the ServiceClassID attribute to the sequence specified by seq. |
| 187 | * Note that the identifiers need to be in sorted order from the most |
| 188 | * specific to the most generic service class that this service |
| 189 | * conforms to. |
| 190 | */ |
| 191 | static inline int sdp_set_service_classes(sdp_record_t *rec, sdp_list_t *seq) |
| 192 | { |
| 193 | return sdp_set_uuidseq_attr(rec, SDP_ATTR_SVCLASS_ID_LIST, seq); |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Get the service classes to which the service conforms. |
| 198 | * |
| 199 | * When set, the list contains elements of ServiceClassIdentifer(uint16_t) |
| 200 | * ordered from most specific to most generic |
| 201 | */ |
| 202 | static inline int sdp_get_service_classes(const sdp_record_t *rec, sdp_list_t **seqp) |
| 203 | { |
| 204 | return sdp_get_uuidseq_attr(rec, SDP_ATTR_SVCLASS_ID_LIST, seqp); |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * Set the BrowseGroupList attribute to the list specified by seq. |
| 209 | * |
| 210 | * A service can belong to one or more service groups |
| 211 | * and the list comprises such group identifiers (UUIDs) |
| 212 | */ |
| 213 | static inline int sdp_set_browse_groups(sdp_record_t *rec, sdp_list_t *seq) |
| 214 | { |
| 215 | return sdp_set_uuidseq_attr(rec, SDP_ATTR_BROWSE_GRP_LIST, seq); |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * Set the access protocols of the record to those specified in proto |
| 220 | */ |
| 221 | int sdp_set_access_protos(sdp_record_t *rec, const sdp_list_t *proto); |
| 222 | |
| 223 | /* |
| 224 | * Set the additional access protocols of the record to those specified in proto |
| 225 | */ |
| 226 | int sdp_set_add_access_protos(sdp_record_t *rec, const sdp_list_t *proto); |
| 227 | |
| 228 | /* |
| 229 | * Get protocol port (i.e. PSM for L2CAP, Channel for RFCOMM) |
| 230 | */ |
| 231 | int sdp_get_proto_port(const sdp_list_t *list, int proto); |
| 232 | |
| 233 | /* |
| 234 | * Get protocol descriptor. |
| 235 | */ |
| 236 | sdp_data_t *sdp_get_proto_desc(sdp_list_t *list, int proto); |
| 237 | |
| 238 | /* |
| 239 | * Set the LanguageBase attributes to the values specified in list |
| 240 | * (a linked list of sdp_lang_attr_t objects, one for each language in |
| 241 | * which user-visible attributes are present). |
| 242 | */ |
| 243 | int sdp_set_lang_attr(sdp_record_t *rec, const sdp_list_t *list); |
| 244 | |
| 245 | /* |
| 246 | * Set the ServiceInfoTimeToLive attribute of the service. |
| 247 | * This is the number of seconds that this record is guaranteed |
| 248 | * not to change after being obtained by a client. |
| 249 | */ |
| 250 | static inline int sdp_set_service_ttl(sdp_record_t *rec, uint32_t ttl) |
| 251 | { |
| 252 | return sdp_attr_add_new(rec, SDP_ATTR_SVCINFO_TTL, SDP_UINT32, p: &ttl); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Set the ServiceRecordState attribute of a service. This is |
| 257 | * guaranteed to change if there is any kind of modification to |
| 258 | * the record. |
| 259 | */ |
| 260 | static inline int sdp_set_record_state(sdp_record_t *rec, uint32_t state) |
| 261 | { |
| 262 | return sdp_attr_add_new(rec, SDP_ATTR_RECORD_STATE, SDP_UINT32, p: &state); |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | * Set the ServiceID attribute of a service. |
| 267 | */ |
| 268 | void sdp_set_service_id(sdp_record_t *rec, uuid_t uuid); |
| 269 | |
| 270 | /* |
| 271 | * Set the GroupID attribute of a service |
| 272 | */ |
| 273 | void sdp_set_group_id(sdp_record_t *rec, uuid_t grouuuid); |
| 274 | |
| 275 | /* |
| 276 | * Set the ServiceAvailability attribute of a service. |
| 277 | * |
| 278 | * Note that this represents the relative availability |
| 279 | * of the service: 0x00 means completely unavailable; |
| 280 | * 0xFF means maximum availability. |
| 281 | */ |
| 282 | static inline int sdp_set_service_avail(sdp_record_t *rec, uint8_t avail) |
| 283 | { |
| 284 | return sdp_attr_add_new(rec, SDP_ATTR_SERVICE_AVAILABILITY, SDP_UINT8, p: &avail); |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * Set the profile descriptor list attribute of a record. |
| 289 | * |
| 290 | * Each element in the list is an object of type |
| 291 | * sdp_profile_desc_t which is a definition of the |
| 292 | * Bluetooth profile that this service conforms to. |
| 293 | */ |
| 294 | int sdp_set_profile_descs(sdp_record_t *rec, const sdp_list_t *desc); |
| 295 | |
| 296 | /* |
| 297 | * Set URL attributes of a record. |
| 298 | * |
| 299 | * ClientExecutableURL: a URL to a client's platform specific (WinCE, |
| 300 | * PalmOS) executable code that can be used to access this service. |
| 301 | * |
| 302 | * DocumentationURL: a URL pointing to service documentation |
| 303 | * |
| 304 | * IconURL: a URL to an icon that can be used to represent this service. |
| 305 | * |
| 306 | * Note: pass NULL for any URLs that you don't want to set or remove |
| 307 | */ |
| 308 | void sdp_set_url_attr(sdp_record_t *rec, const char *clientExecURL, const char *docURL, const char *iconURL); |
| 309 | |
| 310 | /* |
| 311 | * a service search request. |
| 312 | * |
| 313 | * INPUT : |
| 314 | * |
| 315 | * sdp_list_t *search |
| 316 | * list containing elements of the search |
| 317 | * pattern. Each entry in the list is a UUID |
| 318 | * of the service to be searched |
| 319 | * |
| 320 | * uint16_t max_rec_num |
| 321 | * An integer specifying the maximum number of |
| 322 | * entries that the client can handle in the response. |
| 323 | * |
| 324 | * OUTPUT : |
| 325 | * |
| 326 | * int return value |
| 327 | * 0 |
| 328 | * The request completed successfully. This does not |
| 329 | * mean the requested services were found |
| 330 | * -1 |
| 331 | * The request completed unsuccessfully |
| 332 | * |
| 333 | * sdp_list_t *rsp_list |
| 334 | * This variable is set on a successful return if there are |
| 335 | * non-zero service handles. It is a singly linked list of |
| 336 | * service record handles (uint16_t) |
| 337 | */ |
| 338 | int sdp_service_search_req(sdp_session_t *session, const sdp_list_t *search, uint16_t max_rec_num, sdp_list_t **rsp_list); |
| 339 | |
| 340 | /* |
| 341 | * a service attribute request. |
| 342 | * |
| 343 | * INPUT : |
| 344 | * |
| 345 | * uint32_t handle |
| 346 | * The handle of the service for which the attribute(s) are |
| 347 | * requested |
| 348 | * |
| 349 | * sdp_attrreq_type_t reqtype |
| 350 | * Attribute identifiers are 16 bit unsigned integers specified |
| 351 | * in one of 2 ways described below : |
| 352 | * SDP_ATTR_REQ_INDIVIDUAL - 16bit individual identifiers |
| 353 | * They are the actual attribute identifiers in ascending order |
| 354 | * |
| 355 | * SDP_ATTR_REQ_RANGE - 32bit identifier range |
| 356 | * The high-order 16bits is the start of range |
| 357 | * the low-order 16bits are the end of range |
| 358 | * 0x0000 to 0xFFFF gets all attributes |
| 359 | * |
| 360 | * sdp_list_t *attrid_list |
| 361 | * Singly linked list containing attribute identifiers desired. |
| 362 | * Every element is either a uint16_t(attrSpec = SDP_ATTR_REQ_INDIVIDUAL) |
| 363 | * or a uint32_t(attrSpec=SDP_ATTR_REQ_RANGE) |
| 364 | * |
| 365 | * OUTPUT : |
| 366 | * int return value |
| 367 | * 0 |
| 368 | * The request completed successfully. This does not |
| 369 | * mean the requested services were found |
| 370 | * -1 |
| 371 | * The request completed unsuccessfully due to a timeout |
| 372 | */ |
| 373 | sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list); |
| 374 | |
| 375 | /* |
| 376 | * This is a service search request combined with the service |
| 377 | * attribute request. First a service class match is done and |
| 378 | * for matching service, requested attributes are extracted |
| 379 | * |
| 380 | * INPUT : |
| 381 | * |
| 382 | * sdp_list_t *search |
| 383 | * Singly linked list containing elements of the search |
| 384 | * pattern. Each entry in the list is a UUID(DataTypeSDP_UUID16) |
| 385 | * of the service to be searched |
| 386 | * |
| 387 | * AttributeSpecification attrSpec |
| 388 | * Attribute identifiers are 16 bit unsigned integers specified |
| 389 | * in one of 2 ways described below : |
| 390 | * SDP_ATTR_REQ_INDIVIDUAL - 16bit individual identifiers |
| 391 | * They are the actual attribute identifiers in ascending order |
| 392 | * |
| 393 | * SDP_ATTR_REQ_RANGE - 32bit identifier range |
| 394 | * The high-order 16bits is the start of range |
| 395 | * the low-order 16bits are the end of range |
| 396 | * 0x0000 to 0xFFFF gets all attributes |
| 397 | * |
| 398 | * sdp_list_t *attrid_list |
| 399 | * Singly linked list containing attribute identifiers desired. |
| 400 | * Every element is either a uint16_t(attrSpec = SDP_ATTR_REQ_INDIVIDUAL) |
| 401 | * or a uint32_t(attrSpec=SDP_ATTR_REQ_RANGE) |
| 402 | * |
| 403 | * OUTPUT : |
| 404 | * int return value |
| 405 | * 0 |
| 406 | * The request completed successfully. This does not |
| 407 | * mean the requested services were found |
| 408 | * -1 |
| 409 | * The request completed unsuccessfully due to a timeout |
| 410 | * |
| 411 | * sdp_list_t *rsp_list |
| 412 | * This variable is set on a successful return to point to |
| 413 | * service(s) found. Each element of this list is of type |
| 414 | * sdp_record_t *. |
| 415 | */ |
| 416 | int sdp_service_search_attr_req(sdp_session_t *session, const sdp_list_t *search, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list, sdp_list_t **rsp_list); |
| 417 | |
| 418 | /* |
| 419 | * Allocate/free a service record and its attributes |
| 420 | */ |
| 421 | sdp_record_t *sdp_record_alloc(void); |
| 422 | void sdp_record_free(sdp_record_t *rec); |
| 423 | |
| 424 | /* |
| 425 | * Register a service record. |
| 426 | * |
| 427 | * Note: It is the responsbility of the Service Provider to create the |
| 428 | * record first and set its attributes using setXXX() methods. |
| 429 | * |
| 430 | * The service provider must then call sdp_record_register() to make |
| 431 | * the service record visible to SDP clients. This function returns 0 |
| 432 | * on success or -1 on failure (and sets errno). |
| 433 | */ |
| 434 | int sdp_device_record_register_binary(sdp_session_t *session, bdaddr_t *device, uint8_t *data, uint32_t size, uint8_t flags, uint32_t *handle); |
| 435 | int sdp_device_record_register(sdp_session_t *session, bdaddr_t *device, sdp_record_t *rec, uint8_t flags); |
| 436 | int sdp_record_register(sdp_session_t *session, sdp_record_t *rec, uint8_t flags); |
| 437 | |
| 438 | /* |
| 439 | * Unregister a service record. |
| 440 | */ |
| 441 | int sdp_device_record_unregister_binary(sdp_session_t *session, bdaddr_t *device, uint32_t handle); |
| 442 | int sdp_device_record_unregister(sdp_session_t *session, bdaddr_t *device, sdp_record_t *rec); |
| 443 | int sdp_record_unregister(sdp_session_t *session, sdp_record_t *rec); |
| 444 | |
| 445 | /* |
| 446 | * Update an existing service record. (Calling this function |
| 447 | * before a previous call to sdp_record_register() will result |
| 448 | * in an error.) |
| 449 | */ |
| 450 | int sdp_device_record_update_binary(sdp_session_t *session, bdaddr_t *device, uint32_t handle, uint8_t *data, uint32_t size); |
| 451 | int sdp_device_record_update(sdp_session_t *session, bdaddr_t *device, const sdp_record_t *rec); |
| 452 | int sdp_record_update(sdp_session_t *sess, const sdp_record_t *rec); |
| 453 | |
| 454 | void sdp_record_print(const sdp_record_t *rec); |
| 455 | |
| 456 | /* |
| 457 | * UUID functions |
| 458 | */ |
| 459 | uuid_t *sdp_uuid16_create(uuid_t *uuid, uint16_t data); |
| 460 | uuid_t *sdp_uuid32_create(uuid_t *uuid, uint32_t data); |
| 461 | uuid_t *sdp_uuid128_create(uuid_t *uuid, const void *data); |
| 462 | int sdp_uuid16_cmp(const void *p1, const void *p2); |
| 463 | int sdp_uuid128_cmp(const void *p1, const void *p2); |
| 464 | int sdp_uuid_cmp(const void *p1, const void *p2); |
| 465 | uuid_t *sdp_uuid_to_uuid128(const uuid_t *uuid); |
| 466 | void sdp_uuid16_to_uuid128(uuid_t *uuid128, const uuid_t *uuid16); |
| 467 | void sdp_uuid32_to_uuid128(uuid_t *uuid128, const uuid_t *uuid32); |
| 468 | int sdp_uuid128_to_uuid(uuid_t *uuid); |
| 469 | int sdp_uuid_to_proto(uuid_t *uuid); |
| 470 | int (const uint8_t *buffer, int bufsize, uuid_t *uuid, int *scanned); |
| 471 | void sdp_uuid_print(const uuid_t *uuid); |
| 472 | |
| 473 | #define MAX_LEN_UUID_STR 37 |
| 474 | #define MAX_LEN_PROTOCOL_UUID_STR 8 |
| 475 | #define MAX_LEN_SERVICECLASS_UUID_STR 28 |
| 476 | #define MAX_LEN_PROFILEDESCRIPTOR_UUID_STR 28 |
| 477 | |
| 478 | int sdp_uuid2strn(const uuid_t *uuid, char *str, size_t n); |
| 479 | int sdp_proto_uuid2strn(const uuid_t *uuid, char *str, size_t n); |
| 480 | int sdp_svclass_uuid2strn(const uuid_t *uuid, char *str, size_t n); |
| 481 | int sdp_profile_uuid2strn(const uuid_t *uuid, char *str, size_t n); |
| 482 | |
| 483 | /* |
| 484 | * In all the sdp_get_XXX(handle, XXX *xxx) functions below, |
| 485 | * the XXX * is set to point to the value, should it exist |
| 486 | * and 0 is returned. If the value does not exist, -1 is |
| 487 | * returned and errno set to ENODATA. |
| 488 | * |
| 489 | * In all the methods below, the memory management rules are |
| 490 | * simple. Don't free anything! The pointer returned, in the |
| 491 | * case of constructed types, is a pointer to the contents |
| 492 | * of the sdp_record_t. |
| 493 | */ |
| 494 | |
| 495 | /* |
| 496 | * Get the access protocols from the service record |
| 497 | */ |
| 498 | int sdp_get_access_protos(const sdp_record_t *rec, sdp_list_t **protos); |
| 499 | |
| 500 | /* |
| 501 | * Get the additional access protocols from the service record |
| 502 | */ |
| 503 | int sdp_get_add_access_protos(const sdp_record_t *rec, sdp_list_t **protos); |
| 504 | |
| 505 | /* |
| 506 | * Extract the list of browse groups to which the service belongs. |
| 507 | * When set, seqp contains elements of GroupID (uint16_t) |
| 508 | */ |
| 509 | static inline int sdp_get_browse_groups(const sdp_record_t *rec, sdp_list_t **seqp) |
| 510 | { |
| 511 | return sdp_get_uuidseq_attr(rec, SDP_ATTR_BROWSE_GRP_LIST, seqp); |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * Extract language attribute meta-data of the service record. |
| 516 | * For each language in the service record, LangSeq has a struct of type |
| 517 | * sdp_lang_attr_t. |
| 518 | */ |
| 519 | int sdp_get_lang_attr(const sdp_record_t *rec, sdp_list_t **langSeq); |
| 520 | |
| 521 | /* |
| 522 | * Extract the Bluetooth profile descriptor sequence from a record. |
| 523 | * Each element in the list is of type sdp_profile_desc_t |
| 524 | * which contains the UUID of the profile and its version number |
| 525 | * (encoded as major and minor in the high-order 8bits |
| 526 | * and low-order 8bits respectively of the uint16_t) |
| 527 | */ |
| 528 | int sdp_get_profile_descs(const sdp_record_t *rec, sdp_list_t **profDesc); |
| 529 | |
| 530 | /* |
| 531 | * Extract SDP server version numbers |
| 532 | * |
| 533 | * Note: that this is an attribute of the SDP server only and |
| 534 | * contains a list of uint16_t each of which represent the |
| 535 | * major and minor SDP version numbers supported by this server |
| 536 | */ |
| 537 | int sdp_get_server_ver(const sdp_record_t *rec, sdp_list_t **pVnumList); |
| 538 | |
| 539 | int sdp_get_service_id(const sdp_record_t *rec, uuid_t *uuid); |
| 540 | int sdp_get_group_id(const sdp_record_t *rec, uuid_t *uuid); |
| 541 | int sdp_get_record_state(const sdp_record_t *rec, uint32_t *svcRecState); |
| 542 | int sdp_get_service_avail(const sdp_record_t *rec, uint8_t *svcAvail); |
| 543 | int sdp_get_service_ttl(const sdp_record_t *rec, uint32_t *svcTTLInfo); |
| 544 | int sdp_get_database_state(const sdp_record_t *rec, uint32_t *svcDBState); |
| 545 | |
| 546 | static inline int sdp_get_service_name(const sdp_record_t *rec, char *str, int len) |
| 547 | { |
| 548 | return sdp_get_string_attr(rec, SDP_ATTR_SVCNAME_PRIMARY, value: str, valuelen: len); |
| 549 | } |
| 550 | |
| 551 | static inline int sdp_get_service_desc(const sdp_record_t *rec, char *str, int len) |
| 552 | { |
| 553 | return sdp_get_string_attr(rec, SDP_ATTR_SVCDESC_PRIMARY, value: str, valuelen: len); |
| 554 | } |
| 555 | |
| 556 | static inline int sdp_get_provider_name(const sdp_record_t *rec, char *str, int len) |
| 557 | { |
| 558 | return sdp_get_string_attr(rec, SDP_ATTR_PROVNAME_PRIMARY, value: str, valuelen: len); |
| 559 | } |
| 560 | |
| 561 | static inline int sdp_get_doc_url(const sdp_record_t *rec, char *str, int len) |
| 562 | { |
| 563 | return sdp_get_string_attr(rec, SDP_ATTR_DOC_URL, value: str, valuelen: len); |
| 564 | } |
| 565 | |
| 566 | static inline int sdp_get_clnt_exec_url(const sdp_record_t *rec, char *str, int len) |
| 567 | { |
| 568 | return sdp_get_string_attr(rec, SDP_ATTR_CLNT_EXEC_URL, value: str, valuelen: len); |
| 569 | } |
| 570 | |
| 571 | static inline int sdp_get_icon_url(const sdp_record_t *rec, char *str, int len) |
| 572 | { |
| 573 | return sdp_get_string_attr(rec, SDP_ATTR_ICON_URL, value: str, valuelen: len); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * Set the supported features |
| 578 | * sf should be a list of list with each feature data |
| 579 | * Returns 0 on success -1 on fail |
| 580 | */ |
| 581 | int sdp_set_supp_feat(sdp_record_t *rec, const sdp_list_t *sf); |
| 582 | |
| 583 | /* |
| 584 | * Get the supported features |
| 585 | * seqp is set to a list of list with each feature data |
| 586 | * Returns 0 on success, if an error occurred -1 is returned and errno is set |
| 587 | */ |
| 588 | int sdp_get_supp_feat(const sdp_record_t *rec, sdp_list_t **seqp); |
| 589 | |
| 590 | sdp_record_t *(const uint8_t *pdata, int bufsize, int *scanned); |
| 591 | sdp_record_t *sdp_copy_record(sdp_record_t *rec); |
| 592 | |
| 593 | void sdp_data_print(sdp_data_t *data); |
| 594 | void sdp_print_service_attr(sdp_list_t *alist); |
| 595 | |
| 596 | int sdp_attrid_comp_func(const void *key1, const void *key2); |
| 597 | |
| 598 | void sdp_set_seq_len(uint8_t *ptr, uint32_t length); |
| 599 | void sdp_set_attrid(sdp_buf_t *pdu, uint16_t id); |
| 600 | void sdp_append_to_pdu(sdp_buf_t *dst, sdp_data_t *d); |
| 601 | void sdp_append_to_buf(sdp_buf_t *dst, uint8_t *data, uint32_t len); |
| 602 | |
| 603 | int sdp_gen_pdu(sdp_buf_t *pdu, sdp_data_t *data); |
| 604 | int sdp_gen_record_pdu(const sdp_record_t *rec, sdp_buf_t *pdu); |
| 605 | |
| 606 | int (const uint8_t *buf, int bufsize, uint8_t *dtdp, int *size); |
| 607 | |
| 608 | sdp_data_t *(const uint8_t *pdata, int bufsize, int *, sdp_record_t *rec); |
| 609 | |
| 610 | void sdp_pattern_add_uuid(sdp_record_t *rec, uuid_t *uuid); |
| 611 | void sdp_pattern_add_uuidseq(sdp_record_t *rec, sdp_list_t *seq); |
| 612 | |
| 613 | int sdp_send_req_w4_rsp(sdp_session_t *session, uint8_t *req, uint8_t *rsp, uint32_t reqsize, uint32_t *rspsize); |
| 614 | |
| 615 | void sdp_add_lang_attr(sdp_record_t *rec); |
| 616 | |
| 617 | #ifdef __cplusplus |
| 618 | } |
| 619 | #endif |
| 620 | |
| 621 | #endif /* __SDP_LIB_H */ |
| 622 | |