예제 #1
0
PROCESS_THREAD(cetic_6lbr_process, ev, data)
{
  PROCESS_BEGIN();

  cetic_6lbr_startup = clock_seconds();

#if CONTIKI_TARGET_NATIVE
  slip_config_handle_arguments(contiki_argc, contiki_argv);
#endif

  load_nvm_config();

  platform_init();

  process_start(&eth_drv_process, NULL);

  while(!ethernet_ready) {
    PROCESS_PAUSE();
  }

  process_start(&tcpip_process, NULL);

  PROCESS_PAUSE();

#if CETIC_NODE_INFO
  node_info_init();
#endif

  packet_filter_init();
  cetic_6lbr_init();

#if WEBSERVER
  process_start(&webserver_nogui_process, NULL);
#endif
#if UDPSERVER
  process_start(&udp_server_process, NULL);
#endif

  printf("CETIC 6LBR Started\n");

#if CONTIKI_TARGET_NATIVE
  PROCESS_WAIT_EVENT();
  etimer_set(&reboot_timer, CLOCK_SECOND);
  PROCESS_WAIT_EVENT();
  printf("Exiting...\n");
  exit(0);
#endif

  PROCESS_END();
}
예제 #2
0
PROCESS_THREAD(cetic_6lbr_process, ev, data)
{
  static struct etimer timer;
  static int addr_number;
  PROCESS_BEGIN();

  /* Step 0: Basic infrastructure initialization */

  LOG6LBR_NOTICE("Starting 6LBR version " CETIC_6LBR_VERSION " (" CONTIKI_VERSION_STRING ")\n");

  //Turn off radio until 6LBR is properly configured
  NETSTACK_MAC.off(0);

  cetic_6lbr_restart_event = process_alloc_event();
  cetic_6lbr_reload_event = process_alloc_event();
  cetic_6lbr_startup = clock_seconds();

#if CETIC_6LBR_MULTI_RADIO
  network_itf_init();
#endif

  /* Step 1: Platform specific initialization */

  platform_init();

  /* Step 2: Register configuration hooks and set default configuration */

#if CETIC_6LBR_NODE_INFO
  node_info_config();
#endif

  /* Step 3: Load configuration from NVM and configuration file */

  platform_load_config(CONFIG_LEVEL_BOOT);

#if !LOG6LBR_STATIC
  if(nvm_data.log_level != 0xFF) {
    Log6lbr_level = nvm_data.log_level;
    Log6lbr_services = nvm_data.log_services;
  }
  LOG6LBR_NOTICE("Log level: %d (services: %x)\n", Log6lbr_level, Log6lbr_services);
#else
  LOG6LBR_NOTICE("Log level: %d (services: %x)\n", LOG6LBR_LEVEL, LOG6LBR_SERVICE_DEFAULT);
#endif

  /* Step 4: Initialize radio and network interfaces */
#if CETIC_6LBR_FRAMER_WRAPPER
  framer_wrapper_init();
#endif

#if CETIC_6LBR_MAC_WRAPPER
  mac_wrapper_init();
#endif

#if CETIC_6LBR_MULTI_RADIO
  CETIC_6LBR_MULTI_RADIO_DEFAULT_MAC.init();
#endif

#if !CETIC_6LBR_ONE_ITF
  platform_radio_init();
  while(!radio_ready) {
    PROCESS_PAUSE();
  }
#endif

  eth_drv_init();

  while(!ethernet_ready) {
    PROCESS_PAUSE();
  }

  //Turn on radio and keep it always on
  NETSTACK_MAC.off(1);

  /* Step 5: Initialize Network stack */

#if CETIC_6LBR_LLSEC_WRAPPER
#if CETIC_6LBR_WITH_ADAPTIVESEC
  llsec_strategy_wrapper_init();
#endif
  llsec_wrapper_init();
#endif

#if CETIC_6LBR_MULTICAST_WRAPPER
  multicast_wrapper_init();
#endif
  //6LoWPAN init
  memcpy(addr_contexts[0].prefix, nvm_data.wsn_6lowpan_context_0, sizeof(addr_contexts[0].prefix));

  //clean up any early packet
  uip_len = 0;
  process_start(&tcpip_process, NULL);

  PROCESS_PAUSE();

  /* Step 6: Configure network interfaces */

  packet_filter_init();
  cetic_6lbr_init();

  //Wait result of DAD on 6LBR addresses
  addr_number = uip_ds6_get_addr_number(-1);
  LOG6LBR_INFO("Checking addresses duplication\n");
  etimer_set(&timer, CLOCK_SECOND);
  while(uip_ds6_get_addr_number(ADDR_TENTATIVE) > 0) {
    PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
    etimer_set(&timer, CLOCK_SECOND);
  }
  //Can not use equality as autoconf address could be created when running DAD
  if(uip_ds6_get_addr_number(-1) < addr_number) {
    LOG6LBR_FATAL("Addresses duplication failed\n");
    cetic_6lbr_restart_type = CETIC_6LBR_RESTART;
    platform_restart();
  }

  /* Step 7: Finalize configuration of network interfaces */
  cetic_6lbr_init_finalize();

  /* Step 8: Initialize 6LBR core and base applications */

  platform_load_config(CONFIG_LEVEL_CORE);
  PROCESS_PAUSE();

#if CETIC_6LBR_WITH_WEBSERVER
  webserver_init();
#endif

#if CETIC_6LBR_NODE_INFO
  node_info_init();
#endif

#if CETIC_6LBR_NODE_CONFIG
  node_config_init();
#endif

  /* Step 9: Initialize and configure 6LBR applications */

  platform_load_config(CONFIG_LEVEL_BASE);
  PROCESS_PAUSE();

#if CETIC_6LBR_WITH_UDPSERVER
  udp_server_init();
#endif
#if UDPCLIENT
  process_start(&udp_client_process, NULL);
#endif

#if WITH_TINYDTLS
  dtls_init();
#endif

#if WITH_COAPSERVER
  if((nvm_data.global_flags & CETIC_GLOBAL_DISABLE_COAP_SERVER) == 0) {
    coap_server_init();
  }
#endif

#if WITH_DTLS_ECHO
  process_start(&dtls_echo_server_process, NULL);
#endif

#if CETIC_6LBR_WITH_NVM_PROXY
  nvm_proxy_init();
#endif

#if CETIC_6LBR_WITH_DNS_PROXY
  dns_proxy_init();
#endif

  /* Step 10: Finalize platform configuration and load runtime configuration */

  platform_finalize();
  platform_load_config(CONFIG_LEVEL_APP);

  LOG6LBR_INFO("CETIC 6LBR Started\n");

  PROCESS_WAIT_EVENT_UNTIL(ev == cetic_6lbr_restart_event);

  etimer_set(&timer, CLOCK_SECOND);
  PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);

  /* Shutdown 6LBR */

  //Turn off radio
  NETSTACK_MAC.off(0);
  platform_restart();

  PROCESS_END();
}
예제 #3
0
파일: cetic-6lbr.c 프로젝트: Mastnest/6lbr
PROCESS_THREAD(cetic_6lbr_process, ev, data)
{
  PROCESS_BEGIN();

  cetic_6lbr_startup = clock_seconds();

#if CONTIKI_TARGET_NATIVE
  slip_config_handle_arguments(contiki_argc, contiki_argv);
  if (watchdog_interval) {
    process_start(&native_6lbr_watchdog, NULL);
  } else {
    LOG6LBR_WARN("6LBR Watchdog disabled\n");
  }
#endif

  LOG6LBR_INFO("Starting 6LBR version " CETIC_6LBR_VERSION " (" CONTIKI_VERSION_STRING ")\n");

  load_nvm_config();

  platform_init();

  process_start(&eth_drv_process, NULL);

  while(!ethernet_ready) {
    PROCESS_PAUSE();
  }

  //clean up any early packet
  uip_len = 0;
  process_start(&tcpip_process, NULL);

  PROCESS_PAUSE();

#if CETIC_NODE_INFO
  node_info_init();
#endif

  packet_filter_init();
  cetic_6lbr_init();

#if WEBSERVER
  process_start(&webserver_nogui_process, NULL);
#endif
#if UDPSERVER
  process_start(&udp_server_process, NULL);
#endif

  LOG6LBR_INFO("CETIC 6LBR Started\n");

#if CONTIKI_TARGET_NATIVE
  PROCESS_WAIT_EVENT();
  etimer_set(&reboot_timer, CLOCK_SECOND);
  PROCESS_WAIT_EVENT();
  switch (cetic_6lbr_restart_type) {
    case CETIC_6LBR_RESTART:
      LOG6LBR_INFO("Exiting...\n");
      exit(0);
      break;
    case CETIC_6LBR_REBOOT:
      LOG6LBR_INFO("Rebooting...\n");
      system("reboot");
      break;
    case CETIC_6LBR_HALT:
      LOG6LBR_INFO("Halting...\n");
      system("halt");
      break;
    default:
      //We should never end up here...
      exit(1);
  }
  //We should never end up here...
  exit(1);
#endif

  PROCESS_END();
}