diff options
Diffstat (limited to 'include/net/ieee802154_netdev.h')
| -rw-r--r-- | include/net/ieee802154_netdev.h | 187 |
1 files changed, 170 insertions, 17 deletions
diff --git a/include/net/ieee802154_netdev.h b/include/net/ieee802154_netdev.h index 5a719ca892f4..3b53c8e405e4 100644 --- a/include/net/ieee802154_netdev.h +++ b/include/net/ieee802154_netdev.h | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #ifndef IEEE802154_NETDEVICE_H | 27 | #ifndef IEEE802154_NETDEVICE_H |
| 28 | #define IEEE802154_NETDEVICE_H | 28 | #define IEEE802154_NETDEVICE_H |
| 29 | 29 | ||
| 30 | #include <net/ieee802154.h> | ||
| 30 | #include <net/af_ieee802154.h> | 31 | #include <net/af_ieee802154.h> |
| 31 | #include <linux/netdevice.h> | 32 | #include <linux/netdevice.h> |
| 32 | #include <linux/skbuff.h> | 33 | #include <linux/skbuff.h> |
| @@ -114,6 +115,34 @@ int ieee802154_hdr_pull(struct sk_buff *skb, struct ieee802154_hdr *hdr); | |||
| 114 | int ieee802154_hdr_peek_addrs(const struct sk_buff *skb, | 115 | int ieee802154_hdr_peek_addrs(const struct sk_buff *skb, |
| 115 | struct ieee802154_hdr *hdr); | 116 | struct ieee802154_hdr *hdr); |
| 116 | 117 | ||
| 118 | /* parses the full 802.15.4 header a given skb and stores them into hdr, | ||
| 119 | * performing pan id decompression and length checks to be suitable for use in | ||
| 120 | * header_ops.parse | ||
| 121 | */ | ||
| 122 | int ieee802154_hdr_peek(const struct sk_buff *skb, struct ieee802154_hdr *hdr); | ||
| 123 | |||
| 124 | int ieee802154_max_payload(const struct ieee802154_hdr *hdr); | ||
| 125 | |||
| 126 | static inline int | ||
| 127 | ieee802154_sechdr_authtag_len(const struct ieee802154_sechdr *sec) | ||
| 128 | { | ||
| 129 | switch (sec->level) { | ||
| 130 | case IEEE802154_SCF_SECLEVEL_MIC32: | ||
| 131 | case IEEE802154_SCF_SECLEVEL_ENC_MIC32: | ||
| 132 | return 4; | ||
| 133 | case IEEE802154_SCF_SECLEVEL_MIC64: | ||
| 134 | case IEEE802154_SCF_SECLEVEL_ENC_MIC64: | ||
| 135 | return 8; | ||
| 136 | case IEEE802154_SCF_SECLEVEL_MIC128: | ||
| 137 | case IEEE802154_SCF_SECLEVEL_ENC_MIC128: | ||
| 138 | return 16; | ||
| 139 | case IEEE802154_SCF_SECLEVEL_NONE: | ||
| 140 | case IEEE802154_SCF_SECLEVEL_ENC: | ||
| 141 | default: | ||
| 142 | return 0; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 117 | static inline int ieee802154_hdr_length(struct sk_buff *skb) | 146 | static inline int ieee802154_hdr_length(struct sk_buff *skb) |
| 118 | { | 147 | { |
| 119 | struct ieee802154_hdr hdr; | 148 | struct ieee802154_hdr hdr; |
| @@ -193,8 +222,12 @@ static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa *sa, | |||
| 193 | */ | 222 | */ |
| 194 | struct ieee802154_mac_cb { | 223 | struct ieee802154_mac_cb { |
| 195 | u8 lqi; | 224 | u8 lqi; |
| 196 | u8 flags; | 225 | u8 type; |
| 197 | u8 seq; | 226 | bool ackreq; |
| 227 | bool secen; | ||
| 228 | bool secen_override; | ||
| 229 | u8 seclevel; | ||
| 230 | bool seclevel_override; | ||
| 198 | struct ieee802154_addr source; | 231 | struct ieee802154_addr source; |
| 199 | struct ieee802154_addr dest; | 232 | struct ieee802154_addr dest; |
| 200 | }; | 233 | }; |
| @@ -204,25 +237,96 @@ static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb) | |||
| 204 | return (struct ieee802154_mac_cb *)skb->cb; | 237 | return (struct ieee802154_mac_cb *)skb->cb; |
| 205 | } | 238 | } |
| 206 | 239 | ||
| 207 | #define MAC_CB_FLAG_TYPEMASK ((1 << 3) - 1) | 240 | static inline struct ieee802154_mac_cb *mac_cb_init(struct sk_buff *skb) |
| 208 | |||
| 209 | #define MAC_CB_FLAG_ACKREQ (1 << 3) | ||
| 210 | #define MAC_CB_FLAG_SECEN (1 << 4) | ||
| 211 | |||
| 212 | static inline bool mac_cb_is_ackreq(struct sk_buff *skb) | ||
| 213 | { | 241 | { |
| 214 | return mac_cb(skb)->flags & MAC_CB_FLAG_ACKREQ; | 242 | BUILD_BUG_ON(sizeof(struct ieee802154_mac_cb) > sizeof(skb->cb)); |
| 215 | } | ||
| 216 | 243 | ||
| 217 | static inline bool mac_cb_is_secen(struct sk_buff *skb) | 244 | memset(skb->cb, 0, sizeof(struct ieee802154_mac_cb)); |
| 218 | { | 245 | return mac_cb(skb); |
| 219 | return mac_cb(skb)->flags & MAC_CB_FLAG_SECEN; | ||
| 220 | } | 246 | } |
| 221 | 247 | ||
| 222 | static inline int mac_cb_type(struct sk_buff *skb) | 248 | #define IEEE802154_LLSEC_KEY_SIZE 16 |
| 223 | { | 249 | |
| 224 | return mac_cb(skb)->flags & MAC_CB_FLAG_TYPEMASK; | 250 | struct ieee802154_llsec_key_id { |
| 225 | } | 251 | u8 mode; |
| 252 | u8 id; | ||
| 253 | union { | ||
| 254 | struct ieee802154_addr device_addr; | ||
| 255 | __le32 short_source; | ||
| 256 | __le64 extended_source; | ||
| 257 | }; | ||
| 258 | }; | ||
| 259 | |||
| 260 | struct ieee802154_llsec_key { | ||
| 261 | u8 frame_types; | ||
| 262 | u32 cmd_frame_ids; | ||
| 263 | u8 key[IEEE802154_LLSEC_KEY_SIZE]; | ||
| 264 | }; | ||
| 265 | |||
| 266 | struct ieee802154_llsec_key_entry { | ||
| 267 | struct list_head list; | ||
| 268 | |||
| 269 | struct ieee802154_llsec_key_id id; | ||
| 270 | struct ieee802154_llsec_key *key; | ||
| 271 | }; | ||
| 272 | |||
| 273 | struct ieee802154_llsec_device_key { | ||
| 274 | struct list_head list; | ||
| 275 | |||
| 276 | struct ieee802154_llsec_key_id key_id; | ||
| 277 | u32 frame_counter; | ||
| 278 | }; | ||
| 279 | |||
| 280 | enum { | ||
| 281 | IEEE802154_LLSEC_DEVKEY_IGNORE, | ||
| 282 | IEEE802154_LLSEC_DEVKEY_RESTRICT, | ||
| 283 | IEEE802154_LLSEC_DEVKEY_RECORD, | ||
| 284 | |||
| 285 | __IEEE802154_LLSEC_DEVKEY_MAX, | ||
| 286 | }; | ||
| 287 | |||
| 288 | struct ieee802154_llsec_device { | ||
| 289 | struct list_head list; | ||
| 290 | |||
| 291 | __le16 pan_id; | ||
| 292 | __le16 short_addr; | ||
| 293 | __le64 hwaddr; | ||
| 294 | u32 frame_counter; | ||
| 295 | bool seclevel_exempt; | ||
| 296 | |||
| 297 | u8 key_mode; | ||
| 298 | struct list_head keys; | ||
| 299 | }; | ||
| 300 | |||
| 301 | struct ieee802154_llsec_seclevel { | ||
| 302 | struct list_head list; | ||
| 303 | |||
| 304 | u8 frame_type; | ||
| 305 | u8 cmd_frame_id; | ||
| 306 | bool device_override; | ||
| 307 | u32 sec_levels; | ||
| 308 | }; | ||
| 309 | |||
| 310 | struct ieee802154_llsec_params { | ||
| 311 | bool enabled; | ||
| 312 | |||
| 313 | __be32 frame_counter; | ||
| 314 | u8 out_level; | ||
| 315 | struct ieee802154_llsec_key_id out_key; | ||
| 316 | |||
| 317 | __le64 default_key_source; | ||
| 318 | |||
| 319 | __le16 pan_id; | ||
| 320 | __le64 hwaddr; | ||
| 321 | __le64 coord_hwaddr; | ||
| 322 | __le16 coord_shortaddr; | ||
| 323 | }; | ||
| 324 | |||
| 325 | struct ieee802154_llsec_table { | ||
| 326 | struct list_head keys; | ||
| 327 | struct list_head devices; | ||
| 328 | struct list_head security_levels; | ||
| 329 | }; | ||
| 226 | 330 | ||
| 227 | #define IEEE802154_MAC_SCAN_ED 0 | 331 | #define IEEE802154_MAC_SCAN_ED 0 |
| 228 | #define IEEE802154_MAC_SCAN_ACTIVE 1 | 332 | #define IEEE802154_MAC_SCAN_ACTIVE 1 |
| @@ -242,6 +346,53 @@ struct ieee802154_mac_params { | |||
| 242 | }; | 346 | }; |
| 243 | 347 | ||
| 244 | struct wpan_phy; | 348 | struct wpan_phy; |
| 349 | |||
| 350 | enum { | ||
| 351 | IEEE802154_LLSEC_PARAM_ENABLED = 1 << 0, | ||
| 352 | IEEE802154_LLSEC_PARAM_FRAME_COUNTER = 1 << 1, | ||
| 353 | IEEE802154_LLSEC_PARAM_OUT_LEVEL = 1 << 2, | ||
| 354 | IEEE802154_LLSEC_PARAM_OUT_KEY = 1 << 3, | ||
| 355 | IEEE802154_LLSEC_PARAM_KEY_SOURCE = 1 << 4, | ||
| 356 | IEEE802154_LLSEC_PARAM_PAN_ID = 1 << 5, | ||
| 357 | IEEE802154_LLSEC_PARAM_HWADDR = 1 << 6, | ||
| 358 | IEEE802154_LLSEC_PARAM_COORD_HWADDR = 1 << 7, | ||
| 359 | IEEE802154_LLSEC_PARAM_COORD_SHORTADDR = 1 << 8, | ||
| 360 | }; | ||
| 361 | |||
| 362 | struct ieee802154_llsec_ops { | ||
| 363 | int (*get_params)(struct net_device *dev, | ||
| 364 | struct ieee802154_llsec_params *params); | ||
| 365 | int (*set_params)(struct net_device *dev, | ||
| 366 | const struct ieee802154_llsec_params *params, | ||
| 367 | int changed); | ||
| 368 | |||
| 369 | int (*add_key)(struct net_device *dev, | ||
| 370 | const struct ieee802154_llsec_key_id *id, | ||
| 371 | const struct ieee802154_llsec_key *key); | ||
| 372 | int (*del_key)(struct net_device *dev, | ||
| 373 | const struct ieee802154_llsec_key_id *id); | ||
| 374 | |||
| 375 | int (*add_dev)(struct net_device *dev, | ||
| 376 | const struct ieee802154_llsec_device *llsec_dev); | ||
| 377 | int (*del_dev)(struct net_device *dev, __le64 dev_addr); | ||
| 378 | |||
| 379 | int (*add_devkey)(struct net_device *dev, | ||
| 380 | __le64 device_addr, | ||
| 381 | const struct ieee802154_llsec_device_key *key); | ||
| 382 | int (*del_devkey)(struct net_device *dev, | ||
| 383 | __le64 device_addr, | ||
| 384 | const struct ieee802154_llsec_device_key *key); | ||
| 385 | |||
| 386 | int (*add_seclevel)(struct net_device *dev, | ||
| 387 | const struct ieee802154_llsec_seclevel *sl); | ||
| 388 | int (*del_seclevel)(struct net_device *dev, | ||
| 389 | const struct ieee802154_llsec_seclevel *sl); | ||
| 390 | |||
| 391 | void (*lock_table)(struct net_device *dev); | ||
| 392 | void (*get_table)(struct net_device *dev, | ||
| 393 | struct ieee802154_llsec_table **t); | ||
| 394 | void (*unlock_table)(struct net_device *dev); | ||
| 395 | }; | ||
| 245 | /* | 396 | /* |
| 246 | * This should be located at net_device->ml_priv | 397 | * This should be located at net_device->ml_priv |
| 247 | * | 398 | * |
| @@ -272,6 +423,8 @@ struct ieee802154_mlme_ops { | |||
| 272 | void (*get_mac_params)(struct net_device *dev, | 423 | void (*get_mac_params)(struct net_device *dev, |
| 273 | struct ieee802154_mac_params *params); | 424 | struct ieee802154_mac_params *params); |
| 274 | 425 | ||
| 426 | struct ieee802154_llsec_ops *llsec; | ||
| 427 | |||
| 275 | /* The fields below are required. */ | 428 | /* The fields below are required. */ |
| 276 | 429 | ||
| 277 | struct wpan_phy *(*get_phy)(const struct net_device *dev); | 430 | struct wpan_phy *(*get_phy)(const struct net_device *dev); |
