ioctl.c 23 KB

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