This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathu_ble_gap_extmod.c
536 lines (500 loc) · 20.9 KB
/
u_ble_gap_extmod.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/*
* Copyright 2019-2024 u-blox
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Only #includes of u_* and the C standard library are allowed here,
* no platform stuff and no OS stuff. Anything required from
* the platform/OS must be brought in through u_port* to maintain
* portability.
*/
/** @file
* @brief Implementation of the GAP API for BLE.
*/
#ifndef U_CFG_BLE_MODULE_INTERNAL
#ifdef U_CFG_OVERRIDE
#include "u_cfg_override.h" // For a customer's configuration override
#endif
#include "stdbool.h"
#include "stddef.h" // NULL, size_t etc.
#include "stdint.h" // int32_t etc.
#include "stdio.h" // snprintf()
#include "stdlib.h" // strol(), atoi(), strol(), strtof()
#include "string.h" // memset(), strncpy(), strtok_r(), strtol()
#include "u_error_common.h"
#include "u_timeout.h"
#include "u_at_client.h"
#include "u_ble.h"
#include "u_ble_cfg.h"
#include "u_ble_extmod_private.h"
#include "u_ble_gap.h"
#include "u_ble_private.h"
#include "u_cfg_sw.h"
#include "u_port.h"
#include "u_port_os.h"
#include "u_port_heap.h"
#include "u_short_range.h"
#include "u_short_range_module_type.h"
#include "u_short_range_pbuf.h"
#include "u_short_range_private.h"
#include "u_network.h"
#include "u_network_shared.h"
#include "u_network_config_ble.h"
#include "u_ble_gatt.h"
#include "u_ble_context.h"
#include "u_cx_system.h"
#include "u_cx_bluetooth.h"
#include "u_cx_urc.h"
#include "u_cx_log.h"
/* ----------------------------------------------------------------
* COMPILE-TIME MACROS
* -------------------------------------------------------------- */
/* ----------------------------------------------------------------
* TYPES
* -------------------------------------------------------------- */
/* ----------------------------------------------------------------
* VARIABLES
* -------------------------------------------------------------- */
/* ----------------------------------------------------------------
* STATIC FUNCTIONS
* -------------------------------------------------------------- */
// Callback wrappers
static void bleConnectCallback(struct uCxHandle *pUcxHandle, int32_t connHandle,
uBtLeAddress_t *pBdAddr)
{
uBleDeviceState_t *pState = pGetBleContext(pUcxHandle->pAtClient->pConfig->pContext);
if (pState != NULL) {
pState->connHandle = connHandle;
if (pState->connectCallback != NULL) {
char bdAddrString[U_BD_STRING_MAX_LENGTH_BYTES];
if (uCxBdAddressToString(pBdAddr, bdAddrString, sizeof(bdAddrString)) > 0) {
pState->connectCallback(connHandle, bdAddrString, true);
}
}
}
}
static void bleDisconnectCallback(struct uCxHandle *pUcxHandle, int32_t connHandle)
{
uBleDeviceState_t *pState = pGetBleContext(pUcxHandle->pAtClient->pConfig->pContext);
if (pState != NULL) {
pState->connHandle = -1;
if (pState->connectCallback != NULL) {
pState->connectCallback(connHandle, NULL, false);
}
}
}
static void blePhyUpdateCallback(struct uCxHandle *pUcxHandle, int32_t connHandle, int32_t status,
int32_t txPhy, int32_t rxPhy)
{
uBleDeviceState_t *pState = pGetBleContext(pUcxHandle->pAtClient->pConfig->pContext);
if (pState != NULL) {
if (pState->phyUpdateCallback != NULL) {
pState->phyUpdateCallback(connHandle, status, txPhy, rxPhy);
}
}
}
static void bleBondCompleteCallback(struct uCxHandle *pUcxHandle, uBtLeAddress_t *pBdAddr,
uBondStatus_t status)
{
uBleDeviceState_t *pState = pGetBleContext(pUcxHandle->pAtClient->pConfig->pContext);
if (pState != NULL) {
if (pState->bondCompleteCb != NULL) {
char bdAddrString[U_BD_STRING_MAX_LENGTH_BYTES];
if ((pState->bondCompleteCb != NULL) &&
(uCxBdAddressToString(pBdAddr, bdAddrString, sizeof(bdAddrString)) > 0)) {
pState->bondCompleteCb(bdAddrString, (int32_t)status);
}
}
}
}
static void bleBondConfirmCallback(struct uCxHandle *pUcxHandle, uBtLeAddress_t *pBdAddr,
int32_t numericValue)
{
uBleDeviceState_t *pState = pGetBleContext(pUcxHandle->pAtClient->pConfig->pContext);
if (pState != NULL) {
if (pState->confirmCb != NULL) {
char bdAddrString[U_BD_STRING_MAX_LENGTH_BYTES];
if ((pState->confirmCb != NULL) &&
(uCxBdAddressToString(pBdAddr, bdAddrString, sizeof(bdAddrString)) > 0)) {
pState->confirmCb(bdAddrString, numericValue);
}
}
}
}
static void bleBondPassKeyRequestCallback(struct uCxHandle *pUcxHandle, uBtLeAddress_t *pBdAddr)
{
uBleDeviceState_t *pState = pGetBleContext(pUcxHandle->pAtClient->pConfig->pContext);
if (pState != NULL) {
char bdAddrString[U_BD_STRING_MAX_LENGTH_BYTES];
if ((pState->passKeyRequestCb != NULL) &&
(uCxBdAddressToString(pBdAddr, bdAddrString, sizeof(bdAddrString)) > 0)) {
pState->passKeyRequestCb(bdAddrString);
}
}
}
static void bleBondPassKeyEntryCallback(struct uCxHandle *pUcxHandle, uBtLeAddress_t *pBdAddr,
int32_t passKey)
{
uBleDeviceState_t *pState = pGetBleContext(pUcxHandle->pAtClient->pConfig->pContext);
if (pState != NULL) {
char bdAddrString[U_BD_STRING_MAX_LENGTH_BYTES];
if ((pState->passKeyEntryCb != NULL) &&
(uCxBdAddressToString(pBdAddr, bdAddrString, sizeof(bdAddrString)) > 0)) {
pState->passKeyEntryCb(bdAddrString, passKey);
}
}
}
/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS
* -------------------------------------------------------------- */
int32_t uBleGapGetMac(uDeviceHandle_t devHandle, char *pMac)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
uMacAddress_t macAddr;
errorCode = uCxSystemGetLocalAddress(pUcxHandle,
U_INTERFACE_ID_BLUETOOTH, &macAddr);
if (errorCode == 0) {
uCxMacAddressToString(&macAddr, pMac, U_SHORT_RANGE_BT_ADDRESS_SIZE);
}
}
return errorCode;
}
int32_t uBleGapSetPairable(uDeviceHandle_t devHandle, bool isPairable)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
errorCode = uCxBluetoothSetPairingMode(pUcxHandle,
isPairable ?
U_PAIRING_MODE_PAIRING_MODE_ENABLE :
U_PAIRING_MODE_PAIRING_MODE_DISABLE);
}
return errorCode;
}
int32_t uBleSetBondParameters(uDeviceHandle_t devHandle, int32_t ioCapabilities,
int32_t bondSecurity,
uBleGapBondConfirmCallback_t confirmCb,
uBleGapBondPasskeyRequestCallback_t passKeyRequestCb,
uBleGapBondPasskeyEntryCallback_t passKeyEntryCb)
{
int32_t errorCode = uShortRangeLock();
if (errorCode == 0) {
errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uShortRangePrivateInstance_t *pInstance = pUShortRangePrivateGetInstance(devHandle);
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if ((pUcxHandle != NULL) && (pInstance != NULL)) {
errorCode = checkCreateBleContext(pInstance);
if (errorCode == 0) {
errorCode =
uCxBluetoothSetIoCapabilities(pUcxHandle, (uIoCapabilities_t)ioCapabilities);
if (errorCode == 0) {
errorCode =
uCxBluetoothSetSecurityMode(pUcxHandle, (uBtSecurityMode_t)bondSecurity);
}
if (errorCode == 0) {
uBleDeviceState_t *pBleContext = (uBleDeviceState_t *)(pInstance->pBleContext);
uCxBluetoothRegisterUserConfirmation(pUcxHandle, bleBondConfirmCallback);
pBleContext->confirmCb = confirmCb;
uCxBluetoothRegisterPasskeyRequest(pUcxHandle, bleBondPassKeyRequestCallback);
pBleContext->passKeyRequestCb = passKeyRequestCb;
uCxBluetoothRegisterPasskeyEntry(pUcxHandle, bleBondPassKeyEntryCallback);
pBleContext->passKeyEntryCb = passKeyEntryCb;
}
}
}
uShortRangeUnlock();
}
return errorCode;
}
int32_t uBleGapBond(uDeviceHandle_t devHandle, const char *pAddress,
uBleGapBondCompleteCallback_t cb)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uShortRangePrivateInstance_t *pInstance = pUShortRangePrivateGetInstance(devHandle);
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if ((pUcxHandle != NULL) && (pInstance != NULL)) {
uBtLeAddress_t bdAddr;
errorCode = uCxStringToBdAddress(pAddress, &bdAddr);
if (errorCode == 0) {
errorCode = checkCreateBleContext(pInstance);
if (errorCode == 0) {
((uBleDeviceState_t *)(pInstance->pBleContext))->bondCompleteCb = cb;
uCxBluetoothRegisterBondStatus(pUcxHandle, bleBondCompleteCallback);
errorCode = uCxBluetoothBond(pUcxHandle, &bdAddr);
}
}
}
return errorCode;
}
int32_t uBleGapRemoveBond(uDeviceHandle_t devHandle, const char *pAddress)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
if (pAddress == NULL) {
errorCode = uCxBluetoothUnbondAll(pUcxHandle);
} else {
uBtLeAddress_t bdAddr;
errorCode = uCxStringToBdAddress(pAddress, &bdAddr);
if (errorCode == 0) {
errorCode = uCxBluetoothUnbond(pUcxHandle, &bdAddr);
}
}
}
return errorCode;
}
int32_t uBleGapBondConfirm(uDeviceHandle_t devHandle, bool confirm, const char *pAddress)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
uBtLeAddress_t bdAddr;
errorCode = uCxStringToBdAddress(pAddress, &bdAddr);
if (errorCode == 0) {
errorCode = uCxBluetoothUserConfirmation(pUcxHandle, &bdAddr,
confirm ? U_YES_NO_YES : U_YES_NO_NO);
}
}
return errorCode;
}
int32_t uBleGapBondEnterPasskey(uDeviceHandle_t devHandle, bool confirm, const char *pAddress,
int32_t passkey)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
uBtLeAddress_t bdAddr;
errorCode = uCxStringToBdAddress(pAddress, &bdAddr);
if (errorCode == 0) {
errorCode = uCxBluetoothUserPasskeyEntry3(pUcxHandle, &bdAddr,
confirm ? U_YES_NO_YES : U_YES_NO_NO,
passkey);
}
}
return errorCode;
}
int32_t uBleGapSetConnectCallback(uDeviceHandle_t devHandle, uBleGapConnectCallback_t cb)
{
int32_t errorCode = uShortRangeLock();
if (errorCode == 0) {
errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
uShortRangePrivateInstance_t *pInstance = pUShortRangePrivateGetInstance(devHandle);
if ((pUcxHandle != NULL) && (pInstance != NULL)) {
errorCode = checkCreateBleContext(pInstance);
if (errorCode == 0) {
((uBleDeviceState_t *)(pInstance->pBleContext))->connectCallback = cb;
uCxBluetoothRegisterConnect(pUcxHandle, bleConnectCallback);
uCxBluetoothRegisterDisconnect(pUcxHandle, bleDisconnectCallback);
}
}
uShortRangeUnlock();
}
return errorCode;
}
int32_t uBleGapScan(uDeviceHandle_t devHandle,
uBleGapDiscoveryType_t discType,
bool activeScan,
uint32_t timeousMs,
uBleGapScanCallback_t cb)
{
int32_t errorCode = uShortRangeLock();
if (errorCode == 0) {
errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
// Map old discovery types to the new uCx ones
uDiscoveryType_t uCxType;
if ((discType == U_BLE_GAP_SCAN_DISCOVER_ALL_ONCE) ||
(discType == U_BLE_GAP_SCAN_DISCOVER_LIMITED_ONCE)) {
uCxType = U_DISCOVERY_TYPE_DISCOVER_ALL_NO_DUPLICATES;
} else {
uCxType = U_DISCOVERY_TYPE_DISCOVER_ALL;
}
// Start and loop over all received discoveries
uCxBluetoothDiscovery3Begin(pUcxHandle, uCxType,
activeScan ? U_DISCOVERY_MODE_ACTIVE : U_DISCOVERY_MODE_PASSIVE,
(int32_t)timeousMs);
uCxBluetoothDiscovery_t uCxResp;
while (uCxBluetoothDiscovery3GetNext(pUcxHandle, &uCxResp)) {
uBleScanResult_t result;
uCxBdAddressToString(&uCxResp.bd_addr, result.address, sizeof(result.address));
int32_t length = MIN(sizeof(result.data), uCxResp.data.length);
memcpy(result.data, uCxResp.data.pData, length);
result.dataLength = length;
result.dataType = uCxResp.data_type;
strcpy(result.name, uCxResp.device_name);
result.rssi = uCxResp.rssi;
cb(&result);
}
errorCode = uCxEnd(pUcxHandle);
if (errorCode == U_CX_ERROR_CMD_TIMEOUT) {
// *** UCX MISSING FUNCTION ***
// Ignore timeout for now, not possible to set ucx timeout value
errorCode = (int32_t)U_ERROR_COMMON_SUCCESS;
}
}
uShortRangeUnlock();
}
return errorCode;
}
int32_t uBleGapSetConnectParams(uDeviceHandle_t devHandle, uBleGapConnectConfig_t *pConfig)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
// *** UCX MISSING FUNCTION ***
/* Currently no ucx command for the following settings:
scanIntervalMs
scanWindowMs
connCreateTimeoutMs
*/
errorCode = uCxBluetoothSetConnectionIntervalMin(pUcxHandle,
(pConfig->connIntervalMinMs) * 4 / 5);
if (errorCode == 0) {
errorCode = uCxBluetoothSetConnectionIntervalMax(pUcxHandle,
(pConfig->connIntervalMaxMs) * 4 / 5);
}
if (errorCode == 0) {
errorCode = uCxBluetoothSetConnectionPeripheralLatency(pUcxHandle, pConfig->connLatency);
}
if (errorCode == 0) {
errorCode = uCxBluetoothSetConnectionLinklossTimeout(pUcxHandle, pConfig->linkLossTimeoutMs);
}
if (errorCode == 0) {
errorCode = uCxBluetoothSetPreferredTxPhy(pUcxHandle, pConfig->preferredTxPhy);
}
if (errorCode == 0) {
errorCode = uCxBluetoothSetPreferredRxPhy(pUcxHandle, pConfig->preferredRxPhy);
}
}
return errorCode;
}
int32_t uBleGapConnect(uDeviceHandle_t devHandle, const char *pAddress)
{
int32_t errorCode = uShortRangeLock();
if (errorCode == 0) {
errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uShortRangePrivateInstance_t *pInstance = pUShortRangePrivateGetInstance(devHandle);
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if ((pUcxHandle != NULL) && (pInstance != NULL)) {
errorCode = checkCreateBleContext(pInstance);
if (errorCode == 0) {
((uBleDeviceState_t *)(pInstance->pBleContext))->connHandle = -1;
uBtLeAddress_t bdAddr;
errorCode = uCxStringToBdAddress(pAddress, &bdAddr);
if (errorCode == 0) {
errorCode = uCxBluetoothConnect(pUcxHandle, &bdAddr);
}
}
}
uShortRangeUnlock();
}
return errorCode;
}
int32_t uBleGapRequestPhyChange(uDeviceHandle_t devHandle, int32_t connHandle,
int32_t txPhy, int32_t rxPhy, uBleGapPhyUpdateCallback_t cb)
{
int32_t errorCode = uShortRangeLock();
if (errorCode == 0) {
errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
uShortRangePrivateInstance_t *pInstance = pUShortRangePrivateGetInstance(devHandle);
if ((pUcxHandle != NULL) && (pInstance != NULL)) {
errorCode = checkCreateBleContext(pInstance);
if (errorCode == 0) {
((uBleDeviceState_t *)(pInstance->pBleContext))->phyUpdateCallback = cb;
uCxBluetoothRegisterPhyUpdate(pUcxHandle, blePhyUpdateCallback);
errorCode = uCxBluetoothRequestPhy(pUcxHandle, connHandle, txPhy, rxPhy);
}
}
uShortRangeUnlock();
}
return errorCode;
}
int32_t uBleGapDisconnect(uDeviceHandle_t devHandle, int32_t connHandle)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
errorCode = uCxBluetoothDisconnect(pUcxHandle, connHandle);
}
return errorCode;
}
int32_t uBleGapSetAdvData(const char *pName,
const uint8_t *pManufData, uint8_t manufDataSize,
uint8_t *pAdvData, uint8_t advDataSize)
{
if (!pName && !pManufData) {
return (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
}
uint8_t nameSize =
pName ? (uint8_t)(strlen(pName) + 2) : 0; /* string length, tag and the string */
manufDataSize = pManufData ? manufDataSize + 2 : 0;
int32_t totSize = nameSize + manufDataSize;
if (totSize > advDataSize) {
return (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
}
if (pName) {
nameSize--;
*(pAdvData++) = nameSize--;
*(pAdvData++) = U_BT_DATA_NAME_COMPLETE;
memcpy(pAdvData, pName, nameSize);
pAdvData += nameSize;
}
if (pManufData) {
manufDataSize--;
*(pAdvData++) = manufDataSize--;
*(pAdvData++) = U_BT_DATA_MANUFACTURER_DATA;
memcpy(pAdvData, pManufData, manufDataSize);
}
return totSize;
}
int32_t uBleGapAdvertiseStart(uDeviceHandle_t devHandle, const uBleGapAdvConfig_t *pConfig)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
// *** UCX MISSING FUNCTION ***
// Currently no ucx command for setting connectable and maxClients
errorCode = uCxBluetoothSetAdvIntervalMin(pUcxHandle, (int32_t)(pConfig->minIntervalMs * 16 / 10));
if (errorCode == 0) {
errorCode = uCxBluetoothSetAdvIntervalMax(pUcxHandle, (int32_t)(pConfig->maxIntervalMs * 16 / 10));
}
if ((errorCode == 0) && (pConfig->pAdvData != NULL)) {
errorCode = uCxBluetoothSetAdvertiseData(pUcxHandle, pConfig->pAdvData,
pConfig->advDataLength);
}
if (errorCode == 0) {
errorCode = uCxBluetoothSetAdvertisements(pUcxHandle, 1);
}
}
return errorCode;
}
int32_t uBleGapAdvertiseStop(uDeviceHandle_t devHandle)
{
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
errorCode = uCxBluetoothSetAdvertisements(pUcxHandle, 0);
}
return errorCode;
}
int32_t uBleGapReset(uDeviceHandle_t devHandle)
{
uBleGapAdvertiseStop(devHandle);
return uShortrangePrivateRestartDevice(devHandle, false);
}
#endif