Skip to content

Commit

Permalink
Merge pull request RIOT-OS#16586 from jia200x/pr/fix_gnrc_lorawan_psd…
Browse files Browse the repository at this point in the history
…u_null

gnrc_lorawan: fix undefined state when PSDU is NULL
  • Loading branch information
MrKevinWeiss authored Jun 25, 2021
2 parents 05b61e8 + a90e5e6 commit d9973d4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 14 additions & 2 deletions sys/include/net/gnrc/lorawan.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ void gnrc_lorawan_radio_rx_timeout_cb(gnrc_lorawan_t *mac);
*/
void gnrc_lorawan_radio_tx_done_cb(gnrc_lorawan_t *mac);

/**
* @brief Indicate the MAC layer reception of a frame went wrong.
*
* @param[in] mac pointer to the MAC descriptor
*/
static inline void gnrc_lorawan_radio_rx_error_cb(gnrc_lorawan_t *mac)
{
/* The failed reception is seen by the MAC layer as an RX timeout */
gnrc_lorawan_radio_rx_timeout_cb(mac);
}

/**
* @brief Indicate the MAC layer that the timer was fired
*
Expand Down Expand Up @@ -226,8 +237,9 @@ void gnrc_lorawan_mcps_request(gnrc_lorawan_t *mac,
* To be called on radio RX done event.
*
* @param[in] mac pointer to the MAC descriptor
* @param[in] data pointer to the psdu. Pass NULL if the packet was wrong (or
* allocation failed)
* @param[in] data pointer to the psdu. Must not be NULL. Use
* @ref gnrc_lorawan_radio_rx_error_cb instead if the reception was
* not successful.
* @param[in] size size of the PSDU
*/
void gnrc_lorawan_radio_rx_done_cb(gnrc_lorawan_t *mac, uint8_t *data,
Expand Down
4 changes: 1 addition & 3 deletions sys/net/gnrc/link_layer/lorawan/gnrc_lorawan.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,8 @@ void gnrc_lorawan_send_pkt(gnrc_lorawan_t *mac, iolist_t *psdu, uint8_t dr)
void gnrc_lorawan_radio_rx_done_cb(gnrc_lorawan_t *mac, uint8_t *psdu,
size_t size)
{
assert(psdu);
_sleep_radio(mac);
if (psdu == NULL) {
return;
}
mac->state = LORAWAN_STATE_IDLE;
gnrc_lorawan_remove_timer(mac);

Expand Down
4 changes: 2 additions & 2 deletions sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ static void _rx_done(gnrc_lorawan_t *mac)
DEBUG("_recv_lorawan: cannot allocate pktsnip.\n");
/* Discard packet on netdev device */
dev->driver->recv(dev, NULL, bytes_expected, NULL);
gnrc_lorawan_radio_rx_done_cb(mac, NULL, 0);
gnrc_lorawan_radio_rx_error_cb(mac);
return;
}
nread = dev->driver->recv(dev, pkt->data, bytes_expected, &rx_info);
if (nread <= 0) {
gnrc_pktbuf_release(pkt);
gnrc_lorawan_radio_rx_done_cb(mac, NULL, 0);
gnrc_lorawan_radio_rx_error_cb(mac);
return;
}

Expand Down

0 comments on commit d9973d4

Please sign in to comment.