diff --git a/examples/default/main.c b/examples/default/main.c index 4e5ad60a7f..a9e56d215b 100644 --- a/examples/default/main.c +++ b/examples/default/main.c @@ -53,10 +53,8 @@ int main(void) #endif #ifdef MODULE_NETIF - gnrc_netreg_entry_t dump; - - dump.pid = gnrc_pktdump_pid; - dump.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; + 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 diff --git a/examples/gnrc_networking/udp.c b/examples/gnrc_networking/udp.c index 9ba7a0316d..a422934e48 100644 --- a/examples/gnrc_networking/udp.c +++ b/examples/gnrc_networking/udp.c @@ -28,7 +28,8 @@ #include "timex.h" #include "xtimer.h" -static gnrc_netreg_entry_t server = { NULL, GNRC_NETREG_DEMUX_CTX_ALL, KERNEL_PID_UNDEF }; +static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + KERNEL_PID_UNDEF); static void send(char *addr_str, char *port_str, char *data, unsigned int num, diff --git a/pkg/ccn-lite/patches/0001-RIOT-adapter-port-to-new-netreg-struct.patch b/pkg/ccn-lite/patches/0001-RIOT-adapter-port-to-new-netreg-struct.patch new file mode 100644 index 0000000000..88de86321d Binary files /dev/null and b/pkg/ccn-lite/patches/0001-RIOT-adapter-port-to-new-netreg-struct.patch differ diff --git a/sys/include/net/gnrc.h b/sys/include/net/gnrc.h index b298960eb0..44e71b1997 100644 --- a/sys/include/net/gnrc.h +++ b/sys/include/net/gnrc.h @@ -66,10 +66,9 @@ * static msg_t _msg_q[Q_SZ]; * (void)arg; * msg_init_queue(_msg_q, Q_SZ); - * gnrc_netreg_entry me_reg = { - * .demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL, - * .pid = thread_getpid() - * }; + * gnrc_netreg_entry me_reg = GNRC_NETREG_ENTRY_INIT_PID( + * GNRC_NETREG_DEMUX_CTX_ALL, + * sched_active_pid); * gnrc_netreg_register(GNRC_NETTYPE_IPV6, &me_reg); * while (1) { * msg_receive(&msg); diff --git a/sys/include/net/gnrc/conn.h b/sys/include/net/gnrc/conn.h index 07f9123ed8..ad0d2100ff 100644 --- a/sys/include/net/gnrc/conn.h +++ b/sys/include/net/gnrc/conn.h @@ -83,8 +83,7 @@ struct conn_udp { static inline void gnrc_conn_reg(gnrc_netreg_entry_t *entry, gnrc_nettype_t type, uint32_t demux_ctx) { - entry->pid = sched_active_pid; - entry->demux_ctx = demux_ctx; + gnrc_netreg_entry_init_pid(entry, demux_ctx, sched_active_pid); gnrc_netreg_register(type, entry); } diff --git a/sys/include/net/gnrc/netreg.h b/sys/include/net/gnrc/netreg.h index 4080a98429..0b7b48a86f 100644 --- a/sys/include/net/gnrc/netreg.h +++ b/sys/include/net/gnrc/netreg.h @@ -77,7 +77,7 @@ typedef struct gnrc_netreg_entry { void gnrc_netreg_init(void); /** - * @brief Initializes a netreg entry statically with PID + * @brief Initializes a netreg entry dynamically with PID * * @param[out] entry A netreg entry * @param[in] demux_ctx The @ref gnrc_netreg_entry_t::demux_ctx "demux context" diff --git a/sys/net/gnrc/application_layer/tftp/gnrc_tftp.c b/sys/net/gnrc/application_layer/tftp/gnrc_tftp.c index f7d62acf5d..d20ba0fc44 100644 --- a/sys/net/gnrc/application_layer/tftp/gnrc_tftp.c +++ b/sys/net/gnrc/application_layer/tftp/gnrc_tftp.c @@ -454,8 +454,8 @@ int _tftp_server(tftp_context_t *ctxt) { msg_t msg; bool active = true; - gnrc_netreg_entry_t entry = { NULL, GNRC_TFTP_DEFAULT_DST_PORT, - thread_getpid() }; + gnrc_netreg_entry_t entry = GNRC_NETREG_ENTRY_INIT_PID(GNRC_TFTP_DEFAULT_DST_PORT, + sched_active_pid); while (active) { int ret = TS_BUSY; @@ -520,7 +520,8 @@ int _tftp_do_client_transfer(tftp_context_t *ctxt) tftp_state ret = TS_BUSY; /* register our DNS response listener */ - gnrc_netreg_entry_t entry = { NULL, ctxt->src_port, thread_getpid() }; + 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."); @@ -636,9 +637,8 @@ tftp_state _tftp_state_processes(tftp_context_t *ctxt, msg_t *m) } /* register a listener for the UDP port */ - ctxt->entry.next = NULL; - ctxt->entry.demux_ctx = ctxt->src_port; - ctxt->entry.pid = thread_getpid(); + gnrc_netreg_entry_init_pid(&(ctxt->entry), ctxt->src_port, + sched_active_pid); gnrc_netreg_register(GNRC_NETTYPE_UDP, &(ctxt->entry)); /* try to decode the options */ diff --git a/sys/net/gnrc/application_layer/zep/gnrc_zep.c b/sys/net/gnrc/application_layer/zep/gnrc_zep.c index 8f1eb8d88b..6953ec9af4 100644 --- a/sys/net/gnrc/application_layer/zep/gnrc_zep.c +++ b/sys/net/gnrc/application_layer/zep/gnrc_zep.c @@ -557,14 +557,11 @@ void *_event_loop(void *args) msg_t msg, ack, msg_q[GNRC_ZEP_MSG_QUEUE_SIZE]; gnrc_netdev_t *dev = (gnrc_netdev_t *)args; gnrc_netapi_opt_t *opt; - gnrc_netreg_entry_t my_reg = { NULL, ((gnrc_zep_t *)args)->src_port, - KERNEL_PID_UNDEF - }; + gnrc_netreg_entry_t my_reg = GNRC_NETREG_ENTRY_INIT_PID(((gnrc_zep_t *)args)->src_port, + sched_active_pid); msg_init_queue(msg_q, GNRC_ZEP_MSG_QUEUE_SIZE); - my_reg.pid = thread_getpid(); - gnrc_netreg_register(GNRC_NETTYPE_UDP, &my_reg); while (1) { diff --git a/sys/net/gnrc/nettest/gnrc_nettest.c b/sys/net/gnrc/nettest/gnrc_nettest.c index a2aaa15480..6838b81139 100644 --- a/sys/net/gnrc/nettest/gnrc_nettest.c +++ b/sys/net/gnrc/nettest/gnrc_nettest.c @@ -111,7 +111,8 @@ gnrc_nettest_res_t gnrc_nettest_send(kernel_pid_t pid, gnrc_pktsnip_t *in, const gnrc_pktsnip_t **exp_out, gnrc_nettype_t exp_type, uint32_t exp_demux_ctx) { - gnrc_netreg_entry_t reg_entry = { NULL, exp_demux_ctx, thread_getpid() }; + 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); @@ -147,7 +148,8 @@ gnrc_nettest_res_t gnrc_nettest_receive(kernel_pid_t pid, gnrc_pktsnip_t *in, const gnrc_pktsnip_t **exp_out, gnrc_nettype_t exp_type, uint32_t exp_demux_ctx) { - gnrc_netreg_entry_t reg_entry = { NULL, exp_demux_ctx, thread_getpid() }; + 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); diff --git a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c index 7a76c74c42..6d6314ed3a 100644 --- a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c +++ b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c @@ -251,14 +251,12 @@ static void _dispatch_next_header(gnrc_pktsnip_t *current, gnrc_pktsnip_t *pkt, static void *_event_loop(void *args) { msg_t msg, reply, msg_q[GNRC_IPV6_MSG_QUEUE_SIZE]; - gnrc_netreg_entry_t me_reg; + 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_IPV6_MSG_QUEUE_SIZE); - me_reg.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; - me_reg.pid = thread_getpid(); - /* register interest in all IPv6 packets */ gnrc_netreg_register(GNRC_NETTYPE_IPV6, &me_reg); diff --git a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c index 888afa685a..5aa4feb932 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c +++ b/sys/net/gnrc/network_layer/sixlowpan/gnrc_sixlowpan.c @@ -310,14 +310,12 @@ static void _send(gnrc_pktsnip_t *pkt) 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_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); - me_reg.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; - me_reg.pid = thread_getpid(); - /* register interest in all 6LoWPAN packets */ gnrc_netreg_register(GNRC_NETTYPE_SIXLOWPAN, &me_reg); diff --git a/sys/net/gnrc/transport_layer/udp/gnrc_udp.c b/sys/net/gnrc/transport_layer/udp/gnrc_udp.c index 3a75d3dd61..859117b79f 100644 --- a/sys/net/gnrc/transport_layer/udp/gnrc_udp.c +++ b/sys/net/gnrc/transport_layer/udp/gnrc_udp.c @@ -222,16 +222,14 @@ static void *_event_loop(void *arg) (void)arg; msg_t msg, reply; msg_t msg_queue[GNRC_UDP_MSG_QUEUE_SIZE]; - gnrc_netreg_entry_t netreg; - + gnrc_netreg_entry_t netreg = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + sched_active_pid); /* preset reply message */ reply.type = GNRC_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)-ENOTSUP; /* initialize message queue */ msg_init_queue(msg_queue, GNRC_UDP_MSG_QUEUE_SIZE); /* register UPD at netreg */ - netreg.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; - netreg.pid = thread_getpid(); gnrc_netreg_register(GNRC_NETTYPE_UDP, &netreg); /* dispatch NETAPI messages */ diff --git a/sys/shell/commands/sc_ccnl.c b/sys/shell/commands/sc_ccnl.c index 04243a63f6..3203578aa1 100644 --- a/sys/shell/commands/sc_ccnl.c +++ b/sys/shell/commands/sc_ccnl.c @@ -211,10 +211,10 @@ int _ccnl_interest(int argc, char **argv) memset(_int_buf, '\0', BUF_SIZE); memset(_cont_buf, '\0', BUF_SIZE); for (int cnt = 0; cnt < CCNL_INTEREST_RETRIES; cnt++) { - gnrc_netreg_entry_t _ne; + gnrc_netreg_entry_t _ne = + GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + sched_active_pid); /* register for content chunks */ - _ne.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; - _ne.pid = sched_active_pid; gnrc_netreg_register(GNRC_NETTYPE_CCN_CHUNK, &_ne); struct ccnl_prefix_s *prefix = ccnl_URItoPrefix(argv[1], CCNL_SUITE_NDNTLV, NULL, 0); diff --git a/sys/shell/commands/sc_icmpv6_echo.c b/sys/shell/commands/sc_icmpv6_echo.c index b49164ca1b..1ab7cbf7ee 100644 --- a/sys/shell/commands/sc_icmpv6_echo.c +++ b/sys/shell/commands/sc_icmpv6_echo.c @@ -153,7 +153,8 @@ int _icmpv6_ping(int argc, char **argv) ipv6_addr_t addr; kernel_pid_t src_iface; msg_t msg; - gnrc_netreg_entry_t my_entry = { NULL, ICMPV6_ECHO_REP, thread_getpid() }; + gnrc_netreg_entry_t my_entry = GNRC_NETREG_ENTRY_INIT_PID(ICMPV6_ECHO_REP, + sched_active_pid); uint32_t min_rtt = UINT32_MAX, max_rtt = 0; uint64_t sum_rtt = 0; uint64_t ping_start; diff --git a/tests/driver_kw2xrf/main.c b/tests/driver_kw2xrf/main.c index 199e8f9189..c0d6390fd3 100644 --- a/tests/driver_kw2xrf/main.c +++ b/tests/driver_kw2xrf/main.c @@ -26,14 +26,13 @@ int main(void) { - gnrc_netreg_entry_t dump; + gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + gnrc_pktdump_pid); puts("KW2XRF device driver test"); /* register the pktdump thread */ puts("Register the packet dump thread for GNRC_NETTYPE_UNDEF packets"); - dump.pid = gnrc_pktdump_pid; - dump.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump); /* start the shell */ diff --git a/tests/driver_nrfmin/main.c b/tests/driver_nrfmin/main.c index 15cf9e2070..c6b336b7b1 100644 --- a/tests/driver_nrfmin/main.c +++ b/tests/driver_nrfmin/main.c @@ -31,7 +31,8 @@ static char nomac_stack[THREAD_STACKSIZE_DEFAULT]; int main(void) { gnrc_netdev_t dev; - gnrc_netreg_entry_t netobj; + gnrc_netreg_entry_t netobj = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + gnrc_pktdump_pid); puts("\nManual test for the minimal NRF51822 radio driver\n"); puts("Use the 'ifconfig' and 'txtsnd' shell commands to verify the driver"); @@ -41,8 +42,6 @@ int main(void) gnrc_nomac_init(nomac_stack, sizeof(nomac_stack), 5, "nomac", &dev); /* initialize packet dumper */ - netobj.pid = gnrc_pktdump_pid; - netobj.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &netobj); /* initialize and run the shell */ diff --git a/tests/driver_xbee/main.c b/tests/driver_xbee/main.c index d9cc6a5f92..06b0ca4acf 100644 --- a/tests/driver_xbee/main.c +++ b/tests/driver_xbee/main.c @@ -30,17 +30,16 @@ */ int main(void) { - gnrc_netreg_entry_t dump; + 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 */ - dump.pid = gnrc_pktdump_pid; - if (dump.pid <= KERNEL_PID_UNDEF) { + if (gnrc_pktdump_pid <= KERNEL_PID_UNDEF) { puts("Error starting pktdump thread"); return -1; } - dump.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump); /* start the shell */ diff --git a/tests/gnrc_sixlowpan/main.c b/tests/gnrc_sixlowpan/main.c index de5e775e86..815915aae7 100644 --- a/tests/gnrc_sixlowpan/main.c +++ b/tests/gnrc_sixlowpan/main.c @@ -123,10 +123,10 @@ static void _send_packet(void) 0x00, 0x00, 0x00, 0x00, }; - gnrc_netreg_entry_t dump_6lowpan = { NULL, GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid }; - gnrc_netreg_entry_t dump_ipv6 = { NULL, GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid }; - gnrc_netreg_entry_t dump_udp = { NULL, GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pktdump_pid }; - gnrc_netreg_entry_t dump_udp_61616 = { NULL, 61616, gnrc_pktdump_pid }; + 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); diff --git a/tests/netdev2_test/main.c b/tests/netdev2_test/main.c index 637174ef74..53899d459f 100644 --- a/tests/netdev2_test/main.c +++ b/tests/netdev2_test/main.c @@ -133,8 +133,8 @@ static int test_receive(void) ethernet_hdr_t *rcv_mac = (ethernet_hdr_t *)_tmp; uint8_t *rcv_payload = _tmp + sizeof(ethernet_hdr_t); gnrc_pktsnip_t *pkt, *hdr; - gnrc_netreg_entry_t me = { NULL, GNRC_NETREG_DEMUX_CTX_ALL, - thread_getpid() }; + gnrc_netreg_entry_t me = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + sched_active_pid); msg_t msg; if (_dev.netdev.event_callback == NULL) { diff --git a/tests/slip/main.c b/tests/slip/main.c index ee718cf99e..6d7299ef99 100644 --- a/tests/slip/main.c +++ b/tests/slip/main.c @@ -30,14 +30,12 @@ */ int main(void) { - gnrc_netreg_entry_t dump; + gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + gnrc_pktdump_pid); puts("SLIP test"); - /* initialize and register pktdump */ - dump.pid = gnrc_pktdump_pid; - dump.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; - + /* register pktdump */ if (dump.pid <= KERNEL_PID_UNDEF) { puts("Error starting pktdump thread"); return -1; diff --git a/tests/unittests/tests-netreg/tests-netreg.c b/tests/unittests/tests-netreg/tests-netreg.c index 7a94adee68..d6b2d8a9a4 100644 --- a/tests/unittests/tests-netreg/tests-netreg.c +++ b/tests/unittests/tests-netreg/tests-netreg.c @@ -22,8 +22,8 @@ #include "tests-netreg.h" static gnrc_netreg_entry_t entries[] = { - { NULL, TEST_UINT16, TEST_UINT8 }, - { NULL, TEST_UINT16, TEST_UINT8 + 1 } + GNRC_NETREG_ENTRY_INIT_PID(TEST_UINT16, TEST_UINT8), + GNRC_NETREG_ENTRY_INIT_PID(TEST_UINT16, TEST_UINT8 + 1) }; static void set_up(void) diff --git a/tests/zep/main.c b/tests/zep/main.c index d34bb6131b..7965ebf3dd 100644 --- a/tests/zep/main.c +++ b/tests/zep/main.c @@ -30,19 +30,17 @@ */ int main(void) { - gnrc_netreg_entry_t dump; + gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + gnrc_pktdump_pid); puts("ZEP module test"); /* initialize and register pktdump */ - dump.pid = gnrc_pktdump_pid; - - if (dump.pid <= KERNEL_PID_UNDEF) { + if (gnrc_pktdump_pid <= KERNEL_PID_UNDEF) { puts("Error starting pktdump thread"); return -1; } - dump.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL; gnrc_netreg_register(GNRC_NETTYPE_NETIF, &dump); /* start the shell */