/*---------------------------------------------------------------------------*/ 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(); }
void init_dtls() { static dtls_handler_t cb = { .write = send_to_peer, .read = read_from_peer, .event = NULL, #ifdef DTLS_PSK .get_psk_info = get_psk_info, #endif /* DTLS_PSK */ #ifdef DTLS_ECC .get_ecdsa_key = get_ecdsa_key, .verify_ecdsa_key = verify_ecdsa_key #endif /* DTLS_ECC */ }; #if 0 uip_ipaddr_t ipaddr; /* struct uip_ds6_addr *root_if; */ #endif /* UIP_CONF_ROUTER */ PRINTF("DTLS server started\n"); #if 0 /* TEST */ memset(&tmp_addr, 0, sizeof(rimeaddr_t)); if(get_eui64_from_eeprom(tmp_addr.u8)); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8); #endif #endif /* TEST */ #if 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); */ /* create_rpl_dag(&ipaddr); */ /* #else */ /* uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); */ uip_ip6addr(&ipaddr, 0xaaaa, 0,0,0,0x0200,0,0,0x0003); uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL); create_rpl_dag(&ipaddr); #endif /* UIP_CONF_ROUTER */ server_conn = udp_new(NULL, 0, NULL); udp_bind(server_conn, UIP_HTONS(20220)); dtls_set_log_level(DTLS_LOG_DEBUG); dtls_context = dtls_new_context(server_conn); if (dtls_context) dtls_set_handler(dtls_context, &cb); }
/*---------------------------------------------------------------------------*/ 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(); }