/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
  static struct etimer et;

  PROCESS_BEGIN();
  PRINTF("Border Router started\n");
  prefix_set = 0;

  leds_on(LEDS_RED);

  /* Request prefix until it has been received */
  while(!prefix_set) {
    leds_on(LEDS_GREEN);
    PRINTF("Prefix request.\n");
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    leds_off(LEDS_GREEN);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }

  /* We have created a new DODAG when we reach here */
  PRINTF("On Channel %u\n", (uint8_t)((FREQCTRL + 44) / 5));

  print_local_addresses();

  leds_off(LEDS_RED);

  PROCESS_EXIT();

  PROCESS_END();
}
예제 #2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
  static struct etimer et;

  PROCESS_BEGIN();
  PUTSTRING("Border Router started\n");
  prefix_set = 0;

  leds_on(LEDS_GREEN);

  /* Request prefix until it has been received */
  while(!prefix_set) {
    leds_on(LEDS_RED);
    PUTSTRING("Prefix request.\n");
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    leds_off(LEDS_RED);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }
  /* We have created a new DODAG when we reach here */
  PUTSTRING("On Channel ");
  PUTDEC(cc2530_rf_channel_get());
  PUTCHAR('\n');

  print_local_addresses();

  leds_off(LEDS_GREEN);

  PROCESS_EXIT();

  PROCESS_END();
}
예제 #3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
  static struct etimer et;

  PROCESS_BEGIN();

/* While waiting for the prefix to be sent through the SLIP connection, the future
 * border router can join an existing DAG as a parent or child, or acquire a default
 * router that will later take precedence over the SLIP fallback interface.
 * Prevent that by turning the radio off until we are initialized as a DAG root.
 */
  prefix_set = 0;

  PROCESS_PAUSE();

  PRINTF("RPL-Border router started\n");

  /* Request prefix until it has been received */
  while(!prefix_set) {
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    PRINTF("Waiting for prefix\n");
  }

  PRINTF("Obtained prefix: ");
  uip_debug_ipaddr_print(&prefix);
  PRINTF("\n");

  rpl_tools_init(&prefix);

  PROCESS_END();
}
예제 #4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(borderest_process, ev, data)
{
  static struct etimer et;

  PROCESS_BEGIN();

/* While waiting for the prefix to be sent through the SLIP connection, the future
 * border router can join an existing DAG as a parent or child, or acquire a default
 * router that will later take precedence over the SLIP fallback interface.
 * Prevent that by turning the radio off until we are initialized as a DAG root.
 */
  prefix_set = 0;
  NETSTACK_MAC.off(0);

  PROCESS_PAUSE();

  SENSORS_ACTIVATE(button_sensor);

  PRINTF("RPL-Border router started\n");
#if 0
   /* The border router runs with a 100% duty cycle in order to ensure high
     packet reception rates.
     Note if the MAC RDC is not turned off now, aggressive power management of the
     cpu will interfere with establishing the SLIP connection */
  NETSTACK_MAC.off(1);
#endif

  /* Request prefix until it has been received */
  while(!prefix_set) {
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }

  /* Now turn the radio on, but disable radio duty cycling.
   * Since we are the DAG root, reception delays would constrain mesh throughbut.
   */
  NETSTACK_MAC.off(1);

#if DEBUG || 1
  print_local_addresses();
#endif

  rest_init_engine();
  activate_coap_resources();

  leds_init();
  while(1) {
    PROCESS_YIELD();
    if (ev == sensors_event && data == &button_sensor) {
      PRINTF("Initiating global repair\n");
      rpl_repair_root(RPL_DEFAULT_INSTANCE);
      leds_toggle(LEDS_ALL);
    }
  }

  PROCESS_END();
}
예제 #5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
#ifdef PREFIX_DISC
  static struct etimer et;
#endif
  rpl_dag_t *dag;

  PROCESS_BEGIN();

  prefix_set = 0;

  PROCESS_PAUSE();

  SENSORS_ACTIVATE(button_sensor);

  PRINTF("RPL-Border router started\n");

   /* The border router runs with a 100% duty cycle in order to ensure high
     packet reception rates.
     Note if the MAC RDC is not turned off now, aggressive power management of the
     cpu will interfere with establishing the SLIP connection */
  NETSTACK_MAC.off(1);
 
