ieee80211softmac_wx.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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. if (ieee->modulation & IEEE80211_OFDM_MODULATION)
  159. in_rate = 24000000;
  160. else
  161. in_rate = 11000000;
  162. }
  163. switch (in_rate) {
  164. case 1000000:
  165. rate = IEEE80211_CCK_RATE_1MB;
  166. break;
  167. case 2000000:
  168. rate = IEEE80211_CCK_RATE_2MB;
  169. break;
  170. case 5500000:
  171. rate = IEEE80211_CCK_RATE_5MB;
  172. break;
  173. case 11000000:
  174. rate = IEEE80211_CCK_RATE_11MB;
  175. break;
  176. case 6000000:
  177. rate = IEEE80211_OFDM_RATE_6MB;
  178. is_ofdm = 1;
  179. break;
  180. case 9000000:
  181. rate = IEEE80211_OFDM_RATE_9MB;
  182. is_ofdm = 1;
  183. break;
  184. case 12000000:
  185. rate = IEEE80211_OFDM_RATE_12MB;
  186. is_ofdm = 1;
  187. break;
  188. case 18000000:
  189. rate = IEEE80211_OFDM_RATE_18MB;
  190. is_ofdm = 1;
  191. break;
  192. case 24000000:
  193. rate = IEEE80211_OFDM_RATE_24MB;
  194. is_ofdm = 1;
  195. break;
  196. case 36000000:
  197. rate = IEEE80211_OFDM_RATE_36MB;
  198. is_ofdm = 1;
  199. break;
  200. case 48000000:
  201. rate = IEEE80211_OFDM_RATE_48MB;
  202. is_ofdm = 1;
  203. break;
  204. case 54000000:
  205. rate = IEEE80211_OFDM_RATE_54MB;
  206. is_ofdm = 1;
  207. break;
  208. default:
  209. goto out;
  210. }
  211. spin_lock_irqsave(&mac->lock, flags);
  212. /* Check if correct modulation for this PHY. */
  213. if (is_ofdm && !(ieee->modulation & IEEE80211_OFDM_MODULATION))
  214. goto out_unlock;
  215. mac->txrates.user_rate = rate;
  216. ieee80211softmac_recalc_txrates(mac);
  217. err = 0;
  218. out_unlock:
  219. spin_unlock_irqrestore(&mac->lock, flags);
  220. out:
  221. return err;
  222. }
  223. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_rate);
  224. int
  225. ieee80211softmac_wx_get_rate(struct net_device *net_dev,
  226. struct iw_request_info *info,
  227. union iwreq_data *data,
  228. char *extra)
  229. {
  230. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  231. unsigned long flags;
  232. int err = -EINVAL;
  233. spin_lock_irqsave(&mac->lock, flags);
  234. if (unlikely(!mac->running)) {
  235. err = -ENODEV;
  236. goto out_unlock;
  237. }
  238. switch (mac->txrates.default_rate) {
  239. case IEEE80211_CCK_RATE_1MB:
  240. data->bitrate.value = 1000000;
  241. break;
  242. case IEEE80211_CCK_RATE_2MB:
  243. data->bitrate.value = 2000000;
  244. break;
  245. case IEEE80211_CCK_RATE_5MB:
  246. data->bitrate.value = 5500000;
  247. break;
  248. case IEEE80211_CCK_RATE_11MB:
  249. data->bitrate.value = 11000000;
  250. break;
  251. case IEEE80211_OFDM_RATE_6MB:
  252. data->bitrate.value = 6000000;
  253. break;
  254. case IEEE80211_OFDM_RATE_9MB:
  255. data->bitrate.value = 9000000;
  256. break;
  257. case IEEE80211_OFDM_RATE_12MB:
  258. data->bitrate.value = 12000000;
  259. break;
  260. case IEEE80211_OFDM_RATE_18MB:
  261. data->bitrate.value = 18000000;
  262. break;
  263. case IEEE80211_OFDM_RATE_24MB:
  264. data->bitrate.value = 24000000;
  265. break;
  266. case IEEE80211_OFDM_RATE_36MB:
  267. data->bitrate.value = 36000000;
  268. break;
  269. case IEEE80211_OFDM_RATE_48MB:
  270. data->bitrate.value = 48000000;
  271. break;
  272. case IEEE80211_OFDM_RATE_54MB:
  273. data->bitrate.value = 54000000;
  274. break;
  275. default:
  276. assert(0);
  277. goto out_unlock;
  278. }
  279. err = 0;
  280. out_unlock:
  281. spin_unlock_irqrestore(&mac->lock, flags);
  282. return err;
  283. }
  284. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_rate);
  285. int
  286. ieee80211softmac_wx_get_wap(struct net_device *net_dev,
  287. struct iw_request_info *info,
  288. union iwreq_data *data,
  289. char *extra)
  290. {
  291. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  292. int err = 0;
  293. mutex_lock(&mac->associnfo.mutex);
  294. if (mac->associnfo.bssvalid)
  295. memcpy(data->ap_addr.sa_data, mac->associnfo.bssid, ETH_ALEN);
  296. else
  297. memset(data->ap_addr.sa_data, 0xff, ETH_ALEN);
  298. data->ap_addr.sa_family = ARPHRD_ETHER;
  299. mutex_unlock(&mac->associnfo.mutex);
  300. return err;
  301. }
  302. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_wap);
  303. int
  304. ieee80211softmac_wx_set_wap(struct net_device *net_dev,
  305. struct iw_request_info *info,
  306. union iwreq_data *data,
  307. char *extra)
  308. {
  309. struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
  310. /* sanity check */
  311. if (data->ap_addr.sa_family != ARPHRD_ETHER) {
  312. return -EINVAL;
  313. }
  314. mutex_lock(&mac->associnfo.mutex);
  315. if (is_broadcast_ether_addr(data->ap_addr.sa_data)) {
  316. /* the bssid we have is not to be fixed any longer,
  317. * and we should reassociate to the best AP. */
  318. mac->associnfo.bssfixed = 0;
  319. /* force reassociation */
  320. mac->associnfo.bssvalid = 0;
  321. if (mac->associnfo.associated)
  322. schedule_delayed_work(&mac->associnfo.work, 0);
  323. } else if (is_zero_ether_addr(data->ap_addr.sa_data)) {
  324. /* the bssid we have is no longer fixed */
  325. mac->associnfo.bssfixed = 0;
  326. } else {
  327. if (!memcmp(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN)) {
  328. if (mac->associnfo.associating || mac->associnfo.associated) {
  329. /* bssid unchanged and associated or associating - just return */
  330. goto out;
  331. }
  332. } else {
  333. /* copy new value in data->ap_addr.sa_data to bssid */
  334. memcpy(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN);
  335. }
  336. /* tell the other code that this bssid should be used no matter what */
  337. mac->associnfo.bssfixed = 1;
  338. /* queue associate if new bssid or (old one again and not associated) */
  339. schedule_delayed_work(&mac->associnfo.work, 0);
  340. }
  341. out:
  342. mutex_unlock(&mac->associnfo.mutex);
  343. return 0;
  344. }
  345. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_wap);
  346. int
  347. ieee80211softmac_wx_set_genie(struct net_device *dev,
  348. struct iw_request_info *info,
  349. union iwreq_data *wrqu,
  350. char *extra)
  351. {
  352. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  353. unsigned long flags;
  354. int err = 0;
  355. char *buf;
  356. int i;
  357. mutex_lock(&mac->associnfo.mutex);
  358. spin_lock_irqsave(&mac->lock, flags);
  359. /* bleh. shouldn't be locked for that kmalloc... */
  360. if (wrqu->data.length) {
  361. if ((wrqu->data.length < 2) || (extra[1]+2 != wrqu->data.length)) {
  362. /* this is an IE, so the length must be
  363. * correct. Is it possible though that
  364. * more than one IE is passed in?
  365. */
  366. err = -EINVAL;
  367. goto out;
  368. }
  369. if (mac->wpa.IEbuflen <= wrqu->data.length) {
  370. buf = kmalloc(wrqu->data.length, GFP_ATOMIC);
  371. if (!buf) {
  372. err = -ENOMEM;
  373. goto out;
  374. }
  375. kfree(mac->wpa.IE);
  376. mac->wpa.IE = buf;
  377. mac->wpa.IEbuflen = wrqu->data.length;
  378. }
  379. memcpy(mac->wpa.IE, extra, wrqu->data.length);
  380. dprintk(KERN_INFO PFX "generic IE set to ");
  381. for (i=0;i<wrqu->data.length;i++)
  382. dprintk("%.2x", (u8)mac->wpa.IE[i]);
  383. dprintk("\n");
  384. mac->wpa.IElen = wrqu->data.length;
  385. } else {
  386. kfree(mac->wpa.IE);
  387. mac->wpa.IE = NULL;
  388. mac->wpa.IElen = 0;
  389. mac->wpa.IEbuflen = 0;
  390. }
  391. out:
  392. spin_unlock_irqrestore(&mac->lock, flags);
  393. mutex_unlock(&mac->associnfo.mutex);
  394. return err;
  395. }
  396. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_genie);
  397. int
  398. ieee80211softmac_wx_get_genie(struct net_device *dev,
  399. struct iw_request_info *info,
  400. union iwreq_data *wrqu,
  401. char *extra)
  402. {
  403. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  404. unsigned long flags;
  405. int err = 0;
  406. int space = wrqu->data.length;
  407. mutex_lock(&mac->associnfo.mutex);
  408. spin_lock_irqsave(&mac->lock, flags);
  409. wrqu->data.length = 0;
  410. if (mac->wpa.IE && mac->wpa.IElen) {
  411. wrqu->data.length = mac->wpa.IElen;
  412. if (mac->wpa.IElen <= space)
  413. memcpy(extra, mac->wpa.IE, mac->wpa.IElen);
  414. else
  415. err = -E2BIG;
  416. }
  417. spin_unlock_irqrestore(&mac->lock, flags);
  418. mutex_unlock(&mac->associnfo.mutex);
  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. int err = -EINVAL;
  433. mutex_lock(&mac->associnfo.mutex);
  434. if (memcmp(mac->associnfo.bssid, mlme->addr.sa_data, ETH_ALEN)) {
  435. printk(KERN_DEBUG PFX "wx_set_mlme: requested operation on net we don't use\n");
  436. goto out;
  437. }
  438. switch (mlme->cmd) {
  439. case IW_MLME_DEAUTH:
  440. net = ieee80211softmac_get_network_by_bssid_locked(mac, mlme->addr.sa_data);
  441. if (!net) {
  442. printk(KERN_DEBUG PFX "wx_set_mlme: we should know the net here...\n");
  443. goto out;
  444. }
  445. err = ieee80211softmac_deauth_req(mac, net, reason);
  446. goto out;
  447. case IW_MLME_DISASSOC:
  448. ieee80211softmac_send_disassoc_req(mac, reason);
  449. mac->associnfo.associated = 0;
  450. mac->associnfo.associating = 0;
  451. err = 0;
  452. goto out;
  453. default:
  454. err = -EOPNOTSUPP;
  455. }
  456. out:
  457. mutex_unlock(&mac->associnfo.mutex);
  458. return err;
  459. }
  460. EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_mlme);