ieee80211softmac_wx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. * This file contains our _wx handlers. Make sure you EXPORT_SYMBOL_GPL them
  3. *
  4. * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net>
  5. * Joseph Jezak <josejx@gentoo.org>
  6. * Larry Finger <Larry.Finger@lwfinger.net>
  7. * Danny van Dyk <kugelfang@gentoo.org>
  8. * Michael Buesch <mbuesch@freenet.de>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * The full GNU General Public License is included in this distribution in the
  24. * file called COPYING.
  25. */
  26. #include "ieee80211softmac_priv.h"
  27. #include <net/iw_handler.h>
  28. /* for is_broadcast_ether_addr and is_zero_ether_addr */
  29. #include <linux/etherdevice.h>
  30. int
  31. ieee80211softmac_wx_trigger_scan(struct net_device *net_dev,
  32. struct iw_request_info *info,
  33. union iwreq_data *data,
  34. char *extra)
  35. {
  36. struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
  37. return ieee80211softmac_start_scan(sm);
  38. }
  39. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_trigger_scan);
  40. /* if we're still scanning, return -EAGAIN so that userspace tools
  41. * can get the complete scan results, otherwise return 0. */
  42. int
  43. ieee80211softmac_wx_get_scan_results(struct net_device *net_dev,
  44. struct iw_request_info *info,
  45. union iwreq_data *data,
  46. char *extra)
  47. {
  48. unsigned long flags;
  49. struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
  50. spin_lock_irqsave(&sm->lock, flags);
  51. if (sm->scanning) {
  52. spin_unlock_irqrestore(&sm->lock, flags);
  53. return -EAGAIN;
  54. }
  55. spin_unlock_irqrestore(&sm->lock, flags);
  56. return ieee80211_wx_get_scan(sm->ieee, info, data, extra);
  57. }
  58. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_scan_results);
  59. int
  60. ieee80211softmac_wx_set_essid(struct net_device *net_dev,
  61. struct iw_request_info *info,
  62. union iwreq_data *data,
  63. char *extra)
  64. {
  65. struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
  66. int length = 0;
  67. unsigned long flags;
  68. spin_lock_irqsave(&sm->lock, flags);
  69. sm->associnfo.static_essid = 0;
  70. if (data->essid.flags && data->essid.length && extra /*required?*/) {
  71. length = min(data->essid.length - 1, IW_ESSID_MAX_SIZE);
  72. if (length) {
  73. memcpy(sm->associnfo.req_essid.data, extra, length);
  74. sm->associnfo.static_essid = 1;
  75. }
  76. }
  77. /* set our requested ESSID length.
  78. * If applicable, we have already copied the data in */
  79. sm->associnfo.req_essid.len = length;
  80. /* queue lower level code to do work (if necessary) */
  81. schedule_work(&sm->associnfo.work);
  82. spin_unlock_irqrestore(&sm->lock, flags);
  83. return 0;
  84. }
  85. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_essid);
  86. int
  87. ieee80211softmac_wx_get_essid(struct net_device *net_dev,
  88. struct iw_request_info *info,
  89. union iwreq_data *data,
  90. char *extra)
  91. {
  92. struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
  93. unsigned long flags;
  94. /* avoid getting inconsistent information */
  95. spin_lock_irqsave(&sm->lock, flags);
  96. /* If all fails, return ANY (empty) */
  97. data->essid.length = 0;
  98. data->essid.flags = 0; /* active */
  99. /* If we have a statically configured ESSID then return it */
  100. if (sm->associnfo.static_essid) {
  101. data->essid.length = sm->associnfo.req_essid.len;
  102. data->essid.flags = 1; /* active */
  103. memcpy(extra, sm->associnfo.req_essid.data, sm->associnfo.req_essid.len);
  104. }
  105. /* If we're associating/associated, return that */
  106. if (sm->associated || sm->associnfo.associating) {
  107. data->essid.length = sm->associnfo.associate_essid.len;
  108. data->essid.flags = 1; /* active */
  109. memcpy(extra, sm->associnfo.associate_essid.data, sm->associnfo.associate_essid.len);
  110. }
  111. spin_unlock_irqrestore(&sm->lock, flags);
  112. return 0;
  113. }
  114. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_essid);
  115. int
  116. ieee80211softmac_wx_set_rate(struct net_device *net_dev,
  117. struct iw_request_info *info,
  118. union iwreq_data *data,
  119. char *extra)
  120. {
  121. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  122. struct ieee80211_device *ieee = mac->ieee;
  123. unsigned long flags;
  124. s32 in_rate = data->bitrate.value;
  125. u8 rate;
  126. int is_ofdm = 0;
  127. int err = -EINVAL;
  128. if (in_rate == -1) {
  129. /* FIXME: We don't correctly handle backing down to lower
  130. rates, so 801.11g devices start off at 11M for now. People
  131. can manually change it if they really need to, but 11M is
  132. more reliable. Note similar logic in
  133. ieee80211softmac_wx_set_rate() */
  134. if (ieee->modulation & IEEE80211_CCK_MODULATION)
  135. in_rate = 11000000;
  136. else
  137. in_rate = 54000000;
  138. }
  139. switch (in_rate) {
  140. case 1000000:
  141. rate = IEEE80211_CCK_RATE_1MB;
  142. break;
  143. case 2000000:
  144. rate = IEEE80211_CCK_RATE_2MB;
  145. break;
  146. case 5500000:
  147. rate = IEEE80211_CCK_RATE_5MB;
  148. break;
  149. case 11000000:
  150. rate = IEEE80211_CCK_RATE_11MB;
  151. break;
  152. case 6000000:
  153. rate = IEEE80211_OFDM_RATE_6MB;
  154. is_ofdm = 1;
  155. break;
  156. case 9000000:
  157. rate = IEEE80211_OFDM_RATE_9MB;
  158. is_ofdm = 1;
  159. break;
  160. case 12000000:
  161. rate = IEEE80211_OFDM_RATE_12MB;
  162. is_ofdm = 1;
  163. break;
  164. case 18000000:
  165. rate = IEEE80211_OFDM_RATE_18MB;
  166. is_ofdm = 1;
  167. break;
  168. case 24000000:
  169. rate = IEEE80211_OFDM_RATE_24MB;
  170. is_ofdm = 1;
  171. break;
  172. case 36000000:
  173. rate = IEEE80211_OFDM_RATE_36MB;
  174. is_ofdm = 1;
  175. break;
  176. case 48000000:
  177. rate = IEEE80211_OFDM_RATE_48MB;
  178. is_ofdm = 1;
  179. break;
  180. case 54000000:
  181. rate = IEEE80211_OFDM_RATE_54MB;
  182. is_ofdm = 1;
  183. break;
  184. default:
  185. goto out;
  186. }
  187. spin_lock_irqsave(&mac->lock, flags);
  188. /* Check if correct modulation for this PHY. */
  189. if (is_ofdm && !(ieee->modulation & IEEE80211_OFDM_MODULATION))
  190. goto out_unlock;
  191. mac->txrates.default_rate = rate;
  192. mac->txrates.default_fallback = lower_rate(mac, rate);
  193. err = 0;
  194. out_unlock:
  195. spin_unlock_irqrestore(&mac->lock, flags);
  196. out:
  197. return err;
  198. }
  199. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_rate);
  200. int
  201. ieee80211softmac_wx_get_rate(struct net_device *net_dev,
  202. struct iw_request_info *info,
  203. union iwreq_data *data,
  204. char *extra)
  205. {
  206. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  207. unsigned long flags;
  208. int err = -EINVAL;
  209. spin_lock_irqsave(&mac->lock, flags);
  210. switch (mac->txrates.default_rate) {
  211. case IEEE80211_CCK_RATE_1MB:
  212. data->bitrate.value = 1000000;
  213. break;
  214. case IEEE80211_CCK_RATE_2MB:
  215. data->bitrate.value = 2000000;
  216. break;
  217. case IEEE80211_CCK_RATE_5MB:
  218. data->bitrate.value = 5500000;
  219. break;
  220. case IEEE80211_CCK_RATE_11MB:
  221. data->bitrate.value = 11000000;
  222. break;
  223. case IEEE80211_OFDM_RATE_6MB:
  224. data->bitrate.value = 6000000;
  225. break;
  226. case IEEE80211_OFDM_RATE_9MB:
  227. data->bitrate.value = 9000000;
  228. break;
  229. case IEEE80211_OFDM_RATE_12MB:
  230. data->bitrate.value = 12000000;
  231. break;
  232. case IEEE80211_OFDM_RATE_18MB:
  233. data->bitrate.value = 18000000;
  234. break;
  235. case IEEE80211_OFDM_RATE_24MB:
  236. data->bitrate.value = 24000000;
  237. break;
  238. case IEEE80211_OFDM_RATE_36MB:
  239. data->bitrate.value = 36000000;
  240. break;
  241. case IEEE80211_OFDM_RATE_48MB:
  242. data->bitrate.value = 48000000;
  243. break;
  244. case IEEE80211_OFDM_RATE_54MB:
  245. data->bitrate.value = 54000000;
  246. break;
  247. default:
  248. assert(0);
  249. goto out_unlock;
  250. }
  251. err = 0;
  252. out_unlock:
  253. spin_unlock_irqrestore(&mac->lock, flags);
  254. return err;
  255. }
  256. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_rate);
  257. int
  258. ieee80211softmac_wx_get_wap(struct net_device *net_dev,
  259. struct iw_request_info *info,
  260. union iwreq_data *data,
  261. char *extra)
  262. {
  263. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  264. int err = 0;
  265. unsigned long flags;
  266. spin_lock_irqsave(&mac->lock, flags);
  267. if (mac->associnfo.bssvalid)
  268. memcpy(data->ap_addr.sa_data, mac->associnfo.bssid, ETH_ALEN);
  269. else
  270. memset(data->ap_addr.sa_data, 0xff, ETH_ALEN);
  271. data->ap_addr.sa_family = ARPHRD_ETHER;
  272. spin_unlock_irqrestore(&mac->lock, flags);
  273. return err;
  274. }
  275. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_wap);
  276. int
  277. ieee80211softmac_wx_set_wap(struct net_device *net_dev,
  278. struct iw_request_info *info,
  279. union iwreq_data *data,
  280. char *extra)
  281. {
  282. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  283. unsigned long flags;
  284. /* sanity check */
  285. if (data->ap_addr.sa_family != ARPHRD_ETHER) {
  286. return -EINVAL;
  287. }
  288. spin_lock_irqsave(&mac->lock, flags);
  289. if (is_broadcast_ether_addr(data->ap_addr.sa_data)) {
  290. /* the bssid we have is not to be fixed any longer,
  291. * and we should reassociate to the best AP. */
  292. mac->associnfo.bssfixed = 0;
  293. /* force reassociation */
  294. mac->associnfo.bssvalid = 0;
  295. if (mac->associated)
  296. schedule_work(&mac->associnfo.work);
  297. } else if (is_zero_ether_addr(data->ap_addr.sa_data)) {
  298. /* the bssid we have is no longer fixed */
  299. mac->associnfo.bssfixed = 0;
  300. } else {
  301. if (!memcmp(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN)) {
  302. if (mac->associnfo.associating || mac->associated) {
  303. /* bssid unchanged and associated or associating - just return */
  304. goto out;
  305. }
  306. } else {
  307. /* copy new value in data->ap_addr.sa_data to bssid */
  308. memcpy(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN);
  309. }
  310. /* tell the other code that this bssid should be used no matter what */
  311. mac->associnfo.bssfixed = 1;
  312. /* queue associate if new bssid or (old one again and not associated) */
  313. schedule_work(&mac->associnfo.work);
  314. }
  315. out:
  316. spin_unlock_irqrestore(&mac->lock, flags);
  317. return 0;
  318. }
  319. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_wap);
  320. int
  321. ieee80211softmac_wx_set_genie(struct net_device *dev,
  322. struct iw_request_info *info,
  323. union iwreq_data *wrqu,
  324. char *extra)
  325. {
  326. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  327. unsigned long flags;
  328. int err = 0;
  329. char *buf;
  330. int i;
  331. spin_lock_irqsave(&mac->lock, flags);
  332. /* bleh. shouldn't be locked for that kmalloc... */
  333. if (wrqu->data.length) {
  334. if ((wrqu->data.length < 2) || (extra[1]+2 != wrqu->data.length)) {
  335. /* this is an IE, so the length must be
  336. * correct. Is it possible though that
  337. * more than one IE is passed in?
  338. */
  339. err = -EINVAL;
  340. goto out;
  341. }
  342. if (mac->wpa.IEbuflen <= wrqu->data.length) {
  343. buf = kmalloc(wrqu->data.length, GFP_ATOMIC);
  344. if (!buf) {
  345. err = -ENOMEM;
  346. goto out;
  347. }
  348. kfree(mac->wpa.IE);
  349. mac->wpa.IE = buf;
  350. mac->wpa.IEbuflen = wrqu->data.length;
  351. }
  352. memcpy(mac->wpa.IE, extra, wrqu->data.length);
  353. dprintk(KERN_INFO PFX "generic IE set to ");
  354. for (i=0;i<wrqu->data.length;i++)
  355. dprintk("%.2x", mac->wpa.IE[i]);
  356. dprintk("\n");
  357. mac->wpa.IElen = wrqu->data.length;
  358. } else {
  359. kfree(mac->wpa.IE);
  360. mac->wpa.IE = NULL;
  361. mac->wpa.IElen = 0;
  362. mac->wpa.IEbuflen = 0;
  363. }
  364. out:
  365. spin_unlock_irqrestore(&mac->lock, flags);
  366. return err;
  367. }
  368. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_genie);
  369. int
  370. ieee80211softmac_wx_get_genie(struct net_device *dev,
  371. struct iw_request_info *info,
  372. union iwreq_data *wrqu,
  373. char *extra)
  374. {
  375. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  376. unsigned long flags;
  377. int err = 0;
  378. int space = wrqu->data.length;
  379. spin_lock_irqsave(&mac->lock, flags);
  380. wrqu->data.length = 0;
  381. if (mac->wpa.IE && mac->wpa.IElen) {
  382. wrqu->data.length = mac->wpa.IElen;
  383. if (mac->wpa.IElen <= space)
  384. memcpy(extra, mac->wpa.IE, mac->wpa.IElen);
  385. else
  386. err = -E2BIG;
  387. }
  388. spin_unlock_irqrestore(&mac->lock, flags);
  389. return err;
  390. }
  391. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_genie);