Exemplo n.º 1
0
void
uip_ds6_route_info_callback(uip_nd6_opt_route_info * rio,
                            uip_ip6addr_t * next_hop)
{
    PRINTF("RIO received\n");
    //TODO Preferences ?
    uip_ds6_route_t *found;

    if((found = uip_ds6_route_lookup(&rio->prefix)) == NULL
            && rio->rlifetime != 0) {
        //New route
        PRINTF("New route received\n");
        PRINTF("type=%d, flags=%d, length=%d, lifetime=%"PRIu32", Preflen=%d, prefix=",
               rio->type, rio->flagsreserved, rio->len, uip_ntohl(rio->rlifetime), rio->preflen);
        uip_ds6_route_t *new_route;

        if((new_route =
                    uip_ds6_route_add(&rio->prefix, rio->preflen, next_hop)) == NULL) {
            PRINTF("error when adding route\n");
        } else {
            PRINTF("Route added\n");
            new_route->state.lifetime = uip_ntohl(rio->rlifetime);
        }
    } else {
        PRINTF("Route already exists\n");
        if(rio->rlifetime == 0) {
            uip_ds6_route_rm(found);
        } else {
            found->state.lifetime = uip_ntohl(rio->rlifetime);
        }
    }
}
Exemplo n.º 2
0
uip_ds6_route_t *
rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len,
              uip_ipaddr_t *next_hop)
{
  uip_ds6_route_t *rep;

  rep = uip_ds6_route_lookup(prefix);
  if(rep == NULL) {
    if((rep = uip_ds6_route_add(prefix, prefix_len, next_hop, 0)) == NULL) {
      PRINTF("RPL: No space for more route entries\n");
      return NULL;
    }
  } else {
    PRINTF("RPL: Updated the next hop for prefix ");
    PRINT6ADDR(prefix);
    PRINTF(" to ");
    PRINT6ADDR(next_hop);
    PRINTF("\n");
    uip_ipaddr_copy(&rep->nexthop, next_hop);
  }
  rep->state.dag = dag;
  rep->state.lifetime = RPL_LIFETIME(dag, dag->default_lifetime);
  rep->state.learned_from = RPL_ROUTE_FROM_INTERNAL;

  PRINTF("RPL: Added a route to ");
  PRINT6ADDR(prefix);
  PRINTF("/%d via ", prefix_len);
  PRINT6ADDR(next_hop);
  PRINTF("\n");

  return rep;
}
Exemplo n.º 3
0
void stack_add_route(int iface, const ipv6_addr_t *prefix, uint8_t prefix_len,
                     const ipv6_addr_t *next_hop)
{
    uip_ds6_route_t *res;

    (void)iface;
    res = uip_ds6_route_add((uip_ipaddr_t *)prefix, prefix_len,
                            (uip_ipaddr_t *)next_hop);
    if (res != NULL) {
        res->state.lifetime = UINT32_MAX;
    }
}
Exemplo n.º 4
0
static void set_routes()
{
	/* Workaround to get packets from this task to listening fiber.
	 * Do not attempt to do anything like this in live environment.
	 */
	if (!uip_ds6_nbr_add((uip_ipaddr_t *)&in6addr_dest,
					&dest_mac, 0, NBR_REACHABLE))
		PRINT("Cannot add neighbor cache\n");

	if (!uip_ds6_route_add((uip_ipaddr_t *)&in6addr_dest, 128,
					(uip_ipaddr_t *)&in6addr_dest))
		PRINT("Cannot add localhost route\n");
}
Exemplo n.º 5
0
static void add_route_ext(int dest, int next) {
    uip_ipaddr_t ipaddr_dest, ipaddr_next;
#if !IN_COOJA
    uint32_t next_suffix = get_mote_suffix(next);
#endif
    PRINTF("add route ext %d %d\n", dest, next);
    uip_ip6addr(&ipaddr_dest, 0xaaaa, 0, 0, 0, 0, 0, 0, dest);
#if IN_COOJA
    uip_ip6addr(&ipaddr_next, 0xfe80, 0, 0, 0, 0x0212, 0x7400 | next, next, next<<8 | next);
#else
    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.º 6
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ipv6_process, ev, data)
{


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

  // Setup the destination address
  uiplib_ipaddrconv(RECEIVER_ADDR, &dest_addr);

  // Add a "neighbor" for our custom route
  // Setup the default broadcast route
  uiplib_ipaddrconv(ADDR_ALL_ROUTERS, &bcast_ipaddr);
  uip_ds6_nbr_add(&bcast_ipaddr, &bcast_lladdr, 0, NBR_REACHABLE);
  uip_ds6_route_add(&dest_addr, 128, &bcast_ipaddr);

  // Setup a udp "connection"
  client_conn = udp_new(&dest_addr, UIP_HTONS(RECEIVER_PORT), NULL);
  if (client_conn == NULL) {
    // Too many udp connections
    // not sure how to exit...stupid contiki
  }
  udp_bind(client_conn, UIP_HTONS(3001));

  etimer_set(&periodic_timer, 10*CLOCK_SECOND);

  while(1) {
    PROCESS_YIELD();

    if (etimer_expired(&periodic_timer)) {
      send_handler(ev, data);
      etimer_restart(&periodic_timer);
    } else if (ev == tcpip_event) {
      recv_handler();
    }
  }

  PROCESS_END();
}
Exemplo n.º 7
0
/*---------------------------------------------------------------------------*/
uip_ds6_route_t *
rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len,
              uip_ipaddr_t *next_hop)
{
  uip_ds6_route_t *rep;

  if((rep = uip_ds6_route_add(prefix, prefix_len, next_hop)) == NULL) {
    PRINTF("RPL: No space for more route entries\n");
    return NULL;
  }

  rep->state.dag = dag;
  rep->state.lifetime = RPL_LIFETIME(dag->instance, dag->instance->default_lifetime);
  rep->state.learned_from = RPL_ROUTE_FROM_INTERNAL;

  PRINTF("RPL: Added a route to ");
  PRINT6ADDR(prefix);
  PRINTF("/%d via ", prefix_len);
  PRINT6ADDR(next_hop);
  PRINTF("\n");

  return rep;
}
Exemplo n.º 8
0
/*---------------------------------------------------------------------------*/
uip_ds6_route_t *
rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len,
              uip_ipaddr_t *next_hop)
{
  uip_ds6_route_t *rep;

  if((rep = uip_ds6_route_add(prefix, prefix_len, next_hop)) == NULL) {
    PRINTF("RPL: No space for more route entries\n");
    return NULL;
  }

  rep->state.dag = dag;
  rep->state.lifetime = RPL_LIFETIME(dag->instance, dag->instance->default_lifetime);
  /* always clear state flags for the no-path received when adding/refreshing */
  RPL_ROUTE_CLEAR_NOPATH_RECEIVED(rep);

  PRINTF("RPL: Added a route to ");
  PRINT6ADDR(prefix);
  PRINTF("/%d via ", prefix_len);
  PRINT6ADDR(next_hop);
  PRINTF("\n");

  return rep;
}
Exemplo n.º 9
0
/* Switch the ports and addresses and set route and neighbor cache.
 * Returns 1 if packet was sent properly, in this case it is the caller
 * that needs to release the net_buf. If 0 is returned, then uIP stack
 * has released the net_buf already because there was an some net related
 * error when sending the buffer.
 */
