diff --git a/samples/net/common/ieee802154_settings.c b/samples/net/common/ieee802154_settings.c index 5ed054801a7..99b4242d785 100644 --- a/samples/net/common/ieee802154_settings.c +++ b/samples/net/common/ieee802154_settings.c @@ -19,6 +19,15 @@ int ieee802154_sample_setup(void) uint16_t channel = CONFIG_NET_APP_IEEE802154_CHANNEL; uint16_t pan_id = CONFIG_NET_APP_IEEE802154_PAN_ID; +#ifdef CONFIG_NET_L2_IEEE802154_SECURITY + struct ieee802154_security_params sec_params = { + .key = CONFIG_NET_APP_IEEE802154_SECURITY_KEY, + .key_len = sizeof(CONFIG_NET_APP_IEEE802154_SECURITY_KEY), + .key_mode = CONFIG_NET_APP_IEEE802154_SECURITY_KEY_MODE, + .level = CONFIG_NET_APP_IEEE802154_SECURITY_LEVEL, + }; +#endif /* CONFIG_NET_L2_IEEE802154_SECURITY */ + struct net_if *iface; struct device *dev; @@ -39,5 +48,12 @@ int ieee802154_sample_setup(void) return -EINVAL; } +#ifdef CONFIG_NET_L2_IEEE802154_SECURITY + if (net_mgmt(NET_REQUEST_IEEE802154_SET_SECURITY_SETTINGS, iface, + &sec_params, sizeof(struct ieee802154_security_params))) { + return -EINVAL; + } +#endif /* CONFIG_NET_L2_IEEE802154_SECURITY */ + return 0; } diff --git a/subsys/net/ip/Kconfig.app b/subsys/net/ip/Kconfig.app index bc7143c9965..bc62920d276 100644 --- a/subsys/net/ip/Kconfig.app +++ b/subsys/net/ip/Kconfig.app @@ -69,6 +69,38 @@ config NET_APP_IEEE802154_CHANNEL help The channel to use by default in the sample application. +config NET_APP_IEEE802154_SECURITY_KEY + string "IEEE 802.15.4 security key" + default "moooh!" + depends on NET_L2_IEEE802154_SECURITY + help + The key string to use for the link-layer security part. + +config NET_APP_IEEE802154_SECURITY_KEY_MODE + int "IEEE 802.15.4 security key mode" + default 0 + range 0 0 + depends on NET_L2_IEEE802154_SECURITY + help + The key mode to use for the link-layer security part. + Only implicit mode is supported, thus 0. + +config NET_APP_IEEE802154_SECURITY_LEVEL + int "IEEE 802.15.4 security level (0-7)" + default 0 + range 0 7 + depends on NET_L2_IEEE802154_SECURITY + help + The security level to use for the link-layer security part. + 0 means no security + 1 authentication only with a 4 bytes length tag + 2 authentication only with a 8 bytes length tag + 3 authentication only with a 16 bytes length tag + 4 encryption only + 5 encryption/authentication with a 4 bytes length tag + 6 encryption/authentication with a 8 bytes length tag + 7 encryption/authentication with a 16 bytes length tag + endif # NET_L2_IEEE802154 || NET_L2_RAW_CHANNEL endif # NET_APP_SETTINGS