Esempio n. 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);
		}
	}
		
}
Esempio n. 2
0
//================================
static void
send_packet(void)
{

  static int seq_id;
  char buf[MAX_PAYLOAD_LEN];
  char buf2[MAX_PAYLOAD_LEN];

  seq_id++;
  PRINTF("DATA send to %d 'Hello %d'\n",
         client_conn->ripaddr.u8[15], seq_id);
  sprintf(buf, "Hello %d from ", seq_id);

sprintf(buf2, "Hello %d from %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", seq_id, ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[0], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[1], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[2], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[3], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[4], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[5], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[6], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[7], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[8], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[9], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[10], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[11], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[12], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[13], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[14], ((cyg_uint8 *)&uip_ds6_if.addr_list[1].ipaddr)[15]);
//=======
/*
char buf3[150];
uip_udp_packet_sendto(client_conn, buf3, 150,
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
*/
//========
 
    uip_udp_packet_sendto(client_conn, buf2, strlen(buf2),
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));

//printf("length = %i\n", strlen(buf2));

}
Esempio n. 3
0
TC_RUN_THREAD void server_thread()
{
    int i=0;
    for (i=0; i<sizeof(workers)/sizeof(worker_t); i++) {
        workers[i].busy = false;
    }

    ipconfig(false);

    struct uip_udp_conn* conn = udp_new(NULL, 0, NULL);
    udp_bind(conn, UDP_SERVER_PORT);

    while(1) {
        if (! tc_receive(&cond_server)) {
            for (i=0; i<sizeof(workers)/sizeof(worker_t); i++) {
                worker_t* worker = workers + i;
                if (worker->busy == false) {
                    worker->busy = true;
                    bool success = rpc_unmarshall_call(CALL, MAX_TELL_DEPTH, uip_appdata, uip_datalen());
                    ASSERT(success == true);
                    worker->peer = UIP_IP_BUF->srcipaddr;
                    tc_condition_signal(&worker->cond, NULL);
                    break;
                }
            }
            ASSERT(i != sizeof(workers)/sizeof(worker_t));
        } else {
            worker_t* worker = cond_server.data;
            worker->busy = false;
            int16_t size = rpc_marshall_response(RESPONSE, uip_appdata, UIP_BUFSIZE);
            ASSERT(size != -1);
            uip_udp_packet_sendto(conn, uip_appdata, size, &worker->peer, UDP_CLIENT_PORT);
        }
    }
}
Esempio n. 4
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");
} 
Esempio n. 5
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;
}
Esempio n. 6
0
void handle_call(worker_t* worker)
{
    printf("trace: "); rpc_print_call(CALL);
    if (0) { 
    } else if(CALL->function == RPC_TELL) {
        int16_t size = rpc_marshall_call(CALL->data.tell.call, uip_appdata, UIP_BUFSIZE);
        ASSERT(size != -1);
        uip_udp_packet_sendto(worker->conn, uip_appdata, size, &CALL->data.tell.peer, UDP_SERVER_PORT);
        do {
            tc_receive(NULL);
        } while (! uip_ipaddr_cmp(&UIP_IP_BUF->srcipaddr, &CALL->data.tell.peer));

        bool success = rpc_unmarshall_response(RESPONSE + 1, MAX_TELL_DEPTH - 1, uip_appdata, uip_datalen());
        ASSERT(success == true);
        rpc_response_tell(RESPONSE + 1, CALL, RESPONSE);
    } else if (CALL->function == RPC_READ_SLOW_SENSOR) {
        tc_sleep(clock_time() + SLOW_SENSOR_DELAY, NULL);
        rpc_response_read_slow_sensor(rand(), CALL, RESPONSE);
    } else if (CALL->function == RPC_READ_FAST_SENSOR) {
        rpc_response_read_fast_sensor(rand(), CALL, RESPONSE);
    } else {
        ASSERT(false);
    }
    
    printf("trace: "); rpc_print_response(RESPONSE);
}
Esempio n. 7
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);
}
Esempio n. 8
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
  //static int seq_id;
  static unsigned char seq_id=0,i=0; 
  
  
  
  seq_id++;
  //PRINTF("DATA send to %d 'Hello %d'\n",
    //    server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);
  //sprintf(buf, "Hello1 %d from the client", seq_id);
  //uip_udp_packet_sendto(client_conn, buf, strlen(buf),
    //                    &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));*/
  //buf[0] = seq_id;
  //buf[1] = seq_id >> 8;
 
  //clock_delay(1);	
	//for(i=2;i<78;i++)   
	  // printf("%d",buf[i]);
	for(i=2;i<20;i++)   
