rtw_mlme.c 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTW_MLME_C_
  21. #include <drv_types.h>
  22. extern void indicate_wx_scan_complete_event(_adapter *padapter);
  23. extern u8 rtw_do_join(_adapter * padapter);
  24. #ifdef CONFIG_DISABLE_MCS13TO15
  25. extern unsigned char MCS_rate_2R_MCS13TO15_OFF[16];
  26. extern unsigned char MCS_rate_2R[16];
  27. #else //CONFIG_DISABLE_MCS13TO15
  28. extern unsigned char MCS_rate_2R[16];
  29. #endif //CONFIG_DISABLE_MCS13TO15
  30. extern unsigned char MCS_rate_1R[16];
  31. sint _rtw_init_mlme_priv (_adapter* padapter)
  32. {
  33. sint i;
  34. u8 *pbuf;
  35. struct wlan_network *pnetwork;
  36. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  37. sint res = _SUCCESS;
  38. _func_enter_;
  39. // We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc().
  40. //_rtw_memset((u8 *)pmlmepriv, 0, sizeof(struct mlme_priv));
  41. pmlmepriv->nic_hdl = (u8 *)padapter;
  42. pmlmepriv->pscanned = NULL;
  43. pmlmepriv->fw_state = 0;
  44. pmlmepriv->cur_network.network.InfrastructureMode = Ndis802_11AutoUnknown;
  45. pmlmepriv->scan_mode=SCAN_ACTIVE;// 1: active, 0: pasive. Maybe someday we should rename this varable to "active_mode" (Jeff)
  46. _rtw_spinlock_init(&(pmlmepriv->lock));
  47. _rtw_init_queue(&(pmlmepriv->free_bss_pool));
  48. _rtw_init_queue(&(pmlmepriv->scanned_queue));
  49. set_scanned_network_val(pmlmepriv, 0);
  50. _rtw_memset(&pmlmepriv->assoc_ssid,0,sizeof(NDIS_802_11_SSID));
  51. pbuf = rtw_zvmalloc(MAX_BSS_CNT * (sizeof(struct wlan_network)));
  52. if (pbuf == NULL){
  53. res=_FAIL;
  54. goto exit;
  55. }
  56. pmlmepriv->free_bss_buf = pbuf;
  57. pnetwork = (struct wlan_network *)pbuf;
  58. for(i = 0; i < MAX_BSS_CNT; i++)
  59. {
  60. _rtw_init_listhead(&(pnetwork->list));
  61. rtw_list_insert_tail(&(pnetwork->list), &(pmlmepriv->free_bss_pool.queue));
  62. pnetwork++;
  63. }
  64. //allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf
  65. rtw_clear_scan_deny(padapter);
  66. #ifdef CONFIG_FTP_PROTECT
  67. pmlmepriv->ftp_lock_flag = 0;
  68. #endif //CONFIG_FTP_PROTECT
  69. rtw_init_mlme_timer(padapter);
  70. exit:
  71. _func_exit_;
  72. return res;
  73. }
  74. void rtw_mfree_mlme_priv_lock (struct mlme_priv *pmlmepriv);
  75. void rtw_mfree_mlme_priv_lock (struct mlme_priv *pmlmepriv)
  76. {
  77. _rtw_spinlock_free(&pmlmepriv->lock);
  78. _rtw_spinlock_free(&(pmlmepriv->free_bss_pool.lock));
  79. _rtw_spinlock_free(&(pmlmepriv->scanned_queue.lock));
  80. }
  81. static void rtw_free_mlme_ie_data(u8 **ppie, u32 *plen)
  82. {
  83. if(*ppie)
  84. {
  85. _rtw_mfree(*ppie, *plen);
  86. *plen = 0;
  87. *ppie=NULL;
  88. }
  89. }
  90. void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv)
  91. {
  92. #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
  93. rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len);
  94. rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
  95. rtw_free_mlme_ie_data(&pmlmepriv->wps_beacon_ie, &pmlmepriv->wps_beacon_ie_len);
  96. rtw_free_mlme_ie_data(&pmlmepriv->wps_probe_req_ie, &pmlmepriv->wps_probe_req_ie_len);
  97. rtw_free_mlme_ie_data(&pmlmepriv->wps_probe_resp_ie, &pmlmepriv->wps_probe_resp_ie_len);
  98. rtw_free_mlme_ie_data(&pmlmepriv->wps_assoc_resp_ie, &pmlmepriv->wps_assoc_resp_ie_len);
  99. rtw_free_mlme_ie_data(&pmlmepriv->p2p_beacon_ie, &pmlmepriv->p2p_beacon_ie_len);
  100. rtw_free_mlme_ie_data(&pmlmepriv->p2p_probe_req_ie, &pmlmepriv->p2p_probe_req_ie_len);
  101. rtw_free_mlme_ie_data(&pmlmepriv->p2p_probe_resp_ie, &pmlmepriv->p2p_probe_resp_ie_len);
  102. rtw_free_mlme_ie_data(&pmlmepriv->p2p_go_probe_resp_ie, &pmlmepriv->p2p_go_probe_resp_ie_len);
  103. rtw_free_mlme_ie_data(&pmlmepriv->p2p_assoc_req_ie, &pmlmepriv->p2p_assoc_req_ie_len);
  104. #endif
  105. #if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
  106. rtw_free_mlme_ie_data(&pmlmepriv->wfd_beacon_ie, &pmlmepriv->wfd_beacon_ie_len);
  107. rtw_free_mlme_ie_data(&pmlmepriv->wfd_probe_req_ie, &pmlmepriv->wfd_probe_req_ie_len);
  108. rtw_free_mlme_ie_data(&pmlmepriv->wfd_probe_resp_ie, &pmlmepriv->wfd_probe_resp_ie_len);
  109. rtw_free_mlme_ie_data(&pmlmepriv->wfd_go_probe_resp_ie, &pmlmepriv->wfd_go_probe_resp_ie_len);
  110. rtw_free_mlme_ie_data(&pmlmepriv->wfd_assoc_req_ie, &pmlmepriv->wfd_assoc_req_ie_len);
  111. #endif
  112. }
  113. void _rtw_free_mlme_priv (struct mlme_priv *pmlmepriv)
  114. {
  115. _func_enter_;
  116. rtw_free_mlme_priv_ie_data(pmlmepriv);
  117. if(pmlmepriv){
  118. rtw_mfree_mlme_priv_lock (pmlmepriv);
  119. if (pmlmepriv->free_bss_buf) {
  120. rtw_vmfree(pmlmepriv->free_bss_buf, MAX_BSS_CNT * sizeof(struct wlan_network));
  121. }
  122. }
  123. _func_exit_;
  124. }
  125. sint _rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork)
  126. {
  127. _irqL irqL;
  128. _func_enter_;
  129. if (pnetwork == NULL)
  130. goto exit;
  131. _enter_critical_bh(&queue->lock, &irqL);
  132. rtw_list_insert_tail(&pnetwork->list, &queue->queue);
  133. _exit_critical_bh(&queue->lock, &irqL);
  134. exit:
  135. _func_exit_;
  136. return _SUCCESS;
  137. }
  138. /*
  139. struct wlan_network *_rtw_dequeue_network(_queue *queue)
  140. {
  141. _irqL irqL;
  142. struct wlan_network *pnetwork;
  143. _func_enter_;
  144. _enter_critical_bh(&queue->lock, &irqL);
  145. if (_rtw_queue_empty(queue) == _TRUE)
  146. pnetwork = NULL;
  147. else
  148. {
  149. pnetwork = LIST_CONTAINOR(get_next(&queue->queue), struct wlan_network, list);
  150. rtw_list_delete(&(pnetwork->list));
  151. }
  152. _exit_critical_bh(&queue->lock, &irqL);
  153. _func_exit_;
  154. return pnetwork;
  155. }
  156. */
  157. struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv )//(_queue *free_queue)
  158. {
  159. _irqL irqL;
  160. struct wlan_network *pnetwork;
  161. _queue *free_queue = &pmlmepriv->free_bss_pool;
  162. _list* plist = NULL;
  163. _func_enter_;
  164. _enter_critical_bh(&free_queue->lock, &irqL);
  165. if (_rtw_queue_empty(free_queue) == _TRUE) {
  166. pnetwork=NULL;
  167. goto exit;
  168. }
  169. plist = get_next(&(free_queue->queue));
  170. pnetwork = LIST_CONTAINOR(plist , struct wlan_network, list);
  171. rtw_list_delete(&pnetwork->list);
  172. RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("_rtw_alloc_network: ptr=%p\n", plist));
  173. pnetwork->network_type = 0;
  174. pnetwork->fixed = _FALSE;
  175. pnetwork->last_scanned = rtw_get_current_time();
  176. pnetwork->aid=0;
  177. pnetwork->join_res=0;
  178. pmlmepriv->num_of_scanned ++;
  179. exit:
  180. _exit_critical_bh(&free_queue->lock, &irqL);
  181. _func_exit_;
  182. return pnetwork;
  183. }
  184. void _rtw_free_network(struct mlme_priv *pmlmepriv ,struct wlan_network *pnetwork, u8 isfreeall)
  185. {
  186. u32 delta_time;
  187. u32 lifetime = SCANQUEUE_LIFETIME;
  188. _irqL irqL;
  189. _queue *free_queue = &(pmlmepriv->free_bss_pool);
  190. _func_enter_;
  191. if (pnetwork == NULL)
  192. goto exit;
  193. if (pnetwork->fixed == _TRUE)
  194. goto exit;
  195. if ( (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)==_TRUE ) ||
  196. (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)==_TRUE ) )
  197. lifetime = 1;
  198. if(!isfreeall)
  199. {
  200. delta_time = (u32) rtw_get_passing_time_ms(pnetwork->last_scanned);
  201. if(delta_time < lifetime)// unit:msec
  202. goto exit;
  203. }
  204. _enter_critical_bh(&free_queue->lock, &irqL);
  205. rtw_list_delete(&(pnetwork->list));
  206. rtw_list_insert_tail(&(pnetwork->list),&(free_queue->queue));
  207. pmlmepriv->num_of_scanned --;
  208. //DBG_871X("_rtw_free_network:SSID=%s\n", pnetwork->network.Ssid.Ssid);
  209. _exit_critical_bh(&free_queue->lock, &irqL);
  210. exit:
  211. _func_exit_;
  212. }
  213. void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork)
  214. {
  215. _queue *free_queue = &(pmlmepriv->free_bss_pool);
  216. _func_enter_;
  217. if (pnetwork == NULL)
  218. goto exit;
  219. if (pnetwork->fixed == _TRUE)
  220. goto exit;
  221. //_enter_critical(&free_queue->lock, &irqL);
  222. rtw_list_delete(&(pnetwork->list));
  223. rtw_list_insert_tail(&(pnetwork->list), get_list_head(free_queue));
  224. pmlmepriv->num_of_scanned --;
  225. //_exit_critical(&free_queue->lock, &irqL);
  226. exit:
  227. _func_exit_;
  228. }
  229. /*
  230. return the wlan_network with the matching addr
  231. Shall be calle under atomic context... to avoid possible racing condition...
  232. */
  233. struct wlan_network *_rtw_find_network(_queue *scanned_queue, u8 *addr)
  234. {
  235. //_irqL irqL;
  236. _list *phead, *plist;
  237. struct wlan_network *pnetwork = NULL;
  238. u8 zero_addr[ETH_ALEN] = {0,0,0,0,0,0};
  239. _func_enter_;
  240. if(_rtw_memcmp(zero_addr, addr, ETH_ALEN)){
  241. pnetwork=NULL;
  242. goto exit;
  243. }
  244. //_enter_critical_bh(&scanned_queue->lock, &irqL);
  245. phead = get_list_head(scanned_queue);
  246. plist = get_next(phead);
  247. while (plist != phead)
  248. {
  249. pnetwork = LIST_CONTAINOR(plist, struct wlan_network ,list);
  250. if (_rtw_memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN) == _TRUE)
  251. break;
  252. plist = get_next(plist);
  253. }
  254. if(plist == phead)
  255. pnetwork = NULL;
  256. //_exit_critical_bh(&scanned_queue->lock, &irqL);
  257. exit:
  258. _func_exit_;
  259. return pnetwork;
  260. }
  261. void _rtw_free_network_queue(_adapter *padapter, u8 isfreeall)
  262. {
  263. _irqL irqL;
  264. _list *phead, *plist;
  265. struct wlan_network *pnetwork;
  266. struct mlme_priv* pmlmepriv = &padapter->mlmepriv;
  267. _queue *scanned_queue = &pmlmepriv->scanned_queue;
  268. _func_enter_;
  269. _enter_critical_bh(&scanned_queue->lock, &irqL);
  270. phead = get_list_head(scanned_queue);
  271. plist = get_next(phead);
  272. while (rtw_end_of_queue_search(phead, plist) == _FALSE)
  273. {
  274. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  275. plist = get_next(plist);
  276. _rtw_free_network(pmlmepriv,pnetwork, isfreeall);
  277. }
  278. _exit_critical_bh(&scanned_queue->lock, &irqL);
  279. _func_exit_;
  280. }
  281. sint rtw_if_up(_adapter *padapter) {
  282. sint res;
  283. _func_enter_;
  284. if( padapter->bDriverStopped || padapter->bSurpriseRemoved ||
  285. (check_fwstate(&padapter->mlmepriv, _FW_LINKED)== _FALSE)){
  286. RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_if_up:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
  287. res=_FALSE;
  288. }
  289. else
  290. res= _TRUE;
  291. _func_exit_;
  292. return res;
  293. }
  294. void rtw_generate_random_ibss(u8* pibss)
  295. {
  296. u32 curtime = rtw_get_current_time();
  297. _func_enter_;
  298. pibss[0] = 0x02; //in ad-hoc mode bit1 must set to 1
  299. pibss[1] = 0x11;
  300. pibss[2] = 0x87;
  301. pibss[3] = (u8)(curtime & 0xff) ;//p[0];
  302. pibss[4] = (u8)((curtime>>8) & 0xff) ;//p[1];
  303. pibss[5] = (u8)((curtime>>16) & 0xff) ;//p[2];
  304. _func_exit_;
  305. return;
  306. }
  307. u8 *rtw_get_capability_from_ie(u8 *ie)
  308. {
  309. return (ie + 8 + 2);
  310. }
  311. u16 rtw_get_capability(WLAN_BSSID_EX *bss)
  312. {
  313. u16 val;
  314. _func_enter_;
  315. _rtw_memcpy((u8 *)&val, rtw_get_capability_from_ie(bss->IEs), 2);
  316. _func_exit_;
  317. return le16_to_cpu(val);
  318. }
  319. u8 *rtw_get_timestampe_from_ie(u8 *ie)
  320. {
  321. return (ie + 0);
  322. }
  323. u8 *rtw_get_beacon_interval_from_ie(u8 *ie)
  324. {
  325. return (ie + 8);
  326. }
  327. int rtw_init_mlme_priv (_adapter *padapter)//(struct mlme_priv *pmlmepriv)
  328. {
  329. int res;
  330. _func_enter_;
  331. res = _rtw_init_mlme_priv(padapter);// (pmlmepriv);
  332. _func_exit_;
  333. return res;
  334. }
  335. void rtw_free_mlme_priv (struct mlme_priv *pmlmepriv)
  336. {
  337. _func_enter_;
  338. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("rtw_free_mlme_priv\n"));
  339. _rtw_free_mlme_priv (pmlmepriv);
  340. _func_exit_;
  341. }
  342. int rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork);
  343. int rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork)
  344. {
  345. int res;
  346. _func_enter_;
  347. res = _rtw_enqueue_network(queue, pnetwork);
  348. _func_exit_;
  349. return res;
  350. }
  351. /*
  352. static struct wlan_network *rtw_dequeue_network(_queue *queue)
  353. {
  354. struct wlan_network *pnetwork;
  355. _func_enter_;
  356. pnetwork = _rtw_dequeue_network(queue);
  357. _func_exit_;
  358. return pnetwork;
  359. }
  360. */
  361. struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv );
  362. struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv )//(_queue *free_queue)
  363. {
  364. struct wlan_network *pnetwork;
  365. _func_enter_;
  366. pnetwork = _rtw_alloc_network(pmlmepriv);
  367. _func_exit_;
  368. return pnetwork;
  369. }
  370. void rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 is_freeall);
  371. void rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 is_freeall)//(struct wlan_network *pnetwork, _queue *free_queue)
  372. {
  373. _func_enter_;
  374. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("rtw_free_network==> ssid = %s \n\n" , pnetwork->network.Ssid.Ssid));
  375. _rtw_free_network(pmlmepriv, pnetwork, is_freeall);
  376. _func_exit_;
  377. }
  378. void rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork );
  379. void rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork )
  380. {
  381. _func_enter_;
  382. //RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("rtw_free_network==> ssid = %s \n\n" , pnetwork->network.Ssid.Ssid));
  383. _rtw_free_network_nolock(pmlmepriv, pnetwork);
  384. _func_exit_;
  385. }
  386. void rtw_free_network_queue(_adapter* dev, u8 isfreeall)
  387. {
  388. _func_enter_;
  389. _rtw_free_network_queue(dev, isfreeall);
  390. _func_exit_;
  391. }
  392. /*
  393. return the wlan_network with the matching addr
  394. Shall be calle under atomic context... to avoid possible racing condition...
  395. */
  396. struct wlan_network *rtw_find_network(_queue *scanned_queue, u8 *addr)
  397. {
  398. struct wlan_network *pnetwork = _rtw_find_network(scanned_queue, addr);
  399. return pnetwork;
  400. }
  401. int rtw_is_same_ibss(_adapter *adapter, struct wlan_network *pnetwork)
  402. {
  403. int ret=_TRUE;
  404. struct security_priv *psecuritypriv = &adapter->securitypriv;
  405. if ( (psecuritypriv->dot11PrivacyAlgrthm != _NO_PRIVACY_ ) &&
  406. ( pnetwork->network.Privacy == 0 ) )
  407. {
  408. ret=_FALSE;
  409. }
  410. else if((psecuritypriv->dot11PrivacyAlgrthm == _NO_PRIVACY_ ) &&
  411. ( pnetwork->network.Privacy == 1 ) )
  412. {
  413. ret=_FALSE;
  414. }
  415. else
  416. {
  417. ret=_TRUE;
  418. }
  419. return ret;
  420. }
  421. inline int is_same_ess(WLAN_BSSID_EX *a, WLAN_BSSID_EX *b);
  422. inline int is_same_ess(WLAN_BSSID_EX *a, WLAN_BSSID_EX *b)
  423. {
  424. //RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("(%s,%d)(%s,%d)\n",
  425. // a->Ssid.Ssid,a->Ssid.SsidLength,b->Ssid.Ssid,b->Ssid.SsidLength));
  426. return (a->Ssid.SsidLength == b->Ssid.SsidLength)
  427. && _rtw_memcmp(a->Ssid.Ssid, b->Ssid.Ssid, a->Ssid.SsidLength)==_TRUE;
  428. }
  429. int is_same_network(WLAN_BSSID_EX *src, WLAN_BSSID_EX *dst)
  430. {
  431. u16 s_cap, d_cap;
  432. _func_enter_;
  433. if(rtw_bug_check(dst, src, &s_cap, &d_cap)==_FALSE)
  434. return _FALSE;
  435. _rtw_memcpy((u8 *)&s_cap, rtw_get_capability_from_ie(src->IEs), 2);
  436. _rtw_memcpy((u8 *)&d_cap, rtw_get_capability_from_ie(dst->IEs), 2);
  437. s_cap = le16_to_cpu(s_cap);
  438. d_cap = le16_to_cpu(d_cap);
  439. _func_exit_;
  440. return ((src->Ssid.SsidLength == dst->Ssid.SsidLength) &&
  441. // (src->Configuration.DSConfig == dst->Configuration.DSConfig) &&
  442. ( (_rtw_memcmp(src->MacAddress, dst->MacAddress, ETH_ALEN)) == _TRUE) &&
  443. ( (_rtw_memcmp(src->Ssid.Ssid, dst->Ssid.Ssid, src->Ssid.SsidLength)) == _TRUE) &&
  444. ((s_cap & WLAN_CAPABILITY_IBSS) ==
  445. (d_cap & WLAN_CAPABILITY_IBSS)) &&
  446. ((s_cap & WLAN_CAPABILITY_BSS) ==
  447. (d_cap & WLAN_CAPABILITY_BSS)));
  448. }
  449. struct wlan_network * rtw_get_oldest_wlan_network(_queue *scanned_queue)
  450. {
  451. _list *plist, *phead;
  452. struct wlan_network *pwlan = NULL;
  453. struct wlan_network *oldest = NULL;
  454. _func_enter_;
  455. phead = get_list_head(scanned_queue);
  456. plist = get_next(phead);
  457. while(1)
  458. {
  459. if (rtw_end_of_queue_search(phead,plist)== _TRUE)
  460. break;
  461. pwlan= LIST_CONTAINOR(plist, struct wlan_network, list);
  462. if(pwlan->fixed!=_TRUE)
  463. {
  464. if (oldest == NULL ||time_after(oldest->last_scanned, pwlan->last_scanned))
  465. oldest = pwlan;
  466. }
  467. plist = get_next(plist);
  468. }
  469. _func_exit_;
  470. return oldest;
  471. }
  472. void update_network(WLAN_BSSID_EX *dst, WLAN_BSSID_EX *src,
  473. _adapter * padapter, bool update_ie)
  474. {
  475. u8 ss_ori = dst->PhyInfo.SignalStrength;
  476. u8 sq_ori = dst->PhyInfo.SignalQuality;
  477. long rssi_ori = dst->Rssi;
  478. u8 ss_smp = src->PhyInfo.SignalStrength;
  479. u8 sq_smp = src->PhyInfo.SignalQuality;
  480. long rssi_smp = src->Rssi;
  481. u8 ss_final;
  482. u8 sq_final;
  483. long rssi_final;
  484. _func_enter_;
  485. #ifdef CONFIG_ANTENNA_DIVERSITY
  486. rtw_hal_antdiv_rssi_compared(padapter, dst, src); //this will update src.Rssi, need consider again
  487. #endif
  488. #if defined(DBG_RX_SIGNAL_DISPLAY_PROCESSING) && 1
  489. if(strcmp(dst->Ssid.Ssid, DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) == 0) {
  490. DBG_871X("%s %s("MAC_FMT", ch%u) ss_ori:%3u, sq_ori:%3u, rssi_ori:%3ld, ss_smp:%3u, sq_smp:%3u, rssi_smp:%3ld\n"
  491. , __FUNCTION__
  492. , src->Ssid.Ssid, MAC_ARG(src->MacAddress), src->Configuration.DSConfig
  493. ,ss_ori, sq_ori, rssi_ori
  494. ,ss_smp, sq_smp, rssi_smp
  495. );
  496. }
  497. #endif
  498. /* The rule below is 1/5 for sample value, 4/5 for history value */
  499. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) && is_same_network(&(padapter->mlmepriv.cur_network.network), src)) {
  500. /* Take the recvpriv's value for the connected AP*/
  501. ss_final = padapter->recvpriv.signal_strength;
  502. sq_final = padapter->recvpriv.signal_qual;
  503. /* the rssi value here is undecorated, and will be used for antenna diversity */
  504. if(sq_smp != 101) /* from the right channel */
  505. rssi_final = (src->Rssi+dst->Rssi*4)/5;
  506. else
  507. rssi_final = rssi_ori;
  508. }
  509. else {
  510. if(sq_smp != 101) { /* from the right channel */
  511. ss_final = ((u32)(src->PhyInfo.SignalStrength)+(u32)(dst->PhyInfo.SignalStrength)*4)/5;
  512. sq_final = ((u32)(src->PhyInfo.SignalQuality)+(u32)(dst->PhyInfo.SignalQuality)*4)/5;
  513. rssi_final = (src->Rssi+dst->Rssi*4)/5;
  514. } else {
  515. /* bss info not receving from the right channel, use the original RX signal infos */
  516. ss_final = dst->PhyInfo.SignalStrength;
  517. sq_final = dst->PhyInfo.SignalQuality;
  518. rssi_final = dst->Rssi;
  519. }
  520. }
  521. if (update_ie)
  522. _rtw_memcpy((u8 *)dst, (u8 *)src, get_WLAN_BSSID_EX_sz(src));
  523. dst->PhyInfo.SignalStrength = ss_final;
  524. dst->PhyInfo.SignalQuality = sq_final;
  525. dst->Rssi = rssi_final;
  526. #if defined(DBG_RX_SIGNAL_DISPLAY_PROCESSING) && 1
  527. if(strcmp(dst->Ssid.Ssid, DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) == 0) {
  528. DBG_871X("%s %s("MAC_FMT"), SignalStrength:%u, SignalQuality:%u, RawRSSI:%ld\n"
  529. , __FUNCTION__
  530. , dst->Ssid.Ssid, MAC_ARG(dst->MacAddress), dst->PhyInfo.SignalStrength, dst->PhyInfo.SignalQuality, dst->Rssi);
  531. }
  532. #endif
  533. #if 0 // old codes, may be useful one day...
  534. // DBG_871X("update_network: rssi=0x%lx dst->Rssi=%d ,dst->Rssi=0x%lx , src->Rssi=0x%lx",(dst->Rssi+src->Rssi)/2,dst->Rssi,dst->Rssi,src->Rssi);
  535. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) && is_same_network(&(padapter->mlmepriv.cur_network.network), src))
  536. {
  537. //DBG_871X("b:ssid=%s update_network: src->rssi=0x%d padapter->recvpriv.ui_rssi=%d\n",src->Ssid.Ssid,src->Rssi,padapter->recvpriv.signal);
  538. if(padapter->recvpriv.signal_qual_data.total_num++ >= PHY_LINKQUALITY_SLID_WIN_MAX)
  539. {
  540. padapter->recvpriv.signal_qual_data.total_num = PHY_LINKQUALITY_SLID_WIN_MAX;
  541. last_evm = padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index];
  542. padapter->recvpriv.signal_qual_data.total_val -= last_evm;
  543. }
  544. padapter->recvpriv.signal_qual_data.total_val += query_rx_pwr_percentage(src->Rssi);
  545. padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index++] = query_rx_pwr_percentage(src->Rssi);
  546. if(padapter->recvpriv.signal_qual_data.index >= PHY_LINKQUALITY_SLID_WIN_MAX)
  547. padapter->recvpriv.signal_qual_data.index = 0;
  548. //DBG_871X("Total SQ=%d pattrib->signal_qual= %d\n", padapter->recvpriv.signal_qual_data.total_val, src->Rssi);
  549. // <1> Showed on UI for user,in percentage.
  550. tmpVal = padapter->recvpriv.signal_qual_data.total_val/padapter->recvpriv.signal_qual_data.total_num;
  551. padapter->recvpriv.signal=(u8)tmpVal;//Link quality
  552. src->Rssi= translate_percentage_to_dbm(padapter->recvpriv.signal) ;
  553. }
  554. else{
  555. // DBG_871X("ELSE:ssid=%s update_network: src->rssi=0x%d dst->rssi=%d\n",src->Ssid.Ssid,src->Rssi,dst->Rssi);
  556. src->Rssi=(src->Rssi +dst->Rssi)/2;//dBM
  557. }
  558. // DBG_871X("a:update_network: src->rssi=0x%d padapter->recvpriv.ui_rssi=%d\n",src->Rssi,padapter->recvpriv.signal);
  559. #endif
  560. _func_exit_;
  561. }
  562. static void update_current_network(_adapter *adapter, WLAN_BSSID_EX *pnetwork)
  563. {
  564. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  565. _func_enter_;
  566. rtw_bug_check(&(pmlmepriv->cur_network.network),
  567. &(pmlmepriv->cur_network.network),
  568. &(pmlmepriv->cur_network.network),
  569. &(pmlmepriv->cur_network.network));
  570. if ( (check_fwstate(pmlmepriv, _FW_LINKED)== _TRUE) && (is_same_network(&(pmlmepriv->cur_network.network), pnetwork)))
  571. {
  572. //RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,"Same Network\n");
  573. //if(pmlmepriv->cur_network.network.IELength<= pnetwork->IELength)
  574. {
  575. update_network(&(pmlmepriv->cur_network.network), pnetwork,adapter, _TRUE);
  576. rtw_update_protection(adapter, (pmlmepriv->cur_network.network.IEs) + sizeof (NDIS_802_11_FIXED_IEs),
  577. pmlmepriv->cur_network.network.IELength);
  578. }
  579. }
  580. _func_exit_;
  581. }
  582. /*
  583. Caller must hold pmlmepriv->lock first.
  584. */
  585. void rtw_update_scanned_network(_adapter *adapter, WLAN_BSSID_EX *target)
  586. {
  587. _irqL irqL;
  588. _list *plist, *phead;
  589. ULONG bssid_ex_sz;
  590. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  591. _queue *queue = &(pmlmepriv->scanned_queue);
  592. struct wlan_network *pnetwork = NULL;
  593. struct wlan_network *oldest = NULL;
  594. _func_enter_;
  595. _enter_critical_bh(&queue->lock, &irqL);
  596. phead = get_list_head(queue);
  597. plist = get_next(phead);
  598. while(1)
  599. {
  600. if (rtw_end_of_queue_search(phead,plist)== _TRUE)
  601. break;
  602. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  603. rtw_bug_check(pnetwork, pnetwork, pnetwork, pnetwork);
  604. if (is_same_network(&(pnetwork->network), target))
  605. break;
  606. if ((oldest == ((struct wlan_network *)0)) ||
  607. time_after(oldest->last_scanned, pnetwork->last_scanned))
  608. oldest = pnetwork;
  609. plist = get_next(plist);
  610. }
  611. /* If we didn't find a match, then get a new network slot to initialize
  612. * with this beacon's information */
  613. if (rtw_end_of_queue_search(phead,plist)== _TRUE) {
  614. if (_rtw_queue_empty(&(pmlmepriv->free_bss_pool)) == _TRUE) {
  615. /* If there are no more slots, expire the oldest */
  616. //list_del_init(&oldest->list);
  617. pnetwork = oldest;
  618. #ifdef CONFIG_ANTENNA_DIVERSITY
  619. //target->PhyInfo.Optimum_antenna = pHalData->CurAntenna;//optimum_antenna=>For antenna diversity
  620. rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA, &(target->PhyInfo.Optimum_antenna));
  621. #endif
  622. _rtw_memcpy(&(pnetwork->network), target, get_WLAN_BSSID_EX_sz(target));
  623. //pnetwork->last_scanned = rtw_get_current_time();
  624. // variable initialize
  625. pnetwork->fixed = _FALSE;
  626. pnetwork->last_scanned = rtw_get_current_time();
  627. pnetwork->network_type = 0;
  628. pnetwork->aid=0;
  629. pnetwork->join_res=0;
  630. /* bss info not receving from the right channel */
  631. if (pnetwork->network.PhyInfo.SignalQuality == 101)
  632. pnetwork->network.PhyInfo.SignalQuality = 0;
  633. }
  634. else {
  635. /* Otherwise just pull from the free list */
  636. pnetwork = rtw_alloc_network(pmlmepriv); // will update scan_time
  637. if(pnetwork==NULL){
  638. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("\n\n\nsomething wrong here\n\n\n"));
  639. goto exit;
  640. }
  641. bssid_ex_sz = get_WLAN_BSSID_EX_sz(target);
  642. target->Length = bssid_ex_sz;
  643. #ifdef CONFIG_ANTENNA_DIVERSITY
  644. //target->PhyInfo.Optimum_antenna = pHalData->CurAntenna;
  645. rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA, &(target->PhyInfo.Optimum_antenna));
  646. #endif
  647. _rtw_memcpy(&(pnetwork->network), target, bssid_ex_sz );
  648. pnetwork->last_scanned = rtw_get_current_time();
  649. /* bss info not receving from the right channel */
  650. if (pnetwork->network.PhyInfo.SignalQuality == 101)
  651. pnetwork->network.PhyInfo.SignalQuality = 0;
  652. rtw_list_insert_tail(&(pnetwork->list),&(queue->queue));
  653. }
  654. }
  655. else {
  656. /* we have an entry and we are going to update it. But this entry may
  657. * be already expired. In this case we do the same as we found a new
  658. * net and call the new_net handler
  659. */
  660. bool update_ie = _TRUE;
  661. pnetwork->last_scanned = rtw_get_current_time();
  662. //target.Reserved[0]==1, means that scaned network is a bcn frame.
  663. if((pnetwork->network.IELength>target->IELength) && (target->Reserved[0]==1))
  664. update_ie = _FALSE;
  665. update_network(&(pnetwork->network), target,adapter, update_ie);
  666. }
  667. exit:
  668. _exit_critical_bh(&queue->lock, &irqL);
  669. _func_exit_;
  670. }
  671. void rtw_add_network(_adapter *adapter, WLAN_BSSID_EX *pnetwork);
  672. void rtw_add_network(_adapter *adapter, WLAN_BSSID_EX *pnetwork)
  673. {
  674. _irqL irqL;
  675. struct mlme_priv *pmlmepriv = &(((_adapter *)adapter)->mlmepriv);
  676. //_queue *queue = &(pmlmepriv->scanned_queue);
  677. _func_enter_;
  678. //_enter_critical_bh(&queue->lock, &irqL);
  679. #if defined(CONFIG_P2P) && defined(CONFIG_P2P_REMOVE_GROUP_INFO)
  680. rtw_WLAN_BSSID_EX_remove_p2p_attr(pnetwork, P2P_ATTR_GROUP_INFO);
  681. #endif
  682. update_current_network(adapter, pnetwork);
  683. rtw_update_scanned_network(adapter, pnetwork);
  684. //_exit_critical_bh(&queue->lock, &irqL);
  685. _func_exit_;
  686. }
  687. //select the desired network based on the capability of the (i)bss.
  688. // check items: (1) security
  689. // (2) network_type
  690. // (3) WMM
  691. // (4) HT
  692. // (5) others
  693. int rtw_is_desired_network(_adapter *adapter, struct wlan_network *pnetwork);
  694. int rtw_is_desired_network(_adapter *adapter, struct wlan_network *pnetwork)
  695. {
  696. struct security_priv *psecuritypriv = &adapter->securitypriv;
  697. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  698. u32 desired_encmode;
  699. u32 privacy;
  700. //u8 wps_ie[512];
  701. uint wps_ielen;
  702. int bselected = _TRUE;
  703. desired_encmode = psecuritypriv->ndisencryptstatus;
  704. privacy = pnetwork->network.Privacy;
  705. if(check_fwstate(pmlmepriv, WIFI_UNDER_WPS))
  706. {
  707. if(rtw_get_wps_ie(pnetwork->network.IEs+_FIXED_IE_LENGTH_, pnetwork->network.IELength-_FIXED_IE_LENGTH_, NULL, &wps_ielen)!=NULL)
  708. {
  709. return _TRUE;
  710. }
  711. else
  712. {
  713. return _FALSE;
  714. }
  715. }
  716. if (adapter->registrypriv.wifi_spec == 1) //for correct flow of 8021X to do....
  717. {
  718. if ((desired_encmode == Ndis802_11EncryptionDisabled) && (privacy != 0))
  719. bselected = _FALSE;
  720. }
  721. if ((desired_encmode != Ndis802_11EncryptionDisabled) && (privacy == 0)) {
  722. DBG_871X("desired_encmode: %d, privacy: %d\n", desired_encmode, privacy);
  723. bselected = _FALSE;
  724. }
  725. if(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE)
  726. {
  727. if(pnetwork->network.InfrastructureMode != pmlmepriv->cur_network.network.InfrastructureMode)
  728. bselected = _FALSE;
  729. }
  730. return bselected;
  731. }
  732. /* TODO: Perry : For Power Management */
  733. void rtw_atimdone_event_callback(_adapter *adapter , u8 *pbuf)
  734. {
  735. _func_enter_;
  736. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("receive atimdone_evet\n"));
  737. _func_exit_;
  738. return;
  739. }
  740. void rtw_survey_event_callback(_adapter *adapter, u8 *pbuf)
  741. {
  742. _irqL irqL;
  743. u32 len;
  744. WLAN_BSSID_EX *pnetwork;
  745. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  746. _func_enter_;
  747. pnetwork = (WLAN_BSSID_EX *)pbuf;
  748. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_survey_event_callback, ssid=%s\n", pnetwork->Ssid.Ssid));
  749. #ifdef CONFIG_RTL8712
  750. //endian_convert
  751. pnetwork->Length = le32_to_cpu(pnetwork->Length);
  752. pnetwork->Ssid.SsidLength = le32_to_cpu(pnetwork->Ssid.SsidLength);
  753. pnetwork->Privacy =le32_to_cpu( pnetwork->Privacy);
  754. pnetwork->Rssi = le32_to_cpu(pnetwork->Rssi);
  755. pnetwork->NetworkTypeInUse =le32_to_cpu(pnetwork->NetworkTypeInUse);
  756. pnetwork->Configuration.ATIMWindow = le32_to_cpu(pnetwork->Configuration.ATIMWindow);
  757. pnetwork->Configuration.BeaconPeriod = le32_to_cpu(pnetwork->Configuration.BeaconPeriod);
  758. pnetwork->Configuration.DSConfig =le32_to_cpu(pnetwork->Configuration.DSConfig);
  759. pnetwork->Configuration.FHConfig.DwellTime=le32_to_cpu(pnetwork->Configuration.FHConfig.DwellTime);
  760. pnetwork->Configuration.FHConfig.HopPattern=le32_to_cpu(pnetwork->Configuration.FHConfig.HopPattern);
  761. pnetwork->Configuration.FHConfig.HopSet=le32_to_cpu(pnetwork->Configuration.FHConfig.HopSet);
  762. pnetwork->Configuration.FHConfig.Length=le32_to_cpu(pnetwork->Configuration.FHConfig.Length);
  763. pnetwork->Configuration.Length = le32_to_cpu(pnetwork->Configuration.Length);
  764. pnetwork->InfrastructureMode = le32_to_cpu(pnetwork->InfrastructureMode);
  765. pnetwork->IELength = le32_to_cpu(pnetwork->IELength);
  766. #endif
  767. len = get_WLAN_BSSID_EX_sz(pnetwork);
  768. if(len > (sizeof(WLAN_BSSID_EX)))
  769. {
  770. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("\n ****rtw_survey_event_callback: return a wrong bss ***\n"));
  771. return;
  772. }
  773. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  774. // update IBSS_network 's timestamp
  775. if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) == _TRUE)
  776. {
  777. //RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,"rtw_survey_event_callback : WIFI_ADHOC_MASTER_STATE \n\n");
  778. if(_rtw_memcmp(&(pmlmepriv->cur_network.network.MacAddress), pnetwork->MacAddress, ETH_ALEN))
  779. {
  780. struct wlan_network* ibss_wlan = NULL;
  781. _irqL irqL;
  782. _rtw_memcpy(pmlmepriv->cur_network.network.IEs, pnetwork->IEs, 8);
  783. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  784. ibss_wlan = rtw_find_network(&pmlmepriv->scanned_queue, pnetwork->MacAddress);
  785. if(ibss_wlan)
  786. {
  787. _rtw_memcpy(ibss_wlan->network.IEs , pnetwork->IEs, 8);
  788. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  789. goto exit;
  790. }
  791. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  792. }
  793. }
  794. // lock pmlmepriv->lock when you accessing network_q
  795. if ((check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) == _FALSE)
  796. {
  797. if( pnetwork->Ssid.Ssid[0] == 0 )
  798. {
  799. pnetwork->Ssid.SsidLength = 0;
  800. }
  801. rtw_add_network(adapter, pnetwork);
  802. }
  803. exit:
  804. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  805. _func_exit_;
  806. return;
  807. }
  808. void rtw_surveydone_event_callback(_adapter *adapter, u8 *pbuf)
  809. {
  810. _irqL irqL;
  811. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  812. #ifdef CONFIG_MLME_EXT
  813. mlmeext_surveydone_event_callback(adapter);
  814. #endif
  815. _func_enter_;
  816. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  817. if(pmlmepriv->wps_probe_req_ie)
  818. {
  819. u32 free_len = pmlmepriv->wps_probe_req_ie_len;
  820. pmlmepriv->wps_probe_req_ie_len = 0;
  821. rtw_mfree(pmlmepriv->wps_probe_req_ie, free_len);
  822. pmlmepriv->wps_probe_req_ie = NULL;
  823. }
  824. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_surveydone_event_callback: fw_state:%x\n\n", get_fwstate(pmlmepriv)));
  825. if (check_fwstate(pmlmepriv,_FW_UNDER_SURVEY))
  826. {
  827. u8 timer_cancelled;
  828. _cancel_timer(&pmlmepriv->scan_to_timer, &timer_cancelled);
  829. _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
  830. }
  831. else {
  832. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("nic status =%x, survey done event comes too late!\n", get_fwstate(pmlmepriv)));
  833. }
  834. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  835. rtw_set_signal_stat_timer(&adapter->recvpriv);
  836. #endif
  837. if(pmlmepriv->to_join == _TRUE)
  838. {
  839. if((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)==_TRUE) )
  840. {
  841. if(check_fwstate(pmlmepriv, _FW_LINKED)==_FALSE)
  842. {
  843. set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
  844. if(rtw_select_and_join_from_scanned_queue(pmlmepriv)==_SUCCESS)
  845. {
  846. _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT );
  847. }
  848. else
  849. {
  850. WLAN_BSSID_EX *pdev_network = &(adapter->registrypriv.dev_network);
  851. u8 *pibss = adapter->registrypriv.dev_network.MacAddress;
  852. //pmlmepriv->fw_state ^= _FW_UNDER_SURVEY;//because don't set assoc_timer
  853. _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
  854. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("switching to adhoc master\n"));
  855. _rtw_memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
  856. _rtw_memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
  857. rtw_update_registrypriv_dev_network(adapter);
  858. rtw_generate_random_ibss(pibss);
  859. pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;
  860. if(rtw_createbss_cmd(adapter)!=_SUCCESS)
  861. {
  862. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("Error=>rtw_createbss_cmd status FAIL\n"));
  863. }
  864. pmlmepriv->to_join = _FALSE;
  865. }
  866. }
  867. }
  868. else
  869. {
  870. int s_ret;
  871. set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
  872. pmlmepriv->to_join = _FALSE;
  873. if(_SUCCESS == (s_ret=rtw_select_and_join_from_scanned_queue(pmlmepriv)))
  874. {
  875. _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
  876. }
  877. else if(s_ret == 2)//there is no need to wait for join
  878. {
  879. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  880. rtw_indicate_connect(adapter);
  881. }
  882. else
  883. {
  884. DBG_871X("try_to_join, but select scanning queue fail, to_roaming:%d\n", rtw_to_roaming(adapter));
  885. #ifdef CONFIG_LAYER2_ROAMING
  886. if (rtw_to_roaming(adapter) != 0) {
  887. if( --pmlmepriv->to_roaming == 0
  888. || _SUCCESS != rtw_sitesurvey_cmd(adapter, &pmlmepriv->assoc_ssid, 1, NULL, 0)
  889. ) {
  890. rtw_set_roaming(adapter, 0);
  891. #ifdef CONFIG_INTEL_WIDI
  892. if(adapter->mlmepriv.widi_state == INTEL_WIDI_STATE_ROAMING)
  893. {
  894. _rtw_memset(pmlmepriv->sa_ext, 0x00, L2SDTA_SERVICE_VE_LEN);
  895. intel_widi_wk_cmd(adapter, INTEL_WIDI_LISTEN_WK, NULL);
  896. DBG_871X("change to widi listen\n");
  897. }
  898. #endif // CONFIG_INTEL_WIDI
  899. rtw_free_assoc_resources(adapter, 1);
  900. rtw_indicate_disconnect(adapter);
  901. } else {
  902. pmlmepriv->to_join = _TRUE;
  903. }
  904. }
  905. #endif
  906. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  907. }
  908. }
  909. }
  910. indicate_wx_scan_complete_event(adapter);
  911. //DBG_871X("scan complete in %dms\n",rtw_get_passing_time_ms(pmlmepriv->scan_start_time));
  912. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  913. #ifdef CONFIG_P2P_PS
  914. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  915. p2p_ps_wk_cmd(adapter, P2P_PS_SCAN_DONE, 0);
  916. }
  917. #endif // CONFIG_P2P_PS
  918. rtw_os_xmit_schedule(adapter);
  919. #ifdef CONFIG_CONCURRENT_MODE
  920. rtw_os_xmit_schedule(adapter->pbuddy_adapter);
  921. #endif
  922. #ifdef CONFIG_DUALMAC_CONCURRENT
  923. dc_resume_xmit(adapter);
  924. #endif
  925. #ifdef CONFIG_DRVEXT_MODULE_WSC
  926. drvext_surveydone_callback(&adapter->drvextpriv);
  927. #endif
  928. #ifdef DBG_CONFIG_ERROR_DETECT
  929. {
  930. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  931. if(pmlmeext->sitesurvey_res.bss_cnt == 0){
  932. rtw_hal_sreset_reset(adapter);
  933. }
  934. }
  935. #endif
  936. #ifdef CONFIG_IOCTL_CFG80211
  937. rtw_cfg80211_surveydone_event_callback(adapter);
  938. #endif //CONFIG_IOCTL_CFG80211
  939. _func_exit_;
  940. }
  941. void rtw_dummy_event_callback(_adapter *adapter , u8 *pbuf)
  942. {
  943. }
  944. void rtw_fwdbg_event_callback(_adapter *adapter , u8 *pbuf)
  945. {
  946. }
  947. static void free_scanqueue(struct mlme_priv *pmlmepriv)
  948. {
  949. _irqL irqL, irqL0;
  950. _queue *free_queue = &pmlmepriv->free_bss_pool;
  951. _queue *scan_queue = &pmlmepriv->scanned_queue;
  952. _list *plist, *phead, *ptemp;
  953. _func_enter_;
  954. RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_, ("+free_scanqueue\n"));
  955. _enter_critical_bh(&scan_queue->lock, &irqL0);
  956. _enter_critical_bh(&free_queue->lock, &irqL);
  957. phead = get_list_head(scan_queue);
  958. plist = get_next(phead);
  959. while (plist != phead)
  960. {
  961. ptemp = get_next(plist);
  962. rtw_list_delete(plist);
  963. rtw_list_insert_tail(plist, &free_queue->queue);
  964. plist =ptemp;
  965. pmlmepriv->num_of_scanned --;
  966. }
  967. _exit_critical_bh(&free_queue->lock, &irqL);
  968. _exit_critical_bh(&scan_queue->lock, &irqL0);
  969. _func_exit_;
  970. }
  971. /*
  972. *rtw_free_assoc_resources: the caller has to lock pmlmepriv->lock
  973. */
  974. void rtw_free_assoc_resources(_adapter *adapter, int lock_scanned_queue)
  975. {
  976. _irqL irqL;
  977. struct wlan_network* pwlan = NULL;
  978. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  979. struct sta_priv *pstapriv = &adapter->stapriv;
  980. struct wlan_network *tgt_network = &pmlmepriv->cur_network;
  981. #ifdef CONFIG_TDLS
  982. struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
  983. #endif //CONFIG_TDLS
  984. _func_enter_;
  985. RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_, ("+rtw_free_assoc_resources\n"));
  986. RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("tgt_network->network.MacAddress="MAC_FMT" ssid=%s\n",
  987. MAC_ARG(tgt_network->network.MacAddress), tgt_network->network.Ssid.Ssid));
  988. if(check_fwstate( pmlmepriv, WIFI_STATION_STATE|WIFI_AP_STATE))
  989. {
  990. struct sta_info* psta;
  991. psta = rtw_get_stainfo(&adapter->stapriv, tgt_network->network.MacAddress);
  992. #ifdef CONFIG_TDLS
  993. if(ptdlsinfo->setup_state != TDLS_STATE_NONE)
  994. {
  995. rtw_tdls_cmd(adapter, myid(&(adapter->eeprompriv)), TDLS_RS_RCR);
  996. rtw_reset_tdls_info(adapter);
  997. rtw_free_all_stainfo(adapter);
  998. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  999. }
  1000. else
  1001. #endif //CONFIG_TDLS
  1002. {
  1003. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  1004. rtw_free_stainfo(adapter, psta);
  1005. }
  1006. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  1007. }
  1008. if(check_fwstate( pmlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE))
  1009. {
  1010. struct sta_info* psta;
  1011. rtw_free_all_stainfo(adapter);
  1012. psta = rtw_get_bcmc_stainfo(adapter);
  1013. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  1014. rtw_free_stainfo(adapter, psta);
  1015. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  1016. rtw_init_bcmc_stainfo(adapter);
  1017. }
  1018. if(lock_scanned_queue)
  1019. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1020. pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.MacAddress);
  1021. if(pwlan)
  1022. {
  1023. pwlan->fixed = _FALSE;
  1024. }
  1025. else
  1026. {
  1027. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("rtw_free_assoc_resources : pwlan== NULL \n\n"));
  1028. }
  1029. if((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) && (adapter->stapriv.asoc_sta_count== 1))
  1030. /*||check_fwstate(pmlmepriv, WIFI_STATION_STATE)*/)
  1031. {
  1032. rtw_free_network_nolock(pmlmepriv, pwlan);
  1033. }
  1034. if(lock_scanned_queue)
  1035. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1036. pmlmepriv->key_mask = 0;
  1037. _func_exit_;
  1038. }
  1039. /*
  1040. *rtw_indicate_connect: the caller has to lock pmlmepriv->lock
  1041. */
  1042. void rtw_indicate_connect(_adapter *padapter)
  1043. {
  1044. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1045. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1046. _func_enter_;
  1047. RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("+rtw_indicate_connect\n"));
  1048. pmlmepriv->to_join = _FALSE;
  1049. if(!check_fwstate(&padapter->mlmepriv, _FW_LINKED))
  1050. {
  1051. #ifdef CONFIG_SW_ANTENNA_DIVERSITY
  1052. rtw_hal_set_hwreg(padapter, HW_VAR_ANTENNA_DIVERSITY_LINK, 0);
  1053. #endif
  1054. set_fwstate(pmlmepriv, _FW_LINKED);
  1055. rtw_led_control(padapter, LED_CTL_LINK);
  1056. #ifdef CONFIG_DRVEXT_MODULE
  1057. if(padapter->drvextpriv.enable_wpa)
  1058. {
  1059. indicate_l2_connect(padapter);
  1060. }
  1061. else
  1062. #endif
  1063. {
  1064. rtw_os_indicate_connect(padapter);
  1065. }
  1066. }
  1067. rtw_set_roaming(padapter, 0);
  1068. #ifdef CONFIG_INTEL_WIDI
  1069. if(padapter->mlmepriv.widi_state == INTEL_WIDI_STATE_ROAMING)
  1070. {
  1071. _rtw_memset(pmlmepriv->sa_ext, 0x00, L2SDTA_SERVICE_VE_LEN);
  1072. intel_widi_wk_cmd(padapter, INTEL_WIDI_LISTEN_WK, NULL);
  1073. DBG_871X("change to widi listen\n");
  1074. }
  1075. #endif // CONFIG_INTEL_WIDI
  1076. rtw_set_scan_deny(padapter, 3000);
  1077. RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("-rtw_indicate_connect: fw_state=0x%08x\n", get_fwstate(pmlmepriv)));
  1078. _func_exit_;
  1079. }
  1080. /*
  1081. *rtw_indicate_disconnect: the caller has to lock pmlmepriv->lock
  1082. */
  1083. void rtw_indicate_disconnect( _adapter *padapter )
  1084. {
  1085. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1086. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1087. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1088. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  1089. struct sta_info *psta;
  1090. struct sta_priv *pstapriv = &padapter->stapriv;
  1091. _func_enter_;
  1092. RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("+rtw_indicate_disconnect\n"));
  1093. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING|WIFI_UNDER_WPS);
  1094. //DBG_871X("clear wps when %s\n", __func__);
  1095. if(rtw_to_roaming(padapter) > 0)
  1096. _clr_fwstate_(pmlmepriv, _FW_LINKED);
  1097. #ifdef CONFIG_WAPI_SUPPORT
  1098. psta = rtw_get_stainfo(pstapriv,cur_network->MacAddress);
  1099. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
  1100. {
  1101. rtw_wapi_return_one_sta_info(padapter, psta->hwaddr);
  1102. }
  1103. else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
  1104. check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
  1105. {
  1106. rtw_wapi_return_all_sta_info(padapter);
  1107. }
  1108. #endif
  1109. if(check_fwstate(&padapter->mlmepriv, _FW_LINKED)
  1110. || (rtw_to_roaming(padapter) <= 0)
  1111. )
  1112. {
  1113. rtw_os_indicate_disconnect(padapter);
  1114. //set ips_deny_time to avoid enter IPS before LPS leave
  1115. padapter->pwrctrlpriv.ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(3000);
  1116. _clr_fwstate_(pmlmepriv, _FW_LINKED);
  1117. rtw_led_control(padapter, LED_CTL_NO_LINK);
  1118. rtw_clear_scan_deny(padapter);
  1119. }
  1120. #ifdef CONFIG_P2P_PS
  1121. p2p_ps_wk_cmd(padapter, P2P_PS_DISABLE, 1);
  1122. #endif // CONFIG_P2P_PS
  1123. #ifdef CONFIG_LPS
  1124. #ifdef CONFIG_WOWLAN
  1125. if(padapter->pwrctrlpriv.wowlan_mode==_FALSE)
  1126. #endif //CONFIG_WOWLAN
  1127. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, 1);
  1128. #endif
  1129. _func_exit_;
  1130. }
  1131. inline void rtw_indicate_scan_done( _adapter *padapter, bool aborted)
  1132. {
  1133. rtw_os_indicate_scan_done(padapter, aborted);
  1134. }
  1135. void rtw_scan_abort(_adapter *adapter)
  1136. {
  1137. u32 cnt=0;
  1138. u32 start;
  1139. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  1140. struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
  1141. start = rtw_get_current_time();
  1142. pmlmeext->scan_abort = _TRUE;
  1143. while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)
  1144. && rtw_get_passing_time_ms(start) <= 200) {
  1145. if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
  1146. break;
  1147. DBG_871X(FUNC_NDEV_FMT"fw_state=_FW_UNDER_SURVEY!\n", FUNC_NDEV_ARG(adapter->pnetdev));
  1148. rtw_msleep_os(20);
  1149. }
  1150. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
  1151. if (!adapter->bDriverStopped && !adapter->bSurpriseRemoved)
  1152. DBG_871X(FUNC_NDEV_FMT"waiting for scan_abort time out!\n", FUNC_NDEV_ARG(adapter->pnetdev));
  1153. #ifdef CONFIG_PLATFORM_MSTAR_TITANIA12
  1154. //_clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
  1155. set_survey_timer(pmlmeext, 0);
  1156. _set_timer(&pmlmepriv->scan_to_timer, 50);
  1157. #endif
  1158. rtw_indicate_scan_done(adapter, _TRUE);
  1159. }
  1160. pmlmeext->scan_abort = _FALSE;
  1161. }
  1162. static struct sta_info *rtw_joinbss_update_stainfo(_adapter *padapter, struct wlan_network *pnetwork)
  1163. {
  1164. int i;
  1165. struct sta_info *bmc_sta, *psta=NULL;
  1166. struct recv_reorder_ctrl *preorder_ctrl;
  1167. struct sta_priv *pstapriv = &padapter->stapriv;
  1168. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1169. psta = rtw_get_stainfo(pstapriv, pnetwork->network.MacAddress);
  1170. if(psta==NULL) {
  1171. psta = rtw_alloc_stainfo(pstapriv, pnetwork->network.MacAddress);
  1172. }
  1173. if(psta) //update ptarget_sta
  1174. {
  1175. DBG_871X("%s\n", __FUNCTION__);
  1176. psta->aid = pnetwork->join_res;
  1177. #if 0 //alloc macid when call rtw_alloc_stainfo(), and release macid when call rtw_free_stainfo()
  1178. #ifdef CONFIG_CONCURRENT_MODE
  1179. if(PRIMARY_ADAPTER == padapter->adapter_type)
  1180. psta->mac_id=0;
  1181. else
  1182. psta->mac_id=2;
  1183. #else
  1184. psta->mac_id=0;
  1185. #endif
  1186. #endif //removed
  1187. //psta->raid = networktype_to_raid(pmlmeext->cur_wireless_mode);
  1188. psta->raid = rtw_hal_networktype_to_raid(padapter,pmlmeext->cur_wireless_mode);
  1189. //sta mode
  1190. rtw_hal_set_odm_var(padapter,HAL_ODM_STA_INFO,psta,_TRUE);
  1191. //security related
  1192. if(padapter->securitypriv.dot11AuthAlgrthm== dot11AuthAlgrthm_8021X)
  1193. {
  1194. padapter->securitypriv.binstallGrpkey=_FALSE;
  1195. padapter->securitypriv.busetkipkey=_FALSE;
  1196. padapter->securitypriv.bgrpkey_handshake=_FALSE;
  1197. psta->ieee8021x_blocked=_TRUE;
  1198. psta->dot118021XPrivacy=padapter->securitypriv.dot11PrivacyAlgrthm;
  1199. _rtw_memset((u8 *)&psta->dot118021x_UncstKey, 0, sizeof (union Keytype));
  1200. _rtw_memset((u8 *)&psta->dot11tkiprxmickey, 0, sizeof (union Keytype));
  1201. _rtw_memset((u8 *)&psta->dot11tkiptxmickey, 0, sizeof (union Keytype));
  1202. _rtw_memset((u8 *)&psta->dot11txpn, 0, sizeof (union pn48));
  1203. _rtw_memset((u8 *)&psta->dot11rxpn, 0, sizeof (union pn48));
  1204. }
  1205. // Commented by Albert 2012/07/21
  1206. // When doing the WPS, the wps_ie_len won't equal to 0
  1207. // And the Wi-Fi driver shouldn't allow the data packet to be tramsmitted.
  1208. if ( padapter->securitypriv.wps_ie_len != 0 )
  1209. {
  1210. psta->ieee8021x_blocked=_TRUE;
  1211. padapter->securitypriv.wps_ie_len = 0;
  1212. }
  1213. //for A-MPDU Rx reordering buffer control for bmc_sta & sta_info
  1214. //if A-MPDU Rx is enabled, reseting rx_ordering_ctrl wstart_b(indicate_seq) to default value=0xffff
  1215. //todo: check if AP can send A-MPDU packets
  1216. for(i=0; i < 16 ; i++)
  1217. {
  1218. //preorder_ctrl = &precvpriv->recvreorder_ctrl[i];
  1219. preorder_ctrl = &psta->recvreorder_ctrl[i];
  1220. preorder_ctrl->enable = _FALSE;
  1221. preorder_ctrl->indicate_seq = 0xffff;
  1222. #ifdef DBG_RX_SEQ
  1223. DBG_871X("DBG_RX_SEQ %s:%d indicate_seq:%u \n", __FUNCTION__, __LINE__,
  1224. preorder_ctrl->indicate_seq);
  1225. #endif
  1226. preorder_ctrl->wend_b= 0xffff;
  1227. preorder_ctrl->wsize_b = 64;//max_ampdu_sz;//ex. 32(kbytes) -> wsize_b=32
  1228. }
  1229. bmc_sta = rtw_get_bcmc_stainfo(padapter);
  1230. if(bmc_sta)
  1231. {
  1232. for(i=0; i < 16 ; i++)
  1233. {
  1234. //preorder_ctrl = &precvpriv->recvreorder_ctrl[i];
  1235. preorder_ctrl = &bmc_sta->recvreorder_ctrl[i];
  1236. preorder_ctrl->enable = _FALSE;
  1237. preorder_ctrl->indicate_seq = 0xffff;
  1238. #ifdef DBG_RX_SEQ
  1239. DBG_871X("DBG_RX_SEQ %s:%d indicate_seq:%u \n", __FUNCTION__, __LINE__,
  1240. preorder_ctrl->indicate_seq);
  1241. #endif
  1242. preorder_ctrl->wend_b= 0xffff;
  1243. preorder_ctrl->wsize_b = 64;//max_ampdu_sz;//ex. 32(kbytes) -> wsize_b=32
  1244. }
  1245. }
  1246. //misc.
  1247. update_sta_info(padapter, psta);
  1248. }
  1249. return psta;
  1250. }
  1251. //pnetwork : returns from rtw_joinbss_event_callback
  1252. //ptarget_wlan: found from scanned_queue
  1253. static void rtw_joinbss_update_network(_adapter *padapter, struct wlan_network *ptarget_wlan, struct wlan_network *pnetwork)
  1254. {
  1255. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1256. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  1257. DBG_871X("%s\n", __FUNCTION__);
  1258. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("\nfw_state:%x, BSSID:"MAC_FMT"\n"
  1259. ,get_fwstate(pmlmepriv), MAC_ARG(pnetwork->network.MacAddress)));
  1260. // why not use ptarget_wlan??
  1261. _rtw_memcpy(&cur_network->network, &pnetwork->network, pnetwork->network.Length);
  1262. // some IEs in pnetwork is wrong, so we should use ptarget_wlan IEs
  1263. cur_network->network.IELength = ptarget_wlan->network.IELength;
  1264. _rtw_memcpy(&cur_network->network.IEs[0], &ptarget_wlan->network.IEs[0], MAX_IE_SZ);
  1265. cur_network->aid = pnetwork->join_res;
  1266. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  1267. rtw_set_signal_stat_timer(&padapter->recvpriv);
  1268. #endif
  1269. padapter->recvpriv.signal_strength = ptarget_wlan->network.PhyInfo.SignalStrength;
  1270. padapter->recvpriv.signal_qual = ptarget_wlan->network.PhyInfo.SignalQuality;
  1271. //the ptarget_wlan->network.Rssi is raw data, we use ptarget_wlan->network.PhyInfo.SignalStrength instead (has scaled)
  1272. padapter->recvpriv.rssi = translate_percentage_to_dbm(ptarget_wlan->network.PhyInfo.SignalStrength);
  1273. #if defined(DBG_RX_SIGNAL_DISPLAY_PROCESSING) && 1
  1274. DBG_871X("%s signal_strength:%3u, rssi:%3d, signal_qual:%3u"
  1275. "\n"
  1276. , __FUNCTION__
  1277. , padapter->recvpriv.signal_strength
  1278. , padapter->recvpriv.rssi
  1279. , padapter->recvpriv.signal_qual
  1280. );
  1281. #endif
  1282. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  1283. rtw_set_signal_stat_timer(&padapter->recvpriv);
  1284. #endif
  1285. //update fw_state //will clr _FW_UNDER_LINKING here indirectly
  1286. switch(pnetwork->network.InfrastructureMode)
  1287. {
  1288. case Ndis802_11Infrastructure:
  1289. if(pmlmepriv->fw_state&WIFI_UNDER_WPS)
  1290. pmlmepriv->fw_state = WIFI_STATION_STATE|WIFI_UNDER_WPS;
  1291. else
  1292. pmlmepriv->fw_state = WIFI_STATION_STATE;
  1293. break;
  1294. case Ndis802_11IBSS:
  1295. pmlmepriv->fw_state = WIFI_ADHOC_STATE;
  1296. break;
  1297. default:
  1298. pmlmepriv->fw_state = WIFI_NULL_STATE;
  1299. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("Invalid network_mode\n"));
  1300. break;
  1301. }
  1302. rtw_update_protection(padapter, (cur_network->network.IEs) + sizeof (NDIS_802_11_FIXED_IEs),
  1303. (cur_network->network.IELength));
  1304. #ifdef CONFIG_80211N_HT
  1305. rtw_update_ht_cap(padapter, cur_network->network.IEs, cur_network->network.IELength, (u8) cur_network->network.Configuration.DSConfig);
  1306. #endif
  1307. }
  1308. //Notes: the fucntion could be > passive_level (the same context as Rx tasklet)
  1309. //pnetwork : returns from rtw_joinbss_event_callback
  1310. //ptarget_wlan: found from scanned_queue
  1311. //if join_res > 0, for (fw_state==WIFI_STATION_STATE), we check if "ptarget_sta" & "ptarget_wlan" exist.
  1312. //if join_res > 0, for (fw_state==WIFI_ADHOC_STATE), we only check if "ptarget_wlan" exist.
  1313. //if join_res > 0, update "cur_network->network" from "pnetwork->network" if (ptarget_wlan !=NULL).
  1314. //
  1315. //#define REJOIN
  1316. void rtw_joinbss_event_prehandle(_adapter *adapter, u8 *pbuf)
  1317. {
  1318. _irqL irqL,irqL2;
  1319. static u8 retry=0;
  1320. u8 timer_cancelled;
  1321. struct sta_info *ptarget_sta= NULL, *pcur_sta = NULL;
  1322. struct sta_priv *pstapriv = &adapter->stapriv;
  1323. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  1324. struct wlan_network *pnetwork = (struct wlan_network *)pbuf;
  1325. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  1326. struct wlan_network *pcur_wlan = NULL, *ptarget_wlan = NULL;
  1327. unsigned int the_same_macaddr = _FALSE;
  1328. _func_enter_;
  1329. #ifdef CONFIG_RTL8712
  1330. //endian_convert
  1331. pnetwork->join_res = le32_to_cpu(pnetwork->join_res);
  1332. pnetwork->network_type = le32_to_cpu(pnetwork->network_type);
  1333. pnetwork->network.Length = le32_to_cpu(pnetwork->network.Length);
  1334. pnetwork->network.Ssid.SsidLength = le32_to_cpu(pnetwork->network.Ssid.SsidLength);
  1335. pnetwork->network.Privacy =le32_to_cpu( pnetwork->network.Privacy);
  1336. pnetwork->network.Rssi = le32_to_cpu(pnetwork->network.Rssi);
  1337. pnetwork->network.NetworkTypeInUse =le32_to_cpu(pnetwork->network.NetworkTypeInUse) ;
  1338. pnetwork->network.Configuration.ATIMWindow = le32_to_cpu(pnetwork->network.Configuration.ATIMWindow);
  1339. pnetwork->network.Configuration.BeaconPeriod = le32_to_cpu(pnetwork->network.Configuration.BeaconPeriod);
  1340. pnetwork->network.Configuration.DSConfig = le32_to_cpu(pnetwork->network.Configuration.DSConfig);
  1341. pnetwork->network.Configuration.FHConfig.DwellTime=le32_to_cpu(pnetwork->network.Configuration.FHConfig.DwellTime);
  1342. pnetwork->network.Configuration.FHConfig.HopPattern=le32_to_cpu(pnetwork->network.Configuration.FHConfig.HopPattern);
  1343. pnetwork->network.Configuration.FHConfig.HopSet=le32_to_cpu(pnetwork->network.Configuration.FHConfig.HopSet);
  1344. pnetwork->network.Configuration.FHConfig.Length=le32_to_cpu(pnetwork->network.Configuration.FHConfig.Length);
  1345. pnetwork->network.Configuration.Length = le32_to_cpu(pnetwork->network.Configuration.Length);
  1346. pnetwork->network.InfrastructureMode = le32_to_cpu(pnetwork->network.InfrastructureMode);
  1347. pnetwork->network.IELength = le32_to_cpu(pnetwork->network.IELength );
  1348. #endif
  1349. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("joinbss event call back received with res=%d\n", pnetwork->join_res));
  1350. rtw_get_encrypt_decrypt_from_registrypriv(adapter);
  1351. if (pmlmepriv->assoc_ssid.SsidLength == 0)
  1352. {
  1353. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("@@@@@ joinbss event call back for Any SSid\n"));
  1354. }
  1355. else
  1356. {
  1357. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("@@@@@ rtw_joinbss_event_callback for SSid:%s\n", pmlmepriv->assoc_ssid.Ssid));
  1358. }
  1359. the_same_macaddr = _rtw_memcmp(pnetwork->network.MacAddress, cur_network->network.MacAddress, ETH_ALEN);
  1360. pnetwork->network.Length = get_WLAN_BSSID_EX_sz(&pnetwork->network);
  1361. if(pnetwork->network.Length > sizeof(WLAN_BSSID_EX))
  1362. {
  1363. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("\n\n ***joinbss_evt_callback return a wrong bss ***\n\n"));
  1364. goto ignore_joinbss_callback;
  1365. }
  1366. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  1367. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("\n rtw_joinbss_event_callback !! _enter_critical \n"));
  1368. if(pnetwork->join_res > 0)
  1369. {
  1370. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1371. retry = 0;
  1372. if (check_fwstate(pmlmepriv,_FW_UNDER_LINKING) )
  1373. {
  1374. //s1. find ptarget_wlan
  1375. if(check_fwstate(pmlmepriv, _FW_LINKED) )
  1376. {
  1377. if(the_same_macaddr == _TRUE)
  1378. {
  1379. ptarget_wlan = rtw_find_network(&pmlmepriv->scanned_queue, cur_network->network.MacAddress);
  1380. }
  1381. else
  1382. {
  1383. pcur_wlan = rtw_find_network(&pmlmepriv->scanned_queue, cur_network->network.MacAddress);
  1384. if(pcur_wlan) pcur_wlan->fixed = _FALSE;
  1385. pcur_sta = rtw_get_stainfo(pstapriv, cur_network->network.MacAddress);
  1386. if(pcur_sta){
  1387. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
  1388. rtw_free_stainfo(adapter, pcur_sta);
  1389. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
  1390. }
  1391. ptarget_wlan = rtw_find_network(&pmlmepriv->scanned_queue, pnetwork->network.MacAddress);
  1392. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE){
  1393. if(ptarget_wlan) ptarget_wlan->fixed = _TRUE;
  1394. }
  1395. }
  1396. }
  1397. else
  1398. {
  1399. ptarget_wlan = rtw_find_network(&pmlmepriv->scanned_queue, pnetwork->network.MacAddress);
  1400. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE){
  1401. if(ptarget_wlan) ptarget_wlan->fixed = _TRUE;
  1402. }
  1403. }
  1404. //s2. update cur_network
  1405. if(ptarget_wlan)
  1406. {
  1407. rtw_joinbss_update_network(adapter, ptarget_wlan, pnetwork);
  1408. }
  1409. else
  1410. {
  1411. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("Can't find ptarget_wlan when joinbss_event callback\n"));
  1412. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1413. goto ignore_joinbss_callback;
  1414. }
  1415. //s3. find ptarget_sta & update ptarget_sta after update cur_network only for station mode
  1416. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
  1417. {
  1418. ptarget_sta = rtw_joinbss_update_stainfo(adapter, pnetwork);
  1419. if(ptarget_sta==NULL)
  1420. {
  1421. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("Can't update stainfo when joinbss_event callback\n"));
  1422. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1423. goto ignore_joinbss_callback;
  1424. }
  1425. }
  1426. //s4. indicate connect
  1427. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
  1428. {
  1429. rtw_indicate_connect(adapter);
  1430. }
  1431. else
  1432. {
  1433. //adhoc mode will rtw_indicate_connect when rtw_stassoc_event_callback
  1434. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("adhoc mode, fw_state:%x", get_fwstate(pmlmepriv)));
  1435. }
  1436. //s5. Cancle assoc_timer
  1437. _cancel_timer(&pmlmepriv->assoc_timer, &timer_cancelled);
  1438. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("Cancle assoc_timer \n"));
  1439. }
  1440. else
  1441. {
  1442. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("rtw_joinbss_event_callback err: fw_state:%x", get_fwstate(pmlmepriv)));
  1443. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1444. goto ignore_joinbss_callback;
  1445. }
  1446. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1447. }
  1448. else if(pnetwork->join_res == -4)
  1449. {
  1450. rtw_reset_securitypriv(adapter);
  1451. _set_timer(&pmlmepriv->assoc_timer, 1);
  1452. //rtw_free_assoc_resources(adapter, 1);
  1453. if((check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) == _TRUE)
  1454. {
  1455. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("fail! clear _FW_UNDER_LINKING ^^^fw_state=%x\n", get_fwstate(pmlmepriv)));
  1456. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  1457. }
  1458. }
  1459. else //if join_res < 0 (join fails), then try again
  1460. {
  1461. #ifdef REJOIN
  1462. res = _FAIL;
  1463. if(retry < 2) {
  1464. res = rtw_select_and_join_from_scanned_queue(pmlmepriv);
  1465. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("rtw_select_and_join_from_scanned_queue again! res:%d\n",res));
  1466. }
  1467. if(res == _SUCCESS)
  1468. {
  1469. //extend time of assoc_timer
  1470. _set_timer(&pmlmepriv->assoc_timer, MAX_JOIN_TIMEOUT);
  1471. retry++;
  1472. }
  1473. else if(res == 2)//there is no need to wait for join
  1474. {
  1475. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  1476. rtw_indicate_connect(adapter);
  1477. }
  1478. else
  1479. {
  1480. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("Set Assoc_Timer = 1; can't find match ssid in scanned_q \n"));
  1481. #endif
  1482. _set_timer(&pmlmepriv->assoc_timer, 1);
  1483. //rtw_free_assoc_resources(adapter, 1);
  1484. _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  1485. #ifdef REJOIN
  1486. retry = 0;
  1487. }
  1488. #endif
  1489. }
  1490. ignore_joinbss_callback:
  1491. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  1492. _func_exit_;
  1493. }
  1494. void rtw_joinbss_event_callback(_adapter *adapter, u8 *pbuf)
  1495. {
  1496. struct wlan_network *pnetwork = (struct wlan_network *)pbuf;
  1497. _func_enter_;
  1498. mlmeext_joinbss_event_callback(adapter, pnetwork->join_res);
  1499. rtw_os_xmit_schedule(adapter);
  1500. #ifdef CONFIG_CONCURRENT_MODE
  1501. rtw_os_xmit_schedule(adapter->pbuddy_adapter);
  1502. #endif
  1503. #ifdef CONFIG_DUALMAC_CONCURRENT
  1504. dc_resume_xmit(adapter);
  1505. #endif
  1506. _func_exit_;
  1507. }
  1508. u8 search_max_mac_id(_adapter *padapter)
  1509. {
  1510. u8 mac_id, aid;
  1511. #if (RATE_ADAPTIVE_SUPPORT==1) //for 88E RA
  1512. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1513. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1514. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1515. struct sta_priv *pstapriv = &padapter->stapriv;
  1516. #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
  1517. if(check_fwstate(pmlmepriv, WIFI_AP_STATE)){
  1518. #if 1
  1519. _irqL irqL;
  1520. struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
  1521. _enter_critical_bh(&pdvobj->lock, &irqL);
  1522. for(mac_id=(NUM_STA-1); mac_id>0; mac_id--)
  1523. if(pdvobj->macid[mac_id] == _TRUE)
  1524. break;
  1525. _exit_critical_bh(&pdvobj->lock, &irqL);
  1526. #else
  1527. for (aid = (pstapriv->max_num_sta); aid > 0; aid--)
  1528. {
  1529. if (pstapriv->sta_aid[aid-1] != NULL)
  1530. {
  1531. psta = pstapriv->sta_aid[aid-1];
  1532. break;
  1533. }
  1534. }
  1535. /*
  1536. for (mac_id = (pstapriv->max_num_sta-1); mac_id >= 0; mac_id--)
  1537. {
  1538. if (pstapriv->sta_aid[mac_id] != NULL)
  1539. break;
  1540. }
  1541. */
  1542. mac_id = aid + 1;
  1543. #endif
  1544. }
  1545. else
  1546. #endif
  1547. {//adhoc id = 31~2
  1548. for (mac_id = (NUM_STA-1); mac_id >= IBSS_START_MAC_ID ; mac_id--)
  1549. {
  1550. if (pmlmeinfo->FW_sta_info[mac_id].status == 1)
  1551. {
  1552. break;
  1553. }
  1554. }
  1555. }
  1556. #endif
  1557. DBG_871X("max mac_id=%d\n", mac_id);
  1558. return mac_id;
  1559. }
  1560. //FOR AP ,AD-HOC mode
  1561. void rtw_stassoc_hw_rpt(_adapter *adapter,struct sta_info *psta)
  1562. {
  1563. u16 media_status;
  1564. if(psta==NULL) return;
  1565. #if (RATE_ADAPTIVE_SUPPORT==1) //for 88E RA
  1566. {
  1567. u8 macid = search_max_mac_id(adapter);
  1568. rtw_hal_set_hwreg(adapter,HW_VAR_TX_RPT_MAX_MACID, (u8*)&macid);
  1569. }
  1570. #endif
  1571. media_status = (psta->mac_id<<8)|1; // MACID|OPMODE:1 connect
  1572. rtw_hal_set_hwreg(adapter,HW_VAR_H2C_MEDIA_STATUS_RPT,(u8 *)&media_status);
  1573. }
  1574. void rtw_stassoc_event_callback(_adapter *adapter, u8 *pbuf)
  1575. {
  1576. _irqL irqL;
  1577. struct sta_info *psta;
  1578. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  1579. struct stassoc_event *pstassoc = (struct stassoc_event*)pbuf;
  1580. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  1581. struct wlan_network *ptarget_wlan = NULL;
  1582. _func_enter_;
  1583. if(rtw_access_ctrl(adapter, pstassoc->macaddr) == _FALSE)
  1584. return;
  1585. #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
  1586. if(check_fwstate(pmlmepriv, WIFI_AP_STATE))
  1587. {
  1588. psta = rtw_get_stainfo(&adapter->stapriv, pstassoc->macaddr);
  1589. if(psta)
  1590. {
  1591. #ifdef CONFIG_AUTO_AP_MODE
  1592. rtw_stassoc_hw_rpt(adapter, psta);
  1593. goto exit;
  1594. #else //CONFIG_AUTO_AP_MODE
  1595. #ifdef CONFIG_IOCTL_CFG80211
  1596. #ifdef COMPAT_KERNEL_RELEASE
  1597. #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37)) || defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  1598. u8 *passoc_req = NULL;
  1599. u32 assoc_req_len;
  1600. _enter_critical_bh(&psta->lock, &irqL);
  1601. if(psta->passoc_req && psta->assoc_req_len>0)
  1602. {
  1603. passoc_req = rtw_zmalloc(psta->assoc_req_len);
  1604. if(passoc_req)
  1605. {
  1606. assoc_req_len = psta->assoc_req_len;
  1607. _rtw_memcpy(passoc_req, psta->passoc_req, assoc_req_len);
  1608. _rtw_mfree(psta->passoc_req , psta->assoc_req_len);
  1609. psta->passoc_req = NULL;
  1610. psta->assoc_req_len = 0;
  1611. }
  1612. }
  1613. _exit_critical_bh(&psta->lock, &irqL);
  1614. if(passoc_req && assoc_req_len>0)
  1615. {
  1616. rtw_cfg80211_indicate_sta_assoc(adapter, passoc_req, assoc_req_len);
  1617. _rtw_mfree(passoc_req, assoc_req_len);
  1618. }
  1619. #endif //(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37)) || defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  1620. #endif //CONFIG_IOCTL_CFG80211
  1621. //bss_cap_update_on_sta_join(adapter, psta);
  1622. //sta_info_update(adapter, psta);
  1623. ap_sta_info_defer_update(adapter, psta);
  1624. rtw_stassoc_hw_rpt(adapter,psta);
  1625. #endif //CONFIG_AUTO_AP_MODE
  1626. }
  1627. goto exit;
  1628. }
  1629. #endif
  1630. //for AD-HOC mode
  1631. psta = rtw_get_stainfo(&adapter->stapriv, pstassoc->macaddr);
  1632. if( psta != NULL)
  1633. {
  1634. //the sta have been in sta_info_queue => do nothing
  1635. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("Error: rtw_stassoc_event_callback: sta has been in sta_hash_queue \n"));
  1636. goto exit; //(between drv has received this event before and fw have not yet to set key to CAM_ENTRY)
  1637. }
  1638. psta = rtw_alloc_stainfo(&adapter->stapriv, pstassoc->macaddr);
  1639. if (psta == NULL) {
  1640. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("Can't alloc sta_info when rtw_stassoc_event_callback\n"));
  1641. goto exit;
  1642. }
  1643. //to do : init sta_info variable
  1644. psta->qos_option = 0;
  1645. psta->mac_id = (uint)pstassoc->cam_id;
  1646. //psta->aid = (uint)pstassoc->cam_id;
  1647. DBG_871X("%s\n",__FUNCTION__);
  1648. //for ad-hoc mode
  1649. rtw_hal_set_odm_var(adapter,HAL_ODM_STA_INFO,psta,_TRUE);
  1650. rtw_stassoc_hw_rpt(adapter,psta);
  1651. if(adapter->securitypriv.dot11AuthAlgrthm==dot11AuthAlgrthm_8021X)
  1652. psta->dot118021XPrivacy = adapter->securitypriv.dot11PrivacyAlgrthm;
  1653. psta->ieee8021x_blocked = _FALSE;
  1654. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  1655. if ( (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)==_TRUE ) ||
  1656. (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)==_TRUE ) )
  1657. {
  1658. if(adapter->stapriv.asoc_sta_count== 2)
  1659. {
  1660. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1661. ptarget_wlan = rtw_find_network(&pmlmepriv->scanned_queue, cur_network->network.MacAddress);
  1662. if(ptarget_wlan) ptarget_wlan->fixed = _TRUE;
  1663. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1664. // a sta + bc/mc_stainfo (not Ibss_stainfo)
  1665. rtw_indicate_connect(adapter);
  1666. }
  1667. }
  1668. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  1669. mlmeext_sta_add_event_callback(adapter, psta);
  1670. #ifdef CONFIG_RTL8711
  1671. //submit SetStaKey_cmd to tell fw, fw will allocate an CAM entry for this sta
  1672. rtw_setstakey_cmd(adapter, (unsigned char*)psta, _FALSE);
  1673. #endif
  1674. exit:
  1675. _func_exit_;
  1676. }
  1677. void rtw_stadel_event_callback(_adapter *adapter, u8 *pbuf)
  1678. {
  1679. _irqL irqL,irqL2;
  1680. int mac_id = (-1);
  1681. struct sta_info *psta;
  1682. struct wlan_network* pwlan = NULL;
  1683. WLAN_BSSID_EX *pdev_network=NULL;
  1684. u8* pibss = NULL;
  1685. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  1686. struct stadel_event *pstadel = (struct stadel_event*)pbuf;
  1687. struct sta_priv *pstapriv = &adapter->stapriv;
  1688. struct wlan_network *tgt_network = &(pmlmepriv->cur_network);
  1689. _func_enter_;
  1690. psta = rtw_get_stainfo(&adapter->stapriv, pstadel->macaddr);
  1691. if(psta)
  1692. mac_id = psta->mac_id;
  1693. else
  1694. mac_id = pstadel->mac_id;
  1695. DBG_871X("%s(mac_id=%d)=" MAC_FMT "\n", __func__, mac_id, MAC_ARG(pstadel->macaddr));
  1696. if(mac_id>=0){
  1697. u16 media_status;
  1698. media_status = (mac_id<<8)|0; // MACID|OPMODE:0 means disconnect
  1699. //for STA,AP,ADHOC mode, report disconnect stauts to FW
  1700. rtw_hal_set_hwreg(adapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status);
  1701. }
  1702. if(check_fwstate(pmlmepriv, WIFI_AP_STATE))
  1703. {
  1704. #ifdef CONFIG_IOCTL_CFG80211
  1705. #ifdef COMPAT_KERNEL_RELEASE
  1706. #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37)) || defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  1707. rtw_cfg80211_indicate_sta_disassoc(adapter, pstadel->macaddr, *(u16*)pstadel->rsvd);
  1708. #endif //(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37)) || defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  1709. #endif //CONFIG_IOCTL_CFG80211
  1710. return;
  1711. }
  1712. mlmeext_sta_del_event_callback(adapter);
  1713. _enter_critical_bh(&pmlmepriv->lock, &irqL2);
  1714. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) )
  1715. {
  1716. #ifdef CONFIG_LAYER2_ROAMING
  1717. if (rtw_to_roaming(adapter) > 0)
  1718. pmlmepriv->to_roaming--; /* this stadel_event is caused by roaming, decrease to_roaming */
  1719. else if (rtw_to_roaming(adapter) == 0)
  1720. rtw_set_roaming(adapter, adapter->registrypriv.max_roaming_times);
  1721. #ifdef CONFIG_INTEL_WIDI
  1722. if(adapter->mlmepriv.widi_state != INTEL_WIDI_STATE_CONNECTED)
  1723. #endif // CONFIG_INTEL_WIDI
  1724. if(*((unsigned short *)(pstadel->rsvd)) != WLAN_REASON_EXPIRATION_CHK)
  1725. rtw_set_roaming(adapter, 0); /* don't roam */
  1726. #endif
  1727. rtw_free_uc_swdec_pending_queue(adapter);
  1728. rtw_free_assoc_resources(adapter, 1);
  1729. rtw_indicate_disconnect(adapter);
  1730. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1731. // remove the network entry in scanned_queue
  1732. pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.MacAddress);
  1733. if (pwlan) {
  1734. pwlan->fixed = _FALSE;
  1735. rtw_free_network_nolock(pmlmepriv, pwlan);
  1736. }
  1737. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1738. #ifdef CONFIG_LAYER2_ROAMING
  1739. _rtw_roaming(adapter, tgt_network);
  1740. #else
  1741. #ifdef CONFIG_INTEL_WIDI
  1742. process_intel_widi_disconnect(adapter, 1);
  1743. #endif // CONFIG_INTEL_WIDI
  1744. #endif //CONFIG_LAYER2_ROAMING
  1745. }
  1746. if ( check_fwstate(pmlmepriv,WIFI_ADHOC_MASTER_STATE) ||
  1747. check_fwstate(pmlmepriv,WIFI_ADHOC_STATE))
  1748. {
  1749. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  1750. rtw_free_stainfo(adapter, psta);
  1751. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  1752. if(adapter->stapriv.asoc_sta_count== 1) //a sta + bc/mc_stainfo (not Ibss_stainfo)
  1753. {
  1754. //rtw_indicate_disconnect(adapter);//removed@20091105
  1755. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1756. //free old ibss network
  1757. //pwlan = rtw_find_network(&pmlmepriv->scanned_queue, pstadel->macaddr);
  1758. pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.MacAddress);
  1759. if(pwlan)
  1760. {
  1761. pwlan->fixed = _FALSE;
  1762. rtw_free_network_nolock(pmlmepriv, pwlan);
  1763. }
  1764. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1765. //re-create ibss
  1766. pdev_network = &(adapter->registrypriv.dev_network);
  1767. pibss = adapter->registrypriv.dev_network.MacAddress;
  1768. _rtw_memcpy(pdev_network, &tgt_network->network, get_WLAN_BSSID_EX_sz(&tgt_network->network));
  1769. _rtw_memset(&pdev_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
  1770. _rtw_memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(NDIS_802_11_SSID));
  1771. rtw_update_registrypriv_dev_network(adapter);
  1772. rtw_generate_random_ibss(pibss);
  1773. if(check_fwstate(pmlmepriv,WIFI_ADHOC_STATE))
  1774. {
  1775. set_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  1776. _clr_fwstate_(pmlmepriv, WIFI_ADHOC_STATE);
  1777. }
  1778. if(rtw_createbss_cmd(adapter)!=_SUCCESS)
  1779. {
  1780. RT_TRACE(_module_rtl871x_ioctl_set_c_,_drv_err_,("***Error=>stadel_event_callback: rtw_createbss_cmd status FAIL*** \n "));
  1781. }
  1782. }
  1783. }
  1784. _exit_critical_bh(&pmlmepriv->lock, &irqL2);
  1785. _func_exit_;
  1786. }
  1787. void rtw_cpwm_event_callback(PADAPTER padapter, u8 *pbuf)
  1788. {
  1789. #ifdef CONFIG_LPS_LCLK
  1790. struct reportpwrstate_parm *preportpwrstate;
  1791. #endif
  1792. _func_enter_;
  1793. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("+rtw_cpwm_event_callback !!!\n"));
  1794. #ifdef CONFIG_LPS_LCLK
  1795. preportpwrstate = (struct reportpwrstate_parm*)pbuf;
  1796. preportpwrstate->state |= (u8)(padapter->pwrctrlpriv.cpwm_tog + 0x80);
  1797. cpwm_int_hdl(padapter, preportpwrstate);
  1798. #endif
  1799. _func_exit_;
  1800. }
  1801. /*
  1802. * _rtw_join_timeout_handler - Timeout/faliure handler for CMD JoinBss
  1803. * @adapter: pointer to _adapter structure
  1804. */
  1805. void _rtw_join_timeout_handler (_adapter *adapter)
  1806. {
  1807. _irqL irqL;
  1808. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  1809. #ifdef CONFIG_LAYER2_ROAMING
  1810. int do_join_r;
  1811. #endif //CONFIG_LAYER2_ROAMING
  1812. #if 0
  1813. if (adapter->bDriverStopped == _TRUE){
  1814. _rtw_up_sema(&pmlmepriv->assoc_terminate);
  1815. return;
  1816. }
  1817. #endif
  1818. _func_enter_;
  1819. DBG_871X("%s, fw_state=%x\n", __FUNCTION__, get_fwstate(pmlmepriv));
  1820. if(adapter->bDriverStopped ||adapter->bSurpriseRemoved)
  1821. return;
  1822. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  1823. #ifdef CONFIG_LAYER2_ROAMING
  1824. if (rtw_to_roaming(adapter) > 0) { /* join timeout caused by roaming */
  1825. while(1) {
  1826. pmlmepriv->to_roaming--;
  1827. if (rtw_to_roaming(adapter) != 0) { /* try another */
  1828. DBG_871X("%s try another roaming\n", __FUNCTION__);
  1829. if( _SUCCESS!=(do_join_r=rtw_do_join(adapter)) ) {
  1830. DBG_871X("%s roaming do_join return %d\n", __FUNCTION__ ,do_join_r);
  1831. continue;
  1832. }
  1833. break;
  1834. } else {
  1835. #ifdef CONFIG_INTEL_WIDI
  1836. if(adapter->mlmepriv.widi_state == INTEL_WIDI_STATE_ROAMING)
  1837. {
  1838. _rtw_memset(pmlmepriv->sa_ext, 0x00, L2SDTA_SERVICE_VE_LEN);
  1839. intel_widi_wk_cmd(adapter, INTEL_WIDI_LISTEN_WK, NULL);
  1840. DBG_871X("change to widi listen\n");
  1841. }
  1842. #endif // CONFIG_INTEL_WIDI
  1843. DBG_871X("%s We've try roaming but fail\n", __FUNCTION__);
  1844. rtw_indicate_disconnect(adapter);
  1845. break;
  1846. }
  1847. }
  1848. } else
  1849. #endif
  1850. {
  1851. rtw_indicate_disconnect(adapter);
  1852. free_scanqueue(pmlmepriv);//???
  1853. #ifdef CONFIG_IOCTL_CFG80211
  1854. //indicate disconnect for the case that join_timeout and check_fwstate != FW_LINKED
  1855. rtw_cfg80211_indicate_disconnect(adapter);
  1856. #endif //CONFIG_IOCTL_CFG80211
  1857. }
  1858. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  1859. #ifdef CONFIG_DRVEXT_MODULE_WSC
  1860. drvext_assoc_fail_indicate(&adapter->drvextpriv);
  1861. #endif
  1862. _func_exit_;
  1863. }
  1864. /*
  1865. * rtw_scan_timeout_handler - Timeout/Faliure handler for CMD SiteSurvey
  1866. * @adapter: pointer to _adapter structure
  1867. */
  1868. void rtw_scan_timeout_handler (_adapter *adapter)
  1869. {
  1870. _irqL irqL;
  1871. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  1872. DBG_871X(FUNC_ADPT_FMT" fw_state=%x\n", FUNC_ADPT_ARG(adapter), get_fwstate(pmlmepriv));
  1873. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  1874. _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
  1875. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  1876. rtw_indicate_scan_done(adapter, _TRUE);
  1877. }
  1878. static void rtw_auto_scan_handler(_adapter *padapter)
  1879. {
  1880. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1881. struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
  1882. //auto site survey per 60sec
  1883. if(pmlmepriv->scan_interval >0)
  1884. {
  1885. pmlmepriv->scan_interval--;
  1886. if(pmlmepriv->scan_interval==0)
  1887. {
  1888. /*
  1889. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == _TRUE)
  1890. {
  1891. DBG_871X("exit %s when _FW_UNDER_SURVEY|_FW_UNDER_LINKING -> \n", __FUNCTION__);
  1892. return;
  1893. }
  1894. if(pmlmepriv->sitesurveyctrl.traffic_busy == _TRUE)
  1895. {
  1896. DBG_871X("%s exit cause traffic_busy(%x)\n",__FUNCTION__, pmlmepriv->sitesurveyctrl.traffic_busy);
  1897. return;
  1898. }
  1899. */
  1900. #ifdef CONFIG_CONCURRENT_MODE
  1901. if (rtw_buddy_adapter_up(padapter))
  1902. {
  1903. if ((check_buddy_fwstate(padapter, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == _TRUE) ||
  1904. (padapter->pbuddy_adapter->mlmepriv.LinkDetectInfo.bBusyTraffic == _TRUE))
  1905. {
  1906. DBG_871X("%s, but buddy_intf is under scanning or linking or BusyTraffic\n", __FUNCTION__);
  1907. return;
  1908. }
  1909. }
  1910. #endif
  1911. DBG_871X("%s\n", __FUNCTION__);
  1912. rtw_set_802_11_bssid_list_scan(padapter, NULL, 0);
  1913. pmlmepriv->scan_interval = SCAN_INTERVAL;// 30*2 sec = 60sec
  1914. }
  1915. }
  1916. }
  1917. void rtw_dynamic_check_timer_handlder(_adapter *adapter)
  1918. {
  1919. #ifdef CONFIG_AP_MODE
  1920. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  1921. #endif //CONFIG_AP_MODE
  1922. struct registry_priv *pregistrypriv = &adapter->registrypriv;
  1923. #ifdef CONFIG_CONCURRENT_MODE
  1924. PADAPTER pbuddy_adapter = adapter->pbuddy_adapter;
  1925. #endif
  1926. if(!adapter)
  1927. return;
  1928. if(adapter->hw_init_completed == _FALSE)
  1929. return;
  1930. if ((adapter->bDriverStopped == _TRUE)||(adapter->bSurpriseRemoved== _TRUE))
  1931. return;
  1932. #ifdef CONFIG_CONCURRENT_MODE
  1933. if(pbuddy_adapter)
  1934. {
  1935. if(adapter->net_closed == _TRUE && pbuddy_adapter->net_closed == _TRUE)
  1936. {
  1937. return;
  1938. }
  1939. }
  1940. else
  1941. #endif //CONFIG_CONCURRENT_MODE
  1942. if(adapter->net_closed == _TRUE)
  1943. {
  1944. return;
  1945. }
  1946. rtw_dynamic_chk_wk_cmd(adapter);
  1947. if(pregistrypriv->wifi_spec==1)
  1948. {
  1949. #ifdef CONFIG_P2P
  1950. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  1951. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  1952. #endif
  1953. {
  1954. //auto site survey
  1955. rtw_auto_scan_handler(adapter);
  1956. }
  1957. }
  1958. #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  1959. #ifdef CONFIG_AP_MODE
  1960. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1961. {
  1962. expire_timeout_chk(adapter);
  1963. }
  1964. #endif
  1965. #endif //!CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  1966. #ifdef CONFIG_BR_EXT
  1967. #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
  1968. rcu_read_lock();
  1969. #endif // (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
  1970. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  1971. if( adapter->pnetdev->br_port
  1972. #else // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  1973. if( rcu_dereference(adapter->pnetdev->rx_handler_data)
  1974. #endif // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  1975. && (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) == _TRUE) )
  1976. {
  1977. // expire NAT2.5 entry
  1978. void nat25_db_expire(_adapter *priv);
  1979. nat25_db_expire(adapter);
  1980. if (adapter->pppoe_connection_in_progress > 0) {
  1981. adapter->pppoe_connection_in_progress--;
  1982. }
  1983. // due to rtw_dynamic_check_timer_handlder() is called every 2 seconds
  1984. if (adapter->pppoe_connection_in_progress > 0) {
  1985. adapter->pppoe_connection_in_progress--;
  1986. }
  1987. }
  1988. #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
  1989. rcu_read_unlock();
  1990. #endif // (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
  1991. #endif // CONFIG_BR_EXT
  1992. }
  1993. #ifdef CONFIG_SET_SCAN_DENY_TIMER
  1994. inline bool rtw_is_scan_deny(_adapter *adapter)
  1995. {
  1996. struct mlme_priv *mlmepriv = &adapter->mlmepriv;
  1997. return (ATOMIC_READ(&mlmepriv->set_scan_deny) != 0) ? _TRUE : _FALSE;
  1998. }
  1999. inline void rtw_clear_scan_deny(_adapter *adapter)
  2000. {
  2001. struct mlme_priv *mlmepriv = &adapter->mlmepriv;
  2002. ATOMIC_SET(&mlmepriv->set_scan_deny, 0);
  2003. if (0)
  2004. DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter));
  2005. }
  2006. void rtw_set_scan_deny_timer_hdl(_adapter *adapter)
  2007. {
  2008. rtw_clear_scan_deny(adapter);
  2009. }
  2010. void rtw_set_scan_deny(_adapter *adapter, u32 ms)
  2011. {
  2012. struct mlme_priv *mlmepriv = &adapter->mlmepriv;
  2013. #ifdef CONFIG_CONCURRENT_MODE
  2014. struct mlme_priv *b_mlmepriv;
  2015. #endif
  2016. if (0)
  2017. DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter));
  2018. ATOMIC_SET(&mlmepriv->set_scan_deny, 1);
  2019. _set_timer(&mlmepriv->set_scan_deny_timer, ms);
  2020. #ifdef CONFIG_CONCURRENT_MODE
  2021. if (!adapter->pbuddy_adapter)
  2022. return;
  2023. if (0)
  2024. DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter->pbuddy_adapter));
  2025. b_mlmepriv = &adapter->pbuddy_adapter->mlmepriv;
  2026. ATOMIC_SET(&b_mlmepriv->set_scan_deny, 1);
  2027. _set_timer(&b_mlmepriv->set_scan_deny_timer, ms);
  2028. #endif
  2029. }
  2030. #endif
  2031. #if defined(IEEE80211_SCAN_RESULT_EXPIRE)
  2032. #define RTW_SCAN_RESULT_EXPIRE IEEE80211_SCAN_RESULT_EXPIRE/HZ*1000 -1000 //3000 -1000
  2033. #else
  2034. #define RTW_SCAN_RESULT_EXPIRE 2000
  2035. #endif
  2036. #ifndef PLATFORM_FREEBSD
  2037. /*
  2038. * Select a new join candidate from the original @param candidate and @param competitor
  2039. * @return _TRUE: candidate is updated
  2040. * @return _FALSE: candidate is not updated
  2041. */
  2042. static int rtw_check_join_candidate(struct mlme_priv *pmlmepriv
  2043. , struct wlan_network **candidate, struct wlan_network *competitor)
  2044. {
  2045. int updated = _FALSE;
  2046. _adapter *adapter = container_of(pmlmepriv, _adapter, mlmepriv);
  2047. //check bssid, if needed
  2048. if(pmlmepriv->assoc_by_bssid==_TRUE) {
  2049. if(_rtw_memcmp(competitor->network.MacAddress, pmlmepriv->assoc_bssid, ETH_ALEN) ==_FALSE)
  2050. goto exit;
  2051. }
  2052. //check ssid, if needed
  2053. if(pmlmepriv->assoc_ssid.Ssid && pmlmepriv->assoc_ssid.SsidLength) {
  2054. if( competitor->network.Ssid.SsidLength != pmlmepriv->assoc_ssid.SsidLength
  2055. || _rtw_memcmp(competitor->network.Ssid.Ssid, pmlmepriv->assoc_ssid.Ssid, pmlmepriv->assoc_ssid.SsidLength) == _FALSE
  2056. )
  2057. goto exit;
  2058. }
  2059. if(rtw_is_desired_network(adapter, competitor) == _FALSE)
  2060. goto exit;
  2061. #ifdef CONFIG_LAYER2_ROAMING
  2062. if(rtw_to_roaming(adapter) > 0) {
  2063. if( rtw_get_passing_time_ms((u32)competitor->last_scanned) >= RTW_SCAN_RESULT_EXPIRE
  2064. || is_same_ess(&competitor->network, &pmlmepriv->cur_network.network) == _FALSE
  2065. )
  2066. goto exit;
  2067. }
  2068. #endif
  2069. if(*candidate == NULL ||(*candidate)->network.Rssi<competitor->network.Rssi )
  2070. {
  2071. *candidate = competitor;
  2072. updated = _TRUE;
  2073. }
  2074. #if 0
  2075. if(pmlmepriv->assoc_by_bssid==_TRUE) { // associate with bssid
  2076. if( (*candidate == NULL ||(*candidate)->network.Rssi<competitor->network.Rssi )
  2077. && _rtw_memcmp(competitor->network.MacAddress, pmlmepriv->assoc_bssid, ETH_ALEN)==_TRUE
  2078. ) {
  2079. *candidate = competitor;
  2080. updated = _TRUE;
  2081. }
  2082. } else if (pmlmepriv->assoc_ssid.SsidLength == 0 ) { // associate with ssid, but ssidlength is 0
  2083. if( (*candidate == NULL ||(*candidate)->network.Rssi<competitor->network.Rssi ) ) {
  2084. *candidate = competitor;
  2085. updated = _TRUE;
  2086. }
  2087. } else
  2088. #ifdef CONFIG_LAYER2_ROAMING
  2089. if(rtw_to_roaming(adapter)) { // roaming
  2090. if( (*candidate == NULL ||(*candidate)->network.Rssi<competitor->network.Rssi )
  2091. && is_same_ess(&competitor->network, &pmlmepriv->cur_network.network)
  2092. //&&(!is_same_network(&competitor->network, &pmlmepriv->cur_network.network))
  2093. && rtw_get_passing_time_ms((u32)competitor->last_scanned) < RTW_SCAN_RESULT_EXPIRE
  2094. && rtw_is_desired_network(adapter, competitor)
  2095. ) {
  2096. *candidate = competitor;
  2097. updated = _TRUE;
  2098. }
  2099. } else
  2100. #endif
  2101. { // associate with ssid
  2102. if( (*candidate == NULL ||(*candidate)->network.Rssi<competitor->network.Rssi )
  2103. && (competitor->network.Ssid.SsidLength==pmlmepriv->assoc_ssid.SsidLength)
  2104. &&((_rtw_memcmp(competitor->network.Ssid.Ssid, pmlmepriv->assoc_ssid.Ssid, pmlmepriv->assoc_ssid.SsidLength)) == _TRUE)
  2105. && rtw_is_desired_network(adapter, competitor)
  2106. ) {
  2107. *candidate = competitor;
  2108. updated = _TRUE;
  2109. }
  2110. }
  2111. #endif
  2112. if(updated){
  2113. DBG_871X("[by_bssid:%u][assoc_ssid:%s]"
  2114. #ifdef CONFIG_LAYER2_ROAMING
  2115. "[to_roaming:%u] "
  2116. #endif
  2117. "new candidate: %s("MAC_FMT") rssi:%d\n",
  2118. pmlmepriv->assoc_by_bssid,
  2119. pmlmepriv->assoc_ssid.Ssid,
  2120. #ifdef CONFIG_LAYER2_ROAMING
  2121. rtw_to_roaming(adapter),
  2122. #endif
  2123. (*candidate)->network.Ssid.Ssid,
  2124. MAC_ARG((*candidate)->network.MacAddress),
  2125. (int)(*candidate)->network.Rssi
  2126. );
  2127. }
  2128. exit:
  2129. return updated;
  2130. }
  2131. /*
  2132. Calling context:
  2133. The caller of the sub-routine will be in critical section...
  2134. The caller must hold the following spinlock
  2135. pmlmepriv->lock
  2136. */
  2137. int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv )
  2138. {
  2139. _irqL irqL;
  2140. int ret;
  2141. _list *phead;
  2142. _adapter *adapter;
  2143. _queue *queue = &(pmlmepriv->scanned_queue);
  2144. struct wlan_network *pnetwork = NULL;
  2145. struct wlan_network *candidate = NULL;
  2146. u8 bSupportAntDiv = _FALSE;
  2147. _func_enter_;
  2148. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2149. phead = get_list_head(queue);
  2150. adapter = (_adapter *)pmlmepriv->nic_hdl;
  2151. pmlmepriv->pscanned = get_next( phead );
  2152. while (!rtw_end_of_queue_search(phead, pmlmepriv->pscanned)) {
  2153. pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned, struct wlan_network, list);
  2154. if(pnetwork==NULL){
  2155. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("%s return _FAIL:(pnetwork==NULL)\n", __FUNCTION__));
  2156. ret = _FAIL;
  2157. goto exit;
  2158. }
  2159. pmlmepriv->pscanned = get_next(pmlmepriv->pscanned);
  2160. #if 0
  2161. DBG_871X("MacAddress:"MAC_FMT" ssid:%s\n", MAC_ARG(pnetwork->network.MacAddress), pnetwork->network.Ssid.Ssid);
  2162. #endif
  2163. rtw_check_join_candidate(pmlmepriv, &candidate, pnetwork);
  2164. }
  2165. if(candidate == NULL) {
  2166. DBG_871X("%s: return _FAIL(candidate == NULL)\n", __FUNCTION__);
  2167. #ifdef CONFIG_WOWLAN
  2168. _clr_fwstate_(pmlmepriv, _FW_LINKED|_FW_UNDER_LINKING);
  2169. #endif
  2170. ret = _FAIL;
  2171. goto exit;
  2172. } else {
  2173. DBG_871X("%s: candidate: %s("MAC_FMT", ch:%u)\n", __FUNCTION__,
  2174. candidate->network.Ssid.Ssid, MAC_ARG(candidate->network.MacAddress),
  2175. candidate->network.Configuration.DSConfig);
  2176. }
  2177. // check for situation of _FW_LINKED
  2178. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  2179. {
  2180. DBG_871X("%s: _FW_LINKED while ask_for_joinbss!!!\n", __FUNCTION__);
  2181. #if 0 // for WPA/WPA2 authentication, wpa_supplicant will expect authentication from AP, it is needed to reconnect AP...
  2182. if(is_same_network(&pmlmepriv->cur_network.network, &candidate->network))
  2183. {
  2184. DBG_871X("%s: _FW_LINKED and is same network, it needn't join again\n", __FUNCTION__);
  2185. rtw_indicate_connect(adapter);//rtw_indicate_connect again
  2186. ret = 2;
  2187. goto exit;
  2188. }
  2189. else
  2190. #endif
  2191. {
  2192. rtw_disassoc_cmd(adapter, 0, _TRUE);
  2193. rtw_indicate_disconnect(adapter);
  2194. rtw_free_assoc_resources(adapter, 0);
  2195. }
  2196. }
  2197. #ifdef CONFIG_ANTENNA_DIVERSITY
  2198. rtw_hal_get_def_var(adapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &(bSupportAntDiv));
  2199. if(_TRUE == bSupportAntDiv)
  2200. {
  2201. u8 CurrentAntenna;
  2202. rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA, &(CurrentAntenna));
  2203. DBG_871X("#### Opt_Ant_(%s) , cur_Ant(%s)\n",
  2204. (2==candidate->network.PhyInfo.Optimum_antenna)?"A":"B",
  2205. (2==CurrentAntenna)?"A":"B"
  2206. );
  2207. }
  2208. #endif
  2209. set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
  2210. ret = rtw_joinbss_cmd(adapter, candidate);
  2211. exit:
  2212. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2213. _func_exit_;
  2214. return ret;
  2215. }
  2216. #else
  2217. int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv )
  2218. {
  2219. _irqL irqL;
  2220. _list *phead;
  2221. #ifdef CONFIG_ANTENNA_DIVERSITY
  2222. u8 CurrentAntenna;
  2223. #endif
  2224. unsigned char *dst_ssid, *src_ssid;
  2225. _adapter *adapter;
  2226. _queue *queue = &(pmlmepriv->scanned_queue);
  2227. struct wlan_network *pnetwork = NULL;
  2228. struct wlan_network *pnetwork_max_rssi = NULL;
  2229. #ifdef CONFIG_LAYER2_ROAMING
  2230. struct wlan_network * roaming_candidate=NULL;
  2231. u32 cur_time=rtw_get_current_time();
  2232. #endif
  2233. _func_enter_;
  2234. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2235. phead = get_list_head(queue);
  2236. adapter = (_adapter *)pmlmepriv->nic_hdl;
  2237. pmlmepriv->pscanned = get_next( phead );
  2238. while (!rtw_end_of_queue_search(phead, pmlmepriv->pscanned)) {
  2239. pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned, struct wlan_network, list);
  2240. if(pnetwork==NULL){
  2241. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("(2)rtw_select_and_join_from_scanned_queue return _FAIL:(pnetwork==NULL)\n"));
  2242. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2243. return _FAIL;
  2244. }
  2245. dst_ssid = pnetwork->network.Ssid.Ssid;
  2246. src_ssid = pmlmepriv->assoc_ssid.Ssid;
  2247. pmlmepriv->pscanned = get_next(pmlmepriv->pscanned);
  2248. #if 0
  2249. DBG_871X("MacAddress:"MAC_FMT" ssid:%s\n", MAC_ARG(pnetwork->network.MacAddress), pnetwork->network.Ssid.Ssid);
  2250. #endif
  2251. if(pmlmepriv->assoc_by_bssid==_TRUE)
  2252. {
  2253. if(_rtw_memcmp(pnetwork->network.MacAddress, pmlmepriv->assoc_bssid, ETH_ALEN)==_TRUE)
  2254. {
  2255. //remove the condition @ 20081125
  2256. //if((pmlmepriv->cur_network.network.InfrastructureMode==Ndis802_11AutoUnknown)||
  2257. // pmlmepriv->cur_network.network.InfrastructureMode == pnetwork->network.InfrastructureMode)
  2258. // goto ask_for_joinbss;
  2259. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  2260. {
  2261. if(is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network))
  2262. {
  2263. //DBG_871X("select_and_join(1): _FW_LINKED and is same network, it needn't join again\n");
  2264. rtw_indicate_connect(adapter);//rtw_indicate_connect again
  2265. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2266. return 2;
  2267. }
  2268. else
  2269. {
  2270. rtw_disassoc_cmd(adapter, 0, _TRUE);
  2271. rtw_indicate_disconnect(adapter);
  2272. rtw_free_assoc_resources(adapter, 0);
  2273. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2274. goto ask_for_joinbss;
  2275. }
  2276. }
  2277. else
  2278. {
  2279. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2280. goto ask_for_joinbss;
  2281. }
  2282. }
  2283. } else if (pmlmepriv->assoc_ssid.SsidLength == 0) {
  2284. goto ask_for_joinbss;//anyway, join first selected(dequeued) pnetwork if ssid_len=0
  2285. #ifdef CONFIG_LAYER2_ROAMING
  2286. } else if (rtw_to_roaming(adapter) > 0) {
  2287. if( (roaming_candidate == NULL ||roaming_candidate->network.Rssi<pnetwork->network.Rssi )
  2288. && is_same_ess(&pnetwork->network, &pmlmepriv->cur_network.network)
  2289. //&&(!is_same_network(&pnetwork->network, &pmlmepriv->cur_network.network))
  2290. && rtw_get_time_interval_ms((u32)pnetwork->last_scanned,cur_time) < 5000
  2291. ) {
  2292. roaming_candidate = pnetwork;
  2293. //RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,
  2294. DBG_871X
  2295. ("roaming_candidate???: %s("MAC_FMT")\n",
  2296. roaming_candidate->network.Ssid.Ssid, MAC_ARG(roaming_candidate->network.MacAddress) )
  2297. //)
  2298. ;
  2299. }
  2300. continue;
  2301. #endif
  2302. } else if ( (pnetwork->network.Ssid.SsidLength==pmlmepriv->assoc_ssid.SsidLength)
  2303. &&((_rtw_memcmp(dst_ssid, src_ssid, pmlmepriv->assoc_ssid.SsidLength)) == _TRUE)
  2304. )
  2305. {
  2306. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("dst_ssid=%s, src_ssid=%s \n", dst_ssid, src_ssid));
  2307. #ifdef CONFIG_ANTENNA_DIVERSITY
  2308. rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA, &(CurrentAntenna));
  2309. DBG_871X("#### dst_ssid=(%s) Opt_Ant_(%s) , cur_Ant(%s)\n", dst_ssid,
  2310. (2==pnetwork->network.PhyInfo.Optimum_antenna)?"A":"B",
  2311. (2==CurrentAntenna)?"A":"B");
  2312. #endif
  2313. //remove the condition @ 20081125
  2314. //if((pmlmepriv->cur_network.network.InfrastructureMode==Ndis802_11AutoUnknown)||
  2315. // pmlmepriv->cur_network.network.InfrastructureMode == pnetwork->network.InfrastructureMode)
  2316. //{
  2317. // _rtw_memcpy(pmlmepriv->assoc_bssid, pnetwork->network.MacAddress, ETH_ALEN);
  2318. // goto ask_for_joinbss;
  2319. //}
  2320. if(pmlmepriv->assoc_by_rssi==_TRUE)//if the ssid is the same, select the bss which has the max rssi
  2321. {
  2322. if( NULL==pnetwork_max_rssi|| pnetwork->network.Rssi > pnetwork_max_rssi->network.Rssi)
  2323. pnetwork_max_rssi = pnetwork;
  2324. }
  2325. else if(rtw_is_desired_network(adapter, pnetwork) == _TRUE)
  2326. {
  2327. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  2328. {
  2329. #if 0
  2330. if(is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network))
  2331. {
  2332. DBG_871X("select_and_join(2): _FW_LINKED and is same network, it needn't join again\n");
  2333. rtw_indicate_connect(adapter);//rtw_indicate_connect again
  2334. return 2;
  2335. }
  2336. else
  2337. #endif
  2338. {
  2339. rtw_disassoc_cmd(adapter, 0, _TRUE);
  2340. //rtw_indicate_disconnect(adapter);//
  2341. rtw_free_assoc_resources(adapter, 0);
  2342. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2343. goto ask_for_joinbss;
  2344. }
  2345. }
  2346. else
  2347. {
  2348. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2349. goto ask_for_joinbss;
  2350. }
  2351. }
  2352. }
  2353. }
  2354. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2355. #ifdef CONFIG_LAYER2_ROAMING
  2356. if(rtw_to_roaming(adapter) > 0 && roaming_candidate ){
  2357. pnetwork=roaming_candidate;
  2358. DBG_871X("select_and_join_from_scanned_queue: roaming_candidate: %s("MAC_FMT")\n",
  2359. pnetwork->network.Ssid.Ssid, MAC_ARG(pnetwork->network.MacAddress));
  2360. goto ask_for_joinbss;
  2361. }
  2362. #endif
  2363. if((pmlmepriv->assoc_by_rssi==_TRUE) && (pnetwork_max_rssi!=NULL))
  2364. {
  2365. pnetwork = pnetwork_max_rssi;
  2366. DBG_871X("select_and_join_from_scanned_queue: pnetwork_max_rssi: %s("MAC_FMT")\n",
  2367. pnetwork->network.Ssid.Ssid, MAC_ARG(pnetwork->network.MacAddress));
  2368. goto ask_for_joinbss;
  2369. }
  2370. DBG_871X("(1)rtw_select_and_join_from_scanned_queue return _FAIL\n");
  2371. _func_exit_;
  2372. return _FAIL;
  2373. ask_for_joinbss:
  2374. _func_exit_;
  2375. return rtw_joinbss_cmd(adapter, pnetwork);
  2376. }
  2377. #endif //PLATFORM_FREEBSD
  2378. sint rtw_set_auth(_adapter * adapter,struct security_priv *psecuritypriv)
  2379. {
  2380. struct cmd_obj* pcmd;
  2381. struct setauth_parm *psetauthparm;
  2382. struct cmd_priv *pcmdpriv=&(adapter->cmdpriv);
  2383. sint res=_SUCCESS;
  2384. _func_enter_;
  2385. pcmd = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  2386. if(pcmd==NULL){
  2387. res= _FAIL; //try again
  2388. goto exit;
  2389. }
  2390. psetauthparm=(struct setauth_parm*)rtw_zmalloc(sizeof(struct setauth_parm));
  2391. if(psetauthparm==NULL){
  2392. rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
  2393. res= _FAIL;
  2394. goto exit;
  2395. }
  2396. _rtw_memset(psetauthparm, 0, sizeof(struct setauth_parm));
  2397. psetauthparm->mode=(unsigned char)psecuritypriv->dot11AuthAlgrthm;
  2398. pcmd->cmdcode = _SetAuth_CMD_;
  2399. pcmd->parmbuf = (unsigned char *)psetauthparm;
  2400. pcmd->cmdsz = (sizeof(struct setauth_parm));
  2401. pcmd->rsp = NULL;
  2402. pcmd->rspsz = 0;
  2403. _rtw_init_listhead(&pcmd->list);
  2404. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("after enqueue set_auth_cmd, auth_mode=%x\n", psecuritypriv->dot11AuthAlgrthm));
  2405. res = rtw_enqueue_cmd(pcmdpriv, pcmd);
  2406. exit:
  2407. _func_exit_;
  2408. return res;
  2409. }
  2410. sint rtw_set_key(_adapter * adapter,struct security_priv *psecuritypriv,sint keyid, u8 set_tx)
  2411. {
  2412. u8 keylen;
  2413. struct cmd_obj *pcmd;
  2414. struct setkey_parm *psetkeyparm;
  2415. struct cmd_priv *pcmdpriv = &(adapter->cmdpriv);
  2416. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  2417. sint res=_SUCCESS;
  2418. _func_enter_;
  2419. pcmd = (struct cmd_obj*)rtw_zmalloc(sizeof(struct cmd_obj));
  2420. if(pcmd==NULL){
  2421. res= _FAIL; //try again
  2422. goto exit;
  2423. }
  2424. psetkeyparm=(struct setkey_parm*)rtw_zmalloc(sizeof(struct setkey_parm));
  2425. if(psetkeyparm==NULL){
  2426. rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
  2427. res= _FAIL;
  2428. goto exit;
  2429. }
  2430. _rtw_memset(psetkeyparm, 0, sizeof(struct setkey_parm));
  2431. if(psecuritypriv->dot11AuthAlgrthm ==dot11AuthAlgrthm_8021X){
  2432. psetkeyparm->algorithm=(unsigned char)psecuritypriv->dot118021XGrpPrivacy;
  2433. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("\n rtw_set_key: psetkeyparm->algorithm=(unsigned char)psecuritypriv->dot118021XGrpPrivacy=%d \n", psetkeyparm->algorithm));
  2434. }
  2435. else{
  2436. psetkeyparm->algorithm=(u8)psecuritypriv->dot11PrivacyAlgrthm;
  2437. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("\n rtw_set_key: psetkeyparm->algorithm=(u8)psecuritypriv->dot11PrivacyAlgrthm=%d \n", psetkeyparm->algorithm));
  2438. }
  2439. psetkeyparm->keyid = (u8)keyid;//0~3
  2440. psetkeyparm->set_tx = set_tx;
  2441. if (is_wep_enc(psetkeyparm->algorithm))
  2442. pmlmepriv->key_mask |= BIT(psetkeyparm->keyid);
  2443. #ifdef CONFIG_AUTOSUSPEND
  2444. if( _TRUE == adapter->pwrctrlpriv.bInternalAutoSuspend)
  2445. {
  2446. adapter->pwrctrlpriv.wepkeymask = pmlmepriv->key_mask;
  2447. DBG_871X("....AutoSuspend pwrctrlpriv.wepkeymask(%x)\n",adapter->pwrctrlpriv.wepkeymask);
  2448. }
  2449. #endif
  2450. DBG_871X("==> rtw_set_key algorithm(%x),keyid(%x),key_mask(%x)\n",psetkeyparm->algorithm,psetkeyparm->keyid,pmlmepriv->key_mask);
  2451. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("\n rtw_set_key: psetkeyparm->algorithm=%d psetkeyparm->keyid=(u8)keyid=%d \n",psetkeyparm->algorithm, keyid));
  2452. switch(psetkeyparm->algorithm){
  2453. case _WEP40_:
  2454. keylen=5;
  2455. _rtw_memcpy(&(psetkeyparm->key[0]), &(psecuritypriv->dot11DefKey[keyid].skey[0]), keylen);
  2456. break;
  2457. case _WEP104_:
  2458. keylen=13;
  2459. _rtw_memcpy(&(psetkeyparm->key[0]), &(psecuritypriv->dot11DefKey[keyid].skey[0]), keylen);
  2460. break;
  2461. case _TKIP_:
  2462. keylen=16;
  2463. _rtw_memcpy(&psetkeyparm->key, &psecuritypriv->dot118021XGrpKey[keyid], keylen);
  2464. psetkeyparm->grpkey=1;
  2465. break;
  2466. case _AES_:
  2467. keylen=16;
  2468. _rtw_memcpy(&psetkeyparm->key, &psecuritypriv->dot118021XGrpKey[keyid], keylen);
  2469. psetkeyparm->grpkey=1;
  2470. break;
  2471. default:
  2472. RT_TRACE(_module_rtl871x_mlme_c_,_drv_err_,("\n rtw_set_key:psecuritypriv->dot11PrivacyAlgrthm = %x (must be 1 or 2 or 4 or 5)\n",psecuritypriv->dot11PrivacyAlgrthm));
  2473. res= _FAIL;
  2474. goto exit;
  2475. }
  2476. pcmd->cmdcode = _SetKey_CMD_;
  2477. pcmd->parmbuf = (u8 *)psetkeyparm;
  2478. pcmd->cmdsz = (sizeof(struct setkey_parm));
  2479. pcmd->rsp = NULL;
  2480. pcmd->rspsz = 0;
  2481. _rtw_init_listhead(&pcmd->list);
  2482. //_rtw_init_sema(&(pcmd->cmd_sem), 0);
  2483. res = rtw_enqueue_cmd(pcmdpriv, pcmd);
  2484. exit:
  2485. _func_exit_;
  2486. return res;
  2487. }
  2488. //adjust IEs for rtw_joinbss_cmd in WMM
  2489. int rtw_restruct_wmm_ie(_adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len, uint initial_out_len)
  2490. {
  2491. unsigned int ielength=0;
  2492. unsigned int i, j;
  2493. i = 12; //after the fixed IE
  2494. while(i<in_len)
  2495. {
  2496. ielength = initial_out_len;
  2497. if(in_ie[i] == 0xDD && in_ie[i+2] == 0x00 && in_ie[i+3] == 0x50 && in_ie[i+4] == 0xF2 && in_ie[i+5] == 0x02 && i+5 < in_len) //WMM element ID and OUI
  2498. {
  2499. //Append WMM IE to the last index of out_ie
  2500. /*
  2501. for(j=i; j< i+(in_ie[i+1]+2); j++)
  2502. {
  2503. out_ie[ielength] = in_ie[j];
  2504. ielength++;
  2505. }
  2506. out_ie[initial_out_len+8] = 0x00; //force the QoS Info Field to be zero
  2507. */
  2508. for ( j = i; j < i + 9; j++ )
  2509. {
  2510. out_ie[ ielength] = in_ie[ j ];
  2511. ielength++;
  2512. }
  2513. out_ie[ initial_out_len + 1 ] = 0x07;
  2514. out_ie[ initial_out_len + 6 ] = 0x00;
  2515. out_ie[ initial_out_len + 8 ] = 0x00;
  2516. break;
  2517. }
  2518. i+=(in_ie[i+1]+2); // to the next IE element
  2519. }
  2520. return ielength;
  2521. }
  2522. //
  2523. // Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.)
  2524. // Added by Annie, 2006-05-07.
  2525. //
  2526. // Search by BSSID,
  2527. // Return Value:
  2528. // -1 :if there is no pre-auth key in the table
  2529. // >=0 :if there is pre-auth key, and return the entry id
  2530. //
  2531. //
  2532. static int SecIsInPMKIDList(_adapter *Adapter, u8 *bssid)
  2533. {
  2534. struct security_priv *psecuritypriv=&Adapter->securitypriv;
  2535. int i=0;
  2536. do
  2537. {
  2538. if( ( psecuritypriv->PMKIDList[i].bUsed ) &&
  2539. ( _rtw_memcmp( psecuritypriv->PMKIDList[i].Bssid, bssid, ETH_ALEN ) == _TRUE ) )
  2540. {
  2541. break;
  2542. }
  2543. else
  2544. {
  2545. i++;
  2546. //continue;
  2547. }
  2548. }while(i<NUM_PMKID_CACHE);
  2549. if( i == NUM_PMKID_CACHE )
  2550. {
  2551. i = -1;// Could not find.
  2552. }
  2553. else
  2554. {
  2555. // There is one Pre-Authentication Key for the specific BSSID.
  2556. }
  2557. return (i);
  2558. }
  2559. //
  2560. // Check the RSN IE length
  2561. // If the RSN IE length <= 20, the RSN IE didn't include the PMKID information
  2562. // 0-11th element in the array are the fixed IE
  2563. // 12th element in the array is the IE
  2564. // 13th element in the array is the IE length
  2565. //
  2566. static int rtw_append_pmkid(_adapter *Adapter,int iEntry, u8 *ie, uint ie_len)
  2567. {
  2568. struct security_priv *psecuritypriv=&Adapter->securitypriv;
  2569. if(ie[13]<=20){
  2570. // The RSN IE didn't include the PMK ID, append the PMK information
  2571. ie[ie_len]=1;
  2572. ie_len++;
  2573. ie[ie_len]=0; //PMKID count = 0x0100
  2574. ie_len++;
  2575. _rtw_memcpy( &ie[ie_len], &psecuritypriv->PMKIDList[iEntry].PMKID, 16);
  2576. ie_len+=16;
  2577. ie[13]+=18;//PMKID length = 2+16
  2578. }
  2579. return (ie_len);
  2580. }
  2581. sint rtw_restruct_sec_ie(_adapter *adapter,u8 *in_ie, u8 *out_ie, uint in_len)
  2582. {
  2583. u8 authmode, securitytype, match;
  2584. u8 sec_ie[255], uncst_oui[4], bkup_ie[255];
  2585. u8 wpa_oui[4]={0x0, 0x50, 0xf2, 0x01};
  2586. uint ielength, cnt, remove_cnt;
  2587. int iEntry;
  2588. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  2589. struct security_priv *psecuritypriv=&adapter->securitypriv;
  2590. uint ndisauthmode=psecuritypriv->ndisauthtype;
  2591. uint ndissecuritytype = psecuritypriv->ndisencryptstatus;
  2592. _func_enter_;
  2593. RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
  2594. ("+rtw_restruct_sec_ie: ndisauthmode=%d ndissecuritytype=%d\n",
  2595. ndisauthmode, ndissecuritytype));
  2596. //copy fixed ie only
  2597. _rtw_memcpy(out_ie, in_ie,12);
  2598. ielength=12;
  2599. if((ndisauthmode==Ndis802_11AuthModeWPA)||(ndisauthmode==Ndis802_11AuthModeWPAPSK))
  2600. authmode=_WPA_IE_ID_;
  2601. if((ndisauthmode==Ndis802_11AuthModeWPA2)||(ndisauthmode==Ndis802_11AuthModeWPA2PSK))
  2602. authmode=_WPA2_IE_ID_;
  2603. if(check_fwstate(pmlmepriv, WIFI_UNDER_WPS))
  2604. {
  2605. _rtw_memcpy(out_ie+ielength, psecuritypriv->wps_ie, psecuritypriv->wps_ie_len);
  2606. ielength += psecuritypriv->wps_ie_len;
  2607. }
  2608. else if((authmode==_WPA_IE_ID_)||(authmode==_WPA2_IE_ID_))
  2609. {
  2610. //copy RSN or SSN
  2611. _rtw_memcpy(&out_ie[ielength], &psecuritypriv->supplicant_ie[0], psecuritypriv->supplicant_ie[1]+2);
  2612. ielength+=psecuritypriv->supplicant_ie[1]+2;
  2613. rtw_report_sec_ie(adapter, authmode, psecuritypriv->supplicant_ie);
  2614. #ifdef CONFIG_DRVEXT_MODULE
  2615. drvext_report_sec_ie(&adapter->drvextpriv, authmode, sec_ie);
  2616. #endif
  2617. }
  2618. iEntry = SecIsInPMKIDList(adapter, pmlmepriv->assoc_bssid);
  2619. if(iEntry<0)
  2620. {
  2621. return ielength;
  2622. }
  2623. else
  2624. {
  2625. if(authmode == _WPA2_IE_ID_)
  2626. {
  2627. ielength=rtw_append_pmkid(adapter, iEntry, out_ie, ielength);
  2628. }
  2629. }
  2630. _func_exit_;
  2631. return ielength;
  2632. }
  2633. void rtw_init_registrypriv_dev_network( _adapter* adapter)
  2634. {
  2635. struct registry_priv* pregistrypriv = &adapter->registrypriv;
  2636. struct eeprom_priv* peepriv = &adapter->eeprompriv;
  2637. WLAN_BSSID_EX *pdev_network = &pregistrypriv->dev_network;
  2638. u8 *myhwaddr = myid(peepriv);
  2639. _func_enter_;
  2640. _rtw_memcpy(pdev_network->MacAddress, myhwaddr, ETH_ALEN);
  2641. _rtw_memcpy(&pdev_network->Ssid, &pregistrypriv->ssid, sizeof(NDIS_802_11_SSID));
  2642. pdev_network->Configuration.Length=sizeof(NDIS_802_11_CONFIGURATION);
  2643. pdev_network->Configuration.BeaconPeriod = 100;
  2644. pdev_network->Configuration.FHConfig.Length = 0;
  2645. pdev_network->Configuration.FHConfig.HopPattern = 0;
  2646. pdev_network->Configuration.FHConfig.HopSet = 0;
  2647. pdev_network->Configuration.FHConfig.DwellTime = 0;
  2648. _func_exit_;
  2649. }
  2650. void rtw_update_registrypriv_dev_network(_adapter* adapter)
  2651. {
  2652. int sz=0;
  2653. struct registry_priv* pregistrypriv = &adapter->registrypriv;
  2654. WLAN_BSSID_EX *pdev_network = &pregistrypriv->dev_network;
  2655. struct security_priv* psecuritypriv = &adapter->securitypriv;
  2656. struct wlan_network *cur_network = &adapter->mlmepriv.cur_network;
  2657. //struct xmit_priv *pxmitpriv = &adapter->xmitpriv;
  2658. _func_enter_;
  2659. #if 0
  2660. pxmitpriv->vcs_setting = pregistrypriv->vrtl_carrier_sense;
  2661. pxmitpriv->vcs = pregistrypriv->vcs_type;
  2662. pxmitpriv->vcs_type = pregistrypriv->vcs_type;
  2663. //pxmitpriv->rts_thresh = pregistrypriv->rts_thresh;
  2664. pxmitpriv->frag_len = pregistrypriv->frag_thresh;
  2665. adapter->qospriv.qos_option = pregistrypriv->wmm_enable;
  2666. #endif
  2667. pdev_network->Privacy = (psecuritypriv->dot11PrivacyAlgrthm > 0 ? 1 : 0) ; // adhoc no 802.1x
  2668. pdev_network->Rssi = 0;
  2669. switch(pregistrypriv->wireless_mode)
  2670. {
  2671. case WIRELESS_11B:
  2672. pdev_network->NetworkTypeInUse = (Ndis802_11DS);
  2673. break;
  2674. case WIRELESS_11G:
  2675. case WIRELESS_11BG:
  2676. case WIRELESS_11_24N:
  2677. case WIRELESS_11G_24N:
  2678. case WIRELESS_11BG_24N:
  2679. pdev_network->NetworkTypeInUse = (Ndis802_11OFDM24);
  2680. break;
  2681. case WIRELESS_11A:
  2682. case WIRELESS_11A_5N:
  2683. pdev_network->NetworkTypeInUse = (Ndis802_11OFDM5);
  2684. break;
  2685. case WIRELESS_11ABGN:
  2686. if(pregistrypriv->channel > 14)
  2687. pdev_network->NetworkTypeInUse = (Ndis802_11OFDM5);
  2688. else
  2689. pdev_network->NetworkTypeInUse = (Ndis802_11OFDM24);
  2690. break;
  2691. default :
  2692. // TODO
  2693. break;
  2694. }
  2695. pdev_network->Configuration.DSConfig = (pregistrypriv->channel);
  2696. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("pregistrypriv->channel=%d, pdev_network->Configuration.DSConfig=0x%x\n", pregistrypriv->channel, pdev_network->Configuration.DSConfig));
  2697. if(cur_network->network.InfrastructureMode == Ndis802_11IBSS)
  2698. pdev_network->Configuration.ATIMWindow = (0);
  2699. pdev_network->InfrastructureMode = (cur_network->network.InfrastructureMode);
  2700. // 1. Supported rates
  2701. // 2. IE
  2702. //rtw_set_supported_rate(pdev_network->SupportedRates, pregistrypriv->wireless_mode) ; // will be called in rtw_generate_ie
  2703. sz = rtw_generate_ie(pregistrypriv);
  2704. pdev_network->IELength = sz;
  2705. pdev_network->Length = get_WLAN_BSSID_EX_sz((WLAN_BSSID_EX *)pdev_network);
  2706. //notes: translate IELength & Length after assign the Length to cmdsz in createbss_cmd();
  2707. //pdev_network->IELength = cpu_to_le32(sz);
  2708. _func_exit_;
  2709. }
  2710. void rtw_get_encrypt_decrypt_from_registrypriv(_adapter* adapter)
  2711. {
  2712. _func_enter_;
  2713. _func_exit_;
  2714. }
  2715. //the fucntion is at passive_level
  2716. void rtw_joinbss_reset(_adapter *padapter)
  2717. {
  2718. u8 threshold;
  2719. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2720. #ifdef CONFIG_80211N_HT
  2721. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  2722. #endif
  2723. //todo: if you want to do something io/reg/hw setting before join_bss, please add code here
  2724. #ifdef CONFIG_80211N_HT
  2725. pmlmepriv->num_FortyMHzIntolerant = 0;
  2726. pmlmepriv->num_sta_no_ht = 0;
  2727. phtpriv->ampdu_enable = _FALSE;//reset to disabled
  2728. #if defined( CONFIG_USB_HCI) || defined (CONFIG_SDIO_HCI)
  2729. // TH=1 => means that invalidate usb rx aggregation
  2730. // TH=0 => means that validate usb rx aggregation, use init value.
  2731. if(phtpriv->ht_option)
  2732. {
  2733. if(padapter->registrypriv.wifi_spec==1)
  2734. threshold = 1;
  2735. else
  2736. threshold = 0;
  2737. rtw_hal_set_hwreg(padapter, HW_VAR_RXDMA_AGG_PG_TH, (u8 *)(&threshold));
  2738. }
  2739. else
  2740. {
  2741. threshold = 1;
  2742. rtw_hal_set_hwreg(padapter, HW_VAR_RXDMA_AGG_PG_TH, (u8 *)(&threshold));
  2743. }
  2744. #endif
  2745. #endif
  2746. }
  2747. #ifdef CONFIG_80211N_HT
  2748. //the fucntion is >= passive_level
  2749. unsigned int rtw_restructure_ht_ie(_adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len)
  2750. {
  2751. u32 ielen, out_len;
  2752. HT_CAP_AMPDU_FACTOR max_rx_ampdu_factor;
  2753. unsigned char *p, *pframe;
  2754. struct rtw_ieee80211_ht_cap ht_capie;
  2755. unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};
  2756. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2757. struct qos_priv *pqospriv= &pmlmepriv->qospriv;
  2758. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  2759. phtpriv->ht_option = _FALSE;
  2760. p = rtw_get_ie(in_ie+12, _HT_CAPABILITY_IE_, &ielen, in_len-12);
  2761. if(p && ielen>0)
  2762. {
  2763. if(pqospriv->qos_option == 0)
  2764. {
  2765. out_len = *pout_len;
  2766. pframe = rtw_set_ie(out_ie+out_len, _VENDOR_SPECIFIC_IE_,
  2767. _WMM_IE_Length_, WMM_IE, pout_len);
  2768. pqospriv->qos_option = 1;
  2769. }
  2770. out_len = *pout_len;
  2771. _rtw_memset(&ht_capie, 0, sizeof(struct rtw_ieee80211_ht_cap));
  2772. ht_capie.cap_info = IEEE80211_HT_CAP_SUP_WIDTH |IEEE80211_HT_CAP_SGI_20 |
  2773. IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_TX_STBC |
  2774. IEEE80211_HT_CAP_DSSSCCK40;
  2775. {
  2776. u32 rx_packet_offset, max_recvbuf_sz;
  2777. rtw_hal_get_def_var(padapter, HAL_DEF_RX_PACKET_OFFSET, &rx_packet_offset);
  2778. rtw_hal_get_def_var(padapter, HAL_DEF_MAX_RECVBUF_SZ, &max_recvbuf_sz);
  2779. //if(max_recvbuf_sz-rx_packet_offset>(8191-256)) {
  2780. // DBG_871X("%s IEEE80211_HT_CAP_MAX_AMSDU is set\n", __FUNCTION__);
  2781. // ht_capie.cap_info = ht_capie.cap_info |IEEE80211_HT_CAP_MAX_AMSDU;
  2782. //}
  2783. }
  2784. /*
  2785. AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
  2786. AMPDU_para [4:2]:Min MPDU Start Spacing
  2787. */
  2788. /*
  2789. #if defined(CONFIG_RTL8188E )&& defined (CONFIG_SDIO_HCI)
  2790. ht_capie.ampdu_params_info = 2;
  2791. #else
  2792. ht_capie.ampdu_params_info = (IEEE80211_HT_CAP_AMPDU_FACTOR&0x03);
  2793. #endif
  2794. */
  2795. rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
  2796. ht_capie.ampdu_params_info = (max_rx_ampdu_factor&0x03);
  2797. if(padapter->securitypriv.dot11PrivacyAlgrthm == _AES_ )
  2798. ht_capie.ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY&(0x07<<2));
  2799. else
  2800. ht_capie.ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY&0x00);
  2801. pframe = rtw_set_ie(out_ie+out_len, _HT_CAPABILITY_IE_,
  2802. sizeof(struct rtw_ieee80211_ht_cap), (unsigned char*)&ht_capie, pout_len);
  2803. //_rtw_memcpy(out_ie+out_len, p, ielen+2);//gtest
  2804. //*pout_len = *pout_len + (ielen+2);
  2805. phtpriv->ht_option = _TRUE;
  2806. p = rtw_get_ie(in_ie+12, _HT_ADD_INFO_IE_, &ielen, in_len-12);
  2807. if(p && (ielen==sizeof(struct ieee80211_ht_addt_info)))
  2808. {
  2809. out_len = *pout_len;
  2810. pframe = rtw_set_ie(out_ie+out_len, _HT_ADD_INFO_IE_, ielen, p+2 , pout_len);
  2811. }
  2812. }
  2813. return (phtpriv->ht_option);
  2814. }
  2815. //the fucntion is > passive_level (in critical_section)
  2816. void rtw_update_ht_cap(_adapter *padapter, u8 *pie, uint ie_len, u8 channel)
  2817. {
  2818. u8 *p, max_ampdu_sz;
  2819. int len;
  2820. //struct sta_info *bmc_sta, *psta;
  2821. struct rtw_ieee80211_ht_cap *pht_capie;
  2822. struct ieee80211_ht_addt_info *pht_addtinfo;
  2823. //struct recv_reorder_ctrl *preorder_ctrl;
  2824. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2825. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  2826. //struct recv_priv *precvpriv = &padapter->recvpriv;
  2827. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  2828. //struct wlan_network *pcur_network = &(pmlmepriv->cur_network);;
  2829. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2830. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2831. u8 cbw40_enable=0;
  2832. if(!phtpriv->ht_option)
  2833. return;
  2834. if ((!pmlmeinfo->HT_info_enable) || (!pmlmeinfo->HT_caps_enable))
  2835. return;
  2836. DBG_871X("+rtw_update_ht_cap()\n");
  2837. //maybe needs check if ap supports rx ampdu.
  2838. if((phtpriv->ampdu_enable==_FALSE) &&(pregistrypriv->ampdu_enable==1))
  2839. {
  2840. if(pregistrypriv->wifi_spec==1)
  2841. {
  2842. phtpriv->ampdu_enable = _FALSE;
  2843. }
  2844. else
  2845. {
  2846. phtpriv->ampdu_enable = _TRUE;
  2847. }
  2848. }
  2849. else if(pregistrypriv->ampdu_enable==2)
  2850. {
  2851. phtpriv->ampdu_enable = _TRUE;
  2852. }
  2853. //check Max Rx A-MPDU Size
  2854. len = 0;
  2855. p = rtw_get_ie(pie+sizeof (NDIS_802_11_FIXED_IEs), _HT_CAPABILITY_IE_, &len, ie_len-sizeof (NDIS_802_11_FIXED_IEs));
  2856. if(p && len>0)
  2857. {
  2858. pht_capie = (struct rtw_ieee80211_ht_cap *)(p+2);
  2859. max_ampdu_sz = (pht_capie->ampdu_params_info & IEEE80211_HT_CAP_AMPDU_FACTOR);
  2860. max_ampdu_sz = 1 << (max_ampdu_sz+3); // max_ampdu_sz (kbytes);
  2861. //DBG_871X("rtw_update_ht_cap(): max_ampdu_sz=%d\n", max_ampdu_sz);
  2862. phtpriv->rx_ampdu_maxlen = max_ampdu_sz;
  2863. }
  2864. len=0;
  2865. p = rtw_get_ie(pie+sizeof (NDIS_802_11_FIXED_IEs), _HT_ADD_INFO_IE_, &len, ie_len-sizeof (NDIS_802_11_FIXED_IEs));
  2866. if(p && len>0)
  2867. {
  2868. pht_addtinfo = (struct ieee80211_ht_addt_info *)(p+2);
  2869. //todo:
  2870. }
  2871. if (channel > 14) {
  2872. if ((pregistrypriv->bw_mode & 0xf0) > 0)
  2873. cbw40_enable = 1;
  2874. } else {
  2875. if ((pregistrypriv->bw_mode & 0x0f) > 0)
  2876. cbw40_enable = 1;
  2877. }
  2878. //update cur_bwmode & cur_ch_offset
  2879. if ((cbw40_enable) &&
  2880. (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & BIT(1)) &&
  2881. (pmlmeinfo->HT_info.infos[0] & BIT(2)))
  2882. {
  2883. int i;
  2884. u8 rf_type;
  2885. padapter->HalFunc.GetHwRegHandler(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  2886. //update the MCS rates
  2887. for (i = 0; i < 16; i++)
  2888. {
  2889. if((rf_type == RF_1T1R) || (rf_type == RF_1T2R))
  2890. {
  2891. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  2892. }
  2893. else
  2894. {
  2895. #ifdef CONFIG_DISABLE_MCS13TO15
  2896. if(pmlmeext->cur_bwmode == CHANNEL_WIDTH_40 && pregistrypriv->wifi_spec != 1 )
  2897. {
  2898. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= MCS_rate_2R_MCS13TO15_OFF[i];
  2899. }
  2900. else
  2901. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= MCS_rate_2R[i];
  2902. #else
  2903. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= MCS_rate_2R[i];
  2904. #endif //CONFIG_DISABLE_MCS13TO15
  2905. }
  2906. #ifdef RTL8192C_RECONFIG_TO_1T1R
  2907. {
  2908. pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  2909. }
  2910. #endif
  2911. }
  2912. //switch to the 40M Hz mode accoring to the AP
  2913. pmlmeext->cur_bwmode = CHANNEL_WIDTH_40;
  2914. switch ((pmlmeinfo->HT_info.infos[0] & 0x3))
  2915. {
  2916. case EXTCHNL_OFFSET_UPPER:
  2917. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  2918. break;
  2919. case EXTCHNL_OFFSET_LOWER:
  2920. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  2921. break;
  2922. default:
  2923. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  2924. break;
  2925. }
  2926. }
  2927. //
  2928. // Config SM Power Save setting
  2929. //
  2930. pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
  2931. if(pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
  2932. {
  2933. /*u8 i;
  2934. //update the MCS rates
  2935. for (i = 0; i < 16; i++)
  2936. {
  2937. pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  2938. }*/
  2939. DBG_871X("%s(): WLAN_HT_CAP_SM_PS_STATIC\n",__FUNCTION__);
  2940. }
  2941. //
  2942. // Config current HT Protection mode.
  2943. //
  2944. pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3;
  2945. #if 0 //move to rtw_update_sta_info_client()
  2946. //for A-MPDU Rx reordering buffer control for bmc_sta & sta_info
  2947. //if A-MPDU Rx is enabled, reseting rx_ordering_ctrl wstart_b(indicate_seq) to default value=0xffff
  2948. //todo: check if AP can send A-MPDU packets
  2949. bmc_sta = rtw_get_bcmc_stainfo(padapter);
  2950. if(bmc_sta)
  2951. {
  2952. for(i=0; i < 16 ; i++)
  2953. {
  2954. //preorder_ctrl = &precvpriv->recvreorder_ctrl[i];
  2955. preorder_ctrl = &bmc_sta->recvreorder_ctrl[i];
  2956. preorder_ctrl->enable = _FALSE;
  2957. preorder_ctrl->indicate_seq = 0xffff;
  2958. #ifdef DBG_RX_SEQ
  2959. DBG_871X("DBG_RX_SEQ %s:%d indicate_seq:%u \n", __FUNCTION__, __LINE__,
  2960. preorder_ctrl->indicate_seq);
  2961. #endif
  2962. preorder_ctrl->wend_b= 0xffff;
  2963. preorder_ctrl->wsize_b = 64;//max_ampdu_sz;//ex. 32(kbytes) -> wsize_b=32
  2964. }
  2965. }
  2966. psta = rtw_get_stainfo(&padapter->stapriv, pcur_network->network.MacAddress);
  2967. if(psta)
  2968. {
  2969. for(i=0; i < 16 ; i++)
  2970. {
  2971. //preorder_ctrl = &precvpriv->recvreorder_ctrl[i];
  2972. preorder_ctrl = &psta->recvreorder_ctrl[i];
  2973. preorder_ctrl->enable = _FALSE;
  2974. preorder_ctrl->indicate_seq = 0xffff;
  2975. #ifdef DBG_RX_SEQ
  2976. DBG_871X("DBG_RX_SEQ %s:%d indicate_seq:%u \n", __FUNCTION__, __LINE__,
  2977. preorder_ctrl->indicate_seq);
  2978. #endif
  2979. preorder_ctrl->wend_b= 0xffff;
  2980. preorder_ctrl->wsize_b = 64;//max_ampdu_sz;//ex. 32(kbytes) -> wsize_b=32
  2981. }
  2982. }
  2983. #endif
  2984. }
  2985. void rtw_issue_addbareq_cmd(_adapter *padapter, struct xmit_frame *pxmitframe)
  2986. {
  2987. u8 issued;
  2988. int priority;
  2989. struct sta_info *psta=NULL;
  2990. struct ht_priv *phtpriv;
  2991. struct pkt_attrib *pattrib =&pxmitframe->attrib;
  2992. s32 bmcst = IS_MCAST(pattrib->ra);
  2993. //if(bmcst || (padapter->mlmepriv.LinkDetectInfo.bTxBusyTraffic == _FALSE))
  2994. if(bmcst || (padapter->mlmepriv.LinkDetectInfo.NumTxOkInPeriod<100))
  2995. return;
  2996. priority = pattrib->priority;
  2997. psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
  2998. if(pattrib->psta != psta)
  2999. {
  3000. DBG_871X("%s, pattrib->psta(%p) != psta(%p)\n", __func__, pattrib->psta, psta);
  3001. return;
  3002. }
  3003. if(psta==NULL)
  3004. {
  3005. DBG_871X("%s, psta==NUL\n", __func__);
  3006. return;
  3007. }
  3008. if(!(psta->state &_FW_LINKED))
  3009. {
  3010. DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  3011. return;
  3012. }
  3013. phtpriv = &psta->htpriv;
  3014. if((phtpriv->ht_option==_TRUE) && (phtpriv->ampdu_enable==_TRUE))
  3015. {
  3016. issued = (phtpriv->agg_enable_bitmap>>priority)&0x1;
  3017. issued |= (phtpriv->candidate_tid_bitmap>>priority)&0x1;
  3018. if(0==issued)
  3019. {
  3020. DBG_871X("rtw_issue_addbareq_cmd, p=%d\n", priority);
  3021. psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority);
  3022. rtw_addbareq_cmd(padapter,(u8) priority, pattrib->ra);
  3023. }
  3024. }
  3025. }
  3026. #endif
  3027. #ifdef CONFIG_LAYER2_ROAMING
  3028. inline void rtw_set_roaming(_adapter *adapter, u8 to_roaming)
  3029. {
  3030. if (to_roaming == 0)
  3031. adapter->mlmepriv.to_join = _FALSE;
  3032. adapter->mlmepriv.to_roaming = to_roaming;
  3033. }
  3034. inline u8 rtw_to_roaming(_adapter *adapter)
  3035. {
  3036. return adapter->mlmepriv.to_roaming;
  3037. }
  3038. void rtw_roaming(_adapter *padapter, struct wlan_network *tgt_network)
  3039. {
  3040. _irqL irqL;
  3041. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3042. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  3043. _rtw_roaming(padapter, tgt_network);
  3044. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  3045. }
  3046. void _rtw_roaming(_adapter *padapter, struct wlan_network *tgt_network)
  3047. {
  3048. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3049. int do_join_r;
  3050. struct wlan_network *pnetwork;
  3051. if(tgt_network != NULL)
  3052. pnetwork = tgt_network;
  3053. else
  3054. pnetwork = &pmlmepriv->cur_network;
  3055. if(0 < rtw_to_roaming(padapter)) {
  3056. DBG_871X("roaming from %s("MAC_FMT"), length:%d\n",
  3057. pnetwork->network.Ssid.Ssid, MAC_ARG(pnetwork->network.MacAddress),
  3058. pnetwork->network.Ssid.SsidLength);
  3059. _rtw_memcpy(&pmlmepriv->assoc_ssid, &pnetwork->network.Ssid, sizeof(NDIS_802_11_SSID));
  3060. pmlmepriv->assoc_by_bssid = _FALSE;
  3061. #ifdef CONFIG_WAPI_SUPPORT
  3062. rtw_wapi_return_all_sta_info(padapter);
  3063. #endif
  3064. while(1) {
  3065. if( _SUCCESS==(do_join_r=rtw_do_join(padapter)) ) {
  3066. break;
  3067. } else {
  3068. DBG_871X("roaming do_join return %d\n", do_join_r);
  3069. pmlmepriv->to_roaming--;
  3070. if(0< rtw_to_roaming(padapter)) {
  3071. continue;
  3072. } else {
  3073. DBG_871X("%s(%d) -to roaming fail, indicate_disconnect\n", __FUNCTION__,__LINE__);
  3074. rtw_indicate_disconnect(padapter);
  3075. break;
  3076. }
  3077. }
  3078. }
  3079. }
  3080. }
  3081. #endif
  3082. sint rtw_linked_check(_adapter *padapter)
  3083. {
  3084. if( (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == _TRUE) ||
  3085. (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE) == _TRUE))
  3086. {
  3087. if(padapter->stapriv.asoc_sta_count > 2)
  3088. return _TRUE;
  3089. }
  3090. else
  3091. { //Station mode
  3092. if(check_fwstate(&padapter->mlmepriv, _FW_LINKED)== _TRUE)
  3093. return _TRUE;
  3094. }
  3095. return _FALSE;
  3096. }
  3097. #ifdef CONFIG_CONCURRENT_MODE
  3098. sint rtw_buddy_adapter_up(_adapter *padapter)
  3099. {
  3100. sint res = _FALSE;
  3101. if(padapter == NULL)
  3102. return res;
  3103. if(padapter->pbuddy_adapter == NULL)
  3104. {
  3105. res = _FALSE;
  3106. }
  3107. else if( (padapter->pbuddy_adapter->bDriverStopped) || (padapter->pbuddy_adapter->bSurpriseRemoved) ||
  3108. (padapter->pbuddy_adapter->bup == _FALSE) || (padapter->pbuddy_adapter->hw_init_completed == _FALSE))
  3109. {
  3110. res = _FALSE;
  3111. }
  3112. else
  3113. {
  3114. res = _TRUE;
  3115. }
  3116. return res;
  3117. }
  3118. sint check_buddy_fwstate(_adapter *padapter, sint state)
  3119. {
  3120. if(padapter == NULL)
  3121. return _FALSE;
  3122. if(padapter->pbuddy_adapter == NULL)
  3123. return _FALSE;
  3124. if ((state == WIFI_FW_NULL_STATE) &&
  3125. (padapter->pbuddy_adapter->mlmepriv.fw_state == WIFI_FW_NULL_STATE))
  3126. return _TRUE;
  3127. if (padapter->pbuddy_adapter->mlmepriv.fw_state & state)
  3128. return _TRUE;
  3129. return _FALSE;
  3130. }
  3131. #endif //CONFIG_CONCURRENT_MODE