rtw_xmit.c 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349
  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_XMIT_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. static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
  26. static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
  27. static void _init_txservq(struct tx_servq *ptxservq)
  28. {
  29. _func_enter_;
  30. _rtw_init_listhead(&ptxservq->tx_pending);
  31. _rtw_init_queue(&ptxservq->sta_pending);
  32. ptxservq->qcnt = 0;
  33. _func_exit_;
  34. }
  35. void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv)
  36. {
  37. _func_enter_;
  38. _rtw_memset((unsigned char *)psta_xmitpriv, 0, sizeof (struct sta_xmit_priv));
  39. _rtw_spinlock_init(&psta_xmitpriv->lock);
  40. //for(i = 0 ; i < MAX_NUMBLKS; i++)
  41. // _init_txservq(&(psta_xmitpriv->blk_q[i]));
  42. _init_txservq(&psta_xmitpriv->be_q);
  43. _init_txservq(&psta_xmitpriv->bk_q);
  44. _init_txservq(&psta_xmitpriv->vi_q);
  45. _init_txservq(&psta_xmitpriv->vo_q);
  46. _rtw_init_listhead(&psta_xmitpriv->legacy_dz);
  47. _rtw_init_listhead(&psta_xmitpriv->apsd);
  48. _func_exit_;
  49. }
  50. s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, _adapter *padapter)
  51. {
  52. int i;
  53. struct xmit_buf *pxmitbuf;
  54. struct xmit_frame *pxframe;
  55. sint res=_SUCCESS;
  56. u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
  57. u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
  58. _func_enter_;
  59. // We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc().
  60. //_rtw_memset((unsigned char *)pxmitpriv, 0, sizeof(struct xmit_priv));
  61. _rtw_spinlock_init(&pxmitpriv->lock);
  62. _rtw_spinlock_init(&pxmitpriv->lock_sctx);
  63. _rtw_init_sema(&pxmitpriv->xmit_sema, 0);
  64. _rtw_init_sema(&pxmitpriv->terminate_xmitthread_sema, 0);
  65. /*
  66. Please insert all the queue initializaiton using _rtw_init_queue below
  67. */
  68. pxmitpriv->adapter = padapter;
  69. //for(i = 0 ; i < MAX_NUMBLKS; i++)
  70. // _rtw_init_queue(&pxmitpriv->blk_strms[i]);
  71. _rtw_init_queue(&pxmitpriv->be_pending);
  72. _rtw_init_queue(&pxmitpriv->bk_pending);
  73. _rtw_init_queue(&pxmitpriv->vi_pending);
  74. _rtw_init_queue(&pxmitpriv->vo_pending);
  75. _rtw_init_queue(&pxmitpriv->bm_pending);
  76. //_rtw_init_queue(&pxmitpriv->legacy_dz_queue);
  77. //_rtw_init_queue(&pxmitpriv->apsd_queue);
  78. _rtw_init_queue(&pxmitpriv->free_xmit_queue);
  79. /*
  80. Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME,
  81. and initialize free_xmit_frame below.
  82. Please also apply free_txobj to link_up all the xmit_frames...
  83. */
  84. pxmitpriv->pallocated_frame_buf = rtw_zvmalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4);
  85. if (pxmitpriv->pallocated_frame_buf == NULL){
  86. pxmitpriv->pxmit_frame_buf =NULL;
  87. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("alloc xmit_frame fail!\n"));
  88. res= _FAIL;
  89. goto exit;
  90. }
  91. pxmitpriv->pxmit_frame_buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_frame_buf), 4);
  92. //pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 -
  93. // ((SIZE_PTR) (pxmitpriv->pallocated_frame_buf) &3);
  94. pxframe = (struct xmit_frame*) pxmitpriv->pxmit_frame_buf;
  95. for (i = 0; i < NR_XMITFRAME; i++)
  96. {
  97. _rtw_init_listhead(&(pxframe->list));
  98. pxframe->padapter = padapter;
  99. pxframe->frame_tag = NULL_FRAMETAG;
  100. pxframe->pkt = NULL;
  101. pxframe->buf_addr = NULL;
  102. pxframe->pxmitbuf = NULL;
  103. rtw_list_insert_tail(&(pxframe->list), &(pxmitpriv->free_xmit_queue.queue));
  104. pxframe++;
  105. }
  106. pxmitpriv->free_xmitframe_cnt = NR_XMITFRAME;
  107. pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
  108. //init xmit_buf
  109. _rtw_init_queue(&pxmitpriv->free_xmitbuf_queue);
  110. _rtw_init_queue(&pxmitpriv->pending_xmitbuf_queue);
  111. pxmitpriv->pallocated_xmitbuf = rtw_zvmalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4);
  112. if (pxmitpriv->pallocated_xmitbuf == NULL){
  113. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("alloc xmit_buf fail!\n"));
  114. res= _FAIL;
  115. goto exit;
  116. }
  117. pxmitpriv->pxmitbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_xmitbuf), 4);
  118. //pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 -
  119. // ((SIZE_PTR) (pxmitpriv->pallocated_xmitbuf) &3);
  120. pxmitbuf = (struct xmit_buf*)pxmitpriv->pxmitbuf;
  121. for (i = 0; i < NR_XMITBUFF; i++)
  122. {
  123. _rtw_init_listhead(&pxmitbuf->list);
  124. pxmitbuf->priv_data = NULL;
  125. pxmitbuf->padapter = padapter;
  126. pxmitbuf->buf_tag = XMITBUF_DATA;
  127. /* Tx buf allocation may fail sometimes, so sleep and retry. */
  128. if((res=rtw_os_xmit_resource_alloc(padapter, pxmitbuf,(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), _TRUE)) == _FAIL) {
  129. rtw_msleep_os(10);
  130. res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf,(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), _TRUE);
  131. if (res == _FAIL) {
  132. goto exit;
  133. }
  134. }
  135. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  136. pxmitbuf->phead = pxmitbuf->pbuf;
  137. pxmitbuf->pend = pxmitbuf->pbuf + MAX_XMITBUF_SZ;
  138. pxmitbuf->len = 0;
  139. pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
  140. #endif
  141. pxmitbuf->flags = XMIT_VO_QUEUE;
  142. rtw_list_insert_tail(&pxmitbuf->list, &(pxmitpriv->free_xmitbuf_queue.queue));
  143. #ifdef DBG_XMIT_BUF
  144. pxmitbuf->no=i;
  145. #endif
  146. pxmitbuf++;
  147. }
  148. pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
  149. /* init xframe_ext queue, the same count as extbuf */
  150. _rtw_init_queue(&pxmitpriv->free_xframe_ext_queue);
  151. pxmitpriv->xframe_ext_alloc_addr = rtw_zvmalloc(num_xmit_extbuf * sizeof(struct xmit_frame) + 4);
  152. if (pxmitpriv->xframe_ext_alloc_addr == NULL){
  153. pxmitpriv->xframe_ext = NULL;
  154. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("alloc xframe_ext fail!\n"));
  155. res= _FAIL;
  156. goto exit;
  157. }
  158. pxmitpriv->xframe_ext = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->xframe_ext_alloc_addr), 4);
  159. pxframe = (struct xmit_frame*)pxmitpriv->xframe_ext;
  160. for (i = 0; i < num_xmit_extbuf; i++) {
  161. _rtw_init_listhead(&(pxframe->list));
  162. pxframe->padapter = padapter;
  163. pxframe->frame_tag = NULL_FRAMETAG;
  164. pxframe->pkt = NULL;
  165. pxframe->buf_addr = NULL;
  166. pxframe->pxmitbuf = NULL;
  167. pxframe->ext_tag = 1;
  168. rtw_list_insert_tail(&(pxframe->list), &(pxmitpriv->free_xframe_ext_queue.queue));
  169. pxframe++;
  170. }
  171. pxmitpriv->free_xframe_ext_cnt = num_xmit_extbuf;
  172. // Init xmit extension buff
  173. _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue);
  174. pxmitpriv->pallocated_xmit_extbuf = rtw_zvmalloc(num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
  175. if (pxmitpriv->pallocated_xmit_extbuf == NULL){
  176. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("alloc xmit_extbuf fail!\n"));
  177. res= _FAIL;
  178. goto exit;
  179. }
  180. pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitpriv->pallocated_xmit_extbuf), 4);
  181. pxmitbuf = (struct xmit_buf*)pxmitpriv->pxmit_extbuf;
  182. for (i = 0; i < num_xmit_extbuf; i++)
  183. {
  184. _rtw_init_listhead(&pxmitbuf->list);
  185. pxmitbuf->priv_data = NULL;
  186. pxmitbuf->padapter = padapter;
  187. pxmitbuf->buf_tag = XMITBUF_MGNT;
  188. if((res=rtw_os_xmit_resource_alloc(padapter, pxmitbuf,max_xmit_extbuf_size + XMITBUF_ALIGN_SZ, _TRUE)) == _FAIL) {
  189. res= _FAIL;
  190. goto exit;
  191. }
  192. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  193. pxmitbuf->phead = pxmitbuf->pbuf;
  194. pxmitbuf->pend = pxmitbuf->pbuf + max_xmit_extbuf_size;
  195. pxmitbuf->len = 0;
  196. pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
  197. #endif
  198. rtw_list_insert_tail(&pxmitbuf->list, &(pxmitpriv->free_xmit_extbuf_queue.queue));
  199. #ifdef DBG_XMIT_BUF_EXT
  200. pxmitbuf->no=i;
  201. #endif
  202. pxmitbuf++;
  203. }
  204. pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
  205. pxmitbuf = &pxmitpriv->pcmd_xmitbuf;
  206. if (pxmitbuf) {
  207. _rtw_init_listhead(&pxmitbuf->list);
  208. pxmitbuf->priv_data = NULL;
  209. pxmitbuf->padapter = padapter;
  210. pxmitbuf->buf_tag = XMITBUF_CMD;
  211. if((res=rtw_os_xmit_resource_alloc(padapter, pxmitbuf, 0, _TRUE)) == _FAIL) {
  212. res= _FAIL;
  213. goto exit;
  214. }
  215. }
  216. rtw_alloc_hwxmits(padapter);
  217. rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
  218. for (i = 0; i < 4; i ++)
  219. {
  220. pxmitpriv->wmm_para_seq[i] = i;
  221. }
  222. #ifdef CONFIG_USB_HCI
  223. pxmitpriv->txirp_cnt=1;
  224. _rtw_init_sema(&(pxmitpriv->tx_retevt), 0);
  225. //per AC pending irp
  226. pxmitpriv->beq_cnt = 0;
  227. pxmitpriv->bkq_cnt = 0;
  228. pxmitpriv->viq_cnt = 0;
  229. pxmitpriv->voq_cnt = 0;
  230. #endif
  231. #ifdef CONFIG_XMIT_ACK
  232. pxmitpriv->ack_tx = _FALSE;
  233. _rtw_mutex_init(&pxmitpriv->ack_tx_mutex);
  234. rtw_sctx_init(&pxmitpriv->ack_tx_ops, 0);
  235. #endif
  236. rtw_hal_init_xmit_priv(padapter);
  237. exit:
  238. _func_exit_;
  239. return res;
  240. }
  241. void rtw_mfree_xmit_priv_lock (struct xmit_priv *pxmitpriv);
  242. void rtw_mfree_xmit_priv_lock (struct xmit_priv *pxmitpriv)
  243. {
  244. _rtw_spinlock_free(&pxmitpriv->lock);
  245. _rtw_free_sema(&pxmitpriv->xmit_sema);
  246. _rtw_free_sema(&pxmitpriv->terminate_xmitthread_sema);
  247. _rtw_spinlock_free(&pxmitpriv->be_pending.lock);
  248. _rtw_spinlock_free(&pxmitpriv->bk_pending.lock);
  249. _rtw_spinlock_free(&pxmitpriv->vi_pending.lock);
  250. _rtw_spinlock_free(&pxmitpriv->vo_pending.lock);
  251. _rtw_spinlock_free(&pxmitpriv->bm_pending.lock);
  252. //_rtw_spinlock_free(&pxmitpriv->legacy_dz_queue.lock);
  253. //_rtw_spinlock_free(&pxmitpriv->apsd_queue.lock);
  254. _rtw_spinlock_free(&pxmitpriv->free_xmit_queue.lock);
  255. _rtw_spinlock_free(&pxmitpriv->free_xmitbuf_queue.lock);
  256. _rtw_spinlock_free(&pxmitpriv->pending_xmitbuf_queue.lock);
  257. }
  258. void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv)
  259. {
  260. int i;
  261. _adapter *padapter = pxmitpriv->adapter;
  262. struct xmit_frame *pxmitframe = (struct xmit_frame*) pxmitpriv->pxmit_frame_buf;
  263. struct xmit_buf *pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
  264. u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
  265. u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
  266. #if defined(CONFIG_MP_INCLUDED) && (defined(CONFIG_RTL8723A) ||defined(CONFIG_RTL8723B))
  267. if (padapter->registrypriv.mp_mode) {
  268. max_xmit_extbuf_size = 20000;
  269. num_xmit_extbuf = 1;
  270. }
  271. #endif
  272. _func_enter_;
  273. rtw_hal_free_xmit_priv(padapter);
  274. rtw_mfree_xmit_priv_lock(pxmitpriv);
  275. if(pxmitpriv->pxmit_frame_buf==NULL)
  276. goto out;
  277. for(i=0; i<NR_XMITFRAME; i++)
  278. {
  279. rtw_os_xmit_complete(padapter, pxmitframe);
  280. pxmitframe++;
  281. }
  282. for(i=0; i<NR_XMITBUFF; i++)
  283. {
  284. rtw_os_xmit_resource_free(padapter, pxmitbuf,(MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ), _TRUE);
  285. pxmitbuf++;
  286. }
  287. if(pxmitpriv->pallocated_frame_buf) {
  288. rtw_vmfree(pxmitpriv->pallocated_frame_buf, NR_XMITFRAME * sizeof(struct xmit_frame) + 4);
  289. }
  290. if(pxmitpriv->pallocated_xmitbuf) {
  291. rtw_vmfree(pxmitpriv->pallocated_xmitbuf, NR_XMITBUFF * sizeof(struct xmit_buf) + 4);
  292. }
  293. /* free xframe_ext queue, the same count as extbuf */
  294. if ((pxmitframe = (struct xmit_frame*)pxmitpriv->xframe_ext)) {
  295. for (i=0; i<num_xmit_extbuf; i++) {
  296. rtw_os_xmit_complete(padapter, pxmitframe);
  297. pxmitframe++;
  298. }
  299. }
  300. if (pxmitpriv->xframe_ext_alloc_addr)
  301. rtw_vmfree(pxmitpriv->xframe_ext_alloc_addr, num_xmit_extbuf * sizeof(struct xmit_frame) + 4);
  302. _rtw_spinlock_free(&pxmitpriv->free_xframe_ext_queue.lock);
  303. // free xmit extension buff
  304. _rtw_spinlock_free(&pxmitpriv->free_xmit_extbuf_queue.lock);
  305. pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
  306. for(i=0; i<num_xmit_extbuf; i++)
  307. {
  308. rtw_os_xmit_resource_free(padapter, pxmitbuf,(max_xmit_extbuf_size + XMITBUF_ALIGN_SZ), _TRUE);
  309. pxmitbuf++;
  310. }
  311. if(pxmitpriv->pallocated_xmit_extbuf) {
  312. rtw_vmfree(pxmitpriv->pallocated_xmit_extbuf, num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
  313. }
  314. pxmitbuf = &pxmitpriv->pcmd_xmitbuf;
  315. rtw_os_xmit_resource_free(padapter, pxmitbuf, 0, _TRUE);
  316. rtw_free_hwxmits(padapter);
  317. #ifdef CONFIG_XMIT_ACK
  318. _rtw_mutex_free(&pxmitpriv->ack_tx_mutex);
  319. #endif
  320. out:
  321. _func_exit_;
  322. }
  323. static void update_attrib_vcs_info(_adapter *padapter, struct xmit_frame *pxmitframe)
  324. {
  325. u32 sz;
  326. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  327. //struct sta_info *psta = pattrib->psta;
  328. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  329. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  330. /*
  331. if(pattrib->psta)
  332. {
  333. psta = pattrib->psta;
  334. }
  335. else
  336. {
  337. DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
  338. psta=rtw_get_stainfo(&padapter->stapriv ,&pattrib->ra[0] );
  339. }
  340. if(psta==NULL)
  341. {
  342. DBG_871X("%s, psta==NUL\n", __func__);
  343. return;
  344. }
  345. if(!(psta->state &_FW_LINKED))
  346. {
  347. DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  348. return;
  349. }
  350. */
  351. if (pattrib->nr_frags != 1)
  352. {
  353. sz = padapter->xmitpriv.frag_len;
  354. }
  355. else //no frag
  356. {
  357. sz = pattrib->last_txcmdsz;
  358. }
  359. // (1) RTS_Threshold is compared to the MPDU, not MSDU.
  360. // (2) If there are more than one frag in this MSDU, only the first frag uses protection frame.
  361. // Other fragments are protected by previous fragment.
  362. // So we only need to check the length of first fragment.
  363. if(pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec)
  364. {
  365. if(sz > padapter->registrypriv.rts_thresh)
  366. {
  367. pattrib->vcs_mode = RTS_CTS;
  368. }
  369. else
  370. {
  371. if(pattrib->rtsen)
  372. pattrib->vcs_mode = RTS_CTS;
  373. else if(pattrib->cts2self)
  374. pattrib->vcs_mode = CTS_TO_SELF;
  375. else
  376. pattrib->vcs_mode = NONE_VCS;
  377. }
  378. }
  379. else
  380. {
  381. while (_TRUE)
  382. {
  383. #if 0 //Todo
  384. //check IOT action
  385. if(pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF)
  386. {
  387. pattrib->vcs_mode = CTS_TO_SELF;
  388. pattrib->rts_rate = MGN_24M;
  389. break;
  390. }
  391. else if(pHTInfo->IOTAction & (HT_IOT_ACT_FORCED_RTS|HT_IOT_ACT_PURE_N_MODE))
  392. {
  393. pattrib->vcs_mode = RTS_CTS;
  394. pattrib->rts_rate = MGN_24M;
  395. break;
  396. }
  397. #endif
  398. //IOT action
  399. if((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_ATHEROS) && (pattrib->ampdu_en==_TRUE) &&
  400. (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_ ))
  401. {
  402. pattrib->vcs_mode = CTS_TO_SELF;
  403. break;
  404. }
  405. //check ERP protection
  406. if(pattrib->rtsen || pattrib->cts2self)
  407. {
  408. if(pattrib->rtsen)
  409. pattrib->vcs_mode = RTS_CTS;
  410. else if(pattrib->cts2self)
  411. pattrib->vcs_mode = CTS_TO_SELF;
  412. break;
  413. }
  414. //check HT op mode
  415. if(pattrib->ht_en)
  416. {
  417. u8 HTOpMode = pmlmeinfo->HT_protection;
  418. if((pmlmeext->cur_bwmode && (HTOpMode == 2 || HTOpMode == 3)) ||
  419. (!pmlmeext->cur_bwmode && HTOpMode == 3) )
  420. {
  421. pattrib->vcs_mode = RTS_CTS;
  422. break;
  423. }
  424. }
  425. //check rts
  426. if(sz > padapter->registrypriv.rts_thresh)
  427. {
  428. pattrib->vcs_mode = RTS_CTS;
  429. break;
  430. }
  431. //to do list: check MIMO power save condition.
  432. //check AMPDU aggregation for TXOP
  433. if((pattrib->ampdu_en==_TRUE) && (!IS_HARDWARE_TYPE_JAGUAR(padapter)))
  434. {
  435. pattrib->vcs_mode = RTS_CTS;
  436. break;
  437. }
  438. pattrib->vcs_mode = NONE_VCS;
  439. break;
  440. }
  441. }
  442. }
  443. static void update_attrib_phy_info(struct pkt_attrib *pattrib, struct sta_info *psta)
  444. {
  445. pattrib->rtsen = psta->rtsen;
  446. pattrib->cts2self = psta->cts2self;
  447. pattrib->mdata = 0;
  448. pattrib->eosp = 0;
  449. pattrib->triggered=0;
  450. //qos_en, ht_en, init rate, ,bw, ch_offset, sgi
  451. pattrib->qos_en = psta->qos_option;
  452. pattrib->raid = psta->raid;
  453. #ifdef CONFIG_80211N_HT
  454. #ifdef CONFIG_80211AC_VHT
  455. if (psta->vhtpriv.vht_option) {
  456. pattrib->bwmode = psta->vhtpriv.bwmode;
  457. pattrib->sgi= psta->vhtpriv.sgi;
  458. if(TEST_FLAG(psta->vhtpriv.ldpc_cap, LDPC_VHT_ENABLE_TX))
  459. pattrib->ldpc = 1;
  460. if(TEST_FLAG(psta->vhtpriv.stbc_cap, STBC_VHT_ENABLE_TX))
  461. pattrib->stbc = 1;
  462. }
  463. else
  464. #endif //CONFIG_80211AC_VHT
  465. {
  466. pattrib->bwmode = psta->htpriv.bwmode;
  467. pattrib->sgi= psta->htpriv.sgi;
  468. }
  469. pattrib->ht_en = psta->htpriv.ht_option;
  470. pattrib->ch_offset = psta->htpriv.ch_offset;
  471. pattrib->ampdu_en = _FALSE;
  472. #endif //CONFIG_80211N_HT
  473. //if(pattrib->ht_en && psta->htpriv.ampdu_enable)
  474. //{
  475. // if(psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
  476. // pattrib->ampdu_en = _TRUE;
  477. //}
  478. pattrib->retry_ctrl = _FALSE;
  479. #ifdef CONFIG_AUTO_AP_MODE
  480. if(psta->isrc && psta->pid>0)
  481. pattrib->pctrl = _TRUE;
  482. #endif
  483. }
  484. static s32 update_attrib_sec_info(_adapter *padapter, struct pkt_attrib *pattrib, struct sta_info *psta)
  485. {
  486. sint res = _SUCCESS;
  487. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  488. struct security_priv *psecuritypriv = &padapter->securitypriv;
  489. sint bmcast = IS_MCAST(pattrib->ra);
  490. _rtw_memset(pattrib->dot118021x_UncstKey.skey, 0, 16);
  491. _rtw_memset(pattrib->dot11tkiptxmickey.skey, 0, 16);
  492. if (psta->ieee8021x_blocked == _TRUE)
  493. {
  494. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("\n psta->ieee8021x_blocked == _TRUE \n"));
  495. pattrib->encrypt = 0;
  496. if((pattrib->ether_type != 0x888e) && (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _FALSE))
  497. {
  498. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("\npsta->ieee8021x_blocked == _TRUE, pattrib->ether_type(%.4x) != 0x888e\n",pattrib->ether_type));
  499. #ifdef DBG_TX_DROP_FRAME
  500. DBG_871X("DBG_TX_DROP_FRAME %s psta->ieee8021x_blocked == _TRUE, pattrib->ether_type(%04x) != 0x888e\n", __FUNCTION__,pattrib->ether_type);
  501. #endif
  502. res = _FAIL;
  503. goto exit;
  504. }
  505. }
  506. else
  507. {
  508. GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
  509. #ifdef CONFIG_WAPI_SUPPORT
  510. if(pattrib->ether_type == 0x88B4)
  511. pattrib->encrypt=_NO_PRIVACY_;
  512. #endif
  513. switch(psecuritypriv->dot11AuthAlgrthm)
  514. {
  515. case dot11AuthAlgrthm_Open:
  516. case dot11AuthAlgrthm_Shared:
  517. case dot11AuthAlgrthm_Auto:
  518. pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex;
  519. break;
  520. case dot11AuthAlgrthm_8021X:
  521. if(bmcast)
  522. pattrib->key_idx = (u8)psecuritypriv->dot118021XGrpKeyid;
  523. else
  524. pattrib->key_idx = 0;
  525. break;
  526. default:
  527. pattrib->key_idx = 0;
  528. break;
  529. }
  530. //For WPS 1.0 WEP, driver should not encrypt EAPOL Packet for WPS handshake.
  531. if (((pattrib->encrypt ==_WEP40_)||(pattrib->encrypt ==_WEP104_)) && (pattrib->ether_type == 0x888e))
  532. pattrib->encrypt=_NO_PRIVACY_;
  533. }
  534. switch (pattrib->encrypt)
  535. {
  536. case _WEP40_:
  537. case _WEP104_:
  538. pattrib->iv_len = 4;
  539. pattrib->icv_len = 4;
  540. WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
  541. break;
  542. case _TKIP_:
  543. pattrib->iv_len = 8;
  544. pattrib->icv_len = 4;
  545. if(psecuritypriv->busetkipkey==_FAIL)
  546. {
  547. #ifdef DBG_TX_DROP_FRAME
  548. DBG_871X("DBG_TX_DROP_FRAME %s psecuritypriv->busetkipkey(%d)==_FAIL drop packet\n", __FUNCTION__, psecuritypriv->busetkipkey);
  549. #endif
  550. res =_FAIL;
  551. goto exit;
  552. }
  553. if(bmcast)
  554. TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
  555. else
  556. TKIP_IV(pattrib->iv, psta->dot11txpn, 0);
  557. _rtw_memcpy(pattrib->dot11tkiptxmickey.skey, psta->dot11tkiptxmickey.skey, 16);
  558. break;
  559. case _AES_:
  560. pattrib->iv_len = 8;
  561. pattrib->icv_len = 8;
  562. if(bmcast)
  563. AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
  564. else
  565. AES_IV(pattrib->iv, psta->dot11txpn, 0);
  566. break;
  567. #ifdef CONFIG_WAPI_SUPPORT
  568. case _SMS4_:
  569. pattrib->iv_len = 18;
  570. pattrib->icv_len = 16;
  571. rtw_wapi_get_iv(padapter,pattrib->ra,pattrib->iv);
  572. break;
  573. #endif
  574. default:
  575. pattrib->iv_len = 0;
  576. pattrib->icv_len = 0;
  577. break;
  578. }
  579. if(pattrib->encrypt>0)
  580. _rtw_memcpy(pattrib->dot118021x_UncstKey.skey, psta->dot118021x_UncstKey.skey, 16);
  581. exit:
  582. return res;
  583. }
  584. u8 qos_acm(u8 acm_mask, u8 priority)
  585. {
  586. u8 change_priority = priority;
  587. switch (priority)
  588. {
  589. case 0:
  590. case 3:
  591. if(acm_mask & BIT(1))
  592. change_priority = 1;
  593. break;
  594. case 1:
  595. case 2:
  596. break;
  597. case 4:
  598. case 5:
  599. if(acm_mask & BIT(2))
  600. change_priority = 0;
  601. break;
  602. case 6:
  603. case 7:
  604. if(acm_mask & BIT(3))
  605. change_priority = 5;
  606. break;
  607. default:
  608. DBG_871X("qos_acm(): invalid pattrib->priority: %d!!!\n", priority);
  609. break;
  610. }
  611. return change_priority;
  612. }
  613. static void set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
  614. {
  615. struct ethhdr etherhdr;
  616. struct iphdr ip_hdr;
  617. s32 UserPriority = 0;
  618. _rtw_open_pktfile(ppktfile->pkt, ppktfile);
  619. _rtw_pktfile_read(ppktfile, (unsigned char*)&etherhdr, ETH_HLEN);
  620. // get UserPriority from IP hdr
  621. if (pattrib->ether_type == 0x0800) {
  622. _rtw_pktfile_read(ppktfile, (u8*)&ip_hdr, sizeof(ip_hdr));
  623. // UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3;
  624. UserPriority = ip_hdr.tos >> 5;
  625. } else if (pattrib->ether_type == 0x888e) {
  626. // "When priority processing of data frames is supported,
  627. // a STA's SME should send EAPOL-Key frames at the highest priority."
  628. UserPriority = 7;
  629. }
  630. pattrib->priority = UserPriority;
  631. pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
  632. pattrib->subtype = WIFI_QOS_DATA_TYPE;
  633. }
  634. static s32 update_attrib(_adapter *padapter, _pkt *pkt, struct pkt_attrib *pattrib)
  635. {
  636. uint i;
  637. struct pkt_file pktfile;
  638. struct sta_info *psta = NULL;
  639. struct ethhdr etherhdr;
  640. sint bmcast;
  641. struct sta_priv *pstapriv = &padapter->stapriv;
  642. struct security_priv *psecuritypriv = &padapter->securitypriv;
  643. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  644. struct qos_priv *pqospriv= &pmlmepriv->qospriv;
  645. sint res = _SUCCESS;
  646. _func_enter_;
  647. _rtw_open_pktfile(pkt, &pktfile);
  648. i = _rtw_pktfile_read(&pktfile, (u8*)&etherhdr, ETH_HLEN);
  649. pattrib->ether_type = ntohs(etherhdr.h_proto);
  650. _rtw_memcpy(pattrib->dst, &etherhdr.h_dest, ETH_ALEN);
  651. _rtw_memcpy(pattrib->src, &etherhdr.h_source, ETH_ALEN);
  652. if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) ||
  653. (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
  654. _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
  655. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  656. }
  657. else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
  658. _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
  659. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  660. }
  661. else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  662. _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
  663. _rtw_memcpy(pattrib->ta, get_bssid(pmlmepriv), ETH_ALEN);
  664. }
  665. pattrib->pktlen = pktfile.pkt_len;
  666. if (ETH_P_IP == pattrib->ether_type)
  667. {
  668. // The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time
  669. // to prevent DHCP protocol fail
  670. u8 tmp[24];
  671. _rtw_pktfile_read(&pktfile, &tmp[0], 24);
  672. pattrib->dhcp_pkt = 0;
  673. if (pktfile.pkt_len > 282) {//MINIMUM_DHCP_PACKET_SIZE) {
  674. if (ETH_P_IP == pattrib->ether_type) {// IP header
  675. if (((tmp[21] == 68) && (tmp[23] == 67)) ||
  676. ((tmp[21] == 67) && (tmp[23] == 68))) {
  677. // 68 : UDP BOOTP client
  678. // 67 : UDP BOOTP server
  679. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("======================update_attrib: get DHCP Packet \n"));
  680. // Use low rate to send DHCP packet.
  681. //if(pMgntInfo->IOTAction & HT_IOT_ACT_WA_IOT_Broadcom)
  682. //{
  683. // tcb_desc->DataRate = MgntQuery_TxRateExcludeCCKRates(ieee);//0xc;//ofdm 6m
  684. // tcb_desc->bTxDisableRateFallBack = false;
  685. //}
  686. //else
  687. // pTcb->DataRate = Adapter->MgntInfo.LowestBasicRate;
  688. //RTPRINT(FDM, WA_IOT, ("DHCP TranslateHeader(), pTcb->DataRate = 0x%x\n", pTcb->DataRate));
  689. pattrib->dhcp_pkt = 1;
  690. }
  691. }
  692. }
  693. } else if (0x888e == pattrib->ether_type) {
  694. DBG_871X_LEVEL(_drv_always_, "send eapol packet\n");
  695. }
  696. if ( (pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1) )
  697. {
  698. rtw_set_scan_deny(padapter, 3000);
  699. }
  700. #ifdef CONFIG_LPS
  701. // If EAPOL , ARP , OR DHCP packet, driver must be in active mode.
  702. #ifdef CONFIG_WAPI_SUPPORT
  703. if ( (pattrib->ether_type == 0x88B4) || (pattrib->ether_type == 0x0806) || (pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1) )
  704. #else
  705. if ( (pattrib->ether_type == 0x0806) || (pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1) )
  706. #endif
  707. {
  708. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SPECIAL_PACKET, 1);
  709. }
  710. #endif
  711. bmcast = IS_MCAST(pattrib->ra);
  712. // get sta_info
  713. if (bmcast) {
  714. psta = rtw_get_bcmc_stainfo(padapter);
  715. } else {
  716. psta = rtw_get_stainfo(pstapriv, pattrib->ra);
  717. if (psta == NULL) { // if we cannot get psta => drrp the pkt
  718. RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra:" MAC_FMT"\n", MAC_ARG(pattrib->ra)));
  719. #ifdef DBG_TX_DROP_FRAME
  720. DBG_871X("DBG_TX_DROP_FRAME %s get sta_info fail, ra:" MAC_FMT"\n", __FUNCTION__, MAC_ARG(pattrib->ra));
  721. #endif
  722. res =_FAIL;
  723. goto exit;
  724. }
  725. else if((check_fwstate(pmlmepriv, WIFI_AP_STATE)==_TRUE)&&(!(psta->state & _FW_LINKED)))
  726. {
  727. res =_FAIL;
  728. goto exit;
  729. }
  730. }
  731. if(psta == NULL)
  732. { // if we cannot get psta => drop the pkt
  733. RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra:" MAC_FMT "\n", MAC_ARG(pattrib->ra)));
  734. #ifdef DBG_TX_DROP_FRAME
  735. DBG_871X("DBG_TX_DROP_FRAME %s get sta_info fail, ra:" MAC_FMT"\n", __FUNCTION__, MAC_ARG(pattrib->ra));
  736. #endif
  737. res = _FAIL;
  738. goto exit;
  739. }
  740. if(!(psta->state &_FW_LINKED))
  741. {
  742. DBG_871X("%s, psta("MAC_FMT")->state(0x%x) != _FW_LINKED\n", __func__, MAC_ARG(psta->hwaddr), psta->state);
  743. return _FAIL;
  744. }
  745. //TODO:_lock
  746. if(update_attrib_sec_info(padapter, pattrib, psta) == _FAIL)
  747. {
  748. res = _FAIL;
  749. goto exit;
  750. }
  751. update_attrib_phy_info(pattrib, psta);
  752. pattrib->mac_id = psta->mac_id;
  753. //DBG_8192C("%s ==> mac_id(%d)\n",__FUNCTION__,pattrib->mac_id );
  754. pattrib->psta = psta;
  755. //TODO:_unlock
  756. pattrib->pctrl = 0;
  757. pattrib->ack_policy = 0;
  758. // get ether_hdr_len
  759. pattrib->pkt_hdrlen = ETH_HLEN;//(pattrib->ether_type == 0x8100) ? (14 + 4 ): 14; //vlan tag
  760. pattrib->hdrlen = WLAN_HDR_A3_LEN;
  761. pattrib->subtype = WIFI_DATA_TYPE;
  762. pattrib->priority = 0;
  763. if (check_fwstate(pmlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE))
  764. {
  765. if(pattrib->qos_en)
  766. set_qos(&pktfile, pattrib);
  767. }
  768. else
  769. {
  770. if(pqospriv->qos_option)
  771. {
  772. set_qos(&pktfile, pattrib);
  773. if(pmlmepriv->acm_mask != 0)
  774. {
  775. pattrib->priority = qos_acm(pmlmepriv->acm_mask, pattrib->priority);
  776. }
  777. }
  778. }
  779. //pattrib->priority = 5; //force to used VI queue, for testing
  780. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
  781. ("update_attrib: encrypt=%d securitypriv.sw_encrypt=%d\n",
  782. pattrib->encrypt, padapter->securitypriv.sw_encrypt));
  783. if (pattrib->encrypt &&
  784. ((padapter->securitypriv.sw_encrypt == _TRUE) || (psecuritypriv->hw_decrypted == _FALSE)))
  785. {
  786. pattrib->bswenc = _TRUE;
  787. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,
  788. ("update_attrib: encrypt=%d securitypriv.hw_decrypted=%d bswenc=_TRUE\n",
  789. pattrib->encrypt, padapter->securitypriv.sw_encrypt));
  790. } else {
  791. pattrib->bswenc = _FALSE;
  792. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("update_attrib: bswenc=_FALSE\n"));
  793. }
  794. #ifdef CONFIG_CONCURRENT_MODE
  795. if((pattrib->encrypt && bmcast) || (pattrib->encrypt ==_WEP40_) || (pattrib->encrypt ==_WEP104_))
  796. {
  797. pattrib->bswenc = _TRUE;//force using sw enc.
  798. }
  799. #endif
  800. #ifdef CONFIG_WAPI_SUPPORT
  801. if(pattrib->encrypt == _SMS4_)
  802. pattrib->bswenc = _FALSE;
  803. #endif
  804. rtw_set_tx_chksum_offload(pkt, pattrib);
  805. exit:
  806. _func_exit_;
  807. return res;
  808. }
  809. static s32 xmitframe_addmic(_adapter *padapter, struct xmit_frame *pxmitframe){
  810. sint curfragnum,length;
  811. u8 *pframe, *payload,mic[8];
  812. struct mic_data micdata;
  813. //struct sta_info *stainfo;
  814. struct qos_priv *pqospriv= &(padapter->mlmepriv.qospriv);
  815. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  816. struct security_priv *psecuritypriv=&padapter->securitypriv;
  817. struct xmit_priv *pxmitpriv=&padapter->xmitpriv;
  818. u8 priority[4]={0x0,0x0,0x0,0x0};
  819. u8 hw_hdr_offset = 0;
  820. sint bmcst = IS_MCAST(pattrib->ra);
  821. /*
  822. if(pattrib->psta)
  823. {
  824. stainfo = pattrib->psta;
  825. }
  826. else
  827. {
  828. DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
  829. stainfo=rtw_get_stainfo(&padapter->stapriv ,&pattrib->ra[0]);
  830. }
  831. if(stainfo==NULL)
  832. {
  833. DBG_871X("%s, psta==NUL\n", __func__);
  834. return _FAIL;
  835. }
  836. if(!(stainfo->state &_FW_LINKED))
  837. {
  838. DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, stainfo->state);
  839. return _FAIL;
  840. }
  841. */
  842. _func_enter_;
  843. #ifdef CONFIG_USB_TX_AGGREGATION
  844. hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);;
  845. #else
  846. #ifdef CONFIG_TX_EARLY_MODE
  847. hw_hdr_offset = TXDESC_OFFSET+ EARLY_MODE_INFO_SIZE;
  848. #else
  849. hw_hdr_offset = TXDESC_OFFSET;
  850. #endif
  851. #endif
  852. if(pattrib->encrypt ==_TKIP_)//if(psecuritypriv->dot11PrivacyAlgrthm==_TKIP_PRIVACY_)
  853. {
  854. //encode mic code
  855. //if(stainfo!= NULL)
  856. {
  857. u8 null_key[16]={0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
  858. pframe = pxmitframe->buf_addr + hw_hdr_offset;
  859. if(bmcst)
  860. {
  861. if(_rtw_memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16)==_TRUE){
  862. //DbgPrint("\nxmitframe_addmic:stainfo->dot11tkiptxmickey==0\n");
  863. //rtw_msleep_os(10);
  864. return _FAIL;
  865. }
  866. //start to calculate the mic code
  867. rtw_secmicsetkey(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey);
  868. }
  869. else
  870. {
  871. if(_rtw_memcmp(&pattrib->dot11tkiptxmickey.skey[0],null_key, 16)==_TRUE){
  872. //DbgPrint("\nxmitframe_addmic:stainfo->dot11tkiptxmickey==0\n");
  873. //rtw_msleep_os(10);
  874. return _FAIL;
  875. }
  876. //start to calculate the mic code
  877. rtw_secmicsetkey(&micdata, &pattrib->dot11tkiptxmickey.skey[0]);
  878. }
  879. if(pframe[1]&1){ //ToDS==1
  880. rtw_secmicappend(&micdata, &pframe[16], 6); //DA
  881. if(pframe[1]&2) //From Ds==1
  882. rtw_secmicappend(&micdata, &pframe[24], 6);
  883. else
  884. rtw_secmicappend(&micdata, &pframe[10], 6);
  885. }
  886. else{ //ToDS==0
  887. rtw_secmicappend(&micdata, &pframe[4], 6); //DA
  888. if(pframe[1]&2) //From Ds==1
  889. rtw_secmicappend(&micdata, &pframe[16], 6);
  890. else
  891. rtw_secmicappend(&micdata, &pframe[10], 6);
  892. }
  893. //if(pqospriv->qos_option==1)
  894. if(pattrib->qos_en)
  895. priority[0]=(u8)pxmitframe->attrib.priority;
  896. rtw_secmicappend(&micdata, &priority[0], 4);
  897. payload=pframe;
  898. for(curfragnum=0;curfragnum<pattrib->nr_frags;curfragnum++){
  899. payload=(u8 *)RND4((SIZE_PTR)(payload));
  900. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("===curfragnum=%d, pframe= 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n",
  901. curfragnum,*payload, *(payload+1),*(payload+2),*(payload+3),*(payload+4),*(payload+5),*(payload+6),*(payload+7)));
  902. payload=payload+pattrib->hdrlen+pattrib->iv_len;
  903. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("curfragnum=%d pattrib->hdrlen=%d pattrib->iv_len=%d",curfragnum,pattrib->hdrlen,pattrib->iv_len));
  904. if((curfragnum+1)==pattrib->nr_frags){
  905. length=pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-( (pattrib->bswenc) ? pattrib->icv_len : 0);
  906. rtw_secmicappend(&micdata, payload,length);
  907. payload=payload+length;
  908. }
  909. else{
  910. length=pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-( (pattrib->bswenc) ? pattrib->icv_len : 0);
  911. rtw_secmicappend(&micdata, payload, length);
  912. payload=payload+length+pattrib->icv_len;
  913. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("curfragnum=%d length=%d pattrib->icv_len=%d",curfragnum,length,pattrib->icv_len));
  914. }
  915. }
  916. rtw_secgetmic(&micdata,&(mic[0]));
  917. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("xmitframe_addmic: before add mic code!!!\n"));
  918. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("xmitframe_addmic: pattrib->last_txcmdsz=%d!!!\n",pattrib->last_txcmdsz));
  919. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("xmitframe_addmic: mic[0]=0x%.2x ,mic[1]=0x%.2x ,mic[2]=0x%.2x ,mic[3]=0x%.2x \n\
  920. mic[4]=0x%.2x ,mic[5]=0x%.2x ,mic[6]=0x%.2x ,mic[7]=0x%.2x !!!!\n",
  921. mic[0],mic[1],mic[2],mic[3],mic[4],mic[5],mic[6],mic[7]));
  922. //add mic code and add the mic code length in last_txcmdsz
  923. _rtw_memcpy(payload, &(mic[0]),8);
  924. pattrib->last_txcmdsz+=8;
  925. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("\n ========last pkt========\n"));
  926. payload=payload-pattrib->last_txcmdsz+8;
  927. for(curfragnum=0;curfragnum<pattrib->last_txcmdsz;curfragnum=curfragnum+8)
  928. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,(" %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x ",
  929. *(payload+curfragnum), *(payload+curfragnum+1), *(payload+curfragnum+2),*(payload+curfragnum+3),
  930. *(payload+curfragnum+4),*(payload+curfragnum+5),*(payload+curfragnum+6),*(payload+curfragnum+7)));
  931. }
  932. /*
  933. else{
  934. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("xmitframe_addmic: rtw_get_stainfo==NULL!!!\n"));
  935. }
  936. */
  937. }
  938. _func_exit_;
  939. return _SUCCESS;
  940. }
  941. static s32 xmitframe_swencrypt(_adapter *padapter, struct xmit_frame *pxmitframe){
  942. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  943. //struct security_priv *psecuritypriv=&padapter->securitypriv;
  944. _func_enter_;
  945. //if((psecuritypriv->sw_encrypt)||(pattrib->bswenc))
  946. if(pattrib->bswenc)
  947. {
  948. //DBG_871X("start xmitframe_swencrypt\n");
  949. RT_TRACE(_module_rtl871x_xmit_c_,_drv_alert_,("### xmitframe_swencrypt\n"));
  950. switch(pattrib->encrypt){
  951. case _WEP40_:
  952. case _WEP104_:
  953. rtw_wep_encrypt(padapter, (u8 *)pxmitframe);
  954. break;
  955. case _TKIP_:
  956. rtw_tkip_encrypt(padapter, (u8 *)pxmitframe);
  957. break;
  958. case _AES_:
  959. rtw_aes_encrypt(padapter, (u8 * )pxmitframe);
  960. break;
  961. #ifdef CONFIG_WAPI_SUPPORT
  962. case _SMS4_:
  963. rtw_sms4_encrypt(padapter, (u8 * )pxmitframe);
  964. #endif
  965. default:
  966. break;
  967. }
  968. } else {
  969. RT_TRACE(_module_rtl871x_xmit_c_,_drv_notice_,("### xmitframe_hwencrypt\n"));
  970. }
  971. _func_exit_;
  972. return _SUCCESS;
  973. }
  974. s32 rtw_make_wlanhdr (_adapter *padapter , u8 *hdr, struct pkt_attrib *pattrib)
  975. {
  976. u16 *qc;
  977. struct rtw_ieee80211_hdr *pwlanhdr = (struct rtw_ieee80211_hdr *)hdr;
  978. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  979. struct qos_priv *pqospriv = &pmlmepriv->qospriv;
  980. u8 qos_option = _FALSE;
  981. #ifdef CONFIG_TDLS
  982. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  983. struct sta_priv *pstapriv = &padapter->stapriv;
  984. struct sta_info *ptdls_sta=NULL, *psta_backup=NULL;
  985. u8 direct_link=0;
  986. #endif //CONFIG_TDLS
  987. sint res = _SUCCESS;
  988. u16 *fctrl = &pwlanhdr->frame_ctl;
  989. //struct sta_info *psta;
  990. //sint bmcst = IS_MCAST(pattrib->ra);
  991. _func_enter_;
  992. /*
  993. psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
  994. if(pattrib->psta != psta)
  995. {
  996. DBG_871X("%s, pattrib->psta(%p) != psta(%p)\n", __func__, pattrib->psta, psta);
  997. return;
  998. }
  999. if(psta==NULL)
  1000. {
  1001. DBG_871X("%s, psta==NUL\n", __func__);
  1002. return _FAIL;
  1003. }
  1004. if(!(psta->state &_FW_LINKED))
  1005. {
  1006. DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  1007. return _FAIL;
  1008. }
  1009. */
  1010. _rtw_memset(hdr, 0, WLANHDR_OFFSET);
  1011. SetFrameSubType(fctrl, pattrib->subtype);
  1012. if (pattrib->subtype & WIFI_DATA_TYPE)
  1013. {
  1014. if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)) {
  1015. //to_ds = 1, fr_ds = 0;
  1016. #ifdef CONFIG_TDLS
  1017. if((ptdlsinfo->setup_state == TDLS_LINKED_STATE)){
  1018. ptdls_sta = rtw_get_stainfo(pstapriv, pattrib->dst);
  1019. if((ptdls_sta!=NULL)&&(ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE)&&(pattrib->ether_type!=0x0806)){
  1020. //TDLS data transfer, ToDS=0, FrDs=0
  1021. _rtw_memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
  1022. _rtw_memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
  1023. _rtw_memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), ETH_ALEN);
  1024. direct_link=1;
  1025. }else{
  1026. // 1.Data transfer to AP
  1027. // 2.Arp pkt will relayed by AP
  1028. SetToDs(fctrl);
  1029. _rtw_memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), ETH_ALEN);
  1030. _rtw_memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
  1031. _rtw_memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
  1032. }
  1033. }else
  1034. #endif //CONFIG_TDLS
  1035. {
  1036. //Data transfer to AP
  1037. SetToDs(fctrl);
  1038. _rtw_memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), ETH_ALEN);
  1039. _rtw_memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
  1040. _rtw_memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
  1041. }
  1042. if (pqospriv->qos_option)
  1043. qos_option = _TRUE;
  1044. }
  1045. else if ((check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) ) {
  1046. //to_ds = 0, fr_ds = 1;
  1047. SetFrDs(fctrl);
  1048. _rtw_memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
  1049. _rtw_memcpy(pwlanhdr->addr2, get_bssid(pmlmepriv), ETH_ALEN);
  1050. _rtw_memcpy(pwlanhdr->addr3, pattrib->src, ETH_ALEN);
  1051. if(pattrib->qos_en)
  1052. qos_option = _TRUE;
  1053. }
  1054. else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) ||
  1055. (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
  1056. _rtw_memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
  1057. _rtw_memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
  1058. _rtw_memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), ETH_ALEN);
  1059. if(pattrib->qos_en)
  1060. qos_option = _TRUE;
  1061. }
  1062. else {
  1063. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("fw_state:%x is not allowed to xmit frame\n", get_fwstate(pmlmepriv)));
  1064. res = _FAIL;
  1065. goto exit;
  1066. }
  1067. if(pattrib->mdata)
  1068. SetMData(fctrl);
  1069. if (pattrib->encrypt)
  1070. SetPrivacy(fctrl);
  1071. if (qos_option)
  1072. {
  1073. qc = (unsigned short *)(hdr + pattrib->hdrlen - 2);
  1074. if (pattrib->priority)
  1075. SetPriority(qc, pattrib->priority);
  1076. SetEOSP(qc, pattrib->eosp);
  1077. SetAckpolicy(qc, pattrib->ack_policy);
  1078. }
  1079. //TODO: fill HT Control Field
  1080. //Update Seq Num will be handled by f/w
  1081. {
  1082. struct sta_info *psta;
  1083. psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
  1084. if(pattrib->psta != psta)
  1085. {
  1086. DBG_871X("%s, pattrib->psta(%p) != psta(%p)\n", __func__, pattrib->psta, psta);
  1087. return _FAIL;
  1088. }
  1089. if(psta==NULL)
  1090. {
  1091. DBG_871X("%s, psta==NUL\n", __func__);
  1092. return _FAIL;
  1093. }
  1094. if(!(psta->state &_FW_LINKED))
  1095. {
  1096. DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  1097. return _FAIL;
  1098. }
  1099. //if(psta)
  1100. {
  1101. #ifdef CONFIG_TDLS
  1102. if(direct_link==1)
  1103. {
  1104. psta_backup = psta;
  1105. psta = ptdls_sta;
  1106. }
  1107. #endif //CONFIG_TDLS
  1108. psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
  1109. psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
  1110. pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
  1111. SetSeqNum(hdr, pattrib->seqnum);
  1112. #ifdef CONFIG_80211N_HT
  1113. //check if enable ampdu
  1114. if(pattrib->ht_en && psta->htpriv.ampdu_enable)
  1115. {
  1116. if(psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
  1117. pattrib->ampdu_en = _TRUE;
  1118. }
  1119. //re-check if enable ampdu by BA_starting_seqctrl
  1120. if(pattrib->ampdu_en == _TRUE)
  1121. {
  1122. u16 tx_seq;
  1123. tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
  1124. //check BA_starting_seqctrl
  1125. if(SN_LESS(pattrib->seqnum, tx_seq))
  1126. {
  1127. //DBG_871X("tx ampdu seqnum(%d) < tx_seq(%d)\n", pattrib->seqnum, tx_seq);
  1128. pattrib->ampdu_en = _FALSE;//AGG BK
  1129. }
  1130. else if(SN_EQUAL(pattrib->seqnum, tx_seq))
  1131. {
  1132. psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
  1133. pattrib->ampdu_en = _TRUE;//AGG EN
  1134. }
  1135. else
  1136. {
  1137. //DBG_871X("tx ampdu over run\n");
  1138. psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
  1139. pattrib->ampdu_en = _TRUE;//AGG EN
  1140. }
  1141. }
  1142. #endif //CONFIG_80211N_HT
  1143. #ifdef CONFIG_TDLS
  1144. if(direct_link==1)
  1145. {
  1146. if (pattrib->encrypt){
  1147. pattrib->encrypt= _AES_;
  1148. pattrib->iv_len=8;
  1149. pattrib->icv_len=8;
  1150. }
  1151. //qos_en, ht_en, init rate, ,bw, ch_offset, sgi
  1152. //pattrib->qos_en = ptdls_sta->qos_option;
  1153. pattrib->raid = ptdls_sta->raid;
  1154. #ifdef CONFIG_80211N_HT
  1155. pattrib->bwmode = ptdls_sta->htpriv.bwmode;
  1156. pattrib->ht_en = ptdls_sta->htpriv.ht_option;
  1157. pattrib->ch_offset = ptdls_sta->htpriv.ch_offset;
  1158. pattrib->sgi= ptdls_sta->htpriv.sgi;
  1159. #endif //CONFIG_80211N_HT
  1160. pattrib->mac_id = ptdls_sta->mac_id;
  1161. psta = psta_backup;
  1162. }
  1163. #endif //CONFIG_TDLS
  1164. }
  1165. }
  1166. }
  1167. else
  1168. {
  1169. }
  1170. exit:
  1171. _func_exit_;
  1172. return res;
  1173. }
  1174. s32 rtw_txframes_pending(_adapter *padapter)
  1175. {
  1176. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1177. return ((_rtw_queue_empty(&pxmitpriv->be_pending) == _FALSE) ||
  1178. (_rtw_queue_empty(&pxmitpriv->bk_pending) == _FALSE) ||
  1179. (_rtw_queue_empty(&pxmitpriv->vi_pending) == _FALSE) ||
  1180. (_rtw_queue_empty(&pxmitpriv->vo_pending) == _FALSE));
  1181. }
  1182. s32 rtw_txframes_sta_ac_pending(_adapter *padapter, struct pkt_attrib *pattrib)
  1183. {
  1184. struct sta_info *psta;
  1185. struct tx_servq *ptxservq;
  1186. int priority = pattrib->priority;
  1187. /*
  1188. if(pattrib->psta)
  1189. {
  1190. psta = pattrib->psta;
  1191. }
  1192. else
  1193. {
  1194. DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
  1195. psta=rtw_get_stainfo(&padapter->stapriv ,&pattrib->ra[0]);
  1196. }
  1197. */
  1198. psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
  1199. if(pattrib->psta != psta)
  1200. {
  1201. DBG_871X("%s, pattrib->psta(%p) != psta(%p)\n", __func__, pattrib->psta, psta);
  1202. return 0;
  1203. }
  1204. if(psta==NULL)
  1205. {
  1206. DBG_871X("%s, psta==NUL\n", __func__);
  1207. return 0;
  1208. }
  1209. if(!(psta->state &_FW_LINKED))
  1210. {
  1211. DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  1212. return 0;
  1213. }
  1214. switch(priority)
  1215. {
  1216. case 1:
  1217. case 2:
  1218. ptxservq = &(psta->sta_xmitpriv.bk_q);
  1219. break;
  1220. case 4:
  1221. case 5:
  1222. ptxservq = &(psta->sta_xmitpriv.vi_q);
  1223. break;
  1224. case 6:
  1225. case 7:
  1226. ptxservq = &(psta->sta_xmitpriv.vo_q);
  1227. break;
  1228. case 0:
  1229. case 3:
  1230. default:
  1231. ptxservq = &(psta->sta_xmitpriv.be_q);
  1232. break;
  1233. }
  1234. return ptxservq->qcnt;
  1235. }
  1236. #ifdef CONFIG_TDLS
  1237. int rtw_build_tdls_ies(_adapter * padapter, struct xmit_frame * pxmitframe, u8 *pframe, u8 action)
  1238. {
  1239. int res=_SUCCESS;
  1240. switch(action){
  1241. case TDLS_SETUP_REQUEST:
  1242. rtw_build_tdls_setup_req_ies(padapter, pxmitframe, pframe);
  1243. break;
  1244. case TDLS_SETUP_RESPONSE:
  1245. rtw_build_tdls_setup_rsp_ies(padapter, pxmitframe, pframe);
  1246. break;
  1247. case TDLS_SETUP_CONFIRM:
  1248. rtw_build_tdls_setup_cfm_ies(padapter, pxmitframe, pframe);
  1249. break;
  1250. case TDLS_TEARDOWN:
  1251. rtw_build_tdls_teardown_ies(padapter, pxmitframe, pframe);
  1252. break;
  1253. case TDLS_DISCOVERY_REQUEST:
  1254. rtw_build_tdls_dis_req_ies(padapter, pxmitframe, pframe);
  1255. break;
  1256. case TDLS_PEER_TRAFFIC_INDICATION:
  1257. rtw_build_tdls_peer_traffic_indication_ies(padapter, pxmitframe, pframe);
  1258. break;
  1259. case TDLS_CHANNEL_SWITCH_REQUEST:
  1260. rtw_build_tdls_ch_switch_req_ies(padapter, pxmitframe, pframe);
  1261. break;
  1262. case TDLS_CHANNEL_SWITCH_RESPONSE:
  1263. rtw_build_tdls_ch_switch_rsp_ies(padapter, pxmitframe, pframe);
  1264. break;
  1265. #ifdef CONFIG_WFD
  1266. case TUNNELED_PROBE_REQ:
  1267. rtw_build_tunneled_probe_req_ies(padapter, pxmitframe, pframe);
  1268. break;
  1269. case TUNNELED_PROBE_RSP:
  1270. rtw_build_tunneled_probe_rsp_ies(padapter, pxmitframe, pframe);
  1271. break;
  1272. #endif //CONFIG_WFD
  1273. default:
  1274. res=_FAIL;
  1275. break;
  1276. }
  1277. return res;
  1278. }
  1279. s32 rtw_make_tdls_wlanhdr (_adapter *padapter , u8 *hdr, struct pkt_attrib *pattrib, u8 action)
  1280. {
  1281. u16 *qc;
  1282. struct rtw_ieee80211_hdr *pwlanhdr = (struct rtw_ieee80211_hdr *)hdr;
  1283. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1284. struct qos_priv *pqospriv = &pmlmepriv->qospriv;
  1285. struct sta_priv *pstapriv = &padapter->stapriv;
  1286. struct sta_info *psta=NULL, *ptdls_sta=NULL;
  1287. u8 tdls_seq=0, baddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  1288. sint res = _SUCCESS;
  1289. u16 *fctrl = &pwlanhdr->frame_ctl;
  1290. _func_enter_;
  1291. _rtw_memset(hdr, 0, WLANHDR_OFFSET);
  1292. SetFrameSubType(fctrl, pattrib->subtype);
  1293. switch(action){
  1294. case TDLS_SETUP_REQUEST:
  1295. case TDLS_SETUP_RESPONSE:
  1296. case TDLS_SETUP_CONFIRM:
  1297. case TDLS_TEARDOWN: //directly to peer STA or via AP
  1298. case TDLS_PEER_TRAFFIC_INDICATION:
  1299. case TDLS_PEER_PSM_REQUEST: //directly to peer STA or via AP
  1300. case TUNNELED_PROBE_REQ:
  1301. case TUNNELED_PROBE_RSP:
  1302. SetToDs(fctrl);
  1303. _rtw_memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), ETH_ALEN);
  1304. _rtw_memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
  1305. _rtw_memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
  1306. break;
  1307. case TDLS_CHANNEL_SWITCH_REQUEST:
  1308. case TDLS_CHANNEL_SWITCH_RESPONSE:
  1309. case TDLS_PEER_PSM_RESPONSE:
  1310. case TDLS_PEER_TRAFFIC_RESPONSE:
  1311. _rtw_memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
  1312. _rtw_memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
  1313. _rtw_memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), ETH_ALEN);
  1314. tdls_seq=1;
  1315. break;
  1316. case TDLS_DISCOVERY_REQUEST: //unicast: directly to peer sta, Bcast: via AP
  1317. if(_rtw_memcmp(pattrib->dst, baddr, ETH_ALEN) )
  1318. {
  1319. SetToDs(fctrl);
  1320. _rtw_memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), ETH_ALEN);
  1321. _rtw_memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
  1322. _rtw_memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
  1323. }
  1324. else
  1325. {
  1326. _rtw_memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
  1327. _rtw_memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
  1328. _rtw_memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), ETH_ALEN);
  1329. tdls_seq=1;
  1330. }
  1331. break;
  1332. }
  1333. if (pattrib->encrypt)
  1334. SetPrivacy(fctrl);
  1335. if (pqospriv->qos_option)
  1336. {
  1337. qc = (unsigned short *)(hdr + pattrib->hdrlen - 2);
  1338. if (pattrib->priority)
  1339. SetPriority(qc, pattrib->priority);
  1340. SetAckpolicy(qc, pattrib->ack_policy);
  1341. }
  1342. psta = pattrib->psta;
  1343. // 1. update seq_num per link by sta_info
  1344. // 2. rewrite encrypt to _AES_, also rewrite iv_len, icv_len
  1345. if(tdls_seq==1){
  1346. ptdls_sta=rtw_get_stainfo(pstapriv, pattrib->dst);
  1347. if(ptdls_sta){
  1348. ptdls_sta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
  1349. ptdls_sta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
  1350. pattrib->seqnum = ptdls_sta->sta_xmitpriv.txseq_tid[pattrib->priority];
  1351. SetSeqNum(hdr, pattrib->seqnum);
  1352. if (pattrib->encrypt){
  1353. pattrib->encrypt= _AES_;
  1354. pattrib->iv_len=8;
  1355. pattrib->icv_len=8;
  1356. }
  1357. }else{
  1358. res=_FAIL;
  1359. goto exit;
  1360. }
  1361. }else if(psta){
  1362. psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
  1363. psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
  1364. pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
  1365. SetSeqNum(hdr, pattrib->seqnum);
  1366. }
  1367. exit:
  1368. _func_exit_;
  1369. return res;
  1370. }
  1371. s32 rtw_xmit_tdls_coalesce(_adapter * padapter, struct xmit_frame * pxmitframe, u8 action)
  1372. {
  1373. s32 llc_sz;
  1374. u8 *pframe, *mem_start;
  1375. struct sta_info *psta;
  1376. struct sta_priv *pstapriv = &padapter->stapriv;
  1377. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1378. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1379. u8 *pbuf_start;
  1380. s32 bmcst = IS_MCAST(pattrib->ra);
  1381. s32 res = _SUCCESS;
  1382. _func_enter_;
  1383. if (pattrib->psta) {
  1384. psta = pattrib->psta;
  1385. } else {
  1386. if(bmcst) {
  1387. psta = rtw_get_bcmc_stainfo(padapter);
  1388. } else {
  1389. psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
  1390. }
  1391. }
  1392. if(psta==NULL)
  1393. return _FAIL;
  1394. if (pxmitframe->buf_addr == NULL)
  1395. return _FAIL;
  1396. pbuf_start = pxmitframe->buf_addr;
  1397. mem_start = pbuf_start + TXDESC_OFFSET;
  1398. if (rtw_make_tdls_wlanhdr(padapter, mem_start, pattrib, action) == _FAIL) {
  1399. res = _FAIL;
  1400. goto exit;
  1401. }
  1402. pframe = mem_start;
  1403. pframe += pattrib->hdrlen;
  1404. //adding icv, if necessary...
  1405. if (pattrib->iv_len)
  1406. {
  1407. if (psta != NULL)
  1408. {
  1409. switch(pattrib->encrypt)
  1410. {
  1411. case _WEP40_:
  1412. case _WEP104_:
  1413. WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
  1414. break;
  1415. case _TKIP_:
  1416. if(bmcst)
  1417. TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
  1418. else
  1419. TKIP_IV(pattrib->iv, psta->dot11txpn, 0);
  1420. break;
  1421. case _AES_:
  1422. if(bmcst)
  1423. AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
  1424. else
  1425. AES_IV(pattrib->iv, psta->dot11txpn, 0);
  1426. break;
  1427. }
  1428. }
  1429. _rtw_memcpy(pframe, pattrib->iv, pattrib->iv_len);
  1430. pframe += pattrib->iv_len;
  1431. }
  1432. llc_sz = rtw_put_snap(pframe, pattrib->ether_type);
  1433. pframe += llc_sz;
  1434. //pattrib->pktlen will be counted in rtw_build_tdls_ies
  1435. pattrib->pktlen = 0;
  1436. rtw_build_tdls_ies(padapter, pxmitframe, pframe, action);
  1437. if ((pattrib->icv_len >0 )&& (pattrib->bswenc)) {
  1438. pframe += pattrib->pktlen;
  1439. _rtw_memcpy(pframe, pattrib->icv, pattrib->icv_len);
  1440. pframe += pattrib->icv_len;
  1441. }
  1442. pattrib->nr_frags = 1;
  1443. pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + llc_sz +
  1444. ((pattrib->bswenc) ? pattrib->icv_len : 0) + pattrib->pktlen;
  1445. if (xmitframe_addmic(padapter, pxmitframe) == _FAIL)
  1446. {
  1447. goto exit;
  1448. }
  1449. xmitframe_swencrypt(padapter, pxmitframe);
  1450. update_attrib_vcs_info(padapter, pxmitframe);
  1451. exit:
  1452. _func_exit_;
  1453. return res;
  1454. }
  1455. #endif //CONFIG_TDLS
  1456. /*
  1457. * Calculate wlan 802.11 packet MAX size from pkt_attrib
  1458. * This function doesn't consider fragment case
  1459. */
  1460. u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib)
  1461. {
  1462. u32 len = 0;
  1463. len = pattrib->hdrlen + pattrib->iv_len; // WLAN Header and IV
  1464. len += SNAP_SIZE + sizeof(u16); // LLC
  1465. len += pattrib->pktlen;
  1466. if (pattrib->encrypt == _TKIP_) len += 8; // MIC
  1467. len += ((pattrib->bswenc) ? pattrib->icv_len : 0); // ICV
  1468. return len;
  1469. }
  1470. /*
  1471. This sub-routine will perform all the following:
  1472. 1. remove 802.3 header.
  1473. 2. create wlan_header, based on the info in pxmitframe
  1474. 3. append sta's iv/ext-iv
  1475. 4. append LLC
  1476. 5. move frag chunk from pframe to pxmitframe->mem
  1477. 6. apply sw-encrypt, if necessary.
  1478. */
  1479. s32 rtw_xmitframe_coalesce(_adapter *padapter, _pkt *pkt, struct xmit_frame *pxmitframe)
  1480. {
  1481. struct pkt_file pktfile;
  1482. s32 frg_inx, frg_len, mpdu_len, llc_sz, mem_sz;
  1483. SIZE_PTR addr;
  1484. u8 *pframe, *mem_start;
  1485. u8 hw_hdr_offset;
  1486. //struct sta_info *psta;
  1487. //struct sta_priv *pstapriv = &padapter->stapriv;
  1488. //struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1489. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1490. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  1491. u8 *pbuf_start;
  1492. s32 bmcst = IS_MCAST(pattrib->ra);
  1493. s32 res = _SUCCESS;
  1494. _func_enter_;
  1495. /*
  1496. if (pattrib->psta)
  1497. {
  1498. psta = pattrib->psta;
  1499. } else
  1500. {
  1501. DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
  1502. psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
  1503. }
  1504. if(psta==NULL)
  1505. {
  1506. DBG_871X("%s, psta==NUL\n", __func__);
  1507. return _FAIL;
  1508. }
  1509. if(!(psta->state &_FW_LINKED))
  1510. {
  1511. DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  1512. return _FAIL;
  1513. }
  1514. */
  1515. if (pxmitframe->buf_addr == NULL){
  1516. DBG_8192C("==> %s buf_addr==NULL \n",__FUNCTION__);
  1517. return _FAIL;
  1518. }
  1519. pbuf_start = pxmitframe->buf_addr;
  1520. #ifdef CONFIG_USB_TX_AGGREGATION
  1521. hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);
  1522. #else
  1523. #ifdef CONFIG_TX_EARLY_MODE //for SDIO && Tx Agg
  1524. hw_hdr_offset = TXDESC_OFFSET + EARLY_MODE_INFO_SIZE;
  1525. #else
  1526. hw_hdr_offset = TXDESC_OFFSET;
  1527. #endif
  1528. #endif
  1529. mem_start = pbuf_start + hw_hdr_offset;
  1530. if (rtw_make_wlanhdr(padapter, mem_start, pattrib) == _FAIL) {
  1531. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n"));
  1532. DBG_8192C("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n");
  1533. res = _FAIL;
  1534. goto exit;
  1535. }
  1536. _rtw_open_pktfile(pkt, &pktfile);
  1537. _rtw_pktfile_read(&pktfile, NULL, pattrib->pkt_hdrlen);
  1538. frg_inx = 0;
  1539. frg_len = pxmitpriv->frag_len - 4;//2346-4 = 2342
  1540. while (1)
  1541. {
  1542. llc_sz = 0;
  1543. mpdu_len = frg_len;
  1544. pframe = mem_start;
  1545. SetMFrag(mem_start);
  1546. pframe += pattrib->hdrlen;
  1547. mpdu_len -= pattrib->hdrlen;
  1548. //adding icv, if necessary...
  1549. if (pattrib->iv_len)
  1550. {
  1551. /*
  1552. //if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
  1553. // psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
  1554. //else
  1555. // psta = rtw_get_stainfo(pstapriv, pattrib->ra);
  1556. if (psta != NULL)
  1557. {
  1558. switch(pattrib->encrypt)
  1559. {
  1560. case _WEP40_:
  1561. case _WEP104_:
  1562. WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
  1563. break;
  1564. case _TKIP_:
  1565. if(bmcst)
  1566. TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
  1567. else
  1568. TKIP_IV(pattrib->iv, psta->dot11txpn, 0);
  1569. break;
  1570. case _AES_:
  1571. if(bmcst)
  1572. AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
  1573. else
  1574. AES_IV(pattrib->iv, psta->dot11txpn, 0);
  1575. break;
  1576. #ifdef CONFIG_WAPI_SUPPORT
  1577. case _SMS4_:
  1578. rtw_wapi_get_iv(padapter,pattrib->ra,pattrib->iv);
  1579. break;
  1580. #endif
  1581. }
  1582. }
  1583. */
  1584. _rtw_memcpy(pframe, pattrib->iv, pattrib->iv_len);
  1585. RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
  1586. ("rtw_xmitframe_coalesce: keyid=%d pattrib->iv[3]=%.2x pframe=%.2x %.2x %.2x %.2x\n",
  1587. padapter->securitypriv.dot11PrivacyKeyIndex, pattrib->iv[3], *pframe, *(pframe+1), *(pframe+2), *(pframe+3)));
  1588. pframe += pattrib->iv_len;
  1589. mpdu_len -= pattrib->iv_len;
  1590. }
  1591. if (frg_inx == 0) {
  1592. llc_sz = rtw_put_snap(pframe, pattrib->ether_type);
  1593. pframe += llc_sz;
  1594. mpdu_len -= llc_sz;
  1595. }
  1596. if ((pattrib->icv_len >0) && (pattrib->bswenc)) {
  1597. mpdu_len -= pattrib->icv_len;
  1598. }
  1599. if (bmcst) {
  1600. // don't do fragment to broadcat/multicast packets
  1601. mem_sz = _rtw_pktfile_read(&pktfile, pframe, pattrib->pktlen);
  1602. } else {
  1603. mem_sz = _rtw_pktfile_read(&pktfile, pframe, mpdu_len);
  1604. }
  1605. pframe += mem_sz;
  1606. if ((pattrib->icv_len >0 )&& (pattrib->bswenc)) {
  1607. _rtw_memcpy(pframe, pattrib->icv, pattrib->icv_len);
  1608. pframe += pattrib->icv_len;
  1609. }
  1610. frg_inx++;
  1611. if (bmcst || (rtw_endofpktfile(&pktfile) == _TRUE))
  1612. {
  1613. pattrib->nr_frags = frg_inx;
  1614. pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + ((pattrib->nr_frags==1)? llc_sz:0) +
  1615. ((pattrib->bswenc) ? pattrib->icv_len : 0) + mem_sz;
  1616. ClearMFrag(mem_start);
  1617. break;
  1618. } else {
  1619. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("%s: There're still something in packet!\n", __FUNCTION__));
  1620. }
  1621. addr = (SIZE_PTR)(pframe);
  1622. mem_start = (unsigned char *)RND4(addr) + hw_hdr_offset;
  1623. _rtw_memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen);
  1624. }
  1625. if (xmitframe_addmic(padapter, pxmitframe) == _FAIL)
  1626. {
  1627. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic(padapter, pxmitframe)==_FAIL\n"));
  1628. DBG_8192C("xmitframe_addmic(padapter, pxmitframe)==_FAIL\n");
  1629. res = _FAIL;
  1630. goto exit;
  1631. }
  1632. xmitframe_swencrypt(padapter, pxmitframe);
  1633. if(bmcst == _FALSE)
  1634. update_attrib_vcs_info(padapter, pxmitframe);
  1635. else
  1636. pattrib->vcs_mode = NONE_VCS;
  1637. exit:
  1638. _func_exit_;
  1639. return res;
  1640. }
  1641. /* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
  1642. * IEEE LLC/SNAP header contains 8 octets
  1643. * First 3 octets comprise the LLC portion
  1644. * SNAP portion, 5 octets, is divided into two fields:
  1645. * Organizationally Unique Identifier(OUI), 3 octets,
  1646. * type, defined by that organization, 2 octets.
  1647. */
  1648. s32 rtw_put_snap(u8 *data, u16 h_proto)
  1649. {
  1650. struct ieee80211_snap_hdr *snap;
  1651. u8 *oui;
  1652. _func_enter_;
  1653. snap = (struct ieee80211_snap_hdr *)data;
  1654. snap->dsap = 0xaa;
  1655. snap->ssap = 0xaa;
  1656. snap->ctrl = 0x03;
  1657. if (h_proto == 0x8137 || h_proto == 0x80f3)
  1658. oui = P802_1H_OUI;
  1659. else
  1660. oui = RFC1042_OUI;
  1661. snap->oui[0] = oui[0];
  1662. snap->oui[1] = oui[1];
  1663. snap->oui[2] = oui[2];
  1664. *(u16 *)(data + SNAP_SIZE) = htons(h_proto);
  1665. _func_exit_;
  1666. return SNAP_SIZE + sizeof(u16);
  1667. }
  1668. void rtw_update_protection(_adapter *padapter, u8 *ie, uint ie_len)
  1669. {
  1670. uint protection;
  1671. u8 *perp;
  1672. sint erp_len;
  1673. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1674. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1675. _func_enter_;
  1676. switch(pxmitpriv->vcs_setting)
  1677. {
  1678. case DISABLE_VCS:
  1679. pxmitpriv->vcs = NONE_VCS;
  1680. break;
  1681. case ENABLE_VCS:
  1682. break;
  1683. case AUTO_VCS:
  1684. default:
  1685. perp = rtw_get_ie(ie, _ERPINFO_IE_, &erp_len, ie_len);
  1686. if(perp == NULL)
  1687. {
  1688. pxmitpriv->vcs = NONE_VCS;
  1689. }
  1690. else
  1691. {
  1692. protection = (*(perp + 2)) & BIT(1);
  1693. if (protection)
  1694. {
  1695. if(pregistrypriv->vcs_type == RTS_CTS)
  1696. pxmitpriv->vcs = RTS_CTS;
  1697. else
  1698. pxmitpriv->vcs = CTS_TO_SELF;
  1699. }
  1700. else
  1701. pxmitpriv->vcs = NONE_VCS;
  1702. }
  1703. break;
  1704. }
  1705. _func_exit_;
  1706. }
  1707. void rtw_count_tx_stats(PADAPTER padapter, struct xmit_frame *pxmitframe, int sz)
  1708. {
  1709. struct sta_info *psta = NULL;
  1710. struct stainfo_stats *pstats = NULL;
  1711. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1712. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1713. if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG)
  1714. {
  1715. pxmitpriv->tx_bytes += sz;
  1716. #if defined(CONFIG_USB_TX_AGGREGATION) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1717. pmlmepriv->LinkDetectInfo.NumTxOkInPeriod += pxmitframe->agg_num;
  1718. #else
  1719. pmlmepriv->LinkDetectInfo.NumTxOkInPeriod++;
  1720. #endif
  1721. psta = pxmitframe->attrib.psta;
  1722. if (psta)
  1723. {
  1724. pstats = &psta->sta_stats;
  1725. #if defined(CONFIG_USB_TX_AGGREGATION) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1726. pstats->tx_pkts += pxmitframe->agg_num;
  1727. #else
  1728. pstats->tx_pkts++;
  1729. #endif
  1730. pstats->tx_bytes += sz;
  1731. }
  1732. }
  1733. }
  1734. struct xmit_buf *rtw_alloc_cmd_xmitbuf(struct xmit_priv *pxmitpriv, u32 buffsize)
  1735. {
  1736. struct xmit_buf *pxmitbuf = NULL;
  1737. _func_enter_;
  1738. pxmitbuf = &pxmitpriv->pcmd_xmitbuf;
  1739. if (pxmitbuf != NULL) {
  1740. if(rtw_os_xmit_resource_alloc(pxmitpriv->adapter, pxmitbuf,(buffsize + XMITBUF_ALIGN_SZ), _FALSE) == _FAIL) {
  1741. return NULL;
  1742. }
  1743. pxmitbuf->alloc_sz = buffsize + XMITBUF_ALIGN_SZ;
  1744. pxmitbuf->priv_data = NULL;
  1745. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1746. pxmitbuf->phead = pxmitbuf->pbuf;
  1747. pxmitbuf->pend = pxmitbuf->pbuf + buffsize;
  1748. pxmitbuf->len = 0;
  1749. pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
  1750. #endif
  1751. #ifdef CONFIG_PCI_HCI
  1752. pxmitbuf->len = 0;
  1753. #endif
  1754. if (pxmitbuf->sctx) {
  1755. DBG_871X("%s pxmitbuf->sctx is not NULL\n", __func__);
  1756. rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
  1757. }
  1758. } else {
  1759. DBG_871X("%s fail, no xmitbuf available !!!\n", __func__);
  1760. }
  1761. _func_exit_;
  1762. return pxmitbuf;
  1763. }
  1764. s32 rtw_free_cmd_xmitbuf(struct xmit_priv *pxmitpriv)
  1765. {
  1766. struct xmit_buf *pxmitbuf = NULL;
  1767. _func_enter_;
  1768. pxmitbuf = &pxmitpriv->pcmd_xmitbuf;
  1769. if (pxmitbuf==NULL) {
  1770. DBG_871X("%s fail, no xmitbuf available !!!\n", __func__);
  1771. return _FAIL;
  1772. } else {
  1773. rtw_os_xmit_resource_free(pxmitbuf->padapter, pxmitbuf, pxmitbuf->alloc_sz, _FALSE);
  1774. }
  1775. _func_exit_;
  1776. return _SUCCESS;
  1777. }
  1778. struct xmit_frame *rtw_alloc_cmdxmitframe(struct xmit_priv *pxmitpriv, u32 buffsize)
  1779. {
  1780. struct xmit_frame *pcmdframe;
  1781. struct xmit_buf *pxmitbuf;
  1782. if ((pcmdframe = rtw_alloc_xmitframe(pxmitpriv)) == NULL)
  1783. {
  1784. DBG_871X("%s, alloc xmitframe fail\n", __FUNCTION__);
  1785. return NULL;
  1786. }
  1787. if ((pxmitbuf = rtw_alloc_cmd_xmitbuf(pxmitpriv, buffsize)) == NULL) {
  1788. DBG_871X("%s, alloc xmitbuf fail\n", __FUNCTION__);
  1789. rtw_free_xmitframe(pxmitpriv, pcmdframe);
  1790. return NULL;
  1791. }
  1792. pcmdframe->frame_tag = MGNT_FRAMETAG;
  1793. pcmdframe->pxmitbuf = pxmitbuf;
  1794. pcmdframe->buf_addr = pxmitbuf->pbuf;
  1795. pxmitbuf->priv_data = pcmdframe;
  1796. return pcmdframe;
  1797. }
  1798. void rtw_free_cmdxmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe)
  1799. {
  1800. rtw_free_xmitframe(pxmitpriv, pxmitframe);
  1801. rtw_free_cmd_xmitbuf(pxmitpriv);
  1802. }
  1803. struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv)
  1804. {
  1805. _irqL irqL;
  1806. struct xmit_buf *pxmitbuf = NULL;
  1807. _list *plist, *phead;
  1808. _queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
  1809. _func_enter_;
  1810. _enter_critical(&pfree_queue->lock, &irqL);
  1811. if(_rtw_queue_empty(pfree_queue) == _TRUE) {
  1812. pxmitbuf = NULL;
  1813. } else {
  1814. phead = get_list_head(pfree_queue);
  1815. plist = get_next(phead);
  1816. pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
  1817. rtw_list_delete(&(pxmitbuf->list));
  1818. }
  1819. if (pxmitbuf != NULL)
  1820. {
  1821. pxmitpriv->free_xmit_extbuf_cnt--;
  1822. #ifdef DBG_XMIT_BUF_EXT
  1823. DBG_871X("DBG_XMIT_BUF_EXT ALLOC no=%d, free_xmit_extbuf_cnt=%d\n",pxmitbuf->no, pxmitpriv->free_xmit_extbuf_cnt);
  1824. #endif
  1825. pxmitbuf->priv_data = NULL;
  1826. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1827. pxmitbuf->len = 0;
  1828. pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
  1829. #endif
  1830. #ifdef CONFIG_PCI_HCI
  1831. pxmitbuf->len = 0;
  1832. #endif
  1833. if (pxmitbuf->sctx) {
  1834. DBG_871X("%s pxmitbuf->sctx is not NULL\n", __func__);
  1835. rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
  1836. }
  1837. }
  1838. _exit_critical(&pfree_queue->lock, &irqL);
  1839. _func_exit_;
  1840. return pxmitbuf;
  1841. }
  1842. s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
  1843. {
  1844. _irqL irqL;
  1845. _queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
  1846. _func_enter_;
  1847. if(pxmitbuf==NULL)
  1848. {
  1849. return _FAIL;
  1850. }
  1851. _enter_critical(&pfree_queue->lock, &irqL);
  1852. rtw_list_delete(&pxmitbuf->list);
  1853. rtw_list_insert_tail(&(pxmitbuf->list), get_list_head(pfree_queue));
  1854. pxmitpriv->free_xmit_extbuf_cnt++;
  1855. #ifdef DBG_XMIT_BUF_EXT
  1856. DBG_871X("DBG_XMIT_BUF_EXT FREE no=%d, free_xmit_extbuf_cnt=%d\n",pxmitbuf->no ,pxmitpriv->free_xmit_extbuf_cnt);
  1857. #endif
  1858. _exit_critical(&pfree_queue->lock, &irqL);
  1859. _func_exit_;
  1860. return _SUCCESS;
  1861. }
  1862. struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
  1863. {
  1864. _irqL irqL;
  1865. struct xmit_buf *pxmitbuf = NULL;
  1866. _list *plist, *phead;
  1867. _queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
  1868. _func_enter_;
  1869. //DBG_871X("+rtw_alloc_xmitbuf\n");
  1870. _enter_critical(&pfree_xmitbuf_queue->lock, &irqL);
  1871. if(_rtw_queue_empty(pfree_xmitbuf_queue) == _TRUE) {
  1872. pxmitbuf = NULL;
  1873. } else {
  1874. phead = get_list_head(pfree_xmitbuf_queue);
  1875. plist = get_next(phead);
  1876. pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
  1877. rtw_list_delete(&(pxmitbuf->list));
  1878. }
  1879. if (pxmitbuf != NULL)
  1880. {
  1881. pxmitpriv->free_xmitbuf_cnt--;
  1882. #ifdef DBG_XMIT_BUF
  1883. DBG_871X("DBG_XMIT_BUF ALLOC no=%d, free_xmitbuf_cnt=%d\n",pxmitbuf->no, pxmitpriv->free_xmitbuf_cnt);
  1884. #endif
  1885. //DBG_871X("alloc, free_xmitbuf_cnt=%d\n", pxmitpriv->free_xmitbuf_cnt);
  1886. pxmitbuf->priv_data = NULL;
  1887. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1888. pxmitbuf->len = 0;
  1889. pxmitbuf->pdata = pxmitbuf->ptail = pxmitbuf->phead;
  1890. pxmitbuf->agg_num = 0;
  1891. pxmitbuf->pg_num = 0;
  1892. #endif
  1893. #ifdef CONFIG_PCI_HCI
  1894. pxmitbuf->len = 0;
  1895. #endif
  1896. if (pxmitbuf->sctx) {
  1897. DBG_871X("%s pxmitbuf->sctx is not NULL\n", __func__);
  1898. rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
  1899. }
  1900. }
  1901. #ifdef DBG_XMIT_BUF
  1902. else
  1903. {
  1904. DBG_871X("DBG_XMIT_BUF rtw_alloc_xmitbuf return NULL\n");
  1905. }
  1906. #endif
  1907. _exit_critical(&pfree_xmitbuf_queue->lock, &irqL);
  1908. _func_exit_;
  1909. return pxmitbuf;
  1910. }
  1911. s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
  1912. {
  1913. _irqL irqL;
  1914. _queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
  1915. _func_enter_;
  1916. //DBG_871X("+rtw_free_xmitbuf\n");
  1917. if(pxmitbuf==NULL)
  1918. {
  1919. return _FAIL;
  1920. }
  1921. if (pxmitbuf->sctx) {
  1922. DBG_871X("%s pxmitbuf->sctx is not NULL\n", __func__);
  1923. rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_FREE);
  1924. }
  1925. if(pxmitbuf->buf_tag == XMITBUF_CMD) {
  1926. }
  1927. else if(pxmitbuf->buf_tag == XMITBUF_MGNT) {
  1928. rtw_free_xmitbuf_ext(pxmitpriv, pxmitbuf);
  1929. }
  1930. else
  1931. {
  1932. _enter_critical(&pfree_xmitbuf_queue->lock, &irqL);
  1933. rtw_list_delete(&pxmitbuf->list);
  1934. rtw_list_insert_tail(&(pxmitbuf->list), get_list_head(pfree_xmitbuf_queue));
  1935. pxmitpriv->free_xmitbuf_cnt++;
  1936. //DBG_871X("FREE, free_xmitbuf_cnt=%d\n", pxmitpriv->free_xmitbuf_cnt);
  1937. #ifdef DBG_XMIT_BUF
  1938. DBG_871X("DBG_XMIT_BUF FREE no=%d, free_xmitbuf_cnt=%d\n",pxmitbuf->no ,pxmitpriv->free_xmitbuf_cnt);
  1939. #endif
  1940. _exit_critical(&pfree_xmitbuf_queue->lock, &irqL);
  1941. }
  1942. _func_exit_;
  1943. return _SUCCESS;
  1944. }
  1945. void rtw_init_xmitframe(struct xmit_frame *pxframe)
  1946. {
  1947. if (pxframe != NULL)//default value setting
  1948. {
  1949. pxframe->buf_addr = NULL;
  1950. pxframe->pxmitbuf = NULL;
  1951. _rtw_memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib));
  1952. //pxframe->attrib.psta = NULL;
  1953. pxframe->frame_tag = DATA_FRAMETAG;
  1954. #ifdef CONFIG_USB_HCI
  1955. pxframe->pkt = NULL;
  1956. pxframe->pkt_offset = 1;//default use pkt_offset to fill tx desc
  1957. #ifdef CONFIG_USB_TX_AGGREGATION
  1958. pxframe->agg_num = 1;
  1959. #endif
  1960. #endif //#ifdef CONFIG_USB_HCI
  1961. #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1962. pxframe->pg_num = 1;
  1963. pxframe->agg_num = 1;
  1964. #endif
  1965. #ifdef CONFIG_XMIT_ACK
  1966. pxframe->ack_report = 0;
  1967. #endif
  1968. }
  1969. }
  1970. /*
  1971. Calling context:
  1972. 1. OS_TXENTRY
  1973. 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack)
  1974. If we turn on USE_RXTHREAD, then, no need for critical section.
  1975. Otherwise, we must use _enter/_exit critical to protect free_xmit_queue...
  1976. Must be very very cautious...
  1977. */
  1978. struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)//(_queue *pfree_xmit_queue)
  1979. {
  1980. /*
  1981. Please remember to use all the osdep_service api,
  1982. and lock/unlock or _enter/_exit critical to protect
  1983. pfree_xmit_queue
  1984. */
  1985. _irqL irqL;
  1986. struct xmit_frame *pxframe = NULL;
  1987. _list *plist, *phead;
  1988. _queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
  1989. _func_enter_;
  1990. _enter_critical_bh(&pfree_xmit_queue->lock, &irqL);
  1991. if (_rtw_queue_empty(pfree_xmit_queue) == _TRUE) {
  1992. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_alloc_xmitframe:%d\n", pxmitpriv->free_xmitframe_cnt));
  1993. pxframe = NULL;
  1994. } else {
  1995. phead = get_list_head(pfree_xmit_queue);
  1996. plist = get_next(phead);
  1997. pxframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
  1998. rtw_list_delete(&(pxframe->list));
  1999. pxmitpriv->free_xmitframe_cnt--;
  2000. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv->free_xmitframe_cnt));
  2001. }
  2002. _exit_critical_bh(&pfree_xmit_queue->lock, &irqL);
  2003. rtw_init_xmitframe(pxframe);
  2004. _func_exit_;
  2005. return pxframe;
  2006. }
  2007. struct xmit_frame *rtw_alloc_xmitframe_ext(struct xmit_priv *pxmitpriv)
  2008. {
  2009. _irqL irqL;
  2010. struct xmit_frame *pxframe = NULL;
  2011. _list *plist, *phead;
  2012. _queue *queue = &pxmitpriv->free_xframe_ext_queue;
  2013. _func_enter_;
  2014. _enter_critical_bh(&queue->lock, &irqL);
  2015. if (_rtw_queue_empty(queue) == _TRUE) {
  2016. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_alloc_xmitframe_ext:%d\n", pxmitpriv->free_xframe_ext_cnt));
  2017. pxframe = NULL;
  2018. } else {
  2019. phead = get_list_head(queue);
  2020. plist = get_next(phead);
  2021. pxframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
  2022. rtw_list_delete(&(pxframe->list));
  2023. pxmitpriv->free_xframe_ext_cnt--;
  2024. RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe_ext():free_xmitframe_cnt=%d\n", pxmitpriv->free_xframe_ext_cnt));
  2025. }
  2026. _exit_critical_bh(&queue->lock, &irqL);
  2027. rtw_init_xmitframe(pxframe);
  2028. _func_exit_;
  2029. return pxframe;
  2030. }
  2031. struct xmit_frame *rtw_alloc_xmitframe_once(struct xmit_priv *pxmitpriv)
  2032. {
  2033. struct xmit_frame *pxframe = NULL;
  2034. u8 *alloc_addr;
  2035. alloc_addr = rtw_zmalloc(sizeof(struct xmit_frame) + 4);
  2036. if (alloc_addr == NULL)
  2037. goto exit;
  2038. pxframe = (struct xmit_frame *)N_BYTE_ALIGMENT((SIZE_PTR)(alloc_addr), 4);
  2039. pxframe->alloc_addr = alloc_addr;
  2040. pxframe->padapter = pxmitpriv->adapter;
  2041. pxframe->frame_tag = NULL_FRAMETAG;
  2042. pxframe->pkt = NULL;
  2043. pxframe->buf_addr = NULL;
  2044. pxframe->pxmitbuf = NULL;
  2045. rtw_init_xmitframe(pxframe);
  2046. DBG_871X("################## %s ##################\n", __func__);
  2047. exit:
  2048. return pxframe;
  2049. }
  2050. s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe)
  2051. {
  2052. _irqL irqL;
  2053. _queue *queue;
  2054. _adapter *padapter = pxmitpriv->adapter;
  2055. _pkt *pndis_pkt = NULL;
  2056. _func_enter_;
  2057. if (pxmitframe == NULL) {
  2058. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("======rtw_free_xmitframe():pxmitframe==NULL!!!!!!!!!!\n"));
  2059. goto exit;
  2060. }
  2061. if (pxmitframe->pkt){
  2062. pndis_pkt = pxmitframe->pkt;
  2063. pxmitframe->pkt = NULL;
  2064. }
  2065. if (pxmitframe->alloc_addr) {
  2066. DBG_871X("################## %s with alloc_addr ##################\n", __func__);
  2067. rtw_mfree(pxmitframe->alloc_addr, sizeof(struct xmit_frame) + 4);
  2068. goto check_pkt_complete;
  2069. }
  2070. if (pxmitframe->ext_tag == 0)
  2071. queue = &pxmitpriv->free_xmit_queue;
  2072. else if(pxmitframe->ext_tag == 1)
  2073. queue = &pxmitpriv->free_xframe_ext_queue;
  2074. else
  2075. {}
  2076. _enter_critical_bh(&queue->lock, &irqL);
  2077. rtw_list_delete(&pxmitframe->list);
  2078. rtw_list_insert_tail(&pxmitframe->list, get_list_head(queue));
  2079. if (pxmitframe->ext_tag == 0) {
  2080. pxmitpriv->free_xmitframe_cnt++;
  2081. RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_, ("rtw_free_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv->free_xmitframe_cnt));
  2082. } else if(pxmitframe->ext_tag == 1) {
  2083. pxmitpriv->free_xframe_ext_cnt++;
  2084. RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_, ("rtw_free_xmitframe():free_xframe_ext_cnt=%d\n", pxmitpriv->free_xframe_ext_cnt));
  2085. } else {
  2086. }
  2087. _exit_critical_bh(&queue->lock, &irqL);
  2088. check_pkt_complete:
  2089. if(pndis_pkt)
  2090. rtw_os_pkt_complete(padapter, pndis_pkt);
  2091. exit:
  2092. _func_exit_;
  2093. return _SUCCESS;
  2094. }
  2095. void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, _queue *pframequeue)
  2096. {
  2097. _irqL irqL;
  2098. _list *plist, *phead;
  2099. struct xmit_frame *pxmitframe;
  2100. _func_enter_;
  2101. _enter_critical_bh(&(pframequeue->lock), &irqL);
  2102. phead = get_list_head(pframequeue);
  2103. plist = get_next(phead);
  2104. while (rtw_end_of_queue_search(phead, plist) == _FALSE)
  2105. {
  2106. pxmitframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
  2107. plist = get_next(plist);
  2108. rtw_free_xmitframe(pxmitpriv,pxmitframe);
  2109. }
  2110. _exit_critical_bh(&(pframequeue->lock), &irqL);
  2111. _func_exit_;
  2112. }
  2113. s32 rtw_xmitframe_enqueue(_adapter *padapter, struct xmit_frame *pxmitframe)
  2114. {
  2115. if (rtw_xmit_classifier(padapter, pxmitframe) == _FAIL)
  2116. {
  2117. RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
  2118. ("rtw_xmitframe_enqueue: drop xmit pkt for classifier fail\n"));
  2119. // pxmitframe->pkt = NULL;
  2120. return _FAIL;
  2121. }
  2122. return _SUCCESS;
  2123. }
  2124. static struct xmit_frame *dequeue_one_xmitframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit, struct tx_servq *ptxservq, _queue *pframe_queue)
  2125. {
  2126. _list *xmitframe_plist, *xmitframe_phead;
  2127. struct xmit_frame *pxmitframe=NULL;
  2128. xmitframe_phead = get_list_head(pframe_queue);
  2129. xmitframe_plist = get_next(xmitframe_phead);
  2130. while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE)
  2131. {
  2132. pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
  2133. xmitframe_plist = get_next(xmitframe_plist);
  2134. /*#ifdef RTK_DMP_PLATFORM
  2135. #ifdef CONFIG_USB_TX_AGGREGATION
  2136. if((ptxservq->qcnt>0) && (ptxservq->qcnt<=2))
  2137. {
  2138. pxmitframe = NULL;
  2139. tasklet_schedule(&pxmitpriv->xmit_tasklet);
  2140. break;
  2141. }
  2142. #endif
  2143. #endif*/
  2144. rtw_list_delete(&pxmitframe->list);
  2145. ptxservq->qcnt--;
  2146. //rtw_list_insert_tail(&pxmitframe->list, &phwxmit->pending);
  2147. //ptxservq->qcnt--;
  2148. break;
  2149. pxmitframe = NULL;
  2150. }
  2151. return pxmitframe;
  2152. }
  2153. struct xmit_frame* rtw_dequeue_xframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit_i, sint entry)
  2154. {
  2155. _irqL irqL0;
  2156. _list *sta_plist, *sta_phead;
  2157. struct hw_xmit *phwxmit;
  2158. struct tx_servq *ptxservq = NULL;
  2159. _queue *pframe_queue = NULL;
  2160. struct xmit_frame *pxmitframe = NULL;
  2161. _adapter *padapter = pxmitpriv->adapter;
  2162. struct registry_priv *pregpriv = &padapter->registrypriv;
  2163. int i, inx[4];
  2164. #ifdef CONFIG_USB_HCI
  2165. // int j, tmp, acirp_cnt[4];
  2166. #endif
  2167. _func_enter_;
  2168. inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3;
  2169. if(pregpriv->wifi_spec==1)
  2170. {
  2171. int j, tmp, acirp_cnt[4];
  2172. #if 0
  2173. if(flags<XMIT_QUEUE_ENTRY)
  2174. {
  2175. //priority exchange according to the completed xmitbuf flags.
  2176. inx[flags] = 0;
  2177. inx[0] = flags;
  2178. }
  2179. #endif
  2180. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI)
  2181. for(j=0; j<4; j++)
  2182. inx[j] = pxmitpriv->wmm_para_seq[j];
  2183. #endif
  2184. }
  2185. _enter_critical_bh(&pxmitpriv->lock, &irqL0);
  2186. for(i = 0; i < entry; i++)
  2187. {
  2188. phwxmit = phwxmit_i + inx[i];
  2189. //_enter_critical_ex(&phwxmit->sta_queue->lock, &irqL0);
  2190. sta_phead = get_list_head(phwxmit->sta_queue);
  2191. sta_plist = get_next(sta_phead);
  2192. while ((rtw_end_of_queue_search(sta_phead, sta_plist)) == _FALSE)
  2193. {
  2194. ptxservq= LIST_CONTAINOR(sta_plist, struct tx_servq, tx_pending);
  2195. pframe_queue = &ptxservq->sta_pending;
  2196. pxmitframe = dequeue_one_xmitframe(pxmitpriv, phwxmit, ptxservq, pframe_queue);
  2197. if(pxmitframe)
  2198. {
  2199. phwxmit->accnt--;
  2200. //Remove sta node when there is no pending packets.
  2201. if(_rtw_queue_empty(pframe_queue)) //must be done after get_next and before break
  2202. rtw_list_delete(&ptxservq->tx_pending);
  2203. //_exit_critical_ex(&phwxmit->sta_queue->lock, &irqL0);
  2204. goto exit;
  2205. }
  2206. sta_plist = get_next(sta_plist);
  2207. }
  2208. //_exit_critical_ex(&phwxmit->sta_queue->lock, &irqL0);
  2209. }
  2210. exit:
  2211. _exit_critical_bh(&pxmitpriv->lock, &irqL0);
  2212. _func_exit_;
  2213. return pxmitframe;
  2214. }
  2215. #if 1
  2216. struct tx_servq *rtw_get_sta_pending(_adapter *padapter, struct sta_info *psta, sint up, u8 *ac)
  2217. {
  2218. struct tx_servq *ptxservq=NULL;
  2219. _func_enter_;
  2220. switch (up)
  2221. {
  2222. case 1:
  2223. case 2:
  2224. ptxservq = &(psta->sta_xmitpriv.bk_q);
  2225. *(ac) = 3;
  2226. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_get_sta_pending : BK \n"));
  2227. break;
  2228. case 4:
  2229. case 5:
  2230. ptxservq = &(psta->sta_xmitpriv.vi_q);
  2231. *(ac) = 1;
  2232. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_get_sta_pending : VI\n"));
  2233. break;
  2234. case 6:
  2235. case 7:
  2236. ptxservq = &(psta->sta_xmitpriv.vo_q);
  2237. *(ac) = 0;
  2238. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_get_sta_pending : VO \n"));
  2239. break;
  2240. case 0:
  2241. case 3:
  2242. default:
  2243. ptxservq = &(psta->sta_xmitpriv.be_q);
  2244. *(ac) = 2;
  2245. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_get_sta_pending : BE \n"));
  2246. break;
  2247. }
  2248. _func_exit_;
  2249. return ptxservq;
  2250. }
  2251. #else
  2252. __inline static struct tx_servq *rtw_get_sta_pending
  2253. (_adapter *padapter, _queue **ppstapending, struct sta_info *psta, sint up)
  2254. {
  2255. struct tx_servq *ptxservq;
  2256. struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
  2257. _func_enter_;
  2258. #ifdef CONFIG_RTL8711
  2259. if(IS_MCAST(psta->hwaddr))
  2260. {
  2261. ptxservq = &(psta->sta_xmitpriv.be_q); // we will use be_q to queue bc/mc frames in BCMC_stainfo
  2262. *ppstapending = &padapter->xmitpriv.bm_pending;
  2263. }
  2264. else
  2265. #endif
  2266. {
  2267. switch (up)
  2268. {
  2269. case 1:
  2270. case 2:
  2271. ptxservq = &(psta->sta_xmitpriv.bk_q);
  2272. *ppstapending = &padapter->xmitpriv.bk_pending;
  2273. (phwxmits+3)->accnt++;
  2274. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_get_sta_pending : BK \n"));
  2275. break;
  2276. case 4:
  2277. case 5:
  2278. ptxservq = &(psta->sta_xmitpriv.vi_q);
  2279. *ppstapending = &padapter->xmitpriv.vi_pending;
  2280. (phwxmits+1)->accnt++;
  2281. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_get_sta_pending : VI\n"));
  2282. break;
  2283. case 6:
  2284. case 7:
  2285. ptxservq = &(psta->sta_xmitpriv.vo_q);
  2286. *ppstapending = &padapter->xmitpriv.vo_pending;
  2287. (phwxmits+0)->accnt++;
  2288. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_get_sta_pending : VO \n"));
  2289. break;
  2290. case 0:
  2291. case 3:
  2292. default:
  2293. ptxservq = &(psta->sta_xmitpriv.be_q);
  2294. *ppstapending = &padapter->xmitpriv.be_pending;
  2295. (phwxmits+2)->accnt++;
  2296. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("rtw_get_sta_pending : BE \n"));
  2297. break;
  2298. }
  2299. }
  2300. _func_exit_;
  2301. return ptxservq;
  2302. }
  2303. #endif
  2304. /*
  2305. * Will enqueue pxmitframe to the proper queue,
  2306. * and indicate it to xx_pending list.....
  2307. */
  2308. s32 rtw_xmit_classifier(_adapter *padapter, struct xmit_frame *pxmitframe)
  2309. {
  2310. //_irqL irqL0;
  2311. u8 ac_index;
  2312. struct sta_info *psta;
  2313. struct tx_servq *ptxservq;
  2314. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  2315. struct sta_priv *pstapriv = &padapter->stapriv;
  2316. struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
  2317. sint res = _SUCCESS;
  2318. _func_enter_;
  2319. /*
  2320. if (pattrib->psta) {
  2321. psta = pattrib->psta;
  2322. } else {
  2323. DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
  2324. psta = rtw_get_stainfo(pstapriv, pattrib->ra);
  2325. }
  2326. */
  2327. psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
  2328. if(pattrib->psta != psta)
  2329. {
  2330. DBG_871X("%s, pattrib->psta(%p) != psta(%p)\n", __func__, pattrib->psta, psta);
  2331. return _FAIL;
  2332. }
  2333. if (psta == NULL) {
  2334. res = _FAIL;
  2335. DBG_8192C("rtw_xmit_classifier: psta == NULL\n");
  2336. RT_TRACE(_module_rtl871x_xmit_c_,_drv_err_,("rtw_xmit_classifier: psta == NULL\n"));
  2337. goto exit;
  2338. }
  2339. if(!(psta->state &_FW_LINKED))
  2340. {
  2341. DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  2342. return _FAIL;
  2343. }
  2344. ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
  2345. //_enter_critical(&pstapending->lock, &irqL0);
  2346. if (rtw_is_list_empty(&ptxservq->tx_pending)) {
  2347. rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(phwxmits[ac_index].sta_queue));
  2348. }
  2349. //_enter_critical(&ptxservq->sta_pending.lock, &irqL1);
  2350. rtw_list_insert_tail(&pxmitframe->list, get_list_head(&ptxservq->sta_pending));
  2351. ptxservq->qcnt++;
  2352. phwxmits[ac_index].accnt++;
  2353. //_exit_critical(&ptxservq->sta_pending.lock, &irqL1);
  2354. //_exit_critical(&pstapending->lock, &irqL0);
  2355. exit:
  2356. _func_exit_;
  2357. return res;
  2358. }
  2359. void rtw_alloc_hwxmits(_adapter *padapter)
  2360. {
  2361. struct hw_xmit *hwxmits;
  2362. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  2363. pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;
  2364. pxmitpriv->hwxmits = (struct hw_xmit *)rtw_zmalloc(sizeof (struct hw_xmit) * pxmitpriv->hwxmit_entry);
  2365. hwxmits = pxmitpriv->hwxmits;
  2366. if(pxmitpriv->hwxmit_entry == 5)
  2367. {
  2368. //pxmitpriv->bmc_txqueue.head = 0;
  2369. //hwxmits[0] .phwtxqueue = &pxmitpriv->bmc_txqueue;
  2370. hwxmits[0] .sta_queue = &pxmitpriv->bm_pending;
  2371. //pxmitpriv->vo_txqueue.head = 0;
  2372. //hwxmits[1] .phwtxqueue = &pxmitpriv->vo_txqueue;
  2373. hwxmits[1] .sta_queue = &pxmitpriv->vo_pending;
  2374. //pxmitpriv->vi_txqueue.head = 0;
  2375. //hwxmits[2] .phwtxqueue = &pxmitpriv->vi_txqueue;
  2376. hwxmits[2] .sta_queue = &pxmitpriv->vi_pending;
  2377. //pxmitpriv->bk_txqueue.head = 0;
  2378. //hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue;
  2379. hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
  2380. //pxmitpriv->be_txqueue.head = 0;
  2381. //hwxmits[4] .phwtxqueue = &pxmitpriv->be_txqueue;
  2382. hwxmits[4] .sta_queue = &pxmitpriv->be_pending;
  2383. }
  2384. else if(pxmitpriv->hwxmit_entry == 4)
  2385. {
  2386. //pxmitpriv->vo_txqueue.head = 0;
  2387. //hwxmits[0] .phwtxqueue = &pxmitpriv->vo_txqueue;
  2388. hwxmits[0] .sta_queue = &pxmitpriv->vo_pending;
  2389. //pxmitpriv->vi_txqueue.head = 0;
  2390. //hwxmits[1] .phwtxqueue = &pxmitpriv->vi_txqueue;
  2391. hwxmits[1] .sta_queue = &pxmitpriv->vi_pending;
  2392. //pxmitpriv->be_txqueue.head = 0;
  2393. //hwxmits[2] .phwtxqueue = &pxmitpriv->be_txqueue;
  2394. hwxmits[2] .sta_queue = &pxmitpriv->be_pending;
  2395. //pxmitpriv->bk_txqueue.head = 0;
  2396. //hwxmits[3] .phwtxqueue = &pxmitpriv->bk_txqueue;
  2397. hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
  2398. }
  2399. else
  2400. {
  2401. }
  2402. }
  2403. void rtw_free_hwxmits(_adapter *padapter)
  2404. {
  2405. struct hw_xmit *hwxmits;
  2406. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  2407. hwxmits = pxmitpriv->hwxmits;
  2408. if(hwxmits)
  2409. rtw_mfree((u8 *)hwxmits, (sizeof (struct hw_xmit) * pxmitpriv->hwxmit_entry));
  2410. }
  2411. void rtw_init_hwxmits(struct hw_xmit *phwxmit, sint entry)
  2412. {
  2413. sint i;
  2414. _func_enter_;
  2415. for(i = 0; i < entry; i++, phwxmit++)
  2416. {
  2417. //_rtw_spinlock_init(&phwxmit->xmit_lock);
  2418. //_rtw_init_listhead(&phwxmit->pending);
  2419. //phwxmit->txcmdcnt = 0;
  2420. phwxmit->accnt = 0;
  2421. }
  2422. _func_exit_;
  2423. }
  2424. #ifdef CONFIG_BR_EXT
  2425. int rtw_br_client_tx(_adapter *padapter, struct sk_buff **pskb)
  2426. {
  2427. struct sk_buff *skb = *pskb;
  2428. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  2429. _irqL irqL;
  2430. //if(check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) == _TRUE)
  2431. {
  2432. void dhcp_flag_bcast(_adapter *priv, struct sk_buff *skb);
  2433. int res, is_vlan_tag=0, i, do_nat25=1;
  2434. unsigned short vlan_hdr=0;
  2435. void *br_port = NULL;
  2436. //mac_clone_handle_frame(priv, skb);
  2437. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  2438. br_port = padapter->pnetdev->br_port;
  2439. #else // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  2440. rcu_read_lock();
  2441. br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
  2442. rcu_read_unlock();
  2443. #endif // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  2444. _enter_critical_bh(&padapter->br_ext_lock, &irqL);
  2445. if ( !(skb->data[0] & 1) &&
  2446. br_port &&
  2447. memcmp(skb->data+MACADDRLEN, padapter->br_mac, MACADDRLEN) &&
  2448. *((unsigned short *)(skb->data+MACADDRLEN*2)) != __constant_htons(ETH_P_8021Q) &&
  2449. *((unsigned short *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_IP) &&
  2450. !memcmp(padapter->scdb_mac, skb->data+MACADDRLEN, MACADDRLEN) && padapter->scdb_entry) {
  2451. memcpy(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN);
  2452. padapter->scdb_entry->ageing_timer = jiffies;
  2453. _exit_critical_bh(&padapter->br_ext_lock, &irqL);
  2454. }
  2455. else
  2456. //if (!priv->pmib->ethBrExtInfo.nat25_disable)
  2457. {
  2458. // if (priv->dev->br_port &&
  2459. // !memcmp(skb->data+MACADDRLEN, priv->br_mac, MACADDRLEN)) {
  2460. #if 1
  2461. if (*((unsigned short *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_8021Q)) {
  2462. is_vlan_tag = 1;
  2463. vlan_hdr = *((unsigned short *)(skb->data+MACADDRLEN*2+2));
  2464. for (i=0; i<6; i++)
  2465. *((unsigned short *)(skb->data+MACADDRLEN*2+2-i*2)) = *((unsigned short *)(skb->data+MACADDRLEN*2-2-i*2));
  2466. skb_pull(skb, 4);
  2467. }
  2468. //if SA == br_mac && skb== IP => copy SIP to br_ip ?? why
  2469. if (!memcmp(skb->data+MACADDRLEN, padapter->br_mac, MACADDRLEN) &&
  2470. (*((unsigned short *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_IP)))
  2471. memcpy(padapter->br_ip, skb->data+WLAN_ETHHDR_LEN+12, 4);
  2472. if (*((unsigned short *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_IP)) {
  2473. if (memcmp(padapter->scdb_mac, skb->data+MACADDRLEN, MACADDRLEN)) {
  2474. void *scdb_findEntry(_adapter *priv, unsigned char *macAddr, unsigned char *ipAddr);
  2475. if ((padapter->scdb_entry = (struct nat25_network_db_entry *)scdb_findEntry(padapter,
  2476. skb->data+MACADDRLEN, skb->data+WLAN_ETHHDR_LEN+12)) != NULL) {
  2477. memcpy(padapter->scdb_mac, skb->data+MACADDRLEN, MACADDRLEN);
  2478. memcpy(padapter->scdb_ip, skb->data+WLAN_ETHHDR_LEN+12, 4);
  2479. padapter->scdb_entry->ageing_timer = jiffies;
  2480. do_nat25 = 0;
  2481. }
  2482. }
  2483. else {
  2484. if (padapter->scdb_entry) {
  2485. padapter->scdb_entry->ageing_timer = jiffies;
  2486. do_nat25 = 0;
  2487. }
  2488. else {
  2489. memset(padapter->scdb_mac, 0, MACADDRLEN);
  2490. memset(padapter->scdb_ip, 0, 4);
  2491. }
  2492. }
  2493. }
  2494. _exit_critical_bh(&padapter->br_ext_lock, &irqL);
  2495. #endif // 1
  2496. if (do_nat25)
  2497. {
  2498. int nat25_db_handle(_adapter *priv, struct sk_buff *skb, int method);
  2499. if (nat25_db_handle(padapter, skb, NAT25_CHECK) == 0) {
  2500. struct sk_buff *newskb;
  2501. if (is_vlan_tag) {
  2502. skb_push(skb, 4);
  2503. for (i=0; i<6; i++)
  2504. *((unsigned short *)(skb->data+i*2)) = *((unsigned short *)(skb->data+4+i*2));
  2505. *((unsigned short *)(skb->data+MACADDRLEN*2)) = __constant_htons(ETH_P_8021Q);
  2506. *((unsigned short *)(skb->data+MACADDRLEN*2+2)) = vlan_hdr;
  2507. }
  2508. newskb = skb_copy(skb, GFP_ATOMIC);
  2509. if (newskb == NULL) {
  2510. //priv->ext_stats.tx_drops++;
  2511. DEBUG_ERR("TX DROP: skb_copy fail!\n");
  2512. //goto stop_proc;
  2513. return -1;
  2514. }
  2515. dev_kfree_skb_any(skb);
  2516. *pskb = skb = newskb;
  2517. if (is_vlan_tag) {
  2518. vlan_hdr = *((unsigned short *)(skb->data+MACADDRLEN*2+2));
  2519. for (i=0; i<6; i++)
  2520. *((unsigned short *)(skb->data+MACADDRLEN*2+2-i*2)) = *((unsigned short *)(skb->data+MACADDRLEN*2-2-i*2));
  2521. skb_pull(skb, 4);
  2522. }
  2523. }
  2524. if (skb_is_nonlinear(skb))
  2525. DEBUG_ERR("%s(): skb_is_nonlinear!!\n", __FUNCTION__);
  2526. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
  2527. res = skb_linearize(skb, GFP_ATOMIC);
  2528. #else // (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
  2529. res = skb_linearize(skb);
  2530. #endif // (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
  2531. if (res < 0) {
  2532. DEBUG_ERR("TX DROP: skb_linearize fail!\n");
  2533. //goto free_and_stop;
  2534. return -1;
  2535. }
  2536. res = nat25_db_handle(padapter, skb, NAT25_INSERT);
  2537. if (res < 0) {
  2538. if (res == -2) {
  2539. //priv->ext_stats.tx_drops++;
  2540. DEBUG_ERR("TX DROP: nat25_db_handle fail!\n");
  2541. //goto free_and_stop;
  2542. return -1;
  2543. }
  2544. // we just print warning message and let it go
  2545. //DEBUG_WARN("%s()-%d: nat25_db_handle INSERT Warning!\n", __FUNCTION__, __LINE__);
  2546. //return -1; // return -1 will cause system crash on 2011/08/30!
  2547. return 0;
  2548. }
  2549. }
  2550. memcpy(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN);
  2551. dhcp_flag_bcast(padapter, skb);
  2552. if (is_vlan_tag) {
  2553. skb_push(skb, 4);
  2554. for (i=0; i<6; i++)
  2555. *((unsigned short *)(skb->data+i*2)) = *((unsigned short *)(skb->data+4+i*2));
  2556. *((unsigned short *)(skb->data+MACADDRLEN*2)) = __constant_htons(ETH_P_8021Q);
  2557. *((unsigned short *)(skb->data+MACADDRLEN*2+2)) = vlan_hdr;
  2558. }
  2559. }
  2560. #if 0
  2561. else{
  2562. if (*((unsigned short *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_8021Q)) {
  2563. is_vlan_tag = 1;
  2564. }
  2565. if(is_vlan_tag){
  2566. if(ICMPV6_MCAST_MAC(skb->data) && ICMPV6_PROTO1A_VALN(skb->data)){
  2567. memcpy(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN);
  2568. }
  2569. }else
  2570. {
  2571. if(ICMPV6_MCAST_MAC(skb->data) && ICMPV6_PROTO1A(skb->data)){
  2572. memcpy(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN);
  2573. }
  2574. }
  2575. }
  2576. #endif // 0
  2577. // check if SA is equal to our MAC
  2578. if (memcmp(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN)) {
  2579. //priv->ext_stats.tx_drops++;
  2580. DEBUG_ERR("TX DROP: untransformed frame SA:%02X%02X%02X%02X%02X%02X!\n",
  2581. skb->data[6],skb->data[7],skb->data[8],skb->data[9],skb->data[10],skb->data[11]);
  2582. //goto free_and_stop;
  2583. return -1;
  2584. }
  2585. }
  2586. return 0;
  2587. }
  2588. #endif // CONFIG_BR_EXT
  2589. u32 rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe)
  2590. {
  2591. u32 addr;
  2592. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  2593. switch(pattrib->qsel)
  2594. {
  2595. case 0:
  2596. case 3:
  2597. addr = BE_QUEUE_INX;
  2598. break;
  2599. case 1:
  2600. case 2:
  2601. addr = BK_QUEUE_INX;
  2602. break;
  2603. case 4:
  2604. case 5:
  2605. addr = VI_QUEUE_INX;
  2606. break;
  2607. case 6:
  2608. case 7:
  2609. addr = VO_QUEUE_INX;
  2610. break;
  2611. case 0x10:
  2612. addr = BCN_QUEUE_INX;
  2613. break;
  2614. case 0x11://BC/MC in PS (HIQ)
  2615. addr = HIGH_QUEUE_INX;
  2616. break;
  2617. case 0x12:
  2618. default:
  2619. addr = MGT_QUEUE_INX;
  2620. break;
  2621. }
  2622. return addr;
  2623. }
  2624. static void do_queue_select(_adapter *padapter, struct pkt_attrib *pattrib)
  2625. {
  2626. u8 qsel;
  2627. qsel = pattrib->priority;
  2628. RT_TRACE(_module_rtl871x_xmit_c_,_drv_info_,("### do_queue_select priority=%d ,qsel = %d\n",pattrib->priority ,qsel));
  2629. #ifdef CONFIG_CONCURRENT_MODE
  2630. // if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == _TRUE)
  2631. // qsel = 7;//
  2632. #endif
  2633. pattrib->qsel = qsel;
  2634. }
  2635. /*
  2636. * The main transmit(tx) entry
  2637. *
  2638. * Return
  2639. * 1 enqueue
  2640. * 0 success, hardware will handle this xmit frame(packet)
  2641. * <0 fail
  2642. */
  2643. s32 rtw_xmit(_adapter *padapter, _pkt **ppkt)
  2644. {
  2645. static u32 start = 0;
  2646. static u32 drop_cnt = 0;
  2647. #ifdef CONFIG_AP_MODE
  2648. _irqL irqL0;
  2649. #endif
  2650. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  2651. struct xmit_frame *pxmitframe = NULL;
  2652. #ifdef CONFIG_BR_EXT
  2653. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2654. void *br_port = NULL;
  2655. #endif // CONFIG_BR_EXT
  2656. s32 res;
  2657. if (start == 0)
  2658. start = rtw_get_current_time();
  2659. pxmitframe = rtw_alloc_xmitframe(pxmitpriv);
  2660. if (rtw_get_passing_time_ms(start) > 2000) {
  2661. if (drop_cnt)
  2662. DBG_871X("DBG_TX_DROP_FRAME %s no more pxmitframe, drop_cnt:%u\n", __FUNCTION__, drop_cnt);
  2663. start = rtw_get_current_time();
  2664. drop_cnt = 0;
  2665. }
  2666. if (pxmitframe == NULL) {
  2667. drop_cnt ++;
  2668. RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: no more pxmitframe\n"));
  2669. return -1;
  2670. }
  2671. #ifdef CONFIG_BR_EXT
  2672. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  2673. br_port = padapter->pnetdev->br_port;
  2674. #else // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  2675. rcu_read_lock();
  2676. br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
  2677. rcu_read_unlock();
  2678. #endif // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  2679. if( br_port && check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) == _TRUE)
  2680. {
  2681. res = rtw_br_client_tx(padapter, ppkt);
  2682. if (res == -1)
  2683. {
  2684. rtw_free_xmitframe(pxmitpriv, pxmitframe);
  2685. return -1;
  2686. }
  2687. }
  2688. #endif // CONFIG_BR_EXT
  2689. res = update_attrib(padapter, *ppkt, &pxmitframe->attrib);
  2690. #ifdef CONFIG_WAPI_SUPPORT
  2691. if(pxmitframe->attrib.ether_type != 0x88B4)
  2692. {
  2693. if(rtw_wapi_drop_for_key_absent(padapter, pxmitframe->attrib.ra))
  2694. {
  2695. WAPI_TRACE(WAPI_RX,"drop for key absend when tx \n");
  2696. res = _FAIL;
  2697. }
  2698. }
  2699. #endif
  2700. if (res == _FAIL) {
  2701. RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: update attrib fail\n"));
  2702. #ifdef DBG_TX_DROP_FRAME
  2703. DBG_871X("DBG_TX_DROP_FRAME %s update attrib fail\n", __FUNCTION__);
  2704. #endif
  2705. rtw_free_xmitframe(pxmitpriv, pxmitframe);
  2706. return -1;
  2707. }
  2708. pxmitframe->pkt = *ppkt;
  2709. rtw_led_control(padapter, LED_CTL_TX);
  2710. do_queue_select(padapter, &pxmitframe->attrib);
  2711. #ifdef CONFIG_AP_MODE
  2712. _enter_critical_bh(&pxmitpriv->lock, &irqL0);
  2713. if(xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe) == _TRUE)
  2714. {
  2715. _exit_critical_bh(&pxmitpriv->lock, &irqL0);
  2716. return 1;
  2717. }
  2718. _exit_critical_bh(&pxmitpriv->lock, &irqL0);
  2719. #endif
  2720. if (rtw_hal_xmit(padapter, pxmitframe) == _FALSE)
  2721. return 1;
  2722. return 0;
  2723. }
  2724. #ifdef CONFIG_TDLS
  2725. sint xmitframe_enqueue_for_tdls_sleeping_sta(_adapter *padapter, struct xmit_frame *pxmitframe)
  2726. {
  2727. sint ret=_FALSE;
  2728. _irqL irqL;
  2729. struct sta_info *ptdls_sta=NULL;
  2730. struct sta_priv *pstapriv = &padapter->stapriv;
  2731. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  2732. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2733. int i;
  2734. ptdls_sta=rtw_get_stainfo(pstapriv, pattrib->dst);
  2735. if(ptdls_sta==NULL){
  2736. return ret;
  2737. }else if(ptdls_sta->tdls_sta_state&TDLS_LINKED_STATE){
  2738. if(pattrib->triggered==1)
  2739. {
  2740. ret = _TRUE;
  2741. return ret;
  2742. }
  2743. _enter_critical_bh(&ptdls_sta->sleep_q.lock, &irqL);
  2744. if(ptdls_sta->state&WIFI_SLEEP_STATE)
  2745. {
  2746. rtw_list_delete(&pxmitframe->list);
  2747. //_enter_critical_bh(&psta->sleep_q.lock, &irqL);
  2748. rtw_list_insert_tail(&pxmitframe->list, get_list_head(&ptdls_sta->sleep_q));
  2749. ptdls_sta->sleepq_len++;
  2750. ptdls_sta->sleepq_ac_len++;
  2751. //indicate 4-AC queue bit in TDLS peer traffic indication
  2752. switch(pattrib->priority)
  2753. {
  2754. case 1:
  2755. case 2:
  2756. ptdls_sta->uapsd_bk = ptdls_sta->uapsd_bk | BIT(1);
  2757. break;
  2758. case 4:
  2759. case 5:
  2760. ptdls_sta->uapsd_vi = ptdls_sta->uapsd_vi | BIT(1);
  2761. break;
  2762. case 6:
  2763. case 7:
  2764. ptdls_sta->uapsd_vo = ptdls_sta->uapsd_vo | BIT(1);
  2765. break;
  2766. case 0:
  2767. case 3:
  2768. default:
  2769. ptdls_sta->uapsd_be = ptdls_sta->uapsd_be | BIT(1);
  2770. break;
  2771. }
  2772. if(ptdls_sta->sleepq_len==1)
  2773. {
  2774. //transmit TDLS PTI via AP
  2775. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_SD_PTI);
  2776. }
  2777. ret = _TRUE;
  2778. }
  2779. _exit_critical_bh(&ptdls_sta->sleep_q.lock, &irqL);
  2780. }
  2781. return ret;
  2782. }
  2783. #endif //CONFIG_TDLS
  2784. #if defined(CONFIG_AP_MODE) || defined(CONFIG_TDLS)
  2785. sint xmitframe_enqueue_for_sleeping_sta(_adapter *padapter, struct xmit_frame *pxmitframe)
  2786. {
  2787. _irqL irqL;
  2788. sint ret=_FALSE;
  2789. struct sta_info *psta=NULL;
  2790. struct sta_priv *pstapriv = &padapter->stapriv;
  2791. struct pkt_attrib *pattrib = &pxmitframe->attrib;
  2792. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2793. sint bmcst = IS_MCAST(pattrib->ra);
  2794. #ifdef CONFIG_TDLS
  2795. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  2796. if( ptdlsinfo->setup_state == TDLS_LINKED_STATE )
  2797. {
  2798. ret = xmitframe_enqueue_for_tdls_sleeping_sta(padapter, pxmitframe);
  2799. return ret;
  2800. }
  2801. #endif //CONFIG_TDLS
  2802. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _FALSE)
  2803. return ret;
  2804. /*
  2805. if(pattrib->psta)
  2806. {
  2807. psta = pattrib->psta;
  2808. }
  2809. else
  2810. {
  2811. DBG_871X("%s, call rtw_get_stainfo()\n", __func__);
  2812. psta=rtw_get_stainfo(pstapriv, pattrib->ra);
  2813. }
  2814. */
  2815. psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
  2816. if(pattrib->psta != psta)
  2817. {
  2818. DBG_871X("%s, pattrib->psta(%p) != psta(%p)\n", __func__, pattrib->psta, psta);
  2819. return _FALSE;
  2820. }
  2821. if(psta==NULL)
  2822. {
  2823. DBG_871X("%s, psta==NUL\n", __func__);
  2824. return _FALSE;
  2825. }
  2826. if(!(psta->state &_FW_LINKED))
  2827. {
  2828. DBG_871X("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, psta->state);
  2829. return _FALSE;
  2830. }
  2831. if(pattrib->triggered==1)
  2832. {
  2833. //DBG_871X("directly xmit pspoll_triggered packet\n");
  2834. //pattrib->triggered=0;
  2835. if(bmcst)
  2836. pattrib->qsel = 0x11;//HIQ
  2837. return ret;
  2838. }
  2839. if(bmcst)
  2840. {
  2841. _enter_critical_bh(&psta->sleep_q.lock, &irqL);
  2842. if(pstapriv->sta_dz_bitmap)//if anyone sta is in ps mode
  2843. {
  2844. //pattrib->qsel = 0x11;//HIQ
  2845. rtw_list_delete(&pxmitframe->list);
  2846. //_enter_critical_bh(&psta->sleep_q.lock, &irqL);
  2847. rtw_list_insert_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
  2848. psta->sleepq_len++;
  2849. pstapriv->tim_bitmap |= BIT(0);//
  2850. pstapriv->sta_dz_bitmap |= BIT(0);
  2851. //DBG_871X("enqueue, sq_len=%d, tim=%x\n", psta->sleepq_len, pstapriv->tim_bitmap);
  2852. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);//tx bc/mc packets after upate bcn
  2853. //_exit_critical_bh(&psta->sleep_q.lock, &irqL);
  2854. ret = _TRUE;
  2855. }
  2856. _exit_critical_bh(&psta->sleep_q.lock, &irqL);
  2857. return ret;
  2858. }
  2859. _enter_critical_bh(&psta->sleep_q.lock, &irqL);
  2860. if(psta->state&WIFI_SLEEP_STATE)
  2861. {
  2862. u8 wmmps_ac=0;
  2863. if(pstapriv->sta_dz_bitmap&BIT(psta->aid))
  2864. {
  2865. rtw_list_delete(&pxmitframe->list);
  2866. //_enter_critical_bh(&psta->sleep_q.lock, &irqL);
  2867. rtw_list_insert_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
  2868. psta->sleepq_len++;
  2869. switch(pattrib->priority)
  2870. {
  2871. case 1:
  2872. case 2:
  2873. wmmps_ac = psta->uapsd_bk&BIT(0);
  2874. break;
  2875. case 4:
  2876. case 5:
  2877. wmmps_ac = psta->uapsd_vi&BIT(0);
  2878. break;
  2879. case 6:
  2880. case 7:
  2881. wmmps_ac = psta->uapsd_vo&BIT(0);
  2882. break;
  2883. case 0:
  2884. case 3:
  2885. default:
  2886. wmmps_ac = psta->uapsd_be&BIT(0);
  2887. break;
  2888. }
  2889. if(wmmps_ac)
  2890. psta->sleepq_ac_len++;
  2891. if(((psta->has_legacy_ac) && (!wmmps_ac)) ||((!psta->has_legacy_ac)&&(wmmps_ac)))
  2892. {
  2893. pstapriv->tim_bitmap |= BIT(psta->aid);
  2894. //DBG_871X("enqueue, sq_len=%d, tim=%x\n", psta->sleepq_len, pstapriv->tim_bitmap);
  2895. if(psta->sleepq_len==1)
  2896. {
  2897. //DBG_871X("sleepq_len==1, update BCNTIM\n");
  2898. //upate BCN for TIM IE
  2899. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  2900. }
  2901. }
  2902. //_exit_critical_bh(&psta->sleep_q.lock, &irqL);
  2903. //if(psta->sleepq_len > (NR_XMITFRAME>>3))
  2904. //{
  2905. // wakeup_sta_to_xmit(padapter, psta);
  2906. //}
  2907. ret = _TRUE;
  2908. }
  2909. }
  2910. _exit_critical_bh(&psta->sleep_q.lock, &irqL);
  2911. return ret;
  2912. }
  2913. static void dequeue_xmitframes_to_sleeping_queue(_adapter *padapter, struct sta_info *psta, _queue *pframequeue)
  2914. {
  2915. sint ret;
  2916. _list *plist, *phead;
  2917. u8 ac_index;
  2918. struct tx_servq *ptxservq;
  2919. struct pkt_attrib *pattrib;
  2920. struct xmit_frame *pxmitframe;
  2921. struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
  2922. phead = get_list_head(pframequeue);
  2923. plist = get_next(phead);
  2924. while (rtw_end_of_queue_search(phead, plist) == _FALSE)
  2925. {
  2926. pxmitframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
  2927. plist = get_next(plist);
  2928. ret = xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe);
  2929. if(_TRUE == ret)
  2930. {
  2931. pattrib = &pxmitframe->attrib;
  2932. ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
  2933. ptxservq->qcnt--;
  2934. phwxmits[ac_index].accnt--;
  2935. }
  2936. else
  2937. {
  2938. //DBG_871X("xmitframe_enqueue_for_sleeping_sta return _FALSE\n");
  2939. }
  2940. }
  2941. }
  2942. void stop_sta_xmit(_adapter *padapter, struct sta_info *psta)
  2943. {
  2944. _irqL irqL0;
  2945. struct sta_info *psta_bmc;
  2946. struct sta_xmit_priv *pstaxmitpriv;
  2947. struct sta_priv *pstapriv = &padapter->stapriv;
  2948. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  2949. pstaxmitpriv = &psta->sta_xmitpriv;
  2950. //for BC/MC Frames
  2951. psta_bmc = rtw_get_bcmc_stainfo(padapter);
  2952. _enter_critical_bh(&pxmitpriv->lock, &irqL0);
  2953. psta->state |= WIFI_SLEEP_STATE;
  2954. #ifdef CONFIG_TDLS
  2955. if( !(psta->tdls_sta_state & TDLS_LINKED_STATE) )
  2956. #endif //CONFIG_TDLS
  2957. pstapriv->sta_dz_bitmap |= BIT(psta->aid);
  2958. dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vo_q.sta_pending);
  2959. rtw_list_delete(&(pstaxmitpriv->vo_q.tx_pending));
  2960. dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vi_q.sta_pending);
  2961. rtw_list_delete(&(pstaxmitpriv->vi_q.tx_pending));
  2962. dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->be_q.sta_pending);
  2963. rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
  2964. dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->bk_q.sta_pending);
  2965. rtw_list_delete(&(pstaxmitpriv->bk_q.tx_pending));
  2966. #ifdef CONFIG_TDLS
  2967. if( !(psta->tdls_sta_state & TDLS_LINKED_STATE) )
  2968. {
  2969. if( psta_bmc != NULL )
  2970. {
  2971. #endif //CONFIG_TDLS
  2972. //for BC/MC Frames
  2973. pstaxmitpriv = &psta_bmc->sta_xmitpriv;
  2974. dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc, &pstaxmitpriv->be_q.sta_pending);
  2975. rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
  2976. #ifdef CONFIG_TDLS
  2977. }
  2978. }
  2979. #endif //CONFIG_TDLS
  2980. _exit_critical_bh(&pxmitpriv->lock, &irqL0);
  2981. }
  2982. void wakeup_sta_to_xmit(_adapter *padapter, struct sta_info *psta)
  2983. {
  2984. _irqL irqL;
  2985. u8 update_mask=0, wmmps_ac=0;
  2986. struct sta_info *psta_bmc;
  2987. _list *xmitframe_plist, *xmitframe_phead;
  2988. struct xmit_frame *pxmitframe=NULL;
  2989. struct sta_priv *pstapriv = &padapter->stapriv;
  2990. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  2991. psta_bmc = rtw_get_bcmc_stainfo(padapter);
  2992. //_enter_critical_bh(&psta->sleep_q.lock, &irqL);
  2993. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  2994. xmitframe_phead = get_list_head(&psta->sleep_q);
  2995. xmitframe_plist = get_next(xmitframe_phead);
  2996. while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE)
  2997. {
  2998. pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
  2999. xmitframe_plist = get_next(xmitframe_plist);
  3000. rtw_list_delete(&pxmitframe->list);
  3001. switch(pxmitframe->attrib.priority)
  3002. {
  3003. case 1:
  3004. case 2:
  3005. wmmps_ac = psta->uapsd_bk&BIT(1);
  3006. break;
  3007. case 4:
  3008. case 5:
  3009. wmmps_ac = psta->uapsd_vi&BIT(1);
  3010. break;
  3011. case 6:
  3012. case 7:
  3013. wmmps_ac = psta->uapsd_vo&BIT(1);
  3014. break;
  3015. case 0:
  3016. case 3:
  3017. default:
  3018. wmmps_ac = psta->uapsd_be&BIT(1);
  3019. break;
  3020. }
  3021. psta->sleepq_len--;
  3022. if(psta->sleepq_len>0)
  3023. pxmitframe->attrib.mdata = 1;
  3024. else
  3025. pxmitframe->attrib.mdata = 0;
  3026. if(wmmps_ac)
  3027. {
  3028. psta->sleepq_ac_len--;
  3029. if(psta->sleepq_ac_len>0)
  3030. {
  3031. pxmitframe->attrib.mdata = 1;
  3032. pxmitframe->attrib.eosp = 0;
  3033. }
  3034. else
  3035. {
  3036. pxmitframe->attrib.mdata = 0;
  3037. pxmitframe->attrib.eosp = 1;
  3038. }
  3039. }
  3040. pxmitframe->attrib.triggered = 1;
  3041. /*
  3042. _exit_critical_bh(&psta->sleep_q.lock, &irqL);
  3043. if(rtw_hal_xmit(padapter, pxmitframe) == _TRUE)
  3044. {
  3045. rtw_os_xmit_complete(padapter, pxmitframe);
  3046. }
  3047. _enter_critical_bh(&psta->sleep_q.lock, &irqL);
  3048. */
  3049. rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
  3050. }
  3051. //for BC/MC Frames
  3052. if(!psta_bmc)
  3053. goto _exit;
  3054. if((pstapriv->sta_dz_bitmap&0xfffe) == 0x0)//no any sta in ps mode
  3055. {
  3056. xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
  3057. xmitframe_plist = get_next(xmitframe_phead);
  3058. while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE)
  3059. {
  3060. pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
  3061. xmitframe_plist = get_next(xmitframe_plist);
  3062. rtw_list_delete(&pxmitframe->list);
  3063. psta_bmc->sleepq_len--;
  3064. if(psta_bmc->sleepq_len>0)
  3065. pxmitframe->attrib.mdata = 1;
  3066. else
  3067. pxmitframe->attrib.mdata = 0;
  3068. pxmitframe->attrib.triggered = 1;
  3069. /*
  3070. _exit_critical_bh(&psta_bmc->sleep_q.lock, &irqL);
  3071. if(rtw_hal_xmit(padapter, pxmitframe) == _TRUE)
  3072. {
  3073. rtw_os_xmit_complete(padapter, pxmitframe);
  3074. }
  3075. _enter_critical_bh(&psta_bmc->sleep_q.lock, &irqL);
  3076. */
  3077. rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
  3078. }
  3079. if(psta_bmc->sleepq_len==0)
  3080. {
  3081. pstapriv->tim_bitmap &= ~BIT(0);
  3082. pstapriv->sta_dz_bitmap &= ~BIT(0);
  3083. //DBG_871X("wakeup to xmit, qlen==0, update_BCNTIM, tim=%x\n", pstapriv->tim_bitmap);
  3084. //upate BCN for TIM IE
  3085. //update_BCNTIM(padapter);
  3086. update_mask |= BIT(1);
  3087. }
  3088. }
  3089. if(psta->sleepq_len==0)
  3090. {
  3091. #ifdef CONFIG_TDLS
  3092. if( psta->tdls_sta_state & TDLS_LINKED_STATE )
  3093. {
  3094. if(psta->state&WIFI_SLEEP_STATE)
  3095. psta->state ^= WIFI_SLEEP_STATE;
  3096. goto _exit;
  3097. }
  3098. #endif //CONFIG_TDLS
  3099. pstapriv->tim_bitmap &= ~BIT(psta->aid);
  3100. //DBG_871X("wakeup to xmit, qlen==0, update_BCNTIM, tim=%x\n", pstapriv->tim_bitmap);
  3101. //upate BCN for TIM IE
  3102. //update_BCNTIM(padapter);
  3103. update_mask = BIT(0);
  3104. if(psta->state&WIFI_SLEEP_STATE)
  3105. psta->state ^= WIFI_SLEEP_STATE;
  3106. if(psta->state & WIFI_STA_ALIVE_CHK_STATE)
  3107. {
  3108. psta->expire_to = pstapriv->expire_to;
  3109. psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
  3110. }
  3111. pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
  3112. }
  3113. _exit:
  3114. //_exit_critical_bh(&psta_bmc->sleep_q.lock, &irqL);
  3115. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  3116. if(update_mask)
  3117. {
  3118. //update_BCNTIM(padapter);
  3119. //printk("%s => call update_beacon\n",__FUNCTION__);
  3120. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  3121. }
  3122. }
  3123. void xmit_delivery_enabled_frames(_adapter *padapter, struct sta_info *psta)
  3124. {
  3125. _irqL irqL;
  3126. u8 wmmps_ac=0;
  3127. _list *xmitframe_plist, *xmitframe_phead;
  3128. struct xmit_frame *pxmitframe=NULL;
  3129. struct sta_priv *pstapriv = &padapter->stapriv;
  3130. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  3131. //_enter_critical_bh(&psta->sleep_q.lock, &irqL);
  3132. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  3133. xmitframe_phead = get_list_head(&psta->sleep_q);
  3134. xmitframe_plist = get_next(xmitframe_phead);
  3135. while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE)
  3136. {
  3137. pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
  3138. xmitframe_plist = get_next(xmitframe_plist);
  3139. switch(pxmitframe->attrib.priority)
  3140. {
  3141. case 1:
  3142. case 2:
  3143. wmmps_ac = psta->uapsd_bk&BIT(1);
  3144. break;
  3145. case 4:
  3146. case 5:
  3147. wmmps_ac = psta->uapsd_vi&BIT(1);
  3148. break;
  3149. case 6:
  3150. case 7:
  3151. wmmps_ac = psta->uapsd_vo&BIT(1);
  3152. break;
  3153. case 0:
  3154. case 3:
  3155. default:
  3156. wmmps_ac = psta->uapsd_be&BIT(1);
  3157. break;
  3158. }
  3159. if(!wmmps_ac)
  3160. continue;
  3161. rtw_list_delete(&pxmitframe->list);
  3162. psta->sleepq_len--;
  3163. psta->sleepq_ac_len--;
  3164. if(psta->sleepq_ac_len>0)
  3165. {
  3166. pxmitframe->attrib.mdata = 1;
  3167. pxmitframe->attrib.eosp = 0;
  3168. }
  3169. else
  3170. {
  3171. pxmitframe->attrib.mdata = 0;
  3172. pxmitframe->attrib.eosp = 1;
  3173. }
  3174. pxmitframe->attrib.triggered = 1;
  3175. /*
  3176. if(rtw_hal_xmit(padapter, pxmitframe) == _TRUE)
  3177. {
  3178. rtw_os_xmit_complete(padapter, pxmitframe);
  3179. }
  3180. */
  3181. rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
  3182. if((psta->sleepq_ac_len==0) && (!psta->has_legacy_ac) && (wmmps_ac))
  3183. {
  3184. #ifdef CONFIG_TDLS
  3185. if(psta->tdls_sta_state & TDLS_LINKED_STATE )
  3186. {
  3187. //_exit_critical_bh(&psta->sleep_q.lock, &irqL);
  3188. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  3189. return;
  3190. }
  3191. #endif //CONFIG_TDLS
  3192. pstapriv->tim_bitmap &= ~BIT(psta->aid);
  3193. //DBG_871X("wakeup to xmit, qlen==0, update_BCNTIM, tim=%x\n", pstapriv->tim_bitmap);
  3194. //upate BCN for TIM IE
  3195. //update_BCNTIM(padapter);
  3196. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  3197. //update_mask = BIT(0);
  3198. }
  3199. }
  3200. //_exit_critical_bh(&psta->sleep_q.lock, &irqL);
  3201. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  3202. }
  3203. #endif
  3204. #ifdef CONFIG_XMIT_THREAD_MODE
  3205. void enqueue_pending_xmitbuf(
  3206. struct xmit_priv *pxmitpriv,
  3207. struct xmit_buf *pxmitbuf)
  3208. {
  3209. _irqL irql;
  3210. _queue *pqueue;
  3211. _adapter *pri_adapter = pxmitpriv->adapter;
  3212. pqueue = &pxmitpriv->pending_xmitbuf_queue;
  3213. _enter_critical_bh(&pqueue->lock, &irql);
  3214. rtw_list_delete(&pxmitbuf->list);
  3215. rtw_list_insert_tail(&pxmitbuf->list, get_list_head(pqueue));
  3216. _exit_critical_bh(&pqueue->lock, &irql);
  3217. #if defined(CONFIG_SDIO_HCI) && defined(CONFIG_CONCURRENT_MODE)
  3218. if (pri_adapter->adapter_type > PRIMARY_ADAPTER)
  3219. pri_adapter = pri_adapter->pbuddy_adapter;
  3220. #endif //SDIO_HCI + CONCURRENT
  3221. _rtw_up_sema(&(pri_adapter->xmitpriv.xmit_sema));
  3222. }
  3223. struct xmit_buf* dequeue_pending_xmitbuf(
  3224. struct xmit_priv *pxmitpriv)
  3225. {
  3226. _irqL irql;
  3227. struct xmit_buf *pxmitbuf;
  3228. _queue *pqueue;
  3229. pxmitbuf = NULL;
  3230. pqueue = &pxmitpriv->pending_xmitbuf_queue;
  3231. _enter_critical_bh(&pqueue->lock, &irql);
  3232. if (_rtw_queue_empty(pqueue) == _FALSE)
  3233. {
  3234. _list *plist, *phead;
  3235. phead = get_list_head(pqueue);
  3236. plist = get_next(phead);
  3237. pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
  3238. rtw_list_delete(&pxmitbuf->list);
  3239. }
  3240. _exit_critical_bh(&pqueue->lock, &irql);
  3241. return pxmitbuf;
  3242. }
  3243. struct xmit_buf* dequeue_pending_xmitbuf_under_survey(
  3244. struct xmit_priv *pxmitpriv)
  3245. {
  3246. _irqL irql;
  3247. struct xmit_buf *pxmitbuf;
  3248. #ifdef CONFIG_USB_HCI
  3249. struct xmit_frame *pxmitframe;
  3250. #endif
  3251. _queue *pqueue;
  3252. pxmitbuf = NULL;
  3253. pqueue = &pxmitpriv->pending_xmitbuf_queue;
  3254. _enter_critical_bh(&pqueue->lock, &irql);
  3255. if (_rtw_queue_empty(pqueue) == _FALSE)
  3256. {
  3257. _list *plist, *phead;
  3258. u8 type;
  3259. phead = get_list_head(pqueue);
  3260. plist = phead;
  3261. do {
  3262. plist = get_next(plist);
  3263. if (plist == phead) break;
  3264. pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
  3265. #ifdef CONFIG_USB_HCI
  3266. pxmitframe = (struct xmit_frame*)pxmitbuf->priv_data;
  3267. if(pxmitframe)
  3268. {
  3269. type = GetFrameSubType(pxmitbuf->pbuf + TXDESC_SIZE + pxmitframe->pkt_offset * PACKET_OFFSET_SZ);
  3270. }
  3271. else
  3272. {
  3273. DBG_871X("%s, !!!ERROR!!! For USB, TODO ITEM \n", __FUNCTION__);
  3274. }
  3275. #else
  3276. type = GetFrameSubType(pxmitbuf->pbuf + TXDESC_OFFSET);
  3277. #endif
  3278. if ((type == WIFI_PROBEREQ) ||
  3279. (type == WIFI_DATA_NULL) ||
  3280. (type == WIFI_QOS_DATA_NULL))
  3281. {
  3282. rtw_list_delete(&pxmitbuf->list);
  3283. break;
  3284. }
  3285. pxmitbuf = NULL;
  3286. } while (1);
  3287. }
  3288. _exit_critical_bh(&pqueue->lock, &irql);
  3289. return pxmitbuf;
  3290. }
  3291. sint check_pending_xmitbuf(
  3292. struct xmit_priv *pxmitpriv)
  3293. {
  3294. _queue *pqueue;
  3295. pqueue = &pxmitpriv->pending_xmitbuf_queue;
  3296. if(_rtw_queue_empty(pqueue) == _FALSE)
  3297. return _TRUE;
  3298. else
  3299. return _FALSE;
  3300. }
  3301. thread_return rtw_xmit_thread(thread_context context)
  3302. {
  3303. s32 err;
  3304. PADAPTER padapter;
  3305. err = _SUCCESS;
  3306. padapter = (PADAPTER)context;
  3307. thread_enter("RTW_XMIT_THREAD");
  3308. do {
  3309. err = rtw_hal_xmit_thread_handler(padapter);
  3310. flush_signals_thread();
  3311. } while (_SUCCESS == err);
  3312. _rtw_up_sema(&padapter->xmitpriv.terminate_xmitthread_sema);
  3313. thread_exit();
  3314. }
  3315. #endif
  3316. void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms)
  3317. {
  3318. sctx->timeout_ms = timeout_ms;
  3319. sctx->submit_time= rtw_get_current_time();
  3320. #ifdef PLATFORM_LINUX /* TODO: add condition wating interface for other os */
  3321. init_completion(&sctx->done);
  3322. #endif
  3323. sctx->status = RTW_SCTX_SUBMITTED;
  3324. }
  3325. int rtw_sctx_wait(struct submit_ctx *sctx)
  3326. {
  3327. int ret = _FAIL;
  3328. unsigned long expire;
  3329. int status = 0;
  3330. #ifdef PLATFORM_LINUX
  3331. expire= sctx->timeout_ms ? msecs_to_jiffies(sctx->timeout_ms) : MAX_SCHEDULE_TIMEOUT;
  3332. if (!wait_for_completion_timeout(&sctx->done, expire)) {
  3333. /* timeout, do something?? */
  3334. status = RTW_SCTX_DONE_TIMEOUT;
  3335. DBG_871X("%s timeout\n", __func__);
  3336. } else {
  3337. status = sctx->status;
  3338. }
  3339. #endif
  3340. if (status == RTW_SCTX_DONE_SUCCESS) {
  3341. ret = _SUCCESS;
  3342. }
  3343. return ret;
  3344. }
  3345. bool rtw_sctx_chk_waring_status(int status)
  3346. {
  3347. switch(status) {
  3348. case RTW_SCTX_DONE_UNKNOWN:
  3349. case RTW_SCTX_DONE_BUF_ALLOC:
  3350. case RTW_SCTX_DONE_BUF_FREE:
  3351. case RTW_SCTX_DONE_DRV_STOP:
  3352. case RTW_SCTX_DONE_DEV_REMOVE:
  3353. return _TRUE;
  3354. default:
  3355. return _FALSE;
  3356. }
  3357. }
  3358. void rtw_sctx_done_err(struct submit_ctx **sctx, int status)
  3359. {
  3360. if (*sctx) {
  3361. if (rtw_sctx_chk_waring_status(status))
  3362. DBG_871X("%s status:%d\n", __func__, status);
  3363. (*sctx)->status = status;
  3364. #ifdef PLATFORM_LINUX
  3365. complete(&((*sctx)->done));
  3366. #endif
  3367. *sctx = NULL;
  3368. }
  3369. }
  3370. void rtw_sctx_done(struct submit_ctx **sctx)
  3371. {
  3372. rtw_sctx_done_err(sctx, RTW_SCTX_DONE_SUCCESS);
  3373. }
  3374. #ifdef CONFIG_XMIT_ACK
  3375. #ifdef CONFIG_XMIT_ACK_POLLING
  3376. s32 c2h_evt_hdl(_adapter *adapter, struct c2h_evt_hdr *c2h_evt, c2h_id_filter filter);
  3377. /**
  3378. * rtw_ack_tx_polling -
  3379. * @pxmitpriv: xmit_priv to address ack_tx_ops
  3380. * @timeout_ms: timeout msec
  3381. *
  3382. * Init ack_tx_ops and then do c2h_evt_hdl() and polling ack_tx_ops repeatedly
  3383. * till tx report or timeout
  3384. * Returns: _SUCCESS if TX report ok, _FAIL for others
  3385. */
  3386. int rtw_ack_tx_polling(struct xmit_priv *pxmitpriv, u32 timeout_ms)
  3387. {
  3388. int ret = _FAIL;
  3389. struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
  3390. _adapter *adapter = container_of(pxmitpriv, _adapter, xmitpriv);
  3391. pack_tx_ops->submit_time = rtw_get_current_time();
  3392. pack_tx_ops->timeout_ms = timeout_ms;
  3393. pack_tx_ops->status = RTW_SCTX_SUBMITTED;
  3394. do {
  3395. c2h_evt_hdl(adapter, NULL, rtw_hal_c2h_id_filter_ccx(adapter));
  3396. if (pack_tx_ops->status != RTW_SCTX_SUBMITTED)
  3397. break;
  3398. if (adapter->bDriverStopped) {
  3399. pack_tx_ops->status = RTW_SCTX_DONE_DRV_STOP;
  3400. break;
  3401. }
  3402. if (adapter->bSurpriseRemoved) {
  3403. pack_tx_ops->status = RTW_SCTX_DONE_DEV_REMOVE;
  3404. break;
  3405. }
  3406. rtw_msleep_os(10);
  3407. } while (rtw_get_passing_time_ms(pack_tx_ops->submit_time) < timeout_ms);
  3408. if (pack_tx_ops->status == RTW_SCTX_SUBMITTED) {
  3409. pack_tx_ops->status = RTW_SCTX_DONE_TIMEOUT;
  3410. DBG_871X("%s timeout\n", __func__);
  3411. }
  3412. if (pack_tx_ops->status == RTW_SCTX_DONE_SUCCESS)
  3413. ret = _SUCCESS;
  3414. return ret;
  3415. }
  3416. #endif
  3417. int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms)
  3418. {
  3419. #ifdef CONFIG_XMIT_ACK_POLLING
  3420. return rtw_ack_tx_polling(pxmitpriv, timeout_ms);
  3421. #else
  3422. struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
  3423. pack_tx_ops->submit_time = rtw_get_current_time();
  3424. pack_tx_ops->timeout_ms = timeout_ms;
  3425. pack_tx_ops->status = RTW_SCTX_SUBMITTED;
  3426. return rtw_sctx_wait(pack_tx_ops);
  3427. #endif
  3428. }
  3429. void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status)
  3430. {
  3431. struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
  3432. if (pxmitpriv->ack_tx) {
  3433. rtw_sctx_done_err(&pack_tx_ops, status);
  3434. } else {
  3435. DBG_871X("%s ack_tx not set\n", __func__);
  3436. }
  3437. }
  3438. #endif //CONFIG_XMIT_ACK