Commit c88e5360 authored by Florian Grandel's avatar Florian Grandel Committed by Anas Nashif
Browse files

net: l2: ieee802154: fix settings order

In the IEEE 802.15.4 area certain settings must be set before
net_if_up() may be called (e.g. the channel).

Also net_if_up() may not be called if
CONFIG_IEEE802154_NET_IF_NO_AUTO_START=y.

This fixes the set-up order and handling of
CONFIG_IEEE802154_NET_IF_NO_AUTO_START.

Signed-off-by: default avatarFlorian Grandel <fgrandel@code-for-humans.de>
parent 5aa329ce
Loading
Loading
Loading
Loading
+2 −1
Changes for subsys/net/l2/ieee802154/ieee802154.c: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -655,7 +655,8 @@ void ieee802154_init(struct net_if *iface)
	memcpy(ctx->linkaddr.addr, eui64_be, IEEE802154_EXT_ADDR_LENGTH);
	net_if_set_link_addr(iface, ctx->linkaddr.addr, ctx->linkaddr.len, ctx->linkaddr.type);

	if (IS_ENABLED(CONFIG_IEEE802154_NET_IF_NO_AUTO_START)) {
	if (IS_ENABLED(CONFIG_IEEE802154_NET_IF_NO_AUTO_START) ||
	    IS_ENABLED(CONFIG_NET_CONFIG_SETTINGS)) {
		LOG_DBG("Interface auto start disabled.");
		net_if_flag_set(iface, NET_IF_NO_AUTO_START);
	}
+13 −5
Changes for subsys/net/lib/config/ieee802154_settings.c: 13 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -17,10 +17,12 @@ LOG_MODULE_DECLARE(net_config, CONFIG_NET_CONFIG_LOG_LEVEL);
#include <zephyr/net/net_mgmt.h>
#include <zephyr/net/ieee802154_mgmt.h>

int z_net_config_ieee802154_setup(void)
int z_net_config_ieee802154_setup(struct net_if *iface)
{
	uint16_t channel = CONFIG_NET_CONFIG_IEEE802154_CHANNEL;
	uint16_t pan_id = CONFIG_NET_CONFIG_IEEE802154_PAN_ID;
	const struct device *const dev = iface == NULL ? DEVICE_DT_GET(DT_CHOSEN(zephyr_ieee802154))
						       : net_if_get_device(iface);
	int16_t tx_power = CONFIG_NET_CONFIG_IEEE802154_RADIO_TX_POWER;

#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
@@ -32,16 +34,15 @@ int z_net_config_ieee802154_setup(void)
	};
#endif /* CONFIG_NET_L2_IEEE802154_SECURITY */

	struct net_if *iface;
	const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_ieee802154));

	if (!device_is_ready(dev)) {
		return -ENODEV;
	}

	if (!iface) {
		iface = net_if_lookup_by_dev(dev);
		if (!iface) {
		return -EINVAL;
			return -ENOENT;
		}
	}

	if (net_mgmt(NET_REQUEST_IEEE802154_SET_PAN_ID,
@@ -60,7 +61,14 @@ int z_net_config_ieee802154_setup(void)
	}
#endif /* CONFIG_NET_L2_IEEE802154_SECURITY */

	if (!IS_ENABLED(CONFIG_IEEE802154_NET_IF_NO_AUTO_START)) {
		/* The NET_IF_NO_AUTO_START flag was set by the driver, see
		 * ieee802154_init() to allow for configuration before starting
		 * up the interface.
		 */
		net_if_flag_clear(iface, NET_IF_NO_AUTO_START);
		net_if_up(iface);
	}

	return 0;
}
+3 −1
Changes for subsys/net/lib/config/ieee802154_settings.h: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -7,7 +7,9 @@
 */

#if defined(CONFIG_NET_L2_IEEE802154) && defined(CONFIG_NET_CONFIG_SETTINGS)
int z_net_config_ieee802154_setup(void);
struct net_if;

int z_net_config_ieee802154_setup(struct net_if *iface);
#else
#define z_net_config_ieee802154_setup(...) 0
#endif
+20 −6
Changes for subsys/net/lib/config/init.c: 20 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -367,6 +367,14 @@ int net_config_init_by_iface(struct net_if *iface, const char *app_info,
		iface = net_if_get_default();
	}

	if (!iface) {
		return -ENOENT;
	}

	if (net_if_flag_is_set(iface, NET_IF_NO_AUTO_START)) {
		return -ENETDOWN;
	}

	if (timeout < 0) {
		count = -1;
	} else if (timeout == 0) {
@@ -453,7 +461,7 @@ int net_config_init_app(const struct device *dev, const char *app_info)
		}
	}

	ret = z_net_config_ieee802154_setup();
	ret = z_net_config_ieee802154_setup(iface);
	if (ret < 0) {
		NET_ERR("Cannot setup IEEE 802.15.4 interface (%d)", ret);
	}
@@ -466,6 +474,17 @@ int net_config_init_app(const struct device *dev, const char *app_info)
	}
#endif

	/* Only try to use a network interface that is auto started */
	if (iface == NULL) {
		net_if_foreach(iface_find_cb, &iface);
	}

	if (!iface) {
		NET_WARN("No auto-started network interface - "
			 "network-bound app initialization skipped.");
		return 0;
	}

	if (IS_ENABLED(CONFIG_NET_CONFIG_NEED_IPV6)) {
		flags |= NET_CONFIG_NEED_IPV6;
	}
@@ -478,11 +497,6 @@ int net_config_init_app(const struct device *dev, const char *app_info)
		flags |= NET_CONFIG_NEED_IPV4;
	}

	/* Only try to use a network interface that is auto started */
	if (iface == NULL) {
		net_if_foreach(iface_find_cb, &iface);
	}

	/* Initialize the application automatically if needed */
	ret = net_config_init_by_iface(iface, app_info, flags,
				CONFIG_NET_CONFIG_INIT_TIMEOUT * MSEC_PER_SEC);