Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2006, Technical University of Munich 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 * 00031 * Author: Simon Barner <barner@in.tum.de> 00032 * 00033 * @(#)$$ 00034 */ 00035 #include "contiki-raven.h" 00036 #if !RF230BB 00037 #include "zmac.h" 00038 #endif 00039 #include "sicslowpan.h" 00040 #include "sicslow_ethernet.h" 00041 #include "rndis/rndis_task.h" 00042 00043 void byte_reverse(uint8_t * bytes, uint8_t num) 00044 { 00045 uint8_t tempbyte; 00046 00047 uint8_t i, j; 00048 00049 i = 0; 00050 j = num - 1; 00051 00052 while(i < j) { 00053 tempbyte = bytes[i]; 00054 bytes[i] = bytes[j]; 00055 bytes[j] = tempbyte; 00056 00057 j--; 00058 i++; 00059 } 00060 00061 return; 00062 } 00063 00064 void 00065 init_net(void) 00066 { 00067 extern uint64_t macLongAddr; 00068 uint64_t usb_ethernet_addr; 00069 00070 // Because all of the logic below is done using little-endian 00071 // 64-bit integers, we need to reverse the byte order before 00072 // we can continue; 00073 byte_reverse((uint8_t*)&macLongAddr,8); 00074 00075 /* Set local bit, Clear translate bit, Clear Multicast bit */ 00076 macLongAddr &= ~(0x0700000000000000ULL); 00077 macLongAddr |= 0x0200000000000000ULL; 00078 00079 /* Set the Ethernet address to the 15.4 MAC address */ 00080 usb_ethernet_addr = macLongAddr; 00081 00082 /* Remove the middle two bytes... */ 00083 usb_ethernet_addr = (usb_ethernet_addr & 0xffffffUL) | ((usb_ethernet_addr & 0xffffff0000000000ULL) >> 16); 00084 00085 /* Change ieee802.15.4 address to correspond with what the ethernet's 00086 IPv6 address will be. This will have ff:fe in the middle. */ 00087 macLongAddr = (macLongAddr & 0xffffff0000ffffffULL) | (0x000000fffe000000ULL); 00088 00089 #if !RF230BB 00090 ieee15_4ManagerAddress.set_long_addr(macLongAddr); 00091 #endif 00092 00093 byte_reverse((uint8_t*)&macLongAddr,8); 00094 byte_reverse((uint8_t*)&usb_ethernet_addr,6); 00095 00096 usb_eth_set_mac_address((uint8_t*)&usb_ethernet_addr); 00097 } 00098