net/samples: Add 802.15.4 link-layer security settings for the samples

And use them accordingly in the common code part.

Change-Id: Id91b76e5baea607c0d68eebcde6f84e4e35ca44c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2017-03-16 08:38:44 +01:00
parent e3c0310d98
commit d2f8a5a27f
2 changed files with 48 additions and 0 deletions

View File

@ -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;
}

View File

@ -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