wpactl.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. *
  20. * File: wpactl.c
  21. *
  22. * Purpose: handle wpa supplicant ioctl input/out functions
  23. *
  24. * Author: Lyndon Chen
  25. *
  26. * Date: Oct. 20, 2003
  27. *
  28. * Functions:
  29. *
  30. * Revision History:
  31. *
  32. */
  33. #include "wpactl.h"
  34. #include "key.h"
  35. #include "mac.h"
  36. #include "device.h"
  37. #include "wmgr.h"
  38. #include "iocmd.h"
  39. #include "iowpa.h"
  40. #include "rf.h"
  41. /*--------------------- Static Definitions -------------------------*/
  42. #define VIAWGET_WPA_MAX_BUF_SIZE 1024
  43. static const int frequency_list[] = {
  44. 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  45. 2447, 2452, 2457, 2462, 2467, 2472, 2484
  46. };
  47. /*--------------------- Static Classes ----------------------------*/
  48. /*--------------------- Static Functions --------------------------*/
  49. /*--------------------- Export Variables --------------------------*/
  50. static void wpadev_setup(struct net_device *dev)
  51. {
  52. dev->type = ARPHRD_IEEE80211;
  53. dev->hard_header_len = ETH_HLEN;
  54. dev->mtu = 2048;
  55. dev->addr_len = ETH_ALEN;
  56. dev->tx_queue_len = 1000;
  57. memset(dev->broadcast, 0xFF, ETH_ALEN);
  58. dev->flags = IFF_BROADCAST|IFF_MULTICAST;
  59. }
  60. /*
  61. * Description:
  62. * register netdev for wpa supplicant daemon
  63. *
  64. * Parameters:
  65. * In:
  66. * pDevice -
  67. * enable -
  68. * Out:
  69. *
  70. * Return Value:
  71. *
  72. */
  73. static int wpa_init_wpadev(struct vnt_private *pDevice)
  74. {
  75. struct vnt_private *wpadev_priv;
  76. struct net_device *dev = pDevice->dev;
  77. int ret = 0;
  78. pDevice->wpadev = alloc_netdev(sizeof(*wpadev_priv), "vntwpa",
  79. NET_NAME_UNKNOWN, wpadev_setup);
  80. if (pDevice->wpadev == NULL)
  81. return -ENOMEM;
  82. wpadev_priv = netdev_priv(pDevice->wpadev);
  83. *wpadev_priv = *pDevice;
  84. eth_hw_addr_inherit(pDevice->wpadev, dev);
  85. pDevice->wpadev->base_addr = dev->base_addr;
  86. pDevice->wpadev->irq = dev->irq;
  87. pDevice->wpadev->mem_start = dev->mem_start;
  88. pDevice->wpadev->mem_end = dev->mem_end;
  89. ret = register_netdev(pDevice->wpadev);
  90. if (ret) {
  91. pr_debug("%s: register_netdev(WPA) failed!\n", dev->name);
  92. free_netdev(pDevice->wpadev);
  93. return -1;
  94. }
  95. if (pDevice->skb == NULL) {
  96. pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
  97. if (pDevice->skb == NULL)
  98. return -ENOMEM;
  99. }
  100. pr_debug("%s: Registered netdev %s for WPA management\n",
  101. dev->name, pDevice->wpadev->name);
  102. return 0;
  103. }
  104. /*
  105. * Description:
  106. * unregister net_device (wpadev)
  107. *
  108. * Parameters:
  109. * In:
  110. * pDevice -
  111. * Out:
  112. *
  113. * Return Value:
  114. *
  115. */
  116. static int wpa_release_wpadev(struct vnt_private *pDevice)
  117. {
  118. if (pDevice->skb) {
  119. dev_kfree_skb(pDevice->skb);
  120. pDevice->skb = NULL;
  121. }
  122. if (pDevice->wpadev) {
  123. pr_debug("%s: Netdevice %s unregistered\n",
  124. pDevice->dev->name, pDevice->wpadev->name);
  125. unregister_netdev(pDevice->wpadev);
  126. free_netdev(pDevice->wpadev);
  127. pDevice->wpadev = NULL;
  128. }
  129. return 0;
  130. }
  131. /*
  132. * Description:
  133. * Set enable/disable dev for wpa supplicant daemon
  134. *
  135. * Parameters:
  136. * In:
  137. * pDevice -
  138. * val -
  139. * Out:
  140. *
  141. * Return Value:
  142. *
  143. */
  144. int wpa_set_wpadev(struct vnt_private *pDevice, int val)
  145. {
  146. if (val)
  147. return wpa_init_wpadev(pDevice);
  148. else
  149. return wpa_release_wpadev(pDevice);
  150. }
  151. /*
  152. * Description:
  153. * Set WPA algorithm & keys
  154. *
  155. * Parameters:
  156. * In:
  157. * pDevice -
  158. * param -
  159. * Out:
  160. *
  161. * Return Value:
  162. *
  163. */
  164. int wpa_set_keys(struct vnt_private *pDevice, void *ctx,
  165. bool fcpfkernel) __must_hold(&pDevice->lock)
  166. {
  167. struct viawget_wpa_param *param = ctx;
  168. PSMgmtObject pMgmt = pDevice->pMgmt;
  169. unsigned long dwKeyIndex = 0;
  170. unsigned char abyKey[MAX_KEY_LEN];
  171. unsigned char abySeq[MAX_KEY_LEN];
  172. u64 KeyRSC;
  173. unsigned char byKeyDecMode = KEY_CTL_WEP;
  174. int ret = 0;
  175. int uu, ii;
  176. if (param->u.wpa_key.alg_name > WPA_ALG_CCMP ||
  177. param->u.wpa_key.key_len > MAX_KEY_LEN ||
  178. param->u.wpa_key.seq_len > MAX_KEY_LEN)
  179. return -EINVAL;
  180. pr_debug("param->u.wpa_key.alg_name = %d\n", param->u.wpa_key.alg_name);
  181. if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
  182. pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
  183. pDevice->bEncryptionEnable = false;
  184. pDevice->byKeyIndex = 0;
  185. pDevice->bTransmitKey = false;
  186. KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
  187. for (uu = 0; uu < MAX_KEY_TABLE; uu++)
  188. MACvDisableKeyEntry(pDevice->PortOffset, uu);
  189. return ret;
  190. }
  191. if (param->u.wpa_key.key && fcpfkernel) {
  192. memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
  193. } else {
  194. spin_unlock_irq(&pDevice->lock);
  195. if (param->u.wpa_key.key &&
  196. copy_from_user(&abyKey[0],
  197. (void __user *)param->u.wpa_key.key,
  198. param->u.wpa_key.key_len)) {
  199. spin_lock_irq(&pDevice->lock);
  200. return -EINVAL;
  201. }
  202. spin_lock_irq(&pDevice->lock);
  203. }
  204. dwKeyIndex = (unsigned long)(param->u.wpa_key.key_index);
  205. if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
  206. if (dwKeyIndex > 3) {
  207. return -EINVAL;
  208. } else {
  209. if (param->u.wpa_key.set_tx) {
  210. pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
  211. pDevice->bTransmitKey = true;
  212. dwKeyIndex |= (1 << 31);
  213. }
  214. KeybSetDefaultKey(&(pDevice->sKey),
  215. dwKeyIndex & ~(BIT30 | USE_KEYRSC),
  216. param->u.wpa_key.key_len,
  217. NULL,
  218. abyKey,
  219. KEY_CTL_WEP,
  220. pDevice->PortOffset,
  221. pDevice->byLocalID);
  222. }
  223. pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
  224. pDevice->bEncryptionEnable = true;
  225. return ret;
  226. }
  227. if (param->u.wpa_key.seq && fcpfkernel) {
  228. memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
  229. } else {
  230. spin_unlock_irq(&pDevice->lock);
  231. if (param->u.wpa_key.seq &&
  232. copy_from_user(&abySeq[0],
  233. (void __user *)param->u.wpa_key.seq,
  234. param->u.wpa_key.seq_len)) {
  235. spin_lock_irq(&pDevice->lock);
  236. return -EINVAL;
  237. }
  238. spin_lock_irq(&pDevice->lock);
  239. }
  240. if (param->u.wpa_key.seq_len > 0) {
  241. for (ii = 0; ii < param->u.wpa_key.seq_len; ii++) {
  242. if (ii < 4)
  243. KeyRSC |= (u64)(abySeq[ii] << (ii * 8));
  244. else
  245. KeyRSC |= (u64)(abySeq[ii] << ((ii-4) * 8));
  246. }
  247. dwKeyIndex |= 1 << 29;
  248. }
  249. if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
  250. pr_debug("return dwKeyIndex > 3\n");
  251. return -EINVAL;
  252. }
  253. if (param->u.wpa_key.alg_name == WPA_ALG_TKIP)
  254. pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
  255. if (param->u.wpa_key.alg_name == WPA_ALG_CCMP)
  256. pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
  257. if (param->u.wpa_key.set_tx)
  258. dwKeyIndex |= (1 << 31);
  259. if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
  260. byKeyDecMode = KEY_CTL_CCMP;
  261. else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
  262. byKeyDecMode = KEY_CTL_TKIP;
  263. else
  264. byKeyDecMode = KEY_CTL_WEP;
  265. /* Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled */
  266. if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
  267. if (param->u.wpa_key.key_len == MAX_KEY_LEN)
  268. byKeyDecMode = KEY_CTL_TKIP;
  269. else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
  270. byKeyDecMode = KEY_CTL_WEP;
  271. else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
  272. byKeyDecMode = KEY_CTL_WEP;
  273. } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
  274. if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
  275. byKeyDecMode = KEY_CTL_WEP;
  276. else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
  277. byKeyDecMode = KEY_CTL_WEP;
  278. }
  279. /* Check TKIP key length */
  280. if ((byKeyDecMode == KEY_CTL_TKIP) &&
  281. (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
  282. /* TKIP Key must be 256 bits */
  283. pr_debug("return- TKIP Key must be 256 bits!\n");
  284. return -EINVAL;
  285. }
  286. /* Check AES key length */
  287. if ((byKeyDecMode == KEY_CTL_CCMP) &&
  288. (param->u.wpa_key.key_len != AES_KEY_LEN)) {
  289. /* AES Key must be 128 bits */
  290. return -EINVAL;
  291. }
  292. /* spin_lock_irq(&pDevice->lock); */
  293. if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
  294. /* If is_broadcast_ether_addr, set the key as every key entry's group key. */
  295. pr_debug("Groupe Key Assign\n");
  296. if (KeybSetAllGroupKey(&(pDevice->sKey),
  297. dwKeyIndex,
  298. param->u.wpa_key.key_len,
  299. (u64 *) &KeyRSC,
  300. (unsigned char *)abyKey,
  301. byKeyDecMode,
  302. pDevice->PortOffset,
  303. pDevice->byLocalID) &&
  304. KeybSetDefaultKey(&(pDevice->sKey),
  305. dwKeyIndex,
  306. param->u.wpa_key.key_len,
  307. (u64 *) &KeyRSC,
  308. (unsigned char *)abyKey,
  309. byKeyDecMode,
  310. pDevice->PortOffset,
  311. pDevice->byLocalID)) {
  312. pr_debug("GROUP Key Assign\n");
  313. } else {
  314. return -EINVAL;
  315. }
  316. } else {
  317. pr_debug("Pairwise Key Assign\n");
  318. /* BSSID not 0xffffffffffff */
  319. /* Pairwise Key can't be WEP */
  320. if (byKeyDecMode == KEY_CTL_WEP) {
  321. pr_debug("Pairwise Key can't be WEP\n");
  322. return -EINVAL;
  323. }
  324. dwKeyIndex |= (1 << 30); /* set pairwise key */
  325. if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA)
  326. return -EINVAL;
  327. if (KeybSetKey(&(pDevice->sKey),
  328. &param->addr[0],
  329. dwKeyIndex,
  330. param->u.wpa_key.key_len,
  331. (u64 *) &KeyRSC,
  332. (unsigned char *)abyKey,
  333. byKeyDecMode,
  334. pDevice->PortOffset,
  335. pDevice->byLocalID)) {
  336. pr_debug("Pairwise Key Set\n");
  337. } else {
  338. /* Key Table Full */
  339. return -EINVAL;
  340. }
  341. } /* BSSID not 0xffffffffffff */
  342. if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
  343. pDevice->byKeyIndex = (unsigned char)param->u.wpa_key.key_index;
  344. pDevice->bTransmitKey = true;
  345. }
  346. pDevice->bEncryptionEnable = true;
  347. return ret;
  348. }
  349. /*
  350. * Description:
  351. * enable wpa auth & mode
  352. *
  353. * Parameters:
  354. * In:
  355. * pDevice -
  356. * param -
  357. * Out:
  358. *
  359. * Return Value:
  360. *
  361. */
  362. static int wpa_set_wpa(struct vnt_private *pDevice,
  363. struct viawget_wpa_param *param)
  364. {
  365. PSMgmtObject pMgmt = pDevice->pMgmt;
  366. pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
  367. pMgmt->bShareKeyAlgorithm = false;
  368. return 0;
  369. }
  370. /*
  371. * Description:
  372. * set disassociate
  373. *
  374. * Parameters:
  375. * In:
  376. * pDevice -
  377. * param -
  378. * Out:
  379. *
  380. * Return Value:
  381. *
  382. */
  383. static int wpa_set_disassociate(struct vnt_private *pDevice,
  384. struct viawget_wpa_param *param)
  385. {
  386. PSMgmtObject pMgmt = pDevice->pMgmt;
  387. spin_lock_irq(&pDevice->lock);
  388. if (pDevice->bLinkPass) {
  389. if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
  390. bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
  391. }
  392. spin_unlock_irq(&pDevice->lock);
  393. return 0;
  394. }
  395. /*
  396. * Description:
  397. * enable scan process
  398. *
  399. * Parameters:
  400. * In:
  401. * pDevice -
  402. * param -
  403. * Out:
  404. *
  405. * Return Value:
  406. *
  407. */
  408. static int wpa_set_scan(struct vnt_private *pDevice,
  409. struct viawget_wpa_param *param)
  410. {
  411. spin_lock_irq(&pDevice->lock);
  412. BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
  413. bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
  414. spin_unlock_irq(&pDevice->lock);
  415. return 0;
  416. }
  417. /*
  418. * Description:
  419. * get bssid
  420. *
  421. * Parameters:
  422. * In:
  423. * pDevice -
  424. * param -
  425. * Out:
  426. *
  427. * Return Value:
  428. *
  429. */
  430. static int wpa_get_bssid(struct vnt_private *pDevice,
  431. struct viawget_wpa_param *param)
  432. {
  433. PSMgmtObject pMgmt = pDevice->pMgmt;
  434. memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
  435. return 0;
  436. }
  437. /*
  438. * Description:
  439. * get bssid
  440. *
  441. * Parameters:
  442. * In:
  443. * pDevice -
  444. * param -
  445. * Out:
  446. *
  447. * Return Value:
  448. *
  449. */
  450. static int wpa_get_ssid(struct vnt_private *pDevice,
  451. struct viawget_wpa_param *param)
  452. {
  453. PSMgmtObject pMgmt = pDevice->pMgmt;
  454. PWLAN_IE_SSID pItemSSID;
  455. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  456. memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
  457. param->u.wpa_associate.ssid_len = pItemSSID->len;
  458. return 0;
  459. }
  460. /*
  461. * Description:
  462. * get scan results
  463. *
  464. * Parameters:
  465. * In:
  466. * pDevice -
  467. * param -
  468. * Out:
  469. *
  470. * Return Value:
  471. *
  472. */
  473. static int wpa_get_scan(struct vnt_private *pDevice,
  474. struct viawget_wpa_param *param)
  475. {
  476. struct viawget_scan_result *scan_buf;
  477. PSMgmtObject pMgmt = pDevice->pMgmt;
  478. PWLAN_IE_SSID pItemSSID;
  479. PKnownBSS pBSS;
  480. unsigned char *pBuf;
  481. int ret = 0;
  482. u16 count = 0;
  483. u16 ii, jj;
  484. #if 1
  485. unsigned char *ptempBSS;
  486. ptempBSS = kmalloc(sizeof(KnownBSS), GFP_ATOMIC);
  487. if (ptempBSS == NULL) {
  488. pr_err("bubble sort kmalloc memory fail@@@\n");
  489. ret = -ENOMEM;
  490. return ret;
  491. }
  492. for (ii = 0; ii < MAX_BSS_NUM; ii++) {
  493. for (jj = 0; jj < MAX_BSS_NUM - ii - 1; jj++) {
  494. if ((pMgmt->sBSSList[jj].bActive != true) ||
  495. ((pMgmt->sBSSList[jj].uRSSI > pMgmt->sBSSList[jj + 1].uRSSI) && (pMgmt->sBSSList[jj + 1].bActive != false))) {
  496. memcpy(ptempBSS, &pMgmt->sBSSList[jj], sizeof(KnownBSS));
  497. memcpy(&pMgmt->sBSSList[jj], &pMgmt->sBSSList[jj + 1], sizeof(KnownBSS));
  498. memcpy(&pMgmt->sBSSList[jj + 1], ptempBSS, sizeof(KnownBSS));
  499. }
  500. }
  501. }
  502. kfree(ptempBSS);
  503. #endif
  504. //******mike:bubble sort by stronger RSSI*****//
  505. count = 0;
  506. pBSS = &(pMgmt->sBSSList[0]);
  507. for (ii = 0; ii < MAX_BSS_NUM; ii++) {
  508. pBSS = &(pMgmt->sBSSList[ii]);
  509. if (!pBSS->bActive)
  510. continue;
  511. count++;
  512. }
  513. pBuf = kcalloc(count, sizeof(struct viawget_scan_result), GFP_ATOMIC);
  514. if (pBuf == NULL) {
  515. ret = -ENOMEM;
  516. return ret;
  517. }
  518. scan_buf = (struct viawget_scan_result *)pBuf;
  519. pBSS = &(pMgmt->sBSSList[0]);
  520. for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
  521. pBSS = &(pMgmt->sBSSList[ii]);
  522. if (pBSS->bActive) {
  523. if (jj >= count)
  524. break;
  525. memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
  526. pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
  527. memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
  528. scan_buf->ssid_len = pItemSSID->len;
  529. scan_buf->freq = frequency_list[pBSS->uChannel-1];
  530. scan_buf->caps = pBSS->wCapInfo;
  531. if (pBSS->wWPALen != 0) {
  532. scan_buf->wpa_ie_len = pBSS->wWPALen;
  533. memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
  534. }
  535. if (pBSS->wRSNLen != 0) {
  536. scan_buf->rsn_ie_len = pBSS->wRSNLen;
  537. memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
  538. }
  539. scan_buf = (struct viawget_scan_result *)((unsigned char *)scan_buf + sizeof(struct viawget_scan_result));
  540. jj++;
  541. }
  542. }
  543. if (jj < count)
  544. count = jj;
  545. if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count))
  546. ret = -EFAULT;
  547. param->u.scan_results.scan_count = count;
  548. pr_debug(" param->u.scan_results.scan_count = %d\n", count);
  549. kfree(pBuf);
  550. return ret;
  551. }
  552. /*
  553. * Description:
  554. * set associate with AP
  555. *
  556. * Parameters:
  557. * In:
  558. * pDevice -
  559. * param -
  560. * Out:
  561. *
  562. * Return Value:
  563. *
  564. */
  565. static int wpa_set_associate(struct vnt_private *pDevice,
  566. struct viawget_wpa_param *param)
  567. {
  568. PSMgmtObject pMgmt = pDevice->pMgmt;
  569. PWLAN_IE_SSID pItemSSID;
  570. unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  571. unsigned char abyWPAIE[64];
  572. bool bWepEnabled = false;
  573. /* set key type & algorithm */
  574. pr_debug("pairwise_suite = %d\n",
  575. param->u.wpa_associate.pairwise_suite);
  576. pr_debug("group_suite = %d\n", param->u.wpa_associate.group_suite);
  577. pr_debug("key_mgmt_suite = %d\n",
  578. param->u.wpa_associate.key_mgmt_suite);
  579. pr_debug("auth_alg = %d\n", param->u.wpa_associate.auth_alg);
  580. pr_debug("mode = %d\n", param->u.wpa_associate.mode);
  581. pr_debug("wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
  582. if (param->u.wpa_associate.wpa_ie_len) {
  583. if (!param->u.wpa_associate.wpa_ie)
  584. return -EINVAL;
  585. if (param->u.wpa_associate.wpa_ie_len > sizeof(abyWPAIE))
  586. return -EINVAL;
  587. if (copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
  588. return -EFAULT;
  589. }
  590. if (param->u.wpa_associate.mode == 1)
  591. pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
  592. else
  593. pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
  594. /* set ssid */
  595. memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  596. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
  597. pItemSSID->byElementID = WLAN_EID_SSID;
  598. pItemSSID->len = param->u.wpa_associate.ssid_len;
  599. memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
  600. /* set bssid */
  601. if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
  602. memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
  603. else
  604. bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
  605. if (param->u.wpa_associate.wpa_ie_len == 0) {
  606. if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
  607. pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
  608. else
  609. pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
  610. } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
  611. if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
  612. pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
  613. else
  614. pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
  615. } else {
  616. if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
  617. pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
  618. else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
  619. pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
  620. else
  621. pMgmt->eAuthenMode = WMAC_AUTH_WPA;
  622. }
  623. switch (param->u.wpa_associate.pairwise_suite) {
  624. case CIPHER_CCMP:
  625. pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
  626. break;
  627. case CIPHER_TKIP:
  628. pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
  629. break;
  630. case CIPHER_WEP40:
  631. case CIPHER_WEP104:
  632. pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
  633. bWepEnabled = true;
  634. break;
  635. case CIPHER_NONE:
  636. if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
  637. pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
  638. else
  639. pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
  640. break;
  641. default:
  642. pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
  643. }
  644. //DavidWang add for WPA_supplicant support open/share mode
  645. if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
  646. pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
  647. pMgmt->bShareKeyAlgorithm = true;
  648. } else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
  649. if (!bWepEnabled) pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
  650. else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
  651. }
  652. //mike save old encryption status
  653. pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
  654. if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled)
  655. pDevice->bEncryptionEnable = true;
  656. else
  657. pDevice->bEncryptionEnable = false;
  658. if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
  659. ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && bWepEnabled))) //DavidWang //20080717-06,<Modify> by chester//Not to initial WEP
  660. KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
  661. spin_lock_irq(&pDevice->lock);
  662. pDevice->bLinkPass = false;
  663. memset(pMgmt->abyCurrBSSID, 0, 6);
  664. pMgmt->eCurrState = WMAC_STATE_IDLE;
  665. netif_stop_queue(pDevice->dev);
  666. //20080701-02,<Add> by Mike Liu
  667. /*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
  668. {
  669. PKnownBSS pCurr = NULL;
  670. pCurr = BSSpSearchBSSList(pDevice,
  671. pMgmt->abyDesireBSSID,
  672. pMgmt->abyDesireSSID,
  673. pMgmt->eConfigPHYMode
  674. );
  675. if (pCurr == NULL) {
  676. pr_debug("wpa_set_associate---->hidden mode site survey before associate.......\n");
  677. bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
  678. }
  679. }
  680. /****************************************************************/
  681. bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
  682. spin_unlock_irq(&pDevice->lock);
  683. return 0;
  684. }
  685. /*
  686. * Description:
  687. * wpa_ioctl main function supported for wpa supplicant
  688. *
  689. * Parameters:
  690. * In:
  691. * pDevice -
  692. * iw_point -
  693. * Out:
  694. *
  695. * Return Value:
  696. *
  697. */
  698. int wpa_ioctl(struct vnt_private *pDevice, struct iw_point *p)
  699. {
  700. struct viawget_wpa_param *param;
  701. int ret = 0;
  702. int wpa_ioctl = 0;
  703. if (p->length < sizeof(struct viawget_wpa_param) ||
  704. p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
  705. return -EINVAL;
  706. param = kmalloc((int)p->length, GFP_KERNEL);
  707. if (param == NULL)
  708. return -ENOMEM;
  709. if (copy_from_user(param, p->pointer, p->length)) {
  710. ret = -EFAULT;
  711. goto out;
  712. }
  713. switch (param->cmd) {
  714. case VIAWGET_SET_WPA:
  715. ret = wpa_set_wpa(pDevice, param);
  716. pr_debug("VIAWGET_SET_WPA\n");
  717. break;
  718. case VIAWGET_SET_KEY:
  719. pr_debug("VIAWGET_SET_KEY\n");
  720. spin_lock_irq(&pDevice->lock);
  721. ret = wpa_set_keys(pDevice, param, false);
  722. spin_unlock_irq(&pDevice->lock);
  723. break;
  724. case VIAWGET_SET_SCAN:
  725. pr_debug("VIAWGET_SET_SCAN\n");
  726. ret = wpa_set_scan(pDevice, param);
  727. break;
  728. case VIAWGET_GET_SCAN:
  729. pr_debug("VIAWGET_GET_SCAN\n");
  730. ret = wpa_get_scan(pDevice, param);
  731. wpa_ioctl = 1;
  732. break;
  733. case VIAWGET_GET_SSID:
  734. pr_debug("VIAWGET_GET_SSID\n");
  735. ret = wpa_get_ssid(pDevice, param);
  736. wpa_ioctl = 1;
  737. break;
  738. case VIAWGET_GET_BSSID:
  739. pr_debug("VIAWGET_GET_BSSID\n");
  740. ret = wpa_get_bssid(pDevice, param);
  741. wpa_ioctl = 1;
  742. break;
  743. case VIAWGET_SET_ASSOCIATE:
  744. pr_debug("VIAWGET_SET_ASSOCIATE\n");
  745. ret = wpa_set_associate(pDevice, param);
  746. break;
  747. case VIAWGET_SET_DISASSOCIATE:
  748. pr_debug("VIAWGET_SET_DISASSOCIATE\n");
  749. ret = wpa_set_disassociate(pDevice, param);
  750. break;
  751. case VIAWGET_SET_DROP_UNENCRYPT:
  752. pr_debug("VIAWGET_SET_DROP_UNENCRYPT\n");
  753. break;
  754. case VIAWGET_SET_DEAUTHENTICATE:
  755. pr_debug("VIAWGET_SET_DEAUTHENTICATE\n");
  756. break;
  757. default:
  758. pr_debug("wpa_ioctl: unknown cmd=%d\n",
  759. param->cmd);
  760. ret = -EOPNOTSUPP;
  761. goto out;
  762. }
  763. if ((ret == 0) && wpa_ioctl) {
  764. if (copy_to_user(p->pointer, param, p->length)) {
  765. ret = -EFAULT;
  766. goto out;
  767. }
  768. }
  769. out:
  770. kfree(param);
  771. return ret;
  772. }