contiki-init-net.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "contiki-net.h"
00044
00045 #if UIP_CONF_IPV6
00046
00047 #define DEBUG 1
00048 #if DEBUG
00049 #include <stdio.h>
00050 #define PRINTF(...) printf(__VA_ARGS__)
00051 #define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
00052 #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])
00053 #else
00054 #define PRINTF(...)
00055 #define PRINT6ADDR(addr)
00056 #define PRINTLLADDR(addr)
00057 #endif
00058
00059 void print_address(uip_ds6_addr_t *lladdr)
00060 {
00061 int i;
00062
00063 for(i = 0; i < 7; ++i) {
00064 printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]);
00065 }
00066 printf("%02x%02x", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
00067 }
00068
00069
00070 void print_addresses(void)
00071 {
00072 uip_ds6_addr_t *lladdr;
00073
00074
00075 printf("link-local IPv6 address: ");
00076
00077 lladdr = uip_ds6_get_link_local(-1);
00078 if(lladdr != NULL){
00079 print_address(lladdr);
00080 printf("\r\n");
00081 }
00082 else
00083 printf("None\r\n");
00084
00085 printf("global IPv6 address: ");
00086
00087 lladdr = uip_ds6_get_global(-1);
00088 if(lladdr != NULL){
00089 print_address(lladdr);
00090 printf("\r\n");
00091 }
00092 else
00093 printf("None\r\n");
00094
00095 }
00096
00097 #if FIXED_NET_ADDRESS
00098
00099 #include "net/rpl/rpl.h"
00100
00101
00102 void set_net_address(void)
00103 {
00104 uip_ipaddr_t ipaddr;
00105 #if RPL_BORDER_ROUTER
00106 rpl_dag_t *dag;
00107 #endif
00108
00109 uip_ip6addr(&ipaddr, NET_ADDR_A, NET_ADDR_B, NET_ADDR_C, NET_ADDR_D, 0, 0, 0, 0);
00110 uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
00111 uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
00112
00113
00114
00115
00116
00117
00118
00119
00120 print_addresses();
00121
00122 #if RPL_BORDER_ROUTER
00123 dag = rpl_set_root(&ipaddr);
00124 if(dag != NULL) {
00125 PRINTF("This node is setted as root of a DAG.\r\n");
00126 }
00127 else {
00128 PRINTF("Error while setting this node as root of a DAG.\r\n");
00129 }
00130 #endif
00131
00132 }
00133 #endif
00134
00135
00136 #endif