diff --git a/features/lorawan/LoRaWANBase.h b/features/lorawan/LoRaWANBase.h index 33fbe09c89..a57a639806 100644 --- a/features/lorawan/LoRaWANBase.h +++ b/features/lorawan/LoRaWANBase.h @@ -310,6 +310,7 @@ public: * * @return The number of bytes sent, or a negative error code on failure: * LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(), + * LORAWAN_STATUS_NO_ACTIVE_SESSIONS if connection is not open, * LORAWAN_STATUS_WOULD_BLOCK if another TX is ongoing, * LORAWAN_STATUS_PORT_INVALID if trying to send to an invalid port (e.g. to 0) * LORAWAN_STATUS_PARAMETER_INVALID if NULL data pointer is given or flags are invalid. @@ -345,6 +346,7 @@ public: * i) 0 if there is nothing else to read. * ii) Number of bytes written to user buffer. * iii) A negative error code on failure: + * LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(), * LORAWAN_STATUS_NO_ACTIVE_SESSIONS if connection is not open, * LORAWAN_STATUS_WOULD_BLOCK if there is nothing available to read at the moment, * LORAWAN_STATUS_PARAMETER_INVALID if NULL data or length is given, @@ -370,6 +372,7 @@ public: * i) 0 if there is nothing else to read. * ii) Number of bytes written to user buffer. * iii) A negative error code on failure: + * LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(), * LORAWAN_STATUS_NO_ACTIVE_SESSIONS if connection is not open, * LORAWAN_STATUS_PARAMETER_INVALID if NULL data or length is given, * LORAWAN_STATUS_WOULD_BLOCK if there is nothing available to read at the moment. diff --git a/features/lorawan/LoRaWANStack.cpp b/features/lorawan/LoRaWANStack.cpp index 52ceb447f3..34322e62f5 100644 --- a/features/lorawan/LoRaWANStack.cpp +++ b/features/lorawan/LoRaWANStack.cpp @@ -296,6 +296,10 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data, uint16_t length, uint8_t flags, bool null_allowed, bool allow_port_0) { + if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) { + return LORAWAN_STATUS_NOT_INITIALIZED; + } + if (!null_allowed && !data) { return LORAWAN_STATUS_PARAMETER_INVALID; } @@ -356,6 +360,10 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data, int16_t LoRaWANStack::handle_rx(uint8_t *data, uint16_t length, uint8_t &port, int &flags, bool validate_params) { + if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) { + return LORAWAN_STATUS_NOT_INITIALIZED; + } + if (!_lw_session.active) { return LORAWAN_STATUS_NO_ACTIVE_SESSIONS; }