Loading...
Searching...
No Matches
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 "sched.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
35extern "C" {
36#endif
37
38#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) || \
39 defined(DOXYGEN)
45typedef enum {
54#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
62#endif
63#if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
71#endif
73#endif
74
80#define GNRC_NETREG_DEMUX_CTX_ALL (0xffff0000)
81
96#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS)
97#define GNRC_NETREG_ENTRY_INIT_PID(demux_ctx, pid) { NULL, demux_ctx, \
98 GNRC_NETREG_TYPE_DEFAULT, \
99 { pid } }
100#else
101#define GNRC_NETREG_ENTRY_INIT_PID(demux_ctx, pid) { NULL, demux_ctx, { pid } }
102#endif
103
104#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
116#define GNRC_NETREG_ENTRY_INIT_MBOX(demux_ctx, _mbox) { NULL, demux_ctx, \
117 GNRC_NETREG_TYPE_MBOX, \
118 { .mbox = _mbox } }
119#endif
120
121#if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
133#define GNRC_NETREG_ENTRY_INIT_CB(demux_ctx, _cbd) { NULL, demux_ctx, \
134 GNRC_NETREG_TYPE_CB, \
135 { .cbd = _cbd } }
151typedef void (*gnrc_netreg_entry_cb_t)(uint16_t cmd, gnrc_pktsnip_t *pkt,
152 void *ctx);
153
162#endif
163
167typedef struct gnrc_netreg_entry {
174
182 uint32_t demux_ctx;
183#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) || \
184 defined(DOXYGEN)
192#endif
193 union {
195#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
202#endif
203
204#if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
211#endif
214
250
257
273 uint32_t demux_ctx,
274 kernel_pid_t pid)
275{
276 entry->next = NULL;
277 entry->demux_ctx = demux_ctx;
278#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS)
280#endif
281 entry->target.pid = pid;
282}
283
284#if defined(MODULE_GNRC_NETAPI_MBOX) || defined(DOXYGEN)
296 uint32_t demux_ctx,
297 mbox_t *mbox)
298{
299 entry->next = NULL;
300 entry->demux_ctx = demux_ctx;
302 entry->target.mbox = mbox;
303}
304#endif
305
306#if defined(MODULE_GNRC_NETAPI_CALLBACKS) || defined(DOXYGEN)
318 uint32_t demux_ctx,
320{
321 entry->next = NULL;
322 entry->demux_ctx = demux_ctx;
323 entry->type = GNRC_NETREG_TYPE_CB;
324 entry->target.cbd = cbd;
325}
326#endif
354
362
379
398int gnrc_netreg_num(gnrc_nettype_t type, uint32_t demux_ctx);
399
417
433
434#ifdef __cplusplus
435}
436#endif
437
438#endif /* NET_GNRC_NETREG_H */
int16_t kernel_pid_t
Unique process identifier.
Definition sched.h:139
void gnrc_netreg_acquire_shared(void)
The global locking of netregs.
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.
int gnrc_netreg_calc_csum(gnrc_pktsnip_t *hdr, gnrc_pktsnip_t *pseudo_hdr)
Calculates the checksum for a header.
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:295
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.
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:151
gnrc_netreg_type_t
The type of the netreg entry.
Definition netreg.h:45
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:272
void gnrc_netreg_release_shared(void)
Release a shared lock on the GNRC netreg.
struct gnrc_netreg_entry gnrc_netreg_entry_t
Entry to the Network protocol registry.
void gnrc_netreg_init(void)
Initializes module.
void gnrc_netreg_unregister(gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
Removes a thread from the registry.
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:317
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.
@ GNRC_NETREG_TYPE_DEFAULT
Use default IPC for netapi operations.
Definition netreg.h:53
@ GNRC_NETREG_TYPE_MBOX
Use centralized IPC for netapi operations.
Definition netreg.h:61
@ GNRC_NETREG_TYPE_CB
Use function callbacks for netapi operations.
Definition netreg.h:70
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition nettype.h:51
Adds include for missing inttype definitions.
Mailbox API.
General definitions for network packets and their helper functions.
Protocol type definitions.
Scheduler API definition.
Callback + Context descriptor.
Definition netreg.h:158
gnrc_netreg_entry_cb_t cb
the callback
Definition netreg.h:159
void * ctx
application context for the callback
Definition netreg.h:160
Entry to the Network protocol registry.
Definition netreg.h:167
uint32_t demux_ctx
The demultiplexing context for the registering thread.
Definition netreg.h:182
struct gnrc_netreg_entry * next
next element in list
Definition netreg.h:173
mbox_t * mbox
Target mailbox for the registry entry.
Definition netreg.h:201
kernel_pid_t pid
The PID of the registering thread.
Definition netreg.h:194
union gnrc_netreg_entry::@370 target
Target for the registry entry.
gnrc_netreg_entry_cbd_t * cbd
Target callback for the registry entry.
Definition netreg.h:210
gnrc_netreg_type_t type
Type of the registry entry.
Definition netreg.h:191
Type to represent parts (either headers or payload) of a packet, called snips.
Definition pkt.h:108
Mailbox struct definition.
Definition mbox.h:41