OSDN Git Service

monitor: Add support for user logging priority selection
authorMarcel Holtmann <marcel@holtmann.org>
Sun, 8 Nov 2015 02:48:21 +0000 (03:48 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Sun, 8 Nov 2015 02:51:25 +0000 (03:51 +0100)
monitor/main.c
monitor/packet.c
monitor/packet.h

index de48db5..faf629e 100644 (file)
@@ -61,6 +61,7 @@ static void usage(void)
                "\t-w, --write <file>     Save traces in btsnoop format\n"
                "\t-a, --analyze <file>   Analyze traces in btsnoop format\n"
                "\t-s, --server <socket>  Start monitor server socket\n"
+               "\t-p, --priority <level> Show only priority or lower\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"
@@ -104,7 +105,7 @@ int main(int argc, char *argv[])
        for (;;) {
                int opt;
 
-               opt = getopt_long(argc, argv, "r:w:a:s:i:tTSE:vh",
+               opt = getopt_long(argc, argv, "r:w:a:s:p:i:tTSE:vh",
                                                main_options, NULL);
                if (opt < 0)
                        break;
@@ -122,6 +123,9 @@ int main(int argc, char *argv[])
                case 's':
                        control_server(optarg);
                        break;
+               case 'p':
+                       packet_set_priority(optarg);
+                       break;
                case 'i':
                        if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))
                                str = optarg + 3;
index 8674542..1e3fc4c 100644 (file)
@@ -88,6 +88,7 @@
 #define COLOR_PHY_PACKET               COLOR_BLUE
 
 static time_t time_offset = ((time_t) -1);
+static int priority_level = 6;
 static unsigned long filter_mask = 0;
 static bool index_filter = false;
 static uint16_t index_number = 0;
@@ -160,6 +161,11 @@ void packet_del_filter(unsigned long filter)
        filter_mask &= ~filter;
 }
 
+void packet_set_priority(const char *priority)
+{
+       priority_level = atoi(priority);
+}
+
 void packet_select_index(uint16_t index)
 {
        filter_mask &= ~PACKET_FILTER_SHOW_INDEX;
@@ -8717,6 +8723,9 @@ void packet_user_logging(struct timeval *tv, struct ucred *cred,
        const char *label;
        const char *color;
 
+       if (priority > priority_level)
+               return;
+
        switch (priority) {
        case 0x03:
                color = COLOR_ERROR;
index 218a63b..322f101 100644 (file)
@@ -38,6 +38,7 @@ void packet_set_filter(unsigned long filter);
 void packet_add_filter(unsigned long filter);
 void packet_del_filter(unsigned long filter);
 
+void packet_set_priority(const char *priority);
 void packet_select_index(uint16_t index);
 
 void packet_hexdump(const unsigned char *buf, uint16_t len);