2015-03-21 11:47:25 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup net_pktdump
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Generic module to dump packages received via netapi to STDOUT
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2015-03-25 03:01:34 +01:00
|
|
|
#include <inttypes.h>
|
2015-03-21 11:47:25 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-06-17 14:25:39 +02:00
|
|
|
#include <errno.h>
|
2015-03-25 03:01:34 +01:00
|
|
|
#include "byteorder.h"
|
2015-03-21 11:47:25 +01:00
|
|
|
#include "thread.h"
|
|
|
|
#include "msg.h"
|
2015-03-25 23:50:46 +01:00
|
|
|
#include "kernel.h"
|
2015-03-21 11:47:25 +01:00
|
|
|
#include "net/ng_pktdump.h"
|
2015-08-10 02:41:08 +02:00
|
|
|
#include "net/gnrc.h"
|
2015-08-10 00:26:36 +02:00
|
|
|
#include "net/ipv6/addr.h"
|
2015-08-09 23:53:40 +02:00
|
|
|
#include "net/ipv6/hdr.h"
|
2015-04-14 00:18:36 +02:00
|
|
|
#include "net/ng_sixlowpan.h"
|
2015-08-10 03:16:53 +02:00
|
|
|
#include "net/udp.h"
|
2015-03-24 02:53:06 +01:00
|
|
|
#include "od.h"
|
2015-03-21 11:47:25 +01:00
|
|
|
|
2015-03-25 23:50:46 +01:00
|
|
|
/**
|
|
|
|
* @brief PID of the pktdump thread
|
|
|
|
*/
|
|
|
|
static kernel_pid_t _pid = KERNEL_PID_UNDEF;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Stack for the pktdump thread
|
|
|
|
*/
|
|
|
|
static char _stack[NG_PKTDUMP_STACKSIZE];
|
|
|
|
|
2015-03-24 02:53:06 +01:00
|
|
|
static void _dump_snip(ng_pktsnip_t *pkt)
|
2015-03-21 11:47:25 +01:00
|
|
|
{
|
2015-03-24 02:53:06 +01:00
|
|
|
switch (pkt->type) {
|
2015-03-21 11:47:25 +01:00
|
|
|
case NG_NETTYPE_UNDEF:
|
2015-03-24 02:53:06 +01:00
|
|
|
printf("NETTYPE_UNDEF (%i)\n", pkt->type);
|
|
|
|
od_hex_dump(pkt->data, pkt->size, OD_WIDTH_DEFAULT);
|
2015-03-21 11:47:25 +01:00
|
|
|
break;
|
2015-03-24 02:53:06 +01:00
|
|
|
#ifdef MODULE_NG_NETIF
|
|
|
|
case NG_NETTYPE_NETIF:
|
|
|
|
printf("NETTYPE_NETIF (%i)\n", pkt->type);
|
2015-04-20 10:54:03 +02:00
|
|
|
ng_netif_hdr_print(pkt->data);
|
2015-03-24 02:53:06 +01:00
|
|
|
break;
|
|
|
|
#endif
|
2015-03-21 11:47:25 +01:00
|
|
|
#ifdef MODULE_NG_SIXLOWPAN
|
|
|
|
case NG_NETTYPE_SIXLOWPAN:
|
2015-04-19 16:46:32 +02:00
|
|
|
printf("NETTYPE_SIXLOWPAN (%i)\n", pkt->type);
|
2015-04-14 00:18:36 +02:00
|
|
|
ng_sixlowpan_print(pkt->data, pkt->size);
|
2015-03-21 11:47:25 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef MODULE_NG_IPV6
|
|
|
|
case NG_NETTYPE_IPV6:
|
2015-03-25 03:01:34 +01:00
|
|
|
printf("NETTYPE_IPV6 (%i)\n", pkt->type);
|
2015-08-09 23:53:40 +02:00
|
|
|
ipv6_hdr_print(pkt->data);
|
2015-03-21 11:47:25 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef MODULE_NG_ICMPV6
|
|
|
|
case NG_NETTYPE_ICMPV6:
|
2015-04-19 16:46:32 +02:00
|
|
|
printf("NETTYPE_ICMPV6 (%i)\n", pkt->type);
|
2015-03-21 11:47:25 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef MODULE_NG_TCP
|
|
|
|
case NG_NETTYPE_TCP:
|
2015-04-19 16:46:32 +02:00
|
|
|
printf("NETTYPE_TCP (%i)\n", pkt->type);
|
2015-03-21 11:47:25 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef MODULE_NG_UDP
|
|
|
|
case NG_NETTYPE_UDP:
|
2015-04-19 16:46:32 +02:00
|
|
|
printf("NETTYPE_UDP (%i)\n", pkt->type);
|
2015-08-10 03:16:53 +02:00
|
|
|
udp_hdr_print(pkt->data);
|
2015-03-21 11:47:25 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef TEST_SUITES
|
|
|
|
case NG_NETTYPE_TEST:
|
2015-04-19 16:46:32 +02:00
|
|
|
printf("NETTYPE_TEST (%i)\n", pkt->type);
|
2015-03-24 02:53:06 +01:00
|
|
|
od_hex_dump(pkt->data, pkt->size, OD_WIDTH_DEFAULT);
|
2015-03-21 11:47:25 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2015-04-19 16:46:32 +02:00
|
|
|
printf("NETTYPE_UNKNOWN (%i)\n", pkt->type);
|
2015-03-24 02:53:06 +01:00
|
|
|
od_hex_dump(pkt->data, pkt->size, OD_WIDTH_DEFAULT);
|
2015-03-21 11:47:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 16:28:34 +02:00
|
|
|
static void _dump(ng_pktsnip_t *pkt)
|
2015-03-21 11:47:25 +01:00
|
|
|
{
|
|
|
|
int snips = 0;
|
|
|
|
int size = 0;
|
2015-03-24 22:14:16 +01:00
|
|
|
ng_pktsnip_t *snip = pkt;
|
2015-03-21 11:47:25 +01:00
|
|
|
|
2015-03-24 22:14:16 +01:00
|
|
|
while (snip != NULL) {
|
2015-04-20 10:56:04 +02:00
|
|
|
printf("~~ SNIP %2i - size: %3u byte, type: ", snips,
|
|
|
|
(unsigned int)snip->size);
|
2015-03-24 02:53:06 +01:00
|
|
|
_dump_snip(snip);
|
2015-03-21 11:47:25 +01:00
|
|
|
++snips;
|
2015-03-24 22:14:16 +01:00
|
|
|
size += snip->size;
|
|
|
|
snip = snip->next;
|
2015-03-21 11:47:25 +01:00
|
|
|
}
|
2015-03-24 02:53:06 +01:00
|
|
|
|
2015-03-21 11:47:25 +01:00
|
|
|
printf("~~ PKT - %2i snips, total size: %3i byte\n", snips, size);
|
|
|
|
ng_pktbuf_release(pkt);
|
|
|
|
}
|
|
|
|
|
2015-04-09 16:28:34 +02:00
|
|
|
static void *_eventloop(void *arg)
|
2015-03-21 11:47:25 +01:00
|
|
|
{
|
|
|
|
(void)arg;
|
2015-04-14 17:09:07 +02:00
|
|
|
msg_t msg, reply;
|
2015-03-25 23:47:19 +01:00
|
|
|
msg_t msg_queue[NG_PKTDUMP_MSG_QUEUE_SIZE];
|
|
|
|
|
|
|
|
/* setup the message queue */
|
|
|
|
msg_init_queue(msg_queue, NG_PKTDUMP_MSG_QUEUE_SIZE);
|
2015-03-21 11:47:25 +01:00
|
|
|
|
2015-04-14 17:09:07 +02:00
|
|
|
reply.content.value = (uint32_t)(-ENOTSUP);
|
|
|
|
reply.type = NG_NETAPI_MSG_TYPE_ACK;
|
|
|
|
|
2015-03-21 11:47:25 +01:00
|
|
|
while (1) {
|
|
|
|
msg_receive(&msg);
|
|
|
|
|
|
|
|
switch (msg.type) {
|
|
|
|
case NG_NETAPI_MSG_TYPE_RCV:
|
|
|
|
puts("PKTDUMP: data received:");
|
|
|
|
_dump((ng_pktsnip_t *)msg.content.ptr);
|
|
|
|
break;
|
|
|
|
case NG_NETAPI_MSG_TYPE_SND:
|
|
|
|
puts("PKTDUMP: data to send:");
|
|
|
|
_dump((ng_pktsnip_t *)msg.content.ptr);
|
|
|
|
break;
|
2015-04-14 17:09:07 +02:00
|
|
|
case NG_NETAPI_MSG_TYPE_GET:
|
|
|
|
case NG_NETAPI_MSG_TYPE_SET:
|
|
|
|
msg_reply(&msg, &reply);
|
|
|
|
break;
|
2015-03-21 11:47:25 +01:00
|
|
|
default:
|
|
|
|
puts("PKTDUMP: received something unexpected");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* never reached */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-25 23:50:46 +01:00
|
|
|
kernel_pid_t ng_pktdump_getpid(void)
|
2015-03-21 11:47:25 +01:00
|
|
|
{
|
2015-03-25 23:50:46 +01:00
|
|
|
return _pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
kernel_pid_t ng_pktdump_init(void)
|
|
|
|
{
|
|
|
|
if (_pid == KERNEL_PID_UNDEF) {
|
|
|
|
_pid = thread_create(_stack, sizeof(_stack), NG_PKTDUMP_PRIO,
|
2015-04-02 23:45:34 +02:00
|
|
|
CREATE_STACKTEST, _eventloop, NULL, "pktdump");
|
2015-03-25 23:50:46 +01:00
|
|
|
}
|
|
|
|
return _pid;
|
2015-03-21 11:47:25 +01:00
|
|
|
}
|