Skip to content

Commit 61c5f84

Browse files
rugeGerritsenrlubos
authored andcommitted
Samples: Bluetooth: sec error prints to use bt_security_err_to_str()
When developing Bluetooth applications, you typically run into some errors. If you are an experienced Bluetooth developer, you would typically know how to translate the error codes into string representations. Others might not. This commit starts using `bt_security_err_to_str()` for all samples under `samples/bluetooth`. Similar changes can be done in other applications and samples. To enable string printing, enable CONFIG_BT_SECURITY_ERR_TO_STR. The format used is equal to the one added in zephyrproject-rtos/zephyr#75442. Signed-off-by: Rubin Gerritsen <[email protected]>
1 parent 7359e3d commit 61c5f84

File tree

26 files changed

+94
-81
lines changed

26 files changed

+94
-81
lines changed

samples/bluetooth/central_and_peripheral_hr/src/main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,11 @@ static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
197197

198198
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
199199

200-
printk("Pairing failed conn: %s, reason %d\n", addr, reason);
200+
printk("Pairing failed conn: %s, reason %d %s\n", addr, reason,
201+
bt_security_err_to_str(reason));
201202
}
202203

203-
static const struct bt_conn_auth_cb auth_callbacks = {
204-
.cancel = auth_cancel
205-
};
204+
static const struct bt_conn_auth_cb auth_callbacks = {.cancel = auth_cancel};
206205

207206
static struct bt_conn_auth_info_cb conn_auth_info_callbacks = {
208207
.pairing_complete = pairing_complete,
@@ -294,8 +293,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
294293
if (!err) {
295294
printk("Security changed: %s level %u\n", addr, level);
296295
} else {
297-
printk("Security failed: %s level %u err %d\n", addr, level,
298-
err);
296+
printk("Security failed: %s level %u err %d %s\n", addr, level, err,
297+
bt_security_err_to_str(err));
299298
}
300299

301300
if (conn == central_conn) {

samples/bluetooth/central_bas/src/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
230230
if (!err) {
231231
printk("Security changed: %s level %u\n", addr, level);
232232
} else {
233-
printk("Security failed: %s level %u err %d\n", addr, level,
234-
err);
233+
printk("Security failed: %s level %u err %d %s\n", addr, level, err,
234+
bt_security_err_to_str(err));
235235
}
236236

237237
gatt_discover(conn);
@@ -348,10 +348,10 @@ static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
348348

349349
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
350350

351-
printk("Pairing failed conn: %s, reason %d\n", addr, reason);
351+
printk("Pairing failed conn: %s, reason %d %s\n", addr, reason,
352+
bt_security_err_to_str(reason));
352353
}
353354

354-
355355
static struct bt_conn_auth_cb conn_auth_callbacks = {
356356
.cancel = auth_cancel,
357357
};

samples/bluetooth/central_hids/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
252252
if (!err) {
253253
printk("Security changed: %s level %u\n", addr, level);
254254
} else {
255-
printk("Security failed: %s level %u err %d\n", addr, level,
256-
err);
255+
printk("Security failed: %s level %u err %d %s\n", addr, level, err,
256+
bt_security_err_to_str(err));
257257
}
258258

259259
gatt_discover(conn);
@@ -621,7 +621,8 @@ static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
621621

622622
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
623623

624-
printk("Pairing failed conn: %s, reason %d\n", addr, reason);
624+
printk("Pairing failed conn: %s, reason %d %s\n", addr, reason,
625+
bt_security_err_to_str(reason));
625626
}
626627

627628
static struct bt_conn_auth_cb conn_auth_callbacks = {

samples/bluetooth/central_nfc_pairing/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
202202
if (!err) {
203203
printk("Security changed: %s level %u\n", addr, level);
204204
} else {
205-
printk("Security failed: %s level %u err %d\n", addr, level,
206-
err);
205+
printk("Security failed: %s level %u err %d %s\n", addr, level, err,
206+
bt_security_err_to_str(err));
207207
}
208208
}
209209

@@ -325,7 +325,8 @@ static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
325325

326326
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
327327

328-
printk("Pairing failed conn: %s, reason %d\n", addr, reason);
328+
printk("Pairing failed conn: %s, reason %d %s\n", addr, reason,
329+
bt_security_err_to_str(reason));
329330

330331
k_poll_signal_raise(&pair_signal, 0);
331332
bt_le_oob_set_sc_flag(false);

samples/bluetooth/central_smp_client/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
213213
if (!err) {
214214
printk("Security changed: %s level %u\n", addr, level);
215215
} else {
216-
printk("Security failed: %s level %u err %d\n", addr, level,
217-
err);
216+
printk("Security failed: %s level %u err %d %s\n", addr, level, err,
217+
bt_security_err_to_str(err));
218218
}
219219
}
220220

samples/bluetooth/central_uart/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
427427
if (!err) {
428428
LOG_INF("Security changed: %s level %u", addr, level);
429429
} else {
430-
LOG_WRN("Security failed: %s level %u err %d", addr,
431-
level, err);
430+
LOG_WRN("Security failed: %s level %u err %d %s", addr, level, err,
431+
bt_security_err_to_str(err));
432432
}
433433

434434
gatt_discover(conn);
@@ -539,7 +539,8 @@ static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
539539

540540
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
541541

542-
LOG_WRN("Pairing failed conn: %s, reason %d", addr, reason);
542+
LOG_WRN("Pairing failed conn: %s, reason %d %s", addr, reason,
543+
bt_security_err_to_str(reason));
543544
}
544545

545546
static struct bt_conn_auth_cb conn_auth_callbacks = {

samples/bluetooth/fast_pair/input_device/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_
237237
if (!err) {
238238
LOG_INF("Security changed: %s level %u", addr, level);
239239
} else {
240-
LOG_WRN("Security failed: %s level %u err %d", addr, level, err);
240+
LOG_WRN("Security failed: %s level %u err %d %s", addr, level, err,
241+
bt_security_err_to_str(err));
241242
}
242243
}
243244

samples/bluetooth/fast_pair/locator_tag/src/fp_adv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_
392392
if (!err) {
393393
LOG_INF("Security changed: %s level %u", addr, level);
394394
} else {
395-
LOG_WRN("Security failed: %s level %u err %d", addr, level, err);
395+
LOG_WRN("Security failed: %s level %u err %d %s", addr, level, err,
396+
bt_security_err_to_str(err));
396397
}
397398
}
398399

samples/bluetooth/llpm/src/main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,9 @@ static void test_run(void)
392392
}
393393
}
394394

395-
void security_changed(struct bt_conn *conn, bt_security_t level,
396-
enum bt_security_err err)
395+
void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err)
397396
{
398-
printk("Security changed: level %i, err: %i\n", level, err);
397+
printk("Security changed: level %i, err: %i %s\n", level, err, bt_security_err_to_str(err));
399398

400399
if (err != 0) {
401400
printk("Failed to encrypt link\n");

samples/bluetooth/peripheral_ams_client/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
306306
}
307307
}
308308
} else {
309-
printk("Security failed: %s level %u err %d\n", addr, level,
310-
err);
309+
printk("Security failed: %s level %u err %d %s\n", addr, level, err,
310+
bt_security_err_to_str(err));
311311
}
312312
}
313313

@@ -343,7 +343,8 @@ static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
343343

344344
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
345345

346-
printk("Pairing failed conn: %s, reason %d\n", addr, reason);
346+
printk("Pairing failed conn: %s, reason %d %s\n", addr, reason,
347+
bt_security_err_to_str(reason));
347348

348349
bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
349350
}

0 commit comments

Comments
 (0)