printf("\n==============================================\n");
 sprintf(buf, "at_kitchen_on %d",count);

  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
printf("packet sent\n");

}/*---------------------------------------------------------------------------*/
Esempio n. 9
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
  static int seq_id;
  char buf[MAX_PAYLOAD_LEN];
  int len = 0;
  
  seq_id++;

  len += snprintf((char *) &buf[len], sizeof(buf), "&: ");
  len += snprintf((char *) &buf[len], sizeof(buf), "V_MCU=%-d ", battery_sensor.value(0));

  /* 
   * Cooja needs to set a node_id. So we can skip sensor reading in case of simulation.
   */

  if(node_id == 0) {
    len += snprintf((char *) &buf[len], sizeof(buf), "T_MCU=%-d ", temp_mcu_sensor.value(0));
    len += snprintf((char *) &buf[len], sizeof(buf), "LIGHT=%-d ", light_sensor.value(0));
#ifdef CO2
    len += snprintf((char *) &buf[len], sizeof(buf), "CO2=%-d ", co2_sa_kxx_sensor.value(value));
#endif
  }
  PRINTF("TX %d to %d %s\n",
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id, buf);

  leds_on(LEDS_YELLOW);

  uip_udp_packet_sendto(client_conn, buf, strlen(buf),
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 10
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
  /*For send critical packets*/
  static int seq_id;
  struct {
    uint8_t instance_id;   //RPL_DEFAULT_INSTANCE
    uint8_t for_alignment;
    uint8_t seqno;
    uint8_t for_alignment1;
    char msg[MAX_PAYLOAD_LEN];
  } msg;

  memset(&msg, 0, sizeof(msg));
  seq_id++;
  if(seq_id == 0) {
    /* Wrap to 128 to identify restarts */
    seq_id = 128;
  }
  msg.instance_id = RPL_DEFAULT_INSTANCE ; 
  msg.seqno = seq_id ;
  sprintf(&msg.msg, "Hello %d", seq_id);
  
  printf ("msg send, %d, %d\n", msg.instance_id, msg.seqno);
  uip_udp_packet_sendto(client_conn, &msg, sizeof(msg),
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 11
0
char collectd_common_send(struct uip_udp_conn* client_conn,collectd_conf_t* collectd_conf){
	collectd_prepare_data();
	PRINTF("%s\n", buf);

	uip_udp_packet_sendto(client_conn, buf,
			blen, &collectd_conf->mnaddr, UIP_HTONS(collectd_conf->mnrport));

	return COLLECTD_ERROR_NO_ERROR;
}
Esempio n. 12
0
/*---------------------------------------------------------------------------*/
int
simple_udp_send(struct simple_udp_connection *c,
                const void *data, uint16_t datalen)
{
  if(c->udp_conn != NULL) {
    uip_udp_packet_sendto(c->udp_conn, data, datalen,
                          &c->remote_addr, UIP_HTONS(c->remote_port));
  }
  return 0;
}
Esempio n. 13
0
/*---------------------------------------------------------------------------*/
int
simple_udp_sendto_port(struct simple_udp_connection *c,
		       const void *data, uint16_t datalen,
		       const uip_ipaddr_t *to,
		       uint16_t port)
{
  if(c->udp_conn != NULL) {
    uip_udp_packet_sendto(c->udp_conn, data, datalen,
                          to, UIP_HTONS(port));
  }
  return 0;
}
Esempio n. 14
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
  static int seq_id;
  char buf[MAX_PAYLOAD_LEN];

  seq_id++;
  PRINTF("DATA send to %d 'Hello %d from %d'\n",
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id, rimeaddr_node_addr.u8[RIMEADDR_SIZE-1]);
  sprintf(buf, "Hello %d from the client %d", seq_id, rimeaddr_node_addr.u8[RIMEADDR_SIZE-1]);
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 15
0
static void
send_packet(void *ptr)
{
  static int seq_id;
  char buf[MAX_PAYLOAD_LEN];

  seq_id++;
  PRINTF("DATA send to %d 'Hello %d'\n",
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);
  sprintf(buf, "ACLL X: %d, Y:%d", adc_read(1), adc_read(2));
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 16
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
  static int seq_id;
  char buf[MAX_PAYLOAD_LEN];

  seq_id++;
  PRINTF("DATA send to %d 'Hello %d'\n",
         client_conn->ripaddr.u8[15], seq_id);
  sprintf(buf, "Hello %d from the client", seq_id);
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 17
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
//  static int seq_id;
  char buf[MAX_PAYLOAD_LEN];

  seq_id++;
 // seq++;
  printf("'Hello %d'\n", seq_id);
  sprintf(buf, "Hello %d from the client", seq_id);
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 18
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
	struct data_msg msg;
	static uint8_t seqno;
	uint16_t rank;
	uint16_t num_neighbors;

	rpl_dag_t *dag;

	memset(&msg,0,sizeof(msg));
	seqno++;
	msg.seqno = seqno;
	//linkaddr_copy(&parent, &linkaddr_null);

	/* Let's suppose we have only one instance */
	dag = rpl_get_any_dag();
	/*
	if(dag !=NULL) {
		preferred_parent = dag->preferred_parent;
		if(preferred_parent != NULL) {
			uip_ds6_nbr_t *nbr;
			nbr = uip_ds6_nbr_lookup(rpl_get_parent_ipaddr(preferred_parent));
			if(nbr !=NULL){
				/* USE parts of the IPV6 address as the parent address, in reversed byte order. */
/*		        parent.u8[LINKADDR_SIZE - 1] = nbr->ipaddr.u8[sizeof(uip_ipaddr_t) - 2];
		        parent.u8[LINKADDR_SIZE - 2] = nbr->ipaddr.u8[sizeof(uip_ipaddr_t) - 1];
		        parent_etx = rpl_get_parent_rank((uip_lladdr_t *) uip_ds6_nbr_get_ll(nbr)) / 2;
			}
		}
		*/
		rank = dag->rank;
		num_neighbors = uip_ds6_nbr_num();
	/*} else {
		rank = 0;
		num_neighbors = 0;
	}*/
	msg.len = sizeof(struct data_msg) / sizeof(uint16_t);
	msg.clock = clock_time();

	msg.rank = rank;
	msg.num_neighbors = num_neighbors;
	PRINTF("DATA send to %d: ",server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1]);
	PRINTF("seqno: %d, len: %d, clock: %u, rank: %d, num_neighbors: %d \n",
			msg.seqno,msg.len,msg.clock,msg.rank,msg.num_neighbors);

	//common_net_print();

	uip_udp_packet_sendto(client_conn, &msg, sizeof(msg),
	                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 19
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
  static int seq_id;
  char buf[MAX_PAYLOAD_LEN];

  seq_id++;
clock_time_t start_time = clock_time();
  PRINTF("DATA send to %d 'Msg %d'\n",
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);

  sprintf(buf, "%lu", (unsigned long)start_time);
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 20
0
/*---------------------------------------------------------------------------*/
int
udp_socket_sendto(struct net_buf *buf, struct udp_socket *c,
                  const void *data, uint16_t datalen,
                  const uip_ipaddr_t *to,
                  uint16_t port)
{
  if(c == NULL || c->udp_conn == NULL) {
    return -1;
  }

  if(c->udp_conn != NULL) {
    return uip_udp_packet_sendto(buf, c->udp_conn, data, datalen,
                          to, UIP_HTONS(port));
  }
  return -1;
}
Esempio n. 21
0
/*----------------------------------------------------------------------------*/
static void _demo_udp_sendMsg(uint32_t seqID)
{
	char 		pc_buf[MAX_S_PAYLOAD_LEN];
	int			i;
	i = sprintf(pc_buf, "%lu | ", seqID);
	if (seqID != 0)
		l_expSeqID++;
	LOG_INFO("Lost packets (%lu)\n\r", l_expSeqID - seqID);
    rpl_dag_t *dag = rpl_get_any_dag();
    if(dag && dag->instance->def_route) {
    	_demo_add_ipaddr(pc_buf + i, &dag->instance->def_route->ipaddr);
    } else {
      sprintf(pc_buf + i, "(null)");
    }
    LOG_INFO("Send message: %s\n\r",pc_buf);
	uip_udp_packet_sendto(pst_conn, pc_buf, strlen(pc_buf),&un_server_ipaddr,UIP_HTONS(__SERVER_PORT));
} /* _demo_udp_sendMsg */
Esempio n. 22
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]);
    }
}
Esempio n. 23
0
/*---------------------------------------------------------------------------*/
void ntp_client_send(struct uip_udp_conn *udpconn, uip_ipaddr_t srv_ipaddr, struct ntp_msg clientmsg)
{
	clientmsg.status = MODE_CLIENT | (NTP_VERSION << 3) | LI_ALARM;

	clock_get_time(&ts);
	//TODO: could be in danger when timer change!
	clientmsg.xmttime.int_partl = uip_htonl(ts.sec + JAN_1970);
	clientmsg.xmttime.fractionl = uip_htonl(ts.nsec);

	uip_udp_packet_sendto(udpconn, &clientmsg, sizeof(struct ntp_msg),
			&srv_ipaddr, UIP_HTONS(SERVER_PORT));
	PRINTF("Sent timestamp: %ld sec %ld nsec to ", ts.sec, ts.nsec);
#ifdef UIP_CONF_IPV6
	PRINT6ADDR(&udpconn->ripaddr);
#else
	PRINTLLADDR(&udpconn->ripaddr);
#endif /* UIP_CONF_IPV6 */
	PRINTF("\n");
}
Esempio n. 24
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
  static int seq_id;
  char buf[MAX_PAYLOAD_LEN];
  uint8_t data_ptr = 0;
  uint8_t data_len = 33;

  seq_id++;
  PRINTF("DATA send to %d 'Hello %d'\n",
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);
  //sprintf(&buf[data_ptr], "Hello %d from the", seq_id);
  sprintf(&buf[data_ptr], "XXXXXXXXOOOOOOOOXXXXXXXXOOOOOOOO%d", seq_id);

  	uint8_t i;
    PRINTF("before: ");
    for(i=0; i<data_len; i++) PRINTF("%.2x",buf[i]);
    PRINTF("\n");

  //data_ptr = keymanagement_creat_encrypted_packet(client_conn, (uint8_t *)buf, &data_len);
  //PRINTF("result: %d\n", data_ptr);
//
//  result = cc2420_encrypt_ccm((uint8_t *)buf, 24);
//  if(!result) PRINTF("Encryption failed: busy!\n");
//  else {
//	  //PRINTF("result: ");
//	  //for(i=0; i<35; i++) PRINTF("%.2x",(uint8_t)buf[i]);
//	  //PRINTF("\n");
//  }
//
//  uint32_t test = 0;
//  uint8_t test2 = 2;
//  result = cc2420_decrypt_ccm((uint8_t *)buf, &test, &test2, 34);
//  if(!result) PRINTF("Encryption failed: busy!\n");
//  else {
//	  //PRINTF("result: ");
//	  //for(i=0; i<35; i++) PRINTF("%.2x",(uint8_t)buf[i]);
//	  //PRINTF("\n");
//  }
  uip_udp_packet_sendto(client_conn, &buf[data_ptr], 26,
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 25
0
/*---------------------------------------------------------------------------*/
void 
broadcast_identity(int id)
{
  /* Broadcast its own region rank */
  uip_ipaddr_t addr;

  identity_pkt_t ipkt;
  ipkt.type = 2;
  ipkt.id = id;

  /* Will be dynamic based on the packet transmission with the parent */
  ipkt.loc_addr[0] = sender_id;
  ipkt.loc_addr[1] = 0;
  ipkt.loc_addr[2] = 0;
  ipkt.loc_addr[3] = 0;

  uip_create_linklocal_allnodes_mcast(&addr);
  uip_udp_packet_sendto(server_conn, &ipkt, sizeof(ipkt),
                        &addr, UIP_HTONS(UDP_CLIENT_PORT));
}
Esempio n. 26
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));
}
Esempio n. 27
0
/*---------------------------------------------------------------------------*/
void client_send(void) {
	static uint8_t seqno;
	struct {
		uint8_t seqno;
		uint8_t resID;
		uint8_t numReq;
		uint8_t for_alignment;
		uint32_t senderlastRX;
		uint32_t senderlastTX;
		uint8_t padding[18];

	} msg;

	if (client_conn == NULL) {
		/* Not setup yet */
		return;
	}
	memset(&msg, 0, sizeof(msg));
	seqno++;
	if (seqno == 0) {
		/* Wrap to 128 to identify restarts */
		seqno = 128;
	}
	msg.seqno = seqno;
	msg.resID = nodeInf.resID;
	msg.numReq = nodeInf.numReq;

	//Get the time before sending response
	uint32_t time = get_time_ms();
	msg.senderlastRX = nodeInf.senderlastRX;
	msg.senderlastTX = time;
	nodeInf.senderlastTX = time;
	printf("TX-RX: %u\n", time - msg.senderlastRX);
	printf("TX: Time : %lu resID: %u numReq: %u sizeof %u\n", time, msg.resID,
			msg.numReq, sizeof(msg));
	printf("seqno %u\n", seqno);

	uip_udp_packet_sendto(client_conn, &msg, sizeof(msg), &server_ipaddr,
			UIP_HTONS(UDP_SERVER_PORT));
}
Esempio n. 28
0
/*---------------------------------------------------------------------------*/
static void
send_packet(void *ptr)
{
  static int seq_id;
  char buf[MAX_PAYLOAD_LEN];

  seq_id++;
  PRINTF("DATA send to %d Hello %d\n",
           server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);
    sprintf(buf, "Hello %d from the client", seq_id);
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),
                        &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
  /*
   * Every time we send a packet, we check if there was DATA received
   * TODO: This must be changed into the core system.
   */
  /*if(NO_DATA == 1 && mobility_flag == 0 && hand_off_backoff_flag == 0) {
    test_unreachable = 1;
    printf("starting mobility process because no DATA was detected\n");
    process_post(&unreach_process, PARENT_UNREACHABLE, NULL);
  }*/
}
Esempio n. 29
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",
           UDP_IP_BUF->srcipaddr.u8[sizeof(UDP_IP_BUF->srcipaddr.u8) - 1]);
    PRINTF("\n");
