Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa491001 authored by Alexander Aring's avatar Alexander Aring Committed by Marcel Holtmann
Browse files

ieee802154: add valid psdu length helper



This patch adds a generic valid psdu length check function helper. This
is useful to check the length field after receiving. For example the
at86rf231 doesn't filter invalid psdu length. Sometimes the CRC can also
be correct. If we get the lqi value with an invalid frame length the
kernel may crash because we dereference an invalid pointer in the
receive buffer.

Signed-off-by: default avatarAlexander Aring <alex.aring@gmail.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent e176b681
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -23,7 +23,10 @@
#ifndef LINUX_IEEE802154_H
#ifndef LINUX_IEEE802154_H
#define LINUX_IEEE802154_H
#define LINUX_IEEE802154_H


#include <linux/types.h>

#define IEEE802154_MTU			127
#define IEEE802154_MTU			127
#define IEEE802154_MIN_PSDU_LEN		5


#define IEEE802154_FC_TYPE_BEACON	0x0	/* Frame is beacon */
#define IEEE802154_FC_TYPE_BEACON	0x0	/* Frame is beacon */
#define	IEEE802154_FC_TYPE_DATA		0x1	/* Frame is data */
#define	IEEE802154_FC_TYPE_DATA		0x1	/* Frame is data */
@@ -185,5 +188,13 @@ enum {
	IEEE802154_SCAN_IN_PROGRESS = 0xfc,
	IEEE802154_SCAN_IN_PROGRESS = 0xfc,
};
};


/**
 * ieee802154_is_valid_psdu_len - check if psdu len is valid
 * @len: psdu len with (MHR + payload + MFR)
 */
static inline bool ieee802154_is_valid_psdu_len(const u8 len)
{
	return (len >= IEEE802154_MIN_PSDU_LEN && len <= IEEE802154_MTU);
}


#endif /* LINUX_IEEE802154_H */
#endif /* LINUX_IEEE802154_H */