netapi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
59 #ifndef NET_GNRC_NETAPI_H
60 #define NET_GNRC_NETAPI_H
61 
62 #include "thread.h"
63 #include "net/netopt.h"
64 #include "net/gnrc/nettype.h"
65 #include "net/gnrc/pkt.h"
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
74 #define GNRC_NETAPI_MSG_TYPE_RCV (0x0201)
75 
79 #define GNRC_NETAPI_MSG_TYPE_SND (0x0202)
80 
84 #define GNRC_NETAPI_MSG_TYPE_SET (0x0203)
85 
89 #define GNRC_NETAPI_MSG_TYPE_GET (0x0204)
90 
94 #define GNRC_NETAPI_MSG_TYPE_ACK (0x0205)
95 
100 typedef struct {
102  uint16_t context;
103  void *data;
104  uint16_t data_len;
106 
120 int _gnrc_netapi_send_recv(kernel_pid_t pid, gnrc_pktsnip_t *pkt, uint16_t type);
121 
141 int _gnrc_netapi_get_set(kernel_pid_t pid, netopt_t opt, uint16_t context,
142  void *data, size_t data_len, uint16_t type);
143 
144 
154 static inline int gnrc_netapi_send(kernel_pid_t pid, gnrc_pktsnip_t *pkt)
155 {
157 }
158 
169 int gnrc_netapi_dispatch(gnrc_nettype_t type, uint32_t demux_ctx, uint16_t cmd,
170  gnrc_pktsnip_t *pkt);
171 
182 static inline int gnrc_netapi_dispatch_send(gnrc_nettype_t type, uint32_t demux_ctx,
183  gnrc_pktsnip_t *pkt)
184 {
185  return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_SND, pkt);
186 }
187 
197 static inline int gnrc_netapi_receive(kernel_pid_t pid, gnrc_pktsnip_t *pkt)
198 {
200 }
201 
212 static inline int gnrc_netapi_dispatch_receive(gnrc_nettype_t type, uint32_t demux_ctx,
213  gnrc_pktsnip_t *pkt)
214 {
215  return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_RCV, pkt);
216 }
217 
233 static inline int gnrc_netapi_get(kernel_pid_t pid, netopt_t opt,
234  uint16_t context, void *data, size_t max_len)
235 {
236  return _gnrc_netapi_get_set(pid, opt, context, data, max_len,
238 }
239 
255 static inline int gnrc_netapi_set(kernel_pid_t pid, netopt_t opt,
256  uint16_t context, const void *data,
257  size_t data_len)
258 {
259  /* disregard const pointer. This *should* be safe and any modification
260  * to `data` should be considered a bug */
261  return _gnrc_netapi_get_set(pid, opt, context, (void *)data, data_len,
263 }
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 #endif /* NET_GNRC_NETAPI_H */
270 
kernel_pid_t
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:125
netopt_t
netopt_t
Global list of configuration options available throughout the network stack, e.g.
Definition: netopt.h:50
gnrc_netapi_get
static int gnrc_netapi_get(kernel_pid_t pid, netopt_t opt, uint16_t context, void *data, size_t max_len)
Shortcut function for sending GNRC_NETAPI_MSG_TYPE_GET messages and parsing the returned GNRC_NETAPI_...
Definition: netapi.h:233
_gnrc_netapi_send_recv
int _gnrc_netapi_send_recv(kernel_pid_t pid, gnrc_pktsnip_t *pkt, uint16_t type)
Shortcut function for sending GNRC_NETAPI_MSG_TYPE_SND or GNRC_NETAPI_MSG_TYPE_RCV messages.
GNRC_NETAPI_MSG_TYPE_SND
#define GNRC_NETAPI_MSG_TYPE_SND
Messaging / IPC type for passing a Packet down the network stack
Definition: netapi.h:79
gnrc_netapi_opt_t::opt
netopt_t opt
the option to get/set
Definition: netapi.h:101
gnrc_netapi_opt_t
Data structure to be send for setting (GNRC_NETAPI_MSG_TYPE_SET) and getting (GNRC_NETAPI_MSG_TYPE_GE...
Definition: netapi.h:100
netopt.h
Definition of global configuration options.
gnrc_netapi_opt_t::data_len
uint16_t data_len
size of the data / the buffer
Definition: netapi.h:104
gnrc_netapi_send
static int gnrc_netapi_send(kernel_pid_t pid, gnrc_pktsnip_t *pkt)
Shortcut function for sending GNRC_NETAPI_MSG_TYPE_SND messages.
Definition: netapi.h:154
gnrc_netapi_set
static int gnrc_netapi_set(kernel_pid_t pid, netopt_t opt, uint16_t context, const void *data, size_t data_len)
Shortcut function for sending GNRC_NETAPI_MSG_TYPE_SET messages and parsing the returned GNRC_NETAPI_...
Definition: netapi.h:255
GNRC_NETAPI_MSG_TYPE_RCV
#define GNRC_NETAPI_MSG_TYPE_RCV
Messaging / IPC type for passing a Packet up the network stack
Definition: netapi.h:74
gnrc_netapi_receive
static int gnrc_netapi_receive(kernel_pid_t pid, gnrc_pktsnip_t *pkt)
Shortcut function for sending GNRC_NETAPI_MSG_TYPE_RCV messages.
Definition: netapi.h:197
GNRC_NETAPI_MSG_TYPE_GET
#define GNRC_NETAPI_MSG_TYPE_GET
Messaging / IPC type for getting options from network modules
Definition: netapi.h:89
pkt.h
General definitions for network packets and their helper functions.
nettype.h
Protocol type definitions.
gnrc_netapi_dispatch_send
static int gnrc_netapi_dispatch_send(gnrc_nettype_t type, uint32_t demux_ctx, gnrc_pktsnip_t *pkt)
Sends a GNRC_NETAPI_MSG_TYPE_SND command to all subscribers to (type, demux_ctx).
Definition: netapi.h:182
GNRC_NETAPI_MSG_TYPE_SET
#define GNRC_NETAPI_MSG_TYPE_SET
Messaging / IPC type for setting options of network modules
Definition: netapi.h:84
gnrc_netapi_opt_t::context
uint16_t context
(optional) context for that option
Definition: netapi.h:102
_gnrc_netapi_get_set
int _gnrc_netapi_get_set(kernel_pid_t pid, netopt_t opt, uint16_t context, void *data, size_t data_len, uint16_t type)
Shortcut function for sending GNRC_NETAPI_MSG_TYPE_GET or GNRC_NETAPI_MSG_TYPE_SET messages and parsi...
gnrc_nettype_t
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:50
gnrc_netapi_dispatch_receive
static int gnrc_netapi_dispatch_receive(gnrc_nettype_t type, uint32_t demux_ctx, gnrc_pktsnip_t *pkt)
Sends a GNRC_NETAPI_MSG_TYPE_RCV command to all subscribers to (type, demux_ctx).
Definition: netapi.h:212
gnrc_netapi_opt_t::data
void * data
data to set or buffer to read into
Definition: netapi.h:103
gnrc_netapi_dispatch
int gnrc_netapi_dispatch(gnrc_nettype_t type, uint32_t demux_ctx, uint16_t cmd, gnrc_pktsnip_t *pkt)
Sends cmd to all subscribers to (type, demux_ctx).
gnrc_pktsnip
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:108