PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/staging/ks7010/ks_wlan_net.c

http://github.com/mirrors/linux-2.6
C | 2669 lines | 2086 code | 365 blank | 218 comment | 393 complexity | 380d4310caf67dfad3a0058303a263f2 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for KeyStream 11b/g wireless LAN
  4. *
  5. * Copyright (C) 2005-2008 KeyStream Corp.
  6. * Copyright (C) 2009 Renesas Technology Corp.
  7. */
  8. #include <linux/atomic.h>
  9. #include <linux/completion.h>
  10. #include <linux/if_arp.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/timer.h>
  13. #include <linux/uaccess.h>
  14. static int wep_on_off;
  15. #define WEP_OFF 0
  16. #define WEP_ON_64BIT 1
  17. #define WEP_ON_128BIT 2
  18. #include "ks_wlan.h"
  19. #include "ks_hostif.h"
  20. #include "ks_wlan_ioctl.h"
  21. /* Include Wireless Extension definition and check version */
  22. #include <linux/wireless.h>
  23. #define WIRELESS_SPY /* enable iwspy support */
  24. #include <net/iw_handler.h> /* New driver API */
  25. /* Frequency list (map channels to frequencies) */
  26. static const long frequency_list[] = {
  27. 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  28. 2447, 2452, 2457, 2462, 2467, 2472, 2484
  29. };
  30. /* A few details needed for WEP (Wireless Equivalent Privacy) */
  31. #define MAX_KEY_SIZE 13 /* 128 (?) bits */
  32. #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
  33. struct wep_key {
  34. u16 len;
  35. u8 key[16]; /* 40-bit and 104-bit keys */
  36. };
  37. /*
  38. * function prototypes
  39. */
  40. static int ks_wlan_open(struct net_device *dev);
  41. static void ks_wlan_tx_timeout(struct net_device *dev, unsigned int txqueue);
  42. static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev);
  43. static int ks_wlan_close(struct net_device *dev);
  44. static void ks_wlan_set_rx_mode(struct net_device *dev);
  45. static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev);
  46. static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
  47. static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
  48. int cmd);
  49. static atomic_t update_phyinfo;
  50. static struct timer_list update_phyinfo_timer;
  51. static
  52. int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
  53. {
  54. struct iw_statistics *wstats = &priv->wstats;
  55. netdev_dbg(priv->net_dev, "in_interrupt = %ld\n", in_interrupt());
  56. if (priv->dev_state < DEVICE_STATE_READY)
  57. return -EBUSY; /* not finished initialize */
  58. if (atomic_read(&update_phyinfo))
  59. return -EPERM;
  60. /* The status */
  61. wstats->status = priv->reg.operation_mode; /* Operation mode */
  62. /* Signal quality and co. But where is the noise level ??? */
  63. hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
  64. /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
  65. if (!wait_for_completion_interruptible_timeout
  66. (&priv->confirm_wait, HZ / 2)) {
  67. netdev_dbg(priv->net_dev, "wait time out!!\n");
  68. }
  69. atomic_inc(&update_phyinfo);
  70. update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
  71. add_timer(&update_phyinfo_timer);
  72. return 0;
  73. }
  74. static
  75. void ks_wlan_update_phyinfo_timeout(struct timer_list *unused)
  76. {
  77. pr_debug("in_interrupt = %ld\n", in_interrupt());
  78. atomic_set(&update_phyinfo, 0);
  79. }
  80. int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
  81. unsigned int commit_flag)
  82. {
  83. hostif_sme_enqueue(priv, SME_STOP_REQUEST);
  84. if (commit_flag & SME_RTS)
  85. hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
  86. if (commit_flag & SME_FRAG)
  87. hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
  88. if (commit_flag & SME_WEP_INDEX)
  89. hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
  90. if (commit_flag & SME_WEP_VAL1)
  91. hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
  92. if (commit_flag & SME_WEP_VAL2)
  93. hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
  94. if (commit_flag & SME_WEP_VAL3)
  95. hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
  96. if (commit_flag & SME_WEP_VAL4)
  97. hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
  98. if (commit_flag & SME_WEP_FLAG)
  99. hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
  100. if (commit_flag & SME_RSN) {
  101. hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
  102. hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
  103. }
  104. if (commit_flag & SME_RSN_MULTICAST)
  105. hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
  106. if (commit_flag & SME_RSN_UNICAST)
  107. hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
  108. if (commit_flag & SME_RSN_AUTH)
  109. hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
  110. hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
  111. hostif_sme_enqueue(priv, SME_START_REQUEST);
  112. return 0;
  113. }
  114. /*
  115. * Initial Wireless Extension code for Ks_Wlannet driver by :
  116. * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
  117. * Conversion to new driver API by :
  118. * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
  119. * Javier also did a good amount of work here, adding some new extensions
  120. * and fixing my code. Let's just say that without him this code just
  121. * would not work at all... - Jean II
  122. */
  123. static int ks_wlan_get_name(struct net_device *dev,
  124. struct iw_request_info *info,
  125. union iwreq_data *cwrq,
  126. char *extra)
  127. {
  128. struct ks_wlan_private *priv = netdev_priv(dev);
  129. if (priv->sleep_mode == SLP_SLEEP)
  130. return -EPERM;
  131. /* for SLEEP MODE */
  132. if (priv->dev_state < DEVICE_STATE_READY)
  133. strcpy(cwrq->name, "NOT READY!");
  134. else if (priv->reg.phy_type == D_11B_ONLY_MODE)
  135. strcpy(cwrq->name, "IEEE 802.11b");
  136. else if (priv->reg.phy_type == D_11G_ONLY_MODE)
  137. strcpy(cwrq->name, "IEEE 802.11g");
  138. else
  139. strcpy(cwrq->name, "IEEE 802.11b/g");
  140. return 0;
  141. }
  142. static int ks_wlan_set_freq(struct net_device *dev,
  143. struct iw_request_info *info,
  144. union iwreq_data *fwrq, char *extra)
  145. {
  146. struct ks_wlan_private *priv = netdev_priv(dev);
  147. int channel;
  148. if (priv->sleep_mode == SLP_SLEEP)
  149. return -EPERM;
  150. /* for SLEEP MODE */
  151. /* If setting by frequency, convert to a channel */
  152. if ((fwrq->freq.e == 1) &&
  153. (fwrq->freq.m >= 241200000) && (fwrq->freq.m <= 248700000)) {
  154. int f = fwrq->freq.m / 100000;
  155. int c = 0;
  156. while ((c < 14) && (f != frequency_list[c]))
  157. c++;
  158. /* Hack to fall through... */
  159. fwrq->freq.e = 0;
  160. fwrq->freq.m = c + 1;
  161. }
  162. /* Setting by channel number */
  163. if ((fwrq->freq.m > 1000) || (fwrq->freq.e > 0))
  164. return -EOPNOTSUPP;
  165. channel = fwrq->freq.m;
  166. /* We should do a better check than that,
  167. * based on the card capability !!!
  168. */
  169. if ((channel < 1) || (channel > 14)) {
  170. netdev_dbg(dev, "%s: New channel value of %d is invalid!\n",
  171. dev->name, fwrq->freq.m);
  172. return -EINVAL;
  173. }
  174. /* Yes ! We can set it !!! */
  175. priv->reg.channel = (u8)(channel);
  176. priv->need_commit |= SME_MODE_SET;
  177. return -EINPROGRESS; /* Call commit handler */
  178. }
  179. static int ks_wlan_get_freq(struct net_device *dev,
  180. struct iw_request_info *info,
  181. union iwreq_data *fwrq, char *extra)
  182. {
  183. struct ks_wlan_private *priv = netdev_priv(dev);
  184. int f;
  185. if (priv->sleep_mode == SLP_SLEEP)
  186. return -EPERM;
  187. /* for SLEEP MODE */
  188. if (is_connect_status(priv->connect_status))
  189. f = (int)priv->current_ap.channel;
  190. else
  191. f = (int)priv->reg.channel;
  192. fwrq->freq.m = frequency_list[f - 1] * 100000;
  193. fwrq->freq.e = 1;
  194. return 0;
  195. }
  196. static int ks_wlan_set_essid(struct net_device *dev,
  197. struct iw_request_info *info,
  198. union iwreq_data *dwrq, char *extra)
  199. {
  200. struct ks_wlan_private *priv = netdev_priv(dev);
  201. size_t len;
  202. if (priv->sleep_mode == SLP_SLEEP)
  203. return -EPERM;
  204. /* for SLEEP MODE */
  205. /* Check if we asked for `any' */
  206. if (!dwrq->essid.flags) {
  207. /* Just send an empty SSID list */
  208. memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
  209. priv->reg.ssid.size = 0;
  210. } else {
  211. len = dwrq->essid.length;
  212. /* iwconfig uses nul termination in SSID.. */
  213. if (len > 0 && extra[len - 1] == '\0')
  214. len--;
  215. /* Check the size of the string */
  216. if (len > IW_ESSID_MAX_SIZE)
  217. return -EINVAL;
  218. /* Set the SSID */
  219. memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
  220. memcpy(priv->reg.ssid.body, extra, len);
  221. priv->reg.ssid.size = len;
  222. }
  223. /* Write it to the card */
  224. priv->need_commit |= SME_MODE_SET;
  225. ks_wlan_setup_parameter(priv, priv->need_commit);
  226. priv->need_commit = 0;
  227. return 0;
  228. }
  229. static int ks_wlan_get_essid(struct net_device *dev,
  230. struct iw_request_info *info,
  231. union iwreq_data *dwrq, char *extra)
  232. {
  233. struct ks_wlan_private *priv = netdev_priv(dev);
  234. if (priv->sleep_mode == SLP_SLEEP)
  235. return -EPERM;
  236. /* for SLEEP MODE */
  237. /* Note : if dwrq->flags != 0, we should
  238. * get the relevant SSID from the SSID list...
  239. */
  240. if (priv->reg.ssid.size != 0) {
  241. /* Get the current SSID */
  242. memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
  243. /* If none, we may want to get the one that was set */
  244. /* Push it out ! */
  245. dwrq->essid.length = priv->reg.ssid.size;
  246. dwrq->essid.flags = 1; /* active */
  247. } else {
  248. dwrq->essid.length = 0;
  249. dwrq->essid.flags = 0; /* ANY */
  250. }
  251. return 0;
  252. }
  253. static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
  254. union iwreq_data *awrq, char *extra)
  255. {
  256. struct ks_wlan_private *priv = netdev_priv(dev);
  257. if (priv->sleep_mode == SLP_SLEEP)
  258. return -EPERM;
  259. /* for SLEEP MODE */
  260. if (priv->reg.operation_mode != MODE_ADHOC &&
  261. priv->reg.operation_mode != MODE_INFRASTRUCTURE) {
  262. eth_zero_addr(priv->reg.bssid);
  263. return -EOPNOTSUPP;
  264. }
  265. ether_addr_copy(priv->reg.bssid, awrq->ap_addr.sa_data);
  266. if (is_valid_ether_addr((u8 *)priv->reg.bssid))
  267. priv->need_commit |= SME_MODE_SET;
  268. netdev_dbg(dev, "bssid = %pM\n", priv->reg.bssid);
  269. /* Write it to the card */
  270. if (priv->need_commit) {
  271. priv->need_commit |= SME_MODE_SET;
  272. return -EINPROGRESS; /* Call commit handler */
  273. }
  274. return 0;
  275. }
  276. static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
  277. union iwreq_data *awrq, char *extra)
  278. {
  279. struct ks_wlan_private *priv = netdev_priv(dev);
  280. if (priv->sleep_mode == SLP_SLEEP)
  281. return -EPERM;
  282. /* for SLEEP MODE */
  283. if (is_connect_status(priv->connect_status))
  284. ether_addr_copy(awrq->ap_addr.sa_data, priv->current_ap.bssid);
  285. else
  286. eth_zero_addr(awrq->ap_addr.sa_data);
  287. awrq->ap_addr.sa_family = ARPHRD_ETHER;
  288. return 0;
  289. }
  290. static int ks_wlan_set_nick(struct net_device *dev,
  291. struct iw_request_info *info,
  292. union iwreq_data *dwrq, char *extra)
  293. {
  294. struct ks_wlan_private *priv = netdev_priv(dev);
  295. if (priv->sleep_mode == SLP_SLEEP)
  296. return -EPERM;
  297. /* for SLEEP MODE */
  298. /* Check the size of the string */
  299. if (dwrq->data.length > 16 + 1)
  300. return -E2BIG;
  301. memset(priv->nick, 0, sizeof(priv->nick));
  302. memcpy(priv->nick, extra, dwrq->data.length);
  303. return -EINPROGRESS; /* Call commit handler */
  304. }
  305. static int ks_wlan_get_nick(struct net_device *dev,
  306. struct iw_request_info *info,
  307. union iwreq_data *dwrq, char *extra)
  308. {
  309. struct ks_wlan_private *priv = netdev_priv(dev);
  310. if (priv->sleep_mode == SLP_SLEEP)
  311. return -EPERM;
  312. /* for SLEEP MODE */
  313. strncpy(extra, priv->nick, 16);
  314. extra[16] = '\0';
  315. dwrq->data.length = strlen(extra) + 1;
  316. return 0;
  317. }
  318. static int ks_wlan_set_rate(struct net_device *dev,
  319. struct iw_request_info *info,
  320. union iwreq_data *vwrq, char *extra)
  321. {
  322. struct ks_wlan_private *priv = netdev_priv(dev);
  323. int i = 0;
  324. if (priv->sleep_mode == SLP_SLEEP)
  325. return -EPERM;
  326. /* for SLEEP MODE */
  327. if (priv->reg.phy_type == D_11B_ONLY_MODE) {
  328. if (vwrq->bitrate.fixed == 1) {
  329. switch (vwrq->bitrate.value) {
  330. case 11000000:
  331. case 5500000:
  332. priv->reg.rate_set.body[0] =
  333. (u8)(vwrq->bitrate.value / 500000);
  334. break;
  335. case 2000000:
  336. case 1000000:
  337. priv->reg.rate_set.body[0] =
  338. ((u8)(vwrq->bitrate.value / 500000)) |
  339. BASIC_RATE;
  340. break;
  341. default:
  342. return -EINVAL;
  343. }
  344. priv->reg.tx_rate = TX_RATE_FIXED;
  345. priv->reg.rate_set.size = 1;
  346. } else { /* vwrq->fixed == 0 */
  347. if (vwrq->bitrate.value > 0) {
  348. switch (vwrq->bitrate.value) {
  349. case 11000000:
  350. priv->reg.rate_set.body[3] =
  351. TX_RATE_11M;
  352. i++;
  353. /* fall through */
  354. case 5500000:
  355. priv->reg.rate_set.body[2] = TX_RATE_5M;
  356. i++;
  357. /* fall through */
  358. case 2000000:
  359. priv->reg.rate_set.body[1] =
  360. TX_RATE_2M | BASIC_RATE;
  361. i++;
  362. /* fall through */
  363. case 1000000:
  364. priv->reg.rate_set.body[0] =
  365. TX_RATE_1M | BASIC_RATE;
  366. i++;
  367. break;
  368. default:
  369. return -EINVAL;
  370. }
  371. priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
  372. priv->reg.rate_set.size = i;
  373. } else {
  374. priv->reg.rate_set.body[3] = TX_RATE_11M;
  375. priv->reg.rate_set.body[2] = TX_RATE_5M;
  376. priv->reg.rate_set.body[1] =
  377. TX_RATE_2M | BASIC_RATE;
  378. priv->reg.rate_set.body[0] =
  379. TX_RATE_1M | BASIC_RATE;
  380. priv->reg.tx_rate = TX_RATE_FULL_AUTO;
  381. priv->reg.rate_set.size = 4;
  382. }
  383. }
  384. } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
  385. if (vwrq->bitrate.fixed == 1) {
  386. switch (vwrq->bitrate.value) {
  387. case 54000000:
  388. case 48000000:
  389. case 36000000:
  390. case 18000000:
  391. case 9000000:
  392. priv->reg.rate_set.body[0] =
  393. (u8)(vwrq->bitrate.value / 500000);
  394. break;
  395. case 24000000:
  396. case 12000000:
  397. case 11000000:
  398. case 6000000:
  399. case 5500000:
  400. case 2000000:
  401. case 1000000:
  402. priv->reg.rate_set.body[0] =
  403. ((u8)(vwrq->bitrate.value / 500000)) |
  404. BASIC_RATE;
  405. break;
  406. default:
  407. return -EINVAL;
  408. }
  409. priv->reg.tx_rate = TX_RATE_FIXED;
  410. priv->reg.rate_set.size = 1;
  411. } else { /* vwrq->fixed == 0 */
  412. if (vwrq->bitrate.value > 0) {
  413. switch (vwrq->bitrate.value) {
  414. case 54000000:
  415. priv->reg.rate_set.body[11] =
  416. TX_RATE_54M;
  417. i++;
  418. /* fall through */
  419. case 48000000:
  420. priv->reg.rate_set.body[10] =
  421. TX_RATE_48M;
  422. i++;
  423. /* fall through */
  424. case 36000000:
  425. priv->reg.rate_set.body[9] =
  426. TX_RATE_36M;
  427. i++;
  428. /* fall through */
  429. case 24000000:
  430. case 18000000:
  431. case 12000000:
  432. case 11000000:
  433. case 9000000:
  434. case 6000000:
  435. if (vwrq->bitrate.value == 24000000) {
  436. priv->reg.rate_set.body[8] =
  437. TX_RATE_18M;
  438. i++;
  439. priv->reg.rate_set.body[7] =
  440. TX_RATE_9M;
  441. i++;
  442. priv->reg.rate_set.body[6] =
  443. TX_RATE_24M | BASIC_RATE;
  444. i++;
  445. priv->reg.rate_set.body[5] =
  446. TX_RATE_12M | BASIC_RATE;
  447. i++;
  448. priv->reg.rate_set.body[4] =
  449. TX_RATE_6M | BASIC_RATE;
  450. i++;
  451. priv->reg.rate_set.body[3] =
  452. TX_RATE_11M | BASIC_RATE;
  453. i++;
  454. } else if (vwrq->bitrate.value == 18000000) {
  455. priv->reg.rate_set.body[7] =
  456. TX_RATE_18M;
  457. i++;
  458. priv->reg.rate_set.body[6] =
  459. TX_RATE_9M;
  460. i++;
  461. priv->reg.rate_set.body[5] =
  462. TX_RATE_12M | BASIC_RATE;
  463. i++;
  464. priv->reg.rate_set.body[4] =
  465. TX_RATE_6M | BASIC_RATE;
  466. i++;
  467. priv->reg.rate_set.body[3] =
  468. TX_RATE_11M | BASIC_RATE;
  469. i++;
  470. } else if (vwrq->bitrate.value == 12000000) {
  471. priv->reg.rate_set.body[6] =
  472. TX_RATE_9M;
  473. i++;
  474. priv->reg.rate_set.body[5] =
  475. TX_RATE_12M | BASIC_RATE;
  476. i++;
  477. priv->reg.rate_set.body[4] =
  478. TX_RATE_6M | BASIC_RATE;
  479. i++;
  480. priv->reg.rate_set.body[3] =
  481. TX_RATE_11M | BASIC_RATE;
  482. i++;
  483. } else if (vwrq->bitrate.value == 11000000) {
  484. priv->reg.rate_set.body[5] =
  485. TX_RATE_9M;
  486. i++;
  487. priv->reg.rate_set.body[4] =
  488. TX_RATE_6M | BASIC_RATE;
  489. i++;
  490. priv->reg.rate_set.body[3] =
  491. TX_RATE_11M | BASIC_RATE;
  492. i++;
  493. } else if (vwrq->bitrate.value == 9000000) {
  494. priv->reg.rate_set.body[4] =
  495. TX_RATE_9M;
  496. i++;
  497. priv->reg.rate_set.body[3] =
  498. TX_RATE_6M | BASIC_RATE;
  499. i++;
  500. } else { /* vwrq->value == 6000000 */
  501. priv->reg.rate_set.body[3] =
  502. TX_RATE_6M | BASIC_RATE;
  503. i++;
  504. }
  505. /* fall through */
  506. case 5500000:
  507. priv->reg.rate_set.body[2] =
  508. TX_RATE_5M | BASIC_RATE;
  509. i++;
  510. /* fall through */
  511. case 2000000:
  512. priv->reg.rate_set.body[1] =
  513. TX_RATE_2M | BASIC_RATE;
  514. i++;
  515. /* fall through */
  516. case 1000000:
  517. priv->reg.rate_set.body[0] =
  518. TX_RATE_1M | BASIC_RATE;
  519. i++;
  520. break;
  521. default:
  522. return -EINVAL;
  523. }
  524. priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
  525. priv->reg.rate_set.size = i;
  526. } else {
  527. priv->reg.rate_set.body[11] = TX_RATE_54M;
  528. priv->reg.rate_set.body[10] = TX_RATE_48M;
  529. priv->reg.rate_set.body[9] = TX_RATE_36M;
  530. priv->reg.rate_set.body[8] = TX_RATE_18M;
  531. priv->reg.rate_set.body[7] = TX_RATE_9M;
  532. priv->reg.rate_set.body[6] =
  533. TX_RATE_24M | BASIC_RATE;
  534. priv->reg.rate_set.body[5] =
  535. TX_RATE_12M | BASIC_RATE;
  536. priv->reg.rate_set.body[4] =
  537. TX_RATE_6M | BASIC_RATE;
  538. priv->reg.rate_set.body[3] =
  539. TX_RATE_11M | BASIC_RATE;
  540. priv->reg.rate_set.body[2] =
  541. TX_RATE_5M | BASIC_RATE;
  542. priv->reg.rate_set.body[1] =
  543. TX_RATE_2M | BASIC_RATE;
  544. priv->reg.rate_set.body[0] =
  545. TX_RATE_1M | BASIC_RATE;
  546. priv->reg.tx_rate = TX_RATE_FULL_AUTO;
  547. priv->reg.rate_set.size = 12;
  548. }
  549. }
  550. }
  551. priv->need_commit |= SME_MODE_SET;
  552. return -EINPROGRESS; /* Call commit handler */
  553. }
  554. static int ks_wlan_get_rate(struct net_device *dev,
  555. struct iw_request_info *info,
  556. union iwreq_data *vwrq, char *extra)
  557. {
  558. struct ks_wlan_private *priv = netdev_priv(dev);
  559. netdev_dbg(dev, "in_interrupt = %ld update_phyinfo = %d\n",
  560. in_interrupt(), atomic_read(&update_phyinfo));
  561. if (priv->sleep_mode == SLP_SLEEP)
  562. return -EPERM;
  563. /* for SLEEP MODE */
  564. if (!atomic_read(&update_phyinfo))
  565. ks_wlan_update_phy_information(priv);
  566. vwrq->bitrate.value = ((priv->current_rate) & RATE_MASK) * 500000;
  567. vwrq->bitrate.fixed = (priv->reg.tx_rate == TX_RATE_FIXED) ? 1 : 0;
  568. return 0;
  569. }
  570. static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
  571. union iwreq_data *vwrq, char *extra)
  572. {
  573. struct ks_wlan_private *priv = netdev_priv(dev);
  574. int rthr = vwrq->rts.value;
  575. if (priv->sleep_mode == SLP_SLEEP)
  576. return -EPERM;
  577. /* for SLEEP MODE */
  578. if (vwrq->rts.disabled)
  579. rthr = 2347;
  580. if ((rthr < 0) || (rthr > 2347))
  581. return -EINVAL;
  582. priv->reg.rts = rthr;
  583. priv->need_commit |= SME_RTS;
  584. return -EINPROGRESS; /* Call commit handler */
  585. }
  586. static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
  587. union iwreq_data *vwrq, char *extra)
  588. {
  589. struct ks_wlan_private *priv = netdev_priv(dev);
  590. if (priv->sleep_mode == SLP_SLEEP)
  591. return -EPERM;
  592. /* for SLEEP MODE */
  593. vwrq->rts.value = priv->reg.rts;
  594. vwrq->rts.disabled = (vwrq->rts.value >= 2347);
  595. vwrq->rts.fixed = 1;
  596. return 0;
  597. }
  598. static int ks_wlan_set_frag(struct net_device *dev,
  599. struct iw_request_info *info,
  600. union iwreq_data *vwrq, char *extra)
  601. {
  602. struct ks_wlan_private *priv = netdev_priv(dev);
  603. int fthr = vwrq->frag.value;
  604. if (priv->sleep_mode == SLP_SLEEP)
  605. return -EPERM;
  606. /* for SLEEP MODE */
  607. if (vwrq->frag.disabled)
  608. fthr = 2346;
  609. if ((fthr < 256) || (fthr > 2346))
  610. return -EINVAL;
  611. fthr &= ~0x1; /* Get an even value - is it really needed ??? */
  612. priv->reg.fragment = fthr;
  613. priv->need_commit |= SME_FRAG;
  614. return -EINPROGRESS; /* Call commit handler */
  615. }
  616. static int ks_wlan_get_frag(struct net_device *dev,
  617. struct iw_request_info *info,
  618. union iwreq_data *vwrq, char *extra)
  619. {
  620. struct ks_wlan_private *priv = netdev_priv(dev);
  621. if (priv->sleep_mode == SLP_SLEEP)
  622. return -EPERM;
  623. /* for SLEEP MODE */
  624. vwrq->frag.value = priv->reg.fragment;
  625. vwrq->frag.disabled = (vwrq->frag.value >= 2346);
  626. vwrq->frag.fixed = 1;
  627. return 0;
  628. }
  629. static int ks_wlan_set_mode(struct net_device *dev,
  630. struct iw_request_info *info,
  631. union iwreq_data *uwrq, char *extra)
  632. {
  633. struct ks_wlan_private *priv = netdev_priv(dev);
  634. if (priv->sleep_mode == SLP_SLEEP)
  635. return -EPERM;
  636. if (uwrq->mode != IW_MODE_ADHOC &&
  637. uwrq->mode != IW_MODE_INFRA)
  638. return -EINVAL;
  639. priv->reg.operation_mode = (uwrq->mode == IW_MODE_ADHOC) ?
  640. MODE_ADHOC : MODE_INFRASTRUCTURE;
  641. priv->need_commit |= SME_MODE_SET;
  642. return -EINPROGRESS; /* Call commit handler */
  643. }
  644. static int ks_wlan_get_mode(struct net_device *dev,
  645. struct iw_request_info *info,
  646. union iwreq_data *uwrq, char *extra)
  647. {
  648. struct ks_wlan_private *priv = netdev_priv(dev);
  649. if (priv->sleep_mode == SLP_SLEEP)
  650. return -EPERM;
  651. /* If not managed, assume it's ad-hoc */
  652. uwrq->mode = (priv->reg.operation_mode == MODE_INFRASTRUCTURE) ?
  653. IW_MODE_INFRA : IW_MODE_ADHOC;
  654. return 0;
  655. }
  656. static int ks_wlan_set_encode(struct net_device *dev,
  657. struct iw_request_info *info,
  658. union iwreq_data *dwrq, char *extra)
  659. {
  660. struct ks_wlan_private *priv = netdev_priv(dev);
  661. struct iw_point *enc = &dwrq->encoding;
  662. struct wep_key key;
  663. int index = (enc->flags & IW_ENCODE_INDEX);
  664. if (priv->sleep_mode == SLP_SLEEP)
  665. return -EPERM;
  666. if (enc->length > MAX_KEY_SIZE)
  667. return -EINVAL;
  668. /* for SLEEP MODE */
  669. if ((index < 0) || (index > 4))
  670. return -EINVAL;
  671. index = (index == 0) ? priv->reg.wep_index : (index - 1);
  672. /* Is WEP supported ? */
  673. /* Basic checking: do we have a key to set ? */
  674. if (enc->length > 0) {
  675. key.len = (enc->length > MIN_KEY_SIZE) ?
  676. MAX_KEY_SIZE : MIN_KEY_SIZE;
  677. priv->reg.privacy_invoked = 0x01;
  678. priv->need_commit |= SME_WEP_FLAG;
  679. wep_on_off = (enc->length > MIN_KEY_SIZE) ?
  680. WEP_ON_128BIT : WEP_ON_64BIT;
  681. /* Check if the key is not marked as invalid */
  682. if (enc->flags & IW_ENCODE_NOKEY)
  683. return 0;
  684. /* Cleanup */
  685. memset(key.key, 0, MAX_KEY_SIZE);
  686. /* Copy the key in the driver */
  687. if (copy_from_user(key.key, enc->pointer, enc->length)) {
  688. key.len = 0;
  689. return -EFAULT;
  690. }
  691. /* Send the key to the card */
  692. priv->reg.wep_key[index].size = key.len;
  693. memcpy(&priv->reg.wep_key[index].val[0], &key.key[0],
  694. priv->reg.wep_key[index].size);
  695. priv->need_commit |= (SME_WEP_VAL1 << index);
  696. priv->reg.wep_index = index;
  697. priv->need_commit |= SME_WEP_INDEX;
  698. } else {
  699. if (enc->flags & IW_ENCODE_DISABLED) {
  700. priv->reg.wep_key[0].size = 0;
  701. priv->reg.wep_key[1].size = 0;
  702. priv->reg.wep_key[2].size = 0;
  703. priv->reg.wep_key[3].size = 0;
  704. priv->reg.privacy_invoked = 0x00;
  705. if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
  706. priv->need_commit |= SME_MODE_SET;
  707. priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
  708. wep_on_off = WEP_OFF;
  709. priv->need_commit |= SME_WEP_FLAG;
  710. } else {
  711. /* set_wep_key(priv, index, 0, 0, 1); xxx */
  712. if (priv->reg.wep_key[index].size == 0)
  713. return -EINVAL;
  714. priv->reg.wep_index = index;
  715. priv->need_commit |= SME_WEP_INDEX;
  716. }
  717. }
  718. /* Commit the changes if needed */
  719. if (enc->flags & IW_ENCODE_MODE)
  720. priv->need_commit |= SME_WEP_FLAG;
  721. if (enc->flags & IW_ENCODE_OPEN) {
  722. if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
  723. priv->need_commit |= SME_MODE_SET;
  724. priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
  725. } else if (enc->flags & IW_ENCODE_RESTRICTED) {
  726. if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM)
  727. priv->need_commit |= SME_MODE_SET;
  728. priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
  729. }
  730. if (priv->need_commit) {
  731. ks_wlan_setup_parameter(priv, priv->need_commit);
  732. priv->need_commit = 0;
  733. }
  734. return 0;
  735. }
  736. static int ks_wlan_get_encode(struct net_device *dev,
  737. struct iw_request_info *info,
  738. union iwreq_data *dwrq, char *extra)
  739. {
  740. struct ks_wlan_private *priv = netdev_priv(dev);
  741. struct iw_point *enc = &dwrq->encoding;
  742. int index = (enc->flags & IW_ENCODE_INDEX) - 1;
  743. if (priv->sleep_mode == SLP_SLEEP)
  744. return -EPERM;
  745. /* for SLEEP MODE */
  746. enc->flags = IW_ENCODE_DISABLED;
  747. /* Check encryption mode */
  748. switch (priv->reg.authenticate_type) {
  749. case AUTH_TYPE_OPEN_SYSTEM:
  750. enc->flags = IW_ENCODE_OPEN;
  751. break;
  752. case AUTH_TYPE_SHARED_KEY:
  753. enc->flags = IW_ENCODE_RESTRICTED;
  754. break;
  755. }
  756. /* Which key do we want ? -1 -> tx index */
  757. if ((index < 0) || (index >= 4))
  758. index = priv->reg.wep_index;
  759. if (priv->reg.privacy_invoked) {
  760. enc->flags &= ~IW_ENCODE_DISABLED;
  761. /* dwrq->flags |= IW_ENCODE_NOKEY; */
  762. }
  763. enc->flags |= index + 1;
  764. /* Copy the key to the user buffer */
  765. if (index >= 0 && index < 4) {
  766. enc->length = (priv->reg.wep_key[index].size <= 16) ?
  767. priv->reg.wep_key[index].size : 0;
  768. memcpy(extra, priv->reg.wep_key[index].val, enc->length);
  769. }
  770. return 0;
  771. }
  772. static int ks_wlan_get_range(struct net_device *dev,
  773. struct iw_request_info *info,
  774. union iwreq_data *dwrq, char *extra)
  775. {
  776. struct ks_wlan_private *priv = netdev_priv(dev);
  777. struct iw_range *range = (struct iw_range *)extra;
  778. int i, k;
  779. if (priv->sleep_mode == SLP_SLEEP)
  780. return -EPERM;
  781. /* for SLEEP MODE */
  782. dwrq->data.length = sizeof(struct iw_range);
  783. memset(range, 0, sizeof(*range));
  784. range->min_nwid = 0x0000;
  785. range->max_nwid = 0x0000;
  786. range->num_channels = 14;
  787. /* Should be based on cap_rid.country to give only
  788. * what the current card support
  789. */
  790. k = 0;
  791. for (i = 0; i < 13; i++) { /* channel 1 -- 13 */
  792. range->freq[k].i = i + 1; /* List index */
  793. range->freq[k].m = frequency_list[i] * 100000;
  794. range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
  795. }
  796. range->num_frequency = k;
  797. if (priv->reg.phy_type == D_11B_ONLY_MODE ||
  798. priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */
  799. range->freq[13].i = 14; /* List index */
  800. range->freq[13].m = frequency_list[13] * 100000;
  801. range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
  802. range->num_frequency = 14;
  803. }
  804. /* Hum... Should put the right values there */
  805. range->max_qual.qual = 100;
  806. range->max_qual.level = 256 - 128; /* 0 dBm? */
  807. range->max_qual.noise = 256 - 128;
  808. range->sensitivity = 1;
  809. if (priv->reg.phy_type == D_11B_ONLY_MODE) {
  810. range->bitrate[0] = 1e6;
  811. range->bitrate[1] = 2e6;
  812. range->bitrate[2] = 5.5e6;
  813. range->bitrate[3] = 11e6;
  814. range->num_bitrates = 4;
  815. } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
  816. range->bitrate[0] = 1e6;
  817. range->bitrate[1] = 2e6;
  818. range->bitrate[2] = 5.5e6;
  819. range->bitrate[3] = 11e6;
  820. range->bitrate[4] = 6e6;
  821. range->bitrate[5] = 9e6;
  822. range->bitrate[6] = 12e6;
  823. if (IW_MAX_BITRATES < 9) {
  824. range->bitrate[7] = 54e6;
  825. range->num_bitrates = 8;
  826. } else {
  827. range->bitrate[7] = 18e6;
  828. range->bitrate[8] = 24e6;
  829. range->bitrate[9] = 36e6;
  830. range->bitrate[10] = 48e6;
  831. range->bitrate[11] = 54e6;
  832. range->num_bitrates = 12;
  833. }
  834. }
  835. /* Set an indication of the max TCP throughput
  836. * in bit/s that we can expect using this interface.
  837. * May be use for QoS stuff... Jean II
  838. */
  839. if (i > 2)
  840. range->throughput = 5000 * 1000;
  841. else
  842. range->throughput = 1500 * 1000;
  843. range->min_rts = 0;
  844. range->max_rts = 2347;
  845. range->min_frag = 256;
  846. range->max_frag = 2346;
  847. range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
  848. range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
  849. range->num_encoding_sizes = 2;
  850. range->max_encoding_tokens = 4;
  851. /* power management not support */
  852. range->pmp_flags = IW_POWER_ON;
  853. range->pmt_flags = IW_POWER_ON;
  854. range->pm_capa = 0;
  855. /* Transmit Power - values are in dBm( or mW) */
  856. range->txpower[0] = -256;
  857. range->num_txpower = 1;
  858. range->txpower_capa = IW_TXPOW_DBM;
  859. /* range->txpower_capa = IW_TXPOW_MWATT; */
  860. range->we_version_source = 21;
  861. range->we_version_compiled = WIRELESS_EXT;
  862. range->retry_capa = IW_RETRY_ON;
  863. range->retry_flags = IW_RETRY_ON;
  864. range->r_time_flags = IW_RETRY_ON;
  865. /* Experimental measurements - boundary 11/5.5 Mb/s
  866. *
  867. * Note : with or without the (local->rssi), results
  868. * are somewhat different. - Jean II
  869. */
  870. range->avg_qual.qual = 50;
  871. range->avg_qual.level = 186; /* -70 dBm */
  872. range->avg_qual.noise = 0;
  873. /* Event capability (kernel + driver) */
  874. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  875. IW_EVENT_CAPA_MASK(SIOCGIWAP) |
  876. IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
  877. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  878. range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
  879. IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
  880. /* encode extension (WPA) capability */
  881. range->enc_capa = (IW_ENC_CAPA_WPA |
  882. IW_ENC_CAPA_WPA2 |
  883. IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
  884. return 0;
  885. }
  886. static int ks_wlan_set_power(struct net_device *dev,
  887. struct iw_request_info *info,
  888. union iwreq_data *vwrq, char *extra)
  889. {
  890. struct ks_wlan_private *priv = netdev_priv(dev);
  891. if (priv->sleep_mode == SLP_SLEEP)
  892. return -EPERM;
  893. if (vwrq->power.disabled) {
  894. priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
  895. } else {
  896. if (priv->reg.operation_mode != MODE_INFRASTRUCTURE)
  897. return -EINVAL;
  898. priv->reg.power_mgmt = POWER_MGMT_SAVE1;
  899. }
  900. hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
  901. return 0;
  902. }
  903. static int ks_wlan_get_power(struct net_device *dev,
  904. struct iw_request_info *info,
  905. union iwreq_data *vwrq, char *extra)
  906. {
  907. struct ks_wlan_private *priv = netdev_priv(dev);
  908. if (priv->sleep_mode == SLP_SLEEP)
  909. return -EPERM;
  910. /* for SLEEP MODE */
  911. vwrq->power.disabled = (priv->reg.power_mgmt <= 0);
  912. return 0;
  913. }
  914. static int ks_wlan_get_iwstats(struct net_device *dev,
  915. struct iw_request_info *info,
  916. union iwreq_data *vwrq, char *extra)
  917. {
  918. struct ks_wlan_private *priv = netdev_priv(dev);
  919. if (priv->sleep_mode == SLP_SLEEP)
  920. return -EPERM;
  921. /* for SLEEP MODE */
  922. vwrq->qual.qual = 0; /* not supported */
  923. vwrq->qual.level = priv->wstats.qual.level;
  924. vwrq->qual.noise = 0; /* not supported */
  925. vwrq->qual.updated = 0;
  926. return 0;
  927. }
  928. /* Note : this is deprecated in favor of IWSCAN */
  929. static int ks_wlan_get_aplist(struct net_device *dev,
  930. struct iw_request_info *info,
  931. union iwreq_data *dwrq, char *extra)
  932. {
  933. struct ks_wlan_private *priv = netdev_priv(dev);
  934. struct sockaddr *address = (struct sockaddr *)extra;
  935. struct iw_quality qual[LOCAL_APLIST_MAX];
  936. int i;
  937. if (priv->sleep_mode == SLP_SLEEP)
  938. return -EPERM;
  939. /* for SLEEP MODE */
  940. for (i = 0; i < priv->aplist.size; i++) {
  941. ether_addr_copy(address[i].sa_data, priv->aplist.ap[i].bssid);
  942. address[i].sa_family = ARPHRD_ETHER;
  943. qual[i].level = 256 - priv->aplist.ap[i].rssi;
  944. qual[i].qual = priv->aplist.ap[i].sq;
  945. qual[i].noise = 0; /* invalid noise value */
  946. qual[i].updated = 7;
  947. }
  948. if (i) {
  949. dwrq->data.flags = 1; /* Should be define'd */
  950. memcpy(extra + sizeof(struct sockaddr) * i,
  951. &qual, sizeof(struct iw_quality) * i);
  952. }
  953. dwrq->data.length = i;
  954. return 0;
  955. }
  956. static int ks_wlan_set_scan(struct net_device *dev,
  957. struct iw_request_info *info,
  958. union iwreq_data *wrqu, char *extra)
  959. {
  960. struct ks_wlan_private *priv = netdev_priv(dev);
  961. struct iw_scan_req *req = NULL;
  962. if (priv->sleep_mode == SLP_SLEEP)
  963. return -EPERM;
  964. /* for SLEEP MODE */
  965. /* specified SSID SCAN */
  966. if (wrqu->data.length == sizeof(struct iw_scan_req) &&
  967. wrqu->data.flags & IW_SCAN_THIS_ESSID) {
  968. req = (struct iw_scan_req *)extra;
  969. priv->scan_ssid_len = req->essid_len;
  970. memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
  971. } else {
  972. priv->scan_ssid_len = 0;
  973. }
  974. priv->sme_i.sme_flag |= SME_AP_SCAN;
  975. hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
  976. /* At this point, just return to the user. */
  977. return 0;
  978. }
  979. static char *ks_wlan_add_leader_event(const char *rsn_leader, char *end_buf,
  980. char *current_ev, struct rsn_ie *rsn,
  981. struct iw_event *iwe,
  982. struct iw_request_info *info)
  983. {
  984. char buffer[RSN_IE_BODY_MAX * 2 + 30];
  985. char *pbuf;
  986. int i;
  987. pbuf = &buffer[0];
  988. memset(iwe, 0, sizeof(*iwe));
  989. iwe->cmd = IWEVCUSTOM;
  990. memcpy(buffer, rsn_leader, sizeof(rsn_leader) - 1);
  991. iwe->u.data.length += sizeof(rsn_leader) - 1;
  992. pbuf += sizeof(rsn_leader) - 1;
  993. pbuf += sprintf(pbuf, "%02x", rsn->id);
  994. pbuf += sprintf(pbuf, "%02x", rsn->size);
  995. iwe->u.data.length += 4;
  996. for (i = 0; i < rsn->size; i++)
  997. pbuf += sprintf(pbuf, "%02x", rsn->body[i]);
  998. iwe->u.data.length += rsn->size * 2;
  999. return iwe_stream_add_point(info, current_ev, end_buf, iwe, &buffer[0]);
  1000. }
  1001. /*
  1002. * Translate scan data returned from the card to a card independent
  1003. * format that the Wireless Tools will understand - Jean II
  1004. */
  1005. static inline char *ks_wlan_translate_scan(struct net_device *dev,
  1006. struct iw_request_info *info,
  1007. char *current_ev, char *end_buf,
  1008. struct local_ap *ap)
  1009. {
  1010. /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
  1011. static const char rsn_leader[] = "rsn_ie=";
  1012. static const char wpa_leader[] = "wpa_ie=";
  1013. struct iw_event iwe; /* Temporary buffer */
  1014. u16 capabilities;
  1015. char *current_val; /* For rates */
  1016. int i;
  1017. /* First entry *MUST* be the AP MAC address */
  1018. iwe.cmd = SIOCGIWAP;
  1019. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1020. ether_addr_copy(iwe.u.ap_addr.sa_data, ap->bssid);
  1021. current_ev = iwe_stream_add_event(info, current_ev,
  1022. end_buf, &iwe, IW_EV_ADDR_LEN);
  1023. /* Other entries will be displayed in the order we give them */
  1024. /* Add the ESSID */
  1025. iwe.u.data.length = ap->ssid.size;
  1026. if (iwe.u.data.length > 32)
  1027. iwe.u.data.length = 32;
  1028. iwe.cmd = SIOCGIWESSID;
  1029. iwe.u.data.flags = 1;
  1030. current_ev = iwe_stream_add_point(info, current_ev,
  1031. end_buf, &iwe, ap->ssid.body);
  1032. /* Add mode */
  1033. iwe.cmd = SIOCGIWMODE;
  1034. capabilities = ap->capability;
  1035. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  1036. iwe.u.mode = (capabilities & WLAN_CAPABILITY_ESS) ?
  1037. IW_MODE_INFRA : IW_MODE_ADHOC;
  1038. current_ev = iwe_stream_add_event(info, current_ev,
  1039. end_buf, &iwe, IW_EV_UINT_LEN);
  1040. }
  1041. /* Add frequency */
  1042. iwe.cmd = SIOCGIWFREQ;
  1043. iwe.u.freq.m = ap->channel;
  1044. iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
  1045. iwe.u.freq.e = 1;
  1046. current_ev = iwe_stream_add_event(info, current_ev,
  1047. end_buf, &iwe, IW_EV_FREQ_LEN);
  1048. /* Add quality statistics */
  1049. iwe.cmd = IWEVQUAL;
  1050. iwe.u.qual.level = 256 - ap->rssi;
  1051. iwe.u.qual.qual = ap->sq;
  1052. iwe.u.qual.noise = 0; /* invalid noise value */
  1053. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1054. &iwe, IW_EV_QUAL_LEN);
  1055. /* Add encryption capability */
  1056. iwe.cmd = SIOCGIWENCODE;
  1057. iwe.u.data.flags = (capabilities & WLAN_CAPABILITY_PRIVACY) ?
  1058. (IW_ENCODE_ENABLED | IW_ENCODE_NOKEY) :
  1059. IW_ENCODE_DISABLED;
  1060. iwe.u.data.length = 0;
  1061. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1062. &iwe, ap->ssid.body);
  1063. /*
  1064. * Rate : stuffing multiple values in a single event
  1065. * require a bit more of magic - Jean II
  1066. */
  1067. current_val = current_ev + IW_EV_LCP_LEN;
  1068. iwe.cmd = SIOCGIWRATE;
  1069. /* These two flags are ignored... */
  1070. iwe.u.bitrate.fixed = 0;
  1071. iwe.u.bitrate.disabled = 0;
  1072. /* Max 16 values */
  1073. for (i = 0; i < 16; i++) {
  1074. /* NULL terminated */
  1075. if (i >= ap->rate_set.size)
  1076. break;
  1077. /* Bit rate given in 500 kb/s units (+ 0x80) */
  1078. iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
  1079. /* Add new value to event */
  1080. current_val = iwe_stream_add_value(info, current_ev,
  1081. current_val, end_buf, &iwe,
  1082. IW_EV_PARAM_LEN);
  1083. }
  1084. /* Check if we added any event */
  1085. if ((current_val - current_ev) > IW_EV_LCP_LEN)
  1086. current_ev = current_val;
  1087. if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0)
  1088. current_ev = ks_wlan_add_leader_event(rsn_leader, end_buf,
  1089. current_ev, &ap->rsn_ie,
  1090. &iwe, info);
  1091. if (ap->wpa_ie.id == WPA_INFO_ELEM_ID && ap->wpa_ie.size != 0)
  1092. current_ev = ks_wlan_add_leader_event(wpa_leader, end_buf,
  1093. current_ev, &ap->wpa_ie,
  1094. &iwe, info);
  1095. /*
  1096. * The other data in the scan result are not really
  1097. * interesting, so for now drop it - Jean II
  1098. */
  1099. return current_ev;
  1100. }
  1101. static int ks_wlan_get_scan(struct net_device *dev,
  1102. struct iw_request_info *info,
  1103. union iwreq_data *dwrq, char *extra)
  1104. {
  1105. struct ks_wlan_private *priv = netdev_priv(dev);
  1106. int i;
  1107. char *current_ev = extra;
  1108. if (priv->sleep_mode == SLP_SLEEP)
  1109. return -EPERM;
  1110. /* for SLEEP MODE */
  1111. if (priv->sme_i.sme_flag & SME_AP_SCAN)
  1112. return -EAGAIN;
  1113. if (priv->aplist.size == 0) {
  1114. /* Client error, no scan results...
  1115. * The caller need to restart the scan.
  1116. */
  1117. return -ENODATA;
  1118. }
  1119. /* Read and parse all entries */
  1120. for (i = 0; i < priv->aplist.size; i++) {
  1121. if ((extra + dwrq->data.length) - current_ev <= IW_EV_ADDR_LEN) {
  1122. dwrq->data.length = 0;
  1123. return -E2BIG;
  1124. }
  1125. /* Translate to WE format this entry */
  1126. current_ev = ks_wlan_translate_scan(dev, info, current_ev,
  1127. extra + dwrq->data.length,
  1128. &priv->aplist.ap[i]);
  1129. }
  1130. /* Length of data */
  1131. dwrq->data.length = (current_ev - extra);
  1132. dwrq->data.flags = 0;
  1133. return 0;
  1134. }
  1135. /* called after a bunch of SET operations */
  1136. static int ks_wlan_config_commit(struct net_device *dev,
  1137. struct iw_request_info *info,
  1138. union iwreq_data *zwrq,
  1139. char *extra)
  1140. {
  1141. struct ks_wlan_private *priv = netdev_priv(dev);
  1142. if (!priv->need_commit)
  1143. return 0;
  1144. ks_wlan_setup_parameter(priv, priv->need_commit);
  1145. priv->need_commit = 0;
  1146. return 0;
  1147. }
  1148. /* set association ie params */
  1149. static int ks_wlan_set_genie(struct net_device *dev,
  1150. struct iw_request_info *info,
  1151. union iwreq_data *dwrq, char *extra)
  1152. {
  1153. struct ks_wlan_private *priv = netdev_priv(dev);
  1154. if (priv->sleep_mode == SLP_SLEEP)
  1155. return -EPERM;
  1156. /* for SLEEP MODE */
  1157. return 0;
  1158. // return -EOPNOTSUPP;
  1159. }
  1160. static int ks_wlan_set_auth_mode(struct net_device *dev,
  1161. struct iw_request_info *info,
  1162. union iwreq_data *vwrq, char *extra)
  1163. {
  1164. struct ks_wlan_private *priv = netdev_priv(dev);
  1165. struct iw_param *param = &vwrq->param;
  1166. int index = (param->flags & IW_AUTH_INDEX);
  1167. int value = param->value;
  1168. if (priv->sleep_mode == SLP_SLEEP)
  1169. return -EPERM;
  1170. /* for SLEEP MODE */
  1171. switch (index) {
  1172. case IW_AUTH_WPA_VERSION: /* 0 */
  1173. switch (value) {
  1174. case IW_AUTH_WPA_VERSION_DISABLED:
  1175. priv->wpa.version = value;
  1176. if (priv->wpa.rsn_enabled)
  1177. priv->wpa.rsn_enabled = false;
  1178. priv->need_commit |= SME_RSN;
  1179. break;
  1180. case IW_AUTH_WPA_VERSION_WPA:
  1181. case IW_AUTH_WPA_VERSION_WPA2:
  1182. priv->wpa.version = value;
  1183. if (!(priv->wpa.rsn_enabled))
  1184. priv->wpa.rsn_enabled = true;
  1185. priv->need_commit |= SME_RSN;
  1186. break;
  1187. default:
  1188. return -EOPNOTSUPP;
  1189. }
  1190. break;
  1191. case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
  1192. switch (value) {
  1193. case IW_AUTH_CIPHER_NONE:
  1194. if (priv->reg.privacy_invoked) {
  1195. priv->reg.privacy_invoked = 0x00;
  1196. priv->need_commit |= SME_WEP_FLAG;
  1197. }
  1198. break;
  1199. case IW_AUTH_CIPHER_WEP40:
  1200. case IW_AUTH_CIPHER_TKIP:
  1201. case IW_AUTH_CIPHER_CCMP:
  1202. case IW_AUTH_CIPHER_WEP104:
  1203. if (!priv->reg.privacy_invoked) {
  1204. priv->reg.privacy_invoked = 0x01;
  1205. priv->need_commit |= SME_WEP_FLAG;
  1206. }
  1207. priv->wpa.pairwise_suite = value;
  1208. priv->need_commit |= SME_RSN_UNICAST;
  1209. break;
  1210. default:
  1211. return -EOPNOTSUPP;
  1212. }
  1213. break;
  1214. case IW_AUTH_CIPHER_GROUP: /* 2 */
  1215. switch (value) {
  1216. case IW_AUTH_CIPHER_NONE:
  1217. if (priv->reg.privacy_invoked) {
  1218. priv->reg.privacy_invoked = 0x00;
  1219. priv->need_commit |= SME_WEP_FLAG;
  1220. }
  1221. break;
  1222. case IW_AUTH_CIPHER_WEP40:
  1223. case IW_AUTH_CIPHER_TKIP:
  1224. case IW_AUTH_CIPHER_CCMP:
  1225. case IW_AUTH_CIPHER_WEP104:
  1226. if (!priv->reg.privacy_invoked) {
  1227. priv->reg.privacy_invoked = 0x01;
  1228. priv->need_commit |= SME_WEP_FLAG;
  1229. }
  1230. priv->wpa.group_suite = value;
  1231. priv->need_commit |= SME_RSN_MULTICAST;
  1232. break;
  1233. default:
  1234. return -EOPNOTSUPP;
  1235. }
  1236. break;
  1237. case IW_AUTH_KEY_MGMT: /* 3 */
  1238. switch (value) {
  1239. case IW_AUTH_KEY_MGMT_802_1X:
  1240. case IW_AUTH_KEY_MGMT_PSK:
  1241. case 0: /* NONE or 802_1X_NO_WPA */
  1242. case 4: /* WPA_NONE */
  1243. priv->wpa.key_mgmt_suite = value;
  1244. priv->need_commit |= SME_RSN_AUTH;
  1245. break;
  1246. default:
  1247. return -EOPNOTSUPP;
  1248. }
  1249. break;
  1250. case IW_AUTH_80211_AUTH_ALG: /* 6 */
  1251. switch (value) {
  1252. case IW_AUTH_ALG_OPEN_SYSTEM:
  1253. priv->wpa.auth_alg = value;
  1254. priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
  1255. break;
  1256. case IW_AUTH_ALG_SHARED_KEY:
  1257. priv->wpa.auth_alg = value;
  1258. priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
  1259. break;
  1260. case IW_AUTH_ALG_LEAP:
  1261. default:
  1262. return -EOPNOTSUPP;
  1263. }
  1264. priv->need_commit |= SME_MODE_SET;
  1265. break;
  1266. case IW_AUTH_WPA_ENABLED: /* 7 */
  1267. priv->wpa.wpa_enabled = value;
  1268. break;
  1269. case IW_AUTH_PRIVACY_INVOKED: /* 10 */
  1270. if ((value && !priv->reg.privacy_invoked) ||
  1271. (!value && priv->reg.privacy_invoked)) {
  1272. priv->reg.privacy_invoked = value ? 0x01 : 0x00;
  1273. priv->need_commit |= SME_WEP_FLAG;
  1274. }
  1275. break;
  1276. case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
  1277. case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
  1278. case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
  1279. case IW_AUTH_ROAMING_CONTROL: /* 9 */
  1280. default:
  1281. break;
  1282. }
  1283. /* return -EINPROGRESS; */
  1284. if (priv->need_commit) {
  1285. ks_wlan_setup_parameter(priv, priv->need_commit);
  1286. priv->need_commit = 0;
  1287. }
  1288. return 0;
  1289. }
  1290. static int ks_wlan_get_auth_mode(struct net_device *dev,
  1291. struct iw_request_info *info,
  1292. union iwreq_data *vwrq, char *extra)
  1293. {
  1294. struct ks_wlan_private *priv = netdev_priv(dev);
  1295. struct iw_param *param = &vwrq->param;
  1296. int index = (param->flags & IW_AUTH_INDEX);
  1297. if (priv->sleep_mode == SLP_SLEEP)
  1298. return -EPERM;
  1299. /* for SLEEP MODE */
  1300. /* WPA (not used ?? wpa_supplicant) */
  1301. switch (index) {
  1302. case IW_AUTH_WPA_VERSION:
  1303. param->value = priv->wpa.version;
  1304. break;
  1305. case IW_AUTH_CIPHER_PAIRWISE:
  1306. param->value = priv->wpa.pairwise_suite;
  1307. break;
  1308. case IW_AUTH_CIPHER_GROUP:
  1309. param->value = priv->wpa.group_suite;
  1310. break;
  1311. case IW_AUTH_KEY_MGMT:
  1312. param->value = priv->wpa.key_mgmt_suite;
  1313. break;
  1314. case IW_AUTH_80211_AUTH_ALG:
  1315. param->value = priv->wpa.auth_alg;
  1316. break;
  1317. case IW_AUTH_WPA_ENABLED:
  1318. param->value = priv->wpa.rsn_enabled;
  1319. break;
  1320. case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
  1321. case IW_AUTH_TKIP_COUNTERMEASURES:
  1322. case IW_AUTH_DROP_UNENCRYPTED:
  1323. default:
  1324. /* return -EOPNOTSUPP; */
  1325. break;
  1326. }
  1327. return 0;
  1328. }
  1329. /* set encoding token & mode (WPA)*/
  1330. static int ks_wlan_set_encode_ext(struct net_device *dev,
  1331. struct iw_request_info *info,
  1332. union iwreq_data *dwrq, char *extra)
  1333. {
  1334. struct ks_wlan_private *priv = netdev_priv(dev);
  1335. struct iw_encode_ext *enc;
  1336. int index = dwrq->encoding.flags & IW_ENCODE_INDEX;
  1337. unsigned int commit = 0;
  1338. struct wpa_key *key;
  1339. enc = (struct iw_encode_ext *)extra;
  1340. if (!enc)
  1341. return -EINVAL;
  1342. if (priv->sleep_mode == SLP_SLEEP)
  1343. return -EPERM;
  1344. /* for SLEEP MODE */
  1345. if (index < 1 || index > 4)
  1346. return -EINVAL;
  1347. index--;
  1348. key = &priv->wpa.key[index];
  1349. if (dwrq->encoding.flags & IW_ENCODE_DISABLED)
  1350. key->key_len = 0;
  1351. key->ext_flags = enc->ext_flags;
  1352. if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  1353. priv->wpa.txkey = index;
  1354. commit |= SME_WEP_INDEX;
  1355. } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
  1356. memcpy(&key->rx_seq[0], &enc->rx_seq[0], IW_ENCODE_SEQ_MAX_SIZE);
  1357. }
  1358. ether_addr_copy(&key->addr.sa_data[0], &enc->addr.sa_data[0]);
  1359. switch (enc->alg) {
  1360. case IW_ENCODE_ALG_NONE:
  1361. if (priv->reg.privacy_invoked) {
  1362. priv->reg.privacy_invoked = 0x00;
  1363. commit |= SME_WEP_FLAG;
  1364. }
  1365. key->key_len = 0;
  1366. break;
  1367. case IW_ENCODE_ALG_WEP:
  1368. case IW_ENCODE_ALG_CCMP:
  1369. if (!priv->reg.privacy_invoked) {
  1370. priv->reg.privacy_invoked = 0x01;
  1371. commit |= SME_WEP_FLAG;
  1372. }
  1373. if (enc->key_len) {
  1374. memcpy(&key->key_val[0], &enc->key[0], enc->key_len);
  1375. key->key_len = enc->key_len;
  1376. commit |= (SME_WEP_VAL1 << index);
  1377. }
  1378. break;
  1379. case IW_ENCODE_ALG_TKIP:
  1380. if (!priv->reg.privacy_invoked) {
  1381. priv->reg.privacy_invoked = 0x01;
  1382. commit |= SME_WEP_FLAG;
  1383. }
  1384. if (enc->key_len == 32) {
  1385. memcpy(&key->key_val[0], &enc->key[0], enc->key_len - 16);
  1386. key->key_len = enc->key_len - 16;
  1387. if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
  1388. memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
  1389. memcpy(&key->rx_mic_key[0], &enc->key[16], 8);
  1390. } else {
  1391. memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
  1392. memcpy(&key->rx_mic_key[0], &enc->key[24], 8);
  1393. }
  1394. commit |= (SME_WEP_VAL1 << index);
  1395. }
  1396. break;
  1397. default:
  1398. return -EINVAL;
  1399. }
  1400. key->alg = enc->alg;
  1401. if (commit) {
  1402. if (commit & SME_WEP_INDEX)
  1403. hostif_sme_enqueue(priv, SME_SET_TXKEY);
  1404. if (commit & SME_WEP_VAL_MASK)
  1405. hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
  1406. if (commit & SME_WEP_FLAG)
  1407. hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
  1408. }
  1409. return 0;
  1410. }
  1411. /* get encoding token & mode (WPA)*/
  1412. static int ks_wlan_get_encode_ext(struct net_device *dev,
  1413. struct iw_request_info *info,
  1414. union iwreq_data *dwrq, char *extra)
  1415. {
  1416. struct ks_wlan_private *priv = netdev_priv(dev);
  1417. if (priv->sleep_mode == SLP_SLEEP)
  1418. return -EPERM;
  1419. /* for SLEEP MODE */
  1420. /* WPA (not used ?? wpa_supplicant)
  1421. * struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
  1422. * struct iw_encode_ext *enc;
  1423. * enc = (struct iw_encode_ext *)extra;
  1424. * int index = dwrq->flags & IW_ENCODE_INDEX;
  1425. * WPA (not used ?? wpa_supplicant)
  1426. */
  1427. return 0;
  1428. }
  1429. static int ks_wlan_set_pmksa(struct net_device *dev,
  1430. struct iw_request_info *info,
  1431. union iwreq_data *dwrq, char *extra)
  1432. {
  1433. struct ks_wlan_private *priv = netdev_priv(dev);
  1434. struct iw_pmksa *pmksa;
  1435. int i;
  1436. struct pmk *pmk;
  1437. struct list_head *ptr;
  1438. if (priv->sleep_mode == SLP_SLEEP)
  1439. return -EPERM;
  1440. /* for SLEEP MODE */
  1441. if (!extra)
  1442. return -EINVAL;
  1443. pmksa = (struct iw_pmksa *)extra;
  1444. switch (pmksa->cmd) {
  1445. case IW_PMKSA_ADD:
  1446. if (list_empty(&priv->pmklist.head)) {
  1447. for (i = 0; i < PMK_LIST_MAX; i++) {
  1448. pmk = &priv->pmklist.pmk[i];
  1449. if (is_zero_ether_addr(pmk->bssid))
  1450. break;
  1451. }
  1452. ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data);
  1453. memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
  1454. list_add(&pmk->list, &priv->pmklist.head);
  1455. priv->pmklist.size++;
  1456. break;
  1457. }
  1458. /* search cache data */
  1459. list_for_each(ptr, &priv->pmklist.head) {
  1460. pmk = list_entry(ptr, struct pmk, list);
  1461. if (ether_addr_equal(pmksa->bssid.sa_data, pmk->bssid)) {
  1462. memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
  1463. list_move(&pmk->list, &priv->pmklist.head);
  1464. break;
  1465. }
  1466. }
  1467. /* not find address. */
  1468. if (ptr != &priv->pmklist.head)
  1469. break;
  1470. /* new cache data */
  1471. if (priv->pmklist.size < PMK_LIST_MAX) {
  1472. for (i = 0; i < PMK_LIST_MAX; i++) {
  1473. pmk = &priv->pmklist.pmk[i];
  1474. if (is_zero_ether_addr(pmk->bssid))
  1475. break;
  1476. }
  1477. ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data);
  1478. memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
  1479. list_add(&pmk->list, &priv->pmklist.head);
  1480. priv->pmklist.size++;
  1481. } else { /* overwrite old cache data */
  1482. pmk = list_entry(priv->pmklist.head.prev, struct pmk,
  1483. list);
  1484. ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data);
  1485. memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
  1486. list_move(&pmk->list, &priv->pmklist.head);
  1487. }
  1488. break;
  1489. case IW_PMKSA_REMOVE:
  1490. if (list_empty(&priv->pmklist.head))
  1491. return -EINVAL;
  1492. /* search cache data */
  1493. list_for_each(ptr, &priv->pmklist.head) {
  1494. pmk = list_entry(ptr, struct pmk, list);
  1495. if (ether_addr_equal(pmksa->bssid.sa_data, pmk->bssid)) {
  1496. eth_zero_addr(pmk->bssid);
  1497. memset(pmk->pmkid, 0, IW_PMKID_LEN);
  1498. list_del_init(&pmk->list);
  1499. break;
  1500. }
  1501. }
  1502. /* not find address. */
  1503. if (ptr == &priv->pmklist.head)
  1504. return 0;
  1505. break;
  1506. case IW_PMKSA_FLUSH:
  1507. memset(&priv->pmklist, 0, sizeof(priv->pmklist));
  1508. INIT_LIST_HEAD(&priv->pmklist.head);
  1509. for (i = 0; i < PMK_LIST_MAX; i++)
  1510. INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
  1511. break;
  1512. default:
  1513. return -EINVAL;
  1514. }
  1515. hostif_sme_enqueue(priv, SME_SET_PMKSA);
  1516. return 0;
  1517. }
  1518. static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
  1519. {
  1520. struct ks_wlan_private *priv = netdev_priv(dev);
  1521. struct iw_statistics *wstats = &priv->wstats;
  1522. if (!atomic_read(&update_phyinfo))
  1523. return (priv->dev_state < DEVICE_STATE_READY) ? NULL : wstats;
  1524. /*
  1525. * Packets discarded in the wireless adapter due to wireless
  1526. * specific problems
  1527. */
  1528. wstats->discard.nwid = 0; /* Rx invalid nwid */
  1529. wstats->discard.code = 0; /* Rx invalid crypt */
  1530. wstats->discard.fragment = 0; /* Rx invalid frag */
  1531. wstats->discard.retries = 0; /* Tx excessive retries */
  1532. wstats->discard.misc = 0; /* Invalid misc */
  1533. wstats->miss.beacon = 0; /* Missed beacon */
  1534. return wstats;
  1535. }
  1536. static int ks_wlan_set_stop_request(struct net_device *dev,
  1537. struct iw_request_info *info, __u32 *uwrq,
  1538. char *extra)
  1539. {
  1540. struct ks_wlan_private *priv = netdev_priv(dev);
  1541. if (priv->sleep_mode == SLP_SLEEP)
  1542. return -EPERM;
  1543. /* for SLEEP MODE */
  1544. if (!(*uwrq))
  1545. return -EINVAL;
  1546. hostif_sme_enqueue(priv, SME_STOP_REQUEST);
  1547. return 0;
  1548. }
  1549. #include <linux/ieee80211.h>
  1550. static int ks_wlan_set_mlme(struct net_device *dev,
  1551. struct iw_request_info *info,
  1552. union iwreq_data *dwrq, char *extra)
  1553. {
  1554. struct ks_wlan_private *priv = netdev_priv(dev);
  1555. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  1556. __u32 mode = 1;
  1557. if (priv->sleep_mode == SLP_SLEEP)
  1558. return -EPERM;
  1559. if (mlme->cmd != IW_MLME_DEAUTH &&
  1560. mlme->cmd != IW_MLME_DISASSOC)
  1561. return -EOPNOTSUPP;
  1562. if (mlme->cmd == IW_MLME_DEAUTH &&
  1563. mlme->reason_code == WLAN_REASON_MIC_FAILURE)
  1564. return 0;
  1565. return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
  1566. }
  1567. static int ks_wlan_get_firmware_version(struct net_device *dev,
  1568. struct iw_request_info *info,
  1569. struct iw_point *dwrq, char *extra)
  1570. {
  1571. struct ks_wlan_private *priv = netdev_priv(dev);
  1572. strcpy(extra, priv->firmware_version);
  1573. dwrq->length = priv->version_size + 1;
  1574. return 0;
  1575. }
  1576. static int ks_wlan_set_preamble(struct net_device *dev,
  1577. struct iw_request_info *info, __u32 *uwrq,
  1578. char *extra)
  1579. {
  1580. struct ks_wlan_private *priv = netdev_priv(dev);
  1581. if (priv->sleep_mode == SLP_SLEEP)
  1582. return -EPERM;
  1583. /* for SLEEP MODE */
  1584. if (*uwrq != LONG_PREAMBLE && *uwrq != SHORT_PREAMBLE)
  1585. return -EINVAL;
  1586. priv->reg.preamble = *uwrq;
  1587. priv->need_commit |= SME_MODE_SET;
  1588. return -EINPROGRESS; /* Call commit handler */
  1589. }
  1590. static int ks_wlan_get_preamble(struct net_device *dev,
  1591. struct iw_request_info *info, __u32 *uwrq,
  1592. char *extra)
  1593. {
  1594. struct ks_wlan_private *priv = netdev_priv(dev);
  1595. if (priv->sleep_mode == SLP_SLEEP)
  1596. return -EPERM;
  1597. /* for SLEEP MODE */
  1598. *uwrq = priv->reg.preamble;
  1599. return 0;
  1600. }
  1601. static int ks_wlan_set_power_mgmt(struct net_device *dev,
  1602. struct iw_request_info *info, __u32 *uwrq,
  1603. char *extra)
  1604. {
  1605. struct ks_wlan_private *priv = netdev_priv(dev);
  1606. if (priv->sleep_mode == SLP_SLEEP)
  1607. return -EPERM;
  1608. if (*uwrq != POWER_MGMT_ACTIVE &&
  1609. *uwrq != POWER_MGMT_SAVE1 &&
  1610. *uwrq != POWER_MGMT_SAVE2)
  1611. return -EINVAL;
  1612. if ((*uwrq == POWER_MGMT_SAVE1 || *uwrq == POWER_MGMT_SAVE2) &&
  1613. (priv->reg.operation_mode != MODE_INFRASTRUCTURE))
  1614. return -EINVAL;
  1615. priv->reg.power_mgmt = *uwrq;
  1616. hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
  1617. return

Large files files are truncated, but you can click here to view the full file