Ejemplo n.º 1
0
/*
 * This function is called when the timer of an element in the nwlr_table
 * expires. This function send a DIS message to the node whose timer is expired
 * and reset the timer to call the function set by the user.
 *
 * @paramenter expired_elem, the element in the table whose timer is expired.
 */
void
last_chance(void* expired_elem)
{
  struct kag_nwlr_element* expired_element= (struct kag_nwlr_element*) expired_elem;
  dis_output(&expired_element->ip);
  ctimer_set(&expired_element->keep_alive_timer, kag_data.next_dio_msg, kag_data.found_dead_node, &expired_element->ip);
}
Ejemplo n.º 2
0
static void
tcpip_handler(void)
{
 /*
    char *str;
    uip_ipaddr_t tadd;
    printf("In tcphandler\n");
    if(uip_newdata()) {
        str = uip_appdata;
        str[uip_datalen()] = '\0';
        printf("DATA recv '%s'\n", str);
        //uip_ip6addr(&tadd, 0xaaaa, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202);
        //uip_udp_packet_sendto(client_conn, "from client ", sizeof("from client "), &tadd, UIP_HTONS(12345));
    }
*/
    
        uint8_t *appdata=NULL,a;int code=0;
        if(uip_newdata()) {

    	appdata = (uint8_t *) uip_appdata;
    	MAPPER_GET_PACKETDATA(code,appdata);
    	switch(code)
    	{
    		case 1://helping packet
	    	printf("Helper message \n");
			help(appdata);
    		break;
    		case 2://adding neighbor info and ranks
    			forward_packet(appdata);
    		break;
		case 3://victim packet
    		printf("I am Victim\n");
			monitoring(appdata);
    		break;
		case 4://monitoring node
		
    		break;
		case 5://Selent packet
    		//upade_info(appdata);
    		break;
		case 7://Nbr info req
		snd_nbr_info();
    		break;
		case 8://nbr_info process
		if(!attacker_set)    		
			select_attacker(appdata); 
    		break;
		case 9://Wormhole deactive
		
    		MAPPER_GET_PACKETDATA(code,appdata);
		if(code==2)
		{printf("Attacker 2\n");attack_flag=1;attacker=2;setreg(17,0);}
		if(code==3)	
		{printf("Attacker 3\n");attack_flag=1;attacker=3;dis_output(NULL);setreg(17,0);}
    		break;
    	}
        }
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
void
rpl_dag_root_init_dag(void)
{
  rpl_dag_root_init();

  ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL);
  to_become_root = 1;

  /* Send a DIS packet to request RPL info from neighbors. */
  dis_output(NULL);
}
Ejemplo n.º 4
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);
		}
	}
		
}
Ejemplo n.º 5
0
/*---------------------------------------------------------------------------*/
void
simple_rpl_init_dag(void)
{
    ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL);
    to_become_root = 1;

    /* Send a DIS packet to request RPL info from neighbors. */
    dis_output(NULL);

    /* We set a default route of NULL. This means that we want our
       default route to be the fallback interface, regardless if we
       learn new default routes from the RPL network. */
    uip_ds6_defrt_add(NULL, 0);
}
Ejemplo n.º 6
0
/*---------------------------------------------------------------------------*/
static void
handle_periodic_timer(void *ptr)
{
  rpl_purge_routes();
  rpl_recalculate_ranks();

  /* handle DIS */
#if UIP_ND6_ENGINE != UIP_ND6_ENGINE_RPL
#if RPL_DIS_SEND
  next_dis++;
  if(rpl_get_any_dag() == NULL && next_dis >= RPL_DIS_INTERVAL) {
    next_dis = 0;
    dis_output(NULL);
  }
#endif
#else
 if(rpl_get_any_dag() == NULL && stimer_expired(&uip_ds6_timer_dis)) {
	discount++;
	dis_output(NULL); 
	stimer_set(&uip_ds6_timer_dis, rs_rtx_time(discount));
 }
#endif
  ctimer_reset(&periodic_timer);
}
Ejemplo n.º 7
0
/*---------------------------------------------------------------------------*/
static void
handle_periodic_timer(void *ptr)
{
  rpl_purge_routes();
  rpl_recalculate_ranks();

  /* handle DIS */
#if RPL_DIS_SEND
  next_dis++;
  if(rpl_get_any_dag() == NULL && next_dis >= RPL_DIS_INTERVAL) {
    next_dis = 0;
    dis_output(NULL);
  }
#endif
  ctimer_reset(&periodic_timer);
}
Ejemplo n.º 8
0
void
cetic_6lbr_start_delayed_dodag_root(int send_dis)
{
  if(rpl_can_become_root && is_own_dodag()) {
    LOG6LBR_INFO("Own DODAG already existing\n");
    cetic_6lbr_start_dodag_root();
  } else {
    dodag_root_check_interval = rpl_wait_delay / 2 + random_rand() % (rpl_wait_delay / 2);
    LOG6LBR_INFO("Wait for potential DODAGs\n");
    ctimer_set(&create_dodag_root_timer, dodag_root_check_interval, check_dodag_creation, NULL);
    uip_ds6_notification_add(&create_dodag_root_route_callback, route_callback);
    if(send_dis) {
      dis_output(NULL);
    }
  }
}
Ejemplo n.º 9
0
/*void start_no_data_timer() {
	etimer_set(&bad_etx_timer, NO_DATA_PERIOD);
}
void stop_no_data_timer(){
	etimer_stop(&bad_etx_timer);
}*/
void eventhandler(process_event_t ev, process_data_t data) {
	switch (ev) {

	case PARENT_UNREACHABLE: {
		instance = &instance_table[0];
		dag = instance->current_dag;
		if (dag->preferred_parent != NULL) {
			p = dag->preferred_parent;
			PRINT6ADDR(rpl_get_parent_ipaddr(p));
		} else {
			PRINTF("NULL");
		} PRINTF("\n");

		if (test_unreachable == 1 && hand_off_backoff_flag == 0) {
			PRINTF("Connection unstable\n");

			reliable = 0;
			if (wait_dio_flag == 0) {
				PRINTF("Sending DIS to current parent\n");
				dis_output(rpl_get_parent_ipaddr(p), 1, 0, 0, 0); /* Send DIS to assess parent */
				wait_dio_flag = 1;
				/*
				 * Wait DIO reply. If parent doesn't reply until timer finishes,
				 * he's considered unreachable.
				 */
				etimer_set(&dio_check, WAIT_DIO);
			} else {
				etimer_set(&dio_check, WAIT_DIO);
			}
		}
	}
		break;

	case PARENT_REACHABLE: {
		uint8_t *dis_rssi;

		/* We received the DIO reply from parent but we need to check the RSSI value */
		dis_rssi = data;
		rssi = dis_rssi - 45;
		if (dis_rssi > 200) {
			rssi = dis_rssi - 255 - 46;
		} PRINTF("RSSI response from parent = %d ->", rssi);
		if (rssi <= -85) {
			PRINTF(" Unreliable\n");
			mobility_flag = 1;
			leds_on(LEDS_ALL);
			current_t = clock_time() * 1000 / CLOCK_SECOND;
			PRINTF("%u\n", current_t);
			dis_output(NULL, 1, counter, 0, 0);
			rpl_dis_burst();
		} else {
			PRINTF(" Reliable\n");
			reliable = 1;
			process_post(&tcpip_process, RESET_MOBILITY_FLAG, NULL);
		}
	}
		break;

	case DIS_BURST: {
		etimer_reset(&dis_timer);
	}
		break;

		/* DIO received when checking current parent, stop the timer */
	case STOP_DIO_CHECK: {
		printf("stopping DIO CHECK\n");
		etimer_stop(&dio_check);
		etimer_stop(&dis_timer);
	}
		break;

	case PROCESS_EVENT_TIMER: {
		/* Current parent Unreachable/Unreliable, print current time and start DIS_BURST */
		if (data == &dio_check && etimer_expired(&dio_check) && !reliable
				&& test_unreachable == 1) {
			mobility_flag = 1;
			if (dis_burst_flag == 0) {
				dis_burst_flag++;
				current_t = clock_time() * 1000 / CLOCK_SECOND;
				 printf("Start %u\n", current_t);
				dis_output(NULL, 1, counter, 0, 0);
				etimer_set(&dis_timer, SEND_TIME);
			} else {
				rpl_dis_burst();
			}
		}
		/* 1st DIS was sent above. Check for the backoff delay and keep sending (Total = 3DIS) */
		if (data == &dis_timer && etimer_expired(&dis_timer)) {
			counter++;
			dis_output(NULL, 1, counter, 0, 0);
			if (counter < 3) {
				etimer_reset(&dis_timer);
			} else {
				counter = 1;
				dis_burst_flag = 0;
			}
		}

	}break;
}
}
Ejemplo n.º 10
0
/*---------------------------------------------------------------------------*/
static void
packet_input(void)
{
#if FORWARDER
	rpl_instance_t *instance;
	uint8_t octet;
	uint8_t ip6id;
	int rssi_temp;
	uint8_t send_rssi;
	rimeaddr_t packet_from_addr;

	packet_from_addr = *packetbuf_addr(PACKETBUF_ADDR_SENDER);
	instance = &instance_table[0];
	octet = packet_from_addr.u8[7];
	ip6id = (octet & 0b00111111) << 2;
	tcp_rssi = packetbuf_attr(PACKETBUF_ATTR_RSSI);
  if(is_mobile_node(octet) == 1) {
    packet_input_count++;
    rssi_temp = tcp_rssi - 45;
    if(tcp_rssi > 200) {
      rssi_temp = tcp_rssi - 255 - 46;
    }
    rssi_sum += rssi_temp;

    if(packet_input_count == WINDOW_SIZE) {
      rssi_sum = rssi_sum / WINDOW_SIZE;
      PRINTF("RSSI = %d\n", rssi_sum);
      PRINTF("packet input count = %d\n", packet_input_count);
      if(rssi_sum <= -90) {
        send_rssi = rssi_sum + 255 + 46;
        dis_output(NULL, 1, 0, send_rssi, ip6id);
      }
      rssi_sum = 0;
      packet_input_count = 0;
    }
  }
#endif

#if UIP_CONF_IP_FORWARD
  if(uip_len > 0) {
    tcpip_is_forwarding = 1;
    if(uip_fw_forward() == UIP_FW_LOCAL) {
      tcpip_is_forwarding = 0;
      check_for_tcp_syn();
      uip_input();
      if(uip_len > 0) {
#if UIP_CONF_TCP_SPLIT
        uip_split_output();
#else /* UIP_CONF_TCP_SPLIT */
#if UIP_CONF_IPV6
        tcpip_ipv6_output();
#else
        PRINTF("tcpip packet_input forward output len %d\n", uip_len);
        tcpip_output();
#endif
#endif /* UIP_CONF_TCP_SPLIT */
      }
    }
    tcpip_is_forwarding = 0;
  }
#else /* UIP_CONF_IP_FORWARD */
  if(uip_len > 0) {
    check_for_tcp_syn();
    uip_input();
    if(uip_len > 0) {
#if UIP_CONF_TCP_SPLIT
      uip_split_output();
#else /* UIP_CONF_TCP_SPLIT */
#if UIP_CONF_IPV6
      tcpip_ipv6_output();
#else
      PRINTF("tcpip packet_input output len %d\n", uip_len);
      tcpip_output();
#endif
#endif /* UIP_CONF_TCP_SPLIT */
    }
  }
#endif /* UIP_CONF_IP_FORWARD */
}
Ejemplo n.º 11
0
PROCESS_THREAD(udp_client_process, ev, data)
{
    static struct etimer start_timer, send_timer;
    static int flag=1;int i=0;
    static struct mt_thread sending_thread, attackinit_thread;	

    PROCESS_BEGIN();

    SENSORS_ACTIVATE(button_sensor);
    SENSORS_ACTIVATE(radio_sensor);

    set_global_address();

    printf("UDP client process started\n");

    print_local_addresses();

	myip=uip_ds6_get_link_local(ADDR_PREFERRED)->ipaddr;

    /* new connection with remote host */
    client_conn = udp_new(NULL, NULL, NULL);
    if(client_conn == NULL) {
        printf("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
    udp_bind(client_conn, UIP_HTONS(10000+(int)myip.u8[15]));

    udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT),tcpip_handler);
    //uip_create_unspecified(&udp_bconn->ripaddr);	
    if(udp_bconn == NULL) {
        printf("No UDP broadcast connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
	
    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(&start_timer, 60 * CLOCK_SECOND);//network setting time
    etimer_set(&send_timer, CLOCK_SECOND * ((int)myip.u8[15]+60+40));//node check/send parent info
    char buf[3]="hi";


    mt_init();
    mt_start(&sending_thread, sendpacket, 0);
    mt_start(&attackinit_thread, attack_init, NULL);	
    while(1) {

        PROCESS_YIELD();

        //NETSTACK_RDC.off(0);
        //NETSTACK_MAC.off(0);
        //NETSTACK_RADIO.off();
        //button_sensor::value(0);

        if(ev==tcpip_event)
        {
			
	    tcpip_handler();	                  
        }
	if(rssi_stored==5)// if got 5 rssi value from parent or child
	{
		monitor=0;
		monitor_target=0;
		for(i=0;i<5;i++)
			printf("Monitered value %d \n",mrssi[i]);
		rssi_stored=0;
	}
        if((ev==sensors_event) && (data == &button_sensor)) {            
	if(attack_flag)      
	{
		printf("Attack deactivated\n");   
		attack_flag=0;
		attacker=0;
		attacker_set=0;
		dis_output(NULL);
	}else {
		printf("Attack activated\n");   
		mt_exec(&attackinit_thread);
	}	
        }
        if((ev==sensors_event) && (data == &radio_sensor))
        {
            printf("Radio value %d",radio_sensor.value(0));
        }
        if(etimer_expired(&send_timer))
	{
		//uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &server_ipaddr, UIP_HTONS(2345));
		//uip_create_unspecified(&client_conn->ripaddr); 
		//if(myip.u8[15]==4)
		//sendpacket(0);
		etimer_set(&send_timer, CLOCK_SECOND*(myip.u8[15]+60));
		if(parent_change)        // send only at parent change event
		{	            
	            if(!attack_flag)	//  this is not attacker and
		    {	
			mt_exec(&sending_thread);
			//sendpacket(0);	//  send nbr info by broadcast 0 for broadcast 
			parent_change=0;
			printf("Thread initiated\n");
		    }
	        }
	}
        if(etimer_expired(&start_timer) && flag==1)
        {
            flag=0;
            send_xy();
	    etimer_set(&start_timer, CLOCK_SECOND*(myip.u8[15]+1));
	    PROCESS_WAIT_UNTIL(etimer_expired(&start_timer));
	    send_broadcast("hi",sizeof("hi"));	
	    sendpacket(1);	// 0 means send by unicast	
	    	
        }
    }

    PROCESS_END();
}