• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gap.h"
17 #include "gap_def.h"
18 #include "gap_task_internal.h"
19 
20 #include <securec.h>
21 
22 #include "allocator.h"
23 #include "log.h"
24 
25 #include "btm/btm_thread.h"
26 
27 typedef struct {
28     int result;
29     char *name;
30     int length;
31 } GapSetLocalNameInfo;
32 
33 typedef struct {
34     int result;
35     uint32_t cod;
36 } GapSetClassOfDeviceInfo;
37 
38 typedef struct {
39     int result;
40     uint8_t *eir;
41 } GapSetExtendedInquiryResponseInfo;
42 
43 typedef struct {
44     int result;
45     GapDiscoverModeInfo discoverInfo;
46     GapConnectableModeInfo connectableInfo;
47     GapSetScanModeResultCallback callback;
48     void *context;
49 } GapSetScanModeInfo;
50 
51 typedef struct {
52     int result;
53     uint8_t isBondable;
54 } GapSetBondableModeInfo;
55 
56 typedef struct {
57     int result;
58     BtAddr *addr;
59     GapServiceSecurityInfo serviceInfo;
60     uint16_t securityMode;
61 } GapRegisterServiceSecurityInfo;
62 
63 typedef struct {
64     int result;
65     BtAddr *addr;
66     GapServiceSecurityInfo serviceInfo;
67 } GapDeregisterServiceSecurityInfo;
68 
69 typedef struct {
70     int result;
71     BtAddr addr;
72     GapRequestSecurityParam param;
73 } GapRequestSecurityInfo;
74 
75 typedef struct {
76     int result;
77     GAP_SecurityMode mode;
78 } GapSetSecurityModeInfo;
79 
80 typedef struct {
81     int result;
82     BtAddr *addr;
83     GAP_Service service;
84     uint8_t accept;
85 } GapAuthorizeResInfo;
86 
87 typedef struct {
88     int result;
89     BtAddr *addr;
90     bool *isLocal;
91 } GapPairIsFromLocalInfo;
92 
93 typedef struct {
94     int result;
95     BtAddr *addr;
96     uint8_t accept;
97     uint8_t ioCapability;
98     uint8_t oobDataPresent;
99     uint8_t authReq;
100 } GapIOCapabilityRspInfo;
101 
102 typedef struct {
103     int result;
104     BtAddr *addr;
105     uint8_t accept;
106 } GapUserConfirmRspInfo;
107 
108 typedef struct {
109     int result;
110     BtAddr *addr;
111     uint8_t accept;
112     uint32_t number;
113 } GapUserPasskeyRspInfo;
114 
115 typedef struct {
116     int result;
117     BtAddr *addr;
118     uint8_t accept;
119     GapOOBData *data;
120 } GapRemoteOobRspInfo;
121 
122 typedef struct {
123     int result;
124     BtAddr *addr;
125     uint8_t accept;
126     GapOOBData *data192;
127     GapOOBData *data256;
128 } GapRemoteExtandedOobRspInfo;
129 
130 typedef struct {
131     int result;
132     BtAddr *addr;
133     uint8_t accept;
134     uint8_t *pinCode;
135     uint8_t pinCodeLength;
136 } GapPinCodeRspInfo;
137 
138 typedef struct {
139     int result;
140     BtAddr *addr;
141     uint8_t accept;
142     uint8_t *linkKey;
143     uint8_t keyType;
144 } GapLinkKeyRspInfo;
145 
146 typedef struct {
147     int result;
148     BtAddr *addr;
149     uint8_t status;
150     GapEncryptionChangeCallback callback;
151     void *context;
152 } GapSetEncryptionInfo;
153 
154 typedef struct {
155     int result;
156     GapOOBData *data192;
157     GapOOBData *data256;
158 } GapGetLocalExtendedOOBDataInfo;
159 
160 typedef struct {
161     int result;
162     uint8_t mode;
163     uint8_t inquiryLength;
164 } GapInquiryInfo;
165 
166 typedef struct {
167     int result;
168     bool retry;
169 } GapSetKeyMissingRetryInfo;
170 
171 #ifdef GAP_BREDR_SUPPORT
172 
GapSetLocalNameTask(void * ctx)173 static void GapSetLocalNameTask(void *ctx)
174 {
175     GapSetLocalNameInfo *info = ctx;
176     info->result = GAP_SetLocalName(info->name, info->length);
177 }
178 
GAPIF_SetLocalName(const char * name,int length)179 int GAPIF_SetLocalName(const char *name, int length)
180 {
181     LOG_INFO("%{public}s: ", __FUNCTION__);
182     GapSetLocalNameInfo *ctx = MEM_MALLOC.alloc(sizeof(GapSetLocalNameInfo));
183     if (ctx == NULL) {
184         return BT_NO_MEMORY;
185     }
186 
187     (void)memset_s(ctx, sizeof(GapSetLocalNameInfo), 0x00, sizeof(GapSetLocalNameInfo));
188 
189     ctx->name = (char *)name;
190     ctx->length = length;
191 
192     int ret = GapRunTaskBlockProcess(GapSetLocalNameTask, ctx);
193     if (ret == BT_NO_ERROR) {
194         ret = ctx->result;
195     }
196 
197     MEM_MALLOC.free(ctx);
198     return ret;
199 }
200 
GapSetClassOfDeviceTask(void * ctx)201 static void GapSetClassOfDeviceTask(void *ctx)
202 {
203     GapSetClassOfDeviceInfo *info = ctx;
204     info->result = GAP_SetClassOfDevice(info->cod);
205 }
206 
GAPIF_SetClassOfDevice(uint32_t cod)207 int GAPIF_SetClassOfDevice(uint32_t cod)
208 {
209     LOG_INFO("%{public}s: ", __FUNCTION__);
210     GapSetClassOfDeviceInfo *ctx = MEM_MALLOC.alloc(sizeof(GapSetClassOfDeviceInfo));
211     if (ctx == NULL) {
212         return BT_NO_MEMORY;
213     }
214 
215     (void)memset_s(ctx, sizeof(GapSetClassOfDeviceInfo), 0x00, sizeof(GapSetClassOfDeviceInfo));
216 
217     ctx->cod = cod;
218 
219     int ret = GapRunTaskBlockProcess(GapSetClassOfDeviceTask, ctx);
220     if (ret == BT_NO_ERROR) {
221         ret = ctx->result;
222     }
223 
224     MEM_MALLOC.free(ctx);
225     return ret;
226 }
227 
GapSetExtendedInquiryResponseTask(void * ctx)228 static void GapSetExtendedInquiryResponseTask(void *ctx)
229 {
230     GapSetExtendedInquiryResponseInfo *info = ctx;
231     info->result = GAP_SetExtendedInquiryResponse(info->eir);
232 }
233 
GAPIF_SetExtendedInquiryResponse(const uint8_t eir[GAP_EIR_SIZE_MAX])234 int GAPIF_SetExtendedInquiryResponse(const uint8_t eir[GAP_EIR_SIZE_MAX])
235 {
236     LOG_INFO("%{public}s: ", __FUNCTION__);
237     GapSetExtendedInquiryResponseInfo *ctx = MEM_MALLOC.alloc(sizeof(GapSetExtendedInquiryResponseInfo));
238     if (ctx == NULL) {
239         return BT_NO_MEMORY;
240     }
241 
242     (void)memset_s(ctx, sizeof(GapSetExtendedInquiryResponseInfo), 0x00, sizeof(GapSetExtendedInquiryResponseInfo));
243 
244     ctx->eir = (uint8_t *)eir;
245 
246     int ret = GapRunTaskBlockProcess(GapSetExtendedInquiryResponseTask, ctx);
247     if (ret == BT_NO_ERROR) {
248         ret = ctx->result;
249     }
250 
251     MEM_MALLOC.free(ctx);
252     return ret;
253 }
254 
GapSetScanModeTask(void * ctx)255 static void GapSetScanModeTask(void *ctx)
256 {
257     GapSetScanModeInfo *info = ctx;
258     info->result = GAP_SetScanMode(&info->discoverInfo, &info->connectableInfo, info->callback, info->context);
259 }
260 
GAPIF_SetScanMode(const GapDiscoverModeInfo * discoverInfo,const GapConnectableModeInfo * connectableInfo,GapSetScanModeResultCallback callback,void * context)261 int GAPIF_SetScanMode(const GapDiscoverModeInfo *discoverInfo, const GapConnectableModeInfo *connectableInfo,
262     GapSetScanModeResultCallback callback, void *context)
263 {
264     LOG_INFO("%{public}s: ", __FUNCTION__);
265     GapSetScanModeInfo *ctx = MEM_MALLOC.alloc(sizeof(GapSetScanModeInfo));
266     if (ctx == NULL) {
267         return BT_NO_MEMORY;
268     }
269 
270     (void)memset_s(ctx, sizeof(GapSetScanModeInfo), 0x00, sizeof(GapSetScanModeInfo));
271 
272     ctx->discoverInfo = *discoverInfo;
273     ctx->connectableInfo = *connectableInfo;
274     ctx->callback = callback;
275     ctx->context = context;
276 
277     int ret = GapRunTaskBlockProcess(GapSetScanModeTask, ctx);
278     if (ret == BT_NO_ERROR) {
279         ret = ctx->result;
280     }
281 
282     MEM_MALLOC.free(ctx);
283     return ret;
284 }
285 
GapSetBondableModeTask(void * ctx)286 static void GapSetBondableModeTask(void *ctx)
287 {
288     GapSetBondableModeInfo *info = ctx;
289     info->result = GAP_SetBondableMode(info->isBondable);
290 }
291 
GAPIF_SetBondableMode(uint8_t isBondable)292 int GAPIF_SetBondableMode(uint8_t isBondable)
293 {
294     LOG_INFO("%{public}s: Bondable:%hhu", __FUNCTION__, isBondable);
295     GapSetBondableModeInfo *ctx = MEM_MALLOC.alloc(sizeof(GapSetBondableModeInfo));
296     if (ctx == NULL) {
297         return BT_NO_MEMORY;
298     }
299 
300     (void)memset_s(ctx, sizeof(GapSetBondableModeInfo), 0x00, sizeof(GapSetBondableModeInfo));
301 
302     ctx->isBondable = isBondable;
303 
304     int ret = GapRunTaskBlockProcess(GapSetBondableModeTask, ctx);
305     if (ret == BT_NO_ERROR) {
306         ret = ctx->result;
307     }
308 
309     MEM_MALLOC.free(ctx);
310     return ret;
311 }
312 
GapRegisterServiceSecurityTask(void * ctx)313 static void GapRegisterServiceSecurityTask(void *ctx)
314 {
315     GapRegisterServiceSecurityInfo *info = ctx;
316     info->result = GAP_RegisterServiceSecurity(info->addr, &info->serviceInfo, info->securityMode);
317 }
318 
GAPIF_RegisterServiceSecurity(const BtAddr * addr,const GapServiceSecurityInfo * serviceInfo,uint16_t securityMode)319 int GAPIF_RegisterServiceSecurity(const BtAddr *addr, const GapServiceSecurityInfo *serviceInfo, uint16_t securityMode)
320 {
321     LOG_INFO("%{public}s:%{public}s-%02d-%{public}s-0x%04x mode:%04x",
322         __FUNCTION__,
323         serviceInfo->direction ? "IN" : "OUT",
324         serviceInfo->serviceId,
325         serviceInfo->protocolId ? "RFCOMM" : "L2CAP",
326         serviceInfo->protocolId ? serviceInfo->channelId.rfcommChannel : serviceInfo->channelId.l2capPsm,
327         securityMode);
328     GapRegisterServiceSecurityInfo *ctx = MEM_MALLOC.alloc(sizeof(GapRegisterServiceSecurityInfo));
329     if (ctx == NULL) {
330         return BT_NO_MEMORY;
331     }
332 
333     (void)memset_s(ctx, sizeof(GapRegisterServiceSecurityInfo), 0x00, sizeof(GapRegisterServiceSecurityInfo));
334 
335     ctx->addr = (BtAddr *)addr;
336     ctx->serviceInfo = *serviceInfo;
337     ctx->securityMode = securityMode;
338 
339     int ret = GapRunTaskBlockProcess(GapRegisterServiceSecurityTask, ctx);
340     if (ret == BT_NO_ERROR) {
341         ret = ctx->result;
342     }
343 
344     MEM_MALLOC.free(ctx);
345     return ret;
346 }
347 
GapFreeRegisterServiceSecurity(void * ctx)348 static void GapFreeRegisterServiceSecurity(void *ctx)
349 {
350     GapRegisterServiceSecurityInfo *info = ctx;
351 
352     MEM_MALLOC.free(info->addr);
353 }
354 
GAPIF_RegisterServiceSecurityAsync(const BtAddr * addr,const GapServiceSecurityInfo * serviceInfo,uint16_t securityMode)355 int GAPIF_RegisterServiceSecurityAsync(
356     const BtAddr *addr, const GapServiceSecurityInfo *serviceInfo, uint16_t securityMode)
357 {
358     LOG_INFO("%{public}s:%{public}s-%02d-%{public}s-0x%04x mode:%04x",
359         __FUNCTION__,
360         serviceInfo->direction ? "IN" : "OUT",
361         serviceInfo->serviceId,
362         serviceInfo->protocolId ? "RFCOMM" : "L2CAP",
363         serviceInfo->protocolId ? serviceInfo->channelId.rfcommChannel : serviceInfo->channelId.l2capPsm,
364         securityMode);
365     GapRegisterServiceSecurityInfo *ctx = MEM_MALLOC.alloc(sizeof(GapRegisterServiceSecurityInfo));
366     if (ctx == NULL) {
367         return BT_NO_MEMORY;
368     }
369 
370     (void)memset_s(ctx, sizeof(GapRegisterServiceSecurityInfo), 0x00, sizeof(GapRegisterServiceSecurityInfo));
371 
372     ctx->addr = MEM_MALLOC.alloc(sizeof(BtAddr));
373     if (ctx->addr == NULL) {
374         MEM_MALLOC.free(ctx);
375         return BT_NO_MEMORY;
376     }
377 
378     if (addr != NULL) {
379         ctx->addr = (BtAddr *)addr;
380     } else {
381         (void)memset_s(ctx->addr, sizeof(BtAddr), 0x00, sizeof(BtAddr));
382     }
383     ctx->serviceInfo = *serviceInfo;
384     ctx->securityMode = securityMode;
385 
386     int ret = GapRunTaskUnBlockProcess(GapRegisterServiceSecurityTask, ctx, GapFreeRegisterServiceSecurity);
387     if (ret == BT_NO_ERROR) {
388         ret = ctx->result;
389     }
390 
391     return ret;
392 }
393 
GapDeregisterServiceSecurityTask(void * ctx)394 static void GapDeregisterServiceSecurityTask(void *ctx)
395 {
396     GapDeregisterServiceSecurityInfo *info = ctx;
397     info->result = GAP_DeregisterServiceSecurity(info->addr, &info->serviceInfo);
398 }
399 
GAPIF_DeregisterServiceSecurity(const BtAddr * addr,const GapServiceSecurityInfo * serviceInfo)400 int GAPIF_DeregisterServiceSecurity(const BtAddr *addr, const GapServiceSecurityInfo *serviceInfo)
401 {
402     LOG_INFO("%{public}s:%{public}s-%02d-%{public}s-0x%04x",
403         __FUNCTION__,
404         serviceInfo->direction ? "IN" : "OUT",
405         serviceInfo->serviceId,
406         serviceInfo->protocolId ? "RFCOMM" : "L2CAP",
407         serviceInfo->protocolId ? serviceInfo->channelId.rfcommChannel : serviceInfo->channelId.l2capPsm);
408     GapDeregisterServiceSecurityInfo *ctx = MEM_MALLOC.alloc(sizeof(GapDeregisterServiceSecurityInfo));
409     if (ctx == NULL) {
410         return BT_NO_MEMORY;
411     }
412 
413     (void)memset_s(ctx, sizeof(GapDeregisterServiceSecurityInfo), 0x00, sizeof(GapDeregisterServiceSecurityInfo));
414 
415     ctx->addr = (BtAddr *)addr;
416     ctx->serviceInfo = *serviceInfo;
417 
418     int ret = GapRunTaskBlockProcess(GapDeregisterServiceSecurityTask, ctx);
419     if (ret == BT_NO_ERROR) {
420         ret = ctx->result;
421     }
422 
423     MEM_MALLOC.free(ctx);
424     return ret;
425 }
426 
GapFreeDeregisterServiceSecurity(void * ctx)427 static void GapFreeDeregisterServiceSecurity(void *ctx)
428 {
429     GapDeregisterServiceSecurityInfo *info = ctx;
430 
431     MEM_MALLOC.free(info->addr);
432 }
433 
GAPIF_DeregisterServiceSecurityAsync(const BtAddr * addr,const GapServiceSecurityInfo * serviceInfo)434 int GAPIF_DeregisterServiceSecurityAsync(const BtAddr *addr, const GapServiceSecurityInfo *serviceInfo)
435 {
436     LOG_INFO("%{public}s:%{public}s-%02d-%{public}s-0x%04x",
437         __FUNCTION__,
438         serviceInfo->direction ? "IN" : "OUT",
439         serviceInfo->serviceId,
440         serviceInfo->protocolId ? "RFCOMM" : "L2CAP",
441         serviceInfo->protocolId ? serviceInfo->channelId.rfcommChannel : serviceInfo->channelId.l2capPsm);
442     GapDeregisterServiceSecurityInfo *ctx = MEM_MALLOC.alloc(sizeof(GapDeregisterServiceSecurityInfo));
443     if (ctx == NULL) {
444         return BT_NO_MEMORY;
445     }
446 
447     (void)memset_s(ctx, sizeof(GapDeregisterServiceSecurityInfo), 0x00, sizeof(GapDeregisterServiceSecurityInfo));
448 
449     ctx->addr = MEM_MALLOC.alloc(sizeof(BtAddr));
450     if (ctx->addr == NULL) {
451         MEM_MALLOC.free(ctx);
452         return BT_NO_MEMORY;
453     }
454 
455     if (addr != NULL) {
456         ctx->addr = (BtAddr *)addr;
457     } else {
458         (void)memset_s(ctx->addr, sizeof(BtAddr), 0x00, sizeof(BtAddr));
459     }
460     ctx->serviceInfo = *serviceInfo;
461 
462     int ret = GapRunTaskUnBlockProcess(GapDeregisterServiceSecurityTask, ctx, GapFreeDeregisterServiceSecurity);
463     if (ret == BT_NO_ERROR) {
464         ret = ctx->result;
465     }
466 
467     return ret;
468 }
469 
GapRequestSecurityTask(void * ctx)470 static void GapRequestSecurityTask(void *ctx)
471 {
472     GapRequestSecurityInfo *info = ctx;
473     info->result = GAP_RequestSecurity(&info->addr, &info->param);
474 }
475 
GAPIF_RequestSecurity(const BtAddr * addr,const GapRequestSecurityParam * param)476 int GAPIF_RequestSecurity(const BtAddr *addr, const GapRequestSecurityParam *param)
477 {
478     LOG_INFO("%{public}s:%{public}s-%02d-%{public}s-0x%04x",
479         __FUNCTION__,
480         param->info.direction ? "IN" : "OUT",
481         param->info.serviceId,
482         param->info.protocolId ? "RFCOMM" : "L2CAP",
483         param->info.protocolId ? param->info.channelId.rfcommChannel : param->info.channelId.l2capPsm);
484     GapRequestSecurityInfo *ctx = MEM_MALLOC.alloc(sizeof(GapRequestSecurityInfo));
485     if (ctx == NULL) {
486         return BT_NO_MEMORY;
487     }
488 
489     (void)memset_s(ctx, sizeof(GapRequestSecurityInfo), 0x00, sizeof(GapRequestSecurityInfo));
490 
491     (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr));
492     (void)memcpy_s(&ctx->param, sizeof(GapRequestSecurityParam), param, sizeof(GapRequestSecurityParam));
493 
494     int ret = GapRunTaskBlockProcess(GapRequestSecurityTask, ctx);
495     if (ret == BT_NO_ERROR) {
496         ret = ctx->result;
497     }
498 
499     MEM_MALLOC.free(ctx);
500     return ret;
501 }
502 
GAPIF_RequestSecurityAsync(const BtAddr * addr,const GapRequestSecurityParam * param)503 int GAPIF_RequestSecurityAsync(const BtAddr *addr, const GapRequestSecurityParam *param)
504 {
505     LOG_INFO("%{public}s:%{public}s-%02d-%{public}s-0x%04x",
506         __FUNCTION__,
507         param->info.direction ? "IN" : "OUT",
508         param->info.serviceId,
509         param->info.protocolId ? "RFCOMM" : "L2CAP",
510         param->info.protocolId ? param->info.channelId.rfcommChannel : param->info.channelId.l2capPsm);
511     GapRequestSecurityInfo *ctx = MEM_MALLOC.alloc(sizeof(GapRequestSecurityInfo));
512     if (ctx == NULL) {
513         return BT_NO_MEMORY;
514     }
515 
516     (void)memset_s(ctx, sizeof(GapRequestSecurityInfo), 0x00, sizeof(GapRequestSecurityInfo));
517 
518     (void)memcpy_s(&ctx->addr, sizeof(BtAddr), addr, sizeof(BtAddr));
519     (void)memcpy_s(&ctx->param, sizeof(GapRequestSecurityParam), param, sizeof(GapRequestSecurityParam));
520 
521     int ret = GapRunTaskUnBlockProcess(GapRequestSecurityTask, ctx, NULL);
522     if (ret == BT_NO_ERROR) {
523         ret = ctx->result;
524     }
525 
526     return ret;
527 }
528 
GapRegisterSecurityCallbackTask(void * ctx)529 static void GapRegisterSecurityCallbackTask(void *ctx)
530 {
531     GapGeneralCallbackInfo *info = ctx;
532     info->result = GAP_RegisterSecurityCallback(info->callback, info->context);
533 }
534 
GAPIF_RegisterSecurityCallback(const GapSecurityCallback * callback,void * context)535 int GAPIF_RegisterSecurityCallback(const GapSecurityCallback *callback, void *context)
536 {
537     LOG_INFO("%{public}s: ", __FUNCTION__);
538     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
539     if (ctx == NULL) {
540         return BT_NO_MEMORY;
541     }
542 
543     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
544 
545     ctx->callback = (void *)callback;
546     ctx->context = context;
547 
548     int ret = GapRunTaskBlockProcess(GapRegisterSecurityCallbackTask, ctx);
549     if (ret == BT_NO_ERROR) {
550         ret = ctx->result;
551     }
552 
553     MEM_MALLOC.free(ctx);
554     return ret;
555 }
556 
GapDeregisterSecurityCallbackTask(void * ctx)557 static void GapDeregisterSecurityCallbackTask(void *ctx)
558 {
559     GapGeneralVoidInfo *info = ctx;
560     info->result = GAP_DeregisterSecurityCallback();
561 }
562 
GAPIF_DeregisterSecurityCallback(void)563 int GAPIF_DeregisterSecurityCallback(void)
564 {
565     LOG_INFO("%{public}s: ", __FUNCTION__);
566     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
567     if (ctx == NULL) {
568         return BT_NO_MEMORY;
569     }
570 
571     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
572 
573     int ret = GapRunTaskBlockProcess(GapDeregisterSecurityCallbackTask, ctx);
574     if (ret == BT_NO_ERROR) {
575         ret = ctx->result;
576     }
577 
578     MEM_MALLOC.free(ctx);
579     return ret;
580 }
581 
GapSetSecurityModeTask(void * ctx)582 static void GapSetSecurityModeTask(void *ctx)
583 {
584     GapSetSecurityModeInfo *info = ctx;
585     info->result = GAP_SetSecurityMode(info->mode);
586 }
587 
GAPIF_SetSecurityMode(GAP_SecurityMode mode)588 int GAPIF_SetSecurityMode(GAP_SecurityMode mode)
589 {
590     LOG_INFO("%{public}s: mode:%{public}d", __FUNCTION__, mode);
591     GapSetSecurityModeInfo *ctx = MEM_MALLOC.alloc(sizeof(GapSetSecurityModeInfo));
592     if (ctx == NULL) {
593         return BT_NO_MEMORY;
594     }
595 
596     (void)memset_s(ctx, sizeof(GapSetSecurityModeInfo), 0x00, sizeof(GapSetSecurityModeInfo));
597 
598     ctx->mode = mode;
599 
600     int ret = GapRunTaskBlockProcess(GapSetSecurityModeTask, ctx);
601     if (ret == BT_NO_ERROR) {
602         ret = ctx->result;
603     }
604 
605     MEM_MALLOC.free(ctx);
606     return ret;
607 }
608 
GapAuthorizeResTask(void * ctx)609 static void GapAuthorizeResTask(void *ctx)
610 {
611     GapAuthorizeResInfo *info = ctx;
612     info->result = GAP_AuthorizeRes(info->addr, info->service, info->accept);
613 }
614 
GAPIF_AuthorizeRes(const BtAddr * addr,GAP_Service service,uint8_t accept)615 int GAPIF_AuthorizeRes(const BtAddr *addr, GAP_Service service, uint8_t accept)
616 {
617     LOG_INFO("%{public}s: " BT_ADDR_FMT "%{public}d accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), service, accept);
618     GapAuthorizeResInfo *ctx = MEM_MALLOC.alloc(sizeof(GapAuthorizeResInfo));
619     if (ctx == NULL) {
620         return BT_NO_MEMORY;
621     }
622 
623     (void)memset_s(ctx, sizeof(GapAuthorizeResInfo), 0x00, sizeof(GapAuthorizeResInfo));
624 
625     ctx->addr = (BtAddr *)addr;
626     ctx->service = service;
627     ctx->accept = accept;
628 
629     int ret = GapRunTaskBlockProcess(GapAuthorizeResTask, ctx);
630     if (ret == BT_NO_ERROR) {
631         ret = ctx->result;
632     }
633 
634     MEM_MALLOC.free(ctx);
635     return ret;
636 }
637 
GapRegisterAuthenticationCallbackTask(void * ctx)638 static void GapRegisterAuthenticationCallbackTask(void *ctx)
639 {
640     GapGeneralCallbackInfo *info = ctx;
641     info->result = GAP_RegisterAuthenticationCallback(info->callback, info->context);
642 }
643 
GAPIF_RegisterAuthenticationCallback(const GapAuthenticationCallback * callback,void * context)644 int GAPIF_RegisterAuthenticationCallback(const GapAuthenticationCallback *callback, void *context)
645 {
646     LOG_INFO("%{public}s: ", __FUNCTION__);
647     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
648     if (ctx == NULL) {
649         return BT_NO_MEMORY;
650     }
651 
652     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
653 
654     ctx->callback = (void *)callback;
655     ctx->context = context;
656 
657     int ret = GapRunTaskBlockProcess(GapRegisterAuthenticationCallbackTask, ctx);
658     if (ret == BT_NO_ERROR) {
659         ret = ctx->result;
660     }
661 
662     MEM_MALLOC.free(ctx);
663     return ret;
664 }
665 
GapDeregisterAuthenticationCallbackTask(void * ctx)666 static void GapDeregisterAuthenticationCallbackTask(void *ctx)
667 {
668     GapGeneralVoidInfo *info = ctx;
669     info->result = GAP_DeregisterAuthenticationCallback();
670 }
671 
GAPIF_DeregisterAuthenticationCallback(void)672 int GAPIF_DeregisterAuthenticationCallback(void)
673 {
674     LOG_INFO("%{public}s: ", __FUNCTION__);
675     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
676     if (ctx == NULL) {
677         return BT_NO_MEMORY;
678     }
679 
680     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
681 
682     int ret = GapRunTaskBlockProcess(GapDeregisterAuthenticationCallbackTask, ctx);
683     if (ret == BT_NO_ERROR) {
684         ret = ctx->result;
685     }
686 
687     MEM_MALLOC.free(ctx);
688     return ret;
689 }
690 
GapPairIsFromLocalTask(void * ctx)691 static void GapPairIsFromLocalTask(void *ctx)
692 {
693     GapPairIsFromLocalInfo *info = ctx;
694     info->result = GAP_PairIsFromLocal(info->addr, info->isLocal);
695 }
696 
GAPIF_PairIsFromLocal(const BtAddr * addr,bool * isLocal)697 int GAPIF_PairIsFromLocal(const BtAddr *addr, bool *isLocal)
698 {
699     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
700     GapPairIsFromLocalInfo *ctx = MEM_MALLOC.alloc(sizeof(GapPairIsFromLocalInfo));
701     if (ctx == NULL) {
702         return BT_NO_MEMORY;
703     }
704 
705     (void)memset_s(ctx, sizeof(GapPairIsFromLocalInfo), 0x00, sizeof(GapPairIsFromLocalInfo));
706 
707     ctx->addr = (BtAddr *)addr;
708     ctx->isLocal = isLocal;
709 
710     int ret = GapRunTaskBlockProcess(GapPairIsFromLocalTask, ctx);
711     if (ret == BT_NO_ERROR) {
712         ret = ctx->result;
713     }
714 
715     MEM_MALLOC.free(ctx);
716     return ret;
717 }
718 
GapAuthenticationReqTask(void * ctx)719 static void GapAuthenticationReqTask(void *ctx)
720 {
721     GapGeneralPointerInfo *info = ctx;
722     info->result = GAP_AuthenticationReq(info->pointer);
723 }
724 
GAPIF_AuthenticationReq(const BtAddr * addr)725 int GAPIF_AuthenticationReq(const BtAddr *addr)
726 {
727     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
728     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
729     if (ctx == NULL) {
730         return BT_NO_MEMORY;
731     }
732 
733     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
734 
735     ctx->pointer = (void *)addr;
736 
737     int ret = GapRunTaskBlockProcess(GapAuthenticationReqTask, ctx);
738     if (ret == BT_NO_ERROR) {
739         ret = ctx->result;
740     }
741 
742     MEM_MALLOC.free(ctx);
743     return ret;
744 }
745 
GapCancelAuthenticationReqTask(void * ctx)746 static void GapCancelAuthenticationReqTask(void *ctx)
747 {
748     GapGeneralPointerInfo *info = ctx;
749     info->result = GAP_CancelAuthenticationReq(info->pointer);
750 }
751 
GAPIF_CancelAuthenticationReq(const BtAddr * addr)752 int GAPIF_CancelAuthenticationReq(const BtAddr *addr)
753 {
754     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
755     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
756     if (ctx == NULL) {
757         return BT_NO_MEMORY;
758     }
759 
760     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
761 
762     ctx->pointer = (void *)addr;
763 
764     int ret = GapRunTaskBlockProcess(GapCancelAuthenticationReqTask, ctx);
765     if (ret == BT_NO_ERROR) {
766         ret = ctx->result;
767     }
768 
769     MEM_MALLOC.free(ctx);
770     return ret;
771 }
772 
GapIOCapabilityRspTask(void * ctx)773 static void GapIOCapabilityRspTask(void *ctx)
774 {
775     GapIOCapabilityRspInfo *info = ctx;
776     info->result =
777         GAP_IOCapabilityRsp(info->addr, info->accept, info->ioCapability, info->oobDataPresent, info->authReq);
778 }
779 
GAPIF_IOCapabilityRsp(const BtAddr * addr,uint8_t accept,uint8_t ioCapability,uint8_t oobDataPresent,uint8_t authReq)780 int GAPIF_IOCapabilityRsp(
781     const BtAddr *addr, uint8_t accept, uint8_t ioCapability, uint8_t oobDataPresent, uint8_t authReq)
782 {
783     LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
784     GapIOCapabilityRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapIOCapabilityRspInfo));
785     if (ctx == NULL) {
786         return BT_NO_MEMORY;
787     }
788 
789     (void)memset_s(ctx, sizeof(GapIOCapabilityRspInfo), 0x00, sizeof(GapIOCapabilityRspInfo));
790 
791     ctx->addr = (BtAddr *)addr;
792     ctx->accept = accept;
793     ctx->ioCapability = ioCapability;
794     ctx->oobDataPresent = oobDataPresent;
795     ctx->authReq = authReq;
796 
797     int ret = GapRunTaskBlockProcess(GapIOCapabilityRspTask, ctx);
798     if (ret == BT_NO_ERROR) {
799         ret = ctx->result;
800     }
801 
802     MEM_MALLOC.free(ctx);
803     return ret;
804 }
805 
GapUserConfirmRspTask(void * ctx)806 static void GapUserConfirmRspTask(void *ctx)
807 {
808     GapUserConfirmRspInfo *info = ctx;
809     info->result = GAP_UserConfirmRsp(info->addr, info->accept);
810 }
811 
GAPIF_UserConfirmRsp(const BtAddr * addr,uint8_t accept)812 int GAPIF_UserConfirmRsp(const BtAddr *addr, uint8_t accept)
813 {
814     LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
815     GapUserConfirmRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapUserConfirmRspInfo));
816     if (ctx == NULL) {
817         return BT_NO_MEMORY;
818     }
819 
820     (void)memset_s(ctx, sizeof(GapUserConfirmRspInfo), 0x00, sizeof(GapUserConfirmRspInfo));
821 
822     ctx->addr = (BtAddr *)addr;
823     ctx->accept = accept;
824 
825     int ret = GapRunTaskBlockProcess(GapUserConfirmRspTask, ctx);
826     if (ret == BT_NO_ERROR) {
827         ret = ctx->result;
828     }
829 
830     MEM_MALLOC.free(ctx);
831     return ret;
832 }
833 
GapUserPasskeyRspTask(void * ctx)834 static void GapUserPasskeyRspTask(void *ctx)
835 {
836     GapUserPasskeyRspInfo *info = ctx;
837     info->result = GAP_UserPasskeyRsp(info->addr, info->accept, info->number);
838 }
839 
GAPIF_UserPasskeyRsp(const BtAddr * addr,uint8_t accept,uint32_t number)840 int GAPIF_UserPasskeyRsp(const BtAddr *addr, uint8_t accept, uint32_t number)
841 {
842     LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
843     GapUserPasskeyRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapUserPasskeyRspInfo));
844     if (ctx == NULL) {
845         return BT_NO_MEMORY;
846     }
847 
848     (void)memset_s(ctx, sizeof(GapUserPasskeyRspInfo), 0x00, sizeof(GapUserPasskeyRspInfo));
849 
850     ctx->addr = (BtAddr *)addr;
851     ctx->accept = accept;
852     ctx->number = number;
853 
854     int ret = GapRunTaskBlockProcess(GapUserPasskeyRspTask, ctx);
855     if (ret == BT_NO_ERROR) {
856         ret = ctx->result;
857     }
858 
859     MEM_MALLOC.free(ctx);
860     return ret;
861 }
862 
GapRemoteOobRspTask(void * ctx)863 static void GapRemoteOobRspTask(void *ctx)
864 {
865     GapRemoteOobRspInfo *info = ctx;
866     info->result = GAP_RemoteOobRsp(info->addr, info->accept, info->data);
867 }
868 
GAPIF_RemoteOobRsp(const BtAddr * addr,uint8_t accept,const GapOOBData * data)869 int GAPIF_RemoteOobRsp(const BtAddr *addr, uint8_t accept, const GapOOBData *data)
870 {
871     LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
872     GapRemoteOobRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapRemoteOobRspInfo));
873     if (ctx == NULL) {
874         return BT_NO_MEMORY;
875     }
876 
877     (void)memset_s(ctx, sizeof(GapRemoteOobRspInfo), 0x00, sizeof(GapRemoteOobRspInfo));
878 
879     ctx->addr = (BtAddr *)addr;
880     ctx->accept = accept;
881     ctx->data = (GapOOBData *)data;
882 
883     int ret = GapRunTaskBlockProcess(GapRemoteOobRspTask, ctx);
884     if (ret == BT_NO_ERROR) {
885         ret = ctx->result;
886     }
887 
888     MEM_MALLOC.free(ctx);
889     return ret;
890 }
891 
GapPinCodeRspTask(void * ctx)892 static void GapPinCodeRspTask(void *ctx)
893 {
894     GapPinCodeRspInfo *info = ctx;
895     info->result = GAP_PinCodeRsp(info->addr, info->accept, info->pinCode, info->pinCodeLength);
896 }
897 
GAPIF_PinCodeRsp(const BtAddr * addr,uint8_t accept,const uint8_t * pinCode,uint8_t pinCodeLength)898 int GAPIF_PinCodeRsp(const BtAddr *addr, uint8_t accept, const uint8_t *pinCode, uint8_t pinCodeLength)
899 {
900     LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
901     GapPinCodeRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapPinCodeRspInfo));
902     if (ctx == NULL) {
903         return BT_NO_MEMORY;
904     }
905 
906     (void)memset_s(ctx, sizeof(GapPinCodeRspInfo), 0x00, sizeof(GapPinCodeRspInfo));
907 
908     ctx->addr = (BtAddr *)addr;
909     ctx->accept = accept;
910     ctx->pinCode = (uint8_t *)pinCode;
911     ctx->pinCodeLength = pinCodeLength;
912 
913     int ret = GapRunTaskBlockProcess(GapPinCodeRspTask, ctx);
914     if (ret == BT_NO_ERROR) {
915         ret = ctx->result;
916     }
917 
918     MEM_MALLOC.free(ctx);
919     return ret;
920 }
921 
GapLinkKeyRspTask(void * ctx)922 static void GapLinkKeyRspTask(void *ctx)
923 {
924     GapLinkKeyRspInfo *info = ctx;
925     info->result = GAP_LinkKeyRsp(info->addr, info->accept, info->linkKey, info->keyType);
926 }
927 
GAPIF_LinkKeyRsp(const BtAddr * addr,uint8_t accept,const uint8_t linkKey[GAP_LINKKEY_SIZE],uint8_t keyType)928 int GAPIF_LinkKeyRsp(const BtAddr *addr, uint8_t accept, const uint8_t linkKey[GAP_LINKKEY_SIZE], uint8_t keyType)
929 {
930     LOG_INFO(
931         "%{public}s: " BT_ADDR_FMT " accept:%hhu keyType:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept, keyType);
932     GapLinkKeyRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLinkKeyRspInfo));
933     if (ctx == NULL) {
934         return BT_NO_MEMORY;
935     }
936 
937     (void)memset_s(ctx, sizeof(GapLinkKeyRspInfo), 0x00, sizeof(GapLinkKeyRspInfo));
938 
939     ctx->addr = (BtAddr *)addr;
940     ctx->accept = accept;
941     ctx->linkKey = (uint8_t *)linkKey;
942     ctx->keyType = keyType;
943 
944     int ret = GapRunTaskBlockProcess(GapLinkKeyRspTask, ctx);
945     if (ret == BT_NO_ERROR) {
946         ret = ctx->result;
947     }
948 
949     MEM_MALLOC.free(ctx);
950     return ret;
951 }
952 
GapRegisterDiscoveryCallbackTask(void * ctx)953 static void GapRegisterDiscoveryCallbackTask(void *ctx)
954 {
955     GapGeneralCallbackInfo *info = ctx;
956     info->result = GAP_RegisterDiscoveryCallback(info->callback, info->context);
957 }
958 
GAPIF_RegisterDiscoveryCallback(const GapDiscoveryCallback * callback,void * context)959 int GAPIF_RegisterDiscoveryCallback(const GapDiscoveryCallback *callback, void *context)
960 {
961     LOG_INFO("%{public}s: ", __FUNCTION__);
962     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
963     if (ctx == NULL) {
964         return BT_NO_MEMORY;
965     }
966 
967     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
968 
969     ctx->callback = (void *)callback;
970     ctx->context = context;
971 
972     int ret = GapRunTaskBlockProcess(GapRegisterDiscoveryCallbackTask, ctx);
973     if (ret == BT_NO_ERROR) {
974         ret = ctx->result;
975     }
976 
977     MEM_MALLOC.free(ctx);
978     return ret;
979 }
980 
GapDeregisterDiscoveryCallbackTask(void * ctx)981 static void GapDeregisterDiscoveryCallbackTask(void *ctx)
982 {
983     GapGeneralVoidInfo *info = ctx;
984     info->result = GAP_DeregisterDiscoveryCallback();
985 }
986 
GAPIF_DeregisterDiscoveryCallback(void)987 int GAPIF_DeregisterDiscoveryCallback(void)
988 {
989     LOG_INFO("%{public}s: ", __FUNCTION__);
990     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
991     if (ctx == NULL) {
992         return BT_NO_MEMORY;
993     }
994 
995     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
996 
997     int ret = GapRunTaskBlockProcess(GapDeregisterDiscoveryCallbackTask, ctx);
998     if (ret == BT_NO_ERROR) {
999         ret = ctx->result;
1000     }
1001 
1002     MEM_MALLOC.free(ctx);
1003     return ret;
1004 }
1005 
GapInquiryTask(void * ctx)1006 static void GapInquiryTask(void *ctx)
1007 {
1008     GapInquiryInfo *info = ctx;
1009     info->result = GAP_Inquiry(info->mode, info->inquiryLength);
1010 }
1011 
GAPIF_Inquiry(uint8_t mode,uint8_t inquiryLength)1012 int GAPIF_Inquiry(uint8_t mode, uint8_t inquiryLength)
1013 {
1014     LOG_INFO("%{public}s: ", __FUNCTION__);
1015     GapInquiryInfo *ctx = MEM_MALLOC.alloc(sizeof(GapInquiryInfo));
1016     if (ctx == NULL) {
1017         return BT_NO_MEMORY;
1018     }
1019 
1020     (void)memset_s(ctx, sizeof(GapInquiryInfo), 0x00, sizeof(GapInquiryInfo));
1021 
1022     ctx->mode = mode;
1023     ctx->inquiryLength = inquiryLength;
1024 
1025     int ret = GapRunTaskBlockProcess(GapInquiryTask, ctx);
1026     if (ret == BT_NO_ERROR) {
1027         ret = ctx->result;
1028     }
1029 
1030     MEM_MALLOC.free(ctx);
1031     return ret;
1032 }
1033 
GapInquiryCancelTask(void * ctx)1034 static void GapInquiryCancelTask(void *ctx)
1035 {
1036     GapGeneralVoidInfo *info = ctx;
1037     info->result = GAP_InquiryCancel();
1038 }
1039 
GAPIF_InquiryCancel(void)1040 int GAPIF_InquiryCancel(void)
1041 {
1042     LOG_INFO("%{public}s: ", __FUNCTION__);
1043     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
1044     if (ctx == NULL) {
1045         return BT_NO_MEMORY;
1046     }
1047 
1048     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
1049 
1050     int ret = GapRunTaskBlockProcess(GapInquiryCancelTask, ctx);
1051     if (ret == BT_NO_ERROR) {
1052         ret = ctx->result;
1053     }
1054 
1055     MEM_MALLOC.free(ctx);
1056     return ret;
1057 }
1058 
GapGetRemoteNameTask(void * ctx)1059 static void GapGetRemoteNameTask(void *ctx)
1060 {
1061     GapGeneralPointerInfo *info = ctx;
1062     info->result = GAP_GetRemoteName(info->pointer);
1063 }
1064 
GAPIF_GetRemoteName(const BtAddr * addr)1065 int GAPIF_GetRemoteName(const BtAddr *addr)
1066 {
1067     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1068     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
1069     if (ctx == NULL) {
1070         return BT_NO_MEMORY;
1071     }
1072 
1073     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
1074 
1075     ctx->pointer = (void *)addr;
1076 
1077     int ret = GapRunTaskBlockProcess(GapGetRemoteNameTask, ctx);
1078     if (ret == BT_NO_ERROR) {
1079         ret = ctx->result;
1080     }
1081 
1082     MEM_MALLOC.free(ctx);
1083     return ret;
1084 }
1085 
GapGetRemoteNameCancelTask(void * ctx)1086 static void GapGetRemoteNameCancelTask(void *ctx)
1087 {
1088     GapGeneralPointerInfo *info = ctx;
1089     info->result = GAP_GetRemoteNameCancel(info->pointer);
1090 }
1091 
GAPIF_GetRemoteNameCancel(const BtAddr * addr)1092 int GAPIF_GetRemoteNameCancel(const BtAddr *addr)
1093 {
1094     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1095     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
1096     if (ctx == NULL) {
1097         return BT_NO_MEMORY;
1098     }
1099 
1100     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
1101 
1102     ctx->pointer = (void *)addr;
1103 
1104     int ret = GapRunTaskBlockProcess(GapGetRemoteNameCancelTask, ctx);
1105     if (ret == BT_NO_ERROR) {
1106         ret = ctx->result;
1107     }
1108 
1109     MEM_MALLOC.free(ctx);
1110     return ret;
1111 }
1112 
GapGetLocalAddrTask(void * ctx)1113 static void GapGetLocalAddrTask(void *ctx)
1114 {
1115     GapGeneralPointerInfo *info = ctx;
1116     info->result = GAP_GetLocalAddr(info->pointer);
1117 }
1118 
GAPIF_GetLocalAddr(BtAddr * addr)1119 int GAPIF_GetLocalAddr(BtAddr *addr)
1120 {
1121     LOG_INFO("%{public}s: ", __FUNCTION__);
1122     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
1123     if (ctx == NULL) {
1124         return BT_NO_MEMORY;
1125     }
1126 
1127     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
1128 
1129     ctx->pointer = (void *)addr;
1130 
1131     int ret = GapRunTaskBlockProcess(GapGetLocalAddrTask, ctx);
1132     if (ret == BT_NO_ERROR) {
1133         ret = ctx->result;
1134     }
1135 
1136     MEM_MALLOC.free(ctx);
1137     return ret;
1138 }
1139 
1140 #endif