static inline int udp_prepare_and_send(struct net_context *context,
				       struct net_buf *buf)
{
#ifdef CONFIG_NETWORKING_WITH_IPV6
	uip_ds6_route_t *route_old, *route_new = NULL;
	uip_ds6_nbr_t *nbr;
#endif
	uip_ipaddr_t tmp;
	uint16_t port;
	uint8_t ret;

	if (uip_len(buf) == 0) {
		/* This is expected as uIP will typically set the
		 * packet length to 0 after receiving it. So we need
		 * to fix the length here. The protocol specific
		 * part is added also here.
		 */
		uip_len(buf) = uip_slen(buf) = uip_appdatalen(buf);
		buf->data = buf->buf + UIP_IPUDPH_LEN;
	}

	port = UIP_UDP_BUF(buf)->srcport;
	UIP_UDP_BUF(buf)->srcport = UIP_UDP_BUF(buf)->destport;
	UIP_UDP_BUF(buf)->destport = port;

	uip_ipaddr_copy(&tmp, &UIP_IP_BUF(buf)->srcipaddr);
	uip_ipaddr_copy(&UIP_IP_BUF(buf)->srcipaddr,
			&UIP_IP_BUF(buf)->destipaddr);
	uip_ipaddr_copy(&UIP_IP_BUF(buf)->destipaddr, &tmp);

#ifdef CONFIG_NETWORKING_WITH_IPV6
	/* The peer needs to be in neighbor cache before route can be added.
	 */
	nbr = uip_ds6_nbr_lookup((uip_ipaddr_t *)&UIP_IP_BUF(buf)->destipaddr);
	if (!nbr) {
		const uip_lladdr_t *lladdr = (const uip_lladdr_t *)&buf->src;
		nbr = uip_ds6_nbr_add(
			(uip_ipaddr_t *)&UIP_IP_BUF(buf)->destipaddr,
			lladdr, 0, NBR_REACHABLE);
		if (!nbr) {
			NET_DBG("Cannot add peer ");
			PRINT6ADDR(&UIP_IP_BUF(buf)->destipaddr);
			PRINT(" to neighbor cache\n");
		}
	}

