/** * @brief Maybe you are a golfer?! */ int main(void) { shell_t shell; ng_netreg_entry_t dump; puts("ZEP module test"); /* initialize and register pktdump */ dump.pid = ng_pktdump_getpid(); if (dump.pid <= KERNEL_PID_UNDEF) { puts("Error starting pktdump thread"); return -1; } dump.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; ng_netreg_register(NG_NETTYPE_NETIF, &dump); /* start the shell */ puts("Initialization OK, starting shell now"); shell_init(&shell, NULL, SHELL_BUFSIZE, getchar, putchar); shell_run(&shell); return 0; }
static void *_event_loop(void *args) { msg_t msg, reply, msg_q[NG_SIXLOWPAN_MSG_QUEUE_SIZE]; ng_netreg_entry_t me_reg; (void)args; msg_init_queue(msg_q, NG_SIXLOWPAN_MSG_QUEUE_SIZE); me_reg.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; me_reg.pid = thread_getpid(); /* register interest in all 6LoWPAN packets */ ng_netreg_register(NG_NETTYPE_SIXLOWPAN, &me_reg); /* preinitialize ACK */ reply.type = NG_NETAPI_MSG_TYPE_ACK; /* start event loop */ while (1) { DEBUG("6lo: waiting for incoming message.\n"); msg_receive(&msg); switch (msg.type) { case NG_NETAPI_MSG_TYPE_RCV: DEBUG("6lo: NG_NETDEV_MSG_TYPE_RCV received\n"); _receive((ng_pktsnip_t *)msg.content.ptr); break; case NG_NETAPI_MSG_TYPE_SND: DEBUG("6lo: NG_NETDEV_MSG_TYPE_SND received\n"); _send((ng_pktsnip_t *)msg.content.ptr); break; case NG_NETAPI_MSG_TYPE_GET: case NG_NETAPI_MSG_TYPE_SET: DEBUG("6lo: reply to unsupported get/set\n"); reply.content.value = -ENOTSUP; msg_reply(&msg, &reply); break; default: DEBUG("6lo: operation not supported\n"); break; } } return NULL; }
ng_nettest_res_t ng_nettest_receive(kernel_pid_t pid, ng_pktsnip_t *in, unsigned int exp_pkts, kernel_pid_t exp_senders[], ng_pktsnip_t *exp_out[], ng_nettype_t exp_type, uint32_t exp_demux_ctx) { ng_netreg_entry_t reg_entry = { NULL, exp_demux_ctx, thread_getpid() }; ng_nettest_res_t res; ng_netreg_register(exp_type, ®_entry); res = _pkt_test(NG_NETAPI_MSG_TYPE_RCV, pid, in, exp_pkts, exp_senders, exp_out); ng_netreg_unregister(exp_type, ®_entry); return res; }
static void *_event_loop(void *arg) { (void)arg; msg_t msg, reply; msg_t msg_queue[NG_UDP_MSG_QUEUE_SIZE]; ng_netreg_entry_t netreg; /* preset reply message */ reply.type = NG_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)-ENOTSUP; /* initialize message queue */ msg_init_queue(msg_queue, NG_UDP_MSG_QUEUE_SIZE); /* register UPD at netreg */ netreg.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; netreg.pid = thread_getpid(); ng_netreg_register(NG_NETTYPE_UDP, &netreg); /* dispatch NETAPI messages */ while (1) { msg_receive(&msg); switch (msg.type) { case NG_NETAPI_MSG_TYPE_RCV: DEBUG("udp: NG_NETAPI_MSG_TYPE_RCV\n"); _receive((ng_pktsnip_t *)msg.content.ptr); break; case NG_NETAPI_MSG_TYPE_SND: DEBUG("udp: NG_NETAPI_MSG_TYPE_SND\n"); _send((ng_pktsnip_t *)msg.content.ptr); break; case NG_NETAPI_MSG_TYPE_SET: case NG_NETAPI_MSG_TYPE_GET: msg_reply(&msg, &reply); break; default: DEBUG("udp: received unidentified message\n"); break; } } /* never reached */ return NULL; }
/** * @brief Maybe you are a golfer?! */ int main(void) { shell_t shell; ng_netreg_entry_t dump; puts("AT86RF2xx device driver test"); /* register the pktdump thread */ puts("Register the packet dump thread for NG_NETTYPE_UNDEF packets"); dump.pid = ng_pktdump_getpid(); dump.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; ng_netreg_register(NG_NETTYPE_UNDEF, &dump); /* start the shell */ puts("Initialization successful - starting the shell now"); (void) posix_open(uart0_handler_pid, 0); shell_init(&shell, NULL, SHELL_BUFSIZE, uart0_readc, uart0_putc); shell_run(&shell); return 0; }
static void start_server(char *port_str) { uint16_t port; /* check if server is already running */ if (server.pid != KERNEL_PID_UNDEF) { printf("Error: server already running on port %" PRIu32 "\n", server.demux_ctx); return; } /* parse port */ port = (uint16_t)atoi(port_str); if (port == 0) { puts("Error: invalid port specified"); return; } /* start server (which means registering pktdump for the chosen port) */ server.pid = ng_pktdump_getpid(); server.demux_ctx = (uint32_t)port; ng_netreg_register(NG_NETTYPE_UDP, &server); printf("Success: started UDP server on port %" PRIu16 "\n", port); }
/** * @brief Maybe you are a golfer?! */ int main(void) { shell_t shell; ng_netreg_entry_t dump; puts("RIOT sniffer application"); /* start and register rawdump thread */ puts("Run the rawdump thread and register it"); dump.pid = thread_create(rawdmp_stack, sizeof(rawdmp_stack), RAWDUMP_PRIO, CREATE_STACKTEST, rawdump, NULL, "rawdump"); dump.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; ng_netreg_register(NG_NETTYPE_UNDEF, &dump); /* start the shell */ puts("All ok, starting the shell now"); (void) posix_open(uart0_handler_pid, 0); shell_init(&shell, NULL, SHELL_BUFSIZE, uart0_readc, uart0_putc); shell_run(&shell); return 0; }
static void *_brain_thread(void *arg) { ng_netreg_entry_t netreg; ng_pktsnip_t *snip; msg_t msg; netreg.pid = thread_getpid(); netreg.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; ng_netreg_register(NG_NETTYPE_UNDEF, &netreg); while (1) { msg_receive(&msg); if (msg.type == NG_NETAPI_MSG_TYPE_RCV) { snip = (ng_pktsnip_t *)msg.content.ptr; _dispatch(snip->data, snip->size); ng_pktbuf_release(snip); } } /* never reached */ return NULL; }
/* internal functions */ static void *_event_loop(void *args) { msg_t msg, reply, msg_q[NG_IPV6_MSG_QUEUE_SIZE]; ng_netreg_entry_t me_reg; (void)args; msg_init_queue(msg_q, NG_IPV6_MSG_QUEUE_SIZE); me_reg.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; me_reg.pid = thread_getpid(); /* register interest in all IPv6 packets */ ng_netreg_register(NG_NETTYPE_IPV6, &me_reg); /* preinitialize ACK */ reply.type = NG_NETAPI_MSG_TYPE_ACK; /* start event loop */ while (1) { DEBUG("ipv6: waiting for incoming message.\n"); msg_receive(&msg); switch (msg.type) { case NG_NETAPI_MSG_TYPE_RCV: DEBUG("ipv6: NG_NETAPI_MSG_TYPE_RCV received\n"); _receive((ng_pktsnip_t *)msg.content.ptr); break; case NG_NETAPI_MSG_TYPE_SND: DEBUG("ipv6: NG_NETAPI_MSG_TYPE_SND received\n"); _send((ng_pktsnip_t *)msg.content.ptr, true); break; case NG_NETAPI_MSG_TYPE_GET: case NG_NETAPI_MSG_TYPE_SET: DEBUG("ipv6: reply to unsupported get/set\n"); reply.content.value = -ENOTSUP; msg_reply(&msg, &reply); break; case NG_NDP_MSG_RTR_TIMEOUT: DEBUG("ipv6: Router timeout received\n"); ((ng_ipv6_nc_t *)msg.content.ptr)->flags &= ~NG_IPV6_NC_IS_ROUTER; break; case NG_NDP_MSG_ADDR_TIMEOUT: DEBUG("ipv6: Router advertisement timer event received\n"); ng_ipv6_netif_remove_addr(KERNEL_PID_UNDEF, (ng_ipv6_addr_t *)msg.content.ptr); break; case NG_NDP_MSG_NBR_SOL_RETRANS: DEBUG("ipv6: Neigbor solicitation retransmission timer event received\n"); ng_ndp_retrans_nbr_sol((ng_ipv6_nc_t *)msg.content.ptr); break; case NG_NDP_MSG_NC_STATE_TIMEOUT: DEBUG("ipv6: Neigbor cace state timeout received\n"); ng_ndp_state_timeout((ng_ipv6_nc_t *)msg.content.ptr); break; default: break; } } return NULL; }