예제 #1
0
static void select_attacker(uint8_t *appdata)
{

	//printf("Selecting attacker\n");
	int num,i,j,k; uip_ipaddr_t tempadd,temp2;
	MAPPER_GET_PACKETDATA(num,appdata);
	uint8_t a; unsigned char buf[5],buf2[5], *buf_p;

	for(i=0;i<num;i++)
	{
		
		MAPPER_GET_PACKETDATA(a,appdata);	
		//printf("nbr of %u chk for %u\n",UIP_IP_BUF->srcipaddr.u8[15],a);

		uip_ipaddr_copy(&temp2, &UIP_IP_BUF->srcipaddr);
		if(a!=1)
		if(UIP_IP_BUF->srcipaddr.u8[15]!=myip.u8[15])
		if(a!=myip.u8[15])
		if(!is_nbr(a))
		{	
  			
			k=3;j=9;
			buf_p=buf2;
			MAPPER_ADD_PACKETDATA(buf_p,j);
			MAPPER_ADD_PACKETDATA(buf_p,k);			
			//uip_ip6addr(&server_ipaddr, 0xfe80, 0, 0, 0,0x0212, 0x7401, 1, 0x0101);
			tempadd.u16[0]=0xaaaa; tempadd.u16[1]=0;tempadd.u16[2]=0; tempadd.u16[3]=0;
			tempadd.u16[4]=0x1202; tempadd.u8[10]=0x74;tempadd.u8[11]=a;tempadd.u8[12]=0;tempadd.u8[13]=a;tempadd.u8[14]=a;
			tempadd.u8[15]=a;
			uip_udp_packet_sendto(client_conn, buf2, sizeof(buf2), &tempadd, UIP_HTONS(10000+(int)tempadd.u8[15]));
			uip_create_unspecified(&client_conn->ripaddr);	
			printf("attacker 3 is %u\n",tempadd.u8[15]);

			
 			k=2;buf_p=buf;
			MAPPER_ADD_PACKETDATA(buf_p,j);
			MAPPER_ADD_PACKETDATA(buf_p,k);						
			//temp2.u16[0]=0xaaaa;                
			uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &temp2, UIP_HTONS(10000+(int)temp2.u8[15]));
			uip_create_unspecified(&client_conn->ripaddr);	
			printf("attacker 2 is %u\n",temp2.u8[15]);

			
			attacker_set=1;
			attacker=1;		
			attack_flag=1;
			dis_output(NULL);
			setreg(17,0);
		}
	}
		
}
예제 #2
0
/*---------------------------------------------------------------------------*/
static void
tcpip_handler(void)
{
  memset(buf, 0, MAX_PAYLOAD_LEN);

  if(uip_newdata()) {
    len = uip_datalen();
    memcpy(buf, uip_appdata, len);
    PRINTF("%u bytes from [", len);
    PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
    PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport));
    len = read_sensor(buf);
    if( len ) {
      server_conn->rport = UIP_UDP_BUF->srcport;
      uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
      uip_udp_packet_send(server_conn, buf, len);
      PRINTF("Sent %u bytes\n", len);
    }

    /* Restore server connection to allow data from any node */
    uip_create_unspecified(&server_conn->ripaddr);
    server_conn->rport = 0;
  }
  return;
}
예제 #3
0
/*---------------------------------------------------------------------------*/
static void
tcpip_handler(void)
{
  char *appdata;

  char buf[10];

  if(uip_newdata()) {
    packets++;
    rssi_packets++;
    rssi_rec += packetbuf_attr(PACKETBUF_ATTR_RSSI) - 45;
    appdata = (char *)uip_appdata;
    appdata[uip_datalen()] = 0;
    PRINTF("DATA recv '%s' from ", appdata);
    PRINTF("%d",
           UIP_IP_BUF->srcipaddr.u8[sizeof(UIP_IP_BUF->srcipaddr.u8) - 1]);
    PRINTF("\n");
    if(rssi_packets == 3) {
    	/*PRINTF("packets_received = %d\n", packets);*/
      sprintf(buf, "%d %u", rssi_rec / rssi_packets, packets);
      /*PRINTF("RSSI: %d, %d\n",rssi/rssi_packets, packets);*/
      uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
      uip_udp_packet_send(server_conn, buf, strlen(buf));
      uip_create_unspecified(&server_conn->ripaddr);
      rssi_packets = 0;
      rssi_rec = 0;
    }
  }
}
예제 #4
0
/*---------------------------------------------------------------------------*/
static void
tcpip_handler(void)
{
  memset(buf, 0, MAX_PAYLOAD_LEN);
  if(uip_newdata()) {
    leds_on(LEDS_RED);
    len = uip_datalen();
    memcpy(buf, uip_appdata, len);
    PRINTF("%u bytes from [", len);
    PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
    PRINTF("]:%u", UIP_HTONS(UIP_UDP_BUF->srcport));
    PRINTF(" V=%u", *buf);
    PRINTF(" I=%u", *(buf + 1));
    PRINTF(" T=%u", *(buf + 2));
    PRINTF(" Val=%u\n", *(uint16_t *)(buf + 3));
#if SERVER_REPLY
    uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
    server_conn->rport = UIP_UDP_BUF->srcport;

    uip_udp_packet_send(server_conn, buf, len);
    /* Restore server connection to allow data from any node */
    uip_create_unspecified(&server_conn->ripaddr);
    server_conn->rport = 0;
#endif
  }
  leds_off(LEDS_RED);
  PRINTF("sent\n");
  return;
}
예제 #5
0
/*---------------------------------------------------------------------------*/
void
http_socket_init(struct http_socket *s)
{
  init();
  uip_create_unspecified(&s->proxy_addr);
  s->proxy_port = 0;
}
예제 #6
0
파일: rime-udp.c 프로젝트: kincki/contiki
PROCESS_THREAD(rime_udp_process, ev, data)
{
  static uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();

  broadcast_conn = udp_broadcast_new(HTONS(RIME_UDP_PORT), NULL);
  if(broadcast_conn == NULL) {
    PRINTF("rime-udp: Failed to allocate a broadcast connection!\n");
  }

  uip_create_unspecified(&ipaddr);
  unicast_conn = udp_new(&ipaddr, HTONS(RIME_UDP_PORT), NULL);
  if(unicast_conn == NULL) {
    PRINTF("rime-udp: Failed to allocate a unicast connection!\n");
  }

  udp_bind(unicast_conn, HTONS(RIME_UDP_PORT));

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    if(uip_newdata()) {
      packetbuf_clear();
      memmove(packetbuf_hdrptr(), uip_appdata, uip_datalen());
      PRINTF("rime-udp: received %d bytes\n", uip_datalen());
      receiver_callback(&rime_udp_driver);
    }
  }

  PROCESS_END();
}
예제 #7
0
/*---------------------------------------------------------------------------*/
static void
trickle_tx(void *ptr, uint8_t suppress)
{
  /* *ptr is a pointer to the trickle_timer that triggered this callback. In
   * his example we know that ptr points to tt. However, we pretend that we did
   * not know (which would be the case if we e.g. had multiple trickle timers)
   * and cast it to a local struct trickle_timer* */
  struct trickle_timer *loc_tt = (struct trickle_timer *)ptr;

  if(suppress == TRICKLE_TIMER_TX_SUPPRESS) {
    return;
  }

  leds_on(LEDS_RED);

  PRINTF("At %lu (I=%lu, c=%u): ",
         (unsigned long)clock_time(), (unsigned long)loc_tt->i_cur,
         loc_tt->c);
  PRINTF("Trickle TX token 0x%02x\n", token);

  /* Instead of changing ->ripaddr around by ourselves, we could have used
   * uip_udp_packet_sendto which would have done it for us. However it puts an
   * extra ~20 bytes on stack and the cc2x3x micros hate it, so we stick with
   * send() */

  /* Destination IP: link-local all-nodes multicast */
  uip_ipaddr_copy(&trickle_conn->ripaddr, &ipaddr);
  uip_udp_packet_send(trickle_conn, &token, sizeof(token));

  /* Restore to 'accept incoming from any IP' */
  uip_create_unspecified(&trickle_conn->ripaddr);

  leds_off(LEDS_RED);
}
예제 #8
0
static void help(uint8_t *appdata)
{
	unsigned char buf[5], *buf_p;int i=3;//victim code
	uint8_t dest;	
	buf_p=buf;

	uip_ds6_nbr_t *nbr=NULL;
    	uip_ipaddr_t tempadd;

	MAPPER_ADD_PACKETDATA(buf_p,i);
	MAPPER_GET_PACKETDATA(dest,appdata);

	memcpy(buf_p, appdata, 1);
    for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) { 
	if(dest==nbr->ipaddr.u8[15])
	{       
		uip_ipaddr_copy(&tempadd, &nbr->ipaddr);
		uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &tempadd, UIP_HTONS(10000+(int)tempadd.u8[15]));
		uip_create_unspecified(&client_conn->ripaddr);
		printf("In hepl: sent to %u\n",tempadd.u8[15]);	
		return;
	}
	}
	printf("In help: neighbor not found\n");
} 
예제 #9
0
static void forward_packet(uint8_t *appdata)
{
    uint8_t nodeid;
    int code=2;
    uint8_t temp_id=0;
    printf("Forwarding by broadcast\n");	
	//appdata = (uint8_t *) uip_appdata;
	//MAPPER_GET_PACKETDATA(code,appdata);
	MAPPER_GET_PACKETDATA(nodeid,appdata);	
        MAPPER_GET_PACKETDATA(temp_id,appdata);
	printf("In broad cast recv Code %d osndr %u myid %u \n", code, nodeid, myip.u8[15]);

	printf("Data size %d \n",uip_datalen());
	unsigned char buf[uip_datalen()], *buf_p; 
	buf_p=buf;  
	MAPPER_ADD_PACKETDATA(buf_p,code); //1 
	MAPPER_ADD_PACKETDATA(buf_p,nodeid);//1		original sender			
	MAPPER_ADD_PACKETDATA(buf_p,myip.u8[15]);//1    intermediate sender
	//MAPPER_ADD_PACKETDATA(buf_p,appdata);
	memcpy(buf_p, appdata, uip_datalen() - 3);

	//uip_create_unspecified(&udp_bconn->ripaddr);
	//uip_create_unspecified(&client_conn->ripaddr);      			
	uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &server_ipaddr, UIP_HTONS(2345));
	uip_create_unspecified(&client_conn->ripaddr);    
	printf("Broadcasted Data unicasted buf size %d \n", sizeof(buf));

    //printf("received a broadcast of %d bytes: %s\n", uip_datalen(),uip_appdata);
}
예제 #10
0
static int snd_nbr_info(void)
{
	int num = uip_ds6_nbr_num();
	if(num==1)
	{	printf("Only one neighbor so returning \n");
		return 0;	
	}
        unsigned char buf4[num +10], *buf_p; 
	buf_p=buf4; int i=8;
	uip_ipaddr_t tempadd;

    	uip_ds6_nbr_t *nbr=NULL;
	MAPPER_ADD_PACKETDATA(buf_p,i);
	MAPPER_ADD_PACKETDATA(buf_p,num);

    for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) {
        
        MAPPER_ADD_PACKETDATA(buf_p,nbr->ipaddr.u8[15]);
       	
	}
	uip_ipaddr_copy(&tempadd, &UIP_IP_BUF->srcipaddr);
        //tempadd.u16[0]=0xaaaa;                
	uip_udp_packet_sendto(client_conn, buf4, sizeof(buf4), &tempadd, UIP_HTONS(10000+(int)tempadd.u8[15]));
	uip_create_unspecified(&client_conn->ripaddr);
	printf("nbr info sent to %u\n",tempadd.u8[15]);
	return 1;
}
예제 #11
0
static void
send_unicast(uip_ipaddr_t *dest, char *buf, int size)
{
    uip_ipaddr_copy(&client_conn->ripaddr, dest);
    uip_udp_packet_send(client_conn, buf, size);
    uip_create_unspecified(&client_conn->ripaddr);
}
예제 #12
0
/*---------------------------------------------------------------------------*/
void
uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
{
  uint8_t best = 0;             /* number of bit in common with best match */
  uint8_t n = 0;
  uip_ds6_addr_t *matchaddr = NULL;

  if(!uip_is_addr_link_local(dst) &&
		  (!uip_is_addr_mcast(dst) || uip_is_addr_routable_mcast(dst))) {
    /* find longest match */
    for(locaddr = uip_ds6_if.addr_list;
        locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
      /* Only preferred global (not link-local) addresses */
      if(locaddr->isused && locaddr->state == ADDR_PREFERRED &&
         !uip_is_addr_link_local(&locaddr->ipaddr)) {
        n = get_match_length(dst, &locaddr->ipaddr);
        if(n >= best) {
          best = n;
          matchaddr = locaddr;
        }
      }
    }
  } else {
    matchaddr = uip_ds6_get_link_local(ADDR_PREFERRED);
  }

  /* use the :: (unspecified address) as source if no match found */
  if(matchaddr == NULL) {
    uip_create_unspecified(src);
  } else {
    uip_ipaddr_copy(src, &matchaddr->ipaddr);
  }
}
예제 #13
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);
  }

  if(ipaddr == NULL) {
    /* A special case: if uip_ds6_defrt_add() is called with a NULL
       route, this is an indication that we want to force packets to
       go out to the fallback interface. If so, we add an unspecified
       route to the list of default routes. uip_ds6_defrt_choose()
       will trap this and ensure that packets go to the fallback
       interface. */
    uip_create_unspecified(&d->ipaddr);
    ipaddr = &d->ipaddr;
  } else {
    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;
}
예제 #14
0
static void
send_broadcast(unsigned char *buf, int size)
{
    printf("In send broadcast: \n");
    uip_create_linklocal_allnodes_mcast(&udp_bconn->ripaddr);
    uip_udp_packet_send(udp_bconn, buf, size);
    uip_create_unspecified(&udp_bconn->ripaddr);
}
예제 #15
0
/*----------------------------------------------------------------------------*/
static void _demo_udp_sendMsg(uint64_t seqID)
{
	char 		pc_buf[MAX_S_PAYLOAD_LEN];
	sprintf(pc_buf, "%d | OK", seqID);
	LOG_INFO("Respond with message: %s\n\r",pc_buf);
	uip_ipaddr_copy(&pst_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
	uip_udp_packet_send(pst_conn, pc_buf, strlen(pc_buf));
	uip_create_unspecified(&pst_conn->ripaddr);
} /* _demo_udp_sendMsg */
예제 #16
0
/*------------------------------------------------------------------*/
void
uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt)
{
  uip_ext_len = 0;
  UIP_IP_BUF->vtc = 0x60;
  UIP_IP_BUF->tcflow = 0;
  UIP_IP_BUF->flow = 0;
  UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
  UIP_IP_BUF->ttl = UIP_ND6_HOP_LIMIT;

  if(dest == NULL) {
    uip_create_solicited_node(tgt, &UIP_IP_BUF->destipaddr);
  } else {
    uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, dest);
  }
  UIP_ICMP_BUF->type = ICMP6_NS;
  UIP_ICMP_BUF->icode = 0;
  UIP_ND6_NS_BUF->reserved = 0;
  uip_ipaddr_copy((uip_ipaddr_t *) &UIP_ND6_NS_BUF->tgtipaddr, tgt);
  UIP_IP_BUF->len[0] = 0;       /* length will not be more than 255 */
  /*
   * check if we add a SLLAO option: for DAD, MUST NOT, for NUD, MAY
   * (here yes), for Address resolution , MUST 
   */
  if(!(uip_ds6_is_my_addr(tgt))) {
    if(src != NULL) {
      uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, src);
    } else {
      uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
    }
    UIP_IP_BUF->len[1] =
      UIP_ICMPH_LEN + UIP_ND6_NS_LEN + UIP_ND6_OPT_LLAO_LEN;

    create_llao(&uip_buf[uip_l2_l3_icmp_hdr_len + UIP_ND6_NS_LEN],
		UIP_ND6_OPT_SLLAO);

    uip_len =
      UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ND6_NS_LEN + UIP_ND6_OPT_LLAO_LEN;
  } else {
    uip_create_unspecified(&UIP_IP_BUF->srcipaddr);
    UIP_IP_BUF->len[1] = UIP_ICMPH_LEN + UIP_ND6_NS_LEN;
    uip_len = UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ND6_NS_LEN;
  }

  UIP_ICMP_BUF->icmpchksum = 0;
  UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();

  UIP_STAT(++uip_stat.nd6.sent);
  PRINTF("Sending NS to");
  PRINT6ADDR(&UIP_IP_BUF->destipaddr);
  PRINTF("from");
  PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
  PRINTF("with target address");
  PRINT6ADDR(tgt);
  PRINTF("\n");
  return;
}
예제 #17
0
/*---------------------------------------------------------------------------*/
static void
timeout_handler(void)
{
  cur_time++;
  buf[0] = 'P';
  uip_create_linklocal_allnodes_mcast(&conn->ripaddr);
  conn->rport = UIP_HTONS(3000);
  uip_udp_packet_send(conn, buf, 1);
  uip_create_unspecified(&conn->ripaddr);
  conn->rport = 0;
}
예제 #18
0
static int native_config_network_route_handler(config_level_t level, void* user, const char* section, const char* name,
    const char* value) {
  static uip_ipaddr_t ipaddr;
  static uint8_t length = 0;
  static uip_ipaddr_t next_hop;

  if(level != CONFIG_LEVEL_NETWORK) {
    return 1;
  }

  if(!name) {
    if(!uip_is_addr_unspecified(&ipaddr) && length > 0 && !uip_is_addr_unspecified(&next_hop)) {
      uip_ds6_route_add_static(&ipaddr, length, &next_hop);
    } else {
      LOG6LBR_ERROR("Missing parameters for route creation\n");
      return 0;
    }
    //Reset parameters
    uip_create_unspecified(&ipaddr);
    uip_create_unspecified(&next_hop);
    length = 0;
    return 1;
  }

  if(strcmp(name, "dest") == 0) {
    if(uiplib_ipaddrconv(value, &ipaddr) == 0) {
      LOG6LBR_ERROR("Invalid ip address : %s\n", value);
      return 0;
    }
    length = 128;
  } else if (strcmp(name, "via") == 0) {
    if(uiplib_ipaddrconv(value, &next_hop) == 0) {
      LOG6LBR_ERROR("Invalid ip address : %s\n", value);
      return 0;
    }
  } else {
    LOG6LBR_ERROR("Invalid parameter : %s\n", name);
    return 0;
  }
  return 1;
}
예제 #19
0
/*---------------------------------------------------------------------------*/
static void
tcpip_handler(void)
{
  char *appdata;

  if(uip_newdata()) {
    appdata = (char *)uip_appdata;
    appdata[uip_datalen()] = 0;
    PRINTF("DATA recv '%s' from ", appdata);
    PRINTF("%d", UIP_IP_BUF->srcipaddr.u8[15]);
    PRINTF("\n");
#if SERVER_REPLY
    uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
    uip_udp_packet_send(server_conn, "Reply", sizeof("Reply"));
    uip_create_unspecified(&server_conn->ripaddr);
#endif
  }
}
예제 #20
0
void attack_init(void)
{
	if(num_nbrs<=1)
	{printf("Insufficient neighbors can't create attack \n"); return;
	}	
        unsigned char buf4[4], *buf_p;
	buf_p=buf4; int i=7;	//nbr info code
	uip_ds6_nbr_t *nbr=NULL;
    	uip_ipaddr_t tempadd;
	MAPPER_ADD_PACKETDATA(buf_p,i);
    for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) {        
	uip_ipaddr_copy(&tempadd, &nbr->ipaddr);
        //tempadd.u16[0]=0xaaaa;                
	uip_udp_packet_sendto(client_conn, buf4, sizeof(buf4), &tempadd, UIP_HTONS(10000+(int)tempadd.u8[15]));
	uip_create_unspecified(&client_conn->ripaddr);
	printf("nbr req sent to %u\n",tempadd.u8[15]);
    }
}
예제 #21
0
파일: disco.c 프로젝트: 1uk3/contiki
/*---------------------------------------------------------------------------*/
static void
timer_handler(void *p)
{
  uint8_t *s = p;
  uint8_t wip;

  PRINTF("Disco: @ %lu, s: %u\n", clock_seconds(), *s);

  if(*s == DISCO_STATE_PREPARING) {
    n740_analog_deactivate();
    wip = M25P16_WIP();
    n740_analog_activate();

    if(wip) {
      restart_timer(DISCO_TIMEOUT_PREPARE);
    } else {
      PRINTF("Disco: Erased %u\n", sector);
      if((sector & 1) == 0) {
        sector++;
        PRINTF("Disco: Next %u\n", sector);
        n740_analog_deactivate();
        m25p16_se(sector);
        n740_analog_activate();
        restart_timer(DISCO_TIMEOUT_PREPARE);
      } else {
        PRINTF("Disco: Ready\n");
        *s = DISCO_STATE_READY;
        resp.status = DISCO_CMD_INIT;
        restart_timer(DISCO_TIMEOUT_ABORT);
        server_conn->rport = seed.port;
        uip_ipaddr_copy(&server_conn->ripaddr, &seed.addr);
        uip_udp_packet_send(server_conn, &resp, DISCO_RESP_LEN_INIT);

        /* Restore server connection to allow data from any node */
        uip_create_unspecified(&server_conn->ripaddr);
        server_conn->rport = 0;
      }
    }
  } else if(*s == DISCO_STATE_READY) {
    abort();
  } else if(*s == DISCO_STATE_REBOOTING) {
    watchdog_reboot();
  }
}
예제 #22
0
/*---------------------------------------------------------------------------*/
uip_ipaddr_t *
uip_ds6_defrt_choose(void)
{
  uip_ds6_defrt_t *d;
  uip_ds6_nbr_t *bestnbr;
  uip_ipaddr_t *addr;
  uip_ipaddr_t unspec;

  /* Check if we have a default route that go to the unspecified IP
     address. This signals that we have set up a route that should
     always go to the fallback interface. If so, we return NULL for
     any route. */
  uip_create_unspecified(&unspec);
  for(d = list_head(defaultrouterlist);
      d != NULL;
      d = list_item_next(d)) {
    if(uip_ipaddr_cmp(&d->ipaddr, &unspec)) {
      return NULL;
    }
  }
  addr = NULL;
  for(d = list_head(defaultrouterlist);
      d != NULL;
      d = list_item_next(d)) {
    PRINTF("Defrt, IP address ");
    PRINT6ADDR(&d->ipaddr);
    PRINTF("\n");
    bestnbr = uip_ds6_nbr_lookup(&d->ipaddr);
    if(bestnbr != NULL && bestnbr->state != NBR_INCOMPLETE) {
      PRINTF("Defrt found, IP address ");
      PRINT6ADDR(&d->ipaddr);
      PRINTF("\n");
      return &d->ipaddr;
    } else {
      addr = &d->ipaddr;
      PRINTF("Defrt INCOMPLETE found, IP address ");
      PRINT6ADDR(&d->ipaddr);
      PRINTF("\n");
    }
  }
  return addr;
}
예제 #23
0
static void send_xy(void)
{

    int i=1, x=node_loc_x, y=node_loc_y, sizeof_buf = sizeof(int) + sizeof(uip_ipaddr_t) + sizeof(int) +sizeof(int);
    unsigned char buf[sizeof_buf];
    unsigned char * buf_p = buf;

    MAPPER_ADD_PACKETDATA(buf_p, i);
    MAPPER_ADD_PACKETDATA(buf_p, myip);
    MAPPER_ADD_PACKETDATA(buf_p, x);
    MAPPER_ADD_PACKETDATA(buf_p, y);

    PRINT6ADDR(&myip);
    printf(" %02x X %u Y %u Bufsize %d \n",myip.u8[15],node_loc_x,node_loc_y, sizeof_buf);
    //send_unicast(&server_ipaddr,buf,sizeof(buf));

    uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &server_ipaddr, UIP_HTONS(2345));
    uip_create_unspecified(&client_conn->ripaddr);
    //uip_udp_packet_sendto(client_conn, "from client ", sizeof("from client "), &server_ipaddr, UIP_HTONS(12345));
}
예제 #24
0
/*---------------------------------------------------------------------------*/
static void
tcpip_handler(void)
{
  char *appdata;

  if(uip_newdata()) {
    appdata = (char *)uip_appdata;
    appdata[uip_datalen()] = 0;
    PRINTF("DATA recv '%s' from ", appdata);
    PRINTF("%d",
           UIP_IP_BUF->srcipaddr.u8[sizeof(UIP_IP_BUF->srcipaddr.u8) - 1]);
    PRINTF("\n");
    PRINTF("DATA sending reply\n");
    uip_ipaddr_copy(&client_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
    uip_udp_packet_send(client_conn, "Reply", sizeof("Reply"));
    uip_create_unspecified(&client_conn->ripaddr);

  }


}
예제 #25
0
파일: rime-udp.c 프로젝트: kincki/contiki
/*---------------------------------------------------------------------------*/
static int
send_packet(void)
{
  const rimeaddr_t *addr;

  addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
  PRINTF("rime-udp: Sending %d bytes to %d.%d\n", packetbuf_totlen(),
         addr->u8[RIMEADDR_SIZE-2], addr->u8[RIMEADDR_SIZE-1]);

  if(rimeaddr_cmp(&rimeaddr_null, addr)) {
    uip_udp_packet_send(broadcast_conn,
                        packetbuf_hdrptr(), packetbuf_totlen());
  } else {
    uip_ip6addr(&unicast_conn->ripaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
    uip_netif_addr_autoconf_set(&unicast_conn->ripaddr, (uip_lladdr_t *)addr);
    uip_udp_packet_send(unicast_conn,
                        packetbuf_hdrptr(), packetbuf_totlen());
    uip_create_unspecified(&unicast_conn->ripaddr);
  }
  return 1;
}
예제 #26
0
/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent_callback, void *ptr)
{
  const rimeaddr_t *addr;

  addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
  PRINTF("rime-udp: Sending %d bytes to %d.%d\n", packetbuf_totlen(),
         addr->u8[0], addr->u8[1]);

  if(rimeaddr_cmp(&rimeaddr_null, addr)) {
    uip_udp_packet_send(broadcast_conn,
                        packetbuf_hdrptr(), packetbuf_totlen());
    mac_call_sent_callback(sent_callback, ptr, MAC_TX_OK, 1);
  } else {
    uip_ip6addr(&unicast_conn->ripaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
    uip_netif_addr_autoconf_set(&unicast_conn->ripaddr, (uip_lladdr_t *)addr);
    uip_udp_packet_send(unicast_conn,
                        packetbuf_hdrptr(), packetbuf_totlen());
    uip_create_unspecified(&unicast_conn->ripaddr);
  }
  return;
}
예제 #27
0
파일: web-sensor.c 프로젝트: notank/contiki
static void udp_data_handler(char *data,struct udp_tx *udp_tx_info)
{
	uint8_t cmd_type ;
	int cmd_flag;
	int i = 0;
	uint8_t cmd[2]={0,0};
	uint8_t device_type[4]={0,0,0,0};
    user.userID=(((0xff)&(data[4]))<<24)+(((0xff)&(data[5]))<<16)+(((0xff)&(data[6]))<<8)+((0xff)&(data[7]));
	printf("userid =%lu\n",user.userID);
    uint8_t m=0;
    m=data[8]+8;

    printf("Udp_Device ID=%d\n",m);

	/*1st,check if header is right,*/
	if((udp_header[0] == data[0])&&(udp_header[1] == data[1])){
		/*2nd,check if version is right.if it's not the right, discard it*/
		//if(version[0]== data[2])
		{
		    /*3nd,check if UDP identification is right.if it's not for us,we'll discard it*/
		#if 0
				for(i = 9;i < deviceID_length+8;i++)
				{
					if(data[i] != udp_id[i-9])
						break;
				}
				for(j = deviceID_length+9;j < deviceID_length+12;j++)
							{
								if(data[i] != device_type[i-9-deviceID_length])
									break;
							}
		#endif


				//if( i == K+1)
					if( i == 0)
				{
				   /*3rd,analyze the cmd type*/
					cmd_type = data[3];
					  printf("cmd=%x\n",cmd_type);

					switch(cmd_type)
					{
		/*----------------------------------------------------(1)注册模考-------------------------------------------*/
						case REGISTER_RSP:                                                  //C0

						break;

						case REGISTER_RECV:                                                 //D0

						break;

/*---------------------------------------------------状态查询模块------------------------------------------------*/
						case STATE_INQUIRE:                                                  //B1
					 cmd[0]=data[m+7];
					 cmd[1]=data[m+8];
					 leds_toggle(LEDS_YELLOW);

					udp_send_state( udp_tx_info,(char*)cmd);
				    uip_udp_packet_send(server_conn, &udp_tx_info->buf[0], udp_tx_info->len);
					 leds_toggle(LEDS_YELLOW);
						break;
/*---------------------------------------------------上电请求模块------------------------------------------------*/
						case REGISTER:                                                 //00
					if ((0x11 == data[m+7])){
						 leds_on(LEDS_YELLOW);                                      /* register succuss */
						 leds_toggle(LEDS_GREEN);
						 server_conn->rport=0;
					}
						break;

/*---------------------------------------------------(3)采样开始停止设置模块---------------------------------------*/
						case DATA_START:                                                   //0xc1

						if ((0x01 == data[m+7])&&(0x31 == data[m+8]))
						{
							printf("DATA_REQ successful\r\n");
							 udp_tx_info ->len =0;
							 udp_fill_data_start_rsp(udp_tx_info);
							 uip_udp_packet_send(server_conn, &udp_tx_info->buf[0], udp_tx_info->len);
							 Sample_begin_flag=1;
						   //  udp_fill_data_rsp(udp_tx_info);
							 udp_tx_info ->len =0;
						}
						else
						{
							printf("DATA_REQ palyload is not right!\r\n");
							udp_tx_info ->len =0;
						}

						break;

						case DATA_END:                                                     //0xc2

							if ((0x01 == data[m+7])&&(0x30 == data[m+8]))
							{
							printf("DATA_end successful\r\n");
							udp_tx_info ->len =0;
							Sample_begin_flag=0;
							 udp_fill_data_end_rsp(udp_tx_info);
						     uip_udp_packet_send(server_conn, &udp_tx_info->buf[0], udp_tx_info->len);
							udp_tx_info ->len =0;
							}
							else
							{
							printf("DATA_end is not right!\r\n");
							udp_tx_info ->len =0;
							}

						break;
/*---------------------------------------------数据查询模块-------------------------------------------------*/
						case  DATA_INQUIRE:                                                //b0
							if ((0x01 == data[m+7])&&(0x01 == data[m+8]))
								udp_fill_data_rsp(udp_tx_info);
							 uip_udp_packet_send(server_conn, &udp_tx_info->buf[0], udp_tx_info->len);

							break;
/*---------------------------------------------------------------------------------------------------------*/
							default:
								udp_tx_info ->len =0;
								printf("undefine type");
					}
					//	if(udp_tx_info->len == 0)
						{
						   uip_create_unspecified(&server_conn->ripaddr);
						   server_conn->rport=0;

						}
					}
		}
	}
}
예제 #28
0
파일: uip-nd6.c 프로젝트: drandreas/6lbr
static void
ns_input(void)
{
    uint8_t flags;
#if CETIC_6LBR_SMARTBRIDGE
    uip_ds6_route_t * route;
#endif
    uip_ipaddr_t tgtipaddr;

    PRINTF("Received NS from ");
    PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
    PRINTF(" to ");
    PRINT6ADDR(&UIP_IP_BUF->destipaddr);
    PRINTF(" with target address");
    PRINT6ADDR((uip_ipaddr_t *) (&UIP_ND6_NS_BUF->tgtipaddr));
    PRINTF("\n");
    UIP_STAT(++uip_stat.nd6.recv);

#if UIP_CONF_IPV6_CHECKS
    if((UIP_IP_BUF->ttl != UIP_ND6_HOP_LIMIT) ||
            (uip_is_addr_mcast(&UIP_ND6_NS_BUF->tgtipaddr)) ||
            (UIP_ICMP_BUF->icode != 0)) {
        PRINTF("NS received is bad\n");
        goto discard;
    }
#endif /* UIP_CONF_IPV6_CHECKS */

    /* Options processing */
    nd6_opt_llao = NULL;
    nd6_opt_offset = UIP_ND6_NS_LEN;
    while(uip_l3_icmp_hdr_len + nd6_opt_offset < uip_len) {
#if UIP_CONF_IPV6_CHECKS
        if(UIP_ND6_OPT_HDR_BUF->len == 0) {
            PRINTF("NS received is bad\n");
            goto discard;
        }
#endif /* UIP_CONF_IPV6_CHECKS */
        switch (UIP_ND6_OPT_HDR_BUF->type) {
        case UIP_ND6_OPT_SLLAO:
            nd6_opt_llao = &uip_buf[uip_l2_l3_icmp_hdr_len + nd6_opt_offset];
#if UIP_CONF_IPV6_CHECKS
            /* There must be NO option in a DAD NS */
            if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
                PRINTF("NS received is bad\n");
                goto discard;
            } else {
#endif /*UIP_CONF_IPV6_CHECKS */
                nbr = uip_ds6_nbr_lookup(&UIP_IP_BUF->srcipaddr);
                if(nbr == NULL) {
                    /* Copy link address to a uip_lladdr_t first
                     * to ensure the second argument to uip_ds6_nbr_add is word-aligned */
                    uip_lladdr_t lladdr;
                    memcpy(&lladdr, &nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET], UIP_LLADDR_LEN);
                    uip_ds6_nbr_add(&UIP_IP_BUF->srcipaddr, &lladdr, 0, NBR_STALE);
                } else {
                    uip_lladdr_t *lladdr = (uip_lladdr_t *)uip_ds6_nbr_get_ll(nbr);
                    if(memcmp(&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET],
                              lladdr, UIP_LLADDR_LEN) != 0) {
                        memcpy(lladdr, &nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET], UIP_LLADDR_LEN);
                        nbr->state = NBR_STALE;
                    } else {
                        if(nbr->state == NBR_INCOMPLETE) {
                            nbr->state = NBR_STALE;
                        }
                    }
                }
#if UIP_CONF_IPV6_CHECKS
            }
#endif /*UIP_CONF_IPV6_CHECKS */
            break;
        default:
            PRINTF("ND option not supported in NS");
            break;
        }
        nd6_opt_offset += (UIP_ND6_OPT_HDR_BUF->len << 3);
    }

    memcpy(&tgtipaddr, &UIP_ND6_NS_BUF->tgtipaddr, sizeof(tgtipaddr));
    addr = uip_ds6_addr_lookup(&tgtipaddr);
