示例#1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(servreg_hack_process, ev, data)
{
  static struct etimer periodic;
  static struct uip_udp_conn *outconn, *inconn;
  PROCESS_BEGIN();

  /* Create outbound UDP connection. */
  outconn = udp_broadcast_new(UIP_HTONS(UDP_PORT), NULL);
  udp_bind(outconn, UIP_HTONS(UDP_PORT));

  /* Create inbound UDP connection. */
  inconn = udp_new(NULL, UIP_HTONS(UDP_PORT), NULL);
  udp_bind(inconn, UIP_HTONS(UDP_PORT));

  etimer_set(&periodic, PERIOD_TIME);
  etimer_set(&sendtimer, random_rand() % (PERIOD_TIME));
  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == PROCESS_EVENT_TIMER && data == &periodic) {
      etimer_reset(&periodic);
      etimer_set(&sendtimer, random_rand() % (PERIOD_TIME));
    } else if(ev == PROCESS_EVENT_TIMER && data == &sendtimer) {
      send_udp_packet(outconn);
    } else if(ev == tcpip_event) {
      parse_incoming_packet(uip_appdata, uip_datalen());
    }
  }
  PROCESS_END();
}
示例#2
0
PROCESS_THREAD(udp_process, ev, data)
{
  static struct uip_udp_conn *s;
  static struct etimer et;

  PROCESS_BEGIN();

  uart0_set_br(1000000);

  /* setup udp connection             */
  s = udp_broadcast_new(UIP_HTONS(2020),NULL); // incoming
  udp_bind(s,UIP_HTONS(2020));                 // outgoing

  /* start estimator process and init psock connection handler */
  process_start(&ahrs_process, NULL);

  etimer_set(&et, SEND_INTERVAL);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev==PROCESS_EVENT_TIMER);
    uip_udp_packet_send(s,msg,strlen(msg));
    etimer_restart(&et);
  }

  PROCESS_END();
}
示例#3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(broadcast_example_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t addr;
 
  PROCESS_BEGIN();
//set_global_address();
 udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT),NULL);
    //uip_create_unspecified(&udp_bconn->ripaddr);	
    if(udp_bconn == NULL) {
        printf("NUC E\n");
        PROCESS_EXIT();
    }

  etimer_set(&periodic_timer, SEND_INTERVAL);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_reset(&periodic_timer);
    etimer_set(&send_timer, SEND_TIME);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
    printf("Sending broadcast\n");
    send_broadcast("hi",sizeof("hi"));
  }

  PROCESS_END();
}
示例#4
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();
}
示例#5
0
/*
 * Here we implement the process. The process is run whenever an event
 * occurs, and the parameters "ev" and "data" will we set to the event
 * type and any data that may be passed along with the event.
 */
