Contiki 3.x
sicslow_ethernet.c
Go to the documentation of this file.
1 /**
2  * \file sicslow_ethernet.c
3  * Routines to interface between Ethernet and 6LowPan
4  *
5  * \author
6  * Colin O'Flynn <coflynn@newae.com>
7  *
8  * \addtogroup usbstick
9  */
10 
11 /* Copyright (c) 2008 by:
12  * Colin O'Flynn coflynn@newae.com
13  * Eric Gnoske egnoske@gmail.com
14  * Blake Leverett bleverett@gmail.com
15  * Mike Vidales mavida404@gmail.com
16  * Kevin Brown kbrown3@uccs.edu
17  * Nate Bohlmann nate@elfwerks.com
18  *
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions
23  * are met:
24  *
25  * * Redistributions of source code must retain the above copyright
26  * notice, this list of conditions and the following disclaimer.
27  * * Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in
29  * the documentation and/or other materials provided with the
30  * distribution.
31  * * Neither the name of the copyright holders nor the names of
32  * contributors may be used to endorse or promote products derived
33  * from this software without specific prior written permission.
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
39  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
42  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
43  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45  * POSSIBILITY OF SUCH DAMAGE.
46  */
47 
48 /**
49  \ingroup usbstick
50  \defgroup sicslowinterop 6LowPan Ethernet Interop
51  @{
52 */
53 
54 //TODO: Should be able to always use this SIMPLE mode, hence can remove the 'complex' mode permanently
55 //TODO: RF230BB !SIMPLE works on XP, Ubuntu. SIMPLE works on Vista, W7. Find out why!
56 
57 #ifndef UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
58 #define UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS 0
59 #endif // ifndef UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
60 
61 #ifndef UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR
62 #define UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR 1
63 #endif // ifndef UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR
64 
65 #if UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
66 /**
67  \par Ethernet to 6LowPan Address Translation
68 
69  It should be obvious that since 802.15.4 addresses are 8
70  bytes, and 802.3 addresses are 6 bytes, some form of
71  address translation is needed. These routines provide this
72 
73  \par Address Translation on Packets coming FROM Ethernet
74 
75  Packets coming from Ethernet, have any addresses inside
76  IPv6 packets (such as 'source link-layer address') expanded
77  by inserting a 0xFF 0xFE sequence as such:
78 
79  \verbatim
80  AA:BB:CC:DD:EE:FF
81 
82  becomes
83 
84  AA:BB:CC:FF:FE:DD:EE:FF
85  \endverbatim
86 
87  The 802.15.4 destination address is always derived from the IPv6
88  destination address.
89 
90  \par Address Translation on Packets coming FROM 802.15.4
91 
92  Packets coming from 802.15.4, have any addresses inside IPv6
93  packets (such as a 'source link-layer address') replaced
94  with the local_ethernet_addr, defined to 3A:3B:3C:3D:3E:3F here.
95 
96  The destination ethernet address is performed by performing
97  the reverse process used to make the 802.15.4 addresses before.
98 
99  \par Comments on Using This
100 
101  Thus you always send IPv6 messages to the local_ethernet_addr,
102  which is 3A:3B:3C:3D:3E:3F. The actual 802.15.4 destination
103  address is based on the lower 64-bits of your IPv6 destination
104  address. IPv6 addresses must always be based on link-layer
105  addresses in the 802.15.4 network for this to work.
106 
107  \par Notes on how addresses are stored
108 
109  An 802.15.4 address will be reported for example as:
110 
111  0x8877665544332211
112 
113  Stored in the array as passed to these functions, it will be:
114  \verbatim
115  array[0] = 0x88;
116  array[1] = 0x77;
117  array[2] = 0x66;
118  etc.
119  \endverbatim
120 
121  An 802.3 address will be reported for example as:
122  02:43:53:35:45:45
123 
124  Stored in the array as passed to these functions, it will be:
125  \verbatim
126  array[0] = 0x02;
127  array[1] = 0x43;
128  array[2] = 0x53;
129  array[3] = 0x35
130  etc.
131  \endverbatim
132 */
133 #else
134 /**
135  \par Ethernet to 6LowPan Address Translation
136 
137  It should be obvious that since 802.15.4 addresses are 8
138  bytes, and 802.3 addresses are 6 bytes, some form of
139  address translation is needed. These routines provide this
140 
141  \par 802.3 Address Formats
142 
143  802.3 MAC addresses used here have this form:
144 
145  \verbatim
146  +----+----+----+----+----+----+----+----+
147  + + + + + + TR + GL + MU +
148  +----+----+----+----+----+----+----+----+
149  \endverbatim
150 
151 
152  It can be seen this is like a normal ethernet MAC address,
153  with GL being the Global/Local bit, and MU being the
154  Multicast/Unicast bit.
155 
156  The addition is the 'TR' bit, which if set indicates that
157  the address must be translated when going between 802.15.4
158  and 802.3.
159 
160  \par Address Translation
161 
162  If the TRANSLATE (TR) bit is CLEAR, this means the 5th and
163  4th LSBytes of the 802.15.4 address are fffe, aka the address
164  has the hexidecial form:
165 
166  xxxxxxfffexxxxxx
167 
168  \note
169  You should always aim to set the 802.15.4 addresses
170  of the devices on your network to ones that will
171  satisfy this requirement. Some examples are:
172  \note
173  0x02 23 42 ff fe 73 92 28
174  \note
175  0x82 00 82 ff fe cd ee 22
176 
177  \note
178  So the most significant octets MUST
179  have bit 0 CLEAR, bit 1 SET, and bit 2 CLEAR. The remaining
180  bits in this octet can be anything.
181 
182  If the TRANSLATE bit is SET, this means the address on the
183  802.3 side does not directly convert to an 802.15.4 address.
184  To translate it, the remainder of the octet is used as an
185  index in a look-up table. This look-up table simply stores
186  the 4th, 5th, and 8th octet of the 802.15.4 address, and attaches
187  them to the remaining 5 bytes of the 802.3 address.
188 
189  In this way there can be 32 different 802.15.4 'prefixes',
190  requiring only 96 bytes of RAM in a storage table on the
191  802.3 to 802.15.4 bridge.
192 
193  Mulitcast addresses on 802.3 are mapped to broadcast addresses on
194  802.15.4 and vis-versa. Since IPv6 does not use 802.3 broadcast,
195  this code will drop all 802.3 broadcast packets. They are most
196  likely something unwanted, such as IPv4 packets that snuck in.
197 
198  \par Notes on how addresses are stored
199 
200  An 802.15.4 address will be reported for example as:
201 
202  0x8877665544332211
203 
204  Stored in the array as passed to these functions, it will be:
205  \verbatim
206  array[0] = 0x88;
207  array[1] = 0x77;
208  array[2] = 0x66;
209  etc.
210  \endverbatim
211 
212  An 802.3 address will be reported for example as:
213  02:43:53:35:45:45
214 
215  Stored in the array as passed to these functions, it will be:
216  \verbatim
217  array[0] = 0x02;
218  array[1] = 0x43;
219  array[2] = 0x53;
220  array[3] = 0x35
221  etc.
222  \endverbatim
223 */
224 #endif
225 
226 #include "uip.h"
227 #include "uip_arp.h" //For ethernet header structure
228 
229 #include "net/rime/rime.h"
230 #include "sicslowpan.h"
231 #include "sicslow_ethernet.h"
232 #if !RF230BB
233 #include "zmac.h"
234 #include "frame.h"
235 #include "radio.h"
236 #endif
237 #include "rndis/rndis_protocol.h"
238 #include "rndis/rndis_task.h"
239 
240 #include <stdint.h>
241 #include <stdio.h>
242 #include <string.h>
243 
244 #define DEBUG 0
245 #if DEBUG
246 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
247 #else
248 #define PRINTF(...)
249 #endif
250 
251 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
252 #define ETHBUF(x) ((struct uip_eth_hdr *)x)
253 
254 //For little endian, such as our friend mr. AVR
255 #ifndef LSB
256 #define LSB(u16) (((uint8_t *)&(u16))[0]) //!< Least significant byte of \a u16.
257 #define MSB(u16) (((uint8_t *)&(u16))[1]) //!< Most significant byte of \a u16.
258 #endif
259 
260 static const uint64_t simple_trans_ethernet_addr = 0x3E3D3C3B3AF2ULL;
261 
262 #if UIP_CONF_IPV6_RPL
263 static uip_ipaddr_t last_sender;
264 #endif
265 
266 extern uint64_t usb_ethernet_addr;
267 
268 extern uint64_t macLongAddr;
269 
270 #if !RF230BB
271 extern void (*pinput)(const struct mac_driver *r);
272 void (*sicslowinput)(const struct mac_driver *r);
273 parsed_frame_t * parsed_frame;
274 #endif
275 usbstick_mode_t usbstick_mode;
276 
277 uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan);
278 uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan);
279 uint8_t mac_createDefaultEthernetAddr(uint8_t * ethernet);
280 void mac_ethhijack_nondata(const struct mac_driver *r);
281 void mac_ethhijack(const struct mac_driver *r);
282 
283 extern void (*sicslowmac_snifferhook)(const struct mac_driver *r);
284 
285 
286 //! Location of TRANSLATE (TR) bit in Ethernet address
287 #define TRANSLATE_BIT_MASK (1<<2)
288 //! Location of LOCAL (GL) bit in Ethernet address
289 #define LOCAL_BIT_MASK (1<<1)
290 //! Location of MULTICAST (MU) bit in Ethernet address
291 #define MULTICAST_BIT_MASK (1<<0)
292 
293 #define PREFIX_BUFFER_SIZE 32
294 
295 uint8_t prefixCounter;
296 uint8_t prefixBuffer[PREFIX_BUFFER_SIZE][3];
297 
298 /* 6lowpan max size + ethernet header size + 1 */
299 uint8_t raw_buf[127+ UIP_LLH_LEN +1];
300 
301 /**
302  * \brief Perform any setup needed
303  */
304 #if !RF230BB
305  struct mac_driver * pmac;
306 #endif
307 void mac_ethernetSetup(void)
308 {
309  usbstick_mode.sicslowpan = 1;
310  usbstick_mode.sendToRf = 1;
311  usbstick_mode.translate = 1;
312  usbstick_mode.debugOn= 1;
313  usbstick_mode.raw = 0;
314  usbstick_mode.sneeze=0;
315 
316 #if !RF230BB
317  sicslowinput = pinput;
318 
319  pmac = sicslowmac_get_driver();
320  pmac->set_receive_function(mac_ethhijack);
321  sicslowmac_snifferhook = mac_ethhijack_nondata;
322 #endif
323 }
324 
325 
326 /**
327  * \brief Take a packet received over the ethernet link, and send it
328  * out over 802.15.4
329  */
330 void mac_ethernetToLowpan(uint8_t * ethHeader)
331 {
332  //Dest address
333  uip_lladdr_t destAddr;
334  uip_lladdr_t *destAddrPtr = NULL;
335 
336  PRINTF("Packet type: 0x%04x\n\r", uip_ntohs(((struct uip_eth_hdr *) ethHeader)->type));
337 
338  //RUM doesn't support sending data
339  #if UIP_CONF_USE_RUM
340  return;
341  #endif
342 
343  /* In sniffer or sneezr mode we don't ever send anything */
344  if ((usbstick_mode.sendToRf == 0) || (usbstick_mode.sneeze != 0)) {
345  uip_clear_buf();
346  return;
347  }
348 
349 
350  /* If not IPv6 we don't do anything. Disable ipv4 on the interface to prevent possible hangs from discovery packet flooding */
351  if (((struct uip_eth_hdr *) ethHeader)->type != UIP_HTONS(UIP_ETHTYPE_IPV6)) {
352  PRINTF("eth2low: Dropping packet w/type=0x%04x\n",uip_ntohs(((struct uip_eth_hdr *) ethHeader)->type));
353  // printf("!ipv6");
354 #if !RF230BB
355  usb_eth_stat.txbad++;
356 #endif
357  uip_clear_buf();
358  return;
359  }
360 
361  /* IPv6 uses 33-33-xx-xx-xx-xx prefix for multicast ND stuff */
362  if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0x33) &&
363  (((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0x33) )
364  {
365  PRINTF("eth2low: Ethernet multicast packet received\n\r");
366  ;//Do Nothing
367  } else if ( (((struct uip_eth_hdr *) ethHeader)->dest.addr[0] == 0xFF) &&
368  (((struct uip_eth_hdr *) ethHeader)->dest.addr[1] == 0xFF) &&
369  (((struct uip_eth_hdr *) ethHeader)->dest.addr[2] == 0xFF) &&
370  (((struct uip_eth_hdr *) ethHeader)->dest.addr[3] == 0xFF) &&
371  (((struct uip_eth_hdr *) ethHeader)->dest.addr[4] == 0xFF) &&
372  (((struct uip_eth_hdr *) ethHeader)->dest.addr[5] == 0xFF) ) {
373  /* IPv6 does not use broadcast addresses, hence this should not happen */
374  PRINTF("eth2low: Dropping broadcast packet\n\r");
375 #if !RF230BB
376  usb_eth_stat.txbad++;
377 #endif
378  uip_clear_buf();
379  return;
380  } else {
381 
382  /* Simple Address Translation */
383  if(memcmp((uint8_t *)&simple_trans_ethernet_addr, &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), 6) == 0) {
384 #if NETSTACK_CONF_WITH_IPV6
385  //Addressed to us: make 802.15.4 address from IPv6 Address
386  destAddr.addr[0] = UIP_IP_BUF->destipaddr.u8[8] ^ 0x02;
387  destAddr.addr[1] = UIP_IP_BUF->destipaddr.u8[9];
388  destAddr.addr[2] = UIP_IP_BUF->destipaddr.u8[10];
389  destAddr.addr[3] = UIP_IP_BUF->destipaddr.u8[11];
390  destAddr.addr[4] = UIP_IP_BUF->destipaddr.u8[12];
391  destAddr.addr[5] = UIP_IP_BUF->destipaddr.u8[13];
392  destAddr.addr[6] = UIP_IP_BUF->destipaddr.u8[14];
393  destAddr.addr[7] = UIP_IP_BUF->destipaddr.u8[15];
394 #else
395  //Not intended to be functional, but allows ip4 build without errors.
396  destAddr.addr[0] = UIP_IP_BUF->destipaddr.u8[0] ^ 0x02;
397  destAddr.addr[1] = UIP_IP_BUF->destipaddr.u8[1];
398  destAddr.addr[2] = UIP_IP_BUF->destipaddr.u8[2];
399  destAddr.addr[3] = UIP_IP_BUF->destipaddr.u8[3];
400  destAddr.addr[4] = UIP_IP_BUF->destipaddr.u8[0];
401  destAddr.addr[5] = UIP_IP_BUF->destipaddr.u8[1];
402  destAddr.addr[6] = UIP_IP_BUF->destipaddr.u8[2];
403  destAddr.addr[7] = UIP_IP_BUF->destipaddr.u8[3];
404 
405 #endif
406 
407  destAddrPtr = &destAddr;
408  }
409 #if UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
410  else {
411  //Not addressed to us
412  uip_clear_buf();
413  return;
414  }
415 #else
416 
417  /* Complex Address Translation */
418  PRINTF("eth2low: Addressed packet received... ");
419  //Check this returns OK
420  if (mac_createSicslowpanLongAddr( &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), &destAddr) == 0) {
421  PRINTF(" translation failed\n\r");
422 #if !RF230BB
423  usb_eth_stat.txbad++;
424 #endif
425  uip_clear_buf();
426  return;
427  }
428  PRINTF(" translated OK\n\r");
429  destAddrPtr = &destAddr;
430 #endif /* UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS */
431 
432 
433  }
434 
435  //Remove header from length before passing onward
436  uip_len -= UIP_LLH_LEN;
437 
438  //Some IP packets have link layer in them, need to change them around!
439  if (usbstick_mode.translate) {
440 #if DEBUG
441  uint8_t transReturn = mac_translateIPLinkLayer(ll_802154_type);
442  PRINTF("IPTranslation: returns %d\n\r", transReturn);
443 #else
444  mac_translateIPLinkLayer(ll_802154_type);
445 #endif
446  }
447 
448 #if NETSTACK_CONF_WITH_IPV6
449 /* Send the packet to the uip6 stack if it exists, else send to 6lowpan */
450 #if UIP_CONF_IPV6_RPL
451 /* Save the destination address, to trap ponging it back to the interface */
452  uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr);
453  tcpip_input();
454 #else
455 // PRINTF("Input from %x %x %x %x %x %x %x %x\n",UIP_IP_BUF->srcipaddr.u8[0],UIP_IP_BUF->srcipaddr.u8[1],UIP_IP_BUF->srcipaddr.u8[2],UIP_IP_BUF->srcipaddr.u8[3],UIP_IP_BUF->srcipaddr.u8[4],UIP_IP_BUF->srcipaddr.u8[5],UIP_IP_BUF->srcipaddr.u8[6],UIP_IP_BUF->srcipaddr.u8[7]);
456 // PRINTF("Output to %x %x %x %x %x %x %x %x\n",destAddr.addr[0],destAddr.addr[1],destAddr.addr[2],destAddr.addr[3],destAddr.addr[4],destAddr.addr[5],destAddr.addr[6],destAddr.addr[7]);
457  tcpip_output(destAddrPtr);
458 #endif
459 #else /* NETSTACK_CONF_WITH_IPV6 */
460  tcpip_output(); //Allow non-ipv6 builds (Hello World)
461 #endif /* NETSTACK_CONF_WITH_IPV6 */
462 
463 #if !RF230BB
464  usb_eth_stat.txok++;
465 #endif
466  uip_clear_buf();
467 
468 }
469 
470 
471 /**
472  * \brief Take a packet received over the 802.15.4 link, and send it
473  * out over ethernet, performing any translations needed.
474  */
476 {
477 #if !RF230BB
478  parsed_frame = sicslowmac_get_frame();
479 #endif
480 
481  //Setup generic ethernet stuff
482  ETHBUF(uip_buf)->type = uip_htons(UIP_ETHTYPE_IPV6);
483 
484 #if RF230BB
486 #else
487  if( ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) &&
488  ( parsed_frame->dest_addr->addr16 == 0xffff) ) {
489 #endif
490  ETHBUF(uip_buf)->dest.addr[0] = 0x33;
491  ETHBUF(uip_buf)->dest.addr[1] = 0x33;
492 
493 #if NETSTACK_CONF_WITH_IPV6
494  ETHBUF(uip_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12];
495  ETHBUF(uip_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13];
496  ETHBUF(uip_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14];
497  ETHBUF(uip_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15];
498 #else
499  //Not intended to be functional, but allows ip4 build without errors.
500  ETHBUF(uip_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[0];
501  ETHBUF(uip_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[1];
502  ETHBUF(uip_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[2];
503  ETHBUF(uip_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[3];
504 #endif
505  } else {
506  //Otherwise we have a real address
507  mac_createEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->dest.addr[0]),
508  (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
509  }
510 
511 #if !UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
512  //Source ethernet depends on node
514  (uint8_t *) &(ETHBUF(uip_buf)->src.addr[0]),
515  (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)
516  ))
517 #endif
518 
519  {
520  mac_createDefaultEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->src.addr[0]));
521  }
522 
523  //We only do address translation in network mode!
524  if (usbstick_mode.translate) {
525  //Some IP packets have link layer in them, need to change them around!
526  mac_translateIPLinkLayer(ll_8023_type);
527  }
528 
529 #if UIP_CONF_IPV6_RPL
530 /* We won't play ping-pong with the host! */
531  if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
532  PRINTF("siclow_ethernet: Destination off-link but no route\n");
533  uip_len=0;
534  return;
535  }
536 #endif
537 
538  PRINTF("Low2Eth: Sending packet to ethernet\n\r");
539 
540  uip_len += UIP_LLH_LEN;
541 
543 #if !RF230BB
544  usb_eth_stat.rxok++;
545 #endif
546  uip_clear_buf();
547 }
548 
549 /**
550  * \brief Translate IP packet's possible link-layer addresses, passing
551  * the message to the appropriate higher level function for this
552  * packet (aka: ICMP)
553  * \param target The target we want to end up with - either ll_8023_type
554  * for ethernet, or ll_802154_type for 802.15.4
555  * \return Returns how successful the translation was
556  * \retval 0 Addresses, if present, were translated.
557  * \retval <0 Negative return values indicate various errors, as defined
558  * by the higher level function.
559  */
560 int8_t mac_translateIPLinkLayer(lltype_t target)
561 {
562 
563 #if UIP_LLADDR_LEN == 8
564  if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6) {
565  PRINTF("eth2low: ICMP Message detected\n\r");
566  return mac_translateIcmpLinkLayer(target);
567  }
568  return 0;
569 #else
570  return 1;
571 #endif
572 
573 }
574 
575 #include "net/ipv6/uip-icmp6.h"
576 #include "net/ipv6/uip-nd6.h"
577 
578 typedef struct {
579  uint8_t type;
580  uint8_t length;
581  uint8_t data[16];
582 } icmp_opts_t;
583 
584 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
585 #define UIP_ICMP_OPTS(x) ((icmp_opts_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + x])
586 
587 void slide(uint8_t * data, uint8_t length, int16_t slide);
588 
589 /**
590  * \brief Translate the link-layer (L2) addresses in an ICMP packet.
591  * This will just be NA/NS/RA/RS packets currently.
592  * \param target The target we want to end up with - either ll_8023_type
593  * for ethernet, or ll_802154_type for 802.15.4
594  * \return Returns how successful the translation was
595  * \retval 0 Addresses, if present, were translated.
596  * \retval -1 ICMP message was unknown type, nothing done.
597  * \retval -2 ICMP Length does not make sense?
598  * \retval -3 Unknown 'target' type
599  */
600 int8_t mac_translateIcmpLinkLayer(lltype_t target)
601 {
602  uint16_t icmp_opt_offset = 0;
603  int16_t len = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0] << 8);
604 
605  uint16_t iplen;
606 
607  uint8_t i;
608 
609  int16_t sizechange;
610 
611  uint8_t llbuf[16];
612 
613  //Figure out offset to start of options
614  switch(UIP_ICMP_BUF->type) {
615  case ICMP6_NS:
616  case ICMP6_NA:
617  icmp_opt_offset = 24;
618  break;
619 
620  case ICMP6_RS:
621  icmp_opt_offset = 8;
622  break;
623 
624  case ICMP6_RA:
625  icmp_opt_offset = 16;
626  break;
627 
628  case ICMP6_REDIRECT:
629  icmp_opt_offset = 40;
630  break;
631 
632  /** Things without link-layer */
633  case ICMP6_DST_UNREACH:
635  case ICMP6_TIME_EXCEEDED:
636  case ICMP6_PARAM_PROB:
637  case ICMP6_ECHO_REQUEST:
638  case ICMP6_ECHO_REPLY:
639  return 0;
640  break;
641 
642  default:
643  return -1;
644  }
645 
646  //Figure out length of options
647  len -= icmp_opt_offset;
648 
649  //Sanity check
650  if (len < 8) return -2;
651 
652  //While we have options to do...
653  while (len >= 8){
654 
655  //If we have one of these, we have something useful!
656  if (((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_SLLAO) ||
657  ((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_TLLAO) ) {
658 
659  /* Shrinking the buffer may thrash things, so we store the old
660  link-layer address */
661  for(i = 0; i < (UIP_ICMP_OPTS(icmp_opt_offset)->length*8 - 2); i++) {
662  llbuf[i] = UIP_ICMP_OPTS(icmp_opt_offset)->data[i];
663  }
664 
665  //Shrink/grow buffer as needed
666  if (target == ll_802154_type) {
667  //Current is 802.3, Hence current link-layer option is 6 extra bytes
668  sizechange = 8;
669  slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 6, len - 6, sizechange);
670  } else if (target == ll_8023_type) {
671  /* Current is 802.15.4, Hence current link-layer option is 14 extra
672  * bytes.
673  * (Actual LL is 8 bytes, but total option length is in multiples of
674  * 8 Bytes, hence 8 + 2 = 10. Closest is 16 bytes, then 16 bytes for
675  * total optional length - 2 bytes for type + length leaves 14 )
676  */
677  sizechange = -8;
678  slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 14, len - 14, sizechange);
679  } else {
680  return -3; //Uh-oh!
681  }
682 
683  //Translate addresses
684  if (target == ll_802154_type) {
685  mac_createSicslowpanLongAddr(llbuf, (uip_lladdr_t *)UIP_ICMP_OPTS(icmp_opt_offset)->data);
686  } else {
687 #if !UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
688  if(!mac_createEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data, (uip_lladdr_t *)llbuf))
689 #endif
690  mac_createDefaultEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data);
691  }
692 
693  //Adjust the length
694  if (target == ll_802154_type) {
695  UIP_ICMP_OPTS(icmp_opt_offset)->length = 2;
696  } else {
697  UIP_ICMP_OPTS(icmp_opt_offset)->length = 1;
698  }
699 
700  //Adjust the IP header length, as well as uIP length
701  iplen = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0]<<8);
702  iplen += sizechange;
703  len += sizechange;
704 
705  UIP_IP_BUF->len[1] = (uint8_t)iplen;
706  UIP_IP_BUF->len[0] = (uint8_t)(iplen >> 8);
707 
708  uip_len += sizechange;
709 
710  //We broke ICMP checksum, be sure to fix that
711  UIP_ICMP_BUF->icmpchksum = 0;
712 #if NETSTACK_CONF_WITH_IPV6 //allow non ipv6 builds
713  UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
714 #endif
715 
716  //Finally set up next run in while loop
717  len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
718  icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
719  } else {
720 
721  //Not an option we care about, ignore it
722  len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
723 
724  //This shouldn't happen!
725  if (UIP_ICMP_OPTS(icmp_opt_offset)->length == 0) {
726  PRINTF("Option in ND packet has length zero, error?\n\r");
727  len = 0;
728  }
729 
730  icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
731 
732  } //If ICMP_OPT is one we care about
733 
734  } //while(len >= 8)
735 
736  return 0;
737 
738 }
739 
740 
741 /**
742  * \brief Create a 802.15.4 long address from a 802.3 address
743  * \param ethernet Pointer to ethernet address
744  * \param lowpan Pointer to 802.15.4 address
745  */
746 uint8_t mac_createSicslowpanLongAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
747 {
748 #if UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR
749  //Special case - if the address is our address, we just copy over what we know to be
750  //our 802.15.4 address
751  if (memcmp((uint8_t *)&usb_ethernet_addr, ethernet, 6) == 0)
752  {
753  memcpy((uint8_t *)lowpan, &macLongAddr, UIP_LLADDR_LEN);
754  return 1;
755  }
756 #endif
757 
758 #if UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
759 
760  //Easy does it!
761  lowpan->addr[0] = ethernet[0];
762  lowpan->addr[1] = ethernet[1];
763  lowpan->addr[2] = ethernet[2];
764  lowpan->addr[3] = 0xff;
765  lowpan->addr[4] = 0xfe;
766  lowpan->addr[5] = ethernet[3];
767  lowpan->addr[6] = ethernet[4];
768  lowpan->addr[7] = ethernet[5];
769 
770 #else //!UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
771 
772  uint8_t index;
773 
774 #if UIP_LLADDR_LEN == 8
775  //Check if translate bit is set, hence we have to look up the prefix
777  //Get top bits
778  index = ethernet[0] >> 3;
779 
780  //Copy over prefix
781  lowpan->addr[0] = prefixBuffer[index][0];
782  lowpan->addr[1] = prefixBuffer[index][1];
783  lowpan->addr[2] = prefixBuffer[index][2];
784  lowpan->addr[3] = ethernet[1];
785  lowpan->addr[4] = ethernet[2];
786 
787  //Check this is plausible...
788  if (index >= prefixCounter)
789  return 0;
790  } else {
791  lowpan->addr[0] = ethernet[0];
792  lowpan->addr[1] = ethernet[1];
793  lowpan->addr[2] = ethernet[2];
794  lowpan->addr[3] = 0xff;
795  lowpan->addr[4] = 0xfe;
796  }
797 
798  lowpan->addr[5] = ethernet[3];
799  lowpan->addr[6] = ethernet[4];
800  lowpan->addr[7] = ethernet[5];
801 
802 #else //UIP_LLADDR != 8
803  // Not sure when we would ever hit this case...
804  uint8_t i;
805  for(i = 0; i < UIP_LLADDR_LEN; i++) {
806  lowpan->addr[i] = ethernet[i];
807  }
808 #endif //UIP_LLADDR == 8
809 
810 #endif //UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
811 
812  return 1;
813 }
814 
815 
816 /**
817  * \brief Create a 802.3 address from a 802.15.4 long address
818  * \param ethernet Pointer to ethernet address
819  * \param lowpan Pointer to 802.15.4 address
820  */
821 uint8_t mac_createEthernetAddr(uint8_t * ethernet, uip_lladdr_t * lowpan)
822 {
823 #if UIP_CONF_AUTO_SUBSTITUTE_LOCAL_MAC_ADDR
824  //Special case - if the address is our address, we just copy over what we know to be
825  //our 802.3 address
826  if (memcmp((uint8_t *)&macLongAddr, (uint8_t *)lowpan, UIP_LLADDR_LEN) == 0) {
827  usb_eth_get_mac_address(ethernet);
828  return 1;
829  }
830 #endif
831 
832 #if UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
833 
834  /** Just copy over 6 bytes **/
835  ethernet[0] = lowpan->addr[0];
836  ethernet[1] = lowpan->addr[1];
837  ethernet[2] = lowpan->addr[2];
838  ethernet[3] = lowpan->addr[5];
839  ethernet[4] = lowpan->addr[6];
840  ethernet[5] = lowpan->addr[7];
841 
842 #else //!UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
843 
844  uint8_t index = 0;
845  uint8_t i;
846 
847 #if UIP_LLADDR_LEN == 8
848 
849  //Check if we need to do anything:
850  if ((lowpan->addr[3] == 0xff) && (lowpan->addr[4] == 0xfe) &&
851  ((lowpan->addr[0] & TRANSLATE_BIT_MASK) == 0) &&
852  ((lowpan->addr[0] & MULTICAST_BIT_MASK) == 0) &&
853  (lowpan->addr[0] & LOCAL_BIT_MASK)) {
854 
855  /** Nope: just copy over 6 bytes **/
856  ethernet[0] = lowpan->addr[0];
857  ethernet[1] = lowpan->addr[1];
858  ethernet[2] = lowpan->addr[2];
859  ethernet[3] = lowpan->addr[5];
860  ethernet[4] = lowpan->addr[6];
861  ethernet[5] = lowpan->addr[7];
862 
863 
864  } else {
865 
866  /** Yes: need to store prefix **/
867  for (i = 0; i < prefixCounter; i++) {
868  //Check the current prefix - if it fails, check next one
869  if ((lowpan->addr[0] == prefixBuffer[i][0]) &&
870  (lowpan->addr[1] == prefixBuffer[i][1]) &&
871  (lowpan->addr[2] == prefixBuffer[i][2])) {
872  break;
873  }
874  }
875  index = i;
876 
877  if (index >= PREFIX_BUFFER_SIZE) {
878  // Overflow. Fall back to simple translation.
879  // TODO: Implement me!
880  ethernet[0] = lowpan->addr[0];
881  ethernet[1] = lowpan->addr[1];
882  ethernet[2] = lowpan->addr[2];
883  ethernet[3] = lowpan->addr[5];
884  ethernet[4] = lowpan->addr[6];
885  ethernet[5] = lowpan->addr[7];
886  return 0;
887  } else {
888  //Are we making a new one?
889  if (index == prefixCounter) {
890  prefixCounter++;
891  prefixBuffer[index][0] = lowpan->addr[0];
892  prefixBuffer[index][1] = lowpan->addr[1];
893  prefixBuffer[index][2] = lowpan->addr[2];
894  }
895 
896  //Create ethernet MAC address now
897  ethernet[0] = TRANSLATE_BIT_MASK | LOCAL_BIT_MASK | (index << 3);
898  ethernet[1] = lowpan->addr[3];
899  ethernet[2] = lowpan->addr[4];
900  ethernet[3] = lowpan->addr[5];
901  ethernet[4] = lowpan->addr[6];
902  ethernet[5] = lowpan->addr[7];
903  }
904  }
905 
906 #else //UIP_LLADDR_LEN != 8
907  // Not sure when we would ever hit this case...
908  //Create ethernet MAC address now
909  for(i = 0; i < UIP_LLADDR_LEN; i++) {
910  ethernet[i] = lowpan->addr[i];
911  }
912 #endif //UIP_LLADDR_LEN == 8
913 
914 #endif //UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
915 
916  return 1;
917 }
918 /**
919  * \brief Create a 802.3 address (default)
920  * \param ethernet Pointer to ethernet address
921  */
922 uint8_t mac_createDefaultEthernetAddr(uint8_t * ethernet)
923 {
924  memcpy(ethernet, &simple_trans_ethernet_addr, 6);
925  return 1;
926 }
927 /**
928  * \brief Slide the pointed to memory up a certain amount,
929  * growing/shrinking a buffer
930  * \param data Pointer to start of data buffer
931  * \param length Length of the data buffer
932  * \param slide How many bytes to slide the buffer up in memory (if +) or
933  * down in memory (if -)
934  */
935 void slide(uint8_t * data, uint8_t length, int16_t slide)
936 {
937  //Sanity checks
938  if (!length) return;
939  if (!slide) return;
940 
941  uint8_t i = 0;
942 
943  while(length) {
944  length--;
945 
946  //If we are sliding up, we do from the top of the buffer down
947  if (slide > 0) {
948  *(data + length + slide) = *(data + length);
949 
950  //If we are sliding down, we do from the bottom of the buffer up
951  } else {
952  *(data + slide + i) = *(data + i);
953  }
954 
955  i++;
956  }
957 }
958 
959 //#define ETHBUF(x) ((struct uip_eth_hdr *)x)
960 //#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
961 
962 void
963 mac_log_802_15_4_tx(const uint8_t* buffer, size_t total_len) {
964  if (usbstick_mode.raw != 0) {
965  uint8_t sendlen;
966 
967  static uint8_t raw_buf[127+ UIP_LLH_LEN +1];
968 
969  /* Get the raw frame */
970  memcpy(&raw_buf[UIP_LLH_LEN], buffer, total_len);
971  sendlen = total_len;
972 
973  /* Setup generic ethernet stuff */
974  ETHBUF(raw_buf)->type = uip_htons(0x809A); //UIP_ETHTYPE_802154 0x809A
975 
976  /* Check for broadcast message */
978  ETHBUF(raw_buf)->dest.addr[0] = 0x33;
979  ETHBUF(raw_buf)->dest.addr[1] = 0x33;
980  ETHBUF(raw_buf)->dest.addr[2] = 0x00;
981  ETHBUF(raw_buf)->dest.addr[3] = 0x00;
982  ETHBUF(raw_buf)->dest.addr[4] = 0x80;
983  ETHBUF(raw_buf)->dest.addr[5] = 0x9A;
984 
985 /*
986  ETHBUF(raw_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12];
987  ETHBUF(raw_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13];
988  ETHBUF(raw_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14];
989  ETHBUF(raw_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15];
990 */
991  } else {
992  /* Otherwise we have a real address */
993  mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->dest.addr[0]),
994  (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
995  }
996 
997 // mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]),(uip_lladdr_t *)&uip_lladdr.addr);
998  mac_createDefaultEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]));
999 
1000  sendlen += UIP_LLH_LEN;
1001  usb_eth_send(raw_buf, sendlen, 0);
1002  }
1003 }
1004 
1005 void
1006 mac_log_802_15_4_rx(const uint8_t* buf, size_t len) {
1007  if (usbstick_mode.raw != 0) {
1008  uint8_t sendlen;
1009 
1010  /* Get the raw frame */
1011  memcpy(&raw_buf[UIP_LLH_LEN], buf, len);
1012  sendlen = len;
1013 
1014  /* Setup generic ethernet stuff */
1015  ETHBUF(raw_buf)->type = uip_htons(0x809A); //UIP_ETHTYPE_802154 0x809A
1016 
1017  /* Check for broadcast message */
1019  ETHBUF(raw_buf)->dest.addr[0] = 0x33;
1020  ETHBUF(raw_buf)->dest.addr[1] = 0x33;
1021  ETHBUF(raw_buf)->dest.addr[2] = 0x00;
1022  ETHBUF(raw_buf)->dest.addr[3] = 0x00;
1023  ETHBUF(raw_buf)->dest.addr[4] = 0x80;
1024  ETHBUF(raw_buf)->dest.addr[5] = 0x9A;
1025 /*
1026  ETHBUF(raw_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12];
1027  ETHBUF(raw_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13];
1028  ETHBUF(raw_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14];
1029  ETHBUF(raw_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15];
1030 */
1031  } else {
1032  /* Otherwise we have a real address */
1033  mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->dest.addr[0]),
1034  (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
1035  }
1036 
1037 // mac_createEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]),(uip_lladdr_t *)&uip_lladdr.addr);
1038  mac_createDefaultEthernetAddr((uint8_t *) &(ETHBUF(raw_buf)->src.addr[0]));
1039 
1040  sendlen += UIP_LLH_LEN;
1041  usb_eth_send(raw_buf, sendlen, 0);
1042  }
1043 }
1044 /* The rf230bb send driver may call this routine via RF230BB_HOOK_IS_SEND_ENABLED */
1045 bool
1046 mac_is_send_enabled(void) {
1047  if ((usbstick_mode.sendToRf == 0) || (usbstick_mode.sneeze != 0)) return 0;
1048  return 1;
1049 //return usbstick_mode.sendToRf;
1050 }
1051 
1052 /** @} */
1053 
1054 
1055 
1056 /** @} */
1057 
1058 
1059 #if !RF230BB
1060 /*--------------------------------------------------------------------*/
1061 /** \brief Process a received 6lowpan packet. Hijack function.
1062  * \param r The MAC layer
1063  *
1064  * The 6lowpan packet is put in packetbuf by the MAC. This routine calls
1065  * any other needed layers (either 6lowpan, or just raw ethernet dump)
1066  */
1067 void mac_ethhijack(const struct mac_driver *r)
1068 {
1069  if (usbstick_mode.raw) {
1070  mac_802154raw(r);
1071  }
1072 
1073  if (usbstick_mode.sicslowpan) {
1074 
1075 #if UIP_CONF_USE_RUM
1076  if (parsed_frame->payload[4]) { /* RUM 6lowpan frame type */
1077 #endif
1078  sicslowinput(r);
1079 #if UIP_CONF_USE_RUM
1080  }
1081 #endif
1082 
1083 
1084  }
1085 
1086 }
1087 
1088 void mac_ethhijack_nondata(const struct mac_driver *r)
1089 {
1090  if (usbstick_mode.raw)
1091  mac_802154raw(r);
1092 }
1093 
1094 
1095 /*--------------------------------------------------------------------*/
1096 /*--------------------------------------------------------------------*/
1097 /** \brief Logs a sent 6lowpan frame
1098  *
1099  * This routine passes a frame
1100  * directly to the ethernet layer without decompressing.
1101  */
1103 {
1104  mac_log_802_15_4_tx(frame_result->frame, frame_result->length);
1105 }
1106 
1107 
1108 /*--------------------------------------------------------------------*/
1109 /** \brief Process a received 6lowpan packet.
1110  * \param r The MAC layer
1111  *
1112  * The 6lowpan packet is put in packetbuf by the MAC. This routine passes
1113  * it directly to the ethernet layer without decompressing.
1114  */
1115 void mac_802154raw(const struct mac_driver *r) {
1116  mac_log_802_15_4_tx(radio_frame_data(), radio_frame_length());
1117 }
1118 
1119 #endif /* !RF230BB */
1120 
1121 
1122 
Header file for IPv6 Neighbor discovery (RFC 4861)
#define ICMP6_ECHO_REPLY
Echo reply.
Definition: uip-icmp6.h:58
uip_len
The length of the packet in the uip_buf buffer.
Definition: tcp_loader.c:75
void mac_ethernetToLowpan(uint8_t *ethHeader)
Take a packet received over the ethernet link, and send it out over 802.15.4.
void mac_802154raw(const struct mac_driver *r)
Process a received 6lowpan packet.
uint8_t mac_createEthernetAddr(uint8_t *ethernet, uip_lladdr_t *lowpan)
Create a 802.3 address from a 802.15.4 long address.
#define ICMP6_NS
Neighbor Solicitation.
Definition: uip-icmp6.h:62
uint8_t * frame
Pointer to created frame.
Definition: frame.h:154
void mac_logTXtoEthernet(frame_create_params_t *p, frame_result_t *frame_result)
Logs a sent 6lowpan frame.
void mac_ethhijack(const struct mac_driver *r)
Process a received 6lowpan packet.
void slide(uint8_t *data, uint8_t length, int16_t slide)
Slide the pointed to memory up a certain amount, growing/shrinking a buffer.
Parameters used by the frame_tx_create() function.
Definition: frame.h:162
#define TRANSLATE_BIT_MASK
Location of TRANSLATE (TR) bit in Ethernet address.
RNDIS Defines
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
Definition: uip.h:1239
#define ICMP6_ECHO_REQUEST
Echo request.
Definition: uip-icmp6.h:57
#define UIP_LLH_LEN
The link level header length.
Definition: uipopt.h:160
uint16_t uip_icmp6chksum(void)
Calculate the ICMP checksum of the packet in uip_buf.
Definition: uip.c:340
int8_t mac_translateIPLinkLayer(lltype_t target)
Translate IP packet's possible link-layer addresses, passing the message to the appropriate higher le...
#define UIP_LLADDR_LEN
Link layer address length.
Definition: uip.h:151
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
Definition: uip.h:523
#define ICMP6_DST_UNREACH
dest unreachable
Definition: uip-icmp6.h:53
#define MULTICAST_BIT_MASK
Location of MULTICAST (MU) bit in Ethernet address.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
Definition: uip.h:1027
The Ethernet header.
Definition: uip_arp.h:60
int packetbuf_holds_broadcast(void)
Checks whether the current packet is a broadcast.
Definition: packetbuf.c:242
uint8_t mac_createSicslowpanLongAddr(uint8_t *ethernet, uip_lladdr_t *lowpan)
Create a 802.15.4 long address from a 802.3 address.
#define UIP_IP_BUF
Pointer to IP header.
Definition: uip-nd6.c:104
uint8_t length
Length (in bytes) of created frame.
Definition: frame.h:155
802.15.4 frame creation and parsing functions
uint8_t mac_createDefaultEthernetAddr(uint8_t *ethernet)
Create a 802.3 address (default)
Header file for the Rime stack
The IEEE 802.15.4 (2003/2006) MAC utility functions.
#define NULL
The null pointer.
802.3 address
Definition: uip.h:129
Header file for ICMPv6 message and error handing (RFC 4443)
The structure of a MAC protocol driver in Contiki.
Definition: mac.h:54
This file manages the RNDIS task.
#define UIP_ICMP_BUF
Pointer to ICMP header.
Definition: uip-nd6.c:105
#define ICMP6_PARAM_PROB
ip6 header bad
Definition: uip-icmp6.h:56
Header file for the uIP TCP/IP stack.
#define LOCAL_BIT_MASK
Location of LOCAL (GL) bit in Ethernet address.
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:120
int8_t mac_translateIcmpLinkLayer(lltype_t target)
Translate the link-layer (L2) addresses in an ICMP packet.
#define ICMP6_TIME_EXCEEDED
time exceeded
Definition: uip-icmp6.h:55
#define ICMP6_REDIRECT
Redirect.
Definition: uip-icmp6.h:64
#define ICMP6_RA
Router Advertisement.
Definition: uip-icmp6.h:61
#define ICMP6_RS
Router Solicitation.
Definition: uip-icmp6.h:60
uint8_t usb_eth_send(uint8_t *senddata, uint16_t sendlen, uint8_t led)
Sends a single ethernet frame over USB using appropriate low-level protocol (EEM or RNDIS) ...
Definition: rndis_task.c:303
#define ICMP6_NA
Neighbor advertisement.
Definition: uip-icmp6.h:63
void tcpip_input(void)
Deliver an incoming packet to the TCP/IP stack.
Definition: tcpip.c:522
Strucure used to return that status of the frame create process.
Definition: frame.h:153
Header file for the 6lowpan implementation (RFC4944 and draft-hui-6lowpan-hc-01) ...
void mac_LowpanToEthernet(void)
Take a packet received over the 802.15.4 link, and send it out over ethernet, performing any translat...
#define ICMP6_PACKET_TOO_BIG
packet too big
Definition: uip-icmp6.h:54
Macros and definitions for the ARP module.
uint64_t macLongAddr
Our own long address.
Definition: mac.c:145
CCIF uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
Definition: uip.c:1948
struct mac_driver * pmac
Perform any setup needed.