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