diff --git a/mgmt/main.c b/mgmt/main.c
index 573cfb3..14116a1 100644
--- a/mgmt/main.c
+++ b/mgmt/main.c
return 0;
}
-static void type2str(uint8_t type, char *str, size_t len)
+static const char *typestr(uint8_t type)
{
- switch (type) {
- case MGMT_ADDR_BREDR:
- strncpy(str, "BR/EDR", len);
- break;
- case MGMT_ADDR_LE_PUBLIC:
- strncpy(str, "LE Public", len);
- break;
- case MGMT_ADDR_LE_RANDOM:
- strncpy(str, "LE Random", len);
- break;
- default:
- strncpy(str, "(unknown)", len);
- break;
- }
+ const char *str[] = { "BR/EDR", "LE Public", "LE Random" };
+
+ if (type <= MGMT_ADDR_LE_RANDOM)
+ return str[type];
+
+ return "(unknown)";
}
static int mgmt_connected(int mgmt_sk, uint16_t index, bool connected,
}
if (monitor) {
- char addr[18], type[10];
-
+ char addr[18];
ba2str(&ev->bdaddr, addr);
- type2str(ev->type, type, sizeof(type));
- printf("hci%u %s type %s %s\n", index, addr, type, ev_name);
+ printf("hci%u %s type %s %s\n", index, addr,
+ typestr(ev->type), ev_name);
}
return 0;
}
if (monitor) {
- char addr[18], type[10];
-
+ char addr[18];
ba2str(&ev->addr.bdaddr, addr);
- type2str(ev->addr.type, type, sizeof(type));
printf("hci%u %s type %s connect failed (status 0x%02x)\n",
- index, addr, type, ev->status);
+ index, addr, typestr(ev->addr.type), ev->status);
}
return 0;
}
if (monitor || discovery) {
- char addr[18], type[10];
+ char addr[18];
ba2str(&ev->addr.bdaddr, addr);
- type2str(ev->addr.type, type, sizeof(type));
printf("hci%u dev_found: %s type %s class 0x%02x%02x%02x "
- "rssi %d eir (%s)\n", index, addr, type,
+ "rssi %d eir (%s)\n", index, addr,
+ typestr(ev->addr.type),
ev->dev_class[2], ev->dev_class[1], ev->dev_class[0],
ev->rssi, ev->eir[0] == 0 ? "no" : "yes");
}
}
for (i = 0; i < count; i++) {
- char addr[18], type[18];
+ char addr[18];
ba2str(&rp->addr[i].bdaddr, addr);
- type2str(rp->addr[i].type, type, sizeof(type));
- printf("%s type %s\n", addr, type);
+ printf("%s type %s\n", addr, typestr(rp->addr[i].type));
}
exit(EXIT_SUCCESS);
ba2str(&rp->addr.bdaddr, addr);
if (rp->status != 0) {
- fprintf(stderr, "Pairing with %s failed with status %u\n",
- addr, rp->status);
+ fprintf(stderr, "Pairing with %s (%s) failed with status %u\n",
+ addr, typestr(rp->addr.type), rp->status);
exit(EXIT_FAILURE);
}