static void *_event_loop(void *args) { msg_t msg, reply, msg_q[GNRC_SIXLOWPAN_MSG_QUEUE_SIZE]; gnrc_netreg_entry_t me_reg = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, sched_active_pid); (void)args; msg_init_queue(msg_q, GNRC_SIXLOWPAN_MSG_QUEUE_SIZE); /* register interest in all 6LoWPAN packets */ gnrc_netreg_register(GNRC_NETTYPE_SIXLOWPAN, &me_reg); /* preinitialize ACK */ reply.type = GNRC_NETAPI_MSG_TYPE_ACK; /* start event loop */ while (1) { DEBUG("6lo: waiting for incoming message.\n"); msg_receive(&msg); switch (msg.type) { case GNRC_NETAPI_MSG_TYPE_RCV: DEBUG("6lo: GNRC_NETDEV_MSG_TYPE_RCV received\n"); _receive(msg.content.ptr); break; case GNRC_NETAPI_MSG_TYPE_SND: DEBUG("6lo: GNRC_NETDEV_MSG_TYPE_SND received\n"); _send(msg.content.ptr); break; case GNRC_NETAPI_MSG_TYPE_GET: case GNRC_NETAPI_MSG_TYPE_SET: DEBUG("6lo: reply to unsupported get/set\n"); reply.content.value = -ENOTSUP; msg_reply(&msg, &reply); break; #ifdef MODULE_GNRC_SIXLOWPAN_FRAG case GNRC_SIXLOWPAN_MSG_FRAG_SND: DEBUG("6lo: send fragmented event received\n"); gnrc_sixlowpan_frag_send(msg.content.ptr); break; #endif default: DEBUG("6lo: operation not supported\n"); break; } } return NULL; }
int main(void) { puts("LWMAC test application"); gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid); gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump); char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); return 0; }
int main(void) { #ifdef MODULE_NETIF gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid); gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump); #endif (void) puts("Welcome to RIOT!"); char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); return 0; }
gnrc_nettest_res_t gnrc_nettest_receive(kernel_pid_t pid, gnrc_pktsnip_t *in, unsigned int exp_pkts, const kernel_pid_t *exp_senders, const gnrc_pktsnip_t **exp_out, gnrc_nettype_t exp_type, uint32_t exp_demux_ctx) { gnrc_netreg_entry_t reg_entry = GNRC_NETREG_ENTRY_INIT_PID(exp_demux_ctx, sched_active_pid); gnrc_nettest_res_t res; gnrc_netreg_register(exp_type, ®_entry); res = _pkt_test(GNRC_NETAPI_MSG_TYPE_RCV, pid, in, exp_pkts, exp_senders, exp_out); gnrc_netreg_unregister(exp_type, ®_entry); return res; }
int _tftp_do_client_transfer(tftp_context_t *ctxt) { msg_t msg; tftp_state ret = TS_BUSY; /* register our DNS response listener */ gnrc_netreg_entry_t entry = GNRC_NETREG_ENTRY_INIT_PID(ctxt->src_port, sched_active_pid); if (gnrc_netreg_register(GNRC_NETTYPE_UDP, &entry)) { DEBUG("tftp: error starting server.\n"); return TS_FAILED; } /* try to start the TFTP transfer */ ret = _tftp_state_processes(ctxt, NULL); if (ret != TS_BUSY) { DEBUG("tftp: transfer failed\n"); /* if the start failed return */ return ret; } /* main processing loop */ while (ret == TS_BUSY) { /* wait for a message */ msg_receive(&msg); DEBUG("tftp: message received\n"); ret = _tftp_state_processes(ctxt, &msg); /* release packet if we received one */ if (msg.type == GNRC_NETAPI_MSG_TYPE_RCV) { gnrc_pktbuf_release(msg.content.ptr); } } /* unregister our UDP listener on this thread */ gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &entry); return ret; }
/** * @brief Maybe you are a golfer?! */ int main(void) { gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid); puts("Xbee S1 device driver test"); /* initialize and register pktdump */ if (gnrc_pktdump_pid <= KERNEL_PID_UNDEF) { puts("Error starting pktdump thread"); return -1; } gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump); /* start the shell */ puts("Initialization OK, starting shell now"); char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); return 0; }
int _tftp_server(tftp_context_t *ctxt) { msg_t msg; bool active = true; gnrc_netreg_entry_t entry = GNRC_NETREG_ENTRY_INIT_PID(GNRC_TFTP_DEFAULT_DST_PORT, sched_active_pid); while (active) { int ret = TS_BUSY; bool got_client = false; /* register the servers main listening port */ if (gnrc_netreg_register(GNRC_NETTYPE_UDP, &entry)) { DEBUG("tftp: error starting server.\n"); return TS_FAILED; } /* main processing loop */ while (ret == TS_BUSY) { /* wait for a message */ msg_receive(&msg); /* check if the server stop message has been received */ if (msg.type == TFTP_STOP_SERVER_MSG) { active = false; ret = TS_FAILED; break; } else { /* continue normal server opration */ DEBUG("tftp: message incoming\n"); ret = _tftp_state_processes(ctxt, &msg); /* release packet if we received one */ if (msg.type == GNRC_NETAPI_MSG_TYPE_RCV) { gnrc_pktbuf_release(msg.content.ptr); } } /* if we just accepted a client, disable the server main listening port */ if (!got_client) { gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &entry); if (ret == TS_BUSY) { got_client = true; DEBUG("tftp: connection established\n"); } } } /* remove any stall timers */ xtimer_remove(&(ctxt->timer)); /* if the server transfer has finished, unregister the client dst port */ gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &(ctxt->entry)); DEBUG("tftp: connection terminated\n"); } /* unregister our UDP listener on this thread */ gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &entry); return 0; }
static void _send_packet(void) { gnrc_netif_t *netif = gnrc_netif_iter(NULL); struct { gnrc_netif_hdr_t netif_hdr; uint8_t src[8]; uint8_t dst[8]; } netif_hdr = { .src = IEEE802154_REMOTE_EUI64, .dst = IEEE802154_LOCAL_EUI64, }; gnrc_netif_hdr_init(&(netif_hdr.netif_hdr), 8, 8); netif_hdr.netif_hdr.if_pid = netif->pid; uint8_t data1[] = { /* 6LoWPAN Header */ /* Fragmentation Header (first) */ 0xc0, 0x94, /* 0b11000: frag1, 0b00010010100: datagram_size (148) */ 0x00, 0x01, /* datagram_tag */ /* 0b011: LOWPAN_IPHC */ /* 0b11: Traffic Class and Flow Label are elided */ /* 0b1: Next Header is compressed */ /* 0b11: The Hop Limit field is compressed and the hop limit is 255 */ 0x7f, /* 0b0: No additional 8-bit Context Identifier Extension is used */ /* 0b0: Source address compression uses stateless compression */ /* 0b11: source address mode is 0 bits */ /* 0b0: Destination address is not a multicast address */ /* 0x0: Destination address compression uses stateless compression */ /* 0x00: destination address mode is 128 bits */ 0x30, /* destination address: fd01::1 */ 0xfd, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0b11110: UDP LOWPAN_NHC */ /* 0b0: Checksum is carried in-line */ /* 0b11: First 12 bits of both Source Port and Destination Port are 0xf0b and elided */ 0xf3, 0x00, /* Source Port and Destination Port (4 bits each) */ 0x23, 0x2f, /* Checksum */ /* payload */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; uint8_t data2[] = { /* 6LoWPAN Header */ /* Fragmentation Header (rest) */ 0xe0, 0x94, /* 0b11100: frag1, 0b00010010100: datagram_size (148) */ 0x00, 0x01, /* datagram_tag */ 0x0c, /* datagram_offset (12 * 8 = 96) */ /* payload */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; gnrc_netreg_entry_t dump_6lowpan = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid); gnrc_netreg_entry_t dump_ipv6 = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid); gnrc_netreg_entry_t dump_udp = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid); gnrc_netreg_entry_t dump_udp_61616 = GNRC_NETREG_ENTRY_INIT_PID(61616, gnrc_pktdump_pid); gnrc_netreg_register(GNRC_NETTYPE_SIXLOWPAN, &dump_6lowpan); gnrc_netreg_register(GNRC_NETTYPE_IPV6, &dump_ipv6); gnrc_netreg_register(GNRC_NETTYPE_UDP, &dump_udp); gnrc_netreg_register(GNRC_NETTYPE_UDP, &dump_udp_61616); gnrc_pktsnip_t *netif1 = gnrc_pktbuf_add(NULL, &netif_hdr, sizeof(netif_hdr), GNRC_NETTYPE_NETIF); gnrc_pktsnip_t *pkt1 = gnrc_pktbuf_add(netif1, data1, sizeof(data1), GNRC_NETTYPE_SIXLOWPAN); gnrc_netapi_dispatch_receive(GNRC_NETTYPE_SIXLOWPAN, GNRC_NETREG_DEMUX_CTX_ALL, pkt1); gnrc_pktsnip_t *netif2 = gnrc_pktbuf_add(NULL, &netif_hdr, sizeof(netif_hdr), GNRC_NETTYPE_NETIF); gnrc_pktsnip_t *pkt2 = gnrc_pktbuf_add(netif2, data2, sizeof(data2), GNRC_NETTYPE_SIXLOWPAN); gnrc_netapi_dispatch_receive(GNRC_NETTYPE_SIXLOWPAN, GNRC_NETREG_DEMUX_CTX_ALL, pkt2); }
/* Fragmentation Header (rest) */ 0xe0, 0x94, /* 0b11100: frag1, 0b00010010100: datagram_size (148) */ 0x00, 0x01, /* datagram_tag */ 0x0c, /* datagram_offset (12 * 8 = 96) */ /* payload */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; gnrc_netreg_entry_t dump_6lowpan = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid); gnrc_netreg_entry_t dump_ipv6 = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid); gnrc_netreg_entry_t dump_udp = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid); gnrc_netreg_entry_t dump_udp_61616 = GNRC_NETREG_ENTRY_INIT_PID(61616, gnrc_pktdump_pid); gnrc_netreg_register(GNRC_NETTYPE_SIXLOWPAN, &dump_6lowpan); gnrc_netreg_register(GNRC_NETTYPE_IPV6, &dump_ipv6); gnrc_netreg_register(GNRC_NETTYPE_UDP, &dump_udp); gnrc_netreg_register(GNRC_NETTYPE_UDP, &dump_udp_61616); gnrc_pktsnip_t *netif1 = gnrc_pktbuf_add(NULL, &netif_hdr, sizeof(netif_hdr), GNRC_NETTYPE_NETIF); gnrc_pktsnip_t *pkt1 = gnrc_pktbuf_add(netif1, data1,