hostap.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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. * File: hostap.c
  20. *
  21. * Purpose: handle hostap deamon ioctl input/out functions
  22. *
  23. * Author: Lyndon Chen
  24. *
  25. * Date: Oct. 20, 2003
  26. *
  27. * Functions:
  28. *
  29. * Revision History:
  30. *
  31. */
  32. #include "hostap.h"
  33. #include "iocmd.h"
  34. #include "mac.h"
  35. #include "card.h"
  36. #include "baseband.h"
  37. #include "wpactl.h"
  38. #include "key.h"
  39. #include "datarate.h"
  40. #define VIAWGET_HOSTAPD_MAX_BUF_SIZE 1024
  41. #define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT0
  42. #define HOSTAP_CRYPT_FLAG_PERMANENT BIT1
  43. #define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
  44. #define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
  45. #define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
  46. #define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
  47. #define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
  48. #define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
  49. /*--------------------- Static Definitions -------------------------*/
  50. /*--------------------- Static Classes ----------------------------*/
  51. /*--------------------- Static Variables --------------------------*/
  52. //static int msglevel =MSG_LEVEL_DEBUG;
  53. static int msglevel =MSG_LEVEL_INFO;
  54. /*--------------------- Static Functions --------------------------*/
  55. /*--------------------- Export Variables --------------------------*/
  56. /*
  57. * Description:
  58. * register net_device (AP) for hostap deamon
  59. *
  60. * Parameters:
  61. * In:
  62. * pDevice -
  63. * rtnl_locked -
  64. * Out:
  65. *
  66. * Return Value:
  67. *
  68. */
  69. static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
  70. {
  71. PSDevice apdev_priv;
  72. struct net_device *dev = pDevice->dev;
  73. int ret;
  74. const struct net_device_ops apdev_netdev_ops = {
  75. .ndo_start_xmit = pDevice->tx_80211,
  76. };
  77. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
  78. pDevice->apdev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
  79. if (pDevice->apdev == NULL)
  80. return -ENOMEM;
  81. apdev_priv = netdev_priv(pDevice->apdev);
  82. *apdev_priv = *pDevice;
  83. memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
  84. pDevice->apdev->netdev_ops = &apdev_netdev_ops;
  85. pDevice->apdev->type = ARPHRD_IEEE80211;
  86. pDevice->apdev->base_addr = dev->base_addr;
  87. pDevice->apdev->irq = dev->irq;
  88. pDevice->apdev->mem_start = dev->mem_start;
  89. pDevice->apdev->mem_end = dev->mem_end;
  90. sprintf(pDevice->apdev->name, "%sap", dev->name);
  91. if (rtnl_locked)
  92. ret = register_netdevice(pDevice->apdev);
  93. else
  94. ret = register_netdev(pDevice->apdev);
  95. if (ret) {
  96. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n",
  97. dev->name);
  98. return -1;
  99. }
  100. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
  101. dev->name, pDevice->apdev->name);
  102. KeyvInitTable(pDevice,&pDevice->sKey);
  103. return 0;
  104. }
  105. /*
  106. * Description:
  107. * unregister net_device(AP)
  108. *
  109. * Parameters:
  110. * In:
  111. * pDevice -
  112. * rtnl_locked -
  113. * Out:
  114. *
  115. * Return Value:
  116. *
  117. */
  118. static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked)
  119. {
  120. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
  121. if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) {
  122. if (rtnl_locked)
  123. unregister_netdevice(pDevice->apdev);
  124. else
  125. unregister_netdev(pDevice->apdev);
  126. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
  127. pDevice->dev->name, pDevice->apdev->name);
  128. }
  129. kfree(pDevice->apdev);
  130. pDevice->apdev = NULL;
  131. pDevice->bEnable8021x = FALSE;
  132. pDevice->bEnableHostWEP = FALSE;
  133. pDevice->bEncryptionEnable = FALSE;
  134. return 0;
  135. }
  136. /*
  137. * Description:
  138. * Set enable/disable hostapd mode
  139. *
  140. * Parameters:
  141. * In:
  142. * pDevice -
  143. * rtnl_locked -
  144. * Out:
  145. *
  146. * Return Value:
  147. *
  148. */
  149. int vt6656_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked)
  150. {
  151. if (val < 0 || val > 1)
  152. return -EINVAL;
  153. if (pDevice->bEnableHostapd == val)
  154. return 0;
  155. pDevice->bEnableHostapd = val;
  156. if (val)
  157. return hostap_enable_hostapd(pDevice, rtnl_locked);
  158. else
  159. return hostap_disable_hostapd(pDevice, rtnl_locked);
  160. }
  161. /*
  162. * Description:
  163. * remove station function supported for hostap deamon
  164. *
  165. * Parameters:
  166. * In:
  167. * pDevice -
  168. * param -
  169. * Out:
  170. *
  171. * Return Value:
  172. *
  173. */
  174. static int hostap_remove_sta(PSDevice pDevice,
  175. struct viawget_hostapd_param *param)
  176. {
  177. unsigned int uNodeIndex;
  178. if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
  179. BSSvRemoveOneNode(pDevice, uNodeIndex);
  180. }
  181. else {
  182. return -ENOENT;
  183. }
  184. return 0;
  185. }
  186. /*
  187. * Description:
  188. * add a station from hostap deamon
  189. *
  190. * Parameters:
  191. * In:
  192. * pDevice -
  193. * param -
  194. * Out:
  195. *
  196. * Return Value:
  197. *
  198. */
  199. static int hostap_add_sta(PSDevice pDevice,
  200. struct viawget_hostapd_param *param)
  201. {
  202. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  203. unsigned int uNodeIndex;
  204. if (!BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
  205. BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
  206. }
  207. memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
  208. pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
  209. pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
  210. // TODO listenInterval
  211. // pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1;
  212. pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = FALSE;
  213. pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
  214. // set max tx rate
  215. pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
  216. pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
  217. // set max basic rate
  218. pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M;
  219. // Todo: check sta preamble, if ap can't support, set status code
  220. pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
  221. WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
  222. pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)param->u.add_sta.aid;
  223. pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
  224. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID);
  225. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
  226. param->sta_addr[0],
  227. param->sta_addr[1],
  228. param->sta_addr[2],
  229. param->sta_addr[3],
  230. param->sta_addr[4],
  231. param->sta_addr[5]
  232. ) ;
  233. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n",
  234. pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
  235. return 0;
  236. }
  237. /*
  238. * Description:
  239. * get station info
  240. *
  241. * Parameters:
  242. * In:
  243. * pDevice -
  244. * param -
  245. * Out:
  246. *
  247. * Return Value:
  248. *
  249. */
  250. static int hostap_get_info_sta(PSDevice pDevice,
  251. struct viawget_hostapd_param *param)
  252. {
  253. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  254. unsigned int uNodeIndex;
  255. if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
  256. param->u.get_info_sta.inactive_sec =
  257. (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
  258. //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts;
  259. }
  260. else {
  261. return -ENOENT;
  262. }
  263. return 0;
  264. }
  265. /*
  266. * Description:
  267. * reset txexec
  268. *
  269. * Parameters:
  270. * In:
  271. * pDevice -
  272. * param -
  273. * Out:
  274. * TURE, FALSE
  275. *
  276. * Return Value:
  277. *
  278. */
  279. /*
  280. static int hostap_reset_txexc_sta(PSDevice pDevice,
  281. struct viawget_hostapd_param *param)
  282. {
  283. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  284. unsigned int uNodeIndex;
  285. if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
  286. pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0;
  287. }
  288. else {
  289. return -ENOENT;
  290. }
  291. return 0;
  292. }
  293. */
  294. /*
  295. * Description:
  296. * set station flag
  297. *
  298. * Parameters:
  299. * In:
  300. * pDevice -
  301. * param -
  302. * Out:
  303. *
  304. * Return Value:
  305. *
  306. */
  307. static int hostap_set_flags_sta(PSDevice pDevice,
  308. struct viawget_hostapd_param *param)
  309. {
  310. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  311. unsigned int uNodeIndex;
  312. if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
  313. pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or;
  314. pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and;
  315. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " dwFlags = %x\n",
  316. (unsigned int) pMgmt->sNodeDBTable[uNodeIndex].dwFlags);
  317. }
  318. else {
  319. return -ENOENT;
  320. }
  321. return 0;
  322. }
  323. /*
  324. * Description:
  325. * set generic element (wpa ie)
  326. *
  327. * Parameters:
  328. * In:
  329. * pDevice -
  330. * param -
  331. * Out:
  332. *
  333. * Return Value:
  334. *
  335. */
  336. static int hostap_set_generic_element(PSDevice pDevice,
  337. struct viawget_hostapd_param *param)
  338. {
  339. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  340. memcpy( pMgmt->abyWPAIE,
  341. param->u.generic_elem.data,
  342. param->u.generic_elem.len
  343. );
  344. pMgmt->wWPAIELen = param->u.generic_elem.len;
  345. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen);
  346. // disable wpa
  347. if (pMgmt->wWPAIELen == 0) {
  348. pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
  349. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " No WPAIE, Disable WPA \n");
  350. } else {
  351. // enable wpa
  352. if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) ||
  353. (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) {
  354. pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
  355. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n");
  356. } else
  357. return -EINVAL;
  358. }
  359. return 0;
  360. }
  361. /*
  362. * Description:
  363. * flush station nodes table.
  364. *
  365. * Parameters:
  366. * In:
  367. * pDevice -
  368. * Out:
  369. *
  370. * Return Value:
  371. *
  372. */
  373. static void hostap_flush_sta(PSDevice pDevice)
  374. {
  375. // reserved node index =0 for multicast node.
  376. BSSvClearNodeDBTable(pDevice, 1);
  377. pDevice->uAssocCount = 0;
  378. return;
  379. }
  380. /*
  381. * Description:
  382. * set each stations encryption key
  383. *
  384. * Parameters:
  385. * In:
  386. * pDevice -
  387. * param -
  388. * Out:
  389. *
  390. * Return Value:
  391. *
  392. */
  393. static int hostap_set_encryption(PSDevice pDevice,
  394. struct viawget_hostapd_param *param,
  395. int param_len)
  396. {
  397. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  398. DWORD dwKeyIndex = 0;
  399. BYTE abyKey[MAX_KEY_LEN];
  400. BYTE abySeq[MAX_KEY_LEN];
  401. NDIS_802_11_KEY_RSC KeyRSC;
  402. BYTE byKeyDecMode = KEY_CTL_WEP;
  403. int ret = 0;
  404. int iNodeIndex = -1;
  405. int ii;
  406. BOOL bKeyTableFull = FALSE;
  407. WORD wKeyCtl = 0;
  408. param->u.crypt.err = 0;
  409. /*
  410. if (param_len !=
  411. (int) ((char *) param->u.crypt.key - (char *) param) +
  412. param->u.crypt.key_len)
  413. return -EINVAL;
  414. */
  415. if (param->u.crypt.alg > WPA_ALG_CCMP)
  416. return -EINVAL;
  417. if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
  418. param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
  419. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
  420. return -EINVAL;
  421. }
  422. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  423. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  424. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
  425. if (param->u.crypt.idx >= MAX_GROUP_KEY)
  426. return -EINVAL;
  427. iNodeIndex = 0;
  428. } else {
  429. if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) {
  430. param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
  431. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
  432. return -EINVAL;
  433. }
  434. }
  435. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex);
  436. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg);
  437. if (param->u.crypt.alg == WPA_ALG_NONE) {
  438. if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == TRUE) {
  439. if (KeybRemoveKey( pDevice,
  440. &(pDevice->sKey),
  441. param->sta_addr,
  442. pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex
  443. ) == FALSE) {
  444. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
  445. }
  446. pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
  447. }
  448. pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
  449. pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
  450. pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
  451. pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
  452. pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
  453. pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
  454. pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
  455. memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
  456. 0,
  457. MAX_KEY_LEN
  458. );
  459. return ret;
  460. }
  461. memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
  462. // copy to node key tbl
  463. pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
  464. pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
  465. memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
  466. param->u.crypt.key,
  467. param->u.crypt.key_len
  468. );
  469. dwKeyIndex = (DWORD)(param->u.crypt.idx);
  470. if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
  471. pDevice->byKeyIndex = (BYTE)dwKeyIndex;
  472. pDevice->bTransmitKey = TRUE;
  473. dwKeyIndex |= (1 << 31);
  474. }
  475. if (param->u.crypt.alg == WPA_ALG_WEP) {
  476. if ((pDevice->bEnable8021x == FALSE) || (iNodeIndex == 0)) {
  477. KeybSetDefaultKey( pDevice,
  478. &(pDevice->sKey),
  479. dwKeyIndex & ~(BIT30 | USE_KEYRSC),
  480. param->u.crypt.key_len,
  481. NULL,
  482. abyKey,
  483. KEY_CTL_WEP
  484. );
  485. } else {
  486. // 8021x enable, individual key
  487. dwKeyIndex |= (1 << 30); // set pairwise key
  488. if (KeybSetKey(pDevice,
  489. &(pDevice->sKey),
  490. &param->sta_addr[0],
  491. dwKeyIndex & ~(USE_KEYRSC),
  492. param->u.crypt.key_len,
  493. (PQWORD) &(KeyRSC),
  494. (PBYTE)abyKey,
  495. KEY_CTL_WEP
  496. ) == TRUE) {
  497. pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
  498. } else {
  499. // Key Table Full
  500. pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
  501. bKeyTableFull = TRUE;
  502. }
  503. }
  504. pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
  505. pDevice->bEncryptionEnable = TRUE;
  506. pMgmt->byCSSPK = KEY_CTL_WEP;
  507. pMgmt->byCSSGK = KEY_CTL_WEP;
  508. pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
  509. pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
  510. return ret;
  511. }
  512. if (param->u.crypt.seq) {
  513. memcpy(&abySeq, param->u.crypt.seq, 8);
  514. for (ii = 0 ; ii < 8 ; ii++) {
  515. KeyRSC |= (abySeq[ii] << (ii * 8));
  516. }
  517. dwKeyIndex |= 1 << 29;
  518. pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC;
  519. }
  520. if (param->u.crypt.alg == WPA_ALG_TKIP) {
  521. if (param->u.crypt.key_len != MAX_KEY_LEN)
  522. return -EINVAL;
  523. pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
  524. byKeyDecMode = KEY_CTL_TKIP;
  525. pMgmt->byCSSPK = KEY_CTL_TKIP;
  526. pMgmt->byCSSGK = KEY_CTL_TKIP;
  527. }
  528. if (param->u.crypt.alg == WPA_ALG_CCMP) {
  529. if ((param->u.crypt.key_len != AES_KEY_LEN) ||
  530. (pDevice->byLocalID <= REV_ID_VT3253_A1))
  531. return -EINVAL;
  532. pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
  533. byKeyDecMode = KEY_CTL_CCMP;
  534. pMgmt->byCSSPK = KEY_CTL_CCMP;
  535. pMgmt->byCSSGK = KEY_CTL_CCMP;
  536. }
  537. if (iNodeIndex == 0) {
  538. KeybSetDefaultKey( pDevice,
  539. &(pDevice->sKey),
  540. dwKeyIndex,
  541. param->u.crypt.key_len,
  542. (PQWORD) &(KeyRSC),
  543. abyKey,
  544. byKeyDecMode
  545. );
  546. pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
  547. } else {
  548. dwKeyIndex |= (1 << 30); // set pairwise key
  549. if (KeybSetKey(pDevice,
  550. &(pDevice->sKey),
  551. &param->sta_addr[0],
  552. dwKeyIndex,
  553. param->u.crypt.key_len,
  554. (PQWORD) &(KeyRSC),
  555. (PBYTE)abyKey,
  556. byKeyDecMode
  557. ) == TRUE) {
  558. pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
  559. } else {
  560. // Key Table Full
  561. pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
  562. bKeyTableFull = TRUE;
  563. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
  564. }
  565. }
  566. if (bKeyTableFull == TRUE) {
  567. wKeyCtl &= 0x7F00; // clear all key control filed
  568. wKeyCtl |= (byKeyDecMode << 4);
  569. wKeyCtl |= (byKeyDecMode);
  570. wKeyCtl |= 0x0044; // use group key for all address
  571. wKeyCtl |= 0x4000; // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int
  572. // Todo.. xxxxxx
  573. //MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
  574. }
  575. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex);
  576. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx,
  577. param->u.crypt.key_len );
  578. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
  579. pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
  580. pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
  581. pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
  582. pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
  583. pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]
  584. );
  585. // set wep key
  586. pDevice->bEncryptionEnable = TRUE;
  587. pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
  588. pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
  589. pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
  590. pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
  591. return ret;
  592. }
  593. /*
  594. * Description:
  595. * get each stations encryption key
  596. *
  597. * Parameters:
  598. * In:
  599. * pDevice -
  600. * param -
  601. * Out:
  602. *
  603. * Return Value:
  604. *
  605. */
  606. static int hostap_get_encryption(PSDevice pDevice,
  607. struct viawget_hostapd_param *param,
  608. int param_len)
  609. {
  610. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  611. int ret = 0;
  612. int ii;
  613. int iNodeIndex =0;
  614. param->u.crypt.err = 0;
  615. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  616. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  617. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
  618. iNodeIndex = 0;
  619. } else {
  620. if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) {
  621. param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
  622. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
  623. return -EINVAL;
  624. }
  625. }
  626. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex);
  627. memset(param->u.crypt.seq, 0, 8);
  628. for (ii = 0 ; ii < 8 ; ii++) {
  629. param->u.crypt.seq[ii] = (BYTE)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
  630. }
  631. return ret;
  632. }
  633. /*
  634. * Description:
  635. * vt6656_hostap_ioctl main function supported for hostap deamon.
  636. *
  637. * Parameters:
  638. * In:
  639. * pDevice -
  640. * iw_point -
  641. * Out:
  642. *
  643. * Return Value:
  644. *
  645. */
  646. int vt6656_hostap_ioctl(PSDevice pDevice, struct iw_point *p)
  647. {
  648. struct viawget_hostapd_param *param;
  649. int ret = 0;
  650. int ap_ioctl = 0;
  651. if (p->length < sizeof(struct viawget_hostapd_param) ||
  652. p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
  653. return -EINVAL;
  654. param = kmalloc((int)p->length, (int)GFP_KERNEL);
  655. if (param == NULL)
  656. return -ENOMEM;
  657. if (copy_from_user(param, p->pointer, p->length)) {
  658. ret = -EFAULT;
  659. goto out;
  660. }
  661. switch (param->cmd) {
  662. case VIAWGET_HOSTAPD_SET_ENCRYPTION:
  663. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n");
  664. spin_lock_irq(&pDevice->lock);
  665. ret = hostap_set_encryption(pDevice, param, p->length);
  666. spin_unlock_irq(&pDevice->lock);
  667. break;
  668. case VIAWGET_HOSTAPD_GET_ENCRYPTION:
  669. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n");
  670. spin_lock_irq(&pDevice->lock);
  671. ret = hostap_get_encryption(pDevice, param, p->length);
  672. spin_unlock_irq(&pDevice->lock);
  673. break;
  674. case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR:
  675. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n");
  676. return -EOPNOTSUPP;
  677. break;
  678. case VIAWGET_HOSTAPD_FLUSH:
  679. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n");
  680. spin_lock_irq(&pDevice->lock);
  681. hostap_flush_sta(pDevice);
  682. spin_unlock_irq(&pDevice->lock);
  683. break;
  684. case VIAWGET_HOSTAPD_ADD_STA:
  685. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n");
  686. spin_lock_irq(&pDevice->lock);
  687. ret = hostap_add_sta(pDevice, param);
  688. spin_unlock_irq(&pDevice->lock);
  689. break;
  690. case VIAWGET_HOSTAPD_REMOVE_STA:
  691. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n");
  692. spin_lock_irq(&pDevice->lock);
  693. ret = hostap_remove_sta(pDevice, param);
  694. spin_unlock_irq(&pDevice->lock);
  695. break;
  696. case VIAWGET_HOSTAPD_GET_INFO_STA:
  697. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n");
  698. ret = hostap_get_info_sta(pDevice, param);
  699. ap_ioctl = 1;
  700. break;
  701. /*
  702. case VIAWGET_HOSTAPD_RESET_TXEXC_STA:
  703. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_RESET_TXEXC_STA \n");
  704. ret = hostap_reset_txexc_sta(pDevice, param);
  705. break;
  706. */
  707. case VIAWGET_HOSTAPD_SET_FLAGS_STA:
  708. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n");
  709. ret = hostap_set_flags_sta(pDevice, param);
  710. break;
  711. case VIAWGET_HOSTAPD_MLME:
  712. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
  713. return -EOPNOTSUPP;
  714. case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT:
  715. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n");
  716. ret = hostap_set_generic_element(pDevice, param);
  717. break;
  718. case VIAWGET_HOSTAPD_SCAN_REQ:
  719. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
  720. return -EOPNOTSUPP;
  721. case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
  722. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
  723. return -EOPNOTSUPP;
  724. default:
  725. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vt6656_hostap_ioctl: unknown cmd=%d\n",
  726. (int)param->cmd);
  727. return -EOPNOTSUPP;
  728. break;
  729. }
  730. if ((ret == 0) && ap_ioctl) {
  731. if (copy_to_user(p->pointer, param, p->length)) {
  732. ret = -EFAULT;
  733. goto out;
  734. }
  735. }
  736. out:
  737. kfree(param);
  738. return ret;
  739. }