119e95205Sopenharmony_ci/*
219e95205Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
319e95205Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
419e95205Sopenharmony_ci * you may not use this file except in compliance with the License.
519e95205Sopenharmony_ci * You may obtain a copy of the License at
619e95205Sopenharmony_ci *
719e95205Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
819e95205Sopenharmony_ci *
919e95205Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1019e95205Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1119e95205Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1219e95205Sopenharmony_ci * See the License for the specific language governing permissions and
1319e95205Sopenharmony_ci * limitations under the License.
1419e95205Sopenharmony_ci */
1519e95205Sopenharmony_ci
1619e95205Sopenharmony_ci#include "sdp.h"
1719e95205Sopenharmony_ci
1819e95205Sopenharmony_ci#include <string.h>
1919e95205Sopenharmony_ci
2019e95205Sopenharmony_ci#include "sdp_client.h"
2119e95205Sopenharmony_ci#include "sdp_connect.h"
2219e95205Sopenharmony_ci#include "sdp_server.h"
2319e95205Sopenharmony_ci#include "sdp_util.h"
2419e95205Sopenharmony_ci
2519e95205Sopenharmony_ci#include "btstack.h"
2619e95205Sopenharmony_ci#include "event.h"
2719e95205Sopenharmony_ci#include "module.h"
2819e95205Sopenharmony_ci
2919e95205Sopenharmony_ci#include "allocator.h"
3019e95205Sopenharmony_ci#include "log.h"
3119e95205Sopenharmony_ci
3219e95205Sopenharmony_ci#include "../btm/btm_thread.h"
3319e95205Sopenharmony_ci
3419e95205Sopenharmony_ci#define WAIT_TIME (-1)
3519e95205Sopenharmony_ci
3619e95205Sopenharmony_citypedef struct {
3719e95205Sopenharmony_ci    int traceLevel;
3819e95205Sopenharmony_ci    Event *event;
3919e95205Sopenharmony_ci} SdpInitializeInfo;
4019e95205Sopenharmony_ci
4119e95205Sopenharmony_citypedef struct {
4219e95205Sopenharmony_ci    uint32_t handle;
4319e95205Sopenharmony_ci    Event *event;
4419e95205Sopenharmony_ci} SdpServiceRecordHandle;
4519e95205Sopenharmony_ci
4619e95205Sopenharmony_citypedef struct {
4719e95205Sopenharmony_ci    uint32_t handle;
4819e95205Sopenharmony_ci    Event *event;
4919e95205Sopenharmony_ci    int result;
5019e95205Sopenharmony_ci} SdpServiceRecord;
5119e95205Sopenharmony_ci
5219e95205Sopenharmony_citypedef struct {
5319e95205Sopenharmony_ci    uint32_t handle;
5419e95205Sopenharmony_ci    const BtUuid *classid;
5519e95205Sopenharmony_ci    uint16_t classidNumber;
5619e95205Sopenharmony_ci    Event *event;
5719e95205Sopenharmony_ci    int result;
5819e95205Sopenharmony_ci} SdpServiceClassID;
5919e95205Sopenharmony_ci
6019e95205Sopenharmony_citypedef struct {
6119e95205Sopenharmony_ci    uint32_t handle;
6219e95205Sopenharmony_ci    uint32_t state;
6319e95205Sopenharmony_ci    Event *event;
6419e95205Sopenharmony_ci    int result;
6519e95205Sopenharmony_ci} SdpServiceRecordState;
6619e95205Sopenharmony_ci
6719e95205Sopenharmony_citypedef struct {
6819e95205Sopenharmony_ci    uint32_t handle;
6919e95205Sopenharmony_ci    BtUuid serviceid;
7019e95205Sopenharmony_ci    Event *event;
7119e95205Sopenharmony_ci    int result;
7219e95205Sopenharmony_ci} SdpServiceId;
7319e95205Sopenharmony_ci
7419e95205Sopenharmony_citypedef struct {
7519e95205Sopenharmony_ci    uint32_t handle;
7619e95205Sopenharmony_ci    const SdpProtocolDescriptor *descriptor;
7719e95205Sopenharmony_ci    uint16_t descriptorNumber;
7819e95205Sopenharmony_ci    Event *event;
7919e95205Sopenharmony_ci    int result;
8019e95205Sopenharmony_ci} SdpProtocolDescriptorList;
8119e95205Sopenharmony_ci
8219e95205Sopenharmony_citypedef struct {
8319e95205Sopenharmony_ci    uint32_t handle;
8419e95205Sopenharmony_ci    const SdpAdditionalProtocolDescriptor *descriptorList;
8519e95205Sopenharmony_ci    uint16_t descriptorListNumber;
8619e95205Sopenharmony_ci    Event *event;
8719e95205Sopenharmony_ci    int result;
8819e95205Sopenharmony_ci} SdpAdditionalProtocolDescriptorList;
8919e95205Sopenharmony_ci
9019e95205Sopenharmony_citypedef struct {
9119e95205Sopenharmony_ci    uint32_t handle;
9219e95205Sopenharmony_ci    const BtUuid *browseUuid;
9319e95205Sopenharmony_ci    uint16_t browseUuidNumber;
9419e95205Sopenharmony_ci    Event *event;
9519e95205Sopenharmony_ci    int result;
9619e95205Sopenharmony_ci} SdpBrowseGroupList;
9719e95205Sopenharmony_ci
9819e95205Sopenharmony_citypedef struct {
9919e95205Sopenharmony_ci    uint32_t handle;
10019e95205Sopenharmony_ci    const SdpLanguageBaseAttributeId *baseAttributeId;
10119e95205Sopenharmony_ci    uint16_t baseAttributeIdNumber;
10219e95205Sopenharmony_ci    Event *event;
10319e95205Sopenharmony_ci    int result;
10419e95205Sopenharmony_ci} SdpLanguageBaseAttributeIdList;
10519e95205Sopenharmony_ci
10619e95205Sopenharmony_citypedef struct {
10719e95205Sopenharmony_ci    uint32_t handle;
10819e95205Sopenharmony_ci    uint32_t value;
10919e95205Sopenharmony_ci    Event *event;
11019e95205Sopenharmony_ci    int result;
11119e95205Sopenharmony_ci} SdpServiceInfoTimeToLive;
11219e95205Sopenharmony_ci
11319e95205Sopenharmony_citypedef struct {
11419e95205Sopenharmony_ci    uint32_t handle;
11519e95205Sopenharmony_ci    uint8_t value;
11619e95205Sopenharmony_ci    Event *event;
11719e95205Sopenharmony_ci    int result;
11819e95205Sopenharmony_ci} SdpServiceAvailability;
11919e95205Sopenharmony_ci
12019e95205Sopenharmony_citypedef struct {
12119e95205Sopenharmony_ci    uint32_t handle;
12219e95205Sopenharmony_ci    const SdpProfileDescriptor *profileDescriptor;
12319e95205Sopenharmony_ci    uint16_t profileDescriptorNumber;
12419e95205Sopenharmony_ci    Event *event;
12519e95205Sopenharmony_ci    int result;
12619e95205Sopenharmony_ci} SdpBluetoothProfileDescriptorList;
12719e95205Sopenharmony_ci
12819e95205Sopenharmony_citypedef struct {
12919e95205Sopenharmony_ci    uint32_t handle;
13019e95205Sopenharmony_ci    const uint8_t *url;
13119e95205Sopenharmony_ci    uint16_t urlLen;
13219e95205Sopenharmony_ci    Event *event;
13319e95205Sopenharmony_ci    int result;
13419e95205Sopenharmony_ci} SdpUrl;
13519e95205Sopenharmony_ci
13619e95205Sopenharmony_citypedef struct {
13719e95205Sopenharmony_ci    uint32_t handle;
13819e95205Sopenharmony_ci    uint16_t baseAttributeId;
13919e95205Sopenharmony_ci    const char *name;
14019e95205Sopenharmony_ci    uint16_t nameLen;
14119e95205Sopenharmony_ci    Event *event;
14219e95205Sopenharmony_ci    int result;
14319e95205Sopenharmony_ci} SdpName;
14419e95205Sopenharmony_ci
14519e95205Sopenharmony_citypedef struct {
14619e95205Sopenharmony_ci    uint32_t handle;
14719e95205Sopenharmony_ci    uint16_t attributeId;
14819e95205Sopenharmony_ci    SdpDataType type;
14919e95205Sopenharmony_ci    void *attributeValue;
15019e95205Sopenharmony_ci    uint16_t attributeValueLength;
15119e95205Sopenharmony_ci    Event *event;
15219e95205Sopenharmony_ci    int result;
15319e95205Sopenharmony_ci} SdpAttributeInfo;
15419e95205Sopenharmony_ci
15519e95205Sopenharmony_citypedef struct {
15619e95205Sopenharmony_ci    uint32_t handle;
15719e95205Sopenharmony_ci    uint16_t attributeId;
15819e95205Sopenharmony_ci    const uint8_t *attributeValue;
15919e95205Sopenharmony_ci    uint16_t attributeValueLength;
16019e95205Sopenharmony_ci    Event *event;
16119e95205Sopenharmony_ci    int result;
16219e95205Sopenharmony_ci} SdpSequenceAttributeInfo;
16319e95205Sopenharmony_ci
16419e95205Sopenharmony_citypedef struct {
16519e95205Sopenharmony_ci    BtAddr addr;
16619e95205Sopenharmony_ci    SdpUuid uuidArray;
16719e95205Sopenharmony_ci    void *context;
16819e95205Sopenharmony_ci    void (*ServiceSearchCb)(const BtAddr *addr, const uint32_t *handleArray, uint16_t handleNum, void *context);
16919e95205Sopenharmony_ci    Event *event;
17019e95205Sopenharmony_ci    int result;
17119e95205Sopenharmony_ci} SdpServiceSearchInfo;
17219e95205Sopenharmony_ci
17319e95205Sopenharmony_citypedef struct {
17419e95205Sopenharmony_ci    BtAddr addr;
17519e95205Sopenharmony_ci    uint32_t handle;
17619e95205Sopenharmony_ci    SdpAttributeIdList attributeIdList;
17719e95205Sopenharmony_ci    void *context;
17819e95205Sopenharmony_ci    void (*ServiceAttributeCb)(const BtAddr *addr, const SdpService *service, void *context);
17919e95205Sopenharmony_ci    Event *event;
18019e95205Sopenharmony_ci    int result;
18119e95205Sopenharmony_ci} SdpServiceAttributeInfo;
18219e95205Sopenharmony_ci
18319e95205Sopenharmony_citypedef struct {
18419e95205Sopenharmony_ci    BtAddr addr;
18519e95205Sopenharmony_ci    SdpUuid uuidArray;
18619e95205Sopenharmony_ci    SdpAttributeIdList attributeIdList;
18719e95205Sopenharmony_ci    void *context;
18819e95205Sopenharmony_ci    void (*ServiceSearchAttributeCb)(
18919e95205Sopenharmony_ci        const BtAddr *addr, const SdpService *serviceArray, uint16_t serviceNum, void *context);
19019e95205Sopenharmony_ci    Event *event;
19119e95205Sopenharmony_ci    int result;
19219e95205Sopenharmony_ci} SdpServiceSearchAttributeInfo;
19319e95205Sopenharmony_ci
19419e95205Sopenharmony_citypedef struct {
19519e95205Sopenharmony_ci    BtAddr addr;
19619e95205Sopenharmony_ci    void *context;
19719e95205Sopenharmony_ci    void (*ServiceBrowseCb)(const BtAddr *addr, const uint32_t *handleArray, uint16_t handleNum, void *context);
19819e95205Sopenharmony_ci    Event *event;
19919e95205Sopenharmony_ci    int result;
20019e95205Sopenharmony_ci} SdpServiceBrowseInfo;
20119e95205Sopenharmony_ci
20219e95205Sopenharmony_cistatic void SdpInitializeTask(void *context)
20319e95205Sopenharmony_ci{
20419e95205Sopenharmony_ci    LOG_INFO("%{public}s", __func__);
20519e95205Sopenharmony_ci
20619e95205Sopenharmony_ci    SdpInitializeInfo *ctx = context;
20719e95205Sopenharmony_ci
20819e95205Sopenharmony_ci    if (ctx == NULL) {
20919e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
21019e95205Sopenharmony_ci        return;
21119e95205Sopenharmony_ci    }
21219e95205Sopenharmony_ci
21319e95205Sopenharmony_ci    SdpInitializeClient();
21419e95205Sopenharmony_ci    SdpInitializeServer();
21519e95205Sopenharmony_ci    SdpRegisterToL2cap();
21619e95205Sopenharmony_ci    SdpSetEnableState();
21719e95205Sopenharmony_ci
21819e95205Sopenharmony_ci    if (ctx->event != NULL) {
21919e95205Sopenharmony_ci        EventSet(ctx->event);
22019e95205Sopenharmony_ci    }
22119e95205Sopenharmony_ci}
22219e95205Sopenharmony_ci
22319e95205Sopenharmony_cistatic void SdpStartup(int traceLevel)
22419e95205Sopenharmony_ci{
22519e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
22619e95205Sopenharmony_ci
22719e95205Sopenharmony_ci    int ret;
22819e95205Sopenharmony_ci    SdpInitializeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpInitializeInfo));
22919e95205Sopenharmony_ci    if (ctx == NULL) {
23019e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
23119e95205Sopenharmony_ci        return;
23219e95205Sopenharmony_ci    }
23319e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpInitializeInfo), 0x00, sizeof(SdpInitializeInfo));
23419e95205Sopenharmony_ci
23519e95205Sopenharmony_ci    ret = BTM_CreateProcessingQueue(PROCESSING_QUEUE_ID_SDP, BTM_PROCESSING_QUEUE_SIZE_DEFAULT);
23619e95205Sopenharmony_ci    if (ret != BT_SUCCESS) {
23719e95205Sopenharmony_ci        MEM_MALLOC.free(ctx);
23819e95205Sopenharmony_ci        return;
23919e95205Sopenharmony_ci    }
24019e95205Sopenharmony_ci
24119e95205Sopenharmony_ci    ctx->traceLevel = traceLevel;
24219e95205Sopenharmony_ci    ctx->event = EventCreate(true);
24319e95205Sopenharmony_ci
24419e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpInitializeTask, ctx);
24519e95205Sopenharmony_ci    if (ret != BT_SUCCESS) {
24619e95205Sopenharmony_ci        EventDelete(ctx->event);
24719e95205Sopenharmony_ci        MEM_MALLOC.free(ctx);
24819e95205Sopenharmony_ci        return;
24919e95205Sopenharmony_ci    }
25019e95205Sopenharmony_ci
25119e95205Sopenharmony_ci    EventWait(ctx->event, WAIT_TIME);
25219e95205Sopenharmony_ci    EventDelete(ctx->event);
25319e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
25419e95205Sopenharmony_ci}
25519e95205Sopenharmony_ci
25619e95205Sopenharmony_cistatic void SdpFinalizeTask(void *context)
25719e95205Sopenharmony_ci{
25819e95205Sopenharmony_ci    Event *ctx = context;
25919e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
26019e95205Sopenharmony_ci    if (ctx == NULL) {
26119e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
26219e95205Sopenharmony_ci        return;
26319e95205Sopenharmony_ci    }
26419e95205Sopenharmony_ci    SdpSetDisableState();
26519e95205Sopenharmony_ci    SdpDeregisterToL2cap();
26619e95205Sopenharmony_ci    SdpFinalizeServer();
26719e95205Sopenharmony_ci    SdpFinalizeClient();
26819e95205Sopenharmony_ci
26919e95205Sopenharmony_ci    BTM_DeleteProcessingQueue(PROCESSING_QUEUE_ID_SDP);
27019e95205Sopenharmony_ci    EventSet(ctx);
27119e95205Sopenharmony_ci}
27219e95205Sopenharmony_ci
27319e95205Sopenharmony_cistatic void SdpShutdown()
27419e95205Sopenharmony_ci{
27519e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
27619e95205Sopenharmony_ci
27719e95205Sopenharmony_ci    int ret;
27819e95205Sopenharmony_ci    Event *ctx = EventCreate(true);
27919e95205Sopenharmony_ci
28019e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpFinalizeTask, ctx);
28119e95205Sopenharmony_ci    if (ret != BT_SUCCESS) {
28219e95205Sopenharmony_ci        EventDelete(ctx);
28319e95205Sopenharmony_ci        return;
28419e95205Sopenharmony_ci    }
28519e95205Sopenharmony_ci
28619e95205Sopenharmony_ci    EventWait(ctx, WAIT_TIME);
28719e95205Sopenharmony_ci    EventDelete(ctx);
28819e95205Sopenharmony_ci
28919e95205Sopenharmony_ci    LOG_INFO("%{public}s end", __FUNCTION__);
29019e95205Sopenharmony_ci}
29119e95205Sopenharmony_ci
29219e95205Sopenharmony_cistatic void SdpCreateServiceRecordTask(void *context)
29319e95205Sopenharmony_ci{
29419e95205Sopenharmony_ci    SdpServiceRecordHandle *ctx = context;
29519e95205Sopenharmony_ci
29619e95205Sopenharmony_ci    if (ctx == NULL) {
29719e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
29819e95205Sopenharmony_ci        return;
29919e95205Sopenharmony_ci    }
30019e95205Sopenharmony_ci    ctx->handle = SdpCreateServiceRecord();
30119e95205Sopenharmony_ci    if (ctx->event != NULL) {
30219e95205Sopenharmony_ci        EventSet(ctx->event);
30319e95205Sopenharmony_ci    }
30419e95205Sopenharmony_ci}
30519e95205Sopenharmony_ci
30619e95205Sopenharmony_ciuint32_t SDP_CreateServiceRecord()
30719e95205Sopenharmony_ci{
30819e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
30919e95205Sopenharmony_ci
31019e95205Sopenharmony_ci    int ret;
31119e95205Sopenharmony_ci    int handle = 0;
31219e95205Sopenharmony_ci    SdpServiceRecordHandle *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecordHandle));
31319e95205Sopenharmony_ci    if (ctx == NULL) {
31419e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
31519e95205Sopenharmony_ci        return 0;
31619e95205Sopenharmony_ci    }
31719e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceRecordHandle), 0x00, sizeof(SdpServiceRecordHandle));
31819e95205Sopenharmony_ci
31919e95205Sopenharmony_ci    ctx->event = EventCreate(true);
32019e95205Sopenharmony_ci
32119e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpCreateServiceRecordTask, ctx);
32219e95205Sopenharmony_ci    if (ret != BT_SUCCESS) {
32319e95205Sopenharmony_ci        EventDelete(ctx->event);
32419e95205Sopenharmony_ci        MEM_MALLOC.free(ctx);
32519e95205Sopenharmony_ci        return handle;
32619e95205Sopenharmony_ci    }
32719e95205Sopenharmony_ci
32819e95205Sopenharmony_ci    EventWait(ctx->event, WAIT_TIME);
32919e95205Sopenharmony_ci    EventDelete(ctx->event);
33019e95205Sopenharmony_ci    handle = ctx->handle;
33119e95205Sopenharmony_ci
33219e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
33319e95205Sopenharmony_ci    return handle;
33419e95205Sopenharmony_ci}
33519e95205Sopenharmony_ci
33619e95205Sopenharmony_cistatic void SdpDestroyServiceRecordTask(void *context)
33719e95205Sopenharmony_ci{
33819e95205Sopenharmony_ci    SdpServiceRecord *ctx = context;
33919e95205Sopenharmony_ci
34019e95205Sopenharmony_ci    if (ctx == NULL) {
34119e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
34219e95205Sopenharmony_ci        return;
34319e95205Sopenharmony_ci    }
34419e95205Sopenharmony_ci    ctx->result = SdpDestroyServiceRecord(ctx->handle);
34519e95205Sopenharmony_ci    if (ctx->event != NULL) {
34619e95205Sopenharmony_ci        EventSet(ctx->event);
34719e95205Sopenharmony_ci    }
34819e95205Sopenharmony_ci}
34919e95205Sopenharmony_ci
35019e95205Sopenharmony_ciint SDP_DestroyServiceRecord(uint32_t handle)
35119e95205Sopenharmony_ci{
35219e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
35319e95205Sopenharmony_ci
35419e95205Sopenharmony_ci    int ret;
35519e95205Sopenharmony_ci    SdpServiceRecord *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecord));
35619e95205Sopenharmony_ci    if (ctx == NULL) {
35719e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
35819e95205Sopenharmony_ci        return BT_NO_MEMORY;
35919e95205Sopenharmony_ci    }
36019e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceRecord), 0x00, sizeof(SdpServiceRecord));
36119e95205Sopenharmony_ci
36219e95205Sopenharmony_ci    ctx->handle = handle;
36319e95205Sopenharmony_ci    ctx->event = EventCreate(true);
36419e95205Sopenharmony_ci
36519e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpDestroyServiceRecordTask, ctx);
36619e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
36719e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
36819e95205Sopenharmony_ci        ret = ctx->result;
36919e95205Sopenharmony_ci    }
37019e95205Sopenharmony_ci
37119e95205Sopenharmony_ci    EventDelete(ctx->event);
37219e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
37319e95205Sopenharmony_ci
37419e95205Sopenharmony_ci    LOG_INFO("%{public}s exit", __FUNCTION__);
37519e95205Sopenharmony_ci    return ret;
37619e95205Sopenharmony_ci}
37719e95205Sopenharmony_ci
37819e95205Sopenharmony_cistatic void SdpRegisterServiceRecordTask(void *context)
37919e95205Sopenharmony_ci{
38019e95205Sopenharmony_ci    SdpServiceRecord *ctx = context;
38119e95205Sopenharmony_ci
38219e95205Sopenharmony_ci    if (ctx == NULL) {
38319e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
38419e95205Sopenharmony_ci        return;
38519e95205Sopenharmony_ci    }
38619e95205Sopenharmony_ci    ctx->result = SdpRegisterServiceRecord(ctx->handle);
38719e95205Sopenharmony_ci    if (ctx->event != NULL) {
38819e95205Sopenharmony_ci        EventSet(ctx->event);
38919e95205Sopenharmony_ci    }
39019e95205Sopenharmony_ci}
39119e95205Sopenharmony_ci
39219e95205Sopenharmony_ciint SDP_RegisterServiceRecord(uint32_t handle)
39319e95205Sopenharmony_ci{
39419e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
39519e95205Sopenharmony_ci
39619e95205Sopenharmony_ci    int ret;
39719e95205Sopenharmony_ci    SdpServiceRecord *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecord));
39819e95205Sopenharmony_ci    if (ctx == NULL) {
39919e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
40019e95205Sopenharmony_ci        return BT_NO_MEMORY;
40119e95205Sopenharmony_ci    }
40219e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceRecord), 0x00, sizeof(SdpServiceRecord));
40319e95205Sopenharmony_ci
40419e95205Sopenharmony_ci    ctx->handle = handle;
40519e95205Sopenharmony_ci    ctx->event = EventCreate(true);
40619e95205Sopenharmony_ci
40719e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpRegisterServiceRecordTask, ctx);
40819e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
40919e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
41019e95205Sopenharmony_ci        ret = ctx->result;
41119e95205Sopenharmony_ci    }
41219e95205Sopenharmony_ci
41319e95205Sopenharmony_ci    EventDelete(ctx->event);
41419e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
41519e95205Sopenharmony_ci    return ret;
41619e95205Sopenharmony_ci}
41719e95205Sopenharmony_ci
41819e95205Sopenharmony_cistatic void SdpDeregisterServiceRecordTask(void *context)
41919e95205Sopenharmony_ci{
42019e95205Sopenharmony_ci    SdpServiceRecord *ctx = context;
42119e95205Sopenharmony_ci
42219e95205Sopenharmony_ci    if (ctx == NULL) {
42319e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
42419e95205Sopenharmony_ci        return;
42519e95205Sopenharmony_ci    }
42619e95205Sopenharmony_ci    ctx->result = SdpDeregisterServiceRecord(ctx->handle);
42719e95205Sopenharmony_ci    if (ctx->event != NULL) {
42819e95205Sopenharmony_ci        EventSet(ctx->event);
42919e95205Sopenharmony_ci    }
43019e95205Sopenharmony_ci}
43119e95205Sopenharmony_ci
43219e95205Sopenharmony_ciint SDP_DeregisterServiceRecord(uint32_t handle)
43319e95205Sopenharmony_ci{
43419e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
43519e95205Sopenharmony_ci
43619e95205Sopenharmony_ci    int ret;
43719e95205Sopenharmony_ci    SdpServiceRecord *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecord));
43819e95205Sopenharmony_ci    if (ctx == NULL) {
43919e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
44019e95205Sopenharmony_ci        return BT_NO_MEMORY;
44119e95205Sopenharmony_ci    }
44219e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceRecord), 0x00, sizeof(SdpServiceRecord));
44319e95205Sopenharmony_ci
44419e95205Sopenharmony_ci    ctx->handle = handle;
44519e95205Sopenharmony_ci    ctx->event = EventCreate(true);
44619e95205Sopenharmony_ci
44719e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpDeregisterServiceRecordTask, ctx);
44819e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
44919e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
45019e95205Sopenharmony_ci        ret = ctx->result;
45119e95205Sopenharmony_ci    }
45219e95205Sopenharmony_ci
45319e95205Sopenharmony_ci    EventDelete(ctx->event);
45419e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
45519e95205Sopenharmony_ci
45619e95205Sopenharmony_ci    LOG_INFO("%{public}s exit", __FUNCTION__);
45719e95205Sopenharmony_ci    return ret;
45819e95205Sopenharmony_ci}
45919e95205Sopenharmony_ci
46019e95205Sopenharmony_cistatic void SdpAddServiceClassIdListTask(void *context)
46119e95205Sopenharmony_ci{
46219e95205Sopenharmony_ci    SdpServiceClassID *ctx = context;
46319e95205Sopenharmony_ci
46419e95205Sopenharmony_ci    if (ctx == NULL) {
46519e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
46619e95205Sopenharmony_ci        return;
46719e95205Sopenharmony_ci    }
46819e95205Sopenharmony_ci    ctx->result = SdpAddServiceClassIdList(ctx->handle, ctx->classid, ctx->classidNumber);
46919e95205Sopenharmony_ci    if (ctx->event != NULL) {
47019e95205Sopenharmony_ci        EventSet(ctx->event);
47119e95205Sopenharmony_ci    }
47219e95205Sopenharmony_ci}
47319e95205Sopenharmony_ci
47419e95205Sopenharmony_ciint SDP_AddServiceClassIdList(uint32_t handle, const BtUuid *classid, uint16_t classidNumber)
47519e95205Sopenharmony_ci{
47619e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
47719e95205Sopenharmony_ci
47819e95205Sopenharmony_ci    int ret;
47919e95205Sopenharmony_ci    SdpServiceClassID *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceClassID));
48019e95205Sopenharmony_ci    if (ctx == NULL) {
48119e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
48219e95205Sopenharmony_ci        return BT_NO_MEMORY;
48319e95205Sopenharmony_ci    }
48419e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceClassID), 0x00, sizeof(SdpServiceClassID));
48519e95205Sopenharmony_ci
48619e95205Sopenharmony_ci    ctx->handle = handle;
48719e95205Sopenharmony_ci    ctx->classid = classid;
48819e95205Sopenharmony_ci    ctx->classidNumber = classidNumber;
48919e95205Sopenharmony_ci    ctx->event = EventCreate(true);
49019e95205Sopenharmony_ci
49119e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceClassIdListTask, ctx);
49219e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
49319e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
49419e95205Sopenharmony_ci        ret = ctx->result;
49519e95205Sopenharmony_ci    }
49619e95205Sopenharmony_ci
49719e95205Sopenharmony_ci    EventDelete(ctx->event);
49819e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
49919e95205Sopenharmony_ci    return ret;
50019e95205Sopenharmony_ci}
50119e95205Sopenharmony_ci
50219e95205Sopenharmony_cistatic void SdpAddServiceRecordStateTask(void *context)
50319e95205Sopenharmony_ci{
50419e95205Sopenharmony_ci    SdpServiceRecordState *ctx = context;
50519e95205Sopenharmony_ci
50619e95205Sopenharmony_ci    if (ctx == NULL) {
50719e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
50819e95205Sopenharmony_ci        return;
50919e95205Sopenharmony_ci    }
51019e95205Sopenharmony_ci    ctx->result = SdpAddServiceRecordState(ctx->handle, ctx->state);
51119e95205Sopenharmony_ci    if (ctx->event != NULL) {
51219e95205Sopenharmony_ci        EventSet(ctx->event);
51319e95205Sopenharmony_ci    }
51419e95205Sopenharmony_ci}
51519e95205Sopenharmony_ci
51619e95205Sopenharmony_ciint SDP_AddServiceRecordState(uint32_t handle, uint32_t state)
51719e95205Sopenharmony_ci{
51819e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
51919e95205Sopenharmony_ci
52019e95205Sopenharmony_ci    int ret;
52119e95205Sopenharmony_ci    SdpServiceRecordState *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceRecordState));
52219e95205Sopenharmony_ci    if (ctx == NULL) {
52319e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
52419e95205Sopenharmony_ci        return BT_NO_MEMORY;
52519e95205Sopenharmony_ci    }
52619e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceRecordState), 0x00, sizeof(SdpServiceRecordState));
52719e95205Sopenharmony_ci
52819e95205Sopenharmony_ci    ctx->handle = handle;
52919e95205Sopenharmony_ci    ctx->state = state;
53019e95205Sopenharmony_ci    ctx->event = EventCreate(true);
53119e95205Sopenharmony_ci
53219e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceRecordStateTask, ctx);
53319e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
53419e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
53519e95205Sopenharmony_ci        ret = ctx->result;
53619e95205Sopenharmony_ci    }
53719e95205Sopenharmony_ci
53819e95205Sopenharmony_ci    EventDelete(ctx->event);
53919e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
54019e95205Sopenharmony_ci    return ret;
54119e95205Sopenharmony_ci}
54219e95205Sopenharmony_ci
54319e95205Sopenharmony_cistatic void SdpAddServiceIdTask(void *context)
54419e95205Sopenharmony_ci{
54519e95205Sopenharmony_ci    SdpServiceId *ctx = context;
54619e95205Sopenharmony_ci
54719e95205Sopenharmony_ci    if (ctx == NULL) {
54819e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
54919e95205Sopenharmony_ci        return;
55019e95205Sopenharmony_ci    }
55119e95205Sopenharmony_ci    ctx->result = SdpAddServiceId(ctx->handle, &ctx->serviceid);
55219e95205Sopenharmony_ci    if (ctx->event != NULL) {
55319e95205Sopenharmony_ci        EventSet(ctx->event);
55419e95205Sopenharmony_ci    }
55519e95205Sopenharmony_ci}
55619e95205Sopenharmony_ci
55719e95205Sopenharmony_ciint SDP_AddServiceId(uint32_t handle, const BtUuid *serviceid)
55819e95205Sopenharmony_ci{
55919e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
56019e95205Sopenharmony_ci
56119e95205Sopenharmony_ci    int ret;
56219e95205Sopenharmony_ci    SdpServiceId *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceId));
56319e95205Sopenharmony_ci    if (ctx == NULL) {
56419e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
56519e95205Sopenharmony_ci        return BT_NO_MEMORY;
56619e95205Sopenharmony_ci    }
56719e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceId), 0x00, sizeof(SdpServiceId));
56819e95205Sopenharmony_ci
56919e95205Sopenharmony_ci    ctx->handle = handle;
57019e95205Sopenharmony_ci    (void)memcpy_s(&ctx->serviceid, sizeof(BtUuid), serviceid, sizeof(BtUuid));
57119e95205Sopenharmony_ci    ctx->event = EventCreate(true);
57219e95205Sopenharmony_ci
57319e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceIdTask, ctx);
57419e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
57519e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
57619e95205Sopenharmony_ci        ret = ctx->result;
57719e95205Sopenharmony_ci    }
57819e95205Sopenharmony_ci
57919e95205Sopenharmony_ci    EventDelete(ctx->event);
58019e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
58119e95205Sopenharmony_ci    return ret;
58219e95205Sopenharmony_ci}
58319e95205Sopenharmony_ci
58419e95205Sopenharmony_cistatic void SdpAddProtocolDescriptorListTask(void *context)
58519e95205Sopenharmony_ci{
58619e95205Sopenharmony_ci    SdpProtocolDescriptorList *ctx = context;
58719e95205Sopenharmony_ci
58819e95205Sopenharmony_ci    if (ctx == NULL) {
58919e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
59019e95205Sopenharmony_ci        return;
59119e95205Sopenharmony_ci    }
59219e95205Sopenharmony_ci    ctx->result = SdpAddProtocolDescriptorList(ctx->handle, ctx->descriptor, ctx->descriptorNumber);
59319e95205Sopenharmony_ci    if (ctx->event != NULL) {
59419e95205Sopenharmony_ci        EventSet(ctx->event);
59519e95205Sopenharmony_ci    }
59619e95205Sopenharmony_ci}
59719e95205Sopenharmony_ci
59819e95205Sopenharmony_ciint SDP_AddProtocolDescriptorList(uint32_t handle, const SdpProtocolDescriptor *descriptor, uint16_t descriptorNumber)
59919e95205Sopenharmony_ci{
60019e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
60119e95205Sopenharmony_ci
60219e95205Sopenharmony_ci    int ret;
60319e95205Sopenharmony_ci    SdpProtocolDescriptorList *ctx = MEM_MALLOC.alloc(sizeof(SdpProtocolDescriptorList));
60419e95205Sopenharmony_ci    if (ctx == NULL) {
60519e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
60619e95205Sopenharmony_ci        return BT_NO_MEMORY;
60719e95205Sopenharmony_ci    }
60819e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpProtocolDescriptorList), 0x00, sizeof(SdpProtocolDescriptorList));
60919e95205Sopenharmony_ci
61019e95205Sopenharmony_ci    ctx->handle = handle;
61119e95205Sopenharmony_ci    ctx->descriptor = descriptor;
61219e95205Sopenharmony_ci    ctx->descriptorNumber = descriptorNumber;
61319e95205Sopenharmony_ci    ctx->event = EventCreate(true);
61419e95205Sopenharmony_ci
61519e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddProtocolDescriptorListTask, ctx);
61619e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
61719e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
61819e95205Sopenharmony_ci        ret = ctx->result;
61919e95205Sopenharmony_ci    }
62019e95205Sopenharmony_ci
62119e95205Sopenharmony_ci    EventDelete(ctx->event);
62219e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
62319e95205Sopenharmony_ci    return ret;
62419e95205Sopenharmony_ci}
62519e95205Sopenharmony_ci
62619e95205Sopenharmony_cistatic void SdpAddAdditionalProtocolDescriptorListTask(void *context)
62719e95205Sopenharmony_ci{
62819e95205Sopenharmony_ci    SdpAdditionalProtocolDescriptorList *ctx = context;
62919e95205Sopenharmony_ci
63019e95205Sopenharmony_ci    if (ctx == NULL) {
63119e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
63219e95205Sopenharmony_ci        return;
63319e95205Sopenharmony_ci    }
63419e95205Sopenharmony_ci    ctx->result = SdpAddAdditionalProtocolDescriptorList(ctx->handle, ctx->descriptorList, ctx->descriptorListNumber);
63519e95205Sopenharmony_ci    if (ctx->event != NULL) {
63619e95205Sopenharmony_ci        EventSet(ctx->event);
63719e95205Sopenharmony_ci    }
63819e95205Sopenharmony_ci}
63919e95205Sopenharmony_ci
64019e95205Sopenharmony_ciint SDP_AddAdditionalProtocolDescriptorList(
64119e95205Sopenharmony_ci    uint32_t handle, const SdpAdditionalProtocolDescriptor *descriptorList, uint16_t descriptorListNumber)
64219e95205Sopenharmony_ci{
64319e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
64419e95205Sopenharmony_ci
64519e95205Sopenharmony_ci    int ret;
64619e95205Sopenharmony_ci    SdpAdditionalProtocolDescriptorList *ctx = MEM_MALLOC.alloc(sizeof(SdpAdditionalProtocolDescriptorList));
64719e95205Sopenharmony_ci    if (ctx == NULL) {
64819e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
64919e95205Sopenharmony_ci        return BT_NO_MEMORY;
65019e95205Sopenharmony_ci    }
65119e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpAdditionalProtocolDescriptorList), 0x00, sizeof(SdpAdditionalProtocolDescriptorList));
65219e95205Sopenharmony_ci
65319e95205Sopenharmony_ci    ctx->handle = handle;
65419e95205Sopenharmony_ci    ctx->descriptorList = descriptorList;
65519e95205Sopenharmony_ci    ctx->descriptorListNumber = descriptorListNumber;
65619e95205Sopenharmony_ci    ctx->event = EventCreate(true);
65719e95205Sopenharmony_ci
65819e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddAdditionalProtocolDescriptorListTask, ctx);
65919e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
66019e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
66119e95205Sopenharmony_ci        ret = ctx->result;
66219e95205Sopenharmony_ci    }
66319e95205Sopenharmony_ci
66419e95205Sopenharmony_ci    EventDelete(ctx->event);
66519e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
66619e95205Sopenharmony_ci    return ret;
66719e95205Sopenharmony_ci}
66819e95205Sopenharmony_ci
66919e95205Sopenharmony_cistatic void SdpAddBrowseGroupListTask(void *context)
67019e95205Sopenharmony_ci{
67119e95205Sopenharmony_ci    SdpBrowseGroupList *ctx = context;
67219e95205Sopenharmony_ci
67319e95205Sopenharmony_ci    if (ctx == NULL) {
67419e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
67519e95205Sopenharmony_ci        return;
67619e95205Sopenharmony_ci    }
67719e95205Sopenharmony_ci    ctx->result = SdpAddBrowseGroupList(ctx->handle, ctx->browseUuid, ctx->browseUuidNumber);
67819e95205Sopenharmony_ci    if (ctx->event != NULL) {
67919e95205Sopenharmony_ci        EventSet(ctx->event);
68019e95205Sopenharmony_ci    }
68119e95205Sopenharmony_ci}
68219e95205Sopenharmony_ci
68319e95205Sopenharmony_ciint SDP_AddBrowseGroupList(uint32_t handle, const BtUuid *browseUuid, uint16_t browseUuidNumber)
68419e95205Sopenharmony_ci{
68519e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
68619e95205Sopenharmony_ci
68719e95205Sopenharmony_ci    int ret;
68819e95205Sopenharmony_ci    SdpBrowseGroupList *ctx = MEM_MALLOC.alloc(sizeof(SdpBrowseGroupList));
68919e95205Sopenharmony_ci    if (ctx == NULL) {
69019e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
69119e95205Sopenharmony_ci        return BT_NO_MEMORY;
69219e95205Sopenharmony_ci    }
69319e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpBrowseGroupList), 0x00, sizeof(SdpBrowseGroupList));
69419e95205Sopenharmony_ci
69519e95205Sopenharmony_ci    ctx->handle = handle;
69619e95205Sopenharmony_ci    ctx->browseUuid = browseUuid;
69719e95205Sopenharmony_ci    ctx->browseUuidNumber = browseUuidNumber;
69819e95205Sopenharmony_ci    ctx->event = EventCreate(true);
69919e95205Sopenharmony_ci
70019e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddBrowseGroupListTask, ctx);
70119e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
70219e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
70319e95205Sopenharmony_ci        ret = ctx->result;
70419e95205Sopenharmony_ci    }
70519e95205Sopenharmony_ci
70619e95205Sopenharmony_ci    EventDelete(ctx->event);
70719e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
70819e95205Sopenharmony_ci    return ret;
70919e95205Sopenharmony_ci}
71019e95205Sopenharmony_ci
71119e95205Sopenharmony_cistatic void SdpAddLanguageBaseAttributeIdListTask(void *context)
71219e95205Sopenharmony_ci{
71319e95205Sopenharmony_ci    SdpLanguageBaseAttributeIdList *ctx = context;
71419e95205Sopenharmony_ci
71519e95205Sopenharmony_ci    if (ctx == NULL) {
71619e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
71719e95205Sopenharmony_ci        return;
71819e95205Sopenharmony_ci    }
71919e95205Sopenharmony_ci    ctx->result = SdpAddLanguageBaseAttributeIdList(ctx->handle, ctx->baseAttributeId, ctx->baseAttributeIdNumber);
72019e95205Sopenharmony_ci    if (ctx->event != NULL) {
72119e95205Sopenharmony_ci        EventSet(ctx->event);
72219e95205Sopenharmony_ci    }
72319e95205Sopenharmony_ci}
72419e95205Sopenharmony_ci
72519e95205Sopenharmony_ciint SDP_AddLanguageBaseAttributeIdList(
72619e95205Sopenharmony_ci    uint32_t handle, const SdpLanguageBaseAttributeId *baseAttributeId, uint16_t baseAttributeIdNum)
72719e95205Sopenharmony_ci{
72819e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
72919e95205Sopenharmony_ci
73019e95205Sopenharmony_ci    int ret;
73119e95205Sopenharmony_ci    SdpLanguageBaseAttributeIdList *ctx = MEM_MALLOC.alloc(sizeof(SdpLanguageBaseAttributeIdList));
73219e95205Sopenharmony_ci    if (ctx == NULL) {
73319e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
73419e95205Sopenharmony_ci        return BT_NO_MEMORY;
73519e95205Sopenharmony_ci    }
73619e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpLanguageBaseAttributeIdList), 0x00, sizeof(SdpLanguageBaseAttributeIdList));
73719e95205Sopenharmony_ci
73819e95205Sopenharmony_ci    ctx->handle = handle;
73919e95205Sopenharmony_ci    ctx->baseAttributeId = baseAttributeId;
74019e95205Sopenharmony_ci    ctx->baseAttributeIdNumber = baseAttributeIdNum;
74119e95205Sopenharmony_ci    ctx->event = EventCreate(true);
74219e95205Sopenharmony_ci
74319e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddLanguageBaseAttributeIdListTask, ctx);
74419e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
74519e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
74619e95205Sopenharmony_ci        ret = ctx->result;
74719e95205Sopenharmony_ci    }
74819e95205Sopenharmony_ci
74919e95205Sopenharmony_ci    EventDelete(ctx->event);
75019e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
75119e95205Sopenharmony_ci    return ret;
75219e95205Sopenharmony_ci}
75319e95205Sopenharmony_ci
75419e95205Sopenharmony_cistatic void SdpAddServiceInfoTimeToLiveTask(void *context)
75519e95205Sopenharmony_ci{
75619e95205Sopenharmony_ci    SdpServiceInfoTimeToLive *ctx = context;
75719e95205Sopenharmony_ci
75819e95205Sopenharmony_ci    if (ctx == NULL) {
75919e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
76019e95205Sopenharmony_ci        return;
76119e95205Sopenharmony_ci    }
76219e95205Sopenharmony_ci    ctx->result = SdpAddServiceInfoTimeToLive(ctx->handle, ctx->value);
76319e95205Sopenharmony_ci    if (ctx->event != NULL) {
76419e95205Sopenharmony_ci        EventSet(ctx->event);
76519e95205Sopenharmony_ci    }
76619e95205Sopenharmony_ci}
76719e95205Sopenharmony_ci
76819e95205Sopenharmony_ciint SDP_AddServiceInfoTimeToLive(uint32_t handle, uint32_t value)
76919e95205Sopenharmony_ci{
77019e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
77119e95205Sopenharmony_ci
77219e95205Sopenharmony_ci    int ret;
77319e95205Sopenharmony_ci    SdpServiceInfoTimeToLive *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceInfoTimeToLive));
77419e95205Sopenharmony_ci    if (ctx == NULL) {
77519e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
77619e95205Sopenharmony_ci        return BT_NO_MEMORY;
77719e95205Sopenharmony_ci    }
77819e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceInfoTimeToLive), 0x00, sizeof(SdpServiceInfoTimeToLive));
77919e95205Sopenharmony_ci
78019e95205Sopenharmony_ci    ctx->handle = handle;
78119e95205Sopenharmony_ci    ctx->value = value;
78219e95205Sopenharmony_ci    ctx->event = EventCreate(true);
78319e95205Sopenharmony_ci
78419e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceInfoTimeToLiveTask, ctx);
78519e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
78619e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
78719e95205Sopenharmony_ci        ret = ctx->result;
78819e95205Sopenharmony_ci    }
78919e95205Sopenharmony_ci
79019e95205Sopenharmony_ci    EventDelete(ctx->event);
79119e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
79219e95205Sopenharmony_ci    return ret;
79319e95205Sopenharmony_ci}
79419e95205Sopenharmony_ci
79519e95205Sopenharmony_cistatic void SdpAddServiceAvailabilityTask(void *context)
79619e95205Sopenharmony_ci{
79719e95205Sopenharmony_ci    SdpServiceAvailability *ctx = context;
79819e95205Sopenharmony_ci
79919e95205Sopenharmony_ci    if (ctx == NULL) {
80019e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
80119e95205Sopenharmony_ci        return;
80219e95205Sopenharmony_ci    }
80319e95205Sopenharmony_ci    ctx->result = SdpAddServiceAvailability(ctx->handle, ctx->value);
80419e95205Sopenharmony_ci    if (ctx->event != NULL) {
80519e95205Sopenharmony_ci        EventSet(ctx->event);
80619e95205Sopenharmony_ci    }
80719e95205Sopenharmony_ci}
80819e95205Sopenharmony_ci
80919e95205Sopenharmony_ciint SDP_AddServiceAvailability(uint32_t handle, uint8_t value)
81019e95205Sopenharmony_ci{
81119e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
81219e95205Sopenharmony_ci
81319e95205Sopenharmony_ci    int ret;
81419e95205Sopenharmony_ci    SdpServiceAvailability *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceAvailability));
81519e95205Sopenharmony_ci    if (ctx == NULL) {
81619e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
81719e95205Sopenharmony_ci        return BT_NO_MEMORY;
81819e95205Sopenharmony_ci    }
81919e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceAvailability), 0x00, sizeof(SdpServiceAvailability));
82019e95205Sopenharmony_ci
82119e95205Sopenharmony_ci    ctx->handle = handle;
82219e95205Sopenharmony_ci    ctx->value = value;
82319e95205Sopenharmony_ci    ctx->event = EventCreate(true);
82419e95205Sopenharmony_ci
82519e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceAvailabilityTask, ctx);
82619e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
82719e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
82819e95205Sopenharmony_ci        ret = ctx->result;
82919e95205Sopenharmony_ci    }
83019e95205Sopenharmony_ci
83119e95205Sopenharmony_ci    EventDelete(ctx->event);
83219e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
83319e95205Sopenharmony_ci    return ret;
83419e95205Sopenharmony_ci}
83519e95205Sopenharmony_ci
83619e95205Sopenharmony_cistatic void SdpAddBluetoothProfileDescriptorListTask(void *context)
83719e95205Sopenharmony_ci{
83819e95205Sopenharmony_ci    SdpBluetoothProfileDescriptorList *ctx = context;
83919e95205Sopenharmony_ci
84019e95205Sopenharmony_ci    if (ctx == NULL) {
84119e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
84219e95205Sopenharmony_ci        return;
84319e95205Sopenharmony_ci    }
84419e95205Sopenharmony_ci    ctx->result =
84519e95205Sopenharmony_ci        SdpAddBluetoothProfileDescriptorList(ctx->handle, ctx->profileDescriptor, ctx->profileDescriptorNumber);
84619e95205Sopenharmony_ci    if (ctx->event != NULL) {
84719e95205Sopenharmony_ci        EventSet(ctx->event);
84819e95205Sopenharmony_ci    }
84919e95205Sopenharmony_ci}
85019e95205Sopenharmony_ci
85119e95205Sopenharmony_ciint SDP_AddBluetoothProfileDescriptorList(
85219e95205Sopenharmony_ci    uint32_t handle, const SdpProfileDescriptor *profileDescriptor, uint16_t profileDescriptorNum)
85319e95205Sopenharmony_ci{
85419e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
85519e95205Sopenharmony_ci
85619e95205Sopenharmony_ci    int ret;
85719e95205Sopenharmony_ci    SdpBluetoothProfileDescriptorList *ctx = MEM_MALLOC.alloc(sizeof(SdpBluetoothProfileDescriptorList));
85819e95205Sopenharmony_ci    if (ctx == NULL) {
85919e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
86019e95205Sopenharmony_ci        return BT_NO_MEMORY;
86119e95205Sopenharmony_ci    }
86219e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpBluetoothProfileDescriptorList), 0x00, sizeof(SdpBluetoothProfileDescriptorList));
86319e95205Sopenharmony_ci
86419e95205Sopenharmony_ci    ctx->handle = handle;
86519e95205Sopenharmony_ci    ctx->profileDescriptor = profileDescriptor;
86619e95205Sopenharmony_ci    ctx->profileDescriptorNumber = profileDescriptorNum;
86719e95205Sopenharmony_ci    ctx->event = EventCreate(true);
86819e95205Sopenharmony_ci
86919e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddBluetoothProfileDescriptorListTask, ctx);
87019e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
87119e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
87219e95205Sopenharmony_ci        ret = ctx->result;
87319e95205Sopenharmony_ci    }
87419e95205Sopenharmony_ci
87519e95205Sopenharmony_ci    EventDelete(ctx->event);
87619e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
87719e95205Sopenharmony_ci    return ret;
87819e95205Sopenharmony_ci}
87919e95205Sopenharmony_ci
88019e95205Sopenharmony_cistatic void SdpAddDocumentationUrlTask(void *context)
88119e95205Sopenharmony_ci{
88219e95205Sopenharmony_ci    SdpUrl *ctx = context;
88319e95205Sopenharmony_ci
88419e95205Sopenharmony_ci    if (ctx == NULL) {
88519e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
88619e95205Sopenharmony_ci        return;
88719e95205Sopenharmony_ci    }
88819e95205Sopenharmony_ci    ctx->result = SdpAddDocumentationUrl(ctx->handle, ctx->url, ctx->urlLen);
88919e95205Sopenharmony_ci    if (ctx->event != NULL) {
89019e95205Sopenharmony_ci        EventSet(ctx->event);
89119e95205Sopenharmony_ci    }
89219e95205Sopenharmony_ci}
89319e95205Sopenharmony_ci
89419e95205Sopenharmony_ciint SDP_AddDocumentationUrl(uint32_t handle, const uint8_t *url, uint16_t urlLen)
89519e95205Sopenharmony_ci{
89619e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
89719e95205Sopenharmony_ci
89819e95205Sopenharmony_ci    int ret;
89919e95205Sopenharmony_ci    SdpUrl *ctx = MEM_MALLOC.alloc(sizeof(SdpUrl));
90019e95205Sopenharmony_ci    if (ctx == NULL) {
90119e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
90219e95205Sopenharmony_ci        return BT_NO_MEMORY;
90319e95205Sopenharmony_ci    }
90419e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpUrl), 0x00, sizeof(SdpUrl));
90519e95205Sopenharmony_ci
90619e95205Sopenharmony_ci    ctx->handle = handle;
90719e95205Sopenharmony_ci    ctx->url = url;
90819e95205Sopenharmony_ci    ctx->urlLen = urlLen;
90919e95205Sopenharmony_ci    ctx->event = EventCreate(true);
91019e95205Sopenharmony_ci
91119e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddDocumentationUrlTask, ctx);
91219e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
91319e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
91419e95205Sopenharmony_ci        ret = ctx->result;
91519e95205Sopenharmony_ci    }
91619e95205Sopenharmony_ci
91719e95205Sopenharmony_ci    EventDelete(ctx->event);
91819e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
91919e95205Sopenharmony_ci    return ret;
92019e95205Sopenharmony_ci}
92119e95205Sopenharmony_ci
92219e95205Sopenharmony_cistatic void SdpAddClientExecutableUrlTask(void *context)
92319e95205Sopenharmony_ci{
92419e95205Sopenharmony_ci    SdpUrl *ctx = context;
92519e95205Sopenharmony_ci
92619e95205Sopenharmony_ci    if (ctx == NULL) {
92719e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
92819e95205Sopenharmony_ci        return;
92919e95205Sopenharmony_ci    }
93019e95205Sopenharmony_ci    ctx->result = SdpAddClientExecutableUrl(ctx->handle, ctx->url, ctx->urlLen);
93119e95205Sopenharmony_ci    if (ctx->event != NULL) {
93219e95205Sopenharmony_ci        EventSet(ctx->event);
93319e95205Sopenharmony_ci    }
93419e95205Sopenharmony_ci}
93519e95205Sopenharmony_ci
93619e95205Sopenharmony_ciint SDP_AddClientExecutableUrl(uint32_t handle, const uint8_t *url, uint16_t urlLen)
93719e95205Sopenharmony_ci{
93819e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
93919e95205Sopenharmony_ci
94019e95205Sopenharmony_ci    int ret;
94119e95205Sopenharmony_ci    SdpUrl *ctx = MEM_MALLOC.alloc(sizeof(SdpUrl));
94219e95205Sopenharmony_ci    if (ctx == NULL) {
94319e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
94419e95205Sopenharmony_ci        return BT_NO_MEMORY;
94519e95205Sopenharmony_ci    }
94619e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpUrl), 0x00, sizeof(SdpUrl));
94719e95205Sopenharmony_ci
94819e95205Sopenharmony_ci    ctx->handle = handle;
94919e95205Sopenharmony_ci    ctx->url = url;
95019e95205Sopenharmony_ci    ctx->urlLen = urlLen;
95119e95205Sopenharmony_ci    ctx->event = EventCreate(true);
95219e95205Sopenharmony_ci
95319e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddClientExecutableUrlTask, ctx);
95419e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
95519e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
95619e95205Sopenharmony_ci        ret = ctx->result;
95719e95205Sopenharmony_ci    }
95819e95205Sopenharmony_ci
95919e95205Sopenharmony_ci    EventDelete(ctx->event);
96019e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
96119e95205Sopenharmony_ci    return ret;
96219e95205Sopenharmony_ci}
96319e95205Sopenharmony_ci
96419e95205Sopenharmony_cistatic void SdpAddIconUrlTask(void *context)
96519e95205Sopenharmony_ci{
96619e95205Sopenharmony_ci    SdpUrl *ctx = context;
96719e95205Sopenharmony_ci
96819e95205Sopenharmony_ci    if (ctx == NULL) {
96919e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
97019e95205Sopenharmony_ci        return;
97119e95205Sopenharmony_ci    }
97219e95205Sopenharmony_ci    ctx->result = SdpAddIconUrl(ctx->handle, ctx->url, ctx->urlLen);
97319e95205Sopenharmony_ci    if (ctx->event != NULL) {
97419e95205Sopenharmony_ci        EventSet(ctx->event);
97519e95205Sopenharmony_ci    }
97619e95205Sopenharmony_ci}
97719e95205Sopenharmony_ci
97819e95205Sopenharmony_ciint SDP_AddIconUrl(uint32_t handle, const uint8_t *url, uint16_t urlLen)
97919e95205Sopenharmony_ci{
98019e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
98119e95205Sopenharmony_ci
98219e95205Sopenharmony_ci    int ret;
98319e95205Sopenharmony_ci    SdpUrl *ctx = MEM_MALLOC.alloc(sizeof(SdpUrl));
98419e95205Sopenharmony_ci    if (ctx == NULL) {
98519e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
98619e95205Sopenharmony_ci        return BT_NO_MEMORY;
98719e95205Sopenharmony_ci    }
98819e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpUrl), 0x00, sizeof(SdpUrl));
98919e95205Sopenharmony_ci
99019e95205Sopenharmony_ci    ctx->handle = handle;
99119e95205Sopenharmony_ci    ctx->url = url;
99219e95205Sopenharmony_ci    ctx->urlLen = urlLen;
99319e95205Sopenharmony_ci    ctx->event = EventCreate(true);
99419e95205Sopenharmony_ci
99519e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddIconUrlTask, ctx);
99619e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
99719e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
99819e95205Sopenharmony_ci        ret = ctx->result;
99919e95205Sopenharmony_ci    }
100019e95205Sopenharmony_ci
100119e95205Sopenharmony_ci    EventDelete(ctx->event);
100219e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
100319e95205Sopenharmony_ci    return ret;
100419e95205Sopenharmony_ci}
100519e95205Sopenharmony_ci
100619e95205Sopenharmony_cistatic void SdpAddServiceNameTask(void *context)
100719e95205Sopenharmony_ci{
100819e95205Sopenharmony_ci    SdpName *ctx = context;
100919e95205Sopenharmony_ci
101019e95205Sopenharmony_ci    if (ctx == NULL) {
101119e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
101219e95205Sopenharmony_ci        return;
101319e95205Sopenharmony_ci    }
101419e95205Sopenharmony_ci    ctx->result = SdpAddServiceName(ctx->handle, ctx->baseAttributeId, ctx->name, ctx->nameLen);
101519e95205Sopenharmony_ci    if (ctx->event != NULL) {
101619e95205Sopenharmony_ci        EventSet(ctx->event);
101719e95205Sopenharmony_ci    }
101819e95205Sopenharmony_ci}
101919e95205Sopenharmony_ci
102019e95205Sopenharmony_ciint SDP_AddServiceName(uint32_t handle, uint16_t baseAttributeId, const char *name, uint16_t nameLen)
102119e95205Sopenharmony_ci{
102219e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
102319e95205Sopenharmony_ci
102419e95205Sopenharmony_ci    int ret;
102519e95205Sopenharmony_ci    SdpName *ctx = MEM_MALLOC.alloc(sizeof(SdpName));
102619e95205Sopenharmony_ci    if (ctx == NULL) {
102719e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
102819e95205Sopenharmony_ci        return BT_NO_MEMORY;
102919e95205Sopenharmony_ci    }
103019e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpName), 0x00, sizeof(SdpName));
103119e95205Sopenharmony_ci
103219e95205Sopenharmony_ci    ctx->handle = handle;
103319e95205Sopenharmony_ci    ctx->baseAttributeId = baseAttributeId;
103419e95205Sopenharmony_ci    ctx->name = name;
103519e95205Sopenharmony_ci    ctx->nameLen = nameLen;
103619e95205Sopenharmony_ci    ctx->event = EventCreate(true);
103719e95205Sopenharmony_ci
103819e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceNameTask, ctx);
103919e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
104019e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
104119e95205Sopenharmony_ci        ret = ctx->result;
104219e95205Sopenharmony_ci    }
104319e95205Sopenharmony_ci
104419e95205Sopenharmony_ci    EventDelete(ctx->event);
104519e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
104619e95205Sopenharmony_ci    return ret;
104719e95205Sopenharmony_ci}
104819e95205Sopenharmony_ci
104919e95205Sopenharmony_cistatic void SdpAddServiceDescriptionTask(void *context)
105019e95205Sopenharmony_ci{
105119e95205Sopenharmony_ci    SdpName *ctx = context;
105219e95205Sopenharmony_ci
105319e95205Sopenharmony_ci    if (ctx == NULL) {
105419e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
105519e95205Sopenharmony_ci        return;
105619e95205Sopenharmony_ci    }
105719e95205Sopenharmony_ci    ctx->result = SdpAddServiceDescription(ctx->handle, ctx->baseAttributeId, ctx->name, ctx->nameLen);
105819e95205Sopenharmony_ci    if (ctx->event != NULL) {
105919e95205Sopenharmony_ci        EventSet(ctx->event);
106019e95205Sopenharmony_ci    }
106119e95205Sopenharmony_ci}
106219e95205Sopenharmony_ci
106319e95205Sopenharmony_ciint SDP_AddServiceDescription(
106419e95205Sopenharmony_ci    uint32_t handle, uint16_t baseAttributeId, const char *description, uint16_t descriptionLen)
106519e95205Sopenharmony_ci{
106619e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
106719e95205Sopenharmony_ci
106819e95205Sopenharmony_ci    int ret;
106919e95205Sopenharmony_ci    SdpName *ctx = MEM_MALLOC.alloc(sizeof(SdpName));
107019e95205Sopenharmony_ci    if (ctx == NULL) {
107119e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
107219e95205Sopenharmony_ci        return BT_NO_MEMORY;
107319e95205Sopenharmony_ci    }
107419e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpName), 0x00, sizeof(SdpName));
107519e95205Sopenharmony_ci
107619e95205Sopenharmony_ci    ctx->handle = handle;
107719e95205Sopenharmony_ci    ctx->name = description;
107819e95205Sopenharmony_ci    ctx->nameLen = descriptionLen;
107919e95205Sopenharmony_ci    ctx->baseAttributeId = baseAttributeId;
108019e95205Sopenharmony_ci    ctx->event = EventCreate(true);
108119e95205Sopenharmony_ci
108219e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddServiceDescriptionTask, ctx);
108319e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
108419e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
108519e95205Sopenharmony_ci        ret = ctx->result;
108619e95205Sopenharmony_ci    }
108719e95205Sopenharmony_ci
108819e95205Sopenharmony_ci    EventDelete(ctx->event);
108919e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
109019e95205Sopenharmony_ci    return ret;
109119e95205Sopenharmony_ci}
109219e95205Sopenharmony_ci
109319e95205Sopenharmony_cistatic void SdpAddProviderNameTask(void *context)
109419e95205Sopenharmony_ci{
109519e95205Sopenharmony_ci    SdpName *ctx = context;
109619e95205Sopenharmony_ci
109719e95205Sopenharmony_ci    if (ctx == NULL) {
109819e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
109919e95205Sopenharmony_ci        return;
110019e95205Sopenharmony_ci    }
110119e95205Sopenharmony_ci    ctx->result = SdpAddProviderName(ctx->handle, ctx->baseAttributeId, ctx->name, ctx->nameLen);
110219e95205Sopenharmony_ci    if (ctx->event != NULL) {
110319e95205Sopenharmony_ci        EventSet(ctx->event);
110419e95205Sopenharmony_ci    }
110519e95205Sopenharmony_ci}
110619e95205Sopenharmony_ci
110719e95205Sopenharmony_ciint SDP_AddProviderName(uint32_t handle, uint16_t baseAttributeId, const char *name, uint16_t nameLen)
110819e95205Sopenharmony_ci{
110919e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
111019e95205Sopenharmony_ci
111119e95205Sopenharmony_ci    int ret;
111219e95205Sopenharmony_ci    SdpName *ctx = MEM_MALLOC.alloc(sizeof(SdpName));
111319e95205Sopenharmony_ci    if (ctx == NULL) {
111419e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
111519e95205Sopenharmony_ci        return BT_NO_MEMORY;
111619e95205Sopenharmony_ci    }
111719e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpName), 0x00, sizeof(SdpName));
111819e95205Sopenharmony_ci
111919e95205Sopenharmony_ci    ctx->handle = handle;
112019e95205Sopenharmony_ci    ctx->name = name;
112119e95205Sopenharmony_ci    ctx->nameLen = nameLen;
112219e95205Sopenharmony_ci    ctx->baseAttributeId = baseAttributeId;
112319e95205Sopenharmony_ci    ctx->event = EventCreate(true);
112419e95205Sopenharmony_ci
112519e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddProviderNameTask, ctx);
112619e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
112719e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
112819e95205Sopenharmony_ci        ret = ctx->result;
112919e95205Sopenharmony_ci    }
113019e95205Sopenharmony_ci
113119e95205Sopenharmony_ci    EventDelete(ctx->event);
113219e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
113319e95205Sopenharmony_ci    return ret;
113419e95205Sopenharmony_ci}
113519e95205Sopenharmony_ci
113619e95205Sopenharmony_cistatic void SdpAddAttributeTask(void *context)
113719e95205Sopenharmony_ci{
113819e95205Sopenharmony_ci    SdpAttributeInfo *ctx = context;
113919e95205Sopenharmony_ci
114019e95205Sopenharmony_ci    if (ctx == NULL) {
114119e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
114219e95205Sopenharmony_ci        return;
114319e95205Sopenharmony_ci    }
114419e95205Sopenharmony_ci    ctx->result =
114519e95205Sopenharmony_ci        SdpAddAttribute(ctx->handle, ctx->attributeId, ctx->type, ctx->attributeValue, ctx->attributeValueLength);
114619e95205Sopenharmony_ci    if (ctx->event != NULL) {
114719e95205Sopenharmony_ci        EventSet(ctx->event);
114819e95205Sopenharmony_ci    }
114919e95205Sopenharmony_ci}
115019e95205Sopenharmony_ci
115119e95205Sopenharmony_ciint SDP_AddAttribute(
115219e95205Sopenharmony_ci    uint32_t handle, uint16_t attributeId, SdpDataType type, void *attributeValue, uint16_t attributeValueLength)
115319e95205Sopenharmony_ci{
115419e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
115519e95205Sopenharmony_ci
115619e95205Sopenharmony_ci    int ret;
115719e95205Sopenharmony_ci    SdpAttributeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpAttributeInfo));
115819e95205Sopenharmony_ci    if (ctx == NULL) {
115919e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
116019e95205Sopenharmony_ci        return BT_NO_MEMORY;
116119e95205Sopenharmony_ci    }
116219e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpAttributeInfo), 0x00, sizeof(SdpAttributeInfo));
116319e95205Sopenharmony_ci
116419e95205Sopenharmony_ci    ctx->handle = handle;
116519e95205Sopenharmony_ci    ctx->attributeId = attributeId;
116619e95205Sopenharmony_ci    ctx->type = type;
116719e95205Sopenharmony_ci    ctx->attributeValue = attributeValue;
116819e95205Sopenharmony_ci    ctx->attributeValueLength = attributeValueLength;
116919e95205Sopenharmony_ci    ctx->event = EventCreate(true);
117019e95205Sopenharmony_ci
117119e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddAttributeTask, ctx);
117219e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
117319e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
117419e95205Sopenharmony_ci        ret = ctx->result;
117519e95205Sopenharmony_ci    }
117619e95205Sopenharmony_ci
117719e95205Sopenharmony_ci    EventDelete(ctx->event);
117819e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
117919e95205Sopenharmony_ci    return ret;
118019e95205Sopenharmony_ci}
118119e95205Sopenharmony_ci
118219e95205Sopenharmony_cistatic void SdpAddSequenceAttributeTask(void *context)
118319e95205Sopenharmony_ci{
118419e95205Sopenharmony_ci    SdpSequenceAttributeInfo *ctx = context;
118519e95205Sopenharmony_ci
118619e95205Sopenharmony_ci    if (ctx == NULL) {
118719e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
118819e95205Sopenharmony_ci        return;
118919e95205Sopenharmony_ci    }
119019e95205Sopenharmony_ci    ctx->result =
119119e95205Sopenharmony_ci        SdpAddSequenceAttribute(ctx->handle, ctx->attributeId, ctx->attributeValue, ctx->attributeValueLength);
119219e95205Sopenharmony_ci    if (ctx->event != NULL) {
119319e95205Sopenharmony_ci        EventSet(ctx->event);
119419e95205Sopenharmony_ci    }
119519e95205Sopenharmony_ci}
119619e95205Sopenharmony_ci
119719e95205Sopenharmony_ciint SDP_AddSequenceAttribute(
119819e95205Sopenharmony_ci    uint32_t handle, uint16_t attributeId, const uint8_t *attributeValue, uint16_t attributeValueLength)
119919e95205Sopenharmony_ci{
120019e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
120119e95205Sopenharmony_ci
120219e95205Sopenharmony_ci    int ret;
120319e95205Sopenharmony_ci    SdpSequenceAttributeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpSequenceAttributeInfo));
120419e95205Sopenharmony_ci    if (ctx == NULL) {
120519e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
120619e95205Sopenharmony_ci        return BT_NO_MEMORY;
120719e95205Sopenharmony_ci    }
120819e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpSequenceAttributeInfo), 0x00, sizeof(SdpSequenceAttributeInfo));
120919e95205Sopenharmony_ci
121019e95205Sopenharmony_ci    ctx->handle = handle;
121119e95205Sopenharmony_ci    ctx->attributeId = attributeId;
121219e95205Sopenharmony_ci    ctx->attributeValue = attributeValue;
121319e95205Sopenharmony_ci    ctx->attributeValueLength = attributeValueLength;
121419e95205Sopenharmony_ci    ctx->event = EventCreate(true);
121519e95205Sopenharmony_ci
121619e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpAddSequenceAttributeTask, ctx);
121719e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
121819e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
121919e95205Sopenharmony_ci        ret = ctx->result;
122019e95205Sopenharmony_ci    }
122119e95205Sopenharmony_ci
122219e95205Sopenharmony_ci    EventDelete(ctx->event);
122319e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
122419e95205Sopenharmony_ci    return ret;
122519e95205Sopenharmony_ci}
122619e95205Sopenharmony_ci
122719e95205Sopenharmony_cistatic void SdpServiceSearchTask(void *context)
122819e95205Sopenharmony_ci{
122919e95205Sopenharmony_ci    SdpServiceSearchInfo *ctx = context;
123019e95205Sopenharmony_ci
123119e95205Sopenharmony_ci    if (ctx == NULL) {
123219e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
123319e95205Sopenharmony_ci        return;
123419e95205Sopenharmony_ci    }
123519e95205Sopenharmony_ci    ctx->result = SdpServiceSearch(&ctx->addr, &ctx->uuidArray, ctx->context, ctx->ServiceSearchCb);
123619e95205Sopenharmony_ci    if (ctx->event != NULL) {
123719e95205Sopenharmony_ci        EventSet(ctx->event);
123819e95205Sopenharmony_ci    }
123919e95205Sopenharmony_ci}
124019e95205Sopenharmony_ci
124119e95205Sopenharmony_ciint SDP_ServiceSearch(const BtAddr *addr, const SdpUuid *uuidArray, void *context,
124219e95205Sopenharmony_ci    void (*serviceSearchCb)(const BtAddr *addr, const uint32_t *handleArray, uint16_t handleNum, void *context))
124319e95205Sopenharmony_ci{
124419e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
124519e95205Sopenharmony_ci
124619e95205Sopenharmony_ci    int ret;
124719e95205Sopenharmony_ci    SdpServiceSearchInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceSearchInfo));
124819e95205Sopenharmony_ci    if (ctx == NULL) {
124919e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
125019e95205Sopenharmony_ci        return BT_NO_MEMORY;
125119e95205Sopenharmony_ci    }
125219e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceSearchInfo), 0x00, sizeof(SdpServiceSearchInfo));
125319e95205Sopenharmony_ci
125419e95205Sopenharmony_ci    (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr));
125519e95205Sopenharmony_ci    (void)memcpy_s(&ctx->uuidArray, sizeof(SdpUuid), uuidArray, sizeof(SdpUuid));
125619e95205Sopenharmony_ci    ctx->context = context;
125719e95205Sopenharmony_ci    ctx->ServiceSearchCb = serviceSearchCb;
125819e95205Sopenharmony_ci    ctx->event = EventCreate(true);
125919e95205Sopenharmony_ci
126019e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpServiceSearchTask, ctx);
126119e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
126219e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
126319e95205Sopenharmony_ci        ret = ctx->result;
126419e95205Sopenharmony_ci    }
126519e95205Sopenharmony_ci
126619e95205Sopenharmony_ci    EventDelete(ctx->event);
126719e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
126819e95205Sopenharmony_ci    return ret;
126919e95205Sopenharmony_ci}
127019e95205Sopenharmony_ci
127119e95205Sopenharmony_cistatic void SdpServiceAttributeTask(void *context)
127219e95205Sopenharmony_ci{
127319e95205Sopenharmony_ci    SdpServiceAttributeInfo *ctx = context;
127419e95205Sopenharmony_ci
127519e95205Sopenharmony_ci    if (ctx == NULL) {
127619e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
127719e95205Sopenharmony_ci        return;
127819e95205Sopenharmony_ci    }
127919e95205Sopenharmony_ci    ctx->result =
128019e95205Sopenharmony_ci        SdpServiceAttribute(&ctx->addr, ctx->handle, ctx->attributeIdList, ctx->context, ctx->ServiceAttributeCb);
128119e95205Sopenharmony_ci    if (ctx->event != NULL) {
128219e95205Sopenharmony_ci        EventSet(ctx->event);
128319e95205Sopenharmony_ci    }
128419e95205Sopenharmony_ci}
128519e95205Sopenharmony_ci
128619e95205Sopenharmony_ciint SDP_ServiceAttribute(const BtAddr *addr, uint32_t handle, SdpAttributeIdList attributeIdList, void *context,
128719e95205Sopenharmony_ci    void (*serviceAttributeCb)(const BtAddr *addr, const SdpService *service, void *context))
128819e95205Sopenharmony_ci{
128919e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
129019e95205Sopenharmony_ci
129119e95205Sopenharmony_ci    int ret;
129219e95205Sopenharmony_ci    SdpServiceAttributeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceAttributeInfo));
129319e95205Sopenharmony_ci    if (ctx == NULL) {
129419e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
129519e95205Sopenharmony_ci        return BT_NO_MEMORY;
129619e95205Sopenharmony_ci    }
129719e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceAttributeInfo), 0x00, sizeof(SdpServiceAttributeInfo));
129819e95205Sopenharmony_ci
129919e95205Sopenharmony_ci    (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr));
130019e95205Sopenharmony_ci    ctx->handle = handle;
130119e95205Sopenharmony_ci    (void)memcpy_s(&ctx->attributeIdList, sizeof(SdpAttributeIdList), &attributeIdList, sizeof(SdpAttributeIdList));
130219e95205Sopenharmony_ci    ctx->context = context;
130319e95205Sopenharmony_ci    ctx->ServiceAttributeCb = serviceAttributeCb;
130419e95205Sopenharmony_ci    ctx->event = EventCreate(true);
130519e95205Sopenharmony_ci
130619e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpServiceAttributeTask, ctx);
130719e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
130819e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
130919e95205Sopenharmony_ci        ret = ctx->result;
131019e95205Sopenharmony_ci    }
131119e95205Sopenharmony_ci
131219e95205Sopenharmony_ci    EventDelete(ctx->event);
131319e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
131419e95205Sopenharmony_ci    return ret;
131519e95205Sopenharmony_ci}
131619e95205Sopenharmony_ci
131719e95205Sopenharmony_cistatic void SdpServiceSearchAttributeTask(void *context)
131819e95205Sopenharmony_ci{
131919e95205Sopenharmony_ci    SdpServiceSearchAttributeInfo *ctx = context;
132019e95205Sopenharmony_ci
132119e95205Sopenharmony_ci    if (ctx == NULL) {
132219e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
132319e95205Sopenharmony_ci        return;
132419e95205Sopenharmony_ci    }
132519e95205Sopenharmony_ci    ctx->result = SdpServiceSearchAttribute(
132619e95205Sopenharmony_ci        &ctx->addr, &ctx->uuidArray, ctx->attributeIdList, ctx->context, ctx->ServiceSearchAttributeCb);
132719e95205Sopenharmony_ci    if (ctx->event != NULL) {
132819e95205Sopenharmony_ci        EventSet(ctx->event);
132919e95205Sopenharmony_ci    }
133019e95205Sopenharmony_ci}
133119e95205Sopenharmony_ci
133219e95205Sopenharmony_ciint SDP_ServiceSearchAttribute(const BtAddr *addr, const SdpUuid *uuidArray, SdpAttributeIdList attributeIdList,
133319e95205Sopenharmony_ci    void *context,
133419e95205Sopenharmony_ci    void (*searchAttributeCb)(const BtAddr *addr, const SdpService *serviceArray, uint16_t serviceNum, void *context))
133519e95205Sopenharmony_ci{
133619e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
133719e95205Sopenharmony_ci
133819e95205Sopenharmony_ci    int ret;
133919e95205Sopenharmony_ci    SdpServiceSearchAttributeInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceSearchAttributeInfo));
134019e95205Sopenharmony_ci    if (ctx == NULL) {
134119e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
134219e95205Sopenharmony_ci        return BT_NO_MEMORY;
134319e95205Sopenharmony_ci    }
134419e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceSearchAttributeInfo), 0x00, sizeof(SdpServiceSearchAttributeInfo));
134519e95205Sopenharmony_ci
134619e95205Sopenharmony_ci    (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr));
134719e95205Sopenharmony_ci    (void)memcpy_s(&ctx->uuidArray, sizeof(SdpUuid), uuidArray, sizeof(SdpUuid));
134819e95205Sopenharmony_ci    (void)memcpy_s(&ctx->attributeIdList, sizeof(SdpAttributeIdList), &attributeIdList, sizeof(SdpAttributeIdList));
134919e95205Sopenharmony_ci    ctx->context = context;
135019e95205Sopenharmony_ci    ctx->ServiceSearchAttributeCb = searchAttributeCb;
135119e95205Sopenharmony_ci    ctx->event = EventCreate(true);
135219e95205Sopenharmony_ci
135319e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpServiceSearchAttributeTask, ctx);
135419e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
135519e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
135619e95205Sopenharmony_ci        ret = ctx->result;
135719e95205Sopenharmony_ci    }
135819e95205Sopenharmony_ci
135919e95205Sopenharmony_ci    EventDelete(ctx->event);
136019e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
136119e95205Sopenharmony_ci    return ret;
136219e95205Sopenharmony_ci}
136319e95205Sopenharmony_ci
136419e95205Sopenharmony_cistatic void SdpServiceBrowseTask(void *context)
136519e95205Sopenharmony_ci{
136619e95205Sopenharmony_ci    SdpServiceBrowseInfo *ctx = context;
136719e95205Sopenharmony_ci
136819e95205Sopenharmony_ci    if (ctx == NULL) {
136919e95205Sopenharmony_ci        LOG_ERROR("[%{public}s][%{public}d] context is NULL ", __FUNCTION__, __LINE__);
137019e95205Sopenharmony_ci        return;
137119e95205Sopenharmony_ci    }
137219e95205Sopenharmony_ci    ctx->result = SdpServiceBrowse(&ctx->addr, ctx->context, ctx->ServiceBrowseCb);
137319e95205Sopenharmony_ci    if (ctx->event != NULL) {
137419e95205Sopenharmony_ci        EventSet(ctx->event);
137519e95205Sopenharmony_ci    }
137619e95205Sopenharmony_ci}
137719e95205Sopenharmony_ci
137819e95205Sopenharmony_ciint SDP_ServiceBrowse(const BtAddr *addr, void *context,
137919e95205Sopenharmony_ci    void (*serviceBrowseCb)(const BtAddr *addr, const uint32_t *handleArray, uint16_t handleNum, void *context))
138019e95205Sopenharmony_ci{
138119e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
138219e95205Sopenharmony_ci
138319e95205Sopenharmony_ci    int ret;
138419e95205Sopenharmony_ci    SdpServiceBrowseInfo *ctx = MEM_MALLOC.alloc(sizeof(SdpServiceBrowseInfo));
138519e95205Sopenharmony_ci    if (ctx == NULL) {
138619e95205Sopenharmony_ci        LOG_ERROR("point to NULL");
138719e95205Sopenharmony_ci        return BT_NO_MEMORY;
138819e95205Sopenharmony_ci    }
138919e95205Sopenharmony_ci    (void)memset_s(ctx, sizeof(SdpServiceBrowseInfo), 0x00, sizeof(SdpServiceBrowseInfo));
139019e95205Sopenharmony_ci
139119e95205Sopenharmony_ci    (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr));
139219e95205Sopenharmony_ci    ctx->context = context;
139319e95205Sopenharmony_ci    ctx->ServiceBrowseCb = serviceBrowseCb;
139419e95205Sopenharmony_ci    ctx->event = EventCreate(true);
139519e95205Sopenharmony_ci
139619e95205Sopenharmony_ci    ret = BTM_RunTaskInProcessingQueue(PROCESSING_QUEUE_ID_SDP, SdpServiceBrowseTask, ctx);
139719e95205Sopenharmony_ci    if (ret == BT_SUCCESS) {
139819e95205Sopenharmony_ci        EventWait(ctx->event, WAIT_TIME);
139919e95205Sopenharmony_ci        ret = ctx->result;
140019e95205Sopenharmony_ci    }
140119e95205Sopenharmony_ci
140219e95205Sopenharmony_ci    EventDelete(ctx->event);
140319e95205Sopenharmony_ci    MEM_MALLOC.free(ctx);
140419e95205Sopenharmony_ci    return ret;
140519e95205Sopenharmony_ci}
140619e95205Sopenharmony_ci
140719e95205Sopenharmony_cistatic void SdpInitialize(int traceLevel)
140819e95205Sopenharmony_ci{
140919e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
141019e95205Sopenharmony_ci    return;
141119e95205Sopenharmony_ci}
141219e95205Sopenharmony_ci
141319e95205Sopenharmony_cistatic void SdpFinalize()
141419e95205Sopenharmony_ci{
141519e95205Sopenharmony_ci    LOG_INFO("%{public}s enter", __FUNCTION__);
141619e95205Sopenharmony_ci    return;
141719e95205Sopenharmony_ci}
141819e95205Sopenharmony_ci
141919e95205Sopenharmony_ciModule g_sdp = {
142019e95205Sopenharmony_ci    .name = MODULE_NAME_SDP,
142119e95205Sopenharmony_ci    .init = SdpInitialize,
142219e95205Sopenharmony_ci    .startup = SdpStartup,
142319e95205Sopenharmony_ci    .shutdown = SdpShutdown,
142419e95205Sopenharmony_ci    .cleanup = SdpFinalize,
142519e95205Sopenharmony_ci    .dependencies = {MODULE_NAME_L2CAP},
142619e95205Sopenharmony_ci};
142719e95205Sopenharmony_ci
142819e95205Sopenharmony_ciMODULE_DECL(g_sdp)
1429