PROCESS_THREAD(announce_process, ev, data)
{
  static struct uip_udp_conn *c;
  unsigned short sz = 0;
  uip_ipaddr_t addr;
  
  PROCESS_BEGIN();
  c = udp_broadcast_new(UIP_HTONS(4321), NULL);
  
   while(1) {

    
    // wake up periodically every second. 
    
    etimer_set(&timer, 4*CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));

    /*
     * To send a UDP packet request the uIP TCP/IP stack process call
     * us back with the buffer
     */
    tcpip_poll_udp(c);
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);

	uip_gethostaddr(&addr);
	// str = makebyte(addr->u8[0], str);
	
    // send our packet.
	sz = snprintf((char *)uip_appdata, uip_mss() - sz,
         "HELLO %s ETH %02x:%02x:%02x:%02x:%02x:%02x IP %d.%d.%d.%d RTC ",
         version,
         eth_mac_addr[0], eth_mac_addr[1], eth_mac_addr[2], 
         eth_mac_addr[3], eth_mac_addr[4], eth_mac_addr[5], 
		addr.u8[0],
		addr.u8[1],
		addr.u8[2],
		addr.u8[3]);
	sz += printRTCTime((char*) uip_appdata+sz );
	sz += snprintf((char *)uip_appdata+sz, uip_mss() - sz, "\n" );
	
    uip_send(uip_appdata, sz);

  }

  PROCESS_END();
}
示例#6
0
PROCESS_THREAD(test_receiver_process, ev, data)
{
  static struct uip_udp_conn *conn;

  PROCESS_BEGIN();

  conn = udp_broadcast_new(HTONS(PORT), NULL);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event && uip_newdata());
    leds_invert(LEDS_YELLOW);

    /* Make sure the message is null terminated */
    ((char *) uip_appdata)[uip_datalen()] = 0;
    printf("RECV: %s\n", (char *) uip_appdata);

  }
  PROCESS_END();
}
示例#7
0
文件: codeprop.c 项目: EDAyele/ptunes
/*---------------------------------------------------------------------*/
PROCESS_THREAD(codeprop_process, ev, data)
{
  PROCESS_BEGIN();
  
  s.id = 0/*random_rand()*/;
  
  send_time = CLOCK_SECOND/4;
  
  PT_INIT(&s.udpthread_pt);
  PT_INIT(&s.recv_udpthread_pt);
  
  tcp_listen(HTONS(CODEPROP_DATA_PORT));
  
  udp_conn = udp_broadcast_new(HTONS(CODEPROP_DATA_PORT), NULL);
  
  codeprop_event_quit = process_alloc_event();
  
  s.state = STATE_NONE;
  s.received = 0;
  s.addr = 0;
  s.len = 0;

  while(1) {

    PROCESS_YIELD();
  
    if(ev == EVENT_START_PROGRAM) {
      /* First kill old program. */
      elfloader_unload();
      elfloader_load(EEPROMFS_ADDR_CODEPROP);
    } else if(ev == tcpip_event) {
      uipcall(data);
    } else if(ev == PROCESS_EVENT_TIMER) {
      tcpip_poll_udp(udp_conn);
    }
  }

  PROCESS_END();
}
示例#8
0
文件: testuip.c 项目: 21moons/contiki
/*---------------------------------------------------------------------*/
PROCESS_THREAD(test_uip_process, ev, data)
{
    PROCESS_BEGIN();

    printf("uIP test process started\n");

    broadcast_conn = udp_broadcast_new(COOJA_PORT, NULL);
    button_sensor.configure(SENSORS_ACTIVE, 1);

    while(1) {
        PROCESS_WAIT_EVENT();
        printf("An event occured: ");

        if(ev == PROCESS_EVENT_EXIT) {
            printf("shutting down\n");
            break;
        }

        if(ev == sensors_event && data == &button_sensor) {
            printf("button clicked, sending packet\n");

            tcpip_poll_udp(broadcast_conn);
            PROCESS_WAIT_UNTIL(ev == tcpip_event && uip_poll());
            uip_send("cooyah COOJA", 12);
        } else if(ev == sensors_event) {
            printf("unknown sensor event: %s\n", ((struct sensors_sensor *)data)->type);
        } else if(ev == tcpip_event && uip_newdata()) {
            printf("a packet was received, toggling leds\n");
            printf("packet data: '%s'\n", (char*) uip_appdata);
            leds_toggle(LEDS_ALL);
        } else {
            printf("unknown event: %d\n", ev);
        }
    }

    PROCESS_END();
}
示例#9
0
/*---------------------------------------------------------------------*/
PROCESS_THREAD(codeprop_process, ev, data)
{
  PROCESS_BEGIN();

  elfloader_init();

  s.id = 0/*random_rand()*/;

  send_time = CLOCK_SECOND/4;

  PT_INIT(&s.udpthread_pt);
  PT_INIT(&s.recv_udpthread_pt);

  tcp_listen(HTONS(CODEPROP_DATA_PORT));

  udp_conn = udp_broadcast_new(HTONS(CODEPROP_DATA_PORT), NULL);

  s.state = STATE_NONE;
  s.received = 0;
  s.addr = 0;
  s.len = 0;

  fd = cfs_open("codeprop-image", CFS_READ | CFS_WRITE);

  while(1) {

    PROCESS_YIELD();

    if(ev == tcpip_event) {
      uipcall(data);
    } else if(ev == PROCESS_EVENT_TIMER) {
      tcpip_poll_udp(udp_conn);
    }
  }

  PROCESS_END();
}
示例#10
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(pinger, ev, data)
{
  static struct pt config_pt;
  
  PROCESS_BEGIN();

  pingeron = 0;
  
  conn = udp_broadcast_new(UIP_HTONS(PORT), NULL);
  
  PT_INIT(&config_pt);

  button_sensor.configure(SENSORS_ACTIVE, 1);
    
  
  while(1) {

    config_thread(&config_pt, ev, data);    
        
    PROCESS_WAIT_EVENT();

    printf("Event %d\n", ev);
    
    beep();
    
    if(ev == tcpip_event) {
      udp_appcall(data);
    }
    
    if(ev == PROCESS_EVENT_TIMER && etimer_expired(&etimer)) {
      tcpip_poll_udp(conn);
    }
   
  }
  
  PROCESS_END();
}
示例#11
0
/*
 * Here we implement the process. The process is run whenever an event
 * occurs, and the parameters "ev" and "data" will we set to the event
 * type and any data that may be passed along with the event.
 */
