cfg80211.c 163 KB

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