bssdb.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  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: bssdb.c
  20. *
  21. * Purpose: Handles the Basic Service Set & Node Database functions
  22. *
  23. * Functions:
  24. * BSSpSearchBSSList - Search known BSS list for Desire SSID or BSSID
  25. * BSSvClearBSSList - Clear BSS List
  26. * BSSbInsertToBSSList - Insert a BSS set into known BSS list
  27. * BSSbUpdateToBSSList - Update BSS set in known BSS list
  28. * BSSDBbIsSTAInNodeDB - Search Node DB table to find the index of matched DstAddr
  29. * BSSvCreateOneNode - Allocate an Node for Node DB
  30. * BSSvUpdateAPNode - Update AP Node content in Index 0 of KnownNodeDB
  31. * BSSvSecondCallBack - One second timer callback function to update Node DB info & AP link status
  32. * BSSvUpdateNodeTxCounter - Update Tx attemps, Tx failure counter in Node DB for auto-fall back rate control
  33. *
  34. * Revision History:
  35. *
  36. * Author: Lyndon Chen
  37. *
  38. * Date: July 17, 2002
  39. *
  40. */
  41. #include "ttype.h"
  42. #include "tmacro.h"
  43. #include "tether.h"
  44. #include "device.h"
  45. #include "80211hdr.h"
  46. #include "bssdb.h"
  47. #include "wmgr.h"
  48. #include "datarate.h"
  49. #include "desc.h"
  50. #include "wcmd.h"
  51. #include "wpa.h"
  52. #include "baseband.h"
  53. #include "rf.h"
  54. #include "card.h"
  55. #include "channel.h"
  56. #include "mac.h"
  57. #include "wpa2.h"
  58. #include "iowpa.h"
  59. //#define PLICE_DEBUG
  60. /*--------------------- Static Definitions -------------------------*/
  61. /*--------------------- Static Classes ----------------------------*/
  62. /*--------------------- Static Variables --------------------------*/
  63. static int msglevel =MSG_LEVEL_INFO;
  64. //static int msglevel =MSG_LEVEL_DEBUG;
  65. const unsigned short awHWRetry0[5][5] = {
  66. {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
  67. {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
  68. {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
  69. {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
  70. {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
  71. };
  72. const unsigned short awHWRetry1[5][5] = {
  73. {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
  74. {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
  75. {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
  76. {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
  77. {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
  78. };
  79. /*--------------------- Static Functions --------------------------*/
  80. void s_vCheckSensitivity(
  81. void *hDeviceContext
  82. );
  83. #ifdef Calcu_LinkQual
  84. void s_uCalculateLinkQual(
  85. void *hDeviceContext
  86. );
  87. #endif
  88. void s_vCheckPreEDThreshold(
  89. void *hDeviceContext
  90. );
  91. /*--------------------- Export Variables --------------------------*/
  92. /*--------------------- Export Functions --------------------------*/
  93. /*+
  94. *
  95. * Routine Description:
  96. * Search known BSS list for Desire SSID or BSSID.
  97. *
  98. * Return Value:
  99. * PTR to KnownBSS or NULL
  100. *
  101. -*/
  102. PKnownBSS
  103. BSSpSearchBSSList(
  104. void *hDeviceContext,
  105. unsigned char *pbyDesireBSSID,
  106. unsigned char *pbyDesireSSID,
  107. CARD_PHY_TYPE ePhyType
  108. )
  109. {
  110. PSDevice pDevice = (PSDevice)hDeviceContext;
  111. PSMgmtObject pMgmt = pDevice->pMgmt;
  112. unsigned char *pbyBSSID = NULL;
  113. PWLAN_IE_SSID pSSID = NULL;
  114. PKnownBSS pCurrBSS = NULL;
  115. PKnownBSS pSelect = NULL;
  116. unsigned char ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
  117. unsigned int ii = 0;
  118. if (pbyDesireBSSID != NULL) {
  119. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSpSearchBSSList BSSID[%02X %02X %02X-%02X %02X %02X]\n",
  120. *pbyDesireBSSID,*(pbyDesireBSSID+1),*(pbyDesireBSSID+2),
  121. *(pbyDesireBSSID+3),*(pbyDesireBSSID+4),*(pbyDesireBSSID+5));
  122. if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
  123. (memcmp(pbyDesireBSSID, ZeroBSSID, 6)!= 0)){
  124. pbyBSSID = pbyDesireBSSID;
  125. }
  126. }
  127. if (pbyDesireSSID != NULL) {
  128. if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
  129. pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
  130. }
  131. }
  132. if (pbyBSSID != NULL) {
  133. // match BSSID first
  134. for (ii = 0; ii <MAX_BSS_NUM; ii++) {
  135. pCurrBSS = &(pMgmt->sBSSList[ii]);
  136. if(pDevice->bLinkPass==false) pCurrBSS->bSelected = false;
  137. if ((pCurrBSS->bActive) &&
  138. (pCurrBSS->bSelected == false)) {
  139. if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
  140. if (pSSID != NULL) {
  141. // compare ssid
  142. if ( !memcmp(pSSID->abySSID,
  143. ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
  144. pSSID->len)) {
  145. if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
  146. ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
  147. ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
  148. ) {
  149. pCurrBSS->bSelected = true;
  150. return(pCurrBSS);
  151. }
  152. }
  153. } else {
  154. if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
  155. ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
  156. ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
  157. ) {
  158. pCurrBSS->bSelected = true;
  159. return(pCurrBSS);
  160. }
  161. }
  162. }
  163. }
  164. }
  165. } else {
  166. // ignore BSSID
  167. for (ii = 0; ii <MAX_BSS_NUM; ii++) {
  168. pCurrBSS = &(pMgmt->sBSSList[ii]);
  169. //2007-0721-01<Add>by MikeLiu
  170. pCurrBSS->bSelected = false;
  171. if (pCurrBSS->bActive) {
  172. if (pSSID != NULL) {
  173. // matched SSID
  174. if (! !memcmp(pSSID->abySSID,
  175. ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
  176. pSSID->len) ||
  177. (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
  178. // SSID not match skip this BSS
  179. continue;
  180. }
  181. }
  182. if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
  183. ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
  184. ){
  185. // Type not match skip this BSS
  186. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
  187. continue;
  188. }
  189. if (ePhyType != PHY_TYPE_AUTO) {
  190. if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
  191. ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
  192. // PhyType not match skip this BSS
  193. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
  194. continue;
  195. }
  196. }
  197. /*
  198. if (pMgmt->eAuthenMode < WMAC_AUTH_WPA) {
  199. if (pCurrBSS->bWPAValid == true) {
  200. // WPA AP will reject connection of station without WPA enable.
  201. continue;
  202. }
  203. } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
  204. (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
  205. if (pCurrBSS->bWPAValid == false) {
  206. // station with WPA enable can't join NonWPA AP.
  207. continue;
  208. }
  209. } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
  210. (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
  211. if (pCurrBSS->bWPA2Valid == false) {
  212. // station with WPA2 enable can't join NonWPA2 AP.
  213. continue;
  214. }
  215. }
  216. */
  217. if (pSelect == NULL) {
  218. pSelect = pCurrBSS;
  219. } else {
  220. // compare RSSI, select signal strong one
  221. if (pCurrBSS->uRSSI < pSelect->uRSSI) {
  222. pSelect = pCurrBSS;
  223. }
  224. }
  225. }
  226. }
  227. if (pSelect != NULL) {
  228. pSelect->bSelected = true;
  229. /*
  230. if (pDevice->bRoaming == false) {
  231. // Einsn Add @20070907
  232. memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  233. memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
  234. }*/
  235. return(pSelect);
  236. }
  237. }
  238. return(NULL);
  239. }
  240. /*+
  241. *
  242. * Routine Description:
  243. * Clear BSS List
  244. *
  245. * Return Value:
  246. * None.
  247. *
  248. -*/
  249. void
  250. BSSvClearBSSList(
  251. void *hDeviceContext,
  252. bool bKeepCurrBSSID
  253. )
  254. {
  255. PSDevice pDevice = (PSDevice)hDeviceContext;
  256. PSMgmtObject pMgmt = pDevice->pMgmt;
  257. unsigned int ii;
  258. for (ii = 0; ii < MAX_BSS_NUM; ii++) {
  259. if (bKeepCurrBSSID) {
  260. if (pMgmt->sBSSList[ii].bActive &&
  261. !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pMgmt->abyCurrBSSID)) {
  262. // bKeepCurrBSSID = false;
  263. continue;
  264. }
  265. }
  266. if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
  267. pMgmt->sBSSList[ii].uClearCount ++;
  268. continue;
  269. }
  270. pMgmt->sBSSList[ii].bActive = false;
  271. memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
  272. }
  273. BSSvClearAnyBSSJoinRecord(pDevice);
  274. return;
  275. }
  276. /*+
  277. *
  278. * Routine Description:
  279. * search BSS list by BSSID & SSID if matched
  280. *
  281. * Return Value:
  282. * true if found.
  283. *
  284. -*/
  285. PKnownBSS
  286. BSSpAddrIsInBSSList(
  287. void *hDeviceContext,
  288. unsigned char *abyBSSID,
  289. PWLAN_IE_SSID pSSID
  290. )
  291. {
  292. PSDevice pDevice = (PSDevice)hDeviceContext;
  293. PSMgmtObject pMgmt = pDevice->pMgmt;
  294. PKnownBSS pBSSList = NULL;
  295. unsigned int ii;
  296. for (ii = 0; ii < MAX_BSS_NUM; ii++) {
  297. pBSSList = &(pMgmt->sBSSList[ii]);
  298. if (pBSSList->bActive) {
  299. if (!compare_ether_addr(pBSSList->abyBSSID, abyBSSID)) {
  300. // if (pSSID == NULL)
  301. // return pBSSList;
  302. if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len){
  303. if (memcmp(pSSID->abySSID,
  304. ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
  305. pSSID->len) == 0)
  306. return pBSSList;
  307. }
  308. }
  309. }
  310. }
  311. return NULL;
  312. };
  313. /*+
  314. *
  315. * Routine Description:
  316. * Insert a BSS set into known BSS list
  317. *
  318. * Return Value:
  319. * true if success.
  320. *
  321. -*/
  322. bool
  323. BSSbInsertToBSSList (
  324. void *hDeviceContext,
  325. unsigned char *abyBSSIDAddr,
  326. QWORD qwTimestamp,
  327. unsigned short wBeaconInterval,
  328. unsigned short wCapInfo,
  329. unsigned char byCurrChannel,
  330. PWLAN_IE_SSID pSSID,
  331. PWLAN_IE_SUPP_RATES pSuppRates,
  332. PWLAN_IE_SUPP_RATES pExtSuppRates,
  333. PERPObject psERP,
  334. PWLAN_IE_RSN pRSN,
  335. PWLAN_IE_RSN_EXT pRSNWPA,
  336. PWLAN_IE_COUNTRY pIE_Country,
  337. PWLAN_IE_QUIET pIE_Quiet,
  338. unsigned int uIELength,
  339. unsigned char *pbyIEs,
  340. void *pRxPacketContext
  341. )
  342. {
  343. PSDevice pDevice = (PSDevice)hDeviceContext;
  344. PSMgmtObject pMgmt = pDevice->pMgmt;
  345. PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
  346. PKnownBSS pBSSList = NULL;
  347. unsigned int ii;
  348. bool bParsingQuiet = false;
  349. PWLAN_IE_QUIET pQuiet = NULL;
  350. pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
  351. for (ii = 0; ii < MAX_BSS_NUM; ii++) {
  352. pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
  353. if (!pBSSList->bActive)
  354. break;
  355. }
  356. if (ii == MAX_BSS_NUM){
  357. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
  358. return false;
  359. }
  360. // save the BSS info
  361. pBSSList->bActive = true;
  362. memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
  363. HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
  364. LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
  365. pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
  366. pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
  367. pBSSList->uClearCount = 0;
  368. if (pSSID->len > WLAN_SSID_MAXLEN)
  369. pSSID->len = WLAN_SSID_MAXLEN;
  370. memcpy( pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
  371. pBSSList->uChannel = byCurrChannel;
  372. if (pSuppRates->len > WLAN_RATES_MAXLEN)
  373. pSuppRates->len = WLAN_RATES_MAXLEN;
  374. memcpy( pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
  375. if (pExtSuppRates != NULL) {
  376. if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
  377. pExtSuppRates->len = WLAN_RATES_MAXLEN;
  378. memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
  379. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
  380. } else {
  381. memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
  382. }
  383. pBSSList->sERP.byERP = psERP->byERP;
  384. pBSSList->sERP.bERPExist = psERP->bERPExist;
  385. // Check if BSS is 802.11a/b/g
  386. if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
  387. pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
  388. } else {
  389. if (pBSSList->sERP.bERPExist == true) {
  390. pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
  391. } else {
  392. pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
  393. }
  394. }
  395. pBSSList->byRxRate = pRxPacket->byRxRate;
  396. pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
  397. pBSSList->uRSSI = pRxPacket->uRSSI;
  398. pBSSList->bySQ = pRxPacket->bySQ;
  399. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
  400. (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
  401. // assoc with BSS
  402. if (pBSSList == pMgmt->pCurrBSS) {
  403. bParsingQuiet = true;
  404. }
  405. }
  406. WPA_ClearRSN(pBSSList);
  407. if (pRSNWPA != NULL) {
  408. unsigned int uLen = pRSNWPA->len + 2;
  409. if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
  410. pBSSList->wWPALen = uLen;
  411. memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
  412. WPA_ParseRSN(pBSSList, pRSNWPA);
  413. }
  414. }
  415. WPA2_ClearRSN(pBSSList);
  416. if (pRSN != NULL) {
  417. unsigned int uLen = pRSN->len + 2;
  418. if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
  419. pBSSList->wRSNLen = uLen;
  420. memcpy(pBSSList->byRSNIE, pRSN, uLen);
  421. WPA2vParseRSN(pBSSList, pRSN);
  422. }
  423. }
  424. if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == true)) {
  425. PSKeyItem pTransmitKey = NULL;
  426. bool bIs802_1x = false;
  427. for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
  428. if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
  429. bIs802_1x = true;
  430. break;
  431. }
  432. }
  433. if ((bIs802_1x == true) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
  434. ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
  435. bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
  436. if ((pDevice->bLinkPass == true) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
  437. if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) ||
  438. (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == true)) {
  439. pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
  440. pDevice->gsPMKIDCandidate.Version = 1;
  441. }
  442. }
  443. }
  444. }
  445. if (pDevice->bUpdateBBVGA) {
  446. // Moniter if RSSI is too strong.
  447. pBSSList->byRSSIStatCnt = 0;
  448. RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
  449. pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
  450. for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
  451. pBSSList->ldBmAverage[ii] = 0;
  452. }
  453. if ((pIE_Country != NULL) &&
  454. (pMgmt->b11hEnable == true)) {
  455. set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
  456. pIE_Country);
  457. }
  458. if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
  459. if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
  460. (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
  461. // valid EID
  462. if (pQuiet == NULL) {
  463. pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
  464. CARDbSetQuiet( pMgmt->pAdapter,
  465. true,
  466. pQuiet->byQuietCount,
  467. pQuiet->byQuietPeriod,
  468. *((unsigned short *)pQuiet->abyQuietDuration),
  469. *((unsigned short *)pQuiet->abyQuietOffset)
  470. );
  471. } else {
  472. pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
  473. CARDbSetQuiet( pMgmt->pAdapter,
  474. false,
  475. pQuiet->byQuietCount,
  476. pQuiet->byQuietPeriod,
  477. *((unsigned short *)pQuiet->abyQuietDuration),
  478. *((unsigned short *)pQuiet->abyQuietOffset)
  479. );
  480. }
  481. }
  482. }
  483. if ((bParsingQuiet == true) &&
  484. (pQuiet != NULL)) {
  485. CARDbStartQuiet(pMgmt->pAdapter);
  486. }
  487. pBSSList->uIELength = uIELength;
  488. if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
  489. pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
  490. memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
  491. return true;
  492. }
  493. /*+
  494. *
  495. * Routine Description:
  496. * Update BSS set in known BSS list
  497. *
  498. * Return Value:
  499. * true if success.
  500. *
  501. -*/
  502. // TODO: input structure modify
  503. bool
  504. BSSbUpdateToBSSList (
  505. void *hDeviceContext,
  506. QWORD qwTimestamp,
  507. unsigned short wBeaconInterval,
  508. unsigned short wCapInfo,
  509. unsigned char byCurrChannel,
  510. bool bChannelHit,
  511. PWLAN_IE_SSID pSSID,
  512. PWLAN_IE_SUPP_RATES pSuppRates,
  513. PWLAN_IE_SUPP_RATES pExtSuppRates,
  514. PERPObject psERP,
  515. PWLAN_IE_RSN pRSN,
  516. PWLAN_IE_RSN_EXT pRSNWPA,
  517. PWLAN_IE_COUNTRY pIE_Country,
  518. PWLAN_IE_QUIET pIE_Quiet,
  519. PKnownBSS pBSSList,
  520. unsigned int uIELength,
  521. unsigned char *pbyIEs,
  522. void *pRxPacketContext
  523. )
  524. {
  525. int ii;
  526. PSDevice pDevice = (PSDevice)hDeviceContext;
  527. PSMgmtObject pMgmt = pDevice->pMgmt;
  528. PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
  529. long ldBm;
  530. bool bParsingQuiet = false;
  531. PWLAN_IE_QUIET pQuiet = NULL;
  532. if (pBSSList == NULL)
  533. return false;
  534. HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
  535. LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
  536. pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
  537. pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
  538. pBSSList->uClearCount = 0;
  539. pBSSList->uChannel = byCurrChannel;
  540. // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbUpdateToBSSList: pBSSList->uChannel: %d\n", pBSSList->uChannel);
  541. if (pSSID->len > WLAN_SSID_MAXLEN)
  542. pSSID->len = WLAN_SSID_MAXLEN;
  543. if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
  544. memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
  545. memcpy(pBSSList->abySuppRates, pSuppRates,pSuppRates->len + WLAN_IEHDR_LEN);
  546. if (pExtSuppRates != NULL) {
  547. memcpy(pBSSList->abyExtSuppRates, pExtSuppRates,pExtSuppRates->len + WLAN_IEHDR_LEN);
  548. } else {
  549. memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
  550. }
  551. pBSSList->sERP.byERP = psERP->byERP;
  552. pBSSList->sERP.bERPExist = psERP->bERPExist;
  553. // Check if BSS is 802.11a/b/g
  554. if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
  555. pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
  556. } else {
  557. if (pBSSList->sERP.bERPExist == true) {
  558. pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
  559. } else {
  560. pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
  561. }
  562. }
  563. pBSSList->byRxRate = pRxPacket->byRxRate;
  564. pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
  565. if(bChannelHit)
  566. pBSSList->uRSSI = pRxPacket->uRSSI;
  567. pBSSList->bySQ = pRxPacket->bySQ;
  568. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
  569. (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
  570. // assoc with BSS
  571. if (pBSSList == pMgmt->pCurrBSS) {
  572. bParsingQuiet = true;
  573. }
  574. }
  575. WPA_ClearRSN(pBSSList); //mike update
  576. if (pRSNWPA != NULL) {
  577. unsigned int uLen = pRSNWPA->len + 2;
  578. if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
  579. pBSSList->wWPALen = uLen;
  580. memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
  581. WPA_ParseRSN(pBSSList, pRSNWPA);
  582. }
  583. }
  584. WPA2_ClearRSN(pBSSList); //mike update
  585. if (pRSN != NULL) {
  586. unsigned int uLen = pRSN->len + 2;
  587. if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
  588. pBSSList->wRSNLen = uLen;
  589. memcpy(pBSSList->byRSNIE, pRSN, uLen);
  590. WPA2vParseRSN(pBSSList, pRSN);
  591. }
  592. }
  593. if (pRxPacket->uRSSI != 0) {
  594. RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
  595. // Moniter if RSSI is too strong.
  596. pBSSList->byRSSIStatCnt++;
  597. pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
  598. pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
  599. for(ii=0;ii<RSSI_STAT_COUNT;ii++) {
  600. if (pBSSList->ldBmAverage[ii] != 0) {
  601. pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
  602. }
  603. }
  604. }
  605. if ((pIE_Country != NULL) &&
  606. (pMgmt->b11hEnable == true)) {
  607. set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
  608. pIE_Country);
  609. }
  610. if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
  611. if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
  612. (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
  613. // valid EID
  614. if (pQuiet == NULL) {
  615. pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
  616. CARDbSetQuiet( pMgmt->pAdapter,
  617. true,
  618. pQuiet->byQuietCount,
  619. pQuiet->byQuietPeriod,
  620. *((unsigned short *)pQuiet->abyQuietDuration),
  621. *((unsigned short *)pQuiet->abyQuietOffset)
  622. );
  623. } else {
  624. pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
  625. CARDbSetQuiet( pMgmt->pAdapter,
  626. false,
  627. pQuiet->byQuietCount,
  628. pQuiet->byQuietPeriod,
  629. *((unsigned short *)pQuiet->abyQuietDuration),
  630. *((unsigned short *)pQuiet->abyQuietOffset)
  631. );
  632. }
  633. }
  634. }
  635. if ((bParsingQuiet == true) &&
  636. (pQuiet != NULL)) {
  637. CARDbStartQuiet(pMgmt->pAdapter);
  638. }
  639. pBSSList->uIELength = uIELength;
  640. if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
  641. pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
  642. memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
  643. return true;
  644. }
  645. /*+
  646. *
  647. * Routine Description:
  648. * Search Node DB table to find the index of matched DstAddr
  649. *
  650. * Return Value:
  651. * None
  652. *
  653. -*/
  654. bool
  655. BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
  656. unsigned int *puNodeIndex)
  657. {
  658. PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
  659. unsigned int ii;
  660. // Index = 0 reserved for AP Node
  661. for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
  662. if (pMgmt->sNodeDBTable[ii].bActive) {
  663. if (!compare_ether_addr(abyDstAddr, pMgmt->sNodeDBTable[ii].abyMACAddr)) {
  664. *puNodeIndex = ii;
  665. return true;
  666. }
  667. }
  668. }
  669. return false;
  670. };
  671. /*+
  672. *
  673. * Routine Description:
  674. * Find an empty node and allocated; if no empty found,
  675. * instand used of most inactive one.
  676. *
  677. * Return Value:
  678. * None
  679. *
  680. -*/
  681. void
  682. BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
  683. {
  684. PSDevice pDevice = (PSDevice)hDeviceContext;
  685. PSMgmtObject pMgmt = pDevice->pMgmt;
  686. unsigned int ii;
  687. unsigned int BigestCount = 0;
  688. unsigned int SelectIndex;
  689. struct sk_buff *skb;
  690. // Index = 0 reserved for AP Node (In STA mode)
  691. // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
  692. SelectIndex = 1;
  693. for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
  694. if (pMgmt->sNodeDBTable[ii].bActive) {
  695. if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
  696. BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
  697. SelectIndex = ii;
  698. }
  699. }
  700. else {
  701. break;
  702. }
  703. }
  704. // if not found replace uInActiveCount is largest one.
  705. if ( ii == (MAX_NODE_NUM + 1)) {
  706. *puNodeIndex = SelectIndex;
  707. DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
  708. // clear ps buffer
  709. if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
  710. while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
  711. dev_kfree_skb(skb);
  712. }
  713. }
  714. else {
  715. *puNodeIndex = ii;
  716. }
  717. memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
  718. pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
  719. pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
  720. // for AP mode PS queue
  721. skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
  722. pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
  723. pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
  724. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
  725. return;
  726. };
  727. /*+
  728. *
  729. * Routine Description:
  730. * Remove Node by NodeIndex
  731. *
  732. *
  733. * Return Value:
  734. * None
  735. *
  736. -*/
  737. void
  738. BSSvRemoveOneNode(
  739. void *hDeviceContext,
  740. unsigned int uNodeIndex
  741. )
  742. {
  743. PSDevice pDevice = (PSDevice)hDeviceContext;
  744. PSMgmtObject pMgmt = pDevice->pMgmt;
  745. unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
  746. struct sk_buff *skb;
  747. while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
  748. dev_kfree_skb(skb);
  749. // clear context
  750. memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
  751. // clear tx bit map
  752. pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
  753. return;
  754. };
  755. /*+
  756. *
  757. * Routine Description:
  758. * Update AP Node content in Index 0 of KnownNodeDB
  759. *
  760. *
  761. * Return Value:
  762. * None
  763. *
  764. -*/
  765. void
  766. BSSvUpdateAPNode(
  767. void *hDeviceContext,
  768. unsigned short *pwCapInfo,
  769. PWLAN_IE_SUPP_RATES pSuppRates,
  770. PWLAN_IE_SUPP_RATES pExtSuppRates
  771. )
  772. {
  773. PSDevice pDevice = (PSDevice)hDeviceContext;
  774. PSMgmtObject pMgmt = pDevice->pMgmt;
  775. unsigned int uRateLen = WLAN_RATES_MAXLEN;
  776. memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
  777. pMgmt->sNodeDBTable[0].bActive = true;
  778. if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
  779. uRateLen = WLAN_RATES_MAXLEN_11B;
  780. }
  781. pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
  782. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  783. uRateLen);
  784. pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
  785. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
  786. uRateLen);
  787. RATEvParseMaxRate((void *)pDevice,
  788. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  789. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
  790. true,
  791. &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
  792. &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
  793. &(pMgmt->sNodeDBTable[0].wSuppRate),
  794. &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
  795. &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
  796. );
  797. memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
  798. pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
  799. pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
  800. pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
  801. #ifdef PLICE_DEBUG
  802. printk("BSSvUpdateAPNode:MaxSuppRate is %d\n",pMgmt->sNodeDBTable[0].wMaxSuppRate);
  803. #endif
  804. // Auto rate fallback function initiation.
  805. // RATEbInit(pDevice);
  806. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt->sNodeDBTable[0].wTxDataRate);
  807. };
  808. /*+
  809. *
  810. * Routine Description:
  811. * Add Multicast Node content in Index 0 of KnownNodeDB
  812. *
  813. *
  814. * Return Value:
  815. * None
  816. *
  817. -*/
  818. void
  819. BSSvAddMulticastNode(
  820. void *hDeviceContext
  821. )
  822. {
  823. PSDevice pDevice = (PSDevice)hDeviceContext;
  824. PSMgmtObject pMgmt = pDevice->pMgmt;
  825. if (!pDevice->bEnableHostWEP)
  826. memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
  827. memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
  828. pMgmt->sNodeDBTable[0].bActive = true;
  829. pMgmt->sNodeDBTable[0].bPSEnable = false;
  830. skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
  831. RATEvParseMaxRate((void *)pDevice,
  832. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  833. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
  834. true,
  835. &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
  836. &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
  837. &(pMgmt->sNodeDBTable[0].wSuppRate),
  838. &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
  839. &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
  840. );
  841. pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
  842. #ifdef PLICE_DEBUG
  843. printk("BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
  844. #endif
  845. pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
  846. };
  847. /*+
  848. *
  849. * Routine Description:
  850. *
  851. *
  852. * Second call back function to update Node DB info & AP link status
  853. *
  854. *
  855. * Return Value:
  856. * none.
  857. *
  858. -*/
  859. //2008-4-14 <add> by chester for led issue
  860. #ifdef FOR_LED_ON_NOTEBOOK
  861. bool cc=false;
  862. unsigned int status;
  863. #endif
  864. void
  865. BSSvSecondCallBack(
  866. void *hDeviceContext
  867. )
  868. {
  869. PSDevice pDevice = (PSDevice)hDeviceContext;
  870. PSMgmtObject pMgmt = pDevice->pMgmt;
  871. unsigned int ii;
  872. PWLAN_IE_SSID pItemSSID, pCurrSSID;
  873. unsigned int uSleepySTACnt = 0;
  874. unsigned int uNonShortSlotSTACnt = 0;
  875. unsigned int uLongPreambleSTACnt = 0;
  876. viawget_wpa_header* wpahdr; //DavidWang
  877. spin_lock_irq(&pDevice->lock);
  878. pDevice->uAssocCount = 0;
  879. pDevice->byERPFlag &=
  880. ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
  881. //2008-4-14 <add> by chester for led issue
  882. #ifdef FOR_LED_ON_NOTEBOOK
  883. MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
  884. if ((( !(pDevice->byGPIO & GPIO0_DATA)&&(pDevice->bHWRadioOff == false))||((pDevice->byGPIO & GPIO0_DATA)&&(pDevice->bHWRadioOff == true)))&&(cc==false)){
  885. cc=true;
  886. }
  887. else if(cc==true){
  888. if(pDevice->bHWRadioOff == true){
  889. if ( !(pDevice->byGPIO & GPIO0_DATA))
  890. //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
  891. {if(status==1) goto start;
  892. status=1;
  893. CARDbRadioPowerOff(pDevice);
  894. pMgmt->sNodeDBTable[0].bActive = false;
  895. pMgmt->eCurrMode = WMAC_MODE_STANDBY;
  896. pMgmt->eCurrState = WMAC_STATE_IDLE;
  897. //netif_stop_queue(pDevice->dev);
  898. pDevice->bLinkPass = false;
  899. }
  900. if (pDevice->byGPIO &GPIO0_DATA)
  901. //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
  902. {if(status==2) goto start;
  903. status=2;
  904. CARDbRadioPowerOn(pDevice);
  905. } }
  906. else{
  907. if (pDevice->byGPIO & GPIO0_DATA)
  908. //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
  909. {if(status==3) goto start;
  910. status=3;
  911. CARDbRadioPowerOff(pDevice);
  912. pMgmt->sNodeDBTable[0].bActive = false;
  913. pMgmt->eCurrMode = WMAC_MODE_STANDBY;
  914. pMgmt->eCurrState = WMAC_STATE_IDLE;
  915. //netif_stop_queue(pDevice->dev);
  916. pDevice->bLinkPass = false;
  917. }
  918. if ( !(pDevice->byGPIO & GPIO0_DATA))
  919. //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
  920. {if(status==4) goto start;
  921. status=4;
  922. CARDbRadioPowerOn(pDevice);
  923. } }
  924. }
  925. start:
  926. #endif
  927. if (pDevice->wUseProtectCntDown > 0) {
  928. pDevice->wUseProtectCntDown --;
  929. }
  930. else {
  931. // disable protect mode
  932. pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
  933. }
  934. {
  935. pDevice->byReAssocCount++;
  936. if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != true)) { //10 sec timeout
  937. printk("Re-association timeout!!!\n");
  938. pDevice->byReAssocCount = 0;
  939. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  940. // if(pDevice->bWPASuppWextEnabled == true)
  941. {
  942. union iwreq_data wrqu;
  943. memset(&wrqu, 0, sizeof (wrqu));
  944. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  945. PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
  946. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  947. }
  948. #endif
  949. }
  950. else if(pDevice->bLinkPass == true)
  951. pDevice->byReAssocCount = 0;
  952. }
  953. #ifdef Calcu_LinkQual
  954. s_uCalculateLinkQual((void *)pDevice);
  955. #endif
  956. for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
  957. if (pMgmt->sNodeDBTable[ii].bActive) {
  958. // Increase in-activity counter
  959. pMgmt->sNodeDBTable[ii].uInActiveCount++;
  960. if (ii > 0) {
  961. if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
  962. BSSvRemoveOneNode(pDevice, ii);
  963. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
  964. "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
  965. continue;
  966. }
  967. if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
  968. pDevice->uAssocCount++;
  969. // check if Non ERP exist
  970. if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
  971. if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
  972. pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
  973. uLongPreambleSTACnt ++;
  974. }
  975. if (!pMgmt->sNodeDBTable[ii].bERPExist) {
  976. pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
  977. pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
  978. }
  979. if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
  980. uNonShortSlotSTACnt++;
  981. }
  982. }
  983. // check if any STA in PS mode
  984. if (pMgmt->sNodeDBTable[ii].bPSEnable)
  985. uSleepySTACnt++;
  986. }
  987. // Rate fallback check
  988. if (!pDevice->bFixRate) {
  989. /*
  990. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (ii == 0))
  991. RATEvTxRateFallBack(pDevice, &(pMgmt->sNodeDBTable[ii]));
  992. */
  993. if (ii > 0) {
  994. // ii = 0 for multicast node (AP & Adhoc)
  995. RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
  996. }
  997. else {
  998. // ii = 0 reserved for unicast AP node (Infra STA)
  999. if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
  1000. #ifdef PLICE_DEBUG
  1001. printk("SecondCallback:Before:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
  1002. #endif
  1003. RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
  1004. #ifdef PLICE_DEBUG
  1005. printk("SecondCallback:After:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
  1006. #endif
  1007. }
  1008. }
  1009. // check if pending PS queue
  1010. if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
  1011. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending \n",
  1012. ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
  1013. if ((ii >0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
  1014. BSSvRemoveOneNode(pDevice, ii);
  1015. DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove \n", ii);
  1016. continue;
  1017. }
  1018. }
  1019. }
  1020. }
  1021. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
  1022. // on/off protect mode
  1023. if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
  1024. if (!pDevice->bProtectMode) {
  1025. MACvEnableProtectMD(pDevice->PortOffset);
  1026. pDevice->bProtectMode = true;
  1027. }
  1028. }
  1029. else {
  1030. if (pDevice->bProtectMode) {
  1031. MACvDisableProtectMD(pDevice->PortOffset);
  1032. pDevice->bProtectMode = false;
  1033. }
  1034. }
  1035. // on/off short slot time
  1036. if (uNonShortSlotSTACnt > 0) {
  1037. if (pDevice->bShortSlotTime) {
  1038. pDevice->bShortSlotTime = false;
  1039. BBvSetShortSlotTime(pDevice);
  1040. vUpdateIFS((void *)pDevice);
  1041. }
  1042. }
  1043. else {
  1044. if (!pDevice->bShortSlotTime) {
  1045. pDevice->bShortSlotTime = true;
  1046. BBvSetShortSlotTime(pDevice);
  1047. vUpdateIFS((void *)pDevice);
  1048. }
  1049. }
  1050. // on/off barker long preamble mode
  1051. if (uLongPreambleSTACnt > 0) {
  1052. if (!pDevice->bBarkerPreambleMd) {
  1053. MACvEnableBarkerPreambleMd(pDevice->PortOffset);
  1054. pDevice->bBarkerPreambleMd = true;
  1055. }
  1056. }
  1057. else {
  1058. if (pDevice->bBarkerPreambleMd) {
  1059. MACvDisableBarkerPreambleMd(pDevice->PortOffset);
  1060. pDevice->bBarkerPreambleMd = false;
  1061. }
  1062. }
  1063. }
  1064. // Check if any STA in PS mode, enable DTIM multicast deliver
  1065. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  1066. if (uSleepySTACnt > 0)
  1067. pMgmt->sNodeDBTable[0].bPSEnable = true;
  1068. else
  1069. pMgmt->sNodeDBTable[0].bPSEnable = false;
  1070. }
  1071. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
  1072. pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  1073. if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
  1074. (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
  1075. if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
  1076. // DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Callback inactive Count = [%d]\n", pMgmt->sNodeDBTable[0].uInActiveCount);
  1077. //if (pDevice->bUpdateBBVGA) {
  1078. // s_vCheckSensitivity((void *) pDevice);
  1079. //}
  1080. if (pDevice->bUpdateBBVGA) {
  1081. // s_vCheckSensitivity((void *) pDevice);
  1082. s_vCheckPreEDThreshold((void *)pDevice);
  1083. }
  1084. if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
  1085. (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) ) {
  1086. pDevice->byBBVGANew = pDevice->abyBBVGA[0];
  1087. bScheduleCommand((void *) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
  1088. }
  1089. if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
  1090. pMgmt->sNodeDBTable[0].bActive = false;
  1091. pMgmt->eCurrMode = WMAC_MODE_STANDBY;
  1092. pMgmt->eCurrState = WMAC_STATE_IDLE;
  1093. netif_stop_queue(pDevice->dev);
  1094. pDevice->bLinkPass = false;
  1095. pDevice->bRoaming = true;
  1096. DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
  1097. if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
  1098. wpahdr = (viawget_wpa_header *)pDevice->skb->data;
  1099. wpahdr->type = VIAWGET_DISASSOC_MSG;
  1100. wpahdr->resp_ie_len = 0;
  1101. wpahdr->req_ie_len = 0;
  1102. skb_put(pDevice->skb, sizeof(viawget_wpa_header));
  1103. pDevice->skb->dev = pDevice->wpadev;
  1104. skb_reset_mac_header(pDevice->skb);
  1105. pDevice->skb->pkt_type = PACKET_HOST;
  1106. pDevice->skb->protocol = htons(ETH_P_802_2);
  1107. memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
  1108. netif_rx(pDevice->skb);
  1109. pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
  1110. }
  1111. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  1112. // if(pDevice->bWPASuppWextEnabled == true)
  1113. {
  1114. union iwreq_data wrqu;
  1115. memset(&wrqu, 0, sizeof (wrqu));
  1116. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1117. PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
  1118. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  1119. }
  1120. #endif
  1121. }
  1122. }
  1123. else if (pItemSSID->len != 0) {
  1124. if (pDevice->uAutoReConnectTime < 10) {
  1125. pDevice->uAutoReConnectTime++;
  1126. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  1127. //network manager support need not do Roaming scan???
  1128. if(pDevice->bWPASuppWextEnabled ==true)
  1129. pDevice->uAutoReConnectTime = 0;
  1130. #endif
  1131. }
  1132. else {
  1133. //mike use old encryption status for wpa reauthen
  1134. if(pDevice->bWPADEVUp)
  1135. pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
  1136. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
  1137. BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
  1138. pMgmt->eScanType = WMAC_SCAN_ACTIVE;
  1139. bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
  1140. bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
  1141. pDevice->uAutoReConnectTime = 0;
  1142. }
  1143. }
  1144. }
  1145. if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
  1146. // if adhoc started which essid is NULL string, rescaning.
  1147. if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
  1148. if (pDevice->uAutoReConnectTime < 10) {
  1149. pDevice->uAutoReConnectTime++;
  1150. }
  1151. else {
  1152. DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scaning ...\n");
  1153. pMgmt->eScanType = WMAC_SCAN_ACTIVE;
  1154. bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
  1155. bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
  1156. pDevice->uAutoReConnectTime = 0;
  1157. };
  1158. }
  1159. if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
  1160. if (pDevice->bUpdateBBVGA) {
  1161. //s_vCheckSensitivity((void *) pDevice);
  1162. s_vCheckPreEDThreshold((void *)pDevice);
  1163. }
  1164. if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) {
  1165. DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
  1166. pMgmt->sNodeDBTable[0].uInActiveCount = 0;
  1167. pMgmt->eCurrState = WMAC_STATE_STARTED;
  1168. netif_stop_queue(pDevice->dev);
  1169. pDevice->bLinkPass = false;
  1170. }
  1171. }
  1172. }
  1173. spin_unlock_irq(&pDevice->lock);
  1174. pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
  1175. add_timer(&pMgmt->sTimerSecondCallback);
  1176. return;
  1177. }
  1178. /*+
  1179. *
  1180. * Routine Description:
  1181. *
  1182. *
  1183. * Update Tx attemps, Tx failure counter in Node DB
  1184. *
  1185. *
  1186. * Return Value:
  1187. * none.
  1188. *
  1189. -*/
  1190. void
  1191. BSSvUpdateNodeTxCounter(
  1192. void *hDeviceContext,
  1193. unsigned char byTsr0,
  1194. unsigned char byTsr1,
  1195. unsigned char *pbyBuffer,
  1196. unsigned int uFIFOHeaderSize
  1197. )
  1198. {
  1199. PSDevice pDevice = (PSDevice)hDeviceContext;
  1200. PSMgmtObject pMgmt = pDevice->pMgmt;
  1201. unsigned int uNodeIndex = 0;
  1202. unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
  1203. PSTxBufHead pTxBufHead;
  1204. PS802_11Header pMACHeader;
  1205. unsigned short wRate;
  1206. unsigned short wFallBackRate = RATE_1M;
  1207. unsigned char byFallBack;
  1208. unsigned int ii;
  1209. // unsigned int txRetryTemp;
  1210. //PLICE_DEBUG->
  1211. //txRetryTemp = byTxRetry;
  1212. //if (txRetryTemp== 8)
  1213. //txRetryTemp -=3;
  1214. //PLICE_DEBUG <-
  1215. pTxBufHead = (PSTxBufHead) pbyBuffer;
  1216. if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
  1217. byFallBack = AUTO_FB_0;
  1218. } else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
  1219. byFallBack = AUTO_FB_1;
  1220. } else {
  1221. byFallBack = AUTO_FB_NONE;
  1222. }
  1223. wRate = pTxBufHead->wReserved; //?wRate
  1224. //printk("BSSvUpdateNodeTxCounter:byTxRetry is %d\n",byTxRetry);
  1225. //printk("BSSvUpdateNodeTx:wRate is %d,byFallback is %d\n",wRate,byFallBack);
  1226. //#ifdef PLICE_DEBUG
  1227. //printk("BSSvUpdateNodeTx: wRate is %d\n",wRate);
  1228. ////#endif
  1229. // Only Unicast using support rates
  1230. if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
  1231. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
  1232. if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
  1233. pMgmt->sNodeDBTable[0].uTxAttempts += 1;
  1234. if ((byTsr1 & TSR1_TERR) == 0) {
  1235. // transmit success, TxAttempts at least plus one
  1236. pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
  1237. if ( (byFallBack == AUTO_FB_NONE) ||
  1238. (wRate < RATE_18M) ) {
  1239. wFallBackRate = wRate;
  1240. } else if (byFallBack == AUTO_FB_0) {
  1241. //PLICE_DEBUG
  1242. if (byTxRetry < 5)
  1243. //if (txRetryTemp < 5)
  1244. wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
  1245. //wFallBackRate = awHWRetry0[wRate-RATE_12M][byTxRetry];
  1246. //wFallBackRate = awHWRetry0[wRate-RATE_18M][txRetryTemp] +1;
  1247. else
  1248. wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
  1249. //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
  1250. } else if (byFallBack == AUTO_FB_1) {
  1251. if (byTxRetry < 5)
  1252. wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
  1253. else
  1254. wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
  1255. }
  1256. pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
  1257. } else {
  1258. pMgmt->sNodeDBTable[0].uTxFailures ++;
  1259. }
  1260. pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
  1261. if (byTxRetry != 0) {
  1262. pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE]+=byTxRetry;
  1263. if ( (byFallBack == AUTO_FB_NONE) ||
  1264. (wRate < RATE_18M) ) {
  1265. pMgmt->sNodeDBTable[0].uTxFail[wRate]+=byTxRetry;
  1266. } else if (byFallBack == AUTO_FB_0) {
  1267. //PLICE_DEBUG
  1268. for(ii=0;ii<byTxRetry;ii++)
  1269. //for (ii=0;ii<txRetryTemp;ii++)
  1270. {
  1271. if (ii < 5)
  1272. {
  1273. //PLICE_DEBUG
  1274. wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
  1275. //printk(" II is %d:BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
  1276. //wFallBackRate = awHWRetry0[wRate-RATE_12M][ii];
  1277. }
  1278. else
  1279. {
  1280. wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
  1281. //printk("ii is %d BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
  1282. //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
  1283. }
  1284. pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
  1285. }
  1286. } else if (byFallBack == AUTO_FB_1) {
  1287. for(ii=0;ii<byTxRetry;ii++) {
  1288. if (ii < 5)
  1289. wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
  1290. else
  1291. wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
  1292. pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
  1293. }
  1294. }
  1295. }
  1296. }
  1297. if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
  1298. (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
  1299. pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
  1300. if (BSSDBbIsSTAInNodeDB((void *)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)){
  1301. pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
  1302. if ((byTsr1 & TSR1_TERR) == 0) {
  1303. // transmit success, TxAttempts at least plus one
  1304. pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
  1305. if ( (byFallBack == AUTO_FB_NONE) ||
  1306. (wRate < RATE_18M) ) {
  1307. wFallBackRate = wRate;
  1308. } else if (byFallBack == AUTO_FB_0) {
  1309. if (byTxRetry < 5)
  1310. wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
  1311. else
  1312. wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
  1313. } else if (byFallBack == AUTO_FB_1) {
  1314. if (byTxRetry < 5)
  1315. wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
  1316. else
  1317. wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
  1318. }
  1319. pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
  1320. } else {
  1321. pMgmt->sNodeDBTable[uNodeIndex].uTxFailures ++;
  1322. }
  1323. pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
  1324. if (byTxRetry != 0) {
  1325. pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE]+=byTxRetry;
  1326. if ( (byFallBack == AUTO_FB_NONE) ||
  1327. (wRate < RATE_18M) ) {
  1328. pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate]+=byTxRetry;
  1329. } else if (byFallBack == AUTO_FB_0) {
  1330. for(ii=0;ii<byTxRetry;ii++) {
  1331. if (ii < 5)
  1332. wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
  1333. else
  1334. wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
  1335. pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
  1336. }
  1337. } else if (byFallBack == AUTO_FB_1) {
  1338. for(ii=0;ii<byTxRetry;ii++) {
  1339. if (ii < 5)
  1340. wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
  1341. else
  1342. wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
  1343. pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
  1344. }
  1345. }
  1346. }
  1347. }
  1348. }
  1349. }
  1350. return;
  1351. }
  1352. /*+
  1353. *
  1354. * Routine Description:
  1355. * Clear Nodes & skb in DB Table
  1356. *
  1357. *
  1358. * Parameters:
  1359. * In:
  1360. * hDeviceContext - The adapter context.
  1361. * uStartIndex - starting index
  1362. * Out:
  1363. * none
  1364. *
  1365. * Return Value:
  1366. * None.
  1367. *
  1368. -*/
  1369. void
  1370. BSSvClearNodeDBTable(
  1371. void *hDeviceContext,
  1372. unsigned int uStartIndex
  1373. )
  1374. {
  1375. PSDevice pDevice = (PSDevice)hDeviceContext;
  1376. PSMgmtObject pMgmt = pDevice->pMgmt;
  1377. struct sk_buff *skb;
  1378. unsigned int ii;
  1379. for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
  1380. if (pMgmt->sNodeDBTable[ii].bActive) {
  1381. // check if sTxPSQueue has been initial
  1382. if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
  1383. while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL){
  1384. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
  1385. dev_kfree_skb(skb);
  1386. }
  1387. }
  1388. memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
  1389. }
  1390. }
  1391. return;
  1392. };
  1393. void s_vCheckSensitivity(
  1394. void *hDeviceContext
  1395. )
  1396. {
  1397. PSDevice pDevice = (PSDevice)hDeviceContext;
  1398. PKnownBSS pBSSList = NULL;
  1399. PSMgmtObject pMgmt = pDevice->pMgmt;
  1400. int ii;
  1401. if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
  1402. (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
  1403. return;
  1404. }
  1405. if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
  1406. ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
  1407. pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
  1408. if (pBSSList != NULL) {
  1409. // Updata BB Reg if RSSI is too strong.
  1410. long LocalldBmAverage = 0;
  1411. long uNumofdBm = 0;
  1412. for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
  1413. if (pBSSList->ldBmAverage[ii] != 0) {
  1414. uNumofdBm ++;
  1415. LocalldBmAverage += pBSSList->ldBmAverage[ii];
  1416. }
  1417. }
  1418. if (uNumofdBm > 0) {
  1419. LocalldBmAverage = LocalldBmAverage/uNumofdBm;
  1420. for (ii=0;ii<BB_VGA_LEVEL;ii++) {
  1421. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
  1422. if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
  1423. pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
  1424. break;
  1425. }
  1426. }
  1427. if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
  1428. pDevice->uBBVGADiffCount++;
  1429. if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
  1430. bScheduleCommand((void *) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
  1431. } else {
  1432. pDevice->uBBVGADiffCount = 0;
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. void
  1439. BSSvClearAnyBSSJoinRecord (
  1440. void *hDeviceContext
  1441. )
  1442. {
  1443. PSDevice pDevice = (PSDevice)hDeviceContext;
  1444. PSMgmtObject pMgmt = pDevice->pMgmt;
  1445. unsigned int ii;
  1446. for (ii = 0; ii < MAX_BSS_NUM; ii++) {
  1447. pMgmt->sBSSList[ii].bSelected = false;
  1448. }
  1449. return;
  1450. }
  1451. #ifdef Calcu_LinkQual
  1452. void s_uCalculateLinkQual(
  1453. void *hDeviceContext
  1454. )
  1455. {
  1456. PSDevice pDevice = (PSDevice)hDeviceContext;
  1457. unsigned long TxOkRatio, TxCnt;
  1458. unsigned long RxOkRatio,RxCnt;
  1459. unsigned long RssiRatio;
  1460. long ldBm;
  1461. TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
  1462. pDevice->scStatistic.TxRetryOkCount +
  1463. pDevice->scStatistic.TxFailCount;
  1464. RxCnt = pDevice->scStatistic.RxFcsErrCnt +
  1465. pDevice->scStatistic.RxOkCnt;
  1466. TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
  1467. RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
  1468. //decide link quality
  1469. if(pDevice->bLinkPass !=true)
  1470. {
  1471. // printk("s_uCalculateLinkQual-->Link disconnect and Poor quality**\n");
  1472. pDevice->scStatistic.LinkQuality = 0;
  1473. pDevice->scStatistic.SignalStren = 0;
  1474. }
  1475. else
  1476. {
  1477. RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
  1478. if(-ldBm < 50) {
  1479. RssiRatio = 4000;
  1480. }
  1481. else if(-ldBm > 90) {
  1482. RssiRatio = 0;
  1483. }
  1484. else {
  1485. RssiRatio = (40-(-ldBm-50))*4000/40;
  1486. }
  1487. pDevice->scStatistic.SignalStren = RssiRatio/40;
  1488. pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
  1489. }
  1490. pDevice->scStatistic.RxFcsErrCnt = 0;
  1491. pDevice->scStatistic.RxOkCnt = 0;
  1492. pDevice->scStatistic.TxFailCount = 0;
  1493. pDevice->scStatistic.TxNoRetryOkCount = 0;
  1494. pDevice->scStatistic.TxRetryOkCount = 0;
  1495. return;
  1496. }
  1497. #endif
  1498. void s_vCheckPreEDThreshold(
  1499. void *hDeviceContext
  1500. )
  1501. {
  1502. PSDevice pDevice = (PSDevice)hDeviceContext;
  1503. PKnownBSS pBSSList = NULL;
  1504. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  1505. if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
  1506. ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
  1507. pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
  1508. if (pBSSList != NULL) {
  1509. pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);
  1510. //BBvUpdatePreEDThreshold(pDevice, false);
  1511. }
  1512. }
  1513. return;
  1514. }