PROCESS_THREAD(example_program_process, ev, data)
{
  /*
   * Declare the UDP connection. Note that this *MUST* be declared
   * static, or otherwise the contents may be destroyed. The reason
   * for this is that the process runs as a protothread, and
   * protothreads do not support stack variables.
   */
  static struct uip_udp_conn *c;
  
  /*
   * A process thread starts with PROCESS_BEGIN() and ends with
   * PROCESS_END().
   */  
  PROCESS_BEGIN();

  /*
   * We create the UDP connection to port 4321. We don't want to
   * attach any special data to the connection, so we pass it a NULL
   * parameter.
   */
  c = udp_broadcast_new(HTONS(4321), NULL);
  
  /*
   * Loop for ever.
   */
  while(1) {

    /*
     * We set a timer that wakes us up once every second. 
     */
    etimer_set(&timer, CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));

    /*
     * Now, this is a the tricky bit: in order for us to send a UDP
     * packet, we must call upon the uIP TCP/IP stack process to call
     * us. (uIP works under the Hollywood principle: "Don't call us,
     * we'll call you".) We use the function tcpip_poll_udp() to tell
     * uIP to call us, and then we wait for the uIP event to come.
     */
    tcpip_poll_udp(c);
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);

    /*
     * We can now send our packet.
     */
    uip_send("Hello", 5);

    /*
     * We're done now, so we'll just loop again.
     */
  }

  /*
   * The process ends here. Even though our program sits is a while(1)
   * loop, we must put the PROCESS_END() at the end of the process, or
   * else the program won't compile.
   */
  PROCESS_END();
}
示例#12
0
  uip_ipaddr_copy(&rreq_addr, host);
  command = COMMAND_SEND_RREQ;
  process_post(&uaodv_process, PROCESS_EVENT_MSG, NULL);
  timer_set(&next_time, CLOCK_SECOND/8); /* Max 10/s per RFC3561. */
  return NULL;
}

