Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
19973: sys/shell/gnrc_txtsnd: Move to separate module r=yarrick a=yarrick



Co-authored-by: Erik Ekman <eekman@google.com>
  • Loading branch information
bors[bot] and yarrick authored Oct 12, 2023
2 parents 357e406 + ea545d2 commit 715da20
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 62 deletions.
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ PSEUDOMODULES += shell_cmd_gnrc_pktbuf
PSEUDOMODULES += shell_cmd_gnrc_rpl
PSEUDOMODULES += shell_cmd_gnrc_sixlowpan_ctx
PSEUDOMODULES += shell_cmd_gnrc_sixlowpan_frag_stats
PSEUDOMODULES += shell_cmd_gnrc_txtsnd
PSEUDOMODULES += shell_cmd_gnrc_udp
PSEUDOMODULES += shell_cmd_heap
PSEUDOMODULES += shell_cmd_i2c_scan
Expand Down
3 changes: 3 additions & 0 deletions sys/shell/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ifneq (,$(filter shell_cmds_default,$(USEMODULE)))
USEMODULE += shell_cmd_gnrc_netif_lora
endif
endif
ifneq (,$(filter gnrc_txtsnd,$(USEMODULE)))
USEMODULE += shell_cmd_gnrc_txtsnd
endif
ifneq (,$(filter gnrc_netif_lorawan,$(USEMODULE)))
USEMODULE += shell_cmd_gnrc_netif_lorawan
endif
Expand Down
62 changes: 0 additions & 62 deletions sys/shell/cmds/gnrc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "net/loramac.h"
#include "net/netif.h"
#include "shell.h"
#include "container.h"

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

/* shell commands */
#ifdef MODULE_GNRC_TXTSND
static int _gnrc_netif_send(int argc, char **argv)
{
netif_t *iface;
uint8_t addr[GNRC_NETIF_L2ADDR_MAXLEN];
size_t addr_len;
gnrc_pktsnip_t *pkt, *hdr;
gnrc_netif_hdr_t *nethdr;
uint8_t flags = 0x00;

if (argc < 4) {
printf("usage: %s <if> [<L2 addr>|bcast] <data>\n", argv[0]);
return 1;
}

iface = netif_get_by_name(argv[1]);
if (!iface) {
printf("error: invalid interface given\n");
return 1;
}

/* parse address */
addr_len = gnrc_netif_addr_from_str(argv[2], addr);

if (addr_len == 0) {
if (strcmp(argv[2], "bcast") == 0) {
flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST;
}
else {
printf("error: invalid address given\n");
return 1;
}
}

/* put packet together */
pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF);
if (pkt == NULL) {
printf("error: packet buffer full\n");
return 1;
}
hdr = gnrc_netif_hdr_build(NULL, 0, addr, addr_len);
if (hdr == NULL) {
printf("error: packet buffer full\n");
gnrc_pktbuf_release(pkt);
return 1;
}
pkt = gnrc_pkt_prepend(pkt, hdr);
nethdr = (gnrc_netif_hdr_t *)hdr->data;
nethdr->flags = flags;
/* and send it */
if (gnrc_netif_send(container_of(iface, gnrc_netif_t, netif), pkt) < 1) {
printf("error: unable to send\n");
gnrc_pktbuf_release(pkt);
return 1;
}

return 0;
}

SHELL_COMMAND(txtsnd, "Sends a custom string as is over the link layer", _gnrc_netif_send);
#endif

/* TODO: updated tests/net/gnrc_dhcpv6_client to no longer abuse this shell command
* and add static qualifier */
Expand Down
89 changes: 89 additions & 0 deletions sys/shell/cmds/gnrc_txtsnd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2017 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 sys_shell_commands
* @{
*
* @file
* @brief Shell command for sending raw text on network
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
*/

#include <stdio.h>
#include <string.h>

#include "net/gnrc.h"
#include "net/gnrc.h"
#include "net/gnrc/netif/hdr.h"
#include "net/ipv6/addr.h"
#include "shell.h"
#include "container.h"

static int _gnrc_netif_send(int argc, char **argv)
{
netif_t *iface;
uint8_t addr[GNRC_NETIF_L2ADDR_MAXLEN];
size_t addr_len;
gnrc_pktsnip_t *pkt, *hdr;
gnrc_netif_hdr_t *nethdr;
uint8_t flags = 0x00;

if (argc < 4) {
printf("usage: %s <if> [<L2 addr>|bcast] <data>\n", argv[0]);
return 1;
}

iface = netif_get_by_name(argv[1]);
if (!iface) {
printf("error: invalid interface given\n");
return 1;
}

/* parse address */
addr_len = gnrc_netif_addr_from_str(argv[2], addr);

if (addr_len == 0) {
if (strcmp(argv[2], "bcast") == 0) {
flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST;
}
else {
printf("error: invalid address given\n");
return 1;
}
}

/* put packet together */
pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF);
if (pkt == NULL) {
printf("error: packet buffer full\n");
return 1;
}
hdr = gnrc_netif_hdr_build(NULL, 0, addr, addr_len);
if (hdr == NULL) {
printf("error: packet buffer full\n");
gnrc_pktbuf_release(pkt);
return 1;
}
pkt = gnrc_pkt_prepend(pkt, hdr);
nethdr = (gnrc_netif_hdr_t *)hdr->data;
nethdr->flags = flags;
/* and send it */
if (gnrc_netif_send(container_of(iface, gnrc_netif_t, netif), pkt) < 1) {
printf("error: unable to send\n");
gnrc_pktbuf_release(pkt);
return 1;
}

return 0;
}

SHELL_COMMAND(txtsnd, "Sends a custom string as is over the link layer", _gnrc_netif_send);

0 comments on commit 715da20

Please sign in to comment.