xref: /linux/net/mac802154/llsec.h (revision 3932b9ca55b0be314a36d3e84faff3e823c081f5)
1 /*
2  * Copyright (C) 2014 Fraunhofer ITWM
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * Written by:
14  * Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
15  */
16 
17 #ifndef MAC802154_LLSEC_H
18 #define MAC802154_LLSEC_H
19 
20 #include <linux/slab.h>
21 #include <linux/hashtable.h>
22 #include <linux/crypto.h>
23 #include <linux/kref.h>
24 #include <linux/spinlock.h>
25 #include <net/af_ieee802154.h>
26 #include <net/ieee802154_netdev.h>
27 
28 struct mac802154_llsec_key {
29 	struct ieee802154_llsec_key key;
30 
31 	/* one tfm for each authsize (4/8/16) */
32 	struct crypto_aead *tfm[3];
33 	struct crypto_blkcipher *tfm0;
34 
35 	struct kref ref;
36 };
37 
38 struct mac802154_llsec_device_key {
39 	struct ieee802154_llsec_device_key devkey;
40 
41 	struct rcu_head rcu;
42 };
43 
44 struct mac802154_llsec_device {
45 	struct ieee802154_llsec_device dev;
46 
47 	struct hlist_node bucket_s;
48 	struct hlist_node bucket_hw;
49 
50 	/* protects dev.frame_counter and the elements of dev.keys */
51 	spinlock_t lock;
52 
53 	struct rcu_head rcu;
54 };
55 
56 struct mac802154_llsec_seclevel {
57 	struct ieee802154_llsec_seclevel level;
58 
59 	struct rcu_head rcu;
60 };
61 
62 struct mac802154_llsec {
63 	struct ieee802154_llsec_params params;
64 	struct ieee802154_llsec_table table;
65 
66 	DECLARE_HASHTABLE(devices_short, 6);
67 	DECLARE_HASHTABLE(devices_hw, 6);
68 
69 	/* protects params, all other fields are fine with RCU */
70 	rwlock_t lock;
71 };
72 
73 void mac802154_llsec_init(struct mac802154_llsec *sec);
74 void mac802154_llsec_destroy(struct mac802154_llsec *sec);
75 
76 int mac802154_llsec_get_params(struct mac802154_llsec *sec,
77 			       struct ieee802154_llsec_params *params);
78 int mac802154_llsec_set_params(struct mac802154_llsec *sec,
79 			       const struct ieee802154_llsec_params *params,
80 			       int changed);
81 
82 int mac802154_llsec_key_add(struct mac802154_llsec *sec,
83 			    const struct ieee802154_llsec_key_id *id,
84 			    const struct ieee802154_llsec_key *key);
85 int mac802154_llsec_key_del(struct mac802154_llsec *sec,
86 			    const struct ieee802154_llsec_key_id *key);
87 
88 int mac802154_llsec_dev_add(struct mac802154_llsec *sec,
89 			    const struct ieee802154_llsec_device *dev);
90 int mac802154_llsec_dev_del(struct mac802154_llsec *sec,
91 			    __le64 device_addr);
92 
93 int mac802154_llsec_devkey_add(struct mac802154_llsec *sec,
94 			       __le64 dev_addr,
95 			       const struct ieee802154_llsec_device_key *key);
96 int mac802154_llsec_devkey_del(struct mac802154_llsec *sec,
97 			       __le64 dev_addr,
98 			       const struct ieee802154_llsec_device_key *key);
99 
100 int mac802154_llsec_seclevel_add(struct mac802154_llsec *sec,
101 				 const struct ieee802154_llsec_seclevel *sl);
102 int mac802154_llsec_seclevel_del(struct mac802154_llsec *sec,
103 				 const struct ieee802154_llsec_seclevel *sl);
104 
105 int mac802154_llsec_encrypt(struct mac802154_llsec *sec, struct sk_buff *skb);
106 int mac802154_llsec_decrypt(struct mac802154_llsec *sec, struct sk_buff *skb);
107 
108 #endif /* MAC802154_LLSEC_H */
109