Exemplo n.º 1
0
static void
set_global_address(void)
{
    uip_ipaddr_t ipaddr;

    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_AUTOCONF);

    /* set server address */
    uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
    //uip_ip6addr(&server_ipaddr, 0xfe80, 0, 0, 0,0x0212, 0x7401, 1, 0x0101);

}
/*---------------------------------------------------------------------------*/
static void
set_connection_address(uip_ipaddr_t *ipaddr)
{
#define _QUOTEME(x) #x
#define QUOTEME(x) _QUOTEME(x)
#ifdef UDP_CONNECTION_ADDR
  if(uiplib_ipaddrconv(QUOTEME(UDP_CONNECTION_ADDR), ipaddr) == 0) {
    PRINTF("UDP client failed to parse address '%s'\n", QUOTEME(UDP_CONNECTION_ADDR));
  }
#elif UIP_CONF_ROUTER
  uip_ip6addr(ipaddr,0xaaaa,0,0,0,0x0212,0x7404,0x0004,0x0404);
#else
  uip_ip6addr(ipaddr,0xfe80,0,0,0,0x6466,0x6666,0x6666,0x6666);
#endif /* UDP_CONNECTION_ADDR */
}
Exemplo n.º 3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t global_ipaddr;

  PROCESS_BEGIN();

  printf("App: %u starting\n", node_id);

  uip_ip6addr(&root_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);

  if(node_id == ROOT_ID) {
    memcpy(&global_ipaddr, &root_ipaddr, 16);
    uip_ds6_addr_add(&global_ipaddr, 0, ADDR_MANUAL);
    rpl_dag_t *dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &global_ipaddr);
    rpl_set_prefix(dag, &global_ipaddr, 64);
  } else {
    uip_ip6addr(&global_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&global_ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&global_ipaddr, 0, ADDR_AUTOCONF);
  }

  orpl_init(&global_ipaddr, node_id == ROOT_ID, 1);
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  if(node_id == ROOT_ID) {
    NETSTACK_RDC.off(1);
  } else {
    etimer_set(&periodic_timer, SEND_INTERVAL);
    while(1) {
      etimer_set(&send_timer, random_rand() % (SEND_INTERVAL));
      PROCESS_WAIT_UNTIL(etimer_expired(&send_timer));

      if(orpl_current_edc() != 0xffff) {
        app_send_to(ROOT_ID);
      } else {
        printf("App: not in DODAG\n");
      }

      PROCESS_WAIT_UNTIL(etimer_expired(&periodic_timer));
      etimer_reset(&periodic_timer);
    }
  }

  PROCESS_END();
}
Exemplo n.º 4
0
/* Glowny program */
PROCESS_THREAD(program_UDP, ev, data) {
    static struct etimer et;

    PROCESS_BEGIN();

#if UIP_CONF_IPV6 > 0
    uip_ip6addr(&ipaddr, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]);
#else
    uip_ipaddr(&ipaddr, addr[0], addr[1], addr[2], addr[3]);
#endif

    conn = udp_new(&ipaddr, UIP_HTONS(port), &state);
    udp_bind(conn, UIP_HTONS(port + 1));
    printf("Binded\n");

    etimer_set(&et, CLOCK_CONF_SECOND * 3);

    while (1) {
        PROCESS_WAIT_EVENT();
        if (uip_newdata()) {
            str = uip_appdata;
            str[uip_datalen()] = '\0';
            printf("Received: '%s'\n", str);
        }
        etimer_reset(&et);
    }

    PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(start_app, ev, data)
{
  PROCESS_BEGIN();
  static int is_coordinator = 0;

  memset(rx_buf, '\0', sizeof(rx_buf));
  /* Define process that handles data */
  process_start(&rx_data_process ,NULL);
  /* Initialise UART1 */
  uart1_init(UART1_BAUD_RATE); 
  /* Callback received byte */
  uart1_set_input(handleRxChar);

  /* Start network stack */
  if(is_coordinator) {
    uip_ipaddr_t prefix;
    uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    rpl_tools_init(&prefix);
  } else {
    rpl_tools_init(NULL);
  }
  printf("Starting RPL node\n");
  
  rest_init_engine();
  rest_activate_resource(&resource_coap_rx_uart1, "UART1-RX");
  rest_activate_resource(&resource_coap_tx_uart1, "UART1-TX");

  PROCESS_END();
}
Exemplo n.º 6
0
void set_net_address(void)
{
  uip_ipaddr_t ipaddr;
#if RPL_BORDER_ROUTER
  rpl_dag_t *dag;
#endif

  uip_ip6addr(&ipaddr, NET_ADDR_A, NET_ADDR_B, NET_ADDR_C, NET_ADDR_D, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);  

 
//#if !UIP_CONF_ROUTER
//  uip_ds6_prefix_add(&ipaddr, 64, 0); // For on-link determination.
//#else
//  uip_ds6_prefix_add(&ipaddr, 64, 0, 0, 600, 600);
//#endif
  
  print_addresses();
  
#if RPL_BORDER_ROUTER
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,&ipaddr);
  if(dag != NULL) {
    PRINTF("This node is setted as root of a DAG.\r\n");
  }
  else {
    PRINTF("Error while setting this node as root of a DAG.\r\n");
  }
