Skip to content

Commit

Permalink
Merge pull request #18699 from miri64/gnrc_netif_lorawan/enh/up-down-…
Browse files Browse the repository at this point in the history
…support

gnrc_netif_lorawan: add support for LINK_UP/_DOWN events
  • Loading branch information
benpicco authored Oct 12, 2022
2 parents b11af08 + 7f146b6 commit 913bf37
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
30 changes: 29 additions & 1 deletion sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion sys/net/gnrc/network_layer/ipv6/nib/nib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions tests/gnrc_ipv6_nib/mockup_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down

0 comments on commit 913bf37

Please sign in to comment.