Skip to content

Commit ea545d2

Browse files
committed
sys/shell/gnrc_txtsnd: Move to separate module
1 parent 7bc783e commit ea545d2

4 files changed

Lines changed: 93 additions & 62 deletions

File tree

makefiles/pseudomodules.inc.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ PSEUDOMODULES += shell_cmd_gnrc_pktbuf
479479
PSEUDOMODULES += shell_cmd_gnrc_rpl
480480
PSEUDOMODULES += shell_cmd_gnrc_sixlowpan_ctx
481481
PSEUDOMODULES += shell_cmd_gnrc_sixlowpan_frag_stats
482+
PSEUDOMODULES += shell_cmd_gnrc_txtsnd
482483
PSEUDOMODULES += shell_cmd_gnrc_udp
483484
PSEUDOMODULES += shell_cmd_heap
484485
PSEUDOMODULES += shell_cmd_i2c_scan

sys/shell/Makefile.dep

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ ifneq (,$(filter shell_cmds_default,$(USEMODULE)))
5151
USEMODULE += shell_cmd_gnrc_netif_lora
5252
endif
5353
endif
54+
ifneq (,$(filter gnrc_txtsnd,$(USEMODULE)))
55+
USEMODULE += shell_cmd_gnrc_txtsnd
56+
endif
5457
ifneq (,$(filter gnrc_netif_lorawan,$(USEMODULE)))
5558
USEMODULE += shell_cmd_gnrc_netif_lorawan
5659
endif

sys/shell/cmds/gnrc_netif.c

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "net/loramac.h"
3434
#include "net/netif.h"
3535
#include "shell.h"
36-
#include "container.h"
3736

3837
#ifdef MODULE_NETSTATS
3938
#include "net/netstats.h"
@@ -1793,67 +1792,6 @@ static int _netif_del(netif_t *iface, char *addr_str)
17931792
}
17941793

17951794
/* shell commands */
1796-
#ifdef MODULE_GNRC_TXTSND
1797-
static int _gnrc_netif_send(int argc, char **argv)
1798-
{
1799-
netif_t *iface;
1800-
uint8_t addr[GNRC_NETIF_L2ADDR_MAXLEN];
1801-
size_t addr_len;
1802-
gnrc_pktsnip_t *pkt, *hdr;
1803-
gnrc_netif_hdr_t *nethdr;
1804-
uint8_t flags = 0x00;
1805-
1806-
if (argc < 4) {
1807-
printf("usage: %s <if> [<L2 addr>|bcast] <data>\n", argv[0]);
1808-
return 1;
1809-
}
1810-
1811-
iface = netif_get_by_name(argv[1]);
1812-
if (!iface) {
1813-
printf("error: invalid interface given\n");
1814-
return 1;
1815-
}
1816-
1817-
/* parse address */
1818-
addr_len = gnrc_netif_addr_from_str(argv[2], addr);
1819-
1820-
if (addr_len == 0) {
1821-
if (strcmp(argv[2], "bcast") == 0) {
1822-
flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST;
1823-
}
1824-
else {
1825-
printf("error: invalid address given\n");
1826-
return 1;
1827-
}
1828-
}
1829-
1830-
/* put packet together */
1831-
pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF);
1832-
if (pkt == NULL) {
1833-
printf("error: packet buffer full\n");
1834-
return 1;
1835-
}
1836-
hdr = gnrc_netif_hdr_build(NULL, 0, addr, addr_len);
1837-
if (hdr == NULL) {
1838-
printf("error: packet buffer full\n");
1839-
gnrc_pktbuf_release(pkt);
1840-
return 1;
1841-
}
1842-
pkt = gnrc_pkt_prepend(pkt, hdr);
1843-
nethdr = (gnrc_netif_hdr_t *)hdr->data;
1844-
nethdr->flags = flags;
1845-
/* and send it */
1846-
if (gnrc_netif_send(container_of(iface, gnrc_netif_t, netif), pkt) < 1) {
1847-
printf("error: unable to send\n");
1848-
gnrc_pktbuf_release(pkt);
1849-
return 1;
1850-
}
1851-
1852-
return 0;
1853-
}
1854-
1855-
SHELL_COMMAND(txtsnd, "Sends a custom string as is over the link layer", _gnrc_netif_send);
1856-
#endif
18571795

18581796
/* TODO: updated tests/net/gnrc_dhcpv6_client to no longer abuse this shell command
18591797
* and add static qualifier */

sys/shell/cmds/gnrc_txtsnd.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (C) 2017 Freie Universität Berlin
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup sys_shell_commands
11+
* @{
12+
*
13+
* @file
14+
* @brief Shell command for sending raw text on network
15+
*
16+
* @author Martine Lenders <m.lenders@fu-berlin.de>
17+
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
18+
* @author Oliver Hahm <oliver.hahm@inria.fr>
19+
*/
20+
21+
#include <stdio.h>
22+
#include <string.h>
23+
24+
#include "net/gnrc.h"
25+
#include "net/gnrc.h"
26+
#include "net/gnrc/netif/hdr.h"
27+
#include "net/ipv6/addr.h"
28+
#include "shell.h"
29+
#include "container.h"
30+
31+
static int _gnrc_netif_send(int argc, char **argv)
32+
{
33+
netif_t *iface;
34+
uint8_t addr[GNRC_NETIF_L2ADDR_MAXLEN];
35+
size_t addr_len;
36+
gnrc_pktsnip_t *pkt, *hdr;
37+
gnrc_netif_hdr_t *nethdr;
38+
uint8_t flags = 0x00;
39+
40+
if (argc < 4) {
41+
printf("usage: %s <if> [<L2 addr>|bcast] <data>\n", argv[0]);
42+
return 1;
43+
}
44+
45+
iface = netif_get_by_name(argv[1]);
46+
if (!iface) {
47+
printf("error: invalid interface given\n");
48+
return 1;
49+
}
50+
51+
/* parse address */
52+
addr_len = gnrc_netif_addr_from_str(argv[2], addr);
53+
54+
if (addr_len == 0) {
55+
if (strcmp(argv[2], "bcast") == 0) {
56+
flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST;
57+
}
58+
else {
59+
printf("error: invalid address given\n");
60+
return 1;
61+
}
62+
}
63+
64+
/* put packet together */
65+
pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF);
66+
if (pkt == NULL) {
67+
printf("error: packet buffer full\n");
68+
return 1;
69+
}
70+
hdr = gnrc_netif_hdr_build(NULL, 0, addr, addr_len);
71+
if (hdr == NULL) {
72+
printf("error: packet buffer full\n");
73+
gnrc_pktbuf_release(pkt);
74+
return 1;
75+
}
76+
pkt = gnrc_pkt_prepend(pkt, hdr);
77+
nethdr = (gnrc_netif_hdr_t *)hdr->data;
78+
nethdr->flags = flags;
79+
/* and send it */
80+
if (gnrc_netif_send(container_of(iface, gnrc_netif_t, netif), pkt) < 1) {
81+
printf("error: unable to send\n");
82+
gnrc_pktbuf_release(pkt);
83+
return 1;
84+
}
85+
86+
return 0;
87+
}
88+
89+
SHELL_COMMAND(txtsnd, "Sends a custom string as is over the link layer", _gnrc_netif_send);

0 commit comments

Comments
 (0)