Hi Abhishek, On Tue, Dec 3, 2019 at 3:04 AM Abhishek Pandit-Subedi <abhishekpandit@xxxxxxxxxxxx> wrote: > > 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) > > --- > > Changes in v2: > - Split into its own commit > > 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.24.0.393.g34dc348eaf-goog Applied, thanks. Note that I did change a little bit the code in uinput_create since strncpy generates some warnings with gcc8 see: https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/ What I did was to assign '\0' after the use of strncpy otherwise it would generate warnings, also replaced the use of strncpy when we know it would not need to be truncated. -- Luiz Augusto von Dentz