1*1802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 25d637d5aSPhoebe Buckheister /* 35d637d5aSPhoebe Buckheister * Copyright (C) 2014 Fraunhofer ITWM 45d637d5aSPhoebe Buckheister * 55d637d5aSPhoebe Buckheister * Written by: 65d637d5aSPhoebe Buckheister * Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de> 75d637d5aSPhoebe Buckheister */ 85d637d5aSPhoebe Buckheister 95d637d5aSPhoebe Buckheister #ifndef MAC802154_LLSEC_H 105d637d5aSPhoebe Buckheister #define MAC802154_LLSEC_H 115d637d5aSPhoebe Buckheister 125d637d5aSPhoebe Buckheister #include <linux/slab.h> 135d637d5aSPhoebe Buckheister #include <linux/hashtable.h> 145d637d5aSPhoebe Buckheister #include <linux/kref.h> 155d637d5aSPhoebe Buckheister #include <linux/spinlock.h> 165d637d5aSPhoebe Buckheister #include <net/af_ieee802154.h> 175d637d5aSPhoebe Buckheister #include <net/ieee802154_netdev.h> 185d637d5aSPhoebe Buckheister 195d637d5aSPhoebe Buckheister struct mac802154_llsec_key { 205d637d5aSPhoebe Buckheister struct ieee802154_llsec_key key; 215d637d5aSPhoebe Buckheister 225d637d5aSPhoebe Buckheister /* one tfm for each authsize (4/8/16) */ 235d637d5aSPhoebe Buckheister struct crypto_aead *tfm[3]; 243103f4a7SKees Cook struct crypto_sync_skcipher *tfm0; 255d637d5aSPhoebe Buckheister 265d637d5aSPhoebe Buckheister struct kref ref; 275d637d5aSPhoebe Buckheister }; 285d637d5aSPhoebe Buckheister 295d637d5aSPhoebe Buckheister struct mac802154_llsec_device_key { 305d637d5aSPhoebe Buckheister struct ieee802154_llsec_device_key devkey; 315d637d5aSPhoebe Buckheister 325d637d5aSPhoebe Buckheister struct rcu_head rcu; 335d637d5aSPhoebe Buckheister }; 345d637d5aSPhoebe Buckheister 355d637d5aSPhoebe Buckheister struct mac802154_llsec_device { 365d637d5aSPhoebe Buckheister struct ieee802154_llsec_device dev; 375d637d5aSPhoebe Buckheister 385d637d5aSPhoebe Buckheister struct hlist_node bucket_s; 395d637d5aSPhoebe Buckheister struct hlist_node bucket_hw; 405d637d5aSPhoebe Buckheister 415d637d5aSPhoebe Buckheister /* protects dev.frame_counter and the elements of dev.keys */ 425d637d5aSPhoebe Buckheister spinlock_t lock; 435d637d5aSPhoebe Buckheister 445d637d5aSPhoebe Buckheister struct rcu_head rcu; 455d637d5aSPhoebe Buckheister }; 465d637d5aSPhoebe Buckheister 475d637d5aSPhoebe Buckheister struct mac802154_llsec_seclevel { 485d637d5aSPhoebe Buckheister struct ieee802154_llsec_seclevel level; 495d637d5aSPhoebe Buckheister 505d637d5aSPhoebe Buckheister struct rcu_head rcu; 515d637d5aSPhoebe Buckheister }; 525d637d5aSPhoebe Buckheister 535d637d5aSPhoebe Buckheister struct mac802154_llsec { 545d637d5aSPhoebe Buckheister struct ieee802154_llsec_params params; 555d637d5aSPhoebe Buckheister struct ieee802154_llsec_table table; 565d637d5aSPhoebe Buckheister 575d637d5aSPhoebe Buckheister DECLARE_HASHTABLE(devices_short, 6); 585d637d5aSPhoebe Buckheister DECLARE_HASHTABLE(devices_hw, 6); 595d637d5aSPhoebe Buckheister 605d637d5aSPhoebe Buckheister /* protects params, all other fields are fine with RCU */ 615d637d5aSPhoebe Buckheister rwlock_t lock; 625d637d5aSPhoebe Buckheister }; 635d637d5aSPhoebe Buckheister 645d637d5aSPhoebe Buckheister void mac802154_llsec_init(struct mac802154_llsec *sec); 655d637d5aSPhoebe Buckheister void mac802154_llsec_destroy(struct mac802154_llsec *sec); 665d637d5aSPhoebe Buckheister 675d637d5aSPhoebe Buckheister int mac802154_llsec_get_params(struct mac802154_llsec *sec, 685d637d5aSPhoebe Buckheister struct ieee802154_llsec_params *params); 695d637d5aSPhoebe Buckheister int mac802154_llsec_set_params(struct mac802154_llsec *sec, 705d637d5aSPhoebe Buckheister const struct ieee802154_llsec_params *params, 715d637d5aSPhoebe Buckheister int changed); 725d637d5aSPhoebe Buckheister 735d637d5aSPhoebe Buckheister int mac802154_llsec_key_add(struct mac802154_llsec *sec, 745d637d5aSPhoebe Buckheister const struct ieee802154_llsec_key_id *id, 755d637d5aSPhoebe Buckheister const struct ieee802154_llsec_key *key); 765d637d5aSPhoebe Buckheister int mac802154_llsec_key_del(struct mac802154_llsec *sec, 775d637d5aSPhoebe Buckheister const struct ieee802154_llsec_key_id *key); 785d637d5aSPhoebe Buckheister 795d637d5aSPhoebe Buckheister int mac802154_llsec_dev_add(struct mac802154_llsec *sec, 805d637d5aSPhoebe Buckheister const struct ieee802154_llsec_device *dev); 815d637d5aSPhoebe Buckheister int mac802154_llsec_dev_del(struct mac802154_llsec *sec, 825d637d5aSPhoebe Buckheister __le64 device_addr); 835d637d5aSPhoebe Buckheister 845d637d5aSPhoebe Buckheister int mac802154_llsec_devkey_add(struct mac802154_llsec *sec, 855d637d5aSPhoebe Buckheister __le64 dev_addr, 865d637d5aSPhoebe Buckheister const struct ieee802154_llsec_device_key *key); 875d637d5aSPhoebe Buckheister int mac802154_llsec_devkey_del(struct mac802154_llsec *sec, 885d637d5aSPhoebe Buckheister __le64 dev_addr, 895d637d5aSPhoebe Buckheister const struct ieee802154_llsec_device_key *key); 905d637d5aSPhoebe Buckheister 915d637d5aSPhoebe Buckheister int mac802154_llsec_seclevel_add(struct mac802154_llsec *sec, 925d637d5aSPhoebe Buckheister const struct ieee802154_llsec_seclevel *sl); 935d637d5aSPhoebe Buckheister int mac802154_llsec_seclevel_del(struct mac802154_llsec *sec, 945d637d5aSPhoebe Buckheister const struct ieee802154_llsec_seclevel *sl); 955d637d5aSPhoebe Buckheister 9603556e4dSPhoebe Buckheister int mac802154_llsec_encrypt(struct mac802154_llsec *sec, struct sk_buff *skb); 974c14a2fbSPhoebe Buckheister int mac802154_llsec_decrypt(struct mac802154_llsec *sec, struct sk_buff *skb); 9803556e4dSPhoebe Buckheister 995d637d5aSPhoebe Buckheister #endif /* MAC802154_LLSEC_H */ 100