neterr.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
20 #include <errno.h>
21 #include <stdint.h>
22 
23 #include "msg.h"
24 #include "net/gnrc/pkt.h"
25 #include "thread.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
34 #define GNRC_NETERR_MSG_TYPE (0x0206)
35 
39 #define GNRC_NETERR_SUCCESS (0)
40 
47 #ifdef MODULE_GNRC_NETERR
48 static inline void gnrc_neterr_report(gnrc_pktsnip_t *pkt, uint32_t err)
49 {
50  if (pkt->err_sub != KERNEL_PID_UNDEF) {
51  msg_t msg;
52 
54  msg.content.value = err;
55 
56  msg_send(&msg, pkt->err_sub);
57  }
58 }
59 #else
60 #define gnrc_neterr_report(pkt, err) (void)pkt; (void)err
61 #endif
62 
71 #ifdef MODULE_GNRC_NETERR
72 static inline int gnrc_neterr_reg(gnrc_pktsnip_t *pkt)
73 {
74  if (pkt->err_sub != KERNEL_PID_UNDEF) {
75  return EALREADY;
76  }
77  pkt->err_sub = thread_getpid();
78  return 0;
79 }
80 #else
81 #define gnrc_neterr_reg(pkt) (0)
82 #endif
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
int msg_send(msg_t *m, kernel_pid_t target_pid)
Send a message (blocking).
#define KERNEL_PID_UNDEF
Canonical identifier for an invalid PID.
Definition: sched.h:106
static kernel_pid_t thread_getpid(void)
Returns the process ID of the currently running thread.
Definition: thread.h:396
#define EALREADY
Connection already in progress.
Definition: errno.h:75
#define gnrc_neterr_reg(pkt)
Registers the current thread for errors on a gnrc_pktsnip_t.
Definition: neterr.h:81
#define GNRC_NETERR_MSG_TYPE
Messaging / IPC type for reporting an error.
Definition: neterr.h:34
#define gnrc_neterr_report(pkt, err)
Reports an error to all subscribers of errors to pkt.
Definition: neterr.h:60
General definitions for network packets and their helper functions.
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:105
Describes a message object which can be sent between threads.
Definition: msg.h:192
uint16_t type
Type field.
Definition: msg.h:195
union msg_t::@1 content
Content of the message.
uint32_t value
Value content field.
Definition: msg.h:198