Skip to contentSkip to conversation

replay: Add initial version of replay tool

PATCH Superseded Anton Weber 1 participant 14 messages Aug 9, 2012 – Sep 5, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 replay: Add initial version of replay tool

This utility uses a VHCI interface to simulate HCI traffic from a recorded scenario. It reads packets from BTSnoop dump files and replays them on the virtual interface.

It is meant as a debugging tool that allows to investigate problems with particular controllers and Bluetooth hardware on other system configurations.

---
 .gitignore            |    1 +
 Makefile.tools        |   12 +-
 tools/replay/hciseq.h |   43 +++++
 tools/replay/main.c   |  501 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/replay/main.h   |   64 +++++++
 5 files changed, 620 insertions(+), 1 deletion(-)
 create mode 100644 tools/replay/hciseq.h
 create mode 100644 tools/replay/main.c
 create mode 100644 tools/replay/main.h
.gitignore +1 -0
index 38318cd..d53e266 100644
@@ -87,6 +87,7 @@ unit/test-eir
 tools/btmgmt
 monitor/btmon
 emulator/btvirt
+tools/replay/btreplay
 
 doc/*.bak
 doc/*.stamp
Makefile.tools +11 -1
index 5579b86..4a3aca5 100644
@@ -50,7 +50,7 @@ tools_ppporc_LDADD = lib/libbluetooth-private.la
 
 tools_hcieventmask_LDADD = lib/libbluetooth-private.la
 
-noinst_PROGRAMS += tools/btmgmt monitor/btmon emulator/btvirt
+noinst_PROGRAMS += tools/btmgmt monitor/btmon emulator/btvirt tools/replay/btreplay
 
 tools_btmgmt_SOURCES = tools/btmgmt.c src/glib-helper.c
 tools_btmgmt_LDADD = lib/libbluetooth-private.la @GLIB_LIBS@
@@ -69,6 +69,16 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 					emulator/vhci.h emulator/vhci.c \
 					emulator/btdev.h emulator/btdev.c
 
+tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
+					tools/replay/hciseq.h \
+					monitor/packet.h monitor/packet.c \
+					monitor/btsnoop.h monitor/btsnoop.c \
+					monitor/control.h monitor/control.c \
+					monitor/mainloop.h monitor/mainloop.c \
+					lib/hci.h
+
+tools_replay_btreplay_LDADD = lib/libbluetooth-private.la
+
 if READLINE
 bin_PROGRAMS += attrib/gatttool
 
tools/replay/hciseq.h new file +43 -0

43 lines not on this page · raw message

tools/replay/main.c new file +501 -0

501 lines not on this page · raw message

tools/replay/main.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/4 replay: Add timing functionality

Add -d parameter that lets user choose between two timing modes.
delta: use time difference between two packets for delay
none: no delay

Add -m parameter to specify a factor that multiplies delays in delta timing mode.

Add -t parameter to set the epoll timeout when receiving packets.

---
 Makefile.tools        |    3 +-
 tools/replay/hciseq.c |   53 ++++++++++++++++++++++++++++
 tools/replay/hciseq.h |   23 +++++++++++++
 tools/replay/main.c   |   56 +++++++++++++++++++++++++++++-
 tools/replay/main.h   |   21 +-----------
 tools/replay/time.c   |   91 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/replay/time.h   |   31 +++++++++++++++++
 7 files changed, 256 insertions(+), 22 deletions(-)
 create mode 100644 tools/replay/hciseq.c
 create mode 100644 tools/replay/time.c
 create mode 100644 tools/replay/time.h
Makefile.tools +2 -1
index 4a3aca5..6767300 100644
@@ -70,7 +70,8 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 					emulator/btdev.h emulator/btdev.c
 
 tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
-					tools/replay/hciseq.h \
+					tools/replay/hciseq.h tools/replay/hciseq.c \
+					tools/replay/time.h tools/replay/time.c \
 					monitor/packet.h monitor/packet.c \
 					monitor/btsnoop.h monitor/btsnoop.c \
 					monitor/control.h monitor/control.c \
tools/replay/hciseq.c new file +53 -0

53 lines not on this page · raw message

tools/replay/hciseq.h +23 -0
index bf953cd..f9fe7c8 100644
@@ -22,6 +22,25 @@
  *
  */
 
+struct frame {
+	void *data;
+	uint32_t data_len;
+	void *ptr;
+	uint32_t len;
+	uint16_t dev_id;
+	uint8_t in;
+	uint8_t master;
+	uint16_t handle;
+	uint16_t cid;
+	uint16_t num;
+	uint8_t dlci;
+	uint8_t channel;
+	unsigned long flags;
+	struct timeval ts;
+	int pppdump_fd;
+	int audio_fd;
+};
+
 enum hciseq_action {
 	HCISEQ_ACTION_REPLAY = 0,
 };
