summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2010-11-21 12:09:49 +0100
committerPatrick McHardy <kaber@trash.net>2010-11-21 12:09:49 +0100
commitfab91200de0d946fb4927ac44c50885f74f803f6 (patch)
tree1ad292c3002de7d0121bc54e7cc00719d85095da
parent1a280c1a11e34c4290921670a8dac52275821200 (diff)
dectmon: add raw packet dumping facility
Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r--include/dectmon.h10
-rw-r--r--src/main.c22
2 files changed, 31 insertions, 1 deletions
diff --git a/include/dectmon.h b/include/dectmon.h
index 5a4684c..11999cc 100644
--- a/include/dectmon.h
+++ b/include/dectmon.h
@@ -149,4 +149,14 @@ extern void dect_audio_close(struct dect_audio_handle *ah);
extern void dect_audio_queue(struct dect_audio_handle *ah, unsigned int queue,
struct dect_msg_buf *mb);
+/* Raw dump */
+
+struct dect_raw_frame_hdr {
+ uint8_t len;
+ uint8_t slot;
+ uint8_t frame;
+ uint8_t pad;
+ uint32_t mfn;
+};
+
#endif /* _DECTMON_H */
diff --git a/src/main.c b/src/main.c
index 5da488b..a7ac8bc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,7 @@ static unsigned int locked;
static bool scan;
static FILE *logfile;
+static FILE *dumpfile;
void dectmon_log(const char *fmt, ...)
{
@@ -106,6 +107,17 @@ static struct dect_llme_ops_ llme_ops = {
static void dect_raw_rcv(struct dect_handle *dh, struct dect_fd *dfd,
struct dect_msg_buf *mb)
{
+ struct dect_raw_frame_hdr f;
+
+ if (dumpfile != NULL) {
+ f.slot = mb->slot;
+ f.frame = mb->frame;
+ f.mfn = mb->mfn;
+ f.len = mb->len;
+
+ fwrite(&f, sizeof(f), 1, dumpfile);
+ fwrite(mb->data, mb->len, 1, dumpfile);
+ }
dect_mac_rcv(dh, mb);
}
@@ -132,7 +144,7 @@ static void dect_debug(enum dect_debug_subsys subsys, const char *fmt,
}
}
-#define OPTSTRING "c:sm:d:n:p:h"
+#define OPTSTRING "c:sm:d:n:p:d:h"
enum {
OPT_CLUSTER = 'c',
@@ -142,6 +154,7 @@ enum {
OPT_DUMP_NWK = 'n',
OPT_AUTH_PIN = 'p',
OPT_LOGFILE = 'l',
+ OPT_DUMPFILE = 'w',
OPT_HELP = 'h',
};
@@ -153,6 +166,7 @@ static const struct option dectmon_opts[] = {
{ .name = "dump-nwk", .has_arg = true, .flag = 0, .val = OPT_DUMP_NWK, },
{ .name = "auth-pin", .has_arg = true, .flag = 0, .val = OPT_AUTH_PIN, },
{ .name = "logfile", .has_arg = true, .flag = 0, .val = OPT_LOGFILE, },
+ { .name = "dumpfile", .has_arg = true, .flag = 0, .val = OPT_DUMPFILE, },
{ .name = "help", .has_arg = false, .flag = 0, .val = OPT_HELP, },
{ },
};
@@ -175,6 +189,7 @@ static void dectmon_help(const char *progname)
" -n/--dump-nwk=yes/no Dump NWK layer messages (default: yes)\n"
" -p/--auth-pin=PIN Authentication PIN for Key Allocation\n"
" -l/--logfile=NAME Log output to file\n"
+ " -d/--dumpfile=NAME Dump raw frames to file\n"
" -h/--help Show this help text\n"
"\n",
progname);
@@ -257,6 +272,11 @@ int main(int argc, char **argv)
if (logfile == NULL)
pexit("fopen");
break;
+ case OPT_DUMPFILE:
+ dumpfile = fopen(optarg, "w");
+ if (dumpfile == NULL)
+ pexit("fopen");
+ break;
case OPT_HELP:
dectmon_help(argv[0]);
exit(0);