contiki/platform/mbxxx/contiki-init-net.c

141 lines
4.3 KiB
C
Raw Normal View History

/**
2013-07-11 15:50:15 +00:00
* \addtogroup mbxxx-platform
*
* @{
*/
2010-10-25 09:03:38 +00:00
/*
* Copyright (c) 2010, STMicroelectronics.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
2013-07-11 15:50:15 +00:00
* This file is part of the Contiki OS
*
2010-10-25 09:03:38 +00:00
*/
2013-07-11 15:50:15 +00:00
/*---------------------------------------------------------------------------*/
2010-10-25 09:03:38 +00:00
/**
* \file
2013-07-11 15:50:15 +00:00
* Functions for net initialization.
2010-10-25 09:03:38 +00:00
* \author
2013-07-11 15:50:15 +00:00
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
2010-10-25 09:03:38 +00:00
*/
2013-07-11 15:50:15 +00:00
/*---------------------------------------------------------------------------*/
2010-10-25 09:03:38 +00:00
#include "contiki-net.h"
#if NETSTACK_CONF_WITH_IPV6
2010-10-25 09:03:38 +00:00
#define DEBUG 1
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
2010-10-25 09:03:38 +00:00
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",lladdr.u8[0], lladdr.u8[1], lladdr.u8[2], lladdr.u8[3],lladdr.u8[4], lladdr.u8[5], lladdr.u8[6], lladdr.u8[7])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
2013-07-11 15:50:15 +00:00
void print_address(uip_ds6_addr_t *lladdr)
2010-10-25 09:03:38 +00:00
{
int i;
2013-07-11 15:50:15 +00:00
2010-10-25 09:03:38 +00:00
for(i = 0; i < 7; ++i) {
2013-07-11 15:50:15 +00:00
printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]);
2010-10-25 09:03:38 +00:00
}
printf("%02x%02x", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
}
2013-07-11 15:50:15 +00:00
2010-10-25 09:03:38 +00:00
/*---------------------------------------------------------------------------*/
2013-07-11 15:50:15 +00:00
void print_addresses(void)
2010-10-25 09:03:38 +00:00
{
uip_ds6_addr_t *lladdr;
2013-07-11 15:50:15 +00:00
printf("link-local IPv6 address: ");
2010-10-25 09:03:38 +00:00
lladdr = uip_ds6_get_link_local(-1);
2013-07-11 15:50:15 +00:00
if(lladdr != NULL){
print_address(lladdr);
2010-10-25 09:03:38 +00:00
printf("\r\n");
}
2013-07-11 15:50:15 +00:00
else
printf("None\r\n");
2010-10-25 09:03:38 +00:00
printf("global IPv6 address: ");
2013-07-11 15:50:15 +00:00
2010-10-25 09:03:38 +00:00
lladdr = uip_ds6_get_global(-1);
2013-07-11 15:50:15 +00:00
if(lladdr != NULL){
print_address(lladdr);
2010-10-25 09:03:38 +00:00
printf("\r\n");
}
2013-07-11 15:50:15 +00:00
else
printf("None\r\n");
2010-10-25 09:03:38 +00:00
}
2013-07-11 15:50:15 +00:00
2010-10-25 09:03:38 +00:00
#if FIXED_NET_ADDRESS
2013-07-11 15:50:15 +00:00
2010-10-25 09:03:38 +00:00
#include "net/rpl/rpl.h"
2013-07-11 15:50:15 +00:00
void set_net_address(void)
2010-10-25 09:03:38 +00:00
{
uip_ipaddr_t ipaddr;
#if RPL_BORDER_ROUTER
rpl_dag_t *dag;
#endif
2013-07-11 15:50:15 +00:00
uip_ip6addr(&ipaddr, NET_ADDR_A, NET_ADDR_B, NET_ADDR_C, NET_ADDR_D, 0, 0, 0, 0);
2010-10-25 09:03:38 +00:00
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
2013-07-11 15:50:15 +00:00
uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
//#if !UIP_CONF_ROUTER
// uip_ds6_prefix_add(&ipaddr, 64, 0); // For on-link determination.
//#else
// uip_ds6_prefix_add(&ipaddr, 64, 0, 0, 600, 600);
//#endif
2010-10-25 09:03:38 +00:00
print_addresses();
2013-07-11 15:50:15 +00:00
2010-10-25 09:03:38 +00:00
#if RPL_BORDER_ROUTER
2013-07-11 15:50:15 +00:00
dag = rpl_set_root(RPL_DEFAULT_INSTANCE,&ipaddr);
2010-10-25 09:03:38 +00:00
if(dag != NULL) {
PRINTF("This node is setted as root of a DAG.\r\n");
2013-07-11 15:50:15 +00:00
}
else {
2010-10-25 09:03:38 +00:00
PRINTF("Error while setting this node as root of a DAG.\r\n");
}
#endif
2013-07-11 15:50:15 +00:00
2010-10-25 09:03:38 +00:00
}
#endif /* FIXED_GLOBAL_ADDRESS */
2013-07-11 15:50:15 +00:00
#endif /* NETSTACK_CONF_WITH_IPV6 */
/** @} */