@@ -33,6 +52,8 @@ struct hciseq_list {
 };
 
 struct hciseq_attr {
+	struct timeval ts_rel;
+	struct timeval ts_diff;
 	enum hciseq_action action;
 };
 
@@ -41,3 +62,5 @@ struct hciseq_node {
 	struct hciseq_node *next;
 	struct hciseq_attr *attr;
 };
+
+void calc_rel_ts(struct hciseq_list *seq);
tools/replay/main.c +55 -1

124 lines not on this page · raw message

tools/replay/main.h +1 -20
index d80deec..2223789 100644
@@ -42,23 +42,4 @@ struct btsnoop_pkt {
 } __attribute__ ((packed));
 #define BTSNOOP_PKT_SIZE (sizeof(struct btsnoop_pkt))
 
-static uint8_t btsnoop_id[] = { 0x62, 0x74, 0x73, 0x6e, 0x6f, 0x6f, 0x70, 0x00 };
-
-struct frame {
-	void *data;
-	uint32_t data_len;
-	void *ptr;
-	uint32_t len;
-	uint16_t dev_id;
-	uint8_t in;
-	uint8_t master;
-	uint16_t handle;
-	uint16_t cid;
-	uint16_t num;
-	uint8_t dlci;
-	uint8_t channel;
-	unsigned long flags;
-	struct timeval ts;
-	int pppdump_fd;
-	int audio_fd;
-};
+uint8_t btsnoop_id[] = { 0x62, 0x74, 0x73, 0x6e, 0x6f, 0x6f, 0x70, 0x00 };
tools/replay/time.c new file +91 -0

91 lines not on this page · raw message

tools/replay/time.h new file +31 -0
new file mode 100644
index 0000000..0c876a4
@@ -0,0 +1,31 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *  Copyright (C) 2012       Anton Weber <[email protected]>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+void timeval_adjust_usec(struct timeval *l, struct timeval *r);
+
+__useconds_t
+timeval_diff(struct timeval *l, struct timeval *r, struct timeval *diff);
+
+int timeval_cmp(struct timeval *l, struct timeval *r);
+
+inline __useconds_t
+	get_timeval_passed(struct timeval *since, struct timeval *diff);
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 3/4 replay: Add emulation support

In reply to Anton Weber

Integrate emulator so it can process selected packets instead of replaying them from the sequence. The behaviour is controlled through the action attribute in hciseq_attr.

If set to HCISEQ_ACTION_EMULATE, hcireplay will use the emulator to process the packet automatically instead of replaying it. HCISEQ_ACTION_REPLAY keeps the previous behaviour and replays the packet using the dump file.

---
 Makefile.tools        |    1 +
 tools/replay/hciseq.h |    1 +
 tools/replay/main.c   |   52 ++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 51 insertions(+), 3 deletions(-)
Makefile.tools +1 -0
index 6767300..8b3c8d8 100644
@@ -76,6 +76,7 @@ tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
 					monitor/btsnoop.h monitor/btsnoop.c \
 					monitor/control.h monitor/control.c \
 					monitor/mainloop.h monitor/mainloop.c \
+					emulator/btdev.h emulator/btdev.c \
 					lib/hci.h
 
 tools_replay_btreplay_LDADD = lib/libbluetooth-private.la
