1 /****************************************************************************** 2 * 3 * Copyright (C) 1999-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 #ifndef SDP_API_H 19 #define SDP_API_H 20 21 #include "bt_target.h" 22 #include "sdpdefs.h" 23 24 /***************************************************************************** 25 * Constants 26 ****************************************************************************/ 27 28 /* Success code and error codes */ 29 #define SDP_SUCCESS 0x0000 30 #define SDP_INVALID_VERSION 0x0001 31 #define SDP_INVALID_SERV_REC_HDL 0x0002 32 #define SDP_INVALID_REQ_SYNTAX 0x0003 33 #define SDP_INVALID_PDU_SIZE 0x0004 34 #define SDP_INVALID_CONT_STATE 0x0005 35 #define SDP_NO_RESOURCES 0x0006 36 #define SDP_DI_REG_FAILED 0x0007 37 #define SDP_DI_DISC_FAILED 0x0008 38 #define SDP_NO_DI_RECORD_FOUND 0x0009 39 #define SDP_ERR_ATTR_NOT_PRESENT 0x000A 40 #define SDP_ILLEGAL_PARAMETER 0x000B 41 42 #define SDP_NO_RECS_MATCH 0xFFF0 43 #define SDP_CONN_FAILED 0xFFF1 44 #define SDP_CFG_FAILED 0xFFF2 45 #define SDP_GENERIC_ERROR 0xFFF3 46 #define SDP_DB_FULL 0xFFF4 47 #define SDP_INVALID_PDU 0xFFF5 48 #define SDP_SECURITY_ERR 0xFFF6 49 #define SDP_CONN_REJECTED 0xFFF7 50 #define SDP_CANCEL 0xFFF8 51 52 /* Define the PSM that SDP uses */ 53 #define SDP_PSM 0x0001 54 55 /* Legacy #define to avoid code changes - SDP UUID is same as BT UUID */ 56 #define tSDP_UUID tBT_UUID 57 58 /* Masks for attr_value field of tSDP_DISC_ATTR */ 59 #define SDP_DISC_ATTR_LEN_MASK 0x0FFF 60 #define SDP_DISC_ATTR_TYPE(len_type) ((len_type) >> 12) 61 #define SDP_DISC_ATTR_LEN(len_type) ((len_type)&SDP_DISC_ATTR_LEN_MASK) 62 63 /* Maximum number of protocol list items (list_elem in tSDP_PROTOCOL_ELEM) */ 64 #define SDP_MAX_LIST_ELEMS 3 65 66 /***************************************************************************** 67 * Type Definitions 68 ****************************************************************************/ 69 70 /* Define a callback function for when discovery is complete. */ 71 typedef void(tSDP_DISC_CMPL_CB)(uint16_t result); 72 typedef void(tSDP_DISC_CMPL_CB2)(uint16_t result, void* user_data); 73 74 typedef struct { 75 RawAddress peer_addr; 76 uint16_t peer_mtu; 77 } tSDP_DR_OPEN; 78 79 typedef struct { 80 uint8_t* p_data; 81 uint16_t data_len; 82 } tSDP_DR_DATA; 83 84 typedef union { 85 tSDP_DR_OPEN open; 86 tSDP_DR_DATA data; 87 } tSDP_DATA; 88 89 /* Define a callback function for when discovery result is received. */ 90 typedef void(tSDP_DISC_RES_CB)(uint16_t event, tSDP_DATA* p_data); 91 92 /* Define a structure to hold the discovered service information. */ 93 typedef struct { 94 union { 95 uint8_t u8; /* 8-bit integer */ 96 uint16_t u16; /* 16-bit integer */ 97 uint32_t u32; /* 32-bit integer */ 98 uint8_t array[4]; /* Variable length field */ 99 struct t_sdp_disc_attr* p_sub_attr; /* Addr of first sub-attr (list)*/ 100 } v; 101 102 } tSDP_DISC_ATVAL; 103 104 typedef struct t_sdp_disc_attr { 105 struct t_sdp_disc_attr* p_next_attr; /* Addr of next linked attr */ 106 uint16_t attr_id; /* Attribute ID */ 107 uint16_t attr_len_type; /* Length and type fields */ 108 tSDP_DISC_ATVAL attr_value; /* Variable length entry data */ 109 } tSDP_DISC_ATTR; 110 111 typedef struct t_sdp_disc_rec { 112 tSDP_DISC_ATTR* p_first_attr; /* First attribute of record */ 113 struct t_sdp_disc_rec* p_next_rec; /* Addr of next linked record */ 114 uint32_t time_read; /* The time the record was read */ 115 RawAddress remote_bd_addr; /* Remote BD address */ 116 } tSDP_DISC_REC; 117 118 typedef struct { 119 uint32_t mem_size; /* Memory size of the DB */ 120 uint32_t mem_free; /* Memory still available */ 121 tSDP_DISC_REC* p_first_rec; /* Addr of first record in DB */ 122 uint16_t num_uuid_filters; /* Number of UUIds to filter */ 123 tSDP_UUID uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */ 124 uint16_t num_attr_filters; /* Number of attribute filters */ 125 uint16_t attr_filters[SDP_MAX_ATTR_FILTERS]; /* Attributes to filter */ 126 uint8_t* p_free_mem; /* Pointer to free memory */ 127 #if (SDP_RAW_DATA_INCLUDED == TRUE) 128 uint8_t* 129 raw_data; /* Received record from server. allocated/released by client */ 130 uint32_t raw_size; /* size of raw_data */ 131 uint32_t raw_used; /* length of raw_data used */ 132 #endif 133 } tSDP_DISCOVERY_DB; 134 135 /* This structure is used to add protocol lists and find protocol elements */ 136 typedef struct { 137 uint16_t protocol_uuid; 138 uint16_t num_params; 139 uint16_t params[SDP_MAX_PROTOCOL_PARAMS]; 140 } tSDP_PROTOCOL_ELEM; 141 142 typedef struct { 143 uint16_t num_elems; 144 tSDP_PROTOCOL_ELEM list_elem[SDP_MAX_LIST_ELEMS]; 145 } tSDP_PROTO_LIST_ELEM; 146 147 /* Device Identification (DI) data structure 148 */ 149 /* Used to set the DI record */ 150 typedef struct t_sdp_di_record { 151 uint16_t vendor; 152 uint16_t vendor_id_source; 153 uint16_t product; 154 uint16_t version; 155 bool primary_record; 156 char client_executable_url[SDP_MAX_ATTR_LEN]; /* optional */ 157 char service_description[SDP_MAX_ATTR_LEN]; /* optional */ 158 char documentation_url[SDP_MAX_ATTR_LEN]; /* optional */ 159 } tSDP_DI_RECORD; 160 161 /* Used to get the DI record */ 162 typedef struct t_sdp_di_get_record { 163 uint16_t spec_id; 164 tSDP_DI_RECORD rec; 165 } tSDP_DI_GET_RECORD; 166 167 /* API into the SDP layer for service discovery. */ 168 169 /******************************************************************************* 170 * 171 * Function SDP_InitDiscoveryDb 172 * 173 * Description This function is called to initialize a discovery database. 174 * 175 * Returns true if successful, false if one or more parameters are bad 176 * 177 ******************************************************************************/ 178 bool SDP_InitDiscoveryDb(tSDP_DISCOVERY_DB* p_db, uint32_t len, 179 uint16_t num_uuid, tSDP_UUID* p_uuid_list, 180 uint16_t num_attr, uint16_t* p_attr_list); 181 182 /******************************************************************************* 183 * 184 * Function SDP_CancelServiceSearch 185 * 186 * Description This function cancels an active query to an SDP server. 187 * 188 * Returns true if discovery cancelled, false if a matching activity is 189 * not found. 190 * 191 ******************************************************************************/ 192 bool SDP_CancelServiceSearch(tSDP_DISCOVERY_DB* p_db); 193 194 /******************************************************************************* 195 * 196 * Function SDP_ServiceSearchRequest 197 * 198 * Description This function queries an SDP server for information. 199 * 200 * Returns true if discovery started, false if failed. 201 * 202 ******************************************************************************/ 203 bool SDP_ServiceSearchRequest(const RawAddress& p_bd_addr, 204 tSDP_DISCOVERY_DB* p_db, tSDP_DISC_CMPL_CB* p_cb); 205 206 /******************************************************************************* 207 * 208 * Function SDP_ServiceSearchAttributeRequest 209 * 210 * Description This function queries an SDP server for information. 211 * 212 * The difference between this API function and the function 213 * SDP_ServiceSearchRequest is that this one does a 214 * combined ServiceSearchAttributeRequest SDP function. 215 * 216 * Returns true if discovery started, false if failed. 217 * 218 ******************************************************************************/ 219 bool SDP_ServiceSearchAttributeRequest(const RawAddress& p_bd_addr, 220 tSDP_DISCOVERY_DB* p_db, 221 tSDP_DISC_CMPL_CB* p_cb); 222 223 /******************************************************************************* 224 * 225 * Function SDP_ServiceSearchAttributeRequest2 226 * 227 * Description This function queries an SDP server for information. 228 * 229 * The difference between this API function and the function 230 * SDP_ServiceSearchRequest is that this one does a 231 * combined ServiceSearchAttributeRequest SDP function with the 232 * user data piggyback 233 * 234 * Returns true if discovery started, false if failed. 235 * 236 ******************************************************************************/ 237 bool SDP_ServiceSearchAttributeRequest2(const RawAddress& p_bd_addr, 238 tSDP_DISCOVERY_DB* p_db, 239 tSDP_DISC_CMPL_CB2* p_cb, 240 void* user_data); 241 242 /* API of utilities to find data in the local discovery database */ 243 244 /******************************************************************************* 245 * 246 * Function SDP_FindAttributeInDb 247 * 248 * Description This function queries an SDP database for a specific 249 * attribute. If the p_start_rec pointer is NULL, it looks from 250 * the beginning of the database, else it continues from the 251 * next record after p_start_rec. 252 * 253 * Returns Pointer to matching record, or NULL 254 * 255 ******************************************************************************/ 256 tSDP_DISC_REC* SDP_FindAttributeInDb(tSDP_DISCOVERY_DB* p_db, uint16_t attr_id, 257 tSDP_DISC_REC* p_start_rec); 258 259 /******************************************************************************* 260 * 261 * Function SDP_FindAttributeInRec 262 * 263 * Description This function searches an SDP discovery record for a 264 * specific attribute. 265 * 266 * Returns Pointer to matching attribute entry, or NULL 267 * 268 ******************************************************************************/ 269 tSDP_DISC_ATTR* SDP_FindAttributeInRec(tSDP_DISC_REC* p_rec, uint16_t attr_id); 270 271 /******************************************************************************* 272 * 273 * Function SDP_FindServiceInDb 274 * 275 * Description This function queries an SDP database for a specific 276 * service. If the p_start_rec pointer is NULL, it looks from 277 * the beginning of the database, else it continues from the 278 * next record after p_start_rec. 279 * 280 * Returns Pointer to record containing service class, or NULL 281 * 282 ******************************************************************************/ 283 tSDP_DISC_REC* SDP_FindServiceInDb(tSDP_DISCOVERY_DB* p_db, 284 uint16_t service_uuid, 285 tSDP_DISC_REC* p_start_rec); 286 287 /******************************************************************************* 288 * 289 * Function SDP_FindServiceUUIDInDb 290 * 291 * Description This function queries an SDP database for a specific 292 * service. If the p_start_rec pointer is NULL, it looks from 293 * the beginning of the database, else it continues from the 294 * next record after p_start_rec. 295 * 296 * NOTE the only difference between this function and the previous 297 * function "SDP_FindServiceInDb()" is that this function takes 298 * a tBT_UUID input. 299 * 300 * Returns Pointer to record containing service class, or NULL 301 * 302 ******************************************************************************/ 303 tSDP_DISC_REC* SDP_FindServiceUUIDInDb(tSDP_DISCOVERY_DB* p_db, 304 tBT_UUID* p_uuid, 305 tSDP_DISC_REC* p_start_rec); 306 307 /******************************************************************************* 308 * 309 * Function SDP_FindServiceUUIDInRec_128bit 310 * 311 * Description Read the 128-bit service UUID within a record, 312 * if there is any. 313 * 314 * Parameters: p_rec - pointer to a SDP record. 315 * p_uuid - output parameter to save the UUID found. 316 * 317 * Returns true if found, otherwise false. 318 * 319 ******************************************************************************/ 320 bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid); 321 322 /******************************************************************************* 323 * 324 * Function SDP_FindServiceInDb_128bit 325 * 326 * Description Query an SDP database for a specific service. 327 * If the p_start_rec pointer is NULL, look from the beginning 328 * of the database, else continue from the next record after 329 * p_start_rec. 330 * 331 * Returns Pointer to record containing service class, or NULL 332 * 333 ******************************************************************************/ 334 tSDP_DISC_REC* SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB* p_db, 335 tSDP_DISC_REC* p_start_rec); 336 337 /******************************************************************************* 338 * 339 * Function SDP_FindProtocolListElemInRec 340 * 341 * Description This function looks at a specific discovery record for a 342 * protocol list element. 343 * 344 * Returns true if found, false if not 345 * If found, the passed protocol list element is filled in. 346 * 347 ******************************************************************************/ 348 bool SDP_FindProtocolListElemInRec(tSDP_DISC_REC* p_rec, uint16_t layer_uuid, 349 tSDP_PROTOCOL_ELEM* p_elem); 350 351 /******************************************************************************* 352 * 353 * Function SDP_FindAddProtoListsElemInRec 354 * 355 * Description This function looks at a specific discovery record for a 356 * protocol list element. 357 * 358 * Returns true if found, false if not 359 * If found, the passed protocol list element is filled in. 360 * 361 ******************************************************************************/ 362 bool SDP_FindAddProtoListsElemInRec(tSDP_DISC_REC* p_rec, uint16_t layer_uuid, 363 tSDP_PROTOCOL_ELEM* p_elem); 364 365 /******************************************************************************* 366 * 367 * Function SDP_FindProfileVersionInRec 368 * 369 * Description This function looks at a specific discovery record for the 370 * Profile list descriptor, and pulls out the version number. 371 * The version number consists of an 8-bit major version and 372 * an 8-bit minor version. 373 * 374 * Returns true if found, false if not 375 * If found, the major and minor version numbers that were 376 * passed in are filled in. 377 * 378 ******************************************************************************/ 379 bool SDP_FindProfileVersionInRec(tSDP_DISC_REC* p_rec, uint16_t profile_uuid, 380 uint16_t* p_version); 381 382 /* API into SDP for local service database updates */ 383 384 /******************************************************************************* 385 * 386 * Function SDP_CreateRecord 387 * 388 * Description This function is called to create a record in the database. 389 * This would be through the SDP database maintenance API. The 390 * record is created empty, teh application should then call 391 * "add_attribute" to add the record's attributes. 392 * 393 * Returns Record handle if OK, else 0. 394 * 395 ******************************************************************************/ 396 uint32_t SDP_CreateRecord(void); 397 398 /******************************************************************************* 399 * 400 * Function SDP_DeleteRecord 401 * 402 * Description This function is called to add a record (or all records) 403 * from the database. This would be through the SDP database 404 * maintenance API. 405 * 406 * If a record handle of 0 is passed, all records are deleted. 407 * 408 * Returns true if succeeded, else false 409 * 410 ******************************************************************************/ 411 bool SDP_DeleteRecord(uint32_t handle); 412 413 /******************************************************************************* 414 * 415 * Function SDP_ReadRecord 416 * 417 * Description This function is called to get the raw data of the record 418 * with the given handle from the database. 419 * 420 * Returns -1, if the record is not found. 421 * Otherwise, the offset (0 or 1) to start of data in p_data. 422 * 423 * The size of data copied into p_data is in *p_data_len. 424 * 425 ******************************************************************************/ 426 int32_t SDP_ReadRecord(uint32_t handle, uint8_t* p_data, int32_t* p_data_len); 427 428 /******************************************************************************* 429 * 430 * Function SDP_AddAttribute 431 * 432 * Description This function is called to add an attribute to a record. 433 * This would be through the SDP database maintenance API. 434 * If the attribute already exists in the record, it is 435 * replaced with the new value. 436 * 437 * NOTE Attribute values must be passed as a Big Endian stream. 438 * 439 * Returns true if added OK, else false 440 * 441 ******************************************************************************/ 442 bool SDP_AddAttribute(uint32_t handle, uint16_t attr_id, uint8_t attr_type, 443 uint32_t attr_len, uint8_t* p_val); 444 445 /******************************************************************************* 446 * 447 * Function SDP_AddSequence 448 * 449 * Description This function is called to add a sequence to a record. 450 * This would be through the SDP database maintenance API. 451 * If the sequence already exists in the record, it is replaced 452 * with the new sequence. 453 * 454 * NOTE Element values must be passed as a Big Endian stream. 455 * 456 * Returns true if added OK, else false 457 * 458 ******************************************************************************/ 459 bool SDP_AddSequence(uint32_t handle, uint16_t attr_id, uint16_t num_elem, 460 uint8_t type[], uint8_t len[], uint8_t* p_val[]); 461 462 /******************************************************************************* 463 * 464 * Function SDP_AddUuidSequence 465 * 466 * Description This function is called to add a UUID sequence to a record. 467 * This would be through the SDP database maintenance API. 468 * If the sequence already exists in the record, it is replaced 469 * with the new sequence. 470 * 471 * Returns true if added OK, else false 472 * 473 ******************************************************************************/ 474 bool SDP_AddUuidSequence(uint32_t handle, uint16_t attr_id, uint16_t num_uuids, 475 uint16_t* p_uuids); 476 477 /******************************************************************************* 478 * 479 * Function SDP_AddProtocolList 480 * 481 * Description This function is called to add a protocol descriptor list to 482 * a record. This would be through the SDP database 483 * maintenance API. If the protocol list already exists in the 484 * record, it is replaced with the new list. 485 * 486 * Returns true if added OK, else false 487 * 488 ******************************************************************************/ 489 bool SDP_AddProtocolList(uint32_t handle, uint16_t num_elem, 490 tSDP_PROTOCOL_ELEM* p_elem_list); 491 492 /******************************************************************************* 493 * 494 * Function SDP_AddAdditionProtoLists 495 * 496 * Description This function is called to add a protocol descriptor list to 497 * a record. This would be through the SDP database maintenance 498 * API. If the protocol list already exists in the record, it 499 * is replaced with the new list. 500 * 501 * Returns true if added OK, else false 502 * 503 ******************************************************************************/ 504 bool SDP_AddAdditionProtoLists(uint32_t handle, uint16_t num_elem, 505 tSDP_PROTO_LIST_ELEM* p_proto_list); 506 507 /******************************************************************************* 508 * 509 * Function SDP_AddProfileDescriptorList 510 * 511 * Description This function is called to add a profile descriptor list to 512 * a record. This would be through the SDP database maintenance 513 * API. If the version already exists in the record, it is 514 * replaced with the new one. 515 * 516 * Returns true if added OK, else false 517 * 518 ******************************************************************************/ 519 bool SDP_AddProfileDescriptorList(uint32_t handle, uint16_t profile_uuid, 520 uint16_t version); 521 522 /******************************************************************************* 523 * 524 * Function SDP_AddLanguageBaseAttrIDList 525 * 526 * Description This function is called to add a language base attr list to 527 * a record. This would be through the SDP database maintenance 528 * API. If the version already exists in the record, it is 529 * replaced with the new one. 530 * 531 * Returns true if added OK, else false 532 * 533 ******************************************************************************/ 534 bool SDP_AddLanguageBaseAttrIDList(uint32_t handle, uint16_t lang, 535 uint16_t char_enc, uint16_t base_id); 536 537 /******************************************************************************* 538 * 539 * Function SDP_AddServiceClassIdList 540 * 541 * Description This function is called to add a service list to a record. 542 * This would be through the SDP database maintenance API. 543 * If the service list already exists in the record, it is 544 * replaced with the new list. 545 * 546 * Returns true if added OK, else false 547 * 548 ******************************************************************************/ 549 bool SDP_AddServiceClassIdList(uint32_t handle, uint16_t num_services, 550 uint16_t* p_service_uuids); 551 552 /******************************************************************************* 553 * 554 * Function SDP_DeleteAttribute 555 * 556 * Description Delete an attribute from a record. 557 * This would be through the SDP database maintenance API. 558 * 559 * Returns true if deleted OK, else false if not found 560 * 561 ******************************************************************************/ 562 bool SDP_DeleteAttribute(uint32_t handle, uint16_t attr_id); 563 564 /* Device Identification APIs */ 565 566 /******************************************************************************* 567 * 568 * Function SDP_SetLocalDiRecord 569 * 570 * Description This function adds a DI record to the local SDP database. 571 * 572 * Returns Returns SDP_SUCCESS if record added successfully, else error 573 * 574 ******************************************************************************/ 575 uint16_t SDP_SetLocalDiRecord(tSDP_DI_RECORD* device_info, uint32_t* p_handle); 576 577 /******************************************************************************* 578 * 579 * Function SDP_DiDiscover 580 * 581 * Description This function queries a remote device for DI information. 582 * 583 * Returns SDP_SUCCESS if query started successfully, else error 584 * 585 ******************************************************************************/ 586 uint16_t SDP_DiDiscover(const RawAddress& remote_device, 587 tSDP_DISCOVERY_DB* p_db, uint32_t len, 588 tSDP_DISC_CMPL_CB* p_cb); 589 590 /******************************************************************************* 591 * 592 * Function SDP_GetNumDiRecords 593 * 594 * Description Searches specified database for DI records 595 * 596 * Returns number of DI records found 597 * 598 ******************************************************************************/ 599 uint8_t SDP_GetNumDiRecords(tSDP_DISCOVERY_DB* p_db); 600 601 /******************************************************************************* 602 * 603 * Function SDP_GetDiRecord 604 * 605 * Description This function retrieves a remote device's DI record from 606 * the specified database. 607 * 608 * Returns SDP_SUCCESS if record retrieved, else error 609 * 610 ******************************************************************************/ 611 uint16_t SDP_GetDiRecord(uint8_t getRecordIndex, 612 tSDP_DI_GET_RECORD* device_info, 613 tSDP_DISCOVERY_DB* p_db); 614 615 /******************************************************************************* 616 * 617 * Function SDP_SetTraceLevel 618 * 619 * Description This function sets the trace level for SDP. If called with 620 * a value of 0xFF, it simply reads the current trace level. 621 * 622 * Returns the new (current) trace level 623 * 624 ******************************************************************************/ 625 uint8_t SDP_SetTraceLevel(uint8_t new_level); 626 627 /******************************************************************************* 628 * 629 * Function SDP_FindServiceUUIDInRec 630 * 631 * Description Read the service UUID within a record, 632 * if there is any. 633 * 634 * Parameters: p_rec - pointer to a SDP record. 635 * 636 * Returns true if found, otherwise false. 637 * 638 ******************************************************************************/ 639 bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC* p_rec, tBT_UUID* p_uuid); 640 641 // Converts UUID-16 to UUID-128 by including the base UUID. 642 // |uuid16| is the 2-byte UUID to convert. 643 // The result with the expanded 128-bit UUID is stored in |p_uuid128|. 644 void sdpu_uuid16_to_uuid128(uint16_t uuid16, uint8_t* p_uuid128); 645 646 #endif /* SDP_API_H */ 647