1/* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "sdp.h" 17 18#include <string.h> 19 20#include "sdp_client.h" 21#include "sdp_connect.h" 22#include "sdp_server.h" 23#include "sdp_util.h" 24 25#include "btstack.h" 26#include "event.h" 27#include "module.h" 28 29#include "allocator.h" 30#include "log.h" 31 32#include "../btm/btm_thread.h" 33 34#define WAIT_TIME (-1) 35 36typedef struct { 37 int traceLevel; 38 Event *event; 39} SdpInitializeInfo; 40 41typedef struct { 42 uint32_t handle; 43 Event *event; 44} SdpServiceRecordHandle; 45 46typedef struct { 47 uint32_t handle; 48 Event *event; 49 int result; 50} SdpServiceRecord; 51 52typedef struct { 53 uint32_t handle; 54 const BtUuid *classid; 55 uint16_t classidNumber; 56 Event *event; 57 int result; 58} SdpServiceClassID; 59 60typedef struct { 61 uint32_t handle; 62 uint32_t state; 63 Event *event; 64 int result; 65} SdpServiceRecordState; 66 67typedef struct { 68 uint32_t handle; 69 BtUuid serviceid; 70 Event *event; 71 int result; 72} SdpServiceId; 73 74typedef struct { 75 uint32_t handle; 76 const SdpProtocolDescriptor *descriptor; 77 uint16_t descriptorNumber; 78 Event *event; 79 int result; 80} SdpProtocolDescriptorList; 81 82typedef struct { 83 uint32_t handle; 84 const SdpAdditionalProtocolDescriptor *descriptorList; 85 uint16_t descriptorListNumber; 86 Event *event; 87 int result; 88} SdpAdditionalProtocolDescriptorList; 89 90typedef struct { 91 uint32_t handle; 92 const BtUuid *browseUuid; 93 uint16_t browseUuidNumber; 94 Event *event; 95 int result; 96} SdpBrowseGroupList; 97 98typedef struct { 99 uint32_t handle; 100 const SdpLanguageBaseAttributeId *baseAttributeId; 101 uint16_t baseAttributeIdNumber; 102 Event *event; 103 int result; 104} SdpLanguageBaseAttributeIdList; 105 106typedef struct { 107 uint32_t handle; 108 uint32_t value; 109 Event *event; 110 int result; 111} SdpServiceInfoTimeToLive; 112 113typedef struct { 114 uint32_t handle; 115 uint8_t value; 116 Event *event; 117 int result; 118} SdpServiceAvailability; 119 120typedef struct { 121 uint32_t handle; 122 const SdpProfileDescriptor *profileDescriptor; 123 uint16_t profileDescriptorNumber; 124 Event *event; 125 int result; 126} SdpBluetoothProfileDescriptorList; 127 128typedef struct { 129 uint32_t handle; 130 const uint8_t *url; 131 uint16_t urlLen; 132 Event *event; 133 int result; 134} SdpUrl; 135 136typedef struct { 137 uint32_t handle; 138 uint16_t baseAttributeId; 139 const char *name; 140 uint16_t nameLen; 141 Event *event; 142 int result; 143} SdpName; 144 145typedef struct { 146 uint32_t handle; 147 uint16_t attributeId; 148 SdpDataType type; 149 void *attributeValue; 150 uint16_t attributeValueLength; 151 Event *event; 152 int result; 153} SdpAttributeInfo; 154 155typedef struct { 156 uint32_t handle; 157 uint16_t attributeId; 158 const uint8_t *attributeValue; 159 uint16_t attributeValueLength; 160 Event *event; 161 int result; 162} SdpSequenceAttributeInfo; 163 164typedef struct { 165 BtAddr addr; 166 SdpUuid uuidArray; 167 void *context; 168 void (*ServiceSearchCb)(const BtAddr *addr, const uint32_t *handleArray, uint16_t handleNum, void *context); 169 Event *event; 170 int result; 171} SdpServiceSearchInfo; 172 173typedef struct { 174 BtAddr addr; 175 uint32_t handle; 176 SdpAttributeIdList attributeIdList; 177 void *context; 178 void (*ServiceAttributeCb)(const BtAddr *addr, const SdpService *service, void *context); 179 Event *event; 180 int result; 181} SdpServiceAttributeInfo; 182 183typedef struct { 184 BtAddr addr; 185 SdpUuid uuidArray; 186 SdpAttributeIdList attributeIdList; 187 void *context; 188 void (*ServiceSearchAttributeCb)( 189 const BtAddr *addr, const SdpService *serviceArray, uint16_t serviceNum, void *context); 190 Event *event; 191 int result; 192} SdpServiceSearchAttributeInfo; 193 194typedef struct { 195 BtAddr addr; 196 void *context; 197 void (*ServiceBrowseCb)(const BtAddr *addr, const uint32_t *handleArray, uint16_t handleNum, void *context); 198 Event *event; 199 int result; 200} SdpServiceBrowseInfo; 201 202static void SdpInitializeTask(void *context) 203{ 204 LOG_INFO("%{public}s", __func__); 205 206 SdpInitializeInfo *ctx = context; 207 208 if (ctx == NULL) { 209 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 210 return; 211 } 212 213 SdpInitializeClient(); 214 SdpInitializeServer(); 215 SdpRegisterToL2cap(); 216 SdpSetEnableState(); 217 218 if (ctx->event != NULL) { 219 EventSet(ctx->event); 220 } 221} 222 223static void SdpStartup(int traceLevel) 224{ 225 LOG_INFO("%{public}s enter", __FUNCTION__); 226 227 int ret; 228 SdpInitializeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpInitializeInfo)); 229 if (ctx == NULL) { 230 LOG_ERROR("point to NULL"); 231 return; 232 } 233 (void)memset_s(ctx, sizeof(SdpInitializeInfo), 0x00, sizeof(SdpInitializeInfo)); 234 235 ret = BTM_CreateProcessingQueue(PROCESSING_QUEUE_ID_SDP, BTM_PROCESSING_QUEUE_SIZE_DEFAULT); 236 if (ret != BT_SUCCESS) { 237 MEM_MALLOC.free(ctx); 238 return; 239 } 240 241 ctx->traceLevel = traceLevel; 242 ctx->event = EventCreate(true); 243 244 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpInitializeTask, ctx); 245 if (ret != BT_SUCCESS) { 246 EventDelete(ctx->event); 247 MEM_MALLOC.free(ctx); 248 return; 249 } 250 251 EventWait(ctx->event, WAIT_TIME); 252 EventDelete(ctx->event); 253 MEM_MALLOC.free(ctx); 254} 255 256static void SdpFinalizeTask(void *context) 257{ 258 Event *ctx = context; 259 LOG_INFO("%{public}s enter", __FUNCTION__); 260 if (ctx == NULL) { 261 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 262 return; 263 } 264 SdpSetDisableState(); 265 SdpDeregisterToL2cap(); 266 SdpFinalizeServer(); 267 SdpFinalizeClient(); 268 269 BTM_DeleteProcessingQueue(PROCESSING_QUEUE_ID_SDP); 270 EventSet(ctx); 271} 272 273static void SdpShutdown() 274{ 275 LOG_INFO("%{public}s enter", __FUNCTION__); 276 277 int ret; 278 Event *ctx = EventCreate(true); 279 280 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpFinalizeTask, ctx); 281 if (ret != BT_SUCCESS) { 282 EventDelete(ctx); 283 return; 284 } 285 286 EventWait(ctx, WAIT_TIME); 287 EventDelete(ctx); 288 289 LOG_INFO("%{public}s end", __FUNCTION__); 290} 291 292static void SdpCreateServiceRecordTask(void *context) 293{ 294 SdpServiceRecordHandle *ctx = context; 295 296 if (ctx == NULL) { 297 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 298 return; 299 } 300 ctx->handle = SdpCreateServiceRecord(); 301 if (ctx->event != NULL) { 302 EventSet(ctx->event); 303 } 304} 305 306uint32_t SDP_CreateServiceRecord() 307{ 308 LOG_INFO("%{public}s enter", __FUNCTION__); 309 310 int ret; 311 int handle = 0; 312 SdpServiceRecordHandle *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecordHandle)); 313 if (ctx == NULL) { 314 LOG_ERROR("point to NULL"); 315 return 0; 316 } 317 (void)memset_s(ctx, sizeof(SdpServiceRecordHandle), 0x00, sizeof(SdpServiceRecordHandle)); 318 319 ctx->event = EventCreate(true); 320 321 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpCreateServiceRecordTask, ctx); 322 if (ret != BT_SUCCESS) { 323 EventDelete(ctx->event); 324 MEM_MALLOC.free(ctx); 325 return handle; 326 } 327 328 EventWait(ctx->event, WAIT_TIME); 329 EventDelete(ctx->event); 330 handle = ctx->handle; 331 332 MEM_MALLOC.free(ctx); 333 return handle; 334} 335 336static void SdpDestroyServiceRecordTask(void *context) 337{ 338 SdpServiceRecord *ctx = context; 339 340 if (ctx == NULL) { 341 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 342 return; 343 } 344 ctx->result = SdpDestroyServiceRecord(ctx->handle); 345 if (ctx->event != NULL) { 346 EventSet(ctx->event); 347 } 348} 349 350int SDP_DestroyServiceRecord(uint32_t handle) 351{ 352 LOG_INFO("%{public}s enter", __FUNCTION__); 353 354 int ret; 355 SdpServiceRecord *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecord)); 356 if (ctx == NULL) { 357 LOG_ERROR("point to NULL"); 358 return BT_NO_MEMORY; 359 } 360 (void)memset_s(ctx, sizeof(SdpServiceRecord), 0x00, sizeof(SdpServiceRecord)); 361 362 ctx->handle = handle; 363 ctx->event = EventCreate(true); 364 365 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpDestroyServiceRecordTask, ctx); 366 if (ret == BT_SUCCESS) { 367 EventWait(ctx->event, WAIT_TIME); 368 ret = ctx->result; 369 } 370 371 EventDelete(ctx->event); 372 MEM_MALLOC.free(ctx); 373 374 LOG_INFO("%{public}s exit", __FUNCTION__); 375 return ret; 376} 377 378static void SdpRegisterServiceRecordTask(void *context) 379{ 380 SdpServiceRecord *ctx = context; 381 382 if (ctx == NULL) { 383 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 384 return; 385 } 386 ctx->result = SdpRegisterServiceRecord(ctx->handle); 387 if (ctx->event != NULL) { 388 EventSet(ctx->event); 389 } 390} 391 392int SDP_RegisterServiceRecord(uint32_t handle) 393{ 394 LOG_INFO("%{public}s enter", __FUNCTION__); 395 396 int ret; 397 SdpServiceRecord *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecord)); 398 if (ctx == NULL) { 399 LOG_ERROR("point to NULL"); 400 return BT_NO_MEMORY; 401 } 402 (void)memset_s(ctx, sizeof(SdpServiceRecord), 0x00, sizeof(SdpServiceRecord)); 403 404 ctx->handle = handle; 405 ctx->event = EventCreate(true); 406 407 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpRegisterServiceRecordTask, ctx); 408 if (ret == BT_SUCCESS) { 409 EventWait(ctx->event, WAIT_TIME); 410 ret = ctx->result; 411 } 412 413 EventDelete(ctx->event); 414 MEM_MALLOC.free(ctx); 415 return ret; 416} 417 418static void SdpDeregisterServiceRecordTask(void *context) 419{ 420 SdpServiceRecord *ctx = context; 421 422 if (ctx == NULL) { 423 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 424 return; 425 } 426 ctx->result = SdpDeregisterServiceRecord(ctx->handle); 427 if (ctx->event != NULL) { 428 EventSet(ctx->event); 429 } 430} 431 432int SDP_DeregisterServiceRecord(uint32_t handle) 433{ 434 LOG_INFO("%{public}s enter", __FUNCTION__); 435 436 int ret; 437 SdpServiceRecord *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecord)); 438 if (ctx == NULL) { 439 LOG_ERROR("point to NULL"); 440 return BT_NO_MEMORY; 441 } 442 (void)memset_s(ctx, sizeof(SdpServiceRecord), 0x00, sizeof(SdpServiceRecord)); 443 444 ctx->handle = handle; 445 ctx->event = EventCreate(true); 446 447 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpDeregisterServiceRecordTask, ctx); 448 if (ret == BT_SUCCESS) { 449 EventWait(ctx->event, WAIT_TIME); 450 ret = ctx->result; 451 } 452 453 EventDelete(ctx->event); 454 MEM_MALLOC.free(ctx); 455 456 LOG_INFO("%{public}s exit", __FUNCTION__); 457 return ret; 458} 459 460static void SdpAddServiceClassIdListTask(void *context) 461{ 462 SdpServiceClassID *ctx = context; 463 464 if (ctx == NULL) { 465 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 466 return; 467 } 468 ctx->result = SdpAddServiceClassIdList(ctx->handle, ctx->classid, ctx->classidNumber); 469 if (ctx->event != NULL) { 470 EventSet(ctx->event); 471 } 472} 473 474int SDP_AddServiceClassIdList(uint32_t handle, const BtUuid *classid, uint16_t classidNumber) 475{ 476 LOG_INFO("%{public}s enter", __FUNCTION__); 477 478 int ret; 479 SdpServiceClassID *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceClassID)); 480 if (ctx == NULL) { 481 LOG_ERROR("point to NULL"); 482 return BT_NO_MEMORY; 483 } 484 (void)memset_s(ctx, sizeof(SdpServiceClassID), 0x00, sizeof(SdpServiceClassID)); 485 486 ctx->handle = handle; 487 ctx->classid = classid; 488 ctx->classidNumber = classidNumber; 489 ctx->event = EventCreate(true); 490 491 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceClassIdListTask, ctx); 492 if (ret == BT_SUCCESS) { 493 EventWait(ctx->event, WAIT_TIME); 494 ret = ctx->result; 495 } 496 497 EventDelete(ctx->event); 498 MEM_MALLOC.free(ctx); 499 return ret; 500} 501 502static void SdpAddServiceRecordStateTask(void *context) 503{ 504 SdpServiceRecordState *ctx = context; 505 506 if (ctx == NULL) { 507 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 508 return; 509 } 510 ctx->result = SdpAddServiceRecordState(ctx->handle, ctx->state); 511 if (ctx->event != NULL) { 512 EventSet(ctx->event); 513 } 514} 515 516int SDP_AddServiceRecordState(uint32_t handle, uint32_t state) 517{ 518 LOG_INFO("%{public}s enter", __FUNCTION__); 519 520 int ret; 521 SdpServiceRecordState *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecordState)); 522 if (ctx == NULL) { 523 LOG_ERROR("point to NULL"); 524 return BT_NO_MEMORY; 525 } 526 (void)memset_s(ctx, sizeof(SdpServiceRecordState), 0x00, sizeof(SdpServiceRecordState)); 527 528 ctx->handle = handle; 529 ctx->state = state; 530 ctx->event = EventCreate(true); 531 532 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceRecordStateTask, ctx); 533 if (ret == BT_SUCCESS) { 534 EventWait(ctx->event, WAIT_TIME); 535 ret = ctx->result; 536 } 537 538 EventDelete(ctx->event); 539 MEM_MALLOC.free(ctx); 540 return ret; 541} 542 543static void SdpAddServiceIdTask(void *context) 544{ 545 SdpServiceId *ctx = context; 546 547 if (ctx == NULL) { 548 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 549 return; 550 } 551 ctx->result = SdpAddServiceId(ctx->handle, &ctx->serviceid); 552 if (ctx->event != NULL) { 553 EventSet(ctx->event); 554 } 555} 556 557int SDP_AddServiceId(uint32_t handle, const BtUuid *serviceid) 558{ 559 LOG_INFO("%{public}s enter", __FUNCTION__); 560 561 int ret; 562 SdpServiceId *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceId)); 563 if (ctx == NULL) { 564 LOG_ERROR("point to NULL"); 565 return BT_NO_MEMORY; 566 } 567 (void)memset_s(ctx, sizeof(SdpServiceId), 0x00, sizeof(SdpServiceId)); 568 569 ctx->handle = handle; 570 (void)memcpy_s(&ctx->serviceid, sizeof(BtUuid), serviceid, sizeof(BtUuid)); 571 ctx->event = EventCreate(true); 572 573 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceIdTask, ctx); 574 if (ret == BT_SUCCESS) { 575 EventWait(ctx->event, WAIT_TIME); 576 ret = ctx->result; 577 } 578 579 EventDelete(ctx->event); 580 MEM_MALLOC.free(ctx); 581 return ret; 582} 583 584static void SdpAddProtocolDescriptorListTask(void *context) 585{ 586 SdpProtocolDescriptorList *ctx = context; 587 588 if (ctx == NULL) { 589 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 590 return; 591 } 592 ctx->result = SdpAddProtocolDescriptorList(ctx->handle, ctx->descriptor, ctx->descriptorNumber); 593 if (ctx->event != NULL) { 594 EventSet(ctx->event); 595 } 596} 597 598int SDP_AddProtocolDescriptorList(uint32_t handle, const SdpProtocolDescriptor *descriptor, uint16_t descriptorNumber) 599{ 600 LOG_INFO("%{public}s enter", __FUNCTION__); 601 602 int ret; 603 SdpProtocolDescriptorList *ctx = MEM_MALLOC.alloc(sizeof(SdpProtocolDescriptorList)); 604 if (ctx == NULL) { 605 LOG_ERROR("point to NULL"); 606 return BT_NO_MEMORY; 607 } 608 (void)memset_s(ctx, sizeof(SdpProtocolDescriptorList), 0x00, sizeof(SdpProtocolDescriptorList)); 609 610 ctx->handle = handle; 611 ctx->descriptor = descriptor; 612 ctx->descriptorNumber = descriptorNumber; 613 ctx->event = EventCreate(true); 614 615 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddProtocolDescriptorListTask, ctx); 616 if (ret == BT_SUCCESS) { 617 EventWait(ctx->event, WAIT_TIME); 618 ret = ctx->result; 619 } 620 621 EventDelete(ctx->event); 622 MEM_MALLOC.free(ctx); 623 return ret; 624} 625 626static void SdpAddAdditionalProtocolDescriptorListTask(void *context) 627{ 628 SdpAdditionalProtocolDescriptorList *ctx = context; 629 630 if (ctx == NULL) { 631 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 632 return; 633 } 634 ctx->result = SdpAddAdditionalProtocolDescriptorList(ctx->handle, ctx->descriptorList, ctx->descriptorListNumber); 635 if (ctx->event != NULL) { 636 EventSet(ctx->event); 637 } 638} 639 640int SDP_AddAdditionalProtocolDescriptorList( 641 uint32_t handle, const SdpAdditionalProtocolDescriptor *descriptorList, uint16_t descriptorListNumber) 642{ 643 LOG_INFO("%{public}s enter", __FUNCTION__); 644 645 int ret; 646 SdpAdditionalProtocolDescriptorList *ctx = MEM_MALLOC.alloc(sizeof(SdpAdditionalProtocolDescriptorList)); 647 if (ctx == NULL) { 648 LOG_ERROR("point to NULL"); 649 return BT_NO_MEMORY; 650 } 651 (void)memset_s(ctx, sizeof(SdpAdditionalProtocolDescriptorList), 0x00, sizeof(SdpAdditionalProtocolDescriptorList)); 652 653 ctx->handle = handle; 654 ctx->descriptorList = descriptorList; 655 ctx->descriptorListNumber = descriptorListNumber; 656 ctx->event = EventCreate(true); 657 658 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddAdditionalProtocolDescriptorListTask, ctx); 659 if (ret == BT_SUCCESS) { 660 EventWait(ctx->event, WAIT_TIME); 661 ret = ctx->result; 662 } 663 664 EventDelete(ctx->event); 665 MEM_MALLOC.free(ctx); 666 return ret; 667} 668 669static void SdpAddBrowseGroupListTask(void *context) 670{ 671 SdpBrowseGroupList *ctx = context; 672 673 if (ctx == NULL) { 674 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 675 return; 676 } 677 ctx->result = SdpAddBrowseGroupList(ctx->handle, ctx->browseUuid, ctx->browseUuidNumber); 678 if (ctx->event != NULL) { 679 EventSet(ctx->event); 680 } 681} 682 683int SDP_AddBrowseGroupList(uint32_t handle, const BtUuid *browseUuid, uint16_t browseUuidNumber) 684{ 685 LOG_INFO("%{public}s enter", __FUNCTION__); 686 687 int ret; 688 SdpBrowseGroupList *ctx = MEM_MALLOC.alloc(sizeof(SdpBrowseGroupList)); 689 if (ctx == NULL) { 690 LOG_ERROR("point to NULL"); 691 return BT_NO_MEMORY; 692 } 693 (void)memset_s(ctx, sizeof(SdpBrowseGroupList), 0x00, sizeof(SdpBrowseGroupList)); 694 695 ctx->handle = handle; 696 ctx->browseUuid = browseUuid; 697 ctx->browseUuidNumber = browseUuidNumber; 698 ctx->event = EventCreate(true); 699 700 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddBrowseGroupListTask, ctx); 701 if (ret == BT_SUCCESS) { 702 EventWait(ctx->event, WAIT_TIME); 703 ret = ctx->result; 704 } 705 706 EventDelete(ctx->event); 707 MEM_MALLOC.free(ctx); 708 return ret; 709} 710 711static void SdpAddLanguageBaseAttributeIdListTask(void *context) 712{ 713 SdpLanguageBaseAttributeIdList *ctx = context; 714 715 if (ctx == NULL) { 716 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 717 return; 718 } 719 ctx->result = SdpAddLanguageBaseAttributeIdList(ctx->handle, ctx->baseAttributeId, ctx->baseAttributeIdNumber); 720 if (ctx->event != NULL) { 721 EventSet(ctx->event); 722 } 723} 724 725int SDP_AddLanguageBaseAttributeIdList( 726 uint32_t handle, const SdpLanguageBaseAttributeId *baseAttributeId, uint16_t baseAttributeIdNum) 727{ 728 LOG_INFO("%{public}s enter", __FUNCTION__); 729 730 int ret; 731 SdpLanguageBaseAttributeIdList *ctx = MEM_MALLOC.alloc(sizeof(SdpLanguageBaseAttributeIdList)); 732 if (ctx == NULL) { 733 LOG_ERROR("point to NULL"); 734 return BT_NO_MEMORY; 735 } 736 (void)memset_s(ctx, sizeof(SdpLanguageBaseAttributeIdList), 0x00, sizeof(SdpLanguageBaseAttributeIdList)); 737 738 ctx->handle = handle; 739 ctx->baseAttributeId = baseAttributeId; 740 ctx->baseAttributeIdNumber = baseAttributeIdNum; 741 ctx->event = EventCreate(true); 742 743 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddLanguageBaseAttributeIdListTask, ctx); 744 if (ret == BT_SUCCESS) { 745 EventWait(ctx->event, WAIT_TIME); 746 ret = ctx->result; 747 } 748 749 EventDelete(ctx->event); 750 MEM_MALLOC.free(ctx); 751 return ret; 752} 753 754static void SdpAddServiceInfoTimeToLiveTask(void *context) 755{ 756 SdpServiceInfoTimeToLive *ctx = context; 757 758 if (ctx == NULL) { 759 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 760 return; 761 } 762 ctx->result = SdpAddServiceInfoTimeToLive(ctx->handle, ctx->value); 763 if (ctx->event != NULL) { 764 EventSet(ctx->event); 765 } 766} 767 768int SDP_AddServiceInfoTimeToLive(uint32_t handle, uint32_t value) 769{ 770 LOG_INFO("%{public}s enter", __FUNCTION__); 771 772 int ret; 773 SdpServiceInfoTimeToLive *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceInfoTimeToLive)); 774 if (ctx == NULL) { 775 LOG_ERROR("point to NULL"); 776 return BT_NO_MEMORY; 777 } 778 (void)memset_s(ctx, sizeof(SdpServiceInfoTimeToLive), 0x00, sizeof(SdpServiceInfoTimeToLive)); 779 780 ctx->handle = handle; 781 ctx->value = value; 782 ctx->event = EventCreate(true); 783 784 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceInfoTimeToLiveTask, ctx); 785 if (ret == BT_SUCCESS) { 786 EventWait(ctx->event, WAIT_TIME); 787 ret = ctx->result; 788 } 789 790 EventDelete(ctx->event); 791 MEM_MALLOC.free(ctx); 792 return ret; 793} 794 795static void SdpAddServiceAvailabilityTask(void *context) 796{ 797 SdpServiceAvailability *ctx = context; 798 799 if (ctx == NULL) { 800 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 801 return; 802 } 803 ctx->result = SdpAddServiceAvailability(ctx->handle, ctx->value); 804 if (ctx->event != NULL) { 805 EventSet(ctx->event); 806 } 807} 808 809int SDP_AddServiceAvailability(uint32_t handle, uint8_t value) 810{ 811 LOG_INFO("%{public}s enter", __FUNCTION__); 812 813 int ret; 814 SdpServiceAvailability *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceAvailability)); 815 if (ctx == NULL) { 816 LOG_ERROR("point to NULL"); 817 return BT_NO_MEMORY; 818 } 819 (void)memset_s(ctx, sizeof(SdpServiceAvailability), 0x00, sizeof(SdpServiceAvailability)); 820 821 ctx->handle = handle; 822 ctx->value = value; 823 ctx->event = EventCreate(true); 824 825 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceAvailabilityTask, ctx); 826 if (ret == BT_SUCCESS) { 827 EventWait(ctx->event, WAIT_TIME); 828 ret = ctx->result; 829 } 830 831 EventDelete(ctx->event); 832 MEM_MALLOC.free(ctx); 833 return ret; 834} 835 836static void SdpAddBluetoothProfileDescriptorListTask(void *context) 837{ 838 SdpBluetoothProfileDescriptorList *ctx = context; 839 840 if (ctx == NULL) { 841 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 842 return; 843 } 844 ctx->result = 845 SdpAddBluetoothProfileDescriptorList(ctx->handle, ctx->profileDescriptor, ctx->profileDescriptorNumber); 846 if (ctx->event != NULL) { 847 EventSet(ctx->event); 848 } 849} 850 851int SDP_AddBluetoothProfileDescriptorList( 852 uint32_t handle, const SdpProfileDescriptor *profileDescriptor, uint16_t profileDescriptorNum) 853{ 854 LOG_INFO("%{public}s enter", __FUNCTION__); 855 856 int ret; 857 SdpBluetoothProfileDescriptorList *ctx = MEM_MALLOC.alloc(sizeof(SdpBluetoothProfileDescriptorList)); 858 if (ctx == NULL) { 859 LOG_ERROR("point to NULL"); 860 return BT_NO_MEMORY; 861 } 862 (void)memset_s(ctx, sizeof(SdpBluetoothProfileDescriptorList), 0x00, sizeof(SdpBluetoothProfileDescriptorList)); 863 864 ctx->handle = handle; 865 ctx->profileDescriptor = profileDescriptor; 866 ctx->profileDescriptorNumber = profileDescriptorNum; 867 ctx->event = EventCreate(true); 868 869 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddBluetoothProfileDescriptorListTask, ctx); 870 if (ret == BT_SUCCESS) { 871 EventWait(ctx->event, WAIT_TIME); 872 ret = ctx->result; 873 } 874 875 EventDelete(ctx->event); 876 MEM_MALLOC.free(ctx); 877 return ret; 878} 879 880static void SdpAddDocumentationUrlTask(void *context) 881{ 882 SdpUrl *ctx = context; 883 884 if (ctx == NULL) { 885 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 886 return; 887 } 888 ctx->result = SdpAddDocumentationUrl(ctx->handle, ctx->url, ctx->urlLen); 889 if (ctx->event != NULL) { 890 EventSet(ctx->event); 891 } 892} 893 894int SDP_AddDocumentationUrl(uint32_t handle, const uint8_t *url, uint16_t urlLen) 895{ 896 LOG_INFO("%{public}s enter", __FUNCTION__); 897 898 int ret; 899 SdpUrl *ctx = MEM_MALLOC.alloc(sizeof(SdpUrl)); 900 if (ctx == NULL) { 901 LOG_ERROR("point to NULL"); 902 return BT_NO_MEMORY; 903 } 904 (void)memset_s(ctx, sizeof(SdpUrl), 0x00, sizeof(SdpUrl)); 905 906 ctx->handle = handle; 907 ctx->url = url; 908 ctx->urlLen = urlLen; 909 ctx->event = EventCreate(true); 910 911 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddDocumentationUrlTask, ctx); 912 if (ret == BT_SUCCESS) { 913 EventWait(ctx->event, WAIT_TIME); 914 ret = ctx->result; 915 } 916 917 EventDelete(ctx->event); 918 MEM_MALLOC.free(ctx); 919 return ret; 920} 921 922static void SdpAddClientExecutableUrlTask(void *context) 923{ 924 SdpUrl *ctx = context; 925 926 if (ctx == NULL) { 927 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 928 return; 929 } 930 ctx->result = SdpAddClientExecutableUrl(ctx->handle, ctx->url, ctx->urlLen); 931 if (ctx->event != NULL) { 932 EventSet(ctx->event); 933 } 934} 935 936int SDP_AddClientExecutableUrl(uint32_t handle, const uint8_t *url, uint16_t urlLen) 937{ 938 LOG_INFO("%{public}s enter", __FUNCTION__); 939 940 int ret; 941 SdpUrl *ctx = MEM_MALLOC.alloc(sizeof(SdpUrl)); 942 if (ctx == NULL) { 943 LOG_ERROR("point to NULL"); 944 return BT_NO_MEMORY; 945 } 946 (void)memset_s(ctx, sizeof(SdpUrl), 0x00, sizeof(SdpUrl)); 947 948 ctx->handle = handle; 949 ctx->url = url; 950 ctx->urlLen = urlLen; 951 ctx->event = EventCreate(true); 952 953 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddClientExecutableUrlTask, ctx); 954 if (ret == BT_SUCCESS) { 955 EventWait(ctx->event, WAIT_TIME); 956 ret = ctx->result; 957 } 958 959 EventDelete(ctx->event); 960 MEM_MALLOC.free(ctx); 961 return ret; 962} 963 964static void SdpAddIconUrlTask(void *context) 965{ 966 SdpUrl *ctx = context; 967 968 if (ctx == NULL) { 969 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 970 return; 971 } 972 ctx->result = SdpAddIconUrl(ctx->handle, ctx->url, ctx->urlLen); 973 if (ctx->event != NULL) { 974 EventSet(ctx->event); 975 } 976} 977 978int SDP_AddIconUrl(uint32_t handle, const uint8_t *url, uint16_t urlLen) 979{ 980 LOG_INFO("%{public}s enter", __FUNCTION__); 981 982 int ret; 983 SdpUrl *ctx = MEM_MALLOC.alloc(sizeof(SdpUrl)); 984 if (ctx == NULL) { 985 LOG_ERROR("point to NULL"); 986 return BT_NO_MEMORY; 987 } 988 (void)memset_s(ctx, sizeof(SdpUrl), 0x00, sizeof(SdpUrl)); 989 990 ctx->handle = handle; 991 ctx->url = url; 992 ctx->urlLen = urlLen; 993 ctx->event = EventCreate(true); 994 995 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddIconUrlTask, ctx); 996 if (ret == BT_SUCCESS) { 997 EventWait(ctx->event, WAIT_TIME); 998 ret = ctx->result; 999 } 1000 1001 EventDelete(ctx->event); 1002 MEM_MALLOC.free(ctx); 1003 return ret; 1004} 1005 1006static void SdpAddServiceNameTask(void *context) 1007{ 1008 SdpName *ctx = context; 1009 1010 if (ctx == NULL) { 1011 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 1012 return; 1013 } 1014 ctx->result = SdpAddServiceName(ctx->handle, ctx->baseAttributeId, ctx->name, ctx->nameLen); 1015 if (ctx->event != NULL) { 1016 EventSet(ctx->event); 1017 } 1018} 1019 1020int SDP_AddServiceName(uint32_t handle, uint16_t baseAttributeId, const char *name, uint16_t nameLen) 1021{ 1022 LOG_INFO("%{public}s enter", __FUNCTION__); 1023 1024 int ret; 1025 SdpName *ctx = MEM_MALLOC.alloc(sizeof(SdpName)); 1026 if (ctx == NULL) { 1027 LOG_ERROR("point to NULL"); 1028 return BT_NO_MEMORY; 1029 } 1030 (void)memset_s(ctx, sizeof(SdpName), 0x00, sizeof(SdpName)); 1031 1032 ctx->handle = handle; 1033 ctx->baseAttributeId = baseAttributeId; 1034 ctx->name = name; 1035 ctx->nameLen = nameLen; 1036 ctx->event = EventCreate(true); 1037 1038 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceNameTask, ctx); 1039 if (ret == BT_SUCCESS) { 1040 EventWait(ctx->event, WAIT_TIME); 1041 ret = ctx->result; 1042 } 1043 1044 EventDelete(ctx->event); 1045 MEM_MALLOC.free(ctx); 1046 return ret; 1047} 1048 1049static void SdpAddServiceDescriptionTask(void *context) 1050{ 1051 SdpName *ctx = context; 1052 1053 if (ctx == NULL) { 1054 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 1055 return; 1056 } 1057 ctx->result = SdpAddServiceDescription(ctx->handle, ctx->baseAttributeId, ctx->name, ctx->nameLen); 1058 if (ctx->event != NULL) { 1059 EventSet(ctx->event); 1060 } 1061} 1062 1063int SDP_AddServiceDescription( 1064 uint32_t handle, uint16_t baseAttributeId, const char *description, uint16_t descriptionLen) 1065{ 1066 LOG_INFO("%{public}s enter", __FUNCTION__); 1067 1068 int ret; 1069 SdpName *ctx = MEM_MALLOC.alloc(sizeof(SdpName)); 1070 if (ctx == NULL) { 1071 LOG_ERROR("point to NULL"); 1072 return BT_NO_MEMORY; 1073 } 1074 (void)memset_s(ctx, sizeof(SdpName), 0x00, sizeof(SdpName)); 1075 1076 ctx->handle = handle; 1077 ctx->name = description; 1078 ctx->nameLen = descriptionLen; 1079 ctx->baseAttributeId = baseAttributeId; 1080 ctx->event = EventCreate(true); 1081 1082 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceDescriptionTask, ctx); 1083 if (ret == BT_SUCCESS) { 1084 EventWait(ctx->event, WAIT_TIME); 1085 ret = ctx->result; 1086 } 1087 1088 EventDelete(ctx->event); 1089 MEM_MALLOC.free(ctx); 1090 return ret; 1091} 1092 1093static void SdpAddProviderNameTask(void *context) 1094{ 1095 SdpName *ctx = context; 1096 1097 if (ctx == NULL) { 1098 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 1099 return; 1100 } 1101 ctx->result = SdpAddProviderName(ctx->handle, ctx->baseAttributeId, ctx->name, ctx->nameLen); 1102 if (ctx->event != NULL) { 1103 EventSet(ctx->event); 1104 } 1105} 1106 1107int SDP_AddProviderName(uint32_t handle, uint16_t baseAttributeId, const char *name, uint16_t nameLen) 1108{ 1109 LOG_INFO("%{public}s enter", __FUNCTION__); 1110 1111 int ret; 1112 SdpName *ctx = MEM_MALLOC.alloc(sizeof(SdpName)); 1113 if (ctx == NULL) { 1114 LOG_ERROR("point to NULL"); 1115 return BT_NO_MEMORY; 1116 } 1117 (void)memset_s(ctx, sizeof(SdpName), 0x00, sizeof(SdpName)); 1118 1119 ctx->handle = handle; 1120 ctx->name = name; 1121 ctx->nameLen = nameLen; 1122 ctx->baseAttributeId = baseAttributeId; 1123 ctx->event = EventCreate(true); 1124 1125 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddProviderNameTask, ctx); 1126 if (ret == BT_SUCCESS) { 1127 EventWait(ctx->event, WAIT_TIME); 1128 ret = ctx->result; 1129 } 1130 1131 EventDelete(ctx->event); 1132 MEM_MALLOC.free(ctx); 1133 return ret; 1134} 1135 1136static void SdpAddAttributeTask(void *context) 1137{ 1138 SdpAttributeInfo *ctx = context; 1139 1140 if (ctx == NULL) { 1141 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 1142 return; 1143 } 1144 ctx->result = 1145 SdpAddAttribute(ctx->handle, ctx->attributeId, ctx->type, ctx->attributeValue, ctx->attributeValueLength); 1146 if (ctx->event != NULL) { 1147 EventSet(ctx->event); 1148 } 1149} 1150 1151int SDP_AddAttribute( 1152 uint32_t handle, uint16_t attributeId, SdpDataType type, void *attributeValue, uint16_t attributeValueLength) 1153{ 1154 LOG_INFO("%{public}s enter", __FUNCTION__); 1155 1156 int ret; 1157 SdpAttributeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpAttributeInfo)); 1158 if (ctx == NULL) { 1159 LOG_ERROR("point to NULL"); 1160 return BT_NO_MEMORY; 1161 } 1162 (void)memset_s(ctx, sizeof(SdpAttributeInfo), 0x00, sizeof(SdpAttributeInfo)); 1163 1164 ctx->handle = handle; 1165 ctx->attributeId = attributeId; 1166 ctx->type = type; 1167 ctx->attributeValue = attributeValue; 1168 ctx->attributeValueLength = attributeValueLength; 1169 ctx->event = EventCreate(true); 1170 1171 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddAttributeTask, ctx); 1172 if (ret == BT_SUCCESS) { 1173 EventWait(ctx->event, WAIT_TIME); 1174 ret = ctx->result; 1175 } 1176 1177 EventDelete(ctx->event); 1178 MEM_MALLOC.free(ctx); 1179 return ret; 1180} 1181 1182static void SdpAddSequenceAttributeTask(void *context) 1183{ 1184 SdpSequenceAttributeInfo *ctx = context; 1185 1186 if (ctx == NULL) { 1187 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 1188 return; 1189 } 1190 ctx->result = 1191 SdpAddSequenceAttribute(ctx->handle, ctx->attributeId, ctx->attributeValue, ctx->attributeValueLength); 1192 if (ctx->event != NULL) { 1193 EventSet(ctx->event); 1194 } 1195} 1196 1197int SDP_AddSequenceAttribute( 1198 uint32_t handle, uint16_t attributeId, const uint8_t *attributeValue, uint16_t attributeValueLength) 1199{ 1200 LOG_INFO("%{public}s enter", __FUNCTION__); 1201 1202 int ret; 1203 SdpSequenceAttributeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpSequenceAttributeInfo)); 1204 if (ctx == NULL) { 1205 LOG_ERROR("point to NULL"); 1206 return BT_NO_MEMORY; 1207 } 1208 (void)memset_s(ctx, sizeof(SdpSequenceAttributeInfo), 0x00, sizeof(SdpSequenceAttributeInfo)); 1209 1210 ctx->handle = handle; 1211 ctx->attributeId = attributeId; 1212 ctx->attributeValue = attributeValue; 1213 ctx->attributeValueLength = attributeValueLength; 1214 ctx->event = EventCreate(true); 1215 1216 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddSequenceAttributeTask, ctx); 1217 if (ret == BT_SUCCESS) { 1218 EventWait(ctx->event, WAIT_TIME); 1219 ret = ctx->result; 1220 } 1221 1222 EventDelete(ctx->event); 1223 MEM_MALLOC.free(ctx); 1224 return ret; 1225} 1226 1227static void SdpServiceSearchTask(void *context) 1228{ 1229 SdpServiceSearchInfo *ctx = context; 1230 1231 if (ctx == NULL) { 1232 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 1233 return; 1234 } 1235 ctx->result = SdpServiceSearch(&ctx->addr, &ctx->uuidArray, ctx->context, ctx->ServiceSearchCb); 1236 if (ctx->event != NULL) { 1237 EventSet(ctx->event); 1238 } 1239} 1240 1241int SDP_ServiceSearch(const BtAddr *addr, const SdpUuid *uuidArray, void *context, 1242 void (*serviceSearchCb)(const BtAddr *addr, const uint32_t *handleArray, uint16_t handleNum, void *context)) 1243{ 1244 LOG_INFO("%{public}s enter", __FUNCTION__); 1245 1246 int ret; 1247 SdpServiceSearchInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceSearchInfo)); 1248 if (ctx == NULL) { 1249 LOG_ERROR("point to NULL"); 1250 return BT_NO_MEMORY; 1251 } 1252 (void)memset_s(ctx, sizeof(SdpServiceSearchInfo), 0x00, sizeof(SdpServiceSearchInfo)); 1253 1254 (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr)); 1255 (void)memcpy_s(&ctx->uuidArray, sizeof(SdpUuid), uuidArray, sizeof(SdpUuid)); 1256 ctx->context = context; 1257 ctx->ServiceSearchCb = serviceSearchCb; 1258 ctx->event = EventCreate(true); 1259 1260 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpServiceSearchTask, ctx); 1261 if (ret == BT_SUCCESS) { 1262 EventWait(ctx->event, WAIT_TIME); 1263 ret = ctx->result; 1264 } 1265 1266 EventDelete(ctx->event); 1267 MEM_MALLOC.free(ctx); 1268 return ret; 1269} 1270 1271static void SdpServiceAttributeTask(void *context) 1272{ 1273 SdpServiceAttributeInfo *ctx = context; 1274 1275 if (ctx == NULL) { 1276 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 1277 return; 1278 } 1279 ctx->result = 1280 SdpServiceAttribute(&ctx->addr, ctx->handle, ctx->attributeIdList, ctx->context, ctx->ServiceAttributeCb); 1281 if (ctx->event != NULL) { 1282 EventSet(ctx->event); 1283 } 1284} 1285 1286int SDP_ServiceAttribute(const BtAddr *addr, uint32_t handle, SdpAttributeIdList attributeIdList, void *context, 1287 void (*serviceAttributeCb)(const BtAddr *addr, const SdpService *service, void *context)) 1288{ 1289 LOG_INFO("%{public}s enter", __FUNCTION__); 1290 1291 int ret; 1292 SdpServiceAttributeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceAttributeInfo)); 1293 if (ctx == NULL) { 1294 LOG_ERROR("point to NULL"); 1295 return BT_NO_MEMORY; 1296 } 1297 (void)memset_s(ctx, sizeof(SdpServiceAttributeInfo), 0x00, sizeof(SdpServiceAttributeInfo)); 1298 1299 (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr)); 1300 ctx->handle = handle; 1301 (void)memcpy_s(&ctx->attributeIdList, sizeof(SdpAttributeIdList), &attributeIdList, sizeof(SdpAttributeIdList)); 1302 ctx->context = context; 1303 ctx->ServiceAttributeCb = serviceAttributeCb; 1304 ctx->event = EventCreate(true); 1305 1306 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpServiceAttributeTask, ctx); 1307 if (ret == BT_SUCCESS) { 1308 EventWait(ctx->event, WAIT_TIME); 1309 ret = ctx->result; 1310 } 1311 1312 EventDelete(ctx->event); 1313 MEM_MALLOC.free(ctx); 1314 return ret; 1315} 1316 1317static void SdpServiceSearchAttributeTask(void *context) 1318{ 1319 SdpServiceSearchAttributeInfo *ctx = context; 1320 1321 if (ctx == NULL) { 1322 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 1323 return; 1324 } 1325 ctx->result = SdpServiceSearchAttribute( 1326 &ctx->addr, &ctx->uuidArray, ctx->attributeIdList, ctx->context, ctx->ServiceSearchAttributeCb); 1327 if (ctx->event != NULL) { 1328 EventSet(ctx->event); 1329 } 1330} 1331 1332int SDP_ServiceSearchAttribute(const BtAddr *addr, const SdpUuid *uuidArray, SdpAttributeIdList attributeIdList, 1333 void *context, 1334 void (*searchAttributeCb)(const BtAddr *addr, const SdpService *serviceArray, uint16_t serviceNum, void *context)) 1335{ 1336 LOG_INFO("%{public}s enter", __FUNCTION__); 1337 1338 int ret; 1339 SdpServiceSearchAttributeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceSearchAttributeInfo)); 1340 if (ctx == NULL) { 1341 LOG_ERROR("point to NULL"); 1342 return BT_NO_MEMORY; 1343 } 1344 (void)memset_s(ctx, sizeof(SdpServiceSearchAttributeInfo), 0x00, sizeof(SdpServiceSearchAttributeInfo)); 1345 1346 (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr)); 1347 (void)memcpy_s(&ctx->uuidArray, sizeof(SdpUuid), uuidArray, sizeof(SdpUuid)); 1348 (void)memcpy_s(&ctx->attributeIdList, sizeof(SdpAttributeIdList), &attributeIdList, sizeof(SdpAttributeIdList)); 1349 ctx->context = context; 1350 ctx->ServiceSearchAttributeCb = searchAttributeCb; 1351 ctx->event = EventCreate(true); 1352 1353 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpServiceSearchAttributeTask, ctx); 1354 if (ret == BT_SUCCESS) { 1355 EventWait(ctx->event, WAIT_TIME); 1356 ret = ctx->result; 1357 } 1358 1359 EventDelete(ctx->event); 1360 MEM_MALLOC.free(ctx); 1361 return ret; 1362} 1363 1364static void SdpServiceBrowseTask(void *context) 1365{ 1366 SdpServiceBrowseInfo *ctx = context; 1367 1368 if (ctx == NULL) { 1369 LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__); 1370 return; 1371 } 1372 ctx->result = SdpServiceBrowse(&ctx->addr, ctx->context, ctx->ServiceBrowseCb); 1373 if (ctx->event != NULL) { 1374 EventSet(ctx->event); 1375 } 1376} 1377 1378int SDP_ServiceBrowse(const BtAddr *addr, void *context, 1379 void (*serviceBrowseCb)(const BtAddr *addr, const uint32_t *handleArray, uint16_t handleNum, void *context)) 1380{ 1381 LOG_INFO("%{public}s enter", __FUNCTION__); 1382 1383 int ret; 1384 SdpServiceBrowseInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceBrowseInfo)); 1385 if (ctx == NULL) { 1386 LOG_ERROR("point to NULL"); 1387 return BT_NO_MEMORY; 1388 } 1389 (void)memset_s(ctx, sizeof(SdpServiceBrowseInfo), 0x00, sizeof(SdpServiceBrowseInfo)); 1390 1391 (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr)); 1392 ctx->context = context; 1393 ctx->ServiceBrowseCb = serviceBrowseCb; 1394 ctx->event = EventCreate(true); 1395 1396 ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpServiceBrowseTask, ctx); 1397 if (ret == BT_SUCCESS) { 1398 EventWait(ctx->event, WAIT_TIME); 1399 ret = ctx->result; 1400 } 1401 1402 EventDelete(ctx->event); 1403 MEM_MALLOC.free(ctx); 1404 return ret; 1405} 1406 1407static void SdpInitialize(int traceLevel) 1408{ 1409 LOG_INFO("%{public}s enter", __FUNCTION__); 1410 return; 1411} 1412 1413static void SdpFinalize() 1414{ 1415 LOG_INFO("%{public}s enter", __FUNCTION__); 1416 return; 1417} 1418 1419Module g_sdp = { 1420 .name = MODULE_NAME_SDP, 1421 .init = SdpInitialize, 1422 .startup = SdpStartup, 1423 .shutdown = SdpShutdown, 1424 .cleanup = SdpFinalize, 1425 .dependencies = {MODULE_NAME_L2CAP}, 1426}; 1427 1428MODULE_DECL(g_sdp) 1429