Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

sniffer: use fmt instead of printf #36

Merged
merged 3 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sniffer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BOARD ?= native
RIOTBASE ?= $(CURDIR)/../../RIOT

# Define modules that are used
USEMODULE += fmt
USEMODULE += gnrc
USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif
Expand Down
21 changes: 14 additions & 7 deletions sniffer/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Freie Universität Berlin
* Copyright (C) 2015-18 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -15,12 +15,14 @@
* @brief Sniffer application for RIOT
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Martine Lenders <m.lenders@fu-berlin.de>
*
* @}
*/

#include <stdio.h>

#include "fmt.h"
#include "thread.h"
#include "xtimer.h"
#include "shell.h"
Expand All @@ -45,7 +47,7 @@
/**
* @brief Stack for the raw dump thread
*/
static char rawdmp_stack[THREAD_STACKSIZE_MAIN];
static char rawdmp_stack[THREAD_STACKSIZE_SMALL];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change may need verification on some more platforms though (AVR, msp430, mips)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z1 is an msp430 platform, so this I already tested. I'm not sure XBee works with the sniffer, but we can maybe try with an OpenLabs for the AVR-based board. Same goes probably for MIPS, though SPI is just in the works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The z1 would even be happy with THREAD_STACKSIZE_TINY btw ;-)


/**
* @brief Make a raw dump of the given packet contents
Expand All @@ -59,16 +61,21 @@ void dump_pkt(gnrc_pktsnip_t *pkt)
pkt = gnrc_pktbuf_remove_snip(pkt, pkt->next);
uint64_t now_us = xtimer_usec_from_ticks64(xtimer_now64());

printf("rftest-rx --- len 0x%02x lqi 0x%02x rx_time 0x%08" PRIx32 "%08" PRIx32 "\n\n",
gnrc_pkt_len(pkt), lqi, (uint32_t)(now_us >> 32), (uint32_t)(now_us & 0xffffffff));

print_str("rftest-rx --- len ");
print_u32_hex((uint32_t)gnrc_pkt_len(pkt));
print_str(" lqi ");
print_byte_hex(lqi);
print_str(" rx_time ");
print_u64_hex(now_us);
print_str("\n");
while (snip) {
for (size_t i = 0; i < snip->size; i++) {
printf("0x%02x ", ((uint8_t *)(snip->data))[i]);
print_byte_hex(((uint8_t *)(snip->data))[i]);
print_str(" ");
}
snip = snip->next;
}
puts("\n");
print_str("\n\n");

gnrc_pktbuf_release(pkt);
}
Expand Down
6 changes: 3 additions & 3 deletions sniffer/tools/sniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def generate_pcap(port, out):
while True:
line = port.readline().rstrip()

pkt_header = re.match(r">? *rftest-rx --- len 0x(\w\w).*",
pkt_header = re.match(r">? *rftest-rx --- len (\w+).*",
line.decode(errors="ignore"))
if pkt_header:
now = time()
Expand All @@ -98,10 +98,10 @@ def generate_pcap(port, out):
sys.stderr.write("RX: %i\r" % count)
continue

pkt_data = re.match(r"(0x\w\w )+", line.decode(errors="ignore"))
pkt_data = re.match(r"(\w\w )+", line.decode(errors="ignore"))
if pkt_data:
for part in line.decode(errors="ignore").split(' '):
byte = re.match(r"0x(\w\w)", part)
byte = re.match(r"(\w\w)", part)
if byte:
out.write(pack('<B', int(byte.group(1), 16)))
out.flush()
Expand Down