#if SERVER_REPLY
    PRINTF("DATA sending reply\n");
    //uip_ipaddr_copy(&server_conn->ripaddr, &UDP_IP_BUF->srcipaddr);
    //server_conn->rport = UDP_IP_BUF->srcport;
    //uip_udp_packet_send(server_conn, appdata,uip_datalen() );
    uip_udp_packet_sendto(server_conn, appdata,uip_datalen(),&UDP_IP_BUF->srcipaddr, UDP_IP_BUF->srcport);
    //uip_create_unspecified(&server_conn->ripaddr);
#endif
  }
}
Esempio n. 30
0
File: app.c Progetto: copton/ocram
PROCESS_THREAD(send_process, ev, data)
{
    static struct etimer periodic;
    static uip_ipaddr_t server_ipaddr;
    static struct uip_udp_conn* client_conn;

    PROCESS_BEGIN();

    init();
    
    uip_ip6addr(&server_ipaddr, 0xfe80, 0, 0, 0, 0x212, 0x7403, 0x3, 0x303);
    client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); 
    udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); 

    etimer_set(&periodic, DT_SEND);
    while(1) {
        PROCESS_YIELD();
        if (etimer_expired(&periodic)) {
            etimer_reset(&periodic);
            uint32_t buf[2] = {0xFFFFFFFF, 0};
            size_t i;

            for (i = 0; i<offset; i++) {
                if (values[i] < buf[0]) {
                    buf[0] = values[i];
                }
                if (values[i] > buf[1]) {
                    buf[1] = values[i];
                }
            }
            offset = 0;

            printf("trace: send values: %lu %lu\n", buf[0], buf[1]);
            uip_udp_packet_sendto(client_conn, &buf[0], sizeof(buf), &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));
        }
    }

    PROCESS_END();
}