	/* Temporarily add route to peer, delete the route after
	 * sending the packet. Check if there was already a
	 * route and do not remove it if there was existing
	 * route to this peer.
	 */
	route_old = uip_ds6_route_lookup(&UIP_IP_BUF(buf)->destipaddr);
	if (!route_old) {
		route_new = uip_ds6_route_add(&UIP_IP_BUF(buf)->destipaddr,
					      128,
					      &UIP_IP_BUF(buf)->destipaddr);
		if (!route_new) {
			NET_DBG("Cannot add route to peer ");
			PRINT6ADDR(&UIP_IP_BUF(buf)->destipaddr);
			PRINT("\n");
		}
	}
#endif

	ret = simple_udp_sendto_port(buf,
				     net_context_get_udp_connection(context),
				     buf->data, buf->len,
				     &UIP_IP_BUF(buf)->destipaddr,
				     uip_ntohs(UIP_UDP_BUF(buf)->destport));
	if (!ret) {
		NET_DBG("Packet could not be sent properly.\n");
	}

#ifdef CONFIG_NETWORKING_WITH_IPV6
	if (!route_old && route_new) {
		/* This will also remove the neighbor cache entry */
		uip_ds6_route_rm(route_new);
	}
#endif

	return ret;
}
Exemplo n.º 10
0
static void
receiver(struct simple_udp_connection *c,
         const uip_ipaddr_t *sender_addr,
         uint16_t sender_port,
         const uip_ipaddr_t *receiver_addr,
         uint16_t receiver_port,
         const uint8_t *data,
         uint16_t datalen)
{
  int i,num_neigh;
  uint8_t *ptr;
  struct ip_list_struct *s;
  uip_ipaddr_t *addr;
  uip_ds6_addr_t * nh;

  // Check if this is the first time I get a message from this node
  if( !list_exist(sender_addr) ){
     // First message from this neighbour
     s = memb_alloc(&ip_mem);
     uip_ipaddr_copy(&s->ip, sender_addr);
     list_add(ip_list, s);
     printf("Neighbour added \n"); 
  }

  printf("Neighbour information received from ");
  uip_debug_ipaddr_print(sender_addr);
  printf("\n");
 
  num_neigh = datalen/sizeof(uip_ipaddr_t);
  ptr=data;
  printf("2nd hop neighbour list is: \n");
  for(i=0; i < num_neigh; i++){
     ptr += i*sizeof(uip_ipaddr_t);
     addr = ptr;
     uip_debug_ipaddr_print(addr);

     // Add the 2nd neighbors in the routing table

     if(uip_ds6_is_my_addr(addr))
        continue; // Hey this is myself

     if( list_exist(addr) )
	continue; // Hey you're a 1st hop neighbour

     // I can add the entry in the routing table
     uip_ds6_route_add(addr, 128, sender_addr);
     printf("\nAdded route\n");

     // Verify!
     nh = uip_ds6_route_lookup(addr);
     if( nh != NULL ){
        printf("TO=");
        uip_debug_ipaddr_print(addr);
        printf(" NEXTHOP=");
        uip_debug_ipaddr_print(nh); 	
     }
  }
  printf("\n");



}
Exemplo n.º 11
0
/*------Done in a subroutine to keep main routine stack usage small--------*/
void initialize(void)
{
#if WITH_SLIP
  //Slip border router on uart0
  rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
#else
  /* First rs232 port for debugging */
  rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);

  /* Redirect stdout to first port */
  rs232_redirect_stdout(RS232_PORT_0);

  /* Get input from first port */
  rs232_set_input(RS232_PORT_0, serial_line_input_byte);
