From f5c43df669bc978a982d54f1cddcfbc484432173 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2013 11:19:09 +0100 Subject: [PATCH] monitor: Decode supported commands result --- monitor/packet.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/monitor/packet.c b/monitor/packet.c index 503da75ab..8de496513 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -1382,15 +1382,33 @@ static void print_manufacturer(uint16_t manufacturer) bt_compidtostr(manufacturer), manufacturer); } +static const char *get_supported_command(int bit); + static void print_commands(const uint8_t *commands) { - char str[129]; - int i; + unsigned int count = 0; + int i, n; + + for (i = 0; i < 64; i++) { + for (n = 0; n < 8; n++) { + if (commands[i] & (1 << n)) + count++; + } + } - for (i = 0; i < 64; i++) - sprintf(str + (i * 2), "%2.2x", commands[i]); + print_field("Commands: %u entr%s", count, count == 1 ? "y" : "ies"); - print_field("Commands: 0x%s", str); + for (i = 0; i < 64; i++) { + for (n = 0; n < 8; n++) { + const char *cmd; + + if (!(commands[i] & (1 << n))) + continue; + + cmd = get_supported_command((i * 8) + n); + print_field(" %s (Octet %d - Bit %d)", cmd, i, n); + } + } } struct features_data { @@ -4116,6 +4134,18 @@ static const struct opcode_data opcode_table[] = { { } }; +static const char *get_supported_command(int bit) +{ + int i; + + for (i = 0; opcode_table[i].str; i++) { + if (opcode_table[i].bit == bit) + return opcode_table[i].str; + } + + return NULL; +} + static void status_evt(const void *data, uint8_t size) { uint8_t status = *((uint8_t *) data); -- 2.47.3