Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimble/addr|scanlist: fix nimble_addr_sprint() and use in nimble_scanlist_print() #16859

Merged
merged 2 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/nimble/addr/nimble_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
}
18 changes: 2 additions & 16 deletions pkg/nimble/scanlist/nimble_scanlist_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,10 @@
#include <assert.h>

#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) {
Expand Down Expand Up @@ -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",
Expand Down