cfg80211.c 190 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */
  17. #include <linux/kernel.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/module.h>
  20. #include <linux/vmalloc.h>
  21. #include <net/cfg80211.h>
  22. #include <net/netlink.h>
  23. #include <brcmu_utils.h>
  24. #include <defs.h>
  25. #include <brcmu_wifi.h>
  26. #include "core.h"
  27. #include "debug.h"
  28. #include "tracepoint.h"
  29. #include "fwil_types.h"
  30. #include "p2p.h"
  31. #include "btcoex.h"
  32. #include "pno.h"
  33. #include "cfg80211.h"
  34. #include "feature.h"
  35. #include "fwil.h"
  36. #include "proto.h"
  37. #include "vendor.h"
  38. #include "bus.h"
  39. #include "common.h"
  40. #define BRCMF_SCAN_IE_LEN_MAX 2048
  41. #define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
  42. #define WPA_OUI_TYPE 1
  43. #define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
  44. #define WME_OUI_TYPE 2
  45. #define WPS_OUI_TYPE 4
  46. #define VS_IE_FIXED_HDR_LEN 6
  47. #define WPA_IE_VERSION_LEN 2
  48. #define WPA_IE_MIN_OUI_LEN 4
  49. #define WPA_IE_SUITE_COUNT_LEN 2
  50. #define WPA_CIPHER_NONE 0 /* None */
  51. #define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
  52. #define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
  53. #define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
  54. #define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
  55. #define RSN_AKM_NONE 0 /* None (IBSS) */
  56. #define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
  57. #define RSN_AKM_PSK 2 /* Pre-shared Key */
  58. #define RSN_AKM_SHA256_1X 5 /* SHA256, 802.1X */
  59. #define RSN_AKM_SHA256_PSK 6 /* SHA256, Pre-shared Key */
  60. #define RSN_CAP_LEN 2 /* Length of RSN capabilities */
  61. #define RSN_CAP_PTK_REPLAY_CNTR_MASK (BIT(2) | BIT(3))
  62. #define RSN_CAP_MFPR_MASK BIT(6)
  63. #define RSN_CAP_MFPC_MASK BIT(7)
  64. #define RSN_PMKID_COUNT_LEN 2
  65. #define VNDR_IE_CMD_LEN 4 /* length of the set command
  66. * string :"add", "del" (+ NUL)
  67. */
  68. #define VNDR_IE_COUNT_OFFSET 4
  69. #define VNDR_IE_PKTFLAG_OFFSET 8
  70. #define VNDR_IE_VSIE_OFFSET 12
  71. #define VNDR_IE_HDR_SIZE 12
  72. #define VNDR_IE_PARSE_LIMIT 5
  73. #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
  74. #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
  75. #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
  76. #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
  77. #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
  78. #define BRCMF_SCAN_CHANNEL_TIME 40
  79. #define BRCMF_SCAN_UNASSOC_TIME 40
  80. #define BRCMF_SCAN_PASSIVE_TIME 120
  81. #define BRCMF_ND_INFO_TIMEOUT msecs_to_jiffies(2000)
  82. #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
  83. (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
  84. static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
  85. {
  86. if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
  87. brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
  88. vif->sme_state);
  89. return false;
  90. }
  91. return true;
  92. }
  93. #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
  94. #define RATETAB_ENT(_rateid, _flags) \
  95. { \
  96. .bitrate = RATE_TO_BASE100KBPS(_rateid), \
  97. .hw_value = (_rateid), \
  98. .flags = (_flags), \
  99. }
  100. static struct ieee80211_rate __wl_rates[] = {
  101. RATETAB_ENT(BRCM_RATE_1M, 0),
  102. RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
  103. RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
  104. RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
  105. RATETAB_ENT(BRCM_RATE_6M, 0),
  106. RATETAB_ENT(BRCM_RATE_9M, 0),
  107. RATETAB_ENT(BRCM_RATE_12M, 0),
  108. RATETAB_ENT(BRCM_RATE_18M, 0),
  109. RATETAB_ENT(BRCM_RATE_24M, 0),
  110. RATETAB_ENT(BRCM_RATE_36M, 0),
  111. RATETAB_ENT(BRCM_RATE_48M, 0),
  112. RATETAB_ENT(BRCM_RATE_54M, 0),
  113. };
  114. #define wl_g_rates (__wl_rates + 0)
  115. #define wl_g_rates_size ARRAY_SIZE(__wl_rates)
  116. #define wl_a_rates (__wl_rates + 4)
  117. #define wl_a_rates_size (wl_g_rates_size - 4)
  118. #define CHAN2G(_channel, _freq) { \
  119. .band = NL80211_BAND_2GHZ, \
  120. .center_freq = (_freq), \
  121. .hw_value = (_channel), \
  122. .max_antenna_gain = 0, \
  123. .max_power = 30, \
  124. }
  125. #define CHAN5G(_channel) { \
  126. .band = NL80211_BAND_5GHZ, \
  127. .center_freq = 5000 + (5 * (_channel)), \
  128. .hw_value = (_channel), \
  129. .max_antenna_gain = 0, \
  130. .max_power = 30, \
  131. }
  132. static struct ieee80211_channel __wl_2ghz_channels[] = {
  133. CHAN2G(1, 2412), CHAN2G(2, 2417), CHAN2G(3, 2422), CHAN2G(4, 2427),
  134. CHAN2G(5, 2432), CHAN2G(6, 2437), CHAN2G(7, 2442), CHAN2G(8, 2447),
  135. CHAN2G(9, 2452), CHAN2G(10, 2457), CHAN2G(11, 2462), CHAN2G(12, 2467),
  136. CHAN2G(13, 2472), CHAN2G(14, 2484)
  137. };
  138. static struct ieee80211_channel __wl_5ghz_channels[] = {
  139. CHAN5G(34), CHAN5G(36), CHAN5G(38), CHAN5G(40), CHAN5G(42),
  140. CHAN5G(44), CHAN5G(46), CHAN5G(48), CHAN5G(52), CHAN5G(56),
  141. CHAN5G(60), CHAN5G(64), CHAN5G(100), CHAN5G(104), CHAN5G(108),
  142. CHAN5G(112), CHAN5G(116), CHAN5G(120), CHAN5G(124), CHAN5G(128),
  143. CHAN5G(132), CHAN5G(136), CHAN5G(140), CHAN5G(144), CHAN5G(149),
  144. CHAN5G(153), CHAN5G(157), CHAN5G(161), CHAN5G(165)
  145. };
  146. /* Band templates duplicated per wiphy. The channel info
  147. * above is added to the band during setup.
  148. */
  149. static const struct ieee80211_supported_band __wl_band_2ghz = {
  150. .band = NL80211_BAND_2GHZ,
  151. .bitrates = wl_g_rates,
  152. .n_bitrates = wl_g_rates_size,
  153. };
  154. static const struct ieee80211_supported_band __wl_band_5ghz = {
  155. .band = NL80211_BAND_5GHZ,
  156. .bitrates = wl_a_rates,
  157. .n_bitrates = wl_a_rates_size,
  158. };
  159. /* This is to override regulatory domains defined in cfg80211 module (reg.c)
  160. * By default world regulatory domain defined in reg.c puts the flags
  161. * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
  162. * With respect to these flags, wpa_supplicant doesn't * start p2p
  163. * operations on 5GHz channels. All the changes in world regulatory
  164. * domain are to be done here.
  165. */
  166. static const struct ieee80211_regdomain brcmf_regdom = {
  167. .n_reg_rules = 4,
  168. .alpha2 = "99",
  169. .reg_rules = {
  170. /* IEEE 802.11b/g, channels 1..11 */
  171. REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
  172. /* If any */
  173. /* IEEE 802.11 channel 14 - Only JP enables
  174. * this and for 802.11b only
  175. */
  176. REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
  177. /* IEEE 802.11a, channel 36..64 */
  178. REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
  179. /* IEEE 802.11a, channel 100..165 */
  180. REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
  181. };
  182. /* Note: brcmf_cipher_suites is an array of int defining which cipher suites
  183. * are supported. A pointer to this array and the number of entries is passed
  184. * on to upper layers. AES_CMAC defines whether or not the driver supports MFP.
  185. * So the cipher suite AES_CMAC has to be the last one in the array, and when
  186. * device does not support MFP then the number of suites will be decreased by 1
  187. */
  188. static const u32 brcmf_cipher_suites[] = {
  189. WLAN_CIPHER_SUITE_WEP40,
  190. WLAN_CIPHER_SUITE_WEP104,
  191. WLAN_CIPHER_SUITE_TKIP,
  192. WLAN_CIPHER_SUITE_CCMP,
  193. /* Keep as last entry: */
  194. WLAN_CIPHER_SUITE_AES_CMAC
  195. };
  196. /* Vendor specific ie. id = 221, oui and type defines exact ie */
  197. struct brcmf_vs_tlv {
  198. u8 id;
  199. u8 len;
  200. u8 oui[3];
  201. u8 oui_type;
  202. };
  203. struct parsed_vndr_ie_info {
  204. u8 *ie_ptr;
  205. u32 ie_len; /* total length including id & length field */
  206. struct brcmf_vs_tlv vndrie;
  207. };
  208. struct parsed_vndr_ies {
  209. u32 count;
  210. struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
  211. };
  212. static u8 nl80211_band_to_fwil(enum nl80211_band band)
  213. {
  214. switch (band) {
  215. case NL80211_BAND_2GHZ:
  216. return WLC_BAND_2G;
  217. case NL80211_BAND_5GHZ:
  218. return WLC_BAND_5G;
  219. default:
  220. WARN_ON(1);
  221. break;
  222. }
  223. return 0;
  224. }
  225. static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
  226. struct cfg80211_chan_def *ch)
  227. {
  228. struct brcmu_chan ch_inf;
  229. s32 primary_offset;
  230. brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
  231. ch->chan->center_freq, ch->center_freq1, ch->width);
  232. ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
  233. primary_offset = ch->chan->center_freq - ch->center_freq1;
  234. switch (ch->width) {
  235. case NL80211_CHAN_WIDTH_20:
  236. case NL80211_CHAN_WIDTH_20_NOHT:
  237. ch_inf.bw = BRCMU_CHAN_BW_20;
  238. WARN_ON(primary_offset != 0);
  239. break;
  240. case NL80211_CHAN_WIDTH_40:
  241. ch_inf.bw = BRCMU_CHAN_BW_40;
  242. if (primary_offset > 0)
  243. ch_inf.sb = BRCMU_CHAN_SB_U;
  244. else
  245. ch_inf.sb = BRCMU_CHAN_SB_L;
  246. break;
  247. case NL80211_CHAN_WIDTH_80:
  248. ch_inf.bw = BRCMU_CHAN_BW_80;
  249. if (primary_offset == -30)
  250. ch_inf.sb = BRCMU_CHAN_SB_LL;
  251. else if (primary_offset == -10)
  252. ch_inf.sb = BRCMU_CHAN_SB_LU;
  253. else if (primary_offset == 10)
  254. ch_inf.sb = BRCMU_CHAN_SB_UL;
  255. else
  256. ch_inf.sb = BRCMU_CHAN_SB_UU;
  257. break;
  258. case NL80211_CHAN_WIDTH_80P80:
  259. case NL80211_CHAN_WIDTH_160:
  260. case NL80211_CHAN_WIDTH_5:
  261. case NL80211_CHAN_WIDTH_10:
  262. default:
  263. WARN_ON_ONCE(1);
  264. }
  265. switch (ch->chan->band) {
  266. case NL80211_BAND_2GHZ:
  267. ch_inf.band = BRCMU_CHAN_BAND_2G;
  268. break;
  269. case NL80211_BAND_5GHZ:
  270. ch_inf.band = BRCMU_CHAN_BAND_5G;
  271. break;
  272. case NL80211_BAND_60GHZ:
  273. default:
  274. WARN_ON_ONCE(1);
  275. }
  276. d11inf->encchspec(&ch_inf);
  277. return ch_inf.chspec;
  278. }
  279. u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
  280. struct ieee80211_channel *ch)
  281. {
  282. struct brcmu_chan ch_inf;
  283. ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
  284. ch_inf.bw = BRCMU_CHAN_BW_20;
  285. d11inf->encchspec(&ch_inf);
  286. return ch_inf.chspec;
  287. }
  288. /* Traverse a string of 1-byte tag/1-byte length/variable-length value
  289. * triples, returning a pointer to the substring whose first element
  290. * matches tag
  291. */
  292. static const struct brcmf_tlv *
  293. brcmf_parse_tlvs(const void *buf, int buflen, uint key)
  294. {
  295. const struct brcmf_tlv *elt = buf;
  296. int totlen = buflen;
  297. /* find tagged parameter */
  298. while (totlen >= TLV_HDR_LEN) {
  299. int len = elt->len;
  300. /* validate remaining totlen */
  301. if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
  302. return elt;
  303. elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
  304. totlen -= (len + TLV_HDR_LEN);
  305. }
  306. return NULL;
  307. }
  308. /* Is any of the tlvs the expected entry? If
  309. * not update the tlvs buffer pointer/length.
  310. */
  311. static bool
  312. brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
  313. const u8 *oui, u32 oui_len, u8 type)
  314. {
  315. /* If the contents match the OUI and the type */
  316. if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
  317. !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
  318. type == ie[TLV_BODY_OFF + oui_len]) {
  319. return true;
  320. }
  321. if (tlvs == NULL)
  322. return false;
  323. /* point to the next ie */
  324. ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
  325. /* calculate the length of the rest of the buffer */
  326. *tlvs_len -= (int)(ie - *tlvs);
  327. /* update the pointer to the start of the buffer */
  328. *tlvs = ie;
  329. return false;
  330. }
  331. static struct brcmf_vs_tlv *
  332. brcmf_find_wpaie(const u8 *parse, u32 len)
  333. {
  334. const struct brcmf_tlv *ie;
  335. while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
  336. if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
  337. WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
  338. return (struct brcmf_vs_tlv *)ie;
  339. }
  340. return NULL;
  341. }
  342. static struct brcmf_vs_tlv *
  343. brcmf_find_wpsie(const u8 *parse, u32 len)
  344. {
  345. const struct brcmf_tlv *ie;
  346. while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
  347. if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
  348. WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
  349. return (struct brcmf_vs_tlv *)ie;
  350. }
  351. return NULL;
  352. }
  353. static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg,
  354. struct brcmf_cfg80211_vif *vif,
  355. enum nl80211_iftype new_type)
  356. {
  357. struct brcmf_cfg80211_vif *pos;
  358. bool check_combos = false;
  359. int ret = 0;
  360. struct iface_combination_params params = {
  361. .num_different_channels = 1,
  362. };
  363. list_for_each_entry(pos, &cfg->vif_list, list)
  364. if (pos == vif) {
  365. params.iftype_num[new_type]++;
  366. } else {
  367. /* concurrent interfaces so need check combinations */
  368. check_combos = true;
  369. params.iftype_num[pos->wdev.iftype]++;
  370. }
  371. if (check_combos)
  372. ret = cfg80211_check_combinations(cfg->wiphy, &params);
  373. return ret;
  374. }
  375. static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg,
  376. enum nl80211_iftype new_type)
  377. {
  378. struct brcmf_cfg80211_vif *pos;
  379. struct iface_combination_params params = {
  380. .num_different_channels = 1,
  381. };
  382. list_for_each_entry(pos, &cfg->vif_list, list)
  383. params.iftype_num[pos->wdev.iftype]++;
  384. params.iftype_num[new_type]++;
  385. return cfg80211_check_combinations(cfg->wiphy, &params);
  386. }
  387. static void convert_key_from_CPU(struct brcmf_wsec_key *key,
  388. struct brcmf_wsec_key_le *key_le)
  389. {
  390. key_le->index = cpu_to_le32(key->index);
  391. key_le->len = cpu_to_le32(key->len);
  392. key_le->algo = cpu_to_le32(key->algo);
  393. key_le->flags = cpu_to_le32(key->flags);
  394. key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
  395. key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
  396. key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
  397. memcpy(key_le->data, key->data, sizeof(key->data));
  398. memcpy(key_le->ea, key->ea, sizeof(key->ea));
  399. }
  400. static int
  401. send_key_to_dongle(struct brcmf_if *ifp, struct brcmf_wsec_key *key)
  402. {
  403. int err;
  404. struct brcmf_wsec_key_le key_le;
  405. convert_key_from_CPU(key, &key_le);
  406. brcmf_netdev_wait_pend8021x(ifp);
  407. err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le,
  408. sizeof(key_le));
  409. if (err)
  410. brcmf_err("wsec_key error (%d)\n", err);
  411. return err;
  412. }
  413. static void
  414. brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
  415. {
  416. struct brcmf_cfg80211_vif *vif;
  417. struct brcmf_if *ifp;
  418. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  419. ifp = vif->ifp;
  420. if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
  421. (wdev->iftype == NL80211_IFTYPE_AP) ||
  422. (wdev->iftype == NL80211_IFTYPE_P2P_GO))
  423. brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
  424. ADDR_DIRECT);
  425. else
  426. brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
  427. ADDR_INDIRECT);
  428. }
  429. static int brcmf_get_first_free_bsscfgidx(struct brcmf_pub *drvr)
  430. {
  431. int bsscfgidx;
  432. for (bsscfgidx = 0; bsscfgidx < BRCMF_MAX_IFS; bsscfgidx++) {
  433. /* bsscfgidx 1 is reserved for legacy P2P */
  434. if (bsscfgidx == 1)
  435. continue;
  436. if (!drvr->iflist[bsscfgidx])
  437. return bsscfgidx;
  438. }
  439. return -ENOMEM;
  440. }
  441. static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp)
  442. {
  443. struct brcmf_mbss_ssid_le mbss_ssid_le;
  444. int bsscfgidx;
  445. int err;
  446. memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
  447. bsscfgidx = brcmf_get_first_free_bsscfgidx(ifp->drvr);
  448. if (bsscfgidx < 0)
  449. return bsscfgidx;
  450. mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx);
  451. mbss_ssid_le.SSID_len = cpu_to_le32(5);
  452. sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx);
  453. err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le,
  454. sizeof(mbss_ssid_le));
  455. if (err < 0)
  456. brcmf_err("setting ssid failed %d\n", err);
  457. return err;
  458. }
  459. /**
  460. * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS
  461. *
  462. * @wiphy: wiphy device of new interface.
  463. * @name: name of the new interface.
  464. * @params: contains mac address for AP device.
  465. */
  466. static
  467. struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name,
  468. struct vif_params *params)
  469. {
  470. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  471. struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
  472. struct brcmf_cfg80211_vif *vif;
  473. int err;
  474. if (brcmf_cfg80211_vif_event_armed(cfg))
  475. return ERR_PTR(-EBUSY);
  476. brcmf_dbg(INFO, "Adding vif \"%s\"\n", name);
  477. vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP);
  478. if (IS_ERR(vif))
  479. return (struct wireless_dev *)vif;
  480. brcmf_cfg80211_arm_vif_event(cfg, vif);
  481. err = brcmf_cfg80211_request_ap_if(ifp);
  482. if (err) {
  483. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  484. goto fail;
  485. }
  486. /* wait for firmware event */
  487. err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_ADD,
  488. BRCMF_VIF_EVENT_TIMEOUT);
  489. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  490. if (!err) {
  491. brcmf_err("timeout occurred\n");
  492. err = -EIO;
  493. goto fail;
  494. }
  495. /* interface created in firmware */
  496. ifp = vif->ifp;
  497. if (!ifp) {
  498. brcmf_err("no if pointer provided\n");
  499. err = -ENOENT;
  500. goto fail;
  501. }
  502. strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
  503. err = brcmf_net_attach(ifp, true);
  504. if (err) {
  505. brcmf_err("Registering netdevice failed\n");
  506. free_netdev(ifp->ndev);
  507. goto fail;
  508. }
  509. return &ifp->vif->wdev;
  510. fail:
  511. brcmf_free_vif(vif);
  512. return ERR_PTR(err);
  513. }
  514. static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
  515. {
  516. enum nl80211_iftype iftype;
  517. iftype = vif->wdev.iftype;
  518. return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
  519. }
  520. static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
  521. {
  522. return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
  523. }
  524. static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
  525. const char *name,
  526. unsigned char name_assign_type,
  527. enum nl80211_iftype type,
  528. struct vif_params *params)
  529. {
  530. struct wireless_dev *wdev;
  531. int err;
  532. brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
  533. err = brcmf_vif_add_validate(wiphy_to_cfg(wiphy), type);
  534. if (err) {
  535. brcmf_err("iface validation failed: err=%d\n", err);
  536. return ERR_PTR(err);
  537. }
  538. switch (type) {
  539. case NL80211_IFTYPE_ADHOC:
  540. case NL80211_IFTYPE_STATION:
  541. case NL80211_IFTYPE_AP_VLAN:
  542. case NL80211_IFTYPE_WDS:
  543. case NL80211_IFTYPE_MONITOR:
  544. case NL80211_IFTYPE_MESH_POINT:
  545. return ERR_PTR(-EOPNOTSUPP);
  546. case NL80211_IFTYPE_AP:
  547. wdev = brcmf_ap_add_vif(wiphy, name, params);
  548. break;
  549. case NL80211_IFTYPE_P2P_CLIENT:
  550. case NL80211_IFTYPE_P2P_GO:
  551. case NL80211_IFTYPE_P2P_DEVICE:
  552. wdev = brcmf_p2p_add_vif(wiphy, name, name_assign_type, type, params);
  553. break;
  554. case NL80211_IFTYPE_UNSPECIFIED:
  555. default:
  556. return ERR_PTR(-EINVAL);
  557. }
  558. if (IS_ERR(wdev))
  559. brcmf_err("add iface %s type %d failed: err=%d\n",
  560. name, type, (int)PTR_ERR(wdev));
  561. else
  562. brcmf_cfg80211_update_proto_addr_mode(wdev);
  563. return wdev;
  564. }
  565. static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
  566. {
  567. if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
  568. brcmf_set_mpc(ifp, mpc);
  569. }
  570. void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
  571. {
  572. s32 err = 0;
  573. if (check_vif_up(ifp->vif)) {
  574. err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
  575. if (err) {
  576. brcmf_err("fail to set mpc\n");
  577. return;
  578. }
  579. brcmf_dbg(INFO, "MPC : %d\n", mpc);
  580. }
  581. }
  582. s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
  583. struct brcmf_if *ifp, bool aborted,
  584. bool fw_abort)
  585. {
  586. struct brcmf_scan_params_le params_le;
  587. struct cfg80211_scan_request *scan_request;
  588. u64 reqid;
  589. u32 bucket;
  590. s32 err = 0;
  591. brcmf_dbg(SCAN, "Enter\n");
  592. /* clear scan request, because the FW abort can cause a second call */
  593. /* to this functon and might cause a double cfg80211_scan_done */
  594. scan_request = cfg->scan_request;
  595. cfg->scan_request = NULL;
  596. if (timer_pending(&cfg->escan_timeout))
  597. del_timer_sync(&cfg->escan_timeout);
  598. if (fw_abort) {
  599. /* Do a scan abort to stop the driver's scan engine */
  600. brcmf_dbg(SCAN, "ABORT scan in firmware\n");
  601. memset(&params_le, 0, sizeof(params_le));
  602. eth_broadcast_addr(params_le.bssid);
  603. params_le.bss_type = DOT11_BSSTYPE_ANY;
  604. params_le.scan_type = 0;
  605. params_le.channel_num = cpu_to_le32(1);
  606. params_le.nprobes = cpu_to_le32(1);
  607. params_le.active_time = cpu_to_le32(-1);
  608. params_le.passive_time = cpu_to_le32(-1);
  609. params_le.home_time = cpu_to_le32(-1);
  610. /* Scan is aborted by setting channel_list[0] to -1 */
  611. params_le.channel_list[0] = cpu_to_le16(-1);
  612. /* E-Scan (or anyother type) can be aborted by SCAN */
  613. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
  614. &params_le, sizeof(params_le));
  615. if (err)
  616. brcmf_err("Scan abort failed\n");
  617. }
  618. brcmf_scan_config_mpc(ifp, 1);
  619. /*
  620. * e-scan can be initiated internally
  621. * which takes precedence.
  622. */
  623. if (cfg->int_escan_map) {
  624. brcmf_dbg(SCAN, "scheduled scan completed (%x)\n",
  625. cfg->int_escan_map);
  626. while (cfg->int_escan_map) {
  627. bucket = __ffs(cfg->int_escan_map);
  628. cfg->int_escan_map &= ~BIT(bucket);
  629. reqid = brcmf_pno_find_reqid_by_bucket(cfg->pno,
  630. bucket);
  631. if (!aborted) {
  632. brcmf_dbg(SCAN, "report results: reqid=%llu\n",
  633. reqid);
  634. cfg80211_sched_scan_results(cfg_to_wiphy(cfg),
  635. reqid);
  636. }
  637. }
  638. } else if (scan_request) {
  639. struct cfg80211_scan_info info = {
  640. .aborted = aborted,
  641. };
  642. brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
  643. aborted ? "Aborted" : "Done");
  644. cfg80211_scan_done(scan_request, &info);
  645. }
  646. if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
  647. brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
  648. return err;
  649. }
  650. static int brcmf_cfg80211_del_ap_iface(struct wiphy *wiphy,
  651. struct wireless_dev *wdev)
  652. {
  653. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  654. struct net_device *ndev = wdev->netdev;
  655. struct brcmf_if *ifp = netdev_priv(ndev);
  656. int ret;
  657. int err;
  658. brcmf_cfg80211_arm_vif_event(cfg, ifp->vif);
  659. err = brcmf_fil_bsscfg_data_set(ifp, "interface_remove", NULL, 0);
  660. if (err) {
  661. brcmf_err("interface_remove failed %d\n", err);
  662. goto err_unarm;
  663. }
  664. /* wait for firmware event */
  665. ret = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_DEL,
  666. BRCMF_VIF_EVENT_TIMEOUT);
  667. if (!ret) {
  668. brcmf_err("timeout occurred\n");
  669. err = -EIO;
  670. goto err_unarm;
  671. }
  672. brcmf_remove_interface(ifp, true);
  673. err_unarm:
  674. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  675. return err;
  676. }
  677. static
  678. int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
  679. {
  680. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  681. struct net_device *ndev = wdev->netdev;
  682. if (ndev && ndev == cfg_to_ndev(cfg))
  683. return -ENOTSUPP;
  684. /* vif event pending in firmware */
  685. if (brcmf_cfg80211_vif_event_armed(cfg))
  686. return -EBUSY;
  687. if (ndev) {
  688. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
  689. cfg->escan_info.ifp == netdev_priv(ndev))
  690. brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
  691. true, true);
  692. brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
  693. }
  694. switch (wdev->iftype) {
  695. case NL80211_IFTYPE_ADHOC:
  696. case NL80211_IFTYPE_STATION:
  697. case NL80211_IFTYPE_AP_VLAN:
  698. case NL80211_IFTYPE_WDS:
  699. case NL80211_IFTYPE_MONITOR:
  700. case NL80211_IFTYPE_MESH_POINT:
  701. return -EOPNOTSUPP;
  702. case NL80211_IFTYPE_AP:
  703. return brcmf_cfg80211_del_ap_iface(wiphy, wdev);
  704. case NL80211_IFTYPE_P2P_CLIENT:
  705. case NL80211_IFTYPE_P2P_GO:
  706. case NL80211_IFTYPE_P2P_DEVICE:
  707. return brcmf_p2p_del_vif(wiphy, wdev);
  708. case NL80211_IFTYPE_UNSPECIFIED:
  709. default:
  710. return -EINVAL;
  711. }
  712. return -EOPNOTSUPP;
  713. }
  714. static s32
  715. brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
  716. enum nl80211_iftype type,
  717. struct vif_params *params)
  718. {
  719. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  720. struct brcmf_if *ifp = netdev_priv(ndev);
  721. struct brcmf_cfg80211_vif *vif = ifp->vif;
  722. s32 infra = 0;
  723. s32 ap = 0;
  724. s32 err = 0;
  725. brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, type=%d\n", ifp->bsscfgidx,
  726. type);
  727. /* WAR: There are a number of p2p interface related problems which
  728. * need to be handled initially (before doing the validate).
  729. * wpa_supplicant tends to do iface changes on p2p device/client/go
  730. * which are not always possible/allowed. However we need to return
  731. * OK otherwise the wpa_supplicant wont start. The situation differs
  732. * on configuration and setup (p2pon=1 module param). The first check
  733. * is to see if the request is a change to station for p2p iface.
  734. */
  735. if ((type == NL80211_IFTYPE_STATION) &&
  736. ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
  737. (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) ||
  738. (vif->wdev.iftype == NL80211_IFTYPE_P2P_DEVICE))) {
  739. brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
  740. /* Now depending on whether module param p2pon=1 was used the
  741. * response needs to be either 0 or EOPNOTSUPP. The reason is
  742. * that if p2pon=1 is used, but a newer supplicant is used then
  743. * we should return an error, as this combination wont work.
  744. * In other situations 0 is returned and supplicant will start
  745. * normally. It will give a trace in cfg80211, but it is the
  746. * only way to get it working. Unfortunately this will result
  747. * in situation where we wont support new supplicant in
  748. * combination with module param p2pon=1, but that is the way
  749. * it is. If the user tries this then unloading of driver might
  750. * fail/lock.
  751. */
  752. if (cfg->p2p.p2pdev_dynamically)
  753. return -EOPNOTSUPP;
  754. else
  755. return 0;
  756. }
  757. err = brcmf_vif_change_validate(wiphy_to_cfg(wiphy), vif, type);
  758. if (err) {
  759. brcmf_err("iface validation failed: err=%d\n", err);
  760. return err;
  761. }
  762. switch (type) {
  763. case NL80211_IFTYPE_MONITOR:
  764. case NL80211_IFTYPE_WDS:
  765. brcmf_err("type (%d) : currently we do not support this type\n",
  766. type);
  767. return -EOPNOTSUPP;
  768. case NL80211_IFTYPE_ADHOC:
  769. infra = 0;
  770. break;
  771. case NL80211_IFTYPE_STATION:
  772. infra = 1;
  773. break;
  774. case NL80211_IFTYPE_AP:
  775. case NL80211_IFTYPE_P2P_GO:
  776. ap = 1;
  777. break;
  778. default:
  779. err = -EINVAL;
  780. goto done;
  781. }
  782. if (ap) {
  783. if (type == NL80211_IFTYPE_P2P_GO) {
  784. brcmf_dbg(INFO, "IF Type = P2P GO\n");
  785. err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
  786. }
  787. if (!err) {
  788. brcmf_dbg(INFO, "IF Type = AP\n");
  789. }
  790. } else {
  791. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
  792. if (err) {
  793. brcmf_err("WLC_SET_INFRA error (%d)\n", err);
  794. err = -EAGAIN;
  795. goto done;
  796. }
  797. brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
  798. "Adhoc" : "Infra");
  799. }
  800. ndev->ieee80211_ptr->iftype = type;
  801. brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
  802. done:
  803. brcmf_dbg(TRACE, "Exit\n");
  804. return err;
  805. }
  806. static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
  807. struct brcmf_scan_params_le *params_le,
  808. struct cfg80211_scan_request *request)
  809. {
  810. u32 n_ssids;
  811. u32 n_channels;
  812. s32 i;
  813. s32 offset;
  814. u16 chanspec;
  815. char *ptr;
  816. struct brcmf_ssid_le ssid_le;
  817. eth_broadcast_addr(params_le->bssid);
  818. params_le->bss_type = DOT11_BSSTYPE_ANY;
  819. params_le->scan_type = BRCMF_SCANTYPE_ACTIVE;
  820. params_le->channel_num = 0;
  821. params_le->nprobes = cpu_to_le32(-1);
  822. params_le->active_time = cpu_to_le32(-1);
  823. params_le->passive_time = cpu_to_le32(-1);
  824. params_le->home_time = cpu_to_le32(-1);
  825. memset(&params_le->ssid_le, 0, sizeof(params_le->ssid_le));
  826. n_ssids = request->n_ssids;
  827. n_channels = request->n_channels;
  828. /* Copy channel array if applicable */
  829. brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
  830. n_channels);
  831. if (n_channels > 0) {
  832. for (i = 0; i < n_channels; i++) {
  833. chanspec = channel_to_chanspec(&cfg->d11inf,
  834. request->channels[i]);
  835. brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
  836. request->channels[i]->hw_value, chanspec);
  837. params_le->channel_list[i] = cpu_to_le16(chanspec);
  838. }
  839. } else {
  840. brcmf_dbg(SCAN, "Scanning all channels\n");
  841. }
  842. /* Copy ssid array if applicable */
  843. brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
  844. if (n_ssids > 0) {
  845. offset = offsetof(struct brcmf_scan_params_le, channel_list) +
  846. n_channels * sizeof(u16);
  847. offset = roundup(offset, sizeof(u32));
  848. ptr = (char *)params_le + offset;
  849. for (i = 0; i < n_ssids; i++) {
  850. memset(&ssid_le, 0, sizeof(ssid_le));
  851. ssid_le.SSID_len =
  852. cpu_to_le32(request->ssids[i].ssid_len);
  853. memcpy(ssid_le.SSID, request->ssids[i].ssid,
  854. request->ssids[i].ssid_len);
  855. if (!ssid_le.SSID_len)
  856. brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
  857. else
  858. brcmf_dbg(SCAN, "%d: scan for %.32s size=%d\n",
  859. i, ssid_le.SSID, ssid_le.SSID_len);
  860. memcpy(ptr, &ssid_le, sizeof(ssid_le));
  861. ptr += sizeof(ssid_le);
  862. }
  863. } else {
  864. brcmf_dbg(SCAN, "Performing passive scan\n");
  865. params_le->scan_type = BRCMF_SCANTYPE_PASSIVE;
  866. }
  867. /* Adding mask to channel numbers */
  868. params_le->channel_num =
  869. cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
  870. (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
  871. }
  872. static s32
  873. brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
  874. struct cfg80211_scan_request *request)
  875. {
  876. s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
  877. offsetof(struct brcmf_escan_params_le, params_le);
  878. struct brcmf_escan_params_le *params;
  879. s32 err = 0;
  880. brcmf_dbg(SCAN, "E-SCAN START\n");
  881. if (request != NULL) {
  882. /* Allocate space for populating ssids in struct */
  883. params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
  884. /* Allocate space for populating ssids in struct */
  885. params_size += sizeof(struct brcmf_ssid_le) * request->n_ssids;
  886. }
  887. params = kzalloc(params_size, GFP_KERNEL);
  888. if (!params) {
  889. err = -ENOMEM;
  890. goto exit;
  891. }
  892. BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
  893. brcmf_escan_prep(cfg, &params->params_le, request);
  894. params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
  895. params->action = cpu_to_le16(WL_ESCAN_ACTION_START);
  896. params->sync_id = cpu_to_le16(0x1234);
  897. err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
  898. if (err) {
  899. if (err == -EBUSY)
  900. brcmf_dbg(INFO, "system busy : escan canceled\n");
  901. else
  902. brcmf_err("error (%d)\n", err);
  903. }
  904. kfree(params);
  905. exit:
  906. return err;
  907. }
  908. static s32
  909. brcmf_do_escan(struct brcmf_if *ifp, struct cfg80211_scan_request *request)
  910. {
  911. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  912. s32 err;
  913. struct brcmf_scan_results *results;
  914. struct escan_info *escan = &cfg->escan_info;
  915. brcmf_dbg(SCAN, "Enter\n");
  916. escan->ifp = ifp;
  917. escan->wiphy = cfg->wiphy;
  918. escan->escan_state = WL_ESCAN_STATE_SCANNING;
  919. brcmf_scan_config_mpc(ifp, 0);
  920. results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
  921. results->version = 0;
  922. results->count = 0;
  923. results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
  924. err = escan->run(cfg, ifp, request);
  925. if (err)
  926. brcmf_scan_config_mpc(ifp, 1);
  927. return err;
  928. }
  929. static s32
  930. brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
  931. {
  932. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  933. struct brcmf_cfg80211_vif *vif;
  934. s32 err = 0;
  935. brcmf_dbg(TRACE, "Enter\n");
  936. vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
  937. if (!check_vif_up(vif))
  938. return -EIO;
  939. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
  940. brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
  941. return -EAGAIN;
  942. }
  943. if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
  944. brcmf_err("Scanning being aborted: status (%lu)\n",
  945. cfg->scan_status);
  946. return -EAGAIN;
  947. }
  948. if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
  949. brcmf_err("Scanning suppressed: status (%lu)\n",
  950. cfg->scan_status);
  951. return -EAGAIN;
  952. }
  953. if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state)) {
  954. brcmf_err("Connecting: status (%lu)\n", vif->sme_state);
  955. return -EAGAIN;
  956. }
  957. /* If scan req comes for p2p0, send it over primary I/F */
  958. if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
  959. vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
  960. brcmf_dbg(SCAN, "START ESCAN\n");
  961. cfg->scan_request = request;
  962. set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  963. cfg->escan_info.run = brcmf_run_escan;
  964. err = brcmf_p2p_scan_prep(wiphy, request, vif);
  965. if (err)
  966. goto scan_out;
  967. err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
  968. request->ie, request->ie_len);
  969. if (err)
  970. goto scan_out;
  971. err = brcmf_do_escan(vif->ifp, request);
  972. if (err)
  973. goto scan_out;
  974. /* Arm scan timeout timer */
  975. mod_timer(&cfg->escan_timeout,
  976. jiffies + msecs_to_jiffies(BRCMF_ESCAN_TIMER_INTERVAL_MS));
  977. return 0;
  978. scan_out:
  979. brcmf_err("scan error (%d)\n", err);
  980. clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  981. cfg->scan_request = NULL;
  982. return err;
  983. }
  984. static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
  985. {
  986. s32 err = 0;
  987. err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
  988. rts_threshold);
  989. if (err)
  990. brcmf_err("Error (%d)\n", err);
  991. return err;
  992. }
  993. static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
  994. {
  995. s32 err = 0;
  996. err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
  997. frag_threshold);
  998. if (err)
  999. brcmf_err("Error (%d)\n", err);
  1000. return err;
  1001. }
  1002. static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
  1003. {
  1004. s32 err = 0;
  1005. u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
  1006. err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
  1007. if (err) {
  1008. brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
  1009. return err;
  1010. }
  1011. return err;
  1012. }
  1013. static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1014. {
  1015. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1016. struct net_device *ndev = cfg_to_ndev(cfg);
  1017. struct brcmf_if *ifp = netdev_priv(ndev);
  1018. s32 err = 0;
  1019. brcmf_dbg(TRACE, "Enter\n");
  1020. if (!check_vif_up(ifp->vif))
  1021. return -EIO;
  1022. if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
  1023. (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
  1024. cfg->conf->rts_threshold = wiphy->rts_threshold;
  1025. err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
  1026. if (!err)
  1027. goto done;
  1028. }
  1029. if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
  1030. (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
  1031. cfg->conf->frag_threshold = wiphy->frag_threshold;
  1032. err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
  1033. if (!err)
  1034. goto done;
  1035. }
  1036. if (changed & WIPHY_PARAM_RETRY_LONG
  1037. && (cfg->conf->retry_long != wiphy->retry_long)) {
  1038. cfg->conf->retry_long = wiphy->retry_long;
  1039. err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
  1040. if (!err)
  1041. goto done;
  1042. }
  1043. if (changed & WIPHY_PARAM_RETRY_SHORT
  1044. && (cfg->conf->retry_short != wiphy->retry_short)) {
  1045. cfg->conf->retry_short = wiphy->retry_short;
  1046. err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
  1047. if (!err)
  1048. goto done;
  1049. }
  1050. done:
  1051. brcmf_dbg(TRACE, "Exit\n");
  1052. return err;
  1053. }
  1054. static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
  1055. {
  1056. memset(prof, 0, sizeof(*prof));
  1057. }
  1058. static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e)
  1059. {
  1060. u16 reason;
  1061. switch (e->event_code) {
  1062. case BRCMF_E_DEAUTH:
  1063. case BRCMF_E_DEAUTH_IND:
  1064. case BRCMF_E_DISASSOC_IND:
  1065. reason = e->reason;
  1066. break;
  1067. case BRCMF_E_LINK:
  1068. default:
  1069. reason = 0;
  1070. break;
  1071. }
  1072. return reason;
  1073. }
  1074. static int brcmf_set_pmk(struct brcmf_if *ifp, const u8 *pmk_data, u16 pmk_len)
  1075. {
  1076. struct brcmf_wsec_pmk_le pmk;
  1077. int i, err;
  1078. /* convert to firmware key format */
  1079. pmk.key_len = cpu_to_le16(pmk_len << 1);
  1080. pmk.flags = cpu_to_le16(BRCMF_WSEC_PASSPHRASE);
  1081. for (i = 0; i < pmk_len; i++)
  1082. snprintf(&pmk.key[2 * i], 3, "%02x", pmk_data[i]);
  1083. /* store psk in firmware */
  1084. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_WSEC_PMK,
  1085. &pmk, sizeof(pmk));
  1086. if (err < 0)
  1087. brcmf_err("failed to change PSK in firmware (len=%u)\n",
  1088. pmk_len);
  1089. return err;
  1090. }
  1091. static void brcmf_link_down(struct brcmf_cfg80211_vif *vif, u16 reason)
  1092. {
  1093. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
  1094. s32 err = 0;
  1095. brcmf_dbg(TRACE, "Enter\n");
  1096. if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
  1097. brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n");
  1098. err = brcmf_fil_cmd_data_set(vif->ifp,
  1099. BRCMF_C_DISASSOC, NULL, 0);
  1100. if (err) {
  1101. brcmf_err("WLC_DISASSOC failed (%d)\n", err);
  1102. }
  1103. if ((vif->wdev.iftype == NL80211_IFTYPE_STATION) ||
  1104. (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT))
  1105. cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0,
  1106. true, GFP_KERNEL);
  1107. }
  1108. clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
  1109. clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
  1110. brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
  1111. if (vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_NONE) {
  1112. brcmf_set_pmk(vif->ifp, NULL, 0);
  1113. vif->profile.use_fwsup = BRCMF_PROFILE_FWSUP_NONE;
  1114. }
  1115. brcmf_dbg(TRACE, "Exit\n");
  1116. }
  1117. static s32
  1118. brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
  1119. struct cfg80211_ibss_params *params)
  1120. {
  1121. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1122. struct brcmf_if *ifp = netdev_priv(ndev);
  1123. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  1124. struct brcmf_join_params join_params;
  1125. size_t join_params_size = 0;
  1126. s32 err = 0;
  1127. s32 wsec = 0;
  1128. s32 bcnprd;
  1129. u16 chanspec;
  1130. u32 ssid_len;
  1131. brcmf_dbg(TRACE, "Enter\n");
  1132. if (!check_vif_up(ifp->vif))
  1133. return -EIO;
  1134. if (params->ssid)
  1135. brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
  1136. else {
  1137. brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
  1138. return -EOPNOTSUPP;
  1139. }
  1140. set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1141. if (params->bssid)
  1142. brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
  1143. else
  1144. brcmf_dbg(CONN, "No BSSID specified\n");
  1145. if (params->chandef.chan)
  1146. brcmf_dbg(CONN, "channel: %d\n",
  1147. params->chandef.chan->center_freq);
  1148. else
  1149. brcmf_dbg(CONN, "no channel specified\n");
  1150. if (params->channel_fixed)
  1151. brcmf_dbg(CONN, "fixed channel required\n");
  1152. else
  1153. brcmf_dbg(CONN, "no fixed channel required\n");
  1154. if (params->ie && params->ie_len)
  1155. brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
  1156. else
  1157. brcmf_dbg(CONN, "no ie specified\n");
  1158. if (params->beacon_interval)
  1159. brcmf_dbg(CONN, "beacon interval: %d\n",
  1160. params->beacon_interval);
  1161. else
  1162. brcmf_dbg(CONN, "no beacon interval specified\n");
  1163. if (params->basic_rates)
  1164. brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
  1165. else
  1166. brcmf_dbg(CONN, "no basic rates specified\n");
  1167. if (params->privacy)
  1168. brcmf_dbg(CONN, "privacy required\n");
  1169. else
  1170. brcmf_dbg(CONN, "no privacy required\n");
  1171. /* Configure Privacy for starter */
  1172. if (params->privacy)
  1173. wsec |= WEP_ENABLED;
  1174. err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
  1175. if (err) {
  1176. brcmf_err("wsec failed (%d)\n", err);
  1177. goto done;
  1178. }
  1179. /* Configure Beacon Interval for starter */
  1180. if (params->beacon_interval)
  1181. bcnprd = params->beacon_interval;
  1182. else
  1183. bcnprd = 100;
  1184. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
  1185. if (err) {
  1186. brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
  1187. goto done;
  1188. }
  1189. /* Configure required join parameter */
  1190. memset(&join_params, 0, sizeof(struct brcmf_join_params));
  1191. /* SSID */
  1192. ssid_len = min_t(u32, params->ssid_len, IEEE80211_MAX_SSID_LEN);
  1193. memcpy(join_params.ssid_le.SSID, params->ssid, ssid_len);
  1194. join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
  1195. join_params_size = sizeof(join_params.ssid_le);
  1196. /* BSSID */
  1197. if (params->bssid) {
  1198. memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
  1199. join_params_size += BRCMF_ASSOC_PARAMS_FIXED_SIZE;
  1200. memcpy(profile->bssid, params->bssid, ETH_ALEN);
  1201. } else {
  1202. eth_broadcast_addr(join_params.params_le.bssid);
  1203. eth_zero_addr(profile->bssid);
  1204. }
  1205. /* Channel */
  1206. if (params->chandef.chan) {
  1207. u32 target_channel;
  1208. cfg->channel =
  1209. ieee80211_frequency_to_channel(
  1210. params->chandef.chan->center_freq);
  1211. if (params->channel_fixed) {
  1212. /* adding chanspec */
  1213. chanspec = chandef_to_chanspec(&cfg->d11inf,
  1214. &params->chandef);
  1215. join_params.params_le.chanspec_list[0] =
  1216. cpu_to_le16(chanspec);
  1217. join_params.params_le.chanspec_num = cpu_to_le32(1);
  1218. join_params_size += sizeof(join_params.params_le);
  1219. }
  1220. /* set channel for starter */
  1221. target_channel = cfg->channel;
  1222. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
  1223. target_channel);
  1224. if (err) {
  1225. brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
  1226. goto done;
  1227. }
  1228. } else
  1229. cfg->channel = 0;
  1230. cfg->ibss_starter = false;
  1231. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
  1232. &join_params, join_params_size);
  1233. if (err) {
  1234. brcmf_err("WLC_SET_SSID failed (%d)\n", err);
  1235. goto done;
  1236. }
  1237. done:
  1238. if (err)
  1239. clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1240. brcmf_dbg(TRACE, "Exit\n");
  1241. return err;
  1242. }
  1243. static s32
  1244. brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
  1245. {
  1246. struct brcmf_if *ifp = netdev_priv(ndev);
  1247. brcmf_dbg(TRACE, "Enter\n");
  1248. if (!check_vif_up(ifp->vif)) {
  1249. /* When driver is being unloaded, it can end up here. If an
  1250. * error is returned then later on a debug trace in the wireless
  1251. * core module will be printed. To avoid this 0 is returned.
  1252. */
  1253. return 0;
  1254. }
  1255. brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING);
  1256. brcmf_net_setcarrier(ifp, false);
  1257. brcmf_dbg(TRACE, "Exit\n");
  1258. return 0;
  1259. }
  1260. static s32 brcmf_set_wpa_version(struct net_device *ndev,
  1261. struct cfg80211_connect_params *sme)
  1262. {
  1263. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
  1264. struct brcmf_cfg80211_security *sec;
  1265. s32 val = 0;
  1266. s32 err = 0;
  1267. if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  1268. val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
  1269. else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  1270. val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
  1271. else
  1272. val = WPA_AUTH_DISABLED;
  1273. brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
  1274. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
  1275. if (err) {
  1276. brcmf_err("set wpa_auth failed (%d)\n", err);
  1277. return err;
  1278. }
  1279. sec = &profile->sec;
  1280. sec->wpa_versions = sme->crypto.wpa_versions;
  1281. return err;
  1282. }
  1283. static s32 brcmf_set_auth_type(struct net_device *ndev,
  1284. struct cfg80211_connect_params *sme)
  1285. {
  1286. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
  1287. struct brcmf_cfg80211_security *sec;
  1288. s32 val = 0;
  1289. s32 err = 0;
  1290. switch (sme->auth_type) {
  1291. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  1292. val = 0;
  1293. brcmf_dbg(CONN, "open system\n");
  1294. break;
  1295. case NL80211_AUTHTYPE_SHARED_KEY:
  1296. val = 1;
  1297. brcmf_dbg(CONN, "shared key\n");
  1298. break;
  1299. default:
  1300. val = 2;
  1301. brcmf_dbg(CONN, "automatic, auth type (%d)\n", sme->auth_type);
  1302. break;
  1303. }
  1304. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
  1305. if (err) {
  1306. brcmf_err("set auth failed (%d)\n", err);
  1307. return err;
  1308. }
  1309. sec = &profile->sec;
  1310. sec->auth_type = sme->auth_type;
  1311. return err;
  1312. }
  1313. static s32
  1314. brcmf_set_wsec_mode(struct net_device *ndev,
  1315. struct cfg80211_connect_params *sme)
  1316. {
  1317. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
  1318. struct brcmf_cfg80211_security *sec;
  1319. s32 pval = 0;
  1320. s32 gval = 0;
  1321. s32 wsec;
  1322. s32 err = 0;
  1323. if (sme->crypto.n_ciphers_pairwise) {
  1324. switch (sme->crypto.ciphers_pairwise[0]) {
  1325. case WLAN_CIPHER_SUITE_WEP40:
  1326. case WLAN_CIPHER_SUITE_WEP104:
  1327. pval = WEP_ENABLED;
  1328. break;
  1329. case WLAN_CIPHER_SUITE_TKIP:
  1330. pval = TKIP_ENABLED;
  1331. break;
  1332. case WLAN_CIPHER_SUITE_CCMP:
  1333. pval = AES_ENABLED;
  1334. break;
  1335. case WLAN_CIPHER_SUITE_AES_CMAC:
  1336. pval = AES_ENABLED;
  1337. break;
  1338. default:
  1339. brcmf_err("invalid cipher pairwise (%d)\n",
  1340. sme->crypto.ciphers_pairwise[0]);
  1341. return -EINVAL;
  1342. }
  1343. }
  1344. if (sme->crypto.cipher_group) {
  1345. switch (sme->crypto.cipher_group) {
  1346. case WLAN_CIPHER_SUITE_WEP40:
  1347. case WLAN_CIPHER_SUITE_WEP104:
  1348. gval = WEP_ENABLED;
  1349. break;
  1350. case WLAN_CIPHER_SUITE_TKIP:
  1351. gval = TKIP_ENABLED;
  1352. break;
  1353. case WLAN_CIPHER_SUITE_CCMP:
  1354. gval = AES_ENABLED;
  1355. break;
  1356. case WLAN_CIPHER_SUITE_AES_CMAC:
  1357. gval = AES_ENABLED;
  1358. break;
  1359. default:
  1360. brcmf_err("invalid cipher group (%d)\n",
  1361. sme->crypto.cipher_group);
  1362. return -EINVAL;
  1363. }
  1364. }
  1365. brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
  1366. /* In case of privacy, but no security and WPS then simulate */
  1367. /* setting AES. WPS-2.0 allows no security */
  1368. if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
  1369. sme->privacy)
  1370. pval = AES_ENABLED;
  1371. wsec = pval | gval;
  1372. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
  1373. if (err) {
  1374. brcmf_err("error (%d)\n", err);
  1375. return err;
  1376. }
  1377. sec = &profile->sec;
  1378. sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
  1379. sec->cipher_group = sme->crypto.cipher_group;
  1380. return err;
  1381. }
  1382. static s32
  1383. brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
  1384. {
  1385. struct brcmf_if *ifp = netdev_priv(ndev);
  1386. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  1387. s32 val;
  1388. s32 err;
  1389. const struct brcmf_tlv *rsn_ie;
  1390. const u8 *ie;
  1391. u32 ie_len;
  1392. u32 offset;
  1393. u16 rsn_cap;
  1394. u32 mfp;
  1395. u16 count;
  1396. profile->use_fwsup = BRCMF_PROFILE_FWSUP_NONE;
  1397. if (!sme->crypto.n_akm_suites)
  1398. return 0;
  1399. err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev), "wpa_auth", &val);
  1400. if (err) {
  1401. brcmf_err("could not get wpa_auth (%d)\n", err);
  1402. return err;
  1403. }
  1404. if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
  1405. switch (sme->crypto.akm_suites[0]) {
  1406. case WLAN_AKM_SUITE_8021X:
  1407. val = WPA_AUTH_UNSPECIFIED;
  1408. if (sme->want_1x)
  1409. profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X;
  1410. break;
  1411. case WLAN_AKM_SUITE_PSK:
  1412. val = WPA_AUTH_PSK;
  1413. break;
  1414. default:
  1415. brcmf_err("invalid cipher group (%d)\n",
  1416. sme->crypto.cipher_group);
  1417. return -EINVAL;
  1418. }
  1419. } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
  1420. switch (sme->crypto.akm_suites[0]) {
  1421. case WLAN_AKM_SUITE_8021X:
  1422. val = WPA2_AUTH_UNSPECIFIED;
  1423. if (sme->want_1x)
  1424. profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X;
  1425. break;
  1426. case WLAN_AKM_SUITE_8021X_SHA256:
  1427. val = WPA2_AUTH_1X_SHA256;
  1428. if (sme->want_1x)
  1429. profile->use_fwsup = BRCMF_PROFILE_FWSUP_1X;
  1430. break;
  1431. case WLAN_AKM_SUITE_PSK_SHA256:
  1432. val = WPA2_AUTH_PSK_SHA256;
  1433. break;
  1434. case WLAN_AKM_SUITE_PSK:
  1435. val = WPA2_AUTH_PSK;
  1436. break;
  1437. default:
  1438. brcmf_err("invalid cipher group (%d)\n",
  1439. sme->crypto.cipher_group);
  1440. return -EINVAL;
  1441. }
  1442. }
  1443. if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_1X)
  1444. brcmf_dbg(INFO, "using 1X offload\n");
  1445. if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
  1446. goto skip_mfp_config;
  1447. /* The MFP mode (1 or 2) needs to be determined, parse IEs. The
  1448. * IE will not be verified, just a quick search for MFP config
  1449. */
  1450. rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie, sme->ie_len,
  1451. WLAN_EID_RSN);
  1452. if (!rsn_ie)
  1453. goto skip_mfp_config;
  1454. ie = (const u8 *)rsn_ie;
  1455. ie_len = rsn_ie->len + TLV_HDR_LEN;
  1456. /* Skip unicast suite */
  1457. offset = TLV_HDR_LEN + WPA_IE_VERSION_LEN + WPA_IE_MIN_OUI_LEN;
  1458. if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len)
  1459. goto skip_mfp_config;
  1460. /* Skip multicast suite */
  1461. count = ie[offset] + (ie[offset + 1] << 8);
  1462. offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN);
  1463. if (offset + WPA_IE_SUITE_COUNT_LEN >= ie_len)
  1464. goto skip_mfp_config;
  1465. /* Skip auth key management suite(s) */
  1466. count = ie[offset] + (ie[offset + 1] << 8);
  1467. offset += WPA_IE_SUITE_COUNT_LEN + (count * WPA_IE_MIN_OUI_LEN);
  1468. if (offset + WPA_IE_SUITE_COUNT_LEN > ie_len)
  1469. goto skip_mfp_config;
  1470. /* Ready to read capabilities */
  1471. mfp = BRCMF_MFP_NONE;
  1472. rsn_cap = ie[offset] + (ie[offset + 1] << 8);
  1473. if (rsn_cap & RSN_CAP_MFPR_MASK)
  1474. mfp = BRCMF_MFP_REQUIRED;
  1475. else if (rsn_cap & RSN_CAP_MFPC_MASK)
  1476. mfp = BRCMF_MFP_CAPABLE;
  1477. brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "mfp", mfp);
  1478. skip_mfp_config:
  1479. brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
  1480. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
  1481. if (err) {
  1482. brcmf_err("could not set wpa_auth (%d)\n", err);
  1483. return err;
  1484. }
  1485. return err;
  1486. }
  1487. static s32
  1488. brcmf_set_sharedkey(struct net_device *ndev,
  1489. struct cfg80211_connect_params *sme)
  1490. {
  1491. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
  1492. struct brcmf_cfg80211_security *sec;
  1493. struct brcmf_wsec_key key;
  1494. s32 val;
  1495. s32 err = 0;
  1496. brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
  1497. if (sme->key_len == 0)
  1498. return 0;
  1499. sec = &profile->sec;
  1500. brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
  1501. sec->wpa_versions, sec->cipher_pairwise);
  1502. if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
  1503. return 0;
  1504. if (!(sec->cipher_pairwise &
  1505. (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
  1506. return 0;
  1507. memset(&key, 0, sizeof(key));
  1508. key.len = (u32) sme->key_len;
  1509. key.index = (u32) sme->key_idx;
  1510. if (key.len > sizeof(key.data)) {
  1511. brcmf_err("Too long key length (%u)\n", key.len);
  1512. return -EINVAL;
  1513. }
  1514. memcpy(key.data, sme->key, key.len);
  1515. key.flags = BRCMF_PRIMARY_KEY;
  1516. switch (sec->cipher_pairwise) {
  1517. case WLAN_CIPHER_SUITE_WEP40:
  1518. key.algo = CRYPTO_ALGO_WEP1;
  1519. break;
  1520. case WLAN_CIPHER_SUITE_WEP104:
  1521. key.algo = CRYPTO_ALGO_WEP128;
  1522. break;
  1523. default:
  1524. brcmf_err("Invalid algorithm (%d)\n",
  1525. sme->crypto.ciphers_pairwise[0]);
  1526. return -EINVAL;
  1527. }
  1528. /* Set the new key/index */
  1529. brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
  1530. key.len, key.index, key.algo);
  1531. brcmf_dbg(CONN, "key \"%s\"\n", key.data);
  1532. err = send_key_to_dongle(netdev_priv(ndev), &key);
  1533. if (err)
  1534. return err;
  1535. if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
  1536. brcmf_dbg(CONN, "set auth_type to shared key\n");
  1537. val = WL_AUTH_SHARED_KEY; /* shared key */
  1538. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
  1539. if (err)
  1540. brcmf_err("set auth failed (%d)\n", err);
  1541. }
  1542. return err;
  1543. }
  1544. static
  1545. enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
  1546. enum nl80211_auth_type type)
  1547. {
  1548. if (type == NL80211_AUTHTYPE_AUTOMATIC &&
  1549. brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
  1550. brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
  1551. type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  1552. }
  1553. return type;
  1554. }
  1555. static void brcmf_set_join_pref(struct brcmf_if *ifp,
  1556. struct cfg80211_bss_selection *bss_select)
  1557. {
  1558. struct brcmf_join_pref_params join_pref_params[2];
  1559. enum nl80211_band band;
  1560. int err, i = 0;
  1561. join_pref_params[i].len = 2;
  1562. join_pref_params[i].rssi_gain = 0;
  1563. if (bss_select->behaviour != NL80211_BSS_SELECT_ATTR_BAND_PREF)
  1564. brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_ASSOC_PREFER, WLC_BAND_AUTO);
  1565. switch (bss_select->behaviour) {
  1566. case __NL80211_BSS_SELECT_ATTR_INVALID:
  1567. brcmf_c_set_joinpref_default(ifp);
  1568. return;
  1569. case NL80211_BSS_SELECT_ATTR_BAND_PREF:
  1570. join_pref_params[i].type = BRCMF_JOIN_PREF_BAND;
  1571. band = bss_select->param.band_pref;
  1572. join_pref_params[i].band = nl80211_band_to_fwil(band);
  1573. i++;
  1574. break;
  1575. case NL80211_BSS_SELECT_ATTR_RSSI_ADJUST:
  1576. join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI_DELTA;
  1577. band = bss_select->param.adjust.band;
  1578. join_pref_params[i].band = nl80211_band_to_fwil(band);
  1579. join_pref_params[i].rssi_gain = bss_select->param.adjust.delta;
  1580. i++;
  1581. break;
  1582. case NL80211_BSS_SELECT_ATTR_RSSI:
  1583. default:
  1584. break;
  1585. }
  1586. join_pref_params[i].type = BRCMF_JOIN_PREF_RSSI;
  1587. join_pref_params[i].len = 2;
  1588. join_pref_params[i].rssi_gain = 0;
  1589. join_pref_params[i].band = 0;
  1590. err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
  1591. sizeof(join_pref_params));
  1592. if (err)
  1593. brcmf_err("Set join_pref error (%d)\n", err);
  1594. }
  1595. static s32
  1596. brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
  1597. struct cfg80211_connect_params *sme)
  1598. {
  1599. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1600. struct brcmf_if *ifp = netdev_priv(ndev);
  1601. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  1602. struct ieee80211_channel *chan = sme->channel;
  1603. struct brcmf_join_params join_params;
  1604. size_t join_params_size;
  1605. const struct brcmf_tlv *rsn_ie;
  1606. const struct brcmf_vs_tlv *wpa_ie;
  1607. const void *ie;
  1608. u32 ie_len;
  1609. struct brcmf_ext_join_params_le *ext_join_params;
  1610. u16 chanspec;
  1611. s32 err = 0;
  1612. u32 ssid_len;
  1613. brcmf_dbg(TRACE, "Enter\n");
  1614. if (!check_vif_up(ifp->vif))
  1615. return -EIO;
  1616. if (!sme->ssid) {
  1617. brcmf_err("Invalid ssid\n");
  1618. return -EOPNOTSUPP;
  1619. }
  1620. if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
  1621. /* A normal (non P2P) connection request setup. */
  1622. ie = NULL;
  1623. ie_len = 0;
  1624. /* find the WPA_IE */
  1625. wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
  1626. if (wpa_ie) {
  1627. ie = wpa_ie;
  1628. ie_len = wpa_ie->len + TLV_HDR_LEN;
  1629. } else {
  1630. /* find the RSN_IE */
  1631. rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
  1632. sme->ie_len,
  1633. WLAN_EID_RSN);
  1634. if (rsn_ie) {
  1635. ie = rsn_ie;
  1636. ie_len = rsn_ie->len + TLV_HDR_LEN;
  1637. }
  1638. }
  1639. brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
  1640. }
  1641. err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
  1642. sme->ie, sme->ie_len);
  1643. if (err)
  1644. brcmf_err("Set Assoc REQ IE Failed\n");
  1645. else
  1646. brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
  1647. set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1648. if (chan) {
  1649. cfg->channel =
  1650. ieee80211_frequency_to_channel(chan->center_freq);
  1651. chanspec = channel_to_chanspec(&cfg->d11inf, chan);
  1652. brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
  1653. cfg->channel, chan->center_freq, chanspec);
  1654. } else {
  1655. cfg->channel = 0;
  1656. chanspec = 0;
  1657. }
  1658. brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
  1659. err = brcmf_set_wpa_version(ndev, sme);
  1660. if (err) {
  1661. brcmf_err("wl_set_wpa_version failed (%d)\n", err);
  1662. goto done;
  1663. }
  1664. sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
  1665. err = brcmf_set_auth_type(ndev, sme);
  1666. if (err) {
  1667. brcmf_err("wl_set_auth_type failed (%d)\n", err);
  1668. goto done;
  1669. }
  1670. err = brcmf_set_wsec_mode(ndev, sme);
  1671. if (err) {
  1672. brcmf_err("wl_set_set_cipher failed (%d)\n", err);
  1673. goto done;
  1674. }
  1675. err = brcmf_set_key_mgmt(ndev, sme);
  1676. if (err) {
  1677. brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
  1678. goto done;
  1679. }
  1680. err = brcmf_set_sharedkey(ndev, sme);
  1681. if (err) {
  1682. brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
  1683. goto done;
  1684. }
  1685. if (sme->crypto.psk) {
  1686. if (WARN_ON(profile->use_fwsup != BRCMF_PROFILE_FWSUP_NONE)) {
  1687. err = -EINVAL;
  1688. goto done;
  1689. }
  1690. brcmf_dbg(INFO, "using PSK offload\n");
  1691. profile->use_fwsup = BRCMF_PROFILE_FWSUP_PSK;
  1692. }
  1693. if (profile->use_fwsup != BRCMF_PROFILE_FWSUP_NONE) {
  1694. /* enable firmware supplicant for this interface */
  1695. err = brcmf_fil_iovar_int_set(ifp, "sup_wpa", 1);
  1696. if (err < 0) {
  1697. brcmf_err("failed to enable fw supplicant\n");
  1698. goto done;
  1699. }
  1700. }
  1701. if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_PSK) {
  1702. err = brcmf_set_pmk(ifp, sme->crypto.psk,
  1703. BRCMF_WSEC_MAX_PSK_LEN);
  1704. if (err)
  1705. goto done;
  1706. }
  1707. /* Join with specific BSSID and cached SSID
  1708. * If SSID is zero join based on BSSID only
  1709. */
  1710. join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
  1711. offsetof(struct brcmf_assoc_params_le, chanspec_list);
  1712. if (cfg->channel)
  1713. join_params_size += sizeof(u16);
  1714. ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
  1715. if (ext_join_params == NULL) {
  1716. err = -ENOMEM;
  1717. goto done;
  1718. }
  1719. ssid_len = min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN);
  1720. ext_join_params->ssid_le.SSID_len = cpu_to_le32(ssid_len);
  1721. memcpy(&ext_join_params->ssid_le.SSID, sme->ssid, ssid_len);
  1722. if (ssid_len < IEEE80211_MAX_SSID_LEN)
  1723. brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n",
  1724. ext_join_params->ssid_le.SSID, ssid_len);
  1725. /* Set up join scan parameters */
  1726. ext_join_params->scan_le.scan_type = -1;
  1727. ext_join_params->scan_le.home_time = cpu_to_le32(-1);
  1728. if (sme->bssid)
  1729. memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
  1730. else
  1731. eth_broadcast_addr(ext_join_params->assoc_le.bssid);
  1732. if (cfg->channel) {
  1733. ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
  1734. ext_join_params->assoc_le.chanspec_list[0] =
  1735. cpu_to_le16(chanspec);
  1736. /* Increase dwell time to receive probe response or detect
  1737. * beacon from target AP at a noisy air only during connect
  1738. * command.
  1739. */
  1740. ext_join_params->scan_le.active_time =
  1741. cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
  1742. ext_join_params->scan_le.passive_time =
  1743. cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
  1744. /* To sync with presence period of VSDB GO send probe request
  1745. * more frequently. Probe request will be stopped when it gets
  1746. * probe response from target AP/GO.
  1747. */
  1748. ext_join_params->scan_le.nprobes =
  1749. cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
  1750. BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
  1751. } else {
  1752. ext_join_params->scan_le.active_time = cpu_to_le32(-1);
  1753. ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
  1754. ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
  1755. }
  1756. brcmf_set_join_pref(ifp, &sme->bss_select);
  1757. err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
  1758. join_params_size);
  1759. kfree(ext_join_params);
  1760. if (!err)
  1761. /* This is it. join command worked, we are done */
  1762. goto done;
  1763. /* join command failed, fallback to set ssid */
  1764. memset(&join_params, 0, sizeof(join_params));
  1765. join_params_size = sizeof(join_params.ssid_le);
  1766. memcpy(&join_params.ssid_le.SSID, sme->ssid, ssid_len);
  1767. join_params.ssid_le.SSID_len = cpu_to_le32(ssid_len);
  1768. if (sme->bssid)
  1769. memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
  1770. else
  1771. eth_broadcast_addr(join_params.params_le.bssid);
  1772. if (cfg->channel) {
  1773. join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
  1774. join_params.params_le.chanspec_num = cpu_to_le32(1);
  1775. join_params_size += sizeof(join_params.params_le);
  1776. }
  1777. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
  1778. &join_params, join_params_size);
  1779. if (err)
  1780. brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
  1781. done:
  1782. if (err)
  1783. clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1784. brcmf_dbg(TRACE, "Exit\n");
  1785. return err;
  1786. }
  1787. static s32
  1788. brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
  1789. u16 reason_code)
  1790. {
  1791. struct brcmf_if *ifp = netdev_priv(ndev);
  1792. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  1793. struct brcmf_scb_val_le scbval;
  1794. s32 err = 0;
  1795. brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
  1796. if (!check_vif_up(ifp->vif))
  1797. return -EIO;
  1798. clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
  1799. clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1800. cfg80211_disconnected(ndev, reason_code, NULL, 0, true, GFP_KERNEL);
  1801. memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
  1802. scbval.val = cpu_to_le32(reason_code);
  1803. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
  1804. &scbval, sizeof(scbval));
  1805. if (err)
  1806. brcmf_err("error (%d)\n", err);
  1807. brcmf_dbg(TRACE, "Exit\n");
  1808. return err;
  1809. }
  1810. static s32
  1811. brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
  1812. enum nl80211_tx_power_setting type, s32 mbm)
  1813. {
  1814. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1815. struct net_device *ndev = cfg_to_ndev(cfg);
  1816. struct brcmf_if *ifp = netdev_priv(ndev);
  1817. s32 err;
  1818. s32 disable;
  1819. u32 qdbm = 127;
  1820. brcmf_dbg(TRACE, "Enter %d %d\n", type, mbm);
  1821. if (!check_vif_up(ifp->vif))
  1822. return -EIO;
  1823. switch (type) {
  1824. case NL80211_TX_POWER_AUTOMATIC:
  1825. break;
  1826. case NL80211_TX_POWER_LIMITED:
  1827. case NL80211_TX_POWER_FIXED:
  1828. if (mbm < 0) {
  1829. brcmf_err("TX_POWER_FIXED - dbm is negative\n");
  1830. err = -EINVAL;
  1831. goto done;
  1832. }
  1833. qdbm = MBM_TO_DBM(4 * mbm);
  1834. if (qdbm > 127)
  1835. qdbm = 127;
  1836. qdbm |= WL_TXPWR_OVERRIDE;
  1837. break;
  1838. default:
  1839. brcmf_err("Unsupported type %d\n", type);
  1840. err = -EINVAL;
  1841. goto done;
  1842. }
  1843. /* Make sure radio is off or on as far as software is concerned */
  1844. disable = WL_RADIO_SW_DISABLE << 16;
  1845. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
  1846. if (err)
  1847. brcmf_err("WLC_SET_RADIO error (%d)\n", err);
  1848. err = brcmf_fil_iovar_int_set(ifp, "qtxpower", qdbm);
  1849. if (err)
  1850. brcmf_err("qtxpower error (%d)\n", err);
  1851. done:
  1852. brcmf_dbg(TRACE, "Exit %d (qdbm)\n", qdbm & ~WL_TXPWR_OVERRIDE);
  1853. return err;
  1854. }
  1855. static s32
  1856. brcmf_cfg80211_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
  1857. s32 *dbm)
  1858. {
  1859. struct brcmf_cfg80211_vif *vif = wdev_to_vif(wdev);
  1860. s32 qdbm = 0;
  1861. s32 err;
  1862. brcmf_dbg(TRACE, "Enter\n");
  1863. if (!check_vif_up(vif))
  1864. return -EIO;
  1865. err = brcmf_fil_iovar_int_get(vif->ifp, "qtxpower", &qdbm);
  1866. if (err) {
  1867. brcmf_err("error (%d)\n", err);
  1868. goto done;
  1869. }
  1870. *dbm = (qdbm & ~WL_TXPWR_OVERRIDE) / 4;
  1871. done:
  1872. brcmf_dbg(TRACE, "Exit (0x%x %d)\n", qdbm, *dbm);
  1873. return err;
  1874. }
  1875. static s32
  1876. brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
  1877. u8 key_idx, bool unicast, bool multicast)
  1878. {
  1879. struct brcmf_if *ifp = netdev_priv(ndev);
  1880. u32 index;
  1881. u32 wsec;
  1882. s32 err = 0;
  1883. brcmf_dbg(TRACE, "Enter\n");
  1884. brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  1885. if (!check_vif_up(ifp->vif))
  1886. return -EIO;
  1887. err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
  1888. if (err) {
  1889. brcmf_err("WLC_GET_WSEC error (%d)\n", err);
  1890. goto done;
  1891. }
  1892. if (wsec & WEP_ENABLED) {
  1893. /* Just select a new current key */
  1894. index = key_idx;
  1895. err = brcmf_fil_cmd_int_set(ifp,
  1896. BRCMF_C_SET_KEY_PRIMARY, index);
  1897. if (err)
  1898. brcmf_err("error (%d)\n", err);
  1899. }
  1900. done:
  1901. brcmf_dbg(TRACE, "Exit\n");
  1902. return err;
  1903. }
  1904. static s32
  1905. brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  1906. u8 key_idx, bool pairwise, const u8 *mac_addr)
  1907. {
  1908. struct brcmf_if *ifp = netdev_priv(ndev);
  1909. struct brcmf_wsec_key *key;
  1910. s32 err;
  1911. brcmf_dbg(TRACE, "Enter\n");
  1912. brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  1913. if (!check_vif_up(ifp->vif))
  1914. return -EIO;
  1915. if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
  1916. /* we ignore this key index in this case */
  1917. return -EINVAL;
  1918. }
  1919. key = &ifp->vif->profile.key[key_idx];
  1920. if (key->algo == CRYPTO_ALGO_OFF) {
  1921. brcmf_dbg(CONN, "Ignore clearing of (never configured) key\n");
  1922. return -EINVAL;
  1923. }
  1924. memset(key, 0, sizeof(*key));
  1925. key->index = (u32)key_idx;
  1926. key->flags = BRCMF_PRIMARY_KEY;
  1927. /* Clear the key/index */
  1928. err = send_key_to_dongle(ifp, key);
  1929. brcmf_dbg(TRACE, "Exit\n");
  1930. return err;
  1931. }
  1932. static s32
  1933. brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
  1934. u8 key_idx, bool pairwise, const u8 *mac_addr,
  1935. struct key_params *params)
  1936. {
  1937. struct brcmf_if *ifp = netdev_priv(ndev);
  1938. struct brcmf_wsec_key *key;
  1939. s32 val;
  1940. s32 wsec;
  1941. s32 err;
  1942. u8 keybuf[8];
  1943. bool ext_key;
  1944. brcmf_dbg(TRACE, "Enter\n");
  1945. brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  1946. if (!check_vif_up(ifp->vif))
  1947. return -EIO;
  1948. if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
  1949. /* we ignore this key index in this case */
  1950. brcmf_err("invalid key index (%d)\n", key_idx);
  1951. return -EINVAL;
  1952. }
  1953. if (params->key_len == 0)
  1954. return brcmf_cfg80211_del_key(wiphy, ndev, key_idx, pairwise,
  1955. mac_addr);
  1956. if (params->key_len > sizeof(key->data)) {
  1957. brcmf_err("Too long key length (%u)\n", params->key_len);
  1958. return -EINVAL;
  1959. }
  1960. ext_key = false;
  1961. if (mac_addr && (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
  1962. (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
  1963. brcmf_dbg(TRACE, "Ext key, mac %pM", mac_addr);
  1964. ext_key = true;
  1965. }
  1966. key = &ifp->vif->profile.key[key_idx];
  1967. memset(key, 0, sizeof(*key));
  1968. if ((ext_key) && (!is_multicast_ether_addr(mac_addr)))
  1969. memcpy((char *)&key->ea, (void *)mac_addr, ETH_ALEN);
  1970. key->len = params->key_len;
  1971. key->index = key_idx;
  1972. memcpy(key->data, params->key, key->len);
  1973. if (!ext_key)
  1974. key->flags = BRCMF_PRIMARY_KEY;
  1975. switch (params->cipher) {
  1976. case WLAN_CIPHER_SUITE_WEP40:
  1977. key->algo = CRYPTO_ALGO_WEP1;
  1978. val = WEP_ENABLED;
  1979. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
  1980. break;
  1981. case WLAN_CIPHER_SUITE_WEP104:
  1982. key->algo = CRYPTO_ALGO_WEP128;
  1983. val = WEP_ENABLED;
  1984. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
  1985. break;
  1986. case WLAN_CIPHER_SUITE_TKIP:
  1987. if (!brcmf_is_apmode(ifp->vif)) {
  1988. brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
  1989. memcpy(keybuf, &key->data[24], sizeof(keybuf));
  1990. memcpy(&key->data[24], &key->data[16], sizeof(keybuf));
  1991. memcpy(&key->data[16], keybuf, sizeof(keybuf));
  1992. }
  1993. key->algo = CRYPTO_ALGO_TKIP;
  1994. val = TKIP_ENABLED;
  1995. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
  1996. break;
  1997. case WLAN_CIPHER_SUITE_AES_CMAC:
  1998. key->algo = CRYPTO_ALGO_AES_CCM;
  1999. val = AES_ENABLED;
  2000. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
  2001. break;
  2002. case WLAN_CIPHER_SUITE_CCMP:
  2003. key->algo = CRYPTO_ALGO_AES_CCM;
  2004. val = AES_ENABLED;
  2005. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
  2006. break;
  2007. default:
  2008. brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
  2009. err = -EINVAL;
  2010. goto done;
  2011. }
  2012. err = send_key_to_dongle(ifp, key);
  2013. if (ext_key || err)
  2014. goto done;
  2015. err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
  2016. if (err) {
  2017. brcmf_err("get wsec error (%d)\n", err);
  2018. goto done;
  2019. }
  2020. wsec |= val;
  2021. err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
  2022. if (err) {
  2023. brcmf_err("set wsec error (%d)\n", err);
  2024. goto done;
  2025. }
  2026. done:
  2027. brcmf_dbg(TRACE, "Exit\n");
  2028. return err;
  2029. }
  2030. static s32
  2031. brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, u8 key_idx,
  2032. bool pairwise, const u8 *mac_addr, void *cookie,
  2033. void (*callback)(void *cookie,
  2034. struct key_params *params))
  2035. {
  2036. struct key_params params;
  2037. struct brcmf_if *ifp = netdev_priv(ndev);
  2038. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  2039. struct brcmf_cfg80211_security *sec;
  2040. s32 wsec;
  2041. s32 err = 0;
  2042. brcmf_dbg(TRACE, "Enter\n");
  2043. brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  2044. if (!check_vif_up(ifp->vif))
  2045. return -EIO;
  2046. memset(&params, 0, sizeof(params));
  2047. err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
  2048. if (err) {
  2049. brcmf_err("WLC_GET_WSEC error (%d)\n", err);
  2050. /* Ignore this error, may happen during DISASSOC */
  2051. err = -EAGAIN;
  2052. goto done;
  2053. }
  2054. if (wsec & WEP_ENABLED) {
  2055. sec = &profile->sec;
  2056. if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
  2057. params.cipher = WLAN_CIPHER_SUITE_WEP40;
  2058. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
  2059. } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
  2060. params.cipher = WLAN_CIPHER_SUITE_WEP104;
  2061. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
  2062. }
  2063. } else if (wsec & TKIP_ENABLED) {
  2064. params.cipher = WLAN_CIPHER_SUITE_TKIP;
  2065. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
  2066. } else if (wsec & AES_ENABLED) {
  2067. params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
  2068. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
  2069. } else {
  2070. brcmf_err("Invalid algo (0x%x)\n", wsec);
  2071. err = -EINVAL;
  2072. goto done;
  2073. }
  2074. callback(cookie, &params);
  2075. done:
  2076. brcmf_dbg(TRACE, "Exit\n");
  2077. return err;
  2078. }
  2079. static s32
  2080. brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
  2081. struct net_device *ndev, u8 key_idx)
  2082. {
  2083. struct brcmf_if *ifp = netdev_priv(ndev);
  2084. brcmf_dbg(TRACE, "Enter key_idx %d\n", key_idx);
  2085. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
  2086. return 0;
  2087. brcmf_dbg(INFO, "Not supported\n");
  2088. return -EOPNOTSUPP;
  2089. }
  2090. static void
  2091. brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp)
  2092. {
  2093. s32 err;
  2094. u8 key_idx;
  2095. struct brcmf_wsec_key *key;
  2096. s32 wsec;
  2097. for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) {
  2098. key = &ifp->vif->profile.key[key_idx];
  2099. if ((key->algo == CRYPTO_ALGO_WEP1) ||
  2100. (key->algo == CRYPTO_ALGO_WEP128))
  2101. break;
  2102. }
  2103. if (key_idx == BRCMF_MAX_DEFAULT_KEYS)
  2104. return;
  2105. err = send_key_to_dongle(ifp, key);
  2106. if (err) {
  2107. brcmf_err("Setting WEP key failed (%d)\n", err);
  2108. return;
  2109. }
  2110. err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
  2111. if (err) {
  2112. brcmf_err("get wsec error (%d)\n", err);
  2113. return;
  2114. }
  2115. wsec |= WEP_ENABLED;
  2116. err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
  2117. if (err)
  2118. brcmf_err("set wsec error (%d)\n", err);
  2119. }
  2120. static void brcmf_convert_sta_flags(u32 fw_sta_flags, struct station_info *si)
  2121. {
  2122. struct nl80211_sta_flag_update *sfu;
  2123. brcmf_dbg(TRACE, "flags %08x\n", fw_sta_flags);
  2124. si->filled |= BIT_ULL(NL80211_STA_INFO_STA_FLAGS);
  2125. sfu = &si->sta_flags;
  2126. sfu->mask = BIT(NL80211_STA_FLAG_WME) |
  2127. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  2128. BIT(NL80211_STA_FLAG_ASSOCIATED) |
  2129. BIT(NL80211_STA_FLAG_AUTHORIZED);
  2130. if (fw_sta_flags & BRCMF_STA_WME)
  2131. sfu->set |= BIT(NL80211_STA_FLAG_WME);
  2132. if (fw_sta_flags & BRCMF_STA_AUTHE)
  2133. sfu->set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  2134. if (fw_sta_flags & BRCMF_STA_ASSOC)
  2135. sfu->set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  2136. if (fw_sta_flags & BRCMF_STA_AUTHO)
  2137. sfu->set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  2138. }
  2139. static void brcmf_fill_bss_param(struct brcmf_if *ifp, struct station_info *si)
  2140. {
  2141. struct {
  2142. __le32 len;
  2143. struct brcmf_bss_info_le bss_le;
  2144. } *buf;
  2145. u16 capability;
  2146. int err;
  2147. buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
  2148. if (!buf)
  2149. return;
  2150. buf->len = cpu_to_le32(WL_BSS_INFO_MAX);
  2151. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, buf,
  2152. WL_BSS_INFO_MAX);
  2153. if (err) {
  2154. brcmf_err("Failed to get bss info (%d)\n", err);
  2155. goto out_kfree;
  2156. }
  2157. si->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM);
  2158. si->bss_param.beacon_interval = le16_to_cpu(buf->bss_le.beacon_period);
  2159. si->bss_param.dtim_period = buf->bss_le.dtim_period;
  2160. capability = le16_to_cpu(buf->bss_le.capability);
  2161. if (capability & IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT)
  2162. si->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  2163. if (capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  2164. si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  2165. if (capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  2166. si->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  2167. out_kfree:
  2168. kfree(buf);
  2169. }
  2170. static s32
  2171. brcmf_cfg80211_get_station_ibss(struct brcmf_if *ifp,
  2172. struct station_info *sinfo)
  2173. {
  2174. struct brcmf_scb_val_le scbval;
  2175. struct brcmf_pktcnt_le pktcnt;
  2176. s32 err;
  2177. u32 rate;
  2178. u32 rssi;
  2179. /* Get the current tx rate */
  2180. err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
  2181. if (err < 0) {
  2182. brcmf_err("BRCMF_C_GET_RATE error (%d)\n", err);
  2183. return err;
  2184. }
  2185. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
  2186. sinfo->txrate.legacy = rate * 5;
  2187. memset(&scbval, 0, sizeof(scbval));
  2188. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI, &scbval,
  2189. sizeof(scbval));
  2190. if (err) {
  2191. brcmf_err("BRCMF_C_GET_RSSI error (%d)\n", err);
  2192. return err;
  2193. }
  2194. rssi = le32_to_cpu(scbval.val);
  2195. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
  2196. sinfo->signal = rssi;
  2197. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_GET_PKTCNTS, &pktcnt,
  2198. sizeof(pktcnt));
  2199. if (err) {
  2200. brcmf_err("BRCMF_C_GET_GET_PKTCNTS error (%d)\n", err);
  2201. return err;
  2202. }
  2203. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS) |
  2204. BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC) |
  2205. BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
  2206. BIT_ULL(NL80211_STA_INFO_TX_FAILED);
  2207. sinfo->rx_packets = le32_to_cpu(pktcnt.rx_good_pkt);
  2208. sinfo->rx_dropped_misc = le32_to_cpu(pktcnt.rx_bad_pkt);
  2209. sinfo->tx_packets = le32_to_cpu(pktcnt.tx_good_pkt);
  2210. sinfo->tx_failed = le32_to_cpu(pktcnt.tx_bad_pkt);
  2211. return 0;
  2212. }
  2213. static s32
  2214. brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
  2215. const u8 *mac, struct station_info *sinfo)
  2216. {
  2217. struct brcmf_if *ifp = netdev_priv(ndev);
  2218. struct brcmf_scb_val_le scb_val;
  2219. s32 err = 0;
  2220. struct brcmf_sta_info_le sta_info_le;
  2221. u32 sta_flags;
  2222. u32 is_tdls_peer;
  2223. s32 total_rssi;
  2224. s32 count_rssi;
  2225. int rssi;
  2226. u32 i;
  2227. brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
  2228. if (!check_vif_up(ifp->vif))
  2229. return -EIO;
  2230. if (brcmf_is_ibssmode(ifp->vif))
  2231. return brcmf_cfg80211_get_station_ibss(ifp, sinfo);
  2232. memset(&sta_info_le, 0, sizeof(sta_info_le));
  2233. memcpy(&sta_info_le, mac, ETH_ALEN);
  2234. err = brcmf_fil_iovar_data_get(ifp, "tdls_sta_info",
  2235. &sta_info_le,
  2236. sizeof(sta_info_le));
  2237. is_tdls_peer = !err;
  2238. if (err) {
  2239. err = brcmf_fil_iovar_data_get(ifp, "sta_info",
  2240. &sta_info_le,
  2241. sizeof(sta_info_le));
  2242. if (err < 0) {
  2243. brcmf_err("GET STA INFO failed, %d\n", err);
  2244. goto done;
  2245. }
  2246. }
  2247. brcmf_dbg(TRACE, "version %d\n", le16_to_cpu(sta_info_le.ver));
  2248. sinfo->filled = BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME);
  2249. sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
  2250. sta_flags = le32_to_cpu(sta_info_le.flags);
  2251. brcmf_convert_sta_flags(sta_flags, sinfo);
  2252. sinfo->sta_flags.mask |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  2253. if (is_tdls_peer)
  2254. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  2255. else
  2256. sinfo->sta_flags.set &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  2257. if (sta_flags & BRCMF_STA_ASSOC) {
  2258. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME);
  2259. sinfo->connected_time = le32_to_cpu(sta_info_le.in);
  2260. brcmf_fill_bss_param(ifp, sinfo);
  2261. }
  2262. if (sta_flags & BRCMF_STA_SCBSTATS) {
  2263. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
  2264. sinfo->tx_failed = le32_to_cpu(sta_info_le.tx_failures);
  2265. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
  2266. sinfo->tx_packets = le32_to_cpu(sta_info_le.tx_pkts);
  2267. sinfo->tx_packets += le32_to_cpu(sta_info_le.tx_mcast_pkts);
  2268. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
  2269. sinfo->rx_packets = le32_to_cpu(sta_info_le.rx_ucast_pkts);
  2270. sinfo->rx_packets += le32_to_cpu(sta_info_le.rx_mcast_pkts);
  2271. if (sinfo->tx_packets) {
  2272. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
  2273. sinfo->txrate.legacy =
  2274. le32_to_cpu(sta_info_le.tx_rate) / 100;
  2275. }
  2276. if (sinfo->rx_packets) {
  2277. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
  2278. sinfo->rxrate.legacy =
  2279. le32_to_cpu(sta_info_le.rx_rate) / 100;
  2280. }
  2281. if (le16_to_cpu(sta_info_le.ver) >= 4) {
  2282. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES);
  2283. sinfo->tx_bytes = le64_to_cpu(sta_info_le.tx_tot_bytes);
  2284. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES);
  2285. sinfo->rx_bytes = le64_to_cpu(sta_info_le.rx_tot_bytes);
  2286. }
  2287. total_rssi = 0;
  2288. count_rssi = 0;
  2289. for (i = 0; i < BRCMF_ANT_MAX; i++) {
  2290. if (sta_info_le.rssi[i]) {
  2291. sinfo->chain_signal_avg[count_rssi] =
  2292. sta_info_le.rssi[i];
  2293. sinfo->chain_signal[count_rssi] =
  2294. sta_info_le.rssi[i];
  2295. total_rssi += sta_info_le.rssi[i];
  2296. count_rssi++;
  2297. }
  2298. }
  2299. if (count_rssi) {
  2300. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
  2301. sinfo->chains = count_rssi;
  2302. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
  2303. total_rssi /= count_rssi;
  2304. sinfo->signal = total_rssi;
  2305. } else if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
  2306. &ifp->vif->sme_state)) {
  2307. memset(&scb_val, 0, sizeof(scb_val));
  2308. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
  2309. &scb_val, sizeof(scb_val));
  2310. if (err) {
  2311. brcmf_err("Could not get rssi (%d)\n", err);
  2312. goto done;
  2313. } else {
  2314. rssi = le32_to_cpu(scb_val.val);
  2315. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
  2316. sinfo->signal = rssi;
  2317. brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
  2318. }
  2319. }
  2320. }
  2321. done:
  2322. brcmf_dbg(TRACE, "Exit\n");
  2323. return err;
  2324. }
  2325. static int
  2326. brcmf_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *ndev,
  2327. int idx, u8 *mac, struct station_info *sinfo)
  2328. {
  2329. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2330. struct brcmf_if *ifp = netdev_priv(ndev);
  2331. s32 err;
  2332. brcmf_dbg(TRACE, "Enter, idx %d\n", idx);
  2333. if (idx == 0) {
  2334. cfg->assoclist.count = cpu_to_le32(BRCMF_MAX_ASSOCLIST);
  2335. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_ASSOCLIST,
  2336. &cfg->assoclist,
  2337. sizeof(cfg->assoclist));
  2338. if (err) {
  2339. brcmf_err("BRCMF_C_GET_ASSOCLIST unsupported, err=%d\n",
  2340. err);
  2341. cfg->assoclist.count = 0;
  2342. return -EOPNOTSUPP;
  2343. }
  2344. }
  2345. if (idx < le32_to_cpu(cfg->assoclist.count)) {
  2346. memcpy(mac, cfg->assoclist.mac[idx], ETH_ALEN);
  2347. return brcmf_cfg80211_get_station(wiphy, ndev, mac, sinfo);
  2348. }
  2349. return -ENOENT;
  2350. }
  2351. static s32
  2352. brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
  2353. bool enabled, s32 timeout)
  2354. {
  2355. s32 pm;
  2356. s32 err = 0;
  2357. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2358. struct brcmf_if *ifp = netdev_priv(ndev);
  2359. brcmf_dbg(TRACE, "Enter\n");
  2360. /*
  2361. * Powersave enable/disable request is coming from the
  2362. * cfg80211 even before the interface is up. In that
  2363. * scenario, driver will be storing the power save
  2364. * preference in cfg struct to apply this to
  2365. * FW later while initializing the dongle
  2366. */
  2367. cfg->pwr_save = enabled;
  2368. if (!check_vif_up(ifp->vif)) {
  2369. brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
  2370. goto done;
  2371. }
  2372. pm = enabled ? PM_FAST : PM_OFF;
  2373. /* Do not enable the power save after assoc if it is a p2p interface */
  2374. if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
  2375. brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
  2376. pm = PM_OFF;
  2377. }
  2378. brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
  2379. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
  2380. if (err) {
  2381. if (err == -ENODEV)
  2382. brcmf_err("net_device is not ready yet\n");
  2383. else
  2384. brcmf_err("error (%d)\n", err);
  2385. }
  2386. done:
  2387. brcmf_dbg(TRACE, "Exit\n");
  2388. return err;
  2389. }
  2390. static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
  2391. struct brcmf_bss_info_le *bi)
  2392. {
  2393. struct wiphy *wiphy = cfg_to_wiphy(cfg);
  2394. struct cfg80211_bss *bss;
  2395. enum nl80211_band band;
  2396. struct brcmu_chan ch;
  2397. u16 channel;
  2398. u32 freq;
  2399. u16 notify_capability;
  2400. u16 notify_interval;
  2401. u8 *notify_ie;
  2402. size_t notify_ielen;
  2403. struct cfg80211_inform_bss bss_data = {};
  2404. if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
  2405. brcmf_err("Bss info is larger than buffer. Discarding\n");
  2406. return 0;
  2407. }
  2408. if (!bi->ctl_ch) {
  2409. ch.chspec = le16_to_cpu(bi->chanspec);
  2410. cfg->d11inf.decchspec(&ch);
  2411. bi->ctl_ch = ch.control_ch_num;
  2412. }
  2413. channel = bi->ctl_ch;
  2414. if (channel <= CH_MAX_2G_CHANNEL)
  2415. band = NL80211_BAND_2GHZ;
  2416. else
  2417. band = NL80211_BAND_5GHZ;
  2418. freq = ieee80211_channel_to_frequency(channel, band);
  2419. bss_data.chan = ieee80211_get_channel(wiphy, freq);
  2420. bss_data.scan_width = NL80211_BSS_CHAN_WIDTH_20;
  2421. bss_data.boottime_ns = ktime_to_ns(ktime_get_boottime());
  2422. notify_capability = le16_to_cpu(bi->capability);
  2423. notify_interval = le16_to_cpu(bi->beacon_period);
  2424. notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
  2425. notify_ielen = le32_to_cpu(bi->ie_length);
  2426. bss_data.signal = (s16)le16_to_cpu(bi->RSSI) * 100;
  2427. brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
  2428. brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
  2429. brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
  2430. brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
  2431. brcmf_dbg(CONN, "Signal: %d\n", bss_data.signal);
  2432. bss = cfg80211_inform_bss_data(wiphy, &bss_data,
  2433. CFG80211_BSS_FTYPE_UNKNOWN,
  2434. (const u8 *)bi->BSSID,
  2435. 0, notify_capability,
  2436. notify_interval, notify_ie,
  2437. notify_ielen, GFP_KERNEL);
  2438. if (!bss)
  2439. return -ENOMEM;
  2440. cfg80211_put_bss(wiphy, bss);
  2441. return 0;
  2442. }
  2443. static struct brcmf_bss_info_le *
  2444. next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
  2445. {
  2446. if (bss == NULL)
  2447. return list->bss_info_le;
  2448. return (struct brcmf_bss_info_le *)((unsigned long)bss +
  2449. le32_to_cpu(bss->length));
  2450. }
  2451. static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
  2452. {
  2453. struct brcmf_scan_results *bss_list;
  2454. struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
  2455. s32 err = 0;
  2456. int i;
  2457. bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
  2458. if (bss_list->count != 0 &&
  2459. bss_list->version != BRCMF_BSS_INFO_VERSION) {
  2460. brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
  2461. bss_list->version);
  2462. return -EOPNOTSUPP;
  2463. }
  2464. brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
  2465. for (i = 0; i < bss_list->count; i++) {
  2466. bi = next_bss_le(bss_list, bi);
  2467. err = brcmf_inform_single_bss(cfg, bi);
  2468. if (err)
  2469. break;
  2470. }
  2471. return err;
  2472. }
  2473. static s32 brcmf_inform_ibss(struct brcmf_cfg80211_info *cfg,
  2474. struct net_device *ndev, const u8 *bssid)
  2475. {
  2476. struct wiphy *wiphy = cfg_to_wiphy(cfg);
  2477. struct ieee80211_channel *notify_channel;
  2478. struct brcmf_bss_info_le *bi = NULL;
  2479. struct ieee80211_supported_band *band;
  2480. struct cfg80211_bss *bss;
  2481. struct brcmu_chan ch;
  2482. u8 *buf = NULL;
  2483. s32 err = 0;
  2484. u32 freq;
  2485. u16 notify_capability;
  2486. u16 notify_interval;
  2487. u8 *notify_ie;
  2488. size_t notify_ielen;
  2489. s32 notify_signal;
  2490. brcmf_dbg(TRACE, "Enter\n");
  2491. buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
  2492. if (buf == NULL) {
  2493. err = -ENOMEM;
  2494. goto CleanUp;
  2495. }
  2496. *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
  2497. err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
  2498. buf, WL_BSS_INFO_MAX);
  2499. if (err) {
  2500. brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
  2501. goto CleanUp;
  2502. }
  2503. bi = (struct brcmf_bss_info_le *)(buf + 4);
  2504. ch.chspec = le16_to_cpu(bi->chanspec);
  2505. cfg->d11inf.decchspec(&ch);
  2506. if (ch.band == BRCMU_CHAN_BAND_2G)
  2507. band = wiphy->bands[NL80211_BAND_2GHZ];
  2508. else
  2509. band = wiphy->bands[NL80211_BAND_5GHZ];
  2510. freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band);
  2511. cfg->channel = freq;
  2512. notify_channel = ieee80211_get_channel(wiphy, freq);
  2513. notify_capability = le16_to_cpu(bi->capability);
  2514. notify_interval = le16_to_cpu(bi->beacon_period);
  2515. notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
  2516. notify_ielen = le32_to_cpu(bi->ie_length);
  2517. notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
  2518. brcmf_dbg(CONN, "channel: %d(%d)\n", ch.control_ch_num, freq);
  2519. brcmf_dbg(CONN, "capability: %X\n", notify_capability);
  2520. brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
  2521. brcmf_dbg(CONN, "signal: %d\n", notify_signal);
  2522. bss = cfg80211_inform_bss(wiphy, notify_channel,
  2523. CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
  2524. notify_capability, notify_interval,
  2525. notify_ie, notify_ielen, notify_signal,
  2526. GFP_KERNEL);
  2527. if (!bss) {
  2528. err = -ENOMEM;
  2529. goto CleanUp;
  2530. }
  2531. cfg80211_put_bss(wiphy, bss);
  2532. CleanUp:
  2533. kfree(buf);
  2534. brcmf_dbg(TRACE, "Exit\n");
  2535. return err;
  2536. }
  2537. static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
  2538. struct brcmf_if *ifp)
  2539. {
  2540. struct brcmf_bss_info_le *bi;
  2541. const struct brcmf_tlv *tim;
  2542. u16 beacon_interval;
  2543. u8 dtim_period;
  2544. size_t ie_len;
  2545. u8 *ie;
  2546. s32 err = 0;
  2547. brcmf_dbg(TRACE, "Enter\n");
  2548. if (brcmf_is_ibssmode(ifp->vif))
  2549. return err;
  2550. *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
  2551. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
  2552. cfg->extra_buf, WL_EXTRA_BUF_MAX);
  2553. if (err) {
  2554. brcmf_err("Could not get bss info %d\n", err);
  2555. goto update_bss_info_out;
  2556. }
  2557. bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
  2558. err = brcmf_inform_single_bss(cfg, bi);
  2559. if (err)
  2560. goto update_bss_info_out;
  2561. ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
  2562. ie_len = le32_to_cpu(bi->ie_length);
  2563. beacon_interval = le16_to_cpu(bi->beacon_period);
  2564. tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
  2565. if (tim)
  2566. dtim_period = tim->data[1];
  2567. else {
  2568. /*
  2569. * active scan was done so we could not get dtim
  2570. * information out of probe response.
  2571. * so we speficially query dtim information to dongle.
  2572. */
  2573. u32 var;
  2574. err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
  2575. if (err) {
  2576. brcmf_err("wl dtim_assoc failed (%d)\n", err);
  2577. goto update_bss_info_out;
  2578. }
  2579. dtim_period = (u8)var;
  2580. }
  2581. update_bss_info_out:
  2582. brcmf_dbg(TRACE, "Exit");
  2583. return err;
  2584. }
  2585. void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
  2586. {
  2587. struct escan_info *escan = &cfg->escan_info;
  2588. set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
  2589. if (cfg->int_escan_map || cfg->scan_request) {
  2590. escan->escan_state = WL_ESCAN_STATE_IDLE;
  2591. brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
  2592. }
  2593. clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  2594. clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
  2595. }
  2596. static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
  2597. {
  2598. struct brcmf_cfg80211_info *cfg =
  2599. container_of(work, struct brcmf_cfg80211_info,
  2600. escan_timeout_work);
  2601. brcmf_inform_bss(cfg);
  2602. brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
  2603. }
  2604. static void brcmf_escan_timeout(struct timer_list *t)
  2605. {
  2606. struct brcmf_cfg80211_info *cfg =
  2607. from_timer(cfg, t, escan_timeout);
  2608. if (cfg->int_escan_map || cfg->scan_request) {
  2609. brcmf_err("timer expired\n");
  2610. schedule_work(&cfg->escan_timeout_work);
  2611. }
  2612. }
  2613. static s32
  2614. brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
  2615. struct brcmf_bss_info_le *bss,
  2616. struct brcmf_bss_info_le *bss_info_le)
  2617. {
  2618. struct brcmu_chan ch_bss, ch_bss_info_le;
  2619. ch_bss.chspec = le16_to_cpu(bss->chanspec);
  2620. cfg->d11inf.decchspec(&ch_bss);
  2621. ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
  2622. cfg->d11inf.decchspec(&ch_bss_info_le);
  2623. if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
  2624. ch_bss.band == ch_bss_info_le.band &&
  2625. bss_info_le->SSID_len == bss->SSID_len &&
  2626. !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
  2627. if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
  2628. (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
  2629. s16 bss_rssi = le16_to_cpu(bss->RSSI);
  2630. s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
  2631. /* preserve max RSSI if the measurements are
  2632. * both on-channel or both off-channel
  2633. */
  2634. if (bss_info_rssi > bss_rssi)
  2635. bss->RSSI = bss_info_le->RSSI;
  2636. } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
  2637. (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
  2638. /* preserve the on-channel rssi measurement
  2639. * if the new measurement is off channel
  2640. */
  2641. bss->RSSI = bss_info_le->RSSI;
  2642. bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
  2643. }
  2644. return 1;
  2645. }
  2646. return 0;
  2647. }
  2648. static s32
  2649. brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
  2650. const struct brcmf_event_msg *e, void *data)
  2651. {
  2652. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  2653. s32 status;
  2654. struct brcmf_escan_result_le *escan_result_le;
  2655. u32 escan_buflen;
  2656. struct brcmf_bss_info_le *bss_info_le;
  2657. struct brcmf_bss_info_le *bss = NULL;
  2658. u32 bi_length;
  2659. struct brcmf_scan_results *list;
  2660. u32 i;
  2661. bool aborted;
  2662. status = e->status;
  2663. if (status == BRCMF_E_STATUS_ABORT)
  2664. goto exit;
  2665. if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
  2666. brcmf_err("scan not ready, bsscfgidx=%d\n", ifp->bsscfgidx);
  2667. return -EPERM;
  2668. }
  2669. if (status == BRCMF_E_STATUS_PARTIAL) {
  2670. brcmf_dbg(SCAN, "ESCAN Partial result\n");
  2671. if (e->datalen < sizeof(*escan_result_le)) {
  2672. brcmf_err("invalid event data length\n");
  2673. goto exit;
  2674. }
  2675. escan_result_le = (struct brcmf_escan_result_le *) data;
  2676. if (!escan_result_le) {
  2677. brcmf_err("Invalid escan result (NULL pointer)\n");
  2678. goto exit;
  2679. }
  2680. escan_buflen = le32_to_cpu(escan_result_le->buflen);
  2681. if (escan_buflen > BRCMF_ESCAN_BUF_SIZE ||
  2682. escan_buflen > e->datalen ||
  2683. escan_buflen < sizeof(*escan_result_le)) {
  2684. brcmf_err("Invalid escan buffer length: %d\n",
  2685. escan_buflen);
  2686. goto exit;
  2687. }
  2688. if (le16_to_cpu(escan_result_le->bss_count) != 1) {
  2689. brcmf_err("Invalid bss_count %d: ignoring\n",
  2690. escan_result_le->bss_count);
  2691. goto exit;
  2692. }
  2693. bss_info_le = &escan_result_le->bss_info_le;
  2694. if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
  2695. goto exit;
  2696. if (!cfg->int_escan_map && !cfg->scan_request) {
  2697. brcmf_dbg(SCAN, "result without cfg80211 request\n");
  2698. goto exit;
  2699. }
  2700. bi_length = le32_to_cpu(bss_info_le->length);
  2701. if (bi_length != escan_buflen - WL_ESCAN_RESULTS_FIXED_SIZE) {
  2702. brcmf_err("Ignoring invalid bss_info length: %d\n",
  2703. bi_length);
  2704. goto exit;
  2705. }
  2706. if (!(cfg_to_wiphy(cfg)->interface_modes &
  2707. BIT(NL80211_IFTYPE_ADHOC))) {
  2708. if (le16_to_cpu(bss_info_le->capability) &
  2709. WLAN_CAPABILITY_IBSS) {
  2710. brcmf_err("Ignoring IBSS result\n");
  2711. goto exit;
  2712. }
  2713. }
  2714. list = (struct brcmf_scan_results *)
  2715. cfg->escan_info.escan_buf;
  2716. if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) {
  2717. brcmf_err("Buffer is too small: ignoring\n");
  2718. goto exit;
  2719. }
  2720. for (i = 0; i < list->count; i++) {
  2721. bss = bss ? (struct brcmf_bss_info_le *)
  2722. ((unsigned char *)bss +
  2723. le32_to_cpu(bss->length)) : list->bss_info_le;
  2724. if (brcmf_compare_update_same_bss(cfg, bss,
  2725. bss_info_le))
  2726. goto exit;
  2727. }
  2728. memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le,
  2729. bi_length);
  2730. list->version = le32_to_cpu(bss_info_le->version);
  2731. list->buflen += bi_length;
  2732. list->count++;
  2733. } else {
  2734. cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
  2735. if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
  2736. goto exit;
  2737. if (cfg->int_escan_map || cfg->scan_request) {
  2738. brcmf_inform_bss(cfg);
  2739. aborted = status != BRCMF_E_STATUS_SUCCESS;
  2740. brcmf_notify_escan_complete(cfg, ifp, aborted, false);
  2741. } else
  2742. brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
  2743. status);
  2744. }
  2745. exit:
  2746. return 0;
  2747. }
  2748. static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
  2749. {
  2750. brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
  2751. brcmf_cfg80211_escan_handler);
  2752. cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
  2753. /* Init scan_timeout timer */
  2754. timer_setup(&cfg->escan_timeout, brcmf_escan_timeout, 0);
  2755. INIT_WORK(&cfg->escan_timeout_work,
  2756. brcmf_cfg80211_escan_timeout_worker);
  2757. }
  2758. static struct cfg80211_scan_request *
  2759. brcmf_alloc_internal_escan_request(struct wiphy *wiphy, u32 n_netinfo) {
  2760. struct cfg80211_scan_request *req;
  2761. size_t req_size;
  2762. req_size = sizeof(*req) +
  2763. n_netinfo * sizeof(req->channels[0]) +
  2764. n_netinfo * sizeof(*req->ssids);
  2765. req = kzalloc(req_size, GFP_KERNEL);
  2766. if (req) {
  2767. req->wiphy = wiphy;
  2768. req->ssids = (void *)(&req->channels[0]) +
  2769. n_netinfo * sizeof(req->channels[0]);
  2770. }
  2771. return req;
  2772. }
  2773. static int brcmf_internal_escan_add_info(struct cfg80211_scan_request *req,
  2774. u8 *ssid, u8 ssid_len, u8 channel)
  2775. {
  2776. struct ieee80211_channel *chan;
  2777. enum nl80211_band band;
  2778. int freq, i;
  2779. if (channel <= CH_MAX_2G_CHANNEL)
  2780. band = NL80211_BAND_2GHZ;
  2781. else
  2782. band = NL80211_BAND_5GHZ;
  2783. freq = ieee80211_channel_to_frequency(channel, band);
  2784. if (!freq)
  2785. return -EINVAL;
  2786. chan = ieee80211_get_channel(req->wiphy, freq);
  2787. if (!chan)
  2788. return -EINVAL;
  2789. for (i = 0; i < req->n_channels; i++) {
  2790. if (req->channels[i] == chan)
  2791. break;
  2792. }
  2793. if (i == req->n_channels)
  2794. req->channels[req->n_channels++] = chan;
  2795. for (i = 0; i < req->n_ssids; i++) {
  2796. if (req->ssids[i].ssid_len == ssid_len &&
  2797. !memcmp(req->ssids[i].ssid, ssid, ssid_len))
  2798. break;
  2799. }
  2800. if (i == req->n_ssids) {
  2801. memcpy(req->ssids[req->n_ssids].ssid, ssid, ssid_len);
  2802. req->ssids[req->n_ssids++].ssid_len = ssid_len;
  2803. }
  2804. return 0;
  2805. }
  2806. static int brcmf_start_internal_escan(struct brcmf_if *ifp, u32 fwmap,
  2807. struct cfg80211_scan_request *request)
  2808. {
  2809. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  2810. int err;
  2811. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
  2812. if (cfg->int_escan_map)
  2813. brcmf_dbg(SCAN, "aborting internal scan: map=%u\n",
  2814. cfg->int_escan_map);
  2815. /* Abort any on-going scan */
  2816. brcmf_abort_scanning(cfg);
  2817. }
  2818. brcmf_dbg(SCAN, "start internal scan: map=%u\n", fwmap);
  2819. set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  2820. cfg->escan_info.run = brcmf_run_escan;
  2821. err = brcmf_do_escan(ifp, request);
  2822. if (err) {
  2823. clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  2824. return err;
  2825. }
  2826. cfg->int_escan_map = fwmap;
  2827. return 0;
  2828. }
  2829. static struct brcmf_pno_net_info_le *
  2830. brcmf_get_netinfo_array(struct brcmf_pno_scanresults_le *pfn_v1)
  2831. {
  2832. struct brcmf_pno_scanresults_v2_le *pfn_v2;
  2833. struct brcmf_pno_net_info_le *netinfo;
  2834. switch (pfn_v1->version) {
  2835. default:
  2836. WARN_ON(1);
  2837. /* fall-thru */
  2838. case cpu_to_le32(1):
  2839. netinfo = (struct brcmf_pno_net_info_le *)(pfn_v1 + 1);
  2840. break;
  2841. case cpu_to_le32(2):
  2842. pfn_v2 = (struct brcmf_pno_scanresults_v2_le *)pfn_v1;
  2843. netinfo = (struct brcmf_pno_net_info_le *)(pfn_v2 + 1);
  2844. break;
  2845. }
  2846. return netinfo;
  2847. }
  2848. /* PFN result doesn't have all the info which are required by the supplicant
  2849. * (For e.g IEs) Do a target Escan so that sched scan results are reported
  2850. * via wl_inform_single_bss in the required format. Escan does require the
  2851. * scan request in the form of cfg80211_scan_request. For timebeing, create
  2852. * cfg80211_scan_request one out of the received PNO event.
  2853. */
  2854. static s32
  2855. brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
  2856. const struct brcmf_event_msg *e, void *data)
  2857. {
  2858. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  2859. struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
  2860. struct cfg80211_scan_request *request = NULL;
  2861. struct wiphy *wiphy = cfg_to_wiphy(cfg);
  2862. int i, err = 0;
  2863. struct brcmf_pno_scanresults_le *pfn_result;
  2864. u32 bucket_map;
  2865. u32 result_count;
  2866. u32 status;
  2867. u32 datalen;
  2868. brcmf_dbg(SCAN, "Enter\n");
  2869. if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
  2870. brcmf_dbg(SCAN, "Event data to small. Ignore\n");
  2871. return 0;
  2872. }
  2873. if (e->event_code == BRCMF_E_PFN_NET_LOST) {
  2874. brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
  2875. return 0;
  2876. }
  2877. pfn_result = (struct brcmf_pno_scanresults_le *)data;
  2878. result_count = le32_to_cpu(pfn_result->count);
  2879. status = le32_to_cpu(pfn_result->status);
  2880. /* PFN event is limited to fit 512 bytes so we may get
  2881. * multiple NET_FOUND events. For now place a warning here.
  2882. */
  2883. WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
  2884. brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
  2885. if (!result_count) {
  2886. brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
  2887. goto out_err;
  2888. }
  2889. netinfo_start = brcmf_get_netinfo_array(pfn_result);
  2890. datalen = e->datalen - ((void *)netinfo_start - (void *)pfn_result);
  2891. if (datalen < result_count * sizeof(*netinfo)) {
  2892. brcmf_err("insufficient event data\n");
  2893. goto out_err;
  2894. }
  2895. request = brcmf_alloc_internal_escan_request(wiphy,
  2896. result_count);
  2897. if (!request) {
  2898. err = -ENOMEM;
  2899. goto out_err;
  2900. }
  2901. bucket_map = 0;
  2902. for (i = 0; i < result_count; i++) {
  2903. netinfo = &netinfo_start[i];
  2904. if (netinfo->SSID_len > IEEE80211_MAX_SSID_LEN)
  2905. netinfo->SSID_len = IEEE80211_MAX_SSID_LEN;
  2906. brcmf_dbg(SCAN, "SSID:%.32s Channel:%d\n",
  2907. netinfo->SSID, netinfo->channel);
  2908. bucket_map |= brcmf_pno_get_bucket_map(cfg->pno, netinfo);
  2909. err = brcmf_internal_escan_add_info(request,
  2910. netinfo->SSID,
  2911. netinfo->SSID_len,
  2912. netinfo->channel);
  2913. if (err)
  2914. goto out_err;
  2915. }
  2916. if (!bucket_map)
  2917. goto free_req;
  2918. err = brcmf_start_internal_escan(ifp, bucket_map, request);
  2919. if (!err)
  2920. goto free_req;
  2921. out_err:
  2922. cfg80211_sched_scan_stopped(wiphy, 0);
  2923. free_req:
  2924. kfree(request);
  2925. return err;
  2926. }
  2927. static int
  2928. brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
  2929. struct net_device *ndev,
  2930. struct cfg80211_sched_scan_request *req)
  2931. {
  2932. struct brcmf_if *ifp = netdev_priv(ndev);
  2933. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2934. brcmf_dbg(SCAN, "Enter: n_match_sets=%d n_ssids=%d\n",
  2935. req->n_match_sets, req->n_ssids);
  2936. if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
  2937. brcmf_err("Scanning suppressed: status=%lu\n",
  2938. cfg->scan_status);
  2939. return -EAGAIN;
  2940. }
  2941. if (req->n_match_sets <= 0) {
  2942. brcmf_dbg(SCAN, "invalid number of matchsets specified: %d\n",
  2943. req->n_match_sets);
  2944. return -EINVAL;
  2945. }
  2946. return brcmf_pno_start_sched_scan(ifp, req);
  2947. }
  2948. static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
  2949. struct net_device *ndev, u64 reqid)
  2950. {
  2951. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2952. struct brcmf_if *ifp = netdev_priv(ndev);
  2953. brcmf_dbg(SCAN, "enter\n");
  2954. brcmf_pno_stop_sched_scan(ifp, reqid);
  2955. if (cfg->int_escan_map)
  2956. brcmf_notify_escan_complete(cfg, ifp, true, true);
  2957. return 0;
  2958. }
  2959. static __always_inline void brcmf_delay(u32 ms)
  2960. {
  2961. if (ms < 1000 / HZ) {
  2962. cond_resched();
  2963. mdelay(ms);
  2964. } else {
  2965. msleep(ms);
  2966. }
  2967. }
  2968. static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
  2969. u8 *pattern, u32 patternsize, u8 *mask,
  2970. u32 packet_offset)
  2971. {
  2972. struct brcmf_fil_wowl_pattern_le *filter;
  2973. u32 masksize;
  2974. u32 patternoffset;
  2975. u8 *buf;
  2976. u32 bufsize;
  2977. s32 ret;
  2978. masksize = (patternsize + 7) / 8;
  2979. patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
  2980. bufsize = sizeof(*filter) + patternsize + masksize;
  2981. buf = kzalloc(bufsize, GFP_KERNEL);
  2982. if (!buf)
  2983. return -ENOMEM;
  2984. filter = (struct brcmf_fil_wowl_pattern_le *)buf;
  2985. memcpy(filter->cmd, cmd, 4);
  2986. filter->masksize = cpu_to_le32(masksize);
  2987. filter->offset = cpu_to_le32(packet_offset);
  2988. filter->patternoffset = cpu_to_le32(patternoffset);
  2989. filter->patternsize = cpu_to_le32(patternsize);
  2990. filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
  2991. if ((mask) && (masksize))
  2992. memcpy(buf + sizeof(*filter), mask, masksize);
  2993. if ((pattern) && (patternsize))
  2994. memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
  2995. ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
  2996. kfree(buf);
  2997. return ret;
  2998. }
  2999. static s32
  3000. brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e,
  3001. void *data)
  3002. {
  3003. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  3004. struct brcmf_pno_scanresults_le *pfn_result;
  3005. struct brcmf_pno_net_info_le *netinfo;
  3006. brcmf_dbg(SCAN, "Enter\n");
  3007. if (e->datalen < (sizeof(*pfn_result) + sizeof(*netinfo))) {
  3008. brcmf_dbg(SCAN, "Event data to small. Ignore\n");
  3009. return 0;
  3010. }
  3011. pfn_result = (struct brcmf_pno_scanresults_le *)data;
  3012. if (e->event_code == BRCMF_E_PFN_NET_LOST) {
  3013. brcmf_dbg(SCAN, "PFN NET LOST event. Ignore\n");
  3014. return 0;
  3015. }
  3016. if (le32_to_cpu(pfn_result->count) < 1) {
  3017. brcmf_err("Invalid result count, expected 1 (%d)\n",
  3018. le32_to_cpu(pfn_result->count));
  3019. return -EINVAL;
  3020. }
  3021. netinfo = brcmf_get_netinfo_array(pfn_result);
  3022. if (netinfo->SSID_len > IEEE80211_MAX_SSID_LEN)
  3023. netinfo->SSID_len = IEEE80211_MAX_SSID_LEN;
  3024. memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len);
  3025. cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len;
  3026. cfg->wowl.nd->n_channels = 1;
  3027. cfg->wowl.nd->channels[0] =
  3028. ieee80211_channel_to_frequency(netinfo->channel,
  3029. netinfo->channel <= CH_MAX_2G_CHANNEL ?
  3030. NL80211_BAND_2GHZ : NL80211_BAND_5GHZ);
  3031. cfg->wowl.nd_info->n_matches = 1;
  3032. cfg->wowl.nd_info->matches[0] = cfg->wowl.nd;
  3033. /* Inform (the resume task) that the net detect information was recvd */
  3034. cfg->wowl.nd_data_completed = true;
  3035. wake_up(&cfg->wowl.nd_data_wait);
  3036. return 0;
  3037. }
  3038. #ifdef CONFIG_PM
  3039. static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
  3040. {
  3041. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3042. struct brcmf_wowl_wakeind_le wake_ind_le;
  3043. struct cfg80211_wowlan_wakeup wakeup_data;
  3044. struct cfg80211_wowlan_wakeup *wakeup;
  3045. u32 wakeind;
  3046. s32 err;
  3047. int timeout;
  3048. err = brcmf_fil_iovar_data_get(ifp, "wowl_wakeind", &wake_ind_le,
  3049. sizeof(wake_ind_le));
  3050. if (err) {
  3051. brcmf_err("Get wowl_wakeind failed, err = %d\n", err);
  3052. return;
  3053. }
  3054. wakeind = le32_to_cpu(wake_ind_le.ucode_wakeind);
  3055. if (wakeind & (BRCMF_WOWL_MAGIC | BRCMF_WOWL_DIS | BRCMF_WOWL_BCN |
  3056. BRCMF_WOWL_RETR | BRCMF_WOWL_NET |
  3057. BRCMF_WOWL_PFN_FOUND)) {
  3058. wakeup = &wakeup_data;
  3059. memset(&wakeup_data, 0, sizeof(wakeup_data));
  3060. wakeup_data.pattern_idx = -1;
  3061. if (wakeind & BRCMF_WOWL_MAGIC) {
  3062. brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_MAGIC\n");
  3063. wakeup_data.magic_pkt = true;
  3064. }
  3065. if (wakeind & BRCMF_WOWL_DIS) {
  3066. brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_DIS\n");
  3067. wakeup_data.disconnect = true;
  3068. }
  3069. if (wakeind & BRCMF_WOWL_BCN) {
  3070. brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_BCN\n");
  3071. wakeup_data.disconnect = true;
  3072. }
  3073. if (wakeind & BRCMF_WOWL_RETR) {
  3074. brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_RETR\n");
  3075. wakeup_data.disconnect = true;
  3076. }
  3077. if (wakeind & BRCMF_WOWL_NET) {
  3078. brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_NET\n");
  3079. /* For now always map to pattern 0, no API to get
  3080. * correct information available at the moment.
  3081. */
  3082. wakeup_data.pattern_idx = 0;
  3083. }
  3084. if (wakeind & BRCMF_WOWL_PFN_FOUND) {
  3085. brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_PFN_FOUND\n");
  3086. timeout = wait_event_timeout(cfg->wowl.nd_data_wait,
  3087. cfg->wowl.nd_data_completed,
  3088. BRCMF_ND_INFO_TIMEOUT);
  3089. if (!timeout)
  3090. brcmf_err("No result for wowl net detect\n");
  3091. else
  3092. wakeup_data.net_detect = cfg->wowl.nd_info;
  3093. }
  3094. if (wakeind & BRCMF_WOWL_GTK_FAILURE) {
  3095. brcmf_dbg(INFO, "WOWL Wake indicator: BRCMF_WOWL_GTK_FAILURE\n");
  3096. wakeup_data.gtk_rekey_failure = true;
  3097. }
  3098. } else {
  3099. wakeup = NULL;
  3100. }
  3101. cfg80211_report_wowlan_wakeup(&ifp->vif->wdev, wakeup, GFP_KERNEL);
  3102. }
  3103. #else
  3104. static void brcmf_report_wowl_wakeind(struct wiphy *wiphy, struct brcmf_if *ifp)
  3105. {
  3106. }
  3107. #endif /* CONFIG_PM */
  3108. static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
  3109. {
  3110. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3111. struct net_device *ndev = cfg_to_ndev(cfg);
  3112. struct brcmf_if *ifp = netdev_priv(ndev);
  3113. brcmf_dbg(TRACE, "Enter\n");
  3114. if (cfg->wowl.active) {
  3115. brcmf_report_wowl_wakeind(wiphy, ifp);
  3116. brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
  3117. brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
  3118. if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND))
  3119. brcmf_configure_arp_nd_offload(ifp, true);
  3120. brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
  3121. cfg->wowl.pre_pmmode);
  3122. cfg->wowl.active = false;
  3123. if (cfg->wowl.nd_enabled) {
  3124. brcmf_cfg80211_sched_scan_stop(cfg->wiphy, ifp->ndev, 0);
  3125. brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
  3126. brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
  3127. brcmf_notify_sched_scan_results);
  3128. cfg->wowl.nd_enabled = false;
  3129. }
  3130. }
  3131. return 0;
  3132. }
  3133. static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
  3134. struct brcmf_if *ifp,
  3135. struct cfg80211_wowlan *wowl)
  3136. {
  3137. u32 wowl_config;
  3138. struct brcmf_wowl_wakeind_le wowl_wakeind;
  3139. u32 i;
  3140. brcmf_dbg(TRACE, "Suspend, wowl config.\n");
  3141. if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ARP_ND))
  3142. brcmf_configure_arp_nd_offload(ifp, false);
  3143. brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->wowl.pre_pmmode);
  3144. brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
  3145. wowl_config = 0;
  3146. if (wowl->disconnect)
  3147. wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
  3148. if (wowl->magic_pkt)
  3149. wowl_config |= BRCMF_WOWL_MAGIC;
  3150. if ((wowl->patterns) && (wowl->n_patterns)) {
  3151. wowl_config |= BRCMF_WOWL_NET;
  3152. for (i = 0; i < wowl->n_patterns; i++) {
  3153. brcmf_config_wowl_pattern(ifp, "add",
  3154. (u8 *)wowl->patterns[i].pattern,
  3155. wowl->patterns[i].pattern_len,
  3156. (u8 *)wowl->patterns[i].mask,
  3157. wowl->patterns[i].pkt_offset);
  3158. }
  3159. }
  3160. if (wowl->nd_config) {
  3161. brcmf_cfg80211_sched_scan_start(cfg->wiphy, ifp->ndev,
  3162. wowl->nd_config);
  3163. wowl_config |= BRCMF_WOWL_PFN_FOUND;
  3164. cfg->wowl.nd_data_completed = false;
  3165. cfg->wowl.nd_enabled = true;
  3166. /* Now reroute the event for PFN to the wowl function. */
  3167. brcmf_fweh_unregister(cfg->pub, BRCMF_E_PFN_NET_FOUND);
  3168. brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
  3169. brcmf_wowl_nd_results);
  3170. }
  3171. if (wowl->gtk_rekey_failure)
  3172. wowl_config |= BRCMF_WOWL_GTK_FAILURE;
  3173. if (!test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
  3174. wowl_config |= BRCMF_WOWL_UNASSOC;
  3175. memcpy(&wowl_wakeind, "clear", 6);
  3176. brcmf_fil_iovar_data_set(ifp, "wowl_wakeind", &wowl_wakeind,
  3177. sizeof(wowl_wakeind));
  3178. brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
  3179. brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
  3180. brcmf_bus_wowl_config(cfg->pub->bus_if, true);
  3181. cfg->wowl.active = true;
  3182. }
  3183. static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
  3184. struct cfg80211_wowlan *wowl)
  3185. {
  3186. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3187. struct net_device *ndev = cfg_to_ndev(cfg);
  3188. struct brcmf_if *ifp = netdev_priv(ndev);
  3189. struct brcmf_cfg80211_vif *vif;
  3190. brcmf_dbg(TRACE, "Enter\n");
  3191. /* if the primary net_device is not READY there is nothing
  3192. * we can do but pray resume goes smoothly.
  3193. */
  3194. if (!check_vif_up(ifp->vif))
  3195. goto exit;
  3196. /* Stop scheduled scan */
  3197. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO))
  3198. brcmf_cfg80211_sched_scan_stop(wiphy, ndev, 0);
  3199. /* end any scanning */
  3200. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
  3201. brcmf_abort_scanning(cfg);
  3202. if (wowl == NULL) {
  3203. brcmf_bus_wowl_config(cfg->pub->bus_if, false);
  3204. list_for_each_entry(vif, &cfg->vif_list, list) {
  3205. if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
  3206. continue;
  3207. /* While going to suspend if associated with AP
  3208. * disassociate from AP to save power while system is
  3209. * in suspended state
  3210. */
  3211. brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED);
  3212. /* Make sure WPA_Supplicant receives all the event
  3213. * generated due to DISASSOC call to the fw to keep
  3214. * the state fw and WPA_Supplicant state consistent
  3215. */
  3216. brcmf_delay(500);
  3217. }
  3218. /* Configure MPC */
  3219. brcmf_set_mpc(ifp, 1);
  3220. } else {
  3221. /* Configure WOWL paramaters */
  3222. brcmf_configure_wowl(cfg, ifp, wowl);
  3223. }
  3224. exit:
  3225. brcmf_dbg(TRACE, "Exit\n");
  3226. /* clear any scanning activity */
  3227. cfg->scan_status = 0;
  3228. return 0;
  3229. }
  3230. static __used s32
  3231. brcmf_update_pmklist(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp)
  3232. {
  3233. struct brcmf_pmk_list_le *pmk_list;
  3234. int i;
  3235. u32 npmk;
  3236. s32 err;
  3237. pmk_list = &cfg->pmk_list;
  3238. npmk = le32_to_cpu(pmk_list->npmk);
  3239. brcmf_dbg(CONN, "No of elements %d\n", npmk);
  3240. for (i = 0; i < npmk; i++)
  3241. brcmf_dbg(CONN, "PMK[%d]: %pM\n", i, &pmk_list->pmk[i].bssid);
  3242. err = brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_list,
  3243. sizeof(*pmk_list));
  3244. return err;
  3245. }
  3246. static s32
  3247. brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
  3248. struct cfg80211_pmksa *pmksa)
  3249. {
  3250. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3251. struct brcmf_if *ifp = netdev_priv(ndev);
  3252. struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
  3253. s32 err;
  3254. u32 npmk, i;
  3255. brcmf_dbg(TRACE, "Enter\n");
  3256. if (!check_vif_up(ifp->vif))
  3257. return -EIO;
  3258. npmk = le32_to_cpu(cfg->pmk_list.npmk);
  3259. for (i = 0; i < npmk; i++)
  3260. if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN))
  3261. break;
  3262. if (i < BRCMF_MAXPMKID) {
  3263. memcpy(pmk[i].bssid, pmksa->bssid, ETH_ALEN);
  3264. memcpy(pmk[i].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
  3265. if (i == npmk) {
  3266. npmk++;
  3267. cfg->pmk_list.npmk = cpu_to_le32(npmk);
  3268. }
  3269. } else {
  3270. brcmf_err("Too many PMKSA entries cached %d\n", npmk);
  3271. return -EINVAL;
  3272. }
  3273. brcmf_dbg(CONN, "set_pmksa - PMK bssid: %pM =\n", pmk[npmk].bssid);
  3274. for (i = 0; i < WLAN_PMKID_LEN; i += 4)
  3275. brcmf_dbg(CONN, "%02x %02x %02x %02x\n", pmk[npmk].pmkid[i],
  3276. pmk[npmk].pmkid[i + 1], pmk[npmk].pmkid[i + 2],
  3277. pmk[npmk].pmkid[i + 3]);
  3278. err = brcmf_update_pmklist(cfg, ifp);
  3279. brcmf_dbg(TRACE, "Exit\n");
  3280. return err;
  3281. }
  3282. static s32
  3283. brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
  3284. struct cfg80211_pmksa *pmksa)
  3285. {
  3286. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3287. struct brcmf_if *ifp = netdev_priv(ndev);
  3288. struct brcmf_pmksa *pmk = &cfg->pmk_list.pmk[0];
  3289. s32 err;
  3290. u32 npmk, i;
  3291. brcmf_dbg(TRACE, "Enter\n");
  3292. if (!check_vif_up(ifp->vif))
  3293. return -EIO;
  3294. brcmf_dbg(CONN, "del_pmksa - PMK bssid = %pM\n", pmksa->bssid);
  3295. npmk = le32_to_cpu(cfg->pmk_list.npmk);
  3296. for (i = 0; i < npmk; i++)
  3297. if (!memcmp(pmksa->bssid, pmk[i].bssid, ETH_ALEN))
  3298. break;
  3299. if ((npmk > 0) && (i < npmk)) {
  3300. for (; i < (npmk - 1); i++) {
  3301. memcpy(&pmk[i].bssid, &pmk[i + 1].bssid, ETH_ALEN);
  3302. memcpy(&pmk[i].pmkid, &pmk[i + 1].pmkid,
  3303. WLAN_PMKID_LEN);
  3304. }
  3305. memset(&pmk[i], 0, sizeof(*pmk));
  3306. cfg->pmk_list.npmk = cpu_to_le32(npmk - 1);
  3307. } else {
  3308. brcmf_err("Cache entry not found\n");
  3309. return -EINVAL;
  3310. }
  3311. err = brcmf_update_pmklist(cfg, ifp);
  3312. brcmf_dbg(TRACE, "Exit\n");
  3313. return err;
  3314. }
  3315. static s32
  3316. brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
  3317. {
  3318. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3319. struct brcmf_if *ifp = netdev_priv(ndev);
  3320. s32 err;
  3321. brcmf_dbg(TRACE, "Enter\n");
  3322. if (!check_vif_up(ifp->vif))
  3323. return -EIO;
  3324. memset(&cfg->pmk_list, 0, sizeof(cfg->pmk_list));
  3325. err = brcmf_update_pmklist(cfg, ifp);
  3326. brcmf_dbg(TRACE, "Exit\n");
  3327. return err;
  3328. }
  3329. static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
  3330. {
  3331. s32 err;
  3332. s32 wpa_val;
  3333. /* set auth */
  3334. err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
  3335. if (err < 0) {
  3336. brcmf_err("auth error %d\n", err);
  3337. return err;
  3338. }
  3339. /* set wsec */
  3340. err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
  3341. if (err < 0) {
  3342. brcmf_err("wsec error %d\n", err);
  3343. return err;
  3344. }
  3345. /* set upper-layer auth */
  3346. if (brcmf_is_ibssmode(ifp->vif))
  3347. wpa_val = WPA_AUTH_NONE;
  3348. else
  3349. wpa_val = WPA_AUTH_DISABLED;
  3350. err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_val);
  3351. if (err < 0) {
  3352. brcmf_err("wpa_auth error %d\n", err);
  3353. return err;
  3354. }
  3355. return 0;
  3356. }
  3357. static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
  3358. {
  3359. if (is_rsn_ie)
  3360. return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
  3361. return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
  3362. }
  3363. static s32
  3364. brcmf_configure_wpaie(struct brcmf_if *ifp,
  3365. const struct brcmf_vs_tlv *wpa_ie,
  3366. bool is_rsn_ie)
  3367. {
  3368. u32 auth = 0; /* d11 open authentication */
  3369. u16 count;
  3370. s32 err = 0;
  3371. s32 len;
  3372. u32 i;
  3373. u32 wsec;
  3374. u32 pval = 0;
  3375. u32 gval = 0;
  3376. u32 wpa_auth = 0;
  3377. u32 offset;
  3378. u8 *data;
  3379. u16 rsn_cap;
  3380. u32 wme_bss_disable;
  3381. u32 mfp;
  3382. brcmf_dbg(TRACE, "Enter\n");
  3383. if (wpa_ie == NULL)
  3384. goto exit;
  3385. len = wpa_ie->len + TLV_HDR_LEN;
  3386. data = (u8 *)wpa_ie;
  3387. offset = TLV_HDR_LEN;
  3388. if (!is_rsn_ie)
  3389. offset += VS_IE_FIXED_HDR_LEN;
  3390. else
  3391. offset += WPA_IE_VERSION_LEN;
  3392. /* check for multicast cipher suite */
  3393. if (offset + WPA_IE_MIN_OUI_LEN > len) {
  3394. err = -EINVAL;
  3395. brcmf_err("no multicast cipher suite\n");
  3396. goto exit;
  3397. }
  3398. if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
  3399. err = -EINVAL;
  3400. brcmf_err("ivalid OUI\n");
  3401. goto exit;
  3402. }
  3403. offset += TLV_OUI_LEN;
  3404. /* pick up multicast cipher */
  3405. switch (data[offset]) {
  3406. case WPA_CIPHER_NONE:
  3407. gval = 0;
  3408. break;
  3409. case WPA_CIPHER_WEP_40:
  3410. case WPA_CIPHER_WEP_104:
  3411. gval = WEP_ENABLED;
  3412. break;
  3413. case WPA_CIPHER_TKIP:
  3414. gval = TKIP_ENABLED;
  3415. break;
  3416. case WPA_CIPHER_AES_CCM:
  3417. gval = AES_ENABLED;
  3418. break;
  3419. default:
  3420. err = -EINVAL;
  3421. brcmf_err("Invalid multi cast cipher info\n");
  3422. goto exit;
  3423. }
  3424. offset++;
  3425. /* walk thru unicast cipher list and pick up what we recognize */
  3426. count = data[offset] + (data[offset + 1] << 8);
  3427. offset += WPA_IE_SUITE_COUNT_LEN;
  3428. /* Check for unicast suite(s) */
  3429. if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
  3430. err = -EINVAL;
  3431. brcmf_err("no unicast cipher suite\n");
  3432. goto exit;
  3433. }
  3434. for (i = 0; i < count; i++) {
  3435. if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
  3436. err = -EINVAL;
  3437. brcmf_err("ivalid OUI\n");
  3438. goto exit;
  3439. }
  3440. offset += TLV_OUI_LEN;
  3441. switch (data[offset]) {
  3442. case WPA_CIPHER_NONE:
  3443. break;
  3444. case WPA_CIPHER_WEP_40:
  3445. case WPA_CIPHER_WEP_104:
  3446. pval |= WEP_ENABLED;
  3447. break;
  3448. case WPA_CIPHER_TKIP:
  3449. pval |= TKIP_ENABLED;
  3450. break;
  3451. case WPA_CIPHER_AES_CCM:
  3452. pval |= AES_ENABLED;
  3453. break;
  3454. default:
  3455. brcmf_err("Invalid unicast security info\n");
  3456. }
  3457. offset++;
  3458. }
  3459. /* walk thru auth management suite list and pick up what we recognize */
  3460. count = data[offset] + (data[offset + 1] << 8);
  3461. offset += WPA_IE_SUITE_COUNT_LEN;
  3462. /* Check for auth key management suite(s) */
  3463. if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
  3464. err = -EINVAL;
  3465. brcmf_err("no auth key mgmt suite\n");
  3466. goto exit;
  3467. }
  3468. for (i = 0; i < count; i++) {
  3469. if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
  3470. err = -EINVAL;
  3471. brcmf_err("ivalid OUI\n");
  3472. goto exit;
  3473. }
  3474. offset += TLV_OUI_LEN;
  3475. switch (data[offset]) {
  3476. case RSN_AKM_NONE:
  3477. brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
  3478. wpa_auth |= WPA_AUTH_NONE;
  3479. break;
  3480. case RSN_AKM_UNSPECIFIED:
  3481. brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
  3482. is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
  3483. (wpa_auth |= WPA_AUTH_UNSPECIFIED);
  3484. break;
  3485. case RSN_AKM_PSK:
  3486. brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
  3487. is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
  3488. (wpa_auth |= WPA_AUTH_PSK);
  3489. break;
  3490. case RSN_AKM_SHA256_PSK:
  3491. brcmf_dbg(TRACE, "RSN_AKM_MFP_PSK\n");
  3492. wpa_auth |= WPA2_AUTH_PSK_SHA256;
  3493. break;
  3494. case RSN_AKM_SHA256_1X:
  3495. brcmf_dbg(TRACE, "RSN_AKM_MFP_1X\n");
  3496. wpa_auth |= WPA2_AUTH_1X_SHA256;
  3497. break;
  3498. default:
  3499. brcmf_err("Invalid key mgmt info\n");
  3500. }
  3501. offset++;
  3502. }
  3503. mfp = BRCMF_MFP_NONE;
  3504. if (is_rsn_ie) {
  3505. wme_bss_disable = 1;
  3506. if ((offset + RSN_CAP_LEN) <= len) {
  3507. rsn_cap = data[offset] + (data[offset + 1] << 8);
  3508. if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
  3509. wme_bss_disable = 0;
  3510. if (rsn_cap & RSN_CAP_MFPR_MASK) {
  3511. brcmf_dbg(TRACE, "MFP Required\n");
  3512. mfp = BRCMF_MFP_REQUIRED;
  3513. /* Firmware only supports mfp required in
  3514. * combination with WPA2_AUTH_PSK_SHA256 or
  3515. * WPA2_AUTH_1X_SHA256.
  3516. */
  3517. if (!(wpa_auth & (WPA2_AUTH_PSK_SHA256 |
  3518. WPA2_AUTH_1X_SHA256))) {
  3519. err = -EINVAL;
  3520. goto exit;
  3521. }
  3522. /* Firmware has requirement that WPA2_AUTH_PSK/
  3523. * WPA2_AUTH_UNSPECIFIED be set, if SHA256 OUI
  3524. * is to be included in the rsn ie.
  3525. */
  3526. if (wpa_auth & WPA2_AUTH_PSK_SHA256)
  3527. wpa_auth |= WPA2_AUTH_PSK;
  3528. else if (wpa_auth & WPA2_AUTH_1X_SHA256)
  3529. wpa_auth |= WPA2_AUTH_UNSPECIFIED;
  3530. } else if (rsn_cap & RSN_CAP_MFPC_MASK) {
  3531. brcmf_dbg(TRACE, "MFP Capable\n");
  3532. mfp = BRCMF_MFP_CAPABLE;
  3533. }
  3534. }
  3535. offset += RSN_CAP_LEN;
  3536. /* set wme_bss_disable to sync RSN Capabilities */
  3537. err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
  3538. wme_bss_disable);
  3539. if (err < 0) {
  3540. brcmf_err("wme_bss_disable error %d\n", err);
  3541. goto exit;
  3542. }
  3543. /* Skip PMKID cnt as it is know to be 0 for AP. */
  3544. offset += RSN_PMKID_COUNT_LEN;
  3545. /* See if there is BIP wpa suite left for MFP */
  3546. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP) &&
  3547. ((offset + WPA_IE_MIN_OUI_LEN) <= len)) {
  3548. err = brcmf_fil_bsscfg_data_set(ifp, "bip",
  3549. &data[offset],
  3550. WPA_IE_MIN_OUI_LEN);
  3551. if (err < 0) {
  3552. brcmf_err("bip error %d\n", err);
  3553. goto exit;
  3554. }
  3555. }
  3556. }
  3557. /* FOR WPS , set SES_OW_ENABLED */
  3558. wsec = (pval | gval | SES_OW_ENABLED);
  3559. /* set auth */
  3560. err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
  3561. if (err < 0) {
  3562. brcmf_err("auth error %d\n", err);
  3563. goto exit;
  3564. }
  3565. /* set wsec */
  3566. err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
  3567. if (err < 0) {
  3568. brcmf_err("wsec error %d\n", err);
  3569. goto exit;
  3570. }
  3571. /* Configure MFP, this needs to go after wsec otherwise the wsec command
  3572. * will overwrite the values set by MFP
  3573. */
  3574. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP)) {
  3575. err = brcmf_fil_bsscfg_int_set(ifp, "mfp", mfp);
  3576. if (err < 0) {
  3577. brcmf_err("mfp error %d\n", err);
  3578. goto exit;
  3579. }
  3580. }
  3581. /* set upper-layer auth */
  3582. err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
  3583. if (err < 0) {
  3584. brcmf_err("wpa_auth error %d\n", err);
  3585. goto exit;
  3586. }
  3587. exit:
  3588. return err;
  3589. }
  3590. static s32
  3591. brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
  3592. struct parsed_vndr_ies *vndr_ies)
  3593. {
  3594. struct brcmf_vs_tlv *vndrie;
  3595. struct brcmf_tlv *ie;
  3596. struct parsed_vndr_ie_info *parsed_info;
  3597. s32 remaining_len;
  3598. remaining_len = (s32)vndr_ie_len;
  3599. memset(vndr_ies, 0, sizeof(*vndr_ies));
  3600. ie = (struct brcmf_tlv *)vndr_ie_buf;
  3601. while (ie) {
  3602. if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
  3603. goto next;
  3604. vndrie = (struct brcmf_vs_tlv *)ie;
  3605. /* len should be bigger than OUI length + one */
  3606. if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
  3607. brcmf_err("invalid vndr ie. length is too small %d\n",
  3608. vndrie->len);
  3609. goto next;
  3610. }
  3611. /* if wpa or wme ie, do not add ie */
  3612. if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
  3613. ((vndrie->oui_type == WPA_OUI_TYPE) ||
  3614. (vndrie->oui_type == WME_OUI_TYPE))) {
  3615. brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
  3616. goto next;
  3617. }
  3618. parsed_info = &vndr_ies->ie_info[vndr_ies->count];
  3619. /* save vndr ie information */
  3620. parsed_info->ie_ptr = (char *)vndrie;
  3621. parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
  3622. memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
  3623. vndr_ies->count++;
  3624. brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
  3625. parsed_info->vndrie.oui[0],
  3626. parsed_info->vndrie.oui[1],
  3627. parsed_info->vndrie.oui[2],
  3628. parsed_info->vndrie.oui_type);
  3629. if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
  3630. break;
  3631. next:
  3632. remaining_len -= (ie->len + TLV_HDR_LEN);
  3633. if (remaining_len <= TLV_HDR_LEN)
  3634. ie = NULL;
  3635. else
  3636. ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
  3637. TLV_HDR_LEN);
  3638. }
  3639. return 0;
  3640. }
  3641. static u32
  3642. brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
  3643. {
  3644. strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
  3645. iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
  3646. put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]);
  3647. put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]);
  3648. memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
  3649. return ie_len + VNDR_IE_HDR_SIZE;
  3650. }
  3651. s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
  3652. const u8 *vndr_ie_buf, u32 vndr_ie_len)
  3653. {
  3654. struct brcmf_if *ifp;
  3655. struct vif_saved_ie *saved_ie;
  3656. s32 err = 0;
  3657. u8 *iovar_ie_buf;
  3658. u8 *curr_ie_buf;
  3659. u8 *mgmt_ie_buf = NULL;
  3660. int mgmt_ie_buf_len;
  3661. u32 *mgmt_ie_len;
  3662. u32 del_add_ie_buf_len = 0;
  3663. u32 total_ie_buf_len = 0;
  3664. u32 parsed_ie_buf_len = 0;
  3665. struct parsed_vndr_ies old_vndr_ies;
  3666. struct parsed_vndr_ies new_vndr_ies;
  3667. struct parsed_vndr_ie_info *vndrie_info;
  3668. s32 i;
  3669. u8 *ptr;
  3670. int remained_buf_len;
  3671. if (!vif)
  3672. return -ENODEV;
  3673. ifp = vif->ifp;
  3674. saved_ie = &vif->saved_ie;
  3675. brcmf_dbg(TRACE, "bsscfgidx %d, pktflag : 0x%02X\n", ifp->bsscfgidx,
  3676. pktflag);
  3677. iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
  3678. if (!iovar_ie_buf)
  3679. return -ENOMEM;
  3680. curr_ie_buf = iovar_ie_buf;
  3681. switch (pktflag) {
  3682. case BRCMF_VNDR_IE_PRBREQ_FLAG:
  3683. mgmt_ie_buf = saved_ie->probe_req_ie;
  3684. mgmt_ie_len = &saved_ie->probe_req_ie_len;
  3685. mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
  3686. break;
  3687. case BRCMF_VNDR_IE_PRBRSP_FLAG:
  3688. mgmt_ie_buf = saved_ie->probe_res_ie;
  3689. mgmt_ie_len = &saved_ie->probe_res_ie_len;
  3690. mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
  3691. break;
  3692. case BRCMF_VNDR_IE_BEACON_FLAG:
  3693. mgmt_ie_buf = saved_ie->beacon_ie;
  3694. mgmt_ie_len = &saved_ie->beacon_ie_len;
  3695. mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
  3696. break;
  3697. case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
  3698. mgmt_ie_buf = saved_ie->assoc_req_ie;
  3699. mgmt_ie_len = &saved_ie->assoc_req_ie_len;
  3700. mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
  3701. break;
  3702. default:
  3703. err = -EPERM;
  3704. brcmf_err("not suitable type\n");
  3705. goto exit;
  3706. }
  3707. if (vndr_ie_len > mgmt_ie_buf_len) {
  3708. err = -ENOMEM;
  3709. brcmf_err("extra IE size too big\n");
  3710. goto exit;
  3711. }
  3712. /* parse and save new vndr_ie in curr_ie_buff before comparing it */
  3713. if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
  3714. ptr = curr_ie_buf;
  3715. brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
  3716. for (i = 0; i < new_vndr_ies.count; i++) {
  3717. vndrie_info = &new_vndr_ies.ie_info[i];
  3718. memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
  3719. vndrie_info->ie_len);
  3720. parsed_ie_buf_len += vndrie_info->ie_len;
  3721. }
  3722. }
  3723. if (mgmt_ie_buf && *mgmt_ie_len) {
  3724. if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
  3725. (memcmp(mgmt_ie_buf, curr_ie_buf,
  3726. parsed_ie_buf_len) == 0)) {
  3727. brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
  3728. goto exit;
  3729. }
  3730. /* parse old vndr_ie */
  3731. brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
  3732. /* make a command to delete old ie */
  3733. for (i = 0; i < old_vndr_ies.count; i++) {
  3734. vndrie_info = &old_vndr_ies.ie_info[i];
  3735. brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
  3736. vndrie_info->vndrie.id,
  3737. vndrie_info->vndrie.len,
  3738. vndrie_info->vndrie.oui[0],
  3739. vndrie_info->vndrie.oui[1],
  3740. vndrie_info->vndrie.oui[2]);
  3741. del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
  3742. vndrie_info->ie_ptr,
  3743. vndrie_info->ie_len,
  3744. "del");
  3745. curr_ie_buf += del_add_ie_buf_len;
  3746. total_ie_buf_len += del_add_ie_buf_len;
  3747. }
  3748. }
  3749. *mgmt_ie_len = 0;
  3750. /* Add if there is any extra IE */
  3751. if (mgmt_ie_buf && parsed_ie_buf_len) {
  3752. ptr = mgmt_ie_buf;
  3753. remained_buf_len = mgmt_ie_buf_len;
  3754. /* make a command to add new ie */
  3755. for (i = 0; i < new_vndr_ies.count; i++) {
  3756. vndrie_info = &new_vndr_ies.ie_info[i];
  3757. /* verify remained buf size before copy data */
  3758. if (remained_buf_len < (vndrie_info->vndrie.len +
  3759. VNDR_IE_VSIE_OFFSET)) {
  3760. brcmf_err("no space in mgmt_ie_buf: len left %d",
  3761. remained_buf_len);
  3762. break;
  3763. }
  3764. remained_buf_len -= (vndrie_info->ie_len +
  3765. VNDR_IE_VSIE_OFFSET);
  3766. brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
  3767. vndrie_info->vndrie.id,
  3768. vndrie_info->vndrie.len,
  3769. vndrie_info->vndrie.oui[0],
  3770. vndrie_info->vndrie.oui[1],
  3771. vndrie_info->vndrie.oui[2]);
  3772. del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
  3773. vndrie_info->ie_ptr,
  3774. vndrie_info->ie_len,
  3775. "add");
  3776. /* save the parsed IE in wl struct */
  3777. memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
  3778. vndrie_info->ie_len);
  3779. *mgmt_ie_len += vndrie_info->ie_len;
  3780. curr_ie_buf += del_add_ie_buf_len;
  3781. total_ie_buf_len += del_add_ie_buf_len;
  3782. }
  3783. }
  3784. if (total_ie_buf_len) {
  3785. err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
  3786. total_ie_buf_len);
  3787. if (err)
  3788. brcmf_err("vndr ie set error : %d\n", err);
  3789. }
  3790. exit:
  3791. kfree(iovar_ie_buf);
  3792. return err;
  3793. }
  3794. s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
  3795. {
  3796. s32 pktflags[] = {
  3797. BRCMF_VNDR_IE_PRBREQ_FLAG,
  3798. BRCMF_VNDR_IE_PRBRSP_FLAG,
  3799. BRCMF_VNDR_IE_BEACON_FLAG
  3800. };
  3801. int i;
  3802. for (i = 0; i < ARRAY_SIZE(pktflags); i++)
  3803. brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
  3804. memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
  3805. return 0;
  3806. }
  3807. static s32
  3808. brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
  3809. struct cfg80211_beacon_data *beacon)
  3810. {
  3811. s32 err;
  3812. /* Set Beacon IEs to FW */
  3813. err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
  3814. beacon->tail, beacon->tail_len);
  3815. if (err) {
  3816. brcmf_err("Set Beacon IE Failed\n");
  3817. return err;
  3818. }
  3819. brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
  3820. /* Set Probe Response IEs to FW */
  3821. err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
  3822. beacon->proberesp_ies,
  3823. beacon->proberesp_ies_len);
  3824. if (err)
  3825. brcmf_err("Set Probe Resp IE Failed\n");
  3826. else
  3827. brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
  3828. return err;
  3829. }
  3830. static s32
  3831. brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
  3832. struct cfg80211_ap_settings *settings)
  3833. {
  3834. s32 ie_offset;
  3835. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3836. struct brcmf_if *ifp = netdev_priv(ndev);
  3837. const struct brcmf_tlv *ssid_ie;
  3838. const struct brcmf_tlv *country_ie;
  3839. struct brcmf_ssid_le ssid_le;
  3840. s32 err = -EPERM;
  3841. const struct brcmf_tlv *rsn_ie;
  3842. const struct brcmf_vs_tlv *wpa_ie;
  3843. struct brcmf_join_params join_params;
  3844. enum nl80211_iftype dev_role;
  3845. struct brcmf_fil_bss_enable_le bss_enable;
  3846. u16 chanspec = chandef_to_chanspec(&cfg->d11inf, &settings->chandef);
  3847. bool mbss;
  3848. int is_11d;
  3849. bool supports_11d;
  3850. brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
  3851. settings->chandef.chan->hw_value,
  3852. settings->chandef.center_freq1, settings->chandef.width,
  3853. settings->beacon_interval, settings->dtim_period);
  3854. brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
  3855. settings->ssid, settings->ssid_len, settings->auth_type,
  3856. settings->inactivity_timeout);
  3857. dev_role = ifp->vif->wdev.iftype;
  3858. mbss = ifp->vif->mbss;
  3859. /* store current 11d setting */
  3860. if (brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY,
  3861. &ifp->vif->is_11d)) {
  3862. is_11d = supports_11d = false;
  3863. } else {
  3864. country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
  3865. settings->beacon.tail_len,
  3866. WLAN_EID_COUNTRY);
  3867. is_11d = country_ie ? 1 : 0;
  3868. supports_11d = true;
  3869. }
  3870. memset(&ssid_le, 0, sizeof(ssid_le));
  3871. if (settings->ssid == NULL || settings->ssid_len == 0) {
  3872. ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
  3873. ssid_ie = brcmf_parse_tlvs(
  3874. (u8 *)&settings->beacon.head[ie_offset],
  3875. settings->beacon.head_len - ie_offset,
  3876. WLAN_EID_SSID);
  3877. if (!ssid_ie || ssid_ie->len > IEEE80211_MAX_SSID_LEN)
  3878. return -EINVAL;
  3879. memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
  3880. ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
  3881. brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
  3882. } else {
  3883. memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
  3884. ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
  3885. }
  3886. if (!mbss) {
  3887. brcmf_set_mpc(ifp, 0);
  3888. brcmf_configure_arp_nd_offload(ifp, false);
  3889. }
  3890. /* find the RSN_IE */
  3891. rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
  3892. settings->beacon.tail_len, WLAN_EID_RSN);
  3893. /* find the WPA_IE */
  3894. wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
  3895. settings->beacon.tail_len);
  3896. if ((wpa_ie != NULL || rsn_ie != NULL)) {
  3897. brcmf_dbg(TRACE, "WPA(2) IE is found\n");
  3898. if (wpa_ie != NULL) {
  3899. /* WPA IE */
  3900. err = brcmf_configure_wpaie(ifp, wpa_ie, false);
  3901. if (err < 0)
  3902. goto exit;
  3903. } else {
  3904. struct brcmf_vs_tlv *tmp_ie;
  3905. tmp_ie = (struct brcmf_vs_tlv *)rsn_ie;
  3906. /* RSN IE */
  3907. err = brcmf_configure_wpaie(ifp, tmp_ie, true);
  3908. if (err < 0)
  3909. goto exit;
  3910. }
  3911. } else {
  3912. brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
  3913. brcmf_configure_opensecurity(ifp);
  3914. }
  3915. /* Parameters shared by all radio interfaces */
  3916. if (!mbss) {
  3917. if ((supports_11d) && (is_11d != ifp->vif->is_11d)) {
  3918. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
  3919. is_11d);
  3920. if (err < 0) {
  3921. brcmf_err("Regulatory Set Error, %d\n", err);
  3922. goto exit;
  3923. }
  3924. }
  3925. if (settings->beacon_interval) {
  3926. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
  3927. settings->beacon_interval);
  3928. if (err < 0) {
  3929. brcmf_err("Beacon Interval Set Error, %d\n",
  3930. err);
  3931. goto exit;
  3932. }
  3933. }
  3934. if (settings->dtim_period) {
  3935. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
  3936. settings->dtim_period);
  3937. if (err < 0) {
  3938. brcmf_err("DTIM Interval Set Error, %d\n", err);
  3939. goto exit;
  3940. }
  3941. }
  3942. if ((dev_role == NL80211_IFTYPE_AP) &&
  3943. ((ifp->ifidx == 0) ||
  3944. !brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) {
  3945. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
  3946. if (err < 0) {
  3947. brcmf_err("BRCMF_C_DOWN error %d\n", err);
  3948. goto exit;
  3949. }
  3950. brcmf_fil_iovar_int_set(ifp, "apsta", 0);
  3951. }
  3952. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
  3953. if (err < 0) {
  3954. brcmf_err("SET INFRA error %d\n", err);
  3955. goto exit;
  3956. }
  3957. } else if (WARN_ON(supports_11d && (is_11d != ifp->vif->is_11d))) {
  3958. /* Multiple-BSS should use same 11d configuration */
  3959. err = -EINVAL;
  3960. goto exit;
  3961. }
  3962. /* Interface specific setup */
  3963. if (dev_role == NL80211_IFTYPE_AP) {
  3964. if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss))
  3965. brcmf_fil_iovar_int_set(ifp, "mbss", 1);
  3966. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
  3967. if (err < 0) {
  3968. brcmf_err("setting AP mode failed %d\n", err);
  3969. goto exit;
  3970. }
  3971. if (!mbss) {
  3972. /* Firmware 10.x requires setting channel after enabling
  3973. * AP and before bringing interface up.
  3974. */
  3975. err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
  3976. if (err < 0) {
  3977. brcmf_err("Set Channel failed: chspec=%d, %d\n",
  3978. chanspec, err);
  3979. goto exit;
  3980. }
  3981. }
  3982. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
  3983. if (err < 0) {
  3984. brcmf_err("BRCMF_C_UP error (%d)\n", err);
  3985. goto exit;
  3986. }
  3987. /* On DOWN the firmware removes the WEP keys, reconfigure
  3988. * them if they were set.
  3989. */
  3990. brcmf_cfg80211_reconfigure_wep(ifp);
  3991. memset(&join_params, 0, sizeof(join_params));
  3992. /* join parameters starts with ssid */
  3993. memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
  3994. /* create softap */
  3995. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
  3996. &join_params, sizeof(join_params));
  3997. if (err < 0) {
  3998. brcmf_err("SET SSID error (%d)\n", err);
  3999. goto exit;
  4000. }
  4001. if (settings->hidden_ssid) {
  4002. err = brcmf_fil_iovar_int_set(ifp, "closednet", 1);
  4003. if (err) {
  4004. brcmf_err("closednet error (%d)\n", err);
  4005. goto exit;
  4006. }
  4007. }
  4008. brcmf_dbg(TRACE, "AP mode configuration complete\n");
  4009. } else if (dev_role == NL80211_IFTYPE_P2P_GO) {
  4010. err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
  4011. if (err < 0) {
  4012. brcmf_err("Set Channel failed: chspec=%d, %d\n",
  4013. chanspec, err);
  4014. goto exit;
  4015. }
  4016. err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
  4017. sizeof(ssid_le));
  4018. if (err < 0) {
  4019. brcmf_err("setting ssid failed %d\n", err);
  4020. goto exit;
  4021. }
  4022. bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
  4023. bss_enable.enable = cpu_to_le32(1);
  4024. err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
  4025. sizeof(bss_enable));
  4026. if (err < 0) {
  4027. brcmf_err("bss_enable config failed %d\n", err);
  4028. goto exit;
  4029. }
  4030. brcmf_dbg(TRACE, "GO mode configuration complete\n");
  4031. } else {
  4032. WARN_ON(1);
  4033. }
  4034. brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
  4035. set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
  4036. brcmf_net_setcarrier(ifp, true);
  4037. exit:
  4038. if ((err) && (!mbss)) {
  4039. brcmf_set_mpc(ifp, 1);
  4040. brcmf_configure_arp_nd_offload(ifp, true);
  4041. }
  4042. return err;
  4043. }
  4044. static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
  4045. {
  4046. struct brcmf_if *ifp = netdev_priv(ndev);
  4047. s32 err;
  4048. struct brcmf_fil_bss_enable_le bss_enable;
  4049. struct brcmf_join_params join_params;
  4050. brcmf_dbg(TRACE, "Enter\n");
  4051. if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
  4052. /* Due to most likely deauths outstanding we sleep */
  4053. /* first to make sure they get processed by fw. */
  4054. msleep(400);
  4055. if (ifp->vif->mbss) {
  4056. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
  4057. return err;
  4058. }
  4059. /* First BSS doesn't get a full reset */
  4060. if (ifp->bsscfgidx == 0)
  4061. brcmf_fil_iovar_int_set(ifp, "closednet", 0);
  4062. memset(&join_params, 0, sizeof(join_params));
  4063. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
  4064. &join_params, sizeof(join_params));
  4065. if (err < 0)
  4066. brcmf_err("SET SSID error (%d)\n", err);
  4067. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
  4068. if (err < 0)
  4069. brcmf_err("BRCMF_C_DOWN error %d\n", err);
  4070. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
  4071. if (err < 0)
  4072. brcmf_err("setting AP mode failed %d\n", err);
  4073. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS))
  4074. brcmf_fil_iovar_int_set(ifp, "mbss", 0);
  4075. brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
  4076. ifp->vif->is_11d);
  4077. /* Bring device back up so it can be used again */
  4078. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
  4079. if (err < 0)
  4080. brcmf_err("BRCMF_C_UP error %d\n", err);
  4081. brcmf_vif_clear_mgmt_ies(ifp->vif);
  4082. } else {
  4083. bss_enable.bsscfgidx = cpu_to_le32(ifp->bsscfgidx);
  4084. bss_enable.enable = cpu_to_le32(0);
  4085. err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
  4086. sizeof(bss_enable));
  4087. if (err < 0)
  4088. brcmf_err("bss_enable config failed %d\n", err);
  4089. }
  4090. brcmf_set_mpc(ifp, 1);
  4091. brcmf_configure_arp_nd_offload(ifp, true);
  4092. clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
  4093. brcmf_net_setcarrier(ifp, false);
  4094. return err;
  4095. }
  4096. static s32
  4097. brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
  4098. struct cfg80211_beacon_data *info)
  4099. {
  4100. struct brcmf_if *ifp = netdev_priv(ndev);
  4101. s32 err;
  4102. brcmf_dbg(TRACE, "Enter\n");
  4103. err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
  4104. return err;
  4105. }
  4106. static int
  4107. brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
  4108. struct station_del_parameters *params)
  4109. {
  4110. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  4111. struct brcmf_scb_val_le scbval;
  4112. struct brcmf_if *ifp = netdev_priv(ndev);
  4113. s32 err;
  4114. if (!params->mac)
  4115. return -EFAULT;
  4116. brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
  4117. if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
  4118. ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
  4119. if (!check_vif_up(ifp->vif))
  4120. return -EIO;
  4121. memcpy(&scbval.ea, params->mac, ETH_ALEN);
  4122. scbval.val = cpu_to_le32(params->reason_code);
  4123. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
  4124. &scbval, sizeof(scbval));
  4125. if (err)
  4126. brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
  4127. brcmf_dbg(TRACE, "Exit\n");
  4128. return err;
  4129. }
  4130. static int
  4131. brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev,
  4132. const u8 *mac, struct station_parameters *params)
  4133. {
  4134. struct brcmf_if *ifp = netdev_priv(ndev);
  4135. s32 err;
  4136. brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac,
  4137. params->sta_flags_mask, params->sta_flags_set);
  4138. /* Ignore all 00 MAC */
  4139. if (is_zero_ether_addr(mac))
  4140. return 0;
  4141. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  4142. return 0;
  4143. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  4144. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE,
  4145. (void *)mac, ETH_ALEN);
  4146. else
  4147. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE,
  4148. (void *)mac, ETH_ALEN);
  4149. if (err < 0)
  4150. brcmf_err("Setting SCB (de-)authorize failed, %d\n", err);
  4151. return err;
  4152. }
  4153. static void
  4154. brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
  4155. struct wireless_dev *wdev,
  4156. u16 frame_type, bool reg)
  4157. {
  4158. struct brcmf_cfg80211_vif *vif;
  4159. u16 mgmt_type;
  4160. brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
  4161. mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
  4162. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  4163. if (reg)
  4164. vif->mgmt_rx_reg |= BIT(mgmt_type);
  4165. else
  4166. vif->mgmt_rx_reg &= ~BIT(mgmt_type);
  4167. }
  4168. static int
  4169. brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  4170. struct cfg80211_mgmt_tx_params *params, u64 *cookie)
  4171. {
  4172. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  4173. struct ieee80211_channel *chan = params->chan;
  4174. const u8 *buf = params->buf;
  4175. size_t len = params->len;
  4176. const struct ieee80211_mgmt *mgmt;
  4177. struct brcmf_cfg80211_vif *vif;
  4178. s32 err = 0;
  4179. s32 ie_offset;
  4180. s32 ie_len;
  4181. struct brcmf_fil_action_frame_le *action_frame;
  4182. struct brcmf_fil_af_params_le *af_params;
  4183. bool ack;
  4184. s32 chan_nr;
  4185. u32 freq;
  4186. brcmf_dbg(TRACE, "Enter\n");
  4187. *cookie = 0;
  4188. mgmt = (const struct ieee80211_mgmt *)buf;
  4189. if (!ieee80211_is_mgmt(mgmt->frame_control)) {
  4190. brcmf_err("Driver only allows MGMT packet type\n");
  4191. return -EPERM;
  4192. }
  4193. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  4194. if (ieee80211_is_probe_resp(mgmt->frame_control)) {
  4195. /* Right now the only reason to get a probe response */
  4196. /* is for p2p listen response or for p2p GO from */
  4197. /* wpa_supplicant. Unfortunately the probe is send */
  4198. /* on primary ndev, while dongle wants it on the p2p */
  4199. /* vif. Since this is only reason for a probe */
  4200. /* response to be sent, the vif is taken from cfg. */
  4201. /* If ever desired to send proberesp for non p2p */
  4202. /* response then data should be checked for */
  4203. /* "DIRECT-". Note in future supplicant will take */
  4204. /* dedicated p2p wdev to do this and then this 'hack'*/
  4205. /* is not needed anymore. */
  4206. ie_offset = DOT11_MGMT_HDR_LEN +
  4207. DOT11_BCN_PRB_FIXED_LEN;
  4208. ie_len = len - ie_offset;
  4209. if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
  4210. vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  4211. err = brcmf_vif_set_mgmt_ie(vif,
  4212. BRCMF_VNDR_IE_PRBRSP_FLAG,
  4213. &buf[ie_offset],
  4214. ie_len);
  4215. cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
  4216. GFP_KERNEL);
  4217. } else if (ieee80211_is_action(mgmt->frame_control)) {
  4218. if (len > BRCMF_FIL_ACTION_FRAME_SIZE + DOT11_MGMT_HDR_LEN) {
  4219. brcmf_err("invalid action frame length\n");
  4220. err = -EINVAL;
  4221. goto exit;
  4222. }
  4223. af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
  4224. if (af_params == NULL) {
  4225. brcmf_err("unable to allocate frame\n");
  4226. err = -ENOMEM;
  4227. goto exit;
  4228. }
  4229. action_frame = &af_params->action_frame;
  4230. /* Add the packet Id */
  4231. action_frame->packet_id = cpu_to_le32(*cookie);
  4232. /* Add BSSID */
  4233. memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
  4234. memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
  4235. /* Add the length exepted for 802.11 header */
  4236. action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
  4237. /* Add the channel. Use the one specified as parameter if any or
  4238. * the current one (got from the firmware) otherwise
  4239. */
  4240. if (chan)
  4241. freq = chan->center_freq;
  4242. else
  4243. brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
  4244. &freq);
  4245. chan_nr = ieee80211_frequency_to_channel(freq);
  4246. af_params->channel = cpu_to_le32(chan_nr);
  4247. memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
  4248. le16_to_cpu(action_frame->len));
  4249. brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
  4250. *cookie, le16_to_cpu(action_frame->len), freq);
  4251. ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
  4252. af_params);
  4253. cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
  4254. GFP_KERNEL);
  4255. kfree(af_params);
  4256. } else {
  4257. brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
  4258. brcmf_dbg_hex_dump(true, buf, len, "payload, len=%zu\n", len);
  4259. }
  4260. exit:
  4261. return err;
  4262. }
  4263. static int
  4264. brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
  4265. struct wireless_dev *wdev,
  4266. u64 cookie)
  4267. {
  4268. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  4269. struct brcmf_cfg80211_vif *vif;
  4270. int err = 0;
  4271. brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
  4272. vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  4273. if (vif == NULL) {
  4274. brcmf_err("No p2p device available for probe response\n");
  4275. err = -ENODEV;
  4276. goto exit;
  4277. }
  4278. brcmf_p2p_cancel_remain_on_channel(vif->ifp);
  4279. exit:
  4280. return err;
  4281. }
  4282. static int brcmf_cfg80211_get_channel(struct wiphy *wiphy,
  4283. struct wireless_dev *wdev,
  4284. struct cfg80211_chan_def *chandef)
  4285. {
  4286. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  4287. struct net_device *ndev = wdev->netdev;
  4288. struct brcmf_if *ifp;
  4289. struct brcmu_chan ch;
  4290. enum nl80211_band band = 0;
  4291. enum nl80211_chan_width width = 0;
  4292. u32 chanspec;
  4293. int freq, err;
  4294. if (!ndev)
  4295. return -ENODEV;
  4296. ifp = netdev_priv(ndev);
  4297. err = brcmf_fil_iovar_int_get(ifp, "chanspec", &chanspec);
  4298. if (err) {
  4299. brcmf_err("chanspec failed (%d)\n", err);
  4300. return err;
  4301. }
  4302. ch.chspec = chanspec;
  4303. cfg->d11inf.decchspec(&ch);
  4304. switch (ch.band) {
  4305. case BRCMU_CHAN_BAND_2G:
  4306. band = NL80211_BAND_2GHZ;
  4307. break;
  4308. case BRCMU_CHAN_BAND_5G:
  4309. band = NL80211_BAND_5GHZ;
  4310. break;
  4311. }
  4312. switch (ch.bw) {
  4313. case BRCMU_CHAN_BW_80:
  4314. width = NL80211_CHAN_WIDTH_80;
  4315. break;
  4316. case BRCMU_CHAN_BW_40:
  4317. width = NL80211_CHAN_WIDTH_40;
  4318. break;
  4319. case BRCMU_CHAN_BW_20:
  4320. width = NL80211_CHAN_WIDTH_20;
  4321. break;
  4322. case BRCMU_CHAN_BW_80P80:
  4323. width = NL80211_CHAN_WIDTH_80P80;
  4324. break;
  4325. case BRCMU_CHAN_BW_160:
  4326. width = NL80211_CHAN_WIDTH_160;
  4327. break;
  4328. }
  4329. freq = ieee80211_channel_to_frequency(ch.control_ch_num, band);
  4330. chandef->chan = ieee80211_get_channel(wiphy, freq);
  4331. chandef->width = width;
  4332. chandef->center_freq1 = ieee80211_channel_to_frequency(ch.chnum, band);
  4333. chandef->center_freq2 = 0;
  4334. return 0;
  4335. }
  4336. static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
  4337. struct wireless_dev *wdev,
  4338. enum nl80211_crit_proto_id proto,
  4339. u16 duration)
  4340. {
  4341. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  4342. struct brcmf_cfg80211_vif *vif;
  4343. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  4344. /* only DHCP support for now */
  4345. if (proto != NL80211_CRIT_PROTO_DHCP)
  4346. return -EINVAL;
  4347. /* suppress and abort scanning */
  4348. set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
  4349. brcmf_abort_scanning(cfg);
  4350. return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
  4351. }
  4352. static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
  4353. struct wireless_dev *wdev)
  4354. {
  4355. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  4356. struct brcmf_cfg80211_vif *vif;
  4357. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  4358. brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
  4359. clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
  4360. }
  4361. static s32
  4362. brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
  4363. const struct brcmf_event_msg *e, void *data)
  4364. {
  4365. switch (e->reason) {
  4366. case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
  4367. brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
  4368. break;
  4369. case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
  4370. brcmf_dbg(TRACE, "TDLS Peer Connected\n");
  4371. brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
  4372. break;
  4373. case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
  4374. brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
  4375. brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
  4376. break;
  4377. }
  4378. return 0;
  4379. }
  4380. static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
  4381. {
  4382. int ret;
  4383. switch (oper) {
  4384. case NL80211_TDLS_DISCOVERY_REQ:
  4385. ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
  4386. break;
  4387. case NL80211_TDLS_SETUP:
  4388. ret = BRCMF_TDLS_MANUAL_EP_CREATE;
  4389. break;
  4390. case NL80211_TDLS_TEARDOWN:
  4391. ret = BRCMF_TDLS_MANUAL_EP_DELETE;
  4392. break;
  4393. default:
  4394. brcmf_err("unsupported operation: %d\n", oper);
  4395. ret = -EOPNOTSUPP;
  4396. }
  4397. return ret;
  4398. }
  4399. static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
  4400. struct net_device *ndev, const u8 *peer,
  4401. enum nl80211_tdls_operation oper)
  4402. {
  4403. struct brcmf_if *ifp;
  4404. struct brcmf_tdls_iovar_le info;
  4405. int ret = 0;
  4406. ret = brcmf_convert_nl80211_tdls_oper(oper);
  4407. if (ret < 0)
  4408. return ret;
  4409. ifp = netdev_priv(ndev);
  4410. memset(&info, 0, sizeof(info));
  4411. info.mode = (u8)ret;
  4412. if (peer)
  4413. memcpy(info.ea, peer, ETH_ALEN);
  4414. ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
  4415. &info, sizeof(info));
  4416. if (ret < 0)
  4417. brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
  4418. return ret;
  4419. }
  4420. static int
  4421. brcmf_cfg80211_update_conn_params(struct wiphy *wiphy,
  4422. struct net_device *ndev,
  4423. struct cfg80211_connect_params *sme,
  4424. u32 changed)
  4425. {
  4426. struct brcmf_if *ifp;
  4427. int err;
  4428. if (!(changed & UPDATE_ASSOC_IES))
  4429. return 0;
  4430. ifp = netdev_priv(ndev);
  4431. err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
  4432. sme->ie, sme->ie_len);
  4433. if (err)
  4434. brcmf_err("Set Assoc REQ IE Failed\n");
  4435. else
  4436. brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
  4437. return err;
  4438. }
  4439. #ifdef CONFIG_PM
  4440. static int
  4441. brcmf_cfg80211_set_rekey_data(struct wiphy *wiphy, struct net_device *ndev,
  4442. struct cfg80211_gtk_rekey_data *gtk)
  4443. {
  4444. struct brcmf_if *ifp = netdev_priv(ndev);
  4445. struct brcmf_gtk_keyinfo_le gtk_le;
  4446. int ret;
  4447. brcmf_dbg(TRACE, "Enter, bssidx=%d\n", ifp->bsscfgidx);
  4448. memcpy(gtk_le.kck, gtk->kck, sizeof(gtk_le.kck));
  4449. memcpy(gtk_le.kek, gtk->kek, sizeof(gtk_le.kek));
  4450. memcpy(gtk_le.replay_counter, gtk->replay_ctr,
  4451. sizeof(gtk_le.replay_counter));
  4452. ret = brcmf_fil_iovar_data_set(ifp, "gtk_key_info", &gtk_le,
  4453. sizeof(gtk_le));
  4454. if (ret < 0)
  4455. brcmf_err("gtk_key_info iovar failed: ret=%d\n", ret);
  4456. return ret;
  4457. }
  4458. #endif
  4459. static int brcmf_cfg80211_set_pmk(struct wiphy *wiphy, struct net_device *dev,
  4460. const struct cfg80211_pmk_conf *conf)
  4461. {
  4462. struct brcmf_if *ifp;
  4463. brcmf_dbg(TRACE, "enter\n");
  4464. /* expect using firmware supplicant for 1X */
  4465. ifp = netdev_priv(dev);
  4466. if (WARN_ON(ifp->vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_1X))
  4467. return -EINVAL;
  4468. if (conf->pmk_len > BRCMF_WSEC_MAX_PSK_LEN)
  4469. return -ERANGE;
  4470. return brcmf_set_pmk(ifp, conf->pmk, conf->pmk_len);
  4471. }
  4472. static int brcmf_cfg80211_del_pmk(struct wiphy *wiphy, struct net_device *dev,
  4473. const u8 *aa)
  4474. {
  4475. struct brcmf_if *ifp;
  4476. brcmf_dbg(TRACE, "enter\n");
  4477. ifp = netdev_priv(dev);
  4478. if (WARN_ON(ifp->vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_1X))
  4479. return -EINVAL;
  4480. return brcmf_set_pmk(ifp, NULL, 0);
  4481. }
  4482. static struct cfg80211_ops brcmf_cfg80211_ops = {
  4483. .add_virtual_intf = brcmf_cfg80211_add_iface,
  4484. .del_virtual_intf = brcmf_cfg80211_del_iface,
  4485. .change_virtual_intf = brcmf_cfg80211_change_iface,
  4486. .scan = brcmf_cfg80211_scan,
  4487. .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
  4488. .join_ibss = brcmf_cfg80211_join_ibss,
  4489. .leave_ibss = brcmf_cfg80211_leave_ibss,
  4490. .get_station = brcmf_cfg80211_get_station,
  4491. .dump_station = brcmf_cfg80211_dump_station,
  4492. .set_tx_power = brcmf_cfg80211_set_tx_power,
  4493. .get_tx_power = brcmf_cfg80211_get_tx_power,
  4494. .add_key = brcmf_cfg80211_add_key,
  4495. .del_key = brcmf_cfg80211_del_key,
  4496. .get_key = brcmf_cfg80211_get_key,
  4497. .set_default_key = brcmf_cfg80211_config_default_key,
  4498. .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
  4499. .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
  4500. .connect = brcmf_cfg80211_connect,
  4501. .disconnect = brcmf_cfg80211_disconnect,
  4502. .suspend = brcmf_cfg80211_suspend,
  4503. .resume = brcmf_cfg80211_resume,
  4504. .set_pmksa = brcmf_cfg80211_set_pmksa,
  4505. .del_pmksa = brcmf_cfg80211_del_pmksa,
  4506. .flush_pmksa = brcmf_cfg80211_flush_pmksa,
  4507. .start_ap = brcmf_cfg80211_start_ap,
  4508. .stop_ap = brcmf_cfg80211_stop_ap,
  4509. .change_beacon = brcmf_cfg80211_change_beacon,
  4510. .del_station = brcmf_cfg80211_del_station,
  4511. .change_station = brcmf_cfg80211_change_station,
  4512. .sched_scan_start = brcmf_cfg80211_sched_scan_start,
  4513. .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
  4514. .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
  4515. .mgmt_tx = brcmf_cfg80211_mgmt_tx,
  4516. .remain_on_channel = brcmf_p2p_remain_on_channel,
  4517. .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
  4518. .get_channel = brcmf_cfg80211_get_channel,
  4519. .start_p2p_device = brcmf_p2p_start_device,
  4520. .stop_p2p_device = brcmf_p2p_stop_device,
  4521. .crit_proto_start = brcmf_cfg80211_crit_proto_start,
  4522. .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
  4523. .tdls_oper = brcmf_cfg80211_tdls_oper,
  4524. .update_connect_params = brcmf_cfg80211_update_conn_params,
  4525. .set_pmk = brcmf_cfg80211_set_pmk,
  4526. .del_pmk = brcmf_cfg80211_del_pmk,
  4527. };
  4528. struct cfg80211_ops *brcmf_cfg80211_get_ops(struct brcmf_mp_device *settings)
  4529. {
  4530. struct cfg80211_ops *ops;
  4531. ops = kmemdup(&brcmf_cfg80211_ops, sizeof(brcmf_cfg80211_ops),
  4532. GFP_KERNEL);
  4533. if (ops && settings->roamoff)
  4534. ops->update_connect_params = NULL;
  4535. return ops;
  4536. }
  4537. struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
  4538. enum nl80211_iftype type)
  4539. {
  4540. struct brcmf_cfg80211_vif *vif_walk;
  4541. struct brcmf_cfg80211_vif *vif;
  4542. bool mbss;
  4543. brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
  4544. sizeof(*vif));
  4545. vif = kzalloc(sizeof(*vif), GFP_KERNEL);
  4546. if (!vif)
  4547. return ERR_PTR(-ENOMEM);
  4548. vif->wdev.wiphy = cfg->wiphy;
  4549. vif->wdev.iftype = type;
  4550. brcmf_init_prof(&vif->profile);
  4551. if (type == NL80211_IFTYPE_AP) {
  4552. mbss = false;
  4553. list_for_each_entry(vif_walk, &cfg->vif_list, list) {
  4554. if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) {
  4555. mbss = true;
  4556. break;
  4557. }
  4558. }
  4559. vif->mbss = mbss;
  4560. }
  4561. list_add_tail(&vif->list, &cfg->vif_list);
  4562. return vif;
  4563. }
  4564. void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
  4565. {
  4566. list_del(&vif->list);
  4567. kfree(vif);
  4568. }
  4569. void brcmf_cfg80211_free_netdev(struct net_device *ndev)
  4570. {
  4571. struct brcmf_cfg80211_vif *vif;
  4572. struct brcmf_if *ifp;
  4573. ifp = netdev_priv(ndev);
  4574. vif = ifp->vif;
  4575. if (vif)
  4576. brcmf_free_vif(vif);
  4577. }
  4578. static bool brcmf_is_linkup(struct brcmf_cfg80211_vif *vif,
  4579. const struct brcmf_event_msg *e)
  4580. {
  4581. u32 event = e->event_code;
  4582. u32 status = e->status;
  4583. if (vif->profile.use_fwsup == BRCMF_PROFILE_FWSUP_PSK &&
  4584. event == BRCMF_E_PSK_SUP &&
  4585. status == BRCMF_E_STATUS_FWSUP_COMPLETED)
  4586. set_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &vif->sme_state);
  4587. if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
  4588. brcmf_dbg(CONN, "Processing set ssid\n");
  4589. memcpy(vif->profile.bssid, e->addr, ETH_ALEN);
  4590. if (vif->profile.use_fwsup != BRCMF_PROFILE_FWSUP_PSK)
  4591. return true;
  4592. set_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &vif->sme_state);
  4593. }
  4594. if (test_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &vif->sme_state) &&
  4595. test_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &vif->sme_state)) {
  4596. clear_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &vif->sme_state);
  4597. clear_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &vif->sme_state);
  4598. return true;
  4599. }
  4600. return false;
  4601. }
  4602. static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
  4603. {
  4604. u32 event = e->event_code;
  4605. u16 flags = e->flags;
  4606. if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
  4607. (event == BRCMF_E_DISASSOC_IND) ||
  4608. ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
  4609. brcmf_dbg(CONN, "Processing link down\n");
  4610. return true;
  4611. }
  4612. return false;
  4613. }
  4614. static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
  4615. const struct brcmf_event_msg *e)
  4616. {
  4617. u32 event = e->event_code;
  4618. u32 status = e->status;
  4619. if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
  4620. brcmf_dbg(CONN, "Processing Link %s & no network found\n",
  4621. e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
  4622. return true;
  4623. }
  4624. if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
  4625. brcmf_dbg(CONN, "Processing connecting & no network found\n");
  4626. return true;
  4627. }
  4628. if (event == BRCMF_E_PSK_SUP &&
  4629. status != BRCMF_E_STATUS_FWSUP_COMPLETED) {
  4630. brcmf_dbg(CONN, "Processing failed supplicant state: %u\n",
  4631. status);
  4632. return true;
  4633. }
  4634. return false;
  4635. }
  4636. static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
  4637. {
  4638. struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
  4639. kfree(conn_info->req_ie);
  4640. conn_info->req_ie = NULL;
  4641. conn_info->req_ie_len = 0;
  4642. kfree(conn_info->resp_ie);
  4643. conn_info->resp_ie = NULL;
  4644. conn_info->resp_ie_len = 0;
  4645. }
  4646. static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
  4647. struct brcmf_if *ifp)
  4648. {
  4649. struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
  4650. struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
  4651. u32 req_len;
  4652. u32 resp_len;
  4653. s32 err = 0;
  4654. brcmf_clear_assoc_ies(cfg);
  4655. err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
  4656. cfg->extra_buf, WL_ASSOC_INFO_MAX);
  4657. if (err) {
  4658. brcmf_err("could not get assoc info (%d)\n", err);
  4659. return err;
  4660. }
  4661. assoc_info =
  4662. (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
  4663. req_len = le32_to_cpu(assoc_info->req_len);
  4664. resp_len = le32_to_cpu(assoc_info->resp_len);
  4665. if (req_len) {
  4666. err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
  4667. cfg->extra_buf,
  4668. WL_ASSOC_INFO_MAX);
  4669. if (err) {
  4670. brcmf_err("could not get assoc req (%d)\n", err);
  4671. return err;
  4672. }
  4673. conn_info->req_ie_len = req_len;
  4674. conn_info->req_ie =
  4675. kmemdup(cfg->extra_buf, conn_info->req_ie_len,
  4676. GFP_KERNEL);
  4677. if (!conn_info->req_ie)
  4678. conn_info->req_ie_len = 0;
  4679. } else {
  4680. conn_info->req_ie_len = 0;
  4681. conn_info->req_ie = NULL;
  4682. }
  4683. if (resp_len) {
  4684. err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
  4685. cfg->extra_buf,
  4686. WL_ASSOC_INFO_MAX);
  4687. if (err) {
  4688. brcmf_err("could not get assoc resp (%d)\n", err);
  4689. return err;
  4690. }
  4691. conn_info->resp_ie_len = resp_len;
  4692. conn_info->resp_ie =
  4693. kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
  4694. GFP_KERNEL);
  4695. if (!conn_info->resp_ie)
  4696. conn_info->resp_ie_len = 0;
  4697. } else {
  4698. conn_info->resp_ie_len = 0;
  4699. conn_info->resp_ie = NULL;
  4700. }
  4701. brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
  4702. conn_info->req_ie_len, conn_info->resp_ie_len);
  4703. return err;
  4704. }
  4705. static s32
  4706. brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
  4707. struct net_device *ndev,
  4708. const struct brcmf_event_msg *e)
  4709. {
  4710. struct brcmf_if *ifp = netdev_priv(ndev);
  4711. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  4712. struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
  4713. struct wiphy *wiphy = cfg_to_wiphy(cfg);
  4714. struct ieee80211_channel *notify_channel = NULL;
  4715. struct ieee80211_supported_band *band;
  4716. struct brcmf_bss_info_le *bi;
  4717. struct brcmu_chan ch;
  4718. struct cfg80211_roam_info roam_info = {};
  4719. u32 freq;
  4720. s32 err = 0;
  4721. u8 *buf;
  4722. brcmf_dbg(TRACE, "Enter\n");
  4723. brcmf_get_assoc_ies(cfg, ifp);
  4724. memcpy(profile->bssid, e->addr, ETH_ALEN);
  4725. brcmf_update_bss_info(cfg, ifp);
  4726. buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
  4727. if (buf == NULL) {
  4728. err = -ENOMEM;
  4729. goto done;
  4730. }
  4731. /* data sent to dongle has to be little endian */
  4732. *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
  4733. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
  4734. buf, WL_BSS_INFO_MAX);
  4735. if (err)
  4736. goto done;
  4737. bi = (struct brcmf_bss_info_le *)(buf + 4);
  4738. ch.chspec = le16_to_cpu(bi->chanspec);
  4739. cfg->d11inf.decchspec(&ch);
  4740. if (ch.band == BRCMU_CHAN_BAND_2G)
  4741. band = wiphy->bands[NL80211_BAND_2GHZ];
  4742. else
  4743. band = wiphy->bands[NL80211_BAND_5GHZ];
  4744. freq = ieee80211_channel_to_frequency(ch.control_ch_num, band->band);
  4745. notify_channel = ieee80211_get_channel(wiphy, freq);
  4746. done:
  4747. kfree(buf);
  4748. roam_info.channel = notify_channel;
  4749. roam_info.bssid = profile->bssid;
  4750. roam_info.req_ie = conn_info->req_ie;
  4751. roam_info.req_ie_len = conn_info->req_ie_len;
  4752. roam_info.resp_ie = conn_info->resp_ie;
  4753. roam_info.resp_ie_len = conn_info->resp_ie_len;
  4754. cfg80211_roamed(ndev, &roam_info, GFP_KERNEL);
  4755. brcmf_dbg(CONN, "Report roaming result\n");
  4756. set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
  4757. brcmf_dbg(TRACE, "Exit\n");
  4758. return err;
  4759. }
  4760. static s32
  4761. brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
  4762. struct net_device *ndev, const struct brcmf_event_msg *e,
  4763. bool completed)
  4764. {
  4765. struct brcmf_if *ifp = netdev_priv(ndev);
  4766. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  4767. struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
  4768. struct cfg80211_connect_resp_params conn_params;
  4769. brcmf_dbg(TRACE, "Enter\n");
  4770. if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
  4771. &ifp->vif->sme_state)) {
  4772. memset(&conn_params, 0, sizeof(conn_params));
  4773. if (completed) {
  4774. brcmf_get_assoc_ies(cfg, ifp);
  4775. brcmf_update_bss_info(cfg, ifp);
  4776. set_bit(BRCMF_VIF_STATUS_CONNECTED,
  4777. &ifp->vif->sme_state);
  4778. conn_params.status = WLAN_STATUS_SUCCESS;
  4779. } else {
  4780. conn_params.status = WLAN_STATUS_AUTH_TIMEOUT;
  4781. }
  4782. conn_params.bssid = profile->bssid;
  4783. conn_params.req_ie = conn_info->req_ie;
  4784. conn_params.req_ie_len = conn_info->req_ie_len;
  4785. conn_params.resp_ie = conn_info->resp_ie;
  4786. conn_params.resp_ie_len = conn_info->resp_ie_len;
  4787. cfg80211_connect_done(ndev, &conn_params, GFP_KERNEL);
  4788. brcmf_dbg(CONN, "Report connect result - connection %s\n",
  4789. completed ? "succeeded" : "failed");
  4790. }
  4791. brcmf_dbg(TRACE, "Exit\n");
  4792. return 0;
  4793. }
  4794. static s32
  4795. brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
  4796. struct net_device *ndev,
  4797. const struct brcmf_event_msg *e, void *data)
  4798. {
  4799. static int generation;
  4800. u32 event = e->event_code;
  4801. u32 reason = e->reason;
  4802. struct station_info *sinfo;
  4803. brcmf_dbg(CONN, "event %s (%u), reason %d\n",
  4804. brcmf_fweh_event_name(event), event, reason);
  4805. if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
  4806. ndev != cfg_to_ndev(cfg)) {
  4807. brcmf_dbg(CONN, "AP mode link down\n");
  4808. complete(&cfg->vif_disabled);
  4809. return 0;
  4810. }
  4811. if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
  4812. (reason == BRCMF_E_STATUS_SUCCESS)) {
  4813. if (!data) {
  4814. brcmf_err("No IEs present in ASSOC/REASSOC_IND");
  4815. return -EINVAL;
  4816. }
  4817. sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
  4818. if (!sinfo)
  4819. return -ENOMEM;
  4820. sinfo->assoc_req_ies = data;
  4821. sinfo->assoc_req_ies_len = e->datalen;
  4822. generation++;
  4823. sinfo->generation = generation;
  4824. cfg80211_new_sta(ndev, e->addr, sinfo, GFP_KERNEL);
  4825. kfree(sinfo);
  4826. } else if ((event == BRCMF_E_DISASSOC_IND) ||
  4827. (event == BRCMF_E_DEAUTH_IND) ||
  4828. (event == BRCMF_E_DEAUTH)) {
  4829. cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
  4830. }
  4831. return 0;
  4832. }
  4833. static s32
  4834. brcmf_notify_connect_status(struct brcmf_if *ifp,
  4835. const struct brcmf_event_msg *e, void *data)
  4836. {
  4837. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  4838. struct net_device *ndev = ifp->ndev;
  4839. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  4840. struct ieee80211_channel *chan;
  4841. s32 err = 0;
  4842. if ((e->event_code == BRCMF_E_DEAUTH) ||
  4843. (e->event_code == BRCMF_E_DEAUTH_IND) ||
  4844. (e->event_code == BRCMF_E_DISASSOC_IND) ||
  4845. ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
  4846. brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
  4847. }
  4848. if (brcmf_is_apmode(ifp->vif)) {
  4849. err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
  4850. } else if (brcmf_is_linkup(ifp->vif, e)) {
  4851. brcmf_dbg(CONN, "Linkup\n");
  4852. if (brcmf_is_ibssmode(ifp->vif)) {
  4853. brcmf_inform_ibss(cfg, ndev, e->addr);
  4854. chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
  4855. memcpy(profile->bssid, e->addr, ETH_ALEN);
  4856. cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
  4857. clear_bit(BRCMF_VIF_STATUS_CONNECTING,
  4858. &ifp->vif->sme_state);
  4859. set_bit(BRCMF_VIF_STATUS_CONNECTED,
  4860. &ifp->vif->sme_state);
  4861. } else
  4862. brcmf_bss_connect_done(cfg, ndev, e, true);
  4863. brcmf_net_setcarrier(ifp, true);
  4864. } else if (brcmf_is_linkdown(e)) {
  4865. brcmf_dbg(CONN, "Linkdown\n");
  4866. if (!brcmf_is_ibssmode(ifp->vif)) {
  4867. brcmf_bss_connect_done(cfg, ndev, e, false);
  4868. brcmf_link_down(ifp->vif,
  4869. brcmf_map_fw_linkdown_reason(e));
  4870. brcmf_init_prof(ndev_to_prof(ndev));
  4871. if (ndev != cfg_to_ndev(cfg))
  4872. complete(&cfg->vif_disabled);
  4873. brcmf_net_setcarrier(ifp, false);
  4874. }
  4875. } else if (brcmf_is_nonetwork(cfg, e)) {
  4876. if (brcmf_is_ibssmode(ifp->vif))
  4877. clear_bit(BRCMF_VIF_STATUS_CONNECTING,
  4878. &ifp->vif->sme_state);
  4879. else
  4880. brcmf_bss_connect_done(cfg, ndev, e, false);
  4881. }
  4882. return err;
  4883. }
  4884. static s32
  4885. brcmf_notify_roaming_status(struct brcmf_if *ifp,
  4886. const struct brcmf_event_msg *e, void *data)
  4887. {
  4888. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  4889. u32 event = e->event_code;
  4890. u32 status = e->status;
  4891. if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
  4892. if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
  4893. &ifp->vif->sme_state)) {
  4894. brcmf_bss_roaming_done(cfg, ifp->ndev, e);
  4895. } else {
  4896. brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
  4897. brcmf_net_setcarrier(ifp, true);
  4898. }
  4899. }
  4900. return 0;
  4901. }
  4902. static s32
  4903. brcmf_notify_mic_status(struct brcmf_if *ifp,
  4904. const struct brcmf_event_msg *e, void *data)
  4905. {
  4906. u16 flags = e->flags;
  4907. enum nl80211_key_type key_type;
  4908. if (flags & BRCMF_EVENT_MSG_GROUP)
  4909. key_type = NL80211_KEYTYPE_GROUP;
  4910. else
  4911. key_type = NL80211_KEYTYPE_PAIRWISE;
  4912. cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
  4913. NULL, GFP_KERNEL);
  4914. return 0;
  4915. }
  4916. static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
  4917. const struct brcmf_event_msg *e, void *data)
  4918. {
  4919. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  4920. struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
  4921. struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
  4922. struct brcmf_cfg80211_vif *vif;
  4923. brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfgidx %u\n",
  4924. ifevent->action, ifevent->flags, ifevent->ifidx,
  4925. ifevent->bsscfgidx);
  4926. spin_lock(&event->vif_event_lock);
  4927. event->action = ifevent->action;
  4928. vif = event->vif;
  4929. switch (ifevent->action) {
  4930. case BRCMF_E_IF_ADD:
  4931. /* waiting process may have timed out */
  4932. if (!cfg->vif_event.vif) {
  4933. spin_unlock(&event->vif_event_lock);
  4934. return -EBADF;
  4935. }
  4936. ifp->vif = vif;
  4937. vif->ifp = ifp;
  4938. if (ifp->ndev) {
  4939. vif->wdev.netdev = ifp->ndev;
  4940. ifp->ndev->ieee80211_ptr = &vif->wdev;
  4941. SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
  4942. }
  4943. spin_unlock(&event->vif_event_lock);
  4944. wake_up(&event->vif_wq);
  4945. return 0;
  4946. case BRCMF_E_IF_DEL:
  4947. spin_unlock(&event->vif_event_lock);
  4948. /* event may not be upon user request */
  4949. if (brcmf_cfg80211_vif_event_armed(cfg))
  4950. wake_up(&event->vif_wq);
  4951. return 0;
  4952. case BRCMF_E_IF_CHANGE:
  4953. spin_unlock(&event->vif_event_lock);
  4954. wake_up(&event->vif_wq);
  4955. return 0;
  4956. default:
  4957. spin_unlock(&event->vif_event_lock);
  4958. break;
  4959. }
  4960. return -EINVAL;
  4961. }
  4962. static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
  4963. {
  4964. conf->frag_threshold = (u32)-1;
  4965. conf->rts_threshold = (u32)-1;
  4966. conf->retry_short = (u32)-1;
  4967. conf->retry_long = (u32)-1;
  4968. }
  4969. static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
  4970. {
  4971. brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
  4972. brcmf_notify_connect_status);
  4973. brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
  4974. brcmf_notify_connect_status);
  4975. brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
  4976. brcmf_notify_connect_status);
  4977. brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
  4978. brcmf_notify_connect_status);
  4979. brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
  4980. brcmf_notify_connect_status);
  4981. brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
  4982. brcmf_notify_connect_status);
  4983. brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
  4984. brcmf_notify_roaming_status);
  4985. brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
  4986. brcmf_notify_mic_status);
  4987. brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
  4988. brcmf_notify_connect_status);
  4989. brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
  4990. brcmf_notify_sched_scan_results);
  4991. brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
  4992. brcmf_notify_vif_event);
  4993. brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
  4994. brcmf_p2p_notify_rx_mgmt_p2p_probereq);
  4995. brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
  4996. brcmf_p2p_notify_listen_complete);
  4997. brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
  4998. brcmf_p2p_notify_action_frame_rx);
  4999. brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
  5000. brcmf_p2p_notify_action_tx_complete);
  5001. brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
  5002. brcmf_p2p_notify_action_tx_complete);
  5003. brcmf_fweh_register(cfg->pub, BRCMF_E_PSK_SUP,
  5004. brcmf_notify_connect_status);
  5005. }
  5006. static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
  5007. {
  5008. kfree(cfg->conf);
  5009. cfg->conf = NULL;
  5010. kfree(cfg->extra_buf);
  5011. cfg->extra_buf = NULL;
  5012. kfree(cfg->wowl.nd);
  5013. cfg->wowl.nd = NULL;
  5014. kfree(cfg->wowl.nd_info);
  5015. cfg->wowl.nd_info = NULL;
  5016. kfree(cfg->escan_info.escan_buf);
  5017. cfg->escan_info.escan_buf = NULL;
  5018. }
  5019. static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
  5020. {
  5021. cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
  5022. if (!cfg->conf)
  5023. goto init_priv_mem_out;
  5024. cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
  5025. if (!cfg->extra_buf)
  5026. goto init_priv_mem_out;
  5027. cfg->wowl.nd = kzalloc(sizeof(*cfg->wowl.nd) + sizeof(u32), GFP_KERNEL);
  5028. if (!cfg->wowl.nd)
  5029. goto init_priv_mem_out;
  5030. cfg->wowl.nd_info = kzalloc(sizeof(*cfg->wowl.nd_info) +
  5031. sizeof(struct cfg80211_wowlan_nd_match *),
  5032. GFP_KERNEL);
  5033. if (!cfg->wowl.nd_info)
  5034. goto init_priv_mem_out;
  5035. cfg->escan_info.escan_buf = kzalloc(BRCMF_ESCAN_BUF_SIZE, GFP_KERNEL);
  5036. if (!cfg->escan_info.escan_buf)
  5037. goto init_priv_mem_out;
  5038. return 0;
  5039. init_priv_mem_out:
  5040. brcmf_deinit_priv_mem(cfg);
  5041. return -ENOMEM;
  5042. }
  5043. static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
  5044. {
  5045. s32 err = 0;
  5046. cfg->scan_request = NULL;
  5047. cfg->pwr_save = true;
  5048. cfg->dongle_up = false; /* dongle is not up yet */
  5049. err = brcmf_init_priv_mem(cfg);
  5050. if (err)
  5051. return err;
  5052. brcmf_register_event_handlers(cfg);
  5053. mutex_init(&cfg->usr_sync);
  5054. brcmf_init_escan(cfg);
  5055. brcmf_init_conf(cfg->conf);
  5056. init_completion(&cfg->vif_disabled);
  5057. return err;
  5058. }
  5059. static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
  5060. {
  5061. cfg->dongle_up = false; /* dongle down */
  5062. brcmf_abort_scanning(cfg);
  5063. brcmf_deinit_priv_mem(cfg);
  5064. }
  5065. static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
  5066. {
  5067. init_waitqueue_head(&event->vif_wq);
  5068. spin_lock_init(&event->vif_event_lock);
  5069. }
  5070. static s32 brcmf_dongle_roam(struct brcmf_if *ifp)
  5071. {
  5072. s32 err;
  5073. u32 bcn_timeout;
  5074. __le32 roamtrigger[2];
  5075. __le32 roam_delta[2];
  5076. /* Configure beacon timeout value based upon roaming setting */
  5077. if (ifp->drvr->settings->roamoff)
  5078. bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF;
  5079. else
  5080. bcn_timeout = BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON;
  5081. err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
  5082. if (err) {
  5083. brcmf_err("bcn_timeout error (%d)\n", err);
  5084. goto roam_setup_done;
  5085. }
  5086. /* Enable/Disable built-in roaming to allow supplicant to take care of
  5087. * roaming.
  5088. */
  5089. brcmf_dbg(INFO, "Internal Roaming = %s\n",
  5090. ifp->drvr->settings->roamoff ? "Off" : "On");
  5091. err = brcmf_fil_iovar_int_set(ifp, "roam_off",
  5092. ifp->drvr->settings->roamoff);
  5093. if (err) {
  5094. brcmf_err("roam_off error (%d)\n", err);
  5095. goto roam_setup_done;
  5096. }
  5097. roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
  5098. roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
  5099. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
  5100. (void *)roamtrigger, sizeof(roamtrigger));
  5101. if (err) {
  5102. brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
  5103. goto roam_setup_done;
  5104. }
  5105. roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
  5106. roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
  5107. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
  5108. (void *)roam_delta, sizeof(roam_delta));
  5109. if (err) {
  5110. brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
  5111. goto roam_setup_done;
  5112. }
  5113. roam_setup_done:
  5114. return err;
  5115. }
  5116. static s32
  5117. brcmf_dongle_scantime(struct brcmf_if *ifp)
  5118. {
  5119. s32 err = 0;
  5120. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
  5121. BRCMF_SCAN_CHANNEL_TIME);
  5122. if (err) {
  5123. brcmf_err("Scan assoc time error (%d)\n", err);
  5124. goto dongle_scantime_out;
  5125. }
  5126. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
  5127. BRCMF_SCAN_UNASSOC_TIME);
  5128. if (err) {
  5129. brcmf_err("Scan unassoc time error (%d)\n", err);
  5130. goto dongle_scantime_out;
  5131. }
  5132. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
  5133. BRCMF_SCAN_PASSIVE_TIME);
  5134. if (err) {
  5135. brcmf_err("Scan passive time error (%d)\n", err);
  5136. goto dongle_scantime_out;
  5137. }
  5138. dongle_scantime_out:
  5139. return err;
  5140. }
  5141. static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
  5142. struct brcmu_chan *ch)
  5143. {
  5144. u32 ht40_flag;
  5145. ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
  5146. if (ch->sb == BRCMU_CHAN_SB_U) {
  5147. if (ht40_flag == IEEE80211_CHAN_NO_HT40)
  5148. channel->flags &= ~IEEE80211_CHAN_NO_HT40;
  5149. channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
  5150. } else {
  5151. /* It should be one of
  5152. * IEEE80211_CHAN_NO_HT40 or
  5153. * IEEE80211_CHAN_NO_HT40PLUS
  5154. */
  5155. channel->flags &= ~IEEE80211_CHAN_NO_HT40;
  5156. if (ht40_flag == IEEE80211_CHAN_NO_HT40)
  5157. channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
  5158. }
  5159. }
  5160. static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
  5161. u32 bw_cap[])
  5162. {
  5163. struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
  5164. struct ieee80211_supported_band *band;
  5165. struct ieee80211_channel *channel;
  5166. struct wiphy *wiphy;
  5167. struct brcmf_chanspec_list *list;
  5168. struct brcmu_chan ch;
  5169. int err;
  5170. u8 *pbuf;
  5171. u32 i, j;
  5172. u32 total;
  5173. u32 chaninfo;
  5174. pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
  5175. if (pbuf == NULL)
  5176. return -ENOMEM;
  5177. list = (struct brcmf_chanspec_list *)pbuf;
  5178. err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
  5179. BRCMF_DCMD_MEDLEN);
  5180. if (err) {
  5181. brcmf_err("get chanspecs error (%d)\n", err);
  5182. goto fail_pbuf;
  5183. }
  5184. wiphy = cfg_to_wiphy(cfg);
  5185. band = wiphy->bands[NL80211_BAND_2GHZ];
  5186. if (band)
  5187. for (i = 0; i < band->n_channels; i++)
  5188. band->channels[i].flags = IEEE80211_CHAN_DISABLED;
  5189. band = wiphy->bands[NL80211_BAND_5GHZ];
  5190. if (band)
  5191. for (i = 0; i < band->n_channels; i++)
  5192. band->channels[i].flags = IEEE80211_CHAN_DISABLED;
  5193. total = le32_to_cpu(list->count);
  5194. for (i = 0; i < total; i++) {
  5195. ch.chspec = (u16)le32_to_cpu(list->element[i]);
  5196. cfg->d11inf.decchspec(&ch);
  5197. if (ch.band == BRCMU_CHAN_BAND_2G) {
  5198. band = wiphy->bands[NL80211_BAND_2GHZ];
  5199. } else if (ch.band == BRCMU_CHAN_BAND_5G) {
  5200. band = wiphy->bands[NL80211_BAND_5GHZ];
  5201. } else {
  5202. brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
  5203. continue;
  5204. }
  5205. if (!band)
  5206. continue;
  5207. if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
  5208. ch.bw == BRCMU_CHAN_BW_40)
  5209. continue;
  5210. if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
  5211. ch.bw == BRCMU_CHAN_BW_80)
  5212. continue;
  5213. channel = NULL;
  5214. for (j = 0; j < band->n_channels; j++) {
  5215. if (band->channels[j].hw_value == ch.control_ch_num) {
  5216. channel = &band->channels[j];
  5217. break;
  5218. }
  5219. }
  5220. if (!channel) {
  5221. /* It seems firmware supports some channel we never
  5222. * considered. Something new in IEEE standard?
  5223. */
  5224. brcmf_err("Ignoring unexpected firmware channel %d\n",
  5225. ch.control_ch_num);
  5226. continue;
  5227. }
  5228. if (channel->orig_flags & IEEE80211_CHAN_DISABLED)
  5229. continue;
  5230. /* assuming the chanspecs order is HT20,
  5231. * HT40 upper, HT40 lower, and VHT80.
  5232. */
  5233. if (ch.bw == BRCMU_CHAN_BW_80) {
  5234. channel->flags &= ~IEEE80211_CHAN_NO_80MHZ;
  5235. } else if (ch.bw == BRCMU_CHAN_BW_40) {
  5236. brcmf_update_bw40_channel_flag(channel, &ch);
  5237. } else {
  5238. /* enable the channel and disable other bandwidths
  5239. * for now as mentioned order assure they are enabled
  5240. * for subsequent chanspecs.
  5241. */
  5242. channel->flags = IEEE80211_CHAN_NO_HT40 |
  5243. IEEE80211_CHAN_NO_80MHZ |
  5244. IEEE80211_CHAN_NO_160MHZ;
  5245. ch.bw = BRCMU_CHAN_BW_20;
  5246. cfg->d11inf.encchspec(&ch);
  5247. chaninfo = ch.chspec;
  5248. err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
  5249. &chaninfo);
  5250. if (!err) {
  5251. if (chaninfo & WL_CHAN_RADAR)
  5252. channel->flags |=
  5253. (IEEE80211_CHAN_RADAR |
  5254. IEEE80211_CHAN_NO_IR);
  5255. if (chaninfo & WL_CHAN_PASSIVE)
  5256. channel->flags |=
  5257. IEEE80211_CHAN_NO_IR;
  5258. }
  5259. }
  5260. }
  5261. fail_pbuf:
  5262. kfree(pbuf);
  5263. return err;
  5264. }
  5265. static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
  5266. {
  5267. struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
  5268. struct ieee80211_supported_band *band;
  5269. struct brcmf_fil_bwcap_le band_bwcap;
  5270. struct brcmf_chanspec_list *list;
  5271. u8 *pbuf;
  5272. u32 val;
  5273. int err;
  5274. struct brcmu_chan ch;
  5275. u32 num_chan;
  5276. int i, j;
  5277. /* verify support for bw_cap command */
  5278. val = WLC_BAND_5G;
  5279. err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
  5280. if (!err) {
  5281. /* only set 2G bandwidth using bw_cap command */
  5282. band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
  5283. band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
  5284. err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
  5285. sizeof(band_bwcap));
  5286. } else {
  5287. brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
  5288. val = WLC_N_BW_40ALL;
  5289. err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
  5290. }
  5291. if (!err) {
  5292. /* update channel info in 2G band */
  5293. pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
  5294. if (pbuf == NULL)
  5295. return -ENOMEM;
  5296. ch.band = BRCMU_CHAN_BAND_2G;
  5297. ch.bw = BRCMU_CHAN_BW_40;
  5298. ch.sb = BRCMU_CHAN_SB_NONE;
  5299. ch.chnum = 0;
  5300. cfg->d11inf.encchspec(&ch);
  5301. /* pass encoded chanspec in query */
  5302. *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
  5303. err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
  5304. BRCMF_DCMD_MEDLEN);
  5305. if (err) {
  5306. brcmf_err("get chanspecs error (%d)\n", err);
  5307. kfree(pbuf);
  5308. return err;
  5309. }
  5310. band = cfg_to_wiphy(cfg)->bands[NL80211_BAND_2GHZ];
  5311. list = (struct brcmf_chanspec_list *)pbuf;
  5312. num_chan = le32_to_cpu(list->count);
  5313. for (i = 0; i < num_chan; i++) {
  5314. ch.chspec = (u16)le32_to_cpu(list->element[i]);
  5315. cfg->d11inf.decchspec(&ch);
  5316. if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
  5317. continue;
  5318. if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
  5319. continue;
  5320. for (j = 0; j < band->n_channels; j++) {
  5321. if (band->channels[j].hw_value == ch.control_ch_num)
  5322. break;
  5323. }
  5324. if (WARN_ON(j == band->n_channels))
  5325. continue;
  5326. brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
  5327. }
  5328. kfree(pbuf);
  5329. }
  5330. return err;
  5331. }
  5332. static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
  5333. {
  5334. u32 band, mimo_bwcap;
  5335. int err;
  5336. band = WLC_BAND_2G;
  5337. err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
  5338. if (!err) {
  5339. bw_cap[NL80211_BAND_2GHZ] = band;
  5340. band = WLC_BAND_5G;
  5341. err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
  5342. if (!err) {
  5343. bw_cap[NL80211_BAND_5GHZ] = band;
  5344. return;
  5345. }
  5346. WARN_ON(1);
  5347. return;
  5348. }
  5349. brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
  5350. mimo_bwcap = 0;
  5351. err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
  5352. if (err)
  5353. /* assume 20MHz if firmware does not give a clue */
  5354. mimo_bwcap = WLC_N_BW_20ALL;
  5355. switch (mimo_bwcap) {
  5356. case WLC_N_BW_40ALL:
  5357. bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
  5358. /* fall-thru */
  5359. case WLC_N_BW_20IN2G_40IN5G:
  5360. bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
  5361. /* fall-thru */
  5362. case WLC_N_BW_20ALL:
  5363. bw_cap[NL80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
  5364. bw_cap[NL80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
  5365. break;
  5366. default:
  5367. brcmf_err("invalid mimo_bw_cap value\n");
  5368. }
  5369. }
  5370. static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
  5371. u32 bw_cap[2], u32 nchain)
  5372. {
  5373. band->ht_cap.ht_supported = true;
  5374. if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
  5375. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  5376. band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  5377. }
  5378. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  5379. band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
  5380. band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  5381. band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
  5382. memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
  5383. band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  5384. }
  5385. static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
  5386. {
  5387. u16 mcs_map;
  5388. int i;
  5389. for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
  5390. mcs_map = (mcs_map << 2) | supp;
  5391. return cpu_to_le16(mcs_map);
  5392. }
  5393. static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
  5394. u32 bw_cap[2], u32 nchain, u32 txstreams,
  5395. u32 txbf_bfe_cap, u32 txbf_bfr_cap)
  5396. {
  5397. __le16 mcs_map;
  5398. /* not allowed in 2.4G band */
  5399. if (band->band == NL80211_BAND_2GHZ)
  5400. return;
  5401. band->vht_cap.vht_supported = true;
  5402. /* 80MHz is mandatory */
  5403. band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
  5404. if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
  5405. band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  5406. band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
  5407. }
  5408. /* all support 256-QAM */
  5409. mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
  5410. band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
  5411. band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
  5412. /* Beamforming support information */
  5413. if (txbf_bfe_cap & BRCMF_TXBF_SU_BFE_CAP)
  5414. band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
  5415. if (txbf_bfe_cap & BRCMF_TXBF_MU_BFE_CAP)
  5416. band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  5417. if (txbf_bfr_cap & BRCMF_TXBF_SU_BFR_CAP)
  5418. band->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
  5419. if (txbf_bfr_cap & BRCMF_TXBF_MU_BFR_CAP)
  5420. band->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
  5421. if ((txbf_bfe_cap || txbf_bfr_cap) && (txstreams > 1)) {
  5422. band->vht_cap.cap |=
  5423. (2 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
  5424. band->vht_cap.cap |= ((txstreams - 1) <<
  5425. IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
  5426. band->vht_cap.cap |=
  5427. IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
  5428. }
  5429. }
  5430. static int brcmf_setup_wiphybands(struct brcmf_cfg80211_info *cfg)
  5431. {
  5432. struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
  5433. struct wiphy *wiphy;
  5434. u32 nmode = 0;
  5435. u32 vhtmode = 0;
  5436. u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
  5437. u32 rxchain;
  5438. u32 nchain;
  5439. int err;
  5440. s32 i;
  5441. struct ieee80211_supported_band *band;
  5442. u32 txstreams = 0;
  5443. u32 txbf_bfe_cap = 0;
  5444. u32 txbf_bfr_cap = 0;
  5445. (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
  5446. err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
  5447. if (err) {
  5448. brcmf_err("nmode error (%d)\n", err);
  5449. } else {
  5450. brcmf_get_bwcap(ifp, bw_cap);
  5451. }
  5452. brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
  5453. nmode, vhtmode, bw_cap[NL80211_BAND_2GHZ],
  5454. bw_cap[NL80211_BAND_5GHZ]);
  5455. err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
  5456. if (err) {
  5457. brcmf_err("rxchain error (%d)\n", err);
  5458. nchain = 1;
  5459. } else {
  5460. for (nchain = 0; rxchain; nchain++)
  5461. rxchain = rxchain & (rxchain - 1);
  5462. }
  5463. brcmf_dbg(INFO, "nchain=%d\n", nchain);
  5464. err = brcmf_construct_chaninfo(cfg, bw_cap);
  5465. if (err) {
  5466. brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
  5467. return err;
  5468. }
  5469. if (vhtmode) {
  5470. (void)brcmf_fil_iovar_int_get(ifp, "txstreams", &txstreams);
  5471. (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfe_cap",
  5472. &txbf_bfe_cap);
  5473. (void)brcmf_fil_iovar_int_get(ifp, "txbf_bfr_cap",
  5474. &txbf_bfr_cap);
  5475. }
  5476. wiphy = cfg_to_wiphy(cfg);
  5477. for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
  5478. band = wiphy->bands[i];
  5479. if (band == NULL)
  5480. continue;
  5481. if (nmode)
  5482. brcmf_update_ht_cap(band, bw_cap, nchain);
  5483. if (vhtmode)
  5484. brcmf_update_vht_cap(band, bw_cap, nchain, txstreams,
  5485. txbf_bfe_cap, txbf_bfr_cap);
  5486. }
  5487. return 0;
  5488. }
  5489. static const struct ieee80211_txrx_stypes
  5490. brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
  5491. [NL80211_IFTYPE_STATION] = {
  5492. .tx = 0xffff,
  5493. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  5494. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  5495. },
  5496. [NL80211_IFTYPE_P2P_CLIENT] = {
  5497. .tx = 0xffff,
  5498. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  5499. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  5500. },
  5501. [NL80211_IFTYPE_P2P_GO] = {
  5502. .tx = 0xffff,
  5503. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  5504. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  5505. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  5506. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  5507. BIT(IEEE80211_STYPE_AUTH >> 4) |
  5508. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  5509. BIT(IEEE80211_STYPE_ACTION >> 4)
  5510. },
  5511. [NL80211_IFTYPE_P2P_DEVICE] = {
  5512. .tx = 0xffff,
  5513. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  5514. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  5515. },
  5516. [NL80211_IFTYPE_AP] = {
  5517. .tx = 0xffff,
  5518. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  5519. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  5520. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  5521. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  5522. BIT(IEEE80211_STYPE_AUTH >> 4) |
  5523. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  5524. BIT(IEEE80211_STYPE_ACTION >> 4)
  5525. }
  5526. };
  5527. /**
  5528. * brcmf_setup_ifmodes() - determine interface modes and combinations.
  5529. *
  5530. * @wiphy: wiphy object.
  5531. * @ifp: interface object needed for feat module api.
  5532. *
  5533. * The interface modes and combinations are determined dynamically here
  5534. * based on firmware functionality.
  5535. *
  5536. * no p2p and no mbss:
  5537. *
  5538. * #STA <= 1, #AP <= 1, channels = 1, 2 total
  5539. *
  5540. * no p2p and mbss:
  5541. *
  5542. * #STA <= 1, #AP <= 1, channels = 1, 2 total
  5543. * #AP <= 4, matching BI, channels = 1, 4 total
  5544. *
  5545. * p2p, no mchan, and mbss:
  5546. *
  5547. * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 1, 3 total
  5548. * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
  5549. * #AP <= 4, matching BI, channels = 1, 4 total
  5550. *
  5551. * p2p, mchan, and mbss:
  5552. *
  5553. * #STA <= 1, #P2P-DEV <= 1, #{P2P-CL, P2P-GO} <= 1, channels = 2, 3 total
  5554. * #STA <= 1, #P2P-DEV <= 1, #AP <= 1, #P2P-CL <= 1, channels = 1, 4 total
  5555. * #AP <= 4, matching BI, channels = 1, 4 total
  5556. */
  5557. static int brcmf_setup_ifmodes(struct wiphy *wiphy, struct brcmf_if *ifp)
  5558. {
  5559. struct ieee80211_iface_combination *combo = NULL;
  5560. struct ieee80211_iface_limit *c0_limits = NULL;
  5561. struct ieee80211_iface_limit *p2p_limits = NULL;
  5562. struct ieee80211_iface_limit *mbss_limits = NULL;
  5563. bool mbss, p2p;
  5564. int i, c, n_combos;
  5565. mbss = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS);
  5566. p2p = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_P2P);
  5567. n_combos = 1 + !!p2p + !!mbss;
  5568. combo = kcalloc(n_combos, sizeof(*combo), GFP_KERNEL);
  5569. if (!combo)
  5570. goto err;
  5571. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  5572. BIT(NL80211_IFTYPE_ADHOC) |
  5573. BIT(NL80211_IFTYPE_AP);
  5574. c = 0;
  5575. i = 0;
  5576. c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL);
  5577. if (!c0_limits)
  5578. goto err;
  5579. c0_limits[i].max = 1;
  5580. c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
  5581. if (p2p) {
  5582. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
  5583. combo[c].num_different_channels = 2;
  5584. else
  5585. combo[c].num_different_channels = 1;
  5586. wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT) |
  5587. BIT(NL80211_IFTYPE_P2P_GO) |
  5588. BIT(NL80211_IFTYPE_P2P_DEVICE);
  5589. c0_limits[i].max = 1;
  5590. c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
  5591. c0_limits[i].max = 1;
  5592. c0_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
  5593. BIT(NL80211_IFTYPE_P2P_GO);
  5594. } else {
  5595. combo[c].num_different_channels = 1;
  5596. c0_limits[i].max = 1;
  5597. c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
  5598. }
  5599. combo[c].max_interfaces = i;
  5600. combo[c].n_limits = i;
  5601. combo[c].limits = c0_limits;
  5602. if (p2p) {
  5603. c++;
  5604. i = 0;
  5605. p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL);
  5606. if (!p2p_limits)
  5607. goto err;
  5608. p2p_limits[i].max = 1;
  5609. p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
  5610. p2p_limits[i].max = 1;
  5611. p2p_limits[i++].types = BIT(NL80211_IFTYPE_AP);
  5612. p2p_limits[i].max = 1;
  5613. p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT);
  5614. p2p_limits[i].max = 1;
  5615. p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
  5616. combo[c].num_different_channels = 1;
  5617. combo[c].max_interfaces = i;
  5618. combo[c].n_limits = i;
  5619. combo[c].limits = p2p_limits;
  5620. }
  5621. if (mbss) {
  5622. c++;
  5623. i = 0;
  5624. mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL);
  5625. if (!mbss_limits)
  5626. goto err;
  5627. mbss_limits[i].max = 4;
  5628. mbss_limits[i++].types = BIT(NL80211_IFTYPE_AP);
  5629. combo[c].beacon_int_infra_match = true;
  5630. combo[c].num_different_channels = 1;
  5631. combo[c].max_interfaces = 4;
  5632. combo[c].n_limits = i;
  5633. combo[c].limits = mbss_limits;
  5634. }
  5635. wiphy->n_iface_combinations = n_combos;
  5636. wiphy->iface_combinations = combo;
  5637. return 0;
  5638. err:
  5639. kfree(c0_limits);
  5640. kfree(p2p_limits);
  5641. kfree(mbss_limits);
  5642. kfree(combo);
  5643. return -ENOMEM;
  5644. }
  5645. #ifdef CONFIG_PM
  5646. static const struct wiphy_wowlan_support brcmf_wowlan_support = {
  5647. .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
  5648. .n_patterns = BRCMF_WOWL_MAXPATTERNS,
  5649. .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
  5650. .pattern_min_len = 1,
  5651. .max_pkt_offset = 1500,
  5652. };
  5653. #endif
  5654. static void brcmf_wiphy_wowl_params(struct wiphy *wiphy, struct brcmf_if *ifp)
  5655. {
  5656. #ifdef CONFIG_PM
  5657. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  5658. struct wiphy_wowlan_support *wowl;
  5659. wowl = kmemdup(&brcmf_wowlan_support, sizeof(brcmf_wowlan_support),
  5660. GFP_KERNEL);
  5661. if (!wowl) {
  5662. brcmf_err("only support basic wowlan features\n");
  5663. wiphy->wowlan = &brcmf_wowlan_support;
  5664. return;
  5665. }
  5666. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
  5667. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ND)) {
  5668. wowl->flags |= WIPHY_WOWLAN_NET_DETECT;
  5669. wowl->max_nd_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
  5670. init_waitqueue_head(&cfg->wowl.nd_data_wait);
  5671. }
  5672. }
  5673. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) {
  5674. wowl->flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY;
  5675. wowl->flags |= WIPHY_WOWLAN_GTK_REKEY_FAILURE;
  5676. }
  5677. wiphy->wowlan = wowl;
  5678. #endif
  5679. }
  5680. static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
  5681. {
  5682. struct brcmf_pub *drvr = ifp->drvr;
  5683. const struct ieee80211_iface_combination *combo;
  5684. struct ieee80211_supported_band *band;
  5685. u16 max_interfaces = 0;
  5686. bool gscan;
  5687. __le32 bandlist[3];
  5688. u32 n_bands;
  5689. int err, i;
  5690. wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
  5691. wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
  5692. wiphy->max_num_pmkids = BRCMF_MAXPMKID;
  5693. err = brcmf_setup_ifmodes(wiphy, ifp);
  5694. if (err)
  5695. return err;
  5696. for (i = 0, combo = wiphy->iface_combinations;
  5697. i < wiphy->n_iface_combinations; i++, combo++) {
  5698. max_interfaces = max(max_interfaces, combo->max_interfaces);
  5699. }
  5700. for (i = 0; i < max_interfaces && i < ARRAY_SIZE(drvr->addresses);
  5701. i++) {
  5702. u8 *addr = drvr->addresses[i].addr;
  5703. memcpy(addr, drvr->mac, ETH_ALEN);
  5704. if (i) {
  5705. addr[0] |= BIT(1);
  5706. addr[ETH_ALEN - 1] ^= i;
  5707. }
  5708. }
  5709. wiphy->addresses = drvr->addresses;
  5710. wiphy->n_addresses = i;
  5711. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  5712. wiphy->cipher_suites = brcmf_cipher_suites;
  5713. wiphy->n_cipher_suites = ARRAY_SIZE(brcmf_cipher_suites);
  5714. if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MFP))
  5715. wiphy->n_cipher_suites--;
  5716. wiphy->bss_select_support = BIT(NL80211_BSS_SELECT_ATTR_RSSI) |
  5717. BIT(NL80211_BSS_SELECT_ATTR_BAND_PREF) |
  5718. BIT(NL80211_BSS_SELECT_ATTR_RSSI_ADJUST);
  5719. wiphy->flags |= WIPHY_FLAG_NETNS_OK |
  5720. WIPHY_FLAG_PS_ON_BY_DEFAULT |
  5721. WIPHY_FLAG_HAVE_AP_SME |
  5722. WIPHY_FLAG_OFFCHAN_TX |
  5723. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  5724. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS))
  5725. wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  5726. if (!ifp->drvr->settings->roamoff)
  5727. wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
  5728. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_FWSUP)) {
  5729. wiphy_ext_feature_set(wiphy,
  5730. NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK);
  5731. wiphy_ext_feature_set(wiphy,
  5732. NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X);
  5733. }
  5734. wiphy->mgmt_stypes = brcmf_txrx_stypes;
  5735. wiphy->max_remain_on_channel_duration = 5000;
  5736. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
  5737. gscan = brcmf_feat_is_enabled(ifp, BRCMF_FEAT_GSCAN);
  5738. brcmf_pno_wiphy_params(wiphy, gscan);
  5739. }
  5740. /* vendor commands/events support */
  5741. wiphy->vendor_commands = brcmf_vendor_cmds;
  5742. wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
  5743. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
  5744. brcmf_wiphy_wowl_params(wiphy, ifp);
  5745. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BANDLIST, &bandlist,
  5746. sizeof(bandlist));
  5747. if (err) {
  5748. brcmf_err("could not obtain band info: err=%d\n", err);
  5749. return err;
  5750. }
  5751. /* first entry in bandlist is number of bands */
  5752. n_bands = le32_to_cpu(bandlist[0]);
  5753. for (i = 1; i <= n_bands && i < ARRAY_SIZE(bandlist); i++) {
  5754. if (bandlist[i] == cpu_to_le32(WLC_BAND_2G)) {
  5755. band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
  5756. GFP_KERNEL);
  5757. if (!band)
  5758. return -ENOMEM;
  5759. band->channels = kmemdup(&__wl_2ghz_channels,
  5760. sizeof(__wl_2ghz_channels),
  5761. GFP_KERNEL);
  5762. if (!band->channels) {
  5763. kfree(band);
  5764. return -ENOMEM;
  5765. }
  5766. band->n_channels = ARRAY_SIZE(__wl_2ghz_channels);
  5767. wiphy->bands[NL80211_BAND_2GHZ] = band;
  5768. }
  5769. if (bandlist[i] == cpu_to_le32(WLC_BAND_5G)) {
  5770. band = kmemdup(&__wl_band_5ghz, sizeof(__wl_band_5ghz),
  5771. GFP_KERNEL);
  5772. if (!band)
  5773. return -ENOMEM;
  5774. band->channels = kmemdup(&__wl_5ghz_channels,
  5775. sizeof(__wl_5ghz_channels),
  5776. GFP_KERNEL);
  5777. if (!band->channels) {
  5778. kfree(band);
  5779. return -ENOMEM;
  5780. }
  5781. band->n_channels = ARRAY_SIZE(__wl_5ghz_channels);
  5782. wiphy->bands[NL80211_BAND_5GHZ] = band;
  5783. }
  5784. }
  5785. wiphy_read_of_freq_limits(wiphy);
  5786. return 0;
  5787. }
  5788. static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
  5789. {
  5790. struct net_device *ndev;
  5791. struct wireless_dev *wdev;
  5792. struct brcmf_if *ifp;
  5793. s32 power_mode;
  5794. s32 err = 0;
  5795. if (cfg->dongle_up)
  5796. return err;
  5797. ndev = cfg_to_ndev(cfg);
  5798. wdev = ndev->ieee80211_ptr;
  5799. ifp = netdev_priv(ndev);
  5800. /* make sure RF is ready for work */
  5801. brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
  5802. brcmf_dongle_scantime(ifp);
  5803. power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
  5804. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
  5805. if (err)
  5806. goto default_conf_out;
  5807. brcmf_dbg(INFO, "power save set to %s\n",
  5808. (power_mode ? "enabled" : "disabled"));
  5809. err = brcmf_dongle_roam(ifp);
  5810. if (err)
  5811. goto default_conf_out;
  5812. err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
  5813. NULL);
  5814. if (err)
  5815. goto default_conf_out;
  5816. brcmf_configure_arp_nd_offload(ifp, true);
  5817. cfg->dongle_up = true;
  5818. default_conf_out:
  5819. return err;
  5820. }
  5821. static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
  5822. {
  5823. set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
  5824. return brcmf_config_dongle(ifp->drvr->config);
  5825. }
  5826. static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
  5827. {
  5828. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  5829. /*
  5830. * While going down, if associated with AP disassociate
  5831. * from AP to save power
  5832. */
  5833. if (check_vif_up(ifp->vif)) {
  5834. brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED);
  5835. /* Make sure WPA_Supplicant receives all the event
  5836. generated due to DISASSOC call to the fw to keep
  5837. the state fw and WPA_Supplicant state consistent
  5838. */
  5839. brcmf_delay(500);
  5840. }
  5841. brcmf_abort_scanning(cfg);
  5842. clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
  5843. return 0;
  5844. }
  5845. s32 brcmf_cfg80211_up(struct net_device *ndev)
  5846. {
  5847. struct brcmf_if *ifp = netdev_priv(ndev);
  5848. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  5849. s32 err = 0;
  5850. mutex_lock(&cfg->usr_sync);
  5851. err = __brcmf_cfg80211_up(ifp);
  5852. mutex_unlock(&cfg->usr_sync);
  5853. return err;
  5854. }
  5855. s32 brcmf_cfg80211_down(struct net_device *ndev)
  5856. {
  5857. struct brcmf_if *ifp = netdev_priv(ndev);
  5858. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  5859. s32 err = 0;
  5860. mutex_lock(&cfg->usr_sync);
  5861. err = __brcmf_cfg80211_down(ifp);
  5862. mutex_unlock(&cfg->usr_sync);
  5863. return err;
  5864. }
  5865. enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
  5866. {
  5867. struct wireless_dev *wdev = &ifp->vif->wdev;
  5868. return wdev->iftype;
  5869. }
  5870. bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
  5871. unsigned long state)
  5872. {
  5873. struct brcmf_cfg80211_vif *vif;
  5874. list_for_each_entry(vif, &cfg->vif_list, list) {
  5875. if (test_bit(state, &vif->sme_state))
  5876. return true;
  5877. }
  5878. return false;
  5879. }
  5880. static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
  5881. u8 action)
  5882. {
  5883. u8 evt_action;
  5884. spin_lock(&event->vif_event_lock);
  5885. evt_action = event->action;
  5886. spin_unlock(&event->vif_event_lock);
  5887. return evt_action == action;
  5888. }
  5889. void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
  5890. struct brcmf_cfg80211_vif *vif)
  5891. {
  5892. struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
  5893. spin_lock(&event->vif_event_lock);
  5894. event->vif = vif;
  5895. event->action = 0;
  5896. spin_unlock(&event->vif_event_lock);
  5897. }
  5898. bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
  5899. {
  5900. struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
  5901. bool armed;
  5902. spin_lock(&event->vif_event_lock);
  5903. armed = event->vif != NULL;
  5904. spin_unlock(&event->vif_event_lock);
  5905. return armed;
  5906. }
  5907. int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,
  5908. u8 action, ulong timeout)
  5909. {
  5910. struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
  5911. return wait_event_timeout(event->vif_wq,
  5912. vif_event_equals(event, action), timeout);
  5913. }
  5914. static s32 brcmf_translate_country_code(struct brcmf_pub *drvr, char alpha2[2],
  5915. struct brcmf_fil_country_le *ccreq)
  5916. {
  5917. struct brcmfmac_pd_cc *country_codes;
  5918. struct brcmfmac_pd_cc_entry *cc;
  5919. s32 found_index;
  5920. int i;
  5921. country_codes = drvr->settings->country_codes;
  5922. if (!country_codes) {
  5923. brcmf_dbg(TRACE, "No country codes configured for device\n");
  5924. return -EINVAL;
  5925. }
  5926. if ((alpha2[0] == ccreq->country_abbrev[0]) &&
  5927. (alpha2[1] == ccreq->country_abbrev[1])) {
  5928. brcmf_dbg(TRACE, "Country code already set\n");
  5929. return -EAGAIN;
  5930. }
  5931. found_index = -1;
  5932. for (i = 0; i < country_codes->table_size; i++) {
  5933. cc = &country_codes->table[i];
  5934. if ((cc->iso3166[0] == '\0') && (found_index == -1))
  5935. found_index = i;
  5936. if ((cc->iso3166[0] == alpha2[0]) &&
  5937. (cc->iso3166[1] == alpha2[1])) {
  5938. found_index = i;
  5939. break;
  5940. }
  5941. }
  5942. if (found_index == -1) {
  5943. brcmf_dbg(TRACE, "No country code match found\n");
  5944. return -EINVAL;
  5945. }
  5946. memset(ccreq, 0, sizeof(*ccreq));
  5947. ccreq->rev = cpu_to_le32(country_codes->table[found_index].rev);
  5948. memcpy(ccreq->ccode, country_codes->table[found_index].cc,
  5949. BRCMF_COUNTRY_BUF_SZ);
  5950. ccreq->country_abbrev[0] = alpha2[0];
  5951. ccreq->country_abbrev[1] = alpha2[1];
  5952. ccreq->country_abbrev[2] = 0;
  5953. return 0;
  5954. }
  5955. static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
  5956. struct regulatory_request *req)
  5957. {
  5958. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  5959. struct brcmf_if *ifp = brcmf_get_ifp(cfg->pub, 0);
  5960. struct brcmf_fil_country_le ccreq;
  5961. s32 err;
  5962. int i;
  5963. /* The country code gets set to "00" by default at boot, ignore */
  5964. if (req->alpha2[0] == '0' && req->alpha2[1] == '0')
  5965. return;
  5966. /* ignore non-ISO3166 country codes */
  5967. for (i = 0; i < 2; i++)
  5968. if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') {
  5969. brcmf_err("not an ISO3166 code (0x%02x 0x%02x)\n",
  5970. req->alpha2[0], req->alpha2[1]);
  5971. return;
  5972. }
  5973. brcmf_dbg(TRACE, "Enter: initiator=%d, alpha=%c%c\n", req->initiator,
  5974. req->alpha2[0], req->alpha2[1]);
  5975. err = brcmf_fil_iovar_data_get(ifp, "country", &ccreq, sizeof(ccreq));
  5976. if (err) {
  5977. brcmf_err("Country code iovar returned err = %d\n", err);
  5978. return;
  5979. }
  5980. err = brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccreq);
  5981. if (err)
  5982. return;
  5983. err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq));
  5984. if (err) {
  5985. brcmf_err("Firmware rejected country setting\n");
  5986. return;
  5987. }
  5988. brcmf_setup_wiphybands(cfg);
  5989. }
  5990. static void brcmf_free_wiphy(struct wiphy *wiphy)
  5991. {
  5992. int i;
  5993. if (!wiphy)
  5994. return;
  5995. if (wiphy->iface_combinations) {
  5996. for (i = 0; i < wiphy->n_iface_combinations; i++)
  5997. kfree(wiphy->iface_combinations[i].limits);
  5998. }
  5999. kfree(wiphy->iface_combinations);
  6000. if (wiphy->bands[NL80211_BAND_2GHZ]) {
  6001. kfree(wiphy->bands[NL80211_BAND_2GHZ]->channels);
  6002. kfree(wiphy->bands[NL80211_BAND_2GHZ]);
  6003. }
  6004. if (wiphy->bands[NL80211_BAND_5GHZ]) {
  6005. kfree(wiphy->bands[NL80211_BAND_5GHZ]->channels);
  6006. kfree(wiphy->bands[NL80211_BAND_5GHZ]);
  6007. }
  6008. #if IS_ENABLED(CONFIG_PM)
  6009. if (wiphy->wowlan != &brcmf_wowlan_support)
  6010. kfree(wiphy->wowlan);
  6011. #endif
  6012. }
  6013. struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
  6014. struct cfg80211_ops *ops,
  6015. bool p2pdev_forced)
  6016. {
  6017. struct wiphy *wiphy = drvr->wiphy;
  6018. struct net_device *ndev = brcmf_get_ifp(drvr, 0)->ndev;
  6019. struct brcmf_cfg80211_info *cfg;
  6020. struct brcmf_cfg80211_vif *vif;
  6021. struct brcmf_if *ifp;
  6022. s32 err = 0;
  6023. s32 io_type;
  6024. u16 *cap = NULL;
  6025. if (!ndev) {
  6026. brcmf_err("ndev is invalid\n");
  6027. return NULL;
  6028. }
  6029. cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
  6030. if (!cfg) {
  6031. brcmf_err("Could not allocate wiphy device\n");
  6032. return NULL;
  6033. }
  6034. cfg->wiphy = wiphy;
  6035. cfg->pub = drvr;
  6036. init_vif_event(&cfg->vif_event);
  6037. INIT_LIST_HEAD(&cfg->vif_list);
  6038. vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION);
  6039. if (IS_ERR(vif))
  6040. goto wiphy_out;
  6041. ifp = netdev_priv(ndev);
  6042. vif->ifp = ifp;
  6043. vif->wdev.netdev = ndev;
  6044. ndev->ieee80211_ptr = &vif->wdev;
  6045. SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
  6046. err = wl_init_priv(cfg);
  6047. if (err) {
  6048. brcmf_err("Failed to init iwm_priv (%d)\n", err);
  6049. brcmf_free_vif(vif);
  6050. goto wiphy_out;
  6051. }
  6052. ifp->vif = vif;
  6053. /* determine d11 io type before wiphy setup */
  6054. err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
  6055. if (err) {
  6056. brcmf_err("Failed to get D11 version (%d)\n", err);
  6057. goto priv_out;
  6058. }
  6059. cfg->d11inf.io_type = (u8)io_type;
  6060. brcmu_d11_attach(&cfg->d11inf);
  6061. /* regulatory notifer below needs access to cfg so
  6062. * assign it now.
  6063. */
  6064. drvr->config = cfg;
  6065. err = brcmf_setup_wiphy(wiphy, ifp);
  6066. if (err < 0)
  6067. goto priv_out;
  6068. brcmf_dbg(INFO, "Registering custom regulatory\n");
  6069. wiphy->reg_notifier = brcmf_cfg80211_reg_notifier;
  6070. wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
  6071. wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
  6072. /* firmware defaults to 40MHz disabled in 2G band. We signal
  6073. * cfg80211 here that we do and have it decide we can enable
  6074. * it. But first check if device does support 2G operation.
  6075. */
  6076. if (wiphy->bands[NL80211_BAND_2GHZ]) {
  6077. cap = &wiphy->bands[NL80211_BAND_2GHZ]->ht_cap.cap;
  6078. *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  6079. }
  6080. #ifdef CONFIG_PM
  6081. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK))
  6082. ops->set_rekey_data = brcmf_cfg80211_set_rekey_data;
  6083. #endif
  6084. err = wiphy_register(wiphy);
  6085. if (err < 0) {
  6086. brcmf_err("Could not register wiphy device (%d)\n", err);
  6087. goto priv_out;
  6088. }
  6089. err = brcmf_setup_wiphybands(cfg);
  6090. if (err) {
  6091. brcmf_err("Setting wiphy bands failed (%d)\n", err);
  6092. goto wiphy_unreg_out;
  6093. }
  6094. /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
  6095. * setup 40MHz in 2GHz band and enable OBSS scanning.
  6096. */
  6097. if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
  6098. err = brcmf_enable_bw40_2g(cfg);
  6099. if (!err)
  6100. err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
  6101. BRCMF_OBSS_COEX_AUTO);
  6102. else
  6103. *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  6104. }
  6105. err = brcmf_fweh_activate_events(ifp);
  6106. if (err) {
  6107. brcmf_err("FWEH activation failed (%d)\n", err);
  6108. goto wiphy_unreg_out;
  6109. }
  6110. err = brcmf_p2p_attach(cfg, p2pdev_forced);
  6111. if (err) {
  6112. brcmf_err("P2P initialisation failed (%d)\n", err);
  6113. goto wiphy_unreg_out;
  6114. }
  6115. err = brcmf_btcoex_attach(cfg);
  6116. if (err) {
  6117. brcmf_err("BT-coex initialisation failed (%d)\n", err);
  6118. brcmf_p2p_detach(&cfg->p2p);
  6119. goto wiphy_unreg_out;
  6120. }
  6121. err = brcmf_pno_attach(cfg);
  6122. if (err) {
  6123. brcmf_err("PNO initialisation failed (%d)\n", err);
  6124. brcmf_btcoex_detach(cfg);
  6125. brcmf_p2p_detach(&cfg->p2p);
  6126. goto wiphy_unreg_out;
  6127. }
  6128. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_TDLS)) {
  6129. err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
  6130. if (err) {
  6131. brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
  6132. wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
  6133. } else {
  6134. brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
  6135. brcmf_notify_tdls_peer_event);
  6136. }
  6137. }
  6138. /* (re-) activate FWEH event handling */
  6139. err = brcmf_fweh_activate_events(ifp);
  6140. if (err) {
  6141. brcmf_err("FWEH activation failed (%d)\n", err);
  6142. goto detach;
  6143. }
  6144. /* Fill in some of the advertised nl80211 supported features */
  6145. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_RANDOM_MAC)) {
  6146. wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
  6147. #ifdef CONFIG_PM
  6148. if (wiphy->wowlan &&
  6149. wiphy->wowlan->flags & WIPHY_WOWLAN_NET_DETECT)
  6150. wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
  6151. #endif
  6152. }
  6153. return cfg;
  6154. detach:
  6155. brcmf_pno_detach(cfg);
  6156. brcmf_btcoex_detach(cfg);
  6157. brcmf_p2p_detach(&cfg->p2p);
  6158. wiphy_unreg_out:
  6159. wiphy_unregister(cfg->wiphy);
  6160. priv_out:
  6161. wl_deinit_priv(cfg);
  6162. brcmf_free_vif(vif);
  6163. ifp->vif = NULL;
  6164. wiphy_out:
  6165. brcmf_free_wiphy(wiphy);
  6166. kfree(cfg);
  6167. return NULL;
  6168. }
  6169. void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
  6170. {
  6171. if (!cfg)
  6172. return;
  6173. brcmf_pno_detach(cfg);
  6174. brcmf_btcoex_detach(cfg);
  6175. wiphy_unregister(cfg->wiphy);
  6176. kfree(cfg->ops);
  6177. wl_deinit_priv(cfg);
  6178. brcmf_free_wiphy(cfg->wiphy);
  6179. kfree(cfg);
  6180. }