/drivers/net/wireless/prism54/isl_ioctl.c

http://github.com/mirrors/linux · C · 2910 lines · 2193 code · 444 blank · 273 comment · 323 complexity · 5bf01e167f7eddfe96d97b272a402a9b MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * Copyright (C) 2002 Intersil Americas Inc.
  3. * (C) 2003,2004 Aurelien Alleaume <slts@free.fr>
  4. * (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
  5. * (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/capability.h>
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/if_arp.h>
  25. #include <linux/slab.h>
  26. #include <linux/pci.h>
  27. #include <asm/uaccess.h>
  28. #include "prismcompat.h"
  29. #include "isl_ioctl.h"
  30. #include "islpci_mgt.h"
  31. #include "isl_oid.h" /* additional types and defs for isl38xx fw */
  32. #include "oid_mgt.h"
  33. #include <net/iw_handler.h> /* New driver API */
  34. #define KEY_SIZE_WEP104 13 /* 104/128-bit WEP keys */
  35. #define KEY_SIZE_WEP40 5 /* 40/64-bit WEP keys */
  36. /* KEY_SIZE_TKIP should match isl_oid.h, struct obj_key.key[] size */
  37. #define KEY_SIZE_TKIP 32 /* TKIP keys */
  38. static void prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid,
  39. u8 *wpa_ie, size_t wpa_ie_len);
  40. static size_t prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie);
  41. static int prism54_set_wpa(struct net_device *, struct iw_request_info *,
  42. __u32 *, char *);
  43. /* In 500 kbps */
  44. static const unsigned char scan_rate_list[] = { 2, 4, 11, 22,
  45. 12, 18, 24, 36,
  46. 48, 72, 96, 108 };
  47. /**
  48. * prism54_mib_mode_helper - MIB change mode helper function
  49. * @mib: the &struct islpci_mib object to modify
  50. * @iw_mode: new mode (%IW_MODE_*)
  51. *
  52. * This is a helper function, hence it does not lock. Make sure
  53. * caller deals with locking *if* necessary. This function sets the
  54. * mode-dependent mib values and does the mapping of the Linux
  55. * Wireless API modes to Device firmware modes. It also checks for
  56. * correct valid Linux wireless modes.
  57. */
  58. static int
  59. prism54_mib_mode_helper(islpci_private *priv, u32 iw_mode)
  60. {
  61. u32 config = INL_CONFIG_MANUALRUN;
  62. u32 mode, bsstype;
  63. /* For now, just catch early the Repeater and Secondary modes here */
  64. if (iw_mode == IW_MODE_REPEAT || iw_mode == IW_MODE_SECOND) {
  65. printk(KERN_DEBUG
  66. "%s(): Sorry, Repeater mode and Secondary mode "
  67. "are not yet supported by this driver.\n", __func__);
  68. return -EINVAL;
  69. }
  70. priv->iw_mode = iw_mode;
  71. switch (iw_mode) {
  72. case IW_MODE_AUTO:
  73. mode = INL_MODE_CLIENT;
  74. bsstype = DOT11_BSSTYPE_ANY;
  75. break;
  76. case IW_MODE_ADHOC:
  77. mode = INL_MODE_CLIENT;
  78. bsstype = DOT11_BSSTYPE_IBSS;
  79. break;
  80. case IW_MODE_INFRA:
  81. mode = INL_MODE_CLIENT;
  82. bsstype = DOT11_BSSTYPE_INFRA;
  83. break;
  84. case IW_MODE_MASTER:
  85. mode = INL_MODE_AP;
  86. bsstype = DOT11_BSSTYPE_INFRA;
  87. break;
  88. case IW_MODE_MONITOR:
  89. mode = INL_MODE_PROMISCUOUS;
  90. bsstype = DOT11_BSSTYPE_ANY;
  91. config |= INL_CONFIG_RXANNEX;
  92. break;
  93. default:
  94. return -EINVAL;
  95. }
  96. if (init_wds)
  97. config |= INL_CONFIG_WDS;
  98. mgt_set(priv, DOT11_OID_BSSTYPE, &bsstype);
  99. mgt_set(priv, OID_INL_CONFIG, &config);
  100. mgt_set(priv, OID_INL_MODE, &mode);
  101. return 0;
  102. }
  103. /**
  104. * prism54_mib_init - fill MIB cache with defaults
  105. *
  106. * this function initializes the struct given as @mib with defaults,
  107. * of which many are retrieved from the global module parameter
  108. * variables.
  109. */
  110. void
  111. prism54_mib_init(islpci_private *priv)
  112. {
  113. u32 channel, authen, wep, filter, dot1x, mlme, conformance, power, mode;
  114. struct obj_buffer psm_buffer = {
  115. .size = PSM_BUFFER_SIZE,
  116. .addr = priv->device_psm_buffer
  117. };
  118. channel = CARD_DEFAULT_CHANNEL;
  119. authen = CARD_DEFAULT_AUTHEN;
  120. wep = CARD_DEFAULT_WEP;
  121. filter = CARD_DEFAULT_FILTER; /* (0) Do not filter un-encrypted data */
  122. dot1x = CARD_DEFAULT_DOT1X;
  123. mlme = CARD_DEFAULT_MLME_MODE;
  124. conformance = CARD_DEFAULT_CONFORMANCE;
  125. power = 127;
  126. mode = CARD_DEFAULT_IW_MODE;
  127. mgt_set(priv, DOT11_OID_CHANNEL, &channel);
  128. mgt_set(priv, DOT11_OID_AUTHENABLE, &authen);
  129. mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &wep);
  130. mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer);
  131. mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &filter);
  132. mgt_set(priv, DOT11_OID_DOT1XENABLE, &dot1x);
  133. mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlme);
  134. mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &conformance);
  135. mgt_set(priv, OID_INL_OUTPUTPOWER, &power);
  136. /* This sets all of the mode-dependent values */
  137. prism54_mib_mode_helper(priv, mode);
  138. }
  139. /* this will be executed outside of atomic context thanks to
  140. * schedule_work(), thus we can as well use sleeping semaphore
  141. * locking */
  142. void
  143. prism54_update_stats(struct work_struct *work)
  144. {
  145. islpci_private *priv = container_of(work, islpci_private, stats_work);
  146. char *data;
  147. int j;
  148. struct obj_bss bss, *bss2;
  149. union oid_res_t r;
  150. mutex_lock(&priv->stats_lock);
  151. /* Noise floor.
  152. * I'm not sure if the unit is dBm.
  153. * Note : If we are not connected, this value seems to be irrelevant. */
  154. mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
  155. priv->local_iwstatistics.qual.noise = r.u;
  156. /* Get the rssi of the link. To do this we need to retrieve a bss. */
  157. /* First get the MAC address of the AP we are associated with. */
  158. mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
  159. data = r.ptr;
  160. /* copy this MAC to the bss */
  161. memcpy(bss.address, data, 6);
  162. kfree(data);
  163. /* now ask for the corresponding bss */
  164. j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r);
  165. bss2 = r.ptr;
  166. /* report the rssi and use it to calculate
  167. * link quality through a signal-noise
  168. * ratio */
  169. priv->local_iwstatistics.qual.level = bss2->rssi;
  170. priv->local_iwstatistics.qual.qual =
  171. bss2->rssi - priv->iwstatistics.qual.noise;
  172. kfree(bss2);
  173. /* report that the stats are new */
  174. priv->local_iwstatistics.qual.updated = 0x7;
  175. /* Rx : unable to decrypt the MPDU */
  176. mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r);
  177. priv->local_iwstatistics.discard.code = r.u;
  178. /* Tx : Max MAC retries num reached */
  179. mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r);
  180. priv->local_iwstatistics.discard.retries = r.u;
  181. mutex_unlock(&priv->stats_lock);
  182. }
  183. struct iw_statistics *
  184. prism54_get_wireless_stats(struct net_device *ndev)
  185. {
  186. islpci_private *priv = netdev_priv(ndev);
  187. /* If the stats are being updated return old data */
  188. if (mutex_trylock(&priv->stats_lock)) {
  189. memcpy(&priv->iwstatistics, &priv->local_iwstatistics,
  190. sizeof (struct iw_statistics));
  191. /* They won't be marked updated for the next time */
  192. priv->local_iwstatistics.qual.updated = 0;
  193. mutex_unlock(&priv->stats_lock);
  194. } else
  195. priv->iwstatistics.qual.updated = 0;
  196. /* Update our wireless stats, but do not schedule to often
  197. * (max 1 HZ) */
  198. if ((priv->stats_timestamp == 0) ||
  199. time_after(jiffies, priv->stats_timestamp + 1 * HZ)) {
  200. schedule_work(&priv->stats_work);
  201. priv->stats_timestamp = jiffies;
  202. }
  203. return &priv->iwstatistics;
  204. }
  205. static int
  206. prism54_commit(struct net_device *ndev, struct iw_request_info *info,
  207. char *cwrq, char *extra)
  208. {
  209. islpci_private *priv = netdev_priv(ndev);
  210. /* simply re-set the last set SSID, this should commit most stuff */
  211. /* Commit in Monitor mode is not necessary, also setting essid
  212. * in Monitor mode does not make sense and isn't allowed for this
  213. * device's firmware */
  214. if (priv->iw_mode != IW_MODE_MONITOR)
  215. return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL);
  216. return 0;
  217. }
  218. static int
  219. prism54_get_name(struct net_device *ndev, struct iw_request_info *info,
  220. char *cwrq, char *extra)
  221. {
  222. islpci_private *priv = netdev_priv(ndev);
  223. char *capabilities;
  224. union oid_res_t r;
  225. int rvalue;
  226. if (islpci_get_state(priv) < PRV_STATE_INIT) {
  227. strncpy(cwrq, "NOT READY!", IFNAMSIZ);
  228. return 0;
  229. }
  230. rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r);
  231. switch (r.u) {
  232. case INL_PHYCAP_5000MHZ:
  233. capabilities = "IEEE 802.11a/b/g";
  234. break;
  235. case INL_PHYCAP_FAA:
  236. capabilities = "IEEE 802.11b/g - FAA Support";
  237. break;
  238. case INL_PHYCAP_2400MHZ:
  239. default:
  240. capabilities = "IEEE 802.11b/g"; /* Default */
  241. break;
  242. }
  243. strncpy(cwrq, capabilities, IFNAMSIZ);
  244. return rvalue;
  245. }
  246. static int
  247. prism54_set_freq(struct net_device *ndev, struct iw_request_info *info,
  248. struct iw_freq *fwrq, char *extra)
  249. {
  250. islpci_private *priv = netdev_priv(ndev);
  251. int rvalue;
  252. u32 c;
  253. if (fwrq->m < 1000)
  254. /* we have a channel number */
  255. c = fwrq->m;
  256. else
  257. c = (fwrq->e == 1) ? channel_of_freq(fwrq->m / 100000) : 0;
  258. rvalue = c ? mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c) : -EINVAL;
  259. /* Call commit handler */
  260. return (rvalue ? rvalue : -EINPROGRESS);
  261. }
  262. static int
  263. prism54_get_freq(struct net_device *ndev, struct iw_request_info *info,
  264. struct iw_freq *fwrq, char *extra)
  265. {
  266. islpci_private *priv = netdev_priv(ndev);
  267. union oid_res_t r;
  268. int rvalue;
  269. rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r);
  270. fwrq->i = r.u;
  271. rvalue |= mgt_get_request(priv, DOT11_OID_FREQUENCY, 0, NULL, &r);
  272. fwrq->m = r.u;
  273. fwrq->e = 3;
  274. return rvalue;
  275. }
  276. static int
  277. prism54_set_mode(struct net_device *ndev, struct iw_request_info *info,
  278. __u32 * uwrq, char *extra)
  279. {
  280. islpci_private *priv = netdev_priv(ndev);
  281. u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
  282. /* Let's see if the user passed a valid Linux Wireless mode */
  283. if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) {
  284. printk(KERN_DEBUG
  285. "%s: %s() You passed a non-valid init_mode.\n",
  286. priv->ndev->name, __func__);
  287. return -EINVAL;
  288. }
  289. down_write(&priv->mib_sem);
  290. if (prism54_mib_mode_helper(priv, *uwrq)) {
  291. up_write(&priv->mib_sem);
  292. return -EOPNOTSUPP;
  293. }
  294. /* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an
  295. * extended one.
  296. */
  297. if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN))
  298. mlmeautolevel = DOT11_MLME_INTERMEDIATE;
  299. if (priv->wpa)
  300. mlmeautolevel = DOT11_MLME_EXTENDED;
  301. mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
  302. if (mgt_commit(priv)) {
  303. up_write(&priv->mib_sem);
  304. return -EIO;
  305. }
  306. priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR)
  307. ? priv->monitor_type : ARPHRD_ETHER;
  308. up_write(&priv->mib_sem);
  309. return 0;
  310. }
  311. /* Use mib cache */
  312. static int
  313. prism54_get_mode(struct net_device *ndev, struct iw_request_info *info,
  314. __u32 * uwrq, char *extra)
  315. {
  316. islpci_private *priv = netdev_priv(ndev);
  317. BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode >
  318. IW_MODE_MONITOR));
  319. *uwrq = priv->iw_mode;
  320. return 0;
  321. }
  322. /* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to
  323. * emit data if (sensitivity > rssi - noise) (in dBm).
  324. * prism54_set_sens does not seem to work.
  325. */
  326. static int
  327. prism54_set_sens(struct net_device *ndev, struct iw_request_info *info,
  328. struct iw_param *vwrq, char *extra)
  329. {
  330. islpci_private *priv = netdev_priv(ndev);
  331. u32 sens;
  332. /* by default the card sets this to 20. */
  333. sens = vwrq->disabled ? 20 : vwrq->value;
  334. return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens);
  335. }
  336. static int
  337. prism54_get_sens(struct net_device *ndev, struct iw_request_info *info,
  338. struct iw_param *vwrq, char *extra)
  339. {
  340. islpci_private *priv = netdev_priv(ndev);
  341. union oid_res_t r;
  342. int rvalue;
  343. rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r);
  344. vwrq->value = r.u;
  345. vwrq->disabled = (vwrq->value == 0);
  346. vwrq->fixed = 1;
  347. return rvalue;
  348. }
  349. static int
  350. prism54_get_range(struct net_device *ndev, struct iw_request_info *info,
  351. struct iw_point *dwrq, char *extra)
  352. {
  353. struct iw_range *range = (struct iw_range *) extra;
  354. islpci_private *priv = netdev_priv(ndev);
  355. u8 *data;
  356. int i, m, rvalue;
  357. struct obj_frequencies *freq;
  358. union oid_res_t r;
  359. memset(range, 0, sizeof (struct iw_range));
  360. dwrq->length = sizeof (struct iw_range);
  361. /* set the wireless extension version number */
  362. range->we_version_source = SUPPORTED_WIRELESS_EXT;
  363. range->we_version_compiled = WIRELESS_EXT;
  364. /* Now the encoding capabilities */
  365. range->num_encoding_sizes = 3;
  366. /* 64(40) bits WEP */
  367. range->encoding_size[0] = 5;
  368. /* 128(104) bits WEP */
  369. range->encoding_size[1] = 13;
  370. /* 256 bits for WPA-PSK */
  371. range->encoding_size[2] = 32;
  372. /* 4 keys are allowed */
  373. range->max_encoding_tokens = 4;
  374. /* we don't know the quality range... */
  375. range->max_qual.level = 0;
  376. range->max_qual.noise = 0;
  377. range->max_qual.qual = 0;
  378. /* these value describe an average quality. Needs more tweaking... */
  379. range->avg_qual.level = -80; /* -80 dBm */
  380. range->avg_qual.noise = 0; /* don't know what to put here */
  381. range->avg_qual.qual = 0;
  382. range->sensitivity = 200;
  383. /* retry limit capabilities */
  384. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  385. range->retry_flags = IW_RETRY_LIMIT;
  386. range->r_time_flags = IW_RETRY_LIFETIME;
  387. /* I don't know the range. Put stupid things here */
  388. range->min_retry = 1;
  389. range->max_retry = 65535;
  390. range->min_r_time = 1024;
  391. range->max_r_time = 65535 * 1024;
  392. /* txpower is supported in dBm's */
  393. range->txpower_capa = IW_TXPOW_DBM;
  394. /* Event capability (kernel + driver) */
  395. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  396. IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
  397. IW_EVENT_CAPA_MASK(SIOCGIWAP));
  398. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  399. range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM);
  400. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
  401. IW_ENC_CAPA_CIPHER_TKIP;
  402. if (islpci_get_state(priv) < PRV_STATE_INIT)
  403. return 0;
  404. /* Request the device for the supported frequencies
  405. * not really relevant since some devices will report the 5 GHz band
  406. * frequencies even if they don't support them.
  407. */
  408. rvalue =
  409. mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r);
  410. freq = r.ptr;
  411. range->num_channels = freq->nr;
  412. range->num_frequency = freq->nr;
  413. m = min(IW_MAX_FREQUENCIES, (int) freq->nr);
  414. for (i = 0; i < m; i++) {
  415. range->freq[i].m = freq->mhz[i];
  416. range->freq[i].e = 6;
  417. range->freq[i].i = channel_of_freq(freq->mhz[i]);
  418. }
  419. kfree(freq);
  420. rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
  421. data = r.ptr;
  422. /* We got an array of char. It is NULL terminated. */
  423. i = 0;
  424. while ((i < IW_MAX_BITRATES) && (*data != 0)) {
  425. /* the result must be in bps. The card gives us 500Kbps */
  426. range->bitrate[i] = *data * 500000;
  427. i++;
  428. data++;
  429. }
  430. range->num_bitrates = i;
  431. kfree(r.ptr);
  432. return rvalue;
  433. }
  434. /* Set AP address*/
  435. static int
  436. prism54_set_wap(struct net_device *ndev, struct iw_request_info *info,
  437. struct sockaddr *awrq, char *extra)
  438. {
  439. islpci_private *priv = netdev_priv(ndev);
  440. char bssid[6];
  441. int rvalue;
  442. if (awrq->sa_family != ARPHRD_ETHER)
  443. return -EINVAL;
  444. /* prepare the structure for the set object */
  445. memcpy(&bssid[0], awrq->sa_data, 6);
  446. /* set the bssid -- does this make sense when in AP mode? */
  447. rvalue = mgt_set_request(priv, DOT11_OID_BSSID, 0, &bssid);
  448. return (rvalue ? rvalue : -EINPROGRESS); /* Call commit handler */
  449. }
  450. /* get AP address*/
  451. static int
  452. prism54_get_wap(struct net_device *ndev, struct iw_request_info *info,
  453. struct sockaddr *awrq, char *extra)
  454. {
  455. islpci_private *priv = netdev_priv(ndev);
  456. union oid_res_t r;
  457. int rvalue;
  458. rvalue = mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
  459. memcpy(awrq->sa_data, r.ptr, 6);
  460. awrq->sa_family = ARPHRD_ETHER;
  461. kfree(r.ptr);
  462. return rvalue;
  463. }
  464. static int
  465. prism54_set_scan(struct net_device *dev, struct iw_request_info *info,
  466. struct iw_param *vwrq, char *extra)
  467. {
  468. /* hehe the device does this automagicaly */
  469. return 0;
  470. }
  471. /* a little helper that will translate our data into a card independent
  472. * format that the Wireless Tools will understand. This was inspired by
  473. * the "Aironet driver for 4500 and 4800 series cards" (GPL)
  474. */
  475. static char *
  476. prism54_translate_bss(struct net_device *ndev, struct iw_request_info *info,
  477. char *current_ev, char *end_buf, struct obj_bss *bss,
  478. char noise)
  479. {
  480. struct iw_event iwe; /* Temporary buffer */
  481. short cap;
  482. islpci_private *priv = netdev_priv(ndev);
  483. u8 wpa_ie[MAX_WPA_IE_LEN];
  484. size_t wpa_ie_len;
  485. /* The first entry must be the MAC address */
  486. memcpy(iwe.u.ap_addr.sa_data, bss->address, 6);
  487. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  488. iwe.cmd = SIOCGIWAP;
  489. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  490. &iwe, IW_EV_ADDR_LEN);
  491. /* The following entries will be displayed in the same order we give them */
  492. /* The ESSID. */
  493. iwe.u.data.length = bss->ssid.length;
  494. iwe.u.data.flags = 1;
  495. iwe.cmd = SIOCGIWESSID;
  496. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  497. &iwe, bss->ssid.octets);
  498. /* Capabilities */
  499. #define CAP_ESS 0x01
  500. #define CAP_IBSS 0x02
  501. #define CAP_CRYPT 0x10
  502. /* Mode */
  503. cap = bss->capinfo;
  504. iwe.u.mode = 0;
  505. if (cap & CAP_ESS)
  506. iwe.u.mode = IW_MODE_MASTER;
  507. else if (cap & CAP_IBSS)
  508. iwe.u.mode = IW_MODE_ADHOC;
  509. iwe.cmd = SIOCGIWMODE;
  510. if (iwe.u.mode)
  511. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  512. &iwe, IW_EV_UINT_LEN);
  513. /* Encryption capability */
  514. if (cap & CAP_CRYPT)
  515. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  516. else
  517. iwe.u.data.flags = IW_ENCODE_DISABLED;
  518. iwe.u.data.length = 0;
  519. iwe.cmd = SIOCGIWENCODE;
  520. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  521. &iwe, NULL);
  522. /* Add frequency. (short) bss->channel is the frequency in MHz */
  523. iwe.u.freq.m = bss->channel;
  524. iwe.u.freq.e = 6;
  525. iwe.cmd = SIOCGIWFREQ;
  526. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  527. &iwe, IW_EV_FREQ_LEN);
  528. /* Add quality statistics */
  529. iwe.u.qual.level = bss->rssi;
  530. iwe.u.qual.noise = noise;
  531. /* do a simple SNR for quality */
  532. iwe.u.qual.qual = bss->rssi - noise;
  533. iwe.cmd = IWEVQUAL;
  534. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  535. &iwe, IW_EV_QUAL_LEN);
  536. /* Add WPA/RSN Information Element, if any */
  537. wpa_ie_len = prism54_wpa_bss_ie_get(priv, bss->address, wpa_ie);
  538. if (wpa_ie_len > 0) {
  539. iwe.cmd = IWEVGENIE;
  540. iwe.u.data.length = min(wpa_ie_len, (size_t)MAX_WPA_IE_LEN);
  541. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  542. &iwe, wpa_ie);
  543. }
  544. /* Do the bitrates */
  545. {
  546. char *current_val = current_ev + iwe_stream_lcp_len(info);
  547. int i;
  548. int mask;
  549. iwe.cmd = SIOCGIWRATE;
  550. /* Those two flags are ignored... */
  551. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  552. /* Parse the bitmask */
  553. mask = 0x1;
  554. for(i = 0; i < sizeof(scan_rate_list); i++) {
  555. if(bss->rates & mask) {
  556. iwe.u.bitrate.value = (scan_rate_list[i] * 500000);
  557. current_val = iwe_stream_add_value(
  558. info, current_ev, current_val,
  559. end_buf, &iwe, IW_EV_PARAM_LEN);
  560. }
  561. mask <<= 1;
  562. }
  563. /* Check if we added any event */
  564. if ((current_val - current_ev) > iwe_stream_lcp_len(info))
  565. current_ev = current_val;
  566. }
  567. return current_ev;
  568. }
  569. static int
  570. prism54_get_scan(struct net_device *ndev, struct iw_request_info *info,
  571. struct iw_point *dwrq, char *extra)
  572. {
  573. islpci_private *priv = netdev_priv(ndev);
  574. int i, rvalue;
  575. struct obj_bsslist *bsslist;
  576. u32 noise = 0;
  577. char *current_ev = extra;
  578. union oid_res_t r;
  579. if (islpci_get_state(priv) < PRV_STATE_INIT) {
  580. /* device is not ready, fail gently */
  581. dwrq->length = 0;
  582. return 0;
  583. }
  584. /* first get the noise value. We will use it to report the link quality */
  585. rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
  586. noise = r.u;
  587. /* Ask the device for a list of known bss.
  588. * The old API, using SIOCGIWAPLIST, had a hard limit of IW_MAX_AP=64.
  589. * The new API, using SIOCGIWSCAN, is only limited by the buffer size.
  590. * WE-14->WE-16, the buffer is limited to IW_SCAN_MAX_DATA bytes.
  591. * Starting with WE-17, the buffer can be as big as needed.
  592. * But the device won't repport anything if you change the value
  593. * of IWMAX_BSS=24. */
  594. rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r);
  595. bsslist = r.ptr;
  596. /* ok now, scan the list and translate its info */
  597. for (i = 0; i < (int) bsslist->nr; i++) {
  598. current_ev = prism54_translate_bss(ndev, info, current_ev,
  599. extra + dwrq->length,
  600. &(bsslist->bsslist[i]),
  601. noise);
  602. /* Check if there is space for one more entry */
  603. if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
  604. /* Ask user space to try again with a bigger buffer */
  605. rvalue = -E2BIG;
  606. break;
  607. }
  608. }
  609. kfree(bsslist);
  610. dwrq->length = (current_ev - extra);
  611. dwrq->flags = 0; /* todo */
  612. return rvalue;
  613. }
  614. static int
  615. prism54_set_essid(struct net_device *ndev, struct iw_request_info *info,
  616. struct iw_point *dwrq, char *extra)
  617. {
  618. islpci_private *priv = netdev_priv(ndev);
  619. struct obj_ssid essid;
  620. memset(essid.octets, 0, 33);
  621. /* Check if we were asked for `any' */
  622. if (dwrq->flags && dwrq->length) {
  623. if (dwrq->length > 32)
  624. return -E2BIG;
  625. essid.length = dwrq->length;
  626. memcpy(essid.octets, extra, dwrq->length);
  627. } else
  628. essid.length = 0;
  629. if (priv->iw_mode != IW_MODE_MONITOR)
  630. return mgt_set_request(priv, DOT11_OID_SSID, 0, &essid);
  631. /* If in monitor mode, just save to mib */
  632. mgt_set(priv, DOT11_OID_SSID, &essid);
  633. return 0;
  634. }
  635. static int
  636. prism54_get_essid(struct net_device *ndev, struct iw_request_info *info,
  637. struct iw_point *dwrq, char *extra)
  638. {
  639. islpci_private *priv = netdev_priv(ndev);
  640. struct obj_ssid *essid;
  641. union oid_res_t r;
  642. int rvalue;
  643. rvalue = mgt_get_request(priv, DOT11_OID_SSID, 0, NULL, &r);
  644. essid = r.ptr;
  645. if (essid->length) {
  646. dwrq->flags = 1; /* set ESSID to ON for Wireless Extensions */
  647. /* if it is too big, trunk it */
  648. dwrq->length = min((u8)IW_ESSID_MAX_SIZE, essid->length);
  649. } else {
  650. dwrq->flags = 0;
  651. dwrq->length = 0;
  652. }
  653. essid->octets[dwrq->length] = '\0';
  654. memcpy(extra, essid->octets, dwrq->length);
  655. kfree(essid);
  656. return rvalue;
  657. }
  658. /* Provides no functionality, just completes the ioctl. In essence this is a
  659. * just a cosmetic ioctl.
  660. */
  661. static int
  662. prism54_set_nick(struct net_device *ndev, struct iw_request_info *info,
  663. struct iw_point *dwrq, char *extra)
  664. {
  665. islpci_private *priv = netdev_priv(ndev);
  666. if (dwrq->length > IW_ESSID_MAX_SIZE)
  667. return -E2BIG;
  668. down_write(&priv->mib_sem);
  669. memset(priv->nickname, 0, sizeof (priv->nickname));
  670. memcpy(priv->nickname, extra, dwrq->length);
  671. up_write(&priv->mib_sem);
  672. return 0;
  673. }
  674. static int
  675. prism54_get_nick(struct net_device *ndev, struct iw_request_info *info,
  676. struct iw_point *dwrq, char *extra)
  677. {
  678. islpci_private *priv = netdev_priv(ndev);
  679. dwrq->length = 0;
  680. down_read(&priv->mib_sem);
  681. dwrq->length = strlen(priv->nickname);
  682. memcpy(extra, priv->nickname, dwrq->length);
  683. up_read(&priv->mib_sem);
  684. return 0;
  685. }
  686. /* Set the allowed Bitrates */
  687. static int
  688. prism54_set_rate(struct net_device *ndev,
  689. struct iw_request_info *info,
  690. struct iw_param *vwrq, char *extra)
  691. {
  692. islpci_private *priv = netdev_priv(ndev);
  693. u32 rate, profile;
  694. char *data;
  695. int ret, i;
  696. union oid_res_t r;
  697. if (vwrq->value == -1) {
  698. /* auto mode. No limit. */
  699. profile = 1;
  700. return mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
  701. }
  702. ret = mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
  703. if (ret) {
  704. kfree(r.ptr);
  705. return ret;
  706. }
  707. rate = (u32) (vwrq->value / 500000);
  708. data = r.ptr;
  709. i = 0;
  710. while (data[i]) {
  711. if (rate && (data[i] == rate)) {
  712. break;
  713. }
  714. if (vwrq->value == i) {
  715. break;
  716. }
  717. data[i] |= 0x80;
  718. i++;
  719. }
  720. if (!data[i]) {
  721. kfree(r.ptr);
  722. return -EINVAL;
  723. }
  724. data[i] |= 0x80;
  725. data[i + 1] = 0;
  726. /* Now, check if we want a fixed or auto value */
  727. if (vwrq->fixed) {
  728. data[0] = data[i];
  729. data[1] = 0;
  730. }
  731. /*
  732. i = 0;
  733. printk("prism54 rate: ");
  734. while(data[i]) {
  735. printk("%u ", data[i]);
  736. i++;
  737. }
  738. printk("0\n");
  739. */
  740. profile = -1;
  741. ret = mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
  742. ret |= mgt_set_request(priv, DOT11_OID_EXTENDEDRATES, 0, data);
  743. ret |= mgt_set_request(priv, DOT11_OID_RATES, 0, data);
  744. kfree(r.ptr);
  745. return ret;
  746. }
  747. /* Get the current bit rate */
  748. static int
  749. prism54_get_rate(struct net_device *ndev,
  750. struct iw_request_info *info,
  751. struct iw_param *vwrq, char *extra)
  752. {
  753. islpci_private *priv = netdev_priv(ndev);
  754. int rvalue;
  755. char *data;
  756. union oid_res_t r;
  757. /* Get the current bit rate */
  758. if ((rvalue = mgt_get_request(priv, GEN_OID_LINKSTATE, 0, NULL, &r)))
  759. return rvalue;
  760. vwrq->value = r.u * 500000;
  761. /* request the device for the enabled rates */
  762. rvalue = mgt_get_request(priv, DOT11_OID_RATES, 0, NULL, &r);
  763. if (rvalue) {
  764. kfree(r.ptr);
  765. return rvalue;
  766. }
  767. data = r.ptr;
  768. vwrq->fixed = (data[0] != 0) && (data[1] == 0);
  769. kfree(r.ptr);
  770. return 0;
  771. }
  772. static int
  773. prism54_set_rts(struct net_device *ndev, struct iw_request_info *info,
  774. struct iw_param *vwrq, char *extra)
  775. {
  776. islpci_private *priv = netdev_priv(ndev);
  777. return mgt_set_request(priv, DOT11_OID_RTSTHRESH, 0, &vwrq->value);
  778. }
  779. static int
  780. prism54_get_rts(struct net_device *ndev, struct iw_request_info *info,
  781. struct iw_param *vwrq, char *extra)
  782. {
  783. islpci_private *priv = netdev_priv(ndev);
  784. union oid_res_t r;
  785. int rvalue;
  786. /* get the rts threshold */
  787. rvalue = mgt_get_request(priv, DOT11_OID_RTSTHRESH, 0, NULL, &r);
  788. vwrq->value = r.u;
  789. return rvalue;
  790. }
  791. static int
  792. prism54_set_frag(struct net_device *ndev, struct iw_request_info *info,
  793. struct iw_param *vwrq, char *extra)
  794. {
  795. islpci_private *priv = netdev_priv(ndev);
  796. return mgt_set_request(priv, DOT11_OID_FRAGTHRESH, 0, &vwrq->value);
  797. }
  798. static int
  799. prism54_get_frag(struct net_device *ndev, struct iw_request_info *info,
  800. struct iw_param *vwrq, char *extra)
  801. {
  802. islpci_private *priv = netdev_priv(ndev);
  803. union oid_res_t r;
  804. int rvalue;
  805. rvalue = mgt_get_request(priv, DOT11_OID_FRAGTHRESH, 0, NULL, &r);
  806. vwrq->value = r.u;
  807. return rvalue;
  808. }
  809. /* Here we have (min,max) = max retries for (small frames, big frames). Where
  810. * big frame <=> bigger than the rts threshold
  811. * small frame <=> smaller than the rts threshold
  812. * This is not really the behavior expected by the wireless tool but it seems
  813. * to be a common behavior in other drivers.
  814. */
  815. static int
  816. prism54_set_retry(struct net_device *ndev, struct iw_request_info *info,
  817. struct iw_param *vwrq, char *extra)
  818. {
  819. islpci_private *priv = netdev_priv(ndev);
  820. u32 slimit = 0, llimit = 0; /* short and long limit */
  821. u32 lifetime = 0;
  822. int rvalue = 0;
  823. if (vwrq->disabled)
  824. /* we cannot disable this feature */
  825. return -EINVAL;
  826. if (vwrq->flags & IW_RETRY_LIMIT) {
  827. if (vwrq->flags & IW_RETRY_SHORT)
  828. slimit = vwrq->value;
  829. else if (vwrq->flags & IW_RETRY_LONG)
  830. llimit = vwrq->value;
  831. else {
  832. /* we are asked to set both */
  833. slimit = vwrq->value;
  834. llimit = vwrq->value;
  835. }
  836. }
  837. if (vwrq->flags & IW_RETRY_LIFETIME)
  838. /* Wireless tools use us unit while the device uses 1024 us unit */
  839. lifetime = vwrq->value / 1024;
  840. /* now set what is requested */
  841. if (slimit)
  842. rvalue =
  843. mgt_set_request(priv, DOT11_OID_SHORTRETRIES, 0, &slimit);
  844. if (llimit)
  845. rvalue |=
  846. mgt_set_request(priv, DOT11_OID_LONGRETRIES, 0, &llimit);
  847. if (lifetime)
  848. rvalue |=
  849. mgt_set_request(priv, DOT11_OID_MAXTXLIFETIME, 0,
  850. &lifetime);
  851. return rvalue;
  852. }
  853. static int
  854. prism54_get_retry(struct net_device *ndev, struct iw_request_info *info,
  855. struct iw_param *vwrq, char *extra)
  856. {
  857. islpci_private *priv = netdev_priv(ndev);
  858. union oid_res_t r;
  859. int rvalue = 0;
  860. vwrq->disabled = 0; /* It cannot be disabled */
  861. if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  862. /* we are asked for the life time */
  863. rvalue =
  864. mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r);
  865. vwrq->value = r.u * 1024;
  866. vwrq->flags = IW_RETRY_LIFETIME;
  867. } else if ((vwrq->flags & IW_RETRY_LONG)) {
  868. /* we are asked for the long retry limit */
  869. rvalue |=
  870. mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r);
  871. vwrq->value = r.u;
  872. vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  873. } else {
  874. /* default. get the short retry limit */
  875. rvalue |=
  876. mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r);
  877. vwrq->value = r.u;
  878. vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
  879. }
  880. return rvalue;
  881. }
  882. static int
  883. prism54_set_encode(struct net_device *ndev, struct iw_request_info *info,
  884. struct iw_point *dwrq, char *extra)
  885. {
  886. islpci_private *priv = netdev_priv(ndev);
  887. int rvalue = 0, force = 0;
  888. int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
  889. union oid_res_t r;
  890. /* with the new API, it's impossible to get a NULL pointer.
  891. * New version of iwconfig set the IW_ENCODE_NOKEY flag
  892. * when no key is given, but older versions don't. */
  893. if (dwrq->length > 0) {
  894. /* we have a key to set */
  895. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  896. int current_index;
  897. struct obj_key key = { DOT11_PRIV_WEP, 0, "" };
  898. /* get the current key index */
  899. rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
  900. current_index = r.u;
  901. /* Verify that the key is not marked as invalid */
  902. if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
  903. if (dwrq->length > KEY_SIZE_TKIP) {
  904. /* User-provided key data too big */
  905. return -EINVAL;
  906. }
  907. if (dwrq->length > KEY_SIZE_WEP104) {
  908. /* WPA-PSK TKIP */
  909. key.type = DOT11_PRIV_TKIP;
  910. key.length = KEY_SIZE_TKIP;
  911. } else if (dwrq->length > KEY_SIZE_WEP40) {
  912. /* WEP 104/128 */
  913. key.length = KEY_SIZE_WEP104;
  914. } else {
  915. /* WEP 40/64 */
  916. key.length = KEY_SIZE_WEP40;
  917. }
  918. memset(key.key, 0, sizeof (key.key));
  919. memcpy(key.key, extra, dwrq->length);
  920. if ((index < 0) || (index > 3))
  921. /* no index provided use the current one */
  922. index = current_index;
  923. /* now send the key to the card */
  924. rvalue |=
  925. mgt_set_request(priv, DOT11_OID_DEFKEYX, index,
  926. &key);
  927. }
  928. /*
  929. * If a valid key is set, encryption should be enabled
  930. * (user may turn it off later).
  931. * This is also how "iwconfig ethX key on" works
  932. */
  933. if ((index == current_index) && (key.length > 0))
  934. force = 1;
  935. } else {
  936. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  937. if ((index >= 0) && (index <= 3)) {
  938. /* we want to set the key index */
  939. rvalue |=
  940. mgt_set_request(priv, DOT11_OID_DEFKEYID, 0,
  941. &index);
  942. } else {
  943. if (!(dwrq->flags & IW_ENCODE_MODE)) {
  944. /* we cannot do anything. Complain. */
  945. return -EINVAL;
  946. }
  947. }
  948. }
  949. /* now read the flags */
  950. if (dwrq->flags & IW_ENCODE_DISABLED) {
  951. /* Encoding disabled,
  952. * authen = DOT11_AUTH_OS;
  953. * invoke = 0;
  954. * exunencrypt = 0; */
  955. }
  956. if (dwrq->flags & IW_ENCODE_OPEN)
  957. /* Encode but accept non-encoded packets. No auth */
  958. invoke = 1;
  959. if ((dwrq->flags & IW_ENCODE_RESTRICTED) || force) {
  960. /* Refuse non-encoded packets. Auth */
  961. authen = DOT11_AUTH_BOTH;
  962. invoke = 1;
  963. exunencrypt = 1;
  964. }
  965. /* do the change if requested */
  966. if ((dwrq->flags & IW_ENCODE_MODE) || force) {
  967. rvalue |=
  968. mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
  969. rvalue |=
  970. mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke);
  971. rvalue |=
  972. mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
  973. &exunencrypt);
  974. }
  975. return rvalue;
  976. }
  977. static int
  978. prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
  979. struct iw_point *dwrq, char *extra)
  980. {
  981. islpci_private *priv = netdev_priv(ndev);
  982. struct obj_key *key;
  983. u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  984. u32 authen = 0, invoke = 0, exunencrypt = 0;
  985. int rvalue;
  986. union oid_res_t r;
  987. /* first get the flags */
  988. rvalue = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
  989. authen = r.u;
  990. rvalue |= mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
  991. invoke = r.u;
  992. rvalue |= mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
  993. exunencrypt = r.u;
  994. if (invoke && (authen == DOT11_AUTH_BOTH) && exunencrypt)
  995. dwrq->flags = IW_ENCODE_RESTRICTED;
  996. else if ((authen == DOT11_AUTH_OS) && !exunencrypt) {
  997. if (invoke)
  998. dwrq->flags = IW_ENCODE_OPEN;
  999. else
  1000. dwrq->flags = IW_ENCODE_DISABLED;
  1001. } else
  1002. /* The card should not work in this state */
  1003. dwrq->flags = 0;
  1004. /* get the current device key index */
  1005. rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
  1006. devindex = r.u;
  1007. /* Now get the key, return it */
  1008. if (index == -1 || index > 3)
  1009. /* no index provided, use the current one */
  1010. index = devindex;
  1011. rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);
  1012. key = r.ptr;
  1013. dwrq->length = key->length;
  1014. memcpy(extra, key->key, dwrq->length);
  1015. kfree(key);
  1016. /* return the used key index */
  1017. dwrq->flags |= devindex + 1;
  1018. return rvalue;
  1019. }
  1020. static int
  1021. prism54_get_txpower(struct net_device *ndev, struct iw_request_info *info,
  1022. struct iw_param *vwrq, char *extra)
  1023. {
  1024. islpci_private *priv = netdev_priv(ndev);
  1025. union oid_res_t r;
  1026. int rvalue;
  1027. rvalue = mgt_get_request(priv, OID_INL_OUTPUTPOWER, 0, NULL, &r);
  1028. /* intersil firmware operates in 0.25 dBm (1/4 dBm) */
  1029. vwrq->value = (s32) r.u / 4;
  1030. vwrq->fixed = 1;
  1031. /* radio is not turned of
  1032. * btw: how is possible to turn off only the radio
  1033. */
  1034. vwrq->disabled = 0;
  1035. return rvalue;
  1036. }
  1037. static int
  1038. prism54_set_txpower(struct net_device *ndev, struct iw_request_info *info,
  1039. struct iw_param *vwrq, char *extra)
  1040. {
  1041. islpci_private *priv = netdev_priv(ndev);
  1042. s32 u = vwrq->value;
  1043. /* intersil firmware operates in 0.25 dBm (1/4) */
  1044. u *= 4;
  1045. if (vwrq->disabled) {
  1046. /* don't know how to disable radio */
  1047. printk(KERN_DEBUG
  1048. "%s: %s() disabling radio is not yet supported.\n",
  1049. priv->ndev->name, __func__);
  1050. return -ENOTSUPP;
  1051. } else if (vwrq->fixed)
  1052. /* currently only fixed value is supported */
  1053. return mgt_set_request(priv, OID_INL_OUTPUTPOWER, 0, &u);
  1054. else {
  1055. printk(KERN_DEBUG
  1056. "%s: %s() auto power will be implemented later.\n",
  1057. priv->ndev->name, __func__);
  1058. return -ENOTSUPP;
  1059. }
  1060. }
  1061. static int prism54_set_genie(struct net_device *ndev,
  1062. struct iw_request_info *info,
  1063. struct iw_point *data, char *extra)
  1064. {
  1065. islpci_private *priv = netdev_priv(ndev);
  1066. int alen, ret = 0;
  1067. struct obj_attachment *attach;
  1068. if (data->length > MAX_WPA_IE_LEN ||
  1069. (data->length && extra == NULL))
  1070. return -EINVAL;
  1071. memcpy(priv->wpa_ie, extra, data->length);
  1072. priv->wpa_ie_len = data->length;
  1073. alen = sizeof(*attach) + priv->wpa_ie_len;
  1074. attach = kzalloc(alen, GFP_KERNEL);
  1075. if (attach == NULL)
  1076. return -ENOMEM;
  1077. #define WLAN_FC_TYPE_MGMT 0
  1078. #define WLAN_FC_STYPE_ASSOC_REQ 0
  1079. #define WLAN_FC_STYPE_REASSOC_REQ 2
  1080. /* Note: endianness is covered by mgt_set_varlen */
  1081. attach->type = (WLAN_FC_TYPE_MGMT << 2) |
  1082. (WLAN_FC_STYPE_ASSOC_REQ << 4);
  1083. attach->id = -1;
  1084. attach->size = priv->wpa_ie_len;
  1085. memcpy(attach->data, extra, priv->wpa_ie_len);
  1086. ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach,
  1087. priv->wpa_ie_len);
  1088. if (ret == 0) {
  1089. attach->type = (WLAN_FC_TYPE_MGMT << 2) |
  1090. (WLAN_FC_STYPE_REASSOC_REQ << 4);
  1091. ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach,
  1092. priv->wpa_ie_len);
  1093. if (ret == 0)
  1094. printk(KERN_DEBUG "%s: WPA IE Attachment was set\n",
  1095. ndev->name);
  1096. }
  1097. kfree(attach);
  1098. return ret;
  1099. }
  1100. static int prism54_get_genie(struct net_device *ndev,
  1101. struct iw_request_info *info,
  1102. struct iw_point *data, char *extra)
  1103. {
  1104. islpci_private *priv = netdev_priv(ndev);
  1105. int len = priv->wpa_ie_len;
  1106. if (len <= 0) {
  1107. data->length = 0;
  1108. return 0;
  1109. }
  1110. if (data->length < len)
  1111. return -E2BIG;
  1112. data->length = len;
  1113. memcpy(extra, priv->wpa_ie, len);
  1114. return 0;
  1115. }
  1116. static int prism54_set_auth(struct net_device *ndev,
  1117. struct iw_request_info *info,
  1118. union iwreq_data *wrqu, char *extra)
  1119. {
  1120. islpci_private *priv = netdev_priv(ndev);
  1121. struct iw_param *param = &wrqu->param;
  1122. u32 mlmelevel = 0, authen = 0, dot1x = 0;
  1123. u32 exunencrypt = 0, privinvoked = 0, wpa = 0;
  1124. u32 old_wpa;
  1125. int ret = 0;
  1126. union oid_res_t r;
  1127. if (islpci_get_state(priv) < PRV_STATE_INIT)
  1128. return 0;
  1129. /* first get the flags */
  1130. down_write(&priv->mib_sem);
  1131. wpa = old_wpa = priv->wpa;
  1132. up_write(&priv->mib_sem);
  1133. ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
  1134. authen = r.u;
  1135. ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
  1136. privinvoked = r.u;
  1137. ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
  1138. exunencrypt = r.u;
  1139. ret = mgt_get_request(priv, DOT11_OID_DOT1XENABLE, 0, NULL, &r);
  1140. dot1x = r.u;
  1141. ret = mgt_get_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, NULL, &r);
  1142. mlmelevel = r.u;
  1143. if (ret < 0)
  1144. goto out;
  1145. switch (param->flags & IW_AUTH_INDEX) {
  1146. case IW_AUTH_CIPHER_PAIRWISE:
  1147. case IW_AUTH_CIPHER_GROUP:
  1148. case IW_AUTH_KEY_MGMT:
  1149. break;
  1150. case IW_AUTH_WPA_ENABLED:
  1151. /* Do the same thing as IW_AUTH_WPA_VERSION */
  1152. if (param->value) {
  1153. wpa = 1;
  1154. privinvoked = 1; /* For privacy invoked */
  1155. exunencrypt = 1; /* Filter out all unencrypted frames */
  1156. dot1x = 0x01; /* To enable eap filter */
  1157. mlmelevel = DOT11_MLME_EXTENDED;
  1158. authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */
  1159. } else {
  1160. wpa = 0;
  1161. privinvoked = 0;
  1162. exunencrypt = 0; /* Do not filter un-encrypted data */
  1163. dot1x = 0;
  1164. mlmelevel = DOT11_MLME_AUTO;
  1165. }
  1166. break;
  1167. case IW_AUTH_WPA_VERSION:
  1168. if (param->value & IW_AUTH_WPA_VERSION_DISABLED) {
  1169. wpa = 0;
  1170. privinvoked = 0;
  1171. exunencrypt = 0; /* Do not filter un-encrypted data */
  1172. dot1x = 0;
  1173. mlmelevel = DOT11_MLME_AUTO;
  1174. } else {
  1175. if (param->value & IW_AUTH_WPA_VERSION_WPA)
  1176. wpa = 1;
  1177. else if (param->value & IW_AUTH_WPA_VERSION_WPA2)
  1178. wpa = 2;
  1179. privinvoked = 1; /* For privacy invoked */
  1180. exunencrypt = 1; /* Filter out all unencrypted frames */
  1181. dot1x = 0x01; /* To enable eap filter */
  1182. mlmelevel = DOT11_MLME_EXTENDED;
  1183. authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */
  1184. }
  1185. break;
  1186. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  1187. /* dot1x should be the opposite of RX_UNENCRYPTED_EAPOL;
  1188. * turn off dot1x when allowing receipt of unencrypted EAPOL
  1189. * frames, turn on dot1x when receipt should be disallowed
  1190. */
  1191. dot1x = param->value ? 0 : 0x01;
  1192. break;
  1193. case IW_AUTH_PRIVACY_INVOKED:
  1194. privinvoked = param->value ? 1 : 0;
  1195. break;
  1196. case IW_AUTH_DROP_UNENCRYPTED:
  1197. exunencrypt = param->value ? 1 : 0;
  1198. break;
  1199. case IW_AUTH_80211_AUTH_ALG:
  1200. if (param->value & IW_AUTH_ALG_SHARED_KEY) {
  1201. /* Only WEP uses _SK and _BOTH */
  1202. if (wpa > 0) {
  1203. ret = -EINVAL;
  1204. goto out;
  1205. }
  1206. authen = DOT11_AUTH_SK;
  1207. } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
  1208. authen = DOT11_AUTH_OS;
  1209. } else {
  1210. ret = -EINVAL;
  1211. goto out;
  1212. }
  1213. break;
  1214. default:
  1215. return -EOPNOTSUPP;
  1216. }
  1217. /* Set all the values */
  1218. down_write(&priv->mib_sem);
  1219. priv->wpa = wpa;
  1220. up_write(&priv->mib_sem);
  1221. mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
  1222. mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &privinvoked);
  1223. mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &exunencrypt);
  1224. mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x);
  1225. mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlmelevel);
  1226. out:
  1227. return ret;
  1228. }
  1229. static int prism54_get_auth(struct net_device *ndev,
  1230. struct iw_request_info *info,
  1231. union iwreq_data *wrqu, char *extra)
  1232. {
  1233. islpci_private *priv = netdev_priv(ndev);
  1234. struct iw_param *param = &wrqu->param;
  1235. u32 wpa = 0;
  1236. int ret = 0;
  1237. union oid_res_t r;
  1238. if (islpci_get_state(priv) < PRV_STATE_INIT)
  1239. return 0;
  1240. /* first get the flags */
  1241. down_write(&priv->mib_sem);
  1242. wpa = priv->wpa;
  1243. up_write(&priv->mib_sem);
  1244. switch (param->flags & IW_AUTH_INDEX) {
  1245. case IW_AUTH_CIPHER_PAIRWISE:
  1246. case IW_AUTH_CIPHER_GROUP:
  1247. case IW_AUTH_KEY_MGMT:
  1248. /*
  1249. * wpa_supplicant will control these internally
  1250. */
  1251. ret = -EOPNOTSUPP;
  1252. break;
  1253. case IW_AUTH_WPA_VERSION:
  1254. switch (wpa) {
  1255. case 1:
  1256. param->value = IW_AUTH_WPA_VERSION_WPA;
  1257. break;
  1258. case 2:
  1259. param->value = IW_AUTH_WPA_VERSION_WPA2;
  1260. break;
  1261. case 0:
  1262. default:
  1263. param->value = IW_AUTH_WPA_VERSION_DISABLED;
  1264. break;
  1265. }
  1266. break;
  1267. case IW_AUTH_DROP_UNENCRYPTED:
  1268. ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
  1269. if (ret >= 0)
  1270. param->value = r.u > 0 ? 1 : 0;
  1271. break;
  1272. case IW_AUTH_80211_AUTH_ALG:
  1273. ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
  1274. if (ret >= 0) {
  1275. switch (r.u) {
  1276. case DOT11_AUTH_OS:
  1277. param->value = IW_AUTH_ALG_OPEN_SYSTEM;
  1278. break;
  1279. case DOT11_AUTH_BOTH:
  1280. case DOT11_AUTH_SK:
  1281. param->value = IW_AUTH_ALG_SHARED_KEY;
  1282. break;
  1283. case DOT11_AUTH_NONE:
  1284. default:
  1285. param->value = 0;
  1286. break;
  1287. }
  1288. }
  1289. break;
  1290. case IW_AUTH_WPA_ENABLED:
  1291. param->value = wpa > 0 ? 1 : 0;
  1292. break;
  1293. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  1294. ret = mgt_get_request(priv, DOT11_OID_DOT1XENABLE, 0, NULL, &r);
  1295. if (ret >= 0)
  1296. param->value = r.u > 0 ? 1 : 0;
  1297. break;
  1298. case IW_AUTH_PRIVACY_INVOKED:
  1299. ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
  1300. if (ret >= 0)
  1301. param->value = r.u > 0 ? 1 : 0;
  1302. break;
  1303. default:
  1304. return -EOPNOTSUPP;
  1305. }
  1306. return ret;
  1307. }
  1308. static int prism54_set_encodeext(struct net_device *ndev,
  1309. struct iw_request_info *info,
  1310. union iwreq_data *wrqu,
  1311. char *extra)
  1312. {
  1313. islpci_private *priv = netdev_priv(ndev);
  1314. struct iw_point *encoding = &wrqu->encoding;
  1315. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1316. int idx, alg = ext->alg, set_key = 1;
  1317. union oid_res_t r;
  1318. int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
  1319. int ret = 0;
  1320. if (islpci_get_state(priv) < PRV_STATE_INIT)
  1321. return 0;
  1322. /* Determine and validate the key index */
  1323. idx = (encoding->flags & IW_ENCODE_INDEX) - 1;
  1324. if (idx) {
  1325. if (idx < 0 || idx > 3)
  1326. return -EINVAL;
  1327. } else {
  1328. ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
  1329. if (ret < 0)
  1330. goto out;
  1331. idx = r.u;
  1332. }
  1333. if (encoding->flags & IW_ENCODE_DISABLED)
  1334. alg = IW_ENCODE_ALG_NONE;
  1335. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  1336. /* Only set transmit key index here, actual
  1337. * key is set below if needed.
  1338. */
  1339. ret = mgt_set_request(priv, DOT11_OID_DEFKEYID, 0, &idx);
  1340. set_key = ext->key_len > 0 ? 1 : 0;
  1341. }
  1342. if (set_key) {
  1343. struct obj_key key = { DOT11_PRIV_WEP, 0, "" };
  1344. switch (alg) {
  1345. case IW_ENCODE_ALG_NONE:
  1346. break;
  1347. case IW_ENCODE_ALG_WEP:
  1348. if (ext->key_len > KEY_SIZE_WEP104) {
  1349. ret = -EINVAL;
  1350. goto out;
  1351. }
  1352. if (ext->key_len > KEY_SIZE_WEP40)
  1353. key.length = KEY_SIZE_WEP104;
  1354. else
  1355. key.length = KEY_SIZE_WEP40;
  1356. break;
  1357. case IW_ENCODE_ALG_TKIP:
  1358. if (ext->key_len > KEY_SIZE_TKIP) {
  1359. ret = -EINVAL;
  1360. goto out;
  1361. }
  1362. key.type = DOT11_PRIV_TKIP;
  1363. key.length = KEY_SIZE_TKIP;
  1364. break;
  1365. default:
  1366. return -EINVAL;
  1367. }
  1368. if (key.length) {
  1369. memset(key.key, 0, sizeof(key.key));
  1370. memcpy(key.key, ext->key, ext->key_len);
  1371. ret = mgt_set_request(priv, DOT11_OID_DEFKEYX, idx,
  1372. &key);
  1373. if (ret < 0)
  1374. goto out;
  1375. }
  1376. }
  1377. /* Read the flags */
  1378. if (encoding->flags & IW_ENCODE_DISABLED) {
  1379. /* Encoding disabled,
  1380. * authen = DOT11_AUTH_OS;
  1381. * invoke = 0;
  1382. * exunencrypt = 0; */
  1383. }
  1384. if (encoding->flags & IW_ENCODE_OPEN) {
  1385. /* Encode but accept non-encoded packets. No auth */
  1386. invoke = 1;
  1387. }
  1388. if (encoding->flags & IW_ENCODE_RESTRICTED) {
  1389. /* Refuse non-encoded packets. Auth */
  1390. authen = DOT11_AUTH_BOTH;
  1391. invoke = 1;
  1392. exunencrypt = 1;
  1393. }
  1394. /* do the change if requested */
  1395. if (encoding->flags & IW_ENCODE_MODE) {
  1396. ret = mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0,
  1397. &authen);
  1398. ret = mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0,
  1399. &invoke);
  1400. ret = mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
  1401. &exunencrypt);
  1402. }
  1403. out:
  1404. return ret;
  1405. }
  1406. static int prism54_get_encodeext(struct net_device *ndev,
  1407. struct iw_request_info *info,
  1408. union iwreq_data *wrqu,
  1409. char *extra)
  1410. {
  1411. islpci_private *priv = netdev_priv(ndev);
  1412. struct iw_point *encoding = &wrqu->encoding;
  1413. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1414. int idx, max_key_len;
  1415. union oid_res_t r;
  1416. int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0, wpa = 0;
  1417. int ret = 0;
  1418. if (islpci_get_state(priv) < PRV_STATE_INIT)
  1419. return 0;
  1420. /* first get the flags */
  1421. ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
  1422. authen = r.u;
  1423. ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
  1424. invoke = r.u;
  1425. ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
  1426. exunencrypt = r.u;
  1427. if (ret < 0)
  1428. goto out;
  1429. max_key_len = encoding->length - sizeof(*ext);
  1430. if (max_key_len < 0)
  1431. return -EINVAL;
  1432. idx = (encoding->flags & IW_ENCODE_INDEX) - 1;
  1433. if (idx) {
  1434. if (idx < 0 || idx > 3)
  1435. return -EINVAL;
  1436. } else {
  1437. ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
  1438. if (ret < 0)
  1439. goto out;
  1440. idx = r.u;
  1441. }
  1442. encoding->flags = idx + 1;
  1443. memset(ext, 0, sizeof(*ext));
  1444. switch (authen) {
  1445. case DOT11_AUTH_BOTH:
  1446. case DOT11_AUTH_SK:
  1447. wrqu->encoding.flags |= IW_ENCODE_RESTRICTED;
  1448. case DOT11_AUTH_OS:
  1449. default:
  1450. wrqu->encoding.flags |= IW_ENCODE_OPEN;
  1451. break;
  1452. }
  1453. down_write(&priv->mib_sem);
  1454. wpa = priv->wpa;
  1455. up_write(&priv->mib_sem);
  1456. if (authen == DOT11_AUTH_OS && !exunencrypt && !invoke && !wpa) {
  1457. /* No encryption */
  1458. ext->alg = IW_ENCODE_ALG_NONE;
  1459. ext->key_len = 0;
  1460. wrqu->encoding.flags |= IW_ENCODE_DISABLED;
  1461. } else {
  1462. struct obj_key *key;
  1463. ret = mgt_get_request(priv, DOT11_OID_DEFKEYX, idx, NULL, &r);
  1464. if (ret < 0)
  1465. goto out;
  1466. key = r.ptr;
  1467. if (max_key_len < key->length) {
  1468. ret = -E2BIG;
  1469. goto out;
  1470. }
  1471. memcpy(ext->key, key->key, key->length);
  1472. ext->key_len = key->length;
  1473. switch (key->type) {
  1474. case DOT11_PRIV_TKIP:
  1475. ext->alg = IW_ENCODE_ALG_TKIP;
  1476. break;
  1477. default:
  1478. case DOT11_PRIV_WEP:
  1479. ext->alg = IW_ENCODE_ALG_WEP;
  1480. break;
  1481. }
  1482. wrqu->encoding.flags |= IW_ENCODE_ENABLED;
  1483. }
  1484. out:
  1485. return ret;
  1486. }
  1487. static int
  1488. prism54_reset(struct net_device *ndev, struct iw_request_info *info,
  1489. __u32 * uwrq, char *extra)
  1490. {
  1491. islpci_reset(netdev_priv(ndev), 0);
  1492. return 0;
  1493. }
  1494. static int
  1495. prism54_get_oid(struct net_device *ndev, struct iw_request_info *info,
  1496. struct iw_point *dwrq, char *extra)
  1497. {
  1498. union oid_res_t r;
  1499. int rvalue;
  1500. enum oid_num_t n = dwrq->flags;
  1501. rvalue = mgt_get_request(netdev_priv(ndev), n, 0, NULL, &r);
  1502. dwrq->length = mgt_response_to_str(n, &r, extra);
  1503. if ((isl_oid[n].flags & OID_FLAG_TYPE) != OID_TYPE_U32)
  1504. kfree(r.ptr);
  1505. return rvalue;
  1506. }
  1507. static int
  1508. prism54_set_u32(struct net_device *ndev, struct iw_request_info *info,
  1509. __u32 * uwrq, char *extra)
  1510. {
  1511. u32 oid = uwrq[0], u = uwrq[1];
  1512. return mgt_set_request(netdev_priv(ndev), oid, 0, &u);
  1513. }
  1514. static int
  1515. prism54_set_raw(struct net_device *ndev, struct iw_request_info *info,
  1516. struct iw_point *dwrq, char *extra)
  1517. {
  1518. u32 oid = dwrq->flags;
  1519. return mgt_set_request(netdev_priv(ndev), oid, 0, extra);
  1520. }
  1521. void
  1522. prism54_acl_init(struct islpci_acl *acl)
  1523. {
  1524. mutex_init(&acl->lock);
  1525. INIT_LIST_HEAD(&acl->mac_list);
  1526. acl->size = 0;
  1527. acl->policy = MAC_POLICY_OPEN;
  1528. }
  1529. static void
  1530. prism54_clear_mac(struct islpci_acl *acl)
  1531. {
  1532. struct list_head *ptr, *next;
  1533. struct mac_entry *entry;
  1534. mutex_lock(&acl->lock);
  1535. if (acl->size == 0) {
  1536. mutex_unlock(&acl->lock);
  1537. return;
  1538. }
  1539. for (ptr = acl->mac_list.next, next = ptr->next;
  1540. ptr != &acl->mac_list; ptr = next, next = ptr->next) {
  1541. entry = list_entry(ptr, struct mac_entry, _list);
  1542. list_del(ptr);
  1543. kfree(entry);
  1544. }
  1545. acl->size = 0;
  1546. mutex_unlock(&acl->lock);
  1547. }
  1548. void
  1549. prism54_acl_clean(struct islpci_acl *acl)
  1550. {
  1551. prism54_clear_mac(acl);
  1552. }
  1553. static int
  1554. prism54_add_mac(struct net_device *ndev, struct iw_request_info *info,
  1555. struct sockaddr *awrq, char *extra)
  1556. {
  1557. islpci_private *priv = netdev_priv(ndev);
  1558. struct islpci_acl *acl = &priv->acl;
  1559. struct mac_entry *entry;
  1560. struct sockaddr *addr = (struct sockaddr *) extra;
  1561. if (addr->sa_family != ARPHRD_ETHER)
  1562. return -EOPNOTSUPP;
  1563. entry = kmalloc(sizeof (struct mac_entry), GFP_KERNEL);
  1564. if (entry == NULL)
  1565. return -ENOMEM;
  1566. memcpy(entry->addr, addr->sa_data, ETH_ALEN);
  1567. if (mutex_lock_interruptible(&acl->lock)) {
  1568. kfree(entry);
  1569. return -ERESTARTSYS;
  1570. }
  1571. list_add_tail(&entry->_list, &acl->mac_list);
  1572. acl->size++;
  1573. mutex_unlock(&acl->lock);
  1574. return 0;
  1575. }
  1576. static int
  1577. prism54_del_mac(struct net_device *ndev, struct iw_request_info *info,
  1578. struct sockaddr *awrq, char *extra)
  1579. {
  1580. islpci_private *priv = netdev_priv(ndev);
  1581. struct islpci_acl *acl = &priv->acl;
  1582. struct mac_entry *entry;
  1583. struct sockaddr *addr = (struct sockaddr *) extra;
  1584. if (addr->sa_family != ARPHRD_ETHER)
  1585. return -EOPNOTSUPP;
  1586. if (mutex_lock_interruptible(&acl->lock))
  1587. return -ERESTARTSYS;
  1588. list_for_each_entry(entry, &acl->mac_list, _list) {
  1589. if (memcmp(entry->addr, addr->sa_data, ETH_ALEN) == 0) {
  1590. list_del(&entry->_list);
  1591. acl->size--;
  1592. kfree(entry);
  1593. mutex_unlock(&acl->lock);
  1594. return 0;
  1595. }
  1596. }
  1597. mutex_unlock(&acl->lock);
  1598. return -EINVAL;
  1599. }
  1600. static int
  1601. prism54_get_mac(struct net_device *ndev, struct iw_request_info *info,
  1602. struct iw_point *dwrq, char *extra)
  1603. {
  1604. islpci_private *priv = netdev_priv(ndev);
  1605. struct islpci_acl *acl = &priv->acl;
  1606. struct mac_entry *entry;
  1607. struct sockaddr *dst = (struct sockaddr *) extra;
  1608. dwrq->length = 0;
  1609. if (mutex_lock_interruptible(&acl->lock))
  1610. return -ERESTARTSYS;
  1611. list_for_each_entry(entry, &acl->mac_list, _list) {
  1612. memcpy(dst->sa_data, entry->addr, ETH_ALEN);
  1613. dst->sa_family = ARPHRD_ETHER;
  1614. dwrq->length++;
  1615. dst++;
  1616. }
  1617. mutex_unlock(&acl->lock);
  1618. return 0;
  1619. }
  1620. /* Setting policy also clears the MAC acl, even if we don't change the default
  1621. * policy
  1622. */
  1623. static int
  1624. prism54_set_policy(struct net_device *ndev, struct iw_request_info *info,
  1625. __u32 * uwrq, char *extra)
  1626. {
  1627. islpci_private *priv = netdev_priv(ndev);
  1628. struct islpci_acl *acl = &priv->acl;
  1629. u32 mlmeautolevel;
  1630. prism54_clear_mac(acl);
  1631. if ((*uwrq < MAC_POLICY_OPEN) || (*uwrq > MAC_POLICY_REJECT))
  1632. return -EINVAL;
  1633. down_write(&priv->mib_sem);
  1634. acl->policy = *uwrq;
  1635. /* the ACL code needs an intermediate mlmeautolevel */
  1636. if ((priv->iw_mode == IW_MODE_MASTER) &&
  1637. (acl->policy != MAC_POLICY_OPEN))
  1638. mlmeautolevel = DOT11_MLME_INTERMEDIATE;
  1639. else
  1640. mlmeautolevel = CARD_DEFAULT_MLME_MODE;
  1641. if (priv->wpa)
  1642. mlmeautolevel = DOT11_MLME_EXTENDED;
  1643. mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
  1644. /* restart the card with our new policy */
  1645. if (mgt_commit(