ioctl.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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: ioctl.c
  20. *
  21. * Purpose: private ioctl functions
  22. *
  23. * Author: Lyndon Chen
  24. *
  25. * Date: Auguest 20, 2003
  26. *
  27. * Functions:
  28. *
  29. * Revision History:
  30. *
  31. */
  32. #include "ioctl.h"
  33. #include "iocmd.h"
  34. #include "mac.h"
  35. #include "card.h"
  36. #include "hostap.h"
  37. #include "wpactl.h"
  38. #include "rf.h"
  39. /*--------------------- Static Definitions -------------------------*/
  40. /*--------------------- Static Classes ----------------------------*/
  41. /*--------------------- Static Variables --------------------------*/
  42. //static int msglevel =MSG_LEVEL_DEBUG;
  43. static int msglevel =MSG_LEVEL_INFO;
  44. #ifdef WPA_SM_Transtatus
  45. SWPAResult wpa_Result;
  46. #endif
  47. /*--------------------- Static Functions --------------------------*/
  48. /*--------------------- Export Variables --------------------------*/
  49. int private_ioctl(PSDevice pDevice, struct ifreq *rq) {
  50. PSCmdRequest pReq = (PSCmdRequest)rq;
  51. PSMgmtObject pMgmt = pDevice->pMgmt;
  52. int result = 0;
  53. PWLAN_IE_SSID pItemSSID;
  54. SCmdBSSJoin sJoinCmd;
  55. SCmdZoneTypeSet sZoneTypeCmd;
  56. SCmdScan sScanCmd;
  57. SCmdStartAP sStartAPCmd;
  58. SCmdSetWEP sWEPCmd;
  59. SCmdValue sValue;
  60. SBSSIDList sList;
  61. SNodeList sNodeList;
  62. PSBSSIDList pList;
  63. PSNodeList pNodeList;
  64. unsigned int cbListCount;
  65. PKnownBSS pBSS;
  66. PKnownNodeDB pNode;
  67. unsigned int ii, jj;
  68. SCmdLinkStatus sLinkStatus;
  69. unsigned char abySuppRates[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
  70. unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  71. unsigned long dwKeyIndex= 0;
  72. unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
  73. long ldBm;
  74. pReq->wResult = 0;
  75. switch (pReq->wCmdCode) {
  76. case WLAN_CMD_BSS_SCAN:
  77. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_BSS_SCAN..begin \n");
  78. if (copy_from_user(&sScanCmd, pReq->data, sizeof(SCmdScan))) {
  79. result = -EFAULT;
  80. break;
  81. }
  82. pItemSSID = (PWLAN_IE_SSID)sScanCmd.ssid;
  83. if (pItemSSID->len != 0) {
  84. memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  85. memcpy(abyScanSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
  86. }
  87. if (pDevice->bMACSuspend == true) {
  88. if (pDevice->bRadioOff == true)
  89. CARDbRadioPowerOn(pDevice);
  90. vMgrTimerInit(pDevice);
  91. MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
  92. add_timer(&pMgmt->sTimerSecondCallback);
  93. pDevice->bMACSuspend = false;
  94. }
  95. spin_lock_irq(&pDevice->lock);
  96. if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0)
  97. BSSvClearBSSList((void *)pDevice, false);
  98. else
  99. BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
  100. if (pItemSSID->len != 0)
  101. bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
  102. else
  103. bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
  104. spin_unlock_irq(&pDevice->lock);
  105. break;
  106. case WLAN_CMD_ZONETYPE_SET:
  107. //mike add :cann't support.
  108. result=-EOPNOTSUPP;
  109. break;
  110. if (copy_from_user(&sZoneTypeCmd, pReq->data, sizeof(SCmdZoneTypeSet))) {
  111. result = -EFAULT;
  112. break;
  113. }
  114. if(sZoneTypeCmd.bWrite==true) {
  115. //////write zonetype
  116. if(sZoneTypeCmd.ZoneType == ZoneType_USA) {
  117. //set to USA
  118. printk("set_ZoneType:USA\n");
  119. }
  120. else if(sZoneTypeCmd.ZoneType == ZoneType_Japan) {
  121. //set to Japan
  122. printk("set_ZoneType:Japan\n");
  123. }
  124. else if(sZoneTypeCmd.ZoneType == ZoneType_Europe) {
  125. //set to Europe
  126. printk("set_ZoneType:Europe\n");
  127. }
  128. }
  129. else {
  130. ///////read zonetype
  131. unsigned char zonetype=0;
  132. if(zonetype == 0x00) { //USA
  133. sZoneTypeCmd.ZoneType = ZoneType_USA;
  134. }
  135. else if(zonetype == 0x01) { //Japan
  136. sZoneTypeCmd.ZoneType = ZoneType_Japan;
  137. }
  138. else if(zonetype == 0x02) { //Europe
  139. sZoneTypeCmd.ZoneType = ZoneType_Europe;
  140. }
  141. else { //Unknown ZoneType
  142. printk("Error:ZoneType[%x] Unknown ???\n",zonetype);
  143. result = -EFAULT;
  144. break;
  145. }
  146. if (copy_to_user(pReq->data, &sZoneTypeCmd, sizeof(SCmdZoneTypeSet))) {
  147. result = -EFAULT;
  148. break;
  149. }
  150. }
  151. break;
  152. case WLAN_CMD_BSS_JOIN:
  153. if (pDevice->bMACSuspend == true) {
  154. if (pDevice->bRadioOff == true)
  155. CARDbRadioPowerOn(pDevice);
  156. vMgrTimerInit(pDevice);
  157. MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
  158. add_timer(&pMgmt->sTimerSecondCallback);
  159. pDevice->bMACSuspend = false;
  160. }
  161. if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) {
  162. result = -EFAULT;
  163. break;
  164. }
  165. pItemSSID = (PWLAN_IE_SSID)sJoinCmd.ssid;
  166. memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  167. memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
  168. if (sJoinCmd.wBSSType == ADHOC) {
  169. pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
  170. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to adhoc mode\n");
  171. }
  172. else {
  173. pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
  174. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to STA mode\n");
  175. }
  176. if (sJoinCmd.bPSEnable == true) {
  177. pDevice->ePSMode = WMAC_POWER_FAST;
  178. // pDevice->ePSMode = WMAC_POWER_MAX;
  179. pMgmt->wListenInterval = 2;
  180. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving On\n");
  181. }
  182. else {
  183. pDevice->ePSMode = WMAC_POWER_CAM;
  184. pMgmt->wListenInterval = 1;
  185. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving Off \n");
  186. }
  187. if (sJoinCmd.bShareKeyAuth == true){
  188. pMgmt->bShareKeyAlgorithm = true;
  189. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
  190. }
  191. else {
  192. pMgmt->bShareKeyAlgorithm = false;
  193. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
  194. }
  195. pDevice->uChannel = sJoinCmd.uChannel;
  196. netif_stop_queue(pDevice->dev);
  197. spin_lock_irq(&pDevice->lock);
  198. pMgmt->eCurrState = WMAC_STATE_IDLE;
  199. bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
  200. bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
  201. spin_unlock_irq(&pDevice->lock);
  202. break;
  203. case WLAN_CMD_SET_WEP:
  204. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WEP Key. \n");
  205. memset(&sWEPCmd, 0 ,sizeof(SCmdSetWEP));
  206. if (copy_from_user(&sWEPCmd, pReq->data, sizeof(SCmdSetWEP))) {
  207. result = -EFAULT;
  208. break;
  209. }
  210. if (sWEPCmd.bEnableWep != true) {
  211. pDevice->bEncryptionEnable = false;
  212. pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
  213. MACvDisableDefaultKey(pDevice->PortOffset);
  214. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP function disable. \n");
  215. break;
  216. }
  217. for (ii = 0; ii < WLAN_WEP_NKEYS; ii ++) {
  218. if (sWEPCmd.bWepKeyAvailable[ii]) {
  219. if (ii == sWEPCmd.byKeyIndex)
  220. //2006-1123-02,<Modify> by EinsnLiu
  221. //Evaluate the "dwKeyIndex" error
  222. // dwKeyIndex |= (1 << 31);
  223. dwKeyIndex =ii|(1 << 31);
  224. else
  225. dwKeyIndex = ii;
  226. KeybSetDefaultKey(&(pDevice->sKey),
  227. dwKeyIndex,
  228. sWEPCmd.auWepKeyLength[ii],
  229. NULL,
  230. (unsigned char *)&sWEPCmd.abyWepKey[ii][0],
  231. KEY_CTL_WEP,
  232. pDevice->PortOffset,
  233. pDevice->byLocalID);
  234. }
  235. }
  236. pDevice->byKeyIndex = sWEPCmd.byKeyIndex;
  237. pDevice->bTransmitKey = true;
  238. pDevice->bEncryptionEnable = true;
  239. pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
  240. break;
  241. case WLAN_CMD_GET_LINK:
  242. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_GET_LINK status. \n");
  243. memset(sLinkStatus.abySSID, 0 , WLAN_SSID_MAXLEN + 1);
  244. if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
  245. sLinkStatus.wBSSType = ADHOC;
  246. else
  247. sLinkStatus.wBSSType = INFRA;
  248. if (pMgmt->eCurrState == WMAC_STATE_JOINTED)
  249. sLinkStatus.byState = ADHOC_JOINTED;
  250. else
  251. sLinkStatus.byState = ADHOC_STARTED;
  252. sLinkStatus.uChannel = pMgmt->uCurrChannel;
  253. if (pDevice->bLinkPass == true) {
  254. sLinkStatus.bLink = true;
  255. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  256. memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len);
  257. memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  258. sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate;
  259. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Link Success ! \n");
  260. }
  261. else {
  262. sLinkStatus.bLink = false;
  263. }
  264. if (copy_to_user(pReq->data, &sLinkStatus, sizeof(SCmdLinkStatus))) {
  265. result = -EFAULT;
  266. break;
  267. }
  268. break;
  269. case WLAN_CMD_GET_LISTLEN:
  270. cbListCount = 0;
  271. pBSS = &(pMgmt->sBSSList[0]);
  272. for (ii = 0; ii < MAX_BSS_NUM; ii++) {
  273. pBSS = &(pMgmt->sBSSList[ii]);
  274. if (!pBSS->bActive)
  275. continue;
  276. cbListCount++;
  277. }
  278. sList.uItem = cbListCount;
  279. if (copy_to_user(pReq->data, &sList, sizeof(SBSSIDList))) {
  280. result = -EFAULT;
  281. break;
  282. }
  283. pReq->wResult = 0;
  284. break;
  285. case WLAN_CMD_GET_LIST:
  286. if (copy_from_user(&sList, pReq->data, sizeof(SBSSIDList))) {
  287. result = -EFAULT;
  288. break;
  289. }
  290. pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)), (int)GFP_ATOMIC);
  291. if (pList == NULL) {
  292. result = -ENOMEM;
  293. break;
  294. }
  295. pList->uItem = sList.uItem;
  296. pBSS = &(pMgmt->sBSSList[0]);
  297. for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
  298. pBSS = &(pMgmt->sBSSList[jj]);
  299. if (pBSS->bActive) {
  300. pList->sBSSIDList[ii].uChannel = pBSS->uChannel;
  301. pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval;
  302. pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo;
  303. // pList->sBSSIDList[ii].uRSSI = pBSS->uRSSI;
  304. RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
  305. pList->sBSSIDList[ii].uRSSI = (unsigned int)ldBm;
  306. memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN);
  307. pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
  308. memset(pList->sBSSIDList[ii].abySSID, 0, WLAN_SSID_MAXLEN + 1);
  309. memcpy(pList->sBSSIDList[ii].abySSID, pItemSSID->abySSID, pItemSSID->len);
  310. if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
  311. pList->sBSSIDList[ii].byNetType = INFRA;
  312. }
  313. else {
  314. pList->sBSSIDList[ii].byNetType = ADHOC;
  315. }
  316. if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
  317. pList->sBSSIDList[ii].bWEPOn = true;
  318. }
  319. else {
  320. pList->sBSSIDList[ii].bWEPOn = false;
  321. }
  322. ii ++;
  323. if (ii >= pList->uItem)
  324. break;
  325. }
  326. }
  327. if (copy_to_user(pReq->data, pList, sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)))) {
  328. result = -EFAULT;
  329. break;
  330. }
  331. kfree(pList);
  332. pReq->wResult = 0;
  333. break;
  334. case WLAN_CMD_GET_MIB:
  335. if (copy_to_user(pReq->data, &(pDevice->s802_11Counter), sizeof(SDot11MIBCount))) {
  336. result = -EFAULT;
  337. break;
  338. }
  339. break;
  340. case WLAN_CMD_GET_STAT:
  341. if (copy_to_user(pReq->data, &(pDevice->scStatistic), sizeof(SStatCounter))) {
  342. result = -EFAULT;
  343. break;
  344. }
  345. break;
  346. case WLAN_CMD_STOP_MAC:
  347. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_STOP_MAC\n");
  348. netif_stop_queue(pDevice->dev);
  349. spin_lock_irq(&pDevice->lock);
  350. if (pDevice->bRadioOff == false) {
  351. CARDbRadioPowerOff(pDevice);
  352. }
  353. pDevice->bLinkPass = false;
  354. memset(pMgmt->abyCurrBSSID, 0, 6);
  355. pMgmt->eCurrState = WMAC_STATE_IDLE;
  356. del_timer(&pDevice->sTimerCommand);
  357. del_timer(&pMgmt->sTimerSecondCallback);
  358. pDevice->bCmdRunning = false;
  359. pDevice->bMACSuspend = true;
  360. MACvIntDisable(pDevice->PortOffset);
  361. spin_unlock_irq(&pDevice->lock);
  362. break;
  363. case WLAN_CMD_START_MAC:
  364. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_START_MAC\n");
  365. if (pDevice->bMACSuspend == true) {
  366. if (pDevice->bRadioOff == true)
  367. CARDbRadioPowerOn(pDevice);
  368. vMgrTimerInit(pDevice);
  369. MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
  370. add_timer(&pMgmt->sTimerSecondCallback);
  371. pDevice->bMACSuspend = false;
  372. }
  373. break;
  374. case WLAN_CMD_SET_HOSTAPD:
  375. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD\n");
  376. if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
  377. result = -EFAULT;
  378. break;
  379. }
  380. if (sValue.dwValue == 1) {
  381. if (vt6655_hostap_set_hostapd(pDevice, 1, 1) == 0){
  382. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HOSTAP\n");
  383. }
  384. else {
  385. result = -EFAULT;
  386. break;
  387. }
  388. }
  389. else {
  390. vt6655_hostap_set_hostapd(pDevice, 0, 1);
  391. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HOSTAP\n");
  392. }
  393. break;
  394. case WLAN_CMD_SET_HOSTAPD_STA:
  395. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD_STA\n");
  396. break;
  397. case WLAN_CMD_SET_802_1X:
  398. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_802_1X\n");
  399. if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
  400. result = -EFAULT;
  401. break;
  402. }
  403. if (sValue.dwValue == 1) {
  404. pDevice->bEnable8021x = true;
  405. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable 802.1x\n");
  406. }
  407. else {
  408. pDevice->bEnable8021x = false;
  409. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable 802.1x\n");
  410. }
  411. break;
  412. case WLAN_CMD_SET_HOST_WEP:
  413. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOST_WEP\n");
  414. if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
  415. result = -EFAULT;
  416. break;
  417. }
  418. if (sValue.dwValue == 1) {
  419. pDevice->bEnableHostWEP = true;
  420. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HostWEP\n");
  421. }
  422. else {
  423. pDevice->bEnableHostWEP = false;
  424. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HostWEP\n");
  425. }
  426. break;
  427. case WLAN_CMD_SET_WPA:
  428. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WPA\n");
  429. if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
  430. result = -EFAULT;
  431. break;
  432. }
  433. if (sValue.dwValue == 1) {
  434. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "up wpadev\n");
  435. memcpy(pDevice->wpadev->dev_addr, pDevice->dev->dev_addr, ETH_ALEN);
  436. pDevice->bWPADEVUp = true;
  437. }
  438. else {
  439. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "close wpadev\n");
  440. pDevice->bWPADEVUp = false;
  441. }
  442. break;
  443. case WLAN_CMD_AP_START:
  444. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_AP_START\n");
  445. if (pDevice->bRadioOff == true) {
  446. CARDbRadioPowerOn(pDevice);
  447. vMgrTimerInit(pDevice);
  448. MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
  449. add_timer(&pMgmt->sTimerSecondCallback);
  450. }
  451. if (copy_from_user(&sStartAPCmd, pReq->data, sizeof(SCmdStartAP))) {
  452. result = -EFAULT;
  453. break;
  454. }
  455. if (sStartAPCmd.wBSSType == AP) {
  456. pMgmt->eConfigMode = WMAC_CONFIG_AP;
  457. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to AP mode\n");
  458. }
  459. else {
  460. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct BSS type not set to AP mode\n");
  461. result = -EFAULT;
  462. break;
  463. }
  464. if (sStartAPCmd.wBBPType == PHY80211g) {
  465. pMgmt->byAPBBType = PHY_TYPE_11G;
  466. }
  467. else if (sStartAPCmd.wBBPType == PHY80211a) {
  468. pMgmt->byAPBBType = PHY_TYPE_11A;
  469. }
  470. else {
  471. pMgmt->byAPBBType = PHY_TYPE_11B;
  472. }
  473. pItemSSID = (PWLAN_IE_SSID)sStartAPCmd.ssid;
  474. memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  475. memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
  476. if ((sStartAPCmd.uChannel > 0)&&(sStartAPCmd.uChannel <= 14))
  477. pDevice->uChannel = sStartAPCmd.uChannel;
  478. if ((sStartAPCmd.uBeaconInt >= 20) && (sStartAPCmd.uBeaconInt <= 1000))
  479. pMgmt->wIBSSBeaconPeriod = sStartAPCmd.uBeaconInt;
  480. else
  481. pMgmt->wIBSSBeaconPeriod = 100;
  482. if (sStartAPCmd.bShareKeyAuth == true){
  483. pMgmt->bShareKeyAlgorithm = true;
  484. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
  485. }
  486. else {
  487. pMgmt->bShareKeyAlgorithm = false;
  488. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
  489. }
  490. memcpy(pMgmt->abyIBSSSuppRates, abySuppRates, 6);
  491. if (sStartAPCmd.byBasicRate & BIT3) {
  492. pMgmt->abyIBSSSuppRates[2] |= BIT7;
  493. pMgmt->abyIBSSSuppRates[3] |= BIT7;
  494. pMgmt->abyIBSSSuppRates[4] |= BIT7;
  495. pMgmt->abyIBSSSuppRates[5] |= BIT7;
  496. }else if (sStartAPCmd.byBasicRate & BIT2) {
  497. pMgmt->abyIBSSSuppRates[2] |= BIT7;
  498. pMgmt->abyIBSSSuppRates[3] |= BIT7;
  499. pMgmt->abyIBSSSuppRates[4] |= BIT7;
  500. }else if (sStartAPCmd.byBasicRate & BIT1) {
  501. pMgmt->abyIBSSSuppRates[2] |= BIT7;
  502. pMgmt->abyIBSSSuppRates[3] |= BIT7;
  503. }else if (sStartAPCmd.byBasicRate & BIT1) {
  504. pMgmt->abyIBSSSuppRates[2] |= BIT7;
  505. }else {
  506. //default 1,2M
  507. pMgmt->abyIBSSSuppRates[2] |= BIT7;
  508. pMgmt->abyIBSSSuppRates[3] |= BIT7;
  509. }
  510. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Support Rate= %x %x %x %x\n",
  511. pMgmt->abyIBSSSuppRates[2],
  512. pMgmt->abyIBSSSuppRates[3],
  513. pMgmt->abyIBSSSuppRates[4],
  514. pMgmt->abyIBSSSuppRates[5]
  515. );
  516. netif_stop_queue(pDevice->dev);
  517. spin_lock_irq(&pDevice->lock);
  518. bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
  519. spin_unlock_irq(&pDevice->lock);
  520. break;
  521. case WLAN_CMD_GET_NODE_CNT:
  522. cbListCount = 0;
  523. pNode = &(pMgmt->sNodeDBTable[0]);
  524. for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
  525. pNode = &(pMgmt->sNodeDBTable[ii]);
  526. if (!pNode->bActive)
  527. continue;
  528. cbListCount++;
  529. }
  530. sNodeList.uItem = cbListCount;
  531. if (copy_to_user(pReq->data, &sNodeList, sizeof(SNodeList))) {
  532. result = -EFAULT;
  533. break;
  534. }
  535. pReq->wResult = 0;
  536. break;
  537. case WLAN_CMD_GET_NODE_LIST:
  538. if (copy_from_user(&sNodeList, pReq->data, sizeof(SNodeList))) {
  539. result = -EFAULT;
  540. break;
  541. }
  542. pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), (int)GFP_ATOMIC);
  543. if (pNodeList == NULL) {
  544. result = -ENOMEM;
  545. break;
  546. }
  547. pNodeList->uItem = sNodeList.uItem;
  548. pNode = &(pMgmt->sNodeDBTable[0]);
  549. for (ii = 0, jj = 0; ii < (MAX_NODE_NUM + 1); ii++) {
  550. pNode = &(pMgmt->sNodeDBTable[ii]);
  551. if (pNode->bActive) {
  552. pNodeList->sNodeList[jj].wAID = pNode->wAID;
  553. memcpy(pNodeList->sNodeList[jj].abyMACAddr, pNode->abyMACAddr, WLAN_ADDR_LEN);
  554. pNodeList->sNodeList[jj].wTxDataRate = pNode->wTxDataRate;
  555. pNodeList->sNodeList[jj].wInActiveCount = (unsigned short)pNode->uInActiveCount;
  556. pNodeList->sNodeList[jj].wEnQueueCnt = (unsigned short)pNode->wEnQueueCnt;
  557. pNodeList->sNodeList[jj].wFlags = (unsigned short)pNode->dwFlags;
  558. pNodeList->sNodeList[jj].bPWBitOn = pNode->bPSEnable;
  559. pNodeList->sNodeList[jj].byKeyIndex = pNode->byKeyIndex;
  560. pNodeList->sNodeList[jj].wWepKeyLength = pNode->uWepKeyLength;
  561. memcpy(&(pNodeList->sNodeList[jj].abyWepKey[0]), &(pNode->abyWepKey[0]), WEP_KEYMAXLEN);
  562. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key= %2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
  563. pNodeList->sNodeList[jj].abyWepKey[0],
  564. pNodeList->sNodeList[jj].abyWepKey[1],
  565. pNodeList->sNodeList[jj].abyWepKey[2],
  566. pNodeList->sNodeList[jj].abyWepKey[3],
  567. pNodeList->sNodeList[jj].abyWepKey[4]
  568. );
  569. pNodeList->sNodeList[jj].bIsInFallback = pNode->bIsInFallback;
  570. pNodeList->sNodeList[jj].uTxFailures = pNode->uTxFailures;
  571. pNodeList->sNodeList[jj].uTxAttempts = pNode->uTxAttempts;
  572. pNodeList->sNodeList[jj].wFailureRatio = (unsigned short)pNode->uFailureRatio;
  573. jj ++;
  574. if (jj >= pNodeList->uItem)
  575. break;
  576. }
  577. }
  578. if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) {
  579. result = -EFAULT;
  580. break;
  581. }
  582. kfree(pNodeList);
  583. pReq->wResult = 0;
  584. break;
  585. #ifdef WPA_SM_Transtatus
  586. case 0xFF:
  587. memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
  588. wpa_Result.proto = 0;
  589. wpa_Result.key_mgmt = 0;
  590. wpa_Result.eap_type = 0;
  591. wpa_Result.authenticated = false;
  592. pDevice->fWPA_Authened = false;
  593. if (copy_from_user(&wpa_Result, pReq->data, sizeof(wpa_Result))) {
  594. result = -EFAULT;
  595. break;
  596. }
  597. if(wpa_Result.authenticated==true) {
  598. #ifdef SndEvt_ToAPI
  599. {
  600. union iwreq_data wrqu;
  601. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  602. memset(&wrqu, 0, sizeof(wrqu));
  603. wrqu.data.flags = RT_WPACONNECTED_EVENT_FLAG;
  604. wrqu.data.length =pItemSSID->len;
  605. wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pItemSSID->abySSID);
  606. }
  607. #endif
  608. pDevice->fWPA_Authened = true; //is successful peer to wpa_Result.authenticated?
  609. }
  610. //printk("get private wpa_supplicant announce WPA SM\n");
  611. //printk("wpa-->ifname=%s\n",wpa_Result.ifname);
  612. //printk("wpa-->proto=%d\n",wpa_Result.proto);
  613. //printk("wpa-->key-mgmt=%d\n",wpa_Result.key_mgmt);
  614. //printk("wpa-->eap_type=%d\n",wpa_Result.eap_type);
  615. //printk("wpa-->authenticated is %s\n",(wpa_Result.authenticated==true)?"true":"false");
  616. pReq->wResult = 0;
  617. break;
  618. #endif
  619. default:
  620. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Private command not support..\n");
  621. }
  622. return result;
  623. }
  624. /*
  625. void
  626. vConfigWEPKey (
  627. PSDevice pDevice,
  628. unsigned long dwKeyIndex,
  629. unsigned char *pbyKey,
  630. unsigned long uKeyLength
  631. )
  632. {
  633. int ii;
  634. memset(&pDevice->abyWepKey[dwKeyIndex][0], 0, WLAN_WEPMAX_KEYLEN);
  635. memcpy(&pDevice->abyWepKey[dwKeyIndex][0], pbyKey, uKeyLength);
  636. pDevice->bWepKeyAvailable[dwKeyIndex] = true;
  637. pDevice->auWepKeyLength[dwKeyIndex] = uKeyLength;
  638. MACvSetDefaultKeyEntry(pDevice->PortOffset, uKeyLength, dwKeyIndex,
  639. (unsigned long *) &(pDevice->abyWepKey[dwKeyIndex][0]), pDevice->byLocalID);
  640. if (pDevice->eEncryptionStatus < Ndis802_11EncryptionNotSupported) {
  641. for(ii=0; ii<MAX_GROUP_KEY; ii++) {
  642. if ((pDevice->bWepKeyAvailable[ii] == true) &&
  643. (pDevice->auWepKeyLength[ii] == WLAN_WEP232_KEYLEN)) {
  644. pDevice->uCurrentWEPMode = TX_WEP_SW232;
  645. MACvDisableDefaultKey(pDevice->PortOffset);
  646. break;
  647. }
  648. }
  649. if ((ii == MAX_GROUP_KEY) &&
  650. (pDevice->eEncryptionStatus < Ndis802_11EncryptionNotSupported)) {
  651. MACvEnableDefaultKey(pDevice->PortOffset, pDevice->byLocalID);
  652. }
  653. }
  654. }
  655. */