Esempio n. 1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udpstream_process, ev, data)
{
  static uint16_t streamno;
  static struct etimer et;
  static uip_ipaddr_t *ipaddr;

  PROCESS_BEGIN();
  PROCESS_PAUSE();

  printf("Formatting Coffee FS...\n");
  cfs_coffee_format();
  printf("done.\n");
  /* We need re-initialize queuebuf after formatting */
  queuebuf_init();

  /* Start service registration */
  servreg_hack_init();
  ipaddr = set_global_address();

  if(node_id == SINK_ID) {
    /* The sink creates a dag and waits for UDP datagrams */
    create_rpl_dag(ipaddr);
    servreg_hack_register(SERVICE_ID, ipaddr);
    simple_udp_register(&unicast_connection, UDP_PORT,
                        NULL, UDP_PORT, receiver);
    while(1) {
      PROCESS_WAIT_EVENT();
    }
  } else if(node_id == SENDER_ID) {
    /* The sender looks for the sink and sends UDP streams */
    ipaddr = NULL;
    simple_udp_register(&unicast_connection, UDP_PORT,
                          NULL, UDP_PORT, receiver);

    etimer_set(&et, 10*CLOCK_SECOND);
    etimer_restart(&et);

    while(1) {
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
      if(ipaddr != NULL) {
        streamno++;
        send_stream(ipaddr, streamno);
      } else {
        ipaddr = servreg_hack_lookup(SERVICE_ID);
        if(ipaddr != NULL) {
          etimer_set(&et, 2*CLOCK_SECOND);
          printf("Streaming to ");
          uip_debug_ipaddr_print(ipaddr);
          printf("\n");
        } else {
          printf("Service %d not found\n", SERVICE_ID);
        }
      }
      etimer_restart(&et);
    }
  }

  PROCESS_END();
}
Esempio n. 2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(otau_client_process, ev, data)
{
  static struct etimer server_timer;
  uip_ip6addr_t *srv_addr;
  
  PROCESS_BEGIN();
  servreg_hack_init();
  set_global_address();
  
  ota_mgr_init();
  
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);
  etimer_set(&server_timer, SEND_INTERVAL);					  

  while(1) {
	PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&server_timer));
	srv_addr = servreg_hack_lookup(SERVICE_ID);
	if(srv_addr != NULL) {
		printf("Server address configured\r\n");
		server_configured =1;
		configure_server_details(srv_addr);
		memcpy((uint8_t *)&(global_server_addr.u16[4]),&(srv_addr->u16[4]),NATIVE_ADDR_SIZE);
        //uip_create_linklocal_allnodes_mcast(srv_addr);
		etimer_stop(&server_timer);
	}
	else
	{
		etimer_reset(&server_timer);
		printf("server not found\r\n");
	}
  }
  PROCESS_END();
}
Esempio n. 3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(receiver_node_process, ev, data)
{
  static struct etimer et;
  static struct uip_ds6_notification n;
  uip_ipaddr_t *ipaddr;

  PROCESS_BEGIN();

  ipaddr = set_global_address();

  uip_ds6_notification_add(&n, route_callback);

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  etimer_set(&et, CLOCK_SECOND);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    etimer_reset(&et);
    if(should_blink) {
      leds_on(LEDS_ALL);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
      etimer_reset(&et);
      leds_off(LEDS_ALL);
    }
  }
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(broadcast_example_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t addr;

  PROCESS_BEGIN();

  simple_udp_register(&broadcast_connection, UDP_PORT,
                      NULL, UDP_PORT,
                      receiver);

  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("Jamming\n");
    uip_create_linklocal_allnodes_mcast(&addr);
    simple_udp_sendto(&broadcast_connection, "jamming", 7, &addr);
  }

  PROCESS_END();
}
Esempio n. 5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t global_ipaddr;

  PROCESS_BEGIN();


  random_rand();
  rpl_log_start();
  if(node_id ==0) {
    NETSTACK_RDC.off(0);
    uint16_t mymac = linkaddr_node_addr.u8[7] << 8 | linkaddr_node_addr.u8[6];
    printf("Node id unset, my mac is 0x%04x\n", mymac);
    PROCESS_EXIT();
  }

  cc2420_set_txpower(RF_POWER);
  cc2420_set_cca_threshold(RSSI_THR);
  printf("App: %u starting\n", node_id);

  deployment_init(&global_ipaddr);
  //rpl_setup(node_id == ROOT_ID, node_id);
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  if(node_id == ROOT_ID) {
    uip_ipaddr_t my_ipaddr;
    set_ipaddr_from_id(&my_ipaddr, node_id);
    //NETSTACK_RDC.off(1);
  }
  else {
    etimer_set(&periodic_timer,1 * 30 * CLOCK_SECOND);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_set(&periodic_timer, SEND_INTERVAL);


    while(1) {

      etimer_set(&send_timer, random_rand() % (SEND_INTERVAL));

      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
      int rank = default_instance != NULL ? default_instance->current_dag->rank : 0xffff;
     if(rank != 0xffff){
      app_send_to(ROOT_ID);
      }
      else{
        printf("App: not in DODAG\n");
      }

      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
      etimer_reset(&periodic_timer);

    }
  }

  PROCESS_END();
}
Esempio n. 6
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{

//  uint16_t ipaddr=(uint16_t) IP_TRANS128;
//#if UIP_CONF_ROUTER
  uip_ipaddr_t ipaddr;//=IP_TRANS128;
  uip_ip6addr(&ipaddr,0xfe80,0,0,0,0x2001,0x22ff,0xfe33,0x4455);
//#endif /* UIP_CONF_ROUTER */

  PROCESS_BEGIN();



  SENSORS_ACTIVATE(button_sensor);//activate button
  leds_init();
  leds_off(LEDS_ALL);
  simple_udp_register(&udp_connection, UDP_PORT, NULL, UDP_PORT, receiver);


  while(1) {
//	  printf("bla1");
   PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);
  // PROCESS_YIELD();
   send_data(&ipaddr);
    
  }

  PROCESS_END();
}
Esempio n. 7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;

  PROCESS_BEGIN();

  if(node_id == 0) {
    NETSTACK_RDC.off(0);
    uint16_t mymac = rimeaddr_node_addr.u8[7] << 8 | rimeaddr_node_addr.u8[6];
    printf("Node id unset, my mac is 0x%04x\n", mymac);
    PROCESS_EXIT();
  }

  random_rand();
  simple_energest_start();

  anycast_init(node_id == ROOT_ID);
  rpl_setup(node_id == ROOT_ID, node_id);
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  if(node_id == ROOT_ID) {
    NETSTACK_RDC.off(1);

    printf("App: %u starting\n", node_id);
    etimer_set(&periodic_timer, SEND_INTERVAL);
    while(1) {
      if(check_reachable_count()) {
        uip_ipaddr_t dest_ipaddr;
        int id;
        do {
          id = get_random_id();
          node_ip6addr(&dest_ipaddr, id);
        } while (id == ROOT_ID || !is_in_subdodag(&dest_ipaddr));
        app_send_to(id);
      }

      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
      etimer_reset(&periodic_timer);
    }
  } else if(has_outage()) {
    etimer_set(&periodic_timer, OUTAGE_TIME_BEFORE);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    while(1) {
      printf("App: %u start outage\n", node_id);
      NETSTACK_RDC.off(0);
      etimer_set(&periodic_timer, OUTAGE_DURATION);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
      printf("App: %u stop outage\n", node_id);
      NETSTACK_RDC.on();
      etimer_set(&periodic_timer, OUTAGE_TIME_BETWEEN);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    }
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;

  uip_ipaddr_t *addr;

  PROCESS_BEGIN();

  SENSORS_ACTIVATE(button_sensor);
 // SENSORS_ACTIVATE(light_sensor);

  servreg_hack_init();

  set_global_address();

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  //etimer_set(&periodic_timer, SEND_INTERVAL);
  while(1) {

   // PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);
   // etimer_reset(&periodic_timer);
    etimer_set(&send_timer, SEND_TIME);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
    addr = servreg_hack_lookup(SERVICE_ID);

    if(addr != NULL) {
      static unsigned int button_number;
      char buf[50];

      if(button_number == 0) {
	button_number = 1;
	leds_toggle(LEDS_ALL);
      } else {
	button_number = 0;
	leds_toggle(LEDS_ALL);
      }

      printf("Sending unicast to ");
      uip_debug_ipaddr_print(addr);
      printf("\n");

      //sprintf(buf, "Occupancy Detector: %d, Luminaire Illuminance: %d", button_number, LUMINAIRE_ILLUMINANCE);
      sprintf(buf, "Occupancy Detector: %d, Luminaire Illuminance: %d", button_number, (int)(410 ));      

      simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, addr);
    } else {
      printf("Service %d not found\n", SERVICE_ID);
    }
  }

  PROCESS_END();
}
Esempio n. 9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t global_ipaddr;

  PROCESS_BEGIN();

  if(node_id == 0) {
    NETSTACK_RDC.off(0);
    printf("Node id unset, my mac is ");
    uip_debug_lladdr_print(&rimeaddr_node_addr);
    printf("\n");
    PROCESS_EXIT();
  }

  cc2420_set_txpower(RF_POWER);
  cc2420_set_cca_threshold(RSSI_THR);
  orpl_log_start();

  printf("App: %u starting\n", node_id);

  deployment_init(&global_ipaddr);
