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)); diff --git a/sys/include/net/netopt.h b/sys/include/net/netopt.h index 3c8c1a56d3..9c9a610c1c 100644 --- a/sys/include/net/netopt.h +++ b/sys/include/net/netopt.h @@ -186,6 +186,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", diff --git a/tests/driver_sx127x/main.c b/tests/driver_sx127x/main.c index 1883d4bb8c..3fcc8662eb 100644 --- a/tests/driver_sx127x/main.c +++ b/tests/driver_sx127x/main.c @@ -378,8 +378,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 },