wext-sme.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * cfg80211 wext compat for managed mode.
  3. *
  4. * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright (C) 2009 Intel Corporation. All rights reserved.
  6. */
  7. #include <linux/etherdevice.h>
  8. #include <linux/if_arp.h>
  9. #include <net/cfg80211.h>
  10. #include "nl80211.h"
  11. static int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
  12. struct wireless_dev *wdev)
  13. {
  14. int err;
  15. if (!netif_running(wdev->netdev))
  16. return 0;
  17. wdev->wext.connect.ie = wdev->wext.ie;
  18. wdev->wext.connect.ie_len = wdev->wext.ie_len;
  19. wdev->wext.connect.privacy = wdev->wext.default_key != -1;
  20. err = 0;
  21. if (wdev->wext.connect.ssid_len != 0)
  22. err = cfg80211_connect(rdev, wdev->netdev,
  23. &wdev->wext.connect);
  24. return err;
  25. }
  26. int cfg80211_mgd_wext_siwfreq(struct net_device *dev,
  27. struct iw_request_info *info,
  28. struct iw_freq *freq, char *extra)
  29. {
  30. struct wireless_dev *wdev = dev->ieee80211_ptr;
  31. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  32. struct ieee80211_channel *chan;
  33. int err;
  34. /* call only for station! */
  35. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
  36. return -EINVAL;
  37. chan = cfg80211_wext_freq(wdev->wiphy, freq);
  38. if (chan && IS_ERR(chan))
  39. return PTR_ERR(chan);
  40. if (chan && (chan->flags & IEEE80211_CHAN_DISABLED))
  41. return -EINVAL;
  42. if (wdev->wext.connect.channel == chan)
  43. return 0;
  44. if (wdev->sme_state != CFG80211_SME_IDLE) {
  45. bool event = true;
  46. /* if SSID set, we'll try right again, avoid event */
  47. if (wdev->wext.connect.ssid_len)
  48. event = false;
  49. err = cfg80211_disconnect(wiphy_to_dev(wdev->wiphy),
  50. dev, WLAN_REASON_DEAUTH_LEAVING,
  51. event);
  52. if (err)
  53. return err;
  54. }
  55. wdev->wext.connect.channel = chan;
  56. /* SSID is not set, we just want to switch channel */
  57. if (wdev->wext.connect.ssid_len && chan) {
  58. if (!rdev->ops->set_channel)
  59. return -EOPNOTSUPP;
  60. return rdev->ops->set_channel(wdev->wiphy, chan,
  61. NL80211_CHAN_NO_HT);
  62. }
  63. return cfg80211_mgd_wext_connect(wiphy_to_dev(wdev->wiphy), wdev);
  64. }
  65. /* temporary symbol - mark GPL - in the future the handler won't be */
  66. EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_siwfreq);
  67. int cfg80211_mgd_wext_giwfreq(struct net_device *dev,
  68. struct iw_request_info *info,
  69. struct iw_freq *freq, char *extra)
  70. {
  71. struct wireless_dev *wdev = dev->ieee80211_ptr;
  72. struct ieee80211_channel *chan = NULL;
  73. /* call only for station! */
  74. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
  75. return -EINVAL;
  76. if (wdev->current_bss)
  77. chan = wdev->current_bss->pub.channel;
  78. else if (wdev->wext.connect.channel)
  79. chan = wdev->wext.connect.channel;
  80. if (chan) {
  81. freq->m = chan->center_freq;
  82. freq->e = 6;
  83. return 0;
  84. }
  85. /* no channel if not joining */
  86. return -EINVAL;
  87. }
  88. /* temporary symbol - mark GPL - in the future the handler won't be */
  89. EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_giwfreq);
  90. int cfg80211_mgd_wext_siwessid(struct net_device *dev,
  91. struct iw_request_info *info,
  92. struct iw_point *data, char *ssid)
  93. {
  94. struct wireless_dev *wdev = dev->ieee80211_ptr;
  95. size_t len = data->length;
  96. int err;
  97. /* call only for station! */
  98. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
  99. return -EINVAL;
  100. if (!data->flags)
  101. len = 0;
  102. /* iwconfig uses nul termination in SSID.. */
  103. if (len > 0 && ssid[len - 1] == '\0')
  104. len--;
  105. if (wdev->wext.connect.ssid && len &&
  106. len == wdev->wext.connect.ssid_len &&
  107. memcmp(wdev->wext.connect.ssid, ssid, len))
  108. return 0;
  109. if (wdev->sme_state != CFG80211_SME_IDLE) {
  110. bool event = true;
  111. /* if SSID set now, we'll try to connect, avoid event */
  112. if (len)
  113. event = false;
  114. err = cfg80211_disconnect(wiphy_to_dev(wdev->wiphy),
  115. dev, WLAN_REASON_DEAUTH_LEAVING,
  116. event);
  117. if (err)
  118. return err;
  119. }
  120. wdev->wext.connect.ssid = wdev->wext.ssid;
  121. memcpy(wdev->wext.ssid, ssid, len);
  122. wdev->wext.connect.ssid_len = len;
  123. wdev->wext.connect.crypto.control_port = false;
  124. return cfg80211_mgd_wext_connect(wiphy_to_dev(wdev->wiphy), wdev);
  125. }
  126. /* temporary symbol - mark GPL - in the future the handler won't be */
  127. EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_siwessid);
  128. int cfg80211_mgd_wext_giwessid(struct net_device *dev,
  129. struct iw_request_info *info,
  130. struct iw_point *data, char *ssid)
  131. {
  132. struct wireless_dev *wdev = dev->ieee80211_ptr;
  133. /* call only for station! */
  134. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
  135. return -EINVAL;
  136. data->flags = 0;
  137. if (wdev->ssid_len) {
  138. data->flags = 1;
  139. data->length = wdev->ssid_len;
  140. memcpy(ssid, wdev->ssid, data->length);
  141. } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) {
  142. data->flags = 1;
  143. data->length = wdev->wext.connect.ssid_len;
  144. memcpy(ssid, wdev->wext.connect.ssid, data->length);
  145. } else
  146. data->flags = 0;
  147. return 0;
  148. }
  149. /* temporary symbol - mark GPL - in the future the handler won't be */
  150. EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_giwessid);
  151. int cfg80211_mgd_wext_siwap(struct net_device *dev,
  152. struct iw_request_info *info,
  153. struct sockaddr *ap_addr, char *extra)
  154. {
  155. struct wireless_dev *wdev = dev->ieee80211_ptr;
  156. u8 *bssid = ap_addr->sa_data;
  157. int err;
  158. /* call only for station! */
  159. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
  160. return -EINVAL;
  161. if (ap_addr->sa_family != ARPHRD_ETHER)
  162. return -EINVAL;
  163. /* automatic mode */
  164. if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid))
  165. bssid = NULL;
  166. /* both automatic */
  167. if (!bssid && !wdev->wext.connect.bssid)
  168. return 0;
  169. /* fixed already - and no change */
  170. if (wdev->wext.connect.bssid && bssid &&
  171. compare_ether_addr(bssid, wdev->wext.connect.bssid) == 0)
  172. return 0;
  173. if (wdev->sme_state != CFG80211_SME_IDLE) {
  174. err = cfg80211_disconnect(wiphy_to_dev(wdev->wiphy),
  175. dev, WLAN_REASON_DEAUTH_LEAVING,
  176. false);
  177. if (err)
  178. return err;
  179. }
  180. if (bssid) {
  181. memcpy(wdev->wext.bssid, bssid, ETH_ALEN);
  182. wdev->wext.connect.bssid = wdev->wext.bssid;
  183. } else
  184. wdev->wext.connect.bssid = NULL;
  185. return cfg80211_mgd_wext_connect(wiphy_to_dev(wdev->wiphy), wdev);
  186. }
  187. /* temporary symbol - mark GPL - in the future the handler won't be */
  188. EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_siwap);
  189. int cfg80211_mgd_wext_giwap(struct net_device *dev,
  190. struct iw_request_info *info,
  191. struct sockaddr *ap_addr, char *extra)
  192. {
  193. struct wireless_dev *wdev = dev->ieee80211_ptr;
  194. /* call only for station! */
  195. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
  196. return -EINVAL;
  197. ap_addr->sa_family = ARPHRD_ETHER;
  198. if (wdev->current_bss)
  199. memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
  200. else if (wdev->wext.connect.bssid)
  201. memcpy(ap_addr->sa_data, wdev->wext.connect.bssid, ETH_ALEN);
  202. else
  203. memset(ap_addr->sa_data, 0, ETH_ALEN);
  204. return 0;
  205. }
  206. /* temporary symbol - mark GPL - in the future the handler won't be */
  207. EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_giwap);
  208. int cfg80211_wext_siwgenie(struct net_device *dev,
  209. struct iw_request_info *info,
  210. struct iw_point *data, char *extra)
  211. {
  212. struct wireless_dev *wdev = dev->ieee80211_ptr;
  213. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  214. u8 *ie = extra;
  215. int ie_len = data->length, err;
  216. if (wdev->iftype != NL80211_IFTYPE_STATION)
  217. return -EOPNOTSUPP;
  218. if (!ie_len)
  219. ie = NULL;
  220. /* no change */
  221. if (wdev->wext.ie_len == ie_len &&
  222. memcmp(wdev->wext.ie, ie, ie_len) == 0)
  223. return 0;
  224. if (ie_len) {
  225. ie = kmemdup(extra, ie_len, GFP_KERNEL);
  226. if (!ie)
  227. return -ENOMEM;
  228. } else
  229. ie = NULL;
  230. kfree(wdev->wext.ie);
  231. wdev->wext.ie = ie;
  232. wdev->wext.ie_len = ie_len;
  233. if (wdev->sme_state != CFG80211_SME_IDLE) {
  234. err = cfg80211_disconnect(rdev, dev,
  235. WLAN_REASON_DEAUTH_LEAVING, false);
  236. if (err)
  237. return err;
  238. }
  239. /* userspace better not think we'll reconnect */
  240. return 0;
  241. }
  242. EXPORT_SYMBOL_GPL(cfg80211_wext_siwgenie);
  243. int cfg80211_wext_siwmlme(struct net_device *dev,
  244. struct iw_request_info *info,
  245. struct iw_point *data, char *extra)
  246. {
  247. struct wireless_dev *wdev = dev->ieee80211_ptr;
  248. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  249. struct cfg80211_registered_device *rdev;
  250. if (!wdev)
  251. return -EOPNOTSUPP;
  252. rdev = wiphy_to_dev(wdev->wiphy);
  253. if (wdev->iftype != NL80211_IFTYPE_STATION)
  254. return -EINVAL;
  255. if (mlme->addr.sa_family != ARPHRD_ETHER)
  256. return -EINVAL;
  257. switch (mlme->cmd) {
  258. case IW_MLME_DEAUTH:
  259. case IW_MLME_DISASSOC:
  260. return cfg80211_disconnect(rdev, dev, mlme->reason_code,
  261. true);
  262. default:
  263. return -EOPNOTSUPP;
  264. }
  265. }
  266. EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme);