Beispiel #1
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(UIP_HTONS(CODEPROP_DATA_PORT));

  udp_conn = udp_broadcast_new(UIP_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();
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
#if UIP_CONF_ROUTER
  uip_ipaddr_t ipaddr;
#endif /* UIP_CONF_ROUTER */

  PROCESS_BEGIN();
  PRINTF("UDP server started\n");

#if RESOLV_CONF_SUPPORTS_MDNS
  resolv_set_hostname("contiki-udp-server");
#endif

#if UIP_CONF_ROUTER
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
#endif /* UIP_CONF_ROUTER */

  print_local_addresses();

#if SERVER_RPL_ROOT
  create_dag();
#endif
  server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
  udp_bind(server_conn, UIP_HTONS(3000));
PRINTF("Listen port: 3000, TTL=%u\n\r", server_conn->ttl);

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Beispiel #3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
#if UIP_CONF_ROUTER
  uip_ipaddr_t ipaddr;
#endif /* UIP_CONF_ROUTER */

  PROCESS_BEGIN();
  PRINTF("UDP server started\n");

#if RESOLV_CONF_SUPPORTS_MDNS
  resolv_set_hostname("con-serv");

#if RESOLV_CONF_SUPPORTS_DNS_SD
  resolv_add_service("_server._udp", "status=avail", 3000);
#endif /* RESOLV_CONF_SUPPORTS_DNS_SD */
#endif

#if UIP_CONF_ROUTER
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
#endif /* UIP_CONF_ROUTER */

  print_local_addresses();

  server_conn = udp_new(NULL, UIP_HTONS(3001), NULL);
  udp_bind(server_conn, UIP_HTONS(3000));

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Beispiel #4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et;
  uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();
  PRINTF("UDP client process started\n");

  uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0x0215, 0x2000, 0x0002, 0x2145);
  /* new connection with remote host */
  l_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
  if(!l_conn) {
    PRINTF("udp_new l_conn error.\n");
  }
  udp_bind(l_conn, UIP_HTONS(LOCAL_CONN_PORT));

  PRINTF("Link-Local connection with ");
  PRINT6ADDR(&l_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
         UIP_HTONS(l_conn->lport), UIP_HTONS(l_conn->rport));

  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0x0215, 0x2000, 0x0002, 0x2145);
  g_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
  if(!g_conn) {
    PRINTF("udp_new g_conn error.\n");
  }
  udp_bind(g_conn, UIP_HTONS(GLOBAL_CONN_PORT));

  PRINTF("Global connection with ");
  PRINT6ADDR(&g_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
         UIP_HTONS(g_conn->lport), UIP_HTONS(g_conn->rport));

  etimer_set(&et, SEND_INTERVAL);

  while(1) {
    PROCESS_YIELD();
    if(etimer_expired(&et)) {
      timeout_handler();
      etimer_restart(&et);
    } else if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Beispiel #5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(fixed_process, ev, data)
{
  static struct etimer et;
  static uip_ipaddr_t ipaddr;
  PROCESS_BEGIN();

  conn = udp_new(NULL, UIP_HTONS(0), NULL);
  udp_bind(conn, UIP_HTONS(3000));
  memset(history,0,sizeof(history));

  etimer_set(&et, SEND_INTERVAL);
  cur_time = 1;
  while(1) {
    PROCESS_YIELD();
    if(etimer_expired(&et)) {
      timeout_handler();
      etimer_restart(&et);
    } else if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Beispiel #6
0
/*--------------------------------------------------------------------------------------------*/
 void tcpip_handler(struct udp_tx *udp_tx_info){
	 if(uip_newdata()){
		 ((char *)uip_appdata)[uip_datalen()] = 0;
		 		PRINTF("Server received: '%s' from [", (char *)uip_appdata);
		 		PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
		 		PRINTF("]:%u",UIP_HTONS(UIP_UDP_BUF->srcport));
		 		PRINTF("\n");
		 		uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
		 		server_conn->rport=uip_htons(3007);

		 		PRINTF("Responding with message: ");

		 		udp_data_handler(uip_appdata,udp_tx_info);
	 }
 }
PROCESS_THREAD(coap_app_client, ev, data)
{
  PROCESS_BEGIN();

  uip_ip6addr_u8(&server_ipaddr,0xfe,0x80,0,0,0,0,0,0,0xc0,0xa0,0x08,0x39,0xd1,0xe4,0x02,0x05);
  /* new connection with server */
  client_conn = udp_new(&server_ipaddr, UIP_HTONS(REMOTE_PORT), NULL);
  udp_bind(client_conn, UIP_HTONS(LOCAL_PORT));

 // UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

  while(1) {
    PROCESS_YIELD();
    if (ev == PROCESS_EVENT_CONTINUE) { 
      send_data();
    } else if (ev == tcpip_event) {
    	sprintf(outStr_buf,"\r\nPacket received\r\n\r\n");
		sendData_inBackground((uint8_t*)outStr_buf,strlen(outStr_buf),1,0);
      //handle_incoming_data();
    }
  }

  PROCESS_END();
}
Beispiel #8
0
/*---------------------------------------------------------------------------*/
int
udp_socket_connect(struct udp_socket *c,
                   uip_ipaddr_t *remote_addr,
                   uint16_t remote_port)
{
  if(c == NULL || c->udp_conn == NULL) {
    return -1;
  }

  if(remote_addr != NULL) {
    uip_ipaddr_copy(&c->udp_conn->ripaddr, remote_addr);
  }
  c->udp_conn->rport = UIP_HTONS(remote_port);
  return 1;
}
Beispiel #9
0
PROCESS_THREAD(httpd_process, ev, data)
{
  PROCESS_BEGIN();

  tcp_listen(UIP_HTONS(nvm_data.webserver_port));
  LOG6LBR_INFO("Starting webserver on port %d\n", nvm_data.webserver_port);
  memb_init(&conns);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    httpd_appcall(data);
  }

  PROCESS_END();
}
Beispiel #10
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));
}
Beispiel #11
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;
}
Beispiel #12
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();
}
Beispiel #13
0
bool TCPIP_Connect(void)
{
	// Connect to the remote machine (www.example.com)
	uip_ipaddr(&RemoteIPAddress, 192, 0, 32, 10);	
	TCPConnection = uip_connect(&RemoteIPAddress, UIP_HTONS(80));

	if (TCPConnection != NULL)
	{
		Debug_Print("Connecting to host\r\n");
		return true;
	}
	else
	{
		Debug_Print("Failed to Connect\r\n");
		return false;
	}
}
Beispiel #14
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 */
Beispiel #15
0
void send_actuator_command(int channelID){
	ChannelState * state = get_channel_state(channelID);
	if (state == NULL){
		printf("Device disconnected\n");
		return;
	}
	DataPayload *new_dp = &(state->packet);
	clean_packet(new_dp);
	new_dp->hdr.cmd = CMD;
	new_dp->hdr.src_chan_num = state->chan_num;
	new_dp->hdr.dst_chan_num = state->remote_chan_num;
	new_dp->dhdr.tlen = UIP_HTONS(0);
	send_on_knot_channel(state, new_dp);
	state->ticks = 10;
	state->state = STATE_COMMANDED;

}
Beispiel #16
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ntpd_process, ev, data)
{
  static struct etimer et;
  static uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();
  PRINTF("ntpd process started\n");

  set_connection_address(&ipaddr);

  /* find the IP of router */
  //etimer_set(&et, CLOCK_SECOND);
  //while(1){
  //  if(uip_ds6_defrt_choose()){
  //    uip_ipaddr_copy(&ipaddr, uip_ds6_defrt_choose());
  //    break;
  //  }
  //  etimer_set(&et, CLOCK_SECOND);
  //  PROCESS_YIELD_UNTIL(etimer_expired(&et));
  //}

  /* new connection with remote host */
  ntp_conn = udp_new(&ipaddr, UIP_HTONS(NTPD_PORT), NULL);

  etimer_set(&et, SEND_INTERVAL * CLOCK_SECOND);
  while(1) {
    PROCESS_YIELD();
    if(etimer_expired(&et)) {
      timeout_handler();
      
      if((clock_seconds() > 4294967290U) || (clock_seconds() < 20)){
	SEND_INTERVAL = 2 * CLOCK_SECOND;
	etimer_set(&et, SEND_INTERVAL);
      } else {
	if(SEND_INTERVAL <= 512 && (getCurrTime() != 0)) {
	  SEND_INTERVAL = 2 * SEND_INTERVAL;
	}
	etimer_set(&et, SEND_INTERVAL * CLOCK_SECOND);
      }
    } else if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Beispiel #17
0
/* --------------------------------------------------------------- */
static void input_handler(char* input)
{
    // If we haven't be able to reach the DAG RPL Router give error
    if (uip_ds6_get_global(ADDR_PREFERRED) == NULL) {
        printf("E02\n");
        return;
    }

    // Send the data with magic
    uip_udp_packet_send(conn, input, strlen(input));

    // Debug messages
    PRINTF("# %s\n", input);
    PRINTF("# Sent %u bytes to [", strlen(input));
    PRINT6ADDR(&conn->ripaddr);
    PRINTF("]:%u\n", UIP_HTONS(conn->rport));
}
Beispiel #18
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]);
    }
}
Beispiel #19
0
/*---------------------------------------------------------------------------*/
int
coap_context_connect(coap_context_t *coap_ctx, uip_ipaddr_t *addr, uint16_t port)
{
  session_t session;

  if(coap_ctx == NULL || coap_ctx->is_used == 0) {
    return 0;
  }

#ifdef NETSTACK_CONF_WITH_IPV6
  memcpy(&coap_ctx->addr.in6_addr, addr, sizeof(coap_ctx->addr.in6_addr));
  coap_ctx->addr.family = AF_INET6;
#else
  memcpy(&coap_ctx->addr.in_addr, addr, sizeof(coap_ctx->addr.in_addr));
  coap_ctx->addr.family = AF_INET;
#endif
  coap_ctx->port = port;

  coap_ctx->net_ctx = net_context_get(IPPROTO_UDP,
				      (const struct net_addr *)&coap_ctx->addr,
				      coap_ctx->port,
				      (const struct net_addr *)&coap_ctx->my_addr,
				      coap_ctx->my_port);
  if (!coap_ctx->net_ctx) {
    PRINTF("%s: Cannot get network context\n", __FUNCTION__);
    return 0;
  }

  uip_ipaddr_copy(&session.addr.ipaddr, addr);
  session.addr.port = UIP_HTONS(port);
  session.size = sizeof(session.addr);
  session.ifindex = 1;
  coap_ctx->status = STATUS_CONNECTING;
  PRINTF("coap-context: DTLS CONNECT TO [");
  PRINT6ADDR(addr);
  PRINTF("]:%u\n", uip_ntohs(port));
  if(dtls_connect(coap_ctx->dtls_context, &session) >= 0) {
    return 1;
  }

  /* Failed to initiate connection */
  coap_ctx->status = STATUS_ALERT;
  return 0;
}
Beispiel #20
0
/*---------------------------------------------------------------------------*/
void
eth_drv_input(uint8_t *packet, uint16_t len)
{
  LOG6LBR_PRINTF(PACKET, ETH_IN, "read: %d\n", len);
  LOG6LBR_DUMP_PACKET(ETH_IN, packet, len);

#if CETIC_6LBR_IP64
  if((nvm_data.global_flags & CETIC_GLOBAL_IP64) != 0 &&
      (((struct uip_eth_hdr *)packet)->type != UIP_HTONS(UIP_ETHTYPE_IPV6))) {
    IP64_INPUT(packet, len);
  } else {
#endif
    uip_len = len - UIP_LLH_LEN;
    memcpy(uip_buf, packet, len);
    eth_input();
#if CETIC_6LBR_IP64
  }
#endif
}
Beispiel #21
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");
}
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(ctk_vncserver_process, ev, data)
{
  int i;
  
  PROCESS_BEGIN();

  tcp_listen(UIP_HTONS(5900));
  
  for(i = 0; i < CTK_VNCSERVER_CONF_NUMCONNS; ++i) {
    conns[i].state = VNC_DEALLOCATED;
  }
  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == tcpip_event) {
      ctk_vncserver_appcall(data);
    }
  }
  PROCESS_END();
}
Beispiel #23
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));
}
Beispiel #24
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tcpEcho_process, ev, data)
{

  PROCESS_BEGIN();

  /* Listen for a connection on local port */
  tcp_listen(UIP_HTONS(local_port));
  while (1)
  {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    /* If there is new uIP data, display it */
    if(uip_newdata()) {
      /* Add the end of string. */
      ((char *)uip_appdata)[uip_datalen()] = 0;
      printf("New uIP data: '%s'\n", uip_appdata);
    }
  }

  PROCESS_END();
}
Beispiel #25
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\n", UIP_HTONS(UIP_UDP_BUF->srcport));
    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;
  }
  leds_off(LEDS_RED);
  return;
}
Beispiel #26
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));
}
Beispiel #27
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));
}
Beispiel #28
0
static uint8_t network_send_tcpip(uip_lladdr_t *lladdr) {
	if (lladdr == NULL) {
		(&BUF->dest)->addr[0] = 0x33;
		(&BUF->dest)->addr[1] = 0x33;
		(&BUF->dest)->addr[2] = IPBUF->destipaddr.u8[12];
		(&BUF->dest)->addr[3] = IPBUF->destipaddr.u8[13];
		(&BUF->dest)->addr[4] = IPBUF->destipaddr.u8[14];
		(&BUF->dest)->addr[5] = IPBUF->destipaddr.u8[15];
	}
	else {
		memcpy(&BUF->dest, lladdr, UIP_LLADDR_LEN);
	}
	memcpy(&BUF->src, &uip_lladdr, UIP_LLADDR_LEN);
	BUF->type = UIP_HTONS(UIP_ETHTYPE_IPV6);
	uip_len += sizeof(struct uip_eth_hdr);

	network_send();

	return 0;
}
Beispiel #29
0
/*---------------------------------------------------------------------*/
static
PT_THREAD(send_udpthread(struct pt *pt))
{
  int len;
  struct codeprop_udphdr *uh = (struct codeprop_udphdr *)uip_appdata;


  PT_BEGIN(pt);

  while(1) {
    PT_WAIT_UNTIL(pt, s.state == STATE_SENDING_UDPDATA);

    for(s.addr = 0; s.addr < s.len; ) {
      len = send_udpdata(uh);
      s.addr += len;

      etimer_set(&s.sendtimer, CLOCK_SECOND/4);
      do {
	PT_WAIT_UNTIL(pt, uip_newdata() || etimer_expired(&s.sendtimer));

	if(uip_newdata()) {
	  if(uh->type == UIP_HTONS(TYPE_NACK)) {
	    PRINTF(("send_udpthread: got NACK for address 0x%x (now 0x%x)\n",
		    uip_htons(uh->addr), s.addr));
	    /* Only accept a NACK if it points to a lower byte. */
	    if(uip_htons(uh->addr) <= s.addr) {
	      /*	      beep();*/
	      s.addr = uip_htons(uh->addr);
	    }
	  }
	  PT_YIELD(pt);
	}
      } while(!etimer_expired(&s.sendtimer));
    }

    s.state = STATE_NONE;

/*     process_post(PROCESS_BROADCAST, codeprop_event_quit, (process_data_t)NULL); */
  }
  PT_END(pt);
}
Beispiel #30
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));
}