Zephyr API Documentation 4.0.0-rc3
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
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
28#ifndef NET_PKT_HAS_CONTROL_BLOCK
29#define NET_PKT_HAS_CONTROL_BLOCK
30#endif
31
32/* See section 6.16.2.8 - Received Signal Strength Indicator (RSSI) */
33#define IEEE802154_MAC_RSSI_MIN 0U /* corresponds to -174 dBm */
34#define IEEE802154_MAC_RSSI_MAX 254U /* corresponds to 80 dBm */
35#define IEEE802154_MAC_RSSI_UNDEFINED 255U /* used by us to indicate an undefined RSSI value */
36
37#define IEEE802154_MAC_RSSI_DBM_MIN -174 /* in dBm */
38#define IEEE802154_MAC_RSSI_DBM_MAX 80 /* in dBm */
39#define IEEE802154_MAC_RSSI_DBM_UNDEFINED INT16_MIN /* represents an undefined RSSI value */
40
41struct net_pkt_cb_ieee802154 {
42#if defined(CONFIG_NET_L2_OPENTHREAD)
43 uint32_t ack_fc; /* Frame counter set in the ACK */
44 uint8_t ack_keyid; /* Key index set in the ACK */
45#endif
46 union {
47 /* RX packets */
48 struct {
49 uint8_t lqi; /* Link Quality Indicator */
50 /* See section 6.16.2.8 - Received Signal Strength Indicator (RSSI)
51 * "RSSI is represented as one octet of integer [...]; therefore,
52 * the minimum and maximum values are 0 (–174 dBm) and 254 (80 dBm),
53 * respectively. 255 is reserved." (MAC PIB attribute macRssi, see
54 * section 8.4.3.10, table 8-108)
55 *
56 * TX packets will show zero for this value. Drivers may set the
57 * field to the reserved value 255 (0xff) to indicate that an RSSI
58 * value is not available for this packet.
59 */
60 uint8_t rssi;
61 };
62 struct {
63#if defined(CONFIG_IEEE802154_SELECTIVE_TXCHANNEL)
64 /* The channel used for timed transmissions.
65 *
66 * Please refer to `ieee802154_radio_api::tx` documentation for
67 * details.
68 */
69 uint8_t txchannel;
70#endif /* CONFIG_IEEE802154_SELECTIVE_TXCHANNEL */
71 };
72 };
73
74 /* Flags */
75 uint8_t ack_fpb : 1; /* Frame Pending Bit was set in the ACK */
76 uint8_t frame_secured : 1; /* Frame is authenticated and
77 * encrypted according to its
78 * Auxiliary Security Header
79 */
80 uint8_t mac_hdr_rdy : 1; /* Indicates if frame's MAC header
81 * is ready to be transmitted or if
82 * it requires further modifications,
83 * e.g. Frame Counter injection.
84 */
85#if defined(CONFIG_NET_L2_OPENTHREAD)
86 uint8_t ack_seb : 1; /* Security Enabled Bit was set in the ACK */
87#endif
88};
89
90struct net_pkt;
91static inline void *net_pkt_cb(struct net_pkt *pkt);
92
93static inline struct net_pkt_cb_ieee802154 *net_pkt_cb_ieee802154(struct net_pkt *pkt)
94{
95 return (struct net_pkt_cb_ieee802154 *)net_pkt_cb(pkt);
96};
97
98static inline uint8_t net_pkt_ieee802154_lqi(struct net_pkt *pkt)
99{
100 return net_pkt_cb_ieee802154(pkt)->lqi;
101}
102
103static inline void net_pkt_set_ieee802154_lqi(struct net_pkt *pkt, uint8_t lqi)
104{
105 net_pkt_cb_ieee802154(pkt)->lqi = lqi;
106}
107
120static inline uint8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt)
121{
122 return net_pkt_cb_ieee802154(pkt)->rssi;
123}
124
137static inline void net_pkt_set_ieee802154_rssi(struct net_pkt *pkt, uint8_t rssi)
138{
139 net_pkt_cb_ieee802154(pkt)->rssi = rssi;
140}
141
153static inline int16_t net_pkt_ieee802154_rssi_dbm(struct net_pkt *pkt)
154{
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;
158}
159
171static inline void net_pkt_set_ieee802154_rssi_dbm(struct net_pkt *pkt, int16_t rssi)
172{
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;
175
176 net_pkt_cb_ieee802154(pkt)->rssi = unsigned_rssi;
177 return;
178 } else if (rssi == IEEE802154_MAC_RSSI_DBM_UNDEFINED) {
179 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_UNDEFINED;
180 return;
181 } else if (rssi < IEEE802154_MAC_RSSI_DBM_MIN) {
182 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_MIN;
183 return;
184 } else if (rssi > IEEE802154_MAC_RSSI_DBM_MAX) {
185 net_pkt_cb_ieee802154(pkt)->rssi = IEEE802154_MAC_RSSI_MAX;
186 return;
187 }
188
189 CODE_UNREACHABLE;
190}
191
192#if defined(CONFIG_IEEE802154_SELECTIVE_TXCHANNEL)
193static inline uint8_t net_pkt_ieee802154_txchannel(struct net_pkt *pkt)
194{
195 return net_pkt_cb_ieee802154(pkt)->txchannel;
196}
197
198static inline void net_pkt_set_ieee802154_txchannel(struct net_pkt *pkt, uint8_t channel)
199{
200 net_pkt_cb_ieee802154(pkt)->txchannel = channel;
201}
202#endif /* CONFIG_IEEE802154_SELECTIVE_TXCHANNEL */
203
204static inline bool net_pkt_ieee802154_ack_fpb(struct net_pkt *pkt)
205{
206 return net_pkt_cb_ieee802154(pkt)->ack_fpb;
207}
208
209static inline void net_pkt_set_ieee802154_ack_fpb(struct net_pkt *pkt, bool fpb)
210{
211 net_pkt_cb_ieee802154(pkt)->ack_fpb = fpb;
212}
213
214static inline bool net_pkt_ieee802154_frame_secured(struct net_pkt *pkt)
215{
216 return net_pkt_cb_ieee802154(pkt)->frame_secured;
217}
218
219static inline void net_pkt_set_ieee802154_frame_secured(struct net_pkt *pkt, bool secured)
220{
221 net_pkt_cb_ieee802154(pkt)->frame_secured = secured;
222}
223
224static inline bool net_pkt_ieee802154_mac_hdr_rdy(struct net_pkt *pkt)
225{
226 return net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy;
227}
228
229static inline void net_pkt_set_ieee802154_mac_hdr_rdy(struct net_pkt *pkt, bool rdy)
230{
231 net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy = rdy;
232}
233
234#if defined(CONFIG_NET_L2_OPENTHREAD)
235static inline uint32_t net_pkt_ieee802154_ack_fc(struct net_pkt *pkt)
236{
237 return net_pkt_cb_ieee802154(pkt)->ack_fc;
238}
239
240static inline void net_pkt_set_ieee802154_ack_fc(struct net_pkt *pkt, uint32_t fc)
241{
242 net_pkt_cb_ieee802154(pkt)->ack_fc = fc;
243}
244
245static inline uint8_t net_pkt_ieee802154_ack_keyid(struct net_pkt *pkt)
246{
247 return net_pkt_cb_ieee802154(pkt)->ack_keyid;
248}
249
250static inline void net_pkt_set_ieee802154_ack_keyid(struct net_pkt *pkt, uint8_t keyid)
251{
252 net_pkt_cb_ieee802154(pkt)->ack_keyid = keyid;
253}
254
255static inline bool net_pkt_ieee802154_ack_seb(struct net_pkt *pkt)
256{
257 return net_pkt_cb_ieee802154(pkt)->ack_seb;
258}
259
260static inline void net_pkt_set_ieee802154_ack_seb(struct net_pkt *pkt, bool seb)
261{
262 net_pkt_cb_ieee802154(pkt)->ack_seb = seb;
263}
264#endif /* CONFIG_NET_L2_OPENTHREAD */
265
268#ifdef __cplusplus
269}
270#endif
271
272#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