diff --git a/lib/bluetooth.c b/lib/bluetooth.c
index f51e310..a1b4c13 100644
--- a/lib/bluetooth.c
+++ b/lib/bluetooth.c
int str2ba(const char *str, bdaddr_t *ba)
{
- uint8_t b[6];
- const char *ptr = str;
+ bdaddr_t b;
int i;
- for (i = 0; i < 6; i++) {
- b[i] = (uint8_t) strtol(ptr, NULL, 16);
- if (i != 5 && !(ptr = strchr(ptr, ':')))
- ptr = ":00:00:00:00:00";
- ptr++;
+ if (bachk(str) < 0) {
+ memset(ba, 0, sizeof(*ba));
+ return -1;
}
- baswap(ba, (bdaddr_t *) b);
+ for (i = 0; i < 6; i++, str += 3)
+ b.b[i] = strtol(str, NULL, 16);
+
+ baswap(ba, &b);
return 0;
}