mib.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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_short_addr(struct net_device *dev, __le16 val)
  26. {
  27. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  28. BUG_ON(dev->type != ARPHRD_IEEE802154);
  29. spin_lock_bh(&sdata->mib_lock);
  30. sdata->short_addr = val;
  31. spin_unlock_bh(&sdata->mib_lock);
  32. }
  33. __le16 mac802154_dev_get_short_addr(const struct net_device *dev)
  34. {
  35. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  36. __le16 ret;
  37. BUG_ON(dev->type != ARPHRD_IEEE802154);
  38. spin_lock_bh(&sdata->mib_lock);
  39. ret = sdata->short_addr;
  40. spin_unlock_bh(&sdata->mib_lock);
  41. return ret;
  42. }
  43. __le16 mac802154_dev_get_pan_id(const struct net_device *dev)
  44. {
  45. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  46. __le16 ret;
  47. BUG_ON(dev->type != ARPHRD_IEEE802154);
  48. spin_lock_bh(&sdata->mib_lock);
  49. ret = sdata->pan_id;
  50. spin_unlock_bh(&sdata->mib_lock);
  51. return ret;
  52. }
  53. void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val)
  54. {
  55. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  56. BUG_ON(dev->type != ARPHRD_IEEE802154);
  57. spin_lock_bh(&sdata->mib_lock);
  58. sdata->pan_id = val;
  59. spin_unlock_bh(&sdata->mib_lock);
  60. }
  61. u8 mac802154_dev_get_dsn(const struct net_device *dev)
  62. {
  63. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  64. BUG_ON(dev->type != ARPHRD_IEEE802154);
  65. return sdata->dsn++;
  66. }
  67. void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
  68. {
  69. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  70. struct ieee802154_local *local = sdata->local;
  71. int res;
  72. BUG_ON(dev->type != ARPHRD_IEEE802154);
  73. res = drv_set_channel(local, page, chan);
  74. if (res) {
  75. pr_debug("set_channel failed\n");
  76. } else {
  77. mutex_lock(&local->phy->pib_lock);
  78. local->phy->current_channel = chan;
  79. local->phy->current_page = page;
  80. mutex_unlock(&local->phy->pib_lock);
  81. }
  82. }
  83. int mac802154_get_params(struct net_device *dev,
  84. struct ieee802154_llsec_params *params)
  85. {
  86. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  87. int res;
  88. BUG_ON(dev->type != ARPHRD_IEEE802154);
  89. mutex_lock(&sdata->sec_mtx);
  90. res = mac802154_llsec_get_params(&sdata->sec, params);
  91. mutex_unlock(&sdata->sec_mtx);
  92. return res;
  93. }
  94. int mac802154_set_params(struct net_device *dev,
  95. const struct ieee802154_llsec_params *params,
  96. int changed)
  97. {
  98. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  99. int res;
  100. BUG_ON(dev->type != ARPHRD_IEEE802154);
  101. mutex_lock(&sdata->sec_mtx);
  102. res = mac802154_llsec_set_params(&sdata->sec, params, changed);
  103. mutex_unlock(&sdata->sec_mtx);
  104. return res;
  105. }
  106. int mac802154_add_key(struct net_device *dev,
  107. const struct ieee802154_llsec_key_id *id,
  108. const struct ieee802154_llsec_key *key)
  109. {
  110. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  111. int res;
  112. BUG_ON(dev->type != ARPHRD_IEEE802154);
  113. mutex_lock(&sdata->sec_mtx);
  114. res = mac802154_llsec_key_add(&sdata->sec, id, key);
  115. mutex_unlock(&sdata->sec_mtx);
  116. return res;
  117. }
  118. int mac802154_del_key(struct net_device *dev,
  119. const struct ieee802154_llsec_key_id *id)
  120. {
  121. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  122. int res;
  123. BUG_ON(dev->type != ARPHRD_IEEE802154);
  124. mutex_lock(&sdata->sec_mtx);
  125. res = mac802154_llsec_key_del(&sdata->sec, id);
  126. mutex_unlock(&sdata->sec_mtx);
  127. return res;
  128. }
  129. int mac802154_add_dev(struct net_device *dev,
  130. const struct ieee802154_llsec_device *llsec_dev)
  131. {
  132. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  133. int res;
  134. BUG_ON(dev->type != ARPHRD_IEEE802154);
  135. mutex_lock(&sdata->sec_mtx);
  136. res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev);
  137. mutex_unlock(&sdata->sec_mtx);
  138. return res;
  139. }
  140. int mac802154_del_dev(struct net_device *dev, __le64 dev_addr)
  141. {
  142. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  143. int res;
  144. BUG_ON(dev->type != ARPHRD_IEEE802154);
  145. mutex_lock(&sdata->sec_mtx);
  146. res = mac802154_llsec_dev_del(&sdata->sec, dev_addr);
  147. mutex_unlock(&sdata->sec_mtx);
  148. return res;
  149. }
  150. int mac802154_add_devkey(struct net_device *dev,
  151. __le64 device_addr,
  152. const struct ieee802154_llsec_device_key *key)
  153. {
  154. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  155. int res;
  156. BUG_ON(dev->type != ARPHRD_IEEE802154);
  157. mutex_lock(&sdata->sec_mtx);
  158. res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key);
  159. mutex_unlock(&sdata->sec_mtx);
  160. return res;
  161. }
  162. int mac802154_del_devkey(struct net_device *dev,
  163. __le64 device_addr,
  164. const struct ieee802154_llsec_device_key *key)
  165. {
  166. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  167. int res;
  168. BUG_ON(dev->type != ARPHRD_IEEE802154);
  169. mutex_lock(&sdata->sec_mtx);
  170. res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key);
  171. mutex_unlock(&sdata->sec_mtx);
  172. return res;
  173. }
  174. int mac802154_add_seclevel(struct net_device *dev,
  175. const struct ieee802154_llsec_seclevel *sl)
  176. {
  177. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  178. int res;
  179. BUG_ON(dev->type != ARPHRD_IEEE802154);
  180. mutex_lock(&sdata->sec_mtx);
  181. res = mac802154_llsec_seclevel_add(&sdata->sec, sl);
  182. mutex_unlock(&sdata->sec_mtx);
  183. return res;
  184. }
  185. int mac802154_del_seclevel(struct net_device *dev,
  186. const struct ieee802154_llsec_seclevel *sl)
  187. {
  188. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  189. int res;
  190. BUG_ON(dev->type != ARPHRD_IEEE802154);
  191. mutex_lock(&sdata->sec_mtx);
  192. res = mac802154_llsec_seclevel_del(&sdata->sec, sl);
  193. mutex_unlock(&sdata->sec_mtx);
  194. return res;
  195. }
  196. void mac802154_lock_table(struct net_device *dev)
  197. {
  198. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  199. BUG_ON(dev->type != ARPHRD_IEEE802154);
  200. mutex_lock(&sdata->sec_mtx);
  201. }
  202. void mac802154_get_table(struct net_device *dev,
  203. struct ieee802154_llsec_table **t)
  204. {
  205. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  206. BUG_ON(dev->type != ARPHRD_IEEE802154);
  207. *t = &sdata->sec.table;
  208. }
  209. void mac802154_unlock_table(struct net_device *dev)
  210. {
  211. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  212. BUG_ON(dev->type != ARPHRD_IEEE802154);
  213. mutex_unlock(&sdata->sec_mtx);
  214. }