#if CETIC_6LBR_SMARTBRIDGE
    //ND Proxy implementation
    if ( addr == NULL ) {
        if ( (route = uip_ds6_route_lookup(&tgtipaddr)) != NULL ) {
            if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
                /* DAD CASE */
                uip_create_linklocal_allnodes_mcast(&tgtipaddr);
                uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tgtipaddr);
                flags = UIP_ND6_NA_FLAG_OVERRIDE;
                goto create_na;
            } else {
                uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr);
                uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tgtipaddr);
                flags = UIP_ND6_NA_FLAG_SOLICITED | UIP_ND6_NA_FLAG_OVERRIDE;
                goto create_na;
            }
        }
    }
#endif
    if(addr != NULL) {
#if UIP_ND6_DEF_MAXDADNS > 0
        if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
            /* DAD CASE */
#if UIP_CONF_IPV6_CHECKS
            if(!uip_is_addr_solicited_node(&UIP_IP_BUF->destipaddr)) {
                PRINTF("NS received is bad\n");
                goto discard;
            }
#endif /* UIP_CONF_IPV6_CHECKS */
            if(addr->state != ADDR_TENTATIVE) {
                uip_create_linklocal_allnodes_mcast(&UIP_IP_BUF->destipaddr);
                uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
                flags = UIP_ND6_NA_FLAG_OVERRIDE;
                goto create_na;
            } else {
                /** \todo if I sent a NS before him, I win */
                uip_ds6_dad_failed(addr);
                goto discard;
            }
#else /* UIP_ND6_DEF_MAXDADNS > 0 */
        if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
            /* DAD CASE */
            goto discard;
#endif /* UIP_ND6_DEF_MAXDADNS > 0 */
        }