tools/replay/hciseq.h +1 -0
index f9fe7c8..1454147 100644
@@ -43,6 +43,7 @@ struct frame {
 
 enum hciseq_action {
 	HCISEQ_ACTION_REPLAY = 0,
+	HCISEQ_ACTION_EMULATE = 1
 };
 
 struct hciseq_list {
tools/replay/main.c +49 -3

96 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 4/4 replay: Add config file parser and skip action

In reply to Anton Weber

Add support for config files to manipulate the loaded sequence. A config file can be specified with the new -c command line parameter.

The config syntax is:
scope attr=value[,attr=value,...]

e.g.:
all delta=300,action=replay
1-4 action=emulate
1 delta=500
HCI_EVT_0x0e delta=0
HCI_CMD_0x03|0x0003 action=emulate
HCI_ACL action=replay

The inital version supports the attributes delta and action and all scope types shown in the example.

HCISEQ_ACTION_SKIP allows to skip a packet in the sequence. The action can be set in config files using "action=skip".

---
 Makefile.tools               |    1 +
 tools/replay/config-parser.c |  506 ++++++++++++++++++++++++++++++++++++++++++
 tools/replay/config-parser.h |   36 +++
 tools/replay/hciseq.h        |    3 +-
 tools/replay/main.c          |  117 +++++++++-
 tools/replay/main.h          |    2 -
 6 files changed, 661 insertions(+), 4 deletions(-)
 create mode 100644 tools/replay/config-parser.c
 create mode 100644 tools/replay/config-parser.h
Makefile.tools +1 -0
index 8b3c8d8..ba2db00 100644
@@ -72,6 +72,7 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
 					tools/replay/hciseq.h tools/replay/hciseq.c \
 					tools/replay/time.h tools/replay/time.c \
+					tools/replay/config-parser.h tools/replay/config-parser.c \
 					monitor/packet.h monitor/packet.c \
 					monitor/btsnoop.h monitor/btsnoop.c \
 					monitor/control.h monitor/control.c \
tools/replay/config-parser.c new file +506 -0

506 lines not on this page · raw message

tools/replay/config-parser.h new file +36 -0
new file mode 100644
index 0000000..265628d
@@ -0,0 +1,36 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *  Copyright (C) 2012       Anton Weber <[email protected]>
+ *  Copyright (C) 2004-2010  Marcel Holtmann <[email protected]>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "hciseq.h"
+
+struct hciseq_type_cfg {
+	struct hciseq_attr *cmd[9216]; /*
+					 * opcodes 0x0000 - 0x23FF
+					 * (OGF 0x01 - 0x08)
+					 */
+	struct hciseq_attr *evt[256]; /* events 0x00 - 0xFF */
+	struct hciseq_attr *acl;
+};
+
+int parse_config(char *path, struct hciseq_list *_seq,
+		 struct hciseq_type_cfg *_type_cfg, bool _verbose);
tools/replay/hciseq.h +2 -1
index 1454147..fa589a3 100644
@@ -43,7 +43,8 @@ struct frame {
 
 enum hciseq_action {
 	HCISEQ_ACTION_REPLAY = 0,
-	HCISEQ_ACTION_EMULATE = 1
+	HCISEQ_ACTION_EMULATE = 1,
+	HCISEQ_ACTION_SKIP = 2
 };
 
 struct hciseq_list {
tools/replay/main.c +116 -1

211 lines not on this page · raw message

tools/replay/main.h +0 -2
index 2223789..e8b7365 100644
@@ -23,8 +23,6 @@
  *
  */
 
-#include "hciseq.h"
-
 struct btsnoop_hdr {
 	uint8_t id[8];		/* Identification Pattern */
 	uint32_t version;	/* Version Number = 1 */
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v2 1/4 replay: Add initial version of replay tool

In reply to Anton Weber

This utility uses a VHCI interface to simulate HCI traffic from a recorded scenario. It reads packets from BTSnoop dump files and replays them on the virtual interface.

It is meant as a debugging tool that allows to investigate problems with particular controllers and Bluetooth hardware on other system configurations.
---
v1 -> v2: File header check for "btsnoop" string incorrectly returned failure on return value 0 instead of !=0

 .gitignore            |    1 +
 Makefile.tools        |   12 +-
 tools/replay/hciseq.h |   43 +++++
 tools/replay/main.c   |  501 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/replay/main.h   |   64 +++++++
 5 files changed, 620 insertions(+), 1 deletion(-)
 create mode 100644 tools/replay/hciseq.h
 create mode 100644 tools/replay/main.c
 create mode 100644 tools/replay/main.h
.gitignore +1 -0
index 38318cd..d53e266 100644
@@ -87,6 +87,7 @@ unit/test-eir
 tools/btmgmt
 monitor/btmon
 emulator/btvirt
+tools/replay/btreplay
 
 doc/*.bak
 doc/*.stamp
Makefile.tools +11 -1
index 5579b86..4a3aca5 100644
@@ -50,7 +50,7 @@ tools_ppporc_LDADD = lib/libbluetooth-private.la
 
 tools_hcieventmask_LDADD = lib/libbluetooth-private.la
 
-noinst_PROGRAMS += tools/btmgmt monitor/btmon emulator/btvirt
+noinst_PROGRAMS += tools/btmgmt monitor/btmon emulator/btvirt tools/replay/btreplay
 
 tools_btmgmt_SOURCES = tools/btmgmt.c src/glib-helper.c
 tools_btmgmt_LDADD = lib/libbluetooth-private.la @GLIB_LIBS@
@@ -69,6 +69,16 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 					emulator/vhci.h emulator/vhci.c \
 					emulator/btdev.h emulator/btdev.c
 
+tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
+					tools/replay/hciseq.h \
+					monitor/packet.h monitor/packet.c \
+					monitor/btsnoop.h monitor/btsnoop.c \
+					monitor/control.h monitor/control.c \
+					monitor/mainloop.h monitor/mainloop.c \
+					lib/hci.h
+
+tools_replay_btreplay_LDADD = lib/libbluetooth-private.la
+
 if READLINE
 bin_PROGRAMS += attrib/gatttool
 
tools/replay/hciseq.h new file +43 -0

43 lines not on this page · raw message

tools/replay/main.c new file +501 -0

501 lines not on this page · raw message

tools/replay/main.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v2 2/4 replay: Add timing functionality

Add -d parameter that lets user choose between two timing modes.
delta: use time difference between two packets for delay
none: no delay

Add -m parameter to specify a factor that multiplies delays in delta timing mode.

Add -t parameter to set the epoll timeout when receiving packets.

---
 Makefile.tools        |    3 +-
 tools/replay/hciseq.c |   53 ++++++++++++++++++++++++++++
 tools/replay/hciseq.h |   23 +++++++++++++
 tools/replay/main.c   |   56 +++++++++++++++++++++++++++++-
 tools/replay/main.h   |   21 +-----------
 tools/replay/time.c   |   91 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/replay/time.h   |   31 +++++++++++++++++
 7 files changed, 256 insertions(+), 22 deletions(-)
 create mode 100644 tools/replay/hciseq.c
 create mode 100644 tools/replay/time.c
 create mode 100644 tools/replay/time.h
Makefile.tools +2 -1
index 4a3aca5..6767300 100644
@@ -70,7 +70,8 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 					emulator/btdev.h emulator/btdev.c
 
 tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
-					tools/replay/hciseq.h \
+					tools/replay/hciseq.h tools/replay/hciseq.c \
+					tools/replay/time.h tools/replay/time.c \
 					monitor/packet.h monitor/packet.c \
 					monitor/btsnoop.h monitor/btsnoop.c \
 					monitor/control.h monitor/control.c \
tools/replay/hciseq.c new file +53 -0

53 lines not on this page · raw message

tools/replay/hciseq.h +23 -0
index bf953cd..f9fe7c8 100644
@@ -22,6 +22,25 @@
  *
  */
 
+struct frame {
+	void *data;
+	uint32_t data_len;
+	void *ptr;
+	uint32_t len;
+	uint16_t dev_id;
+	uint8_t in;
+	uint8_t master;
+	uint16_t handle;
+	uint16_t cid;
+	uint16_t num;
+	uint8_t dlci;
+	uint8_t channel;
+	unsigned long flags;
+	struct timeval ts;
+	int pppdump_fd;
+	int audio_fd;
+};
+
 enum hciseq_action {
 	HCISEQ_ACTION_REPLAY = 0,
 };
@@ -33,6 +52,8 @@ struct hciseq_list {
 };
 
 struct hciseq_attr {
+	struct timeval ts_rel;
+	struct timeval ts_diff;
 	enum hciseq_action action;
 };
 
@@ -41,3 +62,5 @@ struct hciseq_node {
 	struct hciseq_node *next;
 	struct hciseq_attr *attr;
 };
+
+void calc_rel_ts(struct hciseq_list *seq);
tools/replay/main.c +55 -1

124 lines not on this page · raw message

tools/replay/main.h +1 -20
index d80deec..2223789 100644
@@ -42,23 +42,4 @@ struct btsnoop_pkt {
 } __attribute__ ((packed));
 #define BTSNOOP_PKT_SIZE (sizeof(struct btsnoop_pkt))
 
-static uint8_t btsnoop_id[] = { 0x62, 0x74, 0x73, 0x6e, 0x6f, 0x6f, 0x70, 0x00 };
-
-struct frame {
-	void *data;
-	uint32_t data_len;
-	void *ptr;
-	uint32_t len;
-	uint16_t dev_id;
-	uint8_t in;
-	uint8_t master;
-	uint16_t handle;
-	uint16_t cid;
-	uint16_t num;
-	uint8_t dlci;
-	uint8_t channel;
-	unsigned long flags;
-	struct timeval ts;
-	int pppdump_fd;
-	int audio_fd;
-};
+uint8_t btsnoop_id[] = { 0x62, 0x74, 0x73, 0x6e, 0x6f, 0x6f, 0x70, 0x00 };
tools/replay/time.c new file +91 -0

91 lines not on this page · raw message

tools/replay/time.h new file +31 -0
new file mode 100644
index 0000000..0c876a4
@@ -0,0 +1,31 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *  Copyright (C) 2012       Anton Weber <[email protected]>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+void timeval_adjust_usec(struct timeval *l, struct timeval *r);
+
+__useconds_t
+timeval_diff(struct timeval *l, struct timeval *r, struct timeval *diff);
+
+int timeval_cmp(struct timeval *l, struct timeval *r);
+
+inline __useconds_t
+	get_timeval_passed(struct timeval *since, struct timeval *diff);
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v2 3/4 replay: Add emulation support

In reply to Anton Weber

Integrate emulator so it can process selected packets instead of replaying them from the sequence. The behaviour is controlled through the action attribute in hciseq_attr.

If set to HCISEQ_ACTION_EMULATE, hcireplay will use the emulator to process the packet automatically instead of replaying it. HCISEQ_ACTION_REPLAY keeps the previous behaviour and replays the packet using the dump file.

---
 Makefile.tools        |    1 +
 tools/replay/hciseq.h |    1 +
 tools/replay/main.c   |   52 ++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 51 insertions(+), 3 deletions(-)
Makefile.tools +1 -0
index 6767300..8b3c8d8 100644
@@ -76,6 +76,7 @@ tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
 					monitor/btsnoop.h monitor/btsnoop.c \
 					monitor/control.h monitor/control.c \
 					monitor/mainloop.h monitor/mainloop.c \
+					emulator/btdev.h emulator/btdev.c \
 					lib/hci.h
 
 tools_replay_btreplay_LDADD = lib/libbluetooth-private.la
tools/replay/hciseq.h +1 -0
index f9fe7c8..1454147 100644
@@ -43,6 +43,7 @@ struct frame {
 
 enum hciseq_action {
 	HCISEQ_ACTION_REPLAY = 0,
+	HCISEQ_ACTION_EMULATE = 1
 };
 
 struct hciseq_list {
tools/replay/main.c +49 -3

96 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#7 lore raw

PATCH v2 4/4 replay: Add config file parser and skip action

In reply to Anton Weber

Add support for config files to manipulate the loaded sequence. A config file can be specified with the new -c command line parameter.

The config syntax is:
scope attr=value[,attr=value,...]

e.g.:
all delta=300,action=replay
1-4 action=emulate
1 delta=500
HCI_EVT_0x0e delta=0
HCI_CMD_0x03|0x0003 action=emulate
HCI_ACL action=replay

The inital version supports the attributes delta and action and all scope types shown in the example.

HCISEQ_ACTION_SKIP allows to skip a packet in the sequence. The action can be set in config files using "action=skip".
---
v1 -> v2: delete_type_cfg() was using an outdated number of entries when freeing type_cfg.cmd[]

 Makefile.tools               |    1 +
 tools/replay/config-parser.c |  506 ++++++++++++++++++++++++++++++++++++++++++
 tools/replay/config-parser.h |   36 +++
 tools/replay/hciseq.h        |    3 +-
 tools/replay/main.c          |  117 +++++++++-
 tools/replay/main.h          |    2 -
 6 files changed, 661 insertions(+), 4 deletions(-)
 create mode 100644 tools/replay/config-parser.c
 create mode 100644 tools/replay/config-parser.h
Makefile.tools +1 -0
index 8b3c8d8..ba2db00 100644
@@ -72,6 +72,7 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
 					tools/replay/hciseq.h tools/replay/hciseq.c \
 					tools/replay/time.h tools/replay/time.c \
+					tools/replay/config-parser.h tools/replay/config-parser.c \
 					monitor/packet.h monitor/packet.c \
 					monitor/btsnoop.h monitor/btsnoop.c \
 					monitor/control.h monitor/control.c \
tools/replay/config-parser.c new file +506 -0

506 lines not on this page · raw message

tools/replay/config-parser.h new file +36 -0
new file mode 100644
index 0000000..265628d
@@ -0,0 +1,36 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *  Copyright (C) 2012       Anton Weber <[email protected]>
+ *  Copyright (C) 2004-2010  Marcel Holtmann <[email protected]>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "hciseq.h"
+
+struct hciseq_type_cfg {
+	struct hciseq_attr *cmd[9216]; /*
+					 * opcodes 0x0000 - 0x23FF
+					 * (OGF 0x01 - 0x08)
+					 */
+	struct hciseq_attr *evt[256]; /* events 0x00 - 0xFF */
+	struct hciseq_attr *acl;
+};
+
+int parse_config(char *path, struct hciseq_list *_seq,
+		 struct hciseq_type_cfg *_type_cfg, bool _verbose);
tools/replay/hciseq.h +2 -1
index 1454147..fa589a3 100644
@@ -43,7 +43,8 @@ struct frame {
 
 enum hciseq_action {
 	HCISEQ_ACTION_REPLAY = 0,
-	HCISEQ_ACTION_EMULATE = 1
+	HCISEQ_ACTION_EMULATE = 1,
+	HCISEQ_ACTION_SKIP = 2
 };
 
 struct hciseq_list {
tools/replay/main.c +116 -1

211 lines not on this page · raw message

tools/replay/main.h +0 -2
index 2223789..e8b7365 100644
@@ -23,8 +23,6 @@
  *
  */
 
-#include "hciseq.h"
-
 struct btsnoop_hdr {
 	uint8_t id[8];		/* Identification Pattern */
 	uint32_t version;	/* Version Number = 1 */
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH v3 1/6 replay: Add initial version of replay tool

In reply to Anton Weber

This utility uses a VHCI interface to simulate HCI traffic from a recorded scenario. It reads packets from BTSnoop dump files and replays them on the virtual interface.

It is meant as a debugging tool that allows to investigate problems with particular controllers and Bluetooth hardware on other system configurations.

---
 .gitignore            |    1 +
 Makefile.tools        |   12 +-
 tools/replay/hciseq.h |   43 +++++
 tools/replay/main.c   |  501 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/replay/main.h   |   64 +++++++
 5 files changed, 620 insertions(+), 1 deletion(-)
 create mode 100644 tools/replay/hciseq.h
 create mode 100644 tools/replay/main.c
 create mode 100644 tools/replay/main.h
.gitignore +1 -0
index 38318cd..d53e266 100644
@@ -87,6 +87,7 @@ unit/test-eir
 tools/btmgmt
 monitor/btmon
 emulator/btvirt
+tools/replay/btreplay
 
 doc/*.bak
 doc/*.stamp
Makefile.tools +11 -1
index 5579b86..4a3aca5 100644
@@ -50,7 +50,7 @@ tools_ppporc_LDADD = lib/libbluetooth-private.la
 
 tools_hcieventmask_LDADD = lib/libbluetooth-private.la
 
-noinst_PROGRAMS += tools/btmgmt monitor/btmon emulator/btvirt
+noinst_PROGRAMS += tools/btmgmt monitor/btmon emulator/btvirt tools/replay/btreplay
 
 tools_btmgmt_SOURCES = tools/btmgmt.c src/glib-helper.c
 tools_btmgmt_LDADD = lib/libbluetooth-private.la @GLIB_LIBS@
@@ -69,6 +69,16 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 					emulator/vhci.h emulator/vhci.c \
 					emulator/btdev.h emulator/btdev.c
 
+tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
+					tools/replay/hciseq.h \
+					monitor/packet.h monitor/packet.c \
+					monitor/btsnoop.h monitor/btsnoop.c \
+					monitor/control.h monitor/control.c \
+					monitor/mainloop.h monitor/mainloop.c \
+					lib/hci.h
+
+tools_replay_btreplay_LDADD = lib/libbluetooth-private.la
+
 if READLINE
 bin_PROGRAMS += attrib/gatttool
 
tools/replay/hciseq.h new file +43 -0

43 lines not on this page · raw message

tools/replay/main.c new file +501 -0

501 lines not on this page · raw message

tools/replay/main.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v3 2/6 replay: Add timing functionality

Add -d parameter that lets user choose between two delay modes.
delta: use time difference between two packets for delay
none: no delay

Add -m parameter to specify a factor that multiplies delays in delta delay mode.

Add -t parameter to set the epoll timeout when receiving packets.
---
v2 -> v3: Rename long parameters timing and factor

 Makefile.tools        |    3 +-
 tools/replay/hciseq.c |   53 ++++++++++++++++++++++++++++
 tools/replay/hciseq.h |   23 +++++++++++++
 tools/replay/main.c   |   62 ++++++++++++++++++++++++++++++---
 tools/replay/main.h   |   21 +-----------
 tools/replay/time.c   |   91 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/replay/time.h   |   31 +++++++++++++++++
 7 files changed, 259 insertions(+), 25 deletions(-)
 create mode 100644 tools/replay/hciseq.c
 create mode 100644 tools/replay/time.c
 create mode 100644 tools/replay/time.h
Makefile.tools +2 -1
index 4a3aca5..6767300 100644
@@ -70,7 +70,8 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 					emulator/btdev.h emulator/btdev.c
 
 tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
-					tools/replay/hciseq.h \
+					tools/replay/hciseq.h tools/replay/hciseq.c \
+					tools/replay/time.h tools/replay/time.c \
 					monitor/packet.h monitor/packet.c \
 					monitor/btsnoop.h monitor/btsnoop.c \
 					monitor/control.h monitor/control.c \
tools/replay/hciseq.c new file +53 -0

53 lines not on this page · raw message

tools/replay/hciseq.h +23 -0
index bf953cd..f9fe7c8 100644
@@ -22,6 +22,25 @@
  *
  */
 
+struct frame {
+	void *data;
+	uint32_t data_len;
+	void *ptr;
+	uint32_t len;
+	uint16_t dev_id;
+	uint8_t in;
+	uint8_t master;
+	uint16_t handle;
+	uint16_t cid;
+	uint16_t num;
+	uint8_t dlci;
+	uint8_t channel;
+	unsigned long flags;
+	struct timeval ts;
+	int pppdump_fd;
+	int audio_fd;
+};
+
 enum hciseq_action {
 	HCISEQ_ACTION_REPLAY = 0,
 };
@@ -33,6 +52,8 @@ struct hciseq_list {
 };
 
 struct hciseq_attr {
+	struct timeval ts_rel;
+	struct timeval ts_diff;
 	enum hciseq_action action;
 };
 
@@ -41,3 +62,5 @@ struct hciseq_node {
 	struct hciseq_node *next;
 	struct hciseq_attr *attr;
 };
+
+void calc_rel_ts(struct hciseq_list *seq);
tools/replay/main.c +58 -4

127 lines not on this page · raw message

tools/replay/main.h +1 -20
index d80deec..2223789 100644
@@ -42,23 +42,4 @@ struct btsnoop_pkt {
 } __attribute__ ((packed));
 #define BTSNOOP_PKT_SIZE (sizeof(struct btsnoop_pkt))
 
-static uint8_t btsnoop_id[] = { 0x62, 0x74, 0x73, 0x6e, 0x6f, 0x6f, 0x70, 0x00 };
-
-struct frame {
-	void *data;
-	uint32_t data_len;
-	void *ptr;
-	uint32_t len;
-	uint16_t dev_id;
-	uint8_t in;
-	uint8_t master;
-	uint16_t handle;
-	uint16_t cid;
-	uint16_t num;
-	uint8_t dlci;
-	uint8_t channel;
-	unsigned long flags;
-	struct timeval ts;
-	int pppdump_fd;
-	int audio_fd;
-};
+uint8_t btsnoop_id[] = { 0x62, 0x74, 0x73, 0x6e, 0x6f, 0x6f, 0x70, 0x00 };
tools/replay/time.c new file +91 -0

91 lines not on this page · raw message

tools/replay/time.h new file +31 -0
new file mode 100644
index 0000000..0c876a4
@@ -0,0 +1,31 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *  Copyright (C) 2012       Anton Weber <[email protected]>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+void timeval_adjust_usec(struct timeval *l, struct timeval *r);
+
+__useconds_t
+timeval_diff(struct timeval *l, struct timeval *r, struct timeval *diff);
+
+int timeval_cmp(struct timeval *l, struct timeval *r);
+
+inline __useconds_t
+	get_timeval_passed(struct timeval *since, struct timeval *diff);
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v3 3/6 replay: Add emulation support

In reply to Anton Weber

Integrate emulator so it can process selected packets instead of replaying them from the sequence. The behaviour is controlled through the action attribute in hciseq_attr.

If set to HCISEQ_ACTION_EMULATE, hcireplay will use the emulator to process the packet automatically instead of replaying it. HCISEQ_ACTION_REPLAY keeps the previous behaviour and replays the packet using the dump file.

---
 Makefile.tools        |    1 +
 tools/replay/hciseq.h |    1 +
 tools/replay/main.c   |   52 ++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 51 insertions(+), 3 deletions(-)
Makefile.tools +1 -0
index 6767300..8b3c8d8 100644
@@ -76,6 +76,7 @@ tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
 					monitor/btsnoop.h monitor/btsnoop.c \
 					monitor/control.h monitor/control.c \
 					monitor/mainloop.h monitor/mainloop.c \
+					emulator/btdev.h emulator/btdev.c \
 					lib/hci.h
 
 tools_replay_btreplay_LDADD = lib/libbluetooth-private.la
tools/replay/hciseq.h +1 -0
index f9fe7c8..1454147 100644
@@ -43,6 +43,7 @@ struct frame {
 
 enum hciseq_action {
 	HCISEQ_ACTION_REPLAY = 0,
+	HCISEQ_ACTION_EMULATE = 1
 };
 
 struct hciseq_list {
tools/replay/main.c +49 -3

96 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#11 lore raw

PATCH v3 4/6 replay: Add config file parser and skip action

In reply to Anton Weber

Add support for config files to manipulate the loaded sequence. A config file can be specified with the new -c command line parameter.

The config syntax is:
scope key=value[,key=value,...]

e.g.:
all delta=300,action=replay
1-4 action=emulate
1 delta=500
HCI_EVT_0x0e delta=0
HCI_CMD_0x03|0x0003 action=emulate
HCI_ACL action=replay

The inital version supports the keys delta and action and all scope types shown in the example.

HCISEQ_ACTION_SKIP allows to skip a packet in the sequence. The action can be set in config files using "action=skip".

---
 Makefile.tools               |    1 +
 tools/replay/config-parser.c |  506 ++++++++++++++++++++++++++++++++++++++++++
 tools/replay/config-parser.h |   36 +++
 tools/replay/hciseq.h        |    3 +-
 tools/replay/main.c          |  117 +++++++++-
 tools/replay/main.h          |    2 -
 6 files changed, 661 insertions(+), 4 deletions(-)
 create mode 100644 tools/replay/config-parser.c
 create mode 100644 tools/replay/config-parser.h
Makefile.tools +1 -0
index 8b3c8d8..ba2db00 100644
@@ -72,6 +72,7 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \
 tools_replay_btreplay_SOURCES = tools/replay/main.h tools/replay/main.c \
 					tools/replay/hciseq.h tools/replay/hciseq.c \
 					tools/replay/time.h tools/replay/time.c \
+					tools/replay/config-parser.h tools/replay/config-parser.c \
 					monitor/packet.h monitor/packet.c \
 					monitor/btsnoop.h monitor/btsnoop.c \
 					monitor/control.h monitor/control.c \
tools/replay/config-parser.c new file +506 -0

506 lines not on this page · raw message

tools/replay/config-parser.h new file +36 -0
new file mode 100644
index 0000000..265628d
@@ -0,0 +1,36 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *  Copyright (C) 2012       Anton Weber <[email protected]>
+ *  Copyright (C) 2004-2010  Marcel Holtmann <[email protected]>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "hciseq.h"
+
+struct hciseq_type_cfg {
+	struct hciseq_attr *cmd[9216]; /*
+					 * opcodes 0x0000 - 0x23FF
+					 * (OGF 0x01 - 0x08)
+					 */
+	struct hciseq_attr *evt[256]; /* events 0x00 - 0xFF */
+	struct hciseq_attr *acl;
+};
+
+int parse_config(char *path, struct hciseq_list *_seq,
+		 struct hciseq_type_cfg *_type_cfg, bool _verbose);
tools/replay/hciseq.h +2 -1
index 1454147..fa589a3 100644
@@ -43,7 +43,8 @@ struct frame {
 
 enum hciseq_action {
 	HCISEQ_ACTION_REPLAY = 0,
-	HCISEQ_ACTION_EMULATE = 1
+	HCISEQ_ACTION_EMULATE = 1,
+	HCISEQ_ACTION_SKIP = 2
 };
 
 struct hciseq_list {
tools/replay/main.c +116 -1

211 lines not on this page · raw message

tools/replay/main.h +0 -2
index 2223789..e8b7365 100644
@@ -23,8 +23,6 @@
  *
  */
 
-#include "hciseq.h"
-
 struct btsnoop_hdr {
 	uint8_t id[8];		/* Identification Pattern */
 	uint32_t version;	/* Version Number = 1 */
Signature · 1 line
1.7.9.5
#12 lore raw

PATCH v3 5/6 replay: Add man page

In reply to Anton Weber
---
 Makefile.tools          |    6 +-
 tools/replay/btreplay.1 |  148 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 152 insertions(+), 2 deletions(-)
 create mode 100644 tools/replay/btreplay.1
Makefile.tools +4 -2
index ba2db00..8b1e3de 100644
@@ -94,11 +94,13 @@ endif
 
 dist_man_MANS += tools/rfcomm.1 tools/l2ping.8 \
 			tools/hciattach.8 tools/hciconfig.8 \
-			tools/hcitool.1 tools/sdptool.1 tools/ciptool.1
+			tools/hcitool.1 tools/sdptool.1 tools/ciptool.1 \
+			tools/replay/btreplay.1
 else
 EXTRA_DIST += tools/rfcomm.1 tools/l2ping.8 \
 			tools/hciattach.8 tools/hciconfig.8 \
-			tools/hcitool.1 tools/sdptool.1 tools/ciptool.1
+			tools/hcitool.1 tools/sdptool.1 tools/ciptool.1 \
+			tools/replay/btreplay.1
 endif
 
 CLEANFILES += tools/lexer.c tools/parser.c tools/parser.h
tools/replay/btreplay.1 new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#13 lore raw

PATCH v3 6/6 replay: Add tutorial

In reply to Anton Weber

Add short tutorial to show example usage of btreplay.

---
 doc/btreplay-tutorial.txt |   60 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 doc/btreplay-tutorial.txt
doc/btreplay-tutorial.txt new file +60 -0
new file mode 100644
index 0000000..61e96b6
@@ -0,0 +1,60 @@
+BlueZ Bluetooth Replayer Tutorial
+*********************************
+
+Copyright (C) 2012  Anton Weber <[email protected]>
+
+
+Create dump
+===========
+A dump can be recorded using the -b option of btmon.
+The best way to record a suitable dump is to disable the Bluetooth controller
+before recording. That way btmon also records the initialisation sequence.
+
+# sudo btmon -b testdump
+<plug in / enable Bluetooth contoller>
+<connect Bluetooth mouse>
+<move mouse around>
+<CTRL+C>
+
+
+Replay dump
+===========
+
+First make sure the VHCI driver is loaded:
+
+# sudo modprobe hci_vhci
+# ls /dev | grep vhci
+
+Now the dump can be replayed with btreplay. When the same machine is used to
+replay the dump, it is recommended to unplug / disable the Bluetooth controller
+to avoid conflicts.
+
+The simplest way to use the Bluetooth Replayer is to run
+
+# sudo btreplay testdump
+
+Some scenarios require minimal delay during the execution to be replayed
+correctly (such as the example above).
+One solution is to use the delta timing mode that adds delays according to the
+time difference between packets in the dump file.
+
+# sudo btreplay -d delta testdump
+
+Running btreplay with a dump from another machine can cause some issues with
+the initialisation sequence. The host might send out packets in a different
+order.
+btreplay will show several packets marked as "[Unknown] ! Wrong opcode" and
+the replay process can get stuck.
+When these packets are not relevant to the actual scenario, they can be ignored
+using a config file. For example, they can be passed on to the emulator.
+To do so, set the action for these packet types to 'emulate' in a config file.
+
+Example config contents:
+
+HCI_CMD_0x03|0x0001 action=emulate
+HCI_CMD_0x03|0x0018 action=emulate
+
+
+and run btreplay with this config file.
+
+# sudo btreplay -d delta -c testconfig testdump
Signature · 1 line
1.7.9.5