#ifndef PREFIX_DISC
  if (!uiplib_ipaddrconv("aaaa::", &prefix))
      goto err;
#else
  /* Request prefix until it has been received */
  while(!prefix_set) {
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }
#endif

  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)dag_id);
  if(dag != NULL) {
    rpl_set_prefix(dag, &prefix, 64);
    PRINTF("created a new RPL dag\n");
  }

#if DEBUG || 1
  print_local_addresses();
#endif

  while(1) {
    PROCESS_YIELD();
    if (ev == sensors_event && data == &button_sensor) {
      PRINTF("Initiating global repair\n");
      rpl_repair_root(RPL_DEFAULT_INSTANCE);
    }
  }

err:
  PRINTF("Shutting down\n");
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
  static struct etimer et;
  rpl_dag_t *dag;

  PROCESS_BEGIN();
  prefix_set = 0;

  PROCESS_PAUSE();

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

  //SENSORS_ACTIVATE(button_sensor);

  PRINTF("RPL-Border router started\n");

  /* Request prefix until it has been received */
  while(!prefix_set) {
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }

  dag = rpl_set_root((uip_ip6addr_t *)dag_id);
  if(dag != NULL) {
    rpl_set_prefix(dag, &prefix, 64);
    PRINTF("created a new RPL dag\n");
  }

#if DEBUG || 1
  print_local_addresses();
#endif

  /* The border router runs with a 100% duty cycle in order to ensure high
     packet reception rates. */
  NETSTACK_MAC.off(1);

  static struct etimer t;
  etimer_set(&t, 10*CLOCK_SECOND);
  while(1) {
    PROCESS_YIELD();
    //if (ev == sensors_event && data == &button_sensor) {
    if (etimer_expired(&t)) {
      PRINTF("Initiating global repair\n");
      rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE));
      etimer_reset(&t);
    }
  }

  PROCESS_END();
}
예제 #7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
  static struct etimer et;
  rpl_dag_t *dag;

  PROCESS_BEGIN();

/* While waiting for the prefix to be sent through the SLIP connection, the future
 * border router can join an existing DAG as a parent or child, or acquire a default 
 * router that will later take precedence over the SLIP fallback interface.
 * Prevent that by turning the radio off until we are initialized as a DAG root.
 */
  prefix_set = 0;
  NETSTACK_MAC.off(0);

  PROCESS_PAUSE();

  SENSORS_ACTIVATE(button_sensor);

  PRINTF("RPL-Border router started\n");
#if 0
   /* The border router runs with a 100% duty cycle in order to ensure high
     packet reception rates.
     Note if the MAC RDC is not turned off now, aggressive power management of the
     cpu will interfere with establishing the SLIP connection */
  NETSTACK_MAC.off(1);
#endif
 
  /* Request prefix until it has been received */
  while(!prefix_set) {
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }

  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)dag_id);
  if(dag != NULL) {
    rpl_set_prefix(dag, &prefix, 64);
    PRINTF("created a new RPL dag\n");
  }

  /* Now turn the radio on, but disable radio duty cycling.
   * Since we are the DAG root, reception delays would constrain mesh throughbut.
   */
  NETSTACK_MAC.off(1);
  
#if DEBUG || 1
  print_local_addresses();
#endif

#if ENABLE_CBC_LINK_SECURITY
//   /*
//	* new connection with remote host at port 0
//	* to allow multiple remote ports on the same
//	* connection
//	*/
//	sec_conn = udp_new(NULL, 0, NULL);
//	if(sec_conn == NULL) {
//		PRINTFSECKEY("No UDP conn, exiting proc!\n");
//		PROCESS_EXIT();
//	}
//	udp_bind(sec_conn, UIP_HTONS(UDP_CLIENT_SEC_PORT));
#endif

  while(1) {
    PROCESS_YIELD();
    if (ev == sensors_event && data == &button_sensor) {
      PRINTF("Initiating global repair\n");
      rpl_repair_root(RPL_DEFAULT_INSTANCE);
    }
  }

  PROCESS_END();
}
예제 #8
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
  rpl_dag_t *dag;

  PROCESS_BEGIN();

