Blame view

RIOT/sys/include/net/gnrc/sixlowpan/nd.h 10.1 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
  /*
   * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    net_gnrc_sixlowpan_nd 6LoWPAN neighbor discovery
   * @ingroup     net_gnrc_sixlowpan
   * @brief       Neighbor Discovery Optimization for 6LoWPAN
   * @see         <a href="https://tools.ietf.org/html/rfc6775">
   *                  RFC 6775
   *              </a>
   * @{
   *
   * @file
   * @brief   General 6LoWPAN ND definitions
   *
   * @author  Martine Lenders <mlenders@inf.fu-berlin.de>
   */
  #ifndef NET_GNRC_SIXLOWPAN_ND_H
  #define NET_GNRC_SIXLOWPAN_ND_H
  
  #include <stdint.h>
  
  #include "kernel_types.h"
  #include "net/gnrc/ipv6/nc.h"
  #include "net/gnrc/ipv6/netif.h"
  #include "net/ipv6/addr.h"
  #include "net/ndp.h"
  #include "net/sixlowpan/nd.h"
  #include "timex.h"
  
  #include "net/gnrc/sixlowpan/nd/border_router.h"
  #include "net/gnrc/sixlowpan/nd/router.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @brief   Message type for next multicast router solicitation.
   */
  #define GNRC_SIXLOWPAN_ND_MSG_MC_RTR_SOL    (0x0220)
  
  /**
   * @brief   Message type for next unicast router solicitation.
   */
  #define GNRC_SIXLOWPAN_ND_MSG_UC_RTR_SOL    (0x0221)
  
  /**
   * @brief   Message type for removing 6LoWPAN contexts.
   */
  #define GNRC_SIXLOWPAN_ND_MSG_DELETE_CTX    (0x0222)
  
  /**
   * @brief   Message type for authoritative border router timeout
   */
  #define GNRC_SIXLOWPAN_ND_MSG_ABR_TIMEOUT   (0x0223)
  
  /**
   * @brief   Message type for address registration timeout
   */
  #define GNRC_SIXLOWPAN_ND_MSG_AR_TIMEOUT    (0x0224)
  
  #ifndef GNRC_SIXLOWPAN_ND_AR_LTIME
  /**
   * @brief   Registration lifetime in minutes for the address registration option
   *
   * This value should be adapted to the devices power-lifecycle so that it is greater than the
   * time the device spends sleeping.
   *
   * @see <a href="https://tools.ietf.org/html/rfc6775#section-5.8.1">
   *          RFC 6775, section 5.8.1
   *      </a>
   */
  #define GNRC_SIXLOWPAN_ND_AR_LTIME          (15U)
  #endif
  
  /**
   * @name    Border router constants
   * @{
   * @see     <a href="https://tools.ietf.org/html/rfc6775#section-9">
   *              RFC 6775, section 9
   *          </a>
   */
  #define GNRC_SIXLOWPAN_ND_RTR_MIN_CTX_DELAY (300U)  /**< minimum delay between context change and
                                                       *   stop of C=0 dissimination in seconds */
  /** @} */
  /**
   * @name    Host constants
   * @{
   * @see     <a href="https://tools.ietf.org/html/rfc6775#section-9">
   *              RFC 6775, section 9
   *          </a>
   */
  #define GNRC_SIXLOWPAN_ND_RTR_SOL_INT       (10U)   /**< replacement value (in seconds) for
                                                       *   @ref GNRC_NDP_MAX_RTR_SOL_INT */
  #define GNRC_SIXLOWPAN_ND_MAX_RTR_SOL_INT   (60U)   /**< retransmission increment for exponential
                                                       *   backoff of subsequent RS */
  /** @} */
  /**
   * @name    Router constants
   * @{
   * @see     <a href="https://tools.ietf.org/html/rfc6775#section-9">
   *              RFC 6775, section 9
   *          </a>
   */
  #define GNRC_SIXLOWPAN_ND_MIN_RTR_ADV_DELAY (10U)   /**< replacement value (in seconds) for
                                                       *   @ref GNRC_NDP_MIN_RTR_ADV_DELAY */
  /**
   * @brief   replacement value (in microseconds) for @ref GNRC_NDP_MAX_RTR_ADV_DELAY
   */
  #define GNRC_SIXLOWPAN_ND_MAX_RTR_ADV_DELAY (2U * US_PER_SEC)
  /**
   * @brief   Lifetime of a tentative address entry in seconds
   */
  #define GNRC_SIXLOWPAN_ND_TENTATIVE_NCE_LIFETIME    (20U)
  /**
   * @brief   6LoWPAN Multihop Hoplimit
   */
  #define GNRC_SIXLOWPAN_ND_MULTIHOP_HOPLIMIT (64U)
  /** @} */
  
  /**
   * @brief   Initializes 6LoWPAN neighbor discovery for the interface.
   * @pre     @p iface->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN
   * @param[in] iface An IPv6 interface.
   */
  void gnrc_sixlowpan_nd_init(gnrc_ipv6_netif_t *iface);
  
  /**
   * @brief   Multicasts a router solicitation over @p iface
   * @pre     @p iface->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN
   * @param[in] iface An IPv6 interface.
   */
  void gnrc_sixlowpan_nd_mc_rtr_sol(gnrc_ipv6_netif_t *iface);
  
  /**
   * @brief   Unicasts a router solicitation to the neighbor represented by @p nce
   * @pre     @p nce->iface is an IPv6 interface and @ref GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN is set
   *          in its flags.
   * @param[in] nce   The neighbor to send the router solicitation to.
   */
  void gnrc_sixlowpan_nd_uc_rtr_sol(gnrc_ipv6_nc_t *nce);
  
  /**
   * @brief   Get link-layer address and interface for next hop to destination
   *          IPv6 address.
   *
   * @param[out] l2addr           The link-layer for the next hop to @p dst.
   * @param[out] l2addr_len       Length of @p l2addr.
   * @param[in] iface             The interface to search the next hop on.
   *                              May be @ref KERNEL_PID_UNDEF if not specified.
   * @param[in] dst               An IPv6 address to search the next hop for.
   *
   * @return  The PID of the interface, on success.
   * @return  -EHOSTUNREACH, if @p dst is not reachable.
   * @return  -ENOBUFS, if @p l2addr_len was smaller than the resulting @p l2addr
   *          would be long.
   */
  kernel_pid_t gnrc_sixlowpan_nd_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len,
                                                 kernel_pid_t iface, ipv6_addr_t *dst);
  
  /**
   * @brief   Reschedules the next router advertisement for a neighboring router.
   *
   * @pre nce != NULL && sec_delay != 0U
   *
   * @param[in] nce       Neighbor cache entry representing the neighboring router.
   * @param[in] sec_delay The delay for the next router solicitation in seconds.
   */
  void gnrc_sixlowpan_nd_rtr_sol_reschedule(gnrc_ipv6_nc_t *nce, uint32_t sec_delay);
  
  /**
   * @brief   Builds the address registration option.
   *
   * @param[in] status    Status for the ARO.
   * @param[in] ltime     Registration lifetime for the ARO.
   * @param[in] eui64     The EUI-64 for the ARO
   * @param[in] next          More options in the packet. NULL, if there are none.
   *
   * @return  The pkt snip list of options, on success
   * @return  NULL, if packet buffer is full
   */
  gnrc_pktsnip_t *gnrc_sixlowpan_nd_opt_ar_build(uint8_t status, uint16_t ltime, eui64_t *eui64,
                                                 gnrc_pktsnip_t *next);
  
  /**
   * @brief   Handles address registration option.
   *
   * @param[in] iface         The interface the ARO was received on.
   * @param[in] ipv6          The IPv6 header the ARO was received in.
   * @param[in] icmpv6_type   Message type of the ICMPv6 message that contained.
   *                          this message.
   * @param[in] addr          The IPv6 address to register.
   * @param[in] ar_opt        The address registration option.
   * @param[in] sl2a          The link-layer source address contained in SL2A accompanying this
   *                          option. May be NULL for icmpv6_type == ICMPV6_NBR_ADV.
   * @param[in] sl2a_len      Length of @p sl2a. May be 0 if sl2a == NULL.
   *
   * @return  Status for the ARO in the replying NA (always 0 if icmpv6_type == ICMPV6_NBR_ADV).
   */
  uint8_t gnrc_sixlowpan_nd_opt_ar_handle(kernel_pid_t iface, ipv6_hdr_t *ipv6,
                                          uint8_t icmpv6_type, ipv6_addr_t *addr,
                                          sixlowpan_nd_opt_ar_t *ar_opt,
                                          uint8_t *sl2a, size_t sl2a_len);
  
  /**
   * @brief   Handles 6LoWPAN context option.
   *
   * @param[in] icmpv6_type   Message type of the ICMPv6 message that contained.
   *                          this message.
   * @param[in] ctx_opt       The 6LoWPAN context option.
   *
   * @return  true, when 6LoWPAN context option was correct.
   * @return  false, when it was incorrect.
   */
  bool gnrc_sixlowpan_nd_opt_6ctx_handle(uint8_t icmpv6_type, sixlowpan_nd_opt_6ctx_t *ctx_opt);
  
  /**
   * @brief   Handles registration calls after node-wakeup.
   *
   * @see     <a href="https://tools.ietf.org/html/rfc6775#section-5.8.2">
   *              RFC 6776, section 5.8.2
   *          </a>
   */
  void gnrc_sixlowpan_nd_wakeup(void);
  
  #ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
  /**
   * @brief   Handles authoritative border router option.
   *
   * @param[in] iface         Interface the source link-layer option was received
   *                          on.
   * @param[in] rtr_adv       The router advertisement containing the ABRO.
   * @param[in] icmpv6_size   The size of the @p rtr_adv.
   * @param[in] abr_opt       The ABRO.
   *
   * @note    Erroneous ABROs are always ignored silently.
   */
  void gnrc_sixlowpan_nd_opt_abr_handle(kernel_pid_t iface, ndp_rtr_adv_t *rtr_adv, int icmpv6_size,
                                        sixlowpan_nd_opt_abr_t *abr_opt);
  
  /**
   * @brief   Builds the 6LoWPAN context option.
   *
   * @param[in] prefix_len    The length of the context's prefix.
   * @param[in] flags         Flags + CID for the context.
   * @param[in] ltime         Lifetime of the context.
   * @param[in] prefix        The context's prefix
   * @param[in] next      More options in the packet. NULL, if there are none.
   *
   * @return  The pkt snip list of options, on success
   * @return  NULL, if packet buffer is full or on error
   */
  gnrc_pktsnip_t *gnrc_sixlowpan_nd_opt_6ctx_build(uint8_t prefix_len, uint8_t flags, uint16_t ltime,
                                                   ipv6_addr_t *prefix, gnrc_pktsnip_t *next);
  
  /**
   * @brief   Builds the authoritative border router option.
   *
   * @param[in] version   Version of the border router information.
   * @param[in] ltime     Registration lifetime for the border router.
   * @param[in] braddr    The IPv6 address of the border router.
   * @param[in] next      More options in the packet. NULL, if there are none.
   *
   * @return  The pkt snip list of options, on success
   * @return  NULL, if packet buffer is full or on error
   */
  gnrc_pktsnip_t *gnrc_sixlowpan_nd_opt_abr_build(uint32_t version, uint16_t ltime,
                                                  ipv6_addr_t *braddr, gnrc_pktsnip_t *next);
  #else
  #define gnrc_sixlowpan_nd_opt_abr_handle(iface, rtr_adv, icmpv6_size, abr_opt)
  #define gnrc_sixlowpan_nd_opt_6ctx_build(prefix_len, flags, ltime, prefix, next)        (NULL)
  #define gnrc_sixlowpan_nd_opt_abr_build(version, ltime, braddr, next)                   (NULL)
  #endif
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* NET_GNRC_SIXLOWPAN_ND_H */
  /** @} */