netreg.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
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 
21 #ifndef NET_GNRC_NETREG_H
22 #define NET_GNRC_NETREG_H
23 
24 #include <inttypes.h>
25 
26 #include "kernel_types.h"
27 #include "net/gnrc/nettype.h"
28 #include "net/gnrc/pkt.h"
29 
30 #ifdef MODULE_GNRC_NETAPI_MBOX
31 #include "mbox.h"
32 #endif
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) || \
39  defined(DOXYGEN)
40 
45 typedef enum {
54 #if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
55 
62 #endif
63 #if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
64 
71 #endif
73 #endif
74 
80 #define GNRC_NETREG_DEMUX_CTX_ALL (0xffff0000)
81 
91 #ifdef MODULE_GNRC_NETAPI_MBOX
92 #define GNRC_NETREG_ENTRY_INIT_PID(demux_ctx, pid) { NULL, demux_ctx, \
93  GNRC_NETREG_TYPE_DEFAULT, \
94  { pid } }
95 #else
96 #define GNRC_NETREG_ENTRY_INIT_PID(demux_ctx, pid) { NULL, demux_ctx, { pid } }
97 #endif
98 
99 #if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
100 
111 #define GNRC_NETREG_ENTRY_INIT_MBOX(demux_ctx, mbox) { NULL, demux_ctx, \
112  GNRC_NETREG_TYPE_MBOX, \
113  { .mbox = mbox } }
114 #endif
115 
116 #if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
117 
128 #define GNRC_NETREG_ENTRY_INIT_CB(demux_ctx, cbd) { NULL, demux_ctx, \
129  GNRC_NETREG_TYPE_CB, \
130  { .cbd = cbd } }
131 
145 typedef void (*gnrc_netreg_entry_cb_t)(uint16_t cmd, gnrc_pktsnip_t *pkt,
146  void *ctx);
147 
152 typedef struct {
154  void *ctx;
156 #endif
157 
161 typedef struct gnrc_netreg_entry {
168 
176  uint32_t demux_ctx;
177 #if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) || \
178  defined(DOXYGEN)
179 
185  gnrc_netreg_type_t type;
186 #endif
187  union {
189 #if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
190 
196 #endif
197 
198 #if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
199 
205 #endif
206  } target;
208 
212 void gnrc_netreg_init(void);
213 
224  uint32_t demux_ctx,
226 {
227  entry->next = NULL;
228  entry->demux_ctx = demux_ctx;
229 #if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS)
231 #endif
232  entry->target.pid = pid;
233 }
234 
235 #if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
236 
247  uint32_t demux_ctx,
248  mbox_t *mbox)
249 {
250  entry->next = NULL;
251  entry->demux_ctx = demux_ctx;
252  entry->type = GNRC_NETREG_TYPE_MBOX;
253  entry->target.mbox = mbox;
254 }
255 #endif
256 
257 #if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
258 
269  uint32_t demux_ctx,
271 {
272  entry->next = NULL;
273  entry->demux_ctx = demux_ctx;
274  entry->type = GNRC_NETREG_TYPE_CB;
275  entry->target.cbd = cbd;
276 }
277 #endif
278 
299 
307 
320 
332 int gnrc_netreg_num(gnrc_nettype_t type, uint32_t demux_ctx);
333 
346 
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 
367 #endif /* NET_GNRC_NETREG_H */
368 
Types used by the kernel.
void(* gnrc_netreg_entry_cb_t)(uint16_t cmd, gnrc_pktsnip_t *pkt, void *ctx)
Packet handler callback for netreg entries with callback.
Definition: netreg.h:145
Entry to the Network protocol registry.
Definition: netreg.h:161
mbox_t * mbox
Target mailbox for the registry entry.
Definition: netreg.h:195
Mailbox struct definition.
Definition: mbox.h:39
Mailbox API.
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
void gnrc_netreg_unregister(gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
Removes a thread from the registry.
General definitions for network packets and their helper functions.
union gnrc_netreg_entry::@166 target
Target for the registry entry.
gnrc_netreg_entry_t * gnrc_netreg_lookup(gnrc_nettype_t type, uint32_t demux_ctx)
Searches for entries with given parameters in the registry and returns the first found.
uint32_t demux_ctx
The demultiplexing context for the registering thread.
Definition: netreg.h:176
gnrc_netreg_entry_cb_t cb
the callback
Definition: netreg.h:153
static void gnrc_netreg_entry_init_cb(gnrc_netreg_entry_t *entry, uint32_t demux_ctx, gnrc_netreg_entry_cbd_t *cbd)
Initializes a netreg entry dynamically with callback.
Definition: netreg.h:268
gnrc_netreg_type_t type
Type of the registry entry.
Definition: netreg.h:185
Callback + Context descriptor.
Definition: netreg.h:152
struct gnrc_netreg_entry gnrc_netreg_entry_t
Entry to the Network protocol registry.
Use default IPC for netapi operations.
Definition: netreg.h:53
void * ctx
application context for the callback
Definition: netreg.h:154
struct gnrc_netreg_entry * next
next element in list
Definition: netreg.h:167
static void gnrc_netreg_entry_init_pid(gnrc_netreg_entry_t *entry, uint32_t demux_ctx, kernel_pid_t pid)
Initializes a netreg entry dynamically with PID.
Definition: netreg.h:223
gnrc_netreg_type_t
The type of the netreg entry.
Definition: netreg.h:45
gnrc_netreg_entry_t * gnrc_netreg_getnext(gnrc_netreg_entry_t *entry)
Returns the next entry after entry with the same gnrc_netreg_entry_t::type and gnrc_netreg_entry_t::d...
int gnrc_netreg_register(gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
Registers a thread to the registry.
Use centralized IPC for netapi operations.
Definition: netreg.h:61
static void gnrc_netreg_entry_init_mbox(gnrc_netreg_entry_t *entry, uint32_t demux_ctx, mbox_t *mbox)
Initializes a netreg entry dynamically with mbox.
Definition: netreg.h:246
Adds include for missing inttype definitions.
int gnrc_netreg_calc_csum(gnrc_pktsnip_t *hdr, gnrc_pktsnip_t *pseudo_hdr)
Calculates the checksum for a header.
void gnrc_netreg_init(void)
Initializes module.
Type to represent parts (either headers or payload) of a packet, called snips.
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:42
kernel_pid_t pid
The PID of the registering thread.
Definition: netreg.h:188
int gnrc_netreg_num(gnrc_nettype_t type, uint32_t demux_ctx)
Returns number of entries with the same gnrc_netreg_entry_t::type and gnrc_netreg_entry_t::demux_ctx...
Use function callbacks for netapi operations.
Definition: netreg.h:70
gnrc_netreg_entry_cbd_t * cbd
Target callback for the registry entry.
Definition: netreg.h:204
Protocol type definitions.