#if UIP_CONF_IPV6_CHECKS
        if(uip_ds6_is_my_addr(&UIP_IP_BUF->srcipaddr)) {
            /**
             * \NOTE do we do something here? we both are using the same address.
             * If we are doing dad, we could cancel it, though we should receive a
             * NA in response of DAD NS we sent, hence DAD will fail anyway. If we
             * were not doing DAD, it means there is a duplicate in the network!
             */
            PRINTF("NS received is bad\n");
            goto discard;
        }
#endif /*UIP_CONF_IPV6_CHECKS */

        /* Address resolution case */
        if(uip_is_addr_solicited_node(&UIP_IP_BUF->destipaddr)) {
            uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr);
            uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tgtipaddr);
            flags = UIP_ND6_NA_FLAG_SOLICITED | UIP_ND6_NA_FLAG_OVERRIDE;
            goto create_na;
        }

        /* NUD CASE */
        if(uip_ds6_addr_lookup(&UIP_IP_BUF->destipaddr) == addr) {
            uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr);
            uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tgtipaddr);
            flags = UIP_ND6_NA_FLAG_SOLICITED | UIP_ND6_NA_FLAG_OVERRIDE;
            goto create_na;
        } else {
#if UIP_CONF_IPV6_CHECKS
            PRINTF("NS received is bad\n");
            goto discard;
#endif /* UIP_CONF_IPV6_CHECKS */
        }
    } else {
        goto discard;
    }


