|
| 1 | +/* |
| 2 | + * Copyright (c) 2016 Intel Corporation. |
| 3 | + * Copyright (c) 2022 Florian Grandel. |
| 4 | + * |
| 5 | + * SPDX-License-Identifier: Apache-2.0 |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * @file |
| 10 | + * @brief Packet data common to all IEEE 802.15.4 L2 layers |
| 11 | + */ |
| 12 | + |
| 13 | +#ifndef ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_ |
| 14 | +#define ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_ |
| 15 | + |
| 16 | +#include <string.h> |
| 17 | + |
| 18 | +#include <zephyr/types.h> |
| 19 | + |
| 20 | +#ifdef __cplusplus |
| 21 | +extern "C" { |
| 22 | +#endif |
| 23 | + |
| 24 | +/** @cond ignore */ |
| 25 | + |
| 26 | +#ifndef NET_PKT_HAS_CONTROL_BLOCK |
| 27 | +#define NET_PKT_HAS_CONTROL_BLOCK |
| 28 | +#endif |
| 29 | + |
| 30 | +struct net_pkt_cb_ieee802154 { |
| 31 | +#if defined(CONFIG_IEEE802154_2015) |
| 32 | + uint32_t ack_fc; /* Frame counter set in the ACK */ |
| 33 | + uint8_t ack_keyid; /* Key index set in the ACK */ |
| 34 | +#endif |
| 35 | + union { |
| 36 | + /* RX packets */ |
| 37 | + struct { |
| 38 | + uint8_t lqi; /* Link Quality Indicator */ |
| 39 | + uint8_t rssi; /* Received Signal Strength Indication */ |
| 40 | + }; |
| 41 | +#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER) |
| 42 | + /* TX packets */ |
| 43 | + struct { |
| 44 | + int8_t txpwr; /* TX power in dBm. */ |
| 45 | + }; |
| 46 | +#endif /* CONFIG_IEEE802154_SELECTIVE_TXPOWER */ |
| 47 | + }; |
| 48 | + |
| 49 | + /* Flags */ |
| 50 | + uint8_t arb : 1; /* ACK Request Bit is set in the frame */ |
| 51 | + uint8_t ack_fpb : 1; /* Frame Pending Bit was set in the ACK */ |
| 52 | + uint8_t frame_secured : 1; /* Frame is authenticated and |
| 53 | + * encrypted according to its |
| 54 | + * Auxiliary Security Header |
| 55 | + */ |
| 56 | + uint8_t mac_hdr_rdy : 1; /* Indicates if frame's MAC header |
| 57 | + * is ready to be transmitted or if |
| 58 | + * it requires further modifications, |
| 59 | + * e.g. Frame Counter injection. |
| 60 | + */ |
| 61 | +#if defined(CONFIG_IEEE802154_2015) |
| 62 | + uint8_t fv2015 : 1; /* Frame version is IEEE 802.15.4-2015 or later */ |
| 63 | + uint8_t ack_seb : 1; /* Security Enabled Bit was set in the ACK */ |
| 64 | +#endif |
| 65 | +}; |
| 66 | + |
| 67 | +struct net_pkt; |
| 68 | +static inline void *net_pkt_cb(struct net_pkt *pkt); |
| 69 | + |
| 70 | +static inline struct net_pkt_cb_ieee802154 *net_pkt_cb_ieee802154(struct net_pkt *pkt) |
| 71 | +{ |
| 72 | + return net_pkt_cb(pkt); |
| 73 | +}; |
| 74 | + |
| 75 | +static inline uint8_t net_pkt_ieee802154_lqi(struct net_pkt *pkt) |
| 76 | +{ |
| 77 | + return net_pkt_cb_ieee802154(pkt)->lqi; |
| 78 | +} |
| 79 | + |
| 80 | +static inline void net_pkt_set_ieee802154_lqi(struct net_pkt *pkt, uint8_t lqi) |
| 81 | +{ |
| 82 | + net_pkt_cb_ieee802154(pkt)->lqi = lqi; |
| 83 | +} |
| 84 | + |
| 85 | +static inline uint8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt) |
| 86 | +{ |
| 87 | + return net_pkt_cb_ieee802154(pkt)->rssi; |
| 88 | +} |
| 89 | + |
| 90 | +static inline void net_pkt_set_ieee802154_rssi(struct net_pkt *pkt, uint8_t rssi) |
| 91 | +{ |
| 92 | + net_pkt_cb_ieee802154(pkt)->rssi = rssi; |
| 93 | +} |
| 94 | + |
| 95 | +#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER) |
| 96 | +static inline int8_t net_pkt_ieee802154_txpwr(struct net_pkt *pkt) |
| 97 | +{ |
| 98 | + return net_pkt_cb_ieee802154(pkt)->txpwr; |
| 99 | +} |
| 100 | + |
| 101 | +static inline void net_pkt_set_ieee802154_txpwr(struct net_pkt *pkt, int8_t txpwr) |
| 102 | +{ |
| 103 | + net_pkt_cb_ieee802154(pkt)->txpwr = txpwr; |
| 104 | +} |
| 105 | +#endif /* CONFIG_IEEE802154_SELECTIVE_TXPOWER */ |
| 106 | + |
| 107 | +static inline bool net_pkt_ieee802154_arb(struct net_pkt *pkt) |
| 108 | +{ |
| 109 | + return net_pkt_cb_ieee802154(pkt)->arb; |
| 110 | +} |
| 111 | + |
| 112 | +static inline void net_pkt_set_ieee802154_arb(struct net_pkt *pkt, bool arb) |
| 113 | +{ |
| 114 | + net_pkt_cb_ieee802154(pkt)->arb = arb; |
| 115 | +} |
| 116 | + |
| 117 | +static inline bool net_pkt_ieee802154_ack_fpb(struct net_pkt *pkt) |
| 118 | +{ |
| 119 | + return net_pkt_cb_ieee802154(pkt)->ack_fpb; |
| 120 | +} |
| 121 | + |
| 122 | +static inline void net_pkt_set_ieee802154_ack_fpb(struct net_pkt *pkt, bool fpb) |
| 123 | +{ |
| 124 | + net_pkt_cb_ieee802154(pkt)->ack_fpb = fpb; |
| 125 | +} |
| 126 | + |
| 127 | +static inline bool net_pkt_ieee802154_frame_secured(struct net_pkt *pkt) |
| 128 | +{ |
| 129 | + return net_pkt_cb_ieee802154(pkt)->frame_secured; |
| 130 | +} |
| 131 | + |
| 132 | +static inline void net_pkt_set_ieee802154_frame_secured(struct net_pkt *pkt, bool secured) |
| 133 | +{ |
| 134 | + net_pkt_cb_ieee802154(pkt)->frame_secured = secured; |
| 135 | +} |
| 136 | + |
| 137 | +static inline bool net_pkt_ieee802154_mac_hdr_rdy(struct net_pkt *pkt) |
| 138 | +{ |
| 139 | + return net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy; |
| 140 | +} |
| 141 | + |
| 142 | +static inline void net_pkt_set_ieee802154_mac_hdr_rdy(struct net_pkt *pkt, bool rdy) |
| 143 | +{ |
| 144 | + net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy = rdy; |
| 145 | +} |
| 146 | + |
| 147 | +#if defined(CONFIG_IEEE802154_2015) |
| 148 | +static inline uint32_t net_pkt_ieee802154_ack_fc(struct net_pkt *pkt) |
| 149 | +{ |
| 150 | + return net_pkt_cb_ieee802154(pkt)->ack_fc; |
| 151 | +} |
| 152 | + |
| 153 | +static inline void net_pkt_set_ieee802154_ack_fc(struct net_pkt *pkt, uint32_t fc) |
| 154 | +{ |
| 155 | + net_pkt_cb_ieee802154(pkt)->ack_fc = fc; |
| 156 | +} |
| 157 | + |
| 158 | +static inline uint8_t net_pkt_ieee802154_ack_keyid(struct net_pkt *pkt) |
| 159 | +{ |
| 160 | + return net_pkt_cb_ieee802154(pkt)->ack_keyid; |
| 161 | +} |
| 162 | + |
| 163 | +static inline void net_pkt_set_ieee802154_ack_keyid(struct net_pkt *pkt, uint8_t keyid) |
| 164 | +{ |
| 165 | + net_pkt_cb_ieee802154(pkt)->ack_keyid = keyid; |
| 166 | +} |
| 167 | + |
| 168 | +static inline bool net_pkt_ieee802154_fv2015(struct net_pkt *pkt) |
| 169 | +{ |
| 170 | + return net_pkt_cb_ieee802154(pkt)->fv2015; |
| 171 | +} |
| 172 | + |
| 173 | +static inline void net_pkt_set_ieee802154_fv2015(struct net_pkt *pkt, bool fv2015) |
| 174 | +{ |
| 175 | + net_pkt_cb_ieee802154(pkt)->fv2015 = fv2015; |
| 176 | +} |
| 177 | + |
| 178 | +static inline bool net_pkt_ieee802154_ack_seb(struct net_pkt *pkt) |
| 179 | +{ |
| 180 | + return net_pkt_cb_ieee802154(pkt)->ack_seb; |
| 181 | +} |
| 182 | + |
| 183 | +static inline void net_pkt_set_ieee802154_ack_seb(struct net_pkt *pkt, bool seb) |
| 184 | +{ |
| 185 | + net_pkt_cb_ieee802154(pkt)->ack_seb = seb; |
| 186 | +} |
| 187 | +#endif /* CONFIG_IEEE802154_2015 */ |
| 188 | + |
| 189 | +/** @endcond */ |
| 190 | + |
| 191 | +#ifdef __cplusplus |
| 192 | +} |
| 193 | +#endif |
| 194 | + |
| 195 | +#endif /* ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_ */ |
0 commit comments