-
Notifications
You must be signed in to change notification settings - Fork 2
/
app_bt_utils.c
286 lines (246 loc) · 10.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
/*******************************************************************************
* File Name: app_bt_utils.c
*
* Description: This file consists of the utility function definitions that will
* help debugging and developing the applications easier with much
* more meaningful information.
*
* Related Document: See README.md
*
*
********************************************************************************
* Copyright 2020-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"
#include "cybt_platform_trace.h"
/****************************************************************************
* FUNCTION DEFINITIONS
***************************************************************************/
/*
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 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_DATA_LENGTH_UPDATE_EVENT)
#ifdef CYW20819A1
CASE_RETURN_STR(BTM_BLE_PHY_UPDATE_EVT)
#endif
}
return "UNKNOWN_EVENT";
}
/*
Function Name:
get_btm_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 mode Bluetooth advertisement mode type
@return wiced_bt_ble_advert_mode_t
*/
const char *get_btm_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_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 reason GATT Disconnection reason
@return wiced_bt_gatt_disconn_reason_t
*/
const char *get_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_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 status GATT status
@return wiced_bt_gatt_status_t
*/
const char *get_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_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_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)
}
return "UNKNOWN_STATUS";
}
/*
* Function Name: print_bd_address()
*
* @brief This utility function prints the address of the Bluetooth device
*
* @param wiced_bt_device_address_t Bluetooth address
*
* @return void
*
*/
void print_bd_address(char * msg, wiced_bt_device_address_t bdaddr)
{
printf("%s %02X:%02X:%02X:%02X:%02X:%02X\n",msg? msg:"", bdaddr[0],
bdaddr[1],
bdaddr[2],
bdaddr[3],
bdaddr[4],
bdaddr[5]);
}
/*
* Function Name: print_local_bd_address()
*
* @brief This utility function prints the address of the Bluetooth device
*
* @param wiced_bt_device_address_t Bluetooth address
*
* @return void
*
*/
void print_local_bd_address(void)
{
wiced_bt_device_address_t local_device_bd_addr = { 0 };
wiced_bt_dev_read_local_addr(local_device_bd_addr);
print_bd_address("\nMy Bluetooth Device Address: ", local_device_bd_addr);
}
/* [] END OF FILE */