Linux Audio

Check our new training course

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