Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ieee802154_ie.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Florian Grandel, Zephyr Project.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
23#ifndef ZEPHYR_INCLUDE_NET_IEEE802154_IE_H_
24#define ZEPHYR_INCLUDE_NET_IEEE802154_IE_H_
25
26#include <zephyr/net/buf.h>
28
46
63
65#define IEEE802154_VENDOR_SPECIFIC_IE_OUI_LEN 3
71 uint8_t vendor_oui[IEEE802154_VENDOR_SPECIFIC_IE_OUI_LEN];
74} __packed;
75
82
88
98
105
114
122
132
137
140/* @brief Generic Header IE, see section 7.4.2.1. */
141struct ieee802154_header_ie {
142#if CONFIG_LITTLE_ENDIAN
143 uint16_t length : 7;
144 uint16_t element_id_low : 1; /* see enum ieee802154_header_ie_element_id */
145 uint16_t element_id_high : 7;
146 uint16_t type : 1; /* always 0 */
147#else
148 uint16_t element_id_low : 1; /* see enum ieee802154_header_ie_element_id */
149 uint16_t length : 7;
150 uint16_t type : 1; /* always 0 */
151 uint16_t element_id_high : 7;
152#endif
153 union {
154 struct ieee802154_header_ie_vendor_specific vendor_specific;
155 struct ieee802154_header_ie_csl csl;
156 struct ieee802154_header_ie_rit rit;
157 struct ieee802154_header_ie_rendezvous_time rendezvous_time;
158 struct ieee802154_header_ie_time_correction time_correction;
159 /* add additional supported header IEs here */
160 } content;
161} __packed;
162
166#define IEEE802154_HEADER_IE_HEADER_LENGTH sizeof(uint16_t)
167
168
170#define IEEE802154_DEFINE_HEADER_IE(_element_id, _length, _content, _content_type) \
171 (struct ieee802154_header_ie) { \
172 .length = (_length), \
173 .element_id_high = (_element_id) >> 1U, .element_id_low = (_element_id) & 0x01, \
174 .type = IEEE802154_IE_TYPE_HEADER, \
175 .content._content_type = _content, \
176 }
177
178#define IEEE802154_DEFINE_HEADER_IE_VENDOR_SPECIFIC_CONTENT_LEN(_vendor_specific_info_len) \
179 (IEEE802154_VENDOR_SPECIFIC_IE_OUI_LEN + (_vendor_specific_info_len))
180
181#define IEEE802154_DEFINE_HEADER_IE_VENDOR_SPECIFIC_CONTENT(_vendor_oui, _vendor_specific_info) \
182 (struct ieee802154_header_ie_vendor_specific) { \
183 .vendor_oui = _vendor_oui, .vendor_specific_info = (_vendor_specific_info), \
184 }
185
186#define IEEE802154_DEFINE_HEADER_IE_CSL_REDUCED_CONTENT(_csl_phase, _csl_period) \
187 (struct ieee802154_header_ie_csl_reduced) { \
188 .csl_phase = sys_cpu_to_le16(_csl_phase), \
189 .csl_period = sys_cpu_to_le16(_csl_period), \
190 }
191
192#define IEEE802154_DEFINE_HEADER_IE_CSL_FULL_CONTENT(_csl_phase, _csl_period, \
193 _csl_rendezvous_time) \
194 (struct ieee802154_header_ie_csl_full) { \
195 .csl_phase = sys_cpu_to_le16(_csl_phase), \
196 .csl_period = sys_cpu_to_le16(_csl_period), \
197 .csl_rendezvous_time = sys_cpu_to_le16(_csl_rendezvous_time), \
198 }
199
200#define IEEE802154_HEADER_IE_TIME_CORRECTION_NACK 0x8000
201#define IEEE802154_HEADER_IE_TIME_CORRECTION_MASK 0x0fff
202#define IEEE802154_HEADER_IE_TIME_CORRECTION_SIGN_BIT_MASK 0x0800
203
204#define IEEE802154_DEFINE_HEADER_IE_TIME_CORRECTION_CONTENT(_ack, _time_correction_us) \
205 (struct ieee802154_header_ie_time_correction) { \
206 .time_sync_info = sys_cpu_to_le16( \
207 (!(_ack) * IEEE802154_HEADER_IE_TIME_CORRECTION_NACK) | \
208 ((_time_correction_us) & IEEE802154_HEADER_IE_TIME_CORRECTION_MASK)), \
209 }
230#define IEEE802154_DEFINE_HEADER_IE_VENDOR_SPECIFIC(_vendor_oui, _vendor_specific_info, \
231 _vendor_specific_info_len) \
232 IEEE802154_DEFINE_HEADER_IE(IEEE802154_HEADER_IE_ELEMENT_ID_VENDOR_SPECIFIC_IE, \
233 IEEE802154_DEFINE_HEADER_IE_VENDOR_SPECIFIC_CONTENT_LEN( \
234 _vendor_specific_info_len), \
235 IEEE802154_DEFINE_HEADER_IE_VENDOR_SPECIFIC_CONTENT( \
236 _vendor_oui, _vendor_specific_info), \
237 vendor_specific)
238
254#define IEEE802154_DEFINE_HEADER_IE_CSL_REDUCED(_csl_phase, _csl_period) \
255 IEEE802154_DEFINE_HEADER_IE( \
256 IEEE802154_HEADER_IE_ELEMENT_ID_CSL_IE, \
257 sizeof(struct ieee802154_header_ie_csl_reduced), \
258 IEEE802154_DEFINE_HEADER_IE_CSL_REDUCED_CONTENT(_csl_phase, _csl_period), \
259 csl.reduced)
260
278#define IEEE802154_DEFINE_HEADER_IE_CSL_FULL(_csl_phase, _csl_period, _csl_rendezvous_time) \
279 IEEE802154_DEFINE_HEADER_IE(IEEE802154_HEADER_IE_ELEMENT_ID_CSL_IE, \
280 sizeof(struct ieee802154_header_ie_csl_full), \
281 IEEE802154_DEFINE_HEADER_IE_CSL_FULL_CONTENT( \
282 _csl_phase, _csl_period, _csl_rendezvous_time), \
283 csl.full)
284
301#define IEEE802154_DEFINE_HEADER_IE_TIME_CORRECTION(_ack, _time_correction_us) \
302 IEEE802154_DEFINE_HEADER_IE( \
303 IEEE802154_HEADER_IE_ELEMENT_ID_TIME_CORRECTION_IE, \
304 sizeof(struct ieee802154_header_ie_time_correction), \
305 IEEE802154_DEFINE_HEADER_IE_TIME_CORRECTION_CONTENT(_ack, _time_correction_us), \
306 time_correction)
307
316static inline int16_t
318{
319 if (ie->time_sync_info & IEEE802154_HEADER_IE_TIME_CORRECTION_SIGN_BIT_MASK) {
320 /* Negative integer */
321 return (int16_t)ie->time_sync_info | ~IEEE802154_HEADER_IE_TIME_CORRECTION_MASK;
322 }
323
324 /* Positive integer */
325 return (int16_t)ie->time_sync_info & IEEE802154_HEADER_IE_TIME_CORRECTION_MASK;
326}
327
334static inline void ieee802154_header_ie_set_element_id(struct ieee802154_header_ie *ie,
335 uint8_t element_id)
336{
337 ie->element_id_high = element_id >> 1U;
338 ie->element_id_low = element_id & 0x01;
339}
340
348static inline uint8_t ieee802154_header_ie_get_element_id(struct ieee802154_header_ie *ie)
349{
350 return (ie->element_id_high << 1U) | ie->element_id_low;
351}
352
354#define IEEE802154_TIME_CORRECTION_HEADER_IE_LEN \
355 (IEEE802154_HEADER_IE_HEADER_LENGTH + sizeof(struct ieee802154_header_ie_time_correction))
356
358#define IEEE802154_HEADER_TERMINATION_1_HEADER_IE_LEN IEEE802154_HEADER_IE_HEADER_LENGTH
359
366#endif /* ZEPHYR_INCLUDE_NET_IEEE802154_IE_H_ */
ieee802154_header_ie_element_id
Header Information Element IDs.
Definition ieee802154_ie.h:53
ieee802154_ie_type
Information Element Types.
Definition ieee802154_ie.h:42
static int16_t ieee802154_header_ie_get_time_correction_us(struct ieee802154_header_ie_time_correction *ie)
Retrieve the time correction value in microseconds from a Time Correction IE, see section 7....
Definition ieee802154_ie.h:317
static uint8_t ieee802154_header_ie_get_element_id(struct ieee802154_header_ie *ie)
Get the element ID of a header IE.
Definition ieee802154_ie.h:348
static void ieee802154_header_ie_set_element_id(struct ieee802154_header_ie *ie, uint8_t element_id)
Set the element ID of a header IE.
Definition ieee802154_ie.h:334
@ IEEE802154_HEADER_IE_ELEMENT_ID_RENDEZVOUS_TIME_IE
Rendezvous time IE.
Definition ieee802154_ie.h:57
@ IEEE802154_HEADER_IE_ELEMENT_ID_TIME_CORRECTION_IE
Time correction IE.
Definition ieee802154_ie.h:58
@ IEEE802154_HEADER_IE_ELEMENT_ID_HEADER_TERMINATION_1
Header termination 1.
Definition ieee802154_ie.h:59
@ IEEE802154_HEADER_IE_ELEMENT_ID_CSL_IE
CSL IE.
Definition ieee802154_ie.h:55
@ IEEE802154_HEADER_IE_ELEMENT_ID_HEADER_TERMINATION_2
Header termination 2.
Definition ieee802154_ie.h:60
@ IEEE802154_HEADER_IE_ELEMENT_ID_VENDOR_SPECIFIC_IE
Vendor specific IE.
Definition ieee802154_ie.h:54
@ IEEE802154_HEADER_IE_ELEMENT_ID_RIT_IE
RIT IE.
Definition ieee802154_ie.h:56
@ IEEE802154_IE_TYPE_HEADER
Header type.
Definition ieee802154_ie.h:43
@ IEEE802154_IE_TYPE_PAYLOAD
Payload type.
Definition ieee802154_ie.h:44
Buffer management.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT16_TYPE__ int16_t
Definition stdint.h:73
Full CSL IE, see section 7.4.2.3.
Definition ieee802154_ie.h:77
uint16_t csl_phase
CSL phase.
Definition ieee802154_ie.h:78
uint16_t csl_period
CSL period.
Definition ieee802154_ie.h:79
uint16_t csl_rendezvous_time
Rendezvous time.
Definition ieee802154_ie.h:80
Reduced CSL IE, see section 7.4.2.3.
Definition ieee802154_ie.h:84
uint16_t csl_phase
CSL phase.
Definition ieee802154_ie.h:85
uint16_t csl_period
CSL period.
Definition ieee802154_ie.h:86
Generic CSL IE, see section 7.4.2.3.
Definition ieee802154_ie.h:90
struct ieee802154_header_ie_csl_reduced reduced
CSL reduced information.
Definition ieee802154_ie.h:95
struct ieee802154_header_ie_csl_full full
CSL full information.
Definition ieee802154_ie.h:93
Full Rendezvous Time IE, see section 7.4.2.6 (macCslInterval is nonzero).
Definition ieee802154_ie.h:110
uint16_t rendezvous_time
Rendezvous time.
Definition ieee802154_ie.h:111
uint16_t wakeup_interval
Wakeup interval.
Definition ieee802154_ie.h:112
Reduced Rendezvous Time IE, see section 7.4.2.6 (macCslInterval is zero).
Definition ieee802154_ie.h:119
uint16_t rendezvous_time
Rendezvous time.
Definition ieee802154_ie.h:120
Rendezvous Time IE, see section 7.4.2.6.
Definition ieee802154_ie.h:124
struct ieee802154_header_ie_rendezvous_time_reduced reduced
Rendezvous time reduced information.
Definition ieee802154_ie.h:129
struct ieee802154_header_ie_rendezvous_time_full full
Rendezvous time full information.
Definition ieee802154_ie.h:127
RIT IE, see section 7.4.2.4.
Definition ieee802154_ie.h:100
uint8_t number_of_repeat_listen
Number of Repeat Listen.
Definition ieee802154_ie.h:102
uint16_t repeat_listen_interval
Repeat listen interval.
Definition ieee802154_ie.h:103
uint8_t time_to_first_listen
Time to First Listen.
Definition ieee802154_ie.h:101
Time Correction IE, see section 7.4.2.7.
Definition ieee802154_ie.h:134
uint16_t time_sync_info
Time synchronization information.
Definition ieee802154_ie.h:135
Vendor Specific Header IE, see section 7.4.2.3.
Definition ieee802154_ie.h:69
uint8_t vendor_oui[IEEE802154_VENDOR_SPECIFIC_IE_OUI_LEN]
Vendor OUI.
Definition ieee802154_ie.h:71
uint8_t * vendor_specific_info
Vendor specific information.
Definition ieee802154_ie.h:73
Byte order helpers.