Ejemplo n.º 1
0
void
uecmd_net_main()
{
  if (!uip_newdata())
    return;

  char *p = (char *) uip_appdata;
  /* This may be 1-2 chars too big in case there is a \r or \n, but it saves us a counting loop */
  char cmd[uip_datalen() + 1];
  char *dp = cmd;
  /* Copy over into temporary buffer, remove \r \n if present, add \0 */
  while (p < (char *) uip_appdata + uip_datalen())
  {
    if (*p == '\r' || *p == '\n')
      break;
    *dp++ = *p++;
  }
  *dp = 0;

  uip_slen = 0;
  while (uip_slen < UIP_BUFSIZE - UIP_IPUDPH_LEN)
  {
    int16_t len = ecmd_parse_command(cmd, ((char *) uip_appdata) + uip_slen,
                                     (UIP_BUFSIZE - UIP_IPUDPH_LEN) -
                                     uip_slen);
    uint8_t real_len = len;
    if (!is_ECMD_FINAL(len))
    {                           /* what about the errors ? */
      /* convert ECMD_AGAIN back to ECMD_FINAL */
      real_len = (uint8_t) ECMD_AGAIN(len);
    }
    uip_slen += real_len + 1;
    ((char *) uip_appdata)[uip_slen - 1] = '\n';
    if (real_len == len || len == 0)
      break;
  }

  /* Sent data out */

  uip_udp_conn_t echo_conn;
  uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr);
  echo_conn.rport = BUF->srcport;
  echo_conn.lport = HTONS(ECMD_UDP_PORT);

  uip_udp_conn = &echo_conn;
  uip_process(UIP_UDP_SEND_CONN);
  router_output();

  uip_slen = 0;
}
Ejemplo n.º 2
0
static void
output(void)
{
#if FALLBACK_HAS_ETHERNET_HEADERS&&0
  if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
    /* Do not bounce packets back to fallback if the packet was received from it */
    PRINTF("FUT: trapping pingpong");
	return;
  }
  uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr);
#endif
    PRINTF("FUT: %u\n", uip_len);
	wfall_send(0);
}
Ejemplo n.º 3
0
void
udpstella_net_main(void)
{
    if (!uip_newdata ())
	return;

    uip_slen = 0;
    uint16_t len = uip_len;
    uint8_t buffer[uip_len];
    memcpy(buffer, uip_appdata, uip_len);

    struct udpstella_packet* packet = (struct udpstella_packet*)buffer;
    uint8_t* answer = uip_appdata;

    while (len>=sizeof(struct udpstella_packet)) {
	    if (packet->type == STELLA_GETALL) {
		answer[0] = 's';
		answer[1] = 't';
		answer[2] = 'e';
		answer[3] = 'l';
		answer[4] = 'l';
		answer[5] = 'a';
		answer[6] = (uint8_t)STELLA_CHANNELS;
		for (uint8_t c=0;c<STELLA_CHANNELS;++c) {
			answer[7+c] = stella_brightness[c];
		}
		uip_slen += STELLA_CHANNELS+6;
		answer += STELLA_CHANNELS+6;
	    } else {
			stella_setValue(packet->type, packet->channel, packet->value);
	    }
     	packet++;
     	len-=sizeof(struct udpstella_packet);
     }

    if (uip_slen == 0) return;
	/* Sent data out */

	uip_udp_conn_t echo_conn;
	uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr);
	echo_conn.rport = BUF->srcport;
	echo_conn.lport = HTONS(UDP_STELLA_PORT);

	uip_udp_conn = &echo_conn;
	uip_process(UIP_UDP_SEND_CONN);
	router_output();

	uip_slen = 0;

}
Ejemplo n.º 4
0
/*---------------------------------------------------------------------------*/
static void
sendto(const uip_ipaddr_t *dest, const void *buf, int len)
{
  /* XXX: this is a HACK! We're updating the uIP UDP connection
     "unicastconn" so that the destination address is the next-hop,
     and we're patching the "uip_udp_conn" variable so that it points
     the this connection instead. THIS IS NOT A NICE WAY TO DO THIS,
     but it is currently nicer than the alternative (requesting a new
     poll, and remembering the state, etc.). */
  
  uip_ipaddr_copy(&unicastconn->ripaddr, dest);
  uip_udp_conn = unicastconn;
  uip_udp_packet_send(unicastconn, buf, len);
}
Ejemplo n.º 5
0
/*---------------------------------------------------------------------------*/
void
uip_udp_packet_sendto(struct uip_udp_conn *c, const void *data, int len,
		      const uip_ipaddr_t *toaddr, uint16_t toport)
{
  uip_ipaddr_t curaddr;
  uint16_t curport;

  if(toaddr != NULL) {
    /* Save current IP addr/port. */
    uip_ipaddr_copy(&curaddr, &c->ripaddr);
    curport = c->rport;

    /* Load new IP addr/port */
    uip_ipaddr_copy(&c->ripaddr, toaddr);
    c->rport = toport;

    uip_udp_packet_send(c, data, len);

    /* Restore old IP addr/port */
    uip_ipaddr_copy(&c->ripaddr, &curaddr);
    c->rport = curport;
  }
}
Ejemplo n.º 6
0
/*
 * this function process the request which fall into 2 cases: request, and reply
 * an example of receiving request:
  		{
		'status': 'start',		//start/stop
		'update': 1,			//in second
		'addr': 'aaaa::1',
		'port': 20000
		}
 */
