ieee802154: add llsec support over nl802154
Subsystems (3)
Alexander Aring
maintainercover ieee802154: add llsec support over nl802154
Hi,
this patch series will add llsec support for nl802154.
What is "llsec"?
The llsec (I suppose it stands for linklayer security) is part of the SoftMAC implementation of 802.15.4 "net/mac802154/llsec.c". The 802.15.4 standard describes an security mechanism over ACL's. The encryption/decryption will do llsec. To access llsec we need an interface for nl802154. The 802.15.4 standard describes PHY/MAC layer and we have "possible" similar paradigms like wireless with SoftMAC and HardMAC drivers. (We don't support HardMAC transceivers right now, I never had some HardMAC transceivers, are really expensive and there are only few some which can also run in a "raw" mode.) Anyway the nl802154 should access SoftMAC/HardMAC drivers to abstract "one interface to userspace".
These ACL's are known as "security tables" inside the mac information base (MIB) of 802.15.4 standard, security MIB.
The final goal we have to provide these tables in userspace is an "iptables" handling "store" and "restore", over the userspace application "iwpan" which contains the general "framework mechanism" like wireless "iw" tool, you can add/del entries on these security tables, then.
I don't looked right now how iptables userspace application do "exactly" the store and restore mechanism. The current way is a very KISS handling:
We add netlink cmd's to add/del the table entries. Over the dump callback it's possible to get all information which is printed out as the command line string "iwpan dev $WPAN_DEV $TABLE add ...". The restore script will simple export $WPAN_DEV variable to restore these configuration for a specific interface.
I will send the userspace patches as well to netdev, maybe somebody wants to know what I did there for first support.
This sounds weird but is to support llsec somehow a acceptable use-case. The final goal is to lookup how iptables works and make a nicer C implementation. There is currently no "official supported" userspace tool which support accessing the "llsec".
I added several TODO's to the current implementation and added a new:
CONFIG_IEEE802154_NL802154_EXPERIMENTAL
This config will not build the nl802154 llsec layer and reduce the MAX_ATTR attribute of nl802154 interface. With this config I explicit say this interface over nl802154 is still in development and will be changed later.
The 802.15.4 subsystem is still in EXPERIMENTAL state, there was some commit f4671a90c418b5aae14b61a9fc9d79c629403ca0 ("net/ieee802154: remove depends on CONFIG_EXPERIMENTAL") which is fine but no maintainer ever said it's not experimental anymore.
Checkpatch will complain about some above 80-chars width, at these places I ignore these warning otherwise the code looks awful in my opinion.
My current working repository is still bluetooth-next/master. David if everything is fine, then please ack patch "[PATCH bluetooth-next 1/4]
netlink: add nla_get for le32 and le64", so Marcel can apply it. Thanks.
- Alex
Alexander Aring (4):
netlink: add nla_get for le32 and le64
nl802154: use nla_get_le64 for get extended addr
nl802154: add support for security layer
mac802154: add comments for llsec issues
include/net/cfg802154.h | 131 ++++ include/net/ieee802154_netdev.h | 75 --- include/net/netlink.h | 18 + include/net/nl802154.h | 191 ++++++ net/ieee802154/Kconfig | 5 + net/ieee802154/core.c | 12 + net/ieee802154/core.h | 1 + net/ieee802154/nl802154.c | 1320 ++++++++++++++++++++++++++++++++++++--- net/ieee802154/rdev-ops.h | 109 ++++ net/mac802154/cfg.c | 205 ++++++ net/mac802154/rx.c | 4 + net/mac802154/tx.c | 4 + 12 files changed, 1903 insertions(+), 172 deletions(-)
Signature · 1 line
2.5.3
Alexander Aring
maintainerPATCH 1/4 netlink: add nla_get for le32 and le64
This patch adds missing inline wrappers for nla_get_le32 and nla_get_le64. The 802.15.4 MAC byteorder is little endian and we keep the byteorder for fields like address configuration in the same byteorder as it comes from the MAC layer.
To provide these fields for nl802154 userspace applications, we need these inline wrappers for netlink.
--- include/net/netlink.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/net/netlink.h +18 -0
@@ -1004,6 +1004,15 @@ static inline __be32 nla_get_be32(const struct nlattr *nla) }/** +* nla_get_le32 - return payload of __le32 attribute +* @nla: __le32 netlink attribute +*/ +static inline __le32 nla_get_le32 (const struct nlattr *nla) +{ +return *(__le32 *)nla_data (nla); +} + +/** * nla_get_u16 - return payload of u16 attribute * @nla: u16 netlink attribute */
@@ -1066,6 +1075,15 @@ static inline __be64 nla_get_be64(const struct nlattr *nla) }/** +* nla_get_le64 - return payload of __le64 attribute +* @nla: __le64 netlink attribute +*/ +static inline __le64 nla_get_le64 (const struct nlattr *nla) +{ +return *(__le64 *)nla_data (nla); +} + +/** * nla_get_s32 - return payload of s32 attribute * @nla: s32 netlink attribute */
Signature · 1 line
2.5.3
Re: [PATCH bluetooth-next 1/4] netlink: add nla_get for le32 and le64
Hi Dave,
Quoted 40 lines
This patch adds missing inline wrappers for
nla_get_le32andnla_get_le64. The 802.15.4 MAC byteorder is little endian and we keep the byteorder for fields like address configuration in the same byteorder as it comes from the MAC layer.To provide these fields for nl802154 userspace applications, we need these inline wrappers for netlink.
Cc David S. Miller <[email protected]>Signed-off-by Alexander Aring <[email protected]>---
include/net/netlink.h| 18 ++++++++++++++++++1 file changed, 18 insertions(+)include/net/netlink.h +11
-0@@ -1004,6 +1004,15 @@ static inline __be32 nla_get_be32(const struct nlattr *nla) }/** +* nla_get_le32 - return payload of __le32 attribute +* @nla: __le32 netlink attribute +*/ +static inline __le32 nla_get_le32 (const struct nlattr *nla) +{ +return *(__le32 *)nla_data (nla); +} + +/** * nla_get_u16 - return payload of u16 attribute * @nla: u16 netlink attribute */ @@ -1066,6 +1075,15 @@ static inline __be64 nla_get_be64(const struct nlattr *nla) }/** +* nla_get_le64 - return payload of __le64 attribute +* @nla: __le64 netlink attribute
include/net/netlink.h static inline __be64 nla_get_be64(const struct nlattr *nla) · line 1089
Quoted 10 lines
include/net/netlink.h +7
-0+*/ +static inline __le64 nla_get_le64 (const struct nlattr *nla) +{ +return *(__le64 *)nla_data (nla); +} + +/** * nla_get_s32 - return payload of s32 attribute * @nla: s32 netlink attribute */
do you have any objections to me taking this change through the bluetooth-next tree?
Regards
Marcel
David Miller
maintainerRe: [PATCH bluetooth-next 1/4] netlink: add nla_get for le32 and le64
From: Marcel Holtmann <[email protected]>
Date: Tue, 29 Sep 2015 18:08:32 +0200
Quoted 1 line
do you have any objections to me taking this change through the bluetooth-next tree?
No objections.
Alexander Aring
maintainerPATCH 2/4 nl802154: use nla_get_le64 for get extended addr
In reply to Alexander AringThis patch uses the nla_get_le64 function instead of doing a force converting to le64.
--- net/ieee802154/nl802154.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/ieee802154/nl802154.c +1 -3
@@ -753,10 +753,8 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)return -EINVAL ; } -/* TODO add nla_get_le64 to netlink */ if (info->attrs[NL802154_ATTR_EXTENDED_ADDR ]) - extended_addr = (__force __le64 )nla_get_u64 ( - info->attrs[NL802154_ATTR_EXTENDED_ADDR ]); + extended_addr =nla_get_le64 (info->attrs[NL802154_ATTR_EXTENDED_ADDR ]);if (!rdev->ops->add_virtual_intf)return -EOPNOTSUPP ;
Signature · 1 line
2.5.3
Alexander Aring
maintainerPATCH 3/4 nl802154: add support for security layer
In reply to Alexander AringThis patch adds support for accessing mac802154 llsec implementation over nl802154. I added for a new Kconfig entry to provide this functionality CONFIG_IEEE802154_NL802154_EXPERIMENTAL. This interface is still in development. It provides to change security parameters and add/del/dump entries of security tables. Later we can add also a get to get an entry by unique identifier.
--- include/net/cfg802154.h | 131 ++++ include/net/ieee802154_netdev.h | 75 --- include/net/nl802154.h | 191 ++++++ net/ieee802154/Kconfig | 5 + net/ieee802154/core.c | 12 + net/ieee802154/core.h | 1 + net/ieee802154/nl802154.c | 1316 ++++++++++++++++++++++++++++++++++++--- net/ieee802154/rdev-ops.h | 109 ++++ net/mac802154/cfg.c | 205 ++++++ 9 files changed, 1876 insertions(+), 169 deletions(-)
include/net/cfg802154.h +131 -0
@@ -27,6 +27,16 @@struct wpan_phy ;struct wpan_phy_cca ; +#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL +struct ieee802154_llsec_device_key ; +struct ieee802154_llsec_seclevel ; +struct ieee802154_llsec_params ; +struct ieee802154_llsec_device ; +struct ieee802154_llsec_table ; +struct ieee802154_llsec_key_id ; +struct ieee802154_llsec_key ; +#endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */ +struct cfg802154_ops { struct net_device * (*add_virtual_intf_deprecated)(struct wpan_phy *wpan_phy, const char *name,
@@ -65,6 +75,51 @@ struct cfg802154_ops { struct wpan_dev *wpan_dev, bool mode);int (*set_ackreq_default)(struct wpan_phy *wpan_phy,struct wpan_dev *wpan_dev,bool ackreq); +#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL +void (*get_llsec_table)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +struct ieee802154_llsec_table **table); +void (*lock_llsec_table)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev); +void (*unlock_llsec_table)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev); +/* TODO remove locking/get table callbacks, this is part of the +* nl802154 interface and should be accessible from ieee802154 layer. +*/ +int (*get_llsec_params)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +struct ieee802154_llsec_params *params); +int (*set_llsec_params)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +const struct ieee802154_llsec_params *params, +int changed); +int (*add_llsec_key)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +const struct ieee802154_llsec_key_id *id, +const struct ieee802154_llsec_key *key); +int (*del_llsec_key)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +const struct ieee802154_llsec_key_id *id); +int (*add_seclevel)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +const struct ieee802154_llsec_seclevel *sl); +int (*del_seclevel)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +const struct ieee802154_llsec_seclevel *sl); +int (*add_device)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +const struct ieee802154_llsec_device *dev); +int (*del_device)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev,__le64 extended_addr); +int (*add_devkey)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +__le64 extended_addr, +const struct ieee802154_llsec_device_key *key); +int (*del_devkey)(struct wpan_phy *wpan_phy, +struct wpan_dev *wpan_dev, +__le64 extended_addr, +const struct ieee802154_llsec_device_key *key); +#endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */ }; static inline bool
@@ -176,6 +231,82 @@ struct ieee802154_addr { }; }; +struct ieee802154_llsec_key_id { +u8 mode; +u8 id; +union { +struct ieee802154_addr device_addr; +__le32 short_source; +__le64 extended_source; + }; +}; + +#define IEEE802154_LLSEC_KEY_SIZE 16 + +struct ieee802154_llsec_key { +u8 frame_types; +u32 cmd_frame_ids; +/* TODO replace with NL802154_KEY_SIZE */ +u8 key[IEEE802154_LLSEC_KEY_SIZE ]; +}; + +struct ieee802154_llsec_key_entry { +struct list_head list; + +struct ieee802154_llsec_key_id id; +struct ieee802154_llsec_key *key; +}; + +struct ieee802154_llsec_params { +bool enabled; + +__be32 frame_counter; +u8 out_level; +struct ieee802154_llsec_key_id out_key; + +__le64 default_key_source; + +__le16 pan_id; +__le64 hwaddr; +__le64 coord_hwaddr; +__le16 coord_shortaddr; +}; + +struct ieee802154_llsec_table { +struct list_head keys; +struct list_head devices; +struct list_head security_levels; +}; + +struct ieee802154_llsec_seclevel { +struct list_head list; + +u8 frame_type; +u8 cmd_frame_id; +bool device_override; +u32 sec_levels; +}; + +struct ieee802154_llsec_device { +struct list_head list; + +__le16 pan_id; +__le16 short_addr; +__le64 hwaddr; +u32 frame_counter; +bool seclevel_exempt; + +u8 key_mode; +struct list_head keys; +}; + +struct ieee802154_llsec_device_key { +struct list_head list; + +struct ieee802154_llsec_key_id key_id; +u32 frame_counter; +}; +struct wpan_dev_header_ops {/* TODO create callback currently assumes ieee802154_mac_cb inside * skb->cb. This should be changed to give these information as
include/net/ieee802154_netdev.h +0 -75
87 lines not on this page · raw message
include/net/nl802154.h +191 -0
207 lines not on this page · raw message
net/ieee802154/Kconfig +5 -0
@@ -12,6 +12,11 @@ menuconfig IEEE802154 if IEEE802154 +config IEEE802154_NL802154_EXPERIMENTAL + bool "IEEE 802.15.4 experimental netlink support" + ---help--- + Adds experimental netlink support for nl802154. + config IEEE802154_SOCKET tristate "IEEE 802.15.4 socket interface" default y
net/ieee802154/core.c +12 -0
@@ -95,6 +95,18 @@ cfg802154_rdev_by_wpan_phy_idx(int wpan_phy_idx)return result; } +struct wpan_phy *wpan_phy_idx_to_wpan_phy (int wpan_phy_idx) +{ +struct cfg802154_registered_device *rdev; + +ASSERT_RTNL (); + + rdev =cfg802154_rdev_by_wpan_phy_idx (wpan_phy_idx); +if (!rdev) +return NULL ; +return &rdev->wpan_phy; +} +struct wpan_phy *wpan_phy_new (const struct cfg802154_ops *ops,size_t priv_size) {
net/ieee802154/core.h +1 -0
@@ -42,5 +42,6 @@ extern int cfg802154_rdev_list_generation;void cfg802154_dev_free (struct cfg802154_registered_device *rdev);struct cfg802154_registered_device *cfg802154_rdev_by_wpan_phy_idx (int wpan_phy_idx); +struct wpan_phy *wpan_phy_idx_to_wpan_phy (int wpan_phy_idx);#endif /* __IEEE802154_CORE_H */
net/ieee802154/nl802154.c +1222 -94
1,370 lines not on this page · raw message
net/ieee802154/rdev-ops.h +109 -0
113 lines not on this page · raw message
net/mac802154/cfg.c +205 -0
215 lines not on this page · raw message
Signature · 1 line
2.5.3
Alexander Aring
maintainerPATCH 4/4 mac802154: add comments for llsec issues
In reply to Alexander AringWhile doing a little test with the llsec implementation I saw these issues. We should move decryption and encruption somewhere else, otherwise while capturing with wireshark the mac header shows secuirty fields but the payload is plaintext.
A complete other issue is what doing with HardMAC drivers where the payload is always plaintext. I think we need a special handling then in userspace. We currently doesn't support any HardMAC transceivers, so we should fix the first issue for SoftMAC transceivers.
--- net/mac802154/rx.c | 4 ++++ net/mac802154/tx.c | 4 ++++ 2 files changed, 8 insertions(+)
net/mac802154/rx.c +4 -0
@@ -87,6 +87,10 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata, skb->dev = sdata->dev; +/* TODO this should be moved after netif_receive_skb call, otherwise +* wireshark will show a mac header with security fields and the +* payload is already decrypted. +*/ rc =mac802154_llsec_decrypt (&sdata->sec, skb);if (rc) {pr_debug ("decryption failed: %i\n" , rc);
net/mac802154/tx.c +4 -0
@@ -129,6 +129,10 @@ ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev)struct ieee802154_sub_if_data *sdata =IEEE802154_DEV_TO_SUB_IF (dev);int rc; +/* TODO we should move it to wpan_dev_hard_header and dev_hard_header +* functions. The reason is wireshark will show a mac header which is +* with security fields but the payload is not encrypted. +*/ rc =mac802154_llsec_encrypt (&sdata->sec, skb);if (rc) {netdev_warn (dev,"encryption failed: %i\n" , rc);
Signature · 1 line
2.5.3
Hi Alex,
Quoted 67 lines
this patch series will add llsec support for nl802154.
What is "llsec"?
The llsec (I suppose it stands for linklayer security) is part of the SoftMAC implementation of 802.15.4 "
net/mac802154/llsec.c". The 802.15.4 standard describes an security mechanism over ACL's. The encryption/decryption will do llsec. To access llsec we need an interface for nl802154. The 802.15.4 standard describes PHY/MAC layer and we have "possible" similar paradigms like wireless with SoftMAC and HardMAC drivers. (We don't support HardMAC transceivers right now, I never had some HardMAC transceivers, are really expensive and there are only few some which can also run in a "raw" mode.) Anyway the nl802154 should access SoftMAC/HardMAC drivers to abstract "one interface to userspace".These ACL's are known as "security tables" inside the mac information base (MIB) of 802.15.4 standard, security MIB.
The final goal we have to provide these tables in userspace is an "iptables" handling "store" and "restore", over the userspace application "iwpan" which contains the general "framework mechanism" like wireless "iw" tool, you can add/del entries on these security tables, then.
I don't looked right now how iptables userspace application do "exactly" the store and restore mechanism. The current way is a very KISS handling:
We add netlink cmd's to add/del the table entries. Over the dump callback it's possible to get all information which is printed out as the command line string "iwpan dev $WPAN_DEV $TABLE add ...". The restore script will simple export $WPAN_DEV variable to restore these configuration for a specific interface.
I will send the userspace patches as well to netdev, maybe somebody wants to know what I did there for first support.
This sounds weird but is to support llsec somehow a acceptable use-case. The final goal is to lookup how iptables works and make a nicer C implementation. There is currently no "official supported" userspace tool which support accessing the "llsec".
I added several TODO's to the current implementation and added a new:
CONFIG_IEEE802154_NL802154_EXPERIMENTALThis config will not build the nl802154 llsec layer and reduce the
MAX_ATTRattribute of nl802154 interface. With this config I explicit say this interface over nl802154 is still in development and will be changed later.The 802.15.4 subsystem is still in EXPERIMENTAL state, there was some commit
f4671a90c418b5aae14b61a9fc9d79c629403ca0("net/ieee802154: remove depends onCONFIG_EXPERIMENTAL") which is fine but no maintainer ever said it's not experimental anymore.Checkpatch will complain about some above 80-chars width, at these places I ignore these warning otherwise the code looks awful in my opinion.
My current working repository is still bluetooth-next/master. David if everything is fine, then please ack patch "[PATCH bluetooth-next 1/4]
netlink: addnla_getfor le32 and le64", so Marcel can apply it. Thanks.- Alex
Alexander Aring (4):
netlink: addnla_getfor le32 and le64
nl802154: usenla_get_le64for get extended addr
nl802154: add support for security layer
mac802154: add comments for llsec issues
Quoted 13 lines
include/net/cfg802154.h | 131 ++++ include/net/ieee802154_netdev.h | 75 --- include/net/netlink.h | 18 + include/net/nl802154.h | 191 ++++++ net/ieee802154/Kconfig | 5 + net/ieee802154/core.c | 12 + net/ieee802154/core.h | 1 + net/ieee802154/nl802154.c | 1320 ++++++++++++++++++++++++++++++++++++--- net/ieee802154/rdev-ops.h | 109 ++++ net/mac802154/cfg.c | 205 ++++++ net/mac802154/rx.c | 4 + net/mac802154/tx.c | 4 + 12 files changed, 1903 insertions(+), 172 deletions(-)
all 4 patches have been applied to bluetooth-next tree.
Regards
Marcel