rtw_mlme_ext.c 476 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910
  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_MLME_EXT_C_
  21. #include <drv_types.h>
  22. #ifdef CONFIG_IOCTL_CFG80211
  23. #include <rtw_wifi_regd.h>
  24. #endif /* CONFIG_IOCTL_CFG80211 */
  25. #include <hal_data.h>
  26. struct mlme_handler mlme_sta_tbl[] = {
  27. {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
  28. {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
  29. {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
  30. {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
  31. {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
  32. {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
  33. /*----------------------------------------------------------
  34. below 2 are reserved
  35. -----------------------------------------------------------*/
  36. {0, "DoReserved", &DoReserved},
  37. {0, "DoReserved", &DoReserved},
  38. {WIFI_BEACON, "OnBeacon", &OnBeacon},
  39. {WIFI_ATIM, "OnATIM", &OnAtim},
  40. {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
  41. {WIFI_AUTH, "OnAuth", &OnAuthClient},
  42. {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
  43. {WIFI_ACTION, "OnAction", &OnAction},
  44. {WIFI_ACTION_NOACK, "OnActionNoAck", &OnAction},
  45. };
  46. #ifdef _CONFIG_NATIVEAP_MLME_
  47. struct mlme_handler mlme_ap_tbl[] = {
  48. {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
  49. {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
  50. {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
  51. {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
  52. {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
  53. {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
  54. /*----------------------------------------------------------
  55. below 2 are reserved
  56. -----------------------------------------------------------*/
  57. {0, "DoReserved", &DoReserved},
  58. {0, "DoReserved", &DoReserved},
  59. {WIFI_BEACON, "OnBeacon", &OnBeacon},
  60. {WIFI_ATIM, "OnATIM", &OnAtim},
  61. {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
  62. {WIFI_AUTH, "OnAuth", &OnAuth},
  63. {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
  64. {WIFI_ACTION, "OnAction", &OnAction},
  65. {WIFI_ACTION_NOACK, "OnActionNoAck", &OnAction},
  66. };
  67. #endif
  68. struct action_handler OnAction_tbl[] = {
  69. {RTW_WLAN_CATEGORY_SPECTRUM_MGMT, "ACTION_SPECTRUM_MGMT", on_action_spct},
  70. {RTW_WLAN_CATEGORY_QOS, "ACTION_QOS", &OnAction_qos},
  71. {RTW_WLAN_CATEGORY_DLS, "ACTION_DLS", &OnAction_dls},
  72. {RTW_WLAN_CATEGORY_BACK, "ACTION_BACK", &OnAction_back},
  73. {RTW_WLAN_CATEGORY_PUBLIC, "ACTION_PUBLIC", on_action_public},
  74. {RTW_WLAN_CATEGORY_RADIO_MEASUREMENT, "ACTION_RADIO_MEASUREMENT", &DoReserved},
  75. {RTW_WLAN_CATEGORY_FT, "ACTION_FT", &OnAction_ft},
  76. {RTW_WLAN_CATEGORY_HT, "ACTION_HT", &OnAction_ht},
  77. #ifdef CONFIG_IEEE80211W
  78. {RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &OnAction_sa_query},
  79. #else
  80. {RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &DoReserved},
  81. #endif /* CONFIG_IEEE80211W */
  82. #ifdef CONFIG_RTW_WNM
  83. {RTW_WLAN_CATEGORY_WNM, "ACTION_WNM", &on_action_wnm},
  84. #endif
  85. {RTW_WLAN_CATEGORY_UNPROTECTED_WNM, "ACTION_UNPROTECTED_WNM", &DoReserved},
  86. {RTW_WLAN_CATEGORY_SELF_PROTECTED, "ACTION_SELF_PROTECTED", &DoReserved},
  87. {RTW_WLAN_CATEGORY_WMM, "ACTION_WMM", &OnAction_wmm},
  88. {RTW_WLAN_CATEGORY_VHT, "ACTION_VHT", &OnAction_vht},
  89. {RTW_WLAN_CATEGORY_P2P, "ACTION_P2P", &OnAction_p2p},
  90. };
  91. u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
  92. /**************************************************
  93. OUI definitions for the vendor specific IE
  94. ***************************************************/
  95. unsigned char RTW_WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};
  96. unsigned char WMM_OUI[] = {0x00, 0x50, 0xf2, 0x02};
  97. unsigned char WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};
  98. unsigned char P2P_OUI[] = {0x50, 0x6F, 0x9A, 0x09};
  99. unsigned char WFD_OUI[] = {0x50, 0x6F, 0x9A, 0x0A};
  100. unsigned char WMM_INFO_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
  101. unsigned char WMM_PARA_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
  102. unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02};
  103. unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02};
  104. extern unsigned char REALTEK_96B_IE[];
  105. #ifdef LEGACY_CHANNEL_PLAN_REF
  106. /********************************************************
  107. ChannelPlan definitions
  108. *********************************************************/
  109. static RT_CHANNEL_PLAN legacy_channel_plan[] = {
  110. /* 0x00, RTW_CHPLAN_FCC */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165}, 32},
  111. /* 0x01, RTW_CHPLAN_IC */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 136, 140, 149, 153, 157, 161, 165}, 31},
  112. /* 0x02, RTW_CHPLAN_ETSI */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}, 32},
  113. /* 0x03, RTW_CHPLAN_SPAIN */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  114. /* 0x04, RTW_CHPLAN_FRANCE */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  115. /* 0x05, RTW_CHPLAN_MKK */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  116. /* 0x06, RTW_CHPLAN_MKK1 */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  117. /* 0x07, RTW_CHPLAN_ISRAEL */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64}, 21},
  118. /* 0x08, RTW_CHPLAN_TELEC */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},
  119. /* 0x09, RTW_CHPLAN_GLOBAL_DOAMIN */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14},
  120. /* 0x0A, RTW_CHPLAN_WORLD_WIDE_13 */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
  121. /* 0x0B, RTW_CHPLAN_TAIWAN */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 56, 60, 64, 100, 104, 108, 112, 116, 136, 140, 149, 153, 157, 161, 165}, 26},
  122. /* 0x0C, RTW_CHPLAN_CHINA */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 149, 153, 157, 161, 165}, 18},
  123. /* 0x0D, RTW_CHPLAN_SINGAPORE_INDIA_MEXICO */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165}, 24},
  124. /* 0x0E, RTW_CHPLAN_KOREA */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 149, 153, 157, 161, 165}, 31},
  125. /* 0x0F, RTW_CHPLAN_TURKEY */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64}, 19},
  126. /* 0x10, RTW_CHPLAN_JAPAN */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}, 32},
  127. /* 0x11, RTW_CHPLAN_FCC_NO_DFS */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 149, 153, 157, 161, 165}, 20},
  128. /* 0x12, RTW_CHPLAN_JAPAN_NO_DFS */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48}, 17},
  129. /* 0x13, RTW_CHPLAN_WORLD_WIDE_5G */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165}, 37},
  130. /* 0x14, RTW_CHPLAN_TAIWAN_NO_DFS */ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 56, 60, 64, 149, 153, 157, 161, 165}, 19},
  131. };
  132. #endif
  133. static struct ch_list_t RTW_ChannelPlan2G[] = {
  134. /* 0, RTW_RD_2G_NULL */ CH_LIST_ENT(0),
  135. /* 1, RTW_RD_2G_WORLD */ CH_LIST_ENT(13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
  136. /* 2, RTW_RD_2G_ETSI1 */ CH_LIST_ENT(13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
  137. /* 3, RTW_RD_2G_FCC1 */ CH_LIST_ENT(11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
  138. /* 4, RTW_RD_2G_MKK1 */ CH_LIST_ENT(14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14),
  139. /* 5, RTW_RD_2G_ETSI2 */ CH_LIST_ENT(4, 10, 11, 12, 13),
  140. /* 6, RTW_RD_2G_GLOBAL */ CH_LIST_ENT(14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14),
  141. /* 7, RTW_RD_2G_MKK2 */ CH_LIST_ENT(13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
  142. /* 8, RTW_RD_2G_FCC2 */ CH_LIST_ENT(13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
  143. };
  144. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  145. static struct ch_list_t RTW_ChannelPlan5G[] = {
  146. /* 0, RTW_RD_5G_NULL */ CH_LIST_ENT(0),
  147. /* 1, RTW_RD_5G_ETSI1 */ CH_LIST_ENT(19, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140),
  148. /* 2, RTW_RD_5G_ETSI2 */ CH_LIST_ENT(24, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165),
  149. /* 3, RTW_RD_5G_ETSI3 */ CH_LIST_ENT(22, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 149, 153, 157, 161, 165),
  150. /* 4, RTW_RD_5G_FCC1 */ CH_LIST_ENT(24, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165),
  151. /* 5, RTW_RD_5G_FCC2 */ CH_LIST_ENT(9, 36, 40, 44, 48, 149, 153, 157, 161, 165),
  152. /* 6, RTW_RD_5G_FCC3 */ CH_LIST_ENT(13, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165),
  153. /* 7, RTW_RD_5G_FCC4 */ CH_LIST_ENT(12, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161),
  154. /* 8, RTW_RD_5G_FCC5 */ CH_LIST_ENT(5, 149, 153, 157, 161, 165),
  155. /* 9, RTW_RD_5G_FCC6 */ CH_LIST_ENT(8, 36, 40, 44, 48, 52, 56, 60, 64),
  156. /* 10, RTW_RD_5G_FCC7 */ CH_LIST_ENT(21, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165),
  157. /* 11, RTW_RD_5G_KCC1 */ CH_LIST_ENT(19, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 149, 153, 157, 161),
  158. /* 12, RTW_RD_5G_MKK1 */ CH_LIST_ENT(19, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140),
  159. /* 13, RTW_RD_5G_MKK2 */ CH_LIST_ENT(8, 36, 40, 44, 48, 52, 56, 60, 64),
  160. /* 14, RTW_RD_5G_MKK3 */ CH_LIST_ENT(11, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140),
  161. /* 15, RTW_RD_5G_NCC1 */ CH_LIST_ENT(16, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165),
  162. /* 16, RTW_RD_5G_NCC2 */ CH_LIST_ENT(8, 56, 60, 64, 149, 153, 157, 161, 165),
  163. /* 17, RTW_RD_5G_NCC3 */ CH_LIST_ENT(5, 149, 153, 157, 161, 165),
  164. /* 18, RTW_RD_5G_ETSI4 */ CH_LIST_ENT(4, 36, 40, 44, 48),
  165. /* 19, RTW_RD_5G_ETSI5 */ CH_LIST_ENT(21, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165),
  166. /* 20, RTW_RD_5G_FCC8 */ CH_LIST_ENT(4, 149, 153, 157, 161),
  167. /* 21, RTW_RD_5G_ETSI6 */ CH_LIST_ENT(8, 36, 40, 44, 48, 52, 56, 60, 64),
  168. /* 22, RTW_RD_5G_ETSI7 */ CH_LIST_ENT(13, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165),
  169. /* 23, RTW_RD_5G_ETSI8 */ CH_LIST_ENT(9, 36, 40, 44, 48, 149, 153, 157, 161, 165),
  170. /* 24, RTW_RD_5G_ETSI9 */ CH_LIST_ENT(11, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140),
  171. /* 25, RTW_RD_5G_ETSI10 */ CH_LIST_ENT(5, 149, 153, 157, 161, 165),
  172. /* 26, RTW_RD_5G_ETSI11 */ CH_LIST_ENT(16, 36, 40, 44, 48, 52, 56, 60, 64, 132, 136, 140, 149, 153, 157, 161, 165),
  173. /* 27, RTW_RD_5G_NCC4 */ CH_LIST_ENT(17, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165),
  174. /* 28, RTW_RD_5G_ETSI12 */ CH_LIST_ENT(4, 149, 153, 157, 161),
  175. /* 29, RTW_RD_5G_FCC9 */ CH_LIST_ENT(21, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165),
  176. /* 30, RTW_RD_5G_ETSI13 */ CH_LIST_ENT(16, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140),
  177. /* 31, RTW_RD_5G_FCC10 */ CH_LIST_ENT(20, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161),
  178. /* 32, RTW_RD_5G_MKK4 */ CH_LIST_ENT(4, 36, 40, 44, 48),
  179. /* 33, RTW_RD_5G_ETSI14 */ CH_LIST_ENT(11, 36, 40, 44, 48, 52, 56, 60, 64, 132, 136, 140),
  180. /* 34, RTW_RD_5G_FCC11 */ CH_LIST_ENT(25, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 149, 153, 157, 161, 165),
  181. /* 35, RTW_RD_5G_ETSI15 */ CH_LIST_ENT(21, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 149, 153, 157, 161, 165),
  182. /* 36, RTW_RD_5G_MKK5 */ CH_LIST_ENT(24, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165),
  183. /* 37, RTW_RD_5G_ETSI16 */ CH_LIST_ENT(24, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165),
  184. /* 38, RTW_RD_5G_ETSI17 */ CH_LIST_ENT(24, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165),
  185. /* 39, RTW_RD_5G_FCC12*/ CH_LIST_ENT(24, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165),
  186. /* 40, RTW_RD_5G_FCC13 */ CH_LIST_ENT(24, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165),
  187. /* 41, RTW_RD_5G_FCC14 */ CH_LIST_ENT(21, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165),
  188. /* 42, RTW_RD_5G_FCC15 */ CH_LIST_ENT(13, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165),
  189. /* 43, RTW_RD_5G_FCC16 */ CH_LIST_ENT(13, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165),
  190. /* 44, RTW_RD_5G_ETSI18 */ CH_LIST_ENT(9, 36, 40, 44, 48, 149, 153, 157, 161, 165),
  191. /* 45, RTW_RD_5G_ETSI19 */ CH_LIST_ENT(24, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165),
  192. /* === Below are driver defined for legacy channel plan compatible, NO static index assigned ==== */
  193. /* RTW_RD_5G_OLD_FCC1 */ CH_LIST_ENT(20, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 136, 140, 149, 153, 157, 161, 165),
  194. /* RTW_RD_5G_OLD_NCC1 */ CH_LIST_ENT(15, 56, 60, 64, 100, 104, 108, 112, 116, 136, 140, 149, 153, 157, 161, 165),
  195. /* RTW_RD_5G_OLD_KCC1 */ CH_LIST_ENT(20, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 149, 153, 157, 161, 165),
  196. };
  197. #endif /* CONFIG_IEEE80211_BAND_5GHZ */
  198. static RT_CHANNEL_PLAN_MAP RTW_ChannelPlanMap[] = {
  199. /* ===== 0x00 ~ 0x1F, legacy channel plan ===== */
  200. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_KCC1, TXPWR_LMT_FCC), /* 0x00, RTW_CHPLAN_FCC */
  201. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_OLD_FCC1, TXPWR_LMT_FCC), /* 0x01, RTW_CHPLAN_IC */
  202. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_ETSI1, TXPWR_LMT_ETSI), /* 0x02, RTW_CHPLAN_ETSI */
  203. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_NULL, TXPWR_LMT_ETSI), /* 0x03, RTW_CHPLAN_SPAIN */
  204. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_NULL, TXPWR_LMT_ETSI), /* 0x04, RTW_CHPLAN_FRANCE */
  205. CHPLAN_ENT(RTW_RD_2G_MKK1, RTW_RD_5G_NULL, TXPWR_LMT_MKK), /* 0x05, RTW_CHPLAN_MKK */
  206. CHPLAN_ENT(RTW_RD_2G_MKK1, RTW_RD_5G_NULL, TXPWR_LMT_MKK), /* 0x06, RTW_CHPLAN_MKK1 */
  207. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_FCC6, TXPWR_LMT_ETSI), /* 0x07, RTW_CHPLAN_ISRAEL */
  208. CHPLAN_ENT(RTW_RD_2G_MKK1, RTW_RD_5G_FCC6, TXPWR_LMT_MKK), /* 0x08, RTW_CHPLAN_TELEC */
  209. CHPLAN_ENT(RTW_RD_2G_MKK1, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x09, RTW_CHPLAN_GLOBAL_DOAMIN */
  210. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x0A, RTW_CHPLAN_WORLD_WIDE_13 */
  211. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_OLD_NCC1, TXPWR_LMT_FCC), /* 0x0B, RTW_CHPLAN_TAIWAN */
  212. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_FCC5, TXPWR_LMT_ETSI), /* 0x0C, RTW_CHPLAN_CHINA */
  213. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC3, TXPWR_LMT_WW), /* 0x0D, RTW_CHPLAN_SINGAPORE_INDIA_MEXICO */ /* ETSI:Singapore, India. FCC:Mexico => WW */
  214. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_OLD_KCC1, TXPWR_LMT_ETSI), /* 0x0E, RTW_CHPLAN_KOREA */
  215. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC6, TXPWR_LMT_ETSI), /* 0x0F, RTW_CHPLAN_TURKEY */
  216. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_ETSI1, TXPWR_LMT_MKK), /* 0x10, RTW_CHPLAN_JAPAN */
  217. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC2, TXPWR_LMT_FCC), /* 0x11, RTW_CHPLAN_FCC_NO_DFS */
  218. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_FCC7, TXPWR_LMT_MKK), /* 0x12, RTW_CHPLAN_JAPAN_NO_DFS */
  219. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC1, TXPWR_LMT_WW), /* 0x13, RTW_CHPLAN_WORLD_WIDE_5G */
  220. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_NCC2, TXPWR_LMT_FCC), /* 0x14, RTW_CHPLAN_TAIWAN_NO_DFS */
  221. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC7, TXPWR_LMT_ETSI), /* 0x15, RTW_CHPLAN_ETSI_NO_DFS */
  222. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_NCC1, TXPWR_LMT_ETSI), /* 0x16, RTW_CHPLAN_KOREA_NO_DFS */
  223. CHPLAN_ENT(RTW_RD_2G_MKK1, RTW_RD_5G_FCC7, TXPWR_LMT_MKK), /* 0x17, RTW_CHPLAN_JAPAN_NO_DFS */
  224. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_FCC5, TXPWR_LMT_ETSI), /* 0x18, RTW_CHPLAN_PAKISTAN_NO_DFS */
  225. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC5, TXPWR_LMT_FCC), /* 0x19, RTW_CHPLAN_TAIWAN2_NO_DFS */
  226. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x1A, */
  227. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x1B, */
  228. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x1C, */
  229. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x1D, */
  230. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x1E, */
  231. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_FCC1, TXPWR_LMT_WW), /* 0x1F, RTW_CHPLAN_WORLD_WIDE_ONLY_5G */
  232. /* ===== 0x20 ~ 0x7F, new channel plan ===== */
  233. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x20, RTW_CHPLAN_WORLD_NULL */
  234. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_NULL, TXPWR_LMT_ETSI), /* 0x21, RTW_CHPLAN_ETSI1_NULL */
  235. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_NULL, TXPWR_LMT_FCC), /* 0x22, RTW_CHPLAN_FCC1_NULL */
  236. CHPLAN_ENT(RTW_RD_2G_MKK1, RTW_RD_5G_NULL, TXPWR_LMT_MKK), /* 0x23, RTW_CHPLAN_MKK1_NULL */
  237. CHPLAN_ENT(RTW_RD_2G_ETSI2, RTW_RD_5G_NULL, TXPWR_LMT_ETSI), /* 0x24, RTW_CHPLAN_ETSI2_NULL */
  238. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC1, TXPWR_LMT_FCC), /* 0x25, RTW_CHPLAN_FCC1_FCC1 */
  239. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI1, TXPWR_LMT_ETSI), /* 0x26, RTW_CHPLAN_WORLD_ETSI1 */
  240. CHPLAN_ENT(RTW_RD_2G_MKK1, RTW_RD_5G_MKK1, TXPWR_LMT_MKK), /* 0x27, RTW_CHPLAN_MKK1_MKK1 */
  241. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_KCC1, TXPWR_LMT_ETSI), /* 0x28, RTW_CHPLAN_WORLD_KCC1 */
  242. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC2, TXPWR_LMT_FCC), /* 0x29, RTW_CHPLAN_WORLD_FCC2 */
  243. CHPLAN_ENT(RTW_RD_2G_FCC2, RTW_RD_5G_NULL, TXPWR_LMT_FCC), /* 0x2A, RTW_CHPLAN_FCC2_NULL */
  244. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x2B, */
  245. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x2C, */
  246. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x2D, */
  247. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x2E, */
  248. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x2F, */
  249. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC3, TXPWR_LMT_FCC), /* 0x30, RTW_CHPLAN_WORLD_FCC3 */
  250. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC4, TXPWR_LMT_FCC), /* 0x31, RTW_CHPLAN_WORLD_FCC4 */
  251. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC5, TXPWR_LMT_FCC), /* 0x32, RTW_CHPLAN_WORLD_FCC5 */
  252. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC6, TXPWR_LMT_FCC), /* 0x33, RTW_CHPLAN_WORLD_FCC6 */
  253. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC7, TXPWR_LMT_FCC), /* 0x34, RTW_CHPLAN_FCC1_FCC7 */
  254. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI2, TXPWR_LMT_ETSI), /* 0x35, RTW_CHPLAN_WORLD_ETSI2 */
  255. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI3, TXPWR_LMT_ETSI), /* 0x36, RTW_CHPLAN_WORLD_ETSI3 */
  256. CHPLAN_ENT(RTW_RD_2G_MKK1, RTW_RD_5G_MKK2, TXPWR_LMT_MKK), /* 0x37, RTW_CHPLAN_MKK1_MKK2 */
  257. CHPLAN_ENT(RTW_RD_2G_MKK1, RTW_RD_5G_MKK3, TXPWR_LMT_MKK), /* 0x38, RTW_CHPLAN_MKK1_MKK3 */
  258. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_NCC1, TXPWR_LMT_FCC), /* 0x39, RTW_CHPLAN_FCC1_NCC1 */
  259. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x3A, */
  260. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x3B, */
  261. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x3C, */
  262. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x3D, */
  263. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x3E, */
  264. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x3F, */
  265. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_NCC2, TXPWR_LMT_FCC), /* 0x40, RTW_CHPLAN_FCC1_NCC2 */
  266. CHPLAN_ENT(RTW_RD_2G_GLOBAL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x41, RTW_CHPLAN_GLOBAL_NULL */
  267. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_ETSI4, TXPWR_LMT_ETSI), /* 0x42, RTW_CHPLAN_ETSI1_ETSI4 */
  268. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC2, TXPWR_LMT_FCC), /* 0x43, RTW_CHPLAN_FCC1_FCC2 */
  269. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_NCC3, TXPWR_LMT_FCC), /* 0x44, RTW_CHPLAN_FCC1_NCC3 */
  270. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI5, TXPWR_LMT_ETSI), /* 0x45, RTW_CHPLAN_WORLD_ETSI5 */
  271. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC8, TXPWR_LMT_FCC), /* 0x46, RTW_CHPLAN_FCC1_FCC8 */
  272. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI6, TXPWR_LMT_ETSI), /* 0x47, RTW_CHPLAN_WORLD_ETSI6 */
  273. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI7, TXPWR_LMT_ETSI), /* 0x48, RTW_CHPLAN_WORLD_ETSI7 */
  274. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI8, TXPWR_LMT_ETSI), /* 0x49, RTW_CHPLAN_WORLD_ETSI8 */
  275. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x4A, */
  276. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x4B, */
  277. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x4C, */
  278. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x4D, */
  279. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x4E, */
  280. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x4F, */
  281. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI9, TXPWR_LMT_ETSI), /* 0x50, RTW_CHPLAN_WORLD_ETSI9 */
  282. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI10, TXPWR_LMT_ETSI), /* 0x51, RTW_CHPLAN_WORLD_ETSI10 */
  283. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI11, TXPWR_LMT_ETSI), /* 0x52, RTW_CHPLAN_WORLD_ETSI11 */
  284. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_NCC4, TXPWR_LMT_FCC), /* 0x53, RTW_CHPLAN_FCC1_NCC4 */
  285. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI12, TXPWR_LMT_ETSI), /* 0x54, RTW_CHPLAN_WORLD_ETSI12 */
  286. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC9, TXPWR_LMT_FCC), /* 0x55, RTW_CHPLAN_FCC1_FCC9 */
  287. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI13, TXPWR_LMT_ETSI), /* 0x56, RTW_CHPLAN_WORLD_ETSI13 */
  288. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC10, TXPWR_LMT_FCC), /* 0x57, RTW_CHPLAN_FCC1_FCC10 */
  289. CHPLAN_ENT(RTW_RD_2G_MKK2, RTW_RD_5G_MKK4, TXPWR_LMT_MKK), /* 0x58, RTW_CHPLAN_MKK2_MKK4 */
  290. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI14, TXPWR_LMT_ETSI), /* 0x59, RTW_CHPLAN_WORLD_ETSI14 */
  291. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x5A, */
  292. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x5B, */
  293. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x5C, */
  294. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x5D, */
  295. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x5E, */
  296. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_NULL, TXPWR_LMT_WW), /* 0x5F, */
  297. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC5, TXPWR_LMT_FCC), /* 0x60, RTW_CHPLAN_FCC1_FCC5 */
  298. CHPLAN_ENT(RTW_RD_2G_FCC2, RTW_RD_5G_FCC7, TXPWR_LMT_FCC), /* 0x61, RTW_CHPLAN_FCC2_FCC7 */
  299. CHPLAN_ENT(RTW_RD_2G_FCC2, RTW_RD_5G_FCC1, TXPWR_LMT_FCC), /* 0x62, RTW_CHPLAN_FCC2_FCC1 */
  300. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_ETSI15, TXPWR_LMT_ETSI), /* 0x63, RTW_CHPLAN_WORLD_ETSI15 */
  301. CHPLAN_ENT(RTW_RD_2G_MKK2, RTW_RD_5G_MKK5, TXPWR_LMT_MKK), /* 0x64, RTW_CHPLAN_MKK2_MKK5 */
  302. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_ETSI16, TXPWR_LMT_ETSI), /* 0x65, RTW_CHPLAN_ETSI1_ETSI16 */
  303. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC14, TXPWR_LMT_FCC), /* 0x66, RTW_CHPLAN_FCC1_FCC14 */
  304. CHPLAN_ENT(RTW_RD_2G_FCC1, RTW_RD_5G_FCC12, TXPWR_LMT_FCC), /* 0x67, RTW_CHPLAN_FCC1_FCC12 */
  305. CHPLAN_ENT(RTW_RD_2G_FCC2, RTW_RD_5G_FCC14, TXPWR_LMT_FCC), /* 0x68, RTW_CHPLAN_FCC2_FCC14 */
  306. CHPLAN_ENT(RTW_RD_2G_FCC2, RTW_RD_5G_FCC12, TXPWR_LMT_FCC), /* 0x69, RTW_CHPLAN_FCC2_FCC12 */
  307. CHPLAN_ENT(RTW_RD_2G_ETSI1, RTW_RD_5G_ETSI17, TXPWR_LMT_ETSI), /* 0x6A, RTW_CHPLAN_ETSI1_ETSI17 */
  308. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC16, TXPWR_LMT_FCC), /* 0x6B, RTW_CHPLAN_WORLD_FCC16 */
  309. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC13, TXPWR_LMT_FCC), /* 0x6C, RTW_CHPLAN_WORLD_FCC13 */
  310. CHPLAN_ENT(RTW_RD_2G_FCC2, RTW_RD_5G_FCC15, TXPWR_LMT_FCC), /* 0x6D, RTW_CHPLAN_FCC2_FCC15 */
  311. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC12, TXPWR_LMT_FCC), /* 0x6E, RTW_CHPLAN_WORLD_FCC12 */
  312. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_ETSI8, TXPWR_LMT_ETSI), /* 0x6F, RTW_CHPLAN_NULL_ETSI8 */
  313. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_ETSI18, TXPWR_LMT_ETSI), /* 0x70, RTW_CHPLAN_NULL_ETSI18 */
  314. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_ETSI17, TXPWR_LMT_ETSI), /* 0x71, RTW_CHPLAN_NULL_ETSI17 */
  315. CHPLAN_ENT(RTW_RD_2G_NULL, RTW_RD_5G_ETSI19, TXPWR_LMT_ETSI), /* 0x72, RTW_CHPLAN_NULL_ETSI19 */
  316. };
  317. static RT_CHANNEL_PLAN_MAP RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE =
  318. CHPLAN_ENT(RTW_RD_2G_WORLD, RTW_RD_5G_FCC1, TXPWR_LMT_FCC); /* 0x7F, Realtek Define */
  319. bool rtw_chplan_is_empty(u8 id)
  320. {
  321. RT_CHANNEL_PLAN_MAP *chplan_map;
  322. if (id == RTW_CHPLAN_REALTEK_DEFINE)
  323. chplan_map = &RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE;
  324. else
  325. chplan_map = &RTW_ChannelPlanMap[id];
  326. if (chplan_map->Index2G == RTW_RD_2G_NULL
  327. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  328. && chplan_map->Index5G == RTW_RD_5G_NULL
  329. #endif
  330. )
  331. return _TRUE;
  332. return _FALSE;
  333. }
  334. inline u8 rtw_rd_5g_band1_passive(u8 rtw_rd_5g)
  335. {
  336. u8 passive = 0;
  337. switch (rtw_rd_5g) {
  338. case RTW_RD_5G_FCC13:
  339. case RTW_RD_5G_FCC16:
  340. case RTW_RD_5G_ETSI18:
  341. case RTW_RD_5G_ETSI19:
  342. passive = 1;
  343. };
  344. return passive;
  345. }
  346. inline u8 rtw_rd_5g_band4_passive(u8 rtw_rd_5g)
  347. {
  348. u8 passive = 0;
  349. switch (rtw_rd_5g) {
  350. case RTW_RD_5G_MKK5:
  351. case RTW_RD_5G_ETSI16:
  352. case RTW_RD_5G_ETSI18:
  353. case RTW_RD_5G_ETSI19:
  354. passive = 1;
  355. };
  356. return passive;
  357. }
  358. void rtw_rfctl_init(_adapter *adapter)
  359. {
  360. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  361. _rtw_memset(rfctl, 0, sizeof(*rfctl));
  362. #ifdef CONFIG_DFS_MASTER
  363. rfctl->cac_start_time = rfctl->cac_end_time = RTW_CAC_STOPPED;
  364. /* TODO: dfs_master_timer */
  365. #endif
  366. }
  367. #ifdef CONFIG_DFS_MASTER
  368. /*
  369. * called in rtw_dfs_master_enable()
  370. * assume the request channel coverage is DFS range
  371. * base on the current status and the request channel coverage to check if need to reset complete CAC time
  372. */
  373. bool rtw_is_cac_reset_needed(_adapter *adapter, u8 ch, u8 bw, u8 offset)
  374. {
  375. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  376. bool needed = _FALSE;
  377. u32 cur_hi, cur_lo, hi, lo;
  378. if (rfctl->radar_detected == 1) {
  379. needed = _TRUE;
  380. goto exit;
  381. }
  382. if (rfctl->radar_detect_ch == 0) {
  383. needed = _TRUE;
  384. goto exit;
  385. }
  386. if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE) {
  387. RTW_ERR("request detection range ch:%u, bw:%u, offset:%u\n", ch, bw, offset);
  388. rtw_warn_on(1);
  389. }
  390. if (rtw_chbw_to_freq_range(rfctl->radar_detect_ch, rfctl->radar_detect_bw, rfctl->radar_detect_offset, &cur_hi, &cur_lo) == _FALSE) {
  391. RTW_ERR("cur detection range ch:%u, bw:%u, offset:%u\n", rfctl->radar_detect_ch, rfctl->radar_detect_bw, rfctl->radar_detect_offset);
  392. rtw_warn_on(1);
  393. }
  394. if (hi <= lo || cur_hi <= cur_lo) {
  395. RTW_ERR("hi:%u, lo:%u, cur_hi:%u, cur_lo:%u\n", hi, lo, cur_hi, cur_lo);
  396. rtw_warn_on(1);
  397. }
  398. if (rtw_is_range_a_in_b(hi, lo, cur_hi, cur_lo)) {
  399. /* request is in current detect range */
  400. goto exit;
  401. }
  402. /* check if request channel coverage has new range and the new range is in DFS range */
  403. if (!rtw_is_range_overlap(hi, lo, cur_hi, cur_lo)) {
  404. /* request has no overlap with current */
  405. needed = _TRUE;
  406. } else if (rtw_is_range_a_in_b(cur_hi, cur_lo, hi, lo)) {
  407. /* request is supper set of current */
  408. if ((hi != cur_hi && rtw_is_dfs_range(hi, cur_hi)) || (lo != cur_lo && rtw_is_dfs_range(cur_lo, lo)))
  409. needed = _TRUE;
  410. } else {
  411. /* request is not supper set of current, but has overlap */
  412. if ((lo < cur_lo && rtw_is_dfs_range(cur_lo, lo)) || (hi > cur_hi && rtw_is_dfs_range(hi, cur_hi)))
  413. needed = _TRUE;
  414. }
  415. exit:
  416. return needed;
  417. }
  418. bool _rtw_rfctl_overlap_radar_detect_ch(struct rf_ctl_t *rfctl, u8 ch, u8 bw, u8 offset)
  419. {
  420. bool ret = _FALSE;
  421. u32 hi = 0, lo = 0;
  422. u32 r_hi = 0, r_lo = 0;
  423. int i;
  424. if (rfctl->radar_detect_by_others)
  425. goto exit;
  426. if (rfctl->radar_detect_ch == 0)
  427. goto exit;
  428. if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE) {
  429. rtw_warn_on(1);
  430. goto exit;
  431. }
  432. if (rtw_chbw_to_freq_range(rfctl->radar_detect_ch
  433. , rfctl->radar_detect_bw, rfctl->radar_detect_offset
  434. , &r_hi, &r_lo) == _FALSE) {
  435. rtw_warn_on(1);
  436. goto exit;
  437. }
  438. if (rtw_is_range_overlap(hi, lo, r_hi, r_lo))
  439. ret = _TRUE;
  440. exit:
  441. return ret;
  442. }
  443. bool rtw_rfctl_overlap_radar_detect_ch(struct rf_ctl_t *rfctl)
  444. {
  445. return _rtw_rfctl_overlap_radar_detect_ch(rfctl
  446. , rfctl_to_dvobj(rfctl)->oper_channel
  447. , rfctl_to_dvobj(rfctl)->oper_bwmode
  448. , rfctl_to_dvobj(rfctl)->oper_ch_offset);
  449. }
  450. bool rtw_rfctl_is_tx_blocked_by_ch_waiting(struct rf_ctl_t *rfctl)
  451. {
  452. return rtw_rfctl_overlap_radar_detect_ch(rfctl) && IS_CH_WAITING(rfctl);
  453. }
  454. bool rtw_chset_is_ch_non_ocp(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset)
  455. {
  456. bool ret = _FALSE;
  457. u32 hi = 0, lo = 0;
  458. int i;
  459. if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
  460. goto exit;
  461. for (i = 0; i < MAX_CHANNEL_NUM && ch_set[i].ChannelNum != 0; i++) {
  462. if (!rtw_ch2freq(ch_set[i].ChannelNum)) {
  463. rtw_warn_on(1);
  464. continue;
  465. }
  466. if (!CH_IS_NON_OCP(&ch_set[i]))
  467. continue;
  468. if (lo <= rtw_ch2freq(ch_set[i].ChannelNum)
  469. && rtw_ch2freq(ch_set[i].ChannelNum) <= hi
  470. ) {
  471. ret = _TRUE;
  472. break;
  473. }
  474. }
  475. exit:
  476. return ret;
  477. }
  478. u32 rtw_chset_get_ch_non_ocp_ms(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset)
  479. {
  480. int ms = 0;
  481. u32 current_time;
  482. u32 hi = 0, lo = 0;
  483. int i;
  484. if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
  485. goto exit;
  486. current_time = rtw_get_current_time();
  487. for (i = 0; i < MAX_CHANNEL_NUM && ch_set[i].ChannelNum != 0; i++) {
  488. if (!rtw_ch2freq(ch_set[i].ChannelNum)) {
  489. rtw_warn_on(1);
  490. continue;
  491. }
  492. if (!CH_IS_NON_OCP(&ch_set[i]))
  493. continue;
  494. if (lo <= rtw_ch2freq(ch_set[i].ChannelNum)
  495. && rtw_ch2freq(ch_set[i].ChannelNum) <= hi
  496. ) {
  497. if (rtw_systime_to_ms(ch_set[i].non_ocp_end_time - current_time) > ms)
  498. ms = rtw_systime_to_ms(ch_set[i].non_ocp_end_time - current_time);
  499. }
  500. }
  501. exit:
  502. return ms;
  503. }
  504. /**
  505. * rtw_chset_update_non_ocp - update non_ocp_end_time according to the given @ch, @bw, @offset into @ch_set
  506. * @ch_set: the given channel set
  507. * @ch: channel number on which radar is detected
  508. * @bw: bandwidth on which radar is detected
  509. * @offset: bandwidth offset on which radar is detected
  510. * @ms: ms to add from now to update non_ocp_end_time, ms < 0 means use NON_OCP_TIME_MS
  511. */
  512. static void _rtw_chset_update_non_ocp(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset, int ms)
  513. {
  514. u32 hi = 0, lo = 0;
  515. int i;
  516. if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
  517. goto exit;
  518. for (i = 0; i < MAX_CHANNEL_NUM && ch_set[i].ChannelNum != 0; i++) {
  519. if (!rtw_ch2freq(ch_set[i].ChannelNum)) {
  520. rtw_warn_on(1);
  521. continue;
  522. }
  523. if (lo <= rtw_ch2freq(ch_set[i].ChannelNum)
  524. && rtw_ch2freq(ch_set[i].ChannelNum) <= hi
  525. ) {
  526. if (ms >= 0)
  527. ch_set[i].non_ocp_end_time = rtw_get_current_time() + rtw_ms_to_systime(ms);
  528. else
  529. ch_set[i].non_ocp_end_time = rtw_get_current_time() + rtw_ms_to_systime(NON_OCP_TIME_MS);
  530. }
  531. }
  532. exit:
  533. return;
  534. }
  535. inline void rtw_chset_update_non_ocp(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset)
  536. {
  537. _rtw_chset_update_non_ocp(ch_set, ch, bw, offset, -1);
  538. }
  539. inline void rtw_chset_update_non_ocp_ms(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset, int ms)
  540. {
  541. _rtw_chset_update_non_ocp(ch_set, ch, bw, offset, ms);
  542. }
  543. u32 rtw_get_ch_waiting_ms(_adapter *adapter, u8 ch, u8 bw, u8 offset, u32 *r_non_ocp_ms, u32 *r_cac_ms)
  544. {
  545. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  546. struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
  547. u32 non_ocp_ms;
  548. u32 cac_ms;
  549. u8 in_rd_range = 0; /* if in current radar detection range*/
  550. if (rtw_chset_is_ch_non_ocp(mlmeext->channel_set, ch, bw, offset))
  551. non_ocp_ms = rtw_chset_get_ch_non_ocp_ms(mlmeext->channel_set, ch, bw, offset);
  552. else
  553. non_ocp_ms = 0;
  554. if (rfctl->dfs_master_enabled) {
  555. u32 cur_hi, cur_lo, hi, lo;
  556. if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE) {
  557. RTW_ERR("input range ch:%u, bw:%u, offset:%u\n", ch, bw, offset);
  558. rtw_warn_on(1);
  559. }
  560. if (rtw_chbw_to_freq_range(rfctl->radar_detect_ch, rfctl->radar_detect_bw, rfctl->radar_detect_offset, &cur_hi, &cur_lo) == _FALSE) {
  561. RTW_ERR("cur detection range ch:%u, bw:%u, offset:%u\n", rfctl->radar_detect_ch, rfctl->radar_detect_bw, rfctl->radar_detect_offset);
  562. rtw_warn_on(1);
  563. }
  564. if (rtw_is_range_a_in_b(hi, lo, cur_hi, cur_lo))
  565. in_rd_range = 1;
  566. }
  567. if (!rtw_is_dfs_chbw(ch, bw, offset))
  568. cac_ms = 0;
  569. else if (in_rd_range && !non_ocp_ms) {
  570. if (IS_CH_WAITING(rfctl))
  571. cac_ms = rtw_systime_to_ms(rfctl->cac_end_time - rtw_get_current_time());
  572. else
  573. cac_ms = 0;
  574. } else if (rtw_is_long_cac_ch(ch, bw, offset, rtw_odm_get_dfs_domain(adapter)))
  575. cac_ms = CAC_TIME_CE_MS;
  576. else
  577. cac_ms = CAC_TIME_MS;
  578. if (r_non_ocp_ms)
  579. *r_non_ocp_ms = non_ocp_ms;
  580. if (r_cac_ms)
  581. *r_cac_ms = cac_ms;
  582. return non_ocp_ms + cac_ms;
  583. }
  584. void rtw_reset_cac(_adapter *adapter, u8 ch, u8 bw, u8 offset)
  585. {
  586. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  587. u32 non_ocp_ms;
  588. u32 cac_ms;
  589. rtw_get_ch_waiting_ms(adapter
  590. , ch
  591. , bw
  592. , offset
  593. , &non_ocp_ms
  594. , &cac_ms
  595. );
  596. rfctl->cac_start_time = rtw_get_current_time() + rtw_ms_to_systime(non_ocp_ms);
  597. rfctl->cac_end_time = rfctl->cac_start_time + rtw_ms_to_systime(cac_ms);
  598. /* skip special value */
  599. if (rfctl->cac_start_time == RTW_CAC_STOPPED) {
  600. rfctl->cac_start_time++;
  601. rfctl->cac_end_time++;
  602. }
  603. if (rfctl->cac_end_time == RTW_CAC_STOPPED)
  604. rfctl->cac_end_time++;
  605. }
  606. #endif /* CONFIG_DFS_MASTER */
  607. /* choose channel with shortest waiting (non ocp + cac) time */
  608. bool rtw_choose_shortest_waiting_ch(_adapter *adapter, u8 req_bw, u8 *dec_ch, u8 *dec_bw, u8 *dec_offset, u8 d_flags)
  609. {
  610. #ifndef DBG_CHOOSE_SHORTEST_WAITING_CH
  611. #define DBG_CHOOSE_SHORTEST_WAITING_CH 0
  612. #endif
  613. struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
  614. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  615. struct registry_priv *regsty = adapter_to_regsty(adapter);
  616. u8 ch, bw, offset;
  617. u8 ch_c = 0, bw_c = 0, offset_c = 0;
  618. int i;
  619. u32 min_waiting_ms = 0;
  620. if (!dec_ch || !dec_bw || !dec_offset) {
  621. rtw_warn_on(1);
  622. return _FALSE;
  623. }
  624. /* full search and narrow bw judegement first to avoid potetial judegement timing issue */
  625. for (bw = CHANNEL_WIDTH_20; bw <= req_bw; bw++) {
  626. if (!hal_is_bw_support(adapter, bw))
  627. continue;
  628. for (i = 0; i < mlmeext->max_chan_nums; i++) {
  629. u32 non_ocp_ms = 0;
  630. u32 cac_ms = 0;
  631. u32 waiting_ms = 0;
  632. ch = mlmeext->channel_set[i].ChannelNum;
  633. if ((d_flags & RTW_CHF_2G) && ch <= 14)
  634. continue;
  635. if ((d_flags & RTW_CHF_5G) && ch > 14)
  636. continue;
  637. if (ch > 14) {
  638. if (bw > REGSTY_BW_5G(regsty))
  639. continue;
  640. } else {
  641. if (bw > REGSTY_BW_2G(regsty))
  642. continue;
  643. }
  644. if (!rtw_get_offset_by_chbw(ch, bw, &offset))
  645. continue;
  646. if (!rtw_chset_is_chbw_valid(mlmeext->channel_set, ch, bw, offset))
  647. continue;
  648. if ((d_flags & RTW_CHF_NON_OCP) && rtw_chset_is_ch_non_ocp(mlmeext->channel_set, ch, bw, offset))
  649. continue;
  650. if ((d_flags & RTW_CHF_DFS) && rtw_is_dfs_chbw(ch, bw, offset))
  651. continue;
  652. if ((d_flags & RTW_CHF_LONG_CAC) && rtw_is_long_cac_ch(ch, bw, offset, rtw_odm_get_dfs_domain(adapter)))
  653. continue;
  654. if ((d_flags & RTW_CHF_NON_DFS) && !rtw_is_dfs_chbw(ch, bw, offset))
  655. continue;
  656. if ((d_flags & RTW_CHF_NON_LONG_CAC) && !rtw_is_long_cac_ch(ch, bw, offset, rtw_odm_get_dfs_domain(adapter)))
  657. continue;
  658. #ifdef CONFIG_DFS_MASTER
  659. waiting_ms = rtw_get_ch_waiting_ms(adapter, ch, bw, offset, &non_ocp_ms, &cac_ms);
  660. #endif
  661. if (DBG_CHOOSE_SHORTEST_WAITING_CH)
  662. RTW_INFO(FUNC_ADPT_FMT":%u,%u,%u %u(non_ocp:%u, cac:%u)\n"
  663. , FUNC_ADPT_ARG(adapter), ch, bw, offset, waiting_ms, non_ocp_ms, cac_ms);
  664. if (ch_c == 0
  665. || min_waiting_ms > waiting_ms
  666. || (min_waiting_ms == waiting_ms && bw > bw_c) /* wider bw first */
  667. ) {
  668. ch_c = ch;
  669. bw_c = bw;
  670. offset_c = offset;
  671. min_waiting_ms = waiting_ms;
  672. }
  673. }
  674. }
  675. if (ch_c != 0) {
  676. RTW_INFO(FUNC_ADPT_FMT": d_flags:0x%02x %u,%u,%u waiting_ms:%u\n"
  677. , FUNC_ADPT_ARG(adapter), d_flags, ch_c, bw_c, offset_c, min_waiting_ms);
  678. *dec_ch = ch_c;
  679. *dec_bw = bw_c;
  680. *dec_offset = offset_c;
  681. return _TRUE;
  682. }
  683. if (d_flags == 0)
  684. rtw_warn_on(1);
  685. return _FALSE;
  686. }
  687. void dump_country_chplan(void *sel, const struct country_chplan *ent)
  688. {
  689. _RTW_PRINT_SEL(sel, "\"%c%c\", 0x%02X%s\n"
  690. , ent->alpha2[0], ent->alpha2[1], ent->chplan
  691. , COUNTRY_CHPLAN_EN_11AC(ent) ? " ac" : ""
  692. );
  693. }
  694. void dump_country_chplan_map(void *sel)
  695. {
  696. const struct country_chplan *ent;
  697. u8 code[2];
  698. #if RTW_DEF_MODULE_REGULATORY_CERT
  699. _RTW_PRINT_SEL(sel, "RTW_DEF_MODULE_REGULATORY_CERT:0x%x\n", RTW_DEF_MODULE_REGULATORY_CERT);
  700. #endif
  701. #ifdef CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP
  702. _RTW_PRINT_SEL(sel, "CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP\n");
  703. #endif
  704. for (code[0] = 'A'; code[0] <= 'Z'; code[0]++) {
  705. for (code[1] = 'A'; code[1] <= 'Z'; code[1]++) {
  706. ent = rtw_get_chplan_from_country(code);
  707. if (!ent)
  708. continue;
  709. dump_country_chplan(sel, ent);
  710. }
  711. }
  712. }
  713. void dump_chplan_id_list(void *sel)
  714. {
  715. int i;
  716. for (i = 0; i < RTW_CHPLAN_MAX; i++) {
  717. if (!rtw_is_channel_plan_valid(i))
  718. continue;
  719. _RTW_PRINT_SEL(sel, "0x%02X ", i);
  720. }
  721. RTW_PRINT_SEL(sel, "0x7F\n");
  722. }
  723. void dump_chplan_test(void *sel)
  724. {
  725. int i, j;
  726. /* check invalid channel */
  727. for (i = 0; i < RTW_RD_2G_MAX; i++) {
  728. for (j = 0; j < CH_LIST_LEN(RTW_ChannelPlan2G[i]); j++) {
  729. if (rtw_ch2freq(CH_LIST_CH(RTW_ChannelPlan2G[i], j)) == 0)
  730. RTW_PRINT_SEL(sel, "invalid ch:%u at (%d,%d)\n", CH_LIST_CH(RTW_ChannelPlan2G[i], j), i, j);
  731. }
  732. }
  733. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  734. for (i = 0; i < RTW_RD_5G_MAX; i++) {
  735. for (j = 0; j < CH_LIST_LEN(RTW_ChannelPlan5G[i]); j++) {
  736. if (rtw_ch2freq(CH_LIST_CH(RTW_ChannelPlan5G[i], j)) == 0)
  737. RTW_PRINT_SEL(sel, "invalid ch:%u at (%d,%d)\n", CH_LIST_CH(RTW_ChannelPlan5G[i], j), i, j);
  738. }
  739. }
  740. #endif
  741. }
  742. void dump_chset(void *sel, RT_CHANNEL_INFO *ch_set)
  743. {
  744. u8 i;
  745. for (i = 0; i < MAX_CHANNEL_NUM && ch_set[i].ChannelNum != 0; i++) {
  746. RTW_PRINT_SEL(sel, "ch:%3u, freq:%u, scan_type:%d"
  747. , ch_set[i].ChannelNum, rtw_ch2freq(ch_set[i].ChannelNum), ch_set[i].ScanType);
  748. #ifdef CONFIG_FIND_BEST_CHANNEL
  749. _RTW_PRINT_SEL(sel, ", rx_count:%u", ch_set[i].rx_count);
  750. #endif
  751. #ifdef CONFIG_DFS_MASTER
  752. if (rtw_is_dfs_ch(ch_set[i].ChannelNum)) {
  753. if (CH_IS_NON_OCP(&ch_set[i]))
  754. _RTW_PRINT_SEL(sel, ", non_ocp:%d"
  755. , rtw_systime_to_ms(ch_set[i].non_ocp_end_time - rtw_get_current_time()));
  756. else
  757. _RTW_PRINT_SEL(sel, ", non_ocp:N/A");
  758. }
  759. #endif
  760. _RTW_PRINT_SEL(sel, "\n");
  761. }
  762. RTW_PRINT_SEL(sel, "total ch number:%d\n", i);
  763. }
  764. void dump_cur_chset(void *sel, _adapter *adapter)
  765. {
  766. struct mlme_priv *mlme = &adapter->mlmepriv;
  767. struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
  768. struct registry_priv *regsty = adapter_to_regsty(adapter);
  769. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  770. int i;
  771. if (mlme->country_ent)
  772. dump_country_chplan(sel, mlme->country_ent);
  773. else
  774. RTW_PRINT_SEL(sel, "chplan:0x%02X\n", mlme->ChannelPlan);
  775. RTW_PRINT_SEL(sel, "2G_PLS:%u, 5G_PLS:%u\n"
  776. , hal_data->Regulation2_4G, hal_data->Regulation5G);
  777. #ifdef CONFIG_DFS_MASTER
  778. RTW_PRINT_SEL(sel, "dfs_domain:%u\n", rtw_odm_get_dfs_domain(adapter));
  779. #endif
  780. for (i = 0; i < MAX_CHANNEL_NUM; i++)
  781. if (regsty->excl_chs[i] != 0)
  782. break;
  783. if (i < MAX_CHANNEL_NUM) {
  784. _RTW_PRINT_SEL(sel, "excl_chs:");
  785. for (i = 0; i < MAX_CHANNEL_NUM; i++) {
  786. if (regsty->excl_chs[i] == 0)
  787. break;
  788. _RTW_PRINT_SEL(sel, "%u ", regsty->excl_chs[i]);
  789. }
  790. RTW_PRINT_SEL(sel, "\n");
  791. }
  792. dump_chset(sel, mlmeext->channel_set);
  793. }
  794. /*
  795. * Search the @param ch in given @param ch_set
  796. * @ch_set: the given channel set
  797. * @ch: the given channel number
  798. *
  799. * return the index of channel_num in channel_set, -1 if not found
  800. */
  801. int rtw_chset_search_ch(RT_CHANNEL_INFO *ch_set, const u32 ch)
  802. {
  803. int i;
  804. if (ch == 0)
  805. return -1;
  806. for (i = 0; i < MAX_CHANNEL_NUM && ch_set[i].ChannelNum != 0; i++) {
  807. if (ch == ch_set[i].ChannelNum)
  808. return i;
  809. }
  810. return -1;
  811. }
  812. /*
  813. * Check if the @param ch, bw, offset is valid for the given @param ch_set
  814. * @ch_set: the given channel set
  815. * @ch: the given channel number
  816. * @bw: the given bandwidth
  817. * @offset: the given channel offset
  818. *
  819. * return valid (1) or not (0)
  820. */
  821. u8 rtw_chset_is_chbw_valid(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset)
  822. {
  823. u8 cch;
  824. u8 *op_chs;
  825. u8 op_ch_num;
  826. u8 valid = 0;
  827. int i;
  828. cch = rtw_get_center_ch(ch, bw, offset);
  829. if (!rtw_get_op_chs_by_cch_bw(cch, bw, &op_chs, &op_ch_num))
  830. goto exit;
  831. for (i = 0; i < op_ch_num; i++) {
  832. if (0)
  833. RTW_INFO("%u,%u,%u - cch:%u, bw:%u, op_ch:%u\n", ch, bw, offset, cch, bw, *(op_chs + i));
  834. if (rtw_chset_search_ch(ch_set, *(op_chs + i)) == -1)
  835. break;
  836. }
  837. if (op_ch_num != 0 && i == op_ch_num)
  838. valid = 1;
  839. exit:
  840. return valid;
  841. }
  842. /*
  843. * Check the @param ch is fit with setband setting of @param adapter
  844. * @adapter: the given adapter
  845. * @ch: the given channel number
  846. *
  847. * return _TRUE when check valid, _FALSE not valid
  848. */
  849. bool rtw_mlme_band_check(_adapter *adapter, const u32 ch)
  850. {
  851. if (adapter->setband == WIFI_FREQUENCY_BAND_AUTO /* 2.4G and 5G */
  852. || (adapter->setband == WIFI_FREQUENCY_BAND_2GHZ && ch < 35) /* 2.4G only */
  853. || (adapter->setband == WIFI_FREQUENCY_BAND_5GHZ && ch > 35) /* 5G only */
  854. )
  855. return _TRUE;
  856. return _FALSE;
  857. }
  858. inline void RTW_SET_SCAN_BAND_SKIP(_adapter *padapter, int skip_band)
  859. {
  860. int bs = ATOMIC_READ(&padapter->bandskip);
  861. bs |= skip_band;
  862. ATOMIC_SET(&padapter->bandskip, bs);
  863. }
  864. inline void RTW_CLR_SCAN_BAND_SKIP(_adapter *padapter, int skip_band)
  865. {
  866. int bs = ATOMIC_READ(&padapter->bandskip);
  867. bs &= ~(skip_band);
  868. ATOMIC_SET(&padapter->bandskip, bs);
  869. }
  870. inline int RTW_GET_SCAN_BAND_SKIP(_adapter *padapter)
  871. {
  872. return ATOMIC_READ(&padapter->bandskip);
  873. }
  874. #define RTW_IS_SCAN_BAND_SKIP(padapter, skip_band) (ATOMIC_READ(&padapter->bandskip) & (skip_band))
  875. bool rtw_mlme_ignore_chan(_adapter *adapter, const u32 ch)
  876. {
  877. if (RTW_IS_SCAN_BAND_SKIP(adapter, BAND_24G) && ch < 35) /* SKIP 2.4G Band channel */
  878. return _TRUE;
  879. if (RTW_IS_SCAN_BAND_SKIP(adapter, BAND_5G) && ch > 35) /* SKIP 5G Band channel */
  880. return _TRUE;
  881. return _FALSE;
  882. }
  883. /****************************************************************************
  884. Following are the initialization functions for WiFi MLME
  885. *****************************************************************************/
  886. int init_hw_mlme_ext(_adapter *padapter)
  887. {
  888. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  889. /* set_opmode_cmd(padapter, infra_client_with_mlme); */ /* removed */
  890. set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  891. return _SUCCESS;
  892. }
  893. void init_mlme_default_rate_set(_adapter *padapter)
  894. {
  895. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  896. unsigned char mixed_datarate[NumRates] = {_1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_, _9M_RATE_, _12M_RATE_, _18M_RATE_, _24M_RATE_, _36M_RATE_, _48M_RATE_, _54M_RATE_, 0xff};
  897. unsigned char mixed_basicrate[NumRates] = {_1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_, _12M_RATE_, _24M_RATE_, 0xff,};
  898. unsigned char supported_mcs_set[16] = {0xff, 0xff, 0xff, 0x00, 0x00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
  899. _rtw_memcpy(pmlmeext->datarate, mixed_datarate, NumRates);
  900. _rtw_memcpy(pmlmeext->basicrate, mixed_basicrate, NumRates);
  901. _rtw_memcpy(pmlmeext->default_supported_mcs_set, supported_mcs_set, sizeof(pmlmeext->default_supported_mcs_set));
  902. }
  903. static void init_mlme_ext_priv_value(_adapter *padapter)
  904. {
  905. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  906. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  907. ATOMIC_SET(&pmlmeext->event_seq, 0);
  908. pmlmeext->mgnt_seq = 0;/* reset to zero when disconnect at client mode */
  909. #ifdef CONFIG_IEEE80211W
  910. pmlmeext->sa_query_seq = 0;
  911. pmlmeext->mgnt_80211w_IPN = 0;
  912. pmlmeext->mgnt_80211w_IPN_rx = 0;
  913. #endif /* CONFIG_IEEE80211W */
  914. pmlmeext->cur_channel = padapter->registrypriv.channel;
  915. pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
  916. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  917. pmlmeext->retry = 0;
  918. pmlmeext->cur_wireless_mode = padapter->registrypriv.wireless_mode;
  919. init_mlme_default_rate_set(padapter);
  920. if (pmlmeext->cur_channel > 14)
  921. pmlmeext->tx_rate = IEEE80211_OFDM_RATE_6MB;
  922. else
  923. pmlmeext->tx_rate = IEEE80211_CCK_RATE_1MB;
  924. mlmeext_set_scan_state(pmlmeext, SCAN_DISABLE);
  925. pmlmeext->sitesurvey_res.channel_idx = 0;
  926. pmlmeext->sitesurvey_res.bss_cnt = 0;
  927. pmlmeext->sitesurvey_res.scan_ch_ms = SURVEY_TO;
  928. pmlmeext->sitesurvey_res.rx_ampdu_accept = RX_AMPDU_ACCEPT_INVALID;
  929. pmlmeext->sitesurvey_res.rx_ampdu_size = RX_AMPDU_SIZE_INVALID;
  930. #ifdef CONFIG_SCAN_BACKOP
  931. mlmeext_assign_scan_backop_flags_sta(pmlmeext, /*SS_BACKOP_EN|*/SS_BACKOP_PS_ANNC | SS_BACKOP_TX_RESUME);
  932. mlmeext_assign_scan_backop_flags_ap(pmlmeext, SS_BACKOP_EN | SS_BACKOP_PS_ANNC | SS_BACKOP_TX_RESUME);
  933. pmlmeext->sitesurvey_res.scan_cnt = 0;
  934. pmlmeext->sitesurvey_res.scan_cnt_max = RTW_SCAN_NUM_OF_CH;
  935. pmlmeext->sitesurvey_res.backop_ms = RTW_BACK_OP_CH_MS;
  936. #endif
  937. #if defined(CONFIG_ANTENNA_DIVERSITY) || defined(DBG_SCAN_SW_ANTDIV_BL)
  938. pmlmeext->sitesurvey_res.is_sw_antdiv_bl_scan = 0;
  939. #endif
  940. pmlmeext->scan_abort = _FALSE;
  941. pmlmeinfo->state = WIFI_FW_NULL_STATE;
  942. pmlmeinfo->reauth_count = 0;
  943. pmlmeinfo->reassoc_count = 0;
  944. pmlmeinfo->link_count = 0;
  945. pmlmeinfo->auth_seq = 0;
  946. pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
  947. pmlmeinfo->key_index = 0;
  948. pmlmeinfo->iv = 0;
  949. pmlmeinfo->enc_algo = _NO_PRIVACY_;
  950. pmlmeinfo->authModeToggle = 0;
  951. _rtw_memset(pmlmeinfo->chg_txt, 0, 128);
  952. pmlmeinfo->slotTime = SHORT_SLOT_TIME;
  953. pmlmeinfo->preamble_mode = PREAMBLE_AUTO;
  954. pmlmeinfo->dialogToken = 0;
  955. pmlmeext->action_public_rxseq = 0xffff;
  956. pmlmeext->action_public_dialog_token = 0xff;
  957. }
  958. static void init_channel_list(_adapter *padapter, RT_CHANNEL_INFO *channel_set
  959. , struct p2p_channels *channel_list)
  960. {
  961. struct registry_priv *regsty = adapter_to_regsty(padapter);
  962. struct p2p_oper_class_map op_class[] = {
  963. { IEEE80211G, 81, 1, 13, 1, BW20 },
  964. { IEEE80211G, 82, 14, 14, 1, BW20 },
  965. #if 0 /* Do not enable HT40 on 2 GHz */
  966. { IEEE80211G, 83, 1, 9, 1, BW40PLUS },
  967. { IEEE80211G, 84, 5, 13, 1, BW40MINUS },
  968. #endif
  969. { IEEE80211A, 115, 36, 48, 4, BW20 },
  970. { IEEE80211A, 116, 36, 44, 8, BW40PLUS },
  971. { IEEE80211A, 117, 40, 48, 8, BW40MINUS },
  972. { IEEE80211A, 124, 149, 161, 4, BW20 },
  973. { IEEE80211A, 125, 149, 169, 4, BW20 },
  974. { IEEE80211A, 126, 149, 157, 8, BW40PLUS },
  975. { IEEE80211A, 127, 153, 161, 8, BW40MINUS },
  976. { -1, 0, 0, 0, 0, BW20 }
  977. };
  978. int cla, op;
  979. cla = 0;
  980. for (op = 0; op_class[op].op_class; op++) {
  981. u8 ch;
  982. struct p2p_oper_class_map *o = &op_class[op];
  983. struct p2p_reg_class *reg = NULL;
  984. for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
  985. if (rtw_chset_search_ch(channel_set, ch) == -1)
  986. continue;
  987. if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc))
  988. continue;
  989. if ((REGSTY_IS_BW_5G_SUPPORT(regsty, CHANNEL_WIDTH_40)) &&
  990. ((BW40MINUS == o->bw) || (BW40PLUS == o->bw)))
  991. continue;
  992. if (reg == NULL) {
  993. reg = &channel_list->reg_class[cla];
  994. cla++;
  995. reg->reg_class = o->op_class;
  996. reg->channels = 0;
  997. }
  998. reg->channel[reg->channels] = ch;
  999. reg->channels++;
  1000. }
  1001. }
  1002. channel_list->reg_classes = cla;
  1003. }
  1004. bool rtw_regsty_is_excl_chs(struct registry_priv *regsty, u8 ch)
  1005. {
  1006. int i;
  1007. for (i = 0; i < MAX_CHANNEL_NUM; i++) {
  1008. if (regsty->excl_chs[i] == 0)
  1009. break;
  1010. if (regsty->excl_chs[i] == ch)
  1011. return _TRUE;
  1012. }
  1013. return _FALSE;
  1014. }
  1015. static u8 init_channel_set(_adapter *padapter, u8 ChannelPlan, RT_CHANNEL_INFO *channel_set)
  1016. {
  1017. struct registry_priv *regsty = adapter_to_regsty(padapter);
  1018. u8 index, chanset_size = 0;
  1019. u8 b5GBand = _FALSE, b2_4GBand = _FALSE;
  1020. u8 Index2G = 0, Index5G = 0;
  1021. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(padapter);
  1022. int i;
  1023. if (!rtw_is_channel_plan_valid(ChannelPlan)) {
  1024. RTW_ERR("ChannelPlan ID 0x%02X error !!!!!\n", ChannelPlan);
  1025. return chanset_size;
  1026. }
  1027. _rtw_memset(channel_set, 0, sizeof(RT_CHANNEL_INFO) * MAX_CHANNEL_NUM);
  1028. if (IsSupported24G(regsty->wireless_mode) && hal_chk_band_cap(padapter, BAND_CAP_2G))
  1029. b2_4GBand = _TRUE;
  1030. if (is_supported_5g(regsty->wireless_mode) && hal_chk_band_cap(padapter, BAND_CAP_5G))
  1031. b5GBand = _TRUE;
  1032. if (b2_4GBand == _FALSE && b5GBand == _FALSE) {
  1033. RTW_WARN("HW band_cap has no intersection with SW wireless_mode setting\n");
  1034. return chanset_size;
  1035. }
  1036. if (b2_4GBand) {
  1037. if (RTW_CHPLAN_REALTEK_DEFINE == ChannelPlan)
  1038. Index2G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.Index2G;
  1039. else
  1040. Index2G = RTW_ChannelPlanMap[ChannelPlan].Index2G;
  1041. for (index = 0; index < CH_LIST_LEN(RTW_ChannelPlan2G[Index2G]); index++) {
  1042. if (rtw_regsty_is_excl_chs(regsty, CH_LIST_CH(RTW_ChannelPlan2G[Index2G], index)) == _TRUE)
  1043. continue;
  1044. if (chanset_size >= MAX_CHANNEL_NUM) {
  1045. RTW_WARN("chset size can't exceed MAX_CHANNEL_NUM(%u)\n", MAX_CHANNEL_NUM);
  1046. break;
  1047. }
  1048. channel_set[chanset_size].ChannelNum = CH_LIST_CH(RTW_ChannelPlan2G[Index2G], index);
  1049. if (RTW_CHPLAN_GLOBAL_DOAMIN == ChannelPlan
  1050. || RTW_CHPLAN_GLOBAL_NULL == ChannelPlan
  1051. ) {
  1052. /* Channel 1~11 is active, and 12~14 is passive */
  1053. if (channel_set[chanset_size].ChannelNum >= 1 && channel_set[chanset_size].ChannelNum <= 11)
  1054. channel_set[chanset_size].ScanType = SCAN_ACTIVE;
  1055. else if ((channel_set[chanset_size].ChannelNum >= 12 && channel_set[chanset_size].ChannelNum <= 14))
  1056. channel_set[chanset_size].ScanType = SCAN_PASSIVE;
  1057. } else if (RTW_CHPLAN_WORLD_WIDE_13 == ChannelPlan
  1058. || RTW_CHPLAN_WORLD_WIDE_5G == ChannelPlan
  1059. || RTW_RD_2G_WORLD == Index2G
  1060. ) {
  1061. /* channel 12~13, passive scan */
  1062. if (channel_set[chanset_size].ChannelNum <= 11)
  1063. channel_set[chanset_size].ScanType = SCAN_ACTIVE;
  1064. else
  1065. channel_set[chanset_size].ScanType = SCAN_PASSIVE;
  1066. } else
  1067. channel_set[chanset_size].ScanType = SCAN_ACTIVE;
  1068. chanset_size++;
  1069. }
  1070. }
  1071. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  1072. if (b5GBand) {
  1073. if (RTW_CHPLAN_REALTEK_DEFINE == ChannelPlan)
  1074. Index5G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.Index5G;
  1075. else
  1076. Index5G = RTW_ChannelPlanMap[ChannelPlan].Index5G;
  1077. for (index = 0; index < CH_LIST_LEN(RTW_ChannelPlan5G[Index5G]); index++) {
  1078. if (rtw_regsty_is_excl_chs(regsty, CH_LIST_CH(RTW_ChannelPlan5G[Index5G], index)) == _TRUE)
  1079. continue;
  1080. #ifndef CONFIG_DFS
  1081. if (rtw_is_dfs_ch(CH_LIST_CH(RTW_ChannelPlan5G[Index5G], index)))
  1082. continue;
  1083. #endif
  1084. if (chanset_size >= MAX_CHANNEL_NUM) {
  1085. RTW_WARN("chset size can't exceed MAX_CHANNEL_NUM(%u)\n", MAX_CHANNEL_NUM);
  1086. break;
  1087. }
  1088. channel_set[chanset_size].ChannelNum = CH_LIST_CH(RTW_ChannelPlan5G[Index5G], index);
  1089. if ((ChannelPlan == RTW_CHPLAN_WORLD_WIDE_5G) /* all channels passive */
  1090. || (rtw_is_5g_band1(channel_set[chanset_size].ChannelNum)
  1091. && rtw_rd_5g_band1_passive(Index5G)) /* band1 passive */
  1092. || (rtw_is_5g_band4(channel_set[chanset_size].ChannelNum)
  1093. && rtw_rd_5g_band4_passive(Index5G)) /* band4 passive */
  1094. || (rtw_is_dfs_ch(channel_set[chanset_size].ChannelNum)) /* DFS channel(band2, 3) passive */
  1095. )
  1096. channel_set[chanset_size].ScanType = SCAN_PASSIVE;
  1097. else
  1098. channel_set[chanset_size].ScanType = SCAN_ACTIVE;
  1099. chanset_size++;
  1100. }
  1101. }
  1102. #ifdef CONFIG_DFS_MASTER
  1103. for (i = 0; i < chanset_size; i++)
  1104. channel_set[i].non_ocp_end_time = rtw_get_current_time();
  1105. #endif
  1106. #endif /* CONFIG_IEEE80211_BAND_5GHZ */
  1107. if (RTW_CHPLAN_REALTEK_DEFINE == ChannelPlan) {
  1108. hal_data->Regulation2_4G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.regd;
  1109. hal_data->Regulation5G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.regd;
  1110. } else {
  1111. hal_data->Regulation2_4G = RTW_ChannelPlanMap[ChannelPlan].regd;
  1112. hal_data->Regulation5G = RTW_ChannelPlanMap[ChannelPlan].regd;
  1113. }
  1114. if (chanset_size)
  1115. RTW_INFO(FUNC_ADPT_FMT" ChannelPlan ID:0x%02x, ch num:%d\n"
  1116. , FUNC_ADPT_ARG(padapter), ChannelPlan, chanset_size);
  1117. else
  1118. RTW_WARN(FUNC_ADPT_FMT" ChannelPlan ID:0x%02x, final chset has no channel\n"
  1119. , FUNC_ADPT_ARG(padapter), ChannelPlan);
  1120. return chanset_size;
  1121. }
  1122. void init_mlme_ext_timer(_adapter *padapter)
  1123. {
  1124. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1125. rtw_init_timer(&pmlmeext->survey_timer, padapter, survey_timer_hdl);
  1126. rtw_init_timer(&pmlmeext->link_timer, padapter, link_timer_hdl);
  1127. #ifdef CONFIG_RTW_80211R
  1128. rtw_init_timer(&pmlmeext->ft_link_timer, padapter, ft_link_timer_hdl, padapter);
  1129. rtw_init_timer(&pmlmeext->ft_roam_timer, padapter, ft_roam_timer_hdl, padapter);
  1130. #endif
  1131. }
  1132. int init_mlme_ext_priv(_adapter *padapter)
  1133. {
  1134. int res = _SUCCESS;
  1135. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1136. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1137. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1138. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1139. /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */
  1140. /* _rtw_memset((u8 *)pmlmeext, 0, sizeof(struct mlme_ext_priv)); */
  1141. pmlmeext->padapter = padapter;
  1142. /* fill_fwpriv(padapter, &(pmlmeext->fwpriv)); */
  1143. init_mlme_ext_priv_value(padapter);
  1144. pmlmeinfo->bAcceptAddbaReq = pregistrypriv->bAcceptAddbaReq;
  1145. init_mlme_ext_timer(padapter);
  1146. #ifdef CONFIG_AP_MODE
  1147. init_mlme_ap_info(padapter);
  1148. #endif
  1149. pmlmeext->max_chan_nums = init_channel_set(padapter, pmlmepriv->ChannelPlan, pmlmeext->channel_set);
  1150. init_channel_list(padapter, pmlmeext->channel_set, &pmlmeext->channel_list);
  1151. pmlmeext->last_scan_time = 0;
  1152. pmlmeext->mlmeext_init = _TRUE;
  1153. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  1154. pmlmeext->active_keep_alive_check = _TRUE;
  1155. #else
  1156. pmlmeext->active_keep_alive_check = _FALSE;
  1157. #endif
  1158. #ifdef DBG_FIXED_CHAN
  1159. pmlmeext->fixed_chan = 0xFF;
  1160. #endif
  1161. return res;
  1162. }
  1163. void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext)
  1164. {
  1165. _adapter *padapter = pmlmeext->padapter;
  1166. if (!padapter)
  1167. return;
  1168. if (rtw_is_drv_stopped(padapter)) {
  1169. _cancel_timer_ex(&pmlmeext->survey_timer);
  1170. _cancel_timer_ex(&pmlmeext->link_timer);
  1171. }
  1172. }
  1173. static u8 cmp_pkt_chnl_diff(_adapter *padapter, u8 *pframe, uint packet_len)
  1174. {
  1175. /* if the channel is same, return 0. else return channel differential */
  1176. uint len;
  1177. u8 channel;
  1178. u8 *p;
  1179. p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _BEACON_IE_OFFSET_, _DSSET_IE_, &len, packet_len - _BEACON_IE_OFFSET_);
  1180. if (p) {
  1181. channel = *(p + 2);
  1182. if (padapter->mlmeextpriv.cur_channel >= channel)
  1183. return padapter->mlmeextpriv.cur_channel - channel;
  1184. else
  1185. return channel - padapter->mlmeextpriv.cur_channel;
  1186. } else
  1187. return 0;
  1188. }
  1189. static void _mgt_dispatcher(_adapter *padapter, struct mlme_handler *ptable, union recv_frame *precv_frame)
  1190. {
  1191. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  1192. u8 *pframe = precv_frame->u.hdr.rx_data;
  1193. if (ptable->func) {
  1194. /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
  1195. if (!_rtw_memcmp(GetAddr1Ptr(pframe), adapter_mac_addr(padapter), ETH_ALEN) &&
  1196. !_rtw_memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
  1197. return;
  1198. ptable->func(padapter, precv_frame);
  1199. }
  1200. }
  1201. void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame)
  1202. {
  1203. int index;
  1204. struct mlme_handler *ptable;
  1205. #ifdef CONFIG_AP_MODE
  1206. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1207. #endif /* CONFIG_AP_MODE */
  1208. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  1209. u8 *pframe = precv_frame->u.hdr.rx_data;
  1210. struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, get_addr2_ptr(pframe));
  1211. struct dvobj_priv *psdpriv = padapter->dvobj;
  1212. struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
  1213. #if 0
  1214. {
  1215. u8 *pbuf;
  1216. pbuf = GetAddr1Ptr(pframe);
  1217. RTW_INFO("A1-%x:%x:%x:%x:%x:%x\n", *pbuf, *(pbuf + 1), *(pbuf + 2), *(pbuf + 3), *(pbuf + 4), *(pbuf + 5));
  1218. pbuf = get_addr2_ptr(pframe);
  1219. RTW_INFO("A2-%x:%x:%x:%x:%x:%x\n", *pbuf, *(pbuf + 1), *(pbuf + 2), *(pbuf + 3), *(pbuf + 4), *(pbuf + 5));
  1220. pbuf = GetAddr3Ptr(pframe);
  1221. RTW_INFO("A3-%x:%x:%x:%x:%x:%x\n", *pbuf, *(pbuf + 1), *(pbuf + 2), *(pbuf + 3), *(pbuf + 4), *(pbuf + 5));
  1222. }
  1223. #endif
  1224. if (GetFrameType(pframe) != WIFI_MGT_TYPE) {
  1225. return;
  1226. }
  1227. /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
  1228. if (!_rtw_memcmp(GetAddr1Ptr(pframe), adapter_mac_addr(padapter), ETH_ALEN) &&
  1229. !_rtw_memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
  1230. return;
  1231. ptable = mlme_sta_tbl;
  1232. index = get_frame_sub_type(pframe) >> 4;
  1233. #ifdef CONFIG_TDLS
  1234. if ((index << 4) == WIFI_ACTION) {
  1235. /* category==public (4), action==TDLS_DISCOVERY_RESPONSE */
  1236. if (*(pframe + 24) == RTW_WLAN_CATEGORY_PUBLIC && *(pframe + 25) == TDLS_DISCOVERY_RESPONSE) {
  1237. RTW_INFO("[TDLS] Recv %s from "MAC_FMT"\n", rtw_tdls_action_txt(TDLS_DISCOVERY_RESPONSE), MAC_ARG(get_addr2_ptr(pframe)));
  1238. On_TDLS_Dis_Rsp(padapter, precv_frame);
  1239. }
  1240. }
  1241. #endif /* CONFIG_TDLS */
  1242. if (index >= (sizeof(mlme_sta_tbl) / sizeof(struct mlme_handler))) {
  1243. return;
  1244. }
  1245. ptable += index;
  1246. #if 1
  1247. if (psta != NULL) {
  1248. if (GetRetry(pframe)) {
  1249. if (precv_frame->u.hdr.attrib.seq_num == psta->RxMgmtFrameSeqNum) {
  1250. /* drop the duplicate management frame */
  1251. pdbgpriv->dbg_rx_dup_mgt_frame_drop_count++;
  1252. RTW_INFO("Drop duplicate management frame with seq_num = %d.\n", precv_frame->u.hdr.attrib.seq_num);
  1253. return;
  1254. }
  1255. }
  1256. psta->RxMgmtFrameSeqNum = precv_frame->u.hdr.attrib.seq_num;
  1257. }
  1258. #else
  1259. if (GetRetry(pframe)) {
  1260. /* return; */
  1261. }
  1262. #endif
  1263. #ifdef CONFIG_AP_MODE
  1264. switch (get_frame_sub_type(pframe)) {
  1265. case WIFI_AUTH:
  1266. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1267. ptable->func = &OnAuth;
  1268. else
  1269. ptable->func = &OnAuthClient;
  1270. /* pass through */
  1271. case WIFI_ASSOCREQ:
  1272. case WIFI_REASSOCREQ:
  1273. _mgt_dispatcher(padapter, ptable, precv_frame);
  1274. #ifdef CONFIG_HOSTAPD_MLME
  1275. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1276. rtw_hostapd_mlme_rx(padapter, precv_frame);
  1277. #endif
  1278. break;
  1279. case WIFI_PROBEREQ:
  1280. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
  1281. #ifdef CONFIG_HOSTAPD_MLME
  1282. rtw_hostapd_mlme_rx(padapter, precv_frame);
  1283. #else
  1284. _mgt_dispatcher(padapter, ptable, precv_frame);
  1285. #endif
  1286. } else
  1287. _mgt_dispatcher(padapter, ptable, precv_frame);
  1288. break;
  1289. case WIFI_BEACON:
  1290. _mgt_dispatcher(padapter, ptable, precv_frame);
  1291. break;
  1292. case WIFI_ACTION:
  1293. /* if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) */
  1294. _mgt_dispatcher(padapter, ptable, precv_frame);
  1295. break;
  1296. default:
  1297. _mgt_dispatcher(padapter, ptable, precv_frame);
  1298. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1299. rtw_hostapd_mlme_rx(padapter, precv_frame);
  1300. break;
  1301. }
  1302. #else
  1303. _mgt_dispatcher(padapter, ptable, precv_frame);
  1304. #endif
  1305. }
  1306. #ifdef CONFIG_P2P
  1307. u32 p2p_listen_state_process(_adapter *padapter, unsigned char *da)
  1308. {
  1309. bool response = _TRUE;
  1310. #ifdef CONFIG_IOCTL_CFG80211
  1311. if (padapter->wdinfo.driver_interface == DRIVER_CFG80211) {
  1312. if (rtw_cfg80211_get_is_roch(padapter) == _FALSE
  1313. || rtw_get_oper_ch(padapter) != padapter->wdinfo.listen_channel
  1314. || adapter_wdev_data(padapter)->p2p_enabled == _FALSE
  1315. || padapter->mlmepriv.wps_probe_resp_ie == NULL
  1316. || padapter->mlmepriv.p2p_probe_resp_ie == NULL
  1317. ) {
  1318. #ifdef CONFIG_DEBUG_CFG80211
  1319. RTW_INFO(ADPT_FMT" DON'T issue_probersp_p2p: p2p_enabled:%d, wps_probe_resp_ie:%p, p2p_probe_resp_ie:%p\n"
  1320. , ADPT_ARG(padapter)
  1321. , adapter_wdev_data(padapter)->p2p_enabled
  1322. , padapter->mlmepriv.wps_probe_resp_ie
  1323. , padapter->mlmepriv.p2p_probe_resp_ie);
  1324. RTW_INFO(ADPT_FMT" DON'T issue_probersp_p2p: is_ro_ch:%d, op_ch:%d, p2p_listen_channel:%d\n"
  1325. , ADPT_ARG(padapter)
  1326. , rtw_cfg80211_get_is_roch(padapter)
  1327. , rtw_get_oper_ch(padapter)
  1328. , padapter->wdinfo.listen_channel);
  1329. #endif
  1330. response = _FALSE;
  1331. }
  1332. } else
  1333. #endif /* CONFIG_IOCTL_CFG80211 */
  1334. if (padapter->wdinfo.driver_interface == DRIVER_WEXT) {
  1335. /* do nothing if the device name is empty */
  1336. if (!padapter->wdinfo.device_name_len)
  1337. response = _FALSE;
  1338. }
  1339. if (response == _TRUE)
  1340. issue_probersp_p2p(padapter, da);
  1341. return _SUCCESS;
  1342. }
  1343. #endif /* CONFIG_P2P */
  1344. /****************************************************************************
  1345. Following are the callback functions for each subtype of the management frames
  1346. *****************************************************************************/
  1347. unsigned int OnProbeReq(_adapter *padapter, union recv_frame *precv_frame)
  1348. {
  1349. unsigned int ielen;
  1350. unsigned char *p;
  1351. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1352. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1353. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1354. WLAN_BSSID_EX *cur = &(pmlmeinfo->network);
  1355. u8 *pframe = precv_frame->u.hdr.rx_data;
  1356. uint len = precv_frame->u.hdr.len;
  1357. u8 is_valid_p2p_probereq = _FALSE;
  1358. #ifdef CONFIG_ATMEL_RC_PATCH
  1359. u8 *target_ie = NULL, *wps_ie = NULL;
  1360. u8 *start;
  1361. uint search_len = 0, wps_ielen = 0, target_ielen = 0;
  1362. struct sta_info *psta;
  1363. struct sta_priv *pstapriv = &padapter->stapriv;
  1364. #endif
  1365. #ifdef CONFIG_P2P
  1366. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  1367. struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
  1368. u8 wifi_test_chk_rate = 1;
  1369. #ifdef CONFIG_IOCTL_CFG80211
  1370. if ((pwdinfo->driver_interface == DRIVER_CFG80211)
  1371. && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)
  1372. && (GET_CFG80211_REPORT_MGMT(adapter_wdev_data(padapter), IEEE80211_STYPE_PROBE_REQ) == _TRUE)
  1373. ) {
  1374. rtw_cfg80211_rx_probe_request(padapter, precv_frame);
  1375. return _SUCCESS;
  1376. }
  1377. #endif /* CONFIG_IOCTL_CFG80211 */
  1378. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) &&
  1379. !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE) &&
  1380. !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) &&
  1381. !rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH) &&
  1382. !rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN)
  1383. ) {
  1384. /* Commented by Albert 2011/03/17 */
  1385. /* mcs_rate = 0->CCK 1M rate */
  1386. /* mcs_rate = 1->CCK 2M rate */
  1387. /* mcs_rate = 2->CCK 5.5M rate */
  1388. /* mcs_rate = 3->CCK 11M rate */
  1389. /* In the P2P mode, the driver should not support the CCK rate */
  1390. /* Commented by Kurt 2012/10/16 */
  1391. /* IOT issue: Google Nexus7 use 1M rate to send p2p_probe_req after GO nego completed and Nexus7 is client */
  1392. if (padapter->registrypriv.wifi_spec == 1) {
  1393. if (pattrib->data_rate <= 3)
  1394. wifi_test_chk_rate = 0;
  1395. }
  1396. if (wifi_test_chk_rate == 1) {
  1397. is_valid_p2p_probereq = process_probe_req_p2p_ie(pwdinfo, pframe, len);
  1398. if (is_valid_p2p_probereq == _TRUE) {
  1399. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE)) {
  1400. /* FIXME */
  1401. if (padapter->wdinfo.driver_interface == DRIVER_WEXT)
  1402. report_survey_event(padapter, precv_frame);
  1403. p2p_listen_state_process(padapter, get_sa(pframe));
  1404. return _SUCCESS;
  1405. }
  1406. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
  1407. goto _continue;
  1408. }
  1409. }
  1410. }
  1411. _continue:
  1412. #endif /* CONFIG_P2P */
  1413. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
  1414. return _SUCCESS;
  1415. if (check_fwstate(pmlmepriv, _FW_LINKED) == _FALSE &&
  1416. check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE | WIFI_AP_STATE) == _FALSE)
  1417. return _SUCCESS;
  1418. /* RTW_INFO("+OnProbeReq\n"); */
  1419. #ifdef CONFIG_ATMEL_RC_PATCH
  1420. wps_ie = rtw_get_wps_ie(
  1421. pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_,
  1422. len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_,
  1423. NULL, &wps_ielen);
  1424. if (wps_ie)
  1425. target_ie = rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_MANUFACTURER, NULL, &target_ielen);
  1426. if ((target_ie && (target_ielen == 4)) && (_TRUE == _rtw_memcmp((void *)target_ie, "Ozmo", 4))) {
  1427. /* psta->flag_atmel_rc = 1; */
  1428. unsigned char *sa_addr = get_sa(pframe);
  1429. printk("%s: Find Ozmo RC -- %02x:%02x:%02x:%02x:%02x:%02x \n\n",
  1430. __func__, *sa_addr, *(sa_addr + 1), *(sa_addr + 2), *(sa_addr + 3), *(sa_addr + 4), *(sa_addr + 5));
  1431. _rtw_memcpy(pstapriv->atmel_rc_pattern, get_sa(pframe), ETH_ALEN);
  1432. }
  1433. #endif
  1434. #ifdef CONFIG_AUTO_AP_MODE
  1435. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE &&
  1436. pmlmepriv->cur_network.join_res == _TRUE) {
  1437. _irqL irqL;
  1438. struct sta_info *psta;
  1439. u8 *mac_addr, *peer_addr;
  1440. struct sta_priv *pstapriv = &padapter->stapriv;
  1441. u8 RC_OUI[4] = {0x00, 0xE0, 0x4C, 0x0A};
  1442. /* EID[1] + EID_LEN[1] + RC_OUI[4] + MAC[6] + PairingID[2] + ChannelNum[2] */
  1443. p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, (int *)&ielen,
  1444. len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
  1445. if (!p || ielen != 14)
  1446. goto _non_rc_device;
  1447. if (!_rtw_memcmp(p + 2, RC_OUI, sizeof(RC_OUI)))
  1448. goto _non_rc_device;
  1449. if (!_rtw_memcmp(p + 6, get_sa(pframe), ETH_ALEN)) {
  1450. RTW_INFO("%s, do rc pairing ("MAC_FMT"), but mac addr mismatch!("MAC_FMT")\n", __FUNCTION__,
  1451. MAC_ARG(get_sa(pframe)), MAC_ARG(p + 6));
  1452. goto _non_rc_device;
  1453. }
  1454. RTW_INFO("%s, got the pairing device("MAC_FMT")\n", __FUNCTION__, MAC_ARG(get_sa(pframe)));
  1455. /* new a station */
  1456. psta = rtw_get_stainfo(pstapriv, get_sa(pframe));
  1457. if (psta == NULL) {
  1458. /* allocate a new one */
  1459. RTW_INFO("going to alloc stainfo for rc="MAC_FMT"\n", MAC_ARG(get_sa(pframe)));
  1460. psta = rtw_alloc_stainfo(pstapriv, get_sa(pframe));
  1461. if (psta == NULL) {
  1462. /* TODO: */
  1463. RTW_INFO(" Exceed the upper limit of supported clients...\n");
  1464. return _SUCCESS;
  1465. }
  1466. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  1467. if (rtw_is_list_empty(&psta->asoc_list)) {
  1468. psta->expire_to = pstapriv->expire_to;
  1469. rtw_list_insert_tail(&psta->asoc_list, &pstapriv->asoc_list);
  1470. pstapriv->asoc_list_cnt++;
  1471. }
  1472. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  1473. /* generate pairing ID */
  1474. mac_addr = adapter_mac_addr(padapter);
  1475. peer_addr = psta->hwaddr;
  1476. psta->pid = (u16)(((mac_addr[4] << 8) + mac_addr[5]) + ((peer_addr[4] << 8) + peer_addr[5]));
  1477. /* update peer stainfo */
  1478. psta->isrc = _TRUE;
  1479. /* get a unique AID */
  1480. if (psta->aid > 0)
  1481. RTW_INFO("old AID %d\n", psta->aid);
  1482. else {
  1483. for (psta->aid = 1; psta->aid <= NUM_STA; psta->aid++)
  1484. if (pstapriv->sta_aid[psta->aid - 1] == NULL)
  1485. break;
  1486. if (psta->aid > pstapriv->max_num_sta) {
  1487. psta->aid = 0;
  1488. RTW_INFO("no room for more AIDs\n");
  1489. return _SUCCESS;
  1490. } else {
  1491. pstapriv->sta_aid[psta->aid - 1] = psta;
  1492. RTW_INFO("allocate new AID = (%d)\n", psta->aid);
  1493. }
  1494. }
  1495. psta->qos_option = 1;
  1496. psta->bw_mode = CHANNEL_WIDTH_20;
  1497. psta->ieee8021x_blocked = _FALSE;
  1498. #ifdef CONFIG_80211N_HT
  1499. psta->htpriv.ht_option = _TRUE;
  1500. psta->htpriv.ampdu_enable = _FALSE;
  1501. psta->htpriv.sgi_20m = _FALSE;
  1502. psta->htpriv.sgi_40m = _FALSE;
  1503. psta->htpriv.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1504. psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
  1505. psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
  1506. #endif
  1507. rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _TRUE);
  1508. _rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
  1509. _enter_critical_bh(&psta->lock, &irqL);
  1510. psta->state |= _FW_LINKED;
  1511. _exit_critical_bh(&psta->lock, &irqL);
  1512. report_add_sta_event(padapter, psta->hwaddr);
  1513. }
  1514. issue_probersp(padapter, get_sa(pframe), _FALSE);
  1515. return _SUCCESS;
  1516. }
  1517. _non_rc_device:
  1518. return _SUCCESS;
  1519. #endif /* CONFIG_AUTO_AP_MODE */
  1520. #ifdef CONFIG_CONCURRENT_MODE
  1521. if (((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) &&
  1522. rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_LINKING | _FW_UNDER_SURVEY)) {
  1523. /* don't process probe req */
  1524. return _SUCCESS;
  1525. }
  1526. #endif
  1527. p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _SSID_IE_, (int *)&ielen,
  1528. len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
  1529. /* check (wildcard) SSID */
  1530. if (p != NULL) {
  1531. if (is_valid_p2p_probereq == _TRUE)
  1532. goto _issue_probersp;
  1533. if ((ielen != 0 && _FALSE == _rtw_memcmp((void *)(p + 2), (void *)cur->Ssid.Ssid, cur->Ssid.SsidLength))
  1534. || (ielen == 0 && pmlmeinfo->hidden_ssid_mode)
  1535. )
  1536. return _SUCCESS;
  1537. _issue_probersp:
  1538. if (((check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE &&
  1539. pmlmepriv->cur_network.join_res == _TRUE)) || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
  1540. /* RTW_INFO("+issue_probersp during ap mode\n"); */
  1541. issue_probersp(padapter, get_sa(pframe), is_valid_p2p_probereq);
  1542. }
  1543. }
  1544. return _SUCCESS;
  1545. }
  1546. unsigned int OnProbeRsp(_adapter *padapter, union recv_frame *precv_frame)
  1547. {
  1548. struct sta_info *psta;
  1549. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1550. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1551. struct sta_priv *pstapriv = &padapter->stapriv;
  1552. u8 *pframe = precv_frame->u.hdr.rx_data;
  1553. #ifdef CONFIG_P2P
  1554. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  1555. #endif
  1556. #ifdef CONFIG_P2P
  1557. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ)) {
  1558. if (_TRUE == pwdinfo->tx_prov_disc_info.benable) {
  1559. if (_rtw_memcmp(pwdinfo->tx_prov_disc_info.peerIFAddr, get_addr2_ptr(pframe), ETH_ALEN)) {
  1560. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
  1561. pwdinfo->tx_prov_disc_info.benable = _FALSE;
  1562. issue_p2p_provision_request(padapter,
  1563. pwdinfo->tx_prov_disc_info.ssid.Ssid,
  1564. pwdinfo->tx_prov_disc_info.ssid.SsidLength,
  1565. pwdinfo->tx_prov_disc_info.peerDevAddr);
  1566. } else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  1567. pwdinfo->tx_prov_disc_info.benable = _FALSE;
  1568. issue_p2p_provision_request(padapter,
  1569. NULL,
  1570. 0,
  1571. pwdinfo->tx_prov_disc_info.peerDevAddr);
  1572. }
  1573. }
  1574. }
  1575. return _SUCCESS;
  1576. } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING)) {
  1577. if (_TRUE == pwdinfo->nego_req_info.benable) {
  1578. RTW_INFO("[%s] P2P State is GONEGO ING!\n", __FUNCTION__);
  1579. if (_rtw_memcmp(pwdinfo->nego_req_info.peerDevAddr, get_addr2_ptr(pframe), ETH_ALEN)) {
  1580. pwdinfo->nego_req_info.benable = _FALSE;
  1581. issue_p2p_GO_request(padapter, pwdinfo->nego_req_info.peerDevAddr);
  1582. }
  1583. }
  1584. } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_INVITE_REQ)) {
  1585. if (_TRUE == pwdinfo->invitereq_info.benable) {
  1586. RTW_INFO("[%s] P2P_STATE_TX_INVITE_REQ!\n", __FUNCTION__);
  1587. if (_rtw_memcmp(pwdinfo->invitereq_info.peer_macaddr, get_addr2_ptr(pframe), ETH_ALEN)) {
  1588. pwdinfo->invitereq_info.benable = _FALSE;
  1589. issue_p2p_invitation_request(padapter, pwdinfo->invitereq_info.peer_macaddr);
  1590. }
  1591. }
  1592. }
  1593. #endif
  1594. if (mlmeext_chk_scan_state(pmlmeext, SCAN_PROCESS)) {
  1595. rtw_mi_report_survey_event(padapter, precv_frame);
  1596. return _SUCCESS;
  1597. }
  1598. #if 0 /* move to validate_recv_mgnt_frame */
  1599. if (_rtw_memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) {
  1600. if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
  1601. psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  1602. if (psta != NULL)
  1603. psta->sta_stats.rx_mgnt_pkts++;
  1604. }
  1605. }
  1606. #endif
  1607. return _SUCCESS;
  1608. }
  1609. /* for 11n Logo 4.2.31/4.2.32 */
  1610. static void rtw_check_legacy_ap(_adapter *padapter, u8 *pframe, u32 len)
  1611. {
  1612. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1613. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1614. if (!padapter->registrypriv.wifi_spec)
  1615. return;
  1616. if(!MLME_IS_AP(padapter))
  1617. return;
  1618. if (pmlmeext->bstart_bss == _TRUE) {
  1619. int left;
  1620. u16 capability;
  1621. unsigned char *pos;
  1622. struct rtw_ieee802_11_elems elems;
  1623. struct HT_info_element *pht_info = NULL;
  1624. u16 cur_op_mode;
  1625. /* checking IEs */
  1626. left = len - sizeof(struct rtw_ieee80211_hdr_3addr) - _BEACON_IE_OFFSET_;
  1627. pos = pframe + sizeof(struct rtw_ieee80211_hdr_3addr) + _BEACON_IE_OFFSET_;
  1628. if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed) {
  1629. RTW_INFO("%s: parse fail for "MAC_FMT"\n", __func__, MAC_ARG(GetAddr3Ptr(pframe)));
  1630. return;
  1631. }
  1632. cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  1633. /* for legacy ap */
  1634. if (elems.ht_capabilities == NULL && elems.ht_capabilities_len == 0) {
  1635. if (0)
  1636. RTW_INFO("%s: "MAC_FMT" is legacy ap\n", __func__, MAC_ARG(GetAddr3Ptr(pframe)));
  1637. ATOMIC_SET(&pmlmepriv->olbc, _TRUE);
  1638. ATOMIC_SET(&pmlmepriv->olbc_ht, _TRUE);
  1639. }
  1640. }
  1641. }
  1642. unsigned int OnBeacon(_adapter *padapter, union recv_frame *precv_frame)
  1643. {
  1644. struct sta_info *psta;
  1645. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1646. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1647. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1648. struct sta_priv *pstapriv = &padapter->stapriv;
  1649. u8 *pframe = precv_frame->u.hdr.rx_data;
  1650. uint len = precv_frame->u.hdr.len;
  1651. WLAN_BSSID_EX *pbss;
  1652. int ret = _SUCCESS;
  1653. u8 *p = NULL;
  1654. u32 ielen = 0;
  1655. #ifdef CONFIG_TDLS
  1656. struct sta_info *ptdls_sta;
  1657. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  1658. #ifdef CONFIG_TDLS_CH_SW
  1659. struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
  1660. #endif
  1661. #endif /* CONFIG_TDLS */
  1662. if (validate_beacon_len(pframe, len) == _FALSE)
  1663. return _SUCCESS;
  1664. #ifdef CONFIG_ATTEMPT_TO_FIX_AP_BEACON_ERROR
  1665. p = rtw_get_ie(pframe + sizeof(struct rtw_ieee80211_hdr_3addr) + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ielen,
  1666. precv_frame->u.hdr.len - sizeof(struct rtw_ieee80211_hdr_3addr) - _BEACON_IE_OFFSET_);
  1667. if ((p != NULL) && (ielen > 0)) {
  1668. if ((*(p + 1 + ielen) == 0x2D) && (*(p + 2 + ielen) != 0x2D)) {
  1669. /* Invalid value 0x2D is detected in Extended Supported Rates (ESR) IE. Try to fix the IE length to avoid failed Beacon parsing. */
  1670. RTW_INFO("[WIFIDBG] Error in ESR IE is detected in Beacon of BSSID:"MAC_FMT". Fix the length of ESR IE to avoid failed Beacon parsing.\n", MAC_ARG(GetAddr3Ptr(pframe)));
  1671. *(p + 1) = ielen - 1;
  1672. }
  1673. }
  1674. #endif
  1675. if (mlmeext_chk_scan_state(pmlmeext, SCAN_PROCESS)) {
  1676. rtw_mi_report_survey_event(padapter, precv_frame);
  1677. return _SUCCESS;
  1678. }
  1679. rtw_check_legacy_ap(padapter, pframe, len);
  1680. if (_rtw_memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) {
  1681. if ((pmlmeinfo->state & WIFI_FW_AUTH_NULL)
  1682. && rtw_sta_linking_test_wait_done()
  1683. ) {
  1684. if (rtw_sta_linking_test_force_fail()) {
  1685. set_link_timer(pmlmeext, 1);
  1686. return _SUCCESS;
  1687. }
  1688. /* we should update current network before auth, or some IE is wrong */
  1689. pbss = (WLAN_BSSID_EX *)rtw_malloc(sizeof(WLAN_BSSID_EX));
  1690. if (pbss) {
  1691. if (collect_bss_info(padapter, precv_frame, pbss) == _SUCCESS) {
  1692. struct beacon_keys recv_beacon;
  1693. update_network(&(pmlmepriv->cur_network.network), pbss, padapter, _TRUE);
  1694. rtw_get_bcn_info(&(pmlmepriv->cur_network));
  1695. /* update bcn keys */
  1696. if (rtw_get_bcn_keys(padapter, pframe, len, &recv_beacon) == _TRUE) {
  1697. RTW_INFO("%s: beacon keys ready\n", __func__);
  1698. _rtw_memcpy(&pmlmepriv->cur_beacon_keys,
  1699. &recv_beacon, sizeof(recv_beacon));
  1700. pmlmepriv->new_beacon_cnts = 0;
  1701. } else {
  1702. RTW_ERR("%s: get beacon keys failed\n", __func__);
  1703. _rtw_memset(&pmlmepriv->cur_beacon_keys, 0, sizeof(recv_beacon));
  1704. pmlmepriv->new_beacon_cnts = 0;
  1705. }
  1706. }
  1707. rtw_mfree((u8 *)pbss, sizeof(WLAN_BSSID_EX));
  1708. }
  1709. /* check the vendor of the assoc AP */
  1710. pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pframe + sizeof(struct rtw_ieee80211_hdr_3addr), len - sizeof(struct rtw_ieee80211_hdr_3addr));
  1711. /* update TSF Value */
  1712. update_TSF(pmlmeext, pframe, len);
  1713. /* reset for adaptive_early_32k */
  1714. pmlmeext->adaptive_tsf_done = _FALSE;
  1715. pmlmeext->DrvBcnEarly = 0xff;
  1716. pmlmeext->DrvBcnTimeOut = 0xff;
  1717. pmlmeext->bcn_cnt = 0;
  1718. _rtw_memset(pmlmeext->bcn_delay_cnt, 0, sizeof(pmlmeext->bcn_delay_cnt));
  1719. _rtw_memset(pmlmeext->bcn_delay_ratio, 0, sizeof(pmlmeext->bcn_delay_ratio));
  1720. #ifdef CONFIG_P2P_PS
  1721. /* Comment by YiWei , in wifi p2p spec the "3.3 P2P Power Management" , "These mechanisms are available in a P2P Group in which only P2P Devices are associated." */
  1722. /* process_p2p_ps_ie(padapter, (pframe + WLAN_HDR_A3_LEN), (len - WLAN_HDR_A3_LEN)); */
  1723. #endif /* CONFIG_P2P_PS */
  1724. #if defined(CONFIG_P2P) && defined(CONFIG_CONCURRENT_MODE)
  1725. if (padapter->registrypriv.wifi_spec) {
  1726. if (process_p2p_cross_connect_ie(padapter, (pframe + WLAN_HDR_A3_LEN), (len - WLAN_HDR_A3_LEN)) == _FALSE) {
  1727. if (rtw_mi_buddy_check_mlmeinfo_state(padapter, WIFI_FW_AP_STATE)) {
  1728. RTW_PRINT("no issue auth, P2P cross-connect does not permit\n ");
  1729. return _SUCCESS;
  1730. }
  1731. }
  1732. }
  1733. #endif /* CONFIG_P2P CONFIG_P2P and CONFIG_CONCURRENT_MODE */
  1734. /* start auth */
  1735. start_clnt_auth(padapter);
  1736. return _SUCCESS;
  1737. }
  1738. if (((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) && (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) {
  1739. psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  1740. if (psta != NULL) {
  1741. #ifdef CONFIG_PATCH_JOIN_WRONG_CHANNEL
  1742. /* Merge from 8712 FW code */
  1743. if (cmp_pkt_chnl_diff(padapter, pframe, len) != 0) {
  1744. /* join wrong channel, deauth and reconnect */
  1745. issue_deauth(padapter, (&(pmlmeinfo->network))->MacAddress, WLAN_REASON_DEAUTH_LEAVING);
  1746. report_del_sta_event(padapter, (&(pmlmeinfo->network))->MacAddress, WLAN_REASON_JOIN_WRONG_CHANNEL, _TRUE, _FALSE);
  1747. pmlmeinfo->state &= (~WIFI_FW_ASSOC_SUCCESS);
  1748. return _SUCCESS;
  1749. }
  1750. #endif /* CONFIG_PATCH_JOIN_WRONG_CHANNEL */
  1751. ret = rtw_check_bcn_info(padapter, pframe, len);
  1752. if (!ret) {
  1753. RTW_PRINT("ap has changed, disconnect now\n ");
  1754. receive_disconnect(padapter, pmlmeinfo->network.MacAddress , 0, _FALSE);
  1755. return _SUCCESS;
  1756. }
  1757. /* update WMM, ERP in the beacon */
  1758. /* todo: the timer is used instead of the number of the beacon received */
  1759. if ((sta_rx_pkts(psta) & 0xf) == 0) {
  1760. /* RTW_INFO("update_bcn_info\n"); */
  1761. update_beacon_info(padapter, pframe, len, psta);
  1762. }
  1763. pmlmepriv->cur_network_scanned->network.Rssi = precv_frame->u.hdr.attrib.phy_info.RecvSignalPower;
  1764. adaptive_early_32k(pmlmeext, pframe, len);
  1765. #ifdef CONFIG_TDLS
  1766. #ifdef CONFIG_TDLS_CH_SW
  1767. if (rtw_tdls_is_chsw_allowed(padapter) == _TRUE) {
  1768. /* Send TDLS Channel Switch Request when receiving Beacon */
  1769. if ((padapter->tdlsinfo.chsw_info.ch_sw_state & TDLS_CH_SW_INITIATOR_STATE) && (ATOMIC_READ(&pchsw_info->chsw_on) == _TRUE)
  1770. && (pmlmeext->cur_channel == rtw_get_oper_ch(padapter))) {
  1771. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, padapter->tdlsinfo.chsw_info.addr);
  1772. if (ptdls_sta != NULL) {
  1773. if (ptdls_sta->tdls_sta_state | TDLS_LINKED_STATE)
  1774. _set_timer(&ptdls_sta->stay_on_base_chnl_timer, TDLS_CH_SW_STAY_ON_BASE_CHNL_TIMEOUT);
  1775. }
  1776. }
  1777. }
  1778. #endif
  1779. #endif /* CONFIG_TDLS */
  1780. #ifdef CONFIG_DFS
  1781. process_csa_ie(padapter, pframe, len); /* channel switch announcement */
  1782. #endif /* CONFIG_DFS */
  1783. #ifdef CONFIG_P2P_PS
  1784. process_p2p_ps_ie(padapter, (pframe + WLAN_HDR_A3_LEN), (len - WLAN_HDR_A3_LEN));
  1785. #endif /* CONFIG_P2P_PS */
  1786. if (pmlmeext->en_hw_update_tsf)
  1787. rtw_enable_hw_update_tsf_cmd(padapter);
  1788. #if 0 /* move to validate_recv_mgnt_frame */
  1789. psta->sta_stats.rx_mgnt_pkts++;
  1790. #endif
  1791. }
  1792. } else if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) {
  1793. _irqL irqL;
  1794. u8 rate_set[16];
  1795. u8 rate_num = 0;
  1796. psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  1797. if (psta != NULL) {
  1798. /*
  1799. * update WMM, ERP in the beacon
  1800. * todo: the timer is used instead of the number of the beacon received
  1801. */
  1802. if ((sta_rx_pkts(psta) & 0xf) == 0)
  1803. update_beacon_info(padapter, pframe, len, psta);
  1804. if (pmlmeext->en_hw_update_tsf)
  1805. rtw_enable_hw_update_tsf_cmd(padapter);
  1806. } else {
  1807. rtw_ies_get_supported_rate(pframe + WLAN_HDR_A3_LEN + _BEACON_IE_OFFSET_, len - WLAN_HDR_A3_LEN - _BEACON_IE_OFFSET_, rate_set, &rate_num);
  1808. if (rate_num == 0) {
  1809. RTW_INFO(FUNC_ADPT_FMT" RX beacon with no supported rate\n", FUNC_ADPT_ARG(padapter));
  1810. goto _END_ONBEACON_;
  1811. }
  1812. psta = rtw_alloc_stainfo(pstapriv, get_addr2_ptr(pframe));
  1813. if (psta == NULL) {
  1814. RTW_INFO(FUNC_ADPT_FMT" Exceed the upper limit of supported clients\n", FUNC_ADPT_ARG(padapter));
  1815. goto _END_ONBEACON_;
  1816. }
  1817. psta->expire_to = pstapriv->adhoc_expire_to;
  1818. _rtw_memcpy(psta->bssrateset, rate_set, rate_num);
  1819. psta->bssratelen = rate_num;
  1820. /* update TSF Value */
  1821. update_TSF(pmlmeext, pframe, len);
  1822. /* report sta add event */
  1823. report_add_sta_event(padapter, get_addr2_ptr(pframe));
  1824. }
  1825. }
  1826. }
  1827. _END_ONBEACON_:
  1828. return _SUCCESS;
  1829. }
  1830. unsigned int OnAuth(_adapter *padapter, union recv_frame *precv_frame)
  1831. {
  1832. #ifdef CONFIG_AP_MODE
  1833. _irqL irqL;
  1834. unsigned int auth_mode, seq, ie_len;
  1835. unsigned char *sa, *p;
  1836. u16 algorithm;
  1837. int status;
  1838. static struct sta_info stat;
  1839. struct sta_info *pstat = NULL;
  1840. struct sta_priv *pstapriv = &padapter->stapriv;
  1841. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1842. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1843. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1844. u8 *pframe = precv_frame->u.hdr.rx_data;
  1845. uint len = precv_frame->u.hdr.len;
  1846. u8 offset = 0;
  1847. #ifdef CONFIG_CONCURRENT_MODE
  1848. if (((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) &&
  1849. rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_LINKING | _FW_UNDER_SURVEY)) {
  1850. /* don't process auth request; */
  1851. return _SUCCESS;
  1852. }
  1853. #endif /* CONFIG_CONCURRENT_MODE */
  1854. if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
  1855. return _FAIL;
  1856. RTW_INFO("+OnAuth\n");
  1857. sa = get_addr2_ptr(pframe);
  1858. auth_mode = psecuritypriv->dot11AuthAlgrthm;
  1859. if (GetPrivacy(pframe)) {
  1860. u8 *iv;
  1861. struct rx_pkt_attrib *prxattrib = &(precv_frame->u.hdr.attrib);
  1862. prxattrib->hdrlen = WLAN_HDR_A3_LEN;
  1863. prxattrib->encrypt = _WEP40_;
  1864. iv = pframe + prxattrib->hdrlen;
  1865. prxattrib->key_index = ((iv[3] >> 6) & 0x3);
  1866. prxattrib->iv_len = 4;
  1867. prxattrib->icv_len = 4;
  1868. rtw_wep_decrypt(padapter, (u8 *)precv_frame);
  1869. offset = 4;
  1870. }
  1871. algorithm = le16_to_cpu(*(u16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset));
  1872. seq = le16_to_cpu(*(u16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 2));
  1873. RTW_INFO("auth alg=%x, seq=%X\n", algorithm, seq);
  1874. if (auth_mode == 2 &&
  1875. psecuritypriv->dot11PrivacyAlgrthm != _WEP40_ &&
  1876. psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)
  1877. auth_mode = 0;
  1878. if ((algorithm > 0 && auth_mode == 0) || /* rx a shared-key auth but shared not enabled */
  1879. (algorithm == 0 && auth_mode == 1)) { /* rx a open-system auth but shared-key is enabled */
  1880. RTW_INFO("auth rejected due to bad alg [alg=%d, auth_mib=%d] %02X%02X%02X%02X%02X%02X\n",
  1881. algorithm, auth_mode, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
  1882. status = _STATS_NO_SUPP_ALG_;
  1883. goto auth_fail;
  1884. }
  1885. #if CONFIG_RTW_MACADDR_ACL
  1886. if (rtw_access_ctrl(padapter, sa) == _FALSE) {
  1887. status = _STATS_UNABLE_HANDLE_STA_;
  1888. goto auth_fail;
  1889. }
  1890. #endif
  1891. pstat = rtw_get_stainfo(pstapriv, sa);
  1892. if (pstat == NULL) {
  1893. /* allocate a new one */
  1894. RTW_INFO("going to alloc stainfo for sa="MAC_FMT"\n", MAC_ARG(sa));
  1895. pstat = rtw_alloc_stainfo(pstapriv, sa);
  1896. if (pstat == NULL) {
  1897. RTW_INFO(" Exceed the upper limit of supported clients...\n");
  1898. status = _STATS_UNABLE_HANDLE_STA_;
  1899. goto auth_fail;
  1900. }
  1901. pstat->state = WIFI_FW_AUTH_NULL;
  1902. pstat->auth_seq = 0;
  1903. /* pstat->flags = 0; */
  1904. /* pstat->capability = 0; */
  1905. } else {
  1906. #ifdef CONFIG_IEEE80211W
  1907. if (pstat->bpairwise_key_installed != _TRUE && !(pstat->state & WIFI_FW_ASSOC_SUCCESS))
  1908. #endif /* CONFIG_IEEE80211W */
  1909. {
  1910. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  1911. if (rtw_is_list_empty(&pstat->asoc_list) == _FALSE) {
  1912. rtw_list_delete(&pstat->asoc_list);
  1913. pstapriv->asoc_list_cnt--;
  1914. if (pstat->expire_to > 0)
  1915. ;/* TODO: STA re_auth within expire_to */
  1916. }
  1917. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  1918. if (seq == 1)
  1919. ; /* TODO: STA re_auth and auth timeout */
  1920. }
  1921. }
  1922. #ifdef CONFIG_IEEE80211W
  1923. if (pstat->bpairwise_key_installed != _TRUE && !(pstat->state & WIFI_FW_ASSOC_SUCCESS))
  1924. #endif /* CONFIG_IEEE80211W */
  1925. {
  1926. _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
  1927. if (rtw_is_list_empty(&pstat->auth_list)) {
  1928. rtw_list_insert_tail(&pstat->auth_list, &pstapriv->auth_list);
  1929. pstapriv->auth_list_cnt++;
  1930. }
  1931. _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
  1932. }
  1933. if (pstat->auth_seq == 0)
  1934. pstat->expire_to = pstapriv->auth_to;
  1935. if ((pstat->auth_seq + 1) != seq) {
  1936. RTW_INFO("(1)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
  1937. seq, pstat->auth_seq + 1);
  1938. status = _STATS_OUT_OF_AUTH_SEQ_;
  1939. goto auth_fail;
  1940. }
  1941. if (algorithm == 0 && (auth_mode == 0 || auth_mode == 2 || auth_mode == 3)) {
  1942. if (seq == 1) {
  1943. #ifdef CONFIG_IEEE80211W
  1944. if (pstat->bpairwise_key_installed != _TRUE && !(pstat->state & WIFI_FW_ASSOC_SUCCESS))
  1945. #endif /* CONFIG_IEEE80211W */
  1946. {
  1947. pstat->state &= ~WIFI_FW_AUTH_NULL;
  1948. pstat->state |= WIFI_FW_AUTH_SUCCESS;
  1949. pstat->expire_to = pstapriv->assoc_to;
  1950. }
  1951. pstat->authalg = algorithm;
  1952. } else {
  1953. RTW_INFO("(2)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
  1954. seq, pstat->auth_seq + 1);
  1955. status = _STATS_OUT_OF_AUTH_SEQ_;
  1956. goto auth_fail;
  1957. }
  1958. } else { /* shared system or auto authentication */
  1959. if (seq == 1) {
  1960. /* prepare for the challenging txt... */
  1961. /* get_random_bytes((void *)pstat->chg_txt, 128); */ /* TODO: */
  1962. _rtw_memset((void *)pstat->chg_txt, 78, 128);
  1963. #ifdef CONFIG_IEEE80211W
  1964. if (pstat->bpairwise_key_installed != _TRUE && !(pstat->state & WIFI_FW_ASSOC_SUCCESS))
  1965. #endif /* CONFIG_IEEE80211W */
  1966. {
  1967. pstat->state &= ~WIFI_FW_AUTH_NULL;
  1968. pstat->state |= WIFI_FW_AUTH_STATE;
  1969. }
  1970. pstat->authalg = algorithm;
  1971. pstat->auth_seq = 2;
  1972. } else if (seq == 3) {
  1973. /* checking for challenging txt... */
  1974. RTW_INFO("checking for challenging txt...\n");
  1975. p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + 4 + _AUTH_IE_OFFSET_ , _CHLGETXT_IE_, (int *)&ie_len,
  1976. len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_ - 4);
  1977. if ((p == NULL) || (ie_len <= 0)) {
  1978. RTW_INFO("auth rejected because challenge failure!(1)\n");
  1979. status = _STATS_CHALLENGE_FAIL_;
  1980. goto auth_fail;
  1981. }
  1982. if (_rtw_memcmp((void *)(p + 2), pstat->chg_txt, 128)) {
  1983. #ifdef CONFIG_IEEE80211W
  1984. if (pstat->bpairwise_key_installed != _TRUE && !(pstat->state & WIFI_FW_ASSOC_SUCCESS))
  1985. #endif /* CONFIG_IEEE80211W */
  1986. {
  1987. pstat->state &= (~WIFI_FW_AUTH_STATE);
  1988. pstat->state |= WIFI_FW_AUTH_SUCCESS;
  1989. /* challenging txt is correct... */
  1990. pstat->expire_to = pstapriv->assoc_to;
  1991. }
  1992. } else {
  1993. RTW_INFO("auth rejected because challenge failure!\n");
  1994. status = _STATS_CHALLENGE_FAIL_;
  1995. goto auth_fail;
  1996. }
  1997. } else {
  1998. RTW_INFO("(3)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
  1999. seq, pstat->auth_seq + 1);
  2000. status = _STATS_OUT_OF_AUTH_SEQ_;
  2001. goto auth_fail;
  2002. }
  2003. }
  2004. /* Now, we are going to issue_auth... */
  2005. pstat->auth_seq = seq + 1;
  2006. #ifdef CONFIG_NATIVEAP_MLME
  2007. issue_auth(padapter, pstat, (unsigned short)(_STATS_SUCCESSFUL_));
  2008. #endif
  2009. if ((pstat->state & WIFI_FW_AUTH_SUCCESS) || (pstat->state & WIFI_FW_ASSOC_SUCCESS))
  2010. pstat->auth_seq = 0;
  2011. return _SUCCESS;
  2012. auth_fail:
  2013. if (pstat)
  2014. rtw_free_stainfo(padapter , pstat);
  2015. pstat = &stat;
  2016. _rtw_memset((char *)pstat, '\0', sizeof(stat));
  2017. pstat->auth_seq = 2;
  2018. _rtw_memcpy(pstat->hwaddr, sa, 6);
  2019. #ifdef CONFIG_NATIVEAP_MLME
  2020. issue_auth(padapter, pstat, (unsigned short)status);
  2021. #endif
  2022. #endif
  2023. return _FAIL;
  2024. }
  2025. unsigned int OnAuthClient(_adapter *padapter, union recv_frame *precv_frame)
  2026. {
  2027. unsigned int seq, len, status, algthm, offset;
  2028. unsigned char *p;
  2029. unsigned int go2asoc = 0;
  2030. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2031. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2032. #ifdef CONFIG_RTW_80211R
  2033. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2034. ft_priv *pftpriv = &pmlmepriv->ftpriv;
  2035. struct sta_priv *pstapriv = &padapter->stapriv;
  2036. struct sta_info *psta = NULL;
  2037. #endif
  2038. u8 *pframe = precv_frame->u.hdr.rx_data;
  2039. uint pkt_len = precv_frame->u.hdr.len;
  2040. RTW_INFO("%s\n", __FUNCTION__);
  2041. /* check A1 matches or not */
  2042. if (!_rtw_memcmp(adapter_mac_addr(padapter), get_da(pframe), ETH_ALEN))
  2043. return _SUCCESS;
  2044. if (!(pmlmeinfo->state & WIFI_FW_AUTH_STATE))
  2045. return _SUCCESS;
  2046. offset = (GetPrivacy(pframe)) ? 4 : 0;
  2047. algthm = le16_to_cpu(*(unsigned short *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset));
  2048. seq = le16_to_cpu(*(unsigned short *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 2));
  2049. status = le16_to_cpu(*(unsigned short *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 4));
  2050. if (status != 0) {
  2051. RTW_INFO("clnt auth fail, status: %d\n", status);
  2052. if (status == 13) { /* && pmlmeinfo->auth_algo == dot11AuthAlgrthm_Auto) */
  2053. if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
  2054. pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
  2055. else
  2056. pmlmeinfo->auth_algo = dot11AuthAlgrthm_Shared;
  2057. /* pmlmeinfo->reauth_count = 0; */
  2058. }
  2059. set_link_timer(pmlmeext, 1);
  2060. goto authclnt_fail;
  2061. }
  2062. if (seq == 2) {
  2063. if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) {
  2064. /* legendary shared system */
  2065. p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, _CHLGETXT_IE_, (int *)&len,
  2066. pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_);
  2067. if (p == NULL) {
  2068. /* RTW_INFO("marc: no challenge text?\n"); */
  2069. goto authclnt_fail;
  2070. }
  2071. _rtw_memcpy((void *)(pmlmeinfo->chg_txt), (void *)(p + 2), len);
  2072. pmlmeinfo->auth_seq = 3;
  2073. issue_auth(padapter, NULL, 0);
  2074. set_link_timer(pmlmeext, REAUTH_TO);
  2075. return _SUCCESS;
  2076. } else {
  2077. /* open, or 802.11r FTAA system */
  2078. go2asoc = 1;
  2079. }
  2080. } else if (seq == 4) {
  2081. if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
  2082. go2asoc = 1;
  2083. else
  2084. goto authclnt_fail;
  2085. } else {
  2086. /* this is also illegal */
  2087. /* RTW_INFO("marc: clnt auth failed due to illegal seq=%x\n", seq); */
  2088. goto authclnt_fail;
  2089. }
  2090. if (go2asoc) {
  2091. #ifdef CONFIG_RTW_80211R
  2092. if ((rtw_to_roam(padapter) > 0) && rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED)) {
  2093. u8 target_ap_addr[ETH_ALEN] = {0};
  2094. if ((rtw_chk_ft_status(padapter, RTW_FT_AUTHENTICATED_STA)) ||
  2095. (rtw_chk_ft_status(padapter, RTW_FT_ASSOCIATING_STA)) ||
  2096. (rtw_chk_ft_status(padapter, RTW_FT_ASSOCIATED_STA))) {
  2097. /*report_ft_reassoc_event already, and waiting for cfg80211_rtw_update_ft_ies*/
  2098. return _SUCCESS;
  2099. }
  2100. rtw_buf_update(&pmlmepriv->auth_rsp, &pmlmepriv->auth_rsp_len, pframe, pkt_len);
  2101. pftpriv->ft_event.ies = pmlmepriv->auth_rsp + sizeof(struct rtw_ieee80211_hdr_3addr) + 6;
  2102. pftpriv->ft_event.ies_len = pmlmepriv->auth_rsp_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 6;
  2103. /*Not support RIC*/
  2104. pftpriv->ft_event.ric_ies = NULL;
  2105. pftpriv->ft_event.ric_ies_len = 0;
  2106. _rtw_memcpy(target_ap_addr, pmlmepriv->assoc_bssid, ETH_ALEN);
  2107. report_ft_reassoc_event(padapter, target_ap_addr);
  2108. return _SUCCESS;
  2109. }
  2110. #endif
  2111. RTW_PRINT("auth success, start assoc\n");
  2112. start_clnt_assoc(padapter);
  2113. return _SUCCESS;
  2114. }
  2115. authclnt_fail:
  2116. /* pmlmeinfo->state &= ~(WIFI_FW_AUTH_STATE); */
  2117. return _FAIL;
  2118. }
  2119. unsigned int OnAssocReq(_adapter *padapter, union recv_frame *precv_frame)
  2120. {
  2121. #ifdef CONFIG_AP_MODE
  2122. _irqL irqL;
  2123. u16 capab_info, listen_interval;
  2124. struct rtw_ieee802_11_elems elems;
  2125. struct sta_info *pstat;
  2126. unsigned char reassoc, *p, *pos, *wpa_ie;
  2127. unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
  2128. int i, ie_len, wpa_ie_len, left;
  2129. u8 rate_set[16];
  2130. u8 rate_num;
  2131. unsigned short status = _STATS_SUCCESSFUL_;
  2132. unsigned short frame_type, ie_offset = 0;
  2133. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2134. struct security_priv *psecuritypriv = &padapter->securitypriv;
  2135. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2136. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2137. WLAN_BSSID_EX *cur = &(pmlmeinfo->network);
  2138. struct sta_priv *pstapriv = &padapter->stapriv;
  2139. u8 *pframe = precv_frame->u.hdr.rx_data;
  2140. uint pkt_len = precv_frame->u.hdr.len;
  2141. #ifdef CONFIG_P2P
  2142. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  2143. u8 p2p_status_code = P2P_STATUS_SUCCESS;
  2144. u8 *p2pie;
  2145. u32 p2pielen = 0;
  2146. #endif /* CONFIG_P2P */
  2147. #ifdef CONFIG_CONCURRENT_MODE
  2148. if (((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) &&
  2149. rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_LINKING | _FW_UNDER_SURVEY)) {
  2150. /* don't process assoc request; */
  2151. return _SUCCESS;
  2152. }
  2153. #endif /* CONFIG_CONCURRENT_MODE */
  2154. if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
  2155. return _FAIL;
  2156. frame_type = get_frame_sub_type(pframe);
  2157. if (frame_type == WIFI_ASSOCREQ) {
  2158. reassoc = 0;
  2159. ie_offset = _ASOCREQ_IE_OFFSET_;
  2160. } else { /* WIFI_REASSOCREQ */
  2161. reassoc = 1;
  2162. ie_offset = _REASOCREQ_IE_OFFSET_;
  2163. }
  2164. if (pkt_len < IEEE80211_3ADDR_LEN + ie_offset) {
  2165. RTW_INFO("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
  2166. "\n", reassoc, (unsigned long)pkt_len);
  2167. return _FAIL;
  2168. }
  2169. pstat = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  2170. if (pstat == (struct sta_info *)NULL) {
  2171. status = _RSON_CLS2_;
  2172. goto asoc_class2_error;
  2173. }
  2174. capab_info = RTW_GET_LE16(pframe + WLAN_HDR_A3_LEN);
  2175. /* capab_info = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN)); */
  2176. /* listen_interval = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN+2)); */
  2177. listen_interval = RTW_GET_LE16(pframe + WLAN_HDR_A3_LEN + 2);
  2178. left = pkt_len - (IEEE80211_3ADDR_LEN + ie_offset);
  2179. pos = pframe + (IEEE80211_3ADDR_LEN + ie_offset);
  2180. RTW_INFO("%s\n", __FUNCTION__);
  2181. /* check if this stat has been successfully authenticated/assocated */
  2182. if (!((pstat->state) & WIFI_FW_AUTH_SUCCESS)) {
  2183. if (!((pstat->state) & WIFI_FW_ASSOC_SUCCESS)) {
  2184. status = _RSON_CLS2_;
  2185. goto asoc_class2_error;
  2186. } else {
  2187. pstat->state &= (~WIFI_FW_ASSOC_SUCCESS);
  2188. pstat->state |= WIFI_FW_ASSOC_STATE;
  2189. }
  2190. } else {
  2191. pstat->state &= (~WIFI_FW_AUTH_SUCCESS);
  2192. pstat->state |= WIFI_FW_ASSOC_STATE;
  2193. }
  2194. #if 0/* todo:tkip_countermeasures */
  2195. if (hapd->tkip_countermeasures) {
  2196. resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
  2197. goto fail;
  2198. }
  2199. #endif
  2200. pstat->capability = capab_info;
  2201. #if 0/* todo: */
  2202. /* check listen_interval */
  2203. if (listen_interval > hapd->conf->max_listen_interval) {
  2204. hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
  2205. HOSTAPD_LEVEL_DEBUG,
  2206. "Too large Listen Interval (%d)",
  2207. listen_interval);
  2208. resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
  2209. goto fail;
  2210. }
  2211. pstat->listen_interval = listen_interval;
  2212. #endif
  2213. /* now parse all ieee802_11 ie to point to elems */
  2214. if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
  2215. !elems.ssid) {
  2216. RTW_INFO("STA " MAC_FMT " sent invalid association request\n",
  2217. MAC_ARG(pstat->hwaddr));
  2218. status = _STATS_FAILURE_;
  2219. goto OnAssocReqFail;
  2220. }
  2221. /* now we should check all the fields... */
  2222. /* checking SSID */
  2223. p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
  2224. pkt_len - WLAN_HDR_A3_LEN - ie_offset);
  2225. if (p == NULL)
  2226. status = _STATS_FAILURE_;
  2227. if (ie_len == 0) /* broadcast ssid, however it is not allowed in assocreq */
  2228. status = _STATS_FAILURE_;
  2229. else {
  2230. /* check if ssid match */
  2231. if (!_rtw_memcmp((void *)(p + 2), cur->Ssid.Ssid, cur->Ssid.SsidLength))
  2232. status = _STATS_FAILURE_;
  2233. if (ie_len != cur->Ssid.SsidLength)
  2234. status = _STATS_FAILURE_;
  2235. }
  2236. if (_STATS_SUCCESSFUL_ != status)
  2237. goto OnAssocReqFail;
  2238. rtw_ies_get_supported_rate(pframe + WLAN_HDR_A3_LEN + ie_offset, pkt_len - WLAN_HDR_A3_LEN - ie_offset, rate_set, &rate_num);
  2239. if (rate_num == 0) {
  2240. RTW_INFO(FUNC_ADPT_FMT" RX assoc-req with no supported rate\n", FUNC_ADPT_ARG(padapter));
  2241. status = _STATS_FAILURE_;
  2242. goto OnAssocReqFail;
  2243. }
  2244. _rtw_memcpy(pstat->bssrateset, rate_set, rate_num);
  2245. pstat->bssratelen = rate_num;
  2246. UpdateBrateTblForSoftAP(pstat->bssrateset, pstat->bssratelen);
  2247. /* check RSN/WPA/WPS */
  2248. pstat->dot8021xalg = 0;
  2249. pstat->wpa_psk = 0;
  2250. pstat->wpa_group_cipher = 0;
  2251. pstat->wpa2_group_cipher = 0;
  2252. pstat->wpa_pairwise_cipher = 0;
  2253. pstat->wpa2_pairwise_cipher = 0;
  2254. _rtw_memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
  2255. if ((psecuritypriv->wpa_psk & BIT(1)) && elems.rsn_ie) {
  2256. int group_cipher = 0, pairwise_cipher = 0;
  2257. wpa_ie = elems.rsn_ie;
  2258. wpa_ie_len = elems.rsn_ie_len;
  2259. if (rtw_parse_wpa2_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
  2260. pstat->dot8021xalg = 1;/* psk, todo:802.1x */
  2261. pstat->wpa_psk |= BIT(1);
  2262. pstat->wpa2_group_cipher = group_cipher & psecuritypriv->wpa2_group_cipher;
  2263. pstat->wpa2_pairwise_cipher = pairwise_cipher & psecuritypriv->wpa2_pairwise_cipher;
  2264. if (!pstat->wpa2_group_cipher)
  2265. status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  2266. if (!pstat->wpa2_pairwise_cipher)
  2267. status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  2268. } else
  2269. status = WLAN_STATUS_INVALID_IE;
  2270. } else if ((psecuritypriv->wpa_psk & BIT(0)) && elems.wpa_ie) {
  2271. int group_cipher = 0, pairwise_cipher = 0;
  2272. wpa_ie = elems.wpa_ie;
  2273. wpa_ie_len = elems.wpa_ie_len;
  2274. if (rtw_parse_wpa_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
  2275. pstat->dot8021xalg = 1;/* psk, todo:802.1x */
  2276. pstat->wpa_psk |= BIT(0);
  2277. pstat->wpa_group_cipher = group_cipher & psecuritypriv->wpa_group_cipher;
  2278. pstat->wpa_pairwise_cipher = pairwise_cipher & psecuritypriv->wpa_pairwise_cipher;
  2279. if (!pstat->wpa_group_cipher)
  2280. status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  2281. if (!pstat->wpa_pairwise_cipher)
  2282. status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  2283. } else
  2284. status = WLAN_STATUS_INVALID_IE;
  2285. } else {
  2286. wpa_ie = NULL;
  2287. wpa_ie_len = 0;
  2288. }
  2289. if (_STATS_SUCCESSFUL_ != status)
  2290. goto OnAssocReqFail;
  2291. pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
  2292. /* if (hapd->conf->wps_state && wpa_ie == NULL) { */ /* todo: to check ap if supporting WPS */
  2293. if (wpa_ie == NULL) {
  2294. if (elems.wps_ie) {
  2295. RTW_INFO("STA included WPS IE in "
  2296. "(Re)Association Request - assume WPS is "
  2297. "used\n");
  2298. pstat->flags |= WLAN_STA_WPS;
  2299. /* wpabuf_free(sta->wps_ie); */
  2300. /* sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4, */
  2301. /* elems.wps_ie_len - 4); */
  2302. } else {
  2303. RTW_INFO("STA did not include WPA/RSN IE "
  2304. "in (Re)Association Request - possible WPS "
  2305. "use\n");
  2306. pstat->flags |= WLAN_STA_MAYBE_WPS;
  2307. }
  2308. /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
  2309. /* that the selected registrar of AP is _FLASE */
  2310. if ((psecuritypriv->wpa_psk > 0)
  2311. && (pstat->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
  2312. if (pmlmepriv->wps_beacon_ie) {
  2313. u8 selected_registrar = 0;
  2314. rtw_get_wps_attr_content(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR , &selected_registrar, NULL);
  2315. if (!selected_registrar) {
  2316. RTW_INFO("selected_registrar is _FALSE , or AP is not ready to do WPS\n");
  2317. status = _STATS_UNABLE_HANDLE_STA_;
  2318. goto OnAssocReqFail;
  2319. }
  2320. }
  2321. }
  2322. } else {
  2323. int copy_len;
  2324. if (psecuritypriv->wpa_psk == 0) {
  2325. RTW_INFO("STA " MAC_FMT ": WPA/RSN IE in association "
  2326. "request, but AP don't support WPA/RSN\n", MAC_ARG(pstat->hwaddr));
  2327. status = WLAN_STATUS_INVALID_IE;
  2328. goto OnAssocReqFail;
  2329. }
  2330. if (elems.wps_ie) {
  2331. RTW_INFO("STA included WPS IE in "
  2332. "(Re)Association Request - WPS is "
  2333. "used\n");
  2334. pstat->flags |= WLAN_STA_WPS;
  2335. copy_len = 0;
  2336. } else
  2337. copy_len = ((wpa_ie_len + 2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)) : (wpa_ie_len + 2);
  2338. if (copy_len > 0)
  2339. _rtw_memcpy(pstat->wpa_ie, wpa_ie - 2, copy_len);
  2340. }
  2341. /* check if there is WMM IE & support WWM-PS */
  2342. pstat->flags &= ~WLAN_STA_WME;
  2343. pstat->qos_option = 0;
  2344. pstat->qos_info = 0;
  2345. pstat->has_legacy_ac = _TRUE;
  2346. pstat->uapsd_vo = 0;
  2347. pstat->uapsd_vi = 0;
  2348. pstat->uapsd_be = 0;
  2349. pstat->uapsd_bk = 0;
  2350. if (pmlmepriv->qospriv.qos_option) {
  2351. p = pframe + WLAN_HDR_A3_LEN + ie_offset;
  2352. ie_len = 0;
  2353. for (;;) {
  2354. p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
  2355. if (p != NULL) {
  2356. if (_rtw_memcmp(p + 2, WMM_IE, 6)) {
  2357. pstat->flags |= WLAN_STA_WME;
  2358. pstat->qos_option = 1;
  2359. pstat->qos_info = *(p + 8);
  2360. pstat->max_sp_len = (pstat->qos_info >> 5) & 0x3;
  2361. if ((pstat->qos_info & 0xf) != 0xf)
  2362. pstat->has_legacy_ac = _TRUE;
  2363. else
  2364. pstat->has_legacy_ac = _FALSE;
  2365. if (pstat->qos_info & 0xf) {
  2366. if (pstat->qos_info & BIT(0))
  2367. pstat->uapsd_vo = BIT(0) | BIT(1);
  2368. else
  2369. pstat->uapsd_vo = 0;
  2370. if (pstat->qos_info & BIT(1))
  2371. pstat->uapsd_vi = BIT(0) | BIT(1);
  2372. else
  2373. pstat->uapsd_vi = 0;
  2374. if (pstat->qos_info & BIT(2))
  2375. pstat->uapsd_bk = BIT(0) | BIT(1);
  2376. else
  2377. pstat->uapsd_bk = 0;
  2378. if (pstat->qos_info & BIT(3))
  2379. pstat->uapsd_be = BIT(0) | BIT(1);
  2380. else
  2381. pstat->uapsd_be = 0;
  2382. }
  2383. break;
  2384. }
  2385. } else
  2386. break;
  2387. p = p + ie_len + 2;
  2388. }
  2389. }
  2390. #ifdef CONFIG_80211N_HT
  2391. if (pmlmepriv->htpriv.ht_option == _FALSE)
  2392. goto bypass_ht_chk;
  2393. /* save HT capabilities in the sta object */
  2394. _rtw_memset(&pstat->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
  2395. if (elems.ht_capabilities && elems.ht_capabilities_len >= sizeof(struct rtw_ieee80211_ht_cap)) {
  2396. pstat->flags |= WLAN_STA_HT;
  2397. pstat->flags |= WLAN_STA_WME;
  2398. _rtw_memcpy(&pstat->htpriv.ht_cap, elems.ht_capabilities, sizeof(struct rtw_ieee80211_ht_cap));
  2399. } else
  2400. pstat->flags &= ~WLAN_STA_HT;
  2401. bypass_ht_chk:
  2402. if ((pmlmepriv->htpriv.ht_option == _FALSE) && (pstat->flags & WLAN_STA_HT)) {
  2403. rtw_warn_on(1);
  2404. status = _STATS_FAILURE_;
  2405. goto OnAssocReqFail;
  2406. }
  2407. #endif /* CONFIG_80211N_HT */
  2408. #ifdef CONFIG_80211AC_VHT
  2409. if (pmlmepriv->vhtpriv.vht_option == _FALSE)
  2410. goto bypass_vht_chk;
  2411. _rtw_memset(&pstat->vhtpriv, 0, sizeof(struct vht_priv));
  2412. if (elems.vht_capabilities && elems.vht_capabilities_len == 12) {
  2413. pstat->flags |= WLAN_STA_VHT;
  2414. _rtw_memcpy(pstat->vhtpriv.vht_cap, elems.vht_capabilities, 12);
  2415. if (elems.vht_op_mode_notify && elems.vht_op_mode_notify_len == 1)
  2416. _rtw_memcpy(&pstat->vhtpriv.vht_op_mode_notify, elems.vht_op_mode_notify, 1);
  2417. else /* for Frame without Operating Mode notify ie; default: 80M */
  2418. pstat->vhtpriv.vht_op_mode_notify = CHANNEL_WIDTH_80;
  2419. } else
  2420. pstat->flags &= ~WLAN_STA_VHT;
  2421. bypass_vht_chk:
  2422. if ((pmlmepriv->vhtpriv.vht_option == _FALSE) && (pstat->flags & WLAN_STA_VHT)) {
  2423. rtw_warn_on(1);
  2424. status = _STATS_FAILURE_;
  2425. goto OnAssocReqFail;
  2426. }
  2427. #endif /* CONFIG_80211AC_VHT */
  2428. if (((pstat->flags & WLAN_STA_HT) || (pstat->flags & WLAN_STA_VHT)) &&
  2429. ((pstat->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) ||
  2430. (pstat->wpa_pairwise_cipher & WPA_CIPHER_TKIP))) {
  2431. RTW_INFO("(V)HT: " MAC_FMT " tried to use TKIP with (V)HT association\n", MAC_ARG(pstat->hwaddr));
  2432. pstat->flags &= ~WLAN_STA_HT;
  2433. pstat->flags &= ~WLAN_STA_VHT;
  2434. /*status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
  2435. * goto OnAssocReqFail;
  2436. */
  2437. }
  2438. /*
  2439. * if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) */ /* ? */
  2440. pstat->flags |= WLAN_STA_NONERP;
  2441. for (i = 0; i < pstat->bssratelen; i++) {
  2442. if ((pstat->bssrateset[i] & 0x7f) > 22) {
  2443. pstat->flags &= ~WLAN_STA_NONERP;
  2444. break;
  2445. }
  2446. }
  2447. if (pstat->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  2448. pstat->flags |= WLAN_STA_SHORT_PREAMBLE;
  2449. else
  2450. pstat->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  2451. if (status != _STATS_SUCCESSFUL_)
  2452. goto OnAssocReqFail;
  2453. #ifdef CONFIG_P2P
  2454. pstat->is_p2p_device = _FALSE;
  2455. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  2456. p2pie = rtw_get_p2p_ie(pframe + WLAN_HDR_A3_LEN + ie_offset , pkt_len - WLAN_HDR_A3_LEN - ie_offset , NULL, &p2pielen);
  2457. if (p2pie) {
  2458. pstat->is_p2p_device = _TRUE;
  2459. p2p_status_code = (u8)process_assoc_req_p2p_ie(pwdinfo, pframe, pkt_len, pstat);
  2460. if (p2p_status_code > 0) {
  2461. pstat->p2p_status_code = p2p_status_code;
  2462. status = _STATS_CAP_FAIL_;
  2463. goto OnAssocReqFail;
  2464. }
  2465. }
  2466. #ifdef CONFIG_WFD
  2467. rtw_process_wfd_ies(padapter, pframe + WLAN_HDR_A3_LEN + ie_offset, pkt_len - WLAN_HDR_A3_LEN - ie_offset, __func__);
  2468. #endif
  2469. }
  2470. pstat->p2p_status_code = p2p_status_code;
  2471. #endif /* CONFIG_P2P */
  2472. /* TODO: identify_proprietary_vendor_ie(); */
  2473. /* Realtek proprietary IE */
  2474. /* identify if this is Broadcom sta */
  2475. /* identify if this is ralink sta */
  2476. /* Customer proprietary IE */
  2477. /* get a unique AID */
  2478. if (pstat->aid > 0)
  2479. RTW_INFO(" old AID %d\n", pstat->aid);
  2480. else {
  2481. for (pstat->aid = 1; pstat->aid <= NUM_STA; pstat->aid++) {
  2482. if (pstapriv->sta_aid[pstat->aid - 1] == NULL) {
  2483. if (pstat->aid > pstapriv->max_num_sta) {
  2484. pstat->aid = 0;
  2485. RTW_INFO(" no room for more AIDs\n");
  2486. status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  2487. goto OnAssocReqFail;
  2488. } else {
  2489. pstapriv->sta_aid[pstat->aid - 1] = pstat;
  2490. RTW_INFO("allocate new AID = (%d)\n", pstat->aid);
  2491. break;
  2492. }
  2493. }
  2494. }
  2495. }
  2496. pstat->state &= (~WIFI_FW_ASSOC_STATE);
  2497. pstat->state |= WIFI_FW_ASSOC_SUCCESS;
  2498. /* RTW_INFO("==================%s, %d, (%x), bpairwise_key_installed=%d, MAC:"MAC_FMT"\n"
  2499. , __func__, __LINE__, pstat->state, pstat->bpairwise_key_installed, MAC_ARG(pstat->hwaddr)); */
  2500. #ifdef CONFIG_IEEE80211W
  2501. if (pstat->bpairwise_key_installed != _TRUE)
  2502. #endif /* CONFIG_IEEE80211W */
  2503. {
  2504. _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
  2505. if (!rtw_is_list_empty(&pstat->auth_list)) {
  2506. rtw_list_delete(&pstat->auth_list);
  2507. pstapriv->auth_list_cnt--;
  2508. }
  2509. _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
  2510. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2511. if (rtw_is_list_empty(&pstat->asoc_list)) {
  2512. pstat->expire_to = pstapriv->expire_to;
  2513. rtw_list_insert_tail(&pstat->asoc_list, &pstapriv->asoc_list);
  2514. pstapriv->asoc_list_cnt++;
  2515. }
  2516. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2517. }
  2518. /* now the station is qualified to join our BSS... */
  2519. if (pstat && (pstat->state & WIFI_FW_ASSOC_SUCCESS) && (_STATS_SUCCESSFUL_ == status)) {
  2520. #ifdef CONFIG_NATIVEAP_MLME
  2521. #ifdef CONFIG_IEEE80211W
  2522. if (pstat->bpairwise_key_installed != _TRUE)
  2523. #endif /* CONFIG_IEEE80211W */
  2524. {
  2525. /* .1 bss_cap_update & sta_info_update */
  2526. bss_cap_update_on_sta_join(padapter, pstat);
  2527. sta_info_update(padapter, pstat);
  2528. }
  2529. #ifdef CONFIG_IEEE80211W
  2530. if (pstat->bpairwise_key_installed == _TRUE)
  2531. status = _STATS_REFUSED_TEMPORARILY_;
  2532. #endif /* CONFIG_IEEE80211W */
  2533. /* .2 issue assoc rsp before notify station join event. */
  2534. if (frame_type == WIFI_ASSOCREQ)
  2535. issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
  2536. else
  2537. issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
  2538. #ifdef CONFIG_IOCTL_CFG80211
  2539. _enter_critical_bh(&pstat->lock, &irqL);
  2540. if (pstat->passoc_req) {
  2541. rtw_mfree(pstat->passoc_req, pstat->assoc_req_len);
  2542. pstat->passoc_req = NULL;
  2543. pstat->assoc_req_len = 0;
  2544. }
  2545. pstat->passoc_req = rtw_zmalloc(pkt_len);
  2546. if (pstat->passoc_req) {
  2547. _rtw_memcpy(pstat->passoc_req, pframe, pkt_len);
  2548. pstat->assoc_req_len = pkt_len;
  2549. }
  2550. _exit_critical_bh(&pstat->lock, &irqL);
  2551. #endif /* CONFIG_IOCTL_CFG80211 */
  2552. #ifdef CONFIG_IEEE80211W
  2553. if (pstat->bpairwise_key_installed != _TRUE)
  2554. #endif /* CONFIG_IEEE80211W */
  2555. {
  2556. /* .3-(1) report sta add event */
  2557. report_add_sta_event(padapter, pstat->hwaddr);
  2558. }
  2559. #ifdef CONFIG_IEEE80211W
  2560. if (pstat->bpairwise_key_installed == _TRUE && padapter->securitypriv.binstallBIPkey == _TRUE) {
  2561. RTW_INFO(MAC_FMT"\n", MAC_ARG(pstat->hwaddr));
  2562. issue_action_SA_Query(padapter, pstat->hwaddr, 0, 0, IEEE80211W_RIGHT_KEY);
  2563. }
  2564. #endif /* CONFIG_IEEE80211W */
  2565. #endif /* CONFIG_NATIVEAP_MLME */
  2566. }
  2567. return _SUCCESS;
  2568. asoc_class2_error:
  2569. #ifdef CONFIG_NATIVEAP_MLME
  2570. issue_deauth(padapter, (void *)get_addr2_ptr(pframe), status);
  2571. #endif
  2572. return _FAIL;
  2573. OnAssocReqFail:
  2574. #ifdef CONFIG_NATIVEAP_MLME
  2575. pstat->aid = 0;
  2576. if (frame_type == WIFI_ASSOCREQ)
  2577. issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
  2578. else
  2579. issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
  2580. #endif
  2581. #endif /* CONFIG_AP_MODE */
  2582. return _FAIL;
  2583. }
  2584. unsigned int OnAssocRsp(_adapter *padapter, union recv_frame *precv_frame)
  2585. {
  2586. uint i;
  2587. int res;
  2588. unsigned short status;
  2589. PNDIS_802_11_VARIABLE_IEs pIE;
  2590. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2591. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2592. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2593. /* WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network); */
  2594. u8 *pframe = precv_frame->u.hdr.rx_data;
  2595. uint pkt_len = precv_frame->u.hdr.len;
  2596. PNDIS_802_11_VARIABLE_IEs pWapiIE = NULL;
  2597. RTW_INFO("%s\n", __FUNCTION__);
  2598. /* check A1 matches or not */
  2599. if (!_rtw_memcmp(adapter_mac_addr(padapter), get_da(pframe), ETH_ALEN))
  2600. return _SUCCESS;
  2601. if (!(pmlmeinfo->state & (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE)))
  2602. return _SUCCESS;
  2603. if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
  2604. return _SUCCESS;
  2605. _cancel_timer_ex(&pmlmeext->link_timer);
  2606. /* status */
  2607. status = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN + 2));
  2608. if (status > 0) {
  2609. RTW_INFO("assoc reject, status code: %d\n", status);
  2610. pmlmeinfo->state = WIFI_FW_NULL_STATE;
  2611. res = -4;
  2612. goto report_assoc_result;
  2613. }
  2614. /* get capabilities */
  2615. pmlmeinfo->capability = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN));
  2616. /* set slot time */
  2617. pmlmeinfo->slotTime = (pmlmeinfo->capability & BIT(10)) ? 9 : 20;
  2618. /* AID */
  2619. res = pmlmeinfo->aid = (int)(le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN + 4)) & 0x3fff);
  2620. /* following are moved to join event callback function */
  2621. /* to handle HT, WMM, rate adaptive, update MAC reg */
  2622. /* for not to handle the synchronous IO in the tasklet */
  2623. for (i = (6 + WLAN_HDR_A3_LEN); i < pkt_len;) {
  2624. pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + i);
  2625. switch (pIE->ElementID) {
  2626. case _VENDOR_SPECIFIC_IE_:
  2627. if (_rtw_memcmp(pIE->data, WMM_PARA_OUI, 6)) /* WMM */
  2628. WMM_param_handler(padapter, pIE);
  2629. #if defined(CONFIG_P2P) && defined(CONFIG_WFD)
  2630. else if (_rtw_memcmp(pIE->data, WFD_OUI, 4)) /* WFD */
  2631. rtw_process_wfd_ie(padapter, (u8 *)pIE, pIE->Length, __func__);
  2632. #endif
  2633. break;
  2634. #ifdef CONFIG_WAPI_SUPPORT
  2635. case _WAPI_IE_:
  2636. pWapiIE = pIE;
  2637. break;
  2638. #endif
  2639. case _HT_CAPABILITY_IE_: /* HT caps */
  2640. HT_caps_handler(padapter, pIE);
  2641. break;
  2642. case _HT_EXTRA_INFO_IE_: /* HT info */
  2643. HT_info_handler(padapter, pIE);
  2644. break;
  2645. #ifdef CONFIG_80211AC_VHT
  2646. case EID_VHTCapability:
  2647. VHT_caps_handler(padapter, pIE);
  2648. break;
  2649. case EID_VHTOperation:
  2650. VHT_operation_handler(padapter, pIE);
  2651. break;
  2652. #endif
  2653. case _ERPINFO_IE_:
  2654. ERP_IE_handler(padapter, pIE);
  2655. break;
  2656. #ifdef CONFIG_TDLS
  2657. case _EXT_CAP_IE_:
  2658. if (check_ap_tdls_prohibited(pIE->data, pIE->Length) == _TRUE)
  2659. padapter->tdlsinfo.ap_prohibited = _TRUE;
  2660. if (check_ap_tdls_ch_switching_prohibited(pIE->data, pIE->Length) == _TRUE)
  2661. padapter->tdlsinfo.ch_switch_prohibited = _TRUE;
  2662. break;
  2663. #endif /* CONFIG_TDLS */
  2664. default:
  2665. break;
  2666. }
  2667. i += (pIE->Length + 2);
  2668. }
  2669. #ifdef CONFIG_WAPI_SUPPORT
  2670. rtw_wapi_on_assoc_ok(padapter, pIE);
  2671. #endif
  2672. pmlmeinfo->state &= (~WIFI_FW_ASSOC_STATE);
  2673. pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
  2674. /* Update Basic Rate Table for spec, 2010-12-28 , by thomas */
  2675. UpdateBrateTbl(padapter, pmlmeinfo->network.SupportedRates);
  2676. report_assoc_result:
  2677. if (res > 0)
  2678. rtw_buf_update(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len, pframe, pkt_len);
  2679. else
  2680. rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
  2681. report_join_res(padapter, res);
  2682. return _SUCCESS;
  2683. }
  2684. unsigned int OnDeAuth(_adapter *padapter, union recv_frame *precv_frame)
  2685. {
  2686. unsigned short reason;
  2687. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2688. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2689. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2690. u8 *pframe = precv_frame->u.hdr.rx_data;
  2691. #ifdef CONFIG_P2P
  2692. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  2693. #endif /* CONFIG_P2P */
  2694. /* check A3 */
  2695. if (!(_rtw_memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
  2696. return _SUCCESS;
  2697. RTW_INFO(FUNC_ADPT_FMT" - Start to Disconnect\n", FUNC_ADPT_ARG(padapter));
  2698. #ifdef CONFIG_P2P
  2699. if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
  2700. _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
  2701. _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
  2702. }
  2703. #endif /* CONFIG_P2P */
  2704. reason = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN));
  2705. rtw_lock_rx_suspend_timeout(8000);
  2706. #ifdef CONFIG_AP_MODE
  2707. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
  2708. _irqL irqL;
  2709. struct sta_info *psta;
  2710. struct sta_priv *pstapriv = &padapter->stapriv;
  2711. /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  2712. /* rtw_free_stainfo(padapter, psta); */
  2713. /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  2714. RTW_PRINT(FUNC_ADPT_FMT" reason=%u, ta=%pM\n"
  2715. , FUNC_ADPT_ARG(padapter), reason, get_addr2_ptr(pframe));
  2716. psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  2717. if (psta) {
  2718. u8 updated = _FALSE;
  2719. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2720. if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
  2721. rtw_list_delete(&psta->asoc_list);
  2722. pstapriv->asoc_list_cnt--;
  2723. updated = ap_free_sta(padapter, psta, _FALSE, reason, _TRUE);
  2724. }
  2725. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2726. associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
  2727. }
  2728. return _SUCCESS;
  2729. } else
  2730. #endif
  2731. {
  2732. int ignore_received_deauth = 0;
  2733. /* Commented by Albert 20130604 */
  2734. /* Before sending the auth frame to start the STA/GC mode connection with AP/GO, */
  2735. /* we will send the deauth first. */
  2736. /* However, the Win8.1 with BRCM Wi-Fi will send the deauth with reason code 6 to us after receieving our deauth. */
  2737. /* Added the following code to avoid this case. */
  2738. if ((pmlmeinfo->state & WIFI_FW_AUTH_STATE) ||
  2739. (pmlmeinfo->state & WIFI_FW_ASSOC_STATE)) {
  2740. if (reason == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA)
  2741. ignore_received_deauth = 1;
  2742. else if (WLAN_REASON_PREV_AUTH_NOT_VALID == reason) {
  2743. /* TODO: 802.11r */
  2744. ignore_received_deauth = 1;
  2745. }
  2746. }
  2747. RTW_PRINT(FUNC_ADPT_FMT" reason=%u, ta=%pM, ignore=%d\n"
  2748. , FUNC_ADPT_ARG(padapter), reason, get_addr2_ptr(pframe), ignore_received_deauth);
  2749. if (0 == ignore_received_deauth)
  2750. receive_disconnect(padapter, get_addr2_ptr(pframe), reason, _FALSE);
  2751. }
  2752. pmlmepriv->LinkDetectInfo.bBusyTraffic = _FALSE;
  2753. return _SUCCESS;
  2754. }
  2755. unsigned int OnDisassoc(_adapter *padapter, union recv_frame *precv_frame)
  2756. {
  2757. unsigned short reason;
  2758. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2759. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2760. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2761. u8 *pframe = precv_frame->u.hdr.rx_data;
  2762. #ifdef CONFIG_P2P
  2763. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  2764. #endif /* CONFIG_P2P */
  2765. /* check A3 */
  2766. if (!(_rtw_memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
  2767. return _SUCCESS;
  2768. RTW_INFO(FUNC_ADPT_FMT" - Start to Disconnect\n", FUNC_ADPT_ARG(padapter));
  2769. #ifdef CONFIG_P2P
  2770. if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
  2771. _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
  2772. _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
  2773. }
  2774. #endif /* CONFIG_P2P */
  2775. reason = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN));
  2776. rtw_lock_rx_suspend_timeout(8000);
  2777. #ifdef CONFIG_AP_MODE
  2778. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
  2779. _irqL irqL;
  2780. struct sta_info *psta;
  2781. struct sta_priv *pstapriv = &padapter->stapriv;
  2782. /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  2783. /* rtw_free_stainfo(padapter, psta); */
  2784. /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  2785. RTW_PRINT(FUNC_ADPT_FMT" reason=%u, ta=%pM\n"
  2786. , FUNC_ADPT_ARG(padapter), reason, get_addr2_ptr(pframe));
  2787. psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  2788. if (psta) {
  2789. u8 updated = _FALSE;
  2790. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2791. if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
  2792. rtw_list_delete(&psta->asoc_list);
  2793. pstapriv->asoc_list_cnt--;
  2794. updated = ap_free_sta(padapter, psta, _FALSE, reason, _TRUE);
  2795. }
  2796. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2797. associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
  2798. }
  2799. return _SUCCESS;
  2800. } else
  2801. #endif
  2802. {
  2803. RTW_PRINT(FUNC_ADPT_FMT" reason=%u, ta=%pM\n"
  2804. , FUNC_ADPT_ARG(padapter), reason, get_addr2_ptr(pframe));
  2805. receive_disconnect(padapter, get_addr2_ptr(pframe), reason, _FALSE);
  2806. }
  2807. pmlmepriv->LinkDetectInfo.bBusyTraffic = _FALSE;
  2808. return _SUCCESS;
  2809. }
  2810. unsigned int OnAtim(_adapter *padapter, union recv_frame *precv_frame)
  2811. {
  2812. RTW_INFO("%s\n", __FUNCTION__);
  2813. return _SUCCESS;
  2814. }
  2815. unsigned int on_action_spct_ch_switch(_adapter *padapter, struct sta_info *psta, u8 *ies, uint ies_len)
  2816. {
  2817. unsigned int ret = _FAIL;
  2818. struct mlme_ext_priv *mlmeext = &padapter->mlmeextpriv;
  2819. struct mlme_ext_info *pmlmeinfo = &(mlmeext->mlmext_info);
  2820. if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) {
  2821. ret = _SUCCESS;
  2822. goto exit;
  2823. }
  2824. if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) {
  2825. int ch_switch_mode = -1, ch = -1, ch_switch_cnt = -1;
  2826. int ch_offset = -1;
  2827. u8 bwmode;
  2828. struct ieee80211_info_element *ie;
  2829. RTW_INFO(FUNC_NDEV_FMT" from "MAC_FMT"\n",
  2830. FUNC_NDEV_ARG(padapter->pnetdev), MAC_ARG(psta->hwaddr));
  2831. for_each_ie(ie, ies, ies_len) {
  2832. if (ie->id == WLAN_EID_CHANNEL_SWITCH) {
  2833. ch_switch_mode = ie->data[0];
  2834. ch = ie->data[1];
  2835. ch_switch_cnt = ie->data[2];
  2836. RTW_INFO("ch_switch_mode:%d, ch:%d, ch_switch_cnt:%d\n",
  2837. ch_switch_mode, ch, ch_switch_cnt);
  2838. } else if (ie->id == WLAN_EID_SECONDARY_CHANNEL_OFFSET) {
  2839. ch_offset = secondary_ch_offset_to_hal_ch_offset(ie->data[0]);
  2840. RTW_INFO("ch_offset:%d\n", ch_offset);
  2841. }
  2842. }
  2843. if (ch == -1)
  2844. return _SUCCESS;
  2845. if (ch_offset == -1)
  2846. bwmode = mlmeext->cur_bwmode;
  2847. else
  2848. bwmode = (ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) ?
  2849. CHANNEL_WIDTH_20 : CHANNEL_WIDTH_40;
  2850. ch_offset = (ch_offset == -1) ? mlmeext->cur_ch_offset : ch_offset;
  2851. /* todo:
  2852. * 1. the decision of channel switching
  2853. * 2. things after channel switching
  2854. */
  2855. ret = rtw_set_ch_cmd(padapter, ch, bwmode, ch_offset, _TRUE);
  2856. }
  2857. exit:
  2858. return ret;
  2859. }
  2860. unsigned int on_action_spct(_adapter *padapter, union recv_frame *precv_frame)
  2861. {
  2862. unsigned int ret = _FAIL;
  2863. struct sta_info *psta = NULL;
  2864. struct sta_priv *pstapriv = &padapter->stapriv;
  2865. u8 *pframe = precv_frame->u.hdr.rx_data;
  2866. uint frame_len = precv_frame->u.hdr.len;
  2867. u8 *frame_body = (u8 *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
  2868. u8 category;
  2869. u8 action;
  2870. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
  2871. psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  2872. if (!psta)
  2873. goto exit;
  2874. category = frame_body[0];
  2875. if (category != RTW_WLAN_CATEGORY_SPECTRUM_MGMT)
  2876. goto exit;
  2877. action = frame_body[1];
  2878. switch (action) {
  2879. case RTW_WLAN_ACTION_SPCT_MSR_REQ:
  2880. case RTW_WLAN_ACTION_SPCT_MSR_RPRT:
  2881. case RTW_WLAN_ACTION_SPCT_TPC_REQ:
  2882. case RTW_WLAN_ACTION_SPCT_TPC_RPRT:
  2883. break;
  2884. case RTW_WLAN_ACTION_SPCT_CHL_SWITCH:
  2885. #ifdef CONFIG_SPCT_CH_SWITCH
  2886. ret = on_action_spct_ch_switch(padapter, psta, &frame_body[2],
  2887. frame_len - (frame_body - pframe) - 2);
  2888. #endif
  2889. break;
  2890. default:
  2891. break;
  2892. }
  2893. exit:
  2894. return ret;
  2895. }
  2896. unsigned int OnAction_qos(_adapter *padapter, union recv_frame *precv_frame)
  2897. {
  2898. return _SUCCESS;
  2899. }
  2900. unsigned int OnAction_dls(_adapter *padapter, union recv_frame *precv_frame)
  2901. {
  2902. return _SUCCESS;
  2903. }
  2904. #ifdef CONFIG_RTW_WNM
  2905. unsigned int on_action_wnm(_adapter *adapter, union recv_frame *rframe)
  2906. {
  2907. unsigned int ret = _FAIL;
  2908. struct sta_info *sta = NULL;
  2909. struct sta_priv *stapriv = &adapter->stapriv;
  2910. u8 *frame = rframe->u.hdr.rx_data;
  2911. uint frame_len = rframe->u.hdr.len;
  2912. u8 *frame_body = (u8 *)(frame + sizeof(struct rtw_ieee80211_hdr_3addr));
  2913. u8 category;
  2914. u8 action;
  2915. int cnt = 0;
  2916. char msg[16];
  2917. sta = rtw_get_stainfo(stapriv, get_addr2_ptr(frame));
  2918. if (!sta)
  2919. goto exit;
  2920. category = frame_body[0];
  2921. if (category != RTW_WLAN_CATEGORY_WNM)
  2922. goto exit;
  2923. action = frame_body[1];
  2924. switch (action) {
  2925. default:
  2926. #ifdef CONFIG_IOCTL_CFG80211
  2927. cnt += sprintf((msg + cnt), "ACT_WNM %u", action);
  2928. rtw_cfg80211_rx_action(adapter, rframe, msg);
  2929. #endif
  2930. ret = _SUCCESS;
  2931. break;
  2932. }
  2933. exit:
  2934. return ret;
  2935. }
  2936. #endif /* CONFIG_RTW_WNM */
  2937. /**
  2938. * rtw_rx_ampdu_size - Get the target RX AMPDU buffer size for the specific @adapter
  2939. * @adapter: the adapter to get target RX AMPDU buffer size
  2940. *
  2941. * Returns: the target RX AMPDU buffer size
  2942. */
  2943. u8 rtw_rx_ampdu_size(_adapter *adapter)
  2944. {
  2945. u8 size;
  2946. HT_CAP_AMPDU_FACTOR max_rx_ampdu_factor;
  2947. #ifdef CONFIG_BT_COEXIST
  2948. if (rtw_btcoex_IsBTCoexCtrlAMPDUSize(adapter) == _TRUE) {
  2949. size = rtw_btcoex_GetAMPDUSize(adapter);
  2950. goto exit;
  2951. }
  2952. #endif
  2953. /* for scan */
  2954. if (!mlmeext_chk_scan_state(&adapter->mlmeextpriv, SCAN_DISABLE)
  2955. && !mlmeext_chk_scan_state(&adapter->mlmeextpriv, SCAN_COMPLETE)
  2956. && adapter->mlmeextpriv.sitesurvey_res.rx_ampdu_size != RX_AMPDU_SIZE_INVALID
  2957. ) {
  2958. size = adapter->mlmeextpriv.sitesurvey_res.rx_ampdu_size;
  2959. goto exit;
  2960. }
  2961. /* default value based on max_rx_ampdu_factor */
  2962. if (adapter->driver_rx_ampdu_factor != 0xFF)
  2963. max_rx_ampdu_factor = (HT_CAP_AMPDU_FACTOR)adapter->driver_rx_ampdu_factor;
  2964. else
  2965. rtw_hal_get_def_var(adapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
  2966. /* In Maximum A-MPDU Length Exponent subfield of A-MPDU Parameters field of HT Capabilities element,
  2967. the unit of max_rx_ampdu_factor are octets. 8K, 16K, 32K, 64K is right.
  2968. But the buffer size subfield of Block Ack Parameter Set field in ADDBA action frame indicates
  2969. the number of buffers available for this particular TID. Each buffer is equal to max. size of
  2970. MSDU or AMSDU.
  2971. The size variable means how many MSDUs or AMSDUs, it's not Kbytes.
  2972. */
  2973. if (MAX_AMPDU_FACTOR_64K == max_rx_ampdu_factor)
  2974. size = 64;
  2975. else if (MAX_AMPDU_FACTOR_32K == max_rx_ampdu_factor)
  2976. size = 32;
  2977. else if (MAX_AMPDU_FACTOR_16K == max_rx_ampdu_factor)
  2978. size = 16;
  2979. else if (MAX_AMPDU_FACTOR_8K == max_rx_ampdu_factor)
  2980. size = 8;
  2981. else
  2982. size = 64;
  2983. exit:
  2984. if (size > 127)
  2985. size = 127;
  2986. return size;
  2987. }
  2988. /**
  2989. * rtw_rx_ampdu_is_accept - Get the permission if RX AMPDU should be set up for the specific @adapter
  2990. * @adapter: the adapter to get the permission if RX AMPDU should be set up
  2991. *
  2992. * Returns: accept or not
  2993. */
  2994. bool rtw_rx_ampdu_is_accept(_adapter *adapter)
  2995. {
  2996. bool accept;
  2997. if (adapter->fix_rx_ampdu_accept != RX_AMPDU_ACCEPT_INVALID) {
  2998. accept = adapter->fix_rx_ampdu_accept;
  2999. goto exit;
  3000. }
  3001. #ifdef CONFIG_BT_COEXIST
  3002. if (rtw_btcoex_IsBTCoexRejectAMPDU(adapter) == _TRUE) {
  3003. accept = _FALSE;
  3004. goto exit;
  3005. }
  3006. #endif
  3007. /* for scan */
  3008. if (!mlmeext_chk_scan_state(&adapter->mlmeextpriv, SCAN_DISABLE)
  3009. && !mlmeext_chk_scan_state(&adapter->mlmeextpriv, SCAN_COMPLETE)
  3010. && adapter->mlmeextpriv.sitesurvey_res.rx_ampdu_accept != RX_AMPDU_ACCEPT_INVALID
  3011. ) {
  3012. accept = adapter->mlmeextpriv.sitesurvey_res.rx_ampdu_accept;
  3013. goto exit;
  3014. }
  3015. /* default value for other cases */
  3016. accept = adapter->mlmeextpriv.mlmext_info.bAcceptAddbaReq;
  3017. exit:
  3018. return accept;
  3019. }
  3020. /**
  3021. * rtw_rx_ampdu_set_size - Set the target RX AMPDU buffer size for the specific @adapter and specific @reason
  3022. * @adapter: the adapter to set target RX AMPDU buffer size
  3023. * @size: the target RX AMPDU buffer size to set
  3024. * @reason: reason for the target RX AMPDU buffer size setting
  3025. *
  3026. * Returns: whether the target RX AMPDU buffer size is changed
  3027. */
  3028. bool rtw_rx_ampdu_set_size(_adapter *adapter, u8 size, u8 reason)
  3029. {
  3030. bool is_adj = _FALSE;
  3031. struct mlme_ext_priv *mlmeext;
  3032. struct mlme_ext_info *mlmeinfo;
  3033. mlmeext = &adapter->mlmeextpriv;
  3034. mlmeinfo = &mlmeext->mlmext_info;
  3035. if (reason == RX_AMPDU_DRV_FIXED) {
  3036. if (adapter->fix_rx_ampdu_size != size) {
  3037. adapter->fix_rx_ampdu_size = size;
  3038. is_adj = _TRUE;
  3039. RTW_INFO(FUNC_ADPT_FMT" fix_rx_ampdu_size:%u\n", FUNC_ADPT_ARG(adapter), size);
  3040. }
  3041. } else if (reason == RX_AMPDU_DRV_SCAN) {
  3042. struct ss_res *ss = &adapter->mlmeextpriv.sitesurvey_res;
  3043. if (ss->rx_ampdu_size != size) {
  3044. ss->rx_ampdu_size = size;
  3045. is_adj = _TRUE;
  3046. RTW_INFO(FUNC_ADPT_FMT" ss.rx_ampdu_size:%u\n", FUNC_ADPT_ARG(adapter), size);
  3047. }
  3048. }
  3049. return is_adj;
  3050. }
  3051. /**
  3052. * rtw_rx_ampdu_set_accept - Set the permission if RX AMPDU should be set up for the specific @adapter and specific @reason
  3053. * @adapter: the adapter to set if RX AMPDU should be set up
  3054. * @accept: if RX AMPDU should be set up
  3055. * @reason: reason for the permission if RX AMPDU should be set up
  3056. *
  3057. * Returns: whether the permission if RX AMPDU should be set up is changed
  3058. */
  3059. bool rtw_rx_ampdu_set_accept(_adapter *adapter, u8 accept, u8 reason)
  3060. {
  3061. bool is_adj = _FALSE;
  3062. struct mlme_ext_priv *mlmeext;
  3063. struct mlme_ext_info *mlmeinfo;
  3064. mlmeext = &adapter->mlmeextpriv;
  3065. mlmeinfo = &mlmeext->mlmext_info;
  3066. if (reason == RX_AMPDU_DRV_FIXED) {
  3067. if (adapter->fix_rx_ampdu_accept != accept) {
  3068. adapter->fix_rx_ampdu_accept = accept;
  3069. is_adj = _TRUE;
  3070. RTW_INFO(FUNC_ADPT_FMT" fix_rx_ampdu_accept:%u\n", FUNC_ADPT_ARG(adapter), accept);
  3071. }
  3072. } else if (reason == RX_AMPDU_DRV_SCAN) {
  3073. if (adapter->mlmeextpriv.sitesurvey_res.rx_ampdu_accept != accept) {
  3074. adapter->mlmeextpriv.sitesurvey_res.rx_ampdu_accept = accept;
  3075. is_adj = _TRUE;
  3076. RTW_INFO(FUNC_ADPT_FMT" ss.rx_ampdu_accept:%u\n", FUNC_ADPT_ARG(adapter), accept);
  3077. }
  3078. }
  3079. return is_adj;
  3080. }
  3081. /**
  3082. * rx_ampdu_apply_sta_tid - Apply RX AMPDU setting to the specific @sta and @tid
  3083. * @adapter: the adapter to which @sta belongs
  3084. * @sta: the sta to be checked
  3085. * @tid: the tid to be checked
  3086. * @accept: the target permission if RX AMPDU should be set up
  3087. * @size: the target RX AMPDU buffer size
  3088. *
  3089. * Returns:
  3090. * 0: no canceled
  3091. * 1: canceled by no permission
  3092. * 2: canceled by different buffer size
  3093. * 3: canceled by potential mismatched status
  3094. *
  3095. * Blocking function, may sleep
  3096. */
  3097. u8 rx_ampdu_apply_sta_tid(_adapter *adapter, struct sta_info *sta, u8 tid, u8 accept, u8 size)
  3098. {
  3099. u8 ret = 0;
  3100. struct recv_reorder_ctrl *reorder_ctl = &sta->recvreorder_ctrl[tid];
  3101. if (reorder_ctl->enable == _FALSE) {
  3102. if (reorder_ctl->ampdu_size != RX_AMPDU_SIZE_INVALID) {
  3103. send_delba_sta_tid_wait_ack(adapter, 0, sta, tid, 1);
  3104. ret = 3;
  3105. }
  3106. goto exit;
  3107. }
  3108. if (accept == _FALSE) {
  3109. send_delba_sta_tid_wait_ack(adapter, 0, sta, tid, 0);
  3110. ret = 1;
  3111. } else if (reorder_ctl->ampdu_size != size) {
  3112. send_delba_sta_tid_wait_ack(adapter, 0, sta, tid, 0);
  3113. ret = 2;
  3114. }
  3115. exit:
  3116. return ret;
  3117. }
  3118. u8 rx_ampdu_size_sta_limit(_adapter *adapter, struct sta_info *sta)
  3119. {
  3120. u8 sz_limit = 0xFF;
  3121. #ifdef CONFIG_80211N_HT
  3122. struct registry_priv *regsty = adapter_to_regsty(adapter);
  3123. struct mlme_priv *mlme = &adapter->mlmepriv;
  3124. struct mlme_ext_info *mlmeinfo = &adapter->mlmeextpriv.mlmext_info;
  3125. s8 nss = -1;
  3126. u8 bw = rtw_min(sta->bw_mode, adapter->mlmeextpriv.cur_bwmode);
  3127. #ifdef CONFIG_80211AC_VHT
  3128. if (is_supported_vht(sta->wireless_mode)) {
  3129. nss = rtw_min(rtw_vht_mcsmap_to_nss(mlme->vhtpriv.vht_mcs_map)
  3130. , rtw_vht_mcsmap_to_nss(sta->vhtpriv.vht_mcs_map));
  3131. } else
  3132. #endif
  3133. if (is_supported_ht(sta->wireless_mode)) {
  3134. nss = rtw_min(rtw_ht_mcsset_to_nss(mlmeinfo->HT_caps.u.HT_cap_element.MCS_rate)
  3135. , rtw_ht_mcsset_to_nss(sta->htpriv.ht_cap.supp_mcs_set));
  3136. }
  3137. if (nss >= 1)
  3138. sz_limit = regsty->rx_ampdu_sz_limit_by_nss_bw[nss - 1][bw];
  3139. #endif /* CONFIG_80211N_HT */
  3140. return sz_limit;
  3141. }
  3142. /**
  3143. * rx_ampdu_apply_sta - Apply RX AMPDU setting to the specific @sta
  3144. * @adapter: the adapter to which @sta belongs
  3145. * @sta: the sta to be checked
  3146. * @accept: the target permission if RX AMPDU should be set up
  3147. * @size: the target RX AMPDU buffer size
  3148. *
  3149. * Returns: number of the RX AMPDU assciation canceled for applying current target setting
  3150. *
  3151. * Blocking function, may sleep
  3152. */
  3153. u8 rx_ampdu_apply_sta(_adapter *adapter, struct sta_info *sta, u8 accept, u8 size)
  3154. {
  3155. u8 change_cnt = 0;
  3156. int i;
  3157. for (i = 0; i < TID_NUM; i++) {
  3158. if (rx_ampdu_apply_sta_tid(adapter, sta, i, accept, size) != 0)
  3159. change_cnt++;
  3160. }
  3161. return change_cnt;
  3162. }
  3163. /**
  3164. * rtw_rx_ampdu_apply - Apply the current target RX AMPDU setting for the specific @adapter
  3165. * @adapter: the adapter to be applied
  3166. *
  3167. * Returns: number of the RX AMPDU assciation canceled for applying current target setting
  3168. */
  3169. u16 rtw_rx_ampdu_apply(_adapter *adapter)
  3170. {
  3171. u16 adj_cnt = 0;
  3172. struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
  3173. struct sta_info *sta;
  3174. u8 accept = rtw_rx_ampdu_is_accept(adapter);
  3175. u8 size;
  3176. if (adapter->fix_rx_ampdu_size != RX_AMPDU_SIZE_INVALID)
  3177. size = adapter->fix_rx_ampdu_size;
  3178. else
  3179. size = rtw_rx_ampdu_size(adapter);
  3180. if (mlmeext_msr(mlmeext) == WIFI_FW_STATION_STATE) {
  3181. sta = rtw_get_stainfo(&adapter->stapriv, get_bssid(&adapter->mlmepriv));
  3182. if (sta) {
  3183. u8 sta_size = size;
  3184. if (adapter->fix_rx_ampdu_size == RX_AMPDU_SIZE_INVALID)
  3185. sta_size = rtw_min(size, rx_ampdu_size_sta_limit(adapter, sta));
  3186. adj_cnt += rx_ampdu_apply_sta(adapter, sta, accept, sta_size);
  3187. }
  3188. } else if (mlmeext_msr(mlmeext) == WIFI_FW_AP_STATE) {
  3189. _irqL irqL;
  3190. _list *phead, *plist;
  3191. u8 peer_num = 0;
  3192. char peers[NUM_STA];
  3193. struct sta_priv *pstapriv = &adapter->stapriv;
  3194. int i;
  3195. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3196. phead = &pstapriv->asoc_list;
  3197. plist = get_next(phead);
  3198. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  3199. int stainfo_offset;
  3200. sta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  3201. plist = get_next(plist);
  3202. stainfo_offset = rtw_stainfo_offset(pstapriv, sta);
  3203. if (stainfo_offset_valid(stainfo_offset))
  3204. peers[peer_num++] = stainfo_offset;
  3205. }
  3206. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3207. for (i = 0; i < peer_num; i++) {
  3208. sta = rtw_get_stainfo_by_offset(pstapriv, peers[i]);
  3209. if (sta) {
  3210. u8 sta_size = size;
  3211. if (adapter->fix_rx_ampdu_size == RX_AMPDU_SIZE_INVALID)
  3212. sta_size = rtw_min(size, rx_ampdu_size_sta_limit(adapter, sta));
  3213. adj_cnt += rx_ampdu_apply_sta(adapter, sta, accept, sta_size);
  3214. }
  3215. }
  3216. }
  3217. return adj_cnt;
  3218. }
  3219. unsigned int OnAction_back(_adapter *padapter, union recv_frame *precv_frame)
  3220. {
  3221. u8 *addr;
  3222. struct sta_info *psta = NULL;
  3223. struct recv_reorder_ctrl *preorder_ctrl;
  3224. unsigned char *frame_body;
  3225. unsigned char category, action;
  3226. unsigned short tid, status, reason_code = 0;
  3227. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3228. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3229. u8 *pframe = precv_frame->u.hdr.rx_data;
  3230. struct sta_priv *pstapriv = &padapter->stapriv;
  3231. struct registry_priv *pregpriv = &padapter->registrypriv;
  3232. #ifdef CONFIG_80211N_HT
  3233. RTW_INFO("%s\n", __FUNCTION__);
  3234. /* check RA matches or not */
  3235. if (!_rtw_memcmp(adapter_mac_addr(padapter), GetAddr1Ptr(pframe), ETH_ALEN))
  3236. return _SUCCESS;
  3237. #if 0
  3238. /* check A1 matches or not */
  3239. if (!_rtw_memcmp(adapter_mac_addr(padapter), get_da(pframe), ETH_ALEN))
  3240. return _SUCCESS;
  3241. #endif
  3242. if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
  3243. if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
  3244. return _SUCCESS;
  3245. addr = get_addr2_ptr(pframe);
  3246. psta = rtw_get_stainfo(pstapriv, addr);
  3247. if (psta == NULL)
  3248. return _SUCCESS;
  3249. frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
  3250. category = frame_body[0];
  3251. if (category == RTW_WLAN_CATEGORY_BACK) { /* representing Block Ack */
  3252. #ifdef CONFIG_TDLS
  3253. if ((psta->tdls_sta_state & TDLS_LINKED_STATE) &&
  3254. (psta->htpriv.ht_option == _TRUE) &&
  3255. (psta->htpriv.ampdu_enable == _TRUE))
  3256. RTW_INFO("Recv [%s] from direc link\n", __FUNCTION__);
  3257. else
  3258. #endif /* CONFIG_TDLS */
  3259. if (!pmlmeinfo->HT_enable)
  3260. return _SUCCESS;
  3261. action = frame_body[1];
  3262. RTW_INFO("%s, action=%d\n", __FUNCTION__, action);
  3263. switch (action) {
  3264. case RTW_WLAN_ACTION_ADDBA_REQ: /* ADDBA request */
  3265. _rtw_memcpy(&(pmlmeinfo->ADDBA_req), &(frame_body[2]), sizeof(struct ADDBA_request));
  3266. /* process_addba_req(padapter, (u8*)&(pmlmeinfo->ADDBA_req), GetAddr3Ptr(pframe)); */
  3267. process_addba_req(padapter, (u8 *)&(pmlmeinfo->ADDBA_req), addr);
  3268. break;
  3269. case RTW_WLAN_ACTION_ADDBA_RESP: /* ADDBA response */
  3270. /* status = frame_body[3] | (frame_body[4] << 8); */ /* endian issue */
  3271. status = RTW_GET_LE16(&frame_body[3]);
  3272. tid = ((frame_body[5] >> 2) & 0x7);
  3273. if (status == 0) {
  3274. /* successful */
  3275. RTW_INFO("agg_enable for TID=%d\n", tid);
  3276. psta->htpriv.agg_enable_bitmap |= 1 << tid;
  3277. psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
  3278. /* amsdu in ampdu */
  3279. if (pregpriv->tx_ampdu_amsdu == 0)
  3280. psta->htpriv.tx_amsdu_enable = _FALSE;
  3281. else if (pregpriv->tx_ampdu_amsdu == 1)
  3282. psta->htpriv.tx_amsdu_enable = _TRUE;
  3283. else {
  3284. if (frame_body[5] & 1)
  3285. psta->htpriv.tx_amsdu_enable = _TRUE;
  3286. }
  3287. } else
  3288. psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
  3289. if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
  3290. RTW_INFO("%s alive check - rx ADDBA response\n", __func__);
  3291. psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
  3292. psta->expire_to = pstapriv->expire_to;
  3293. psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
  3294. }
  3295. /* RTW_INFO("marc: ADDBA RSP: %x\n", pmlmeinfo->agg_enable_bitmap); */
  3296. break;
  3297. case RTW_WLAN_ACTION_DELBA: /* DELBA */
  3298. if ((frame_body[3] & BIT(3)) == 0) {
  3299. psta->htpriv.agg_enable_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
  3300. psta->htpriv.candidate_tid_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
  3301. /* reason_code = frame_body[4] | (frame_body[5] << 8); */
  3302. reason_code = RTW_GET_LE16(&frame_body[4]);
  3303. } else if ((frame_body[3] & BIT(3)) == BIT(3)) {
  3304. tid = (frame_body[3] >> 4) & 0x0F;
  3305. preorder_ctrl = &psta->recvreorder_ctrl[tid];
  3306. preorder_ctrl->enable = _FALSE;
  3307. preorder_ctrl->ampdu_size = RX_AMPDU_SIZE_INVALID;
  3308. }
  3309. RTW_INFO("%s(): DELBA: %x(%x)\n", __FUNCTION__, pmlmeinfo->agg_enable_bitmap, reason_code);
  3310. /* todo: how to notify the host while receiving DELETE BA */
  3311. break;
  3312. default:
  3313. break;
  3314. }
  3315. }
  3316. #endif /* CONFIG_80211N_HT */
  3317. return _SUCCESS;
  3318. }
  3319. #ifdef CONFIG_P2P
  3320. static int get_reg_classes_full_count(struct p2p_channels channel_list)
  3321. {
  3322. int cnt = 0;
  3323. int i;
  3324. for (i = 0; i < channel_list.reg_classes; i++)
  3325. cnt += channel_list.reg_class[i].channels;
  3326. return cnt;
  3327. }
  3328. void issue_p2p_GO_request(_adapter *padapter, u8 *raddr)
  3329. {
  3330. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  3331. u8 action = P2P_PUB_ACTION_ACTION;
  3332. u32 p2poui = cpu_to_be32(P2POUI);
  3333. u8 oui_subtype = P2P_GO_NEGO_REQ;
  3334. u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
  3335. u8 wpsielen = 0, p2pielen = 0, i;
  3336. u8 channel_cnt_24g = 0, channel_cnt_5gl = 0, channel_cnt_5gh = 0;
  3337. u16 len_channellist_attr = 0;
  3338. #ifdef CONFIG_WFD
  3339. u32 wfdielen = 0;
  3340. #endif
  3341. struct xmit_frame *pmgntframe;
  3342. struct pkt_attrib *pattrib;
  3343. unsigned char *pframe;
  3344. struct rtw_ieee80211_hdr *pwlanhdr;
  3345. unsigned short *fctrl;
  3346. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  3347. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3348. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3349. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3350. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  3351. if (pmgntframe == NULL)
  3352. return;
  3353. RTW_INFO("[%s] In\n", __FUNCTION__);
  3354. /* update attribute */
  3355. pattrib = &pmgntframe->attrib;
  3356. update_mgntframe_attrib(padapter, pattrib);
  3357. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  3358. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  3359. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  3360. fctrl = &(pwlanhdr->frame_ctl);
  3361. *(fctrl) = 0;
  3362. _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
  3363. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  3364. _rtw_memcpy(pwlanhdr->addr3, adapter_mac_addr(padapter), ETH_ALEN);
  3365. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  3366. pmlmeext->mgnt_seq++;
  3367. set_frame_sub_type(pframe, WIFI_ACTION);
  3368. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  3369. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  3370. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  3371. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  3372. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  3373. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  3374. pwdinfo->negotiation_dialog_token = 1; /* Initialize the dialog value */
  3375. pframe = rtw_set_fixed_ie(pframe, 1, &pwdinfo->negotiation_dialog_token, &(pattrib->pktlen));
  3376. /* WPS Section */
  3377. wpsielen = 0;
  3378. /* WPS OUI */
  3379. *(u32 *)(wpsie) = cpu_to_be32(WPSOUI);
  3380. wpsielen += 4;
  3381. /* WPS version */
  3382. /* Type: */
  3383. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
  3384. wpsielen += 2;
  3385. /* Length: */
  3386. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  3387. wpsielen += 2;
  3388. /* Value: */
  3389. wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
  3390. /* Device Password ID */
  3391. /* Type: */
  3392. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
  3393. wpsielen += 2;
  3394. /* Length: */
  3395. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
  3396. wpsielen += 2;
  3397. /* Value: */
  3398. if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN)
  3399. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_USER_SPEC);
  3400. else if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN)
  3401. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC);
  3402. else if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PBC)
  3403. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_PBC);
  3404. wpsielen += 2;
  3405. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen);
  3406. /* P2P IE Section. */
  3407. /* P2P OUI */
  3408. p2pielen = 0;
  3409. p2pie[p2pielen++] = 0x50;
  3410. p2pie[p2pielen++] = 0x6F;
  3411. p2pie[p2pielen++] = 0x9A;
  3412. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  3413. /* Commented by Albert 20110306 */
  3414. /* According to the P2P Specification, the group negoitation request frame should contain 9 P2P attributes */
  3415. /* 1. P2P Capability */
  3416. /* 2. Group Owner Intent */
  3417. /* 3. Configuration Timeout */
  3418. /* 4. Listen Channel */
  3419. /* 5. Extended Listen Timing */
  3420. /* 6. Intended P2P Interface Address */
  3421. /* 7. Channel List */
  3422. /* 8. P2P Device Info */
  3423. /* 9. Operating Channel */
  3424. /* P2P Capability */
  3425. /* Type: */
  3426. p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
  3427. /* Length: */
  3428. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
  3429. p2pielen += 2;
  3430. /* Value: */
  3431. /* Device Capability Bitmap, 1 byte */
  3432. p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
  3433. /* Group Capability Bitmap, 1 byte */
  3434. if (pwdinfo->persistent_supported)
  3435. p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
  3436. else
  3437. p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
  3438. /* Group Owner Intent */
  3439. /* Type: */
  3440. p2pie[p2pielen++] = P2P_ATTR_GO_INTENT;
  3441. /* Length: */
  3442. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
  3443. p2pielen += 2;
  3444. /* Value: */
  3445. /* Todo the tie breaker bit. */
  3446. p2pie[p2pielen++] = ((pwdinfo->intent << 1) & 0xFE);
  3447. /* Configuration Timeout */
  3448. /* Type: */
  3449. p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
  3450. /* Length: */
  3451. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
  3452. p2pielen += 2;
  3453. /* Value: */
  3454. p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
  3455. p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
  3456. /* Listen Channel */
  3457. /* Type: */
  3458. p2pie[p2pielen++] = P2P_ATTR_LISTEN_CH;
  3459. /* Length: */
  3460. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
  3461. p2pielen += 2;
  3462. /* Value: */
  3463. /* Country String */
  3464. p2pie[p2pielen++] = 'X';
  3465. p2pie[p2pielen++] = 'X';
  3466. /* The third byte should be set to 0x04. */
  3467. /* Described in the "Operating Channel Attribute" section. */
  3468. p2pie[p2pielen++] = 0x04;
  3469. /* Operating Class */
  3470. p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
  3471. /* Channel Number */
  3472. p2pie[p2pielen++] = pwdinfo->listen_channel; /* listening channel number */
  3473. /* Extended Listen Timing ATTR */
  3474. /* Type: */
  3475. p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
  3476. /* Length: */
  3477. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
  3478. p2pielen += 2;
  3479. /* Value: */
  3480. /* Availability Period */
  3481. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
  3482. p2pielen += 2;
  3483. /* Availability Interval */
  3484. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
  3485. p2pielen += 2;
  3486. /* Intended P2P Interface Address */
  3487. /* Type: */
  3488. p2pie[p2pielen++] = P2P_ATTR_INTENDED_IF_ADDR;
  3489. /* Length: */
  3490. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
  3491. p2pielen += 2;
  3492. /* Value: */
  3493. _rtw_memcpy(p2pie + p2pielen, adapter_mac_addr(padapter), ETH_ALEN);
  3494. p2pielen += ETH_ALEN;
  3495. /* Channel List */
  3496. /* Type: */
  3497. p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
  3498. /* Length: */
  3499. /* Country String(3) */
  3500. /* + ( Operating Class (1) + Number of Channels(1) ) * Operation Classes (?) */
  3501. /* + number of channels in all classes */
  3502. len_channellist_attr = 3
  3503. + (1 + 1) * (u16)(pmlmeext->channel_list.reg_classes)
  3504. + get_reg_classes_full_count(pmlmeext->channel_list);
  3505. #ifdef CONFIG_CONCURRENT_MODE
  3506. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  3507. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(5 + 1);
  3508. else
  3509. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
  3510. #else
  3511. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
  3512. #endif
  3513. p2pielen += 2;
  3514. /* Value: */
  3515. /* Country String */
  3516. p2pie[p2pielen++] = 'X';
  3517. p2pie[p2pielen++] = 'X';
  3518. /* The third byte should be set to 0x04. */
  3519. /* Described in the "Operating Channel Attribute" section. */
  3520. p2pie[p2pielen++] = 0x04;
  3521. /* Channel Entry List */
  3522. #ifdef CONFIG_CONCURRENT_MODE
  3523. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  3524. u8 union_ch = rtw_mi_get_union_chan(padapter);
  3525. /* Operating Class */
  3526. if (union_ch > 14) {
  3527. if (union_ch >= 149)
  3528. p2pie[p2pielen++] = 0x7c;
  3529. else
  3530. p2pie[p2pielen++] = 0x73;
  3531. } else
  3532. p2pie[p2pielen++] = 0x51;
  3533. /* Number of Channels */
  3534. /* Just support 1 channel and this channel is AP's channel */
  3535. p2pie[p2pielen++] = 1;
  3536. /* Channel List */
  3537. p2pie[p2pielen++] = union_ch;
  3538. } else {
  3539. int i, j;
  3540. for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
  3541. /* Operating Class */
  3542. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
  3543. /* Number of Channels */
  3544. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
  3545. /* Channel List */
  3546. for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++)
  3547. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
  3548. }
  3549. }
  3550. #else /* CONFIG_CONCURRENT_MODE */
  3551. {
  3552. int i, j;
  3553. for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
  3554. /* Operating Class */
  3555. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
  3556. /* Number of Channels */
  3557. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
  3558. /* Channel List */
  3559. for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++)
  3560. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
  3561. }
  3562. }
  3563. #endif /* CONFIG_CONCURRENT_MODE */
  3564. /* Device Info */
  3565. /* Type: */
  3566. p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
  3567. /* Length: */
  3568. /* 21->P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
  3569. /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
  3570. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
  3571. p2pielen += 2;
  3572. /* Value: */
  3573. /* P2P Device Address */
  3574. _rtw_memcpy(p2pie + p2pielen, adapter_mac_addr(padapter), ETH_ALEN);
  3575. p2pielen += ETH_ALEN;
  3576. /* Config Method */
  3577. /* This field should be big endian. Noted by P2P specification. */
  3578. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
  3579. p2pielen += 2;
  3580. /* Primary Device Type */
  3581. /* Category ID */
  3582. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
  3583. p2pielen += 2;
  3584. /* OUI */
  3585. *(u32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
  3586. p2pielen += 4;
  3587. /* Sub Category ID */
  3588. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
  3589. p2pielen += 2;
  3590. /* Number of Secondary Device Types */
  3591. p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
  3592. /* Device Name */
  3593. /* Type: */
  3594. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
  3595. p2pielen += 2;
  3596. /* Length: */
  3597. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
  3598. p2pielen += 2;
  3599. /* Value: */
  3600. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_name , pwdinfo->device_name_len);
  3601. p2pielen += pwdinfo->device_name_len;
  3602. /* Operating Channel */
  3603. /* Type: */
  3604. p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
  3605. /* Length: */
  3606. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
  3607. p2pielen += 2;
  3608. /* Value: */
  3609. /* Country String */
  3610. p2pie[p2pielen++] = 'X';
  3611. p2pie[p2pielen++] = 'X';
  3612. /* The third byte should be set to 0x04. */
  3613. /* Described in the "Operating Channel Attribute" section. */
  3614. p2pie[p2pielen++] = 0x04;
  3615. /* Operating Class */
  3616. if (pwdinfo->operating_channel <= 14) {
  3617. /* Operating Class */
  3618. p2pie[p2pielen++] = 0x51;
  3619. } else if ((pwdinfo->operating_channel >= 36) && (pwdinfo->operating_channel <= 48)) {
  3620. /* Operating Class */
  3621. p2pie[p2pielen++] = 0x73;
  3622. } else {
  3623. /* Operating Class */
  3624. p2pie[p2pielen++] = 0x7c;
  3625. }
  3626. /* Channel Number */
  3627. p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
  3628. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen);
  3629. #ifdef CONFIG_WFD
  3630. wfdielen = build_nego_req_wfd_ie(pwdinfo, pframe);
  3631. pframe += wfdielen;
  3632. pattrib->pktlen += wfdielen;
  3633. #endif
  3634. pattrib->last_txcmdsz = pattrib->pktlen;
  3635. dump_mgntframe(padapter, pmgntframe);
  3636. return;
  3637. }
  3638. void issue_p2p_GO_response(_adapter *padapter, u8 *raddr, u8 *frame_body, uint len, u8 result)
  3639. {
  3640. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  3641. u8 action = P2P_PUB_ACTION_ACTION;
  3642. u32 p2poui = cpu_to_be32(P2POUI);
  3643. u8 oui_subtype = P2P_GO_NEGO_RESP;
  3644. u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
  3645. u8 p2pielen = 0, i;
  3646. uint wpsielen = 0;
  3647. u16 wps_devicepassword_id = 0x0000;
  3648. uint wps_devicepassword_id_len = 0;
  3649. u8 channel_cnt_24g = 0, channel_cnt_5gl = 0, channel_cnt_5gh;
  3650. u16 len_channellist_attr = 0;
  3651. struct xmit_frame *pmgntframe;
  3652. struct pkt_attrib *pattrib;
  3653. unsigned char *pframe;
  3654. struct rtw_ieee80211_hdr *pwlanhdr;
  3655. unsigned short *fctrl;
  3656. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  3657. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3658. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3659. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3660. #ifdef CONFIG_WFD
  3661. u32 wfdielen = 0;
  3662. #endif
  3663. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  3664. if (pmgntframe == NULL)
  3665. return;
  3666. RTW_INFO("[%s] In, result = %d\n", __FUNCTION__, result);
  3667. /* update attribute */
  3668. pattrib = &pmgntframe->attrib;
  3669. update_mgntframe_attrib(padapter, pattrib);
  3670. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  3671. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  3672. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  3673. fctrl = &(pwlanhdr->frame_ctl);
  3674. *(fctrl) = 0;
  3675. _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
  3676. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  3677. _rtw_memcpy(pwlanhdr->addr3, adapter_mac_addr(padapter), ETH_ALEN);
  3678. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  3679. pmlmeext->mgnt_seq++;
  3680. set_frame_sub_type(pframe, WIFI_ACTION);
  3681. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  3682. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  3683. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  3684. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  3685. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  3686. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  3687. pwdinfo->negotiation_dialog_token = frame_body[7]; /* The Dialog Token of provisioning discovery request frame. */
  3688. pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
  3689. /* Commented by Albert 20110328 */
  3690. /* Try to get the device password ID from the WPS IE of group negotiation request frame */
  3691. /* WiFi Direct test plan 5.1.15 */
  3692. rtw_get_wps_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, wpsie, &wpsielen);
  3693. rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_DEVICE_PWID, (u8 *) &wps_devicepassword_id, &wps_devicepassword_id_len);
  3694. wps_devicepassword_id = be16_to_cpu(wps_devicepassword_id);
  3695. _rtw_memset(wpsie, 0x00, 255);
  3696. wpsielen = 0;
  3697. /* WPS Section */
  3698. wpsielen = 0;
  3699. /* WPS OUI */
  3700. *(u32 *)(wpsie) = cpu_to_be32(WPSOUI);
  3701. wpsielen += 4;
  3702. /* WPS version */
  3703. /* Type: */
  3704. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
  3705. wpsielen += 2;
  3706. /* Length: */
  3707. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  3708. wpsielen += 2;
  3709. /* Value: */
  3710. wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
  3711. /* Device Password ID */
  3712. /* Type: */
  3713. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
  3714. wpsielen += 2;
  3715. /* Length: */
  3716. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
  3717. wpsielen += 2;
  3718. /* Value: */
  3719. if (wps_devicepassword_id == WPS_DPID_USER_SPEC)
  3720. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC);
  3721. else if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
  3722. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_USER_SPEC);
  3723. else
  3724. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_PBC);
  3725. wpsielen += 2;
  3726. /* Commented by Kurt 20120113 */
  3727. /* If some device wants to do p2p handshake without sending prov_disc_req */
  3728. /* We have to get peer_req_cm from here. */
  3729. if (_rtw_memcmp(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "000", 3)) {
  3730. if (wps_devicepassword_id == WPS_DPID_USER_SPEC)
  3731. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "dis", 3);
  3732. else if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
  3733. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pad", 3);
  3734. else
  3735. _rtw_memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pbc", 3);
  3736. }
  3737. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen);
  3738. /* P2P IE Section. */
  3739. /* P2P OUI */
  3740. p2pielen = 0;
  3741. p2pie[p2pielen++] = 0x50;
  3742. p2pie[p2pielen++] = 0x6F;
  3743. p2pie[p2pielen++] = 0x9A;
  3744. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  3745. /* Commented by Albert 20100908 */
  3746. /* According to the P2P Specification, the group negoitation response frame should contain 9 P2P attributes */
  3747. /* 1. Status */
  3748. /* 2. P2P Capability */
  3749. /* 3. Group Owner Intent */
  3750. /* 4. Configuration Timeout */
  3751. /* 5. Operating Channel */
  3752. /* 6. Intended P2P Interface Address */
  3753. /* 7. Channel List */
  3754. /* 8. Device Info */
  3755. /* 9. Group ID ( Only GO ) */
  3756. /* ToDo: */
  3757. /* P2P Status */
  3758. /* Type: */
  3759. p2pie[p2pielen++] = P2P_ATTR_STATUS;
  3760. /* Length: */
  3761. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
  3762. p2pielen += 2;
  3763. /* Value: */
  3764. p2pie[p2pielen++] = result;
  3765. /* P2P Capability */
  3766. /* Type: */
  3767. p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
  3768. /* Length: */
  3769. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
  3770. p2pielen += 2;
  3771. /* Value: */
  3772. /* Device Capability Bitmap, 1 byte */
  3773. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
  3774. /* Commented by Albert 2011/03/08 */
  3775. /* According to the P2P specification */
  3776. /* if the sending device will be client, the P2P Capability should be reserved of group negotation response frame */
  3777. p2pie[p2pielen++] = 0;
  3778. } else {
  3779. /* Be group owner or meet the error case */
  3780. p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
  3781. }
  3782. /* Group Capability Bitmap, 1 byte */
  3783. if (pwdinfo->persistent_supported)
  3784. p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
  3785. else
  3786. p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
  3787. /* Group Owner Intent */
  3788. /* Type: */
  3789. p2pie[p2pielen++] = P2P_ATTR_GO_INTENT;
  3790. /* Length: */
  3791. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
  3792. p2pielen += 2;
  3793. /* Value: */
  3794. if (pwdinfo->peer_intent & 0x01) {
  3795. /* Peer's tie breaker bit is 1, our tie breaker bit should be 0 */
  3796. p2pie[p2pielen++] = (pwdinfo->intent << 1);
  3797. } else {
  3798. /* Peer's tie breaker bit is 0, our tie breaker bit should be 1 */
  3799. p2pie[p2pielen++] = ((pwdinfo->intent << 1) | BIT(0));
  3800. }
  3801. /* Configuration Timeout */
  3802. /* Type: */
  3803. p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
  3804. /* Length: */
  3805. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
  3806. p2pielen += 2;
  3807. /* Value: */
  3808. p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
  3809. p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
  3810. /* Operating Channel */
  3811. /* Type: */
  3812. p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
  3813. /* Length: */
  3814. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
  3815. p2pielen += 2;
  3816. /* Value: */
  3817. /* Country String */
  3818. p2pie[p2pielen++] = 'X';
  3819. p2pie[p2pielen++] = 'X';
  3820. /* The third byte should be set to 0x04. */
  3821. /* Described in the "Operating Channel Attribute" section. */
  3822. p2pie[p2pielen++] = 0x04;
  3823. /* Operating Class */
  3824. if (pwdinfo->operating_channel <= 14) {
  3825. /* Operating Class */
  3826. p2pie[p2pielen++] = 0x51;
  3827. } else if ((pwdinfo->operating_channel >= 36) && (pwdinfo->operating_channel <= 48)) {
  3828. /* Operating Class */
  3829. p2pie[p2pielen++] = 0x73;
  3830. } else {
  3831. /* Operating Class */
  3832. p2pie[p2pielen++] = 0x7c;
  3833. }
  3834. /* Channel Number */
  3835. p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
  3836. /* Intended P2P Interface Address */
  3837. /* Type: */
  3838. p2pie[p2pielen++] = P2P_ATTR_INTENDED_IF_ADDR;
  3839. /* Length: */
  3840. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
  3841. p2pielen += 2;
  3842. /* Value: */
  3843. _rtw_memcpy(p2pie + p2pielen, adapter_mac_addr(padapter), ETH_ALEN);
  3844. p2pielen += ETH_ALEN;
  3845. /* Channel List */
  3846. /* Type: */
  3847. p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
  3848. /* Country String(3) */
  3849. /* + ( Operating Class (1) + Number of Channels(1) ) * Operation Classes (?) */
  3850. /* + number of channels in all classes */
  3851. len_channellist_attr = 3
  3852. + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
  3853. + get_reg_classes_full_count(pmlmeext->channel_list);
  3854. #ifdef CONFIG_CONCURRENT_MODE
  3855. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  3856. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(5 + 1);
  3857. else
  3858. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
  3859. #else
  3860. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
  3861. #endif
  3862. p2pielen += 2;
  3863. /* Value: */
  3864. /* Country String */
  3865. p2pie[p2pielen++] = 'X';
  3866. p2pie[p2pielen++] = 'X';
  3867. /* The third byte should be set to 0x04. */
  3868. /* Described in the "Operating Channel Attribute" section. */
  3869. p2pie[p2pielen++] = 0x04;
  3870. /* Channel Entry List */
  3871. #ifdef CONFIG_CONCURRENT_MODE
  3872. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  3873. u8 union_chan = rtw_mi_get_union_chan(padapter);
  3874. /*Operating Class*/
  3875. if (union_chan > 14) {
  3876. if (union_chan >= 149)
  3877. p2pie[p2pielen++] = 0x7c;
  3878. else
  3879. p2pie[p2pielen++] = 0x73;
  3880. } else
  3881. p2pie[p2pielen++] = 0x51;
  3882. /* Number of Channels
  3883. Just support 1 channel and this channel is AP's channel*/
  3884. p2pie[p2pielen++] = 1;
  3885. /*Channel List*/
  3886. p2pie[p2pielen++] = union_chan;
  3887. } else {
  3888. int i, j;
  3889. for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
  3890. /* Operating Class */
  3891. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
  3892. /* Number of Channels */
  3893. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
  3894. /* Channel List */
  3895. for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++)
  3896. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
  3897. }
  3898. }
  3899. #else /* CONFIG_CONCURRENT_MODE */
  3900. {
  3901. int i, j;
  3902. for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
  3903. /* Operating Class */
  3904. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
  3905. /* Number of Channels */
  3906. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
  3907. /* Channel List */
  3908. for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++)
  3909. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
  3910. }
  3911. }
  3912. #endif /* CONFIG_CONCURRENT_MODE */
  3913. /* Device Info */
  3914. /* Type: */
  3915. p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
  3916. /* Length: */
  3917. /* 21->P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
  3918. /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
  3919. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
  3920. p2pielen += 2;
  3921. /* Value: */
  3922. /* P2P Device Address */
  3923. _rtw_memcpy(p2pie + p2pielen, adapter_mac_addr(padapter), ETH_ALEN);
  3924. p2pielen += ETH_ALEN;
  3925. /* Config Method */
  3926. /* This field should be big endian. Noted by P2P specification. */
  3927. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
  3928. p2pielen += 2;
  3929. /* Primary Device Type */
  3930. /* Category ID */
  3931. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
  3932. p2pielen += 2;
  3933. /* OUI */
  3934. *(u32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
  3935. p2pielen += 4;
  3936. /* Sub Category ID */
  3937. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
  3938. p2pielen += 2;
  3939. /* Number of Secondary Device Types */
  3940. p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
  3941. /* Device Name */
  3942. /* Type: */
  3943. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
  3944. p2pielen += 2;
  3945. /* Length: */
  3946. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
  3947. p2pielen += 2;
  3948. /* Value: */
  3949. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_name , pwdinfo->device_name_len);
  3950. p2pielen += pwdinfo->device_name_len;
  3951. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  3952. /* Group ID Attribute */
  3953. /* Type: */
  3954. p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
  3955. /* Length: */
  3956. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN + pwdinfo->nego_ssidlen);
  3957. p2pielen += 2;
  3958. /* Value: */
  3959. /* p2P Device Address */
  3960. _rtw_memcpy(p2pie + p2pielen , pwdinfo->device_addr, ETH_ALEN);
  3961. p2pielen += ETH_ALEN;
  3962. /* SSID */
  3963. _rtw_memcpy(p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
  3964. p2pielen += pwdinfo->nego_ssidlen;
  3965. }
  3966. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen);
  3967. #ifdef CONFIG_WFD
  3968. wfdielen = build_nego_resp_wfd_ie(pwdinfo, pframe);
  3969. pframe += wfdielen;
  3970. pattrib->pktlen += wfdielen;
  3971. #endif
  3972. pattrib->last_txcmdsz = pattrib->pktlen;
  3973. dump_mgntframe(padapter, pmgntframe);
  3974. return;
  3975. }
  3976. void issue_p2p_GO_confirm(_adapter *padapter, u8 *raddr, u8 result)
  3977. {
  3978. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  3979. u8 action = P2P_PUB_ACTION_ACTION;
  3980. u32 p2poui = cpu_to_be32(P2POUI);
  3981. u8 oui_subtype = P2P_GO_NEGO_CONF;
  3982. u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
  3983. u8 wpsielen = 0, p2pielen = 0;
  3984. struct xmit_frame *pmgntframe;
  3985. struct pkt_attrib *pattrib;
  3986. unsigned char *pframe;
  3987. struct rtw_ieee80211_hdr *pwlanhdr;
  3988. unsigned short *fctrl;
  3989. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  3990. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3991. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3992. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3993. #ifdef CONFIG_WFD
  3994. u32 wfdielen = 0;
  3995. #endif
  3996. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  3997. if (pmgntframe == NULL)
  3998. return;
  3999. RTW_INFO("[%s] In\n", __FUNCTION__);
  4000. /* update attribute */
  4001. pattrib = &pmgntframe->attrib;
  4002. update_mgntframe_attrib(padapter, pattrib);
  4003. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  4004. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  4005. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  4006. fctrl = &(pwlanhdr->frame_ctl);
  4007. *(fctrl) = 0;
  4008. _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
  4009. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  4010. _rtw_memcpy(pwlanhdr->addr3, adapter_mac_addr(padapter), ETH_ALEN);
  4011. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  4012. pmlmeext->mgnt_seq++;
  4013. set_frame_sub_type(pframe, WIFI_ACTION);
  4014. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  4015. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  4016. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  4017. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  4018. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  4019. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  4020. pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
  4021. /* P2P IE Section. */
  4022. /* P2P OUI */
  4023. p2pielen = 0;
  4024. p2pie[p2pielen++] = 0x50;
  4025. p2pie[p2pielen++] = 0x6F;
  4026. p2pie[p2pielen++] = 0x9A;
  4027. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  4028. /* Commented by Albert 20110306 */
  4029. /* According to the P2P Specification, the group negoitation request frame should contain 5 P2P attributes */
  4030. /* 1. Status */
  4031. /* 2. P2P Capability */
  4032. /* 3. Operating Channel */
  4033. /* 4. Channel List */
  4034. /* 5. Group ID ( if this WiFi is GO ) */
  4035. /* P2P Status */
  4036. /* Type: */
  4037. p2pie[p2pielen++] = P2P_ATTR_STATUS;
  4038. /* Length: */
  4039. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
  4040. p2pielen += 2;
  4041. /* Value: */
  4042. p2pie[p2pielen++] = result;
  4043. /* P2P Capability */
  4044. /* Type: */
  4045. p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
  4046. /* Length: */
  4047. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
  4048. p2pielen += 2;
  4049. /* Value: */
  4050. /* Device Capability Bitmap, 1 byte */
  4051. p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
  4052. /* Group Capability Bitmap, 1 byte */
  4053. if (pwdinfo->persistent_supported)
  4054. p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
  4055. else
  4056. p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
  4057. /* Operating Channel */
  4058. /* Type: */
  4059. p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
  4060. /* Length: */
  4061. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
  4062. p2pielen += 2;
  4063. /* Value: */
  4064. /* Country String */
  4065. p2pie[p2pielen++] = 'X';
  4066. p2pie[p2pielen++] = 'X';
  4067. /* The third byte should be set to 0x04. */
  4068. /* Described in the "Operating Channel Attribute" section. */
  4069. p2pie[p2pielen++] = 0x04;
  4070. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
  4071. if (pwdinfo->peer_operating_ch <= 14) {
  4072. /* Operating Class */
  4073. p2pie[p2pielen++] = 0x51;
  4074. } else if ((pwdinfo->peer_operating_ch >= 36) && (pwdinfo->peer_operating_ch <= 48)) {
  4075. /* Operating Class */
  4076. p2pie[p2pielen++] = 0x73;
  4077. } else {
  4078. /* Operating Class */
  4079. p2pie[p2pielen++] = 0x7c;
  4080. }
  4081. p2pie[p2pielen++] = pwdinfo->peer_operating_ch;
  4082. } else {
  4083. if (pwdinfo->operating_channel <= 14) {
  4084. /* Operating Class */
  4085. p2pie[p2pielen++] = 0x51;
  4086. } else if ((pwdinfo->operating_channel >= 36) && (pwdinfo->operating_channel <= 48)) {
  4087. /* Operating Class */
  4088. p2pie[p2pielen++] = 0x73;
  4089. } else {
  4090. /* Operating Class */
  4091. p2pie[p2pielen++] = 0x7c;
  4092. }
  4093. /* Channel Number */
  4094. p2pie[p2pielen++] = pwdinfo->operating_channel; /* Use the listen channel as the operating channel */
  4095. }
  4096. /* Channel List */
  4097. /* Type: */
  4098. p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
  4099. *(u16 *)(p2pie + p2pielen) = 6;
  4100. p2pielen += 2;
  4101. /* Country String */
  4102. p2pie[p2pielen++] = 'X';
  4103. p2pie[p2pielen++] = 'X';
  4104. /* The third byte should be set to 0x04. */
  4105. /* Described in the "Operating Channel Attribute" section. */
  4106. p2pie[p2pielen++] = 0x04;
  4107. /* Value: */
  4108. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
  4109. if (pwdinfo->peer_operating_ch <= 14) {
  4110. /* Operating Class */
  4111. p2pie[p2pielen++] = 0x51;
  4112. } else if ((pwdinfo->peer_operating_ch >= 36) && (pwdinfo->peer_operating_ch <= 48)) {
  4113. /* Operating Class */
  4114. p2pie[p2pielen++] = 0x73;
  4115. } else {
  4116. /* Operating Class */
  4117. p2pie[p2pielen++] = 0x7c;
  4118. }
  4119. p2pie[p2pielen++] = 1;
  4120. p2pie[p2pielen++] = pwdinfo->peer_operating_ch;
  4121. } else {
  4122. if (pwdinfo->operating_channel <= 14) {
  4123. /* Operating Class */
  4124. p2pie[p2pielen++] = 0x51;
  4125. } else if ((pwdinfo->operating_channel >= 36) && (pwdinfo->operating_channel <= 48)) {
  4126. /* Operating Class */
  4127. p2pie[p2pielen++] = 0x73;
  4128. } else {
  4129. /* Operating Class */
  4130. p2pie[p2pielen++] = 0x7c;
  4131. }
  4132. /* Channel Number */
  4133. p2pie[p2pielen++] = 1;
  4134. p2pie[p2pielen++] = pwdinfo->operating_channel; /* Use the listen channel as the operating channel */
  4135. }
  4136. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  4137. /* Group ID Attribute */
  4138. /* Type: */
  4139. p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
  4140. /* Length: */
  4141. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN + pwdinfo->nego_ssidlen);
  4142. p2pielen += 2;
  4143. /* Value: */
  4144. /* p2P Device Address */
  4145. _rtw_memcpy(p2pie + p2pielen , pwdinfo->device_addr, ETH_ALEN);
  4146. p2pielen += ETH_ALEN;
  4147. /* SSID */
  4148. _rtw_memcpy(p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
  4149. p2pielen += pwdinfo->nego_ssidlen;
  4150. }
  4151. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen);
  4152. #ifdef CONFIG_WFD
  4153. wfdielen = build_nego_confirm_wfd_ie(pwdinfo, pframe);
  4154. pframe += wfdielen;
  4155. pattrib->pktlen += wfdielen;
  4156. #endif
  4157. pattrib->last_txcmdsz = pattrib->pktlen;
  4158. dump_mgntframe(padapter, pmgntframe);
  4159. return;
  4160. }
  4161. void issue_p2p_invitation_request(_adapter *padapter, u8 *raddr)
  4162. {
  4163. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  4164. u8 action = P2P_PUB_ACTION_ACTION;
  4165. u32 p2poui = cpu_to_be32(P2POUI);
  4166. u8 oui_subtype = P2P_INVIT_REQ;
  4167. u8 p2pie[255] = { 0x00 };
  4168. u8 p2pielen = 0, i;
  4169. u8 dialogToken = 3;
  4170. u8 channel_cnt_24g = 0, channel_cnt_5gl = 0, channel_cnt_5gh = 0;
  4171. u16 len_channellist_attr = 0;
  4172. #ifdef CONFIG_WFD
  4173. u32 wfdielen = 0;
  4174. #endif
  4175. struct xmit_frame *pmgntframe;
  4176. struct pkt_attrib *pattrib;
  4177. unsigned char *pframe;
  4178. struct rtw_ieee80211_hdr *pwlanhdr;
  4179. unsigned short *fctrl;
  4180. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  4181. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  4182. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  4183. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4184. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  4185. if (pmgntframe == NULL)
  4186. return;
  4187. /* update attribute */
  4188. pattrib = &pmgntframe->attrib;
  4189. update_mgntframe_attrib(padapter, pattrib);
  4190. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  4191. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  4192. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  4193. fctrl = &(pwlanhdr->frame_ctl);
  4194. *(fctrl) = 0;
  4195. _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
  4196. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  4197. _rtw_memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
  4198. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  4199. pmlmeext->mgnt_seq++;
  4200. set_frame_sub_type(pframe, WIFI_ACTION);
  4201. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  4202. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  4203. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  4204. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  4205. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  4206. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  4207. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  4208. /* P2P IE Section. */
  4209. /* P2P OUI */
  4210. p2pielen = 0;
  4211. p2pie[p2pielen++] = 0x50;
  4212. p2pie[p2pielen++] = 0x6F;
  4213. p2pie[p2pielen++] = 0x9A;
  4214. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  4215. /* Commented by Albert 20101011 */
  4216. /* According to the P2P Specification, the P2P Invitation request frame should contain 7 P2P attributes */
  4217. /* 1. Configuration Timeout */
  4218. /* 2. Invitation Flags */
  4219. /* 3. Operating Channel ( Only GO ) */
  4220. /* 4. P2P Group BSSID ( Should be included if I am the GO ) */
  4221. /* 5. Channel List */
  4222. /* 6. P2P Group ID */
  4223. /* 7. P2P Device Info */
  4224. /* Configuration Timeout */
  4225. /* Type: */
  4226. p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
  4227. /* Length: */
  4228. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
  4229. p2pielen += 2;
  4230. /* Value: */
  4231. p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
  4232. p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
  4233. /* Invitation Flags */
  4234. /* Type: */
  4235. p2pie[p2pielen++] = P2P_ATTR_INVITATION_FLAGS;
  4236. /* Length: */
  4237. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
  4238. p2pielen += 2;
  4239. /* Value: */
  4240. p2pie[p2pielen++] = P2P_INVITATION_FLAGS_PERSISTENT;
  4241. /* Operating Channel */
  4242. /* Type: */
  4243. p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
  4244. /* Length: */
  4245. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
  4246. p2pielen += 2;
  4247. /* Value: */
  4248. /* Country String */
  4249. p2pie[p2pielen++] = 'X';
  4250. p2pie[p2pielen++] = 'X';
  4251. /* The third byte should be set to 0x04. */
  4252. /* Described in the "Operating Channel Attribute" section. */
  4253. p2pie[p2pielen++] = 0x04;
  4254. /* Operating Class */
  4255. if (pwdinfo->invitereq_info.operating_ch <= 14)
  4256. p2pie[p2pielen++] = 0x51;
  4257. else if ((pwdinfo->invitereq_info.operating_ch >= 36) && (pwdinfo->invitereq_info.operating_ch <= 48))
  4258. p2pie[p2pielen++] = 0x73;
  4259. else
  4260. p2pie[p2pielen++] = 0x7c;
  4261. /* Channel Number */
  4262. p2pie[p2pielen++] = pwdinfo->invitereq_info.operating_ch; /* operating channel number */
  4263. if (_rtw_memcmp(adapter_mac_addr(padapter), pwdinfo->invitereq_info.go_bssid, ETH_ALEN)) {
  4264. /* P2P Group BSSID */
  4265. /* Type: */
  4266. p2pie[p2pielen++] = P2P_ATTR_GROUP_BSSID;
  4267. /* Length: */
  4268. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
  4269. p2pielen += 2;
  4270. /* Value: */
  4271. /* P2P Device Address for GO */
  4272. _rtw_memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN);
  4273. p2pielen += ETH_ALEN;
  4274. }
  4275. /* Channel List */
  4276. /* Type: */
  4277. p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
  4278. /* Length: */
  4279. /* Country String(3) */
  4280. /* + ( Operating Class (1) + Number of Channels(1) ) * Operation Classes (?) */
  4281. /* + number of channels in all classes */
  4282. len_channellist_attr = 3
  4283. + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
  4284. + get_reg_classes_full_count(pmlmeext->channel_list);
  4285. #ifdef CONFIG_CONCURRENT_MODE
  4286. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  4287. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(5 + 1);
  4288. else
  4289. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
  4290. #else
  4291. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
  4292. #endif
  4293. p2pielen += 2;
  4294. /* Value: */
  4295. /* Country String */
  4296. p2pie[p2pielen++] = 'X';
  4297. p2pie[p2pielen++] = 'X';
  4298. /* The third byte should be set to 0x04. */
  4299. /* Described in the "Operating Channel Attribute" section. */
  4300. p2pie[p2pielen++] = 0x04;
  4301. /* Channel Entry List */
  4302. #ifdef CONFIG_CONCURRENT_MODE
  4303. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  4304. u8 union_ch = rtw_mi_get_union_chan(padapter);
  4305. /* Operating Class */
  4306. if (union_ch > 14) {
  4307. if (union_ch >= 149)
  4308. p2pie[p2pielen++] = 0x7c;
  4309. else
  4310. p2pie[p2pielen++] = 0x73;
  4311. } else
  4312. p2pie[p2pielen++] = 0x51;
  4313. /* Number of Channels */
  4314. /* Just support 1 channel and this channel is AP's channel */
  4315. p2pie[p2pielen++] = 1;
  4316. /* Channel List */
  4317. p2pie[p2pielen++] = union_ch;
  4318. } else {
  4319. int i, j;
  4320. for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
  4321. /* Operating Class */
  4322. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
  4323. /* Number of Channels */
  4324. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
  4325. /* Channel List */
  4326. for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++)
  4327. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
  4328. }
  4329. }
  4330. #else /* CONFIG_CONCURRENT_MODE */
  4331. {
  4332. int i, j;
  4333. for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
  4334. /* Operating Class */
  4335. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
  4336. /* Number of Channels */
  4337. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
  4338. /* Channel List */
  4339. for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++)
  4340. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
  4341. }
  4342. }
  4343. #endif /* CONFIG_CONCURRENT_MODE */
  4344. /* P2P Group ID */
  4345. /* Type: */
  4346. p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
  4347. /* Length: */
  4348. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(6 + pwdinfo->invitereq_info.ssidlen);
  4349. p2pielen += 2;
  4350. /* Value: */
  4351. /* P2P Device Address for GO */
  4352. _rtw_memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN);
  4353. p2pielen += ETH_ALEN;
  4354. /* SSID */
  4355. _rtw_memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_ssid, pwdinfo->invitereq_info.ssidlen);
  4356. p2pielen += pwdinfo->invitereq_info.ssidlen;
  4357. /* Device Info */
  4358. /* Type: */
  4359. p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
  4360. /* Length: */
  4361. /* 21->P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
  4362. /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
  4363. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
  4364. p2pielen += 2;
  4365. /* Value: */
  4366. /* P2P Device Address */
  4367. _rtw_memcpy(p2pie + p2pielen, adapter_mac_addr(padapter), ETH_ALEN);
  4368. p2pielen += ETH_ALEN;
  4369. /* Config Method */
  4370. /* This field should be big endian. Noted by P2P specification. */
  4371. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_DISPLAY);
  4372. p2pielen += 2;
  4373. /* Primary Device Type */
  4374. /* Category ID */
  4375. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
  4376. p2pielen += 2;
  4377. /* OUI */
  4378. *(u32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
  4379. p2pielen += 4;
  4380. /* Sub Category ID */
  4381. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
  4382. p2pielen += 2;
  4383. /* Number of Secondary Device Types */
  4384. p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
  4385. /* Device Name */
  4386. /* Type: */
  4387. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
  4388. p2pielen += 2;
  4389. /* Length: */
  4390. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
  4391. p2pielen += 2;
  4392. /* Value: */
  4393. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
  4394. p2pielen += pwdinfo->device_name_len;
  4395. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen);
  4396. #ifdef CONFIG_WFD
  4397. wfdielen = build_invitation_req_wfd_ie(pwdinfo, pframe);
  4398. pframe += wfdielen;
  4399. pattrib->pktlen += wfdielen;
  4400. #endif
  4401. pattrib->last_txcmdsz = pattrib->pktlen;
  4402. dump_mgntframe(padapter, pmgntframe);
  4403. return;
  4404. }
  4405. void issue_p2p_invitation_response(_adapter *padapter, u8 *raddr, u8 dialogToken, u8 status_code)
  4406. {
  4407. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  4408. u8 action = P2P_PUB_ACTION_ACTION;
  4409. u32 p2poui = cpu_to_be32(P2POUI);
  4410. u8 oui_subtype = P2P_INVIT_RESP;
  4411. u8 p2pie[255] = { 0x00 };
  4412. u8 p2pielen = 0, i;
  4413. u8 channel_cnt_24g = 0, channel_cnt_5gl = 0, channel_cnt_5gh = 0;
  4414. u16 len_channellist_attr = 0;
  4415. #ifdef CONFIG_WFD
  4416. u32 wfdielen = 0;
  4417. #endif
  4418. struct xmit_frame *pmgntframe;
  4419. struct pkt_attrib *pattrib;
  4420. unsigned char *pframe;
  4421. struct rtw_ieee80211_hdr *pwlanhdr;
  4422. unsigned short *fctrl;
  4423. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  4424. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  4425. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  4426. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4427. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  4428. if (pmgntframe == NULL)
  4429. return;
  4430. /* update attribute */
  4431. pattrib = &pmgntframe->attrib;
  4432. update_mgntframe_attrib(padapter, pattrib);
  4433. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  4434. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  4435. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  4436. fctrl = &(pwlanhdr->frame_ctl);
  4437. *(fctrl) = 0;
  4438. _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
  4439. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  4440. _rtw_memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
  4441. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  4442. pmlmeext->mgnt_seq++;
  4443. set_frame_sub_type(pframe, WIFI_ACTION);
  4444. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  4445. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  4446. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  4447. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  4448. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  4449. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  4450. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  4451. /* P2P IE Section. */
  4452. /* P2P OUI */
  4453. p2pielen = 0;
  4454. p2pie[p2pielen++] = 0x50;
  4455. p2pie[p2pielen++] = 0x6F;
  4456. p2pie[p2pielen++] = 0x9A;
  4457. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  4458. /* Commented by Albert 20101005 */
  4459. /* According to the P2P Specification, the P2P Invitation response frame should contain 5 P2P attributes */
  4460. /* 1. Status */
  4461. /* 2. Configuration Timeout */
  4462. /* 3. Operating Channel ( Only GO ) */
  4463. /* 4. P2P Group BSSID ( Only GO ) */
  4464. /* 5. Channel List */
  4465. /* P2P Status */
  4466. /* Type: */
  4467. p2pie[p2pielen++] = P2P_ATTR_STATUS;
  4468. /* Length: */
  4469. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
  4470. p2pielen += 2;
  4471. /* Value: */
  4472. /* When status code is P2P_STATUS_FAIL_INFO_UNAVAILABLE. */
  4473. /* Sent the event receiving the P2P Invitation Req frame to DMP UI. */
  4474. /* DMP had to compare the MAC address to find out the profile. */
  4475. /* So, the WiFi driver will send the P2P_STATUS_FAIL_INFO_UNAVAILABLE to NB. */
  4476. /* If the UI found the corresponding profile, the WiFi driver sends the P2P Invitation Req */
  4477. /* to NB to rebuild the persistent group. */
  4478. p2pie[p2pielen++] = status_code;
  4479. /* Configuration Timeout */
  4480. /* Type: */
  4481. p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
  4482. /* Length: */
  4483. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
  4484. p2pielen += 2;
  4485. /* Value: */
  4486. p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
  4487. p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
  4488. if (status_code == P2P_STATUS_SUCCESS) {
  4489. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  4490. /* The P2P Invitation request frame asks this Wi-Fi device to be the P2P GO */
  4491. /* In this case, the P2P Invitation response frame should carry the two more P2P attributes. */
  4492. /* First one is operating channel attribute. */
  4493. /* Second one is P2P Group BSSID attribute. */
  4494. /* Operating Channel */
  4495. /* Type: */
  4496. p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
  4497. /* Length: */
  4498. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
  4499. p2pielen += 2;
  4500. /* Value: */
  4501. /* Country String */
  4502. p2pie[p2pielen++] = 'X';
  4503. p2pie[p2pielen++] = 'X';
  4504. /* The third byte should be set to 0x04. */
  4505. /* Described in the "Operating Channel Attribute" section. */
  4506. p2pie[p2pielen++] = 0x04;
  4507. /* Operating Class */
  4508. p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
  4509. /* Channel Number */
  4510. p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
  4511. /* P2P Group BSSID */
  4512. /* Type: */
  4513. p2pie[p2pielen++] = P2P_ATTR_GROUP_BSSID;
  4514. /* Length: */
  4515. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
  4516. p2pielen += 2;
  4517. /* Value: */
  4518. /* P2P Device Address for GO */
  4519. _rtw_memcpy(p2pie + p2pielen, adapter_mac_addr(padapter), ETH_ALEN);
  4520. p2pielen += ETH_ALEN;
  4521. }
  4522. /* Channel List */
  4523. /* Type: */
  4524. p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
  4525. /* Length: */
  4526. /* Country String(3) */
  4527. /* + ( Operating Class (1) + Number of Channels(1) ) * Operation Classes (?) */
  4528. /* + number of channels in all classes */
  4529. len_channellist_attr = 3
  4530. + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
  4531. + get_reg_classes_full_count(pmlmeext->channel_list);
  4532. #ifdef CONFIG_CONCURRENT_MODE
  4533. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0)
  4534. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(5 + 1);
  4535. else
  4536. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
  4537. #else
  4538. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
  4539. #endif
  4540. p2pielen += 2;
  4541. /* Value: */
  4542. /* Country String */
  4543. p2pie[p2pielen++] = 'X';
  4544. p2pie[p2pielen++] = 'X';
  4545. /* The third byte should be set to 0x04. */
  4546. /* Described in the "Operating Channel Attribute" section. */
  4547. p2pie[p2pielen++] = 0x04;
  4548. /* Channel Entry List */
  4549. #ifdef CONFIG_CONCURRENT_MODE
  4550. if (rtw_mi_check_status(padapter, MI_LINKED) && padapter->registrypriv.full_ch_in_p2p_handshake == 0) {
  4551. u8 union_ch = rtw_mi_get_union_chan(padapter);
  4552. /* Operating Class */
  4553. if (union_ch > 14) {
  4554. if (union_ch >= 149)
  4555. p2pie[p2pielen++] = 0x7c;
  4556. else
  4557. p2pie[p2pielen++] = 0x73;
  4558. } else
  4559. p2pie[p2pielen++] = 0x51;
  4560. /* Number of Channels */
  4561. /* Just support 1 channel and this channel is AP's channel */
  4562. p2pie[p2pielen++] = 1;
  4563. /* Channel List */
  4564. p2pie[p2pielen++] = union_ch;
  4565. } else {
  4566. int i, j;
  4567. for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
  4568. /* Operating Class */
  4569. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
  4570. /* Number of Channels */
  4571. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
  4572. /* Channel List */
  4573. for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++)
  4574. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
  4575. }
  4576. }
  4577. #else /* CONFIG_CONCURRENT_MODE */
  4578. {
  4579. int i, j;
  4580. for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
  4581. /* Operating Class */
  4582. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
  4583. /* Number of Channels */
  4584. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
  4585. /* Channel List */
  4586. for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++)
  4587. p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
  4588. }
  4589. }
  4590. #endif /* CONFIG_CONCURRENT_MODE */
  4591. }
  4592. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen);
  4593. #ifdef CONFIG_WFD
  4594. wfdielen = build_invitation_resp_wfd_ie(pwdinfo, pframe);
  4595. pframe += wfdielen;
  4596. pattrib->pktlen += wfdielen;
  4597. #endif
  4598. pattrib->last_txcmdsz = pattrib->pktlen;
  4599. dump_mgntframe(padapter, pmgntframe);
  4600. return;
  4601. }
  4602. void issue_p2p_provision_request(_adapter *padapter, u8 *pssid, u8 ussidlen, u8 *pdev_raddr)
  4603. {
  4604. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  4605. u8 action = P2P_PUB_ACTION_ACTION;
  4606. u8 dialogToken = 1;
  4607. u32 p2poui = cpu_to_be32(P2POUI);
  4608. u8 oui_subtype = P2P_PROVISION_DISC_REQ;
  4609. u8 wpsie[100] = { 0x00 };
  4610. u8 wpsielen = 0;
  4611. u32 p2pielen = 0;
  4612. #ifdef CONFIG_WFD
  4613. u32 wfdielen = 0;
  4614. #endif
  4615. struct xmit_frame *pmgntframe;
  4616. struct pkt_attrib *pattrib;
  4617. unsigned char *pframe;
  4618. struct rtw_ieee80211_hdr *pwlanhdr;
  4619. unsigned short *fctrl;
  4620. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  4621. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  4622. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  4623. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4624. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  4625. if (pmgntframe == NULL)
  4626. return;
  4627. RTW_INFO("[%s] In\n", __FUNCTION__);
  4628. /* update attribute */
  4629. pattrib = &pmgntframe->attrib;
  4630. update_mgntframe_attrib(padapter, pattrib);
  4631. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  4632. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  4633. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  4634. fctrl = &(pwlanhdr->frame_ctl);
  4635. *(fctrl) = 0;
  4636. _rtw_memcpy(pwlanhdr->addr1, pdev_raddr, ETH_ALEN);
  4637. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  4638. _rtw_memcpy(pwlanhdr->addr3, pdev_raddr, ETH_ALEN);
  4639. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  4640. pmlmeext->mgnt_seq++;
  4641. set_frame_sub_type(pframe, WIFI_ACTION);
  4642. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  4643. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  4644. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  4645. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  4646. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  4647. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  4648. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  4649. p2pielen = build_prov_disc_request_p2p_ie(pwdinfo, pframe, pssid, ussidlen, pdev_raddr);
  4650. pframe += p2pielen;
  4651. pattrib->pktlen += p2pielen;
  4652. wpsielen = 0;
  4653. /* WPS OUI */
  4654. *(u32 *)(wpsie) = cpu_to_be32(WPSOUI);
  4655. wpsielen += 4;
  4656. /* WPS version */
  4657. /* Type: */
  4658. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
  4659. wpsielen += 2;
  4660. /* Length: */
  4661. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  4662. wpsielen += 2;
  4663. /* Value: */
  4664. wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
  4665. /* Config Method */
  4666. /* Type: */
  4667. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
  4668. wpsielen += 2;
  4669. /* Length: */
  4670. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
  4671. wpsielen += 2;
  4672. /* Value: */
  4673. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->tx_prov_disc_info.wps_config_method_request);
  4674. wpsielen += 2;
  4675. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen);
  4676. #ifdef CONFIG_WFD
  4677. wfdielen = build_provdisc_req_wfd_ie(pwdinfo, pframe);
  4678. pframe += wfdielen;
  4679. pattrib->pktlen += wfdielen;
  4680. #endif
  4681. pattrib->last_txcmdsz = pattrib->pktlen;
  4682. dump_mgntframe(padapter, pmgntframe);
  4683. return;
  4684. }
  4685. u8 is_matched_in_profilelist(u8 *peermacaddr, struct profile_info *profileinfo)
  4686. {
  4687. u8 i, match_result = 0;
  4688. RTW_INFO("[%s] peermac = %.2X %.2X %.2X %.2X %.2X %.2X\n", __FUNCTION__,
  4689. peermacaddr[0], peermacaddr[1], peermacaddr[2], peermacaddr[3], peermacaddr[4], peermacaddr[5]);
  4690. for (i = 0; i < P2P_MAX_PERSISTENT_GROUP_NUM; i++, profileinfo++) {
  4691. RTW_INFO("[%s] profileinfo_mac = %.2X %.2X %.2X %.2X %.2X %.2X\n", __FUNCTION__,
  4692. profileinfo->peermac[0], profileinfo->peermac[1], profileinfo->peermac[2], profileinfo->peermac[3], profileinfo->peermac[4], profileinfo->peermac[5]);
  4693. if (_rtw_memcmp(peermacaddr, profileinfo->peermac, ETH_ALEN)) {
  4694. match_result = 1;
  4695. RTW_INFO("[%s] Match!\n", __FUNCTION__);
  4696. break;
  4697. }
  4698. }
  4699. return match_result ;
  4700. }
  4701. void issue_probersp_p2p(_adapter *padapter, unsigned char *da)
  4702. {
  4703. struct xmit_frame *pmgntframe;
  4704. struct pkt_attrib *pattrib;
  4705. unsigned char *pframe;
  4706. struct rtw_ieee80211_hdr *pwlanhdr;
  4707. unsigned short *fctrl;
  4708. unsigned char *mac;
  4709. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  4710. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  4711. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  4712. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  4713. /* WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network); */
  4714. u16 beacon_interval = 100;
  4715. u16 capInfo = 0;
  4716. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4717. u8 wpsie[255] = { 0x00 };
  4718. u32 wpsielen = 0, p2pielen = 0;
  4719. #ifdef CONFIG_WFD
  4720. u32 wfdielen = 0;
  4721. #endif
  4722. #ifdef CONFIG_INTEL_WIDI
  4723. u8 zero_array_check[L2SDTA_SERVICE_VE_LEN] = { 0x00 };
  4724. #endif /* CONFIG_INTEL_WIDI */
  4725. /* RTW_INFO("%s\n", __FUNCTION__); */
  4726. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  4727. if (pmgntframe == NULL)
  4728. return;
  4729. /* update attribute */
  4730. pattrib = &pmgntframe->attrib;
  4731. update_mgntframe_attrib(padapter, pattrib);
  4732. if (IS_CCK_RATE(pattrib->rate)) {
  4733. /* force OFDM 6M rate */
  4734. pattrib->rate = MGN_6M;
  4735. pattrib->raid = rtw_get_mgntframe_raid(padapter, WIRELESS_11G);
  4736. }
  4737. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  4738. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  4739. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  4740. mac = adapter_mac_addr(padapter);
  4741. fctrl = &(pwlanhdr->frame_ctl);
  4742. *(fctrl) = 0;
  4743. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  4744. _rtw_memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
  4745. /* Use the device address for BSSID field. */
  4746. _rtw_memcpy(pwlanhdr->addr3, mac, ETH_ALEN);
  4747. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  4748. pmlmeext->mgnt_seq++;
  4749. set_frame_sub_type(fctrl, WIFI_PROBERSP);
  4750. pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  4751. pattrib->pktlen = pattrib->hdrlen;
  4752. pframe += pattrib->hdrlen;
  4753. /* timestamp will be inserted by hardware */
  4754. pframe += 8;
  4755. pattrib->pktlen += 8;
  4756. /* beacon interval: 2 bytes */
  4757. _rtw_memcpy(pframe, (unsigned char *) &beacon_interval, 2);
  4758. pframe += 2;
  4759. pattrib->pktlen += 2;
  4760. /* capability info: 2 bytes */
  4761. /* ESS and IBSS bits must be 0 (defined in the 3.1.2.1.1 of WiFi Direct Spec) */
  4762. capInfo |= cap_ShortPremble;
  4763. capInfo |= cap_ShortSlot;
  4764. _rtw_memcpy(pframe, (unsigned char *) &capInfo, 2);
  4765. pframe += 2;
  4766. pattrib->pktlen += 2;
  4767. /* SSID */
  4768. pframe = rtw_set_ie(pframe, _SSID_IE_, 7, pwdinfo->p2p_wildcard_ssid, &pattrib->pktlen);
  4769. /* supported rates... */
  4770. /* Use the OFDM rate in the P2P probe response frame. ( 6(B), 9(B), 12, 18, 24, 36, 48, 54 ) */
  4771. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
  4772. /* DS parameter set */
  4773. pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&pwdinfo->listen_channel, &pattrib->pktlen);
  4774. #ifdef CONFIG_IOCTL_CFG80211
  4775. if (adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211) {
  4776. if (pmlmepriv->wps_probe_resp_ie != NULL && pmlmepriv->p2p_probe_resp_ie != NULL) {
  4777. /* WPS IE */
  4778. _rtw_memcpy(pframe, pmlmepriv->wps_probe_resp_ie, pmlmepriv->wps_probe_resp_ie_len);
  4779. pattrib->pktlen += pmlmepriv->wps_probe_resp_ie_len;
  4780. pframe += pmlmepriv->wps_probe_resp_ie_len;
  4781. /* P2P IE */
  4782. _rtw_memcpy(pframe, pmlmepriv->p2p_probe_resp_ie, pmlmepriv->p2p_probe_resp_ie_len);
  4783. pattrib->pktlen += pmlmepriv->p2p_probe_resp_ie_len;
  4784. pframe += pmlmepriv->p2p_probe_resp_ie_len;
  4785. }
  4786. } else
  4787. #endif /* CONFIG_IOCTL_CFG80211 */
  4788. {
  4789. /* Todo: WPS IE */
  4790. /* Noted by Albert 20100907 */
  4791. /* According to the WPS specification, all the WPS attribute is presented by Big Endian. */
  4792. wpsielen = 0;
  4793. /* WPS OUI */
  4794. *(u32 *)(wpsie) = cpu_to_be32(WPSOUI);
  4795. wpsielen += 4;
  4796. /* WPS version */
  4797. /* Type: */
  4798. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
  4799. wpsielen += 2;
  4800. /* Length: */
  4801. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  4802. wpsielen += 2;
  4803. /* Value: */
  4804. wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
  4805. #ifdef CONFIG_INTEL_WIDI
  4806. /* Commented by Kurt */
  4807. /* Appended WiDi info. only if we did issued_probereq_widi(), and then we saved ven. ext. in pmlmepriv->sa_ext. */
  4808. if (_rtw_memcmp(pmlmepriv->sa_ext, zero_array_check, L2SDTA_SERVICE_VE_LEN) == _FALSE
  4809. || pmlmepriv->num_p2p_sdt != 0) {
  4810. /* Sec dev type */
  4811. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_SEC_DEV_TYPE_LIST);
  4812. wpsielen += 2;
  4813. /* Length: */
  4814. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0008);
  4815. wpsielen += 2;
  4816. /* Value: */
  4817. /* Category ID */
  4818. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_CID_DISPLAYS);
  4819. wpsielen += 2;
  4820. /* OUI */
  4821. *(u32 *)(wpsie + wpsielen) = cpu_to_be32(INTEL_DEV_TYPE_OUI);
  4822. wpsielen += 4;
  4823. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_SCID_WIDI_CONSUMER_SINK);
  4824. wpsielen += 2;
  4825. if (_rtw_memcmp(pmlmepriv->sa_ext, zero_array_check, L2SDTA_SERVICE_VE_LEN) == _FALSE) {
  4826. /* Vendor Extension */
  4827. _rtw_memcpy(wpsie + wpsielen, pmlmepriv->sa_ext, L2SDTA_SERVICE_VE_LEN);
  4828. wpsielen += L2SDTA_SERVICE_VE_LEN;
  4829. }
  4830. }
  4831. #endif /* CONFIG_INTEL_WIDI */
  4832. /* WiFi Simple Config State */
  4833. /* Type: */
  4834. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_SIMPLE_CONF_STATE);
  4835. wpsielen += 2;
  4836. /* Length: */
  4837. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  4838. wpsielen += 2;
  4839. /* Value: */
  4840. wpsie[wpsielen++] = WPS_WSC_STATE_NOT_CONFIG; /* Not Configured. */
  4841. /* Response Type */
  4842. /* Type: */
  4843. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_RESP_TYPE);
  4844. wpsielen += 2;
  4845. /* Length: */
  4846. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  4847. wpsielen += 2;
  4848. /* Value: */
  4849. wpsie[wpsielen++] = WPS_RESPONSE_TYPE_8021X;
  4850. /* UUID-E */
  4851. /* Type: */
  4852. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_UUID_E);
  4853. wpsielen += 2;
  4854. /* Length: */
  4855. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0010);
  4856. wpsielen += 2;
  4857. /* Value: */
  4858. if (pwdinfo->external_uuid == 0) {
  4859. _rtw_memset(wpsie + wpsielen, 0x0, 16);
  4860. _rtw_memcpy(wpsie + wpsielen, mac, ETH_ALEN);
  4861. } else
  4862. _rtw_memcpy(wpsie + wpsielen, pwdinfo->uuid, 0x10);
  4863. wpsielen += 0x10;
  4864. /* Manufacturer */
  4865. /* Type: */
  4866. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MANUFACTURER);
  4867. wpsielen += 2;
  4868. /* Length: */
  4869. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0007);
  4870. wpsielen += 2;
  4871. /* Value: */
  4872. _rtw_memcpy(wpsie + wpsielen, "Realtek", 7);
  4873. wpsielen += 7;
  4874. /* Model Name */
  4875. /* Type: */
  4876. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MODEL_NAME);
  4877. wpsielen += 2;
  4878. /* Length: */
  4879. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0006);
  4880. wpsielen += 2;
  4881. /* Value: */
  4882. _rtw_memcpy(wpsie + wpsielen, "8192CU", 6);
  4883. wpsielen += 6;
  4884. /* Model Number */
  4885. /* Type: */
  4886. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MODEL_NUMBER);
  4887. wpsielen += 2;
  4888. /* Length: */
  4889. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  4890. wpsielen += 2;
  4891. /* Value: */
  4892. wpsie[wpsielen++] = 0x31; /* character 1 */
  4893. /* Serial Number */
  4894. /* Type: */
  4895. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_SERIAL_NUMBER);
  4896. wpsielen += 2;
  4897. /* Length: */
  4898. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(ETH_ALEN);
  4899. wpsielen += 2;
  4900. /* Value: */
  4901. _rtw_memcpy(wpsie + wpsielen, "123456" , ETH_ALEN);
  4902. wpsielen += ETH_ALEN;
  4903. /* Primary Device Type */
  4904. /* Type: */
  4905. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
  4906. wpsielen += 2;
  4907. /* Length: */
  4908. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0008);
  4909. wpsielen += 2;
  4910. /* Value: */
  4911. /* Category ID */
  4912. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
  4913. wpsielen += 2;
  4914. /* OUI */
  4915. *(u32 *)(wpsie + wpsielen) = cpu_to_be32(WPSOUI);
  4916. wpsielen += 4;
  4917. /* Sub Category ID */
  4918. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
  4919. wpsielen += 2;
  4920. /* Device Name */
  4921. /* Type: */
  4922. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
  4923. wpsielen += 2;
  4924. /* Length: */
  4925. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->device_name_len);
  4926. wpsielen += 2;
  4927. /* Value: */
  4928. _rtw_memcpy(wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len);
  4929. wpsielen += pwdinfo->device_name_len;
  4930. /* Config Method */
  4931. /* Type: */
  4932. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
  4933. wpsielen += 2;
  4934. /* Length: */
  4935. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
  4936. wpsielen += 2;
  4937. /* Value: */
  4938. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
  4939. wpsielen += 2;
  4940. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen);
  4941. p2pielen = build_probe_resp_p2p_ie(pwdinfo, pframe);
  4942. pframe += p2pielen;
  4943. pattrib->pktlen += p2pielen;
  4944. }
  4945. #ifdef CONFIG_WFD
  4946. wfdielen = rtw_append_probe_resp_wfd_ie(padapter, pframe);
  4947. pframe += wfdielen;
  4948. pattrib->pktlen += wfdielen;
  4949. #endif
  4950. pattrib->last_txcmdsz = pattrib->pktlen;
  4951. dump_mgntframe(padapter, pmgntframe);
  4952. return;
  4953. }
  4954. int _issue_probereq_p2p(_adapter *padapter, u8 *da, int wait_ack)
  4955. {
  4956. int ret = _FAIL;
  4957. struct xmit_frame *pmgntframe;
  4958. struct pkt_attrib *pattrib;
  4959. unsigned char *pframe;
  4960. struct rtw_ieee80211_hdr *pwlanhdr;
  4961. unsigned short *fctrl;
  4962. unsigned char *mac;
  4963. unsigned char bssrate[NumRates];
  4964. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  4965. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  4966. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  4967. int bssrate_len = 0;
  4968. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  4969. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4970. u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
  4971. u16 wpsielen = 0, p2pielen = 0;
  4972. #ifdef CONFIG_WFD
  4973. u32 wfdielen = 0;
  4974. #endif
  4975. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  4976. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  4977. if (pmgntframe == NULL)
  4978. goto exit;
  4979. /* update attribute */
  4980. pattrib = &pmgntframe->attrib;
  4981. update_mgntframe_attrib(padapter, pattrib);
  4982. if (IS_CCK_RATE(pattrib->rate)) {
  4983. /* force OFDM 6M rate */
  4984. pattrib->rate = MGN_6M;
  4985. pattrib->raid = rtw_get_mgntframe_raid(padapter, WIRELESS_11G);
  4986. }
  4987. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  4988. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  4989. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  4990. mac = adapter_mac_addr(padapter);
  4991. fctrl = &(pwlanhdr->frame_ctl);
  4992. *(fctrl) = 0;
  4993. if (da) {
  4994. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  4995. _rtw_memcpy(pwlanhdr->addr3, da, ETH_ALEN);
  4996. } else {
  4997. if ((pwdinfo->p2p_info.scan_op_ch_only) || (pwdinfo->rx_invitereq_info.scan_op_ch_only)) {
  4998. /* This two flags will be set when this is only the P2P client mode. */
  4999. _rtw_memcpy(pwlanhdr->addr1, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
  5000. _rtw_memcpy(pwlanhdr->addr3, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
  5001. } else {
  5002. /* broadcast probe request frame */
  5003. _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
  5004. _rtw_memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
  5005. }
  5006. }
  5007. _rtw_memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
  5008. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  5009. pmlmeext->mgnt_seq++;
  5010. set_frame_sub_type(pframe, WIFI_PROBEREQ);
  5011. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  5012. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  5013. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ))
  5014. pframe = rtw_set_ie(pframe, _SSID_IE_, pwdinfo->tx_prov_disc_info.ssid.SsidLength, pwdinfo->tx_prov_disc_info.ssid.Ssid, &(pattrib->pktlen));
  5015. else
  5016. pframe = rtw_set_ie(pframe, _SSID_IE_, P2P_WILDCARD_SSID_LEN, pwdinfo->p2p_wildcard_ssid, &(pattrib->pktlen));
  5017. /* Use the OFDM rate in the P2P probe request frame. ( 6(B), 9(B), 12(B), 24(B), 36, 48, 54 ) */
  5018. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
  5019. #ifdef CONFIG_IOCTL_CFG80211
  5020. if (adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211) {
  5021. if (pmlmepriv->wps_probe_req_ie != NULL && pmlmepriv->p2p_probe_req_ie != NULL) {
  5022. /* WPS IE */
  5023. _rtw_memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
  5024. pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
  5025. pframe += pmlmepriv->wps_probe_req_ie_len;
  5026. /* P2P IE */
  5027. _rtw_memcpy(pframe, pmlmepriv->p2p_probe_req_ie, pmlmepriv->p2p_probe_req_ie_len);
  5028. pattrib->pktlen += pmlmepriv->p2p_probe_req_ie_len;
  5029. pframe += pmlmepriv->p2p_probe_req_ie_len;
  5030. }
  5031. } else
  5032. #endif /* CONFIG_IOCTL_CFG80211 */
  5033. {
  5034. /* WPS IE */
  5035. /* Noted by Albert 20110221 */
  5036. /* According to the WPS specification, all the WPS attribute is presented by Big Endian. */
  5037. wpsielen = 0;
  5038. /* WPS OUI */
  5039. *(u32 *)(wpsie) = cpu_to_be32(WPSOUI);
  5040. wpsielen += 4;
  5041. /* WPS version */
  5042. /* Type: */
  5043. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
  5044. wpsielen += 2;
  5045. /* Length: */
  5046. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  5047. wpsielen += 2;
  5048. /* Value: */
  5049. wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
  5050. if (pmlmepriv->wps_probe_req_ie == NULL) {
  5051. /* UUID-E */
  5052. /* Type: */
  5053. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_UUID_E);
  5054. wpsielen += 2;
  5055. /* Length: */
  5056. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0010);
  5057. wpsielen += 2;
  5058. /* Value: */
  5059. if (pwdinfo->external_uuid == 0) {
  5060. _rtw_memset(wpsie + wpsielen, 0x0, 16);
  5061. _rtw_memcpy(wpsie + wpsielen, mac, ETH_ALEN);
  5062. } else
  5063. _rtw_memcpy(wpsie + wpsielen, pwdinfo->uuid, 0x10);
  5064. wpsielen += 0x10;
  5065. /* Config Method */
  5066. /* Type: */
  5067. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
  5068. wpsielen += 2;
  5069. /* Length: */
  5070. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
  5071. wpsielen += 2;
  5072. /* Value: */
  5073. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
  5074. wpsielen += 2;
  5075. }
  5076. /* Device Name */
  5077. /* Type: */
  5078. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
  5079. wpsielen += 2;
  5080. /* Length: */
  5081. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->device_name_len);
  5082. wpsielen += 2;
  5083. /* Value: */
  5084. _rtw_memcpy(wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len);
  5085. wpsielen += pwdinfo->device_name_len;
  5086. /* Primary Device Type */
  5087. /* Type: */
  5088. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
  5089. wpsielen += 2;
  5090. /* Length: */
  5091. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0008);
  5092. wpsielen += 2;
  5093. /* Value: */
  5094. /* Category ID */
  5095. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_CID_RTK_WIDI);
  5096. wpsielen += 2;
  5097. /* OUI */
  5098. *(u32 *)(wpsie + wpsielen) = cpu_to_be32(WPSOUI);
  5099. wpsielen += 4;
  5100. /* Sub Category ID */
  5101. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_SCID_RTK_DMP);
  5102. wpsielen += 2;
  5103. /* Device Password ID */
  5104. /* Type: */
  5105. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
  5106. wpsielen += 2;
  5107. /* Length: */
  5108. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
  5109. wpsielen += 2;
  5110. /* Value: */
  5111. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC); /* Registrar-specified */
  5112. wpsielen += 2;
  5113. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen);
  5114. /* P2P OUI */
  5115. p2pielen = 0;
  5116. p2pie[p2pielen++] = 0x50;
  5117. p2pie[p2pielen++] = 0x6F;
  5118. p2pie[p2pielen++] = 0x9A;
  5119. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  5120. /* Commented by Albert 20110221 */
  5121. /* According to the P2P Specification, the probe request frame should contain 5 P2P attributes */
  5122. /* 1. P2P Capability */
  5123. /* 2. P2P Device ID if this probe request wants to find the specific P2P device */
  5124. /* 3. Listen Channel */
  5125. /* 4. Extended Listen Timing */
  5126. /* 5. Operating Channel if this WiFi is working as the group owner now */
  5127. /* P2P Capability */
  5128. /* Type: */
  5129. p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
  5130. /* Length: */
  5131. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
  5132. p2pielen += 2;
  5133. /* Value: */
  5134. /* Device Capability Bitmap, 1 byte */
  5135. p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
  5136. /* Group Capability Bitmap, 1 byte */
  5137. if (pwdinfo->persistent_supported)
  5138. p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
  5139. else
  5140. p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
  5141. /* Listen Channel */
  5142. /* Type: */
  5143. p2pie[p2pielen++] = P2P_ATTR_LISTEN_CH;
  5144. /* Length: */
  5145. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
  5146. p2pielen += 2;
  5147. /* Value: */
  5148. /* Country String */
  5149. p2pie[p2pielen++] = 'X';
  5150. p2pie[p2pielen++] = 'X';
  5151. /* The third byte should be set to 0x04. */
  5152. /* Described in the "Operating Channel Attribute" section. */
  5153. p2pie[p2pielen++] = 0x04;
  5154. /* Operating Class */
  5155. p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
  5156. /* Channel Number */
  5157. p2pie[p2pielen++] = pwdinfo->listen_channel; /* listen channel */
  5158. /* Extended Listen Timing */
  5159. /* Type: */
  5160. p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
  5161. /* Length: */
  5162. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
  5163. p2pielen += 2;
  5164. /* Value: */
  5165. /* Availability Period */
  5166. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
  5167. p2pielen += 2;
  5168. /* Availability Interval */
  5169. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
  5170. p2pielen += 2;
  5171. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  5172. /* Operating Channel (if this WiFi is working as the group owner now) */
  5173. /* Type: */
  5174. p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
  5175. /* Length: */
  5176. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
  5177. p2pielen += 2;
  5178. /* Value: */
  5179. /* Country String */
  5180. p2pie[p2pielen++] = 'X';
  5181. p2pie[p2pielen++] = 'X';
  5182. /* The third byte should be set to 0x04. */
  5183. /* Described in the "Operating Channel Attribute" section. */
  5184. p2pie[p2pielen++] = 0x04;
  5185. /* Operating Class */
  5186. p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
  5187. /* Channel Number */
  5188. p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
  5189. }
  5190. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen);
  5191. }
  5192. #ifdef CONFIG_WFD
  5193. wfdielen = rtw_append_probe_req_wfd_ie(padapter, pframe);
  5194. pframe += wfdielen;
  5195. pattrib->pktlen += wfdielen;
  5196. #endif
  5197. pattrib->last_txcmdsz = pattrib->pktlen;
  5198. if (wait_ack)
  5199. ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
  5200. else {
  5201. dump_mgntframe(padapter, pmgntframe);
  5202. ret = _SUCCESS;
  5203. }
  5204. exit:
  5205. return ret;
  5206. }
  5207. inline void issue_probereq_p2p(_adapter *adapter, u8 *da)
  5208. {
  5209. _issue_probereq_p2p(adapter, da, _FALSE);
  5210. }
  5211. /*
  5212. * wait_ms == 0 means that there is no need to wait ack through C2H_CCX_TX_RPT
  5213. * wait_ms > 0 means you want to wait ack through C2H_CCX_TX_RPT, and the value of wait_ms means the interval between each TX
  5214. * try_cnt means the maximal TX count to try
  5215. */
  5216. int issue_probereq_p2p_ex(_adapter *adapter, u8 *da, int try_cnt, int wait_ms)
  5217. {
  5218. int ret;
  5219. int i = 0;
  5220. u32 start = rtw_get_current_time();
  5221. do {
  5222. ret = _issue_probereq_p2p(adapter, da, wait_ms > 0 ? _TRUE : _FALSE);
  5223. i++;
  5224. if (RTW_CANNOT_RUN(adapter))
  5225. break;
  5226. if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
  5227. rtw_msleep_os(wait_ms);
  5228. } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
  5229. if (ret != _FAIL) {
  5230. ret = _SUCCESS;
  5231. #ifndef DBG_XMIT_ACK
  5232. goto exit;
  5233. #endif
  5234. }
  5235. if (try_cnt && wait_ms) {
  5236. if (da)
  5237. RTW_INFO(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
  5238. FUNC_ADPT_ARG(adapter), MAC_ARG(da), rtw_get_oper_ch(adapter),
  5239. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  5240. else
  5241. RTW_INFO(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
  5242. FUNC_ADPT_ARG(adapter), rtw_get_oper_ch(adapter),
  5243. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  5244. }
  5245. exit:
  5246. return ret;
  5247. }
  5248. #endif /* CONFIG_P2P */
  5249. s32 rtw_action_public_decache(union recv_frame *rframe, u8 token_offset)
  5250. {
  5251. _adapter *adapter = rframe->u.hdr.adapter;
  5252. struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
  5253. u8 *frame = rframe->u.hdr.rx_data;
  5254. u16 seq_ctrl = ((rframe->u.hdr.attrib.seq_num & 0xffff) << 4) | (rframe->u.hdr.attrib.frag_num & 0xf);
  5255. u8 token = *(rframe->u.hdr.rx_data + sizeof(struct rtw_ieee80211_hdr_3addr) + token_offset);
  5256. if (GetRetry(frame)) {
  5257. if ((seq_ctrl == mlmeext->action_public_rxseq)
  5258. && (token == mlmeext->action_public_dialog_token)
  5259. ) {
  5260. RTW_INFO(FUNC_ADPT_FMT" seq_ctrl=0x%x, rxseq=0x%x, token:%d\n",
  5261. FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq, token);
  5262. return _FAIL;
  5263. }
  5264. }
  5265. /* TODO: per sta seq & token */
  5266. mlmeext->action_public_rxseq = seq_ctrl;
  5267. mlmeext->action_public_dialog_token = token;
  5268. return _SUCCESS;
  5269. }
  5270. unsigned int on_action_public_p2p(union recv_frame *precv_frame)
  5271. {
  5272. _adapter *padapter = precv_frame->u.hdr.adapter;
  5273. u8 *pframe = precv_frame->u.hdr.rx_data;
  5274. uint len = precv_frame->u.hdr.len;
  5275. u8 *frame_body;
  5276. #ifdef CONFIG_P2P
  5277. u8 *p2p_ie;
  5278. u32 p2p_ielen, wps_ielen;
  5279. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  5280. u8 result = P2P_STATUS_SUCCESS;
  5281. u8 empty_addr[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  5282. u8 *merged_p2pie = NULL;
  5283. u32 merged_p2p_ielen = 0;
  5284. #endif /* CONFIG_P2P */
  5285. frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
  5286. #ifdef CONFIG_P2P
  5287. _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
  5288. #ifdef CONFIG_IOCTL_CFG80211
  5289. if (adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211)
  5290. rtw_cfg80211_rx_p2p_action_public(padapter, precv_frame);
  5291. else
  5292. #endif /* CONFIG_IOCTL_CFG80211 */
  5293. {
  5294. /* Do nothing if the driver doesn't enable the P2P function. */
  5295. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
  5296. return _SUCCESS;
  5297. len -= sizeof(struct rtw_ieee80211_hdr_3addr);
  5298. switch (frame_body[6]) { /* OUI Subtype */
  5299. case P2P_GO_NEGO_REQ: {
  5300. RTW_INFO("[%s] Got GO Nego Req Frame\n", __FUNCTION__);
  5301. _rtw_memset(&pwdinfo->groupid_info, 0x00, sizeof(struct group_id_info));
  5302. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
  5303. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  5304. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL)) {
  5305. /* Commented by Albert 20110526 */
  5306. /* In this case, this means the previous nego fail doesn't be reset yet. */
  5307. _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
  5308. /* Restore the previous p2p state */
  5309. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  5310. RTW_INFO("[%s] Restore the previous p2p state to %d\n", __FUNCTION__, rtw_p2p_state(pwdinfo));
  5311. }
  5312. #ifdef CONFIG_CONCURRENT_MODE
  5313. if (rtw_mi_buddy_check_fwstate(padapter, _FW_LINKED))
  5314. _cancel_timer_ex(&pwdinfo->ap_p2p_switch_timer);
  5315. #endif /* CONFIG_CONCURRENT_MODE */
  5316. /* Commented by Kurt 20110902 */
  5317. /* Add if statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered. */
  5318. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING))
  5319. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  5320. /* Commented by Kurt 20120113 */
  5321. /* Get peer_dev_addr here if peer doesn't issue prov_disc frame. */
  5322. if (_rtw_memcmp(pwdinfo->rx_prov_disc_info.peerDevAddr, empty_addr, ETH_ALEN))
  5323. _rtw_memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, get_addr2_ptr(pframe), ETH_ALEN);
  5324. result = process_p2p_group_negotation_req(pwdinfo, frame_body, len);
  5325. issue_p2p_GO_response(padapter, get_addr2_ptr(pframe), frame_body, len, result);
  5326. #ifdef CONFIG_INTEL_WIDI
  5327. if (padapter->mlmepriv.widi_state == INTEL_WIDI_STATE_LISTEN) {
  5328. padapter->mlmepriv.widi_state = INTEL_WIDI_STATE_WFD_CONNECTION;
  5329. _cancel_timer_ex(&(padapter->mlmepriv.listen_timer));
  5330. intel_widi_wk_cmd(padapter, INTEL_WIDI_LISTEN_STOP_WK, NULL, 0);
  5331. }
  5332. #endif /* CONFIG_INTEL_WIDI */
  5333. /* Commented by Albert 20110718 */
  5334. /* No matter negotiating or negotiation failure, the driver should set up the restore P2P state timer. */
  5335. #ifdef CONFIG_CONCURRENT_MODE
  5336. /* Commented by Albert 20120107 */
  5337. _set_timer(&pwdinfo->restore_p2p_state_timer, 3000);
  5338. #else /* CONFIG_CONCURRENT_MODE */
  5339. _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
  5340. #endif /* CONFIG_CONCURRENT_MODE */
  5341. break;
  5342. }
  5343. case P2P_GO_NEGO_RESP: {
  5344. RTW_INFO("[%s] Got GO Nego Resp Frame\n", __FUNCTION__);
  5345. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING)) {
  5346. /* Commented by Albert 20110425 */
  5347. /* The restore timer is enabled when issuing the nego request frame of rtw_p2p_connect function. */
  5348. _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
  5349. pwdinfo->nego_req_info.benable = _FALSE;
  5350. result = process_p2p_group_negotation_resp(pwdinfo, frame_body, len);
  5351. issue_p2p_GO_confirm(pwdinfo->padapter, get_addr2_ptr(pframe), result);
  5352. if (P2P_STATUS_SUCCESS == result) {
  5353. if (rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT) {
  5354. pwdinfo->p2p_info.operation_ch[0] = pwdinfo->peer_operating_ch;
  5355. #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
  5356. pwdinfo->p2p_info.operation_ch[1] = 1; /* Check whether GO is operating in channel 1; */
  5357. pwdinfo->p2p_info.operation_ch[2] = 6; /* Check whether GO is operating in channel 6; */
  5358. pwdinfo->p2p_info.operation_ch[3] = 11; /* Check whether GO is operating in channel 11; */
  5359. #endif /* CONFIG_P2P_OP_CHK_SOCIAL_CH */
  5360. pwdinfo->p2p_info.scan_op_ch_only = 1;
  5361. _set_timer(&pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH);
  5362. }
  5363. }
  5364. /* Reset the dialog token for group negotiation frames. */
  5365. pwdinfo->negotiation_dialog_token = 1;
  5366. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL))
  5367. _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
  5368. } else
  5369. RTW_INFO("[%s] Skipped GO Nego Resp Frame (p2p_state != P2P_STATE_GONEGO_ING)\n", __FUNCTION__);
  5370. break;
  5371. }
  5372. case P2P_GO_NEGO_CONF: {
  5373. RTW_INFO("[%s] Got GO Nego Confirm Frame\n", __FUNCTION__);
  5374. result = process_p2p_group_negotation_confirm(pwdinfo, frame_body, len);
  5375. if (P2P_STATUS_SUCCESS == result) {
  5376. if (rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT) {
  5377. pwdinfo->p2p_info.operation_ch[0] = pwdinfo->peer_operating_ch;
  5378. #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
  5379. pwdinfo->p2p_info.operation_ch[1] = 1; /* Check whether GO is operating in channel 1; */
  5380. pwdinfo->p2p_info.operation_ch[2] = 6; /* Check whether GO is operating in channel 6; */
  5381. pwdinfo->p2p_info.operation_ch[3] = 11; /* Check whether GO is operating in channel 11; */
  5382. #endif /* CONFIG_P2P_OP_CHK_SOCIAL_CH */
  5383. pwdinfo->p2p_info.scan_op_ch_only = 1;
  5384. _set_timer(&pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH);
  5385. }
  5386. }
  5387. break;
  5388. }
  5389. case P2P_INVIT_REQ: {
  5390. /* Added by Albert 2010/10/05 */
  5391. /* Received the P2P Invite Request frame. */
  5392. RTW_INFO("[%s] Got invite request frame!\n", __FUNCTION__);
  5393. p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
  5394. if (p2p_ie) {
  5395. /* Parse the necessary information from the P2P Invitation Request frame. */
  5396. /* For example: The MAC address of sending this P2P Invitation Request frame. */
  5397. u32 attr_contentlen = 0;
  5398. u8 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
  5399. struct group_id_info group_id;
  5400. u8 invitation_flag = 0;
  5401. int j = 0;
  5402. merged_p2p_ielen = rtw_get_p2p_merged_ies_len(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_);
  5403. merged_p2pie = rtw_zmalloc(merged_p2p_ielen + 2); /* 2 is for EID and Length */
  5404. if (merged_p2pie == NULL) {
  5405. RTW_INFO("[%s] Malloc p2p ie fail\n", __FUNCTION__);
  5406. goto exit;
  5407. }
  5408. _rtw_memset(merged_p2pie, 0x00, merged_p2p_ielen);
  5409. merged_p2p_ielen = rtw_p2p_merge_ies(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, merged_p2pie);
  5410. rtw_get_p2p_attr_content(merged_p2pie, merged_p2p_ielen, P2P_ATTR_INVITATION_FLAGS, &invitation_flag, &attr_contentlen);
  5411. if (attr_contentlen) {
  5412. rtw_get_p2p_attr_content(merged_p2pie, merged_p2p_ielen, P2P_ATTR_GROUP_BSSID, pwdinfo->p2p_peer_interface_addr, &attr_contentlen);
  5413. /* Commented by Albert 20120510 */
  5414. /* Copy to the pwdinfo->p2p_peer_interface_addr. */
  5415. /* So that the WFD UI ( or Sigma ) can get the peer interface address by using the following command. */
  5416. /* #> iwpriv wlan0 p2p_get peer_ifa */
  5417. /* After having the peer interface address, the sigma can find the correct conf file for wpa_supplicant. */
  5418. if (attr_contentlen) {
  5419. RTW_INFO("[%s] GO's BSSID = %.2X %.2X %.2X %.2X %.2X %.2X\n", __FUNCTION__,
  5420. pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1],
  5421. pwdinfo->p2p_peer_interface_addr[2], pwdinfo->p2p_peer_interface_addr[3],
  5422. pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
  5423. }
  5424. if (invitation_flag & P2P_INVITATION_FLAGS_PERSISTENT) {
  5425. /* Re-invoke the persistent group. */
  5426. _rtw_memset(&group_id, 0x00, sizeof(struct group_id_info));
  5427. rtw_get_p2p_attr_content(merged_p2pie, merged_p2p_ielen, P2P_ATTR_GROUP_ID, (u8 *) &group_id, &attr_contentlen);
  5428. if (attr_contentlen) {
  5429. if (_rtw_memcmp(group_id.go_device_addr, adapter_mac_addr(padapter), ETH_ALEN)) {
  5430. /* The p2p device sending this p2p invitation request wants this Wi-Fi device to be the persistent GO. */
  5431. rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_GO);
  5432. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  5433. status_code = P2P_STATUS_SUCCESS;
  5434. } else {
  5435. /* The p2p device sending this p2p invitation request wants to be the persistent GO. */
  5436. if (is_matched_in_profilelist(pwdinfo->p2p_peer_interface_addr, &pwdinfo->profileinfo[0])) {
  5437. u8 operatingch_info[5] = { 0x00 };
  5438. if (rtw_get_p2p_attr_content(merged_p2pie, merged_p2p_ielen, P2P_ATTR_OPERATING_CH, operatingch_info,
  5439. &attr_contentlen)) {
  5440. if (rtw_chset_search_ch(padapter->mlmeextpriv.channel_set, (u32)operatingch_info[4]) >= 0) {
  5441. /* The operating channel is acceptable for this device. */
  5442. pwdinfo->rx_invitereq_info.operation_ch[0] = operatingch_info[4];
  5443. #ifdef CONFIG_P2P_OP_CHK_SOCIAL_CH
  5444. pwdinfo->rx_invitereq_info.operation_ch[1] = 1; /* Check whether GO is operating in channel 1; */
  5445. pwdinfo->rx_invitereq_info.operation_ch[2] = 6; /* Check whether GO is operating in channel 6; */
  5446. pwdinfo->rx_invitereq_info.operation_ch[3] = 11; /* Check whether GO is operating in channel 11; */
  5447. #endif /* CONFIG_P2P_OP_CHK_SOCIAL_CH */
  5448. pwdinfo->rx_invitereq_info.scan_op_ch_only = 1;
  5449. _set_timer(&pwdinfo->reset_ch_sitesurvey, P2P_RESET_SCAN_CH);
  5450. rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH);
  5451. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  5452. status_code = P2P_STATUS_SUCCESS;
  5453. } else {
  5454. /* The operating channel isn't supported by this device. */
  5455. rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
  5456. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  5457. status_code = P2P_STATUS_FAIL_NO_COMMON_CH;
  5458. _set_timer(&pwdinfo->restore_p2p_state_timer, 3000);
  5459. }
  5460. } else {
  5461. /* Commented by Albert 20121130 */
  5462. /* Intel will use the different P2P IE to store the operating channel information */
  5463. /* Workaround for Intel WiDi 3.5 */
  5464. rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH);
  5465. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  5466. status_code = P2P_STATUS_SUCCESS;
  5467. }
  5468. } else {
  5469. rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
  5470. #ifdef CONFIG_INTEL_WIDI
  5471. _rtw_memcpy(pwdinfo->p2p_peer_device_addr, group_id.go_device_addr , ETH_ALEN);
  5472. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  5473. #endif /* CONFIG_INTEL_WIDI */
  5474. status_code = P2P_STATUS_FAIL_UNKNOWN_P2PGROUP;
  5475. }
  5476. }
  5477. } else {
  5478. RTW_INFO("[%s] P2P Group ID Attribute NOT FOUND!\n", __FUNCTION__);
  5479. status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
  5480. }
  5481. } else {
  5482. /* Received the invitation to join a P2P group. */
  5483. _rtw_memset(&group_id, 0x00, sizeof(struct group_id_info));
  5484. rtw_get_p2p_attr_content(merged_p2pie, merged_p2p_ielen, P2P_ATTR_GROUP_ID, (u8 *) &group_id, &attr_contentlen);
  5485. if (attr_contentlen) {
  5486. if (_rtw_memcmp(group_id.go_device_addr, adapter_mac_addr(padapter), ETH_ALEN)) {
  5487. /* In this case, the GO can't be myself. */
  5488. rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
  5489. status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
  5490. } else {
  5491. /* The p2p device sending this p2p invitation request wants to join an existing P2P group */
  5492. /* Commented by Albert 2012/06/28 */
  5493. /* In this case, this Wi-Fi device should use the iwpriv command to get the peer device address. */
  5494. /* The peer device address should be the destination address for the provisioning discovery request. */
  5495. /* Then, this Wi-Fi device should use the iwpriv command to get the peer interface address. */
  5496. /* The peer interface address should be the address for WPS mac address */
  5497. _rtw_memcpy(pwdinfo->p2p_peer_device_addr, group_id.go_device_addr , ETH_ALEN);
  5498. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  5499. rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_JOIN);
  5500. status_code = P2P_STATUS_SUCCESS;
  5501. }
  5502. } else {
  5503. RTW_INFO("[%s] P2P Group ID Attribute NOT FOUND!\n", __FUNCTION__);
  5504. status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
  5505. }
  5506. }
  5507. } else {
  5508. RTW_INFO("[%s] P2P Invitation Flags Attribute NOT FOUND!\n", __FUNCTION__);
  5509. status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
  5510. }
  5511. RTW_INFO("[%s] status_code = %d\n", __FUNCTION__, status_code);
  5512. pwdinfo->inviteresp_info.token = frame_body[7];
  5513. issue_p2p_invitation_response(padapter, get_addr2_ptr(pframe), pwdinfo->inviteresp_info.token, status_code);
  5514. _set_timer(&pwdinfo->restore_p2p_state_timer, 3000);
  5515. }
  5516. #ifdef CONFIG_INTEL_WIDI
  5517. if (padapter->mlmepriv.widi_state == INTEL_WIDI_STATE_LISTEN) {
  5518. padapter->mlmepriv.widi_state = INTEL_WIDI_STATE_WFD_CONNECTION;
  5519. _cancel_timer_ex(&(padapter->mlmepriv.listen_timer));
  5520. intel_widi_wk_cmd(padapter, INTEL_WIDI_LISTEN_STOP_WK, NULL, 0);
  5521. }
  5522. #endif /* CONFIG_INTEL_WIDI */
  5523. break;
  5524. }
  5525. case P2P_INVIT_RESP: {
  5526. u8 attr_content = 0x00;
  5527. u32 attr_contentlen = 0;
  5528. RTW_INFO("[%s] Got invite response frame!\n", __FUNCTION__);
  5529. _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
  5530. p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
  5531. if (p2p_ie) {
  5532. rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, &attr_content, &attr_contentlen);
  5533. if (attr_contentlen == 1) {
  5534. RTW_INFO("[%s] Status = %d\n", __FUNCTION__, attr_content);
  5535. pwdinfo->invitereq_info.benable = _FALSE;
  5536. if (attr_content == P2P_STATUS_SUCCESS) {
  5537. if (_rtw_memcmp(pwdinfo->invitereq_info.go_bssid, adapter_mac_addr(padapter), ETH_ALEN))
  5538. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  5539. else
  5540. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  5541. rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_OK);
  5542. } else {
  5543. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  5544. rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
  5545. }
  5546. } else {
  5547. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  5548. rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
  5549. }
  5550. } else {
  5551. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  5552. rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
  5553. }
  5554. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL))
  5555. _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
  5556. break;
  5557. }
  5558. case P2P_DEVDISC_REQ:
  5559. process_p2p_devdisc_req(pwdinfo, pframe, len);
  5560. break;
  5561. case P2P_DEVDISC_RESP:
  5562. process_p2p_devdisc_resp(pwdinfo, pframe, len);
  5563. break;
  5564. case P2P_PROVISION_DISC_REQ:
  5565. RTW_INFO("[%s] Got Provisioning Discovery Request Frame\n", __FUNCTION__);
  5566. process_p2p_provdisc_req(pwdinfo, pframe, len);
  5567. _rtw_memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, get_addr2_ptr(pframe), ETH_ALEN);
  5568. /* 20110902 Kurt */
  5569. /* Add the following statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered. */
  5570. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
  5571. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  5572. rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ);
  5573. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
  5574. #ifdef CONFIG_INTEL_WIDI
  5575. if (padapter->mlmepriv.widi_state == INTEL_WIDI_STATE_LISTEN) {
  5576. padapter->mlmepriv.widi_state = INTEL_WIDI_STATE_WFD_CONNECTION;
  5577. _cancel_timer_ex(&(padapter->mlmepriv.listen_timer));
  5578. intel_widi_wk_cmd(padapter, INTEL_WIDI_LISTEN_STOP_WK, NULL, 0);
  5579. }
  5580. #endif /* CONFIG_INTEL_WIDI */
  5581. break;
  5582. case P2P_PROVISION_DISC_RESP:
  5583. /* Commented by Albert 20110707 */
  5584. /* Should we check the pwdinfo->tx_prov_disc_info.bsent flag here?? */
  5585. RTW_INFO("[%s] Got Provisioning Discovery Response Frame\n", __FUNCTION__);
  5586. /* Commented by Albert 20110426 */
  5587. /* The restore timer is enabled when issuing the provisioing request frame in rtw_p2p_prov_disc function. */
  5588. _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
  5589. rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_RSP);
  5590. process_p2p_provdisc_resp(pwdinfo, pframe);
  5591. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
  5592. break;
  5593. }
  5594. }
  5595. exit:
  5596. if (merged_p2pie)
  5597. rtw_mfree(merged_p2pie, merged_p2p_ielen + 2);
  5598. #endif /* CONFIG_P2P */
  5599. return _SUCCESS;
  5600. }
  5601. unsigned int on_action_public_vendor(union recv_frame *precv_frame)
  5602. {
  5603. unsigned int ret = _FAIL;
  5604. u8 *pframe = precv_frame->u.hdr.rx_data;
  5605. uint frame_len = precv_frame->u.hdr.len;
  5606. u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  5607. if (_rtw_memcmp(frame_body + 2, P2P_OUI, 4) == _TRUE) {
  5608. if (rtw_action_public_decache(precv_frame, 7) == _FAIL)
  5609. goto exit;
  5610. if (!hal_chk_wl_func(precv_frame->u.hdr.adapter, WL_FUNC_MIRACAST))
  5611. rtw_rframe_del_wfd_ie(precv_frame, 8);
  5612. ret = on_action_public_p2p(precv_frame);
  5613. }
  5614. exit:
  5615. return ret;
  5616. }
  5617. unsigned int on_action_public_default(union recv_frame *precv_frame, u8 action)
  5618. {
  5619. unsigned int ret = _FAIL;
  5620. u8 *pframe = precv_frame->u.hdr.rx_data;
  5621. uint frame_len = precv_frame->u.hdr.len;
  5622. u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  5623. u8 token;
  5624. _adapter *adapter = precv_frame->u.hdr.adapter;
  5625. int cnt = 0;
  5626. char msg[64];
  5627. token = frame_body[2];
  5628. if (rtw_action_public_decache(precv_frame, 2) == _FAIL)
  5629. goto exit;
  5630. #ifdef CONFIG_IOCTL_CFG80211
  5631. cnt += sprintf((msg + cnt), "%s(token:%u)", action_public_str(action), token);
  5632. rtw_cfg80211_rx_action(adapter, precv_frame, msg);
  5633. #endif
  5634. ret = _SUCCESS;
  5635. exit:
  5636. return ret;
  5637. }
  5638. unsigned int on_action_public(_adapter *padapter, union recv_frame *precv_frame)
  5639. {
  5640. unsigned int ret = _FAIL;
  5641. u8 *pframe = precv_frame->u.hdr.rx_data;
  5642. uint frame_len = precv_frame->u.hdr.len;
  5643. u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  5644. u8 category, action;
  5645. /* check RA matches or not */
  5646. if (!_rtw_memcmp(adapter_mac_addr(padapter), GetAddr1Ptr(pframe), ETH_ALEN))
  5647. goto exit;
  5648. category = frame_body[0];
  5649. if (category != RTW_WLAN_CATEGORY_PUBLIC)
  5650. goto exit;
  5651. action = frame_body[1];
  5652. switch (action) {
  5653. case ACT_PUBLIC_BSSCOEXIST:
  5654. #ifdef CONFIG_80211N_HT
  5655. #ifdef CONFIG_AP_MODE
  5656. /*20/40 BSS Coexistence Management frame is a Public Action frame*/
  5657. if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == _TRUE)
  5658. rtw_process_public_act_bsscoex(padapter, pframe, frame_len);
  5659. #endif /*CONFIG_AP_MODE*/
  5660. #endif /*CONFIG_80211N_HT*/
  5661. break;
  5662. case ACT_PUBLIC_VENDOR:
  5663. ret = on_action_public_vendor(precv_frame);
  5664. break;
  5665. default:
  5666. ret = on_action_public_default(precv_frame, action);
  5667. break;
  5668. }
  5669. exit:
  5670. return ret;
  5671. }
  5672. unsigned int OnAction_ft(_adapter *padapter, union recv_frame *precv_frame)
  5673. {
  5674. #ifdef CONFIG_RTW_80211R
  5675. u32 ret = _FAIL;
  5676. u32 frame_len = 0;
  5677. u8 action_code = 0;
  5678. u8 category = 0;
  5679. u8 *pframe = NULL;
  5680. u8 *pframe_body = NULL;
  5681. u8 sta_addr[ETH_ALEN] = {0};
  5682. u8 *pie = NULL;
  5683. u32 ft_ie_len = 0;
  5684. u32 status_code = 0;
  5685. struct mlme_ext_priv *pmlmeext = NULL;
  5686. struct mlme_ext_info *pmlmeinfo = NULL;
  5687. struct mlme_priv *pmlmepriv = NULL;
  5688. struct wlan_network *proam_target = NULL;
  5689. ft_priv *pftpriv = NULL;
  5690. _irqL irqL;
  5691. pmlmeext = &padapter->mlmeextpriv;
  5692. pmlmeinfo = &(pmlmeext->mlmext_info);
  5693. pmlmepriv = &padapter->mlmepriv;
  5694. pftpriv = &pmlmepriv->ftpriv;
  5695. pframe = precv_frame->u.hdr.rx_data;
  5696. frame_len = precv_frame->u.hdr.len;
  5697. pframe_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  5698. category = pframe_body[0];
  5699. if (category != RTW_WLAN_CATEGORY_FT)
  5700. goto exit;
  5701. action_code = pframe_body[1];
  5702. switch (action_code) {
  5703. case RTW_WLAN_ACTION_FT_RESPONSE:
  5704. RTW_INFO("FT: %s RTW_WLAN_ACTION_FT_RESPONSE\n", __func__);
  5705. if (!_rtw_memcmp(adapter_mac_addr(padapter), &pframe_body[2], ETH_ALEN)) {
  5706. RTW_ERR("FT: Unmatched STA MAC Address "MAC_FMT"\n", MAC_ARG(&pframe_body[2]));
  5707. goto exit;
  5708. }
  5709. status_code = le16_to_cpu(*(u16 *)((SIZE_PTR)pframe + sizeof(struct rtw_ieee80211_hdr_3addr) + 14));
  5710. if (status_code != 0) {
  5711. RTW_ERR("FT: WLAN ACTION FT RESPONSE fail, status: %d\n", status_code);
  5712. goto exit;
  5713. }
  5714. if (is_zero_mac_addr(&pframe_body[8]) || is_broadcast_mac_addr(&pframe_body[8])) {
  5715. RTW_ERR("FT: Invalid Target MAC Address "MAC_FMT"\n", MAC_ARG(padapter->mlmepriv.roam_tgt_addr));
  5716. goto exit;
  5717. }
  5718. pie = rtw_get_ie(pframe_body, _MDIE_, &ft_ie_len, frame_len);
  5719. if (pie) {
  5720. if (!_rtw_memcmp(&pftpriv->mdid, pie+2, 2)) {
  5721. RTW_ERR("FT: Invalid MDID\n");
  5722. goto exit;
  5723. }
  5724. }
  5725. rtw_set_ft_status(padapter, RTW_FT_REQUESTED_STA);
  5726. _cancel_timer_ex(&pmlmeext->ft_link_timer);
  5727. /*Disconnect current AP*/
  5728. receive_disconnect(padapter, pmlmepriv->cur_network.network.MacAddress, WLAN_REASON_ACTIVE_ROAM, _FALSE);
  5729. pftpriv->ft_action_len = frame_len;
  5730. _rtw_memcpy(pftpriv->ft_action, pframe, rtw_min(frame_len, RTW_MAX_FTIE_SZ));
  5731. ret = _SUCCESS;
  5732. break;
  5733. case RTW_WLAN_ACTION_FT_REQUEST:
  5734. case RTW_WLAN_ACTION_FT_CONFIRM:
  5735. case RTW_WLAN_ACTION_FT_ACK:
  5736. default:
  5737. RTW_ERR("FT: Unsupported FT Action!\n");
  5738. break;
  5739. }
  5740. exit:
  5741. return ret;
  5742. #else
  5743. return _SUCCESS;
  5744. #endif
  5745. }
  5746. unsigned int OnAction_ht(_adapter *padapter, union recv_frame *precv_frame)
  5747. {
  5748. u8 *pframe = precv_frame->u.hdr.rx_data;
  5749. uint frame_len = precv_frame->u.hdr.len;
  5750. u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  5751. u8 category, action;
  5752. /* check RA matches or not */
  5753. if (!_rtw_memcmp(adapter_mac_addr(padapter), GetAddr1Ptr(pframe), ETH_ALEN))
  5754. goto exit;
  5755. category = frame_body[0];
  5756. if (category != RTW_WLAN_CATEGORY_HT)
  5757. goto exit;
  5758. action = frame_body[1];
  5759. switch (action) {
  5760. case RTW_WLAN_ACTION_HT_SM_PS:
  5761. #ifdef CONFIG_80211N_HT
  5762. #ifdef CONFIG_AP_MODE
  5763. if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) == _TRUE)
  5764. rtw_process_ht_action_smps(padapter, get_addr2_ptr(pframe), frame_body[2]);
  5765. #endif /*CONFIG_AP_MODE*/
  5766. #endif /*CONFIG_80211N_HT*/
  5767. break;
  5768. case RTW_WLAN_ACTION_HT_COMPRESS_BEAMFORMING:
  5769. #ifdef CONFIG_BEAMFORMING
  5770. /*RTW_INFO("RTW_WLAN_ACTION_HT_COMPRESS_BEAMFORMING\n");*/
  5771. rtw_beamforming_get_report_frame(padapter, precv_frame);
  5772. #endif /*CONFIG_BEAMFORMING*/
  5773. break;
  5774. default:
  5775. break;
  5776. }
  5777. exit:
  5778. return _SUCCESS;
  5779. }
  5780. #ifdef CONFIG_IEEE80211W
  5781. unsigned int OnAction_sa_query(_adapter *padapter, union recv_frame *precv_frame)
  5782. {
  5783. u8 *pframe = precv_frame->u.hdr.rx_data;
  5784. struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
  5785. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  5786. struct sta_info *psta;
  5787. struct sta_priv *pstapriv = &padapter->stapriv;
  5788. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  5789. u16 tid;
  5790. /* Baron */
  5791. RTW_INFO("OnAction_sa_query\n");
  5792. switch (pframe[WLAN_HDR_A3_LEN + 1]) {
  5793. case 0: /* SA Query req */
  5794. _rtw_memcpy(&tid, &pframe[WLAN_HDR_A3_LEN + 2], sizeof(u16));
  5795. RTW_INFO("OnAction_sa_query request,action=%d, tid=%04x, pframe=%02x-%02x\n"
  5796. , pframe[WLAN_HDR_A3_LEN + 1], tid, pframe[WLAN_HDR_A3_LEN + 2], pframe[WLAN_HDR_A3_LEN + 3]);
  5797. issue_action_SA_Query(padapter, get_addr2_ptr(pframe), 1, tid, IEEE80211W_RIGHT_KEY);
  5798. break;
  5799. case 1: /* SA Query rsp */
  5800. psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  5801. if (psta != NULL)
  5802. _cancel_timer_ex(&psta->dot11w_expire_timer);
  5803. _rtw_memcpy(&tid, &pframe[WLAN_HDR_A3_LEN + 2], sizeof(u16));
  5804. RTW_INFO("OnAction_sa_query response,action=%d, tid=%04x, cancel timer\n", pframe[WLAN_HDR_A3_LEN + 1], tid);
  5805. break;
  5806. default:
  5807. break;
  5808. }
  5809. if (0) {
  5810. int pp;
  5811. printk("pattrib->pktlen = %d =>", pattrib->pkt_len);
  5812. for (pp = 0; pp < pattrib->pkt_len; pp++)
  5813. printk(" %02x ", pframe[pp]);
  5814. printk("\n");
  5815. }
  5816. return _SUCCESS;
  5817. }
  5818. #endif /* CONFIG_IEEE80211W */
  5819. unsigned int OnAction_wmm(_adapter *padapter, union recv_frame *precv_frame)
  5820. {
  5821. return _SUCCESS;
  5822. }
  5823. unsigned int OnAction_vht(_adapter *padapter, union recv_frame *precv_frame)
  5824. {
  5825. #ifdef CONFIG_80211AC_VHT
  5826. struct rx_pkt_attrib *prxattrib = &precv_frame->u.hdr.attrib;
  5827. u8 *pframe = precv_frame->u.hdr.rx_data;
  5828. uint frame_len = precv_frame->u.hdr.len;
  5829. struct rtw_ieee80211_hdr_3addr *whdr = (struct rtw_ieee80211_hdr_3addr *)pframe;
  5830. u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  5831. u8 category, action;
  5832. struct sta_info *psta = NULL;
  5833. /* check RA matches or not */
  5834. if (!_rtw_memcmp(adapter_mac_addr(padapter), GetAddr1Ptr(pframe), ETH_ALEN))
  5835. goto exit;
  5836. category = frame_body[0];
  5837. if (category != RTW_WLAN_CATEGORY_VHT)
  5838. goto exit;
  5839. action = frame_body[1];
  5840. switch (action) {
  5841. case RTW_WLAN_ACTION_VHT_COMPRESSED_BEAMFORMING:
  5842. #ifdef CONFIG_BEAMFORMING
  5843. /*RTW_INFO("RTW_WLAN_ACTION_VHT_COMPRESSED_BEAMFORMING\n");*/
  5844. rtw_beamforming_get_report_frame(padapter, precv_frame);
  5845. #endif /*CONFIG_BEAMFORMING*/
  5846. break;
  5847. case RTW_WLAN_ACTION_VHT_OPMODE_NOTIFICATION:
  5848. /* CategoryCode(1) + ActionCode(1) + OpModeNotification(1) */
  5849. /* RTW_INFO("RTW_WLAN_ACTION_VHT_OPMODE_NOTIFICATION\n"); */
  5850. psta = rtw_get_stainfo(&padapter->stapriv, whdr->addr2);
  5851. if (psta)
  5852. rtw_process_vht_op_mode_notify(padapter, &frame_body[2], psta);
  5853. break;
  5854. case RTW_WLAN_ACTION_VHT_GROUPID_MANAGEMENT:
  5855. #ifdef CONFIG_BEAMFORMING
  5856. #ifdef RTW_BEAMFORMING_VERSION_2
  5857. rtw_beamforming_get_vht_gid_mgnt_frame(padapter, precv_frame);
  5858. #endif /* RTW_BEAMFORMING_VERSION_2 */
  5859. #endif /* CONFIG_BEAMFORMING */
  5860. break;
  5861. default:
  5862. break;
  5863. }
  5864. exit:
  5865. #endif /* CONFIG_80211AC_VHT */
  5866. return _SUCCESS;
  5867. }
  5868. unsigned int OnAction_p2p(_adapter *padapter, union recv_frame *precv_frame)
  5869. {
  5870. #ifdef CONFIG_P2P
  5871. u8 *frame_body;
  5872. u8 category, OUI_Subtype, dialogToken = 0;
  5873. u8 *pframe = precv_frame->u.hdr.rx_data;
  5874. uint len = precv_frame->u.hdr.len;
  5875. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  5876. /* check RA matches or not */
  5877. if (!_rtw_memcmp(adapter_mac_addr(padapter), GetAddr1Ptr(pframe), ETH_ALEN))
  5878. return _SUCCESS;
  5879. frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
  5880. category = frame_body[0];
  5881. if (category != RTW_WLAN_CATEGORY_P2P)
  5882. return _SUCCESS;
  5883. if (cpu_to_be32(*((u32 *)(frame_body + 1))) != P2POUI)
  5884. return _SUCCESS;
  5885. #ifdef CONFIG_IOCTL_CFG80211
  5886. if (adapter_wdev_data(padapter)->p2p_enabled
  5887. && pwdinfo->driver_interface == DRIVER_CFG80211
  5888. ) {
  5889. rtw_cfg80211_rx_action_p2p(padapter, precv_frame);
  5890. return _SUCCESS;
  5891. } else
  5892. #endif /* CONFIG_IOCTL_CFG80211 */
  5893. {
  5894. len -= sizeof(struct rtw_ieee80211_hdr_3addr);
  5895. OUI_Subtype = frame_body[5];
  5896. dialogToken = frame_body[6];
  5897. switch (OUI_Subtype) {
  5898. case P2P_NOTICE_OF_ABSENCE:
  5899. break;
  5900. case P2P_PRESENCE_REQUEST:
  5901. process_p2p_presence_req(pwdinfo, pframe, len);
  5902. break;
  5903. case P2P_PRESENCE_RESPONSE:
  5904. break;
  5905. case P2P_GO_DISC_REQUEST:
  5906. break;
  5907. default:
  5908. break;
  5909. }
  5910. }
  5911. #endif /* CONFIG_P2P */
  5912. return _SUCCESS;
  5913. }
  5914. unsigned int OnAction(_adapter *padapter, union recv_frame *precv_frame)
  5915. {
  5916. int i;
  5917. unsigned char category;
  5918. struct action_handler *ptable;
  5919. unsigned char *frame_body;
  5920. u8 *pframe = precv_frame->u.hdr.rx_data;
  5921. frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
  5922. category = frame_body[0];
  5923. for (i = 0; i < sizeof(OnAction_tbl) / sizeof(struct action_handler); i++) {
  5924. ptable = &OnAction_tbl[i];
  5925. if (category == ptable->num)
  5926. ptable->func(padapter, precv_frame);
  5927. }
  5928. return _SUCCESS;
  5929. }
  5930. unsigned int DoReserved(_adapter *padapter, union recv_frame *precv_frame)
  5931. {
  5932. /* RTW_INFO("rcvd mgt frame(%x, %x)\n", (get_frame_sub_type(pframe) >> 4), *(unsigned int *)GetAddr1Ptr(pframe)); */
  5933. return _SUCCESS;
  5934. }
  5935. struct xmit_frame *_alloc_mgtxmitframe(struct xmit_priv *pxmitpriv, bool once)
  5936. {
  5937. struct xmit_frame *pmgntframe;
  5938. struct xmit_buf *pxmitbuf;
  5939. if (once)
  5940. pmgntframe = rtw_alloc_xmitframe_once(pxmitpriv);
  5941. else
  5942. pmgntframe = rtw_alloc_xmitframe_ext(pxmitpriv);
  5943. if (pmgntframe == NULL) {
  5944. RTW_INFO(FUNC_ADPT_FMT" alloc xmitframe fail, once:%d\n", FUNC_ADPT_ARG(pxmitpriv->adapter), once);
  5945. goto exit;
  5946. }
  5947. pxmitbuf = rtw_alloc_xmitbuf_ext(pxmitpriv);
  5948. if (pxmitbuf == NULL) {
  5949. RTW_INFO(FUNC_ADPT_FMT" alloc xmitbuf fail\n", FUNC_ADPT_ARG(pxmitpriv->adapter));
  5950. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  5951. pmgntframe = NULL;
  5952. goto exit;
  5953. }
  5954. pmgntframe->frame_tag = MGNT_FRAMETAG;
  5955. pmgntframe->pxmitbuf = pxmitbuf;
  5956. pmgntframe->buf_addr = pxmitbuf->pbuf;
  5957. pxmitbuf->priv_data = pmgntframe;
  5958. exit:
  5959. return pmgntframe;
  5960. }
  5961. inline struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv)
  5962. {
  5963. return _alloc_mgtxmitframe(pxmitpriv, _FALSE);
  5964. }
  5965. inline struct xmit_frame *alloc_mgtxmitframe_once(struct xmit_priv *pxmitpriv)
  5966. {
  5967. return _alloc_mgtxmitframe(pxmitpriv, _TRUE);
  5968. }
  5969. /****************************************************************************
  5970. Following are some TX fuctions for WiFi MLME
  5971. *****************************************************************************/
  5972. void update_mgnt_tx_rate(_adapter *padapter, u8 rate)
  5973. {
  5974. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  5975. pmlmeext->tx_rate = rate;
  5976. /* RTW_INFO("%s(): rate = %x\n",__FUNCTION__, rate); */
  5977. }
  5978. void update_monitor_frame_attrib(_adapter *padapter, struct pkt_attrib *pattrib)
  5979. {
  5980. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  5981. u8 wireless_mode;
  5982. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  5983. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  5984. struct sta_info *psta = NULL;
  5985. struct sta_priv *pstapriv = &padapter->stapriv;
  5986. struct sta_info *pbcmc_sta = NULL;
  5987. psta = rtw_get_stainfo(pstapriv, pattrib->ra);
  5988. pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
  5989. pattrib->hdrlen = 24;
  5990. pattrib->nr_frags = 1;
  5991. pattrib->priority = 7;
  5992. if (pbcmc_sta)
  5993. pattrib->mac_id = pbcmc_sta->mac_id;
  5994. else {
  5995. pattrib->mac_id = 0;
  5996. RTW_INFO("mgmt use mac_id 0 will affect RA\n");
  5997. }
  5998. pattrib->qsel = QSLT_MGNT;
  5999. pattrib->pktlen = 0;
  6000. if (pmlmeext->tx_rate == IEEE80211_CCK_RATE_1MB)
  6001. wireless_mode = WIRELESS_11B;
  6002. else
  6003. wireless_mode = WIRELESS_11G;
  6004. pattrib->raid = rtw_get_mgntframe_raid(padapter, wireless_mode);
  6005. #ifdef CONFIG_80211AC_VHT
  6006. if (pHalData->rf_type == RF_1T1R)
  6007. pattrib->raid = RATEID_IDX_VHT_1SS;
  6008. else if (pHalData->rf_type == RF_2T2R || pHalData->rf_type == RF_2T4R)
  6009. pattrib->raid = RATEID_IDX_VHT_2SS;
  6010. else if (pHalData->rf_type == RF_3T3R)
  6011. pattrib->raid = RATEID_IDX_VHT_3SS;
  6012. else
  6013. pattrib->raid = RATEID_IDX_BGN_40M_1SS;
  6014. #endif
  6015. #ifdef CONFIG_80211AC_VHT
  6016. pattrib->rate = MGN_VHT1SS_MCS9;
  6017. #else
  6018. pattrib->rate = MGN_MCS7;
  6019. #endif
  6020. pattrib->encrypt = _NO_PRIVACY_;
  6021. pattrib->bswenc = _FALSE;
  6022. pattrib->qos_en = _FALSE;
  6023. pattrib->ht_en = 1;
  6024. pattrib->bwmode = CHANNEL_WIDTH_20;
  6025. pattrib->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  6026. pattrib->sgi = _FALSE;
  6027. pattrib->seqnum = pmlmeext->mgnt_seq;
  6028. pattrib->retry_ctrl = _TRUE;
  6029. pattrib->mbssid = 0;
  6030. pattrib->hw_ssn_sel = pxmitpriv->hw_ssn_seq_no;
  6031. }
  6032. void update_mgntframe_attrib(_adapter *padapter, struct pkt_attrib *pattrib)
  6033. {
  6034. u8 wireless_mode;
  6035. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  6036. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  6037. struct sta_info *pbcmc_sta = NULL;
  6038. /* _rtw_memset((u8 *)(pattrib), 0, sizeof(struct pkt_attrib)); */
  6039. pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
  6040. pattrib->hdrlen = 24;
  6041. pattrib->nr_frags = 1;
  6042. pattrib->priority = 7;
  6043. if (pbcmc_sta)
  6044. pattrib->mac_id = pbcmc_sta->mac_id;
  6045. else {
  6046. pattrib->mac_id = 1; /* use STA's BCMC sta-info macid */
  6047. if (MLME_IS_AP(padapter) || MLME_IS_GO(padapter))
  6048. RTW_INFO("%s-"ADPT_FMT" get bcmc sta_info fail,use MACID=1\n", __func__, ADPT_ARG(padapter));
  6049. }
  6050. pattrib->qsel = QSLT_MGNT;
  6051. #ifdef CONFIG_MCC_MODE
  6052. update_mcc_mgntframe_attrib(padapter, pattrib);
  6053. #endif
  6054. pattrib->pktlen = 0;
  6055. if (IS_CCK_RATE(pmlmeext->tx_rate))
  6056. wireless_mode = WIRELESS_11B;
  6057. else
  6058. wireless_mode = WIRELESS_11G;
  6059. pattrib->raid = rtw_get_mgntframe_raid(padapter, wireless_mode);
  6060. pattrib->rate = pmlmeext->tx_rate;
  6061. pattrib->encrypt = _NO_PRIVACY_;
  6062. pattrib->bswenc = _FALSE;
  6063. pattrib->qos_en = _FALSE;
  6064. pattrib->ht_en = _FALSE;
  6065. pattrib->bwmode = CHANNEL_WIDTH_20;
  6066. pattrib->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  6067. pattrib->sgi = _FALSE;
  6068. pattrib->seqnum = pmlmeext->mgnt_seq;
  6069. pattrib->retry_ctrl = _TRUE;
  6070. pattrib->mbssid = 0;
  6071. pattrib->hw_ssn_sel = pxmitpriv->hw_ssn_seq_no;
  6072. }
  6073. void update_mgntframe_attrib_addr(_adapter *padapter, struct xmit_frame *pmgntframe)
  6074. {
  6075. u8 *pframe;
  6076. struct pkt_attrib *pattrib = &pmgntframe->attrib;
  6077. #ifdef CONFIG_BEAMFORMING
  6078. struct sta_info *sta = NULL;
  6079. #endif /* CONFIG_BEAMFORMING */
  6080. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  6081. _rtw_memcpy(pattrib->ra, GetAddr1Ptr(pframe), ETH_ALEN);
  6082. _rtw_memcpy(pattrib->ta, get_addr2_ptr(pframe), ETH_ALEN);
  6083. #ifdef CONFIG_BEAMFORMING
  6084. sta = pattrib->psta;
  6085. if (!sta) {
  6086. sta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
  6087. pattrib->psta = sta;
  6088. }
  6089. if (sta)
  6090. update_attrib_txbf_info(padapter, pattrib, sta);
  6091. #endif /* CONFIG_BEAMFORMING */
  6092. }
  6093. void dump_mgntframe(_adapter *padapter, struct xmit_frame *pmgntframe)
  6094. {
  6095. if (RTW_CANNOT_RUN(padapter)) {
  6096. rtw_free_xmitbuf(&padapter->xmitpriv, pmgntframe->pxmitbuf);
  6097. rtw_free_xmitframe(&padapter->xmitpriv, pmgntframe);
  6098. return;
  6099. }
  6100. rtw_hal_mgnt_xmit(padapter, pmgntframe);
  6101. }
  6102. s32 dump_mgntframe_and_wait(_adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms)
  6103. {
  6104. s32 ret = _FAIL;
  6105. _irqL irqL;
  6106. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  6107. struct xmit_buf *pxmitbuf = pmgntframe->pxmitbuf;
  6108. struct submit_ctx sctx;
  6109. if (RTW_CANNOT_RUN(padapter)) {
  6110. rtw_free_xmitbuf(&padapter->xmitpriv, pmgntframe->pxmitbuf);
  6111. rtw_free_xmitframe(&padapter->xmitpriv, pmgntframe);
  6112. return ret;
  6113. }
  6114. rtw_sctx_init(&sctx, timeout_ms);
  6115. pxmitbuf->sctx = &sctx;
  6116. ret = rtw_hal_mgnt_xmit(padapter, pmgntframe);
  6117. if (ret == _SUCCESS)
  6118. ret = rtw_sctx_wait(&sctx, __func__);
  6119. _enter_critical(&pxmitpriv->lock_sctx, &irqL);
  6120. pxmitbuf->sctx = NULL;
  6121. _exit_critical(&pxmitpriv->lock_sctx, &irqL);
  6122. return ret;
  6123. }
  6124. s32 dump_mgntframe_and_wait_ack_timeout(_adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms)
  6125. {
  6126. #ifdef CONFIG_XMIT_ACK
  6127. static u8 seq_no = 0;
  6128. s32 ret = _FAIL;
  6129. struct xmit_priv *pxmitpriv = &(GET_PRIMARY_ADAPTER(padapter))->xmitpriv;
  6130. if (RTW_CANNOT_RUN(padapter)) {
  6131. rtw_free_xmitbuf(&padapter->xmitpriv, pmgntframe->pxmitbuf);
  6132. rtw_free_xmitframe(&padapter->xmitpriv, pmgntframe);
  6133. return -1;
  6134. }
  6135. _enter_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
  6136. pxmitpriv->ack_tx = _TRUE;
  6137. pxmitpriv->seq_no = seq_no++;
  6138. pmgntframe->ack_report = 1;
  6139. rtw_sctx_init(&(pxmitpriv->ack_tx_ops), timeout_ms);
  6140. if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS)
  6141. ret = rtw_sctx_wait(&(pxmitpriv->ack_tx_ops), __func__);
  6142. pxmitpriv->ack_tx = _FALSE;
  6143. _exit_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
  6144. return ret;
  6145. #else /* !CONFIG_XMIT_ACK */
  6146. dump_mgntframe(padapter, pmgntframe);
  6147. rtw_msleep_os(50);
  6148. return _SUCCESS;
  6149. #endif /* !CONFIG_XMIT_ACK */
  6150. }
  6151. s32 dump_mgntframe_and_wait_ack(_adapter *padapter, struct xmit_frame *pmgntframe)
  6152. {
  6153. /* In this case, use 500 ms as the default wait_ack timeout */
  6154. return dump_mgntframe_and_wait_ack_timeout(padapter, pmgntframe, 500);
  6155. }
  6156. int update_hidden_ssid(u8 *ies, u32 ies_len, u8 hidden_ssid_mode)
  6157. {
  6158. u8 *ssid_ie;
  6159. sint ssid_len_ori;
  6160. int len_diff = 0;
  6161. ssid_ie = rtw_get_ie(ies, WLAN_EID_SSID, &ssid_len_ori, ies_len);
  6162. /* RTW_INFO("%s hidden_ssid_mode:%u, ssid_ie:%p, ssid_len_ori:%d\n", __FUNCTION__, hidden_ssid_mode, ssid_ie, ssid_len_ori); */
  6163. if (ssid_ie && ssid_len_ori > 0) {
  6164. switch (hidden_ssid_mode) {
  6165. case 1: {
  6166. u8 *next_ie = ssid_ie + 2 + ssid_len_ori;
  6167. u32 remain_len = 0;
  6168. remain_len = ies_len - (next_ie - ies);
  6169. ssid_ie[1] = 0;
  6170. _rtw_memcpy(ssid_ie + 2, next_ie, remain_len);
  6171. len_diff -= ssid_len_ori;
  6172. break;
  6173. }
  6174. case 2:
  6175. _rtw_memset(&ssid_ie[2], 0, ssid_len_ori);
  6176. break;
  6177. default:
  6178. break;
  6179. }
  6180. }
  6181. return len_diff;
  6182. }
  6183. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  6184. u32 rtw_build_vendor_ie(_adapter *padapter , unsigned char *pframe , u8 mgmt_frame_tyte)
  6185. {
  6186. int vendor_ie_num = 0;
  6187. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6188. u32 len = 0;
  6189. for (vendor_ie_num = 0 ; vendor_ie_num < WLAN_MAX_VENDOR_IE_NUM ; vendor_ie_num++) {
  6190. if (pmlmepriv->vendor_ielen[vendor_ie_num] > 0 && pmlmepriv->vendor_ie_mask[vendor_ie_num] & mgmt_frame_tyte) {
  6191. _rtw_memcpy(pframe , pmlmepriv->vendor_ie[vendor_ie_num] , pmlmepriv->vendor_ielen[vendor_ie_num]);
  6192. pframe += pmlmepriv->vendor_ielen[vendor_ie_num];
  6193. len += pmlmepriv->vendor_ielen[vendor_ie_num];
  6194. }
  6195. }
  6196. return len;
  6197. }
  6198. #endif
  6199. void issue_beacon(_adapter *padapter, int timeout_ms)
  6200. {
  6201. struct xmit_frame *pmgntframe;
  6202. struct pkt_attrib *pattrib;
  6203. unsigned char *pframe;
  6204. struct rtw_ieee80211_hdr *pwlanhdr;
  6205. unsigned short *fctrl;
  6206. unsigned int rate_len;
  6207. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  6208. #if defined(CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
  6209. _irqL irqL;
  6210. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6211. #endif /* #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME) */
  6212. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  6213. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  6214. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  6215. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  6216. #ifdef CONFIG_P2P
  6217. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  6218. #endif /* CONFIG_P2P */
  6219. /* RTW_INFO("%s\n", __FUNCTION__); */
  6220. #ifdef CONFIG_BCN_ICF
  6221. pmgntframe = rtw_alloc_bcnxmitframe(pxmitpriv);
  6222. if (pmgntframe == NULL)
  6223. #else
  6224. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  6225. if (pmgntframe == NULL)
  6226. #endif
  6227. {
  6228. RTW_INFO("%s, alloc mgnt frame fail\n", __FUNCTION__);
  6229. return;
  6230. }
  6231. #if defined(CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
  6232. _enter_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
  6233. #endif /* #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME) */
  6234. /* update attribute */
  6235. pattrib = &pmgntframe->attrib;
  6236. update_mgntframe_attrib(padapter, pattrib);
  6237. pattrib->qsel = QSLT_BEACON;
  6238. #if defined(CONFIG_CONCURRENT_MODE) && (!defined(CONFIG_SWTIMER_BASED_TXBCN))
  6239. if (padapter->hw_port == HW_PORT1)
  6240. pattrib->mbssid = 1;
  6241. #endif
  6242. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  6243. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  6244. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  6245. fctrl = &(pwlanhdr->frame_ctl);
  6246. *(fctrl) = 0;
  6247. _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
  6248. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  6249. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN);
  6250. SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
  6251. /* pmlmeext->mgnt_seq++; */
  6252. set_frame_sub_type(pframe, WIFI_BEACON);
  6253. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  6254. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  6255. if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
  6256. /* RTW_INFO("ie len=%d\n", cur_network->IELength); */
  6257. #ifdef CONFIG_P2P
  6258. /* for P2P : Primary Device Type & Device Name */
  6259. u32 wpsielen = 0, insert_len = 0;
  6260. u8 *wpsie = NULL;
  6261. wpsie = rtw_get_wps_ie(cur_network->IEs + _FIXED_IE_LENGTH_, cur_network->IELength - _FIXED_IE_LENGTH_, NULL, &wpsielen);
  6262. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && wpsie && wpsielen > 0) {
  6263. uint wps_offset, remainder_ielen;
  6264. u8 *premainder_ie, *pframe_wscie;
  6265. wps_offset = (uint)(wpsie - cur_network->IEs);
  6266. premainder_ie = wpsie + wpsielen;
  6267. remainder_ielen = cur_network->IELength - wps_offset - wpsielen;
  6268. #ifdef CONFIG_IOCTL_CFG80211
  6269. if (adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211) {
  6270. if (pmlmepriv->wps_beacon_ie && pmlmepriv->wps_beacon_ie_len > 0) {
  6271. _rtw_memcpy(pframe, cur_network->IEs, wps_offset);
  6272. pframe += wps_offset;
  6273. pattrib->pktlen += wps_offset;
  6274. _rtw_memcpy(pframe, pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len);
  6275. pframe += pmlmepriv->wps_beacon_ie_len;
  6276. pattrib->pktlen += pmlmepriv->wps_beacon_ie_len;
  6277. /* copy remainder_ie to pframe */
  6278. _rtw_memcpy(pframe, premainder_ie, remainder_ielen);
  6279. pframe += remainder_ielen;
  6280. pattrib->pktlen += remainder_ielen;
  6281. } else {
  6282. _rtw_memcpy(pframe, cur_network->IEs, cur_network->IELength);
  6283. pframe += cur_network->IELength;
  6284. pattrib->pktlen += cur_network->IELength;
  6285. }
  6286. } else
  6287. #endif /* CONFIG_IOCTL_CFG80211 */
  6288. {
  6289. pframe_wscie = pframe + wps_offset;
  6290. _rtw_memcpy(pframe, cur_network->IEs, wps_offset + wpsielen);
  6291. pframe += (wps_offset + wpsielen);
  6292. pattrib->pktlen += (wps_offset + wpsielen);
  6293. /* now pframe is end of wsc ie, insert Primary Device Type & Device Name */
  6294. /* Primary Device Type */
  6295. /* Type: */
  6296. *(u16 *)(pframe + insert_len) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
  6297. insert_len += 2;
  6298. /* Length: */
  6299. *(u16 *)(pframe + insert_len) = cpu_to_be16(0x0008);
  6300. insert_len += 2;
  6301. /* Value: */
  6302. /* Category ID */
  6303. *(u16 *)(pframe + insert_len) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
  6304. insert_len += 2;
  6305. /* OUI */
  6306. *(u32 *)(pframe + insert_len) = cpu_to_be32(WPSOUI);
  6307. insert_len += 4;
  6308. /* Sub Category ID */
  6309. *(u16 *)(pframe + insert_len) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
  6310. insert_len += 2;
  6311. /* Device Name */
  6312. /* Type: */
  6313. *(u16 *)(pframe + insert_len) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
  6314. insert_len += 2;
  6315. /* Length: */
  6316. *(u16 *)(pframe + insert_len) = cpu_to_be16(pwdinfo->device_name_len);
  6317. insert_len += 2;
  6318. /* Value: */
  6319. _rtw_memcpy(pframe + insert_len, pwdinfo->device_name, pwdinfo->device_name_len);
  6320. insert_len += pwdinfo->device_name_len;
  6321. /* update wsc ie length */
  6322. *(pframe_wscie + 1) = (wpsielen - 2) + insert_len;
  6323. /* pframe move to end */
  6324. pframe += insert_len;
  6325. pattrib->pktlen += insert_len;
  6326. /* copy remainder_ie to pframe */
  6327. _rtw_memcpy(pframe, premainder_ie, remainder_ielen);
  6328. pframe += remainder_ielen;
  6329. pattrib->pktlen += remainder_ielen;
  6330. }
  6331. } else
  6332. #endif /* CONFIG_P2P */
  6333. {
  6334. int len_diff;
  6335. _rtw_memcpy(pframe, cur_network->IEs, cur_network->IELength);
  6336. len_diff = update_hidden_ssid(
  6337. pframe + _BEACON_IE_OFFSET_
  6338. , cur_network->IELength - _BEACON_IE_OFFSET_
  6339. , pmlmeinfo->hidden_ssid_mode
  6340. );
  6341. pframe += (cur_network->IELength + len_diff);
  6342. pattrib->pktlen += (cur_network->IELength + len_diff);
  6343. }
  6344. {
  6345. u8 *wps_ie;
  6346. uint wps_ielen;
  6347. u8 sr = 0;
  6348. wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr + TXDESC_OFFSET + sizeof(struct rtw_ieee80211_hdr_3addr) + _BEACON_IE_OFFSET_,
  6349. pattrib->pktlen - sizeof(struct rtw_ieee80211_hdr_3addr) - _BEACON_IE_OFFSET_, NULL, &wps_ielen);
  6350. if (wps_ie && wps_ielen > 0)
  6351. rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
  6352. if (sr != 0)
  6353. set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
  6354. else
  6355. _clr_fwstate_(pmlmepriv, WIFI_UNDER_WPS);
  6356. }
  6357. #ifdef CONFIG_P2P
  6358. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  6359. u32 len;
  6360. #ifdef CONFIG_IOCTL_CFG80211
  6361. if (adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211) {
  6362. len = pmlmepriv->p2p_beacon_ie_len;
  6363. if (pmlmepriv->p2p_beacon_ie && len > 0)
  6364. _rtw_memcpy(pframe, pmlmepriv->p2p_beacon_ie, len);
  6365. } else
  6366. #endif /* CONFIG_IOCTL_CFG80211 */
  6367. {
  6368. len = build_beacon_p2p_ie(pwdinfo, pframe);
  6369. }
  6370. pframe += len;
  6371. pattrib->pktlen += len;
  6372. #ifdef CONFIG_MCC_MODE
  6373. pframe = rtw_hal_mcc_append_go_p2p_ie(padapter, pframe, &pattrib->pktlen);
  6374. #endif /* CONFIG_MCC_MODE*/
  6375. #ifdef CONFIG_WFD
  6376. len = rtw_append_beacon_wfd_ie(padapter, pframe);
  6377. pframe += len;
  6378. pattrib->pktlen += len;
  6379. #endif
  6380. }
  6381. #endif /* CONFIG_P2P */
  6382. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  6383. pattrib->pktlen += rtw_build_vendor_ie(padapter , pframe , WIFI_BEACON_VENDOR_IE_BIT);
  6384. #endif
  6385. goto _issue_bcn;
  6386. }
  6387. /* below for ad-hoc mode */
  6388. /* timestamp will be inserted by hardware */
  6389. pframe += 8;
  6390. pattrib->pktlen += 8;
  6391. /* beacon interval: 2 bytes */
  6392. _rtw_memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
  6393. pframe += 2;
  6394. pattrib->pktlen += 2;
  6395. /* capability info: 2 bytes */
  6396. _rtw_memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
  6397. pframe += 2;
  6398. pattrib->pktlen += 2;
  6399. /* SSID */
  6400. pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
  6401. /* supported rates... */
  6402. rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
  6403. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
  6404. /* DS parameter set */
  6405. pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
  6406. /* if( (pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) */
  6407. {
  6408. u8 erpinfo = 0;
  6409. u32 ATIMWindow;
  6410. /* IBSS Parameter Set... */
  6411. /* ATIMWindow = cur->Configuration.ATIMWindow; */
  6412. ATIMWindow = 0;
  6413. pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
  6414. /* ERP IE */
  6415. pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
  6416. }
  6417. /* EXTERNDED SUPPORTED RATE */
  6418. if (rate_len > 8)
  6419. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
  6420. /* todo:HT for adhoc */
  6421. _issue_bcn:
  6422. #if defined(CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
  6423. pmlmepriv->update_bcn = _FALSE;
  6424. _exit_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
  6425. #endif /* #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME) */
  6426. if ((pattrib->pktlen + TXDESC_SIZE) > 512) {
  6427. RTW_INFO("beacon frame too large\n");
  6428. return;
  6429. }
  6430. pattrib->last_txcmdsz = pattrib->pktlen;
  6431. /* RTW_INFO("issue bcn_sz=%d\n", pattrib->last_txcmdsz); */
  6432. if (timeout_ms > 0)
  6433. dump_mgntframe_and_wait(padapter, pmgntframe, timeout_ms);
  6434. else
  6435. dump_mgntframe(padapter, pmgntframe);
  6436. }
  6437. void issue_probersp(_adapter *padapter, unsigned char *da, u8 is_valid_p2p_probereq)
  6438. {
  6439. struct xmit_frame *pmgntframe;
  6440. struct pkt_attrib *pattrib;
  6441. unsigned char *pframe;
  6442. struct rtw_ieee80211_hdr *pwlanhdr;
  6443. unsigned short *fctrl;
  6444. unsigned char *mac, *bssid;
  6445. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  6446. #if defined(CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
  6447. u8 *pwps_ie;
  6448. uint wps_ielen;
  6449. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  6450. #endif /* #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME) */
  6451. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  6452. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  6453. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  6454. unsigned int rate_len;
  6455. #ifdef CONFIG_P2P
  6456. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  6457. #ifdef CONFIG_WFD
  6458. u32 wfdielen = 0;
  6459. #endif
  6460. #endif /* CONFIG_P2P */
  6461. /* RTW_INFO("%s\n", __FUNCTION__); */
  6462. if (da == NULL)
  6463. return;
  6464. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  6465. return;
  6466. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  6467. if (pmgntframe == NULL) {
  6468. RTW_INFO("%s, alloc mgnt frame fail\n", __FUNCTION__);
  6469. return;
  6470. }
  6471. /* update attribute */
  6472. pattrib = &pmgntframe->attrib;
  6473. update_mgntframe_attrib(padapter, pattrib);
  6474. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  6475. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  6476. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  6477. mac = adapter_mac_addr(padapter);
  6478. bssid = cur_network->MacAddress;
  6479. fctrl = &(pwlanhdr->frame_ctl);
  6480. *(fctrl) = 0;
  6481. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  6482. _rtw_memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
  6483. _rtw_memcpy(pwlanhdr->addr3, bssid, ETH_ALEN);
  6484. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  6485. pmlmeext->mgnt_seq++;
  6486. set_frame_sub_type(fctrl, WIFI_PROBERSP);
  6487. pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  6488. pattrib->pktlen = pattrib->hdrlen;
  6489. pframe += pattrib->hdrlen;
  6490. if (cur_network->IELength > MAX_IE_SZ)
  6491. return;
  6492. #if defined(CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
  6493. if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
  6494. pwps_ie = rtw_get_wps_ie(cur_network->IEs + _FIXED_IE_LENGTH_, cur_network->IELength - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
  6495. /* inerset & update wps_probe_resp_ie */
  6496. if ((pmlmepriv->wps_probe_resp_ie != NULL) && pwps_ie && (wps_ielen > 0)) {
  6497. uint wps_offset, remainder_ielen;
  6498. u8 *premainder_ie;
  6499. wps_offset = (uint)(pwps_ie - cur_network->IEs);
  6500. premainder_ie = pwps_ie + wps_ielen;
  6501. remainder_ielen = cur_network->IELength - wps_offset - wps_ielen;
  6502. _rtw_memcpy(pframe, cur_network->IEs, wps_offset);
  6503. pframe += wps_offset;
  6504. pattrib->pktlen += wps_offset;
  6505. wps_ielen = (uint)pmlmepriv->wps_probe_resp_ie[1];/* to get ie data len */
  6506. if ((wps_offset + wps_ielen + 2) <= MAX_IE_SZ) {
  6507. _rtw_memcpy(pframe, pmlmepriv->wps_probe_resp_ie, wps_ielen + 2);
  6508. pframe += wps_ielen + 2;
  6509. pattrib->pktlen += wps_ielen + 2;
  6510. }
  6511. if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
  6512. _rtw_memcpy(pframe, premainder_ie, remainder_ielen);
  6513. pframe += remainder_ielen;
  6514. pattrib->pktlen += remainder_ielen;
  6515. }
  6516. } else {
  6517. _rtw_memcpy(pframe, cur_network->IEs, cur_network->IELength);
  6518. pframe += cur_network->IELength;
  6519. pattrib->pktlen += cur_network->IELength;
  6520. }
  6521. /* retrieve SSID IE from cur_network->Ssid */
  6522. {
  6523. u8 *ssid_ie;
  6524. sint ssid_ielen;
  6525. sint ssid_ielen_diff;
  6526. u8 buf[MAX_IE_SZ];
  6527. u8 *ies = pmgntframe->buf_addr + TXDESC_OFFSET + sizeof(struct rtw_ieee80211_hdr_3addr);
  6528. ssid_ie = rtw_get_ie(ies + _FIXED_IE_LENGTH_, _SSID_IE_, &ssid_ielen,
  6529. (pframe - ies) - _FIXED_IE_LENGTH_);
  6530. ssid_ielen_diff = cur_network->Ssid.SsidLength - ssid_ielen;
  6531. if (ssid_ie && cur_network->Ssid.SsidLength) {
  6532. uint remainder_ielen;
  6533. u8 *remainder_ie;
  6534. remainder_ie = ssid_ie + 2;
  6535. remainder_ielen = (pframe - remainder_ie);
  6536. if (remainder_ielen > MAX_IE_SZ) {
  6537. RTW_WARN(FUNC_ADPT_FMT" remainder_ielen > MAX_IE_SZ\n", FUNC_ADPT_ARG(padapter));
  6538. remainder_ielen = MAX_IE_SZ;
  6539. }
  6540. _rtw_memcpy(buf, remainder_ie, remainder_ielen);
  6541. _rtw_memcpy(remainder_ie + ssid_ielen_diff, buf, remainder_ielen);
  6542. *(ssid_ie + 1) = cur_network->Ssid.SsidLength;
  6543. _rtw_memcpy(ssid_ie + 2, cur_network->Ssid.Ssid, cur_network->Ssid.SsidLength);
  6544. pframe += ssid_ielen_diff;
  6545. pattrib->pktlen += ssid_ielen_diff;
  6546. }
  6547. }
  6548. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  6549. pattrib->pktlen += rtw_build_vendor_ie(padapter , pframe , WIFI_PROBERESP_VENDOR_IE_BIT);
  6550. #endif
  6551. } else
  6552. #endif
  6553. {
  6554. /* timestamp will be inserted by hardware */
  6555. pframe += 8;
  6556. pattrib->pktlen += 8;
  6557. /* beacon interval: 2 bytes */
  6558. _rtw_memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
  6559. pframe += 2;
  6560. pattrib->pktlen += 2;
  6561. /* capability info: 2 bytes */
  6562. _rtw_memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
  6563. pframe += 2;
  6564. pattrib->pktlen += 2;
  6565. /* below for ad-hoc mode */
  6566. /* SSID */
  6567. pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
  6568. /* supported rates... */
  6569. rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
  6570. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
  6571. /* DS parameter set */
  6572. pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
  6573. if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) {
  6574. u8 erpinfo = 0;
  6575. u32 ATIMWindow;
  6576. /* IBSS Parameter Set... */
  6577. /* ATIMWindow = cur->Configuration.ATIMWindow; */
  6578. ATIMWindow = 0;
  6579. pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
  6580. /* ERP IE */
  6581. pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
  6582. }
  6583. /* EXTERNDED SUPPORTED RATE */
  6584. if (rate_len > 8)
  6585. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
  6586. /* todo:HT for adhoc */
  6587. }
  6588. #ifdef CONFIG_P2P
  6589. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)
  6590. /* IOT issue, When wifi_spec is not set, send probe_resp with P2P IE even if probe_req has no P2P IE */
  6591. && (is_valid_p2p_probereq || !padapter->registrypriv.wifi_spec)) {
  6592. u32 len;
  6593. #ifdef CONFIG_IOCTL_CFG80211
  6594. if (adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211) {
  6595. /* if pwdinfo->role == P2P_ROLE_DEVICE will call issue_probersp_p2p() */
  6596. len = pmlmepriv->p2p_go_probe_resp_ie_len;
  6597. if (pmlmepriv->p2p_go_probe_resp_ie && len > 0)
  6598. _rtw_memcpy(pframe, pmlmepriv->p2p_go_probe_resp_ie, len);
  6599. } else
  6600. #endif /* CONFIG_IOCTL_CFG80211 */
  6601. {
  6602. len = build_probe_resp_p2p_ie(pwdinfo, pframe);
  6603. }
  6604. pframe += len;
  6605. pattrib->pktlen += len;
  6606. #ifdef CONFIG_MCC_MODE
  6607. pframe = rtw_hal_mcc_append_go_p2p_ie(padapter, pframe, &pattrib->pktlen);
  6608. #endif /* CONFIG_MCC_MODE*/
  6609. #ifdef CONFIG_WFD
  6610. len = rtw_append_probe_resp_wfd_ie(padapter, pframe);
  6611. pframe += len;
  6612. pattrib->pktlen += len;
  6613. #endif
  6614. }
  6615. #endif /* CONFIG_P2P */
  6616. #ifdef CONFIG_AUTO_AP_MODE
  6617. {
  6618. struct sta_info *psta;
  6619. struct sta_priv *pstapriv = &padapter->stapriv;
  6620. RTW_INFO("(%s)\n", __FUNCTION__);
  6621. /* check rc station */
  6622. psta = rtw_get_stainfo(pstapriv, da);
  6623. if (psta && psta->isrc && psta->pid > 0) {
  6624. u8 RC_OUI[4] = {0x00, 0xE0, 0x4C, 0x0A};
  6625. u8 RC_INFO[14] = {0};
  6626. /* EID[1] + EID_LEN[1] + RC_OUI[4] + MAC[6] + PairingID[2] + ChannelNum[2] */
  6627. u16 cu_ch = (u16)cur_network->Configuration.DSConfig;
  6628. RTW_INFO("%s, reply rc(pid=0x%x) device "MAC_FMT" in ch=%d\n", __FUNCTION__,
  6629. psta->pid, MAC_ARG(psta->hwaddr), cu_ch);
  6630. /* append vendor specific ie */
  6631. _rtw_memcpy(RC_INFO, RC_OUI, sizeof(RC_OUI));
  6632. _rtw_memcpy(&RC_INFO[4], mac, ETH_ALEN);
  6633. _rtw_memcpy(&RC_INFO[10], (u8 *)&psta->pid, 2);
  6634. _rtw_memcpy(&RC_INFO[12], (u8 *)&cu_ch, 2);
  6635. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, sizeof(RC_INFO), RC_INFO, &pattrib->pktlen);
  6636. }
  6637. }
  6638. #endif /* CONFIG_AUTO_AP_MODE */
  6639. pattrib->last_txcmdsz = pattrib->pktlen;
  6640. dump_mgntframe(padapter, pmgntframe);
  6641. return;
  6642. }
  6643. int _issue_probereq(_adapter *padapter, NDIS_802_11_SSID *pssid, u8 *da, u8 ch, bool append_wps, int wait_ack)
  6644. {
  6645. int ret = _FAIL;
  6646. struct xmit_frame *pmgntframe;
  6647. struct pkt_attrib *pattrib;
  6648. unsigned char *pframe;
  6649. struct rtw_ieee80211_hdr *pwlanhdr;
  6650. unsigned short *fctrl;
  6651. unsigned char *mac;
  6652. unsigned char bssrate[NumRates];
  6653. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  6654. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6655. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  6656. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  6657. int bssrate_len = 0;
  6658. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  6659. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  6660. goto exit;
  6661. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  6662. if (pmgntframe == NULL)
  6663. goto exit;
  6664. /* update attribute */
  6665. pattrib = &pmgntframe->attrib;
  6666. update_mgntframe_attrib(padapter, pattrib);
  6667. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  6668. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  6669. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  6670. mac = adapter_mac_addr(padapter);
  6671. fctrl = &(pwlanhdr->frame_ctl);
  6672. *(fctrl) = 0;
  6673. if (da) {
  6674. /* unicast probe request frame */
  6675. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  6676. _rtw_memcpy(pwlanhdr->addr3, da, ETH_ALEN);
  6677. } else {
  6678. /* broadcast probe request frame */
  6679. _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
  6680. _rtw_memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
  6681. }
  6682. _rtw_memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
  6683. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  6684. pmlmeext->mgnt_seq++;
  6685. set_frame_sub_type(pframe, WIFI_PROBEREQ);
  6686. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  6687. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  6688. if (pssid)
  6689. pframe = rtw_set_ie(pframe, _SSID_IE_, pssid->SsidLength, pssid->Ssid, &(pattrib->pktlen));
  6690. else
  6691. pframe = rtw_set_ie(pframe, _SSID_IE_, 0, NULL, &(pattrib->pktlen));
  6692. get_rate_set(padapter, bssrate, &bssrate_len);
  6693. if (bssrate_len > 8) {
  6694. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
  6695. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
  6696. } else
  6697. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
  6698. if (ch)
  6699. pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, &ch, &pattrib->pktlen);
  6700. if (append_wps) {
  6701. /* add wps_ie for wps2.0 */
  6702. if (pmlmepriv->wps_probe_req_ie_len > 0 && pmlmepriv->wps_probe_req_ie) {
  6703. _rtw_memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
  6704. pframe += pmlmepriv->wps_probe_req_ie_len;
  6705. pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
  6706. /* pmlmepriv->wps_probe_req_ie_len = 0 ; */ /* reset to zero */
  6707. }
  6708. }
  6709. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  6710. pattrib->pktlen += rtw_build_vendor_ie(padapter , pframe , WIFI_PROBEREQ_VENDOR_IE_BIT);
  6711. #endif
  6712. pattrib->last_txcmdsz = pattrib->pktlen;
  6713. if (wait_ack)
  6714. ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
  6715. else {
  6716. dump_mgntframe(padapter, pmgntframe);
  6717. ret = _SUCCESS;
  6718. }
  6719. exit:
  6720. return ret;
  6721. }
  6722. inline void issue_probereq(_adapter *padapter, NDIS_802_11_SSID *pssid, u8 *da)
  6723. {
  6724. _issue_probereq(padapter, pssid, da, 0, 1, _FALSE);
  6725. }
  6726. /*
  6727. * wait_ms == 0 means that there is no need to wait ack through C2H_CCX_TX_RPT
  6728. * wait_ms > 0 means you want to wait ack through C2H_CCX_TX_RPT, and the value of wait_ms means the interval between each TX
  6729. * try_cnt means the maximal TX count to try
  6730. */
  6731. int issue_probereq_ex(_adapter *padapter, NDIS_802_11_SSID *pssid, u8 *da, u8 ch, bool append_wps,
  6732. int try_cnt, int wait_ms)
  6733. {
  6734. int ret = _FAIL;
  6735. int i = 0;
  6736. u32 start = rtw_get_current_time();
  6737. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  6738. goto exit;
  6739. do {
  6740. ret = _issue_probereq(padapter, pssid, da, ch, append_wps, wait_ms > 0 ? _TRUE : _FALSE);
  6741. i++;
  6742. if (RTW_CANNOT_RUN(padapter))
  6743. break;
  6744. if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
  6745. rtw_msleep_os(wait_ms);
  6746. } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
  6747. if (ret != _FAIL) {
  6748. ret = _SUCCESS;
  6749. #ifndef DBG_XMIT_ACK
  6750. goto exit;
  6751. #endif
  6752. }
  6753. if (try_cnt && wait_ms) {
  6754. if (da)
  6755. RTW_INFO(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
  6756. FUNC_ADPT_ARG(padapter), MAC_ARG(da), rtw_get_oper_ch(padapter),
  6757. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  6758. else
  6759. RTW_INFO(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
  6760. FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
  6761. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  6762. }
  6763. exit:
  6764. return ret;
  6765. }
  6766. /* if psta == NULL, indiate we are station(client) now... */
  6767. void issue_auth(_adapter *padapter, struct sta_info *psta, unsigned short status)
  6768. {
  6769. struct xmit_frame *pmgntframe;
  6770. struct pkt_attrib *pattrib;
  6771. unsigned char *pframe;
  6772. struct rtw_ieee80211_hdr *pwlanhdr;
  6773. unsigned short *fctrl;
  6774. unsigned int val32;
  6775. unsigned short val16;
  6776. int use_shared_key = 0;
  6777. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  6778. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  6779. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  6780. #ifdef CONFIG_RTW_80211R
  6781. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6782. ft_priv *pftpriv = &pmlmepriv->ftpriv;
  6783. u8 is_ft_roaming = _FALSE;
  6784. u8 is_ft_roaming_with_rsn_ie = _TRUE;
  6785. u8 *pie = NULL;
  6786. u32 ft_ie_len = 0;
  6787. #endif
  6788. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  6789. return;
  6790. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  6791. if (pmgntframe == NULL)
  6792. return;
  6793. /* update attribute */
  6794. pattrib = &pmgntframe->attrib;
  6795. update_mgntframe_attrib(padapter, pattrib);
  6796. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  6797. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  6798. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  6799. fctrl = &(pwlanhdr->frame_ctl);
  6800. *(fctrl) = 0;
  6801. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  6802. pmlmeext->mgnt_seq++;
  6803. set_frame_sub_type(pframe, WIFI_AUTH);
  6804. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  6805. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  6806. if (psta) { /* for AP mode */
  6807. #ifdef CONFIG_NATIVEAP_MLME
  6808. _rtw_memcpy(pwlanhdr->addr1, psta->hwaddr, ETH_ALEN);
  6809. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  6810. _rtw_memcpy(pwlanhdr->addr3, adapter_mac_addr(padapter), ETH_ALEN);
  6811. /* setting auth algo number */
  6812. val16 = (u16)psta->authalg;
  6813. if (status != _STATS_SUCCESSFUL_)
  6814. val16 = 0;
  6815. if (val16) {
  6816. val16 = cpu_to_le16(val16);
  6817. use_shared_key = 1;
  6818. }
  6819. pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&val16, &(pattrib->pktlen));
  6820. /* setting auth seq number */
  6821. val16 = (u16)psta->auth_seq;
  6822. val16 = cpu_to_le16(val16);
  6823. pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&val16, &(pattrib->pktlen));
  6824. /* setting status code... */
  6825. val16 = status;
  6826. val16 = cpu_to_le16(val16);
  6827. pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&val16, &(pattrib->pktlen));
  6828. /* added challenging text... */
  6829. if ((psta->auth_seq == 2) && (psta->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1))
  6830. pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, psta->chg_txt, &(pattrib->pktlen));
  6831. #endif
  6832. } else {
  6833. _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
  6834. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  6835. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
  6836. #ifdef CONFIG_RTW_80211R
  6837. /*For Fast BSS Transition */
  6838. if ((rtw_to_roam(padapter) > 0) && rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED)) {
  6839. is_ft_roaming = _TRUE;
  6840. val16 = 2; /* 2: 802.11R FTAA */
  6841. val16 = cpu_to_le16(val16);
  6842. } else
  6843. #endif
  6844. {
  6845. /* setting auth algo number */
  6846. val16 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) ? 1 : 0; /* 0:OPEN System, 1:Shared key */
  6847. if (val16) {
  6848. val16 = cpu_to_le16(val16);
  6849. use_shared_key = 1;
  6850. }
  6851. }
  6852. /* RTW_INFO("%s auth_algo= %s auth_seq=%d\n",__FUNCTION__,(pmlmeinfo->auth_algo==0)?"OPEN":"SHARED",pmlmeinfo->auth_seq); */
  6853. /* setting IV for auth seq #3 */
  6854. if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
  6855. /* RTW_INFO("==> iv(%d),key_index(%d)\n",pmlmeinfo->iv,pmlmeinfo->key_index); */
  6856. val32 = ((pmlmeinfo->iv++) | (pmlmeinfo->key_index << 30));
  6857. val32 = cpu_to_le32(val32);
  6858. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&val32, &(pattrib->pktlen));
  6859. pattrib->iv_len = 4;
  6860. }
  6861. pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&val16, &(pattrib->pktlen));
  6862. /* setting auth seq number */
  6863. val16 = pmlmeinfo->auth_seq;
  6864. val16 = cpu_to_le16(val16);
  6865. pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&val16, &(pattrib->pktlen));
  6866. /* setting status code... */
  6867. val16 = status;
  6868. val16 = cpu_to_le16(val16);
  6869. pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&val16, &(pattrib->pktlen));
  6870. #ifdef CONFIG_RTW_80211R
  6871. if (is_ft_roaming == _TRUE) {
  6872. pie = rtw_get_ie(pftpriv->updated_ft_ies, EID_WPA2, &ft_ie_len, pftpriv->updated_ft_ies_len);
  6873. if (pie)
  6874. pframe = rtw_set_ie(pframe, EID_WPA2, ft_ie_len, pie+2, &(pattrib->pktlen));
  6875. else
  6876. is_ft_roaming_with_rsn_ie = _FALSE;
  6877. pie = rtw_get_ie(pftpriv->updated_ft_ies, _MDIE_, &ft_ie_len, pftpriv->updated_ft_ies_len);
  6878. if (pie)
  6879. pframe = rtw_set_ie(pframe, _MDIE_, ft_ie_len , pie+2, &(pattrib->pktlen));
  6880. pie = rtw_get_ie(pftpriv->updated_ft_ies, _FTIE_, &ft_ie_len, pftpriv->updated_ft_ies_len);
  6881. if (pie && is_ft_roaming_with_rsn_ie)
  6882. pframe = rtw_set_ie(pframe, _FTIE_, ft_ie_len , pie+2, &(pattrib->pktlen));
  6883. }
  6884. #endif
  6885. /* then checking to see if sending challenging text... */
  6886. if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
  6887. pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, pmlmeinfo->chg_txt, &(pattrib->pktlen));
  6888. SetPrivacy(fctrl);
  6889. pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  6890. pattrib->encrypt = _WEP40_;
  6891. pattrib->icv_len = 4;
  6892. pattrib->pktlen += pattrib->icv_len;
  6893. }
  6894. }
  6895. pattrib->last_txcmdsz = pattrib->pktlen;
  6896. rtw_wep_encrypt(padapter, (u8 *)pmgntframe);
  6897. RTW_INFO("%s\n", __FUNCTION__);
  6898. dump_mgntframe(padapter, pmgntframe);
  6899. return;
  6900. }
  6901. void issue_asocrsp(_adapter *padapter, unsigned short status, struct sta_info *pstat, int pkt_type)
  6902. {
  6903. #ifdef CONFIG_AP_MODE
  6904. struct xmit_frame *pmgntframe;
  6905. struct rtw_ieee80211_hdr *pwlanhdr;
  6906. struct pkt_attrib *pattrib;
  6907. unsigned char *pbuf, *pframe;
  6908. unsigned short val, ie_status;
  6909. unsigned short *fctrl;
  6910. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  6911. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6912. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  6913. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  6914. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  6915. u8 *ie = pnetwork->IEs;
  6916. #ifdef CONFIG_P2P
  6917. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  6918. #ifdef CONFIG_WFD
  6919. u32 wfdielen = 0;
  6920. #endif
  6921. #endif /* CONFIG_P2P */
  6922. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  6923. return;
  6924. RTW_INFO("%s\n", __FUNCTION__);
  6925. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  6926. if (pmgntframe == NULL)
  6927. return;
  6928. /* update attribute */
  6929. pattrib = &pmgntframe->attrib;
  6930. update_mgntframe_attrib(padapter, pattrib);
  6931. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  6932. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  6933. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  6934. fctrl = &(pwlanhdr->frame_ctl);
  6935. *(fctrl) = 0;
  6936. _rtw_memcpy((void *)GetAddr1Ptr(pwlanhdr), pstat->hwaddr, ETH_ALEN);
  6937. _rtw_memcpy((void *)get_addr2_ptr(pwlanhdr), adapter_mac_addr(padapter), ETH_ALEN);
  6938. _rtw_memcpy((void *)GetAddr3Ptr(pwlanhdr), get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  6939. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  6940. pmlmeext->mgnt_seq++;
  6941. if ((pkt_type == WIFI_ASSOCRSP) || (pkt_type == WIFI_REASSOCRSP))
  6942. set_frame_sub_type(pwlanhdr, pkt_type);
  6943. else
  6944. return;
  6945. pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  6946. pattrib->pktlen += pattrib->hdrlen;
  6947. pframe += pattrib->hdrlen;
  6948. /* capability */
  6949. val = *(unsigned short *)rtw_get_capability_from_ie(ie);
  6950. pframe = rtw_set_fixed_ie(pframe, _CAPABILITY_ , (unsigned char *)&val, &(pattrib->pktlen));
  6951. ie_status = cpu_to_le16(status);
  6952. pframe = rtw_set_fixed_ie(pframe , _STATUS_CODE_ , (unsigned char *)&ie_status, &(pattrib->pktlen));
  6953. val = cpu_to_le16(pstat->aid | BIT(14) | BIT(15));
  6954. pframe = rtw_set_fixed_ie(pframe, _ASOC_ID_ , (unsigned char *)&val, &(pattrib->pktlen));
  6955. if (pstat->bssratelen <= 8)
  6956. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, pstat->bssratelen, pstat->bssrateset, &(pattrib->pktlen));
  6957. else {
  6958. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pstat->bssrateset, &(pattrib->pktlen));
  6959. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (pstat->bssratelen - 8), pstat->bssrateset + 8, &(pattrib->pktlen));
  6960. }
  6961. #ifdef CONFIG_IEEE80211W
  6962. if (status == _STATS_REFUSED_TEMPORARILY_) {
  6963. u8 timeout_itvl[5];
  6964. u32 timeout_interval = 3000;
  6965. /* Association Comeback time */
  6966. timeout_itvl[0] = 0x03;
  6967. timeout_interval = cpu_to_le32(timeout_interval);
  6968. _rtw_memcpy(timeout_itvl + 1, &timeout_interval, 4);
  6969. pframe = rtw_set_ie(pframe, _TIMEOUT_ITVL_IE_, 5, timeout_itvl, &(pattrib->pktlen));
  6970. }
  6971. #endif /* CONFIG_IEEE80211W */
  6972. #ifdef CONFIG_80211N_HT
  6973. if ((pstat->flags & WLAN_STA_HT) && (pmlmepriv->htpriv.ht_option)) {
  6974. uint ie_len = 0;
  6975. /* FILL HT CAP INFO IE */
  6976. /* p = hostapd_eid_ht_capabilities_info(hapd, p); */
  6977. pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  6978. if (pbuf && ie_len > 0) {
  6979. _rtw_memcpy(pframe, pbuf, ie_len + 2);
  6980. pframe += (ie_len + 2);
  6981. pattrib->pktlen += (ie_len + 2);
  6982. }
  6983. /* FILL HT ADD INFO IE */
  6984. /* p = hostapd_eid_ht_operation(hapd, p); */
  6985. pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  6986. if (pbuf && ie_len > 0) {
  6987. _rtw_memcpy(pframe, pbuf, ie_len + 2);
  6988. pframe += (ie_len + 2);
  6989. pattrib->pktlen += (ie_len + 2);
  6990. }
  6991. }
  6992. #endif
  6993. /*adding EXT_CAPAB_IE */
  6994. if (pmlmepriv->ext_capab_ie_len > 0) {
  6995. uint ie_len = 0;
  6996. pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_CAP_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  6997. if (pbuf && ie_len > 0) {
  6998. _rtw_memcpy(pframe, pbuf, ie_len + 2);
  6999. pframe += (ie_len + 2);
  7000. pattrib->pktlen += (ie_len + 2);
  7001. }
  7002. }
  7003. #ifdef CONFIG_80211AC_VHT
  7004. if ((pstat->flags & WLAN_STA_VHT) && (pmlmepriv->vhtpriv.vht_option)
  7005. && (pstat->wpa_pairwise_cipher != WPA_CIPHER_TKIP)
  7006. && (pstat->wpa2_pairwise_cipher != WPA_CIPHER_TKIP)) {
  7007. u32 ie_len = 0;
  7008. /* FILL VHT CAP IE */
  7009. pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_VHTCapability, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  7010. if (pbuf && ie_len > 0) {
  7011. _rtw_memcpy(pframe, pbuf, ie_len + 2);
  7012. pframe += (ie_len + 2);
  7013. pattrib->pktlen += (ie_len + 2);
  7014. }
  7015. /* FILL VHT OPERATION IE */
  7016. pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_VHTOperation, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  7017. if (pbuf && ie_len > 0) {
  7018. _rtw_memcpy(pframe, pbuf, ie_len + 2);
  7019. pframe += (ie_len + 2);
  7020. pattrib->pktlen += (ie_len + 2);
  7021. }
  7022. }
  7023. #endif /* CONFIG_80211AC_VHT */
  7024. /* FILL WMM IE */
  7025. if ((pstat->flags & WLAN_STA_WME) && (pmlmepriv->qospriv.qos_option)) {
  7026. uint ie_len = 0;
  7027. unsigned char WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
  7028. for (pbuf = ie + _BEACON_IE_OFFSET_; ; pbuf += (ie_len + 2)) {
  7029. pbuf = rtw_get_ie(pbuf, _VENDOR_SPECIFIC_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
  7030. if (pbuf && _rtw_memcmp(pbuf + 2, WMM_PARA_IE, 6)) {
  7031. _rtw_memcpy(pframe, pbuf, ie_len + 2);
  7032. pframe += (ie_len + 2);
  7033. pattrib->pktlen += (ie_len + 2);
  7034. break;
  7035. }
  7036. if ((pbuf == NULL) || (ie_len == 0))
  7037. break;
  7038. }
  7039. }
  7040. if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
  7041. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
  7042. /* add WPS IE ie for wps 2.0 */
  7043. if (pmlmepriv->wps_assoc_resp_ie && pmlmepriv->wps_assoc_resp_ie_len > 0) {
  7044. _rtw_memcpy(pframe, pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len);
  7045. pframe += pmlmepriv->wps_assoc_resp_ie_len;
  7046. pattrib->pktlen += pmlmepriv->wps_assoc_resp_ie_len;
  7047. }
  7048. #ifdef CONFIG_P2P
  7049. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && (pstat->is_p2p_device == _TRUE)) {
  7050. u32 len;
  7051. if (padapter->wdinfo.driver_interface == DRIVER_CFG80211) {
  7052. len = 0;
  7053. if (pmlmepriv->p2p_assoc_resp_ie && pmlmepriv->p2p_assoc_resp_ie_len > 0) {
  7054. len = pmlmepriv->p2p_assoc_resp_ie_len;
  7055. _rtw_memcpy(pframe, pmlmepriv->p2p_assoc_resp_ie, len);
  7056. }
  7057. } else
  7058. len = build_assoc_resp_p2p_ie(pwdinfo, pframe, pstat->p2p_status_code);
  7059. pframe += len;
  7060. pattrib->pktlen += len;
  7061. }
  7062. #ifdef CONFIG_WFD
  7063. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  7064. wfdielen = rtw_append_assoc_resp_wfd_ie(padapter, pframe);
  7065. pframe += wfdielen;
  7066. pattrib->pktlen += wfdielen;
  7067. }
  7068. #endif
  7069. #endif /* CONFIG_P2P */
  7070. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  7071. pattrib->pktlen += rtw_build_vendor_ie(padapter , pframe , WIFI_ASSOCRESP_VENDOR_IE_BIT);
  7072. #endif
  7073. pattrib->last_txcmdsz = pattrib->pktlen;
  7074. dump_mgntframe(padapter, pmgntframe);
  7075. #endif
  7076. }
  7077. void _issue_assocreq(_adapter *padapter, u8 is_reassoc)
  7078. {
  7079. int ret = _FAIL;
  7080. struct xmit_frame *pmgntframe;
  7081. struct pkt_attrib *pattrib;
  7082. unsigned char *pframe, *p;
  7083. struct rtw_ieee80211_hdr *pwlanhdr;
  7084. unsigned short *fctrl;
  7085. unsigned short val16;
  7086. unsigned int i, j, ie_len, index = 0;
  7087. unsigned char rf_type, bssrate[NumRates], sta_bssrate[NumRates];
  7088. PNDIS_802_11_VARIABLE_IEs pIE;
  7089. struct registry_priv *pregpriv = &padapter->registrypriv;
  7090. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  7091. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7092. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7093. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7094. int bssrate_len = 0, sta_bssrate_len = 0;
  7095. u8 vs_ie_length = 0;
  7096. #ifdef CONFIG_P2P
  7097. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  7098. u8 p2pie[255] = { 0x00 };
  7099. u16 p2pielen = 0;
  7100. #ifdef CONFIG_WFD
  7101. u32 wfdielen = 0;
  7102. #endif
  7103. #endif /* CONFIG_P2P */
  7104. #ifdef CONFIG_DFS
  7105. u16 cap;
  7106. /* Dot H */
  7107. u8 pow_cap_ele[2] = { 0x00 };
  7108. u8 sup_ch[30 * 2] = {0x00 }, sup_ch_idx = 0, idx_5g = 2; /* For supported channel */
  7109. #endif /* CONFIG_DFS */
  7110. #ifdef CONFIG_RTW_80211R
  7111. u8 *pie = NULL;
  7112. u32 ft_ie_len = 0;
  7113. ft_priv *pftpriv = &pmlmepriv->ftpriv;
  7114. #endif
  7115. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7116. goto exit;
  7117. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  7118. if (pmgntframe == NULL)
  7119. goto exit;
  7120. /* update attribute */
  7121. pattrib = &pmgntframe->attrib;
  7122. update_mgntframe_attrib(padapter, pattrib);
  7123. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  7124. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  7125. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  7126. fctrl = &(pwlanhdr->frame_ctl);
  7127. *(fctrl) = 0;
  7128. _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  7129. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  7130. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  7131. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  7132. pmlmeext->mgnt_seq++;
  7133. if (is_reassoc == _TRUE)
  7134. set_frame_sub_type(pframe, WIFI_REASSOCREQ);
  7135. else
  7136. set_frame_sub_type(pframe, WIFI_ASSOCREQ);
  7137. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  7138. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  7139. /* caps */
  7140. #ifdef CONFIG_DFS
  7141. _rtw_memcpy(&cap, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
  7142. cap |= cap_SpecMgmt;
  7143. _rtw_memcpy(pframe, &cap, 2);
  7144. #else
  7145. _rtw_memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
  7146. #endif /* CONFIG_DFS */
  7147. pframe += 2;
  7148. pattrib->pktlen += 2;
  7149. /* listen interval */
  7150. /* todo: listen interval for power saving */
  7151. val16 = cpu_to_le16(3);
  7152. _rtw_memcpy(pframe , (unsigned char *)&val16, 2);
  7153. pframe += 2;
  7154. pattrib->pktlen += 2;
  7155. /*Construct Current AP Field for Reassoc-Req only*/
  7156. if (is_reassoc == _TRUE) {
  7157. _rtw_memcpy(pframe, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  7158. pframe += ETH_ALEN;
  7159. pattrib->pktlen += ETH_ALEN;
  7160. }
  7161. /* SSID */
  7162. pframe = rtw_set_ie(pframe, _SSID_IE_, pmlmeinfo->network.Ssid.SsidLength, pmlmeinfo->network.Ssid.Ssid, &(pattrib->pktlen));
  7163. #ifdef CONFIG_DFS
  7164. /* Dot H */
  7165. if (pmlmeext->cur_channel > 14) {
  7166. pow_cap_ele[0] = 13; /* Minimum transmit power capability */
  7167. pow_cap_ele[1] = 21; /* Maximum transmit power capability */
  7168. pframe = rtw_set_ie(pframe, EID_PowerCap, 2, pow_cap_ele, &(pattrib->pktlen));
  7169. /* supported channels */
  7170. while (sup_ch_idx < pmlmeext->max_chan_nums && pmlmeext->channel_set[sup_ch_idx].ChannelNum != 0) {
  7171. if (pmlmeext->channel_set[sup_ch_idx].ChannelNum <= 14) {
  7172. /* TODO: fix 2.4G supported channel when channel doesn't start from 1 and continuous */
  7173. sup_ch[0] = 1; /* First channel number */
  7174. sup_ch[1] = pmlmeext->channel_set[sup_ch_idx].ChannelNum; /* Number of channel */
  7175. } else {
  7176. sup_ch[idx_5g++] = pmlmeext->channel_set[sup_ch_idx].ChannelNum;
  7177. sup_ch[idx_5g++] = 1;
  7178. }
  7179. sup_ch_idx++;
  7180. }
  7181. pframe = rtw_set_ie(pframe, EID_SupportedChannels, idx_5g, sup_ch, &(pattrib->pktlen));
  7182. }
  7183. #endif /* CONFIG_DFS */
  7184. /* supported rate & extended supported rate */
  7185. #if 1 /* Check if the AP's supported rates are also supported by STA. */
  7186. get_rate_set(padapter, sta_bssrate, &sta_bssrate_len);
  7187. /* RTW_INFO("sta_bssrate_len=%d\n", sta_bssrate_len); */
  7188. if (pmlmeext->cur_channel == 14) /* for JAPAN, channel 14 can only uses B Mode(CCK) */
  7189. sta_bssrate_len = 4;
  7190. /* for (i = 0; i < sta_bssrate_len; i++) { */
  7191. /* RTW_INFO("sta_bssrate[%d]=%02X\n", i, sta_bssrate[i]); */
  7192. /* } */
  7193. for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
  7194. if (pmlmeinfo->network.SupportedRates[i] == 0)
  7195. break;
  7196. RTW_INFO("network.SupportedRates[%d]=%02X\n", i, pmlmeinfo->network.SupportedRates[i]);
  7197. }
  7198. for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
  7199. if (pmlmeinfo->network.SupportedRates[i] == 0)
  7200. break;
  7201. /* Check if the AP's supported rates are also supported by STA. */
  7202. for (j = 0; j < sta_bssrate_len; j++) {
  7203. /* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
  7204. if ((pmlmeinfo->network.SupportedRates[i] | IEEE80211_BASIC_RATE_MASK)
  7205. == (sta_bssrate[j] | IEEE80211_BASIC_RATE_MASK)) {
  7206. /* RTW_INFO("match i = %d, j=%d\n", i, j); */
  7207. break;
  7208. } else {
  7209. /* RTW_INFO("not match: %02X != %02X\n", (pmlmeinfo->network.SupportedRates[i]|IEEE80211_BASIC_RATE_MASK), (sta_bssrate[j]|IEEE80211_BASIC_RATE_MASK)); */
  7210. }
  7211. }
  7212. if (j == sta_bssrate_len) {
  7213. /* the rate is not supported by STA */
  7214. RTW_INFO("%s(): the rate[%d]=%02X is not supported by STA!\n", __FUNCTION__, i, pmlmeinfo->network.SupportedRates[i]);
  7215. } else {
  7216. /* the rate is supported by STA */
  7217. bssrate[index++] = pmlmeinfo->network.SupportedRates[i];
  7218. }
  7219. }
  7220. bssrate_len = index;
  7221. RTW_INFO("bssrate_len = %d\n", bssrate_len);
  7222. #else /* Check if the AP's supported rates are also supported by STA. */
  7223. #if 0
  7224. get_rate_set(padapter, bssrate, &bssrate_len);
  7225. #else
  7226. for (bssrate_len = 0; bssrate_len < NumRates; bssrate_len++) {
  7227. if (pmlmeinfo->network.SupportedRates[bssrate_len] == 0)
  7228. break;
  7229. if (pmlmeinfo->network.SupportedRates[bssrate_len] == 0x2C) /* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
  7230. break;
  7231. bssrate[bssrate_len] = pmlmeinfo->network.SupportedRates[bssrate_len];
  7232. }
  7233. #endif
  7234. #endif /* Check if the AP's supported rates are also supported by STA. */
  7235. if ((bssrate_len == 0) && (pmlmeinfo->network.SupportedRates[0] != 0)) {
  7236. rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
  7237. rtw_free_xmitframe(pxmitpriv, pmgntframe);
  7238. goto exit; /* don't connect to AP if no joint supported rate */
  7239. }
  7240. if (bssrate_len > 8) {
  7241. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
  7242. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
  7243. } else if (bssrate_len > 0)
  7244. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
  7245. else
  7246. RTW_INFO("%s: Connect to AP without 11b and 11g data rate!\n", __FUNCTION__);
  7247. /* vendor specific IE, such as WPA, WMM, WPS */
  7248. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pmlmeinfo->network.IELength;) {
  7249. pIE = (PNDIS_802_11_VARIABLE_IEs)(pmlmeinfo->network.IEs + i);
  7250. switch (pIE->ElementID) {
  7251. case _VENDOR_SPECIFIC_IE_:
  7252. if ((_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4)) ||
  7253. (_rtw_memcmp(pIE->data, WMM_OUI, 4)) ||
  7254. (_rtw_memcmp(pIE->data, WPS_OUI, 4))) {
  7255. vs_ie_length = pIE->Length;
  7256. if ((!padapter->registrypriv.wifi_spec) && (_rtw_memcmp(pIE->data, WPS_OUI, 4))) {
  7257. /* Commented by Kurt 20110629 */
  7258. /* In some older APs, WPS handshake */
  7259. /* would be fail if we append vender extensions informations to AP */
  7260. vs_ie_length = 14;
  7261. }
  7262. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, vs_ie_length, pIE->data, &(pattrib->pktlen));
  7263. }
  7264. break;
  7265. case EID_WPA2:
  7266. #ifdef CONFIG_RTW_80211R
  7267. if ((is_reassoc == _TRUE) && (rtw_to_roam(padapter) > 0) && rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED)) {
  7268. pie = rtw_get_ie(pftpriv->updated_ft_ies, EID_WPA2, &ft_ie_len, pftpriv->updated_ft_ies_len);
  7269. if (pie)
  7270. pframe = rtw_set_ie(pframe, EID_WPA2, ft_ie_len, pie+2, &(pattrib->pktlen));
  7271. } else
  7272. #endif
  7273. pframe = rtw_set_ie(pframe, EID_WPA2, pIE->Length, pIE->data, &(pattrib->pktlen));
  7274. break;
  7275. #ifdef CONFIG_80211N_HT
  7276. case EID_HTCapability:
  7277. if (padapter->mlmepriv.htpriv.ht_option == _TRUE) {
  7278. if (!(is_ap_in_tkip(padapter))) {
  7279. _rtw_memcpy(&(pmlmeinfo->HT_caps), pIE->data, sizeof(struct HT_caps_element));
  7280. pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info = cpu_to_le16(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info);
  7281. pframe = rtw_set_ie(pframe, EID_HTCapability, pIE->Length , (u8 *)(&(pmlmeinfo->HT_caps)), &(pattrib->pktlen));
  7282. }
  7283. }
  7284. break;
  7285. case EID_EXTCapability:
  7286. if (padapter->mlmepriv.htpriv.ht_option == _TRUE)
  7287. pframe = rtw_set_ie(pframe, EID_EXTCapability, pIE->Length, pIE->data, &(pattrib->pktlen));
  7288. break;
  7289. #endif /* CONFIG_80211N_HT */
  7290. #ifdef CONFIG_80211AC_VHT
  7291. case EID_VHTCapability:
  7292. if (padapter->mlmepriv.vhtpriv.vht_option == _TRUE)
  7293. pframe = rtw_set_ie(pframe, EID_VHTCapability, pIE->Length, pIE->data, &(pattrib->pktlen));
  7294. break;
  7295. case EID_OpModeNotification:
  7296. if (padapter->mlmepriv.vhtpriv.vht_option == _TRUE)
  7297. pframe = rtw_set_ie(pframe, EID_OpModeNotification, pIE->Length, pIE->data, &(pattrib->pktlen));
  7298. break;
  7299. #endif /* CONFIG_80211AC_VHT */
  7300. default:
  7301. break;
  7302. }
  7303. i += (pIE->Length + 2);
  7304. }
  7305. if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
  7306. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
  7307. #ifdef CONFIG_WAPI_SUPPORT
  7308. rtw_build_assoc_req_wapi_ie(padapter, pframe, pattrib);
  7309. #endif
  7310. #ifdef CONFIG_P2P
  7311. #ifdef CONFIG_IOCTL_CFG80211
  7312. if (adapter_wdev_data(padapter)->p2p_enabled && pwdinfo->driver_interface == DRIVER_CFG80211) {
  7313. if (pmlmepriv->p2p_assoc_req_ie && pmlmepriv->p2p_assoc_req_ie_len > 0) {
  7314. _rtw_memcpy(pframe, pmlmepriv->p2p_assoc_req_ie, pmlmepriv->p2p_assoc_req_ie_len);
  7315. pframe += pmlmepriv->p2p_assoc_req_ie_len;
  7316. pattrib->pktlen += pmlmepriv->p2p_assoc_req_ie_len;
  7317. }
  7318. } else
  7319. #endif /* CONFIG_IOCTL_CFG80211 */
  7320. {
  7321. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)) {
  7322. /* Should add the P2P IE in the association request frame. */
  7323. /* P2P OUI */
  7324. p2pielen = 0;
  7325. p2pie[p2pielen++] = 0x50;
  7326. p2pie[p2pielen++] = 0x6F;
  7327. p2pie[p2pielen++] = 0x9A;
  7328. p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  7329. /* Commented by Albert 20101109 */
  7330. /* According to the P2P Specification, the association request frame should contain 3 P2P attributes */
  7331. /* 1. P2P Capability */
  7332. /* 2. Extended Listen Timing */
  7333. /* 3. Device Info */
  7334. /* Commented by Albert 20110516 */
  7335. /* 4. P2P Interface */
  7336. /* P2P Capability */
  7337. /* Type: */
  7338. p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
  7339. /* Length: */
  7340. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
  7341. p2pielen += 2;
  7342. /* Value: */
  7343. /* Device Capability Bitmap, 1 byte */
  7344. p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
  7345. /* Group Capability Bitmap, 1 byte */
  7346. if (pwdinfo->persistent_supported)
  7347. p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
  7348. else
  7349. p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
  7350. /* Extended Listen Timing */
  7351. /* Type: */
  7352. p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
  7353. /* Length: */
  7354. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
  7355. p2pielen += 2;
  7356. /* Value: */
  7357. /* Availability Period */
  7358. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
  7359. p2pielen += 2;
  7360. /* Availability Interval */
  7361. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
  7362. p2pielen += 2;
  7363. /* Device Info */
  7364. /* Type: */
  7365. p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
  7366. /* Length: */
  7367. /* 21->P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
  7368. /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
  7369. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
  7370. p2pielen += 2;
  7371. /* Value: */
  7372. /* P2P Device Address */
  7373. _rtw_memcpy(p2pie + p2pielen, adapter_mac_addr(padapter), ETH_ALEN);
  7374. p2pielen += ETH_ALEN;
  7375. /* Config Method */
  7376. /* This field should be big endian. Noted by P2P specification. */
  7377. if ((pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN) ||
  7378. (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN))
  7379. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_DISPLAY);
  7380. else
  7381. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_PBC);
  7382. p2pielen += 2;
  7383. /* Primary Device Type */
  7384. /* Category ID */
  7385. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
  7386. p2pielen += 2;
  7387. /* OUI */
  7388. *(u32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
  7389. p2pielen += 4;
  7390. /* Sub Category ID */
  7391. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
  7392. p2pielen += 2;
  7393. /* Number of Secondary Device Types */
  7394. p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
  7395. /* Device Name */
  7396. /* Type: */
  7397. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
  7398. p2pielen += 2;
  7399. /* Length: */
  7400. *(u16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
  7401. p2pielen += 2;
  7402. /* Value: */
  7403. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
  7404. p2pielen += pwdinfo->device_name_len;
  7405. /* P2P Interface */
  7406. /* Type: */
  7407. p2pie[p2pielen++] = P2P_ATTR_INTERFACE;
  7408. /* Length: */
  7409. *(u16 *)(p2pie + p2pielen) = cpu_to_le16(0x000D);
  7410. p2pielen += 2;
  7411. /* Value: */
  7412. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN); /* P2P Device Address */
  7413. p2pielen += ETH_ALEN;
  7414. p2pie[p2pielen++] = 1; /* P2P Interface Address Count */
  7415. _rtw_memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN); /* P2P Interface Address List */
  7416. p2pielen += ETH_ALEN;
  7417. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &pattrib->pktlen);
  7418. }
  7419. }
  7420. #endif /* CONFIG_P2P */
  7421. #ifdef CONFIG_WFD
  7422. wfdielen = rtw_append_assoc_req_wfd_ie(padapter, pframe);
  7423. pframe += wfdielen;
  7424. pattrib->pktlen += wfdielen;
  7425. #endif
  7426. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  7427. pattrib->pktlen += rtw_build_vendor_ie(padapter , pframe , WIFI_ASSOCREQ_VENDOR_IE_BIT);
  7428. #endif
  7429. #ifdef CONFIG_RTW_80211R
  7430. if (rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED)) {
  7431. u8 mdieval[3] = {0};
  7432. _rtw_memcpy(mdieval, &(pftpriv->mdid), 2);
  7433. mdieval[2] = pftpriv->ft_cap;
  7434. pframe = rtw_set_ie(pframe, _MDIE_, 3, mdieval, &(pattrib->pktlen));
  7435. }
  7436. if (is_reassoc == _TRUE) {
  7437. if ((rtw_to_roam(padapter) > 0) && rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED)) {
  7438. u8 is_ft_roaming_with_rsn_ie = _TRUE;
  7439. pie = rtw_get_ie(pftpriv->updated_ft_ies, EID_WPA2, &ft_ie_len, pftpriv->updated_ft_ies_len);
  7440. if (!pie)
  7441. is_ft_roaming_with_rsn_ie = _FALSE;
  7442. pie = rtw_get_ie(pftpriv->updated_ft_ies, _FTIE_, &ft_ie_len, pftpriv->updated_ft_ies_len);
  7443. if (pie && is_ft_roaming_with_rsn_ie)
  7444. pframe = rtw_set_ie(pframe, _FTIE_, ft_ie_len , pie+2, &(pattrib->pktlen));
  7445. }
  7446. }
  7447. #endif
  7448. pattrib->last_txcmdsz = pattrib->pktlen;
  7449. dump_mgntframe(padapter, pmgntframe);
  7450. ret = _SUCCESS;
  7451. exit:
  7452. if (ret == _SUCCESS)
  7453. rtw_buf_update(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len, (u8 *)pwlanhdr, pattrib->pktlen);
  7454. else
  7455. rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len);
  7456. return;
  7457. }
  7458. void issue_assocreq(_adapter *padapter)
  7459. {
  7460. _issue_assocreq(padapter, _FALSE);
  7461. }
  7462. void issue_reassocreq(_adapter *padapter)
  7463. {
  7464. _issue_assocreq(padapter, _TRUE);
  7465. }
  7466. /* when wait_ack is ture, this function shoule be called at process context */
  7467. static int _issue_nulldata(_adapter *padapter, unsigned char *da, unsigned int power_mode, int wait_ack)
  7468. {
  7469. int ret = _FAIL;
  7470. struct xmit_frame *pmgntframe;
  7471. struct pkt_attrib *pattrib;
  7472. unsigned char *pframe;
  7473. struct rtw_ieee80211_hdr *pwlanhdr;
  7474. unsigned short *fctrl;
  7475. struct xmit_priv *pxmitpriv;
  7476. struct mlme_ext_priv *pmlmeext;
  7477. struct mlme_ext_info *pmlmeinfo;
  7478. /* RTW_INFO("%s:%d\n", __FUNCTION__, power_mode); */
  7479. if (!padapter)
  7480. goto exit;
  7481. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7482. goto exit;
  7483. pxmitpriv = &(padapter->xmitpriv);
  7484. pmlmeext = &(padapter->mlmeextpriv);
  7485. pmlmeinfo = &(pmlmeext->mlmext_info);
  7486. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  7487. if (pmgntframe == NULL)
  7488. goto exit;
  7489. /* update attribute */
  7490. pattrib = &pmgntframe->attrib;
  7491. update_mgntframe_attrib(padapter, pattrib);
  7492. pattrib->retry_ctrl = _FALSE;
  7493. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  7494. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  7495. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  7496. fctrl = &(pwlanhdr->frame_ctl);
  7497. *(fctrl) = 0;
  7498. if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE)
  7499. SetFrDs(fctrl);
  7500. else if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE)
  7501. SetToDs(fctrl);
  7502. if (power_mode)
  7503. SetPwrMgt(fctrl);
  7504. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  7505. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  7506. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  7507. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  7508. pmlmeext->mgnt_seq++;
  7509. set_frame_sub_type(pframe, WIFI_DATA_NULL);
  7510. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  7511. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  7512. pattrib->last_txcmdsz = pattrib->pktlen;
  7513. if (wait_ack)
  7514. ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
  7515. else {
  7516. dump_mgntframe(padapter, pmgntframe);
  7517. ret = _SUCCESS;
  7518. }
  7519. exit:
  7520. return ret;
  7521. }
  7522. /*
  7523. * [IMPORTANT] Don't call this function in interrupt context
  7524. *
  7525. * When wait_ms > 0, this function should be called at process context
  7526. * wait_ms == 0 means that there is no need to wait ack through C2H_CCX_TX_RPT
  7527. * wait_ms > 0 means you want to wait ack through C2H_CCX_TX_RPT, and the value of wait_ms means the interval between each TX
  7528. * try_cnt means the maximal TX count to try
  7529. * da == NULL for station mode
  7530. */
  7531. int issue_nulldata(_adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms)
  7532. {
  7533. int ret = _FAIL;
  7534. int i = 0;
  7535. u32 start = rtw_get_current_time();
  7536. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7537. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7538. struct sta_info *psta;
  7539. u8 macid_sleep_reg_access = _TRUE;
  7540. #ifdef CONFIG_MCC_MODE
  7541. if (MCC_EN(padapter)) {
  7542. /* driver doesn't access macid sleep reg under MCC */
  7543. if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC)) {
  7544. macid_sleep_reg_access = _FALSE;
  7545. if (da == NULL) {
  7546. RTW_INFO("Warning: Do not tx null data to AP under MCC mode\n");
  7547. rtw_warn_on(1);
  7548. }
  7549. }
  7550. }
  7551. #endif
  7552. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7553. goto exit;
  7554. /* da == NULL, assum it's null data for sta to ap*/
  7555. if (da == NULL)
  7556. da = get_my_bssid(&(pmlmeinfo->network));
  7557. psta = rtw_get_stainfo(&padapter->stapriv, da);
  7558. if (psta) {
  7559. if (macid_sleep_reg_access) {
  7560. if (power_mode)
  7561. rtw_hal_macid_sleep(padapter, psta->mac_id);
  7562. else
  7563. rtw_hal_macid_wakeup(padapter, psta->mac_id);
  7564. }
  7565. } else {
  7566. RTW_INFO(FUNC_ADPT_FMT ": Can't find sta info for " MAC_FMT ", skip macid %s!!\n",
  7567. FUNC_ADPT_ARG(padapter), MAC_ARG(da), power_mode ? "sleep" : "wakeup");
  7568. rtw_warn_on(1);
  7569. }
  7570. do {
  7571. ret = _issue_nulldata(padapter, da, power_mode, wait_ms > 0 ? _TRUE : _FALSE);
  7572. i++;
  7573. if (RTW_CANNOT_RUN(padapter))
  7574. break;
  7575. if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
  7576. rtw_msleep_os(wait_ms);
  7577. } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
  7578. if (ret != _FAIL) {
  7579. ret = _SUCCESS;
  7580. #ifndef DBG_XMIT_ACK
  7581. goto exit;
  7582. #endif
  7583. }
  7584. if (try_cnt && wait_ms) {
  7585. if (da)
  7586. RTW_INFO(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
  7587. FUNC_ADPT_ARG(padapter), MAC_ARG(da), rtw_get_oper_ch(padapter),
  7588. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  7589. else
  7590. RTW_INFO(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
  7591. FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
  7592. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  7593. }
  7594. exit:
  7595. return ret;
  7596. }
  7597. /*
  7598. * [IMPORTANT] This function run in interrupt context
  7599. *
  7600. * The null data packet would be sent without power bit,
  7601. * and not guarantee success.
  7602. */
  7603. s32 issue_nulldata_in_interrupt(PADAPTER padapter, u8 *da, unsigned int power_mode)
  7604. {
  7605. int ret;
  7606. struct mlme_ext_priv *pmlmeext;
  7607. struct mlme_ext_info *pmlmeinfo;
  7608. pmlmeext = &padapter->mlmeextpriv;
  7609. pmlmeinfo = &pmlmeext->mlmext_info;
  7610. /* da == NULL, assum it's null data for sta to ap*/
  7611. if (da == NULL)
  7612. da = get_my_bssid(&(pmlmeinfo->network));
  7613. ret = _issue_nulldata(padapter, da, power_mode, _FALSE);
  7614. return ret;
  7615. }
  7616. /* when wait_ack is ture, this function shoule be called at process context */
  7617. static int _issue_qos_nulldata(_adapter *padapter, unsigned char *da, u16 tid, int wait_ack)
  7618. {
  7619. int ret = _FAIL;
  7620. struct xmit_frame *pmgntframe;
  7621. struct pkt_attrib *pattrib;
  7622. unsigned char *pframe;
  7623. struct rtw_ieee80211_hdr *pwlanhdr;
  7624. unsigned short *fctrl, *qc;
  7625. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  7626. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7627. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7628. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7629. goto exit;
  7630. RTW_INFO("%s\n", __FUNCTION__);
  7631. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  7632. if (pmgntframe == NULL)
  7633. goto exit;
  7634. /* update attribute */
  7635. pattrib = &pmgntframe->attrib;
  7636. update_mgntframe_attrib(padapter, pattrib);
  7637. pattrib->hdrlen += 2;
  7638. pattrib->qos_en = _TRUE;
  7639. pattrib->eosp = 1;
  7640. pattrib->ack_policy = 0;
  7641. pattrib->mdata = 0;
  7642. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  7643. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  7644. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  7645. fctrl = &(pwlanhdr->frame_ctl);
  7646. *(fctrl) = 0;
  7647. if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE)
  7648. SetFrDs(fctrl);
  7649. else if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE)
  7650. SetToDs(fctrl);
  7651. if (pattrib->mdata)
  7652. SetMData(fctrl);
  7653. qc = (unsigned short *)(pframe + pattrib->hdrlen - 2);
  7654. SetPriority(qc, tid);
  7655. SetEOSP(qc, pattrib->eosp);
  7656. SetAckpolicy(qc, pattrib->ack_policy);
  7657. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  7658. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  7659. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  7660. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  7661. pmlmeext->mgnt_seq++;
  7662. set_frame_sub_type(pframe, WIFI_QOS_DATA_NULL);
  7663. pframe += sizeof(struct rtw_ieee80211_hdr_3addr_qos);
  7664. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr_qos);
  7665. pattrib->last_txcmdsz = pattrib->pktlen;
  7666. if (wait_ack)
  7667. ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
  7668. else {
  7669. dump_mgntframe(padapter, pmgntframe);
  7670. ret = _SUCCESS;
  7671. }
  7672. exit:
  7673. return ret;
  7674. }
  7675. /*
  7676. * when wait_ms >0 , this function should be called at process context
  7677. * wait_ms == 0 means that there is no need to wait ack through C2H_CCX_TX_RPT
  7678. * wait_ms > 0 means you want to wait ack through C2H_CCX_TX_RPT, and the value of wait_ms means the interval between each TX
  7679. * try_cnt means the maximal TX count to try
  7680. * da == NULL for station mode
  7681. */
  7682. int issue_qos_nulldata(_adapter *padapter, unsigned char *da, u16 tid, int try_cnt, int wait_ms)
  7683. {
  7684. int ret = _FAIL;
  7685. int i = 0;
  7686. u32 start = rtw_get_current_time();
  7687. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7688. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7689. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7690. goto exit;
  7691. /* da == NULL, assum it's null data for sta to ap*/
  7692. if (da == NULL)
  7693. da = get_my_bssid(&(pmlmeinfo->network));
  7694. do {
  7695. ret = _issue_qos_nulldata(padapter, da, tid, wait_ms > 0 ? _TRUE : _FALSE);
  7696. i++;
  7697. if (RTW_CANNOT_RUN(padapter))
  7698. break;
  7699. if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
  7700. rtw_msleep_os(wait_ms);
  7701. } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
  7702. if (ret != _FAIL) {
  7703. ret = _SUCCESS;
  7704. #ifndef DBG_XMIT_ACK
  7705. goto exit;
  7706. #endif
  7707. }
  7708. if (try_cnt && wait_ms) {
  7709. if (da)
  7710. RTW_INFO(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
  7711. FUNC_ADPT_ARG(padapter), MAC_ARG(da), rtw_get_oper_ch(padapter),
  7712. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  7713. else
  7714. RTW_INFO(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
  7715. FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
  7716. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  7717. }
  7718. exit:
  7719. return ret;
  7720. }
  7721. static int _issue_deauth(_adapter *padapter, unsigned char *da, unsigned short reason, u8 wait_ack, u8 key_type)
  7722. {
  7723. struct xmit_frame *pmgntframe;
  7724. struct pkt_attrib *pattrib;
  7725. unsigned char *pframe;
  7726. struct rtw_ieee80211_hdr *pwlanhdr;
  7727. unsigned short *fctrl;
  7728. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  7729. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7730. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7731. int ret = _FAIL;
  7732. #ifdef CONFIG_P2P
  7733. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  7734. #endif /* CONFIG_P2P */
  7735. /* RTW_INFO("%s to "MAC_FMT"\n", __func__, MAC_ARG(da)); */
  7736. #ifdef CONFIG_P2P
  7737. if (!(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) && (pwdinfo->rx_invitereq_info.scan_op_ch_only)) {
  7738. _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
  7739. _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
  7740. }
  7741. #endif /* CONFIG_P2P */
  7742. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7743. goto exit;
  7744. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  7745. if (pmgntframe == NULL)
  7746. goto exit;
  7747. /* update attribute */
  7748. pattrib = &pmgntframe->attrib;
  7749. update_mgntframe_attrib(padapter, pattrib);
  7750. pattrib->retry_ctrl = _FALSE;
  7751. pattrib->key_type = key_type;
  7752. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  7753. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  7754. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  7755. fctrl = &(pwlanhdr->frame_ctl);
  7756. *(fctrl) = 0;
  7757. _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  7758. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  7759. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  7760. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  7761. pmlmeext->mgnt_seq++;
  7762. set_frame_sub_type(pframe, WIFI_DEAUTH);
  7763. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  7764. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  7765. reason = cpu_to_le16(reason);
  7766. pframe = rtw_set_fixed_ie(pframe, _RSON_CODE_ , (unsigned char *)&reason, &(pattrib->pktlen));
  7767. pattrib->last_txcmdsz = pattrib->pktlen;
  7768. if (wait_ack)
  7769. ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
  7770. else {
  7771. dump_mgntframe(padapter, pmgntframe);
  7772. ret = _SUCCESS;
  7773. }
  7774. exit:
  7775. return ret;
  7776. }
  7777. int issue_deauth(_adapter *padapter, unsigned char *da, unsigned short reason)
  7778. {
  7779. RTW_INFO("%s to "MAC_FMT"\n", __func__, MAC_ARG(da));
  7780. return _issue_deauth(padapter, da, reason, _FALSE, IEEE80211W_RIGHT_KEY);
  7781. }
  7782. #ifdef CONFIG_IEEE80211W
  7783. int issue_deauth_11w(_adapter *padapter, unsigned char *da, unsigned short reason, u8 key_type)
  7784. {
  7785. RTW_INFO("%s to "MAC_FMT"\n", __func__, MAC_ARG(da));
  7786. return _issue_deauth(padapter, da, reason, _FALSE, key_type);
  7787. }
  7788. #endif /* CONFIG_IEEE80211W */
  7789. /*
  7790. * wait_ms == 0 means that there is no need to wait ack through C2H_CCX_TX_RPT
  7791. * wait_ms > 0 means you want to wait ack through C2H_CCX_TX_RPT, and the value of wait_ms means the interval between each TX
  7792. * try_cnt means the maximal TX count to try
  7793. */
  7794. int issue_deauth_ex(_adapter *padapter, u8 *da, unsigned short reason, int try_cnt,
  7795. int wait_ms)
  7796. {
  7797. int ret = _FAIL;
  7798. int i = 0;
  7799. u32 start = rtw_get_current_time();
  7800. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7801. goto exit;
  7802. do {
  7803. ret = _issue_deauth(padapter, da, reason, wait_ms > 0 ? _TRUE : _FALSE, IEEE80211W_RIGHT_KEY);
  7804. i++;
  7805. if (RTW_CANNOT_RUN(padapter))
  7806. break;
  7807. if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
  7808. rtw_msleep_os(wait_ms);
  7809. } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
  7810. if (ret != _FAIL) {
  7811. ret = _SUCCESS;
  7812. #ifndef DBG_XMIT_ACK
  7813. goto exit;
  7814. #endif
  7815. }
  7816. if (try_cnt && wait_ms) {
  7817. if (da)
  7818. RTW_INFO(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
  7819. FUNC_ADPT_ARG(padapter), MAC_ARG(da), rtw_get_oper_ch(padapter),
  7820. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  7821. else
  7822. RTW_INFO(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
  7823. FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
  7824. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  7825. }
  7826. exit:
  7827. return ret;
  7828. }
  7829. void issue_action_spct_ch_switch(_adapter *padapter, u8 *ra, u8 new_ch, u8 ch_offset)
  7830. {
  7831. _irqL irqL;
  7832. _list *plist, *phead;
  7833. struct xmit_frame *pmgntframe;
  7834. struct pkt_attrib *pattrib;
  7835. unsigned char *pframe;
  7836. struct rtw_ieee80211_hdr *pwlanhdr;
  7837. unsigned short *fctrl;
  7838. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  7839. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  7840. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7841. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7842. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7843. return;
  7844. RTW_INFO(FUNC_NDEV_FMT" ra="MAC_FMT", ch:%u, offset:%u\n",
  7845. FUNC_NDEV_ARG(padapter->pnetdev), MAC_ARG(ra), new_ch, ch_offset);
  7846. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  7847. if (pmgntframe == NULL)
  7848. return;
  7849. /* update attribute */
  7850. pattrib = &pmgntframe->attrib;
  7851. update_mgntframe_attrib(padapter, pattrib);
  7852. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  7853. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  7854. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  7855. fctrl = &(pwlanhdr->frame_ctl);
  7856. *(fctrl) = 0;
  7857. _rtw_memcpy(pwlanhdr->addr1, ra, ETH_ALEN); /* RA */
  7858. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN); /* TA */
  7859. _rtw_memcpy(pwlanhdr->addr3, ra, ETH_ALEN); /* DA = RA */
  7860. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  7861. pmlmeext->mgnt_seq++;
  7862. set_frame_sub_type(pframe, WIFI_ACTION);
  7863. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  7864. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  7865. /* category, action */
  7866. {
  7867. u8 category, action;
  7868. category = RTW_WLAN_CATEGORY_SPECTRUM_MGMT;
  7869. action = RTW_WLAN_ACTION_SPCT_CHL_SWITCH;
  7870. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  7871. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  7872. }
  7873. pframe = rtw_set_ie_ch_switch(pframe, &(pattrib->pktlen), 0, new_ch, 0);
  7874. pframe = rtw_set_ie_secondary_ch_offset(pframe, &(pattrib->pktlen),
  7875. hal_ch_offset_to_secondary_ch_offset(ch_offset));
  7876. pattrib->last_txcmdsz = pattrib->pktlen;
  7877. dump_mgntframe(padapter, pmgntframe);
  7878. }
  7879. #ifdef CONFIG_IEEE80211W
  7880. void issue_action_SA_Query(_adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short tid, u8 key_type)
  7881. {
  7882. u8 category = RTW_WLAN_CATEGORY_SA_QUERY;
  7883. u16 reason_code;
  7884. struct xmit_frame *pmgntframe;
  7885. struct pkt_attrib *pattrib;
  7886. u8 *pframe;
  7887. struct rtw_ieee80211_hdr *pwlanhdr;
  7888. u16 *fctrl;
  7889. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  7890. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7891. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7892. struct sta_info *psta;
  7893. struct sta_priv *pstapriv = &padapter->stapriv;
  7894. struct registry_priv *pregpriv = &padapter->registrypriv;
  7895. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  7896. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7897. return;
  7898. RTW_INFO("%s, %04x\n", __FUNCTION__, tid);
  7899. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  7900. if (pmgntframe == NULL) {
  7901. RTW_INFO("%s: alloc_mgtxmitframe fail\n", __FUNCTION__);
  7902. return;
  7903. }
  7904. /* update attribute */
  7905. pattrib = &pmgntframe->attrib;
  7906. update_mgntframe_attrib(padapter, pattrib);
  7907. pattrib->key_type = key_type;
  7908. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  7909. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  7910. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  7911. fctrl = &(pwlanhdr->frame_ctl);
  7912. *(fctrl) = 0;
  7913. if (raddr)
  7914. _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
  7915. else
  7916. _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  7917. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  7918. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  7919. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  7920. pmlmeext->mgnt_seq++;
  7921. set_frame_sub_type(pframe, WIFI_ACTION);
  7922. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  7923. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  7924. pframe = rtw_set_fixed_ie(pframe, 1, &category, &pattrib->pktlen);
  7925. pframe = rtw_set_fixed_ie(pframe, 1, &action, &pattrib->pktlen);
  7926. switch (action) {
  7927. case 0: /* SA Query req */
  7928. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)&pmlmeext->sa_query_seq, &pattrib->pktlen);
  7929. pmlmeext->sa_query_seq++;
  7930. /* send sa query request to AP, AP should reply sa query response in 1 second */
  7931. if (pattrib->key_type == IEEE80211W_RIGHT_KEY) {
  7932. psta = rtw_get_stainfo(pstapriv, raddr);
  7933. if (psta != NULL) {
  7934. /* RTW_INFO("%s, %d, set dot11w_expire_timer\n", __func__, __LINE__); */
  7935. _set_timer(&psta->dot11w_expire_timer, 1000);
  7936. }
  7937. }
  7938. break;
  7939. case 1: /* SA Query rsp */
  7940. tid = cpu_to_le16(tid);
  7941. /* RTW_INFO("rtw_set_fixed_ie, %04x\n", tid); */
  7942. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)&tid, &pattrib->pktlen);
  7943. break;
  7944. default:
  7945. break;
  7946. }
  7947. pattrib->last_txcmdsz = pattrib->pktlen;
  7948. dump_mgntframe(padapter, pmgntframe);
  7949. }
  7950. #endif /* CONFIG_IEEE80211W */
  7951. /**
  7952. * issue_action_ba - internal function to TX Block Ack action frame
  7953. * @padapter: the adapter to TX
  7954. * @raddr: receiver address
  7955. * @action: Block Ack Action
  7956. * @tid: tid
  7957. * @size: the announced AMPDU buffer size. used by ADDBA_RESP
  7958. * @status: status/reason code. used by ADDBA_RESP, DELBA
  7959. * @initiator: if we are the initiator of AMPDU association. used by DELBA
  7960. * @wait_ack: used xmit ack
  7961. *
  7962. * Returns:
  7963. * _SUCCESS: No xmit ack is used or acked
  7964. * _FAIL: not acked when using xmit ack
  7965. */
  7966. static int issue_action_ba(_adapter *padapter, unsigned char *raddr, unsigned char action
  7967. , u8 tid, u8 size, u16 status, u8 initiator, int wait_ack)
  7968. {
  7969. int ret = _FAIL;
  7970. u8 category = RTW_WLAN_CATEGORY_BACK;
  7971. u16 start_seq;
  7972. u16 BA_para_set;
  7973. u16 BA_timeout_value;
  7974. u16 BA_starting_seqctrl;
  7975. struct xmit_frame *pmgntframe;
  7976. struct pkt_attrib *pattrib;
  7977. u8 *pframe;
  7978. struct rtw_ieee80211_hdr *pwlanhdr;
  7979. u16 *fctrl;
  7980. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  7981. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7982. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  7983. struct sta_info *psta;
  7984. struct sta_priv *pstapriv = &padapter->stapriv;
  7985. struct registry_priv *pregpriv = &padapter->registrypriv;
  7986. #ifdef CONFIG_80211N_HT
  7987. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  7988. goto exit;
  7989. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  7990. if (pmgntframe == NULL)
  7991. goto exit;
  7992. /* update attribute */
  7993. pattrib = &pmgntframe->attrib;
  7994. update_mgntframe_attrib(padapter, pattrib);
  7995. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  7996. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  7997. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  7998. fctrl = &(pwlanhdr->frame_ctl);
  7999. *(fctrl) = 0;
  8000. /* _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); */
  8001. _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
  8002. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  8003. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  8004. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  8005. pmlmeext->mgnt_seq++;
  8006. set_frame_sub_type(pframe, WIFI_ACTION);
  8007. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  8008. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  8009. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  8010. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  8011. if (category == 3) {
  8012. switch (action) {
  8013. case RTW_WLAN_ACTION_ADDBA_REQ:
  8014. do {
  8015. pmlmeinfo->dialogToken++;
  8016. } while (pmlmeinfo->dialogToken == 0);
  8017. pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->dialogToken), &(pattrib->pktlen));
  8018. #if defined(CONFIG_RTL8188E) && defined(CONFIG_SDIO_HCI)
  8019. BA_para_set = (0x0802 | ((tid & 0xf) << 2)); /* immediate ack & 16 buffer size */
  8020. #else
  8021. BA_para_set = (0x1002 | ((tid & 0xf) << 2)); /* immediate ack & 64 buffer size */
  8022. #endif
  8023. #ifdef CONFIG_TX_AMSDU
  8024. if (padapter->tx_amsdu >= 1) /* TX AMSDU enabled */
  8025. BA_para_set |= BIT(0);
  8026. else /* TX AMSDU disabled */
  8027. BA_para_set &= ~BIT(0);
  8028. #endif
  8029. BA_para_set = cpu_to_le16(BA_para_set);
  8030. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_para_set)), &(pattrib->pktlen));
  8031. /* BA_timeout_value = 0xffff; */ /* max: 65535 TUs(~ 65 ms) */
  8032. BA_timeout_value = 5000;/* ~ 5ms */
  8033. BA_timeout_value = cpu_to_le16(BA_timeout_value);
  8034. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_timeout_value)), &(pattrib->pktlen));
  8035. /* if ((psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress)) != NULL) */
  8036. psta = rtw_get_stainfo(pstapriv, raddr);
  8037. if (psta != NULL) {
  8038. start_seq = (psta->sta_xmitpriv.txseq_tid[tid & 0x07] & 0xfff) + 1;
  8039. RTW_INFO("BA_starting_seqctrl = %d for TID=%d\n", start_seq, tid & 0x07);
  8040. psta->BA_starting_seqctrl[tid & 0x07] = start_seq;
  8041. BA_starting_seqctrl = start_seq << 4;
  8042. }
  8043. BA_starting_seqctrl = cpu_to_le16(BA_starting_seqctrl);
  8044. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_starting_seqctrl)), &(pattrib->pktlen));
  8045. break;
  8046. case RTW_WLAN_ACTION_ADDBA_RESP:
  8047. pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->ADDBA_req.dialog_token), &(pattrib->pktlen));
  8048. status = cpu_to_le16(status);
  8049. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&status), &(pattrib->pktlen));
  8050. BA_para_set = le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set);
  8051. BA_para_set &= ~IEEE80211_ADDBA_PARAM_TID_MASK;
  8052. BA_para_set |= (tid << 2) & IEEE80211_ADDBA_PARAM_TID_MASK;
  8053. BA_para_set &= ~RTW_IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
  8054. BA_para_set |= (size << 6) & RTW_IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK;
  8055. if (!padapter->registrypriv.wifi_spec) {
  8056. if (pregpriv->rx_ampdu_amsdu == 0) /* disabled */
  8057. BA_para_set &= ~BIT(0);
  8058. else if (pregpriv->rx_ampdu_amsdu == 1) /* enabled */
  8059. BA_para_set |= BIT(0);
  8060. }
  8061. BA_para_set = cpu_to_le16(BA_para_set);
  8062. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_para_set)), &(pattrib->pktlen));
  8063. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(pmlmeinfo->ADDBA_req.BA_timeout_value)), &(pattrib->pktlen));
  8064. break;
  8065. case RTW_WLAN_ACTION_DELBA:
  8066. BA_para_set = 0;
  8067. BA_para_set |= (tid << 12) & IEEE80211_DELBA_PARAM_TID_MASK;
  8068. BA_para_set |= (initiator << 11) & IEEE80211_DELBA_PARAM_INITIATOR_MASK;
  8069. BA_para_set = cpu_to_le16(BA_para_set);
  8070. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(BA_para_set)), &(pattrib->pktlen));
  8071. status = cpu_to_le16(status);
  8072. pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(status)), &(pattrib->pktlen));
  8073. break;
  8074. default:
  8075. break;
  8076. }
  8077. }
  8078. pattrib->last_txcmdsz = pattrib->pktlen;
  8079. if (wait_ack)
  8080. ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
  8081. else {
  8082. dump_mgntframe(padapter, pmgntframe);
  8083. ret = _SUCCESS;
  8084. }
  8085. exit:
  8086. #endif /* CONFIG_80211N_HT */
  8087. return ret;
  8088. }
  8089. /**
  8090. * issue_addba_req - TX ADDBA_REQ
  8091. * @adapter: the adapter to TX
  8092. * @ra: receiver address
  8093. * @tid: tid
  8094. */
  8095. inline void issue_addba_req(_adapter *adapter, unsigned char *ra, u8 tid)
  8096. {
  8097. issue_action_ba(adapter, ra, RTW_WLAN_ACTION_ADDBA_REQ
  8098. , tid
  8099. , 0 /* unused */
  8100. , 0 /* unused */
  8101. , 0 /* unused */
  8102. , _FALSE
  8103. );
  8104. RTW_INFO(FUNC_ADPT_FMT" ra="MAC_FMT" tid=%u\n"
  8105. , FUNC_ADPT_ARG(adapter), MAC_ARG(ra), tid);
  8106. }
  8107. /**
  8108. * issue_addba_rsp - TX ADDBA_RESP
  8109. * @adapter: the adapter to TX
  8110. * @ra: receiver address
  8111. * @tid: tid
  8112. * @status: status code
  8113. * @size: the announced AMPDU buffer size
  8114. */
  8115. inline void issue_addba_rsp(_adapter *adapter, unsigned char *ra, u8 tid, u16 status, u8 size)
  8116. {
  8117. issue_action_ba(adapter, ra, RTW_WLAN_ACTION_ADDBA_RESP
  8118. , tid
  8119. , size
  8120. , status
  8121. , 0 /* unused */
  8122. , _FALSE
  8123. );
  8124. RTW_INFO(FUNC_ADPT_FMT" ra="MAC_FMT" status=%u, tid=%u, size=%u\n"
  8125. , FUNC_ADPT_ARG(adapter), MAC_ARG(ra), status, tid, size);
  8126. }
  8127. /**
  8128. * issue_addba_rsp_wait_ack - TX ADDBA_RESP and wait ack
  8129. * @adapter: the adapter to TX
  8130. * @ra: receiver address
  8131. * @tid: tid
  8132. * @status: status code
  8133. * @size: the announced AMPDU buffer size
  8134. * @try_cnt: the maximal TX count to try
  8135. * @wait_ms: == 0 means that there is no need to wait ack through C2H_CCX_TX_RPT
  8136. * > 0 means you want to wait ack through C2H_CCX_TX_RPT, and the value of wait_ms means the interval between each TX
  8137. */
  8138. inline u8 issue_addba_rsp_wait_ack(_adapter *adapter, unsigned char *ra, u8 tid, u16 status, u8 size, int try_cnt, int wait_ms)
  8139. {
  8140. int ret = _FAIL;
  8141. int i = 0;
  8142. u32 start = rtw_get_current_time();
  8143. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(adapter)))
  8144. goto exit;
  8145. do {
  8146. ret = issue_action_ba(adapter, ra, RTW_WLAN_ACTION_ADDBA_RESP
  8147. , tid
  8148. , size
  8149. , status
  8150. , 0 /* unused */
  8151. , _TRUE
  8152. );
  8153. i++;
  8154. if (RTW_CANNOT_RUN(adapter))
  8155. break;
  8156. if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
  8157. rtw_msleep_os(wait_ms);
  8158. } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
  8159. if (ret != _FAIL) {
  8160. ret = _SUCCESS;
  8161. #ifndef DBG_XMIT_ACK
  8162. /* goto exit; */
  8163. #endif
  8164. }
  8165. if (try_cnt && wait_ms) {
  8166. RTW_INFO(FUNC_ADPT_FMT" ra="MAC_FMT" status:=%u tid=%u size:%u%s, %d/%d in %u ms\n"
  8167. , FUNC_ADPT_ARG(adapter), MAC_ARG(ra), status, tid, size
  8168. , ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  8169. }
  8170. exit:
  8171. return ret;
  8172. }
  8173. /**
  8174. * issue_del_ba - TX DELBA
  8175. * @adapter: the adapter to TX
  8176. * @ra: receiver address
  8177. * @tid: tid
  8178. * @reason: reason code
  8179. * @initiator: if we are the initiator of AMPDU association. used by DELBA
  8180. */
  8181. inline void issue_del_ba(_adapter *adapter, unsigned char *ra, u8 tid, u16 reason, u8 initiator)
  8182. {
  8183. issue_action_ba(adapter, ra, RTW_WLAN_ACTION_DELBA
  8184. , tid
  8185. , 0 /* unused */
  8186. , reason
  8187. , initiator
  8188. , _FALSE
  8189. );
  8190. RTW_INFO(FUNC_ADPT_FMT" ra="MAC_FMT" reason=%u, tid=%u, initiator=%u\n"
  8191. , FUNC_ADPT_ARG(adapter), MAC_ARG(ra), reason, tid, initiator);
  8192. }
  8193. /**
  8194. * issue_del_ba_ex - TX DELBA with xmit ack options
  8195. * @adapter: the adapter to TX
  8196. * @ra: receiver address
  8197. * @tid: tid
  8198. * @reason: reason code
  8199. * @initiator: if we are the initiator of AMPDU association. used by DELBA
  8200. * @try_cnt: the maximal TX count to try
  8201. * @wait_ms: == 0 means that there is no need to wait ack through C2H_CCX_TX_RPT
  8202. * > 0 means you want to wait ack through C2H_CCX_TX_RPT, and the value of wait_ms means the interval between each TX
  8203. */
  8204. int issue_del_ba_ex(_adapter *adapter, unsigned char *ra, u8 tid, u16 reason, u8 initiator
  8205. , int try_cnt, int wait_ms)
  8206. {
  8207. int ret = _FAIL;
  8208. int i = 0;
  8209. u32 start = rtw_get_current_time();
  8210. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(adapter)))
  8211. goto exit;
  8212. do {
  8213. ret = issue_action_ba(adapter, ra, RTW_WLAN_ACTION_DELBA
  8214. , tid
  8215. , 0 /* unused */
  8216. , reason
  8217. , initiator
  8218. , wait_ms > 0 ? _TRUE : _FALSE
  8219. );
  8220. i++;
  8221. if (RTW_CANNOT_RUN(adapter))
  8222. break;
  8223. if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
  8224. rtw_msleep_os(wait_ms);
  8225. } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
  8226. if (ret != _FAIL) {
  8227. ret = _SUCCESS;
  8228. #ifndef DBG_XMIT_ACK
  8229. /* goto exit; */
  8230. #endif
  8231. }
  8232. if (try_cnt && wait_ms) {
  8233. RTW_INFO(FUNC_ADPT_FMT" ra="MAC_FMT" reason=%u, tid=%u, initiator=%u%s, %d/%d in %u ms\n"
  8234. , FUNC_ADPT_ARG(adapter), MAC_ARG(ra), reason, tid, initiator
  8235. , ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  8236. }
  8237. exit:
  8238. return ret;
  8239. }
  8240. static void issue_action_BSSCoexistPacket(_adapter *padapter)
  8241. {
  8242. _irqL irqL;
  8243. _list *plist, *phead;
  8244. unsigned char category, action;
  8245. struct xmit_frame *pmgntframe;
  8246. struct pkt_attrib *pattrib;
  8247. unsigned char *pframe;
  8248. struct rtw_ieee80211_hdr *pwlanhdr;
  8249. unsigned short *fctrl;
  8250. struct wlan_network *pnetwork = NULL;
  8251. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  8252. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  8253. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  8254. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  8255. _queue *queue = &(pmlmepriv->scanned_queue);
  8256. u8 InfoContent[16] = {0};
  8257. u8 ICS[8][15];
  8258. #ifdef CONFIG_80211N_HT
  8259. if ((pmlmepriv->num_FortyMHzIntolerant == 0) || (pmlmepriv->num_sta_no_ht == 0))
  8260. return;
  8261. if (_TRUE == pmlmeinfo->bwmode_updated)
  8262. return;
  8263. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  8264. return;
  8265. RTW_INFO("%s\n", __FUNCTION__);
  8266. category = RTW_WLAN_CATEGORY_PUBLIC;
  8267. action = ACT_PUBLIC_BSSCOEXIST;
  8268. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  8269. if (pmgntframe == NULL)
  8270. return;
  8271. /* update attribute */
  8272. pattrib = &pmgntframe->attrib;
  8273. update_mgntframe_attrib(padapter, pattrib);
  8274. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  8275. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  8276. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  8277. fctrl = &(pwlanhdr->frame_ctl);
  8278. *(fctrl) = 0;
  8279. _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  8280. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  8281. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  8282. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  8283. pmlmeext->mgnt_seq++;
  8284. set_frame_sub_type(pframe, WIFI_ACTION);
  8285. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  8286. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  8287. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  8288. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  8289. /* */
  8290. if (pmlmepriv->num_FortyMHzIntolerant > 0) {
  8291. u8 iedata = 0;
  8292. iedata |= BIT(2);/* 20 MHz BSS Width Request */
  8293. pframe = rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
  8294. }
  8295. /* */
  8296. _rtw_memset(ICS, 0, sizeof(ICS));
  8297. if (pmlmepriv->num_sta_no_ht > 0) {
  8298. int i;
  8299. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  8300. phead = get_list_head(queue);
  8301. plist = get_next(phead);
  8302. while (1) {
  8303. int len;
  8304. u8 *p;
  8305. WLAN_BSSID_EX *pbss_network;
  8306. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  8307. break;
  8308. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  8309. plist = get_next(plist);
  8310. pbss_network = (WLAN_BSSID_EX *)&pnetwork->network;
  8311. p = rtw_get_ie(pbss_network->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pbss_network->IELength - _FIXED_IE_LENGTH_);
  8312. if ((p == NULL) || (len == 0)) { /* non-HT */
  8313. if ((pbss_network->Configuration.DSConfig <= 0) || (pbss_network->Configuration.DSConfig > 14))
  8314. continue;
  8315. ICS[0][pbss_network->Configuration.DSConfig] = 1;
  8316. if (ICS[0][0] == 0)
  8317. ICS[0][0] = 1;
  8318. }
  8319. }
  8320. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  8321. for (i = 0; i < 8; i++) {
  8322. if (ICS[i][0] == 1) {
  8323. int j, k = 0;
  8324. InfoContent[k] = i;
  8325. /* SET_BSS_INTOLERANT_ELE_REG_CLASS(InfoContent,i); */
  8326. k++;
  8327. for (j = 1; j <= 14; j++) {
  8328. if (ICS[i][j] == 1) {
  8329. if (k < 16) {
  8330. InfoContent[k] = j; /* channel number */
  8331. /* SET_BSS_INTOLERANT_ELE_CHANNEL(InfoContent+k, j); */
  8332. k++;
  8333. }
  8334. }
  8335. }
  8336. pframe = rtw_set_ie(pframe, EID_BSSIntolerantChlReport, k, InfoContent, &(pattrib->pktlen));
  8337. }
  8338. }
  8339. }
  8340. pattrib->last_txcmdsz = pattrib->pktlen;
  8341. dump_mgntframe(padapter, pmgntframe);
  8342. #endif /* CONFIG_80211N_HT */
  8343. }
  8344. /* Spatial Multiplexing Powersave (SMPS) action frame */
  8345. int _issue_action_SM_PS(_adapter *padapter , unsigned char *raddr , u8 NewMimoPsMode , u8 wait_ack)
  8346. {
  8347. int ret = _FAIL;
  8348. unsigned char category = RTW_WLAN_CATEGORY_HT;
  8349. u8 action = RTW_WLAN_ACTION_HT_SM_PS;
  8350. u8 sm_power_control = 0;
  8351. struct xmit_frame *pmgntframe;
  8352. struct pkt_attrib *pattrib;
  8353. unsigned char *pframe;
  8354. struct rtw_ieee80211_hdr *pwlanhdr;
  8355. unsigned short *fctrl;
  8356. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  8357. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  8358. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  8359. if (NewMimoPsMode == WLAN_HT_CAP_SM_PS_DISABLED) {
  8360. sm_power_control = sm_power_control & ~(BIT(0)); /* SM Power Save Enable = 0 SM Power Save Disable */
  8361. } else if (NewMimoPsMode == WLAN_HT_CAP_SM_PS_STATIC) {
  8362. sm_power_control = sm_power_control | BIT(0); /* SM Power Save Enable = 1 SM Power Save Enable */
  8363. sm_power_control = sm_power_control & ~(BIT(1)); /* SM Mode = 0 Static Mode */
  8364. } else if (NewMimoPsMode == WLAN_HT_CAP_SM_PS_DYNAMIC) {
  8365. sm_power_control = sm_power_control | BIT(0); /* SM Power Save Enable = 1 SM Power Save Enable */
  8366. sm_power_control = sm_power_control | BIT(1); /* SM Mode = 1 Dynamic Mode */
  8367. } else
  8368. return ret;
  8369. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  8370. return ret;
  8371. RTW_INFO("%s, sm_power_control=%u, NewMimoPsMode=%u\n", __FUNCTION__ , sm_power_control , NewMimoPsMode);
  8372. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  8373. if (pmgntframe == NULL)
  8374. return ret;
  8375. /* update attribute */
  8376. pattrib = &pmgntframe->attrib;
  8377. update_mgntframe_attrib(padapter, pattrib);
  8378. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  8379. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  8380. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  8381. fctrl = &(pwlanhdr->frame_ctl);
  8382. *(fctrl) = 0;
  8383. _rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN); /* RA */
  8384. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN); /* TA */
  8385. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); /* DA = RA */
  8386. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  8387. pmlmeext->mgnt_seq++;
  8388. set_frame_sub_type(pframe, WIFI_ACTION);
  8389. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  8390. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  8391. /* category, action */
  8392. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  8393. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  8394. pframe = rtw_set_fixed_ie(pframe, 1, &(sm_power_control), &(pattrib->pktlen));
  8395. pattrib->last_txcmdsz = pattrib->pktlen;
  8396. if (wait_ack)
  8397. ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
  8398. else {
  8399. dump_mgntframe(padapter, pmgntframe);
  8400. ret = _SUCCESS;
  8401. }
  8402. if (ret != _SUCCESS)
  8403. RTW_INFO("%s, ack to\n", __func__);
  8404. return ret;
  8405. }
  8406. /*
  8407. * wait_ms == 0 means that there is no need to wait ack through C2H_CCX_TX_RPT
  8408. * wait_ms > 0 means you want to wait ack through C2H_CCX_TX_RPT, and the value of wait_ms means the interval between each TX
  8409. * try_cnt means the maximal TX count to try
  8410. */
  8411. int issue_action_SM_PS_wait_ack(_adapter *padapter, unsigned char *raddr, u8 NewMimoPsMode, int try_cnt, int wait_ms)
  8412. {
  8413. int ret = _FAIL;
  8414. int i = 0;
  8415. u32 start = rtw_get_current_time();
  8416. if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
  8417. goto exit;
  8418. do {
  8419. ret = _issue_action_SM_PS(padapter, raddr, NewMimoPsMode , wait_ms > 0 ? _TRUE : _FALSE);
  8420. i++;
  8421. if (RTW_CANNOT_RUN(padapter))
  8422. break;
  8423. if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
  8424. rtw_msleep_os(wait_ms);
  8425. } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
  8426. if (ret != _FAIL) {
  8427. ret = _SUCCESS;
  8428. #ifndef DBG_XMIT_ACK
  8429. goto exit;
  8430. #endif
  8431. }
  8432. if (try_cnt && wait_ms) {
  8433. if (raddr)
  8434. RTW_INFO(FUNC_ADPT_FMT" to "MAC_FMT", %s , %d/%d in %u ms\n",
  8435. FUNC_ADPT_ARG(padapter), MAC_ARG(raddr),
  8436. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  8437. else
  8438. RTW_INFO(FUNC_ADPT_FMT", %s , %d/%d in %u ms\n",
  8439. FUNC_ADPT_ARG(padapter),
  8440. ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
  8441. }
  8442. exit:
  8443. return ret;
  8444. }
  8445. int issue_action_SM_PS(_adapter *padapter , unsigned char *raddr , u8 NewMimoPsMode)
  8446. {
  8447. RTW_INFO("%s to "MAC_FMT"\n", __func__, MAC_ARG(raddr));
  8448. return _issue_action_SM_PS(padapter, raddr, NewMimoPsMode , _FALSE);
  8449. }
  8450. /**
  8451. * _send_delba_sta_tid - Cancel the AMPDU association for the specific @sta, @tid
  8452. * @adapter: the adapter to which @sta belongs
  8453. * @initiator: if we are the initiator of AMPDU association
  8454. * @sta: the sta to be checked
  8455. * @tid: the tid to be checked
  8456. * @force: cancel and send DELBA even when no AMPDU association is setup
  8457. * @wait_ack: send delba with xmit ack (valid when initiator == 0)
  8458. *
  8459. * Returns:
  8460. * _FAIL if sta is NULL
  8461. * when initiator is 1, always _SUCCESS
  8462. * when initiator is 0, _SUCCESS if DELBA is acked
  8463. */
  8464. static unsigned int _send_delba_sta_tid(_adapter *adapter, u8 initiator, struct sta_info *sta, u8 tid
  8465. , u8 force, int wait_ack)
  8466. {
  8467. int ret = _SUCCESS;
  8468. if (sta == NULL) {
  8469. ret = _FAIL;
  8470. goto exit;
  8471. }
  8472. if (initiator == 0) {
  8473. /* recipient */
  8474. if (force || sta->recvreorder_ctrl[tid].enable == _TRUE) {
  8475. u8 ampdu_size_bak = sta->recvreorder_ctrl[tid].ampdu_size;
  8476. sta->recvreorder_ctrl[tid].enable = _FALSE;
  8477. sta->recvreorder_ctrl[tid].ampdu_size = RX_AMPDU_SIZE_INVALID;
  8478. if (rtw_del_rx_ampdu_test_trigger_no_tx_fail())
  8479. ret = _FAIL;
  8480. else if (wait_ack)
  8481. ret = issue_del_ba_ex(adapter, sta->hwaddr, tid, 37, initiator, 3, 1);
  8482. else
  8483. issue_del_ba(adapter, sta->hwaddr, tid, 37, initiator);
  8484. if (ret == _FAIL && sta->recvreorder_ctrl[tid].enable == _FALSE)
  8485. sta->recvreorder_ctrl[tid].ampdu_size = ampdu_size_bak;
  8486. }
  8487. } else if (initiator == 1) {
  8488. /* originator */
  8489. #ifdef CONFIG_80211N_HT
  8490. if (force || sta->htpriv.agg_enable_bitmap & BIT(tid)) {
  8491. sta->htpriv.agg_enable_bitmap &= ~BIT(tid);
  8492. sta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
  8493. issue_del_ba(adapter, sta->hwaddr, tid, 37, initiator);
  8494. }
  8495. #endif
  8496. }
  8497. exit:
  8498. return ret;
  8499. }
  8500. inline unsigned int send_delba_sta_tid(_adapter *adapter, u8 initiator, struct sta_info *sta, u8 tid
  8501. , u8 force)
  8502. {
  8503. return _send_delba_sta_tid(adapter, initiator, sta, tid, force, 0);
  8504. }
  8505. inline unsigned int send_delba_sta_tid_wait_ack(_adapter *adapter, u8 initiator, struct sta_info *sta, u8 tid
  8506. , u8 force)
  8507. {
  8508. return _send_delba_sta_tid(adapter, initiator, sta, tid, force, 1);
  8509. }
  8510. unsigned int send_delba(_adapter *padapter, u8 initiator, u8 *addr)
  8511. {
  8512. struct sta_priv *pstapriv = &padapter->stapriv;
  8513. struct sta_info *psta = NULL;
  8514. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  8515. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  8516. u16 tid;
  8517. if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
  8518. if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
  8519. return _SUCCESS;
  8520. psta = rtw_get_stainfo(pstapriv, addr);
  8521. if (psta == NULL)
  8522. return _SUCCESS;
  8523. #if 0
  8524. RTW_INFO("%s:%s\n", __func__, (initiator == 0) ? "RX_DIR" : "TX_DIR");
  8525. if (initiator == 1) /* originator */
  8526. RTW_INFO("tx agg_enable_bitmap(0x%08x)\n", psta->htpriv.agg_enable_bitmap);
  8527. #endif
  8528. for (tid = 0; tid < TID_NUM; tid++)
  8529. send_delba_sta_tid(padapter, initiator, psta, tid, 0);
  8530. return _SUCCESS;
  8531. }
  8532. unsigned int send_beacon(_adapter *padapter)
  8533. {
  8534. u8 bxmitok = _FALSE;
  8535. int issue = 0;
  8536. int poll = 0;
  8537. #if defined(CONFIG_PCI_HCI) && defined(RTL8814AE_SW_BCN)
  8538. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  8539. #endif
  8540. #ifdef CONFIG_PCI_HCI
  8541. /* bypass TX BCN queue because op ch is switching/waiting */
  8542. if (check_fwstate(&padapter->mlmepriv, WIFI_OP_CH_SWITCHING)
  8543. #ifdef CONFIG_DFS_MASTER
  8544. || IS_CH_WAITING(adapter_to_rfctl(padapter))
  8545. #endif
  8546. )
  8547. return _SUCCESS;
  8548. /* RTW_INFO("%s\n", __FUNCTION__); */
  8549. rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
  8550. /* 8192EE Port select for Beacon DL */
  8551. rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL);
  8552. issue_beacon(padapter, 0);
  8553. #ifdef RTL8814AE_SW_BCN
  8554. if (pHalData->bCorrectBCN != 0)
  8555. RTW_INFO("%s, line%d, Warnning, pHalData->bCorrectBCN != 0\n", __func__, __LINE__);
  8556. pHalData->bCorrectBCN = 1;
  8557. #endif
  8558. return _SUCCESS;
  8559. #endif
  8560. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  8561. u32 start = rtw_get_current_time();
  8562. /* bypass TX BCN queue because op ch is switching/waiting */
  8563. if (check_fwstate(&padapter->mlmepriv, WIFI_OP_CH_SWITCHING)
  8564. #ifdef CONFIG_DFS_MASTER
  8565. || IS_CH_WAITING(adapter_to_rfctl(padapter))
  8566. #endif
  8567. )
  8568. return _SUCCESS;
  8569. #if defined(CONFIG_USB_HCI)
  8570. #if defined(CONFIG_RTL8812A)
  8571. if (IS_FULL_SPEED_USB(padapter)) {
  8572. issue_beacon(padapter, 300);
  8573. bxmitok = _TRUE;
  8574. } else
  8575. #endif
  8576. #endif
  8577. {
  8578. rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
  8579. rtw_hal_set_hwreg(padapter, HW_VAR_DL_BCN_SEL, NULL);
  8580. do {
  8581. issue_beacon(padapter, 100);
  8582. issue++;
  8583. do {
  8584. rtw_yield_os();
  8585. rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bxmitok));
  8586. poll++;
  8587. } while ((poll % 10) != 0 && _FALSE == bxmitok && !RTW_CANNOT_RUN(padapter));
  8588. } while (bxmitok == _FALSE && (issue < 100) && !RTW_CANNOT_RUN(padapter));
  8589. }
  8590. if (RTW_CANNOT_RUN(padapter))
  8591. return _FAIL;
  8592. if (_FALSE == bxmitok) {
  8593. RTW_INFO("%s fail! %u ms\n", __FUNCTION__, rtw_get_passing_time_ms(start));
  8594. return _FAIL;
  8595. } else {
  8596. u32 passing_time = rtw_get_passing_time_ms(start);
  8597. if (passing_time > 100 || issue > 3)
  8598. RTW_INFO("%s success, issue:%d, poll:%d, %u ms\n", __FUNCTION__, issue, poll, rtw_get_passing_time_ms(start));
  8599. else if (0)
  8600. RTW_INFO("%s success, issue:%d, poll:%d, %u ms\n", __FUNCTION__, issue, poll, rtw_get_passing_time_ms(start));
  8601. rtw_hal_fw_correct_bcn(padapter);
  8602. return _SUCCESS;
  8603. }
  8604. #endif
  8605. }
  8606. /****************************************************************************
  8607. Following are some utitity fuctions for WiFi MLME
  8608. *****************************************************************************/
  8609. BOOLEAN IsLegal5GChannel(
  8610. IN PADAPTER Adapter,
  8611. IN u8 channel)
  8612. {
  8613. int i = 0;
  8614. u8 Channel_5G[45] = {36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
  8615. 60, 62, 64, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122,
  8616. 124, 126, 128, 130, 132, 134, 136, 138, 140, 149, 151, 153, 155, 157, 159,
  8617. 161, 163, 165
  8618. };
  8619. for (i = 0; i < sizeof(Channel_5G); i++)
  8620. if (channel == Channel_5G[i])
  8621. return _TRUE;
  8622. return _FALSE;
  8623. }
  8624. /* collect bss info from Beacon and Probe request/response frames. */
  8625. u8 collect_bss_info(_adapter *padapter, union recv_frame *precv_frame, WLAN_BSSID_EX *bssid)
  8626. {
  8627. int i;
  8628. u32 len;
  8629. u8 *p;
  8630. u16 val16, subtype;
  8631. u8 *pframe = precv_frame->u.hdr.rx_data;
  8632. u32 packet_len = precv_frame->u.hdr.len;
  8633. u8 ie_offset;
  8634. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  8635. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  8636. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  8637. len = packet_len - sizeof(struct rtw_ieee80211_hdr_3addr);
  8638. if (len > MAX_IE_SZ) {
  8639. /* RTW_INFO("IE too long for survey event\n"); */
  8640. return _FAIL;
  8641. }
  8642. _rtw_memset(bssid, 0, sizeof(WLAN_BSSID_EX));
  8643. subtype = get_frame_sub_type(pframe);
  8644. if (subtype == WIFI_BEACON) {
  8645. bssid->Reserved[0] = 1;
  8646. ie_offset = _BEACON_IE_OFFSET_;
  8647. } else {
  8648. /* FIXME : more type */
  8649. if (subtype == WIFI_PROBERSP) {
  8650. ie_offset = _PROBERSP_IE_OFFSET_;
  8651. bssid->Reserved[0] = 3;
  8652. } else if (subtype == WIFI_PROBEREQ) {
  8653. ie_offset = _PROBEREQ_IE_OFFSET_;
  8654. bssid->Reserved[0] = 2;
  8655. } else {
  8656. bssid->Reserved[0] = 0;
  8657. ie_offset = _FIXED_IE_LENGTH_;
  8658. }
  8659. }
  8660. bssid->Length = sizeof(WLAN_BSSID_EX) - MAX_IE_SZ + len;
  8661. /* below is to copy the information element */
  8662. bssid->IELength = len;
  8663. _rtw_memcpy(bssid->IEs, (pframe + sizeof(struct rtw_ieee80211_hdr_3addr)), bssid->IELength);
  8664. /* get the signal strength */
  8665. /* bssid->Rssi = precv_frame->u.hdr.attrib.SignalStrength; */ /* 0-100 index. */
  8666. bssid->Rssi = precv_frame->u.hdr.attrib.phy_info.RecvSignalPower; /* in dBM.raw data */
  8667. bssid->PhyInfo.SignalQuality = precv_frame->u.hdr.attrib.phy_info.SignalQuality;/* in percentage */
  8668. bssid->PhyInfo.SignalStrength = precv_frame->u.hdr.attrib.phy_info.SignalStrength;/* in percentage */
  8669. #ifdef CONFIG_ANTENNA_DIVERSITY
  8670. rtw_hal_get_odm_var(padapter, HAL_ODM_ANTDIV_SELECT, &(bssid->PhyInfo.Optimum_antenna), NULL);
  8671. #endif
  8672. /* checking SSID */
  8673. p = rtw_get_ie(bssid->IEs + ie_offset, _SSID_IE_, &len, bssid->IELength - ie_offset);
  8674. if (p == NULL) {
  8675. RTW_INFO("marc: cannot find SSID for survey event\n");
  8676. return _FAIL;
  8677. }
  8678. if (*(p + 1)) {
  8679. if (len > NDIS_802_11_LENGTH_SSID) {
  8680. RTW_INFO("%s()-%d: IE too long (%d) for survey event\n", __FUNCTION__, __LINE__, len);
  8681. return _FAIL;
  8682. }
  8683. _rtw_memcpy(bssid->Ssid.Ssid, (p + 2), *(p + 1));
  8684. bssid->Ssid.SsidLength = *(p + 1);
  8685. } else
  8686. bssid->Ssid.SsidLength = 0;
  8687. _rtw_memset(bssid->SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
  8688. /* checking rate info... */
  8689. i = 0;
  8690. p = rtw_get_ie(bssid->IEs + ie_offset, _SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
  8691. if (p != NULL) {
  8692. if (len > NDIS_802_11_LENGTH_RATES_EX) {
  8693. RTW_INFO("%s()-%d: IE too long (%d) for survey event\n", __FUNCTION__, __LINE__, len);
  8694. return _FAIL;
  8695. }
  8696. _rtw_memcpy(bssid->SupportedRates, (p + 2), len);
  8697. i = len;
  8698. }
  8699. p = rtw_get_ie(bssid->IEs + ie_offset, _EXT_SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
  8700. if (p != NULL) {
  8701. if (len > (NDIS_802_11_LENGTH_RATES_EX - i)) {
  8702. RTW_INFO("%s()-%d: IE too long (%d) for survey event\n", __FUNCTION__, __LINE__, len);
  8703. return _FAIL;
  8704. }
  8705. _rtw_memcpy(bssid->SupportedRates + i, (p + 2), len);
  8706. }
  8707. /* todo: */
  8708. #if 0
  8709. if (judge_network_type(bssid->SupportedRates, (len + i)) == WIRELESS_11B)
  8710. bssid->NetworkTypeInUse = Ndis802_11DS;
  8711. else
  8712. #endif
  8713. {
  8714. bssid->NetworkTypeInUse = Ndis802_11OFDM24;
  8715. }
  8716. #ifdef CONFIG_P2P
  8717. if (subtype == WIFI_PROBEREQ) {
  8718. u8 *p2p_ie;
  8719. u32 p2p_ielen;
  8720. /* Set Listion Channel */
  8721. p2p_ie = rtw_get_p2p_ie(bssid->IEs, bssid->IELength, NULL, &p2p_ielen);
  8722. if (p2p_ie) {
  8723. u32 attr_contentlen = 0;
  8724. u8 listen_ch[5] = { 0x00 };
  8725. rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_LISTEN_CH, listen_ch, &attr_contentlen);
  8726. bssid->Configuration.DSConfig = listen_ch[4];
  8727. } else {
  8728. /* use current channel */
  8729. bssid->Configuration.DSConfig = padapter->mlmeextpriv.cur_channel;
  8730. RTW_INFO("%s()-%d: Cannot get p2p_ie. set DSconfig to op_ch(%d)\n", __FUNCTION__, __LINE__, bssid->Configuration.DSConfig);
  8731. }
  8732. /* FIXME */
  8733. bssid->InfrastructureMode = Ndis802_11Infrastructure;
  8734. _rtw_memcpy(bssid->MacAddress, get_addr2_ptr(pframe), ETH_ALEN);
  8735. bssid->Privacy = 1;
  8736. return _SUCCESS;
  8737. }
  8738. #endif /* CONFIG_P2P */
  8739. if (bssid->IELength < 12)
  8740. return _FAIL;
  8741. /* Checking for DSConfig */
  8742. p = rtw_get_ie(bssid->IEs + ie_offset, _DSSET_IE_, &len, bssid->IELength - ie_offset);
  8743. bssid->Configuration.DSConfig = 0;
  8744. bssid->Configuration.Length = 0;
  8745. if (p)
  8746. bssid->Configuration.DSConfig = *(p + 2);
  8747. else {
  8748. /* In 5G, some ap do not have DSSET IE */
  8749. /* checking HT info for channel */
  8750. p = rtw_get_ie(bssid->IEs + ie_offset, _HT_ADD_INFO_IE_, &len, bssid->IELength - ie_offset);
  8751. if (p) {
  8752. struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2);
  8753. bssid->Configuration.DSConfig = HT_info->primary_channel;
  8754. } else {
  8755. /* use current channel */
  8756. bssid->Configuration.DSConfig = rtw_get_oper_ch(padapter);
  8757. }
  8758. }
  8759. _rtw_memcpy(&bssid->Configuration.BeaconPeriod, rtw_get_beacon_interval_from_ie(bssid->IEs), 2);
  8760. bssid->Configuration.BeaconPeriod = le32_to_cpu(bssid->Configuration.BeaconPeriod);
  8761. val16 = rtw_get_capability((WLAN_BSSID_EX *)bssid);
  8762. if (val16 & BIT(0)) {
  8763. bssid->InfrastructureMode = Ndis802_11Infrastructure;
  8764. _rtw_memcpy(bssid->MacAddress, get_addr2_ptr(pframe), ETH_ALEN);
  8765. } else {
  8766. bssid->InfrastructureMode = Ndis802_11IBSS;
  8767. _rtw_memcpy(bssid->MacAddress, GetAddr3Ptr(pframe), ETH_ALEN);
  8768. }
  8769. if (val16 & BIT(4))
  8770. bssid->Privacy = 1;
  8771. else
  8772. bssid->Privacy = 0;
  8773. bssid->Configuration.ATIMWindow = 0;
  8774. /* 20/40 BSS Coexistence check */
  8775. if ((pregistrypriv->wifi_spec == 1) && (_FALSE == pmlmeinfo->bwmode_updated)) {
  8776. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  8777. #ifdef CONFIG_80211N_HT
  8778. p = rtw_get_ie(bssid->IEs + ie_offset, _HT_CAPABILITY_IE_, &len, bssid->IELength - ie_offset);
  8779. if (p && len > 0) {
  8780. struct HT_caps_element *pHT_caps;
  8781. pHT_caps = (struct HT_caps_element *)(p + 2);
  8782. if (pHT_caps->u.HT_cap_element.HT_caps_info & BIT(14))
  8783. pmlmepriv->num_FortyMHzIntolerant++;
  8784. } else
  8785. pmlmepriv->num_sta_no_ht++;
  8786. #endif /* CONFIG_80211N_HT */
  8787. }
  8788. #ifdef CONFIG_INTEL_WIDI
  8789. /* process_intel_widi_query_or_tigger(padapter, bssid); */
  8790. if (process_intel_widi_query_or_tigger(padapter, bssid))
  8791. return _FAIL;
  8792. #endif /* CONFIG_INTEL_WIDI */
  8793. #if defined(DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) & 1
  8794. if (strcmp(bssid->Ssid.Ssid, DBG_RX_SIGNAL_DISPLAY_SSID_MONITORED) == 0) {
  8795. RTW_INFO("Receiving %s("MAC_FMT", DSConfig:%u) from ch%u with ss:%3u, sq:%3u, RawRSSI:%3ld\n"
  8796. , bssid->Ssid.Ssid, MAC_ARG(bssid->MacAddress), bssid->Configuration.DSConfig
  8797. , rtw_get_oper_ch(padapter)
  8798. , bssid->PhyInfo.SignalStrength, bssid->PhyInfo.SignalQuality, bssid->Rssi
  8799. );
  8800. }
  8801. #endif
  8802. /* mark bss info receving from nearby channel as SignalQuality 101 */
  8803. if (bssid->Configuration.DSConfig != rtw_get_oper_ch(padapter))
  8804. bssid->PhyInfo.SignalQuality = 101;
  8805. return _SUCCESS;
  8806. }
  8807. void start_create_ibss(_adapter *padapter)
  8808. {
  8809. unsigned short caps;
  8810. u8 val8;
  8811. u8 join_type;
  8812. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  8813. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  8814. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
  8815. u8 doiqk = _FALSE;
  8816. pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
  8817. pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
  8818. /* update wireless mode */
  8819. update_wireless_mode(padapter);
  8820. /* udpate capability */
  8821. caps = rtw_get_capability((WLAN_BSSID_EX *)pnetwork);
  8822. update_capinfo(padapter, caps);
  8823. if (caps & cap_IBSS) { /* adhoc master */
  8824. /* set_opmode_cmd(padapter, adhoc); */ /* removed */
  8825. val8 = 0xcf;
  8826. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
  8827. doiqk = _TRUE;
  8828. rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
  8829. /* switch channel */
  8830. set_channel_bwmode(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  8831. doiqk = _FALSE;
  8832. rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
  8833. beacon_timing_control(padapter);
  8834. /* set msr to WIFI_FW_ADHOC_STATE */
  8835. pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
  8836. Set_MSR(padapter, (pmlmeinfo->state & 0x3));
  8837. /* issue beacon */
  8838. if (send_beacon(padapter) == _FAIL) {
  8839. report_join_res(padapter, -1);
  8840. pmlmeinfo->state = WIFI_FW_NULL_STATE;
  8841. } else {
  8842. rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, padapter->registrypriv.dev_network.MacAddress);
  8843. join_type = 0;
  8844. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
  8845. report_join_res(padapter, 1);
  8846. pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
  8847. rtw_indicate_connect(padapter);
  8848. }
  8849. } else {
  8850. RTW_INFO("start_create_ibss, invalid cap:%x\n", caps);
  8851. return;
  8852. }
  8853. /* update bc/mc sta_info */
  8854. update_bmc_sta(padapter);
  8855. }
  8856. void start_clnt_join(_adapter *padapter)
  8857. {
  8858. unsigned short caps;
  8859. u8 val8;
  8860. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  8861. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  8862. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
  8863. int beacon_timeout;
  8864. u8 ASIX_ID[] = {0x00, 0x0E, 0xC6};
  8865. /* update wireless mode */
  8866. update_wireless_mode(padapter);
  8867. /* udpate capability */
  8868. caps = rtw_get_capability((WLAN_BSSID_EX *)pnetwork);
  8869. update_capinfo(padapter, caps);
  8870. /* check if sta is ASIX peer and fix IOT issue if it is. */
  8871. if (_rtw_memcmp(get_my_bssid(&pmlmeinfo->network) , ASIX_ID , 3)) {
  8872. u8 iot_flag = _TRUE;
  8873. rtw_hal_set_hwreg(padapter, HW_VAR_ASIX_IOT, (u8 *)(&iot_flag));
  8874. }
  8875. if (caps & cap_ESS) {
  8876. Set_MSR(padapter, WIFI_FW_STATION_STATE);
  8877. val8 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
  8878. #ifdef CONFIG_WAPI_SUPPORT
  8879. if (padapter->wapiInfo.bWapiEnable && pmlmeinfo->auth_algo == dot11AuthAlgrthm_WAPI) {
  8880. /* Disable TxUseDefaultKey, RxUseDefaultKey, RxBroadcastUseDefaultKey. */
  8881. val8 = 0x4c;
  8882. }
  8883. #endif
  8884. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
  8885. #ifdef CONFIG_DEAUTH_BEFORE_CONNECT
  8886. /* Because of AP's not receiving deauth before */
  8887. /* AP may: 1)not response auth or 2)deauth us after link is complete */
  8888. /* issue deauth before issuing auth to deal with the situation */
  8889. /* Commented by Albert 2012/07/21 */
  8890. /* For the Win8 P2P connection, it will be hard to have a successful connection if this Wi-Fi doesn't connect to it. */
  8891. {
  8892. #ifdef CONFIG_P2P
  8893. _queue *queue = &(padapter->mlmepriv.scanned_queue);
  8894. _list *head = get_list_head(queue);
  8895. _list *pos = get_next(head);
  8896. struct wlan_network *scanned = NULL;
  8897. u8 ie_offset = 0;
  8898. _irqL irqL;
  8899. bool has_p2p_ie = _FALSE;
  8900. _enter_critical_bh(&(padapter->mlmepriv.scanned_queue.lock), &irqL);
  8901. for (pos = get_next(head); !rtw_end_of_queue_search(head, pos); pos = get_next(pos)) {
  8902. scanned = LIST_CONTAINOR(pos, struct wlan_network, list);
  8903. if (_rtw_memcmp(&(scanned->network.Ssid), &(pnetwork->Ssid), sizeof(NDIS_802_11_SSID)) == _TRUE
  8904. && _rtw_memcmp(scanned->network.MacAddress, pnetwork->MacAddress, sizeof(NDIS_802_11_MAC_ADDRESS)) == _TRUE
  8905. ) {
  8906. ie_offset = (scanned->network.Reserved[0] == 2 ? 0 : 12);
  8907. if (rtw_get_p2p_ie(scanned->network.IEs + ie_offset, scanned->network.IELength - ie_offset, NULL, NULL))
  8908. has_p2p_ie = _TRUE;
  8909. break;
  8910. }
  8911. }
  8912. _exit_critical_bh(&(padapter->mlmepriv.scanned_queue.lock), &irqL);
  8913. if (scanned == NULL || rtw_end_of_queue_search(head, pos) || has_p2p_ie == _FALSE)
  8914. #endif /* CONFIG_P2P */
  8915. /* To avoid connecting to AP fail during resume process, change retry count from 5 to 1 */
  8916. issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 1, 100);
  8917. }
  8918. #endif /* CONFIG_DEAUTH_BEFORE_CONNECT */
  8919. /* here wait for receiving the beacon to start auth */
  8920. /* and enable a timer */
  8921. beacon_timeout = decide_wait_for_beacon_timeout(pmlmeinfo->bcn_interval);
  8922. set_link_timer(pmlmeext, beacon_timeout);
  8923. _set_timer(&padapter->mlmepriv.assoc_timer,
  8924. (REAUTH_TO * REAUTH_LIMIT) + (REASSOC_TO * REASSOC_LIMIT) + beacon_timeout);
  8925. #ifdef CONFIG_RTW_80211R
  8926. if ((rtw_to_roam(padapter) > 0) && rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED)) {
  8927. if (rtw_chk_ft_flags(padapter, RTW_FT_OVER_DS_SUPPORTED)) {
  8928. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  8929. ft_priv *pftpriv = &pmlmepriv->ftpriv;
  8930. pmlmeinfo->state = WIFI_FW_AUTH_SUCCESS | WIFI_FW_STATION_STATE;
  8931. pftpriv->ft_event.ies = pftpriv->ft_action + sizeof(struct rtw_ieee80211_hdr_3addr) + 16;
  8932. pftpriv->ft_event.ies_len = pftpriv->ft_action_len - sizeof(struct rtw_ieee80211_hdr_3addr);
  8933. /*Not support RIC*/
  8934. pftpriv->ft_event.ric_ies = NULL;
  8935. pftpriv->ft_event.ric_ies_len = 0;
  8936. report_ft_event(padapter);
  8937. } else {
  8938. pmlmeinfo->state = WIFI_FW_AUTH_NULL | WIFI_FW_STATION_STATE;
  8939. start_clnt_auth(padapter);
  8940. }
  8941. } else
  8942. #endif
  8943. {
  8944. rtw_sta_linking_test_set_start();
  8945. pmlmeinfo->state = WIFI_FW_AUTH_NULL | WIFI_FW_STATION_STATE;
  8946. }
  8947. } else if (caps & cap_IBSS) { /* adhoc client */
  8948. Set_MSR(padapter, WIFI_FW_ADHOC_STATE);
  8949. val8 = 0xcf;
  8950. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
  8951. beacon_timing_control(padapter);
  8952. pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
  8953. report_join_res(padapter, 1);
  8954. } else {
  8955. /* RTW_INFO("marc: invalid cap:%x\n", caps); */
  8956. return;
  8957. }
  8958. }
  8959. void start_clnt_auth(_adapter *padapter)
  8960. {
  8961. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  8962. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  8963. _cancel_timer_ex(&pmlmeext->link_timer);
  8964. pmlmeinfo->state &= (~WIFI_FW_AUTH_NULL);
  8965. pmlmeinfo->state |= WIFI_FW_AUTH_STATE;
  8966. pmlmeinfo->auth_seq = 1;
  8967. pmlmeinfo->reauth_count = 0;
  8968. pmlmeinfo->reassoc_count = 0;
  8969. pmlmeinfo->link_count = 0;
  8970. pmlmeext->retry = 0;
  8971. #ifdef CONFIG_RTW_80211R
  8972. if ((rtw_to_roam(padapter) > 0) && rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED)) {
  8973. rtw_set_ft_status(padapter, RTW_FT_AUTHENTICATING_STA);
  8974. RTW_PRINT("start ft auth\n");
  8975. } else
  8976. #endif
  8977. RTW_PRINT("start auth\n");
  8978. issue_auth(padapter, NULL, 0);
  8979. set_link_timer(pmlmeext, REAUTH_TO);
  8980. }
  8981. void start_clnt_assoc(_adapter *padapter)
  8982. {
  8983. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  8984. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  8985. _cancel_timer_ex(&pmlmeext->link_timer);
  8986. pmlmeinfo->state &= (~(WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE));
  8987. pmlmeinfo->state |= (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE);
  8988. #ifdef CONFIG_RTW_80211R
  8989. if ((rtw_to_roam(padapter) > 0) && rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED))
  8990. issue_reassocreq(padapter);
  8991. else
  8992. #endif
  8993. issue_assocreq(padapter);
  8994. set_link_timer(pmlmeext, REASSOC_TO);
  8995. }
  8996. unsigned int receive_disconnect(_adapter *padapter, unsigned char *MacAddr, unsigned short reason, u8 locally_generated)
  8997. {
  8998. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  8999. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9000. if (!(_rtw_memcmp(MacAddr, get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
  9001. return _SUCCESS;
  9002. RTW_INFO("%s\n", __FUNCTION__);
  9003. if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) {
  9004. if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
  9005. if (report_del_sta_event(padapter, MacAddr, reason, _TRUE, locally_generated) != _FAIL)
  9006. pmlmeinfo->state = WIFI_FW_NULL_STATE;
  9007. } else if (pmlmeinfo->state & WIFI_FW_LINKING_STATE) {
  9008. if (report_join_res(padapter, -2) != _FAIL)
  9009. pmlmeinfo->state = WIFI_FW_NULL_STATE;
  9010. } else
  9011. RTW_INFO(FUNC_ADPT_FMT" - End to Disconnect\n", FUNC_ADPT_ARG(padapter));
  9012. #ifdef CONFIG_RTW_80211R
  9013. if ((rtw_to_roam(padapter) > 0) && !rtw_chk_ft_status(padapter, RTW_FT_REQUESTED_STA))
  9014. rtw_reset_ft_status(padapter);
  9015. #endif
  9016. }
  9017. return _SUCCESS;
  9018. }
  9019. #ifdef CONFIG_80211D
  9020. static void process_80211d(PADAPTER padapter, WLAN_BSSID_EX *bssid)
  9021. {
  9022. struct registry_priv *pregistrypriv;
  9023. struct mlme_ext_priv *pmlmeext;
  9024. RT_CHANNEL_INFO *chplan_new;
  9025. u8 channel;
  9026. u8 i;
  9027. pregistrypriv = &padapter->registrypriv;
  9028. pmlmeext = &padapter->mlmeextpriv;
  9029. /* Adjust channel plan by AP Country IE */
  9030. if (pregistrypriv->enable80211d
  9031. && (!pmlmeext->update_channel_plan_by_ap_done)) {
  9032. u8 *ie, *p;
  9033. u32 len;
  9034. RT_CHANNEL_PLAN chplan_ap;
  9035. RT_CHANNEL_INFO chplan_sta[MAX_CHANNEL_NUM];
  9036. u8 country[4];
  9037. u8 fcn; /* first channel number */
  9038. u8 noc; /* number of channel */
  9039. u8 j, k;
  9040. ie = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _COUNTRY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  9041. if (!ie)
  9042. return;
  9043. if (len < 6)
  9044. return;
  9045. ie += 2;
  9046. p = ie;
  9047. ie += len;
  9048. _rtw_memset(country, 0, 4);
  9049. _rtw_memcpy(country, p, 3);
  9050. p += 3;
  9051. RTW_INFO("%s: 802.11d country=%s\n", __FUNCTION__, country);
  9052. i = 0;
  9053. while ((ie - p) >= 3) {
  9054. fcn = *(p++);
  9055. noc = *(p++);
  9056. p++;
  9057. for (j = 0; j < noc; j++) {
  9058. if (fcn <= 14)
  9059. channel = fcn + j; /* 2.4 GHz */
  9060. else
  9061. channel = fcn + j * 4; /* 5 GHz */
  9062. chplan_ap.Channel[i++] = channel;
  9063. }
  9064. }
  9065. chplan_ap.Len = i;
  9066. #ifdef CONFIG_RTW_DEBUG
  9067. i = 0;
  9068. RTW_INFO("%s: AP[%s] channel plan {", __FUNCTION__, bssid->Ssid.Ssid);
  9069. while ((i < chplan_ap.Len) && (chplan_ap.Channel[i] != 0)) {
  9070. _RTW_INFO("%02d,", chplan_ap.Channel[i]);
  9071. i++;
  9072. }
  9073. _RTW_INFO("}\n");
  9074. #endif
  9075. _rtw_memcpy(chplan_sta, pmlmeext->channel_set, sizeof(chplan_sta));
  9076. #ifdef CONFIG_RTW_DEBUG
  9077. i = 0;
  9078. RTW_INFO("%s: STA channel plan {", __FUNCTION__);
  9079. while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0)) {
  9080. _RTW_INFO("%02d(%c),", chplan_sta[i].ChannelNum, chplan_sta[i].ScanType == SCAN_PASSIVE ? 'p' : 'a');
  9081. i++;
  9082. }
  9083. _RTW_INFO("}\n");
  9084. #endif
  9085. _rtw_memset(pmlmeext->channel_set, 0, sizeof(pmlmeext->channel_set));
  9086. chplan_new = pmlmeext->channel_set;
  9087. i = j = k = 0;
  9088. if (pregistrypriv->wireless_mode & WIRELESS_11G) {
  9089. do {
  9090. if ((i == MAX_CHANNEL_NUM)
  9091. || (chplan_sta[i].ChannelNum == 0)
  9092. || (chplan_sta[i].ChannelNum > 14))
  9093. break;
  9094. if ((j == chplan_ap.Len) || (chplan_ap.Channel[j] > 14))
  9095. break;
  9096. if (chplan_sta[i].ChannelNum == chplan_ap.Channel[j]) {
  9097. chplan_new[k].ChannelNum = chplan_ap.Channel[j];
  9098. chplan_new[k].ScanType = SCAN_ACTIVE;
  9099. i++;
  9100. j++;
  9101. k++;
  9102. } else if (chplan_sta[i].ChannelNum < chplan_ap.Channel[j]) {
  9103. chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
  9104. #if 0
  9105. chplan_new[k].ScanType = chplan_sta[i].ScanType;
  9106. #else
  9107. chplan_new[k].ScanType = SCAN_PASSIVE;
  9108. #endif
  9109. i++;
  9110. k++;
  9111. } else if (chplan_sta[i].ChannelNum > chplan_ap.Channel[j]) {
  9112. chplan_new[k].ChannelNum = chplan_ap.Channel[j];
  9113. chplan_new[k].ScanType = SCAN_ACTIVE;
  9114. j++;
  9115. k++;
  9116. }
  9117. } while (1);
  9118. /* change AP not support channel to Passive scan */
  9119. while ((i < MAX_CHANNEL_NUM)
  9120. && (chplan_sta[i].ChannelNum != 0)
  9121. && (chplan_sta[i].ChannelNum <= 14)) {
  9122. chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
  9123. #if 0
  9124. chplan_new[k].ScanType = chplan_sta[i].ScanType;
  9125. #else
  9126. chplan_new[k].ScanType = SCAN_PASSIVE;
  9127. #endif
  9128. i++;
  9129. k++;
  9130. }
  9131. /* add channel AP supported */
  9132. while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14)) {
  9133. chplan_new[k].ChannelNum = chplan_ap.Channel[j];
  9134. chplan_new[k].ScanType = SCAN_ACTIVE;
  9135. j++;
  9136. k++;
  9137. }
  9138. } else {
  9139. /* keep original STA 2.4G channel plan */
  9140. while ((i < MAX_CHANNEL_NUM)
  9141. && (chplan_sta[i].ChannelNum != 0)
  9142. && (chplan_sta[i].ChannelNum <= 14)) {
  9143. chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
  9144. chplan_new[k].ScanType = chplan_sta[i].ScanType;
  9145. i++;
  9146. k++;
  9147. }
  9148. /* skip AP 2.4G channel plan */
  9149. while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14))
  9150. j++;
  9151. }
  9152. if (pregistrypriv->wireless_mode & WIRELESS_11A) {
  9153. do {
  9154. if ((i >= MAX_CHANNEL_NUM)
  9155. || (chplan_sta[i].ChannelNum == 0))
  9156. break;
  9157. if ((j == chplan_ap.Len) || (chplan_ap.Channel[j] == 0))
  9158. break;
  9159. if (chplan_sta[i].ChannelNum == chplan_ap.Channel[j]) {
  9160. chplan_new[k].ChannelNum = chplan_ap.Channel[j];
  9161. chplan_new[k].ScanType = SCAN_ACTIVE;
  9162. i++;
  9163. j++;
  9164. k++;
  9165. } else if (chplan_sta[i].ChannelNum < chplan_ap.Channel[j]) {
  9166. chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
  9167. #if 0
  9168. chplan_new[k].ScanType = chplan_sta[i].ScanType;
  9169. #else
  9170. chplan_new[k].ScanType = SCAN_PASSIVE;
  9171. #endif
  9172. i++;
  9173. k++;
  9174. } else if (chplan_sta[i].ChannelNum > chplan_ap.Channel[j]) {
  9175. chplan_new[k].ChannelNum = chplan_ap.Channel[j];
  9176. chplan_new[k].ScanType = SCAN_ACTIVE;
  9177. j++;
  9178. k++;
  9179. }
  9180. } while (1);
  9181. /* change AP not support channel to Passive scan */
  9182. while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0)) {
  9183. chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
  9184. #if 0
  9185. chplan_new[k].ScanType = chplan_sta[i].ScanType;
  9186. #else
  9187. chplan_new[k].ScanType = SCAN_PASSIVE;
  9188. #endif
  9189. i++;
  9190. k++;
  9191. }
  9192. /* add channel AP supported */
  9193. while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] != 0)) {
  9194. chplan_new[k].ChannelNum = chplan_ap.Channel[j];
  9195. chplan_new[k].ScanType = SCAN_ACTIVE;
  9196. j++;
  9197. k++;
  9198. }
  9199. } else {
  9200. /* keep original STA 5G channel plan */
  9201. while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0)) {
  9202. chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
  9203. chplan_new[k].ScanType = chplan_sta[i].ScanType;
  9204. i++;
  9205. k++;
  9206. }
  9207. }
  9208. pmlmeext->update_channel_plan_by_ap_done = 1;
  9209. #ifdef CONFIG_RTW_DEBUG
  9210. k = 0;
  9211. RTW_INFO("%s: new STA channel plan {", __FUNCTION__);
  9212. while ((k < MAX_CHANNEL_NUM) && (chplan_new[k].ChannelNum != 0)) {
  9213. _RTW_INFO("%02d(%c),", chplan_new[k].ChannelNum, chplan_new[k].ScanType == SCAN_PASSIVE ? 'p' : 'c');
  9214. k++;
  9215. }
  9216. _RTW_INFO("}\n");
  9217. #endif
  9218. #if 0
  9219. /* recover the right channel index */
  9220. channel = chplan_sta[pmlmeext->sitesurvey_res.channel_idx].ChannelNum;
  9221. k = 0;
  9222. while ((k < MAX_CHANNEL_NUM) && (chplan_new[k].ChannelNum != 0)) {
  9223. if (chplan_new[k].ChannelNum == channel) {
  9224. RTW_INFO("%s: change mlme_ext sitesurvey channel index from %d to %d\n",
  9225. __FUNCTION__, pmlmeext->sitesurvey_res.channel_idx, k);
  9226. pmlmeext->sitesurvey_res.channel_idx = k;
  9227. break;
  9228. }
  9229. k++;
  9230. }
  9231. #endif
  9232. }
  9233. /* If channel is used by AP, set channel scan type to active */
  9234. channel = bssid->Configuration.DSConfig;
  9235. chplan_new = pmlmeext->channel_set;
  9236. i = 0;
  9237. while (i < MAX_CHANNEL_NUM && chplan_new[i].ChannelNum != 0) {
  9238. if (chplan_new[i].ChannelNum == channel) {
  9239. if (chplan_new[i].ScanType == SCAN_PASSIVE) {
  9240. /* 5G Bnad 2, 3 (DFS) doesn't change to active scan */
  9241. if (rtw_is_dfs_ch(channel))
  9242. break;
  9243. chplan_new[i].ScanType = SCAN_ACTIVE;
  9244. RTW_INFO("%s: change channel %d scan type from passive to active\n",
  9245. __FUNCTION__, channel);
  9246. }
  9247. break;
  9248. }
  9249. i++;
  9250. }
  9251. }
  9252. #endif
  9253. /****************************************************************************
  9254. Following are the functions to report events
  9255. *****************************************************************************/
  9256. void report_survey_event(_adapter *padapter, union recv_frame *precv_frame)
  9257. {
  9258. struct cmd_obj *pcmd_obj;
  9259. u8 *pevtcmd;
  9260. u32 cmdsz;
  9261. struct survey_event *psurvey_evt;
  9262. struct C2HEvent_Header *pc2h_evt_hdr;
  9263. struct mlme_ext_priv *pmlmeext;
  9264. struct cmd_priv *pcmdpriv;
  9265. /* u8 *pframe = precv_frame->u.hdr.rx_data; */
  9266. /* uint len = precv_frame->u.hdr.len; */
  9267. int ch_set_idx = -1;
  9268. if (!padapter)
  9269. return;
  9270. pmlmeext = &padapter->mlmeextpriv;
  9271. pcmdpriv = &padapter->cmdpriv;
  9272. pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  9273. if (pcmd_obj == NULL)
  9274. return;
  9275. cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
  9276. pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
  9277. if (pevtcmd == NULL) {
  9278. rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
  9279. return;
  9280. }
  9281. _rtw_init_listhead(&pcmd_obj->list);
  9282. pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
  9283. pcmd_obj->cmdsz = cmdsz;
  9284. pcmd_obj->parmbuf = pevtcmd;
  9285. pcmd_obj->rsp = NULL;
  9286. pcmd_obj->rspsz = 0;
  9287. pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
  9288. pc2h_evt_hdr->len = sizeof(struct survey_event);
  9289. pc2h_evt_hdr->ID = GEN_EVT_CODE(_Survey);
  9290. pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
  9291. psurvey_evt = (struct survey_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
  9292. if (collect_bss_info(padapter, precv_frame, (WLAN_BSSID_EX *)&psurvey_evt->bss) == _FAIL) {
  9293. rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
  9294. rtw_mfree((u8 *)pevtcmd, cmdsz);
  9295. return;
  9296. }
  9297. #ifdef CONFIG_80211D
  9298. process_80211d(padapter, &psurvey_evt->bss);
  9299. #endif
  9300. #ifdef CONFIG_DFS
  9301. ch_set_idx = rtw_chset_search_ch(pmlmeext->channel_set, psurvey_evt->bss.Configuration.DSConfig);
  9302. if (ch_set_idx >= 0) {
  9303. if (psurvey_evt->bss.Ssid.SsidLength == 0
  9304. || is_all_null(psurvey_evt->bss.Ssid.Ssid, psurvey_evt->bss.Ssid.SsidLength) == _TRUE)
  9305. pmlmeext->channel_set[ch_set_idx].hidden_bss_cnt++;
  9306. }
  9307. #endif
  9308. rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
  9309. pmlmeext->sitesurvey_res.bss_cnt++;
  9310. return;
  9311. }
  9312. void report_surveydone_event(_adapter *padapter)
  9313. {
  9314. struct cmd_obj *pcmd_obj;
  9315. u8 *pevtcmd;
  9316. u32 cmdsz;
  9317. struct surveydone_event *psurveydone_evt;
  9318. struct C2HEvent_Header *pc2h_evt_hdr;
  9319. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9320. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  9321. pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  9322. if (pcmd_obj == NULL)
  9323. return;
  9324. cmdsz = (sizeof(struct surveydone_event) + sizeof(struct C2HEvent_Header));
  9325. pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
  9326. if (pevtcmd == NULL) {
  9327. rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
  9328. return;
  9329. }
  9330. _rtw_init_listhead(&pcmd_obj->list);
  9331. pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
  9332. pcmd_obj->cmdsz = cmdsz;
  9333. pcmd_obj->parmbuf = pevtcmd;
  9334. pcmd_obj->rsp = NULL;
  9335. pcmd_obj->rspsz = 0;
  9336. pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
  9337. pc2h_evt_hdr->len = sizeof(struct surveydone_event);
  9338. pc2h_evt_hdr->ID = GEN_EVT_CODE(_SurveyDone);
  9339. pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
  9340. psurveydone_evt = (struct surveydone_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
  9341. psurveydone_evt->bss_cnt = pmlmeext->sitesurvey_res.bss_cnt;
  9342. RTW_INFO("survey done event(%x) band:%d for "ADPT_FMT"\n", psurveydone_evt->bss_cnt, padapter->setband, ADPT_ARG(padapter));
  9343. rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
  9344. return;
  9345. }
  9346. u32 report_join_res(_adapter *padapter, int res)
  9347. {
  9348. struct cmd_obj *pcmd_obj;
  9349. u8 *pevtcmd;
  9350. u32 cmdsz;
  9351. struct joinbss_event *pjoinbss_evt;
  9352. struct C2HEvent_Header *pc2h_evt_hdr;
  9353. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9354. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9355. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  9356. u32 ret = _FAIL;
  9357. pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  9358. if (pcmd_obj == NULL)
  9359. goto exit;
  9360. cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
  9361. pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
  9362. if (pevtcmd == NULL) {
  9363. rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
  9364. goto exit;
  9365. }
  9366. _rtw_init_listhead(&pcmd_obj->list);
  9367. pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
  9368. pcmd_obj->cmdsz = cmdsz;
  9369. pcmd_obj->parmbuf = pevtcmd;
  9370. pcmd_obj->rsp = NULL;
  9371. pcmd_obj->rspsz = 0;
  9372. pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
  9373. pc2h_evt_hdr->len = sizeof(struct joinbss_event);
  9374. pc2h_evt_hdr->ID = GEN_EVT_CODE(_JoinBss);
  9375. pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
  9376. pjoinbss_evt = (struct joinbss_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
  9377. _rtw_memcpy((unsigned char *)(&(pjoinbss_evt->network.network)), &(pmlmeinfo->network), sizeof(WLAN_BSSID_EX));
  9378. pjoinbss_evt->network.join_res = pjoinbss_evt->network.aid = res;
  9379. RTW_INFO("report_join_res(%d)\n", res);
  9380. rtw_joinbss_event_prehandle(padapter, (u8 *)&pjoinbss_evt->network);
  9381. ret = rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
  9382. exit:
  9383. return ret;
  9384. }
  9385. void report_wmm_edca_update(_adapter *padapter)
  9386. {
  9387. struct cmd_obj *pcmd_obj;
  9388. u8 *pevtcmd;
  9389. u32 cmdsz;
  9390. struct wmm_event *pwmm_event;
  9391. struct C2HEvent_Header *pc2h_evt_hdr;
  9392. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9393. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9394. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  9395. pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  9396. if (pcmd_obj == NULL)
  9397. return;
  9398. cmdsz = (sizeof(struct wmm_event) + sizeof(struct C2HEvent_Header));
  9399. pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
  9400. if (pevtcmd == NULL) {
  9401. rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
  9402. return;
  9403. }
  9404. _rtw_init_listhead(&pcmd_obj->list);
  9405. pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
  9406. pcmd_obj->cmdsz = cmdsz;
  9407. pcmd_obj->parmbuf = pevtcmd;
  9408. pcmd_obj->rsp = NULL;
  9409. pcmd_obj->rspsz = 0;
  9410. pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
  9411. pc2h_evt_hdr->len = sizeof(struct wmm_event);
  9412. pc2h_evt_hdr->ID = GEN_EVT_CODE(_WMM);
  9413. pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
  9414. pwmm_event = (struct wmm_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
  9415. pwmm_event->wmm = 0;
  9416. rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
  9417. return;
  9418. }
  9419. u32 report_del_sta_event(_adapter *padapter, unsigned char *MacAddr, unsigned short reason, bool enqueue, u8 locally_generated)
  9420. {
  9421. struct cmd_obj *pcmd_obj;
  9422. u8 *pevtcmd;
  9423. u32 cmdsz;
  9424. struct sta_info *psta;
  9425. int mac_id = -1;
  9426. struct stadel_event *pdel_sta_evt;
  9427. struct C2HEvent_Header *pc2h_evt_hdr;
  9428. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9429. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  9430. u8 res = _SUCCESS;
  9431. /* prepare cmd parameter */
  9432. cmdsz = (sizeof(struct stadel_event) + sizeof(struct C2HEvent_Header));
  9433. pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
  9434. if (pevtcmd == NULL) {
  9435. res = _FAIL;
  9436. goto exit;
  9437. }
  9438. pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
  9439. pc2h_evt_hdr->len = sizeof(struct stadel_event);
  9440. pc2h_evt_hdr->ID = GEN_EVT_CODE(_DelSTA);
  9441. pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
  9442. pdel_sta_evt = (struct stadel_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
  9443. _rtw_memcpy((unsigned char *)(&(pdel_sta_evt->macaddr)), MacAddr, ETH_ALEN);
  9444. _rtw_memcpy((unsigned char *)(pdel_sta_evt->rsvd), (unsigned char *)(&reason), 2);
  9445. psta = rtw_get_stainfo(&padapter->stapriv, MacAddr);
  9446. if (psta)
  9447. mac_id = (int)psta->mac_id;
  9448. else
  9449. mac_id = (-1);
  9450. pdel_sta_evt->mac_id = mac_id;
  9451. pdel_sta_evt->locally_generated = locally_generated;
  9452. if (!enqueue) {
  9453. /* do directly */
  9454. rtw_stadel_event_callback(padapter, (u8 *)pdel_sta_evt);
  9455. rtw_mfree(pevtcmd, cmdsz);
  9456. } else {
  9457. pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  9458. if (pcmd_obj == NULL) {
  9459. rtw_mfree(pevtcmd, cmdsz);
  9460. res = _FAIL;
  9461. goto exit;
  9462. }
  9463. _rtw_init_listhead(&pcmd_obj->list);
  9464. pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
  9465. pcmd_obj->cmdsz = cmdsz;
  9466. pcmd_obj->parmbuf = pevtcmd;
  9467. pcmd_obj->rsp = NULL;
  9468. pcmd_obj->rspsz = 0;
  9469. res = rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
  9470. }
  9471. exit:
  9472. RTW_INFO(FUNC_ADPT_FMT" "MAC_FMT" mac_id=%d, enqueue:%d, res:%u\n"
  9473. , FUNC_ADPT_ARG(padapter), MAC_ARG(MacAddr), mac_id, enqueue, res);
  9474. return res;
  9475. }
  9476. void report_add_sta_event(_adapter *padapter, unsigned char *MacAddr)
  9477. {
  9478. struct cmd_obj *pcmd_obj;
  9479. u8 *pevtcmd;
  9480. u32 cmdsz;
  9481. struct stassoc_event *padd_sta_evt;
  9482. struct C2HEvent_Header *pc2h_evt_hdr;
  9483. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9484. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  9485. pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  9486. if (pcmd_obj == NULL)
  9487. return;
  9488. cmdsz = (sizeof(struct stassoc_event) + sizeof(struct C2HEvent_Header));
  9489. pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
  9490. if (pevtcmd == NULL) {
  9491. rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
  9492. return;
  9493. }
  9494. _rtw_init_listhead(&pcmd_obj->list);
  9495. pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
  9496. pcmd_obj->cmdsz = cmdsz;
  9497. pcmd_obj->parmbuf = pevtcmd;
  9498. pcmd_obj->rsp = NULL;
  9499. pcmd_obj->rspsz = 0;
  9500. pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
  9501. pc2h_evt_hdr->len = sizeof(struct stassoc_event);
  9502. pc2h_evt_hdr->ID = GEN_EVT_CODE(_AddSTA);
  9503. pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
  9504. padd_sta_evt = (struct stassoc_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
  9505. _rtw_memcpy((unsigned char *)(&(padd_sta_evt->macaddr)), MacAddr, ETH_ALEN);
  9506. RTW_INFO("report_add_sta_event: add STA\n");
  9507. rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
  9508. return;
  9509. }
  9510. bool rtw_port_switch_chk(_adapter *adapter)
  9511. {
  9512. bool switch_needed = _FALSE;
  9513. #ifdef CONFIG_CONCURRENT_MODE
  9514. #ifdef CONFIG_RUNTIME_PORT_SWITCH
  9515. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  9516. struct pwrctrl_priv *pwrctl = dvobj_to_pwrctl(dvobj);
  9517. _adapter *if_port0 = NULL;
  9518. _adapter *if_port1 = NULL;
  9519. struct mlme_ext_info *if_port0_mlmeinfo = NULL;
  9520. struct mlme_ext_info *if_port1_mlmeinfo = NULL;
  9521. int i;
  9522. for (i = 0; i < dvobj->iface_nums; i++) {
  9523. if (get_hw_port(dvobj->padapters[i]) == HW_PORT0) {
  9524. if_port0 = dvobj->padapters[i];
  9525. if_port0_mlmeinfo = &(if_port0->mlmeextpriv.mlmext_info);
  9526. } else if (get_hw_port(dvobj->padapters[i]) == HW_PORT1) {
  9527. if_port1 = dvobj->padapters[i];
  9528. if_port1_mlmeinfo = &(if_port1->mlmeextpriv.mlmext_info);
  9529. }
  9530. }
  9531. if (if_port0 == NULL) {
  9532. rtw_warn_on(1);
  9533. goto exit;
  9534. }
  9535. if (if_port1 == NULL) {
  9536. rtw_warn_on(1);
  9537. goto exit;
  9538. }
  9539. #ifdef DBG_RUNTIME_PORT_SWITCH
  9540. RTW_INFO(FUNC_ADPT_FMT" wowlan_mode:%u\n"
  9541. ADPT_FMT", port0, mlmeinfo->state:0x%08x, p2p_state:%d, %d\n"
  9542. ADPT_FMT", port1, mlmeinfo->state:0x%08x, p2p_state:%d, %d\n",
  9543. FUNC_ADPT_ARG(adapter), pwrctl->wowlan_mode,
  9544. ADPT_ARG(if_port0), if_port0_mlmeinfo->state, rtw_p2p_state(&if_port0->wdinfo), rtw_p2p_chk_state(&if_port0->wdinfo, P2P_STATE_NONE),
  9545. ADPT_ARG(if_port1), if_port1_mlmeinfo->state, rtw_p2p_state(&if_port1->wdinfo), rtw_p2p_chk_state(&if_port1->wdinfo, P2P_STATE_NONE));
  9546. #endif /* DBG_RUNTIME_PORT_SWITCH */
  9547. #ifdef CONFIG_WOWLAN
  9548. /* WOWLAN interface(primary, for now) should be port0 */
  9549. if (pwrctl->wowlan_mode == _TRUE) {
  9550. if (!is_primary_adapter(if_port0)) {
  9551. RTW_INFO("%s "ADPT_FMT" enable WOWLAN\n", __func__, ADPT_ARG(if_port1));
  9552. switch_needed = _TRUE;
  9553. }
  9554. goto exit;
  9555. }
  9556. #endif /* CONFIG_WOWLAN */
  9557. /* AP should use port0 for ctl frame's ack */
  9558. if ((if_port1_mlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
  9559. RTW_INFO("%s "ADPT_FMT" is AP/GO\n", __func__, ADPT_ARG(if_port1));
  9560. switch_needed = _TRUE;
  9561. goto exit;
  9562. }
  9563. /* GC should use port0 for p2p ps */
  9564. if (((if_port1_mlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE)
  9565. && (if_port1_mlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
  9566. #ifdef CONFIG_P2P
  9567. && !rtw_p2p_chk_state(&if_port1->wdinfo, P2P_STATE_NONE)
  9568. #endif
  9569. && !check_fwstate(&if_port1->mlmepriv, WIFI_UNDER_WPS)
  9570. ) {
  9571. RTW_INFO("%s "ADPT_FMT" is GC\n", __func__, ADPT_ARG(if_port1));
  9572. switch_needed = _TRUE;
  9573. goto exit;
  9574. }
  9575. /* port1 linked, but port0 not linked */
  9576. if ((if_port1_mlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
  9577. && !(if_port0_mlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
  9578. && ((if_port0_mlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
  9579. ) {
  9580. RTW_INFO("%s "ADPT_FMT" is SINGLE_LINK\n", __func__, ADPT_ARG(if_port1));
  9581. switch_needed = _TRUE;
  9582. goto exit;
  9583. }
  9584. exit:
  9585. #ifdef DBG_RUNTIME_PORT_SWITCH
  9586. RTW_INFO(FUNC_ADPT_FMT" ret:%d\n", FUNC_ADPT_ARG(adapter), switch_needed);
  9587. #endif /* DBG_RUNTIME_PORT_SWITCH */
  9588. #endif /* CONFIG_RUNTIME_PORT_SWITCH */
  9589. #endif /* CONFIG_CONCURRENT_MODE */
  9590. return switch_needed;
  9591. }
  9592. /****************************************************************************
  9593. Following are the event callback functions
  9594. *****************************************************************************/
  9595. /* for sta/adhoc mode */
  9596. void update_sta_info(_adapter *padapter, struct sta_info *psta)
  9597. {
  9598. _irqL irqL;
  9599. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  9600. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9601. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9602. /* ERP */
  9603. VCS_update(padapter, psta);
  9604. #ifdef CONFIG_80211N_HT
  9605. /* HT */
  9606. if (pmlmepriv->htpriv.ht_option) {
  9607. psta->htpriv.ht_option = _TRUE;
  9608. psta->htpriv.ampdu_enable = pmlmepriv->htpriv.ampdu_enable;
  9609. psta->htpriv.rx_ampdu_min_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
  9610. if (support_short_GI(padapter, &(pmlmeinfo->HT_caps), CHANNEL_WIDTH_20))
  9611. psta->htpriv.sgi_20m = _TRUE;
  9612. if (support_short_GI(padapter, &(pmlmeinfo->HT_caps), CHANNEL_WIDTH_40))
  9613. psta->htpriv.sgi_40m = _TRUE;
  9614. psta->qos_option = _TRUE;
  9615. psta->htpriv.ldpc_cap = pmlmepriv->htpriv.ldpc_cap;
  9616. psta->htpriv.stbc_cap = pmlmepriv->htpriv.stbc_cap;
  9617. psta->htpriv.beamform_cap = pmlmepriv->htpriv.beamform_cap;
  9618. _rtw_memcpy(&psta->htpriv.ht_cap, &pmlmeinfo->HT_caps, sizeof(struct rtw_ieee80211_ht_cap));
  9619. } else
  9620. #endif /* CONFIG_80211N_HT */
  9621. {
  9622. #ifdef CONFIG_80211N_HT
  9623. psta->htpriv.ht_option = _FALSE;
  9624. psta->htpriv.ampdu_enable = _FALSE;
  9625. psta->htpriv.tx_amsdu_enable = _FALSE;
  9626. psta->htpriv.sgi_20m = _FALSE;
  9627. psta->htpriv.sgi_40m = _FALSE;
  9628. #endif /* CONFIG_80211N_HT */
  9629. psta->qos_option = _FALSE;
  9630. }
  9631. #ifdef CONFIG_80211N_HT
  9632. psta->htpriv.ch_offset = pmlmeext->cur_ch_offset;
  9633. psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
  9634. psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
  9635. #endif /* CONFIG_80211N_HT */
  9636. psta->bw_mode = pmlmeext->cur_bwmode;
  9637. /* QoS */
  9638. if (pmlmepriv->qospriv.qos_option)
  9639. psta->qos_option = _TRUE;
  9640. #ifdef CONFIG_80211AC_VHT
  9641. _rtw_memcpy(&psta->vhtpriv, &pmlmepriv->vhtpriv, sizeof(struct vht_priv));
  9642. #endif /* CONFIG_80211AC_VHT */
  9643. update_ldpc_stbc_cap(psta);
  9644. _enter_critical_bh(&psta->lock, &irqL);
  9645. psta->state = _FW_LINKED;
  9646. _exit_critical_bh(&psta->lock, &irqL);
  9647. }
  9648. static void rtw_mlmeext_disconnect(_adapter *padapter)
  9649. {
  9650. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  9651. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9652. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9653. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
  9654. u8 state_backup = (pmlmeinfo->state & 0x03);
  9655. u8 ASIX_ID[] = {0x00, 0x0E, 0xC6};
  9656. /* set_opmode_cmd(padapter, infra_client_with_mlme); */
  9657. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, 0);
  9658. rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
  9659. /* set MSR to no link state->infra. mode */
  9660. Set_MSR(padapter, _HW_STATE_STATION_);
  9661. /* check if sta is ASIX peer and fix IOT issue if it is. */
  9662. if (_rtw_memcmp(get_my_bssid(&pmlmeinfo->network) , ASIX_ID , 3)) {
  9663. u8 iot_flag = _FALSE;
  9664. rtw_hal_set_hwreg(padapter, HW_VAR_ASIX_IOT, (u8 *)(&iot_flag));
  9665. }
  9666. pmlmeinfo->state = WIFI_FW_NULL_STATE;
  9667. #ifdef CONFIG_MCC_MODE
  9668. /* mcc disconnect setting before download LPS rsvd page */
  9669. rtw_hal_set_mcc_setting_disconnect(padapter);
  9670. #endif /* CONFIG_MCC_MODE */
  9671. if (state_backup == WIFI_FW_STATION_STATE) {
  9672. if (rtw_port_switch_chk(padapter) == _TRUE) {
  9673. rtw_hal_set_hwreg(padapter, HW_VAR_PORT_SWITCH, NULL);
  9674. #ifdef CONFIG_LPS
  9675. {
  9676. _adapter *port0_iface = dvobj_get_port0_adapter(adapter_to_dvobj(padapter));
  9677. if (port0_iface)
  9678. rtw_lps_ctrl_wk_cmd(port0_iface, LPS_CTRL_CONNECT, 0);
  9679. }
  9680. #endif
  9681. }
  9682. }
  9683. /* switch to the 20M Hz mode after disconnect */
  9684. pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
  9685. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  9686. #ifdef CONFIG_FCS_MODE
  9687. if (EN_FCS(padapter))
  9688. rtw_hal_set_hwreg(padapter, HW_VAR_STOP_FCS_MODE, NULL);
  9689. #endif
  9690. #ifdef CONFIG_DFS_MASTER
  9691. if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
  9692. rtw_dfs_master_status_apply(padapter, MLME_AP_STOPPED);
  9693. else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
  9694. rtw_dfs_master_status_apply(padapter, MLME_STA_DISCONNECTED);
  9695. #endif
  9696. {
  9697. u8 ch, bw, offset;
  9698. if (rtw_mi_get_ch_setting_union_no_self(padapter, &ch, &bw, &offset) != 0) {
  9699. set_channel_bwmode(padapter, ch, offset, bw);
  9700. rtw_mi_update_union_chan_inf(padapter, ch, offset, bw);
  9701. }
  9702. }
  9703. flush_all_cam_entry(padapter);
  9704. _cancel_timer_ex(&pmlmeext->link_timer);
  9705. /* pmlmepriv->LinkDetectInfo.TrafficBusyState = _FALSE; */
  9706. pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 0;
  9707. pmlmepriv->LinkDetectInfo.LowPowerTransitionCount = 0;
  9708. #ifdef CONFIG_TDLS
  9709. padapter->tdlsinfo.ap_prohibited = _FALSE;
  9710. /* For TDLS channel switch, currently we only allow it to work in wifi logo test mode */
  9711. if (padapter->registrypriv.wifi_spec == 1)
  9712. padapter->tdlsinfo.ch_switch_prohibited = _FALSE;
  9713. #endif /* CONFIG_TDLS */
  9714. }
  9715. void mlmeext_joinbss_event_callback(_adapter *padapter, int join_res)
  9716. {
  9717. struct sta_info *psta, *psta_bmc;
  9718. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9719. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9720. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  9721. struct sta_priv *pstapriv = &padapter->stapriv;
  9722. u8 join_type;
  9723. #ifdef CONFIG_ARP_KEEP_ALIVE
  9724. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  9725. #endif
  9726. struct security_priv *psecuritypriv = &padapter->securitypriv;
  9727. if (join_res < 0) {
  9728. join_type = 1;
  9729. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
  9730. rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
  9731. goto exit_mlmeext_joinbss_event_callback;
  9732. }
  9733. #ifdef CONFIG_ARP_KEEP_ALIVE
  9734. pmlmepriv->bGetGateway = 1;
  9735. pmlmepriv->GetGatewayTryCnt = 0;
  9736. #endif
  9737. if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) {
  9738. /* update bc/mc sta_info */
  9739. update_bmc_sta(padapter);
  9740. }
  9741. /* turn on dynamic functions */
  9742. /* Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, _TRUE); */
  9743. /* update IOT-releated issue */
  9744. update_IOT_info(padapter);
  9745. rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, cur_network->SupportedRates);
  9746. /* BCN interval */
  9747. rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pmlmeinfo->bcn_interval));
  9748. /* udpate capability */
  9749. update_capinfo(padapter, pmlmeinfo->capability);
  9750. /* WMM, Update EDCA param */
  9751. WMMOnAssocRsp(padapter);
  9752. /* HT */
  9753. HTOnAssocRsp(padapter);
  9754. #ifdef CONFIG_80211AC_VHT
  9755. /* VHT */
  9756. VHTOnAssocRsp(padapter);
  9757. #endif
  9758. psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
  9759. if (psta) { /* only for infra. mode */
  9760. /* RTW_INFO("set_sta_rate\n"); */
  9761. psta->wireless_mode = pmlmeext->cur_wireless_mode;
  9762. #ifdef CONFIG_FW_MULTI_PORT_SUPPORT
  9763. rtw_hal_set_default_port_id_cmd(padapter, psta->mac_id);
  9764. #endif
  9765. /* set per sta rate after updating HT cap. */
  9766. set_sta_rate(padapter, psta);
  9767. rtw_sta_media_status_rpt(padapter, psta, 1);
  9768. /* wakeup macid after join bss successfully to ensure
  9769. the subsequent data frames can be sent out normally */
  9770. rtw_hal_macid_wakeup(padapter, psta->mac_id);
  9771. }
  9772. #ifndef CONFIG_IOCTL_CFG80211
  9773. if (is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm))
  9774. rtw_sec_restore_wep_key(padapter);
  9775. #endif /* CONFIG_IOCTL_CFG80211 */
  9776. if (rtw_port_switch_chk(padapter) == _TRUE)
  9777. rtw_hal_set_hwreg(padapter, HW_VAR_PORT_SWITCH, NULL);
  9778. join_type = 2;
  9779. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
  9780. if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) {
  9781. /* correcting TSF */
  9782. correct_TSF(padapter, pmlmeext);
  9783. /* set_link_timer(pmlmeext, DISCONNECT_TO); */
  9784. }
  9785. #ifdef CONFIG_LPS
  9786. #ifndef CONFIG_FW_MULTI_PORT_SUPPORT
  9787. if (get_hw_port(padapter) == HW_PORT0)
  9788. #endif
  9789. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_CONNECT, 0);
  9790. #endif
  9791. #ifdef CONFIG_BEAMFORMING
  9792. if (psta)
  9793. beamforming_wk_cmd(padapter, BEAMFORMING_CTRL_ENTER, (u8 *)psta, sizeof(struct sta_info), 0);
  9794. #endif/*CONFIG_BEAMFORMING*/
  9795. exit_mlmeext_joinbss_event_callback:
  9796. rtw_join_done_chk_ch(padapter, join_res);
  9797. RTW_INFO("=>%s - End to Connection without 4-way\n", __FUNCTION__);
  9798. }
  9799. /* currently only adhoc mode will go here */
  9800. void mlmeext_sta_add_event_callback(_adapter *padapter, struct sta_info *psta)
  9801. {
  9802. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  9803. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9804. u8 join_type;
  9805. RTW_INFO("%s\n", __FUNCTION__);
  9806. if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) {
  9807. if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) { /* adhoc master or sta_count>1 */
  9808. /* nothing to do */
  9809. } else { /* adhoc client */
  9810. /* update TSF Value */
  9811. /* update_TSF(pmlmeext, pframe, len); */
  9812. /* correcting TSF */
  9813. correct_TSF(padapter, pmlmeext);
  9814. /* start beacon */
  9815. if (send_beacon(padapter) == _FAIL)
  9816. rtw_warn_on(1);
  9817. pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
  9818. }
  9819. join_type = 2;
  9820. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
  9821. }
  9822. /* update adhoc sta_info */
  9823. update_sta_info(padapter, psta);
  9824. rtw_hal_update_sta_rate_mask(padapter, psta);
  9825. /* ToDo: HT for Ad-hoc */
  9826. psta->wireless_mode = rtw_check_network_type(psta->bssrateset, psta->bssratelen, pmlmeext->cur_channel);
  9827. psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
  9828. /* rate radaptive */
  9829. Update_RA_Entry(padapter, psta);
  9830. }
  9831. void mlmeext_sta_del_event_callback(_adapter *padapter)
  9832. {
  9833. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9834. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9835. if (is_client_associated_to_ap(padapter) || is_IBSS_empty(padapter))
  9836. rtw_mlmeext_disconnect(padapter);
  9837. }
  9838. /****************************************************************************
  9839. Following are the functions for the timer handlers
  9840. *****************************************************************************/
  9841. void _linked_info_dump(_adapter *padapter)
  9842. {
  9843. int i;
  9844. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9845. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9846. HAL_DATA_TYPE *HalData = GET_HAL_DATA(padapter);
  9847. int undecorated_smoothed_pwdb = 0;
  9848. if (padapter->bLinkInfoDump) {
  9849. RTW_INFO("\n============["ADPT_FMT"] linked status check ===================\n", ADPT_ARG(padapter));
  9850. if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) {
  9851. rtw_hal_get_def_var(padapter, HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, &undecorated_smoothed_pwdb);
  9852. RTW_INFO("AP[" MAC_FMT "] - undecorated_smoothed_pwdb:%d\n",
  9853. MAC_ARG(padapter->mlmepriv.cur_network.network.MacAddress), undecorated_smoothed_pwdb);
  9854. } else if ((pmlmeinfo->state & 0x03) == _HW_STATE_AP_) {
  9855. _irqL irqL;
  9856. _list *phead, *plist;
  9857. struct sta_info *psta = NULL;
  9858. struct sta_priv *pstapriv = &padapter->stapriv;
  9859. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  9860. phead = &pstapriv->asoc_list;
  9861. plist = get_next(phead);
  9862. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  9863. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  9864. plist = get_next(plist);
  9865. RTW_INFO("STA[" MAC_FMT "]:undecorated_smoothed_pwdb:%d\n",
  9866. MAC_ARG(psta->hwaddr), psta->rssi_stat.undecorated_smoothed_pwdb);
  9867. }
  9868. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  9869. }
  9870. /*============ tx info ============ */
  9871. rtw_hal_get_def_var(padapter, HW_DEF_RA_INFO_DUMP, RTW_DBGDUMP);
  9872. rtw_hal_set_odm_var(padapter, HAL_ODM_RX_INFO_DUMP, RTW_DBGDUMP, _FALSE);
  9873. }
  9874. }
  9875. /********************************************************************
  9876. When station does not receive any packet in MAX_CONTINUAL_NORXPACKET_COUNT*2 seconds,
  9877. recipient station will teardown the block ack by issuing DELBA frame.
  9878. *********************************************************************/
  9879. void rtw_delba_check(_adapter *padapter, struct sta_info *psta, u8 from_timer)
  9880. {
  9881. int i = 0;
  9882. int ret = _SUCCESS;
  9883. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9884. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9885. /*
  9886. IOT issue,occur Broadcom ap(Buffalo WZR-D1800H,Netgear R6300).
  9887. AP is originator.AP does not transmit unicast packets when STA response its BAR.
  9888. This case probably occur ap issue BAR after AP builds BA.
  9889. Follow 802.11 spec, STA shall maintain an inactivity timer for every negotiated Block Ack setup.
  9890. The inactivity timer is not reset when MPDUs corresponding to other TIDs are received.
  9891. */
  9892. if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_BROADCOM) {
  9893. for (i = 0; i < TID_NUM ; i++) {
  9894. if ((psta->recvreorder_ctrl[i].enable) &&
  9895. (sta_rx_data_qos_pkts(psta, i) == sta_last_rx_data_qos_pkts(psta, i)) ) {
  9896. if (_TRUE == rtw_inc_and_chk_continual_no_rx_packet(psta, i)) {
  9897. /* send a DELBA frame to the peer STA with the Reason Code field set to TIMEOUT */
  9898. if (!from_timer)
  9899. ret = issue_del_ba_ex(padapter, psta->hwaddr, i, 39, 0, 3, 1);
  9900. else
  9901. issue_del_ba(padapter, psta->hwaddr, i, 39, 0);
  9902. psta->recvreorder_ctrl[i].enable = _FALSE;
  9903. if (ret != _FAIL)
  9904. psta->recvreorder_ctrl[i].ampdu_size = RX_AMPDU_SIZE_INVALID;
  9905. rtw_reset_continual_no_rx_packet(psta, i);
  9906. }
  9907. } else {
  9908. /* The inactivity timer is reset when MPDUs to the TID is received. */
  9909. rtw_reset_continual_no_rx_packet(psta, i);
  9910. }
  9911. }
  9912. }
  9913. }
  9914. u8 chk_ap_is_alive(_adapter *padapter, struct sta_info *psta)
  9915. {
  9916. u8 ret = _FALSE;
  9917. int i = 0;
  9918. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  9919. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9920. #ifdef DBG_EXPIRATION_CHK
  9921. RTW_INFO(FUNC_ADPT_FMT" rx:"STA_PKTS_FMT", beacon:%llu, probersp_to_self:%llu"
  9922. /*", probersp_bm:%llu, probersp_uo:%llu, probereq:%llu, BI:%u"*/
  9923. ", retry:%u\n"
  9924. , FUNC_ADPT_ARG(padapter)
  9925. , STA_RX_PKTS_DIFF_ARG(psta)
  9926. , psta->sta_stats.rx_beacon_pkts - psta->sta_stats.last_rx_beacon_pkts
  9927. , psta->sta_stats.rx_probersp_pkts - psta->sta_stats.last_rx_probersp_pkts
  9928. /*, psta->sta_stats.rx_probersp_bm_pkts - psta->sta_stats.last_rx_probersp_bm_pkts
  9929. , psta->sta_stats.rx_probersp_uo_pkts - psta->sta_stats.last_rx_probersp_uo_pkts
  9930. , psta->sta_stats.rx_probereq_pkts - psta->sta_stats.last_rx_probereq_pkts
  9931. , pmlmeinfo->bcn_interval*/
  9932. , pmlmeext->retry
  9933. );
  9934. RTW_INFO(FUNC_ADPT_FMT" tx_pkts:%llu, link_count:%u\n", FUNC_ADPT_ARG(padapter)
  9935. , padapter->xmitpriv.tx_pkts
  9936. , pmlmeinfo->link_count
  9937. );
  9938. #endif
  9939. if ((sta_rx_data_pkts(psta) == sta_last_rx_data_pkts(psta))
  9940. && sta_rx_beacon_pkts(psta) == sta_last_rx_beacon_pkts(psta)
  9941. && sta_rx_probersp_pkts(psta) == sta_last_rx_probersp_pkts(psta)
  9942. )
  9943. ret = _FALSE;
  9944. else
  9945. ret = _TRUE;
  9946. sta_update_last_rx_pkts(psta);
  9947. /*
  9948. record last rx data packets for every tid.
  9949. */
  9950. for (i = 0; i < TID_NUM; i++)
  9951. psta->sta_stats.last_rx_data_qos_pkts[i] = psta->sta_stats.rx_data_qos_pkts[i];
  9952. return ret;
  9953. }
  9954. u8 chk_adhoc_peer_is_alive(struct sta_info *psta)
  9955. {
  9956. u8 ret = _TRUE;
  9957. #ifdef DBG_EXPIRATION_CHK
  9958. RTW_INFO("sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", beacon:%llu, probersp_to_self:%llu"
  9959. /*", probersp_bm:%llu, probersp_uo:%llu, probereq:%llu, BI:%u"*/
  9960. ", expire_to:%u\n"
  9961. , MAC_ARG(psta->hwaddr)
  9962. , psta->rssi_stat.undecorated_smoothed_pwdb
  9963. , STA_RX_PKTS_DIFF_ARG(psta)
  9964. , psta->sta_stats.rx_beacon_pkts - psta->sta_stats.last_rx_beacon_pkts
  9965. , psta->sta_stats.rx_probersp_pkts - psta->sta_stats.last_rx_probersp_pkts
  9966. /*, psta->sta_stats.rx_probersp_bm_pkts - psta->sta_stats.last_rx_probersp_bm_pkts
  9967. , psta->sta_stats.rx_probersp_uo_pkts - psta->sta_stats.last_rx_probersp_uo_pkts
  9968. , psta->sta_stats.rx_probereq_pkts - psta->sta_stats.last_rx_probereq_pkts
  9969. , pmlmeinfo->bcn_interval*/
  9970. , psta->expire_to
  9971. );
  9972. #endif
  9973. if (sta_rx_data_pkts(psta) == sta_last_rx_data_pkts(psta)
  9974. && sta_rx_beacon_pkts(psta) == sta_last_rx_beacon_pkts(psta)
  9975. && sta_rx_probersp_pkts(psta) == sta_last_rx_probersp_pkts(psta))
  9976. ret = _FALSE;
  9977. sta_update_last_rx_pkts(psta);
  9978. return ret;
  9979. }
  9980. #ifdef CONFIG_TDLS
  9981. u8 chk_tdls_peer_sta_is_alive(_adapter *padapter, struct sta_info *psta)
  9982. {
  9983. if ((psta->sta_stats.rx_data_pkts == psta->sta_stats.last_rx_data_pkts)
  9984. && (psta->sta_stats.rx_tdls_disc_rsp_pkts == psta->sta_stats.last_rx_tdls_disc_rsp_pkts))
  9985. return _FALSE;
  9986. return _TRUE;
  9987. }
  9988. void linked_status_chk_tdls(_adapter *padapter)
  9989. {
  9990. struct candidate_pool {
  9991. struct sta_info *psta;
  9992. u8 addr[ETH_ALEN];
  9993. };
  9994. struct sta_priv *pstapriv = &padapter->stapriv;
  9995. _irqL irqL;
  9996. u8 ack_chk;
  9997. struct sta_info *psta;
  9998. int i, num_teardown = 0, num_checkalive = 0;
  9999. _list *plist, *phead;
  10000. struct tdls_txmgmt txmgmt;
  10001. struct candidate_pool checkalive[MAX_ALLOWED_TDLS_STA_NUM];
  10002. struct candidate_pool teardown[MAX_ALLOWED_TDLS_STA_NUM];
  10003. u8 tdls_sta_max = _FALSE;
  10004. #define ALIVE_MIN 2
  10005. #define ALIVE_MAX 5
  10006. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  10007. _rtw_memset(checkalive, 0x00, sizeof(checkalive));
  10008. _rtw_memset(teardown, 0x00, sizeof(teardown));
  10009. if ((padapter->tdlsinfo.link_established == _TRUE)) {
  10010. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  10011. for (i = 0; i < NUM_STA; i++) {
  10012. phead = &(pstapriv->sta_hash[i]);
  10013. plist = get_next(phead);
  10014. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  10015. psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
  10016. plist = get_next(plist);
  10017. if (psta->tdls_sta_state & TDLS_LINKED_STATE) {
  10018. psta->alive_count++;
  10019. if (psta->alive_count >= ALIVE_MIN) {
  10020. if (chk_tdls_peer_sta_is_alive(padapter, psta) == _FALSE) {
  10021. if (psta->alive_count < ALIVE_MAX) {
  10022. _rtw_memcpy(checkalive[num_checkalive].addr, psta->hwaddr, ETH_ALEN);
  10023. checkalive[num_checkalive].psta = psta;
  10024. num_checkalive++;
  10025. } else {
  10026. _rtw_memcpy(teardown[num_teardown].addr, psta->hwaddr, ETH_ALEN);
  10027. teardown[num_teardown].psta = psta;
  10028. num_teardown++;
  10029. }
  10030. } else
  10031. psta->alive_count = 0;
  10032. }
  10033. psta->sta_stats.last_rx_data_pkts = psta->sta_stats.rx_data_pkts;
  10034. psta->sta_stats.last_rx_tdls_disc_rsp_pkts = psta->sta_stats.rx_tdls_disc_rsp_pkts;
  10035. if ((num_checkalive >= MAX_ALLOWED_TDLS_STA_NUM) || (num_teardown >= MAX_ALLOWED_TDLS_STA_NUM)) {
  10036. tdls_sta_max = _TRUE;
  10037. break;
  10038. }
  10039. }
  10040. }
  10041. if (tdls_sta_max == _TRUE)
  10042. break;
  10043. }
  10044. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  10045. if (num_checkalive > 0) {
  10046. for (i = 0; i < num_checkalive; i++) {
  10047. _rtw_memcpy(txmgmt.peer, checkalive[i].addr, ETH_ALEN);
  10048. issue_tdls_dis_req(padapter, &txmgmt);
  10049. issue_tdls_dis_req(padapter, &txmgmt);
  10050. issue_tdls_dis_req(padapter, &txmgmt);
  10051. }
  10052. }
  10053. if (num_teardown > 0) {
  10054. for (i = 0; i < num_teardown; i++) {
  10055. RTW_INFO("[%s %d] Send teardown to "MAC_FMT"\n", __FUNCTION__, __LINE__, MAC_ARG(teardown[i].addr));
  10056. txmgmt.status_code = _RSON_TDLS_TEAR_TOOFAR_;
  10057. _rtw_memcpy(txmgmt.peer, teardown[i].addr, ETH_ALEN);
  10058. issue_tdls_teardown(padapter, &txmgmt, _FALSE);
  10059. }
  10060. }
  10061. }
  10062. }
  10063. #endif /* CONFIG_TDLS */
  10064. /* from_timer == 1 means driver is in LPS */
  10065. void linked_status_chk(_adapter *padapter, u8 from_timer)
  10066. {
  10067. u32 i;
  10068. struct sta_info *psta;
  10069. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  10070. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10071. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10072. struct sta_priv *pstapriv = &padapter->stapriv;
  10073. #if defined(CONFIG_ARP_KEEP_ALIVE) || defined(CONFIG_LAYER2_ROAMING)
  10074. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  10075. #endif
  10076. #ifdef CONFIG_LAYER2_ROAMING
  10077. struct recv_priv *precvpriv = &padapter->recvpriv;
  10078. #endif
  10079. if (padapter->registrypriv.mp_mode == _TRUE)
  10080. return;
  10081. if (is_client_associated_to_ap(padapter)) {
  10082. /* linked infrastructure client mode */
  10083. int tx_chk = _SUCCESS, rx_chk = _SUCCESS;
  10084. int rx_chk_limit;
  10085. int link_count_limit;
  10086. #ifdef CONFIG_LAYER2_ROAMING
  10087. if (rtw_chk_roam_flags(padapter, RTW_ROAM_ACTIVE)) {
  10088. RTW_INFO("signal_strength_data.avg_val = %d\n", precvpriv->signal_strength_data.avg_val);
  10089. if (precvpriv->signal_strength_data.avg_val < pmlmepriv->roam_rssi_threshold) {
  10090. pmlmepriv->need_to_roam = _TRUE;
  10091. rtw_drv_scan_by_self(padapter, RTW_AUTO_SCAN_REASON_ROAM);
  10092. } else {
  10093. pmlmepriv->need_to_roam = _FALSE;
  10094. }
  10095. }
  10096. #endif
  10097. #ifdef CONFIG_MCC_MODE
  10098. /*
  10099. * due to tx ps null date to ao, so ap doest not tx pkt to driver
  10100. * we may check chk_ap_is_alive fail, and may issue_probereq to wrong channel under sitesurvey
  10101. * don't keep alive check under MCC
  10102. */
  10103. if (rtw_hal_mcc_link_status_chk(padapter, __func__) == _FALSE)
  10104. return;
  10105. #endif
  10106. #if defined(DBG_ROAMING_TEST)
  10107. rx_chk_limit = 1;
  10108. #elif defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && !defined(CONFIG_LPS_LCLK_WD_TIMER)
  10109. rx_chk_limit = 4;
  10110. #else
  10111. rx_chk_limit = 8;
  10112. #endif
  10113. #ifdef CONFIG_ARP_KEEP_ALIVE
  10114. if (!from_timer && pmlmepriv->bGetGateway == 1 && pmlmepriv->GetGatewayTryCnt < 3) {
  10115. RTW_INFO("do rtw_gw_addr_query() : %d\n", pmlmepriv->GetGatewayTryCnt);
  10116. pmlmepriv->GetGatewayTryCnt++;
  10117. if (rtw_gw_addr_query(padapter) == 0)
  10118. pmlmepriv->bGetGateway = 0;
  10119. else {
  10120. _rtw_memset(pmlmepriv->gw_ip, 0, 4);
  10121. _rtw_memset(pmlmepriv->gw_mac_addr, 0, 6);
  10122. }
  10123. }
  10124. #endif
  10125. #ifdef CONFIG_P2P
  10126. if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE)) {
  10127. if (!from_timer)
  10128. link_count_limit = 3; /* 8 sec */
  10129. else
  10130. link_count_limit = 15; /* 32 sec */
  10131. } else
  10132. #endif /* CONFIG_P2P */
  10133. {
  10134. if (!from_timer)
  10135. link_count_limit = 7; /* 16 sec */
  10136. else
  10137. link_count_limit = 29; /* 60 sec */
  10138. }
  10139. #ifdef CONFIG_TDLS
  10140. #ifdef CONFIG_TDLS_CH_SW
  10141. if (ATOMIC_READ(&padapter->tdlsinfo.chsw_info.chsw_on) == _TRUE)
  10142. return;
  10143. #endif /* CONFIG_TDLS_CH_SW */
  10144. #ifdef CONFIG_TDLS_AUTOCHECKALIVE
  10145. linked_status_chk_tdls(padapter);
  10146. #endif /* CONFIG_TDLS_AUTOCHECKALIVE */
  10147. #endif /* CONFIG_TDLS */
  10148. psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress);
  10149. if (psta != NULL) {
  10150. bool is_p2p_enable = _FALSE;
  10151. #ifdef CONFIG_P2P
  10152. is_p2p_enable = !rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE);
  10153. #endif
  10154. #ifdef CONFIG_ISSUE_DELBA_WHEN_NO_TRAFFIC
  10155. /*issue delba when ap does not tx data packet that is Broadcom ap */
  10156. rtw_delba_check(padapter, psta, from_timer);
  10157. #endif
  10158. if (chk_ap_is_alive(padapter, psta) == _FALSE)
  10159. rx_chk = _FAIL;
  10160. if (pxmitpriv->last_tx_pkts == pxmitpriv->tx_pkts)
  10161. tx_chk = _FAIL;
  10162. #if defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && !defined(CONFIG_LPS_LCLK_WD_TIMER)
  10163. if (pmlmeext->active_keep_alive_check && (rx_chk == _FAIL || tx_chk == _FAIL)
  10164. #ifdef CONFIG_MCC_MODE
  10165. /* Driver don't know operation channel under MCC*/
  10166. /* So driver don't do KEEP_ALIVE_CHECK */
  10167. && (!rtw_hal_check_mcc_status(padapter, MCC_STATUS_NEED_MCC))
  10168. #endif
  10169. ) {
  10170. u8 backup_ch = 0, backup_bw, backup_offset;
  10171. u8 union_ch = 0, union_bw, union_offset;
  10172. if (!rtw_mi_get_ch_setting_union(padapter, &union_ch, &union_bw, &union_offset)
  10173. || pmlmeext->cur_channel != union_ch)
  10174. goto bypass_active_keep_alive;
  10175. /* switch to correct channel of current network before issue keep-alive frames */
  10176. if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
  10177. backup_ch = rtw_get_oper_ch(padapter);
  10178. backup_bw = rtw_get_oper_bw(padapter);
  10179. backup_offset = rtw_get_oper_choffset(padapter);
  10180. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  10181. }
  10182. if (rx_chk != _SUCCESS)
  10183. issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, psta->hwaddr, 0, 0, 3, 1);
  10184. if ((tx_chk != _SUCCESS && pmlmeinfo->link_count++ == link_count_limit) || rx_chk != _SUCCESS) {
  10185. tx_chk = issue_nulldata(padapter, psta->hwaddr, 0, 3, 1);
  10186. /* if tx acked and p2p disabled, set rx_chk _SUCCESS to reset retry count */
  10187. if (tx_chk == _SUCCESS && !is_p2p_enable)
  10188. rx_chk = _SUCCESS;
  10189. }
  10190. /* back to the original operation channel */
  10191. if (backup_ch > 0)
  10192. set_channel_bwmode(padapter, backup_ch, backup_offset, backup_bw);
  10193. bypass_active_keep_alive:
  10194. ;
  10195. } else
  10196. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  10197. {
  10198. if (rx_chk != _SUCCESS) {
  10199. if (pmlmeext->retry == 0) {
  10200. #ifdef DBG_EXPIRATION_CHK
  10201. RTW_INFO("issue_probereq to trigger probersp, retry=%d\n", pmlmeext->retry);
  10202. #endif
  10203. issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress, 0, 0, 0, 0);
  10204. issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress, 0, 0, 0, 0);
  10205. issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress, 0, 0, 0, 0);
  10206. }
  10207. }
  10208. if (tx_chk != _SUCCESS && pmlmeinfo->link_count++ == link_count_limit
  10209. #ifdef CONFIG_MCC_MODE
  10210. /* FW tx nulldata under MCC mode, we just check ap is alive */
  10211. && (!rtw_hal_check_mcc_status(padapter, MCC_STATUS_NEED_MCC))
  10212. #endif /* CONFIG_MCC_MODE */
  10213. ) {
  10214. #ifdef DBG_EXPIRATION_CHK
  10215. RTW_INFO("%s issue_nulldata(%d)\n", __FUNCTION__, from_timer ? 1 : 0);
  10216. #endif
  10217. tx_chk = issue_nulldata_in_interrupt(padapter, NULL, from_timer ? 1 : 0);
  10218. }
  10219. }
  10220. if (rx_chk == _FAIL) {
  10221. pmlmeext->retry++;
  10222. if (pmlmeext->retry > rx_chk_limit) {
  10223. RTW_PRINT(FUNC_ADPT_FMT" disconnect or roaming\n",
  10224. FUNC_ADPT_ARG(padapter));
  10225. receive_disconnect(padapter, pmlmeinfo->network.MacAddress
  10226. , WLAN_REASON_EXPIRATION_CHK, _FALSE);
  10227. return;
  10228. }
  10229. } else
  10230. pmlmeext->retry = 0;
  10231. if (tx_chk == _FAIL)
  10232. pmlmeinfo->link_count %= (link_count_limit + 1);
  10233. else {
  10234. pxmitpriv->last_tx_pkts = pxmitpriv->tx_pkts;
  10235. pmlmeinfo->link_count = 0;
  10236. }
  10237. } /* end of if ((psta = rtw_get_stainfo(pstapriv, passoc_res->network.MacAddress)) != NULL) */
  10238. } else if (is_client_associated_to_ibss(padapter)) {
  10239. _irqL irqL;
  10240. _list *phead, *plist, dlist;
  10241. _rtw_init_listhead(&dlist);
  10242. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  10243. for (i = 0; i < NUM_STA; i++) {
  10244. phead = &(pstapriv->sta_hash[i]);
  10245. plist = get_next(phead);
  10246. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  10247. psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
  10248. plist = get_next(plist);
  10249. if (is_broadcast_mac_addr(psta->hwaddr))
  10250. continue;
  10251. if (chk_adhoc_peer_is_alive(psta) || !psta->expire_to)
  10252. psta->expire_to = pstapriv->adhoc_expire_to;
  10253. else
  10254. psta->expire_to--;
  10255. if (psta->expire_to <= 0) {
  10256. rtw_list_delete(&psta->list);
  10257. rtw_list_insert_tail(&psta->list, &dlist);
  10258. }
  10259. }
  10260. }
  10261. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  10262. plist = get_next(&dlist);
  10263. while (rtw_end_of_queue_search(&dlist, plist) == _FALSE) {
  10264. psta = LIST_CONTAINOR(plist, struct sta_info, list);
  10265. plist = get_next(plist);
  10266. rtw_list_delete(&psta->list);
  10267. RTW_INFO(FUNC_ADPT_FMT" ibss expire "MAC_FMT"\n"
  10268. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->hwaddr));
  10269. report_del_sta_event(padapter, psta->hwaddr, WLAN_REASON_EXPIRATION_CHK, from_timer ? _TRUE : _FALSE, _FALSE);
  10270. }
  10271. }
  10272. }
  10273. void survey_timer_hdl(struct timer_list *t)
  10274. {
  10275. struct mlme_ext_priv *pmlmeext = from_timer(pmlmeext, t, survey_timer);
  10276. _adapter *padapter = container_of(pmlmeext, _adapter, mlmeextpriv);
  10277. struct cmd_obj *cmd;
  10278. struct sitesurvey_parm *psurveyPara;
  10279. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  10280. #ifdef CONFIG_P2P
  10281. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  10282. #endif
  10283. if (mlmeext_scan_state(pmlmeext) > SCAN_DISABLE) {
  10284. cmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  10285. if (cmd == NULL) {
  10286. rtw_warn_on(1);
  10287. goto exit;
  10288. }
  10289. psurveyPara = (struct sitesurvey_parm *)rtw_zmalloc(sizeof(struct sitesurvey_parm));
  10290. if (psurveyPara == NULL) {
  10291. rtw_warn_on(1);
  10292. rtw_mfree((unsigned char *)cmd, sizeof(struct cmd_obj));
  10293. goto exit;
  10294. }
  10295. init_h2fwcmd_w_parm_no_rsp(cmd, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
  10296. rtw_enqueue_cmd(pcmdpriv, cmd);
  10297. }
  10298. exit:
  10299. return;
  10300. }
  10301. void link_timer_hdl(struct timer_list *t)
  10302. {
  10303. struct mlme_ext_priv *pmlmeext = from_timer(pmlmeext, t, link_timer);
  10304. _adapter *padapter = container_of(pmlmeext, _adapter, mlmeextpriv);
  10305. /* static unsigned int rx_pkt = 0; */
  10306. /* static u64 tx_cnt = 0; */
  10307. /* struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); */
  10308. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10309. /* struct sta_priv *pstapriv = &padapter->stapriv; */
  10310. #ifdef CONFIG_RTW_80211R
  10311. struct sta_priv *pstapriv = &padapter->stapriv;
  10312. struct sta_info *psta = NULL;
  10313. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
  10314. #endif
  10315. if (rtw_sta_linking_test_force_fail())
  10316. RTW_INFO("rtw_sta_linking_test_force_fail\n");
  10317. if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
  10318. RTW_INFO("link_timer_hdl:no beacon while connecting\n");
  10319. pmlmeinfo->state = WIFI_FW_NULL_STATE;
  10320. report_join_res(padapter, -3);
  10321. } else if (pmlmeinfo->state & WIFI_FW_AUTH_STATE) {
  10322. /* re-auth timer */
  10323. if (++pmlmeinfo->reauth_count > REAUTH_LIMIT) {
  10324. /* if (pmlmeinfo->auth_algo != dot11AuthAlgrthm_Auto) */
  10325. /* { */
  10326. pmlmeinfo->state = 0;
  10327. report_join_res(padapter, -1);
  10328. return;
  10329. /* } */
  10330. /* else */
  10331. /* { */
  10332. /* pmlmeinfo->auth_algo = dot11AuthAlgrthm_Shared; */
  10333. /* pmlmeinfo->reauth_count = 0; */
  10334. /* } */
  10335. }
  10336. RTW_INFO("link_timer_hdl: auth timeout and try again\n");
  10337. pmlmeinfo->auth_seq = 1;
  10338. issue_auth(padapter, NULL, 0);
  10339. set_link_timer(pmlmeext, REAUTH_TO);
  10340. } else if (pmlmeinfo->state & WIFI_FW_ASSOC_STATE) {
  10341. /* re-assoc timer */
  10342. if (++pmlmeinfo->reassoc_count > REASSOC_LIMIT) {
  10343. pmlmeinfo->state = WIFI_FW_NULL_STATE;
  10344. #ifdef CONFIG_RTW_80211R
  10345. if ((rtw_to_roam(padapter) > 0) && rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED)) {
  10346. psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress);
  10347. if (psta)
  10348. rtw_free_stainfo(padapter, psta);
  10349. }
  10350. #endif
  10351. report_join_res(padapter, -2);
  10352. return;
  10353. }
  10354. #ifdef CONFIG_RTW_80211R
  10355. if ((rtw_to_roam(padapter) > 0) && rtw_chk_ft_flags(padapter, RTW_FT_SUPPORTED)) {
  10356. RTW_INFO("link_timer_hdl: reassoc timeout and try again\n");
  10357. issue_reassocreq(padapter);
  10358. } else
  10359. #endif
  10360. {
  10361. RTW_INFO("link_timer_hdl: assoc timeout and try again\n");
  10362. issue_assocreq(padapter);
  10363. }
  10364. set_link_timer(pmlmeext, REASSOC_TO);
  10365. }
  10366. return;
  10367. }
  10368. void addba_timer_hdl(struct timer_list *t)
  10369. {
  10370. struct sta_info *psta = from_timer(psta, t, addba_retry_timer);
  10371. #ifdef CONFIG_80211N_HT
  10372. struct ht_priv *phtpriv;
  10373. if (!psta)
  10374. return;
  10375. phtpriv = &psta->htpriv;
  10376. if ((phtpriv->ht_option == _TRUE) && (phtpriv->ampdu_enable == _TRUE)) {
  10377. if (phtpriv->candidate_tid_bitmap)
  10378. phtpriv->candidate_tid_bitmap = 0x0;
  10379. }
  10380. #endif /* CONFIG_80211N_HT */
  10381. }
  10382. #ifdef CONFIG_IEEE80211W
  10383. void report_sta_timeout_event(_adapter *padapter, u8 *MacAddr, unsigned short reason)
  10384. {
  10385. struct cmd_obj *pcmd_obj;
  10386. u8 *pevtcmd;
  10387. u32 cmdsz;
  10388. struct sta_info *psta;
  10389. int mac_id;
  10390. struct stadel_event *pdel_sta_evt;
  10391. struct C2HEvent_Header *pc2h_evt_hdr;
  10392. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10393. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  10394. pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  10395. if (pcmd_obj == NULL)
  10396. return;
  10397. cmdsz = (sizeof(struct stadel_event) + sizeof(struct C2HEvent_Header));
  10398. pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
  10399. if (pevtcmd == NULL) {
  10400. rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
  10401. return;
  10402. }
  10403. _rtw_init_listhead(&pcmd_obj->list);
  10404. pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
  10405. pcmd_obj->cmdsz = cmdsz;
  10406. pcmd_obj->parmbuf = pevtcmd;
  10407. pcmd_obj->rsp = NULL;
  10408. pcmd_obj->rspsz = 0;
  10409. pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
  10410. pc2h_evt_hdr->len = sizeof(struct stadel_event);
  10411. pc2h_evt_hdr->ID = GEN_EVT_CODE(_TimeoutSTA);
  10412. pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
  10413. pdel_sta_evt = (struct stadel_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
  10414. _rtw_memcpy((unsigned char *)(&(pdel_sta_evt->macaddr)), MacAddr, ETH_ALEN);
  10415. _rtw_memcpy((unsigned char *)(pdel_sta_evt->rsvd), (unsigned char *)(&reason), 2);
  10416. psta = rtw_get_stainfo(&padapter->stapriv, MacAddr);
  10417. if (psta)
  10418. mac_id = (int)psta->mac_id;
  10419. else
  10420. mac_id = (-1);
  10421. pdel_sta_evt->mac_id = mac_id;
  10422. RTW_INFO("report_del_sta_event: delete STA, mac_id=%d\n", mac_id);
  10423. rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
  10424. return;
  10425. }
  10426. void clnt_sa_query_timeout(_adapter *padapter)
  10427. {
  10428. rtw_disassoc_cmd(padapter, 0, 0);
  10429. rtw_indicate_disconnect(padapter, 0, _FALSE);
  10430. rtw_free_assoc_resources(padapter, 1);
  10431. RTW_INFO("SA query timeout client disconnect\n");
  10432. }
  10433. void sa_query_timer_hdl(void *ctx)
  10434. {
  10435. struct sta_info *psta = (struct sta_info *)ctx;
  10436. _adapter *padapter = psta->padapter;
  10437. _irqL irqL;
  10438. struct sta_priv *pstapriv = &padapter->stapriv;
  10439. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  10440. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE &&
  10441. check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  10442. clnt_sa_query_timeout(padapter);
  10443. else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  10444. report_sta_timeout_event(padapter, psta->hwaddr, WLAN_REASON_PREV_AUTH_NOT_VALID);
  10445. }
  10446. #endif /* CONFIG_IEEE80211W */
  10447. #ifdef CONFIG_RTW_80211R
  10448. void start_clnt_ft_action(_adapter *padapter, u8 *pTargetAddr)
  10449. {
  10450. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10451. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10452. rtw_set_ft_status(padapter, RTW_FT_REQUESTING_STA);
  10453. issue_action_ft_request(padapter, pTargetAddr);
  10454. _set_timer(&pmlmeext->ft_link_timer, REASSOC_TO);
  10455. }
  10456. void ft_link_timer_hdl(void *ctx)
  10457. {
  10458. _adapter *padapter = (_adapter *)ctx;
  10459. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10460. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10461. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  10462. ft_priv *pftpriv = &pmlmepriv->ftpriv;
  10463. if (rtw_chk_ft_status(padapter, RTW_FT_REQUESTING_STA)) {
  10464. if (pftpriv->ft_req_retry_cnt < FT_ACTION_REQ_LIMIT) {
  10465. pftpriv->ft_req_retry_cnt++;
  10466. issue_action_ft_request(padapter, (u8 *)pmlmepriv->roam_network->network.MacAddress);
  10467. _set_timer(&pmlmeext->ft_link_timer, REASSOC_TO);
  10468. } else {
  10469. pftpriv->ft_req_retry_cnt = 0;
  10470. if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
  10471. rtw_set_ft_status(padapter, RTW_FT_ASSOCIATED_STA);
  10472. else
  10473. rtw_reset_ft_status(padapter);
  10474. }
  10475. }
  10476. }
  10477. void ft_roam_timer_hdl(void *ctx)
  10478. {
  10479. _adapter *padapter = (_adapter *)ctx;
  10480. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  10481. receive_disconnect(padapter, pmlmepriv->cur_network.network.MacAddress
  10482. , WLAN_REASON_ACTIVE_ROAM, _FALSE);
  10483. }
  10484. void issue_action_ft_request(_adapter *padapter, u8 *pTargetAddr)
  10485. {
  10486. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  10487. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  10488. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  10489. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10490. struct xmit_frame *pmgntframe = NULL;
  10491. struct rtw_ieee80211_hdr *pwlanhdr = NULL;
  10492. struct pkt_attrib *pattrib = NULL;
  10493. ft_priv *pftpriv = NULL;
  10494. u8 *pframe = NULL;
  10495. u8 category = RTW_WLAN_CATEGORY_FT;
  10496. u8 action = RTW_WLAN_ACTION_FT_REQUEST;
  10497. u8 is_ft_roaming_with_rsn_ie = _TRUE;
  10498. u8 *pie = NULL;
  10499. u16 *fctrl = NULL;
  10500. u32 ft_ie_len = 0;
  10501. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  10502. if (pmgntframe == NULL)
  10503. return;
  10504. pattrib = &pmgntframe->attrib;
  10505. update_mgntframe_attrib(padapter, pattrib);
  10506. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  10507. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  10508. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  10509. fctrl = &(pwlanhdr->frame_ctl);
  10510. *(fctrl) = 0;
  10511. _rtw_memcpy(pwlanhdr->addr1, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
  10512. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  10513. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
  10514. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  10515. pmlmeext->mgnt_seq++;
  10516. set_frame_sub_type(pframe, WIFI_ACTION);
  10517. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  10518. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  10519. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  10520. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  10521. _rtw_memcpy(pframe, adapter_mac_addr(padapter), ETH_ALEN);
  10522. pframe += ETH_ALEN;
  10523. pattrib->pktlen += ETH_ALEN;
  10524. _rtw_memcpy(pframe, pTargetAddr, ETH_ALEN);
  10525. pframe += ETH_ALEN;
  10526. pattrib->pktlen += ETH_ALEN;
  10527. pftpriv = &pmlmepriv->ftpriv;
  10528. pie = rtw_get_ie(pftpriv->updated_ft_ies, EID_WPA2, &ft_ie_len, pftpriv->updated_ft_ies_len);
  10529. if (pie)
  10530. pframe = rtw_set_ie(pframe, EID_WPA2, ft_ie_len, pie+2, &(pattrib->pktlen));
  10531. else
  10532. is_ft_roaming_with_rsn_ie = _FALSE;
  10533. pie = rtw_get_ie(pftpriv->updated_ft_ies, _MDIE_, &ft_ie_len, pftpriv->updated_ft_ies_len);
  10534. if (pie)
  10535. pframe = rtw_set_ie(pframe, _MDIE_, ft_ie_len , pie+2, &(pattrib->pktlen));
  10536. pie = rtw_get_ie(pftpriv->updated_ft_ies, _FTIE_, &ft_ie_len, pftpriv->updated_ft_ies_len);
  10537. if (pie && is_ft_roaming_with_rsn_ie)
  10538. pframe = rtw_set_ie(pframe, _FTIE_, ft_ie_len , pie+2, &(pattrib->pktlen));
  10539. pattrib->last_txcmdsz = pattrib->pktlen;
  10540. dump_mgntframe(padapter, pmgntframe);
  10541. }
  10542. void report_ft_event(_adapter *padapter)
  10543. {
  10544. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  10545. ft_priv *pftpriv = &pmlmepriv->ftpriv;
  10546. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10547. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10548. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
  10549. struct cfg80211_ft_event_params ft_evt_parms;
  10550. _irqL irqL;
  10551. _rtw_memset(&ft_evt_parms, 0, sizeof(ft_evt_parms));
  10552. rtw_update_ft_stainfo(padapter, pnetwork);
  10553. if (!pnetwork)
  10554. goto err_2;
  10555. ft_evt_parms.ies_len = pftpriv->ft_event.ies_len;
  10556. ft_evt_parms.ies = rtw_zmalloc(ft_evt_parms.ies_len);
  10557. if (ft_evt_parms.ies)
  10558. _rtw_memcpy((void *)ft_evt_parms.ies, pftpriv->ft_event.ies, ft_evt_parms.ies_len);
  10559. else
  10560. goto err_2;
  10561. ft_evt_parms.target_ap = rtw_zmalloc(ETH_ALEN);
  10562. if (ft_evt_parms.target_ap)
  10563. _rtw_memcpy((void *)ft_evt_parms.target_ap, pnetwork->MacAddress, ETH_ALEN);
  10564. else
  10565. goto err_1;
  10566. ft_evt_parms.ric_ies = pftpriv->ft_event.ric_ies;
  10567. ft_evt_parms.ric_ies_len = pftpriv->ft_event.ric_ies_len;
  10568. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  10569. rtw_set_ft_status(padapter, RTW_FT_AUTHENTICATED_STA);
  10570. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  10571. rtw_cfg80211_ft_event(padapter, &ft_evt_parms);
  10572. RTW_INFO("FT: report_ft_event\n");
  10573. rtw_mfree((u8 *)pftpriv->ft_event.target_ap, ETH_ALEN);
  10574. err_1:
  10575. rtw_mfree((u8 *)ft_evt_parms.ies, ft_evt_parms.ies_len);
  10576. err_2:
  10577. return;
  10578. }
  10579. void report_ft_reassoc_event(_adapter *padapter, u8 *pMacAddr)
  10580. {
  10581. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10582. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  10583. struct cmd_obj *pcmd_obj = NULL;
  10584. struct stassoc_event *passoc_sta_evt = NULL;
  10585. struct C2HEvent_Header *pc2h_evt_hdr = NULL;
  10586. u8 *pevtcmd = NULL;
  10587. u32 cmdsz = 0;
  10588. pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  10589. if (pcmd_obj == NULL)
  10590. return;
  10591. cmdsz = (sizeof(struct stassoc_event) + sizeof(struct C2HEvent_Header));
  10592. pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
  10593. if (pevtcmd == NULL) {
  10594. rtw_mfree((u8 *)pcmd_obj, sizeof(struct cmd_obj));
  10595. return;
  10596. }
  10597. _rtw_init_listhead(&pcmd_obj->list);
  10598. pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
  10599. pcmd_obj->cmdsz = cmdsz;
  10600. pcmd_obj->parmbuf = pevtcmd;
  10601. pcmd_obj->rsp = NULL;
  10602. pcmd_obj->rspsz = 0;
  10603. pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
  10604. pc2h_evt_hdr->len = sizeof(struct stassoc_event);
  10605. pc2h_evt_hdr->ID = GEN_EVT_CODE(_FT_REASSOC);
  10606. pc2h_evt_hdr->seq = ATOMIC_INC_RETURN(&pmlmeext->event_seq);
  10607. passoc_sta_evt = (struct stassoc_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
  10608. _rtw_memcpy((unsigned char *)(&(passoc_sta_evt->macaddr)), pMacAddr, ETH_ALEN);
  10609. rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
  10610. }
  10611. #endif
  10612. u8 NULL_hdl(_adapter *padapter, u8 *pbuf)
  10613. {
  10614. return H2C_SUCCESS;
  10615. }
  10616. #ifdef CONFIG_AUTO_AP_MODE
  10617. void rtw_start_auto_ap(_adapter *adapter)
  10618. {
  10619. RTW_INFO("%s\n", __FUNCTION__);
  10620. rtw_set_802_11_infrastructure_mode(adapter, Ndis802_11APMode);
  10621. rtw_setopmode_cmd(adapter, Ndis802_11APMode, _TRUE);
  10622. }
  10623. static int rtw_auto_ap_start_beacon(_adapter *adapter)
  10624. {
  10625. int ret = 0;
  10626. u8 *pbuf = NULL;
  10627. uint len;
  10628. u8 supportRate[16];
  10629. int sz = 0, rateLen;
  10630. u8 *ie;
  10631. u8 wireless_mode, oper_channel;
  10632. u8 ssid[3] = {0}; /* hidden ssid */
  10633. u32 ssid_len = sizeof(ssid);
  10634. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  10635. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  10636. return -EINVAL;
  10637. len = 128;
  10638. pbuf = rtw_zmalloc(len);
  10639. if (!pbuf)
  10640. return -ENOMEM;
  10641. /* generate beacon */
  10642. ie = pbuf;
  10643. /* timestamp will be inserted by hardware */
  10644. sz += 8;
  10645. ie += sz;
  10646. /* beacon interval : 2bytes */
  10647. *(u16 *)ie = cpu_to_le16((u16)100); /* BCN_INTERVAL=100; */
  10648. sz += 2;
  10649. ie += 2;
  10650. /* capability info */
  10651. *(u16 *)ie = 0;
  10652. *(u16 *)ie |= cpu_to_le16(cap_ESS);
  10653. *(u16 *)ie |= cpu_to_le16(cap_ShortPremble);
  10654. /* *(u16*)ie |= cpu_to_le16(cap_Privacy); */
  10655. sz += 2;
  10656. ie += 2;
  10657. /* SSID */
  10658. ie = rtw_set_ie(ie, _SSID_IE_, ssid_len, ssid, &sz);
  10659. /* supported rates */
  10660. wireless_mode = WIRELESS_11BG_24N;
  10661. rtw_set_supported_rate(supportRate, wireless_mode) ;
  10662. rateLen = rtw_get_rateset_len(supportRate);
  10663. if (rateLen > 8)
  10664. ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, supportRate, &sz);
  10665. else
  10666. ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, supportRate, &sz);
  10667. /* DS parameter set */
  10668. if (rtw_mi_check_status(adapter, MI_LINKED))
  10669. oper_channel = rtw_mi_get_union_chan(adapter);
  10670. else
  10671. oper_channel = adapter_to_dvobj(adapter)->oper_channel;
  10672. ie = rtw_set_ie(ie, _DSSET_IE_, 1, &oper_channel, &sz);
  10673. /* ext supported rates */
  10674. if (rateLen > 8)
  10675. ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (supportRate + 8), &sz);
  10676. RTW_INFO("%s, start auto ap beacon sz=%d\n", __FUNCTION__, sz);
  10677. /* lunch ap mode & start to issue beacon */
  10678. if (rtw_check_beacon_data(adapter, pbuf, sz) == _SUCCESS) {
  10679. } else
  10680. ret = -EINVAL;
  10681. rtw_mfree(pbuf, len);
  10682. return ret;
  10683. }
  10684. #endif/* CONFIG_AUTO_AP_MODE */
  10685. u8 setopmode_hdl(_adapter *padapter, u8 *pbuf)
  10686. {
  10687. u8 type;
  10688. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10689. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10690. struct setopmode_parm *psetop = (struct setopmode_parm *)pbuf;
  10691. if (psetop->mode == Ndis802_11APMode) {
  10692. pmlmeinfo->state = WIFI_FW_AP_STATE;
  10693. type = _HW_STATE_AP_;
  10694. #ifdef CONFIG_NATIVEAP_MLME
  10695. /* start_ap_mode(padapter); */
  10696. #endif
  10697. } else if (psetop->mode == Ndis802_11Infrastructure) {
  10698. pmlmeinfo->state &= ~(BIT(0) | BIT(1)); /* clear state */
  10699. pmlmeinfo->state |= WIFI_FW_STATION_STATE;/* set to STATION_STATE */
  10700. type = _HW_STATE_STATION_;
  10701. } else if (psetop->mode == Ndis802_11IBSS)
  10702. type = _HW_STATE_ADHOC_;
  10703. else if (psetop->mode == Ndis802_11Monitor)
  10704. type = _HW_STATE_MONITOR_;
  10705. else
  10706. type = _HW_STATE_NOLINK_;
  10707. #ifdef CONFIG_AP_PORT_SWAP
  10708. rtw_hal_set_hwreg(padapter, HW_VAR_PORT_SWITCH, (u8 *)(&type));
  10709. #endif
  10710. rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type));
  10711. #ifdef CONFIG_AUTO_AP_MODE
  10712. if (psetop->mode == Ndis802_11APMode)
  10713. rtw_auto_ap_start_beacon(padapter);
  10714. #endif
  10715. if (rtw_port_switch_chk(padapter) == _TRUE) {
  10716. rtw_hal_set_hwreg(padapter, HW_VAR_PORT_SWITCH, NULL);
  10717. if (psetop->mode == Ndis802_11APMode)
  10718. adapter_to_pwrctl(padapter)->fw_psmode_iface_id = 0xff; /* ap mode won't dowload rsvd pages */
  10719. else if (psetop->mode == Ndis802_11Infrastructure) {
  10720. #ifdef CONFIG_LPS
  10721. _adapter *port0_iface = dvobj_get_port0_adapter(adapter_to_dvobj(padapter));
  10722. if (port0_iface)
  10723. rtw_lps_ctrl_wk_cmd(port0_iface, LPS_CTRL_CONNECT, 0);
  10724. #endif
  10725. }
  10726. }
  10727. #ifdef CONFIG_BT_COEXIST
  10728. if (psetop->mode == Ndis802_11APMode ||
  10729. psetop->mode == Ndis802_11Monitor) {
  10730. /* Do this after port switch to */
  10731. /* prevent from downloading rsvd page to wrong port */
  10732. rtw_btcoex_MediaStatusNotify(padapter, 1); /* connect */
  10733. }
  10734. #endif /* CONFIG_BT_COEXIST */
  10735. return H2C_SUCCESS;
  10736. }
  10737. u8 createbss_hdl(_adapter *padapter, u8 *pbuf)
  10738. {
  10739. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10740. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10741. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
  10742. WLAN_BSSID_EX *pdev_network = &padapter->registrypriv.dev_network;
  10743. struct createbss_parm *parm = (struct createbss_parm *)pbuf;
  10744. u8 ret = H2C_SUCCESS;
  10745. /* u8 initialgain; */
  10746. #ifdef CONFIG_AP_MODE
  10747. if (pmlmeinfo->state == WIFI_FW_AP_STATE) {
  10748. start_bss_network(padapter, parm);
  10749. goto exit;
  10750. }
  10751. #endif
  10752. /* below is for ad-hoc master */
  10753. if (parm->adhoc) {
  10754. rtw_warn_on(pdev_network->InfrastructureMode != Ndis802_11IBSS);
  10755. rtw_joinbss_reset(padapter);
  10756. pmlmeext->cur_bwmode = CHANNEL_WIDTH_20;
  10757. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  10758. pmlmeinfo->ERP_enable = 0;
  10759. pmlmeinfo->WMM_enable = 0;
  10760. pmlmeinfo->HT_enable = 0;
  10761. pmlmeinfo->HT_caps_enable = 0;
  10762. pmlmeinfo->HT_info_enable = 0;
  10763. pmlmeinfo->agg_enable_bitmap = 0;
  10764. pmlmeinfo->candidate_tid_bitmap = 0;
  10765. /* config the initial gain under linking, need to write the BB registers */
  10766. /* initialgain = 0x1E; */
  10767. /*rtw_hal_set_odm_var(padapter, HAL_ODM_INITIAL_GAIN, &initialgain, _FALSE);*/
  10768. /* disable dynamic functions, such as high power, DIG */
  10769. rtw_phydm_ability_backup(padapter);
  10770. rtw_phydm_func_disable_all(padapter);
  10771. /* cancel link timer */
  10772. _cancel_timer_ex(&pmlmeext->link_timer);
  10773. /* clear CAM */
  10774. flush_all_cam_entry(padapter);
  10775. pdev_network->Length = get_WLAN_BSSID_EX_sz(pdev_network);
  10776. _rtw_memcpy(pnetwork, pdev_network, FIELD_OFFSET(WLAN_BSSID_EX, IELength));
  10777. pnetwork->IELength = pdev_network->IELength;
  10778. if (pnetwork->IELength > MAX_IE_SZ) {
  10779. ret = H2C_PARAMETERS_ERROR;
  10780. goto ibss_post_hdl;
  10781. }
  10782. _rtw_memcpy(pnetwork->IEs, pdev_network->IEs, pnetwork->IELength);
  10783. start_create_ibss(padapter);
  10784. } else {
  10785. rtw_warn_on(1);
  10786. ret = H2C_PARAMETERS_ERROR;
  10787. }
  10788. ibss_post_hdl:
  10789. rtw_create_ibss_post_hdl(padapter, ret);
  10790. exit:
  10791. return ret;
  10792. }
  10793. u8 join_cmd_hdl(_adapter *padapter, u8 *pbuf)
  10794. {
  10795. u8 join_type;
  10796. PNDIS_802_11_VARIABLE_IEs pIE;
  10797. struct registry_priv *pregpriv = &padapter->registrypriv;
  10798. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10799. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10800. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
  10801. #ifdef CONFIG_ANTENNA_DIVERSITY
  10802. struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf;
  10803. #endif /* CONFIG_ANTENNA_DIVERSITY */
  10804. u32 i;
  10805. /* u8 initialgain; */
  10806. /* u32 acparm; */
  10807. u8 u_ch, u_bw, u_offset;
  10808. u8 doiqk = _FALSE;
  10809. /* check already connecting to AP or not */
  10810. if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
  10811. if (pmlmeinfo->state & WIFI_FW_STATION_STATE)
  10812. issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 1, 100);
  10813. pmlmeinfo->state = WIFI_FW_NULL_STATE;
  10814. /* clear CAM */
  10815. flush_all_cam_entry(padapter);
  10816. _cancel_timer_ex(&pmlmeext->link_timer);
  10817. /* set MSR to nolink->infra. mode */
  10818. /* Set_MSR(padapter, _HW_STATE_NOLINK_); */
  10819. Set_MSR(padapter, _HW_STATE_STATION_);
  10820. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, 0);
  10821. }
  10822. #ifdef CONFIG_ANTENNA_DIVERSITY
  10823. rtw_antenna_select_cmd(padapter, pparm->network.PhyInfo.Optimum_antenna, _FALSE);
  10824. #endif
  10825. #ifdef CONFIG_WAPI_SUPPORT
  10826. rtw_wapi_clear_all_cam_entry(padapter);
  10827. #endif
  10828. rtw_joinbss_reset(padapter);
  10829. pmlmeinfo->ERP_enable = 0;
  10830. pmlmeinfo->WMM_enable = 0;
  10831. pmlmeinfo->HT_enable = 0;
  10832. pmlmeinfo->HT_caps_enable = 0;
  10833. pmlmeinfo->HT_info_enable = 0;
  10834. pmlmeinfo->agg_enable_bitmap = 0;
  10835. pmlmeinfo->candidate_tid_bitmap = 0;
  10836. pmlmeinfo->bwmode_updated = _FALSE;
  10837. /* pmlmeinfo->assoc_AP_vendor = HT_IOT_PEER_MAX; */
  10838. pmlmeinfo->VHT_enable = 0;
  10839. _rtw_memcpy(pnetwork, pbuf, FIELD_OFFSET(WLAN_BSSID_EX, IELength));
  10840. pnetwork->IELength = ((WLAN_BSSID_EX *)pbuf)->IELength;
  10841. if (pnetwork->IELength > MAX_IE_SZ) /* Check pbuf->IELength */
  10842. return H2C_PARAMETERS_ERROR;
  10843. if (pnetwork->IELength < 2) {
  10844. report_join_res(padapter, (-4));
  10845. return H2C_SUCCESS;
  10846. }
  10847. _rtw_memcpy(pnetwork->IEs, ((WLAN_BSSID_EX *)pbuf)->IEs, pnetwork->IELength);
  10848. pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
  10849. /* Check AP vendor to move rtw_joinbss_cmd() */
  10850. /* pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pnetwork->IEs, pnetwork->IELength); */
  10851. /* sizeof(NDIS_802_11_FIXED_IEs) */
  10852. for (i = _FIXED_IE_LENGTH_ ; i < pnetwork->IELength - 2 ;) {
  10853. pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
  10854. switch (pIE->ElementID) {
  10855. case _VENDOR_SPECIFIC_IE_: /* Get WMM IE. */
  10856. if (_rtw_memcmp(pIE->data, WMM_OUI, 4))
  10857. WMM_param_handler(padapter, pIE);
  10858. break;
  10859. #ifdef CONFIG_80211N_HT
  10860. case _HT_CAPABILITY_IE_: /* Get HT Cap IE. */
  10861. pmlmeinfo->HT_caps_enable = 1;
  10862. break;
  10863. case _HT_EXTRA_INFO_IE_: /* Get HT Info IE. */
  10864. pmlmeinfo->HT_info_enable = 1;
  10865. break;
  10866. #endif /* CONFIG_80211N_HT */
  10867. #ifdef CONFIG_80211AC_VHT
  10868. case EID_VHTCapability: /* Get VHT Cap IE. */
  10869. pmlmeinfo->VHT_enable = 1;
  10870. break;
  10871. case EID_VHTOperation: /* Get VHT Operation IE. */
  10872. break;
  10873. #endif /* CONFIG_80211AC_VHT */
  10874. default:
  10875. break;
  10876. }
  10877. i += (pIE->Length + 2);
  10878. }
  10879. rtw_bss_get_chbw(pnetwork
  10880. , &pmlmeext->cur_channel, &pmlmeext->cur_bwmode, &pmlmeext->cur_ch_offset);
  10881. rtw_adjust_chbw(padapter, pmlmeext->cur_channel, &pmlmeext->cur_bwmode, &pmlmeext->cur_ch_offset);
  10882. #if 0
  10883. if (padapter->registrypriv.wifi_spec) {
  10884. /* for WiFi test, follow WMM test plan spec */
  10885. acparm = 0x002F431C; /* VO */
  10886. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
  10887. acparm = 0x005E541C; /* VI */
  10888. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
  10889. acparm = 0x0000A525; /* BE */
  10890. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
  10891. acparm = 0x0000A549; /* BK */
  10892. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
  10893. /* for WiFi test, mixed mode with intel STA under bg mode throughput issue */
  10894. if (padapter->mlmepriv.htpriv.ht_option == _FALSE) {
  10895. acparm = 0x00004320;
  10896. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
  10897. }
  10898. } else {
  10899. acparm = 0x002F3217; /* VO */
  10900. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
  10901. acparm = 0x005E4317; /* VI */
  10902. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
  10903. acparm = 0x00105320; /* BE */
  10904. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
  10905. acparm = 0x0000A444; /* BK */
  10906. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
  10907. }
  10908. #endif
  10909. /* check channel, bandwidth, offset and switch */
  10910. if (rtw_chk_start_clnt_join(padapter, &u_ch, &u_bw, &u_offset) == _FAIL) {
  10911. report_join_res(padapter, (-4));
  10912. return H2C_SUCCESS;
  10913. }
  10914. /* disable dynamic functions, such as high power, DIG */
  10915. /*rtw_phydm_func_disable_all(padapter);*/
  10916. /* config the initial gain under linking, need to write the BB registers */
  10917. /* initialgain = 0x1E; */
  10918. /*rtw_hal_set_odm_var(padapter, HAL_ODM_INITIAL_GAIN, &initialgain, _FALSE);*/
  10919. rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pmlmeinfo->network.MacAddress);
  10920. join_type = 0;
  10921. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
  10922. doiqk = _TRUE;
  10923. rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
  10924. set_channel_bwmode(padapter, u_ch, u_offset, u_bw);
  10925. rtw_mi_update_union_chan_inf(padapter, u_ch, u_offset, u_bw);
  10926. doiqk = _FALSE;
  10927. rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
  10928. /* cancel link timer */
  10929. _cancel_timer_ex(&pmlmeext->link_timer);
  10930. start_clnt_join(padapter);
  10931. return H2C_SUCCESS;
  10932. }
  10933. u8 disconnect_hdl(_adapter *padapter, unsigned char *pbuf)
  10934. {
  10935. struct disconnect_parm *param = (struct disconnect_parm *)pbuf;
  10936. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  10937. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10938. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
  10939. u8 val8;
  10940. if (is_client_associated_to_ap(padapter)) {
  10941. #ifdef CONFIG_DFS
  10942. if (padapter->mlmepriv.handle_dfs == _FALSE)
  10943. #endif /* CONFIG_DFS */
  10944. #ifdef CONFIG_PLATFORM_ROCKCHIPS
  10945. /* To avoid connecting to AP fail during resume process, change retry count from 5 to 1 */
  10946. issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 1, 100);
  10947. #else
  10948. issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, param->deauth_timeout_ms / 100, 100);
  10949. #endif /* CONFIG_PLATFORM_ROCKCHIPS */
  10950. }
  10951. #ifdef CONFIG_DFS
  10952. if (padapter->mlmepriv.handle_dfs == _TRUE)
  10953. padapter->mlmepriv.handle_dfs = _FALSE;
  10954. #endif /* CONFIG_DFS */
  10955. if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE)) {
  10956. /* Stop BCN */
  10957. val8 = 0;
  10958. rtw_hal_set_hwreg(padapter, HW_VAR_BCN_FUNC, (u8 *)(&val8));
  10959. }
  10960. rtw_mlmeext_disconnect(padapter);
  10961. rtw_free_uc_swdec_pending_queue(padapter);
  10962. rtw_sta_mstatus_report(padapter);
  10963. return H2C_SUCCESS;
  10964. }
  10965. static const char *const _scan_state_str[] = {
  10966. "SCAN_DISABLE",
  10967. "SCAN_START",
  10968. "SCAN_PS_ANNC_WAIT",
  10969. "SCAN_ENTER",
  10970. "SCAN_PROCESS",
  10971. "SCAN_BACKING_OP",
  10972. "SCAN_BACK_OP",
  10973. "SCAN_LEAVING_OP",
  10974. "SCAN_LEAVE_OP",
  10975. "SCAN_SW_ANTDIV_BL",
  10976. "SCAN_TO_P2P_LISTEN",
  10977. "SCAN_P2P_LISTEN",
  10978. "SCAN_COMPLETE",
  10979. "SCAN_STATE_MAX",
  10980. };
  10981. const char *scan_state_str(u8 state)
  10982. {
  10983. state = (state >= SCAN_STATE_MAX) ? SCAN_STATE_MAX : state;
  10984. return _scan_state_str[state];
  10985. }
  10986. static bool scan_abort_hdl(_adapter *adapter)
  10987. {
  10988. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  10989. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  10990. struct ss_res *ss = &pmlmeext->sitesurvey_res;
  10991. #ifdef CONFIG_P2P
  10992. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  10993. #endif
  10994. bool ret = _FALSE;
  10995. if (pmlmeext->scan_abort == _TRUE) {
  10996. #ifdef CONFIG_P2P
  10997. if (!rtw_p2p_chk_state(&adapter->wdinfo, P2P_STATE_NONE)) {
  10998. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_MAX);
  10999. ss->channel_idx = 3;
  11000. RTW_INFO("%s idx:%d, cnt:%u\n", __FUNCTION__
  11001. , ss->channel_idx
  11002. , pwdinfo->find_phase_state_exchange_cnt
  11003. );
  11004. } else
  11005. #endif
  11006. {
  11007. ss->channel_idx = ss->ch_num;
  11008. RTW_INFO("%s idx:%d\n", __FUNCTION__
  11009. , ss->channel_idx
  11010. );
  11011. }
  11012. pmlmeext->scan_abort = _FALSE;
  11013. ret = _TRUE;
  11014. }
  11015. return ret;
  11016. }
  11017. u8 rtw_scan_sparse(_adapter *adapter, struct rtw_ieee80211_channel *ch, u8 ch_num)
  11018. {
  11019. /* interval larger than this is treated as backgroud scan */
  11020. #ifndef RTW_SCAN_SPARSE_BG_INTERVAL_MS
  11021. #define RTW_SCAN_SPARSE_BG_INTERVAL_MS 12000
  11022. #endif
  11023. #ifndef RTW_SCAN_SPARSE_CH_NUM_MIRACAST
  11024. #define RTW_SCAN_SPARSE_CH_NUM_MIRACAST 1
  11025. #endif
  11026. #ifndef RTW_SCAN_SPARSE_CH_NUM_BG
  11027. #define RTW_SCAN_SPARSE_CH_NUM_BG 4
  11028. #endif
  11029. #ifdef CONFIG_LAYER2_ROAMING
  11030. #ifndef RTW_SCAN_SPARSE_CH_NUM_ROAMING_ACTIVE
  11031. #define RTW_SCAN_SPARSE_CH_NUM_ROAMING_ACTIVE 1
  11032. #endif
  11033. #endif
  11034. #define SCAN_SPARSE_CH_NUM_INVALID 255
  11035. static u8 token = 255;
  11036. u32 interval;
  11037. bool busy_traffic = _FALSE;
  11038. bool miracast_enabled = _FALSE;
  11039. bool bg_scan = _FALSE;
  11040. u8 max_allow_ch = SCAN_SPARSE_CH_NUM_INVALID;
  11041. u8 scan_division_num;
  11042. u8 ret_num = ch_num;
  11043. struct registry_priv *regsty = dvobj_to_regsty(adapter_to_dvobj(adapter));
  11044. struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
  11045. if (regsty->wifi_spec)
  11046. goto exit;
  11047. /* assume ch_num > 6 is normal scan */
  11048. if (ch_num <= 6)
  11049. goto exit;
  11050. if (mlmeext->last_scan_time == 0)
  11051. mlmeext->last_scan_time = rtw_get_current_time();
  11052. interval = rtw_get_passing_time_ms(mlmeext->last_scan_time);
  11053. if (rtw_mi_busy_traffic_check(adapter, _FALSE))
  11054. busy_traffic = _TRUE;
  11055. if (rtw_mi_check_miracast_enabled(adapter))
  11056. miracast_enabled = _TRUE;
  11057. if (interval > RTW_SCAN_SPARSE_BG_INTERVAL_MS)
  11058. bg_scan = _TRUE;
  11059. /* max_allow_ch by conditions*/
  11060. #if RTW_SCAN_SPARSE_MIRACAST
  11061. if (miracast_enabled == _TRUE && busy_traffic == _TRUE)
  11062. max_allow_ch = rtw_min(max_allow_ch, RTW_SCAN_SPARSE_CH_NUM_MIRACAST);
  11063. #endif
  11064. #if RTW_SCAN_SPARSE_BG
  11065. if (bg_scan == _TRUE)
  11066. max_allow_ch = rtw_min(max_allow_ch, RTW_SCAN_SPARSE_CH_NUM_BG);
  11067. #endif
  11068. #if defined(CONFIG_LAYER2_ROAMING) && defined(RTW_SCAN_SPARSE_ROAMING_ACTIVE)
  11069. if (rtw_chk_roam_flags(adapter, RTW_ROAM_ACTIVE)) {
  11070. if (busy_traffic == _TRUE && adapter->mlmepriv.need_to_roam == _TRUE)
  11071. max_allow_ch = rtw_min(max_allow_ch, RTW_SCAN_SPARSE_CH_NUM_ROAMING_ACTIVE);
  11072. }
  11073. #endif
  11074. if (max_allow_ch != SCAN_SPARSE_CH_NUM_INVALID) {
  11075. int i;
  11076. int k = 0;
  11077. scan_division_num = (ch_num / max_allow_ch) + ((ch_num % max_allow_ch) ? 1 : 0);
  11078. token = (token + 1) % scan_division_num;
  11079. if (0)
  11080. RTW_INFO("scan_division_num:%u, token:%u\n", scan_division_num, token);
  11081. for (i = 0; i < ch_num; i++) {
  11082. if (ch[i].hw_value && (i % scan_division_num) == token
  11083. ) {
  11084. if (i != k)
  11085. _rtw_memcpy(&ch[k], &ch[i], sizeof(struct rtw_ieee80211_channel));
  11086. k++;
  11087. }
  11088. }
  11089. _rtw_memset(&ch[k], 0, sizeof(struct rtw_ieee80211_channel));
  11090. ret_num = k;
  11091. mlmeext->last_scan_time = rtw_get_current_time();
  11092. }
  11093. exit:
  11094. return ret_num;
  11095. }
  11096. static int rtw_scan_ch_decision(_adapter *padapter, struct rtw_ieee80211_channel *out,
  11097. u32 out_num, struct rtw_ieee80211_channel *in, u32 in_num)
  11098. {
  11099. int i, j;
  11100. int scan_ch_num = 0;
  11101. int set_idx;
  11102. u8 chan;
  11103. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  11104. /* clear first */
  11105. _rtw_memset(out, 0, sizeof(struct rtw_ieee80211_channel) * out_num);
  11106. /* acquire channels from in */
  11107. j = 0;
  11108. for (i = 0; i < in_num; i++) {
  11109. if (0)
  11110. RTW_INFO(FUNC_ADPT_FMT" "CHAN_FMT"\n", FUNC_ADPT_ARG(padapter), CHAN_ARG(&in[i]));
  11111. if (!in[i].hw_value || (in[i].flags & RTW_IEEE80211_CHAN_DISABLED))
  11112. continue;
  11113. if (rtw_mlme_band_check(padapter, in[i].hw_value) == _FALSE)
  11114. continue;
  11115. set_idx = rtw_chset_search_ch(pmlmeext->channel_set, in[i].hw_value);
  11116. if (set_idx >= 0) {
  11117. if (j >= out_num) {
  11118. RTW_PRINT(FUNC_ADPT_FMT" out_num:%u not enough\n",
  11119. FUNC_ADPT_ARG(padapter), out_num);
  11120. break;
  11121. }
  11122. _rtw_memcpy(&out[j], &in[i], sizeof(struct rtw_ieee80211_channel));
  11123. if (pmlmeext->channel_set[set_idx].ScanType == SCAN_PASSIVE)
  11124. out[j].flags |= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
  11125. j++;
  11126. }
  11127. if (j >= out_num)
  11128. break;
  11129. }
  11130. /* if out is empty, use channel_set as default */
  11131. if (j == 0) {
  11132. for (i = 0; i < pmlmeext->max_chan_nums; i++) {
  11133. chan = pmlmeext->channel_set[i].ChannelNum;
  11134. if (rtw_mlme_band_check(padapter, chan) == _TRUE) {
  11135. if (rtw_mlme_ignore_chan(padapter, chan) == _TRUE)
  11136. continue;
  11137. if (0)
  11138. RTW_INFO(FUNC_ADPT_FMT" ch:%u\n", FUNC_ADPT_ARG(padapter), chan);
  11139. if (j >= out_num) {
  11140. RTW_PRINT(FUNC_ADPT_FMT" out_num:%u not enough\n",
  11141. FUNC_ADPT_ARG(padapter), out_num);
  11142. break;
  11143. }
  11144. out[j].hw_value = chan;
  11145. if (pmlmeext->channel_set[i].ScanType == SCAN_PASSIVE)
  11146. out[j].flags |= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
  11147. j++;
  11148. }
  11149. }
  11150. }
  11151. /* scan_sparse */
  11152. j = rtw_scan_sparse(padapter, out, j);
  11153. return j;
  11154. }
  11155. static void sitesurvey_res_reset(_adapter *adapter, struct sitesurvey_parm *parm)
  11156. {
  11157. struct ss_res *ss = &adapter->mlmeextpriv.sitesurvey_res;
  11158. int i;
  11159. ss->bss_cnt = 0;
  11160. ss->channel_idx = 0;
  11161. #ifdef CONFIG_DFS
  11162. ss->dfs_ch_ssid_scan = 0;
  11163. #endif
  11164. ss->igi_scan = 0;
  11165. ss->igi_before_scan = 0;
  11166. #ifdef CONFIG_SCAN_BACKOP
  11167. ss->scan_cnt = 0;
  11168. #endif
  11169. #if defined(CONFIG_ANTENNA_DIVERSITY) || defined(DBG_SCAN_SW_ANTDIV_BL)
  11170. ss->is_sw_antdiv_bl_scan = 0;
  11171. #endif
  11172. ss->ssid_num = 0;
  11173. for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
  11174. if (parm->ssid[i].SsidLength) {
  11175. _rtw_memcpy(ss->ssid[i].Ssid, parm->ssid[i].Ssid, IW_ESSID_MAX_SIZE);
  11176. ss->ssid[i].SsidLength = parm->ssid[i].SsidLength;
  11177. ss->ssid_num++;
  11178. } else
  11179. ss->ssid[i].SsidLength = 0;
  11180. }
  11181. ss->ch_num = rtw_scan_ch_decision(adapter
  11182. , ss->ch, RTW_CHANNEL_SCAN_AMOUNT
  11183. , parm->ch, parm->ch_num
  11184. );
  11185. #ifdef CONFIG_DFS
  11186. for (i = 0; i < MAX_CHANNEL_NUM; i++)
  11187. adapter->mlmeextpriv.channel_set[i].hidden_bss_cnt = 0;
  11188. #endif
  11189. ss->scan_mode = parm->scan_mode;
  11190. }
  11191. static u8 sitesurvey_pick_ch_behavior(_adapter *padapter, u8 *ch, RT_SCAN_TYPE *type)
  11192. {
  11193. u8 next_state;
  11194. u8 scan_ch = 0;
  11195. RT_SCAN_TYPE scan_type = SCAN_PASSIVE;
  11196. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  11197. struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  11198. struct ss_res *ss = &pmlmeext->sitesurvey_res;
  11199. #ifdef CONFIG_P2P
  11200. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  11201. #endif
  11202. /* handle scan abort request */
  11203. scan_abort_hdl(padapter);
  11204. #ifdef CONFIG_P2P
  11205. if (pwdinfo->rx_invitereq_info.scan_op_ch_only || pwdinfo->p2p_info.scan_op_ch_only) {
  11206. if (pwdinfo->rx_invitereq_info.scan_op_ch_only)
  11207. scan_ch = pwdinfo->rx_invitereq_info.operation_ch[ss->channel_idx];
  11208. else
  11209. scan_ch = pwdinfo->p2p_info.operation_ch[ss->channel_idx];
  11210. scan_type = SCAN_ACTIVE;
  11211. } else if (rtw_p2p_findphase_ex_is_social(pwdinfo)) {
  11212. /*
  11213. * Commented by Albert 2011/06/03
  11214. * The driver is in the find phase, it should go through the social channel.
  11215. */
  11216. int ch_set_idx;
  11217. scan_ch = pwdinfo->social_chan[ss->channel_idx];
  11218. ch_set_idx = rtw_chset_search_ch(pmlmeext->channel_set, scan_ch);
  11219. if (ch_set_idx >= 0)
  11220. scan_type = pmlmeext->channel_set[ch_set_idx].ScanType;
  11221. else
  11222. scan_type = SCAN_ACTIVE;
  11223. } else
  11224. #endif /* CONFIG_P2P */
  11225. {
  11226. struct rtw_ieee80211_channel *ch;
  11227. #ifdef CONFIG_DFS
  11228. if (ss->channel_idx != 0 && ss->dfs_ch_ssid_scan == 0
  11229. && pmlmeext->sitesurvey_res.ssid_num
  11230. && rtw_is_dfs_ch(ss->ch[ss->channel_idx - 1].hw_value)
  11231. ) {
  11232. int ch_set_idx;
  11233. ch_set_idx = rtw_chset_search_ch(pmlmeext->channel_set, ss->ch[ss->channel_idx - 1].hw_value);
  11234. if (ch_set_idx != -1 && pmlmeext->channel_set[ch_set_idx].hidden_bss_cnt) {
  11235. ss->channel_idx--;
  11236. ss->dfs_ch_ssid_scan = 1;
  11237. }
  11238. } else
  11239. ss->dfs_ch_ssid_scan = 0;
  11240. #endif /* CONFIG_DFS */
  11241. if (ss->channel_idx < ss->ch_num) {
  11242. ch = &ss->ch[ss->channel_idx];
  11243. scan_ch = ch->hw_value;
  11244. scan_type = (ch->flags & RTW_IEEE80211_CHAN_PASSIVE_SCAN) ? SCAN_PASSIVE : SCAN_ACTIVE;
  11245. }
  11246. }
  11247. if (scan_ch != 0) {
  11248. next_state = SCAN_PROCESS;
  11249. #ifdef CONFIG_SCAN_BACKOP
  11250. {
  11251. struct mi_state mstate;
  11252. u8 backop_flags = 0;
  11253. rtw_mi_status(padapter, &mstate);
  11254. if ((MSTATE_STA_LD_NUM(&mstate) && mlmeext_chk_scan_backop_flags_sta(pmlmeext, SS_BACKOP_EN))
  11255. || (MSTATE_STA_NUM(&mstate) && mlmeext_chk_scan_backop_flags_sta(pmlmeext, SS_BACKOP_EN_NL)))
  11256. backop_flags |= mlmeext_scan_backop_flags_sta(pmlmeext);
  11257. if ((MSTATE_AP_LD_NUM(&mstate) && mlmeext_chk_scan_backop_flags_ap(pmlmeext, SS_BACKOP_EN))
  11258. || (MSTATE_AP_NUM(&mstate) && mlmeext_chk_scan_backop_flags_ap(pmlmeext, SS_BACKOP_EN_NL)))
  11259. backop_flags |= mlmeext_scan_backop_flags_ap(pmlmeext);
  11260. if (backop_flags) {
  11261. if (ss->scan_cnt < ss->scan_cnt_max)
  11262. ss->scan_cnt++;
  11263. else {
  11264. mlmeext_assign_scan_backop_flags(pmlmeext, backop_flags);
  11265. next_state = SCAN_BACKING_OP;
  11266. }
  11267. }
  11268. }
  11269. #endif /* CONFIG_SCAN_BACKOP */
  11270. } else if (rtw_p2p_findphase_ex_is_needed(pwdinfo)) {
  11271. /* go p2p listen */
  11272. next_state = SCAN_TO_P2P_LISTEN;
  11273. #ifdef CONFIG_ANTENNA_DIVERSITY
  11274. } else if (rtw_hal_antdiv_before_linked(padapter)) {
  11275. /* go sw antdiv before link */
  11276. next_state = SCAN_SW_ANTDIV_BL;
  11277. #endif
  11278. } else {
  11279. next_state = SCAN_COMPLETE;
  11280. #if defined(DBG_SCAN_SW_ANTDIV_BL)
  11281. {
  11282. /* for SCAN_SW_ANTDIV_BL state testing */
  11283. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  11284. int i;
  11285. bool is_linked = _FALSE;
  11286. for (i = 0; i < dvobj->iface_nums; i++) {
  11287. if (rtw_linked_check(dvobj->padapters[i]))
  11288. is_linked = _TRUE;
  11289. }
  11290. if (!is_linked) {
  11291. static bool fake_sw_antdiv_bl_state = 0;
  11292. if (fake_sw_antdiv_bl_state == 0) {
  11293. next_state = SCAN_SW_ANTDIV_BL;
  11294. fake_sw_antdiv_bl_state = 1;
  11295. } else
  11296. fake_sw_antdiv_bl_state = 0;
  11297. }
  11298. }
  11299. #endif /* defined(DBG_SCAN_SW_ANTDIV_BL) */
  11300. }
  11301. #ifdef CONFIG_SCAN_BACKOP
  11302. if (next_state != SCAN_PROCESS)
  11303. ss->scan_cnt = 0;
  11304. #endif
  11305. #ifdef DBG_FIXED_CHAN
  11306. if (pmlmeext->fixed_chan != 0xff && next_state == SCAN_PROCESS)
  11307. scan_ch = pmlmeext->fixed_chan;
  11308. #endif
  11309. if (ch)
  11310. *ch = scan_ch;
  11311. if (type)
  11312. *type = scan_type;
  11313. return next_state;
  11314. }
  11315. void site_survey(_adapter *padapter, u8 survey_channel, RT_SCAN_TYPE ScanType)
  11316. {
  11317. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  11318. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  11319. struct ss_res *ss = &pmlmeext->sitesurvey_res;
  11320. u8 ssid_scan = 0;
  11321. #ifdef CONFIG_P2P
  11322. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  11323. #endif
  11324. if (survey_channel != 0) {
  11325. set_channel_bwmode(padapter, survey_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  11326. #ifdef CONFIG_AUTO_CHNL_SEL_NHM
  11327. if (ACS_ENABLE == GET_ACS_STATE(padapter)) {
  11328. ACS_OP acs_op = ACS_RESET;
  11329. rtw_hal_set_odm_var(padapter, HAL_ODM_AUTO_CHNL_SEL, &acs_op, _TRUE);
  11330. rtw_set_acs_channel(padapter, survey_channel);
  11331. #ifdef DBG_AUTO_CHNL_SEL_NHM
  11332. RTW_INFO("[ACS-"ADPT_FMT"]-set ch:%u\n",
  11333. ADPT_ARG(padapter), rtw_get_acs_channel(padapter));
  11334. #endif
  11335. }
  11336. #endif
  11337. #ifdef CONFIG_DFS
  11338. if (ScanType == SCAN_PASSIVE && ss->dfs_ch_ssid_scan)
  11339. ssid_scan = 1;
  11340. else
  11341. #endif
  11342. if (ScanType == SCAN_ACTIVE) {
  11343. #ifdef CONFIG_P2P
  11344. #ifdef CONFIG_IOCTL_CFG80211
  11345. if (rtw_cfg80211_is_p2p_scan(padapter))
  11346. #else
  11347. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN)
  11348. || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH))
  11349. #endif
  11350. {
  11351. issue_probereq_p2p(padapter, NULL);
  11352. issue_probereq_p2p(padapter, NULL);
  11353. issue_probereq_p2p(padapter, NULL);
  11354. } else
  11355. #endif /* CONFIG_P2P */
  11356. {
  11357. if (pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) {
  11358. /* IOT issue, When wifi_spec is not set, send one probe req without WPS IE. */
  11359. if (padapter->registrypriv.wifi_spec)
  11360. issue_probereq(padapter, NULL, NULL);
  11361. else
  11362. issue_probereq_ex(padapter, NULL, NULL, 0, 0, 0, 0);
  11363. issue_probereq(padapter, NULL, NULL);
  11364. }
  11365. ssid_scan = 1;
  11366. }
  11367. }
  11368. if (ssid_scan) {
  11369. int i;
  11370. for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
  11371. if (pmlmeext->sitesurvey_res.ssid[i].SsidLength) {
  11372. /* IOT issue, When wifi_spec is not set, send one probe req without WPS IE. */
  11373. if (padapter->registrypriv.wifi_spec)
  11374. issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
  11375. else
  11376. issue_probereq_ex(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL, 0, 0, 0, 0);
  11377. issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
  11378. }
  11379. }
  11380. }
  11381. } else {
  11382. /* channel number is 0 or this channel is not valid. */
  11383. rtw_warn_on(1);
  11384. }
  11385. return;
  11386. }
  11387. void survey_done_set_ch_bw(_adapter *padapter)
  11388. {
  11389. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  11390. u8 cur_channel = 0;
  11391. u8 cur_bwmode;
  11392. u8 cur_ch_offset;
  11393. #ifdef CONFIG_MCC_MODE
  11394. if (!rtw_hal_mcc_change_scan_flag(padapter, &cur_channel, &cur_bwmode, &cur_ch_offset)) {
  11395. if (0)
  11396. RTW_INFO(FUNC_ADPT_FMT" back to AP channel - ch:%u, bw:%u, offset:%u\n",
  11397. FUNC_ADPT_ARG(padapter), cur_channel, cur_bwmode, cur_ch_offset);
  11398. goto exit;
  11399. }
  11400. #endif
  11401. if (rtw_mi_get_ch_setting_union(padapter, &cur_channel, &cur_bwmode, &cur_ch_offset) != 0) {
  11402. if (0)
  11403. RTW_INFO(FUNC_ADPT_FMT" back to linked/linking union - ch:%u, bw:%u, offset:%u\n",
  11404. FUNC_ADPT_ARG(padapter), cur_channel, cur_bwmode, cur_ch_offset);
  11405. } else {
  11406. #ifdef CONFIG_P2P
  11407. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  11408. _adapter *iface;
  11409. int i;
  11410. for (i = 0; i < dvobj->iface_nums; i++) {
  11411. iface = dvobj->padapters[i];
  11412. if (!iface)
  11413. continue;
  11414. #ifdef CONFIG_IOCTL_CFG80211
  11415. if (iface->wdinfo.driver_interface == DRIVER_CFG80211 && !adapter_wdev_data(iface)->p2p_enabled)
  11416. continue;
  11417. #endif
  11418. if (rtw_p2p_chk_state(&iface->wdinfo, P2P_STATE_LISTEN)) {
  11419. cur_channel = iface->wdinfo.listen_channel;
  11420. cur_bwmode = CHANNEL_WIDTH_20;
  11421. cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  11422. if (0)
  11423. RTW_INFO(FUNC_ADPT_FMT" back to "ADPT_FMT"'s listen ch - ch:%u, bw:%u, offset:%u\n",
  11424. FUNC_ADPT_ARG(padapter), ADPT_ARG(iface), cur_channel, cur_bwmode, cur_ch_offset);
  11425. break;
  11426. }
  11427. }
  11428. #endif /* CONFIG_P2P */
  11429. if (cur_channel == 0) {
  11430. cur_channel = pmlmeext->cur_channel;
  11431. cur_bwmode = pmlmeext->cur_bwmode;
  11432. cur_ch_offset = pmlmeext->cur_ch_offset;
  11433. if (0)
  11434. RTW_INFO(FUNC_ADPT_FMT" back to ch:%u, bw:%u, offset:%u\n",
  11435. FUNC_ADPT_ARG(padapter), cur_channel, cur_bwmode, cur_ch_offset);
  11436. }
  11437. }
  11438. exit:
  11439. set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
  11440. }
  11441. #if 1
  11442. /**
  11443. * sitesurvey_ps_annc - check and doing ps announcement for all the adapters of given @dvobj
  11444. * @padapter
  11445. * @ps: power saving or not
  11446. *
  11447. * Returns: 0: no ps announcement is doing. 1: ps announcement is doing
  11448. */
  11449. u8 sitesurvey_ps_annc(_adapter *padapter, bool ps)
  11450. {
  11451. u8 ps_anc = 0;
  11452. if (rtw_mi_issue_nulldata(padapter, NULL, ps, 3, 500))
  11453. ps_anc = 1;
  11454. return ps_anc;
  11455. }
  11456. #else
  11457. /**
  11458. * sitesurvey_ps_annc - check and doing ps announcement for all the adapters of given @dvobj
  11459. * @dvobj: the dvobj to check
  11460. * @ps: power saving or not
  11461. *
  11462. * Returns: 0: no ps announcement is doing. 1: ps announcement is doing
  11463. */
  11464. u8 sitesurvey_ps_annc(struct dvobj_priv *dvobj, bool ps)
  11465. {
  11466. _adapter *adapter;
  11467. int i;
  11468. u8 ps_anc = 0;
  11469. for (i = 0; i < dvobj->iface_nums; i++) {
  11470. adapter = dvobj->padapters[i];
  11471. if (!adapter)
  11472. continue;
  11473. if (ps) {
  11474. if (is_client_associated_to_ap(adapter) == _TRUE) {
  11475. /* TODO: TDLS peers */
  11476. issue_nulldata(adapter, NULL, 1, 3, 500);
  11477. ps_anc = 1;
  11478. }
  11479. } else {
  11480. if (is_client_associated_to_ap(adapter) == _TRUE) {
  11481. /* TODO: TDLS peers */
  11482. issue_nulldata(adapter, NULL, 0, 3, 500);
  11483. ps_anc = 1;
  11484. }
  11485. }
  11486. }
  11487. return ps_anc;
  11488. }
  11489. #endif
  11490. void sitesurvey_set_igi(_adapter *adapter)
  11491. {
  11492. struct mlme_ext_priv *mlmeext = &adapter->mlmeextpriv;
  11493. struct ss_res *ss = &mlmeext->sitesurvey_res;
  11494. u8 igi;
  11495. #ifdef CONFIG_P2P
  11496. struct wifidirect_info *pwdinfo = &adapter->wdinfo;
  11497. #endif
  11498. switch (mlmeext_scan_state(mlmeext)) {
  11499. case SCAN_ENTER:
  11500. #ifdef CONFIG_P2P
  11501. #ifdef CONFIG_IOCTL_CFG80211
  11502. if (adapter_wdev_data(adapter)->p2p_enabled == _TRUE && pwdinfo->driver_interface == DRIVER_CFG80211)
  11503. igi = 0x30;
  11504. else
  11505. #endif /* CONFIG_IOCTL_CFG80211 */
  11506. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  11507. igi = 0x28;
  11508. else
  11509. #endif /* CONFIG_P2P */
  11510. igi = 0x1e;
  11511. /* record IGI status */
  11512. ss->igi_scan = igi;
  11513. rtw_hal_get_odm_var(adapter, HAL_ODM_INITIAL_GAIN, &ss->igi_before_scan, NULL);
  11514. /* disable DIG and set IGI for scan */
  11515. rtw_hal_set_odm_var(adapter, HAL_ODM_INITIAL_GAIN, &igi, _FALSE);
  11516. break;
  11517. case SCAN_COMPLETE:
  11518. case SCAN_TO_P2P_LISTEN:
  11519. /* enable DIG and restore IGI */
  11520. igi = 0xff;
  11521. rtw_hal_set_odm_var(adapter, HAL_ODM_INITIAL_GAIN, &igi, _FALSE);
  11522. break;
  11523. #ifdef CONFIG_SCAN_BACKOP
  11524. case SCAN_BACKING_OP:
  11525. /* write IGI for op channel when DIG is not enabled */
  11526. odm_write_dig(GET_ODM(adapter), ss->igi_before_scan);
  11527. break;
  11528. case SCAN_LEAVE_OP:
  11529. /* write IGI for scan when DIG is not enabled */
  11530. odm_write_dig(GET_ODM(adapter), ss->igi_scan);
  11531. break;
  11532. #endif /* CONFIG_SCAN_BACKOP */
  11533. default:
  11534. rtw_warn_on(1);
  11535. break;
  11536. }
  11537. }
  11538. void sitesurvey_set_msr(_adapter *adapter, bool enter)
  11539. {
  11540. u8 network_type;
  11541. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  11542. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  11543. if (enter) {
  11544. #ifdef CONFIG_MI_WITH_MBSSID_CAM
  11545. rtw_hal_get_hwreg(adapter, HW_VAR_MEDIA_STATUS, (u8 *)(&pmlmeinfo->hw_media_state));
  11546. #endif
  11547. /* set MSR to no link state */
  11548. network_type = _HW_STATE_NOLINK_;
  11549. } else {
  11550. #ifdef CONFIG_MI_WITH_MBSSID_CAM
  11551. network_type = pmlmeinfo->hw_media_state;
  11552. #else
  11553. network_type = pmlmeinfo->state & 0x3;
  11554. #endif
  11555. }
  11556. Set_MSR(adapter, network_type);
  11557. }
  11558. u8 sitesurvey_cmd_hdl(_adapter *padapter, u8 *pbuf)
  11559. {
  11560. struct sitesurvey_parm *pparm = (struct sitesurvey_parm *)pbuf;
  11561. struct dvobj_priv *dvobj = padapter->dvobj;
  11562. struct debug_priv *pdbgpriv = &dvobj->drv_dbg;
  11563. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  11564. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  11565. struct ss_res *ss = &pmlmeext->sitesurvey_res;
  11566. u8 val8;
  11567. #ifdef CONFIG_P2P
  11568. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  11569. #endif
  11570. #ifdef DBG_CHECK_FW_PS_STATE
  11571. if (rtw_fw_ps_state(padapter) == _FAIL) {
  11572. RTW_INFO("scan without leave 32k\n");
  11573. pdbgpriv->dbg_scan_pwr_state_cnt++;
  11574. }
  11575. #endif /* DBG_CHECK_FW_PS_STATE */
  11576. /* increase channel idx */
  11577. if (mlmeext_chk_scan_state(pmlmeext, SCAN_PROCESS))
  11578. ss->channel_idx++;
  11579. /* update scan state to next state (assigned by previous cmd hdl) */
  11580. if (mlmeext_scan_state(pmlmeext) != mlmeext_scan_next_state(pmlmeext))
  11581. mlmeext_set_scan_state(pmlmeext, mlmeext_scan_next_state(pmlmeext));
  11582. operation_by_state:
  11583. switch (mlmeext_scan_state(pmlmeext)) {
  11584. case SCAN_DISABLE:
  11585. /*
  11586. * SW parameter initialization
  11587. */
  11588. sitesurvey_res_reset(padapter, pparm);
  11589. mlmeext_set_scan_state(pmlmeext, SCAN_START);
  11590. goto operation_by_state;
  11591. case SCAN_START:
  11592. /*
  11593. * prepare to leave operating channel
  11594. */
  11595. #ifdef CONFIG_MCC_MODE
  11596. rtw_hal_set_mcc_setting_scan_start(padapter);
  11597. #endif /* CONFIG_MCC_MODE */
  11598. /* apply rx ampdu setting */
  11599. if (ss->rx_ampdu_accept != RX_AMPDU_ACCEPT_INVALID
  11600. || ss->rx_ampdu_size != RX_AMPDU_SIZE_INVALID)
  11601. rtw_rx_ampdu_apply(padapter);
  11602. /* clear HW TX queue before scan */
  11603. rtw_hal_set_hwreg(padapter, HW_VAR_CHECK_TXBUF, 0);
  11604. /* power save state announcement */
  11605. if (sitesurvey_ps_annc(padapter, 1)) {
  11606. mlmeext_set_scan_state(pmlmeext, SCAN_PS_ANNC_WAIT);
  11607. mlmeext_set_scan_next_state(pmlmeext, SCAN_ENTER);
  11608. set_survey_timer(pmlmeext, 50); /* delay 50ms to protect nulldata(1) */
  11609. } else {
  11610. mlmeext_set_scan_state(pmlmeext, SCAN_ENTER);
  11611. goto operation_by_state;
  11612. }
  11613. break;
  11614. case SCAN_ENTER:
  11615. /*
  11616. * HW register and DM setting for enter scan
  11617. */
  11618. rtw_phydm_ability_backup(padapter);
  11619. sitesurvey_set_igi(padapter);
  11620. /* config dynamic functions for off channel */
  11621. rtw_phydm_func_for_offchannel(padapter);
  11622. /* set MSR to no link state */
  11623. sitesurvey_set_msr(padapter, _TRUE);
  11624. val8 = 1; /* under site survey */
  11625. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  11626. mlmeext_set_scan_state(pmlmeext, SCAN_PROCESS);
  11627. goto operation_by_state;
  11628. case SCAN_PROCESS: {
  11629. u8 scan_ch;
  11630. RT_SCAN_TYPE scan_type;
  11631. u8 next_state;
  11632. u32 scan_ms;
  11633. #ifdef CONFIG_AUTO_CHNL_SEL_NHM
  11634. if ((ACS_ENABLE == GET_ACS_STATE(padapter)) && (0 != rtw_get_acs_channel(padapter))) {
  11635. ACS_OP acs_op = ACS_SELECT;
  11636. rtw_hal_set_odm_var(padapter, HAL_ODM_AUTO_CHNL_SEL, &acs_op, _TRUE);
  11637. }
  11638. #endif
  11639. next_state = sitesurvey_pick_ch_behavior(padapter, &scan_ch, &scan_type);
  11640. if (next_state != SCAN_PROCESS) {
  11641. #ifdef CONFIG_AUTO_CHNL_SEL_NHM
  11642. if (ACS_ENABLE == GET_ACS_STATE(padapter)) {
  11643. rtw_set_acs_channel(padapter, 0);
  11644. #ifdef DBG_AUTO_CHNL_SEL_NHM
  11645. RTW_INFO("[ACS-"ADPT_FMT"]-set ch:%u\n", ADPT_ARG(padapter), rtw_get_acs_channel(padapter));
  11646. #endif
  11647. }
  11648. #endif
  11649. mlmeext_set_scan_state(pmlmeext, next_state);
  11650. goto operation_by_state;
  11651. }
  11652. /* still SCAN_PROCESS state */
  11653. if (0)
  11654. #ifdef CONFIG_P2P
  11655. RTW_INFO(FUNC_ADPT_FMT" %s ch:%u (cnt:%u,idx:%d) at %dms, %c%c%c\n"
  11656. , FUNC_ADPT_ARG(padapter)
  11657. , mlmeext_scan_state_str(pmlmeext)
  11658. , scan_ch
  11659. , pwdinfo->find_phase_state_exchange_cnt, ss->channel_idx
  11660. , rtw_get_passing_time_ms(padapter->mlmepriv.scan_start_time)
  11661. , scan_type ? 'A' : 'P', ss->scan_mode ? 'A' : 'P'
  11662. , ss->ssid[0].SsidLength ? 'S' : ' '
  11663. );
  11664. #else
  11665. RTW_INFO(FUNC_ADPT_FMT" %s ch:%u (idx:%d) at %dms, %c%c%c\n"
  11666. , FUNC_ADPT_ARG(padapter)
  11667. , mlmeext_scan_state_str(pmlmeext)
  11668. , scan_ch
  11669. , ss->channel_idx
  11670. , rtw_get_passing_time_ms(padapter->mlmepriv.scan_start_time)
  11671. , scan_type ? 'A' : 'P', ss->scan_mode ? 'A' : 'P'
  11672. , ss->ssid[0].SsidLength ? 'S' : ' '
  11673. );
  11674. #endif /* CONFIG_P2P */
  11675. #ifdef DBG_FIXED_CHAN
  11676. if (pmlmeext->fixed_chan != 0xff)
  11677. RTW_INFO(FUNC_ADPT_FMT" fixed_chan:%u\n", pmlmeext->fixed_chan);
  11678. #endif
  11679. site_survey(padapter, scan_ch, scan_type);
  11680. #if defined(CONFIG_ATMEL_RC_PATCH)
  11681. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  11682. scan_ms = 20;
  11683. else
  11684. scan_ms = 40;
  11685. #else
  11686. scan_ms = ss->scan_ch_ms;
  11687. #endif
  11688. #if defined(CONFIG_ANTENNA_DIVERSITY) || defined(DBG_SCAN_SW_ANTDIV_BL)
  11689. if (ss->is_sw_antdiv_bl_scan)
  11690. scan_ms = scan_ms / 2;
  11691. #endif
  11692. #if defined(CONFIG_SIGNAL_DISPLAY_DBM) && defined(CONFIG_BACKGROUND_NOISE_MONITOR)
  11693. {
  11694. struct noise_info info;
  11695. info.bPauseDIG = _FALSE;
  11696. info.IGIValue = 0;
  11697. info.max_time = scan_ms / 2;
  11698. info.chan = scan_ch;
  11699. rtw_hal_set_odm_var(padapter, HAL_ODM_NOISE_MONITOR, &info, _FALSE);
  11700. }
  11701. #endif
  11702. set_survey_timer(pmlmeext, scan_ms);
  11703. break;
  11704. }
  11705. #ifdef CONFIG_SCAN_BACKOP
  11706. case SCAN_BACKING_OP: {
  11707. u8 back_ch, back_bw, back_ch_offset;
  11708. u8 need_ch_setting_union = _TRUE;
  11709. #ifdef CONFIG_MCC_MODE
  11710. need_ch_setting_union = rtw_hal_mcc_change_scan_flag(padapter,
  11711. &back_ch, &back_bw, &back_ch_offset);
  11712. #endif /* CONFIG_MCC_MODE */
  11713. if (need_ch_setting_union) {
  11714. if (rtw_mi_get_ch_setting_union(padapter, &back_ch, &back_bw, &back_ch_offset) == 0)
  11715. rtw_warn_on(1);
  11716. }
  11717. if (0)
  11718. RTW_INFO(FUNC_ADPT_FMT" %s ch:%u, bw:%u, offset:%u at %dms\n"
  11719. , FUNC_ADPT_ARG(padapter)
  11720. , mlmeext_scan_state_str(pmlmeext)
  11721. , back_ch, back_bw, back_ch_offset
  11722. , rtw_get_passing_time_ms(padapter->mlmepriv.scan_start_time)
  11723. );
  11724. set_channel_bwmode(padapter, back_ch, back_ch_offset, back_bw);
  11725. sitesurvey_set_msr(padapter, _FALSE);
  11726. val8 = 0; /* survey done */
  11727. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  11728. if (mlmeext_chk_scan_backop_flags(pmlmeext, SS_BACKOP_PS_ANNC)) {
  11729. sitesurvey_set_igi(padapter);
  11730. sitesurvey_ps_annc(padapter, 0);
  11731. }
  11732. mlmeext_set_scan_state(pmlmeext, SCAN_BACK_OP);
  11733. ss->backop_time = rtw_get_current_time();
  11734. if (mlmeext_chk_scan_backop_flags(pmlmeext, SS_BACKOP_TX_RESUME))
  11735. rtw_mi_os_xmit_schedule(padapter);
  11736. goto operation_by_state;
  11737. }
  11738. case SCAN_BACK_OP:
  11739. if (rtw_get_passing_time_ms(ss->backop_time) >= ss->backop_ms
  11740. || pmlmeext->scan_abort
  11741. ) {
  11742. mlmeext_set_scan_state(pmlmeext, SCAN_LEAVING_OP);
  11743. goto operation_by_state;
  11744. }
  11745. set_survey_timer(pmlmeext, 50);
  11746. break;
  11747. case SCAN_LEAVING_OP:
  11748. /*
  11749. * prepare to leave operating channel
  11750. */
  11751. /* clear HW TX queue before scan */
  11752. rtw_hal_set_hwreg(padapter, HW_VAR_CHECK_TXBUF, 0);
  11753. if (mlmeext_chk_scan_backop_flags(pmlmeext, SS_BACKOP_PS_ANNC)
  11754. && sitesurvey_ps_annc(padapter, 1)
  11755. ) {
  11756. mlmeext_set_scan_state(pmlmeext, SCAN_PS_ANNC_WAIT);
  11757. mlmeext_set_scan_next_state(pmlmeext, SCAN_LEAVE_OP);
  11758. set_survey_timer(pmlmeext, 50); /* delay 50ms to protect nulldata(1) */
  11759. } else {
  11760. mlmeext_set_scan_state(pmlmeext, SCAN_LEAVE_OP);
  11761. goto operation_by_state;
  11762. }
  11763. break;
  11764. case SCAN_LEAVE_OP:
  11765. /*
  11766. * HW register and DM setting for enter scan
  11767. */
  11768. if (mlmeext_chk_scan_backop_flags(pmlmeext, SS_BACKOP_PS_ANNC))
  11769. sitesurvey_set_igi(padapter);
  11770. sitesurvey_set_msr(padapter, _TRUE);
  11771. val8 = 1; /* under site survey */
  11772. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  11773. mlmeext_set_scan_state(pmlmeext, SCAN_PROCESS);
  11774. goto operation_by_state;
  11775. #endif /* CONFIG_SCAN_BACKOP */
  11776. #if defined(CONFIG_ANTENNA_DIVERSITY) || defined(DBG_SCAN_SW_ANTDIV_BL)
  11777. case SCAN_SW_ANTDIV_BL:
  11778. /*
  11779. * 20100721
  11780. * For SW antenna diversity before link, it needs to switch to another antenna and scan again.
  11781. * It compares the scan result and select better one to do connection.
  11782. */
  11783. ss->bss_cnt = 0;
  11784. ss->channel_idx = 0;
  11785. ss->is_sw_antdiv_bl_scan = 1;
  11786. mlmeext_set_scan_next_state(pmlmeext, SCAN_PROCESS);
  11787. set_survey_timer(pmlmeext, ss->scan_ch_ms);
  11788. break;
  11789. #endif
  11790. #ifdef CONFIG_P2P
  11791. case SCAN_TO_P2P_LISTEN:
  11792. /*
  11793. * Set the P2P State to the listen state of find phase
  11794. * and set the current channel to the listen channel
  11795. */
  11796. set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  11797. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_LISTEN);
  11798. /* turn on phy-dynamic functions */
  11799. rtw_phydm_ability_restore(padapter);
  11800. sitesurvey_set_igi(padapter);
  11801. mlmeext_set_scan_state(pmlmeext, SCAN_P2P_LISTEN);
  11802. _set_timer(&pwdinfo->find_phase_timer, (u32)((u32)pwdinfo->listen_dwell * 100));
  11803. break;
  11804. case SCAN_P2P_LISTEN:
  11805. mlmeext_set_scan_state(pmlmeext, SCAN_PROCESS);
  11806. ss->channel_idx = 0;
  11807. goto operation_by_state;
  11808. #endif /* CONFIG_P2P */
  11809. case SCAN_COMPLETE:
  11810. #ifdef CONFIG_P2P
  11811. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN)
  11812. || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH)
  11813. ) {
  11814. #ifdef CONFIG_CONCURRENT_MODE
  11815. if (pwdinfo->driver_interface == DRIVER_WEXT) {
  11816. if (rtw_mi_check_status(padapter, MI_LINKED))
  11817. _set_timer(&pwdinfo->ap_p2p_switch_timer, 500);
  11818. }
  11819. #endif
  11820. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  11821. }
  11822. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
  11823. #endif /* CONFIG_P2P */
  11824. /* switch channel */
  11825. survey_done_set_ch_bw(padapter);
  11826. sitesurvey_set_msr(padapter, _FALSE);
  11827. val8 = 0; /* survey done */
  11828. rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
  11829. /* turn on phy-dynamic functions */
  11830. rtw_phydm_ability_restore(padapter);
  11831. sitesurvey_set_igi(padapter);
  11832. #ifdef CONFIG_MCC_MODE
  11833. /* start MCC fail, then tx null data */
  11834. if (!rtw_hal_set_mcc_setting_scan_complete(padapter))
  11835. #endif /* CONFIG_MCC_MODE */
  11836. sitesurvey_ps_annc(padapter, 0);
  11837. /* apply rx ampdu setting */
  11838. rtw_rx_ampdu_apply(padapter);
  11839. mlmeext_set_scan_state(pmlmeext, SCAN_DISABLE);
  11840. report_surveydone_event(padapter);
  11841. issue_action_BSSCoexistPacket(padapter);
  11842. issue_action_BSSCoexistPacket(padapter);
  11843. issue_action_BSSCoexistPacket(padapter);
  11844. }
  11845. return H2C_SUCCESS;
  11846. }
  11847. u8 setauth_hdl(_adapter *padapter, unsigned char *pbuf)
  11848. {
  11849. struct setauth_parm *pparm = (struct setauth_parm *)pbuf;
  11850. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  11851. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  11852. if (pparm->mode < 4)
  11853. pmlmeinfo->auth_algo = pparm->mode;
  11854. return H2C_SUCCESS;
  11855. }
  11856. /*
  11857. SEC CAM Entry format (32 bytes)
  11858. DW0 - MAC_ADDR[15:0] | Valid[15] | MFB[14:8] | RSVD[7] | GK[6] | MIC_KEY[5] | SEC_TYPE[4:2] | KID[1:0]
  11859. DW0 - MAC_ADDR[15:0] | Valid[15] |RSVD[14:9] | RPT_MODE[8] | SPP_MODE[7] | GK[6] | MIC_KEY[5] | SEC_TYPE[4:2] | KID[1:0] (92E/8812A/8814A)
  11860. DW1 - MAC_ADDR[47:16]
  11861. DW2 - KEY[31:0]
  11862. DW3 - KEY[63:32]
  11863. DW4 - KEY[95:64]
  11864. DW5 - KEY[127:96]
  11865. DW6 - RSVD
  11866. DW7 - RSVD
  11867. */
  11868. /*Set WEP key or Group Key*/
  11869. u8 setkey_hdl(_adapter *padapter, u8 *pbuf)
  11870. {
  11871. u16 ctrl = 0;
  11872. s16 cam_id = 0;
  11873. struct setkey_parm *pparm = (struct setkey_parm *)pbuf;
  11874. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  11875. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  11876. unsigned char null_addr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  11877. u8 *addr;
  11878. bool used = _FALSE;
  11879. /* main tx key for wep. */
  11880. if (pparm->set_tx)
  11881. pmlmeinfo->key_index = pparm->keyid;
  11882. #ifdef CONFIG_CONCURRENT_MODE
  11883. if (((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
  11884. cam_id = rtw_iface_bcmc_id_get(padapter);
  11885. else
  11886. #endif
  11887. cam_id = rtw_camid_alloc(padapter, NULL, pparm->keyid, &used);
  11888. if (cam_id < 0)
  11889. goto enable_mc;
  11890. #ifndef CONFIG_CONCURRENT_MODE
  11891. if (cam_id >= 0 && cam_id <= 3)
  11892. addr = null_addr;
  11893. else
  11894. #endif
  11895. {
  11896. if (((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
  11897. /* for AP mode ,we will force sec cam entry_id so hw dont search cam when tx*/
  11898. addr = adapter_mac_addr(padapter);
  11899. else
  11900. /* not default key, searched by A2 */
  11901. addr = get_bssid(&padapter->mlmepriv);
  11902. }
  11903. /* cam entry searched is pairwise key */
  11904. if (used == _TRUE && rtw_camid_is_gk(padapter, cam_id) == _FALSE) {
  11905. s16 camid_clr;
  11906. RTW_PRINT(FUNC_ADPT_FMT" group key with "MAC_FMT" id:%u the same key id as pairwise key\n"
  11907. , FUNC_ADPT_ARG(padapter), MAC_ARG(addr), pparm->keyid);
  11908. /* HW has problem to distinguish this group key with existing pairwise key, stop HW enc and dec for BMC */
  11909. rtw_camctl_set_flags(padapter, SEC_STATUS_STA_PK_GK_CONFLICT_DIS_BMC_SEARCH);
  11910. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, NULL);
  11911. /* clear group key */
  11912. while ((camid_clr = rtw_camid_search(padapter, addr, -1, 1)) >= 0) {
  11913. RTW_PRINT("clear group key for addr:"MAC_FMT", camid:%d\n", MAC_ARG(addr), camid_clr);
  11914. clear_cam_entry(padapter, camid_clr);
  11915. rtw_camid_free(padapter, camid_clr);
  11916. }
  11917. goto enable_mc;
  11918. }
  11919. ctrl = BIT(15) | BIT(6) | ((pparm->algorithm) << 2) | pparm->keyid;
  11920. RTW_PRINT("set group key camid:%d, addr:"MAC_FMT", kid:%d, type:%s\n"
  11921. , cam_id, MAC_ARG(addr), pparm->keyid, security_type_str(pparm->algorithm));
  11922. write_cam(padapter, cam_id, ctrl, addr, pparm->key);
  11923. /* if ((cam_id > 3) && (((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE)))*/
  11924. #ifdef CONFIG_CONCURRENT_MODE
  11925. if (((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE)) {
  11926. if (is_wep_enc(pparm->algorithm)) {
  11927. padapter->securitypriv.dot11Def_camid[pparm->keyid] = cam_id;
  11928. padapter->securitypriv.dot118021x_bmc_cam_id =
  11929. padapter->securitypriv.dot11Def_camid[padapter->securitypriv.dot11PrivacyKeyIndex];
  11930. RTW_PRINT("wep group key - force camid:%d\n", padapter->securitypriv.dot118021x_bmc_cam_id);
  11931. } else {
  11932. /*u8 org_cam_id = padapter->securitypriv.dot118021x_bmc_cam_id;*/
  11933. /*force GK's cam id*/
  11934. padapter->securitypriv.dot118021x_bmc_cam_id = cam_id;
  11935. /* for GTK rekey
  11936. if ((org_cam_id != INVALID_SEC_MAC_CAM_ID) &&
  11937. (org_cam_id != cam_id)) {
  11938. RTW_PRINT("clear group key for addr:"MAC_FMT", org_camid:%d new_camid:%d\n", MAC_ARG(addr), org_cam_id, cam_id);
  11939. clear_cam_entry(padapter, org_cam_id);
  11940. rtw_camid_free(padapter, org_cam_id);
  11941. }*/
  11942. }
  11943. }
  11944. #endif
  11945. #ifndef CONFIG_CONCURRENT_MODE
  11946. if (cam_id >= 0 && cam_id <= 3)
  11947. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_DK_CFG, (u8 *)_TRUE);
  11948. #endif
  11949. /* 8814au should set both broadcast and unicast CAM entry for WEP key in STA mode */
  11950. if (is_wep_enc(pparm->algorithm) && check_mlmeinfo_state(pmlmeext, WIFI_FW_STATION_STATE) &&
  11951. _rtw_camctl_chk_cap(padapter, SEC_CAP_CHK_BMC)) {
  11952. struct set_stakey_parm sta_pparm;
  11953. sta_pparm.algorithm = pparm->algorithm;
  11954. sta_pparm.keyid = pparm->keyid;
  11955. _rtw_memcpy(sta_pparm.key, pparm->key, 16);
  11956. _rtw_memcpy(sta_pparm.addr, get_bssid(&padapter->mlmepriv), ETH_ALEN);
  11957. set_stakey_hdl(padapter, (u8 *)&sta_pparm);
  11958. }
  11959. enable_mc:
  11960. /* allow multicast packets to driver */
  11961. rtw_hal_set_hwreg(padapter, HW_VAR_ON_RCR_AM, null_addr);
  11962. return H2C_SUCCESS;
  11963. }
  11964. void rtw_ap_wep_pk_setting(_adapter *adapter, struct sta_info *psta)
  11965. {
  11966. struct security_priv *psecuritypriv = &(adapter->securitypriv);
  11967. struct set_stakey_parm sta_pparm;
  11968. sint keyid;
  11969. if (!is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm))
  11970. return;
  11971. for (keyid = 0; keyid < 4; keyid++) {
  11972. if ((psecuritypriv->key_mask & BIT(keyid)) && (keyid == psecuritypriv->dot11PrivacyKeyIndex)) {
  11973. sta_pparm.algorithm = psecuritypriv->dot11PrivacyAlgrthm;
  11974. sta_pparm.keyid = keyid;
  11975. _rtw_memcpy(sta_pparm.key, &(psecuritypriv->dot11DefKey[keyid].skey[0]), 16);
  11976. _rtw_memcpy(sta_pparm.addr, psta->hwaddr, ETH_ALEN);
  11977. RTW_PRINT(FUNC_ADPT_FMT"set WEP - PK with "MAC_FMT" keyid:%u\n"
  11978. , FUNC_ADPT_ARG(adapter), MAC_ARG(psta->hwaddr), keyid);
  11979. set_stakey_hdl(adapter, (u8 *)&sta_pparm);
  11980. }
  11981. }
  11982. }
  11983. u8 set_stakey_hdl(_adapter *padapter, u8 *pbuf)
  11984. {
  11985. u16 ctrl = 0;
  11986. s16 cam_id = 0;
  11987. bool used;
  11988. u8 kid = 0;
  11989. u8 ret = H2C_SUCCESS;
  11990. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  11991. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  11992. struct set_stakey_parm *pparm = (struct set_stakey_parm *)pbuf;
  11993. struct sta_priv *pstapriv = &padapter->stapriv;
  11994. struct sta_info *psta;
  11995. if (pparm->algorithm == _NO_PRIVACY_)
  11996. goto write_to_cam;
  11997. psta = rtw_get_stainfo(pstapriv, pparm->addr);
  11998. if (!psta) {
  11999. RTW_PRINT("%s sta:"MAC_FMT" not found\n", __func__, MAC_ARG(pparm->addr));
  12000. ret = H2C_REJECTED;
  12001. goto exit;
  12002. }
  12003. pmlmeinfo->enc_algo = pparm->algorithm;
  12004. if (is_wep_enc(pparm->algorithm))
  12005. kid = pparm->keyid;
  12006. cam_id = rtw_camid_alloc(padapter, psta, kid, &used);
  12007. if (cam_id < 0)
  12008. goto exit;
  12009. /* cam entry searched is group key */
  12010. if (used == _TRUE && rtw_camid_is_gk(padapter, cam_id) == _TRUE) {
  12011. s16 camid_clr;
  12012. RTW_PRINT(FUNC_ADPT_FMT" pairwise key with "MAC_FMT" id:%u the same key id as group key\n"
  12013. , FUNC_ADPT_ARG(padapter), MAC_ARG(pparm->addr), pparm->keyid);
  12014. /* HW has problem to distinguish this pairwise key with existing group key, stop HW enc and dec for BMC */
  12015. rtw_camctl_set_flags(padapter, SEC_STATUS_STA_PK_GK_CONFLICT_DIS_BMC_SEARCH);
  12016. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, NULL);
  12017. /* clear group key */
  12018. while ((camid_clr = rtw_camid_search(padapter, pparm->addr, -1, 1)) >= 0) {
  12019. RTW_PRINT("clear group key for addr:"MAC_FMT", camid:%d\n", MAC_ARG(pparm->addr), camid_clr);
  12020. clear_cam_entry(padapter, camid_clr);
  12021. rtw_camid_free(padapter, camid_clr);
  12022. }
  12023. }
  12024. write_to_cam:
  12025. if (pparm->algorithm == _NO_PRIVACY_) {
  12026. while ((cam_id = rtw_camid_search(padapter, pparm->addr, -1, -1)) >= 0) {
  12027. RTW_PRINT("clear key for addr:"MAC_FMT", camid:%d\n", MAC_ARG(pparm->addr), cam_id);
  12028. clear_cam_entry(padapter, cam_id);
  12029. rtw_camid_free(padapter, cam_id);
  12030. }
  12031. } else {
  12032. RTW_PRINT("set pairwise key camid:%d, addr:"MAC_FMT", kid:%d, type:%s\n",
  12033. cam_id, MAC_ARG(pparm->addr), pparm->keyid, security_type_str(pparm->algorithm));
  12034. ctrl = BIT(15) | ((pparm->algorithm) << 2) | pparm->keyid;
  12035. write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
  12036. }
  12037. ret = H2C_SUCCESS_RSP;
  12038. exit:
  12039. return ret;
  12040. }
  12041. u8 add_ba_hdl(_adapter *padapter, unsigned char *pbuf)
  12042. {
  12043. struct addBaReq_parm *pparm = (struct addBaReq_parm *)pbuf;
  12044. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  12045. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  12046. struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, pparm->addr);
  12047. if (!psta)
  12048. return H2C_SUCCESS;
  12049. #ifdef CONFIG_80211N_HT
  12050. if (((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && (pmlmeinfo->HT_enable)) ||
  12051. ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE)) {
  12052. /* pmlmeinfo->ADDBA_retry_count = 0; */
  12053. /* pmlmeinfo->candidate_tid_bitmap |= (0x1 << pparm->tid); */
  12054. /* psta->htpriv.candidate_tid_bitmap |= BIT(pparm->tid); */
  12055. issue_addba_req(padapter, pparm->addr, (u8)pparm->tid);
  12056. _set_timer(&psta->addba_retry_timer, ADDBA_TO);
  12057. }
  12058. #ifdef CONFIG_TDLS
  12059. else if ((psta->tdls_sta_state & TDLS_LINKED_STATE) &&
  12060. (psta->htpriv.ht_option == _TRUE) &&
  12061. (psta->htpriv.ampdu_enable == _TRUE)) {
  12062. issue_addba_req(padapter, pparm->addr, (u8)pparm->tid);
  12063. _set_timer(&psta->addba_retry_timer, ADDBA_TO);
  12064. }
  12065. #endif /* CONFIG */
  12066. else
  12067. psta->htpriv.candidate_tid_bitmap &= ~BIT(pparm->tid);
  12068. #endif /* CONFIG_80211N_HT */
  12069. return H2C_SUCCESS;
  12070. }
  12071. u8 add_ba_rsp_hdl(_adapter *padapter, unsigned char *pbuf)
  12072. {
  12073. struct addBaRsp_parm *pparm = (struct addBaRsp_parm *)pbuf;
  12074. u8 ret = _TRUE, i = 0, try_cnt = 3, wait_ms = 50;
  12075. struct recv_reorder_ctrl *preorder_ctrl;
  12076. struct sta_priv *pstapriv = &padapter->stapriv;
  12077. struct sta_info *psta;
  12078. psta = rtw_get_stainfo(pstapriv, pparm->addr);
  12079. if (!psta)
  12080. goto exit;
  12081. preorder_ctrl = &psta->recvreorder_ctrl[pparm->tid];
  12082. ret = issue_addba_rsp_wait_ack(padapter, pparm->addr, pparm->tid, pparm->status, pparm->size, 3, 50);
  12083. #ifdef CONFIG_UPDATE_INDICATE_SEQ_WHILE_PROCESS_ADDBA_REQ
  12084. /* status = 0 means accept this addba req, so update indicate seq = start_seq under this compile flag */
  12085. if (pparm->status == 0) {
  12086. preorder_ctrl->indicate_seq = pparm->start_seq;
  12087. #ifdef DBG_RX_SEQ
  12088. RTW_INFO("DBG_RX_SEQ %s:%d IndicateSeq: %d, start_seq: %d\n", __func__, __LINE__,
  12089. preorder_ctrl->indicate_seq, pparm->start_seq);
  12090. #endif
  12091. }
  12092. #else
  12093. preorder_ctrl->indicate_seq = 0xffff;
  12094. #endif
  12095. /*
  12096. * status = 0 means accept this addba req
  12097. * status = 37 means reject this addba req
  12098. */
  12099. if (pparm->status == 0) {
  12100. preorder_ctrl->enable = _TRUE;
  12101. preorder_ctrl->ampdu_size = pparm->size;
  12102. } else if (pparm->status == 37)
  12103. preorder_ctrl->enable = _FALSE;
  12104. exit:
  12105. return H2C_SUCCESS;
  12106. }
  12107. u8 chk_bmc_sleepq_cmd(_adapter *padapter)
  12108. {
  12109. struct cmd_obj *ph2c;
  12110. struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
  12111. u8 res = _SUCCESS;
  12112. ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  12113. if (ph2c == NULL) {
  12114. res = _FAIL;
  12115. goto exit;
  12116. }
  12117. init_h2fwcmd_w_parm_no_parm_rsp(ph2c, GEN_CMD_CODE(_ChkBMCSleepq));
  12118. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  12119. exit:
  12120. return res;
  12121. }
  12122. u8 set_tx_beacon_cmd(_adapter *padapter)
  12123. {
  12124. struct cmd_obj *ph2c;
  12125. struct Tx_Beacon_param *ptxBeacon_parm;
  12126. struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
  12127. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  12128. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  12129. u8 res = _SUCCESS;
  12130. int len_diff = 0;
  12131. ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  12132. if (ph2c == NULL) {
  12133. res = _FAIL;
  12134. goto exit;
  12135. }
  12136. ptxBeacon_parm = (struct Tx_Beacon_param *)rtw_zmalloc(sizeof(struct Tx_Beacon_param));
  12137. if (ptxBeacon_parm == NULL) {
  12138. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  12139. res = _FAIL;
  12140. goto exit;
  12141. }
  12142. _rtw_memcpy(&(ptxBeacon_parm->network), &(pmlmeinfo->network), sizeof(WLAN_BSSID_EX));
  12143. len_diff = update_hidden_ssid(
  12144. ptxBeacon_parm->network.IEs + _BEACON_IE_OFFSET_
  12145. , ptxBeacon_parm->network.IELength - _BEACON_IE_OFFSET_
  12146. , pmlmeinfo->hidden_ssid_mode
  12147. );
  12148. ptxBeacon_parm->network.IELength += len_diff;
  12149. init_h2fwcmd_w_parm_no_rsp(ph2c, ptxBeacon_parm, GEN_CMD_CODE(_TX_Beacon));
  12150. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  12151. exit:
  12152. return res;
  12153. }
  12154. u8 mlme_evt_hdl(_adapter *padapter, unsigned char *pbuf)
  12155. {
  12156. u8 evt_code, evt_seq;
  12157. u16 evt_sz;
  12158. uint *peventbuf;
  12159. void (*event_callback)(_adapter *dev, u8 *pbuf);
  12160. struct evt_priv *pevt_priv = &(padapter->evtpriv);
  12161. if (pbuf == NULL)
  12162. goto _abort_event_;
  12163. peventbuf = (uint *)pbuf;
  12164. evt_sz = (u16)(*peventbuf & 0xffff);
  12165. evt_seq = (u8)((*peventbuf >> 24) & 0x7f);
  12166. evt_code = (u8)((*peventbuf >> 16) & 0xff);
  12167. #ifdef CHECK_EVENT_SEQ
  12168. /* checking event sequence... */
  12169. if (evt_seq != (ATOMIC_READ(&pevt_priv->event_seq) & 0x7f)) {
  12170. pevt_priv->event_seq = (evt_seq + 1) & 0x7f;
  12171. goto _abort_event_;
  12172. }
  12173. #endif
  12174. /* checking if event code is valid */
  12175. if (evt_code >= MAX_C2HEVT) {
  12176. goto _abort_event_;
  12177. }
  12178. /* checking if event size match the event parm size */
  12179. if ((wlanevents[evt_code].parmsize != 0) &&
  12180. (wlanevents[evt_code].parmsize != evt_sz)) {
  12181. goto _abort_event_;
  12182. }
  12183. ATOMIC_INC(&pevt_priv->event_seq);
  12184. peventbuf += 2;
  12185. if (peventbuf) {
  12186. event_callback = wlanevents[evt_code].event_callback;
  12187. event_callback(padapter, (u8 *)peventbuf);
  12188. pevt_priv->evt_done_cnt++;
  12189. }
  12190. _abort_event_:
  12191. return H2C_SUCCESS;
  12192. }
  12193. u8 h2c_msg_hdl(_adapter *padapter, unsigned char *pbuf)
  12194. {
  12195. if (!pbuf)
  12196. return H2C_PARAMETERS_ERROR;
  12197. return H2C_SUCCESS;
  12198. }
  12199. u8 chk_bmc_sleepq_hdl(_adapter *padapter, unsigned char *pbuf)
  12200. {
  12201. #ifdef CONFIG_AP_MODE
  12202. _irqL irqL;
  12203. struct sta_info *psta_bmc;
  12204. _list *xmitframe_plist, *xmitframe_phead;
  12205. struct xmit_frame *pxmitframe = NULL;
  12206. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  12207. struct sta_priv *pstapriv = &padapter->stapriv;
  12208. /* for BC/MC Frames */
  12209. psta_bmc = rtw_get_bcmc_stainfo(padapter);
  12210. if (!psta_bmc)
  12211. return H2C_SUCCESS;
  12212. if ((pstapriv->tim_bitmap & BIT(0)) && (psta_bmc->sleepq_len > 0)) {
  12213. #ifndef CONFIG_PCI_HCI
  12214. rtw_msleep_os(10);/* 10ms, ATIM(HIQ) Windows */
  12215. #endif
  12216. /* _enter_critical_bh(&psta_bmc->sleep_q.lock, &irqL); */
  12217. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  12218. xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
  12219. xmitframe_plist = get_next(xmitframe_phead);
  12220. while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE) {
  12221. pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
  12222. xmitframe_plist = get_next(xmitframe_plist);
  12223. rtw_list_delete(&pxmitframe->list);
  12224. psta_bmc->sleepq_len--;
  12225. if (psta_bmc->sleepq_len > 0)
  12226. pxmitframe->attrib.mdata = 1;
  12227. else
  12228. pxmitframe->attrib.mdata = 0;
  12229. pxmitframe->attrib.triggered = 1;
  12230. if (xmitframe_hiq_filter(pxmitframe) == _TRUE)
  12231. pxmitframe->attrib.qsel = QSLT_HIGH;/* HIQ */
  12232. #if 0
  12233. _exit_critical_bh(&psta_bmc->sleep_q.lock, &irqL);
  12234. if (rtw_hal_xmit(padapter, pxmitframe) == _TRUE)
  12235. rtw_os_xmit_complete(padapter, pxmitframe);
  12236. _enter_critical_bh(&psta_bmc->sleep_q.lock, &irqL);
  12237. #endif
  12238. rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
  12239. }
  12240. /* _exit_critical_bh(&psta_bmc->sleep_q.lock, &irqL); */
  12241. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  12242. if (rtw_get_intf_type(padapter) != RTW_PCIE) {
  12243. /* check hi queue and bmc_sleepq */
  12244. rtw_chk_hi_queue_cmd(padapter);
  12245. }
  12246. }
  12247. #endif
  12248. return H2C_SUCCESS;
  12249. }
  12250. u8 tx_beacon_hdl(_adapter *padapter, unsigned char *pbuf)
  12251. {
  12252. #ifdef CONFIG_SWTIMER_BASED_TXBCN
  12253. tx_beacon_handlder(padapter->dvobj);
  12254. #else
  12255. if (send_beacon(padapter) == _FAIL) {
  12256. RTW_INFO("issue_beacon, fail!\n");
  12257. return H2C_PARAMETERS_ERROR;
  12258. }
  12259. /* tx bc/mc frames after update TIM */
  12260. chk_bmc_sleepq_hdl(padapter, NULL);
  12261. #endif
  12262. return H2C_SUCCESS;
  12263. }
  12264. /*
  12265. * according to channel
  12266. * add/remove WLAN_BSSID_EX.IEs's ERP ie
  12267. * set WLAN_BSSID_EX.SupportedRates
  12268. * update WLAN_BSSID_EX.IEs's Supported Rate and Extended Supported Rate ie
  12269. */
  12270. void change_band_update_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 ch)
  12271. {
  12272. u8 network_type, rate_len, total_rate_len, remainder_rate_len;
  12273. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  12274. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  12275. u8 erpinfo = 0x4;
  12276. if (ch >= 36) {
  12277. network_type = WIRELESS_11A;
  12278. total_rate_len = IEEE80211_NUM_OFDM_RATESLEN;
  12279. rtw_remove_bcn_ie(padapter, pnetwork, _ERPINFO_IE_);
  12280. } else {
  12281. network_type = WIRELESS_11BG;
  12282. total_rate_len = IEEE80211_CCK_RATE_LEN + IEEE80211_NUM_OFDM_RATESLEN;
  12283. rtw_add_bcn_ie(padapter, pnetwork, _ERPINFO_IE_, &erpinfo, 1);
  12284. }
  12285. rtw_set_supported_rate(pnetwork->SupportedRates, network_type);
  12286. UpdateBrateTbl(padapter, pnetwork->SupportedRates);
  12287. if (total_rate_len > 8) {
  12288. rate_len = 8;
  12289. remainder_rate_len = total_rate_len - 8;
  12290. } else {
  12291. rate_len = total_rate_len;
  12292. remainder_rate_len = 0;
  12293. }
  12294. rtw_add_bcn_ie(padapter, pnetwork, _SUPPORTEDRATES_IE_, pnetwork->SupportedRates, rate_len);
  12295. if (remainder_rate_len)
  12296. rtw_add_bcn_ie(padapter, pnetwork, _EXT_SUPPORTEDRATES_IE_, (pnetwork->SupportedRates + 8), remainder_rate_len);
  12297. else
  12298. rtw_remove_bcn_ie(padapter, pnetwork, _EXT_SUPPORTEDRATES_IE_);
  12299. pnetwork->Length = get_WLAN_BSSID_EX_sz(pnetwork);
  12300. }
  12301. void rtw_join_done_chk_ch(_adapter *adapter, int join_res)
  12302. {
  12303. #define DUMP_ADAPTERS_STATUS 0
  12304. struct dvobj_priv *dvobj;
  12305. _adapter *iface;
  12306. struct mlme_priv *mlme;
  12307. struct mlme_ext_priv *mlmeext;
  12308. u8 u_ch, u_offset, u_bw;
  12309. int i;
  12310. dvobj = adapter_to_dvobj(adapter);
  12311. if (DUMP_ADAPTERS_STATUS) {
  12312. RTW_INFO(FUNC_ADPT_FMT" enter\n", FUNC_ADPT_ARG(adapter));
  12313. dump_adapters_status(RTW_DBGDUMP , dvobj);
  12314. }
  12315. if (join_res >= 0) {
  12316. #ifdef CONFIG_MCC_MODE
  12317. /* MCC setting success, don't go to ch union process */
  12318. if (rtw_hal_set_mcc_setting_join_done_chk_ch(adapter))
  12319. return;
  12320. #endif /* CONFIG_MCC_MODE */
  12321. if (rtw_mi_get_ch_setting_union(adapter, &u_ch, &u_bw, &u_offset) <= 0) {
  12322. dump_adapters_status(RTW_DBGDUMP , dvobj);
  12323. rtw_warn_on(1);
  12324. }
  12325. for (i = 0; i < dvobj->iface_nums; i++) {
  12326. iface = dvobj->padapters[i];
  12327. mlme = &iface->mlmepriv;
  12328. mlmeext = &iface->mlmeextpriv;
  12329. if (!iface || iface == adapter)
  12330. continue;
  12331. if (check_fwstate(mlme, WIFI_AP_STATE)
  12332. && check_fwstate(mlme, WIFI_ASOC_STATE)
  12333. ) {
  12334. bool is_grouped = rtw_is_chbw_grouped(u_ch, u_bw, u_offset
  12335. , mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
  12336. if (is_grouped == _FALSE) {
  12337. /* handle AP which need to switch ch setting */
  12338. /* restore original bw, adjust bw by registry setting on target ch */
  12339. mlmeext->cur_bwmode = mlme->ori_bw;
  12340. mlmeext->cur_channel = u_ch;
  12341. rtw_adjust_chbw(iface
  12342. , mlmeext->cur_channel, &mlmeext->cur_bwmode, &mlmeext->cur_ch_offset);
  12343. rtw_sync_chbw(&mlmeext->cur_channel, &mlmeext->cur_bwmode, &mlmeext->cur_ch_offset
  12344. , &u_ch, &u_bw, &u_offset);
  12345. rtw_ap_update_bss_chbw(iface, &(mlmeext->mlmext_info.network)
  12346. , mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
  12347. _rtw_memcpy(&(mlme->cur_network.network), &(mlmeext->mlmext_info.network), sizeof(WLAN_BSSID_EX));
  12348. rtw_start_bss_hdl_after_chbw_decided(iface);
  12349. }
  12350. clr_fwstate(mlme, WIFI_OP_CH_SWITCHING);
  12351. update_beacon(iface, 0, NULL, _TRUE);
  12352. }
  12353. }
  12354. #ifdef CONFIG_DFS_MASTER
  12355. rtw_dfs_master_status_apply(adapter, MLME_STA_CONNECTED);
  12356. #endif
  12357. } else {
  12358. for (i = 0; i < dvobj->iface_nums; i++) {
  12359. iface = dvobj->padapters[i];
  12360. mlme = &iface->mlmepriv;
  12361. mlmeext = &iface->mlmeextpriv;
  12362. if (!iface || iface == adapter)
  12363. continue;
  12364. if (check_fwstate(mlme, WIFI_AP_STATE)
  12365. && check_fwstate(mlme, WIFI_ASOC_STATE)
  12366. ) {
  12367. clr_fwstate(mlme, WIFI_OP_CH_SWITCHING);
  12368. update_beacon(iface, 0, NULL, _TRUE);
  12369. }
  12370. }
  12371. #ifdef CONFIG_DFS_MASTER
  12372. rtw_dfs_master_status_apply(adapter, MLME_STA_DISCONNECTED);
  12373. #endif
  12374. }
  12375. if (rtw_mi_get_ch_setting_union(adapter, &u_ch, &u_bw, &u_offset)) {
  12376. set_channel_bwmode(adapter, u_ch, u_offset, u_bw);
  12377. rtw_mi_update_union_chan_inf(adapter, u_ch, u_offset, u_bw);
  12378. }
  12379. if (DUMP_ADAPTERS_STATUS) {
  12380. RTW_INFO(FUNC_ADPT_FMT" exit\n", FUNC_ADPT_ARG(adapter));
  12381. dump_adapters_status(RTW_DBGDUMP , dvobj);
  12382. }
  12383. }
  12384. int rtw_chk_start_clnt_join(_adapter *adapter, u8 *ch, u8 *bw, u8 *offset)
  12385. {
  12386. bool chbw_allow = _TRUE;
  12387. bool connect_allow = _TRUE;
  12388. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  12389. u8 cur_ch, cur_bw, cur_ch_offset;
  12390. u8 u_ch, u_offset, u_bw;
  12391. u_ch = cur_ch = pmlmeext->cur_channel;
  12392. u_bw = cur_bw = pmlmeext->cur_bwmode;
  12393. u_offset = cur_ch_offset = pmlmeext->cur_ch_offset;
  12394. if (!ch || !bw || !offset) {
  12395. connect_allow = _FALSE;
  12396. rtw_warn_on(1);
  12397. goto exit;
  12398. }
  12399. if (cur_ch == 0) {
  12400. connect_allow = _FALSE;
  12401. RTW_ERR(FUNC_ADPT_FMT" cur_ch:%u\n"
  12402. , FUNC_ADPT_ARG(adapter), cur_ch);
  12403. rtw_warn_on(1);
  12404. goto exit;
  12405. }
  12406. RTW_INFO(FUNC_ADPT_FMT" req: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
  12407. #ifdef CONFIG_CONCURRENT_MODE
  12408. {
  12409. struct dvobj_priv *dvobj;
  12410. _adapter *iface;
  12411. struct mlme_priv *mlme;
  12412. struct mlme_ext_priv *mlmeext;
  12413. struct mi_state mstate;
  12414. int i;
  12415. dvobj = adapter_to_dvobj(adapter);
  12416. rtw_mi_status_no_self(adapter, &mstate);
  12417. RTW_INFO(FUNC_ADPT_FMT" ld_sta_num:%u, ap_num:%u\n"
  12418. , FUNC_ADPT_ARG(adapter), MSTATE_STA_LD_NUM(&mstate), MSTATE_AP_NUM(&mstate));
  12419. if (!MSTATE_STA_LD_NUM(&mstate) && !MSTATE_AP_NUM(&mstate)) {
  12420. /* consider linking STA? */
  12421. goto connect_allow_hdl;
  12422. }
  12423. if (rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset) <= 0) {
  12424. dump_adapters_status(RTW_DBGDUMP , dvobj);
  12425. rtw_warn_on(1);
  12426. }
  12427. RTW_INFO(FUNC_ADPT_FMT" union no self: %u,%u,%u\n"
  12428. , FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
  12429. /* chbw_allow? */
  12430. chbw_allow = rtw_is_chbw_grouped(pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset
  12431. , u_ch, u_bw, u_offset);
  12432. RTW_INFO(FUNC_ADPT_FMT" chbw_allow:%d\n"
  12433. , FUNC_ADPT_ARG(adapter), chbw_allow);
  12434. #ifdef CONFIG_MCC_MODE
  12435. /* check setting success, don't go to ch union process */
  12436. if (rtw_hal_set_mcc_setting_chk_start_clnt_join(adapter, &u_ch, &u_bw, &u_offset, chbw_allow))
  12437. goto exit;
  12438. #endif
  12439. if (chbw_allow == _TRUE) {
  12440. rtw_sync_chbw(&cur_ch, &cur_bw, &cur_ch_offset, &u_ch, &u_bw, &u_offset);
  12441. rtw_warn_on(cur_ch != pmlmeext->cur_channel);
  12442. rtw_warn_on(cur_bw != pmlmeext->cur_bwmode);
  12443. rtw_warn_on(cur_ch_offset != pmlmeext->cur_ch_offset);
  12444. goto connect_allow_hdl;
  12445. }
  12446. #ifdef CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT
  12447. /* chbw_allow is _FALSE, connect allow? */
  12448. for (i = 0; i < dvobj->iface_nums; i++) {
  12449. iface = dvobj->padapters[i];
  12450. mlme = &iface->mlmepriv;
  12451. mlmeext = &iface->mlmeextpriv;
  12452. if (check_fwstate(mlme, WIFI_STATION_STATE)
  12453. && check_fwstate(mlme, WIFI_ASOC_STATE)
  12454. #if defined(CONFIG_P2P)
  12455. && rtw_p2p_chk_state(&(iface->wdinfo), P2P_STATE_NONE)
  12456. #endif
  12457. ) {
  12458. connect_allow = _FALSE;
  12459. break;
  12460. }
  12461. }
  12462. #endif /* CONFIG_CFG80211_ONECHANNEL_UNDER_CONCURRENT */
  12463. if (MSTATE_STA_LD_NUM(&mstate) + MSTATE_AP_LD_NUM(&mstate) >= 2)
  12464. connect_allow = _FALSE;
  12465. RTW_INFO(FUNC_ADPT_FMT" connect_allow:%d\n"
  12466. , FUNC_ADPT_ARG(adapter), connect_allow);
  12467. if (connect_allow == _FALSE)
  12468. goto exit;
  12469. connect_allow_hdl:
  12470. /* connect_allow == _TRUE */
  12471. #ifdef CONFIG_DFS_MASTER
  12472. rtw_dfs_master_status_apply(adapter, MLME_STA_CONNECTING);
  12473. #endif
  12474. if (chbw_allow == _FALSE) {
  12475. u_ch = cur_ch;
  12476. u_bw = cur_bw;
  12477. u_offset = cur_ch_offset;
  12478. for (i = 0; i < dvobj->iface_nums; i++) {
  12479. iface = dvobj->padapters[i];
  12480. mlme = &iface->mlmepriv;
  12481. mlmeext = &iface->mlmeextpriv;
  12482. if (!iface || iface == adapter)
  12483. continue;
  12484. if (check_fwstate(mlme, WIFI_AP_STATE)
  12485. && check_fwstate(mlme, WIFI_ASOC_STATE)
  12486. ) {
  12487. #ifdef CONFIG_SPCT_CH_SWITCH
  12488. if (1)
  12489. rtw_ap_inform_ch_switch(iface, pmlmeext->cur_channel , pmlmeext->cur_ch_offset);
  12490. else
  12491. #endif
  12492. rtw_sta_flush(iface, _FALSE);
  12493. rtw_hal_set_hwreg(iface, HW_VAR_CHECK_TXBUF, 0);
  12494. set_fwstate(mlme, WIFI_OP_CH_SWITCHING);
  12495. } else if (check_fwstate(mlme, WIFI_STATION_STATE)
  12496. && check_fwstate(mlme, WIFI_ASOC_STATE)
  12497. ) {
  12498. rtw_disassoc_cmd(iface, 500, RTW_CMDF_DIRECTLY);
  12499. rtw_indicate_disconnect(iface, 0, _FALSE);
  12500. rtw_free_assoc_resources(iface, 1);
  12501. }
  12502. }
  12503. }
  12504. }
  12505. #endif /* CONFIG_CONCURRENT_MODE */
  12506. exit:
  12507. if (connect_allow == _TRUE) {
  12508. RTW_INFO(FUNC_ADPT_FMT" union: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
  12509. *ch = u_ch;
  12510. *bw = u_bw;
  12511. *offset = u_offset;
  12512. }
  12513. return connect_allow == _TRUE ? _SUCCESS : _FAIL;
  12514. }
  12515. u8 set_ch_hdl(_adapter *padapter, u8 *pbuf)
  12516. {
  12517. struct set_ch_parm *set_ch_parm;
  12518. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  12519. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  12520. if (!pbuf)
  12521. return H2C_PARAMETERS_ERROR;
  12522. set_ch_parm = (struct set_ch_parm *)pbuf;
  12523. RTW_INFO(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
  12524. FUNC_NDEV_ARG(padapter->pnetdev),
  12525. set_ch_parm->ch, set_ch_parm->bw, set_ch_parm->ch_offset);
  12526. pmlmeext->cur_channel = set_ch_parm->ch;
  12527. pmlmeext->cur_ch_offset = set_ch_parm->ch_offset;
  12528. pmlmeext->cur_bwmode = set_ch_parm->bw;
  12529. set_channel_bwmode(padapter, set_ch_parm->ch, set_ch_parm->ch_offset, set_ch_parm->bw);
  12530. return H2C_SUCCESS;
  12531. }
  12532. u8 set_chplan_hdl(_adapter *padapter, unsigned char *pbuf)
  12533. {
  12534. struct SetChannelPlan_param *setChannelPlan_param;
  12535. struct mlme_priv *mlme = &padapter->mlmepriv;
  12536. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  12537. if (!pbuf)
  12538. return H2C_PARAMETERS_ERROR;
  12539. setChannelPlan_param = (struct SetChannelPlan_param *)pbuf;
  12540. if (!rtw_is_channel_plan_valid(setChannelPlan_param->channel_plan))
  12541. return H2C_PARAMETERS_ERROR;
  12542. mlme->country_ent = setChannelPlan_param->country_ent;
  12543. mlme->ChannelPlan = setChannelPlan_param->channel_plan;
  12544. pmlmeext->max_chan_nums = init_channel_set(padapter, setChannelPlan_param->channel_plan, pmlmeext->channel_set);
  12545. init_channel_list(padapter, pmlmeext->channel_set, &pmlmeext->channel_list);
  12546. rtw_hal_set_odm_var(padapter, HAL_ODM_REGULATION, NULL, _TRUE);
  12547. #ifdef CONFIG_IOCTL_CFG80211
  12548. rtw_reg_notify_by_driver(padapter);
  12549. #endif /* CONFIG_IOCTL_CFG80211 */
  12550. return H2C_SUCCESS;
  12551. }
  12552. u8 led_blink_hdl(_adapter *padapter, unsigned char *pbuf)
  12553. {
  12554. struct LedBlink_param *ledBlink_param;
  12555. if (!pbuf)
  12556. return H2C_PARAMETERS_ERROR;
  12557. ledBlink_param = (struct LedBlink_param *)pbuf;
  12558. #ifdef CONFIG_LED_HANDLED_BY_CMD_THREAD
  12559. BlinkHandler((PLED_DATA)ledBlink_param->pLed);
  12560. #endif
  12561. return H2C_SUCCESS;
  12562. }
  12563. u8 set_csa_hdl(_adapter *padapter, unsigned char *pbuf)
  12564. {
  12565. #ifdef CONFIG_DFS
  12566. struct SetChannelSwitch_param *setChannelSwitch_param;
  12567. u8 new_ch_no;
  12568. u8 gval8 = 0x00, sval8 = 0xff;
  12569. if (!pbuf)
  12570. return H2C_PARAMETERS_ERROR;
  12571. setChannelSwitch_param = (struct SetChannelSwitch_param *)pbuf;
  12572. new_ch_no = setChannelSwitch_param->new_ch_no;
  12573. rtw_hal_get_hwreg(padapter, HW_VAR_TXPAUSE, &gval8);
  12574. rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, &sval8);
  12575. RTW_INFO("DFS detected! Swiching channel to %d!\n", new_ch_no);
  12576. set_channel_bwmode(padapter, new_ch_no, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  12577. rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, &gval8);
  12578. rtw_disassoc_cmd(padapter, 0, RTW_CMDF_DIRECTLY);
  12579. rtw_indicate_disconnect(padapter, 0, _FALSE);
  12580. rtw_free_assoc_resources(padapter, 1);
  12581. rtw_free_network_queue(padapter, _TRUE);
  12582. if (rtw_is_dfs_ch(new_ch_no))
  12583. RTW_INFO("Switched to DFS band (ch %u) again!!\n", new_ch_no);
  12584. return H2C_SUCCESS;
  12585. #else
  12586. return H2C_REJECTED;
  12587. #endif /* CONFIG_DFS */
  12588. }
  12589. u8 tdls_hdl(_adapter *padapter, unsigned char *pbuf)
  12590. {
  12591. #ifdef CONFIG_TDLS
  12592. _irqL irqL;
  12593. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  12594. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  12595. #ifdef CONFIG_TDLS_CH_SW
  12596. struct tdls_ch_switch *pchsw_info = &ptdlsinfo->chsw_info;
  12597. #endif
  12598. struct TDLSoption_param *TDLSoption;
  12599. struct sta_info *ptdls_sta = NULL;
  12600. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  12601. struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  12602. u8 survey_channel, i, min, option;
  12603. struct tdls_txmgmt txmgmt;
  12604. u32 setchtime, resp_sleep = 0, wait_time;
  12605. u8 zaddr[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  12606. u8 ret;
  12607. u8 doiqk;
  12608. if (!pbuf)
  12609. return H2C_PARAMETERS_ERROR;
  12610. TDLSoption = (struct TDLSoption_param *)pbuf;
  12611. option = TDLSoption->option;
  12612. if (!_rtw_memcmp(TDLSoption->addr, zaddr, ETH_ALEN)) {
  12613. ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), TDLSoption->addr);
  12614. if (ptdls_sta == NULL)
  12615. return H2C_REJECTED;
  12616. } else {
  12617. if (!(option == TDLS_RS_RCR))
  12618. return H2C_REJECTED;
  12619. }
  12620. /* _enter_critical_bh(&(ptdlsinfo->hdl_lock), &irqL); */
  12621. /* RTW_INFO("[%s] option:%d\n", __FUNCTION__, option); */
  12622. switch (option) {
  12623. case TDLS_ESTABLISHED: {
  12624. /* As long as TDLS handshake success, we should set RCR_CBSSID_DATA bit to 0 */
  12625. /* So we can receive all kinds of data frames. */
  12626. u8 sta_band = 0;
  12627. /* leave ALL PS when TDLS is established */
  12628. rtw_pwr_wakeup(padapter);
  12629. rtw_hal_set_hwreg(padapter, HW_VAR_TDLS_WRCR, 0);
  12630. RTW_INFO("Created Direct Link with "MAC_FMT"\n", MAC_ARG(ptdls_sta->hwaddr));
  12631. /* Set TDLS sta rate. */
  12632. /* Update station supportRate */
  12633. rtw_hal_update_sta_rate_mask(padapter, ptdls_sta);
  12634. if (pmlmeext->cur_channel > 14) {
  12635. if (ptdls_sta->ra_mask & 0xffff000)
  12636. sta_band |= WIRELESS_11_5N ;
  12637. if (ptdls_sta->ra_mask & 0xff0)
  12638. sta_band |= WIRELESS_11A;
  12639. /* 5G band */
  12640. #ifdef CONFIG_80211AC_VHT
  12641. if (ptdls_sta->vhtpriv.vht_option)
  12642. sta_band = WIRELESS_11_5AC;
  12643. #endif
  12644. } else {
  12645. if (ptdls_sta->ra_mask & 0xffff000)
  12646. sta_band |= WIRELESS_11_24N;
  12647. if (ptdls_sta->ra_mask & 0xff0)
  12648. sta_band |= WIRELESS_11G;
  12649. if (ptdls_sta->ra_mask & 0x0f)
  12650. sta_band |= WIRELESS_11B;
  12651. }
  12652. ptdls_sta->wireless_mode = sta_band;
  12653. ptdls_sta->raid = rtw_hal_networktype_to_raid(padapter, ptdls_sta);
  12654. set_sta_rate(padapter, ptdls_sta);
  12655. rtw_sta_media_status_rpt(padapter, ptdls_sta, 1);
  12656. /* Sta mode */
  12657. rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, ptdls_sta, _TRUE);
  12658. break;
  12659. }
  12660. case TDLS_ISSUE_PTI:
  12661. ptdls_sta->tdls_sta_state |= TDLS_WAIT_PTR_STATE;
  12662. issue_tdls_peer_traffic_indication(padapter, ptdls_sta);
  12663. _set_timer(&ptdls_sta->pti_timer, TDLS_PTI_TIME);
  12664. break;
  12665. #ifdef CONFIG_TDLS_CH_SW
  12666. case TDLS_CH_SW_RESP:
  12667. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  12668. txmgmt.status_code = 0;
  12669. _rtw_memcpy(txmgmt.peer, ptdls_sta->hwaddr, ETH_ALEN);
  12670. issue_nulldata(padapter, NULL, 1, 3, 3);
  12671. RTW_INFO("[TDLS ] issue tdls channel switch response\n");
  12672. ret = issue_tdls_ch_switch_rsp(padapter, &txmgmt, _TRUE);
  12673. /* If we receive TDLS_CH_SW_REQ at off channel which it's target is AP's channel */
  12674. /* then we just switch to AP's channel*/
  12675. if (padapter->mlmeextpriv.cur_channel == pchsw_info->off_ch_num) {
  12676. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_CH_SW_END_TO_BASE_CHNL);
  12677. break;
  12678. }
  12679. if (ret == _SUCCESS)
  12680. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_CH_SW_TO_OFF_CHNL);
  12681. else
  12682. RTW_INFO("[TDLS] issue_tdls_ch_switch_rsp wait ack fail !!!!!!!!!!\n");
  12683. break;
  12684. case TDLS_CH_SW_PREPARE:
  12685. pchsw_info->ch_sw_state |= TDLS_CH_SWITCH_PREPARE_STATE;
  12686. /* to collect IQK info of off-chnl */
  12687. doiqk = _TRUE;
  12688. rtw_hal_set_hwreg(padapter, HW_VAR_DO_IQK, &doiqk);
  12689. set_channel_bwmode(padapter, pchsw_info->off_ch_num, pchsw_info->ch_offset, (pchsw_info->ch_offset) ? CHANNEL_WIDTH_40 : CHANNEL_WIDTH_20);
  12690. doiqk = _FALSE;
  12691. rtw_hal_set_hwreg(padapter, HW_VAR_DO_IQK, &doiqk);
  12692. /* switch back to base-chnl */
  12693. set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  12694. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_CH_SW_START);
  12695. pchsw_info->ch_sw_state &= ~(TDLS_CH_SWITCH_PREPARE_STATE);
  12696. break;
  12697. case TDLS_CH_SW_START:
  12698. rtw_tdls_set_ch_sw_oper_control(padapter, _TRUE);
  12699. break;
  12700. case TDLS_CH_SW_TO_OFF_CHNL:
  12701. issue_nulldata(padapter, NULL, 1, 3, 3);
  12702. if (!(pchsw_info->ch_sw_state & TDLS_CH_SW_INITIATOR_STATE))
  12703. _set_timer(&ptdls_sta->ch_sw_timer, (u32)(ptdls_sta->ch_switch_timeout) / 1000);
  12704. if (rtw_tdls_do_ch_sw(padapter, ptdls_sta, TDLS_CH_SW_OFF_CHNL, pchsw_info->off_ch_num,
  12705. pchsw_info->ch_offset, (pchsw_info->ch_offset) ? CHANNEL_WIDTH_40 : CHANNEL_WIDTH_20, ptdls_sta->ch_switch_time) == _SUCCESS) {
  12706. pchsw_info->ch_sw_state &= ~(TDLS_PEER_AT_OFF_STATE);
  12707. if (pchsw_info->ch_sw_state & TDLS_CH_SW_INITIATOR_STATE) {
  12708. if (issue_nulldata_to_TDLS_peer_STA(ptdls_sta->padapter, ptdls_sta->hwaddr, 0, 1, 3) == _FAIL)
  12709. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_CH_SW_TO_BASE_CHNL);
  12710. }
  12711. } else {
  12712. if (!(pchsw_info->ch_sw_state & TDLS_CH_SW_INITIATOR_STATE))
  12713. _cancel_timer_ex(&ptdls_sta->ch_sw_timer);
  12714. }
  12715. break;
  12716. case TDLS_CH_SW_END:
  12717. case TDLS_CH_SW_END_TO_BASE_CHNL:
  12718. rtw_tdls_set_ch_sw_oper_control(padapter, _FALSE);
  12719. _cancel_timer_ex(&ptdls_sta->ch_sw_timer);
  12720. _cancel_timer_ex(&ptdls_sta->stay_on_base_chnl_timer);
  12721. _cancel_timer_ex(&ptdls_sta->ch_sw_monitor_timer);
  12722. #if 0
  12723. _rtw_memset(pHalData->tdls_ch_sw_iqk_info_base_chnl, 0x00, sizeof(pHalData->tdls_ch_sw_iqk_info_base_chnl));
  12724. _rtw_memset(pHalData->tdls_ch_sw_iqk_info_off_chnl, 0x00, sizeof(pHalData->tdls_ch_sw_iqk_info_off_chnl));
  12725. #endif
  12726. if (option == TDLS_CH_SW_END_TO_BASE_CHNL)
  12727. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_CH_SW_TO_BASE_CHNL);
  12728. break;
  12729. case TDLS_CH_SW_TO_BASE_CHNL_UNSOLICITED:
  12730. case TDLS_CH_SW_TO_BASE_CHNL:
  12731. pchsw_info->ch_sw_state &= ~(TDLS_PEER_AT_OFF_STATE | TDLS_WAIT_CH_RSP_STATE);
  12732. if (option == TDLS_CH_SW_TO_BASE_CHNL_UNSOLICITED) {
  12733. if (ptdls_sta != NULL) {
  12734. /* Send unsolicited channel switch rsp. to peer */
  12735. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  12736. txmgmt.status_code = 0;
  12737. _rtw_memcpy(txmgmt.peer, ptdls_sta->hwaddr, ETH_ALEN);
  12738. issue_tdls_ch_switch_rsp(padapter, &txmgmt, _FALSE);
  12739. }
  12740. }
  12741. if (rtw_tdls_do_ch_sw(padapter, ptdls_sta, TDLS_CH_SW_BASE_CHNL, pmlmeext->cur_channel,
  12742. pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode, ptdls_sta->ch_switch_time) == _SUCCESS) {
  12743. issue_nulldata(padapter, NULL, 0, 3, 3);
  12744. /* set ch sw monitor timer for responder */
  12745. if (!(pchsw_info->ch_sw_state & TDLS_CH_SW_INITIATOR_STATE))
  12746. _set_timer(&ptdls_sta->ch_sw_monitor_timer, TDLS_CH_SW_MONITOR_TIMEOUT);
  12747. }
  12748. break;
  12749. #endif
  12750. case TDLS_RS_RCR:
  12751. rtw_hal_set_hwreg(padapter, HW_VAR_TDLS_RS_RCR, 0);
  12752. RTW_INFO("[TDLS] write REG_RCR, set bit6 on\n");
  12753. break;
  12754. case TDLS_TEARDOWN_STA:
  12755. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  12756. txmgmt.status_code = 0;
  12757. _rtw_memcpy(txmgmt.peer, ptdls_sta->hwaddr, ETH_ALEN);
  12758. issue_tdls_teardown(padapter, &txmgmt, _TRUE);
  12759. break;
  12760. case TDLS_TEARDOWN_STA_LOCALLY:
  12761. #ifdef CONFIG_TDLS_CH_SW
  12762. if (_rtw_memcmp(TDLSoption->addr, pchsw_info->addr, ETH_ALEN) == _TRUE) {
  12763. pchsw_info->ch_sw_state &= ~(TDLS_CH_SW_INITIATOR_STATE |
  12764. TDLS_CH_SWITCH_ON_STATE |
  12765. TDLS_PEER_AT_OFF_STATE);
  12766. rtw_tdls_set_ch_sw_oper_control(padapter, _FALSE);
  12767. _rtw_memset(pchsw_info->addr, 0x00, ETH_ALEN);
  12768. }
  12769. #endif
  12770. rtw_sta_media_status_rpt(padapter, ptdls_sta, 0);
  12771. free_tdls_sta(padapter, ptdls_sta);
  12772. break;
  12773. }
  12774. /* _exit_critical_bh(&(ptdlsinfo->hdl_lock), &irqL); */
  12775. return H2C_SUCCESS;
  12776. #else
  12777. return H2C_REJECTED;
  12778. #endif /* CONFIG_TDLS */
  12779. }
  12780. u8 run_in_thread_hdl(_adapter *padapter, u8 *pbuf)
  12781. {
  12782. struct RunInThread_param *p;
  12783. if (NULL == pbuf)
  12784. return H2C_PARAMETERS_ERROR;
  12785. p = (struct RunInThread_param *)pbuf;
  12786. if (p->func)
  12787. p->func(p->context);
  12788. return H2C_SUCCESS;
  12789. }
  12790. u8 rtw_getmacreg_hdl(_adapter *padapter, u8 *pbuf)
  12791. {
  12792. struct readMAC_parm *preadmacparm = NULL;
  12793. u8 sz = 0;
  12794. u32 addr = 0;
  12795. u32 value = 0;
  12796. if (!pbuf)
  12797. return H2C_PARAMETERS_ERROR;
  12798. preadmacparm = (struct readMAC_parm *) pbuf;
  12799. sz = preadmacparm->len;
  12800. addr = preadmacparm->addr;
  12801. value = 0;
  12802. switch (sz) {
  12803. case 1:
  12804. value = rtw_read8(padapter, addr);
  12805. break;
  12806. case 2:
  12807. value = rtw_read16(padapter, addr);
  12808. break;
  12809. case 4:
  12810. value = rtw_read32(padapter, addr);
  12811. break;
  12812. default:
  12813. RTW_INFO("%s: Unknown size\n", __func__);
  12814. break;
  12815. }
  12816. RTW_INFO("%s: addr:0x%02x valeu:0x%02x\n", __func__, addr, value);
  12817. return H2C_SUCCESS;
  12818. }