From 0b8af3a3bcc94817ec27c4586ad09b3a7f86293b Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 16 Sep 2021 10:17:37 +0200 Subject: [PATCH 1/2] nimble/addr: fix byte-order and string termination --- pkg/nimble/addr/nimble_addr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/nimble/addr/nimble_addr.c b/pkg/nimble/addr/nimble_addr.c index 6b534d9122dc..d2dc1dd2fb1c 100644 --- a/pkg/nimble/addr/nimble_addr.c +++ b/pkg/nimble/addr/nimble_addr.c @@ -33,7 +33,9 @@ void nimble_addr_print(const ble_addr_t *addr) void nimble_addr_sprint(char *buf, const ble_addr_t *addr) { - bluetil_addr_sprint(buf, addr->val); + uint8_t addrn[BLE_ADDR_LEN]; + bluetil_addr_swapped_cp(addr->val, addrn); + bluetil_addr_sprint(buf, addrn); const char *type; switch (addr->type) { case BLE_ADDR_PUBLIC: type = " (public) "; break; @@ -43,5 +45,5 @@ void nimble_addr_sprint(char *buf, const ble_addr_t *addr) default: type = " (unknown)"; break; } memcpy(&buf[BLUETIL_ADDR_STRLEN - 1], type, 10); - buf[BLUETIL_ADDR_STRLEN - 1] = '\0'; + buf[NIMBLE_ADDR_STRLEN - 1] = '\0'; } From 1486c419fa43d6bfcdc447a1eb2f96278c07692d Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Thu, 16 Sep 2021 10:20:32 +0200 Subject: [PATCH 2/2] nimble/scanlist: use nimble_addr_print() --- pkg/nimble/scanlist/nimble_scanlist_print.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/pkg/nimble/scanlist/nimble_scanlist_print.c b/pkg/nimble/scanlist/nimble_scanlist_print.c index b594e6f5d042..edbecad599e7 100644 --- a/pkg/nimble/scanlist/nimble_scanlist_print.c +++ b/pkg/nimble/scanlist/nimble_scanlist_print.c @@ -23,24 +23,10 @@ #include #include "net/bluetil/ad.h" +#include "nimble_addr.h" #include "nimble_scanlist.h" #include "nimble/hci_common.h" -static void _print_addr(const ble_addr_t *addr) -{ - printf("%02x", (int)addr->val[5]); - for (int i = 4; i >= 0; i--) { - printf(":%02x", addr->val[i]); - } - switch (addr->type) { - case BLE_ADDR_PUBLIC: printf(" (PUBLIC)"); break; - case BLE_ADDR_RANDOM: printf(" (RANDOM)"); break; - case BLE_ADDR_PUBLIC_ID: printf(" (PUB_ID)"); break; - case BLE_ADDR_RANDOM_ID: printf(" (RAND_ID)"); break; - default: printf(" (UNKNOWN)"); break; - } -} - static void _print_type(uint8_t type) { switch (type) { @@ -92,7 +78,7 @@ void nimble_scanlist_print_entry(nimble_scanlist_entry_t *e) strncpy(name, "undefined", sizeof(name)); } - _print_addr(&e->addr); + nimble_addr_print(&e->addr); _print_type(e->type); unsigned adv_int = ((e->last_update - e->first_update) / e->adv_msg_cnt); printf(" \"%s\", adv_msg_cnt: %u, adv_int: %uus, last_rssi: %i\n",