/*---------------------------------------------------------------------------*/ int main(void) { DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE); leds_init(); //printf("\rStarting Contiki on STM32VL Discovery...\n\r"); clock_init(); process_init(); uip_init(); uip_fw_init(); process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); uip_ipaddr(&hostaddr, 172, 16, 0, 3); uip_sethostaddr(&hostaddr); uip_ipaddr(&netmask, 255, 255, 0, 0); uip_setnetmask(&netmask); uip_ipaddr(&netmask, 172, 16, 0, 1); uip_setdraddr(&draddr); process_start(&etimer_process, NULL); ctimer_init(); /* Networking stack. */ NETSTACK_RADIO.init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); { rimeaddr_t rimeaddr; rimeaddr.u8[0] = 0x02; rimeaddr.u8[1] = 0x00; rimeaddr_set_node_addr(&rimeaddr); } autostart_start(autostart_processes); while (1) { process_run(); } return 0; }
/*---------------------------------------------------------------------------*/ void init_net(void) { int i; uip_ipaddr_t hostaddr, netmask; rimeaddr_t rimeaddr; /* Init Rime */ ctimer_init(); rimeaddr.u8[0] = node_id & 0xff; rimeaddr.u8[1] = node_id >> 8; rimeaddr_set_node_addr(&rimeaddr); printf("Rime started with address: "); for(i = 0; i < sizeof(rimeaddr_node_addr.u8) - 1; i++) { printf("%d.", rimeaddr_node_addr.u8[i]); } printf("%d\n", rimeaddr_node_addr.u8[i]); /* Init uIPv4 */ process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); process_start(&slip_process, NULL); uip_init(); uip_fw_init(); uip_ipaddr(&hostaddr, 172, 16, rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0]); uip_ipaddr(&netmask, 255,255,0,0); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_fw_register(&wsn_if); uip_fw_default(&slip_if); rs232_set_input(slip_input_byte); printf("uIP started with IP address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); /* uIPv4 <-> COOJA's packet radio */ /*tcpip_set_outputfunc(sender);*/ cooja_radio.set_receive_function(receiver); }
/*---------------------------------------------------------------------------*/ void init_net(void) { set_rime_addr(); cc2420_init(); { uint8_t longaddr[8]; uint16_t shortaddr; shortaddr = (linkaddr_node_addr.u8[0] << 8) + linkaddr_node_addr.u8[1]; memset(longaddr, 0, sizeof(longaddr)); linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr); printf_P(PSTR("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n"), longaddr[0], longaddr[1], longaddr[2], longaddr[3], longaddr[4], longaddr[5], longaddr[6], longaddr[7]); cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, ds2401_id, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */ /* printf(" %s channel %u\n", sicslowmac_driver.name, CC2420_CONF_CHANNEL); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf_P(PSTR("%s %s, channel check rate %d Hz, radio channel %d\n"), NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), CC2420_CONF_CHANNEL); process_start(&tcpip_process, NULL); printf_P(PSTR("Tentative link-local IPv6 address ")); { uip_ds6_addr_t *lladdr; int i; lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { printf_P(PSTR("%02x%02x:"), lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } printf_P(PSTR("%02x%02x\n"), lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } if(!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf_P(PSTR("Tentative global IPv6 address ")); for(i = 0; i < 7; ++i) { printf_P(PSTR("%02x%02x:"), ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf_P(PSTR("%02x%02x\n"), ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } #else /* NETSTACK_CONF_WITH_IPV6 */ NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf_P(PSTR("%s %s, channel check rate %d Hz, radio channel %d\n"), NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), CC2420_CONF_CHANNEL); #endif /* NETSTACK_CONF_WITH_IPV6 */ #if NETSTACK_CONF_WITH_IPV4 uip_ipaddr_t hostaddr, netmask; uip_init(); uip_fw_init(); process_start(&tcpip_process, NULL); process_start(&slip_process, NULL); process_start(&uip_fw_process, NULL); slip_set_input_callback(set_gateway); /* Construct ip address from four bytes. */ uip_ipaddr(&hostaddr, 172, 16, linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]); /* Construct netmask from four bytes. */ uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); /* Set the IP address for this host. */ uip_sethostaddr(&hostaddr); /* Set the netmask for this host. */ uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); /* Register slip interface with forwarding module. */ //uip_fw_register(&slipif); uip_over_mesh_set_gateway_netif(&slipif); /* Set slip interface to be a default forwarding interface . */ uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); printf_P(PSTR("uIP started with IP address %d.%d.%d.%d\n"), uip_ipaddr_to_quad(&hostaddr)); #endif /* NETSTACK_CONF_WITH_IPV4 */ }
/*---------------------------------------------------------------------------*/ void contiki_init() { /* Initialize random generator (moved to moteid.c) */ /* Start process handler */ process_init(); /* Start Contiki processes */ process_start(&etimer_process, NULL); process_start(&sensors_process, NULL); ctimer_init(); /* Print startup information */ printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { printf("Node id is set to %u.\n", node_id); } else { printf("Node id is not set.\n"); } set_rime_addr(); { uint8_t longaddr[8]; memset(longaddr, 0, sizeof(longaddr)); linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", longaddr[0], longaddr[1], longaddr[2], longaddr[3], longaddr[4], longaddr[5], longaddr[6], longaddr[7]); } queuebuf_init(); /* Initialize communication stack */ netstack_init(); printf("%s/%s/%s, channel check rate %lu Hz\n", NETSTACK_NETWORK.name, NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval())); #if WITH_UIP /* IPv4 CONFIGURATION */ { uip_ipaddr_t hostaddr, netmask; process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); uip_init(); uip_fw_init(); uip_ipaddr(&hostaddr, 172,16,linkaddr_node_addr.u8[0],linkaddr_node_addr.u8[1]); uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); rs232_set_input(slip_input_byte); printf("IPv4 address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ #if WITH_UIP6 /* IPv6 CONFIGURATION */ { int i; uint8_t addr[sizeof(uip_lladdr.addr)]; for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) { addr[i + 1] = node_id & 0xff; addr[i + 0] = node_id >> 8; } linkaddr_copy((linkaddr_t *)addr, &linkaddr_node_addr); memcpy(&uip_lladdr.addr, addr, sizeof(uip_lladdr.addr)); process_start(&tcpip_process, NULL); printf("Tentative link-local IPv6 address "); { uip_ds6_addr_t *lladdr; int i; lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } if(1) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } } #endif /* WITH_UIP6 */ /* Initialize eeprom */ eeprom_init(); /* Start serial process */ serial_line_init(); /* Start autostart processes (defined in Contiki application) */ print_processes(autostart_processes); autostart_start(autostart_processes); }
void init_net(void) { /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ set_rime_addr(); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */ /* printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); PRINTA("%s %s, channel %u , check rate %u Hz tx power %u\n", NETSTACK_MAC.name, NETSTACK_RDC.name, rf2xx_get_channel(), CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 : NETSTACK_RDC.channel_check_interval()), rf2xx_get_txpower()); #if UIP_CONF_IPV6_RPL PRINTA("RPL Enabled\n"); #endif #if UIP_CONF_ROUTER PRINTA("Routing Enabled\n"); #endif process_start(&tcpip_process, NULL); #if ANNOUNCE_BOOT && UIP_CONF_IPV6 PRINTA("Tentative link-local IPv6 address "); { uip_ds6_addr_t *lladdr; int i; lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { PRINTA("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } PRINTA("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } if(!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); PRINTA("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { PRINTA("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } PRINTA("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } #endif /* ANNOUNCE_BOOT */ #if WITH_UIP uip_ipaddr_t hostaddr, netmask; uip_init(); uip_fw_init(); process_start(&tcpip_process, NULL); process_start(&slip_process, NULL); process_start(&uip_fw_process, NULL); slip_set_input_callback(set_gateway); /* Construct ip address from four bytes. */ uip_ipaddr(&hostaddr, 172, 16, rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]); /* Construct netmask from four bytes. */ uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); /* Set the IP address for this host. */ uip_sethostaddr(&hostaddr); /* Set the netmask for this host. */ uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); /* Register slip interface with forwarding module. */ //uip_fw_register(&slipif); uip_over_mesh_set_gateway_netif(&slipif); /* Set slip interface to be a default forwarding interface . */ uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); PRINTA(PSTR("uIP started with IP address %d.%d.%d.%d\n"), uip_ipaddr_to_quad(&hostaddr)); #endif /* WITH_UIP */ }
/*---------------------------------------------------------------------------*/ void contiki_init() { /* Initialize random generator (moved to moteid.c) */ /* Start process handler */ process_init(); /* Start Contiki processes */ procinit_init(); /* Print startup information */ printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { printf("Node id is set to %u.\n", node_id); } else { printf("Node id is not set.\n"); } /* RIME CONFIGURATION */ { int i; rimeaddr_t rimeaddr; /* Init Rime */ ctimer_init(); rimeaddr.u8[0] = node_id & 0xff; rimeaddr.u8[1] = node_id >> 8; rimeaddr_set_node_addr(&rimeaddr); printf("Rime address: "); for(i = 0; i < sizeof(rimeaddr_node_addr.u8) - 1; i++) { printf("%d.", rimeaddr_node_addr.u8[i]); } printf("%d\n", rimeaddr_node_addr.u8[i]); } queuebuf_init(); /* Initialize communication stack */ netstack_init(); printf("MAC %s RDC %s NETWORK %s\n", NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name); #if WITH_UIP /* IPv4 CONFIGURATION */ { uip_ipaddr_t hostaddr, netmask; process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); uip_init(); uip_fw_init(); uip_ipaddr(&hostaddr, 172,16,rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); rs232_set_input(slip_input_byte); printf("IPv4 address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ #if WITH_UIP6 /* IPv6 CONFIGURATION */ { int i; uint8_t addr[sizeof(uip_lladdr.addr)]; for (i=0; i < sizeof(uip_lladdr.addr); i++) { addr[i] = node_id & 0xff; } memcpy(&uip_lladdr.addr, addr, sizeof(uip_lladdr.addr)); process_start(&tcpip_process, NULL); printf("Tentative link-local IPv6 address "); { int i, a; for(a = 0; a < UIP_DS6_ADDR_NB; a++) { if (uip_ds6_if.addr_list[a].isused) { for(i = 0; i < 7; ++i) { printf("%02x%02x:", uip_ds6_if.addr_list[a].ipaddr.u8[i * 2], uip_ds6_if.addr_list[a].ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", uip_ds6_if.addr_list[a].ipaddr.u8[14], uip_ds6_if.addr_list[a].ipaddr.u8[15]); } } } if(1) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } } #endif /* WITH_UIP6 */ /* Start serial process */ serial_line_init(); /* Start autostart processes (defined in Contiki application) */ print_processes(autostart_processes); autostart_start(autostart_processes); }