/*------Done in a subroutine to keep main routine stack usage small--------*/ void initialize(void) { watchdog_init(); watchdog_start(); init_lowlevel(); clock_init(); forwarding_enabled = get_forwarding_from_eeprom(); #if ANNOUNCE_BOOT PRINTF("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif /* rtimers needed for radio cycling */ rtimer_init(); /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); #if RF230BB || RF212BB ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ rimeaddr_t addr; memset(&addr, 0, sizeof(rimeaddr_t)); get_mac_from_eeprom(addr.u8); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &addr.u8, 8); #endif #if RF230BB rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&addr.u8 ); rf230_set_channel(CHANNEL_802_15_4); #elif RF212BB rf212_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&addr.u8 ); #endif extern uint16_t mac_dst_pan_id; extern uint16_t mac_src_pan_id; //set pan_id for frame creation mac_dst_pan_id = get_panid_from_eeprom(); mac_src_pan_id = mac_dst_pan_id; rimeaddr_set_node_addr(&addr); PRINTFD("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE_BOOT #if RF230BB PRINTF("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel()); #elif RF212BB PRINTF("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name, rf212_get_channel()); #endif /* RF230BB */ if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp); } PRINTF("\n"); #if UIP_CONF_IPV6_RPL PRINTF("RPL Enabled\n"); #endif #if UIP_CONF_ROUTER PRINTF("Routing Enabled\n"); #endif #endif /* ANNOUNCE_BOOT */ // rime_init(rime_udp_init(NULL)); // uip_router_register(&rimeroute); process_start(&tcpip_process, NULL); #else /* Original RF230 combined mac/radio driver */ /* mac process must be started before tcpip process! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /*RF230BB || RF212BB*/ #if WEBSERVER process_start(&webserver_nogui_process, NULL); #endif /* Handler for HEXABUS UDP Packets */ process_start(&udp_handler_process, NULL); mdns_responder_init(); /* Button Process */ process_start(&button_pressed_process, NULL); /* Init Metering */ metering_init(); /*Init Relay */ relay_init(); /* Autostart other processes */ autostart_start(autostart_processes); /*---If using coffee file system create initial web content if necessary---*/ #if COFFEE_FILES int fa = cfs_open( "/index.html", CFS_READ); if (fa<0) { //Make some default web content PRINTF("No index.html file found, creating upload.html!\n"); PRINTF("Formatting FLASH file system for coffee..."); cfs_coffee_format(); PRINTF("Done!\n"); fa = cfs_open( "/index.html", CFS_WRITE); int r = cfs_write(fa, &"It works!", 9); if (r<0) PRINTF("Can''t create /index.html!\n"); cfs_close(fa); // fa = cfs_open("upload.html"), CFW_WRITE); // <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html> } #endif /* COFFEE_FILES */ /* Add addresses for testing */ #if 0 { uip_ip6addr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); // uip_ds6_prefix_add(&ipaddr,64,0); } #endif /*--------------------------Announce the configuration---------------------*/ #if ANNOUNCE_BOOT #if WEBSERVER uint8_t i; char buf[80]; unsigned int size; for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf); PRINTF("IPv6 Address: %s\n",buf); } } eeprom_read_block(buf, (const void*) EE_DOMAIN_NAME, EE_DOMAIN_NAME_SIZE); buf[EE_DOMAIN_NAME_SIZE] = 0; size=httpd_fs_get_size(); #ifndef COFFEE_FILES PRINTF(".%s online with fixed %u byte web content\n",buf,size); #elif COFFEE_FILES==1 PRINTF(".%s online with static %u byte EEPROM file system\n",buf,size); #elif COFFEE_FILES==2 PRINTF(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10); #elif COFFEE_FILES==3 PRINTF(".%s online with static %u byte program memory file system\n",buf,size); #elif COFFEE_FILES==4 PRINTF(".%s online with dynamic %u KB program memory file system\n",buf,size>>10); #endif /* COFFEE_FILES */ #else PRINTF("Online\n"); #endif /* WEBSERVER */ #endif /* ANNOUNCE_BOOT */ }
void cmd_parser(unsigned long data) { char *curr_pos = &user_string[0]; int ret; while(1) { while(cmd_in_progress) os_TaskDelay(10); DBG_P(( DBG_L0 "\r\n> ")); cmd_parser_read_line(); if(strlen(user_string) == 0) { /* Do Nothing. */ } else if(!memcmp(user_string,"iwlist",6)){ userif_prepare_scan_cmd(0); } else if(!memcmp(user_string,"iwconf",6)){ curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos,"essid",5)) { curr_pos = &curr_pos[get_next_word(curr_pos)]; specificSSID.Len = strlen(curr_pos); memcpy((void *)specificSSID.SsId, curr_pos, strlen(curr_pos)); if(link_present) { if(currbss_type != BSS_INDEPENDENT) userif_prepare_deauth_cmd(); else userif_prepare_adhoc_stop_cmd(); } else { userif_prepare_scan_cmd(1); } link_present = 0; } else if (!memcmp(curr_pos,"mode",4)) { curr_pos = &curr_pos[get_next_word(curr_pos)]; if(!memcmp(curr_pos,"ad-hoc",6)) { bss_type = BSS_INDEPENDENT; } else if(!memcmp(curr_pos,"manage",6)) { bss_type = BSS_INFRASTRUCTURE; } else { bss_type = BSS_ANY; } } else if (!memcmp(curr_pos,"ap",2)) { curr_pos = &curr_pos[get_next_word(curr_pos)]; get_macaddr(curr_pos,(char *)specificBSSID); if (FindBSSIDinList()) { userif_prepare_auth_cmd(); } else { if(link_present) { link_present = 0; userif_prepare_deauth_cmd(); } else { userif_prepare_scan_cmd(2); } } } } else if(!memcmp(user_string,"econfi",6)){ unsigned int ip; unsigned int nm; unsigned int gw; curr_pos = &user_string[get_next_word(user_string)]; get_ipaddr(curr_pos, (char *)&ip); curr_pos = &curr_pos[get_next_word(curr_pos)]; get_ipaddr(curr_pos, (char *)&nm); curr_pos = &curr_pos[get_next_word(curr_pos)]; get_ipaddr(curr_pos, (char *)&gw); sys_tcpip_init(ip, nm); } else if(!memcmp(user_string, "printip", 7)){ DBG_P(( DBG_L0 "%d.%d.%d.%d,", ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3] )); DBG_P(( DBG_L0 "%d.%d.%d.%d,", net_mask[0], net_mask[1], net_mask[2], net_mask[3] )); DBG_P(( DBG_L0 "%d.%d.%d.%d\r\n", def_gtwy[0], def_gtwy[1], def_gtwy[2], def_gtwy[3] )); } else if(!memcmp(user_string, "printmac", 8)){ char mac[6]; GetMACAddr(NULL, mac); DBG_P(( DBG_L0 "%02x:%02x:%02x:%02x:%02x:%02x\r\n", \ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])); } else if(!memcmp(user_string,"ping",4)){ curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos,"stop",4)) { send_ping = 0; } else { get_ipaddr(curr_pos, ping_ipaddr); #ifdef EMBEDDED_TCPIP userif_prepare_open_raw_socket(); #else userif_prepare_macaddr_get_cmd(); #endif send_ping = 1; } } /* Link-local address manager. */ else if(!memcmp(user_string, "linklocal", 9)) { curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "start", 5)) { /* Launch the link local manager */ ret = ll_init(); if(ret) DBG_P(( DBG_L0 "Error launching link local: %d.\r\n", ret)); } else if(!memcmp(curr_pos, "stop", 4)) { /* Kill the link local manager. */ ret = ll_shutdown(); if(ret) DBG_P(( DBG_L0 "Error killing link local: %d.\r\n", ret)); } } /* mDNS responder */ else if(!memcmp(user_string, "mdns", 4)) { curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "start", 5)) { /* launch the mDNS responder */ ret = mdns_responder_init(); if(ret) DBG_P(( DBG_L0 "Error launching mDNS responder: %d.\r\n",ret)); } else if(!memcmp(curr_pos, "stop", 4)) { /* stop the mDNS responder */ ret = mdns_responder_shutdown(); if(ret) DBG_P(( DBG_L0 "Error stopping mDNS responder: %d.\r\n", ret)); } } else if(!memcmp(user_string, "mcast", 5 )){ curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "get", 3 )) { userif_prepare_mcast_cmd(); } else if(!memcmp(curr_pos, "set", 3 )) { userif_prepare_mcast_add_cmd(); } } /* httpd interface */ else if(!memcmp(user_string, "httpd", 5)) { curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "start", 5)) { ret = httpd_init(); if(ret) DBG_P(( DBG_L0 "Error launching httpd: %d.\r\n",ret)); } else if(!memcmp(curr_pos, "stop", 4)) { ret = httpd_shutdown(); if(ret) DBG_P(( DBG_L0 "Error stopping httpd: %d.\r\n", ret)); } else { DBG_P(( DBG_L0 "No such httpd command: %s.\r\n", curr_pos)); } } /* log interface */ else if(!memcmp(user_string, "log", 3)) { curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "init", 5)) { ret = log_init(); if(ret) DBG_P(( DBG_L0 "Error launching logger: %d.\r\n",ret)); } else if(!memcmp(curr_pos, "shutdown", 8)) { ret = log_shutdown(); if(ret) DBG_P(( DBG_L0 "Error stopping logger: %d.\r\n", ret)); } else if(!memcmp(curr_pos, "dump", 4)) { ret = log_dump(); if(ret) DBG_P(( DBG_L0 "Error dumping log: %d.\r\n", ret)); } else if(!memcmp(curr_pos, "purge", 5)) { ret = log_purge(); if(ret) DBG_P(( DBG_L0 "Error purging log: %d.\r\n", ret)); } else if(!memcmp(curr_pos, "write", 5)) { curr_pos = &curr_pos[get_next_word(curr_pos)]; ret = log(curr_pos); if(ret) DBG_P(( DBG_L0 "Failed to write log: %d.\r\n", ret)); } else { DBG_P(( DBG_L0 "No such log command: %s.\r\n", curr_pos)); } } else if(!memcmp(user_string, "help", 4)) { print_usage(); } else { #ifdef UART_DRV DBG_P(( DBG_L0 "Unknown command.\r\n")); #endif } } }