#if WITH_ORPL
  orpl_init(node_id == ROOT_ID, 0);
#endif /* WITH_ORPL */
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  if(node_id == ROOT_ID) {
    NETSTACK_RDC.off(1);
    etimer_set(&periodic_timer, 2 * 60 * CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_set(&periodic_timer, SEND_INTERVAL);
    while(1) {
      etimer_set(&send_timer, random_rand() % (SEND_INTERVAL));
      PROCESS_WAIT_UNTIL(etimer_expired(&send_timer));

      if(check_reachable_count()) {
        uip_ipaddr_t dest_ipaddr;
        static uint16_t target_id;
        static uint16_t i;
        do {
          target_id = get_node_id_from_index((random_rand()>>8)%get_n_nodes());
          set_ipaddr_from_id(&dest_ipaddr, target_id);
        } while (target_id == ROOT_ID || !orpl_routing_set_contains(&dest_ipaddr));
        app_send_to(target_id);
      }

      PROCESS_WAIT_UNTIL(etimer_expired(&periodic_timer));
      etimer_reset(&periodic_timer);
    }
  }
Esempio n. 10
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_broadcast_process, ev, data)
{
  static struct etimer periodic_timer;
  uip_ipaddr_t addr;

  PROCESS_BEGIN();

  simple_udp_register(&broadcast_connection, UDP_PORT, NULL, UDP_PORT,
                      receiver);

  etimer_set(&periodic_timer, SEND_INTERVAL);

#if (MIST_CONF_NETSTACK & MIST_CONF_MULTICHAN)
  if(HAS_MULTICHANNEL_AUTH()) {
    multichan_force_auth(1);
  }
#endif /* (MIST_CONF_NETSTACK & MIST_CONF_MULTICHAN) */
#if (MIST_CONF_NETSTACK & MIST_CONF_DROWSIE_MULTICHANNEL)
  if(HAS_MULTICHANNEL_AUTH()) {
    drowsie_multichannel_force_auth(1);
  }
#endif /* (MIST_CONF_NETSTACK & MIST_CONF_DROWSIE_MULTICHANNEL) */

  while(1) {
    static char buf[MAX_SIZE + 1];
    static int current_size = MIN_SIZE;

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_reset(&periodic_timer);

    if(IS_SENDER()) {
      int i;

      current_size++;
      if(current_size > MAX_SIZE) {
        current_size = MIN_SIZE;
      }

      for(i = 0; i < current_size; i++) {
        buf[i] = 'a';
      }
      buf[current_size] = '\0';

      printf("TX[%02d]: '%s'\n", current_size, buf);

      leds_toggle(LEDS_GREEN);
      uip_create_linklocal_allnodes_mcast(&addr);
      simple_udp_sendto(&broadcast_connection, buf, current_size, &addr);
    }
  }

  PROCESS_END();
}
Esempio n. 11
0
int mqtt_sn_create_socket(struct mqtt_sn_connection *mqc, uint16_t local_port, uip_ipaddr_t *remote_addr, uint16_t remote_port)
{
  simple_udp_register(&(mqc->sock), local_port, remote_addr, remote_port, mqtt_sn_receiver);
  mqc->stat = MQTTSN_DISCONNECTED;
  mqc->keep_alive=0;
  mqc->next_message_id = 1;
  mqc->connection_retries = 0;
  LIST_STRUCT_INIT(mqc,requests);
  mqtt_sn_request_event = process_alloc_event();
  process_start(&mqtt_sn_process, NULL);
  return 0;
}
PROCESS_THREAD(run_test_session,ev,data)
{
  PROCESS_BEGIN();
  current = 0;
  simple_udp_register(&unicast_connection, UDP_RECEIVER_PORT,
                      NULL, UDP_SENDER_PORT, receiver);

  PROCESS_WAIT_UNTIL(current == TEST_AMOUNT-1);
  //PROCESS_WAIT_UNTIL(current == 2749);
 
  PROCESS_END();
  PROCESS_EXIT();
}
Esempio n. 13
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(broadcast_example_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t addr;
  char buf[sizeof(uip_ipaddr_t) * MAX_IP];
  char* ptr;
  int len;
  struct ip_list_struct *s;

  PROCESS_BEGIN();

  simple_udp_register(&broadcast_connection, UDP_PORT,
                      NULL, UDP_PORT,
                      receiver);

  list_init(ip_list);

  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 adv message\n");
    
    // Create the message with the list of mi neighbors
    ptr = &buf;
    len = 0;
    for(s = list_head(ip_list);
        s != NULL;
        s = list_item_next(s)) {
      uip_ipaddr_copy((uip_ipaddr_t*)ptr, &s->ip);
      ptr += sizeof(uip_ipaddr_t);
      len += sizeof(uip_ipaddr_t);
    }

    // An empty message is not delivered, make some padding and sent it!
    if(len == 0){
       buf[0] = 0;
       len++;
    }

    // Showtime, deliver the message
    uip_create_linklocal_allnodes_mcast(&addr);
    simple_udp_sendto(&broadcast_connection, &buf, len, &addr);
  }

  PROCESS_END();
}
Esempio n. 14
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(network_reboot_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  static struct etimer countdown_timer;

  PROCESS_BEGIN();

  /* Wait for a while before starting to listen to the reboot code. */

  etimer_set(&periodic_timer, STARTUP_GRACE_PERIOD);
  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));

  simple_udp_register(&broadcast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  etimer_set(&periodic_timer, SEND_INTERVAL);
  etimer_set(&send_timer, SEND_TIME);
  etimer_set(&countdown_timer, CLOCK_SECOND);
  while(1) {
    PROCESS_WAIT_EVENT();

    if(data == &countdown_timer) {
      etimer_reset(&countdown_timer);
      if(seconds_until_reboot > 0) {
	printf("Seconds until reboot %d\n", seconds_until_reboot);
	leds_toggle(LEDS_ALL);
	seconds_until_reboot--;
	if(seconds_until_reboot == 0) {
	  printf("Rebooting\n");
	  watchdog_reboot();
	}
      }
    }

    if(data == &periodic_timer) {
      etimer_reset(&periodic_timer);
      etimer_set(&send_timer, SEND_TIME);
    }

    if(data == &send_timer) {
      if(seconds_until_reboot > 0) {
	send_msg(&broadcast_connection, seconds_until_reboot);
      }
    }
  }

  PROCESS_END();
}
Esempio n. 15
0
PROCESS_THREAD(udp_component_kev, ev, data)
{
	static uip_ipaddr_t addr;
	static struct simple_udp_connection unicast_connection;
	static struct etimer timer;
	static UDPClientComponent* inst;
	static uint16_t message_number;
	PROCESS_BEGIN();

	PRINTF("UDP server started\n");

	/* confire server address */
	uip_ip6addr(&addr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);

	inst = (UDPClientComponent*) data;

	/* print local address */
	print_local_addresses();

	etimer_set(&timer, CLOCK_SECOND * (inst->interval/1000));

	/* initialize the UDP stuff */
	simple_udp_register(&unicast_connection, inst->remotePort,
			NULL, inst->remotePort, receiver);

	/* TODO: print the RPL tree */

	while(1) {
		PROCESS_WAIT_EVENT();
		if (ev == PROCESS_EVENT_TIMER) {
			char buf[20];

			sprintf(buf, "Message %d", message_number++);

			printf("Sending %s unicast to ", buf);
			uip_debug_ipaddr_print(&addr);

			printf("\n");

			/* send message to the server */
			simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, &addr);
			generate_routes();
			etimer_restart(&timer);
		} else {
			/* process network messages */
		}
	}
	PROCESS_END();
}
Esempio n. 16
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;

  PROCESS_BEGIN();

  random_rand();
  simple_energest_start();

  if(node_id == 0) {
    NETSTACK_RDC.off(0);
    uint16_t mymac = rimeaddr_node_addr.u8[7] << 8 | rimeaddr_node_addr.u8[6];
    printf("Node id unset, my mac is 0x%04x\n", mymac);
    PROCESS_EXIT();
  }

  //  etimer_set(&periodic_timer, 90 * CLOCK_SECOND);
  //  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
  printf("App: %u starting\n", node_id);

  rpl_setup(node_id == ROOT_ID, node_id);
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  if(node_id == ROOT_ID) {
    NETSTACK_RDC.off(1);
  } else {
    etimer_set(&periodic_timer, 2 * 60 * CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_set(&periodic_timer, SEND_INTERVAL);
    while(1) {
      etimer_set(&send_timer, random_rand() % (SEND_INTERVAL));
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));

      if(rank != 0xffff) {
        app_send_to(ROOT_ID);
      } else {
        printf("App: not in DODAG (%u %u)\n", node_id, ROOT_ID);
      }

      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
      etimer_reset(&periodic_timer);
    }
  }

  PROCESS_END();
}
Esempio n. 17
0
/* Internal function to send network data to uIP stack */
static int check_and_send_packet(struct net_buf *buf)
{
	struct net_tuple *tuple;
	struct simple_udp_connection *udp;
	int ret = 0;

	if (!netdev.drv) {
		return -EINVAL;
	}

	tuple = net_context_get_tuple(buf->context);
	if (!tuple) {
		return -EINVAL;
	}

	switch (tuple->ip_proto) {
	case IPPROTO_UDP:
		udp = net_context_get_udp_connection(buf->context);
		if (!net_context_get_receiver_registered(buf->context)) {
			ret = simple_udp_register(udp, tuple->local_port,
#ifdef CONFIG_NETWORKING_WITH_IPV6
				(uip_ip6addr_t *)&tuple->remote_addr->in6_addr,
#else
				(uip_ip4addr_t *)&tuple->remote_addr->in_addr,
#endif
				tuple->remote_port, udp_packet_reply, buf);
			if (!ret) {
				NET_DBG("UDP connection creation failed\n");
				ret = -ENOENT;
				break;
			}
			net_context_set_receiver_registered(buf->context);
		}
		simple_udp_send(buf, udp, buf->data, buf->len);
		ret = 0;
		break;
	case IPPROTO_TCP:
		NET_DBG("TCP not yet supported\n");
		ret = -EINVAL;
		break;
	case IPPROTO_ICMPV6:
		NET_DBG("ICMPv6 not yet supported\n");
		ret = -EINVAL;
		break;
	}

	return ret;
}
Esempio n. 18
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t global_ipaddr;

  PROCESS_BEGIN();

  printf("App: %u starting\n", node_id);

  uip_ip6addr(&root_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);

  if(node_id == ROOT_ID) {
    memcpy(&global_ipaddr, &root_ipaddr, 16);
    uip_ds6_addr_add(&global_ipaddr, 0, ADDR_MANUAL);
    rpl_dag_t *dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &global_ipaddr);
    rpl_set_prefix(dag, &global_ipaddr, 64);
  } else {
    uip_ip6addr(&global_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&global_ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&global_ipaddr, 0, ADDR_AUTOCONF);
  }

  orpl_init(&global_ipaddr, node_id == ROOT_ID, 1);
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  if(node_id == ROOT_ID) {
    NETSTACK_RDC.off(1);
  } else {
    etimer_set(&periodic_timer, SEND_INTERVAL);
    while(1) {
      etimer_set(&send_timer, random_rand() % (SEND_INTERVAL));
      PROCESS_WAIT_UNTIL(etimer_expired(&send_timer));

      if(orpl_current_edc() != 0xffff) {
        app_send_to(ROOT_ID);
      } else {
        printf("App: not in DODAG\n");
      }

      PROCESS_WAIT_UNTIL(etimer_expired(&periodic_timer));
      etimer_reset(&periodic_timer);
    }
  }

  PROCESS_END();
}
Esempio n. 19
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_receiver_process, ev, data)
{
  uip_ipaddr_t *ipaddr;

  PROCESS_BEGIN();

  ipaddr = set_global_address();

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  while(1) {
    PROCESS_WAIT_EVENT();
  }
  PROCESS_END();
}
Esempio n. 20
0
/* Called by application when it wants to receive network data */
struct net_buf *net_receive(struct net_context *context)
{
	struct nano_fifo *rx_queue = net_context_get_queue(context);
	struct net_tuple *tuple;
	int ret = 0;

