Select one of the symbols to view example projects that use it.
 
Outline
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "host/ble_hs.h"
#include "host/ble_uuid.h"
#include "esp_central.h"
print_bytes(const uint8_t *, int)
print_mbuf(const struct os_mbuf *)
addr_str(const void *)
print_uuid(const ble_uuid_t *)
print_conn_desc(const struct ble_gap_conn_desc *)
print_adv_fields(const struct ble_hs_adv_fields *)
print_mbuf_data(const struct os_mbuf *)
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFexamples/bluetooth/nimble/common/nimble_central_utils/misc.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 *//* ... */ #include <assert.h> #include <stdio.h> #include <string.h> #include "host/ble_hs.h" #include "host/ble_uuid.h" #include "esp_central.h"6 includes /** * Utility function to log an array of bytes. *//* ... */ void print_bytes(const uint8_t *bytes, int len) { int i; for (i = 0; i < len; i++) { MODLOG_DFLT(DEBUG, "%s0x%02x", i != 0 ? ":" : "", bytes[i]); }{...} }{ ... } void print_mbuf(const struct os_mbuf *om) { int colon, i; colon = 0; while (om != NULL) { if (colon) { MODLOG_DFLT(INFO, ":"); }{...} else { colon = 1; }{...} for (i = 0; i < om->om_len; i++) { MODLOG_DFLT(INFO, "%s0x%02x", i != 0 ? ":" : "", om->om_data[i]); }{...} om = SLIST_NEXT(om, om_next); }{...} }{ ... } char * addr_str(const void *addr) { static char buf[6 * 2 + 5 + 1]; const uint8_t *u8p; u8p = addr; sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]); return buf; }{ ... } void print_uuid(const ble_uuid_t *uuid) { char buf[BLE_UUID_STR_LEN]; MODLOG_DFLT(DEBUG, "%s", ble_uuid_to_str(uuid, buf)); }{ ... } /** * Logs information about a connection to the console. *//* ... */ void print_conn_desc(const struct ble_gap_conn_desc *desc) { MODLOG_DFLT(DEBUG, "handle=%d our_ota_addr_type=%d our_ota_addr=%s ", desc->conn_handle, desc->our_ota_addr.type, addr_str(desc->our_ota_addr.val)); MODLOG_DFLT(DEBUG, "our_id_addr_type=%d our_id_addr=%s ", desc->our_id_addr.type, addr_str(desc->our_id_addr.val)); MODLOG_DFLT(DEBUG, "peer_ota_addr_type=%d peer_ota_addr=%s ", desc->peer_ota_addr.type, addr_str(desc->peer_ota_addr.val)); MODLOG_DFLT(DEBUG, "peer_id_addr_type=%d peer_id_addr=%s ", desc->peer_id_addr.type, addr_str(desc->peer_id_addr.val)); MODLOG_DFLT(DEBUG, "conn_itvl=%d conn_latency=%d supervision_timeout=%d " "encrypted=%d authenticated=%d bonded=%d", desc->conn_itvl, desc->conn_latency, desc->supervision_timeout, desc->sec_state.encrypted, desc->sec_state.authenticated, desc->sec_state.bonded); }{ ... } #if MYNEWT_VAL(BLE_EXT_ADV) void print_addr(const void *addr, const char *name) { const uint8_t *u8p; u8p = addr; MODLOG_DFLT(DEBUG, "%s = %02x:%02x:%02x:%02x:%02x:%02x", name, u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]); }{...} void ext_print_adv_report(const void *param) { const struct ble_gap_ext_disc_desc *disc = (struct ble_gap_ext_disc_desc *)param; MODLOG_DFLT(DEBUG, "props=%d data_status=%d legacy_event_type=%d", disc->props, disc->data_status, disc->legacy_event_type); print_addr(disc->addr.val, "address"); MODLOG_DFLT(DEBUG, "rssi=%d tx_power=%d", disc->rssi, disc->tx_power); MODLOG_DFLT(DEBUG, "sid=%d prim_phy=%d sec_phy=%d", disc->sid, disc->prim_phy, disc->sec_phy); MODLOG_DFLT(DEBUG, "periodic_adv_itvl=%d length_data=%d", disc->periodic_adv_itvl, disc->length_data); print_addr(disc->direct_addr.val, "direct address"); }{...} /* ... */#endif void print_adv_fields(const struct ble_hs_adv_fields *fields) { char s[BLE_HS_ADV_MAX_SZ]; const uint8_t *u8p; int i; if (fields->flags != 0) { MODLOG_DFLT(DEBUG, " flags=0x%02x\n", fields->flags); }{...} if (fields->uuids16 != NULL) { MODLOG_DFLT(DEBUG, " uuids16(%scomplete)=", fields->uuids16_is_complete ? "" : "in"); for (i = 0; i < fields->num_uuids16; i++) { print_uuid(&fields->uuids16[i].u); MODLOG_DFLT(DEBUG, " "); }{...} MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->uuids32 != NULL) { MODLOG_DFLT(DEBUG, " uuids32(%scomplete)=", fields->uuids32_is_complete ? "" : "in"); for (i = 0; i < fields->num_uuids32; i++) { print_uuid(&fields->uuids32[i].u); MODLOG_DFLT(DEBUG, " "); }{...} MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->uuids128 != NULL) { MODLOG_DFLT(DEBUG, " uuids128(%scomplete)=", fields->uuids128_is_complete ? "" : "in"); for (i = 0; i < fields->num_uuids128; i++) { print_uuid(&fields->uuids128[i].u); MODLOG_DFLT(DEBUG, " "); }{...} MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->name != NULL) { assert(fields->name_len < sizeof s - 1); memcpy(s, fields->name, fields->name_len); s[fields->name_len] = '\0'; MODLOG_DFLT(DEBUG, " name(%scomplete)=%s\n", fields->name_is_complete ? "" : "in", s); }{...} if (fields->tx_pwr_lvl_is_present) { MODLOG_DFLT(DEBUG, " tx_pwr_lvl=%d\n", fields->tx_pwr_lvl); }{...} if (fields->slave_itvl_range != NULL) { MODLOG_DFLT(DEBUG, " slave_itvl_range="); print_bytes(fields->slave_itvl_range, BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN); MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->sm_tk_value_is_present) { MODLOG_DFLT(DEBUG, " sm_tk_value="); print_bytes(fields->sm_tk_value, 16); MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->sm_oob_flag_is_present) { MODLOG_DFLT(DEBUG, " sm_oob_flag=%d\n", fields->sm_oob_flag); }{...} if (fields->sol_uuids16 != NULL) { MODLOG_DFLT(DEBUG, " sol_uuids16="); for (i = 0; i < fields->sol_num_uuids16; i++) { print_uuid(&fields->sol_uuids16[i].u); MODLOG_DFLT(DEBUG, " "); }{...} MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->sol_uuids32 != NULL) { MODLOG_DFLT(DEBUG, " sol_uuids32="); for (i = 0; i < fields->sol_num_uuids32; i++) { print_uuid(&fields->sol_uuids32[i].u); MODLOG_DFLT(DEBUG, "\n"); }{...} MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->sol_uuids128 != NULL) { MODLOG_DFLT(DEBUG, " sol_uuids128="); for (i = 0; i < fields->sol_num_uuids128; i++) { print_uuid(&fields->sol_uuids128[i].u); MODLOG_DFLT(DEBUG, " "); }{...} MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->svc_data_uuid16 != NULL) { MODLOG_DFLT(DEBUG, " svc_data_uuid16="); print_bytes(fields->svc_data_uuid16, fields->svc_data_uuid16_len); MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->public_tgt_addr != NULL) { MODLOG_DFLT(DEBUG, " public_tgt_addr="); u8p = fields->public_tgt_addr; for (i = 0; i < fields->num_public_tgt_addrs; i++) { MODLOG_DFLT(DEBUG, "public_tgt_addr=%s ", addr_str(u8p)); u8p += BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN; }{...} MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->random_tgt_addr != NULL) { MODLOG_DFLT(DEBUG, " random_tgt_addr="); u8p = fields->random_tgt_addr; for (i = 0; i < fields->num_random_tgt_addrs; i++) { MODLOG_DFLT(DEBUG, "random_tgt_addr=%s ", addr_str(u8p)); u8p += BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN; }{...} MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->appearance_is_present) { MODLOG_DFLT(DEBUG, " appearance=0x%04x\n", fields->appearance); }{...} if (fields->adv_itvl_is_present) { MODLOG_DFLT(DEBUG, " adv_itvl=0x%04x\n", fields->adv_itvl); }{...} if (fields->device_addr_is_present) { MODLOG_DFLT(DEBUG, " device_addr="); u8p = fields->device_addr; MODLOG_DFLT(DEBUG, "%s ", addr_str(u8p)); u8p += BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN; MODLOG_DFLT(DEBUG, "addr_type %d ", *u8p); }{...} if (fields->le_role_is_present) { MODLOG_DFLT(DEBUG, " le_role=%d\n", fields->le_role); }{...} if (fields->svc_data_uuid32 != NULL) { MODLOG_DFLT(DEBUG, " svc_data_uuid32="); print_bytes(fields->svc_data_uuid32, fields->svc_data_uuid32_len); MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->svc_data_uuid128 != NULL) { MODLOG_DFLT(DEBUG, " svc_data_uuid128="); print_bytes(fields->svc_data_uuid128, fields->svc_data_uuid128_len); MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->uri != NULL) { MODLOG_DFLT(DEBUG, " uri="); print_bytes(fields->uri, fields->uri_len); MODLOG_DFLT(DEBUG, "\n"); }{...} if (fields->mfg_data != NULL) { MODLOG_DFLT(DEBUG, " mfg_data="); print_bytes(fields->mfg_data, fields->mfg_data_len); MODLOG_DFLT(DEBUG, "\n"); }{...} }{ ... } void print_mbuf_data(const struct os_mbuf *om) { int i; MODLOG_DFLT(INFO, "Data: "); while (om != NULL) { for (i = 0; i < om->om_len; i++) { printf(" %d", om->om_data[i]); }{...} om = SLIST_NEXT(om, om_next); }{...} }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.