char collectd_processing(u8_t* const input, const u16_t input_len, collectd_conf_t *collectd_conf) {
	static jsmn_parser p;
	static jsmntok_t tokens[MAX_TOKEN];
	static char value[TOKEN_LEN];

	//values to save temp from input json (before make sure json msg is valid)
	u8_t commandtype;
	u16_t update;
	u16_t srcport;
	uip_ipaddr_t mnaddr;
	int r;

	input[input_len] = 0;
	PRINTF("%s\n", input);
	jsmn_init(&p);
	r = jsmn_parse(&p, (char*)input, tokens, MAX_TOKEN);
	check(r == JSMN_SUCCESS);

	//get status
	check(js_get(input, tokens, MAX_TOKEN, "status", value, MAX_TOKEN) == JSMN_TOKEN_SUCCESS);
	check( (strcmp(value, "start")==0) || (strcmp(value, "stop")==0) );
	commandtype = (strcmp(value, "start") == 0)? COMMAND_START : COMMAND_STOP;
	//PRINTF("start = %d\n", commandtype);

	check(js_get(input, tokens, MAX_TOKEN, "update", value, MAX_TOKEN) == JSMN_TOKEN_SUCCESS);
	errno = 0;
	update = (u16_t)strtol(value, NULL, 10);		//convert to base 10
	check(!(errno == ERANGE || (errno != 0 && update == 0)));
	//PRINTF("update = %d\n", update);

	check(js_get(input, tokens, MAX_TOKEN, "addr", value, MAX_TOKEN) == JSMN_TOKEN_SUCCESS);
	check(uiplib_ipaddrconv(value, &mnaddr) == 1);
	//PRINT6ADDR(&mnaddr);
	//PRINTF("\n");

	check(js_get(input, tokens, MAX_TOKEN, "port", value, MAX_TOKEN) == JSMN_TOKEN_SUCCESS);
	errno = 0;
	srcport = (u16_t)strtol(value, NULL, 10);		//convert to base 10
	check(!(errno == ERANGE || (errno != 0 && update == 0)));
	//PRINTF("port = %d\n", srcport);

	/*save the request to conf*/
	collectd_conf->send_active = commandtype;
	collectd_conf->update_freq_in_sec = update;
	collectd_conf->mnrport = srcport;
	uip_ipaddr_copy(&collectd_conf->mnaddr, &mnaddr);

	return COLLECTD_ERROR_NO_ERROR;
}
Ejemplo n.º 7
0
FAR struct igmp_group_s *uip_grpalloc(FAR struct uip_driver_s *dev,
                                      FAR const uip_ipaddr_t *addr)
{
  FAR struct igmp_group_s *group;
  uip_lock_t flags;

  nllvdbg("addr: %08x dev: %p\n", *addr, dev);
  if (up_interrupt_context())
    {
#if CONFIG_PREALLOC_IGMPGROUPS > 0
      grplldbg("Use a pre-allocated group entry\n");
      group = uip_grpprealloc();
#else
      grplldbg("Cannot allocate from interrupt handler\n");
      group = NULL;
#endif
    }
  else
    {
      grplldbg("Allocate from the heap\n");
      group = uip_grpheapalloc();
    }
  grplldbg("group: %p\n", group);

  /* Check if we succesfully allocated a group structure */

  if (group)
    {
      /* Initialize the non-zero elements of the group structure */

      uip_ipaddr_copy(group->grpaddr, *addr);
      sem_init(&group->sem, 0, 0);

      /* Initialize the group timer (but don't start it yet) */

      group->wdog = wd_create();
      DEBUGASSERT(group->wdog);

      /* Interrupts must be disabled in order to modify the group list */

      flags = uip_lock();

      /* Add the group structure to the list in the device structure */

      sq_addfirst((FAR sq_entry_t*)group, &dev->grplist);
      uip_unlock(flags);
    }
  return group;
}
Ejemplo n.º 8
0
/*---------------------------------------------------------------------------*/
void
uip_netif_addr_add(uip_ipaddr_t *ipaddr, u8_t length, unsigned long vlifetime, uip_netif_type type) {
  
  /* check prefix has the right length if we are doing autoconf */
  if((type == AUTOCONF) && (length != UIP_DEFAULT_PREFIX_LEN)) {
    UIP_LOG("Error: UNSUPPORTED PREFIX LENGTH");
    return;
  }
  
  /* check if addr does not already exist and find a free entry */
  for(i = 0; i < UIP_CONF_NETIF_MAX_ADDRESSES; ++i) {
    if(uip_netif_physical_if.addresses[i].state == NOT_USED){
      /*
       * Copying address
       * If we are doing autoconf, ipaddr is a prefix, we copy the 128 bits
       * of it, then overwrite the last 64 bits with the interface ID at 
       * next if statement.
       * Otherwise ipaddr is an address, we just copy it
       */
      uip_ipaddr_copy(&uip_netif_physical_if.addresses[i].ipaddr, ipaddr);
      if(type == AUTOCONF) {
        /* construct address from prefix and layer2 id */
        uip_netif_addr_autoconf_set(&uip_netif_physical_if.addresses[i].ipaddr, &uip_lladdr);
      } 
      /* setting state, type */
      uip_netif_physical_if.addresses[i].state = TENTATIVE;
      uip_netif_physical_if.addresses[i].type = type;
      /* setting lifetime timer if lieftime is not infinite */
      if(vlifetime != 0) {
        stimer_set(&(uip_netif_physical_if.addresses[i].vlifetime), vlifetime);
        uip_netif_physical_if.addresses[i].is_infinite = 0;
      } else {
        uip_netif_physical_if.addresses[i].is_infinite = 1;
      }
      PRINTF("Created new address");
      PRINT6ADDR(&uip_netif_physical_if.addresses[i].ipaddr);
      PRINTF("for interface\n");
   
      /* schedule DAD */
      uip_netif_sched_dad(&uip_netif_physical_if.addresses[i]);
      
      return;
    }
  }
 
  /* If we did not find space, log */ 
  UIP_LOG("ADDRESS LIST FULL");
  return;
}
Ejemplo n.º 9
0
/*-------------------------------------------
| Name:uip_sock_init
| Description:
| Parameters:
| Return Type:
| Comments:
| See:
---------------------------------------------*/
int uip_sock_init(void) {
#if defined (USE_UIP)
   int i;
   socketList = (socket_t*)&_socketList;
   socksconn_state_list = (struct socksconn_state*)&_socksconn_state_list;
   uip_init();
   #if UIP_CONF_IPV6
   {
      uip_ip6addr_t ip6addr;
      memcpy(uip_lladdr.addr, "\x00\x0c\x29\x28\x23\x45", 6); // Set in zigbeestack.cpp (UID)    
      uip_ip6addr(&ip6addr, 0xfe80,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0002);
      uip_sethostaddr(&ip6addr);
      uip_ipaddr_copy(&uip_hostaddr, &ip6addr);

      tcpip_init();  // rpl_init() is called inside tcpip_init()
      clock_init();
      uip_ds6_addr_add(&ip6addr, 0, ADDR_MANUAL);
   }
   #endif
   //ethernet
   #if defined(USE_IF_ETHERNET)
      #if !UIP_CONF_IPV6
   uip_arp_init();
   #endif
#endif
 
   for(i=0; i<MAX_SOCKET; i++) {
      #if UIP_CONF_IPV6
      socketList[i].addr_in.sin6_port=0;
      #else
      socketList[i].addr_in.sin_port=0;
      #endif
      socketList[i].socksconn=NULL;
      socketList[i].desc = -1;
   }

   for(i=0; i<UIP_CONNS; i++) {
      socksconn_state_list[i].hsocks=NULL;
      uip_conns[i].appstate.state = &socksconn_state_list[i];
   }
   for(;i<(UIP_CONNS+UIP_UDP_CONNS);i++){
      socksconn_state_list[i].hsocks=NULL;
      uip_udp_conns[i-UIP_CONNS].appstate.state = &socksconn_state_list[i];
   }
#else
   return -1;
#endif
   return 0;
}
Ejemplo n.º 10
0
void handle_pir_frame(uint8_t *frame)
{
	if (frame[1] == REQUEST_MSG)
		{
			if (frame[2] == PIR_REGISTER)
			{
				uip_ipaddr_copy(&register_address, &UIP_IP_BUF->srcipaddr);
				pir_registered = PIR_REGISTERED;
			}
			else
			{
				pir_registered = PIR_N_REGISTERED;
			}
		}
}
Ejemplo n.º 11
0
/*--------------------------------------------------------------------------------------------*/
 void tcpip_handler(struct udp_tx *udp_tx_info){
	 if(uip_newdata()){
		 ((char *)uip_appdata)[uip_datalen()] = 0;
		 		PRINTF("Server received: '%s' from [", (char *)uip_appdata);
		 		PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
		 		PRINTF("]:%u",UIP_HTONS(UIP_UDP_BUF->srcport));
		 		PRINTF("\n");
		 		uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
		 		server_conn->rport=uip_htons(3007);

		 		PRINTF("Responding with message: ");

		 		udp_data_handler(uip_appdata,udp_tx_info);
	 }
 }
