[PATCH v2 2/3] tools/btmon-logger: Add support for chainning snoop files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This allows to generate split btsnoop file (eg for log rotation). To
achieve that new opcode is added to btsnoop file format. This opcode
contains random Set ID and sequence number which are used to identyfing
files and set. This special opcode is always first opcode in btsnoop
file that is part of a set.
---
 src/shared/btsnoop.h |  6 ++++++
 tools/btmon-logger.c | 26 +++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/shared/btsnoop.h b/src/shared/btsnoop.h
index 3df8998a3..a26d0a147 100644
--- a/src/shared/btsnoop.h
+++ b/src/shared/btsnoop.h
@@ -53,6 +53,7 @@
 #define BTSNOOP_OPCODE_CTRL_CLOSE	15
 #define BTSNOOP_OPCODE_CTRL_COMMAND	16
 #define BTSNOOP_OPCODE_CTRL_EVENT	17
+#define BTSNOOP_OPCODE_SET_ID		18
 
 #define BTSNOOP_MAX_PACKET_SIZE		(1486 + 4)
 
@@ -96,6 +97,11 @@ struct btsnoop_opcode_user_logging {
 	uint8_t  ident_len;
 } __attribute__((packed));
 
+struct btsnoop_opcode_set_id {
+	uint8_t id[16];
+	uint32_t seq;
+} __attribute__((packed));
+
 struct btsnoop;
 
 struct btsnoop *btsnoop_open(const char *path, unsigned long flags);
diff --git a/tools/btmon-logger.c b/tools/btmon-logger.c
index cd02f611b..f0d47f820 100644
--- a/tools/btmon-logger.c
+++ b/tools/btmon-logger.c
@@ -35,6 +35,7 @@
 #include <getopt.h>
 #include <unistd.h>
 #include <sys/socket.h>
+#include <sys/random.h>
 
 #include "lib/bluetooth.h"
 #include "lib/hci.h"
@@ -69,6 +70,9 @@ static size_t write_size = 0;
 
 static struct btsnoop *btsnoop_file = NULL;
 
+static uint8_t set_random_id[16];
+static uint32_t set_seq = 0;
+
 static bool create_btsnoop(void)
 {
 	static char real_path[FILENAME_MAX];
@@ -86,10 +90,8 @@ static bool create_btsnoop(void)
 				path, prefix, tm.tm_year + 1900, tm.tm_mon + 1,
 				tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
 	} else {
-		static unsigned int cnt = 0;
-
 		snprintf(real_path, sizeof(real_path), "%s/%s_%u.btsnoop",
-							path, prefix, cnt++);
+							path, prefix, set_seq);
 	}
 
 	btsnoop_file = btsnoop_create(real_path, BTSNOOP_FORMAT_MONITOR);
@@ -98,6 +100,21 @@ static bool create_btsnoop(void)
 
 	write_size = BTSNOOP_HDR_SIZE;
 
+	if (write_limit) {
+		struct btsnoop_opcode_set_id op;
+		uint32_t flags;
+
+		memcpy(&op.id, set_random_id, sizeof(op.id));
+		op.seq = cpu_to_be32(set_seq);
+
+		flags = (MGMT_INDEX_NONE << 16) | BTSNOOP_OPCODE_SET_ID;
+
+		btsnoop_write(btsnoop_file, &tv, flags, 0, &op, sizeof(op));
+
+		set_seq++;
+		write_size += BTSNOOP_PKT_SIZE + sizeof(op);
+	}
+
 	return true;
 }
 
@@ -324,6 +341,9 @@ int main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
+	if (write_limit)
+		getrandom(set_random_id, sizeof(set_random_id), 0);
+
 	if (!open_monitor_channel() || !create_btsnoop())
 		return EXIT_FAILURE;
 
-- 
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux