diff --git a/mgmt/main.c b/mgmt/main.c
index 14116a1..ea963f8 100644
--- a/mgmt/main.c
+++ b/mgmt/main.c
"Device Unblocked",
};
+static const char *mgmt_status[] = {
+ "Success",
+ "Unknown Command",
+ "Not Connected",
+ "Failed",
+ "Connect Failed",
+ "Authentication Failed",
+ "Not Paired",
+ "No Resources",
+ "Timeout",
+ "Already Connected",
+ "Busy",
+ "Rejected",
+ "Not Supported",
+ "Invalid Parameters",
+ "Disconnected",
+ "Not Powered",
+};
+
static bool monitor = false;
static bool discovery = false;
return mgmt_ev[ev];
}
+static const char *mgmt_errstr(uint8_t status)
+{
+ if (status >= NELEM(mgmt_status))
+ return "<unknown status>";
+ return mgmt_status[status];
+}
+
static int mgmt_send_cmd(int mgmt_sk, uint16_t op, uint16_t id, void *data,
size_t len, cmd_cb func, void *user_data)
{
opcode = bt_get_le16(&ev->opcode);
if (monitor)
- printf("cmd status, opcode 0x%04x status 0x%02x\n",
- opcode, ev->status);
+ printf("cmd status, opcode 0x%04x status 0x%02x (%s)\n",
+ opcode, ev->status, mgmt_errstr(ev->status));
if (ev->status != 0)
mgmt_check_pending(mgmt_sk, opcode, index, ev->status,
if (monitor) {
char addr[18];
ba2str(&ev->addr.bdaddr, addr);
- printf("hci%u %s type %s connect failed (status 0x%02x)\n",
- index, addr, typestr(ev->addr.type), ev->status);
+ printf("hci%u %s type %s connect failed (status 0x%02x, %s)\n",
+ index, addr, typestr(ev->addr.type), ev->status,
+ mgmt_errstr(ev->status));
}
return 0;
if (monitor) {
char addr[18];
ba2str(&ev->bdaddr, addr);
- printf("hci%u %s auth failed with status 0x%02x\n",
- index, addr, ev->status);
+ printf("hci%u %s auth failed with status 0x%02x (%s)\n",
+ index, addr, ev->status, mgmt_errstr(ev->status));
}
return 0;
void *rsp, uint16_t len, void *user_data)
{
if (status != 0) {
- fprintf(stderr, "hci%u PIN Code reply failed with status %u",
- id, status);
+ fprintf(stderr,
+ "hci%u PIN Code reply failed with status 0x%02x (%s)",
+ id, status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
void *rsp, uint16_t len, void *user_data)
{
if (status != 0) {
- fprintf(stderr, "hci%u PIN Neg reply failed with status %u",
- id, status);
+ fprintf(stderr,
+ "hci%u PIN Neg reply failed with status 0x%02x (%s)",
+ id, status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
{
if (status != 0) {
fprintf(stderr,
- "hci%u User Confirm reply failed with status %u",
- id, status);
+ "hci%u User Confirm reply failed. status 0x%02x (%s)",
+ id, status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
{
if (status != 0) {
fprintf(stderr,
- "hci%u Confirm Negative reply failed with status %u",
- id, status);
+ "hci%u Confirm Neg reply failed. status 0x%02x (%s)",
+ id, status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
char addr[18];
if (status != 0) {
- fprintf(stderr, "Reading hci%u info failed with status %u\n",
- id, status);
+ fprintf(stderr,
+ "Reading hci%u info failed with status 0x%02x (%s)\n",
+ id, status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
unsigned int i;
if (status != 0) {
- fprintf(stderr, "Reading index list failed with status %u\n",
- status);
+ fprintf(stderr,
+ "Reading index list failed with status 0x%02x (%s)\n",
+ status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
struct mgmt_mode *rp = rsp;
if (status != 0) {
- fprintf(stderr, "%s for hci%u failed with status %u\n",
- mgmt_opstr(op), id, status);
+ fprintf(stderr,
+ "%s for hci%u failed with status 0x%02x (%s)\n",
+ mgmt_opstr(op), id, status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
void *rsp, uint16_t len, void *user_data)
{
if (status != 0) {
- fprintf(stderr, "Setting hci%u class failed with status %u",
- id, status);
+ fprintf(stderr,
+ "Setting hci%u class failed with status 0x%02x (%s)",
+ id, status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
char addr[18];
if (status != 0) {
- fprintf(stderr, "Disconnect failed with status %u\n", status);
+ fprintf(stderr, "Disconnect failed with status 0x%02x (%s)\n",
+ status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
printf("%s disconnected\n", addr);
exit(EXIT_SUCCESS);
} else {
- fprintf(stderr, "Disconnecting %s failed with status %u\n",
- addr, rp->status);
+ fprintf(stderr,
+ "Disconnecting %s failed with status 0x%02x (%s)\n",
+ addr, rp->status, mgmt_errstr(rp->status));
exit(EXIT_FAILURE);
}
}
void *rsp, uint16_t len, void *user_data)
{
if (status != 0) {
- fprintf(stderr, "Unable to start discovery (status %u)\n",
- status);
+ fprintf(stderr,
+ "Unable to start discovery. status 0x%02x (%s)\n",
+ status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
void *rsp, uint16_t len, void *user_data)
{
if (status != 0) {
- fprintf(stderr, "Unable to set local name (status %u)",
- status);
+ fprintf(stderr, "Unable to set local name. status 0x%02x (%s)",
+ status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
char addr[18];
if (status != 0) {
- fprintf(stderr, "Pairing failed with status %u\n", status);
+ fprintf(stderr, "Pairing failed with status 0x%02x (%s)\n",
+ status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
ba2str(&rp->addr.bdaddr, addr);
if (rp->status != 0) {
- fprintf(stderr, "Pairing with %s (%s) failed with status %u\n",
- addr, typestr(rp->addr.type), rp->status);
+ fprintf(stderr,
+ "Pairing with %s (%s) failed. status 0x%02x (%s)\n",
+ addr, typestr(rp->addr.type), rp->status,
+ mgmt_errstr(rp->status));
exit(EXIT_FAILURE);
}
char addr[18];
if (status != 0) {
- fprintf(stderr, "Remove keys failed with status %u\n", status);
+ fprintf(stderr, "Remove keys failed with status 0x%02x (%s)\n",
+ status, mgmt_errstr(status));
exit(EXIT_FAILURE);
}
ba2str(&rp->bdaddr, addr);
if (rp->status != 0) {
- fprintf(stderr, "Removing keys for %s failed with status %u\n",
- addr, rp->status);
+ fprintf(stderr,
+ "Removing keys for %s failed. status 0x%02x (%s)\n",
+ addr, rp->status, mgmt_errstr(rp->status));
exit(EXIT_FAILURE);
}