Contiki 3.x
frame802154e-ie.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, SICS Swedish ICT.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * IEEE 802.15.4e Information Element (IE) creation and parsing.
36  * \author
37  * Simon Duquennoy <simonduq@sics.se>
38  */
39 
40 #include <string.h>
42 
43 #define DEBUG DEBUG_NONE
44 #include "net/net-debug.h"
45 
46 /* c.f. IEEE 802.15.4e Table 4b */
47 enum ieee802154e_header_ie_id {
48  HEADER_IE_LE_CSL = 0x1a,
49  HEADER_IE_LE_RIT,
50  HEADER_IE_DSME_PAN_DESCRIPTOR,
51  HEADER_IE_RZ_TIME,
52  HEADER_IE_ACK_NACK_TIME_CORRECTION,
53  HEADER_IE_GACK,
54  HEADER_IE_LOW_LATENCY_NETWORK_INFO,
55  HEADER_IE_LIST_TERMINATION_1 = 0x7e,
56  HEADER_IE_LIST_TERMINATION_2 = 0x7f,
57 };
58 
59 /* c.f. IEEE 802.15.4e Table 4c */
60 enum ieee802154e_payload_ie_id {
61  PAYLOAD_IE_ESDU = 0,
62  PAYLOAD_IE_MLME,
63  PAYLOAD_IE_LIST_TERMINATION = 0xf,
64 };
65 
66 /* c.f. IEEE 802.15.4e Table 4d */
67 enum ieee802154e_mlme_short_subie_id {
68  MLME_SHORT_IE_TSCH_SYNCHRONIZATION = 0x1a,
69  MLME_SHORT_IE_TSCH_SLOFTRAME_AND_LINK,
70  MLME_SHORT_IE_TSCH_TIMESLOT,
71  MLME_SHORT_IE_TSCH_HOPPING_TIMING,
72  MLME_SHORT_IE_TSCH_EB_FILTER,
73  MLME_SHORT_IE_TSCH_MAC_METRICS_1,
74  MLME_SHORT_IE_TSCH_MAC_METRICS_2,
75 };
76 
77 /* c.f. IEEE 802.15.4e Table 4e */
78 enum ieee802154e_mlme_long_subie_id {
79  MLME_LONG_IE_TSCH_CHANNEL_HOPPING_SEQUENCE = 0x9,
80 };
81 
82 #define WRITE16(buf, val) \
83  do { ((uint8_t *)(buf))[0] = (val) & 0xff; \
84  ((uint8_t *)(buf))[1] = ((val) >> 8) & 0xff; } while(0);
85 
86 #define READ16(buf, var) \
87  (var) = ((uint8_t *)(buf))[0] | ((uint8_t *)(buf))[1] << 8
88 
89 /* Create a header IE 2-byte descriptor */
90 static void
91 create_header_ie_descriptor(uint8_t *buf, uint8_t element_id, int ie_len)
92 {
93  uint16_t ie_desc;
94  /* Header IE descriptor: b0-6: len, b7-14: element id:, b15: type: 0 */
95  ie_desc = (ie_len & 0x7f) + ((element_id & 0xff) << 7);
96  WRITE16(buf, ie_desc);
97 }
98 
99 /* Create a payload IE 2-byte descriptor */
100 static void
101 create_payload_ie_descriptor(uint8_t *buf, uint8_t group_id, int ie_len)
102 {
103  uint16_t ie_desc;
104  /* MLME Long IE descriptor: b0-10: len, b11-14: group id:, b15: type: 1 */
105  ie_desc = (ie_len & 0x07ff) + ((group_id & 0x0f) << 11) + (1 << 15);
106  WRITE16(buf, ie_desc);
107 }
108 
109 /* Create a MLME short IE 2-byte descriptor */
110 static void
111 create_mlme_short_ie_descriptor(uint8_t *buf, uint8_t sub_id, int ie_len)
112 {
113  uint16_t ie_desc;
114  /* MLME Short IE descriptor: b0-7: len, b8-14: sub id:, b15: type: 0 */
115  ie_desc = (ie_len & 0xff) + ((sub_id & 0x7f) << 8);
116  WRITE16(buf, ie_desc);
117 }
118 
119 /* Create a MLME long IE 2-byte descriptor */
120 static void
121 create_mlme_long_ie_descriptor(uint8_t *buf, uint8_t sub_id, int ie_len)
122 {
123  uint16_t ie_desc;
124  /* MLME Long IE descriptor: b0-10: len, b11-14: sub id:, b15: type: 1 */
125  ie_desc = (ie_len & 0x07ff) + ((sub_id & 0x0f) << 11) + (1 << 15);
126  WRITE16(buf, ie_desc);
127 }
128 
129 /* Header IE. ACK/NACK time correction. Used in enhanced ACKs */
130 int
132  struct ieee802154_ies *ies)
133 {
134  int ie_len = 2;
135  if(len >= 2 + ie_len && ies != NULL) {
136  int16_t drift_us;
137  uint16_t time_sync_field;
138  drift_us = ies->ie_time_correction;
139  time_sync_field = drift_us & 0x0fff;
140  if(ies->ie_is_nack) {
141  time_sync_field |= 0x8000;
142  }
143  WRITE16(buf+2, time_sync_field);
144  create_header_ie_descriptor(buf, HEADER_IE_ACK_NACK_TIME_CORRECTION, ie_len);
145  return 2 + ie_len;
146  } else {
147  return -1;
148  }
149 }
150 
151 /* Header IE. List termination 1 (Signals the end of the Header IEs when
152  * followed by payload IEs) */
153 int
154 frame80215e_create_ie_header_list_termination_1(uint8_t *buf, int len,
155  struct ieee802154_ies *ies)
156 {
157  int ie_len = 0;
158  if(len >= 2 + ie_len && ies != NULL) {
159  create_header_ie_descriptor(buf, HEADER_IE_LIST_TERMINATION_1, 0);
160  return 2 + ie_len;
161  } else {
162  return -1;
163  }
164 }
165 
166 /* Header IE. List termination 2 (Signals the end of the Header IEs when
167  * followed by an unformatted payload) */
168 int
169 frame80215e_create_ie_header_list_termination_2(uint8_t *buf, int len,
170  struct ieee802154_ies *ies)
171 {
172  int ie_len = 0;
173  if(len >= 2 + ie_len && ies != NULL) {
174  create_header_ie_descriptor(buf, HEADER_IE_LIST_TERMINATION_2, 0);
175  return 2 + ie_len;
176  } else {
177  return -1;
178  }
179 }
180 
181 /* Payload IE. List termination */
182 int
183 frame80215e_create_ie_payload_list_termination(uint8_t *buf, int len,
184  struct ieee802154_ies *ies)
185 {
186  int ie_len = 0;
187  if(len >= 2 + ie_len && ies != NULL) {
188  create_payload_ie_descriptor(buf, PAYLOAD_IE_LIST_TERMINATION, 0);
189  return 2 + ie_len;
190  } else {
191  return -1;
192  }
193 }
194 
195 /* Payload IE. MLME. Used to nest sub-IEs */
196 int
197 frame80215e_create_ie_mlme(uint8_t *buf, int len,
198  struct ieee802154_ies *ies)
199 {
200  int ie_len = 0;
201  if(len >= 2 + ie_len && ies != NULL) {
202  /* The length of the outer MLME IE is the total length of sub-IEs */
203  create_payload_ie_descriptor(buf, PAYLOAD_IE_MLME, ies->ie_mlme_len);
204  return 2 + ie_len;
205  } else {
206  return -1;
207  }
208 }
209 
210 /* MLME sub-IE. TSCH synchronization. Used in EBs: ASN and join priority */
211 int
212 frame80215e_create_ie_tsch_synchronization(uint8_t *buf, int len,
213  struct ieee802154_ies *ies)
214 {
215  int ie_len = 6;
216  if(len >= 2 + ie_len && ies != NULL) {
217  buf[2] = ies->ie_asn.ls4b;
218  buf[3] = ies->ie_asn.ls4b >> 8;
219  buf[4] = ies->ie_asn.ls4b >> 16;
220  buf[5] = ies->ie_asn.ls4b >> 24;
221  buf[6] = ies->ie_asn.ms1b;
222  buf[7] = ies->ie_join_priority;
223  create_mlme_short_ie_descriptor(buf, MLME_SHORT_IE_TSCH_SYNCHRONIZATION, ie_len);
224  return 2 + ie_len;
225  } else {
226  return -1;
227  }
228 }
229 
230 /* MLME sub-IE. TSCH slotframe and link. Used in EBs: initial schedule */
231 int
232 frame80215e_create_ie_tsch_slotframe_and_link(uint8_t *buf, int len,
233  struct ieee802154_ies *ies)
234 {
235  if(ies != NULL) {
236  int i;
237  int num_slotframes = ies->ie_tsch_slotframe_and_link.num_slotframes;
238  int num_links = ies->ie_tsch_slotframe_and_link.num_links;
239  int ie_len = 1 + num_slotframes * (4 + 5 * num_links);
240  if(num_slotframes > 1 || num_links > FRAME802154E_IE_MAX_LINKS
241  || len < 2 + ie_len) {
242  /* We support only 0 or 1 slotframe in this IE and a predefined maximum number of links */
243  return -1;
244  }
245  /* Insert IE */
246  buf[2] = num_slotframes;
247  /* Insert slotframe */
248  if(num_slotframes == 1) {
249  buf[2 + 1] = ies->ie_tsch_slotframe_and_link.slotframe_handle;
250  WRITE16(buf + 2 + 2, ies->ie_tsch_slotframe_and_link.slotframe_size);
251  buf[2 + 4] = num_links;
252  /* Loop over links */
253  for(i = 0; i < num_links; i++) {
254  /* Insert links */
255  WRITE16(buf + 2 + 5 + i * 5, ies->ie_tsch_slotframe_and_link.links[i].timeslot);
256  WRITE16(buf + 2 + 5 + i * 5 + 2, ies->ie_tsch_slotframe_and_link.links[i].channel_offset);
257  buf[2 + 5 + i * 5 + 4] = ies->ie_tsch_slotframe_and_link.links[i].link_options;
258  }
259  }
260  create_mlme_short_ie_descriptor(buf, MLME_SHORT_IE_TSCH_SLOFTRAME_AND_LINK, ie_len);
261  return 2 + ie_len;
262  } else {
263  return -1;
264  }
265 }
266 
267 /* MLME sub-IE. TSCH timeslot. Used in EBs: timeslot template (timing) */
268 int
269 frame80215e_create_ie_tsch_timeslot(uint8_t *buf, int len,
270  struct ieee802154_ies *ies)
271 {
272  int ie_len;
273  if(ies == NULL) {
274  return -1;
275  }
276  /* Only ID if ID == 0, else full timing description */
277  ie_len = ies->ie_tsch_timeslot_id == 0 ? 1 : 25;
278  if(len >= 2 + ie_len) {
279  buf[2] = ies->ie_tsch_timeslot_id;
280  if(ies->ie_tsch_timeslot_id != 0) {
281  int i;
282  for(i = 0; i < tsch_ts_elements_count; i++) {
283  WRITE16(buf + 3 + 2 * i, ies->ie_tsch_timeslot[i]);
284  }
285  }
286  create_mlme_short_ie_descriptor(buf, MLME_SHORT_IE_TSCH_TIMESLOT, ie_len);
287  return 2 + ie_len;
288  } else {
289  return -1;
290  }
291 }
292 
293 /* MLME sub-IE. TSCH channel hopping sequence. Used in EBs: hopping sequence */
294 int
295 frame80215e_create_ie_tsch_channel_hopping_sequence(uint8_t *buf, int len,
296  struct ieee802154_ies *ies)
297 {
298  int ie_len;
299  if(ies == NULL || ies->ie_hopping_sequence_len > sizeof(ies->ie_hopping_sequence_list)) {
300  return -1;
301  }
302  ie_len = ies->ie_channel_hopping_sequence_id == 0 ? 1 : 12 + ies->ie_hopping_sequence_len;
303  if(len >= 2 + ie_len && ies != NULL) {
304  buf[2] = ies->ie_channel_hopping_sequence_id;
305  buf[3] = 0; /* channel page */
306  WRITE16(buf + 4, 0); /* number of channels */
307  WRITE16(buf + 6, 0); /* phy configuration */
308  WRITE16(buf + 8, 0);
309  /* Extended bitmap. Size: 0 */
310  WRITE16(buf + 10, ies->ie_hopping_sequence_len); /* sequence len */
311  memcpy(buf + 12, ies->ie_hopping_sequence_list, ies->ie_hopping_sequence_len); /* sequence list */
312  WRITE16(buf + 12 + ies->ie_hopping_sequence_len, 0); /* current hop */
313  create_mlme_long_ie_descriptor(buf, MLME_LONG_IE_TSCH_CHANNEL_HOPPING_SEQUENCE, ie_len);
314  return 2 + ie_len;
315  } else {
316  return -1;
317  }
318 }
319 
320 /* Parse a header IE */
321 static int
322 frame802154e_parse_header_ie(const uint8_t *buf, int len,
323  uint8_t element_id, struct ieee802154_ies *ies)
324 {
325  switch(element_id) {
326  case HEADER_IE_ACK_NACK_TIME_CORRECTION:
327  if(len == 2) {
328  if(ies != NULL) {
329  /* If the originator was a time source neighbor, the receiver adjust
330  * its own clock by incorporating the received drift correction */
331  uint16_t time_sync_field = 0;
332  int16_t drift_us = 0;
333  /* Extract drift correction from Sync-IE, cast from 12 to 16-bit,
334  * and convert it to RTIMER ticks.
335  * See page 88 in IEEE Std 802.15.4e-2012. */
336  READ16(buf, time_sync_field);
337  /* First extract NACK */
338  ies->ie_is_nack = (time_sync_field & (uint16_t)0x8000) ? 1 : 0;
339  /* Then cast from 12 to 16 bit signed */
340  if(time_sync_field & 0x0800) { /* Negative integer */
341  drift_us = time_sync_field | 0xf000;
342  } else { /* Positive integer */
343  drift_us = time_sync_field & 0x0fff;
344  }
345  /* Convert to RTIMER ticks */
346  ies->ie_time_correction = drift_us;
347  }
348  return len;
349  }
350  break;
351  }
352  return -1;
353 }
354 
355 /* Parse a MLME short IE */
356 static int
357 frame802154e_parse_mlme_short_ie(const uint8_t *buf, int len,
358  uint8_t sub_id, struct ieee802154_ies *ies)
359 {
360  switch(sub_id) {
361  case MLME_SHORT_IE_TSCH_SLOFTRAME_AND_LINK:
362  if(len >= 1) {
363  int i;
364  int num_slotframes = buf[0];
365  int num_links = buf[4];
366  if(num_slotframes == 0) {
367  return len;
368  }
369  if(num_slotframes <= 1 && num_links <= FRAME802154E_IE_MAX_LINKS
370  && len == 1 + num_slotframes * (4 + 5 * num_links)) {
371  if(ies != NULL) {
372  /* We support only 0 or 1 slotframe in this IE and a predefined maximum number of links */
373  ies->ie_tsch_slotframe_and_link.num_slotframes = buf[0];
374  ies->ie_tsch_slotframe_and_link.slotframe_handle = buf[1];
375  READ16(buf + 2, ies->ie_tsch_slotframe_and_link.slotframe_size);
376  ies->ie_tsch_slotframe_and_link.num_links = buf[4];
377  for(i = 0; i < num_links; i++) {
378  READ16(buf + 5 + i * 5, ies->ie_tsch_slotframe_and_link.links[i].timeslot);
379  READ16(buf + 5 + i * 5 + 2, ies->ie_tsch_slotframe_and_link.links[i].channel_offset);
380  ies->ie_tsch_slotframe_and_link.links[i].link_options = buf[5 + i * 5 + 4];
381  }
382  }
383  return len;
384  }
385  }
386  break;
387  case MLME_SHORT_IE_TSCH_SYNCHRONIZATION:
388  if(len == 6) {
389  if(ies != NULL) {
390  ies->ie_asn.ls4b = (uint32_t)buf[0];
391  ies->ie_asn.ls4b |= (uint32_t)buf[1] << 8;
392  ies->ie_asn.ls4b |= (uint32_t)buf[2] << 16;
393  ies->ie_asn.ls4b |= (uint32_t)buf[3] << 24;
394  ies->ie_asn.ms1b = (uint8_t)buf[4];
395  ies->ie_join_priority = (uint8_t)buf[5];
396  }
397  return len;
398  }
399  break;
400  case MLME_SHORT_IE_TSCH_TIMESLOT:
401  if(len == 1 || len == 25) {
402  if(ies != NULL) {
403  ies->ie_tsch_timeslot_id = buf[0];
404  if(len == 25) {
405  int i;
406  for(i = 0; i < tsch_ts_elements_count; i++) {
407  READ16(buf+1+2*i, ies->ie_tsch_timeslot[i]);
408  }
409  }
410  }
411  return len;
412  }
413  break;
414  }
415  return -1;
416 }
417 
418 /* Parse a MLME long IE */
419 static int
420 frame802154e_parse_mlme_long_ie(const uint8_t *buf, int len,
421  uint8_t sub_id, struct ieee802154_ies *ies)
422 {
423  switch(sub_id) {
424  case MLME_LONG_IE_TSCH_CHANNEL_HOPPING_SEQUENCE:
425  if(len > 0) {
426  if(ies != NULL) {
427  ies->ie_channel_hopping_sequence_id = buf[0];
428  if(len > 1) {
429  READ16(buf+8, ies->ie_hopping_sequence_len); /* sequence len */
430  if(ies->ie_hopping_sequence_len <= sizeof(ies->ie_hopping_sequence_list)
431  && len == 12 + ies->ie_hopping_sequence_len) {
432  memcpy(ies->ie_hopping_sequence_list, buf+10, ies->ie_hopping_sequence_len); /* sequence list */
433  }
434  }
435  }
436  return len;
437  }
438  break;
439  }
440  return -1;
441 }
442 
443 /* Parse all IEEE 802.15.4e Information Elements (IE) from a frame */
444 int
445 frame802154e_parse_information_elements(const uint8_t *buf, uint8_t buf_size,
446  struct ieee802154_ies *ies)
447 {
448  const uint8_t *start = buf;
449  uint16_t ie_desc;
450  uint8_t type;
451  uint8_t id;
452  uint16_t len = 0;
453  int nested_mlme_len = 0;
454  enum {PARSING_HEADER_IE, PARSING_PAYLOAD_IE, PARSING_MLME_SUBIE} parsing_state;
455 
456  if(ies == NULL) {
457  return -1;
458  }
459 
460  /* Always look for a header IE first (at least "list termination 1") */
461  parsing_state = PARSING_HEADER_IE;
462  ies->ie_payload_ie_offset = 0;
463 
464  /* Loop over all IEs */
465  while(buf_size > 0) {
466  if(buf_size < 2) { /* Not enough space for IE descriptor */
467  return -1;
468  }
469  READ16(buf, ie_desc);
470  buf_size -= 2;
471  buf += 2;
472  type = ie_desc & 0x8000 ? 1 : 0; /* b15 */
473  PRINTF("frame802154e: ie type %u, current state %u\n", type, parsing_state);
474 
475  switch(parsing_state) {
476  case PARSING_HEADER_IE:
477  if(type != 0) {
478  PRINTF("frame802154e: wrong type %04x\n", ie_desc);
479  return -1;
480  }
481  /* Header IE: 2 bytes descriptor, c.f. fig 48n in IEEE 802.15.4e */
482  len = ie_desc & 0x007f; /* b0-b6 */
483  id = (ie_desc & 0x7f80) >> 7; /* b7-b14 */
484  PRINTF("frame802154e: header ie len %u id %x\n", len, id);
485  switch(id) {
486  case HEADER_IE_LIST_TERMINATION_1:
487  if(len == 0) {
488  /* End of payload IE list, now expect payload IEs */
489  parsing_state = PARSING_PAYLOAD_IE;
490  ies->ie_payload_ie_offset = buf - start; /* Save IE header len */
491  PRINTF("frame802154e: list termination 1, look for payload IEs\n");
492  } else {
493  PRINTF("frame802154e: list termination 1, wrong len %u\n", len);
494  return -1;
495  }
496  break;
497  case HEADER_IE_LIST_TERMINATION_2:
498  /* End of IE parsing */
499  if(len == 0) {
500  ies->ie_payload_ie_offset = buf - start; /* Save IE header len */
501  PRINTF("frame802154e: list termination 2\n");
502  return buf + len - start;
503  } else {
504  PRINTF("frame802154e: list termination 2, wrong len %u\n", len);
505  return -1;
506  }
507  default:
508  if(len > buf_size || frame802154e_parse_header_ie(buf, len, id, ies) == -1) {
509  PRINTF("frame802154e: failed to parse\n");
510  return -1;
511  }
512  break;
513  }
514  break;
515  case PARSING_PAYLOAD_IE:
516  if(type != 1) {
517  PRINTF("frame802154e: wrong type %04x\n", ie_desc);
518  return -1;
519  }
520  /* Payload IE: 2 bytes descriptor, c.f. fig 48o in IEEE 802.15.4e */
521  len = ie_desc & 0x7ff; /* b0-b10 */
522  id = (ie_desc & 0x7800) >> 11; /* b11-b14 */
523  PRINTF("frame802154e: payload ie len %u id %x\n", len, id);
524  switch(id) {
525  case PAYLOAD_IE_MLME:
526  /* Now expect 'len' bytes of MLME sub-IEs */
527  parsing_state = PARSING_MLME_SUBIE;
528  nested_mlme_len = len;
529  len = 0; /* Reset len as we want to read subIEs and not jump over them */
530  PRINTF("frame802154e: entering MLME ie with len %u\n", nested_mlme_len);
531  break;
532  case PAYLOAD_IE_LIST_TERMINATION:
533  PRINTF("frame802154e: payload ie list termination %u\n", len);
534  return (len == 0) ? buf + len - start : -1;
535  default:
536  PRINTF("frame802154e: non-supported payload ie\n");
537  return -1;
538  }
539  break;
540  case PARSING_MLME_SUBIE:
541  /* MLME sub-IE: 2 bytes descriptor, c.f. fig 48q in IEEE 802.15.4e */
542  /* type == 0 means short sub-IE, type == 1 means long sub-IE */
543  if(type == 0) {
544  /* Short sub-IE, c.f. fig 48r in IEEE 802.15.4e */
545  len = ie_desc & 0x00ff; /* b0-b7 */
546  id = (ie_desc & 0x7f00) >> 8; /* b8-b14 */
547  PRINTF("frame802154e: short mlme ie len %u id %x\n", len, id);
548  if(len > buf_size || frame802154e_parse_mlme_short_ie(buf, len, id, ies) == -1) {
549  PRINTF("frame802154e: failed to parse ie\n");
550  return -1;
551  }
552  } else {
553  /* Long sub-IE, c.f. fig 48s in IEEE 802.15.4e */
554  len = ie_desc & 0x7ff; /* b0-b10 */
555  id = (ie_desc & 0x7800) >> 11; /* b11-b14 */
556  PRINTF("frame802154e: long mlme ie len %u id %x\n", len, id);
557  if(len > buf_size || frame802154e_parse_mlme_long_ie(buf, len, id, ies) == -1) {
558  PRINTF("frame802154e: failed to parse ie\n");
559  return -1;
560  }
561  }
562  /* Update remaining nested MLME len */
563  nested_mlme_len -= 2 + len;
564  if(nested_mlme_len < 0) {
565  PRINTF("frame802154e: found more sub-IEs than initially advertised\n");
566  /* We found more sub-IEs than initially advertised */
567  return -1;
568  }
569  if(nested_mlme_len == 0) {
570  PRINTF("frame802154e: end of MLME IE parsing\n");
571  /* End of IE parsing, look for another payload IE */
572  parsing_state = PARSING_PAYLOAD_IE;
573  }
574  break;
575  }
576  buf += len;
577  buf_size -= len;
578  }
579 
580  if(parsing_state == PARSING_HEADER_IE) {
581  ies->ie_payload_ie_offset = buf - start; /* Save IE header len */
582  }
583 
584  return buf - start;
585 }
static void start(void)
Start measurement.
int frame80215e_create_ie_header_ack_nack_time_correction(uint8_t *buf, int len, struct ieee802154_ies *ies)
Insert various Information Elements.
A set of debugging macros for the netstack
#define NULL
The null pointer.
IEEE 802.15.4e Information Element (IE) creation and parsing.