Diff between dc4eb576b6eba6bce9bc7b82e20ae69878de09a1 and 50b0d43e5624eb740cd4c4200a15d00b08ddaf8d

Changed Files

File Additions Deletions Status
monitor/main.c +19 -4 modified
monitor/packet.c +19 -0 modified
monitor/packet.h +2 -0 modified

Full Patch

diff --git a/monitor/main.c b/monitor/main.c
index 8a12a6d..ac4dc1f 100644
--- a/monitor/main.c
+++ b/monitor/main.c
@@ -27,7 +27,9 @@
 #endif
 
 #include <stdio.h>
+#include <ctype.h>
 #include <stdlib.h>
+#include <string.h>
 #include <getopt.h>
 
 #include "mainloop.h"
@@ -55,6 +57,7 @@ static void usage(void)
 		"\t-r, --read <file>      Read traces in btsnoop format\n"
 		"\t-w, --write <file>     Save traces in btsnoop format\n"
 		"\t-s, --server <socket>  Start monitor server socket\n"
+		"\t-i, --index <num>      Show only specified controller\n"
 		"\t-t, --time             Show time instead of time offset\n"
 		"\t-T, --date             Show time and date information\n"
 		"\t-h, --help             Show help options\n");
@@ -62,8 +65,9 @@ static void usage(void)
 
 static const struct option main_options[] = {
 	{ "read",    required_argument, NULL, 'r' },
-	{ "write",   required_argument, NULL, 'b' },
-	{ "server",  required_argument, NULL, 'r' },
+	{ "write",   required_argument, NULL, 'w' },
+	{ "server",  required_argument, NULL, 's' },
+	{ "index",   required_argument, NULL, 'i' },
 	{ "time",    no_argument,       NULL, 't' },
 	{ "date",    no_argument,       NULL, 'T' },
 	{ "version", no_argument,       NULL, 'v' },
@@ -74,7 +78,7 @@ static const struct option main_options[] = {
 int main(int argc, char *argv[])
 {
 	unsigned long filter_mask = 0;
-	const char *reader_path = NULL;
+	const char *str, *reader_path = NULL;
 	sigset_t mask;
 
 	mainloop_init();
@@ -84,7 +88,7 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "r:w:s:tTvh",
+		opt = getopt_long(argc, argv, "r:w:s:i:tTvh",
 						main_options, NULL);
 		if (opt < 0)
 			break;
@@ -99,6 +103,17 @@ int main(int argc, char *argv[])
 		case 's':
 			control_server(optarg);
 			break;
+		case 'i':
+			if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))
+				str = optarg + 3;
+			else
+				str = optarg;
+			if (!isdigit(*str)) {
+				usage();
+				return EXIT_FAILURE;
+			}
+			packet_select_index(atoi(str));
+			break;
 		case 't':
 			filter_mask &= ~PACKET_FILTER_SHOW_TIME_OFFSET;
 			filter_mask |= PACKET_FILTER_SHOW_TIME;
diff --git a/monitor/packet.c b/monitor/packet.c
index a080ff7..fea13df 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -84,6 +84,8 @@
 
 static time_t time_offset = ((time_t) -1);
 static unsigned long filter_mask = 0;
+static bool index_filter = false;
+static uint16_t index_number = 0;
 
 void packet_set_filter(unsigned long filter)
 {
@@ -92,6 +94,9 @@ void packet_set_filter(unsigned long filter)
 
 void packet_add_filter(unsigned long filter)
 {
+	if (index_filter)
+		filter &= ~PACKET_FILTER_SHOW_INDEX;
+
 	filter_mask |= filter;
 }
 
@@ -100,6 +105,14 @@ void packet_del_filter(unsigned long filter)
 	filter_mask &= ~filter;
 }
 
+void packet_select_index(uint16_t index)
+{
+	filter_mask &= ~PACKET_FILTER_SHOW_INDEX;
+
+	index_filter = true;
+	index_number = index;
+}
+
 #define print_space(x) printf("%*c", (x), ' ');
 
 static void print_packet(struct timeval *tv, uint16_t index, char ident,
@@ -1135,6 +1148,9 @@ void packet_hexdump(const unsigned char *buf, uint16_t len)
 void packet_control(struct timeval *tv, uint16_t index, uint16_t opcode,
 					const void *data, uint16_t size)
 {
+	if (index_filter && index_number != index)
+		return;
+
 	control_message(opcode, data, size);
 }
 
@@ -1231,6 +1247,9 @@ void packet_monitor(struct timeval *tv, uint16_t index, uint16_t opcode,
 	const struct monitor_new_index *ni;
 	char str[18], extra_str[24];
 
+	if (index_filter && index_number != index)
+		return;
+
 	if (tv && time_offset == ((time_t) -1))
 		time_offset = tv->tv_sec;
 
diff --git a/monitor/packet.h b/monitor/packet.h
index 711e35c..9a12376 100644
--- a/monitor/packet.h
+++ b/monitor/packet.h
@@ -37,6 +37,8 @@ void packet_set_filter(unsigned long filter);
 void packet_add_filter(unsigned long filter);
 void packet_del_filter(unsigned long filter);
 
+void packet_select_index(uint16_t index);
+
 void packet_hexdump(const unsigned char *buf, uint16_t len);
 
 void packet_control(struct timeval *tv, uint16_t index, uint16_t opcode,