cfg80211.c 189 KB

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