diff --git a/sys/include/net/ng_netapi.h b/sys/include/net/ng_netapi.h index 3116a8e70209b1fc9f2669b0c063dc316a3d50a9..9bf4b772b54e3e1b33a6662eaff5bb8c52b3f291 100644 --- a/sys/include/net/ng_netapi.h +++ b/sys/include/net/ng_netapi.h @@ -31,6 +31,7 @@ #include "kernel.h" #include "thread.h" #include "net/ng_netconf.h" +#include "net/ng_nettype.h" #include "net/ng_pkt.h" #ifdef __cplusplus @@ -83,6 +84,19 @@ typedef struct { */ int ng_netapi_send(kernel_pid_t pid, ng_pktsnip_t *pkt); +/** + * @brief Sends a @ref NG_NETAPI_MSG_TYPE_SND command to all subscribers to + * (@p type, @p demux_ctx). + * + * @param[in] type type of the targeted network module. + * @param[in] demux_ctx demultiplexing context for @p type. + * @param[in] pkt pointer into the packet buffer holding the data to send + * + * @return Number of subscribers to (@p type, @p demux_ctx). + */ +int ng_netapi_dispatch_send(ng_nettype_t type, uint32_t demux_ctx, + ng_pktsnip_t *pkt); + /** * @brief Shortcut function for sending @ref NG_NETAPI_MSG_TYPE_RCV messages * @@ -94,6 +108,19 @@ int ng_netapi_send(kernel_pid_t pid, ng_pktsnip_t *pkt); */ int ng_netapi_receive(kernel_pid_t pid, ng_pktsnip_t *pkt); +/** + * @brief Sends a @ref NG_NETAPI_MSG_TYPE_RCV command to all subscribers to + * (@p type, @p demux_ctx). + * + * @param[in] type type of the targeted network module. + * @param[in] demux_ctx demultiplexing context for @p type. + * @param[in] pkt pointer into the packet buffer holding the data to send + * + * @return Number of subscribers to (@p type, @p demux_ctx). + */ +int ng_netapi_dispatch_receive(ng_nettype_t type, uint32_t demux_ctx, + ng_pktsnip_t *pkt); + /** * @brief Shortcut function for sending @ref NG_NETAPI_MSG_TYPE_GET messages and * parsing the returned @ref NG_NETAPI_MSG_TYPE_ACK message diff --git a/sys/net/crosslayer/ng_netapi/ng_netapi.c b/sys/net/crosslayer/ng_netapi/ng_netapi.c index 97894dd5631f0925b73f06b9c9d29e4bf847bd6a..c2a3593104341736130578741adf6bb2b3581d16 100644 --- a/sys/net/crosslayer/ng_netapi/ng_netapi.c +++ b/sys/net/crosslayer/ng_netapi/ng_netapi.c @@ -20,6 +20,8 @@ #include "kernel.h" #include "msg.h" +#include "net/ng_netreg.h" +#include "net/ng_pktbuf.h" #include "net/ng_netapi.h" /** @@ -64,16 +66,47 @@ static inline int _snd_rcv(kernel_pid_t pid, uint16_t type, ng_pktsnip_t *pkt) return msg_send(&msg, pid); } +static inline int _snd_rcv_dispatch(ng_nettype_t type, uint32_t demux_ctx, + uint16_t cmd, ng_pktsnip_t *pkt) +{ + int numof = ng_netreg_num(type, demux_ctx); + ng_netreg_entry_t *sendto; + + if (numof != 0) { + sendto = ng_netreg_lookup(type, demux_ctx); + + ng_pktbuf_hold(pkt, numof - 1); + + while (sendto) { + _snd_rcv(sendto->pid, cmd, pkt); + sendto = ng_netreg_getnext(sendto); + } + } + + return numof; +} int ng_netapi_send(kernel_pid_t pid, ng_pktsnip_t *pkt) { return _snd_rcv(pid, NG_NETAPI_MSG_TYPE_SND, pkt); } +int ng_netapi_dispatch_send(ng_nettype_t type, uint32_t demux_ctx, + ng_pktsnip_t *pkt) +{ + return _snd_rcv_dispatch(type, demux_ctx, NG_NETAPI_MSG_TYPE_SND, pkt); +} + int ng_netapi_receive(kernel_pid_t pid, ng_pktsnip_t *pkt) { return _snd_rcv(pid, NG_NETAPI_MSG_TYPE_RCV, pkt); } +int ng_netapi_dispatch_receive(ng_nettype_t type, uint32_t demux_ctx, + ng_pktsnip_t *pkt) +{ + return _snd_rcv_dispatch(type, demux_ctx, NG_NETAPI_MSG_TYPE_RCV, pkt); +} + int ng_netapi_get(kernel_pid_t pid, ng_netconf_opt_t opt, uint16_t context, void *data, size_t data_len) {