	tuple = net_context_get_tuple(context);
	if (!tuple) {
		return NULL;
	}

	switch (tuple->ip_proto) {
	case IPPROTO_UDP:
		if (!net_context_get_receiver_registered(context)) {
			struct simple_udp_connection *udp =
				net_context_get_udp_connection(context);

			ret = simple_udp_register(udp, tuple->local_port,
#ifdef CONFIG_NETWORKING_WITH_IPV6
				(uip_ip6addr_t *)&tuple->remote_addr->in6_addr,
#else
				(uip_ip4addr_t *)&tuple->remote_addr->in_addr,
#endif
				tuple->remote_port,
				udp_packet_receive,
				context);
			if (!ret) {
				NET_DBG("UDP connection listener failed\n");
				ret = -ENOENT;
				break;
			}
		}
		net_context_set_receiver_registered(context);
		ret = 0;
		break;
	case IPPROTO_TCP:
		NET_DBG("TCP not yet supported\n");
		ret = -EINVAL;
		break;
	case IPPROTO_ICMPV6:
		NET_DBG("ICMPv6 not yet supported\n");
		ret = -EINVAL;
		break;
	}

	return nano_fifo_get(rx_queue);
}
Esempio n. 21
0
/*--------------------------------PROCESS BROADCAST----------------------------------*/
PROCESS_THREAD(broadcast_example_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t addr;

  static uint8_t initialize = 1; //this is used for mote-1 only for intialization
#if RANDOM_TOKEN_ERROR
  random_init(clock_time() % 100);
#endif

  PROCESS_BEGIN();

  simple_udp_register(&broadcast_connection, UDP_PORT,
                      NULL, UDP_PORT,
                      receiver);

  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");
    uip_create_linklocal_allnodes_mcast(&addr);

    // initialize transmission by mote-1
    if (1 == node_id && 1 == initialize) {
      token = 1;
      initialize = 0; // this statement will never execute again
    }

    if (token) { 
      printf("I got the token, it's my turn\n");
      simple_udp_sendto(&broadcast_connection, (uint8_t *) &node_id, 4, &addr);
      token = 0;
      
      //trigger an event to all service subscribers
      printf("RES-Event Process\n");
      res_event.trigger();
    }
  }

  PROCESS_END();
}
Esempio n. 22
0
PROCESS_THREAD(snd_process, ev, data){
	static struct etimer et;
	static struct simple_udp_connection broadcast_connection;
	static uip_ipaddr_t mcast_allnodes_address;

PROCESS_BEGIN();
	etimer_set(&et, CLOCK_SECOND*HOW_MUCH_TIME);
	set_address();
	simple_udp_register(&broadcast_connection, UDP_PORT, NULL,UDP_PORT, 		callback_function);
	mcast_allnodes_address=get_multicast_all_nodes_addr();

	while(1){//A broadcast message is sent periodically
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
		simple_udp_sendto(&broadcast_connection, "Hello", 5, (const 		uip_ipaddr_t*)&mcast_allnodes_address);
		etimer_reset(&et);
		}
	
PROCESS_END();
}
Esempio n. 23
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(simple_udp_ping_process, ev, data)
{
  static struct etimer et;
  int i;

  PROCESS_BEGIN();

  for(i = 0; i < MAX_DESTINATIONS; i++) {
    pingconns[i].in_use = 0;
  }

  simple_udp_register(&ping_connection, UDP_PORT, NULL, UDP_PORT, receiver);

  while(1) {
#define PERIOD (3*CLOCK_SECOND)
    etimer_set(&et, PERIOD);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    for(i = 0; i < MAX_DESTINATIONS; i++) {
      if (pingconns[i].in_use && pingconns[i].waiting) {
        struct pingconn_t* pingconn = &pingconns[i];

        pingconn->waiting = 0;

        /* Send ping */
#if DEBUG
        printf("Sending ping to ");
        uip_debug_ipaddr_print(&pingconn->host);
        printf("\n");
#endif
        simple_udp_sendto(&ping_connection, "ping", DATALEN, &pingconn->host);
        pingconn->echo_time = RTIMER_NOW();
        pingconn->echo_time2 = clock_time();
        pingconn->sent = 1;
        pingconn->replied = 0;
        break;
      }
    }

  }

  PROCESS_END();
}
Esempio n. 24
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t *addr;

  PROCESS_BEGIN();

  servreg_hack_init();

  set_global_address();

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  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("SIMPLE_UNICAST_SENDER: Unicast attempt!\n");
    addr = servreg_hack_lookup(SERVICE_ID);
	
    if(addr != NULL) {
      static unsigned int message_number;
      char buf[20];

      printf("Sending unicast to ");
      uip_debug_ipaddr_print(addr);
      printf(" \n");
      sprintf(buf, "Message %d", message_number);
      message_number++;
      simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, addr);
    } else {
      printf("Service %d not found\n", SERVICE_ID);
    }
  }

  PROCESS_END();
}
Esempio n. 25
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et;
  uip_ipaddr_t ipaddr;

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

