Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ieee802154_pkt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Intel Corporation.
3 * Copyright (c) 2022 Florian Grandel.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
14
15#ifndef ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_
16#define ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_
17
18#include <string.h>
19
20#include <zephyr/types.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
27
28/* See section 6.16.2.8 - Received Signal Strength Indicator (RSSI) */
29#define IEEE802154_MAC_RSSI_MIN 0U /* corresponds to -174 dBm */
30#define IEEE802154_MAC_RSSI_MAX 254U /* corresponds to 80 dBm */
31#define IEEE802154_MAC_RSSI_UNDEFINED 255U /* used by us to indicate an undefined RSSI value */
32
33#define IEEE802154_MAC_RSSI_DBM_MIN -174 /* in dBm */
34#define IEEE802154_MAC_RSSI_DBM_MAX 80 /* in dBm */
35#define IEEE802154_MAC_RSSI_DBM_UNDEFINED INT16_MIN /* represents an undefined RSSI value */
36
37struct net_pkt_cb_ieee802154 {
38#if defined(CONFIG_NET_L2_OPENTHREAD)
39 uint32_t ack_fc; /* Frame counter set in the ACK */
40 uint8_t ack_keyid; /* Key index set in the ACK */
41#endif
42 union {
43 /* RX packets */
44 struct {
45 uint8_t lqi; /* Link Quality Indicator */
46 /* See section 6.16.2.8 - Received Signal Strength Indicator (RSSI)
47 * "RSSI is represented as one octet of integer [...]; therefore,
48 * the minimum and maximum values are 0 (–174 dBm) and 254 (80 dBm),
49 * respectively. 255 is reserved." (MAC PIB attribute macRssi, see
50 * section 8.4.3.10, table 8-108)
51 *
52 * TX packets will show zero for this value. Drivers may set the
53 * field to the reserved value 255 (0xff) to indicate that an RSSI
54 * value is not available for this packet.
55 */
56 uint8_t rssi;
57 };
58 struct {
59#if defined(CONFIG_IEEE802154_SELECTIVE_TXCHANNEL)
60 /* The channel used for timed transmissions.
61 *
62 * Please refer to `ieee802154_radio_api::tx` documentation for
63 * details.
64 */
65 uint8_t txchannel;
66#endif /* CONFIG_IEEE802154_SELECTIVE_TXCHANNEL */
67 };
68 };
69
70 /* Flags */
71 uint8_t ack_fpb : 1; /* Frame Pending Bit was set in the ACK */
72 uint8_t frame_secured : 1; /* Frame is authenticated and
73 * encrypted according to its
74 * Auxiliary Security Header
75 */
76 uint8_t mac_hdr_rdy : 1; /* Indicates if frame's MAC header
77 * is ready to be transmitted or if
78 * it requires further modifications,
79 * e.g. Frame Counter injection.
80 */
81#if defined(CONFIG_NET_L2_OPENTHREAD)
82 uint8_t ack_seb : 1; /* Security Enabled Bit was set in the ACK */
83#endif
84};
85
86struct net_pkt;
87static inline void *net_pkt_cb(struct net_pkt *pkt);
88
89static inline struct net_pkt_cb_ieee802154 *net_pkt_cb_ieee802154(struct net_pkt *pkt)
90{
91 return (struct net_pkt_cb_ieee802154 *)net_pkt_cb(pkt);
92};
93
94static inline uint8_t net_pkt_ieee802154_lqi(struct net_pkt *pkt)
95{
96 return net_pkt_cb_ieee802154(pkt)->lqi;
97}
98
99static inline void net_pkt_set_ieee802154_lqi(struct net_pkt *pkt, uint8_t lqi)
100{
101 net_pkt_cb_ieee802154(pkt)->lqi = lqi;
102}
103
116static inline uint8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt)
117{
118 return net_pkt_cb_ieee802154(pkt)->rssi;
119}
120
133static inline void net_pkt_set_ieee802154_rssi(struct net_pkt *pkt, uint8_t rssi)
134{
135 net_pkt_cb_ieee802154(pkt)->rssi = rssi;
136}
137
149static inline int16_t net_pkt_ieee802154_rssi_dbm(struct net_pkt *pkt)
150{
151 int16_t rssi = net_pkt_cb_ieee802154(pkt)->rssi;
152 return rssi == IEEE802154_MAC_RSSI_UNDEFINED ? IEEE802154_MAC_RSSI_DBM_UNDEFINED
153 : rssi + IEEE802154_MAC_RSSI_DBM_MIN;
154}
155
167static inline void net_pkt_set_ieee802154_rssi_dbm(struct net_pkt *pkt, int16_t rssi)
168{
169 if (likely(rssi >= IEEE802154_MAC_RSSI_DBM_MIN && rssi <= IEEE802154_MAC_RSSI_DBM_MAX)) {
170 int16_t unsigned_rssi = rssi - IEEE802154_MAC_RSSI_DBM_MIN;
171
172 net_pkt_cb_ieee802154(pkt)->rssi = unsigned_rssi;
173 return;
174 } else if (rssi == IEEE802154_MAC_RSSI_DBM_UNDEFINED) {
175 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_UNDEFINED;
176 return;
177 } else if (rssi < IEEE802154_MAC_RSSI_DBM_MIN) {
178 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_MIN;
179 return;
180 } else if (rssi > IEEE802154_MAC_RSSI_DBM_MAX) {
181 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_MAX;
182 return;
183 }
184
185 CODE_UNREACHABLE;
186}
187
188#if defined(CONFIG_IEEE802154_SELECTIVE_TXCHANNEL)
189static inline uint8_t net_pkt_ieee802154_txchannel(struct net_pkt *pkt)
190{
191 return net_pkt_cb_ieee802154(pkt)->txchannel;
192}
193
194static inline void net_pkt_set_ieee802154_txchannel(struct net_pkt *pkt, uint8_t channel)
195{
196 net_pkt_cb_ieee802154(pkt)->txchannel = channel;
197}
198#endif /* CONFIG_IEEE802154_SELECTIVE_TXCHANNEL */
199
200static inline bool net_pkt_ieee802154_ack_fpb(struct net_pkt *pkt)
201{
202 return net_pkt_cb_ieee802154(pkt)->ack_fpb;
203}
204
205static inline void net_pkt_set_ieee802154_ack_fpb(struct net_pkt *pkt, bool fpb)
206{
207 net_pkt_cb_ieee802154(pkt)->ack_fpb = fpb;
208}
209
210static inline bool net_pkt_ieee802154_frame_secured(struct net_pkt *pkt)
211{
212 return net_pkt_cb_ieee802154(pkt)->frame_secured;
213}
214
215static inline void net_pkt_set_ieee802154_frame_secured(struct net_pkt *pkt, bool secured)
216{
217 net_pkt_cb_ieee802154(pkt)->frame_secured = secured;
218}
219
220static inline bool net_pkt_ieee802154_mac_hdr_rdy(struct net_pkt *pkt)
221{
222 return net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy;
223}
224
225static inline void net_pkt_set_ieee802154_mac_hdr_rdy(struct net_pkt *pkt, bool rdy)
226{
227 net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy = rdy;
228}
229
230#if defined(CONFIG_NET_L2_OPENTHREAD)
231static inline uint32_t net_pkt_ieee802154_ack_fc(struct net_pkt *pkt)
232{
233 return net_pkt_cb_ieee802154(pkt)->ack_fc;
234}
235
236static inline void net_pkt_set_ieee802154_ack_fc(struct net_pkt *pkt, uint32_t fc)
237{
238 net_pkt_cb_ieee802154(pkt)->ack_fc = fc;
239}
240
241static inline uint8_t net_pkt_ieee802154_ack_keyid(struct net_pkt *pkt)
242{
243 return net_pkt_cb_ieee802154(pkt)->ack_keyid;
244}
245
246static inline void net_pkt_set_ieee802154_ack_keyid(struct net_pkt *pkt, uint8_t keyid)
247{
248 net_pkt_cb_ieee802154(pkt)->ack_keyid = keyid;
249}
250
251static inline bool net_pkt_ieee802154_ack_seb(struct net_pkt *pkt)
252{
253 return net_pkt_cb_ieee802154(pkt)->ack_seb;
254}
255
256static inline void net_pkt_set_ieee802154_ack_seb(struct net_pkt *pkt, bool seb)
257{
258 net_pkt_cb_ieee802154(pkt)->ack_seb = seb;
259}
260#endif /* CONFIG_NET_L2_OPENTHREAD */
261
263
264#ifdef __cplusplus
265}
266#endif
267
268#endif /* ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_ */
__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