15#ifndef ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_
16#define ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_
28#ifndef NET_PKT_HAS_CONTROL_BLOCK
29#define NET_PKT_HAS_CONTROL_BLOCK
33#define IEEE802154_MAC_RSSI_MIN 0U
34#define IEEE802154_MAC_RSSI_MAX 254U
35#define IEEE802154_MAC_RSSI_UNDEFINED 255U
37#define IEEE802154_MAC_RSSI_DBM_MIN -174
38#define IEEE802154_MAC_RSSI_DBM_MAX 80
39#define IEEE802154_MAC_RSSI_DBM_UNDEFINED INT16_MIN
41struct net_pkt_cb_ieee802154 {
42#if defined(CONFIG_NET_L2_OPENTHREAD)
63#if defined(CONFIG_IEEE802154_SELECTIVE_TXCHANNEL)
85#if defined(CONFIG_NET_L2_OPENTHREAD)
91static inline void *net_pkt_cb(
struct net_pkt *pkt);
93static inline struct net_pkt_cb_ieee802154 *net_pkt_cb_ieee802154(
struct net_pkt *pkt)
95 return (
struct net_pkt_cb_ieee802154 *)net_pkt_cb(pkt);
100 return net_pkt_cb_ieee802154(pkt)->lqi;
103static inline void net_pkt_set_ieee802154_lqi(
struct net_pkt *pkt,
uint8_t lqi)
105 net_pkt_cb_ieee802154(pkt)->lqi = lqi;
122 return net_pkt_cb_ieee802154(pkt)->rssi;
137static inline void net_pkt_set_ieee802154_rssi(
struct net_pkt *pkt,
uint8_t rssi)
139 net_pkt_cb_ieee802154(pkt)->rssi = rssi;
153static inline int16_t net_pkt_ieee802154_rssi_dbm(
struct net_pkt *pkt)
155 int16_t rssi = net_pkt_cb_ieee802154(pkt)->rssi;
156 return rssi == IEEE802154_MAC_RSSI_UNDEFINED ? IEEE802154_MAC_RSSI_DBM_UNDEFINED
157 : rssi + IEEE802154_MAC_RSSI_DBM_MIN;
171static inline void net_pkt_set_ieee802154_rssi_dbm(
struct net_pkt *pkt,
int16_t rssi)
173 if (likely(rssi >= IEEE802154_MAC_RSSI_DBM_MIN && rssi <= IEEE802154_MAC_RSSI_DBM_MAX)) {
174 int16_t unsigned_rssi = rssi - IEEE802154_MAC_RSSI_DBM_MIN;
176 net_pkt_cb_ieee802154(pkt)->rssi = unsigned_rssi;
178 }
else if (rssi == IEEE802154_MAC_RSSI_DBM_UNDEFINED) {
179 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_UNDEFINED;
181 }
else if (rssi < IEEE802154_MAC_RSSI_DBM_MIN) {
182 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_MIN;
184 }
else if (rssi > IEEE802154_MAC_RSSI_DBM_MAX) {
185 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_MAX;
192#if defined(CONFIG_IEEE802154_SELECTIVE_TXCHANNEL)
193static inline uint8_t net_pkt_ieee802154_txchannel(
struct net_pkt *pkt)
195 return net_pkt_cb_ieee802154(pkt)->txchannel;
198static inline void net_pkt_set_ieee802154_txchannel(
struct net_pkt *pkt,
uint8_t channel)
200 net_pkt_cb_ieee802154(pkt)->txchannel = channel;
204static inline bool net_pkt_ieee802154_ack_fpb(
struct net_pkt *pkt)
206 return net_pkt_cb_ieee802154(pkt)->ack_fpb;
209static inline void net_pkt_set_ieee802154_ack_fpb(
struct net_pkt *pkt,
bool fpb)
211 net_pkt_cb_ieee802154(pkt)->ack_fpb = fpb;
214static inline bool net_pkt_ieee802154_frame_secured(
struct net_pkt *pkt)
216 return net_pkt_cb_ieee802154(pkt)->frame_secured;
219static inline void net_pkt_set_ieee802154_frame_secured(
struct net_pkt *pkt,
bool secured)
221 net_pkt_cb_ieee802154(pkt)->frame_secured = secured;
224static inline bool net_pkt_ieee802154_mac_hdr_rdy(
struct net_pkt *pkt)
226 return net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy;
229static inline void net_pkt_set_ieee802154_mac_hdr_rdy(
struct net_pkt *pkt,
bool rdy)
231 net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy = rdy;
234#if defined(CONFIG_NET_L2_OPENTHREAD)
237 return net_pkt_cb_ieee802154(pkt)->ack_fc;
240static inline void net_pkt_set_ieee802154_ack_fc(
struct net_pkt *pkt,
uint32_t fc)
242 net_pkt_cb_ieee802154(pkt)->ack_fc = fc;
245static inline uint8_t net_pkt_ieee802154_ack_keyid(
struct net_pkt *pkt)
247 return net_pkt_cb_ieee802154(pkt)->ack_keyid;
250static inline void net_pkt_set_ieee802154_ack_keyid(
struct net_pkt *pkt,
uint8_t keyid)
252 net_pkt_cb_ieee802154(pkt)->ack_keyid = keyid;
255static inline bool net_pkt_ieee802154_ack_seb(
struct net_pkt *pkt)
257 return net_pkt_cb_ieee802154(pkt)->ack_seb;
260static inline void net_pkt_set_ieee802154_ack_seb(
struct net_pkt *pkt,
bool seb)
262 net_pkt_cb_ieee802154(pkt)->ack_seb = seb;
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__INT16_TYPE__ int16_t
Definition stdint.h:73
Network packet.
Definition net_pkt.h:91