From 326a40214844b331a66a10227128e5d3ea9332cc Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 20 Mar 2015 19:21:44 +0100 Subject: [PATCH] ng_netapi: introduce ng_netapi_receive() --- sys/include/net/ng_netapi.h | 11 +++++++++++ sys/net/crosslayer/ng_netapi/ng_netapi.c | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sys/include/net/ng_netapi.h b/sys/include/net/ng_netapi.h index 2bd01938e2..3116a8e702 100644 --- a/sys/include/net/ng_netapi.h +++ b/sys/include/net/ng_netapi.h @@ -83,6 +83,17 @@ typedef struct { */ int ng_netapi_send(kernel_pid_t pid, ng_pktsnip_t *pkt); +/** + * @brief Shortcut function for sending @ref NG_NETAPI_MSG_TYPE_RCV messages + * + * @param[in] pid PID of the targeted network module + * @param[in] pkt pointer into the packet buffer holding the received data + * + * @return 1 if packet was successfully delivered + * @return -1 on error (invalid PID or no space in queue) + */ +int ng_netapi_receive(kernel_pid_t pid, 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 df5eb60724..97894dd563 100644 --- a/sys/net/crosslayer/ng_netapi/ng_netapi.c +++ b/sys/net/crosslayer/ng_netapi/ng_netapi.c @@ -54,16 +54,26 @@ static inline int _get_set(kernel_pid_t pid, uint16_t type, return (int)ack.content.value; } -int ng_netapi_send(kernel_pid_t pid, ng_pktsnip_t *pkt) +static inline int _snd_rcv(kernel_pid_t pid, uint16_t type, ng_pktsnip_t *pkt) { msg_t msg; /* set the outgoing message's fields */ - msg.type = NG_NETAPI_MSG_TYPE_SND; + msg.type = type; msg.content.ptr = (void *)pkt; - /* send data using netapi */ + /* send message */ return msg_send(&msg, pid); } +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_receive(kernel_pid_t pid, ng_pktsnip_t *pkt) +{ + return _snd_rcv(pid, 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) {