ioctl_cfg80211.c 290 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #define _IOCTL_CFG80211_C_
  16. #include <drv_types.h>
  17. #include <hal_data.h>
  18. #ifdef CONFIG_IOCTL_CFG80211
  19. #ifndef DBG_RTW_CFG80211_STA_PARAM
  20. #define DBG_RTW_CFG80211_STA_PARAM 0
  21. #endif
  22. #ifndef DBG_RTW_CFG80211_MESH_CONF
  23. #define DBG_RTW_CFG80211_MESH_CONF 0
  24. #endif
  25. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0))
  26. #define STATION_INFO_INACTIVE_TIME BIT(NL80211_STA_INFO_INACTIVE_TIME)
  27. #define STATION_INFO_LLID BIT(NL80211_STA_INFO_LLID)
  28. #define STATION_INFO_PLID BIT(NL80211_STA_INFO_PLID)
  29. #define STATION_INFO_PLINK_STATE BIT(NL80211_STA_INFO_PLINK_STATE)
  30. #define STATION_INFO_SIGNAL BIT(NL80211_STA_INFO_SIGNAL)
  31. #define STATION_INFO_TX_BITRATE BIT(NL80211_STA_INFO_TX_BITRATE)
  32. #define STATION_INFO_RX_PACKETS BIT(NL80211_STA_INFO_RX_PACKETS)
  33. #define STATION_INFO_TX_PACKETS BIT(NL80211_STA_INFO_TX_PACKETS)
  34. #define STATION_INFO_TX_FAILED BIT(NL80211_STA_INFO_TX_FAILED)
  35. #define STATION_INFO_LOCAL_PM BIT(NL80211_STA_INFO_LOCAL_PM)
  36. #define STATION_INFO_PEER_PM BIT(NL80211_STA_INFO_PEER_PM)
  37. #define STATION_INFO_NONPEER_PM BIT(NL80211_STA_INFO_NONPEER_PM)
  38. #define STATION_INFO_ASSOC_REQ_IES 0
  39. #endif /* Linux kernel >= 4.0.0 */
  40. #include <rtw_wifi_regd.h>
  41. #define RTW_MAX_MGMT_TX_CNT (8)
  42. #define RTW_MAX_MGMT_TX_MS_GAS (500)
  43. #define RTW_SCAN_IE_LEN_MAX 2304
  44. #define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 5000 /* ms */
  45. #define RTW_MAX_NUM_PMKIDS 4
  46. #define RTW_CH_MAX_2G_CHANNEL 14 /* Max channel in 2G band */
  47. #ifdef CONFIG_WAPI_SUPPORT
  48. #ifndef WLAN_CIPHER_SUITE_SMS4
  49. #define WLAN_CIPHER_SUITE_SMS4 0x00147201
  50. #endif
  51. #ifndef WLAN_AKM_SUITE_WAPI_PSK
  52. #define WLAN_AKM_SUITE_WAPI_PSK 0x000FAC04
  53. #endif
  54. #ifndef WLAN_AKM_SUITE_WAPI_CERT
  55. #define WLAN_AKM_SUITE_WAPI_CERT 0x000FAC12
  56. #endif
  57. #ifndef NL80211_WAPI_VERSION_1
  58. #define NL80211_WAPI_VERSION_1 (1 << 2)
  59. #endif
  60. #endif /* CONFIG_WAPI_SUPPORT */
  61. #ifdef CONFIG_RTW_80211R
  62. #define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
  63. #define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
  64. #endif
  65. /*
  66. * In the current design of Wi-Fi driver, it will return success to the system (e.g. supplicant)
  67. * when Wi-Fi driver decides to abort the scan request in the scan flow by default.
  68. * Defining this flag makes Wi-Fi driver to return -EBUSY to the system if Wi-Fi driver is too busy to do the scan.
  69. */
  70. #ifndef CONFIG_NOTIFY_SCAN_ABORT_WITH_BUSY
  71. #define CONFIG_NOTIFY_SCAN_ABORT_WITH_BUSY 0
  72. #endif
  73. static const u32 rtw_cipher_suites[] = {
  74. WLAN_CIPHER_SUITE_WEP40,
  75. WLAN_CIPHER_SUITE_WEP104,
  76. WLAN_CIPHER_SUITE_TKIP,
  77. WLAN_CIPHER_SUITE_CCMP,
  78. #ifdef CONFIG_WAPI_SUPPORT
  79. WLAN_CIPHER_SUITE_SMS4,
  80. #endif /* CONFIG_WAPI_SUPPORT */
  81. #ifdef CONFIG_IEEE80211W
  82. WLAN_CIPHER_SUITE_AES_CMAC,
  83. #endif /* CONFIG_IEEE80211W */
  84. };
  85. #define RATETAB_ENT(_rate, _rateid, _flags) \
  86. { \
  87. .bitrate = (_rate), \
  88. .hw_value = (_rateid), \
  89. .flags = (_flags), \
  90. }
  91. #define CHAN2G(_channel, _freq, _flags) { \
  92. .band = NL80211_BAND_2GHZ, \
  93. .center_freq = (_freq), \
  94. .hw_value = (_channel), \
  95. .flags = (_flags), \
  96. .max_antenna_gain = 0, \
  97. .max_power = 30, \
  98. }
  99. #define CHAN5G(_channel, _flags) { \
  100. .band = NL80211_BAND_5GHZ, \
  101. .center_freq = 5000 + (5 * (_channel)), \
  102. .hw_value = (_channel), \
  103. .flags = (_flags), \
  104. .max_antenna_gain = 0, \
  105. .max_power = 30, \
  106. }
  107. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  108. /* if wowlan is not supported, kernel generate a disconnect at each suspend
  109. * cf: /net/wireless/sysfs.c, so register a stub wowlan.
  110. * Moreover wowlan has to be enabled via a the nl80211_set_wowlan callback.
  111. * (from user space, e.g. iw phy0 wowlan enable)
  112. */
  113. static const struct wiphy_wowlan_support wowlan_stub = {
  114. .flags = WIPHY_WOWLAN_ANY,
  115. .n_patterns = 0,
  116. .pattern_max_len = 0,
  117. .pattern_min_len = 0,
  118. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  119. .max_pkt_offset = 0,
  120. #endif
  121. };
  122. #endif
  123. static struct ieee80211_rate rtw_rates[] = {
  124. RATETAB_ENT(10, 0x1, 0),
  125. RATETAB_ENT(20, 0x2, 0),
  126. RATETAB_ENT(55, 0x4, 0),
  127. RATETAB_ENT(110, 0x8, 0),
  128. RATETAB_ENT(60, 0x10, 0),
  129. RATETAB_ENT(90, 0x20, 0),
  130. RATETAB_ENT(120, 0x40, 0),
  131. RATETAB_ENT(180, 0x80, 0),
  132. RATETAB_ENT(240, 0x100, 0),
  133. RATETAB_ENT(360, 0x200, 0),
  134. RATETAB_ENT(480, 0x400, 0),
  135. RATETAB_ENT(540, 0x800, 0),
  136. };
  137. #define rtw_a_rates (rtw_rates + 4)
  138. #define RTW_A_RATES_NUM 8
  139. #define rtw_g_rates (rtw_rates + 0)
  140. #define RTW_G_RATES_NUM 12
  141. /* from center_ch_2g */
  142. static struct ieee80211_channel rtw_2ghz_channels[MAX_CHANNEL_NUM_2G] = {
  143. CHAN2G(1, 2412, 0),
  144. CHAN2G(2, 2417, 0),
  145. CHAN2G(3, 2422, 0),
  146. CHAN2G(4, 2427, 0),
  147. CHAN2G(5, 2432, 0),
  148. CHAN2G(6, 2437, 0),
  149. CHAN2G(7, 2442, 0),
  150. CHAN2G(8, 2447, 0),
  151. CHAN2G(9, 2452, 0),
  152. CHAN2G(10, 2457, 0),
  153. CHAN2G(11, 2462, 0),
  154. CHAN2G(12, 2467, 0),
  155. CHAN2G(13, 2472, 0),
  156. CHAN2G(14, 2484, 0),
  157. };
  158. /* from center_ch_5g_20m */
  159. static struct ieee80211_channel rtw_5ghz_a_channels[MAX_CHANNEL_NUM_5G] = {
  160. CHAN5G(36, 0), CHAN5G(40, 0), CHAN5G(44, 0), CHAN5G(48, 0),
  161. CHAN5G(52, 0), CHAN5G(56, 0), CHAN5G(60, 0), CHAN5G(64, 0),
  162. CHAN5G(100, 0), CHAN5G(104, 0), CHAN5G(108, 0), CHAN5G(112, 0),
  163. CHAN5G(116, 0), CHAN5G(120, 0), CHAN5G(124, 0), CHAN5G(128, 0),
  164. CHAN5G(132, 0), CHAN5G(136, 0), CHAN5G(140, 0), CHAN5G(144, 0),
  165. CHAN5G(149, 0), CHAN5G(153, 0), CHAN5G(157, 0), CHAN5G(161, 0),
  166. CHAN5G(165, 0), CHAN5G(169, 0), CHAN5G(173, 0), CHAN5G(177, 0),
  167. };
  168. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  169. static const char *nl80211_channel_type_str(enum nl80211_channel_type ctype)
  170. {
  171. switch (ctype) {
  172. case NL80211_CHAN_NO_HT:
  173. return "NO_HT";
  174. case NL80211_CHAN_HT20:
  175. return "HT20";
  176. case NL80211_CHAN_HT40MINUS:
  177. return "HT40-";
  178. case NL80211_CHAN_HT40PLUS:
  179. return "HT40+";
  180. default:
  181. return "INVALID";
  182. };
  183. }
  184. static enum nl80211_channel_type rtw_chbw_to_nl80211_channel_type(u8 ch, u8 bw, u8 offset, u8 ht)
  185. {
  186. rtw_warn_on(!ht && (bw >= CHANNEL_WIDTH_40 || offset != HAL_PRIME_CHNL_OFFSET_DONT_CARE));
  187. if (!ht)
  188. return NL80211_CHAN_NO_HT;
  189. if (bw >= CHANNEL_WIDTH_40) {
  190. if (offset == HAL_PRIME_CHNL_OFFSET_UPPER)
  191. return NL80211_CHAN_HT40MINUS;
  192. else if (offset == HAL_PRIME_CHNL_OFFSET_LOWER)
  193. return NL80211_CHAN_HT40PLUS;
  194. else
  195. rtw_warn_on(1);
  196. }
  197. return NL80211_CHAN_HT20;
  198. }
  199. static void rtw_get_chbw_from_nl80211_channel_type(struct ieee80211_channel *chan, enum nl80211_channel_type ctype, u8 *ht, u8 *ch, u8 *bw, u8 *offset)
  200. {
  201. int pri_freq;
  202. pri_freq = rtw_ch2freq(chan->hw_value);
  203. if (!pri_freq) {
  204. RTW_INFO("invalid channel:%d\n", chan->hw_value);
  205. rtw_warn_on(1);
  206. *ch = 0;
  207. return;
  208. }
  209. *ch = chan->hw_value;
  210. switch (ctype) {
  211. case NL80211_CHAN_NO_HT:
  212. *ht = 0;
  213. *bw = CHANNEL_WIDTH_20;
  214. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  215. break;
  216. case NL80211_CHAN_HT20:
  217. *ht = 1;
  218. *bw = CHANNEL_WIDTH_20;
  219. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  220. break;
  221. case NL80211_CHAN_HT40MINUS:
  222. *ht = 1;
  223. *bw = CHANNEL_WIDTH_40;
  224. *offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  225. break;
  226. case NL80211_CHAN_HT40PLUS:
  227. *ht = 1;
  228. *bw = CHANNEL_WIDTH_40;
  229. *offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  230. break;
  231. default:
  232. *ht = 0;
  233. *bw = CHANNEL_WIDTH_20;
  234. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  235. RTW_INFO("unsupported ctype:%s\n", nl80211_channel_type_str(ctype));
  236. rtw_warn_on(1);
  237. };
  238. }
  239. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)) */
  240. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  241. static const char *nl80211_chan_width_str(enum nl80211_chan_width cwidth)
  242. {
  243. switch (cwidth) {
  244. case NL80211_CHAN_WIDTH_20_NOHT:
  245. return "20_NOHT";
  246. case NL80211_CHAN_WIDTH_20:
  247. return "20";
  248. case NL80211_CHAN_WIDTH_40:
  249. return "40";
  250. case NL80211_CHAN_WIDTH_80:
  251. return "80";
  252. case NL80211_CHAN_WIDTH_80P80:
  253. return "80+80";
  254. case NL80211_CHAN_WIDTH_160:
  255. return "160";
  256. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  257. case NL80211_CHAN_WIDTH_5:
  258. return "5";
  259. case NL80211_CHAN_WIDTH_10:
  260. return "10";
  261. #endif
  262. default:
  263. return "INVALID";
  264. };
  265. }
  266. static u8 rtw_chbw_to_cfg80211_chan_def(struct wiphy *wiphy, struct cfg80211_chan_def *chdef, u8 ch, u8 bw, u8 offset, u8 ht)
  267. {
  268. int freq, cfreq;
  269. struct ieee80211_channel *chan;
  270. u8 ret = _FAIL;
  271. freq = rtw_ch2freq(ch);
  272. if (!freq)
  273. goto exit;
  274. cfreq = rtw_get_center_ch(ch, bw, offset);
  275. if (!cfreq)
  276. goto exit;
  277. cfreq = rtw_ch2freq(cfreq);
  278. if (!cfreq)
  279. goto exit;
  280. chan = ieee80211_get_channel(wiphy, freq);
  281. if (!chan)
  282. goto exit;
  283. if (bw == CHANNEL_WIDTH_20)
  284. chdef->width = ht ? NL80211_CHAN_WIDTH_20 : NL80211_CHAN_WIDTH_20_NOHT;
  285. else if (bw == CHANNEL_WIDTH_40)
  286. chdef->width = NL80211_CHAN_WIDTH_40;
  287. else if (bw == CHANNEL_WIDTH_80)
  288. chdef->width = NL80211_CHAN_WIDTH_80;
  289. else if (bw == CHANNEL_WIDTH_160)
  290. chdef->width = NL80211_CHAN_WIDTH_160;
  291. else {
  292. rtw_warn_on(1);
  293. goto exit;
  294. }
  295. chdef->chan = chan;
  296. chdef->center_freq1 = cfreq;
  297. chdef->center_freq2 = 0;
  298. ret = _SUCCESS;
  299. exit:
  300. return ret;
  301. }
  302. static void rtw_get_chbw_from_cfg80211_chan_def(struct cfg80211_chan_def *chdef, u8 *ht, u8 *ch, u8 *bw, u8 *offset)
  303. {
  304. int pri_freq;
  305. struct ieee80211_channel *chan = chdef->chan;
  306. pri_freq = rtw_ch2freq(chan->hw_value);
  307. if (!pri_freq) {
  308. RTW_INFO("invalid channel:%d\n", chan->hw_value);
  309. rtw_warn_on(1);
  310. *ch = 0;
  311. return;
  312. }
  313. switch (chdef->width) {
  314. case NL80211_CHAN_WIDTH_20_NOHT:
  315. *ht = 0;
  316. *bw = CHANNEL_WIDTH_20;
  317. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  318. *ch = chan->hw_value;
  319. break;
  320. case NL80211_CHAN_WIDTH_20:
  321. *ht = 1;
  322. *bw = CHANNEL_WIDTH_20;
  323. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  324. *ch = chan->hw_value;
  325. break;
  326. case NL80211_CHAN_WIDTH_40:
  327. *ht = 1;
  328. *bw = CHANNEL_WIDTH_40;
  329. *offset = pri_freq > chdef->center_freq1 ? HAL_PRIME_CHNL_OFFSET_UPPER : HAL_PRIME_CHNL_OFFSET_LOWER;
  330. if (rtw_get_offset_by_chbw(chan->hw_value, *bw, offset))
  331. *ch = chan->hw_value;
  332. break;
  333. case NL80211_CHAN_WIDTH_80:
  334. *ht = 1;
  335. *bw = CHANNEL_WIDTH_80;
  336. if (rtw_get_offset_by_chbw(chan->hw_value, *bw, offset))
  337. *ch = chan->hw_value;
  338. break;
  339. case NL80211_CHAN_WIDTH_160:
  340. *ht = 1;
  341. *bw = CHANNEL_WIDTH_160;
  342. if (rtw_get_offset_by_chbw(chan->hw_value, *bw, offset))
  343. *ch = chan->hw_value;
  344. break;
  345. case NL80211_CHAN_WIDTH_80P80:
  346. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  347. case NL80211_CHAN_WIDTH_5:
  348. case NL80211_CHAN_WIDTH_10:
  349. #endif
  350. default:
  351. *ht = 0;
  352. *bw = CHANNEL_WIDTH_20;
  353. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  354. RTW_INFO("unsupported cwidth:%s\n", nl80211_chan_width_str(chdef->width));
  355. rtw_warn_on(1);
  356. };
  357. }
  358. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) */
  359. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  360. u8 rtw_cfg80211_ch_switch_notify(_adapter *adapter, u8 ch, u8 bw, u8 offset, u8 ht)
  361. {
  362. struct wiphy *wiphy = adapter_to_wiphy(adapter);
  363. u8 ret = _SUCCESS;
  364. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  365. struct cfg80211_chan_def chdef;
  366. ret = rtw_chbw_to_cfg80211_chan_def(wiphy, &chdef, ch, bw, offset, ht);
  367. if (ret != _SUCCESS)
  368. goto exit;
  369. #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 2)
  370. cfg80211_ch_switch_notify(adapter->pnetdev, &chdef);
  371. #elif LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0)
  372. cfg80211_ch_switch_notify(adapter->pnetdev, &chdef, 0);
  373. #else
  374. cfg80211_ch_switch_notify(adapter->pnetdev, &chdef, 0, 0);
  375. #endif
  376. #else
  377. int freq = rtw_ch2freq(ch);
  378. enum nl80211_channel_type ctype;
  379. if (!freq) {
  380. ret = _FAIL;
  381. goto exit;
  382. }
  383. ctype = rtw_chbw_to_nl80211_channel_type(ch, bw, offset, ht);
  384. cfg80211_ch_switch_notify(adapter->pnetdev, freq, ctype);
  385. #endif
  386. exit:
  387. return ret;
  388. }
  389. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) */
  390. void rtw_2g_channels_init(struct ieee80211_channel *channels)
  391. {
  392. _rtw_memcpy((void *)channels, (void *)rtw_2ghz_channels, sizeof(rtw_2ghz_channels));
  393. }
  394. void rtw_5g_channels_init(struct ieee80211_channel *channels)
  395. {
  396. _rtw_memcpy((void *)channels, (void *)rtw_5ghz_a_channels, sizeof(rtw_5ghz_a_channels));
  397. }
  398. void rtw_2g_rates_init(struct ieee80211_rate *rates)
  399. {
  400. _rtw_memcpy(rates, rtw_g_rates,
  401. sizeof(struct ieee80211_rate) * RTW_G_RATES_NUM
  402. );
  403. }
  404. void rtw_5g_rates_init(struct ieee80211_rate *rates)
  405. {
  406. _rtw_memcpy(rates, rtw_a_rates,
  407. sizeof(struct ieee80211_rate) * RTW_A_RATES_NUM
  408. );
  409. }
  410. struct ieee80211_supported_band *rtw_spt_band_alloc(BAND_TYPE band)
  411. {
  412. struct ieee80211_supported_band *spt_band = NULL;
  413. int n_channels, n_bitrates;
  414. if (band == BAND_ON_2_4G) {
  415. n_channels = MAX_CHANNEL_NUM_2G;
  416. n_bitrates = RTW_G_RATES_NUM;
  417. } else if (band == BAND_ON_5G) {
  418. n_channels = MAX_CHANNEL_NUM_5G;
  419. n_bitrates = RTW_A_RATES_NUM;
  420. } else
  421. goto exit;
  422. spt_band = (struct ieee80211_supported_band *)rtw_zmalloc(
  423. sizeof(struct ieee80211_supported_band)
  424. + sizeof(struct ieee80211_channel) * n_channels
  425. + sizeof(struct ieee80211_rate) * n_bitrates
  426. );
  427. if (!spt_band)
  428. goto exit;
  429. spt_band->channels = (struct ieee80211_channel *)(((u8 *)spt_band) + sizeof(struct ieee80211_supported_band));
  430. spt_band->bitrates = (struct ieee80211_rate *)(((u8 *)spt_band->channels) + sizeof(struct ieee80211_channel) * n_channels);
  431. spt_band->band = rtw_band_to_nl80211_band(band);
  432. spt_band->n_channels = n_channels;
  433. spt_band->n_bitrates = n_bitrates;
  434. if (band == BAND_ON_2_4G) {
  435. rtw_2g_channels_init(spt_band->channels);
  436. rtw_2g_rates_init(spt_band->bitrates);
  437. } else if (band == BAND_ON_5G) {
  438. rtw_5g_channels_init(spt_band->channels);
  439. rtw_5g_rates_init(spt_band->bitrates);
  440. }
  441. /* spt_band.ht_cap */
  442. exit:
  443. return spt_band;
  444. }
  445. void rtw_spt_band_free(struct ieee80211_supported_band *spt_band)
  446. {
  447. u32 size = 0;
  448. if (!spt_band)
  449. return;
  450. if (spt_band->band == NL80211_BAND_2GHZ) {
  451. size = sizeof(struct ieee80211_supported_band)
  452. + sizeof(struct ieee80211_channel) * MAX_CHANNEL_NUM_2G
  453. + sizeof(struct ieee80211_rate) * RTW_G_RATES_NUM;
  454. } else if (spt_band->band == NL80211_BAND_5GHZ) {
  455. size = sizeof(struct ieee80211_supported_band)
  456. + sizeof(struct ieee80211_channel) * MAX_CHANNEL_NUM_5G
  457. + sizeof(struct ieee80211_rate) * RTW_A_RATES_NUM;
  458. } else {
  459. }
  460. rtw_mfree((u8 *)spt_band, size);
  461. }
  462. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  463. static const struct ieee80211_txrx_stypes
  464. rtw_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  465. [NL80211_IFTYPE_ADHOC] = {
  466. .tx = 0xffff,
  467. .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
  468. },
  469. [NL80211_IFTYPE_STATION] = {
  470. .tx = 0xffff,
  471. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  472. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  473. },
  474. [NL80211_IFTYPE_AP] = {
  475. .tx = 0xffff,
  476. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  477. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  478. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  479. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  480. BIT(IEEE80211_STYPE_AUTH >> 4) |
  481. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  482. BIT(IEEE80211_STYPE_ACTION >> 4)
  483. },
  484. [NL80211_IFTYPE_AP_VLAN] = {
  485. /* copy AP */
  486. .tx = 0xffff,
  487. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  488. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  489. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  490. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  491. BIT(IEEE80211_STYPE_AUTH >> 4) |
  492. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  493. BIT(IEEE80211_STYPE_ACTION >> 4)
  494. },
  495. [NL80211_IFTYPE_P2P_CLIENT] = {
  496. .tx = 0xffff,
  497. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  498. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  499. },
  500. [NL80211_IFTYPE_P2P_GO] = {
  501. .tx = 0xffff,
  502. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  503. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  504. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  505. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  506. BIT(IEEE80211_STYPE_AUTH >> 4) |
  507. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  508. BIT(IEEE80211_STYPE_ACTION >> 4)
  509. },
  510. #if defined(RTW_DEDICATED_P2P_DEVICE)
  511. [NL80211_IFTYPE_P2P_DEVICE] = {
  512. .tx = 0xffff,
  513. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  514. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  515. },
  516. #endif
  517. #if defined(CONFIG_RTW_MESH)
  518. [NL80211_IFTYPE_MESH_POINT] = {
  519. .tx = 0xffff,
  520. .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
  521. | BIT(IEEE80211_STYPE_AUTH >> 4)
  522. },
  523. #endif
  524. };
  525. #endif
  526. NDIS_802_11_NETWORK_INFRASTRUCTURE nl80211_iftype_to_rtw_network_type(enum nl80211_iftype type)
  527. {
  528. switch (type) {
  529. case NL80211_IFTYPE_ADHOC:
  530. return Ndis802_11IBSS;
  531. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  532. case NL80211_IFTYPE_P2P_CLIENT:
  533. #endif
  534. case NL80211_IFTYPE_STATION:
  535. return Ndis802_11Infrastructure;
  536. #ifdef CONFIG_AP_MODE
  537. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  538. case NL80211_IFTYPE_P2P_GO:
  539. #endif
  540. case NL80211_IFTYPE_AP:
  541. return Ndis802_11APMode;
  542. #endif
  543. #ifdef CONFIG_RTW_MESH
  544. case NL80211_IFTYPE_MESH_POINT:
  545. return Ndis802_11_mesh;
  546. #endif
  547. case NL80211_IFTYPE_MONITOR:
  548. return Ndis802_11Monitor;
  549. default:
  550. return Ndis802_11InfrastructureMax;
  551. }
  552. }
  553. u32 nl80211_iftype_to_rtw_mlme_state(enum nl80211_iftype type)
  554. {
  555. switch (type) {
  556. case NL80211_IFTYPE_ADHOC:
  557. return WIFI_ADHOC_STATE;
  558. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  559. case NL80211_IFTYPE_P2P_CLIENT:
  560. #endif
  561. case NL80211_IFTYPE_STATION:
  562. return WIFI_STATION_STATE;
  563. #ifdef CONFIG_AP_MODE
  564. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  565. case NL80211_IFTYPE_P2P_GO:
  566. #endif
  567. case NL80211_IFTYPE_AP:
  568. return WIFI_AP_STATE;
  569. #endif
  570. #ifdef CONFIG_RTW_MESH
  571. case NL80211_IFTYPE_MESH_POINT:
  572. return WIFI_MESH_STATE;
  573. #endif
  574. case NL80211_IFTYPE_MONITOR:
  575. return WIFI_MONITOR_STATE;
  576. default:
  577. return WIFI_NULL_STATE;
  578. }
  579. }
  580. static int rtw_cfg80211_sync_iftype(_adapter *adapter)
  581. {
  582. struct wireless_dev *rtw_wdev = adapter->rtw_wdev;
  583. if (!(nl80211_iftype_to_rtw_mlme_state(rtw_wdev->iftype) & MLME_STATE(adapter))) {
  584. /* iftype and mlme state is not syc */
  585. NDIS_802_11_NETWORK_INFRASTRUCTURE network_type;
  586. network_type = nl80211_iftype_to_rtw_network_type(rtw_wdev->iftype);
  587. if (network_type != Ndis802_11InfrastructureMax) {
  588. if (rtw_pwr_wakeup(adapter) == _FAIL) {
  589. RTW_WARN(FUNC_ADPT_FMT" call rtw_pwr_wakeup fail\n", FUNC_ADPT_ARG(adapter));
  590. return _FAIL;
  591. }
  592. rtw_set_802_11_infrastructure_mode(adapter, network_type);
  593. rtw_setopmode_cmd(adapter, network_type, RTW_CMDF_WAIT_ACK);
  594. } else {
  595. rtw_warn_on(1);
  596. RTW_WARN(FUNC_ADPT_FMT" iftype:%u is not support\n", FUNC_ADPT_ARG(adapter), rtw_wdev->iftype);
  597. return _FAIL;
  598. }
  599. }
  600. return _SUCCESS;
  601. }
  602. static u64 rtw_get_systime_us(void)
  603. {
  604. return ktime_to_us(ktime_get_boottime());
  605. }
  606. /* Try to remove non target BSS's SR to reduce PBC overlap rate */
  607. static int rtw_cfg80211_clear_wps_sr_of_non_target_bss(_adapter *padapter, struct wlan_network *pnetwork, struct cfg80211_ssid *req_ssid)
  608. {
  609. int ret = 0;
  610. u8 *psr = NULL, sr = 0;
  611. NDIS_802_11_SSID *pssid = &pnetwork->network.Ssid;
  612. u32 wpsielen = 0;
  613. u8 *wpsie = NULL;
  614. if (pssid->SsidLength == req_ssid->ssid_len
  615. && _rtw_memcmp(pssid->Ssid, req_ssid->ssid, req_ssid->ssid_len) == _TRUE)
  616. goto exit;
  617. wpsie = rtw_get_wps_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_
  618. , pnetwork->network.IELength - _FIXED_IE_LENGTH_, NULL, &wpsielen);
  619. if (wpsie && wpsielen > 0)
  620. psr = rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_SELECTED_REGISTRAR, &sr, NULL);
  621. if (psr && sr) {
  622. if (0)
  623. RTW_INFO("clear sr of non target bss:%s("MAC_FMT")\n"
  624. , pssid->Ssid, MAC_ARG(pnetwork->network.MacAddress));
  625. *psr = 0; /* clear sr */
  626. ret = 1;
  627. }
  628. exit:
  629. return ret;
  630. }
  631. #define MAX_BSSINFO_LEN 1000
  632. struct cfg80211_bss *rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnetwork)
  633. {
  634. struct ieee80211_channel *notify_channel;
  635. struct cfg80211_bss *bss = NULL;
  636. /* struct ieee80211_supported_band *band; */
  637. u16 channel;
  638. u32 freq;
  639. u64 notify_timestamp;
  640. u16 notify_capability;
  641. u16 notify_interval;
  642. u8 *notify_ie;
  643. size_t notify_ielen;
  644. s32 notify_signal;
  645. /* u8 buf[MAX_BSSINFO_LEN]; */
  646. u8 *pbuf;
  647. size_t buf_size = MAX_BSSINFO_LEN;
  648. size_t len, bssinf_len = 0;
  649. struct rtw_ieee80211_hdr *pwlanhdr;
  650. unsigned short *fctrl;
  651. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  652. struct wireless_dev *wdev = padapter->rtw_wdev;
  653. struct wiphy *wiphy = wdev->wiphy;
  654. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  655. pbuf = rtw_zmalloc(buf_size);
  656. if (pbuf == NULL) {
  657. RTW_INFO("%s pbuf allocate failed !!\n", __FUNCTION__);
  658. return bss;
  659. }
  660. /* RTW_INFO("%s\n", __func__); */
  661. bssinf_len = pnetwork->network.IELength + sizeof(struct rtw_ieee80211_hdr_3addr);
  662. if (bssinf_len > buf_size) {
  663. RTW_INFO("%s IE Length too long > %zu byte\n", __FUNCTION__, buf_size);
  664. goto exit;
  665. }
  666. #ifndef CONFIG_WAPI_SUPPORT
  667. {
  668. u16 wapi_len = 0;
  669. if (rtw_get_wapi_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &wapi_len) > 0) {
  670. if (wapi_len > 0) {
  671. RTW_INFO("%s, no support wapi!\n", __FUNCTION__);
  672. goto exit;
  673. }
  674. }
  675. }
  676. #endif /* !CONFIG_WAPI_SUPPORT */
  677. channel = pnetwork->network.Configuration.DSConfig;
  678. freq = rtw_ch2freq(channel);
  679. notify_channel = ieee80211_get_channel(wiphy, freq);
  680. if (0)
  681. notify_timestamp = le64_to_cpu(*(u64 *)rtw_get_timestampe_from_ie(pnetwork->network.IEs));
  682. else
  683. notify_timestamp = rtw_get_systime_us();
  684. notify_interval = le16_to_cpu(*(u16 *)rtw_get_beacon_interval_from_ie(pnetwork->network.IEs));
  685. notify_capability = le16_to_cpu(*(u16 *)rtw_get_capability_from_ie(pnetwork->network.IEs));
  686. notify_ie = pnetwork->network.IEs + _FIXED_IE_LENGTH_;
  687. notify_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_;
  688. /* We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM: signal strength in mBm (100*dBm) */
  689. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE &&
  690. is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)) {
  691. notify_signal = 100 * translate_percentage_to_dbm(padapter->recvpriv.signal_strength); /* dbm */
  692. } else {
  693. notify_signal = 100 * translate_percentage_to_dbm(pnetwork->network.PhyInfo.SignalStrength); /* dbm */
  694. }
  695. #if 0
  696. RTW_INFO("bssid: "MAC_FMT"\n", MAC_ARG(pnetwork->network.MacAddress));
  697. RTW_INFO("Channel: %d(%d)\n", channel, freq);
  698. RTW_INFO("Capability: %X\n", notify_capability);
  699. RTW_INFO("Beacon interval: %d\n", notify_interval);
  700. RTW_INFO("Signal: %d\n", notify_signal);
  701. RTW_INFO("notify_timestamp: %llu\n", notify_timestamp);
  702. #endif
  703. /* pbuf = buf; */
  704. pwlanhdr = (struct rtw_ieee80211_hdr *)pbuf;
  705. fctrl = &(pwlanhdr->frame_ctl);
  706. *(fctrl) = 0;
  707. SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
  708. /* pmlmeext->mgnt_seq++; */
  709. if (pnetwork->network.Reserved[0] == BSS_TYPE_BCN) { /* WIFI_BEACON */
  710. _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
  711. set_frame_sub_type(pbuf, WIFI_BEACON);
  712. } else {
  713. _rtw_memcpy(pwlanhdr->addr1, adapter_mac_addr(padapter), ETH_ALEN);
  714. set_frame_sub_type(pbuf, WIFI_PROBERSP);
  715. }
  716. _rtw_memcpy(pwlanhdr->addr2, pnetwork->network.MacAddress, ETH_ALEN);
  717. _rtw_memcpy(pwlanhdr->addr3, pnetwork->network.MacAddress, ETH_ALEN);
  718. /* pbuf += sizeof(struct rtw_ieee80211_hdr_3addr); */
  719. len = sizeof(struct rtw_ieee80211_hdr_3addr);
  720. _rtw_memcpy((pbuf + len), pnetwork->network.IEs, pnetwork->network.IELength);
  721. *((u64 *)(pbuf + len)) = cpu_to_le64(notify_timestamp);
  722. len += pnetwork->network.IELength;
  723. #if defined(CONFIG_P2P) && 0
  724. if(rtw_get_p2p_ie(pnetwork->network.IEs+12, pnetwork->network.IELength-12, NULL, NULL))
  725. RTW_INFO("%s, got p2p_ie\n", __func__);
  726. #endif
  727. #if 1
  728. bss = cfg80211_inform_bss_frame(wiphy, notify_channel, (struct ieee80211_mgmt *)pbuf,
  729. len, notify_signal, GFP_ATOMIC);
  730. #else
  731. bss = cfg80211_inform_bss(wiphy, notify_channel, (const u8 *)pnetwork->network.MacAddress,
  732. notify_timestamp, notify_capability, notify_interval, notify_ie,
  733. notify_ielen, notify_signal, GFP_ATOMIC/*GFP_KERNEL*/);
  734. #endif
  735. if (unlikely(!bss)) {
  736. RTW_INFO(FUNC_ADPT_FMT" bss NULL\n", FUNC_ADPT_ARG(padapter));
  737. goto exit;
  738. }
  739. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38))
  740. #ifndef COMPAT_KERNEL_RELEASE
  741. /* patch for cfg80211, update beacon ies to information_elements */
  742. if (pnetwork->network.Reserved[0] == BSS_TYPE_BCN) { /* WIFI_BEACON */
  743. if (bss->len_information_elements != bss->len_beacon_ies) {
  744. bss->information_elements = bss->beacon_ies;
  745. bss->len_information_elements = bss->len_beacon_ies;
  746. }
  747. }
  748. #endif /* COMPAT_KERNEL_RELEASE */
  749. #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) */
  750. #if 0
  751. {
  752. if (bss->information_elements == bss->proberesp_ies) {
  753. if (bss->len_information_elements != bss->len_proberesp_ies)
  754. RTW_INFO("error!, len_information_elements != bss->len_proberesp_ies\n");
  755. } else if (bss->len_information_elements < bss->len_beacon_ies) {
  756. bss->information_elements = bss->beacon_ies;
  757. bss->len_information_elements = bss->len_beacon_ies;
  758. }
  759. }
  760. #endif
  761. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
  762. cfg80211_put_bss(wiphy, bss);
  763. #else
  764. cfg80211_put_bss(bss);
  765. #endif
  766. exit:
  767. if (pbuf)
  768. rtw_mfree(pbuf, buf_size);
  769. return bss;
  770. }
  771. /*
  772. Check the given bss is valid by kernel API cfg80211_get_bss()
  773. @padapter : the given adapter
  774. return _TRUE if bss is valid, _FALSE for not found.
  775. */
  776. int rtw_cfg80211_check_bss(_adapter *padapter)
  777. {
  778. WLAN_BSSID_EX *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network);
  779. struct cfg80211_bss *bss = NULL;
  780. struct ieee80211_channel *notify_channel = NULL;
  781. u32 freq;
  782. if (!(pnetwork) || !(padapter->rtw_wdev))
  783. return _FALSE;
  784. freq = rtw_ch2freq(pnetwork->Configuration.DSConfig);
  785. notify_channel = ieee80211_get_channel(padapter->rtw_wdev->wiphy, freq);
  786. bss = cfg80211_get_bss(padapter->rtw_wdev->wiphy, notify_channel,
  787. pnetwork->MacAddress, pnetwork->Ssid.Ssid,
  788. pnetwork->Ssid.SsidLength,
  789. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
  790. pnetwork->InfrastructureMode == Ndis802_11Infrastructure?IEEE80211_BSS_TYPE_ESS:IEEE80211_BSS_TYPE_IBSS,
  791. IEEE80211_PRIVACY(pnetwork->Privacy));
  792. #else
  793. pnetwork->InfrastructureMode == Ndis802_11Infrastructure?WLAN_CAPABILITY_ESS:WLAN_CAPABILITY_IBSS, pnetwork->InfrastructureMode == Ndis802_11Infrastructure?WLAN_CAPABILITY_ESS:WLAN_CAPABILITY_IBSS);
  794. #endif
  795. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
  796. cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss);
  797. #else
  798. cfg80211_put_bss(bss);
  799. #endif
  800. return bss != NULL;
  801. }
  802. void rtw_cfg80211_ibss_indicate_connect(_adapter *padapter)
  803. {
  804. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  805. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  806. struct wireless_dev *pwdev = padapter->rtw_wdev;
  807. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0))
  808. struct wiphy *wiphy = pwdev->wiphy;
  809. int freq = 2412;
  810. struct ieee80211_channel *notify_channel;
  811. #endif
  812. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  813. if (pwdev->iftype != NL80211_IFTYPE_ADHOC)
  814. return;
  815. if (!rtw_cfg80211_check_bss(padapter)) {
  816. WLAN_BSSID_EX *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network);
  817. struct wlan_network *scanned = pmlmepriv->cur_network_scanned;
  818. if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
  819. _rtw_memcpy(&cur_network->network, pnetwork, sizeof(WLAN_BSSID_EX));
  820. if (cur_network) {
  821. if (!rtw_cfg80211_inform_bss(padapter, cur_network))
  822. RTW_INFO(FUNC_ADPT_FMT" inform fail !!\n", FUNC_ADPT_ARG(padapter));
  823. else
  824. RTW_INFO(FUNC_ADPT_FMT" inform success !!\n", FUNC_ADPT_ARG(padapter));
  825. } else {
  826. RTW_INFO("cur_network is not exist!!!\n");
  827. return ;
  828. }
  829. } else {
  830. if (scanned == NULL)
  831. rtw_warn_on(1);
  832. if (_rtw_memcmp(&(scanned->network.Ssid), &(pnetwork->Ssid), sizeof(NDIS_802_11_SSID)) == _TRUE
  833. && _rtw_memcmp(scanned->network.MacAddress, pnetwork->MacAddress, sizeof(NDIS_802_11_MAC_ADDRESS)) == _TRUE
  834. ) {
  835. if (!rtw_cfg80211_inform_bss(padapter, scanned))
  836. RTW_INFO(FUNC_ADPT_FMT" inform fail !!\n", FUNC_ADPT_ARG(padapter));
  837. else {
  838. /* RTW_INFO(FUNC_ADPT_FMT" inform success !!\n", FUNC_ADPT_ARG(padapter)); */
  839. }
  840. } else {
  841. RTW_INFO("scanned & pnetwork compare fail\n");
  842. rtw_warn_on(1);
  843. }
  844. }
  845. if (!rtw_cfg80211_check_bss(padapter))
  846. RTW_PRINT(FUNC_ADPT_FMT" BSS not found !!\n", FUNC_ADPT_ARG(padapter));
  847. }
  848. /* notify cfg80211 that device joined an IBSS */
  849. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0))
  850. freq = rtw_ch2freq(cur_network->network.Configuration.DSConfig);
  851. if (1)
  852. RTW_INFO("chan: %d, freq: %d\n", cur_network->network.Configuration.DSConfig, freq);
  853. notify_channel = ieee80211_get_channel(wiphy, freq);
  854. cfg80211_ibss_joined(padapter->pnetdev, cur_network->network.MacAddress, notify_channel, GFP_ATOMIC);
  855. #else
  856. cfg80211_ibss_joined(padapter->pnetdev, cur_network->network.MacAddress, GFP_ATOMIC);
  857. #endif
  858. }
  859. void rtw_cfg80211_indicate_connect(_adapter *padapter)
  860. {
  861. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  862. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  863. struct wireless_dev *pwdev = padapter->rtw_wdev;
  864. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  865. _irqL irqL;
  866. #ifdef CONFIG_P2P
  867. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  868. #endif
  869. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
  870. struct cfg80211_roam_info roam_info ={};
  871. #endif
  872. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  873. if (pwdev->iftype != NL80211_IFTYPE_STATION
  874. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  875. && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT
  876. #endif
  877. )
  878. return;
  879. if (!MLME_IS_STA(padapter))
  880. return;
  881. #ifdef CONFIG_P2P
  882. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  883. #if !RTW_P2P_GROUP_INTERFACE
  884. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  885. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  886. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  887. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  888. RTW_INFO("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
  889. }
  890. #endif
  891. }
  892. #endif /* CONFIG_P2P */
  893. if (check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) != _TRUE) {
  894. WLAN_BSSID_EX *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network);
  895. struct wlan_network *scanned = pmlmepriv->cur_network_scanned;
  896. /* RTW_INFO(FUNC_ADPT_FMT" BSS not found\n", FUNC_ADPT_ARG(padapter)); */
  897. if (scanned == NULL) {
  898. rtw_warn_on(1);
  899. goto check_bss;
  900. }
  901. if (_rtw_memcmp(scanned->network.MacAddress, pnetwork->MacAddress, sizeof(NDIS_802_11_MAC_ADDRESS)) == _TRUE
  902. && _rtw_memcmp(&(scanned->network.Ssid), &(pnetwork->Ssid), sizeof(NDIS_802_11_SSID)) == _TRUE
  903. ) {
  904. if (!rtw_cfg80211_inform_bss(padapter, scanned))
  905. RTW_INFO(FUNC_ADPT_FMT" inform fail !!\n", FUNC_ADPT_ARG(padapter));
  906. else {
  907. /* RTW_INFO(FUNC_ADPT_FMT" inform success !!\n", FUNC_ADPT_ARG(padapter)); */
  908. }
  909. } else {
  910. RTW_INFO("scanned: %s("MAC_FMT"), cur: %s("MAC_FMT")\n",
  911. scanned->network.Ssid.Ssid, MAC_ARG(scanned->network.MacAddress),
  912. pnetwork->Ssid.Ssid, MAC_ARG(pnetwork->MacAddress)
  913. );
  914. rtw_warn_on(1);
  915. }
  916. }
  917. check_bss:
  918. if (!rtw_cfg80211_check_bss(padapter))
  919. RTW_PRINT(FUNC_ADPT_FMT" BSS not found !!\n", FUNC_ADPT_ARG(padapter));
  920. _enter_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  921. if (rtw_to_roam(padapter) > 0) {
  922. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39) || defined(COMPAT_KERNEL_RELEASE)
  923. struct wiphy *wiphy = pwdev->wiphy;
  924. struct ieee80211_channel *notify_channel;
  925. u32 freq;
  926. u16 channel = cur_network->network.Configuration.DSConfig;
  927. freq = rtw_ch2freq(channel);
  928. notify_channel = ieee80211_get_channel(wiphy, freq);
  929. #endif
  930. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
  931. #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 0, 0)
  932. roam_info.channel = notify_channel;
  933. roam_info.bssid = cur_network->network.MacAddress;
  934. #else
  935. roam_info.links[0].channel = notify_channel;
  936. roam_info.links[0].bssid = cur_network->network.MacAddress;
  937. #endif
  938. roam_info.req_ie = pmlmepriv->assoc_req + sizeof(struct rtw_ieee80211_hdr_3addr) + 2;
  939. roam_info.req_ie_len = pmlmepriv->assoc_req_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 2;
  940. roam_info.resp_ie = pmlmepriv->assoc_rsp + sizeof(struct rtw_ieee80211_hdr_3addr) + 6;
  941. roam_info.resp_ie_len = pmlmepriv->assoc_rsp_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 6;
  942. cfg80211_roamed(padapter->pnetdev, &roam_info, GFP_ATOMIC);
  943. #else
  944. cfg80211_roamed(padapter->pnetdev
  945. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39) || defined(COMPAT_KERNEL_RELEASE)
  946. , notify_channel
  947. #endif
  948. , cur_network->network.MacAddress
  949. , pmlmepriv->assoc_req + sizeof(struct rtw_ieee80211_hdr_3addr) + 2
  950. , pmlmepriv->assoc_req_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 2
  951. , pmlmepriv->assoc_rsp + sizeof(struct rtw_ieee80211_hdr_3addr) + 6
  952. , pmlmepriv->assoc_rsp_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 6
  953. , GFP_ATOMIC);
  954. #endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)*/
  955. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_roamed\n", FUNC_ADPT_ARG(padapter));
  956. #ifdef CONFIG_RTW_80211R
  957. if (rtw_ft_roam(padapter))
  958. rtw_ft_set_status(padapter, RTW_FT_ASSOCIATED_STA);
  959. #endif
  960. } else {
  961. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) || defined(COMPAT_KERNEL_RELEASE)
  962. RTW_INFO("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
  963. #endif
  964. if (check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) != _TRUE)
  965. rtw_cfg80211_connect_result(pwdev, cur_network->network.MacAddress
  966. , pmlmepriv->assoc_req + sizeof(struct rtw_ieee80211_hdr_3addr) + 2
  967. , pmlmepriv->assoc_req_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 2
  968. , pmlmepriv->assoc_rsp + sizeof(struct rtw_ieee80211_hdr_3addr) + 6
  969. , pmlmepriv->assoc_rsp_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 6
  970. , WLAN_STATUS_SUCCESS, GFP_ATOMIC);
  971. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) || defined(COMPAT_KERNEL_RELEASE)
  972. RTW_INFO("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
  973. #endif
  974. }
  975. rtw_wdev_free_connect_req(pwdev_priv);
  976. _exit_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  977. }
  978. void rtw_cfg80211_indicate_disconnect(_adapter *padapter, u16 reason, u8 locally_generated)
  979. {
  980. struct wireless_dev *pwdev = padapter->rtw_wdev;
  981. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  982. _irqL irqL;
  983. #ifdef CONFIG_P2P
  984. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  985. #endif
  986. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  987. /*always replace privated definitions with wifi reserved value 0*/
  988. if (WLAN_REASON_IS_PRIVATE(reason))
  989. reason = 0;
  990. if (pwdev->iftype != NL80211_IFTYPE_STATION
  991. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  992. && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT
  993. #endif
  994. )
  995. return;
  996. if (!MLME_IS_STA(padapter))
  997. return;
  998. #ifdef CONFIG_P2P
  999. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  1000. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  1001. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  1002. #if RTW_P2P_GROUP_INTERFACE
  1003. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1004. if (pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
  1005. #endif
  1006. #endif
  1007. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  1008. RTW_INFO("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
  1009. }
  1010. }
  1011. #endif /* CONFIG_P2P */
  1012. _enter_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  1013. if (padapter->ndev_unregistering || !rtw_wdev_not_indic_disco(pwdev_priv)) {
  1014. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) || defined(COMPAT_KERNEL_RELEASE)
  1015. RTW_INFO("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
  1016. if (pwdev->sme_state == CFG80211_SME_CONNECTING) {
  1017. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_connect_result\n", FUNC_ADPT_ARG(padapter));
  1018. rtw_cfg80211_connect_result(pwdev, NULL, NULL, 0, NULL, 0,
  1019. reason, GFP_ATOMIC);
  1020. } else if (pwdev->sme_state == CFG80211_SME_CONNECTED) {
  1021. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_disconnected\n", FUNC_ADPT_ARG(padapter));
  1022. rtw_cfg80211_disconnected(pwdev, reason, NULL, 0, locally_generated, GFP_ATOMIC);
  1023. }
  1024. RTW_INFO("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
  1025. #else
  1026. if (pwdev_priv->connect_req) {
  1027. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_connect_result\n", FUNC_ADPT_ARG(padapter));
  1028. rtw_cfg80211_connect_result(pwdev, NULL, NULL, 0, NULL, 0,
  1029. reason, GFP_ATOMIC);
  1030. } else {
  1031. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_disconnected\n", FUNC_ADPT_ARG(padapter));
  1032. rtw_cfg80211_disconnected(pwdev, reason, NULL, 0, locally_generated, GFP_ATOMIC);
  1033. }
  1034. #endif
  1035. }
  1036. rtw_wdev_free_connect_req(pwdev_priv);
  1037. _exit_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  1038. }
  1039. #ifdef CONFIG_AP_MODE
  1040. static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_param *param)
  1041. {
  1042. int ret = 0;
  1043. u32 wep_key_idx, wep_key_len;
  1044. struct sta_info *psta = NULL, *pbcmc_sta = NULL;
  1045. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1046. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1047. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  1048. struct sta_priv *pstapriv = &padapter->stapriv;
  1049. RTW_INFO("%s\n", __FUNCTION__);
  1050. param->u.crypt.err = 0;
  1051. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  1052. if (is_broadcast_mac_addr(param->sta_addr)) {
  1053. if (param->u.crypt.idx >= WEP_KEYS
  1054. #ifdef CONFIG_IEEE80211W
  1055. && param->u.crypt.idx > BIP_MAX_KEYID
  1056. #endif
  1057. ) {
  1058. ret = -EINVAL;
  1059. goto exit;
  1060. }
  1061. } else {
  1062. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  1063. if (!psta) {
  1064. ret = -EINVAL;
  1065. RTW_INFO(FUNC_ADPT_FMT", sta "MAC_FMT" not found\n"
  1066. , FUNC_ADPT_ARG(padapter), MAC_ARG(param->sta_addr));
  1067. goto exit;
  1068. }
  1069. }
  1070. if (strcmp(param->u.crypt.alg, "none") == 0 && (psta == NULL)) {
  1071. /* todo:clear default encryption keys */
  1072. RTW_INFO("clear default encryption keys, keyid=%d\n", param->u.crypt.idx);
  1073. goto exit;
  1074. }
  1075. if (strcmp(param->u.crypt.alg, "WEP") == 0 && (psta == NULL)) {
  1076. RTW_INFO("r871x_set_encryption, crypt.alg = WEP\n");
  1077. wep_key_idx = param->u.crypt.idx;
  1078. wep_key_len = param->u.crypt.key_len;
  1079. RTW_INFO("r871x_set_encryption, wep_key_idx=%d, len=%d\n", wep_key_idx, wep_key_len);
  1080. if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
  1081. ret = -EINVAL;
  1082. goto exit;
  1083. }
  1084. if (wep_key_len > 0)
  1085. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  1086. if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
  1087. /* wep default key has not been set, so use this key index as default key. */
  1088. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  1089. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1090. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  1091. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  1092. if (wep_key_len == 13) {
  1093. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  1094. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  1095. }
  1096. psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
  1097. }
  1098. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
  1099. psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
  1100. rtw_ap_set_wep_key(padapter, param->u.crypt.key, wep_key_len, wep_key_idx, 1);
  1101. goto exit;
  1102. }
  1103. if (!psta) { /* group key */
  1104. if (param->u.crypt.set_tx == 0) { /* group key, TX only */
  1105. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  1106. RTW_INFO(FUNC_ADPT_FMT" set WEP TX GTK idx:%u, len:%u\n"
  1107. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1108. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1109. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  1110. if (param->u.crypt.key_len == 13)
  1111. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  1112. } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
  1113. RTW_INFO(FUNC_ADPT_FMT" set TKIP TX GTK idx:%u, len:%u\n"
  1114. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1115. psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
  1116. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1117. /* set mic key */
  1118. _rtw_memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  1119. _rtw_memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  1120. psecuritypriv->busetkipkey = _TRUE;
  1121. } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  1122. RTW_INFO(FUNC_ADPT_FMT" set CCMP TX GTK idx:%u, len:%u\n"
  1123. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1124. psecuritypriv->dot118021XGrpPrivacy = _AES_;
  1125. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1126. #ifdef CONFIG_IEEE80211W
  1127. } else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
  1128. RTW_INFO(FUNC_ADPT_FMT" set TX IGTK idx:%u, len:%u\n"
  1129. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1130. _rtw_memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1131. padapter->securitypriv.dot11wBIPKeyid = param->u.crypt.idx;
  1132. psecuritypriv->dot11wBIPtxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1133. padapter->securitypriv.binstallBIPkey = _TRUE;
  1134. goto exit;
  1135. #endif /* CONFIG_IEEE80211W */
  1136. } else if (strcmp(param->u.crypt.alg, "none") == 0) {
  1137. RTW_INFO(FUNC_ADPT_FMT" clear group key, idx:%u\n"
  1138. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx);
  1139. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  1140. } else {
  1141. RTW_WARN(FUNC_ADPT_FMT" set group key, not support\n"
  1142. , FUNC_ADPT_ARG(padapter));
  1143. goto exit;
  1144. }
  1145. psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
  1146. pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
  1147. if (pbcmc_sta) {
  1148. pbcmc_sta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1149. pbcmc_sta->ieee8021x_blocked = _FALSE;
  1150. pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy; /* rx will use bmc_sta's dot118021XPrivacy */
  1151. }
  1152. psecuritypriv->binstallGrpkey = _TRUE;
  1153. psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* !!! */
  1154. rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
  1155. }
  1156. goto exit;
  1157. }
  1158. if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /* psk/802_1x */
  1159. if (param->u.crypt.set_tx == 1) {
  1160. /* pairwise key */
  1161. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1162. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  1163. RTW_INFO(FUNC_ADPT_FMT" set WEP PTK of "MAC_FMT" idx:%u, len:%u\n"
  1164. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1165. , param->u.crypt.idx, param->u.crypt.key_len);
  1166. psta->dot118021XPrivacy = _WEP40_;
  1167. if (param->u.crypt.key_len == 13)
  1168. psta->dot118021XPrivacy = _WEP104_;
  1169. } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
  1170. RTW_INFO(FUNC_ADPT_FMT" set TKIP PTK of "MAC_FMT" idx:%u, len:%u\n"
  1171. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1172. , param->u.crypt.idx, param->u.crypt.key_len);
  1173. psta->dot118021XPrivacy = _TKIP_;
  1174. /* set mic key */
  1175. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  1176. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  1177. psecuritypriv->busetkipkey = _TRUE;
  1178. } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  1179. RTW_INFO(FUNC_ADPT_FMT" set CCMP PTK of "MAC_FMT" idx:%u, len:%u\n"
  1180. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1181. , param->u.crypt.idx, param->u.crypt.key_len);
  1182. psta->dot118021XPrivacy = _AES_;
  1183. } else if (strcmp(param->u.crypt.alg, "none") == 0) {
  1184. RTW_INFO(FUNC_ADPT_FMT" clear pairwise key of "MAC_FMT" idx:%u\n"
  1185. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1186. , param->u.crypt.idx);
  1187. psta->dot118021XPrivacy = _NO_PRIVACY_;
  1188. } else {
  1189. RTW_WARN(FUNC_ADPT_FMT" set pairwise key of "MAC_FMT", not support\n"
  1190. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
  1191. goto exit;
  1192. }
  1193. psta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1194. psta->dot11rxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1195. psta->ieee8021x_blocked = _FALSE;
  1196. if (psta->dot118021XPrivacy != _NO_PRIVACY_) {
  1197. psta->bpairwise_key_installed = _TRUE;
  1198. /* WPA2 key-handshake has completed */
  1199. if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPA2PSK)
  1200. psta->state &= (~WIFI_UNDER_KEY_HANDSHAKE);
  1201. }
  1202. rtw_ap_set_pairwise_key(padapter, psta);
  1203. } else {
  1204. /* peer's group key, RX only */
  1205. #ifdef CONFIG_RTW_MESH
  1206. if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  1207. RTW_INFO(FUNC_ADPT_FMT" set CCMP GTK of "MAC_FMT", idx:%u, len:%u\n"
  1208. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1209. , param->u.crypt.idx, param->u.crypt.key_len);
  1210. psta->group_privacy = _AES_;
  1211. _rtw_memcpy(psta->gtk.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1212. psta->gtk_bmp |= BIT(param->u.crypt.idx);
  1213. psta->gtk_pn.val = RTW_GET_LE64(param->u.crypt.seq);
  1214. #ifdef CONFIG_IEEE80211W
  1215. } else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
  1216. RTW_INFO(FUNC_ADPT_FMT" set IGTK of "MAC_FMT", idx:%u, len:%u\n"
  1217. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1218. , param->u.crypt.idx, param->u.crypt.key_len);
  1219. _rtw_memcpy(psta->igtk.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1220. psta->igtk_bmp |= BIT(param->u.crypt.idx);
  1221. psta->igtk_id = param->u.crypt.idx;
  1222. psta->igtk_pn.val = RTW_GET_LE64(param->u.crypt.seq);
  1223. goto exit;
  1224. #endif /* CONFIG_IEEE80211W */
  1225. } else if (strcmp(param->u.crypt.alg, "none") == 0) {
  1226. RTW_INFO(FUNC_ADPT_FMT" clear group key of "MAC_FMT", idx:%u\n"
  1227. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1228. , param->u.crypt.idx);
  1229. psta->group_privacy = _NO_PRIVACY_;
  1230. psta->gtk_bmp &= ~BIT(param->u.crypt.idx);
  1231. } else
  1232. #endif /* CONFIG_RTW_MESH */
  1233. {
  1234. RTW_WARN(FUNC_ADPT_FMT" set group key of "MAC_FMT", not support\n"
  1235. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
  1236. goto exit;
  1237. }
  1238. #ifdef CONFIG_RTW_MESH
  1239. rtw_ap_set_sta_key(padapter, psta->cmn.mac_addr, psta->group_privacy
  1240. , param->u.crypt.key, param->u.crypt.idx, 1);
  1241. #endif
  1242. }
  1243. }
  1244. exit:
  1245. return ret;
  1246. }
  1247. #endif /* CONFIG_AP_MODE */
  1248. static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param *param)
  1249. {
  1250. int ret = 0;
  1251. u32 wep_key_idx, wep_key_len;
  1252. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1253. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1254. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1255. #ifdef CONFIG_P2P
  1256. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  1257. #endif /* CONFIG_P2P */
  1258. RTW_INFO("%s\n", __func__);
  1259. param->u.crypt.err = 0;
  1260. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  1261. if (is_broadcast_mac_addr(param->sta_addr)) {
  1262. if (param->u.crypt.idx >= WEP_KEYS
  1263. #ifdef CONFIG_IEEE80211W
  1264. && param->u.crypt.idx > BIP_MAX_KEYID
  1265. #endif
  1266. ) {
  1267. ret = -EINVAL;
  1268. goto exit;
  1269. }
  1270. } else {
  1271. #ifdef CONFIG_WAPI_SUPPORT
  1272. if (strcmp(param->u.crypt.alg, "SMS4"))
  1273. #endif
  1274. {
  1275. ret = -EINVAL;
  1276. goto exit;
  1277. }
  1278. }
  1279. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  1280. RTW_INFO("wpa_set_encryption, crypt.alg = WEP\n");
  1281. wep_key_idx = param->u.crypt.idx;
  1282. wep_key_len = param->u.crypt.key_len;
  1283. if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
  1284. ret = -EINVAL;
  1285. goto exit;
  1286. }
  1287. if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
  1288. /* wep default key has not been set, so use this key index as default key. */
  1289. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  1290. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1291. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  1292. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  1293. if (wep_key_len == 13) {
  1294. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  1295. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  1296. }
  1297. psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
  1298. }
  1299. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
  1300. psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
  1301. rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0, _TRUE);
  1302. goto exit;
  1303. }
  1304. if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */
  1305. struct sta_info *psta, *pbcmc_sta;
  1306. struct sta_priv *pstapriv = &padapter->stapriv;
  1307. /* RTW_INFO("%s, : dot11AuthAlgrthm == dot11AuthAlgrthm_8021X\n", __func__); */
  1308. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == _TRUE) { /* sta mode */
  1309. #ifdef CONFIG_RTW_80211R
  1310. if (rtw_ft_roam(padapter))
  1311. psta = rtw_get_stainfo(pstapriv, pmlmepriv->assoc_bssid);
  1312. else
  1313. #endif
  1314. psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
  1315. if (psta == NULL) {
  1316. /* DEBUG_ERR( ("Set wpa_set_encryption: Obtain Sta_info fail\n")); */
  1317. RTW_INFO("%s, : Obtain Sta_info fail\n", __func__);
  1318. } else {
  1319. /* Jeff: don't disable ieee8021x_blocked while clearing key */
  1320. if (strcmp(param->u.crypt.alg, "none") != 0)
  1321. psta->ieee8021x_blocked = _FALSE;
  1322. if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
  1323. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  1324. psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  1325. if (param->u.crypt.set_tx == 1) { /* pairwise key */
  1326. RTW_INFO(FUNC_ADPT_FMT" set %s PTK idx:%u, len:%u\n"
  1327. , FUNC_ADPT_ARG(padapter), param->u.crypt.alg, param->u.crypt.idx, param->u.crypt.key_len);
  1328. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1329. if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
  1330. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  1331. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  1332. padapter->securitypriv.busetkipkey = _FALSE;
  1333. }
  1334. psta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1335. psta->dot11rxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1336. psta->bpairwise_key_installed = _TRUE;
  1337. #ifdef CONFIG_RTW_80211R
  1338. psta->ft_pairwise_key_installed = _TRUE;
  1339. #endif
  1340. rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, _TRUE);
  1341. } else { /* group key */
  1342. if (strcmp(param->u.crypt.alg, "TKIP") == 0 || strcmp(param->u.crypt.alg, "CCMP") == 0) {
  1343. RTW_INFO(FUNC_ADPT_FMT" set %s GTK idx:%u, len:%u\n"
  1344. , FUNC_ADPT_ARG(padapter), param->u.crypt.alg, param->u.crypt.idx, param->u.crypt.key_len);
  1345. _rtw_memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key,
  1346. (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1347. _rtw_memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  1348. _rtw_memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  1349. padapter->securitypriv.binstallGrpkey = _TRUE;
  1350. if (param->u.crypt.idx < 4)
  1351. _rtw_memcpy(padapter->securitypriv.iv_seq[param->u.crypt.idx], param->u.crypt.seq, 8);
  1352. padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
  1353. rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1, _TRUE);
  1354. #ifdef CONFIG_IEEE80211W
  1355. } else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
  1356. RTW_INFO(FUNC_ADPT_FMT" set IGTK idx:%u, len:%u\n"
  1357. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1358. _rtw_memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key,
  1359. (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1360. psecuritypriv->dot11wBIPKeyid = param->u.crypt.idx;
  1361. psecuritypriv->dot11wBIPrxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1362. psecuritypriv->binstallBIPkey = _TRUE;
  1363. #endif /* CONFIG_IEEE80211W */
  1364. }
  1365. #ifdef CONFIG_P2P
  1366. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  1367. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
  1368. rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_DONE);
  1369. }
  1370. #endif /* CONFIG_P2P */
  1371. /* WPA/WPA2 key-handshake has completed */
  1372. clr_fwstate(pmlmepriv, WIFI_UNDER_KEY_HANDSHAKE);
  1373. }
  1374. }
  1375. pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
  1376. if (pbcmc_sta == NULL) {
  1377. /* DEBUG_ERR( ("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n")); */
  1378. } else {
  1379. /* Jeff: don't disable ieee8021x_blocked while clearing key */
  1380. if (strcmp(param->u.crypt.alg, "none") != 0)
  1381. pbcmc_sta->ieee8021x_blocked = _FALSE;
  1382. if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
  1383. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  1384. pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  1385. }
  1386. } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { /* adhoc mode */
  1387. }
  1388. }
  1389. #ifdef CONFIG_WAPI_SUPPORT
  1390. if (strcmp(param->u.crypt.alg, "SMS4") == 0)
  1391. rtw_wapi_set_set_encryption(padapter, param);
  1392. #endif
  1393. exit:
  1394. RTW_INFO("%s, ret=%d\n", __func__, ret);
  1395. return ret;
  1396. }
  1397. static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev
  1398. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
  1399. , int link_id
  1400. #endif
  1401. , u8 key_index
  1402. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1403. , bool pairwise
  1404. #endif
  1405. , const u8 *mac_addr, struct key_params *params)
  1406. {
  1407. char *alg_name;
  1408. u32 param_len;
  1409. struct ieee_param *param = NULL;
  1410. int ret = 0;
  1411. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1412. struct wireless_dev *rtw_wdev = padapter->rtw_wdev;
  1413. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1414. #ifdef CONFIG_TDLS
  1415. struct sta_info *ptdls_sta;
  1416. #endif /* CONFIG_TDLS */
  1417. if (mac_addr)
  1418. RTW_INFO(FUNC_NDEV_FMT" adding key for %pM\n", FUNC_NDEV_ARG(ndev), mac_addr);
  1419. RTW_INFO(FUNC_NDEV_FMT" cipher=0x%x\n", FUNC_NDEV_ARG(ndev), params->cipher);
  1420. RTW_INFO(FUNC_NDEV_FMT" key_len=%d, key_index=%d\n", FUNC_NDEV_ARG(ndev), params->key_len, key_index);
  1421. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1422. RTW_INFO(FUNC_NDEV_FMT" pairwise=%d\n", FUNC_NDEV_ARG(ndev), pairwise);
  1423. #endif
  1424. if (rtw_cfg80211_sync_iftype(padapter) != _SUCCESS) {
  1425. ret = -ENOTSUPP;
  1426. goto addkey_end;
  1427. }
  1428. param_len = sizeof(struct ieee_param) + params->key_len;
  1429. param = rtw_malloc(param_len);
  1430. if (param == NULL)
  1431. return -1;
  1432. _rtw_memset(param, 0, param_len);
  1433. param->cmd = IEEE_CMD_SET_ENCRYPTION;
  1434. _rtw_memset(param->sta_addr, 0xff, ETH_ALEN);
  1435. switch (params->cipher) {
  1436. case IW_AUTH_CIPHER_NONE:
  1437. /* todo: remove key */
  1438. /* remove = 1; */
  1439. alg_name = "none";
  1440. break;
  1441. case WLAN_CIPHER_SUITE_WEP40:
  1442. case WLAN_CIPHER_SUITE_WEP104:
  1443. alg_name = "WEP";
  1444. break;
  1445. case WLAN_CIPHER_SUITE_TKIP:
  1446. alg_name = "TKIP";
  1447. break;
  1448. case WLAN_CIPHER_SUITE_CCMP:
  1449. alg_name = "CCMP";
  1450. break;
  1451. #ifdef CONFIG_IEEE80211W
  1452. case WLAN_CIPHER_SUITE_AES_CMAC:
  1453. alg_name = "BIP";
  1454. break;
  1455. #endif /* CONFIG_IEEE80211W */
  1456. #ifdef CONFIG_WAPI_SUPPORT
  1457. case WLAN_CIPHER_SUITE_SMS4:
  1458. alg_name = "SMS4";
  1459. if (pairwise == NL80211_KEYTYPE_PAIRWISE) {
  1460. if (key_index != 0 && key_index != 1) {
  1461. ret = -ENOTSUPP;
  1462. goto addkey_end;
  1463. }
  1464. _rtw_memcpy((void *)param->sta_addr, (void *)mac_addr, ETH_ALEN);
  1465. } else
  1466. RTW_INFO("mac_addr is null\n");
  1467. RTW_INFO("rtw_wx_set_enc_ext: SMS4 case\n");
  1468. break;
  1469. #endif
  1470. default:
  1471. ret = -ENOTSUPP;
  1472. goto addkey_end;
  1473. }
  1474. strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
  1475. if (!mac_addr || is_broadcast_ether_addr(mac_addr)
  1476. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1477. || !pairwise
  1478. #endif
  1479. ) {
  1480. param->u.crypt.set_tx = 0; /* for wpa/wpa2 group key */
  1481. } else {
  1482. param->u.crypt.set_tx = 1; /* for wpa/wpa2 pairwise key */
  1483. }
  1484. param->u.crypt.idx = key_index;
  1485. if (params->seq_len && params->seq) {
  1486. _rtw_memcpy(param->u.crypt.seq, (u8 *)params->seq, params->seq_len);
  1487. RTW_INFO(FUNC_NDEV_FMT" seq_len:%u, seq:0x%llx\n", FUNC_NDEV_ARG(ndev)
  1488. , params->seq_len, RTW_GET_LE64(param->u.crypt.seq));
  1489. }
  1490. if (params->key_len && params->key) {
  1491. param->u.crypt.key_len = params->key_len;
  1492. _rtw_memcpy(param->u.crypt.key, (u8 *)params->key, params->key_len);
  1493. }
  1494. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE) {
  1495. #ifdef CONFIG_TDLS
  1496. if (rtw_tdls_is_driver_setup(padapter) == _FALSE && mac_addr) {
  1497. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, (void *)mac_addr);
  1498. if (ptdls_sta != NULL && ptdls_sta->tdls_sta_state) {
  1499. _rtw_memcpy(ptdls_sta->tpk.tk, params->key, params->key_len);
  1500. rtw_tdls_set_key(padapter, ptdls_sta);
  1501. goto addkey_end;
  1502. }
  1503. }
  1504. #endif /* CONFIG_TDLS */
  1505. ret = rtw_cfg80211_set_encryption(ndev, param);
  1506. } else if (MLME_IS_AP(padapter) || MLME_IS_MESH(padapter)) {
  1507. #ifdef CONFIG_AP_MODE
  1508. if (mac_addr)
  1509. _rtw_memcpy(param->sta_addr, (void *)mac_addr, ETH_ALEN);
  1510. ret = rtw_cfg80211_ap_set_encryption(ndev, param);
  1511. #endif
  1512. } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE
  1513. || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE
  1514. ) {
  1515. /* RTW_INFO("@@@@@@@@@@ fw_state=0x%x, iftype=%d\n", pmlmepriv->fw_state, rtw_wdev->iftype); */
  1516. ret = rtw_cfg80211_set_encryption(ndev, param);
  1517. } else
  1518. RTW_INFO("error! fw_state=0x%x, iftype=%d\n", pmlmepriv->fw_state, rtw_wdev->iftype);
  1519. addkey_end:
  1520. if (param)
  1521. rtw_mfree(param, param_len);
  1522. return ret;
  1523. }
  1524. static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev
  1525. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
  1526. , int link_id
  1527. #endif
  1528. , u8 keyid
  1529. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1530. , bool pairwise
  1531. #endif
  1532. , const u8 *mac_addr, void *cookie
  1533. , void (*callback)(void *cookie, struct key_params *))
  1534. {
  1535. #define GET_KEY_PARAM_FMT_S " keyid=%d"
  1536. #define GET_KEY_PARAM_ARG_S , keyid
  1537. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1538. #define GET_KEY_PARAM_FMT_2_6_37 ", pairwise=%d"
  1539. #define GET_KEY_PARAM_ARG_2_6_37 , pairwise
  1540. #else
  1541. #define GET_KEY_PARAM_FMT_2_6_37 ""
  1542. #define GET_KEY_PARAM_ARG_2_6_37
  1543. #endif
  1544. #define GET_KEY_PARAM_FMT_E ", addr=%pM"
  1545. #define GET_KEY_PARAM_ARG_E , mac_addr
  1546. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  1547. struct security_priv *sec = &adapter->securitypriv;
  1548. struct sta_priv *stapriv = &adapter->stapriv;
  1549. struct sta_info *sta = NULL;
  1550. u32 cipher = _NO_PRIVACY_;
  1551. union Keytype *key = NULL;
  1552. u8 key_len = 0;
  1553. u64 *pn = NULL;
  1554. u8 pn_len = 0;
  1555. u8 pn_val[8] = {0};
  1556. struct key_params params;
  1557. int ret = -ENOENT;
  1558. if (keyid >= WEP_KEYS
  1559. #ifdef CONFIG_IEEE80211W
  1560. && keyid > BIP_MAX_KEYID
  1561. #endif
  1562. )
  1563. goto exit;
  1564. if (!mac_addr || is_broadcast_ether_addr(mac_addr)
  1565. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1566. || (MLME_IS_STA(adapter) && !pairwise)
  1567. #endif
  1568. ) {
  1569. /* WEP key, TX GTK/IGTK, RX GTK/IGTK(for STA mode) */
  1570. if (is_wep_enc(sec->dot118021XGrpPrivacy)) {
  1571. if (keyid >= WEP_KEYS)
  1572. goto exit;
  1573. if (!(sec->key_mask & BIT(keyid)))
  1574. goto exit;
  1575. cipher = sec->dot118021XGrpPrivacy;
  1576. key = &sec->dot11DefKey[keyid];
  1577. } else {
  1578. if (keyid < WEP_KEYS) {
  1579. if (sec->binstallGrpkey != _TRUE)
  1580. goto exit;
  1581. cipher = sec->dot118021XGrpPrivacy;
  1582. key = &sec->dot118021XGrpKey[keyid];
  1583. sta = rtw_get_bcmc_stainfo(adapter);
  1584. if (sta)
  1585. pn = &sta->dot11txpn.val;
  1586. #ifdef CONFIG_IEEE80211W
  1587. } else if (keyid < BIP_MAX_KEYID) {
  1588. if (SEC_IS_BIP_KEY_INSTALLED(sec) != _TRUE)
  1589. goto exit;
  1590. cipher = _BIP_;
  1591. key = &sec->dot11wBIPKey[keyid];
  1592. pn = &sec->dot11wBIPtxpn.val;
  1593. #endif
  1594. }
  1595. }
  1596. } else {
  1597. /* Pairwise key, RX GTK/IGTK for specific peer */
  1598. sta = rtw_get_stainfo(stapriv, mac_addr);
  1599. if (!sta)
  1600. goto exit;
  1601. if (keyid < WEP_KEYS && pairwise) {
  1602. if (sta->bpairwise_key_installed != _TRUE)
  1603. goto exit;
  1604. cipher = sta->dot118021XPrivacy;
  1605. key = &sta->dot118021x_UncstKey;
  1606. #ifdef CONFIG_RTW_MESH
  1607. } else if (keyid < WEP_KEYS && !pairwise) {
  1608. if (!(sta->gtk_bmp & BIT(keyid)))
  1609. goto exit;
  1610. cipher = sta->group_privacy;
  1611. key = &sta->gtk;
  1612. #ifdef CONFIG_IEEE80211W
  1613. } else if (keyid < BIP_MAX_KEYID && !pairwise) {
  1614. if (!(sta->igtk_bmp & BIT(keyid)))
  1615. goto exit;
  1616. cipher = _BIP_;
  1617. key = &sta->igtk;
  1618. pn = &sta->igtk_pn.val;
  1619. #endif
  1620. #endif /* CONFIG_RTW_MESH */
  1621. }
  1622. }
  1623. if (!key)
  1624. goto exit;
  1625. if (cipher == _WEP40_) {
  1626. cipher = WLAN_CIPHER_SUITE_WEP40;
  1627. key_len = sec->dot11DefKeylen[keyid];
  1628. } else if (cipher == _WEP104_) {
  1629. cipher = WLAN_CIPHER_SUITE_WEP104;
  1630. key_len = sec->dot11DefKeylen[keyid];
  1631. } else if (cipher == _TKIP_) {
  1632. cipher = WLAN_CIPHER_SUITE_TKIP;
  1633. key_len = 16;
  1634. } else if (cipher == _AES_) {
  1635. cipher = WLAN_CIPHER_SUITE_CCMP;
  1636. key_len = 16;
  1637. #ifdef CONFIG_IEEE80211W
  1638. } else if (cipher == _BIP_) {
  1639. cipher = WLAN_CIPHER_SUITE_AES_CMAC;
  1640. key_len = 16;
  1641. #endif
  1642. } else {
  1643. RTW_WARN(FUNC_NDEV_FMT" unknown cipher:%u\n", FUNC_NDEV_ARG(ndev), cipher);
  1644. rtw_warn_on(1);
  1645. goto exit;
  1646. }
  1647. if (pn) {
  1648. *((u64 *)pn_val) = cpu_to_le64(*pn);
  1649. pn_len = 6;
  1650. }
  1651. ret = 0;
  1652. exit:
  1653. RTW_INFO(FUNC_NDEV_FMT
  1654. GET_KEY_PARAM_FMT_S
  1655. GET_KEY_PARAM_FMT_2_6_37
  1656. GET_KEY_PARAM_FMT_E
  1657. " ret %d\n", FUNC_NDEV_ARG(ndev)
  1658. GET_KEY_PARAM_ARG_S
  1659. GET_KEY_PARAM_ARG_2_6_37
  1660. GET_KEY_PARAM_ARG_E
  1661. , ret);
  1662. if (pn)
  1663. RTW_INFO(FUNC_NDEV_FMT " seq:0x%llx\n", FUNC_NDEV_ARG(ndev), *pn);
  1664. if (ret == 0) {
  1665. _rtw_memset(&params, 0, sizeof(params));
  1666. params.cipher = cipher;
  1667. params.key = key->skey;
  1668. params.key_len = key_len;
  1669. if (pn) {
  1670. params.seq = pn_val;
  1671. params.seq_len = pn_len;
  1672. }
  1673. callback(cookie, &params);
  1674. }
  1675. return ret;
  1676. }
  1677. static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev,
  1678. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
  1679. int link_id,
  1680. #endif
  1681. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1682. u8 key_index, bool pairwise, const u8 *mac_addr)
  1683. #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) */
  1684. u8 key_index, const u8 *mac_addr)
  1685. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) */
  1686. {
  1687. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1688. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1689. RTW_INFO(FUNC_NDEV_FMT" key_index=%d, addr=%pM\n", FUNC_NDEV_ARG(ndev), key_index, mac_addr);
  1690. if (key_index == psecuritypriv->dot11PrivacyKeyIndex) {
  1691. /* clear the flag of wep default key set. */
  1692. psecuritypriv->bWepDefaultKeyIdxSet = 0;
  1693. }
  1694. return 0;
  1695. }
  1696. static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
  1697. struct net_device *ndev
  1698. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
  1699. , int link_id
  1700. #endif
  1701. , u8 key_index
  1702. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  1703. , bool unicast, bool multicast
  1704. #endif
  1705. )
  1706. {
  1707. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1708. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1709. #define SET_DEF_KEY_PARAM_FMT " key_index=%d"
  1710. #define SET_DEF_KEY_PARAM_ARG , key_index
  1711. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  1712. #define SET_DEF_KEY_PARAM_FMT_2_6_38 ", unicast=%d, multicast=%d"
  1713. #define SET_DEF_KEY_PARAM_ARG_2_6_38 , unicast, multicast
  1714. #else
  1715. #define SET_DEF_KEY_PARAM_FMT_2_6_38 ""
  1716. #define SET_DEF_KEY_PARAM_ARG_2_6_38
  1717. #endif
  1718. RTW_INFO(FUNC_NDEV_FMT
  1719. SET_DEF_KEY_PARAM_FMT
  1720. SET_DEF_KEY_PARAM_FMT_2_6_38
  1721. "\n", FUNC_NDEV_ARG(ndev)
  1722. SET_DEF_KEY_PARAM_ARG
  1723. SET_DEF_KEY_PARAM_ARG_2_6_38
  1724. );
  1725. if ((key_index < WEP_KEYS) && ((psecuritypriv->dot11PrivacyAlgrthm == _WEP40_) || (psecuritypriv->dot11PrivacyAlgrthm == _WEP104_))) { /* set wep default key */
  1726. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1727. psecuritypriv->dot11PrivacyKeyIndex = key_index;
  1728. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  1729. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  1730. if (psecuritypriv->dot11DefKeylen[key_index] == 13) {
  1731. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  1732. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  1733. }
  1734. psecuritypriv->bWepDefaultKeyIdxSet = 1; /* set the flag to represent that wep default key has been set */
  1735. }
  1736. return 0;
  1737. }
  1738. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
  1739. int cfg80211_rtw_set_default_mgmt_key(struct wiphy *wiphy,
  1740. struct net_device *ndev
  1741. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
  1742. , int link_idm
  1743. #endif
  1744. , u8 key_index
  1745. )
  1746. {
  1747. #define SET_DEF_KEY_PARAM_FMT " key_index=%d"
  1748. #define SET_DEF_KEY_PARAM_ARG , key_index
  1749. RTW_INFO(FUNC_NDEV_FMT
  1750. SET_DEF_KEY_PARAM_FMT
  1751. "\n", FUNC_NDEV_ARG(ndev)
  1752. SET_DEF_KEY_PARAM_ARG
  1753. );
  1754. return 0;
  1755. }
  1756. #endif
  1757. #if defined(CONFIG_GTK_OL) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
  1758. static int cfg80211_rtw_set_rekey_data(struct wiphy *wiphy,
  1759. struct net_device *ndev,
  1760. struct cfg80211_gtk_rekey_data *data)
  1761. {
  1762. /*int i;*/
  1763. struct sta_info *psta;
  1764. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1765. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1766. struct sta_priv *pstapriv = &padapter->stapriv;
  1767. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  1768. psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
  1769. if (psta == NULL) {
  1770. RTW_INFO("%s, : Obtain Sta_info fail\n", __func__);
  1771. return -1;
  1772. }
  1773. _rtw_memcpy(psta->kek, data->kek, NL80211_KEK_LEN);
  1774. /*printk("\ncfg80211_rtw_set_rekey_data KEK:");
  1775. for(i=0;i<NL80211_KEK_LEN; i++)
  1776. printk(" %02x ", psta->kek[i]);*/
  1777. _rtw_memcpy(psta->kck, data->kck, NL80211_KCK_LEN);
  1778. /*printk("\ncfg80211_rtw_set_rekey_data KCK:");
  1779. for(i=0;i<NL80211_KCK_LEN; i++)
  1780. printk(" %02x ", psta->kck[i]);*/
  1781. _rtw_memcpy(psta->replay_ctr, data->replay_ctr, NL80211_REPLAY_CTR_LEN);
  1782. psecuritypriv->binstallKCK_KEK = _TRUE;
  1783. /*printk("\nREPLAY_CTR: ");
  1784. for(i=0;i<RTW_REPLAY_CTR_LEN; i++)
  1785. printk(" %02x ", psta->replay_ctr[i]);*/
  1786. return 0;
  1787. }
  1788. #endif /*CONFIG_GTK_OL*/
  1789. #ifdef CONFIG_RTW_MESH
  1790. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  1791. static enum nl80211_mesh_power_mode rtw_mesh_ps_to_nl80211_mesh_power_mode(u8 ps)
  1792. {
  1793. if (ps == RTW_MESH_PS_UNKNOWN)
  1794. return NL80211_MESH_POWER_UNKNOWN;
  1795. if (ps == RTW_MESH_PS_ACTIVE)
  1796. return NL80211_MESH_POWER_ACTIVE;
  1797. if (ps == RTW_MESH_PS_LSLEEP)
  1798. return NL80211_MESH_POWER_LIGHT_SLEEP;
  1799. if (ps == RTW_MESH_PS_DSLEEP)
  1800. return NL80211_MESH_POWER_DEEP_SLEEP;
  1801. rtw_warn_on(1);
  1802. return NL80211_MESH_POWER_UNKNOWN;
  1803. }
  1804. #endif
  1805. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  1806. enum nl80211_plink_state rtw_plink_state_to_nl80211_plink_state(u8 plink_state)
  1807. {
  1808. if (plink_state == RTW_MESH_PLINK_UNKNOWN)
  1809. return NUM_NL80211_PLINK_STATES;
  1810. if (plink_state == RTW_MESH_PLINK_LISTEN)
  1811. return NL80211_PLINK_LISTEN;
  1812. if (plink_state == RTW_MESH_PLINK_OPN_SNT)
  1813. return NL80211_PLINK_OPN_SNT;
  1814. if (plink_state == RTW_MESH_PLINK_OPN_RCVD)
  1815. return NL80211_PLINK_OPN_RCVD;
  1816. if (plink_state == RTW_MESH_PLINK_CNF_RCVD)
  1817. return NL80211_PLINK_CNF_RCVD;
  1818. if (plink_state == RTW_MESH_PLINK_ESTAB)
  1819. return NL80211_PLINK_ESTAB;
  1820. if (plink_state == RTW_MESH_PLINK_HOLDING)
  1821. return NL80211_PLINK_HOLDING;
  1822. if (plink_state == RTW_MESH_PLINK_BLOCKED)
  1823. return NL80211_PLINK_BLOCKED;
  1824. rtw_warn_on(1);
  1825. return NUM_NL80211_PLINK_STATES;
  1826. }
  1827. u8 nl80211_plink_state_to_rtw_plink_state(enum nl80211_plink_state plink_state)
  1828. {
  1829. if (plink_state == NL80211_PLINK_LISTEN)
  1830. return RTW_MESH_PLINK_LISTEN;
  1831. if (plink_state == NL80211_PLINK_OPN_SNT)
  1832. return RTW_MESH_PLINK_OPN_SNT;
  1833. if (plink_state == NL80211_PLINK_OPN_RCVD)
  1834. return RTW_MESH_PLINK_OPN_RCVD;
  1835. if (plink_state == NL80211_PLINK_CNF_RCVD)
  1836. return RTW_MESH_PLINK_CNF_RCVD;
  1837. if (plink_state == NL80211_PLINK_ESTAB)
  1838. return RTW_MESH_PLINK_ESTAB;
  1839. if (plink_state == NL80211_PLINK_HOLDING)
  1840. return RTW_MESH_PLINK_HOLDING;
  1841. if (plink_state == NL80211_PLINK_BLOCKED)
  1842. return RTW_MESH_PLINK_BLOCKED;
  1843. rtw_warn_on(1);
  1844. return RTW_MESH_PLINK_UNKNOWN;
  1845. }
  1846. #endif
  1847. static void rtw_cfg80211_fill_mesh_only_sta_info(struct mesh_plink_ent *plink, struct sta_info *sta, struct station_info *sinfo)
  1848. {
  1849. sinfo->filled |= STATION_INFO_LLID;
  1850. sinfo->llid = plink->llid;
  1851. sinfo->filled |= STATION_INFO_PLID;
  1852. sinfo->plid = plink->plid;
  1853. sinfo->filled |= STATION_INFO_PLINK_STATE;
  1854. sinfo->plink_state = rtw_plink_state_to_nl80211_plink_state(plink->plink_state);
  1855. if (!sta && plink->scanned) {
  1856. sinfo->filled |= STATION_INFO_SIGNAL;
  1857. sinfo->signal = translate_percentage_to_dbm(plink->scanned->network.PhyInfo.SignalStrength);
  1858. sinfo->filled |= STATION_INFO_INACTIVE_TIME;
  1859. if (plink->plink_state == RTW_MESH_PLINK_UNKNOWN)
  1860. sinfo->inactive_time = 0 - 1;
  1861. else
  1862. sinfo->inactive_time = rtw_get_passing_time_ms(plink->scanned->last_scanned);
  1863. }
  1864. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  1865. if (sta) {
  1866. sinfo->filled |= STATION_INFO_LOCAL_PM;
  1867. sinfo->local_pm = rtw_mesh_ps_to_nl80211_mesh_power_mode(sta->local_mps);
  1868. sinfo->filled |= STATION_INFO_PEER_PM;
  1869. sinfo->peer_pm = rtw_mesh_ps_to_nl80211_mesh_power_mode(sta->peer_mps);
  1870. sinfo->filled |= STATION_INFO_NONPEER_PM;
  1871. sinfo->nonpeer_pm = rtw_mesh_ps_to_nl80211_mesh_power_mode(sta->nonpeer_mps);
  1872. }
  1873. #endif
  1874. }
  1875. #endif /* CONFIG_RTW_MESH */
  1876. static int cfg80211_rtw_get_station(struct wiphy *wiphy,
  1877. struct net_device *ndev,
  1878. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0))
  1879. u8 *mac,
  1880. #else
  1881. const u8 *mac,
  1882. #endif
  1883. struct station_info *sinfo)
  1884. {
  1885. int ret = 0;
  1886. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1887. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1888. struct sta_info *psta = NULL;
  1889. struct sta_priv *pstapriv = &padapter->stapriv;
  1890. #ifdef CONFIG_RTW_MESH
  1891. struct mesh_plink_ent *plink = NULL;
  1892. #endif
  1893. sinfo->filled = 0;
  1894. if (!mac) {
  1895. RTW_INFO(FUNC_NDEV_FMT" mac==%p\n", FUNC_NDEV_ARG(ndev), mac);
  1896. ret = -ENOENT;
  1897. goto exit;
  1898. }
  1899. psta = rtw_get_stainfo(pstapriv, mac);
  1900. #ifdef CONFIG_RTW_MESH
  1901. if (MLME_IS_MESH(padapter)) {
  1902. if (psta)
  1903. plink = psta->plink;
  1904. if (!plink)
  1905. plink = rtw_mesh_plink_get(padapter, mac);
  1906. }
  1907. #endif /* CONFIG_RTW_MESH */
  1908. if ((!MLME_IS_MESH(padapter) && !psta)
  1909. #ifdef CONFIG_RTW_MESH
  1910. || (MLME_IS_MESH(padapter) && !plink)
  1911. #endif
  1912. ) {
  1913. RTW_INFO(FUNC_NDEV_FMT" no sta info for mac="MAC_FMT"\n"
  1914. , FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
  1915. ret = -ENOENT;
  1916. goto exit;
  1917. }
  1918. #ifdef CONFIG_DEBUG_CFG80211
  1919. RTW_INFO(FUNC_NDEV_FMT" mac="MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
  1920. #endif
  1921. /* for infra./P2PClient mode */
  1922. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)
  1923. && check_fwstate(pmlmepriv, _FW_LINKED)
  1924. ) {
  1925. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  1926. if (_rtw_memcmp((u8 *)mac, cur_network->network.MacAddress, ETH_ALEN) == _FALSE) {
  1927. RTW_INFO("%s, mismatch bssid="MAC_FMT"\n", __func__, MAC_ARG(cur_network->network.MacAddress));
  1928. ret = -ENOENT;
  1929. goto exit;
  1930. }
  1931. sinfo->filled |= STATION_INFO_SIGNAL;
  1932. sinfo->signal = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);
  1933. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1934. sinfo->txrate.legacy = rtw_get_cur_max_rate(padapter);
  1935. }
  1936. if (psta) {
  1937. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE
  1938. || check_fwstate(pmlmepriv, _FW_LINKED) == _FALSE
  1939. ) {
  1940. sinfo->filled |= STATION_INFO_SIGNAL;
  1941. sinfo->signal = translate_percentage_to_dbm(psta->cmn.rssi_stat.rssi);
  1942. }
  1943. sinfo->filled |= STATION_INFO_INACTIVE_TIME;
  1944. sinfo->inactive_time = rtw_get_passing_time_ms(psta->sta_stats.last_rx_time);
  1945. sinfo->filled |= STATION_INFO_RX_PACKETS;
  1946. sinfo->rx_packets = sta_rx_data_pkts(psta);
  1947. sinfo->filled |= STATION_INFO_TX_PACKETS;
  1948. sinfo->tx_packets = psta->sta_stats.tx_pkts;
  1949. sinfo->filled |= STATION_INFO_TX_FAILED;
  1950. sinfo->tx_failed = psta->sta_stats.tx_fail_cnt;
  1951. }
  1952. #ifdef CONFIG_RTW_MESH
  1953. if (MLME_IS_MESH(padapter))
  1954. rtw_cfg80211_fill_mesh_only_sta_info(plink, psta, sinfo);
  1955. #endif
  1956. exit:
  1957. return ret;
  1958. }
  1959. extern int netdev_open(struct net_device *pnetdev);
  1960. #if 0
  1961. enum nl80211_iftype {
  1962. NL80211_IFTYPE_UNSPECIFIED,
  1963. NL80211_IFTYPE_ADHOC, /* 1 */
  1964. NL80211_IFTYPE_STATION, /* 2 */
  1965. NL80211_IFTYPE_AP, /* 3 */
  1966. NL80211_IFTYPE_AP_VLAN,
  1967. NL80211_IFTYPE_WDS,
  1968. NL80211_IFTYPE_MONITOR, /* 6 */
  1969. NL80211_IFTYPE_MESH_POINT,
  1970. NL80211_IFTYPE_P2P_CLIENT, /* 8 */
  1971. NL80211_IFTYPE_P2P_GO, /* 9 */
  1972. /* keep last */
  1973. NUM_NL80211_IFTYPES,
  1974. NL80211_IFTYPE_MAX = NUM_NL80211_IFTYPES - 1
  1975. };
  1976. #endif
  1977. static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
  1978. struct net_device *ndev,
  1979. enum nl80211_iftype type,
  1980. #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
  1981. u32 *flags,
  1982. #endif
  1983. struct vif_params *params)
  1984. {
  1985. enum nl80211_iftype old_type;
  1986. NDIS_802_11_NETWORK_INFRASTRUCTURE networkType;
  1987. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1988. struct wireless_dev *rtw_wdev = padapter->rtw_wdev;
  1989. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1990. #ifdef CONFIG_P2P
  1991. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  1992. u8 is_p2p = _FALSE;
  1993. #endif
  1994. int ret = 0;
  1995. u8 change = _FALSE;
  1996. RTW_INFO(FUNC_NDEV_FMT" type=%d, hw_port:%d\n", FUNC_NDEV_ARG(ndev), type, padapter->hw_port);
  1997. if (adapter_to_dvobj(padapter)->processing_dev_remove == _TRUE) {
  1998. ret = -EPERM;
  1999. goto exit;
  2000. }
  2001. RTW_INFO(FUNC_NDEV_FMT" call netdev_open\n", FUNC_NDEV_ARG(ndev));
  2002. if (netdev_open(ndev) != 0) {
  2003. RTW_INFO(FUNC_NDEV_FMT" call netdev_open fail\n", FUNC_NDEV_ARG(ndev));
  2004. ret = -EPERM;
  2005. goto exit;
  2006. }
  2007. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  2008. RTW_INFO(FUNC_NDEV_FMT" call rtw_pwr_wakeup fail\n", FUNC_NDEV_ARG(ndev));
  2009. ret = -EPERM;
  2010. goto exit;
  2011. }
  2012. old_type = rtw_wdev->iftype;
  2013. RTW_INFO(FUNC_NDEV_FMT" old_iftype=%d, new_iftype=%d\n",
  2014. FUNC_NDEV_ARG(ndev), old_type, type);
  2015. if (old_type != type) {
  2016. change = _TRUE;
  2017. pmlmeext->action_public_rxseq = 0xffff;
  2018. pmlmeext->action_public_dialog_token = 0xff;
  2019. }
  2020. /* initial default type */
  2021. ndev->type = ARPHRD_ETHER;
  2022. /*
  2023. * Disable Power Save in moniter mode,
  2024. * and enable it after leaving moniter mode.
  2025. */
  2026. if (type == NL80211_IFTYPE_MONITOR) {
  2027. rtw_ps_deny(padapter, PS_DENY_MONITOR_MODE);
  2028. LeaveAllPowerSaveMode(padapter);
  2029. } else if (old_type == NL80211_IFTYPE_MONITOR) {
  2030. /* driver in moniter mode in last time */
  2031. rtw_ps_deny_cancel(padapter, PS_DENY_MONITOR_MODE);
  2032. }
  2033. switch (type) {
  2034. case NL80211_IFTYPE_ADHOC:
  2035. networkType = Ndis802_11IBSS;
  2036. break;
  2037. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  2038. case NL80211_IFTYPE_P2P_CLIENT:
  2039. is_p2p = _TRUE;
  2040. __attribute__((__fallthrough__));
  2041. #endif
  2042. case NL80211_IFTYPE_STATION:
  2043. networkType = Ndis802_11Infrastructure;
  2044. #ifdef CONFIG_P2P
  2045. if (change && pwdinfo->driver_interface == DRIVER_CFG80211) {
  2046. if (is_p2p == _TRUE)
  2047. rtw_p2p_enable(padapter, P2P_ROLE_CLIENT);
  2048. #if !RTW_P2P_GROUP_INTERFACE
  2049. else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)
  2050. || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)
  2051. ) {
  2052. /* it means remove GC/GO and change mode from GC/GO to station(P2P DEVICE) */
  2053. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  2054. }
  2055. #endif
  2056. }
  2057. #endif /* CONFIG_P2P */
  2058. break;
  2059. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  2060. case NL80211_IFTYPE_P2P_GO:
  2061. is_p2p = _TRUE;
  2062. __attribute__((__fallthrough__));
  2063. #endif
  2064. case NL80211_IFTYPE_AP:
  2065. networkType = Ndis802_11APMode;
  2066. #ifdef CONFIG_P2P
  2067. if (change && pwdinfo->driver_interface == DRIVER_CFG80211) {
  2068. if (is_p2p == _TRUE)
  2069. rtw_p2p_enable(padapter, P2P_ROLE_GO);
  2070. #if !RTW_P2P_GROUP_INTERFACE
  2071. else if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  2072. /* it means P2P Group created, we will be GO and change mode from P2P DEVICE to AP(GO) */
  2073. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  2074. }
  2075. #endif
  2076. }
  2077. #endif /* CONFIG_P2P */
  2078. break;
  2079. #ifdef CONFIG_RTW_MESH
  2080. case NL80211_IFTYPE_MESH_POINT:
  2081. networkType = Ndis802_11_mesh;
  2082. break;
  2083. #endif
  2084. case NL80211_IFTYPE_MONITOR:
  2085. networkType = Ndis802_11Monitor;
  2086. #if 0
  2087. ndev->type = ARPHRD_IEEE80211; /* IEEE 802.11 : 801 */
  2088. #endif
  2089. ndev->type = ARPHRD_IEEE80211_RADIOTAP; /* IEEE 802.11 + radiotap header : 803 */
  2090. break;
  2091. default:
  2092. ret = -EOPNOTSUPP;
  2093. goto exit;
  2094. }
  2095. rtw_wdev->iftype = type;
  2096. if (rtw_set_802_11_infrastructure_mode(padapter, networkType) == _FALSE) {
  2097. rtw_wdev->iftype = old_type;
  2098. ret = -EPERM;
  2099. goto exit;
  2100. }
  2101. rtw_setopmode_cmd(padapter, networkType, RTW_CMDF_WAIT_ACK);
  2102. exit:
  2103. RTW_INFO(FUNC_NDEV_FMT" ret:%d\n", FUNC_NDEV_ARG(ndev), ret);
  2104. return ret;
  2105. }
  2106. void rtw_cfg80211_indicate_scan_done(_adapter *adapter, bool aborted)
  2107. {
  2108. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
  2109. _irqL irqL;
  2110. #if (KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE)
  2111. struct cfg80211_scan_info info;
  2112. memset(&info, 0, sizeof(info));
  2113. info.aborted = aborted;
  2114. #endif
  2115. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2116. if (pwdev_priv->scan_request != NULL) {
  2117. #ifdef CONFIG_DEBUG_CFG80211
  2118. RTW_INFO("%s with scan req\n", __FUNCTION__);
  2119. #endif
  2120. /* avoid WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); */
  2121. if (pwdev_priv->scan_request->wiphy != pwdev_priv->rtw_wdev->wiphy)
  2122. RTW_INFO("error wiphy compare\n");
  2123. else
  2124. #if (KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE)
  2125. cfg80211_scan_done(pwdev_priv->scan_request, &info);
  2126. #else
  2127. cfg80211_scan_done(pwdev_priv->scan_request, aborted);
  2128. #endif
  2129. pwdev_priv->scan_request = NULL;
  2130. } else {
  2131. #ifdef CONFIG_DEBUG_CFG80211
  2132. RTW_INFO("%s without scan req\n", __FUNCTION__);
  2133. #endif
  2134. }
  2135. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2136. }
  2137. u32 rtw_cfg80211_wait_scan_req_empty(_adapter *adapter, u32 timeout_ms)
  2138. {
  2139. struct rtw_wdev_priv *wdev_priv = adapter_wdev_data(adapter);
  2140. u8 empty = _FALSE;
  2141. systime start;
  2142. u32 pass_ms;
  2143. start = rtw_get_current_time();
  2144. while (rtw_get_passing_time_ms(start) <= timeout_ms) {
  2145. if (RTW_CANNOT_RUN(adapter))
  2146. break;
  2147. if (!wdev_priv->scan_request) {
  2148. empty = _TRUE;
  2149. break;
  2150. }
  2151. rtw_msleep_os(10);
  2152. }
  2153. pass_ms = rtw_get_passing_time_ms(start);
  2154. if (empty == _FALSE && pass_ms > timeout_ms)
  2155. RTW_PRINT(FUNC_ADPT_FMT" pass_ms:%u, timeout\n"
  2156. , FUNC_ADPT_ARG(adapter), pass_ms);
  2157. return pass_ms;
  2158. }
  2159. void rtw_cfg80211_unlink_bss(_adapter *padapter, struct wlan_network *pnetwork)
  2160. {
  2161. struct wireless_dev *pwdev = padapter->rtw_wdev;
  2162. struct wiphy *wiphy = pwdev->wiphy;
  2163. struct cfg80211_bss *bss = NULL;
  2164. WLAN_BSSID_EX select_network = pnetwork->network;
  2165. bss = cfg80211_get_bss(wiphy, NULL/*notify_channel*/,
  2166. select_network.MacAddress, select_network.Ssid.Ssid,
  2167. select_network.Ssid.SsidLength,
  2168. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
  2169. select_network.InfrastructureMode == Ndis802_11Infrastructure?IEEE80211_BSS_TYPE_ESS:IEEE80211_BSS_TYPE_IBSS,
  2170. IEEE80211_PRIVACY(select_network.Privacy));
  2171. #else
  2172. select_network.InfrastructureMode == Ndis802_11Infrastructure?WLAN_CAPABILITY_ESS:WLAN_CAPABILITY_IBSS,
  2173. select_network.InfrastructureMode == Ndis802_11Infrastructure?WLAN_CAPABILITY_ESS:WLAN_CAPABILITY_IBSS);
  2174. #endif
  2175. if (bss) {
  2176. cfg80211_unlink_bss(wiphy, bss);
  2177. RTW_INFO("%s(): cfg80211_unlink %s!!\n", __func__, select_network.Ssid.Ssid);
  2178. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
  2179. cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss);
  2180. #else
  2181. cfg80211_put_bss(bss);
  2182. #endif
  2183. }
  2184. return;
  2185. }
  2186. /* if target wps scan ongoing, target_ssid is filled */
  2187. int rtw_cfg80211_is_target_wps_scan(struct cfg80211_scan_request *scan_req, struct cfg80211_ssid *target_ssid)
  2188. {
  2189. int ret = 0;
  2190. if (scan_req->n_ssids != 1
  2191. || scan_req->ssids[0].ssid_len == 0
  2192. || scan_req->n_channels != 1
  2193. )
  2194. goto exit;
  2195. /* under target WPS scan */
  2196. _rtw_memcpy(target_ssid, scan_req->ssids, sizeof(struct cfg80211_ssid));
  2197. ret = 1;
  2198. exit:
  2199. return ret;
  2200. }
  2201. static void _rtw_cfg80211_surveydone_event_callback(_adapter *padapter, struct cfg80211_scan_request *scan_req)
  2202. {
  2203. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  2204. RT_CHANNEL_INFO *chset = rfctl->channel_set;
  2205. _irqL irqL;
  2206. _list *plist, *phead;
  2207. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2208. _queue *queue = &(pmlmepriv->scanned_queue);
  2209. struct wlan_network *pnetwork = NULL;
  2210. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  2211. struct cfg80211_ssid target_ssid;
  2212. u8 target_wps_scan = 0;
  2213. u8 ch;
  2214. #ifdef CONFIG_DEBUG_CFG80211
  2215. RTW_INFO("%s\n", __func__);
  2216. #endif
  2217. if (scan_req)
  2218. target_wps_scan = rtw_cfg80211_is_target_wps_scan(scan_req, &target_ssid);
  2219. else {
  2220. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2221. if (pwdev_priv->scan_request != NULL)
  2222. target_wps_scan = rtw_cfg80211_is_target_wps_scan(pwdev_priv->scan_request, &target_ssid);
  2223. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2224. }
  2225. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2226. phead = get_list_head(queue);
  2227. plist = get_next(phead);
  2228. while (1) {
  2229. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  2230. break;
  2231. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  2232. ch = pnetwork->network.Configuration.DSConfig;
  2233. /* report network only if the current channel set contains the channel to which this network belongs */
  2234. if (rtw_chset_search_ch(chset, ch) >= 0
  2235. && rtw_mlme_band_check(padapter, ch) == _TRUE
  2236. && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))
  2237. && (!IS_DFS_SLAVE_WITH_RD(rfctl)
  2238. || rtw_odm_dfs_domain_unknown(rfctl_to_dvobj(rfctl))
  2239. || !rtw_chset_is_ch_non_ocp(chset, ch))
  2240. ) {
  2241. if (target_wps_scan)
  2242. rtw_cfg80211_clear_wps_sr_of_non_target_bss(padapter, pnetwork, &target_ssid);
  2243. rtw_cfg80211_inform_bss(padapter, pnetwork);
  2244. }
  2245. #if 0
  2246. /* check ralink testbed RSN IE length */
  2247. {
  2248. if (_rtw_memcmp(pnetwork->network.Ssid.Ssid, "Ralink_11n_AP", 13)) {
  2249. uint ie_len = 0;
  2250. u8 *p = NULL;
  2251. p = rtw_get_ie(pnetwork->network.IEs + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pnetwork->network.IELength - _BEACON_IE_OFFSET_));
  2252. RTW_INFO("ie_len=%d\n", ie_len);
  2253. }
  2254. }
  2255. #endif
  2256. plist = get_next(plist);
  2257. }
  2258. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2259. }
  2260. inline void rtw_cfg80211_surveydone_event_callback(_adapter *padapter)
  2261. {
  2262. _rtw_cfg80211_surveydone_event_callback(padapter, NULL);
  2263. }
  2264. static int rtw_cfg80211_set_probe_req_wpsp2pie(_adapter *padapter, char *buf, int len)
  2265. {
  2266. int ret = 0;
  2267. uint wps_ielen = 0;
  2268. u8 *wps_ie;
  2269. u32 p2p_ielen = 0;
  2270. u8 *p2p_ie;
  2271. u32 wfd_ielen = 0;
  2272. u8 *wfd_ie;
  2273. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2274. #ifdef CONFIG_DEBUG_CFG80211
  2275. RTW_INFO("%s, ielen=%d\n", __func__, len);
  2276. #endif
  2277. if (len > 0) {
  2278. wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen);
  2279. if (wps_ie) {
  2280. #ifdef CONFIG_DEBUG_CFG80211
  2281. RTW_INFO("probe_req_wps_ielen=%d\n", wps_ielen);
  2282. #endif
  2283. if (pmlmepriv->wps_probe_req_ie) {
  2284. u32 free_len = pmlmepriv->wps_probe_req_ie_len;
  2285. pmlmepriv->wps_probe_req_ie_len = 0;
  2286. rtw_mfree(pmlmepriv->wps_probe_req_ie, free_len);
  2287. pmlmepriv->wps_probe_req_ie = NULL;
  2288. }
  2289. pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen);
  2290. if (pmlmepriv->wps_probe_req_ie == NULL) {
  2291. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  2292. return -EINVAL;
  2293. }
  2294. _rtw_memcpy(pmlmepriv->wps_probe_req_ie, wps_ie, wps_ielen);
  2295. pmlmepriv->wps_probe_req_ie_len = wps_ielen;
  2296. }
  2297. /* buf += wps_ielen; */
  2298. /* len -= wps_ielen; */
  2299. #ifdef CONFIG_P2P
  2300. p2p_ie = rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen);
  2301. if (p2p_ie) {
  2302. struct wifidirect_info *wdinfo = &padapter->wdinfo;
  2303. u32 attr_contentlen = 0;
  2304. u8 listen_ch_attr[5];
  2305. #ifdef CONFIG_DEBUG_CFG80211
  2306. RTW_INFO("probe_req_p2p_ielen=%d\n", p2p_ielen);
  2307. #endif
  2308. if (pmlmepriv->p2p_probe_req_ie) {
  2309. u32 free_len = pmlmepriv->p2p_probe_req_ie_len;
  2310. pmlmepriv->p2p_probe_req_ie_len = 0;
  2311. rtw_mfree(pmlmepriv->p2p_probe_req_ie, free_len);
  2312. pmlmepriv->p2p_probe_req_ie = NULL;
  2313. }
  2314. pmlmepriv->p2p_probe_req_ie = rtw_malloc(p2p_ielen);
  2315. if (pmlmepriv->p2p_probe_req_ie == NULL) {
  2316. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  2317. return -EINVAL;
  2318. }
  2319. _rtw_memcpy(pmlmepriv->p2p_probe_req_ie, p2p_ie, p2p_ielen);
  2320. pmlmepriv->p2p_probe_req_ie_len = p2p_ielen;
  2321. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_LISTEN_CH, (u8 *)listen_ch_attr, (uint *) &attr_contentlen)
  2322. && attr_contentlen == 5) {
  2323. if (wdinfo->listen_channel != listen_ch_attr[4]) {
  2324. RTW_INFO(FUNC_ADPT_FMT" listen channel - country:%c%c%c, class:%u, ch:%u\n",
  2325. FUNC_ADPT_ARG(padapter), listen_ch_attr[0], listen_ch_attr[1], listen_ch_attr[2],
  2326. listen_ch_attr[3], listen_ch_attr[4]);
  2327. wdinfo->listen_channel = listen_ch_attr[4];
  2328. }
  2329. }
  2330. }
  2331. #endif /* CONFIG_P2P */
  2332. #ifdef CONFIG_WFD
  2333. wfd_ie = rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen);
  2334. if (wfd_ie) {
  2335. #ifdef CONFIG_DEBUG_CFG80211
  2336. RTW_INFO("probe_req_wfd_ielen=%d\n", wfd_ielen);
  2337. #endif
  2338. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_PROBE_REQ_IE, wfd_ie, wfd_ielen) != _SUCCESS)
  2339. return -EINVAL;
  2340. }
  2341. #endif /* CONFIG_WFD */
  2342. }
  2343. return ret;
  2344. }
  2345. #ifdef CONFIG_CONCURRENT_MODE
  2346. u8 rtw_cfg80211_scan_via_buddy(_adapter *padapter, struct cfg80211_scan_request *request)
  2347. {
  2348. int i;
  2349. u8 ret = _FALSE;
  2350. _adapter *iface = NULL;
  2351. _irqL irqL;
  2352. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  2353. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  2354. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2355. for (i = 0; i < dvobj->iface_nums; i++) {
  2356. struct mlme_priv *buddy_mlmepriv;
  2357. struct rtw_wdev_priv *buddy_wdev_priv;
  2358. iface = dvobj->padapters[i];
  2359. if (iface == NULL)
  2360. continue;
  2361. if (iface == padapter)
  2362. continue;
  2363. if (rtw_is_adapter_up(iface) == _FALSE)
  2364. continue;
  2365. buddy_mlmepriv = &iface->mlmepriv;
  2366. if (!check_fwstate(buddy_mlmepriv, _FW_UNDER_SURVEY))
  2367. continue;
  2368. buddy_wdev_priv = adapter_wdev_data(iface);
  2369. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2370. _enter_critical_bh(&buddy_wdev_priv->scan_req_lock, &irqL);
  2371. if (buddy_wdev_priv->scan_request) {
  2372. pmlmepriv->scanning_via_buddy_intf = _TRUE;
  2373. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  2374. set_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
  2375. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  2376. pwdev_priv->scan_request = request;
  2377. ret = _TRUE;
  2378. }
  2379. _exit_critical_bh(&buddy_wdev_priv->scan_req_lock, &irqL);
  2380. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2381. if (ret == _TRUE)
  2382. goto exit;
  2383. }
  2384. exit:
  2385. return ret;
  2386. }
  2387. void rtw_cfg80211_indicate_scan_done_for_buddy(_adapter *padapter, bool bscan_aborted)
  2388. {
  2389. int i;
  2390. u8 ret = 0;
  2391. _adapter *iface = NULL;
  2392. _irqL irqL;
  2393. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  2394. struct mlme_priv *mlmepriv;
  2395. struct rtw_wdev_priv *wdev_priv;
  2396. bool indicate_buddy_scan;
  2397. for (i = 0; i < dvobj->iface_nums; i++) {
  2398. iface = dvobj->padapters[i];
  2399. if ((iface) && rtw_is_adapter_up(iface)) {
  2400. if (iface == padapter)
  2401. continue;
  2402. mlmepriv = &(iface->mlmepriv);
  2403. wdev_priv = adapter_wdev_data(iface);
  2404. indicate_buddy_scan = _FALSE;
  2405. _enter_critical_bh(&wdev_priv->scan_req_lock, &irqL);
  2406. if (mlmepriv->scanning_via_buddy_intf == _TRUE) {
  2407. mlmepriv->scanning_via_buddy_intf = _FALSE;
  2408. clr_fwstate(mlmepriv, _FW_UNDER_SURVEY);
  2409. if (wdev_priv->scan_request)
  2410. indicate_buddy_scan = _TRUE;
  2411. }
  2412. _exit_critical_bh(&wdev_priv->scan_req_lock, &irqL);
  2413. if (indicate_buddy_scan == _TRUE) {
  2414. rtw_cfg80211_surveydone_event_callback(iface);
  2415. rtw_indicate_scan_done(iface, bscan_aborted);
  2416. }
  2417. }
  2418. }
  2419. }
  2420. #endif /* CONFIG_CONCURRENT_MODE */
  2421. static int cfg80211_rtw_scan(struct wiphy *wiphy
  2422. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
  2423. , struct net_device *ndev
  2424. #endif
  2425. , struct cfg80211_scan_request *request)
  2426. {
  2427. int i;
  2428. u8 _status = _FALSE;
  2429. int ret = 0;
  2430. struct sitesurvey_parm parm;
  2431. _irqL irqL;
  2432. u8 survey_times = 3;
  2433. u8 survey_times_for_one_ch = 6;
  2434. struct cfg80211_ssid *ssids = request->ssids;
  2435. int social_channel = 0, j = 0;
  2436. bool need_indicate_scan_done = _FALSE;
  2437. bool ps_denied = _FALSE;
  2438. u8 ssc_chk;
  2439. _adapter *padapter;
  2440. struct wireless_dev *wdev;
  2441. struct rtw_wdev_priv *pwdev_priv;
  2442. struct mlme_priv *pmlmepriv;
  2443. #ifdef CONFIG_P2P
  2444. struct wifidirect_info *pwdinfo;
  2445. #endif /* CONFIG_P2P */
  2446. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  2447. wdev = request->wdev;
  2448. #if defined(RTW_DEDICATED_P2P_DEVICE)
  2449. if (wdev == wiphy_to_pd_wdev(wiphy))
  2450. padapter = wiphy_to_adapter(wiphy);
  2451. else
  2452. #endif
  2453. if (wdev_to_ndev(wdev))
  2454. padapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  2455. else {
  2456. ret = -EINVAL;
  2457. goto exit;
  2458. }
  2459. #else
  2460. if (ndev == NULL) {
  2461. ret = -EINVAL;
  2462. goto exit;
  2463. }
  2464. padapter = (_adapter *)rtw_netdev_priv(ndev);
  2465. wdev = ndev_to_wdev(ndev);
  2466. #endif
  2467. pwdev_priv = adapter_wdev_data(padapter);
  2468. pmlmepriv = &padapter->mlmepriv;
  2469. #ifdef CONFIG_P2P
  2470. pwdinfo = &(padapter->wdinfo);
  2471. #endif /* CONFIG_P2P */
  2472. RTW_INFO(FUNC_ADPT_FMT"%s\n", FUNC_ADPT_ARG(padapter)
  2473. , wdev == wiphy_to_pd_wdev(wiphy) ? " PD" : "");
  2474. #if 1
  2475. ssc_chk = rtw_sitesurvey_condition_check(padapter, _TRUE);
  2476. if (ssc_chk == SS_DENY_MP_MODE)
  2477. goto bypass_p2p_chk;
  2478. #ifdef DBG_LA_MODE
  2479. if (ssc_chk == SS_DENY_LA_MODE)
  2480. goto bypass_p2p_chk;
  2481. #endif
  2482. #ifdef CONFIG_P2P
  2483. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  2484. if (ssids->ssid != NULL
  2485. && _rtw_memcmp(ssids->ssid, "DIRECT-", 7)
  2486. && rtw_get_p2p_ie((u8 *)request->ie, request->ie_len, NULL, NULL)
  2487. ) {
  2488. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  2489. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  2490. else {
  2491. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  2492. #ifdef CONFIG_DEBUG_CFG80211
  2493. RTW_INFO("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  2494. #endif
  2495. }
  2496. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  2497. if (request->n_channels == 3 &&
  2498. request->channels[0]->hw_value == 1 &&
  2499. request->channels[1]->hw_value == 6 &&
  2500. request->channels[2]->hw_value == 11
  2501. )
  2502. social_channel = 1;
  2503. }
  2504. }
  2505. #endif /*CONFIG_P2P*/
  2506. if (request->ie && request->ie_len > 0)
  2507. rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len);
  2508. bypass_p2p_chk:
  2509. switch (ssc_chk) {
  2510. case SS_ALLOW :
  2511. break;
  2512. case SS_DENY_MP_MODE:
  2513. ret = -EPERM;
  2514. goto exit;
  2515. #ifdef DBG_LA_MODE
  2516. case SS_DENY_LA_MODE:
  2517. ret = -EPERM;
  2518. goto exit;
  2519. #endif
  2520. #ifdef CONFIG_RTW_REPEATER_SON
  2521. case SS_DENY_RSON_SCANING :
  2522. #endif
  2523. case SS_DENY_BLOCK_SCAN :
  2524. case SS_DENY_SELF_AP_UNDER_WPS :
  2525. case SS_DENY_SELF_AP_UNDER_LINKING :
  2526. case SS_DENY_SELF_AP_UNDER_SURVEY :
  2527. case SS_DENY_SELF_STA_UNDER_SURVEY :
  2528. #ifdef CONFIG_CONCURRENT_MODE
  2529. case SS_DENY_BUDDY_UNDER_LINK_WPS :
  2530. #endif
  2531. case SS_DENY_BUSY_TRAFFIC :
  2532. need_indicate_scan_done = _TRUE;
  2533. goto check_need_indicate_scan_done;
  2534. case SS_DENY_BY_DRV :
  2535. #if CONFIG_NOTIFY_SCAN_ABORT_WITH_BUSY
  2536. ret = -EBUSY;
  2537. goto exit;
  2538. #else
  2539. need_indicate_scan_done = _TRUE;
  2540. goto check_need_indicate_scan_done;
  2541. #endif
  2542. break;
  2543. case SS_DENY_SELF_STA_UNDER_LINKING :
  2544. ret = -EBUSY;
  2545. goto check_need_indicate_scan_done;
  2546. #ifdef CONFIG_CONCURRENT_MODE
  2547. case SS_DENY_BUDDY_UNDER_SURVEY :
  2548. {
  2549. bool scan_via_buddy = rtw_cfg80211_scan_via_buddy(padapter, request);
  2550. if (scan_via_buddy == _FALSE)
  2551. need_indicate_scan_done = _TRUE;
  2552. goto check_need_indicate_scan_done;
  2553. }
  2554. #endif
  2555. default :
  2556. RTW_ERR("site survey check code (%d) unknown\n", ssc_chk);
  2557. need_indicate_scan_done = _TRUE;
  2558. goto check_need_indicate_scan_done;
  2559. }
  2560. rtw_ps_deny(padapter, PS_DENY_SCAN);
  2561. ps_denied = _TRUE;
  2562. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  2563. need_indicate_scan_done = _TRUE;
  2564. goto check_need_indicate_scan_done;
  2565. }
  2566. #else
  2567. #ifdef CONFIG_MP_INCLUDED
  2568. if (rtw_mp_mode_check(padapter)) {
  2569. RTW_INFO("MP mode block Scan request\n");
  2570. ret = -EPERM;
  2571. goto exit;
  2572. }
  2573. #endif
  2574. #ifdef CONFIG_P2P
  2575. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  2576. if (ssids->ssid != NULL
  2577. && _rtw_memcmp(ssids->ssid, "DIRECT-", 7)
  2578. && rtw_get_p2p_ie((u8 *)request->ie, request->ie_len, NULL, NULL)
  2579. ) {
  2580. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  2581. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  2582. else {
  2583. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  2584. #ifdef CONFIG_DEBUG_CFG80211
  2585. RTW_INFO("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  2586. #endif
  2587. }
  2588. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  2589. if (request->n_channels == 3 &&
  2590. request->channels[0]->hw_value == 1 &&
  2591. request->channels[1]->hw_value == 6 &&
  2592. request->channels[2]->hw_value == 11
  2593. )
  2594. social_channel = 1;
  2595. }
  2596. }
  2597. #endif /*CONFIG_P2P*/
  2598. if (request->ie && request->ie_len > 0)
  2599. rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len);
  2600. #ifdef CONFIG_RTW_REPEATER_SON
  2601. if (padapter->rtw_rson_scanstage == RSON_SCAN_PROCESS) {
  2602. RTW_INFO(FUNC_ADPT_FMT" blocking scan for under rson scanning process\n", FUNC_ADPT_ARG(padapter));
  2603. need_indicate_scan_done = _TRUE;
  2604. goto check_need_indicate_scan_done;
  2605. }
  2606. #endif
  2607. if (adapter_wdev_data(padapter)->block_scan == _TRUE) {
  2608. RTW_INFO(FUNC_ADPT_FMT" wdev_priv.block_scan is set\n", FUNC_ADPT_ARG(padapter));
  2609. need_indicate_scan_done = _TRUE;
  2610. goto check_need_indicate_scan_done;
  2611. }
  2612. rtw_ps_deny(padapter, PS_DENY_SCAN);
  2613. ps_denied = _TRUE;
  2614. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  2615. need_indicate_scan_done = _TRUE;
  2616. goto check_need_indicate_scan_done;
  2617. }
  2618. if (rtw_is_scan_deny(padapter)) {
  2619. RTW_INFO(FUNC_ADPT_FMT ": scan deny\n", FUNC_ADPT_ARG(padapter));
  2620. #if CONFIG_NOTIFY_SCAN_ABORT_WITH_BUSY
  2621. ret = -EBUSY;
  2622. goto exit;
  2623. #else
  2624. need_indicate_scan_done = _TRUE;
  2625. goto check_need_indicate_scan_done;
  2626. #endif
  2627. }
  2628. /* check fw state*/
  2629. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
  2630. #ifdef CONFIG_DEBUG_CFG80211
  2631. RTW_INFO(FUNC_ADPT_FMT" under WIFI_AP_STATE\n", FUNC_ADPT_ARG(padapter));
  2632. #endif
  2633. if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS | _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == _TRUE) {
  2634. RTW_INFO("%s, fwstate=0x%x\n", __func__, pmlmepriv->fw_state);
  2635. if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS))
  2636. RTW_INFO("AP mode process WPS\n");
  2637. need_indicate_scan_done = _TRUE;
  2638. goto check_need_indicate_scan_done;
  2639. }
  2640. }
  2641. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
  2642. RTW_INFO("%s, fwstate=0x%x\n", __func__, pmlmepriv->fw_state);
  2643. need_indicate_scan_done = _TRUE;
  2644. goto check_need_indicate_scan_done;
  2645. } else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE) {
  2646. RTW_INFO("%s, fwstate=0x%x\n", __func__, pmlmepriv->fw_state);
  2647. ret = -EBUSY;
  2648. goto check_need_indicate_scan_done;
  2649. }
  2650. #ifdef CONFIG_CONCURRENT_MODE
  2651. if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_LINKING | WIFI_UNDER_WPS)) {
  2652. RTW_INFO("%s exit due to buddy_intf's mlme state under linking or wps\n", __func__);
  2653. need_indicate_scan_done = _TRUE;
  2654. goto check_need_indicate_scan_done;
  2655. } else if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_SURVEY)) {
  2656. bool scan_via_buddy = rtw_cfg80211_scan_via_buddy(padapter, request);
  2657. if (scan_via_buddy == _FALSE)
  2658. need_indicate_scan_done = _TRUE;
  2659. goto check_need_indicate_scan_done;
  2660. }
  2661. #endif /* CONFIG_CONCURRENT_MODE */
  2662. /* busy traffic check*/
  2663. if (rtw_mi_busy_traffic_check(padapter, _TRUE)) {
  2664. need_indicate_scan_done = _TRUE;
  2665. goto check_need_indicate_scan_done;
  2666. }
  2667. #endif
  2668. #ifdef CONFIG_P2P
  2669. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)) {
  2670. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  2671. if (social_channel == 0)
  2672. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
  2673. else
  2674. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_SOCIAL_LAST);
  2675. }
  2676. #endif /* CONFIG_P2P */
  2677. rtw_init_sitesurvey_parm(padapter, &parm);
  2678. /* parsing request ssids, n_ssids */
  2679. for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) {
  2680. #ifdef CONFIG_DEBUG_CFG80211
  2681. RTW_INFO("ssid=%s, len=%d\n", ssids[i].ssid, ssids[i].ssid_len);
  2682. #endif
  2683. _rtw_memcpy(&parm.ssid[i].Ssid, ssids[i].ssid, ssids[i].ssid_len);
  2684. parm.ssid[i].SsidLength = ssids[i].ssid_len;
  2685. }
  2686. parm.ssid_num = i;
  2687. /* parsing channels, n_channels */
  2688. for (i = 0; i < request->n_channels && i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
  2689. #ifdef CONFIG_DEBUG_CFG80211
  2690. RTW_INFO(FUNC_ADPT_FMT CHAN_FMT"\n", FUNC_ADPT_ARG(padapter), CHAN_ARG(request->channels[i]));
  2691. #endif
  2692. parm.ch[i].hw_value = request->channels[i]->hw_value;
  2693. parm.ch[i].flags = request->channels[i]->flags;
  2694. }
  2695. parm.ch_num = i;
  2696. if (request->n_channels == 1) {
  2697. for (i = 1; i < survey_times_for_one_ch; i++)
  2698. _rtw_memcpy(&parm.ch[i], &parm.ch[0], sizeof(struct rtw_ieee80211_channel));
  2699. parm.ch_num = survey_times_for_one_ch;
  2700. } else if (request->n_channels <= 4) {
  2701. for (j = request->n_channels - 1; j >= 0; j--)
  2702. for (i = 0; i < survey_times; i++)
  2703. _rtw_memcpy(&parm.ch[j * survey_times + i], &parm.ch[j], sizeof(struct rtw_ieee80211_channel));
  2704. parm.ch_num = survey_times * request->n_channels;
  2705. }
  2706. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2707. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  2708. _status = rtw_sitesurvey_cmd(padapter, &parm);
  2709. if (_status == _SUCCESS)
  2710. pwdev_priv->scan_request = request;
  2711. else
  2712. ret = -1;
  2713. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  2714. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2715. check_need_indicate_scan_done:
  2716. if (_TRUE == need_indicate_scan_done) {
  2717. #if (KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE)
  2718. struct cfg80211_scan_info info;
  2719. memset(&info, 0, sizeof(info));
  2720. info.aborted = 0;
  2721. #endif
  2722. _rtw_cfg80211_surveydone_event_callback(padapter, request);
  2723. #if (KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE)
  2724. cfg80211_scan_done(request, &info);
  2725. #else
  2726. cfg80211_scan_done(request, 0);
  2727. #endif
  2728. }
  2729. cancel_ps_deny:
  2730. if (ps_denied == _TRUE)
  2731. rtw_ps_deny_cancel(padapter, PS_DENY_SCAN);
  2732. exit:
  2733. return ret;
  2734. }
  2735. static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  2736. {
  2737. #if 0
  2738. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  2739. if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
  2740. (iwm->conf.rts_threshold != wiphy->rts_threshold)) {
  2741. int ret;
  2742. iwm->conf.rts_threshold = wiphy->rts_threshold;
  2743. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  2744. CFG_RTS_THRESHOLD,
  2745. iwm->conf.rts_threshold);
  2746. if (ret < 0)
  2747. return ret;
  2748. }
  2749. if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
  2750. (iwm->conf.frag_threshold != wiphy->frag_threshold)) {
  2751. int ret;
  2752. iwm->conf.frag_threshold = wiphy->frag_threshold;
  2753. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX,
  2754. CFG_FRAG_THRESHOLD,
  2755. iwm->conf.frag_threshold);
  2756. if (ret < 0)
  2757. return ret;
  2758. }
  2759. #endif
  2760. RTW_INFO("%s\n", __func__);
  2761. return 0;
  2762. }
  2763. static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv, u32 wpa_version)
  2764. {
  2765. RTW_INFO("%s, wpa_version=%d\n", __func__, wpa_version);
  2766. if (!wpa_version) {
  2767. psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
  2768. return 0;
  2769. }
  2770. if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
  2771. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK;
  2772. #if 0
  2773. if (wpa_version & NL80211_WPA_VERSION_2)
  2774. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
  2775. #endif
  2776. #ifdef CONFIG_WAPI_SUPPORT
  2777. if (wpa_version & NL80211_WAPI_VERSION_1)
  2778. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWAPI;
  2779. #endif
  2780. return 0;
  2781. }
  2782. static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv,
  2783. enum nl80211_auth_type sme_auth_type)
  2784. {
  2785. RTW_INFO("%s, nl80211_auth_type=%d\n", __func__, sme_auth_type);
  2786. switch (sme_auth_type) {
  2787. case NL80211_AUTHTYPE_AUTOMATIC:
  2788. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  2789. break;
  2790. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  2791. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  2792. if (psecuritypriv->ndisauthtype > Ndis802_11AuthModeWPA)
  2793. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2794. #ifdef CONFIG_WAPI_SUPPORT
  2795. if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWAPI)
  2796. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  2797. #endif
  2798. break;
  2799. case NL80211_AUTHTYPE_SHARED_KEY:
  2800. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
  2801. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2802. break;
  2803. default:
  2804. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  2805. /* return -ENOTSUPP; */
  2806. }
  2807. return 0;
  2808. }
  2809. static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 cipher, bool ucast)
  2810. {
  2811. u32 ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2812. u32 *profile_cipher = ucast ? &psecuritypriv->dot11PrivacyAlgrthm :
  2813. &psecuritypriv->dot118021XGrpPrivacy;
  2814. RTW_INFO("%s, ucast=%d, cipher=0x%x\n", __func__, ucast, cipher);
  2815. if (!cipher) {
  2816. *profile_cipher = _NO_PRIVACY_;
  2817. psecuritypriv->ndisencryptstatus = ndisencryptstatus;
  2818. return 0;
  2819. }
  2820. switch (cipher) {
  2821. case IW_AUTH_CIPHER_NONE:
  2822. *profile_cipher = _NO_PRIVACY_;
  2823. ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2824. #ifdef CONFIG_WAPI_SUPPORT
  2825. if (psecuritypriv->dot11PrivacyAlgrthm == _SMS4_)
  2826. *profile_cipher = _SMS4_;
  2827. #endif
  2828. break;
  2829. case WLAN_CIPHER_SUITE_WEP40:
  2830. *profile_cipher = _WEP40_;
  2831. ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2832. break;
  2833. case WLAN_CIPHER_SUITE_WEP104:
  2834. *profile_cipher = _WEP104_;
  2835. ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2836. break;
  2837. case WLAN_CIPHER_SUITE_TKIP:
  2838. *profile_cipher = _TKIP_;
  2839. ndisencryptstatus = Ndis802_11Encryption2Enabled;
  2840. break;
  2841. case WLAN_CIPHER_SUITE_CCMP:
  2842. *profile_cipher = _AES_;
  2843. ndisencryptstatus = Ndis802_11Encryption3Enabled;
  2844. break;
  2845. #ifdef CONFIG_WAPI_SUPPORT
  2846. case WLAN_CIPHER_SUITE_SMS4:
  2847. *profile_cipher = _SMS4_;
  2848. ndisencryptstatus = Ndis802_11_EncrypteionWAPI;
  2849. break;
  2850. #endif
  2851. default:
  2852. RTW_INFO("Unsupported cipher: 0x%x\n", cipher);
  2853. return -ENOTSUPP;
  2854. }
  2855. if (ucast) {
  2856. psecuritypriv->ndisencryptstatus = ndisencryptstatus;
  2857. /* if(psecuritypriv->dot11PrivacyAlgrthm >= _AES_) */
  2858. /* psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK; */
  2859. }
  2860. return 0;
  2861. }
  2862. static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv, u32 key_mgt)
  2863. {
  2864. RTW_INFO("%s, key_mgt=0x%x\n", __func__, key_mgt);
  2865. if (key_mgt == WLAN_AKM_SUITE_8021X) {
  2866. /* *auth_type = UMAC_AUTH_TYPE_8021X; */
  2867. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2868. psecuritypriv->rsn_akm_suite_type = 1;
  2869. } else if (key_mgt == WLAN_AKM_SUITE_PSK) {
  2870. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2871. psecuritypriv->rsn_akm_suite_type = 2;
  2872. }
  2873. #ifdef CONFIG_WAPI_SUPPORT
  2874. else if (key_mgt == WLAN_AKM_SUITE_WAPI_PSK)
  2875. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  2876. else if (key_mgt == WLAN_AKM_SUITE_WAPI_CERT)
  2877. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  2878. #endif
  2879. #ifdef CONFIG_RTW_80211R
  2880. else if (key_mgt == WLAN_AKM_SUITE_FT_8021X) {
  2881. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2882. psecuritypriv->rsn_akm_suite_type = 3;
  2883. } else if (key_mgt == WLAN_AKM_SUITE_FT_PSK) {
  2884. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2885. psecuritypriv->rsn_akm_suite_type = 4;
  2886. }
  2887. #endif
  2888. else {
  2889. RTW_INFO("Invalid key mgt: 0x%x\n", key_mgt);
  2890. /* return -EINVAL; */
  2891. }
  2892. return 0;
  2893. }
  2894. static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
  2895. {
  2896. u8 *buf = NULL, *pos = NULL;
  2897. int group_cipher = 0, pairwise_cipher = 0;
  2898. u8 mfp_opt = MFP_NO;
  2899. int ret = 0;
  2900. int wpa_ielen = 0;
  2901. int wpa2_ielen = 0;
  2902. u8 *pwpa, *pwpa2;
  2903. u8 null_addr[] = {0, 0, 0, 0, 0, 0};
  2904. if (pie == NULL || !ielen) {
  2905. /* Treat this as normal case, but need to clear WIFI_UNDER_WPS */
  2906. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  2907. goto exit;
  2908. }
  2909. if (ielen > MAX_WPA_IE_LEN + MAX_WPS_IE_LEN + MAX_P2P_IE_LEN) {
  2910. ret = -EINVAL;
  2911. goto exit;
  2912. }
  2913. buf = rtw_zmalloc(ielen);
  2914. if (buf == NULL) {
  2915. ret = -ENOMEM;
  2916. goto exit;
  2917. }
  2918. _rtw_memcpy(buf, pie , ielen);
  2919. RTW_INFO("set wpa_ie(length:%zu):\n", ielen);
  2920. RTW_INFO_DUMP(NULL, buf, ielen);
  2921. pos = buf;
  2922. if (ielen < RSN_HEADER_LEN) {
  2923. ret = -1;
  2924. goto exit;
  2925. }
  2926. pwpa = rtw_get_wpa_ie(buf, &wpa_ielen, ielen);
  2927. if (pwpa && wpa_ielen > 0) {
  2928. if (rtw_parse_wpa_ie(pwpa, wpa_ielen + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
  2929. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2930. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK;
  2931. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &pwpa[0], wpa_ielen + 2);
  2932. RTW_INFO("got wpa_ie, wpa_ielen:%u\n", wpa_ielen);
  2933. }
  2934. }
  2935. pwpa2 = rtw_get_wpa2_ie(buf, &wpa2_ielen, ielen);
  2936. if (pwpa2 && wpa2_ielen > 0) {
  2937. if (rtw_parse_wpa2_ie(pwpa2, wpa2_ielen + 2, &group_cipher, &pairwise_cipher, NULL, &mfp_opt) == _SUCCESS) {
  2938. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2939. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK;
  2940. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &pwpa2[0], wpa2_ielen + 2);
  2941. RTW_INFO("got wpa2_ie, wpa2_ielen:%u\n", wpa2_ielen);
  2942. }
  2943. }
  2944. if (group_cipher == 0)
  2945. group_cipher = WPA_CIPHER_NONE;
  2946. if (pairwise_cipher == 0)
  2947. pairwise_cipher = WPA_CIPHER_NONE;
  2948. switch (group_cipher) {
  2949. case WPA_CIPHER_NONE:
  2950. padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
  2951. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2952. break;
  2953. case WPA_CIPHER_WEP40:
  2954. padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
  2955. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2956. break;
  2957. case WPA_CIPHER_TKIP:
  2958. padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_;
  2959. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  2960. break;
  2961. case WPA_CIPHER_CCMP:
  2962. padapter->securitypriv.dot118021XGrpPrivacy = _AES_;
  2963. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  2964. break;
  2965. case WPA_CIPHER_WEP104:
  2966. padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
  2967. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2968. break;
  2969. }
  2970. switch (pairwise_cipher) {
  2971. case WPA_CIPHER_NONE:
  2972. padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
  2973. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2974. break;
  2975. case WPA_CIPHER_WEP40:
  2976. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
  2977. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2978. break;
  2979. case WPA_CIPHER_TKIP:
  2980. padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_;
  2981. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  2982. break;
  2983. case WPA_CIPHER_CCMP:
  2984. padapter->securitypriv.dot11PrivacyAlgrthm = _AES_;
  2985. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  2986. break;
  2987. case WPA_CIPHER_WEP104:
  2988. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
  2989. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2990. break;
  2991. }
  2992. if (mfp_opt == MFP_INVALID) {
  2993. RTW_INFO(FUNC_ADPT_FMT" invalid MFP setting\n", FUNC_ADPT_ARG(padapter));
  2994. ret = -EINVAL;
  2995. goto exit;
  2996. }
  2997. padapter->securitypriv.mfp_opt = mfp_opt;
  2998. {/* handle wps_ie */
  2999. uint wps_ielen;
  3000. u8 *wps_ie;
  3001. wps_ie = rtw_get_wps_ie(buf, ielen, NULL, &wps_ielen);
  3002. if (wps_ie && wps_ielen > 0) {
  3003. RTW_INFO("got wps_ie, wps_ielen:%u\n", wps_ielen);
  3004. padapter->securitypriv.wps_ie_len = wps_ielen < MAX_WPS_IE_LEN ? wps_ielen : MAX_WPS_IE_LEN;
  3005. _rtw_memcpy(padapter->securitypriv.wps_ie, wps_ie, padapter->securitypriv.wps_ie_len);
  3006. set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
  3007. } else
  3008. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  3009. }
  3010. #ifdef CONFIG_P2P
  3011. {/* check p2p_ie for assoc req; */
  3012. uint p2p_ielen = 0;
  3013. u8 *p2p_ie;
  3014. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3015. p2p_ie = rtw_get_p2p_ie(buf, ielen, NULL, &p2p_ielen);
  3016. if (p2p_ie) {
  3017. #ifdef CONFIG_DEBUG_CFG80211
  3018. RTW_INFO("%s p2p_assoc_req_ielen=%d\n", __FUNCTION__, p2p_ielen);
  3019. #endif
  3020. if (pmlmepriv->p2p_assoc_req_ie) {
  3021. u32 free_len = pmlmepriv->p2p_assoc_req_ie_len;
  3022. pmlmepriv->p2p_assoc_req_ie_len = 0;
  3023. rtw_mfree(pmlmepriv->p2p_assoc_req_ie, free_len);
  3024. pmlmepriv->p2p_assoc_req_ie = NULL;
  3025. }
  3026. pmlmepriv->p2p_assoc_req_ie = rtw_malloc(p2p_ielen);
  3027. if (pmlmepriv->p2p_assoc_req_ie == NULL) {
  3028. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  3029. goto exit;
  3030. }
  3031. _rtw_memcpy(pmlmepriv->p2p_assoc_req_ie, p2p_ie, p2p_ielen);
  3032. pmlmepriv->p2p_assoc_req_ie_len = p2p_ielen;
  3033. }
  3034. }
  3035. #endif /* CONFIG_P2P */
  3036. #ifdef CONFIG_WFD
  3037. {
  3038. uint wfd_ielen = 0;
  3039. u8 *wfd_ie;
  3040. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3041. wfd_ie = rtw_get_wfd_ie(buf, ielen, NULL, &wfd_ielen);
  3042. if (wfd_ie) {
  3043. #ifdef CONFIG_DEBUG_CFG80211
  3044. RTW_INFO("%s wfd_assoc_req_ielen=%d\n", __FUNCTION__, wfd_ielen);
  3045. #endif
  3046. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_ASSOC_REQ_IE, wfd_ie, wfd_ielen) != _SUCCESS)
  3047. goto exit;
  3048. }
  3049. }
  3050. #endif /* CONFIG_WFD */
  3051. /* TKIP and AES disallow multicast packets until installing group key */
  3052. if (padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_
  3053. || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_
  3054. || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)
  3055. /* WPS open need to enable multicast */
  3056. /* || check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == _TRUE) */
  3057. rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr);
  3058. exit:
  3059. if (buf)
  3060. rtw_mfree(buf, ielen);
  3061. if (ret)
  3062. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  3063. return ret;
  3064. }
  3065. static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
  3066. struct cfg80211_ibss_params *params)
  3067. {
  3068. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3069. NDIS_802_11_SSID ndis_ssid;
  3070. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3071. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3072. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  3073. struct cfg80211_chan_def *pch_def;
  3074. #endif
  3075. struct ieee80211_channel *pch;
  3076. int ret = 0;
  3077. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  3078. pch_def = (struct cfg80211_chan_def *)(&params->chandef);
  3079. pch = (struct ieee80211_channel *) pch_def->chan;
  3080. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
  3081. pch = (struct ieee80211_channel *)(params->channel);
  3082. #endif
  3083. if (!params->ssid || !params->ssid_len) {
  3084. ret = -EINVAL;
  3085. goto exit;
  3086. }
  3087. if (params->ssid_len > IW_ESSID_MAX_SIZE) {
  3088. ret = -E2BIG;
  3089. goto exit;
  3090. }
  3091. rtw_ps_deny(padapter, PS_DENY_JOIN);
  3092. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  3093. ret = -EPERM;
  3094. goto cancel_ps_deny;
  3095. }
  3096. #ifdef CONFIG_CONCURRENT_MODE
  3097. if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_LINKING)) {
  3098. RTW_INFO("%s, but buddy_intf is under linking\n", __FUNCTION__);
  3099. ret = -EINVAL;
  3100. goto cancel_ps_deny;
  3101. }
  3102. rtw_mi_buddy_scan_abort(padapter, _TRUE); /* OR rtw_mi_scan_abort(padapter, _TRUE);*/
  3103. #endif /*CONFIG_CONCURRENT_MODE*/
  3104. _rtw_memset(&ndis_ssid, 0, sizeof(NDIS_802_11_SSID));
  3105. ndis_ssid.SsidLength = params->ssid_len;
  3106. _rtw_memcpy(ndis_ssid.Ssid, (u8 *)params->ssid, params->ssid_len);
  3107. /* RTW_INFO("ssid=%s, len=%zu\n", ndis_ssid.Ssid, params->ssid_len); */
  3108. psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
  3109. psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
  3110. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  3111. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
  3112. psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
  3113. ret = rtw_cfg80211_set_auth_type(psecuritypriv, NL80211_AUTHTYPE_OPEN_SYSTEM);
  3114. rtw_set_802_11_authentication_mode(padapter, psecuritypriv->ndisauthtype);
  3115. RTW_INFO("%s: center_freq = %d\n", __func__, pch->center_freq);
  3116. pmlmeext->cur_channel = rtw_freq2ch(pch->center_freq);
  3117. if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == _FALSE) {
  3118. ret = -1;
  3119. goto cancel_ps_deny;
  3120. }
  3121. cancel_ps_deny:
  3122. rtw_ps_deny_cancel(padapter, PS_DENY_JOIN);
  3123. exit:
  3124. return ret;
  3125. }
  3126. static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
  3127. {
  3128. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3129. struct wireless_dev *rtw_wdev = padapter->rtw_wdev;
  3130. enum nl80211_iftype old_type;
  3131. int ret = 0;
  3132. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3133. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT)
  3134. rtw_wdev_set_not_indic_disco(adapter_wdev_data(padapter), 1);
  3135. #endif
  3136. old_type = rtw_wdev->iftype;
  3137. rtw_set_to_roam(padapter, 0);
  3138. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
  3139. rtw_scan_abort(padapter);
  3140. LeaveAllPowerSaveMode(padapter);
  3141. rtw_wdev->iftype = NL80211_IFTYPE_STATION;
  3142. if (rtw_set_802_11_infrastructure_mode(padapter, Ndis802_11Infrastructure) == _FALSE) {
  3143. rtw_wdev->iftype = old_type;
  3144. ret = -EPERM;
  3145. goto leave_ibss;
  3146. }
  3147. rtw_setopmode_cmd(padapter, Ndis802_11Infrastructure, RTW_CMDF_WAIT_ACK);
  3148. }
  3149. leave_ibss:
  3150. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT)
  3151. rtw_wdev_set_not_indic_disco(adapter_wdev_data(padapter), 0);
  3152. #endif
  3153. return 0;
  3154. }
  3155. bool rtw_cfg80211_is_connect_requested(_adapter *adapter)
  3156. {
  3157. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
  3158. _irqL irqL;
  3159. bool requested;
  3160. _enter_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  3161. requested = pwdev_priv->connect_req ? 1 : 0;
  3162. _exit_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  3163. return requested;
  3164. }
  3165. static int _rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev)
  3166. {
  3167. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3168. /* if(check_fwstate(&padapter->mlmepriv, _FW_LINKED)) */
  3169. {
  3170. rtw_scan_abort(padapter);
  3171. rtw_join_abort_timeout(padapter, 300);
  3172. LeaveAllPowerSaveMode(padapter);
  3173. rtw_disassoc_cmd(padapter, 500, RTW_CMDF_WAIT_ACK);
  3174. #ifdef CONFIG_RTW_REPEATER_SON
  3175. rtw_rson_do_disconnect(padapter);
  3176. #endif
  3177. RTW_INFO("%s...call rtw_indicate_disconnect\n", __func__);
  3178. rtw_free_assoc_resources_cmd(padapter, _TRUE, RTW_CMDF_WAIT_ACK);
  3179. /* indicate locally_generated = 0 when suspend */
  3180. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0))
  3181. rtw_indicate_disconnect(padapter, 0, wiphy->dev.power.is_prepared ? _FALSE : _TRUE);
  3182. #else
  3183. /*
  3184. * for kernel < 4.2, DISCONNECT event is hardcoded with
  3185. * NL80211_ATTR_DISCONNECTED_BY_AP=1 in NL80211 layer
  3186. * no need to judge if under suspend
  3187. */
  3188. rtw_indicate_disconnect(padapter, 0, _TRUE);
  3189. #endif
  3190. rtw_pwr_wakeup(padapter);
  3191. }
  3192. return 0;
  3193. }
  3194. static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
  3195. struct cfg80211_connect_params *sme)
  3196. {
  3197. int ret = 0;
  3198. NDIS_802_11_AUTHENTICATION_MODE authmode;
  3199. NDIS_802_11_SSID ndis_ssid;
  3200. /* u8 matched_by_bssid=_FALSE; */
  3201. /* u8 matched_by_ssid=_FALSE; */
  3202. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3203. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3204. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  3205. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3206. _irqL irqL;
  3207. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_CONNECT)
  3208. rtw_wdev_set_not_indic_disco(pwdev_priv, 1);
  3209. #endif
  3210. RTW_INFO("=>"FUNC_NDEV_FMT" - Start to Connection\n", FUNC_NDEV_ARG(ndev));
  3211. RTW_INFO("privacy=%d, key=%p, key_len=%d, key_idx=%d, auth_type=%d\n",
  3212. sme->privacy, sme->key, sme->key_len, sme->key_idx, sme->auth_type);
  3213. if (pwdev_priv->block == _TRUE) {
  3214. ret = -EBUSY;
  3215. RTW_INFO("%s wdev_priv.block is set\n", __FUNCTION__);
  3216. goto exit;
  3217. }
  3218. if (check_fwstate(pmlmepriv, _FW_LINKED | _FW_UNDER_LINKING) == _TRUE) {
  3219. _rtw_disconnect(wiphy, ndev);
  3220. RTW_INFO("%s disconnect before connecting! fw_state=0x%x\n",
  3221. __FUNCTION__, pmlmepriv->fw_state);
  3222. }
  3223. #ifdef CONFIG_PLATFORM_MSTAR_SCAN_BEFORE_CONNECT
  3224. printk("MStar Android!\n");
  3225. if (pwdev_priv->bandroid_scan == _FALSE) {
  3226. #ifdef CONFIG_P2P
  3227. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3228. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3229. #endif /* CONFIG_P2P */
  3230. {
  3231. ret = -EBUSY;
  3232. printk("Android hasn't attached yet!\n");
  3233. goto exit;
  3234. }
  3235. }
  3236. #endif
  3237. if (!sme->ssid || !sme->ssid_len) {
  3238. ret = -EINVAL;
  3239. goto exit;
  3240. }
  3241. if (sme->ssid_len > IW_ESSID_MAX_SIZE) {
  3242. ret = -E2BIG;
  3243. goto exit;
  3244. }
  3245. rtw_ps_deny(padapter, PS_DENY_JOIN);
  3246. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  3247. ret = -EPERM;
  3248. goto cancel_ps_deny;
  3249. }
  3250. rtw_mi_scan_abort(padapter, _TRUE);
  3251. rtw_join_abort_timeout(padapter, 300);
  3252. #ifdef CONFIG_CONCURRENT_MODE
  3253. if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_LINKING)) {
  3254. ret = -EINVAL;
  3255. goto cancel_ps_deny;
  3256. }
  3257. #endif
  3258. _rtw_memset(&ndis_ssid, 0, sizeof(NDIS_802_11_SSID));
  3259. ndis_ssid.SsidLength = sme->ssid_len;
  3260. _rtw_memcpy(ndis_ssid.Ssid, (u8 *)sme->ssid, sme->ssid_len);
  3261. RTW_INFO("ssid=%s, len=%zu\n", ndis_ssid.Ssid, sme->ssid_len);
  3262. if (sme->bssid)
  3263. RTW_INFO("bssid="MAC_FMT"\n", MAC_ARG(sme->bssid));
  3264. psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
  3265. psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
  3266. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  3267. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
  3268. psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
  3269. #ifdef CONFIG_WAPI_SUPPORT
  3270. padapter->wapiInfo.bWapiEnable = false;
  3271. #endif
  3272. ret = rtw_cfg80211_set_wpa_version(psecuritypriv, sme->crypto.wpa_versions);
  3273. if (ret < 0)
  3274. goto cancel_ps_deny;
  3275. #ifdef CONFIG_WAPI_SUPPORT
  3276. if (sme->crypto.wpa_versions & NL80211_WAPI_VERSION_1) {
  3277. padapter->wapiInfo.bWapiEnable = true;
  3278. padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN;
  3279. padapter->wapiInfo.extra_postfix_len = SMS4_MIC_LEN;
  3280. }
  3281. #endif
  3282. ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme->auth_type);
  3283. #ifdef CONFIG_WAPI_SUPPORT
  3284. if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_WAPI)
  3285. padapter->mlmeextpriv.mlmext_info.auth_algo = psecuritypriv->dot11AuthAlgrthm;
  3286. #endif
  3287. if (ret < 0)
  3288. goto cancel_ps_deny;
  3289. RTW_INFO("%s, ie_len=%zu\n", __func__, sme->ie_len);
  3290. ret = rtw_cfg80211_set_wpa_ie(padapter, (u8 *)sme->ie, sme->ie_len);
  3291. if (ret < 0)
  3292. goto cancel_ps_deny;
  3293. if (sme->crypto.n_ciphers_pairwise) {
  3294. ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.ciphers_pairwise[0], _TRUE);
  3295. if (ret < 0)
  3296. goto cancel_ps_deny;
  3297. }
  3298. /* For WEP Shared auth */
  3299. if (sme->key_len > 0 && sme->key) {
  3300. u32 wep_key_idx, wep_key_len, wep_total_len;
  3301. NDIS_802_11_WEP *pwep = NULL;
  3302. RTW_INFO("%s(): Shared/Auto WEP\n", __FUNCTION__);
  3303. wep_key_idx = sme->key_idx;
  3304. wep_key_len = sme->key_len;
  3305. if (sme->key_idx > WEP_KEYS) {
  3306. ret = -EINVAL;
  3307. goto cancel_ps_deny;
  3308. }
  3309. if (wep_key_len > 0) {
  3310. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  3311. wep_total_len = wep_key_len + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
  3312. pwep = (NDIS_802_11_WEP *) rtw_malloc(wep_total_len);
  3313. if (pwep == NULL) {
  3314. RTW_INFO(" wpa_set_encryption: pwep allocate fail !!!\n");
  3315. ret = -ENOMEM;
  3316. goto cancel_ps_deny;
  3317. }
  3318. _rtw_memset(pwep, 0, wep_total_len);
  3319. pwep->KeyLength = wep_key_len;
  3320. pwep->Length = wep_total_len;
  3321. if (wep_key_len == 13) {
  3322. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
  3323. padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
  3324. }
  3325. } else {
  3326. ret = -EINVAL;
  3327. goto cancel_ps_deny;
  3328. }
  3329. pwep->KeyIndex = wep_key_idx;
  3330. pwep->KeyIndex |= 0x80000000;
  3331. _rtw_memcpy(pwep->KeyMaterial, (void *)sme->key, pwep->KeyLength);
  3332. if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL)
  3333. ret = -EOPNOTSUPP ;
  3334. if (pwep)
  3335. rtw_mfree((u8 *)pwep, wep_total_len);
  3336. if (ret < 0)
  3337. goto cancel_ps_deny;
  3338. }
  3339. ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.cipher_group, _FALSE);
  3340. if (ret < 0)
  3341. return ret;
  3342. if (sme->crypto.n_akm_suites) {
  3343. ret = rtw_cfg80211_set_key_mgt(psecuritypriv, sme->crypto.akm_suites[0]);
  3344. if (ret < 0)
  3345. goto cancel_ps_deny;
  3346. }
  3347. #ifdef CONFIG_8011R
  3348. else {
  3349. /*It could be a connection without RSN IEs*/
  3350. psecuritypriv->rsn_akm_suite_type = 0;
  3351. }
  3352. #endif
  3353. #ifdef CONFIG_WAPI_SUPPORT
  3354. if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_WAPI_PSK)
  3355. padapter->wapiInfo.bWapiPSK = true;
  3356. else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_WAPI_CERT)
  3357. padapter->wapiInfo.bWapiPSK = false;
  3358. #endif
  3359. authmode = psecuritypriv->ndisauthtype;
  3360. rtw_set_802_11_authentication_mode(padapter, authmode);
  3361. /* rtw_set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */
  3362. if (rtw_set_802_11_connect(padapter, (u8 *)sme->bssid, &ndis_ssid) == _FALSE) {
  3363. ret = -1;
  3364. goto cancel_ps_deny;
  3365. }
  3366. _enter_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  3367. if (pwdev_priv->connect_req) {
  3368. rtw_wdev_free_connect_req(pwdev_priv);
  3369. RTW_INFO(FUNC_NDEV_FMT" free existing connect_req\n", FUNC_NDEV_ARG(ndev));
  3370. }
  3371. pwdev_priv->connect_req = (struct cfg80211_connect_params *)rtw_malloc(sizeof(*pwdev_priv->connect_req));
  3372. if (pwdev_priv->connect_req)
  3373. _rtw_memcpy(pwdev_priv->connect_req, sme, sizeof(*pwdev_priv->connect_req));
  3374. else
  3375. RTW_WARN(FUNC_NDEV_FMT" alloc connect_req fail\n", FUNC_NDEV_ARG(ndev));
  3376. _exit_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  3377. RTW_INFO("set ssid:dot11AuthAlgrthm=%d, dot11PrivacyAlgrthm=%d, dot118021XGrpPrivacy=%d\n", psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm,
  3378. psecuritypriv->dot118021XGrpPrivacy);
  3379. cancel_ps_deny:
  3380. rtw_ps_deny_cancel(padapter, PS_DENY_JOIN);
  3381. exit:
  3382. RTW_INFO("<=%s, ret %d\n", __FUNCTION__, ret);
  3383. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_CONNECT)
  3384. rtw_wdev_set_not_indic_disco(pwdev_priv, 0);
  3385. #endif
  3386. return ret;
  3387. }
  3388. static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
  3389. u16 reason_code)
  3390. {
  3391. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3392. RTW_INFO(FUNC_NDEV_FMT" - Start to Disconnect\n", FUNC_NDEV_ARG(ndev));
  3393. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT)
  3394. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  3395. if (!wiphy->dev.power.is_prepared)
  3396. #endif
  3397. rtw_wdev_set_not_indic_disco(adapter_wdev_data(padapter), 1);
  3398. #endif
  3399. rtw_set_to_roam(padapter, 0);
  3400. /* if(check_fwstate(&padapter->mlmepriv, _FW_LINKED)) */
  3401. {
  3402. _rtw_disconnect(wiphy, ndev);
  3403. }
  3404. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT)
  3405. rtw_wdev_set_not_indic_disco(adapter_wdev_data(padapter), 0);
  3406. #endif
  3407. RTW_INFO(FUNC_NDEV_FMT" return 0\n", FUNC_NDEV_ARG(ndev));
  3408. return 0;
  3409. }
  3410. static int cfg80211_rtw_set_txpower(struct wiphy *wiphy,
  3411. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  3412. struct wireless_dev *wdev,
  3413. #endif
  3414. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) || defined(COMPAT_KERNEL_RELEASE)
  3415. enum nl80211_tx_power_setting type, int mbm)
  3416. #else
  3417. enum tx_power_setting type, int dbm)
  3418. #endif
  3419. {
  3420. #if 0
  3421. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  3422. int ret;
  3423. switch (type) {
  3424. case NL80211_TX_POWER_AUTOMATIC:
  3425. return 0;
  3426. case NL80211_TX_POWER_FIXED:
  3427. if (mbm < 0 || (mbm % 100))
  3428. return -EOPNOTSUPP;
  3429. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  3430. return 0;
  3431. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  3432. CFG_TX_PWR_LIMIT_USR,
  3433. MBM_TO_DBM(mbm) * 2);
  3434. if (ret < 0)
  3435. return ret;
  3436. return iwm_tx_power_trigger(iwm);
  3437. default:
  3438. IWM_ERR(iwm, "Unsupported power type: %d\n", type);
  3439. return -EOPNOTSUPP;
  3440. }
  3441. #endif
  3442. RTW_INFO("%s\n", __func__);
  3443. return 0;
  3444. }
  3445. static int cfg80211_rtw_get_txpower(struct wiphy *wiphy,
  3446. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  3447. struct wireless_dev *wdev,
  3448. #endif
  3449. int *dbm)
  3450. {
  3451. RTW_INFO("%s\n", __func__);
  3452. *dbm = (12);
  3453. return 0;
  3454. }
  3455. inline bool rtw_cfg80211_pwr_mgmt(_adapter *adapter)
  3456. {
  3457. struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(adapter);
  3458. return rtw_wdev_priv->power_mgmt;
  3459. }
  3460. static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy,
  3461. struct net_device *ndev,
  3462. bool enabled, int timeout)
  3463. {
  3464. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3465. struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(padapter);
  3466. RTW_INFO(FUNC_NDEV_FMT" enabled:%u, timeout:%d\n", FUNC_NDEV_ARG(ndev),
  3467. enabled, timeout);
  3468. rtw_wdev_priv->power_mgmt = enabled;
  3469. #ifdef CONFIG_LPS
  3470. if (!enabled)
  3471. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE_CFG80211_PWRMGMT, 1);
  3472. #endif
  3473. return 0;
  3474. }
  3475. static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy,
  3476. struct net_device *ndev,
  3477. struct cfg80211_pmksa *pmksa)
  3478. {
  3479. u8 index, blInserted = _FALSE;
  3480. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3481. struct mlme_priv *mlme = &padapter->mlmepriv;
  3482. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3483. u8 strZeroMacAddress[ETH_ALEN] = { 0x00 };
  3484. RTW_INFO(FUNC_NDEV_FMT" "MAC_FMT" "KEY_FMT"\n", FUNC_NDEV_ARG(ndev)
  3485. , MAC_ARG(pmksa->bssid), KEY_ARG(pmksa->pmkid));
  3486. if (_rtw_memcmp((u8 *)pmksa->bssid, strZeroMacAddress, ETH_ALEN) == _TRUE)
  3487. return -EINVAL;
  3488. if (check_fwstate(mlme, _FW_LINKED) == _FALSE) {
  3489. RTW_INFO(FUNC_NDEV_FMT" not set pmksa cause not in linked state\n", FUNC_NDEV_ARG(ndev));
  3490. return -EINVAL;
  3491. }
  3492. blInserted = _FALSE;
  3493. /* overwrite PMKID */
  3494. for (index = 0 ; index < NUM_PMKID_CACHE; index++) {
  3495. if (_rtw_memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN) == _TRUE) {
  3496. /* BSSID is matched, the same AP => rewrite with new PMKID. */
  3497. RTW_INFO(FUNC_NDEV_FMT" BSSID exists in the PMKList.\n", FUNC_NDEV_ARG(ndev));
  3498. _rtw_memcpy(psecuritypriv->PMKIDList[index].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN);
  3499. psecuritypriv->PMKIDList[index].bUsed = _TRUE;
  3500. psecuritypriv->PMKIDIndex = index + 1;
  3501. blInserted = _TRUE;
  3502. break;
  3503. }
  3504. }
  3505. if (!blInserted) {
  3506. /* Find a new entry */
  3507. RTW_INFO(FUNC_NDEV_FMT" Use the new entry index = %d for this PMKID.\n",
  3508. FUNC_NDEV_ARG(ndev), psecuritypriv->PMKIDIndex);
  3509. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, (u8 *)pmksa->bssid, ETH_ALEN);
  3510. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN);
  3511. psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = _TRUE;
  3512. psecuritypriv->PMKIDIndex++ ;
  3513. if (psecuritypriv->PMKIDIndex == 16)
  3514. psecuritypriv->PMKIDIndex = 0;
  3515. }
  3516. return 0;
  3517. }
  3518. static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy,
  3519. struct net_device *ndev,
  3520. struct cfg80211_pmksa *pmksa)
  3521. {
  3522. u8 index, bMatched = _FALSE;
  3523. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3524. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3525. RTW_INFO(FUNC_NDEV_FMT" "MAC_FMT" "KEY_FMT"\n", FUNC_NDEV_ARG(ndev)
  3526. , MAC_ARG(pmksa->bssid), KEY_ARG(pmksa->pmkid));
  3527. for (index = 0 ; index < NUM_PMKID_CACHE; index++) {
  3528. if (_rtw_memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN) == _TRUE) {
  3529. /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */
  3530. _rtw_memset(psecuritypriv->PMKIDList[index].Bssid, 0x00, ETH_ALEN);
  3531. _rtw_memset(psecuritypriv->PMKIDList[index].PMKID, 0x00, WLAN_PMKID_LEN);
  3532. psecuritypriv->PMKIDList[index].bUsed = _FALSE;
  3533. bMatched = _TRUE;
  3534. RTW_INFO(FUNC_NDEV_FMT" clear id:%hhu\n", FUNC_NDEV_ARG(ndev), index);
  3535. break;
  3536. }
  3537. }
  3538. if (_FALSE == bMatched) {
  3539. RTW_INFO(FUNC_NDEV_FMT" do not have matched BSSID\n"
  3540. , FUNC_NDEV_ARG(ndev));
  3541. return -EINVAL;
  3542. }
  3543. return 0;
  3544. }
  3545. static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy,
  3546. struct net_device *ndev)
  3547. {
  3548. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3549. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3550. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3551. _rtw_memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
  3552. psecuritypriv->PMKIDIndex = 0;
  3553. return 0;
  3554. }
  3555. #ifdef CONFIG_AP_MODE
  3556. void rtw_cfg80211_indicate_sta_assoc(_adapter *padapter, u8 *pmgmt_frame, uint frame_len)
  3557. {
  3558. #if !defined(RTW_USE_CFG80211_STA_EVENT) && !defined(COMPAT_KERNEL_RELEASE)
  3559. s32 freq;
  3560. int channel;
  3561. struct wireless_dev *pwdev = padapter->rtw_wdev;
  3562. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3563. #endif
  3564. struct net_device *ndev = padapter->pnetdev;
  3565. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  3566. #if defined(RTW_USE_CFG80211_STA_EVENT) || defined(COMPAT_KERNEL_RELEASE)
  3567. {
  3568. struct station_info sinfo;
  3569. u8 ie_offset;
  3570. if (get_frame_sub_type(pmgmt_frame) == WIFI_ASSOCREQ)
  3571. ie_offset = _ASOCREQ_IE_OFFSET_;
  3572. else /* WIFI_REASSOCREQ */
  3573. ie_offset = _REASOCREQ_IE_OFFSET_;
  3574. memset(&sinfo, 0, sizeof(sinfo));
  3575. sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
  3576. sinfo.assoc_req_ies = pmgmt_frame + WLAN_HDR_A3_LEN + ie_offset;
  3577. sinfo.assoc_req_ies_len = frame_len - WLAN_HDR_A3_LEN - ie_offset;
  3578. cfg80211_new_sta(ndev, get_addr2_ptr(pmgmt_frame), &sinfo, GFP_ATOMIC);
  3579. }
  3580. #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
  3581. channel = pmlmeext->cur_channel;
  3582. freq = rtw_ch2freq(channel);
  3583. #ifdef COMPAT_KERNEL_RELEASE
  3584. rtw_cfg80211_rx_mgmt(pwdev, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
  3585. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  3586. rtw_cfg80211_rx_mgmt(pwdev, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
  3587. #else /* COMPAT_KERNEL_RELEASE */
  3588. {
  3589. /* to avoid WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION) when calling cfg80211_send_rx_assoc() */
  3590. #ifndef CONFIG_PLATFORM_MSTAR
  3591. pwdev->iftype = NL80211_IFTYPE_STATION;
  3592. #endif /* CONFIG_PLATFORM_MSTAR */
  3593. RTW_INFO("iftype=%d before call cfg80211_send_rx_assoc()\n", pwdev->iftype);
  3594. rtw_cfg80211_send_rx_assoc(padapter, NULL, pmgmt_frame, frame_len);
  3595. RTW_INFO("iftype=%d after call cfg80211_send_rx_assoc()\n", pwdev->iftype);
  3596. pwdev->iftype = NL80211_IFTYPE_AP;
  3597. /* cfg80211_rx_action(padapter->pnetdev, freq, pmgmt_frame, frame_len, GFP_ATOMIC); */
  3598. }
  3599. #endif /* COMPAT_KERNEL_RELEASE */
  3600. #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
  3601. }
  3602. void rtw_cfg80211_indicate_sta_disassoc(_adapter *padapter, const u8 *da, unsigned short reason)
  3603. {
  3604. #if !defined(RTW_USE_CFG80211_STA_EVENT) && !defined(COMPAT_KERNEL_RELEASE)
  3605. s32 freq;
  3606. int channel;
  3607. u8 *pmgmt_frame;
  3608. uint frame_len;
  3609. struct rtw_ieee80211_hdr *pwlanhdr;
  3610. unsigned short *fctrl;
  3611. u8 mgmt_buf[128] = {0};
  3612. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3613. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3614. struct wireless_dev *wdev = padapter->rtw_wdev;
  3615. #endif
  3616. struct net_device *ndev = padapter->pnetdev;
  3617. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  3618. #if defined(RTW_USE_CFG80211_STA_EVENT) || defined(COMPAT_KERNEL_RELEASE)
  3619. cfg80211_del_sta(ndev, da, GFP_ATOMIC);
  3620. #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
  3621. channel = pmlmeext->cur_channel;
  3622. freq = rtw_ch2freq(channel);
  3623. pmgmt_frame = mgmt_buf;
  3624. pwlanhdr = (struct rtw_ieee80211_hdr *)pmgmt_frame;
  3625. fctrl = &(pwlanhdr->frame_ctl);
  3626. *(fctrl) = 0;
  3627. _rtw_memcpy(pwlanhdr->addr1, adapter_mac_addr(padapter), ETH_ALEN);
  3628. _rtw_memcpy(pwlanhdr->addr2, da, ETH_ALEN);
  3629. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  3630. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  3631. pmlmeext->mgnt_seq++;
  3632. set_frame_sub_type(pmgmt_frame, WIFI_DEAUTH);
  3633. pmgmt_frame += sizeof(struct rtw_ieee80211_hdr_3addr);
  3634. frame_len = sizeof(struct rtw_ieee80211_hdr_3addr);
  3635. reason = cpu_to_le16(reason);
  3636. pmgmt_frame = rtw_set_fixed_ie(pmgmt_frame, _RSON_CODE_ , (unsigned char *)&reason, &frame_len);
  3637. #ifdef COMPAT_KERNEL_RELEASE
  3638. rtw_cfg80211_rx_mgmt(wdev, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
  3639. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  3640. rtw_cfg80211_rx_mgmt(wdev, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
  3641. #else /* COMPAT_KERNEL_RELEASE */
  3642. cfg80211_send_disassoc(padapter->pnetdev, mgmt_buf, frame_len);
  3643. /* cfg80211_rx_action(padapter->pnetdev, freq, mgmt_buf, frame_len, GFP_ATOMIC); */
  3644. #endif /* COMPAT_KERNEL_RELEASE */
  3645. #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
  3646. }
  3647. static int rtw_cfg80211_monitor_if_open(struct net_device *ndev)
  3648. {
  3649. int ret = 0;
  3650. RTW_INFO("%s\n", __func__);
  3651. return ret;
  3652. }
  3653. static int rtw_cfg80211_monitor_if_close(struct net_device *ndev)
  3654. {
  3655. int ret = 0;
  3656. RTW_INFO("%s\n", __func__);
  3657. return ret;
  3658. }
  3659. static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_device *ndev)
  3660. {
  3661. int ret = 0;
  3662. int rtap_len;
  3663. int qos_len = 0;
  3664. int dot11_hdr_len = 24;
  3665. int snap_len = 6;
  3666. unsigned char *pdata;
  3667. u16 frame_ctl;
  3668. unsigned char src_mac_addr[ETH_ALEN];
  3669. unsigned char dst_mac_addr[ETH_ALEN];
  3670. struct rtw_ieee80211_hdr *dot11_hdr;
  3671. struct ieee80211_radiotap_header *rtap_hdr;
  3672. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3673. #ifdef CONFIG_DFS_MASTER
  3674. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  3675. #endif
  3676. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3677. if (skb)
  3678. rtw_mstat_update(MSTAT_TYPE_SKB, MSTAT_ALLOC_SUCCESS, skb->truesize);
  3679. if (IS_CH_WAITING(rfctl)) {
  3680. #ifdef CONFIG_DFS_MASTER
  3681. if (rtw_rfctl_overlap_radar_detect_ch(rfctl))
  3682. goto fail;
  3683. #endif
  3684. }
  3685. if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
  3686. goto fail;
  3687. rtap_hdr = (struct ieee80211_radiotap_header *)skb->data;
  3688. if (unlikely(rtap_hdr->it_version))
  3689. goto fail;
  3690. rtap_len = ieee80211_get_radiotap_len(skb->data);
  3691. if (unlikely(skb->len < rtap_len))
  3692. goto fail;
  3693. if (rtap_len != 14) {
  3694. RTW_INFO("radiotap len (should be 14): %d\n", rtap_len);
  3695. goto fail;
  3696. }
  3697. /* Skip the ratio tap header */
  3698. skb_pull(skb, rtap_len);
  3699. dot11_hdr = (struct rtw_ieee80211_hdr *)skb->data;
  3700. frame_ctl = le16_to_cpu(dot11_hdr->frame_ctl);
  3701. /* Check if the QoS bit is set */
  3702. if ((frame_ctl & RTW_IEEE80211_FCTL_FTYPE) == RTW_IEEE80211_FTYPE_DATA) {
  3703. /* Check if this ia a Wireless Distribution System (WDS) frame
  3704. * which has 4 MAC addresses
  3705. */
  3706. if (dot11_hdr->frame_ctl & 0x0080)
  3707. qos_len = 2;
  3708. if ((dot11_hdr->frame_ctl & 0x0300) == 0x0300)
  3709. dot11_hdr_len += 6;
  3710. memcpy(dst_mac_addr, dot11_hdr->addr1, sizeof(dst_mac_addr));
  3711. memcpy(src_mac_addr, dot11_hdr->addr2, sizeof(src_mac_addr));
  3712. /* Skip the 802.11 header, QoS (if any) and SNAP, but leave spaces for
  3713. * for two MAC addresses
  3714. */
  3715. skb_pull(skb, dot11_hdr_len + qos_len + snap_len - sizeof(src_mac_addr) * 2);
  3716. pdata = (unsigned char *)skb->data;
  3717. memcpy(pdata, dst_mac_addr, sizeof(dst_mac_addr));
  3718. memcpy(pdata + sizeof(dst_mac_addr), src_mac_addr, sizeof(src_mac_addr));
  3719. RTW_INFO("should be eapol packet\n");
  3720. /* Use the real net device to transmit the packet */
  3721. ret = _rtw_xmit_entry(skb, padapter->pnetdev);
  3722. return ret;
  3723. } else if ((frame_ctl & (RTW_IEEE80211_FCTL_FTYPE | RTW_IEEE80211_FCTL_STYPE))
  3724. == (RTW_IEEE80211_FTYPE_MGMT | RTW_IEEE80211_STYPE_ACTION)
  3725. ) {
  3726. /* only for action frames */
  3727. struct xmit_frame *pmgntframe;
  3728. struct pkt_attrib *pattrib;
  3729. unsigned char *pframe;
  3730. /* u8 category, action, OUI_Subtype, dialogToken=0; */
  3731. /* unsigned char *frame_body; */
  3732. struct rtw_ieee80211_hdr *pwlanhdr;
  3733. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  3734. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3735. u8 *buf = skb->data;
  3736. u32 len = skb->len;
  3737. u8 category, action;
  3738. int type = -1;
  3739. if (rtw_action_frame_parse(buf, len, &category, &action) == _FALSE) {
  3740. RTW_INFO(FUNC_NDEV_FMT" frame_control:0x%x\n", FUNC_NDEV_ARG(ndev),
  3741. le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl));
  3742. goto fail;
  3743. }
  3744. RTW_INFO("RTW_Tx:da="MAC_FMT" via "FUNC_NDEV_FMT"\n",
  3745. MAC_ARG(GetAddr1Ptr(buf)), FUNC_NDEV_ARG(ndev));
  3746. #ifdef CONFIG_P2P
  3747. type = rtw_p2p_check_frames(padapter, buf, len, _TRUE);
  3748. if (type >= 0)
  3749. goto dump;
  3750. #endif
  3751. if (category == RTW_WLAN_CATEGORY_PUBLIC)
  3752. RTW_INFO("RTW_Tx:%s\n", action_public_str(action));
  3753. else
  3754. RTW_INFO("RTW_Tx:category(%u), action(%u)\n", category, action);
  3755. dump:
  3756. /* starting alloc mgmt frame to dump it */
  3757. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  3758. if (pmgntframe == NULL)
  3759. goto fail;
  3760. /* update attribute */
  3761. pattrib = &pmgntframe->attrib;
  3762. update_mgntframe_attrib(padapter, pattrib);
  3763. pattrib->retry_ctrl = _FALSE;
  3764. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  3765. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  3766. _rtw_memcpy(pframe, (void *)buf, len);
  3767. pattrib->pktlen = len;
  3768. #ifdef CONFIG_P2P
  3769. if (type >= 0)
  3770. rtw_xframe_chk_wfd_ie(pmgntframe);
  3771. #endif /* CONFIG_P2P */
  3772. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  3773. /* update seq number */
  3774. pmlmeext->mgnt_seq = GetSequence(pwlanhdr);
  3775. pattrib->seqnum = pmlmeext->mgnt_seq;
  3776. pmlmeext->mgnt_seq++;
  3777. pattrib->last_txcmdsz = pattrib->pktlen;
  3778. dump_mgntframe(padapter, pmgntframe);
  3779. } else
  3780. RTW_INFO("frame_ctl=0x%x\n", frame_ctl & (RTW_IEEE80211_FCTL_FTYPE | RTW_IEEE80211_FCTL_STYPE));
  3781. fail:
  3782. rtw_skb_free(skb);
  3783. return 0;
  3784. }
  3785. static void rtw_cfg80211_monitor_if_set_multicast_list(struct net_device *ndev)
  3786. {
  3787. RTW_INFO("%s\n", __func__);
  3788. }
  3789. static int rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr)
  3790. {
  3791. int ret = 0;
  3792. RTW_INFO("%s\n", __func__);
  3793. return ret;
  3794. }
  3795. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  3796. static const struct net_device_ops rtw_cfg80211_monitor_if_ops = {
  3797. .ndo_open = rtw_cfg80211_monitor_if_open,
  3798. .ndo_stop = rtw_cfg80211_monitor_if_close,
  3799. .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry,
  3800. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0))
  3801. .ndo_set_multicast_list = rtw_cfg80211_monitor_if_set_multicast_list,
  3802. #endif
  3803. .ndo_set_mac_address = rtw_cfg80211_monitor_if_set_mac_address,
  3804. };
  3805. #endif
  3806. static int rtw_cfg80211_add_monitor_if(_adapter *padapter, char *name, struct net_device **ndev)
  3807. {
  3808. int ret = 0;
  3809. struct net_device *mon_ndev = NULL;
  3810. struct wireless_dev *mon_wdev = NULL;
  3811. struct rtw_netdev_priv_indicator *pnpi;
  3812. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  3813. if (!name) {
  3814. RTW_INFO(FUNC_ADPT_FMT" without specific name\n", FUNC_ADPT_ARG(padapter));
  3815. ret = -EINVAL;
  3816. goto out;
  3817. }
  3818. if (pwdev_priv->pmon_ndev) {
  3819. RTW_INFO(FUNC_ADPT_FMT" monitor interface exist: "NDEV_FMT"\n",
  3820. FUNC_ADPT_ARG(padapter), NDEV_ARG(pwdev_priv->pmon_ndev));
  3821. ret = -EBUSY;
  3822. goto out;
  3823. }
  3824. mon_ndev = alloc_etherdev(sizeof(struct rtw_netdev_priv_indicator));
  3825. if (!mon_ndev) {
  3826. RTW_INFO(FUNC_ADPT_FMT" allocate ndev fail\n", FUNC_ADPT_ARG(padapter));
  3827. ret = -ENOMEM;
  3828. goto out;
  3829. }
  3830. mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP;
  3831. strncpy(mon_ndev->name, name, IFNAMSIZ);
  3832. mon_ndev->name[IFNAMSIZ - 1] = 0;
  3833. #if (LINUX_VERSION_CODE > KERNEL_VERSION(4, 11, 8))
  3834. mon_ndev->priv_destructor = rtw_ndev_destructor;
  3835. #else
  3836. mon_ndev->destructor = rtw_ndev_destructor;
  3837. #endif
  3838. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  3839. mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops;
  3840. #else
  3841. mon_ndev->open = rtw_cfg80211_monitor_if_open;
  3842. mon_ndev->stop = rtw_cfg80211_monitor_if_close;
  3843. mon_ndev->hard_start_xmit = rtw_cfg80211_monitor_if_xmit_entry;
  3844. mon_ndev->set_mac_address = rtw_cfg80211_monitor_if_set_mac_address;
  3845. #endif
  3846. pnpi = netdev_priv(mon_ndev);
  3847. pnpi->priv = padapter;
  3848. pnpi->sizeof_priv = sizeof(_adapter);
  3849. /* wdev */
  3850. mon_wdev = (struct wireless_dev *)rtw_zmalloc(sizeof(struct wireless_dev));
  3851. if (!mon_wdev) {
  3852. RTW_INFO(FUNC_ADPT_FMT" allocate mon_wdev fail\n", FUNC_ADPT_ARG(padapter));
  3853. ret = -ENOMEM;
  3854. goto out;
  3855. }
  3856. mon_wdev->wiphy = padapter->rtw_wdev->wiphy;
  3857. mon_wdev->netdev = mon_ndev;
  3858. mon_wdev->iftype = NL80211_IFTYPE_MONITOR;
  3859. mon_ndev->ieee80211_ptr = mon_wdev;
  3860. ret = register_netdevice(mon_ndev);
  3861. if (ret)
  3862. goto out;
  3863. *ndev = pwdev_priv->pmon_ndev = mon_ndev;
  3864. _rtw_memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ + 1);
  3865. out:
  3866. if (ret && mon_wdev) {
  3867. rtw_mfree((u8 *)mon_wdev, sizeof(struct wireless_dev));
  3868. mon_wdev = NULL;
  3869. }
  3870. if (ret && mon_ndev) {
  3871. free_netdev(mon_ndev);
  3872. *ndev = mon_ndev = NULL;
  3873. }
  3874. return ret;
  3875. }
  3876. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  3877. static struct wireless_dev *
  3878. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  3879. static struct net_device *
  3880. #else
  3881. static int
  3882. #endif
  3883. cfg80211_rtw_add_virtual_intf(
  3884. struct wiphy *wiphy,
  3885. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
  3886. const char *name,
  3887. #else
  3888. char *name,
  3889. #endif
  3890. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0))
  3891. unsigned char name_assign_type,
  3892. #endif
  3893. enum nl80211_iftype type,
  3894. #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
  3895. u32 *flags,
  3896. #endif
  3897. struct vif_params *params)
  3898. {
  3899. int ret = 0;
  3900. struct wireless_dev *wdev = NULL;
  3901. struct net_device *ndev = NULL;
  3902. _adapter *padapter;
  3903. struct dvobj_priv *dvobj = wiphy_to_dvobj(wiphy);
  3904. rtw_set_rtnl_lock_holder(dvobj, current);
  3905. RTW_INFO(FUNC_WIPHY_FMT" name:%s, type:%d\n", FUNC_WIPHY_ARG(wiphy), name, type);
  3906. switch (type) {
  3907. case NL80211_IFTYPE_MONITOR:
  3908. padapter = wiphy_to_adapter(wiphy); /* TODO: get ap iface ? */
  3909. ret = rtw_cfg80211_add_monitor_if(padapter, (char *)name, &ndev);
  3910. if (ret == 0)
  3911. wdev = ndev->ieee80211_ptr;
  3912. break;
  3913. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  3914. case NL80211_IFTYPE_P2P_CLIENT:
  3915. case NL80211_IFTYPE_P2P_GO:
  3916. #endif
  3917. case NL80211_IFTYPE_STATION:
  3918. case NL80211_IFTYPE_AP:
  3919. #ifdef CONFIG_RTW_MESH
  3920. case NL80211_IFTYPE_MESH_POINT:
  3921. #endif
  3922. padapter = dvobj_get_unregisterd_adapter(dvobj);
  3923. if (!padapter) {
  3924. RTW_WARN("adapter pool empty!\n");
  3925. ret = -ENODEV;
  3926. break;
  3927. }
  3928. if (rtw_os_ndev_init(padapter, name) != _SUCCESS) {
  3929. RTW_WARN("ndev init fail!\n");
  3930. ret = -ENODEV;
  3931. break;
  3932. }
  3933. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  3934. if (type == NL80211_IFTYPE_P2P_CLIENT || type == NL80211_IFTYPE_P2P_GO)
  3935. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  3936. #endif
  3937. ndev = padapter->pnetdev;
  3938. wdev = ndev->ieee80211_ptr;
  3939. break;
  3940. #if defined(CONFIG_P2P) && defined(RTW_DEDICATED_P2P_DEVICE)
  3941. case NL80211_IFTYPE_P2P_DEVICE:
  3942. ret = rtw_pd_iface_alloc(wiphy, name, &wdev);
  3943. break;
  3944. #endif
  3945. case NL80211_IFTYPE_ADHOC:
  3946. case NL80211_IFTYPE_AP_VLAN:
  3947. case NL80211_IFTYPE_WDS:
  3948. default:
  3949. ret = -ENODEV;
  3950. RTW_INFO("Unsupported interface type\n");
  3951. break;
  3952. }
  3953. if (ndev)
  3954. RTW_INFO(FUNC_WIPHY_FMT" ndev:%p, ret:%d\n", FUNC_WIPHY_ARG(wiphy), ndev, ret);
  3955. else
  3956. RTW_INFO(FUNC_WIPHY_FMT" wdev:%p, ret:%d\n", FUNC_WIPHY_ARG(wiphy), wdev, ret);
  3957. rtw_set_rtnl_lock_holder(dvobj, NULL);
  3958. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  3959. return wdev ? wdev : ERR_PTR(ret);
  3960. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  3961. return ndev ? ndev : ERR_PTR(ret);
  3962. #else
  3963. return ret;
  3964. #endif
  3965. }
  3966. static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy,
  3967. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  3968. struct wireless_dev *wdev
  3969. #else
  3970. struct net_device *ndev
  3971. #endif
  3972. )
  3973. {
  3974. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  3975. struct net_device *ndev = wdev_to_ndev(wdev);
  3976. #endif
  3977. int ret = 0;
  3978. struct dvobj_priv *dvobj = wiphy_to_dvobj(wiphy);
  3979. _adapter *adapter;
  3980. struct rtw_wdev_priv *pwdev_priv;
  3981. rtw_set_rtnl_lock_holder(dvobj, current);
  3982. if (ndev) {
  3983. adapter = (_adapter *)rtw_netdev_priv(ndev);
  3984. pwdev_priv = adapter_wdev_data(adapter);
  3985. if (ndev == pwdev_priv->pmon_ndev) {
  3986. unregister_netdevice(ndev);
  3987. pwdev_priv->pmon_ndev = NULL;
  3988. pwdev_priv->ifname_mon[0] = '\0';
  3989. RTW_INFO(FUNC_NDEV_FMT" remove monitor ndev\n", FUNC_NDEV_ARG(ndev));
  3990. } else {
  3991. RTW_INFO(FUNC_NDEV_FMT" unregister ndev\n", FUNC_NDEV_ARG(ndev));
  3992. rtw_os_ndev_unregister(adapter);
  3993. }
  3994. } else
  3995. #if defined(CONFIG_P2P) && defined(RTW_DEDICATED_P2P_DEVICE)
  3996. if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
  3997. if (wdev == wiphy_to_pd_wdev(wiphy))
  3998. rtw_pd_iface_free(wiphy);
  3999. else {
  4000. RTW_ERR(FUNC_WIPHY_FMT" unknown P2P Device wdev:%p\n", FUNC_WIPHY_ARG(wiphy), wdev);
  4001. rtw_warn_on(1);
  4002. }
  4003. } else
  4004. #endif
  4005. {
  4006. ret = -EINVAL;
  4007. goto exit;
  4008. }
  4009. exit:
  4010. rtw_set_rtnl_lock_holder(dvobj, NULL);
  4011. return ret;
  4012. }
  4013. static int rtw_add_beacon(_adapter *adapter, const u8 *head, size_t head_len, const u8 *tail, size_t tail_len)
  4014. {
  4015. int ret = 0;
  4016. u8 *pbuf = NULL;
  4017. uint len, wps_ielen = 0;
  4018. uint p2p_ielen = 0;
  4019. u8 got_p2p_ie = _FALSE;
  4020. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  4021. /* struct sta_priv *pstapriv = &padapter->stapriv; */
  4022. RTW_INFO("%s beacon_head_len=%zu, beacon_tail_len=%zu\n", __FUNCTION__, head_len, tail_len);
  4023. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  4024. return -EINVAL;
  4025. if (head_len < 24)
  4026. return -EINVAL;
  4027. #ifdef CONFIG_FW_HANDLE_TXBCN
  4028. if (!rtw_ap_nums_check(adapter)) {
  4029. RTW_ERR(FUNC_ADPT_FMT"failed, con't support over %d BCN\n", FUNC_ADPT_ARG(adapter), CONFIG_LIMITED_AP_NUM);
  4030. return -EINVAL;
  4031. }
  4032. #endif /*CONFIG_FW_HANDLE_TXBCN*/
  4033. pbuf = rtw_zmalloc(head_len + tail_len);
  4034. if (!pbuf)
  4035. return -ENOMEM;
  4036. /* _rtw_memcpy(&pstapriv->max_num_sta, param->u.bcn_ie.reserved, 2); */
  4037. /* if((pstapriv->max_num_sta>NUM_STA) || (pstapriv->max_num_sta<=0)) */
  4038. /* pstapriv->max_num_sta = NUM_STA; */
  4039. _rtw_memcpy(pbuf, (void *)head + 24, head_len - 24); /* 24=beacon header len. */
  4040. _rtw_memcpy(pbuf + head_len - 24, (void *)tail, tail_len);
  4041. len = head_len + tail_len - 24;
  4042. /* check wps ie if inclued */
  4043. if (rtw_get_wps_ie(pbuf + _FIXED_IE_LENGTH_, len - _FIXED_IE_LENGTH_, NULL, &wps_ielen))
  4044. RTW_INFO("add bcn, wps_ielen=%d\n", wps_ielen);
  4045. #ifdef CONFIG_P2P
  4046. if (adapter->wdinfo.driver_interface == DRIVER_CFG80211) {
  4047. /* check p2p if enable */
  4048. if (rtw_get_p2p_ie(pbuf + _FIXED_IE_LENGTH_, len - _FIXED_IE_LENGTH_, NULL, &p2p_ielen)) {
  4049. struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
  4050. RTW_INFO("got p2p_ie, len=%d\n", p2p_ielen);
  4051. got_p2p_ie = _TRUE;
  4052. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  4053. RTW_INFO("Enable P2P function for the first time\n");
  4054. rtw_p2p_enable(adapter, P2P_ROLE_GO);
  4055. adapter->stapriv.expire_to = 3; /* 3x2 = 6 sec in p2p mode */
  4056. } else {
  4057. RTW_INFO("enter GO Mode, p2p_ielen=%d\n", p2p_ielen);
  4058. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  4059. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  4060. pwdinfo->intent = 15;
  4061. }
  4062. }
  4063. }
  4064. #endif /* CONFIG_P2P */
  4065. /* pbss_network->IEs will not include p2p_ie, wfd ie */
  4066. rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, P2P_OUI, 4);
  4067. rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, WFD_OUI, 4);
  4068. if (rtw_check_beacon_data(adapter, pbuf, len) == _SUCCESS) {
  4069. #ifdef CONFIG_P2P
  4070. /* check p2p if enable */
  4071. if (got_p2p_ie == _TRUE) {
  4072. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  4073. struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
  4074. pwdinfo->operating_channel = pmlmeext->cur_channel;
  4075. }
  4076. #endif /* CONFIG_P2P */
  4077. ret = 0;
  4078. } else
  4079. ret = -EINVAL;
  4080. rtw_mfree(pbuf, head_len + tail_len);
  4081. return ret;
  4082. }
  4083. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)) && !defined(COMPAT_KERNEL_RELEASE)
  4084. static int cfg80211_rtw_add_beacon(struct wiphy *wiphy, struct net_device *ndev,
  4085. struct beacon_parameters *info)
  4086. {
  4087. int ret = 0;
  4088. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4089. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4090. if (rtw_cfg80211_sync_iftype(adapter) != _SUCCESS) {
  4091. ret = -ENOTSUPP;
  4092. goto exit;
  4093. }
  4094. rtw_mi_scan_abort(adapter, _TRUE);
  4095. rtw_mi_buddy_set_scan_deny(adapter, 300);
  4096. ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
  4097. exit:
  4098. return ret;
  4099. }
  4100. static int cfg80211_rtw_set_beacon(struct wiphy *wiphy, struct net_device *ndev,
  4101. struct beacon_parameters *info)
  4102. {
  4103. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4104. struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
  4105. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4106. pmlmeext->bstart_bss = _TRUE;
  4107. cfg80211_rtw_add_beacon(wiphy, ndev, info);
  4108. return 0;
  4109. }
  4110. static int cfg80211_rtw_del_beacon(struct wiphy *wiphy, struct net_device *ndev)
  4111. {
  4112. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4113. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4114. rtw_set_802_11_infrastructure_mode(adapter, Ndis802_11Infrastructure);
  4115. rtw_setopmode_cmd(adapter, Ndis802_11Infrastructure, RTW_CMDF_WAIT_ACK);
  4116. return 0;
  4117. }
  4118. #else
  4119. static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev,
  4120. struct cfg80211_ap_settings *settings)
  4121. {
  4122. int ret = 0;
  4123. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4124. RTW_INFO(FUNC_NDEV_FMT" hidden_ssid:%d, auth_type:%d\n", FUNC_NDEV_ARG(ndev),
  4125. settings->hidden_ssid, settings->auth_type);
  4126. if (rtw_cfg80211_sync_iftype(adapter) != _SUCCESS) {
  4127. ret = -ENOTSUPP;
  4128. goto exit;
  4129. }
  4130. rtw_mi_scan_abort(adapter, _TRUE);
  4131. rtw_mi_buddy_set_scan_deny(adapter, 300);
  4132. ret = rtw_add_beacon(adapter, settings->beacon.head, settings->beacon.head_len,
  4133. settings->beacon.tail, settings->beacon.tail_len);
  4134. adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode = settings->hidden_ssid;
  4135. if (settings->ssid && settings->ssid_len) {
  4136. WLAN_BSSID_EX *pbss_network = &adapter->mlmepriv.cur_network.network;
  4137. WLAN_BSSID_EX *pbss_network_ext = &adapter->mlmeextpriv.mlmext_info.network;
  4138. if (0)
  4139. RTW_INFO(FUNC_ADPT_FMT" ssid:(%s,%zu), from ie:(%s,%d)\n", FUNC_ADPT_ARG(adapter),
  4140. settings->ssid, settings->ssid_len,
  4141. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength);
  4142. _rtw_memcpy(pbss_network->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len);
  4143. pbss_network->Ssid.SsidLength = settings->ssid_len;
  4144. _rtw_memcpy(pbss_network_ext->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len);
  4145. pbss_network_ext->Ssid.SsidLength = settings->ssid_len;
  4146. if (0)
  4147. RTW_INFO(FUNC_ADPT_FMT" after ssid:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
  4148. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
  4149. pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
  4150. }
  4151. exit:
  4152. return ret;
  4153. }
  4154. static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
  4155. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0))
  4156. struct cfg80211_ap_update *info)
  4157. #else
  4158. struct cfg80211_beacon_data *info)
  4159. #endif
  4160. {
  4161. int ret = 0;
  4162. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4163. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4164. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0))
  4165. ret = rtw_add_beacon(adapter, info->beacon.head, info->beacon.head_len, info->beacon.tail, info->beacon.tail_len);
  4166. #else
  4167. ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
  4168. #endif
  4169. return ret;
  4170. }
  4171. #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 2)
  4172. static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
  4173. #else
  4174. static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev, unsigned int link_id)
  4175. #endif
  4176. {
  4177. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4178. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4179. rtw_set_802_11_infrastructure_mode(adapter, Ndis802_11Infrastructure);
  4180. rtw_setopmode_cmd(adapter, Ndis802_11Infrastructure, RTW_CMDF_WAIT_ACK);
  4181. return 0;
  4182. }
  4183. #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)) */
  4184. #if CONFIG_RTW_MACADDR_ACL && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  4185. static int cfg80211_rtw_set_mac_acl(struct wiphy *wiphy, struct net_device *ndev,
  4186. const struct cfg80211_acl_data *params)
  4187. {
  4188. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4189. u8 acl_mode = RTW_ACL_MODE_DISABLED;
  4190. int ret = -1;
  4191. int i;
  4192. if (!params) {
  4193. RTW_WARN(FUNC_ADPT_FMT" params NULL\n", FUNC_ADPT_ARG(adapter));
  4194. rtw_macaddr_acl_clear(adapter, RTW_ACL_PERIOD_BSS);
  4195. goto exit;
  4196. }
  4197. RTW_INFO(FUNC_ADPT_FMT" acl_policy:%d, entry_num:%d\n"
  4198. , FUNC_ADPT_ARG(adapter), params->acl_policy, params->n_acl_entries);
  4199. if (params->acl_policy == NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED)
  4200. acl_mode = RTW_ACL_MODE_ACCEPT_UNLESS_LISTED;
  4201. else if (params->acl_policy == NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
  4202. acl_mode = RTW_ACL_MODE_DENY_UNLESS_LISTED;
  4203. rtw_macaddr_acl_clear(adapter, RTW_ACL_PERIOD_BSS);
  4204. rtw_set_macaddr_acl(adapter, RTW_ACL_PERIOD_BSS, acl_mode);
  4205. for (i = 0; i < params->n_acl_entries; i++)
  4206. rtw_acl_add_sta(adapter, RTW_ACL_PERIOD_BSS, params->mac_addrs[i].addr);
  4207. ret = 0;
  4208. exit:
  4209. return ret;
  4210. }
  4211. #endif /* CONFIG_RTW_MACADDR_ACL && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)) */
  4212. const char *_nl80211_sta_flags_str[] = {
  4213. "INVALID",
  4214. "AUTHORIZED",
  4215. "SHORT_PREAMBLE",
  4216. "WME",
  4217. "MFP",
  4218. "AUTHENTICATED",
  4219. "TDLS_PEER",
  4220. "ASSOCIATED",
  4221. };
  4222. #define nl80211_sta_flags_str(_f) ((_f <= NL80211_STA_FLAG_MAX) ? _nl80211_sta_flags_str[_f] : _nl80211_sta_flags_str[0])
  4223. const char *_nl80211_plink_state_str[] = {
  4224. "LISTEN",
  4225. "OPN_SNT",
  4226. "OPN_RCVD",
  4227. "CNF_RCVD",
  4228. "ESTAB",
  4229. "HOLDING",
  4230. "BLOCKED",
  4231. "UNKNOWN",
  4232. };
  4233. #define nl80211_plink_state_str(_s) ((_s < NUM_NL80211_PLINK_STATES) ? _nl80211_plink_state_str[_s] : _nl80211_plink_state_str[NUM_NL80211_PLINK_STATES])
  4234. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0))
  4235. #define NL80211_PLINK_ACTION_NO_ACTION PLINK_ACTION_INVALID
  4236. #define NL80211_PLINK_ACTION_OPEN PLINK_ACTION_OPEN
  4237. #define NL80211_PLINK_ACTION_BLOCK PLINK_ACTION_BLOCK
  4238. #define NUM_NL80211_PLINK_ACTIONS 3
  4239. #endif
  4240. const char *_nl80211_plink_actions_str[] = {
  4241. "NO_ACTION",
  4242. "OPEN",
  4243. "BLOCK",
  4244. "UNKNOWN",
  4245. };
  4246. #define nl80211_plink_actions_str(_a) ((_a < NUM_NL80211_PLINK_ACTIONS) ? _nl80211_plink_actions_str[_a] : _nl80211_plink_actions_str[NUM_NL80211_PLINK_ACTIONS])
  4247. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  4248. const char *_nl80211_mesh_power_mode_str[] = {
  4249. "UNKNOWN",
  4250. "ACTIVE",
  4251. "LIGHT_SLEEP",
  4252. "DEEP_SLEEP",
  4253. };
  4254. #define nl80211_mesh_power_mode_str(_p) ((_p <= NL80211_MESH_POWER_MAX) ? _nl80211_mesh_power_mode_str[_p] : _nl80211_mesh_power_mode_str[0])
  4255. #endif
  4256. void dump_station_parameters(void *sel, struct wiphy *wiphy, const struct station_parameters *params)
  4257. {
  4258. #if DBG_RTW_CFG80211_STA_PARAM
  4259. if (params->supported_rates_len) {
  4260. #define SUPP_RATES_BUF_LEN (3 * RTW_G_RATES_NUM + 1)
  4261. int i;
  4262. char supp_rates_buf[SUPP_RATES_BUF_LEN] = {0};
  4263. u8 cnt = 0;
  4264. rtw_warn_on(params->supported_rates_len > RTW_G_RATES_NUM);
  4265. for (i = 0; i < params->supported_rates_len; i++) {
  4266. if (i >= RTW_G_RATES_NUM)
  4267. break;
  4268. cnt += snprintf(supp_rates_buf + cnt, SUPP_RATES_BUF_LEN - cnt -1
  4269. , "%02X ", params->supported_rates[i]);
  4270. if (cnt >= SUPP_RATES_BUF_LEN - 1)
  4271. break;
  4272. }
  4273. RTW_PRINT_SEL(sel, "supported_rates:%s\n", supp_rates_buf);
  4274. }
  4275. if (params->vlan)
  4276. RTW_PRINT_SEL(sel, "vlan:"NDEV_FMT"\n", NDEV_ARG(params->vlan));
  4277. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
  4278. if (params->sta_flags_mask) {
  4279. #define STA_FLAGS_BUF_LEN 128
  4280. int i = 0;
  4281. char sta_flags_buf[STA_FLAGS_BUF_LEN] = {0};
  4282. u8 cnt = 0;
  4283. for (i = 1; i <= NL80211_STA_FLAG_MAX; i++) {
  4284. if (params->sta_flags_mask & BIT(i)) {
  4285. cnt += snprintf(sta_flags_buf + cnt, STA_FLAGS_BUF_LEN - cnt -1, "%s=%u "
  4286. , nl80211_sta_flags_str(i), (params->sta_flags_set & BIT(i)) ? 1 : 0);
  4287. if (cnt >= STA_FLAGS_BUF_LEN - 1)
  4288. break;
  4289. }
  4290. }
  4291. RTW_PRINT_SEL(sel, "sta_flags:%s\n", sta_flags_buf);
  4292. }
  4293. #else
  4294. u32 station_flags;
  4295. #error "TBD\n"
  4296. #endif
  4297. if (params->listen_interval != -1)
  4298. RTW_PRINT_SEL(sel, "listen_interval:%d\n", params->listen_interval);
  4299. if (params->aid)
  4300. RTW_PRINT_SEL(sel, "aid:%u\n", params->aid);
  4301. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
  4302. if (params->peer_aid)
  4303. RTW_PRINT_SEL(sel, "peer_aid:%u\n", params->peer_aid);
  4304. #endif
  4305. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26))
  4306. if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
  4307. RTW_PRINT_SEL(sel, "plink_action:%s\n", nl80211_plink_actions_str(params->plink_action));
  4308. #endif
  4309. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  4310. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  4311. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  4312. #endif
  4313. RTW_PRINT_SEL(sel, "plink_state:%s\n"
  4314. , nl80211_plink_state_str(params->plink_state));
  4315. #endif
  4316. #if 0 /* TODO */
  4317. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
  4318. const struct ieee80211_ht_cap *ht_capa;
  4319. #endif
  4320. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  4321. const struct ieee80211_vht_cap *vht_capa;
  4322. #endif
  4323. #endif
  4324. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  4325. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
  4326. RTW_PRINT_SEL(sel, "uapsd_queues:0x%02x\n", params->uapsd_queues);
  4327. if (params->max_sp)
  4328. RTW_PRINT_SEL(sel, "max_sp:%u\n", params->max_sp);
  4329. #endif
  4330. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  4331. if (params->local_pm != NL80211_MESH_POWER_UNKNOWN) {
  4332. RTW_PRINT_SEL(sel, "local_pm:%s\n"
  4333. , nl80211_mesh_power_mode_str(params->local_pm));
  4334. }
  4335. if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
  4336. RTW_PRINT_SEL(sel, "capability:0x%04x\n", params->capability);
  4337. #if 0 /* TODO */
  4338. const u8 *ext_capab;
  4339. u8 ext_capab_len;
  4340. #endif
  4341. #endif
  4342. #if 0 /* TODO */
  4343. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
  4344. const u8 *supported_channels;
  4345. u8 supported_channels_len;
  4346. const u8 *supported_oper_classes;
  4347. u8 supported_oper_classes_len;
  4348. #endif
  4349. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
  4350. u8 opmode_notif;
  4351. bool opmode_notif_used;
  4352. #endif
  4353. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
  4354. int support_p2p_ps;
  4355. #endif
  4356. #endif
  4357. #endif /* DBG_RTW_CFG80211_STA_PARAM */
  4358. }
  4359. static int cfg80211_rtw_add_station(struct wiphy *wiphy, struct net_device *ndev,
  4360. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0))
  4361. u8 *mac,
  4362. #else
  4363. const u8 *mac,
  4364. #endif
  4365. struct station_parameters *params)
  4366. {
  4367. int ret = 0;
  4368. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  4369. #if defined(CONFIG_TDLS) || defined(CONFIG_RTW_MESH)
  4370. struct sta_priv *pstapriv = &padapter->stapriv;
  4371. #endif
  4372. #ifdef CONFIG_TDLS
  4373. struct sta_info *psta;
  4374. #endif /* CONFIG_TDLS */
  4375. RTW_INFO(FUNC_NDEV_FMT" mac:"MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
  4376. #if CONFIG_RTW_MACADDR_ACL
  4377. if (rtw_access_ctrl(padapter, mac) == _FALSE) {
  4378. RTW_INFO(FUNC_NDEV_FMT" deny by macaddr ACL\n", FUNC_NDEV_ARG(ndev));
  4379. ret = -EINVAL;
  4380. goto exit;
  4381. }
  4382. #endif
  4383. dump_station_parameters(RTW_DBGDUMP, wiphy, params);
  4384. #ifdef CONFIG_RTW_MESH
  4385. if (MLME_IS_MESH(padapter)) {
  4386. struct rtw_mesh_cfg *mcfg = &padapter->mesh_cfg;
  4387. struct rtw_mesh_info *minfo = &padapter->mesh_info;
  4388. struct mesh_plink_pool *plink_ctl = &minfo->plink_ctl;
  4389. struct mesh_plink_ent *plink = NULL;
  4390. struct wlan_network *scanned = NULL;
  4391. bool acnode = 0;
  4392. u8 add_new_sta = 0, probe_req = 0;
  4393. _irqL irqL;
  4394. if (params->plink_state != NL80211_PLINK_LISTEN) {
  4395. RTW_WARN(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(ndev), nl80211_plink_state_str(params->plink_state));
  4396. rtw_warn_on(1);
  4397. }
  4398. if (!params->aid || params->aid > pstapriv->max_aid) {
  4399. RTW_WARN(FUNC_NDEV_FMT" invalid aid:%u\n", FUNC_NDEV_ARG(ndev), params->aid);
  4400. rtw_warn_on(1);
  4401. ret = -EINVAL;
  4402. goto exit;
  4403. }
  4404. _enter_critical_bh(&(plink_ctl->lock), &irqL);
  4405. plink = _rtw_mesh_plink_get(padapter, mac);
  4406. if (plink)
  4407. goto release_plink_ctl;
  4408. #if CONFIG_RTW_MESH_PEER_BLACKLIST
  4409. if (rtw_mesh_peer_blacklist_search(padapter, mac)) {
  4410. RTW_INFO(FUNC_NDEV_FMT" deny by peer blacklist\n"
  4411. , FUNC_NDEV_ARG(ndev));
  4412. ret = -EINVAL;
  4413. goto release_plink_ctl;
  4414. }
  4415. #endif
  4416. scanned = rtw_find_network(&padapter->mlmepriv.scanned_queue, mac);
  4417. if (!scanned
  4418. || rtw_get_passing_time_ms(scanned->last_scanned) >= mcfg->peer_sel_policy.scanr_exp_ms
  4419. ) {
  4420. if (!scanned)
  4421. RTW_INFO(FUNC_NDEV_FMT" corresponding network not found\n", FUNC_NDEV_ARG(ndev));
  4422. else
  4423. RTW_INFO(FUNC_NDEV_FMT" corresponding network too old\n", FUNC_NDEV_ARG(ndev));
  4424. if (adapter_to_rfctl(padapter)->offch_state == OFFCHS_NONE)
  4425. probe_req = 1;
  4426. ret = -EINVAL;
  4427. goto release_plink_ctl;
  4428. }
  4429. #if CONFIG_RTW_MESH_ACNODE_PREVENT
  4430. if (plink_ctl->acnode_rsvd)
  4431. acnode = rtw_mesh_scanned_is_acnode_confirmed(padapter, scanned);
  4432. #endif
  4433. /* wpa_supplicant's auto peer will initiate peering when candidate peer is reported without max_peer_links consideration */
  4434. if (plink_ctl->num >= mcfg->max_peer_links + acnode ? 1 : 0) {
  4435. RTW_INFO(FUNC_NDEV_FMT" exceed max_peer_links:%u%s\n"
  4436. , FUNC_NDEV_ARG(ndev), mcfg->max_peer_links, acnode ? " acn" : "");
  4437. ret = -EINVAL;
  4438. goto release_plink_ctl;
  4439. }
  4440. if (!rtw_bss_is_candidate_mesh_peer(&padapter->mlmepriv.cur_network.network, &scanned->network, 1, 1)) {
  4441. RTW_WARN(FUNC_NDEV_FMT" corresponding network is not candidate with same ch\n"
  4442. , FUNC_NDEV_ARG(ndev));
  4443. ret = -EINVAL;
  4444. goto release_plink_ctl;
  4445. }
  4446. #if CONFIG_RTW_MESH_CTO_MGATE_BLACKLIST
  4447. if (!rtw_mesh_cto_mgate_network_filter(padapter, scanned)) {
  4448. RTW_INFO(FUNC_NDEV_FMT" peer filtered out by cto_mgate check\n"
  4449. , FUNC_NDEV_ARG(ndev));
  4450. ret = -EINVAL;
  4451. goto release_plink_ctl;
  4452. }
  4453. #endif
  4454. if (_rtw_mesh_plink_add(padapter, mac) == _SUCCESS) {
  4455. /* hook corresponding network in scan queue */
  4456. plink = _rtw_mesh_plink_get(padapter, mac);
  4457. plink->aid = params->aid;
  4458. plink->scanned = scanned;
  4459. #if CONFIG_RTW_MESH_ACNODE_PREVENT
  4460. if (acnode) {
  4461. RTW_INFO(FUNC_ADPT_FMT" acnode "MAC_FMT"\n"
  4462. , FUNC_ADPT_ARG(padapter), MAC_ARG(scanned->network.MacAddress));
  4463. }
  4464. #endif
  4465. add_new_sta = 1;
  4466. } else {
  4467. RTW_WARN(FUNC_NDEV_FMT" rtw_mesh_plink_add not success\n"
  4468. , FUNC_NDEV_ARG(ndev));
  4469. ret = -EINVAL;
  4470. }
  4471. release_plink_ctl:
  4472. _exit_critical_bh(&(plink_ctl->lock), &irqL);
  4473. if (probe_req)
  4474. issue_probereq(padapter, &padapter->mlmepriv.cur_network.network.mesh_id, mac);
  4475. if (add_new_sta) {
  4476. struct station_info sinfo;
  4477. #ifdef CONFIG_DFS_MASTER
  4478. if (IS_UNDER_CAC(adapter_to_rfctl(padapter)))
  4479. rtw_force_stop_cac(adapter_to_rfctl(padapter), 300);
  4480. #endif
  4481. /* indicate new sta */
  4482. _rtw_memset(&sinfo, 0, sizeof(sinfo));
  4483. cfg80211_new_sta(ndev, mac, &sinfo, GFP_ATOMIC);
  4484. }
  4485. goto exit;
  4486. }
  4487. #endif /* CONFIG_RTW_MESH */
  4488. #ifdef CONFIG_TDLS
  4489. psta = rtw_get_stainfo(pstapriv, (u8 *)mac);
  4490. if (psta == NULL) {
  4491. psta = rtw_alloc_stainfo(pstapriv, (u8 *)mac);
  4492. if (psta == NULL) {
  4493. RTW_INFO("[%s] Alloc station for "MAC_FMT" fail\n", __FUNCTION__, MAC_ARG(mac));
  4494. ret = -EOPNOTSUPP;
  4495. goto exit;
  4496. }
  4497. }
  4498. #endif /* CONFIG_TDLS */
  4499. exit:
  4500. return ret;
  4501. }
  4502. static int cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev,
  4503. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0))
  4504. u8 *mac
  4505. #elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0))
  4506. const u8 *mac
  4507. #else
  4508. struct station_del_parameters *params
  4509. #endif
  4510. )
  4511. {
  4512. int ret = 0;
  4513. _irqL irqL;
  4514. _list *phead, *plist;
  4515. u8 updated = _FALSE;
  4516. const u8 *target_mac;
  4517. struct sta_info *psta = NULL;
  4518. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  4519. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  4520. struct sta_priv *pstapriv = &padapter->stapriv;
  4521. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0))
  4522. target_mac = mac;
  4523. #else
  4524. target_mac = params->mac;
  4525. #endif
  4526. RTW_INFO("+"FUNC_NDEV_FMT" mac=%pM\n", FUNC_NDEV_ARG(ndev), target_mac);
  4527. if (check_fwstate(pmlmepriv, (_FW_LINKED | WIFI_AP_STATE | WIFI_MESH_STATE)) != _TRUE) {
  4528. RTW_INFO("%s, fw_state != FW_LINKED|WIFI_AP_STATE|WIFI_MESH_STATE\n", __func__);
  4529. return -EINVAL;
  4530. }
  4531. if (!target_mac) {
  4532. RTW_INFO("flush all sta, and cam_entry\n");
  4533. flush_all_cam_entry(padapter); /* clear CAM */
  4534. #ifdef CONFIG_AP_MODE
  4535. ret = rtw_sta_flush(padapter, _TRUE);
  4536. #endif
  4537. return ret;
  4538. }
  4539. RTW_INFO("free sta macaddr =" MAC_FMT "\n", MAC_ARG(target_mac));
  4540. if (target_mac[0] == 0xff && target_mac[1] == 0xff &&
  4541. target_mac[2] == 0xff && target_mac[3] == 0xff &&
  4542. target_mac[4] == 0xff && target_mac[5] == 0xff)
  4543. return -EINVAL;
  4544. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  4545. phead = &pstapriv->asoc_list;
  4546. plist = get_next(phead);
  4547. /* check asoc_queue */
  4548. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  4549. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  4550. plist = get_next(plist);
  4551. if (_rtw_memcmp((u8 *)target_mac, psta->cmn.mac_addr, ETH_ALEN)) {
  4552. if (psta->dot8021xalg == 1 && psta->bpairwise_key_installed == _FALSE)
  4553. RTW_INFO("%s, sta's dot8021xalg = 1 and key_installed = _FALSE\n", __func__);
  4554. else {
  4555. RTW_INFO("free psta=%p, aid=%d\n", psta, psta->cmn.aid);
  4556. rtw_list_delete(&psta->asoc_list);
  4557. pstapriv->asoc_list_cnt--;
  4558. STA_SET_MESH_PLINK(psta, NULL);
  4559. /* _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL); */
  4560. if (MLME_IS_AP(padapter))
  4561. updated = ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_PREV_AUTH_NOT_VALID, _TRUE);
  4562. else
  4563. updated = ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
  4564. /* _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL); */
  4565. psta = NULL;
  4566. break;
  4567. }
  4568. }
  4569. }
  4570. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  4571. associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
  4572. #ifdef CONFIG_RTW_MESH
  4573. if (MLME_IS_MESH(padapter))
  4574. rtw_mesh_plink_del(padapter, target_mac);
  4575. #endif
  4576. RTW_INFO("-"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4577. return ret;
  4578. }
  4579. static int cfg80211_rtw_change_station(struct wiphy *wiphy, struct net_device *ndev,
  4580. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0))
  4581. u8 *mac,
  4582. #else
  4583. const u8 *mac,
  4584. #endif
  4585. struct station_parameters *params)
  4586. {
  4587. #ifdef CONFIG_RTW_MESH
  4588. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4589. struct sta_priv *stapriv = &adapter->stapriv;
  4590. struct sta_info *sta = NULL;
  4591. _irqL irqL;
  4592. #endif
  4593. int ret = 0;
  4594. RTW_INFO(FUNC_NDEV_FMT" mac:"MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
  4595. dump_station_parameters(RTW_DBGDUMP, wiphy, params);
  4596. #ifdef CONFIG_RTW_MESH
  4597. if (MLME_IS_MESH(adapter)) {
  4598. enum cfg80211_station_type sta_type = CFG80211_STA_MESH_PEER_USER;
  4599. struct rtw_mesh_info *minfo = &adapter->mesh_info;
  4600. struct mesh_plink_pool *plink_ctl = &minfo->plink_ctl;
  4601. struct mesh_plink_ent *plink = NULL;
  4602. _irqL irqL2;
  4603. struct sta_info *del_sta = NULL;
  4604. ret = cfg80211_check_station_change(wiphy, params, sta_type);
  4605. if (ret) {
  4606. RTW_INFO("cfg80211_check_station_change return %d\n", ret);
  4607. goto exit;
  4608. }
  4609. _enter_critical_bh(&(plink_ctl->lock), &irqL2);
  4610. plink = _rtw_mesh_plink_get(adapter, mac);
  4611. if (!plink) {
  4612. ret = -ENOENT;
  4613. goto release_plink_ctl;
  4614. }
  4615. plink->plink_state = nl80211_plink_state_to_rtw_plink_state(params->plink_state);
  4616. #if CONFIG_RTW_MESH_ACNODE_PREVENT
  4617. if (params->plink_state == NL80211_PLINK_OPN_SNT
  4618. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  4619. && (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  4620. #endif
  4621. ) {
  4622. if (rtw_mesh_scanned_is_acnode_confirmed(adapter, plink->scanned)
  4623. && rtw_mesh_acnode_prevent_allow_sacrifice(adapter)
  4624. ) {
  4625. struct sta_info *sac = rtw_mesh_acnode_prevent_pick_sacrifice(adapter);
  4626. if (sac) {
  4627. del_sta = sac;
  4628. _enter_critical_bh(&stapriv->asoc_list_lock, &irqL);
  4629. if (!rtw_is_list_empty(&del_sta->asoc_list)) {
  4630. rtw_list_delete(&del_sta->asoc_list);
  4631. stapriv->asoc_list_cnt--;
  4632. STA_SET_MESH_PLINK(del_sta, NULL);
  4633. }
  4634. _exit_critical_bh(&stapriv->asoc_list_lock, &irqL);
  4635. RTW_INFO(FUNC_ADPT_FMT" sacrifice "MAC_FMT" for acnode\n"
  4636. , FUNC_ADPT_ARG(adapter), MAC_ARG(del_sta->cmn.mac_addr));
  4637. }
  4638. }
  4639. } else
  4640. #endif
  4641. if ((params->plink_state == NL80211_PLINK_OPN_RCVD
  4642. || params->plink_state == NL80211_PLINK_CNF_RCVD
  4643. || params->plink_state == NL80211_PLINK_ESTAB)
  4644. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  4645. && (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  4646. #endif
  4647. ) {
  4648. sta = rtw_get_stainfo(stapriv, mac);
  4649. if (!sta) {
  4650. sta = rtw_alloc_stainfo(stapriv, mac);
  4651. if (!sta)
  4652. goto release_plink_ctl;
  4653. }
  4654. if (params->plink_state == NL80211_PLINK_ESTAB) {
  4655. if (rtw_mesh_peer_establish(adapter, plink, sta) != _SUCCESS) {
  4656. rtw_free_stainfo(adapter, sta);
  4657. ret = -ENOENT;
  4658. goto release_plink_ctl;
  4659. }
  4660. }
  4661. }
  4662. else if (params->plink_state == NL80211_PLINK_HOLDING
  4663. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  4664. && (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  4665. #endif
  4666. ) {
  4667. del_sta = rtw_get_stainfo(stapriv, mac);
  4668. if (!del_sta)
  4669. goto release_plink_ctl;
  4670. _enter_critical_bh(&stapriv->asoc_list_lock, &irqL);
  4671. if (!rtw_is_list_empty(&del_sta->asoc_list)) {
  4672. rtw_list_delete(&del_sta->asoc_list);
  4673. stapriv->asoc_list_cnt--;
  4674. STA_SET_MESH_PLINK(del_sta, NULL);
  4675. }
  4676. _exit_critical_bh(&stapriv->asoc_list_lock, &irqL);
  4677. }
  4678. release_plink_ctl:
  4679. _exit_critical_bh(&(plink_ctl->lock), &irqL2);
  4680. if (del_sta) {
  4681. u8 sta_addr[ETH_ALEN];
  4682. u8 updated = _FALSE;
  4683. _rtw_memcpy(sta_addr, del_sta->cmn.mac_addr, ETH_ALEN);
  4684. updated = ap_free_sta(adapter, del_sta, 0, 0, 1);
  4685. rtw_mesh_expire_peer(stapriv->padapter, sta_addr);
  4686. associated_clients_update(adapter, updated, STA_INFO_UPDATE_ALL);
  4687. }
  4688. }
  4689. #endif /* CONFIG_RTW_MESH */
  4690. exit:
  4691. return ret;
  4692. }
  4693. struct sta_info *rtw_sta_info_get_by_idx(struct sta_priv *pstapriv, const int idx, u8 *asoc_list_num)
  4694. {
  4695. _list *phead, *plist;
  4696. struct sta_info *psta = NULL;
  4697. int i = 0;
  4698. phead = &pstapriv->asoc_list;
  4699. plist = get_next(phead);
  4700. /* check asoc_queue */
  4701. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  4702. if (idx == i)
  4703. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  4704. plist = get_next(plist);
  4705. i++;
  4706. }
  4707. if (asoc_list_num)
  4708. *asoc_list_num = i;
  4709. return psta;
  4710. }
  4711. static int cfg80211_rtw_dump_station(struct wiphy *wiphy, struct net_device *ndev,
  4712. int idx, u8 *mac, struct station_info *sinfo)
  4713. {
  4714. #define DBG_DUMP_STATION 0
  4715. int ret = 0;
  4716. _irqL irqL;
  4717. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  4718. struct sta_priv *pstapriv = &padapter->stapriv;
  4719. struct sta_info *psta = NULL;
  4720. #ifdef CONFIG_RTW_MESH
  4721. struct mesh_plink_ent *plink = NULL;
  4722. #endif
  4723. u8 asoc_list_num;
  4724. if (DBG_DUMP_STATION)
  4725. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4726. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  4727. psta = rtw_sta_info_get_by_idx(pstapriv, idx, &asoc_list_num);
  4728. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  4729. #ifdef CONFIG_RTW_MESH
  4730. if (MLME_IS_MESH(padapter)) {
  4731. if (psta)
  4732. plink = psta->plink;
  4733. if (!plink)
  4734. plink = rtw_mesh_plink_get_no_estab_by_idx(padapter, idx - asoc_list_num);
  4735. }
  4736. #endif /* CONFIG_RTW_MESH */
  4737. if ((!MLME_IS_MESH(padapter) && !psta)
  4738. #ifdef CONFIG_RTW_MESH
  4739. || (MLME_IS_MESH(padapter) && !plink)
  4740. #endif
  4741. ) {
  4742. if (DBG_DUMP_STATION)
  4743. RTW_INFO(FUNC_NDEV_FMT" end with idx:%d\n", FUNC_NDEV_ARG(ndev), idx);
  4744. ret = -ENOENT;
  4745. goto exit;
  4746. }
  4747. if (psta)
  4748. _rtw_memcpy(mac, psta->cmn.mac_addr, ETH_ALEN);
  4749. #ifdef CONFIG_RTW_MESH
  4750. else
  4751. _rtw_memcpy(mac, plink->addr, ETH_ALEN);
  4752. #endif
  4753. sinfo->filled = 0;
  4754. if (psta) {
  4755. sinfo->filled |= STATION_INFO_SIGNAL;
  4756. sinfo->signal = translate_percentage_to_dbm(psta->cmn.rssi_stat.rssi);
  4757. sinfo->filled |= STATION_INFO_INACTIVE_TIME;
  4758. sinfo->inactive_time = rtw_get_passing_time_ms(psta->sta_stats.last_rx_time);
  4759. }
  4760. #ifdef CONFIG_RTW_MESH
  4761. if (MLME_IS_MESH(padapter))
  4762. rtw_cfg80211_fill_mesh_only_sta_info(plink, psta, sinfo);
  4763. #endif
  4764. exit:
  4765. return ret;
  4766. }
  4767. static int cfg80211_rtw_change_bss(struct wiphy *wiphy, struct net_device *ndev,
  4768. struct bss_parameters *params)
  4769. {
  4770. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4771. /*
  4772. RTW_INFO("use_cts_prot=%d\n", params->use_cts_prot);
  4773. RTW_INFO("use_short_preamble=%d\n", params->use_short_preamble);
  4774. RTW_INFO("use_short_slot_time=%d\n", params->use_short_slot_time);
  4775. RTW_INFO("ap_isolate=%d\n", params->ap_isolate);
  4776. RTW_INFO("basic_rates_len=%d\n", params->basic_rates_len);
  4777. for(i = 0; i < params->basic_rates_len; i++)
  4778. RTW_INFO("basic_rates=%d\n", params->basic_rates[i]);
  4779. */
  4780. return 0;
  4781. }
  4782. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  4783. static int cfg80211_rtw_set_txq_params(struct wiphy *wiphy
  4784. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  4785. , struct net_device *ndev
  4786. #endif
  4787. , struct ieee80211_txq_params *params)
  4788. {
  4789. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  4790. _adapter *padapter = rtw_netdev_priv(ndev);
  4791. #else
  4792. _adapter *padapter = wiphy_to_adapter(wiphy);
  4793. #endif
  4794. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  4795. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  4796. u8 ac, AIFS, ECWMin, ECWMax, aSifsTime;
  4797. u16 TXOP;
  4798. u8 shift_count = 0;
  4799. u32 acParm;
  4800. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  4801. ac = params->ac;
  4802. #else
  4803. ac = params->queue;
  4804. #endif
  4805. #if 0
  4806. RTW_INFO("ac=%d\n", ac);
  4807. RTW_INFO("txop=%u\n", params->txop);
  4808. RTW_INFO("cwmin=%u\n", params->cwmin);
  4809. RTW_INFO("cwmax=%u\n", params->cwmax);
  4810. RTW_INFO("aifs=%u\n", params->aifs);
  4811. #endif
  4812. if (is_supported_5g(pmlmeext->cur_wireless_mode) ||
  4813. (pmlmeext->cur_wireless_mode & WIRELESS_11_24N))
  4814. aSifsTime = 16;
  4815. else
  4816. aSifsTime = 10;
  4817. AIFS = params->aifs * pmlmeinfo->slotTime + aSifsTime;
  4818. while ((params->cwmin + 1) >> shift_count != 1) {
  4819. shift_count++;
  4820. if (shift_count == 15)
  4821. break;
  4822. }
  4823. ECWMin = shift_count;
  4824. shift_count = 0;
  4825. while ((params->cwmax + 1) >> shift_count != 1) {
  4826. shift_count++;
  4827. if (shift_count == 15)
  4828. break;
  4829. }
  4830. ECWMax = shift_count;
  4831. TXOP = le16_to_cpu(params->txop);
  4832. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  4833. switch (ac) {
  4834. case NL80211_TXQ_Q_VO:
  4835. RTW_INFO(FUNC_NDEV_FMT" AC_VO = 0x%08x\n", FUNC_ADPT_ARG(padapter), acParm);
  4836. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  4837. break;
  4838. case NL80211_TXQ_Q_VI:
  4839. RTW_INFO(FUNC_NDEV_FMT" AC_VI = 0x%08x\n", FUNC_ADPT_ARG(padapter), acParm);
  4840. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  4841. break;
  4842. case NL80211_TXQ_Q_BE:
  4843. RTW_INFO(FUNC_NDEV_FMT" AC_BE = 0x%08x\n", FUNC_ADPT_ARG(padapter), acParm);
  4844. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  4845. break;
  4846. case NL80211_TXQ_Q_BK:
  4847. RTW_INFO(FUNC_NDEV_FMT" AC_BK = 0x%08x\n", FUNC_ADPT_ARG(padapter), acParm);
  4848. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  4849. break;
  4850. default:
  4851. break;
  4852. }
  4853. return 0;
  4854. }
  4855. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)) */
  4856. static int cfg80211_rtw_set_channel(struct wiphy *wiphy
  4857. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  4858. , struct net_device *ndev
  4859. #endif
  4860. , struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
  4861. {
  4862. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  4863. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  4864. #else
  4865. _adapter *padapter = wiphy_to_adapter(wiphy);
  4866. #endif
  4867. int chan_target = (u8) ieee80211_frequency_to_channel(chan->center_freq);
  4868. int chan_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4869. int chan_width = CHANNEL_WIDTH_20;
  4870. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  4871. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4872. #endif
  4873. switch (channel_type) {
  4874. case NL80211_CHAN_NO_HT:
  4875. case NL80211_CHAN_HT20:
  4876. chan_width = CHANNEL_WIDTH_20;
  4877. chan_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4878. break;
  4879. case NL80211_CHAN_HT40MINUS:
  4880. chan_width = CHANNEL_WIDTH_40;
  4881. chan_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  4882. break;
  4883. case NL80211_CHAN_HT40PLUS:
  4884. chan_width = CHANNEL_WIDTH_40;
  4885. chan_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  4886. break;
  4887. default:
  4888. chan_width = CHANNEL_WIDTH_20;
  4889. chan_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4890. break;
  4891. }
  4892. RTW_INFO(FUNC_ADPT_FMT" ch:%d bw:%d, offset:%d\n"
  4893. , FUNC_ADPT_ARG(padapter), chan_target, chan_width, chan_offset);
  4894. rtw_set_chbw_cmd(padapter, chan_target, chan_width, chan_offset, RTW_CMDF_WAIT_ACK);
  4895. return 0;
  4896. }
  4897. static int cfg80211_rtw_set_monitor_channel(struct wiphy *wiphy
  4898. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  4899. , struct cfg80211_chan_def *chandef
  4900. #else
  4901. , struct ieee80211_channel *chan
  4902. , enum nl80211_channel_type channel_type
  4903. #endif
  4904. )
  4905. {
  4906. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  4907. struct ieee80211_channel *chan = chandef->chan;
  4908. #endif
  4909. _adapter *padapter = wiphy_to_adapter(wiphy);
  4910. int target_channal = chan->hw_value;
  4911. int target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4912. int target_width = CHANNEL_WIDTH_20;
  4913. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  4914. #ifdef CONFIG_DEBUG_CFG80211
  4915. RTW_INFO("center_freq %u Mhz ch %u width %u freq1 %u freq2 %u\n"
  4916. , chan->center_freq
  4917. , chan->hw_value
  4918. , chandef->width
  4919. , chandef->center_freq1
  4920. , chandef->center_freq2);
  4921. #endif /* CONFIG_DEBUG_CFG80211 */
  4922. switch (chandef->width) {
  4923. case NL80211_CHAN_WIDTH_20_NOHT:
  4924. case NL80211_CHAN_WIDTH_20:
  4925. target_width = CHANNEL_WIDTH_20;
  4926. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4927. break;
  4928. case NL80211_CHAN_WIDTH_40:
  4929. target_width = CHANNEL_WIDTH_40;
  4930. if (chandef->center_freq1 > chan->center_freq)
  4931. target_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  4932. else
  4933. target_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  4934. break;
  4935. case NL80211_CHAN_WIDTH_80:
  4936. target_width = CHANNEL_WIDTH_80;
  4937. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4938. break;
  4939. case NL80211_CHAN_WIDTH_80P80:
  4940. target_width = CHANNEL_WIDTH_80_80;
  4941. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4942. break;
  4943. case NL80211_CHAN_WIDTH_160:
  4944. target_width = CHANNEL_WIDTH_160;
  4945. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4946. break;
  4947. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  4948. case NL80211_CHAN_WIDTH_5:
  4949. case NL80211_CHAN_WIDTH_10:
  4950. #endif
  4951. default:
  4952. target_width = CHANNEL_WIDTH_20;
  4953. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4954. break;
  4955. }
  4956. #else
  4957. #ifdef CONFIG_DEBUG_CFG80211
  4958. RTW_INFO("center_freq %u Mhz ch %u channel_type %u\n"
  4959. , chan->center_freq
  4960. , chan->hw_value
  4961. , channel_type);
  4962. #endif /* CONFIG_DEBUG_CFG80211 */
  4963. switch (channel_type) {
  4964. case NL80211_CHAN_NO_HT:
  4965. case NL80211_CHAN_HT20:
  4966. target_width = CHANNEL_WIDTH_20;
  4967. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4968. break;
  4969. case NL80211_CHAN_HT40MINUS:
  4970. target_width = CHANNEL_WIDTH_40;
  4971. target_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  4972. break;
  4973. case NL80211_CHAN_HT40PLUS:
  4974. target_width = CHANNEL_WIDTH_40;
  4975. target_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  4976. break;
  4977. default:
  4978. target_width = CHANNEL_WIDTH_20;
  4979. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4980. break;
  4981. }
  4982. #endif
  4983. RTW_INFO(FUNC_ADPT_FMT" ch:%d bw:%d, offset:%d\n"
  4984. , FUNC_ADPT_ARG(padapter), target_channal, target_width, target_offset);
  4985. rtw_set_chbw_cmd(padapter, target_channal, target_width, target_offset, RTW_CMDF_WAIT_ACK);
  4986. return 0;
  4987. }
  4988. static int cfg80211_rtw_auth(struct wiphy *wiphy, struct net_device *ndev,
  4989. struct cfg80211_auth_request *req)
  4990. {
  4991. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4992. return 0;
  4993. }
  4994. static int cfg80211_rtw_assoc(struct wiphy *wiphy, struct net_device *ndev,
  4995. struct cfg80211_assoc_request *req)
  4996. {
  4997. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4998. return 0;
  4999. }
  5000. #endif /* CONFIG_AP_MODE */
  5001. void rtw_cfg80211_rx_probe_request(_adapter *adapter, union recv_frame *rframe)
  5002. {
  5003. struct wireless_dev *wdev = adapter->rtw_wdev;
  5004. u8 *frame = get_recvframe_data(rframe);
  5005. uint frame_len = rframe->u.hdr.len;
  5006. s32 freq;
  5007. u8 ch, sch = rtw_get_oper_ch(adapter);
  5008. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5009. freq = rtw_ch2freq(ch);
  5010. #ifdef CONFIG_DEBUG_CFG80211
  5011. RTW_INFO("RTW_Rx: probe request, ch=%d(%d), ta="MAC_FMT"\n"
  5012. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5013. #endif
  5014. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  5015. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5016. #else
  5017. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5018. #endif
  5019. }
  5020. void rtw_cfg80211_rx_action_p2p(_adapter *adapter, union recv_frame *rframe)
  5021. {
  5022. struct wireless_dev *wdev = adapter->rtw_wdev;
  5023. u8 *frame = get_recvframe_data(rframe);
  5024. uint frame_len = rframe->u.hdr.len;
  5025. s32 freq;
  5026. u8 ch, sch = rtw_get_oper_ch(adapter);
  5027. u8 category, action;
  5028. int type;
  5029. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5030. freq = rtw_ch2freq(ch);
  5031. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n"
  5032. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5033. #ifdef CONFIG_P2P
  5034. type = rtw_p2p_check_frames(adapter, frame, frame_len, _FALSE);
  5035. if (type >= 0)
  5036. goto indicate;
  5037. #endif
  5038. rtw_action_frame_parse(frame, frame_len, &category, &action);
  5039. RTW_INFO("RTW_Rx:category(%u), action(%u)\n", category, action);
  5040. indicate:
  5041. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5042. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5043. #else
  5044. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5045. #endif
  5046. }
  5047. void rtw_cfg80211_rx_p2p_action_public(_adapter *adapter, union recv_frame *rframe)
  5048. {
  5049. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  5050. struct wireless_dev *wdev = adapter->rtw_wdev;
  5051. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
  5052. u8 *frame = get_recvframe_data(rframe);
  5053. uint frame_len = rframe->u.hdr.len;
  5054. s32 freq;
  5055. u8 ch, sch = rtw_get_oper_ch(adapter);
  5056. u8 category, action;
  5057. int type;
  5058. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5059. freq = rtw_ch2freq(ch);
  5060. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n"
  5061. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5062. #ifdef CONFIG_P2P
  5063. type = rtw_p2p_check_frames(adapter, frame, frame_len, _FALSE);
  5064. if (type >= 0) {
  5065. switch (type) {
  5066. case P2P_GO_NEGO_CONF:
  5067. if (0) {
  5068. RTW_INFO(FUNC_ADPT_FMT" Nego confirm. state=%u, status=%u, iaddr="MAC_FMT"\n"
  5069. , FUNC_ADPT_ARG(adapter), pwdev_priv->nego_info.state, pwdev_priv->nego_info.status
  5070. , MAC_ARG(pwdev_priv->nego_info.iface_addr));
  5071. }
  5072. if (pwdev_priv->nego_info.state == 2
  5073. && pwdev_priv->nego_info.status == 0
  5074. && rtw_check_invalid_mac_address(pwdev_priv->nego_info.iface_addr, _FALSE) == _FALSE
  5075. ) {
  5076. _adapter *intended_iface = dvobj_get_adapter_by_addr(dvobj, pwdev_priv->nego_info.iface_addr);
  5077. if (intended_iface) {
  5078. RTW_INFO(FUNC_ADPT_FMT" Nego confirm. Allow only "ADPT_FMT" to scan for 2000 ms\n"
  5079. , FUNC_ADPT_ARG(adapter), ADPT_ARG(intended_iface));
  5080. /* allow only intended_iface to do scan for 2000 ms */
  5081. rtw_mi_set_scan_deny(adapter, 2000);
  5082. rtw_clear_scan_deny(intended_iface);
  5083. }
  5084. }
  5085. break;
  5086. case P2P_PROVISION_DISC_RESP:
  5087. case P2P_INVIT_RESP:
  5088. rtw_clear_scan_deny(adapter);
  5089. #if !RTW_P2P_GROUP_INTERFACE
  5090. rtw_mi_buddy_set_scan_deny(adapter, 2000);
  5091. #endif
  5092. break;
  5093. }
  5094. goto indicate;
  5095. }
  5096. #endif
  5097. rtw_action_frame_parse(frame, frame_len, &category, &action);
  5098. RTW_INFO("RTW_Rx:category(%u), action(%u)\n", category, action);
  5099. indicate:
  5100. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5101. if (rtw_cfg80211_redirect_pd_wdev(dvobj_to_wiphy(dvobj), get_ra(frame), &wdev))
  5102. if (0)
  5103. RTW_INFO("redirect to pd_wdev:%p\n", wdev);
  5104. #endif
  5105. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5106. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5107. #else
  5108. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5109. #endif
  5110. }
  5111. void rtw_cfg80211_rx_action(_adapter *adapter, union recv_frame *rframe, const char *msg)
  5112. {
  5113. struct wireless_dev *wdev = adapter->rtw_wdev;
  5114. u8 *frame = get_recvframe_data(rframe);
  5115. uint frame_len = rframe->u.hdr.len;
  5116. s32 freq;
  5117. u8 ch, sch = rtw_get_oper_ch(adapter);
  5118. u8 category, action;
  5119. int type = -1;
  5120. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5121. freq = rtw_ch2freq(ch);
  5122. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n"
  5123. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5124. #ifdef CONFIG_RTW_MESH
  5125. if (MLME_IS_MESH(adapter)) {
  5126. type = rtw_mesh_check_frames_rx(adapter, frame, frame_len);
  5127. if (type >= 0)
  5128. goto indicate;
  5129. }
  5130. #endif
  5131. rtw_action_frame_parse(frame, frame_len, &category, &action);
  5132. if (category == RTW_WLAN_CATEGORY_PUBLIC) {
  5133. if (action == ACT_PUBLIC_GAS_INITIAL_REQ) {
  5134. rtw_mi_set_scan_deny(adapter, 200);
  5135. rtw_mi_scan_abort(adapter, _FALSE); /*rtw_scan_abort_no_wait*/
  5136. }
  5137. }
  5138. indicate:
  5139. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5140. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5141. #else
  5142. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5143. #endif
  5144. if (type == -1) {
  5145. if (msg)
  5146. RTW_INFO("RTW_Rx:%s\n", msg);
  5147. else
  5148. RTW_INFO("RTW_Rx:category(%u), action(%u)\n", category, action);
  5149. }
  5150. }
  5151. #ifdef CONFIG_RTW_80211K
  5152. void rtw_cfg80211_rx_rrm_action(_adapter *adapter, union recv_frame *rframe)
  5153. {
  5154. struct wireless_dev *wdev = adapter->rtw_wdev;
  5155. u8 *frame = get_recvframe_data(rframe);
  5156. uint frame_len = rframe->u.hdr.len;
  5157. s32 freq;
  5158. u8 ch, sch = rtw_get_oper_ch(adapter);
  5159. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5160. freq = rtw_ch2freq(ch);
  5161. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5162. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5163. #else
  5164. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5165. #endif
  5166. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n"
  5167. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5168. }
  5169. #endif /* CONFIG_RTW_80211K */
  5170. void rtw_cfg80211_rx_mframe(_adapter *adapter, union recv_frame *rframe, const char *msg)
  5171. {
  5172. struct wireless_dev *wdev = adapter->rtw_wdev;
  5173. u8 *frame = get_recvframe_data(rframe);
  5174. uint frame_len = rframe->u.hdr.len;
  5175. s32 freq;
  5176. u8 ch, sch = rtw_get_oper_ch(adapter);
  5177. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5178. freq = rtw_ch2freq(ch);
  5179. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5180. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5181. #else
  5182. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5183. #endif
  5184. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n", ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5185. #ifdef CONFIG_RTW_MESH
  5186. if (!rtw_sae_check_frames(adapter, frame, frame_len, _FALSE))
  5187. #endif
  5188. {
  5189. if (msg)
  5190. RTW_INFO("RTW_Rx:%s\n", msg);
  5191. else
  5192. RTW_INFO("RTW_Rx:frame_control:0x%02x\n", le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)rframe)->frame_ctl));
  5193. }
  5194. }
  5195. #ifdef CONFIG_P2P
  5196. void rtw_cfg80211_issue_p2p_provision_request(_adapter *padapter, const u8 *buf, size_t len)
  5197. {
  5198. u16 wps_devicepassword_id = 0x0000;
  5199. uint wps_devicepassword_id_len = 0;
  5200. u8 wpsie[255] = { 0x00 }, p2p_ie[255] = { 0x00 };
  5201. uint p2p_ielen = 0;
  5202. uint wpsielen = 0;
  5203. u32 devinfo_contentlen = 0;
  5204. u8 devinfo_content[64] = { 0x00 };
  5205. u16 capability = 0;
  5206. uint capability_len = 0;
  5207. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  5208. u8 action = P2P_PUB_ACTION_ACTION;
  5209. u8 dialogToken = 1;
  5210. u32 p2poui = cpu_to_be32(P2POUI);
  5211. u8 oui_subtype = P2P_PROVISION_DISC_REQ;
  5212. u32 p2pielen = 0;
  5213. #ifdef CONFIG_WFD
  5214. u32 wfdielen = 0;
  5215. #endif
  5216. struct xmit_frame *pmgntframe;
  5217. struct pkt_attrib *pattrib;
  5218. unsigned char *pframe;
  5219. struct rtw_ieee80211_hdr *pwlanhdr;
  5220. unsigned short *fctrl;
  5221. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  5222. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  5223. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  5224. u8 *frame_body = (unsigned char *)(buf + sizeof(struct rtw_ieee80211_hdr_3addr));
  5225. size_t frame_body_len = len - sizeof(struct rtw_ieee80211_hdr_3addr);
  5226. RTW_INFO("[%s] In\n", __FUNCTION__);
  5227. /* prepare for building provision_request frame */
  5228. _rtw_memcpy(pwdinfo->tx_prov_disc_info.peerIFAddr, GetAddr1Ptr(buf), ETH_ALEN);
  5229. _rtw_memcpy(pwdinfo->tx_prov_disc_info.peerDevAddr, GetAddr1Ptr(buf), ETH_ALEN);
  5230. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
  5231. rtw_get_wps_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, frame_body_len - _PUBLIC_ACTION_IE_OFFSET_, wpsie, &wpsielen);
  5232. rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_DEVICE_PWID, (u8 *) &wps_devicepassword_id, &wps_devicepassword_id_len);
  5233. wps_devicepassword_id = be16_to_cpu(wps_devicepassword_id);
  5234. switch (wps_devicepassword_id) {
  5235. case WPS_DPID_PIN:
  5236. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_LABEL;
  5237. break;
  5238. case WPS_DPID_USER_SPEC:
  5239. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_DISPLYA;
  5240. break;
  5241. case WPS_DPID_MACHINE_SPEC:
  5242. break;
  5243. case WPS_DPID_REKEY:
  5244. break;
  5245. case WPS_DPID_PBC:
  5246. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
  5247. break;
  5248. case WPS_DPID_REGISTRAR_SPEC:
  5249. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_KEYPAD;
  5250. break;
  5251. default:
  5252. break;
  5253. }
  5254. if (rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, frame_body_len - _PUBLIC_ACTION_IE_OFFSET_, p2p_ie, &p2p_ielen)) {
  5255. rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_DEVICE_INFO, devinfo_content, &devinfo_contentlen);
  5256. rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8 *)&capability, &capability_len);
  5257. }
  5258. /* start to build provision_request frame */
  5259. _rtw_memset(wpsie, 0, sizeof(wpsie));
  5260. _rtw_memset(p2p_ie, 0, sizeof(p2p_ie));
  5261. p2p_ielen = 0;
  5262. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  5263. if (pmgntframe == NULL)
  5264. return;
  5265. /* update attribute */
  5266. pattrib = &pmgntframe->attrib;
  5267. update_mgntframe_attrib(padapter, pattrib);
  5268. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  5269. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  5270. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  5271. fctrl = &(pwlanhdr->frame_ctl);
  5272. *(fctrl) = 0;
  5273. _rtw_memcpy(pwlanhdr->addr1, pwdinfo->tx_prov_disc_info.peerDevAddr, ETH_ALEN);
  5274. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  5275. _rtw_memcpy(pwlanhdr->addr3, pwdinfo->tx_prov_disc_info.peerDevAddr, ETH_ALEN);
  5276. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  5277. pmlmeext->mgnt_seq++;
  5278. set_frame_sub_type(pframe, WIFI_ACTION);
  5279. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  5280. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  5281. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  5282. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  5283. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  5284. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  5285. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  5286. /* build_prov_disc_request_p2p_ie */
  5287. /* P2P OUI */
  5288. p2pielen = 0;
  5289. p2p_ie[p2pielen++] = 0x50;
  5290. p2p_ie[p2pielen++] = 0x6F;
  5291. p2p_ie[p2pielen++] = 0x9A;
  5292. p2p_ie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  5293. /* Commented by Albert 20110301 */
  5294. /* According to the P2P Specification, the provision discovery request frame should contain 3 P2P attributes */
  5295. /* 1. P2P Capability */
  5296. /* 2. Device Info */
  5297. /* 3. Group ID ( When joining an operating P2P Group ) */
  5298. /* P2P Capability ATTR */
  5299. /* Type: */
  5300. p2p_ie[p2pielen++] = P2P_ATTR_CAPABILITY;
  5301. /* Length: */
  5302. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 ); */
  5303. RTW_PUT_LE16(p2p_ie + p2pielen, 0x0002);
  5304. p2pielen += 2;
  5305. /* Value: */
  5306. /* Device Capability Bitmap, 1 byte */
  5307. /* Group Capability Bitmap, 1 byte */
  5308. _rtw_memcpy(p2p_ie + p2pielen, &capability, 2);
  5309. p2pielen += 2;
  5310. /* Device Info ATTR */
  5311. /* Type: */
  5312. p2p_ie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
  5313. /* Length: */
  5314. /* 21->P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
  5315. /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
  5316. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 21 + pwdinfo->device_name_len ); */
  5317. RTW_PUT_LE16(p2p_ie + p2pielen, devinfo_contentlen);
  5318. p2pielen += 2;
  5319. /* Value: */
  5320. _rtw_memcpy(p2p_ie + p2pielen, devinfo_content, devinfo_contentlen);
  5321. p2pielen += devinfo_contentlen;
  5322. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2p_ie, &p2p_ielen);
  5323. /* p2pielen = build_prov_disc_request_p2p_ie( pwdinfo, pframe, NULL, 0, pwdinfo->tx_prov_disc_info.peerDevAddr); */
  5324. /* pframe += p2pielen; */
  5325. pattrib->pktlen += p2p_ielen;
  5326. wpsielen = 0;
  5327. /* WPS OUI */
  5328. *(u32 *)(wpsie) = cpu_to_be32(WPSOUI);
  5329. wpsielen += 4;
  5330. /* WPS version */
  5331. /* Type: */
  5332. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
  5333. wpsielen += 2;
  5334. /* Length: */
  5335. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  5336. wpsielen += 2;
  5337. /* Value: */
  5338. wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
  5339. /* Config Method */
  5340. /* Type: */
  5341. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
  5342. wpsielen += 2;
  5343. /* Length: */
  5344. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
  5345. wpsielen += 2;
  5346. /* Value: */
  5347. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->tx_prov_disc_info.wps_config_method_request);
  5348. wpsielen += 2;
  5349. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen);
  5350. #ifdef CONFIG_WFD
  5351. wfdielen = build_provdisc_req_wfd_ie(pwdinfo, pframe);
  5352. pframe += wfdielen;
  5353. pattrib->pktlen += wfdielen;
  5354. #endif
  5355. pattrib->last_txcmdsz = pattrib->pktlen;
  5356. /* dump_mgntframe(padapter, pmgntframe); */
  5357. if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS)
  5358. RTW_INFO("%s, ack to\n", __func__);
  5359. #if 0
  5360. if(wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC) {
  5361. RTW_INFO("waiting for p2p peer key-in PIN CODE\n");
  5362. rtw_msleep_os(15000); /* 15 sec for key in PIN CODE, workaround for GS2 before issuing Nego Req. */
  5363. }
  5364. #endif
  5365. }
  5366. #ifdef CONFIG_RTW_80211R
  5367. static s32 cfg80211_rtw_update_ft_ies(struct wiphy *wiphy,
  5368. struct net_device *ndev,
  5369. struct cfg80211_update_ft_ies_params *ftie)
  5370. {
  5371. _adapter *padapter = NULL;
  5372. struct mlme_priv *pmlmepriv = NULL;
  5373. struct ft_roam_info *pft_roam = NULL;
  5374. _irqL irqL;
  5375. u8 *p;
  5376. u8 *pie = NULL;
  5377. u32 ie_len = 0;
  5378. if (ndev == NULL)
  5379. return -EINVAL;
  5380. padapter = (_adapter *)rtw_netdev_priv(ndev);
  5381. pmlmepriv = &(padapter->mlmepriv);
  5382. pft_roam = &(pmlmepriv->ft_roam);
  5383. p = (u8 *)ftie->ie;
  5384. if (ftie->ie_len <= sizeof(pft_roam->updated_ft_ies)) {
  5385. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  5386. _rtw_memcpy(pft_roam->updated_ft_ies, ftie->ie, ftie->ie_len);
  5387. pft_roam->updated_ft_ies_len = ftie->ie_len;
  5388. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  5389. } else {
  5390. RTW_ERR("FTIEs parsing fail!\n");
  5391. return -EINVAL;
  5392. }
  5393. if (rtw_ft_roam_status(padapter, RTW_FT_AUTHENTICATED_STA)) {
  5394. RTW_PRINT("auth success, start reassoc\n");
  5395. rtw_ft_lock_set_status(padapter, RTW_FT_ASSOCIATING_STA, &irqL);
  5396. start_clnt_assoc(padapter);
  5397. }
  5398. return 0;
  5399. }
  5400. #endif
  5401. inline void rtw_cfg80211_set_is_roch(_adapter *adapter, bool val)
  5402. {
  5403. adapter->cfg80211_wdinfo.is_ro_ch = val;
  5404. rtw_mi_update_iface_status(&(adapter->mlmepriv), 0);
  5405. }
  5406. inline bool rtw_cfg80211_get_is_roch(_adapter *adapter)
  5407. {
  5408. return adapter->cfg80211_wdinfo.is_ro_ch;
  5409. }
  5410. inline bool rtw_cfg80211_is_ro_ch_once(_adapter *adapter)
  5411. {
  5412. return adapter->cfg80211_wdinfo.last_ro_ch_time ? 1 : 0;
  5413. }
  5414. inline void rtw_cfg80211_set_last_ro_ch_time(_adapter *adapter)
  5415. {
  5416. adapter->cfg80211_wdinfo.last_ro_ch_time = rtw_get_current_time();
  5417. if (!adapter->cfg80211_wdinfo.last_ro_ch_time)
  5418. adapter->cfg80211_wdinfo.last_ro_ch_time++;
  5419. }
  5420. inline s32 rtw_cfg80211_get_last_ro_ch_passing_ms(_adapter *adapter)
  5421. {
  5422. return rtw_get_passing_time_ms(adapter->cfg80211_wdinfo.last_ro_ch_time);
  5423. }
  5424. static s32 cfg80211_rtw_remain_on_channel(struct wiphy *wiphy,
  5425. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5426. struct wireless_dev *wdev,
  5427. #else
  5428. struct net_device *ndev,
  5429. #endif
  5430. struct ieee80211_channel *channel,
  5431. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5432. enum nl80211_channel_type channel_type,
  5433. #endif
  5434. unsigned int duration, u64 *cookie)
  5435. {
  5436. s32 err = 0;
  5437. u8 remain_ch = (u8) ieee80211_frequency_to_channel(channel->center_freq);
  5438. _adapter *padapter = NULL;
  5439. struct rtw_wdev_priv *pwdev_priv;
  5440. struct wifidirect_info *pwdinfo;
  5441. struct cfg80211_wifidirect_info *pcfg80211_wdinfo;
  5442. #ifdef CONFIG_CONCURRENT_MODE
  5443. u8 is_p2p_find = _FALSE;
  5444. #endif
  5445. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5446. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5447. if (wdev == wiphy_to_pd_wdev(wiphy))
  5448. padapter = wiphy_to_adapter(wiphy);
  5449. else
  5450. #endif
  5451. if (wdev_to_ndev(wdev))
  5452. padapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  5453. else {
  5454. err = -EINVAL;
  5455. goto exit;
  5456. }
  5457. #else
  5458. struct wireless_dev *wdev;
  5459. if (ndev == NULL) {
  5460. err = -EINVAL;
  5461. goto exit;
  5462. }
  5463. padapter = (_adapter *)rtw_netdev_priv(ndev);
  5464. wdev = ndev_to_wdev(ndev);
  5465. #endif
  5466. pwdev_priv = adapter_wdev_data(padapter);
  5467. pwdinfo = &padapter->wdinfo;
  5468. pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  5469. #ifdef CONFIG_CONCURRENT_MODE
  5470. is_p2p_find = (duration < (pwdinfo->ext_listen_interval)) ? _TRUE : _FALSE;
  5471. #endif
  5472. *cookie = ATOMIC_INC_RETURN(&pcfg80211_wdinfo->ro_ch_cookie_gen);
  5473. RTW_INFO(FUNC_ADPT_FMT"%s ch:%u duration:%d, cookie:0x%llx\n"
  5474. , FUNC_ADPT_ARG(padapter), wdev == wiphy_to_pd_wdev(wiphy) ? " PD" : ""
  5475. , remain_ch, duration, *cookie);
  5476. if (rtw_chset_search_ch(adapter_to_chset(padapter), remain_ch) < 0) {
  5477. RTW_WARN(FUNC_ADPT_FMT" invalid ch:%u\n", FUNC_ADPT_ARG(padapter), remain_ch);
  5478. err = -EFAULT;
  5479. goto exit;
  5480. }
  5481. #ifdef CONFIG_MP_INCLUDED
  5482. if (rtw_mp_mode_check(padapter)) {
  5483. RTW_INFO("MP mode block remain_on_channel request\n");
  5484. err = -EFAULT;
  5485. goto exit;
  5486. }
  5487. #endif
  5488. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  5489. err = -EFAULT;
  5490. goto exit;
  5491. }
  5492. rtw_scan_abort(padapter);
  5493. #ifdef CONFIG_CONCURRENT_MODE
  5494. /*don't scan_abort during p2p_listen.*/
  5495. if (is_p2p_find)
  5496. rtw_mi_buddy_scan_abort(padapter, _TRUE);
  5497. #endif /*CONFIG_CONCURRENT_MODE*/
  5498. if (rtw_cfg80211_get_is_roch(padapter) == _TRUE) {
  5499. _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
  5500. p2p_cancel_roch_cmd(padapter, 0, NULL, RTW_CMDF_WAIT_ACK);
  5501. }
  5502. /* if(!rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) && !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) */
  5503. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  5504. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  5505. padapter->wdinfo.listen_channel = remain_ch;
  5506. RTW_INFO(FUNC_ADPT_FMT" init listen_channel %u\n"
  5507. , FUNC_ADPT_ARG(padapter), padapter->wdinfo.listen_channel);
  5508. } else if (rtw_p2p_chk_state(pwdinfo , P2P_STATE_LISTEN)
  5509. && (time_after_eq(rtw_get_current_time(), pwdev_priv->probe_resp_ie_update_time)
  5510. && rtw_get_passing_time_ms(pwdev_priv->probe_resp_ie_update_time) < 50)
  5511. ) {
  5512. if (padapter->wdinfo.listen_channel != remain_ch) {
  5513. padapter->wdinfo.listen_channel = remain_ch;
  5514. RTW_INFO(FUNC_ADPT_FMT" update listen_channel %u\n"
  5515. , FUNC_ADPT_ARG(padapter), padapter->wdinfo.listen_channel);
  5516. }
  5517. } else {
  5518. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  5519. #ifdef CONFIG_DEBUG_CFG80211
  5520. RTW_INFO("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  5521. #endif
  5522. }
  5523. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  5524. #ifdef RTW_ROCH_DURATION_ENLARGE
  5525. if (duration < 400)
  5526. duration = duration * 3; /* extend from exper */
  5527. #endif
  5528. #if defined(RTW_ROCH_BACK_OP) && defined(CONFIG_CONCURRENT_MODE)
  5529. if (rtw_mi_check_status(padapter, MI_LINKED)) {
  5530. if (is_p2p_find) /* p2p_find , duration<1000 */
  5531. duration = duration + pwdinfo->ext_listen_interval;
  5532. else /* p2p_listen, duration=5000 */
  5533. duration = pwdinfo->ext_listen_interval + (pwdinfo->ext_listen_interval / 4);
  5534. }
  5535. #endif /*defined (RTW_ROCH_BACK_OP) && defined(CONFIG_CONCURRENT_MODE) */
  5536. rtw_cfg80211_set_is_roch(padapter, _TRUE);
  5537. pcfg80211_wdinfo->ro_ch_wdev = wdev;
  5538. pcfg80211_wdinfo->remain_on_ch_cookie = *cookie;
  5539. rtw_cfg80211_set_last_ro_ch_time(padapter);
  5540. _rtw_memcpy(&pcfg80211_wdinfo->remain_on_ch_channel, channel, sizeof(struct ieee80211_channel));
  5541. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5542. pcfg80211_wdinfo->remain_on_ch_type = channel_type;
  5543. #endif
  5544. pcfg80211_wdinfo->restore_channel = rtw_get_oper_ch(padapter);
  5545. p2p_roch_cmd(padapter, *cookie, wdev, channel, pcfg80211_wdinfo->remain_on_ch_type,
  5546. duration, RTW_CMDF_WAIT_ACK);
  5547. rtw_cfg80211_ready_on_channel(wdev, *cookie, channel, channel_type, duration, GFP_KERNEL);
  5548. exit:
  5549. return err;
  5550. }
  5551. static s32 cfg80211_rtw_cancel_remain_on_channel(struct wiphy *wiphy,
  5552. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5553. struct wireless_dev *wdev,
  5554. #else
  5555. struct net_device *ndev,
  5556. #endif
  5557. u64 cookie)
  5558. {
  5559. s32 err = 0;
  5560. _adapter *padapter;
  5561. struct rtw_wdev_priv *pwdev_priv;
  5562. struct wifidirect_info *pwdinfo;
  5563. struct cfg80211_wifidirect_info *pcfg80211_wdinfo;
  5564. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5565. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5566. if (wdev == wiphy_to_pd_wdev(wiphy))
  5567. padapter = wiphy_to_adapter(wiphy);
  5568. else
  5569. #endif
  5570. if (wdev_to_ndev(wdev))
  5571. padapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  5572. else {
  5573. err = -EINVAL;
  5574. goto exit;
  5575. }
  5576. #else
  5577. struct wireless_dev *wdev;
  5578. if (ndev == NULL) {
  5579. err = -EINVAL;
  5580. goto exit;
  5581. }
  5582. padapter = (_adapter *)rtw_netdev_priv(ndev);
  5583. wdev = ndev_to_wdev(ndev);
  5584. #endif
  5585. pwdev_priv = adapter_wdev_data(padapter);
  5586. pwdinfo = &padapter->wdinfo;
  5587. pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  5588. RTW_INFO(FUNC_ADPT_FMT"%s cookie:0x%llx\n"
  5589. , FUNC_ADPT_ARG(padapter), wdev == wiphy_to_pd_wdev(wiphy) ? " PD" : ""
  5590. , cookie);
  5591. if (rtw_cfg80211_get_is_roch(padapter) == _TRUE) {
  5592. _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
  5593. p2p_cancel_roch_cmd(padapter, cookie, wdev, RTW_CMDF_WAIT_ACK);
  5594. }
  5595. exit:
  5596. return err;
  5597. }
  5598. inline int rtw_cfg80211_iface_has_p2p_group_cap(_adapter *adapter)
  5599. {
  5600. #if RTW_P2P_GROUP_INTERFACE
  5601. if (is_primary_adapter(adapter))
  5602. return 0;
  5603. #endif
  5604. return 1;
  5605. }
  5606. inline int rtw_cfg80211_is_p2p_scan(_adapter *adapter)
  5607. {
  5608. #if RTW_P2P_GROUP_INTERFACE
  5609. if (rtw_cfg80211_iface_has_p2p_group_cap(adapter))
  5610. #endif
  5611. {
  5612. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  5613. return rtw_p2p_chk_state(wdinfo, P2P_STATE_SCAN)
  5614. || rtw_p2p_chk_state(wdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  5615. }
  5616. #if RTW_P2P_GROUP_INTERFACE
  5617. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5618. if (wiphy_to_pd_wdev(adapter_to_wiphy(adapter))) /* pd_wdev exist */
  5619. return rtw_cfg80211_is_scan_by_pd_wdev(adapter);
  5620. #endif
  5621. {
  5622. /*
  5623. * For 2 RTW_P2P_GROUP_INTERFACE cases:
  5624. * 1. RTW_DEDICATED_P2P_DEVICE defined but upper layer don't use pd_wdev or
  5625. * 2. RTW_DEDICATED_P2P_DEVICE not defined
  5626. */
  5627. struct rtw_wdev_priv *wdev_data = adapter_wdev_data(adapter);
  5628. _irqL irqL;
  5629. int is_p2p_scan = 0;
  5630. _enter_critical_bh(&wdev_data->scan_req_lock, &irqL);
  5631. if (wdev_data->scan_request
  5632. && wdev_data->scan_request->ssids
  5633. && wdev_data->scan_request->ie
  5634. ) {
  5635. if (_rtw_memcmp(wdev_data->scan_request->ssids->ssid, "DIRECT-", 7)
  5636. && rtw_get_p2p_ie((u8 *)wdev_data->scan_request->ie, wdev_data->scan_request->ie_len, NULL, NULL))
  5637. is_p2p_scan = 1;
  5638. }
  5639. _exit_critical_bh(&wdev_data->scan_req_lock, &irqL);
  5640. return is_p2p_scan;
  5641. }
  5642. #endif
  5643. }
  5644. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5645. int rtw_pd_iface_alloc(struct wiphy *wiphy, const char *name, struct wireless_dev **pd_wdev)
  5646. {
  5647. struct rtw_wiphy_data *wiphy_data = rtw_wiphy_priv(wiphy);
  5648. struct wireless_dev *wdev = NULL;
  5649. struct rtw_netdev_priv_indicator *npi;
  5650. _adapter *primary_adpt = wiphy_to_adapter(wiphy);
  5651. int ret = 0;
  5652. if (wiphy_data->pd_wdev) {
  5653. RTW_WARN(FUNC_WIPHY_FMT" pd_wdev already exists\n", FUNC_WIPHY_ARG(wiphy));
  5654. ret = -EBUSY;
  5655. goto exit;
  5656. }
  5657. wdev = (struct wireless_dev *)rtw_zmalloc(sizeof(struct wireless_dev));
  5658. if (!wdev) {
  5659. RTW_WARN(FUNC_WIPHY_FMT" allocate wdev fail\n", FUNC_WIPHY_ARG(wiphy));
  5660. ret = -ENOMEM;
  5661. goto exit;
  5662. }
  5663. wdev->wiphy = wiphy;
  5664. wdev->iftype = NL80211_IFTYPE_P2P_DEVICE;
  5665. _rtw_memcpy(wdev->address, adapter_mac_addr(primary_adpt), ETH_ALEN);
  5666. wiphy_data->pd_wdev = wdev;
  5667. *pd_wdev = wdev;
  5668. RTW_INFO(FUNC_WIPHY_FMT" pd_wdev:%p, addr="MAC_FMT" added\n"
  5669. , FUNC_WIPHY_ARG(wiphy), wdev, MAC_ARG(wdev_address(wdev)));
  5670. exit:
  5671. if (ret && wdev) {
  5672. rtw_mfree((u8 *)wdev, sizeof(struct wireless_dev));
  5673. wdev = NULL;
  5674. }
  5675. return ret;
  5676. }
  5677. void rtw_pd_iface_free(struct wiphy *wiphy)
  5678. {
  5679. struct dvobj_priv *dvobj = wiphy_to_dvobj(wiphy);
  5680. struct rtw_wiphy_data *wiphy_data = rtw_wiphy_priv(wiphy);
  5681. u8 rtnl_lock_needed;
  5682. if (!wiphy_data->pd_wdev)
  5683. goto exit;
  5684. RTW_INFO(FUNC_WIPHY_FMT" pd_wdev:%p, addr="MAC_FMT"\n"
  5685. , FUNC_WIPHY_ARG(wiphy), wiphy_data->pd_wdev
  5686. , MAC_ARG(wdev_address(wiphy_data->pd_wdev)));
  5687. rtnl_lock_needed = rtw_rtnl_lock_needed(dvobj);
  5688. if (rtnl_lock_needed)
  5689. rtnl_lock();
  5690. cfg80211_unregister_wdev(wiphy_data->pd_wdev);
  5691. if (rtnl_lock_needed)
  5692. rtnl_unlock();
  5693. rtw_mfree((u8 *)wiphy_data->pd_wdev, sizeof(struct wireless_dev));
  5694. wiphy_data->pd_wdev = NULL;
  5695. exit:
  5696. return;
  5697. }
  5698. static int cfg80211_rtw_start_p2p_device(struct wiphy *wiphy, struct wireless_dev *wdev)
  5699. {
  5700. _adapter *adapter = wiphy_to_adapter(wiphy);
  5701. RTW_INFO(FUNC_WIPHY_FMT" wdev=%p\n", FUNC_WIPHY_ARG(wiphy), wdev);
  5702. rtw_p2p_enable(adapter, P2P_ROLE_DEVICE);
  5703. return 0;
  5704. }
  5705. static void cfg80211_rtw_stop_p2p_device(struct wiphy *wiphy, struct wireless_dev *wdev)
  5706. {
  5707. _adapter *adapter = wiphy_to_adapter(wiphy);
  5708. RTW_INFO(FUNC_WIPHY_FMT" wdev=%p\n", FUNC_WIPHY_ARG(wiphy), wdev);
  5709. if (rtw_cfg80211_is_p2p_scan(adapter))
  5710. rtw_scan_abort(adapter);
  5711. rtw_p2p_enable(adapter, P2P_ROLE_DISABLE);
  5712. }
  5713. inline int rtw_cfg80211_redirect_pd_wdev(struct wiphy *wiphy, u8 *ra, struct wireless_dev **wdev)
  5714. {
  5715. struct wireless_dev *pd_wdev = wiphy_to_pd_wdev(wiphy);
  5716. if (pd_wdev && pd_wdev != *wdev
  5717. && _rtw_memcmp(wdev_address(pd_wdev), ra, ETH_ALEN) == _TRUE
  5718. ) {
  5719. *wdev = pd_wdev;
  5720. return 1;
  5721. }
  5722. return 0;
  5723. }
  5724. inline int rtw_cfg80211_is_scan_by_pd_wdev(_adapter *adapter)
  5725. {
  5726. struct wiphy *wiphy = adapter_to_wiphy(adapter);
  5727. struct rtw_wdev_priv *wdev_data = adapter_wdev_data(adapter);
  5728. struct wireless_dev *wdev = NULL;
  5729. _irqL irqL;
  5730. _enter_critical_bh(&wdev_data->scan_req_lock, &irqL);
  5731. if (wdev_data->scan_request)
  5732. wdev = wdev_data->scan_request->wdev;
  5733. _exit_critical_bh(&wdev_data->scan_req_lock, &irqL);
  5734. if (wdev && wdev == wiphy_to_pd_wdev(wiphy))
  5735. return 1;
  5736. return 0;
  5737. }
  5738. #endif /* RTW_DEDICATED_P2P_DEVICE */
  5739. #endif /* CONFIG_P2P */
  5740. inline void rtw_cfg80211_set_is_mgmt_tx(_adapter *adapter, u8 val)
  5741. {
  5742. struct rtw_wdev_priv *wdev_priv = adapter_wdev_data(adapter);
  5743. wdev_priv->is_mgmt_tx = val;
  5744. rtw_mi_update_iface_status(&(adapter->mlmepriv), 0);
  5745. }
  5746. inline u8 rtw_cfg80211_get_is_mgmt_tx(_adapter *adapter)
  5747. {
  5748. struct rtw_wdev_priv *wdev_priv = adapter_wdev_data(adapter);
  5749. return wdev_priv->is_mgmt_tx;
  5750. }
  5751. static int _cfg80211_rtw_mgmt_tx(_adapter *padapter, u8 tx_ch, u8 no_cck, const u8 *buf, size_t len, int wait_ack)
  5752. {
  5753. struct xmit_frame *pmgntframe;
  5754. struct pkt_attrib *pattrib;
  5755. unsigned char *pframe;
  5756. int ret = _FAIL;
  5757. bool ack = _TRUE;
  5758. struct rtw_ieee80211_hdr *pwlanhdr;
  5759. #if defined(RTW_ROCH_BACK_OP) && defined(CONFIG_P2P) && defined(CONFIG_CONCURRENT_MODE)
  5760. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  5761. #endif
  5762. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  5763. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  5764. u8 u_ch = rtw_mi_get_union_chan(padapter);
  5765. u8 leave_op = 0;
  5766. #ifdef CONFIG_P2P
  5767. struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  5768. #ifdef CONFIG_CONCURRENT_MODE
  5769. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  5770. #endif
  5771. #endif
  5772. rtw_cfg80211_set_is_mgmt_tx(padapter, 1);
  5773. #ifdef CONFIG_BT_COEXIST
  5774. rtw_btcoex_ScanNotify(padapter, _TRUE);
  5775. #endif
  5776. #ifdef CONFIG_P2P
  5777. if (rtw_cfg80211_get_is_roch(padapter) == _TRUE) {
  5778. #ifdef CONFIG_CONCURRENT_MODE
  5779. if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
  5780. RTW_INFO("%s, extend ro ch time\n", __func__);
  5781. _set_timer(&padapter->cfg80211_wdinfo.remain_on_ch_timer, pwdinfo->ext_listen_period);
  5782. }
  5783. #endif /* CONFIG_CONCURRENT_MODE */
  5784. }
  5785. #endif /* CONFIG_P2P */
  5786. #ifdef CONFIG_MCC_MODE
  5787. if (MCC_EN(padapter)) {
  5788. if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))
  5789. /* don't set channel, issue frame directly */
  5790. goto issue_mgmt_frame;
  5791. }
  5792. #endif /* CONFIG_MCC_MODE */
  5793. if (rtw_mi_check_status(padapter, MI_LINKED)
  5794. && tx_ch != u_ch
  5795. ) {
  5796. rtw_leave_opch(padapter);
  5797. leave_op = 1;
  5798. #if defined(RTW_ROCH_BACK_OP) && defined(CONFIG_P2P) && defined(CONFIG_CONCURRENT_MODE)
  5799. if (rtw_cfg80211_get_is_roch(padapter)
  5800. && ATOMIC_READ(&pwdev_priv->switch_ch_to) == 1
  5801. ) {
  5802. u16 ext_listen_period;
  5803. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED))
  5804. ext_listen_period = 500;
  5805. else
  5806. ext_listen_period = pwdinfo->ext_listen_period;
  5807. ATOMIC_SET(&pwdev_priv->switch_ch_to, 0);
  5808. _set_timer(&pwdinfo->ap_p2p_switch_timer, ext_listen_period);
  5809. RTW_INFO("%s, set switch ch timer, period=%d\n", __func__, ext_listen_period);
  5810. }
  5811. #endif /* RTW_ROCH_BACK_OP && CONFIG_P2P && CONFIG_CONCURRENT_MODE */
  5812. }
  5813. if (tx_ch != rtw_get_oper_ch(padapter))
  5814. set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  5815. issue_mgmt_frame:
  5816. /* starting alloc mgmt frame to dump it */
  5817. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  5818. if (pmgntframe == NULL) {
  5819. /* ret = -ENOMEM; */
  5820. ret = _FAIL;
  5821. goto exit;
  5822. }
  5823. /* update attribute */
  5824. pattrib = &pmgntframe->attrib;
  5825. update_mgntframe_attrib(padapter, pattrib);
  5826. if (no_cck && IS_CCK_RATE(pattrib->rate)) {
  5827. /* force OFDM 6M rate*/
  5828. pattrib->rate = MGN_6M;
  5829. pattrib->raid = rtw_get_mgntframe_raid(padapter, WIRELESS_11G);
  5830. }
  5831. pattrib->retry_ctrl = _FALSE;
  5832. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  5833. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  5834. _rtw_memcpy(pframe, (void *)buf, len);
  5835. pattrib->pktlen = len;
  5836. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  5837. /* update seq number */
  5838. pmlmeext->mgnt_seq = GetSequence(pwlanhdr);
  5839. pattrib->seqnum = pmlmeext->mgnt_seq;
  5840. pmlmeext->mgnt_seq++;
  5841. #ifdef CONFIG_P2P
  5842. rtw_xframe_chk_wfd_ie(pmgntframe);
  5843. #endif /* CONFIG_P2P */
  5844. pattrib->last_txcmdsz = pattrib->pktlen;
  5845. if (wait_ack) {
  5846. if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS) {
  5847. ack = _FALSE;
  5848. ret = _FAIL;
  5849. #ifdef CONFIG_DEBUG_CFG80211
  5850. RTW_INFO("%s, ack == _FAIL\n", __func__);
  5851. #endif
  5852. } else {
  5853. #ifdef CONFIG_XMIT_ACK
  5854. if (!MLME_IS_MESH(padapter)) /* TODO: remove this sleep for all mode */
  5855. rtw_msleep_os(50);
  5856. #endif
  5857. #ifdef CONFIG_DEBUG_CFG80211
  5858. RTW_INFO("%s, ack=%d, ok!\n", __func__, ack);
  5859. #endif
  5860. ret = _SUCCESS;
  5861. }
  5862. } else {
  5863. dump_mgntframe(padapter, pmgntframe);
  5864. ret = _SUCCESS;
  5865. }
  5866. exit:
  5867. #ifdef CONFIG_P2P
  5868. if (rtw_cfg80211_get_is_roch(padapter)
  5869. && !roch_stay_in_cur_chan(padapter)
  5870. && pcfg80211_wdinfo->remain_on_ch_channel.hw_value != u_ch
  5871. ) {
  5872. /* roch is ongoing, switch back to rch */
  5873. if (pcfg80211_wdinfo->remain_on_ch_channel.hw_value != tx_ch)
  5874. set_channel_bwmode(padapter, pcfg80211_wdinfo->remain_on_ch_channel.hw_value
  5875. , HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  5876. } else
  5877. #endif
  5878. if (leave_op) {
  5879. if (rtw_mi_check_status(padapter, MI_LINKED)) {
  5880. u8 u_bw = rtw_mi_get_union_bw(padapter);
  5881. u8 u_offset = rtw_mi_get_union_offset(padapter);
  5882. set_channel_bwmode(padapter, u_ch, u_offset, u_bw);
  5883. }
  5884. rtw_back_opch(padapter);
  5885. }
  5886. rtw_cfg80211_set_is_mgmt_tx(padapter, 0);
  5887. #ifdef CONFIG_BT_COEXIST
  5888. rtw_btcoex_ScanNotify(padapter, _FALSE);
  5889. #endif
  5890. #ifdef CONFIG_DEBUG_CFG80211
  5891. RTW_INFO("%s, ret=%d\n", __func__, ret);
  5892. #endif
  5893. return ret;
  5894. }
  5895. u8 rtw_mgnt_tx_handler(_adapter *adapter, u8 *buf)
  5896. {
  5897. u8 rst = H2C_CMD_FAIL;
  5898. struct mgnt_tx_parm *mgnt_parm = (struct mgnt_tx_parm *)buf;
  5899. if (_cfg80211_rtw_mgmt_tx(adapter, mgnt_parm->tx_ch, mgnt_parm->no_cck,
  5900. mgnt_parm->buf, mgnt_parm->len, mgnt_parm->wait_ack) == _SUCCESS)
  5901. rst = H2C_SUCCESS;
  5902. return rst;
  5903. }
  5904. static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy,
  5905. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5906. struct wireless_dev *wdev,
  5907. #else
  5908. struct net_device *ndev,
  5909. #endif
  5910. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)) || defined(COMPAT_KERNEL_RELEASE)
  5911. struct ieee80211_channel *chan,
  5912. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  5913. bool offchan,
  5914. #endif
  5915. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5916. enum nl80211_channel_type channel_type,
  5917. #endif
  5918. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5919. bool channel_type_valid,
  5920. #endif
  5921. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  5922. unsigned int wait,
  5923. #endif
  5924. const u8 *buf, size_t len,
  5925. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  5926. bool no_cck,
  5927. #endif
  5928. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  5929. bool dont_wait_for_ack,
  5930. #endif
  5931. #else
  5932. struct cfg80211_mgmt_tx_params *params,
  5933. #endif
  5934. u64 *cookie)
  5935. {
  5936. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(COMPAT_KERNEL_RELEASE)
  5937. struct ieee80211_channel *chan = params->chan;
  5938. const u8 *buf = params->buf;
  5939. size_t len = params->len;
  5940. bool no_cck = params->no_cck;
  5941. #endif
  5942. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0))
  5943. bool no_cck = 0;
  5944. #endif
  5945. int ret = 0;
  5946. u8 tx_ret;
  5947. int wait_ack = 1;
  5948. const u8 *dump_buf = buf;
  5949. size_t dump_len = len;
  5950. u32 dump_limit = RTW_MAX_MGMT_TX_CNT;
  5951. u32 dump_cnt = 0;
  5952. u32 sleep_ms = 0;
  5953. u32 retry_guarantee_ms = 0;
  5954. bool ack = _TRUE;
  5955. u8 tx_ch;
  5956. u8 category, action;
  5957. u8 frame_styp;
  5958. #ifdef CONFIG_P2P
  5959. u8 is_p2p = 0;
  5960. #endif
  5961. int type = (-1);
  5962. systime start = rtw_get_current_time();
  5963. _adapter *padapter;
  5964. struct dvobj_priv *dvobj;
  5965. struct rtw_wdev_priv *pwdev_priv;
  5966. struct rf_ctl_t *rfctl;
  5967. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5968. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5969. if (wdev == wiphy_to_pd_wdev(wiphy))
  5970. padapter = wiphy_to_adapter(wiphy);
  5971. else
  5972. #endif
  5973. if (wdev_to_ndev(wdev))
  5974. padapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  5975. else {
  5976. ret = -EINVAL;
  5977. goto exit;
  5978. }
  5979. #else
  5980. struct wireless_dev *wdev;
  5981. if (ndev == NULL) {
  5982. ret = -EINVAL;
  5983. goto exit;
  5984. }
  5985. padapter = (_adapter *)rtw_netdev_priv(ndev);
  5986. wdev = ndev_to_wdev(ndev);
  5987. #endif
  5988. if (chan == NULL) {
  5989. ret = -EINVAL;
  5990. goto exit;
  5991. }
  5992. rfctl = adapter_to_rfctl(padapter);
  5993. tx_ch = (u8)ieee80211_frequency_to_channel(chan->center_freq);
  5994. if (IS_CH_WAITING(rfctl)) {
  5995. #ifdef CONFIG_DFS_MASTER
  5996. if (_rtw_rfctl_overlap_radar_detect_ch(rfctl, tx_ch, CHANNEL_WIDTH_20, HAL_PRIME_CHNL_OFFSET_DONT_CARE)) {
  5997. ret = -EINVAL;
  5998. goto exit;
  5999. }
  6000. #endif
  6001. }
  6002. dvobj = adapter_to_dvobj(padapter);
  6003. pwdev_priv = adapter_wdev_data(padapter);
  6004. /* cookie generation */
  6005. *cookie = pwdev_priv->mgmt_tx_cookie++;
  6006. #ifdef CONFIG_DEBUG_CFG80211
  6007. RTW_INFO(FUNC_ADPT_FMT"%s len=%zu, ch=%d"
  6008. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  6009. ", ch_type=%d"
  6010. #endif
  6011. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  6012. ", channel_type_valid=%d"
  6013. #endif
  6014. "\n", FUNC_ADPT_ARG(padapter), wdev == wiphy_to_pd_wdev(wiphy) ? " PD" : ""
  6015. , len, tx_ch
  6016. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  6017. , channel_type
  6018. #endif
  6019. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  6020. , channel_type_valid
  6021. #endif
  6022. );
  6023. #endif /* CONFIG_DEBUG_CFG80211 */
  6024. /* indicate ack before issue frame to avoid racing with rsp frame */
  6025. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  6026. rtw_cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack, GFP_KERNEL);
  6027. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34) && LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 36))
  6028. cfg80211_action_tx_status(ndev, *cookie, buf, len, ack, GFP_KERNEL);
  6029. #endif
  6030. frame_styp = le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl) & IEEE80211_FCTL_STYPE;
  6031. if (IEEE80211_STYPE_PROBE_RESP == frame_styp) {
  6032. #ifdef CONFIG_DEBUG_CFG80211
  6033. RTW_INFO("RTW_Tx: probe_resp tx_ch=%d, no_cck=%u, da="MAC_FMT"\n", tx_ch, no_cck, MAC_ARG(GetAddr1Ptr(buf)));
  6034. #endif /* CONFIG_DEBUG_CFG80211 */
  6035. wait_ack = 0;
  6036. goto dump;
  6037. }
  6038. #ifdef CONFIG_RTW_MESH
  6039. else if (frame_styp == RTW_IEEE80211_STYPE_AUTH) {
  6040. RTW_INFO("RTW_Tx:tx_ch=%d, no_cck=%u, da="MAC_FMT"\n", tx_ch, no_cck, MAC_ARG(GetAddr1Ptr(buf)));
  6041. if (!rtw_sae_check_frames(padapter, buf, len, _TRUE))
  6042. RTW_INFO("RTW_Tx:AUTH\n");
  6043. dump_limit = 1;
  6044. goto dump;
  6045. }
  6046. #endif
  6047. if (rtw_action_frame_parse(buf, len, &category, &action) == _FALSE) {
  6048. RTW_INFO(FUNC_ADPT_FMT" frame_control:0x%02x\n", FUNC_ADPT_ARG(padapter),
  6049. le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl));
  6050. goto exit;
  6051. }
  6052. RTW_INFO("RTW_Tx:tx_ch=%d, no_cck=%u, da="MAC_FMT"\n", tx_ch, no_cck, MAC_ARG(GetAddr1Ptr(buf)));
  6053. #ifdef CONFIG_P2P
  6054. type = rtw_p2p_check_frames(padapter, buf, len, _TRUE);
  6055. if (type >= 0) {
  6056. is_p2p = 1;
  6057. no_cck = 1; /* force no CCK for P2P frames */
  6058. goto dump;
  6059. }
  6060. #endif
  6061. #ifdef CONFIG_RTW_MESH
  6062. if (MLME_IS_MESH(padapter)) {
  6063. type = rtw_mesh_check_frames_tx(padapter, &dump_buf, &dump_len);
  6064. if (type >= 0) {
  6065. dump_limit = 1;
  6066. goto dump;
  6067. }
  6068. }
  6069. #endif
  6070. if (category == RTW_WLAN_CATEGORY_PUBLIC) {
  6071. RTW_INFO("RTW_Tx:%s\n", action_public_str(action));
  6072. switch (action) {
  6073. case ACT_PUBLIC_GAS_INITIAL_REQ:
  6074. case ACT_PUBLIC_GAS_INITIAL_RSP:
  6075. sleep_ms = 50;
  6076. retry_guarantee_ms = RTW_MAX_MGMT_TX_MS_GAS;
  6077. break;
  6078. }
  6079. }
  6080. #ifdef CONFIG_RTW_80211K
  6081. else if (category == RTW_WLAN_CATEGORY_RADIO_MEAS)
  6082. RTW_INFO("RTW_Tx: RRM Action\n");
  6083. #endif
  6084. else
  6085. RTW_INFO("RTW_Tx:category(%u), action(%u)\n", category, action);
  6086. dump:
  6087. rtw_ps_deny(padapter, PS_DENY_MGNT_TX);
  6088. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  6089. ret = -EFAULT;
  6090. goto cancel_ps_deny;
  6091. }
  6092. while (1) {
  6093. dump_cnt++;
  6094. rtw_mi_set_scan_deny(padapter, 1000);
  6095. rtw_mi_scan_abort(padapter, _TRUE);
  6096. tx_ret = rtw_mgnt_tx_cmd(padapter, tx_ch, no_cck, dump_buf, dump_len, wait_ack, RTW_CMDF_WAIT_ACK);
  6097. if (tx_ret == _SUCCESS
  6098. || (dump_cnt >= dump_limit && rtw_get_passing_time_ms(start) >= retry_guarantee_ms))
  6099. break;
  6100. if (sleep_ms > 0)
  6101. rtw_msleep_os(sleep_ms);
  6102. }
  6103. if (tx_ret != _SUCCESS || dump_cnt > 1) {
  6104. RTW_INFO(FUNC_ADPT_FMT" %s (%d/%d) in %d ms\n", FUNC_ADPT_ARG(padapter),
  6105. tx_ret == _SUCCESS ? "OK" : "FAIL", dump_cnt, dump_limit, rtw_get_passing_time_ms(start));
  6106. }
  6107. #ifdef CONFIG_P2P
  6108. if (is_p2p) {
  6109. switch (type) {
  6110. case P2P_GO_NEGO_CONF:
  6111. if (0) {
  6112. RTW_INFO(FUNC_ADPT_FMT" Nego confirm. state=%u, status=%u, iaddr="MAC_FMT"\n"
  6113. , FUNC_ADPT_ARG(padapter), pwdev_priv->nego_info.state, pwdev_priv->nego_info.status
  6114. , MAC_ARG(pwdev_priv->nego_info.iface_addr));
  6115. }
  6116. if (pwdev_priv->nego_info.state == 2
  6117. && pwdev_priv->nego_info.status == 0
  6118. && rtw_check_invalid_mac_address(pwdev_priv->nego_info.iface_addr, _FALSE) == _FALSE
  6119. ) {
  6120. _adapter *intended_iface = dvobj_get_adapter_by_addr(dvobj, pwdev_priv->nego_info.iface_addr);
  6121. if (intended_iface) {
  6122. RTW_INFO(FUNC_ADPT_FMT" Nego confirm. Allow only "ADPT_FMT" to scan for 2000 ms\n"
  6123. , FUNC_ADPT_ARG(padapter), ADPT_ARG(intended_iface));
  6124. /* allow only intended_iface to do scan for 2000 ms */
  6125. rtw_mi_set_scan_deny(padapter, 2000);
  6126. rtw_clear_scan_deny(intended_iface);
  6127. }
  6128. }
  6129. break;
  6130. case P2P_INVIT_RESP:
  6131. if (pwdev_priv->invit_info.flags & BIT(0)
  6132. && pwdev_priv->invit_info.status == 0
  6133. ) {
  6134. rtw_clear_scan_deny(padapter);
  6135. RTW_INFO(FUNC_ADPT_FMT" agree with invitation of persistent group\n",
  6136. FUNC_ADPT_ARG(padapter));
  6137. #if !RTW_P2P_GROUP_INTERFACE
  6138. rtw_mi_buddy_set_scan_deny(padapter, 5000);
  6139. #endif
  6140. rtw_pwr_wakeup_ex(padapter, 5000);
  6141. }
  6142. break;
  6143. }
  6144. }
  6145. #endif /* CONFIG_P2P */
  6146. cancel_ps_deny:
  6147. rtw_ps_deny_cancel(padapter, PS_DENY_MGNT_TX);
  6148. if (dump_buf != buf)
  6149. rtw_mfree((u8 *)dump_buf, dump_len);
  6150. exit:
  6151. return ret;
  6152. }
  6153. static void cfg80211_rtw_mgmt_frame_register(struct wiphy *wiphy,
  6154. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6155. struct wireless_dev *wdev,
  6156. #else
  6157. struct net_device *ndev,
  6158. #endif
  6159. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
  6160. struct mgmt_frame_regs *upd)
  6161. #else
  6162. u16 frame_type, bool reg)
  6163. #endif
  6164. {
  6165. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6166. struct net_device *ndev = wdev_to_ndev(wdev);
  6167. #endif
  6168. /* hardcoded always true, to make it pass compilation */
  6169. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
  6170. bool reg = true;
  6171. #endif
  6172. _adapter *adapter;
  6173. struct rtw_wdev_priv *pwdev_priv;
  6174. if (ndev == NULL)
  6175. goto exit;
  6176. adapter = (_adapter *)rtw_netdev_priv(ndev);
  6177. pwdev_priv = adapter_wdev_data(adapter);
  6178. #ifdef CONFIG_DEBUG_CFG80211
  6179. RTW_INFO(FUNC_ADPT_FMT" frame_type:%x, reg:%d\n", FUNC_ADPT_ARG(adapter),
  6180. frame_type, reg);
  6181. #endif
  6182. /* Wait QC Verify */
  6183. return;
  6184. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
  6185. switch (upd->interface_stypes) {
  6186. #else
  6187. switch (frame_type) {
  6188. #endif
  6189. case IEEE80211_STYPE_PROBE_REQ: /* 0x0040 */
  6190. SET_CFG80211_REPORT_MGMT(pwdev_priv, IEEE80211_STYPE_PROBE_REQ, reg);
  6191. break;
  6192. case IEEE80211_STYPE_ACTION: /* 0x00D0 */
  6193. SET_CFG80211_REPORT_MGMT(pwdev_priv, IEEE80211_STYPE_ACTION, reg);
  6194. break;
  6195. default:
  6196. break;
  6197. }
  6198. exit:
  6199. return;
  6200. }
  6201. #if defined(CONFIG_TDLS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  6202. static int cfg80211_rtw_tdls_mgmt(struct wiphy *wiphy,
  6203. struct net_device *ndev,
  6204. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  6205. const u8 *peer,
  6206. #else
  6207. u8 *peer,
  6208. #endif
  6209. u8 action_code,
  6210. u8 dialog_token,
  6211. u16 status_code,
  6212. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0))
  6213. u32 peer_capability,
  6214. #endif
  6215. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0))
  6216. bool initiator,
  6217. #endif
  6218. const u8 *buf,
  6219. size_t len)
  6220. {
  6221. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  6222. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  6223. struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  6224. int ret = 0;
  6225. struct tdls_txmgmt txmgmt;
  6226. if (hal_chk_wl_func(padapter, WL_FUNC_TDLS) == _FALSE) {
  6227. RTW_INFO("Discard tdls action:%d, since hal doesn't support tdls\n", action_code);
  6228. goto discard;
  6229. }
  6230. if (rtw_is_tdls_enabled(padapter) == _FALSE) {
  6231. RTW_INFO("TDLS is not enabled\n");
  6232. goto discard;
  6233. }
  6234. if (rtw_tdls_is_driver_setup(padapter)) {
  6235. RTW_INFO("Discard tdls action:%d, let driver to set up direct link\n", action_code);
  6236. goto discard;
  6237. }
  6238. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  6239. _rtw_memcpy(txmgmt.peer, peer, ETH_ALEN);
  6240. txmgmt.action_code = action_code;
  6241. txmgmt.dialog_token = dialog_token;
  6242. txmgmt.status_code = status_code;
  6243. txmgmt.len = len;
  6244. txmgmt.buf = (u8 *)rtw_malloc(txmgmt.len);
  6245. if (txmgmt.buf == NULL) {
  6246. ret = -ENOMEM;
  6247. goto bad;
  6248. }
  6249. _rtw_memcpy(txmgmt.buf, (void *)buf, txmgmt.len);
  6250. /* Debug purpose */
  6251. #if 1
  6252. RTW_INFO("%s %d\n", __FUNCTION__, __LINE__);
  6253. RTW_INFO("peer:"MAC_FMT", action code:%d, dialog:%d, status code:%d\n",
  6254. MAC_ARG(txmgmt.peer), txmgmt.action_code,
  6255. txmgmt.dialog_token, txmgmt.status_code);
  6256. if (txmgmt.len > 0) {
  6257. int i = 0;
  6258. for (; i < len; i++)
  6259. printk("%02x ", *(txmgmt.buf + i));
  6260. RTW_INFO("len:%d\n", (u32)txmgmt.len);
  6261. }
  6262. #endif
  6263. switch (txmgmt.action_code) {
  6264. case TDLS_SETUP_REQUEST:
  6265. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  6266. break;
  6267. case TDLS_SETUP_RESPONSE:
  6268. issue_tdls_setup_rsp(padapter, &txmgmt);
  6269. break;
  6270. case TDLS_SETUP_CONFIRM:
  6271. issue_tdls_setup_cfm(padapter, &txmgmt);
  6272. break;
  6273. case TDLS_TEARDOWN:
  6274. issue_tdls_teardown(padapter, &txmgmt, _TRUE);
  6275. break;
  6276. case TDLS_DISCOVERY_REQUEST:
  6277. issue_tdls_dis_req(padapter, &txmgmt);
  6278. break;
  6279. case TDLS_DISCOVERY_RESPONSE:
  6280. issue_tdls_dis_rsp(padapter, &txmgmt, pmlmeinfo->enc_algo ? _TRUE : _FALSE);
  6281. break;
  6282. }
  6283. bad:
  6284. if (txmgmt.buf)
  6285. rtw_mfree(txmgmt.buf, txmgmt.len);
  6286. discard:
  6287. return ret;
  6288. }
  6289. static int cfg80211_rtw_tdls_oper(struct wiphy *wiphy,
  6290. struct net_device *ndev,
  6291. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  6292. const u8 *peer,
  6293. #else
  6294. u8 *peer,
  6295. #endif
  6296. enum nl80211_tdls_operation oper)
  6297. {
  6298. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  6299. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  6300. struct tdls_txmgmt txmgmt;
  6301. struct sta_info *ptdls_sta = NULL;
  6302. RTW_INFO(FUNC_NDEV_FMT", nl80211_tdls_operation:%d\n", FUNC_NDEV_ARG(ndev), oper);
  6303. if (hal_chk_wl_func(padapter, WL_FUNC_TDLS) == _FALSE) {
  6304. RTW_INFO("Discard tdls oper:%d, since hal doesn't support tdls\n", oper);
  6305. return 0;
  6306. }
  6307. if (rtw_is_tdls_enabled(padapter) == _FALSE) {
  6308. RTW_INFO("TDLS is not enabled\n");
  6309. return 0;
  6310. }
  6311. #ifdef CONFIG_LPS
  6312. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, 1);
  6313. #endif /* CONFIG_LPS */
  6314. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  6315. if (peer)
  6316. _rtw_memcpy(txmgmt.peer, peer, ETH_ALEN);
  6317. if (rtw_tdls_is_driver_setup(padapter)) {
  6318. /* these two cases are done by driver itself */
  6319. if (oper == NL80211_TDLS_ENABLE_LINK || oper == NL80211_TDLS_DISABLE_LINK)
  6320. return 0;
  6321. }
  6322. switch (oper) {
  6323. case NL80211_TDLS_DISCOVERY_REQ:
  6324. issue_tdls_dis_req(padapter, &txmgmt);
  6325. break;
  6326. case NL80211_TDLS_SETUP:
  6327. #ifdef CONFIG_WFD
  6328. if (_AES_ != padapter->securitypriv.dot11PrivacyAlgrthm) {
  6329. if (padapter->wdinfo.wfd_tdls_weaksec == _TRUE)
  6330. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  6331. else
  6332. RTW_INFO("[%s] Current link is not AES, SKIP sending the tdls setup request!!\n", __FUNCTION__);
  6333. } else
  6334. #endif /* CONFIG_WFD */
  6335. {
  6336. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  6337. }
  6338. break;
  6339. case NL80211_TDLS_TEARDOWN:
  6340. ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), txmgmt.peer);
  6341. if (ptdls_sta != NULL) {
  6342. txmgmt.status_code = _RSON_TDLS_TEAR_UN_RSN_;
  6343. issue_tdls_teardown(padapter, &txmgmt, _TRUE);
  6344. } else
  6345. RTW_INFO("TDLS peer not found\n");
  6346. break;
  6347. case NL80211_TDLS_ENABLE_LINK:
  6348. RTW_INFO(FUNC_NDEV_FMT", NL80211_TDLS_ENABLE_LINK;mac:"MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(peer));
  6349. ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), (u8 *)peer);
  6350. if (ptdls_sta != NULL) {
  6351. rtw_tdls_set_link_established(padapter, _TRUE);
  6352. ptdls_sta->tdls_sta_state |= TDLS_LINKED_STATE;
  6353. ptdls_sta->state |= _FW_LINKED;
  6354. rtw_tdls_cmd(padapter, txmgmt.peer, TDLS_ESTABLISHED);
  6355. }
  6356. break;
  6357. case NL80211_TDLS_DISABLE_LINK:
  6358. RTW_INFO(FUNC_NDEV_FMT", NL80211_TDLS_DISABLE_LINK;mac:"MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(peer));
  6359. ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), (u8 *)peer);
  6360. if (ptdls_sta != NULL) {
  6361. rtw_tdls_teardown_pre_hdl(padapter, ptdls_sta);
  6362. rtw_tdls_cmd(padapter, (u8 *)peer, TDLS_TEARDOWN_STA_LOCALLY_POST);
  6363. }
  6364. break;
  6365. }
  6366. return 0;
  6367. }
  6368. #endif /* CONFIG_TDLS */
  6369. #if defined(CONFIG_RTW_MESH) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
  6370. #if DBG_RTW_CFG80211_MESH_CONF
  6371. #define LEGACY_RATES_STR_LEN (RTW_G_RATES_NUM * 5 + 1)
  6372. int get_legacy_rates_str(struct wiphy *wiphy, enum nl80211_band band, u32 mask, char *buf)
  6373. {
  6374. int i;
  6375. int cnt = 0;
  6376. for (i = 0; i < wiphy->bands[band]->n_bitrates; i++) {
  6377. if (mask & BIT(i)) {
  6378. cnt += snprintf(buf + cnt, LEGACY_RATES_STR_LEN - cnt -1, "%d.%d "
  6379. , wiphy->bands[band]->bitrates[i].bitrate / 10
  6380. , wiphy->bands[band]->bitrates[i].bitrate % 10);
  6381. if (cnt >= LEGACY_RATES_STR_LEN - 1)
  6382. break;
  6383. }
  6384. }
  6385. return cnt;
  6386. }
  6387. void dump_mesh_setup(void *sel, struct wiphy *wiphy, const struct mesh_setup *setup)
  6388. {
  6389. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6390. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6391. struct cfg80211_chan_def *chdef = (struct cfg80211_chan_def *)(&setup->chandef);
  6392. #endif
  6393. struct ieee80211_channel *chan;
  6394. #endif
  6395. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6396. chan = (struct ieee80211_channel *)chdef->chan;
  6397. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6398. chan = (struct ieee80211_channel *)setup->channel;
  6399. #endif
  6400. RTW_PRINT_SEL(sel, "mesh_id:\"%s\", len:%u\n", setup->mesh_id, setup->mesh_id_len);
  6401. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6402. RTW_PRINT_SEL(sel, "sync_method:%u\n", setup->sync_method);
  6403. #endif
  6404. RTW_PRINT_SEL(sel, "path_sel_proto:%u, path_metric:%u\n", setup->path_sel_proto, setup->path_metric);
  6405. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6406. RTW_PRINT_SEL(sel, "auth_id:%u\n", setup->auth_id);
  6407. #endif
  6408. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  6409. if (setup->ie && setup->ie_len) {
  6410. RTW_PRINT_SEL(sel, "ie:%p, len:%u\n", setup->ie, setup->ie_len);
  6411. dump_ies(RTW_DBGDUMP, setup->ie, setup->ie_len);
  6412. }
  6413. #else
  6414. if (setup->vendor_ie && setup->vendor_ie_len) {
  6415. RTW_PRINT_SEL(sel, "ie:%p, len:%u\n", setup->vendor_ie, setup->vendor_ie_len);
  6416. dump_ies(RTW_DBGDUMP, setup->vendor_ie, setup->vendor_ie_len);
  6417. }
  6418. #endif
  6419. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  6420. RTW_PRINT_SEL(sel, "is_authenticated:%d, is_secure:%d\n", setup->is_authenticated, setup->is_secure);
  6421. #endif
  6422. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  6423. RTW_PRINT_SEL(sel, "user_mpm:%d\n", setup->user_mpm);
  6424. #endif
  6425. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  6426. RTW_PRINT_SEL(sel, "dtim_period:%u, beacon_interval:%u\n", setup->dtim_period, setup->beacon_interval);
  6427. #endif
  6428. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6429. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6430. RTW_PRINT_SEL(sel, "center_freq:%u, ch:%u, width:%s, cfreq1:%u, cfreq2:%u\n"
  6431. , chan->center_freq, chan->hw_value, nl80211_chan_width_str(chdef->width), chdef->center_freq1, chdef->center_freq2);
  6432. #else
  6433. RTW_PRINT_SEL(sel, "center_freq:%u, ch:%u, channel_type:%s\n"
  6434. , chan->center_freq, chan->hw_value, nl80211_channel_type_str(setup->channel_type));
  6435. #endif
  6436. #endif
  6437. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  6438. if (setup->mcast_rate[chan->band]) {
  6439. RTW_PRINT_SEL(sel, "mcast_rate:%d.%d\n"
  6440. , wiphy->bands[chan->band]->bitrates[setup->mcast_rate[chan->band] - 1].bitrate / 10
  6441. , wiphy->bands[chan->band]->bitrates[setup->mcast_rate[chan->band] - 1].bitrate % 10
  6442. );
  6443. }
  6444. #endif
  6445. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6446. if (setup->basic_rates) {
  6447. char buf[LEGACY_RATES_STR_LEN] = {0};
  6448. get_legacy_rates_str(wiphy, chan->band, setup->basic_rates, buf);
  6449. RTW_PRINT_SEL(sel, "basic_rates:%s\n", buf);
  6450. }
  6451. #endif
  6452. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
  6453. if (setup->beacon_rate.control[chan->band].legacy) {
  6454. char buf[LEGACY_RATES_STR_LEN] = {0};
  6455. get_legacy_rates_str(wiphy, chan->band, setup->beacon_rate.control[chan->band].legacy, buf);
  6456. RTW_PRINT_SEL(sel, "beacon_rate.legacy:%s\n", buf);
  6457. }
  6458. if (*((u32 *)&(setup->beacon_rate.control[chan->band].ht_mcs[0]))
  6459. || *((u32 *)&(setup->beacon_rate.control[chan->band].ht_mcs[4]))
  6460. || *((u16 *)&(setup->beacon_rate.control[chan->band].ht_mcs[8]))
  6461. ) {
  6462. RTW_PRINT_SEL(sel, "beacon_rate.ht_mcs:"HT_RX_MCS_BMP_FMT"\n"
  6463. , HT_RX_MCS_BMP_ARG(setup->beacon_rate.control[chan->band].ht_mcs));
  6464. }
  6465. if (setup->beacon_rate.control[chan->band].vht_mcs[0]
  6466. || setup->beacon_rate.control[chan->band].vht_mcs[1]
  6467. || setup->beacon_rate.control[chan->band].vht_mcs[2]
  6468. || setup->beacon_rate.control[chan->band].vht_mcs[3]
  6469. ) {
  6470. int i;
  6471. for (i = 0; i < 4; i++) {/* parsing up to 4SS */
  6472. u16 mcs_mask = setup->beacon_rate.control[chan->band].vht_mcs[i];
  6473. RTW_PRINT_SEL(sel, "beacon_rate.vht_mcs[%d]:%s\n", i
  6474. , mcs_mask == 0x00FF ? "0~7" : mcs_mask == 0x01FF ? "0~8" : mcs_mask == 0x03FF ? "0~9" : "invalid");
  6475. }
  6476. }
  6477. if (setup->beacon_rate.control[chan->band].gi) {
  6478. RTW_PRINT_SEL(sel, "beacon_rate.gi:%s\n"
  6479. , setup->beacon_rate.control[chan->band].gi == NL80211_TXRATE_FORCE_SGI ? "SGI" :
  6480. setup->beacon_rate.control[chan->band].gi == NL80211_TXRATE_FORCE_LGI ? "LGI" : "invalid"
  6481. );
  6482. }
  6483. #endif
  6484. }
  6485. void dump_mesh_config(void *sel, const struct mesh_config *conf)
  6486. {
  6487. RTW_PRINT_SEL(sel, "dot11MeshRetryTimeout:%u\n", conf->dot11MeshRetryTimeout);
  6488. RTW_PRINT_SEL(sel, "dot11MeshConfirmTimeout:%u\n", conf->dot11MeshConfirmTimeout);
  6489. RTW_PRINT_SEL(sel, "dot11MeshHoldingTimeout:%u\n", conf->dot11MeshHoldingTimeout);
  6490. RTW_PRINT_SEL(sel, "dot11MeshMaxPeerLinks:%u\n", conf->dot11MeshMaxPeerLinks);
  6491. RTW_PRINT_SEL(sel, "dot11MeshMaxRetries:%u\n", conf->dot11MeshMaxRetries);
  6492. RTW_PRINT_SEL(sel, "dot11MeshTTL:%u\n", conf->dot11MeshTTL);
  6493. RTW_PRINT_SEL(sel, "element_ttl:%u\n", conf->element_ttl);
  6494. RTW_PRINT_SEL(sel, "auto_open_plinks:%d\n", conf->auto_open_plinks);
  6495. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6496. RTW_PRINT_SEL(sel, "dot11MeshNbrOffsetMaxNeighbor:%u\n", conf->dot11MeshNbrOffsetMaxNeighbor);
  6497. #endif
  6498. RTW_PRINT_SEL(sel, "dot11MeshHWMPmaxPREQretries:%u\n", conf->dot11MeshHWMPmaxPREQretries);
  6499. RTW_PRINT_SEL(sel, "path_refresh_time:%u\n", conf->path_refresh_time);
  6500. RTW_PRINT_SEL(sel, "min_discovery_timeout:%u\n", conf->min_discovery_timeout);
  6501. RTW_PRINT_SEL(sel, "dot11MeshHWMPactivePathTimeout:%u\n", conf->dot11MeshHWMPactivePathTimeout);
  6502. RTW_PRINT_SEL(sel, "dot11MeshHWMPpreqMinInterval:%u\n", conf->dot11MeshHWMPpreqMinInterval);
  6503. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  6504. RTW_PRINT_SEL(sel, "dot11MeshHWMPperrMinInterval:%u\n", conf->dot11MeshHWMPperrMinInterval);
  6505. #endif
  6506. RTW_PRINT_SEL(sel, "dot11MeshHWMPnetDiameterTraversalTime:%u\n", conf->dot11MeshHWMPnetDiameterTraversalTime);
  6507. RTW_PRINT_SEL(sel, "dot11MeshHWMPRootMode:%u\n", conf->dot11MeshHWMPRootMode);
  6508. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  6509. RTW_PRINT_SEL(sel, "dot11MeshHWMPRannInterval:%u\n", conf->dot11MeshHWMPRannInterval);
  6510. RTW_PRINT_SEL(sel, "dot11MeshGateAnnouncementProtocol:%d\n", conf->dot11MeshGateAnnouncementProtocol);
  6511. #endif
  6512. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
  6513. RTW_PRINT_SEL(sel, "dot11MeshForwarding:%d\n", conf->dot11MeshForwarding);
  6514. RTW_PRINT_SEL(sel, "rssi_threshold:%d\n", conf->rssi_threshold);
  6515. #endif
  6516. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6517. RTW_PRINT_SEL(sel, "ht_opmode:0x%04x\n", conf->ht_opmode);
  6518. #endif
  6519. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6520. RTW_PRINT_SEL(sel, "dot11MeshHWMPactivePathToRootTimeout:%u\n", conf->dot11MeshHWMPactivePathToRootTimeout);
  6521. RTW_PRINT_SEL(sel, "dot11MeshHWMProotInterval:%u\n", conf->dot11MeshHWMProotInterval);
  6522. RTW_PRINT_SEL(sel, "dot11MeshHWMPconfirmationInterval:%u\n", conf->dot11MeshHWMPconfirmationInterval);
  6523. #endif
  6524. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  6525. RTW_PRINT_SEL(sel, "power_mode:%s\n", nl80211_mesh_power_mode_str(conf->power_mode));
  6526. RTW_PRINT_SEL(sel, "dot11MeshAwakeWindowDuration:%u\n", conf->dot11MeshAwakeWindowDuration);
  6527. #endif
  6528. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6529. RTW_PRINT_SEL(sel, "plink_timeout:%u\n", conf->plink_timeout);
  6530. #endif
  6531. }
  6532. #endif /* DBG_RTW_CFG80211_MESH_CONF */
  6533. static void rtw_cfg80211_mesh_info_set_profile(struct rtw_mesh_info *minfo, const struct mesh_setup *setup)
  6534. {
  6535. _rtw_memcpy(minfo->mesh_id, setup->mesh_id, setup->mesh_id_len);
  6536. minfo->mesh_id_len = setup->mesh_id_len;
  6537. minfo->mesh_pp_id = setup->path_sel_proto;
  6538. minfo->mesh_pm_id = setup->path_metric;
  6539. minfo->mesh_cc_id = 0;
  6540. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6541. minfo->mesh_sp_id = setup->sync_method;
  6542. #endif
  6543. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6544. minfo->mesh_auth_id = setup->auth_id;
  6545. #else
  6546. if (setup->is_authenticated) {
  6547. u8 *rsn_ie;
  6548. sint rsn_ie_len;
  6549. struct rsne_info info;
  6550. u8 *akm;
  6551. u8 AKM_SUITE_SAE[4] = {0x00, 0x0F, 0xAC, 0x08};
  6552. rsn_ie = rtw_get_ie(setup->ie, WLAN_EID_RSN, &rsn_ie_len, setup->ie_len);
  6553. if (!rsn_ie || !rsn_ie_len) {
  6554. rtw_warn_on(1);
  6555. return;
  6556. }
  6557. if (rtw_rsne_info_parse(rsn_ie, rsn_ie_len + 2, &info) != _SUCCESS) {
  6558. rtw_warn_on(1);
  6559. return;
  6560. }
  6561. if (!info.akm_list || !info.akm_cnt) {
  6562. rtw_warn_on(1);
  6563. return;
  6564. }
  6565. akm = info.akm_list;
  6566. while (akm < info.akm_list + info.akm_cnt * 4) {
  6567. if (_rtw_memcmp(akm, AKM_SUITE_SAE, 4) == _TRUE) {
  6568. minfo->mesh_auth_id = 0x01;
  6569. break;
  6570. }
  6571. }
  6572. if (!minfo->mesh_auth_id) {
  6573. rtw_warn_on(1);
  6574. return;
  6575. }
  6576. }
  6577. #endif
  6578. }
  6579. static inline bool chk_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  6580. {
  6581. return (mask >> (parm - 1)) & 0x1;
  6582. }
  6583. static void rtw_cfg80211_mesh_cfg_set(_adapter *adapter, const struct mesh_config *conf, u32 mask)
  6584. {
  6585. struct rtw_mesh_cfg *mcfg = &adapter->mesh_cfg;
  6586. #if 0 /* driver MPM */
  6587. if (chk_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask));
  6588. if (chk_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask));
  6589. if (chk_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask));
  6590. if (chk_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask));
  6591. if (chk_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask));
  6592. #endif
  6593. if (chk_mesh_attr(NL80211_MESHCONF_TTL, mask))
  6594. mcfg->dot11MeshTTL = conf->dot11MeshTTL;
  6595. if (chk_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  6596. mcfg->element_ttl = conf->element_ttl;
  6597. #if 0 /* driver MPM */
  6598. if (chk_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask));
  6599. #endif
  6600. #if 0 /* TBD: synchronization */
  6601. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6602. if (chk_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask));
  6603. #endif
  6604. #endif
  6605. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  6606. mcfg->dot11MeshHWMPmaxPREQretries = conf->dot11MeshHWMPmaxPREQretries;
  6607. if (chk_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  6608. mcfg->path_refresh_time = conf->path_refresh_time;
  6609. if (chk_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  6610. mcfg->min_discovery_timeout = conf->min_discovery_timeout;
  6611. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  6612. mcfg->dot11MeshHWMPactivePathTimeout = conf->dot11MeshHWMPactivePathTimeout;
  6613. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  6614. mcfg->dot11MeshHWMPpreqMinInterval = conf->dot11MeshHWMPpreqMinInterval;
  6615. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  6616. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  6617. mcfg->dot11MeshHWMPperrMinInterval = conf->dot11MeshHWMPperrMinInterval;
  6618. #endif
  6619. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, mask))
  6620. mcfg->dot11MeshHWMPnetDiameterTraversalTime = conf->dot11MeshHWMPnetDiameterTraversalTime;
  6621. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask))
  6622. mcfg->dot11MeshHWMPRootMode = conf->dot11MeshHWMPRootMode;
  6623. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  6624. if (chk_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask))
  6625. mcfg->dot11MeshGateAnnouncementProtocol = conf->dot11MeshGateAnnouncementProtocol;
  6626. /* our current gate annc implementation rides on root annc with gate annc bit in PREQ flags */
  6627. if (mcfg->dot11MeshGateAnnouncementProtocol
  6628. && mcfg->dot11MeshHWMPRootMode <= RTW_IEEE80211_ROOTMODE_ROOT
  6629. ) {
  6630. mcfg->dot11MeshHWMPRootMode = RTW_IEEE80211_PROACTIVE_RANN;
  6631. RTW_INFO(ADPT_FMT" enable PROACTIVE_RANN becaue gate annc is needed\n", ADPT_ARG(adapter));
  6632. }
  6633. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  6634. mcfg->dot11MeshHWMPRannInterval = conf->dot11MeshHWMPRannInterval;
  6635. #endif
  6636. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
  6637. if (chk_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  6638. mcfg->dot11MeshForwarding = conf->dot11MeshForwarding;
  6639. if (chk_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask))
  6640. mcfg->rssi_threshold = conf->rssi_threshold;
  6641. #endif
  6642. #if 0 /* controlled by driver */
  6643. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6644. if (chk_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask));
  6645. #endif
  6646. #endif
  6647. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6648. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  6649. mcfg->dot11MeshHWMPactivePathToRootTimeout = conf->dot11MeshHWMPactivePathToRootTimeout;
  6650. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  6651. mcfg->dot11MeshHWMProotInterval = conf->dot11MeshHWMProotInterval;
  6652. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  6653. mcfg->dot11MeshHWMPconfirmationInterval = conf->dot11MeshHWMPconfirmationInterval;
  6654. #endif
  6655. #if 0 /* TBD */
  6656. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  6657. if (chk_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask));
  6658. if (chk_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask));
  6659. #endif
  6660. #endif
  6661. #if 0 /* driver MPM */
  6662. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6663. if (chk_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask));
  6664. #endif
  6665. #endif
  6666. }
  6667. u8 *rtw_cfg80211_construct_mesh_beacon_ies(struct wiphy *wiphy, _adapter *adapter
  6668. , const struct mesh_config *conf, const struct mesh_setup *setup
  6669. , uint *ies_len)
  6670. {
  6671. struct rtw_mesh_info *minfo = &adapter->mesh_info;
  6672. struct rtw_mesh_cfg *mcfg = &adapter->mesh_cfg;
  6673. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6674. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6675. struct cfg80211_chan_def *chdef = (struct cfg80211_chan_def *)(&setup->chandef);
  6676. #endif
  6677. struct ieee80211_channel *chan;
  6678. u8 ch, bw, offset;
  6679. #endif
  6680. uint len;
  6681. u8 n_bitrates;
  6682. u8 ht = 0;
  6683. u8 vht = 0;
  6684. u8 *rsn_ie = NULL;
  6685. sint rsn_ie_len = 0;
  6686. u8 *ies = NULL, *c;
  6687. u8 supported_rates[RTW_G_RATES_NUM] = {0};
  6688. int i;
  6689. *ies_len = 0;
  6690. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6691. chan = (struct ieee80211_channel *)chdef->chan;
  6692. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6693. chan = (struct ieee80211_channel *)setup->channel;
  6694. #endif
  6695. n_bitrates = wiphy->bands[chan->band]->n_bitrates;
  6696. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6697. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6698. rtw_get_chbw_from_cfg80211_chan_def(chdef, &ht, &ch, &bw, &offset);
  6699. #else
  6700. rtw_get_chbw_from_nl80211_channel_type(chan, setup->channel_type, &ht, &ch, &bw, &offset);
  6701. #endif
  6702. if (!ch)
  6703. goto exit;
  6704. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6705. vht = ht && ch > 14 && bw >= CHANNEL_WIDTH_80; /* VHT40/VHT20? */
  6706. #endif
  6707. RTW_INFO(FUNC_ADPT_FMT" => ch:%u,%u,%u, ht:%u, vht:%u\n"
  6708. , FUNC_ADPT_ARG(adapter), ch, bw, offset, ht, vht);
  6709. #endif
  6710. rsn_ie = rtw_get_ie(setup->ie, WLAN_EID_RSN, &rsn_ie_len, setup->ie_len);
  6711. if (rsn_ie && !rsn_ie_len) {
  6712. rtw_warn_on(1);
  6713. rsn_ie = NULL;
  6714. }
  6715. len = _BEACON_IE_OFFSET_
  6716. + 2 /* 0-length SSID */
  6717. + (n_bitrates >= 8 ? 8 : n_bitrates) + 2 /* Supported Rates */
  6718. + 3 /* DS parameter set */
  6719. + 6 /* TIM */
  6720. + (n_bitrates > 8 ? n_bitrates - 8 + 2 : 0) /* Extended Supported Rates */
  6721. + (rsn_ie ? rsn_ie_len + 2 : 0) /* RSN */
  6722. #if defined(CONFIG_80211N_HT)
  6723. + (ht ? HT_CAP_IE_LEN + 2 + HT_OP_IE_LEN + 2 : 0) /* HT */
  6724. #endif
  6725. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6726. + (vht ? VHT_CAP_IE_LEN + 2 + VHT_OP_IE_LEN + 2 : 0) /* VHT */
  6727. #endif
  6728. + minfo->mesh_id_len + 2 /* Mesh ID */
  6729. + 9 /* Mesh configuration */
  6730. ;
  6731. ies = rtw_zmalloc(len);
  6732. if (!ies)
  6733. goto exit;
  6734. /* timestamp */
  6735. c = ies + 8;
  6736. /* beacon interval */
  6737. RTW_PUT_LE16(c , setup->beacon_interval);
  6738. c += 2;
  6739. /* capability */
  6740. if (rsn_ie)
  6741. *((u16 *)c) |= cpu_to_le16(cap_Privacy);
  6742. c += 2;
  6743. /* SSID */
  6744. c = rtw_set_ie(c, WLAN_EID_SSID, 0, NULL, NULL);
  6745. /* Supported Rates */
  6746. for (i = 0; i < n_bitrates; i++) {
  6747. supported_rates[i] = wiphy->bands[chan->band]->bitrates[i].bitrate / 5;
  6748. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6749. if (setup->basic_rates & BIT(i))
  6750. #else
  6751. if (rtw_is_basic_rate_mix(supported_rates[i]))
  6752. #endif
  6753. supported_rates[i] |= IEEE80211_BASIC_RATE_MASK;
  6754. }
  6755. c = rtw_set_ie(c, WLAN_EID_SUPP_RATES, (n_bitrates >= 8 ? 8 : n_bitrates), supported_rates, NULL);
  6756. /* DS parameter set */
  6757. c = rtw_set_ie(c, WLAN_EID_DS_PARAMS, 1, &ch, NULL);
  6758. /* TIM */
  6759. *c = WLAN_EID_TIM;
  6760. *(c + 1) = 4;
  6761. c += 6;
  6762. //c = rtw_set_ie(c, _TIM_IE_, 4, NULL, NULL);
  6763. /* Extended Supported Rates */
  6764. if (n_bitrates > 8)
  6765. c = rtw_set_ie(c, WLAN_EID_EXT_SUPP_RATES, n_bitrates - 8, supported_rates + 8, NULL);
  6766. /* RSN */
  6767. if (rsn_ie)
  6768. c = rtw_set_ie(c, WLAN_EID_RSN, rsn_ie_len, rsn_ie + 2, NULL);
  6769. #if defined(CONFIG_80211N_HT)
  6770. if (ht) {
  6771. struct ieee80211_sta_ht_cap *sta_ht_cap = &wiphy->bands[chan->band]->ht_cap;
  6772. u8 ht_cap[HT_CAP_IE_LEN];
  6773. u8 ht_op[HT_OP_IE_LEN];
  6774. _rtw_memset(ht_cap, 0, HT_CAP_IE_LEN);
  6775. _rtw_memset(ht_op, 0, HT_OP_IE_LEN);
  6776. /* WLAN_EID_HT_CAP */
  6777. RTW_PUT_LE16(HT_CAP_ELE_CAP_INFO(ht_cap), sta_ht_cap->cap);
  6778. SET_HT_CAP_ELE_MAX_AMPDU_LEN_EXP(ht_cap, sta_ht_cap->ampdu_factor);
  6779. SET_HT_CAP_ELE_MIN_MPDU_S_SPACE(ht_cap, sta_ht_cap->ampdu_density);
  6780. _rtw_memcpy(HT_CAP_ELE_SUP_MCS_SET(ht_cap), &sta_ht_cap->mcs, 16);
  6781. c = rtw_set_ie(c, WLAN_EID_HT_CAP, HT_CAP_IE_LEN, ht_cap, NULL);
  6782. /* WLAN_EID_HT_OPERATION */
  6783. SET_HT_OP_ELE_PRI_CHL(ht_op, ch);
  6784. switch (offset) {
  6785. case HAL_PRIME_CHNL_OFFSET_LOWER:
  6786. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op, SCA);
  6787. break;
  6788. case HAL_PRIME_CHNL_OFFSET_UPPER:
  6789. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op, SCB);
  6790. break;
  6791. case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
  6792. default:
  6793. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op, SCN);
  6794. break;
  6795. }
  6796. if (bw >= CHANNEL_WIDTH_40)
  6797. SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op, 1);
  6798. else
  6799. SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op, 0);
  6800. c = rtw_set_ie(c, WLAN_EID_HT_OPERATION, HT_OP_IE_LEN, ht_op, NULL);
  6801. }
  6802. #endif /* defined(CONFIG_80211N_HT) */
  6803. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6804. if (vht) {
  6805. struct ieee80211_sta_vht_cap *sta_vht_cap = &wiphy->bands[chan->band]->vht_cap;
  6806. u8 vht_cap[VHT_CAP_IE_LEN];
  6807. u8 vht_op[VHT_OP_IE_LEN];
  6808. u8 cch = rtw_get_center_ch(ch, bw, offset);
  6809. _rtw_memset(vht_op, 0, VHT_OP_IE_LEN);
  6810. /* WLAN_EID_VHT_CAPABILITY */
  6811. _rtw_memcpy(vht_cap, &sta_vht_cap->cap, 4);
  6812. _rtw_memcpy(vht_cap + 4, &sta_vht_cap->vht_mcs, 8);
  6813. c = rtw_set_ie(c, WLAN_EID_VHT_CAPABILITY, VHT_CAP_IE_LEN, vht_cap, NULL);
  6814. /* WLAN_EID_VHT_OPERATION */
  6815. if (bw < CHANNEL_WIDTH_80) {
  6816. SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op, 0);
  6817. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op, 0);
  6818. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op, 0);
  6819. } else if (bw == CHANNEL_WIDTH_80) {
  6820. SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op, 1);
  6821. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op, cch);
  6822. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op, 0);
  6823. } else {
  6824. RTW_ERR(FUNC_ADPT_FMT" unsupported BW:%u\n", FUNC_ADPT_ARG(adapter), bw);
  6825. rtw_warn_on(1);
  6826. rtw_mfree(ies, len);
  6827. goto exit;
  6828. }
  6829. /* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
  6830. vht_op[3] = 0xfc;
  6831. vht_op[4] = 0xff;
  6832. c = rtw_set_ie(c, WLAN_EID_VHT_OPERATION, VHT_OP_IE_LEN, vht_op, NULL);
  6833. }
  6834. #endif /* defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)) */
  6835. /* Mesh ID */
  6836. c = rtw_set_ie_mesh_id(c, NULL, minfo->mesh_id, minfo->mesh_id_len);
  6837. /* Mesh configuration */
  6838. c = rtw_set_ie_mesh_config(c, NULL
  6839. , minfo->mesh_pp_id
  6840. , minfo->mesh_pm_id
  6841. , minfo->mesh_cc_id
  6842. , minfo->mesh_sp_id
  6843. , minfo->mesh_auth_id
  6844. , 0, 0, 0
  6845. , 1
  6846. , 0, 0
  6847. , mcfg->dot11MeshForwarding
  6848. , 0, 0, 0
  6849. );
  6850. #if DBG_RTW_CFG80211_MESH_CONF
  6851. RTW_INFO(FUNC_ADPT_FMT" ies_len:%u\n", FUNC_ADPT_ARG(adapter), len);
  6852. dump_ies(RTW_DBGDUMP, ies + _BEACON_IE_OFFSET_, len - _BEACON_IE_OFFSET_);
  6853. #endif
  6854. exit:
  6855. if (ies)
  6856. *ies_len = len;
  6857. return ies;
  6858. }
  6859. static int cfg80211_rtw_get_mesh_config(struct wiphy *wiphy, struct net_device *dev
  6860. , struct mesh_config *conf)
  6861. {
  6862. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6863. struct rtw_mesh_cfg *mesh_cfg = &adapter->mesh_cfg;
  6864. int ret = 0;
  6865. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter));
  6866. /* driver MPM */
  6867. conf->dot11MeshRetryTimeout = 0;
  6868. conf->dot11MeshConfirmTimeout = 0;
  6869. conf->dot11MeshHoldingTimeout = 0;
  6870. conf->dot11MeshMaxPeerLinks = mesh_cfg->max_peer_links;
  6871. conf->dot11MeshMaxRetries = 0;
  6872. conf->dot11MeshTTL = mesh_cfg->dot11MeshTTL;
  6873. conf->element_ttl = mesh_cfg->element_ttl;
  6874. /* driver MPM */
  6875. conf->auto_open_plinks = 0;
  6876. /* TBD: synchronization */
  6877. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6878. conf->dot11MeshNbrOffsetMaxNeighbor = 0;
  6879. #endif
  6880. conf->dot11MeshHWMPmaxPREQretries = mesh_cfg->dot11MeshHWMPmaxPREQretries;
  6881. conf->path_refresh_time = mesh_cfg->path_refresh_time;
  6882. conf->min_discovery_timeout = mesh_cfg->min_discovery_timeout;
  6883. conf->dot11MeshHWMPactivePathTimeout = mesh_cfg->dot11MeshHWMPactivePathTimeout;
  6884. conf->dot11MeshHWMPpreqMinInterval = mesh_cfg->dot11MeshHWMPpreqMinInterval;
  6885. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  6886. conf->dot11MeshHWMPperrMinInterval = mesh_cfg->dot11MeshHWMPperrMinInterval;
  6887. #endif
  6888. conf->dot11MeshHWMPnetDiameterTraversalTime = mesh_cfg->dot11MeshHWMPnetDiameterTraversalTime;
  6889. conf->dot11MeshHWMPRootMode = mesh_cfg->dot11MeshHWMPRootMode;
  6890. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  6891. conf->dot11MeshHWMPRannInterval = mesh_cfg->dot11MeshHWMPRannInterval;
  6892. #endif
  6893. conf->dot11MeshGateAnnouncementProtocol = mesh_cfg->dot11MeshGateAnnouncementProtocol;
  6894. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
  6895. conf->dot11MeshForwarding = mesh_cfg->dot11MeshForwarding;
  6896. conf->rssi_threshold = mesh_cfg->rssi_threshold;
  6897. #endif
  6898. /* TBD */
  6899. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6900. conf->ht_opmode = 0xffff;
  6901. #endif
  6902. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6903. conf->dot11MeshHWMPactivePathToRootTimeout = mesh_cfg->dot11MeshHWMPactivePathToRootTimeout;
  6904. conf->dot11MeshHWMProotInterval = mesh_cfg->dot11MeshHWMProotInterval;
  6905. conf->dot11MeshHWMPconfirmationInterval = mesh_cfg->dot11MeshHWMPconfirmationInterval;
  6906. #endif
  6907. /* TBD: power save */
  6908. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  6909. conf->power_mode = NL80211_MESH_POWER_ACTIVE;
  6910. conf->dot11MeshAwakeWindowDuration = 0;
  6911. #endif
  6912. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6913. conf->plink_timeout = mesh_cfg->plink_timeout;
  6914. #endif
  6915. return ret;
  6916. }
  6917. static void rtw_mbss_info_change_notify(_adapter *adapter, bool minfo_changed, bool need_work)
  6918. {
  6919. if (need_work)
  6920. rtw_mesh_work(&adapter->mesh_work);
  6921. }
  6922. static int cfg80211_rtw_update_mesh_config(struct wiphy *wiphy, struct net_device *dev
  6923. , u32 mask, const struct mesh_config *nconf)
  6924. {
  6925. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6926. int ret = 0;
  6927. bool minfo_changed = _FALSE, need_work = _FALSE;
  6928. RTW_INFO(FUNC_ADPT_FMT" mask:0x%08x\n", FUNC_ADPT_ARG(adapter), mask);
  6929. rtw_cfg80211_mesh_cfg_set(adapter, nconf, mask);
  6930. update_beacon(adapter, WLAN_EID_MESH_CONFIG, NULL, _TRUE);
  6931. #if CONFIG_RTW_MESH_CTO_MGATE_CARRIER
  6932. if (rtw_mesh_cto_mgate_required(adapter))
  6933. rtw_netif_carrier_off(adapter->pnetdev);
  6934. else
  6935. rtw_netif_carrier_on(adapter->pnetdev);
  6936. #endif
  6937. need_work = rtw_ieee80211_mesh_root_setup(adapter);
  6938. rtw_mbss_info_change_notify(adapter, minfo_changed, need_work);
  6939. return ret;
  6940. }
  6941. static int cfg80211_rtw_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  6942. const struct mesh_config *conf, const struct mesh_setup *setup)
  6943. {
  6944. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6945. u8 *ies = NULL;
  6946. uint ies_len;
  6947. int ret = 0;
  6948. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter));
  6949. #if DBG_RTW_CFG80211_MESH_CONF
  6950. RTW_INFO(FUNC_ADPT_FMT" mesh_setup:\n", FUNC_ADPT_ARG(adapter));
  6951. dump_mesh_setup(RTW_DBGDUMP, wiphy, setup);
  6952. RTW_INFO(FUNC_ADPT_FMT" mesh_config:\n", FUNC_ADPT_ARG(adapter));
  6953. dump_mesh_config(RTW_DBGDUMP, conf);
  6954. #endif
  6955. if (rtw_cfg80211_sync_iftype(adapter) != _SUCCESS) {
  6956. ret = -ENOTSUPP;
  6957. goto exit;
  6958. }
  6959. /* initialization */
  6960. rtw_mesh_init_mesh_info(adapter);
  6961. /* apply cfg80211 settings*/
  6962. rtw_cfg80211_mesh_info_set_profile(&adapter->mesh_info, setup);
  6963. rtw_cfg80211_mesh_cfg_set(adapter, conf, 0xFFFFFFFF);
  6964. /* apply cfg80211 settings (join only) */
  6965. rtw_mesh_cfg_init_max_peer_links(adapter, conf->dot11MeshMaxPeerLinks);
  6966. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6967. rtw_mesh_cfg_init_plink_timeout(adapter, conf->plink_timeout);
  6968. #endif
  6969. rtw_ieee80211_mesh_root_setup(adapter);
  6970. ies = rtw_cfg80211_construct_mesh_beacon_ies(wiphy, adapter, conf, setup, &ies_len);
  6971. if (!ies) {
  6972. ret = -EINVAL;
  6973. goto exit;
  6974. }
  6975. /* start mbss */
  6976. if (rtw_check_beacon_data(adapter, ies, ies_len) != _SUCCESS) {
  6977. ret = -EINVAL;
  6978. goto exit;
  6979. }
  6980. rtw_mesh_work(&adapter->mesh_work);
  6981. exit:
  6982. if (ies)
  6983. rtw_mfree(ies, ies_len);
  6984. if (ret)
  6985. rtw_mesh_deinit_mesh_info(adapter);
  6986. return ret;
  6987. }
  6988. static int cfg80211_rtw_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  6989. {
  6990. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6991. int ret = 0;
  6992. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter));
  6993. rtw_mesh_deinit_mesh_info(adapter);
  6994. rtw_set_802_11_infrastructure_mode(adapter, Ndis802_11Infrastructure);
  6995. rtw_setopmode_cmd(adapter, Ndis802_11Infrastructure, RTW_CMDF_WAIT_ACK);
  6996. return ret;
  6997. }
  6998. static int cfg80211_rtw_add_mpath(struct wiphy *wiphy, struct net_device *dev
  6999. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  7000. , const u8 *dst, const u8 *next_hop
  7001. #else
  7002. , u8 *dst, u8 *next_hop
  7003. #endif
  7004. )
  7005. {
  7006. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7007. struct sta_priv *stapriv = &adapter->stapriv;
  7008. struct sta_info *sta;
  7009. struct rtw_mesh_path *mpath;
  7010. int ret = 0;
  7011. rtw_rcu_read_lock();
  7012. sta = rtw_get_stainfo(stapriv, next_hop);
  7013. if (!sta) {
  7014. ret = -ENOENT;
  7015. goto exit;
  7016. }
  7017. mpath = rtw_mesh_path_add(adapter, dst);
  7018. if (!mpath) {
  7019. ret = -ENOENT;
  7020. goto exit;
  7021. }
  7022. rtw_mesh_path_fix_nexthop(mpath, sta);
  7023. exit:
  7024. rtw_rcu_read_unlock();
  7025. return ret;
  7026. }
  7027. static int cfg80211_rtw_del_mpath(struct wiphy *wiphy, struct net_device *dev
  7028. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  7029. , const u8 *dst
  7030. #else
  7031. , u8 *dst
  7032. #endif
  7033. )
  7034. {
  7035. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7036. int ret = 0;
  7037. if (dst) {
  7038. if (rtw_mesh_path_del(adapter, dst)) {
  7039. ret = -ENOENT;
  7040. goto exit;
  7041. }
  7042. } else {
  7043. rtw_mesh_path_flush_by_iface(adapter);
  7044. }
  7045. exit:
  7046. return ret;
  7047. }
  7048. static int cfg80211_rtw_change_mpath(struct wiphy *wiphy, struct net_device *dev
  7049. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  7050. , const u8 *dst, const u8 *next_hop
  7051. #else
  7052. , u8 *dst, u8 *next_hop
  7053. #endif
  7054. )
  7055. {
  7056. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7057. struct sta_priv *stapriv = &adapter->stapriv;
  7058. struct sta_info *sta;
  7059. struct rtw_mesh_path *mpath;
  7060. int ret = 0;
  7061. rtw_rcu_read_lock();
  7062. sta = rtw_get_stainfo(stapriv, next_hop);
  7063. if (!sta) {
  7064. ret = -ENOENT;
  7065. goto exit;
  7066. }
  7067. mpath = rtw_mesh_path_lookup(adapter, dst);
  7068. if (!mpath) {
  7069. ret = -ENOENT;
  7070. goto exit;
  7071. }
  7072. rtw_mesh_path_fix_nexthop(mpath, sta);
  7073. exit:
  7074. rtw_rcu_read_unlock();
  7075. return ret;
  7076. }
  7077. static void rtw_cfg80211_mpath_set_pinfo(struct rtw_mesh_path *mpath, u8 *next_hop, struct mpath_info *pinfo)
  7078. {
  7079. struct sta_info *next_hop_sta = rtw_rcu_dereference(mpath->next_hop);
  7080. if (next_hop_sta)
  7081. _rtw_memcpy(next_hop, next_hop_sta->cmn.mac_addr, ETH_ALEN);
  7082. else
  7083. _rtw_memset(next_hop, 0, ETH_ALEN);
  7084. _rtw_memset(pinfo, 0, sizeof(*pinfo));
  7085. pinfo->generation = mpath->adapter->mesh_info.mesh_paths_generation;
  7086. pinfo->filled = 0
  7087. | MPATH_INFO_FRAME_QLEN
  7088. | MPATH_INFO_SN
  7089. | MPATH_INFO_METRIC
  7090. | MPATH_INFO_EXPTIME
  7091. | MPATH_INFO_DISCOVERY_TIMEOUT
  7092. | MPATH_INFO_DISCOVERY_RETRIES
  7093. | MPATH_INFO_FLAGS
  7094. ;
  7095. pinfo->frame_qlen = mpath->frame_queue_len;
  7096. pinfo->sn = mpath->sn;
  7097. pinfo->metric = mpath->metric;
  7098. if (rtw_time_after(mpath->exp_time, rtw_get_current_time()))
  7099. pinfo->exptime = rtw_get_remaining_time_ms(mpath->exp_time);
  7100. pinfo->discovery_timeout = rtw_systime_to_ms(mpath->discovery_timeout);
  7101. pinfo->discovery_retries = mpath->discovery_retries;
  7102. if (mpath->flags & RTW_MESH_PATH_ACTIVE)
  7103. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  7104. if (mpath->flags & RTW_MESH_PATH_RESOLVING)
  7105. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  7106. if (mpath->flags & RTW_MESH_PATH_SN_VALID)
  7107. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  7108. if (mpath->flags & RTW_MESH_PATH_FIXED)
  7109. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  7110. if (mpath->flags & RTW_MESH_PATH_RESOLVED)
  7111. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
  7112. }
  7113. static int cfg80211_rtw_get_mpath(struct wiphy *wiphy, struct net_device *dev, u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  7114. {
  7115. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7116. struct rtw_mesh_path *mpath;
  7117. int ret = 0;
  7118. rtw_rcu_read_lock();
  7119. mpath = rtw_mesh_path_lookup(adapter, dst);
  7120. if (!mpath) {
  7121. ret = -ENOENT;
  7122. goto exit;
  7123. }
  7124. rtw_cfg80211_mpath_set_pinfo(mpath, next_hop, pinfo);
  7125. exit:
  7126. rtw_rcu_read_unlock();
  7127. return ret;
  7128. }
  7129. static int cfg80211_rtw_dump_mpath(struct wiphy *wiphy, struct net_device *dev, int idx, u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  7130. {
  7131. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7132. struct rtw_mesh_path *mpath;
  7133. int ret = 0;
  7134. rtw_rcu_read_lock();
  7135. mpath = rtw_mesh_path_lookup_by_idx(adapter, idx);
  7136. if (!mpath) {
  7137. ret = -ENOENT;
  7138. goto exit;
  7139. }
  7140. _rtw_memcpy(dst, mpath->dst, ETH_ALEN);
  7141. rtw_cfg80211_mpath_set_pinfo(mpath, next_hop, pinfo);
  7142. exit:
  7143. rtw_rcu_read_unlock();
  7144. return ret;
  7145. }
  7146. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0))
  7147. static void rtw_cfg80211_mpp_set_pinfo(struct rtw_mesh_path *mpath, u8 *mpp, struct mpath_info *pinfo)
  7148. {
  7149. _rtw_memcpy(mpp, mpath->mpp, ETH_ALEN);
  7150. _rtw_memset(pinfo, 0, sizeof(*pinfo));
  7151. pinfo->generation = mpath->adapter->mesh_info.mpp_paths_generation;
  7152. }
  7153. static int cfg80211_rtw_get_mpp(struct wiphy *wiphy, struct net_device *dev, u8 *dst, u8 *mpp, struct mpath_info *pinfo)
  7154. {
  7155. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7156. struct rtw_mesh_path *mpath;
  7157. int ret = 0;
  7158. rtw_rcu_read_lock();
  7159. mpath = rtw_mpp_path_lookup(adapter, dst);
  7160. if (!mpath) {
  7161. ret = -ENOENT;
  7162. goto exit;
  7163. }
  7164. rtw_cfg80211_mpp_set_pinfo(mpath, mpp, pinfo);
  7165. exit:
  7166. rtw_rcu_read_unlock();
  7167. return ret;
  7168. }
  7169. static int cfg80211_rtw_dump_mpp(struct wiphy *wiphy, struct net_device *dev, int idx, u8 *dst, u8 *mpp, struct mpath_info *pinfo)
  7170. {
  7171. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7172. struct rtw_mesh_path *mpath;
  7173. int ret = 0;
  7174. rtw_rcu_read_lock();
  7175. mpath = rtw_mpp_path_lookup_by_idx(adapter, idx);
  7176. if (!mpath) {
  7177. ret = -ENOENT;
  7178. goto exit;
  7179. }
  7180. _rtw_memcpy(dst, mpath->dst, ETH_ALEN);
  7181. rtw_cfg80211_mpp_set_pinfo(mpath, mpp, pinfo);
  7182. exit:
  7183. rtw_rcu_read_unlock();
  7184. return ret;
  7185. }
  7186. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) */
  7187. #endif /* defined(CONFIG_RTW_MESH) */
  7188. #if defined(CONFIG_PNO_SUPPORT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7189. static int cfg80211_rtw_sched_scan_start(struct wiphy *wiphy,
  7190. struct net_device *dev,
  7191. struct cfg80211_sched_scan_request *request)
  7192. {
  7193. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  7194. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7195. struct cfg80211_ssid *ssids;
  7196. int n_ssids = 0;
  7197. int interval = 0;
  7198. int i = 0;
  7199. u8 ret;
  7200. if (padapter->bup == _FALSE) {
  7201. RTW_INFO("%s: net device is down.\n", __func__);
  7202. return -EIO;
  7203. }
  7204. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE ||
  7205. check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE ||
  7206. check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE) {
  7207. RTW_INFO("%s: device is busy.\n", __func__);
  7208. rtw_scan_abort(padapter);
  7209. }
  7210. if (request == NULL) {
  7211. RTW_INFO("%s: invalid cfg80211_requests parameters.\n", __func__);
  7212. return -EINVAL;
  7213. }
  7214. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
  7215. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
  7216. interval = request->scan_plans->interval;
  7217. #else
  7218. interval = request->interval;
  7219. #endif
  7220. n_ssids = request->n_match_sets;
  7221. ssids = (struct cfg80211_ssid *)rtw_zmalloc(n_ssids * sizeof(struct cfg80211_ssid));
  7222. if(ssids == NULL) {
  7223. RTW_ERR("Fail to allocate ssids for PNO\n");
  7224. return -ENOMEM;
  7225. }
  7226. for (i=0;i<request->n_match_sets;i++) {
  7227. ssids[i].ssid_len = request->match_sets[i].ssid.ssid_len;
  7228. memcpy(ssids[i].ssid, request->match_sets[i].ssid.ssid,
  7229. request->match_sets[i].ssid.ssid_len);
  7230. }
  7231. #else
  7232. interval = request->interval;
  7233. n_ssids = request->n_ssids;
  7234. ssids = request->ssids;
  7235. #endif
  7236. ret = rtw_android_cfg80211_pno_setup(dev, ssids,
  7237. n_ssids, interval);
  7238. if (ret < 0) {
  7239. RTW_INFO("%s ret: %d\n", __func__, ret);
  7240. goto exit;
  7241. }
  7242. ret = rtw_android_pno_enable(dev, _TRUE);
  7243. if (ret < 0) {
  7244. RTW_INFO("%s ret: %d\n", __func__, ret);
  7245. goto exit;
  7246. }
  7247. exit:
  7248. return ret;
  7249. }
  7250. static int cfg80211_rtw_sched_scan_stop(struct wiphy *wiphy,
  7251. struct net_device *dev)
  7252. {
  7253. return rtw_android_pno_enable(dev, _FALSE);
  7254. }
  7255. int cfg80211_rtw_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wow) {
  7256. RTW_DBG("==> %s\n",__func__);
  7257. RTW_DBG("<== %s\n",__func__);
  7258. return 0;
  7259. }
  7260. int cfg80211_rtw_resume(struct wiphy *wiphy) {
  7261. _adapter *padapter;
  7262. struct pwrctrl_priv *pwrpriv;
  7263. struct mlme_priv *pmlmepriv;
  7264. padapter = wiphy_to_adapter(wiphy);
  7265. pwrpriv = adapter_to_pwrctl(padapter);
  7266. pmlmepriv = &padapter->mlmepriv;
  7267. struct sitesurvey_parm parm;
  7268. int i, len;
  7269. RTW_DBG("==> %s\n",__func__);
  7270. if (pwrpriv->wowlan_last_wake_reason == RX_PNO) {
  7271. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  7272. _irqL irqL;
  7273. int PNOWakeupScanWaitCnt = 0;
  7274. rtw_cfg80211_disconnected(padapter->rtw_wdev, 0, NULL, 0, 1, GFP_ATOMIC);
  7275. rtw_init_sitesurvey_parm(padapter, &parm);
  7276. for (i=0;i<pwrpriv->pnlo_info->ssid_num && i < RTW_SSID_SCAN_AMOUNT; i++) {
  7277. len = pwrpriv->pno_ssid_list->node[i].SSID_len;
  7278. _rtw_memcpy(&parm.ssid[i].Ssid, pwrpriv->pno_ssid_list->node[i].SSID, len);
  7279. parm.ssid[i].SsidLength = len;
  7280. }
  7281. parm.ssid_num = pwrpriv->pnlo_info->ssid_num;
  7282. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  7283. //This modification fix PNO wakeup reconnect issue with hidden SSID AP.
  7284. //rtw_sitesurvey_cmd(padapter, NULL);
  7285. rtw_sitesurvey_cmd(padapter, &parm);
  7286. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  7287. for (PNOWakeupScanWaitCnt = 0; PNOWakeupScanWaitCnt < 10; PNOWakeupScanWaitCnt++) {
  7288. if(check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _FALSE)
  7289. break;
  7290. rtw_msleep_os(1000);
  7291. }
  7292. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  7293. cfg80211_sched_scan_results(padapter->rtw_wdev->wiphy);
  7294. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  7295. }
  7296. RTW_DBG("<== %s\n",__func__);
  7297. return 0;
  7298. }
  7299. #endif /* CONFIG_PNO_SUPPORT */
  7300. static int rtw_cfg80211_set_beacon_wpsp2pie(struct net_device *ndev, char *buf, int len)
  7301. {
  7302. int ret = 0;
  7303. uint wps_ielen = 0;
  7304. u8 *wps_ie;
  7305. u32 p2p_ielen = 0;
  7306. u8 wps_oui[8] = {0x0, 0x50, 0xf2, 0x04};
  7307. u8 *p2p_ie;
  7308. u32 wfd_ielen = 0;
  7309. u8 *wfd_ie;
  7310. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  7311. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7312. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7313. RTW_INFO(FUNC_NDEV_FMT" ielen=%d\n", FUNC_NDEV_ARG(ndev), len);
  7314. if (len > 0) {
  7315. wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen);
  7316. if (wps_ie) {
  7317. #ifdef CONFIG_DEBUG_CFG80211
  7318. RTW_INFO("bcn_wps_ielen=%d\n", wps_ielen);
  7319. #endif
  7320. if (pmlmepriv->wps_beacon_ie) {
  7321. u32 free_len = pmlmepriv->wps_beacon_ie_len;
  7322. pmlmepriv->wps_beacon_ie_len = 0;
  7323. rtw_mfree(pmlmepriv->wps_beacon_ie, free_len);
  7324. pmlmepriv->wps_beacon_ie = NULL;
  7325. }
  7326. pmlmepriv->wps_beacon_ie = rtw_malloc(wps_ielen);
  7327. if (pmlmepriv->wps_beacon_ie == NULL) {
  7328. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7329. return -EINVAL;
  7330. }
  7331. _rtw_memcpy(pmlmepriv->wps_beacon_ie, wps_ie, wps_ielen);
  7332. pmlmepriv->wps_beacon_ie_len = wps_ielen;
  7333. update_beacon(padapter, _VENDOR_SPECIFIC_IE_, wps_oui, _TRUE);
  7334. }
  7335. /* buf += wps_ielen; */
  7336. /* len -= wps_ielen; */
  7337. #ifdef CONFIG_P2P
  7338. p2p_ie = rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen);
  7339. if (p2p_ie) {
  7340. #ifdef CONFIG_DEBUG_CFG80211
  7341. RTW_INFO("bcn_p2p_ielen=%d\n", p2p_ielen);
  7342. #endif
  7343. if (pmlmepriv->p2p_beacon_ie) {
  7344. u32 free_len = pmlmepriv->p2p_beacon_ie_len;
  7345. pmlmepriv->p2p_beacon_ie_len = 0;
  7346. rtw_mfree(pmlmepriv->p2p_beacon_ie, free_len);
  7347. pmlmepriv->p2p_beacon_ie = NULL;
  7348. }
  7349. pmlmepriv->p2p_beacon_ie = rtw_malloc(p2p_ielen);
  7350. if (pmlmepriv->p2p_beacon_ie == NULL) {
  7351. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7352. return -EINVAL;
  7353. }
  7354. _rtw_memcpy(pmlmepriv->p2p_beacon_ie, p2p_ie, p2p_ielen);
  7355. pmlmepriv->p2p_beacon_ie_len = p2p_ielen;
  7356. }
  7357. #endif /* CONFIG_P2P */
  7358. #ifdef CONFIG_WFD
  7359. wfd_ie = rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen);
  7360. if (wfd_ie) {
  7361. #ifdef CONFIG_DEBUG_CFG80211
  7362. RTW_INFO("bcn_wfd_ielen=%d\n", wfd_ielen);
  7363. #endif
  7364. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_BEACON_IE, wfd_ie, wfd_ielen) != _SUCCESS)
  7365. return -EINVAL;
  7366. }
  7367. #endif /* CONFIG_WFD */
  7368. pmlmeext->bstart_bss = _TRUE;
  7369. }
  7370. return ret;
  7371. }
  7372. static int rtw_cfg80211_set_probe_resp_wpsp2pie(struct net_device *net, char *buf, int len)
  7373. {
  7374. int ret = 0;
  7375. uint wps_ielen = 0;
  7376. u8 *wps_ie;
  7377. u32 p2p_ielen = 0;
  7378. u8 *p2p_ie;
  7379. u32 wfd_ielen = 0;
  7380. u8 *wfd_ie;
  7381. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  7382. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7383. #ifdef CONFIG_DEBUG_CFG80211
  7384. RTW_INFO("%s, ielen=%d\n", __func__, len);
  7385. #endif
  7386. if (len > 0) {
  7387. wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen);
  7388. if (wps_ie) {
  7389. uint attr_contentlen = 0;
  7390. u16 uconfig_method, *puconfig_method = NULL;
  7391. #ifdef CONFIG_DEBUG_CFG80211
  7392. RTW_INFO("probe_resp_wps_ielen=%d\n", wps_ielen);
  7393. #endif
  7394. if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) {
  7395. u8 sr = 0;
  7396. rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
  7397. if (sr != 0)
  7398. RTW_INFO("%s, got sr\n", __func__);
  7399. else {
  7400. RTW_INFO("GO mode process WPS under site-survey, sr no set\n");
  7401. return ret;
  7402. }
  7403. }
  7404. if (pmlmepriv->wps_probe_resp_ie) {
  7405. u32 free_len = pmlmepriv->wps_probe_resp_ie_len;
  7406. pmlmepriv->wps_probe_resp_ie_len = 0;
  7407. rtw_mfree(pmlmepriv->wps_probe_resp_ie, free_len);
  7408. pmlmepriv->wps_probe_resp_ie = NULL;
  7409. }
  7410. pmlmepriv->wps_probe_resp_ie = rtw_malloc(wps_ielen);
  7411. if (pmlmepriv->wps_probe_resp_ie == NULL) {
  7412. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7413. return -EINVAL;
  7414. }
  7415. /* add PUSH_BUTTON config_method by driver self in wpsie of probe_resp at GO Mode */
  7416. puconfig_method = (u16 *)rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_CONF_METHOD , NULL, &attr_contentlen);
  7417. if (puconfig_method != NULL) {
  7418. /* struct registry_priv *pregistrypriv = &padapter->registrypriv; */
  7419. struct wireless_dev *wdev = padapter->rtw_wdev;
  7420. #ifdef CONFIG_DEBUG_CFG80211
  7421. /* printk("config_method in wpsie of probe_resp = 0x%x\n", be16_to_cpu(*puconfig_method)); */
  7422. #endif
  7423. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  7424. /* for WIFI-DIRECT LOGO 4.2.2, AUTO GO can't set PUSH_BUTTON flags */
  7425. if (wdev->iftype == NL80211_IFTYPE_P2P_GO) {
  7426. uconfig_method = WPS_CM_PUSH_BUTTON;
  7427. uconfig_method = cpu_to_be16(uconfig_method);
  7428. *puconfig_method &= ~uconfig_method;
  7429. }
  7430. #endif
  7431. }
  7432. _rtw_memcpy(pmlmepriv->wps_probe_resp_ie, wps_ie, wps_ielen);
  7433. pmlmepriv->wps_probe_resp_ie_len = wps_ielen;
  7434. }
  7435. /* buf += wps_ielen; */
  7436. /* len -= wps_ielen; */
  7437. #ifdef CONFIG_P2P
  7438. p2p_ie = rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen);
  7439. if (p2p_ie) {
  7440. u8 is_GO = _FALSE;
  7441. u32 attr_contentlen = 0;
  7442. u16 cap_attr = 0;
  7443. #ifdef CONFIG_DEBUG_CFG80211
  7444. RTW_INFO("probe_resp_p2p_ielen=%d\n", p2p_ielen);
  7445. #endif
  7446. /* Check P2P Capability ATTR */
  7447. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8 *)&cap_attr, (uint *) &attr_contentlen)) {
  7448. u8 grp_cap = 0;
  7449. /* RTW_INFO( "[%s] Got P2P Capability Attr!!\n", __FUNCTION__ ); */
  7450. cap_attr = le16_to_cpu(cap_attr);
  7451. grp_cap = (u8)((cap_attr >> 8) & 0xff);
  7452. is_GO = (grp_cap & BIT(0)) ? _TRUE : _FALSE;
  7453. if (is_GO)
  7454. RTW_INFO("Got P2P Capability Attr, grp_cap=0x%x, is_GO\n", grp_cap);
  7455. }
  7456. if (is_GO == _FALSE) {
  7457. if (pmlmepriv->p2p_probe_resp_ie) {
  7458. u32 free_len = pmlmepriv->p2p_probe_resp_ie_len;
  7459. pmlmepriv->p2p_probe_resp_ie_len = 0;
  7460. rtw_mfree(pmlmepriv->p2p_probe_resp_ie, free_len);
  7461. pmlmepriv->p2p_probe_resp_ie = NULL;
  7462. }
  7463. pmlmepriv->p2p_probe_resp_ie = rtw_malloc(p2p_ielen);
  7464. if (pmlmepriv->p2p_probe_resp_ie == NULL) {
  7465. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7466. return -EINVAL;
  7467. }
  7468. _rtw_memcpy(pmlmepriv->p2p_probe_resp_ie, p2p_ie, p2p_ielen);
  7469. pmlmepriv->p2p_probe_resp_ie_len = p2p_ielen;
  7470. } else {
  7471. if (pmlmepriv->p2p_go_probe_resp_ie) {
  7472. u32 free_len = pmlmepriv->p2p_go_probe_resp_ie_len;
  7473. pmlmepriv->p2p_go_probe_resp_ie_len = 0;
  7474. rtw_mfree(pmlmepriv->p2p_go_probe_resp_ie, free_len);
  7475. pmlmepriv->p2p_go_probe_resp_ie = NULL;
  7476. }
  7477. pmlmepriv->p2p_go_probe_resp_ie = rtw_malloc(p2p_ielen);
  7478. if (pmlmepriv->p2p_go_probe_resp_ie == NULL) {
  7479. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7480. return -EINVAL;
  7481. }
  7482. _rtw_memcpy(pmlmepriv->p2p_go_probe_resp_ie, p2p_ie, p2p_ielen);
  7483. pmlmepriv->p2p_go_probe_resp_ie_len = p2p_ielen;
  7484. }
  7485. }
  7486. #endif /* CONFIG_P2P */
  7487. #ifdef CONFIG_WFD
  7488. wfd_ie = rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen);
  7489. if (wfd_ie) {
  7490. #ifdef CONFIG_DEBUG_CFG80211
  7491. RTW_INFO("probe_resp_wfd_ielen=%d\n", wfd_ielen);
  7492. #endif
  7493. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_PROBE_RESP_IE, wfd_ie, wfd_ielen) != _SUCCESS)
  7494. return -EINVAL;
  7495. }
  7496. #endif /* CONFIG_WFD */
  7497. }
  7498. return ret;
  7499. }
  7500. static int rtw_cfg80211_set_assoc_resp_wpsp2pie(struct net_device *net, char *buf, int len)
  7501. {
  7502. int ret = 0;
  7503. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  7504. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7505. u8 *ie;
  7506. u32 ie_len;
  7507. RTW_INFO("%s, ielen=%d\n", __func__, len);
  7508. if (len <= 0)
  7509. goto exit;
  7510. ie = rtw_get_wps_ie(buf, len, NULL, &ie_len);
  7511. if (ie && ie_len) {
  7512. if (pmlmepriv->wps_assoc_resp_ie) {
  7513. u32 free_len = pmlmepriv->wps_assoc_resp_ie_len;
  7514. pmlmepriv->wps_assoc_resp_ie_len = 0;
  7515. rtw_mfree(pmlmepriv->wps_assoc_resp_ie, free_len);
  7516. pmlmepriv->wps_assoc_resp_ie = NULL;
  7517. }
  7518. pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len);
  7519. if (pmlmepriv->wps_assoc_resp_ie == NULL) {
  7520. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7521. return -EINVAL;
  7522. }
  7523. _rtw_memcpy(pmlmepriv->wps_assoc_resp_ie, ie, ie_len);
  7524. pmlmepriv->wps_assoc_resp_ie_len = ie_len;
  7525. }
  7526. ie = rtw_get_p2p_ie(buf, len, NULL, &ie_len);
  7527. if (ie && ie_len) {
  7528. if (pmlmepriv->p2p_assoc_resp_ie) {
  7529. u32 free_len = pmlmepriv->p2p_assoc_resp_ie_len;
  7530. pmlmepriv->p2p_assoc_resp_ie_len = 0;
  7531. rtw_mfree(pmlmepriv->p2p_assoc_resp_ie, free_len);
  7532. pmlmepriv->p2p_assoc_resp_ie = NULL;
  7533. }
  7534. pmlmepriv->p2p_assoc_resp_ie = rtw_malloc(ie_len);
  7535. if (pmlmepriv->p2p_assoc_resp_ie == NULL) {
  7536. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7537. return -EINVAL;
  7538. }
  7539. _rtw_memcpy(pmlmepriv->p2p_assoc_resp_ie, ie, ie_len);
  7540. pmlmepriv->p2p_assoc_resp_ie_len = ie_len;
  7541. }
  7542. #ifdef CONFIG_WFD
  7543. ie = rtw_get_wfd_ie(buf, len, NULL, &ie_len);
  7544. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_ASSOC_RESP_IE, ie, ie_len) != _SUCCESS)
  7545. return -EINVAL;
  7546. #endif
  7547. exit:
  7548. return ret;
  7549. }
  7550. int rtw_cfg80211_set_mgnt_wpsp2pie(struct net_device *net, char *buf, int len,
  7551. int type)
  7552. {
  7553. int ret = 0;
  7554. uint wps_ielen = 0;
  7555. u32 p2p_ielen = 0;
  7556. #ifdef CONFIG_DEBUG_CFG80211
  7557. RTW_INFO("%s, ielen=%d\n", __func__, len);
  7558. #endif
  7559. if ((rtw_get_wps_ie(buf, len, NULL, &wps_ielen) && (wps_ielen > 0))
  7560. #ifdef CONFIG_P2P
  7561. || (rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen) && (p2p_ielen > 0))
  7562. #endif
  7563. ) {
  7564. if (net != NULL) {
  7565. switch (type) {
  7566. case 0x1: /* BEACON */
  7567. ret = rtw_cfg80211_set_beacon_wpsp2pie(net, buf, len);
  7568. break;
  7569. case 0x2: /* PROBE_RESP */
  7570. ret = rtw_cfg80211_set_probe_resp_wpsp2pie(net, buf, len);
  7571. #ifdef CONFIG_P2P
  7572. if (ret == 0)
  7573. adapter_wdev_data((_adapter *)rtw_netdev_priv(net))->probe_resp_ie_update_time = rtw_get_current_time();
  7574. #endif
  7575. break;
  7576. case 0x4: /* ASSOC_RESP */
  7577. ret = rtw_cfg80211_set_assoc_resp_wpsp2pie(net, buf, len);
  7578. break;
  7579. }
  7580. }
  7581. }
  7582. return ret;
  7583. }
  7584. #ifdef CONFIG_80211N_HT
  7585. static void rtw_cfg80211_init_ht_capab_ex(_adapter *padapter
  7586. , struct ieee80211_sta_ht_cap *ht_cap, BAND_TYPE band, u8 rf_type)
  7587. {
  7588. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  7589. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  7590. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  7591. u8 stbc_rx_enable = _FALSE;
  7592. rtw_ht_use_default_setting(padapter);
  7593. /* RX LDPC */
  7594. if (TEST_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_RX))
  7595. ht_cap->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  7596. /* TX STBC */
  7597. if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX))
  7598. ht_cap->cap |= IEEE80211_HT_CAP_TX_STBC;
  7599. /* RX STBC */
  7600. if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_RX)) {
  7601. /*rtw_rx_stbc 0: disable, bit(0):enable 2.4g, bit(1):enable 5g*/
  7602. if (band == BAND_ON_2_4G)
  7603. stbc_rx_enable = (pregistrypriv->rx_stbc & BIT(0)) ? _TRUE : _FALSE;
  7604. if (band == BAND_ON_5G)
  7605. stbc_rx_enable = (pregistrypriv->rx_stbc & BIT(1)) ? _TRUE : _FALSE;
  7606. if (stbc_rx_enable) {
  7607. switch (rf_type) {
  7608. case RF_1T1R:
  7609. ht_cap->cap |= IEEE80211_HT_CAP_RX_STBC_1R;/*RX STBC One spatial stream*/
  7610. break;
  7611. case RF_2T2R:
  7612. case RF_1T2R:
  7613. ht_cap->cap |= IEEE80211_HT_CAP_RX_STBC_1R;/* Only one spatial-stream STBC RX is supported */
  7614. break;
  7615. case RF_3T3R:
  7616. case RF_3T4R:
  7617. case RF_4T4R:
  7618. ht_cap->cap |= IEEE80211_HT_CAP_RX_STBC_1R;/* Only one spatial-stream STBC RX is supported */
  7619. break;
  7620. default:
  7621. RTW_INFO("[warning] rf_type %d is not expected\n", rf_type);
  7622. break;
  7623. }
  7624. }
  7625. }
  7626. }
  7627. static void rtw_cfg80211_init_ht_capab(_adapter *padapter
  7628. , struct ieee80211_sta_ht_cap *ht_cap, BAND_TYPE band, u8 rf_type)
  7629. {
  7630. struct registry_priv *regsty = &padapter->registrypriv;
  7631. struct hal_spec_t *hal_spec = GET_HAL_SPEC(padapter);
  7632. u8 rx_nss = 0;
  7633. if (!regsty->ht_enable || !is_supported_ht(regsty->wireless_mode))
  7634. return;
  7635. ht_cap->ht_supported = 1;
  7636. ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  7637. IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 |
  7638. IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
  7639. rtw_cfg80211_init_ht_capab_ex(padapter, ht_cap, band, rf_type);
  7640. /*
  7641. *Maximum length of AMPDU that the STA can receive.
  7642. *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
  7643. */
  7644. ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  7645. /*Minimum MPDU start spacing , */
  7646. ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
  7647. ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  7648. rx_nss = rtw_min(rf_type_to_rf_rx_cnt(rf_type), hal_spec->rx_nss_num);
  7649. switch (rx_nss) {
  7650. case 1:
  7651. ht_cap->mcs.rx_mask[0] = 0xFF;
  7652. break;
  7653. case 2:
  7654. ht_cap->mcs.rx_mask[0] = 0xFF;
  7655. ht_cap->mcs.rx_mask[1] = 0xFF;
  7656. break;
  7657. case 3:
  7658. ht_cap->mcs.rx_mask[0] = 0xFF;
  7659. ht_cap->mcs.rx_mask[1] = 0xFF;
  7660. ht_cap->mcs.rx_mask[2] = 0xFF;
  7661. break;
  7662. case 4:
  7663. ht_cap->mcs.rx_mask[0] = 0xFF;
  7664. ht_cap->mcs.rx_mask[1] = 0xFF;
  7665. ht_cap->mcs.rx_mask[2] = 0xFF;
  7666. ht_cap->mcs.rx_mask[3] = 0xFF;
  7667. break;
  7668. default:
  7669. rtw_warn_on(1);
  7670. RTW_INFO("%s, error rf_type=%d\n", __func__, rf_type);
  7671. };
  7672. ht_cap->mcs.rx_highest = cpu_to_le16(
  7673. rtw_mcs_rate(rf_type
  7674. , hal_is_bw_support(padapter, CHANNEL_WIDTH_40)
  7675. , hal_is_bw_support(padapter, CHANNEL_WIDTH_40) ? ht_cap->cap & IEEE80211_HT_CAP_SGI_40 : ht_cap->cap & IEEE80211_HT_CAP_SGI_20
  7676. , ht_cap->mcs.rx_mask) / 10);
  7677. }
  7678. #endif /* CONFIG_80211N_HT */
  7679. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  7680. static void rtw_cfg80211_init_vht_capab(_adapter *padapter
  7681. , struct ieee80211_sta_vht_cap *sta_vht_cap, BAND_TYPE band, u8 rf_type)
  7682. {
  7683. struct registry_priv *regsty = &padapter->registrypriv;
  7684. u8 vht_cap_ie[2 + 12] = {0};
  7685. if (!REGSTY_IS_11AC_ENABLE(regsty) || !is_supported_vht(regsty->wireless_mode))
  7686. return;
  7687. rtw_vht_use_default_setting(padapter);
  7688. rtw_build_vht_cap_ie(padapter, vht_cap_ie);
  7689. sta_vht_cap->vht_supported = 1;
  7690. _rtw_memcpy(&sta_vht_cap->cap, vht_cap_ie + 2, 4);
  7691. _rtw_memcpy(&sta_vht_cap->vht_mcs, vht_cap_ie + 2 + 4, 8);
  7692. }
  7693. #endif /* defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)) */
  7694. void rtw_cfg80211_init_wdev_data(_adapter *padapter)
  7695. {
  7696. #ifdef CONFIG_CONCURRENT_MODE
  7697. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  7698. ATOMIC_SET(&pwdev_priv->switch_ch_to, 1);
  7699. #endif
  7700. }
  7701. void rtw_cfg80211_init_wiphy(_adapter *padapter)
  7702. {
  7703. u8 rf_type;
  7704. struct ieee80211_supported_band *band;
  7705. struct wireless_dev *pwdev = padapter->rtw_wdev;
  7706. struct wiphy *wiphy = pwdev->wiphy;
  7707. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  7708. RTW_INFO("%s:rf_type=%d\n", __func__, rf_type);
  7709. if (IsSupported24G(padapter->registrypriv.wireless_mode)) {
  7710. band = wiphy->bands[NL80211_BAND_2GHZ];
  7711. if (band) {
  7712. #if defined(CONFIG_80211N_HT)
  7713. rtw_cfg80211_init_ht_capab(padapter, &band->ht_cap, BAND_ON_2_4G, rf_type);
  7714. #endif
  7715. }
  7716. }
  7717. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  7718. if (is_supported_5g(padapter->registrypriv.wireless_mode)) {
  7719. band = wiphy->bands[NL80211_BAND_5GHZ];
  7720. if (band) {
  7721. #if defined(CONFIG_80211N_HT)
  7722. rtw_cfg80211_init_ht_capab(padapter, &band->ht_cap, BAND_ON_5G, rf_type);
  7723. #endif
  7724. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  7725. rtw_cfg80211_init_vht_capab(padapter, &band->vht_cap, BAND_ON_5G, rf_type);
  7726. #endif
  7727. }
  7728. }
  7729. #endif
  7730. /* copy mac_addr to wiphy */
  7731. _rtw_memcpy(wiphy->perm_addr, adapter_mac_addr(padapter), ETH_ALEN);
  7732. }
  7733. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7734. struct ieee80211_iface_limit rtw_limits[] = {
  7735. {
  7736. .max = 2,
  7737. .types = BIT(NL80211_IFTYPE_STATION)
  7738. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  7739. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  7740. #endif
  7741. },
  7742. #ifdef CONFIG_AP_MODE
  7743. {
  7744. .max = 1,
  7745. .types = BIT(NL80211_IFTYPE_AP)
  7746. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  7747. | BIT(NL80211_IFTYPE_P2P_GO)
  7748. #endif
  7749. },
  7750. #endif
  7751. #if defined(RTW_DEDICATED_P2P_DEVICE)
  7752. {
  7753. .max = 1,
  7754. .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
  7755. },
  7756. #endif
  7757. #if defined(CONFIG_RTW_MESH)
  7758. {
  7759. .max = 1,
  7760. .types = BIT(NL80211_IFTYPE_MESH_POINT)
  7761. },
  7762. #endif
  7763. };
  7764. struct ieee80211_iface_combination rtw_combinations[] = {
  7765. {
  7766. .limits = rtw_limits,
  7767. .n_limits = ARRAY_SIZE(rtw_limits),
  7768. #if defined(RTW_DEDICATED_P2P_DEVICE)
  7769. .max_interfaces = 3,
  7770. #else
  7771. .max_interfaces = 2,
  7772. #endif
  7773. .num_different_channels = 1,
  7774. },
  7775. };
  7776. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0)) */
  7777. static void rtw_cfg80211_preinit_wiphy(_adapter *adapter, struct wiphy *wiphy)
  7778. {
  7779. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  7780. struct registry_priv *regsty = dvobj_to_regsty(dvobj);
  7781. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  7782. wiphy->max_scan_ssids = RTW_SSID_SCAN_AMOUNT;
  7783. wiphy->max_scan_ie_len = RTW_SCAN_IE_LEN_MAX;
  7784. wiphy->max_num_pmkids = RTW_MAX_NUM_PMKIDS;
  7785. #if CONFIG_RTW_MACADDR_ACL && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  7786. wiphy->max_acl_mac_addrs = NUM_ACL;
  7787. #endif
  7788. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  7789. wiphy->max_remain_on_channel_duration = RTW_MAX_REMAIN_ON_CHANNEL_DURATION;
  7790. #endif
  7791. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
  7792. | BIT(NL80211_IFTYPE_ADHOC)
  7793. #ifdef CONFIG_AP_MODE
  7794. | BIT(NL80211_IFTYPE_AP)
  7795. #ifdef CONFIG_WIFI_MONITOR
  7796. | BIT(NL80211_IFTYPE_MONITOR)
  7797. #endif
  7798. #endif
  7799. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  7800. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  7801. | BIT(NL80211_IFTYPE_P2P_GO)
  7802. #if defined(RTW_DEDICATED_P2P_DEVICE)
  7803. | BIT(NL80211_IFTYPE_P2P_DEVICE)
  7804. #endif
  7805. #endif
  7806. #ifdef CONFIG_RTW_MESH
  7807. | BIT(NL80211_IFTYPE_MESH_POINT) /* 2.6.26 */
  7808. #endif
  7809. ;
  7810. #if defined(CONFIG_ANDROID) && !defined(RTW_SINGLE_WIPHY)
  7811. if (is_primary_adapter(adapter)) {
  7812. wiphy->interface_modes &= ~(BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT));
  7813. RTW_INFO("%s primary- don't set p2p capability\n", __func__);
  7814. }
  7815. #endif
  7816. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  7817. #ifdef CONFIG_AP_MODE
  7818. wiphy->mgmt_stypes = rtw_cfg80211_default_mgmt_stypes;
  7819. #endif /* CONFIG_AP_MODE */
  7820. #endif
  7821. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7822. #ifdef CONFIG_WIFI_MONITOR
  7823. wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
  7824. #endif
  7825. #endif
  7826. #if defined(RTW_SINGLE_WIPHY) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7827. wiphy->iface_combinations = rtw_combinations;
  7828. wiphy->n_iface_combinations = ARRAY_SIZE(rtw_combinations);
  7829. #endif
  7830. wiphy->cipher_suites = rtw_cipher_suites;
  7831. wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites);
  7832. if (IsSupported24G(adapter->registrypriv.wireless_mode))
  7833. wiphy->bands[NL80211_BAND_2GHZ] = rtw_spt_band_alloc(BAND_ON_2_4G);
  7834. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  7835. if (is_supported_5g(adapter->registrypriv.wireless_mode))
  7836. wiphy->bands[NL80211_BAND_5GHZ] = rtw_spt_band_alloc(BAND_ON_5G);
  7837. #endif
  7838. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38) && LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0))
  7839. wiphy->flags |= WIPHY_FLAG_SUPPORTS_SEPARATE_DEFAULT_KEYS;
  7840. #endif
  7841. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  7842. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  7843. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
  7844. /* remove WIPHY_FLAG_OFFCHAN_TX, because we not support this feature */
  7845. /* wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME; */
  7846. #endif
  7847. #if defined(CONFIG_PM) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) && \
  7848. LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
  7849. wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
  7850. #ifdef CONFIG_PNO_SUPPORT
  7851. wiphy->max_sched_scan_ssids = MAX_PNO_LIST_COUNT;
  7852. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
  7853. wiphy->max_match_sets = MAX_PNO_LIST_COUNT;
  7854. #endif
  7855. #endif
  7856. #endif
  7857. #if defined(CONFIG_PM) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7858. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0))
  7859. wiphy->wowlan = wowlan_stub;
  7860. #else
  7861. wiphy->wowlan = &wowlan_stub;
  7862. #endif
  7863. #endif
  7864. #if defined(CONFIG_TDLS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  7865. wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  7866. #ifndef CONFIG_TDLS_DRIVER_SETUP
  7867. wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP; /* Driver handles key exchange */
  7868. wiphy->flags |= NL80211_ATTR_HT_CAPABILITY;
  7869. #endif /* CONFIG_TDLS_DRIVER_SETUP */
  7870. #endif /* CONFIG_TDLS */
  7871. if (regsty->power_mgnt != PS_MODE_ACTIVE)
  7872. wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  7873. else
  7874. wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  7875. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  7876. /* wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM; */
  7877. #endif
  7878. #ifdef CONFIG_RTW_MESH
  7879. wiphy->flags |= 0
  7880. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7881. | WIPHY_FLAG_IBSS_RSN
  7882. #endif
  7883. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7884. | WIPHY_FLAG_MESH_AUTH
  7885. #endif
  7886. ;
  7887. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  7888. wiphy->features |= 0
  7889. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  7890. | NL80211_FEATURE_USERSPACE_MPM
  7891. #endif
  7892. ;
  7893. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)) */
  7894. #endif /* CONFIG_RTW_MESH */
  7895. }
  7896. #ifdef CONFIG_RFKILL_POLL
  7897. void rtw_cfg80211_init_rfkill(struct wiphy *wiphy)
  7898. {
  7899. wiphy_rfkill_set_hw_state(wiphy, 0);
  7900. wiphy_rfkill_start_polling(wiphy);
  7901. }
  7902. void rtw_cfg80211_deinit_rfkill(struct wiphy *wiphy)
  7903. {
  7904. wiphy_rfkill_stop_polling(wiphy);
  7905. }
  7906. static void cfg80211_rtw_rfkill_poll(struct wiphy *wiphy)
  7907. {
  7908. _adapter *padapter = NULL;
  7909. bool blocked = _FALSE;
  7910. u8 valid = 0;
  7911. padapter = wiphy_to_adapter(wiphy);
  7912. if (adapter_to_dvobj(padapter)->processing_dev_remove == _TRUE) {
  7913. /*RTW_INFO("cfg80211_rtw_rfkill_poll: device is removed!\n");*/
  7914. return;
  7915. }
  7916. blocked = rtw_hal_rfkill_poll(padapter, &valid);
  7917. /*RTW_INFO("cfg80211_rtw_rfkill_poll: valid=%d, blocked=%d\n",
  7918. valid, blocked);*/
  7919. if (valid)
  7920. wiphy_rfkill_set_hw_state(wiphy, blocked);
  7921. }
  7922. #endif
  7923. #if defined(CONFIG_RTW_HOSTAPD_ACS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
  7924. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0))
  7925. #define SURVEY_INFO_TIME SURVEY_INFO_CHANNEL_TIME
  7926. #define SURVEY_INFO_TIME_BUSY SURVEY_INFO_CHANNEL_TIME_BUSY
  7927. #define SURVEY_INFO_TIME_EXT_BUSY SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
  7928. #define SURVEY_INFO_TIME_RX SURVEY_INFO_CHANNEL_TIME_RX
  7929. #define SURVEY_INFO_TIME_TX SURVEY_INFO_CHANNEL_TIME_TX
  7930. #endif
  7931. #ifdef CONFIG_FIND_BEST_CHANNEL
  7932. static void rtw_cfg80211_set_survey_info_with_find_best_channel(struct wiphy *wiphy
  7933. , struct net_device *netdev, int idx, struct survey_info *info)
  7934. {
  7935. _adapter *adapter = (_adapter *)rtw_netdev_priv(netdev);
  7936. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  7937. RT_CHANNEL_INFO *ch_set = rfctl->channel_set;
  7938. u8 ch_num = rfctl->max_chan_nums;
  7939. u32 total_rx_cnt = 0;
  7940. int i;
  7941. s8 noise = -50; /*channel noise in dBm. This and all following fields are optional */
  7942. u64 time = 100; /*amount of time in ms the radio was turn on (on the channel)*/
  7943. u64 time_busy = 0; /*amount of time the primary channel was sensed busy*/
  7944. info->filled = SURVEY_INFO_NOISE_DBM
  7945. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7946. | SURVEY_INFO_TIME | SURVEY_INFO_TIME_BUSY
  7947. #endif
  7948. ;
  7949. for (i = 0; i < ch_num; i++)
  7950. total_rx_cnt += ch_set[i].rx_count;
  7951. time_busy = ch_set[idx].rx_count * time / total_rx_cnt;
  7952. noise += ch_set[idx].rx_count * 50 / total_rx_cnt;
  7953. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7954. #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0))
  7955. info->channel_time = time;
  7956. info->channel_time_busy = time_busy;
  7957. #else
  7958. info->time = time;
  7959. info->time_busy = time_busy;
  7960. #endif
  7961. #endif
  7962. info->noise = noise;
  7963. /* reset if final channel is got */
  7964. if (idx == ch_num - 1) {
  7965. for (i = 0; i < ch_num; i++)
  7966. ch_set[i].rx_count = 0;
  7967. }
  7968. }
  7969. #endif /* CONFIG_FIND_BEST_CHANNEL */
  7970. #if defined(CONFIG_RTW_ACS) && defined(CONFIG_BACKGROUND_NOISE_MONITOR)
  7971. static void rtw_cfg80211_set_survey_info_with_clm(PADAPTER padapter, int idx, struct survey_info *pinfo)
  7972. {
  7973. s8 noise = -50; /*channel noise in dBm. This and all following fields are optional */
  7974. u64 time = SURVEY_TO; /*amount of time in ms the radio was turn on (on the channel)*/
  7975. u64 time_busy = 0; /*amount of time the primary channel was sensed busy*/
  7976. u8 chan = (u8)idx;
  7977. if ((idx < 0) || (pinfo == NULL))
  7978. return;
  7979. pinfo->filled = SURVEY_INFO_NOISE_DBM
  7980. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7981. | SURVEY_INFO_TIME | SURVEY_INFO_TIME_BUSY
  7982. #endif
  7983. ;
  7984. time_busy = rtw_acs_get_clm_ratio_by_ch_idx(padapter, chan);
  7985. noise = rtw_noise_query_by_chan_idx(padapter, chan);
  7986. /* RTW_INFO("%s: ch-idx:%d time=%llu(ms), time_busy=%llu(ms), noise=%d(dbm)\n", __func__, idx, time, time_busy, noise); */
  7987. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7988. #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0))
  7989. pinfo->channel_time = time;
  7990. pinfo->channel_time_busy = time_busy;
  7991. #else
  7992. pinfo->time = time;
  7993. pinfo->time_busy = time_busy;
  7994. #endif
  7995. #endif
  7996. pinfo->noise = noise;
  7997. }
  7998. #endif
  7999. int rtw_hostapd_acs_dump_survey(struct wiphy *wiphy, struct net_device *netdev, int idx, struct survey_info *info)
  8000. {
  8001. PADAPTER padapter = (_adapter *)rtw_netdev_priv(netdev);
  8002. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  8003. RT_CHANNEL_INFO *pch_set = rfctl->channel_set;
  8004. u8 max_chan_nums = rfctl->max_chan_nums;
  8005. u32 freq = 0;
  8006. u8 ret = 0;
  8007. u16 channel = 0;
  8008. if (!netdev || !info) {
  8009. RTW_INFO("%s: invial parameters.\n", __func__);
  8010. return -EINVAL;
  8011. }
  8012. _rtw_memset(info, 0, sizeof(struct survey_info));
  8013. if (padapter->bup == _FALSE) {
  8014. RTW_INFO("%s: net device is down.\n", __func__);
  8015. return -EIO;
  8016. }
  8017. if (idx >= max_chan_nums)
  8018. return -ENOENT;
  8019. channel = pch_set[idx].ChannelNum;
  8020. freq = rtw_ch2freq(channel);
  8021. info->channel = ieee80211_get_channel(wiphy, freq);
  8022. /* RTW_INFO("%s: channel %d, freq %d\n", __func__, channel, freq); */
  8023. if (!info->channel)
  8024. return -EINVAL;
  8025. if (info->channel->flags == IEEE80211_CHAN_DISABLED)
  8026. return ret;
  8027. #ifdef CONFIG_FIND_BEST_CHANNEL
  8028. rtw_cfg80211_set_survey_info_with_find_best_channel(wiphy, netdev, idx, info);
  8029. #elif defined(CONFIG_RTW_ACS) && defined(CONFIG_BACKGROUND_NOISE_MONITOR)
  8030. rtw_cfg80211_set_survey_info_with_clm(padapter, idx, info);
  8031. #else
  8032. RTW_ERR("%s: unknown acs operation!\n", __func__);
  8033. #endif
  8034. return ret;
  8035. }
  8036. #endif /* defined(CONFIG_RTW_HOSTAPD_ACS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)) */
  8037. static struct cfg80211_ops rtw_cfg80211_ops = {
  8038. .change_virtual_intf = cfg80211_rtw_change_iface,
  8039. .add_key = cfg80211_rtw_add_key,
  8040. .get_key = cfg80211_rtw_get_key,
  8041. .del_key = cfg80211_rtw_del_key,
  8042. .set_default_key = cfg80211_rtw_set_default_key,
  8043. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
  8044. .set_default_mgmt_key = cfg80211_rtw_set_default_mgmt_key,
  8045. #endif
  8046. #if defined(CONFIG_GTK_OL) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
  8047. .set_rekey_data = cfg80211_rtw_set_rekey_data,
  8048. #endif /*CONFIG_GTK_OL*/
  8049. .get_station = cfg80211_rtw_get_station,
  8050. .scan = cfg80211_rtw_scan,
  8051. .set_wiphy_params = cfg80211_rtw_set_wiphy_params,
  8052. .connect = cfg80211_rtw_connect,
  8053. .disconnect = cfg80211_rtw_disconnect,
  8054. .join_ibss = cfg80211_rtw_join_ibss,
  8055. .leave_ibss = cfg80211_rtw_leave_ibss,
  8056. .set_tx_power = cfg80211_rtw_set_txpower,
  8057. .get_tx_power = cfg80211_rtw_get_txpower,
  8058. .set_power_mgmt = cfg80211_rtw_set_power_mgmt,
  8059. .set_pmksa = cfg80211_rtw_set_pmksa,
  8060. .del_pmksa = cfg80211_rtw_del_pmksa,
  8061. .flush_pmksa = cfg80211_rtw_flush_pmksa,
  8062. #ifdef CONFIG_AP_MODE
  8063. .add_virtual_intf = cfg80211_rtw_add_virtual_intf,
  8064. .del_virtual_intf = cfg80211_rtw_del_virtual_intf,
  8065. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)) && !defined(COMPAT_KERNEL_RELEASE)
  8066. .add_beacon = cfg80211_rtw_add_beacon,
  8067. .set_beacon = cfg80211_rtw_set_beacon,
  8068. .del_beacon = cfg80211_rtw_del_beacon,
  8069. #else
  8070. .start_ap = cfg80211_rtw_start_ap,
  8071. .change_beacon = cfg80211_rtw_change_beacon,
  8072. .stop_ap = cfg80211_rtw_stop_ap,
  8073. #endif
  8074. #if CONFIG_RTW_MACADDR_ACL && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  8075. .set_mac_acl = cfg80211_rtw_set_mac_acl,
  8076. #endif
  8077. .add_station = cfg80211_rtw_add_station,
  8078. .del_station = cfg80211_rtw_del_station,
  8079. .change_station = cfg80211_rtw_change_station,
  8080. .dump_station = cfg80211_rtw_dump_station,
  8081. .change_bss = cfg80211_rtw_change_bss,
  8082. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  8083. .set_txq_params = cfg80211_rtw_set_txq_params,
  8084. #endif
  8085. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
  8086. .set_channel = cfg80211_rtw_set_channel,
  8087. #endif
  8088. /* .auth = cfg80211_rtw_auth, */
  8089. /* .assoc = cfg80211_rtw_assoc, */
  8090. #endif /* CONFIG_AP_MODE */
  8091. #if defined(CONFIG_RTW_MESH) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
  8092. .get_mesh_config = cfg80211_rtw_get_mesh_config,
  8093. .update_mesh_config = cfg80211_rtw_update_mesh_config,
  8094. .join_mesh = cfg80211_rtw_join_mesh,
  8095. .leave_mesh = cfg80211_rtw_leave_mesh,
  8096. .add_mpath = cfg80211_rtw_add_mpath,
  8097. .del_mpath = cfg80211_rtw_del_mpath,
  8098. .change_mpath = cfg80211_rtw_change_mpath,
  8099. .get_mpath = cfg80211_rtw_get_mpath,
  8100. .dump_mpath = cfg80211_rtw_dump_mpath,
  8101. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0))
  8102. .get_mpp = cfg80211_rtw_get_mpp,
  8103. .dump_mpp = cfg80211_rtw_dump_mpp,
  8104. #endif
  8105. #endif
  8106. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  8107. .set_monitor_channel = cfg80211_rtw_set_monitor_channel,
  8108. #endif
  8109. #ifdef CONFIG_P2P
  8110. .remain_on_channel = cfg80211_rtw_remain_on_channel,
  8111. .cancel_remain_on_channel = cfg80211_rtw_cancel_remain_on_channel,
  8112. #if defined(RTW_DEDICATED_P2P_DEVICE)
  8113. .start_p2p_device = cfg80211_rtw_start_p2p_device,
  8114. .stop_p2p_device = cfg80211_rtw_stop_p2p_device,
  8115. #endif
  8116. #endif /* CONFIG_P2P */
  8117. #ifdef CONFIG_RTW_80211R
  8118. .update_ft_ies = cfg80211_rtw_update_ft_ies,
  8119. #endif
  8120. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  8121. .mgmt_tx = cfg80211_rtw_mgmt_tx,
  8122. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
  8123. .update_mgmt_frame_registrations = cfg80211_rtw_mgmt_frame_register,
  8124. #else
  8125. .mgmt_frame_register = cfg80211_rtw_mgmt_frame_register,
  8126. #endif
  8127. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34) && LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  8128. .action = cfg80211_rtw_mgmt_tx,
  8129. #endif
  8130. #if defined(CONFIG_TDLS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  8131. .tdls_mgmt = cfg80211_rtw_tdls_mgmt,
  8132. .tdls_oper = cfg80211_rtw_tdls_oper,
  8133. #endif /* CONFIG_TDLS */
  8134. #if defined(CONFIG_PNO_SUPPORT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  8135. .sched_scan_start = cfg80211_rtw_sched_scan_start,
  8136. .sched_scan_stop = cfg80211_rtw_sched_scan_stop,
  8137. .suspend = cfg80211_rtw_suspend,
  8138. .resume = cfg80211_rtw_resume,
  8139. #endif /* CONFIG_PNO_SUPPORT */
  8140. #ifdef CONFIG_RFKILL_POLL
  8141. .rfkill_poll = cfg80211_rtw_rfkill_poll,
  8142. #endif
  8143. #if defined(CONFIG_RTW_HOSTAPD_ACS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
  8144. .dump_survey = rtw_hostapd_acs_dump_survey,
  8145. #endif
  8146. };
  8147. struct wiphy *rtw_wiphy_alloc(_adapter *padapter, struct device *dev)
  8148. {
  8149. struct wiphy *wiphy;
  8150. struct rtw_wiphy_data *wiphy_data;
  8151. /* wiphy */
  8152. wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct rtw_wiphy_data));
  8153. if (!wiphy) {
  8154. RTW_INFO("Couldn't allocate wiphy device\n");
  8155. goto exit;
  8156. }
  8157. set_wiphy_dev(wiphy, dev);
  8158. /* wiphy_data */
  8159. wiphy_data = rtw_wiphy_priv(wiphy);
  8160. wiphy_data->dvobj = adapter_to_dvobj(padapter);
  8161. #ifndef RTW_SINGLE_WIPHY
  8162. wiphy_data->adapter = padapter;
  8163. #endif
  8164. rtw_cfg80211_preinit_wiphy(padapter, wiphy);
  8165. RTW_INFO(FUNC_WIPHY_FMT"\n", FUNC_WIPHY_ARG(wiphy));
  8166. exit:
  8167. return wiphy;
  8168. }
  8169. void rtw_wiphy_free(struct wiphy *wiphy)
  8170. {
  8171. if (!wiphy)
  8172. return;
  8173. RTW_INFO(FUNC_WIPHY_FMT"\n", FUNC_WIPHY_ARG(wiphy));
  8174. if (wiphy->bands[NL80211_BAND_2GHZ]) {
  8175. rtw_spt_band_free(wiphy->bands[NL80211_BAND_2GHZ]);
  8176. wiphy->bands[NL80211_BAND_2GHZ] = NULL;
  8177. }
  8178. if (wiphy->bands[NL80211_BAND_5GHZ]) {
  8179. rtw_spt_band_free(wiphy->bands[NL80211_BAND_5GHZ]);
  8180. wiphy->bands[NL80211_BAND_5GHZ] = NULL;
  8181. }
  8182. wiphy_free(wiphy);
  8183. }
  8184. int rtw_wiphy_register(struct wiphy *wiphy)
  8185. {
  8186. RTW_INFO(FUNC_WIPHY_FMT"\n", FUNC_WIPHY_ARG(wiphy));
  8187. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT)
  8188. rtw_cfgvendor_attach(wiphy);
  8189. #endif
  8190. rtw_regd_init(wiphy);
  8191. return wiphy_register(wiphy);
  8192. }
  8193. void rtw_wiphy_unregister(struct wiphy *wiphy)
  8194. {
  8195. RTW_INFO(FUNC_WIPHY_FMT"\n", FUNC_WIPHY_ARG(wiphy));
  8196. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT)
  8197. rtw_cfgvendor_detach(wiphy);
  8198. #endif
  8199. #if defined(RTW_DEDICATED_P2P_DEVICE)
  8200. rtw_pd_iface_free(wiphy);
  8201. #endif
  8202. return wiphy_unregister(wiphy);
  8203. }
  8204. int rtw_wdev_alloc(_adapter *padapter, struct wiphy *wiphy)
  8205. {
  8206. int ret = 0;
  8207. struct net_device *pnetdev = padapter->pnetdev;
  8208. struct wireless_dev *wdev;
  8209. struct rtw_wdev_priv *pwdev_priv;
  8210. RTW_INFO("%s(padapter=%p)\n", __func__, padapter);
  8211. /* wdev */
  8212. wdev = (struct wireless_dev *)rtw_zmalloc(sizeof(struct wireless_dev));
  8213. if (!wdev) {
  8214. RTW_INFO("Couldn't allocate wireless device\n");
  8215. ret = -ENOMEM;
  8216. goto exit;
  8217. }
  8218. wdev->wiphy = wiphy;
  8219. wdev->netdev = pnetdev;
  8220. wdev->iftype = NL80211_IFTYPE_STATION;
  8221. padapter->rtw_wdev = wdev;
  8222. pnetdev->ieee80211_ptr = wdev;
  8223. /* init pwdev_priv */
  8224. pwdev_priv = adapter_wdev_data(padapter);
  8225. pwdev_priv->rtw_wdev = wdev;
  8226. pwdev_priv->pmon_ndev = NULL;
  8227. pwdev_priv->ifname_mon[0] = '\0';
  8228. pwdev_priv->padapter = padapter;
  8229. pwdev_priv->scan_request = NULL;
  8230. _rtw_spinlock_init(&pwdev_priv->scan_req_lock);
  8231. pwdev_priv->connect_req = NULL;
  8232. _rtw_spinlock_init(&pwdev_priv->connect_req_lock);
  8233. pwdev_priv->p2p_enabled = _FALSE;
  8234. pwdev_priv->probe_resp_ie_update_time = rtw_get_current_time();
  8235. pwdev_priv->provdisc_req_issued = _FALSE;
  8236. rtw_wdev_invit_info_init(&pwdev_priv->invit_info);
  8237. rtw_wdev_nego_info_init(&pwdev_priv->nego_info);
  8238. pwdev_priv->bandroid_scan = _FALSE;
  8239. if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
  8240. pwdev_priv->power_mgmt = _TRUE;
  8241. else
  8242. pwdev_priv->power_mgmt = _FALSE;
  8243. _rtw_mutex_init(&pwdev_priv->roch_mutex);
  8244. #ifdef CONFIG_CONCURRENT_MODE
  8245. ATOMIC_SET(&pwdev_priv->switch_ch_to, 1);
  8246. #endif
  8247. #ifdef CONFIG_RTW_CFGVEDNOR_RSSIMONITOR
  8248. pwdev_priv->rssi_monitor_enable = 0;
  8249. pwdev_priv->rssi_monitor_max = 0;
  8250. pwdev_priv->rssi_monitor_min = 0;
  8251. #endif
  8252. exit:
  8253. return ret;
  8254. }
  8255. void rtw_wdev_free(struct wireless_dev *wdev)
  8256. {
  8257. if (!wdev)
  8258. return;
  8259. RTW_INFO("%s(wdev=%p)\n", __func__, wdev);
  8260. if (wdev_to_ndev(wdev)) {
  8261. _adapter *adapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  8262. struct rtw_wdev_priv *wdev_priv = adapter_wdev_data(adapter);
  8263. _irqL irqL;
  8264. _rtw_spinlock_free(&wdev_priv->scan_req_lock);
  8265. _enter_critical_bh(&wdev_priv->connect_req_lock, &irqL);
  8266. rtw_wdev_free_connect_req(wdev_priv);
  8267. _exit_critical_bh(&wdev_priv->connect_req_lock, &irqL);
  8268. _rtw_spinlock_free(&wdev_priv->connect_req_lock);
  8269. _rtw_mutex_free(&wdev_priv->roch_mutex);
  8270. }
  8271. rtw_mfree((u8 *)wdev, sizeof(struct wireless_dev));
  8272. }
  8273. void rtw_wdev_unregister(struct wireless_dev *wdev)
  8274. {
  8275. struct net_device *ndev;
  8276. _adapter *adapter;
  8277. struct rtw_wdev_priv *pwdev_priv;
  8278. if (!wdev)
  8279. return;
  8280. RTW_INFO("%s(wdev=%p)\n", __func__, wdev);
  8281. ndev = wdev_to_ndev(wdev);
  8282. if (!ndev)
  8283. return;
  8284. adapter = (_adapter *)rtw_netdev_priv(ndev);
  8285. pwdev_priv = adapter_wdev_data(adapter);
  8286. rtw_cfg80211_indicate_scan_done(adapter, _TRUE);
  8287. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)) || defined(COMPAT_KERNEL_RELEASE)
  8288. #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 2)
  8289. if (wdev->current_bss) {
  8290. #else
  8291. if (wdev->connected) {
  8292. #endif
  8293. RTW_INFO(FUNC_ADPT_FMT" clear current_bss by cfg80211_disconnected\n", FUNC_ADPT_ARG(adapter));
  8294. rtw_cfg80211_indicate_disconnect(adapter, 0, 1);
  8295. }
  8296. #endif
  8297. if (pwdev_priv->pmon_ndev) {
  8298. RTW_INFO("%s, unregister monitor interface\n", __func__);
  8299. unregister_netdev(pwdev_priv->pmon_ndev);
  8300. }
  8301. }
  8302. int rtw_cfg80211_ndev_res_alloc(_adapter *adapter)
  8303. {
  8304. int ret = _FAIL;
  8305. #if !defined(RTW_SINGLE_WIPHY)
  8306. struct wiphy *wiphy;
  8307. struct device *dev = dvobj_to_dev(adapter_to_dvobj(adapter));
  8308. wiphy = rtw_wiphy_alloc(adapter, dev);
  8309. if (wiphy == NULL)
  8310. goto exit;
  8311. adapter->wiphy = wiphy;
  8312. #endif
  8313. if (rtw_wdev_alloc(adapter, adapter_to_wiphy(adapter)) == 0)
  8314. ret = _SUCCESS;
  8315. #if !defined(RTW_SINGLE_WIPHY)
  8316. if (ret != _SUCCESS) {
  8317. rtw_wiphy_free(wiphy);
  8318. adapter->wiphy = NULL;
  8319. }
  8320. #endif
  8321. exit:
  8322. return ret;
  8323. }
  8324. void rtw_cfg80211_ndev_res_free(_adapter *adapter)
  8325. {
  8326. rtw_wdev_free(adapter->rtw_wdev);
  8327. adapter->rtw_wdev = NULL;
  8328. #if !defined(RTW_SINGLE_WIPHY)
  8329. rtw_wiphy_free(adapter_to_wiphy(adapter));
  8330. adapter->wiphy = NULL;
  8331. #endif
  8332. }
  8333. int rtw_cfg80211_ndev_res_register(_adapter *adapter)
  8334. {
  8335. int ret = _FAIL;
  8336. #if !defined(RTW_SINGLE_WIPHY)
  8337. if (rtw_wiphy_register(adapter_to_wiphy(adapter)) < 0) {
  8338. RTW_INFO("%s rtw_wiphy_register fail for if%d\n", __func__, (adapter->iface_id + 1));
  8339. goto exit;
  8340. }
  8341. #ifdef CONFIG_RFKILL_POLL
  8342. rtw_cfg80211_init_rfkill(adapter_to_wiphy(adapter));
  8343. #endif
  8344. #endif
  8345. ret = _SUCCESS;
  8346. exit:
  8347. return ret;
  8348. }
  8349. void rtw_cfg80211_ndev_res_unregister(_adapter *adapter)
  8350. {
  8351. rtw_wdev_unregister(adapter->rtw_wdev);
  8352. }
  8353. int rtw_cfg80211_dev_res_alloc(struct dvobj_priv *dvobj)
  8354. {
  8355. int ret = _FAIL;
  8356. #if defined(RTW_SINGLE_WIPHY)
  8357. struct wiphy *wiphy;
  8358. struct device *dev = dvobj_to_dev(dvobj);
  8359. wiphy = rtw_wiphy_alloc(dvobj_get_primary_adapter(dvobj), dev);
  8360. if (wiphy == NULL)
  8361. goto exit;
  8362. dvobj->wiphy = wiphy;
  8363. #endif
  8364. ret = _SUCCESS;
  8365. exit:
  8366. return ret;
  8367. }
  8368. void rtw_cfg80211_dev_res_free(struct dvobj_priv *dvobj)
  8369. {
  8370. #if defined(RTW_SINGLE_WIPHY)
  8371. rtw_wiphy_free(dvobj_to_wiphy(dvobj));
  8372. dvobj->wiphy = NULL;
  8373. #endif
  8374. }
  8375. int rtw_cfg80211_dev_res_register(struct dvobj_priv *dvobj)
  8376. {
  8377. int ret = _FAIL;
  8378. #if defined(RTW_SINGLE_WIPHY)
  8379. if (rtw_wiphy_register(dvobj_to_wiphy(dvobj)) != 0)
  8380. goto exit;
  8381. #ifdef CONFIG_RFKILL_POLL
  8382. rtw_cfg80211_init_rfkill(dvobj_to_wiphy(dvobj));
  8383. #endif
  8384. #endif
  8385. ret = _SUCCESS;
  8386. exit:
  8387. return ret;
  8388. }
  8389. void rtw_cfg80211_dev_res_unregister(struct dvobj_priv *dvobj)
  8390. {
  8391. #if defined(RTW_SINGLE_WIPHY)
  8392. #ifdef CONFIG_RFKILL_POLL
  8393. rtw_cfg80211_deinit_rfkill(dvobj_to_wiphy(dvobj));
  8394. #endif
  8395. rtw_wiphy_unregister(dvobj_to_wiphy(dvobj));
  8396. #endif
  8397. }
  8398. #endif /* CONFIG_IOCTL_CFG80211 */