mib.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2007-2012 Siemens AG
  4. *
  5. * Written by:
  6. * Dmitry Eremin-Solenikov <[email protected]>
  7. * Sergey Lapin <[email protected]>
  8. * Maxim Gorbachyov <[email protected]>
  9. * Alexander Smirnov <[email protected]>
  10. */
  11. #include <linux/if_arp.h>
  12. #include <net/mac802154.h>
  13. #include <net/ieee802154_netdev.h>
  14. #include <net/cfg802154.h>
  15. #include "ieee802154_i.h"
  16. #include "driver-ops.h"
  17. void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
  18. {
  19. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  20. struct ieee802154_local *local = sdata->local;
  21. int res;
  22. ASSERT_RTNL();
  23. BUG_ON(dev->type != ARPHRD_IEEE802154);
  24. res = drv_set_channel(local, page, chan);
  25. if (res) {
  26. pr_debug("set_channel failed\n");
  27. } else {
  28. local->phy->current_channel = chan;
  29. local->phy->current_page = page;
  30. }
  31. }
  32. int mac802154_get_params(struct net_device *dev,
  33. struct ieee802154_llsec_params *params)
  34. {
  35. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  36. int res;
  37. BUG_ON(dev->type != ARPHRD_IEEE802154);
  38. mutex_lock(&sdata->sec_mtx);
  39. res = mac802154_llsec_get_params(&sdata->sec, params);
  40. mutex_unlock(&sdata->sec_mtx);
  41. return res;
  42. }
  43. int mac802154_set_params(struct net_device *dev,
  44. const struct ieee802154_llsec_params *params,
  45. int changed)
  46. {
  47. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  48. int res;
  49. BUG_ON(dev->type != ARPHRD_IEEE802154);
  50. mutex_lock(&sdata->sec_mtx);
  51. res = mac802154_llsec_set_params(&sdata->sec, params, changed);
  52. mutex_unlock(&sdata->sec_mtx);
  53. return res;
  54. }
  55. int mac802154_add_key(struct net_device *dev,
  56. const struct ieee802154_llsec_key_id *id,
  57. const struct ieee802154_llsec_key *key)
  58. {
  59. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  60. int res;
  61. BUG_ON(dev->type != ARPHRD_IEEE802154);
  62. mutex_lock(&sdata->sec_mtx);
  63. res = mac802154_llsec_key_add(&sdata->sec, id, key);
  64. mutex_unlock(&sdata->sec_mtx);
  65. return res;
  66. }
  67. int mac802154_del_key(struct net_device *dev,
  68. const struct ieee802154_llsec_key_id *id)
  69. {
  70. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  71. int res;
  72. BUG_ON(dev->type != ARPHRD_IEEE802154);
  73. mutex_lock(&sdata->sec_mtx);
  74. res = mac802154_llsec_key_del(&sdata->sec, id);
  75. mutex_unlock(&sdata->sec_mtx);
  76. return res;
  77. }
  78. int mac802154_add_dev(struct net_device *dev,
  79. const struct ieee802154_llsec_device *llsec_dev)
  80. {
  81. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  82. int res;
  83. BUG_ON(dev->type != ARPHRD_IEEE802154);
  84. mutex_lock(&sdata->sec_mtx);
  85. res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev);
  86. mutex_unlock(&sdata->sec_mtx);
  87. return res;
  88. }
  89. int mac802154_del_dev(struct net_device *dev, __le64 dev_addr)
  90. {
  91. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  92. int res;
  93. BUG_ON(dev->type != ARPHRD_IEEE802154);
  94. mutex_lock(&sdata->sec_mtx);
  95. res = mac802154_llsec_dev_del(&sdata->sec, dev_addr);
  96. mutex_unlock(&sdata->sec_mtx);
  97. return res;
  98. }
  99. int mac802154_add_devkey(struct net_device *dev,
  100. __le64 device_addr,
  101. const struct ieee802154_llsec_device_key *key)
  102. {
  103. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  104. int res;
  105. BUG_ON(dev->type != ARPHRD_IEEE802154);
  106. mutex_lock(&sdata->sec_mtx);
  107. res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key);
  108. mutex_unlock(&sdata->sec_mtx);
  109. return res;
  110. }
  111. int mac802154_del_devkey(struct net_device *dev,
  112. __le64 device_addr,
  113. const struct ieee802154_llsec_device_key *key)
  114. {
  115. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  116. int res;
  117. BUG_ON(dev->type != ARPHRD_IEEE802154);
  118. mutex_lock(&sdata->sec_mtx);
  119. res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key);
  120. mutex_unlock(&sdata->sec_mtx);
  121. return res;
  122. }
  123. int mac802154_add_seclevel(struct net_device *dev,
  124. const struct ieee802154_llsec_seclevel *sl)
  125. {
  126. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  127. int res;
  128. BUG_ON(dev->type != ARPHRD_IEEE802154);
  129. mutex_lock(&sdata->sec_mtx);
  130. res = mac802154_llsec_seclevel_add(&sdata->sec, sl);
  131. mutex_unlock(&sdata->sec_mtx);
  132. return res;
  133. }
  134. int mac802154_del_seclevel(struct net_device *dev,
  135. const struct ieee802154_llsec_seclevel *sl)
  136. {
  137. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  138. int res;
  139. BUG_ON(dev->type != ARPHRD_IEEE802154);
  140. mutex_lock(&sdata->sec_mtx);
  141. res = mac802154_llsec_seclevel_del(&sdata->sec, sl);
  142. mutex_unlock(&sdata->sec_mtx);
  143. return res;
  144. }
  145. void mac802154_lock_table(struct net_device *dev)
  146. {
  147. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  148. BUG_ON(dev->type != ARPHRD_IEEE802154);
  149. mutex_lock(&sdata->sec_mtx);
  150. }
  151. void mac802154_get_table(struct net_device *dev,
  152. struct ieee802154_llsec_table **t)
  153. {
  154. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  155. BUG_ON(dev->type != ARPHRD_IEEE802154);
  156. *t = &sdata->sec.table;
  157. }
  158. void mac802154_unlock_table(struct net_device *dev)
  159. {
  160. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  161. BUG_ON(dev->type != ARPHRD_IEEE802154);
  162. mutex_unlock(&sdata->sec_mtx);
  163. }