ieee80211softmac_wx.c 14 KB

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