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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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_SUCCESS) {
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",
618 __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), service, accept);
619 GapAuthorizeResInfo *ctx = MEM_MALLOC.alloc(sizeof(GapAuthorizeResInfo));
620 if (ctx == NULL) {
621 return BT_NO_MEMORY;
622 }
623
624 (void)memset_s(ctx, sizeof(GapAuthorizeResInfo), 0x00, sizeof(GapAuthorizeResInfo));
625
626 ctx->addr = (BtAddr *)addr;
627 ctx->service = service;
628 ctx->accept = accept;
629
630 int ret = GapRunTaskBlockProcess(GapAuthorizeResTask, ctx);
631 if (ret == BT_SUCCESS) {
632 ret = ctx->result;
633 }
634
635 MEM_MALLOC.free(ctx);
636 return ret;
637 }
638
GapRegisterAuthenticationCallbackTask(void * ctx)639 static void GapRegisterAuthenticationCallbackTask(void *ctx)
640 {
641 GapGeneralCallbackInfo *info = ctx;
642 info->result = GAP_RegisterAuthenticationCallback(info->callback, info->context);
643 }
644
GAPIF_RegisterAuthenticationCallback(const GapAuthenticationCallback * callback,void * context)645 int GAPIF_RegisterAuthenticationCallback(const GapAuthenticationCallback *callback, void *context)
646 {
647 LOG_INFO("%{public}s: ", __FUNCTION__);
648 GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
649 if (ctx == NULL) {
650 return BT_NO_MEMORY;
651 }
652
653 (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
654
655 ctx->callback = (void *)callback;
656 ctx->context = context;
657
658 int ret = GapRunTaskBlockProcess(GapRegisterAuthenticationCallbackTask, ctx);
659 if (ret == BT_SUCCESS) {
660 ret = ctx->result;
661 }
662
663 MEM_MALLOC.free(ctx);
664 return ret;
665 }
666
GapDeregisterAuthenticationCallbackTask(void * ctx)667 static void GapDeregisterAuthenticationCallbackTask(void *ctx)
668 {
669 GapGeneralVoidInfo *info = ctx;
670 info->result = GAP_DeregisterAuthenticationCallback();
671 }
672
GAPIF_DeregisterAuthenticationCallback(void)673 int GAPIF_DeregisterAuthenticationCallback(void)
674 {
675 LOG_INFO("%{public}s: ", __FUNCTION__);
676 GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
677 if (ctx == NULL) {
678 return BT_NO_MEMORY;
679 }
680
681 (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
682
683 int ret = GapRunTaskBlockProcess(GapDeregisterAuthenticationCallbackTask, ctx);
684 if (ret == BT_SUCCESS) {
685 ret = ctx->result;
686 }
687
688 MEM_MALLOC.free(ctx);
689 return ret;
690 }
691
GapPairIsFromLocalTask(void * ctx)692 static void GapPairIsFromLocalTask(void *ctx)
693 {
694 GapPairIsFromLocalInfo *info = ctx;
695 info->result = GAP_PairIsFromLocal(info->addr, info->isLocal);
696 }
697
GAPIF_PairIsFromLocal(const BtAddr * addr,bool * isLocal)698 int GAPIF_PairIsFromLocal(const BtAddr *addr, bool *isLocal)
699 {
700 LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
701 GapPairIsFromLocalInfo *ctx = MEM_MALLOC.alloc(sizeof(GapPairIsFromLocalInfo));
702 if (ctx == NULL) {
703 return BT_NO_MEMORY;
704 }
705
706 (void)memset_s(ctx, sizeof(GapPairIsFromLocalInfo), 0x00, sizeof(GapPairIsFromLocalInfo));
707
708 ctx->addr = (BtAddr *)addr;
709 ctx->isLocal = isLocal;
710
711 int ret = GapRunTaskBlockProcess(GapPairIsFromLocalTask, ctx);
712 if (ret == BT_SUCCESS) {
713 ret = ctx->result;
714 }
715
716 MEM_MALLOC.free(ctx);
717 return ret;
718 }
719
GapAuthenticationReqTask(void * ctx)720 static void GapAuthenticationReqTask(void *ctx)
721 {
722 GapGeneralPointerInfo *info = ctx;
723 info->result = GAP_AuthenticationReq(info->pointer);
724 }
725
GAPIF_AuthenticationReq(const BtAddr * addr)726 int GAPIF_AuthenticationReq(const BtAddr *addr)
727 {
728 LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
729 GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
730 if (ctx == NULL) {
731 return BT_NO_MEMORY;
732 }
733
734 (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
735
736 ctx->pointer = (void *)addr;
737
738 int ret = GapRunTaskBlockProcess(GapAuthenticationReqTask, ctx);
739 if (ret == BT_SUCCESS) {
740 ret = ctx->result;
741 }
742
743 MEM_MALLOC.free(ctx);
744 return ret;
745 }
746
GapCancelAuthenticationReqTask(void * ctx)747 static void GapCancelAuthenticationReqTask(void *ctx)
748 {
749 GapGeneralPointerInfo *info = ctx;
750 info->result = GAP_CancelAuthenticationReq(info->pointer);
751 }
752
GAPIF_CancelAuthenticationReq(const BtAddr * addr)753 int GAPIF_CancelAuthenticationReq(const BtAddr *addr)
754 {
755 LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
756 GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
757 if (ctx == NULL) {
758 return BT_NO_MEMORY;
759 }
760
761 (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
762
763 ctx->pointer = (void *)addr;
764
765 int ret = GapRunTaskBlockProcess(GapCancelAuthenticationReqTask, ctx);
766 if (ret == BT_SUCCESS) {
767 ret = ctx->result;
768 }
769
770 MEM_MALLOC.free(ctx);
771 return ret;
772 }
773
GapIOCapabilityRspTask(void * ctx)774 static void GapIOCapabilityRspTask(void *ctx)
775 {
776 GapIOCapabilityRspInfo *info = ctx;
777 info->result =
778 GAP_IOCapabilityRsp(info->addr, info->accept, info->ioCapability, info->oobDataPresent, info->authReq);
779 }
780
GAPIF_IOCapabilityRsp(const BtAddr * addr,uint8_t accept,uint8_t ioCapability,uint8_t oobDataPresent,uint8_t authReq)781 int GAPIF_IOCapabilityRsp(
782 const BtAddr *addr, uint8_t accept, uint8_t ioCapability, uint8_t oobDataPresent, uint8_t authReq)
783 {
784 LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
785 GapIOCapabilityRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapIOCapabilityRspInfo));
786 if (ctx == NULL) {
787 return BT_NO_MEMORY;
788 }
789
790 (void)memset_s(ctx, sizeof(GapIOCapabilityRspInfo), 0x00, sizeof(GapIOCapabilityRspInfo));
791
792 ctx->addr = (BtAddr *)addr;
793 ctx->accept = accept;
794 ctx->ioCapability = ioCapability;
795 ctx->oobDataPresent = oobDataPresent;
796 ctx->authReq = authReq;
797
798 int ret = GapRunTaskBlockProcess(GapIOCapabilityRspTask, ctx);
799 if (ret == BT_SUCCESS) {
800 ret = ctx->result;
801 }
802
803 MEM_MALLOC.free(ctx);
804 return ret;
805 }
806
GapUserConfirmRspTask(void * ctx)807 static void GapUserConfirmRspTask(void *ctx)
808 {
809 GapUserConfirmRspInfo *info = ctx;
810 info->result = GAP_UserConfirmRsp(info->addr, info->accept);
811 }
812
GAPIF_UserConfirmRsp(const BtAddr * addr,uint8_t accept)813 int GAPIF_UserConfirmRsp(const BtAddr *addr, uint8_t accept)
814 {
815 LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
816 GapUserConfirmRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapUserConfirmRspInfo));
817 if (ctx == NULL) {
818 return BT_NO_MEMORY;
819 }
820
821 (void)memset_s(ctx, sizeof(GapUserConfirmRspInfo), 0x00, sizeof(GapUserConfirmRspInfo));
822
823 ctx->addr = (BtAddr *)addr;
824 ctx->accept = accept;
825
826 int ret = GapRunTaskBlockProcess(GapUserConfirmRspTask, ctx);
827 if (ret == BT_SUCCESS) {
828 ret = ctx->result;
829 }
830
831 MEM_MALLOC.free(ctx);
832 return ret;
833 }
834
GapUserPasskeyRspTask(void * ctx)835 static void GapUserPasskeyRspTask(void *ctx)
836 {
837 GapUserPasskeyRspInfo *info = ctx;
838 info->result = GAP_UserPasskeyRsp(info->addr, info->accept, info->number);
839 }
840
GAPIF_UserPasskeyRsp(const BtAddr * addr,uint8_t accept,uint32_t number)841 int GAPIF_UserPasskeyRsp(const BtAddr *addr, uint8_t accept, uint32_t number)
842 {
843 LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
844 GapUserPasskeyRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapUserPasskeyRspInfo));
845 if (ctx == NULL) {
846 return BT_NO_MEMORY;
847 }
848
849 (void)memset_s(ctx, sizeof(GapUserPasskeyRspInfo), 0x00, sizeof(GapUserPasskeyRspInfo));
850
851 ctx->addr = (BtAddr *)addr;
852 ctx->accept = accept;
853 ctx->number = number;
854
855 int ret = GapRunTaskBlockProcess(GapUserPasskeyRspTask, ctx);
856 if (ret == BT_SUCCESS) {
857 ret = ctx->result;
858 }
859
860 MEM_MALLOC.free(ctx);
861 return ret;
862 }
863
GapRemoteOobRspTask(void * ctx)864 static void GapRemoteOobRspTask(void *ctx)
865 {
866 GapRemoteOobRspInfo *info = ctx;
867 info->result = GAP_RemoteOobRsp(info->addr, info->accept, info->data);
868 }
869
GAPIF_RemoteOobRsp(const BtAddr * addr,uint8_t accept,const GapOOBData * data)870 int GAPIF_RemoteOobRsp(const BtAddr *addr, uint8_t accept, const GapOOBData *data)
871 {
872 LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
873 GapRemoteOobRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapRemoteOobRspInfo));
874 if (ctx == NULL) {
875 return BT_NO_MEMORY;
876 }
877
878 (void)memset_s(ctx, sizeof(GapRemoteOobRspInfo), 0x00, sizeof(GapRemoteOobRspInfo));
879
880 ctx->addr = (BtAddr *)addr;
881 ctx->accept = accept;
882 ctx->data = (GapOOBData *)data;
883
884 int ret = GapRunTaskBlockProcess(GapRemoteOobRspTask, ctx);
885 if (ret == BT_SUCCESS) {
886 ret = ctx->result;
887 }
888
889 MEM_MALLOC.free(ctx);
890 return ret;
891 }
892
GapPinCodeRspTask(void * ctx)893 static void GapPinCodeRspTask(void *ctx)
894 {
895 GapPinCodeRspInfo *info = ctx;
896 info->result = GAP_PinCodeRsp(info->addr, info->accept, info->pinCode, info->pinCodeLength);
897 }
898
GAPIF_PinCodeRsp(const BtAddr * addr,uint8_t accept,const uint8_t * pinCode,uint8_t pinCodeLength)899 int GAPIF_PinCodeRsp(const BtAddr *addr, uint8_t accept, const uint8_t *pinCode, uint8_t pinCodeLength)
900 {
901 LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept);
902 GapPinCodeRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapPinCodeRspInfo));
903 if (ctx == NULL) {
904 return BT_NO_MEMORY;
905 }
906
907 (void)memset_s(ctx, sizeof(GapPinCodeRspInfo), 0x00, sizeof(GapPinCodeRspInfo));
908
909 ctx->addr = (BtAddr *)addr;
910 ctx->accept = accept;
911 ctx->pinCode = (uint8_t *)pinCode;
912 ctx->pinCodeLength = pinCodeLength;
913
914 int ret = GapRunTaskBlockProcess(GapPinCodeRspTask, ctx);
915 if (ret == BT_SUCCESS) {
916 ret = ctx->result;
917 }
918
919 MEM_MALLOC.free(ctx);
920 return ret;
921 }
922
GapLinkKeyRspTask(void * ctx)923 static void GapLinkKeyRspTask(void *ctx)
924 {
925 GapLinkKeyRspInfo *info = ctx;
926 info->result = GAP_LinkKeyRsp(info->addr, info->accept, info->linkKey, info->keyType);
927 }
928
GAPIF_LinkKeyRsp(const BtAddr * addr,uint8_t accept,const uint8_t linkKey[GAP_LINKKEY_SIZE],uint8_t keyType)929 int GAPIF_LinkKeyRsp(const BtAddr *addr, uint8_t accept, const uint8_t linkKey[GAP_LINKKEY_SIZE], uint8_t keyType)
930 {
931 LOG_INFO(
932 "%{public}s: " BT_ADDR_FMT " accept:%hhu keyType:%hhu",
933 __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept, keyType);
934 GapLinkKeyRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLinkKeyRspInfo));
935 if (ctx == NULL) {
936 return BT_NO_MEMORY;
937 }
938
939 (void)memset_s(ctx, sizeof(GapLinkKeyRspInfo), 0x00, sizeof(GapLinkKeyRspInfo));
940
941 ctx->addr = (BtAddr *)addr;
942 ctx->accept = accept;
943 ctx->linkKey = (uint8_t *)linkKey;
944 ctx->keyType = keyType;
945
946 int ret = GapRunTaskBlockProcess(GapLinkKeyRspTask, ctx);
947 if (ret == BT_SUCCESS) {
948 ret = ctx->result;
949 }
950
951 MEM_MALLOC.free(ctx);
952 return ret;
953 }
954
GapRegisterDiscoveryCallbackTask(void * ctx)955 static void GapRegisterDiscoveryCallbackTask(void *ctx)
956 {
957 GapGeneralCallbackInfo *info = ctx;
958 info->result = GAP_RegisterDiscoveryCallback(info->callback, info->context);
959 }
960
GAPIF_RegisterDiscoveryCallback(const GapDiscoveryCallback * callback,void * context)961 int GAPIF_RegisterDiscoveryCallback(const GapDiscoveryCallback *callback, void *context)
962 {
963 LOG_INFO("%{public}s: ", __FUNCTION__);
964 GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
965 if (ctx == NULL) {
966 return BT_NO_MEMORY;
967 }
968
969 (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
970
971 ctx->callback = (void *)callback;
972 ctx->context = context;
973
974 int ret = GapRunTaskBlockProcess(GapRegisterDiscoveryCallbackTask, ctx);
975 if (ret == BT_SUCCESS) {
976 ret = ctx->result;
977 }
978
979 MEM_MALLOC.free(ctx);
980 return ret;
981 }
982
GapDeregisterDiscoveryCallbackTask(void * ctx)983 static void GapDeregisterDiscoveryCallbackTask(void *ctx)
984 {
985 GapGeneralVoidInfo *info = ctx;
986 info->result = GAP_DeregisterDiscoveryCallback();
987 }
988
GAPIF_DeregisterDiscoveryCallback(void)989 int GAPIF_DeregisterDiscoveryCallback(void)
990 {
991 LOG_INFO("%{public}s: ", __FUNCTION__);
992 GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
993 if (ctx == NULL) {
994 return BT_NO_MEMORY;
995 }
996
997 (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
998
999 int ret = GapRunTaskBlockProcess(GapDeregisterDiscoveryCallbackTask, ctx);
1000 if (ret == BT_SUCCESS) {
1001 ret = ctx->result;
1002 }
1003
1004 MEM_MALLOC.free(ctx);
1005 return ret;
1006 }
1007
GapInquiryTask(void * ctx)1008 static void GapInquiryTask(void *ctx)
1009 {
1010 GapInquiryInfo *info = ctx;
1011 info->result = GAP_Inquiry(info->mode, info->inquiryLength);
1012 }
1013
GAPIF_Inquiry(uint8_t mode,uint8_t inquiryLength)1014 int GAPIF_Inquiry(uint8_t mode, uint8_t inquiryLength)
1015 {
1016 LOG_INFO("%{public}s: ", __FUNCTION__);
1017 GapInquiryInfo *ctx = MEM_MALLOC.alloc(sizeof(GapInquiryInfo));
1018 if (ctx == NULL) {
1019 return BT_NO_MEMORY;
1020 }
1021
1022 (void)memset_s(ctx, sizeof(GapInquiryInfo), 0x00, sizeof(GapInquiryInfo));
1023
1024 ctx->mode = mode;
1025 ctx->inquiryLength = inquiryLength;
1026
1027 int ret = GapRunTaskBlockProcess(GapInquiryTask, ctx);
1028 if (ret == BT_SUCCESS) {
1029 ret = ctx->result;
1030 }
1031
1032 MEM_MALLOC.free(ctx);
1033 return ret;
1034 }
1035
GapInquiryCancelTask(void * ctx)1036 static void GapInquiryCancelTask(void *ctx)
1037 {
1038 GapGeneralVoidInfo *info = ctx;
1039 info->result = GAP_InquiryCancel();
1040 }
1041
GAPIF_InquiryCancel(void)1042 int GAPIF_InquiryCancel(void)
1043 {
1044 LOG_INFO("%{public}s: ", __FUNCTION__);
1045 GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
1046 if (ctx == NULL) {
1047 return BT_NO_MEMORY;
1048 }
1049
1050 (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
1051
1052 int ret = GapRunTaskBlockProcess(GapInquiryCancelTask, ctx);
1053 if (ret == BT_SUCCESS) {
1054 ret = ctx->result;
1055 }
1056
1057 MEM_MALLOC.free(ctx);
1058 return ret;
1059 }
1060
GapGetRemoteNameTask(void * ctx)1061 static void GapGetRemoteNameTask(void *ctx)
1062 {
1063 GapGeneralPointerInfo *info = ctx;
1064 info->result = GAP_GetRemoteName(info->pointer);
1065 }
1066
GAPIF_GetRemoteName(const BtAddr * addr)1067 int GAPIF_GetRemoteName(const BtAddr *addr)
1068 {
1069 LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1070 GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
1071 if (ctx == NULL) {
1072 return BT_NO_MEMORY;
1073 }
1074
1075 (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
1076
1077 ctx->pointer = (void *)addr;
1078
1079 int ret = GapRunTaskBlockProcess(GapGetRemoteNameTask, ctx);
1080 if (ret == BT_SUCCESS) {
1081 ret = ctx->result;
1082 }
1083
1084 MEM_MALLOC.free(ctx);
1085 return ret;
1086 }
1087
GapGetRemoteNameCancelTask(void * ctx)1088 static void GapGetRemoteNameCancelTask(void *ctx)
1089 {
1090 GapGeneralPointerInfo *info = ctx;
1091 info->result = GAP_GetRemoteNameCancel(info->pointer);
1092 }
1093
GAPIF_GetRemoteNameCancel(const BtAddr * addr)1094 int GAPIF_GetRemoteNameCancel(const BtAddr *addr)
1095 {
1096 LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1097 GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
1098 if (ctx == NULL) {
1099 return BT_NO_MEMORY;
1100 }
1101
1102 (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
1103
1104 ctx->pointer = (void *)addr;
1105
1106 int ret = GapRunTaskBlockProcess(GapGetRemoteNameCancelTask, ctx);
1107 if (ret == BT_SUCCESS) {
1108 ret = ctx->result;
1109 }
1110
1111 MEM_MALLOC.free(ctx);
1112 return ret;
1113 }
1114
GapGetLocalAddrTask(void * ctx)1115 static void GapGetLocalAddrTask(void *ctx)
1116 {
1117 GapGeneralPointerInfo *info = ctx;
1118 info->result = GAP_GetLocalAddr(info->pointer);
1119 }
1120
GAPIF_GetLocalAddr(BtAddr * addr)1121 int GAPIF_GetLocalAddr(BtAddr *addr)
1122 {
1123 LOG_INFO("%{public}s: ", __FUNCTION__);
1124 GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
1125 if (ctx == NULL) {
1126 return BT_NO_MEMORY;
1127 }
1128
1129 (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
1130
1131 ctx->pointer = (void *)addr;
1132
1133 int ret = GapRunTaskBlockProcess(GapGetLocalAddrTask, ctx);
1134 if (ret == BT_SUCCESS) {
1135 ret = ctx->result;
1136 }
1137
1138 MEM_MALLOC.free(ctx);
1139 return ret;
1140 }
1141
1142 #endif