2015-02-07 13:14:37 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-08-17 15:41:29 +02:00
|
|
|
* @defgroup net_gnrc_netreg Network protocol registry
|
2015-08-20 16:17:37 +02:00
|
|
|
* @ingroup net_gnrc
|
|
|
|
* @brief Registry to receive messages of a specified protocol type by GNRC.
|
2015-02-07 13:14:37 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Definitions to register network protocol PIDs to use with
|
2015-08-17 15:41:29 +02:00
|
|
|
* @ref net_gnrc_netapi.
|
2015-02-07 13:14:37 +01:00
|
|
|
*
|
|
|
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
|
|
|
*/
|
|
|
|
#ifndef NETREG_H_
|
|
|
|
#define NETREG_H_
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include "kernel_types.h"
|
2015-08-17 15:41:29 +02:00
|
|
|
#include "net/gnrc/nettype.h"
|
|
|
|
#include "net/gnrc/pkt.h"
|
2015-02-07 13:14:37 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2015-02-13 09:58:42 +01:00
|
|
|
* @brief Demux context value to get all packets of a certain type.
|
|
|
|
*
|
2015-08-17 15:41:29 +02:00
|
|
|
* @see gnrc_netreg_entry_t::demux_ctx
|
2015-02-07 13:14:37 +01:00
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
#define GNRC_NETREG_DEMUX_CTX_ALL (0xffff0000)
|
2015-02-07 13:14:37 +01:00
|
|
|
|
|
|
|
/**
|
2015-08-17 15:41:29 +02:00
|
|
|
* @brief Entry to the @ref net_gnrc_netreg
|
2015-02-07 13:14:37 +01:00
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
typedef struct gnrc_netreg_entry {
|
2015-02-13 09:58:42 +01:00
|
|
|
/**
|
|
|
|
* @brief next element in list
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
struct gnrc_netreg_entry *next;
|
2015-02-07 13:14:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The demultiplexing context for the registering thread.
|
|
|
|
*
|
|
|
|
* @details This can be defined by the network protocol themselves.
|
|
|
|
* E. g. protocol numbers / next header numbers in IPv4/IPv6,
|
|
|
|
* ports in UDP/TCP, or similar.
|
|
|
|
*/
|
2015-02-13 09:58:42 +01:00
|
|
|
uint32_t demux_ctx;
|
2015-02-07 13:14:37 +01:00
|
|
|
kernel_pid_t pid; /**< The PID of the registering thread */
|
2015-08-17 15:41:29 +02:00
|
|
|
} gnrc_netreg_entry_t;
|
2015-02-07 13:14:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initializes module.
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
void gnrc_netreg_init(void);
|
2015-02-07 13:14:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Registers a thread to the registry.
|
|
|
|
*
|
2015-08-17 15:41:29 +02:00
|
|
|
* @details The semantics are: Thread gnrc_netreg_entry_t::pid is interested in
|
|
|
|
* packets of protocol @p type with context gnrc_netreg_entry_t::demux_ctx.
|
2015-02-07 13:14:37 +01:00
|
|
|
*
|
2015-08-17 15:41:29 +02:00
|
|
|
* @param[in] type Type of the protocol. Must not be < GNRC_NETTYPE_UNDEF or
|
|
|
|
* >= GNRC_NETTYPE_NUMOF.
|
2015-02-13 09:58:42 +01:00
|
|
|
* @param[in] entry An entry you want to add to the registry with
|
2015-08-17 15:41:29 +02:00
|
|
|
* gnrc_netreg_entry_t::pid and gnrc_netreg_entry_t::demux_ctx set.
|
2015-02-07 13:14:37 +01:00
|
|
|
*
|
2015-08-17 15:41:29 +02:00
|
|
|
* @warning Call gnrc_netreg_unregister() *before* you leave the context you
|
2015-07-19 11:22:29 +02:00
|
|
|
* allocated @p entry in. Otherwise it might get overwritten.
|
|
|
|
*
|
2015-02-07 13:14:37 +01:00
|
|
|
* @return 0 on success
|
2015-08-17 15:41:29 +02:00
|
|
|
* @return -EINVAL if @p type was < GNRC_NETTYPE_UNDEF or >= GNRC_NETTYPE_NUMOF
|
2015-02-07 13:14:37 +01:00
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
int gnrc_netreg_register(gnrc_nettype_t type, gnrc_netreg_entry_t *entry);
|
2015-02-07 13:14:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Removes a thread from the registry.
|
|
|
|
*
|
|
|
|
* @param[in] type Type of the protocol.
|
2015-02-13 09:58:42 +01:00
|
|
|
* @param[in] entry An entry you want to remove from the registry.
|
2015-02-07 13:14:37 +01:00
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
void gnrc_netreg_unregister(gnrc_nettype_t type, gnrc_netreg_entry_t *entry);
|
2015-02-07 13:14:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Searches for entries with given parameters in the registry and
|
|
|
|
* returns the first found.
|
|
|
|
*
|
|
|
|
* @param[in] type Type of the protocol.
|
|
|
|
* @param[in] demux_ctx The demultiplexing context for the registered thread.
|
2015-08-17 15:41:29 +02:00
|
|
|
* See gnrc_netreg_entry_t::demux_ctx.
|
2015-02-07 13:14:37 +01:00
|
|
|
*
|
|
|
|
* @return The first entry fitting the given parameters on success
|
|
|
|
* @return NULL if no entry can be found.
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
gnrc_netreg_entry_t *gnrc_netreg_lookup(gnrc_nettype_t type, uint32_t demux_ctx);
|
2015-02-07 13:14:37 +01:00
|
|
|
|
|
|
|
/**
|
2015-08-17 15:41:29 +02:00
|
|
|
* @brief Returns number of entries with the same gnrc_netreg_entry_t::type and
|
|
|
|
* gnrc_netreg_entry_t::demux_ctx.
|
2015-02-07 13:14:37 +01:00
|
|
|
*
|
|
|
|
* @param[in] type Type of the protocol.
|
|
|
|
* @param[in] demux_ctx The demultiplexing context for the registered thread.
|
2015-08-17 15:41:29 +02:00
|
|
|
* See gnrc_netreg_entry_t::demux_ctx.
|
2015-02-07 13:14:37 +01:00
|
|
|
*
|
2015-08-17 15:41:29 +02:00
|
|
|
* @return Number of entries with the same gnrc_netreg_entry_t::type and
|
|
|
|
* gnrc_netreg_entry_t::demux_ctx as the given parameters.
|
2015-02-07 13:14:37 +01:00
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
int gnrc_netreg_num(gnrc_nettype_t type, uint32_t demux_ctx);
|
2015-02-07 13:14:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the next entry after @p entry with the same
|
2015-08-17 15:41:29 +02:00
|
|
|
* gnrc_netreg_entry_t::type and gnrc_netreg_entry_t::demux_ctx as the
|
2015-02-07 13:14:37 +01:00
|
|
|
* given entry.
|
|
|
|
*
|
2015-08-17 15:41:29 +02:00
|
|
|
* @param[in] entry A registry entry retrieved by gnrc_netreg_lookup() or
|
|
|
|
* gnrc_netreg_getnext(). Must not be NULL.
|
2015-02-07 13:14:37 +01:00
|
|
|
*
|
|
|
|
* @return The next entry after @p entry fitting the given parameters on success
|
|
|
|
* @return NULL if no entry new entry can be found.
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
gnrc_netreg_entry_t *gnrc_netreg_getnext(gnrc_netreg_entry_t *entry);
|
2015-02-07 13:14:37 +01:00
|
|
|
|
2015-03-07 16:57:42 +01:00
|
|
|
/**
|
|
|
|
* @brief Calculates the checksum for a header.
|
|
|
|
*
|
|
|
|
* @param[in] hdr The header the checksum should be calculated
|
|
|
|
* for.
|
|
|
|
* @param[in] pseudo_hdr The header the pseudo header shall be generated
|
|
|
|
* from. NULL if none is needed.
|
|
|
|
*
|
|
|
|
* @return 0, on success.
|
|
|
|
* @return -EINVAL, if @p pseudo_hdr is NULL but a pseudo header was required.
|
2015-08-17 15:41:29 +02:00
|
|
|
* @return -ENOENT, if @ref net_gnrc_netreg does not know how to calculate checksum
|
|
|
|
* for gnrc_pktsnip_t::type of @p hdr.
|
2015-03-07 16:57:42 +01:00
|
|
|
*/
|
|
|
|
|
2015-08-17 15:41:29 +02:00
|
|
|
int gnrc_netreg_calc_csum(gnrc_pktsnip_t *hdr, gnrc_pktsnip_t *pseudo_hdr);
|
2015-03-07 16:57:42 +01:00
|
|
|
|
2015-03-07 16:53:09 +01:00
|
|
|
/**
|
|
|
|
* @brief Builds a header for sending and adds it to the packet buffer.
|
|
|
|
*
|
|
|
|
* @param[in] type Type of the header.
|
|
|
|
* @param[in] payload Payload for the packet.
|
|
|
|
* @param[in] src Source address for the header. Can be NULL if not
|
|
|
|
* known or required.
|
|
|
|
* @param[in] src_len Length of @p src. Can be 0 if not known or required.
|
|
|
|
* @param[in] dst Destination address for the header. Can be NULL if not
|
|
|
|
* known or required.
|
|
|
|
* @param[in] dst_len Length of @p dst. Can be 0 if not known or required.
|
|
|
|
*
|
|
|
|
* @return The header for the protocol on success.
|
|
|
|
* @return NULL on error.
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
gnrc_pktsnip_t *gnrc_netreg_hdr_build(gnrc_nettype_t type, gnrc_pktsnip_t *payload,
|
|
|
|
uint8_t *src, uint8_t src_len,
|
|
|
|
uint8_t *dst, uint8_t dst_len);
|
2015-03-07 16:53:09 +01:00
|
|
|
|
2015-02-07 13:14:37 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* NETREG_H_ */
|
|
|
|
/** @} */
|