mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #18699 from miri64/gnrc_netif_lorawan/enh/up-down-support
gnrc_netif_lorawan: add support for LINK_UP/_DOWN events
This commit is contained in:
commit
913bf3748c
@ -16,6 +16,8 @@
|
||||
#include <assert.h>
|
||||
#include "fmt.h"
|
||||
|
||||
#include "net/gnrc/ipv6.h"
|
||||
#include "net/gnrc/ipv6/nib.h"
|
||||
#include "net/gnrc/pktbuf.h"
|
||||
#include "net/gnrc/netif.h"
|
||||
#include "net/gnrc/netif/hdr.h"
|
||||
@ -69,7 +71,14 @@ void gnrc_lorawan_mlme_confirm(gnrc_lorawan_t *mac, mlme_confirm_t *confirm)
|
||||
|
||||
if (confirm->type == MLME_JOIN) {
|
||||
if (confirm->status == 0) {
|
||||
DEBUG("gnrc_lorawan: join succeeded\n");
|
||||
gnrc_netif_lorawan_t *lw_netif = container_of(mac, gnrc_netif_lorawan_t, mac);
|
||||
gnrc_netif_t *netif = container_of(lw_netif, gnrc_netif_t, lorawan);
|
||||
|
||||
DEBUG("gnrc_lorawan: join succeeded %d\n", netif->pid);
|
||||
if (netif->dev) {
|
||||
netif->flags |= GNRC_NETIF_FLAGS_HAS_L2ADDR;
|
||||
netif->dev->event_callback(netif->dev, NETDEV_EVENT_LINK_UP);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DEBUG("gnrc_lorawan: join failed\n");
|
||||
@ -217,6 +226,22 @@ static void _driver_cb(netdev_t *dev, netdev_event_t event)
|
||||
case NETDEV_EVENT_TX_COMPLETE:
|
||||
gnrc_lorawan_radio_tx_done_cb(mac);
|
||||
break;
|
||||
case NETDEV_EVENT_LINK_UP: {
|
||||
if (IS_USED(MODULE_GNRC_IPV6)) {
|
||||
msg_t msg = { .type = GNRC_IPV6_NIB_IFACE_UP, .content = { .ptr = netif } };
|
||||
|
||||
msg_send(&msg, gnrc_ipv6_pid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NETDEV_EVENT_LINK_DOWN: {
|
||||
if (IS_USED(MODULE_GNRC_IPV6)) {
|
||||
msg_t msg = { .type = GNRC_IPV6_NIB_IFACE_DOWN, .content = { .ptr = netif } };
|
||||
|
||||
msg_send(&msg, gnrc_ipv6_pid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NETDEV_EVENT_RX_TIMEOUT:
|
||||
gnrc_lorawan_radio_rx_timeout_cb(mac);
|
||||
break;
|
||||
@ -384,6 +409,7 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *payload)
|
||||
res = conf.status;
|
||||
|
||||
if (res < 0) {
|
||||
DEBUG("gnrc_netif: unable to send (%s)\n", strerror(-res));
|
||||
gnrc_pktbuf_release_error(payload, res);
|
||||
}
|
||||
|
||||
@ -578,6 +604,8 @@ static int _set(gnrc_netif_t *netif, const gnrc_netapi_opt_t *opt)
|
||||
&mlme_confirm);
|
||||
res = mlme_confirm.status;
|
||||
if (mlme_confirm.status == 0) {
|
||||
netif->flags &= ~GNRC_NETIF_FLAGS_HAS_L2ADDR;
|
||||
netif->dev->event_callback(netif->dev, NETDEV_EVENT_LINK_DOWN);
|
||||
/* reset netif as well */
|
||||
_reset(netif);
|
||||
}
|
||||
|
@ -56,7 +56,10 @@ void _auto_configure_addr(gnrc_netif_t *netif, const ipv6_addr_t *pfx,
|
||||
#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LN)
|
||||
bool new_address = false;
|
||||
#endif /* CONFIG_GNRC_IPV6_NIB_6LN */
|
||||
gnrc_netif_ipv6_get_iid(netif, (eui64_t *)&addr.u64[1]);
|
||||
if (gnrc_netif_ipv6_get_iid(netif, (eui64_t *)&addr.u64[1]) < 0) {
|
||||
DEBUG("nib: Can't get IID on interface %u\n", netif->pid);
|
||||
return;
|
||||
}
|
||||
ipv6_addr_init_prefix(&addr, pfx, pfx_len);
|
||||
if ((idx = gnrc_netif_ipv6_addr_idx(netif, &addr)) < 0) {
|
||||
if ((idx = gnrc_netif_ipv6_addr_add_internal(netif, &addr, pfx_len,
|
||||
|
@ -136,6 +136,7 @@ void gnrc_ipv6_nib_iface_up(gnrc_netif_t *netif)
|
||||
netif->ipv6.rs_sent = 0;
|
||||
#endif /* CONFIG_GNRC_IPV6_NIB_6LN */
|
||||
netif->ipv6.na_sent = 0;
|
||||
_auto_configure_addr(netif, &ipv6_addr_link_local_prefix, 64U);
|
||||
if (!(gnrc_netif_is_rtr_adv(netif)) ||
|
||||
(gnrc_netif_is_6ln(netif) && !gnrc_netif_is_6lbr(netif))) {
|
||||
uint32_t next_rs_time = random_uint32_range(0, NDP_MAX_RS_MS_DELAY);
|
||||
@ -175,6 +176,12 @@ void gnrc_ipv6_nib_iface_down(gnrc_netif_t *netif, bool send_final_ra)
|
||||
#else
|
||||
(void)send_final_ra;
|
||||
#endif
|
||||
for (unsigned i = 0; i < CONFIG_GNRC_NETIF_IPV6_ADDRS_NUMOF; i++) {
|
||||
if (ipv6_addr_is_link_local(&netif->ipv6.addrs[i])) {
|
||||
/* link-local address might change on reconnect */
|
||||
gnrc_netif_ipv6_addr_remove_internal(netif, &netif->ipv6.addrs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
gnrc_netif_release(netif);
|
||||
}
|
||||
@ -201,7 +208,6 @@ void gnrc_ipv6_nib_init_iface(gnrc_netif_t *netif)
|
||||
return;
|
||||
}
|
||||
_add_static_lladdr(netif);
|
||||
_auto_configure_addr(netif, &ipv6_addr_link_local_prefix, 64U);
|
||||
|
||||
gnrc_netif_release(netif);
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ void _tests_init(void)
|
||||
);
|
||||
_mock_netif = &_netif;
|
||||
expect(res == 0);
|
||||
_common_set_up();
|
||||
/* we do not want to test for SLAAC here so just assure the configured
|
||||
* address is valid */
|
||||
expect(!ipv6_addr_is_unspecified(&_mock_netif->ipv6.addrs[0]));
|
||||
|
Loading…
Reference in New Issue
Block a user