mac80211_hwsim.c 194 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211
  4. * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
  5. * Copyright (c) 2011, Javier Lopez <jlopex@gmail.com>
  6. * Copyright (c) 2016 - 2017 Intel Deutschland GmbH
  7. * Copyright (C) 2018 - 2025 Intel Corporation
  8. */
  9. /*
  10. * TODO:
  11. * - Add TSF sync and fix IBSS beacon transmission by adding
  12. * competition for "air time" at TBTT
  13. * - RX filtering based on filter configuration (data->rx_filter)
  14. */
  15. #include <linux/list.h>
  16. #include <linux/slab.h>
  17. #include <linux/spinlock.h>
  18. #include <net/dst.h>
  19. #include <net/xfrm.h>
  20. #include <net/mac80211.h>
  21. #include <net/ieee80211_radiotap.h>
  22. #include <linux/if_arp.h>
  23. #include <linux/rtnetlink.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/debugfs.h>
  27. #include <linux/module.h>
  28. #include <linux/ktime.h>
  29. #include <net/genetlink.h>
  30. #include <net/net_namespace.h>
  31. #include <net/netns/generic.h>
  32. #include <linux/rhashtable.h>
  33. #include <linux/nospec.h>
  34. #include <linux/virtio.h>
  35. #include <linux/virtio_ids.h>
  36. #include <linux/virtio_config.h>
  37. #include "mac80211_hwsim.h"
  38. #define WARN_QUEUE 100
  39. #define MAX_QUEUE 200
  40. MODULE_AUTHOR("Jouni Malinen");
  41. MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211");
  42. MODULE_LICENSE("GPL");
  43. static int radios = 2;
  44. module_param(radios, int, 0444);
  45. MODULE_PARM_DESC(radios, "Number of simulated radios");
  46. static int channels = 1;
  47. module_param(channels, int, 0444);
  48. MODULE_PARM_DESC(channels, "Number of concurrent channels");
  49. static bool paged_rx = false;
  50. module_param(paged_rx, bool, 0644);
  51. MODULE_PARM_DESC(paged_rx, "Use paged SKBs for RX instead of linear ones");
  52. static bool rctbl = false;
  53. module_param(rctbl, bool, 0444);
  54. MODULE_PARM_DESC(rctbl, "Handle rate control table");
  55. static bool support_p2p_device = true;
  56. module_param(support_p2p_device, bool, 0444);
  57. MODULE_PARM_DESC(support_p2p_device, "Support P2P-Device interface type");
  58. static bool mlo;
  59. module_param(mlo, bool, 0444);
  60. MODULE_PARM_DESC(mlo, "Support MLO");
  61. static bool multi_radio;
  62. module_param(multi_radio, bool, 0444);
  63. MODULE_PARM_DESC(multi_radio, "Support Multiple Radios per wiphy");
  64. /**
  65. * enum hwsim_regtest - the type of regulatory tests we offer
  66. *
  67. * @HWSIM_REGTEST_DISABLED: No regulatory tests are performed,
  68. * this is the default value.
  69. * @HWSIM_REGTEST_DRIVER_REG_FOLLOW: Used for testing the driver regulatory
  70. * hint, only one driver regulatory hint will be sent as such the
  71. * secondary radios are expected to follow.
  72. * @HWSIM_REGTEST_DRIVER_REG_ALL: Used for testing the driver regulatory
  73. * request with all radios reporting the same regulatory domain.
  74. * @HWSIM_REGTEST_DIFF_COUNTRY: Used for testing the drivers calling
  75. * different regulatory domains requests. Expected behaviour is for
  76. * an intersection to occur but each device will still use their
  77. * respective regulatory requested domains. Subsequent radios will
  78. * use the resulting intersection.
  79. * @HWSIM_REGTEST_WORLD_ROAM: Used for testing the world roaming. We accomplish
  80. * this by using a custom beacon-capable regulatory domain for the first
  81. * radio. All other device world roam.
  82. * @HWSIM_REGTEST_CUSTOM_WORLD: Used for testing the custom world regulatory
  83. * domain requests. All radios will adhere to this custom world regulatory
  84. * domain.
  85. * @HWSIM_REGTEST_CUSTOM_WORLD_2: Used for testing 2 custom world regulatory
  86. * domain requests. The first radio will adhere to the first custom world
  87. * regulatory domain, the second one to the second custom world regulatory
  88. * domain. All other devices will world roam.
  89. * @HWSIM_REGTEST_STRICT_FOLLOW: Used for testing strict regulatory domain
  90. * settings, only the first radio will send a regulatory domain request
  91. * and use strict settings. The rest of the radios are expected to follow.
  92. * @HWSIM_REGTEST_STRICT_ALL: Used for testing strict regulatory domain
  93. * settings. All radios will adhere to this.
  94. * @HWSIM_REGTEST_STRICT_AND_DRIVER_REG: Used for testing strict regulatory
  95. * domain settings, combined with secondary driver regulatory domain
  96. * settings. The first radio will get a strict regulatory domain setting
  97. * using the first driver regulatory request and the second radio will use
  98. * non-strict settings using the second driver regulatory request. All
  99. * other devices should follow the intersection created between the
  100. * first two.
  101. * @HWSIM_REGTEST_ALL: Used for testing every possible mix. You will need
  102. * at least 6 radios for a complete test. We will test in this order:
  103. * 1 - driver custom world regulatory domain
  104. * 2 - second custom world regulatory domain
  105. * 3 - first driver regulatory domain request
  106. * 4 - second driver regulatory domain request
  107. * 5 - strict regulatory domain settings using the third driver regulatory
  108. * domain request
  109. * 6 and on - should follow the intersection of the 3rd, 4rth and 5th radio
  110. * regulatory requests.
  111. *
  112. * These are the different values you can use for the regtest
  113. * module parameter. This is useful to help test world roaming
  114. * and the driver regulatory_hint() call and combinations of these.
  115. * If you want to do specific alpha2 regulatory domain tests simply
  116. * use the userspace regulatory request as that will be respected as
  117. * well without the need of this module parameter. This is designed
  118. * only for testing the driver regulatory request, world roaming
  119. * and all possible combinations.
  120. */
  121. enum hwsim_regtest {
  122. HWSIM_REGTEST_DISABLED = 0,
  123. HWSIM_REGTEST_DRIVER_REG_FOLLOW = 1,
  124. HWSIM_REGTEST_DRIVER_REG_ALL = 2,
  125. HWSIM_REGTEST_DIFF_COUNTRY = 3,
  126. HWSIM_REGTEST_WORLD_ROAM = 4,
  127. HWSIM_REGTEST_CUSTOM_WORLD = 5,
  128. HWSIM_REGTEST_CUSTOM_WORLD_2 = 6,
  129. HWSIM_REGTEST_STRICT_FOLLOW = 7,
  130. HWSIM_REGTEST_STRICT_ALL = 8,
  131. HWSIM_REGTEST_STRICT_AND_DRIVER_REG = 9,
  132. HWSIM_REGTEST_ALL = 10,
  133. };
  134. /* Set to one of the HWSIM_REGTEST_* values above */
  135. static int regtest = HWSIM_REGTEST_DISABLED;
  136. module_param(regtest, int, 0444);
  137. MODULE_PARM_DESC(regtest, "The type of regulatory test we want to run");
  138. static const char *hwsim_alpha2s[] = {
  139. "FI",
  140. "AL",
  141. "US",
  142. "DE",
  143. "JP",
  144. "AL",
  145. };
  146. static const struct ieee80211_regdomain hwsim_world_regdom_custom_01 = {
  147. .n_reg_rules = 5,
  148. .alpha2 = "99",
  149. .reg_rules = {
  150. REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
  151. REG_RULE(2484-10, 2484+10, 40, 0, 20, 0),
  152. REG_RULE(5150-10, 5240+10, 40, 0, 30, 0),
  153. REG_RULE(5745-10, 5825+10, 40, 0, 30, 0),
  154. REG_RULE(5855-10, 5925+10, 40, 0, 33, 0),
  155. }
  156. };
  157. static const struct ieee80211_regdomain hwsim_world_regdom_custom_02 = {
  158. .n_reg_rules = 3,
  159. .alpha2 = "99",
  160. .reg_rules = {
  161. REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
  162. REG_RULE(5725-10, 5850+10, 40, 0, 30,
  163. NL80211_RRF_NO_IR),
  164. REG_RULE(5855-10, 5925+10, 40, 0, 33, 0),
  165. }
  166. };
  167. static const struct ieee80211_regdomain hwsim_world_regdom_custom_03 = {
  168. .n_reg_rules = 6,
  169. .alpha2 = "99",
  170. .reg_rules = {
  171. REG_RULE(2412 - 10, 2462 + 10, 40, 0, 20, 0),
  172. REG_RULE(2484 - 10, 2484 + 10, 40, 0, 20, 0),
  173. REG_RULE(5150 - 10, 5240 + 10, 40, 0, 30, 0),
  174. REG_RULE(5745 - 10, 5825 + 10, 40, 0, 30, 0),
  175. REG_RULE(5855 - 10, 5925 + 10, 40, 0, 33, 0),
  176. REG_RULE(5955 - 10, 7125 + 10, 320, 0, 33, 0),
  177. }
  178. };
  179. static const struct ieee80211_regdomain hwsim_world_regdom_custom_04 = {
  180. .n_reg_rules = 6,
  181. .alpha2 = "99",
  182. .reg_rules = {
  183. REG_RULE(2412 - 10, 2462 + 10, 40, 0, 20, 0),
  184. REG_RULE(2484 - 10, 2484 + 10, 40, 0, 20, 0),
  185. REG_RULE(5150 - 10, 5240 + 10, 80, 0, 30, NL80211_RRF_AUTO_BW),
  186. REG_RULE(5260 - 10, 5320 + 10, 80, 0, 30,
  187. NL80211_RRF_DFS_CONCURRENT | NL80211_RRF_DFS |
  188. NL80211_RRF_AUTO_BW),
  189. REG_RULE(5500 - 10, 5720 + 10, 160, 0, 30,
  190. NL80211_RRF_DFS_CONCURRENT | NL80211_RRF_DFS),
  191. REG_RULE(5745 - 10, 5825 + 10, 80, 0, 30, 0),
  192. REG_RULE(5855 - 10, 5925 + 10, 80, 0, 33, 0),
  193. }
  194. };
  195. static const struct ieee80211_regdomain *hwsim_world_regdom_custom[] = {
  196. &hwsim_world_regdom_custom_01,
  197. &hwsim_world_regdom_custom_02,
  198. &hwsim_world_regdom_custom_03,
  199. &hwsim_world_regdom_custom_04,
  200. };
  201. struct hwsim_vif_priv {
  202. u32 magic;
  203. u32 skip_beacons[IEEE80211_MLD_MAX_NUM_LINKS];
  204. u8 bssid[ETH_ALEN];
  205. bool assoc;
  206. bool bcn_en;
  207. u16 aid;
  208. };
  209. #define HWSIM_VIF_MAGIC 0x69537748
  210. static inline void hwsim_check_magic(struct ieee80211_vif *vif)
  211. {
  212. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  213. WARN(vp->magic != HWSIM_VIF_MAGIC,
  214. "Invalid VIF (%p) magic %#x, %pM, %d/%d\n",
  215. vif, vp->magic, vif->addr, vif->type, vif->p2p);
  216. }
  217. static inline void hwsim_set_magic(struct ieee80211_vif *vif)
  218. {
  219. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  220. vp->magic = HWSIM_VIF_MAGIC;
  221. }
  222. static inline void hwsim_clear_magic(struct ieee80211_vif *vif)
  223. {
  224. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  225. vp->magic = 0;
  226. }
  227. struct hwsim_sta_priv {
  228. u32 magic;
  229. unsigned int last_link;
  230. u16 active_links_rx;
  231. };
  232. #define HWSIM_STA_MAGIC 0x6d537749
  233. static inline void hwsim_check_sta_magic(struct ieee80211_sta *sta)
  234. {
  235. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  236. WARN_ON(sp->magic != HWSIM_STA_MAGIC);
  237. }
  238. static inline void hwsim_set_sta_magic(struct ieee80211_sta *sta)
  239. {
  240. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  241. sp->magic = HWSIM_STA_MAGIC;
  242. }
  243. static inline void hwsim_clear_sta_magic(struct ieee80211_sta *sta)
  244. {
  245. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  246. sp->magic = 0;
  247. }
  248. struct hwsim_chanctx_priv {
  249. u32 magic;
  250. };
  251. #define HWSIM_CHANCTX_MAGIC 0x6d53774a
  252. static inline void hwsim_check_chanctx_magic(struct ieee80211_chanctx_conf *c)
  253. {
  254. struct hwsim_chanctx_priv *cp = (void *)c->drv_priv;
  255. WARN_ON(cp->magic != HWSIM_CHANCTX_MAGIC);
  256. }
  257. static inline void hwsim_set_chanctx_magic(struct ieee80211_chanctx_conf *c)
  258. {
  259. struct hwsim_chanctx_priv *cp = (void *)c->drv_priv;
  260. cp->magic = HWSIM_CHANCTX_MAGIC;
  261. }
  262. static inline void hwsim_clear_chanctx_magic(struct ieee80211_chanctx_conf *c)
  263. {
  264. struct hwsim_chanctx_priv *cp = (void *)c->drv_priv;
  265. cp->magic = 0;
  266. }
  267. static unsigned int hwsim_net_id;
  268. static DEFINE_IDA(hwsim_netgroup_ida);
  269. struct hwsim_net {
  270. int netgroup;
  271. u32 wmediumd;
  272. };
  273. static inline int hwsim_net_get_netgroup(struct net *net)
  274. {
  275. struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
  276. return hwsim_net->netgroup;
  277. }
  278. static inline int hwsim_net_set_netgroup(struct net *net)
  279. {
  280. struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
  281. hwsim_net->netgroup = ida_alloc(&hwsim_netgroup_ida, GFP_KERNEL);
  282. return hwsim_net->netgroup >= 0 ? 0 : -ENOMEM;
  283. }
  284. static inline u32 hwsim_net_get_wmediumd(struct net *net)
  285. {
  286. struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
  287. return hwsim_net->wmediumd;
  288. }
  289. static inline void hwsim_net_set_wmediumd(struct net *net, u32 portid)
  290. {
  291. struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
  292. hwsim_net->wmediumd = portid;
  293. }
  294. static struct class *hwsim_class;
  295. static struct net_device *hwsim_mon; /* global monitor netdev */
  296. #define CHAN2G(_freq) { \
  297. .band = NL80211_BAND_2GHZ, \
  298. .center_freq = (_freq), \
  299. .hw_value = (_freq), \
  300. }
  301. #define CHAN5G(_freq) { \
  302. .band = NL80211_BAND_5GHZ, \
  303. .center_freq = (_freq), \
  304. .hw_value = (_freq), \
  305. }
  306. #define CHAN6G(_freq) { \
  307. .band = NL80211_BAND_6GHZ, \
  308. .center_freq = (_freq), \
  309. .hw_value = (_freq), \
  310. }
  311. static const struct ieee80211_channel hwsim_channels_2ghz[] = {
  312. CHAN2G(2412), /* Channel 1 */
  313. CHAN2G(2417), /* Channel 2 */
  314. CHAN2G(2422), /* Channel 3 */
  315. CHAN2G(2427), /* Channel 4 */
  316. CHAN2G(2432), /* Channel 5 */
  317. CHAN2G(2437), /* Channel 6 */
  318. CHAN2G(2442), /* Channel 7 */
  319. CHAN2G(2447), /* Channel 8 */
  320. CHAN2G(2452), /* Channel 9 */
  321. CHAN2G(2457), /* Channel 10 */
  322. CHAN2G(2462), /* Channel 11 */
  323. CHAN2G(2467), /* Channel 12 */
  324. CHAN2G(2472), /* Channel 13 */
  325. CHAN2G(2484), /* Channel 14 */
  326. };
  327. static const struct ieee80211_channel hwsim_channels_5ghz[] = {
  328. CHAN5G(5180), /* Channel 36 */
  329. CHAN5G(5200), /* Channel 40 */
  330. CHAN5G(5220), /* Channel 44 */
  331. CHAN5G(5240), /* Channel 48 */
  332. CHAN5G(5260), /* Channel 52 */
  333. CHAN5G(5280), /* Channel 56 */
  334. CHAN5G(5300), /* Channel 60 */
  335. CHAN5G(5320), /* Channel 64 */
  336. CHAN5G(5500), /* Channel 100 */
  337. CHAN5G(5520), /* Channel 104 */
  338. CHAN5G(5540), /* Channel 108 */
  339. CHAN5G(5560), /* Channel 112 */
  340. CHAN5G(5580), /* Channel 116 */
  341. CHAN5G(5600), /* Channel 120 */
  342. CHAN5G(5620), /* Channel 124 */
  343. CHAN5G(5640), /* Channel 128 */
  344. CHAN5G(5660), /* Channel 132 */
  345. CHAN5G(5680), /* Channel 136 */
  346. CHAN5G(5700), /* Channel 140 */
  347. CHAN5G(5745), /* Channel 149 */
  348. CHAN5G(5765), /* Channel 153 */
  349. CHAN5G(5785), /* Channel 157 */
  350. CHAN5G(5805), /* Channel 161 */
  351. CHAN5G(5825), /* Channel 165 */
  352. CHAN5G(5845), /* Channel 169 */
  353. CHAN5G(5855), /* Channel 171 */
  354. CHAN5G(5860), /* Channel 172 */
  355. CHAN5G(5865), /* Channel 173 */
  356. CHAN5G(5870), /* Channel 174 */
  357. CHAN5G(5875), /* Channel 175 */
  358. CHAN5G(5880), /* Channel 176 */
  359. CHAN5G(5885), /* Channel 177 */
  360. CHAN5G(5890), /* Channel 178 */
  361. CHAN5G(5895), /* Channel 179 */
  362. CHAN5G(5900), /* Channel 180 */
  363. CHAN5G(5905), /* Channel 181 */
  364. CHAN5G(5910), /* Channel 182 */
  365. CHAN5G(5915), /* Channel 183 */
  366. CHAN5G(5920), /* Channel 184 */
  367. CHAN5G(5925), /* Channel 185 */
  368. };
  369. static const struct ieee80211_channel hwsim_channels_6ghz[] = {
  370. CHAN6G(5955), /* Channel 1 */
  371. CHAN6G(5975), /* Channel 5 */
  372. CHAN6G(5995), /* Channel 9 */
  373. CHAN6G(6015), /* Channel 13 */
  374. CHAN6G(6035), /* Channel 17 */
  375. CHAN6G(6055), /* Channel 21 */
  376. CHAN6G(6075), /* Channel 25 */
  377. CHAN6G(6095), /* Channel 29 */
  378. CHAN6G(6115), /* Channel 33 */
  379. CHAN6G(6135), /* Channel 37 */
  380. CHAN6G(6155), /* Channel 41 */
  381. CHAN6G(6175), /* Channel 45 */
  382. CHAN6G(6195), /* Channel 49 */
  383. CHAN6G(6215), /* Channel 53 */
  384. CHAN6G(6235), /* Channel 57 */
  385. CHAN6G(6255), /* Channel 61 */
  386. CHAN6G(6275), /* Channel 65 */
  387. CHAN6G(6295), /* Channel 69 */
  388. CHAN6G(6315), /* Channel 73 */
  389. CHAN6G(6335), /* Channel 77 */
  390. CHAN6G(6355), /* Channel 81 */
  391. CHAN6G(6375), /* Channel 85 */
  392. CHAN6G(6395), /* Channel 89 */
  393. CHAN6G(6415), /* Channel 93 */
  394. CHAN6G(6435), /* Channel 97 */
  395. CHAN6G(6455), /* Channel 181 */
  396. CHAN6G(6475), /* Channel 105 */
  397. CHAN6G(6495), /* Channel 109 */
  398. CHAN6G(6515), /* Channel 113 */
  399. CHAN6G(6535), /* Channel 117 */
  400. CHAN6G(6555), /* Channel 121 */
  401. CHAN6G(6575), /* Channel 125 */
  402. CHAN6G(6595), /* Channel 129 */
  403. CHAN6G(6615), /* Channel 133 */
  404. CHAN6G(6635), /* Channel 137 */
  405. CHAN6G(6655), /* Channel 141 */
  406. CHAN6G(6675), /* Channel 145 */
  407. CHAN6G(6695), /* Channel 149 */
  408. CHAN6G(6715), /* Channel 153 */
  409. CHAN6G(6735), /* Channel 157 */
  410. CHAN6G(6755), /* Channel 161 */
  411. CHAN6G(6775), /* Channel 165 */
  412. CHAN6G(6795), /* Channel 169 */
  413. CHAN6G(6815), /* Channel 173 */
  414. CHAN6G(6835), /* Channel 177 */
  415. CHAN6G(6855), /* Channel 181 */
  416. CHAN6G(6875), /* Channel 185 */
  417. CHAN6G(6895), /* Channel 189 */
  418. CHAN6G(6915), /* Channel 193 */
  419. CHAN6G(6935), /* Channel 197 */
  420. CHAN6G(6955), /* Channel 201 */
  421. CHAN6G(6975), /* Channel 205 */
  422. CHAN6G(6995), /* Channel 209 */
  423. CHAN6G(7015), /* Channel 213 */
  424. CHAN6G(7035), /* Channel 217 */
  425. CHAN6G(7055), /* Channel 221 */
  426. CHAN6G(7075), /* Channel 225 */
  427. CHAN6G(7095), /* Channel 229 */
  428. CHAN6G(7115), /* Channel 233 */
  429. };
  430. #define NUM_S1G_CHANS_US 51
  431. static struct ieee80211_channel hwsim_channels_s1g[NUM_S1G_CHANS_US];
  432. static const struct ieee80211_sta_s1g_cap hwsim_s1g_cap = {
  433. .s1g = true,
  434. .cap = { S1G_CAP0_SGI_1MHZ | S1G_CAP0_SGI_2MHZ,
  435. 0,
  436. 0,
  437. S1G_CAP3_MAX_MPDU_LEN,
  438. 0,
  439. S1G_CAP5_AMPDU,
  440. 0,
  441. S1G_CAP7_DUP_1MHZ,
  442. S1G_CAP8_TWT_RESPOND | S1G_CAP8_TWT_REQUEST,
  443. 0},
  444. .nss_mcs = { 0xfc | 1, /* MCS 7 for 1 SS */
  445. /* RX Highest Supported Long GI Data Rate 0:7 */
  446. 0,
  447. /* RX Highest Supported Long GI Data Rate 0:7 */
  448. /* TX S1G MCS Map 0:6 */
  449. 0xfa,
  450. /* TX S1G MCS Map :7 */
  451. /* TX Highest Supported Long GI Data Rate 0:6 */
  452. 0x80,
  453. /* TX Highest Supported Long GI Data Rate 7:8 */
  454. /* Rx Single spatial stream and S1G-MCS Map for 1MHz */
  455. /* Tx Single spatial stream and S1G-MCS Map for 1MHz */
  456. 0 },
  457. };
  458. static void hwsim_init_s1g_channels(struct ieee80211_channel *chans)
  459. {
  460. int ch, freq;
  461. for (ch = 0; ch < NUM_S1G_CHANS_US; ch++) {
  462. freq = 902000 + (ch + 1) * 500;
  463. chans[ch].band = NL80211_BAND_S1GHZ;
  464. chans[ch].center_freq = KHZ_TO_MHZ(freq);
  465. chans[ch].freq_offset = freq % 1000;
  466. chans[ch].hw_value = ch + 1;
  467. }
  468. }
  469. static const struct ieee80211_rate hwsim_rates[] = {
  470. { .bitrate = 10 },
  471. { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  472. { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  473. { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  474. { .bitrate = 60 },
  475. { .bitrate = 90 },
  476. { .bitrate = 120 },
  477. { .bitrate = 180 },
  478. { .bitrate = 240 },
  479. { .bitrate = 360 },
  480. { .bitrate = 480 },
  481. { .bitrate = 540 }
  482. };
  483. #define DEFAULT_RX_RSSI -50
  484. static const u32 hwsim_ciphers[] = {
  485. WLAN_CIPHER_SUITE_WEP40,
  486. WLAN_CIPHER_SUITE_WEP104,
  487. WLAN_CIPHER_SUITE_TKIP,
  488. WLAN_CIPHER_SUITE_CCMP,
  489. WLAN_CIPHER_SUITE_CCMP_256,
  490. WLAN_CIPHER_SUITE_GCMP,
  491. WLAN_CIPHER_SUITE_GCMP_256,
  492. WLAN_CIPHER_SUITE_AES_CMAC,
  493. WLAN_CIPHER_SUITE_BIP_CMAC_256,
  494. WLAN_CIPHER_SUITE_BIP_GMAC_128,
  495. WLAN_CIPHER_SUITE_BIP_GMAC_256,
  496. };
  497. #define OUI_QCA 0x001374
  498. #define QCA_NL80211_SUBCMD_TEST 1
  499. enum qca_nl80211_vendor_subcmds {
  500. QCA_WLAN_VENDOR_ATTR_TEST = 8,
  501. QCA_WLAN_VENDOR_ATTR_MAX = QCA_WLAN_VENDOR_ATTR_TEST
  502. };
  503. static const struct nla_policy
  504. hwsim_vendor_test_policy[QCA_WLAN_VENDOR_ATTR_MAX + 1] = {
  505. [QCA_WLAN_VENDOR_ATTR_MAX] = { .type = NLA_U32 },
  506. };
  507. static int mac80211_hwsim_vendor_cmd_test(struct wiphy *wiphy,
  508. struct wireless_dev *wdev,
  509. const void *data, int data_len)
  510. {
  511. struct sk_buff *skb;
  512. struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1];
  513. int err;
  514. u32 val;
  515. err = nla_parse_deprecated(tb, QCA_WLAN_VENDOR_ATTR_MAX, data,
  516. data_len, hwsim_vendor_test_policy, NULL);
  517. if (err)
  518. return err;
  519. if (!tb[QCA_WLAN_VENDOR_ATTR_TEST])
  520. return -EINVAL;
  521. val = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_TEST]);
  522. wiphy_dbg(wiphy, "%s: test=%u\n", __func__, val);
  523. /* Send a vendor event as a test. Note that this would not normally be
  524. * done within a command handler, but rather, based on some other
  525. * trigger. For simplicity, this command is used to trigger the event
  526. * here.
  527. *
  528. * event_idx = 0 (index in mac80211_hwsim_vendor_commands)
  529. */
  530. skb = cfg80211_vendor_event_alloc(wiphy, wdev, 100, 0, GFP_KERNEL);
  531. if (skb) {
  532. /* skb_put() or nla_put() will fill up data within
  533. * NL80211_ATTR_VENDOR_DATA.
  534. */
  535. /* Add vendor data */
  536. nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 1);
  537. /* Send the event - this will call nla_nest_end() */
  538. cfg80211_vendor_event(skb, GFP_KERNEL);
  539. }
  540. /* Send a response to the command */
  541. skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, 10);
  542. if (!skb)
  543. return -ENOMEM;
  544. /* skb_put() or nla_put() will fill up data within
  545. * NL80211_ATTR_VENDOR_DATA
  546. */
  547. nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 2);
  548. return cfg80211_vendor_cmd_reply(skb);
  549. }
  550. static struct wiphy_vendor_command mac80211_hwsim_vendor_commands[] = {
  551. {
  552. .info = { .vendor_id = OUI_QCA,
  553. .subcmd = QCA_NL80211_SUBCMD_TEST },
  554. .flags = WIPHY_VENDOR_CMD_NEED_NETDEV,
  555. .doit = mac80211_hwsim_vendor_cmd_test,
  556. .policy = hwsim_vendor_test_policy,
  557. .maxattr = QCA_WLAN_VENDOR_ATTR_MAX,
  558. }
  559. };
  560. /* Advertise support vendor specific events */
  561. static const struct nl80211_vendor_cmd_info mac80211_hwsim_vendor_events[] = {
  562. { .vendor_id = OUI_QCA, .subcmd = 1 },
  563. };
  564. static DEFINE_SPINLOCK(hwsim_radio_lock);
  565. static LIST_HEAD(hwsim_radios);
  566. static struct rhashtable hwsim_radios_rht;
  567. static int hwsim_radio_idx;
  568. static int hwsim_radios_generation = 1;
  569. static struct platform_driver mac80211_hwsim_driver = {
  570. .driver = {
  571. .name = "mac80211_hwsim",
  572. },
  573. };
  574. struct mac80211_hwsim_link_data {
  575. u32 link_id;
  576. u64 beacon_int /* beacon interval in us */;
  577. struct hrtimer beacon_timer;
  578. };
  579. struct mac80211_hwsim_data {
  580. struct list_head list;
  581. struct rhash_head rht;
  582. struct ieee80211_hw *hw;
  583. struct device *dev;
  584. struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
  585. struct ieee80211_channel channels_2ghz[ARRAY_SIZE(hwsim_channels_2ghz)];
  586. struct ieee80211_channel channels_5ghz[ARRAY_SIZE(hwsim_channels_5ghz)];
  587. struct ieee80211_channel channels_6ghz[ARRAY_SIZE(hwsim_channels_6ghz)];
  588. struct ieee80211_channel channels_s1g[ARRAY_SIZE(hwsim_channels_s1g)];
  589. struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)];
  590. struct ieee80211_iface_combination if_combination;
  591. struct ieee80211_iface_limit if_limits[3];
  592. int n_if_limits;
  593. struct ieee80211_iface_combination if_combination_radio;
  594. struct wiphy_radio_freq_range radio_range[NUM_NL80211_BANDS];
  595. struct wiphy_radio radio[NUM_NL80211_BANDS];
  596. u32 ciphers[ARRAY_SIZE(hwsim_ciphers)];
  597. struct mac_address addresses[2];
  598. int channels, idx;
  599. bool use_chanctx;
  600. bool destroy_on_close;
  601. u32 portid;
  602. char alpha2[2];
  603. const struct ieee80211_regdomain *regd;
  604. struct ieee80211_channel *tmp_chan;
  605. struct ieee80211_channel *roc_chan;
  606. u32 roc_duration;
  607. struct delayed_work roc_start;
  608. struct delayed_work roc_done;
  609. struct delayed_work hw_scan;
  610. struct cfg80211_scan_request *hw_scan_request;
  611. struct ieee80211_vif *hw_scan_vif;
  612. int scan_chan_idx;
  613. u8 scan_addr[ETH_ALEN];
  614. struct {
  615. struct ieee80211_channel *channel;
  616. unsigned long next_start, start, end;
  617. } survey_data[ARRAY_SIZE(hwsim_channels_2ghz) +
  618. ARRAY_SIZE(hwsim_channels_5ghz) +
  619. ARRAY_SIZE(hwsim_channels_6ghz)];
  620. struct ieee80211_channel *channel;
  621. enum nl80211_chan_width bw;
  622. unsigned int rx_filter;
  623. bool started, idle, scanning;
  624. struct mutex mutex;
  625. enum ps_mode {
  626. PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
  627. } ps;
  628. bool ps_poll_pending;
  629. struct dentry *debugfs;
  630. atomic_t pending_cookie;
  631. struct sk_buff_head pending; /* packets pending */
  632. /*
  633. * Only radios in the same group can communicate together (the
  634. * channel has to match too). Each bit represents a group. A
  635. * radio can be in more than one group.
  636. */
  637. u64 group;
  638. /* group shared by radios created in the same netns */
  639. int netgroup;
  640. /* wmediumd portid responsible for netgroup of this radio */
  641. u32 wmediumd;
  642. /* difference between this hw's clock and the real clock, in usecs */
  643. s64 tsf_offset;
  644. s64 bcn_delta;
  645. /* absolute beacon transmission time. Used to cover up "tx" delay. */
  646. u64 abs_bcn_ts;
  647. /* Stats */
  648. u64 tx_pkts;
  649. u64 rx_pkts;
  650. u64 tx_bytes;
  651. u64 rx_bytes;
  652. u64 tx_dropped;
  653. u64 tx_failed;
  654. /* RSSI in rx status of the receiver */
  655. int rx_rssi;
  656. /* only used when pmsr capability is supplied */
  657. struct cfg80211_pmsr_capabilities pmsr_capa;
  658. struct cfg80211_pmsr_request *pmsr_request;
  659. struct wireless_dev *pmsr_request_wdev;
  660. struct mac80211_hwsim_link_data link_data[IEEE80211_MLD_MAX_NUM_LINKS];
  661. };
  662. static const struct rhashtable_params hwsim_rht_params = {
  663. .nelem_hint = 2,
  664. .automatic_shrinking = true,
  665. .key_len = ETH_ALEN,
  666. .key_offset = offsetof(struct mac80211_hwsim_data, addresses[1]),
  667. .head_offset = offsetof(struct mac80211_hwsim_data, rht),
  668. };
  669. struct hwsim_radiotap_hdr {
  670. struct ieee80211_radiotap_header_fixed hdr;
  671. __le64 rt_tsft;
  672. u8 rt_flags;
  673. u8 rt_rate;
  674. __le16 rt_channel;
  675. __le16 rt_chbitmask;
  676. } __packed;
  677. struct hwsim_radiotap_ack_hdr {
  678. struct ieee80211_radiotap_header_fixed hdr;
  679. u8 rt_flags;
  680. u8 pad;
  681. __le16 rt_channel;
  682. __le16 rt_chbitmask;
  683. } __packed;
  684. static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr(const u8 *addr)
  685. {
  686. return rhashtable_lookup_fast(&hwsim_radios_rht, addr, hwsim_rht_params);
  687. }
  688. /* MAC80211_HWSIM netlink family */
  689. static struct genl_family hwsim_genl_family;
  690. enum hwsim_multicast_groups {
  691. HWSIM_MCGRP_CONFIG,
  692. };
  693. static const struct genl_multicast_group hwsim_mcgrps[] = {
  694. [HWSIM_MCGRP_CONFIG] = { .name = "config", },
  695. };
  696. /* MAC80211_HWSIM netlink policy */
  697. static const struct nla_policy
  698. hwsim_rate_info_policy[HWSIM_RATE_INFO_ATTR_MAX + 1] = {
  699. [HWSIM_RATE_INFO_ATTR_FLAGS] = { .type = NLA_U8 },
  700. [HWSIM_RATE_INFO_ATTR_MCS] = { .type = NLA_U8 },
  701. [HWSIM_RATE_INFO_ATTR_LEGACY] = { .type = NLA_U16 },
  702. [HWSIM_RATE_INFO_ATTR_NSS] = { .type = NLA_U8 },
  703. [HWSIM_RATE_INFO_ATTR_BW] = { .type = NLA_U8 },
  704. [HWSIM_RATE_INFO_ATTR_HE_GI] = { .type = NLA_U8 },
  705. [HWSIM_RATE_INFO_ATTR_HE_DCM] = { .type = NLA_U8 },
  706. [HWSIM_RATE_INFO_ATTR_HE_RU_ALLOC] = { .type = NLA_U8 },
  707. [HWSIM_RATE_INFO_ATTR_N_BOUNDED_CH] = { .type = NLA_U8 },
  708. [HWSIM_RATE_INFO_ATTR_EHT_GI] = { .type = NLA_U8 },
  709. [HWSIM_RATE_INFO_ATTR_EHT_RU_ALLOC] = { .type = NLA_U8 },
  710. };
  711. static const struct nla_policy
  712. hwsim_ftm_result_policy[NL80211_PMSR_FTM_RESP_ATTR_MAX + 1] = {
  713. [NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON] = { .type = NLA_U32 },
  714. [NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX] = { .type = NLA_U16 },
  715. [NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS] = { .type = NLA_U32 },
  716. [NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES] = { .type = NLA_U32 },
  717. [NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME] = { .type = NLA_U8 },
  718. [NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP] = { .type = NLA_U8 },
  719. [NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION] = { .type = NLA_U8 },
  720. [NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST] = { .type = NLA_U8 },
  721. [NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG] = { .type = NLA_U32 },
  722. [NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD] = { .type = NLA_U32 },
  723. [NL80211_PMSR_FTM_RESP_ATTR_TX_RATE] = NLA_POLICY_NESTED(hwsim_rate_info_policy),
  724. [NL80211_PMSR_FTM_RESP_ATTR_RX_RATE] = NLA_POLICY_NESTED(hwsim_rate_info_policy),
  725. [NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG] = { .type = NLA_U64 },
  726. [NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE] = { .type = NLA_U64 },
  727. [NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD] = { .type = NLA_U64 },
  728. [NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG] = { .type = NLA_U64 },
  729. [NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE] = { .type = NLA_U64 },
  730. [NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD] = { .type = NLA_U64 },
  731. [NL80211_PMSR_FTM_RESP_ATTR_LCI] = { .type = NLA_STRING },
  732. [NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_STRING },
  733. };
  734. static const struct nla_policy
  735. hwsim_pmsr_resp_type_policy[NL80211_PMSR_TYPE_MAX + 1] = {
  736. [NL80211_PMSR_TYPE_FTM] = NLA_POLICY_NESTED(hwsim_ftm_result_policy),
  737. };
  738. static const struct nla_policy
  739. hwsim_pmsr_resp_policy[NL80211_PMSR_RESP_ATTR_MAX + 1] = {
  740. [NL80211_PMSR_RESP_ATTR_STATUS] = { .type = NLA_U32 },
  741. [NL80211_PMSR_RESP_ATTR_HOST_TIME] = { .type = NLA_U64 },
  742. [NL80211_PMSR_RESP_ATTR_AP_TSF] = { .type = NLA_U64 },
  743. [NL80211_PMSR_RESP_ATTR_FINAL] = { .type = NLA_FLAG },
  744. [NL80211_PMSR_RESP_ATTR_DATA] = NLA_POLICY_NESTED(hwsim_pmsr_resp_type_policy),
  745. };
  746. static const struct nla_policy
  747. hwsim_pmsr_peer_result_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
  748. [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR_COMPAT,
  749. [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_REJECT },
  750. [NL80211_PMSR_PEER_ATTR_REQ] = { .type = NLA_REJECT },
  751. [NL80211_PMSR_PEER_ATTR_RESP] = NLA_POLICY_NESTED(hwsim_pmsr_resp_policy),
  752. };
  753. static const struct nla_policy
  754. hwsim_pmsr_peers_result_policy[NL80211_PMSR_ATTR_MAX + 1] = {
  755. [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
  756. [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
  757. [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
  758. [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
  759. [NL80211_PMSR_ATTR_PEERS] = NLA_POLICY_NESTED_ARRAY(hwsim_pmsr_peer_result_policy),
  760. };
  761. static const struct nla_policy
  762. hwsim_ftm_capa_policy[NL80211_PMSR_FTM_CAPA_ATTR_MAX + 1] = {
  763. [NL80211_PMSR_FTM_CAPA_ATTR_ASAP] = { .type = NLA_FLAG },
  764. [NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP] = { .type = NLA_FLAG },
  765. [NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI] = { .type = NLA_FLAG },
  766. [NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC] = { .type = NLA_FLAG },
  767. [NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES] = { .type = NLA_U32 },
  768. [NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS] = { .type = NLA_U32 },
  769. [NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT] = NLA_POLICY_MAX(NLA_U8, 15),
  770. [NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST] = NLA_POLICY_MAX(NLA_U8, 31),
  771. [NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG },
  772. [NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG },
  773. };
  774. static const struct nla_policy
  775. hwsim_pmsr_capa_type_policy[NL80211_PMSR_TYPE_MAX + 1] = {
  776. [NL80211_PMSR_TYPE_FTM] = NLA_POLICY_NESTED(hwsim_ftm_capa_policy),
  777. };
  778. static const struct nla_policy
  779. hwsim_pmsr_capa_policy[NL80211_PMSR_ATTR_MAX + 1] = {
  780. [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_U32 },
  781. [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_FLAG },
  782. [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_FLAG },
  783. [NL80211_PMSR_ATTR_TYPE_CAPA] = NLA_POLICY_NESTED(hwsim_pmsr_capa_type_policy),
  784. [NL80211_PMSR_ATTR_PEERS] = { .type = NLA_REJECT }, // only for request.
  785. };
  786. static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = {
  787. [HWSIM_ATTR_ADDR_RECEIVER] = NLA_POLICY_ETH_ADDR_COMPAT,
  788. [HWSIM_ATTR_ADDR_TRANSMITTER] = NLA_POLICY_ETH_ADDR_COMPAT,
  789. [HWSIM_ATTR_FRAME] = { .type = NLA_BINARY,
  790. .len = IEEE80211_MAX_DATA_LEN },
  791. [HWSIM_ATTR_FLAGS] = { .type = NLA_U32 },
  792. [HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 },
  793. [HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 },
  794. [HWSIM_ATTR_TX_INFO] = { .type = NLA_BINARY,
  795. .len = IEEE80211_TX_MAX_RATES *
  796. sizeof(struct hwsim_tx_rate)},
  797. [HWSIM_ATTR_COOKIE] = { .type = NLA_U64 },
  798. [HWSIM_ATTR_CHANNELS] = { .type = NLA_U32 },
  799. [HWSIM_ATTR_RADIO_ID] = { .type = NLA_U32 },
  800. [HWSIM_ATTR_REG_HINT_ALPHA2] = { .type = NLA_STRING, .len = 2 },
  801. [HWSIM_ATTR_REG_CUSTOM_REG] = { .type = NLA_U32 },
  802. [HWSIM_ATTR_REG_STRICT_REG] = { .type = NLA_FLAG },
  803. [HWSIM_ATTR_SUPPORT_P2P_DEVICE] = { .type = NLA_FLAG },
  804. [HWSIM_ATTR_USE_CHANCTX] = { .type = NLA_FLAG },
  805. [HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE] = { .type = NLA_FLAG },
  806. [HWSIM_ATTR_RADIO_NAME] = { .type = NLA_STRING },
  807. [HWSIM_ATTR_NO_VIF] = { .type = NLA_FLAG },
  808. [HWSIM_ATTR_FREQ] = { .type = NLA_U32 },
  809. [HWSIM_ATTR_TX_INFO_FLAGS] = { .type = NLA_BINARY },
  810. [HWSIM_ATTR_PERM_ADDR] = NLA_POLICY_ETH_ADDR_COMPAT,
  811. [HWSIM_ATTR_IFTYPE_SUPPORT] = { .type = NLA_U32 },
  812. [HWSIM_ATTR_CIPHER_SUPPORT] = { .type = NLA_BINARY },
  813. [HWSIM_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG },
  814. [HWSIM_ATTR_PMSR_SUPPORT] = NLA_POLICY_NESTED(hwsim_pmsr_capa_policy),
  815. [HWSIM_ATTR_PMSR_RESULT] = NLA_POLICY_NESTED(hwsim_pmsr_peers_result_policy),
  816. [HWSIM_ATTR_MULTI_RADIO] = { .type = NLA_FLAG },
  817. };
  818. #if IS_REACHABLE(CONFIG_VIRTIO)
  819. /* MAC80211_HWSIM virtio queues */
  820. static struct virtqueue *hwsim_vqs[HWSIM_NUM_VQS];
  821. static bool hwsim_virtio_enabled;
  822. static DEFINE_SPINLOCK(hwsim_virtio_lock);
  823. static void hwsim_virtio_rx_work(struct work_struct *work);
  824. static DECLARE_WORK(hwsim_virtio_rx, hwsim_virtio_rx_work);
  825. static int hwsim_tx_virtio(struct mac80211_hwsim_data *data,
  826. struct sk_buff *skb)
  827. {
  828. struct scatterlist sg[1];
  829. unsigned long flags;
  830. int err;
  831. spin_lock_irqsave(&hwsim_virtio_lock, flags);
  832. if (!hwsim_virtio_enabled) {
  833. err = -ENODEV;
  834. goto out_free;
  835. }
  836. sg_init_one(sg, skb->head, skb_end_offset(skb));
  837. err = virtqueue_add_outbuf(hwsim_vqs[HWSIM_VQ_TX], sg, 1, skb,
  838. GFP_ATOMIC);
  839. if (err)
  840. goto out_free;
  841. virtqueue_kick(hwsim_vqs[HWSIM_VQ_TX]);
  842. spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
  843. return 0;
  844. out_free:
  845. spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
  846. nlmsg_free(skb);
  847. return err;
  848. }
  849. #else
  850. /* cause a linker error if this ends up being needed */
  851. extern int hwsim_tx_virtio(struct mac80211_hwsim_data *data,
  852. struct sk_buff *skb);
  853. #define hwsim_virtio_enabled false
  854. #endif
  855. static int hwsim_get_chanwidth(enum nl80211_chan_width bw)
  856. {
  857. switch (bw) {
  858. case NL80211_CHAN_WIDTH_20_NOHT:
  859. case NL80211_CHAN_WIDTH_20:
  860. return 20;
  861. case NL80211_CHAN_WIDTH_40:
  862. return 40;
  863. case NL80211_CHAN_WIDTH_80:
  864. return 80;
  865. case NL80211_CHAN_WIDTH_80P80:
  866. case NL80211_CHAN_WIDTH_160:
  867. return 160;
  868. case NL80211_CHAN_WIDTH_320:
  869. return 320;
  870. case NL80211_CHAN_WIDTH_5:
  871. return 5;
  872. case NL80211_CHAN_WIDTH_10:
  873. return 10;
  874. case NL80211_CHAN_WIDTH_1:
  875. return 1;
  876. case NL80211_CHAN_WIDTH_2:
  877. return 2;
  878. case NL80211_CHAN_WIDTH_4:
  879. return 4;
  880. case NL80211_CHAN_WIDTH_8:
  881. return 8;
  882. case NL80211_CHAN_WIDTH_16:
  883. return 16;
  884. }
  885. return INT_MAX;
  886. }
  887. static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
  888. struct sk_buff *skb,
  889. struct ieee80211_channel *chan);
  890. /* sysfs attributes */
  891. static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif)
  892. {
  893. struct mac80211_hwsim_data *data = dat;
  894. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  895. struct sk_buff *skb;
  896. struct ieee80211_pspoll *pspoll;
  897. if (!vp->assoc)
  898. return;
  899. wiphy_dbg(data->hw->wiphy,
  900. "%s: send PS-Poll to %pM for aid %d\n",
  901. __func__, vp->bssid, vp->aid);
  902. skb = dev_alloc_skb(sizeof(*pspoll));
  903. if (!skb)
  904. return;
  905. pspoll = skb_put(skb, sizeof(*pspoll));
  906. pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  907. IEEE80211_STYPE_PSPOLL |
  908. IEEE80211_FCTL_PM);
  909. pspoll->aid = cpu_to_le16(0xc000 | vp->aid);
  910. memcpy(pspoll->bssid, vp->bssid, ETH_ALEN);
  911. memcpy(pspoll->ta, mac, ETH_ALEN);
  912. rcu_read_lock();
  913. mac80211_hwsim_tx_frame(data->hw, skb,
  914. rcu_dereference(vif->bss_conf.chanctx_conf)->def.chan);
  915. rcu_read_unlock();
  916. }
  917. static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac,
  918. struct ieee80211_vif *vif, int ps)
  919. {
  920. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  921. struct sk_buff *skb;
  922. struct ieee80211_hdr *hdr;
  923. struct ieee80211_tx_info *cb;
  924. if (!vp->assoc)
  925. return;
  926. wiphy_dbg(data->hw->wiphy,
  927. "%s: send data::nullfunc to %pM ps=%d\n",
  928. __func__, vp->bssid, ps);
  929. skb = dev_alloc_skb(sizeof(*hdr));
  930. if (!skb)
  931. return;
  932. hdr = skb_put(skb, sizeof(*hdr) - ETH_ALEN);
  933. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  934. IEEE80211_STYPE_NULLFUNC |
  935. IEEE80211_FCTL_TODS |
  936. (ps ? IEEE80211_FCTL_PM : 0));
  937. hdr->duration_id = cpu_to_le16(0);
  938. memcpy(hdr->addr1, vp->bssid, ETH_ALEN);
  939. memcpy(hdr->addr2, mac, ETH_ALEN);
  940. memcpy(hdr->addr3, vp->bssid, ETH_ALEN);
  941. cb = IEEE80211_SKB_CB(skb);
  942. cb->control.rates[0].count = 1;
  943. cb->control.rates[1].idx = -1;
  944. rcu_read_lock();
  945. mac80211_hwsim_tx_frame(data->hw, skb,
  946. rcu_dereference(vif->bss_conf.chanctx_conf)->def.chan);
  947. rcu_read_unlock();
  948. }
  949. static void hwsim_send_nullfunc_ps(void *dat, u8 *mac,
  950. struct ieee80211_vif *vif)
  951. {
  952. struct mac80211_hwsim_data *data = dat;
  953. hwsim_send_nullfunc(data, mac, vif, 1);
  954. }
  955. static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac,
  956. struct ieee80211_vif *vif)
  957. {
  958. struct mac80211_hwsim_data *data = dat;
  959. hwsim_send_nullfunc(data, mac, vif, 0);
  960. }
  961. static int hwsim_fops_ps_read(void *dat, u64 *val)
  962. {
  963. struct mac80211_hwsim_data *data = dat;
  964. *val = data->ps;
  965. return 0;
  966. }
  967. static int hwsim_fops_ps_write(void *dat, u64 val)
  968. {
  969. struct mac80211_hwsim_data *data = dat;
  970. enum ps_mode old_ps;
  971. if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL &&
  972. val != PS_MANUAL_POLL)
  973. return -EINVAL;
  974. if (val == PS_MANUAL_POLL) {
  975. if (data->ps != PS_ENABLED)
  976. return -EINVAL;
  977. local_bh_disable();
  978. ieee80211_iterate_active_interfaces_atomic(
  979. data->hw, IEEE80211_IFACE_ITER_NORMAL,
  980. hwsim_send_ps_poll, data);
  981. local_bh_enable();
  982. return 0;
  983. }
  984. old_ps = data->ps;
  985. data->ps = val;
  986. local_bh_disable();
  987. if (old_ps == PS_DISABLED && val != PS_DISABLED) {
  988. ieee80211_iterate_active_interfaces_atomic(
  989. data->hw, IEEE80211_IFACE_ITER_NORMAL,
  990. hwsim_send_nullfunc_ps, data);
  991. } else if (old_ps != PS_DISABLED && val == PS_DISABLED) {
  992. ieee80211_iterate_active_interfaces_atomic(
  993. data->hw, IEEE80211_IFACE_ITER_NORMAL,
  994. hwsim_send_nullfunc_no_ps, data);
  995. }
  996. local_bh_enable();
  997. return 0;
  998. }
  999. DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write,
  1000. "%llu\n");
  1001. static int hwsim_write_simulate_radar(void *dat, u64 val)
  1002. {
  1003. struct mac80211_hwsim_data *data = dat;
  1004. ieee80211_radar_detected(data->hw, NULL);
  1005. return 0;
  1006. }
  1007. DEFINE_DEBUGFS_ATTRIBUTE(hwsim_simulate_radar, NULL,
  1008. hwsim_write_simulate_radar, "%llu\n");
  1009. static int hwsim_fops_group_read(void *dat, u64 *val)
  1010. {
  1011. struct mac80211_hwsim_data *data = dat;
  1012. *val = data->group;
  1013. return 0;
  1014. }
  1015. static int hwsim_fops_group_write(void *dat, u64 val)
  1016. {
  1017. struct mac80211_hwsim_data *data = dat;
  1018. data->group = val;
  1019. return 0;
  1020. }
  1021. DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_group,
  1022. hwsim_fops_group_read, hwsim_fops_group_write,
  1023. "%llx\n");
  1024. static int hwsim_fops_rx_rssi_read(void *dat, u64 *val)
  1025. {
  1026. struct mac80211_hwsim_data *data = dat;
  1027. *val = data->rx_rssi;
  1028. return 0;
  1029. }
  1030. static int hwsim_fops_rx_rssi_write(void *dat, u64 val)
  1031. {
  1032. struct mac80211_hwsim_data *data = dat;
  1033. int rssi = (int)val;
  1034. if (rssi >= 0 || rssi < -100)
  1035. return -EINVAL;
  1036. data->rx_rssi = rssi;
  1037. return 0;
  1038. }
  1039. DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_rx_rssi,
  1040. hwsim_fops_rx_rssi_read, hwsim_fops_rx_rssi_write,
  1041. "%lld\n");
  1042. static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb,
  1043. struct net_device *dev)
  1044. {
  1045. /* TODO: allow packet injection */
  1046. dev_kfree_skb(skb);
  1047. return NETDEV_TX_OK;
  1048. }
  1049. static inline u64 mac80211_hwsim_get_tsf_raw(void)
  1050. {
  1051. return ktime_to_us(ktime_get_real());
  1052. }
  1053. static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data)
  1054. {
  1055. u64 now = mac80211_hwsim_get_tsf_raw();
  1056. return cpu_to_le64(now + data->tsf_offset);
  1057. }
  1058. static u64 mac80211_hwsim_get_tsf(struct ieee80211_hw *hw,
  1059. struct ieee80211_vif *vif)
  1060. {
  1061. struct mac80211_hwsim_data *data = hw->priv;
  1062. return le64_to_cpu(__mac80211_hwsim_get_tsf(data));
  1063. }
  1064. static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw,
  1065. struct ieee80211_vif *vif, u64 tsf)
  1066. {
  1067. struct mac80211_hwsim_data *data = hw->priv;
  1068. u64 now = mac80211_hwsim_get_tsf(hw, vif);
  1069. /* MLD not supported here */
  1070. u32 bcn_int = data->link_data[0].beacon_int;
  1071. u64 delta = abs(tsf - now);
  1072. struct ieee80211_bss_conf *conf;
  1073. conf = link_conf_dereference_protected(vif, data->link_data[0].link_id);
  1074. if (conf && !conf->enable_beacon)
  1075. return;
  1076. /* adjust after beaconing with new timestamp at old TBTT */
  1077. if (tsf > now) {
  1078. data->tsf_offset += delta;
  1079. data->bcn_delta = do_div(delta, bcn_int);
  1080. } else {
  1081. data->tsf_offset -= delta;
  1082. data->bcn_delta = -(s64)do_div(delta, bcn_int);
  1083. }
  1084. }
  1085. static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
  1086. struct sk_buff *tx_skb,
  1087. struct ieee80211_channel *chan)
  1088. {
  1089. struct mac80211_hwsim_data *data = hw->priv;
  1090. struct sk_buff *skb;
  1091. struct hwsim_radiotap_hdr *hdr;
  1092. u16 flags, bitrate;
  1093. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb);
  1094. struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info);
  1095. if (!txrate)
  1096. bitrate = 0;
  1097. else
  1098. bitrate = txrate->bitrate;
  1099. if (!netif_running(hwsim_mon))
  1100. return;
  1101. skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC);
  1102. if (skb == NULL)
  1103. return;
  1104. hdr = skb_push(skb, sizeof(*hdr));
  1105. hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  1106. hdr->hdr.it_pad = 0;
  1107. hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
  1108. hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  1109. (1 << IEEE80211_RADIOTAP_RATE) |
  1110. (1 << IEEE80211_RADIOTAP_TSFT) |
  1111. (1 << IEEE80211_RADIOTAP_CHANNEL));
  1112. hdr->rt_tsft = __mac80211_hwsim_get_tsf(data);
  1113. hdr->rt_flags = 0;
  1114. hdr->rt_rate = bitrate / 5;
  1115. hdr->rt_channel = cpu_to_le16(chan->center_freq);
  1116. flags = IEEE80211_CHAN_2GHZ;
  1117. if (txrate && txrate->flags & IEEE80211_RATE_ERP_G)
  1118. flags |= IEEE80211_CHAN_OFDM;
  1119. else
  1120. flags |= IEEE80211_CHAN_CCK;
  1121. hdr->rt_chbitmask = cpu_to_le16(flags);
  1122. skb->dev = hwsim_mon;
  1123. skb_reset_mac_header(skb);
  1124. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1125. skb->pkt_type = PACKET_OTHERHOST;
  1126. skb->protocol = htons(ETH_P_802_2);
  1127. memset(skb->cb, 0, sizeof(skb->cb));
  1128. netif_rx(skb);
  1129. }
  1130. static void mac80211_hwsim_monitor_ack(struct ieee80211_channel *chan,
  1131. const u8 *addr)
  1132. {
  1133. struct sk_buff *skb;
  1134. struct hwsim_radiotap_ack_hdr *hdr;
  1135. u16 flags;
  1136. struct ieee80211_hdr *hdr11;
  1137. if (!netif_running(hwsim_mon))
  1138. return;
  1139. skb = dev_alloc_skb(100);
  1140. if (skb == NULL)
  1141. return;
  1142. hdr = skb_put(skb, sizeof(*hdr));
  1143. hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  1144. hdr->hdr.it_pad = 0;
  1145. hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
  1146. hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  1147. (1 << IEEE80211_RADIOTAP_CHANNEL));
  1148. hdr->rt_flags = 0;
  1149. hdr->pad = 0;
  1150. hdr->rt_channel = cpu_to_le16(chan->center_freq);
  1151. flags = IEEE80211_CHAN_2GHZ;
  1152. hdr->rt_chbitmask = cpu_to_le16(flags);
  1153. hdr11 = skb_put(skb, 10);
  1154. hdr11->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  1155. IEEE80211_STYPE_ACK);
  1156. hdr11->duration_id = cpu_to_le16(0);
  1157. memcpy(hdr11->addr1, addr, ETH_ALEN);
  1158. skb->dev = hwsim_mon;
  1159. skb_reset_mac_header(skb);
  1160. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1161. skb->pkt_type = PACKET_OTHERHOST;
  1162. skb->protocol = htons(ETH_P_802_2);
  1163. memset(skb->cb, 0, sizeof(skb->cb));
  1164. netif_rx(skb);
  1165. }
  1166. struct mac80211_hwsim_addr_match_data {
  1167. u8 addr[ETH_ALEN];
  1168. bool ret;
  1169. };
  1170. static void mac80211_hwsim_addr_iter(void *data, u8 *mac,
  1171. struct ieee80211_vif *vif)
  1172. {
  1173. int i;
  1174. struct mac80211_hwsim_addr_match_data *md = data;
  1175. if (memcmp(mac, md->addr, ETH_ALEN) == 0) {
  1176. md->ret = true;
  1177. return;
  1178. }
  1179. /* Match the link address */
  1180. for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) {
  1181. struct ieee80211_bss_conf *conf;
  1182. conf = rcu_dereference(vif->link_conf[i]);
  1183. if (!conf)
  1184. continue;
  1185. if (memcmp(conf->addr, md->addr, ETH_ALEN) == 0) {
  1186. md->ret = true;
  1187. return;
  1188. }
  1189. }
  1190. }
  1191. static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data *data,
  1192. const u8 *addr)
  1193. {
  1194. struct mac80211_hwsim_addr_match_data md = {
  1195. .ret = false,
  1196. };
  1197. if (data->scanning && memcmp(addr, data->scan_addr, ETH_ALEN) == 0)
  1198. return true;
  1199. memcpy(md.addr, addr, ETH_ALEN);
  1200. ieee80211_iterate_active_interfaces_atomic(data->hw,
  1201. IEEE80211_IFACE_ITER_NORMAL,
  1202. mac80211_hwsim_addr_iter,
  1203. &md);
  1204. return md.ret;
  1205. }
  1206. static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data,
  1207. struct sk_buff *skb)
  1208. {
  1209. switch (data->ps) {
  1210. case PS_DISABLED:
  1211. return true;
  1212. case PS_ENABLED:
  1213. return false;
  1214. case PS_AUTO_POLL:
  1215. /* TODO: accept (some) Beacons by default and other frames only
  1216. * if pending PS-Poll has been sent */
  1217. return true;
  1218. case PS_MANUAL_POLL:
  1219. /* Allow unicast frames to own address if there is a pending
  1220. * PS-Poll */
  1221. if (data->ps_poll_pending &&
  1222. mac80211_hwsim_addr_match(data, skb->data + 4)) {
  1223. data->ps_poll_pending = false;
  1224. return true;
  1225. }
  1226. return false;
  1227. }
  1228. return true;
  1229. }
  1230. static int hwsim_unicast_netgroup(struct mac80211_hwsim_data *data,
  1231. struct sk_buff *skb, int portid)
  1232. {
  1233. struct net *net;
  1234. bool found = false;
  1235. int res = -ENOENT;
  1236. rcu_read_lock();
  1237. for_each_net_rcu(net) {
  1238. if (data->netgroup == hwsim_net_get_netgroup(net)) {
  1239. res = genlmsg_unicast(net, skb, portid);
  1240. found = true;
  1241. break;
  1242. }
  1243. }
  1244. rcu_read_unlock();
  1245. if (!found)
  1246. nlmsg_free(skb);
  1247. return res;
  1248. }
  1249. static void mac80211_hwsim_config_mac_nl(struct ieee80211_hw *hw,
  1250. const u8 *addr, bool add)
  1251. {
  1252. struct mac80211_hwsim_data *data = hw->priv;
  1253. u32 _portid = READ_ONCE(data->wmediumd);
  1254. struct sk_buff *skb;
  1255. void *msg_head;
  1256. WARN_ON(!is_valid_ether_addr(addr));
  1257. if (!_portid && !hwsim_virtio_enabled)
  1258. return;
  1259. skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  1260. if (!skb)
  1261. return;
  1262. msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
  1263. add ? HWSIM_CMD_ADD_MAC_ADDR :
  1264. HWSIM_CMD_DEL_MAC_ADDR);
  1265. if (!msg_head) {
  1266. pr_debug("mac80211_hwsim: problem with msg_head\n");
  1267. goto nla_put_failure;
  1268. }
  1269. if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
  1270. ETH_ALEN, data->addresses[1].addr))
  1271. goto nla_put_failure;
  1272. if (nla_put(skb, HWSIM_ATTR_ADDR_RECEIVER, ETH_ALEN, addr))
  1273. goto nla_put_failure;
  1274. genlmsg_end(skb, msg_head);
  1275. if (hwsim_virtio_enabled)
  1276. hwsim_tx_virtio(data, skb);
  1277. else
  1278. hwsim_unicast_netgroup(data, skb, _portid);
  1279. return;
  1280. nla_put_failure:
  1281. nlmsg_free(skb);
  1282. }
  1283. static inline u16 trans_tx_rate_flags_ieee2hwsim(struct ieee80211_tx_rate *rate)
  1284. {
  1285. u16 result = 0;
  1286. if (rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
  1287. result |= MAC80211_HWSIM_TX_RC_USE_RTS_CTS;
  1288. if (rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  1289. result |= MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT;
  1290. if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  1291. result |= MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE;
  1292. if (rate->flags & IEEE80211_TX_RC_MCS)
  1293. result |= MAC80211_HWSIM_TX_RC_MCS;
  1294. if (rate->flags & IEEE80211_TX_RC_GREEN_FIELD)
  1295. result |= MAC80211_HWSIM_TX_RC_GREEN_FIELD;
  1296. if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  1297. result |= MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH;
  1298. if (rate->flags & IEEE80211_TX_RC_DUP_DATA)
  1299. result |= MAC80211_HWSIM_TX_RC_DUP_DATA;
  1300. if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  1301. result |= MAC80211_HWSIM_TX_RC_SHORT_GI;
  1302. if (rate->flags & IEEE80211_TX_RC_VHT_MCS)
  1303. result |= MAC80211_HWSIM_TX_RC_VHT_MCS;
  1304. if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  1305. result |= MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH;
  1306. if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  1307. result |= MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH;
  1308. return result;
  1309. }
  1310. static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
  1311. struct sk_buff *my_skb,
  1312. int dst_portid,
  1313. struct ieee80211_channel *channel)
  1314. {
  1315. struct sk_buff *skb;
  1316. struct mac80211_hwsim_data *data = hw->priv;
  1317. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) my_skb->data;
  1318. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(my_skb);
  1319. void *msg_head;
  1320. unsigned int hwsim_flags = 0;
  1321. int i;
  1322. struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES];
  1323. struct hwsim_tx_rate_flag tx_attempts_flags[IEEE80211_TX_MAX_RATES];
  1324. uintptr_t cookie;
  1325. if (data->ps != PS_DISABLED)
  1326. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  1327. /* If the queue contains MAX_QUEUE skb's drop some */
  1328. if (skb_queue_len(&data->pending) >= MAX_QUEUE) {
  1329. /* Dropping until WARN_QUEUE level */
  1330. while (skb_queue_len(&data->pending) >= WARN_QUEUE) {
  1331. ieee80211_free_txskb(hw, skb_dequeue(&data->pending));
  1332. data->tx_dropped++;
  1333. }
  1334. }
  1335. skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  1336. if (skb == NULL)
  1337. goto nla_put_failure;
  1338. msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
  1339. HWSIM_CMD_FRAME);
  1340. if (msg_head == NULL) {
  1341. pr_debug("mac80211_hwsim: problem with msg_head\n");
  1342. goto nla_put_failure;
  1343. }
  1344. if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
  1345. ETH_ALEN, data->addresses[1].addr))
  1346. goto nla_put_failure;
  1347. /* We get the skb->data */
  1348. if (nla_put(skb, HWSIM_ATTR_FRAME, my_skb->len, my_skb->data))
  1349. goto nla_put_failure;
  1350. /* We get the flags for this transmission, and we translate them to
  1351. wmediumd flags */
  1352. if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)
  1353. hwsim_flags |= HWSIM_TX_CTL_REQ_TX_STATUS;
  1354. if (info->flags & IEEE80211_TX_CTL_NO_ACK)
  1355. hwsim_flags |= HWSIM_TX_CTL_NO_ACK;
  1356. if (nla_put_u32(skb, HWSIM_ATTR_FLAGS, hwsim_flags))
  1357. goto nla_put_failure;
  1358. if (nla_put_u32(skb, HWSIM_ATTR_FREQ, channel->center_freq))
  1359. goto nla_put_failure;
  1360. /* We get the tx control (rate and retries) info*/
  1361. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  1362. tx_attempts[i].idx = info->status.rates[i].idx;
  1363. tx_attempts_flags[i].idx = info->status.rates[i].idx;
  1364. tx_attempts[i].count = info->status.rates[i].count;
  1365. tx_attempts_flags[i].flags =
  1366. trans_tx_rate_flags_ieee2hwsim(
  1367. &info->status.rates[i]);
  1368. }
  1369. if (nla_put(skb, HWSIM_ATTR_TX_INFO,
  1370. sizeof(struct hwsim_tx_rate)*IEEE80211_TX_MAX_RATES,
  1371. tx_attempts))
  1372. goto nla_put_failure;
  1373. if (nla_put(skb, HWSIM_ATTR_TX_INFO_FLAGS,
  1374. sizeof(struct hwsim_tx_rate_flag) * IEEE80211_TX_MAX_RATES,
  1375. tx_attempts_flags))
  1376. goto nla_put_failure;
  1377. /* We create a cookie to identify this skb */
  1378. cookie = atomic_inc_return(&data->pending_cookie);
  1379. info->rate_driver_data[0] = (void *)cookie;
  1380. if (nla_put_u64_64bit(skb, HWSIM_ATTR_COOKIE, cookie, HWSIM_ATTR_PAD))
  1381. goto nla_put_failure;
  1382. genlmsg_end(skb, msg_head);
  1383. if (hwsim_virtio_enabled) {
  1384. if (hwsim_tx_virtio(data, skb))
  1385. goto err_free_txskb;
  1386. } else {
  1387. if (hwsim_unicast_netgroup(data, skb, dst_portid))
  1388. goto err_free_txskb;
  1389. }
  1390. /* Enqueue the packet */
  1391. skb_queue_tail(&data->pending, my_skb);
  1392. data->tx_pkts++;
  1393. data->tx_bytes += my_skb->len;
  1394. return;
  1395. nla_put_failure:
  1396. nlmsg_free(skb);
  1397. err_free_txskb:
  1398. pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
  1399. ieee80211_free_txskb(hw, my_skb);
  1400. data->tx_failed++;
  1401. }
  1402. static bool hwsim_chans_compat(struct ieee80211_channel *c1,
  1403. struct ieee80211_channel *c2)
  1404. {
  1405. if (!c1 || !c2)
  1406. return false;
  1407. return c1->center_freq == c2->center_freq;
  1408. }
  1409. struct tx_iter_data {
  1410. struct ieee80211_channel *channel;
  1411. bool receive;
  1412. };
  1413. static void mac80211_hwsim_tx_iter(void *_data, u8 *addr,
  1414. struct ieee80211_vif *vif)
  1415. {
  1416. struct tx_iter_data *data = _data;
  1417. int i;
  1418. for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) {
  1419. struct ieee80211_bss_conf *conf;
  1420. struct ieee80211_chanctx_conf *chanctx;
  1421. conf = rcu_dereference(vif->link_conf[i]);
  1422. if (!conf)
  1423. continue;
  1424. chanctx = rcu_dereference(conf->chanctx_conf);
  1425. if (!chanctx)
  1426. continue;
  1427. if (!hwsim_chans_compat(data->channel, chanctx->def.chan))
  1428. continue;
  1429. data->receive = true;
  1430. return;
  1431. }
  1432. }
  1433. static void mac80211_hwsim_add_vendor_rtap(struct sk_buff *skb)
  1434. {
  1435. /*
  1436. * To enable this code, #define the HWSIM_RADIOTAP_OUI,
  1437. * e.g. like this:
  1438. * #define HWSIM_RADIOTAP_OUI "\x02\x00\x00"
  1439. * (but you should use a valid OUI, not that)
  1440. *
  1441. * If anyone wants to 'donate' a radiotap OUI/subns code
  1442. * please send a patch removing this #ifdef and changing
  1443. * the values accordingly.
  1444. */
  1445. #ifdef HWSIM_RADIOTAP_OUI
  1446. struct ieee80211_radiotap_vendor_tlv *rtap;
  1447. static const char vendor_data[8] = "ABCDEFGH";
  1448. // Make sure no padding is needed
  1449. BUILD_BUG_ON(sizeof(vendor_data) % 4);
  1450. /* this is last radiotap info before the mac header, so
  1451. * skb_reset_mac_header for mac8022 to know the end of
  1452. * the radiotap TLV/beginning of the 802.11 header
  1453. */
  1454. skb_reset_mac_header(skb);
  1455. /*
  1456. * Note that this code requires the headroom in the SKB
  1457. * that was allocated earlier.
  1458. */
  1459. rtap = skb_push(skb, sizeof(*rtap) + sizeof(vendor_data));
  1460. rtap->len = cpu_to_le16(sizeof(*rtap) -
  1461. sizeof(struct ieee80211_radiotap_tlv) +
  1462. sizeof(vendor_data));
  1463. rtap->type = cpu_to_le16(IEEE80211_RADIOTAP_VENDOR_NAMESPACE);
  1464. rtap->content.oui[0] = HWSIM_RADIOTAP_OUI[0];
  1465. rtap->content.oui[1] = HWSIM_RADIOTAP_OUI[1];
  1466. rtap->content.oui[2] = HWSIM_RADIOTAP_OUI[2];
  1467. rtap->content.oui_subtype = 127;
  1468. /* clear reserved field */
  1469. rtap->content.reserved = 0;
  1470. rtap->content.vendor_type = 0;
  1471. memcpy(rtap->content.data, vendor_data, sizeof(vendor_data));
  1472. IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_RADIOTAP_TLV_AT_END;
  1473. #endif
  1474. }
  1475. static void mac80211_hwsim_rx(struct mac80211_hwsim_data *data,
  1476. struct ieee80211_rx_status *rx_status,
  1477. struct sk_buff *skb)
  1478. {
  1479. struct ieee80211_hdr *hdr = (void *)skb->data;
  1480. if (!ieee80211_has_morefrags(hdr->frame_control) &&
  1481. !is_multicast_ether_addr(hdr->addr1) &&
  1482. (ieee80211_is_mgmt(hdr->frame_control) ||
  1483. ieee80211_is_data(hdr->frame_control))) {
  1484. struct ieee80211_sta *sta;
  1485. unsigned int link_id;
  1486. rcu_read_lock();
  1487. sta = ieee80211_find_sta_by_link_addrs(data->hw, hdr->addr2,
  1488. hdr->addr1, &link_id);
  1489. if (sta) {
  1490. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  1491. if (ieee80211_has_pm(hdr->frame_control))
  1492. sp->active_links_rx &= ~BIT(link_id);
  1493. else
  1494. sp->active_links_rx |= BIT(link_id);
  1495. rx_status->link_valid = true;
  1496. rx_status->link_id = link_id;
  1497. }
  1498. rcu_read_unlock();
  1499. }
  1500. memcpy(IEEE80211_SKB_RXCB(skb), rx_status, sizeof(*rx_status));
  1501. mac80211_hwsim_add_vendor_rtap(skb);
  1502. data->rx_pkts++;
  1503. data->rx_bytes += skb->len;
  1504. ieee80211_rx_irqsafe(data->hw, skb);
  1505. }
  1506. static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw,
  1507. struct sk_buff *skb,
  1508. struct ieee80211_channel *chan)
  1509. {
  1510. struct mac80211_hwsim_data *data = hw->priv, *data2;
  1511. bool ack = false;
  1512. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1513. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1514. struct ieee80211_rx_status rx_status;
  1515. u64 now;
  1516. memset(&rx_status, 0, sizeof(rx_status));
  1517. rx_status.flag |= RX_FLAG_MACTIME_START;
  1518. rx_status.freq = chan->center_freq;
  1519. rx_status.freq_offset = chan->freq_offset ? 1 : 0;
  1520. rx_status.band = chan->band;
  1521. if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
  1522. rx_status.rate_idx =
  1523. ieee80211_rate_get_vht_mcs(&info->control.rates[0]);
  1524. rx_status.nss =
  1525. ieee80211_rate_get_vht_nss(&info->control.rates[0]);
  1526. rx_status.encoding = RX_ENC_VHT;
  1527. } else {
  1528. rx_status.rate_idx = info->control.rates[0].idx;
  1529. if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  1530. rx_status.encoding = RX_ENC_HT;
  1531. }
  1532. if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  1533. rx_status.bw = RATE_INFO_BW_40;
  1534. else if (info->control.rates[0].flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  1535. rx_status.bw = RATE_INFO_BW_80;
  1536. else if (info->control.rates[0].flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  1537. rx_status.bw = RATE_INFO_BW_160;
  1538. else
  1539. rx_status.bw = RATE_INFO_BW_20;
  1540. if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
  1541. rx_status.enc_flags |= RX_ENC_FLAG_SHORT_GI;
  1542. /* TODO: simulate optional packet loss */
  1543. rx_status.signal = data->rx_rssi;
  1544. if (info->control.vif)
  1545. rx_status.signal += info->control.vif->bss_conf.txpower;
  1546. if (data->ps != PS_DISABLED)
  1547. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  1548. /* release the skb's source info */
  1549. skb_orphan(skb);
  1550. skb_dst_drop(skb);
  1551. skb->mark = 0;
  1552. skb_ext_reset(skb);
  1553. nf_reset_ct(skb);
  1554. /*
  1555. * Get absolute mactime here so all HWs RX at the "same time", and
  1556. * absolute TX time for beacon mactime so the timestamp matches.
  1557. * Giving beacons a different mactime than non-beacons looks messy, but
  1558. * it helps the Toffset be exact and a ~10us mactime discrepancy
  1559. * probably doesn't really matter.
  1560. */
  1561. if (ieee80211_is_beacon(hdr->frame_control) ||
  1562. ieee80211_is_probe_resp(hdr->frame_control)) {
  1563. rx_status.boottime_ns = ktime_get_boottime_ns();
  1564. now = data->abs_bcn_ts;
  1565. } else {
  1566. now = mac80211_hwsim_get_tsf_raw();
  1567. }
  1568. /* Copy skb to all enabled radios that are on the current frequency */
  1569. spin_lock(&hwsim_radio_lock);
  1570. list_for_each_entry(data2, &hwsim_radios, list) {
  1571. struct sk_buff *nskb;
  1572. struct tx_iter_data tx_iter_data = {
  1573. .receive = false,
  1574. .channel = chan,
  1575. };
  1576. if (data == data2)
  1577. continue;
  1578. if (!data2->started || (data2->idle && !data2->tmp_chan) ||
  1579. !hwsim_ps_rx_ok(data2, skb))
  1580. continue;
  1581. if (!(data->group & data2->group))
  1582. continue;
  1583. if (data->netgroup != data2->netgroup)
  1584. continue;
  1585. if (!hwsim_chans_compat(chan, data2->tmp_chan) &&
  1586. !hwsim_chans_compat(chan, data2->channel)) {
  1587. ieee80211_iterate_active_interfaces_atomic(
  1588. data2->hw, IEEE80211_IFACE_ITER_NORMAL,
  1589. mac80211_hwsim_tx_iter, &tx_iter_data);
  1590. if (!tx_iter_data.receive)
  1591. continue;
  1592. }
  1593. /*
  1594. * reserve some space for our vendor and the normal
  1595. * radiotap header, since we're copying anyway
  1596. */
  1597. if (skb->len < PAGE_SIZE && paged_rx) {
  1598. struct page *page = alloc_page(GFP_ATOMIC);
  1599. if (!page)
  1600. continue;
  1601. nskb = dev_alloc_skb(128);
  1602. if (!nskb) {
  1603. __free_page(page);
  1604. continue;
  1605. }
  1606. memcpy(page_address(page), skb->data, skb->len);
  1607. skb_add_rx_frag(nskb, 0, page, 0, skb->len, skb->len);
  1608. } else {
  1609. nskb = skb_copy(skb, GFP_ATOMIC);
  1610. if (!nskb)
  1611. continue;
  1612. }
  1613. if (mac80211_hwsim_addr_match(data2, hdr->addr1))
  1614. ack = true;
  1615. rx_status.mactime = now + data2->tsf_offset;
  1616. mac80211_hwsim_rx(data2, &rx_status, nskb);
  1617. }
  1618. spin_unlock(&hwsim_radio_lock);
  1619. return ack;
  1620. }
  1621. static struct ieee80211_bss_conf *
  1622. mac80211_hwsim_select_tx_link(struct mac80211_hwsim_data *data,
  1623. struct ieee80211_vif *vif,
  1624. struct ieee80211_sta *sta,
  1625. struct ieee80211_hdr *hdr,
  1626. struct ieee80211_link_sta **link_sta)
  1627. {
  1628. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  1629. int i;
  1630. if (!ieee80211_vif_is_mld(vif))
  1631. return &vif->bss_conf;
  1632. WARN_ON(is_multicast_ether_addr(hdr->addr1));
  1633. if (WARN_ON_ONCE(!sta || !sta->valid_links))
  1634. return &vif->bss_conf;
  1635. for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) {
  1636. struct ieee80211_bss_conf *bss_conf;
  1637. unsigned int link_id;
  1638. /* round-robin the available link IDs */
  1639. link_id = (sp->last_link + i + 1) % ARRAY_SIZE(vif->link_conf);
  1640. if (!(vif->active_links & BIT(link_id)))
  1641. continue;
  1642. if (!(sp->active_links_rx & BIT(link_id)))
  1643. continue;
  1644. *link_sta = rcu_dereference(sta->link[link_id]);
  1645. if (!*link_sta)
  1646. continue;
  1647. bss_conf = rcu_dereference(vif->link_conf[link_id]);
  1648. if (WARN_ON_ONCE(!bss_conf))
  1649. continue;
  1650. /* can happen while switching links */
  1651. if (!rcu_access_pointer(bss_conf->chanctx_conf))
  1652. continue;
  1653. sp->last_link = link_id;
  1654. return bss_conf;
  1655. }
  1656. return NULL;
  1657. }
  1658. static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
  1659. struct ieee80211_tx_control *control,
  1660. struct sk_buff *skb)
  1661. {
  1662. struct mac80211_hwsim_data *data = hw->priv;
  1663. struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
  1664. struct ieee80211_hdr *hdr = (void *)skb->data;
  1665. struct ieee80211_chanctx_conf *chanctx_conf;
  1666. struct ieee80211_channel *channel;
  1667. bool ack;
  1668. enum nl80211_chan_width confbw = NL80211_CHAN_WIDTH_20_NOHT;
  1669. u32 _portid, i;
  1670. if (WARN_ON(skb->len < 10)) {
  1671. /* Should not happen; just a sanity check for addr1 use */
  1672. ieee80211_free_txskb(hw, skb);
  1673. return;
  1674. }
  1675. if (!data->use_chanctx) {
  1676. channel = data->channel;
  1677. confbw = data->bw;
  1678. } else if (txi->hw_queue == 4) {
  1679. channel = data->tmp_chan;
  1680. } else {
  1681. u8 link = u32_get_bits(IEEE80211_SKB_CB(skb)->control.flags,
  1682. IEEE80211_TX_CTRL_MLO_LINK);
  1683. struct ieee80211_vif *vif = txi->control.vif;
  1684. struct ieee80211_link_sta *link_sta = NULL;
  1685. struct ieee80211_sta *sta = control->sta;
  1686. struct ieee80211_bss_conf *bss_conf;
  1687. if (link != IEEE80211_LINK_UNSPECIFIED) {
  1688. bss_conf = rcu_dereference(txi->control.vif->link_conf[link]);
  1689. if (sta)
  1690. link_sta = rcu_dereference(sta->link[link]);
  1691. } else {
  1692. bss_conf = mac80211_hwsim_select_tx_link(data, vif, sta,
  1693. hdr, &link_sta);
  1694. }
  1695. if (unlikely(!bss_conf)) {
  1696. /* if it's an MLO STA, it might have deactivated all
  1697. * links temporarily - but we don't handle real PS in
  1698. * this code yet, so just drop the frame in that case
  1699. */
  1700. WARN(link != IEEE80211_LINK_UNSPECIFIED || !sta || !sta->mlo,
  1701. "link:%d, sta:%pM, sta->mlo:%d\n",
  1702. link, sta ? sta->addr : NULL, sta ? sta->mlo : -1);
  1703. ieee80211_free_txskb(hw, skb);
  1704. return;
  1705. }
  1706. /* Do address translations only between shared links. It is
  1707. * possible that while an non-AP MLD station and an AP MLD
  1708. * station have shared links, the frame is intended to be sent
  1709. * on a link which is not shared (for example when sending a
  1710. * probe response).
  1711. */
  1712. if (sta && sta->mlo && link_sta) {
  1713. /* address translation to link addresses on TX */
  1714. ether_addr_copy(hdr->addr1, link_sta->addr);
  1715. ether_addr_copy(hdr->addr2, bss_conf->addr);
  1716. /* translate A3 only if it's the BSSID */
  1717. if (!ieee80211_has_tods(hdr->frame_control) &&
  1718. !ieee80211_has_fromds(hdr->frame_control)) {
  1719. if (ether_addr_equal(hdr->addr3, sta->addr))
  1720. ether_addr_copy(hdr->addr3, link_sta->addr);
  1721. else if (ether_addr_equal(hdr->addr3, vif->addr))
  1722. ether_addr_copy(hdr->addr3, bss_conf->addr);
  1723. }
  1724. /* no need to look at A4, if present it's SA */
  1725. }
  1726. chanctx_conf = rcu_dereference(bss_conf->chanctx_conf);
  1727. if (chanctx_conf) {
  1728. channel = chanctx_conf->def.chan;
  1729. confbw = chanctx_conf->def.width;
  1730. } else {
  1731. channel = NULL;
  1732. }
  1733. }
  1734. if (WARN(!channel, "TX w/o channel - queue = %d\n", txi->hw_queue)) {
  1735. ieee80211_free_txskb(hw, skb);
  1736. return;
  1737. }
  1738. if (data->idle && !data->tmp_chan) {
  1739. wiphy_dbg(hw->wiphy, "Trying to TX when idle - reject\n");
  1740. ieee80211_free_txskb(hw, skb);
  1741. return;
  1742. }
  1743. if (txi->control.vif)
  1744. hwsim_check_magic(txi->control.vif);
  1745. if (control->sta)
  1746. hwsim_check_sta_magic(control->sta);
  1747. if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE))
  1748. ieee80211_get_tx_rates(txi->control.vif, control->sta, skb,
  1749. txi->control.rates,
  1750. ARRAY_SIZE(txi->control.rates));
  1751. for (i = 0; i < ARRAY_SIZE(txi->control.rates); i++) {
  1752. u16 rflags = txi->control.rates[i].flags;
  1753. /* initialize to data->bw for 5/10 MHz handling */
  1754. enum nl80211_chan_width bw = data->bw;
  1755. if (txi->control.rates[i].idx == -1)
  1756. break;
  1757. if (rflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  1758. bw = NL80211_CHAN_WIDTH_40;
  1759. else if (rflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  1760. bw = NL80211_CHAN_WIDTH_80;
  1761. else if (rflags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  1762. bw = NL80211_CHAN_WIDTH_160;
  1763. if (WARN_ON(hwsim_get_chanwidth(bw) > hwsim_get_chanwidth(confbw)))
  1764. return;
  1765. }
  1766. if (skb->len >= 24 + 8 &&
  1767. ieee80211_is_probe_resp(hdr->frame_control)) {
  1768. /* fake header transmission time */
  1769. struct ieee80211_mgmt *mgmt;
  1770. struct ieee80211_rate *txrate;
  1771. /* TODO: get MCS */
  1772. int bitrate = 100;
  1773. u64 ts;
  1774. mgmt = (struct ieee80211_mgmt *)skb->data;
  1775. txrate = ieee80211_get_tx_rate(hw, txi);
  1776. if (txrate)
  1777. bitrate = txrate->bitrate;
  1778. ts = mac80211_hwsim_get_tsf_raw();
  1779. mgmt->u.probe_resp.timestamp =
  1780. cpu_to_le64(ts + data->tsf_offset +
  1781. 24 * 8 * 10 / bitrate);
  1782. }
  1783. mac80211_hwsim_monitor_rx(hw, skb, channel);
  1784. /* wmediumd mode check */
  1785. _portid = READ_ONCE(data->wmediumd);
  1786. if (_portid || hwsim_virtio_enabled)
  1787. return mac80211_hwsim_tx_frame_nl(hw, skb, _portid, channel);
  1788. /* NO wmediumd detected, perfect medium simulation */
  1789. data->tx_pkts++;
  1790. data->tx_bytes += skb->len;
  1791. ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel);
  1792. if (ack && skb->len >= 16)
  1793. mac80211_hwsim_monitor_ack(channel, hdr->addr2);
  1794. ieee80211_tx_info_clear_status(txi);
  1795. /* frame was transmitted at most favorable rate at first attempt */
  1796. txi->control.rates[0].count = 1;
  1797. txi->control.rates[1].idx = -1;
  1798. if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK) && ack)
  1799. txi->flags |= IEEE80211_TX_STAT_ACK;
  1800. ieee80211_tx_status_irqsafe(hw, skb);
  1801. }
  1802. static int mac80211_hwsim_start(struct ieee80211_hw *hw)
  1803. {
  1804. struct mac80211_hwsim_data *data = hw->priv;
  1805. wiphy_dbg(hw->wiphy, "%s\n", __func__);
  1806. data->started = true;
  1807. return 0;
  1808. }
  1809. static void mac80211_hwsim_stop(struct ieee80211_hw *hw, bool suspend)
  1810. {
  1811. struct mac80211_hwsim_data *data = hw->priv;
  1812. int i;
  1813. data->started = false;
  1814. for (i = 0; i < ARRAY_SIZE(data->link_data); i++)
  1815. hrtimer_cancel(&data->link_data[i].beacon_timer);
  1816. while (!skb_queue_empty(&data->pending))
  1817. ieee80211_free_txskb(hw, skb_dequeue(&data->pending));
  1818. wiphy_dbg(hw->wiphy, "%s\n", __func__);
  1819. }
  1820. static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw,
  1821. struct ieee80211_vif *vif)
  1822. {
  1823. wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n",
  1824. __func__, ieee80211_vif_type_p2p(vif),
  1825. vif->addr);
  1826. hwsim_set_magic(vif);
  1827. if (vif->type != NL80211_IFTYPE_MONITOR)
  1828. mac80211_hwsim_config_mac_nl(hw, vif->addr, true);
  1829. vif->cab_queue = 0;
  1830. vif->hw_queue[IEEE80211_AC_VO] = 0;
  1831. vif->hw_queue[IEEE80211_AC_VI] = 1;
  1832. vif->hw_queue[IEEE80211_AC_BE] = 2;
  1833. vif->hw_queue[IEEE80211_AC_BK] = 3;
  1834. return 0;
  1835. }
  1836. #ifdef CONFIG_MAC80211_DEBUGFS
  1837. static void
  1838. mac80211_hwsim_link_add_debugfs(struct ieee80211_hw *hw,
  1839. struct ieee80211_vif *vif,
  1840. struct ieee80211_bss_conf *link_conf,
  1841. struct dentry *dir)
  1842. {
  1843. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  1844. debugfs_create_u32("skip_beacons", 0600, dir,
  1845. &vp->skip_beacons[link_conf->link_id]);
  1846. }
  1847. #endif
  1848. static int mac80211_hwsim_change_interface(struct ieee80211_hw *hw,
  1849. struct ieee80211_vif *vif,
  1850. enum nl80211_iftype newtype,
  1851. bool newp2p)
  1852. {
  1853. newtype = ieee80211_iftype_p2p(newtype, newp2p);
  1854. wiphy_dbg(hw->wiphy,
  1855. "%s (old type=%d, new type=%d, mac_addr=%pM)\n",
  1856. __func__, ieee80211_vif_type_p2p(vif),
  1857. newtype, vif->addr);
  1858. hwsim_check_magic(vif);
  1859. /*
  1860. * interface may change from non-AP to AP in
  1861. * which case this needs to be set up again
  1862. */
  1863. vif->cab_queue = 0;
  1864. return 0;
  1865. }
  1866. static void mac80211_hwsim_remove_interface(
  1867. struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1868. {
  1869. wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n",
  1870. __func__, ieee80211_vif_type_p2p(vif),
  1871. vif->addr);
  1872. hwsim_check_magic(vif);
  1873. hwsim_clear_magic(vif);
  1874. if (vif->type != NL80211_IFTYPE_MONITOR)
  1875. mac80211_hwsim_config_mac_nl(hw, vif->addr, false);
  1876. }
  1877. static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
  1878. struct sk_buff *skb,
  1879. struct ieee80211_channel *chan)
  1880. {
  1881. struct mac80211_hwsim_data *data = hw->priv;
  1882. u32 _portid = READ_ONCE(data->wmediumd);
  1883. if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE)) {
  1884. struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
  1885. ieee80211_get_tx_rates(txi->control.vif, NULL, skb,
  1886. txi->control.rates,
  1887. ARRAY_SIZE(txi->control.rates));
  1888. }
  1889. mac80211_hwsim_monitor_rx(hw, skb, chan);
  1890. if (_portid || hwsim_virtio_enabled)
  1891. return mac80211_hwsim_tx_frame_nl(hw, skb, _portid, chan);
  1892. data->tx_pkts++;
  1893. data->tx_bytes += skb->len;
  1894. mac80211_hwsim_tx_frame_no_nl(hw, skb, chan);
  1895. dev_kfree_skb(skb);
  1896. }
  1897. static void __mac80211_hwsim_beacon_tx(struct ieee80211_bss_conf *link_conf,
  1898. struct mac80211_hwsim_data *data,
  1899. struct ieee80211_hw *hw,
  1900. struct ieee80211_vif *vif,
  1901. struct sk_buff *skb)
  1902. {
  1903. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  1904. struct ieee80211_tx_info *info;
  1905. struct ieee80211_rate *txrate;
  1906. struct ieee80211_mgmt *mgmt;
  1907. /* TODO: get MCS */
  1908. int bitrate = 100;
  1909. if (vp->skip_beacons[link_conf->link_id]) {
  1910. vp->skip_beacons[link_conf->link_id]--;
  1911. dev_kfree_skb(skb);
  1912. return;
  1913. }
  1914. info = IEEE80211_SKB_CB(skb);
  1915. if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE))
  1916. ieee80211_get_tx_rates(vif, NULL, skb,
  1917. info->control.rates,
  1918. ARRAY_SIZE(info->control.rates));
  1919. txrate = ieee80211_get_tx_rate(hw, info);
  1920. if (txrate)
  1921. bitrate = txrate->bitrate;
  1922. mgmt = (struct ieee80211_mgmt *) skb->data;
  1923. /* fake header transmission time */
  1924. data->abs_bcn_ts = mac80211_hwsim_get_tsf_raw();
  1925. if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
  1926. struct ieee80211_ext *ext = (void *) mgmt;
  1927. ext->u.s1g_beacon.timestamp = cpu_to_le32(data->abs_bcn_ts +
  1928. data->tsf_offset +
  1929. 10 * 8 * 10 /
  1930. bitrate);
  1931. } else {
  1932. mgmt->u.beacon.timestamp = cpu_to_le64(data->abs_bcn_ts +
  1933. data->tsf_offset +
  1934. 24 * 8 * 10 /
  1935. bitrate);
  1936. }
  1937. mac80211_hwsim_tx_frame(hw, skb,
  1938. rcu_dereference(link_conf->chanctx_conf)->def.chan);
  1939. }
  1940. static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
  1941. struct ieee80211_vif *vif)
  1942. {
  1943. struct mac80211_hwsim_link_data *link_data = arg;
  1944. u32 link_id = link_data->link_id;
  1945. struct ieee80211_bss_conf *link_conf;
  1946. struct mac80211_hwsim_data *data =
  1947. container_of(link_data, struct mac80211_hwsim_data,
  1948. link_data[link_id]);
  1949. struct ieee80211_hw *hw = data->hw;
  1950. struct sk_buff *skb;
  1951. hwsim_check_magic(vif);
  1952. link_conf = rcu_dereference(vif->link_conf[link_id]);
  1953. if (!link_conf)
  1954. return;
  1955. if (vif->type != NL80211_IFTYPE_AP &&
  1956. vif->type != NL80211_IFTYPE_MESH_POINT &&
  1957. vif->type != NL80211_IFTYPE_ADHOC &&
  1958. vif->type != NL80211_IFTYPE_OCB)
  1959. return;
  1960. if (vif->mbssid_tx_vif && vif->mbssid_tx_vif != vif)
  1961. return;
  1962. if (vif->bss_conf.ema_ap) {
  1963. struct ieee80211_ema_beacons *ema;
  1964. u8 i = 0;
  1965. ema = ieee80211_beacon_get_template_ema_list(hw, vif, link_id);
  1966. if (!ema || !ema->cnt)
  1967. return;
  1968. for (i = 0; i < ema->cnt; i++) {
  1969. __mac80211_hwsim_beacon_tx(link_conf, data, hw, vif,
  1970. ema->bcn[i].skb);
  1971. ema->bcn[i].skb = NULL; /* Already freed */
  1972. }
  1973. ieee80211_beacon_free_ema_list(ema);
  1974. } else {
  1975. skb = ieee80211_beacon_get(hw, vif, link_id);
  1976. if (!skb)
  1977. return;
  1978. __mac80211_hwsim_beacon_tx(link_conf, data, hw, vif, skb);
  1979. }
  1980. while ((skb = ieee80211_get_buffered_bc(hw, vif)) != NULL) {
  1981. mac80211_hwsim_tx_frame(hw, skb,
  1982. rcu_dereference(link_conf->chanctx_conf)->def.chan);
  1983. }
  1984. if (link_conf->csa_active && ieee80211_beacon_cntdwn_is_complete(vif, link_id))
  1985. ieee80211_csa_finish(vif, link_id);
  1986. if (link_conf->color_change_active &&
  1987. ieee80211_beacon_cntdwn_is_complete(vif, link_id))
  1988. ieee80211_color_change_finish(vif, link_id);
  1989. }
  1990. static enum hrtimer_restart
  1991. mac80211_hwsim_beacon(struct hrtimer *timer)
  1992. {
  1993. struct mac80211_hwsim_link_data *link_data =
  1994. container_of(timer, struct mac80211_hwsim_link_data, beacon_timer);
  1995. struct mac80211_hwsim_data *data =
  1996. container_of(link_data, struct mac80211_hwsim_data,
  1997. link_data[link_data->link_id]);
  1998. struct ieee80211_hw *hw = data->hw;
  1999. u64 bcn_int = link_data->beacon_int;
  2000. if (!data->started)
  2001. return HRTIMER_NORESTART;
  2002. ieee80211_iterate_active_interfaces_atomic(
  2003. hw, IEEE80211_IFACE_ITER_NORMAL,
  2004. mac80211_hwsim_beacon_tx, link_data);
  2005. /* beacon at new TBTT + beacon interval */
  2006. if (data->bcn_delta) {
  2007. bcn_int -= data->bcn_delta;
  2008. data->bcn_delta = 0;
  2009. }
  2010. hrtimer_forward_now(&link_data->beacon_timer,
  2011. ns_to_ktime(bcn_int * NSEC_PER_USEC));
  2012. return HRTIMER_RESTART;
  2013. }
  2014. static const char * const hwsim_chanwidths[] = {
  2015. [NL80211_CHAN_WIDTH_5] = "ht5",
  2016. [NL80211_CHAN_WIDTH_10] = "ht10",
  2017. [NL80211_CHAN_WIDTH_20_NOHT] = "noht",
  2018. [NL80211_CHAN_WIDTH_20] = "ht20",
  2019. [NL80211_CHAN_WIDTH_40] = "ht40",
  2020. [NL80211_CHAN_WIDTH_80] = "vht80",
  2021. [NL80211_CHAN_WIDTH_80P80] = "vht80p80",
  2022. [NL80211_CHAN_WIDTH_160] = "vht160",
  2023. [NL80211_CHAN_WIDTH_1] = "1MHz",
  2024. [NL80211_CHAN_WIDTH_2] = "2MHz",
  2025. [NL80211_CHAN_WIDTH_4] = "4MHz",
  2026. [NL80211_CHAN_WIDTH_8] = "8MHz",
  2027. [NL80211_CHAN_WIDTH_16] = "16MHz",
  2028. [NL80211_CHAN_WIDTH_320] = "eht320",
  2029. };
  2030. static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
  2031. {
  2032. struct mac80211_hwsim_data *data = hw->priv;
  2033. struct ieee80211_conf *conf = &hw->conf;
  2034. static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
  2035. [IEEE80211_SMPS_AUTOMATIC] = "auto",
  2036. [IEEE80211_SMPS_OFF] = "off",
  2037. [IEEE80211_SMPS_STATIC] = "static",
  2038. [IEEE80211_SMPS_DYNAMIC] = "dynamic",
  2039. };
  2040. int idx;
  2041. if (conf->chandef.chan)
  2042. wiphy_dbg(hw->wiphy,
  2043. "%s (freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n",
  2044. __func__,
  2045. conf->chandef.chan->center_freq,
  2046. conf->chandef.center_freq1,
  2047. conf->chandef.center_freq2,
  2048. hwsim_chanwidths[conf->chandef.width],
  2049. !!(conf->flags & IEEE80211_CONF_IDLE),
  2050. !!(conf->flags & IEEE80211_CONF_PS),
  2051. smps_modes[conf->smps_mode]);
  2052. else
  2053. wiphy_dbg(hw->wiphy,
  2054. "%s (freq=0 idle=%d ps=%d smps=%s)\n",
  2055. __func__,
  2056. !!(conf->flags & IEEE80211_CONF_IDLE),
  2057. !!(conf->flags & IEEE80211_CONF_PS),
  2058. smps_modes[conf->smps_mode]);
  2059. data->idle = !!(conf->flags & IEEE80211_CONF_IDLE);
  2060. WARN_ON(conf->chandef.chan && data->use_chanctx);
  2061. mutex_lock(&data->mutex);
  2062. if (data->scanning && conf->chandef.chan) {
  2063. for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) {
  2064. if (data->survey_data[idx].channel == data->channel) {
  2065. data->survey_data[idx].start =
  2066. data->survey_data[idx].next_start;
  2067. data->survey_data[idx].end = jiffies;
  2068. break;
  2069. }
  2070. }
  2071. data->channel = conf->chandef.chan;
  2072. data->bw = conf->chandef.width;
  2073. for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) {
  2074. if (data->survey_data[idx].channel &&
  2075. data->survey_data[idx].channel != data->channel)
  2076. continue;
  2077. data->survey_data[idx].channel = data->channel;
  2078. data->survey_data[idx].next_start = jiffies;
  2079. break;
  2080. }
  2081. } else {
  2082. data->channel = conf->chandef.chan;
  2083. data->bw = conf->chandef.width;
  2084. }
  2085. mutex_unlock(&data->mutex);
  2086. for (idx = 0; idx < ARRAY_SIZE(data->link_data); idx++) {
  2087. struct mac80211_hwsim_link_data *link_data =
  2088. &data->link_data[idx];
  2089. if (!data->started || !link_data->beacon_int) {
  2090. hrtimer_cancel(&link_data->beacon_timer);
  2091. } else if (!hrtimer_is_queued(&link_data->beacon_timer)) {
  2092. u64 tsf = mac80211_hwsim_get_tsf(hw, NULL);
  2093. u32 bcn_int = link_data->beacon_int;
  2094. u64 until_tbtt = bcn_int - do_div(tsf, bcn_int);
  2095. hrtimer_start(&link_data->beacon_timer,
  2096. ns_to_ktime(until_tbtt * NSEC_PER_USEC),
  2097. HRTIMER_MODE_REL_SOFT);
  2098. }
  2099. }
  2100. return 0;
  2101. }
  2102. static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
  2103. unsigned int changed_flags,
  2104. unsigned int *total_flags,u64 multicast)
  2105. {
  2106. struct mac80211_hwsim_data *data = hw->priv;
  2107. wiphy_dbg(hw->wiphy, "%s\n", __func__);
  2108. data->rx_filter = 0;
  2109. if (*total_flags & FIF_ALLMULTI)
  2110. data->rx_filter |= FIF_ALLMULTI;
  2111. if (*total_flags & FIF_MCAST_ACTION)
  2112. data->rx_filter |= FIF_MCAST_ACTION;
  2113. *total_flags = data->rx_filter;
  2114. }
  2115. static void mac80211_hwsim_bcn_en_iter(void *data, u8 *mac,
  2116. struct ieee80211_vif *vif)
  2117. {
  2118. unsigned int *count = data;
  2119. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  2120. if (vp->bcn_en)
  2121. (*count)++;
  2122. }
  2123. static void mac80211_hwsim_vif_info_changed(struct ieee80211_hw *hw,
  2124. struct ieee80211_vif *vif,
  2125. u64 changed)
  2126. {
  2127. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  2128. hwsim_check_magic(vif);
  2129. wiphy_dbg(hw->wiphy, "%s(changed=0x%llx vif->addr=%pM)\n",
  2130. __func__, changed, vif->addr);
  2131. if (changed & BSS_CHANGED_ASSOC) {
  2132. wiphy_dbg(hw->wiphy, " ASSOC: assoc=%d aid=%d\n",
  2133. vif->cfg.assoc, vif->cfg.aid);
  2134. vp->assoc = vif->cfg.assoc;
  2135. vp->aid = vif->cfg.aid;
  2136. }
  2137. if (vif->type == NL80211_IFTYPE_STATION &&
  2138. changed & (BSS_CHANGED_MLD_VALID_LINKS | BSS_CHANGED_MLD_TTLM)) {
  2139. u16 usable_links = ieee80211_vif_usable_links(vif);
  2140. if (vif->active_links != usable_links)
  2141. ieee80211_set_active_links_async(vif, usable_links);
  2142. }
  2143. }
  2144. static void mac80211_hwsim_link_info_changed(struct ieee80211_hw *hw,
  2145. struct ieee80211_vif *vif,
  2146. struct ieee80211_bss_conf *info,
  2147. u64 changed)
  2148. {
  2149. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  2150. struct mac80211_hwsim_data *data = hw->priv;
  2151. unsigned int link_id = info->link_id;
  2152. struct mac80211_hwsim_link_data *link_data = &data->link_data[link_id];
  2153. hwsim_check_magic(vif);
  2154. wiphy_dbg(hw->wiphy, "%s(changed=0x%llx vif->addr=%pM, link id %u)\n",
  2155. __func__, (unsigned long long)changed, vif->addr, link_id);
  2156. if (changed & BSS_CHANGED_BSSID) {
  2157. wiphy_dbg(hw->wiphy, "%s: BSSID changed: %pM\n",
  2158. __func__, info->bssid);
  2159. memcpy(vp->bssid, info->bssid, ETH_ALEN);
  2160. }
  2161. if (changed & BSS_CHANGED_BEACON_ENABLED) {
  2162. wiphy_dbg(hw->wiphy, " BCN EN: %d (BI=%u)\n",
  2163. info->enable_beacon, info->beacon_int);
  2164. vp->bcn_en = info->enable_beacon;
  2165. if (data->started &&
  2166. !hrtimer_is_queued(&link_data->beacon_timer) &&
  2167. info->enable_beacon) {
  2168. u64 tsf, until_tbtt;
  2169. u32 bcn_int;
  2170. link_data->beacon_int = info->beacon_int * 1024;
  2171. tsf = mac80211_hwsim_get_tsf(hw, vif);
  2172. bcn_int = link_data->beacon_int;
  2173. until_tbtt = bcn_int - do_div(tsf, bcn_int);
  2174. hrtimer_start(&link_data->beacon_timer,
  2175. ns_to_ktime(until_tbtt * NSEC_PER_USEC),
  2176. HRTIMER_MODE_REL_SOFT);
  2177. } else if (!info->enable_beacon) {
  2178. unsigned int count = 0;
  2179. ieee80211_iterate_active_interfaces_atomic(
  2180. data->hw, IEEE80211_IFACE_ITER_NORMAL,
  2181. mac80211_hwsim_bcn_en_iter, &count);
  2182. wiphy_dbg(hw->wiphy, " beaconing vifs remaining: %u",
  2183. count);
  2184. if (count == 0) {
  2185. hrtimer_cancel(&link_data->beacon_timer);
  2186. link_data->beacon_int = 0;
  2187. }
  2188. }
  2189. }
  2190. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  2191. wiphy_dbg(hw->wiphy, " ERP_CTS_PROT: %d\n",
  2192. info->use_cts_prot);
  2193. }
  2194. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  2195. wiphy_dbg(hw->wiphy, " ERP_PREAMBLE: %d\n",
  2196. info->use_short_preamble);
  2197. }
  2198. if (changed & BSS_CHANGED_ERP_SLOT) {
  2199. wiphy_dbg(hw->wiphy, " ERP_SLOT: %d\n", info->use_short_slot);
  2200. }
  2201. if (changed & BSS_CHANGED_HT) {
  2202. wiphy_dbg(hw->wiphy, " HT: op_mode=0x%x\n",
  2203. info->ht_operation_mode);
  2204. }
  2205. if (changed & BSS_CHANGED_BASIC_RATES) {
  2206. wiphy_dbg(hw->wiphy, " BASIC_RATES: 0x%llx\n",
  2207. (unsigned long long) info->basic_rates);
  2208. }
  2209. if (changed & BSS_CHANGED_TXPOWER)
  2210. wiphy_dbg(hw->wiphy, " TX Power: %d dBm\n", info->txpower);
  2211. }
  2212. static void
  2213. mac80211_hwsim_sta_rc_update(struct ieee80211_hw *hw,
  2214. struct ieee80211_vif *vif,
  2215. struct ieee80211_sta *sta,
  2216. u32 changed)
  2217. {
  2218. struct mac80211_hwsim_data *data = hw->priv;
  2219. u32 bw = U32_MAX;
  2220. int link_id;
  2221. rcu_read_lock();
  2222. for (link_id = 0;
  2223. link_id < ARRAY_SIZE(vif->link_conf);
  2224. link_id++) {
  2225. enum nl80211_chan_width confbw = NL80211_CHAN_WIDTH_20_NOHT;
  2226. struct ieee80211_bss_conf *vif_conf;
  2227. struct ieee80211_link_sta *link_sta;
  2228. link_sta = rcu_dereference(sta->link[link_id]);
  2229. if (!link_sta)
  2230. continue;
  2231. switch (link_sta->bandwidth) {
  2232. #define C(_bw) case IEEE80211_STA_RX_BW_##_bw: bw = _bw; break
  2233. C(20);
  2234. C(40);
  2235. C(80);
  2236. C(160);
  2237. C(320);
  2238. #undef C
  2239. }
  2240. if (!data->use_chanctx) {
  2241. confbw = data->bw;
  2242. } else {
  2243. struct ieee80211_chanctx_conf *chanctx_conf;
  2244. vif_conf = rcu_dereference(vif->link_conf[link_id]);
  2245. if (WARN_ON(!vif_conf))
  2246. continue;
  2247. chanctx_conf = rcu_dereference(vif_conf->chanctx_conf);
  2248. if (!WARN_ON(!chanctx_conf))
  2249. confbw = chanctx_conf->def.width;
  2250. }
  2251. WARN(bw > hwsim_get_chanwidth(confbw),
  2252. "intf %pM [link=%d]: bad STA %pM bandwidth %d MHz (%d) > channel config %d MHz (%d)\n",
  2253. vif->addr, link_id, sta->addr, bw, sta->deflink.bandwidth,
  2254. hwsim_get_chanwidth(data->bw), data->bw);
  2255. }
  2256. rcu_read_unlock();
  2257. }
  2258. static int mac80211_hwsim_sta_add(struct ieee80211_hw *hw,
  2259. struct ieee80211_vif *vif,
  2260. struct ieee80211_sta *sta)
  2261. {
  2262. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  2263. hwsim_check_magic(vif);
  2264. hwsim_set_sta_magic(sta);
  2265. mac80211_hwsim_sta_rc_update(hw, vif, sta, 0);
  2266. if (sta->valid_links) {
  2267. WARN(hweight16(sta->valid_links) > 1,
  2268. "expect to add STA with single link, have 0x%x\n",
  2269. sta->valid_links);
  2270. sp->active_links_rx = sta->valid_links;
  2271. }
  2272. return 0;
  2273. }
  2274. static int mac80211_hwsim_sta_remove(struct ieee80211_hw *hw,
  2275. struct ieee80211_vif *vif,
  2276. struct ieee80211_sta *sta)
  2277. {
  2278. hwsim_check_magic(vif);
  2279. hwsim_clear_sta_magic(sta);
  2280. return 0;
  2281. }
  2282. static int mac80211_hwsim_sta_state(struct ieee80211_hw *hw,
  2283. struct ieee80211_vif *vif,
  2284. struct ieee80211_sta *sta,
  2285. enum ieee80211_sta_state old_state,
  2286. enum ieee80211_sta_state new_state)
  2287. {
  2288. if (new_state == IEEE80211_STA_NOTEXIST)
  2289. return mac80211_hwsim_sta_remove(hw, vif, sta);
  2290. if (old_state == IEEE80211_STA_NOTEXIST)
  2291. return mac80211_hwsim_sta_add(hw, vif, sta);
  2292. /*
  2293. * in an MLO connection, when client is authorized
  2294. * (AP station marked as such), enable all links
  2295. */
  2296. if (ieee80211_vif_is_mld(vif) &&
  2297. vif->type == NL80211_IFTYPE_STATION &&
  2298. new_state == IEEE80211_STA_AUTHORIZED && !sta->tdls)
  2299. ieee80211_set_active_links_async(vif,
  2300. ieee80211_vif_usable_links(vif));
  2301. return 0;
  2302. }
  2303. static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
  2304. struct ieee80211_vif *vif,
  2305. enum sta_notify_cmd cmd,
  2306. struct ieee80211_sta *sta)
  2307. {
  2308. hwsim_check_magic(vif);
  2309. switch (cmd) {
  2310. case STA_NOTIFY_SLEEP:
  2311. case STA_NOTIFY_AWAKE:
  2312. /* TODO: make good use of these flags */
  2313. break;
  2314. default:
  2315. WARN(1, "Invalid sta notify: %d\n", cmd);
  2316. break;
  2317. }
  2318. }
  2319. static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
  2320. struct ieee80211_sta *sta,
  2321. bool set)
  2322. {
  2323. hwsim_check_sta_magic(sta);
  2324. return 0;
  2325. }
  2326. static int mac80211_hwsim_conf_tx(struct ieee80211_hw *hw,
  2327. struct ieee80211_vif *vif,
  2328. unsigned int link_id, u16 queue,
  2329. const struct ieee80211_tx_queue_params *params)
  2330. {
  2331. wiphy_dbg(hw->wiphy,
  2332. "%s (queue=%d txop=%d cw_min=%d cw_max=%d aifs=%d)\n",
  2333. __func__, queue,
  2334. params->txop, params->cw_min,
  2335. params->cw_max, params->aifs);
  2336. return 0;
  2337. }
  2338. static int mac80211_hwsim_get_survey(struct ieee80211_hw *hw, int idx,
  2339. struct survey_info *survey)
  2340. {
  2341. struct mac80211_hwsim_data *hwsim = hw->priv;
  2342. if (idx < 0 || idx >= ARRAY_SIZE(hwsim->survey_data))
  2343. return -ENOENT;
  2344. mutex_lock(&hwsim->mutex);
  2345. survey->channel = hwsim->survey_data[idx].channel;
  2346. if (!survey->channel) {
  2347. mutex_unlock(&hwsim->mutex);
  2348. return -ENOENT;
  2349. }
  2350. /*
  2351. * Magically conjured dummy values --- this is only ok for simulated hardware.
  2352. *
  2353. * A real driver which cannot determine real values noise MUST NOT
  2354. * report any, especially not a magically conjured ones :-)
  2355. */
  2356. survey->filled = SURVEY_INFO_NOISE_DBM |
  2357. SURVEY_INFO_TIME |
  2358. SURVEY_INFO_TIME_BUSY;
  2359. survey->noise = -92;
  2360. survey->time =
  2361. jiffies_to_msecs(hwsim->survey_data[idx].end -
  2362. hwsim->survey_data[idx].start);
  2363. /* report 12.5% of channel time is used */
  2364. survey->time_busy = survey->time/8;
  2365. mutex_unlock(&hwsim->mutex);
  2366. return 0;
  2367. }
  2368. static enum ieee80211_neg_ttlm_res
  2369. mac80211_hwsim_can_neg_ttlm(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  2370. struct ieee80211_neg_ttlm *neg_ttlm)
  2371. {
  2372. u32 i;
  2373. /* For testing purposes, accept if all TIDs are mapped to the same links
  2374. * set, otherwise reject.
  2375. */
  2376. for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
  2377. if (neg_ttlm->downlink[i] != neg_ttlm->uplink[i] ||
  2378. neg_ttlm->downlink[i] != neg_ttlm->downlink[0])
  2379. return NEG_TTLM_RES_REJECT;
  2380. }
  2381. return NEG_TTLM_RES_ACCEPT;
  2382. }
  2383. #ifdef CONFIG_NL80211_TESTMODE
  2384. /*
  2385. * This section contains example code for using netlink
  2386. * attributes with the testmode command in nl80211.
  2387. */
  2388. /* These enums need to be kept in sync with userspace */
  2389. enum hwsim_testmode_attr {
  2390. __HWSIM_TM_ATTR_INVALID = 0,
  2391. HWSIM_TM_ATTR_CMD = 1,
  2392. HWSIM_TM_ATTR_PS = 2,
  2393. /* keep last */
  2394. __HWSIM_TM_ATTR_AFTER_LAST,
  2395. HWSIM_TM_ATTR_MAX = __HWSIM_TM_ATTR_AFTER_LAST - 1
  2396. };
  2397. enum hwsim_testmode_cmd {
  2398. HWSIM_TM_CMD_SET_PS = 0,
  2399. HWSIM_TM_CMD_GET_PS = 1,
  2400. HWSIM_TM_CMD_STOP_QUEUES = 2,
  2401. HWSIM_TM_CMD_WAKE_QUEUES = 3,
  2402. };
  2403. static const struct nla_policy hwsim_testmode_policy[HWSIM_TM_ATTR_MAX + 1] = {
  2404. [HWSIM_TM_ATTR_CMD] = { .type = NLA_U32 },
  2405. [HWSIM_TM_ATTR_PS] = { .type = NLA_U32 },
  2406. };
  2407. static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw,
  2408. struct ieee80211_vif *vif,
  2409. void *data, int len)
  2410. {
  2411. struct mac80211_hwsim_data *hwsim = hw->priv;
  2412. struct nlattr *tb[HWSIM_TM_ATTR_MAX + 1];
  2413. struct sk_buff *skb;
  2414. int err, ps;
  2415. err = nla_parse_deprecated(tb, HWSIM_TM_ATTR_MAX, data, len,
  2416. hwsim_testmode_policy, NULL);
  2417. if (err)
  2418. return err;
  2419. if (!tb[HWSIM_TM_ATTR_CMD])
  2420. return -EINVAL;
  2421. switch (nla_get_u32(tb[HWSIM_TM_ATTR_CMD])) {
  2422. case HWSIM_TM_CMD_SET_PS:
  2423. if (!tb[HWSIM_TM_ATTR_PS])
  2424. return -EINVAL;
  2425. ps = nla_get_u32(tb[HWSIM_TM_ATTR_PS]);
  2426. return hwsim_fops_ps_write(hwsim, ps);
  2427. case HWSIM_TM_CMD_GET_PS:
  2428. skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
  2429. nla_total_size(sizeof(u32)));
  2430. if (!skb)
  2431. return -ENOMEM;
  2432. if (nla_put_u32(skb, HWSIM_TM_ATTR_PS, hwsim->ps))
  2433. goto nla_put_failure;
  2434. return cfg80211_testmode_reply(skb);
  2435. case HWSIM_TM_CMD_STOP_QUEUES:
  2436. ieee80211_stop_queues(hw);
  2437. return 0;
  2438. case HWSIM_TM_CMD_WAKE_QUEUES:
  2439. ieee80211_wake_queues(hw);
  2440. return 0;
  2441. default:
  2442. return -EOPNOTSUPP;
  2443. }
  2444. nla_put_failure:
  2445. kfree_skb(skb);
  2446. return -ENOBUFS;
  2447. }
  2448. #endif
  2449. static int mac80211_hwsim_ampdu_action(struct ieee80211_hw *hw,
  2450. struct ieee80211_vif *vif,
  2451. struct ieee80211_ampdu_params *params)
  2452. {
  2453. struct ieee80211_sta *sta = params->sta;
  2454. enum ieee80211_ampdu_mlme_action action = params->action;
  2455. u16 tid = params->tid;
  2456. switch (action) {
  2457. case IEEE80211_AMPDU_TX_START:
  2458. return IEEE80211_AMPDU_TX_START_IMMEDIATE;
  2459. case IEEE80211_AMPDU_TX_STOP_CONT:
  2460. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  2461. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  2462. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  2463. break;
  2464. case IEEE80211_AMPDU_TX_OPERATIONAL:
  2465. break;
  2466. case IEEE80211_AMPDU_RX_START:
  2467. case IEEE80211_AMPDU_RX_STOP:
  2468. break;
  2469. default:
  2470. return -EOPNOTSUPP;
  2471. }
  2472. return 0;
  2473. }
  2474. static void mac80211_hwsim_flush(struct ieee80211_hw *hw,
  2475. struct ieee80211_vif *vif,
  2476. u32 queues, bool drop)
  2477. {
  2478. /* Not implemented, queues only on kernel side */
  2479. }
  2480. static void hw_scan_work(struct work_struct *work)
  2481. {
  2482. struct mac80211_hwsim_data *hwsim =
  2483. container_of(work, struct mac80211_hwsim_data, hw_scan.work);
  2484. struct cfg80211_scan_request *req = hwsim->hw_scan_request;
  2485. int dwell, i;
  2486. mutex_lock(&hwsim->mutex);
  2487. if (hwsim->scan_chan_idx >= req->n_channels) {
  2488. struct cfg80211_scan_info info = {
  2489. .aborted = false,
  2490. };
  2491. wiphy_dbg(hwsim->hw->wiphy, "hw scan complete\n");
  2492. ieee80211_scan_completed(hwsim->hw, &info);
  2493. hwsim->hw_scan_request = NULL;
  2494. hwsim->hw_scan_vif = NULL;
  2495. hwsim->tmp_chan = NULL;
  2496. mutex_unlock(&hwsim->mutex);
  2497. mac80211_hwsim_config_mac_nl(hwsim->hw, hwsim->scan_addr,
  2498. false);
  2499. return;
  2500. }
  2501. wiphy_dbg(hwsim->hw->wiphy, "hw scan %d MHz\n",
  2502. req->channels[hwsim->scan_chan_idx]->center_freq);
  2503. hwsim->tmp_chan = req->channels[hwsim->scan_chan_idx];
  2504. if (hwsim->tmp_chan->flags & (IEEE80211_CHAN_NO_IR |
  2505. IEEE80211_CHAN_RADAR) ||
  2506. !req->n_ssids) {
  2507. dwell = 120;
  2508. } else {
  2509. dwell = 30;
  2510. /* send probes */
  2511. for (i = 0; i < req->n_ssids; i++) {
  2512. struct sk_buff *probe;
  2513. struct ieee80211_mgmt *mgmt;
  2514. probe = ieee80211_probereq_get(hwsim->hw,
  2515. hwsim->scan_addr,
  2516. req->ssids[i].ssid,
  2517. req->ssids[i].ssid_len,
  2518. req->ie_len);
  2519. if (!probe)
  2520. continue;
  2521. mgmt = (struct ieee80211_mgmt *) probe->data;
  2522. memcpy(mgmt->da, req->bssid, ETH_ALEN);
  2523. memcpy(mgmt->bssid, req->bssid, ETH_ALEN);
  2524. if (req->ie_len)
  2525. skb_put_data(probe, req->ie, req->ie_len);
  2526. rcu_read_lock();
  2527. if (!ieee80211_tx_prepare_skb(hwsim->hw,
  2528. hwsim->hw_scan_vif,
  2529. probe,
  2530. hwsim->tmp_chan->band,
  2531. NULL)) {
  2532. rcu_read_unlock();
  2533. kfree_skb(probe);
  2534. continue;
  2535. }
  2536. local_bh_disable();
  2537. mac80211_hwsim_tx_frame(hwsim->hw, probe,
  2538. hwsim->tmp_chan);
  2539. rcu_read_unlock();
  2540. local_bh_enable();
  2541. }
  2542. }
  2543. ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan,
  2544. msecs_to_jiffies(dwell));
  2545. hwsim->survey_data[hwsim->scan_chan_idx].channel = hwsim->tmp_chan;
  2546. hwsim->survey_data[hwsim->scan_chan_idx].start = jiffies;
  2547. hwsim->survey_data[hwsim->scan_chan_idx].end =
  2548. jiffies + msecs_to_jiffies(dwell);
  2549. hwsim->scan_chan_idx++;
  2550. mutex_unlock(&hwsim->mutex);
  2551. }
  2552. static int mac80211_hwsim_hw_scan(struct ieee80211_hw *hw,
  2553. struct ieee80211_vif *vif,
  2554. struct ieee80211_scan_request *hw_req)
  2555. {
  2556. struct mac80211_hwsim_data *hwsim = hw->priv;
  2557. struct cfg80211_scan_request *req = &hw_req->req;
  2558. mutex_lock(&hwsim->mutex);
  2559. if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) {
  2560. mutex_unlock(&hwsim->mutex);
  2561. return -EBUSY;
  2562. }
  2563. hwsim->hw_scan_request = req;
  2564. hwsim->hw_scan_vif = vif;
  2565. hwsim->scan_chan_idx = 0;
  2566. if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
  2567. get_random_mask_addr(hwsim->scan_addr,
  2568. hw_req->req.mac_addr,
  2569. hw_req->req.mac_addr_mask);
  2570. else
  2571. memcpy(hwsim->scan_addr, vif->addr, ETH_ALEN);
  2572. memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data));
  2573. mutex_unlock(&hwsim->mutex);
  2574. mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, true);
  2575. wiphy_dbg(hw->wiphy, "hwsim hw_scan request\n");
  2576. ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan, 0);
  2577. return 0;
  2578. }
  2579. static void mac80211_hwsim_cancel_hw_scan(struct ieee80211_hw *hw,
  2580. struct ieee80211_vif *vif)
  2581. {
  2582. struct mac80211_hwsim_data *hwsim = hw->priv;
  2583. struct cfg80211_scan_info info = {
  2584. .aborted = true,
  2585. };
  2586. wiphy_dbg(hw->wiphy, "hwsim cancel_hw_scan\n");
  2587. cancel_delayed_work_sync(&hwsim->hw_scan);
  2588. mutex_lock(&hwsim->mutex);
  2589. ieee80211_scan_completed(hwsim->hw, &info);
  2590. hwsim->tmp_chan = NULL;
  2591. hwsim->hw_scan_request = NULL;
  2592. hwsim->hw_scan_vif = NULL;
  2593. mutex_unlock(&hwsim->mutex);
  2594. }
  2595. static void mac80211_hwsim_sw_scan(struct ieee80211_hw *hw,
  2596. struct ieee80211_vif *vif,
  2597. const u8 *mac_addr)
  2598. {
  2599. struct mac80211_hwsim_data *hwsim = hw->priv;
  2600. mutex_lock(&hwsim->mutex);
  2601. if (hwsim->scanning) {
  2602. pr_debug("two hwsim sw_scans detected!\n");
  2603. goto out;
  2604. }
  2605. pr_debug("hwsim sw_scan request, prepping stuff\n");
  2606. memcpy(hwsim->scan_addr, mac_addr, ETH_ALEN);
  2607. mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, true);
  2608. hwsim->scanning = true;
  2609. memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data));
  2610. out:
  2611. mutex_unlock(&hwsim->mutex);
  2612. }
  2613. static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw,
  2614. struct ieee80211_vif *vif)
  2615. {
  2616. struct mac80211_hwsim_data *hwsim = hw->priv;
  2617. mutex_lock(&hwsim->mutex);
  2618. pr_debug("hwsim sw_scan_complete\n");
  2619. hwsim->scanning = false;
  2620. mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, false);
  2621. eth_zero_addr(hwsim->scan_addr);
  2622. mutex_unlock(&hwsim->mutex);
  2623. }
  2624. static void hw_roc_start(struct work_struct *work)
  2625. {
  2626. struct mac80211_hwsim_data *hwsim =
  2627. container_of(work, struct mac80211_hwsim_data, roc_start.work);
  2628. mutex_lock(&hwsim->mutex);
  2629. wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC begins\n");
  2630. hwsim->tmp_chan = hwsim->roc_chan;
  2631. ieee80211_ready_on_channel(hwsim->hw);
  2632. ieee80211_queue_delayed_work(hwsim->hw, &hwsim->roc_done,
  2633. msecs_to_jiffies(hwsim->roc_duration));
  2634. mutex_unlock(&hwsim->mutex);
  2635. }
  2636. static void hw_roc_done(struct work_struct *work)
  2637. {
  2638. struct mac80211_hwsim_data *hwsim =
  2639. container_of(work, struct mac80211_hwsim_data, roc_done.work);
  2640. mutex_lock(&hwsim->mutex);
  2641. ieee80211_remain_on_channel_expired(hwsim->hw);
  2642. hwsim->tmp_chan = NULL;
  2643. mutex_unlock(&hwsim->mutex);
  2644. wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC expired\n");
  2645. }
  2646. static int mac80211_hwsim_roc(struct ieee80211_hw *hw,
  2647. struct ieee80211_vif *vif,
  2648. struct ieee80211_channel *chan,
  2649. int duration,
  2650. enum ieee80211_roc_type type)
  2651. {
  2652. struct mac80211_hwsim_data *hwsim = hw->priv;
  2653. mutex_lock(&hwsim->mutex);
  2654. if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) {
  2655. mutex_unlock(&hwsim->mutex);
  2656. return -EBUSY;
  2657. }
  2658. hwsim->roc_chan = chan;
  2659. hwsim->roc_duration = duration;
  2660. mutex_unlock(&hwsim->mutex);
  2661. wiphy_dbg(hw->wiphy, "hwsim ROC (%d MHz, %d ms)\n",
  2662. chan->center_freq, duration);
  2663. ieee80211_queue_delayed_work(hw, &hwsim->roc_start, HZ/50);
  2664. return 0;
  2665. }
  2666. static int mac80211_hwsim_croc(struct ieee80211_hw *hw,
  2667. struct ieee80211_vif *vif)
  2668. {
  2669. struct mac80211_hwsim_data *hwsim = hw->priv;
  2670. cancel_delayed_work_sync(&hwsim->roc_start);
  2671. cancel_delayed_work_sync(&hwsim->roc_done);
  2672. mutex_lock(&hwsim->mutex);
  2673. hwsim->tmp_chan = NULL;
  2674. mutex_unlock(&hwsim->mutex);
  2675. wiphy_dbg(hw->wiphy, "hwsim ROC canceled\n");
  2676. return 0;
  2677. }
  2678. static int mac80211_hwsim_add_chanctx(struct ieee80211_hw *hw,
  2679. struct ieee80211_chanctx_conf *ctx)
  2680. {
  2681. hwsim_set_chanctx_magic(ctx);
  2682. wiphy_dbg(hw->wiphy,
  2683. "add channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
  2684. ctx->def.chan->center_freq, ctx->def.width,
  2685. ctx->def.center_freq1, ctx->def.center_freq2);
  2686. return 0;
  2687. }
  2688. static void mac80211_hwsim_remove_chanctx(struct ieee80211_hw *hw,
  2689. struct ieee80211_chanctx_conf *ctx)
  2690. {
  2691. wiphy_dbg(hw->wiphy,
  2692. "remove channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
  2693. ctx->def.chan->center_freq, ctx->def.width,
  2694. ctx->def.center_freq1, ctx->def.center_freq2);
  2695. hwsim_check_chanctx_magic(ctx);
  2696. hwsim_clear_chanctx_magic(ctx);
  2697. }
  2698. static void mac80211_hwsim_change_chanctx(struct ieee80211_hw *hw,
  2699. struct ieee80211_chanctx_conf *ctx,
  2700. u32 changed)
  2701. {
  2702. hwsim_check_chanctx_magic(ctx);
  2703. wiphy_dbg(hw->wiphy,
  2704. "change channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
  2705. ctx->def.chan->center_freq, ctx->def.width,
  2706. ctx->def.center_freq1, ctx->def.center_freq2);
  2707. }
  2708. static int mac80211_hwsim_assign_vif_chanctx(struct ieee80211_hw *hw,
  2709. struct ieee80211_vif *vif,
  2710. struct ieee80211_bss_conf *link_conf,
  2711. struct ieee80211_chanctx_conf *ctx)
  2712. {
  2713. hwsim_check_magic(vif);
  2714. hwsim_check_chanctx_magic(ctx);
  2715. /* if we activate a link while already associated wake it up */
  2716. if (vif->type == NL80211_IFTYPE_STATION && vif->cfg.assoc) {
  2717. struct sk_buff *skb;
  2718. skb = ieee80211_nullfunc_get(hw, vif, link_conf->link_id, true);
  2719. if (skb) {
  2720. local_bh_disable();
  2721. mac80211_hwsim_tx_frame(hw, skb, ctx->def.chan);
  2722. local_bh_enable();
  2723. }
  2724. }
  2725. return 0;
  2726. }
  2727. static void mac80211_hwsim_unassign_vif_chanctx(struct ieee80211_hw *hw,
  2728. struct ieee80211_vif *vif,
  2729. struct ieee80211_bss_conf *link_conf,
  2730. struct ieee80211_chanctx_conf *ctx)
  2731. {
  2732. hwsim_check_magic(vif);
  2733. hwsim_check_chanctx_magic(ctx);
  2734. /* if we deactivate a link while associated suspend it first */
  2735. if (vif->type == NL80211_IFTYPE_STATION && vif->cfg.assoc) {
  2736. struct sk_buff *skb;
  2737. skb = ieee80211_nullfunc_get(hw, vif, link_conf->link_id, true);
  2738. if (skb) {
  2739. struct ieee80211_hdr *hdr = (void *)skb->data;
  2740. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  2741. local_bh_disable();
  2742. mac80211_hwsim_tx_frame(hw, skb, ctx->def.chan);
  2743. local_bh_enable();
  2744. }
  2745. }
  2746. }
  2747. static int mac80211_hwsim_switch_vif_chanctx(struct ieee80211_hw *hw,
  2748. struct ieee80211_vif_chanctx_switch *vifs,
  2749. int n_vifs,
  2750. enum ieee80211_chanctx_switch_mode mode)
  2751. {
  2752. int i;
  2753. if (n_vifs <= 0)
  2754. return -EINVAL;
  2755. wiphy_dbg(hw->wiphy,
  2756. "switch vif channel context mode: %u\n", mode);
  2757. for (i = 0; i < n_vifs; i++) {
  2758. hwsim_check_chanctx_magic(vifs[i].old_ctx);
  2759. wiphy_dbg(hw->wiphy,
  2760. "switch vif channel context: %d MHz/width: %d/cfreqs:%d/%d MHz -> %d MHz/width: %d/cfreqs:%d/%d MHz\n",
  2761. vifs[i].old_ctx->def.chan->center_freq,
  2762. vifs[i].old_ctx->def.width,
  2763. vifs[i].old_ctx->def.center_freq1,
  2764. vifs[i].old_ctx->def.center_freq2,
  2765. vifs[i].new_ctx->def.chan->center_freq,
  2766. vifs[i].new_ctx->def.width,
  2767. vifs[i].new_ctx->def.center_freq1,
  2768. vifs[i].new_ctx->def.center_freq2);
  2769. switch (mode) {
  2770. case CHANCTX_SWMODE_REASSIGN_VIF:
  2771. hwsim_check_chanctx_magic(vifs[i].new_ctx);
  2772. break;
  2773. case CHANCTX_SWMODE_SWAP_CONTEXTS:
  2774. hwsim_set_chanctx_magic(vifs[i].new_ctx);
  2775. hwsim_clear_chanctx_magic(vifs[i].old_ctx);
  2776. break;
  2777. default:
  2778. WARN(1, "Invalid mode %d\n", mode);
  2779. }
  2780. }
  2781. return 0;
  2782. }
  2783. static const char mac80211_hwsim_gstrings_stats[][ETH_GSTRING_LEN] = {
  2784. "tx_pkts_nic",
  2785. "tx_bytes_nic",
  2786. "rx_pkts_nic",
  2787. "rx_bytes_nic",
  2788. "d_tx_dropped",
  2789. "d_tx_failed",
  2790. "d_ps_mode",
  2791. "d_group",
  2792. };
  2793. #define MAC80211_HWSIM_SSTATS_LEN ARRAY_SIZE(mac80211_hwsim_gstrings_stats)
  2794. static void mac80211_hwsim_get_et_strings(struct ieee80211_hw *hw,
  2795. struct ieee80211_vif *vif,
  2796. u32 sset, u8 *data)
  2797. {
  2798. if (sset == ETH_SS_STATS)
  2799. memcpy(data, mac80211_hwsim_gstrings_stats,
  2800. sizeof(mac80211_hwsim_gstrings_stats));
  2801. }
  2802. static int mac80211_hwsim_get_et_sset_count(struct ieee80211_hw *hw,
  2803. struct ieee80211_vif *vif, int sset)
  2804. {
  2805. if (sset == ETH_SS_STATS)
  2806. return MAC80211_HWSIM_SSTATS_LEN;
  2807. return 0;
  2808. }
  2809. static void mac80211_hwsim_get_et_stats(struct ieee80211_hw *hw,
  2810. struct ieee80211_vif *vif,
  2811. struct ethtool_stats *stats, u64 *data)
  2812. {
  2813. struct mac80211_hwsim_data *ar = hw->priv;
  2814. int i = 0;
  2815. data[i++] = ar->tx_pkts;
  2816. data[i++] = ar->tx_bytes;
  2817. data[i++] = ar->rx_pkts;
  2818. data[i++] = ar->rx_bytes;
  2819. data[i++] = ar->tx_dropped;
  2820. data[i++] = ar->tx_failed;
  2821. data[i++] = ar->ps;
  2822. data[i++] = ar->group;
  2823. WARN_ON(i != MAC80211_HWSIM_SSTATS_LEN);
  2824. }
  2825. static int mac80211_hwsim_tx_last_beacon(struct ieee80211_hw *hw)
  2826. {
  2827. return 1;
  2828. }
  2829. static int mac80211_hwsim_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  2830. {
  2831. return -EOPNOTSUPP;
  2832. }
  2833. static int mac80211_hwsim_change_vif_links(struct ieee80211_hw *hw,
  2834. struct ieee80211_vif *vif,
  2835. u16 old_links, u16 new_links,
  2836. struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
  2837. {
  2838. unsigned long rem = old_links & ~new_links;
  2839. unsigned long add = new_links & ~old_links;
  2840. int i;
  2841. if (!old_links)
  2842. rem |= BIT(0);
  2843. if (!new_links)
  2844. add |= BIT(0);
  2845. for_each_set_bit(i, &rem, IEEE80211_MLD_MAX_NUM_LINKS)
  2846. mac80211_hwsim_config_mac_nl(hw, old[i]->addr, false);
  2847. for_each_set_bit(i, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
  2848. struct ieee80211_bss_conf *link_conf;
  2849. link_conf = link_conf_dereference_protected(vif, i);
  2850. if (WARN_ON(!link_conf))
  2851. continue;
  2852. mac80211_hwsim_config_mac_nl(hw, link_conf->addr, true);
  2853. }
  2854. return 0;
  2855. }
  2856. static int mac80211_hwsim_change_sta_links(struct ieee80211_hw *hw,
  2857. struct ieee80211_vif *vif,
  2858. struct ieee80211_sta *sta,
  2859. u16 old_links, u16 new_links)
  2860. {
  2861. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  2862. hwsim_check_sta_magic(sta);
  2863. if (vif->type == NL80211_IFTYPE_STATION)
  2864. sp->active_links_rx = new_links;
  2865. return 0;
  2866. }
  2867. static int mac80211_hwsim_send_pmsr_ftm_request_peer(struct sk_buff *msg,
  2868. struct cfg80211_pmsr_ftm_request_peer *request)
  2869. {
  2870. struct nlattr *ftm;
  2871. if (!request->requested)
  2872. return -EINVAL;
  2873. ftm = nla_nest_start(msg, NL80211_PMSR_TYPE_FTM);
  2874. if (!ftm)
  2875. return -ENOBUFS;
  2876. if (nla_put_u32(msg, NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE, request->preamble))
  2877. return -ENOBUFS;
  2878. if (nla_put_u16(msg, NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD, request->burst_period))
  2879. return -ENOBUFS;
  2880. if (request->asap && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_ASAP))
  2881. return -ENOBUFS;
  2882. if (request->request_lci && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI))
  2883. return -ENOBUFS;
  2884. if (request->request_civicloc &&
  2885. nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC))
  2886. return -ENOBUFS;
  2887. if (request->trigger_based && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED))
  2888. return -ENOBUFS;
  2889. if (request->non_trigger_based &&
  2890. nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED))
  2891. return -ENOBUFS;
  2892. if (request->lmr_feedback && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK))
  2893. return -ENOBUFS;
  2894. if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP, request->num_bursts_exp))
  2895. return -ENOBUFS;
  2896. if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION, request->burst_duration))
  2897. return -ENOBUFS;
  2898. if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST, request->ftms_per_burst))
  2899. return -ENOBUFS;
  2900. if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES, request->ftmr_retries))
  2901. return -ENOBUFS;
  2902. if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION, request->burst_duration))
  2903. return -ENOBUFS;
  2904. if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_BSS_COLOR, request->bss_color))
  2905. return -ENOBUFS;
  2906. nla_nest_end(msg, ftm);
  2907. return 0;
  2908. }
  2909. static int mac80211_hwsim_send_pmsr_request_peer(struct sk_buff *msg,
  2910. struct cfg80211_pmsr_request_peer *request)
  2911. {
  2912. struct nlattr *peer, *chandef, *req, *data;
  2913. int err;
  2914. peer = nla_nest_start(msg, NL80211_PMSR_ATTR_PEERS);
  2915. if (!peer)
  2916. return -ENOBUFS;
  2917. if (nla_put(msg, NL80211_PMSR_PEER_ATTR_ADDR, ETH_ALEN,
  2918. request->addr))
  2919. return -ENOBUFS;
  2920. chandef = nla_nest_start(msg, NL80211_PMSR_PEER_ATTR_CHAN);
  2921. if (!chandef)
  2922. return -ENOBUFS;
  2923. err = nl80211_send_chandef(msg, &request->chandef);
  2924. if (err)
  2925. return err;
  2926. nla_nest_end(msg, chandef);
  2927. req = nla_nest_start(msg, NL80211_PMSR_PEER_ATTR_REQ);
  2928. if (!req)
  2929. return -ENOBUFS;
  2930. if (request->report_ap_tsf && nla_put_flag(msg, NL80211_PMSR_REQ_ATTR_GET_AP_TSF))
  2931. return -ENOBUFS;
  2932. data = nla_nest_start(msg, NL80211_PMSR_REQ_ATTR_DATA);
  2933. if (!data)
  2934. return -ENOBUFS;
  2935. err = mac80211_hwsim_send_pmsr_ftm_request_peer(msg, &request->ftm);
  2936. if (err)
  2937. return err;
  2938. nla_nest_end(msg, data);
  2939. nla_nest_end(msg, req);
  2940. nla_nest_end(msg, peer);
  2941. return 0;
  2942. }
  2943. static int mac80211_hwsim_send_pmsr_request(struct sk_buff *msg,
  2944. struct cfg80211_pmsr_request *request)
  2945. {
  2946. struct nlattr *pmsr;
  2947. int err;
  2948. pmsr = nla_nest_start(msg, NL80211_ATTR_PEER_MEASUREMENTS);
  2949. if (!pmsr)
  2950. return -ENOBUFS;
  2951. if (nla_put_u32(msg, NL80211_ATTR_TIMEOUT, request->timeout))
  2952. return -ENOBUFS;
  2953. if (!is_zero_ether_addr(request->mac_addr)) {
  2954. if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, request->mac_addr))
  2955. return -ENOBUFS;
  2956. if (nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, request->mac_addr_mask))
  2957. return -ENOBUFS;
  2958. }
  2959. for (int i = 0; i < request->n_peers; i++) {
  2960. err = mac80211_hwsim_send_pmsr_request_peer(msg, &request->peers[i]);
  2961. if (err)
  2962. return err;
  2963. }
  2964. nla_nest_end(msg, pmsr);
  2965. return 0;
  2966. }
  2967. static int mac80211_hwsim_start_pmsr(struct ieee80211_hw *hw,
  2968. struct ieee80211_vif *vif,
  2969. struct cfg80211_pmsr_request *request)
  2970. {
  2971. struct mac80211_hwsim_data *data;
  2972. struct sk_buff *skb = NULL;
  2973. struct nlattr *pmsr;
  2974. void *msg_head;
  2975. u32 _portid;
  2976. int err = 0;
  2977. data = hw->priv;
  2978. _portid = READ_ONCE(data->wmediumd);
  2979. if (!_portid && !hwsim_virtio_enabled)
  2980. return -EOPNOTSUPP;
  2981. mutex_lock(&data->mutex);
  2982. if (data->pmsr_request) {
  2983. err = -EBUSY;
  2984. goto out_free;
  2985. }
  2986. skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2987. if (!skb) {
  2988. err = -ENOMEM;
  2989. goto out_free;
  2990. }
  2991. msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, HWSIM_CMD_START_PMSR);
  2992. if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
  2993. ETH_ALEN, data->addresses[1].addr)) {
  2994. err = -ENOMEM;
  2995. goto out_free;
  2996. }
  2997. pmsr = nla_nest_start(skb, HWSIM_ATTR_PMSR_REQUEST);
  2998. if (!pmsr) {
  2999. err = -ENOMEM;
  3000. goto out_free;
  3001. }
  3002. err = mac80211_hwsim_send_pmsr_request(skb, request);
  3003. if (err)
  3004. goto out_free;
  3005. nla_nest_end(skb, pmsr);
  3006. genlmsg_end(skb, msg_head);
  3007. if (hwsim_virtio_enabled)
  3008. hwsim_tx_virtio(data, skb);
  3009. else
  3010. hwsim_unicast_netgroup(data, skb, _portid);
  3011. data->pmsr_request = request;
  3012. data->pmsr_request_wdev = ieee80211_vif_to_wdev(vif);
  3013. out_free:
  3014. if (err && skb)
  3015. nlmsg_free(skb);
  3016. mutex_unlock(&data->mutex);
  3017. return err;
  3018. }
  3019. static void mac80211_hwsim_abort_pmsr(struct ieee80211_hw *hw,
  3020. struct ieee80211_vif *vif,
  3021. struct cfg80211_pmsr_request *request)
  3022. {
  3023. struct mac80211_hwsim_data *data;
  3024. struct sk_buff *skb = NULL;
  3025. struct nlattr *pmsr;
  3026. void *msg_head;
  3027. u32 _portid;
  3028. int err = 0;
  3029. data = hw->priv;
  3030. _portid = READ_ONCE(data->wmediumd);
  3031. if (!_portid && !hwsim_virtio_enabled)
  3032. return;
  3033. mutex_lock(&data->mutex);
  3034. if (data->pmsr_request != request) {
  3035. err = -EINVAL;
  3036. goto out;
  3037. }
  3038. skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
  3039. if (!skb) {
  3040. err = -ENOMEM;
  3041. goto out;
  3042. }
  3043. msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, HWSIM_CMD_ABORT_PMSR);
  3044. if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, ETH_ALEN, data->addresses[1].addr))
  3045. goto out;
  3046. pmsr = nla_nest_start(skb, HWSIM_ATTR_PMSR_REQUEST);
  3047. if (!pmsr) {
  3048. err = -ENOMEM;
  3049. goto out;
  3050. }
  3051. err = mac80211_hwsim_send_pmsr_request(skb, request);
  3052. if (err)
  3053. goto out;
  3054. err = nla_nest_end(skb, pmsr);
  3055. if (err)
  3056. goto out;
  3057. genlmsg_end(skb, msg_head);
  3058. if (hwsim_virtio_enabled)
  3059. hwsim_tx_virtio(data, skb);
  3060. else
  3061. hwsim_unicast_netgroup(data, skb, _portid);
  3062. out:
  3063. if (err && skb)
  3064. nlmsg_free(skb);
  3065. mutex_unlock(&data->mutex);
  3066. }
  3067. static int mac80211_hwsim_parse_rate_info(struct nlattr *rateattr,
  3068. struct rate_info *rate_info,
  3069. struct genl_info *info)
  3070. {
  3071. struct nlattr *tb[HWSIM_RATE_INFO_ATTR_MAX + 1];
  3072. int ret;
  3073. ret = nla_parse_nested(tb, HWSIM_RATE_INFO_ATTR_MAX,
  3074. rateattr, hwsim_rate_info_policy, info->extack);
  3075. if (ret)
  3076. return ret;
  3077. if (tb[HWSIM_RATE_INFO_ATTR_FLAGS])
  3078. rate_info->flags = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_FLAGS]);
  3079. if (tb[HWSIM_RATE_INFO_ATTR_MCS])
  3080. rate_info->mcs = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_MCS]);
  3081. if (tb[HWSIM_RATE_INFO_ATTR_LEGACY])
  3082. rate_info->legacy = nla_get_u16(tb[HWSIM_RATE_INFO_ATTR_LEGACY]);
  3083. if (tb[HWSIM_RATE_INFO_ATTR_NSS])
  3084. rate_info->nss = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_NSS]);
  3085. if (tb[HWSIM_RATE_INFO_ATTR_BW])
  3086. rate_info->bw = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_BW]);
  3087. if (tb[HWSIM_RATE_INFO_ATTR_HE_GI])
  3088. rate_info->he_gi = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_HE_GI]);
  3089. if (tb[HWSIM_RATE_INFO_ATTR_HE_DCM])
  3090. rate_info->he_dcm = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_HE_DCM]);
  3091. if (tb[HWSIM_RATE_INFO_ATTR_HE_RU_ALLOC])
  3092. rate_info->he_ru_alloc =
  3093. nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_HE_RU_ALLOC]);
  3094. if (tb[HWSIM_RATE_INFO_ATTR_N_BOUNDED_CH])
  3095. rate_info->n_bonded_ch = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_N_BOUNDED_CH]);
  3096. if (tb[HWSIM_RATE_INFO_ATTR_EHT_GI])
  3097. rate_info->eht_gi = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_EHT_GI]);
  3098. if (tb[HWSIM_RATE_INFO_ATTR_EHT_RU_ALLOC])
  3099. rate_info->eht_ru_alloc = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_EHT_RU_ALLOC]);
  3100. return 0;
  3101. }
  3102. static int mac80211_hwsim_parse_ftm_result(struct nlattr *ftm,
  3103. struct cfg80211_pmsr_ftm_result *result,
  3104. struct genl_info *info)
  3105. {
  3106. struct nlattr *tb[NL80211_PMSR_FTM_RESP_ATTR_MAX + 1];
  3107. int ret;
  3108. ret = nla_parse_nested(tb, NL80211_PMSR_FTM_RESP_ATTR_MAX,
  3109. ftm, hwsim_ftm_result_policy, info->extack);
  3110. if (ret)
  3111. return ret;
  3112. if (tb[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON])
  3113. result->failure_reason = nla_get_u32(tb[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON]);
  3114. if (tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX])
  3115. result->burst_index = nla_get_u16(tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX]);
  3116. if (tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS]) {
  3117. result->num_ftmr_attempts_valid = 1;
  3118. result->num_ftmr_attempts =
  3119. nla_get_u32(tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS]);
  3120. }
  3121. if (tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES]) {
  3122. result->num_ftmr_successes_valid = 1;
  3123. result->num_ftmr_successes =
  3124. nla_get_u32(tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES]);
  3125. }
  3126. if (tb[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME])
  3127. result->busy_retry_time =
  3128. nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME]);
  3129. if (tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP])
  3130. result->num_bursts_exp = nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP]);
  3131. if (tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION])
  3132. result->burst_duration = nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION]);
  3133. if (tb[NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST])
  3134. result->ftms_per_burst = nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST]);
  3135. if (tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG]) {
  3136. result->rssi_avg_valid = 1;
  3137. result->rssi_avg = nla_get_s32(tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG]);
  3138. }
  3139. if (tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD]) {
  3140. result->rssi_spread_valid = 1;
  3141. result->rssi_spread =
  3142. nla_get_s32(tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD]);
  3143. }
  3144. if (tb[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE]) {
  3145. result->tx_rate_valid = 1;
  3146. ret = mac80211_hwsim_parse_rate_info(tb[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE],
  3147. &result->tx_rate, info);
  3148. if (ret)
  3149. return ret;
  3150. }
  3151. if (tb[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE]) {
  3152. result->rx_rate_valid = 1;
  3153. ret = mac80211_hwsim_parse_rate_info(tb[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE],
  3154. &result->rx_rate, info);
  3155. if (ret)
  3156. return ret;
  3157. }
  3158. if (tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG]) {
  3159. result->rtt_avg_valid = 1;
  3160. result->rtt_avg =
  3161. nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG]);
  3162. }
  3163. if (tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE]) {
  3164. result->rtt_variance_valid = 1;
  3165. result->rtt_variance =
  3166. nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE]);
  3167. }
  3168. if (tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD]) {
  3169. result->rtt_spread_valid = 1;
  3170. result->rtt_spread =
  3171. nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD]);
  3172. }
  3173. if (tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG]) {
  3174. result->dist_avg_valid = 1;
  3175. result->dist_avg =
  3176. nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG]);
  3177. }
  3178. if (tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE]) {
  3179. result->dist_variance_valid = 1;
  3180. result->dist_variance =
  3181. nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE]);
  3182. }
  3183. if (tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD]) {
  3184. result->dist_spread_valid = 1;
  3185. result->dist_spread =
  3186. nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD]);
  3187. }
  3188. if (tb[NL80211_PMSR_FTM_RESP_ATTR_LCI]) {
  3189. result->lci = nla_data(tb[NL80211_PMSR_FTM_RESP_ATTR_LCI]);
  3190. result->lci_len = nla_len(tb[NL80211_PMSR_FTM_RESP_ATTR_LCI]);
  3191. }
  3192. if (tb[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]) {
  3193. result->civicloc = nla_data(tb[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]);
  3194. result->civicloc_len = nla_len(tb[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]);
  3195. }
  3196. return 0;
  3197. }
  3198. static int mac80211_hwsim_parse_pmsr_resp(struct nlattr *resp,
  3199. struct cfg80211_pmsr_result *result,
  3200. struct genl_info *info)
  3201. {
  3202. struct nlattr *tb[NL80211_PMSR_RESP_ATTR_MAX + 1];
  3203. struct nlattr *pmsr;
  3204. int rem;
  3205. int ret;
  3206. ret = nla_parse_nested(tb, NL80211_PMSR_RESP_ATTR_MAX, resp, hwsim_pmsr_resp_policy,
  3207. info->extack);
  3208. if (ret)
  3209. return ret;
  3210. if (tb[NL80211_PMSR_RESP_ATTR_STATUS])
  3211. result->status = nla_get_u32(tb[NL80211_PMSR_RESP_ATTR_STATUS]);
  3212. if (tb[NL80211_PMSR_RESP_ATTR_HOST_TIME])
  3213. result->host_time = nla_get_u64(tb[NL80211_PMSR_RESP_ATTR_HOST_TIME]);
  3214. if (tb[NL80211_PMSR_RESP_ATTR_AP_TSF]) {
  3215. result->ap_tsf_valid = 1;
  3216. result->ap_tsf = nla_get_u64(tb[NL80211_PMSR_RESP_ATTR_AP_TSF]);
  3217. }
  3218. result->final = !!tb[NL80211_PMSR_RESP_ATTR_FINAL];
  3219. if (!tb[NL80211_PMSR_RESP_ATTR_DATA])
  3220. return 0;
  3221. nla_for_each_nested(pmsr, tb[NL80211_PMSR_RESP_ATTR_DATA], rem) {
  3222. switch (nla_type(pmsr)) {
  3223. case NL80211_PMSR_TYPE_FTM:
  3224. result->type = NL80211_PMSR_TYPE_FTM;
  3225. ret = mac80211_hwsim_parse_ftm_result(pmsr, &result->ftm, info);
  3226. if (ret)
  3227. return ret;
  3228. break;
  3229. default:
  3230. NL_SET_ERR_MSG_ATTR(info->extack, pmsr, "Unknown pmsr resp type");
  3231. return -EINVAL;
  3232. }
  3233. }
  3234. return 0;
  3235. }
  3236. static int mac80211_hwsim_parse_pmsr_result(struct nlattr *peer,
  3237. struct cfg80211_pmsr_result *result,
  3238. struct genl_info *info)
  3239. {
  3240. struct nlattr *tb[NL80211_PMSR_PEER_ATTR_MAX + 1];
  3241. int ret;
  3242. if (!peer)
  3243. return -EINVAL;
  3244. ret = nla_parse_nested(tb, NL80211_PMSR_PEER_ATTR_MAX, peer,
  3245. hwsim_pmsr_peer_result_policy, info->extack);
  3246. if (ret)
  3247. return ret;
  3248. if (tb[NL80211_PMSR_PEER_ATTR_ADDR])
  3249. memcpy(result->addr, nla_data(tb[NL80211_PMSR_PEER_ATTR_ADDR]),
  3250. ETH_ALEN);
  3251. if (tb[NL80211_PMSR_PEER_ATTR_RESP]) {
  3252. ret = mac80211_hwsim_parse_pmsr_resp(tb[NL80211_PMSR_PEER_ATTR_RESP], result, info);
  3253. if (ret)
  3254. return ret;
  3255. }
  3256. return 0;
  3257. };
  3258. static int hwsim_pmsr_report_nl(struct sk_buff *msg, struct genl_info *info)
  3259. {
  3260. struct mac80211_hwsim_data *data;
  3261. struct nlattr *peers, *peer;
  3262. struct nlattr *reqattr;
  3263. const u8 *src;
  3264. int err;
  3265. int rem;
  3266. if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER])
  3267. return -EINVAL;
  3268. src = nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]);
  3269. data = get_hwsim_data_ref_from_addr(src);
  3270. if (!data)
  3271. return -EINVAL;
  3272. mutex_lock(&data->mutex);
  3273. if (!data->pmsr_request) {
  3274. err = -EINVAL;
  3275. goto out;
  3276. }
  3277. reqattr = info->attrs[HWSIM_ATTR_PMSR_RESULT];
  3278. if (!reqattr) {
  3279. err = -EINVAL;
  3280. goto out;
  3281. }
  3282. peers = nla_find_nested(reqattr, NL80211_PMSR_ATTR_PEERS);
  3283. if (!peers) {
  3284. err = -EINVAL;
  3285. goto out;
  3286. }
  3287. nla_for_each_nested(peer, peers, rem) {
  3288. struct cfg80211_pmsr_result result = {};
  3289. err = mac80211_hwsim_parse_pmsr_result(peer, &result, info);
  3290. if (err)
  3291. goto out;
  3292. cfg80211_pmsr_report(data->pmsr_request_wdev,
  3293. data->pmsr_request, &result, GFP_KERNEL);
  3294. }
  3295. cfg80211_pmsr_complete(data->pmsr_request_wdev, data->pmsr_request, GFP_KERNEL);
  3296. err = 0;
  3297. out:
  3298. data->pmsr_request = NULL;
  3299. data->pmsr_request_wdev = NULL;
  3300. mutex_unlock(&data->mutex);
  3301. return err;
  3302. }
  3303. #ifdef CONFIG_MAC80211_DEBUGFS
  3304. #define HWSIM_DEBUGFS_OPS \
  3305. .link_add_debugfs = mac80211_hwsim_link_add_debugfs,
  3306. #else
  3307. #define HWSIM_DEBUGFS_OPS
  3308. #endif
  3309. #define HWSIM_COMMON_OPS \
  3310. .tx = mac80211_hwsim_tx, \
  3311. .wake_tx_queue = ieee80211_handle_wake_tx_queue, \
  3312. .start = mac80211_hwsim_start, \
  3313. .stop = mac80211_hwsim_stop, \
  3314. .add_interface = mac80211_hwsim_add_interface, \
  3315. .change_interface = mac80211_hwsim_change_interface, \
  3316. .remove_interface = mac80211_hwsim_remove_interface, \
  3317. .config = mac80211_hwsim_config, \
  3318. .configure_filter = mac80211_hwsim_configure_filter, \
  3319. .vif_cfg_changed = mac80211_hwsim_vif_info_changed, \
  3320. .link_info_changed = mac80211_hwsim_link_info_changed, \
  3321. .tx_last_beacon = mac80211_hwsim_tx_last_beacon, \
  3322. .sta_notify = mac80211_hwsim_sta_notify, \
  3323. .sta_rc_update = mac80211_hwsim_sta_rc_update, \
  3324. .conf_tx = mac80211_hwsim_conf_tx, \
  3325. .get_survey = mac80211_hwsim_get_survey, \
  3326. CFG80211_TESTMODE_CMD(mac80211_hwsim_testmode_cmd) \
  3327. .ampdu_action = mac80211_hwsim_ampdu_action, \
  3328. .flush = mac80211_hwsim_flush, \
  3329. .get_et_sset_count = mac80211_hwsim_get_et_sset_count, \
  3330. .get_et_stats = mac80211_hwsim_get_et_stats, \
  3331. .get_et_strings = mac80211_hwsim_get_et_strings, \
  3332. .start_pmsr = mac80211_hwsim_start_pmsr, \
  3333. .abort_pmsr = mac80211_hwsim_abort_pmsr, \
  3334. HWSIM_DEBUGFS_OPS
  3335. #define HWSIM_NON_MLO_OPS \
  3336. .sta_add = mac80211_hwsim_sta_add, \
  3337. .sta_remove = mac80211_hwsim_sta_remove, \
  3338. .set_tim = mac80211_hwsim_set_tim, \
  3339. .get_tsf = mac80211_hwsim_get_tsf, \
  3340. .set_tsf = mac80211_hwsim_set_tsf,
  3341. static const struct ieee80211_ops mac80211_hwsim_ops = {
  3342. HWSIM_COMMON_OPS
  3343. HWSIM_NON_MLO_OPS
  3344. .sw_scan_start = mac80211_hwsim_sw_scan,
  3345. .sw_scan_complete = mac80211_hwsim_sw_scan_complete,
  3346. .add_chanctx = ieee80211_emulate_add_chanctx,
  3347. .remove_chanctx = ieee80211_emulate_remove_chanctx,
  3348. .change_chanctx = ieee80211_emulate_change_chanctx,
  3349. .switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx,
  3350. };
  3351. #define HWSIM_CHANCTX_OPS \
  3352. .hw_scan = mac80211_hwsim_hw_scan, \
  3353. .cancel_hw_scan = mac80211_hwsim_cancel_hw_scan, \
  3354. .remain_on_channel = mac80211_hwsim_roc, \
  3355. .cancel_remain_on_channel = mac80211_hwsim_croc, \
  3356. .add_chanctx = mac80211_hwsim_add_chanctx, \
  3357. .remove_chanctx = mac80211_hwsim_remove_chanctx, \
  3358. .change_chanctx = mac80211_hwsim_change_chanctx, \
  3359. .assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx,\
  3360. .unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx, \
  3361. .switch_vif_chanctx = mac80211_hwsim_switch_vif_chanctx,
  3362. static const struct ieee80211_ops mac80211_hwsim_mchan_ops = {
  3363. HWSIM_COMMON_OPS
  3364. HWSIM_NON_MLO_OPS
  3365. HWSIM_CHANCTX_OPS
  3366. };
  3367. static const struct ieee80211_ops mac80211_hwsim_mlo_ops = {
  3368. HWSIM_COMMON_OPS
  3369. HWSIM_CHANCTX_OPS
  3370. .set_rts_threshold = mac80211_hwsim_set_rts_threshold,
  3371. .change_vif_links = mac80211_hwsim_change_vif_links,
  3372. .change_sta_links = mac80211_hwsim_change_sta_links,
  3373. .sta_state = mac80211_hwsim_sta_state,
  3374. .can_neg_ttlm = mac80211_hwsim_can_neg_ttlm,
  3375. };
  3376. struct hwsim_new_radio_params {
  3377. unsigned int channels;
  3378. const char *reg_alpha2;
  3379. const struct ieee80211_regdomain *regd;
  3380. bool reg_strict;
  3381. bool p2p_device;
  3382. bool use_chanctx;
  3383. bool multi_radio;
  3384. bool destroy_on_close;
  3385. const char *hwname;
  3386. bool no_vif;
  3387. const u8 *perm_addr;
  3388. u32 iftypes;
  3389. u32 *ciphers;
  3390. u8 n_ciphers;
  3391. bool mlo;
  3392. const struct cfg80211_pmsr_capabilities *pmsr_capa;
  3393. };
  3394. static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb,
  3395. struct genl_info *info)
  3396. {
  3397. if (info)
  3398. genl_notify(&hwsim_genl_family, mcast_skb, info,
  3399. HWSIM_MCGRP_CONFIG, GFP_KERNEL);
  3400. else
  3401. genlmsg_multicast(&hwsim_genl_family, mcast_skb, 0,
  3402. HWSIM_MCGRP_CONFIG, GFP_KERNEL);
  3403. }
  3404. static int append_radio_msg(struct sk_buff *skb, int id,
  3405. struct hwsim_new_radio_params *param)
  3406. {
  3407. int ret;
  3408. ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
  3409. if (ret < 0)
  3410. return ret;
  3411. if (param->channels) {
  3412. ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels);
  3413. if (ret < 0)
  3414. return ret;
  3415. }
  3416. if (param->reg_alpha2) {
  3417. ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2,
  3418. param->reg_alpha2);
  3419. if (ret < 0)
  3420. return ret;
  3421. }
  3422. if (param->regd) {
  3423. int i;
  3424. for (i = 0; i < ARRAY_SIZE(hwsim_world_regdom_custom); i++) {
  3425. if (hwsim_world_regdom_custom[i] != param->regd)
  3426. continue;
  3427. ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i);
  3428. if (ret < 0)
  3429. return ret;
  3430. break;
  3431. }
  3432. }
  3433. if (param->reg_strict) {
  3434. ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG);
  3435. if (ret < 0)
  3436. return ret;
  3437. }
  3438. if (param->p2p_device) {
  3439. ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE);
  3440. if (ret < 0)
  3441. return ret;
  3442. }
  3443. if (param->use_chanctx) {
  3444. ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX);
  3445. if (ret < 0)
  3446. return ret;
  3447. }
  3448. if (param->multi_radio) {
  3449. ret = nla_put_flag(skb, HWSIM_ATTR_MULTI_RADIO);
  3450. if (ret < 0)
  3451. return ret;
  3452. }
  3453. if (param->hwname) {
  3454. ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME,
  3455. strlen(param->hwname), param->hwname);
  3456. if (ret < 0)
  3457. return ret;
  3458. }
  3459. return 0;
  3460. }
  3461. static void hwsim_mcast_new_radio(int id, struct genl_info *info,
  3462. struct hwsim_new_radio_params *param)
  3463. {
  3464. struct sk_buff *mcast_skb;
  3465. void *data;
  3466. mcast_skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
  3467. if (!mcast_skb)
  3468. return;
  3469. data = genlmsg_put(mcast_skb, 0, 0, &hwsim_genl_family, 0,
  3470. HWSIM_CMD_NEW_RADIO);
  3471. if (!data)
  3472. goto out_err;
  3473. if (append_radio_msg(mcast_skb, id, param) < 0)
  3474. goto out_err;
  3475. genlmsg_end(mcast_skb, data);
  3476. hwsim_mcast_config_msg(mcast_skb, info);
  3477. return;
  3478. out_err:
  3479. nlmsg_free(mcast_skb);
  3480. }
  3481. static const struct ieee80211_sband_iftype_data sband_capa_2ghz[] = {
  3482. {
  3483. .types_mask = BIT(NL80211_IFTYPE_STATION) |
  3484. BIT(NL80211_IFTYPE_P2P_CLIENT),
  3485. .he_cap = {
  3486. .has_he = true,
  3487. .he_cap_elem = {
  3488. .mac_cap_info[0] =
  3489. IEEE80211_HE_MAC_CAP0_HTC_HE,
  3490. .mac_cap_info[1] =
  3491. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  3492. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  3493. .mac_cap_info[2] =
  3494. IEEE80211_HE_MAC_CAP2_BSR |
  3495. IEEE80211_HE_MAC_CAP2_MU_CASCADING |
  3496. IEEE80211_HE_MAC_CAP2_ACK_EN,
  3497. .mac_cap_info[3] =
  3498. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  3499. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
  3500. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
  3501. .phy_cap_info[0] =
  3502. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G,
  3503. .phy_cap_info[1] =
  3504. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  3505. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  3506. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  3507. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
  3508. .phy_cap_info[2] =
  3509. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  3510. IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
  3511. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
  3512. IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
  3513. IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
  3514. /* Leave all the other PHY capability bytes
  3515. * unset, as DCM, beam forming, RU and PPE
  3516. * threshold information are not supported
  3517. */
  3518. },
  3519. .he_mcs_nss_supp = {
  3520. .rx_mcs_80 = cpu_to_le16(0xfffa),
  3521. .tx_mcs_80 = cpu_to_le16(0xfffa),
  3522. .rx_mcs_160 = cpu_to_le16(0xffff),
  3523. .tx_mcs_160 = cpu_to_le16(0xffff),
  3524. .rx_mcs_80p80 = cpu_to_le16(0xffff),
  3525. .tx_mcs_80p80 = cpu_to_le16(0xffff),
  3526. },
  3527. },
  3528. .eht_cap = {
  3529. .has_eht = true,
  3530. .eht_cap_elem = {
  3531. .mac_cap_info[0] =
  3532. IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
  3533. IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
  3534. IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
  3535. .phy_cap_info[0] =
  3536. IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
  3537. IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
  3538. IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
  3539. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
  3540. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE,
  3541. .phy_cap_info[3] =
  3542. IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
  3543. IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
  3544. IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
  3545. IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
  3546. IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
  3547. IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
  3548. IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
  3549. .phy_cap_info[4] =
  3550. IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
  3551. IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
  3552. IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
  3553. IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
  3554. IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
  3555. .phy_cap_info[5] =
  3556. IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
  3557. IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
  3558. IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
  3559. IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
  3560. IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
  3561. IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
  3562. .phy_cap_info[6] =
  3563. IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
  3564. IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
  3565. .phy_cap_info[7] =
  3566. IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW,
  3567. },
  3568. /* For all MCS and bandwidth, set 8 NSS for both Tx and
  3569. * Rx
  3570. */
  3571. .eht_mcs_nss_supp = {
  3572. /*
  3573. * Since B0, B1, B2 and B3 are not set in
  3574. * the supported channel width set field in the
  3575. * HE PHY capabilities information field the
  3576. * device is a 20MHz only device on 2.4GHz band.
  3577. */
  3578. .only_20mhz = {
  3579. .rx_tx_mcs7_max_nss = 0x88,
  3580. .rx_tx_mcs9_max_nss = 0x88,
  3581. .rx_tx_mcs11_max_nss = 0x88,
  3582. .rx_tx_mcs13_max_nss = 0x88,
  3583. },
  3584. },
  3585. /* PPE threshold information is not supported */
  3586. },
  3587. },
  3588. {
  3589. .types_mask = BIT(NL80211_IFTYPE_AP) |
  3590. BIT(NL80211_IFTYPE_P2P_GO),
  3591. .he_cap = {
  3592. .has_he = true,
  3593. .he_cap_elem = {
  3594. .mac_cap_info[0] =
  3595. IEEE80211_HE_MAC_CAP0_HTC_HE,
  3596. .mac_cap_info[1] =
  3597. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  3598. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  3599. .mac_cap_info[2] =
  3600. IEEE80211_HE_MAC_CAP2_BSR |
  3601. IEEE80211_HE_MAC_CAP2_MU_CASCADING |
  3602. IEEE80211_HE_MAC_CAP2_ACK_EN,
  3603. .mac_cap_info[3] =
  3604. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  3605. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
  3606. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
  3607. .phy_cap_info[0] =
  3608. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G,
  3609. .phy_cap_info[1] =
  3610. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  3611. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  3612. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  3613. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
  3614. .phy_cap_info[2] =
  3615. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  3616. IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
  3617. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
  3618. IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
  3619. IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
  3620. /* Leave all the other PHY capability bytes
  3621. * unset, as DCM, beam forming, RU and PPE
  3622. * threshold information are not supported
  3623. */
  3624. },
  3625. .he_mcs_nss_supp = {
  3626. .rx_mcs_80 = cpu_to_le16(0xfffa),
  3627. .tx_mcs_80 = cpu_to_le16(0xfffa),
  3628. .rx_mcs_160 = cpu_to_le16(0xffff),
  3629. .tx_mcs_160 = cpu_to_le16(0xffff),
  3630. .rx_mcs_80p80 = cpu_to_le16(0xffff),
  3631. .tx_mcs_80p80 = cpu_to_le16(0xffff),
  3632. },
  3633. },
  3634. .eht_cap = {
  3635. .has_eht = true,
  3636. .eht_cap_elem = {
  3637. .mac_cap_info[0] =
  3638. IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
  3639. IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
  3640. IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
  3641. .phy_cap_info[0] =
  3642. IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
  3643. IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
  3644. IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
  3645. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
  3646. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE,
  3647. .phy_cap_info[3] =
  3648. IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
  3649. IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
  3650. IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
  3651. IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
  3652. IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
  3653. IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
  3654. IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
  3655. .phy_cap_info[4] =
  3656. IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
  3657. IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
  3658. IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
  3659. IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
  3660. IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
  3661. .phy_cap_info[5] =
  3662. IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
  3663. IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
  3664. IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
  3665. IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
  3666. IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
  3667. IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
  3668. .phy_cap_info[6] =
  3669. IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
  3670. IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
  3671. .phy_cap_info[7] =
  3672. IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW,
  3673. },
  3674. /* For all MCS and bandwidth, set 8 NSS for both Tx and
  3675. * Rx
  3676. */
  3677. .eht_mcs_nss_supp = {
  3678. /*
  3679. * Since B0, B1, B2 and B3 are not set in
  3680. * the supported channel width set field in the
  3681. * HE PHY capabilities information field the
  3682. * device is a 20MHz only device on 2.4GHz band.
  3683. */
  3684. .only_20mhz = {
  3685. .rx_tx_mcs7_max_nss = 0x88,
  3686. .rx_tx_mcs9_max_nss = 0x88,
  3687. .rx_tx_mcs11_max_nss = 0x88,
  3688. .rx_tx_mcs13_max_nss = 0x88,
  3689. },
  3690. },
  3691. /* PPE threshold information is not supported */
  3692. },
  3693. },
  3694. #ifdef CONFIG_MAC80211_MESH
  3695. {
  3696. .types_mask = BIT(NL80211_IFTYPE_MESH_POINT),
  3697. .he_cap = {
  3698. .has_he = true,
  3699. .he_cap_elem = {
  3700. .mac_cap_info[0] =
  3701. IEEE80211_HE_MAC_CAP0_HTC_HE,
  3702. .mac_cap_info[1] =
  3703. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  3704. .mac_cap_info[2] =
  3705. IEEE80211_HE_MAC_CAP2_ACK_EN,
  3706. .mac_cap_info[3] =
  3707. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  3708. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
  3709. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
  3710. .phy_cap_info[0] =
  3711. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G,
  3712. .phy_cap_info[1] =
  3713. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  3714. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  3715. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  3716. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
  3717. .phy_cap_info[2] = 0,
  3718. /* Leave all the other PHY capability bytes
  3719. * unset, as DCM, beam forming, RU and PPE
  3720. * threshold information are not supported
  3721. */
  3722. },
  3723. .he_mcs_nss_supp = {
  3724. .rx_mcs_80 = cpu_to_le16(0xfffa),
  3725. .tx_mcs_80 = cpu_to_le16(0xfffa),
  3726. .rx_mcs_160 = cpu_to_le16(0xffff),
  3727. .tx_mcs_160 = cpu_to_le16(0xffff),
  3728. .rx_mcs_80p80 = cpu_to_le16(0xffff),
  3729. .tx_mcs_80p80 = cpu_to_le16(0xffff),
  3730. },
  3731. },
  3732. },
  3733. #endif
  3734. };
  3735. static const struct ieee80211_sband_iftype_data sband_capa_5ghz[] = {
  3736. {
  3737. .types_mask = BIT(NL80211_IFTYPE_STATION) |
  3738. BIT(NL80211_IFTYPE_P2P_CLIENT),
  3739. .he_cap = {
  3740. .has_he = true,
  3741. .he_cap_elem = {
  3742. .mac_cap_info[0] =
  3743. IEEE80211_HE_MAC_CAP0_HTC_HE,
  3744. .mac_cap_info[1] =
  3745. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  3746. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  3747. .mac_cap_info[2] =
  3748. IEEE80211_HE_MAC_CAP2_BSR |
  3749. IEEE80211_HE_MAC_CAP2_MU_CASCADING |
  3750. IEEE80211_HE_MAC_CAP2_ACK_EN,
  3751. .mac_cap_info[3] =
  3752. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  3753. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
  3754. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
  3755. .phy_cap_info[0] =
  3756. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  3757. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
  3758. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
  3759. .phy_cap_info[1] =
  3760. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  3761. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  3762. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  3763. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
  3764. .phy_cap_info[2] =
  3765. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  3766. IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
  3767. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
  3768. IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
  3769. IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
  3770. /* Leave all the other PHY capability bytes
  3771. * unset, as DCM, beam forming, RU and PPE
  3772. * threshold information are not supported
  3773. */
  3774. },
  3775. .he_mcs_nss_supp = {
  3776. .rx_mcs_80 = cpu_to_le16(0xfffa),
  3777. .tx_mcs_80 = cpu_to_le16(0xfffa),
  3778. .rx_mcs_160 = cpu_to_le16(0xfffa),
  3779. .tx_mcs_160 = cpu_to_le16(0xfffa),
  3780. .rx_mcs_80p80 = cpu_to_le16(0xfffa),
  3781. .tx_mcs_80p80 = cpu_to_le16(0xfffa),
  3782. },
  3783. },
  3784. .eht_cap = {
  3785. .has_eht = true,
  3786. .eht_cap_elem = {
  3787. .mac_cap_info[0] =
  3788. IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
  3789. IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
  3790. IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
  3791. .phy_cap_info[0] =
  3792. IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
  3793. IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
  3794. IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
  3795. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
  3796. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
  3797. IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
  3798. .phy_cap_info[1] =
  3799. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
  3800. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK,
  3801. .phy_cap_info[2] =
  3802. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
  3803. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK,
  3804. .phy_cap_info[3] =
  3805. IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
  3806. IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
  3807. IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
  3808. IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
  3809. IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
  3810. IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
  3811. IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
  3812. .phy_cap_info[4] =
  3813. IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
  3814. IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
  3815. IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
  3816. IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
  3817. IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
  3818. .phy_cap_info[5] =
  3819. IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
  3820. IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
  3821. IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
  3822. IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
  3823. IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
  3824. IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
  3825. .phy_cap_info[6] =
  3826. IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
  3827. IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
  3828. .phy_cap_info[7] =
  3829. IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
  3830. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
  3831. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
  3832. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
  3833. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ,
  3834. },
  3835. /* For all MCS and bandwidth, set 8 NSS for both Tx and
  3836. * Rx
  3837. */
  3838. .eht_mcs_nss_supp = {
  3839. /*
  3840. * As B1 and B2 are set in the supported
  3841. * channel width set field in the HE PHY
  3842. * capabilities information field include all
  3843. * the following MCS/NSS.
  3844. */
  3845. .bw._80 = {
  3846. .rx_tx_mcs9_max_nss = 0x88,
  3847. .rx_tx_mcs11_max_nss = 0x88,
  3848. .rx_tx_mcs13_max_nss = 0x88,
  3849. },
  3850. .bw._160 = {
  3851. .rx_tx_mcs9_max_nss = 0x88,
  3852. .rx_tx_mcs11_max_nss = 0x88,
  3853. .rx_tx_mcs13_max_nss = 0x88,
  3854. },
  3855. },
  3856. /* PPE threshold information is not supported */
  3857. },
  3858. },
  3859. {
  3860. .types_mask = BIT(NL80211_IFTYPE_AP) |
  3861. BIT(NL80211_IFTYPE_P2P_GO),
  3862. .he_cap = {
  3863. .has_he = true,
  3864. .he_cap_elem = {
  3865. .mac_cap_info[0] =
  3866. IEEE80211_HE_MAC_CAP0_HTC_HE,
  3867. .mac_cap_info[1] =
  3868. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  3869. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  3870. .mac_cap_info[2] =
  3871. IEEE80211_HE_MAC_CAP2_BSR |
  3872. IEEE80211_HE_MAC_CAP2_MU_CASCADING |
  3873. IEEE80211_HE_MAC_CAP2_ACK_EN,
  3874. .mac_cap_info[3] =
  3875. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  3876. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
  3877. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
  3878. .phy_cap_info[0] =
  3879. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  3880. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
  3881. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
  3882. .phy_cap_info[1] =
  3883. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  3884. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  3885. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  3886. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
  3887. .phy_cap_info[2] =
  3888. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  3889. IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
  3890. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
  3891. IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
  3892. IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
  3893. /* Leave all the other PHY capability bytes
  3894. * unset, as DCM, beam forming, RU and PPE
  3895. * threshold information are not supported
  3896. */
  3897. },
  3898. .he_mcs_nss_supp = {
  3899. .rx_mcs_80 = cpu_to_le16(0xfffa),
  3900. .tx_mcs_80 = cpu_to_le16(0xfffa),
  3901. .rx_mcs_160 = cpu_to_le16(0xfffa),
  3902. .tx_mcs_160 = cpu_to_le16(0xfffa),
  3903. .rx_mcs_80p80 = cpu_to_le16(0xfffa),
  3904. .tx_mcs_80p80 = cpu_to_le16(0xfffa),
  3905. },
  3906. },
  3907. .eht_cap = {
  3908. .has_eht = true,
  3909. .eht_cap_elem = {
  3910. .mac_cap_info[0] =
  3911. IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
  3912. IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
  3913. IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
  3914. .phy_cap_info[0] =
  3915. IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
  3916. IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
  3917. IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
  3918. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
  3919. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
  3920. IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
  3921. .phy_cap_info[1] =
  3922. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
  3923. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK,
  3924. .phy_cap_info[2] =
  3925. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
  3926. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK,
  3927. .phy_cap_info[3] =
  3928. IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
  3929. IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
  3930. IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
  3931. IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
  3932. IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
  3933. IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
  3934. IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
  3935. .phy_cap_info[4] =
  3936. IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
  3937. IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
  3938. IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
  3939. IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
  3940. IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
  3941. .phy_cap_info[5] =
  3942. IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
  3943. IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
  3944. IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
  3945. IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
  3946. IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
  3947. IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
  3948. .phy_cap_info[6] =
  3949. IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
  3950. IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
  3951. .phy_cap_info[7] =
  3952. IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
  3953. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
  3954. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
  3955. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
  3956. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ,
  3957. },
  3958. /* For all MCS and bandwidth, set 8 NSS for both Tx and
  3959. * Rx
  3960. */
  3961. .eht_mcs_nss_supp = {
  3962. /*
  3963. * As B1 and B2 are set in the supported
  3964. * channel width set field in the HE PHY
  3965. * capabilities information field include all
  3966. * the following MCS/NSS.
  3967. */
  3968. .bw._80 = {
  3969. .rx_tx_mcs9_max_nss = 0x88,
  3970. .rx_tx_mcs11_max_nss = 0x88,
  3971. .rx_tx_mcs13_max_nss = 0x88,
  3972. },
  3973. .bw._160 = {
  3974. .rx_tx_mcs9_max_nss = 0x88,
  3975. .rx_tx_mcs11_max_nss = 0x88,
  3976. .rx_tx_mcs13_max_nss = 0x88,
  3977. },
  3978. },
  3979. /* PPE threshold information is not supported */
  3980. },
  3981. },
  3982. #ifdef CONFIG_MAC80211_MESH
  3983. {
  3984. /* TODO: should we support other types, e.g., IBSS?*/
  3985. .types_mask = BIT(NL80211_IFTYPE_MESH_POINT),
  3986. .he_cap = {
  3987. .has_he = true,
  3988. .he_cap_elem = {
  3989. .mac_cap_info[0] =
  3990. IEEE80211_HE_MAC_CAP0_HTC_HE,
  3991. .mac_cap_info[1] =
  3992. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  3993. .mac_cap_info[2] =
  3994. IEEE80211_HE_MAC_CAP2_ACK_EN,
  3995. .mac_cap_info[3] =
  3996. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  3997. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
  3998. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
  3999. .phy_cap_info[0] =
  4000. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  4001. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
  4002. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
  4003. .phy_cap_info[1] =
  4004. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  4005. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  4006. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  4007. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
  4008. .phy_cap_info[2] = 0,
  4009. /* Leave all the other PHY capability bytes
  4010. * unset, as DCM, beam forming, RU and PPE
  4011. * threshold information are not supported
  4012. */
  4013. },
  4014. .he_mcs_nss_supp = {
  4015. .rx_mcs_80 = cpu_to_le16(0xfffa),
  4016. .tx_mcs_80 = cpu_to_le16(0xfffa),
  4017. .rx_mcs_160 = cpu_to_le16(0xfffa),
  4018. .tx_mcs_160 = cpu_to_le16(0xfffa),
  4019. .rx_mcs_80p80 = cpu_to_le16(0xfffa),
  4020. .tx_mcs_80p80 = cpu_to_le16(0xfffa),
  4021. },
  4022. },
  4023. },
  4024. #endif
  4025. };
  4026. static const struct ieee80211_sband_iftype_data sband_capa_6ghz[] = {
  4027. {
  4028. .types_mask = BIT(NL80211_IFTYPE_STATION) |
  4029. BIT(NL80211_IFTYPE_P2P_CLIENT),
  4030. .he_6ghz_capa = {
  4031. .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START |
  4032. IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP |
  4033. IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN |
  4034. IEEE80211_HE_6GHZ_CAP_SM_PS |
  4035. IEEE80211_HE_6GHZ_CAP_RD_RESPONDER |
  4036. IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
  4037. IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS),
  4038. },
  4039. .he_cap = {
  4040. .has_he = true,
  4041. .he_cap_elem = {
  4042. .mac_cap_info[0] =
  4043. IEEE80211_HE_MAC_CAP0_HTC_HE,
  4044. .mac_cap_info[1] =
  4045. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  4046. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  4047. .mac_cap_info[2] =
  4048. IEEE80211_HE_MAC_CAP2_BSR |
  4049. IEEE80211_HE_MAC_CAP2_MU_CASCADING |
  4050. IEEE80211_HE_MAC_CAP2_ACK_EN,
  4051. .mac_cap_info[3] =
  4052. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  4053. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
  4054. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
  4055. .phy_cap_info[0] =
  4056. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  4057. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
  4058. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
  4059. .phy_cap_info[1] =
  4060. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  4061. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  4062. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  4063. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
  4064. .phy_cap_info[2] =
  4065. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  4066. IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
  4067. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
  4068. IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
  4069. IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
  4070. /* Leave all the other PHY capability bytes
  4071. * unset, as DCM, beam forming, RU and PPE
  4072. * threshold information are not supported
  4073. */
  4074. },
  4075. .he_mcs_nss_supp = {
  4076. .rx_mcs_80 = cpu_to_le16(0xfffa),
  4077. .tx_mcs_80 = cpu_to_le16(0xfffa),
  4078. .rx_mcs_160 = cpu_to_le16(0xfffa),
  4079. .tx_mcs_160 = cpu_to_le16(0xfffa),
  4080. .rx_mcs_80p80 = cpu_to_le16(0xfffa),
  4081. .tx_mcs_80p80 = cpu_to_le16(0xfffa),
  4082. },
  4083. },
  4084. .eht_cap = {
  4085. .has_eht = true,
  4086. .eht_cap_elem = {
  4087. .mac_cap_info[0] =
  4088. IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
  4089. IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
  4090. IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
  4091. .phy_cap_info[0] =
  4092. IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ |
  4093. IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
  4094. IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
  4095. IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
  4096. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
  4097. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
  4098. IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
  4099. .phy_cap_info[1] =
  4100. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
  4101. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK |
  4102. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK,
  4103. .phy_cap_info[2] =
  4104. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
  4105. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK |
  4106. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK,
  4107. .phy_cap_info[3] =
  4108. IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
  4109. IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
  4110. IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
  4111. IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
  4112. IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
  4113. IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
  4114. IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
  4115. .phy_cap_info[4] =
  4116. IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
  4117. IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
  4118. IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
  4119. IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
  4120. IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
  4121. .phy_cap_info[5] =
  4122. IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
  4123. IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
  4124. IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
  4125. IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
  4126. IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
  4127. IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
  4128. .phy_cap_info[6] =
  4129. IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
  4130. IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK |
  4131. IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP,
  4132. .phy_cap_info[7] =
  4133. IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
  4134. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
  4135. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
  4136. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ |
  4137. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
  4138. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
  4139. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ,
  4140. },
  4141. /* For all MCS and bandwidth, set 8 NSS for both Tx and
  4142. * Rx
  4143. */
  4144. .eht_mcs_nss_supp = {
  4145. /*
  4146. * As B1 and B2 are set in the supported
  4147. * channel width set field in the HE PHY
  4148. * capabilities information field and 320MHz in
  4149. * 6GHz is supported include all the following
  4150. * MCS/NSS.
  4151. */
  4152. .bw._80 = {
  4153. .rx_tx_mcs9_max_nss = 0x88,
  4154. .rx_tx_mcs11_max_nss = 0x88,
  4155. .rx_tx_mcs13_max_nss = 0x88,
  4156. },
  4157. .bw._160 = {
  4158. .rx_tx_mcs9_max_nss = 0x88,
  4159. .rx_tx_mcs11_max_nss = 0x88,
  4160. .rx_tx_mcs13_max_nss = 0x88,
  4161. },
  4162. .bw._320 = {
  4163. .rx_tx_mcs9_max_nss = 0x88,
  4164. .rx_tx_mcs11_max_nss = 0x88,
  4165. .rx_tx_mcs13_max_nss = 0x88,
  4166. },
  4167. },
  4168. /* PPE threshold information is not supported */
  4169. },
  4170. },
  4171. {
  4172. .types_mask = BIT(NL80211_IFTYPE_AP) |
  4173. BIT(NL80211_IFTYPE_P2P_GO),
  4174. .he_6ghz_capa = {
  4175. .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START |
  4176. IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP |
  4177. IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN |
  4178. IEEE80211_HE_6GHZ_CAP_SM_PS |
  4179. IEEE80211_HE_6GHZ_CAP_RD_RESPONDER |
  4180. IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
  4181. IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS),
  4182. },
  4183. .he_cap = {
  4184. .has_he = true,
  4185. .he_cap_elem = {
  4186. .mac_cap_info[0] =
  4187. IEEE80211_HE_MAC_CAP0_HTC_HE,
  4188. .mac_cap_info[1] =
  4189. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  4190. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  4191. .mac_cap_info[2] =
  4192. IEEE80211_HE_MAC_CAP2_BSR |
  4193. IEEE80211_HE_MAC_CAP2_MU_CASCADING |
  4194. IEEE80211_HE_MAC_CAP2_ACK_EN,
  4195. .mac_cap_info[3] =
  4196. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  4197. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
  4198. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
  4199. .phy_cap_info[0] =
  4200. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  4201. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
  4202. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
  4203. .phy_cap_info[1] =
  4204. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  4205. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  4206. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  4207. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
  4208. .phy_cap_info[2] =
  4209. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  4210. IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
  4211. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
  4212. IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
  4213. IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
  4214. /* Leave all the other PHY capability bytes
  4215. * unset, as DCM, beam forming, RU and PPE
  4216. * threshold information are not supported
  4217. */
  4218. },
  4219. .he_mcs_nss_supp = {
  4220. .rx_mcs_80 = cpu_to_le16(0xfffa),
  4221. .tx_mcs_80 = cpu_to_le16(0xfffa),
  4222. .rx_mcs_160 = cpu_to_le16(0xfffa),
  4223. .tx_mcs_160 = cpu_to_le16(0xfffa),
  4224. .rx_mcs_80p80 = cpu_to_le16(0xfffa),
  4225. .tx_mcs_80p80 = cpu_to_le16(0xfffa),
  4226. },
  4227. },
  4228. .eht_cap = {
  4229. .has_eht = true,
  4230. .eht_cap_elem = {
  4231. .mac_cap_info[0] =
  4232. IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
  4233. IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
  4234. IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
  4235. .phy_cap_info[0] =
  4236. IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ |
  4237. IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
  4238. IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
  4239. IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
  4240. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
  4241. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
  4242. IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
  4243. .phy_cap_info[1] =
  4244. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
  4245. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK |
  4246. IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK,
  4247. .phy_cap_info[2] =
  4248. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
  4249. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK |
  4250. IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK,
  4251. .phy_cap_info[3] =
  4252. IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
  4253. IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
  4254. IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
  4255. IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
  4256. IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
  4257. IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
  4258. IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
  4259. .phy_cap_info[4] =
  4260. IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
  4261. IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
  4262. IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
  4263. IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
  4264. IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
  4265. .phy_cap_info[5] =
  4266. IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
  4267. IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
  4268. IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
  4269. IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
  4270. IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
  4271. IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
  4272. .phy_cap_info[6] =
  4273. IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
  4274. IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK |
  4275. IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP,
  4276. .phy_cap_info[7] =
  4277. IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
  4278. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
  4279. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
  4280. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ |
  4281. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
  4282. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
  4283. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ,
  4284. },
  4285. /* For all MCS and bandwidth, set 8 NSS for both Tx and
  4286. * Rx
  4287. */
  4288. .eht_mcs_nss_supp = {
  4289. /*
  4290. * As B1 and B2 are set in the supported
  4291. * channel width set field in the HE PHY
  4292. * capabilities information field and 320MHz in
  4293. * 6GHz is supported include all the following
  4294. * MCS/NSS.
  4295. */
  4296. .bw._80 = {
  4297. .rx_tx_mcs9_max_nss = 0x88,
  4298. .rx_tx_mcs11_max_nss = 0x88,
  4299. .rx_tx_mcs13_max_nss = 0x88,
  4300. },
  4301. .bw._160 = {
  4302. .rx_tx_mcs9_max_nss = 0x88,
  4303. .rx_tx_mcs11_max_nss = 0x88,
  4304. .rx_tx_mcs13_max_nss = 0x88,
  4305. },
  4306. .bw._320 = {
  4307. .rx_tx_mcs9_max_nss = 0x88,
  4308. .rx_tx_mcs11_max_nss = 0x88,
  4309. .rx_tx_mcs13_max_nss = 0x88,
  4310. },
  4311. },
  4312. /* PPE threshold information is not supported */
  4313. },
  4314. },
  4315. #ifdef CONFIG_MAC80211_MESH
  4316. {
  4317. /* TODO: should we support other types, e.g., IBSS?*/
  4318. .types_mask = BIT(NL80211_IFTYPE_MESH_POINT),
  4319. .he_6ghz_capa = {
  4320. .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START |
  4321. IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP |
  4322. IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN |
  4323. IEEE80211_HE_6GHZ_CAP_SM_PS |
  4324. IEEE80211_HE_6GHZ_CAP_RD_RESPONDER |
  4325. IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
  4326. IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS),
  4327. },
  4328. .he_cap = {
  4329. .has_he = true,
  4330. .he_cap_elem = {
  4331. .mac_cap_info[0] =
  4332. IEEE80211_HE_MAC_CAP0_HTC_HE,
  4333. .mac_cap_info[1] =
  4334. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  4335. .mac_cap_info[2] =
  4336. IEEE80211_HE_MAC_CAP2_ACK_EN,
  4337. .mac_cap_info[3] =
  4338. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  4339. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
  4340. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
  4341. .phy_cap_info[0] =
  4342. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  4343. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
  4344. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
  4345. .phy_cap_info[1] =
  4346. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  4347. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  4348. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  4349. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
  4350. .phy_cap_info[2] = 0,
  4351. /* Leave all the other PHY capability bytes
  4352. * unset, as DCM, beam forming, RU and PPE
  4353. * threshold information are not supported
  4354. */
  4355. },
  4356. .he_mcs_nss_supp = {
  4357. .rx_mcs_80 = cpu_to_le16(0xfffa),
  4358. .tx_mcs_80 = cpu_to_le16(0xfffa),
  4359. .rx_mcs_160 = cpu_to_le16(0xfffa),
  4360. .tx_mcs_160 = cpu_to_le16(0xfffa),
  4361. .rx_mcs_80p80 = cpu_to_le16(0xfffa),
  4362. .tx_mcs_80p80 = cpu_to_le16(0xfffa),
  4363. },
  4364. },
  4365. },
  4366. #endif
  4367. };
  4368. static void mac80211_hwsim_sband_capab(struct ieee80211_supported_band *sband)
  4369. {
  4370. switch (sband->band) {
  4371. case NL80211_BAND_2GHZ:
  4372. ieee80211_set_sband_iftype_data(sband, sband_capa_2ghz);
  4373. break;
  4374. case NL80211_BAND_5GHZ:
  4375. ieee80211_set_sband_iftype_data(sband, sband_capa_5ghz);
  4376. break;
  4377. case NL80211_BAND_6GHZ:
  4378. ieee80211_set_sband_iftype_data(sband, sband_capa_6ghz);
  4379. break;
  4380. default:
  4381. break;
  4382. }
  4383. }
  4384. #ifdef CONFIG_MAC80211_MESH
  4385. #define HWSIM_MESH_BIT BIT(NL80211_IFTYPE_MESH_POINT)
  4386. #else
  4387. #define HWSIM_MESH_BIT 0
  4388. #endif
  4389. #define HWSIM_DEFAULT_IF_LIMIT \
  4390. (BIT(NL80211_IFTYPE_STATION) | \
  4391. BIT(NL80211_IFTYPE_P2P_CLIENT) | \
  4392. BIT(NL80211_IFTYPE_AP) | \
  4393. BIT(NL80211_IFTYPE_P2P_GO) | \
  4394. HWSIM_MESH_BIT)
  4395. #define HWSIM_IFTYPE_SUPPORT_MASK \
  4396. (BIT(NL80211_IFTYPE_STATION) | \
  4397. BIT(NL80211_IFTYPE_AP) | \
  4398. BIT(NL80211_IFTYPE_P2P_CLIENT) | \
  4399. BIT(NL80211_IFTYPE_P2P_GO) | \
  4400. BIT(NL80211_IFTYPE_ADHOC) | \
  4401. BIT(NL80211_IFTYPE_MESH_POINT) | \
  4402. BIT(NL80211_IFTYPE_OCB))
  4403. static const u8 iftypes_ext_capa_ap[] = {
  4404. [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
  4405. [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
  4406. [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF |
  4407. WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB,
  4408. [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB,
  4409. [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT,
  4410. };
  4411. #define MAC80211_HWSIM_MLD_CAPA_OPS \
  4412. FIELD_PREP_CONST(IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP, \
  4413. IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME) | \
  4414. FIELD_PREP_CONST(IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS, \
  4415. IEEE80211_MLD_MAX_NUM_LINKS - 1)
  4416. static const struct wiphy_iftype_ext_capab mac80211_hwsim_iftypes_ext_capa[] = {
  4417. {
  4418. .iftype = NL80211_IFTYPE_AP,
  4419. .extended_capabilities = iftypes_ext_capa_ap,
  4420. .extended_capabilities_mask = iftypes_ext_capa_ap,
  4421. .extended_capabilities_len = sizeof(iftypes_ext_capa_ap),
  4422. .eml_capabilities = IEEE80211_EML_CAP_EMLSR_SUPP |
  4423. IEEE80211_EML_CAP_EMLMR_SUPPORT,
  4424. .mld_capa_and_ops = MAC80211_HWSIM_MLD_CAPA_OPS,
  4425. },
  4426. };
  4427. static int mac80211_hwsim_new_radio(struct genl_info *info,
  4428. struct hwsim_new_radio_params *param)
  4429. {
  4430. int err;
  4431. u8 addr[ETH_ALEN];
  4432. struct mac80211_hwsim_data *data;
  4433. struct ieee80211_hw *hw;
  4434. enum nl80211_band band;
  4435. const struct ieee80211_ops *ops = &mac80211_hwsim_ops;
  4436. struct net *net;
  4437. int idx, i;
  4438. int n_limits = 0;
  4439. int n_bands = 0;
  4440. if (WARN_ON(param->channels > 1 && !param->use_chanctx))
  4441. return -EINVAL;
  4442. spin_lock_bh(&hwsim_radio_lock);
  4443. idx = hwsim_radio_idx++;
  4444. spin_unlock_bh(&hwsim_radio_lock);
  4445. if (param->mlo)
  4446. ops = &mac80211_hwsim_mlo_ops;
  4447. else if (param->use_chanctx)
  4448. ops = &mac80211_hwsim_mchan_ops;
  4449. hw = ieee80211_alloc_hw_nm(sizeof(*data), ops, param->hwname);
  4450. if (!hw) {
  4451. pr_debug("mac80211_hwsim: ieee80211_alloc_hw failed\n");
  4452. err = -ENOMEM;
  4453. goto failed;
  4454. }
  4455. /* ieee80211_alloc_hw_nm may have used a default name */
  4456. param->hwname = wiphy_name(hw->wiphy);
  4457. if (info)
  4458. net = genl_info_net(info);
  4459. else
  4460. net = &init_net;
  4461. wiphy_net_set(hw->wiphy, net);
  4462. data = hw->priv;
  4463. data->hw = hw;
  4464. data->dev = device_create(hwsim_class, NULL, 0, hw, "hwsim%d", idx);
  4465. if (IS_ERR(data->dev)) {
  4466. printk(KERN_DEBUG
  4467. "mac80211_hwsim: device_create failed (%ld)\n",
  4468. PTR_ERR(data->dev));
  4469. err = -ENOMEM;
  4470. goto failed_drvdata;
  4471. }
  4472. data->dev->driver = &mac80211_hwsim_driver.driver;
  4473. err = device_bind_driver(data->dev);
  4474. if (err != 0) {
  4475. pr_debug("mac80211_hwsim: device_bind_driver failed (%d)\n",
  4476. err);
  4477. goto failed_bind;
  4478. }
  4479. skb_queue_head_init(&data->pending);
  4480. SET_IEEE80211_DEV(hw, data->dev);
  4481. if (!param->perm_addr) {
  4482. eth_zero_addr(addr);
  4483. addr[0] = 0x02;
  4484. addr[3] = idx >> 8;
  4485. addr[4] = idx;
  4486. memcpy(data->addresses[0].addr, addr, ETH_ALEN);
  4487. /* Why need here second address ? */
  4488. memcpy(data->addresses[1].addr, addr, ETH_ALEN);
  4489. data->addresses[1].addr[0] |= 0x40;
  4490. hw->wiphy->n_addresses = 2;
  4491. hw->wiphy->addresses = data->addresses;
  4492. /* possible address clash is checked at hash table insertion */
  4493. } else {
  4494. memcpy(data->addresses[0].addr, param->perm_addr, ETH_ALEN);
  4495. /* compatibility with automatically generated mac addr */
  4496. memcpy(data->addresses[1].addr, param->perm_addr, ETH_ALEN);
  4497. hw->wiphy->n_addresses = 2;
  4498. hw->wiphy->addresses = data->addresses;
  4499. }
  4500. data->channels = param->channels;
  4501. data->use_chanctx = param->use_chanctx;
  4502. data->idx = idx;
  4503. data->destroy_on_close = param->destroy_on_close;
  4504. if (info)
  4505. data->portid = info->snd_portid;
  4506. /* setup interface limits, only on interface types we support */
  4507. if (param->iftypes & BIT(NL80211_IFTYPE_ADHOC)) {
  4508. data->if_limits[n_limits].max = 1;
  4509. data->if_limits[n_limits].types = BIT(NL80211_IFTYPE_ADHOC);
  4510. n_limits++;
  4511. }
  4512. if (param->iftypes & HWSIM_DEFAULT_IF_LIMIT) {
  4513. data->if_limits[n_limits].max = 2048;
  4514. /*
  4515. * For this case, we may only support a subset of
  4516. * HWSIM_DEFAULT_IF_LIMIT, therefore we only want to add the
  4517. * bits that both param->iftype & HWSIM_DEFAULT_IF_LIMIT have.
  4518. */
  4519. data->if_limits[n_limits].types =
  4520. HWSIM_DEFAULT_IF_LIMIT & param->iftypes;
  4521. n_limits++;
  4522. }
  4523. if (param->iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) {
  4524. data->if_limits[n_limits].max = 1;
  4525. data->if_limits[n_limits].types =
  4526. BIT(NL80211_IFTYPE_P2P_DEVICE);
  4527. n_limits++;
  4528. }
  4529. data->if_combination.radar_detect_widths =
  4530. BIT(NL80211_CHAN_WIDTH_5) |
  4531. BIT(NL80211_CHAN_WIDTH_10) |
  4532. BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  4533. BIT(NL80211_CHAN_WIDTH_20) |
  4534. BIT(NL80211_CHAN_WIDTH_40) |
  4535. BIT(NL80211_CHAN_WIDTH_80) |
  4536. BIT(NL80211_CHAN_WIDTH_160);
  4537. if (data->use_chanctx) {
  4538. hw->wiphy->max_scan_ssids = 255;
  4539. hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  4540. hw->wiphy->max_remain_on_channel_duration = 1000;
  4541. data->if_combination.num_different_channels = data->channels;
  4542. } else {
  4543. data->if_combination.num_different_channels = 1;
  4544. }
  4545. if (!n_limits) {
  4546. err = -EINVAL;
  4547. goto failed_hw;
  4548. }
  4549. data->if_combination.max_interfaces = 0;
  4550. for (i = 0; i < n_limits; i++)
  4551. data->if_combination.max_interfaces +=
  4552. data->if_limits[i].max;
  4553. data->if_combination.n_limits = n_limits;
  4554. data->if_combination.limits = data->if_limits;
  4555. /*
  4556. * If we actually were asked to support combinations,
  4557. * advertise them - if there's only a single thing like
  4558. * only IBSS then don't advertise it as combinations.
  4559. */
  4560. if (data->if_combination.max_interfaces > 1) {
  4561. hw->wiphy->iface_combinations = &data->if_combination;
  4562. hw->wiphy->n_iface_combinations = 1;
  4563. }
  4564. if (param->ciphers) {
  4565. memcpy(data->ciphers, param->ciphers,
  4566. param->n_ciphers * sizeof(u32));
  4567. hw->wiphy->cipher_suites = data->ciphers;
  4568. hw->wiphy->n_cipher_suites = param->n_ciphers;
  4569. }
  4570. hw->wiphy->mbssid_max_interfaces = 8;
  4571. hw->wiphy->ema_max_profile_periodicity = 3;
  4572. data->rx_rssi = DEFAULT_RX_RSSI;
  4573. INIT_DELAYED_WORK(&data->roc_start, hw_roc_start);
  4574. INIT_DELAYED_WORK(&data->roc_done, hw_roc_done);
  4575. INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work);
  4576. hw->queues = 5;
  4577. hw->offchannel_tx_hw_queue = 4;
  4578. ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
  4579. ieee80211_hw_set(hw, CHANCTX_STA_CSA);
  4580. ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);
  4581. ieee80211_hw_set(hw, QUEUE_CONTROL);
  4582. ieee80211_hw_set(hw, WANT_MONITOR_VIF);
  4583. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  4584. ieee80211_hw_set(hw, MFP_CAPABLE);
  4585. ieee80211_hw_set(hw, SIGNAL_DBM);
  4586. ieee80211_hw_set(hw, SUPPORTS_PS);
  4587. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  4588. ieee80211_hw_set(hw, TDLS_WIDER_BW);
  4589. ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
  4590. if (param->mlo) {
  4591. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
  4592. ieee80211_hw_set(hw, HAS_RATE_CONTROL);
  4593. ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
  4594. ieee80211_hw_set(hw, CONNECTION_MONITOR);
  4595. ieee80211_hw_set(hw, AP_LINK_PS);
  4596. hw->wiphy->iftype_ext_capab = mac80211_hwsim_iftypes_ext_capa;
  4597. hw->wiphy->num_iftype_ext_capab =
  4598. ARRAY_SIZE(mac80211_hwsim_iftypes_ext_capa);
  4599. } else {
  4600. ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
  4601. ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
  4602. if (rctbl)
  4603. ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
  4604. }
  4605. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  4606. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
  4607. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  4608. WIPHY_FLAG_AP_UAPSD |
  4609. WIPHY_FLAG_SUPPORTS_5_10_MHZ |
  4610. WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  4611. hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
  4612. NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
  4613. NL80211_FEATURE_STATIC_SMPS |
  4614. NL80211_FEATURE_DYNAMIC_SMPS |
  4615. NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
  4616. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
  4617. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_BEACON_PROTECTION);
  4618. wiphy_ext_feature_set(hw->wiphy,
  4619. NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS);
  4620. wiphy_ext_feature_set(hw->wiphy,
  4621. NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
  4622. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
  4623. wiphy_ext_feature_set(hw->wiphy,
  4624. NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
  4625. wiphy_ext_feature_set(hw->wiphy,
  4626. NL80211_EXT_FEATURE_BSS_COLOR);
  4627. hw->wiphy->interface_modes = param->iftypes;
  4628. /* ask mac80211 to reserve space for magic */
  4629. hw->vif_data_size = sizeof(struct hwsim_vif_priv);
  4630. hw->sta_data_size = sizeof(struct hwsim_sta_priv);
  4631. hw->chanctx_data_size = sizeof(struct hwsim_chanctx_priv);
  4632. memcpy(data->channels_2ghz, hwsim_channels_2ghz,
  4633. sizeof(hwsim_channels_2ghz));
  4634. memcpy(data->channels_5ghz, hwsim_channels_5ghz,
  4635. sizeof(hwsim_channels_5ghz));
  4636. memcpy(data->channels_6ghz, hwsim_channels_6ghz,
  4637. sizeof(hwsim_channels_6ghz));
  4638. memcpy(data->channels_s1g, hwsim_channels_s1g,
  4639. sizeof(hwsim_channels_s1g));
  4640. memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates));
  4641. for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
  4642. struct ieee80211_supported_band *sband = &data->bands[band];
  4643. struct wiphy_radio_freq_range *radio_range;
  4644. const struct ieee80211_channel *c;
  4645. struct wiphy_radio *radio;
  4646. sband->band = band;
  4647. switch (band) {
  4648. case NL80211_BAND_2GHZ:
  4649. sband->channels = data->channels_2ghz;
  4650. sband->n_channels = ARRAY_SIZE(hwsim_channels_2ghz);
  4651. sband->bitrates = data->rates;
  4652. sband->n_bitrates = ARRAY_SIZE(hwsim_rates);
  4653. break;
  4654. case NL80211_BAND_5GHZ:
  4655. sband->channels = data->channels_5ghz;
  4656. sband->n_channels = ARRAY_SIZE(hwsim_channels_5ghz);
  4657. sband->bitrates = data->rates + 4;
  4658. sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4;
  4659. sband->vht_cap.vht_supported = true;
  4660. sband->vht_cap.cap =
  4661. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
  4662. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ |
  4663. IEEE80211_VHT_CAP_RXLDPC |
  4664. IEEE80211_VHT_CAP_SHORT_GI_80 |
  4665. IEEE80211_VHT_CAP_SHORT_GI_160 |
  4666. IEEE80211_VHT_CAP_TXSTBC |
  4667. IEEE80211_VHT_CAP_RXSTBC_4 |
  4668. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  4669. sband->vht_cap.vht_mcs.rx_mcs_map =
  4670. cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  4671. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  4672. IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 |
  4673. IEEE80211_VHT_MCS_SUPPORT_0_9 << 6 |
  4674. IEEE80211_VHT_MCS_SUPPORT_0_9 << 8 |
  4675. IEEE80211_VHT_MCS_SUPPORT_0_9 << 10 |
  4676. IEEE80211_VHT_MCS_SUPPORT_0_9 << 12 |
  4677. IEEE80211_VHT_MCS_SUPPORT_0_9 << 14);
  4678. sband->vht_cap.vht_mcs.tx_mcs_map =
  4679. sband->vht_cap.vht_mcs.rx_mcs_map;
  4680. break;
  4681. case NL80211_BAND_6GHZ:
  4682. sband->channels = data->channels_6ghz;
  4683. sband->n_channels = ARRAY_SIZE(hwsim_channels_6ghz);
  4684. sband->bitrates = data->rates + 4;
  4685. sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4;
  4686. break;
  4687. case NL80211_BAND_S1GHZ:
  4688. memcpy(&sband->s1g_cap, &hwsim_s1g_cap,
  4689. sizeof(sband->s1g_cap));
  4690. sband->channels = data->channels_s1g;
  4691. sband->n_channels = ARRAY_SIZE(hwsim_channels_s1g);
  4692. break;
  4693. default:
  4694. continue;
  4695. }
  4696. if (band != NL80211_BAND_6GHZ){
  4697. sband->ht_cap.ht_supported = true;
  4698. sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  4699. IEEE80211_HT_CAP_GRN_FLD |
  4700. IEEE80211_HT_CAP_SGI_20 |
  4701. IEEE80211_HT_CAP_SGI_40 |
  4702. IEEE80211_HT_CAP_DSSSCCK40;
  4703. sband->ht_cap.ampdu_factor = 0x3;
  4704. sband->ht_cap.ampdu_density = 0x6;
  4705. memset(&sband->ht_cap.mcs, 0,
  4706. sizeof(sband->ht_cap.mcs));
  4707. sband->ht_cap.mcs.rx_mask[0] = 0xff;
  4708. sband->ht_cap.mcs.rx_mask[1] = 0xff;
  4709. sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  4710. }
  4711. mac80211_hwsim_sband_capab(sband);
  4712. hw->wiphy->bands[band] = sband;
  4713. if (!param->multi_radio)
  4714. continue;
  4715. c = sband->channels;
  4716. radio_range = &data->radio_range[n_bands];
  4717. radio_range->start_freq = ieee80211_channel_to_khz(c) - 10000;
  4718. c += sband->n_channels - 1;
  4719. radio_range->end_freq = ieee80211_channel_to_khz(c) + 10000;
  4720. radio = &data->radio[n_bands++];
  4721. radio->freq_range = radio_range;
  4722. radio->n_freq_range = 1;
  4723. radio->iface_combinations = &data->if_combination_radio;
  4724. radio->n_iface_combinations = 1;
  4725. }
  4726. if (param->multi_radio) {
  4727. hw->wiphy->radio = data->radio;
  4728. hw->wiphy->n_radio = n_bands;
  4729. memcpy(&data->if_combination_radio, &data->if_combination,
  4730. sizeof(data->if_combination));
  4731. data->if_combination.num_different_channels *= n_bands;
  4732. }
  4733. if (data->use_chanctx)
  4734. data->if_combination.radar_detect_widths = 0;
  4735. /* By default all radios belong to the first group */
  4736. data->group = 1;
  4737. mutex_init(&data->mutex);
  4738. data->netgroup = hwsim_net_get_netgroup(net);
  4739. data->wmediumd = hwsim_net_get_wmediumd(net);
  4740. /* Enable frame retransmissions for lossy channels */
  4741. hw->max_rates = 4;
  4742. hw->max_rate_tries = 11;
  4743. hw->wiphy->vendor_commands = mac80211_hwsim_vendor_commands;
  4744. hw->wiphy->n_vendor_commands =
  4745. ARRAY_SIZE(mac80211_hwsim_vendor_commands);
  4746. hw->wiphy->vendor_events = mac80211_hwsim_vendor_events;
  4747. hw->wiphy->n_vendor_events = ARRAY_SIZE(mac80211_hwsim_vendor_events);
  4748. if (param->reg_strict)
  4749. hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
  4750. if (param->regd) {
  4751. data->regd = param->regd;
  4752. hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
  4753. wiphy_apply_custom_regulatory(hw->wiphy, param->regd);
  4754. /* give the regulatory workqueue a chance to run */
  4755. schedule_timeout_interruptible(1);
  4756. }
  4757. wiphy_ext_feature_set(hw->wiphy,
  4758. NL80211_EXT_FEATURE_DFS_CONCURRENT);
  4759. if (param->no_vif)
  4760. ieee80211_hw_set(hw, NO_AUTO_VIF);
  4761. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
  4762. for (i = 0; i < ARRAY_SIZE(data->link_data); i++) {
  4763. hrtimer_init(&data->link_data[i].beacon_timer, CLOCK_MONOTONIC,
  4764. HRTIMER_MODE_ABS_SOFT);
  4765. data->link_data[i].beacon_timer.function =
  4766. mac80211_hwsim_beacon;
  4767. data->link_data[i].link_id = i;
  4768. }
  4769. err = ieee80211_register_hw(hw);
  4770. if (err < 0) {
  4771. pr_debug("mac80211_hwsim: ieee80211_register_hw failed (%d)\n",
  4772. err);
  4773. goto failed_hw;
  4774. }
  4775. wiphy_dbg(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr);
  4776. if (param->reg_alpha2) {
  4777. data->alpha2[0] = param->reg_alpha2[0];
  4778. data->alpha2[1] = param->reg_alpha2[1];
  4779. regulatory_hint(hw->wiphy, param->reg_alpha2);
  4780. }
  4781. data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir);
  4782. debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps);
  4783. debugfs_create_file("group", 0666, data->debugfs, data,
  4784. &hwsim_fops_group);
  4785. debugfs_create_file("rx_rssi", 0666, data->debugfs, data,
  4786. &hwsim_fops_rx_rssi);
  4787. if (!data->use_chanctx)
  4788. debugfs_create_file("dfs_simulate_radar", 0222,
  4789. data->debugfs,
  4790. data, &hwsim_simulate_radar);
  4791. if (param->pmsr_capa) {
  4792. data->pmsr_capa = *param->pmsr_capa;
  4793. hw->wiphy->pmsr_capa = &data->pmsr_capa;
  4794. }
  4795. spin_lock_bh(&hwsim_radio_lock);
  4796. err = rhashtable_insert_fast(&hwsim_radios_rht, &data->rht,
  4797. hwsim_rht_params);
  4798. if (err < 0) {
  4799. if (info) {
  4800. GENL_SET_ERR_MSG(info, "perm addr already present");
  4801. NL_SET_BAD_ATTR(info->extack,
  4802. info->attrs[HWSIM_ATTR_PERM_ADDR]);
  4803. }
  4804. spin_unlock_bh(&hwsim_radio_lock);
  4805. goto failed_final_insert;
  4806. }
  4807. list_add_tail(&data->list, &hwsim_radios);
  4808. hwsim_radios_generation++;
  4809. spin_unlock_bh(&hwsim_radio_lock);
  4810. hwsim_mcast_new_radio(idx, info, param);
  4811. return idx;
  4812. failed_final_insert:
  4813. debugfs_remove_recursive(data->debugfs);
  4814. ieee80211_unregister_hw(data->hw);
  4815. failed_hw:
  4816. device_release_driver(data->dev);
  4817. failed_bind:
  4818. device_unregister(data->dev);
  4819. failed_drvdata:
  4820. ieee80211_free_hw(hw);
  4821. failed:
  4822. return err;
  4823. }
  4824. static void hwsim_mcast_del_radio(int id, const char *hwname,
  4825. struct genl_info *info)
  4826. {
  4827. struct sk_buff *skb;
  4828. void *data;
  4829. int ret;
  4830. skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4831. if (!skb)
  4832. return;
  4833. data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
  4834. HWSIM_CMD_DEL_RADIO);
  4835. if (!data)
  4836. goto error;
  4837. ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
  4838. if (ret < 0)
  4839. goto error;
  4840. ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, strlen(hwname),
  4841. hwname);
  4842. if (ret < 0)
  4843. goto error;
  4844. genlmsg_end(skb, data);
  4845. hwsim_mcast_config_msg(skb, info);
  4846. return;
  4847. error:
  4848. nlmsg_free(skb);
  4849. }
  4850. static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data,
  4851. const char *hwname,
  4852. struct genl_info *info)
  4853. {
  4854. hwsim_mcast_del_radio(data->idx, hwname, info);
  4855. debugfs_remove_recursive(data->debugfs);
  4856. ieee80211_unregister_hw(data->hw);
  4857. device_release_driver(data->dev);
  4858. device_unregister(data->dev);
  4859. ieee80211_free_hw(data->hw);
  4860. }
  4861. static int mac80211_hwsim_get_radio(struct sk_buff *skb,
  4862. struct mac80211_hwsim_data *data,
  4863. u32 portid, u32 seq,
  4864. struct netlink_callback *cb, int flags)
  4865. {
  4866. void *hdr;
  4867. struct hwsim_new_radio_params param = { };
  4868. int res = -EMSGSIZE;
  4869. hdr = genlmsg_put(skb, portid, seq, &hwsim_genl_family, flags,
  4870. HWSIM_CMD_GET_RADIO);
  4871. if (!hdr)
  4872. return -EMSGSIZE;
  4873. if (cb)
  4874. genl_dump_check_consistent(cb, hdr);
  4875. if (data->alpha2[0] && data->alpha2[1])
  4876. param.reg_alpha2 = data->alpha2;
  4877. param.reg_strict = !!(data->hw->wiphy->regulatory_flags &
  4878. REGULATORY_STRICT_REG);
  4879. param.p2p_device = !!(data->hw->wiphy->interface_modes &
  4880. BIT(NL80211_IFTYPE_P2P_DEVICE));
  4881. param.use_chanctx = data->use_chanctx;
  4882. param.regd = data->regd;
  4883. param.channels = data->channels;
  4884. param.hwname = wiphy_name(data->hw->wiphy);
  4885. param.pmsr_capa = &data->pmsr_capa;
  4886. res = append_radio_msg(skb, data->idx, &param);
  4887. if (res < 0)
  4888. goto out_err;
  4889. genlmsg_end(skb, hdr);
  4890. return 0;
  4891. out_err:
  4892. genlmsg_cancel(skb, hdr);
  4893. return res;
  4894. }
  4895. static void mac80211_hwsim_free(void)
  4896. {
  4897. struct mac80211_hwsim_data *data;
  4898. spin_lock_bh(&hwsim_radio_lock);
  4899. while ((data = list_first_entry_or_null(&hwsim_radios,
  4900. struct mac80211_hwsim_data,
  4901. list))) {
  4902. list_del(&data->list);
  4903. spin_unlock_bh(&hwsim_radio_lock);
  4904. mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
  4905. NULL);
  4906. spin_lock_bh(&hwsim_radio_lock);
  4907. }
  4908. spin_unlock_bh(&hwsim_radio_lock);
  4909. class_destroy(hwsim_class);
  4910. }
  4911. static const struct net_device_ops hwsim_netdev_ops = {
  4912. .ndo_start_xmit = hwsim_mon_xmit,
  4913. .ndo_set_mac_address = eth_mac_addr,
  4914. .ndo_validate_addr = eth_validate_addr,
  4915. };
  4916. static void hwsim_mon_setup(struct net_device *dev)
  4917. {
  4918. u8 addr[ETH_ALEN];
  4919. dev->netdev_ops = &hwsim_netdev_ops;
  4920. dev->needs_free_netdev = true;
  4921. ether_setup(dev);
  4922. dev->priv_flags |= IFF_NO_QUEUE;
  4923. dev->type = ARPHRD_IEEE80211_RADIOTAP;
  4924. eth_zero_addr(addr);
  4925. addr[0] = 0x12;
  4926. eth_hw_addr_set(dev, addr);
  4927. }
  4928. static void hwsim_register_wmediumd(struct net *net, u32 portid)
  4929. {
  4930. struct mac80211_hwsim_data *data;
  4931. hwsim_net_set_wmediumd(net, portid);
  4932. spin_lock_bh(&hwsim_radio_lock);
  4933. list_for_each_entry(data, &hwsim_radios, list) {
  4934. if (data->netgroup == hwsim_net_get_netgroup(net))
  4935. data->wmediumd = portid;
  4936. }
  4937. spin_unlock_bh(&hwsim_radio_lock);
  4938. }
  4939. static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
  4940. struct genl_info *info)
  4941. {
  4942. struct ieee80211_hdr *hdr;
  4943. struct mac80211_hwsim_data *data2;
  4944. struct ieee80211_tx_info *txi;
  4945. struct hwsim_tx_rate *tx_attempts;
  4946. u64 ret_skb_cookie;
  4947. struct sk_buff *skb, *tmp;
  4948. const u8 *src;
  4949. unsigned int hwsim_flags;
  4950. int i;
  4951. unsigned long flags;
  4952. bool found = false;
  4953. if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] ||
  4954. !info->attrs[HWSIM_ATTR_FLAGS] ||
  4955. !info->attrs[HWSIM_ATTR_COOKIE] ||
  4956. !info->attrs[HWSIM_ATTR_SIGNAL] ||
  4957. !info->attrs[HWSIM_ATTR_TX_INFO])
  4958. goto out;
  4959. src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]);
  4960. hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]);
  4961. ret_skb_cookie = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]);
  4962. data2 = get_hwsim_data_ref_from_addr(src);
  4963. if (!data2)
  4964. goto out;
  4965. if (!hwsim_virtio_enabled) {
  4966. if (hwsim_net_get_netgroup(genl_info_net(info)) !=
  4967. data2->netgroup)
  4968. goto out;
  4969. if (info->snd_portid != data2->wmediumd)
  4970. goto out;
  4971. }
  4972. /* look for the skb matching the cookie passed back from user */
  4973. spin_lock_irqsave(&data2->pending.lock, flags);
  4974. skb_queue_walk_safe(&data2->pending, skb, tmp) {
  4975. uintptr_t skb_cookie;
  4976. txi = IEEE80211_SKB_CB(skb);
  4977. skb_cookie = (uintptr_t)txi->rate_driver_data[0];
  4978. if (skb_cookie == ret_skb_cookie) {
  4979. __skb_unlink(skb, &data2->pending);
  4980. found = true;
  4981. break;
  4982. }
  4983. }
  4984. spin_unlock_irqrestore(&data2->pending.lock, flags);
  4985. /* not found */
  4986. if (!found)
  4987. goto out;
  4988. /* Tx info received because the frame was broadcasted on user space,
  4989. so we get all the necessary info: tx attempts and skb control buff */
  4990. tx_attempts = (struct hwsim_tx_rate *)nla_data(
  4991. info->attrs[HWSIM_ATTR_TX_INFO]);
  4992. /* now send back TX status */
  4993. txi = IEEE80211_SKB_CB(skb);
  4994. ieee80211_tx_info_clear_status(txi);
  4995. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  4996. txi->status.rates[i].idx = tx_attempts[i].idx;
  4997. txi->status.rates[i].count = tx_attempts[i].count;
  4998. }
  4999. txi->status.ack_signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]);
  5000. if (!(hwsim_flags & HWSIM_TX_CTL_NO_ACK) &&
  5001. (hwsim_flags & HWSIM_TX_STAT_ACK)) {
  5002. if (skb->len >= 16) {
  5003. hdr = (struct ieee80211_hdr *) skb->data;
  5004. mac80211_hwsim_monitor_ack(data2->channel,
  5005. hdr->addr2);
  5006. }
  5007. txi->flags |= IEEE80211_TX_STAT_ACK;
  5008. }
  5009. if (hwsim_flags & HWSIM_TX_CTL_NO_ACK)
  5010. txi->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
  5011. ieee80211_tx_status_irqsafe(data2->hw, skb);
  5012. return 0;
  5013. out:
  5014. return -EINVAL;
  5015. }
  5016. static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
  5017. struct genl_info *info)
  5018. {
  5019. struct mac80211_hwsim_data *data2;
  5020. struct ieee80211_rx_status rx_status;
  5021. struct ieee80211_hdr *hdr;
  5022. const u8 *dst;
  5023. int frame_data_len;
  5024. void *frame_data;
  5025. struct sk_buff *skb = NULL;
  5026. struct ieee80211_channel *channel = NULL;
  5027. if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] ||
  5028. !info->attrs[HWSIM_ATTR_FRAME] ||
  5029. !info->attrs[HWSIM_ATTR_RX_RATE] ||
  5030. !info->attrs[HWSIM_ATTR_SIGNAL])
  5031. goto out;
  5032. dst = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_RECEIVER]);
  5033. frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]);
  5034. frame_data = (void *)nla_data(info->attrs[HWSIM_ATTR_FRAME]);
  5035. if (frame_data_len < sizeof(struct ieee80211_hdr_3addr) ||
  5036. frame_data_len > IEEE80211_MAX_DATA_LEN)
  5037. goto err;
  5038. /* Allocate new skb here */
  5039. skb = alloc_skb(frame_data_len, GFP_KERNEL);
  5040. if (skb == NULL)
  5041. goto err;
  5042. /* Copy the data */
  5043. skb_put_data(skb, frame_data, frame_data_len);
  5044. data2 = get_hwsim_data_ref_from_addr(dst);
  5045. if (!data2)
  5046. goto out;
  5047. if (data2->use_chanctx) {
  5048. if (data2->tmp_chan)
  5049. channel = data2->tmp_chan;
  5050. } else {
  5051. channel = data2->channel;
  5052. }
  5053. if (!hwsim_virtio_enabled) {
  5054. if (hwsim_net_get_netgroup(genl_info_net(info)) !=
  5055. data2->netgroup)
  5056. goto out;
  5057. if (info->snd_portid != data2->wmediumd)
  5058. goto out;
  5059. }
  5060. /* check if radio is configured properly */
  5061. if ((data2->idle && !data2->tmp_chan) || !data2->started)
  5062. goto out;
  5063. /* A frame is received from user space */
  5064. memset(&rx_status, 0, sizeof(rx_status));
  5065. if (info->attrs[HWSIM_ATTR_FREQ]) {
  5066. struct tx_iter_data iter_data = {};
  5067. /* throw away off-channel packets, but allow both the temporary
  5068. * ("hw" scan/remain-on-channel), regular channels and links,
  5069. * since the internal datapath also allows this
  5070. */
  5071. rx_status.freq = nla_get_u32(info->attrs[HWSIM_ATTR_FREQ]);
  5072. iter_data.channel = ieee80211_get_channel(data2->hw->wiphy,
  5073. rx_status.freq);
  5074. if (!iter_data.channel)
  5075. goto out;
  5076. rx_status.band = iter_data.channel->band;
  5077. mutex_lock(&data2->mutex);
  5078. if (!hwsim_chans_compat(iter_data.channel, channel)) {
  5079. ieee80211_iterate_active_interfaces_atomic(
  5080. data2->hw, IEEE80211_IFACE_ITER_NORMAL,
  5081. mac80211_hwsim_tx_iter, &iter_data);
  5082. if (!iter_data.receive) {
  5083. mutex_unlock(&data2->mutex);
  5084. goto out;
  5085. }
  5086. }
  5087. mutex_unlock(&data2->mutex);
  5088. } else if (!channel) {
  5089. goto out;
  5090. } else {
  5091. rx_status.freq = channel->center_freq;
  5092. rx_status.band = channel->band;
  5093. }
  5094. rx_status.rate_idx = nla_get_u32(info->attrs[HWSIM_ATTR_RX_RATE]);
  5095. if (rx_status.rate_idx >= data2->hw->wiphy->bands[rx_status.band]->n_bitrates)
  5096. goto out;
  5097. rx_status.signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]);
  5098. hdr = (void *)skb->data;
  5099. if (ieee80211_is_beacon(hdr->frame_control) ||
  5100. ieee80211_is_probe_resp(hdr->frame_control))
  5101. rx_status.boottime_ns = ktime_get_boottime_ns();
  5102. mac80211_hwsim_rx(data2, &rx_status, skb);
  5103. return 0;
  5104. err:
  5105. pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
  5106. out:
  5107. dev_kfree_skb(skb);
  5108. return -EINVAL;
  5109. }
  5110. static int hwsim_register_received_nl(struct sk_buff *skb_2,
  5111. struct genl_info *info)
  5112. {
  5113. struct net *net = genl_info_net(info);
  5114. struct mac80211_hwsim_data *data;
  5115. int chans = 1;
  5116. spin_lock_bh(&hwsim_radio_lock);
  5117. list_for_each_entry(data, &hwsim_radios, list)
  5118. chans = max(chans, data->channels);
  5119. spin_unlock_bh(&hwsim_radio_lock);
  5120. /* In the future we should revise the userspace API and allow it
  5121. * to set a flag that it does support multi-channel, then we can
  5122. * let this pass conditionally on the flag.
  5123. * For current userspace, prohibit it since it won't work right.
  5124. */
  5125. if (chans > 1)
  5126. return -EOPNOTSUPP;
  5127. if (hwsim_net_get_wmediumd(net))
  5128. return -EBUSY;
  5129. hwsim_register_wmediumd(net, info->snd_portid);
  5130. pr_debug("mac80211_hwsim: received a REGISTER, "
  5131. "switching to wmediumd mode with pid %d\n", info->snd_portid);
  5132. return 0;
  5133. }
  5134. /* ensures ciphers only include ciphers listed in 'hwsim_ciphers' array */
  5135. static bool hwsim_known_ciphers(const u32 *ciphers, int n_ciphers)
  5136. {
  5137. int i;
  5138. for (i = 0; i < n_ciphers; i++) {
  5139. int j;
  5140. int found = 0;
  5141. for (j = 0; j < ARRAY_SIZE(hwsim_ciphers); j++) {
  5142. if (ciphers[i] == hwsim_ciphers[j]) {
  5143. found = 1;
  5144. break;
  5145. }
  5146. }
  5147. if (!found)
  5148. return false;
  5149. }
  5150. return true;
  5151. }
  5152. static int parse_ftm_capa(const struct nlattr *ftm_capa, struct cfg80211_pmsr_capabilities *out,
  5153. struct genl_info *info)
  5154. {
  5155. struct nlattr *tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX + 1];
  5156. int ret;
  5157. ret = nla_parse_nested(tb, NL80211_PMSR_FTM_CAPA_ATTR_MAX, ftm_capa, hwsim_ftm_capa_policy,
  5158. NULL);
  5159. if (ret) {
  5160. NL_SET_ERR_MSG_ATTR(info->extack, ftm_capa, "malformed FTM capability");
  5161. return -EINVAL;
  5162. }
  5163. out->ftm.supported = 1;
  5164. if (tb[NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES])
  5165. out->ftm.preambles = nla_get_u32(tb[NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES]);
  5166. if (tb[NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS])
  5167. out->ftm.bandwidths = nla_get_u32(tb[NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS]);
  5168. if (tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT])
  5169. out->ftm.max_bursts_exponent =
  5170. nla_get_u8(tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT]);
  5171. if (tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST])
  5172. out->ftm.max_ftms_per_burst =
  5173. nla_get_u8(tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST]);
  5174. out->ftm.asap = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_ASAP];
  5175. out->ftm.non_asap = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP];
  5176. out->ftm.request_lci = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI];
  5177. out->ftm.request_civicloc = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC];
  5178. out->ftm.trigger_based = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED];
  5179. out->ftm.non_trigger_based = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED];
  5180. return 0;
  5181. }
  5182. static int parse_pmsr_capa(const struct nlattr *pmsr_capa, struct cfg80211_pmsr_capabilities *out,
  5183. struct genl_info *info)
  5184. {
  5185. struct nlattr *tb[NL80211_PMSR_ATTR_MAX + 1];
  5186. struct nlattr *nla;
  5187. int size;
  5188. int ret;
  5189. ret = nla_parse_nested(tb, NL80211_PMSR_ATTR_MAX, pmsr_capa, hwsim_pmsr_capa_policy, NULL);
  5190. if (ret) {
  5191. NL_SET_ERR_MSG_ATTR(info->extack, pmsr_capa, "malformed PMSR capability");
  5192. return -EINVAL;
  5193. }
  5194. if (tb[NL80211_PMSR_ATTR_MAX_PEERS])
  5195. out->max_peers = nla_get_u32(tb[NL80211_PMSR_ATTR_MAX_PEERS]);
  5196. out->report_ap_tsf = !!tb[NL80211_PMSR_ATTR_REPORT_AP_TSF];
  5197. out->randomize_mac_addr = !!tb[NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR];
  5198. if (!tb[NL80211_PMSR_ATTR_TYPE_CAPA]) {
  5199. NL_SET_ERR_MSG_ATTR(info->extack, tb[NL80211_PMSR_ATTR_TYPE_CAPA],
  5200. "malformed PMSR type");
  5201. return -EINVAL;
  5202. }
  5203. nla_for_each_nested(nla, tb[NL80211_PMSR_ATTR_TYPE_CAPA], size) {
  5204. switch (nla_type(nla)) {
  5205. case NL80211_PMSR_TYPE_FTM:
  5206. parse_ftm_capa(nla, out, info);
  5207. break;
  5208. default:
  5209. NL_SET_ERR_MSG_ATTR(info->extack, nla, "unsupported measurement type");
  5210. return -EINVAL;
  5211. }
  5212. }
  5213. return 0;
  5214. }
  5215. static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
  5216. {
  5217. struct hwsim_new_radio_params param = { 0 };
  5218. const char *hwname = NULL;
  5219. int ret;
  5220. param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG];
  5221. param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE];
  5222. param.channels = channels;
  5223. param.destroy_on_close =
  5224. info->attrs[HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE];
  5225. if (info->attrs[HWSIM_ATTR_CHANNELS])
  5226. param.channels = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]);
  5227. if (param.channels < 1) {
  5228. GENL_SET_ERR_MSG(info, "must have at least one channel");
  5229. return -EINVAL;
  5230. }
  5231. if (info->attrs[HWSIM_ATTR_NO_VIF])
  5232. param.no_vif = true;
  5233. if (info->attrs[HWSIM_ATTR_USE_CHANCTX])
  5234. param.use_chanctx = true;
  5235. else
  5236. param.use_chanctx = (param.channels > 1);
  5237. if (info->attrs[HWSIM_ATTR_MULTI_RADIO])
  5238. param.multi_radio = true;
  5239. if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2])
  5240. param.reg_alpha2 =
  5241. nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]);
  5242. if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) {
  5243. u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]);
  5244. if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom))
  5245. return -EINVAL;
  5246. idx = array_index_nospec(idx,
  5247. ARRAY_SIZE(hwsim_world_regdom_custom));
  5248. param.regd = hwsim_world_regdom_custom[idx];
  5249. }
  5250. if (info->attrs[HWSIM_ATTR_PERM_ADDR]) {
  5251. if (!is_valid_ether_addr(
  5252. nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]))) {
  5253. GENL_SET_ERR_MSG(info,"MAC is no valid source addr");
  5254. NL_SET_BAD_ATTR(info->extack,
  5255. info->attrs[HWSIM_ATTR_PERM_ADDR]);
  5256. return -EINVAL;
  5257. }
  5258. param.perm_addr = nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]);
  5259. }
  5260. if (info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]) {
  5261. param.iftypes =
  5262. nla_get_u32(info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]);
  5263. if (param.iftypes & ~HWSIM_IFTYPE_SUPPORT_MASK) {
  5264. NL_SET_ERR_MSG_ATTR(info->extack,
  5265. info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT],
  5266. "cannot support more iftypes than kernel");
  5267. return -EINVAL;
  5268. }
  5269. } else {
  5270. param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK;
  5271. }
  5272. /* ensure both flag and iftype support is honored */
  5273. if (param.p2p_device ||
  5274. param.iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) {
  5275. param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE);
  5276. param.p2p_device = true;
  5277. }
  5278. if (info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]) {
  5279. u32 len = nla_len(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]);
  5280. param.ciphers =
  5281. nla_data(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]);
  5282. if (len % sizeof(u32)) {
  5283. NL_SET_ERR_MSG_ATTR(info->extack,
  5284. info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
  5285. "bad cipher list length");
  5286. return -EINVAL;
  5287. }
  5288. param.n_ciphers = len / sizeof(u32);
  5289. if (param.n_ciphers > ARRAY_SIZE(hwsim_ciphers)) {
  5290. NL_SET_ERR_MSG_ATTR(info->extack,
  5291. info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
  5292. "too many ciphers specified");
  5293. return -EINVAL;
  5294. }
  5295. if (!hwsim_known_ciphers(param.ciphers, param.n_ciphers)) {
  5296. NL_SET_ERR_MSG_ATTR(info->extack,
  5297. info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
  5298. "unsupported ciphers specified");
  5299. return -EINVAL;
  5300. }
  5301. }
  5302. param.mlo = info->attrs[HWSIM_ATTR_MLO_SUPPORT];
  5303. if (param.mlo || param.multi_radio)
  5304. param.use_chanctx = true;
  5305. if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
  5306. hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]),
  5307. nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
  5308. GFP_KERNEL);
  5309. if (!hwname)
  5310. return -ENOMEM;
  5311. param.hwname = hwname;
  5312. }
  5313. if (info->attrs[HWSIM_ATTR_PMSR_SUPPORT]) {
  5314. struct cfg80211_pmsr_capabilities *pmsr_capa;
  5315. pmsr_capa = kmalloc(sizeof(*pmsr_capa), GFP_KERNEL);
  5316. if (!pmsr_capa) {
  5317. ret = -ENOMEM;
  5318. goto out_free;
  5319. }
  5320. param.pmsr_capa = pmsr_capa;
  5321. ret = parse_pmsr_capa(info->attrs[HWSIM_ATTR_PMSR_SUPPORT], pmsr_capa, info);
  5322. if (ret)
  5323. goto out_free;
  5324. }
  5325. ret = mac80211_hwsim_new_radio(info, &param);
  5326. out_free:
  5327. kfree(hwname);
  5328. kfree(param.pmsr_capa);
  5329. return ret;
  5330. }
  5331. static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
  5332. {
  5333. struct mac80211_hwsim_data *data;
  5334. s64 idx = -1;
  5335. const char *hwname = NULL;
  5336. if (info->attrs[HWSIM_ATTR_RADIO_ID]) {
  5337. idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
  5338. } else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
  5339. hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]),
  5340. nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
  5341. GFP_KERNEL);
  5342. if (!hwname)
  5343. return -ENOMEM;
  5344. } else
  5345. return -EINVAL;
  5346. spin_lock_bh(&hwsim_radio_lock);
  5347. list_for_each_entry(data, &hwsim_radios, list) {
  5348. if (idx >= 0) {
  5349. if (data->idx != idx)
  5350. continue;
  5351. } else {
  5352. if (!hwname ||
  5353. strcmp(hwname, wiphy_name(data->hw->wiphy)))
  5354. continue;
  5355. }
  5356. if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info)))
  5357. continue;
  5358. list_del(&data->list);
  5359. rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
  5360. hwsim_rht_params);
  5361. hwsim_radios_generation++;
  5362. spin_unlock_bh(&hwsim_radio_lock);
  5363. mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
  5364. info);
  5365. kfree(hwname);
  5366. return 0;
  5367. }
  5368. spin_unlock_bh(&hwsim_radio_lock);
  5369. kfree(hwname);
  5370. return -ENODEV;
  5371. }
  5372. static int hwsim_get_radio_nl(struct sk_buff *msg, struct genl_info *info)
  5373. {
  5374. struct mac80211_hwsim_data *data;
  5375. struct sk_buff *skb;
  5376. int idx, res = -ENODEV;
  5377. if (!info->attrs[HWSIM_ATTR_RADIO_ID])
  5378. return -EINVAL;
  5379. idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
  5380. spin_lock_bh(&hwsim_radio_lock);
  5381. list_for_each_entry(data, &hwsim_radios, list) {
  5382. if (data->idx != idx)
  5383. continue;
  5384. if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info)))
  5385. continue;
  5386. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  5387. if (!skb) {
  5388. res = -ENOMEM;
  5389. goto out_err;
  5390. }
  5391. res = mac80211_hwsim_get_radio(skb, data, info->snd_portid,
  5392. info->snd_seq, NULL, 0);
  5393. if (res < 0) {
  5394. nlmsg_free(skb);
  5395. goto out_err;
  5396. }
  5397. res = genlmsg_reply(skb, info);
  5398. break;
  5399. }
  5400. out_err:
  5401. spin_unlock_bh(&hwsim_radio_lock);
  5402. return res;
  5403. }
  5404. static int hwsim_dump_radio_nl(struct sk_buff *skb,
  5405. struct netlink_callback *cb)
  5406. {
  5407. int last_idx = cb->args[0] - 1;
  5408. struct mac80211_hwsim_data *data = NULL;
  5409. int res = 0;
  5410. void *hdr;
  5411. spin_lock_bh(&hwsim_radio_lock);
  5412. cb->seq = hwsim_radios_generation;
  5413. if (last_idx >= hwsim_radio_idx-1)
  5414. goto done;
  5415. list_for_each_entry(data, &hwsim_radios, list) {
  5416. if (data->idx <= last_idx)
  5417. continue;
  5418. if (!net_eq(wiphy_net(data->hw->wiphy), sock_net(skb->sk)))
  5419. continue;
  5420. res = mac80211_hwsim_get_radio(skb, data,
  5421. NETLINK_CB(cb->skb).portid,
  5422. cb->nlh->nlmsg_seq, cb,
  5423. NLM_F_MULTI);
  5424. if (res < 0)
  5425. break;
  5426. last_idx = data->idx;
  5427. }
  5428. cb->args[0] = last_idx + 1;
  5429. /* list changed, but no new element sent, set interrupted flag */
  5430. if (skb->len == 0 && cb->prev_seq && cb->seq != cb->prev_seq) {
  5431. hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
  5432. cb->nlh->nlmsg_seq, &hwsim_genl_family,
  5433. NLM_F_MULTI, HWSIM_CMD_GET_RADIO);
  5434. if (hdr) {
  5435. genl_dump_check_consistent(cb, hdr);
  5436. genlmsg_end(skb, hdr);
  5437. } else {
  5438. res = -EMSGSIZE;
  5439. }
  5440. }
  5441. done:
  5442. spin_unlock_bh(&hwsim_radio_lock);
  5443. return res ?: skb->len;
  5444. }
  5445. /* Generic Netlink operations array */
  5446. static const struct genl_small_ops hwsim_ops[] = {
  5447. {
  5448. .cmd = HWSIM_CMD_REGISTER,
  5449. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  5450. .doit = hwsim_register_received_nl,
  5451. .flags = GENL_UNS_ADMIN_PERM,
  5452. },
  5453. {
  5454. .cmd = HWSIM_CMD_FRAME,
  5455. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  5456. .doit = hwsim_cloned_frame_received_nl,
  5457. },
  5458. {
  5459. .cmd = HWSIM_CMD_TX_INFO_FRAME,
  5460. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  5461. .doit = hwsim_tx_info_frame_received_nl,
  5462. },
  5463. {
  5464. .cmd = HWSIM_CMD_NEW_RADIO,
  5465. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  5466. .doit = hwsim_new_radio_nl,
  5467. .flags = GENL_UNS_ADMIN_PERM,
  5468. },
  5469. {
  5470. .cmd = HWSIM_CMD_DEL_RADIO,
  5471. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  5472. .doit = hwsim_del_radio_nl,
  5473. .flags = GENL_UNS_ADMIN_PERM,
  5474. },
  5475. {
  5476. .cmd = HWSIM_CMD_GET_RADIO,
  5477. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  5478. .doit = hwsim_get_radio_nl,
  5479. .dumpit = hwsim_dump_radio_nl,
  5480. },
  5481. {
  5482. .cmd = HWSIM_CMD_REPORT_PMSR,
  5483. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  5484. .doit = hwsim_pmsr_report_nl,
  5485. },
  5486. };
  5487. static struct genl_family hwsim_genl_family __ro_after_init = {
  5488. .name = "MAC80211_HWSIM",
  5489. .version = 1,
  5490. .maxattr = HWSIM_ATTR_MAX,
  5491. .policy = hwsim_genl_policy,
  5492. .netnsok = true,
  5493. .module = THIS_MODULE,
  5494. .small_ops = hwsim_ops,
  5495. .n_small_ops = ARRAY_SIZE(hwsim_ops),
  5496. .resv_start_op = HWSIM_CMD_REPORT_PMSR + 1, // match with __HWSIM_CMD_MAX
  5497. .mcgrps = hwsim_mcgrps,
  5498. .n_mcgrps = ARRAY_SIZE(hwsim_mcgrps),
  5499. };
  5500. static void remove_user_radios(u32 portid)
  5501. {
  5502. struct mac80211_hwsim_data *entry, *tmp;
  5503. LIST_HEAD(list);
  5504. spin_lock_bh(&hwsim_radio_lock);
  5505. list_for_each_entry_safe(entry, tmp, &hwsim_radios, list) {
  5506. if (entry->destroy_on_close && entry->portid == portid) {
  5507. list_move(&entry->list, &list);
  5508. rhashtable_remove_fast(&hwsim_radios_rht, &entry->rht,
  5509. hwsim_rht_params);
  5510. hwsim_radios_generation++;
  5511. }
  5512. }
  5513. spin_unlock_bh(&hwsim_radio_lock);
  5514. list_for_each_entry_safe(entry, tmp, &list, list) {
  5515. list_del(&entry->list);
  5516. mac80211_hwsim_del_radio(entry, wiphy_name(entry->hw->wiphy),
  5517. NULL);
  5518. }
  5519. }
  5520. static int mac80211_hwsim_netlink_notify(struct notifier_block *nb,
  5521. unsigned long state,
  5522. void *_notify)
  5523. {
  5524. struct netlink_notify *notify = _notify;
  5525. if (state != NETLINK_URELEASE)
  5526. return NOTIFY_DONE;
  5527. remove_user_radios(notify->portid);
  5528. if (notify->portid == hwsim_net_get_wmediumd(notify->net)) {
  5529. printk(KERN_INFO "mac80211_hwsim: wmediumd released netlink"
  5530. " socket, switching to perfect channel medium\n");
  5531. hwsim_register_wmediumd(notify->net, 0);
  5532. }
  5533. return NOTIFY_DONE;
  5534. }
  5535. static struct notifier_block hwsim_netlink_notifier = {
  5536. .notifier_call = mac80211_hwsim_netlink_notify,
  5537. };
  5538. static int __init hwsim_init_netlink(void)
  5539. {
  5540. int rc;
  5541. printk(KERN_INFO "mac80211_hwsim: initializing netlink\n");
  5542. rc = genl_register_family(&hwsim_genl_family);
  5543. if (rc)
  5544. goto failure;
  5545. rc = netlink_register_notifier(&hwsim_netlink_notifier);
  5546. if (rc) {
  5547. genl_unregister_family(&hwsim_genl_family);
  5548. goto failure;
  5549. }
  5550. return 0;
  5551. failure:
  5552. pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
  5553. return -EINVAL;
  5554. }
  5555. static __net_init int hwsim_init_net(struct net *net)
  5556. {
  5557. return hwsim_net_set_netgroup(net);
  5558. }
  5559. static void __net_exit hwsim_exit_net(struct net *net)
  5560. {
  5561. struct mac80211_hwsim_data *data, *tmp;
  5562. LIST_HEAD(list);
  5563. spin_lock_bh(&hwsim_radio_lock);
  5564. list_for_each_entry_safe(data, tmp, &hwsim_radios, list) {
  5565. if (!net_eq(wiphy_net(data->hw->wiphy), net))
  5566. continue;
  5567. /* Radios created in init_net are returned to init_net. */
  5568. if (data->netgroup == hwsim_net_get_netgroup(&init_net))
  5569. continue;
  5570. list_move(&data->list, &list);
  5571. rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
  5572. hwsim_rht_params);
  5573. hwsim_radios_generation++;
  5574. }
  5575. spin_unlock_bh(&hwsim_radio_lock);
  5576. list_for_each_entry_safe(data, tmp, &list, list) {
  5577. list_del(&data->list);
  5578. mac80211_hwsim_del_radio(data,
  5579. wiphy_name(data->hw->wiphy),
  5580. NULL);
  5581. }
  5582. ida_free(&hwsim_netgroup_ida, hwsim_net_get_netgroup(net));
  5583. }
  5584. static struct pernet_operations hwsim_net_ops = {
  5585. .init = hwsim_init_net,
  5586. .exit = hwsim_exit_net,
  5587. .id = &hwsim_net_id,
  5588. .size = sizeof(struct hwsim_net),
  5589. };
  5590. static void hwsim_exit_netlink(void)
  5591. {
  5592. /* unregister the notifier */
  5593. netlink_unregister_notifier(&hwsim_netlink_notifier);
  5594. /* unregister the family */
  5595. genl_unregister_family(&hwsim_genl_family);
  5596. }
  5597. #if IS_REACHABLE(CONFIG_VIRTIO)
  5598. static void hwsim_virtio_tx_done(struct virtqueue *vq)
  5599. {
  5600. unsigned int len;
  5601. struct sk_buff *skb;
  5602. unsigned long flags;
  5603. spin_lock_irqsave(&hwsim_virtio_lock, flags);
  5604. while ((skb = virtqueue_get_buf(vq, &len)))
  5605. dev_kfree_skb_irq(skb);
  5606. spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
  5607. }
  5608. static int hwsim_virtio_handle_cmd(struct sk_buff *skb)
  5609. {
  5610. struct nlmsghdr *nlh;
  5611. struct genlmsghdr *gnlh;
  5612. struct nlattr *tb[HWSIM_ATTR_MAX + 1];
  5613. struct genl_info info = {};
  5614. int err;
  5615. nlh = nlmsg_hdr(skb);
  5616. gnlh = nlmsg_data(nlh);
  5617. if (skb->len < nlh->nlmsg_len)
  5618. return -EINVAL;
  5619. err = genlmsg_parse(nlh, &hwsim_genl_family, tb, HWSIM_ATTR_MAX,
  5620. hwsim_genl_policy, NULL);
  5621. if (err) {
  5622. pr_err_ratelimited("hwsim: genlmsg_parse returned %d\n", err);
  5623. return err;
  5624. }
  5625. info.attrs = tb;
  5626. switch (gnlh->cmd) {
  5627. case HWSIM_CMD_FRAME:
  5628. hwsim_cloned_frame_received_nl(skb, &info);
  5629. break;
  5630. case HWSIM_CMD_TX_INFO_FRAME:
  5631. hwsim_tx_info_frame_received_nl(skb, &info);
  5632. break;
  5633. case HWSIM_CMD_REPORT_PMSR:
  5634. hwsim_pmsr_report_nl(skb, &info);
  5635. break;
  5636. default:
  5637. pr_err_ratelimited("hwsim: invalid cmd: %d\n", gnlh->cmd);
  5638. return -EPROTO;
  5639. }
  5640. return 0;
  5641. }
  5642. static void hwsim_virtio_rx_work(struct work_struct *work)
  5643. {
  5644. struct virtqueue *vq;
  5645. unsigned int len;
  5646. struct sk_buff *skb;
  5647. struct scatterlist sg[1];
  5648. int err;
  5649. unsigned long flags;
  5650. spin_lock_irqsave(&hwsim_virtio_lock, flags);
  5651. if (!hwsim_virtio_enabled)
  5652. goto out_unlock;
  5653. skb = virtqueue_get_buf(hwsim_vqs[HWSIM_VQ_RX], &len);
  5654. if (!skb)
  5655. goto out_unlock;
  5656. spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
  5657. skb->data = skb->head;
  5658. skb_reset_tail_pointer(skb);
  5659. skb_put(skb, len);
  5660. hwsim_virtio_handle_cmd(skb);
  5661. spin_lock_irqsave(&hwsim_virtio_lock, flags);
  5662. if (!hwsim_virtio_enabled) {
  5663. dev_kfree_skb_irq(skb);
  5664. goto out_unlock;
  5665. }
  5666. vq = hwsim_vqs[HWSIM_VQ_RX];
  5667. sg_init_one(sg, skb->head, skb_end_offset(skb));
  5668. err = virtqueue_add_inbuf(vq, sg, 1, skb, GFP_ATOMIC);
  5669. if (WARN(err, "virtqueue_add_inbuf returned %d\n", err))
  5670. dev_kfree_skb_irq(skb);
  5671. else
  5672. virtqueue_kick(vq);
  5673. schedule_work(&hwsim_virtio_rx);
  5674. out_unlock:
  5675. spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
  5676. }
  5677. static void hwsim_virtio_rx_done(struct virtqueue *vq)
  5678. {
  5679. schedule_work(&hwsim_virtio_rx);
  5680. }
  5681. static int init_vqs(struct virtio_device *vdev)
  5682. {
  5683. struct virtqueue_info vqs_info[HWSIM_NUM_VQS] = {
  5684. [HWSIM_VQ_TX] = { "tx", hwsim_virtio_tx_done },
  5685. [HWSIM_VQ_RX] = { "rx", hwsim_virtio_rx_done },
  5686. };
  5687. return virtio_find_vqs(vdev, HWSIM_NUM_VQS,
  5688. hwsim_vqs, vqs_info, NULL);
  5689. }
  5690. static int fill_vq(struct virtqueue *vq)
  5691. {
  5692. int i, err;
  5693. struct sk_buff *skb;
  5694. struct scatterlist sg[1];
  5695. for (i = 0; i < virtqueue_get_vring_size(vq); i++) {
  5696. skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
  5697. if (!skb)
  5698. return -ENOMEM;
  5699. sg_init_one(sg, skb->head, skb_end_offset(skb));
  5700. err = virtqueue_add_inbuf(vq, sg, 1, skb, GFP_KERNEL);
  5701. if (err) {
  5702. nlmsg_free(skb);
  5703. return err;
  5704. }
  5705. }
  5706. virtqueue_kick(vq);
  5707. return 0;
  5708. }
  5709. static void remove_vqs(struct virtio_device *vdev)
  5710. {
  5711. int i;
  5712. virtio_reset_device(vdev);
  5713. for (i = 0; i < ARRAY_SIZE(hwsim_vqs); i++) {
  5714. struct virtqueue *vq = hwsim_vqs[i];
  5715. struct sk_buff *skb;
  5716. while ((skb = virtqueue_detach_unused_buf(vq)))
  5717. nlmsg_free(skb);
  5718. }
  5719. vdev->config->del_vqs(vdev);
  5720. }
  5721. static int hwsim_virtio_probe(struct virtio_device *vdev)
  5722. {
  5723. int err;
  5724. unsigned long flags;
  5725. spin_lock_irqsave(&hwsim_virtio_lock, flags);
  5726. if (hwsim_virtio_enabled) {
  5727. spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
  5728. return -EEXIST;
  5729. }
  5730. spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
  5731. err = init_vqs(vdev);
  5732. if (err)
  5733. return err;
  5734. virtio_device_ready(vdev);
  5735. err = fill_vq(hwsim_vqs[HWSIM_VQ_RX]);
  5736. if (err)
  5737. goto out_remove;
  5738. spin_lock_irqsave(&hwsim_virtio_lock, flags);
  5739. hwsim_virtio_enabled = true;
  5740. spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
  5741. schedule_work(&hwsim_virtio_rx);
  5742. return 0;
  5743. out_remove:
  5744. remove_vqs(vdev);
  5745. return err;
  5746. }
  5747. static void hwsim_virtio_remove(struct virtio_device *vdev)
  5748. {
  5749. hwsim_virtio_enabled = false;
  5750. cancel_work_sync(&hwsim_virtio_rx);
  5751. remove_vqs(vdev);
  5752. }
  5753. /* MAC80211_HWSIM virtio device id table */
  5754. static const struct virtio_device_id id_table[] = {
  5755. { VIRTIO_ID_MAC80211_HWSIM, VIRTIO_DEV_ANY_ID },
  5756. { 0 }
  5757. };
  5758. MODULE_DEVICE_TABLE(virtio, id_table);
  5759. static struct virtio_driver virtio_hwsim = {
  5760. .driver.name = KBUILD_MODNAME,
  5761. .id_table = id_table,
  5762. .probe = hwsim_virtio_probe,
  5763. .remove = hwsim_virtio_remove,
  5764. };
  5765. static int hwsim_register_virtio_driver(void)
  5766. {
  5767. return register_virtio_driver(&virtio_hwsim);
  5768. }
  5769. static void hwsim_unregister_virtio_driver(void)
  5770. {
  5771. unregister_virtio_driver(&virtio_hwsim);
  5772. }
  5773. #else
  5774. static inline int hwsim_register_virtio_driver(void)
  5775. {
  5776. return 0;
  5777. }
  5778. static inline void hwsim_unregister_virtio_driver(void)
  5779. {
  5780. }
  5781. #endif
  5782. static int __init init_mac80211_hwsim(void)
  5783. {
  5784. int i, err;
  5785. if (radios < 0 || radios > 100)
  5786. return -EINVAL;
  5787. if (channels < 1)
  5788. return -EINVAL;
  5789. err = rhashtable_init(&hwsim_radios_rht, &hwsim_rht_params);
  5790. if (err)
  5791. return err;
  5792. err = register_pernet_device(&hwsim_net_ops);
  5793. if (err)
  5794. goto out_free_rht;
  5795. err = platform_driver_register(&mac80211_hwsim_driver);
  5796. if (err)
  5797. goto out_unregister_pernet;
  5798. err = hwsim_init_netlink();
  5799. if (err)
  5800. goto out_unregister_driver;
  5801. err = hwsim_register_virtio_driver();
  5802. if (err)
  5803. goto out_exit_netlink;
  5804. hwsim_class = class_create("mac80211_hwsim");
  5805. if (IS_ERR(hwsim_class)) {
  5806. err = PTR_ERR(hwsim_class);
  5807. goto out_exit_virtio;
  5808. }
  5809. hwsim_init_s1g_channels(hwsim_channels_s1g);
  5810. for (i = 0; i < radios; i++) {
  5811. struct hwsim_new_radio_params param = { 0 };
  5812. param.channels = channels;
  5813. switch (regtest) {
  5814. case HWSIM_REGTEST_DIFF_COUNTRY:
  5815. if (i < ARRAY_SIZE(hwsim_alpha2s))
  5816. param.reg_alpha2 = hwsim_alpha2s[i];
  5817. break;
  5818. case HWSIM_REGTEST_DRIVER_REG_FOLLOW:
  5819. if (!i)
  5820. param.reg_alpha2 = hwsim_alpha2s[0];
  5821. break;
  5822. case HWSIM_REGTEST_STRICT_ALL:
  5823. param.reg_strict = true;
  5824. fallthrough;
  5825. case HWSIM_REGTEST_DRIVER_REG_ALL:
  5826. param.reg_alpha2 = hwsim_alpha2s[0];
  5827. break;
  5828. case HWSIM_REGTEST_WORLD_ROAM:
  5829. if (i == 0)
  5830. param.regd = &hwsim_world_regdom_custom_01;
  5831. break;
  5832. case HWSIM_REGTEST_CUSTOM_WORLD:
  5833. param.regd = &hwsim_world_regdom_custom_03;
  5834. break;
  5835. case HWSIM_REGTEST_CUSTOM_WORLD_2:
  5836. if (i == 0)
  5837. param.regd = &hwsim_world_regdom_custom_03;
  5838. else if (i == 1)
  5839. param.regd = &hwsim_world_regdom_custom_02;
  5840. break;
  5841. case HWSIM_REGTEST_STRICT_FOLLOW:
  5842. if (i == 0) {
  5843. param.reg_strict = true;
  5844. param.reg_alpha2 = hwsim_alpha2s[0];
  5845. }
  5846. break;
  5847. case HWSIM_REGTEST_STRICT_AND_DRIVER_REG:
  5848. if (i == 0) {
  5849. param.reg_strict = true;
  5850. param.reg_alpha2 = hwsim_alpha2s[0];
  5851. } else if (i == 1) {
  5852. param.reg_alpha2 = hwsim_alpha2s[1];
  5853. }
  5854. break;
  5855. case HWSIM_REGTEST_ALL:
  5856. switch (i) {
  5857. case 0:
  5858. param.regd = &hwsim_world_regdom_custom_01;
  5859. break;
  5860. case 1:
  5861. param.regd = &hwsim_world_regdom_custom_02;
  5862. break;
  5863. case 2:
  5864. param.reg_alpha2 = hwsim_alpha2s[0];
  5865. break;
  5866. case 3:
  5867. param.reg_alpha2 = hwsim_alpha2s[1];
  5868. break;
  5869. case 4:
  5870. param.reg_strict = true;
  5871. param.reg_alpha2 = hwsim_alpha2s[2];
  5872. break;
  5873. }
  5874. break;
  5875. default:
  5876. break;
  5877. }
  5878. param.p2p_device = support_p2p_device;
  5879. param.mlo = mlo;
  5880. param.multi_radio = multi_radio;
  5881. param.use_chanctx = channels > 1 || mlo || multi_radio;
  5882. param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK;
  5883. if (param.p2p_device)
  5884. param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE);
  5885. err = mac80211_hwsim_new_radio(NULL, &param);
  5886. if (err < 0)
  5887. goto out_free_radios;
  5888. }
  5889. hwsim_mon = alloc_netdev(0, "hwsim%d", NET_NAME_UNKNOWN,
  5890. hwsim_mon_setup);
  5891. if (hwsim_mon == NULL) {
  5892. err = -ENOMEM;
  5893. goto out_free_radios;
  5894. }
  5895. rtnl_lock();
  5896. err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
  5897. if (err < 0) {
  5898. rtnl_unlock();
  5899. goto out_free_mon;
  5900. }
  5901. err = register_netdevice(hwsim_mon);
  5902. if (err < 0) {
  5903. rtnl_unlock();
  5904. goto out_free_mon;
  5905. }
  5906. rtnl_unlock();
  5907. return 0;
  5908. out_free_mon:
  5909. free_netdev(hwsim_mon);
  5910. out_free_radios:
  5911. mac80211_hwsim_free();
  5912. out_exit_virtio:
  5913. hwsim_unregister_virtio_driver();
  5914. out_exit_netlink:
  5915. hwsim_exit_netlink();
  5916. out_unregister_driver:
  5917. platform_driver_unregister(&mac80211_hwsim_driver);
  5918. out_unregister_pernet:
  5919. unregister_pernet_device(&hwsim_net_ops);
  5920. out_free_rht:
  5921. rhashtable_destroy(&hwsim_radios_rht);
  5922. return err;
  5923. }
  5924. module_init(init_mac80211_hwsim);
  5925. static void __exit exit_mac80211_hwsim(void)
  5926. {
  5927. pr_debug("mac80211_hwsim: unregister radios\n");
  5928. hwsim_unregister_virtio_driver();
  5929. hwsim_exit_netlink();
  5930. mac80211_hwsim_free();
  5931. rhashtable_destroy(&hwsim_radios_rht);
  5932. unregister_netdev(hwsim_mon);
  5933. platform_driver_unregister(&mac80211_hwsim_driver);
  5934. unregister_pernet_device(&hwsim_net_ops);
  5935. }
  5936. module_exit(exit_mac80211_hwsim);