Loading...
Searching...
No Matches
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
9#pragma once
10
60
61#include "compiler_hints.h"
63#include "net/gnrc/nettype.h"
64#include "net/gnrc/pkt.h"
65#include "net/netopt.h"
66#include "thread.h"
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
75#define GNRC_NETAPI_MSG_TYPE_RCV (0x0201)
76
80#define GNRC_NETAPI_MSG_TYPE_SND (0x0202)
81
85#define GNRC_NETAPI_MSG_TYPE_SET (0x0203)
86
90#define GNRC_NETAPI_MSG_TYPE_GET (0x0204)
91
95#define GNRC_NETAPI_MSG_TYPE_ACK (0x0205)
96
102#define GNRC_NETAPI_MSG_TYPE_NOTIFY (0x0207)
103
108typedef struct {
110 uint16_t context;
111 void *data;
112 uint16_t data_len;
114
129
149int _gnrc_netapi_get_set(kernel_pid_t pid, netopt_t opt, uint16_t context,
150 void *data, size_t data_len, uint16_t type);
151
161static inline int gnrc_netapi_send(kernel_pid_t pid, gnrc_pktsnip_t *pkt)
162{
164}
165
176int gnrc_netapi_dispatch(gnrc_nettype_t type, uint32_t demux_ctx, uint16_t cmd,
177 gnrc_pktsnip_t *pkt);
178
189static inline int gnrc_netapi_dispatch_send(gnrc_nettype_t type, uint32_t demux_ctx,
190 gnrc_pktsnip_t *pkt)
191{
192 return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_SND, pkt);
193}
194
210ACCESS(read_write, 4, 5)
212 void *data, size_t data_len);
213
224{
226}
227
238static inline int gnrc_netapi_dispatch_receive(gnrc_nettype_t type, uint32_t demux_ctx,
239 gnrc_pktsnip_t *pkt)
240{
241 return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_RCV, pkt);
242}
243
259ACCESS(write_only, 4, 5)
260static inline int gnrc_netapi_get(kernel_pid_t pid, netopt_t opt,
261 uint16_t context, void *data, size_t max_len)
262{
263 return _gnrc_netapi_get_set(pid, opt, context, data, max_len,
265}
266
282ACCESS(read_only, 4, 5)
283static inline int gnrc_netapi_set(kernel_pid_t pid, netopt_t opt,
284 uint16_t context, const void *data,
285 size_t data_len)
286{
287 /* disregard const pointer. This *should* be safe and any modification
288 * to `data` should be considered a bug */
289 return _gnrc_netapi_get_set(pid, opt, context, (void *)data, data_len,
291}
292
293#ifdef __cplusplus
294}
295#endif
296
Common macros and compiler attributes/pragmas configuration.
#define ACCESS(mode, ptr_idx, size_idx)
Emit an attribute (if supported by the compiler) that declares how a function will access its paramet...
int16_t kernel_pid_t
Unique process identifier.
Definition sched.h:134
netapi_notify_t
Definition of notification event types in the network stack.
Definition notify.h:49
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:238
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:189
#define GNRC_NETAPI_MSG_TYPE_RCV
Messaging / IPC type for passing a Packet up the network stack
Definition netapi.h:75
#define GNRC_NETAPI_MSG_TYPE_SET
Messaging / IPC type for setting options of network modules
Definition netapi.h:85
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:283
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:260
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_notify(gnrc_nettype_t type, uint32_t demux_ctx, netapi_notify_t event, void *data, size_t data_len)
Sends a GNRC_NETAPI_MSG_TYPE_NOTIFY command 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:90
#define GNRC_NETAPI_MSG_TYPE_SND
Messaging / IPC type for passing a Packet down the network stack
Definition netapi.h:80
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:223
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:161
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition nettype.h:51
struct gnrc_pktsnip gnrc_pktsnip_t
Type to represent parts (either headers or payload) of a packet, called snips.
netopt_t
Global list of configuration options available throughout the network stack, e.g.
Definition netopt.h:44
General definitions for network packets and their helper functions.
Definition of global configuration options.
Protocol type definitions.
Network event notification type definitions.
event structure
Definition event.h:145
Data structure to be send for setting (GNRC_NETAPI_MSG_TYPE_SET) and getting (GNRC_NETAPI_MSG_TYPE_GE...
Definition netapi.h:108
uint16_t data_len
size of the data / the buffer
Definition netapi.h:112
void * data
data to set or buffer to read into
Definition netapi.h:111
uint16_t context
(optional) context for that option
Definition netapi.h:110
netopt_t opt
the option to get/set
Definition netapi.h:109