From 12d4283040fcd4d9bf26a572a6c96ed3d0534066 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Sun, 9 Aug 2015 21:09:29 +0200 Subject: [PATCH] sniffer: remove old application --- ng_sniffer/Makefile | 20 --- ng_sniffer/main.c | 127 ------------------ sniffer/Makefile | 21 +-- {ng_sniffer => sniffer}/README.md | 4 +- sniffer/main.c | 210 +++++++++++------------------- 5 files changed, 87 insertions(+), 295 deletions(-) delete mode 100644 ng_sniffer/Makefile delete mode 100644 ng_sniffer/main.c rename {ng_sniffer => sniffer}/README.md (53%) diff --git a/ng_sniffer/Makefile b/ng_sniffer/Makefile deleted file mode 100644 index d6dff7c..0000000 --- a/ng_sniffer/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# Set the name of your application: -APPLICATION = ng_sniffer - -# If no BOARD is found in the environment, use this default: -BOARD ?= native - -# This has to be the absolute path to the RIOT base directory: -RIOTBASE ?= $(CURDIR)/../../RIOT - -# Define modules that are used -USEMODULE += ng_netif_default -USEMODULE += auto_init_ng_netif -USEMODULE += shell -USEMODULE += shell_commands -USEMODULE += ps - -# Change this to 0 show compiler invocation lines by default: -QUIET ?= 1 - -include $(RIOTBASE)/Makefile.include diff --git a/ng_sniffer/main.c b/ng_sniffer/main.c deleted file mode 100644 index 339a750..0000000 --- a/ng_sniffer/main.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2015 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 - * directory for more details. - */ - -/** - * @defgroup app_sniffer - * @brief Sniffer application based on the new network stack - * @{ - * - * @file - * @brief Sniffer application for RIOT - * - * @author Hauke Petersen - * - * @} - */ - -#include - -#include "thread.h" -#include "hwtimer.h" -#include "shell.h" -#include "shell_commands.h" -#ifdef MODULE_NEWLIB -# include "uart_stdio.h" -#else -# include "posix_io.h" -# include "board_uart0.h" -#endif -#include "net/ng_netbase.h" - -/** - * @brief Buffer size used by the shell - */ -#define SHELL_BUFSIZE (64U) - -/** - * @brief Priority of the RAW dump thread - */ -#define RAWDUMP_PRIO (THREAD_PRIORITY_MAIN - 1) - -/** - * @brief Stack for the raw dump thread - */ -static char rawdmp_stack[THREAD_STACKSIZE_MAIN]; - -/** - * @brief Make a raw dump of the given packet contents - */ -void dump_pkt(ng_pktsnip_t *pkt) -{ - ng_pktsnip_t *snip = pkt; - - printf("rftest-rx --- len 0x%02x lqi 0x%02x rx_time 0x%08lx\n\n", - ng_pkt_len(pkt), 0, hwtimer_now()); - - while (snip) { - for (size_t i = 0; i < snip->size; i++) { - printf("0x%02x ", ((uint8_t *)(snip->data))[i]); - } - snip = snip->next; - } - puts("\n"); - - ng_pktbuf_release(pkt); -} - -/** - * @brief Event loop of the RAW dump thread - * - * @param[in] arg unused parameter - */ -void *rawdump(void *arg) -{ - (void)arg; - msg_t msg; - - while (1) { - msg_receive(&msg); - - switch (msg.type) { - case NG_NETAPI_MSG_TYPE_RCV: - dump_pkt((ng_pktsnip_t *)msg.content.ptr); - break; - default: - /* do nothing */ - break; - } - } - - /* never reached */ - return NULL; -} - -/** - * @brief Maybe you are a golfer?! - */ -int main(void) -{ - shell_t shell; - ng_netreg_entry_t dump; - - puts("RIOT sniffer application"); - - /* start and register rawdump thread */ - puts("Run the rawdump thread and register it"); - dump.pid = thread_create(rawdmp_stack, sizeof(rawdmp_stack), RAWDUMP_PRIO, - CREATE_STACKTEST, rawdump, NULL, "rawdump"); - dump.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; - ng_netreg_register(NG_NETTYPE_UNDEF, &dump); - - /* start the shell */ - puts("All ok, starting the shell now"); -#ifndef MODULE_NEWLIB - (void) posix_open(uart0_handler_pid, 0); - shell_init(&shell, NULL, SHELL_BUFSIZE, uart0_readc, uart0_putc); -#else - shell_init(&shell, NULL, SHELL_BUFSIZE, getchar, putchar); -#endif - shell_run(&shell); - - return 0; -} diff --git a/sniffer/Makefile b/sniffer/Makefile index 350a753..eb04aa6 100644 --- a/sniffer/Makefile +++ b/sniffer/Makefile @@ -7,23 +7,14 @@ BOARD ?= native # This has to be the absolute path to the RIOT base directory: RIOTBASE ?= $(CURDIR)/../../RIOT -# Change this to 0 show compiler invocation lines by default: -QUIET ?= 1 - -# blacklist all boards without radio support -BOARD_BLACKLIST := arduino-due arduino-mega2560 mbed_lpc1768 msb-430 pttu \ - udoo qemu-i386 stm32f0discovery stm32f3discovery \ - stm32f4discovery pca10000 pca10005 msbiot samr21-xpro \ - yunjia-nrf51822 - -# Modules to include: - +# Define modules that are used +USEMODULE += ng_netif_default +USEMODULE += auto_init_ng_netif USEMODULE += shell USEMODULE += shell_commands -USEMODULE += uart0 USEMODULE += ps -USEMODULE += vtimer -USEMODULE += auto_init -USEMODULE += defaulttransceiver + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 include $(RIOTBASE)/Makefile.include diff --git a/ng_sniffer/README.md b/sniffer/README.md similarity index 53% rename from ng_sniffer/README.md rename to sniffer/README.md index db45fe4..6cd9794 100644 --- a/ng_sniffer/README.md +++ b/sniffer/README.md @@ -1,7 +1,7 @@ About ===== -This application is build to run together with the script `RIOTBASE/dist/tools/ng_sniffer/ng_sniffer.py` as sniffer for (wireless) data traffic. This application works with any board with any network device that supports the gnrc network stack (or precisely the gnrc parts up to the link-layer). Further the network device (and it's driver) needs to support promiscuous and raw mode for usable output. Finally the board needs to include auto-initialization code for the targeted network device. +This application is build to run together with the script `RIOTBASE/dist/tools/sniffer/sniffer.py` as sniffer for (wireless) data traffic. This application works with any board with any network device that supports the gnrc network stack (or precisely the gnrc parts up to the link-layer). Further the network device (and it's driver) needs to support promiscuous and raw mode for usable output. Finally the board needs to include auto-initialization code for the targeted network device. Usage @@ -9,4 +9,4 @@ Usage Compile and flash this application to the board of your choice. You can check if everything on the RIOT side works by connecting to the board via UART and by checking with `ifconfig` if a network device is available. Further you can check with `ifconfig 4 promisc` if promiscuous mode is supported and with `ifconfig 4 raw` if raw mode is supported by the driver/network device. -For further information on setting up the host part, see `RIOTBASE/dist/tools/ng_snifffer/README.md`. +For further information on setting up the host part, see `RIOTBASE/dist/tools/sniffer/README.md`. diff --git a/sniffer/main.c b/sniffer/main.c index c0eb646..339a750 100644 --- a/sniffer/main.c +++ b/sniffer/main.c @@ -1,7 +1,5 @@ /* - * Copyright (c) 2010, Mariano Alvira and other contributors to - * the MC1322x project (http://mc1322x.devl.org) - * Copyright (C) 2014 Oliver Hahm + * Copyright (C) 2015 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 @@ -9,170 +7,120 @@ */ /** - * @ingroup examples + * @defgroup app_sniffer + * @brief Sniffer application based on the new network stack * @{ * - * @file main.c + * @file + * @brief Sniffer application for RIOT * - * @brief Sniffer application for MSB-A2 and Wireshark - * - * @author Oliver Hahm - * @author Mariano Alvira + * @author Hauke Petersen * * @} */ #include -#include #include "thread.h" -#include "posix_io.h" +#include "hwtimer.h" #include "shell.h" #include "shell_commands.h" -#include "board_uart0.h" -#include "hwtimer.h" -#include "transceiver.h" -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X -#include "ieee802154_frame.h" +#ifdef MODULE_NEWLIB +# include "uart_stdio.h" +#else +# include "posix_io.h" +# include "board_uart0.h" #endif +#include "net/ng_netbase.h" -#define RCV_BUFFER_SIZE (64) -#define RADIO_STACK_SIZE (KERNEL_CONF_STACKSIZE_MAIN) -#define PER_ROW (16) - -char radio_stack_buffer[RADIO_STACK_SIZE]; -msg_t msg_q[RCV_BUFFER_SIZE]; -transceiver_command_t tcmd; +/** + * @brief Buffer size used by the shell + */ +#define SHELL_BUFSIZE (64U) -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X -void print_packet(ieee802154_packet_t *p) -#else -void print_packet(radio_packet_t *p) -#endif -{ - volatile uint8_t i, j, k; +/** + * @brief Priority of the RAW dump thread + */ +#define RAWDUMP_PRIO (THREAD_PRIORITY_MAIN - 1) - if (p) { - printf("len 0x%02x lqi 0x%02x rx_time 0x%08lx", p->length, p->lqi, hwtimer_now()); +/** + * @brief Stack for the raw dump thread + */ +static char rawdmp_stack[THREAD_STACKSIZE_MAIN]; - for (j = 0, k = 0; j <= ((p->length) / PER_ROW); j++) { - printf("\n\r"); +/** + * @brief Make a raw dump of the given packet contents + */ +void dump_pkt(ng_pktsnip_t *pkt) +{ + ng_pktsnip_t *snip = pkt; - for (i = 0; i < PER_ROW; i++, k++) { - if (k >= p->length) { - printf("\n\r"); - return; - } + printf("rftest-rx --- len 0x%02x lqi 0x%02x rx_time 0x%08lx\n\n", + ng_pkt_len(pkt), 0, hwtimer_now()); -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - printf("%02x ", p->frame.payload[j * PER_ROW + i]); -#else - printf("%02x ", p->data[j * PER_ROW + i]); -#endif - } + while (snip) { + for (size_t i = 0; i < snip->size; i++) { + printf("0x%02x ", ((uint8_t *)(snip->data))[i]); } + snip = snip->next; } + puts("\n"); - printf("\n\r"); - return; + ng_pktbuf_release(pkt); } -void *radio(void *unused) +/** + * @brief Event loop of the RAW dump thread + * + * @param[in] arg unused parameter + */ +void *rawdump(void *arg) { - (void) unused; - - msg_t m; -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - ieee802154_packet_t *p; -#else - radio_packet_t *p; -#endif - - msg_init_queue(msg_q, RCV_BUFFER_SIZE); + (void)arg; + msg_t msg; while (1) { - msg_receive(&m); - - if (m.type == PKT_PENDING) { -#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X - p = (ieee802154_packet_t *) m.content.ptr; -#else - p = (radio_packet_t *) m.content.ptr; -#endif - printf("rftest-rx --- "); - print_packet(p); - p->processing--; - } - else if (m.type == ENOBUFFER) { - puts("Transceiver buffer full"); - } - else { - puts("Unknown packet received"); + msg_receive(&msg); + + switch (msg.type) { + case NG_NETAPI_MSG_TYPE_RCV: + dump_pkt((ng_pktsnip_t *)msg.content.ptr); + break; + default: + /* do nothing */ + break; } } + /* never reached */ return NULL; } -void init_transceiver(void) -{ - kernel_pid_t radio_pid = thread_create( - radio_stack_buffer, - sizeof(radio_stack_buffer), - PRIORITY_MAIN - 2, - CREATE_STACKTEST, - radio, - NULL, - "radio"); - - uint16_t transceivers = TRANSCEIVER_DEFAULT; - - transceiver_init(transceivers); - transceiver_start(); - transceiver_register(transceivers, radio_pid); - - msg_t mesg; - mesg.type = SET_CHANNEL; - mesg.content.ptr = (char *) &tcmd; - - uint16_t c = 10; - - tcmd.transceivers = TRANSCEIVER_DEFAULT; - tcmd.data = &c; - printf("Set transceiver to channel %u\n", c); - msg_send(&mesg, transceiver_pid); - - mesg.type = SET_MONITOR; - mesg.content.ptr = (char *) &tcmd; - - uint16_t v = 1; - - tcmd.data = &v; - printf("Set transceiver into monitor mode\n"); - msg_send(&mesg, transceiver_pid); -} - -static int shell_readc(void) -{ - char c = 0; - posix_read(uart0_handler_pid, &c, 1); - return c; -} - -static void shell_putchar(int c) -{ - putchar(c); -} - +/** + * @brief Maybe you are a golfer?! + */ int main(void) { shell_t shell; - posix_open(uart0_handler_pid, 0); - init_transceiver(); - - puts("Welcome to RIOT!"); - - shell_init(&shell, NULL, UART0_BUFSIZE, shell_readc, shell_putchar); + ng_netreg_entry_t dump; + + puts("RIOT sniffer application"); + + /* start and register rawdump thread */ + puts("Run the rawdump thread and register it"); + dump.pid = thread_create(rawdmp_stack, sizeof(rawdmp_stack), RAWDUMP_PRIO, + CREATE_STACKTEST, rawdump, NULL, "rawdump"); + dump.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; + ng_netreg_register(NG_NETTYPE_UNDEF, &dump); + + /* start the shell */ + puts("All ok, starting the shell now"); +#ifndef MODULE_NEWLIB + (void) posix_open(uart0_handler_pid, 0); + shell_init(&shell, NULL, SHELL_BUFSIZE, uart0_readc, uart0_putc); +#else + shell_init(&shell, NULL, SHELL_BUFSIZE, getchar, putchar); +#endif shell_run(&shell); return 0;