From cf48a5870a7044c66821238fd83df707096114b0 Mon Sep 17 00:00:00 2001 From: Abhishek Pandit-Subedi Date: Mon, 2 Dec 2019 17:03:57 -0800 Subject: [PATCH] lib: Add ba2strlc to match kernel printk format When the kernel prints the bluetooth address (via %pMR), it prints the address in lower case. ba2strlc should be used in cases where we should match the kernel casing (i.e. addresses assigned to /dev/uhid and /dev/uinput) --- lib/bluetooth.c | 7 +++++++ lib/bluetooth.h | 1 + 2 files changed, 8 insertions(+) diff --git a/lib/bluetooth.c b/lib/bluetooth.c index effc7f49d..7cba509d8 100644 --- a/lib/bluetooth.c +++ b/lib/bluetooth.c @@ -81,6 +81,13 @@ int ba2str(const bdaddr_t *ba, char *str) ba->b[5], ba->b[4], ba->b[3], ba->b[2], ba->b[1], ba->b[0]); } +/* Match kernel's lowercase printing of mac address (%pMR) */ +int ba2strlc(const bdaddr_t *ba, char *str) +{ + return sprintf(str, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", + ba->b[5], ba->b[4], ba->b[3], ba->b[2], ba->b[1], ba->b[0]); +} + int str2ba(const char *str, bdaddr_t *ba) { int i; diff --git a/lib/bluetooth.h b/lib/bluetooth.h index eb279260e..756dce164 100644 --- a/lib/bluetooth.h +++ b/lib/bluetooth.h @@ -325,6 +325,7 @@ void baswap(bdaddr_t *dst, const bdaddr_t *src); bdaddr_t *strtoba(const char *str); char *batostr(const bdaddr_t *ba); int ba2str(const bdaddr_t *ba, char *str); +int ba2strlc(const bdaddr_t *ba, char *str); int str2ba(const char *str, bdaddr_t *ba); int ba2oui(const bdaddr_t *ba, char *oui); int bachk(const char *str); -- 2.47.3