#endif
  
}
Exemplo n.º 7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
#if UIP_CONF_ROUTER
  uip_ipaddr_t ipaddr;
#endif /* UIP_CONF_ROUTER */

  PROCESS_BEGIN();
  PRINTF("UDP server started\n");

#if UIP_CONF_ROUTER
  uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
#endif /* UIP_CONF_ROUTER */

  print_local_addresses();

  server_conn = udp_new(NULL, UIP_HTONS(3001), NULL);
  udp_bind(server_conn, UIP_HTONS(3000));

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Exemplo n.º 8
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{

  PROCESS_BEGIN();
  PRINTF("UDP server started\n");

#if UIP_CONF_ROUTER
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_netif_addr_add(&ipaddr, 64, 0, AUTOCONF);
#endif /* UIP_CONF_ROUTER */

  print_local_addresses();

  server_conn = udp_new(NULL, HTONS(61617), NULL);
  udp_bind(server_conn, HTONS(61616));

  PRINTF("Created a server connection with remote address ");
  PRINT6ADDR(&server_conn->ripaddr);
  PRINTF("local/remote port %u/%u\n", HTONS(server_conn->lport),
         HTONS(server_conn->rport));

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Exemplo n.º 9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et;
  uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();

  /* NOTE: Use IPv6 address of server here. */

  uip_ip6addr(&ipaddr, 0xfe80, 0x0000, 0x0000, 0x0000, 0x48ad, 0x5dff, 0xfe71, 0x5d9d);

  /* new connection with remote host */
  client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
  udp_bind(client_conn, UIP_HTONS(3034));

  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));

  etimer_set(&et, SEND_INTERVAL);
  while (1) {
    PROCESS_YIELD();
    if (etimer_expired(&et)) {
      timeout_handler();
      etimer_restart(&et);
    } else if (ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Exemplo n.º 10
0
/* -----------------------------------------------------------------------------
 *
 * -------------------------------------------------------------------------- */
void xtcpd_connect(int linknum, int port_number, xtcp_ipaddr_t addr,
                   xtcp_protocol_t p) {
  uip_ipaddr_t uipaddr;
#if UIP_CONF_IPV4
  uip_ipaddr(&uipaddr, addr.u8[0], addr.u8[1], addr.u8[2], addr.u8[3]);
#elif UIP_CONF_IPV6
  uip_ip6addr(&uipaddr, addr.u16[0], addr.u16[1], addr.u16[2], addr.u16[3],
		                addr.u16[4], addr.u16[5], addr.u16[6], addr.u16[7]);
#endif /* UIP_CONF_IPVx */
  if (p == XTCP_PROTOCOL_TCP) {
    struct uip_conn *conn = uip_connect(&uipaddr, HTONS(port_number));
    if (conn != NULL) {
         xtcpd_state_t *s = (xtcpd_state_t *) &(conn->appstate);
         s->linknum = linknum;
         s->s.connect_request = 1;
         s->conn.connection_type = XTCP_CLIENT_CONNECTION;
       }
  }
  else {
    struct uip_udp_conn *conn;
    conn = uip_udp_new(&uipaddr, HTONS(port_number));
    if (conn != NULL) {
      xtcpd_state_t *s = (xtcpd_state_t *) &(conn->appstate);
      s->linknum = linknum;
      s->s.connect_request = 1;
      s->conn.connection_type = XTCP_CLIENT_CONNECTION;
    }
  }
  return;
}
Exemplo n.º 11
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
#if UIP_CONF_ROUTER
  uip_ipaddr_t ipaddr;
#endif /* UIP_CONF_ROUTER */

  PROCESS_BEGIN();
  PRINTF("UDP server started\n");

#if RESOLV_CONF_SUPPORTS_MDNS
  resolv_set_hostname("contiki-udp-server");
#endif

#if UIP_CONF_ROUTER
  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_AUTOCONF);
#endif /* UIP_CONF_ROUTER */

  print_local_addresses();

  server_conn = udp_new(NULL, UIP_HTONS(3001), NULL);
  udp_bind(server_conn, UIP_HTONS(3000));

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Exemplo n.º 12
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{

//  uint16_t ipaddr=(uint16_t) IP_TRANS128;
//#if UIP_CONF_ROUTER
  uip_ipaddr_t ipaddr;//=IP_TRANS128;
  uip_ip6addr(&ipaddr,0xfe80,0,0,0,0x2001,0x22ff,0xfe33,0x4455);
//#endif /* UIP_CONF_ROUTER */

  PROCESS_BEGIN();



  SENSORS_ACTIVATE(button_sensor);//activate button
  leds_init();
  leds_off(LEDS_ALL);
  simple_udp_register(&udp_connection, UDP_PORT, NULL, UDP_PORT, receiver);


  while(1) {
//	  printf("bla1");
   PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);
  // PROCESS_YIELD();
   send_data(&ipaddr);
    
  }

  PROCESS_END();
}
Exemplo n.º 13
0
/*----------------------------------------------------------------------------*/
int8_t demo_udp_socket_init(void) {


	/* The choice of server address determines its 6LoPAN header compression.
	* (Our address will be compressed Mode 3 since it is derived from our link-local address)
	* Obviously the choice made here must also be selected in udp-server.c.
	*
	* For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences,
	* e.g. set Context 0 to aaaa::.  At present Wireshark copies Context/128 and then overwrites it.
	* (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::1111:22ff:fe33:xxxx)
	*
	* Note the IPCMV6 checksum verification depends on the correct uncompressed addresses.
	*/
	/* We know destination IP address but we need to properly convert it */
	uip_ip6addr(&un_server_ipaddr, 	un_server_ipaddr.u16[0],un_server_ipaddr.u16[1],\
									un_server_ipaddr.u16[2],un_server_ipaddr.u16[3],\
									un_server_ipaddr.u16[4],un_server_ipaddr.u16[5],\
									un_server_ipaddr.u16[6],un_server_ipaddr.u16[7]);
	pst_conn = udp_new(NULL, UIP_HTONS(__SERVER_PORT), NULL);
	udp_bind(pst_conn, UIP_HTONS(__CLIENT_PORT));

	LOG_INFO("%s", "Create connection with the server ");
	//uip_debug_ipaddr_print(&un_server_ipaddr);
	LOG_RAW("\n\r");
	LOG_INFO("local/remote port %u/%u\n\r",
			UIP_HTONS(pst_conn->lport),
			UIP_HTONS(pst_conn->rport));
	//printf("Set dudp timer %p\n\r",&st_et);
	etimer_set(&st_et, SEND_INTERVAL, _demo_udp_callback);
	evproc_regCallback(EVENT_TYPE_TCPIP,_demo_udp_callback);
	return 1;
}/* demo_udp_init()  */
Exemplo n.º 14
0
//**************************************************************************************************************************************************//
PROCESS_THREAD(RSSI_SCAN, ev, data)
{
    static struct etimer rssitimer;
    static struct rtimer rt;
    PROCESS_BEGIN();
    // Set the local address
    uip_ip6addr(&my_addr, 0, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&my_addr, &uip_lladdr);
    uip_ds6_addr_add(&my_addr, 0, ADDR_MANUAL);

    //listening to port 3001 from beacons and sensors
    listen_conn = udp_new(NULL, UIP_HTONS(0), NULL);

    //Server Listen connection is bound too port 4001
    udp_bind(listen_conn, UIP_HTONS(RECEIVER_PORT));

    while(1)
    {
        //printf("inside while\n\r");
        //etimer_set(&rssitimer, CLOCK_SECOND/200);
        //GPIO_SET_PIN(GPIO_C_BASE, GPIO_PIN_MASK(1));
        //PROCESS_YIELD();
        PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
        if ((ev == tcpip_event))
        {
            recv_handler();
        }
    }
    PROCESS_END();
}
Exemplo n.º 15
0
static unsigned short
make_neighbor(void *arg)
{
  struct httpd_state *s = (struct httpd_state *)arg;
  struct collect_neighbor *n = collect_neighbor_get(s->u.count);

  if(n == NULL) {
    return 0;
  }

#if !UIP_CONF_IPV6
  return snprintf((char *)uip_appdata, uip_mss(),
		  "<li><a href=\"http://172.16.%d.%d/\">%d.%d</a>\r\n",
		  n->addr.u8[0], n->addr.u8[1],
		  n->addr.u8[0], n->addr.u8[1]);
#else
#if 0
  uip_ipaddr_t ipaddr;
  char ipaddr_str[41];
  
  uip_ip6addr(&ipaddr, NET_ADDR_A, NET_ADDR_B, NET_ADDR_C, NET_ADDR_D,
              (uint16_t)(((uint16_t)(n->addr.u8[0]^0x02))<<8 | (uint16_t)n->addr.u8[1]),
              ((uint16_t)(n->addr.u8[2]))<<8 | (uint16_t)n->addr.u8[3],
              (uint16_t)(n->addr.u8[4])<<8 | n->addr.u8[5],
              (uint16_t)(n->addr.u8[6])<<8 | n->addr.u8[7]);
  httpd_sprint_ip6(ipaddr, ipaddr_str);
  
  return snprintf((char *)uip_appdata, uip_mss(),
		  "<li><a href=\"http://%s/\">%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X</a>\r\n",
		  ipaddr_str,
          n->addr.u8[0],
          n->addr.u8[1],
          n->addr.u8[2],
          n->addr.u8[3],
          n->addr.u8[4],
          n->addr.u8[5],
          n->addr.u8[6],
          n->addr.u8[7]);
#endif
  /* Automatic generation of node address. Javascript funcion required.
   * Client-side generation is simpler than server-side, as parsing http header
   * would be requied.
   */
  return snprintf((char *)uip_appdata, uip_mss(),
                  "<li><a id=node name='%x:%x:%x:%x'>%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X</a>\r\n",
                  (uint16_t)(((uint16_t)(n->addr.u8[0]^0x02))<<8 | (uint16_t)n->addr.u8[1]),
                  ((uint16_t)(n->addr.u8[2]))<<8 | (uint16_t)n->addr.u8[3],
                  (uint16_t)(n->addr.u8[4])<<8 | n->addr.u8[5],
                  (uint16_t)(n->addr.u8[6])<<8 | n->addr.u8[7],
                  n->addr.u8[0],
                  n->addr.u8[1],
                  n->addr.u8[2],
                  n->addr.u8[3],
                  n->addr.u8[4],
                  n->addr.u8[5],
                  n->addr.u8[6],
                  n->addr.u8[7]);
  
#endif /* UIP_CONF_IPV6 */
}
Exemplo n.º 16
0
void add_route(int dest, int next) {
    uip_ipaddr_t ipaddr_dest, ipaddr_next;
#if !IN_COOJA
    uint32_t dest_suffix = get_mote_suffix(dest);
    uint32_t next_suffix = get_mote_suffix(next);
#endif
    PRINTF("add route %d %d\n", dest, next);
#if IN_COOJA
    uip_ip6addr(&ipaddr_dest, 0xaaaa, 0, 0, 0, 0x0212, 0x7400 | dest, dest, dest<<8 | dest);
    uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400 | next, next, next<<8 | next);
