rtw_recv.c 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 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_RECV_C_
  21. #include <drv_types.h>
  22. #if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
  23. #error "Shall be Linux or Windows, but not both!\n"
  24. #endif
  25. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  26. void rtw_signal_stat_timer_hdl(RTW_TIMER_HDL_ARGS);
  27. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
  28. void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
  29. {
  30. _func_enter_;
  31. _rtw_memset((u8 *)psta_recvpriv, 0, sizeof (struct sta_recv_priv));
  32. _rtw_spinlock_init(&psta_recvpriv->lock);
  33. //for(i=0; i<MAX_RX_NUMBLKS; i++)
  34. // _rtw_init_queue(&psta_recvpriv->blk_strms[i]);
  35. _rtw_init_queue(&psta_recvpriv->defrag_q);
  36. _func_exit_;
  37. }
  38. sint _rtw_init_recv_priv(struct recv_priv *precvpriv, _adapter *padapter)
  39. {
  40. sint i;
  41. union recv_frame *precvframe;
  42. sint res=_SUCCESS;
  43. _func_enter_;
  44. // We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc().
  45. //_rtw_memset((unsigned char *)precvpriv, 0, sizeof (struct recv_priv));
  46. _rtw_spinlock_init(&precvpriv->lock);
  47. _rtw_init_queue(&precvpriv->free_recv_queue);
  48. _rtw_init_queue(&precvpriv->recv_pending_queue);
  49. _rtw_init_queue(&precvpriv->uc_swdec_pending_queue);
  50. precvpriv->adapter = padapter;
  51. precvpriv->free_recvframe_cnt = NR_RECVFRAME;
  52. rtw_os_recv_resource_init(precvpriv, padapter);
  53. precvpriv->pallocated_frame_buf = rtw_zvmalloc(NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
  54. if(precvpriv->pallocated_frame_buf==NULL){
  55. res= _FAIL;
  56. goto exit;
  57. }
  58. //_rtw_memset(precvpriv->pallocated_frame_buf, 0, NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
  59. precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
  60. //precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf + RXFRAME_ALIGN_SZ -
  61. // ((SIZE_PTR) (precvpriv->pallocated_frame_buf) &(RXFRAME_ALIGN_SZ-1));
  62. precvframe = (union recv_frame*) precvpriv->precv_frame_buf;
  63. for(i=0; i < NR_RECVFRAME ; i++)
  64. {
  65. _rtw_init_listhead(&(precvframe->u.list));
  66. rtw_list_insert_tail(&(precvframe->u.list), &(precvpriv->free_recv_queue.queue));
  67. res = rtw_os_recv_resource_alloc(padapter, precvframe);
  68. precvframe->u.hdr.len = 0;
  69. precvframe->u.hdr.adapter =padapter;
  70. precvframe++;
  71. }
  72. #ifdef CONFIG_USB_HCI
  73. precvpriv->rx_pending_cnt=1;
  74. _rtw_init_sema(&precvpriv->allrxreturnevt, 0);
  75. #endif
  76. res = rtw_hal_init_recv_priv(padapter);
  77. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  78. rtw_init_timer(&precvpriv->signal_stat_timer, padapter, RTW_TIMER_HDL_NAME(signal_stat));
  79. precvpriv->signal_stat_sampling_interval = 1000; //ms
  80. //precvpriv->signal_stat_converging_constant = 5000; //ms
  81. rtw_set_signal_stat_timer(precvpriv);
  82. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
  83. exit:
  84. _func_exit_;
  85. return res;
  86. }
  87. void rtw_mfree_recv_priv_lock(struct recv_priv *precvpriv);
  88. void rtw_mfree_recv_priv_lock(struct recv_priv *precvpriv)
  89. {
  90. _rtw_spinlock_free(&precvpriv->lock);
  91. #ifdef CONFIG_RECV_THREAD_MODE
  92. _rtw_free_sema(&precvpriv->recv_sema);
  93. _rtw_free_sema(&precvpriv->terminate_recvthread_sema);
  94. #endif
  95. _rtw_spinlock_free(&precvpriv->free_recv_queue.lock);
  96. _rtw_spinlock_free(&precvpriv->recv_pending_queue.lock);
  97. _rtw_spinlock_free(&precvpriv->free_recv_buf_queue.lock);
  98. #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
  99. _rtw_spinlock_free(&precvpriv->recv_buf_pending_queue.lock);
  100. #endif // CONFIG_USE_USB_BUFFER_ALLOC_RX
  101. }
  102. void _rtw_free_recv_priv (struct recv_priv *precvpriv)
  103. {
  104. _adapter *padapter = precvpriv->adapter;
  105. _func_enter_;
  106. rtw_free_uc_swdec_pending_queue(padapter);
  107. rtw_mfree_recv_priv_lock(precvpriv);
  108. rtw_os_recv_resource_free(precvpriv);
  109. if(precvpriv->pallocated_frame_buf) {
  110. rtw_vmfree(precvpriv->pallocated_frame_buf, NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
  111. }
  112. rtw_hal_free_recv_priv(padapter);
  113. _func_exit_;
  114. }
  115. union recv_frame *_rtw_alloc_recvframe (_queue *pfree_recv_queue)
  116. {
  117. union recv_frame *precvframe;
  118. _list *plist, *phead;
  119. _adapter *padapter;
  120. struct recv_priv *precvpriv;
  121. _func_enter_;
  122. if(_rtw_queue_empty(pfree_recv_queue) == _TRUE)
  123. {
  124. precvframe = NULL;
  125. }
  126. else
  127. {
  128. phead = get_list_head(pfree_recv_queue);
  129. plist = get_next(phead);
  130. precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
  131. rtw_list_delete(&precvframe->u.hdr.list);
  132. padapter=precvframe->u.hdr.adapter;
  133. if(padapter !=NULL){
  134. precvpriv=&padapter->recvpriv;
  135. if(pfree_recv_queue == &precvpriv->free_recv_queue)
  136. precvpriv->free_recvframe_cnt--;
  137. }
  138. }
  139. _func_exit_;
  140. return precvframe;
  141. }
  142. union recv_frame *rtw_alloc_recvframe (_queue *pfree_recv_queue)
  143. {
  144. _irqL irqL;
  145. union recv_frame *precvframe;
  146. _enter_critical_bh(&pfree_recv_queue->lock, &irqL);
  147. precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
  148. _exit_critical_bh(&pfree_recv_queue->lock, &irqL);
  149. return precvframe;
  150. }
  151. void rtw_init_recvframe(union recv_frame *precvframe, struct recv_priv *precvpriv)
  152. {
  153. /* Perry: This can be removed */
  154. _rtw_init_listhead(&precvframe->u.hdr.list);
  155. precvframe->u.hdr.len=0;
  156. }
  157. int rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue)
  158. {
  159. _irqL irqL;
  160. _adapter *padapter=precvframe->u.hdr.adapter;
  161. struct recv_priv *precvpriv = &padapter->recvpriv;
  162. _func_enter_;
  163. #ifdef CONFIG_CONCURRENT_MODE
  164. if(padapter->adapter_type > PRIMARY_ADAPTER)
  165. {
  166. padapter = padapter->pbuddy_adapter;//get primary_padapter
  167. precvpriv = &padapter->recvpriv;
  168. pfree_recv_queue = &precvpriv->free_recv_queue;
  169. precvframe->u.hdr.adapter = padapter;
  170. }
  171. #endif
  172. rtw_os_free_recvframe(precvframe);
  173. _enter_critical_bh(&pfree_recv_queue->lock, &irqL);
  174. rtw_list_delete(&(precvframe->u.hdr.list));
  175. precvframe->u.hdr.len = 0;
  176. rtw_list_insert_tail(&(precvframe->u.hdr.list), get_list_head(pfree_recv_queue));
  177. if(padapter !=NULL){
  178. if(pfree_recv_queue == &precvpriv->free_recv_queue)
  179. precvpriv->free_recvframe_cnt++;
  180. }
  181. _exit_critical_bh(&pfree_recv_queue->lock, &irqL);
  182. _func_exit_;
  183. return _SUCCESS;
  184. }
  185. sint _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue)
  186. {
  187. _adapter *padapter=precvframe->u.hdr.adapter;
  188. struct recv_priv *precvpriv = &padapter->recvpriv;
  189. _func_enter_;
  190. //_rtw_init_listhead(&(precvframe->u.hdr.list));
  191. rtw_list_delete(&(precvframe->u.hdr.list));
  192. rtw_list_insert_tail(&(precvframe->u.hdr.list), get_list_head(queue));
  193. if (padapter != NULL) {
  194. if (queue == &precvpriv->free_recv_queue)
  195. precvpriv->free_recvframe_cnt++;
  196. }
  197. _func_exit_;
  198. return _SUCCESS;
  199. }
  200. sint rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue)
  201. {
  202. sint ret;
  203. _irqL irqL;
  204. //_spinlock(&pfree_recv_queue->lock);
  205. _enter_critical_bh(&queue->lock, &irqL);
  206. ret = _rtw_enqueue_recvframe(precvframe, queue);
  207. //_rtw_spinunlock(&pfree_recv_queue->lock);
  208. _exit_critical_bh(&queue->lock, &irqL);
  209. return ret;
  210. }
  211. /*
  212. sint rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue)
  213. {
  214. return rtw_free_recvframe(precvframe, queue);
  215. }
  216. */
  217. /*
  218. caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
  219. pframequeue: defrag_queue : will be accessed in recv_thread (passive)
  220. using spinlock to protect
  221. */
  222. void rtw_free_recvframe_queue(_queue *pframequeue, _queue *pfree_recv_queue)
  223. {
  224. union recv_frame *precvframe;
  225. _list *plist, *phead;
  226. _func_enter_;
  227. _rtw_spinlock(&pframequeue->lock);
  228. phead = get_list_head(pframequeue);
  229. plist = get_next(phead);
  230. while(rtw_end_of_queue_search(phead, plist) == _FALSE)
  231. {
  232. precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
  233. plist = get_next(plist);
  234. //rtw_list_delete(&precvframe->u.hdr.list); // will do this in rtw_free_recvframe()
  235. rtw_free_recvframe(precvframe, pfree_recv_queue);
  236. }
  237. _rtw_spinunlock(&pframequeue->lock);
  238. _func_exit_;
  239. }
  240. u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter)
  241. {
  242. u32 cnt = 0;
  243. union recv_frame *pending_frame;
  244. while((pending_frame=rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
  245. rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
  246. DBG_871X("%s: dequeue uc_swdec_pending_queue\n", __func__);
  247. cnt++;
  248. }
  249. return cnt;
  250. }
  251. sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue)
  252. {
  253. _irqL irqL;
  254. _enter_critical_bh(&queue->lock, &irqL);
  255. rtw_list_delete(&precvbuf->list);
  256. rtw_list_insert_head(&precvbuf->list, get_list_head(queue));
  257. _exit_critical_bh(&queue->lock, &irqL);
  258. return _SUCCESS;
  259. }
  260. sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue)
  261. {
  262. _irqL irqL;
  263. #ifdef CONFIG_SDIO_HCI
  264. _enter_critical_bh(&queue->lock, &irqL);
  265. #else
  266. _enter_critical_ex(&queue->lock, &irqL);
  267. #endif/*#ifdef CONFIG_SDIO_HCI*/
  268. rtw_list_delete(&precvbuf->list);
  269. rtw_list_insert_tail(&precvbuf->list, get_list_head(queue));
  270. #ifdef CONFIG_SDIO_HCI
  271. _exit_critical_bh(&queue->lock, &irqL);
  272. #else
  273. _exit_critical_ex(&queue->lock, &irqL);
  274. #endif/*#ifdef CONFIG_SDIO_HCI*/
  275. return _SUCCESS;
  276. }
  277. struct recv_buf *rtw_dequeue_recvbuf (_queue *queue)
  278. {
  279. _irqL irqL;
  280. struct recv_buf *precvbuf;
  281. _list *plist, *phead;
  282. #ifdef CONFIG_SDIO_HCI
  283. _enter_critical_bh(&queue->lock, &irqL);
  284. #else
  285. _enter_critical_ex(&queue->lock, &irqL);
  286. #endif/*#ifdef CONFIG_SDIO_HCI*/
  287. if(_rtw_queue_empty(queue) == _TRUE)
  288. {
  289. precvbuf = NULL;
  290. }
  291. else
  292. {
  293. phead = get_list_head(queue);
  294. plist = get_next(phead);
  295. precvbuf = LIST_CONTAINOR(plist, struct recv_buf, list);
  296. rtw_list_delete(&precvbuf->list);
  297. }
  298. #ifdef CONFIG_SDIO_HCI
  299. _exit_critical_bh(&queue->lock, &irqL);
  300. #else
  301. _exit_critical_ex(&queue->lock, &irqL);
  302. #endif/*#ifdef CONFIG_SDIO_HCI*/
  303. return precvbuf;
  304. }
  305. sint recvframe_chkmic(_adapter *adapter, union recv_frame *precvframe);
  306. sint recvframe_chkmic(_adapter *adapter, union recv_frame *precvframe){
  307. sint i,res=_SUCCESS;
  308. u32 datalen;
  309. u8 miccode[8];
  310. u8 bmic_err=_FALSE,brpt_micerror = _TRUE;
  311. u8 *pframe, *payload,*pframemic;
  312. u8 *mickey;
  313. //u8 *iv,rxdata_key_idx=0;
  314. struct sta_info *stainfo;
  315. struct rx_pkt_attrib *prxattrib=&precvframe->u.hdr.attrib;
  316. struct security_priv *psecuritypriv=&adapter->securitypriv;
  317. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  318. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  319. _func_enter_;
  320. stainfo=rtw_get_stainfo(&adapter->stapriv ,&prxattrib->ta[0]);
  321. if(prxattrib->encrypt ==_TKIP_)
  322. {
  323. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n recvframe_chkmic:prxattrib->encrypt ==_TKIP_\n"));
  324. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n recvframe_chkmic:da=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
  325. prxattrib->ra[0],prxattrib->ra[1],prxattrib->ra[2],prxattrib->ra[3],prxattrib->ra[4],prxattrib->ra[5]));
  326. //calculate mic code
  327. if(stainfo!= NULL)
  328. {
  329. if(IS_MCAST(prxattrib->ra))
  330. {
  331. //mickey=&psecuritypriv->dot118021XGrprxmickey.skey[0];
  332. //iv = precvframe->u.hdr.rx_data+prxattrib->hdrlen;
  333. //rxdata_key_idx =( ((iv[3])>>6)&0x3) ;
  334. mickey=&psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
  335. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n recvframe_chkmic: bcmc key \n"));
  336. //DBG_871X("\n recvframe_chkmic: bcmc key psecuritypriv->dot118021XGrpKeyid(%d),pmlmeinfo->key_index(%d) ,recv key_id(%d)\n",
  337. // psecuritypriv->dot118021XGrpKeyid,pmlmeinfo->key_index,rxdata_key_idx);
  338. if(psecuritypriv->binstallGrpkey==_FALSE)
  339. {
  340. res=_FAIL;
  341. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n"));
  342. DBG_871X("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
  343. goto exit;
  344. }
  345. }
  346. else{
  347. mickey=&stainfo->dot11tkiprxmickey.skey[0];
  348. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n recvframe_chkmic: unicast key \n"));
  349. }
  350. datalen=precvframe->u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len-prxattrib->icv_len-8;//icv_len included the mic code
  351. pframe=precvframe->u.hdr.rx_data;
  352. payload=pframe+prxattrib->hdrlen+prxattrib->iv_len;
  353. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n",prxattrib->iv_len,prxattrib->icv_len));
  354. //rtw_seccalctkipmic(&stainfo->dot11tkiprxmickey.skey[0],pframe,payload, datalen ,&miccode[0],(unsigned char)prxattrib->priority); //care the length of the data
  355. rtw_seccalctkipmic(mickey,pframe,payload, datalen ,&miccode[0],(unsigned char)prxattrib->priority); //care the length of the data
  356. pframemic=payload+datalen;
  357. bmic_err=_FALSE;
  358. for(i=0;i<8;i++){
  359. if(miccode[i] != *(pframemic+i)){
  360. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvframe_chkmic:miccode[%d](%02x) != *(pframemic+%d)(%02x) ",i,miccode[i],i,*(pframemic+i)));
  361. bmic_err=_TRUE;
  362. }
  363. }
  364. if(bmic_err==_TRUE){
  365. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n *(pframemic-8)-*(pframemic-1)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
  366. *(pframemic-8),*(pframemic-7),*(pframemic-6),*(pframemic-5),*(pframemic-4),*(pframemic-3),*(pframemic-2),*(pframemic-1)));
  367. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n *(pframemic-16)-*(pframemic-9)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
  368. *(pframemic-16),*(pframemic-15),*(pframemic-14),*(pframemic-13),*(pframemic-12),*(pframemic-11),*(pframemic-10),*(pframemic-9)));
  369. {
  370. uint i;
  371. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n ======demp packet (len=%d)======\n",precvframe->u.hdr.len));
  372. for(i=0;i<precvframe->u.hdr.len;i=i+8){
  373. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
  374. *(precvframe->u.hdr.rx_data+i),*(precvframe->u.hdr.rx_data+i+1),
  375. *(precvframe->u.hdr.rx_data+i+2),*(precvframe->u.hdr.rx_data+i+3),
  376. *(precvframe->u.hdr.rx_data+i+4),*(precvframe->u.hdr.rx_data+i+5),
  377. *(precvframe->u.hdr.rx_data+i+6),*(precvframe->u.hdr.rx_data+i+7)));
  378. }
  379. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n ======demp packet end [len=%d]======\n",precvframe->u.hdr.len));
  380. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n hrdlen=%d, \n",prxattrib->hdrlen));
  381. }
  382. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("ra=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x psecuritypriv->binstallGrpkey=%d ",
  383. prxattrib->ra[0],prxattrib->ra[1],prxattrib->ra[2],
  384. prxattrib->ra[3],prxattrib->ra[4],prxattrib->ra[5],psecuritypriv->binstallGrpkey));
  385. // double check key_index for some timing issue ,
  386. // cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue
  387. if((IS_MCAST(prxattrib->ra)==_TRUE) && (prxattrib->key_index != pmlmeinfo->key_index ))
  388. brpt_micerror = _FALSE;
  389. if((prxattrib->bdecrypted ==_TRUE)&& (brpt_micerror == _TRUE))
  390. {
  391. rtw_handle_tkip_mic_err(adapter,(u8)IS_MCAST(prxattrib->ra));
  392. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" mic error :prxattrib->bdecrypted=%d ",prxattrib->bdecrypted));
  393. DBG_871X(" mic error :prxattrib->bdecrypted=%d\n",prxattrib->bdecrypted);
  394. }
  395. else
  396. {
  397. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" mic error :prxattrib->bdecrypted=%d ",prxattrib->bdecrypted));
  398. DBG_871X(" mic error :prxattrib->bdecrypted=%d\n",prxattrib->bdecrypted);
  399. }
  400. res=_FAIL;
  401. }
  402. else{
  403. //mic checked ok
  404. if((psecuritypriv->bcheck_grpkey ==_FALSE)&&(IS_MCAST(prxattrib->ra)==_TRUE)){
  405. psecuritypriv->bcheck_grpkey =_TRUE;
  406. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("psecuritypriv->bcheck_grpkey =_TRUE"));
  407. }
  408. }
  409. }
  410. else
  411. {
  412. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
  413. }
  414. recvframe_pull_tail(precvframe, 8);
  415. }
  416. exit:
  417. _func_exit_;
  418. return res;
  419. }
  420. //decrypt and set the ivlen,icvlen of the recv_frame
  421. union recv_frame * decryptor(_adapter *padapter,union recv_frame *precv_frame);
  422. union recv_frame * decryptor(_adapter *padapter,union recv_frame *precv_frame)
  423. {
  424. struct rx_pkt_attrib *prxattrib = &precv_frame->u.hdr.attrib;
  425. struct security_priv *psecuritypriv=&padapter->securitypriv;
  426. union recv_frame *return_packet=precv_frame;
  427. u32 res=_SUCCESS;
  428. _func_enter_;
  429. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("prxstat->decrypted=%x prxattrib->encrypt = 0x%03x\n",prxattrib->bdecrypted,prxattrib->encrypt));
  430. if(prxattrib->encrypt>0)
  431. {
  432. u8 *iv = precv_frame->u.hdr.rx_data+prxattrib->hdrlen;
  433. prxattrib->key_index = ( ((iv[3])>>6)&0x3) ;
  434. if(prxattrib->key_index > WEP_KEYS)
  435. {
  436. DBG_871X("prxattrib->key_index(%d) > WEP_KEYS \n", prxattrib->key_index);
  437. switch(prxattrib->encrypt){
  438. case _WEP40_:
  439. case _WEP104_:
  440. prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
  441. break;
  442. case _TKIP_:
  443. case _AES_:
  444. default:
  445. prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
  446. break;
  447. }
  448. }
  449. }
  450. if((prxattrib->encrypt>0) && ((prxattrib->bdecrypted==0) ||(psecuritypriv->sw_decrypt==_TRUE)))
  451. {
  452. #ifdef CONFIG_CONCURRENT_MODE
  453. if(!IS_MCAST(prxattrib->ra))//bc/mc packets use sw decryption for concurrent mode
  454. #endif
  455. psecuritypriv->hw_decrypted=_FALSE;
  456. #ifdef DBG_RX_DECRYPTOR
  457. DBG_871X("prxstat->bdecrypted:%d, prxattrib->encrypt:%d, Setting psecuritypriv->hw_decrypted = %d\n"
  458. , prxattrib->bdecrypted ,prxattrib->encrypt, psecuritypriv->hw_decrypted);
  459. #endif
  460. switch(prxattrib->encrypt){
  461. case _WEP40_:
  462. case _WEP104_:
  463. rtw_wep_decrypt(padapter, (u8 *)precv_frame);
  464. break;
  465. case _TKIP_:
  466. res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
  467. break;
  468. case _AES_:
  469. res = rtw_aes_decrypt(padapter, (u8 * )precv_frame);
  470. break;
  471. #ifdef CONFIG_WAPI_SUPPORT
  472. case _SMS4_:
  473. rtw_sms4_decrypt(padapter, (u8 * )precv_frame);
  474. break;
  475. #endif
  476. default:
  477. break;
  478. }
  479. }
  480. else if(prxattrib->bdecrypted==1
  481. && prxattrib->encrypt >0
  482. && (psecuritypriv->busetkipkey==1 || prxattrib->encrypt !=_TKIP_ )
  483. )
  484. {
  485. #if 0
  486. if((prxstat->icv==1)&&(prxattrib->encrypt!=_AES_))
  487. {
  488. psecuritypriv->hw_decrypted=_FALSE;
  489. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("psecuritypriv->hw_decrypted=_FALSE"));
  490. rtw_free_recvframe(precv_frame, &padapter->recvpriv.free_recv_queue);
  491. return_packet=NULL;
  492. }
  493. else
  494. #endif
  495. {
  496. psecuritypriv->hw_decrypted=_TRUE;
  497. #ifdef DBG_RX_DECRYPTOR
  498. DBG_871X("prxstat->bdecrypted:%d, prxattrib->encrypt:%d, Setting psecuritypriv->hw_decrypted = %d\n"
  499. , prxattrib->bdecrypted ,prxattrib->encrypt, psecuritypriv->hw_decrypted);
  500. #endif
  501. }
  502. }
  503. else {
  504. #ifdef DBG_RX_DECRYPTOR
  505. DBG_871X("prxstat->bdecrypted:%d, prxattrib->encrypt:%d, psecuritypriv->hw_decrypted:%d\n"
  506. , prxattrib->bdecrypted ,prxattrib->encrypt, psecuritypriv->hw_decrypted);
  507. #endif
  508. }
  509. if(res == _FAIL)
  510. {
  511. rtw_free_recvframe(return_packet,&padapter->recvpriv.free_recv_queue);
  512. return_packet = NULL;
  513. }
  514. //recvframe_chkmic(adapter, precv_frame); //move to recvframme_defrag function
  515. _func_exit_;
  516. return return_packet;
  517. }
  518. //###set the security information in the recv_frame
  519. union recv_frame * portctrl(_adapter *adapter,union recv_frame * precv_frame);
  520. union recv_frame * portctrl(_adapter *adapter,union recv_frame * precv_frame)
  521. {
  522. u8 *psta_addr, *ptr;
  523. uint auth_alg;
  524. struct recv_frame_hdr *pfhdr;
  525. struct sta_info *psta;
  526. struct sta_priv *pstapriv ;
  527. union recv_frame *prtnframe;
  528. u16 ether_type=0;
  529. u16 eapol_type = 0x888e;//for Funia BD's WPA issue
  530. struct rx_pkt_attrib *pattrib;
  531. _func_enter_;
  532. pstapriv = &adapter->stapriv;
  533. psta = rtw_get_stainfo(pstapriv, psta_addr);
  534. auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
  535. ptr = get_recvframe_data(precv_frame);
  536. pfhdr = &precv_frame->u.hdr;
  537. pattrib = &pfhdr->attrib;
  538. psta_addr = pattrib->ta;
  539. prtnframe = NULL;
  540. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n",adapter->securitypriv.dot11AuthAlgrthm));
  541. if(auth_alg==2)
  542. {
  543. if ((psta!=NULL) && (psta->ieee8021x_blocked))
  544. {
  545. //blocked
  546. //only accept EAPOL frame
  547. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("########portctrl:psta->ieee8021x_blocked==1\n"));
  548. prtnframe=precv_frame;
  549. //get ether_type
  550. ptr=ptr+pfhdr->attrib.hdrlen+pfhdr->attrib.iv_len+LLC_HEADER_SIZE;
  551. _rtw_memcpy(&ether_type,ptr, 2);
  552. ether_type= ntohs((unsigned short )ether_type);
  553. if (ether_type == eapol_type) {
  554. prtnframe=precv_frame;
  555. }
  556. else {
  557. //free this frame
  558. rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
  559. prtnframe=NULL;
  560. }
  561. }
  562. else
  563. {
  564. //allowed
  565. //check decryption status, and decrypt the frame if needed
  566. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("########portctrl:psta->ieee8021x_blocked==0\n"));
  567. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("portctrl:precv_frame->hdr.attrib.privacy=%x\n",precv_frame->u.hdr.attrib.privacy));
  568. if (pattrib->bdecrypted == 0)
  569. {
  570. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("portctrl:prxstat->decrypted=%x\n", pattrib->bdecrypted));
  571. }
  572. prtnframe=precv_frame;
  573. //check is the EAPOL frame or not (Rekey)
  574. if(ether_type == eapol_type){
  575. RT_TRACE(_module_rtl871x_recv_c_,_drv_notice_,("########portctrl:ether_type == 0x888e\n"));
  576. //check Rekey
  577. prtnframe=precv_frame;
  578. }
  579. else{
  580. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("########portctrl:ether_type=0x%04x\n", ether_type));
  581. }
  582. }
  583. }
  584. else
  585. {
  586. prtnframe=precv_frame;
  587. }
  588. _func_exit_;
  589. return prtnframe;
  590. }
  591. sint recv_decache(union recv_frame *precv_frame, u8 bretry, struct stainfo_rxcache *prxcache);
  592. sint recv_decache(union recv_frame *precv_frame, u8 bretry, struct stainfo_rxcache *prxcache)
  593. {
  594. sint tid = precv_frame->u.hdr.attrib.priority;
  595. u16 seq_ctrl = ( (precv_frame->u.hdr.attrib.seq_num&0xffff) << 4) |
  596. (precv_frame->u.hdr.attrib.frag_num & 0xf);
  597. _func_enter_;
  598. if(tid>15)
  599. {
  600. RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid));
  601. return _FAIL;
  602. }
  603. if(1)//if(bretry)
  604. {
  605. if(seq_ctrl == prxcache->tid_rxseq[tid])
  606. {
  607. RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, seq_ctrl=0x%x, tid=0x%x, tid_rxseq=0x%x\n", seq_ctrl, tid, prxcache->tid_rxseq[tid]));
  608. return _FAIL;
  609. }
  610. }
  611. prxcache->tid_rxseq[tid] = seq_ctrl;
  612. _func_exit_;
  613. return _SUCCESS;
  614. }
  615. void process_pwrbit_data(_adapter *padapter, union recv_frame *precv_frame);
  616. void process_pwrbit_data(_adapter *padapter, union recv_frame *precv_frame)
  617. {
  618. #ifdef CONFIG_AP_MODE
  619. unsigned char pwrbit;
  620. u8 *ptr = precv_frame->u.hdr.rx_data;
  621. struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
  622. struct sta_priv *pstapriv = &padapter->stapriv;
  623. struct sta_info *psta=NULL;
  624. psta = rtw_get_stainfo(pstapriv, pattrib->src);
  625. pwrbit = GetPwrMgt(ptr);
  626. if(psta)
  627. {
  628. if(pwrbit)
  629. {
  630. if(!(psta->state & WIFI_SLEEP_STATE))
  631. {
  632. //psta->state |= WIFI_SLEEP_STATE;
  633. //pstapriv->sta_dz_bitmap |= BIT(psta->aid);
  634. stop_sta_xmit(padapter, psta);
  635. //DBG_871X("to sleep, sta_dz_bitmap=%x\n", pstapriv->sta_dz_bitmap);
  636. }
  637. }
  638. else
  639. {
  640. if(psta->state & WIFI_SLEEP_STATE)
  641. {
  642. //psta->state ^= WIFI_SLEEP_STATE;
  643. //pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
  644. wakeup_sta_to_xmit(padapter, psta);
  645. //DBG_871X("to wakeup, sta_dz_bitmap=%x\n", pstapriv->sta_dz_bitmap);
  646. }
  647. }
  648. }
  649. #endif
  650. }
  651. void process_wmmps_data(_adapter *padapter, union recv_frame *precv_frame);
  652. void process_wmmps_data(_adapter *padapter, union recv_frame *precv_frame)
  653. {
  654. #ifdef CONFIG_AP_MODE
  655. struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
  656. struct sta_priv *pstapriv = &padapter->stapriv;
  657. struct sta_info *psta=NULL;
  658. psta = rtw_get_stainfo(pstapriv, pattrib->src);
  659. if(!psta) return;
  660. #ifdef CONFIG_TDLS
  661. if( !(psta->tdls_sta_state & TDLS_LINKED_STATE ) )
  662. {
  663. #endif //CONFIG_TDLS
  664. if(!psta->qos_option)
  665. return;
  666. if(!(psta->qos_info&0xf))
  667. return;
  668. #ifdef CONFIG_TDLS
  669. }
  670. #endif //CONFIG_TDLS
  671. if(psta->state&WIFI_SLEEP_STATE)
  672. {
  673. u8 wmmps_ac=0;
  674. switch(pattrib->priority)
  675. {
  676. case 1:
  677. case 2:
  678. wmmps_ac = psta->uapsd_bk&BIT(1);
  679. break;
  680. case 4:
  681. case 5:
  682. wmmps_ac = psta->uapsd_vi&BIT(1);
  683. break;
  684. case 6:
  685. case 7:
  686. wmmps_ac = psta->uapsd_vo&BIT(1);
  687. break;
  688. case 0:
  689. case 3:
  690. default:
  691. wmmps_ac = psta->uapsd_be&BIT(1);
  692. break;
  693. }
  694. if(wmmps_ac)
  695. {
  696. if(psta->sleepq_ac_len>0)
  697. {
  698. //process received triggered frame
  699. xmit_delivery_enabled_frames(padapter, psta);
  700. }
  701. else
  702. {
  703. //issue one qos null frame with More data bit = 0 and the EOSP bit set (=1)
  704. issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0);
  705. }
  706. }
  707. }
  708. #endif
  709. }
  710. #ifdef CONFIG_TDLS
  711. sint OnTDLS(_adapter *adapter, union recv_frame *precv_frame)
  712. {
  713. struct rx_pkt_attrib *pattrib = & precv_frame->u.hdr.attrib;
  714. sint ret = _SUCCESS;
  715. u8 *paction = get_recvframe_data(precv_frame);
  716. u8 category_field = 1;
  717. #ifdef CONFIG_WFD
  718. u8 WFA_OUI[3] = { 0x50, 0x6f, 0x9a };
  719. #endif //CONFIG_WFD
  720. struct tdls_info *ptdlsinfo = &(adapter->tdlsinfo);
  721. //point to action field
  722. paction+=pattrib->hdrlen
  723. + pattrib->iv_len
  724. + SNAP_SIZE
  725. + ETH_TYPE_LEN
  726. + PAYLOAD_TYPE_LEN
  727. + category_field;
  728. if(ptdlsinfo->enable == 0)
  729. {
  730. DBG_871X("recv tdls frame, "
  731. "but tdls haven't enabled\n");
  732. ret = _FAIL;
  733. return ret;
  734. }
  735. switch(*paction){
  736. case TDLS_SETUP_REQUEST:
  737. DBG_871X("recv tdls setup request frame\n");
  738. ret=On_TDLS_Setup_Req(adapter, precv_frame);
  739. break;
  740. case TDLS_SETUP_RESPONSE:
  741. DBG_871X("recv tdls setup response frame\n");
  742. ret=On_TDLS_Setup_Rsp(adapter, precv_frame);
  743. break;
  744. case TDLS_SETUP_CONFIRM:
  745. DBG_871X("recv tdls setup confirm frame\n");
  746. ret=On_TDLS_Setup_Cfm(adapter, precv_frame);
  747. break;
  748. case TDLS_TEARDOWN:
  749. DBG_871X("recv tdls teardown, free sta_info\n");
  750. ret=On_TDLS_Teardown(adapter, precv_frame);
  751. break;
  752. case TDLS_DISCOVERY_REQUEST:
  753. DBG_871X("recv tdls discovery request frame\n");
  754. ret=On_TDLS_Dis_Req(adapter, precv_frame);
  755. break;
  756. case TDLS_PEER_TRAFFIC_RESPONSE:
  757. DBG_871X("recv tdls peer traffic response frame\n");
  758. ret=On_TDLS_Peer_Traffic_Rsp(adapter, precv_frame);
  759. break;
  760. case TDLS_CHANNEL_SWITCH_REQUEST:
  761. DBG_871X("recv tdls channel switch request frame\n");
  762. ret=On_TDLS_Ch_Switch_Req(adapter, precv_frame);
  763. break;
  764. case TDLS_CHANNEL_SWITCH_RESPONSE:
  765. DBG_871X("recv tdls channel switch response frame\n");
  766. ret=On_TDLS_Ch_Switch_Rsp(adapter, precv_frame);
  767. break;
  768. #ifdef CONFIG_WFD
  769. case 0x50: //First byte of WFA OUI
  770. if( _rtw_memcmp(WFA_OUI, (paction), 3) )
  771. {
  772. if( *(paction + 3) == 0x04) //Probe request frame
  773. {
  774. //WFDTDLS: for sigma test, do not setup direct link automatically
  775. ptdlsinfo->dev_discovered = 1;
  776. DBG_871X("recv tunneled probe request frame\n");
  777. issue_tunneled_probe_rsp(adapter, precv_frame);
  778. }
  779. if( *(paction + 3) == 0x05) //Probe response frame
  780. {
  781. //WFDTDLS: for sigma test, do not setup direct link automatically
  782. ptdlsinfo->dev_discovered = 1;
  783. DBG_871X("recv tunneled probe response frame\n");
  784. }
  785. }
  786. break;
  787. #endif //CONFIG_WFD
  788. default:
  789. DBG_871X("receive TDLS frame but not supported\n");
  790. ret=_FAIL;
  791. break;
  792. }
  793. exit:
  794. return ret;
  795. }
  796. #endif
  797. void count_rx_stats(_adapter *padapter, union recv_frame *prframe, struct sta_info*sta);
  798. void count_rx_stats(_adapter *padapter, union recv_frame *prframe, struct sta_info*sta)
  799. {
  800. int sz;
  801. struct sta_info *psta = NULL;
  802. struct stainfo_stats *pstats = NULL;
  803. struct rx_pkt_attrib *pattrib = & prframe->u.hdr.attrib;
  804. struct recv_priv *precvpriv = &padapter->recvpriv;
  805. sz = get_recvframe_len(prframe);
  806. precvpriv->rx_bytes += sz;
  807. padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
  808. if( (!MacAddr_isBcst(pattrib->dst)) && (!IS_MCAST(pattrib->dst))){
  809. padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
  810. }
  811. if(sta)
  812. psta = sta;
  813. else
  814. psta = prframe->u.hdr.psta;
  815. if(psta)
  816. {
  817. pstats = &psta->sta_stats;
  818. pstats->rx_data_pkts++;
  819. pstats->rx_bytes += sz;
  820. }
  821. }
  822. sint sta2sta_data_frame(
  823. _adapter *adapter,
  824. union recv_frame *precv_frame,
  825. struct sta_info**psta
  826. );
  827. sint sta2sta_data_frame(
  828. _adapter *adapter,
  829. union recv_frame *precv_frame,
  830. struct sta_info**psta
  831. )
  832. {
  833. u8 *ptr = precv_frame->u.hdr.rx_data;
  834. sint ret = _SUCCESS;
  835. struct rx_pkt_attrib *pattrib = & precv_frame->u.hdr.attrib;
  836. struct sta_priv *pstapriv = &adapter->stapriv;
  837. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  838. u8 *mybssid = get_bssid(pmlmepriv);
  839. u8 *myhwaddr = myid(&adapter->eeprompriv);
  840. u8 * sta_addr = NULL;
  841. sint bmcast = IS_MCAST(pattrib->dst);
  842. #ifdef CONFIG_TDLS
  843. struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
  844. struct sta_info *ptdls_sta=NULL;
  845. u8 *psnap_type=ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
  846. //frame body located after [+2]: ether-type, [+1]: payload type
  847. u8 *pframe_body = psnap_type+2+1;
  848. #endif
  849. _func_enter_;
  850. if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) ||
  851. (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE))
  852. {
  853. // filter packets that SA is myself or multicast or broadcast
  854. if (_rtw_memcmp(myhwaddr, pattrib->src, ETH_ALEN)){
  855. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" SA==myself \n"));
  856. ret= _FAIL;
  857. goto exit;
  858. }
  859. if( (!_rtw_memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast) ){
  860. ret= _FAIL;
  861. goto exit;
  862. }
  863. if( _rtw_memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
  864. _rtw_memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
  865. (!_rtw_memcmp(pattrib->bssid, mybssid, ETH_ALEN)) ) {
  866. ret= _FAIL;
  867. goto exit;
  868. }
  869. sta_addr = pattrib->src;
  870. }
  871. else if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
  872. {
  873. #ifdef CONFIG_TDLS
  874. //direct link data transfer
  875. if(ptdlsinfo->setup_state == TDLS_LINKED_STATE){
  876. ptdls_sta = rtw_get_stainfo(pstapriv, pattrib->src);
  877. if(ptdls_sta==NULL)
  878. {
  879. ret=_FAIL;
  880. goto exit;
  881. }
  882. else if(ptdls_sta->tdls_sta_state&TDLS_LINKED_STATE)
  883. {
  884. //drop QoS-SubType Data, including QoS NULL, excluding QoS-Data
  885. if( (GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE )== WIFI_QOS_DATA_TYPE)
  886. {
  887. if(GetFrameSubType(ptr)&(BIT(4)|BIT(5)|BIT(6)))
  888. {
  889. DBG_871X("drop QoS-Sybtype Data\n");
  890. ret= _FAIL;
  891. goto exit;
  892. }
  893. }
  894. // filter packets that SA is myself or multicast or broadcast
  895. if (_rtw_memcmp(myhwaddr, pattrib->src, ETH_ALEN)){
  896. ret= _FAIL;
  897. goto exit;
  898. }
  899. // da should be for me
  900. if((!_rtw_memcmp(myhwaddr, pattrib->dst, ETH_ALEN))&& (!bmcast))
  901. {
  902. ret= _FAIL;
  903. goto exit;
  904. }
  905. // check BSSID
  906. if( _rtw_memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
  907. _rtw_memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
  908. (!_rtw_memcmp(pattrib->bssid, mybssid, ETH_ALEN)) )
  909. {
  910. ret= _FAIL;
  911. goto exit;
  912. }
  913. //process UAPSD tdls sta
  914. process_pwrbit_data(adapter, precv_frame);
  915. // if NULL-frame, check pwrbit
  916. if ((GetFrameSubType(ptr)) == WIFI_DATA_NULL)
  917. {
  918. //NULL-frame with pwrbit=1, buffer_STA should buffer frames for sleep_STA
  919. if(GetPwrMgt(ptr))
  920. {
  921. DBG_871X("TDLS: recv peer null frame with pwr bit 1\n");
  922. ptdls_sta->tdls_sta_state|=TDLS_PEER_SLEEP_STATE;
  923. // it would be triggered when we are off channel and receiving NULL DATA
  924. // we can confirm that peer STA is at off channel
  925. }
  926. else if(ptdls_sta->tdls_sta_state&TDLS_CH_SWITCH_ON_STATE)
  927. {
  928. if((ptdls_sta->tdls_sta_state & TDLS_PEER_AT_OFF_STATE) != TDLS_PEER_AT_OFF_STATE)
  929. {
  930. issue_nulldata_to_TDLS_peer_STA(adapter, ptdls_sta, 0);
  931. ptdls_sta->tdls_sta_state |= TDLS_PEER_AT_OFF_STATE;
  932. On_TDLS_Peer_Traffic_Rsp(adapter, precv_frame);
  933. }
  934. }
  935. ret= _FAIL;
  936. goto exit;
  937. }
  938. //receive some of all TDLS management frames, process it at ON_TDLS
  939. if((_rtw_memcmp(psnap_type, SNAP_ETH_TYPE_TDLS, 2))){
  940. ret= OnTDLS(adapter, precv_frame);
  941. goto exit;
  942. }
  943. }
  944. sta_addr = pattrib->src;
  945. }
  946. else
  947. #endif //CONFIG_TDLS
  948. {
  949. // For Station mode, sa and bssid should always be BSSID, and DA is my mac-address
  950. if(!_rtw_memcmp(pattrib->bssid, pattrib->src, ETH_ALEN) )
  951. {
  952. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("bssid != TA under STATION_MODE; drop pkt\n"));
  953. ret= _FAIL;
  954. goto exit;
  955. }
  956. sta_addr = pattrib->bssid;
  957. }
  958. }
  959. else if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  960. {
  961. if (bmcast)
  962. {
  963. // For AP mode, if DA == MCAST, then BSSID should be also MCAST
  964. if (!IS_MCAST(pattrib->bssid)){
  965. ret= _FAIL;
  966. goto exit;
  967. }
  968. }
  969. else // not mc-frame
  970. {
  971. // For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID
  972. if(!_rtw_memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN)) {
  973. ret= _FAIL;
  974. goto exit;
  975. }
  976. sta_addr = pattrib->src;
  977. }
  978. }
  979. else if(check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
  980. {
  981. _rtw_memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
  982. _rtw_memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
  983. _rtw_memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
  984. _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
  985. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  986. sta_addr = mybssid;
  987. }
  988. else
  989. {
  990. ret = _FAIL;
  991. }
  992. if(bmcast)
  993. *psta = rtw_get_bcmc_stainfo(adapter);
  994. else
  995. *psta = rtw_get_stainfo(pstapriv, sta_addr); // get ap_info
  996. #ifdef CONFIG_TDLS
  997. if(ptdls_sta != NULL)
  998. *psta = ptdls_sta;
  999. #endif //CONFIG_TDLS
  1000. if (*psta == NULL) {
  1001. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("can't get psta under sta2sta_data_frame ; drop pkt\n"));
  1002. #ifdef CONFIG_MP_INCLUDED
  1003. if (adapter->registrypriv.mp_mode == 1)
  1004. {
  1005. if(check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
  1006. adapter->mppriv.rx_pktloss++;
  1007. }
  1008. #endif
  1009. ret= _FAIL;
  1010. goto exit;
  1011. }
  1012. exit:
  1013. _func_exit_;
  1014. return ret;
  1015. }
  1016. sint ap2sta_data_frame(
  1017. _adapter *adapter,
  1018. union recv_frame *precv_frame,
  1019. struct sta_info**psta );
  1020. sint ap2sta_data_frame(
  1021. _adapter *adapter,
  1022. union recv_frame *precv_frame,
  1023. struct sta_info**psta )
  1024. {
  1025. u8 *ptr = precv_frame->u.hdr.rx_data;
  1026. struct rx_pkt_attrib *pattrib = & precv_frame->u.hdr.attrib;
  1027. sint ret = _SUCCESS;
  1028. struct sta_priv *pstapriv = &adapter->stapriv;
  1029. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  1030. u8 *mybssid = get_bssid(pmlmepriv);
  1031. u8 *myhwaddr = myid(&adapter->eeprompriv);
  1032. sint bmcast = IS_MCAST(pattrib->dst);
  1033. _func_enter_;
  1034. if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
  1035. && (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE
  1036. || check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE )
  1037. )
  1038. {
  1039. // filter packets that SA is myself or multicast or broadcast
  1040. if (_rtw_memcmp(myhwaddr, pattrib->src, ETH_ALEN)){
  1041. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" SA==myself \n"));
  1042. #ifdef DBG_RX_DROP_FRAME
  1043. DBG_871X("DBG_RX_DROP_FRAME %s SA="MAC_FMT", myhwaddr="MAC_FMT"\n",
  1044. __FUNCTION__, MAC_ARG(pattrib->src), MAC_ARG(myhwaddr));
  1045. #endif
  1046. ret= _FAIL;
  1047. goto exit;
  1048. }
  1049. // da should be for me
  1050. if((!_rtw_memcmp(myhwaddr, pattrib->dst, ETH_ALEN))&& (!bmcast))
  1051. {
  1052. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,
  1053. (" ap2sta_data_frame: compare DA fail; DA="MAC_FMT"\n", MAC_ARG(pattrib->dst)));
  1054. #ifdef DBG_RX_DROP_FRAME
  1055. DBG_871X("DBG_RX_DROP_FRAME %s DA="MAC_FMT"\n", __func__, MAC_ARG(pattrib->dst));
  1056. #endif
  1057. ret= _FAIL;
  1058. goto exit;
  1059. }
  1060. // check BSSID
  1061. if( _rtw_memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
  1062. _rtw_memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
  1063. (!_rtw_memcmp(pattrib->bssid, mybssid, ETH_ALEN)) )
  1064. {
  1065. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,
  1066. (" ap2sta_data_frame: compare BSSID fail ; BSSID="MAC_FMT"\n", MAC_ARG(pattrib->bssid)));
  1067. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("mybssid="MAC_FMT"\n", MAC_ARG(mybssid)));
  1068. #ifdef DBG_RX_DROP_FRAME
  1069. DBG_871X("DBG_RX_DROP_FRAME %s BSSID="MAC_FMT", mybssid="MAC_FMT"\n",
  1070. __FUNCTION__, MAC_ARG(pattrib->bssid), MAC_ARG(mybssid));
  1071. DBG_871X( "this adapter = %d, buddy adapter = %d\n", adapter->adapter_type, adapter->pbuddy_adapter->adapter_type );
  1072. #endif
  1073. if(!bmcast)
  1074. {
  1075. DBG_871X("issue_deauth to the nonassociated ap=" MAC_FMT " for the reason(7)\n", MAC_ARG(pattrib->bssid));
  1076. issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1077. }
  1078. ret= _FAIL;
  1079. goto exit;
  1080. }
  1081. if(bmcast)
  1082. *psta = rtw_get_bcmc_stainfo(adapter);
  1083. else
  1084. *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); // get ap_info
  1085. if (*psta == NULL) {
  1086. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
  1087. #ifdef DBG_RX_DROP_FRAME
  1088. DBG_871X("DBG_RX_DROP_FRAME %s can't get psta under STATION_MODE ; drop pkt\n", __FUNCTION__);
  1089. #endif
  1090. ret= _FAIL;
  1091. goto exit;
  1092. }
  1093. if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) {
  1094. }
  1095. if (GetFrameSubType(ptr) & BIT(6)) {
  1096. /* No data, will not indicate to upper layer, temporily count it here */
  1097. count_rx_stats(adapter, precv_frame, *psta);
  1098. ret = RTW_RX_HANDLED;
  1099. goto exit;
  1100. }
  1101. }
  1102. else if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE) &&
  1103. (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) )
  1104. {
  1105. _rtw_memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
  1106. _rtw_memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
  1107. _rtw_memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
  1108. _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
  1109. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  1110. //
  1111. _rtw_memcpy(pattrib->bssid, mybssid, ETH_ALEN);
  1112. *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); // get sta_info
  1113. if (*psta == NULL) {
  1114. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("can't get psta under MP_MODE ; drop pkt\n"));
  1115. #ifdef DBG_RX_DROP_FRAME
  1116. DBG_871X("DBG_RX_DROP_FRAME %s can't get psta under WIFI_MP_STATE ; drop pkt\n", __FUNCTION__);
  1117. #endif
  1118. ret= _FAIL;
  1119. goto exit;
  1120. }
  1121. }
  1122. else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1123. {
  1124. /* Special case */
  1125. ret = RTW_RX_HANDLED;
  1126. goto exit;
  1127. }
  1128. else
  1129. {
  1130. if(_rtw_memcmp(myhwaddr, pattrib->dst, ETH_ALEN)&& (!bmcast))
  1131. {
  1132. *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); // get sta_info
  1133. if (*psta == NULL)
  1134. {
  1135. DBG_871X("issue_deauth to the ap=" MAC_FMT " for the reason(7)\n", MAC_ARG(pattrib->bssid));
  1136. issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1137. }
  1138. }
  1139. ret = _FAIL;
  1140. #ifdef DBG_RX_DROP_FRAME
  1141. DBG_871X("DBG_RX_DROP_FRAME %s fw_state:0x%x\n", __FUNCTION__, get_fwstate(pmlmepriv));
  1142. #endif
  1143. }
  1144. exit:
  1145. _func_exit_;
  1146. return ret;
  1147. }
  1148. sint sta2ap_data_frame(
  1149. _adapter *adapter,
  1150. union recv_frame *precv_frame,
  1151. struct sta_info**psta );
  1152. sint sta2ap_data_frame(
  1153. _adapter *adapter,
  1154. union recv_frame *precv_frame,
  1155. struct sta_info**psta )
  1156. {
  1157. u8 *ptr = precv_frame->u.hdr.rx_data;
  1158. struct rx_pkt_attrib *pattrib = & precv_frame->u.hdr.attrib;
  1159. struct sta_priv *pstapriv = &adapter->stapriv;
  1160. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  1161. unsigned char *mybssid = get_bssid(pmlmepriv);
  1162. sint ret=_SUCCESS;
  1163. _func_enter_;
  1164. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1165. {
  1166. //For AP mode, RA=BSSID, TX=STA(SRC_ADDR), A3=DST_ADDR
  1167. if(!_rtw_memcmp(pattrib->bssid, mybssid, ETH_ALEN))
  1168. {
  1169. ret= _FAIL;
  1170. goto exit;
  1171. }
  1172. *psta = rtw_get_stainfo(pstapriv, pattrib->src);
  1173. if (*psta == NULL)
  1174. {
  1175. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("can't get psta under AP_MODE; drop pkt\n"));
  1176. DBG_871X("issue_deauth to sta=" MAC_FMT " for the reason(7)\n", MAC_ARG(pattrib->src));
  1177. issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1178. ret = RTW_RX_HANDLED;
  1179. goto exit;
  1180. }
  1181. process_pwrbit_data(adapter, precv_frame);
  1182. if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) {
  1183. process_wmmps_data(adapter, precv_frame);
  1184. }
  1185. if (GetFrameSubType(ptr) & BIT(6)) {
  1186. /* No data, will not indicate to upper layer, temporily count it here */
  1187. count_rx_stats(adapter, precv_frame, *psta);
  1188. ret = RTW_RX_HANDLED;
  1189. goto exit;
  1190. }
  1191. }
  1192. else {
  1193. u8 *myhwaddr = myid(&adapter->eeprompriv);
  1194. if (!_rtw_memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
  1195. ret = RTW_RX_HANDLED;
  1196. goto exit;
  1197. }
  1198. DBG_871X("issue_deauth to sta=" MAC_FMT " for the reason(7)\n", MAC_ARG(pattrib->src));
  1199. issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1200. ret = RTW_RX_HANDLED;
  1201. goto exit;
  1202. }
  1203. exit:
  1204. _func_exit_;
  1205. return ret;
  1206. }
  1207. sint validate_recv_ctrl_frame(_adapter *padapter, union recv_frame *precv_frame);
  1208. sint validate_recv_ctrl_frame(_adapter *padapter, union recv_frame *precv_frame)
  1209. {
  1210. #ifdef CONFIG_AP_MODE
  1211. struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
  1212. struct sta_priv *pstapriv = &padapter->stapriv;
  1213. u8 *pframe = precv_frame->u.hdr.rx_data;
  1214. //uint len = precv_frame->u.hdr.len;
  1215. //DBG_871X("+validate_recv_ctrl_frame\n");
  1216. if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
  1217. {
  1218. return _FAIL;
  1219. }
  1220. //receive the frames that ra(a1) is my address
  1221. if (!_rtw_memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN))
  1222. {
  1223. return _FAIL;
  1224. }
  1225. //only handle ps-poll
  1226. if(GetFrameSubType(pframe) == WIFI_PSPOLL)
  1227. {
  1228. u16 aid;
  1229. u8 wmmps_ac=0;
  1230. struct sta_info *psta=NULL;
  1231. aid = GetAid(pframe);
  1232. psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
  1233. if((psta==NULL) || (psta->aid!=aid))
  1234. {
  1235. return _FAIL;
  1236. }
  1237. //for rx pkt statistics
  1238. psta->sta_stats.rx_ctrl_pkts++;
  1239. switch(pattrib->priority)
  1240. {
  1241. case 1:
  1242. case 2:
  1243. wmmps_ac = psta->uapsd_bk&BIT(0);
  1244. break;
  1245. case 4:
  1246. case 5:
  1247. wmmps_ac = psta->uapsd_vi&BIT(0);
  1248. break;
  1249. case 6:
  1250. case 7:
  1251. wmmps_ac = psta->uapsd_vo&BIT(0);
  1252. break;
  1253. case 0:
  1254. case 3:
  1255. default:
  1256. wmmps_ac = psta->uapsd_be&BIT(0);
  1257. break;
  1258. }
  1259. if(wmmps_ac)
  1260. return _FAIL;
  1261. if(psta->state & WIFI_STA_ALIVE_CHK_STATE)
  1262. {
  1263. DBG_871X("%s alive check-rx ps-poll\n", __func__);
  1264. psta->expire_to = pstapriv->expire_to;
  1265. psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
  1266. }
  1267. if((psta->state&WIFI_SLEEP_STATE) && (pstapriv->sta_dz_bitmap&BIT(psta->aid)))
  1268. {
  1269. _irqL irqL;
  1270. _list *xmitframe_plist, *xmitframe_phead;
  1271. struct xmit_frame *pxmitframe=NULL;
  1272. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1273. //_enter_critical_bh(&psta->sleep_q.lock, &irqL);
  1274. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  1275. xmitframe_phead = get_list_head(&psta->sleep_q);
  1276. xmitframe_plist = get_next(xmitframe_phead);
  1277. if ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE)
  1278. {
  1279. pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
  1280. xmitframe_plist = get_next(xmitframe_plist);
  1281. rtw_list_delete(&pxmitframe->list);
  1282. psta->sleepq_len--;
  1283. if(psta->sleepq_len>0)
  1284. pxmitframe->attrib.mdata = 1;
  1285. else
  1286. pxmitframe->attrib.mdata = 0;
  1287. pxmitframe->attrib.triggered = 1;
  1288. //DBG_871X("handling ps-poll, q_len=%d, tim=%x\n", psta->sleepq_len, pstapriv->tim_bitmap);
  1289. #if 0
  1290. _exit_critical_bh(&psta->sleep_q.lock, &irqL);
  1291. if(rtw_hal_xmit(padapter, pxmitframe) == _TRUE)
  1292. {
  1293. rtw_os_xmit_complete(padapter, pxmitframe);
  1294. }
  1295. _enter_critical_bh(&psta->sleep_q.lock, &irqL);
  1296. #endif
  1297. rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
  1298. if(psta->sleepq_len==0)
  1299. {
  1300. pstapriv->tim_bitmap &= ~BIT(psta->aid);
  1301. //DBG_871X("after handling ps-poll, tim=%x\n", pstapriv->tim_bitmap);
  1302. //upate BCN for TIM IE
  1303. //update_BCNTIM(padapter);
  1304. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  1305. }
  1306. //_exit_critical_bh(&psta->sleep_q.lock, &irqL);
  1307. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  1308. }
  1309. else
  1310. {
  1311. //_exit_critical_bh(&psta->sleep_q.lock, &irqL);
  1312. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  1313. //DBG_871X("no buffered packets to xmit\n");
  1314. if(pstapriv->tim_bitmap&BIT(psta->aid))
  1315. {
  1316. if(psta->sleepq_len==0)
  1317. {
  1318. DBG_871X("no buffered packets to xmit\n");
  1319. //issue nulldata with More data bit = 0 to indicate we have no buffered packets
  1320. issue_nulldata(padapter, psta->hwaddr, 0, 0, 0);
  1321. }
  1322. else
  1323. {
  1324. DBG_871X("error!psta->sleepq_len=%d\n", psta->sleepq_len);
  1325. psta->sleepq_len=0;
  1326. }
  1327. pstapriv->tim_bitmap &= ~BIT(psta->aid);
  1328. //upate BCN for TIM IE
  1329. //update_BCNTIM(padapter);
  1330. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  1331. }
  1332. }
  1333. }
  1334. }
  1335. #endif
  1336. return _FAIL;
  1337. }
  1338. union recv_frame* recvframe_chk_defrag(PADAPTER padapter, union recv_frame *precv_frame);
  1339. sint validate_recv_mgnt_frame(PADAPTER padapter, union recv_frame *precv_frame);
  1340. sint validate_recv_mgnt_frame(PADAPTER padapter, union recv_frame *precv_frame)
  1341. {
  1342. //struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  1343. RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("+validate_recv_mgnt_frame\n"));
  1344. #if 0
  1345. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1346. {
  1347. #ifdef CONFIG_NATIVEAP_MLME
  1348. mgt_dispatcher(padapter, precv_frame);
  1349. #else
  1350. rtw_hostapd_mlme_rx(padapter, precv_frame);
  1351. #endif
  1352. }
  1353. else
  1354. {
  1355. mgt_dispatcher(padapter, precv_frame);
  1356. }
  1357. #endif
  1358. precv_frame = recvframe_chk_defrag(padapter, precv_frame);
  1359. if (precv_frame == NULL) {
  1360. RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,("%s: fragment packet\n",__FUNCTION__));
  1361. return _SUCCESS;
  1362. }
  1363. {
  1364. //for rx pkt statistics
  1365. struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(precv_frame->u.hdr.rx_data));
  1366. if (psta) {
  1367. psta->sta_stats.rx_mgnt_pkts++;
  1368. if (GetFrameSubType(precv_frame->u.hdr.rx_data) == WIFI_BEACON)
  1369. psta->sta_stats.rx_beacon_pkts++;
  1370. else if (GetFrameSubType(precv_frame->u.hdr.rx_data) == WIFI_PROBEREQ)
  1371. psta->sta_stats.rx_probereq_pkts++;
  1372. else if (GetFrameSubType(precv_frame->u.hdr.rx_data) == WIFI_PROBERSP) {
  1373. if (_rtw_memcmp(padapter->eeprompriv.mac_addr, GetAddr1Ptr(precv_frame->u.hdr.rx_data), ETH_ALEN) == _TRUE)
  1374. psta->sta_stats.rx_probersp_pkts++;
  1375. else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->u.hdr.rx_data))
  1376. || is_multicast_mac_addr(GetAddr1Ptr(precv_frame->u.hdr.rx_data)))
  1377. psta->sta_stats.rx_probersp_bm_pkts++;
  1378. else
  1379. psta->sta_stats.rx_probersp_uo_pkts++;
  1380. }
  1381. }
  1382. }
  1383. #ifdef CONFIG_INTEL_PROXIM
  1384. if(padapter->proximity.proxim_on==_TRUE)
  1385. {
  1386. struct rx_pkt_attrib * pattrib=&precv_frame->u.hdr.attrib;
  1387. struct recv_stat* prxstat=( struct recv_stat * ) precv_frame->u.hdr.rx_head ;
  1388. u8 * pda,*psa,*pbssid,*ptr;
  1389. ptr=precv_frame->u.hdr.rx_data;
  1390. pda = get_da(ptr);
  1391. psa = get_sa(ptr);
  1392. pbssid = get_hdr_bssid(ptr);
  1393. _rtw_memcpy(pattrib->dst, pda, ETH_ALEN);
  1394. _rtw_memcpy(pattrib->src, psa, ETH_ALEN);
  1395. _rtw_memcpy(pattrib->bssid, pbssid, ETH_ALEN);
  1396. switch(pattrib->to_fr_ds)
  1397. {
  1398. case 0:
  1399. _rtw_memcpy(pattrib->ra, pda, ETH_ALEN);
  1400. _rtw_memcpy(pattrib->ta, psa, ETH_ALEN);
  1401. break;
  1402. case 1:
  1403. _rtw_memcpy(pattrib->ra, pda, ETH_ALEN);
  1404. _rtw_memcpy(pattrib->ta, pbssid, ETH_ALEN);
  1405. break;
  1406. case 2:
  1407. _rtw_memcpy(pattrib->ra, pbssid, ETH_ALEN);
  1408. _rtw_memcpy(pattrib->ta, psa, ETH_ALEN);
  1409. break;
  1410. case 3:
  1411. _rtw_memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
  1412. _rtw_memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
  1413. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" case 3\n"));
  1414. break;
  1415. default:
  1416. break;
  1417. }
  1418. pattrib->priority=0;
  1419. pattrib->hdrlen = pattrib->to_fr_ds==3 ? 30 : 24;
  1420. padapter->proximity.proxim_rx(padapter,precv_frame);
  1421. }
  1422. #endif
  1423. mgt_dispatcher(padapter, precv_frame);
  1424. return _SUCCESS;
  1425. }
  1426. sint validate_recv_data_frame(_adapter *adapter, union recv_frame *precv_frame);
  1427. sint validate_recv_data_frame(_adapter *adapter, union recv_frame *precv_frame)
  1428. {
  1429. u8 bretry;
  1430. u8 *psa, *pda, *pbssid;
  1431. struct sta_info *psta = NULL;
  1432. u8 *ptr = precv_frame->u.hdr.rx_data;
  1433. struct rx_pkt_attrib *pattrib = & precv_frame->u.hdr.attrib;
  1434. struct sta_priv *pstapriv = &adapter->stapriv;
  1435. struct security_priv *psecuritypriv = &adapter->securitypriv;
  1436. sint ret = _SUCCESS;
  1437. #ifdef CONFIG_TDLS
  1438. struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
  1439. #endif //CONFIG_TDLS
  1440. _func_enter_;
  1441. bretry = GetRetry(ptr);
  1442. pda = get_da(ptr);
  1443. psa = get_sa(ptr);
  1444. pbssid = get_hdr_bssid(ptr);
  1445. if(pbssid == NULL){
  1446. #ifdef DBG_RX_DROP_FRAME
  1447. DBG_871X("DBG_RX_DROP_FRAME %s pbssid == NULL\n", __func__);
  1448. #endif
  1449. ret= _FAIL;
  1450. goto exit;
  1451. }
  1452. _rtw_memcpy(pattrib->dst, pda, ETH_ALEN);
  1453. _rtw_memcpy(pattrib->src, psa, ETH_ALEN);
  1454. _rtw_memcpy(pattrib->bssid, pbssid, ETH_ALEN);
  1455. switch(pattrib->to_fr_ds)
  1456. {
  1457. case 0:
  1458. _rtw_memcpy(pattrib->ra, pda, ETH_ALEN);
  1459. _rtw_memcpy(pattrib->ta, psa, ETH_ALEN);
  1460. ret = sta2sta_data_frame(adapter, precv_frame, &psta);
  1461. break;
  1462. case 1:
  1463. _rtw_memcpy(pattrib->ra, pda, ETH_ALEN);
  1464. _rtw_memcpy(pattrib->ta, pbssid, ETH_ALEN);
  1465. ret = ap2sta_data_frame(adapter, precv_frame, &psta);
  1466. break;
  1467. case 2:
  1468. _rtw_memcpy(pattrib->ra, pbssid, ETH_ALEN);
  1469. _rtw_memcpy(pattrib->ta, psa, ETH_ALEN);
  1470. ret = sta2ap_data_frame(adapter, precv_frame, &psta);
  1471. break;
  1472. case 3:
  1473. _rtw_memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
  1474. _rtw_memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
  1475. ret =_FAIL;
  1476. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" case 3\n"));
  1477. break;
  1478. default:
  1479. ret =_FAIL;
  1480. break;
  1481. }
  1482. if(ret ==_FAIL){
  1483. #ifdef DBG_RX_DROP_FRAME
  1484. DBG_871X("DBG_RX_DROP_FRAME %s case:%d, res:%d\n", __FUNCTION__, pattrib->to_fr_ds, ret);
  1485. #endif
  1486. goto exit;
  1487. } else if (ret == RTW_RX_HANDLED) {
  1488. goto exit;
  1489. }
  1490. if(psta==NULL){
  1491. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" after to_fr_ds_chk; psta==NULL \n"));
  1492. #ifdef DBG_RX_DROP_FRAME
  1493. DBG_871X("DBG_RX_DROP_FRAME %s psta == NULL\n", __func__);
  1494. #endif
  1495. ret= _FAIL;
  1496. goto exit;
  1497. }
  1498. //psta->rssi = prxcmd->rssi;
  1499. //psta->signal_quality= prxcmd->sq;
  1500. precv_frame->u.hdr.psta = psta;
  1501. pattrib->amsdu=0;
  1502. pattrib->ack_policy = 0;
  1503. //parsing QC field
  1504. if(pattrib->qos == 1)
  1505. {
  1506. pattrib->priority = GetPriority((ptr + 24));
  1507. pattrib->ack_policy = GetAckpolicy((ptr + 24));
  1508. pattrib->amsdu = GetAMsdu((ptr + 24));
  1509. pattrib->hdrlen = pattrib->to_fr_ds==3 ? 32 : 26;
  1510. if(pattrib->priority!=0 && pattrib->priority!=3)
  1511. {
  1512. adapter->recvpriv.bIsAnyNonBEPkts = _TRUE;
  1513. }
  1514. }
  1515. else
  1516. {
  1517. pattrib->priority=0;
  1518. pattrib->hdrlen = pattrib->to_fr_ds==3 ? 30 : 24;
  1519. }
  1520. if(pattrib->order)//HT-CTRL 11n
  1521. {
  1522. pattrib->hdrlen += 4;
  1523. }
  1524. precv_frame->u.hdr.preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
  1525. // decache, drop duplicate recv packets
  1526. if(recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL)
  1527. {
  1528. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("decache : drop pkt\n"));
  1529. #ifdef DBG_RX_DROP_FRAME
  1530. DBG_871X("DBG_RX_DROP_FRAME %s recv_decache return _FAIL\n", __func__);
  1531. #endif
  1532. ret= _FAIL;
  1533. goto exit;
  1534. }
  1535. #if 0
  1536. if(psta->tdls_sta_state & TDLS_LINKED_STATE )
  1537. {
  1538. if(psta->dot118021XPrivacy==_AES_)
  1539. pattrib->encrypt=psta->dot118021XPrivacy;
  1540. }
  1541. #endif //CONFIG_TDLS
  1542. if(pattrib->privacy){
  1543. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("validate_recv_data_frame:pattrib->privacy=%x\n", pattrib->privacy));
  1544. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n ^^^^^^^^^^^IS_MCAST(pattrib->ra(0x%02x))=%d^^^^^^^^^^^^^^^6\n", pattrib->ra[0],IS_MCAST(pattrib->ra)));
  1545. #ifdef CONFIG_TDLS
  1546. if((psta->tdls_sta_state & TDLS_LINKED_STATE) && (psta->dot118021XPrivacy==_AES_))
  1547. {
  1548. pattrib->encrypt=psta->dot118021XPrivacy;
  1549. }
  1550. else
  1551. #endif //CONFIG_TDLS
  1552. GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra));
  1553. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n pattrib->encrypt=%d\n",pattrib->encrypt));
  1554. SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
  1555. }
  1556. else
  1557. {
  1558. pattrib->encrypt = 0;
  1559. pattrib->iv_len = pattrib->icv_len = 0;
  1560. }
  1561. exit:
  1562. _func_exit_;
  1563. return ret;
  1564. }
  1565. sint validate_recv_frame(_adapter *adapter, union recv_frame *precv_frame);
  1566. sint validate_recv_frame(_adapter *adapter, union recv_frame *precv_frame)
  1567. {
  1568. //shall check frame subtype, to / from ds, da, bssid
  1569. //then call check if rx seq/frag. duplicated.
  1570. u8 type;
  1571. u8 subtype;
  1572. sint retval = _SUCCESS;
  1573. struct rx_pkt_attrib *pattrib = & precv_frame->u.hdr.attrib;
  1574. u8 *ptr = precv_frame->u.hdr.rx_data;
  1575. u8 ver =(unsigned char) (*ptr)&0x3 ;
  1576. #ifdef CONFIG_FIND_BEST_CHANNEL
  1577. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  1578. #endif
  1579. #ifdef CONFIG_TDLS
  1580. struct tdls_info *ptdlsinfo = &adapter->tdlsinfo;
  1581. #endif //CONFIG_TDLS
  1582. #ifdef CONFIG_WAPI_SUPPORT
  1583. PRT_WAPI_T pWapiInfo = &adapter->wapiInfo;
  1584. struct recv_frame_hdr *phdr = &precv_frame->u.hdr;
  1585. u8 wai_pkt = 0;
  1586. u16 sc;
  1587. u8 external_len = 0;
  1588. #endif
  1589. _func_enter_;
  1590. #ifdef CONFIG_FIND_BEST_CHANNEL
  1591. if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
  1592. int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
  1593. if (ch_set_idx >= 0)
  1594. pmlmeext->channel_set[ch_set_idx].rx_count++;
  1595. }
  1596. #endif
  1597. #ifdef CONFIG_TDLS
  1598. if(ptdlsinfo->ch_sensing==1 && ptdlsinfo->cur_channel !=0){
  1599. ptdlsinfo->collect_pkt_num[ptdlsinfo->cur_channel-1]++;
  1600. }
  1601. #endif //CONFIG_TDLS
  1602. #ifdef RTK_DMP_PLATFORM
  1603. if ( 0 )
  1604. {
  1605. DBG_871X("++\n");
  1606. {
  1607. int i;
  1608. for(i=0; i<64;i=i+8)
  1609. DBG_871X("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:", *(ptr+i),
  1610. *(ptr+i+1), *(ptr+i+2) ,*(ptr+i+3) ,*(ptr+i+4),*(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
  1611. }
  1612. DBG_871X("--\n");
  1613. }
  1614. #endif //RTK_DMP_PLATFORM
  1615. //add version chk
  1616. if(ver!=0){
  1617. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("validate_recv_data_frame fail! (ver!=0)\n"));
  1618. retval= _FAIL;
  1619. goto exit;
  1620. }
  1621. type = GetFrameType(ptr);
  1622. subtype = GetFrameSubType(ptr); //bit(7)~bit(2)
  1623. pattrib->to_fr_ds = get_tofr_ds(ptr);
  1624. pattrib->frag_num = GetFragNum(ptr);
  1625. pattrib->seq_num = GetSequence(ptr);
  1626. pattrib->pw_save = GetPwrMgt(ptr);
  1627. pattrib->mfrag = GetMFrag(ptr);
  1628. pattrib->mdata = GetMData(ptr);
  1629. pattrib->privacy = GetPrivacy(ptr);
  1630. pattrib->order = GetOrder(ptr);
  1631. #ifdef CONFIG_WAPI_SUPPORT
  1632. sc = (pattrib->seq_num<<4) | pattrib->frag_num;
  1633. #endif
  1634. #if 1 //Dump rx packets
  1635. {
  1636. u8 bDumpRxPkt;
  1637. rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
  1638. if(bDumpRxPkt ==1){//dump all rx packets
  1639. int i;
  1640. DBG_871X("############################# \n");
  1641. for(i=0; i<64;i=i+8)
  1642. DBG_871X("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
  1643. *(ptr+i+1), *(ptr+i+2) ,*(ptr+i+3) ,*(ptr+i+4),*(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
  1644. DBG_871X("############################# \n");
  1645. }
  1646. else if(bDumpRxPkt ==2){
  1647. if(type== WIFI_MGT_TYPE){
  1648. int i;
  1649. DBG_871X("############################# \n");
  1650. for(i=0; i<64;i=i+8)
  1651. DBG_871X("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
  1652. *(ptr+i+1), *(ptr+i+2) ,*(ptr+i+3) ,*(ptr+i+4),*(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
  1653. DBG_871X("############################# \n");
  1654. }
  1655. }
  1656. else if(bDumpRxPkt ==3){
  1657. if(type== WIFI_DATA_TYPE){
  1658. int i;
  1659. DBG_871X("############################# \n");
  1660. for(i=0; i<64;i=i+8)
  1661. DBG_871X("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
  1662. *(ptr+i+1), *(ptr+i+2) ,*(ptr+i+3) ,*(ptr+i+4),*(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
  1663. DBG_871X("############################# \n");
  1664. }
  1665. }
  1666. }
  1667. #endif
  1668. switch (type)
  1669. {
  1670. case WIFI_MGT_TYPE: //mgnt
  1671. retval = validate_recv_mgnt_frame(adapter, precv_frame);
  1672. if (retval == _FAIL)
  1673. {
  1674. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("validate_recv_mgnt_frame fail\n"));
  1675. }
  1676. retval = _FAIL; // only data frame return _SUCCESS
  1677. break;
  1678. case WIFI_CTRL_TYPE: //ctrl
  1679. retval = validate_recv_ctrl_frame(adapter, precv_frame);
  1680. if (retval == _FAIL)
  1681. {
  1682. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("validate_recv_ctrl_frame fail\n"));
  1683. }
  1684. retval = _FAIL; // only data frame return _SUCCESS
  1685. break;
  1686. case WIFI_DATA_TYPE: //data
  1687. #ifdef CONFIG_WAPI_SUPPORT
  1688. if(pattrib->qos)
  1689. external_len = 2;
  1690. else
  1691. external_len= 0;
  1692. wai_pkt = rtw_wapi_is_wai_packet(adapter,ptr);
  1693. phdr->bIsWaiPacket = wai_pkt;
  1694. if(wai_pkt !=0){
  1695. if(sc != adapter->wapiInfo.wapiSeqnumAndFragNum)
  1696. {
  1697. adapter->wapiInfo.wapiSeqnumAndFragNum = sc;
  1698. }
  1699. else
  1700. {
  1701. retval = _FAIL;
  1702. break;
  1703. }
  1704. }
  1705. else{
  1706. if(rtw_wapi_drop_for_key_absent(adapter,GetAddr2Ptr(ptr))){
  1707. retval=_FAIL;
  1708. WAPI_TRACE(WAPI_RX,"drop for key absent for rx \n");
  1709. break;
  1710. }
  1711. }
  1712. #endif
  1713. pattrib->qos = (subtype & BIT(7))? 1:0;
  1714. retval = validate_recv_data_frame(adapter, precv_frame);
  1715. if (retval == _FAIL)
  1716. {
  1717. struct recv_priv *precvpriv = &adapter->recvpriv;
  1718. //RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("validate_recv_data_frame fail\n"));
  1719. precvpriv->rx_drop++;
  1720. }
  1721. break;
  1722. default:
  1723. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("validate_recv_data_frame fail! type=0x%x\n", type));
  1724. #ifdef DBG_RX_DROP_FRAME
  1725. DBG_871X("DBG_RX_DROP_FRAME validate_recv_data_frame fail! type=0x%x\n", type);
  1726. #endif
  1727. retval = _FAIL;
  1728. break;
  1729. }
  1730. exit:
  1731. _func_exit_;
  1732. return retval;
  1733. }
  1734. //remove the wlanhdr and add the eth_hdr
  1735. #if 1
  1736. sint wlanhdr_to_ethhdr ( union recv_frame *precvframe);
  1737. sint wlanhdr_to_ethhdr ( union recv_frame *precvframe)
  1738. {
  1739. sint rmv_len;
  1740. u16 eth_type, len;
  1741. u8 bsnaphdr;
  1742. u8 *psnap_type;
  1743. struct ieee80211_snap_hdr *psnap;
  1744. sint ret=_SUCCESS;
  1745. _adapter *adapter =precvframe->u.hdr.adapter;
  1746. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  1747. u8 *ptr = get_recvframe_data(precvframe) ; // point to frame_ctrl field
  1748. struct rx_pkt_attrib *pattrib = & precvframe->u.hdr.attrib;
  1749. _func_enter_;
  1750. if(pattrib->encrypt){
  1751. recvframe_pull_tail(precvframe, pattrib->icv_len);
  1752. }
  1753. psnap=(struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
  1754. psnap_type=ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
  1755. /* convert hdr + possible LLC headers into Ethernet header */
  1756. //eth_type = (psnap_type[0] << 8) | psnap_type[1];
  1757. if((_rtw_memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
  1758. (_rtw_memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) == _FALSE) &&
  1759. (_rtw_memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2)==_FALSE) )||
  1760. //eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
  1761. _rtw_memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)){
  1762. /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
  1763. bsnaphdr = _TRUE;
  1764. }
  1765. else {
  1766. /* Leave Ethernet header part of hdr and full payload */
  1767. bsnaphdr = _FALSE;
  1768. }
  1769. rmv_len = pattrib->hdrlen + pattrib->iv_len +(bsnaphdr?SNAP_SIZE:0);
  1770. len = precvframe->u.hdr.len - rmv_len;
  1771. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x ===\n\n", pattrib->hdrlen, pattrib->iv_len));
  1772. _rtw_memcpy(&eth_type, ptr+rmv_len, 2);
  1773. eth_type= ntohs((unsigned short )eth_type); //pattrib->ether_type
  1774. pattrib->eth_type = eth_type;
  1775. #ifdef CONFIG_AUTO_AP_MODE
  1776. if (0x8899 == pattrib->eth_type)
  1777. {
  1778. struct sta_info *psta = precvframe->u.hdr.psta;
  1779. DBG_871X("wlan rx: got eth_type=0x%x\n", pattrib->eth_type);
  1780. if (psta && psta->isrc && psta->pid>0)
  1781. {
  1782. u16 rx_pid;
  1783. rx_pid = *(u16*)(ptr+rmv_len+2);
  1784. DBG_871X("wlan rx(pid=0x%x): sta("MAC_FMT") pid=0x%x\n",
  1785. rx_pid, MAC_ARG(psta->hwaddr), psta->pid);
  1786. if(rx_pid == psta->pid)
  1787. {
  1788. int i;
  1789. u16 len = *(u16*)(ptr+rmv_len+4);
  1790. //u16 ctrl_type = *(u16*)(ptr+rmv_len+6);
  1791. //DBG_871X("RC: len=0x%x, ctrl_type=0x%x\n", len, ctrl_type);
  1792. DBG_871X("RC: len=0x%x\n", len);
  1793. for(i=0;i<len;i++)
  1794. DBG_871X("0x%x\n", *(ptr+rmv_len+6+i));
  1795. //DBG_871X("0x%x\n", *(ptr+rmv_len+8+i));
  1796. DBG_871X("RC-end\n");
  1797. }
  1798. }
  1799. }
  1800. #endif //CONFIG_AUTO_AP_MODE
  1801. if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE))
  1802. {
  1803. ptr += rmv_len ;
  1804. *ptr = 0x87;
  1805. *(ptr+1) = 0x12;
  1806. eth_type = 0x8712;
  1807. // append rx status for mp test packets
  1808. ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24);
  1809. _rtw_memcpy(ptr, get_rxmem(precvframe), 24);
  1810. ptr+=24;
  1811. }
  1812. else {
  1813. ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+ (bsnaphdr?2:0)));
  1814. }
  1815. _rtw_memcpy(ptr, pattrib->dst, ETH_ALEN);
  1816. _rtw_memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
  1817. if(!bsnaphdr) {
  1818. len = htons(len);
  1819. _rtw_memcpy(ptr+12, &len, 2);
  1820. }
  1821. _func_exit_;
  1822. return ret;
  1823. }
  1824. #else
  1825. sint wlanhdr_to_ethhdr ( union recv_frame *precvframe)
  1826. {
  1827. sint rmv_len;
  1828. u16 eth_type;
  1829. u8 bsnaphdr;
  1830. u8 *psnap_type;
  1831. struct ieee80211_snap_hdr *psnap;
  1832. sint ret=_SUCCESS;
  1833. _adapter *adapter =precvframe->u.hdr.adapter;
  1834. struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
  1835. u8* ptr = get_recvframe_data(precvframe) ; // point to frame_ctrl field
  1836. struct rx_pkt_attrib *pattrib = & precvframe->u.hdr.attrib;
  1837. struct _vlan *pvlan = NULL;
  1838. _func_enter_;
  1839. psnap=(struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
  1840. psnap_type=ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
  1841. if (psnap->dsap==0xaa && psnap->ssap==0xaa && psnap->ctrl==0x03)
  1842. {
  1843. if (_rtw_memcmp(psnap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN))
  1844. bsnaphdr=_TRUE;//wlan_pkt_format = WLAN_PKT_FORMAT_SNAP_RFC1042;
  1845. else if (_rtw_memcmp(psnap->oui, SNAP_HDR_APPLETALK_DDP, WLAN_IEEE_OUI_LEN) &&
  1846. _rtw_memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_DDP, 2) )
  1847. bsnaphdr=_TRUE; //wlan_pkt_format = WLAN_PKT_FORMAT_APPLETALK;
  1848. else if (_rtw_memcmp( psnap->oui, oui_8021h, WLAN_IEEE_OUI_LEN))
  1849. bsnaphdr=_TRUE; //wlan_pkt_format = WLAN_PKT_FORMAT_SNAP_TUNNEL;
  1850. else {
  1851. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("drop pkt due to invalid frame format!\n"));
  1852. ret= _FAIL;
  1853. goto exit;
  1854. }
  1855. } else
  1856. bsnaphdr=_FALSE;//wlan_pkt_format = WLAN_PKT_FORMAT_OTHERS;
  1857. rmv_len = pattrib->hdrlen + pattrib->iv_len +(bsnaphdr?SNAP_SIZE:0);
  1858. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("===pattrib->hdrlen: %x, pattrib->iv_len:%x ===\n", pattrib->hdrlen, pattrib->iv_len));
  1859. if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
  1860. {
  1861. ptr += rmv_len ;
  1862. *ptr = 0x87;
  1863. *(ptr+1) = 0x12;
  1864. //back to original pointer
  1865. ptr -= rmv_len;
  1866. }
  1867. ptr += rmv_len ;
  1868. _rtw_memcpy(&eth_type, ptr, 2);
  1869. eth_type= ntohs((unsigned short )eth_type); //pattrib->ether_type
  1870. ptr +=2;
  1871. if(pattrib->encrypt){
  1872. recvframe_pull_tail(precvframe, pattrib->icv_len);
  1873. }
  1874. if(eth_type == 0x8100) //vlan
  1875. {
  1876. pvlan = (struct _vlan *) ptr;
  1877. //eth_type = get_vlan_encap_proto(pvlan);
  1878. //eth_type = pvlan->h_vlan_encapsulated_proto;//?
  1879. rmv_len += 4;
  1880. ptr+=4;
  1881. }
  1882. if(eth_type==0x0800)//ip
  1883. {
  1884. //struct iphdr* piphdr = (struct iphdr*) ptr;
  1885. //__u8 tos = (unsigned char)(pattrib->priority & 0xff);
  1886. //piphdr->tos = tos;
  1887. //if (piphdr->protocol == 0x06)
  1888. //{
  1889. // RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("@@@===recv tcp len:%d @@@===\n", precvframe->u.hdr.len));
  1890. //}
  1891. }
  1892. else if(eth_type==0x8712)// append rx status for mp test packets
  1893. {
  1894. //ptr -= 16;
  1895. //_rtw_memcpy(ptr, get_rxmem(precvframe), 16);
  1896. }
  1897. else
  1898. {
  1899. #ifdef PLATFORM_OS_XP
  1900. NDIS_PACKET_8021Q_INFO VlanPriInfo;
  1901. UINT32 UserPriority = precvframe->u.hdr.attrib.priority;
  1902. UINT32 VlanID = (pvlan!=NULL ? get_vlan_id(pvlan) : 0 );
  1903. VlanPriInfo.Value = // Get current value.
  1904. NDIS_PER_PACKET_INFO_FROM_PACKET(precvframe->u.hdr.pkt, Ieee8021QInfo);
  1905. VlanPriInfo.TagHeader.UserPriority = UserPriority;
  1906. VlanPriInfo.TagHeader.VlanId = VlanID ;
  1907. VlanPriInfo.TagHeader.CanonicalFormatId = 0; // Should be zero.
  1908. VlanPriInfo.TagHeader.Reserved = 0; // Should be zero.
  1909. NDIS_PER_PACKET_INFO_FROM_PACKET(precvframe->u.hdr.pkt, Ieee8021QInfo) = VlanPriInfo.Value;
  1910. #endif
  1911. }
  1912. if(eth_type==0x8712)// append rx status for mp test packets
  1913. {
  1914. ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24);
  1915. _rtw_memcpy(ptr, get_rxmem(precvframe), 24);
  1916. ptr+=24;
  1917. }
  1918. else
  1919. ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2));
  1920. _rtw_memcpy(ptr, pattrib->dst, ETH_ALEN);
  1921. _rtw_memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
  1922. eth_type = htons((unsigned short)eth_type) ;
  1923. _rtw_memcpy(ptr+12, &eth_type, 2);
  1924. exit:
  1925. _func_exit_;
  1926. return ret;
  1927. }
  1928. #endif
  1929. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1930. #ifdef PLATFORM_LINUX
  1931. static void recvframe_expand_pkt(
  1932. PADAPTER padapter,
  1933. union recv_frame *prframe)
  1934. {
  1935. struct recv_frame_hdr *pfhdr;
  1936. _pkt *ppkt;
  1937. u8 shift_sz;
  1938. u32 alloc_sz;
  1939. pfhdr = &prframe->u.hdr;
  1940. // 6 is for IP header 8 bytes alignment in QoS packet case.
  1941. if (pfhdr->attrib.qos)
  1942. shift_sz = 6;
  1943. else
  1944. shift_sz = 0;
  1945. // for first fragment packet, need to allocate
  1946. // (1536 + RXDESC_SIZE + drvinfo_sz) to reassemble packet
  1947. // 8 is for skb->data 8 bytes alignment.
  1948. // alloc_sz = _RND(1536 + RXDESC_SIZE + pfhdr->attrib.drvinfosize + shift_sz + 8, 128);
  1949. alloc_sz = 1664; // round (1536 + 24 + 32 + shift_sz + 8) to 128 bytes alignment
  1950. //3 1. alloc new skb
  1951. // prepare extra space for 4 bytes alignment
  1952. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)) // http://www.mail-archive.com/netdev@vger.kernel.org/msg17214.html
  1953. ppkt = dev_alloc_skb(alloc_sz);
  1954. if (ppkt) ppkt->dev = padapter->pnetdev;
  1955. #else
  1956. ppkt = netdev_alloc_skb(padapter->pnetdev, alloc_sz);
  1957. #endif
  1958. if (!ppkt) return; // no way to expand
  1959. //3 2. Prepare new skb to replace & release old skb
  1960. // force ppkt->data at 8-byte alignment address
  1961. skb_reserve(ppkt, 8 - ((SIZE_PTR)ppkt->data & 7));
  1962. // force ip_hdr at 8-byte alignment address according to shift_sz
  1963. skb_reserve(ppkt, shift_sz);
  1964. // copy data to new pkt
  1965. _rtw_memcpy(skb_put(ppkt, pfhdr->len), pfhdr->rx_data, pfhdr->len);
  1966. dev_kfree_skb_any(pfhdr->pkt);
  1967. // attach new pkt to recvframe
  1968. pfhdr->pkt = ppkt;
  1969. pfhdr->rx_head = ppkt->head;
  1970. pfhdr->rx_data = ppkt->data;
  1971. pfhdr->rx_tail = skb_tail_pointer(ppkt);
  1972. pfhdr->rx_end = skb_end_pointer(ppkt);
  1973. }
  1974. #else
  1975. #warning "recvframe_expand_pkt not implement, defrag may crash system"
  1976. #endif
  1977. #endif
  1978. //perform defrag
  1979. union recv_frame * recvframe_defrag(_adapter *adapter,_queue *defrag_q);
  1980. union recv_frame * recvframe_defrag(_adapter *adapter,_queue *defrag_q)
  1981. {
  1982. _list *plist, *phead;
  1983. u8 *data,wlanhdr_offset;
  1984. u8 curfragnum;
  1985. struct recv_frame_hdr *pfhdr,*pnfhdr;
  1986. union recv_frame* prframe, *pnextrframe;
  1987. _queue *pfree_recv_queue;
  1988. _func_enter_;
  1989. curfragnum=0;
  1990. pfree_recv_queue=&adapter->recvpriv.free_recv_queue;
  1991. phead = get_list_head(defrag_q);
  1992. plist = get_next(phead);
  1993. prframe = LIST_CONTAINOR(plist, union recv_frame, u);
  1994. pfhdr=&prframe->u.hdr;
  1995. rtw_list_delete(&(prframe->u.list));
  1996. if(curfragnum!=pfhdr->attrib.frag_num)
  1997. {
  1998. //the first fragment number must be 0
  1999. //free the whole queue
  2000. rtw_free_recvframe(prframe, pfree_recv_queue);
  2001. rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
  2002. return NULL;
  2003. }
  2004. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  2005. #ifndef CONFIG_SDIO_RX_COPY
  2006. recvframe_expand_pkt(adapter, prframe);
  2007. #endif
  2008. #endif
  2009. curfragnum++;
  2010. plist= get_list_head(defrag_q);
  2011. plist = get_next(plist);
  2012. data=get_recvframe_data(prframe);
  2013. while(rtw_end_of_queue_search(phead, plist) == _FALSE)
  2014. {
  2015. pnextrframe = LIST_CONTAINOR(plist, union recv_frame , u);
  2016. pnfhdr=&pnextrframe->u.hdr;
  2017. //check the fragment sequence (2nd ~n fragment frame)
  2018. if(curfragnum!=pnfhdr->attrib.frag_num)
  2019. {
  2020. //the fragment number must be increasing (after decache)
  2021. //release the defrag_q & prframe
  2022. rtw_free_recvframe(prframe, pfree_recv_queue);
  2023. rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
  2024. return NULL;
  2025. }
  2026. curfragnum++;
  2027. //copy the 2nd~n fragment frame's payload to the first fragment
  2028. //get the 2nd~last fragment frame's payload
  2029. wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
  2030. recvframe_pull(pnextrframe, wlanhdr_offset);
  2031. //append to first fragment frame's tail (if privacy frame, pull the ICV)
  2032. recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
  2033. //memcpy
  2034. _rtw_memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
  2035. recvframe_put(prframe, pnfhdr->len);
  2036. pfhdr->attrib.icv_len=pnfhdr->attrib.icv_len;
  2037. plist = get_next(plist);
  2038. };
  2039. //free the defrag_q queue and return the prframe
  2040. rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
  2041. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("Performance defrag!!!!!\n"));
  2042. _func_exit_;
  2043. return prframe;
  2044. }
  2045. //check if need to defrag, if needed queue the frame to defrag_q
  2046. union recv_frame* recvframe_chk_defrag(PADAPTER padapter, union recv_frame *precv_frame)
  2047. {
  2048. u8 ismfrag;
  2049. u8 fragnum;
  2050. u8 *psta_addr;
  2051. struct recv_frame_hdr *pfhdr;
  2052. struct sta_info *psta;
  2053. struct sta_priv *pstapriv;
  2054. _list *phead;
  2055. union recv_frame *prtnframe = NULL;
  2056. _queue *pfree_recv_queue, *pdefrag_q;
  2057. _func_enter_;
  2058. pstapriv = &padapter->stapriv;
  2059. pfhdr = &precv_frame->u.hdr;
  2060. pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
  2061. //need to define struct of wlan header frame ctrl
  2062. ismfrag = pfhdr->attrib.mfrag;
  2063. fragnum = pfhdr->attrib.frag_num;
  2064. psta_addr = pfhdr->attrib.ta;
  2065. psta = rtw_get_stainfo(pstapriv, psta_addr);
  2066. if (psta == NULL)
  2067. {
  2068. u8 type = GetFrameType(pfhdr->rx_data);
  2069. if (type != WIFI_DATA_TYPE) {
  2070. psta = rtw_get_bcmc_stainfo(padapter);
  2071. pdefrag_q = &psta->sta_recvpriv.defrag_q;
  2072. } else
  2073. pdefrag_q = NULL;
  2074. }
  2075. else
  2076. pdefrag_q = &psta->sta_recvpriv.defrag_q;
  2077. if ((ismfrag==0) && (fragnum==0))
  2078. {
  2079. prtnframe = precv_frame;//isn't a fragment frame
  2080. }
  2081. if (ismfrag==1)
  2082. {
  2083. //0~(n-1) fragment frame
  2084. //enqueue to defraf_g
  2085. if(pdefrag_q != NULL)
  2086. {
  2087. if(fragnum==0)
  2088. {
  2089. //the first fragment
  2090. if(_rtw_queue_empty(pdefrag_q) == _FALSE)
  2091. {
  2092. //free current defrag_q
  2093. rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
  2094. }
  2095. }
  2096. //Then enqueue the 0~(n-1) fragment into the defrag_q
  2097. //_rtw_spinlock(&pdefrag_q->lock);
  2098. phead = get_list_head(pdefrag_q);
  2099. rtw_list_insert_tail(&pfhdr->list, phead);
  2100. //_rtw_spinunlock(&pdefrag_q->lock);
  2101. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("Enqueuq: ismfrag = %d, fragnum= %d\n", ismfrag,fragnum));
  2102. prtnframe=NULL;
  2103. }
  2104. else
  2105. {
  2106. //can't find this ta's defrag_queue, so free this recv_frame
  2107. rtw_free_recvframe(precv_frame, pfree_recv_queue);
  2108. prtnframe=NULL;
  2109. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("Free because pdefrag_q ==NULL: ismfrag = %d, fragnum= %d\n", ismfrag, fragnum));
  2110. }
  2111. }
  2112. if((ismfrag==0)&&(fragnum!=0))
  2113. {
  2114. //the last fragment frame
  2115. //enqueue the last fragment
  2116. if(pdefrag_q != NULL)
  2117. {
  2118. //_rtw_spinlock(&pdefrag_q->lock);
  2119. phead = get_list_head(pdefrag_q);
  2120. rtw_list_insert_tail(&pfhdr->list,phead);
  2121. //_rtw_spinunlock(&pdefrag_q->lock);
  2122. //call recvframe_defrag to defrag
  2123. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("defrag: ismfrag = %d, fragnum= %d\n", ismfrag, fragnum));
  2124. precv_frame = recvframe_defrag(padapter, pdefrag_q);
  2125. prtnframe=precv_frame;
  2126. }
  2127. else
  2128. {
  2129. //can't find this ta's defrag_queue, so free this recv_frame
  2130. rtw_free_recvframe(precv_frame, pfree_recv_queue);
  2131. prtnframe=NULL;
  2132. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("Free because pdefrag_q ==NULL: ismfrag = %d, fragnum= %d\n", ismfrag,fragnum));
  2133. }
  2134. }
  2135. if((prtnframe!=NULL)&&(prtnframe->u.hdr.attrib.privacy))
  2136. {
  2137. //after defrag we must check tkip mic code
  2138. if(recvframe_chkmic(padapter, prtnframe)==_FAIL)
  2139. {
  2140. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvframe_chkmic(padapter, prtnframe)==_FAIL\n"));
  2141. rtw_free_recvframe(prtnframe,pfree_recv_queue);
  2142. prtnframe=NULL;
  2143. }
  2144. }
  2145. _func_exit_;
  2146. return prtnframe;
  2147. }
  2148. int amsdu_to_msdu(_adapter *padapter, union recv_frame *prframe)
  2149. {
  2150. int a_len, padding_len;
  2151. u16 nSubframe_Length;
  2152. u8 nr_subframes, i;
  2153. u8 *pdata;
  2154. _pkt *sub_pkt,*subframes[MAX_SUBFRAME_COUNT];
  2155. struct recv_priv *precvpriv = &padapter->recvpriv;
  2156. _queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
  2157. int ret = _SUCCESS;
  2158. nr_subframes = 0;
  2159. recvframe_pull(prframe, prframe->u.hdr.attrib.hdrlen);
  2160. if(prframe->u.hdr.attrib.iv_len >0)
  2161. {
  2162. recvframe_pull(prframe, prframe->u.hdr.attrib.iv_len);
  2163. }
  2164. a_len = prframe->u.hdr.len;
  2165. pdata = prframe->u.hdr.rx_data;
  2166. while(a_len > ETH_HLEN) {
  2167. /* Offset 12 denote 2 mac address */
  2168. nSubframe_Length = RTW_GET_BE16(pdata + 12);
  2169. if( a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length) ) {
  2170. DBG_871X("nRemain_Length is %d and nSubframe_Length is : %d\n",a_len,nSubframe_Length);
  2171. break;
  2172. }
  2173. sub_pkt = rtw_os_alloc_msdu_pkt(prframe, nSubframe_Length, pdata);
  2174. if (sub_pkt == NULL) {
  2175. DBG_871X("%s(): allocate sub packet fail !!!\n",__FUNCTION__);
  2176. break;
  2177. }
  2178. /* move the data point to data content */
  2179. pdata += ETH_HLEN;
  2180. a_len -= ETH_HLEN;
  2181. subframes[nr_subframes++] = sub_pkt;
  2182. if(nr_subframes >= MAX_SUBFRAME_COUNT) {
  2183. DBG_871X("ParseSubframe(): Too many Subframes! Packets dropped!\n");
  2184. break;
  2185. }
  2186. pdata += nSubframe_Length;
  2187. a_len -= nSubframe_Length;
  2188. if(a_len != 0) {
  2189. padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4-1));
  2190. if(padding_len == 4) {
  2191. padding_len = 0;
  2192. }
  2193. if(a_len < padding_len) {
  2194. DBG_871X("ParseSubframe(): a_len < padding_len !\n");
  2195. break;
  2196. }
  2197. pdata += padding_len;
  2198. a_len -= padding_len;
  2199. }
  2200. }
  2201. for(i=0; i<nr_subframes; i++){
  2202. sub_pkt = subframes[i];
  2203. /* Indicat the packets to upper layer */
  2204. if (sub_pkt) {
  2205. rtw_os_recv_indicate_pkt(padapter, sub_pkt, &prframe->u.hdr.attrib);
  2206. }
  2207. }
  2208. prframe->u.hdr.len = 0;
  2209. rtw_free_recvframe(prframe, pfree_recv_queue);//free this recv_frame
  2210. return ret;
  2211. }
  2212. int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num);
  2213. int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
  2214. {
  2215. u8 wsize = preorder_ctrl->wsize_b;
  2216. u16 wend = (preorder_ctrl->indicate_seq + wsize -1) & 0xFFF;//% 4096;
  2217. // Rx Reorder initialize condition.
  2218. if (preorder_ctrl->indicate_seq == 0xFFFF)
  2219. {
  2220. preorder_ctrl->indicate_seq = seq_num;
  2221. #ifdef DBG_RX_SEQ
  2222. DBG_871X("DBG_RX_SEQ %s:%d init IndicateSeq: %d, NewSeq: %d\n", __FUNCTION__, __LINE__,
  2223. preorder_ctrl->indicate_seq, seq_num);
  2224. #endif
  2225. //DbgPrint("check_indicate_seq, 1st->indicate_seq=%d\n", precvpriv->indicate_seq);
  2226. }
  2227. //DbgPrint("enter->check_indicate_seq(): IndicateSeq: %d, NewSeq: %d\n", precvpriv->indicate_seq, seq_num);
  2228. // Drop out the packet which SeqNum is smaller than WinStart
  2229. if( SN_LESS(seq_num, preorder_ctrl->indicate_seq) )
  2230. {
  2231. //RT_TRACE(COMP_RX_REORDER, DBG_LOUD, ("CheckRxTsIndicateSeq(): Packet Drop! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, NewSeqNum));
  2232. //DbgPrint("CheckRxTsIndicateSeq(): Packet Drop! IndicateSeq: %d, NewSeq: %d\n", precvpriv->indicate_seq, seq_num);
  2233. #ifdef DBG_RX_DROP_FRAME
  2234. DBG_871X("%s IndicateSeq: %d > NewSeq: %d\n", __FUNCTION__,
  2235. preorder_ctrl->indicate_seq, seq_num);
  2236. #endif
  2237. return _FALSE;
  2238. }
  2239. //
  2240. // Sliding window manipulation. Conditions includes:
  2241. // 1. Incoming SeqNum is equal to WinStart =>Window shift 1
  2242. // 2. Incoming SeqNum is larger than the WinEnd => Window shift N
  2243. //
  2244. if( SN_EQUAL(seq_num, preorder_ctrl->indicate_seq) )
  2245. {
  2246. preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
  2247. #ifdef DBG_RX_SEQ
  2248. DBG_871X("DBG_RX_SEQ %s:%d SN_EQUAL IndicateSeq: %d, NewSeq: %d\n", __FUNCTION__, __LINE__,
  2249. preorder_ctrl->indicate_seq, seq_num);
  2250. #endif
  2251. }
  2252. else if(SN_LESS(wend, seq_num))
  2253. {
  2254. //RT_TRACE(COMP_RX_REORDER, DBG_LOUD, ("CheckRxTsIndicateSeq(): Window Shift! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, NewSeqNum));
  2255. //DbgPrint("CheckRxTsIndicateSeq(): Window Shift! IndicateSeq: %d, NewSeq: %d\n", precvpriv->indicate_seq, seq_num);
  2256. // boundary situation, when seq_num cross 0xFFF
  2257. if(seq_num >= (wsize - 1))
  2258. preorder_ctrl->indicate_seq = seq_num + 1 -wsize;
  2259. else
  2260. preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
  2261. #ifdef DBG_RX_SEQ
  2262. DBG_871X("DBG_RX_SEQ %s:%d SN_LESS(wend, seq_num) IndicateSeq: %d, NewSeq: %d\n", __FUNCTION__, __LINE__,
  2263. preorder_ctrl->indicate_seq, seq_num);
  2264. #endif
  2265. }
  2266. //DbgPrint("exit->check_indicate_seq(): IndicateSeq: %d, NewSeq: %d\n", precvpriv->indicate_seq, seq_num);
  2267. return _TRUE;
  2268. }
  2269. int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, union recv_frame *prframe);
  2270. int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, union recv_frame *prframe)
  2271. {
  2272. struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
  2273. _queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
  2274. _list *phead, *plist;
  2275. union recv_frame *pnextrframe;
  2276. struct rx_pkt_attrib *pnextattrib;
  2277. //DbgPrint("+enqueue_reorder_recvframe()\n");
  2278. //_enter_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2279. //_rtw_spinlock_ex(&ppending_recvframe_queue->lock);
  2280. phead = get_list_head(ppending_recvframe_queue);
  2281. plist = get_next(phead);
  2282. while(rtw_end_of_queue_search(phead, plist) == _FALSE)
  2283. {
  2284. pnextrframe = LIST_CONTAINOR(plist, union recv_frame, u);
  2285. pnextattrib = &pnextrframe->u.hdr.attrib;
  2286. if(SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
  2287. {
  2288. plist = get_next(plist);
  2289. }
  2290. else if( SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
  2291. {
  2292. //Duplicate entry is found!! Do not insert current entry.
  2293. //RT_TRACE(COMP_RX_REORDER, DBG_TRACE, ("InsertRxReorderList(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, SeqNum));
  2294. //_exit_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2295. return _FALSE;
  2296. }
  2297. else
  2298. {
  2299. break;
  2300. }
  2301. //DbgPrint("enqueue_reorder_recvframe():while\n");
  2302. }
  2303. //_enter_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2304. //_rtw_spinlock_ex(&ppending_recvframe_queue->lock);
  2305. rtw_list_delete(&(prframe->u.hdr.list));
  2306. rtw_list_insert_tail(&(prframe->u.hdr.list), plist);
  2307. //_rtw_spinunlock_ex(&ppending_recvframe_queue->lock);
  2308. //_exit_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2309. //RT_TRACE(COMP_RX_REORDER, DBG_TRACE, ("InsertRxReorderList(): Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, SeqNum));
  2310. return _TRUE;
  2311. }
  2312. int recv_indicatepkts_in_order(_adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced);
  2313. int recv_indicatepkts_in_order(_adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
  2314. {
  2315. //_irqL irql;
  2316. //u8 bcancelled;
  2317. _list *phead, *plist;
  2318. union recv_frame *prframe;
  2319. struct rx_pkt_attrib *pattrib;
  2320. //u8 index = 0;
  2321. int bPktInBuf = _FALSE;
  2322. struct recv_priv *precvpriv = &padapter->recvpriv;
  2323. _queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
  2324. //DbgPrint("+recv_indicatepkts_in_order\n");
  2325. //_enter_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2326. //_rtw_spinlock_ex(&ppending_recvframe_queue->lock);
  2327. phead = get_list_head(ppending_recvframe_queue);
  2328. plist = get_next(phead);
  2329. #if 0
  2330. // Check if there is any other indication thread running.
  2331. if(pTS->RxIndicateState == RXTS_INDICATE_PROCESSING)
  2332. return;
  2333. #endif
  2334. // Handling some condition for forced indicate case.
  2335. if(bforced==_TRUE)
  2336. {
  2337. if(rtw_is_list_empty(phead))
  2338. {
  2339. // _exit_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2340. //_rtw_spinunlock_ex(&ppending_recvframe_queue->lock);
  2341. return _TRUE;
  2342. }
  2343. prframe = LIST_CONTAINOR(plist, union recv_frame, u);
  2344. pattrib = &prframe->u.hdr.attrib;
  2345. preorder_ctrl->indicate_seq = pattrib->seq_num;
  2346. #ifdef DBG_RX_SEQ
  2347. DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d, NewSeq: %d\n", __FUNCTION__, __LINE__,
  2348. preorder_ctrl->indicate_seq, pattrib->seq_num);
  2349. #endif
  2350. }
  2351. // Prepare indication list and indication.
  2352. // Check if there is any packet need indicate.
  2353. while(!rtw_is_list_empty(phead))
  2354. {
  2355. prframe = LIST_CONTAINOR(plist, union recv_frame, u);
  2356. pattrib = &prframe->u.hdr.attrib;
  2357. if(!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num))
  2358. {
  2359. RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
  2360. ("recv_indicatepkts_in_order: indicate=%d seq=%d amsdu=%d\n",
  2361. preorder_ctrl->indicate_seq, pattrib->seq_num, pattrib->amsdu));
  2362. #if 0
  2363. // This protect buffer from overflow.
  2364. if(index >= REORDER_WIN_SIZE)
  2365. {
  2366. RT_ASSERT(FALSE, ("IndicateRxReorderList(): Buffer overflow!! \n"));
  2367. bPktInBuf = TRUE;
  2368. break;
  2369. }
  2370. #endif
  2371. plist = get_next(plist);
  2372. rtw_list_delete(&(prframe->u.hdr.list));
  2373. if(SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
  2374. {
  2375. preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
  2376. #ifdef DBG_RX_SEQ
  2377. DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d, NewSeq: %d\n", __FUNCTION__, __LINE__,
  2378. preorder_ctrl->indicate_seq, pattrib->seq_num);
  2379. #endif
  2380. }
  2381. #if 0
  2382. index++;
  2383. if(index==1)
  2384. {
  2385. //Cancel previous pending timer.
  2386. //PlatformCancelTimer(Adapter, &pTS->RxPktPendingTimer);
  2387. if(bforced!=_TRUE)
  2388. {
  2389. //DBG_871X("_cancel_timer(&preorder_ctrl->reordering_ctrl_timer, &bcancelled);\n");
  2390. _cancel_timer(&preorder_ctrl->reordering_ctrl_timer, &bcancelled);
  2391. }
  2392. }
  2393. #endif
  2394. //Set this as a lock to make sure that only one thread is indicating packet.
  2395. //pTS->RxIndicateState = RXTS_INDICATE_PROCESSING;
  2396. // Indicate packets
  2397. //RT_ASSERT((index<=REORDER_WIN_SIZE), ("RxReorderIndicatePacket(): Rx Reorder buffer full!! \n"));
  2398. //indicate this recv_frame
  2399. //DbgPrint("recv_indicatepkts_in_order, indicate_seq=%d, seq_num=%d\n", precvpriv->indicate_seq, pattrib->seq_num);
  2400. if(!pattrib->amsdu)
  2401. {
  2402. //DBG_871X("recv_indicatepkts_in_order, amsdu!=1, indicate_seq=%d, seq_num=%d\n", preorder_ctrl->indicate_seq, pattrib->seq_num);
  2403. if ((padapter->bDriverStopped == _FALSE) &&
  2404. (padapter->bSurpriseRemoved == _FALSE))
  2405. {
  2406. rtw_recv_indicatepkt(padapter, prframe);//indicate this recv_frame
  2407. }
  2408. }
  2409. else if(pattrib->amsdu==1)
  2410. {
  2411. if(amsdu_to_msdu(padapter, prframe)!=_SUCCESS)
  2412. {
  2413. rtw_free_recvframe(prframe, &precvpriv->free_recv_queue);
  2414. }
  2415. }
  2416. else
  2417. {
  2418. //error condition;
  2419. }
  2420. //Update local variables.
  2421. bPktInBuf = _FALSE;
  2422. }
  2423. else
  2424. {
  2425. bPktInBuf = _TRUE;
  2426. break;
  2427. }
  2428. //DbgPrint("recv_indicatepkts_in_order():while\n");
  2429. }
  2430. //_rtw_spinunlock_ex(&ppending_recvframe_queue->lock);
  2431. //_exit_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2432. /*
  2433. //Release the indication lock and set to new indication step.
  2434. if(bPktInBuf)
  2435. {
  2436. // Set new pending timer.
  2437. //pTS->RxIndicateState = RXTS_INDICATE_REORDER;
  2438. //PlatformSetTimer(Adapter, &pTS->RxPktPendingTimer, pHTInfo->RxReorderPendingTime);
  2439. //DBG_871X("_set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME)\n");
  2440. _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
  2441. }
  2442. else
  2443. {
  2444. //pTS->RxIndicateState = RXTS_INDICATE_IDLE;
  2445. }
  2446. */
  2447. //_exit_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2448. //return _TRUE;
  2449. return bPktInBuf;
  2450. }
  2451. int recv_indicatepkt_reorder(_adapter *padapter, union recv_frame *prframe);
  2452. int recv_indicatepkt_reorder(_adapter *padapter, union recv_frame *prframe)
  2453. {
  2454. _irqL irql;
  2455. int retval = _SUCCESS;
  2456. struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
  2457. struct recv_reorder_ctrl *preorder_ctrl = prframe->u.hdr.preorder_ctrl;
  2458. _queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
  2459. if(!pattrib->amsdu)
  2460. {
  2461. //s1.
  2462. wlanhdr_to_ethhdr(prframe);
  2463. if ((pattrib->qos!=1) /*|| pattrib->priority!=0 || IS_MCAST(pattrib->ra)*/
  2464. || (pattrib->eth_type==0x0806) || (pattrib->ack_policy!=0))
  2465. {
  2466. if ((padapter->bDriverStopped == _FALSE) &&
  2467. (padapter->bSurpriseRemoved == _FALSE))
  2468. {
  2469. RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ recv_indicatepkt_reorder -recv_func recv_indicatepkt\n" ));
  2470. rtw_recv_indicatepkt(padapter, prframe);
  2471. return _SUCCESS;
  2472. }
  2473. #ifdef DBG_RX_DROP_FRAME
  2474. DBG_871X("DBG_RX_DROP_FRAME %s pattrib->qos !=1\n", __FUNCTION__);
  2475. #endif
  2476. return _FAIL;
  2477. }
  2478. if (preorder_ctrl->enable == _FALSE)
  2479. {
  2480. //indicate this recv_frame
  2481. preorder_ctrl->indicate_seq = pattrib->seq_num;
  2482. #ifdef DBG_RX_SEQ
  2483. DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d, NewSeq: %d\n", __FUNCTION__, __LINE__,
  2484. preorder_ctrl->indicate_seq, pattrib->seq_num);
  2485. #endif
  2486. rtw_recv_indicatepkt(padapter, prframe);
  2487. preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
  2488. #ifdef DBG_RX_SEQ
  2489. DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d, NewSeq: %d\n", __FUNCTION__, __LINE__,
  2490. preorder_ctrl->indicate_seq, pattrib->seq_num);
  2491. #endif
  2492. return _SUCCESS;
  2493. }
  2494. #ifndef CONFIG_RECV_REORDERING_CTRL
  2495. //indicate this recv_frame
  2496. rtw_recv_indicatepkt(padapter, prframe);
  2497. return _SUCCESS;
  2498. #endif
  2499. }
  2500. else if(pattrib->amsdu==1) //temp filter -> means didn't support A-MSDUs in a A-MPDU
  2501. {
  2502. if (preorder_ctrl->enable == _FALSE)
  2503. {
  2504. preorder_ctrl->indicate_seq = pattrib->seq_num;
  2505. #ifdef DBG_RX_SEQ
  2506. DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d, NewSeq: %d\n", __FUNCTION__, __LINE__,
  2507. preorder_ctrl->indicate_seq, pattrib->seq_num);
  2508. #endif
  2509. retval = amsdu_to_msdu(padapter, prframe);
  2510. preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
  2511. #ifdef DBG_RX_SEQ
  2512. DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d, NewSeq: %d\n", __FUNCTION__, __LINE__,
  2513. preorder_ctrl->indicate_seq, pattrib->seq_num);
  2514. #endif
  2515. if(retval != _SUCCESS){
  2516. #ifdef DBG_RX_DROP_FRAME
  2517. DBG_871X("DBG_RX_DROP_FRAME %s amsdu_to_msdu fail\n", __FUNCTION__);
  2518. #endif
  2519. }
  2520. return retval;
  2521. }
  2522. }
  2523. else
  2524. {
  2525. }
  2526. _enter_critical_bh(&ppending_recvframe_queue->lock, &irql);
  2527. RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
  2528. ("recv_indicatepkt_reorder: indicate=%d seq=%d\n",
  2529. preorder_ctrl->indicate_seq, pattrib->seq_num));
  2530. //s2. check if winstart_b(indicate_seq) needs to been updated
  2531. if(!check_indicate_seq(preorder_ctrl, pattrib->seq_num))
  2532. {
  2533. //pHTInfo->RxReorderDropCounter++;
  2534. //ReturnRFDList(Adapter, pRfd);
  2535. //RT_TRACE(COMP_RX_REORDER, DBG_TRACE, ("RxReorderIndicatePacket() ==> Packet Drop!!\n"));
  2536. //_exit_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2537. //return _FAIL;
  2538. #ifdef DBG_RX_DROP_FRAME
  2539. DBG_871X("DBG_RX_DROP_FRAME %s check_indicate_seq fail\n", __FUNCTION__);
  2540. #endif
  2541. #if 0
  2542. rtw_recv_indicatepkt(padapter, prframe);
  2543. _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
  2544. goto _success_exit;
  2545. #else
  2546. goto _err_exit;
  2547. #endif
  2548. }
  2549. //s3. Insert all packet into Reorder Queue to maintain its ordering.
  2550. if(!enqueue_reorder_recvframe(preorder_ctrl, prframe))
  2551. {
  2552. //DbgPrint("recv_indicatepkt_reorder, enqueue_reorder_recvframe fail!\n");
  2553. //_exit_critical_ex(&ppending_recvframe_queue->lock, &irql);
  2554. //return _FAIL;
  2555. #ifdef DBG_RX_DROP_FRAME
  2556. DBG_871X("DBG_RX_DROP_FRAME %s enqueue_reorder_recvframe fail\n", __FUNCTION__);
  2557. #endif
  2558. goto _err_exit;
  2559. }
  2560. //s4.
  2561. // Indication process.
  2562. // After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
  2563. // with the SeqNum smaller than latest WinStart and buffer other packets.
  2564. //
  2565. // For Rx Reorder condition:
  2566. // 1. All packets with SeqNum smaller than WinStart => Indicate
  2567. // 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
  2568. //
  2569. //recv_indicatepkts_in_order(padapter, preorder_ctrl, _TRUE);
  2570. if(recv_indicatepkts_in_order(padapter, preorder_ctrl, _FALSE)==_TRUE)
  2571. {
  2572. _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
  2573. _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
  2574. }
  2575. else
  2576. {
  2577. _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
  2578. _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
  2579. }
  2580. _success_exit:
  2581. return _SUCCESS;
  2582. _err_exit:
  2583. _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
  2584. return _FAIL;
  2585. }
  2586. void rtw_reordering_ctrl_timeout_handler(void *pcontext)
  2587. {
  2588. _irqL irql;
  2589. struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)pcontext;
  2590. _adapter *padapter = preorder_ctrl->padapter;
  2591. _queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
  2592. if(padapter->bDriverStopped ||padapter->bSurpriseRemoved)
  2593. {
  2594. return;
  2595. }
  2596. //DBG_871X("+rtw_reordering_ctrl_timeout_handler()=>\n");
  2597. _enter_critical_bh(&ppending_recvframe_queue->lock, &irql);
  2598. if(recv_indicatepkts_in_order(padapter, preorder_ctrl, _TRUE)==_TRUE)
  2599. {
  2600. _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
  2601. }
  2602. _exit_critical_bh(&ppending_recvframe_queue->lock, &irql);
  2603. }
  2604. int process_recv_indicatepkts(_adapter *padapter, union recv_frame *prframe);
  2605. int process_recv_indicatepkts(_adapter *padapter, union recv_frame *prframe)
  2606. {
  2607. int retval = _SUCCESS;
  2608. //struct recv_priv *precvpriv = &padapter->recvpriv;
  2609. //struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
  2610. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2611. #ifdef CONFIG_TDLS
  2612. struct sta_info *psta = prframe->u.hdr.psta;
  2613. #endif //CONFIG_TDLS
  2614. #ifdef CONFIG_80211N_HT
  2615. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  2616. #ifdef CONFIG_TDLS
  2617. if( (phtpriv->ht_option==_TRUE) ||
  2618. ((psta->tdls_sta_state & TDLS_LINKED_STATE) &&
  2619. (psta->htpriv.ht_option==_TRUE) &&
  2620. (psta->htpriv.ampdu_enable==_TRUE))) //B/G/N Mode
  2621. #else
  2622. if(phtpriv->ht_option==_TRUE) //B/G/N Mode
  2623. #endif //CONFIG_TDLS
  2624. {
  2625. //prframe->u.hdr.preorder_ctrl = &precvpriv->recvreorder_ctrl[pattrib->priority];
  2626. if(recv_indicatepkt_reorder(padapter, prframe)!=_SUCCESS)// including perform A-MPDU Rx Ordering Buffer Control
  2627. {
  2628. #ifdef DBG_RX_DROP_FRAME
  2629. DBG_871X("DBG_RX_DROP_FRAME %s recv_indicatepkt_reorder error!\n", __FUNCTION__);
  2630. #endif
  2631. if ((padapter->bDriverStopped == _FALSE) &&
  2632. (padapter->bSurpriseRemoved == _FALSE))
  2633. {
  2634. retval = _FAIL;
  2635. return retval;
  2636. }
  2637. }
  2638. }
  2639. else //B/G mode
  2640. #endif
  2641. {
  2642. retval=wlanhdr_to_ethhdr (prframe);
  2643. if(retval != _SUCCESS)
  2644. {
  2645. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("wlanhdr_to_ethhdr: drop pkt \n"));
  2646. #ifdef DBG_RX_DROP_FRAME
  2647. DBG_871X("DBG_RX_DROP_FRAME %s wlanhdr_to_ethhdr error!\n", __FUNCTION__);
  2648. #endif
  2649. return retval;
  2650. }
  2651. if ((padapter->bDriverStopped ==_FALSE)&&( padapter->bSurpriseRemoved==_FALSE))
  2652. {
  2653. //indicate this recv_frame
  2654. RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func recv_indicatepkt\n" ));
  2655. rtw_recv_indicatepkt(padapter, prframe);
  2656. }
  2657. else
  2658. {
  2659. RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func free_indicatepkt\n" ));
  2660. RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
  2661. retval = _FAIL;
  2662. return retval;
  2663. }
  2664. }
  2665. return retval;
  2666. }
  2667. int recv_func_prehandle(_adapter *padapter, union recv_frame *rframe)
  2668. {
  2669. int ret = _SUCCESS;
  2670. struct rx_pkt_attrib *pattrib = &rframe->u.hdr.attrib;
  2671. struct recv_priv *precvpriv = &padapter->recvpriv;
  2672. _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
  2673. #ifdef CONFIG_MP_INCLUDED
  2674. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2675. #endif //CONFIG_MP_INCLUDED
  2676. #ifdef CONFIG_MP_INCLUDED
  2677. if (padapter->registrypriv.mp_mode == 1)
  2678. {
  2679. if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE))//&&(padapter->mppriv.check_mp_pkt == 0))
  2680. {
  2681. if (pattrib->crc_err == 1)
  2682. padapter->mppriv.rx_crcerrpktcount++;
  2683. else
  2684. padapter->mppriv.rx_pktcount++;
  2685. if (check_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE) == _FALSE) {
  2686. RT_TRACE(_module_rtl871x_recv_c_, _drv_alert_, ("MP - Not in loopback mode , drop pkt \n"));
  2687. ret = _FAIL;
  2688. rtw_free_recvframe(rframe, pfree_recv_queue);//free this recv_frame
  2689. goto exit;
  2690. }
  2691. }
  2692. }
  2693. #endif
  2694. //check the frame crtl field and decache
  2695. ret = validate_recv_frame(padapter, rframe);
  2696. if (ret != _SUCCESS)
  2697. {
  2698. RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recv_func: validate_recv_frame fail! drop pkt\n"));
  2699. rtw_free_recvframe(rframe, pfree_recv_queue);//free this recv_frame
  2700. goto exit;
  2701. }
  2702. exit:
  2703. return ret;
  2704. }
  2705. int recv_func_posthandle(_adapter *padapter, union recv_frame *prframe)
  2706. {
  2707. int ret = _SUCCESS;
  2708. union recv_frame *orig_prframe = prframe;
  2709. struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
  2710. struct recv_priv *precvpriv = &padapter->recvpriv;
  2711. _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
  2712. #ifdef CONFIG_TDLS
  2713. u8 *psnap_type, *pcategory;
  2714. struct sta_info *ptdls_sta = NULL;
  2715. #endif //CONFIG_TDLS
  2716. // DATA FRAME
  2717. rtw_led_control(padapter, LED_CTL_RX);
  2718. prframe = decryptor(padapter, prframe);
  2719. if (prframe == NULL) {
  2720. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("decryptor: drop pkt\n"));
  2721. #ifdef DBG_RX_DROP_FRAME
  2722. DBG_871X("DBG_RX_DROP_FRAME %s decryptor: drop pkt\n", __FUNCTION__);
  2723. #endif
  2724. ret = _FAIL;
  2725. goto _recv_data_drop;
  2726. }
  2727. #if 0
  2728. if ( padapter->adapter_type == PRIMARY_ADAPTER )
  2729. {
  2730. DBG_871X("+++\n");
  2731. {
  2732. int i;
  2733. u8 *ptr = get_recvframe_data(prframe);
  2734. for(i=0; i<140;i=i+8)
  2735. DBG_871X("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:", *(ptr+i),
  2736. *(ptr+i+1), *(ptr+i+2) ,*(ptr+i+3) ,*(ptr+i+4),*(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
  2737. }
  2738. DBG_871X("---\n");
  2739. }
  2740. #endif
  2741. #ifdef CONFIG_TDLS
  2742. //check TDLS frame
  2743. psnap_type = get_recvframe_data(orig_prframe);
  2744. psnap_type+=pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
  2745. pcategory = psnap_type + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN;
  2746. if((_rtw_memcmp(psnap_type, SNAP_ETH_TYPE_TDLS, ETH_TYPE_LEN)) &&
  2747. ((*pcategory==RTW_WLAN_CATEGORY_TDLS) || (*pcategory==RTW_WLAN_CATEGORY_P2P))){
  2748. ret = OnTDLS(padapter, prframe); //all of functions will return _FAIL
  2749. goto _exit_recv_func;
  2750. }
  2751. #endif //CONFIG_TDLS
  2752. prframe = recvframe_chk_defrag(padapter, prframe);
  2753. if(prframe==NULL) {
  2754. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvframe_chk_defrag: drop pkt\n"));
  2755. #ifdef DBG_RX_DROP_FRAME
  2756. DBG_871X("DBG_RX_DROP_FRAME %s recvframe_chk_defrag: drop pkt\n", __FUNCTION__);
  2757. #endif
  2758. goto _recv_data_drop;
  2759. }
  2760. prframe=portctrl(padapter, prframe);
  2761. if (prframe == NULL) {
  2762. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("portctrl: drop pkt \n"));
  2763. #ifdef DBG_RX_DROP_FRAME
  2764. DBG_871X("DBG_RX_DROP_FRAME %s portctrl: drop pkt\n", __FUNCTION__);
  2765. #endif
  2766. ret = _FAIL;
  2767. goto _recv_data_drop;
  2768. }
  2769. #ifdef CONFIG_TDLS
  2770. if(padapter->tdlsinfo.setup_state == TDLS_LINKED_STATE)
  2771. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, pattrib->src);
  2772. count_rx_stats(padapter, prframe, ptdls_sta);
  2773. #else
  2774. count_rx_stats(padapter, prframe, NULL);
  2775. #endif //CONFIG_TDLS
  2776. #ifdef CONFIG_WAPI_SUPPORT
  2777. rtw_wapi_update_info(padapter, prframe);
  2778. #endif
  2779. #ifdef CONFIG_80211N_HT
  2780. ret = process_recv_indicatepkts(padapter, prframe);
  2781. if (ret != _SUCCESS)
  2782. {
  2783. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recv_func: process_recv_indicatepkts fail! \n"));
  2784. #ifdef DBG_RX_DROP_FRAME
  2785. DBG_871X("DBG_RX_DROP_FRAME %s process_recv_indicatepkts fail!\n", __FUNCTION__);
  2786. #endif
  2787. rtw_free_recvframe(orig_prframe, pfree_recv_queue);//free this recv_frame
  2788. goto _recv_data_drop;
  2789. }
  2790. #else // CONFIG_80211N_HT
  2791. if (!pattrib->amsdu)
  2792. {
  2793. ret = wlanhdr_to_ethhdr (prframe);
  2794. if (ret != _SUCCESS)
  2795. {
  2796. RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("wlanhdr_to_ethhdr: drop pkt \n"));
  2797. #ifdef DBG_RX_DROP_FRAME
  2798. DBG_871X("DBG_RX_DROP_FRAME %s wlanhdr_to_ethhdr: drop pkt\n", __FUNCTION__);
  2799. #endif
  2800. rtw_free_recvframe(orig_prframe, pfree_recv_queue);//free this recv_frame
  2801. goto _recv_data_drop;
  2802. }
  2803. if ((padapter->bDriverStopped == _FALSE) && (padapter->bSurpriseRemoved == _FALSE))
  2804. {
  2805. RT_TRACE(_module_rtl871x_recv_c_, _drv_alert_, ("@@@@ recv_func: recv_func rtw_recv_indicatepkt\n" ));
  2806. //indicate this recv_frame
  2807. ret = rtw_recv_indicatepkt(padapter, prframe);
  2808. if (ret != _SUCCESS)
  2809. {
  2810. #ifdef DBG_RX_DROP_FRAME
  2811. DBG_871X("DBG_RX_DROP_FRAME %s rtw_recv_indicatepkt fail!\n", __FUNCTION__);
  2812. #endif
  2813. goto _recv_data_drop;
  2814. }
  2815. }
  2816. else
  2817. {
  2818. RT_TRACE(_module_rtl871x_recv_c_, _drv_alert_, ("@@@@ recv_func: rtw_free_recvframe\n" ));
  2819. RT_TRACE(_module_rtl871x_recv_c_, _drv_debug_, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
  2820. #ifdef DBG_RX_DROP_FRAME
  2821. DBG_871X("DBG_RX_DROP_FRAME %s ecv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)\n", __FUNCTION__,
  2822. padapter->bDriverStopped, padapter->bSurpriseRemoved);
  2823. #endif
  2824. ret = _FAIL;
  2825. rtw_free_recvframe(orig_prframe, pfree_recv_queue); //free this recv_frame
  2826. }
  2827. }
  2828. else if(pattrib->amsdu==1)
  2829. {
  2830. ret = amsdu_to_msdu(padapter, prframe);
  2831. if(ret != _SUCCESS)
  2832. {
  2833. #ifdef DBG_RX_DROP_FRAME
  2834. DBG_871X("DBG_RX_DROP_FRAME %s amsdu_to_msdu fail\n", __FUNCTION__);
  2835. #endif
  2836. rtw_free_recvframe(orig_prframe, pfree_recv_queue);
  2837. goto _recv_data_drop;
  2838. }
  2839. }
  2840. else
  2841. {
  2842. #ifdef DBG_RX_DROP_FRAME
  2843. DBG_871X("DBG_RX_DROP_FRAME %s what is this condition??\n", __FUNCTION__);
  2844. #endif
  2845. goto _recv_data_drop;
  2846. }
  2847. #endif // CONFIG_80211N_HT
  2848. _exit_recv_func:
  2849. return ret;
  2850. _recv_data_drop:
  2851. precvpriv->rx_drop++;
  2852. return ret;
  2853. }
  2854. int recv_func(_adapter *padapter, union recv_frame *rframe);
  2855. int recv_func(_adapter *padapter, union recv_frame *rframe)
  2856. {
  2857. int ret;
  2858. struct rx_pkt_attrib *prxattrib = &rframe->u.hdr.attrib;
  2859. struct recv_priv *recvpriv = &padapter->recvpriv;
  2860. struct security_priv *psecuritypriv=&padapter->securitypriv;
  2861. struct mlme_priv *mlmepriv = &padapter->mlmepriv;
  2862. /* check if need to handle uc_swdec_pending_queue*/
  2863. if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey)
  2864. {
  2865. union recv_frame *pending_frame;
  2866. _irqL irqL;
  2867. while((pending_frame=rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) {
  2868. if (recv_func_posthandle(padapter, pending_frame) == _SUCCESS)
  2869. DBG_871X("%s: dequeue uc_swdec_pending_queue\n", __func__);
  2870. }
  2871. }
  2872. ret = recv_func_prehandle(padapter, rframe);
  2873. if(ret == _SUCCESS) {
  2874. /* check if need to enqueue into uc_swdec_pending_queue*/
  2875. if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
  2876. !IS_MCAST(prxattrib->ra) && prxattrib->encrypt>0 &&
  2877. (prxattrib->bdecrypted == 0 ||psecuritypriv->sw_decrypt == _TRUE) &&
  2878. !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) &&
  2879. !psecuritypriv->busetkipkey) {
  2880. rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
  2881. DBG_871X("%s: no key, enqueue uc_swdec_pending_queue\n", __func__);
  2882. goto exit;
  2883. }
  2884. ret = recv_func_posthandle(padapter, rframe);
  2885. }
  2886. exit:
  2887. return ret;
  2888. }
  2889. s32 rtw_recv_entry(union recv_frame *precvframe)
  2890. {
  2891. _adapter *padapter;
  2892. struct recv_priv *precvpriv;
  2893. s32 ret=_SUCCESS;
  2894. _func_enter_;
  2895. // RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("+rtw_recv_entry\n"));
  2896. padapter = precvframe->u.hdr.adapter;
  2897. precvpriv = &padapter->recvpriv;
  2898. if ((ret = recv_func(padapter, precvframe)) == _FAIL)
  2899. {
  2900. RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("rtw_recv_entry: recv_func return fail!!!\n"));
  2901. goto _recv_entry_drop;
  2902. }
  2903. precvpriv->rx_pkts++;
  2904. _func_exit_;
  2905. return ret;
  2906. _recv_entry_drop:
  2907. #ifdef CONFIG_MP_INCLUDED
  2908. if (padapter->registrypriv.mp_mode == 1)
  2909. padapter->mppriv.rx_pktloss = precvpriv->rx_drop;
  2910. #endif
  2911. //RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("_recv_entry_drop\n"));
  2912. _func_exit_;
  2913. return ret;
  2914. }
  2915. #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
  2916. void rtw_signal_stat_timer_hdl(RTW_TIMER_HDL_ARGS){
  2917. _adapter *adapter = (_adapter *)FunctionContext;
  2918. struct recv_priv *recvpriv = &adapter->recvpriv;
  2919. u32 tmp_s, tmp_q;
  2920. u8 avg_signal_strength = 0;
  2921. u8 avg_signal_qual = 0;
  2922. u32 num_signal_strength = 0;
  2923. u32 num_signal_qual = 0;
  2924. u8 _alpha = 3; // this value is based on converging_constant = 5000 and sampling_interval = 1000
  2925. if(adapter->recvpriv.is_signal_dbg) {
  2926. //update the user specific value, signal_strength_dbg, to signal_strength, rssi
  2927. adapter->recvpriv.signal_strength= adapter->recvpriv.signal_strength_dbg;
  2928. adapter->recvpriv.rssi=(s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg);
  2929. } else {
  2930. if(recvpriv->signal_strength_data.update_req == 0) {// update_req is clear, means we got rx
  2931. avg_signal_strength = recvpriv->signal_strength_data.avg_val;
  2932. num_signal_strength = recvpriv->signal_strength_data.total_num;
  2933. // after avg_vals are accquired, we can re-stat the signal values
  2934. recvpriv->signal_strength_data.update_req = 1;
  2935. }
  2936. if(recvpriv->signal_qual_data.update_req == 0) {// update_req is clear, means we got rx
  2937. avg_signal_qual = recvpriv->signal_qual_data.avg_val;
  2938. num_signal_qual = recvpriv->signal_qual_data.total_num;
  2939. // after avg_vals are accquired, we can re-stat the signal values
  2940. recvpriv->signal_qual_data.update_req = 1;
  2941. }
  2942. //update value of signal_strength, rssi, signal_qual
  2943. if(check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == _FALSE) {
  2944. tmp_s = (avg_signal_strength+(_alpha-1)*recvpriv->signal_strength);
  2945. if(tmp_s %_alpha)
  2946. tmp_s = tmp_s/_alpha + 1;
  2947. else
  2948. tmp_s = tmp_s/_alpha;
  2949. if(tmp_s>100)
  2950. tmp_s = 100;
  2951. tmp_q = (avg_signal_qual+(_alpha-1)*recvpriv->signal_qual);
  2952. if(tmp_q %_alpha)
  2953. tmp_q = tmp_q/_alpha + 1;
  2954. else
  2955. tmp_q = tmp_q/_alpha;
  2956. if(tmp_q>100)
  2957. tmp_q = 100;
  2958. recvpriv->signal_strength = tmp_s;
  2959. recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
  2960. recvpriv->signal_qual = tmp_q;
  2961. #if defined(DBG_RX_SIGNAL_DISPLAY_PROCESSING) && 1
  2962. DBG_871X("%s signal_strength:%3u, rssi:%3d, signal_qual:%3u"
  2963. ", num_signal_strength:%u, num_signal_qual:%u"
  2964. "\n"
  2965. , __FUNCTION__
  2966. , recvpriv->signal_strength
  2967. , recvpriv->rssi
  2968. , recvpriv->signal_qual
  2969. , num_signal_strength, num_signal_qual
  2970. );
  2971. #endif
  2972. }
  2973. }
  2974. rtw_set_signal_stat_timer(recvpriv);
  2975. }
  2976. #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS