neterr.h
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* 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.
*/
/**
* @defgroup net_gnrc_neterr Error reporting
* @ingroup net
* @brief Allows for asynchronous error reporting in the network stack.
* @{
*
* @file
* @brief Error reporting definitions.
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NET_GNRC_NETERR_H
#define NET_GNRC_NETERR_H
#include <errno.h>
#include <stdint.h>
#include "kernel_types.h"
#include "msg.h"
#include "net/gnrc/pkt.h"
#include "thread.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief @ref core_msg type for reporting an error.
*/
#define GNRC_NETERR_MSG_TYPE (0x0206)
/**
* @brief Error code to signalise success (no error occured) to an gnrc_neterr subscriber.
*/
#define GNRC_NETERR_SUCCESS (0)
/**
* @brief Reports an error to all subscribers of errors to @p pkt.
*
* @param[in] pkt Packet snip to report on.
* @param[in] err The error code for the packet.
*/
#ifdef MODULE_GNRC_NETERR
static inline void gnrc_neterr_report(gnrc_pktsnip_t *pkt, uint32_t err)
{
if (pkt->err_sub != KERNEL_PID_UNDEF) {
msg_t msg;
msg.type = GNRC_NETERR_MSG_TYPE;
msg.content.value = err;
msg_send(&msg, pkt->err_sub);
}
}
#else
#define gnrc_neterr_report(pkt, err) (void)pkt; (void)err
#endif
/**
* @brief Registers the current thread for errors on a @ref gnrc_pktsnip_t.
*
* @param[in] pkt Packet snip to register for errors.
*
* @return 0, on success.
* @return EALREADY, if there already someone registered to errors on @p pkt.
*/
#ifdef MODULE_GNRC_NETERR
static inline int gnrc_neterr_reg(gnrc_pktsnip_t *pkt)
{
if (pkt->err_sub != KERNEL_PID_UNDEF) {
return EALREADY;
}
pkt->err_sub = sched_active_pid;
return 0;
}
#else
#define gnrc_neterr_reg(pkt) (0)
#endif
#ifdef __cplusplus
}
#endif
#endif /* NET_GNRC_NETERR_H */
/** @} */