create_na:
    /* If the node is a router it should set R flag in NAs */
#if UIP_CONF_ROUTER
    flags = flags | UIP_ND6_NA_FLAG_ROUTER;
#endif
    uip_ext_len = 0;
    UIP_IP_BUF->vtc = 0x60;
    UIP_IP_BUF->tcflow = 0;
    UIP_IP_BUF->flow = 0;
    UIP_IP_BUF->len[0] = 0;       /* length will not be more than 255 */
    UIP_IP_BUF->len[1] = UIP_ICMPH_LEN + UIP_ND6_NA_LEN + UIP_ND6_OPT_LLAO_LEN;
    UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
    UIP_IP_BUF->ttl = UIP_ND6_HOP_LIMIT;

    UIP_ICMP_BUF->type = ICMP6_NA;
    UIP_ICMP_BUF->icode = 0;

    UIP_ND6_NA_BUF->flagsreserved = flags;
    memcpy(&UIP_ND6_NA_BUF->tgtipaddr, &tgtipaddr, sizeof(uip_ipaddr_t));

    create_llao(&uip_buf[uip_l2_l3_icmp_hdr_len + UIP_ND6_NA_LEN],
                UIP_ND6_OPT_TLLAO);

    UIP_ICMP_BUF->icmpchksum = 0;
    UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();

    uip_len =
        UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ND6_NA_LEN + UIP_ND6_OPT_LLAO_LEN;

    UIP_STAT(++uip_stat.nd6.sent);
    PRINTF("Sending NA to ");
    PRINT6ADDR(&UIP_IP_BUF->destipaddr);
    PRINTF(" from ");
    PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
    PRINTF(" with target address ");
    PRINT6ADDR(&UIP_ND6_NA_BUF->tgtipaddr);
    PRINTF("\n");
    return;

