Contiki-NG
roll-tm.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Loughborough University - Computer Science
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  * \addtogroup roll-tm
34  * @{
35  */
36 /**
37  * \file
38  * Implementation of the ROLL TM multicast engine
39  * \author
40  * George Oikonomou - <oikonomou@users.sourceforge.net>
41  */
42 
43 #include "contiki.h"
44 #include "contiki-lib.h"
45 #include "contiki-net.h"
46 #include "net/ipv6/uip-icmp6.h"
49 #include "dev/watchdog.h"
50 #include <string.h>
51 
52 #define DEBUG DEBUG_NONE
53 #include "net/ipv6/uip-debug.h"
54 
55 #define TRICKLE_VERBOSE 0
56 
57 #if DEBUG && TRICKLE_VERBOSE
58 #define VERBOSE_PRINTF(...) PRINTF(__VA_ARGS__)
59 #define VERBOSE_PRINT_SEED(s) PRINT_SEED(s)
60 #else
61 #define VERBOSE_PRINTF(...)
62 #define VERBOSE_PRINT_SEED(...)
63 #endif
64 
65 /*---------------------------------------------------------------------------*/
66 /* Data Representation */
67 /*---------------------------------------------------------------------------*/
68 #if ROLL_TM_SHORT_SEEDS
69 typedef union seed_id_u {
70  uint8_t u8[2];
71  uint16_t id; /* Big Endian */
72 } seed_id_t;
73 
74 #define seed_is_null(s) ((s)->id == 0)
75 #define PRINT_SEED(s) PRINTF("0x%02x%02x", (s)->u8[0], (s)->u8[1])
76 #else /* ROLL_TM_SHORT_SEEDS */
77 typedef uip_ip6addr_t seed_id_t;
78 
79 #define seed_is_null(s) uip_is_addr_unspecified(s)
80 #define PRINT_SEED(s) PRINT6ADDR(s)
81 #endif /* ROLL_TM_SHORT_SEEDS */
82 #define seed_id_cmp(a, b) (memcmp((a), (b), sizeof(seed_id_t)) == 0)
83 #define seed_id_cpy(a, b) (memcpy((a), (b), sizeof(seed_id_t)))
84 
85 /* Trickle Timers */
86 struct trickle_param {
87  clock_time_t i_min; /* Clock ticks */
88  clock_time_t t_start; /* Start of the interval (absolute clock_time) */
89  clock_time_t t_end; /* End of the interval (absolute clock_time) */
90  clock_time_t t_next; /* Clock ticks, randomised in [I/2, I) */
91  clock_time_t t_last_trigger;
92  struct ctimer ct;
93  uint8_t i_current; /* Current doublings from i_min */
94  uint8_t i_max; /* Max number of doublings */
95  uint8_t k; /* Redundancy Constant */
96  uint8_t t_active; /* Units of Imax */
97  uint8_t t_dwell; /* Units of Imax */
98  uint8_t c; /* Consistency Counter */
99  uint8_t inconsistency;
100 };
101 
102 /**
103  * \brief Convert a timer to a sane clock_time_t value after d doublings
104  * m is a value of Imin, d is a number of doublings
105  * Careful of overflows
106  */
107 #define TRICKLE_TIME(m, d) ((clock_time_t)((m) << (d)))
108 
109 /**
110  * \brief Convert Imax from number of doublings to clock_time_t units for
111  * trickle_param t. Again, watch out for overflows */
112 #define TRICKLE_IMAX(t) ((uint32_t)((t)->i_min << (t)->i_max))
113 
114 /**
115  * \brief Convert Tactive for a trickle timer to a sane clock_time_t value
116  * t is a pointer to the timer
117  * Careful of overflows
118  */
119 #define TRICKLE_ACTIVE(t) ((uint32_t)(TRICKLE_IMAX(t) * t->t_active))
120 
121 /**
122  * \brief Convert Tdwell for a trickle timer to a sane clock_time_t value
123  * t is a pointer to the timer
124  * Careful of overflows
125  */
126 #define TRICKLE_DWELL(t) ((uint32_t)(TRICKLE_IMAX(t) * t->t_dwell))
127 
128 /**
129  * \brief Check if suppression is enabled for trickle_param t
130  * t is a pointer to the timer
131  */
132 #define SUPPRESSION_ENABLED(t) ((t)->k != ROLL_TM_INFINITE_REDUNDANCY)
133 
134 /**
135  * \brief Check if suppression is disabled for trickle_param t
136  * t is a pointer to the timer
137  */
138 #define SUPPRESSION_DISABLED(t) ((t)->k == ROLL_TM_INFINITE_REDUNDANCY)
139 
140 /**
141  * \brief Init trickle_timer[m]
142  */
143 #define TIMER_CONFIGURE(m) do { \
144  t[m].i_min = ROLL_TM_IMIN_##m; \
145  t[m].i_max = ROLL_TM_IMAX_##m; \
146  t[m].k = ROLL_TM_K_##m; \
147  t[m].t_active = ROLL_TM_T_ACTIVE_##m; \
148  t[m].t_dwell = ROLL_TM_T_DWELL_##m; \
149  t[m].t_last_trigger = clock_time(); \
150 } while(0)
151 /*---------------------------------------------------------------------------*/
152 /* Sequence Values and Serial Number Arithmetic
153  *
154  * Sequence Number Comparisons as per RFC1982 "Serial Number Arithmetic"
155  * Our 'SERIAL_BITS' value is 15 here
156  *
157  * NOTE: There can be pairs of sequence numbers s1 and s2 with an undefined
158  * ordering. All three macros would evaluate as 0, as in:
159  * SEQ_VAL_IS_EQUAL(s1, s2) == 0 and
160  * SEQ_VAL_IS_GT(s1, s2) == 0 and
161  * SEQ_VAL_IS_LT(s1, s2) == 0
162  *
163  * This is not a bug of this implementation, it's an RFC design choice
164  */
165 
166 /**
167  * \brief s1 is said to be equal s2 iif SEQ_VAL_IS_EQ(s1, s2) == 1
168  */
169 #define SEQ_VAL_IS_EQ(i1, i2) ((i1) == (i2))
170 
171 /**
172  * \brief s1 is said to be less than s2 iif SEQ_VAL_IS_LT(s1, s2) == 1
173  */
174 #define SEQ_VAL_IS_LT(i1, i2) \
175  ( \
176  ((i1) != (i2)) && \
177  ((((i1) < (i2)) && ((int16_t)((i2) - (i1)) < 0x4000)) || \
178  (((i1) > (i2)) && ((int16_t)((i1) - (i2)) > 0x4000))) \
179  )
180 
181 /**
182  * \brief s1 is said to be greater than s2 iif SEQ_VAL_IS_LT(s1, s2) == 1
183  */
184 #define SEQ_VAL_IS_GT(i1, i2) \
185 ( \
186  ((i1) != (i2)) && \
187  ((((i1) < (i2)) && ((int16_t)((i2) - (i1)) > 0x4000)) || \
188  (((i1) > (i2)) && ((int16_t)((i1) - (i2)) < 0x4000))) \
189 )
190 
191 /**
192  * \brief Add n to s: (s + n) modulo (2 ^ SERIAL_BITS) => ((s + n) % 0x8000)
193  */
194 #define SEQ_VAL_ADD(s, n) (((s) + (n)) % 0x8000)
195 /*---------------------------------------------------------------------------*/
196 /* Sliding Windows */
197 struct sliding_window {
198  seed_id_t seed_id;
199  int16_t lower_bound; /* lolipop */
200  int16_t upper_bound; /* lolipop */
201  int16_t min_listed; /* lolipop */
202  uint8_t flags; /* Is used, Trickle param, Is listed */
203  uint8_t count;
204 };
205 
206 #define SLIDING_WINDOW_U_BIT 0x80 /* Is used */
207 #define SLIDING_WINDOW_M_BIT 0x40 /* Window trickle parametrization */
208 #define SLIDING_WINDOW_L_BIT 0x20 /* Current ICMP message lists us */
209 #define SLIDING_WINDOW_B_BIT 0x10 /* Used when updating bounds */
210 
211 /**
212  * \brief Is Occupied sliding window location w
213  * w: pointer to a sliding window
214  */
215 #define SLIDING_WINDOW_IS_USED(w) ((w)->flags & SLIDING_WINDOW_U_BIT)
216 
217 /**
218  * \brief Set 'Is Used' bit for window w
219  * w: pointer to a sliding window
220  */
221 #define SLIDING_WINDOW_IS_USED_SET(w) ((w)->flags |= SLIDING_WINDOW_U_BIT)
222 
223 /**
224  * \brief Clear 'Is Used' bit for window w
225  * w: pointer to a sliding window
226  */
227 #define SLIDING_WINDOW_IS_USED_CLR(w) ((w)->flags &= ~SLIDING_WINDOW_U_BIT)
228 #define window_free(w) SLIDING_WINDOW_IS_USED_CLR(w)
229 
230 /**
231  * \brief Set 'Is Seen' bit for window w
232  * w: pointer to a sliding window
233  */
234 #define SLIDING_WINDOW_LISTED_SET(w) ((w)->flags |= SLIDING_WINDOW_L_BIT)
235 
236 /**
237  * \brief Clear 'Is Seen' bit for window w
238  * w: pointer to a sliding window
239  */
240 #define SLIDING_WINDOW_LISTED_CLR(w) ((w)->flags &= ~SLIDING_WINDOW_L_BIT)
241 
242 /**
243  * \brief Is the sliding window at location w listed in current ICMP message?
244  * w: pointer to a sliding window
245  */
246 #define SLIDING_WINDOW_IS_LISTED(w) ((w)->flags & SLIDING_WINDOW_L_BIT)
247 
248 /**
249  * \brief Set M bit for window w
250  * w: pointer to a sliding window
251  */
252 #define SLIDING_WINDOW_M_SET(w) ((w)->flags |= SLIDING_WINDOW_M_BIT)
253 
254 /**
255  * \brief Clear M bit for window w
256  * w: pointer to a sliding window
257  */
258 #define SLIDING_WINDOW_M_CLR(w) ((w)->flags &= ~SLIDING_WINDOW_M_BIT)
259 
260 /**
261  * \brief Retrieve trickle parametrization for sliding window at location w
262  * w: pointer to a sliding window
263  */
264 #define SLIDING_WINDOW_GET_M(w) \
265  ((uint8_t)(((w)->flags & SLIDING_WINDOW_M_BIT) == SLIDING_WINDOW_M_BIT))
266 /*---------------------------------------------------------------------------*/
267 /* Multicast Packet Buffers */
268 struct mcast_packet {
269 #if ROLL_TM_SHORT_SEEDS
270  /* Short seeds are stored inside the message */
271  seed_id_t seed_id;
272 #endif
273  uint32_t active; /* Starts at 0 and increments */
274  uint32_t dwell; /* Starts at 0 and increments */
275  uint16_t buff_len;
276  uint16_t seq_val; /* host-byte order */
277  struct sliding_window *sw; /* Pointer to the SW this packet belongs to */
278  uint8_t flags; /* Is-Used, Must Send, Is Listed */
279  uint8_t buff[UIP_BUFSIZE - UIP_LLH_LEN];
280 };
281 
282 /* Flag bits */
283 #define MCAST_PACKET_U_BIT 0x80 /* Is Used */
284 #define MCAST_PACKET_S_BIT 0x20 /* Must Send Next Pass */
285 #define MCAST_PACKET_L_BIT 0x10 /* Is listed in ICMP message */
286 
287 /* Fetch a pointer to the Seed ID of a buffered message p */
288 #if ROLL_TM_SHORT_SEEDS
289 #define MCAST_PACKET_GET_SEED(p) ((seed_id_t *)&((p)->seed_id))
290 #else
291 #define MCAST_PACKET_GET_SEED(p) \
292  ((seed_id_t *)&((struct uip_ip_hdr *)&(p)->buff[UIP_LLH_LEN])->srcipaddr)
293 #endif
294 
295 /**
296  * \brief Get the TTL of a buffered packet
297  * p: pointer to a packet buffer
298  */
299 #define MCAST_PACKET_TTL(p) \
300  (((struct uip_ip_hdr *)(p)->buff)->ttl)
301 
302 /**
303  * \brief Set 'Is Used' bit for packet p
304  * p: pointer to a packet buffer
305  */
306 #define MCAST_PACKET_USED_SET(p) ((p)->flags |= MCAST_PACKET_U_BIT)
307 
308 /**
309  * \brief Clear 'Is Used' bit for packet p
310  * p: pointer to a packet buffer
311  */
312 #define MCAST_PACKET_USED_CLR(p) ((p)->flags &= ~MCAST_PACKET_U_BIT)
313 
314 /**
315  * \brief Is Occupied buffer location p
316  */
317 #define MCAST_PACKET_IS_USED(p) ((p)->flags & MCAST_PACKET_U_BIT)
318 
319 /**
320  * \brief Must we send this message this pass?
321  */
322 #define MCAST_PACKET_MUST_SEND(p) ((p)->flags & MCAST_PACKET_S_BIT)
323 
324 /**
325  * \brief Set 'Must Send' bit for message p
326  * p: pointer to a struct mcast_packet
327  */
328 #define MCAST_PACKET_SEND_SET(p) ((p)->flags |= MCAST_PACKET_S_BIT)
329 
330 /**
331  * \brief Clear 'Must Send' bit for message p
332  * p: pointer to a struct mcast_packet
333  */
334 #define MCAST_PACKET_SEND_CLR(p) ((p)->flags &= ~MCAST_PACKET_S_BIT)
335 
336 /**
337  * \brief Is the message p listed in current ICMP message?
338  * p: pointer to a struct mcast_packet
339  */
340 #define MCAST_PACKET_IS_LISTED(p) ((p)->flags & MCAST_PACKET_L_BIT)
341 
342 /**
343  * \brief Set 'Is Listed' bit for message p
344  * p: pointer to a struct mcast_packet
345  */
346 #define MCAST_PACKET_LISTED_SET(p) ((p)->flags |= MCAST_PACKET_L_BIT)
347 
348 /**
349  * \brief Clear 'Is Listed' bit for message p
350  * p: pointer to a struct mcast_packet
351  */
352 #define MCAST_PACKET_LISTED_CLR(p) ((p)->flags &= ~MCAST_PACKET_L_BIT)
353 
354 /**
355  * \brief Free a multicast packet buffer
356  * p: pointer to a struct mcast_packet
357  */
358 #define MCAST_PACKET_FREE(p) ((p)->flags = 0)
359 /*---------------------------------------------------------------------------*/
360 /* Sequence Lists in Multicast Trickle ICMP messages */
361 struct sequence_list_header {
362  uint8_t flags; /* S: Seed ID length, M: Trickle parametrization */
363  uint8_t seq_len;
364  seed_id_t seed_id;
365 };
366 
367 #define SEQUENCE_LIST_S_BIT 0x80
368 #define SEQUENCE_LIST_M_BIT 0x40
369 #define SEQUENCE_LIST_RES 0x3F
370 
371 /**
372  * \brief Get the Trickle Parametrization for an ICMPv6 sequence list
373  * l: pointer to a sequence list structure
374  */
375 #define SEQUENCE_LIST_GET_M(l) \
376  ((uint8_t)(((l)->flags & SEQUENCE_LIST_M_BIT) == SEQUENCE_LIST_M_BIT))
377 
378 /**
379  * \brief Get the Seed ID Length for an ICMPv6 sequence list
380  * l: pointer to a sequence list structure
381  */
382 #define SEQUENCE_LIST_GET_S(l) \
383  ((uint8_t)(((l)->flags & SEQUENCE_LIST_S_BIT) == SEQUENCE_LIST_S_BIT))
384 /*---------------------------------------------------------------------------*/
385 /* Trickle Multicast HBH Option */
386 struct hbho_mcast {
387  uint8_t type;
388  uint8_t len;
389 #if ROLL_TM_SHORT_SEEDS
390  seed_id_t seed_id;
391 #endif
392  uint8_t flags; /* M, Seq ID MSB */
393  uint8_t seq_id_lsb;
394 #if !ROLL_TM_SHORT_SEEDS
395  /* Need to Pad to 8 bytes with PadN */
396  uint8_t padn_type; /* 1: PadN */
397  uint8_t padn_len; /* 0->2 bytes */
398 #endif
399 };
400 
401 #define HBHO_OPT_TYPE_TRICKLE 0x0C
402 #define HBHO_LEN_LONG_SEED 2
403 #define HBHO_LEN_SHORT_SEED 4
404 #define HBHO_TOTAL_LEN 8
405 /**
406  * \brief Get the Trickle Parametrization for a multicast HBHO header
407  * m: pointer to the HBHO header
408  */
409 #define HBH_GET_M(h) (((h)->flags & 0x80) == 0x80)
410 
411 /**
412  * \brief Set the Trickle Parametrization bit for a multicast HBHO header
413  * m: pointer to the HBHO header
414  */
415 #define HBH_SET_M(h) ((h)->flags |= 0x80)
416 
417 /**
418  * \brief Retrieve the Sequence Value MSB from a multicast HBHO header
419  * m: pointer to the HBHO header
420  */
421 #define HBH_GET_SV_MSB(h) ((h)->flags & 0x7F)
422 /*---------------------------------------------------------------------------*/
423 /* Destination for our ICMPv6 datagrams */
424 #if ROLL_TM_CONF_DEST_ALL_NODES
425 #define roll_tm_create_dest(a) uip_create_linklocal_allnodes_mcast(a)
426 #else
427 #define roll_tm_create_dest(a) uip_create_linklocal_allrouters_mcast(a)
428 #endif
429 /*---------------------------------------------------------------------------*/
430 /* Maintain Stats */
431 #if UIP_MCAST6_STATS
432 static struct roll_tm_stats stats;
433 
434 #define ROLL_TM_STATS_ADD(x) stats.x++
435 #define ROLL_TM_STATS_INIT() do { memset(&stats, 0, sizeof(stats)); } while(0)
436 #else /* UIP_MCAST6_STATS */
437 #define ROLL_TM_STATS_ADD(x)
438 #define ROLL_TM_STATS_INIT()
439 #endif
440 /*---------------------------------------------------------------------------*/
441 /* Internal Data Structures */
442 /*---------------------------------------------------------------------------*/
443 static struct trickle_param t[2];
444 static struct sliding_window windows[ROLL_TM_WINS];
445 static struct mcast_packet buffered_msgs[ROLL_TM_BUFF_NUM];
446 /*---------------------------------------------------------------------------*/
447 /* Temporary Stores */
448 /*---------------------------------------------------------------------------*/
449 static struct trickle_param *loctpptr;
450 static struct sequence_list_header *locslhptr;
451 static struct sliding_window *locswptr;
452 static struct sliding_window *iterswptr;
453 static struct mcast_packet *locmpptr;
454 static struct hbho_mcast *lochbhmptr;
455 static uint16_t last_seq;
456 /*---------------------------------------------------------------------------*/
457 /* uIPv6 Pointers */
458 /*---------------------------------------------------------------------------*/
459 #define UIP_DATA_BUF ((uint8_t *)&uip_buf[uip_l2_l3_hdr_len + UIP_UDPH_LEN])
460 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
461 #define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
462 #define UIP_EXT_BUF_NEXT ((uint8_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + HBHO_TOTAL_LEN])
463 #define UIP_EXT_OPT_FIRST ((struct hbho_mcast *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + 2])
464 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
465 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
466 #define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len])
467 extern uint16_t uip_slen;
468 /*---------------------------------------------------------------------------*/
469 /* Local function prototypes */
470 /*---------------------------------------------------------------------------*/
471 static void icmp_input(void);
472 static void icmp_output(void);
473 static void window_update_bounds(void);
474 static void reset_trickle_timer(uint8_t);
475 static void handle_timer(void *);
476 /*---------------------------------------------------------------------------*/
477 /* ROLL TM ICMPv6 handler declaration */
478 UIP_ICMP6_HANDLER(roll_tm_icmp_handler, ICMP6_ROLL_TM,
479  UIP_ICMP6_HANDLER_CODE_ANY, icmp_input);
480 /*---------------------------------------------------------------------------*/
481 /* Return a random number in [I/2, I), for a timer with Imin when the timer's
482  * current number of doublings is d */
483 static clock_time_t
484 random_interval(clock_time_t i_min, uint8_t d)
485 {
486  clock_time_t min = TRICKLE_TIME(i_min >> 1, d);
487 
488  VERBOSE_PRINTF("ROLL TM: Random [%lu, %lu)\n", (unsigned long)min,
489  (unsigned long)(TRICKLE_TIME(i_min, d)));
490 
491  return min + (random_rand() % (TRICKLE_TIME(i_min, d) - 1 - min));
492 }
493 /*---------------------------------------------------------------------------*/
494 /* Called at the end of the current interval for timer ptr */
495 static void
496 double_interval(void *ptr)
497 {
498  struct trickle_param *param = (struct trickle_param *)ptr;
499  int16_t offset;
500  clock_time_t next;
501 
502  /*
503  * If we got called long past our expiration, store the offset and try to
504  * compensate this period
505  */
506  offset = (int16_t)(clock_time() - param->t_end);
507 
508  /* Calculate next interval */
509  if(param->i_current < param->i_max) {
510  param->i_current++;
511  }
512 
513  param->t_start = param->t_end;
514  param->t_end = param->t_start + (param->i_min << param->i_current);
515 
516  next = random_interval(param->i_min, param->i_current);
517  if(next > offset) {
518  next -= offset;
519  } else {
520  next = 0;
521  }
522  param->t_next = next;
523  ctimer_set(&param->ct, param->t_next, handle_timer, (void *)param);
524 
525  VERBOSE_PRINTF("ROLL TM: Doubling at %lu (offset %d), Start %lu, End %lu,"
526  " Periodic in %lu\n", clock_time(), offset,
527  (unsigned long)param->t_start,
528  (unsigned long)param->t_end, (unsigned long)param->t_next);
529 }
530 /*---------------------------------------------------------------------------*/
531 /*
532  * Called at a random point in [I/2,I) of the current interval for ptr
533  * PARAM is a pointer to the timer that triggered the callback (&t[index])
534  */
535 static void
536 handle_timer(void *ptr)
537 {
538  struct trickle_param *param;
539  clock_time_t diff_last; /* Time diff from last pass */
540  clock_time_t diff_start; /* Time diff from interval start */
541  uint8_t m;
542 
543  param = (struct trickle_param *)ptr;
544  if(param == &t[0]) {
545  m = 0;
546  } else if(param == &t[1]) {
547  m = 1;
548  } else {
549  /* This is an ooops and a serious one too */
550  return;
551  }
552 
553  /* Bail out pronto if our uIPv6 stack is not ready to send messages */
554  if(uip_ds6_get_link_local(ADDR_PREFERRED) == NULL) {
555  VERBOSE_PRINTF
556  ("ROLL TM: Suppressing timer processing. Stack not ready\n");
557  reset_trickle_timer(m);
558  return;
559  }
560 
561  VERBOSE_PRINTF("ROLL TM: M=%u Periodic at %lu, last=%lu\n",
562  m, (unsigned long)clock_time(),
563  (unsigned long)param->t_last_trigger);
564 
565  /* Temporarily store 'now' in t_next and calculate diffs */
566  param->t_next = clock_time();
567  diff_last = param->t_next - param->t_last_trigger;
568  diff_start = param->t_next - param->t_start;
569  param->t_last_trigger = param->t_next;
570 
571  VERBOSE_PRINTF
572  ("ROLL TM: M=%u Periodic diff from last %lu, from start %lu\n", m,
573  (unsigned long)diff_last, (unsigned long)diff_start);
574 
575  /* Handle all buffered messages */
576  for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
577  locmpptr >= buffered_msgs; locmpptr--) {
578  if(MCAST_PACKET_IS_USED(locmpptr)
579  && (SLIDING_WINDOW_GET_M(locmpptr->sw) == m)) {
580 
581  /*
582  * if()
583  * If the packet was received during the last interval, its reception
584  * caused an inconsistency (and thus a timer reset). This means that
585  * the packet was received at about t_start, we increment by diff_start
586  *
587  * else()
588  * If the packet was not received during the last window, it is safe to
589  * increase its lifetime counters by the time diff from last pass
590  *
591  * if active == dwell == 0 but i_current != 0, this is an oops
592  * (new packet that didn't reset us). We don't handle it
593  */
594  if(locmpptr->active == 0) {
595  locmpptr->active += diff_start;
596  locmpptr->dwell += diff_start;
597  } else {
598  locmpptr->active += diff_last;
599  locmpptr->dwell += diff_last;
600  }
601 
602  VERBOSE_PRINTF("ROLL TM: M=%u Packet %u active %lu of %lu\n",
603  m, locmpptr->seq_val, locmpptr->active,
604  TRICKLE_ACTIVE(param));
605 
606  if(locmpptr->dwell > TRICKLE_DWELL(param)) {
607  locmpptr->sw->count--;
608  PRINTF("ROLL TM: M=%u Free Packet %u (%lu > %lu), Window now at %u\n",
609  m, locmpptr->seq_val, locmpptr->dwell,
610  TRICKLE_DWELL(param), locmpptr->sw->count);
611  if(locmpptr->sw->count == 0) {
612  PRINTF("ROLL TM: M=%u Free Window ", m);
613  PRINT_SEED(&locmpptr->sw->seed_id);
614  PRINTF("\n");
615  window_free(locmpptr->sw);
616  }
617  MCAST_PACKET_FREE(locmpptr);
618  } else if(MCAST_PACKET_TTL(locmpptr) > 0) {
619  /* Handle multicast transmissions */
620  if(locmpptr->active < TRICKLE_ACTIVE(param) &&
621  ((SUPPRESSION_ENABLED(param) && MCAST_PACKET_MUST_SEND(locmpptr)) ||
622  SUPPRESSION_DISABLED(param))) {
623  PRINTF("ROLL TM: M=%u Periodic - Sending packet from Seed ", m);
624  PRINT_SEED(&locmpptr->sw->seed_id);
625  PRINTF(" seq %u\n", locmpptr->seq_val);
626  uip_len = locmpptr->buff_len;
627  memcpy(UIP_IP_BUF, &locmpptr->buff, uip_len);
628 
629  UIP_MCAST6_STATS_ADD(mcast_fwd);
630  tcpip_output(NULL);
631  MCAST_PACKET_SEND_CLR(locmpptr);
633  }
634  }
635  }
636  }
637 
638  /* Suppression Enabled - Send an ICMP */
639  if(SUPPRESSION_ENABLED(param)) {
640  if(param->c < param->k) {
641  icmp_output();
642  }
643  }
644 
645  /* Done handling inconsistencies for this timer */
646  param->inconsistency = 0;
647  param->c = 0;
648 
649  window_update_bounds();
650 
651  /* Temporarily store 'now' in t_next */
652  param->t_next = clock_time();
653  if(param->t_next >= param->t_end) {
654  /* took us too long to process things, double interval asap */
655  param->t_next = 0;
656  } else {
657  param->t_next = param->t_end - param->t_next;
658  }
659  VERBOSE_PRINTF
660  ("ROLL TM: M=%u Periodic at %lu, Interval End at %lu in %lu\n", m,
661  (unsigned long)clock_time(), (unsigned long)param->t_end,
662  (unsigned long)param->t_next);
663  ctimer_set(&param->ct, param->t_next, double_interval, (void *)param);
664 
665  return;
666 }
667 /*---------------------------------------------------------------------------*/
668 static void
669 reset_trickle_timer(uint8_t index)
670 {
671  t[index].t_start = clock_time();
672  t[index].t_end = t[index].t_start + (t[index].i_min);
673  t[index].i_current = 0;
674  t[index].c = 0;
675  t[index].t_next = random_interval(t[index].i_min, t[index].i_current);
676 
677  VERBOSE_PRINTF
678  ("ROLL TM: M=%u Reset at %lu, Start %lu, End %lu, New Interval %lu\n",
679  index, (unsigned long)t[index].t_start, (unsigned long)t[index].t_start,
680  (unsigned long)t[index].t_end, (unsigned long)t[index].t_next);
681 
682  ctimer_set(&t[index].ct, t[index].t_next, handle_timer, (void *)&t[index]);
683 }
684 /*---------------------------------------------------------------------------*/
685 static struct sliding_window *
686 window_allocate()
687 {
688  for(iterswptr = &windows[ROLL_TM_WINS - 1]; iterswptr >= windows;
689  iterswptr--) {
690  if(!SLIDING_WINDOW_IS_USED(iterswptr)) {
691  iterswptr->count = 0;
692  iterswptr->lower_bound = -1;
693  iterswptr->upper_bound = -1;
694  iterswptr->min_listed = -1;
695  return iterswptr;
696  }
697  }
698  return NULL;
699 }
700 /*---------------------------------------------------------------------------*/
701 static struct sliding_window *
702 window_lookup(seed_id_t *s, uint8_t m)
703 {
704  for(iterswptr = &windows[ROLL_TM_WINS - 1]; iterswptr >= windows;
705  iterswptr--) {
706  VERBOSE_PRINTF("ROLL TM: M=%u (%u) ", SLIDING_WINDOW_GET_M(iterswptr), m);
707  VERBOSE_PRINT_SEED(&iterswptr->seed_id);
708  VERBOSE_PRINTF("\n");
709  if(seed_id_cmp(s, &iterswptr->seed_id) &&
710  SLIDING_WINDOW_GET_M(iterswptr) == m) {
711  return iterswptr;
712  }
713  }
714  return NULL;
715 }
716 /*---------------------------------------------------------------------------*/
717 static void
718 window_update_bounds()
719 {
720  for(iterswptr = &windows[ROLL_TM_WINS - 1]; iterswptr >= windows;
721  iterswptr--) {
722  iterswptr->lower_bound = -1;
723  }
724 
725  for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
726  locmpptr >= buffered_msgs; locmpptr--) {
727  if(MCAST_PACKET_IS_USED(locmpptr)) {
728  iterswptr = locmpptr->sw;
729  VERBOSE_PRINTF("ROLL TM: Update Bounds: [%d - %d] vs %u\n",
730  iterswptr->lower_bound, iterswptr->upper_bound,
731  locmpptr->seq_val);
732  if(iterswptr->lower_bound < 0
733  || SEQ_VAL_IS_LT(locmpptr->seq_val, iterswptr->lower_bound)) {
734  iterswptr->lower_bound = locmpptr->seq_val;
735  }
736  if(iterswptr->upper_bound < 0 ||
737  SEQ_VAL_IS_GT(locmpptr->seq_val, iterswptr->upper_bound)) {
738  iterswptr->upper_bound = locmpptr->seq_val;
739  }
740  }
741  }
742 }
743 /*---------------------------------------------------------------------------*/
744 static struct mcast_packet *
745 buffer_reclaim()
746 {
747  struct sliding_window *largest = windows;
748  struct mcast_packet *rv;
749 
750  for(iterswptr = &windows[ROLL_TM_WINS - 1]; iterswptr >= windows;
751  iterswptr--) {
752  if(iterswptr->count > largest->count) {
753  largest = iterswptr;
754  }
755  }
756 
757  if(largest->count == 1) {
758  /* Can't reclaim last entry for a window and this is the largest window */
759  return NULL;
760  }
761 
762  PRINTF("ROLL TM: Reclaim from Seed ");
763  PRINT_SEED(&largest->seed_id);
764  PRINTF(" M=%u, count was %u\n",
765  SLIDING_WINDOW_GET_M(largest), largest->count);
766  /* Find the packet at the lowest bound for the largest window */
767  for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
768  locmpptr >= buffered_msgs; locmpptr--) {
769  if(MCAST_PACKET_IS_USED(locmpptr) && (locmpptr->sw == largest) &&
770  SEQ_VAL_IS_EQ(locmpptr->seq_val, largest->lower_bound)) {
771  rv = locmpptr;
772  PRINTF("ROLL TM: Reclaim seq. val %u\n", locmpptr->seq_val);
773  MCAST_PACKET_FREE(rv);
774  largest->count--;
775  window_update_bounds();
776  VERBOSE_PRINTF("ROLL TM: Reclaim - new bounds [%u , %u]\n",
777  largest->lower_bound, largest->upper_bound);
778  return rv;
779  }
780  }
781 
782  /* oops */
783  return NULL;
784 }
785 /*---------------------------------------------------------------------------*/
786 static struct mcast_packet *
787 buffer_allocate()
788 {
789  for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
790  locmpptr >= buffered_msgs; locmpptr--) {
791  if(!MCAST_PACKET_IS_USED(locmpptr)) {
792  return locmpptr;
793  }
794  }
795  return NULL;
796 }
797 /*---------------------------------------------------------------------------*/
798 static void
799 icmp_output()
800 {
801  struct sequence_list_header *sl;
802  uint8_t *buffer;
803  uint16_t payload_len;
804 
805  PRINTF("ROLL TM: ICMPv6 Out\n");
806 
807  UIP_IP_BUF->vtc = 0x60;
808  UIP_IP_BUF->tcflow = 0;
809  UIP_IP_BUF->flow = 0;
810  UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
812 
813  sl = (struct sequence_list_header *)UIP_ICMP_PAYLOAD;
814  payload_len = 0;
815 
816  VERBOSE_PRINTF("ROLL TM: ICMPv6 Out - Hdr @ %p, payload @ %p\n", UIP_ICMP_BUF, sl);
817 
818  for(iterswptr = &windows[ROLL_TM_WINS - 1]; iterswptr >= windows;
819  iterswptr--) {
820  if(SLIDING_WINDOW_IS_USED(iterswptr) && iterswptr->count > 0) {
821  memset(sl, 0, sizeof(struct sequence_list_header));
822 #if ROLL_TM_SHORT_SEEDS
823  sl->flags = SEQUENCE_LIST_S_BIT;
824 #endif
825  if(SLIDING_WINDOW_GET_M(iterswptr)) {
826  sl->flags |= SEQUENCE_LIST_M_BIT;
827  }
828  seed_id_cpy(&sl->seed_id, &iterswptr->seed_id);
829 
830  PRINTF("ROLL TM: ICMPv6 Out - Seq. F=0x%02x, Seed ID=", sl->flags);
831  PRINT_SEED(&sl->seed_id);
832 
833  buffer = (uint8_t *)sl + sizeof(struct sequence_list_header);
834 
835  for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
836  locmpptr >= buffered_msgs; locmpptr--) {
837  if(MCAST_PACKET_IS_USED(locmpptr) &&
838  locmpptr->active < TRICKLE_ACTIVE((&t[SLIDING_WINDOW_GET_M(iterswptr)]))) {
839  if(locmpptr->sw == iterswptr) {
840  sl->seq_len++;
841  PRINTF(", %u", locmpptr->seq_val);
842  *buffer = (uint8_t)(locmpptr->seq_val >> 8);
843  buffer++;
844  *buffer = (uint8_t)(locmpptr->seq_val & 0xFF);
845  buffer++;
846  }
847  }
848  }
849  PRINTF(", Len=%u\n", sl->seq_len);
850 
851  /* Scrap the entire window if it has no content */
852  if(sl->seq_len > 0) {
853  payload_len += sizeof(struct sequence_list_header) + sl->seq_len * 2;
854  sl = (struct sequence_list_header *)buffer;
855  }
856  }
857  }
858 
859  if(payload_len == 0) {
860  VERBOSE_PRINTF("ROLL TM: ICMPv6 Out - nothing to send\n");
861  return;
862  }
863 
864  roll_tm_create_dest(&UIP_IP_BUF->destipaddr);
865  uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
866 
867  UIP_IP_BUF->len[0] = (UIP_ICMPH_LEN + payload_len) >> 8;
868  UIP_IP_BUF->len[1] = (UIP_ICMPH_LEN + payload_len) & 0xff;
869 
870  UIP_ICMP_BUF->type = ICMP6_ROLL_TM;
872 
873  UIP_ICMP_BUF->icmpchksum = 0;
874  UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
875 
876  uip_len = UIP_IPH_LEN + UIP_ICMPH_LEN + payload_len;
877 
878  VERBOSE_PRINTF("ROLL TM: ICMPv6 Out - %u bytes\n", payload_len);
879 
881  ROLL_TM_STATS_ADD(icmp_out);
882  return;
883 }
884 /*---------------------------------------------------------------------------*/
885 /**
886  * \brief Processes an incoming or outgoing multicast message and determines
887  * whether it should be dropped or accepted
888  *
889  * \param in 1: Incoming packet, 0: Outgoing (we are the seed)
890  *
891  * \return 0: Drop, 1: Accept
892  */
893 static uint8_t
894 accept(uint8_t in)
895 {
896  seed_id_t *seed_ptr;
897  uint8_t m;
898  uint16_t seq_val;
899 
900  PRINTF("ROLL TM: Multicast I/O\n");
901 
902 #if UIP_CONF_IPV6_CHECKS
903  if(uip_is_addr_mcast_non_routable(&UIP_IP_BUF->destipaddr)) {
904  PRINTF("ROLL TM: Mcast I/O, bad destination\n");
905  UIP_MCAST6_STATS_ADD(mcast_bad);
906  return UIP_MCAST6_DROP;
907  }
908  /*
909  * Abort transmission if the v6 src is unspecified. This may happen if the
910  * seed tries to TX while it's still performing DAD or waiting for a prefix
911  */
912  if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
913  PRINTF("ROLL TM: Mcast I/O, bad source\n");
914  UIP_MCAST6_STATS_ADD(mcast_bad);
915  return UIP_MCAST6_DROP;
916  }
917 #endif
918 
919  /* Check the Next Header field: Must be HBHO */
920  if(UIP_IP_BUF->proto != UIP_PROTO_HBHO) {
921  PRINTF("ROLL TM: Mcast I/O, bad proto\n");
922  UIP_MCAST6_STATS_ADD(mcast_bad);
923  return UIP_MCAST6_DROP;
924  } else {
925  /* Check the Option Type */
926  if(UIP_EXT_OPT_FIRST->type != HBHO_OPT_TYPE_TRICKLE) {
927  PRINTF("ROLL TM: Mcast I/O, bad HBHO type\n");
928  UIP_MCAST6_STATS_ADD(mcast_bad);
929  return UIP_MCAST6_DROP;
930  }
931  }
932  lochbhmptr = UIP_EXT_OPT_FIRST;
933 
934  PRINTF("ROLL TM: HBHO T=%u, L=%u, M=%u, S=0x%02x%02x\n",
935  lochbhmptr->type, lochbhmptr->len, HBH_GET_M(lochbhmptr),
936  HBH_GET_SV_MSB(lochbhmptr), lochbhmptr->seq_id_lsb);
937 
938  /* Drop unsupported Seed ID Lengths. S bit: 0->short, 1->long */
939 #if ROLL_TM_SHORT_SEEDS
940  /* Short Seed ID: Len MUST be 4 */
941  if(lochbhmptr->len != HBHO_LEN_SHORT_SEED) {
942  PRINTF("ROLL TM: Mcast I/O, bad length\n");
943  UIP_MCAST6_STATS_ADD(mcast_bad);
944  return UIP_MCAST6_DROP;
945  }
946 #else
947  /* Long Seed ID: Len MUST be 2 (Seed ID is elided) */
948  if(lochbhmptr->len != HBHO_LEN_LONG_SEED) {
949  PRINTF("ROLL TM: Mcast I/O, bad length\n");
950  UIP_MCAST6_STATS_ADD(mcast_bad);
951  return UIP_MCAST6_DROP;
952  }
953 #endif
954 
955 #if UIP_MCAST6_STATS
956  if(in == ROLL_TM_DGRAM_IN) {
957  UIP_MCAST6_STATS_ADD(mcast_in_all);
958  }
959 #endif
960 
961  /* Is this for a known window? */
962 #if ROLL_TM_SHORT_SEEDS
963  seed_ptr = &lochbhmptr->seed_id;
964 #else
965  seed_ptr = &UIP_IP_BUF->srcipaddr;
966 #endif
967  m = HBH_GET_M(lochbhmptr);
968 
969  locswptr = window_lookup(seed_ptr, m);
970 
971  seq_val = lochbhmptr->seq_id_lsb;
972  seq_val |= HBH_GET_SV_MSB(lochbhmptr) << 8;
973 
974  if(locswptr) {
975  if(SEQ_VAL_IS_LT(seq_val, locswptr->lower_bound)) {
976  /* Too old, drop */
977  PRINTF("ROLL TM: Too old\n");
978  UIP_MCAST6_STATS_ADD(mcast_dropped);
979  return UIP_MCAST6_DROP;
980  }
981  for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
982  locmpptr >= buffered_msgs; locmpptr--) {
983  if(MCAST_PACKET_IS_USED(locmpptr) &&
984  locmpptr->sw == locswptr &&
985  SLIDING_WINDOW_GET_M(locmpptr->sw) == m &&
986  SEQ_VAL_IS_EQ(seq_val, locmpptr->seq_val)) {
987  /* Seen before , drop */
988  PRINTF("ROLL TM: Seen before\n");
989  UIP_MCAST6_STATS_ADD(mcast_dropped);
990  return UIP_MCAST6_DROP;
991  }
992  }
993  }
994 
995  PRINTF("ROLL TM: New message\n");
996 
997  /* We have not seen this message before */
998  /* Allocate a window if we have to */
999  if(!locswptr) {
1000  locswptr = window_allocate();
1001  PRINTF("ROLL TM: New seed\n");
1002  }
1003  if(!locswptr) {
1004  /* Couldn't allocate window, drop */
1005  PRINTF("ROLL TM: Failed to allocate window\n");
1006  UIP_MCAST6_STATS_ADD(mcast_dropped);
1007  return UIP_MCAST6_DROP;
1008  }
1009 
1010  /* Allocate a buffer */
1011  locmpptr = buffer_allocate();
1012  if(!locmpptr) {
1013  PRINTF("ROLL TM: Buffer allocation failed, reclaiming\n");
1014  locmpptr = buffer_reclaim();
1015  }
1016 
1017  if(!locmpptr) {
1018  /* Failed to allocate / reclaim a buffer. If the window has only just been
1019  * allocated, free it before dropping */
1020  PRINTF("ROLL TM: Buffer reclaim failed\n");
1021  if(locswptr->count == 0) {
1022  window_free(locswptr);
1023  UIP_MCAST6_STATS_ADD(mcast_dropped);
1024  return UIP_MCAST6_DROP;
1025  }
1026  }
1027 #if UIP_MCAST6_STATS
1028  if(in == ROLL_TM_DGRAM_IN) {
1029  UIP_MCAST6_STATS_ADD(mcast_in_unique);
1030  }
1031 #endif
1032 
1033  /* We have a window and we have a buffer. Accept this message */
1034  /* Set the seed ID and correct M for this window */
1035  SLIDING_WINDOW_M_CLR(locswptr);
1036  if(m) {
1037  SLIDING_WINDOW_M_SET(locswptr);
1038  }
1039  SLIDING_WINDOW_IS_USED_SET(locswptr);
1040  seed_id_cpy(&locswptr->seed_id, seed_ptr);
1041  PRINTF("ROLL TM: Window for seed ");
1042  PRINT_SEED(&locswptr->seed_id);
1043  PRINTF(" M=%u, count=%u\n",
1044  SLIDING_WINDOW_GET_M(locswptr), locswptr->count);
1045 
1046  /* If this window was previously empty, set its lower bound to this packet */
1047  if(locswptr->count == 0) {
1048  locswptr->lower_bound = seq_val;
1049  VERBOSE_PRINTF("ROLL TM: New Lower Bound %u\n", locswptr->lower_bound);
1050  }
1051 
1052  /* If this is a new Seq Num, update the window upper bound */
1053  if(locswptr->count == 0 || SEQ_VAL_IS_GT(seq_val, locswptr->upper_bound)) {
1054  locswptr->upper_bound = seq_val;
1055  VERBOSE_PRINTF("ROLL TM: New Upper Bound %u\n", locswptr->upper_bound);
1056  }
1057 
1058  locswptr->count++;
1059 
1060  memset(locmpptr, 0, sizeof(struct mcast_packet));
1061  memcpy(&locmpptr->buff, UIP_IP_BUF, uip_len);
1062  locmpptr->sw = locswptr;
1063  locmpptr->buff_len = uip_len;
1064  locmpptr->seq_val = seq_val;
1065  MCAST_PACKET_USED_SET(locmpptr);
1066 
1067  PRINTF("ROLL TM: Window for seed ");
1068  PRINT_SEED(&locswptr->seed_id);
1069  PRINTF(" M=%u, %u values within [%u , %u]\n",
1070  SLIDING_WINDOW_GET_M(locswptr), locswptr->count,
1071  locswptr->lower_bound, locswptr->upper_bound);
1072 
1073  /*
1074  * If this is an incoming packet, it is inconsistent and we need to decrement
1075  * its TTL before we start forwarding it.
1076  * If on the other hand we are the seed, the caller will trigger a
1077  * transmission so we don't flag inconsistency and we leave the TTL alone
1078  */
1079  if(in == ROLL_TM_DGRAM_IN) {
1080  MCAST_PACKET_SEND_SET(locmpptr);
1081  MCAST_PACKET_TTL(locmpptr)--;
1082 
1083  t[m].inconsistency = 1;
1084 
1085  PRINTF("ROLL TM: Inconsistency. Reset T%u\n", m);
1086  reset_trickle_timer(m);
1087  }
1088 
1089  /* Deliver if necessary */
1090  return UIP_MCAST6_ACCEPT;
1091 }
1092 /*---------------------------------------------------------------------------*/
1093 /* ROLL TM ICMPv6 Input Handler */
1094 static void
1095 icmp_input()
1096 {
1097  uint8_t inconsistency;
1098  uint16_t *seq_ptr;
1099  uint16_t *end_ptr;
1100  uint16_t val;
1101 
1102 #if UIP_CONF_IPV6_CHECKS
1103  if(!uip_is_addr_linklocal(&UIP_IP_BUF->srcipaddr)) {
1104  PRINTF("ROLL TM: ICMPv6 In, bad source ");
1105  PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
1106  PRINTF(" to ");
1107  PRINT6ADDR(&UIP_IP_BUF->destipaddr);
1108  PRINTF("\n");
1109  ROLL_TM_STATS_ADD(icmp_bad);
1110  goto discard;
1111  }
1112 
1115  PRINTF("ROLL TM: ICMPv6 In, bad destination\n");
1116  ROLL_TM_STATS_ADD(icmp_bad);
1117  goto discard;
1118  }
1119 
1120  if(UIP_ICMP_BUF->icode != ROLL_TM_ICMP_CODE) {
1121  PRINTF("ROLL TM: ICMPv6 In, bad ICMP code\n");
1122  ROLL_TM_STATS_ADD(icmp_bad);
1123  goto discard;
1124  }
1125 
1126  if(UIP_IP_BUF->ttl != ROLL_TM_IP_HOP_LIMIT) {
1127  PRINTF("ROLL TM: ICMPv6 In, bad TTL\n");
1128  ROLL_TM_STATS_ADD(icmp_bad);
1129  goto discard;
1130  }
1131 #endif
1132 
1133  PRINTF("ROLL TM: ICMPv6 In from ");
1134  PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
1135  PRINTF(" len %u, ext %u\n", uip_len, uip_ext_len);
1136 
1137  ROLL_TM_STATS_ADD(icmp_in);
1138 
1139  /* Reset Is-Listed bit for all windows */
1140  for(iterswptr = &windows[ROLL_TM_WINS - 1]; iterswptr >= windows;
1141  iterswptr--) {
1142  SLIDING_WINDOW_LISTED_CLR(iterswptr);
1143  }
1144 
1145  /* Reset Is-Listed bit for all cached packets */
1146  for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
1147  locmpptr >= buffered_msgs; locmpptr--) {
1148  MCAST_PACKET_LISTED_CLR(locmpptr);
1149  }
1150 
1151  locslhptr = (struct sequence_list_header *)UIP_ICMP_PAYLOAD;
1152 
1153  VERBOSE_PRINTF("ROLL TM: ICMPv6 In, parse from %p to %p\n",
1154  UIP_ICMP_PAYLOAD,
1155  (uint8_t *)UIP_ICMP_PAYLOAD + uip_len -
1156  uip_l2_l3_icmp_hdr_len);
1157  while(locslhptr <
1158  (struct sequence_list_header *)((uint8_t *)UIP_ICMP_PAYLOAD +
1159  uip_len - uip_l2_l3_icmp_hdr_len)) {
1160  VERBOSE_PRINTF("ROLL TM: ICMPv6 In, seq hdr @ %p\n", locslhptr);
1161 
1162  if((locslhptr->flags & SEQUENCE_LIST_RES) != 0) {
1163  PRINTF("ROLL TM: ICMPv6 In, non-zero reserved bits\n");
1164  goto drop;
1165  }
1166 
1167  /* Drop unsupported Seed ID Lengths. S bit: 0->short, 1->long */
1168 #if ROLL_TM_SHORT_SEEDS
1169  if(!SEQUENCE_LIST_GET_S(locslhptr)) {
1170  ROLL_TM_STATS_ADD(icmp_bad);
1171  goto drop;
1172  }
1173 #else
1174  if(SEQUENCE_LIST_GET_S(locslhptr)) {
1175  ROLL_TM_STATS_ADD(icmp_bad);
1176  goto drop;
1177  }
1178 #endif
1179 
1180  PRINTF("ROLL TM: ICMPv6 In, Sequence List for Seed ID ");
1181  PRINT_SEED(&locslhptr->seed_id);
1182  PRINTF(" M=%u, S=%u, Len=%u\n", SEQUENCE_LIST_GET_M(locslhptr),
1183  SEQUENCE_LIST_GET_S(locslhptr), locslhptr->seq_len);
1184 
1185  seq_ptr = (uint16_t *)((uint8_t *)locslhptr
1186  + sizeof(struct sequence_list_header));
1187  end_ptr = (uint16_t *)((uint8_t *)locslhptr
1188  + sizeof(struct sequence_list_header) +
1189  locslhptr->seq_len * 2);
1190 
1191  /* Fetch a pointer to the corresponding trickle timer */
1192  loctpptr = &t[SEQUENCE_LIST_GET_M(locslhptr)];
1193 
1194  locswptr = NULL;
1195 
1196  /* Find the sliding window for this Seed ID */
1197  locswptr = window_lookup(&locslhptr->seed_id,
1198  SEQUENCE_LIST_GET_M(locslhptr));
1199 
1200  /* If we have a window, iterate sequence values and check consistency */
1201  if(locswptr) {
1202  SLIDING_WINDOW_LISTED_SET(locswptr);
1203  locswptr->min_listed = -1;
1204  PRINTF("ROLL TM: ICMPv6 In, Window bounds [%u , %u]\n",
1205  locswptr->lower_bound, locswptr->upper_bound);
1206  for(; seq_ptr < end_ptr; seq_ptr++) {
1207  /* Check for "They have new" */
1208  /* If an advertised seq. val is GT our upper bound */
1209  val = uip_htons(*seq_ptr);
1210  PRINTF("ROLL TM: ICMPv6 In, Check seq %u @ %p\n", val, seq_ptr);
1211  if(SEQ_VAL_IS_GT(val, locswptr->upper_bound)) {
1212  PRINTF("ROLL TM: Inconsistency - Advertised Seq. ID %u GT upper"
1213  " bound %u\n", val, locswptr->upper_bound);
1214  loctpptr->inconsistency = 1;
1215  }
1216 
1217  /* If an advertised seq. val is within our bounds */
1218  if((SEQ_VAL_IS_LT(val, locswptr->upper_bound) ||
1219  SEQ_VAL_IS_EQ(val, locswptr->upper_bound)) &&
1220  (SEQ_VAL_IS_GT(val, locswptr->lower_bound) ||
1221  SEQ_VAL_IS_EQ(val, locswptr->lower_bound))) {
1222 
1223  inconsistency = 1;
1224  /* Check if the advertised sequence is in our buffer */
1225  for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
1226  locmpptr >= buffered_msgs; locmpptr--) {
1227  if(MCAST_PACKET_IS_USED(locmpptr) && locmpptr->sw == locswptr) {
1228  if(SEQ_VAL_IS_EQ(locmpptr->seq_val, val)) {
1229 
1230  inconsistency = 0;
1231  MCAST_PACKET_LISTED_SET(locmpptr);
1232  PRINTF("ROLL TM: ICMPv6 In, %u listed\n", locmpptr->seq_val);
1233 
1234  /* Update lowest seq. num listed for this window
1235  * We need this to check for "we have new" */
1236  if(locswptr->min_listed == -1 ||
1237  SEQ_VAL_IS_LT(val, locswptr->min_listed)) {
1238  locswptr->min_listed = val;
1239  }
1240  break;
1241  }
1242  }
1243  }
1244  if(inconsistency) {
1245  PRINTF("ROLL TM: Inconsistency - ");
1246  PRINTF("Advertised Seq. ID %u within bounds", val);
1247  PRINTF(" [%u, %u] but no matching entry\n",
1248  locswptr->lower_bound, locswptr->upper_bound);
1249  loctpptr->inconsistency = 1;
1250  }
1251  }
1252  }
1253  } else {
1254  /* A new sliding window in an ICMP message is not explicitly stated
1255  * in the draft as inconsistency. Until this is clarified, we consider
1256  * this to be a point where we diverge from the draft for performance
1257  * improvement reasons (or as some would say, 'this is an extension') */
1258  PRINTF("ROLL TM: Inconsistency - Advertised window unknown to us\n");
1259  loctpptr->inconsistency = 1;
1260  }
1261  locslhptr = (struct sequence_list_header *)(((uint8_t *)locslhptr) +
1262  sizeof(struct sequence_list_header) + (2 * locslhptr->seq_len));
1263  }
1264  /* Done parsing the message */
1265 
1266  /* Check for "We have new */
1267  PRINTF("ROLL TM: ICMPv6 In, Check our buffer\n");
1268  for(locmpptr = &buffered_msgs[ROLL_TM_BUFF_NUM - 1];
1269  locmpptr >= buffered_msgs; locmpptr--) {
1270  if(MCAST_PACKET_IS_USED(locmpptr)) {
1271  locswptr = locmpptr->sw;
1272  PRINTF("ROLL TM: ICMPv6 In, ");
1273  PRINTF("Check %u, Seed L: %u, This L: %u Min L: %d\n",
1274  locmpptr->seq_val, SLIDING_WINDOW_IS_LISTED(locswptr),
1275  MCAST_PACKET_IS_LISTED(locmpptr), locswptr->min_listed);
1276 
1277  /* Point to the sliding window's trickle param */
1278  loctpptr = &t[SLIDING_WINDOW_GET_M(locswptr)];
1279  if(!SLIDING_WINDOW_IS_LISTED(locswptr)) {
1280  /* If a buffered packet's Seed ID was not listed */
1281  PRINTF("ROLL TM: Inconsistency - Seed ID ");
1282  PRINT_SEED(&locswptr->seed_id);
1283  PRINTF(" was not listed\n");
1284  loctpptr->inconsistency = 1;
1285  MCAST_PACKET_SEND_SET(locmpptr);
1286  } else {
1287  /* This packet was not listed but a prior one was */
1288  if(!MCAST_PACKET_IS_LISTED(locmpptr) &&
1289  (locswptr->min_listed >= 0) &&
1290  SEQ_VAL_IS_GT(locmpptr->seq_val, locswptr->min_listed)) {
1291  PRINTF("ROLL TM: Inconsistency - ");
1292  PRINTF("Seq. %u was not listed but %u was\n",
1293  locmpptr->seq_val, locswptr->min_listed);
1294  loctpptr->inconsistency = 1;
1295  MCAST_PACKET_SEND_SET(locmpptr);
1296  }
1297  }
1298  }
1299  }
1300 
1301 drop:
1302 
1303  if(t[0].inconsistency) {
1304  reset_trickle_timer(0);
1305  } else {
1306  t[0].c++;
1307  }
1308  if(t[1].inconsistency) {
1309  reset_trickle_timer(1);
1310  } else {
1311  t[1].c++;
1312  }
1313 
1314 discard:
1315 
1316  uip_len = 0;
1317  return;
1318 }
1319 /*---------------------------------------------------------------------------*/
1320 static void
1321 out()
1322 {
1323 
1324  if(uip_len + HBHO_TOTAL_LEN > UIP_BUFSIZE - UIP_LLH_LEN) {
1325  PRINTF("ROLL TM: Multicast Out can not add HBHO. Packet too long\n");
1326  goto drop;
1327  }
1328 
1329  /* Slide 'right' by HBHO_TOTAL_LEN bytes */
1330  memmove(UIP_EXT_BUF_NEXT, UIP_EXT_BUF, uip_len - UIP_IPH_LEN);
1331  memset(UIP_EXT_BUF, 0, HBHO_TOTAL_LEN);
1332 
1333  UIP_EXT_BUF->next = UIP_IP_BUF->proto;
1334  UIP_EXT_BUF->len = 0;
1335 
1336  lochbhmptr = UIP_EXT_OPT_FIRST;
1337  lochbhmptr->type = HBHO_OPT_TYPE_TRICKLE;
1338 
1339  /* Set the sequence ID */
1340  last_seq = SEQ_VAL_ADD(last_seq, 1);
1341  lochbhmptr->flags = last_seq >> 8;
1342  lochbhmptr->seq_id_lsb = last_seq & 0xFF;
1343 #if ROLL_TM_SHORT_SEEDS
1344  seed_id_cpy(&lochbhmptr->seed_id, &uip_lladdr.addr[UIP_LLADDR_LEN - 2]);
1345  lochbhmptr->len = HBHO_LEN_SHORT_SEED;
1346 #else
1347  lochbhmptr->len = HBHO_LEN_LONG_SEED;
1348  /* PadN */
1349  lochbhmptr->padn_type = UIP_EXT_HDR_OPT_PADN;
1350  lochbhmptr->padn_len = 0;
1351 #endif
1352 
1353  /* Set the M bit for our outgoing messages, if necessary */
1354 #if ROLL_TM_SET_M_BIT
1355  HBH_SET_M(lochbhmptr);
1356 #endif
1357 
1358  uip_ext_len += HBHO_TOTAL_LEN;
1359  uip_len += HBHO_TOTAL_LEN;
1360 
1361  /* Update the proto and length field in the v6 header */
1362  UIP_IP_BUF->proto = UIP_PROTO_HBHO;
1363  UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
1364  UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
1365 
1366  PRINTF("ROLL TM: Multicast Out, HBHO: T=%u, L=%u, M=%u, S=0x%02x%02x\n",
1367  lochbhmptr->type, lochbhmptr->len, HBH_GET_M(lochbhmptr),
1368  HBH_GET_SV_MSB(lochbhmptr), lochbhmptr->seq_id_lsb);
1369 
1370  /*
1371  * We need to remember this message and advertise it in subsequent ICMP
1372  * messages. Otherwise, our neighs will think we are inconsistent and will
1373  * bounce it back to us.
1374  *
1375  * Queue this message but don't set its MUST_SEND flag. We reset the trickle
1376  * timer and we send it immediately. We then set uip_len = 0 to stop the core
1377  * from re-sending it.
1378  */
1379  if(accept(ROLL_TM_DGRAM_OUT)) {
1380  tcpip_output(NULL);
1381  UIP_MCAST6_STATS_ADD(mcast_out);
1382  }
1383 
1384 drop:
1385  uip_slen = 0;
1386  uip_clear_buf();
1387 }
1388 /*---------------------------------------------------------------------------*/
1389 static uint8_t
1390 in()
1391 {
1392  /*
1393  * We call accept() which will sort out caching and forwarding. Depending
1394  * on accept()'s return value, we then need to signal the core
1395  * whether to deliver this to higher layers
1396  */
1397  if(accept(ROLL_TM_DGRAM_IN) == UIP_MCAST6_DROP) {
1398  return UIP_MCAST6_DROP;
1399  }
1400 
1401  if(!uip_ds6_is_my_maddr(&UIP_IP_BUF->destipaddr)) {
1402  PRINTF("ROLL TM: Not a group member. No further processing\n");
1403  return UIP_MCAST6_DROP;
1404  } else {
1405  PRINTF("ROLL TM: Ours. Deliver to upper layers\n");
1406  UIP_MCAST6_STATS_ADD(mcast_in_ours);
1407  return UIP_MCAST6_ACCEPT;
1408  }
1409 }
1410 /*---------------------------------------------------------------------------*/
1411 static void
1412 init()
1413 {
1414  PRINTF("ROLL TM: ROLL Multicast - Draft #%u\n", ROLL_TM_VER);
1415 
1416  memset(windows, 0, sizeof(windows));
1417  memset(buffered_msgs, 0, sizeof(buffered_msgs));
1418  memset(t, 0, sizeof(t));
1419 
1420  ROLL_TM_STATS_INIT();
1421  UIP_MCAST6_STATS_INIT(&stats);
1422 
1423  /* Register the ICMPv6 input handler */
1424  uip_icmp6_register_input_handler(&roll_tm_icmp_handler);
1425 
1426  for(iterswptr = &windows[ROLL_TM_WINS - 1]; iterswptr >= windows;
1427  iterswptr--) {
1428  iterswptr->lower_bound = -1;
1429  iterswptr->upper_bound = -1;
1430  iterswptr->min_listed = -1;
1431  }
1432 
1433  TIMER_CONFIGURE(0);
1434  reset_trickle_timer(0);
1435  TIMER_CONFIGURE(1);
1436  reset_trickle_timer(1);
1437  return;
1438 }
1439 /*---------------------------------------------------------------------------*/
1440 /**
1441  * \brief The ROLL TM engine driver
1442  */
1444  "ROLL TM",
1445  init,
1446  out,
1447  in,
1448 };
1449 /*---------------------------------------------------------------------------*/
1450 /** @} */
#define UIP_IP_BUF
Pointer to IP header.
Definition: uip-nd6.c:97
#define ROLL_TM_WINS
Number of Sliding Windows In essence: How many unique sources of simultaneous multicast traffic do we...
Definition: roll-tm.h:175
#define SLIDING_WINDOW_M_CLR(w)
Clear M bit for window w w: pointer to a sliding window.
Definition: roll-tm.c:258
#define SEQ_VAL_IS_EQ(i1, i2)
s1 is said to be equal s2 iif SEQ_VAL_IS_EQ(s1, s2) == 1
Definition: roll-tm.c:169
uip_lladdr_t uip_lladdr
Host L2 address.
Definition: uip6.c:107
uint8_t tcpip_output(const uip_lladdr_t *a)
Output packet to layer 2 The eventual parameter is the MAC address of the destination.
Definition: tcpip.c:110
#define SLIDING_WINDOW_LISTED_SET(w)
Set &#39;Is Seen&#39; bit for window w w: pointer to a sliding window.
Definition: roll-tm.c:234
Header file for ICMPv6 message and error handing (RFC 4443)
Multicast stats extension for the ROLL TM engine.
Definition: roll-tm.h:230
Header file for the implementation of the ROLL-TM multicast engine.
#define TRICKLE_TIME(m, d)
Convert a timer to a sane clock_time_t value after d doublings m is a value of Imin, d is a number of doublings Careful of overflows.
Definition: roll-tm.c:107
#define uip_is_addr_linklocal_allrouters_mcast(a)
Is IPv6 address a the link local all-routers multicast address.
Definition: uip.h:2006
#define MCAST_PACKET_IS_LISTED(p)
Is the message p listed in current ICMP message? p: pointer to a struct mcast_packet.
Definition: roll-tm.c:340
uint16_t uip_len
The length of the packet in the uip_buf buffer.
Definition: uip6.c:179
#define ROLL_TM_IP_HOP_LIMIT
Hop limit for ICMP messages.
Definition: roll-tm.h:74
#define ICMP6_ROLL_TM
ROLL Trickle Multicast.
Definition: uip-icmp6.h:71
The data structure used to represent a multicast engine.
Definition: uip-mcast6.h:100
void tcpip_ipv6_output(void)
This function does address resolution and then calls tcpip_output.
Definition: tcpip.c:636
#define SLIDING_WINDOW_IS_USED(w)
Is Occupied sliding window location w w: pointer to a sliding window.
Definition: roll-tm.c:215
#define ROLL_TM_ICMP_CODE
ROLL TM ICMPv6 code field.
Definition: roll-tm.h:73
#define UIP_ICMP_BUF
Pointer to ICMP header.
Definition: uip-nd6.c:98
#define TRICKLE_DWELL(t)
Convert Tdwell for a trickle timer to a sane clock_time_t value t is a pointer to the timer Careful o...
Definition: roll-tm.c:126
#define UIP_PROTO_HBHO
extension headers types
Definition: uip.h:1904
#define UIP_BUFSIZE
The size of the uIP packet buffer.
Definition: uipopt.h:154
A set of debugging macros for the IP stack
#define MCAST_PACKET_SEND_CLR(p)
Clear &#39;Must Send&#39; bit for message p p: pointer to a struct mcast_packet.
Definition: roll-tm.c:334
#define HBH_SET_M(h)
Set the Trickle Parametrization bit for a multicast HBHO header m: pointer to the HBHO header...
Definition: roll-tm.c:415
#define SEQUENCE_LIST_GET_S(l)
Get the Seed ID Length for an ICMPv6 sequence list l: pointer to a sequence list structure.
Definition: roll-tm.c:382
uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
Definition: uip6.c:2324
#define UIP_LLADDR_LEN
802.15.4 address
Definition: uip.h:148
const struct uip_mcast6_driver roll_tm_driver
The ROLL TM engine driver.
Definition: roll-tm.c:1443
#define TRICKLE_ACTIVE(t)
Convert Tactive for a trickle timer to a sane clock_time_t value t is a pointer to the timer Careful ...
Definition: roll-tm.c:119
This header file contains configuration directives for uIPv6 multicast support.
#define SLIDING_WINDOW_M_SET(w)
Set M bit for window w w: pointer to a sliding window.
Definition: roll-tm.c:252
uint8_t(* in)(void)
Process an incoming multicast datagram and determine whether it should be delivered up the stack or n...
Definition: uip-mcast6.h:138
#define SLIDING_WINDOW_GET_M(w)
Retrieve trickle parametrization for sliding window at location w w: pointer to a sliding window...
Definition: roll-tm.c:264
#define uip_is_addr_mcast_non_routable(a)
is address a non-routable multicast address.
Definition: uip.h:2124
static uint8_t accept(uint8_t in)
Processes an incoming or outgoing multicast message and determines whether it should be dropped or ac...
Definition: roll-tm.c:894
#define SLIDING_WINDOW_IS_USED_SET(w)
Set &#39;Is Used&#39; bit for window w w: pointer to a sliding window.
Definition: roll-tm.c:221
#define UIP_LLH_LEN
The link level header length.
Definition: uipopt.h:141
#define SLIDING_WINDOW_IS_LISTED(w)
Is the sliding window at location w listed in current ICMP message? w: pointer to a sliding window...
Definition: roll-tm.c:246
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
Definition: ctimer.c:99
#define uip_is_addr_unspecified(a)
Is IPv6 address a the unspecified address a is of type uip_ipaddr_t.
Definition: uip.h:1982
#define MCAST_PACKET_USED_SET(p)
Set &#39;Is Used&#39; bit for packet p p: pointer to a packet buffer.
Definition: roll-tm.c:306
#define SUPPRESSION_DISABLED(t)
Check if suppression is disabled for trickle_param t t is a pointer to the timer. ...
Definition: roll-tm.c:138
clock_time_t clock_time(void)
Get the current clock time.
Definition: clock.c:118
#define SEQ_VAL_ADD(s, n)
Add n to s: (s + n) modulo (2 ^ SERIAL_BITS) => ((s + n) % 0x8000)
Definition: roll-tm.c:194
#define MCAST_PACKET_MUST_SEND(p)
Must we send this message this pass?
Definition: roll-tm.c:322
#define SEQUENCE_LIST_GET_M(l)
Get the Trickle Parametrization for an ICMPv6 sequence list l: pointer to a sequence list structure...
Definition: roll-tm.c:375
#define MCAST_PACKET_SEND_SET(p)
Set &#39;Must Send&#39; bit for message p p: pointer to a struct mcast_packet.
Definition: roll-tm.c:328
#define HBH_GET_M(h)
Get the Trickle Parametrization for a multicast HBHO header m: pointer to the HBHO header...
Definition: roll-tm.c:409
void(* out)(void)
Process an outgoing datagram with a multicast IPv6 destination address.
Definition: uip-mcast6.h:120
#define ROLL_TM_BUFF_NUM
Maximum Number of Buffered Multicast Messages This buffer is shared across all Seed IDs...
Definition: roll-tm.h:187
#define ROLL_TM_VER
Supported Draft Version.
Definition: roll-tm.h:72
void(* init)(void)
Initialize the multicast engine.
Definition: uip-mcast6.h:105
uint8_t uip_ext_len
The length of the extension headers.
Definition: uip6.c:132
#define SUPPRESSION_ENABLED(t)
Check if suppression is enabled for trickle_param t t is a pointer to the timer.
Definition: roll-tm.c:132
#define SLIDING_WINDOW_LISTED_CLR(w)
Clear &#39;Is Seen&#39; bit for window w w: pointer to a sliding window.
Definition: roll-tm.c:240
uint16_t uip_icmp6chksum(void)
Calculate the ICMP checksum of the packet in uip_buf.
Definition: uip6.c:384
#define uip_is_addr_linklocal_allnodes_mcast(a)
Is IPv6 address a the link local all-nodes multicast address.
Definition: uip.h:1993
#define MCAST_PACKET_FREE(p)
Free a multicast packet buffer p: pointer to a struct mcast_packet.
Definition: roll-tm.c:358
void uip_icmp6_register_input_handler(uip_icmp6_input_handler_t *handler)
Register a handler which can handle a specific ICMPv6 message type.
Definition: uip-icmp6.c:106
#define MCAST_PACKET_LISTED_CLR(p)
Clear &#39;Is Listed&#39; bit for message p p: pointer to a struct mcast_packet.
Definition: roll-tm.c:352
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:85
#define SEQ_VAL_IS_LT(i1, i2)
s1 is said to be less than s2 iif SEQ_VAL_IS_LT(s1, s2) == 1
Definition: roll-tm.c:174
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
Definition: random.c:58
#define uip_is_addr_linklocal(a)
is addr (a) a link local unicast address, see RFC 4291 i.e.
Definition: uip.h:2023
#define MCAST_PACKET_LISTED_SET(p)
Set &#39;Is Listed&#39; bit for message p p: pointer to a struct mcast_packet.
Definition: roll-tm.c:346
#define MCAST_PACKET_TTL(p)
Get the TTL of a buffered packet p: pointer to a packet buffer.
Definition: roll-tm.c:299
#define MCAST_PACKET_IS_USED(p)
Is Occupied buffer location p.
Definition: roll-tm.c:317
#define HBH_GET_SV_MSB(h)
Retrieve the Sequence Value MSB from a multicast HBHO header m: pointer to the HBHO header...
Definition: roll-tm.c:421
#define TIMER_CONFIGURE(m)
Init trickle_timer[m].
Definition: roll-tm.c:143
void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Source address selection, see RFC 3484.
Definition: uip-ds6.c:519
#define SEQ_VAL_IS_GT(i1, i2)
s1 is said to be greater than s2 iif SEQ_VAL_IS_LT(s1, s2) == 1
Definition: roll-tm.c:184