Diff between 37b90a9581a9a388d6c952549644eaf49fe91408 and f5c43df669bc978a982d54f1cddcfbc484432173

Changed Files

File Additions Deletions Status
monitor/packet.c +35 -5 modified

Full Patch

diff --git a/monitor/packet.c b/monitor/packet.c
index 503da75..8de4965 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);