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_le.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     uint8_t role;
30 } GapLeSetRoleInfo;
31 
32 typedef struct {
33     int result;
34     BtAddr *addr;
35     uint16_t payloadTimeout;
36 } GapUseLePingInfo;
37 
38 typedef struct {
39     int result;
40     uint8_t advHandle;
41     uint8_t *addr;
42 } GapLeExAdvSetRandAddrInfo;
43 
44 typedef struct {
45     int result;
46     uint8_t advHandle;
47     uint8_t properties;
48     int8_t txPower;
49     GapLeExAdvParam advExParam;
50 } GapLeExAdvSetParamInfo;
51 
52 typedef struct {
53     int result;
54     uint8_t advHandle;
55     uint8_t operation;
56     uint8_t fragmentPreference;
57     uint8_t advDataLength;
58     uint8_t *advData;
59 } GapLeExAdvSetDataInfo;
60 
61 typedef struct {
62     int result;
63     uint8_t enable;
64     uint8_t numberOfSet;
65     GapExAdvSet *advSet;
66 } GapLeExAdvSetEnableInfo;
67 
68 typedef struct {
69     int result;
70     uint8_t advHandle;
71 } GapLeExAdvRemoveHandleInfo;
72 
73 typedef struct {
74     int result;
75     uint8_t advType;
76     GapLeAdvParam advParam;
77 } GapLeAdvSetParamInfo;
78 
79 typedef struct {
80     int result;
81     uint8_t advDataLength;
82     uint8_t *advData;
83 } GapLeAdvSetDataInfo;
84 
85 typedef struct {
86     int result;
87     uint8_t enable;
88 } GapLeAdvSetEnableInfo;
89 
90 typedef struct {
91     int result;
92     GapLeScanParam param;
93     uint8_t scanFilterPolity;
94 } GapLeScanSetParamInfo;
95 
96 typedef struct {
97     int result;
98     uint8_t scanEnable;
99     uint8_t filterDuplicates;
100 } GapLeScanSetEnableInfo;
101 
102 typedef struct {
103     int result;
104     uint8_t scanFilterPolity;
105     uint8_t scanPhys;
106     GapLeScanParam *param;
107 } GapLeExScanSetParamInfo;
108 
109 typedef struct {
110     int result;
111     uint8_t scanEnable;
112     uint8_t filterDuplicates;
113     uint16_t duration;
114     uint16_t period;
115 } GapLeExScanSetEnableInfo;
116 
117 typedef struct {
118     int result;
119     BtAddr *addr;
120     const GapLeConnectionParameter *connParam;
121 } GapLeConnParamUpdateInfo;
122 
123 typedef struct {
124     int result;
125     BtAddr *addr;
126     uint8_t accept;
127     const GapLeConnectionParameter *connParam;
128 } GapLeConnectionParameterRspInfo;
129 
130 typedef struct {
131     int result;
132     uint64_t channelMap;
133 } GapLeSetHostChannelClassificationInfo;
134 
135 typedef struct {
136     int result;
137     BtAddr *addr;
138     uint8_t accept;
139     LeEncKey encKey;
140     uint8_t keyType;
141 } GapLeEncryptionKeyRspInfo;
142 
143 typedef struct {
144     int result;
145     BtAddr *addr;
146     uint8_t accept;
147     GapSigningAlgorithmInfo info;
148 } GapRequestSigningAlgorithmInfoRspInfo;
149 
150 typedef struct {
151     int result;
152     uint8_t mode;
153 } GapLeSetBondModeInfo;
154 
155 typedef struct {
156     int result;
157     GAP_LeSecMode1Level mode1Level;
158     GAP_LeSecMode2Level mode2Level;
159 } GapLeSetSecurityModeInfo;
160 
161 typedef struct {
162     int result;
163     BtAddr *addr;
164     GAP_LeSecurityStatus *status;
165     uint8_t *encKeySize;
166 } GapLeGetSecurityStatusInfo;
167 
168 typedef struct {
169     int result;
170     BtAddr *addr;
171     GAP_LeSecurityStatus status;
172     GapLeRequestSecurityResult callback;
173     void *context;
174 } GapLeRequestSecurityInfo;
175 
176 typedef struct {
177     int result;
178     uint8_t minSize;
179 } GapLeSetMinEncKeySizeInfo;
180 
181 typedef struct {
182     int result;
183     BtAddr *addr;
184     GapLePairFeature localFrature;
185 } GapLePairFeatureRspInfo;
186 
187 typedef struct {
188     int result;
189     BtAddr *addr;
190     uint8_t accept;
191     uint32_t number;
192 } GapLePairPassKeyRspInfo;
193 
194 typedef struct {
195     int result;
196     BtAddr *addr;
197     uint8_t accept;
198     uint8_t *oobData;
199 } GapLePairOobRspInfo;
200 
201 typedef struct {
202     int result;
203     BtAddr *addr;
204     uint8_t accept;
205     uint8_t *oobDataC;
206     uint8_t *oobDataR;
207 } GapLePairScOobRspInfo;
208 
209 typedef struct {
210     int result;
211     BtAddr *addr;
212     uint8_t accept;
213 } GapLePairScUserConfirmRspInfo;
214 
215 typedef struct {
216     int result;
217     BtAddr *addr;
218     GapSignatureData dataInfo;
219     GAPSignatureGenerationResult callback;
220     void *context;
221 } GapLeDataSignatureGenerationInfo;
222 
223 typedef struct {
224     int result;
225     BtAddr *addr;
226     GapSignatureData dataInfo;
227     uint8_t signature[GAP_SIGNATURE_SIZE];
228     GAPSignatureConfirmationResult callback;
229     void *context;
230 } GapLeDataSignatureConfirmationInfo;
231 
232 #ifdef GAP_LE_SUPPORT
233 
GapLeSetRoleTask(void * ctx)234 static void GapLeSetRoleTask(void *ctx)
235 {
236     GapLeSetRoleInfo *info = ctx;
237     info->result = GAP_LeSetRole(info->role);
238 }
239 
GAPIF_LeSetRole(uint8_t role)240 int GAPIF_LeSetRole(uint8_t role)
241 {
242     LOG_INFO("%{public}s: role:0x%02x", __FUNCTION__, role);
243     GapLeSetRoleInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeSetRoleInfo));
244     if (ctx == NULL) {
245         return BT_NO_MEMORY;
246     }
247 
248     (void)memset_s(ctx, sizeof(GapLeSetRoleInfo), 0x00, sizeof(GapLeSetRoleInfo));
249 
250     ctx->role = role;
251 
252     int ret = GapRunTaskBlockProcess(GapLeSetRoleTask, ctx);
253     if (ret == BT_SUCCESS) {
254         ret = ctx->result;
255     }
256 
257     MEM_MALLOC.free(ctx);
258     return ret;
259 }
260 
GapLeSetStaticIdentityAddrTask(void * ctx)261 static void GapLeSetStaticIdentityAddrTask(void *ctx)
262 {
263     GapGeneralPointerInfo *info = ctx;
264     info->result = GAP_LeSetStaticIdentityAddr(info->pointer);
265 }
266 
GAPIF_LeSetStaticIdentityAddr(uint8_t addr[BT_ADDRESS_SIZE])267 int GAPIF_LeSetStaticIdentityAddr(uint8_t addr[BT_ADDRESS_SIZE])
268 {
269     LOG_INFO("%{public}s: ", __FUNCTION__);
270     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
271     if (ctx == NULL) {
272         return BT_NO_MEMORY;
273     }
274 
275     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
276 
277     ctx->pointer = addr;
278 
279     int ret = GapRunTaskBlockProcess(GapLeSetStaticIdentityAddrTask, ctx);
280     if (ret == BT_SUCCESS) {
281         ret = ctx->result;
282     }
283 
284     MEM_MALLOC.free(ctx);
285     return ret;
286 }
287 
GapLeGenResPriAddrTask(void * ctx)288 static void GapLeGenResPriAddrTask(void *ctx)
289 {
290     GapGeneralCallbackInfo *info = ctx;
291     info->result = GAP_LeGenResPriAddrAsync(info->callback, info->context);
292 }
293 
GAPIF_LeGenResPriAddr(GenResPriAddrResult callback,void * context)294 int GAPIF_LeGenResPriAddr(GenResPriAddrResult callback, void *context)
295 {
296     LOG_INFO("%{public}s: ", __FUNCTION__);
297     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
298     if (ctx == NULL) {
299         return BT_NO_MEMORY;
300     }
301 
302     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
303 
304     ctx->callback = callback;
305     ctx->context = context;
306 
307     int ret = GapRunTaskBlockProcess(GapLeGenResPriAddrTask, ctx);
308     if (ret == BT_SUCCESS) {
309         ret = ctx->result;
310     }
311 
312     MEM_MALLOC.free(ctx);
313     return ret;
314 }
315 
GapLeExAdvGetMaxDataLenTask(void * ctx)316 static void GapLeExAdvGetMaxDataLenTask(void *ctx)
317 {
318     GapGeneralPointerInfo *info = ctx;
319     info->result = GAP_LeExAdvGetMaxDataLen(info->pointer);
320 }
321 
GAPIF_LeExAdvGetMaxDataLen(uint16_t * len)322 int GAPIF_LeExAdvGetMaxDataLen(uint16_t *len)
323 {
324     LOG_INFO("%{public}s: ", __FUNCTION__);
325     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
326     if (ctx == NULL) {
327         return BT_NO_MEMORY;
328     }
329 
330     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
331 
332     ctx->pointer = len;
333 
334     int ret = GapRunTaskBlockProcess(GapLeExAdvGetMaxDataLenTask, ctx);
335     if (ret == BT_SUCCESS) {
336         ret = ctx->result;
337     }
338 
339     MEM_MALLOC.free(ctx);
340     return ret;
341 }
342 
GapLeExAdvGetMaxHandleNumTask(void * ctx)343 static void GapLeExAdvGetMaxHandleNumTask(void *ctx)
344 {
345     GapGeneralPointerInfo *info = ctx;
346     info->result = GAP_LeExAdvGetMaxHandleNum(info->pointer);
347 }
348 
GAPIF_LeExAdvGetMaxHandleNum(uint8_t * num)349 int GAPIF_LeExAdvGetMaxHandleNum(uint8_t *num)
350 {
351     LOG_INFO("%{public}s: ", __FUNCTION__);
352     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
353     if (ctx == NULL) {
354         return BT_NO_MEMORY;
355     }
356 
357     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
358 
359     ctx->pointer = num;
360 
361     int ret = GapRunTaskBlockProcess(GapLeExAdvGetMaxHandleNumTask, ctx);
362     if (ret == BT_SUCCESS) {
363         ret = ctx->result;
364     }
365 
366     MEM_MALLOC.free(ctx);
367     return ret;
368 }
369 
GapRegisterExAdvCallbackTask(void * ctx)370 static void GapRegisterExAdvCallbackTask(void *ctx)
371 {
372     GapGeneralCallbackInfo *info = ctx;
373     info->result = GAP_RegisterExAdvCallback(info->callback, info->context);
374 }
375 
GAPIF_RegisterExAdvCallback(const GapExAdvCallback * callback,void * context)376 int GAPIF_RegisterExAdvCallback(const GapExAdvCallback *callback, void *context)
377 {
378     LOG_INFO("%{public}s: ", __FUNCTION__);
379     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
380     if (ctx == NULL) {
381         return BT_NO_MEMORY;
382     }
383 
384     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
385 
386     ctx->callback = (void *)callback;
387     ctx->context = context;
388 
389     int ret = GapRunTaskBlockProcess(GapRegisterExAdvCallbackTask, ctx);
390     if (ret == BT_SUCCESS) {
391         ret = ctx->result;
392     }
393 
394     MEM_MALLOC.free(ctx);
395     return ret;
396 }
397 
GapDeregisterExAdvCallbackTask(void * ctx)398 static void GapDeregisterExAdvCallbackTask(void *ctx)
399 {
400     GapGeneralVoidInfo *info = ctx;
401     info->result = GAP_DeregisterExAdvCallback();
402 }
403 
GAPIF_DeregisterExAdvCallback(void)404 int GAPIF_DeregisterExAdvCallback(void)
405 {
406     LOG_INFO("%{public}s: ", __FUNCTION__);
407     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
408     if (ctx == NULL) {
409         return BT_NO_MEMORY;
410     }
411 
412     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
413 
414     int ret = GapRunTaskBlockProcess(GapDeregisterExAdvCallbackTask, ctx);
415     if (ret == BT_SUCCESS) {
416         ret = ctx->result;
417     }
418 
419     MEM_MALLOC.free(ctx);
420     return ret;
421 }
422 
GapLeExAdvSetRandAddrTask(void * ctx)423 static void GapLeExAdvSetRandAddrTask(void *ctx)
424 {
425     GapLeExAdvSetRandAddrInfo *info = ctx;
426     info->result = GAP_LeExAdvSetRandAddr(info->advHandle, info->addr);
427 }
428 
GAPIF_LeExAdvSetRandAddr(uint8_t advHandle,const uint8_t addr[BT_ADDRESS_SIZE])429 int GAPIF_LeExAdvSetRandAddr(uint8_t advHandle, const uint8_t addr[BT_ADDRESS_SIZE])
430 {
431     LOG_INFO("%{public}s: advHandle:%hhu " BT_ADDR_FMT, __FUNCTION__, advHandle, BT_ADDR_FMT_OUTPUT(addr));
432     GapLeExAdvSetRandAddrInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeExAdvSetRandAddrInfo));
433     if (ctx == NULL) {
434         return BT_NO_MEMORY;
435     }
436 
437     (void)memset_s(ctx, sizeof(GapLeExAdvSetRandAddrInfo), 0x00, sizeof(GapLeExAdvSetRandAddrInfo));
438 
439     ctx->advHandle = advHandle;
440     ctx->addr = (uint8_t *)addr;
441 
442     int ret = GapRunTaskBlockProcess(GapLeExAdvSetRandAddrTask, ctx);
443     if (ret == BT_SUCCESS) {
444         ret = ctx->result;
445     }
446 
447     MEM_MALLOC.free(ctx);
448     return ret;
449 }
450 
GapLeExAdvSetParamTask(void * ctx)451 static void GapLeExAdvSetParamTask(void *ctx)
452 {
453     GapLeExAdvSetParamInfo *info = ctx;
454     info->result = GAP_LeExAdvSetParam(info->advHandle, info->properties, info->txPower, info->advExParam);
455 }
456 
GAPIF_LeExAdvSetParam(uint8_t advHandle,uint8_t properties,int8_t txPower,GapLeExAdvParam advExParam)457 int GAPIF_LeExAdvSetParam(uint8_t advHandle, uint8_t properties, int8_t txPower, GapLeExAdvParam advExParam)
458 {
459     LOG_INFO("%{public}s: advHandle:%hhu properties:0x%02x", __FUNCTION__, advHandle, properties);
460     GapLeExAdvSetParamInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeExAdvSetParamInfo));
461     if (ctx == NULL) {
462         return BT_NO_MEMORY;
463     }
464 
465     (void)memset_s(ctx, sizeof(GapLeExAdvSetParamInfo), 0x00, sizeof(GapLeExAdvSetParamInfo));
466 
467     ctx->advHandle = advHandle;
468     ctx->properties = properties;
469     ctx->txPower = txPower;
470     ctx->advExParam = advExParam;
471 
472     int ret = GapRunTaskBlockProcess(GapLeExAdvSetParamTask, ctx);
473     if (ret == BT_SUCCESS) {
474         ret = ctx->result;
475     }
476 
477     MEM_MALLOC.free(ctx);
478     return ret;
479 }
480 
GapLeExAdvSetDataTask(void * ctx)481 static void GapLeExAdvSetDataTask(void *ctx)
482 {
483     GapLeExAdvSetDataInfo *info = ctx;
484     info->result = GAP_LeExAdvSetData(
485         info->advHandle, info->operation, info->fragmentPreference, info->advDataLength, info->advData);
486 }
487 
GAPIF_LeExAdvSetData(uint8_t advHandle,uint8_t operation,uint8_t fragmentPreference,uint8_t advDataLength,const uint8_t * advData)488 int GAPIF_LeExAdvSetData(
489     uint8_t advHandle, uint8_t operation, uint8_t fragmentPreference, uint8_t advDataLength, const uint8_t *advData)
490 {
491     LOG_INFO("%{public}s: advHandle:%hhu", __FUNCTION__, advHandle);
492     GapLeExAdvSetDataInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeExAdvSetDataInfo));
493     if (ctx == NULL) {
494         return BT_NO_MEMORY;
495     }
496 
497     (void)memset_s(ctx, sizeof(GapLeExAdvSetDataInfo), 0x00, sizeof(GapLeExAdvSetDataInfo));
498 
499     ctx->advHandle = advHandle;
500     ctx->operation = operation;
501     ctx->fragmentPreference = fragmentPreference;
502     ctx->advDataLength = advDataLength;
503     ctx->advData = (uint8_t *)advData;
504 
505     int ret = GapRunTaskBlockProcess(GapLeExAdvSetDataTask, ctx);
506     if (ret == BT_SUCCESS) {
507         ret = ctx->result;
508     }
509 
510     MEM_MALLOC.free(ctx);
511     return ret;
512 }
513 
GapLeExAdvSetScanRspDataTask(void * ctx)514 static void GapLeExAdvSetScanRspDataTask(void *ctx)
515 {
516     GapLeExAdvSetDataInfo *info = ctx;
517     info->result = GAP_LeExAdvSetScanRspData(
518         info->advHandle, info->operation, info->fragmentPreference, info->advDataLength, info->advData);
519 }
520 
GAPIF_LeExAdvSetScanRspData(uint8_t advHandle,uint8_t operation,uint8_t fragmentPreference,uint8_t scanResponseDataLen,const uint8_t * scanResponseData)521 int GAPIF_LeExAdvSetScanRspData(uint8_t advHandle, uint8_t operation, uint8_t fragmentPreference,
522     uint8_t scanResponseDataLen, const uint8_t *scanResponseData)
523 {
524     LOG_INFO("%{public}s: advHandle:%hhu", __FUNCTION__, advHandle);
525     GapLeExAdvSetDataInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeExAdvSetDataInfo));
526     if (ctx == NULL) {
527         return BT_NO_MEMORY;
528     }
529 
530     (void)memset_s(ctx, sizeof(GapLeExAdvSetDataInfo), 0x00, sizeof(GapLeExAdvSetDataInfo));
531 
532     ctx->advHandle = advHandle;
533     ctx->operation = operation;
534     ctx->fragmentPreference = fragmentPreference;
535     ctx->advDataLength = scanResponseDataLen;
536     ctx->advData = (uint8_t *)scanResponseData;
537 
538     int ret = GapRunTaskBlockProcess(GapLeExAdvSetScanRspDataTask, ctx);
539     if (ret == BT_SUCCESS) {
540         ret = ctx->result;
541     }
542 
543     MEM_MALLOC.free(ctx);
544     return ret;
545 }
546 
GapLeExAdvSetEnableTask(void * ctx)547 static void GapLeExAdvSetEnableTask(void *ctx)
548 {
549     GapLeExAdvSetEnableInfo *info = ctx;
550     info->result = GAP_LeExAdvSetEnable(info->enable, info->numberOfSet, info->advSet);
551 }
552 
GAPIF_LeExAdvSetEnable(uint8_t enable,uint8_t numberOfSet,const GapExAdvSet * advSet)553 int GAPIF_LeExAdvSetEnable(uint8_t enable, uint8_t numberOfSet, const GapExAdvSet *advSet)
554 {
555     LOG_INFO("%{public}s: enable:%hhu", __FUNCTION__, enable);
556     GapLeExAdvSetEnableInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeExAdvSetEnableInfo));
557     if (ctx == NULL) {
558         return BT_NO_MEMORY;
559     }
560 
561     (void)memset_s(ctx, sizeof(GapLeExAdvSetEnableInfo), 0x00, sizeof(GapLeExAdvSetEnableInfo));
562 
563     ctx->enable = enable;
564     ctx->numberOfSet = numberOfSet;
565     ctx->advSet = (GapExAdvSet *)advSet;
566 
567     int ret = GapRunTaskBlockProcess(GapLeExAdvSetEnableTask, ctx);
568     if (ret == BT_SUCCESS) {
569         ret = ctx->result;
570     }
571 
572     MEM_MALLOC.free(ctx);
573     return ret;
574 }
575 
GapLeExAdvClearHandleTask(void * ctx)576 static void GapLeExAdvClearHandleTask(void *ctx)
577 {
578     GapGeneralVoidInfo *info = ctx;
579     info->result = GAP_LeExAdvClearHandle();
580 }
581 
GAPIF_LeExAdvClearHandle(void)582 int GAPIF_LeExAdvClearHandle(void)
583 {
584     LOG_INFO("%{public}s: ", __FUNCTION__);
585     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
586     if (ctx == NULL) {
587         return BT_NO_MEMORY;
588     }
589 
590     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
591 
592     int ret = GapRunTaskBlockProcess(GapLeExAdvClearHandleTask, ctx);
593     if (ret == BT_SUCCESS) {
594         ret = ctx->result;
595     }
596 
597     MEM_MALLOC.free(ctx);
598     return ret;
599 }
600 
GapRegisterAdvCallbackTask(void * ctx)601 static void GapRegisterAdvCallbackTask(void *ctx)
602 {
603     GapGeneralCallbackInfo *info = ctx;
604     info->result = GAP_RegisterAdvCallback(info->callback, info->context);
605 }
606 
GAPIF_RegisterAdvCallback(const GapAdvCallback * callback,void * context)607 int GAPIF_RegisterAdvCallback(const GapAdvCallback *callback, void *context)
608 {
609     LOG_INFO("%{public}s: ", __FUNCTION__);
610     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
611     if (ctx == NULL) {
612         return BT_NO_MEMORY;
613     }
614 
615     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
616 
617     ctx->callback = (void *)callback;
618     ctx->context = context;
619 
620     int ret = GapRunTaskBlockProcess(GapRegisterAdvCallbackTask, ctx);
621     if (ret == BT_SUCCESS) {
622         ret = ctx->result;
623     }
624 
625     MEM_MALLOC.free(ctx);
626     return ret;
627 }
628 
GapDeregisterAdvCallbackTask(void * ctx)629 static void GapDeregisterAdvCallbackTask(void *ctx)
630 {
631     GapGeneralVoidInfo *info = ctx;
632     info->result = GAP_DeregisterAdvCallback();
633 }
634 
GAPIF_DeregisterAdvCallback(void)635 int GAPIF_DeregisterAdvCallback(void)
636 {
637     LOG_INFO("%{public}s: ", __FUNCTION__);
638     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
639     if (ctx == NULL) {
640         return BT_NO_MEMORY;
641     }
642 
643     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
644 
645     int ret = GapRunTaskBlockProcess(GapDeregisterAdvCallbackTask, ctx);
646     if (ret == BT_SUCCESS) {
647         ret = ctx->result;
648     }
649 
650     MEM_MALLOC.free(ctx);
651     return ret;
652 }
653 
GapLeAdvSetParamTask(void * ctx)654 static void GapLeAdvSetParamTask(void *ctx)
655 {
656     GapLeAdvSetParamInfo *info = ctx;
657     info->result = GAP_LeAdvSetParam(info->advType, info->advParam);
658 }
659 
GAPIF_LeAdvSetParam(uint8_t advType,GapLeAdvParam advParam)660 int GAPIF_LeAdvSetParam(uint8_t advType, GapLeAdvParam advParam)
661 {
662     LOG_INFO("%{public}s: advType:%hhu", __FUNCTION__, advType);
663     GapLeAdvSetParamInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeAdvSetParamInfo));
664     if (ctx == NULL) {
665         return BT_NO_MEMORY;
666     }
667 
668     (void)memset_s(ctx, sizeof(GapLeAdvSetParamInfo), 0x00, sizeof(GapLeAdvSetParamInfo));
669 
670     ctx->advType = advType;
671     ctx->advParam = advParam;
672 
673     int ret = GapRunTaskBlockProcess(GapLeAdvSetParamTask, ctx);
674     if (ret == BT_SUCCESS) {
675         ret = ctx->result;
676     }
677 
678     MEM_MALLOC.free(ctx);
679     return ret;
680 }
681 
GapLeAdvReadTxPowerTask(void * ctx)682 static void GapLeAdvReadTxPowerTask(void *ctx)
683 {
684     GapGeneralVoidInfo *info = ctx;
685     info->result = GAP_LeAdvReadTxPower();
686 }
687 
GAPIF_LeAdvReadTxPower(void)688 int GAPIF_LeAdvReadTxPower(void)
689 {
690     LOG_INFO("%{public}s: ", __FUNCTION__);
691     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
692     if (ctx == NULL) {
693         return BT_NO_MEMORY;
694     }
695 
696     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
697 
698     int ret = GapRunTaskBlockProcess(GapLeAdvReadTxPowerTask, ctx);
699     if (ret == BT_SUCCESS) {
700         ret = ctx->result;
701     }
702 
703     MEM_MALLOC.free(ctx);
704     return ret;
705 }
706 
GapLeAdvSetDataTask(void * ctx)707 static void GapLeAdvSetDataTask(void *ctx)
708 {
709     GapLeAdvSetDataInfo *info = ctx;
710     info->result = GAP_LeAdvSetData(info->advDataLength, info->advData);
711 }
712 
GAPIF_LeAdvSetData(uint8_t advDataLength,const uint8_t * advData)713 int GAPIF_LeAdvSetData(uint8_t advDataLength, const uint8_t *advData)
714 {
715     LOG_INFO("%{public}s: ", __FUNCTION__);
716     GapLeAdvSetDataInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeAdvSetDataInfo));
717     if (ctx == NULL) {
718         return BT_NO_MEMORY;
719     }
720 
721     (void)memset_s(ctx, sizeof(GapLeAdvSetDataInfo), 0x00, sizeof(GapLeAdvSetDataInfo));
722 
723     ctx->advDataLength = advDataLength;
724     ctx->advData = (uint8_t *)advData;
725 
726     int ret = GapRunTaskBlockProcess(GapLeAdvSetDataTask, ctx);
727     if (ret == BT_SUCCESS) {
728         ret = ctx->result;
729     }
730 
731     MEM_MALLOC.free(ctx);
732     return ret;
733 }
734 
GapLeAdvSetScanRspDataTask(void * ctx)735 static void GapLeAdvSetScanRspDataTask(void *ctx)
736 {
737     GapLeAdvSetDataInfo *info = ctx;
738     info->result = GAP_LeAdvSetScanRspData(info->advDataLength, info->advData);
739 }
740 
GAPIF_LeAdvSetScanRspData(uint8_t advDataLength,const uint8_t * advData)741 int GAPIF_LeAdvSetScanRspData(uint8_t advDataLength, const uint8_t *advData)
742 {
743     LOG_INFO("%{public}s: ", __FUNCTION__);
744     GapLeAdvSetDataInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeAdvSetDataInfo));
745     if (ctx == NULL) {
746         return BT_NO_MEMORY;
747     }
748 
749     (void)memset_s(ctx, sizeof(GapLeAdvSetDataInfo), 0x00, sizeof(GapLeAdvSetDataInfo));
750 
751     ctx->advDataLength = advDataLength;
752     ctx->advData = (uint8_t *)advData;
753 
754     int ret = GapRunTaskBlockProcess(GapLeAdvSetScanRspDataTask, ctx);
755     if (ret == BT_SUCCESS) {
756         ret = ctx->result;
757     }
758 
759     MEM_MALLOC.free(ctx);
760     return ret;
761 }
762 
GapLeAdvSetEnableTask(void * ctx)763 static void GapLeAdvSetEnableTask(void *ctx)
764 {
765     GapLeAdvSetEnableInfo *info = ctx;
766     info->result = GAP_LeAdvSetEnable(info->enable);
767 }
768 
GAPIF_LeAdvSetEnable(uint8_t enable)769 int GAPIF_LeAdvSetEnable(uint8_t enable)
770 {
771     LOG_INFO("%{public}s: enable:%hhu", __FUNCTION__, enable);
772     GapLeAdvSetEnableInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeAdvSetEnableInfo));
773     if (ctx == NULL) {
774         return BT_NO_MEMORY;
775     }
776 
777     (void)memset_s(ctx, sizeof(GapLeAdvSetEnableInfo), 0x00, sizeof(GapLeAdvSetEnableInfo));
778 
779     ctx->enable = enable;
780 
781     int ret = GapRunTaskBlockProcess(GapLeAdvSetEnableTask, ctx);
782     if (ret == BT_SUCCESS) {
783         ret = ctx->result;
784     }
785 
786     MEM_MALLOC.free(ctx);
787     return ret;
788 }
789 
GapRegisterScanCallbackTask(void * ctx)790 static void GapRegisterScanCallbackTask(void *ctx)
791 {
792     GapGeneralCallbackInfo *info = ctx;
793     info->result = GAP_RegisterScanCallback(info->callback, info->context);
794 }
795 
GAPIF_RegisterScanCallback(const GapScanCallback * callback,void * context)796 int GAPIF_RegisterScanCallback(const GapScanCallback *callback, void *context)
797 {
798     LOG_INFO("%{public}s: ", __FUNCTION__);
799     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
800     if (ctx == NULL) {
801         return BT_NO_MEMORY;
802     }
803 
804     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
805 
806     ctx->callback = (void *)callback;
807     ctx->context = context;
808 
809     int ret = GapRunTaskBlockProcess(GapRegisterScanCallbackTask, ctx);
810     if (ret == BT_SUCCESS) {
811         ret = ctx->result;
812     }
813 
814     MEM_MALLOC.free(ctx);
815     return ret;
816 }
817 
GapDeregisterScanCallbackTask(void * ctx)818 static void GapDeregisterScanCallbackTask(void *ctx)
819 {
820     GapGeneralVoidInfo *info = ctx;
821     info->result = GAP_DeregisterScanCallback();
822 }
823 
GAPIF_DeregisterScanCallback(void)824 int GAPIF_DeregisterScanCallback(void)
825 {
826     LOG_INFO("%{public}s: ", __FUNCTION__);
827     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
828     if (ctx == NULL) {
829         return BT_NO_MEMORY;
830     }
831 
832     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
833 
834     int ret = GapRunTaskBlockProcess(GapDeregisterScanCallbackTask, ctx);
835     if (ret == BT_SUCCESS) {
836         ret = ctx->result;
837     }
838 
839     MEM_MALLOC.free(ctx);
840     return ret;
841 }
842 
GapLeScanSetParamTask(void * ctx)843 static void GapLeScanSetParamTask(void *ctx)
844 {
845     GapLeScanSetParamInfo *info = ctx;
846     info->result = GAP_LeScanSetParam(info->param, info->scanFilterPolity);
847 }
848 
GAPIF_LeScanSetParam(GapLeScanParam param,uint8_t scanFilterPolity)849 int GAPIF_LeScanSetParam(GapLeScanParam param, uint8_t scanFilterPolity)
850 {
851     LOG_INFO("%{public}s: scanType:%hhu", __FUNCTION__, param.scanType);
852     GapLeScanSetParamInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeScanSetParamInfo));
853     if (ctx == NULL) {
854         return BT_NO_MEMORY;
855     }
856 
857     (void)memset_s(ctx, sizeof(GapLeScanSetParamInfo), 0x00, sizeof(GapLeScanSetParamInfo));
858 
859     ctx->param = param;
860     ctx->scanFilterPolity = scanFilterPolity;
861 
862     int ret = GapRunTaskBlockProcess(GapLeScanSetParamTask, ctx);
863     if (ret == BT_SUCCESS) {
864         ret = ctx->result;
865     }
866 
867     MEM_MALLOC.free(ctx);
868     return ret;
869 }
870 
GapLeScanSetEnableTask(void * ctx)871 static void GapLeScanSetEnableTask(void *ctx)
872 {
873     GapLeScanSetEnableInfo *info = ctx;
874     info->result = GAP_LeScanSetEnable(info->scanEnable, info->filterDuplicates);
875 }
876 
GAPIF_LeScanSetEnable(uint8_t scanEnable,uint8_t filterDuplicates)877 int GAPIF_LeScanSetEnable(uint8_t scanEnable, uint8_t filterDuplicates)
878 {
879     LOG_INFO("%{public}s: scanEnable:%hhu", __FUNCTION__, scanEnable);
880     GapLeScanSetEnableInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeScanSetEnableInfo));
881     if (ctx == NULL) {
882         return BT_NO_MEMORY;
883     }
884 
885     (void)memset_s(ctx, sizeof(GapLeScanSetEnableInfo), 0x00, sizeof(GapLeScanSetEnableInfo));
886 
887     ctx->scanEnable = scanEnable;
888     ctx->filterDuplicates = filterDuplicates;
889 
890     int ret = GapRunTaskBlockProcess(GapLeScanSetEnableTask, ctx);
891     if (ret == BT_SUCCESS) {
892         ret = ctx->result;
893     }
894 
895     MEM_MALLOC.free(ctx);
896     return ret;
897 }
898 
GapRegisterExScanCallbackTask(void * ctx)899 static void GapRegisterExScanCallbackTask(void *ctx)
900 {
901     GapGeneralCallbackInfo *info = ctx;
902     info->result = GAP_RegisterExScanCallback(info->callback, info->context);
903 }
904 
GAPIF_RegisterExScanCallback(const GapExScanCallback * callback,void * context)905 int GAPIF_RegisterExScanCallback(const GapExScanCallback *callback, void *context)
906 {
907     LOG_INFO("%{public}s: ", __FUNCTION__);
908     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
909     if (ctx == NULL) {
910         return BT_NO_MEMORY;
911     }
912 
913     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
914 
915     ctx->callback = (void *)callback;
916     ctx->context = context;
917 
918     int ret = GapRunTaskBlockProcess(GapRegisterExScanCallbackTask, ctx);
919     if (ret == BT_SUCCESS) {
920         ret = ctx->result;
921     }
922 
923     MEM_MALLOC.free(ctx);
924     return ret;
925 }
926 
GapDeregisterExScanCallbackTask(void * ctx)927 static void GapDeregisterExScanCallbackTask(void *ctx)
928 {
929     GapGeneralVoidInfo *info = ctx;
930     info->result = GAP_DeregisterExScanCallback();
931 }
932 
GAPIF_DeregisterExScanCallback(void)933 int GAPIF_DeregisterExScanCallback(void)
934 {
935     LOG_INFO("%{public}s: ", __FUNCTION__);
936     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
937     if (ctx == NULL) {
938         return BT_NO_MEMORY;
939     }
940 
941     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
942 
943     int ret = GapRunTaskBlockProcess(GapDeregisterExScanCallbackTask, ctx);
944     if (ret == BT_SUCCESS) {
945         ret = ctx->result;
946     }
947 
948     MEM_MALLOC.free(ctx);
949     return ret;
950 }
951 
GapLeExScanSetParamTask(void * ctx)952 static void GapLeExScanSetParamTask(void *ctx)
953 {
954     GapLeExScanSetParamInfo *info = ctx;
955     info->result = GAP_LeExScanSetParam(info->scanFilterPolity, info->scanPhys, info->param);
956 }
957 
GAPIF_LeExScanSetParam(uint8_t scanFilterPolity,uint8_t scanPhys,const GapLeScanParam param[])958 int GAPIF_LeExScanSetParam(uint8_t scanFilterPolity, uint8_t scanPhys, const GapLeScanParam param[])
959 {
960     LOG_INFO("%{public}s: ", __FUNCTION__);
961     GapLeExScanSetParamInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeExScanSetParamInfo));
962     if (ctx == NULL) {
963         return BT_NO_MEMORY;
964     }
965 
966     (void)memset_s(ctx, sizeof(GapLeExScanSetParamInfo), 0x00, sizeof(GapLeExScanSetParamInfo));
967 
968     ctx->scanFilterPolity = scanFilterPolity;
969     ctx->scanPhys = scanPhys;
970     ctx->param = (GapLeScanParam *)param;
971 
972     int ret = GapRunTaskBlockProcess(GapLeExScanSetParamTask, ctx);
973     if (ret == BT_SUCCESS) {
974         ret = ctx->result;
975     }
976 
977     MEM_MALLOC.free(ctx);
978     return ret;
979 }
980 
GapLeExScanSetEnableTask(void * ctx)981 static void GapLeExScanSetEnableTask(void *ctx)
982 {
983     GapLeExScanSetEnableInfo *info = ctx;
984     info->result = GAP_LeExScanSetEnable(info->scanEnable, info->filterDuplicates, info->duration, info->period);
985 }
986 
GAPIF_LeExScanSetEnable(uint8_t scanEnable,uint8_t filterDuplicates,uint16_t duration,uint16_t period)987 int GAPIF_LeExScanSetEnable(uint8_t scanEnable, uint8_t filterDuplicates, uint16_t duration, uint16_t period)
988 {
989     LOG_INFO("%{public}s: scanEnable:%hhu", __FUNCTION__, scanEnable);
990     GapLeExScanSetEnableInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeExScanSetEnableInfo));
991     if (ctx == NULL) {
992         return BT_NO_MEMORY;
993     }
994 
995     (void)memset_s(ctx, sizeof(GapLeExScanSetEnableInfo), 0x00, sizeof(GapLeExScanSetEnableInfo));
996 
997     ctx->scanEnable = scanEnable;
998     ctx->filterDuplicates = filterDuplicates;
999     ctx->duration = duration;
1000     ctx->period = period;
1001 
1002     int ret = GapRunTaskBlockProcess(GapLeExScanSetEnableTask, ctx);
1003     if (ret == BT_SUCCESS) {
1004         ret = ctx->result;
1005     }
1006 
1007     MEM_MALLOC.free(ctx);
1008     return ret;
1009 }
1010 
GapRegisterLeConnCallbackTask(void * ctx)1011 static void GapRegisterLeConnCallbackTask(void *ctx)
1012 {
1013     GapGeneralCallbackInfo *info = ctx;
1014     info->result = GAP_RegisterLeConnCallback(info->callback, info->context);
1015 }
1016 
GAPIF_RegisterLeConnCallback(const GapLeConnCallback * callback,void * context)1017 int GAPIF_RegisterLeConnCallback(const GapLeConnCallback *callback, void *context)
1018 {
1019     LOG_INFO("%{public}s: ", __FUNCTION__);
1020     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
1021     if (ctx == NULL) {
1022         return BT_NO_MEMORY;
1023     }
1024 
1025     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
1026 
1027     ctx->callback = (void *)callback;
1028     ctx->context = context;
1029 
1030     int ret = GapRunTaskBlockProcess(GapRegisterLeConnCallbackTask, ctx);
1031     if (ret == BT_SUCCESS) {
1032         ret = ctx->result;
1033     }
1034 
1035     MEM_MALLOC.free(ctx);
1036     return ret;
1037 }
1038 
GapDeregisterLeConnCallbackTask(void * ctx)1039 static void GapDeregisterLeConnCallbackTask(void *ctx)
1040 {
1041     GapGeneralVoidInfo *info = ctx;
1042     info->result = GAP_DeregisterLeConnCallback();
1043 }
1044 
GAPIF_DeregisterLeConnCallback(void)1045 int GAPIF_DeregisterLeConnCallback(void)
1046 {
1047     LOG_INFO("%{public}s: ", __FUNCTION__);
1048     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
1049     if (ctx == NULL) {
1050         return BT_NO_MEMORY;
1051     }
1052 
1053     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
1054 
1055     int ret = GapRunTaskBlockProcess(GapDeregisterLeConnCallbackTask, ctx);
1056     if (ret == BT_SUCCESS) {
1057         ret = ctx->result;
1058     }
1059 
1060     MEM_MALLOC.free(ctx);
1061     return ret;
1062 }
1063 
GapLeConnParamUpdateTask(void * ctx)1064 static void GapLeConnParamUpdateTask(void *ctx)
1065 {
1066     GapLeConnParamUpdateInfo *info = ctx;
1067     info->result = GAP_LeConnParamUpdate(info->addr, info->connParam);
1068 }
1069 
GAPIF_LeConnParamUpdate(const BtAddr * addr,const GapLeConnectionParameter * connParam)1070 int GAPIF_LeConnParamUpdate(const BtAddr *addr, const GapLeConnectionParameter *connParam)
1071 {
1072     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1073     GapLeConnParamUpdateInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeConnParamUpdateInfo));
1074     if (ctx == NULL) {
1075         return BT_NO_MEMORY;
1076     }
1077 
1078     (void)memset_s(ctx, sizeof(GapLeConnParamUpdateInfo), 0x00, sizeof(GapLeConnParamUpdateInfo));
1079 
1080     ctx->addr = (BtAddr *)addr;
1081     ctx->connParam = connParam;
1082 
1083     int ret = GapRunTaskBlockProcess(GapLeConnParamUpdateTask, ctx);
1084     if (ret == BT_SUCCESS) {
1085         ret = ctx->result;
1086     }
1087 
1088     MEM_MALLOC.free(ctx);
1089     return ret;
1090 }
1091 
GapLeConnectionParameterRspTask(void * ctx)1092 static void GapLeConnectionParameterRspTask(void *ctx)
1093 {
1094     GapLeConnectionParameterRspInfo *info = ctx;
1095     info->result = GAP_LeConnectionParameterRsp(info->addr, info->accept, info->connParam);
1096 }
1097 
GAPIF_LeConnectionParameterRsp(const BtAddr * addr,uint8_t accept,const GapLeConnectionParameter * connParam)1098 int GAPIF_LeConnectionParameterRsp(const BtAddr *addr, uint8_t accept, const GapLeConnectionParameter *connParam)
1099 {
1100     LOG_INFO("%{public}s: accept:%hhu " BT_ADDR_FMT, __FUNCTION__, accept, BT_ADDR_FMT_OUTPUT(addr->addr));
1101     GapLeConnectionParameterRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeConnectionParameterRspInfo));
1102     if (ctx == NULL) {
1103         return BT_NO_MEMORY;
1104     }
1105 
1106     (void)memset_s(ctx, sizeof(GapLeConnectionParameterRspInfo), 0x00, sizeof(GapLeConnectionParameterRspInfo));
1107 
1108     ctx->addr = (BtAddr *)addr;
1109     ctx->accept = accept;
1110     ctx->connParam = connParam;
1111 
1112     int ret = GapRunTaskBlockProcess(GapLeConnectionParameterRspTask, ctx);
1113     if (ret == BT_SUCCESS) {
1114         ret = ctx->result;
1115     }
1116 
1117     MEM_MALLOC.free(ctx);
1118     return ret;
1119 }
1120 
GapRegisterLeSecurityCallbackTask(void * ctx)1121 static void GapRegisterLeSecurityCallbackTask(void *ctx)
1122 {
1123     GapGeneralCallbackInfo *info = ctx;
1124     info->result = GAP_RegisterLeSecurityCallback(info->callback, info->context);
1125 }
1126 
GAPIF_RegisterLeSecurityCallback(const GapLeSecurityCallback * callback,void * context)1127 int GAPIF_RegisterLeSecurityCallback(const GapLeSecurityCallback *callback, void *context)
1128 {
1129     LOG_INFO("%{public}s: ", __FUNCTION__);
1130     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
1131     if (ctx == NULL) {
1132         return BT_NO_MEMORY;
1133     }
1134 
1135     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
1136 
1137     ctx->callback = (void *)callback;
1138     ctx->context = context;
1139 
1140     int ret = GapRunTaskBlockProcess(GapRegisterLeSecurityCallbackTask, ctx);
1141     if (ret == BT_SUCCESS) {
1142         ret = ctx->result;
1143     }
1144 
1145     MEM_MALLOC.free(ctx);
1146     return ret;
1147 }
1148 
GapDeregisterLeSecurityCallbackTask(void * ctx)1149 static void GapDeregisterLeSecurityCallbackTask(void *ctx)
1150 {
1151     GapGeneralVoidInfo *info = ctx;
1152     info->result = GAP_DeregisterLeSecurityCallback();
1153 }
1154 
GAPIF_DeregisterLeSecurityCallback(void)1155 int GAPIF_DeregisterLeSecurityCallback(void)
1156 {
1157     LOG_INFO("%{public}s: ", __FUNCTION__);
1158     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
1159     if (ctx == NULL) {
1160         return BT_NO_MEMORY;
1161     }
1162 
1163     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
1164 
1165     int ret = GapRunTaskBlockProcess(GapDeregisterLeSecurityCallbackTask, ctx);
1166     if (ret == BT_SUCCESS) {
1167         ret = ctx->result;
1168     }
1169 
1170     MEM_MALLOC.free(ctx);
1171     return ret;
1172 }
1173 
GapLeRemoteEncryptionKeyRspTask(void * ctx)1174 static void GapLeRemoteEncryptionKeyRspTask(void *ctx)
1175 {
1176     GapLeEncryptionKeyRspInfo *info = ctx;
1177     info->result = GAP_LeRemoteEncryptionKeyRsp(info->addr, info->accept, info->encKey, info->keyType);
1178 }
1179 
GAPIF_LeRemoteEncryptionKeyRsp(const BtAddr * addr,uint8_t accept,LeEncKey remoteEncKey,uint8_t keyType)1180 int GAPIF_LeRemoteEncryptionKeyRsp(const BtAddr *addr, uint8_t accept, LeEncKey remoteEncKey, uint8_t keyType)
1181 {
1182     LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu keyType:%hhu",
1183         __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept, keyType);
1184     GapLeEncryptionKeyRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeEncryptionKeyRspInfo));
1185     if (ctx == NULL) {
1186         return BT_NO_MEMORY;
1187     }
1188 
1189     (void)memset_s(ctx, sizeof(GapLeEncryptionKeyRspInfo), 0x00, sizeof(GapLeEncryptionKeyRspInfo));
1190 
1191     ctx->addr = (BtAddr *)addr;
1192     ctx->accept = accept;
1193     ctx->encKey = remoteEncKey;
1194     ctx->keyType = keyType;
1195 
1196     int ret = GapRunTaskBlockProcess(GapLeRemoteEncryptionKeyRspTask, ctx);
1197     if (ret == BT_SUCCESS) {
1198         ret = ctx->result;
1199     }
1200 
1201     MEM_MALLOC.free(ctx);
1202     return ret;
1203 }
1204 
GapLeLocalEncryptionKeyRspTask(void * ctx)1205 static void GapLeLocalEncryptionKeyRspTask(void *ctx)
1206 {
1207     GapLeEncryptionKeyRspInfo *info = ctx;
1208     info->result = GAP_LeLocalEncryptionKeyRsp(info->addr, info->accept, info->encKey, info->keyType);
1209 }
1210 
GAPIF_LeLocalEncryptionKeyRsp(const BtAddr * addr,uint8_t accept,LeEncKey localEncKey,uint8_t keyType)1211 int GAPIF_LeLocalEncryptionKeyRsp(const BtAddr *addr, uint8_t accept, LeEncKey localEncKey, uint8_t keyType)
1212 {
1213     LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu keyType:%{public}d",
1214         __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), accept, keyType);
1215     GapLeEncryptionKeyRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeEncryptionKeyRspInfo));
1216     if (ctx == NULL) {
1217         return BT_NO_MEMORY;
1218     }
1219 
1220     (void)memset_s(ctx, sizeof(GapLeEncryptionKeyRspInfo), 0x00, sizeof(GapLeEncryptionKeyRspInfo));
1221 
1222     ctx->addr = (BtAddr *)addr;
1223     ctx->accept = accept;
1224     ctx->encKey = localEncKey;
1225     ctx->keyType = keyType;
1226 
1227     int ret = GapRunTaskBlockProcess(GapLeLocalEncryptionKeyRspTask, ctx);
1228     if (ret == BT_SUCCESS) {
1229         ret = ctx->result;
1230     }
1231 
1232     MEM_MALLOC.free(ctx);
1233     return ret;
1234 }
1235 
GapRequestSigningAlgorithmInfoRspTask(void * ctx)1236 static void GapRequestSigningAlgorithmInfoRspTask(void *ctx)
1237 {
1238     GapRequestSigningAlgorithmInfoRspInfo *info = ctx;
1239     info->result = GAP_RequestSigningAlgorithmInfoRsp(info->addr, info->accept, info->info);
1240 }
1241 
GAPIF_RequestSigningAlgorithmInfoRsp(const BtAddr * addr,uint8_t accept,GapSigningAlgorithmInfo info)1242 int GAPIF_RequestSigningAlgorithmInfoRsp(const BtAddr *addr, uint8_t accept, GapSigningAlgorithmInfo info)
1243 {
1244     LOG_INFO("%{public}s: " BT_ADDR_FMT " accept:%hhu local:%{public}d remote:%{public}d",
1245         __FUNCTION__,
1246         BT_ADDR_FMT_OUTPUT(addr->addr),
1247         accept,
1248         info.localKey != NULL,
1249         info.remoteKey != NULL);
1250     GapRequestSigningAlgorithmInfoRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapRequestSigningAlgorithmInfoRspInfo));
1251     if (ctx == NULL) {
1252         return BT_NO_MEMORY;
1253     }
1254 
1255     (void)memset_s(
1256         ctx, sizeof(GapRequestSigningAlgorithmInfoRspInfo), 0x00, sizeof(GapRequestSigningAlgorithmInfoRspInfo));
1257 
1258     ctx->addr = (BtAddr *)addr;
1259     ctx->accept = accept;
1260     ctx->info = info;
1261 
1262     int ret = GapRunTaskBlockProcess(GapRequestSigningAlgorithmInfoRspTask, ctx);
1263     if (ret == BT_SUCCESS) {
1264         ret = ctx->result;
1265     }
1266 
1267     MEM_MALLOC.free(ctx);
1268     return ret;
1269 }
1270 
GapLeSetBondModeTask(void * ctx)1271 static void GapLeSetBondModeTask(void *ctx)
1272 {
1273     GapLeSetBondModeInfo *info = ctx;
1274     info->result = GAP_LeSetBondMode(info->mode);
1275 }
1276 
GAPIF_LeSetBondMode(uint8_t mode)1277 int GAPIF_LeSetBondMode(uint8_t mode)
1278 {
1279     LOG_INFO("%{public}s: mode:%hhu", __FUNCTION__, mode);
1280     GapLeSetBondModeInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeSetBondModeInfo));
1281     if (ctx == NULL) {
1282         return BT_NO_MEMORY;
1283     }
1284 
1285     (void)memset_s(ctx, sizeof(GapLeSetBondModeInfo), 0x00, sizeof(GapLeSetBondModeInfo));
1286 
1287     ctx->mode = mode;
1288 
1289     int ret = GapRunTaskBlockProcess(GapLeSetBondModeTask, ctx);
1290     if (ret == BT_SUCCESS) {
1291         ret = ctx->result;
1292     }
1293 
1294     MEM_MALLOC.free(ctx);
1295     return ret;
1296 }
1297 
GapLeSetSecurityModeTask(void * ctx)1298 static void GapLeSetSecurityModeTask(void *ctx)
1299 {
1300     GapLeSetSecurityModeInfo *info = ctx;
1301     info->result = GAP_LeSetSecurityMode(info->mode1Level, info->mode2Level);
1302 }
1303 
GAPIF_LeSetSecurityMode(GAP_LeSecMode1Level mode1Level,GAP_LeSecMode2Level mode2Level)1304 int GAPIF_LeSetSecurityMode(GAP_LeSecMode1Level mode1Level, GAP_LeSecMode2Level mode2Level)
1305 {
1306     LOG_INFO("%{public}s: mode1Level:%{public}d mode2Level:%{public}d", __FUNCTION__, mode1Level, mode2Level);
1307     GapLeSetSecurityModeInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeSetSecurityModeInfo));
1308     if (ctx == NULL) {
1309         return BT_NO_MEMORY;
1310     }
1311 
1312     (void)memset_s(ctx, sizeof(GapLeSetSecurityModeInfo), 0x00, sizeof(GapLeSetSecurityModeInfo));
1313 
1314     ctx->mode1Level = mode1Level;
1315     ctx->mode2Level = mode2Level;
1316 
1317     int ret = GapRunTaskBlockProcess(GapLeSetSecurityModeTask, ctx);
1318     if (ret == BT_SUCCESS) {
1319         ret = ctx->result;
1320     }
1321 
1322     MEM_MALLOC.free(ctx);
1323     return ret;
1324 }
1325 
GapLeGetSecurityStatusTask(void * ctx)1326 static void GapLeGetSecurityStatusTask(void *ctx)
1327 {
1328     GapLeGetSecurityStatusInfo *info = ctx;
1329     info->result = GAP_LeGetSecurityStatus(info->addr, info->status, info->encKeySize);
1330 }
1331 
GAPIF_LeGetSecurityStatus(const BtAddr * addr,GAP_LeSecurityStatus * status,uint8_t * encKeySize)1332 int GAPIF_LeGetSecurityStatus(const BtAddr *addr, GAP_LeSecurityStatus *status, uint8_t *encKeySize)
1333 {
1334     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1335     GapLeGetSecurityStatusInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeGetSecurityStatusInfo));
1336     if (ctx == NULL) {
1337         return BT_NO_MEMORY;
1338     }
1339 
1340     (void)memset_s(ctx, sizeof(GapLeGetSecurityStatusInfo), 0x00, sizeof(GapLeGetSecurityStatusInfo));
1341 
1342     ctx->addr = (BtAddr *)addr;
1343     ctx->status = status;
1344     ctx->encKeySize = encKeySize;
1345 
1346     int ret = GapRunTaskBlockProcess(GapLeGetSecurityStatusTask, ctx);
1347     if (ret == BT_SUCCESS) {
1348         ret = ctx->result;
1349     }
1350 
1351     MEM_MALLOC.free(ctx);
1352     return ret;
1353 }
1354 
GapLeRequestSecurityTask(void * ctx)1355 static void GapLeRequestSecurityTask(void *ctx)
1356 {
1357     GapLeRequestSecurityInfo *info = ctx;
1358     info->result = GAP_LeRequestSecurity(info->addr, info->status, info->callback, info->context);
1359 }
1360 
GAPIF_LeRequestSecurity(const BtAddr * addr,GAP_LeSecurityStatus status,GapLeRequestSecurityResult callback,void * context)1361 int GAPIF_LeRequestSecurity(
1362     const BtAddr *addr, GAP_LeSecurityStatus status, GapLeRequestSecurityResult callback, void *context)
1363 {
1364     LOG_INFO("%{public}s: " BT_ADDR_FMT " status:%{public}d", __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr), status);
1365     GapLeRequestSecurityInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeRequestSecurityInfo));
1366     if (ctx == NULL) {
1367         return BT_NO_MEMORY;
1368     }
1369 
1370     (void)memset_s(ctx, sizeof(GapLeRequestSecurityInfo), 0x00, sizeof(GapLeRequestSecurityInfo));
1371 
1372     ctx->addr = (BtAddr *)addr;
1373     ctx->status = status;
1374     ctx->callback = callback;
1375     ctx->context = context;
1376 
1377     int ret = GapRunTaskBlockProcess(GapLeRequestSecurityTask, ctx);
1378     if (ret == BT_SUCCESS) {
1379         ret = ctx->result;
1380     }
1381 
1382     MEM_MALLOC.free(ctx);
1383     return ret;
1384 }
1385 
GapLePairTask(void * ctx)1386 static void GapLePairTask(void *ctx)
1387 {
1388     GapGeneralPointerInfo *info = ctx;
1389     info->result = GAP_LePair(info->pointer);
1390 }
1391 
GAPIF_LePair(const BtAddr * addr)1392 int GAPIF_LePair(const BtAddr *addr)
1393 {
1394     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1395     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
1396     if (ctx == NULL) {
1397         return BT_NO_MEMORY;
1398     }
1399 
1400     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
1401 
1402     ctx->pointer = (void *)addr;
1403 
1404     int ret = GapRunTaskBlockProcess(GapLePairTask, ctx);
1405     if (ret == BT_SUCCESS) {
1406         ret = ctx->result;
1407     }
1408 
1409     MEM_MALLOC.free(ctx);
1410     return ret;
1411 }
1412 
GapLeCancelPairTask(void * ctx)1413 static void GapLeCancelPairTask(void *ctx)
1414 {
1415     GapGeneralPointerInfo *info = ctx;
1416     info->result = GAP_LeCancelPair(info->pointer);
1417 }
1418 
GAPIF_LeCancelPair(const BtAddr * addr)1419 int GAPIF_LeCancelPair(const BtAddr *addr)
1420 {
1421     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1422     GapGeneralPointerInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralPointerInfo));
1423     if (ctx == NULL) {
1424         return BT_NO_MEMORY;
1425     }
1426 
1427     (void)memset_s(ctx, sizeof(GapGeneralPointerInfo), 0x00, sizeof(GapGeneralPointerInfo));
1428 
1429     ctx->pointer = (void *)addr;
1430 
1431     int ret = GapRunTaskBlockProcess(GapLeCancelPairTask, ctx);
1432     if (ret == BT_SUCCESS) {
1433         ret = ctx->result;
1434     }
1435 
1436     MEM_MALLOC.free(ctx);
1437     return ret;
1438 }
1439 
GapLeSetMinEncKeySizeTask(void * ctx)1440 static void GapLeSetMinEncKeySizeTask(void *ctx)
1441 {
1442     GapLeSetMinEncKeySizeInfo *info = ctx;
1443     info->result = GAP_LeSetMinEncKeySize(info->minSize);
1444 }
1445 
GAPIF_LeSetMinEncKeySize(uint8_t minSize)1446 int GAPIF_LeSetMinEncKeySize(uint8_t minSize)
1447 {
1448     LOG_INFO("%{public}s: minSize:%hhu", __FUNCTION__, minSize);
1449     GapLeSetMinEncKeySizeInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeSetMinEncKeySizeInfo));
1450     if (ctx == NULL) {
1451         return BT_NO_MEMORY;
1452     }
1453 
1454     (void)memset_s(ctx, sizeof(GapLeSetMinEncKeySizeInfo), 0x00, sizeof(GapLeSetMinEncKeySizeInfo));
1455 
1456     ctx->minSize = minSize;
1457 
1458     int ret = GapRunTaskBlockProcess(GapLeSetMinEncKeySizeTask, ctx);
1459     if (ret == BT_SUCCESS) {
1460         ret = ctx->result;
1461     }
1462 
1463     MEM_MALLOC.free(ctx);
1464     return ret;
1465 }
1466 
GapRegisterLePairCallbackTask(void * ctx)1467 static void GapRegisterLePairCallbackTask(void *ctx)
1468 {
1469     GapGeneralCallbackInfo *info = ctx;
1470     info->result = GAP_RegisterLePairCallback(info->callback, info->context);
1471 }
1472 
GAPIF_RegisterLePairCallback(const GapLePairCallback * callback,void * context)1473 int GAPIF_RegisterLePairCallback(const GapLePairCallback *callback, void *context)
1474 {
1475     LOG_INFO("%{public}s: ", __FUNCTION__);
1476     GapGeneralCallbackInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralCallbackInfo));
1477     if (ctx == NULL) {
1478         return BT_NO_MEMORY;
1479     }
1480 
1481     (void)memset_s(ctx, sizeof(GapGeneralCallbackInfo), 0x00, sizeof(GapGeneralCallbackInfo));
1482 
1483     ctx->callback = (void *)callback;
1484     ctx->context = context;
1485 
1486     int ret = GapRunTaskBlockProcess(GapRegisterLePairCallbackTask, ctx);
1487     if (ret == BT_SUCCESS) {
1488         ret = ctx->result;
1489     }
1490 
1491     MEM_MALLOC.free(ctx);
1492     return ret;
1493 }
1494 
GapDeregisterLePairCallbackTask(void * ctx)1495 static void GapDeregisterLePairCallbackTask(void *ctx)
1496 {
1497     GapGeneralVoidInfo *info = ctx;
1498     info->result = GAP_DeregisterLePairCallback();
1499 }
1500 
GAPIF_DeregisterLePairCallback(void)1501 int GAPIF_DeregisterLePairCallback(void)
1502 {
1503     LOG_INFO("%{public}s: ", __FUNCTION__);
1504     GapGeneralVoidInfo *ctx = MEM_MALLOC.alloc(sizeof(GapGeneralVoidInfo));
1505     if (ctx == NULL) {
1506         return BT_NO_MEMORY;
1507     }
1508 
1509     (void)memset_s(ctx, sizeof(GapGeneralVoidInfo), 0x00, sizeof(GapGeneralVoidInfo));
1510 
1511     int ret = GapRunTaskBlockProcess(GapDeregisterLePairCallbackTask, ctx);
1512     if (ret == BT_SUCCESS) {
1513         ret = ctx->result;
1514     }
1515 
1516     MEM_MALLOC.free(ctx);
1517     return ret;
1518 }
1519 
GapLePairFeatureRspTask(void * ctx)1520 static void GapLePairFeatureRspTask(void *ctx)
1521 {
1522     GapLePairFeatureRspInfo *info = ctx;
1523     info->result = GAP_LePairFeatureRsp(info->addr, info->localFrature);
1524 }
1525 
GAPIF_LePairFeatureRsp(const BtAddr * addr,GapLePairFeature localFrature)1526 int GAPIF_LePairFeatureRsp(const BtAddr *addr, GapLePairFeature localFrature)
1527 {
1528     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1529     GapLePairFeatureRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLePairFeatureRspInfo));
1530     if (ctx == NULL) {
1531         return BT_NO_MEMORY;
1532     }
1533 
1534     (void)memset_s(ctx, sizeof(GapLePairFeatureRspInfo), 0x00, sizeof(GapLePairFeatureRspInfo));
1535 
1536     ctx->addr = (BtAddr *)addr;
1537     ctx->localFrature = localFrature;
1538 
1539     int ret = GapRunTaskBlockProcess(GapLePairFeatureRspTask, ctx);
1540     if (ret == BT_SUCCESS) {
1541         ret = ctx->result;
1542     }
1543 
1544     MEM_MALLOC.free(ctx);
1545     return ret;
1546 }
1547 
GapLePairPassKeyRspTask(void * ctx)1548 static void GapLePairPassKeyRspTask(void *ctx)
1549 {
1550     GapLePairPassKeyRspInfo *info = ctx;
1551     info->result = GAP_LePairPassKeyRsp(info->addr, info->accept, info->number);
1552 }
1553 
GAPIF_LePairPassKeyRsp(const BtAddr * addr,uint8_t accept,uint32_t number)1554 int GAPIF_LePairPassKeyRsp(const BtAddr *addr, uint8_t accept, uint32_t number)
1555 {
1556     LOG_INFO("%{public}s: accept:%hhu" BT_ADDR_FMT, __FUNCTION__, accept, BT_ADDR_FMT_OUTPUT(addr->addr));
1557     GapLePairPassKeyRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLePairPassKeyRspInfo));
1558     if (ctx == NULL) {
1559         return BT_NO_MEMORY;
1560     }
1561 
1562     (void)memset_s(ctx, sizeof(GapLePairPassKeyRspInfo), 0x00, sizeof(GapLePairPassKeyRspInfo));
1563 
1564     ctx->addr = (BtAddr *)addr;
1565     ctx->accept = accept;
1566     ctx->number = number;
1567 
1568     int ret = GapRunTaskBlockProcess(GapLePairPassKeyRspTask, ctx);
1569     if (ret == BT_SUCCESS) {
1570         ret = ctx->result;
1571     }
1572 
1573     MEM_MALLOC.free(ctx);
1574     return ret;
1575 }
1576 
GapLePairOobRsptask(void * ctx)1577 static void GapLePairOobRsptask(void *ctx)
1578 {
1579     GapLePairOobRspInfo *info = ctx;
1580     info->result = GAP_LePairOobRsp(info->addr, info->accept, info->oobData);
1581 }
1582 
GAPIF_LePairOobRsp(const BtAddr * addr,uint8_t accept,uint8_t oobData[GAP_OOB_DATA_SIZE])1583 int GAPIF_LePairOobRsp(const BtAddr *addr, uint8_t accept, uint8_t oobData[GAP_OOB_DATA_SIZE])
1584 {
1585     LOG_INFO("%{public}s: accept:%hhu" BT_ADDR_FMT, __FUNCTION__, accept, BT_ADDR_FMT_OUTPUT(addr->addr));
1586     GapLePairOobRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLePairOobRspInfo));
1587     if (ctx == NULL) {
1588         return BT_NO_MEMORY;
1589     }
1590 
1591     (void)memset_s(ctx, sizeof(GapLePairOobRspInfo), 0x00, sizeof(GapLePairOobRspInfo));
1592 
1593     ctx->addr = (BtAddr *)addr;
1594     ctx->accept = accept;
1595     ctx->oobData = oobData;
1596 
1597     int ret = GapRunTaskBlockProcess(GapLePairOobRsptask, ctx);
1598     if (ret == BT_SUCCESS) {
1599         ret = ctx->result;
1600     }
1601 
1602     MEM_MALLOC.free(ctx);
1603     return ret;
1604 }
1605 
GapLePairScOobRsptask(void * ctx)1606 static void GapLePairScOobRsptask(void *ctx)
1607 {
1608     GapLePairScOobRspInfo *info = ctx;
1609     info->result = GAP_LePairScOobRsp(info->addr, info->accept, info->oobDataC, info->oobDataR);
1610 }
1611 
GAPIF_LePairScOobRsp(const BtAddr * addr,uint8_t accept,const uint8_t oobDataC[GAP_OOB_DATA_CONFIRM_SIZE],const uint8_t oobDataR[GAP_OOB_DATA_RANDOM_SIZE])1612 int GAPIF_LePairScOobRsp(const BtAddr *addr, uint8_t accept, const uint8_t oobDataC[GAP_OOB_DATA_CONFIRM_SIZE],
1613     const uint8_t oobDataR[GAP_OOB_DATA_RANDOM_SIZE])
1614 {
1615     LOG_INFO("%{public}s: accept:%hhu" BT_ADDR_FMT, __FUNCTION__, accept, BT_ADDR_FMT_OUTPUT(addr->addr));
1616     GapLePairScOobRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLePairScOobRspInfo));
1617     if (ctx == NULL) {
1618         return BT_NO_MEMORY;
1619     }
1620 
1621     (void)memset_s(ctx, sizeof(GapLePairScOobRspInfo), 0x00, sizeof(GapLePairScOobRspInfo));
1622 
1623     ctx->addr = (BtAddr *)addr;
1624     ctx->accept = accept;
1625     ctx->oobDataC = (uint8_t *)oobDataC;
1626     ctx->oobDataR = (uint8_t *)oobDataR;
1627 
1628     int ret = GapRunTaskBlockProcess(GapLePairScOobRsptask, ctx);
1629     if (ret == BT_SUCCESS) {
1630         ret = ctx->result;
1631     }
1632 
1633     MEM_MALLOC.free(ctx);
1634     return ret;
1635 }
1636 
GapLePairScUserConfirmRspTask(void * ctx)1637 static void GapLePairScUserConfirmRspTask(void *ctx)
1638 {
1639     GapLePairScUserConfirmRspInfo *info = ctx;
1640     info->result = GAP_LePairScUserConfirmRsp(info->addr, info->accept);
1641 }
1642 
GAPIF_LePairScUserConfirmRsp(const BtAddr * addr,uint8_t accept)1643 int GAPIF_LePairScUserConfirmRsp(const BtAddr *addr, uint8_t accept)
1644 {
1645     LOG_INFO("%{public}s: accept:%hhu" BT_ADDR_FMT, __FUNCTION__, accept, BT_ADDR_FMT_OUTPUT(addr->addr));
1646     GapLePairScUserConfirmRspInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLePairScUserConfirmRspInfo));
1647     if (ctx == NULL) {
1648         return BT_NO_MEMORY;
1649     }
1650 
1651     (void)memset_s(ctx, sizeof(GapLePairScUserConfirmRspInfo), 0x00, sizeof(GapLePairScUserConfirmRspInfo));
1652 
1653     ctx->addr = (BtAddr *)addr;
1654     ctx->accept = accept;
1655 
1656     int ret = GapRunTaskBlockProcess(GapLePairScUserConfirmRspTask, ctx);
1657     if (ret == BT_SUCCESS) {
1658         ret = ctx->result;
1659     }
1660 
1661     MEM_MALLOC.free(ctx);
1662     return ret;
1663 }
1664 
GapLeDataSignatureGenerationTask(void * ctx)1665 static void GapLeDataSignatureGenerationTask(void *ctx)
1666 {
1667     GapLeDataSignatureGenerationInfo *info = ctx;
1668     info->result = GAP_LeDataSignatureGeneration(info->addr, info->dataInfo, info->callback, info->context);
1669 }
1670 
GapFreeLeDataSignatureGeneration(void * ctx)1671 static void GapFreeLeDataSignatureGeneration(void *ctx)
1672 {
1673     GapLeDataSignatureGenerationInfo *info = ctx;
1674 
1675     MEM_MALLOC.free((void *)info->dataInfo.data);
1676 }
1677 
GAPIF_LeDataSignatureGenerationAsync(const BtAddr * addr,GapSignatureData dataInfo,GAPSignatureGenerationResult callback,void * context)1678 int GAPIF_LeDataSignatureGenerationAsync(
1679     const BtAddr *addr, GapSignatureData dataInfo, GAPSignatureGenerationResult callback, void *context)
1680 {
1681     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1682     GapLeDataSignatureGenerationInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeDataSignatureGenerationInfo));
1683     if (ctx == NULL) {
1684         return BT_NO_MEMORY;
1685     }
1686 
1687     (void)memset_s(ctx, sizeof(GapLeDataSignatureGenerationInfo), 0x00, sizeof(GapLeDataSignatureGenerationInfo));
1688 
1689     ctx->addr = (BtAddr *)addr;
1690     ctx->dataInfo = dataInfo;
1691     ctx->callback = callback;
1692     ctx->context = context;
1693 
1694     uint8_t *data = MEM_MALLOC.alloc(ctx->dataInfo.dataLen);
1695     if (data == NULL) {
1696         MEM_MALLOC.free(ctx);
1697         return BT_NO_MEMORY;
1698     }
1699     (void)memcpy_s(data, ctx->dataInfo.dataLen, ctx->dataInfo.data, ctx->dataInfo.dataLen);
1700     ctx->dataInfo.data = data;
1701 
1702     int ret = GapRunTaskUnBlockProcess(GapLeDataSignatureGenerationTask, ctx, GapFreeLeDataSignatureGeneration);
1703     if (ret == BT_SUCCESS) {
1704         ret = ctx->result;
1705     }
1706 
1707     return ret;
1708 }
1709 
GapLeDataSignatureConfirmationTask(void * ctx)1710 static void GapLeDataSignatureConfirmationTask(void *ctx)
1711 {
1712     GapLeDataSignatureConfirmationInfo *info = ctx;
1713     info->result =
1714         GAP_LeDataSignatureConfirmation(info->addr, info->dataInfo, info->signature, info->callback, info->context);
1715 }
1716 
GapFreeLeDataSignatureConfirmation(void * ctx)1717 static void GapFreeLeDataSignatureConfirmation(void *ctx)
1718 {
1719     GapLeDataSignatureConfirmationInfo *info = ctx;
1720 
1721     MEM_MALLOC.free((void *)info->dataInfo.data);
1722 }
1723 
GAPIF_LeDataSignatureConfirmationAsync(const BtAddr * addr,GapSignatureData dataInfo,const uint8_t signature[GAP_SIGNATURE_SIZE],GAPSignatureConfirmationResult callback,void * context)1724 int GAPIF_LeDataSignatureConfirmationAsync(const BtAddr *addr, GapSignatureData dataInfo,
1725     const uint8_t signature[GAP_SIGNATURE_SIZE], GAPSignatureConfirmationResult callback, void *context)
1726 {
1727     LOG_INFO("%{public}s: " BT_ADDR_FMT, __FUNCTION__, BT_ADDR_FMT_OUTPUT(addr->addr));
1728     GapLeDataSignatureConfirmationInfo *ctx = MEM_MALLOC.alloc(sizeof(GapLeDataSignatureConfirmationInfo));
1729     if (ctx == NULL) {
1730         return BT_NO_MEMORY;
1731     }
1732 
1733     (void)memset_s(ctx, sizeof(GapLeDataSignatureConfirmationInfo), 0x00, sizeof(GapLeDataSignatureConfirmationInfo));
1734 
1735     ctx->addr = (BtAddr *)addr;
1736     ctx->dataInfo = dataInfo;
1737     (void)memcpy_s(ctx->signature, GAP_SIGNATURE_SIZE, signature, GAP_SIGNATURE_SIZE);
1738     ctx->callback = callback;
1739     ctx->context = context;
1740 
1741     uint8_t *data = MEM_MALLOC.alloc(ctx->dataInfo.dataLen);
1742     if (data == NULL) {
1743         MEM_MALLOC.free(ctx);
1744         return BT_NO_MEMORY;
1745     }
1746     (void)memcpy_s(data, ctx->dataInfo.dataLen, ctx->dataInfo.data, ctx->dataInfo.dataLen);
1747     ctx->dataInfo.data = data;
1748 
1749     int ret = GapRunTaskUnBlockProcess(GapLeDataSignatureConfirmationTask, ctx, GapFreeLeDataSignatureConfirmation);
1750     if (ret == BT_SUCCESS) {
1751         ret = ctx->result;
1752     }
1753 
1754     return ret;
1755 }
1756 
1757 #endif