Network protocol registry

Registry to receive messages of a specified protocol type by GNRC. More...

Detailed Description

Files

file  netreg.h
 Definitions to register network protocol PIDs to use with GNRC communication interface.
 

Data Structures

struct  gnrc_netreg_entry_cbd_t
 Callback + Context descriptor. More...
 
struct  gnrc_netreg_entry
 Entry to the Network protocol registry. More...
 

Macros

#define GNRC_NETREG_DEMUX_CTX_ALL   (0xffff0000)
 Demux context value to get all packets of a certain type. More...
 
#define GNRC_NETREG_ENTRY_INIT_PID(demux_ctx, pid)   { NULL, demux_ctx, { pid } }
 Initializes a netreg entry statically with PID. More...
 
#define GNRC_NETREG_ENTRY_INIT_MBOX(demux_ctx, mbox)
 Initializes a netreg entry statically with mbox. More...
 
#define GNRC_NETREG_ENTRY_INIT_CB(demux_ctx, cbd)
 Initializes a netreg entry statically with callback. More...
 

Typedefs

typedef void(* gnrc_netreg_entry_cb_t) (uint16_t cmd, gnrc_pktsnip_t *pkt, void *ctx)
 Packet handler callback for netreg entries with callback. More...
 
typedef struct gnrc_netreg_entry gnrc_netreg_entry_t
 Entry to the Network protocol registry.
 

Enumerations

enum  gnrc_netreg_type_t { GNRC_NETREG_TYPE_DEFAULT = 0, GNRC_NETREG_TYPE_MBOX, GNRC_NETREG_TYPE_CB }
 The type of the netreg entry. More...
 

Functions

void gnrc_netreg_init (void)
 Initializes module.
 
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. More...
 
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. More...
 
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. More...
 
int gnrc_netreg_register (gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
 Registers a thread to the registry. More...
 
void gnrc_netreg_unregister (gnrc_nettype_t type, gnrc_netreg_entry_t *entry)
 Removes a thread from the registry. More...
 
gnrc_netreg_entry_tgnrc_netreg_lookup (gnrc_nettype_t type, uint32_t demux_ctx)
 Searches for entries with given parameters in the registry and returns the first found. More...
 
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. More...
 
gnrc_netreg_entry_tgnrc_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::demux_ctx as the given entry. More...
 
int gnrc_netreg_calc_csum (gnrc_pktsnip_t *hdr, gnrc_pktsnip_t *pseudo_hdr)
 Calculates the checksum for a header. More...
 

Macro Definition Documentation

◆ GNRC_NETREG_DEMUX_CTX_ALL

#define GNRC_NETREG_DEMUX_CTX_ALL   (0xffff0000)
See also
gnrc_netreg_entry_t::demux_ctx

Definition at line 80 of file netreg.h.

◆ GNRC_NETREG_ENTRY_INIT_CB

#define GNRC_NETREG_ENTRY_INIT_CB (   demux_ctx,
  cbd 
)
Value:
{ NULL, demux_ctx, \
GNRC_NETREG_TYPE_CB, \
{ .cbd = cbd } }
Parameters
[in]demux_ctxThe demux context for the netreg entry
[in]cbdTarget callback for the registry entry
Note
Only available with Callback extension.
Returns
An initialized netreg entry

Definition at line 128 of file netreg.h.

◆ GNRC_NETREG_ENTRY_INIT_MBOX

#define GNRC_NETREG_ENTRY_INIT_MBOX (   demux_ctx,
  mbox 
)
Value:
{ NULL, demux_ctx, \
GNRC_NETREG_TYPE_MBOX, \
{ .mbox = mbox } }
Parameters
[in]demux_ctxThe demux context for the netreg entry
[in]mboxTarget mailbox for the registry entry
Note
Only available with Mailbox IPC extension.
Returns
An initialized netreg entry

Definition at line 111 of file netreg.h.

◆ GNRC_NETREG_ENTRY_INIT_PID

#define GNRC_NETREG_ENTRY_INIT_PID (   demux_ctx,
  pid 
)    { NULL, demux_ctx, { pid } }
Parameters
[in]demux_ctxThe demux context for the netreg entry
[in]pidThe PID of the registering thread
Returns
An initialized netreg entry

Definition at line 96 of file netreg.h.

Typedef Documentation

◆ gnrc_netreg_entry_cb_t

typedef void(* gnrc_netreg_entry_cb_t) (uint16_t cmd, gnrc_pktsnip_t *pkt, void *ctx)
Precondition
cmd ∈ { GNRC_NETAPI_MSG_TYPE_RCV, GNRC_NETAPI_MSG_TYPE_SND }
Note
Only available with Callback extension.
Parameters
[in]cmdGNRC communication interface command type. Must be either GNRC_NETAPI_MSG_TYPE_SND or GNRC_NETAPI_MSG_TYPE_RCV
[in]pktThe packet to handle.
[in]ctxApplication context.

Definition at line 145 of file netreg.h.

Enumeration Type Documentation

◆ gnrc_netreg_type_t

