-
Notifications
You must be signed in to change notification settings - Fork 2.1k
gnrc, nimble/ble: notify network layer of BLE connection events #21608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 36 commits
7564665
0408e39
bf82b94
fbd2219
9715791
9030409
6cef5d6
b6e19c2
f1b82ec
4404817
e9d25cb
6570d30
82b5059
7e911b8
d8d7c81
602e894
418825f
7755585
2447cb8
8c53e7a
2c5bf74
ad4c316
b8ae0f6
abb69a1
afb04c8
8c88416
bee053b
a7d5ac9
2079a8f
30b2b7f
2bfd90d
7713680
f57c38b
2d5e9c5
7de5975
754fe9c
0c8d01d
97a0422
d57474d
06c3e64
5328407
00a8d28
ed5ac34
c45fd59
6e33db2
2ab900c
d0df717
e263d97
d20a7b5
11567f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 TU Dresden | ||
| * SPDX-License-Identifier: LGPL-2.1-only | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| /** | ||
| * @defgroup net_gnrc_netapi_notify Notification events for network APIs. | ||
| * @ingroup net_gnrc_netapi | ||
| * @brief Network event notification types. | ||
| * @{ | ||
| * | ||
| * @file | ||
| * @brief Network event notification type definitions. | ||
| * | ||
| * @details The purpose of this API is to allow lower layers in the network | ||
| * stack to inform higher layers of general, protocol-independent | ||
| * network events. | ||
| * It can be used through the @ref net_gnrc_netapi to notify any | ||
| * other network interfaces that have registered themselves through | ||
| * @ref net_gnrc_netreg for the corresponding @ref net_gnrc_nettype. | ||
| * | ||
| * @note Notification events are associated with type-dependent event data. | ||
| * Receivers should not access the data directly, but instead use the | ||
| * the dedicated API functions to copy the data from the sender's. | ||
| * If the data is read manually, the receiver is responsible for | ||
| * calling @ref gnrc_netapi_notify_ack to unblock the sender. | ||
| * | ||
| * @author Elena Frank <[email protected]> | ||
| */ | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| #include "net/ipv6/addr.h" | ||
| #include "cond.h" | ||
| #include "mutex.h" | ||
|
|
||
| /** | ||
| * @brief Definition of notification event types in the network stack. | ||
| * | ||
| * @note Expand at will. | ||
| * If event data is associated with the type, a helper function must also | ||
| * be added for parsing the data and calling @ref gnrc_netapi_notify_ack. | ||
| */ | ||
| typedef enum { | ||
| NETAPI_NOTIFY_L2_CONNECTED, /**< Connection established on layer 2. */ | ||
elenaf9 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| NETAPI_NOTIFY_L2_DISCONNECTED, /**< Connection closed on layer 2. */ | ||
| NETAPI_NOTIFY_L3_DISCOVERED, /**< Discovered node on the network layer. */ | ||
| NETAPI_NOTIFY_L3_UNREACHABLE, /**< Node became unreachable on the network layer. */ | ||
| } netapi_notify_t; | ||
|
|
||
| /** | ||
| * @brief Data structure to acknowledge netapi notification events. | ||
| */ | ||
| typedef struct { | ||
| int counter; /**< ACK counter */ | ||
| cond_t cond; /**< condition variable to signal change in count */ | ||
| mutex_t lock; /**< lock for counter */ | ||
elenaf9 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } gnrc_netapi_notify_ack_t; | ||
|
|
||
| /** | ||
| * @brief Data structure to be sent for netapi notification events. | ||
| */ | ||
| typedef struct { | ||
| netapi_notify_t event; /**< the type of event */ | ||
| void *_data; /**< associated event data. */ | ||
| uint16_t _data_len; /**< size of the event data */ | ||
elenaf9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| gnrc_netapi_notify_ack_t *ack; /**< acknowledge event */ | ||
elenaf9 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } gnrc_netapi_notify_t; | ||
|
|
||
| /** | ||
| * @brief L2 connection event data associated with @ref NETAPI_NOTIFY_L2_CONNECTED or | ||
| * @ref NETAPI_NOTIFY_L2_DISCONNECTED events. | ||
| */ | ||
| typedef struct { | ||
| uint8_t *l2addr; /**< L2 address of the node */ | ||
| uint8_t l2addr_len; /**< length of L2 address in byte */ | ||
| kernel_pid_t if_pid; /**< PID of network interface */ | ||
| } netapi_notify_l2_connection_t; | ||
|
|
||
| /** | ||
| * @brief Acknowledge that a notify event was received and its data read. | ||
| * | ||
| * @param[in] ack Pointer to the event's acknowledgment structure. | ||
| */ | ||
| static inline void gnrc_netapi_notify_ack(gnrc_netapi_notify_ack_t *ack) | ||
| { | ||
| mutex_lock(&ack->lock); | ||
| ack->counter++; | ||
| /* Signal that the counter changed. */ | ||
| cond_signal(&ack->cond); | ||
| mutex_unlock(&ack->lock); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Parse the connection event data associated with @ref NETAPI_NOTIFY_L2_CONNECTED | ||
| * and @ref NETAPI_NOTIFY_L2_DISCONNECTED events. | ||
| * | ||
| * @note This will call @ref gnrc_netapi_notify_ack. | ||
| * | ||
| * @param[in] notify Pointer to the received notify event. | ||
| * @param[out] data Connection data received in the @p notify event. | ||
| * data.l2addr_len should be set to the size of the l2addr buffer. | ||
| * | ||
| * @retval sizeof(netapi_notify_l2_connection_t) on success. | ||
| * @retval -EINVAL if @p notify is of a wrong @ref netapi_notify_t type. | ||
| * @retval -ENOBUFS if the length of l2addr in @p data is smaller than the | ||
| * received l2addr. | ||
elenaf9 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| uint8_t gnrc_netapi_notify_copy_l2_connection_data(gnrc_netapi_notify_t *notify, | ||
| netapi_notify_l2_connection_t *data); | ||
| /** | ||
| * @brief Parse the ipv6 address associated with @ref NETAPI_NOTIFY_L3_DISCOVERED and | ||
| * @ref NETAPI_NOTIFY_L3_UNREACHABLE events. | ||
| * | ||
| * @note This will call @ref gnrc_netapi_notify_ack. | ||
| * | ||
| * @param[in] notify Pointer to the received notify event. | ||
| * @param[out] addr IPv6 address of the remote. | ||
| * | ||
| * @retval sizeof(ipv6_addr_t) on success. | ||
| * @retval -EINVAL if @p notify is of a wrong @ref netapi_notify_t type. | ||
| */ | ||
| int gnrc_netapi_notify_copy_l3_address(gnrc_netapi_notify_t *notify, ipv6_addr_t *addr); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| /** @} */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ ifneq (,$(filter gnrc_uhcpc,$(USEMODULE))) | |
| USEMODULE += fmt | ||
| endif | ||
|
|
||
| ifneq (,$(filter gnrc_%,$(filter-out gnrc_lorawan gnrc_lorawan_1_1 gnrc_netapi gnrc_netreg gnrc_netif% gnrc_pkt%,$(USEMODULE)))) | ||
| ifneq (,$(filter gnrc_%,$(filter-out gnrc_lorawan gnrc_lorawan_1_1 gnrc_netapi gnrc_netapi_notify gnrc_netreg gnrc_netif% gnrc_pkt%,$(USEMODULE)))) | ||
| USEMODULE += gnrc | ||
| endif | ||
|
|
||
|
|
@@ -442,6 +442,7 @@ endif | |
|
|
||
| ifneq (,$(filter gnrc,$(USEMODULE))) | ||
| USEMODULE += gnrc_netapi | ||
| USEMODULE += gnrc_netapi_notify | ||
|
||
| USEMODULE += gnrc_netreg | ||
| USEMODULE += gnrc_netif | ||
| USEMODULE += gnrc_netif_hdr | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.