#else
    uip_ip6addr(&ipaddr_dest, 0xaaaa, 0, 0, 0, 0x0212, 0x7400, (dest_suffix >> 16) & 0xffff, dest_suffix & 0xffff);
    uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400, (next_suffix >> 16) & 0xffff, next_suffix & 0xffff);
#endif
    uip_ds6_route_add(&ipaddr_dest, 128, &ipaddr_next, 0);
}
Exemplo n.º 17
0
void set_global_address(void) {
  uip_ipaddr_t ipaddr;

  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_AUTOCONF);
}
Exemplo n.º 18
0
/*---------------------------------------------------------------------------*/
void
rpl_link_neighbor_callback(const linkaddr_t *addr, int status, int numtx)
{
  uip_ipaddr_t ipaddr;
  rpl_parent_t *parent;
  rpl_instance_t *instance;
  rpl_instance_t *end;

  uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&ipaddr, (uip_lladdr_t *)addr);

  for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) {
    if(instance->used == 1 ) {
      parent = rpl_find_parent_any_dag(instance, &ipaddr);
      if(parent != NULL) {
        /* Trigger DAG rank recalculation. */
        PRINTF("RPL: rpl_link_neighbor_callback triggering update\n");
        parent->flags |= RPL_PARENT_FLAG_UPDATED;
        if(instance->of->neighbor_link_callback != NULL) {
          instance->of->neighbor_link_callback(parent, status, numtx);
          parent->last_tx_time = clock_time();
        }
      }
    }
  }
}
Exemplo n.º 19
0
/*---------------------------------------------------------------------------*/
static uip_ipaddr_t *
set_global_address(void)
{
  static uip_ipaddr_t ipaddr;
  int i;
  uint8_t state;

  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_AUTOCONF);

  printf("IPv6 addresses: ");
  for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
    state = uip_ds6_if.addr_list[i].state;
    if(uip_ds6_if.addr_list[i].isused &&
       (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
      uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
      printf("\n");
      if(state == ADDR_TENTATIVE) {
        uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
      }
    }
  }

  return &ipaddr;
}
Exemplo n.º 20
0
/* Sends a ping packet out the radio */
static void
raven_ping6(void)
{
   
  /* ping ipv6.google.com*/
  uip_ip6addr(&ping_addr,0x2001,0x420,0x5FFF,0x7D,0x2D0,0xB7FF,0xFE23,0xE6DB);
  //uip_ip6addr(&ping_addr, 0x2001, 0x4860, 0, 0x2001, 0, 0, 0, 0x68);
  //uip_ip6addr(&ping_addr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
  
  UIP_IP_BUF->vtc = 0x60;
  UIP_IP_BUF->tcflow = 1;
  UIP_IP_BUF->flow = 0;
  UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
  UIP_IP_BUF->ttl = uip_netif_physical_if.cur_hop_limit;
  uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &ping_addr);
  uip_netif_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
 
  UIP_ICMP_BUF->type = ICMP6_ECHO_REQUEST;
  UIP_ICMP_BUF->icode = 0;
  /* set identifier and sequence number to 0 */
  memset((void *)UIP_ICMP_BUF + UIP_ICMPH_LEN, 0, 4);
    
  uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN;
  UIP_IP_BUF->len[0] = (u8_t)((uip_len - 40) >> 8);
  UIP_IP_BUF->len[1] = (u8_t)((uip_len - 40) & 0x00FF);
    
  UIP_ICMP_BUF->icmpchksum = 0;
  UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
    
  tcpip_ipv6_output();
}
Exemplo n.º 21
0
PROCESS_THREAD(raven_lcd_process, ev, data)
{
    PROCESS_BEGIN();

    /* Initialize the sensor data history */
    memcpy(last_temp, "20.0", sizeof("20.0"));

    /*Create a udp connection to the server*/
    uip_ip6addr(&server_addr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);

    /* set destination parameters */
    send_conn = udp_new(&server_addr, SERVER_PORT, NULL);
    /*set local port */
    udp_bind(send_conn, HTONS(0xF0B0+1));

    /* Listen to port 0xF0B0 for commands */
    node_conn = udp_new(NULL, 0, NULL);
    udp_bind(node_conn, HTONS(0xF0B0));

    if(icmp6_new(NULL) != NULL) {
        while(1) {
            PROCESS_YIELD();
            raven_gui_loop(ev, data);
        }
    }
    PROCESS_END();
}
Exemplo n.º 22
0
static uip_ipaddr_t *
lookup(uip_ipaddr_t *destipaddr, uip_ipaddr_t *nexthop)
{
  static rimeaddr_t rimeaddr;
  struct route_entry *route;
  int i;

  for(i = 1; i < sizeof(rimeaddr); i++) {
    rimeaddr.u8[i] = destipaddr->u8[sizeof(*destipaddr) - sizeof(rimeaddr) + i];
  }
  rimeaddr.u8[0] = 0;

  PRINTF("rimeroute: looking up ");
  PRINT6ADDR(destipaddr);
  PRINTF(" with Rime address ");
  PRINTRIMEADDR((&rimeaddr));
  PRINTF("\n");

  route = route_lookup(&rimeaddr);
  if(route == NULL) {
    process_post(&rimeroute_process, rimeroute_event, &rimeaddr);
    return NULL;
  }

  uip_ip6addr(nexthop, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
  uip_netif_addr_autoconf_set(nexthop, (uip_lladdr_t *)&route->nexthop);
  PRINTF("rimeroute: ");
  PRINT6ADDR(destipaddr);
  PRINTF(" can be reached via ");
  PRINT6ADDR(nexthop);
  PRINTF("\n");

  return nexthop;
}
Exemplo n.º 23
0
PROCESS_THREAD(raven_lcd_process, ev, data)
{
  u8_t error;

  PROCESS_BEGIN();

  /*Create a udp connection to the IPSOserver*/

  //swisscom uip_ip6addr(&udp_addr,0x2001,918,0xfff9,0,0,0,0,1); 
  //HE uip_ip6addr(&udp_addr,0x2001,0x470,0x1f12,0x5ec,0x12,0x13ff,0xfe14,0x1516);
  uip_ip6addr(&udp_addr,0x2001,0x420,0x5FFF,0x7D,0x2D0,0xB7FF,0xFE23,0xE6DB);
  
  /* set destination parameters*/
  udp_conn = udp_new(&udp_addr, HTONS(0xF0B0), NULL);
  /*set local port */
  udp_bind(udp_conn, HTONS(0xF0B0+1));
  
  if((error = icmp6_new(NULL)) == 0) {
    while(1) {
      PROCESS_YIELD();
      raven_gui_loop(ev, data);
    } 
  }
  PROCESS_END();
}
Exemplo n.º 24
0
/*---------------------------------------------------------------------------*/
static uip_ipaddr_t *
set_global_address(void)
{
  static uip_ipaddr_t ipaddr;
  int i;
  uint8_t state;

  /* Assign a unique local address (RFC4193,
     http://tools.ietf.org/html/rfc4193). */
  uip_ip6addr(&ipaddr, 0xfc00, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);

  printf("IPv6 addresses: ");
  for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
    state = uip_ds6_if.addr_list[i].state;
    if(uip_ds6_if.addr_list[i].isused &&
       (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
      uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
      printf("\n");
    }
  }

  return &ipaddr;
}
Exemplo n.º 25
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(start_app, ev, data)
{
  PROCESS_BEGIN();
  static int is_coordinator = 0;

  /* Switch off dongle leds */

  /* Initialise ct timer, but don't let it run yet */
  ctimer_set(&ct, TOGGLE_TIME, ct_callback, NULL);
  ctimer_stop(&ct);

  /* Start net stack */
  if(is_coordinator) {
    uip_ipaddr_t prefix;
    uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    rpl_tools_init(&prefix);
  } else {
    rpl_tools_init(NULL);
  } printf("Starting RPL node\n");

  rest_init_engine();
  rest_activate_resource(&resource_led_toggle, "Dongle/LED-toggle");

  PROCESS_END();
}
Exemplo n.º 26
0
/*---------------------------------------------------------------------------*/
static void
set_own_addresses(void)
{
  int i;
  uint8_t state;
  rpl_dag_t *dag;
  uip_ipaddr_t ipaddr;

  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_AUTOCONF);

  PRINTF("Our IPv6 addresses:\n");
  for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
    state = uip_ds6_if.addr_list[i].state;
    if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state
        == ADDR_PREFERRED)) {
      PRINTF("  ");
      PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
      PRINTF("\n");
      if(state == ADDR_TENTATIVE) {
        uip_ds6_if.addr_list[i].state = ADDR_PREFERRED;
      }
    }
  }

  /* Become root of a new DODAG with ID our global v6 address */
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &ipaddr);
  if(dag != NULL) {
    rpl_set_prefix(dag, &ipaddr, 64);
    PRINTF("Created a new RPL dag with ID: ");
    PRINT6ADDR(&dag->dag_id);
    PRINTF("\n");
  }
}
Exemplo n.º 27
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et;
  uip_ipaddr_t ipaddr;

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

  uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0x0215, 0x2000, 0x0002, 0x2145);
  /* new connection with remote host */
  l_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
  if(!l_conn) {
    PRINTF("udp_new l_conn error.\n");
  }
  udp_bind(l_conn, UIP_HTONS(LOCAL_CONN_PORT));

  PRINTF("Link-Local connection with ");
  PRINT6ADDR(&l_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
         UIP_HTONS(l_conn->lport), UIP_HTONS(l_conn->rport));

  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0x0215, 0x2000, 0x0002, 0x2145);
  g_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
  if(!g_conn) {
    PRINTF("udp_new g_conn error.\n");
  }
  udp_bind(g_conn, UIP_HTONS(GLOBAL_CONN_PORT));

  PRINTF("Global connection with ");
  PRINT6ADDR(&g_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
         UIP_HTONS(g_conn->lport), UIP_HTONS(g_conn->rport));

  etimer_set(&et, SEND_INTERVAL);

  while(1) {
    PROCESS_YIELD();
    if(etimer_expired(&et)) {
      timeout_handler();
      etimer_restart(&et);
    } else if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Exemplo n.º 28
0
/*---------------------------------------------------------------------------*/
static void
set_global_address(void)
{
  uip_ipaddr_t ipaddr;
  
  #if 0
  /* Mode 1 - 64 bits inline */
  uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
  #elif 1
  /* Mode 2 - 16 bits inline */
  uip_ip6addr(&server_ipaddr, 0x2001, 5, 0, 0, 0x200, 0, 0, 1);
  #else
  /* Mode 3 - derived from server link-local (MAC) address */
  uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0x0250, 0xc2ff, 0xfea8, 0xcd1a); //redbee-econotag
  #endif

}
Exemplo n.º 29
0
  PROCESS_THREAD(raven_relay_process, ev, data) {
    uip_ipaddr_t ipaddr;
    PROCESS_POLLHANDLER(pollhandler());
    PROCESS_EXITHANDLER(exithandler());

    // see: http://senstools.gforge.inria.fr/doku.php?id=contiki:examples
    PROCESS_BEGIN();
    PRINTF("Relay process startup.\r\n");
    // wait 3 second, in order to have the IP addresses well configured
    etimer_set(&udp_periodic_timer, CLOCK_CONF_SECOND*3);
    // wait until the timer has expired
    PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
    // Define Address of the server that receives our heartbeats.
    // TODO: Make this dynamic
#ifdef UDP_ADDR_A
    uip_ip6addr(&ipaddr,
        UDP_ADDR_A,UDP_ADDR_B,UDP_ADDR_C,UDP_ADDR_D,
        UDP_ADDR_E,UDP_ADDR_F,UDP_ADDR_G,UDP_ADDR_H);
#else /* UDP_ADDR_A */
    uip_ip6addr(&ipaddr,0xbbbb,0,0,0,0xd69a,0x20ff,0xfe07,0x7664);
#endif /* UDP_ADDR_A */

    udpconn = udp_new(NULL, HTONS(0), NULL);

    //udpconn = udp_new(&ipaddr, HTONS(0xF0B0+1), NULL);
    udp_bind(udpconn, HTONS(0xF0B0));
    // udp_attach(udpconn, NULL);

    PRINTF("Created connection with remote peer ");
    PRINT6ADDR(&udpconn->ripaddr);
    PRINTF("\r\nlocal/remote port %u/%u\r\n", HTONS(udpconn->lport),HTONS(udpconn->rport));

    print_local_addresses();
    etimer_set(&udp_periodic_timer, 60*CLOCK_SECOND);

    while(1){
      PRINTF("--- Relay: Waiting for events.\r\n");
      //   tcpip_poll_udp(udpconn);
      PROCESS_WAIT_EVENT();
      //    PROCESS_YIELD();
      udphandler(ev, data);
    }


    PROCESS_END();
  }
Exemplo n.º 30
0
PROCESS_THREAD(border_router_process, ev, data)
{

  PROCESS_BEGIN();

  PROCESS_PAUSE();

{ rpl_dag_t *dag;
  char buf[sizeof(dag_id)];
  memcpy(buf,dag_id,sizeof(dag_id));
  dag = rpl_set_root((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
void sprint_ip6(uip_ip6addr_t addr);
    int i;
    uip_ip6addr_t ipaddr;
#ifdef HARD_CODED_ADDRESS
    uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
#else
    uip_ip6addr(&ipaddr, 0xbbbb, 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
  }
}
  /* The border router runs with a 100% duty cycle in order to ensure high
     packet reception rates. */
 // NETSTACK_MAC.off(1);

  while(1) {
    PROCESS_YIELD();
    /* Local and global dag repair can be done from ? */
 //   rpl_set_prefix(rpl_get_dag(RPL_ANY_INSTANCE), &ipaddr, 64);
 //   rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE));

  }

  PROCESS_END();
}