From f3bdf7232d6cc8916d6e3d6c52cccf47ff7be7b0 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Tue, 14 Jul 2020 12:09:43 +0200 Subject: [PATCH 1/3] netopt: add NETOPT_PDU_SIZE --- sys/include/net/netopt.h | 16 ++++++++++++++++ sys/net/crosslayer/netopt/netopt.c | 1 + 2 files changed, 17 insertions(+) diff --git a/sys/include/net/netopt.h b/sys/include/net/netopt.h index b3644029d3..3103f4b66a 100644 --- a/sys/include/net/netopt.h +++ b/sys/include/net/netopt.h @@ -195,6 +195,22 @@ typedef enum { * @brief (uint16_t) maximum protocol data unit */ NETOPT_MAX_PDU_SIZE, + /** + * @brief (uint16_t) protocol data unit size + * + * When set, fixes the number of bytes to be received. This is required for + * MAC layers with implicit header mode (no packet length information in + * PDDU) and predictable packet length (e.g LoRaWAN beacons). The device + * driver implementation should attempt to read exactly the expected number + * of bytes (possibly filling it up with garbage data if the payload is + * smaller). + * + * When get, returns the number of expected bytes for the next reception. + * + * In some MAC layers it will only be effective if used in conjunction with + * @ref NETOPT_FIXED_HEADER + */ + NETOPT_PDU_SIZE, /** * @brief (@ref netopt_enable_t) frame preloading * diff --git a/sys/net/crosslayer/netopt/netopt.c b/sys/net/crosslayer/netopt/netopt.c index d2ef4e9a9c..bc737912e1 100644 --- a/sys/net/crosslayer/netopt/netopt.c +++ b/sys/net/crosslayer/netopt/netopt.c @@ -41,6 +41,7 @@ static const char *_netopt_strmap[] = { [NETOPT_IPV6_FORWARDING] = "NETOPT_IPV6_FORWARDING", [NETOPT_IPV6_SND_RTR_ADV] = "NETOPT_IPV6_SND_RTR_ADV", [NETOPT_TX_POWER] = "NETOPT_TX_POWER", + [NETOPT_PDU_SIZE] = "NETOPT_PDU_SIZE", [NETOPT_MAX_PDU_SIZE] = "NETOPT_MAX_PDU_SIZE", [NETOPT_PRELOADING] = "NETOPT_PRELOADING", [NETOPT_PROMISCUOUSMODE] = "NETOPT_PROMISCUOUSMODE", From 84eb2dc30ca20686e392847907e031db4c346d50 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Tue, 14 Jul 2020 12:11:23 +0200 Subject: [PATCH 2/3] sx127x: implement NETOPT_PDU_SIZE --- drivers/sx127x/sx127x_netdev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/sx127x/sx127x_netdev.c b/drivers/sx127x/sx127x_netdev.c index a4489440dd..1b428fcd59 100644 --- a/drivers/sx127x/sx127x_netdev.c +++ b/drivers/sx127x/sx127x_netdev.c @@ -455,6 +455,11 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len) sx127x_set_fixed_header_len_mode(dev, *((const netopt_enable_t*) val) ? true : false); return sizeof(netopt_enable_t); + case NETOPT_PDU_SIZE: + assert(len <= sizeof(uint16_t)); + sx127x_set_payload_length(dev, *((const uint16_t*) val)); + return sizeof(uint16_t); + case NETOPT_PREAMBLE_LENGTH: assert(len <= sizeof(uint16_t)); sx127x_set_preamble_length(dev, *((const uint16_t*) val)); From 5affd72f7134ccee8b0428f7323b7f93a9deddee Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Tue, 14 Jul 2020 12:39:16 +0200 Subject: [PATCH 3/3] tests/driver_sx127x: add packet commands --- tests/driver_sx127x/main.c | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/driver_sx127x/main.c b/tests/driver_sx127x/main.c index 651e8aafec..1b2b9129ba 100644 --- a/tests/driver_sx127x/main.c +++ b/tests/driver_sx127x/main.c @@ -379,8 +379,65 @@ int reset_cmd(int argc, char **argv) return 0; } +static void _set_opt(netdev_t *netdev, netopt_t opt, bool val, char* str_help) +{ + netopt_enable_t en = val ? NETOPT_ENABLE : NETOPT_DISABLE; + netdev->driver->set(netdev, opt, &en, sizeof(en)); + printf("Successfully "); + if (val) { + printf("enabled "); + } + else { + printf("disabled "); + } + printf("%s\n", str_help); +} + +int crc_cmd(int argc, char **argv) +{ + netdev_t *netdev = (netdev_t *)&sx127x; + if (argc < 3 || strcmp(argv[1], "set") != 0) { + printf("usage: %s set <1|0>\n", argv[0]); + return 1; + } + + int tmp = atoi(argv[2]); + _set_opt(netdev, NETOPT_INTEGRITY_CHECK, tmp, "CRC check"); + return 0; +} + +int implicit_cmd(int argc, char **argv) +{ + netdev_t *netdev = (netdev_t *)&sx127x; + if (argc < 3 || strcmp(argv[1], "set") != 0) { + printf("usage: %s set <1|0>\n", argv[0]); + return 1; + } + + int tmp = atoi(argv[2]); + _set_opt(netdev, NETOPT_FIXED_HEADER, tmp, "implicit header"); + return 0; +} + +int payload_cmd(int argc, char **argv) +{ + netdev_t *netdev = (netdev_t *)&sx127x; + if (argc < 3 || strcmp(argv[1], "set") != 0) { + printf("usage: %s set \n", argv[0]); + return 1; + } + + uint16_t tmp = atoi(argv[2]); + netdev->driver->set(netdev, NETOPT_PDU_SIZE, &tmp, sizeof(tmp)); + printf("Successfully set payload to %i\n", tmp); + return 0; +} + static const shell_command_t shell_commands[] = { { "setup", "Initialize LoRa modulation settings", lora_setup_cmd }, + { "implicit", "Enable implicit header", implicit_cmd }, + { "crc", "Enable CRC", crc_cmd }, + { "payload", "Set payload length (implicit header)", payload_cmd }, { "random", "Get random number from sx127x", random_cmd }, { "syncword", "Get/Set the syncword", syncword_cmd }, { "rx_timeout", "Set the RX timeout", rx_timeout_cmd },