llsec.h 3.2 KB

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