1 /****************************************************************************** 2 * 3 * Copyright 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 /* Masks for attr_value field of tSDP_DISC_ATTR */ 56 #define SDP_DISC_ATTR_LEN_MASK 0x0FFF 57 #define SDP_DISC_ATTR_TYPE(len_type) ((len_type) >> 12) 58 #define SDP_DISC_ATTR_LEN(len_type) ((len_type)&SDP_DISC_ATTR_LEN_MASK) 59 60 /* Maximum number of protocol list items (list_elem in tSDP_PROTOCOL_ELEM) */ 61 #define SDP_MAX_LIST_ELEMS 3 62 63 /***************************************************************************** 64 * Type Definitions 65 ****************************************************************************/ 66 67 /* Define a callback function for when discovery is complete. */ 68 typedef void(tSDP_DISC_CMPL_CB)(uint16_t result); 69 typedef void(tSDP_DISC_CMPL_CB2)(uint16_t result, void* user_data); 70 71 typedef struct { 72 RawAddress peer_addr; 73 uint16_t peer_mtu; 74 } tSDP_DR_OPEN; 75 76 typedef struct { 77 uint8_t* p_data; 78 uint16_t data_len; 79 } tSDP_DR_DATA; 80 81 typedef union { 82 tSDP_DR_OPEN open; 83 tSDP_DR_DATA data; 84 } tSDP_DATA; 85 86 /* Define a structure to hold the discovered service information. */ 87 typedef struct { 88 union { 89 uint8_t u8; /* 8-bit integer */ 90 uint16_t u16; /* 16-bit integer */ 91 uint32_t u32; /* 32-bit integer */ 92 uint8_t array[4]; /* Variable length field */ 93 struct t_sdp_disc_attr* p_sub_attr; /* Addr of first sub-attr (list)*/ 94 } v; 95 96 } tSDP_DISC_ATVAL; 97 98 typedef struct t_sdp_disc_attr { 99 struct t_sdp_disc_attr* p_next_attr; /* Addr of next linked attr */ 100 uint16_t attr_id; /* Attribute ID */ 101 uint16_t attr_len_type; /* Length and type fields */ 102 tSDP_DISC_ATVAL attr_value; /* Variable length entry data */ 103 } tSDP_DISC_ATTR; 104 105 typedef struct t_sdp_disc_rec { 106 tSDP_DISC_ATTR* p_first_attr; /* First attribute of record */ 107 struct t_sdp_disc_rec* p_next_rec; /* Addr of next linked record */ 108 uint32_t time_read; /* The time the record was read */ 109 RawAddress remote_bd_addr; /* Remote BD address */ 110 } tSDP_DISC_REC; 111 112 typedef struct { 113 uint32_t mem_size; /* Memory size of the DB */ 114 uint32_t mem_free; /* Memory still available */ 115 tSDP_DISC_REC* p_first_rec; /* Addr of first record in DB */ 116 uint16_t num_uuid_filters; /* Number of UUIds to filter */ 117 bluetooth::Uuid uuid_filters[SDP_MAX_UUID_FILTERS]; /* UUIDs to filter */ 118 uint16_t num_attr_filters; /* Number of attribute filters */ 119 uint16_t attr_filters[SDP_MAX_ATTR_FILTERS]; /* Attributes to filter */ 120 uint8_t* p_free_mem; /* Pointer to free memory */ 121 #if (SDP_RAW_DATA_INCLUDED == TRUE) 122 uint8_t* 123 raw_data; /* Received record from server. allocated/released by client */ 124 uint32_t raw_size; /* size of raw_data */ 125 uint32_t raw_used; /* length of raw_data used */ 126 #endif 127 } tSDP_DISCOVERY_DB; 128 129 /* This structure is used to add protocol lists and find protocol elements */ 130 typedef struct { 131 uint16_t protocol_uuid; 132 uint16_t num_params; 133 uint16_t params[SDP_MAX_PROTOCOL_PARAMS]; 134 } tSDP_PROTOCOL_ELEM; 135 136 typedef struct { 137 uint16_t num_elems; 138 tSDP_PROTOCOL_ELEM list_elem[SDP_MAX_LIST_ELEMS]; 139 } tSDP_PROTO_LIST_ELEM; 140 141 /* Device Identification (DI) data structure 142 */ 143 /* Used to set the DI record */ 144 typedef struct t_sdp_di_record { 145 uint16_t vendor; 146 uint16_t vendor_id_source; 147 uint16_t product; 148 uint16_t version; 149 bool primary_record; 150 char client_executable_url[SDP_MAX_ATTR_LEN]; /* optional */ 151 char service_description[SDP_MAX_ATTR_LEN]; /* optional */ 152 char documentation_url[SDP_MAX_ATTR_LEN]; /* optional */ 153 } tSDP_DI_RECORD; 154 155 /* Used to get the DI record */ 156 typedef struct t_sdp_di_get_record { 157 uint16_t spec_id; 158 tSDP_DI_RECORD rec; 159 } tSDP_DI_GET_RECORD; 160 161 /* API into the SDP layer for service discovery. */ 162 163 /******************************************************************************* 164 * 165 * Function SDP_InitDiscoveryDb 166 * 167 * Description This function is called to initialize a discovery database. 168 * 169 * Returns true if successful, false if one or more parameters are bad 170 * 171 ******************************************************************************/ 172 bool SDP_InitDiscoveryDb(tSDP_DISCOVERY_DB* p_db, uint32_t len, 173 uint16_t num_uuid, const bluetooth::Uuid* p_uuid_list, 174 uint16_t num_attr, uint16_t* p_attr_list); 175 176 /******************************************************************************* 177 * 178 * Function SDP_CancelServiceSearch 179 * 180 * Description This function cancels an active query to an SDP server. 181 * 182 * Returns true if discovery cancelled, false if a matching activity is 183 * not found. 184 * 185 ******************************************************************************/ 186 bool SDP_CancelServiceSearch(tSDP_DISCOVERY_DB* p_db); 187 188 /******************************************************************************* 189 * 190 * Function SDP_ServiceSearchRequest 191 * 192 * Description This function queries an SDP server for information. 193 * 194 * Returns true if discovery started, false if failed. 195 * 196 ******************************************************************************/ 197 bool SDP_ServiceSearchRequest(const RawAddress& p_bd_addr, 198 tSDP_DISCOVERY_DB* p_db, tSDP_DISC_CMPL_CB* p_cb); 199 200 /******************************************************************************* 201 * 202 * Function SDP_ServiceSearchAttributeRequest 203 * 204 * Description This function queries an SDP server for information. 205 * 206 * The difference between this API function and the function 207 * SDP_ServiceSearchRequest is that this one does a 208 * combined ServiceSearchAttributeRequest SDP function. 209 * 210 * Returns true if discovery started, false if failed. 211 * 212 ******************************************************************************/ 213 bool SDP_ServiceSearchAttributeRequest(const RawAddress& p_bd_addr, 214 tSDP_DISCOVERY_DB* p_db, 215 tSDP_DISC_CMPL_CB* p_cb); 216 217 /******************************************************************************* 218 * 219 * Function SDP_ServiceSearchAttributeRequest2 220 * 221 * Description This function queries an SDP server for information. 222 * 223 * The difference between this API function and the function 224 * SDP_ServiceSearchRequest is that this one does a 225 * combined ServiceSearchAttributeRequest SDP function with the 226 * user data piggyback 227 * 228 * Returns true if discovery started, false if failed. 229 * 230 ******************************************************************************/ 231 bool SDP_ServiceSearchAttributeRequest2(const RawAddress& p_bd_addr, 232 tSDP_DISCOVERY_DB* p_db, 233 tSDP_DISC_CMPL_CB2* p_cb, 234 void* user_data); 235 236 /* API of utilities to find data in the local discovery database */ 237 238 /******************************************************************************* 239 * 240 * Function SDP_FindAttributeInRec 241 * 242 * Description This function searches an SDP discovery record for a 243 * specific attribute. 244 * 245 * Returns Pointer to matching attribute entry, or NULL 246 * 247 ******************************************************************************/ 248 tSDP_DISC_ATTR* SDP_FindAttributeInRec(tSDP_DISC_REC* p_rec, uint16_t attr_id); 249 250 /******************************************************************************* 251 * 252 * Function SDP_FindServiceInDb 253 * 254 * Description This function queries an SDP database for a specific 255 * service. If the p_start_rec pointer is NULL, it looks from 256 * the beginning of the database, else it continues from the 257 * next record after p_start_rec. 258 * 259 * Returns Pointer to record containing service class, or NULL 260 * 261 ******************************************************************************/ 262 tSDP_DISC_REC* SDP_FindServiceInDb(tSDP_DISCOVERY_DB* p_db, 263 uint16_t service_uuid, 264 tSDP_DISC_REC* p_start_rec); 265 266 /******************************************************************************* 267 * 268 * Function SDP_FindServiceUUIDInDb 269 * 270 * Description This function queries an SDP database for a specific 271 * service. If the p_start_rec pointer is NULL, it looks from 272 * the beginning of the database, else it continues from the 273 * next record after p_start_rec. 274 * 275 * NOTE the only difference between this function and the previous 276 * function "SDP_FindServiceInDb()" is that this function takes 277 * a Uuid input. 278 * 279 * Returns Pointer to record containing service class, or NULL 280 * 281 ******************************************************************************/ 282 tSDP_DISC_REC* SDP_FindServiceUUIDInDb(tSDP_DISCOVERY_DB* p_db, 283 const bluetooth::Uuid& uuid, 284 tSDP_DISC_REC* p_start_rec); 285 286 /******************************************************************************* 287 * 288 * Function SDP_FindServiceUUIDInRec_128bit 289 * 290 * Description Read the 128-bit service UUID within a record, 291 * if there is any. 292 * 293 * Parameters: p_rec - pointer to a SDP record. 294 * p_uuid - output parameter to save the UUID found. 295 * 296 * Returns true if found, otherwise false. 297 * 298 ******************************************************************************/ 299 bool SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC* p_rec, 300 bluetooth::Uuid* p_uuid); 301 302 /******************************************************************************* 303 * 304 * Function SDP_FindServiceInDb_128bit 305 * 306 * Description Query an SDP database for a specific service. 307 * If the p_start_rec pointer is NULL, look from the beginning 308 * of the database, else continue from the next record after 309 * p_start_rec. 310 * 311 * Returns Pointer to record containing service class, or NULL 312 * 313 ******************************************************************************/ 314 tSDP_DISC_REC* SDP_FindServiceInDb_128bit(tSDP_DISCOVERY_DB* p_db, 315 tSDP_DISC_REC* p_start_rec); 316 317 /******************************************************************************* 318 * 319 * Function SDP_FindProtocolListElemInRec 320 * 321 * Description This function looks at a specific discovery record for a 322 * protocol list element. 323 * 324 * Returns true if found, false if not 325 * If found, the passed protocol list element is filled in. 326 * 327 ******************************************************************************/ 328 bool SDP_FindProtocolListElemInRec(tSDP_DISC_REC* p_rec, uint16_t layer_uuid, 329 tSDP_PROTOCOL_ELEM* p_elem); 330 331 /******************************************************************************* 332 * 333 * Function SDP_FindProfileVersionInRec 334 * 335 * Description This function looks at a specific discovery record for the 336 * Profile list descriptor, and pulls out the version number. 337 * The version number consists of an 8-bit major version and 338 * an 8-bit minor version. 339 * 340 * Returns true if found, false if not 341 * If found, the major and minor version numbers that were 342 * passed in are filled in. 343 * 344 ******************************************************************************/ 345 bool SDP_FindProfileVersionInRec(tSDP_DISC_REC* p_rec, uint16_t profile_uuid, 346 uint16_t* p_version); 347 348 /* API into SDP for local service database updates */ 349 350 /******************************************************************************* 351 * 352 * Function SDP_CreateRecord 353 * 354 * Description This function is called to create a record in the database. 355 * This would be through the SDP database maintenance API. The 356 * record is created empty, teh application should then call 357 * "add_attribute" to add the record's attributes. 358 * 359 * Returns Record handle if OK, else 0. 360 * 361 ******************************************************************************/ 362 uint32_t SDP_CreateRecord(void); 363 364 /******************************************************************************* 365 * 366 * Function SDP_DeleteRecord 367 * 368 * Description This function is called to add a record (or all records) 369 * from the database. This would be through the SDP database 370 * maintenance API. 371 * 372 * If a record handle of 0 is passed, all records are deleted. 373 * 374 * Returns true if succeeded, else false 375 * 376 ******************************************************************************/ 377 bool SDP_DeleteRecord(uint32_t handle); 378 379 /******************************************************************************* 380 * 381 * Function SDP_AddAttribute 382 * 383 * Description This function is called to add an attribute to a record. 384 * This would be through the SDP database maintenance API. 385 * If the attribute already exists in the record, it is 386 * replaced with the new value. 387 * 388 * NOTE Attribute values must be passed as a Big Endian stream. 389 * 390 * Returns true if added OK, else false 391 * 392 ******************************************************************************/ 393 bool SDP_AddAttribute(uint32_t handle, uint16_t attr_id, uint8_t attr_type, 394 uint32_t attr_len, uint8_t* p_val); 395 396 /******************************************************************************* 397 * 398 * Function SDP_AddSequence 399 * 400 * Description This function is called to add a sequence to a record. 401 * This would be through the SDP database maintenance API. 402 * If the sequence already exists in the record, it is replaced 403 * with the new sequence. 404 * 405 * NOTE Element values must be passed as a Big Endian stream. 406 * 407 * Returns true if added OK, else false 408 * 409 ******************************************************************************/ 410 bool SDP_AddSequence(uint32_t handle, uint16_t attr_id, uint16_t num_elem, 411 uint8_t type[], uint8_t len[], uint8_t* p_val[]); 412 413 /******************************************************************************* 414 * 415 * Function SDP_AddUuidSequence 416 * 417 * Description This function is called to add a UUID sequence to a record. 418 * This would be through the SDP database maintenance API. 419 * If the sequence already exists in the record, it is replaced 420 * with the new sequence. 421 * 422 * Returns true if added OK, else false 423 * 424 ******************************************************************************/ 425 bool SDP_AddUuidSequence(uint32_t handle, uint16_t attr_id, uint16_t num_uuids, 426 uint16_t* p_uuids); 427 428 /******************************************************************************* 429 * 430 * Function SDP_AddProtocolList 431 * 432 * Description This function is called to add a protocol descriptor list to 433 * a record. This would be through the SDP database 434 * maintenance API. If the protocol list already exists in the 435 * record, it is replaced with the new list. 436 * 437 * Returns true if added OK, else false 438 * 439 ******************************************************************************/ 440 bool SDP_AddProtocolList(uint32_t handle, uint16_t num_elem, 441 tSDP_PROTOCOL_ELEM* p_elem_list); 442 443 /******************************************************************************* 444 * 445 * Function SDP_AddAdditionProtoLists 446 * 447 * Description This function is called to add a protocol descriptor list to 448 * a record. This would be through the SDP database maintenance 449 * API. If the protocol list already exists in the record, it 450 * is replaced with the new list. 451 * 452 * Returns true if added OK, else false 453 * 454 ******************************************************************************/ 455 bool SDP_AddAdditionProtoLists(uint32_t handle, uint16_t num_elem, 456 tSDP_PROTO_LIST_ELEM* p_proto_list); 457 458 /******************************************************************************* 459 * 460 * Function SDP_AddProfileDescriptorList 461 * 462 * Description This function is called to add a profile descriptor list to 463 * a record. This would be through the SDP database maintenance 464 * API. If the version already exists in the record, it is 465 * replaced with the new one. 466 * 467 * Returns true if added OK, else false 468 * 469 ******************************************************************************/ 470 bool SDP_AddProfileDescriptorList(uint32_t handle, uint16_t profile_uuid, 471 uint16_t version); 472 473 /******************************************************************************* 474 * 475 * Function SDP_AddLanguageBaseAttrIDList 476 * 477 * Description This function is called to add a language base attr list to 478 * a record. This would be through the SDP database maintenance 479 * API. If the version already exists in the record, it is 480 * replaced with the new one. 481 * 482 * Returns true if added OK, else false 483 * 484 ******************************************************************************/ 485 bool SDP_AddLanguageBaseAttrIDList(uint32_t handle, uint16_t lang, 486 uint16_t char_enc, uint16_t base_id); 487 488 /******************************************************************************* 489 * 490 * Function SDP_AddServiceClassIdList 491 * 492 * Description This function is called to add a service list to a record. 493 * This would be through the SDP database maintenance API. 494 * If the service list already exists in the record, it is 495 * replaced with the new list. 496 * 497 * Returns true if added OK, else false 498 * 499 ******************************************************************************/ 500 bool SDP_AddServiceClassIdList(uint32_t handle, uint16_t num_services, 501 uint16_t* p_service_uuids); 502 503 /******************************************************************************* 504 * 505 * Function SDP_DeleteAttribute 506 * 507 * Description Delete an attribute from a record. 508 * This would be through the SDP database maintenance API. 509 * 510 * Returns true if deleted OK, else false if not found 511 * 512 ******************************************************************************/ 513 bool SDP_DeleteAttribute(uint32_t handle, uint16_t attr_id); 514 515 /* Device Identification APIs */ 516 517 /******************************************************************************* 518 * 519 * Function SDP_SetLocalDiRecord 520 * 521 * Description This function adds a DI record to the local SDP database. 522 * 523 * Returns Returns SDP_SUCCESS if record added successfully, else error 524 * 525 ******************************************************************************/ 526 uint16_t SDP_SetLocalDiRecord(tSDP_DI_RECORD* device_info, uint32_t* p_handle); 527 528 /******************************************************************************* 529 * 530 * Function SDP_DiDiscover 531 * 532 * Description This function queries a remote device for DI information. 533 * 534 * Returns SDP_SUCCESS if query started successfully, else error 535 * 536 ******************************************************************************/ 537 uint16_t SDP_DiDiscover(const RawAddress& remote_device, 538 tSDP_DISCOVERY_DB* p_db, uint32_t len, 539 tSDP_DISC_CMPL_CB* p_cb); 540 541 /******************************************************************************* 542 * 543 * Function SDP_GetNumDiRecords 544 * 545 * Description Searches specified database for DI records 546 * 547 * Returns number of DI records found 548 * 549 ******************************************************************************/ 550 uint8_t SDP_GetNumDiRecords(tSDP_DISCOVERY_DB* p_db); 551 552 /******************************************************************************* 553 * 554 * Function SDP_GetDiRecord 555 * 556 * Description This function retrieves a remote device's DI record from 557 * the specified database. 558 * 559 * Returns SDP_SUCCESS if record retrieved, else error 560 * 561 ******************************************************************************/ 562 uint16_t SDP_GetDiRecord(uint8_t getRecordIndex, 563 tSDP_DI_GET_RECORD* device_info, 564 tSDP_DISCOVERY_DB* p_db); 565 566 /******************************************************************************* 567 * 568 * Function SDP_SetTraceLevel 569 * 570 * Description This function sets the trace level for SDP. If called with 571 * a value of 0xFF, it simply reads the current trace level. 572 * 573 * Returns the new (current) trace level 574 * 575 ******************************************************************************/ 576 uint8_t SDP_SetTraceLevel(uint8_t new_level); 577 578 /******************************************************************************* 579 * 580 * Function SDP_FindServiceUUIDInRec 581 * 582 * Description Read the service UUID within a record, 583 * if there is any. 584 * 585 * Parameters: p_rec - pointer to a SDP record. 586 * 587 * Returns true if found, otherwise false. 588 * 589 ******************************************************************************/ 590 bool SDP_FindServiceUUIDInRec(tSDP_DISC_REC* p_rec, bluetooth::Uuid* p_uuid); 591 592 #endif /* SDP_API_H */ 593