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)
75#if defined(CONFIG_NET_L2_OPENTHREAD)
81static inline void *net_pkt_cb(
struct net_pkt *pkt);
83static inline struct net_pkt_cb_ieee802154 *net_pkt_cb_ieee802154(
struct net_pkt *pkt)
85 return (
struct net_pkt_cb_ieee802154 *)net_pkt_cb(pkt);
90 return net_pkt_cb_ieee802154(pkt)->lqi;
93static inline void net_pkt_set_ieee802154_lqi(
struct net_pkt *pkt,
uint8_t lqi)
95 net_pkt_cb_ieee802154(pkt)->lqi = lqi;
112 return net_pkt_cb_ieee802154(pkt)->rssi;
127static inline void net_pkt_set_ieee802154_rssi(
struct net_pkt *pkt,
uint8_t rssi)
129 net_pkt_cb_ieee802154(pkt)->rssi = rssi;
143static inline int16_t net_pkt_ieee802154_rssi_dbm(
struct net_pkt *pkt)
145 int16_t rssi = net_pkt_cb_ieee802154(pkt)->rssi;
146 return rssi == IEEE802154_MAC_RSSI_UNDEFINED ? IEEE802154_MAC_RSSI_DBM_UNDEFINED
147 : rssi + IEEE802154_MAC_RSSI_DBM_MIN;
161static inline void net_pkt_set_ieee802154_rssi_dbm(
struct net_pkt *pkt,
int16_t rssi)
163 if (likely(rssi >= IEEE802154_MAC_RSSI_DBM_MIN && rssi <= IEEE802154_MAC_RSSI_DBM_MAX)) {
164 int16_t unsigned_rssi = rssi - IEEE802154_MAC_RSSI_DBM_MIN;
166 net_pkt_cb_ieee802154(pkt)->rssi = unsigned_rssi;
168 }
else if (rssi == IEEE802154_MAC_RSSI_DBM_UNDEFINED) {
169 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_UNDEFINED;
171 }
else if (rssi < IEEE802154_MAC_RSSI_DBM_MIN) {
172 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_MIN;
174 }
else if (rssi > IEEE802154_MAC_RSSI_DBM_MAX) {
175 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_MAX;
182static inline bool net_pkt_ieee802154_ack_fpb(
struct net_pkt *pkt)
184 return net_pkt_cb_ieee802154(pkt)->ack_fpb;
187static inline void net_pkt_set_ieee802154_ack_fpb(
struct net_pkt *pkt,
bool fpb)
189 net_pkt_cb_ieee802154(pkt)->ack_fpb = fpb;
192static inline bool net_pkt_ieee802154_frame_secured(
struct net_pkt *pkt)
194 return net_pkt_cb_ieee802154(pkt)->frame_secured;
197static inline void net_pkt_set_ieee802154_frame_secured(
struct net_pkt *pkt,
bool secured)
199 net_pkt_cb_ieee802154(pkt)->frame_secured = secured;
202static inline bool net_pkt_ieee802154_mac_hdr_rdy(
struct net_pkt *pkt)
204 return net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy;
207static inline void net_pkt_set_ieee802154_mac_hdr_rdy(
struct net_pkt *pkt,
bool rdy)
209 net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy = rdy;
212#if defined(CONFIG_NET_L2_OPENTHREAD)
215 return net_pkt_cb_ieee802154(pkt)->ack_fc;
218static inline void net_pkt_set_ieee802154_ack_fc(
struct net_pkt *pkt,
uint32_t fc)
220 net_pkt_cb_ieee802154(pkt)->ack_fc = fc;
223static inline uint8_t net_pkt_ieee802154_ack_keyid(
struct net_pkt *pkt)
225 return net_pkt_cb_ieee802154(pkt)->ack_keyid;
228static inline void net_pkt_set_ieee802154_ack_keyid(
struct net_pkt *pkt,
uint8_t keyid)
230 net_pkt_cb_ieee802154(pkt)->ack_keyid = keyid;
233static inline bool net_pkt_ieee802154_ack_seb(
struct net_pkt *pkt)
235 return net_pkt_cb_ieee802154(pkt)->ack_seb;
238static inline void net_pkt_set_ieee802154_ack_seb(
struct net_pkt *pkt,
bool seb)
240 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:67