llsec.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifndef MAC802154_LLSEC_H
  17. #define MAC802154_LLSEC_H
  18. #include <linux/slab.h>
  19. #include <linux/hashtable.h>
  20. #include <linux/kref.h>
  21. #include <linux/spinlock.h>
  22. #include <net/af_ieee802154.h>
  23. #include <net/ieee802154_netdev.h>
  24. struct mac802154_llsec_key {
  25. struct ieee802154_llsec_key key;
  26. /* one tfm for each authsize (4/8/16) */
  27. struct crypto_aead *tfm[3];
  28. struct crypto_skcipher *tfm0;
  29. struct kref ref;
  30. };
  31. struct mac802154_llsec_device_key {
  32. struct ieee802154_llsec_device_key devkey;
  33. struct rcu_head rcu;
  34. };
  35. struct mac802154_llsec_device {
  36. struct ieee802154_llsec_device dev;
  37. struct hlist_node bucket_s;
  38. struct hlist_node bucket_hw;
  39. /* protects dev.frame_counter and the elements of dev.keys */
  40. spinlock_t lock;
  41. struct rcu_head rcu;
  42. };
  43. struct mac802154_llsec_seclevel {
  44. struct ieee802154_llsec_seclevel level;
  45. struct rcu_head rcu;
  46. };
  47. struct mac802154_llsec {
  48. struct ieee802154_llsec_params params;
  49. struct ieee802154_llsec_table table;
  50. DECLARE_HASHTABLE(devices_short, 6);
  51. DECLARE_HASHTABLE(devices_hw, 6);
  52. /* protects params, all other fields are fine with RCU */
  53. rwlock_t lock;
  54. };
  55. void mac802154_llsec_init(struct mac802154_llsec *sec);
  56. void mac802154_llsec_destroy(struct mac802154_llsec *sec);
  57. int mac802154_llsec_get_params(struct mac802154_llsec *sec,
  58. struct ieee802154_llsec_params *params);
  59. int mac802154_llsec_set_params(struct mac802154_llsec *sec,
  60. const struct ieee802154_llsec_params *params,
  61. int changed);
  62. int mac802154_llsec_key_add(struct mac802154_llsec *sec,
  63. const struct ieee802154_llsec_key_id *id,
  64. const struct ieee802154_llsec_key *key);
  65. int mac802154_llsec_key_del(struct mac802154_llsec *sec,
  66. const struct ieee802154_llsec_key_id *key);
  67. int mac802154_llsec_dev_add(struct mac802154_llsec *sec,
  68. const struct ieee802154_llsec_device *dev);
  69. int mac802154_llsec_dev_del(struct mac802154_llsec *sec,
  70. __le64 device_addr);
  71. int mac802154_llsec_devkey_add(struct mac802154_llsec *sec,
  72. __le64 dev_addr,
  73. const struct ieee802154_llsec_device_key *key);
  74. int mac802154_llsec_devkey_del(struct mac802154_llsec *sec,
  75. __le64 dev_addr,
  76. const struct ieee802154_llsec_device_key *key);
  77. int mac802154_llsec_seclevel_add(struct mac802154_llsec *sec,
  78. const struct ieee802154_llsec_seclevel *sl);
  79. int mac802154_llsec_seclevel_del(struct mac802154_llsec *sec,
  80. const struct ieee802154_llsec_seclevel *sl);
  81. int mac802154_llsec_encrypt(struct mac802154_llsec *sec, struct sk_buff *skb);
  82. int mac802154_llsec_decrypt(struct mac802154_llsec *sec, struct sk_buff *skb);
  83. #endif /* MAC802154_LLSEC_H */