hostap.c 24 KB

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