Different types are availalbe dependent on the used modules.

Enumerator
GNRC_NETREG_TYPE_DEFAULT 

Use default IPC for netapi operations.

Note
Implicitly chosen without gnrc_netapi_mbox and gnrc_netapi_callbacks modules.
GNRC_NETREG_TYPE_MBOX 

Use centralized IPC for netapi operations.

Note
Only available with gnrc_netapi_mbox module.
GNRC_NETREG_TYPE_CB 

Use function callbacks for netapi operations.

Note
Only available with gnrc_netapi_callbacks module.

Definition at line 45 of file netreg.h.

Function Documentation

◆ gnrc_netreg_calc_csum()

int gnrc_netreg_calc_csum ( gnrc_pktsnip_t hdr,
gnrc_pktsnip_t pseudo_hdr 
)
Parameters
[in]hdrThe header the checksum should be calculated for.
[in]pseudo_hdrThe header the pseudo header shall be generated from. NULL if none is needed.
Returns
0, on success.
-EINVAL, if pseudo_hdr is NULL but a pseudo header was required.
-ENOENT, if Network protocol registry does not know how to calculate checksum for gnrc_pktsnip_t::type of hdr.

◆ gnrc_netreg_entry_init_cb()

static void gnrc_netreg_entry_init_cb ( gnrc_netreg_entry_t entry,
uint32_t  demux_ctx,
gnrc_netreg_entry_cbd_t cbd 
)
inlinestatic
Parameters
[out]entryA netreg entry
[in]demux_ctxThe demux context for the netreg entry
[in]cbdTarget callback for the registry entry
Note
Only available with Callback extension.

Definition at line 268 of file netreg.h.

◆ gnrc_netreg_entry_init_mbox()

static void gnrc_netreg_entry_init_mbox ( gnrc_netreg_entry_t entry,
uint32_t  demux_ctx,
mbox_t mbox 
)
inlinestatic
Parameters
[out]entryA netreg entry
[in]demux_ctxThe demux context for the netreg entry
[in]mboxTarget mailbox for the registry entry
Note
Only available with Mailbox IPC extension.

Definition at line 246 of file netreg.h.

◆ gnrc_netreg_entry_init_pid()

static void gnrc_netreg_entry_init_pid ( gnrc_netreg_entry_t entry,
uint32_t  demux_ctx,
kernel_pid_t  pid 
)
inlinestatic
Parameters
[out]entryA netreg entry
[in]demux_ctxThe demux context for the netreg entry
[in]pidThe PID of the registering thread

Definition at line 223 of file netreg.h.

◆ gnrc_netreg_getnext()

gnrc_netreg_entry_t* gnrc_netreg_getnext ( gnrc_netreg_entry_t entry)
Parameters
[in]entryA registry entry retrieved by gnrc_netreg_lookup() or gnrc_netreg_getnext(). Must not be NULL.
Returns
The next entry after entry fitting the given parameters on success
NULL if no entry new entry can be found.

◆ gnrc_netreg_lookup()

gnrc_netreg_entry_t* gnrc_netreg_lookup ( gnrc_nettype_t  type,
uint32_t  demux_ctx 
)
Parameters
[in]typeType of the protocol.
[in]demux_ctxThe demultiplexing context for the registered thread. See gnrc_netreg_entry_t::demux_ctx.
Returns
The first entry fitting the given parameters on success
NULL if no entry can be found.

◆ gnrc_netreg_num()

int gnrc_netreg_num ( gnrc_nettype_t  type,
uint32_t  demux_ctx 
)
Parameters
[in]typeType of the protocol.
[in]demux_ctxThe demultiplexing context for the registered thread. See gnrc_netreg_entry_t::demux_ctx.
Returns
Number of entries with the same gnrc_netreg_entry_t::type and gnrc_netreg_entry_t::demux_ctx as the given parameters.

◆ gnrc_netreg_register()

int gnrc_netreg_register ( gnrc_nettype_t  type,
gnrc_netreg_entry_t entry 
)

The semantics are: Thread gnrc_netreg_entry_t::pid is interested in packets of protocol type with context gnrc_netreg_entry_t::demux_ctx.

Parameters
[in]typeType of the protocol. Must not be < GNRC_NETTYPE_UNDEF or >= GNRC_NETTYPE_NUMOF.
[in]entryAn entry you want to add to the registry with gnrc_netreg_entry_t::pid and gnrc_netreg_entry_t::demux_ctx set.
Warning
Call gnrc_netreg_unregister() before you leave the context you allocated entry in. Otherwise it might get overwritten.
Precondition
The calling thread must provide a message queue.
Returns
0 on success
-EINVAL if type was < GNRC_NETTYPE_UNDEF or >= GNRC_NETTYPE_NUMOF

◆ gnrc_netreg_unregister()

void gnrc_netreg_unregister ( gnrc_nettype_t  type,
gnrc_netreg_entry_t entry 
)
Parameters
[in]typeType of the protocol.
[in]entryAn entry you want to remove from the registry.