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 19 #pragma once 20 21 #include <base/functional/callback_forward.h> 22 #include <base/strings/stringprintf.h> 23 24 #include <cstdint> 25 26 #include "stack/include/sdp_callback.h" 27 #include "stack/include/sdp_device_id.h" 28 #include "stack/include/sdp_status.h" 29 #include "stack/include/sdpdefs.h" 30 #include "stack/sdp/internal/sdp_api.h" 31 #include "stack/sdp/sdp_discovery_db.h" 32 #include "types/bluetooth/uuid.h" 33 #include "types/raw_address.h" 34 35 namespace bluetooth { 36 namespace legacy { 37 namespace stack { 38 namespace sdp { 39 40 struct tSdpApi { 41 struct { 42 /******************************************************************************* 43 Function SDP_InitDiscoveryDb 44 45 Description This function is called to initialize a discovery 46 database. 47 48 Parameters: p_db - (input) address of an area of memory where 49 the discovery database is managed. 50 len - (input) size (in bytes) of the memory 51 NOTE: This must be larger than sizeof(tSDP_DISCOVERY_DB) 52 num_uuid - (input) number of UUID filters applied 53 p_uuid_list - (input) list of UUID filters 54 num_attr - (input) number of attribute filters 55 applied 56 p_attr_list - (input) list of attribute filters 57 58 Returns true if successful, false if one or more parameters are 59 bad 60 ******************************************************************************/ 61 [[nodiscard]] bool (*SDP_InitDiscoveryDb)(tSDP_DISCOVERY_DB*, uint32_t, 62 uint16_t, const bluetooth::Uuid*, 63 uint16_t, const uint16_t*); 64 65 /******************************************************************************* 66 67 Function SDP_CancelServiceSearch 68 69 Description This function cancels an active query to an SDP server. 70 71 Parameters: p_db - (input) address of an area of memory where 72 the discovery database is managed. 73 74 Returns true if discovery cancelled, false if a matching 75 activity is not found. 76 77 ******************************************************************************/ 78 [[nodiscard]] bool (*SDP_CancelServiceSearch)(const tSDP_DISCOVERY_DB*); 79 80 /******************************************************************************* 81 82 Function SDP_ServiceSearchRequest 83 84 Description This function queries an SDP server for information. 85 86 Parameters: p_db - (input) address of an area of memory where 87 the discovery database is managed. 88 p_cb - (input) callback executed when complete 89 90 Returns true if discovery started, false if failed. 91 92 ******************************************************************************/ 93 [[nodiscard]] bool (*SDP_ServiceSearchRequest)(const RawAddress&, 94 tSDP_DISCOVERY_DB*, 95 tSDP_DISC_CMPL_CB*); 96 97 /******************************************************************************* 98 99 Function SDP_ServiceSearchAttributeRequest 100 101 Description This function queries an SDP server for information. 102 103 The difference between this API function and the 104 function SDP_ServiceSearchRequest is that this one does 105 a combined ServiceSearchAttributeRequest SDP function. 106 107 Parameters: bd_addr - (input) device address for service search 108 p_db - (input) address of an area of memory where 109 the discovery database is managed. 110 p_cb - (input) callback executed when complete 111 112 Returns true if discovery started, false if failed. 113 114 ******************************************************************************/ 115 [[nodiscard]] bool (*SDP_ServiceSearchAttributeRequest)(const RawAddress&, 116 tSDP_DISCOVERY_DB*, 117 tSDP_DISC_CMPL_CB*); 118 119 /******************************************************************************* 120 121 Function SDP_ServiceSearchAttributeRequest2 122 123 Description This function queries an SDP server for information. 124 125 The difference between this API function and the 126 function SDP_ServiceSearchRequest is that this one does 127 a combined ServiceSearchAttributeRequest SDP function 128 with the user data piggyback 129 130 parameters: bd_addr - (input) device address for service search 131 p_db - (input) address of an area of memory where 132 the discovery database is managed. 133 complete_callback - (input) callback executed when 134 complete 135 136 Returns true if discovery started, false if failed. 137 138 ******************************************************************************/ 139 [[nodiscard]] bool (*SDP_ServiceSearchAttributeRequest2)( 140 const RawAddress&, tSDP_DISCOVERY_DB*, 141 base::RepeatingCallback<tSDP_DISC_CMPL_CB> complete_callback); 142 } service; 143 144 struct { 145 /******************************************************************************* 146 147 Function SDP_FindServiceInDb 148 149 Description This function queries an SDP database for a specific 150 service. If the p_start_rec pointer is NULL, it looks 151 from the beginning of the database, else it continues 152 from the next record after p_start_rec. 153 154 parameters: p_db - (input) address of an area of memory where 155 the discovery database is managed. 156 uuid16 - (input) Uuid to search in db 157 disc_rec - (output) Record found, null otherwise 158 159 Returns Pointer to record containing service class, or NULL 160 161 ******************************************************************************/ 162 [[nodiscard]] tSDP_DISC_REC* (*SDP_FindServiceInDb)( 163 const tSDP_DISCOVERY_DB*, uint16_t, tSDP_DISC_REC*); 164 165 /******************************************************************************* 166 167 Function SDP_FindServiceUUIDInDb 168 169 Description This function queries an SDP database for a specific 170 service. If the p_start_rec pointer is NULL, it looks 171 from the beginning of the database, else it continues 172 from the next record after p_start_rec. 173 174 NOTE the only difference between this function and the 175 previous function "SDP_FindServiceInDb()" is that this 176 function takes a Uuid input. 177 178 parameters: p_db - (input) address of an area of memory where 179 the discovery database is managed. 180 uuid - (input) Uuid to search in db 181 disc_rec - (input) Start record, null from beginning 182 183 Returns Pointer to record containing service class, or NULL 184 185 ******************************************************************************/ 186 [[nodiscard]] tSDP_DISC_REC* (*SDP_FindServiceUUIDInDb)( 187 const tSDP_DISCOVERY_DB*, const bluetooth::Uuid&, tSDP_DISC_REC*); 188 189 /******************************************************************************* 190 191 Function SDP_FindServiceInDb_128bit 192 193 Description Query an SDP database for a specific service. 194 If the p_start_rec pointer is NULL, look from the 195 beginning of the database, else continue from the next 196 record after p_start_rec. 197 198 parameters: p_db - (input) address of an area of memory where 199 the discovery database is managed. 200 disc_rec - (input) Start record, null from beginning 201 202 Returns Pointer to record containing service class, or NULL 203 204 ******************************************************************************/ 205 [[nodiscard]] tSDP_DISC_REC* (*SDP_FindServiceInDb_128bit)( 206 const tSDP_DISCOVERY_DB*, tSDP_DISC_REC*); 207 } db; 208 209 struct { 210 /******************************************************************************* 211 212 Local discovery database API 213 214 Function SDP_FindAttributeInRec 215 216 Description This function searches an SDP discovery record for a 217 specific attribute. 218 219 parameters: disc_rec - (input) Start record must not be null 220 attr_id - (input) Attribute id to search 221 222 Returns Pointer to matching attribute entry, or NULL 223 224 ******************************************************************************/ 225 [[nodiscard]] tSDP_DISC_ATTR* (*SDP_FindAttributeInRec)( 226 const tSDP_DISC_REC*, uint16_t); 227 228 /******************************************************************************* 229 230 Function SDP_FindServiceUUIDInRec_128bit 231 232 Description Read the 128-bit service UUID within a record; 233 if there is any. 234 235 Parameters: p_rec - (input) pointer to a SDP record. 236 p_uuid - (output) parameter to save the UUID found. 237 238 Returns true if found, otherwise false. 239 240 ******************************************************************************/ 241 [[nodiscard]] bool (*SDP_FindServiceUUIDInRec_128bit)(const tSDP_DISC_REC*, 242 bluetooth::Uuid*); 243 244 /******************************************************************************* 245 246 Function SDP_FindProtocolListElemInRec 247 248 Description This function looks at a specific discovery record for a 249 protocol list element. 250 251 Parameters: p_rec - (input) pointer to a SDP record. 252 p_uuid - (input) layer UUID. 253 p_elem - (output) protocol element 254 255 Returns true if found, false if not 256 If found, the passed protocol list element is filled in. 257 258 ******************************************************************************/ 259 [[nodiscard]] bool (*SDP_FindProtocolListElemInRec)(const tSDP_DISC_REC*, 260 uint16_t, 261 tSDP_PROTOCOL_ELEM*); 262 263 /******************************************************************************* 264 265 Function SDP_FindProfileVersionInRec 266 267 Description This function looks at a specific discovery record for 268 the Profile list descriptor, and pulls out the version 269 number. The version number consists of an 8-bit major 270 version and an 8-bit minor version. 271 272 Parameters: p_rec - (input) pointer to a SDP record. 273 p_uuid - (input) profile UUID. 274 p_elem - (output) major and minor version numbers 275 276 Returns true if found, false if not 277 278 ******************************************************************************/ 279 [[nodiscard]] bool (*SDP_FindProfileVersionInRec)(const tSDP_DISC_REC*, 280 uint16_t, uint16_t*); 281 282 /******************************************************************************* 283 284 Function SDP_FindServiceUUIDInRec 285 286 Description Read the service UUID within a record; 287 if there is any. 288 289 Parameters: p_rec - (input) pointer to a SDP record. 290 p_uuid - (output) found UUID or null. 291 292 Returns true if found, otherwise false. 293 294 ******************************************************************************/ 295 [[nodiscard]] bool (*SDP_FindServiceUUIDInRec)(const tSDP_DISC_REC* p_rec, 296 bluetooth::Uuid* p_uuid); 297 } record; 298 299 struct { 300 /******************************************************************************* 301 302 API into SDP for Local service database updates 303 304 Function SDP_CreateRecord 305 306 Description This function is called to create a record in the 307 database. This would be through the SDP database 308 maintenance API. The record is created empty, teh 309 application should then call "add_attribute" *to add 310 the record's attributes. 311 312 Returns Record handle if OK, else 0. 313 314 ******************************************************************************/ 315 [[nodiscard]] uint32_t (*SDP_CreateRecord)(void); 316 317 /******************************************************************************* 318 319 Function SDP_DeleteRecord 320 321 Description This function is called to add a record (or all records) 322 from the database. This would be through the SDP 323 database maintenance API. 324 325 Parameters: handle - (input) Handle to delete, 0 for all records 326 to be deleted 327 328 Returns true if succeeded, else false 329 330 ******************************************************************************/ 331 [[nodiscard]] bool (*SDP_DeleteRecord)(uint32_t); 332 333 /******************************************************************************* 334 335 Function SDP_AddAttribute 336 337 Description This function is called to add an attribute to a record. 338 This would be through the SDP database maintenance API. 339 If the attribute already exists in the record, it is 340 replaced with the new value. 341 342 NOTE Attribute values must be passed as a Big Endian stream. 343 344 Parameters: handle - (input) Handle to add 345 attr_id - (input) Attribute id to add 346 attr_type - (input) Attribute type to add 347 attr_len - (input) Attribute data length 348 p_val - (input) Attribute data value 349 350 Returns true if added OK, else false 351 352 ******************************************************************************/ 353 [[nodiscard]] bool (*SDP_AddAttribute)(uint32_t handle, uint16_t attr_id, 354 uint8_t attr_type, uint32_t attr_len, 355 uint8_t* p_val); 356 357 /******************************************************************************* 358 359 Function SDP_AddSequence 360 361 Description This function is called to add a sequence to a record. 362 This would be through the SDP database maintenance API. 363 If the sequence already exists in the record, it is 364 replaced with the new sequence. 365 366 NOTE Element values must be passed as a Big Endian stream. 367 368 Parameters: handle - (input) Handle to add 369 attr_id - (input) Attribute id to add 370 num_elem - (input) Number of elements in array 371 type[] - (input) Element type 372 len[] - (input) Element data length 373 p_val[] - (input) Element data value 374 375 Returns true if added OK, else false 376 377 ******************************************************************************/ 378 [[nodiscard]] bool (*SDP_AddSequence)(uint32_t handle, uint16_t attr_id, 379 uint16_t num_elem, uint8_t type[], 380 uint8_t len[], uint8_t* p_val[]); 381 382 /******************************************************************************* 383 384 Function SDP_AddUuidSequence 385 386 Description This function is called to add a UUID sequence to a 387 record. This would be through the SDP database 388 maintenance API. If the sequence already exists in the 389 record, it is replaced with the new sequence. 390 391 Parameters: handle - (input) Handle to add 392 attr_id - (input) Attribute id to add 393 num_uuids - (input) Number of uuids in array 394 p_uuids[] - (input) Array uuid 395 396 Returns true if added OK, else false 397 398 ******************************************************************************/ 399 [[nodiscard]] bool (*SDP_AddUuidSequence)(uint32_t handle, uint16_t attr_id, 400 uint16_t num_uuids, 401 uint16_t* p_uuids); 402 403 /******************************************************************************* 404 405 Function SDP_AddProtocolList 406 407 Description This function is called to add a protocol descriptor 408 list to a record. This would be through the SDP database 409 maintenance API. If the protocol list already exists in 410 the record, it is replaced with the new list. 411 412 Parameters: handle - (input) Handle to add 413 num_elem - (input) Number of elements to add 414 elem_list[]- (input) Element data list to add 415 416 Returns true if added OK, else false 417 418 ******************************************************************************/ 419 [[nodiscard]] bool (*SDP_AddProtocolList)(uint32_t handle, 420 uint16_t num_elem, 421 tSDP_PROTOCOL_ELEM* p_elem_list); 422 423 /******************************************************************************* 424 425 Function SDP_AddAdditionProtoLists 426 427 Description This function is called to add a protocol descriptor 428 list to a record. This would be through the SDP database 429 maintenance API. If the protocol list already exists in 430 the record, it is replaced with the new list. 431 432 Parameters: handle - (input) Handle to add 433 num_elem - (input) Number of elements to add 434 proto_list[]- (input) Element data list to add 435 436 Returns true if added OK, else false 437 438 ******************************************************************************/ 439 [[nodiscard]] bool (*SDP_AddAdditionProtoLists)( 440 uint32_t handle, uint16_t num_elem, tSDP_PROTO_LIST_ELEM* p_proto_list); 441 442 /******************************************************************************* 443 444 Function SDP_AddProfileDescriptorList 445 446 Description This function is called to add a profile descriptor list 447 to a record. This would be through the SDP database 448 maintenance API. If the version already exists in the 449 record, it is replaced with the new one. 450 451 Parameters: handle - (input) Handle to add 452 uuid - (input) Uuid to add 453 version - (input) major and minor version 454 455 Returns true if added OK, else false 456 457 ******************************************************************************/ 458 [[nodiscard]] bool (*SDP_AddProfileDescriptorList)(uint32_t handle, 459 uint16_t profile_uuid, 460 uint16_t version); 461 462 /******************************************************************************* 463 464 Function SDP_AddLanguageBaseAttrIDList 465 466 Description This function is called to add a language base attr list 467 to a record. This would be through the SDP database 468 maintenance API. If the version already exists in the 469 record, it is replaced with the new one. 470 471 Parameters: handle - (input) Handle to add 472 lang - (input) language base descriptor 473 char_enc - (input) character encoding 474 base_id - (input) base id 475 476 Returns true if added OK, else false 477 478 ******************************************************************************/ 479 [[nodiscard]] bool (*SDP_AddLanguageBaseAttrIDList)(uint32_t handle, 480 uint16_t lang, 481 uint16_t char_enc, 482 uint16_t base_id); 483 484 /******************************************************************************* 485 486 Function SDP_AddServiceClassIdList 487 488 Description This function is called to add a service list to a 489 record. This would be through the SDP database 490 maintenance API. If the service list already exists in 491 the record, it is replaced with the new list. 492 493 Parameters: handle - (input) Handle to add 494 num_services - (input) number of services to add 495 uuids[] - (input) list of service uuids to add 496 497 Returns true if added OK, else false 498 499 ******************************************************************************/ 500 [[nodiscard]] bool (*SDP_AddServiceClassIdList)(uint32_t handle, 501 uint16_t num_services, 502 uint16_t* p_service_uuids); 503 } handle; 504 505 struct { 506 /******************************************************************************* 507 508 Device Identification API 509 510 Function SDP_SetLocalDiRecord 511 512 Description This function adds a DI record to the local SDP 513 database. 514 515 Parameters: info - (input) device identification record 516 p_handle - (output) handle of record if successful 517 518 Returns Returns SDP_SUCCESS if record added successfully, else 519 error 520 521 ******************************************************************************/ 522 [[nodiscard]] uint16_t (*SDP_SetLocalDiRecord)( 523 const tSDP_DI_RECORD* device_info, uint32_t* p_handle); 524 525 /******************************************************************************* 526 527 Device Identification API 528 529 Function SDP_DiDiscover 530 531 Description This function queries a remote device for DI 532 information. 533 534 Parameters: bd_addr - (input) remote device 535 p_db - (input) dicovery database 536 len - (input ) data base length 537 p_cb - (input) callback when complete 538 539 Returns SDP_SUCCESS if query started successfully, else error 540 541 ******************************************************************************/ 542 [[nodiscard]] tSDP_STATUS (*SDP_DiDiscover)(const RawAddress& remote_device, 543 tSDP_DISCOVERY_DB* p_db, 544 uint32_t len, 545 tSDP_DISC_CMPL_CB* p_cb); 546 547 /******************************************************************************* 548 549 Device Identification API 550 551 Function SDP_GetNumDiRecords 552 553 Description Searches specified database for DI records 554 555 Parameters: p_db - (input) dicovery database 556 557 Returns number of DI records found 558 559 ******************************************************************************/ 560 [[nodiscard]] uint8_t (*SDP_GetNumDiRecords)(const tSDP_DISCOVERY_DB* p_db); 561 562 /******************************************************************************* 563 564 Device Identification API 565 566 Function SDP_GetDiRecord 567 568 Description This function retrieves a remote device's DI record from 569 the specified database. 570 571 Parameters: index - (input) record index to retrieve 572 device_info - (input) dicovery database 573 p_cb - (input) callback when complete 574 575 Returns SDP_SUCCESS if record retrieved, else error 576 577 ******************************************************************************/ 578 [[nodiscard]] uint16_t (*SDP_GetDiRecord)(uint8_t getRecordIndex, 579 tSDP_DI_GET_RECORD* device_info, 580 const tSDP_DISCOVERY_DB* p_db); 581 582 } device_id; 583 }; 584 585 const struct tSdpApi* get_legacy_stack_sdp_api(); 586 587 struct tLegacyStackSdbCallback { 588 void(tSDP_DISC_CMPL_CB)(const RawAddress& bd_addr, tSDP_RESULT result); 589 void(tSDP_DISC_CMPL_CB2)(const RawAddress& bd_addr, tSDP_RESULT result, 590 const void* user_data); 591 }; 592 593 } // namespace sdp 594 } // namespace stack 595 } // namespace legacy 596 } // namespace bluetooth 597