ieee80211softmac_wx.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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. struct ieee80211softmac_network *n;
  67. struct ieee80211softmac_auth_queue_item *authptr;
  68. int length = 0;
  69. unsigned long flags;
  70. /* Check if we're already associating to this or another network
  71. * If it's another network, cancel and start over with our new network
  72. * If it's our network, ignore the change, we're already doing it!
  73. */
  74. if((sm->associnfo.associating || sm->associated) &&
  75. (data->essid.flags && data->essid.length)) {
  76. /* Get the associating network */
  77. n = ieee80211softmac_get_network_by_bssid(sm, sm->associnfo.bssid);
  78. if(n && n->essid.len == data->essid.length &&
  79. !memcmp(n->essid.data, extra, n->essid.len)) {
  80. dprintk(KERN_INFO PFX "Already associating or associated to "MAC_FMT"\n",
  81. MAC_ARG(sm->associnfo.bssid));
  82. return 0;
  83. } else {
  84. dprintk(KERN_INFO PFX "Canceling existing associate request!\n");
  85. spin_lock_irqsave(&sm->lock,flags);
  86. /* Cancel assoc work */
  87. cancel_delayed_work(&sm->associnfo.work);
  88. /* We don't have to do this, but it's a little cleaner */
  89. list_for_each_entry(authptr, &sm->auth_queue, list)
  90. cancel_delayed_work(&authptr->work);
  91. sm->associnfo.bssvalid = 0;
  92. sm->associnfo.bssfixed = 0;
  93. spin_unlock_irqrestore(&sm->lock,flags);
  94. flush_scheduled_work();
  95. }
  96. }
  97. spin_lock_irqsave(&sm->lock, flags);
  98. sm->associnfo.static_essid = 0;
  99. sm->associnfo.assoc_wait = 0;
  100. if (data->essid.flags && data->essid.length) {
  101. length = min((int)data->essid.length, IW_ESSID_MAX_SIZE);
  102. if (length) {
  103. memcpy(sm->associnfo.req_essid.data, extra, length);
  104. sm->associnfo.static_essid = 1;
  105. }
  106. }
  107. /* set our requested ESSID length.
  108. * If applicable, we have already copied the data in */
  109. sm->associnfo.req_essid.len = length;
  110. /* queue lower level code to do work (if necessary) */
  111. schedule_work(&sm->associnfo.work);
  112. spin_unlock_irqrestore(&sm->lock, flags);
  113. return 0;
  114. }
  115. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_essid);
  116. int
  117. ieee80211softmac_wx_get_essid(struct net_device *net_dev,
  118. struct iw_request_info *info,
  119. union iwreq_data *data,
  120. char *extra)
  121. {
  122. struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
  123. unsigned long flags;
  124. /* avoid getting inconsistent information */
  125. spin_lock_irqsave(&sm->lock, flags);
  126. /* If all fails, return ANY (empty) */
  127. data->essid.length = 0;
  128. data->essid.flags = 0; /* active */
  129. /* If we have a statically configured ESSID then return it */
  130. if (sm->associnfo.static_essid) {
  131. data->essid.length = sm->associnfo.req_essid.len;
  132. data->essid.flags = 1; /* active */
  133. memcpy(extra, sm->associnfo.req_essid.data, sm->associnfo.req_essid.len);
  134. }
  135. /* If we're associating/associated, return that */
  136. if (sm->associated || sm->associnfo.associating) {
  137. data->essid.length = sm->associnfo.associate_essid.len;
  138. data->essid.flags = 1; /* active */
  139. memcpy(extra, sm->associnfo.associate_essid.data, sm->associnfo.associate_essid.len);
  140. }
  141. spin_unlock_irqrestore(&sm->lock, flags);
  142. return 0;
  143. }
  144. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_essid);
  145. int
  146. ieee80211softmac_wx_set_rate(struct net_device *net_dev,
  147. struct iw_request_info *info,
  148. union iwreq_data *data,
  149. char *extra)
  150. {
  151. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  152. struct ieee80211_device *ieee = mac->ieee;
  153. unsigned long flags;
  154. s32 in_rate = data->bitrate.value;
  155. u8 rate;
  156. int is_ofdm = 0;
  157. int err = -EINVAL;
  158. if (in_rate == -1) {
  159. /* FIXME: We don't correctly handle backing down to lower
  160. rates, so 801.11g devices start off at 11M for now. People
  161. can manually change it if they really need to, but 11M is
  162. more reliable. Note similar logic in
  163. ieee80211softmac_wx_set_rate() */
  164. if (ieee->modulation & IEEE80211_CCK_MODULATION)
  165. in_rate = 11000000;
  166. else
  167. in_rate = 54000000;
  168. }
  169. switch (in_rate) {
  170. case 1000000:
  171. rate = IEEE80211_CCK_RATE_1MB;
  172. break;
  173. case 2000000:
  174. rate = IEEE80211_CCK_RATE_2MB;
  175. break;
  176. case 5500000:
  177. rate = IEEE80211_CCK_RATE_5MB;
  178. break;
  179. case 11000000:
  180. rate = IEEE80211_CCK_RATE_11MB;
  181. break;
  182. case 6000000:
  183. rate = IEEE80211_OFDM_RATE_6MB;
  184. is_ofdm = 1;
  185. break;
  186. case 9000000:
  187. rate = IEEE80211_OFDM_RATE_9MB;
  188. is_ofdm = 1;
  189. break;
  190. case 12000000:
  191. rate = IEEE80211_OFDM_RATE_12MB;
  192. is_ofdm = 1;
  193. break;
  194. case 18000000:
  195. rate = IEEE80211_OFDM_RATE_18MB;
  196. is_ofdm = 1;
  197. break;
  198. case 24000000:
  199. rate = IEEE80211_OFDM_RATE_24MB;
  200. is_ofdm = 1;
  201. break;
  202. case 36000000:
  203. rate = IEEE80211_OFDM_RATE_36MB;
  204. is_ofdm = 1;
  205. break;
  206. case 48000000:
  207. rate = IEEE80211_OFDM_RATE_48MB;
  208. is_ofdm = 1;
  209. break;
  210. case 54000000:
  211. rate = IEEE80211_OFDM_RATE_54MB;
  212. is_ofdm = 1;
  213. break;
  214. default:
  215. goto out;
  216. }
  217. spin_lock_irqsave(&mac->lock, flags);
  218. /* Check if correct modulation for this PHY. */
  219. if (is_ofdm && !(ieee->modulation & IEEE80211_OFDM_MODULATION))
  220. goto out_unlock;
  221. mac->txrates.user_rate = rate;
  222. ieee80211softmac_recalc_txrates(mac);
  223. err = 0;
  224. out_unlock:
  225. spin_unlock_irqrestore(&mac->lock, flags);
  226. out:
  227. return err;
  228. }
  229. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_rate);
  230. int
  231. ieee80211softmac_wx_get_rate(struct net_device *net_dev,
  232. struct iw_request_info *info,
  233. union iwreq_data *data,
  234. char *extra)
  235. {
  236. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  237. unsigned long flags;
  238. int err = -EINVAL;
  239. spin_lock_irqsave(&mac->lock, flags);
  240. switch (mac->txrates.default_rate) {
  241. case IEEE80211_CCK_RATE_1MB:
  242. data->bitrate.value = 1000000;
  243. break;
  244. case IEEE80211_CCK_RATE_2MB:
  245. data->bitrate.value = 2000000;
  246. break;
  247. case IEEE80211_CCK_RATE_5MB:
  248. data->bitrate.value = 5500000;
  249. break;
  250. case IEEE80211_CCK_RATE_11MB:
  251. data->bitrate.value = 11000000;
  252. break;
  253. case IEEE80211_OFDM_RATE_6MB:
  254. data->bitrate.value = 6000000;
  255. break;
  256. case IEEE80211_OFDM_RATE_9MB:
  257. data->bitrate.value = 9000000;
  258. break;
  259. case IEEE80211_OFDM_RATE_12MB:
  260. data->bitrate.value = 12000000;
  261. break;
  262. case IEEE80211_OFDM_RATE_18MB:
  263. data->bitrate.value = 18000000;
  264. break;
  265. case IEEE80211_OFDM_RATE_24MB:
  266. data->bitrate.value = 24000000;
  267. break;
  268. case IEEE80211_OFDM_RATE_36MB:
  269. data->bitrate.value = 36000000;
  270. break;
  271. case IEEE80211_OFDM_RATE_48MB:
  272. data->bitrate.value = 48000000;
  273. break;
  274. case IEEE80211_OFDM_RATE_54MB:
  275. data->bitrate.value = 54000000;
  276. break;
  277. default:
  278. assert(0);
  279. goto out_unlock;
  280. }
  281. err = 0;
  282. out_unlock:
  283. spin_unlock_irqrestore(&mac->lock, flags);
  284. return err;
  285. }
  286. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_rate);
  287. int
  288. ieee80211softmac_wx_get_wap(struct net_device *net_dev,
  289. struct iw_request_info *info,
  290. union iwreq_data *data,
  291. char *extra)
  292. {
  293. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  294. int err = 0;
  295. unsigned long flags;
  296. spin_lock_irqsave(&mac->lock, flags);
  297. if (mac->associnfo.bssvalid)
  298. memcpy(data->ap_addr.sa_data, mac->associnfo.bssid, ETH_ALEN);
  299. else
  300. memset(data->ap_addr.sa_data, 0xff, ETH_ALEN);
  301. data->ap_addr.sa_family = ARPHRD_ETHER;
  302. spin_unlock_irqrestore(&mac->lock, flags);
  303. return err;
  304. }
  305. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_wap);
  306. int
  307. ieee80211softmac_wx_set_wap(struct net_device *net_dev,
  308. struct iw_request_info *info,
  309. union iwreq_data *data,
  310. char *extra)
  311. {
  312. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  313. unsigned long flags;
  314. /* sanity check */
  315. if (data->ap_addr.sa_family != ARPHRD_ETHER) {
  316. return -EINVAL;
  317. }
  318. spin_lock_irqsave(&mac->lock, flags);
  319. if (is_broadcast_ether_addr(data->ap_addr.sa_data)) {
  320. /* the bssid we have is not to be fixed any longer,
  321. * and we should reassociate to the best AP. */
  322. mac->associnfo.bssfixed = 0;
  323. /* force reassociation */
  324. mac->associnfo.bssvalid = 0;
  325. if (mac->associated)
  326. schedule_work(&mac->associnfo.work);
  327. } else if (is_zero_ether_addr(data->ap_addr.sa_data)) {
  328. /* the bssid we have is no longer fixed */
  329. mac->associnfo.bssfixed = 0;
  330. } else {
  331. if (!memcmp(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN)) {
  332. if (mac->associnfo.associating || mac->associated) {
  333. /* bssid unchanged and associated or associating - just return */
  334. goto out;
  335. }
  336. } else {
  337. /* copy new value in data->ap_addr.sa_data to bssid */
  338. memcpy(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN);
  339. }
  340. /* tell the other code that this bssid should be used no matter what */
  341. mac->associnfo.bssfixed = 1;
  342. /* queue associate if new bssid or (old one again and not associated) */
  343. schedule_work(&mac->associnfo.work);
  344. }
  345. out:
  346. spin_unlock_irqrestore(&mac->lock, flags);
  347. return 0;
  348. }
  349. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_wap);
  350. int
  351. ieee80211softmac_wx_set_genie(struct net_device *dev,
  352. struct iw_request_info *info,
  353. union iwreq_data *wrqu,
  354. char *extra)
  355. {
  356. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  357. unsigned long flags;
  358. int err = 0;
  359. char *buf;
  360. int i;
  361. spin_lock_irqsave(&mac->lock, flags);
  362. /* bleh. shouldn't be locked for that kmalloc... */
  363. if (wrqu->data.length) {
  364. if ((wrqu->data.length < 2) || (extra[1]+2 != wrqu->data.length)) {
  365. /* this is an IE, so the length must be
  366. * correct. Is it possible though that
  367. * more than one IE is passed in?
  368. */
  369. err = -EINVAL;
  370. goto out;
  371. }
  372. if (mac->wpa.IEbuflen <= wrqu->data.length) {
  373. buf = kmalloc(wrqu->data.length, GFP_ATOMIC);
  374. if (!buf) {
  375. err = -ENOMEM;
  376. goto out;
  377. }
  378. kfree(mac->wpa.IE);
  379. mac->wpa.IE = buf;
  380. mac->wpa.IEbuflen = wrqu->data.length;
  381. }
  382. memcpy(mac->wpa.IE, extra, wrqu->data.length);
  383. dprintk(KERN_INFO PFX "generic IE set to ");
  384. for (i=0;i<wrqu->data.length;i++)
  385. dprintk("%.2x", (u8)mac->wpa.IE[i]);
  386. dprintk("\n");
  387. mac->wpa.IElen = wrqu->data.length;
  388. } else {
  389. kfree(mac->wpa.IE);
  390. mac->wpa.IE = NULL;
  391. mac->wpa.IElen = 0;
  392. mac->wpa.IEbuflen = 0;
  393. }
  394. out:
  395. spin_unlock_irqrestore(&mac->lock, flags);
  396. return err;
  397. }
  398. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_genie);
  399. int
  400. ieee80211softmac_wx_get_genie(struct net_device *dev,
  401. struct iw_request_info *info,
  402. union iwreq_data *wrqu,
  403. char *extra)
  404. {
  405. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  406. unsigned long flags;
  407. int err = 0;
  408. int space = wrqu->data.length;
  409. spin_lock_irqsave(&mac->lock, flags);
  410. wrqu->data.length = 0;
  411. if (mac->wpa.IE && mac->wpa.IElen) {
  412. wrqu->data.length = mac->wpa.IElen;
  413. if (mac->wpa.IElen <= space)
  414. memcpy(extra, mac->wpa.IE, mac->wpa.IElen);
  415. else
  416. err = -E2BIG;
  417. }
  418. spin_unlock_irqrestore(&mac->lock, flags);
  419. return err;
  420. }
  421. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_genie);
  422. int
  423. ieee80211softmac_wx_set_mlme(struct net_device *dev,
  424. struct iw_request_info *info,
  425. union iwreq_data *wrqu,
  426. char *extra)
  427. {
  428. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  429. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  430. u16 reason = cpu_to_le16(mlme->reason_code);
  431. struct ieee80211softmac_network *net;
  432. if (memcmp(mac->associnfo.bssid, mlme->addr.sa_data, ETH_ALEN)) {
  433. printk(KERN_DEBUG PFX "wx_set_mlme: requested operation on net we don't use\n");
  434. return -EINVAL;
  435. }
  436. switch (mlme->cmd) {
  437. case IW_MLME_DEAUTH:
  438. net = ieee80211softmac_get_network_by_bssid_locked(mac, mlme->addr.sa_data);
  439. if (!net) {
  440. printk(KERN_DEBUG PFX "wx_set_mlme: we should know the net here...\n");
  441. return -EINVAL;
  442. }
  443. return ieee80211softmac_deauth_req(mac, net, reason);
  444. case IW_MLME_DISASSOC:
  445. ieee80211softmac_send_disassoc_req(mac, reason);
  446. return 0;
  447. default:
  448. return -EOPNOTSUPP;
  449. }
  450. }
  451. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_mlme);