Ejemplo n.º 12
0
void
uecmd_net_init()
{
  uip_ipaddr_t ip;
  uip_ipaddr_copy(&ip, all_ones_addr);

  uip_udp_conn_t *uecmd_conn = uip_udp_new(&ip, 0, uecmd_net_main);
  if (!uecmd_conn)
  {
    debug_printf("ecmd: udp failed\n");
    return;
  }

  uip_udp_bind(uecmd_conn, HTONS(ECMD_UDP_PORT));
}
Ejemplo n.º 13
0
/*---------------------------------------------------------------------------*/
uip_ds6_route_t *
uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, uip_ipaddr_t *nexthop,
                  uint8_t metric)
{
  if(uip_ds6_list_loop
     ((uip_ds6_element_t *)uip_ds6_routing_table, UIP_DS6_ROUTE_NB,
      sizeof(uip_ds6_route_t), ipaddr, length,
      (uip_ds6_element_t **)&locroute) == FREESPACE) {
    locroute->isused = 1;
    uip_ipaddr_copy(&(locroute->ipaddr), ipaddr);
    locroute->length = length;
    uip_ipaddr_copy(&(locroute->nexthop), nexthop);
    locroute->metric = metric;

    PRINTF("DS6: adding route: ");
    PRINT6ADDR(ipaddr);
    PRINTF(" via ");
    PRINT6ADDR(nexthop);
    PRINTF("");
    ANNOTATE("#L u 1;blue", nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
  }

  return locroute;
}
Ejemplo n.º 14
0
/** Retrieves the next unleased IP in the IP address pool.
 *
 *  \param[out] NewIPAddress  Location where the generated IP Address should be stored
 */
static void DHCPServerApp_GetUnleasedIP(uip_ipaddr_t* const NewIPAddress)
{
	uip_ipaddr_copy(NewIPAddress, &uip_hostaddr);

	/** Look through the current subnet, skipping the broadcast and zero IP addresses */
	for (uint8_t IP = 1; IP < 254; IP++)
	{
		/* Update new IP address to lease with the current IP address to test */
		NewIPAddress->u8[3] = IP;

		/* If we've found an unleased IP, abort with the updated IP stored for the called */
		if (!(DHCPServerApp_CheckIfIPLeased(NewIPAddress)))
		  return;
	}
}
Ejemplo n.º 15
0
void
zbus_raw_net_main(void) 
{
  if (uip_newdata ())
    {
      /* 600ms timeout */
      uip_udp_conn->appstate.zbus_raw.timeout = 3;

      uip_ipaddr_copy(uip_udp_conn->ripaddr, BUF->srcipaddr);
      uip_udp_conn->rport = BUF->srcport;
      
      zbus_send_data(uip_appdata, uip_len);
      return;
    }

  if (! uip_udp_conn->appstate.zbus_raw.timeout)
    return;

  if (-- uip_udp_conn->appstate.zbus_raw.timeout)
    return;			/* timeout not yet over. */

  uip_ipaddr_copy(uip_udp_conn->ripaddr, all_ones_addr);
  uip_udp_conn->rport = 0;
}
Ejemplo n.º 16
0
/*---------------------------------------------------------------------------*/
uip_ds6_maddr_t *
uip_ds6_maddr_add(uip_ipaddr_t *ipaddr)
{
  if(uip_ds6_list_loop
     ((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
      sizeof(uip_ds6_maddr_t), ipaddr, 128,
      (uip_ds6_element_t **)&locmaddr) == FREESPACE) {
    locmaddr->isused = 1;
    locmaddr->isreported = 0;
    uip_ipaddr_copy(&locmaddr->ipaddr, ipaddr);
    mld_report_now();
    return locmaddr;
  }
  return NULL;
}
Ejemplo n.º 17
0
/*---------------------------------------------------------------------------*/
int
udp_socket_connect(struct udp_socket *c,
                   uip_ipaddr_t *remote_addr,
                   uint16_t remote_port)
{
  if(c == NULL || c->udp_conn == NULL) {
    return -1;
  }

  if(remote_addr != NULL) {
    uip_ipaddr_copy(&c->udp_conn->ripaddr, remote_addr);
  }
  c->udp_conn->rport = UIP_HTONS(remote_port);
  return 1;
}
Ejemplo n.º 18
0
static void
artnet_send(const uip_ipaddr_t *dest, uint16_t len)
{
  uip_udp_conn_t artnet_conn;
  uip_ipaddr_copy(&(artnet_conn.ripaddr), dest);
  artnet_conn.rport = HTONS(artnet_port);
  artnet_conn.lport = HTONS(artnet_port);
  uip_udp_conn = &artnet_conn;

  uip_slen = len;
  uip_process(UIP_UDP_SEND_CONN);
  router_output();

  uip_slen = 0;
}
Ejemplo n.º 19
0
/*---------------------------------------------------------------------------*/
static void
handle_incoming_reg(const uip_ipaddr_t *owner, servreg_hack_id_t id, uint8_t seqno)
{
  servreg_hack_item_t *t;
  struct servreg_hack_registration *r;

  /* Walk through list, see if we already have a service ID
     registered. If so, we do different things depending on the seqno
     of the update: if the seqno is older than what we have, we
     discard the incoming registration. If the seqno is newer than
     what we have, we reset the lifetime timer of the current
     registration.

     If we did not have the service registered already, we allocate a
     new registration and put it on our list. If we cannot allocate a
     service registration, we discard the incoming registration (for
     now - we might later choose to discard the oldest registration
     that we have). */

  for(t = servreg_hack_list_head();
      t != NULL;
      t = list_item_next(t)) {
    if(servreg_hack_item_id(t) == id) {
      r = t;
      if(SEQNO_LT(r->seqno, seqno)) {
        r->seqno = seqno;
        timer_set(&r->timer, LIFETIME);

        /* Put item first on list, so that subsequent lookups will
           find this one. */
        list_remove(others_services, r);
        list_push(others_services, r);
      }
      return;
    }
  }

  r = memb_alloc(&registrations);
  if(r == NULL) {
    printf("servreg_hack_register: error, could not allocate memory, should reclaim another registration but this has not been implemented yet.\n");
    return;
  }
  r->id = id;
  r->seqno = 1;
  uip_ipaddr_copy(&r->addr, owner);
  timer_set(&r->timer, LIFETIME);
  list_add(others_services, r);
}
Ejemplo n.º 20
0
/* Sends a ping packet out the radio */
static void
raven_ping6(void)
{
    /* ping the router */
    // Setup destination address.
    struct uip_nd6_defrouter *defrouter;
    uint8_t i,tmp;

    defrouter = uip_nd6_choose_defrouter();
    /* Get address from defrouter struct */
    memcpy(addr, defrouter->nb->ipaddr.u8, 16);
    /* Swap the bytes in the address array */
    for (i=0;i<8;i++)
    {
        tmp = addr[i] & 0xff;
        addr[i] >>= 8;
        addr[i] |= tmp << 8;
    }
    uip_ip6addr(&dest_addr, addr[0], addr[1],addr[2],
                addr[3],addr[4],addr[5],addr[6],addr[7]);
  
    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, &dest_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);
    /* put one byte of data */
    memset((void *)UIP_ICMP_BUF + UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN,
           count, PING6_DATALEN);
     
    
    uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN + PING6_DATALEN;
    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();
}
Ejemplo n.º 21
0
/*---------------------------------------------------------------------------*/
void
rpl_purge_routes(void)
{
  uip_ds6_route_t *r;
  uip_ipaddr_t prefix;
  rpl_dag_t *dag;

  /* First pass, decrement lifetime */
  r = uip_ds6_route_head();

  while(r != NULL) {
    if(r->state.lifetime >= 1) {
      /*
       * If a route is at lifetime == 1, set it to 0, scheduling it for
       * immediate removal below. This achieves the same as the original code,
       * which would delete lifetime <= 1
       */
      r->state.lifetime--;
    }
    r = uip_ds6_route_next(r);
  }

  /* Second pass, remove dead routes */
  r = uip_ds6_route_head();

  while(r != NULL) {
    if(r->state.lifetime < 1) {
      /* Routes with lifetime == 1 have only just been decremented from 2 to 1,
       * thus we want to keep them. Hence < and not <= */
      uip_ipaddr_copy(&prefix, &r->ipaddr);
      uip_ds6_route_rm(r);
      r = uip_ds6_route_head();
      printf("No more routes to ");
      PRINT6ADDR(&prefix);
      dag = default_instance->current_dag;
      /* Propagate this information with a No-Path DAO to preferred parent if we are not a RPL Root */
      if(dag->rank != ROOT_RANK(default_instance)) {
        PRINTF(" -> generate No-Path DAO\n");
        dao_output_target(dag->preferred_parent, &prefix, RPL_ZERO_LIFETIME);
        /* Don't schedule more than 1 No-Path DAO, let next iteration handle that */
        return;
      }
      PRINTF("\n");
    } else {
      r = uip_ds6_route_next(r);
    }
  }
}
Ejemplo n.º 22
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_irc_process, ev, data)
{
  char *next;
  struct shell_input *input;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&irc_command,
		     "irc <server> <nick>: server as address", "");
    PROCESS_EXIT();
  }
  *next = 0;
  ++next;
  strncpy(server, data, sizeof(server));
  strncpy(nick, next, sizeof(nick));
  
  running = 1;

  uiplib_ipaddrconv(server, (u8_t *)&serveraddr);
  ircc_connect(&s, server, &serveraddr, nick);
  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 > 0) {
	parse_line(input->data1);
      }
    } else if(ev == tcpip_event) {
      ircc_appcall(data);
#if 0            
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	ircc_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&irc_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Ejemplo n.º 23
0
void
uaodv_bad_dest(uip_ipaddr_t *dest)
{
  struct uaodv_rt_entry *rt = uaodv_rt_lookup_any(dest);

  if(rt == NULL)
    bad_seqno = 0;		/* Or flag this in RERR? */
  else {
    rt->is_bad = 1;
    bad_seqno = uip_htonl(rt->hseqno);
  }

  uip_ipaddr_copy(&bad_dest, dest);
  command = COMMAND_SEND_RERR;
  process_post(&uaodv_process, PROCESS_EVENT_MSG, NULL);
}
Ejemplo n.º 24
0
/*---------------------------------------------------------------------------*/
uip_ds6_maddr_t *
uip_ds6_maddr_add(const uip_ipaddr_t *ipaddr)
{
  if(uip_ds6_list_loop
     ((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
      sizeof(uip_ds6_maddr_t), (void*)ipaddr, 128,
      (uip_ds6_element_t **)&locmaddr) == FREESPACE) {
    locmaddr->isused = 1;
    uip_ipaddr_copy(&locmaddr->ipaddr, ipaddr);
    PRINTF("Adding maddr ");
    PRINT6ADDR(&locmaddr->ipaddr);
    PRINTF("\n");
    return locmaddr;
  }
  return NULL;
}
Ejemplo n.º 25
0
/*---------------------------------------------------------------------------*/
uip_ds6_maddr_t *
uip_ds6_maddr_add(uip_ipaddr_t *ipaddr)
{
  if(uip_ds6_list_loop
     ((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
      sizeof(uip_ds6_maddr_t), ipaddr, 128,
      (uip_ds6_element_t **)&locmaddr) == FREESPACE) {
    locmaddr->isused = 1;
    uip_ipaddr_copy(&locmaddr->ipaddr, ipaddr);
#if UIP_CONF_MLD
    uip_icmp6_mldv1_schedule_report(locmaddr);
#endif
    return locmaddr;
  }
  return NULL;
}
Ejemplo n.º 26
0
void 
_udp_states_init(void) {
    debug_printf("UDP_STATES registert states (befor init) %x\n", udp_states_n_registert_states);
    udp_states_n_registert_states=0; //no states are registert
    debug_printf("UDP_STATES registert states (after init) %x\n", udp_states_n_registert_states);
    udp_states_n_registert_callbacks=0; //no callbacks registert
    uip_ipaddr_t io;
    uip_ipaddr_copy (&ip, all_ones_addr);

    uip_udp_conn_t *udp_states_connection = uip_udp_new (&ip, 0, _udp_states_process); //register the protocol

    if (!udp_states_connection)
        return;

    uip_udp_bind (udp_states_connection, HTONS (UDP_STATES_PORT)); //bind the protocol to the Port
}
Ejemplo n.º 27
0
/**
 * uIP doesn't provide a mechanism to create a raw-IP packet so
 * we trigger the sending of ECHO_REQUEST by sending ourself an
 * ECHO_REPLY message with all-zeroes destination IP address.
 *
 * A global completion variable is used to notify the reception 
 * of the actual ECHO_REPLY
 */
int vmm_netstack_send_icmp_echo(u8 *ripaddr, u16 size, u16 seqno, 
			      struct vmm_icmp_echo_reply *reply)
{
	struct vmm_mbuf *mbuf;
	struct uip_icmp_echo_request *echo_req;
	u16 all_zeroes_addr[] = {0, 0}; 
	u8 *tmp;
	u64 timeout = (u64)20000000000;
	u16 ethsize;

	/* Create a mbuf */
	MGETHDR(mbuf, 0, 0);
	ethsize = UIP_ICMP_LLH_LEN + UIP_ICMP_ECHO_DLEN;
	MEXTMALLOC(mbuf, ethsize, 0);
	mbuf->m_len = mbuf->m_pktlen = ethsize;
	/* Skip the src & dst mac addresses as they will be filled by 
	 * uip_netport_loopback_send */
	tmp = mtod(mbuf, u8 *) + 12;
	/* IPv4 ethertype */
	*tmp++ = 0x08;
	*tmp++ = 0x00;
	/* Fillup the echo_request structure embedded in ICMP payload */
	echo_req = (struct uip_icmp_echo_request *)(tmp + UIP_ICMP_IPH_LEN);
	uip_ipaddr_copy(echo_req->ripaddr, ripaddr);
	echo_req->len = size;
	echo_req->seqno = seqno;
	/* Fillup the IP header */
	uip_create_ip_pkt(tmp, all_zeroes_addr, (ethsize - UIP_LLH_LEN));
	/* Fillup the ICMP header at last as the icmpchksum is calculated 
	 * over entire icmp message */
	uip_create_icmp_pkt(tmp, ICMP_ECHO_REPLY, 
			    (ethsize - UIP_LLH_LEN - UIP_IPH_LEN), 0);

	/* Update pointer to store uip_ping_reply */
	uip_ping_reply = reply;

	/* Send the mbuf to self to trigger ICMP_ECHO */
	uip_netport_loopback_send(mbuf);
	/* Wait for the reply until timeout */
	vmm_completion_wait_timeout(&uip_ping_done, &timeout);
	/* The callback has copied the reply data before completing, so we
	 * can safely set the pointer as NULL to prevent unwanted callbacks */
	uip_ping_reply = NULL;
	if(timeout == (u64)0) 
		return VMM_EFAIL;
	return VMM_OK;
}
Ejemplo n.º 28
0
/*---------------------------------------------------------------------------*/
uip_ds6_defrt_t *
uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
{
  uip_ds6_defrt_t *d;

#if DEBUG != DEBUG_NONE
  assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */

  PRINTF("uip_ds6_defrt_add\n");
  d = uip_ds6_defrt_lookup(ipaddr);
  if(d == NULL) {
    d = memb_alloc(&defaultroutermemb);
    if(d == NULL) {
      PRINTF("uip_ds6_defrt_add: could not add default route to ");
      PRINT6ADDR(ipaddr);
      PRINTF(", out of memory\n");
      return NULL;
    } else {
      PRINTF("uip_ds6_defrt_add: adding default route to ");
      PRINT6ADDR(ipaddr);
      PRINTF("\n");
    }

    list_push(defaultrouterlist, d);
  }

  uip_ipaddr_copy(&d->ipaddr, ipaddr);
  if(interval != 0) {
    stimer_set(&d->lifetime, interval);
    d->isinfinite = 0;
  } else {
    d->isinfinite = 1;
  }

  ANNOTATE("#L %u 1\n", ipaddr->u8[sizeof(uip_ipaddr_t) - 1]);

#if UIP_DS6_NOTIFICATIONS
  call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_ADD, ipaddr, ipaddr);
#endif

#if DEBUG != DEBUG_NONE
  assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */

  return d;
}
Ejemplo n.º 29
0
void uecmd_net_main() {
	if (!uip_newdata ())
		return;

	char *p = (char *)uip_appdata;

	/* Add \0 to the data and remove \n from the data */
	do {
		if (*p == '\r' || *p == '\n') {
			break;
		}
	} while ( ++p <= ((char *)uip_appdata + uip_datalen()));

	/* Parse the Data */
	*p = 0;
	char cmd[p - (char *)uip_appdata];

	strncpy(cmd, uip_appdata, p - (char *)uip_appdata + 1);

	uip_slen = 0;
	while (uip_slen < UIP_BUFSIZE - UIP_IPUDPH_LEN) {
		int16_t len = ecmd_parse_command(cmd, ((char *)uip_appdata) + uip_slen,
						 (UIP_BUFSIZE - UIP_IPUDPH_LEN) - uip_slen);
		uint8_t real_len = len;
		if (!is_ECMD_FINAL(len)) { /* what about the errors ? */
			/* convert ECMD_AGAIN back to ECMD_FINAL */
			real_len = (uint8_t) ECMD_AGAIN(len);
		}
		uip_slen += real_len + 1;
		((char *)uip_appdata)[uip_slen - 1] = '\n';
		if (real_len == len || len == 0)
			break;
	}

	/* Sent data out */

	uip_udp_conn_t echo_conn;
	uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr);
	echo_conn.rport = BUF->srcport;
	echo_conn.lport = HTONS(ECMD_UDP_PORT);

	uip_udp_conn = &echo_conn;
	uip_process(UIP_UDP_SEND_CONN);
	router_output();

	uip_slen = 0;
}
Ejemplo n.º 30
0
int
send_to_peer(struct dtls_context_t *ctx, 
	     session_t *session, uint8 *data, size_t len) {

  struct uip_udp_conn *conn = (struct uip_udp_conn *)dtls_get_app_data(ctx);

  uip_ipaddr_copy(&conn->ripaddr, &session->addr);
  conn->rport = session->port;

  uip_udp_packet_send(conn, data, len);

  /* Restore server connection to allow data from any node */
  memset(&conn->ripaddr, 0, sizeof(conn->ripaddr));
  memset(&conn->rport, 0, sizeof(conn->rport));

  return len;
}