#if UIP_CONF_ROUTER
  set_global_address();
#endif

  print_local_addresses();

  set_connection_address(&ipaddr);

  /* new connection with remote host */
  SENSORS_ACTIVATE(button_sensor);//activate button
  //client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
   simple_udp_register(&udp_connection, UDP_PORT, NULL, UDP_PORT,    receiver);
 // udp_bind(client_conn, UIP_HTONS(3001));

  //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(&et, SEND_INTERVAL);
  while(1) {
    //PROCESS_YIELD();
    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);

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

  PROCESS_END();
}
Esempio n. 26
0
PROCESS_THREAD(udp_server_process, ev, data)
{

  PROCESS_BEGIN();
  static uip_ipaddr_t ipaddr;
  rpl_dag_t *dag;
  int i;
  uint8_t state;
  static struct etimer timer;
  static struct simple_udp_connection connection;
  static int packet = 0;

  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); 

  //uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  //dag = rpl_set_root(RPL_DEFAULT_INSTANCE, (uip_ip6addr_t*) &ipaddr);
  //rpl_set_prefix(dag, &ipaddr, 64);

  simple_udp_register(&connection, UDP_PORT-1, NULL, UDP_PORT, receiver);

  printf("IPv6 addresses: ");
  for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
    state = uip_ds6_if.addr_list[i].state;
    if(uip_ds6_if.addr_list[i].isused &&
       (state == ADDR_TENTATIVE 
       || state == ADDR_PREFERRED)) {
            uip_debug_ipaddr_print(
               &uip_ds6_if.addr_list[i].ipaddr);
            printf("\n");
    }
  }
  printf("UDP server started\n");
  etimer_set(&timer, CLOCK_SECOND >> 1);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
    etimer_restart(&timer);
    leds_toggle(LEDS_GREEN);
  }
  PROCESS_END();
}
Esempio n. 27
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(broadcast_example_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t addr;
  //uip_ip6addr(&addr, 0xfe80, 0, 0, 0, 0, 0, 0, 1);
  //uip_ip6addr(&addr, 0xfe01, 0, 0, 0, 0, 0, 0, 1);

  PROCESS_BEGIN();

#if PLATFORM_HAS_LEDS
  leds_off(LEDS_ALL);
#endif

  simple_udp_register(&broadcast_connection, UDP_PORT,
                      NULL, UDP_PORT,
                      receiver);

  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));
    uip_create_linklocal_allnodes_mcast(&addr);
