Contiki 2.5
contiki-raven-default-init-net.c
1 /*
2  * Copyright (c) 2006, Technical University of Munich
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  * Author: Simon Barner <barner@in.tum.de>
32  *
33  * @(#)$$
34  */
35 #include "contiki-raven.h"
36 #if !RF230BB
37 #include "zmac.h"
38 #endif
39 #include "sicslowpan.h"
40 #include "sicslow_ethernet.h"
41 #include "rndis/rndis_task.h"
42 
43 void byte_reverse(uint8_t * bytes, uint8_t num)
44 {
45  uint8_t tempbyte;
46 
47  uint8_t i, j;
48 
49  i = 0;
50  j = num - 1;
51 
52  while(i < j) {
53  tempbyte = bytes[i];
54  bytes[i] = bytes[j];
55  bytes[j] = tempbyte;
56 
57  j--;
58  i++;
59  }
60 
61  return;
62 }
63 
64 void
65 init_net(void)
66 {
67  extern uint64_t macLongAddr;
68  uint64_t usb_ethernet_addr;
69 
70  // Because all of the logic below is done using little-endian
71  // 64-bit integers, we need to reverse the byte order before
72  // we can continue;
73  byte_reverse((uint8_t*)&macLongAddr,8);
74 
75  /* Set local bit, Clear translate bit, Clear Multicast bit */
76  macLongAddr &= ~(0x0700000000000000ULL);
77  macLongAddr |= 0x0200000000000000ULL;
78 
79  /* Set the Ethernet address to the 15.4 MAC address */
80  usb_ethernet_addr = macLongAddr;
81 
82  /* Remove the middle two bytes... */
83  usb_ethernet_addr = (usb_ethernet_addr & 0xffffffUL) | ((usb_ethernet_addr & 0xffffff0000000000ULL) >> 16);
84 
85  /* Change ieee802.15.4 address to correspond with what the ethernet's
86  IPv6 address will be. This will have ff:fe in the middle. */
87  macLongAddr = (macLongAddr & 0xffffff0000ffffffULL) | (0x000000fffe000000ULL);
88 
89 #if !RF230BB
91 #endif
92 
93  byte_reverse((uint8_t*)&macLongAddr,8);
94  byte_reverse((uint8_t*)&usb_ethernet_addr,6);
95 
96  usb_eth_set_mac_address((uint8_t*)&usb_ethernet_addr);
97 }
98