-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_bt_utils.c
339 lines (322 loc) · 13.4 KB
/
app_bt_utils.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
/******************************************************************************
* File Name: app_bt_utils.c
*
* Description: This file consists of the utility functions that will help
* debugging and developing the applications easier with much
* more meaningful information.
*
* Related Document: See Readme.md
*
*******************************************************************************
* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) or
* an affiliate of Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related
* materials ("Software") is owned by Cypress Semiconductor Corporation
* or one of its affiliates ("Cypress") and is protected by and subject to
* worldwide patent protection (United States and foreign),
* United States copyright laws and international treaty provisions.
* Therefore, you may use this Software only as provided in the license
* agreement accompanying the software package from which you
* obtained this Software ("EULA").
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software
* source code solely for use in connection with Cypress's
* integrated circuit products. Any reproduction, modification, translation,
* compilation, or representation of this Software except as specified
* above is prohibited without the express written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer
* of such system or application assumes all risk of such use and in doing
* so agrees to indemnify Cypress against all liability.
*******************************************************************************/
/******************************************************************************
* INCLUDES
******************************************************************************/
#include "app_bt_utils.h"
#include "wiced_bt_dev.h"
/****************************************************************************
* FUNCTION DEFINITIONS
***************************************************************************/
/**
* Function Name:
* print_bd_address()
*
* Function Description:
* @brief This is the utility function that prints the address of the Bluetooth device
*
* @param wiced_bt_device_address_t bdadr : Bluetooth address
*
* @return void
*
*/
void print_bd_address(wiced_bt_device_address_t bdadr)
{
printf("%02X:%02X:%02X:%02X:%02X:%02X\r\n",bdadr[0],bdadr[1],bdadr[2],bdadr[3],bdadr[4],bdadr[5]);
}
/**
* Function Name:
* void print_array( void* to_print, uint16_t len )
*
* Function Description:
* @brief This is a utility function that prints the specified number of values from memory
*
* @param void* to_print : Pointer to the location to print
* uint16_t : Number of bytes to print
*
* @return void
*
*/
void print_array(void * to_print, uint16_t len)
{
uint16_t counter;
for( counter = 0; counter<len;counter++ )
{
if( counter % 16 == 0 )
{
printf( "\n" );
}
printf( "%02X ", *(((uint8_t *)(to_print)) + counter) );
}
printf( "\n" );
}
/**
* Function Name:
* get_btm_event_name
*
* Function Description:
* @brief The function converts the wiced_bt_management_evt_t enum value to its
* corresponding string literal. This will help the programmer to debug easily
* with log traces without navigating through the source code.
*
* @param wiced_bt_management_evt_t event: Bluetooth management event type
*
* @return wiced_bt_management_evt_t
*
*/
const char *get_btm_event_name(wiced_bt_management_evt_t event)
{
switch ( (int)event )
{
CASE_RETURN_STR(BTM_ENABLED_EVT)
CASE_RETURN_STR(BTM_DISABLED_EVT)
CASE_RETURN_STR(BTM_POWER_MANAGEMENT_STATUS_EVT)
CASE_RETURN_STR(BTM_PIN_REQUEST_EVT)
CASE_RETURN_STR(BTM_USER_CONFIRMATION_REQUEST_EVT)
CASE_RETURN_STR(BTM_PASSKEY_NOTIFICATION_EVT)
CASE_RETURN_STR(BTM_PASSKEY_REQUEST_EVT)
CASE_RETURN_STR(BTM_KEYPRESS_NOTIFICATION_EVT)
CASE_RETURN_STR(BTM_PAIRING_IO_CAPABILITIES_BR_EDR_REQUEST_EVT)
CASE_RETURN_STR(BTM_PAIRING_IO_CAPABILITIES_BR_EDR_RESPONSE_EVT)
CASE_RETURN_STR(BTM_PAIRING_IO_CAPABILITIES_BLE_REQUEST_EVT)
CASE_RETURN_STR(BTM_PAIRING_COMPLETE_EVT)
CASE_RETURN_STR(BTM_ENCRYPTION_STATUS_EVT)
CASE_RETURN_STR(BTM_SECURITY_REQUEST_EVT)
CASE_RETURN_STR(BTM_SECURITY_FAILED_EVT)
CASE_RETURN_STR(BTM_SECURITY_ABORTED_EVT)
CASE_RETURN_STR(BTM_READ_LOCAL_OOB_DATA_COMPLETE_EVT)
CASE_RETURN_STR(BTM_REMOTE_OOB_DATA_REQUEST_EVT)
CASE_RETURN_STR(BTM_PAIRED_DEVICE_LINK_KEYS_UPDATE_EVT)
CASE_RETURN_STR(BTM_PAIRED_DEVICE_LINK_KEYS_REQUEST_EVT)
CASE_RETURN_STR(BTM_LOCAL_IDENTITY_KEYS_UPDATE_EVT)
CASE_RETURN_STR(BTM_LOCAL_IDENTITY_KEYS_REQUEST_EVT)
CASE_RETURN_STR(BTM_BLE_SCAN_STATE_CHANGED_EVT)
CASE_RETURN_STR(BTM_BLE_ADVERT_STATE_CHANGED_EVT)
CASE_RETURN_STR(BTM_SMP_REMOTE_OOB_DATA_REQUEST_EVT)
CASE_RETURN_STR(BTM_SMP_SC_REMOTE_OOB_DATA_REQUEST_EVT)
CASE_RETURN_STR(BTM_SMP_SC_LOCAL_OOB_DATA_NOTIFICATION_EVT)
CASE_RETURN_STR(BTM_SCO_CONNECTED_EVT)
CASE_RETURN_STR(BTM_SCO_DISCONNECTED_EVT)
CASE_RETURN_STR(BTM_SCO_CONNECTION_REQUEST_EVT)
CASE_RETURN_STR(BTM_SCO_CONNECTION_CHANGE_EVT)
CASE_RETURN_STR(BTM_BLE_CONNECTION_PARAM_UPDATE)
CASE_RETURN_STR(BTM_BLE_PHY_UPDATE_EVT)
CASE_RETURN_STR(BTM_LPM_STATE_LOW_POWER)
CASE_RETURN_STR(BTM_MULTI_ADVERT_RESP_EVENT)
CASE_RETURN_STR(BTM_BLE_DATA_LENGTH_UPDATE_EVENT)
}
return "UNKNOWN_EVENT";
}
/**
* Function Name:
* get_bt_advert_mode_name
*
* Function Description:
* @brief The function converts the wiced_bt_ble_advert_mode_t enum value to its corresponding
* string literal. This will help the programmer to debug easily with log traces
* without navigating through the source code.
*
* @param wiced_bt_ble_advert_mode_t mode: Bluetooth advertisement mode type
*
* @return wiced_bt_ble_advert_mode_t
*
*/
const char *get_bt_advert_mode_name(wiced_bt_ble_advert_mode_t mode)
{
switch ( (int)mode )
{
CASE_RETURN_STR(BTM_BLE_ADVERT_OFF)
CASE_RETURN_STR(BTM_BLE_ADVERT_DIRECTED_HIGH)
CASE_RETURN_STR(BTM_BLE_ADVERT_DIRECTED_LOW)
CASE_RETURN_STR(BTM_BLE_ADVERT_UNDIRECTED_HIGH)
CASE_RETURN_STR(BTM_BLE_ADVERT_UNDIRECTED_LOW)
CASE_RETURN_STR(BTM_BLE_ADVERT_NONCONN_HIGH)
CASE_RETURN_STR(BTM_BLE_ADVERT_NONCONN_LOW)
CASE_RETURN_STR(BTM_BLE_ADVERT_DISCOVERABLE_HIGH)
CASE_RETURN_STR(BTM_BLE_ADVERT_DISCOVERABLE_LOW)
}
return "UNKNOWN_MODE";
}
/**
* Function Name:
* get_bt_gatt_disconn_reason_name
*
* Function Description:
* @brief The function converts the wiced_bt_gatt_disconn_reason_t enum value to its corresponding
* string literal. This will help the programmer to debug easily with log traces
* without navigating through the source code.
*
* @param wiced_bt_gatt_disconn_reason_t reason: GATT Disconnection reason
*
* @return wiced_bt_gatt_disconn_reason_t
*
*/
const char *get_bt_gatt_disconn_reason_name(wiced_bt_gatt_disconn_reason_t reason)
{
switch ( (int)reason )
{
CASE_RETURN_STR(GATT_CONN_UNKNOWN)
CASE_RETURN_STR(GATT_CONN_L2C_FAILURE)
CASE_RETURN_STR(GATT_CONN_TIMEOUT)
CASE_RETURN_STR(GATT_CONN_TERMINATE_PEER_USER)
CASE_RETURN_STR(GATT_CONN_TERMINATE_LOCAL_HOST)
CASE_RETURN_STR(GATT_CONN_FAIL_ESTABLISH)
CASE_RETURN_STR(GATT_CONN_LMP_TIMEOUT)
CASE_RETURN_STR(GATT_CONN_CANCEL)
}
return "UNKNOWN_REASON";
}
/**
* Function Name:
* get_bt_gatt_status_name
*
* Function Description:
* @brief The function converts the wiced_bt_gatt_status_t enum value to its corresponding
* string literal. This will help the programmer to debug easily with log traces
* without navigating through the source code.
*
* @param wiced_bt_gatt_status_t status: GATT status
*
* @return wiced_bt_gatt_status_t
*
**/
const char *get_bt_gatt_status_name(wiced_bt_gatt_status_t status)
{
switch ( (int)status )
{
CASE_RETURN_STR(WICED_BT_GATT_SUCCESS)
CASE_RETURN_STR(WICED_BT_GATT_INVALID_HANDLE)
CASE_RETURN_STR(WICED_BT_GATT_READ_NOT_PERMIT)
CASE_RETURN_STR(WICED_BT_GATT_WRITE_NOT_PERMIT)
CASE_RETURN_STR(WICED_BT_GATT_INVALID_PDU)
CASE_RETURN_STR(WICED_BT_GATT_INSUF_AUTHENTICATION)
CASE_RETURN_STR(WICED_BT_GATT_REQ_NOT_SUPPORTED)
CASE_RETURN_STR(WICED_BT_GATT_INVALID_OFFSET)
CASE_RETURN_STR(WICED_BT_GATT_INSUF_AUTHORIZATION)
CASE_RETURN_STR(WICED_BT_GATT_PREPARE_Q_FULL)
CASE_RETURN_STR(WICED_BT_GATT_ATTRIBUTE_NOT_FOUND)
CASE_RETURN_STR(WICED_BT_GATT_NOT_LONG)
CASE_RETURN_STR(WICED_BT_GATT_INSUF_KEY_SIZE)
CASE_RETURN_STR(WICED_BT_GATT_INVALID_ATTR_LEN)
CASE_RETURN_STR(WICED_BT_GATT_ERR_UNLIKELY)
CASE_RETURN_STR(WICED_BT_GATT_INSUF_ENCRYPTION)
CASE_RETURN_STR(WICED_BT_GATT_UNSUPPORT_GRP_TYPE)
CASE_RETURN_STR(WICED_BT_GATT_INSUF_RESOURCE)
CASE_RETURN_STR(WICED_BT_GATT_DATABASE_OUT_OF_SYNC)
CASE_RETURN_STR(WICED_BT_GATT_VALUE_NOT_ALLOWED)
CASE_RETURN_STR(WICED_BT_GATT_ILLEGAL_PARAMETER)
CASE_RETURN_STR(WICED_BT_GATT_NO_RESOURCES)
CASE_RETURN_STR(WICED_BT_GATT_INTERNAL_ERROR)
CASE_RETURN_STR(WICED_BT_GATT_WRONG_STATE)
CASE_RETURN_STR(WICED_BT_GATT_DB_FULL)
CASE_RETURN_STR(WICED_BT_GATT_BUSY)
CASE_RETURN_STR(WICED_BT_GATT_ERROR)
CASE_RETURN_STR(WICED_BT_GATT_CMD_STARTED)
CASE_RETURN_STR(WICED_BT_GATT_PENDING)
CASE_RETURN_STR(WICED_BT_GATT_AUTH_FAIL)
CASE_RETURN_STR(WICED_BT_GATT_MORE)
CASE_RETURN_STR(WICED_BT_GATT_INVALID_CFG)
CASE_RETURN_STR(WICED_BT_GATT_SERVICE_STARTED)
CASE_RETURN_STR(WICED_BT_GATT_ENCRYPTED_NO_MITM)
CASE_RETURN_STR(WICED_BT_GATT_NOT_ENCRYPTED)
CASE_RETURN_STR(WICED_BT_GATT_CONGESTED)
CASE_RETURN_STR(WICED_BT_GATT_NOT_ALLOWED)
CASE_RETURN_STR(WICED_BT_GATT_HANDLED)
CASE_RETURN_STR(WICED_BT_GATT_NO_PENDING_OPERATION)
CASE_RETURN_STR(WICED_BT_GATT_INDICATION_RESPONSE_PENDING)
CASE_RETURN_STR(WICED_BT_GATT_WRITE_REQ_REJECTED)
CASE_RETURN_STR(WICED_BT_GATT_CCC_CFG_ERR)
CASE_RETURN_STR(WICED_BT_GATT_PRC_IN_PROGRESS)
CASE_RETURN_STR(WICED_BT_GATT_OUT_OF_RANGE)
CASE_RETURN_STR(WICED_BT_GATT_BAD_OPCODE)
CASE_RETURN_STR(WICED_BT_GATT_INVALID_CONNECTION_ID)
}
return "UNKNOWN_STATUS";
}
/**
* Function Name:
* get_bt_smp_status_name
*
* Function Description:
* @brief The function converts the wiced_bt_smp_status_t enum value to its corresponding
* string literal. This will help the programmer to debug easily with log traces
* without navigating through the source code.
*
* @param wiced_bt_smp_status_t status: GATT status
*
* @return wiced_bt_smp_status_t
*
*/
const char *get_bt_smp_status_name(wiced_bt_smp_status_t status)
{
switch ((int)status)
{
CASE_RETURN_STR(SMP_SUCCESS) /**< Success */
CASE_RETURN_STR(SMP_PASSKEY_ENTRY_FAIL) /**< Passkey entry failed */
CASE_RETURN_STR(SMP_OOB_FAIL) /**< OOB failed */
CASE_RETURN_STR(SMP_PAIR_AUTH_FAIL) /**< Authentication failed */
CASE_RETURN_STR(SMP_CONFIRM_VALUE_ERR) /**< Value confirmation failed */
CASE_RETURN_STR(SMP_PAIR_NOT_SUPPORT) /**< Not supported */
CASE_RETURN_STR(SMP_ENC_KEY_SIZE) /**< Encryption key size failure */
CASE_RETURN_STR(SMP_INVALID_CMD) /**< Invalid command */
CASE_RETURN_STR(SMP_PAIR_FAIL_UNKNOWN) /**< Unknown failure */
CASE_RETURN_STR(SMP_REPEATED_ATTEMPTS) /**< Repeated attempts */
CASE_RETURN_STR(SMP_INVALID_PARAMETERS) /**< Invalid parameters */
CASE_RETURN_STR(SMP_DHKEY_CHK_FAIL) /**< DH Key check failed */
CASE_RETURN_STR(SMP_NUMERIC_COMPAR_FAIL) /**< Numeric comparison failed */
CASE_RETURN_STR(SMP_BR_PAIRING_IN_PROGR) /**< BR paIring in progress */
CASE_RETURN_STR(SMP_XTRANS_DERIVE_NOT_ALLOW) /**< Cross transport key derivation not allowed */
/* bte smp status codes */
CASE_RETURN_STR(SMP_PAIR_INTERNAL_ERR) /**< Internal error */
CASE_RETURN_STR(SMP_UNKNOWN_IO_CAP) /**< unknown IO capability, unable to decide associatino model */
CASE_RETURN_STR(SMP_INIT_FAIL) /**< Initialization failed */
CASE_RETURN_STR(SMP_CONFIRM_FAIL) /**< Confirmation failed */
CASE_RETURN_STR(SMP_BUSY) /**< Busy */
CASE_RETURN_STR(SMP_ENC_FAIL) /**< Encryption failed */
CASE_RETURN_STR(SMP_STARTED) /**< Started */
CASE_RETURN_STR(SMP_RSP_TIMEOUT) /**< Response timeout */
CASE_RETURN_STR(SMP_FAIL) /**< Generic failure */
CASE_RETURN_STR(SMP_CONN_TOUT) /**< Connection timeout */
}
return "UNKNOWN_STATUS";
}
/* [] END OF FILE */