cfg80211.c 189 KB

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