mib.c 5.5 KB

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