#if PLATFORM_HAS_LEDS
  leds_on(LEDS_ALL);
#endif
    /*printf("Sending broadcast from: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x on port %d\n", 
	addr.u16[0],addr.u16[1],addr.u16[2],addr.u16[3],addr.u16[4],addr.u16[5],addr.u16[6],addr.u16[7], 
	UDP_PORT);*/
    printf("Sending broadcast from: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x on port %d\n", addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7], addr.u8[8],addr.u8[9],addr.u8[10],addr.u8[11],addr.u8[12],addr.u8[13],addr.u8[14],addr.u8[15], UDP_PORT);
    simple_udp_sendto(&broadcast_connection, "Test", 4, &addr);
#if PLATFORM_HAS_LEDS
  leds_off(LEDS_ALL);
#endif
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_receiver_process, ev, data)
{
  uip_ipaddr_t *ipaddr;

  PROCESS_BEGIN();

  servreg_hack_init();

  ipaddr = set_global_address();

  create_rpl_dag(ipaddr);

  servreg_hack_register(SERVICE_ID, ipaddr);

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  while(1) {
    PROCESS_WAIT_EVENT();
  }
  PROCESS_END();
}
Esempio n. 29
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sender_node_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t addr;

  PROCESS_BEGIN();

  set_global_address();

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  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));

    uip_ip6addr(&addr, 0xaaaa, 0, 0, 0, 0x0201, 0x001, 0x001, 0x001);

    {
      static unsigned int message_number;
      char buf[20];

      printf("Sending unicast to ");
      uip_debug_ipaddr_print(&addr);
      printf("\n");
      sprintf(buf, "Message %d", message_number);
      message_number++;
      simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, &addr);
    }
  }

  PROCESS_END();
}
Esempio n. 30
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sender_process, ev, data)
{

  PROCESS_BEGIN();
  static uip_ipaddr_t ipaddr, unicastaddr;
  int i;
  uint8_t state;
  static struct etimer timer;
  static struct simple_udp_connection connection;
  static char *packet = "Supertest";

  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); 

  uip_ip6addr(&unicastaddr, 0xfe80, 0, 0, 0, 0xc30c, 0, 0, 2);

  simple_udp_register(&connection, UDP_PORT, NULL, UDP_PORT, NULL);

  printf("IPv6 addresses: ");
  for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
    state = uip_ds6_if.addr_list[i].state;
    if(uip_ds6_if.addr_list[i].isused &&
       (state == ADDR_TENTATIVE 
       || state == ADDR_PREFERRED)) {
            uip_debug_ipaddr_print(
               &uip_ds6_if.addr_list[i].ipaddr);
            printf("\n");
    }
  }
  etimer_set(&timer, CLOCK_SECOND);
  while(1) {
    printf("STO MANDANDO UNICAST\n");
    simple_udp_sendto(&connection, packet, strlen(packet)+1, &unicastaddr);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
    etimer_restart(&timer);
  }
  PROCESS_END();
}