at86rf230: use ieee802154_is_valid_psdu_len helper
authorAlexander Aring <alex.aring@gmail.com>
Mon, 27 Oct 2014 16:13:41 +0000 (17:13 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 27 Oct 2014 17:07:49 +0000 (18:07 +0100)
This patch adds the ieee802154_is_valid_psdu_len function to validate
the psdu length. If the psdu length is invalid we use the maximum
payload to receive also corrupted frames in monitor mode.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
drivers/net/ieee802154/at86rf230.c

index e4fbcaa602b6bce4fc8369c3b26dc5a8fbb5d2e7..368791b285852314cad76abacc6a662e437f3499 100644 (file)
@@ -788,26 +788,11 @@ at86rf230_tx_trac_status(void *context)
 
 static void
 at86rf230_rx(struct at86rf230_local *lp,
-            const u8 *data, u8 len)
+            const u8 *data, const u8 len)
 {
-       u8 lqi;
        struct sk_buff *skb;
        u8 rx_local_buf[AT86RF2XX_MAX_BUF];
 
-       if (len < 2)
-               return;
-
-       /* read full frame buffer and invalid lqi value to lowest
-        * indicator if frame was is in a corrupted state.
-        */
-       if (len > IEEE802154_MTU) {
-               lqi = 0;
-               len = IEEE802154_MTU;
-               dev_vdbg(&lp->spi->dev, "corrupted frame received\n");
-       } else {
-               lqi = data[len];
-       }
-
        memcpy(rx_local_buf, data, len);
        enable_irq(lp->spi->irq);
 
@@ -822,7 +807,7 @@ at86rf230_rx(struct at86rf230_local *lp,
        /* We do not put CRC into the frame */
        skb_trim(skb, len - 2);
 
-       ieee802154_rx_irqsafe(lp->hw, skb, lqi);
+       ieee802154_rx_irqsafe(lp->hw, skb, rx_local_buf[len]);
 }
 
 static void
@@ -831,7 +816,12 @@ at86rf230_rx_read_frame_complete(void *context)
        struct at86rf230_state_change *ctx = context;
        struct at86rf230_local *lp = ctx->lp;
        const u8 *buf = lp->irq.buf;
-       const u8 len = buf[1];
+       u8 len = buf[1];
+
+       if (!ieee802154_is_valid_psdu_len(len)) {
+               dev_vdbg(&lp->spi->dev, "corrupted frame received\n");
+               len = IEEE802154_MTU;
+       }
 
        at86rf230_rx(lp, buf + 2, len);
 }