discard:
    uip_clear_buf();
    return;
}
#endif /* UIP_ND6_SEND_NA */


/*------------------------------------------------------------------*/
void
uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt)
{
    uip_ext_len = 0;
    UIP_IP_BUF->vtc = 0x60;
    UIP_IP_BUF->tcflow = 0;
    UIP_IP_BUF->flow = 0;
    UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
    UIP_IP_BUF->ttl = UIP_ND6_HOP_LIMIT;

    if(dest == NULL) {
        uip_create_solicited_node(tgt, &UIP_IP_BUF->destipaddr);
    } else {
        uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, dest);
    }
    UIP_ICMP_BUF->type = ICMP6_NS;
    UIP_ICMP_BUF->icode = 0;
    UIP_ND6_NS_BUF->reserved = 0;
    uip_ipaddr_copy((uip_ipaddr_t *) &UIP_ND6_NS_BUF->tgtipaddr, tgt);
    UIP_IP_BUF->len[0] = 0;       /* length will not be more than 255 */
    /*
     * check if we add a SLLAO option: for DAD, MUST NOT, for NUD, MAY
     * (here yes), for Address resolution , MUST
     */
    if(!(uip_ds6_is_my_addr(tgt))) {
        if(src != NULL) {
            uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, src);
        } else {
            uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
        }
        if (uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
            PRINTF("Dropping NS due to no suitable source address\n");
            uip_clear_buf();
            return;
        }
        UIP_IP_BUF->len[1] =
            UIP_ICMPH_LEN + UIP_ND6_NS_LEN + UIP_ND6_OPT_LLAO_LEN;

        create_llao(&uip_buf[uip_l2_l3_icmp_hdr_len + UIP_ND6_NS_LEN],
                    UIP_ND6_OPT_SLLAO);

        uip_len =
            UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ND6_NS_LEN + UIP_ND6_OPT_LLAO_LEN;
    } else {
        uip_create_unspecified(&UIP_IP_BUF->srcipaddr);
        UIP_IP_BUF->len[1] = UIP_ICMPH_LEN + UIP_ND6_NS_LEN;
        uip_len = UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ND6_NS_LEN;
    }

    UIP_ICMP_BUF->icmpchksum = 0;
    UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();

    UIP_STAT(++uip_stat.nd6.sent);
    PRINTF("Sending NS to");
    PRINT6ADDR(&UIP_IP_BUF->destipaddr);
    PRINTF("from");
    PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
    PRINTF("with target address");
    PRINT6ADDR(tgt);
    PRINTF("\n");
    return;
}
예제 #29
0
/*---------------------------------------------------------------------------*/
void
cetic_6lbr_init(void)
{
  uip_ds6_addr_t *local = uip_ds6_get_link_local(-1);

  uip_ipaddr_copy(&wsn_ip_local_addr, &local->ipaddr);

  LOG6LBR_6ADDR(INFO, &wsn_ip_local_addr, "Tentative local IPv6 address ");

  eth_mac64_addr.addr[0] = eth_mac_addr[0];
  eth_mac64_addr.addr[1] = eth_mac_addr[1];
  eth_mac64_addr.addr[2] = eth_mac_addr[2];
  eth_mac64_addr.addr[3] = CETIC_6LBR_ETH_EXT_A;
  eth_mac64_addr.addr[4] = CETIC_6LBR_ETH_EXT_B;
  eth_mac64_addr.addr[5] = eth_mac_addr[3];
  eth_mac64_addr.addr[6] = eth_mac_addr[4];
  eth_mac64_addr.addr[7] = eth_mac_addr[5];

#if CETIC_6LBR_SMARTBRIDGE

  if((nvm_data.mode & CETIC_MODE_WAIT_RA_MASK) == 0)    //Manual configuration
  {
    memcpy(wsn_net_prefix.u8, &nvm_data.wsn_net_prefix,
           sizeof(nvm_data.wsn_net_prefix));
    wsn_net_prefix_len = nvm_data.wsn_net_prefix_len;
    if((nvm_data.mode & CETIC_MODE_WSN_AUTOCONF) != 0)  //Address auto configuration
    {
      uip_ipaddr_copy(&wsn_ip_addr, &wsn_net_prefix);
      uip_ds6_set_addr_iid(&wsn_ip_addr, &uip_lladdr);
      uip_ds6_addr_add(&wsn_ip_addr, 0, ADDR_AUTOCONF);
    } else {
      memcpy(wsn_ip_addr.u8, &nvm_data.wsn_ip_addr,
             sizeof(nvm_data.wsn_ip_addr));
      uip_ds6_addr_add(&wsn_ip_addr, 0, ADDR_MANUAL);
    }
    LOG6LBR_6ADDR(INFO, &wsn_ip_addr, "Tentative global IPv6 address ");
    memcpy(eth_dft_router.u8, &nvm_data.eth_dft_router,
           sizeof(nvm_data.eth_dft_router));
    if ( !uip_is_addr_unspecified(&eth_dft_router) ) {
      uip_ds6_defrt_add(&eth_dft_router, 0);
    }
    uip_ipaddr_t dns;
    memcpy(dns.u8, &nvm_data.dns_server,
           sizeof(nvm_data.dns_server));
    uip_nameserver_update(&dns, UIP_NAMESERVER_INFINITE_LIFETIME);
  } else {                            //End manual configuration
    uip_create_unspecified(&wsn_net_prefix);
    wsn_net_prefix_len = 0;
    uip_create_unspecified(&wsn_ip_addr);
  }
#endif

#if CETIC_6LBR_ROUTER
  //WSN network configuration
  memcpy(wsn_net_prefix.u8, &nvm_data.wsn_net_prefix,
         sizeof(nvm_data.wsn_net_prefix));
  wsn_net_prefix_len = nvm_data.wsn_net_prefix_len;
  if((nvm_data.mode & CETIC_MODE_WSN_AUTOCONF) != 0)    //Address auto configuration
  {
    uip_ipaddr_copy(&wsn_ip_addr, &wsn_net_prefix);
    uip_ds6_set_addr_iid(&wsn_ip_addr, &uip_lladdr);
    uip_ds6_addr_add(&wsn_ip_addr, 0, ADDR_AUTOCONF);
  } else {
    memcpy(wsn_ip_addr.u8, &nvm_data.wsn_ip_addr,
           sizeof(nvm_data.wsn_ip_addr));
    uip_ds6_addr_add(&wsn_ip_addr, 0, ADDR_MANUAL);
  }
  LOG6LBR_6ADDR(INFO, &wsn_ip_addr, "Tentative global IPv6 address (WSN) ");
  uip_ipaddr_t dns;
  memcpy(dns.u8, &nvm_data.dns_server,
         sizeof(nvm_data.dns_server));
  uip_nameserver_update(&dns, UIP_NAMESERVER_INFINITE_LIFETIME);

  //Ethernet network configuration
  memcpy(eth_net_prefix.u8, &nvm_data.eth_net_prefix,
         sizeof(nvm_data.eth_net_prefix));
  memcpy(eth_dft_router.u8, &nvm_data.eth_dft_router,
         sizeof(nvm_data.eth_dft_router));

  if ( !uip_is_addr_unspecified(&eth_dft_router) ) {
    uip_ds6_defrt_add(&eth_dft_router, 0);
  }

  if((nvm_data.mode & CETIC_MODE_ETH_AUTOCONF) != 0)    //Address auto configuration
  {
    uip_ipaddr_copy(&eth_ip_addr, &eth_net_prefix);
    uip_ds6_set_addr_iid(&eth_ip_addr, &eth_mac64_addr);
    uip_ds6_addr_add(&eth_ip_addr, 0, ADDR_AUTOCONF);
  } else {
    memcpy(eth_ip_addr.u8, &nvm_data.eth_ip_addr,
           sizeof(nvm_data.eth_ip_addr));
    uip_ds6_addr_add(&eth_ip_addr, 0, ADDR_MANUAL);
  }
  LOG6LBR_6ADDR(INFO, &eth_ip_addr, "Tentative global IPv6 address (ETH) ");

  //Ugly hack : in order to set WSN local address as the default address
  //We must add it afterwards as uip_ds6_addr_add allocates addr from the end of the list
  uip_ds6_addr_rm(local);

  uip_create_linklocal_prefix(&eth_ip_local_addr);
  uip_ds6_set_addr_iid(&eth_ip_local_addr, &eth_mac64_addr);
  uip_ds6_addr_add(&eth_ip_local_addr, 0, ADDR_AUTOCONF);

  uip_ds6_addr_add(&wsn_ip_local_addr, 0, ADDR_AUTOCONF);

  //Prefix and RA configuration
#if CETIC_6LBR_WITH_RPL
  uint8_t publish = (nvm_data.ra_prefix_flags & CETIC_6LBR_MODE_SEND_PIO) != 0;
  uip_ds6_prefix_add(&eth_net_prefix, nvm_data.eth_net_prefix_len, publish,
                     nvm_data.ra_prefix_flags,
                     nvm_data.ra_prefix_vtime, nvm_data.ra_prefix_ptime);
#else
  uip_ds6_prefix_add(&eth_net_prefix, nvm_data.eth_net_prefix_len, 0, 0, 0, 0);
  uint8_t publish = (nvm_data.ra_prefix_flags & CETIC_6LBR_MODE_SEND_PIO) != 0;
  uip_ds6_prefix_add(&wsn_net_prefix, nvm_data.wsn_net_prefix_len, publish,
		             nvm_data.ra_prefix_flags,
		             nvm_data.ra_prefix_vtime, nvm_data.ra_prefix_ptime);
#endif

#if CETIC_6LBR_WITH_RPL
  if ((nvm_data.ra_rio_flags & CETIC_6LBR_MODE_SEND_RIO) != 0 ) {
    uip_ds6_route_info_add(&wsn_net_prefix, nvm_data.wsn_net_prefix_len, nvm_data.ra_rio_flags, nvm_data.ra_rio_lifetime);
  }
#endif
  if ((nvm_data.mode & CETIC_MODE_ROUTER_RA_DAEMON) != 0 ) {
    LOG6LBR_INFO("RA Daemon enabled\n");
  } else {
    LOG6LBR_INFO("RA Daemon disabled\n");
  }
#endif
}
예제 #30
0
파일: node-info.c 프로젝트: Ayesha-N/6lbr
node_info_t *
node_info_update(uip_ipaddr_t * ipaddr, char * info)
{
  node_info_t *node = NULL;
  char *  sep;
  uip_ipaddr_t ip_parent;

  node = node_info_lookup(ipaddr);
  if (node == NULL) {
    node = node_info_add(ipaddr);
  }
  if ( node != NULL ) {
    node->last_seen = clock_time();
    node->last_message = clock_time();
    uint16_t up_sequence = 0;
    uint16_t down_sequence = 0;

    sep = index(info, '|');
    if (sep != NULL) {
      node->messages_received++;
      up_sequence = atoi(info);
      *sep = 0;
      info = sep + 1;
      if (*info == ' ') {
        info++;
      }
      sep = index(info, '|');
      if (sep != NULL) {
        *sep = 0;
      }
      if (uiplib_ipaddrconv(info, &ip_parent) == 0) {
        uip_create_unspecified(&ip_parent);
      }
      if(!uip_ipaddr_cmp(&node->ip_parent, &ip_parent)) {
        uip_ipaddr_copy(&(node->ip_parent), &ip_parent);
        if (node->messages_received > 1) {
          node->parent_switch++;
        }
      }
      if (sep != NULL) {
        info = sep + 1;
        down_sequence = atoi(info);
      }
      if (node->messages_received > 1) {
        uint16_t up_delta = up_sequence - node->last_up_sequence;
        if (up_delta < 100) {
          node->messages_sent += up_delta;
          node->up_messages_lost += up_delta - 1;
          if(down_sequence != node->last_down_sequence + 1) {
            node->down_messages_lost += 1;
          }
        } else {
          //Reset statistics
          node->messages_sent = 1;
          node->replies_sent = 0;
          node->up_messages_lost = 0;
          node->down_messages_lost = 0;
        }
      } else {
        node->messages_sent = 1;
        node->replies_sent = 0;
        node->up_messages_lost = 0;
        node->down_messages_lost = 0;
      }
      node->last_up_sequence = up_sequence;
      node->last_down_sequence = down_sequence;
    } else {
      node->last_up_sequence = 0;
      node->last_down_sequence = 0;
      uip_create_unspecified(&node->ip_parent);
    }
  }
  return node;
}