26
26
*
27
27
* @note Notification events are associated with type-dependent event data.
28
28
* Receivers should not access the data directly, but instead use the
29
- * the dedicated API functions.
30
- * If the data is read directly, the receiver is responsible for setting
31
- * the @ref NETAPI_NOTIFY_FLAG_ACK flag for the sending thread.
32
- *
29
+ * the dedicated API functions to copy the data from the sender's.
30
+ * If the data is read manually, the receiver is responsible for
31
+ * calling @ref gnrc_netapi_notify_ack to unblock the sender.
33
32
*
34
33
* @author Elena Frank <[email protected] >
35
34
*/
@@ -39,15 +38,8 @@ extern "C" {
39
38
#endif
40
39
41
40
#include "net/ipv6/addr.h"
42
- #include "sched.h"
43
-
44
- /**
45
- * @brief Thread flag for acknowledging a received notify even.
46
- *
47
- * @note The flag should only be set after all event data was copied
48
- * by receiver and can be freed by the sender.
49
- */
50
- #define NETAPI_NOTIFY_FLAG_ACK (1u << 10)
41
+ #include "cond.h"
42
+ #include "mutex.h"
51
43
52
44
/**
53
45
* @brief Definition of notification event types in the network stack.
@@ -64,13 +56,23 @@ typedef enum {
64
56
NETAPI_NOTIFY_L3_UNREACHABLE , /**< Node became unreachable on the network layer. */
65
57
} netapi_notify_t ;
66
58
59
+ /**
60
+ * @brief Data structure to acknowledge netapi notification events.
61
+ */
62
+ typedef struct {
63
+ int counter ; /**< ACK counter */
64
+ cond_t cond ; /**< condition variable to signal change in count */
65
+ mutex_t lock ; /**< lock for counter */
66
+ } gnrc_netapi_notify_ack_t ;
67
+
67
68
/**
68
69
* @brief Data structure to be sent for netapi notification events.
69
70
*/
70
71
typedef struct {
71
- netapi_notify_t event ; /**< the type of event */
72
- void * _data ; /**< associated event data. */
73
- uint16_t _data_len ; /**< size of the event data */
72
+ netapi_notify_t event ; /**< the type of event */
73
+ void * _data ; /**< associated event data. */
74
+ uint16_t _data_len ; /**< size of the event data */
75
+ gnrc_netapi_notify_ack_t * ack ; /**< acknowledge event */
74
76
} gnrc_netapi_notify_t ;
75
77
76
78
/**
@@ -83,13 +85,26 @@ typedef struct {
83
85
kernel_pid_t if_pid ; /**< PID of network interface */
84
86
} netapi_notify_l2_connection_t ;
85
87
88
+ /**
89
+ * @brief Acknowledge that a notify event was received and its data read.
90
+ *
91
+ * @param[in] ack Pointer to the event's acknowledgment structure.
92
+ */
93
+ static inline void gnrc_netapi_notify_ack (gnrc_netapi_notify_ack_t * ack )
94
+ {
95
+ mutex_lock (& ack -> lock );
96
+ ack -> counter ++ ;
97
+ /* Signal that the counter changed. */
98
+ cond_signal (& ack -> cond );
99
+ mutex_unlock (& ack -> lock );
100
+ }
101
+
86
102
/**
87
103
* @brief Parse the connection event data associated with @ref NETAPI_NOTIFY_L2_CONNECTED
88
104
* and @ref NETAPI_NOTIFY_L2_DISCONNECTED events.
89
105
*
90
106
* @note This will set the @ref NETAPI_NOTIFY_FLAG_ACK for the sending thread.
91
107
*
92
- * @param[in] sender_pid PID of the netapi sender.
93
108
* @param[in] notify Pointer to the received notify event.
94
109
* @param[out] data Connection data received in the @p notify event.
95
110
* data.l2addr_len should be set to the size of the l2addr buffer.
@@ -99,24 +114,21 @@ typedef struct {
99
114
* @retval -ENOBUFS if the length of l2addr in @p data is smaller than the
100
115
* received l2addr.
101
116
*/
102
- uint8_t gnrc_netapi_notify_copy_l2_connection_data (kernel_pid_t sender_pid ,
103
- gnrc_netapi_notify_t * notify ,
117
+ uint8_t gnrc_netapi_notify_copy_l2_connection_data (gnrc_netapi_notify_t * notify ,
104
118
netapi_notify_l2_connection_t * data );
105
119
/**
106
120
* @brief Parse the ipv6 address associated with @ref NETAPI_NOTIFY_L3_DISCOVERED and
107
121
* @ref NETAPI_NOTIFY_L3_UNREACHABLE events.
108
122
*
109
123
* @note This will set the @ref NETAPI_NOTIFY_FLAG_ACK for the sending thread.
110
124
*
111
- * @param[in] sender_pid PID of the netapi sender.
112
125
* @param[in] notify Pointer to the received notify event.
113
126
* @param[out] addr IPv6 address of the remote.
114
127
*
115
128
* @retval sizeof(ipv6_addr_t) on success.
116
129
* @retval -EINVAL if @p notify is of a wrong @ref netapi_notify_t type.
117
130
*/
118
- int gnrc_netapi_notify_copy_l3_address (kernel_pid_t sender_pid , gnrc_netapi_notify_t * notify ,
119
- ipv6_addr_t * addr );
131
+ int gnrc_netapi_notify_copy_l3_address (gnrc_netapi_notify_t * notify , ipv6_addr_t * addr );
120
132
121
133
#ifdef __cplusplus
122
134
}
0 commit comments