PROCESS_THREAD(uaodv_process, ev, data)
{
  PROCESS_EXITHANDLER(goto exit);

  PROCESS_BEGIN();

  printf("uaodv_process starting %lu\n", (unsigned long) my_hseqno);

  bcastconn = udp_broadcast_new(UIP_HTONS(UAODV_UDPPORT), NULL);
  unicastconn = udp_broadcast_new(UIP_HTONS(UAODV_UDPPORT), NULL);
  
  while(1) {
    PROCESS_WAIT_EVENT();

    if(ev == tcpip_event) {
      if(uip_newdata()) {
	handle_incoming_packet();
	continue;
      }
      if(uip_poll()) {
	if(command == COMMAND_SEND_RREQ) {
	  if(uaodv_rt_lookup(&rreq_addr) == NULL)
	    send_rreq(&rreq_addr);
	} else if (command == COMMAND_SEND_RERR) {
/*---------------------------------------------------------------------------*/
struct rawpacket_conn *
rawpacket_setup(int id)
{
  return (struct rawpacket_conn *)udp_broadcast_new(UIP_HTONS(PORT + id), NULL);
}
示例#14
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();
}
PROCESS_THREAD(border_router_process, ev, data)
{
  static struct etimer et;
  rpl_dag_t *dag;

  PROCESS_BEGIN();
  prefix_set = 0;

  PROCESS_PAUSE();

  PRINTF("RPL-Border router started\n");

  slip_config_handle_arguments(contiki_argc, contiki_argv);

  /* tun init is also responsible for setting up the SLIP connection */
  tun_init();

  while(!mac_set) {
    etimer_set(&et, CLOCK_SECOND);
    request_mac();
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }

  if(slip_config_ipaddr != NULL) {
    uip_ipaddr_t prefix;

    if(uiplib_ipaddrconv((const char *)slip_config_ipaddr, &prefix)) {
      PRINTF("Setting prefix ");
      PRINT6ADDR(&prefix);
      PRINTF("\n");
      set_prefix_64(&prefix);
    } else {
      PRINTF("Parse error: %s\n", slip_config_ipaddr);
      exit(0);
    }
  }

  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)dag_id);
  if(dag != NULL) {
    rpl_set_prefix(dag, &prefix, 64);
    PRINTF("created a new RPL dag\n");
  }

#if DEBUG
  print_local_addresses();
#endif

  /* The border router runs with a 100% duty cycle in order to ensure high
     packet reception rates. */
  //NETSTACK_MAC.off(1);
  udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT), tcpip_handler);
  while(1) {
	PROCESS_YIELD();
        if(ev==tcpip_event)
        {	printf("Tcpip event\n");
                tcpip_handler();
        }	
    /* do anything here??? */
  }

  PROCESS_END();
}
示例#16
0
PROCESS_THREAD(udp_server_process, ev, data)
{
    static int distance_flag,i;
    static struct etimer reset_timer,rssi_wait;
    static unsigned char rbuf[20], *buf_p;

    PROCESS_BEGIN();

    distance_flag=0;
    create_dag();

    server_conn = udp_new(NULL, NULL, NULL);
    if(server_conn == NULL) {
        PRINTF("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
    udp_bind(server_conn, UIP_HTONS(2345));


    PRINTF(" local/remote port %u/%u\n", UIP_HTONS(server_conn->lport),
           UIP_HTONS(server_conn->rport));
    udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT), tcpip_handler);

    init_rssi();
    uip_ip6addr(&myip, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
    PRINTF("Listen port: 2345, TTL=%u\n", server_conn->ttl);
    etimer_set(&nw_settle_timer, (nwsettime + 4*Nodes_in_nw-20)* CLOCK_SECOND);//network setting time
    etimer_set(&addmyinfo_wait, 30 * CLOCK_SECOND);
    PROCESS_WAIT_UNTIL(etimer_expired(&addmyinfo_wait));
    addmyinfo();
    etimer_set(&reset_timer, (reset_time)*CLOCK_SECOND);
    


    while(1) {

        PROCESS_YIELD();
        if(rssi_stored==3 && monitor!=0)// if got 5 rssi value from parent or child
        {
            monitor=0;
            rssi_stored=0;

            buf_p=rbuf;
            MAPPER_ADD_PACKETDATA(buf_p,myip.u8[15]);
            MAPPER_ADD_PACKETDATA(buf_p,monitor_target);
            for(i=0; i<3; i++)
            {
                MAPPER_ADD_PACKETDATA(buf_p,mrssi[i]);
                printf("%d ",mrssi[i]);
            }
            printf("\n");
            if(current_victim[1]==myip.u8[15])
            {
                printf("Rssi stored\n");
                victim[1].id=myip.u8[15];
                victim[1].suspect=monitor_target;
                victim[1].mrssi=(int)(mrssi[0] + mrssi[1] + mrssi[2])/3;
                victim[1].is_rssi_stored=1;
                printf("snd rssi %d %u %u %d\n",5,myip.u8[15],monitor_target,victim[1].mrssi);
                monitor_target=0;
            }

        }
        if(ev==tcpip_event)
        {
            tcpip_handler();
        }

        if(rssi_timer_flag)
        {
            rssi_timer_flag=0;
            printf("Set rssi time using flag \n");
            etimer_set(&rssi_wait, rssi_wait_time*CLOCK_SECOND);
        }
        if(reset_timer_flag)
        {
            reset_timer_flag=0;
            printf("Reset time using flag \n");
            etimer_set(&reset_timer, reset_time*CLOCK_SECOND);
        }

        if(distance_flag==0 && etimer_expired(&nw_settle_timer))
        {        
            distance_flag=1;
            process_start(&distance_process, NULL);
        }
        if(rssi_flag==1 && etimer_expired(&rssi_wait))
        {
            rssi_flag=0;
            printf("Ready to process rssi\n");
            process_start(&postrssi_process, NULL);
        }

        if(etimer_expired(&reset_timer))
        {
            attack_processing=0;
            printf("Reset time expired %d %d\n",reset_time,rssi_wait_time);
            victim[0].id=victim[1].id=0;
            victim[0].is_rssi_stored=victim[1].is_rssi_stored=0;
            victim_count=0;
            current_victim[0]=0;
            current_victim[1]=0;

            monitor=0;
            monitor_target=0;
            last_target=0;
            suspect_c=0;
            suspect_send=0;

            etimer_set(&reset_timer, reset_time*CLOCK_SECOND);
            printf("Total nodes %d\n",total_nodes);
	    
	    chk_my_nbr();
	    node_to_v=1;
	    process_start(&validatepc_process, NULL);		
	    
            //for(i=0;i<total_nodes;i++)
            {
                //	printf("N %u x %d y %d p %u\n",nodes[i].id,nodes[i].x,nodes[i].y,nodes[i].parent_id);
            }
        }
    }

    PROCESS_END();
}