ctx.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
26 #ifndef NET_GNRC_SIXLOWPAN_CTX_H
27 #define NET_GNRC_SIXLOWPAN_CTX_H
28 
29 #include <inttypes.h>
30 #include <stdbool.h>
31 
32 #include "net/ipv6/addr.h"
33 #include "timex.h"
34 #include "modules.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #define GNRC_SIXLOWPAN_CTX_SIZE (16)
48 #define GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK (0x0f)
49 #define GNRC_SIXLOWPAN_CTX_FLAGS_COMP (0x10)
57 typedef struct {
59  uint8_t prefix_len;
68  uint8_t flags_id;
76  uint16_t ltime;
78 
88 
98 
115  uint8_t prefix_len, uint16_t ltime,
116  bool comp);
117 
123 static inline void gnrc_sixlowpan_ctx_remove(uint8_t id)
124 {
125  if (IS_USED(MODULE_GNRC_SIXLOWPAN_CTX)) {
127  }
128 }
129 
139 static inline bool gnrc_sixlowpan_ctx_match(const gnrc_sixlowpan_ctx_t *ctx,
140  const ipv6_addr_t *prefix, uint8_t prefix_len)
141 {
142  return (ctx != NULL) &&
143  (ctx->prefix_len == prefix_len) &&
144  (ipv6_addr_match_prefix(&ctx->prefix, prefix) >= prefix_len);
145 }
146 
158 static inline bool gnrc_sixlowpan_ctx_update_6ctx(const ipv6_addr_t *prefix, uint8_t prefix_len,
159  uint32_t valid)
160 {
161  if (!IS_USED(MODULE_GNRC_SIXLOWPAN_CTX)) {
162  return false;
163  }
164 
166  uint8_t cid = 0;
167 
168  if (!gnrc_sixlowpan_ctx_match(ctx, prefix, prefix_len)) {
169  /* While the context is a prefix match, the defined prefix within the
170  * context does not match => use new context */
171  ctx = NULL;
172  }
173  else {
175  }
176  /* find first free context ID */
177  if (ctx == NULL) {
178  while (((ctx = gnrc_sixlowpan_ctx_lookup_id(cid)) != NULL) &&
179  !gnrc_sixlowpan_ctx_match(ctx, prefix, prefix_len)) {
180  cid++;
181  }
182  }
183  if (cid < GNRC_SIXLOWPAN_CTX_SIZE) {
184  return gnrc_sixlowpan_ctx_update(cid, (ipv6_addr_t *)prefix, prefix_len,
185  valid / (60 * MS_PER_SEC),
186  true);
187  }
188 
189  return false;
190 }
191 
192 #ifdef TEST_SUITES
197 #endif
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif /* NET_GNRC_SIXLOWPAN_CTX_H */
gnrc_sixlowpan_ctx_t * gnrc_sixlowpan_ctx_update(uint8_t id, const ipv6_addr_t *prefix, uint8_t prefix_len, uint16_t ltime, bool comp)
Updates (or adds if currently not registered) a context.
static bool gnrc_sixlowpan_ctx_update_6ctx(const ipv6_addr_t *prefix, uint8_t prefix_len, uint32_t valid)
Create or update a compression context.
Definition: ctx.h:158
static bool gnrc_sixlowpan_ctx_match(const gnrc_sixlowpan_ctx_t *ctx, const ipv6_addr_t *prefix, uint8_t prefix_len)
Check if a prefix matches a compression context.
Definition: ctx.h:139
static void gnrc_sixlowpan_ctx_remove(uint8_t id)
Removes context.
Definition: ctx.h:123
void gnrc_sixlowpan_ctx_reset(void)
Resets the whole context buffer.
#define GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK
mask for the Context ID.
Definition: ctx.h:48
#define GNRC_SIXLOWPAN_CTX_SIZE
maximum number of entries in context buffer
Definition: ctx.h:40
gnrc_sixlowpan_ctx_t * gnrc_sixlowpan_ctx_lookup_id(uint8_t id)
Gets context by ID.
gnrc_sixlowpan_ctx_t * gnrc_sixlowpan_ctx_lookup_addr(const ipv6_addr_t *addr)
Gets a context matching the given IPv6 address best with its prefix.
uint8_t ipv6_addr_match_prefix(const ipv6_addr_t *a, const ipv6_addr_t *b)
Checks up to which bit-count two IPv6 addresses match in their prefix.
#define MS_PER_SEC
The number of milliseconds per second.
Definition: time_units.h:75
Adds include for missing inttype definitions.
Definitions for IPv6 addresses.
Common macros and compiler attributes/pragmas configuration.
#define IS_USED(module)
Checks whether a module is being used or not.
Definition: modules.h:71
Entry in the 6LoWPAN context buffer.
Definition: ctx.h:57
uint8_t prefix_len
Length of gnrc_sixlowpan_ctx_t::prefix in bit.
Definition: ctx.h:59
uint16_t ltime
Lifetime in minutes this context is valid.
Definition: ctx.h:76
ipv6_addr_t prefix
The prefix associated to this context.
Definition: ctx.h:58
uint8_t flags_id
4-bit flags, 4-bit Context ID.
Definition: ctx.h:68
Utility library for comparing and computing timestamps.
Data type to represent an IPv6 address.
Definition: addr.h:72