^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2014 Fraunhofer ITWM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef MAC802154_LLSEC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define MAC802154_LLSEC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/hashtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <net/af_ieee802154.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <net/ieee802154_netdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct mac802154_llsec_key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct ieee802154_llsec_key key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* one tfm for each authsize (4/8/16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct crypto_aead *tfm[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct crypto_sync_skcipher *tfm0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct kref ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct mac802154_llsec_device_key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct ieee802154_llsec_device_key devkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct mac802154_llsec_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct ieee802154_llsec_device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct hlist_node bucket_s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct hlist_node bucket_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* protects dev.frame_counter and the elements of dev.keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct mac802154_llsec_seclevel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct ieee802154_llsec_seclevel level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct mac802154_llsec {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct ieee802154_llsec_params params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct ieee802154_llsec_table table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) DECLARE_HASHTABLE(devices_short, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) DECLARE_HASHTABLE(devices_hw, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* protects params, all other fields are fine with RCU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) rwlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) void mac802154_llsec_init(struct mac802154_llsec *sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) void mac802154_llsec_destroy(struct mac802154_llsec *sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int mac802154_llsec_get_params(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct ieee802154_llsec_params *params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int mac802154_llsec_set_params(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) const struct ieee802154_llsec_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int mac802154_llsec_key_add(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) const struct ieee802154_llsec_key_id *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) const struct ieee802154_llsec_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int mac802154_llsec_key_del(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const struct ieee802154_llsec_key_id *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int mac802154_llsec_dev_add(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) const struct ieee802154_llsec_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int mac802154_llsec_dev_del(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) __le64 device_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int mac802154_llsec_devkey_add(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) __le64 dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) const struct ieee802154_llsec_device_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int mac802154_llsec_devkey_del(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) __le64 dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) const struct ieee802154_llsec_device_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int mac802154_llsec_seclevel_add(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) const struct ieee802154_llsec_seclevel *sl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int mac802154_llsec_seclevel_del(struct mac802154_llsec *sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) const struct ieee802154_llsec_seclevel *sl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int mac802154_llsec_encrypt(struct mac802154_llsec *sec, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int mac802154_llsec_decrypt(struct mac802154_llsec *sec, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #endif /* MAC802154_LLSEC_H */