All of lore.kernel.org
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@codecoup.pl>
Subject: [PATCH v2 3/4] tools/btmon-logger: Add support for chainning snoop files
Date: Fri, 19 Jan 2018 16:37:39 +0100	[thread overview]
Message-ID: <20180119153740.4848-3-szymon.janc@codecoup.pl> (raw)
In-Reply-To: <20180119153740.4848-1-szymon.janc@codecoup.pl>

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 428cd3ff2..34afc0d4b 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 = (MONITOR_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


  parent reply	other threads:[~2018-01-19 15:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-19 15:37 [PATCH v2 1/4] lib: Add monitor.h Szymon Janc
2018-01-19 15:37 ` [PATCH v2 2/4] tools: Add initial code for btmon-logger Szymon Janc
2018-01-19 15:37 ` Szymon Janc [this message]
2018-01-19 15:37 ` [PATCH v2 4/4] monitor: Add support for reading btsnoop sets Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180119153740.4848-3-szymon.janc@codecoup.pl \
    --to=szymon.janc@codecoup.pl \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.