#endif

  clock_init();

  if(MCUSR & (1<<PORF )) PRINTA("Power-on reset.\n");
  if(MCUSR & (1<<EXTRF)) PRINTA("External reset!\n");
  if(MCUSR & (1<<BORF )) PRINTA("Brownout reset!\n");
  if(MCUSR & (1<<WDRF )) PRINTA("Watchdog reset!\n");
  if(MCUSR & (1<<JTRF )) PRINTA("JTAG reset!\n");

#if ANNOUNCE_BOOT
  PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
#endif

  /* Initialize process subsystem */
  process_init();

  /* etimers must be started before ctimer_init */
  process_start(&etimer_process, NULL);

  /* Initilaize serial line for input */
  serial_line_init();

  /* Initialize board LEDs */
  leds_init();

  /* When used for testing, we should start with them off */
  leds_off(LEDS_GREEN|LEDS_YELLOW);

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

  memcpy(&uip_lladdr.addr, &addr.u8, 8);

// Is this required with IPv6, I wonder?
#if 1
  rf230_set_pan_addr(
    IEEE802154_PANID,
    0,
    (uint8_t *)&addr.u8
  );
  rf230_set_channel(26);

  rimeaddr_set_node_addr(&addr);
#endif

  PRINTF("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
  PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
  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) PRINTA(", check rate %u Hz",tmp);
  }
  PRINTA("\n");
#endif

#if UIP_CONF_ROUTER
//#warning Zigduino has not been tested with UIP_CONF_ROUTER
#if ANNOUNCE_BOOT
  PRINTA("Routing Enabled\n");
#endif
#endif

  /* Sensors process means all processes will get an event posted whenever sensors change.
     Not always desired, so may want to put this on a compile switch. */
  process_start(&sensors_process, NULL);
  SENSORS_ACTIVATE(button_sensor);

  process_start(&tcpip_process, NULL);

  //Give ourselves a prefix
  // init_net();

  /* Add easy addresses for testing */
  uip_ip6addr_t ipaddr;
  uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0, 0, 0, addr.u8[7]);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
#if UIP_CONF_ROUTER
  uip_ds6_prefix_add(&ipaddr,64,0,0,0,0);
#else
  uip_ds6_prefix_add(&ipaddr,64,0);
#endif

  /* Create a route through the border router for site-local addresses, fec0::/64. */
  uip_ds6_route_t *rep;
  uip_ip6addr_t next_hop;
  uip_ip6addr(&ipaddr, 0xfec0, 0, 0, 0, 0, 0, 0, 0);
  uip_ip6addr(&next_hop, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
  if((rep = uip_ds6_route_add(&ipaddr, 64, &next_hop, 0)) == NULL)
  {
    printf("*** Failed to add a route to fec0::/64\n");
  }
 
  printf("Autostart other processes\n");
  /* Autostart other processes */
  autostart_start(autostart_processes);

  /*--------------------------Announce the configuration---------------------*/
#if ANNOUNCE_BOOT

  extern uip_ds6_netif_t uip_ds6_if;

  uint8_t i;
  PRINTA("\nIP addresses [%u max]\n",UIP_DS6_ADDR_NB);
  for (i=0; i<UIP_DS6_ADDR_NB; i++)
  {
    if (uip_ds6_if.addr_list[i].isused)
    {
      uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
      PRINTA("\n");
    }
  }
#endif /* ANNOUNCE_BOOT */
}