/* While waiting for the prefix to be sent through the SLIP connection, the future
 * border router can join an existing DAG as a parent or child, or acquire a default
 * router that will later take precedence over the SLIP fallback interface.
 * Prevent that by turning the radio off until we are initialized as a DAG root.
 */
  prefix_set = 0;
  NETSTACK_MAC.off(0);

  PROCESS_PAUSE();

  //SENSORS_ACTIVATE(button_sensor);

  PRINTF("RPL-Border router started\n");
#if 0
   /* The border router runs with a 100% duty cycle in order to ensure high
     packet reception rates.
     Note if the MAC RDC is not turned off now, aggressive power management of the
     cpu will interfere with establishing the SLIP connection */
  NETSTACK_MAC.off(1);
#endif

  /* Request prefix until it has been received */
#define REQUEST_PREFIX  1
#if REQUEST_PREFIX

  static struct etimer et;

  while(!prefix_set) {
    etimer_set(&et, 1000);
    request_prefix();
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }

  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)dag_id);
   if(dag != NULL) {
     rpl_set_prefix(dag, &prefix, 64);
     PRINTF("created a new RPL dag\n");
   }

#else
  {
      char buf[sizeof(dag_id)];
      memcpy(buf,dag_id,sizeof(dag_id));
      dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)buf);

      /* Assign separate addresses to the uip stack and the host network
          interface, but with the same prefix E.g. bbbb::ff:fe00:200 to
          the stack and bbbb::1 to the host *fallback* network interface
          Otherwise the host will trap packets intended for the stack,
          just as the stack will trap packets intended for the host
          $ifconfig usb0 -arp on Ubuntu to skip the neighbor
          solicitations. Add explicit neighbors on other OSs */

      if(dag != NULL)
      {
    	  PRINTF("Created a new RPL dag\n");

  #if UIP_CONF_ROUTER_RECEIVE_RA
        /* Contiki stack will shut down until assigned an address from the
  	 interface RA Currently this requires changes in the core
  	 rpl-icmp6.c to pass the link-local RA broadcast.
        */

  #else
        {
			int i;
			uip_ip6addr_t ipaddr;
		  #ifdef HARD_CODED_ADDRESS
			uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
		  #else
			uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0x1);
		  #endif
			uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
			uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
			rpl_set_prefix(dag, &ipaddr, 64);

			for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
			  if(uip_ds6_if.addr_list[i].isused) {
				PRINTF("IPV6 Address: ");
				sprint_ip6(uip_ds6_if.addr_list[i].ipaddr);
				PRINTF("\n");
			  }
			}
        }
  #endif
      }
    }
#endif

  /* Now turn the radio on, but disable radio duty cycling.
   * Since we are the DAG root, reception delays would constrain mesh throughbut.
   */
  NETSTACK_MAC.off(1);

#if DEBUG || 1
  print_local_addresses();
#endif

  while(1) {
    PROCESS_YIELD();   
    if (ev == sensors_event){
		PRINTF("Initiating global repair\n");
		rpl_repair_root(RPL_DEFAULT_INSTANCE);
    }
  }

  PROCESS_END();
}
예제 #9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;
#if WITH_COMPOWER
  static int print = 0;
#endif

  PROCESS_BEGIN();

  PROCESS_PAUSE();

  set_global_address();
  
  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); 
  if(client_conn == NULL) {
    PRINTF("No UDP connection available, exiting the process!\n");
    PROCESS_EXIT();
  }
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); 
  PRINTF("UIP_CONF_TCP_MSS %u \n",UIP_CONF_TCP_MSS);
  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

#if WITH_COMPOWER
  powertrace_sniff(POWERTRACE_ON);
#endif

  etimer_set(&periodic, SEND_INTERVAL);
  request_prefix();
  slip_init();
  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
    
    if(etimer_expired(&periodic)) {
      etimer_reset(&periodic);
      ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);

#if WITH_COMPOWER
      if (print == 0) {
	powertrace_print("#P");
      }
      if (++print == 3) {
	print = 0;
      }
#endif

    }
  }

  PROCESS_END();
}