netapi.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2015 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
58 #include "thread.h"
59 #include "net/netopt.h"
60 #include "net/gnrc/nettype.h"
61 #include "net/gnrc/pkt.h"
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
70 #define GNRC_NETAPI_MSG_TYPE_RCV (0x0201)
71 
75 #define GNRC_NETAPI_MSG_TYPE_SND (0x0202)
76 
80 #define GNRC_NETAPI_MSG_TYPE_SET (0x0203)
81 
85 #define GNRC_NETAPI_MSG_TYPE_GET (0x0204)
86 
90 #define GNRC_NETAPI_MSG_TYPE_ACK (0x0205)
91 
96 typedef struct {
98  uint16_t context;
99  void *data;
100  uint16_t data_len;
102 
116 int _gnrc_netapi_send_recv(kernel_pid_t pid, gnrc_pktsnip_t *pkt, uint16_t type);
117 
137 int _gnrc_netapi_get_set(kernel_pid_t pid, netopt_t opt, uint16_t context,
138  void *data, size_t data_len, uint16_t type);
139 
149 static inline int gnrc_netapi_send(kernel_pid_t pid, gnrc_pktsnip_t *pkt)
150 {
152 }
153 
164 int gnrc_netapi_dispatch(gnrc_nettype_t type, uint32_t demux_ctx, uint16_t cmd,
165  gnrc_pktsnip_t *pkt);
166 
177 static inline int gnrc_netapi_dispatch_send(gnrc_nettype_t type, uint32_t demux_ctx,
178  gnrc_pktsnip_t *pkt)
179 {
180  return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_SND, pkt);
181 }
182 
192 static inline int gnrc_netapi_receive(kernel_pid_t pid, gnrc_pktsnip_t *pkt)
193 {
195 }
196 
207 static inline int gnrc_netapi_dispatch_receive(gnrc_nettype_t type, uint32_t demux_ctx,
208  gnrc_pktsnip_t *pkt)
209 {
210  return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_RCV, pkt);
211 }
212 
228 static inline int gnrc_netapi_get(kernel_pid_t pid, netopt_t opt,
229  uint16_t context, void *data, size_t max_len)
230 {
231  return _gnrc_netapi_get_set(pid, opt, context, data, max_len,
233 }
234 
250 static inline int gnrc_netapi_set(kernel_pid_t pid, netopt_t opt,
251  uint16_t context, const void *data,
252  size_t data_len)
253 {
254  /* disregard const pointer. This *should* be safe and any modification
255  * to `data` should be considered a bug */
256  return _gnrc_netapi_get_set(pid, opt, context, (void *)data, data_len,
258 }
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:135
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:207
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:177
#define GNRC_NETAPI_MSG_TYPE_RCV
Messaging / IPC type for passing a Packet up the network stack
Definition: netapi.h:70
#define GNRC_NETAPI_MSG_TYPE_SET
Messaging / IPC type for setting options of network modules
Definition: netapi.h:80
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:250
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:228
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).
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...
#define GNRC_NETAPI_MSG_TYPE_GET
Messaging / IPC type for getting options from network modules
Definition: netapi.h:85
#define GNRC_NETAPI_MSG_TYPE_SND
Messaging / IPC type for passing a Packet down the network stack
Definition: netapi.h:75
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.
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:192
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:149
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:48
netopt_t
Global list of configuration options available throughout the network stack, e.g.
Definition: netopt.h:41
General definitions for network packets and their helper functions.
Definition of global configuration options.
Protocol type definitions.
Data structure to be send for setting (GNRC_NETAPI_MSG_TYPE_SET) and getting (GNRC_NETAPI_MSG_TYPE_GE...
Definition: netapi.h:96
uint16_t data_len
size of the data / the buffer
Definition: netapi.h:100
void * data
data to set or buffer to read into
Definition: netapi.h:99
uint16_t context
(optional) context for that option
Definition: netapi.h:98
netopt_t opt
the option to get/set
Definition: netapi.h:97
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:105