wl_android.c 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143
  1. /*
  2. * Linux cfg80211 driver - Android related functions
  3. *
  4. * Copyright (C) 1999-2014, Broadcom Corporation
  5. *
  6. * Unless you and Broadcom execute a separate written software license
  7. * agreement governing use of this software, this software is licensed to you
  8. * under the terms of the GNU General Public License version 2 (the "GPL"),
  9. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  10. * following added to such license:
  11. *
  12. * As a special exception, the copyright holders of this software give you
  13. * permission to link this software with independent modules, and to copy and
  14. * distribute the resulting executable under terms of your choice, provided that
  15. * you also meet, for each linked independent module, the terms and conditions of
  16. * the license of that module. An independent module is a module which is not
  17. * derived from this software. The special exception does not apply to any
  18. * modifications of the software.
  19. *
  20. * Notwithstanding the above, under no circumstances may you combine this
  21. * software in any way with any other Broadcom software provided under a license
  22. * other than the GPL, without Broadcom's express prior written consent.
  23. *
  24. * $Id: wl_android.c 517113 2014-11-24 06:29:50Z $
  25. */
  26. #include <linux/module.h>
  27. #include <linux/netdevice.h>
  28. #include <net/netlink.h>
  29. #ifdef CONFIG_COMPAT
  30. #include <linux/compat.h>
  31. #endif
  32. #include <wl_android.h>
  33. #include <wldev_common.h>
  34. #include <wlioctl.h>
  35. #include <bcmutils.h>
  36. #include <linux_osl.h>
  37. #include <dhd_dbg.h>
  38. #include <dngl_stats.h>
  39. #include <dhd.h>
  40. #include <proto/bcmip.h>
  41. #ifdef PNO_SUPPORT
  42. #include <dhd_pno.h>
  43. #endif
  44. #include <bcmsdbus.h>
  45. #ifdef WL_CFG80211
  46. #include <wl_cfg80211.h>
  47. #endif
  48. /*
  49. * Android private command strings, PLEASE define new private commands here
  50. * so they can be updated easily in the future (if needed)
  51. */
  52. #define CMD_START "START"
  53. #define CMD_STOP "STOP"
  54. #define CMD_SCAN_ACTIVE "SCAN-ACTIVE"
  55. #define CMD_SCAN_PASSIVE "SCAN-PASSIVE"
  56. #define CMD_RSSI "RSSI"
  57. #define CMD_LINKSPEED "LINKSPEED"
  58. #define CMD_RXFILTER_START "RXFILTER-START"
  59. #define CMD_RXFILTER_STOP "RXFILTER-STOP"
  60. #define CMD_RXFILTER_ADD "RXFILTER-ADD"
  61. #define CMD_RXFILTER_REMOVE "RXFILTER-REMOVE"
  62. #define CMD_BTCOEXSCAN_START "BTCOEXSCAN-START"
  63. #define CMD_BTCOEXSCAN_STOP "BTCOEXSCAN-STOP"
  64. #define CMD_BTCOEXMODE "BTCOEXMODE"
  65. #define CMD_SETSUSPENDOPT "SETSUSPENDOPT"
  66. #define CMD_SETSUSPENDMODE "SETSUSPENDMODE"
  67. #define CMD_P2P_DEV_ADDR "P2P_DEV_ADDR"
  68. #define CMD_SETFWPATH "SETFWPATH"
  69. #define CMD_SETBAND "SETBAND"
  70. #define CMD_GETBAND "GETBAND"
  71. #define CMD_COUNTRY "COUNTRY"
  72. #define CMD_P2P_SET_NOA "P2P_SET_NOA"
  73. #if !defined WL_ENABLE_P2P_IF
  74. #define CMD_P2P_GET_NOA "P2P_GET_NOA"
  75. #endif /* WL_ENABLE_P2P_IF */
  76. #define CMD_P2P_SD_OFFLOAD "P2P_SD_"
  77. #define CMD_P2P_SET_PS "P2P_SET_PS"
  78. #define CMD_SET_AP_WPS_P2P_IE "SET_AP_WPS_P2P_IE"
  79. #define CMD_SETROAMMODE "SETROAMMODE"
  80. #define CMD_SETIBSSBEACONOUIDATA "SETIBSSBEACONOUIDATA"
  81. #define CMD_MIRACAST "MIRACAST"
  82. #if defined(WL_SUPPORT_AUTO_CHANNEL)
  83. #define CMD_GET_BEST_CHANNELS "GET_BEST_CHANNELS"
  84. #endif /* WL_SUPPORT_AUTO_CHANNEL */
  85. #ifdef CUSTOMER_HW4
  86. #ifdef WL_SUPPORT_AUTO_CHANNEL
  87. #define CMD_SET_HAPD_AUTO_CHANNEL "HAPD_AUTO_CHANNEL"
  88. #endif /* WL_SUPPORT_AUTO_CHANNEL */
  89. #ifdef SUPPORT_HIDDEN_AP
  90. /* Hostapd private command */
  91. #define CMD_SET_HAPD_MAX_NUM_STA "HAPD_MAX_NUM_STA"
  92. #define CMD_SET_HAPD_SSID "HAPD_SSID"
  93. #define CMD_SET_HAPD_HIDE_SSID "HAPD_HIDE_SSID"
  94. #endif /* SUPPORT_HIDDEN_AP */
  95. #ifdef SUPPORT_SOFTAP_SINGL_DISASSOC
  96. #define CMD_HAPD_STA_DISASSOC "HAPD_STA_DISASSOC"
  97. #endif /* SUPPORT_SOFTAP_SINGL_DISASSOC */
  98. #ifdef SUPPORT_SET_LPC
  99. #define CMD_HAPD_LPC_ENABLED "HAPD_LPC_ENABLED"
  100. #endif /* SUPPORT_SET_LPC */
  101. #ifdef SUPPORT_TRIGGER_HANG_EVENT
  102. #define CMD_TEST_FORCE_HANG "TEST_FORCE_HANG"
  103. #endif /* SUPPORT_TRIGGER_HANG_EVENT */
  104. #ifdef SUPPORT_LTECX
  105. #define CMD_LTECX_SET "LTECOEX"
  106. #endif /* SUPPORT_LTECX */
  107. #ifdef TEST_TX_POWER_CONTROL
  108. #define CMD_TEST_SET_TX_POWER "TEST_SET_TX_POWER"
  109. #define CMD_TEST_GET_TX_POWER "TEST_GET_TX_POWER"
  110. #endif /* TEST_TX_POWER_CONTROL */
  111. #ifdef TX_POWER_CONTROL_CALLING
  112. #define CMD_SET_TX_POWER_CALLING "SET_TX_POWER_CALLING"
  113. #endif /* TX_POWER_CONTROL_CALLING */
  114. #ifdef SARLIMIT_TX_CONTROL_NVRAM
  115. #define CMD_SARLIMIT_TX_CONTROL "SET_TX_POWER_CALLING"
  116. #endif /* SARLIMIT_TX_CONTROL_NVRAM */
  117. #endif /* CUSTOMER_HW4 */
  118. #ifdef WLFBT
  119. #define CMD_GET_FTKEY "GET_FTKEY"
  120. #endif
  121. #define CMD_KEEP_ALIVE "KEEPALIVE"
  122. /* CCX Private Commands */
  123. #ifdef BCMCCX
  124. #define CMD_GETCCKM_RN "get cckm_rn"
  125. #define CMD_SETCCKM_KRK "set cckm_krk"
  126. #define CMD_GET_ASSOC_RES_IES "get assoc_res_ies"
  127. #endif
  128. #ifdef PNO_SUPPORT
  129. #define CMD_PNOSSIDCLR_SET "PNOSSIDCLR"
  130. #define CMD_PNOSETUP_SET "PNOSETUP "
  131. #define CMD_PNOENABLE_SET "PNOFORCE"
  132. #define CMD_PNODEBUG_SET "PNODEBUG"
  133. #define CMD_WLS_BATCHING "WLS_BATCHING"
  134. #endif /* PNO_SUPPORT */
  135. #define CMD_OKC_SET_PMK "SET_PMK"
  136. #define CMD_OKC_ENABLE "OKC_ENABLE"
  137. #define CMD_HAPD_MAC_FILTER "HAPD_MAC_FILTER"
  138. #ifdef CUSTOMER_HW4
  139. #ifdef ROAM_API
  140. #define CMD_ROAMTRIGGER_SET "SETROAMTRIGGER"
  141. #define CMD_ROAMTRIGGER_GET "GETROAMTRIGGER"
  142. #define CMD_ROAMDELTA_SET "SETROAMDELTA"
  143. #define CMD_ROAMDELTA_GET "GETROAMDELTA"
  144. #define CMD_ROAMSCANPERIOD_SET "SETROAMSCANPERIOD"
  145. #define CMD_ROAMSCANPERIOD_GET "GETROAMSCANPERIOD"
  146. #define CMD_FULLROAMSCANPERIOD_SET "SETFULLROAMSCANPERIOD"
  147. #define CMD_FULLROAMSCANPERIOD_GET "GETFULLROAMSCANPERIOD"
  148. #define CMD_COUNTRYREV_SET "SETCOUNTRYREV"
  149. #define CMD_COUNTRYREV_GET "GETCOUNTRYREV"
  150. #endif /* ROAM_API */
  151. #ifdef WES_SUPPORT
  152. #define CMD_GETROAMSCANCONTROL "GETROAMSCANCONTROL"
  153. #define CMD_SETROAMSCANCONTROL "SETROAMSCANCONTROL"
  154. #define CMD_GETROAMSCANCHANNELS "GETROAMSCANCHANNELS"
  155. #define CMD_SETROAMSCANCHANNELS "SETROAMSCANCHANNELS"
  156. #define CMD_GETSCANCHANNELTIME "GETSCANCHANNELTIME"
  157. #define CMD_SETSCANCHANNELTIME "SETSCANCHANNELTIME"
  158. #define CMD_GETSCANHOMETIME "GETSCANHOMETIME"
  159. #define CMD_SETSCANHOMETIME "SETSCANHOMETIME"
  160. #define CMD_GETSCANHOMEAWAYTIME "GETSCANHOMEAWAYTIME"
  161. #define CMD_SETSCANHOMEAWAYTIME "SETSCANHOMEAWAYTIME"
  162. #define CMD_GETSCANNPROBES "GETSCANNPROBES"
  163. #define CMD_SETSCANNPROBES "SETSCANNPROBES"
  164. #define CMD_GETDFSSCANMODE "GETDFSSCANMODE"
  165. #define CMD_SETDFSSCANMODE "SETDFSSCANMODE"
  166. #define CMD_SENDACTIONFRAME "SENDACTIONFRAME"
  167. #define CMD_REASSOC "REASSOC"
  168. #define CMD_GETWESMODE "GETWESMODE"
  169. #define CMD_SETWESMODE "SETWESMODE"
  170. #define CMD_GETOKCMODE "GETOKCMODE"
  171. #define CMD_SETOKCMODE "SETOKCMODE"
  172. #define ANDROID_WIFI_MAX_ROAM_SCAN_CHANNELS 100
  173. typedef struct android_wifi_reassoc_params {
  174. unsigned char bssid[18];
  175. int channel;
  176. } android_wifi_reassoc_params_t;
  177. #define ANDROID_WIFI_REASSOC_PARAMS_SIZE sizeof(struct android_wifi_reassoc_params)
  178. #define ANDROID_WIFI_ACTION_FRAME_SIZE 1040
  179. typedef struct android_wifi_af_params {
  180. unsigned char bssid[18];
  181. int channel;
  182. int dwell_time;
  183. int len;
  184. unsigned char data[ANDROID_WIFI_ACTION_FRAME_SIZE];
  185. } android_wifi_af_params_t;
  186. #define ANDROID_WIFI_AF_PARAMS_SIZE sizeof(struct android_wifi_af_params)
  187. #endif /* WES_SUPPORT */
  188. #ifdef SUPPORT_AMPDU_MPDU_CMD
  189. #define CMD_AMPDU_MPDU "AMPDU_MPDU"
  190. #endif /* SUPPORT_AMPDU_MPDU_CMD */
  191. #define CMD_CHANGE_RL "CHANGE_RL"
  192. #define CMD_RESTORE_RL "RESTORE_RL"
  193. #define CMD_SET_RMC_ENABLE "SETRMCENABLE"
  194. #define CMD_SET_RMC_TXRATE "SETRMCTXRATE"
  195. #define CMD_SET_RMC_ACTPERIOD "SETRMCACTIONPERIOD"
  196. #define CMD_SET_RMC_IDLEPERIOD "SETRMCIDLEPERIOD"
  197. #define CMD_SET_RMC_LEADER "SETRMCLEADER"
  198. #define CMD_SET_RMC_EVENT "SETRMCEVENT"
  199. #define CMD_SET_SCSCAN "SETSINGLEANT"
  200. #define CMD_GET_SCSCAN "GETSINGLEANT"
  201. #endif /* CUSTOMER_HW4 */
  202. #ifdef WLAIBSS
  203. #define CMD_SETIBSSTXFAILEVENT "SETIBSSTXFAILEVENT"
  204. #define CMD_GET_IBSS_PEER_INFO "GETIBSSPEERINFO"
  205. #define CMD_GET_IBSS_PEER_INFO_ALL "GETIBSSPEERINFOALL"
  206. #define CMD_SETIBSSROUTETABLE "SETIBSSROUTETABLE"
  207. #define CMD_SETIBSSAMPDU "SETIBSSAMPDU"
  208. #define CMD_SETIBSSANTENNAMODE "SETIBSSANTENNAMODE"
  209. #endif /* WLAIBSS */
  210. #define CMD_ROAM_OFFLOAD "SETROAMOFFLOAD"
  211. /* miracast related definition */
  212. #define MIRACAST_MODE_OFF 0
  213. #define MIRACAST_MODE_SOURCE 1
  214. #define MIRACAST_MODE_SINK 2
  215. #ifndef MIRACAST_AMPDU_SIZE
  216. #define MIRACAST_AMPDU_SIZE 8
  217. #endif
  218. #ifndef MIRACAST_MCHAN_ALGO
  219. #define MIRACAST_MCHAN_ALGO 1
  220. #endif
  221. #ifndef MIRACAST_MCHAN_BW
  222. #define MIRACAST_MCHAN_BW 25
  223. #endif
  224. #ifdef CONNECTION_STATISTICS
  225. #define CMD_GET_CONNECTION_STATS "GET_CONNECTION_STATS"
  226. struct connection_stats {
  227. u32 txframe;
  228. u32 txbyte;
  229. u32 txerror;
  230. u32 rxframe;
  231. u32 rxbyte;
  232. u32 txfail;
  233. u32 txretry;
  234. u32 txretrie;
  235. u32 txrts;
  236. u32 txnocts;
  237. u32 txexptime;
  238. u32 txrate;
  239. u8 chan_idle;
  240. };
  241. #endif /* CONNECTION_STATISTICS */
  242. static LIST_HEAD(miracast_resume_list);
  243. static u8 miracast_cur_mode;
  244. struct io_cfg {
  245. s8 *iovar;
  246. s32 param;
  247. u32 ioctl;
  248. void *arg;
  249. u32 len;
  250. struct list_head list;
  251. };
  252. typedef struct _android_wifi_priv_cmd {
  253. char *buf;
  254. int used_len;
  255. int total_len;
  256. } android_wifi_priv_cmd;
  257. #ifdef CONFIG_COMPAT
  258. typedef struct _compat_android_wifi_priv_cmd {
  259. compat_caddr_t buf;
  260. int used_len;
  261. int total_len;
  262. } compat_android_wifi_priv_cmd;
  263. #endif /* CONFIG_COMPAT */
  264. #if defined(BCMFW_ROAM_ENABLE)
  265. #define CMD_SET_ROAMPREF "SET_ROAMPREF"
  266. #define MAX_NUM_SUITES 10
  267. #define WIDTH_AKM_SUITE 8
  268. #define JOIN_PREF_RSSI_LEN 0x02
  269. #define JOIN_PREF_RSSI_SIZE 4 /* RSSI pref header size in bytes */
  270. #define JOIN_PREF_WPA_HDR_SIZE 4 /* WPA pref header size in bytes */
  271. #define JOIN_PREF_WPA_TUPLE_SIZE 12 /* Tuple size in bytes */
  272. #define JOIN_PREF_MAX_WPA_TUPLES 16
  273. #define MAX_BUF_SIZE (JOIN_PREF_RSSI_SIZE + JOIN_PREF_WPA_HDR_SIZE + \
  274. (JOIN_PREF_WPA_TUPLE_SIZE * JOIN_PREF_MAX_WPA_TUPLES))
  275. #endif /* BCMFW_ROAM_ENABLE */
  276. #ifdef WL_GENL
  277. static s32 wl_genl_handle_msg(struct sk_buff *skb, struct genl_info *info);
  278. static int wl_genl_init(void);
  279. static int wl_genl_deinit(void);
  280. extern struct net init_net;
  281. /* attribute policy: defines which attribute has which type (e.g int, char * etc)
  282. * possible values defined in net/netlink.h
  283. */
  284. static struct nla_policy wl_genl_policy[BCM_GENL_ATTR_MAX + 1] = {
  285. [BCM_GENL_ATTR_STRING] = { .type = NLA_NUL_STRING },
  286. [BCM_GENL_ATTR_MSG] = { .type = NLA_BINARY },
  287. };
  288. #define WL_GENL_VER 1
  289. /* family definition */
  290. static struct genl_family wl_genl_family = {
  291. .id = GENL_ID_GENERATE, /* Genetlink would generate the ID */
  292. .hdrsize = 0,
  293. .name = "bcm-genl", /* Netlink I/F for Android */
  294. .version = WL_GENL_VER, /* Version Number */
  295. .maxattr = BCM_GENL_ATTR_MAX,
  296. };
  297. /* commands: mapping between the command enumeration and the actual function */
  298. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
  299. struct genl_ops wl_genl_ops[] = {
  300. {
  301. .cmd = BCM_GENL_CMD_MSG,
  302. .flags = 0,
  303. .policy = wl_genl_policy,
  304. .doit = wl_genl_handle_msg,
  305. .dumpit = NULL,
  306. },
  307. };
  308. #else
  309. struct genl_ops wl_genl_ops = {
  310. .cmd = BCM_GENL_CMD_MSG,
  311. .flags = 0,
  312. .policy = wl_genl_policy,
  313. .doit = wl_genl_handle_msg,
  314. .dumpit = NULL,
  315. };
  316. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) */
  317. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
  318. static struct genl_multicast_group wl_genl_mcast[] = {
  319. { .name = "bcm-genl-mcast", },
  320. };
  321. #else
  322. static struct genl_multicast_group wl_genl_mcast = {
  323. .id = GENL_ID_GENERATE, /* Genetlink would generate the ID */
  324. .name = "bcm-genl-mcast",
  325. };
  326. #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) */
  327. #endif /* WL_GENL */
  328. /**
  329. * Extern function declarations (TODO: move them to dhd_linux.h)
  330. */
  331. int dhd_net_bus_devreset(struct net_device *dev, uint8 flag);
  332. int dhd_dev_init_ioctl(struct net_device *dev);
  333. #ifdef WL_CFG80211
  334. int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr);
  335. int wl_cfg80211_set_btcoex_dhcp(struct net_device *dev, dhd_pub_t *dhd, char *command);
  336. #if defined(CUSTOMER_HW4) && defined(WES_SUPPORT)
  337. int wl_cfg80211_set_wes_mode(int mode);
  338. int wl_cfg80211_get_wes_mode(void);
  339. #endif
  340. #else
  341. int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr)
  342. { return 0; }
  343. int wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len)
  344. { return 0; }
  345. int wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len)
  346. { return 0; }
  347. int wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len)
  348. { return 0; }
  349. #endif /* WK_CFG80211 */
  350. #if defined(CUSTOMER_HW4) && defined(WES_SUPPORT)
  351. /* wl_roam.c */
  352. extern int get_roamscan_mode(struct net_device *dev, int *mode);
  353. extern int set_roamscan_mode(struct net_device *dev, int mode);
  354. extern int get_roamscan_channel_list(struct net_device *dev, unsigned char channels[]);
  355. extern int set_roamscan_channel_list(struct net_device *dev, unsigned char n,
  356. unsigned char channels[], int ioctl_ver);
  357. #endif
  358. #if defined(CUSTOMER_HW4) && defined(ROAM_CHANNEL_CACHE)
  359. extern void wl_update_roamscan_cache_by_band(struct net_device *dev, int band);
  360. #endif
  361. #ifdef ENABLE_4335BT_WAR
  362. extern int bcm_bt_lock(int cookie);
  363. extern void bcm_bt_unlock(int cookie);
  364. static int lock_cookie_wifi = 'W' | 'i'<<8 | 'F'<<16 | 'i'<<24; /* cookie is "WiFi" */
  365. #endif /* ENABLE_4335BT_WAR */
  366. extern bool ap_fw_loaded;
  367. #if defined(CUSTOMER_HW2) || defined(CUSTOMER_HW4)
  368. extern char iface_name[IFNAMSIZ];
  369. #endif /* CUSTOMER_HW2 || CUSTOMER_HW4 */
  370. /**
  371. * Local (static) functions and variables
  372. */
  373. /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
  374. * time (only) in dhd_open, subsequential wifi on will be handled by
  375. * wl_android_wifi_on
  376. */
  377. static int g_wifi_on = TRUE;
  378. /**
  379. * Local (static) function definitions
  380. */
  381. static int wl_android_get_link_speed(struct net_device *net, char *command, int total_len)
  382. {
  383. int link_speed;
  384. int bytes_written;
  385. int error;
  386. error = wldev_get_link_speed(net, &link_speed);
  387. if (error)
  388. return -1;
  389. /* Convert Kbps to Android Mbps */
  390. link_speed = link_speed / 1000;
  391. bytes_written = snprintf(command, total_len, "LinkSpeed %d", link_speed);
  392. DHD_INFO(("%s: command result is %s\n", __FUNCTION__, command));
  393. return bytes_written;
  394. }
  395. static int wl_android_get_rssi(struct net_device *net, char *command, int total_len)
  396. {
  397. wlc_ssid_t ssid = {0};
  398. int rssi;
  399. int bytes_written = 0;
  400. int error;
  401. error = wldev_get_rssi(net, &rssi);
  402. if (error)
  403. return -1;
  404. error = wldev_get_ssid(net, &ssid);
  405. if (error)
  406. return -1;
  407. if ((ssid.SSID_len == 0) || (ssid.SSID_len > DOT11_MAX_SSID_LEN)) {
  408. DHD_ERROR(("%s: wldev_get_ssid failed\n", __FUNCTION__));
  409. } else {
  410. memcpy(command, ssid.SSID, ssid.SSID_len);
  411. bytes_written = ssid.SSID_len;
  412. }
  413. bytes_written += snprintf(&command[bytes_written], total_len, " rssi %d", rssi);
  414. DHD_INFO(("%s: command result is %s (%d)\n", __FUNCTION__, command, bytes_written));
  415. return bytes_written;
  416. }
  417. static int wl_android_set_suspendopt(struct net_device *dev, char *command, int total_len)
  418. {
  419. int suspend_flag;
  420. int ret_now;
  421. int ret = 0;
  422. #ifdef CUSTOMER_HW4
  423. if (!dhd_download_fw_on_driverload) {
  424. #endif /* CUSTOMER_HW4 */
  425. suspend_flag = *(command + strlen(CMD_SETSUSPENDOPT) + 1) - '0';
  426. if (suspend_flag != 0)
  427. suspend_flag = 1;
  428. ret_now = net_os_set_suspend_disable(dev, suspend_flag);
  429. if (ret_now != suspend_flag) {
  430. if (!(ret = net_os_set_suspend(dev, ret_now, 1)))
  431. DHD_INFO(("%s: Suspend Flag %d -> %d\n",
  432. __FUNCTION__, ret_now, suspend_flag));
  433. else
  434. DHD_ERROR(("%s: failed %d\n", __FUNCTION__, ret));
  435. }
  436. #ifdef CUSTOMER_HW4
  437. }
  438. #endif /* CUSTOMER_HW4 */
  439. return ret;
  440. }
  441. static int wl_android_set_suspendmode(struct net_device *dev, char *command, int total_len)
  442. {
  443. int ret = 0;
  444. #if !defined(CONFIG_HAS_EARLYSUSPEND) || !defined(DHD_USE_EARLYSUSPEND)
  445. int suspend_flag;
  446. suspend_flag = *(command + strlen(CMD_SETSUSPENDMODE) + 1) - '0';
  447. if (suspend_flag != 0)
  448. suspend_flag = 1;
  449. if (!(ret = net_os_set_suspend(dev, suspend_flag, 0)))
  450. DHD_INFO(("%s: Suspend Mode %d\n", __FUNCTION__, suspend_flag));
  451. else
  452. DHD_ERROR(("%s: failed %d\n", __FUNCTION__, ret));
  453. #endif
  454. return ret;
  455. }
  456. static int wl_android_get_band(struct net_device *dev, char *command, int total_len)
  457. {
  458. uint band;
  459. int bytes_written;
  460. int error;
  461. error = wldev_get_band(dev, &band);
  462. if (error)
  463. return -1;
  464. bytes_written = snprintf(command, total_len, "Band %d", band);
  465. return bytes_written;
  466. }
  467. #ifdef CUSTOMER_HW4
  468. #ifdef ROAM_API
  469. int wl_android_set_roam_trigger(
  470. struct net_device *dev, char* command, int total_len)
  471. {
  472. int roam_trigger[2];
  473. sscanf(command, "%*s %10d", &roam_trigger[0]);
  474. roam_trigger[1] = WLC_BAND_ALL;
  475. return wldev_ioctl(dev, WLC_SET_ROAM_TRIGGER, roam_trigger,
  476. sizeof(roam_trigger), 1);
  477. }
  478. static int wl_android_get_roam_trigger(
  479. struct net_device *dev, char *command, int total_len)
  480. {
  481. int bytes_written;
  482. int roam_trigger[2] = {0, 0};
  483. roam_trigger[1] = WLC_BAND_2G;
  484. if (wldev_ioctl(dev, WLC_GET_ROAM_TRIGGER, roam_trigger,
  485. sizeof(roam_trigger), 0)) {
  486. roam_trigger[1] = WLC_BAND_5G;
  487. if (wldev_ioctl(dev, WLC_GET_ROAM_TRIGGER, roam_trigger,
  488. sizeof(roam_trigger), 0))
  489. return -1;
  490. }
  491. bytes_written = snprintf(command, total_len, "%s %d",
  492. CMD_ROAMTRIGGER_GET, roam_trigger[0]);
  493. return bytes_written;
  494. }
  495. int wl_android_set_roam_delta(
  496. struct net_device *dev, char* command, int total_len)
  497. {
  498. int roam_delta[2];
  499. sscanf(command, "%*s %10d", &roam_delta[0]);
  500. roam_delta[1] = WLC_BAND_ALL;
  501. return wldev_ioctl(dev, WLC_SET_ROAM_DELTA, roam_delta,
  502. sizeof(roam_delta), 1);
  503. }
  504. static int wl_android_get_roam_delta(
  505. struct net_device *dev, char *command, int total_len)
  506. {
  507. int bytes_written;
  508. int roam_delta[2] = {0, 0};
  509. roam_delta[1] = WLC_BAND_2G;
  510. if (wldev_ioctl(dev, WLC_GET_ROAM_DELTA, roam_delta,
  511. sizeof(roam_delta), 0)) {
  512. roam_delta[1] = WLC_BAND_5G;
  513. if (wldev_ioctl(dev, WLC_GET_ROAM_DELTA, roam_delta,
  514. sizeof(roam_delta), 0))
  515. return -1;
  516. }
  517. bytes_written = snprintf(command, total_len, "%s %d",
  518. CMD_ROAMDELTA_GET, roam_delta[0]);
  519. return bytes_written;
  520. }
  521. int wl_android_set_roam_scan_period(
  522. struct net_device *dev, char* command, int total_len)
  523. {
  524. int roam_scan_period = 0;
  525. sscanf(command, "%*s %10d", &roam_scan_period);
  526. return wldev_ioctl(dev, WLC_SET_ROAM_SCAN_PERIOD, &roam_scan_period,
  527. sizeof(roam_scan_period), 1);
  528. }
  529. static int wl_android_get_roam_scan_period(
  530. struct net_device *dev, char *command, int total_len)
  531. {
  532. int bytes_written;
  533. int roam_scan_period = 0;
  534. if (wldev_ioctl(dev, WLC_GET_ROAM_SCAN_PERIOD, &roam_scan_period,
  535. sizeof(roam_scan_period), 0))
  536. return -1;
  537. bytes_written = snprintf(command, total_len, "%s %d",
  538. CMD_ROAMSCANPERIOD_GET, roam_scan_period);
  539. return bytes_written;
  540. }
  541. int wl_android_set_full_roam_scan_period(
  542. struct net_device *dev, char* command, int total_len)
  543. {
  544. int error = 0;
  545. int full_roam_scan_period = 0;
  546. char smbuf[WLC_IOCTL_SMLEN];
  547. sscanf(command+sizeof("SETFULLROAMSCANPERIOD"), "%d", &full_roam_scan_period);
  548. WL_TRACE(("fullroamperiod = %d\n", full_roam_scan_period));
  549. error = wldev_iovar_setbuf(dev, "fullroamperiod", &full_roam_scan_period,
  550. sizeof(full_roam_scan_period), smbuf, sizeof(smbuf), NULL);
  551. if (error) {
  552. DHD_ERROR(("Failed to set full roam scan period, error = %d\n", error));
  553. }
  554. return error;
  555. }
  556. static int wl_android_get_full_roam_scan_period(
  557. struct net_device *dev, char *command, int total_len)
  558. {
  559. int error;
  560. int bytes_written;
  561. int full_roam_scan_period = 0;
  562. error = wldev_iovar_getint(dev, "fullroamperiod", &full_roam_scan_period);
  563. if (error) {
  564. DHD_ERROR(("%s: get full roam scan period failed code %d\n",
  565. __func__, error));
  566. return -1;
  567. } else {
  568. DHD_INFO(("%s: get full roam scan period %d\n", __func__, full_roam_scan_period));
  569. }
  570. bytes_written = snprintf(command, total_len, "%s %d",
  571. CMD_FULLROAMSCANPERIOD_GET, full_roam_scan_period);
  572. return bytes_written;
  573. }
  574. int wl_android_set_country_rev(
  575. struct net_device *dev, char* command, int total_len)
  576. {
  577. int error = 0;
  578. wl_country_t cspec = {{0}, 0, {0} };
  579. char country_code[WLC_CNTRY_BUF_SZ];
  580. char smbuf[WLC_IOCTL_SMLEN];
  581. int rev = 0;
  582. memset(country_code, 0, sizeof(country_code));
  583. sscanf(command+sizeof("SETCOUNTRYREV"), "%3s %10d", country_code, &rev);
  584. WL_TRACE(("country_code = %s, rev = %d\n", country_code, rev));
  585. memcpy(cspec.country_abbrev, country_code, sizeof(country_code));
  586. memcpy(cspec.ccode, country_code, sizeof(country_code));
  587. cspec.rev = rev;
  588. error = wldev_iovar_setbuf(dev, "country", (char *)&cspec,
  589. sizeof(cspec), smbuf, sizeof(smbuf), NULL);
  590. if (error) {
  591. DHD_ERROR(("%s: set country '%s/%d' failed code %d\n",
  592. __FUNCTION__, cspec.ccode, cspec.rev, error));
  593. } else {
  594. dhd_bus_country_set(dev, &cspec, true);
  595. DHD_INFO(("%s: set country '%s/%d'\n",
  596. __FUNCTION__, cspec.ccode, cspec.rev));
  597. }
  598. return error;
  599. }
  600. static int wl_android_get_country_rev(
  601. struct net_device *dev, char *command, int total_len)
  602. {
  603. int error;
  604. int bytes_written;
  605. char smbuf[WLC_IOCTL_SMLEN];
  606. wl_country_t cspec;
  607. error = wldev_iovar_getbuf(dev, "country", NULL, 0, smbuf,
  608. sizeof(smbuf), NULL);
  609. if (error) {
  610. DHD_ERROR(("%s: get country failed code %d\n",
  611. __FUNCTION__, error));
  612. return -1;
  613. } else {
  614. memcpy(&cspec, smbuf, sizeof(cspec));
  615. DHD_INFO(("%s: get country '%c%c %d'\n",
  616. __FUNCTION__, cspec.ccode[0], cspec.ccode[1], cspec.rev));
  617. }
  618. bytes_written = snprintf(command, total_len, "%s %c%c %d",
  619. CMD_COUNTRYREV_GET, cspec.ccode[0], cspec.ccode[1], cspec.rev);
  620. return bytes_written;
  621. }
  622. #endif /* ROAM_API */
  623. #ifdef WES_SUPPORT
  624. int wl_android_get_roam_scan_control(struct net_device *dev, char *command, int total_len)
  625. {
  626. int error = 0;
  627. int bytes_written = 0;
  628. int mode = 0;
  629. error = get_roamscan_mode(dev, &mode);
  630. if (error) {
  631. DHD_ERROR(("%s: Failed to get Scan Control, error = %d\n", __FUNCTION__, error));
  632. return -1;
  633. }
  634. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETROAMSCANCONTROL, mode);
  635. return bytes_written;
  636. }
  637. int wl_android_set_roam_scan_control(struct net_device *dev, char *command, int total_len)
  638. {
  639. int error = 0;
  640. int mode = 0;
  641. if (sscanf(command, "%*s %d", &mode) != 1) {
  642. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  643. return -1;
  644. }
  645. error = set_roamscan_mode(dev, mode);
  646. if (error) {
  647. DHD_ERROR(("%s: Failed to set Scan Control %d, error = %d\n",
  648. __FUNCTION__, mode, error));
  649. return -1;
  650. }
  651. return 0;
  652. }
  653. int wl_android_get_roam_scan_channels(struct net_device *dev, char *command, int total_len)
  654. {
  655. int bytes_written = 0;
  656. unsigned char channels[ANDROID_WIFI_MAX_ROAM_SCAN_CHANNELS] = {0};
  657. int channel_cnt = 0;
  658. char channel_info[10 + (ANDROID_WIFI_MAX_ROAM_SCAN_CHANNELS * 3)] = {0};
  659. int channel_info_len = 0;
  660. int i = 0;
  661. channel_cnt = get_roamscan_channel_list(dev, channels);
  662. channel_info_len += sprintf(&channel_info[channel_info_len], "%d ", channel_cnt);
  663. for (i = 0; i < channel_cnt; i++) {
  664. channel_info_len += sprintf(&channel_info[channel_info_len], "%d ", channels[i]);
  665. if (channel_info_len > (sizeof(channel_info) - 10))
  666. break;
  667. }
  668. channel_info_len += sprintf(&channel_info[channel_info_len], "%s", "\0");
  669. bytes_written = snprintf(command, total_len, "%s %s",
  670. CMD_GETROAMSCANCHANNELS, channel_info);
  671. return bytes_written;
  672. }
  673. int wl_android_set_roam_scan_channels(struct net_device *dev, char *command, int total_len)
  674. {
  675. int error = 0;
  676. unsigned char *p = (unsigned char *)(command + strlen(CMD_SETROAMSCANCHANNELS) + 1);
  677. int ioctl_version = wl_cfg80211_get_ioctl_version();
  678. error = set_roamscan_channel_list(dev, p[0], &p[1], ioctl_version);
  679. if (error) {
  680. DHD_ERROR(("%s: Failed to set Scan Channels %d, error = %d\n",
  681. __FUNCTION__, p[0], error));
  682. return -1;
  683. }
  684. return 0;
  685. }
  686. int wl_android_get_scan_channel_time(struct net_device *dev, char *command, int total_len)
  687. {
  688. int error = 0;
  689. int bytes_written = 0;
  690. int time = 0;
  691. error = wldev_ioctl(dev, WLC_GET_SCAN_CHANNEL_TIME, &time, sizeof(time), 0);
  692. if (error) {
  693. DHD_ERROR(("%s: Failed to get Scan Channel Time, error = %d\n",
  694. __FUNCTION__, error));
  695. return -1;
  696. }
  697. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETSCANCHANNELTIME, time);
  698. return bytes_written;
  699. }
  700. int wl_android_set_scan_channel_time(struct net_device *dev, char *command, int total_len)
  701. {
  702. int error = 0;
  703. int time = 0;
  704. if (sscanf(command, "%*s %d", &time) != 1) {
  705. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  706. return -1;
  707. }
  708. error = wldev_ioctl(dev, WLC_SET_SCAN_CHANNEL_TIME, &time, sizeof(time), 1);
  709. if (error) {
  710. DHD_ERROR(("%s: Failed to set Scan Channel Time %d, error = %d\n",
  711. __FUNCTION__, time, error));
  712. return -1;
  713. }
  714. return 0;
  715. }
  716. int wl_android_get_scan_home_time(struct net_device *dev, char *command, int total_len)
  717. {
  718. int error = 0;
  719. int bytes_written = 0;
  720. int time = 0;
  721. error = wldev_ioctl(dev, WLC_GET_SCAN_HOME_TIME, &time, sizeof(time), 0);
  722. if (error) {
  723. DHD_ERROR(("Failed to get Scan Home Time, error = %d\n", error));
  724. return -1;
  725. }
  726. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETSCANHOMETIME, time);
  727. return bytes_written;
  728. }
  729. int wl_android_set_scan_home_time(struct net_device *dev, char *command, int total_len)
  730. {
  731. int error = 0;
  732. int time = 0;
  733. if (sscanf(command, "%*s %d", &time) != 1) {
  734. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  735. return -1;
  736. }
  737. error = wldev_ioctl(dev, WLC_SET_SCAN_HOME_TIME, &time, sizeof(time), 1);
  738. if (error) {
  739. DHD_ERROR(("%s: Failed to set Scan Home Time %d, error = %d\n",
  740. __FUNCTION__, time, error));
  741. return -1;
  742. }
  743. return 0;
  744. }
  745. int wl_android_get_scan_home_away_time(struct net_device *dev, char *command, int total_len)
  746. {
  747. int error = 0;
  748. int bytes_written = 0;
  749. int time = 0;
  750. error = wldev_iovar_getint(dev, "scan_home_away_time", &time);
  751. if (error) {
  752. DHD_ERROR(("%s: Failed to get Scan Home Away Time, error = %d\n",
  753. __FUNCTION__, error));
  754. return -1;
  755. }
  756. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETSCANHOMEAWAYTIME, time);
  757. return bytes_written;
  758. }
  759. int wl_android_set_scan_home_away_time(struct net_device *dev, char *command, int total_len)
  760. {
  761. int error = 0;
  762. int time = 0;
  763. if (sscanf(command, "%*s %d", &time) != 1) {
  764. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  765. return -1;
  766. }
  767. error = wldev_iovar_setint(dev, "scan_home_away_time", time);
  768. if (error) {
  769. DHD_ERROR(("%s: Failed to set Scan Home Away Time %d, error = %d\n",
  770. __FUNCTION__, time, error));
  771. return -1;
  772. }
  773. return 0;
  774. }
  775. int wl_android_get_scan_nprobes(struct net_device *dev, char *command, int total_len)
  776. {
  777. int error = 0;
  778. int bytes_written = 0;
  779. int num = 0;
  780. error = wldev_ioctl(dev, WLC_GET_SCAN_NPROBES, &num, sizeof(num), 0);
  781. if (error) {
  782. DHD_ERROR(("%s: Failed to get Scan NProbes, error = %d\n", __FUNCTION__, error));
  783. return -1;
  784. }
  785. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETSCANNPROBES, num);
  786. return bytes_written;
  787. }
  788. int wl_android_set_scan_nprobes(struct net_device *dev, char *command, int total_len)
  789. {
  790. int error = 0;
  791. int num = 0;
  792. if (sscanf(command, "%*s %d", &num) != 1) {
  793. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  794. return -1;
  795. }
  796. error = wldev_ioctl(dev, WLC_SET_SCAN_NPROBES, &num, sizeof(num), 1);
  797. if (error) {
  798. DHD_ERROR(("%s: Failed to set Scan NProbes %d, error = %d\n",
  799. __FUNCTION__, num, error));
  800. return -1;
  801. }
  802. return 0;
  803. }
  804. int wl_android_get_scan_dfs_channel_mode(struct net_device *dev, char *command, int total_len)
  805. {
  806. int error = 0;
  807. int bytes_written = 0;
  808. int mode = 0;
  809. int scan_passive_time = 0;
  810. error = wldev_iovar_getint(dev, "scan_passive_time", &scan_passive_time);
  811. if (error) {
  812. DHD_ERROR(("%s: Failed to get Passive Time, error = %d\n", __FUNCTION__, error));
  813. return -1;
  814. }
  815. if (scan_passive_time == 0) {
  816. mode = 0;
  817. } else {
  818. mode = 1;
  819. }
  820. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETDFSSCANMODE, mode);
  821. return bytes_written;
  822. }
  823. int wl_android_set_scan_dfs_channel_mode(struct net_device *dev, char *command, int total_len)
  824. {
  825. int error = 0;
  826. int mode = 0;
  827. int scan_passive_time = 0;
  828. if (sscanf(command, "%*s %d", &mode) != 1) {
  829. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  830. return -1;
  831. }
  832. if (mode == 1) {
  833. scan_passive_time = DHD_SCAN_PASSIVE_TIME;
  834. } else if (mode == 0) {
  835. scan_passive_time = 0;
  836. } else {
  837. DHD_ERROR(("%s: Failed to set Scan DFS channel mode %d, error = %d\n",
  838. __FUNCTION__, mode, error));
  839. return -1;
  840. }
  841. error = wldev_iovar_setint(dev, "scan_passive_time", scan_passive_time);
  842. if (error) {
  843. DHD_ERROR(("%s: Failed to set Scan Passive Time %d, error = %d\n",
  844. __FUNCTION__, scan_passive_time, error));
  845. return -1;
  846. }
  847. return 0;
  848. }
  849. int wl_android_send_action_frame(struct net_device *dev, char *command, int total_len)
  850. {
  851. int error = -1;
  852. android_wifi_af_params_t *params = NULL;
  853. wl_action_frame_t *action_frame = NULL;
  854. wl_af_params_t *af_params = NULL;
  855. char *smbuf = NULL;
  856. struct ether_addr tmp_bssid;
  857. int tmp_channel = 0;
  858. params = (android_wifi_af_params_t *)(command + strlen(CMD_SENDACTIONFRAME) + 1);
  859. if (params == NULL) {
  860. DHD_ERROR(("%s: Invalid params \n", __FUNCTION__));
  861. goto send_action_frame_out;
  862. }
  863. if (params->len > ANDROID_WIFI_ACTION_FRAME_SIZE) {
  864. DHD_ERROR(("%s: Requested action frame len was out of range(%d)\n",
  865. __FUNCTION__, params->len));
  866. goto send_action_frame_out;
  867. }
  868. smbuf = kmalloc(WLC_IOCTL_MAXLEN, GFP_KERNEL);
  869. if (smbuf == NULL) {
  870. DHD_ERROR(("%s: failed to allocated memory %d bytes\n",
  871. __FUNCTION__, WLC_IOCTL_MAXLEN));
  872. goto send_action_frame_out;
  873. }
  874. af_params = (wl_af_params_t *) kzalloc(WL_WIFI_AF_PARAMS_SIZE, GFP_KERNEL);
  875. if (af_params == NULL)
  876. {
  877. DHD_ERROR(("%s: unable to allocate frame\n", __FUNCTION__));
  878. goto send_action_frame_out;
  879. }
  880. memset(&tmp_bssid, 0, ETHER_ADDR_LEN);
  881. if (bcm_ether_atoe((const char *)params->bssid, (struct ether_addr *)&tmp_bssid) == 0) {
  882. memset(&tmp_bssid, 0, ETHER_ADDR_LEN);
  883. error = wldev_ioctl(dev, WLC_GET_BSSID, &tmp_bssid, ETHER_ADDR_LEN, false);
  884. if (error) {
  885. memset(&tmp_bssid, 0, ETHER_ADDR_LEN);
  886. DHD_ERROR(("%s: failed to get bssid, error=%d\n", __FUNCTION__, error));
  887. goto send_action_frame_out;
  888. }
  889. }
  890. if (params->channel < 0) {
  891. struct channel_info ci;
  892. error = wldev_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci), false);
  893. if (error) {
  894. DHD_ERROR(("%s: failed to get channel, error=%d\n", __FUNCTION__, error));
  895. goto send_action_frame_out;
  896. }
  897. tmp_channel = ci.hw_channel;
  898. }
  899. else {
  900. tmp_channel = params->channel;
  901. }
  902. af_params->channel = tmp_channel;
  903. af_params->dwell_time = params->dwell_time;
  904. memcpy(&af_params->BSSID, &tmp_bssid, ETHER_ADDR_LEN);
  905. action_frame = &af_params->action_frame;
  906. action_frame->packetId = 0;
  907. memcpy(&action_frame->da, &tmp_bssid, ETHER_ADDR_LEN);
  908. action_frame->len = params->len;
  909. memcpy(action_frame->data, params->data, action_frame->len);
  910. error = wldev_iovar_setbuf(dev, "actframe", af_params,
  911. sizeof(wl_af_params_t), smbuf, WLC_IOCTL_MAXLEN, NULL);
  912. if (error) {
  913. DHD_ERROR(("%s: failed to set action frame, error=%d\n", __FUNCTION__, error));
  914. }
  915. send_action_frame_out:
  916. if (af_params)
  917. kfree(af_params);
  918. if (smbuf)
  919. kfree(smbuf);
  920. if (error)
  921. return -1;
  922. else
  923. return 0;
  924. }
  925. int wl_android_reassoc(struct net_device *dev, char *command, int total_len)
  926. {
  927. int error = 0;
  928. android_wifi_reassoc_params_t *params = NULL;
  929. uint band;
  930. chanspec_t channel;
  931. u32 params_size;
  932. wl_reassoc_params_t reassoc_params;
  933. params = (android_wifi_reassoc_params_t *)(command + strlen(CMD_REASSOC) + 1);
  934. if (params == NULL) {
  935. DHD_ERROR(("%s: Invalid params \n", __FUNCTION__));
  936. return -1;
  937. }
  938. memset(&reassoc_params, 0, WL_REASSOC_PARAMS_FIXED_SIZE);
  939. if (bcm_ether_atoe((const char *)params->bssid,
  940. (struct ether_addr *)&reassoc_params.bssid) == 0) {
  941. DHD_ERROR(("%s: Invalid bssid \n", __FUNCTION__));
  942. return -1;
  943. }
  944. if (params->channel < 0) {
  945. DHD_ERROR(("%s: Invalid Channel \n", __FUNCTION__));
  946. return -1;
  947. }
  948. reassoc_params.chanspec_num = 1;
  949. channel = params->channel;
  950. #ifdef D11AC_IOTYPES
  951. if (wl_cfg80211_get_ioctl_version() == 1) {
  952. band = ((channel <= CH_MAX_2G_CHANNEL) ?
  953. WL_LCHANSPEC_BAND_2G : WL_LCHANSPEC_BAND_5G);
  954. reassoc_params.chanspec_list[0] = channel |
  955. band | WL_LCHANSPEC_BW_20 | WL_LCHANSPEC_CTL_SB_NONE;
  956. }
  957. else {
  958. band = ((channel <= CH_MAX_2G_CHANNEL) ? WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G);
  959. reassoc_params.chanspec_list[0] = channel | band | WL_CHANSPEC_BW_20;
  960. }
  961. #else
  962. band = ((channel <= CH_MAX_2G_CHANNEL) ? WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G);
  963. reassoc_params.chanspec_list[0] = channel |
  964. band | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE;
  965. #endif /* D11AC_IOTYPES */
  966. params_size = WL_REASSOC_PARAMS_FIXED_SIZE + sizeof(chanspec_t);
  967. error = wldev_ioctl(dev, WLC_REASSOC, &reassoc_params, params_size, true);
  968. if (error) {
  969. DHD_ERROR(("%s: failed to reassoc, error=%d\n", __FUNCTION__, error));
  970. }
  971. if (error)
  972. return -1;
  973. else
  974. return 0;
  975. }
  976. int wl_android_get_wes_mode(struct net_device *dev, char *command, int total_len)
  977. {
  978. int bytes_written = 0;
  979. int mode = 0;
  980. mode = wl_cfg80211_get_wes_mode();
  981. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETWESMODE, mode);
  982. return bytes_written;
  983. }
  984. int wl_android_set_wes_mode(struct net_device *dev, char *command, int total_len)
  985. {
  986. int error = 0;
  987. int mode = 0;
  988. if (sscanf(command, "%*s %d", &mode) != 1) {
  989. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  990. return -1;
  991. }
  992. error = wl_cfg80211_set_wes_mode(mode);
  993. if (error) {
  994. DHD_ERROR(("%s: Failed to set WES Mode %d, error = %d\n",
  995. __FUNCTION__, mode, error));
  996. return -1;
  997. }
  998. return 0;
  999. }
  1000. int wl_android_get_okc_mode(struct net_device *dev, char *command, int total_len)
  1001. {
  1002. int error = 0;
  1003. int bytes_written = 0;
  1004. int mode = 0;
  1005. error = wldev_iovar_getint(dev, "okc_enable", &mode);
  1006. if (error) {
  1007. DHD_ERROR(("%s: Failed to get OKC Mode, error = %d\n", __FUNCTION__, error));
  1008. return -1;
  1009. }
  1010. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETOKCMODE, mode);
  1011. return bytes_written;
  1012. }
  1013. int wl_android_set_okc_mode(struct net_device *dev, char *command, int total_len)
  1014. {
  1015. int error = 0;
  1016. int mode = 0;
  1017. if (sscanf(command, "%*s %d", &mode) != 1) {
  1018. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  1019. return -1;
  1020. }
  1021. error = wldev_iovar_setint(dev, "okc_enable", mode);
  1022. if (error) {
  1023. DHD_ERROR(("%s: Failed to set OKC Mode %d, error = %d\n",
  1024. __FUNCTION__, mode, error));
  1025. return -1;
  1026. }
  1027. if (mode)
  1028. wldev_iovar_setint(dev, "ccx_enable", 0);
  1029. return error;
  1030. }
  1031. #endif /* WES_SUPPORT */
  1032. #endif /* CUSTOMER_HW4 */
  1033. #ifdef PNO_SUPPORT
  1034. #define PNO_PARAM_SIZE 50
  1035. #define VALUE_SIZE 50
  1036. #define LIMIT_STR_FMT ("%50s %50s")
  1037. static int
  1038. wls_parse_batching_cmd(struct net_device *dev, char *command, int total_len)
  1039. {
  1040. int err = BCME_OK;
  1041. uint i, tokens;
  1042. char *pos, *pos2, *token, *token2, *delim;
  1043. char param[PNO_PARAM_SIZE+1], value[VALUE_SIZE+1];
  1044. struct dhd_pno_batch_params batch_params;
  1045. DHD_PNO(("%s: command=%s, len=%d\n", __FUNCTION__, command, total_len));
  1046. if (total_len < strlen(CMD_WLS_BATCHING)) {
  1047. DHD_ERROR(("%s argument=%d less min size\n", __FUNCTION__, total_len));
  1048. err = BCME_ERROR;
  1049. goto exit;
  1050. }
  1051. pos = command + strlen(CMD_WLS_BATCHING) + 1;
  1052. memset(&batch_params, 0, sizeof(struct dhd_pno_batch_params));
  1053. if (!strncmp(pos, PNO_BATCHING_SET, strlen(PNO_BATCHING_SET))) {
  1054. pos += strlen(PNO_BATCHING_SET) + 1;
  1055. while ((token = strsep(&pos, PNO_PARAMS_DELIMETER)) != NULL) {
  1056. memset(param, 0, sizeof(param));
  1057. memset(value, 0, sizeof(value));
  1058. if (token == NULL || !*token)
  1059. break;
  1060. if (*token == '\0')
  1061. continue;
  1062. delim = strchr(token, PNO_PARAM_VALUE_DELLIMETER);
  1063. if (delim != NULL)
  1064. *delim = ' ';
  1065. tokens = sscanf(token, LIMIT_STR_FMT, param, value);
  1066. if (!strncmp(param, PNO_PARAM_SCANFREQ, strlen(PNO_PARAM_SCANFREQ))) {
  1067. batch_params.scan_fr = simple_strtol(value, NULL, 0);
  1068. DHD_PNO(("scan_freq : %d\n", batch_params.scan_fr));
  1069. } else if (!strncmp(param, PNO_PARAM_BESTN, strlen(PNO_PARAM_BESTN))) {
  1070. batch_params.bestn = simple_strtol(value, NULL, 0);
  1071. DHD_PNO(("bestn : %d\n", batch_params.bestn));
  1072. } else if (!strncmp(param, PNO_PARAM_MSCAN, strlen(PNO_PARAM_MSCAN))) {
  1073. batch_params.mscan = simple_strtol(value, NULL, 0);
  1074. DHD_PNO(("mscan : %d\n", batch_params.mscan));
  1075. } else if (!strncmp(param, PNO_PARAM_CHANNEL, strlen(PNO_PARAM_CHANNEL))) {
  1076. i = 0;
  1077. pos2 = value;
  1078. tokens = sscanf(value, "<%s>", value);
  1079. if (tokens != 1) {
  1080. err = BCME_ERROR;
  1081. DHD_ERROR(("%s : invalid format for channel"
  1082. " <> params\n", __FUNCTION__));
  1083. goto exit;
  1084. }
  1085. while ((token2 = strsep(&pos2, PNO_PARAM_CHANNEL_DELIMETER))
  1086. != NULL) {
  1087. if (token2 == NULL || !*token2)
  1088. break;
  1089. if (*token2 == '\0')
  1090. continue;
  1091. if (*token2 == 'A' || *token2 == 'B') {
  1092. batch_params.band = (*token2 == 'A')?
  1093. WLC_BAND_5G : WLC_BAND_2G;
  1094. DHD_PNO(("band : %s\n",
  1095. (*token2 == 'A')? "A" : "B"));
  1096. } else {
  1097. if ((batch_params.nchan >= WL_NUMCHANNELS) ||
  1098. (i >= WL_NUMCHANNELS)) {
  1099. DHD_ERROR(("Too many nchan %d\n",
  1100. batch_params.nchan));
  1101. err = BCME_BUFTOOSHORT;
  1102. goto exit;
  1103. }
  1104. batch_params.chan_list[i++] =
  1105. simple_strtol(token2, NULL, 0);
  1106. batch_params.nchan++;
  1107. DHD_PNO(("channel :%d\n",
  1108. batch_params.chan_list[i-1]));
  1109. }
  1110. }
  1111. } else if (!strncmp(param, PNO_PARAM_RTT, strlen(PNO_PARAM_RTT))) {
  1112. batch_params.rtt = simple_strtol(value, NULL, 0);
  1113. DHD_PNO(("rtt : %d\n", batch_params.rtt));
  1114. } else {
  1115. DHD_ERROR(("%s : unknown param: %s\n", __FUNCTION__, param));
  1116. err = BCME_ERROR;
  1117. goto exit;
  1118. }
  1119. }
  1120. err = dhd_dev_pno_set_for_batch(dev, &batch_params);
  1121. if (err < 0) {
  1122. DHD_ERROR(("failed to configure batch scan\n"));
  1123. } else {
  1124. memset(command, 0, total_len);
  1125. err = sprintf(command, "%d", err);
  1126. }
  1127. } else if (!strncmp(pos, PNO_BATCHING_GET, strlen(PNO_BATCHING_GET))) {
  1128. err = dhd_dev_pno_get_for_batch(dev, command, total_len);
  1129. if (err < 0) {
  1130. DHD_ERROR(("failed to getting batching results\n"));
  1131. } else {
  1132. err = strlen(command);
  1133. }
  1134. } else if (!strncmp(pos, PNO_BATCHING_STOP, strlen(PNO_BATCHING_STOP))) {
  1135. err = dhd_dev_pno_stop_for_batch(dev);
  1136. if (err < 0) {
  1137. DHD_ERROR(("failed to stop batching scan\n"));
  1138. } else {
  1139. memset(command, 0, total_len);
  1140. err = sprintf(command, "OK");
  1141. }
  1142. } else {
  1143. DHD_ERROR(("%s : unknown command\n", __FUNCTION__));
  1144. err = BCME_ERROR;
  1145. goto exit;
  1146. }
  1147. exit:
  1148. return err;
  1149. }
  1150. #ifndef WL_SCHED_SCAN
  1151. static int wl_android_set_pno_setup(struct net_device *dev, char *command, int total_len)
  1152. {
  1153. wlc_ssid_t ssids_local[MAX_PFN_LIST_COUNT];
  1154. int res = -1;
  1155. int nssid = 0;
  1156. cmd_tlv_t *cmd_tlv_temp;
  1157. char *str_ptr;
  1158. int tlv_size_left;
  1159. int pno_time = 0;
  1160. int pno_repeat = 0;
  1161. int pno_freq_expo_max = 0;
  1162. #ifdef PNO_SET_DEBUG
  1163. int i;
  1164. char pno_in_example[] = {
  1165. 'P', 'N', 'O', 'S', 'E', 'T', 'U', 'P', ' ',
  1166. 'S', '1', '2', '0',
  1167. 'S',
  1168. 0x05,
  1169. 'd', 'l', 'i', 'n', 'k',
  1170. 'S',
  1171. 0x04,
  1172. 'G', 'O', 'O', 'G',
  1173. 'T',
  1174. '0', 'B',
  1175. 'R',
  1176. '2',
  1177. 'M',
  1178. '2',
  1179. 0x00
  1180. };
  1181. #endif /* PNO_SET_DEBUG */
  1182. DHD_PNO(("%s: command=%s, len=%d\n", __FUNCTION__, command, total_len));
  1183. if (total_len < (strlen(CMD_PNOSETUP_SET) + sizeof(cmd_tlv_t))) {
  1184. DHD_ERROR(("%s argument=%d less min size\n", __FUNCTION__, total_len));
  1185. goto exit_proc;
  1186. }
  1187. #ifdef PNO_SET_DEBUG
  1188. memcpy(command, pno_in_example, sizeof(pno_in_example));
  1189. total_len = sizeof(pno_in_example);
  1190. #endif
  1191. str_ptr = command + strlen(CMD_PNOSETUP_SET);
  1192. tlv_size_left = total_len - strlen(CMD_PNOSETUP_SET);
  1193. cmd_tlv_temp = (cmd_tlv_t *)str_ptr;
  1194. memset(ssids_local, 0, sizeof(ssids_local));
  1195. if ((cmd_tlv_temp->prefix == PNO_TLV_PREFIX) &&
  1196. (cmd_tlv_temp->version == PNO_TLV_VERSION) &&
  1197. (cmd_tlv_temp->subtype == PNO_TLV_SUBTYPE_LEGACY_PNO)) {
  1198. str_ptr += sizeof(cmd_tlv_t);
  1199. tlv_size_left -= sizeof(cmd_tlv_t);
  1200. if ((nssid = wl_iw_parse_ssid_list_tlv(&str_ptr, ssids_local,
  1201. MAX_PFN_LIST_COUNT, &tlv_size_left)) <= 0) {
  1202. DHD_ERROR(("SSID is not presented or corrupted ret=%d\n", nssid));
  1203. goto exit_proc;
  1204. } else {
  1205. if ((str_ptr[0] != PNO_TLV_TYPE_TIME) || (tlv_size_left <= 1)) {
  1206. DHD_ERROR(("%s scan duration corrupted field size %d\n",
  1207. __FUNCTION__, tlv_size_left));
  1208. goto exit_proc;
  1209. }
  1210. str_ptr++;
  1211. pno_time = simple_strtoul(str_ptr, &str_ptr, 16);
  1212. DHD_PNO(("%s: pno_time=%d\n", __FUNCTION__, pno_time));
  1213. if (str_ptr[0] != 0) {
  1214. if ((str_ptr[0] != PNO_TLV_FREQ_REPEAT)) {
  1215. DHD_ERROR(("%s pno repeat : corrupted field\n",
  1216. __FUNCTION__));
  1217. goto exit_proc;
  1218. }
  1219. str_ptr++;
  1220. pno_repeat = simple_strtoul(str_ptr, &str_ptr, 16);
  1221. DHD_PNO(("%s :got pno_repeat=%d\n", __FUNCTION__, pno_repeat));
  1222. if (str_ptr[0] != PNO_TLV_FREQ_EXPO_MAX) {
  1223. DHD_ERROR(("%s FREQ_EXPO_MAX corrupted field size\n",
  1224. __FUNCTION__));
  1225. goto exit_proc;
  1226. }
  1227. str_ptr++;
  1228. pno_freq_expo_max = simple_strtoul(str_ptr, &str_ptr, 16);
  1229. DHD_PNO(("%s: pno_freq_expo_max=%d\n",
  1230. __FUNCTION__, pno_freq_expo_max));
  1231. }
  1232. }
  1233. } else {
  1234. DHD_ERROR(("%s get wrong TLV command\n", __FUNCTION__));
  1235. goto exit_proc;
  1236. }
  1237. res = dhd_dev_pno_set_for_ssid(dev, ssids_local, nssid, pno_time, pno_repeat,
  1238. pno_freq_expo_max, NULL, 0);
  1239. exit_proc:
  1240. return res;
  1241. }
  1242. #endif /* !WL_SCHED_SCAN */
  1243. #endif /* PNO_SUPPORT */
  1244. static int wl_android_get_p2p_dev_addr(struct net_device *ndev, char *command, int total_len)
  1245. {
  1246. int ret;
  1247. int bytes_written = 0;
  1248. ret = wl_cfg80211_get_p2p_dev_addr(ndev, (struct ether_addr*)command);
  1249. if (ret)
  1250. return 0;
  1251. bytes_written = sizeof(struct ether_addr);
  1252. return bytes_written;
  1253. }
  1254. #ifdef BCMCCX
  1255. static int wl_android_get_cckm_rn(struct net_device *dev, char *command)
  1256. {
  1257. int error, rn;
  1258. WL_TRACE(("%s:wl_android_get_cckm_rn\n", dev->name));
  1259. error = wldev_iovar_getint(dev, "cckm_rn", &rn);
  1260. if (unlikely(error)) {
  1261. WL_ERR(("wl_android_get_cckm_rn error (%d)\n", error));
  1262. return -1;
  1263. }
  1264. memcpy(command, &rn, sizeof(int));
  1265. return sizeof(int);
  1266. }
  1267. static int wl_android_set_cckm_krk(struct net_device *dev, char *command)
  1268. {
  1269. int error;
  1270. unsigned char key[16];
  1271. static char iovar_buf[WLC_IOCTL_MEDLEN];
  1272. WL_TRACE(("%s: wl_iw_set_cckm_krk\n", dev->name));
  1273. memset(iovar_buf, 0, sizeof(iovar_buf));
  1274. memcpy(key, command+strlen("set cckm_krk")+1, 16);
  1275. error = wldev_iovar_setbuf(dev, "cckm_krk", key, sizeof(key),
  1276. iovar_buf, WLC_IOCTL_MEDLEN, NULL);
  1277. if (unlikely(error))
  1278. {
  1279. WL_ERR((" cckm_krk set error (%d)\n", error));
  1280. return -1;
  1281. }
  1282. return 0;
  1283. }
  1284. static int wl_android_get_assoc_res_ies(struct net_device *dev, char *command)
  1285. {
  1286. int error;
  1287. u8 buf[WL_ASSOC_INFO_MAX];
  1288. wl_assoc_info_t assoc_info;
  1289. u32 resp_ies_len = 0;
  1290. int bytes_written = 0;
  1291. WL_TRACE(("%s: wl_iw_get_assoc_res_ies\n", dev->name));
  1292. error = wldev_iovar_getbuf(dev, "assoc_info", NULL, 0, buf, WL_ASSOC_INFO_MAX, NULL);
  1293. if (unlikely(error)) {
  1294. WL_ERR(("could not get assoc info (%d)\n", error));
  1295. return -1;
  1296. }
  1297. memcpy(&assoc_info, buf, sizeof(wl_assoc_info_t));
  1298. assoc_info.req_len = htod32(assoc_info.req_len);
  1299. assoc_info.resp_len = htod32(assoc_info.resp_len);
  1300. assoc_info.flags = htod32(assoc_info.flags);
  1301. if (assoc_info.resp_len) {
  1302. resp_ies_len = assoc_info.resp_len - sizeof(struct dot11_assoc_resp);
  1303. }
  1304. /* first 4 bytes are ie len */
  1305. memcpy(command, &resp_ies_len, sizeof(u32));
  1306. bytes_written = sizeof(u32);
  1307. /* get the association resp IE's if there are any */
  1308. if (resp_ies_len) {
  1309. error = wldev_iovar_getbuf(dev, "assoc_resp_ies", NULL, 0,
  1310. buf, WL_ASSOC_INFO_MAX, NULL);
  1311. if (unlikely(error)) {
  1312. WL_ERR(("could not get assoc resp_ies (%d)\n", error));
  1313. return -1;
  1314. }
  1315. memcpy(command+sizeof(u32), buf, resp_ies_len);
  1316. bytes_written += resp_ies_len;
  1317. }
  1318. return bytes_written;
  1319. }
  1320. #endif /* BCMCCX */
  1321. int
  1322. wl_android_set_ap_mac_list(struct net_device *dev, int macmode, struct maclist *maclist)
  1323. {
  1324. int i, j, match;
  1325. int ret = 0;
  1326. char mac_buf[MAX_NUM_OF_ASSOCLIST *
  1327. sizeof(struct ether_addr) + sizeof(uint)] = {0};
  1328. struct maclist *assoc_maclist = (struct maclist *)mac_buf;
  1329. /* set filtering mode */
  1330. if ((ret = wldev_ioctl(dev, WLC_SET_MACMODE, &macmode, sizeof(macmode), true)) != 0) {
  1331. DHD_ERROR(("%s : WLC_SET_MACMODE error=%d\n", __FUNCTION__, ret));
  1332. return ret;
  1333. }
  1334. if (macmode != MACLIST_MODE_DISABLED) {
  1335. /* set the MAC filter list */
  1336. if ((ret = wldev_ioctl(dev, WLC_SET_MACLIST, maclist,
  1337. sizeof(int) + sizeof(struct ether_addr) * maclist->count, true)) != 0) {
  1338. DHD_ERROR(("%s : WLC_SET_MACLIST error=%d\n", __FUNCTION__, ret));
  1339. return ret;
  1340. }
  1341. /* get the current list of associated STAs */
  1342. assoc_maclist->count = MAX_NUM_OF_ASSOCLIST;
  1343. if ((ret = wldev_ioctl(dev, WLC_GET_ASSOCLIST, assoc_maclist,
  1344. sizeof(mac_buf), false)) != 0) {
  1345. DHD_ERROR(("%s : WLC_GET_ASSOCLIST error=%d\n", __FUNCTION__, ret));
  1346. return ret;
  1347. }
  1348. /* do we have any STA associated? */
  1349. if (assoc_maclist->count) {
  1350. /* iterate each associated STA */
  1351. for (i = 0; i < assoc_maclist->count; i++) {
  1352. match = 0;
  1353. /* compare with each entry */
  1354. for (j = 0; j < maclist->count; j++) {
  1355. DHD_INFO(("%s : associated="MACDBG " list="MACDBG "\n",
  1356. __FUNCTION__, MAC2STRDBG(assoc_maclist->ea[i].octet),
  1357. MAC2STRDBG(maclist->ea[j].octet)));
  1358. if (memcmp(assoc_maclist->ea[i].octet,
  1359. maclist->ea[j].octet, ETHER_ADDR_LEN) == 0) {
  1360. match = 1;
  1361. break;
  1362. }
  1363. }
  1364. /* do conditional deauth */
  1365. /* "if not in the allow list" or "if in the deny list" */
  1366. if ((macmode == MACLIST_MODE_ALLOW && !match) ||
  1367. (macmode == MACLIST_MODE_DENY && match)) {
  1368. scb_val_t scbval;
  1369. scbval.val = htod32(1);
  1370. memcpy(&scbval.ea, &assoc_maclist->ea[i],
  1371. ETHER_ADDR_LEN);
  1372. if ((ret = wldev_ioctl(dev,
  1373. WLC_SCB_DEAUTHENTICATE_FOR_REASON,
  1374. &scbval, sizeof(scb_val_t), true)) != 0)
  1375. DHD_ERROR(("%s WLC_SCB_DEAUTHENTICATE error=%d\n",
  1376. __FUNCTION__, ret));
  1377. }
  1378. }
  1379. }
  1380. }
  1381. return ret;
  1382. }
  1383. /*
  1384. * HAPD_MAC_FILTER mac_mode mac_cnt mac_addr1 mac_addr2
  1385. *
  1386. */
  1387. static int
  1388. wl_android_set_mac_address_filter(struct net_device *dev, const char* str)
  1389. {
  1390. int i;
  1391. int ret = 0;
  1392. int macnum = 0;
  1393. int macmode = MACLIST_MODE_DISABLED;
  1394. struct maclist *list;
  1395. char eabuf[ETHER_ADDR_STR_LEN];
  1396. /* string should look like below (macmode/macnum/maclist) */
  1397. /* 1 2 00:11:22:33:44:55 00:11:22:33:44:ff */
  1398. /* get the MAC filter mode */
  1399. macmode = bcm_atoi(strsep((char**)&str, " "));
  1400. if (macmode < MACLIST_MODE_DISABLED || macmode > MACLIST_MODE_ALLOW) {
  1401. DHD_ERROR(("%s : invalid macmode %d\n", __FUNCTION__, macmode));
  1402. return -1;
  1403. }
  1404. macnum = bcm_atoi(strsep((char**)&str, " "));
  1405. if (macnum < 0 || macnum > MAX_NUM_MAC_FILT) {
  1406. DHD_ERROR(("%s : invalid number of MAC address entries %d\n",
  1407. __FUNCTION__, macnum));
  1408. return -1;
  1409. }
  1410. /* allocate memory for the MAC list */
  1411. list = (struct maclist*)kmalloc(sizeof(int) +
  1412. sizeof(struct ether_addr) * macnum, GFP_KERNEL);
  1413. if (!list) {
  1414. DHD_ERROR(("%s : failed to allocate memory\n", __FUNCTION__));
  1415. return -1;
  1416. }
  1417. /* prepare the MAC list */
  1418. list->count = htod32(macnum);
  1419. bzero((char *)eabuf, ETHER_ADDR_STR_LEN);
  1420. for (i = 0; i < list->count; i++) {
  1421. strncpy(eabuf, strsep((char**)&str, " "), ETHER_ADDR_STR_LEN - 1);
  1422. if (!(ret = bcm_ether_atoe(eabuf, &list->ea[i]))) {
  1423. DHD_ERROR(("%s : mac parsing err index=%d, addr=%s\n",
  1424. __FUNCTION__, i, eabuf));
  1425. list->count--;
  1426. break;
  1427. }
  1428. DHD_INFO(("%s : %d/%d MACADDR=%s", __FUNCTION__, i, list->count, eabuf));
  1429. }
  1430. /* set the list */
  1431. if ((ret = wl_android_set_ap_mac_list(dev, macmode, list)) != 0)
  1432. DHD_ERROR(("%s : Setting MAC list failed error=%d\n", __FUNCTION__, ret));
  1433. kfree(list);
  1434. return 0;
  1435. }
  1436. /**
  1437. * Global function definitions (declared in wl_android.h)
  1438. */
  1439. int wl_android_wifi_on(struct net_device *dev)
  1440. {
  1441. int ret = 0;
  1442. int retry = POWERUP_MAX_RETRY;
  1443. DHD_ERROR(("%s in\n", __FUNCTION__));
  1444. if (!dev) {
  1445. DHD_ERROR(("%s: dev is null\n", __FUNCTION__));
  1446. return -EINVAL;
  1447. }
  1448. dhd_net_if_lock(dev);
  1449. if (!g_wifi_on) {
  1450. do {
  1451. dhd_net_wifi_platform_set_power(dev, TRUE, WIFI_TURNON_DELAY);
  1452. ret = dhd_net_bus_resume(dev, 0);
  1453. if (ret == 0)
  1454. break;
  1455. DHD_ERROR(("\nfailed to power up wifi chip, retry again (%d left) **\n\n",
  1456. retry+1));
  1457. dhd_net_wifi_platform_set_power(dev, FALSE, WIFI_TURNOFF_DELAY);
  1458. } while (retry-- >= 0);
  1459. if (ret != 0) {
  1460. DHD_ERROR(("\nfailed to power up wifi chip, max retry reached **\n\n"));
  1461. goto exit;
  1462. }
  1463. ret = dhd_net_bus_devreset(dev, FALSE);
  1464. dhd_net_bus_resume(dev, 1);
  1465. if (!ret) {
  1466. if (dhd_dev_init_ioctl(dev) < 0)
  1467. ret = -EFAULT;
  1468. }
  1469. #if defined(ENABLE_4335BT_WAR) && defined(CUSTOMER_HW4)
  1470. bcm_bt_unlock(lock_cookie_wifi);
  1471. DHD_ERROR(("%s() bcm_bt_unlock\n", __FUNCTION__));
  1472. #endif
  1473. g_wifi_on = TRUE;
  1474. }
  1475. exit:
  1476. dhd_net_if_unlock(dev);
  1477. return ret;
  1478. }
  1479. int wl_android_wifi_off(struct net_device *dev)
  1480. {
  1481. int ret = 0;
  1482. DHD_ERROR(("%s in\n", __FUNCTION__));
  1483. if (!dev) {
  1484. DHD_TRACE(("%s: dev is null\n", __FUNCTION__));
  1485. return -EINVAL;
  1486. }
  1487. dhd_net_if_lock(dev);
  1488. if (g_wifi_on) {
  1489. ret = dhd_net_bus_devreset(dev, TRUE);
  1490. dhd_net_bus_suspend(dev);
  1491. dhd_net_wifi_platform_set_power(dev, FALSE, WIFI_TURNOFF_DELAY);
  1492. g_wifi_on = FALSE;
  1493. }
  1494. dhd_net_if_unlock(dev);
  1495. return ret;
  1496. }
  1497. static int wl_android_set_fwpath(struct net_device *net, char *command, int total_len)
  1498. {
  1499. if ((strlen(command) - strlen(CMD_SETFWPATH)) > MOD_PARAM_PATHLEN)
  1500. return -1;
  1501. return dhd_net_set_fw_path(net, command + strlen(CMD_SETFWPATH) + 1);
  1502. }
  1503. #ifdef CONNECTION_STATISTICS
  1504. static int
  1505. wl_chanim_stats(struct net_device *dev, u8 *chan_idle)
  1506. {
  1507. int err;
  1508. wl_chanim_stats_t *list;
  1509. /* Parameter _and_ returned buffer of chanim_stats. */
  1510. wl_chanim_stats_t param;
  1511. u8 result[WLC_IOCTL_SMLEN];
  1512. chanim_stats_t *stats;
  1513. memset(&param, 0, sizeof(param));
  1514. memset(result, 0, sizeof(result));
  1515. param.buflen = htod32(sizeof(wl_chanim_stats_t));
  1516. param.count = htod32(WL_CHANIM_COUNT_ONE);
  1517. if ((err = wldev_iovar_getbuf(dev, "chanim_stats", (char*)&param, sizeof(wl_chanim_stats_t),
  1518. (char*)result, sizeof(result), 0)) < 0) {
  1519. WL_ERR(("Failed to get chanim results %d \n", err));
  1520. return err;
  1521. }
  1522. list = (wl_chanim_stats_t*)result;
  1523. list->buflen = dtoh32(list->buflen);
  1524. list->version = dtoh32(list->version);
  1525. list->count = dtoh32(list->count);
  1526. if (list->buflen == 0) {
  1527. list->version = 0;
  1528. list->count = 0;
  1529. } else if (list->version != WL_CHANIM_STATS_VERSION) {
  1530. WL_ERR(("Sorry, firmware has wl_chanim_stats version %d "
  1531. "but driver supports only version %d.\n",
  1532. list->version, WL_CHANIM_STATS_VERSION));
  1533. list->buflen = 0;
  1534. list->count = 0;
  1535. }
  1536. stats = list->stats;
  1537. stats->glitchcnt = dtoh32(stats->glitchcnt);
  1538. stats->badplcp = dtoh32(stats->badplcp);
  1539. stats->chanspec = dtoh16(stats->chanspec);
  1540. stats->timestamp = dtoh32(stats->timestamp);
  1541. stats->chan_idle = dtoh32(stats->chan_idle);
  1542. WL_INFO(("chanspec: 0x%4x glitch: %d badplcp: %d idle: %d timestamp: %d\n",
  1543. stats->chanspec, stats->glitchcnt, stats->badplcp, stats->chan_idle,
  1544. stats->timestamp));
  1545. *chan_idle = stats->chan_idle;
  1546. return (err);
  1547. }
  1548. static int
  1549. wl_android_get_connection_stats(struct net_device *dev, char *command, int total_len)
  1550. {
  1551. wl_cnt_t* cnt = NULL;
  1552. int link_speed = 0;
  1553. struct connection_stats *output;
  1554. unsigned int bufsize = 0;
  1555. int bytes_written = 0;
  1556. int ret = 0;
  1557. WL_INFO(("%s: enter Get Connection Stats\n", __FUNCTION__));
  1558. if (total_len <= 0) {
  1559. WL_ERR(("%s: invalid buffer size %d\n", __FUNCTION__, total_len));
  1560. goto error;
  1561. }
  1562. bufsize = total_len;
  1563. if (bufsize < sizeof(struct connection_stats)) {
  1564. WL_ERR(("%s: not enough buffer size, provided=%u, requires=%u\n",
  1565. __FUNCTION__, bufsize,
  1566. sizeof(struct connection_stats)));
  1567. goto error;
  1568. }
  1569. if ((cnt = kmalloc(sizeof(*cnt), GFP_KERNEL)) == NULL) {
  1570. WL_ERR(("kmalloc failed\n"));
  1571. return -1;
  1572. }
  1573. memset(cnt, 0, sizeof(*cnt));
  1574. ret = wldev_iovar_getbuf(dev, "counters", NULL, 0, (char *)cnt, sizeof(wl_cnt_t), NULL);
  1575. if (ret) {
  1576. WL_ERR(("%s: wldev_iovar_getbuf() failed, ret=%d\n",
  1577. __FUNCTION__, ret));
  1578. goto error;
  1579. }
  1580. if (dtoh16(cnt->version) > WL_CNT_T_VERSION) {
  1581. WL_ERR(("%s: incorrect version of wl_cnt_t, expected=%u got=%u\n",
  1582. __FUNCTION__, WL_CNT_T_VERSION, cnt->version));
  1583. goto error;
  1584. }
  1585. /* link_speed is in kbps */
  1586. ret = wldev_get_link_speed(dev, &link_speed);
  1587. if (ret || link_speed < 0) {
  1588. WL_ERR(("%s: wldev_get_link_speed() failed, ret=%d, speed=%d\n",
  1589. __FUNCTION__, ret, link_speed));
  1590. goto error;
  1591. }
  1592. output = (struct connection_stats *)command;
  1593. output->txframe = dtoh32(cnt->txframe);
  1594. output->txbyte = dtoh32(cnt->txbyte);
  1595. output->txerror = dtoh32(cnt->txerror);
  1596. output->rxframe = dtoh32(cnt->rxframe);
  1597. output->rxbyte = dtoh32(cnt->rxbyte);
  1598. output->txfail = dtoh32(cnt->txfail);
  1599. output->txretry = dtoh32(cnt->txretry);
  1600. output->txretrie = dtoh32(cnt->txretrie);
  1601. output->txrts = dtoh32(cnt->txrts);
  1602. output->txnocts = dtoh32(cnt->txnocts);
  1603. output->txexptime = dtoh32(cnt->txexptime);
  1604. output->txrate = link_speed;
  1605. /* Channel idle ratio. */
  1606. if (wl_chanim_stats(dev, &(output->chan_idle)) < 0) {
  1607. output->chan_idle = 0;
  1608. };
  1609. kfree(cnt);
  1610. bytes_written = sizeof(struct connection_stats);
  1611. return bytes_written;
  1612. error:
  1613. if (cnt) {
  1614. kfree(cnt);
  1615. }
  1616. return -1;
  1617. }
  1618. #endif /* CONNECTION_STATISTICS */
  1619. static int
  1620. wl_android_set_pmk(struct net_device *dev, char *command, int total_len)
  1621. {
  1622. uchar pmk[33];
  1623. int error = 0;
  1624. char smbuf[WLC_IOCTL_SMLEN];
  1625. #ifdef OKC_DEBUG
  1626. int i = 0;
  1627. #endif
  1628. bzero(pmk, sizeof(pmk));
  1629. memcpy((char *)pmk, command + strlen("SET_PMK "), 32);
  1630. error = wldev_iovar_setbuf(dev, "okc_info_pmk", pmk, 32, smbuf, sizeof(smbuf), NULL);
  1631. if (error) {
  1632. DHD_ERROR(("Failed to set PMK for OKC, error = %d\n", error));
  1633. }
  1634. #ifdef OKC_DEBUG
  1635. DHD_ERROR(("PMK is "));
  1636. for (i = 0; i < 32; i++)
  1637. DHD_ERROR(("%02X ", pmk[i]));
  1638. DHD_ERROR(("\n"));
  1639. #endif
  1640. return error;
  1641. }
  1642. static int
  1643. wl_android_okc_enable(struct net_device *dev, char *command, int total_len)
  1644. {
  1645. int error = 0;
  1646. char okc_enable = 0;
  1647. okc_enable = command[strlen(CMD_OKC_ENABLE) + 1] - '0';
  1648. error = wldev_iovar_setint(dev, "okc_enable", okc_enable);
  1649. if (error) {
  1650. DHD_ERROR(("Failed to %s OKC, error = %d\n",
  1651. okc_enable ? "enable" : "disable", error));
  1652. }
  1653. wldev_iovar_setint(dev, "ccx_enable", 0);
  1654. return error;
  1655. }
  1656. #ifdef CUSTOMER_HW4
  1657. #ifdef SUPPORT_AMPDU_MPDU_CMD
  1658. /* CMD_AMPDU_MPDU */
  1659. static int
  1660. wl_android_set_ampdu_mpdu(struct net_device *dev, const char* string_num)
  1661. {
  1662. int err = 0;
  1663. int ampdu_mpdu;
  1664. ampdu_mpdu = bcm_atoi(string_num);
  1665. if (ampdu_mpdu > 32) {
  1666. DHD_ERROR(("%s : ampdu_mpdu MAX value is 32.\n", __FUNCTION__));
  1667. return -1;
  1668. }
  1669. DHD_ERROR(("%s : ampdu_mpdu = %d\n", __FUNCTION__, ampdu_mpdu));
  1670. err = wldev_iovar_setint(dev, "ampdu_mpdu", ampdu_mpdu);
  1671. if (err < 0) {
  1672. DHD_ERROR(("%s : ampdu_mpdu set error. %d\n", __FUNCTION__, err));
  1673. return -1;
  1674. }
  1675. return 0;
  1676. }
  1677. #endif /* SUPPORT_AMPDU_MPDU_CMD */
  1678. /* SoftAP feature */
  1679. #if defined(WL_SUPPORT_AUTO_CHANNEL)
  1680. static int
  1681. wl_android_set_auto_channel(struct net_device *dev, const char* string_num,
  1682. char* command, int total_len)
  1683. {
  1684. int channel;
  1685. int chosen = 0;
  1686. int retry = 0;
  1687. int ret = 0;
  1688. u32 req_buf[7] = {0};
  1689. channel = bcm_atoi(string_num);
  1690. DHD_INFO(("%s : HAPD_AUTO_CHANNEL = %d\n", __FUNCTION__, channel));
  1691. if (channel == 20) {
  1692. /* Restrict channel to 1 - 6: 2GHz, 20MHz BW, No SB */
  1693. req_buf[0] = 6;
  1694. for (channel = 1; channel <= 6; channel++) {
  1695. #ifdef D11AC_IOTYPES
  1696. if (wl_cfg80211_get_ioctl_version() == 1)
  1697. req_buf[channel] = CH20MHZ_LCHSPEC(channel);
  1698. else
  1699. req_buf[channel] = CH20MHZ_CHSPEC(channel);
  1700. #else
  1701. req_buf[channel] = CH20MHZ_CHSPEC(channel);
  1702. #endif /* D11AC_IOTYPES */
  1703. DHD_INFO(("%s: channel=%d, chanspec=0x%04X\n",
  1704. __FUNCTION__, channel, req_buf[channel]));
  1705. }
  1706. }
  1707. ret = wldev_ioctl(dev, WLC_START_CHANNEL_SEL, (void *)&req_buf,
  1708. sizeof(req_buf), true);
  1709. if (ret < 0) {
  1710. DHD_ERROR(("%s: can't start auto channel scan, err = %d\n",
  1711. __FUNCTION__, ret));
  1712. channel = 0;
  1713. goto done;
  1714. }
  1715. /* Wait for auto channel selection, max 2500 ms */
  1716. OSL_SLEEP(500);
  1717. retry = 10;
  1718. while (retry--) {
  1719. ret = wldev_ioctl(dev, WLC_GET_CHANNEL_SEL, &chosen,
  1720. sizeof(chosen), false);
  1721. if (ret < 0 || dtoh32(chosen) == 0) {
  1722. DHD_INFO(("%s: %d tried, ret = %d, chosen = %d\n",
  1723. __FUNCTION__, (10 - retry), ret, chosen));
  1724. OSL_SLEEP(200);
  1725. } else {
  1726. #ifdef D11AC_IOTYPES
  1727. if (wl_cfg80211_get_ioctl_version() == 1)
  1728. channel = LCHSPEC_CHANNEL((u16)chosen);
  1729. else
  1730. channel = CHSPEC_CHANNEL((u16)chosen);
  1731. #else
  1732. channel = CHSPEC_CHANNEL((u16)chosen);
  1733. #endif /* D11AC_IOTYPES */
  1734. DHD_ERROR(("%s: selected channel = %d\n", __FUNCTION__, channel));
  1735. break;
  1736. }
  1737. }
  1738. if (retry == 0) {
  1739. DHD_ERROR(("%s: auto channel timed out, failed\n", __FUNCTION__));
  1740. channel = 0;
  1741. }
  1742. done:
  1743. snprintf(command, 4, "%d", channel);
  1744. DHD_INFO(("%s: command result is %s\n", __FUNCTION__, command));
  1745. return 4;
  1746. }
  1747. #endif /* WL_SUPPORT_AUTO_CHANNEL */
  1748. #ifdef SUPPORT_HIDDEN_AP
  1749. static int
  1750. wl_android_set_max_num_sta(struct net_device *dev, const char* string_num)
  1751. {
  1752. int max_assoc;
  1753. max_assoc = bcm_atoi(string_num);
  1754. DHD_INFO(("%s : HAPD_MAX_NUM_STA = %d\n", __FUNCTION__, max_assoc));
  1755. wldev_iovar_setint(dev, "maxassoc", max_assoc);
  1756. return 1;
  1757. }
  1758. static int
  1759. wl_android_set_ssid(struct net_device *dev, const char* hapd_ssid)
  1760. {
  1761. wlc_ssid_t ssid;
  1762. s32 ret;
  1763. ssid.SSID_len = strlen(hapd_ssid);
  1764. if (ssid.SSID_len > DOT11_MAX_SSID_LEN) {
  1765. ssid.SSID_len = DOT11_MAX_SSID_LEN;
  1766. DHD_ERROR(("%s : Too long SSID Length %d\n", __FUNCTION__, strlen(hapd_ssid)));
  1767. }
  1768. bcm_strncpy_s(ssid.SSID, sizeof(ssid.SSID), hapd_ssid, ssid.SSID_len);
  1769. DHD_INFO(("%s: HAPD_SSID = %s\n", __FUNCTION__, ssid.SSID));
  1770. ret = wldev_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(wlc_ssid_t), true);
  1771. if (ret < 0) {
  1772. DHD_ERROR(("%s : WLC_SET_SSID Error:%d\n", __FUNCTION__, ret));
  1773. }
  1774. return 1;
  1775. }
  1776. static int
  1777. wl_android_set_hide_ssid(struct net_device *dev, const char* string_num)
  1778. {
  1779. int hide_ssid;
  1780. int enable = 0;
  1781. hide_ssid = bcm_atoi(string_num);
  1782. DHD_INFO(("%s: HAPD_HIDE_SSID = %d\n", __FUNCTION__, hide_ssid));
  1783. if (hide_ssid)
  1784. enable = 1;
  1785. wldev_iovar_setint(dev, "closednet", enable);
  1786. return 1;
  1787. }
  1788. #endif /* SUPPORT_HIDDEN_AP */
  1789. #ifdef SUPPORT_SOFTAP_SINGL_DISASSOC
  1790. static int
  1791. wl_android_sta_diassoc(struct net_device *dev, const char* straddr)
  1792. {
  1793. scb_val_t scbval;
  1794. int error = 0;
  1795. DHD_INFO(("%s: deauth STA %s\n", __FUNCTION__, straddr));
  1796. /* Unspecified reason */
  1797. scbval.val = htod32(1);
  1798. bcm_ether_atoe(straddr, &scbval.ea);
  1799. DHD_ERROR(("%s: deauth STA: "MACDBG " scb_val.val %d\n", __FUNCTION__,
  1800. MAC2STRDBG(scbval.ea.octet), scbval.val));
  1801. error = wldev_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, &scbval,
  1802. sizeof(scb_val_t), true);
  1803. if (error) {
  1804. DHD_ERROR(("Fail to DEAUTH station, error = %d\n", error));
  1805. }
  1806. return 1;
  1807. }
  1808. #endif /* SUPPORT_SOFTAP_SINGL_DISASSOC */
  1809. #ifdef SUPPORT_SET_LPC
  1810. static int
  1811. wl_android_set_lpc(struct net_device *dev, const char* string_num)
  1812. {
  1813. int lpc_enabled, ret;
  1814. s32 val = 1;
  1815. lpc_enabled = bcm_atoi(string_num);
  1816. DHD_INFO(("%s : HAPD_LPC_ENABLED = %d\n", __FUNCTION__, lpc_enabled));
  1817. ret = wldev_ioctl(dev, WLC_DOWN, &val, sizeof(s32), true);
  1818. if (ret < 0)
  1819. DHD_ERROR(("WLC_DOWN error %d\n", ret));
  1820. wldev_iovar_setint(dev, "lpc", lpc_enabled);
  1821. ret = wldev_ioctl(dev, WLC_UP, &val, sizeof(s32), true);
  1822. if (ret < 0)
  1823. DHD_ERROR(("WLC_UP error %d\n", ret));
  1824. return 1;
  1825. }
  1826. #endif /* SUPPORT_SET_LPC */
  1827. static int
  1828. wl_android_ch_res_rl(struct net_device *dev, bool change)
  1829. {
  1830. int error = 0;
  1831. s32 srl = 7;
  1832. s32 lrl = 4;
  1833. printk("%s enter\n", __FUNCTION__);
  1834. if (change) {
  1835. srl = 4;
  1836. lrl = 2;
  1837. }
  1838. error = wldev_ioctl(dev, WLC_SET_SRL, &srl, sizeof(s32), true);
  1839. if (error) {
  1840. DHD_ERROR(("Failed to set SRL, error = %d\n", error));
  1841. }
  1842. error = wldev_ioctl(dev, WLC_SET_LRL, &lrl, sizeof(s32), true);
  1843. if (error) {
  1844. DHD_ERROR(("Failed to set LRL, error = %d\n", error));
  1845. }
  1846. return error;
  1847. }
  1848. #ifdef SUPPORT_LTECX
  1849. #define DEFAULT_WLANRX_PROT 1
  1850. #define DEFAULT_LTERX_PROT 0
  1851. #define DEFAULT_LTETX_ADV 1200
  1852. static int
  1853. wl_android_set_ltecx(struct net_device *dev, const char* string_num)
  1854. {
  1855. uint16 chan_bitmap;
  1856. int ret;
  1857. chan_bitmap = bcm_strtoul(string_num, NULL, 16);
  1858. DHD_INFO(("%s : LTECOEX 0x%x\n", __FUNCTION__, chan_bitmap));
  1859. if (chan_bitmap) {
  1860. ret = wldev_iovar_setint(dev, "mws_coex_bitmap", chan_bitmap);
  1861. if (ret < 0)
  1862. DHD_ERROR(("mws_coex_bitmap error %d\n", ret));
  1863. ret = wldev_iovar_setint(dev, "mws_wlanrx_prot", DEFAULT_WLANRX_PROT);
  1864. if (ret < 0)
  1865. DHD_ERROR(("mws_wlanrx_prot error %d\n", ret));
  1866. ret = wldev_iovar_setint(dev, "mws_lterx_prot", DEFAULT_LTERX_PROT);
  1867. if (ret < 0)
  1868. DHD_ERROR(("mws_lterx_prot error %d\n", ret));
  1869. ret = wldev_iovar_setint(dev, "mws_ltetx_adv", DEFAULT_LTETX_ADV);
  1870. if (ret < 0)
  1871. DHD_ERROR(("mws_ltetx_adv error %d\n", ret));
  1872. } else {
  1873. ret = wldev_iovar_setint(dev, "mws_coex_bitmap", chan_bitmap);
  1874. if (ret < 0)
  1875. DHD_ERROR(("LTECX_CHAN_BITMAP error %d\n", ret));
  1876. }
  1877. return 1;
  1878. }
  1879. #endif /* SUPPORT_LTECX */
  1880. static int
  1881. wl_android_rmc_enable(struct net_device *net, int rmc_enable)
  1882. {
  1883. int err;
  1884. err = wldev_iovar_setint(net, "rmc_ackreq", rmc_enable);
  1885. return err;
  1886. }
  1887. static int
  1888. wl_android_rmc_set_leader(struct net_device *dev, const char* straddr)
  1889. {
  1890. int error = BCME_OK;
  1891. char smbuf[WLC_IOCTL_SMLEN];
  1892. wl_rmc_entry_t rmc_entry;
  1893. DHD_INFO(("%s: Set new RMC leader %s\n", __FUNCTION__, straddr));
  1894. memset(&rmc_entry, 0, sizeof(wl_rmc_entry_t));
  1895. if (!bcm_ether_atoe(straddr, &rmc_entry.addr)) {
  1896. if (strlen(straddr) == 1 && bcm_atoi(straddr) == 0) {
  1897. DHD_INFO(("%s: Set auto leader selection mode\n", __FUNCTION__));
  1898. memset(&rmc_entry, 0, sizeof(wl_rmc_entry_t));
  1899. } else {
  1900. DHD_ERROR(("%s: No valid mac address provided\n",
  1901. __FUNCTION__));
  1902. return BCME_ERROR;
  1903. }
  1904. }
  1905. error = wldev_iovar_setbuf(dev, "rmc_ar", &rmc_entry, sizeof(wl_rmc_entry_t),
  1906. smbuf, sizeof(smbuf), NULL);
  1907. if (error != BCME_OK) {
  1908. DHD_ERROR(("%s: Unable to set RMC leader, error = %d\n",
  1909. __FUNCTION__, error));
  1910. }
  1911. return error;
  1912. }
  1913. static int wl_android_set_rmc_event(struct net_device *dev, char *command, int total_len)
  1914. {
  1915. int err = 0;
  1916. int pid = 0;
  1917. if (sscanf(command, CMD_SET_RMC_EVENT " %d", &pid) <= 0) {
  1918. WL_ERR(("Failed to get Parameter from : %s\n", command));
  1919. return -1;
  1920. }
  1921. /* set pid, and if the event was happened, let's send a notification through netlink */
  1922. wl_cfg80211_set_rmc_pid(pid);
  1923. WL_DBG(("RMC pid=%d\n", pid));
  1924. return err;
  1925. }
  1926. int wl_android_get_singlecore_scan(struct net_device *dev, char *command, int total_len)
  1927. {
  1928. int error = 0;
  1929. int bytes_written = 0;
  1930. int mode = 0;
  1931. error = wldev_iovar_getint(dev, "scan_ps", &mode);
  1932. if (error) {
  1933. DHD_ERROR(("%s: Failed to get single core scan Mode, error = %d\n",
  1934. __FUNCTION__, error));
  1935. return -1;
  1936. }
  1937. bytes_written = snprintf(command, total_len, "%s %d", CMD_GET_SCSCAN, mode);
  1938. return bytes_written;
  1939. }
  1940. int wl_android_set_singlecore_scan(struct net_device *dev, char *command, int total_len)
  1941. {
  1942. int error = 0;
  1943. int mode = 0;
  1944. if (sscanf(command, "%*s %d", &mode) != 1) {
  1945. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  1946. return -1;
  1947. }
  1948. error = wldev_iovar_setint(dev, "scan_ps", mode);
  1949. if (error) {
  1950. DHD_ERROR(("%s[1]: Failed to set Mode %d, error = %d\n",
  1951. __FUNCTION__, mode, error));
  1952. return -1;
  1953. }
  1954. return error;
  1955. }
  1956. #if defined(TEST_TX_POWER_CONTROL) || defined(TX_POWER_CONTROL_CALLING)
  1957. static int
  1958. wl_android_set_tx_power(struct net_device *dev, const char* string_num)
  1959. {
  1960. int err = 0;
  1961. s32 dbm;
  1962. enum nl80211_tx_power_setting type;
  1963. dbm = bcm_atoi(string_num);
  1964. if (dbm < -1) {
  1965. DHD_ERROR(("%s: dbm is negative...\n", __FUNCTION__));
  1966. return -EINVAL;
  1967. }
  1968. if (dbm == -1)
  1969. type = NL80211_TX_POWER_AUTOMATIC;
  1970. else
  1971. type = NL80211_TX_POWER_FIXED;
  1972. #ifdef TX_POWER_CONTROL_CALLING
  1973. if (dbm == 0) {
  1974. dbm = TX_CALLING_POWER;
  1975. }
  1976. #endif
  1977. err = wl_set_tx_power(dev, type, dbm);
  1978. if (unlikely(err)) {
  1979. DHD_ERROR(("%s: error (%d)\n", __FUNCTION__, err));
  1980. return err;
  1981. }
  1982. return 1;
  1983. }
  1984. #endif /* TEST_TX_POWER_CONTROL || TX_POWER_CONTROL_CALLING */
  1985. #ifdef TEST_TX_POWER_CONTROL
  1986. static int
  1987. wl_android_get_tx_power(struct net_device *dev, char *command, int total_len)
  1988. {
  1989. int err;
  1990. int bytes_written;
  1991. s32 dbm = 0;
  1992. err = wl_get_tx_power(dev, &dbm);
  1993. if (unlikely(err)) {
  1994. DHD_ERROR(("%s: error (%d)\n", __FUNCTION__, err));
  1995. return err;
  1996. }
  1997. bytes_written = snprintf(command, total_len, "%s %d",
  1998. CMD_TEST_GET_TX_POWER, dbm);
  1999. DHD_ERROR(("%s: GET_TX_POWER: dBm=%d\n", __FUNCTION__, dbm));
  2000. return bytes_written;
  2001. }
  2002. #endif /* TEST_TX_POWER_CONTROL */
  2003. #ifdef SARLIMIT_TX_CONTROL_NVRAM
  2004. static int
  2005. wl_android_set_sarlimit_txctrl(struct net_device *dev, const char* string_num)
  2006. {
  2007. int err = 0;
  2008. int setval = 0;
  2009. s32 mode = bcm_atoi(string_num);
  2010. /* As Samsung specific and their requirement, '0' means activate sarlimit
  2011. * and '-1' means back to normal state (deactivate sarlimit)
  2012. */
  2013. if (mode == 0) {
  2014. DHD_INFO(("%s: SAR limit control activated\n", __FUNCTION__));
  2015. setval = 1;
  2016. } else if (mode == -1) {
  2017. DHD_INFO(("%s: SAR limit control deactivated\n", __FUNCTION__));
  2018. setval = 0;
  2019. } else {
  2020. return -EINVAL;
  2021. }
  2022. err = wldev_iovar_setint(dev, "sar_enable", setval);
  2023. if (unlikely(err)) {
  2024. DHD_ERROR(("%s: error (%d)\n", __FUNCTION__, err));
  2025. return err;
  2026. }
  2027. return 1;
  2028. }
  2029. #endif /* SARLIMIT_TX_CONTROL_NVRAM */
  2030. #endif /* CUSTOMER_HW4 */
  2031. int wl_android_set_roam_mode(struct net_device *dev, char *command, int total_len)
  2032. {
  2033. int error = 0;
  2034. int mode = 0;
  2035. if (sscanf(command, "%*s %d", &mode) != 1) {
  2036. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  2037. return -1;
  2038. }
  2039. error = wldev_iovar_setint(dev, "roam_off", mode);
  2040. if (error) {
  2041. DHD_ERROR(("%s: Failed to set roaming Mode %d, error = %d\n",
  2042. __FUNCTION__, mode, error));
  2043. return -1;
  2044. }
  2045. else
  2046. DHD_ERROR(("%s: succeeded to set roaming Mode %d, error = %d\n",
  2047. __FUNCTION__, mode, error));
  2048. return 0;
  2049. }
  2050. int wl_android_set_ibss_beacon_ouidata(struct net_device *dev, char *command, int total_len)
  2051. {
  2052. char ie_buf[VNDR_IE_MAX_LEN];
  2053. char *ioctl_buf = NULL;
  2054. char hex[] = "XX";
  2055. char *pcmd = NULL;
  2056. int ielen = 0, datalen = 0, idx = 0, tot_len = 0;
  2057. vndr_ie_setbuf_t *vndr_ie = NULL;
  2058. s32 iecount;
  2059. uint32 pktflag;
  2060. u16 kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
  2061. s32 err = BCME_OK;
  2062. /* Check the VSIE (Vendor Specific IE) which was added.
  2063. * If exist then send IOVAR to delete it
  2064. */
  2065. if (wl_cfg80211_ibss_vsie_delete(dev) != BCME_OK) {
  2066. return -EINVAL;
  2067. }
  2068. pcmd = command + strlen(CMD_SETIBSSBEACONOUIDATA) + 1;
  2069. for (idx = 0; idx < DOT11_OUI_LEN; idx++) {
  2070. hex[0] = *pcmd++;
  2071. hex[1] = *pcmd++;
  2072. ie_buf[idx] = (uint8)simple_strtoul(hex, NULL, 16);
  2073. }
  2074. pcmd++;
  2075. while ((*pcmd != '\0') && (idx < VNDR_IE_MAX_LEN)) {
  2076. hex[0] = *pcmd++;
  2077. hex[1] = *pcmd++;
  2078. ie_buf[idx++] = (uint8)simple_strtoul(hex, NULL, 16);
  2079. datalen++;
  2080. }
  2081. tot_len = sizeof(vndr_ie_setbuf_t) + (datalen - 1);
  2082. vndr_ie = (vndr_ie_setbuf_t *) kzalloc(tot_len, kflags);
  2083. if (!vndr_ie) {
  2084. WL_ERR(("IE memory alloc failed\n"));
  2085. return -ENOMEM;
  2086. }
  2087. /* Copy the vndr_ie SET command ("add"/"del") to the buffer */
  2088. strncpy(vndr_ie->cmd, "add", VNDR_IE_CMD_LEN - 1);
  2089. vndr_ie->cmd[VNDR_IE_CMD_LEN - 1] = '\0';
  2090. /* Set the IE count - the buffer contains only 1 IE */
  2091. iecount = htod32(1);
  2092. memcpy((void *)&vndr_ie->vndr_ie_buffer.iecount, &iecount, sizeof(s32));
  2093. /* Set packet flag to indicate that BEACON's will contain this IE */
  2094. pktflag = htod32(VNDR_IE_BEACON_FLAG | VNDR_IE_PRBRSP_FLAG);
  2095. memcpy((void *)&vndr_ie->vndr_ie_buffer.vndr_ie_list[0].pktflag, &pktflag,
  2096. sizeof(u32));
  2097. /* Set the IE ID */
  2098. vndr_ie->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.id = (uchar) DOT11_MNG_PROPR_ID;
  2099. memcpy(&vndr_ie->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.oui, &ie_buf,
  2100. DOT11_OUI_LEN);
  2101. memcpy(&vndr_ie->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.data,
  2102. &ie_buf[DOT11_OUI_LEN], datalen);
  2103. ielen = DOT11_OUI_LEN + datalen;
  2104. vndr_ie->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.len = (uchar) ielen;
  2105. ioctl_buf = kmalloc(WLC_IOCTL_MEDLEN, GFP_KERNEL);
  2106. if (!ioctl_buf) {
  2107. WL_ERR(("ioctl memory alloc failed\n"));
  2108. if (vndr_ie) {
  2109. kfree(vndr_ie);
  2110. }
  2111. return -ENOMEM;
  2112. }
  2113. memset(ioctl_buf, 0, WLC_IOCTL_MEDLEN); /* init the buffer */
  2114. err = wldev_iovar_setbuf(dev, "ie", vndr_ie, tot_len, ioctl_buf, WLC_IOCTL_MEDLEN, NULL);
  2115. if (err != BCME_OK) {
  2116. err = -EINVAL;
  2117. if (vndr_ie) {
  2118. kfree(vndr_ie);
  2119. }
  2120. }
  2121. else {
  2122. /* do NOT free 'vndr_ie' for the next process */
  2123. wl_cfg80211_ibss_vsie_set_buffer(vndr_ie, tot_len);
  2124. }
  2125. if (ioctl_buf) {
  2126. kfree(ioctl_buf);
  2127. }
  2128. return err;
  2129. }
  2130. #if defined(BCMFW_ROAM_ENABLE)
  2131. static int
  2132. wl_android_set_roampref(struct net_device *dev, char *command, int total_len)
  2133. {
  2134. int error = 0;
  2135. char smbuf[WLC_IOCTL_SMLEN];
  2136. uint8 buf[MAX_BUF_SIZE];
  2137. uint8 *pref = buf;
  2138. char *pcmd;
  2139. int num_ucipher_suites = 0;
  2140. int num_akm_suites = 0;
  2141. wpa_suite_t ucipher_suites[MAX_NUM_SUITES];
  2142. wpa_suite_t akm_suites[MAX_NUM_SUITES];
  2143. int num_tuples = 0;
  2144. int total_bytes = 0;
  2145. int total_len_left;
  2146. int i, j;
  2147. char hex[] = "XX";
  2148. pcmd = command + strlen(CMD_SET_ROAMPREF) + 1;
  2149. total_len_left = total_len - strlen(CMD_SET_ROAMPREF) + 1;
  2150. num_akm_suites = simple_strtoul(pcmd, NULL, 16);
  2151. /* Increment for number of AKM suites field + space */
  2152. pcmd += 3;
  2153. total_len_left -= 3;
  2154. /* check to make sure pcmd does not overrun */
  2155. if (total_len_left < (num_akm_suites * WIDTH_AKM_SUITE))
  2156. return -1;
  2157. memset(buf, 0, sizeof(buf));
  2158. memset(akm_suites, 0, sizeof(akm_suites));
  2159. memset(ucipher_suites, 0, sizeof(ucipher_suites));
  2160. /* Save the AKM suites passed in the command */
  2161. for (i = 0; i < num_akm_suites; i++) {
  2162. /* Store the MSB first, as required by join_pref */
  2163. for (j = 0; j < 4; j++) {
  2164. hex[0] = *pcmd++;
  2165. hex[1] = *pcmd++;
  2166. buf[j] = (uint8)simple_strtoul(hex, NULL, 16);
  2167. }
  2168. memcpy((uint8 *)&akm_suites[i], buf, sizeof(uint32));
  2169. }
  2170. total_len_left -= (num_akm_suites * WIDTH_AKM_SUITE);
  2171. num_ucipher_suites = simple_strtoul(pcmd, NULL, 16);
  2172. /* Increment for number of cipher suites field + space */
  2173. pcmd += 3;
  2174. total_len_left -= 3;
  2175. if (total_len_left < (num_ucipher_suites * WIDTH_AKM_SUITE))
  2176. return -1;
  2177. /* Save the cipher suites passed in the command */
  2178. for (i = 0; i < num_ucipher_suites; i++) {
  2179. /* Store the MSB first, as required by join_pref */
  2180. for (j = 0; j < 4; j++) {
  2181. hex[0] = *pcmd++;
  2182. hex[1] = *pcmd++;
  2183. buf[j] = (uint8)simple_strtoul(hex, NULL, 16);
  2184. }
  2185. memcpy((uint8 *)&ucipher_suites[i], buf, sizeof(uint32));
  2186. }
  2187. /* Join preference for RSSI
  2188. * Type : 1 byte (0x01)
  2189. * Length : 1 byte (0x02)
  2190. * Value : 2 bytes (reserved)
  2191. */
  2192. *pref++ = WL_JOIN_PREF_RSSI;
  2193. *pref++ = JOIN_PREF_RSSI_LEN;
  2194. *pref++ = 0;
  2195. *pref++ = 0;
  2196. /* Join preference for WPA
  2197. * Type : 1 byte (0x02)
  2198. * Length : 1 byte (not used)
  2199. * Value : (variable length)
  2200. * reserved: 1 byte
  2201. * count : 1 byte (no of tuples)
  2202. * Tuple1 : 12 bytes
  2203. * akm[4]
  2204. * ucipher[4]
  2205. * mcipher[4]
  2206. * Tuple2 : 12 bytes
  2207. * Tuplen : 12 bytes
  2208. */
  2209. num_tuples = num_akm_suites * num_ucipher_suites;
  2210. if (num_tuples != 0) {
  2211. if (num_tuples <= JOIN_PREF_MAX_WPA_TUPLES) {
  2212. *pref++ = WL_JOIN_PREF_WPA;
  2213. *pref++ = 0;
  2214. *pref++ = 0;
  2215. *pref++ = (uint8)num_tuples;
  2216. total_bytes = JOIN_PREF_RSSI_SIZE + JOIN_PREF_WPA_HDR_SIZE +
  2217. (JOIN_PREF_WPA_TUPLE_SIZE * num_tuples);
  2218. } else {
  2219. DHD_ERROR(("%s: Too many wpa configs for join_pref \n", __FUNCTION__));
  2220. return -1;
  2221. }
  2222. } else {
  2223. /* No WPA config, configure only RSSI preference */
  2224. total_bytes = JOIN_PREF_RSSI_SIZE;
  2225. }
  2226. /* akm-ucipher-mcipher tuples in the format required for join_pref */
  2227. for (i = 0; i < num_ucipher_suites; i++) {
  2228. for (j = 0; j < num_akm_suites; j++) {
  2229. memcpy(pref, (uint8 *)&akm_suites[j], WPA_SUITE_LEN);
  2230. pref += WPA_SUITE_LEN;
  2231. memcpy(pref, (uint8 *)&ucipher_suites[i], WPA_SUITE_LEN);
  2232. pref += WPA_SUITE_LEN;
  2233. /* Set to 0 to match any available multicast cipher */
  2234. memset(pref, 0, WPA_SUITE_LEN);
  2235. pref += WPA_SUITE_LEN;
  2236. }
  2237. }
  2238. prhex("join pref", (uint8 *)buf, total_bytes);
  2239. error = wldev_iovar_setbuf(dev, "join_pref", buf, total_bytes, smbuf, sizeof(smbuf), NULL);
  2240. if (error) {
  2241. DHD_ERROR(("Failed to set join_pref, error = %d\n", error));
  2242. }
  2243. return error;
  2244. }
  2245. #endif /* defined(BCMFW_ROAM_ENABLE */
  2246. static int
  2247. wl_android_iolist_add(struct net_device *dev, struct list_head *head, struct io_cfg *config)
  2248. {
  2249. struct io_cfg *resume_cfg;
  2250. s32 ret;
  2251. resume_cfg = kzalloc(sizeof(struct io_cfg), GFP_KERNEL);
  2252. if (!resume_cfg)
  2253. return -ENOMEM;
  2254. if (config->iovar) {
  2255. ret = wldev_iovar_getint(dev, config->iovar, &resume_cfg->param);
  2256. if (ret) {
  2257. DHD_ERROR(("%s: Failed to get current %s value\n",
  2258. __FUNCTION__, config->iovar));
  2259. goto error;
  2260. }
  2261. ret = wldev_iovar_setint(dev, config->iovar, config->param);
  2262. if (ret) {
  2263. DHD_ERROR(("%s: Failed to set %s to %d\n", __FUNCTION__,
  2264. config->iovar, config->param));
  2265. goto error;
  2266. }
  2267. resume_cfg->iovar = config->iovar;
  2268. } else {
  2269. resume_cfg->arg = kzalloc(config->len, GFP_KERNEL);
  2270. if (!resume_cfg->arg) {
  2271. ret = -ENOMEM;
  2272. goto error;
  2273. }
  2274. ret = wldev_ioctl(dev, config->ioctl, resume_cfg->arg, config->len, false);
  2275. if (ret) {
  2276. DHD_ERROR(("%s: Failed to get ioctl %d\n", __FUNCTION__,
  2277. config->ioctl));
  2278. goto error;
  2279. }
  2280. ret = wldev_ioctl(dev, config->ioctl + 1, config->arg, config->len, true);
  2281. if (ret) {
  2282. DHD_ERROR(("%s: Failed to set %s to %d\n", __FUNCTION__,
  2283. config->iovar, config->param));
  2284. goto error;
  2285. }
  2286. if (config->ioctl + 1 == WLC_SET_PM)
  2287. wl_cfg80211_update_power_mode(dev);
  2288. resume_cfg->ioctl = config->ioctl;
  2289. resume_cfg->len = config->len;
  2290. }
  2291. list_add(&resume_cfg->list, head);
  2292. return 0;
  2293. error:
  2294. kfree(resume_cfg->arg);
  2295. kfree(resume_cfg);
  2296. return ret;
  2297. }
  2298. static void
  2299. wl_android_iolist_resume(struct net_device *dev, struct list_head *head)
  2300. {
  2301. struct io_cfg *config;
  2302. struct list_head *cur, *q;
  2303. s32 ret = 0;
  2304. list_for_each_safe(cur, q, head) {
  2305. config = list_entry(cur, struct io_cfg, list);
  2306. if (config->iovar) {
  2307. if (!ret)
  2308. ret = wldev_iovar_setint(dev, config->iovar,
  2309. config->param);
  2310. } else {
  2311. if (!ret)
  2312. ret = wldev_ioctl(dev, config->ioctl + 1,
  2313. config->arg, config->len, true);
  2314. if (config->ioctl + 1 == WLC_SET_PM)
  2315. wl_cfg80211_update_power_mode(dev);
  2316. kfree(config->arg);
  2317. }
  2318. list_del(cur);
  2319. kfree(config);
  2320. }
  2321. }
  2322. static int
  2323. wl_android_set_miracast(struct net_device *dev, char *command, int total_len)
  2324. {
  2325. int mode, val;
  2326. int ret = 0;
  2327. struct io_cfg config;
  2328. if (sscanf(command, "%*s %d", &mode) != 1) {
  2329. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  2330. return -1;
  2331. }
  2332. DHD_INFO(("%s: enter miracast mode %d\n", __FUNCTION__, mode));
  2333. if (miracast_cur_mode == mode) {
  2334. return 0;
  2335. }
  2336. wl_android_iolist_resume(dev, &miracast_resume_list);
  2337. miracast_cur_mode = MIRACAST_MODE_OFF;
  2338. switch (mode) {
  2339. case MIRACAST_MODE_SOURCE:
  2340. /* setting mchan_algo to platform specific value */
  2341. config.iovar = "mchan_algo";
  2342. ret = wldev_ioctl(dev, WLC_GET_BCNPRD, &val, sizeof(int), false);
  2343. if (!ret && val > 100) {
  2344. config.param = 0;
  2345. DHD_ERROR(("%s: Connected station's beacon interval: "
  2346. "%d and set mchan_algo to %d \n",
  2347. __FUNCTION__, val, config.param));
  2348. }
  2349. else {
  2350. config.param = MIRACAST_MCHAN_ALGO;
  2351. }
  2352. ret = wl_android_iolist_add(dev, &miracast_resume_list, &config);
  2353. if (ret) {
  2354. goto resume;
  2355. }
  2356. /* setting mchan_bw to platform specific value */
  2357. config.iovar = "mchan_bw";
  2358. config.param = MIRACAST_MCHAN_BW;
  2359. ret = wl_android_iolist_add(dev, &miracast_resume_list, &config);
  2360. if (ret) {
  2361. goto resume;
  2362. }
  2363. /* setting apmdu to platform specific value */
  2364. config.iovar = "ampdu_mpdu";
  2365. config.param = MIRACAST_AMPDU_SIZE;
  2366. ret = wl_android_iolist_add(dev, &miracast_resume_list, &config);
  2367. if (ret) {
  2368. goto resume;
  2369. }
  2370. /* FALLTROUGH */
  2371. /* Source mode shares most configurations with sink mode.
  2372. * Fall through here to avoid code duplication
  2373. */
  2374. case MIRACAST_MODE_SINK:
  2375. /* disable internal roaming */
  2376. config.iovar = "roam_off";
  2377. config.param = 1;
  2378. ret = wl_android_iolist_add(dev, &miracast_resume_list, &config);
  2379. if (ret) {
  2380. goto resume;
  2381. }
  2382. /* turn off pm */
  2383. ret = wldev_ioctl(dev, WLC_GET_PM, &val, sizeof(val), false);
  2384. if(ret) {
  2385. goto resume;
  2386. }
  2387. if (val != PM_OFF) {
  2388. val = PM_OFF;
  2389. config.iovar = NULL;
  2390. config.ioctl = WLC_GET_PM;
  2391. config.arg = &val;
  2392. config.len = sizeof(int);
  2393. ret = wl_android_iolist_add(dev, &miracast_resume_list, &config);
  2394. if (ret) {
  2395. goto resume;
  2396. }
  2397. }
  2398. break;
  2399. case MIRACAST_MODE_OFF:
  2400. default:
  2401. break;
  2402. }
  2403. miracast_cur_mode = mode;
  2404. return 0;
  2405. resume:
  2406. DHD_ERROR(("%s: turnoff miracast mode because of err%d\n", __FUNCTION__, ret));
  2407. wl_android_iolist_resume(dev, &miracast_resume_list);
  2408. return ret;
  2409. }
  2410. #define NETLINK_OXYGEN 30
  2411. #define AIBSS_BEACON_TIMEOUT 10
  2412. static struct sock *nl_sk = NULL;
  2413. static void wl_netlink_recv(struct sk_buff *skb)
  2414. {
  2415. WL_ERR(("netlink_recv called\n"));
  2416. }
  2417. static int wl_netlink_init(void)
  2418. {
  2419. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  2420. struct netlink_kernel_cfg cfg = {
  2421. .input = wl_netlink_recv,
  2422. };
  2423. #endif
  2424. if (nl_sk != NULL) {
  2425. WL_ERR(("nl_sk already exist\n"));
  2426. return BCME_ERROR;
  2427. }
  2428. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
  2429. nl_sk = netlink_kernel_create(&init_net, NETLINK_OXYGEN,
  2430. 0, wl_netlink_recv, NULL, THIS_MODULE);
  2431. #elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
  2432. nl_sk = netlink_kernel_create(&init_net, NETLINK_OXYGEN, THIS_MODULE, &cfg);
  2433. #else
  2434. nl_sk = netlink_kernel_create(&init_net, NETLINK_OXYGEN, &cfg);
  2435. #endif
  2436. if (nl_sk == NULL) {
  2437. WL_ERR(("nl_sk is not ready\n"));
  2438. return BCME_ERROR;
  2439. }
  2440. return BCME_OK;
  2441. }
  2442. static void wl_netlink_deinit(void)
  2443. {
  2444. if (nl_sk) {
  2445. netlink_kernel_release(nl_sk);
  2446. nl_sk = NULL;
  2447. }
  2448. }
  2449. s32
  2450. wl_netlink_send_msg(int pid, int type, int seq, void *data, size_t size)
  2451. {
  2452. struct sk_buff *skb = NULL;
  2453. struct nlmsghdr *nlh = NULL;
  2454. int ret = -1;
  2455. if (nl_sk == NULL) {
  2456. WL_ERR(("nl_sk was not initialized\n"));
  2457. goto nlmsg_failure;
  2458. }
  2459. skb = alloc_skb(NLMSG_SPACE(size), GFP_ATOMIC);
  2460. if (skb == NULL) {
  2461. WL_ERR(("failed to allocate memory\n"));
  2462. goto nlmsg_failure;
  2463. }
  2464. nlh = nlmsg_put(skb, 0, 0, 0, size, 0);
  2465. if (nlh == NULL) {
  2466. WL_ERR(("failed to build nlmsg, skb_tailroom:%d, nlmsg_total_size:%d\n",
  2467. skb_tailroom(skb), nlmsg_total_size(size)));
  2468. dev_kfree_skb(skb);
  2469. goto nlmsg_failure;
  2470. }
  2471. memcpy(nlmsg_data(nlh), data, size);
  2472. nlh->nlmsg_seq = seq;
  2473. nlh->nlmsg_type = type;
  2474. /* netlink_unicast() takes ownership of the skb and frees it itself. */
  2475. ret = netlink_unicast(nl_sk, skb, pid, 0);
  2476. WL_DBG(("netlink_unicast() pid=%d, ret=%d\n", pid, ret));
  2477. nlmsg_failure:
  2478. return ret;
  2479. }
  2480. #ifdef WLAIBSS
  2481. static int wl_android_set_ibss_txfail_event(struct net_device *dev, char *command, int total_len)
  2482. {
  2483. int err = 0;
  2484. int retry = 0;
  2485. int pid = 0;
  2486. aibss_txfail_config_t txfail_config = {0, 0, 0, 0};
  2487. char smbuf[WLC_IOCTL_SMLEN];
  2488. if (sscanf(command, CMD_SETIBSSTXFAILEVENT " %d %d", &retry, &pid) <= 0) {
  2489. WL_ERR(("Failed to get Parameter from : %s\n", command));
  2490. return -1;
  2491. }
  2492. /* set pid, and if the event was happened, let's send a notification through netlink */
  2493. wl_cfg80211_set_txfail_pid(pid);
  2494. #ifdef CUSTOMER_HW4
  2495. /* using same pid for RMC, AIBSS shares same pid with RMC and it is set once */
  2496. wl_cfg80211_set_rmc_pid(pid);
  2497. #endif
  2498. /* If retry value is 0, it disables the functionality for TX Fail. */
  2499. if (retry > 0) {
  2500. txfail_config.max_tx_retry = retry;
  2501. txfail_config.bcn_timeout = 0; /* 0 : disable tx fail from beacon */
  2502. }
  2503. txfail_config.version = AIBSS_TXFAIL_CONFIG_VER_0;
  2504. txfail_config.len = sizeof(txfail_config);
  2505. err = wldev_iovar_setbuf(dev, "aibss_txfail_config", (void *) &txfail_config,
  2506. sizeof(aibss_txfail_config_t), smbuf, WLC_IOCTL_SMLEN, NULL);
  2507. WL_DBG(("retry=%d, pid=%d, err=%d\n", retry, pid, err));
  2508. return ((err == 0)?total_len:err);
  2509. }
  2510. static int wl_android_get_ibss_peer_info(struct net_device *dev, char *command,
  2511. int total_len, bool bAll)
  2512. {
  2513. int error;
  2514. int bytes_written = 0;
  2515. void *buf = NULL;
  2516. bss_peer_list_info_t peer_list_info;
  2517. bss_peer_info_t *peer_info;
  2518. int i;
  2519. bool found = false;
  2520. struct ether_addr mac_ea;
  2521. char *str = command;
  2522. WL_DBG(("get ibss peer info(%s)\n", bAll?"true":"false"));
  2523. if (!bAll) {
  2524. if (bcmstrtok(&str, " ", NULL) == NULL) {
  2525. WL_ERR(("invalid command\n"));
  2526. return -1;
  2527. }
  2528. if (!str || !bcm_ether_atoe(str, &mac_ea)) {
  2529. WL_ERR(("invalid MAC address\n"));
  2530. return -1;
  2531. }
  2532. }
  2533. if ((buf = kmalloc(WLC_IOCTL_MAXLEN, GFP_KERNEL)) == NULL) {
  2534. WL_ERR(("kmalloc failed\n"));
  2535. return -1;
  2536. }
  2537. error = wldev_iovar_getbuf(dev, "bss_peer_info", NULL, 0, buf, WLC_IOCTL_MAXLEN, NULL);
  2538. if (unlikely(error)) {
  2539. WL_ERR(("could not get ibss peer info (%d)\n", error));
  2540. kfree(buf);
  2541. return -1;
  2542. }
  2543. memcpy(&peer_list_info, buf, sizeof(peer_list_info));
  2544. peer_list_info.version = htod16(peer_list_info.version);
  2545. peer_list_info.bss_peer_info_len = htod16(peer_list_info.bss_peer_info_len);
  2546. peer_list_info.count = htod32(peer_list_info.count);
  2547. WL_DBG(("ver:%d, len:%d, count:%d\n", peer_list_info.version,
  2548. peer_list_info.bss_peer_info_len, peer_list_info.count));
  2549. if (peer_list_info.count > 0) {
  2550. if (bAll)
  2551. bytes_written += sprintf(&command[bytes_written], "%u ",
  2552. peer_list_info.count);
  2553. peer_info = (bss_peer_info_t *) ((void *)buf + BSS_PEER_LIST_INFO_FIXED_LEN);
  2554. for (i = 0; i < peer_list_info.count; i++) {
  2555. WL_DBG(("index:%d rssi:%d, tx:%u, rx:%u\n", i, peer_info->rssi,
  2556. peer_info->tx_rate, peer_info->rx_rate));
  2557. if (!bAll &&
  2558. memcmp(&mac_ea, &peer_info->ea, sizeof(struct ether_addr)) == 0) {
  2559. found = true;
  2560. }
  2561. if (bAll || found) {
  2562. bytes_written += sprintf(&command[bytes_written], MACF,
  2563. ETHER_TO_MACF(peer_info->ea));
  2564. bytes_written += sprintf(&command[bytes_written], " %u %d ",
  2565. peer_info->tx_rate/1000, peer_info->rssi);
  2566. }
  2567. if (found)
  2568. break;
  2569. peer_info = (bss_peer_info_t *)((void *)peer_info+sizeof(bss_peer_info_t));
  2570. }
  2571. }
  2572. else {
  2573. WL_ERR(("could not get ibss peer info : no item\n"));
  2574. }
  2575. bytes_written += sprintf(&command[bytes_written], "%s", "\0");
  2576. WL_DBG(("command(%u):%s\n", total_len, command));
  2577. WL_DBG(("bytes_written:%d\n", bytes_written));
  2578. kfree(buf);
  2579. return bytes_written;
  2580. }
  2581. int wl_android_set_ibss_routetable(struct net_device *dev, char *command, int total_len)
  2582. {
  2583. char *pcmd = command;
  2584. char *str = NULL;
  2585. ibss_route_tbl_t *route_tbl = NULL;
  2586. char *ioctl_buf = NULL;
  2587. u16 kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
  2588. s32 err = BCME_OK;
  2589. uint32 route_tbl_len;
  2590. uint32 entries;
  2591. char *endptr;
  2592. uint32 i = 0;
  2593. struct ipv4_addr dipaddr;
  2594. struct ether_addr ea;
  2595. route_tbl_len = sizeof(ibss_route_tbl_t) +
  2596. (MAX_IBSS_ROUTE_TBL_ENTRY - 1) * sizeof(ibss_route_entry_t);
  2597. route_tbl = (ibss_route_tbl_t *)kzalloc(route_tbl_len, kflags);
  2598. if (!route_tbl) {
  2599. WL_ERR(("Route TBL alloc failed\n"));
  2600. return -ENOMEM;
  2601. }
  2602. ioctl_buf = kzalloc(WLC_IOCTL_MEDLEN, GFP_KERNEL);
  2603. if (!ioctl_buf) {
  2604. WL_ERR(("ioctl memory alloc failed\n"));
  2605. if (route_tbl) {
  2606. kfree(route_tbl);
  2607. }
  2608. return -ENOMEM;
  2609. }
  2610. memset(ioctl_buf, 0, WLC_IOCTL_MEDLEN);
  2611. /* drop command */
  2612. str = bcmstrtok(&pcmd, " ", NULL);
  2613. /* get count */
  2614. str = bcmstrtok(&pcmd, " ", NULL);
  2615. if (!str) {
  2616. WL_ERR(("Invalid number parameter %s\n", str));
  2617. err = -EINVAL;
  2618. goto exit;
  2619. }
  2620. entries = bcm_strtoul(str, &endptr, 0);
  2621. if (*endptr != '\0') {
  2622. WL_ERR(("Invalid number parameter %s\n", str));
  2623. err = -EINVAL;
  2624. goto exit;
  2625. }
  2626. if (entries > MAX_IBSS_ROUTE_TBL_ENTRY) {
  2627. WL_ERR(("Invalid entries number %u\n", entries));
  2628. err = -EINVAL;
  2629. goto exit;
  2630. }
  2631. WL_INFO(("Routing table count:%u\n", entries));
  2632. route_tbl->num_entry = entries;
  2633. for (i = 0; i < entries; i++) {
  2634. str = bcmstrtok(&pcmd, " ", NULL);
  2635. if (!str || !bcm_atoipv4(str, &dipaddr)) {
  2636. WL_ERR(("Invalid ip string %s\n", str));
  2637. err = -EINVAL;
  2638. goto exit;
  2639. }
  2640. str = bcmstrtok(&pcmd, " ", NULL);
  2641. if (!str || !bcm_ether_atoe(str, &ea)) {
  2642. WL_ERR(("Invalid ethernet string %s\n", str));
  2643. err = -EINVAL;
  2644. goto exit;
  2645. }
  2646. bcopy(&dipaddr, &route_tbl->route_entry[i].ipv4_addr, IPV4_ADDR_LEN);
  2647. bcopy(&ea, &route_tbl->route_entry[i].nexthop, ETHER_ADDR_LEN);
  2648. }
  2649. route_tbl_len = sizeof(ibss_route_tbl_t) +
  2650. ((!entries?0:(entries - 1)) * sizeof(ibss_route_entry_t));
  2651. err = wldev_iovar_setbuf(dev, "ibss_route_tbl",
  2652. route_tbl, route_tbl_len, ioctl_buf, WLC_IOCTL_MEDLEN, NULL);
  2653. if (err != BCME_OK) {
  2654. WL_ERR(("Fail to set iovar %d\n", err));
  2655. err = -EINVAL;
  2656. }
  2657. exit:
  2658. if (route_tbl)
  2659. kfree(route_tbl);
  2660. if (ioctl_buf)
  2661. kfree(ioctl_buf);
  2662. return err;
  2663. }
  2664. int wl_android_set_ibss_ampdu(struct net_device *dev, char *command, int total_len)
  2665. {
  2666. char *pcmd = command;
  2667. char *str = NULL, *endptr = NULL;
  2668. int category[4];
  2669. int tid2category[NUMPRIO] = {2, 3, 3, 2, 1, 1, 0, 0};
  2670. struct ampdu_tid_control_mode control;
  2671. char smbuf[WLC_IOCTL_SMLEN];
  2672. int idx;
  2673. int err = 0;
  2674. WL_DBG(("set ibss ampdu:%s\n", command));
  2675. /* acquire parameters */
  2676. /* drop command */
  2677. str = bcmstrtok(&pcmd, " ", NULL);
  2678. for (idx = 0; idx < 4; idx++) {
  2679. str = bcmstrtok(&pcmd, " ", NULL);
  2680. if (!str) {
  2681. WL_ERR(("Invalid parameter : %s\n", pcmd));
  2682. return -EINVAL;
  2683. }
  2684. category[idx] = bcm_strtoul(str, &endptr, 0);
  2685. if (*endptr != '\0') {
  2686. WL_ERR(("Invalid number format %s\n", str));
  2687. return -EINVAL;
  2688. }
  2689. }
  2690. sprintf(control.mode_name, "AIBSS");
  2691. for (idx = 0; idx < NUMPRIO; idx++) {
  2692. control.control[idx].tid = idx;
  2693. control.control[idx].enable = category[tid2category[idx]];
  2694. }
  2695. err = wldev_iovar_setbuf(dev, "ampdu_tid_mode", (void *) &control,
  2696. sizeof(struct ampdu_tid_control_mode), smbuf, WLC_IOCTL_SMLEN, NULL);
  2697. return ((err == 0)?total_len:err);
  2698. }
  2699. int wl_android_set_ibss_antenna(struct net_device *dev, char *command, int total_len)
  2700. {
  2701. char *pcmd = command;
  2702. char *str = NULL;
  2703. int txchain, rxchain;
  2704. int err = 0;
  2705. WL_DBG(("set ibss antenna:%s\n", command));
  2706. /* acquire parameters */
  2707. /* drop command */
  2708. str = bcmstrtok(&pcmd, " ", NULL);
  2709. /* TX chain */
  2710. str = bcmstrtok(&pcmd, " ", NULL);
  2711. if (!str) {
  2712. WL_ERR(("Invalid parameter : %s\n", pcmd));
  2713. return -EINVAL;
  2714. }
  2715. txchain = bcm_atoi(str);
  2716. /* RX chain */
  2717. str = bcmstrtok(&pcmd, " ", NULL);
  2718. if (!str) {
  2719. WL_ERR(("Invalid parameter : %s\n", pcmd));
  2720. return -EINVAL;
  2721. }
  2722. rxchain = bcm_atoi(str);
  2723. err = wldev_iovar_setint(dev, "txchain", txchain);
  2724. if (err != 0)
  2725. return err;
  2726. err = wldev_iovar_setint(dev, "rxchain", rxchain);
  2727. return ((err == 0)?total_len:err);
  2728. }
  2729. #endif /* WLAIBSS */
  2730. int wl_keep_alive_set(struct net_device *dev, char* extra, int total_len)
  2731. {
  2732. char buf[256];
  2733. const char *str;
  2734. wl_mkeep_alive_pkt_t mkeep_alive_pkt;
  2735. wl_mkeep_alive_pkt_t *mkeep_alive_pktp;
  2736. int buf_len;
  2737. int str_len;
  2738. int res = -1;
  2739. uint period_msec = 0;
  2740. if (extra == NULL)
  2741. {
  2742. DHD_ERROR(("%s: extra is NULL\n", __FUNCTION__));
  2743. return -1;
  2744. }
  2745. if (sscanf(extra, "%d", &period_msec) != 1)
  2746. {
  2747. DHD_ERROR(("%s: sscanf error. check period_msec value\n", __FUNCTION__));
  2748. return -EINVAL;
  2749. }
  2750. DHD_ERROR(("%s: period_msec is %d\n", __FUNCTION__, period_msec));
  2751. memset(&mkeep_alive_pkt, 0, sizeof(wl_mkeep_alive_pkt_t));
  2752. str = "mkeep_alive";
  2753. str_len = strlen(str);
  2754. strncpy(buf, str, str_len);
  2755. buf[ str_len ] = '\0';
  2756. mkeep_alive_pktp = (wl_mkeep_alive_pkt_t *) (buf + str_len + 1);
  2757. mkeep_alive_pkt.period_msec = period_msec;
  2758. buf_len = str_len + 1;
  2759. mkeep_alive_pkt.version = htod16(WL_MKEEP_ALIVE_VERSION);
  2760. mkeep_alive_pkt.length = htod16(WL_MKEEP_ALIVE_FIXED_LEN);
  2761. /* Setup keep alive zero for null packet generation */
  2762. mkeep_alive_pkt.keep_alive_id = 0;
  2763. mkeep_alive_pkt.len_bytes = 0;
  2764. buf_len += WL_MKEEP_ALIVE_FIXED_LEN;
  2765. /* Keep-alive attributes are set in local variable (mkeep_alive_pkt), and
  2766. * then memcpy'ed into buffer (mkeep_alive_pktp) since there is no
  2767. * guarantee that the buffer is properly aligned.
  2768. */
  2769. memcpy((char *)mkeep_alive_pktp, &mkeep_alive_pkt, WL_MKEEP_ALIVE_FIXED_LEN);
  2770. if ((res = wldev_ioctl(dev, WLC_SET_VAR, buf, buf_len, TRUE)) < 0)
  2771. {
  2772. DHD_ERROR(("%s:keep_alive set failed. res[%d]\n", __FUNCTION__, res));
  2773. }
  2774. else
  2775. {
  2776. DHD_ERROR(("%s:keep_alive set ok. res[%d]\n", __FUNCTION__, res));
  2777. }
  2778. return res;
  2779. }
  2780. int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
  2781. {
  2782. #define PRIVATE_COMMAND_MAX_LEN 8192
  2783. int ret = 0;
  2784. char *command = NULL;
  2785. int bytes_written = 0;
  2786. android_wifi_priv_cmd priv_cmd;
  2787. net_os_wake_lock(net);
  2788. if (!capable(CAP_NET_ADMIN)) {
  2789. ret = -EPERM;
  2790. goto exit;
  2791. }
  2792. if (!ifr->ifr_data) {
  2793. ret = -EINVAL;
  2794. goto exit;
  2795. }
  2796. if (!capable(CAP_NET_ADMIN)) {
  2797. ret = -EPERM;
  2798. goto exit;
  2799. }
  2800. #ifdef CONFIG_COMPAT
  2801. if (is_compat_task()) {
  2802. compat_android_wifi_priv_cmd compat_priv_cmd;
  2803. if (copy_from_user(&compat_priv_cmd, ifr->ifr_data,
  2804. sizeof(compat_android_wifi_priv_cmd))) {
  2805. ret = -EFAULT;
  2806. goto exit;
  2807. }
  2808. priv_cmd.buf = compat_ptr(compat_priv_cmd.buf);
  2809. priv_cmd.used_len = compat_priv_cmd.used_len;
  2810. priv_cmd.total_len = compat_priv_cmd.total_len;
  2811. } else
  2812. #endif /* CONFIG_COMPAT */
  2813. {
  2814. if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(android_wifi_priv_cmd))) {
  2815. ret = -EFAULT;
  2816. goto exit;
  2817. }
  2818. }
  2819. if ((priv_cmd.total_len > PRIVATE_COMMAND_MAX_LEN) || (priv_cmd.total_len < 0)) {
  2820. DHD_ERROR(("%s: invalid length of private command : %d\n",
  2821. __FUNCTION__, priv_cmd.total_len));
  2822. ret = -EINVAL;
  2823. goto exit;
  2824. }
  2825. command = kmalloc((priv_cmd.total_len + 1), GFP_KERNEL);
  2826. if (!command)
  2827. {
  2828. DHD_ERROR(("%s: failed to allocate memory\n", __FUNCTION__));
  2829. ret = -ENOMEM;
  2830. goto exit;
  2831. }
  2832. if (copy_from_user(command, priv_cmd.buf, priv_cmd.total_len)) {
  2833. ret = -EFAULT;
  2834. goto exit;
  2835. }
  2836. command[priv_cmd.total_len] = '\0';
  2837. DHD_INFO(("%s: Android private cmd \"%s\" on %s\n", __FUNCTION__, command, ifr->ifr_name));
  2838. if (strnicmp(command, CMD_START, strlen(CMD_START)) == 0) {
  2839. DHD_INFO(("%s, Received regular START command\n", __FUNCTION__));
  2840. #ifdef SUPPORT_DEEP_SLEEP
  2841. trigger_deep_sleep = 1;
  2842. #else
  2843. bytes_written = wl_android_wifi_on(net);
  2844. #endif /* SUPPORT_DEEP_SLEEP */
  2845. }
  2846. else if (strnicmp(command, CMD_SETFWPATH, strlen(CMD_SETFWPATH)) == 0) {
  2847. bytes_written = wl_android_set_fwpath(net, command, priv_cmd.total_len);
  2848. }
  2849. if (!g_wifi_on) {
  2850. DHD_ERROR(("%s: Ignore private cmd \"%s\" - iface %s is down\n",
  2851. __FUNCTION__, command, ifr->ifr_name));
  2852. ret = 0;
  2853. goto exit;
  2854. }
  2855. if (strnicmp(command, CMD_STOP, strlen(CMD_STOP)) == 0) {
  2856. #ifdef SUPPORT_DEEP_SLEEP
  2857. trigger_deep_sleep = 1;
  2858. #else
  2859. bytes_written = wl_android_wifi_off(net);
  2860. #endif /* SUPPORT_DEEP_SLEEP */
  2861. }
  2862. else if (strnicmp(command, CMD_SCAN_ACTIVE, strlen(CMD_SCAN_ACTIVE)) == 0) {
  2863. /* TBD: SCAN-ACTIVE */
  2864. }
  2865. else if (strnicmp(command, CMD_SCAN_PASSIVE, strlen(CMD_SCAN_PASSIVE)) == 0) {
  2866. /* TBD: SCAN-PASSIVE */
  2867. }
  2868. else if (strnicmp(command, CMD_RSSI, strlen(CMD_RSSI)) == 0) {
  2869. bytes_written = wl_android_get_rssi(net, command, priv_cmd.total_len);
  2870. }
  2871. else if (strnicmp(command, CMD_LINKSPEED, strlen(CMD_LINKSPEED)) == 0) {
  2872. bytes_written = wl_android_get_link_speed(net, command, priv_cmd.total_len);
  2873. }
  2874. #ifdef PKT_FILTER_SUPPORT
  2875. else if (strnicmp(command, CMD_RXFILTER_START, strlen(CMD_RXFILTER_START)) == 0) {
  2876. bytes_written = net_os_enable_packet_filter(net, 1);
  2877. }
  2878. else if (strnicmp(command, CMD_RXFILTER_STOP, strlen(CMD_RXFILTER_STOP)) == 0) {
  2879. bytes_written = net_os_enable_packet_filter(net, 0);
  2880. }
  2881. else if (strnicmp(command, CMD_RXFILTER_ADD, strlen(CMD_RXFILTER_ADD)) == 0) {
  2882. int filter_num = *(command + strlen(CMD_RXFILTER_ADD) + 1) - '0';
  2883. bytes_written = net_os_rxfilter_add_remove(net, TRUE, filter_num);
  2884. }
  2885. else if (strnicmp(command, CMD_RXFILTER_REMOVE, strlen(CMD_RXFILTER_REMOVE)) == 0) {
  2886. int filter_num = *(command + strlen(CMD_RXFILTER_REMOVE) + 1) - '0';
  2887. bytes_written = net_os_rxfilter_add_remove(net, FALSE, filter_num);
  2888. }
  2889. #endif /* PKT_FILTER_SUPPORT */
  2890. else if (strnicmp(command, CMD_BTCOEXSCAN_START, strlen(CMD_BTCOEXSCAN_START)) == 0) {
  2891. /* TBD: BTCOEXSCAN-START */
  2892. }
  2893. else if (strnicmp(command, CMD_BTCOEXSCAN_STOP, strlen(CMD_BTCOEXSCAN_STOP)) == 0) {
  2894. /* TBD: BTCOEXSCAN-STOP */
  2895. }
  2896. else if (strnicmp(command, CMD_BTCOEXMODE, strlen(CMD_BTCOEXMODE)) == 0) {
  2897. #ifdef WL_CFG80211
  2898. void *dhdp = wl_cfg80211_get_dhdp();
  2899. bytes_written = wl_cfg80211_set_btcoex_dhcp(net, dhdp, command);
  2900. #else
  2901. #ifdef PKT_FILTER_SUPPORT
  2902. uint mode = *(command + strlen(CMD_BTCOEXMODE) + 1) - '0';
  2903. if (mode == 1)
  2904. net_os_enable_packet_filter(net, 0); /* DHCP starts */
  2905. else
  2906. net_os_enable_packet_filter(net, 1); /* DHCP ends */
  2907. #endif /* PKT_FILTER_SUPPORT */
  2908. #endif /* WL_CFG80211 */
  2909. }
  2910. else if (strnicmp(command, CMD_SETSUSPENDOPT, strlen(CMD_SETSUSPENDOPT)) == 0) {
  2911. bytes_written = wl_android_set_suspendopt(net, command, priv_cmd.total_len);
  2912. }
  2913. else if (strnicmp(command, CMD_SETSUSPENDMODE, strlen(CMD_SETSUSPENDMODE)) == 0) {
  2914. bytes_written = wl_android_set_suspendmode(net, command, priv_cmd.total_len);
  2915. }
  2916. else if (strnicmp(command, CMD_SETBAND, strlen(CMD_SETBAND)) == 0) {
  2917. uint band = *(command + strlen(CMD_SETBAND) + 1) - '0';
  2918. #ifdef WL_HOST_BAND_MGMT
  2919. s32 ret = 0;
  2920. if ((ret = wl_cfg80211_set_band(net, band)) < 0) {
  2921. if (ret == BCME_UNSUPPORTED) {
  2922. /* If roam_var is unsupported, fallback to the original method */
  2923. WL_ERR(("WL_HOST_BAND_MGMT defined, "
  2924. "but roam_band iovar unsupported in the firmware\n"));
  2925. } else {
  2926. bytes_written = -1;
  2927. goto exit;
  2928. }
  2929. }
  2930. if ((band == WLC_BAND_AUTO) || (ret == BCME_UNSUPPORTED))
  2931. bytes_written = wldev_set_band(net, band);
  2932. #else
  2933. bytes_written = wldev_set_band(net, band);
  2934. #endif /* WL_HOST_BAND_MGMT */
  2935. #if defined(CUSTOMER_HW4) && defined(ROAM_CHANNEL_CACHE)
  2936. wl_update_roamscan_cache_by_band(net, band);
  2937. #endif
  2938. }
  2939. else if (strnicmp(command, CMD_GETBAND, strlen(CMD_GETBAND)) == 0) {
  2940. bytes_written = wl_android_get_band(net, command, priv_cmd.total_len);
  2941. }
  2942. #ifdef WL_CFG80211
  2943. #ifndef CUSTOMER_SET_COUNTRY
  2944. /* CUSTOMER_SET_COUNTRY feature is define for only GGSM model */
  2945. else if (strnicmp(command, CMD_COUNTRY, strlen(CMD_COUNTRY)) == 0) {
  2946. char *country_code = command + strlen(CMD_COUNTRY) + 1;
  2947. bytes_written = wldev_set_country(net, country_code, true, true);
  2948. }
  2949. #endif /* CUSTOMER_SET_COUNTRY */
  2950. #endif /* WL_CFG80211 */
  2951. #ifdef CUSTOMER_HW4
  2952. #ifdef ROAM_API
  2953. else if (strnicmp(command, CMD_ROAMTRIGGER_SET,
  2954. strlen(CMD_ROAMTRIGGER_SET)) == 0) {
  2955. bytes_written = wl_android_set_roam_trigger(net, command,
  2956. priv_cmd.total_len);
  2957. } else if (strnicmp(command, CMD_ROAMTRIGGER_GET,
  2958. strlen(CMD_ROAMTRIGGER_GET)) == 0) {
  2959. bytes_written = wl_android_get_roam_trigger(net, command,
  2960. priv_cmd.total_len);
  2961. } else if (strnicmp(command, CMD_ROAMDELTA_SET,
  2962. strlen(CMD_ROAMDELTA_SET)) == 0) {
  2963. bytes_written = wl_android_set_roam_delta(net, command,
  2964. priv_cmd.total_len);
  2965. } else if (strnicmp(command, CMD_ROAMDELTA_GET,
  2966. strlen(CMD_ROAMDELTA_GET)) == 0) {
  2967. bytes_written = wl_android_get_roam_delta(net, command,
  2968. priv_cmd.total_len);
  2969. } else if (strnicmp(command, CMD_ROAMSCANPERIOD_SET,
  2970. strlen(CMD_ROAMSCANPERIOD_SET)) == 0) {
  2971. bytes_written = wl_android_set_roam_scan_period(net, command,
  2972. priv_cmd.total_len);
  2973. } else if (strnicmp(command, CMD_ROAMSCANPERIOD_GET,
  2974. strlen(CMD_ROAMSCANPERIOD_GET)) == 0) {
  2975. bytes_written = wl_android_get_roam_scan_period(net, command,
  2976. priv_cmd.total_len);
  2977. } else if (strnicmp(command, CMD_FULLROAMSCANPERIOD_SET,
  2978. strlen(CMD_FULLROAMSCANPERIOD_SET)) == 0) {
  2979. bytes_written = wl_android_set_full_roam_scan_period(net, command,
  2980. priv_cmd.total_len);
  2981. } else if (strnicmp(command, CMD_FULLROAMSCANPERIOD_GET,
  2982. strlen(CMD_FULLROAMSCANPERIOD_GET)) == 0) {
  2983. bytes_written = wl_android_get_full_roam_scan_period(net, command,
  2984. priv_cmd.total_len);
  2985. } else if (strnicmp(command, CMD_COUNTRYREV_SET,
  2986. strlen(CMD_COUNTRYREV_SET)) == 0) {
  2987. bytes_written = wl_android_set_country_rev(net, command,
  2988. priv_cmd.total_len);
  2989. } else if (strnicmp(command, CMD_COUNTRYREV_GET,
  2990. strlen(CMD_COUNTRYREV_GET)) == 0) {
  2991. bytes_written = wl_android_get_country_rev(net, command,
  2992. priv_cmd.total_len);
  2993. }
  2994. #endif /* ROAM_API */
  2995. #ifdef WES_SUPPORT
  2996. else if (strnicmp(command, CMD_GETROAMSCANCONTROL, strlen(CMD_GETROAMSCANCONTROL)) == 0) {
  2997. bytes_written = wl_android_get_roam_scan_control(net, command, priv_cmd.total_len);
  2998. }
  2999. else if (strnicmp(command, CMD_SETROAMSCANCONTROL, strlen(CMD_SETROAMSCANCONTROL)) == 0) {
  3000. bytes_written = wl_android_set_roam_scan_control(net, command, priv_cmd.total_len);
  3001. }
  3002. else if (strnicmp(command, CMD_GETROAMSCANCHANNELS, strlen(CMD_GETROAMSCANCHANNELS)) == 0) {
  3003. bytes_written = wl_android_get_roam_scan_channels(net, command, priv_cmd.total_len);
  3004. }
  3005. else if (strnicmp(command, CMD_SETROAMSCANCHANNELS, strlen(CMD_SETROAMSCANCHANNELS)) == 0) {
  3006. bytes_written = wl_android_set_roam_scan_channels(net, command, priv_cmd.total_len);
  3007. }
  3008. else if (strnicmp(command, CMD_SENDACTIONFRAME, strlen(CMD_SENDACTIONFRAME)) == 0) {
  3009. bytes_written = wl_android_send_action_frame(net, command, priv_cmd.total_len);
  3010. }
  3011. else if (strnicmp(command, CMD_REASSOC, strlen(CMD_REASSOC)) == 0) {
  3012. bytes_written = wl_android_reassoc(net, command, priv_cmd.total_len);
  3013. }
  3014. else if (strnicmp(command, CMD_GETSCANCHANNELTIME, strlen(CMD_GETSCANCHANNELTIME)) == 0) {
  3015. bytes_written = wl_android_get_scan_channel_time(net, command, priv_cmd.total_len);
  3016. }
  3017. else if (strnicmp(command, CMD_SETSCANCHANNELTIME, strlen(CMD_SETSCANCHANNELTIME)) == 0) {
  3018. bytes_written = wl_android_set_scan_channel_time(net, command, priv_cmd.total_len);
  3019. }
  3020. else if (strnicmp(command, CMD_GETSCANHOMETIME, strlen(CMD_GETSCANHOMETIME)) == 0) {
  3021. bytes_written = wl_android_get_scan_home_time(net, command, priv_cmd.total_len);
  3022. }
  3023. else if (strnicmp(command, CMD_SETSCANHOMETIME, strlen(CMD_SETSCANHOMETIME)) == 0) {
  3024. bytes_written = wl_android_set_scan_home_time(net, command, priv_cmd.total_len);
  3025. }
  3026. else if (strnicmp(command, CMD_GETSCANHOMEAWAYTIME, strlen(CMD_GETSCANHOMEAWAYTIME)) == 0) {
  3027. bytes_written = wl_android_get_scan_home_away_time(net, command,
  3028. priv_cmd.total_len);
  3029. }
  3030. else if (strnicmp(command, CMD_SETSCANHOMEAWAYTIME, strlen(CMD_SETSCANHOMEAWAYTIME)) == 0) {
  3031. bytes_written = wl_android_set_scan_home_away_time(net, command,
  3032. priv_cmd.total_len);
  3033. }
  3034. else if (strnicmp(command, CMD_GETSCANNPROBES, strlen(CMD_GETSCANNPROBES)) == 0) {
  3035. bytes_written = wl_android_get_scan_nprobes(net, command, priv_cmd.total_len);
  3036. }
  3037. else if (strnicmp(command, CMD_SETSCANNPROBES, strlen(CMD_SETSCANNPROBES)) == 0) {
  3038. bytes_written = wl_android_set_scan_nprobes(net, command, priv_cmd.total_len);
  3039. }
  3040. else if (strnicmp(command, CMD_GETDFSSCANMODE, strlen(CMD_GETDFSSCANMODE)) == 0) {
  3041. bytes_written = wl_android_get_scan_dfs_channel_mode(net, command,
  3042. priv_cmd.total_len);
  3043. }
  3044. else if (strnicmp(command, CMD_SETDFSSCANMODE, strlen(CMD_SETDFSSCANMODE)) == 0) {
  3045. bytes_written = wl_android_set_scan_dfs_channel_mode(net, command,
  3046. priv_cmd.total_len);
  3047. }
  3048. else if (strnicmp(command, CMD_GETWESMODE, strlen(CMD_GETWESMODE)) == 0) {
  3049. bytes_written = wl_android_get_wes_mode(net, command, priv_cmd.total_len);
  3050. }
  3051. else if (strnicmp(command, CMD_SETWESMODE, strlen(CMD_SETWESMODE)) == 0) {
  3052. bytes_written = wl_android_set_wes_mode(net, command, priv_cmd.total_len);
  3053. }
  3054. else if (strnicmp(command, CMD_GETOKCMODE, strlen(CMD_GETOKCMODE)) == 0) {
  3055. bytes_written = wl_android_get_okc_mode(net, command, priv_cmd.total_len);
  3056. }
  3057. else if (strnicmp(command, CMD_SETOKCMODE, strlen(CMD_SETOKCMODE)) == 0) {
  3058. bytes_written = wl_android_set_okc_mode(net, command, priv_cmd.total_len);
  3059. }
  3060. #endif /* WES_SUPPORT */
  3061. #endif /* CUSTOMER_HW4 */
  3062. #ifdef PNO_SUPPORT
  3063. else if (strnicmp(command, CMD_PNOSSIDCLR_SET, strlen(CMD_PNOSSIDCLR_SET)) == 0) {
  3064. bytes_written = dhd_dev_pno_stop_for_ssid(net);
  3065. }
  3066. #ifndef WL_SCHED_SCAN
  3067. else if (strnicmp(command, CMD_PNOSETUP_SET, strlen(CMD_PNOSETUP_SET)) == 0) {
  3068. bytes_written = wl_android_set_pno_setup(net, command, priv_cmd.total_len);
  3069. }
  3070. #endif /* !WL_SCHED_SCAN */
  3071. else if (strnicmp(command, CMD_PNOENABLE_SET, strlen(CMD_PNOENABLE_SET)) == 0) {
  3072. int enable = *(command + strlen(CMD_PNOENABLE_SET) + 1) - '0';
  3073. bytes_written = (enable)? 0 : dhd_dev_pno_stop_for_ssid(net);
  3074. }
  3075. else if (strnicmp(command, CMD_WLS_BATCHING, strlen(CMD_WLS_BATCHING)) == 0) {
  3076. bytes_written = wls_parse_batching_cmd(net, command, priv_cmd.total_len);
  3077. }
  3078. #endif /* PNO_SUPPORT */
  3079. else if (strnicmp(command, CMD_P2P_DEV_ADDR, strlen(CMD_P2P_DEV_ADDR)) == 0) {
  3080. bytes_written = wl_android_get_p2p_dev_addr(net, command, priv_cmd.total_len);
  3081. }
  3082. else if (strnicmp(command, CMD_P2P_SET_NOA, strlen(CMD_P2P_SET_NOA)) == 0) {
  3083. int skip = strlen(CMD_P2P_SET_NOA) + 1;
  3084. bytes_written = wl_cfg80211_set_p2p_noa(net, command + skip,
  3085. priv_cmd.total_len - skip);
  3086. }
  3087. #if !defined WL_ENABLE_P2P_IF
  3088. else if (strnicmp(command, CMD_P2P_GET_NOA, strlen(CMD_P2P_GET_NOA)) == 0) {
  3089. bytes_written = wl_cfg80211_get_p2p_noa(net, command, priv_cmd.total_len);
  3090. }
  3091. #endif /* WL_ENABLE_P2P_IF */
  3092. else if (strnicmp(command, CMD_P2P_SET_PS, strlen(CMD_P2P_SET_PS)) == 0) {
  3093. int skip = strlen(CMD_P2P_SET_PS) + 1;
  3094. bytes_written = wl_cfg80211_set_p2p_ps(net, command + skip,
  3095. priv_cmd.total_len - skip);
  3096. }
  3097. #ifdef WL_CFG80211
  3098. else if (strnicmp(command, CMD_SET_AP_WPS_P2P_IE,
  3099. strlen(CMD_SET_AP_WPS_P2P_IE)) == 0) {
  3100. int skip = strlen(CMD_SET_AP_WPS_P2P_IE) + 3;
  3101. bytes_written = wl_cfg80211_set_wps_p2p_ie(net, command + skip,
  3102. priv_cmd.total_len - skip, *(command + skip - 2) - '0');
  3103. }
  3104. #ifdef WLFBT
  3105. else if (strnicmp(command, CMD_GET_FTKEY, strlen(CMD_GET_FTKEY)) == 0) {
  3106. wl_cfg80211_get_fbt_key(command);
  3107. bytes_written = FBT_KEYLEN;
  3108. }
  3109. #endif /* WLFBT */
  3110. #endif /* WL_CFG80211 */
  3111. else if (strnicmp(command, CMD_OKC_SET_PMK, strlen(CMD_OKC_SET_PMK)) == 0)
  3112. bytes_written = wl_android_set_pmk(net, command, priv_cmd.total_len);
  3113. else if (strnicmp(command, CMD_OKC_ENABLE, strlen(CMD_OKC_ENABLE)) == 0)
  3114. bytes_written = wl_android_okc_enable(net, command, priv_cmd.total_len);
  3115. #ifdef BCMCCX
  3116. else if (strnicmp(command, CMD_GETCCKM_RN, strlen(CMD_GETCCKM_RN)) == 0) {
  3117. bytes_written = wl_android_get_cckm_rn(net, command);
  3118. }
  3119. else if (strnicmp(command, CMD_SETCCKM_KRK, strlen(CMD_SETCCKM_KRK)) == 0) {
  3120. bytes_written = wl_android_set_cckm_krk(net, command);
  3121. }
  3122. else if (strnicmp(command, CMD_GET_ASSOC_RES_IES, strlen(CMD_GET_ASSOC_RES_IES)) == 0) {
  3123. bytes_written = wl_android_get_assoc_res_ies(net, command);
  3124. }
  3125. #endif /* BCMCCX */
  3126. #if defined(WL_SUPPORT_AUTO_CHANNEL)
  3127. else if (strnicmp(command, CMD_GET_BEST_CHANNELS,
  3128. strlen(CMD_GET_BEST_CHANNELS)) == 0) {
  3129. bytes_written = wl_cfg80211_get_best_channels(net, command,
  3130. priv_cmd.total_len);
  3131. }
  3132. #endif /* WL_SUPPORT_AUTO_CHANNEL */
  3133. #ifdef CUSTOMER_HW4
  3134. #ifdef SUPPORT_AMPDU_MPDU_CMD
  3135. /* CMD_AMPDU_MPDU */
  3136. else if (strnicmp(command, CMD_AMPDU_MPDU, strlen(CMD_AMPDU_MPDU)) == 0) {
  3137. int skip = strlen(CMD_AMPDU_MPDU) + 1;
  3138. bytes_written = wl_android_set_ampdu_mpdu(net, (const char*)command+skip);
  3139. }
  3140. #endif /* SUPPORT_AMPDU_MPDU_CMD */
  3141. #if defined(WL_SUPPORT_AUTO_CHANNEL)
  3142. else if (strnicmp(command, CMD_SET_HAPD_AUTO_CHANNEL,
  3143. strlen(CMD_SET_HAPD_AUTO_CHANNEL)) == 0) {
  3144. int skip = strlen(CMD_SET_HAPD_AUTO_CHANNEL) + 3;
  3145. bytes_written = wl_android_set_auto_channel(net, (const char*)command+skip, command,
  3146. priv_cmd.total_len);
  3147. }
  3148. #endif /* WL_SUPPORT_AUTO_CHANNEL */
  3149. #if defined(SUPPORT_HIDDEN_AP)
  3150. else if (strnicmp(command, CMD_SET_HAPD_MAX_NUM_STA,
  3151. strlen(CMD_SET_HAPD_MAX_NUM_STA)) == 0) {
  3152. int skip = strlen(CMD_SET_HAPD_MAX_NUM_STA) + 3;
  3153. wl_android_set_max_num_sta(net, (const char*)command+skip);
  3154. }
  3155. else if (strnicmp(command, CMD_SET_HAPD_SSID,
  3156. strlen(CMD_SET_HAPD_SSID)) == 0) {
  3157. int skip = strlen(CMD_SET_HAPD_SSID) + 3;
  3158. wl_android_set_ssid(net, (const char*)command+skip);
  3159. }
  3160. else if (strnicmp(command, CMD_SET_HAPD_HIDE_SSID,
  3161. strlen(CMD_SET_HAPD_HIDE_SSID)) == 0) {
  3162. int skip = strlen(CMD_SET_HAPD_HIDE_SSID) + 3;
  3163. wl_android_set_hide_ssid(net, (const char*)command+skip);
  3164. }
  3165. #endif /* SUPPORT_HIDDEN_AP */
  3166. #ifdef SUPPORT_SOFTAP_SINGL_DISASSOC
  3167. else if (strnicmp(command, CMD_HAPD_STA_DISASSOC,
  3168. strlen(CMD_HAPD_STA_DISASSOC)) == 0) {
  3169. int skip = strlen(CMD_HAPD_STA_DISASSOC) + 1;
  3170. wl_android_sta_diassoc(net, (const char*)command+skip);
  3171. }
  3172. #endif /* SUPPORT_SOFTAP_SINGL_DISASSOC */
  3173. #ifdef SUPPORT_SET_LPC
  3174. else if (strnicmp(command, CMD_HAPD_LPC_ENABLED,
  3175. strlen(CMD_HAPD_LPC_ENABLED)) == 0) {
  3176. int skip = strlen(CMD_HAPD_LPC_ENABLED) + 3;
  3177. wl_android_set_lpc(net, (const char*)command+skip);
  3178. }
  3179. #endif /* SUPPORT_SET_LPC */
  3180. #ifdef SUPPORT_TRIGGER_HANG_EVENT
  3181. else if (strnicmp(command, CMD_TEST_FORCE_HANG,
  3182. strlen(CMD_TEST_FORCE_HANG)) == 0) {
  3183. net_os_send_hang_message(net);
  3184. }
  3185. #endif /* SUPPORT_TRIGGER_HANG_EVENT */
  3186. else if (strnicmp(command, CMD_CHANGE_RL, strlen(CMD_CHANGE_RL)) == 0)
  3187. bytes_written = wl_android_ch_res_rl(net, true);
  3188. else if (strnicmp(command, CMD_RESTORE_RL, strlen(CMD_RESTORE_RL)) == 0)
  3189. bytes_written = wl_android_ch_res_rl(net, false);
  3190. #ifdef SUPPORT_LTECX
  3191. else if (strnicmp(command, CMD_LTECX_SET, strlen(CMD_LTECX_SET)) == 0) {
  3192. int skip = strlen(CMD_LTECX_SET) + 1;
  3193. bytes_written = wl_android_set_ltecx(net, (const char*)command+skip);
  3194. }
  3195. #endif /* SUPPORT_LTECX */
  3196. else if (strnicmp(command, CMD_SET_RMC_ENABLE, strlen(CMD_SET_RMC_ENABLE)) == 0) {
  3197. int rmc_enable = *(command + strlen(CMD_SET_RMC_ENABLE) + 1) - '0';
  3198. bytes_written = wl_android_rmc_enable(net, rmc_enable);
  3199. }
  3200. else if (strnicmp(command, CMD_SET_RMC_TXRATE, strlen(CMD_SET_RMC_TXRATE)) == 0) {
  3201. int rmc_txrate;
  3202. sscanf(command, "%*s %10d", &rmc_txrate);
  3203. bytes_written = wldev_iovar_setint(net, "rmc_txrate", rmc_txrate * 2);
  3204. }
  3205. else if (strnicmp(command, CMD_SET_RMC_ACTPERIOD, strlen(CMD_SET_RMC_ACTPERIOD)) == 0) {
  3206. int actperiod;
  3207. sscanf(command, "%*s %10d", &actperiod);
  3208. bytes_written = wldev_iovar_setint(net, "rmc_actf_time", actperiod);
  3209. }
  3210. else if (strnicmp(command, CMD_SET_RMC_IDLEPERIOD, strlen(CMD_SET_RMC_IDLEPERIOD)) == 0) {
  3211. int acktimeout;
  3212. sscanf(command, "%*s %10d", &acktimeout);
  3213. acktimeout *= 1000;
  3214. bytes_written = wldev_iovar_setint(net, "rmc_acktmo", acktimeout);
  3215. }
  3216. else if (strnicmp(command, CMD_SET_RMC_LEADER, strlen(CMD_SET_RMC_LEADER)) == 0) {
  3217. int skip = strlen(CMD_SET_RMC_LEADER) + 1;
  3218. bytes_written = wl_android_rmc_set_leader(net, (const char*)command+skip);
  3219. }
  3220. else if (strnicmp(command, CMD_SET_RMC_EVENT,
  3221. strlen(CMD_SET_RMC_EVENT)) == 0)
  3222. bytes_written = wl_android_set_rmc_event(net, command, priv_cmd.total_len);
  3223. else if (strnicmp(command, CMD_GET_SCSCAN, strlen(CMD_GET_SCSCAN)) == 0) {
  3224. bytes_written = wl_android_get_singlecore_scan(net, command, priv_cmd.total_len);
  3225. }
  3226. else if (strnicmp(command, CMD_SET_SCSCAN, strlen(CMD_SET_SCSCAN)) == 0) {
  3227. bytes_written = wl_android_set_singlecore_scan(net, command, priv_cmd.total_len);
  3228. }
  3229. #ifdef TEST_TX_POWER_CONTROL
  3230. else if (strnicmp(command, CMD_TEST_SET_TX_POWER,
  3231. strlen(CMD_TEST_SET_TX_POWER)) == 0) {
  3232. int skip = strlen(CMD_TEST_SET_TX_POWER) + 1;
  3233. wl_android_set_tx_power(net, (const char*)command+skip);
  3234. }
  3235. else if (strnicmp(command, CMD_TEST_GET_TX_POWER,
  3236. strlen(CMD_TEST_GET_TX_POWER)) == 0) {
  3237. wl_android_get_tx_power(net, command, priv_cmd.total_len);
  3238. }
  3239. #endif /* TEST_TX_POWER_CONTROL */
  3240. #ifdef TX_POWER_CONTROL_CALLING
  3241. else if (strnicmp(command, CMD_SET_TX_POWER_CALLING,
  3242. strlen(CMD_SET_TX_POWER_CALLING)) == 0) {
  3243. int skip = strlen(CMD_SET_TX_POWER_CALLING) + 1;
  3244. wl_android_set_tx_power(net, (const char*)command+skip);
  3245. }
  3246. #endif /* TX_POWER_CONTROL_CALLING */
  3247. #ifdef SARLIMIT_TX_CONTROL_NVRAM
  3248. else if (strnicmp(command, CMD_SARLIMIT_TX_CONTROL,
  3249. strlen(CMD_SARLIMIT_TX_CONTROL)) == 0) {
  3250. int skip = strlen(CMD_SARLIMIT_TX_CONTROL) + 1;
  3251. wl_android_set_sarlimit_txctrl(net, (const char*)command+skip);
  3252. }
  3253. #endif /* SARLIMIT_TX_CONTROL_NVRAM */
  3254. #endif /* CUSTOMER_HW4 */
  3255. else if (strnicmp(command, CMD_HAPD_MAC_FILTER, strlen(CMD_HAPD_MAC_FILTER)) == 0) {
  3256. int skip = strlen(CMD_HAPD_MAC_FILTER) + 1;
  3257. wl_android_set_mac_address_filter(net, (const char*)command+skip);
  3258. }
  3259. else if (strnicmp(command, CMD_SETROAMMODE, strlen(CMD_SETROAMMODE)) == 0)
  3260. bytes_written = wl_android_set_roam_mode(net, command, priv_cmd.total_len);
  3261. #if defined(BCMFW_ROAM_ENABLE)
  3262. else if (strnicmp(command, CMD_SET_ROAMPREF, strlen(CMD_SET_ROAMPREF)) == 0) {
  3263. bytes_written = wl_android_set_roampref(net, command, priv_cmd.total_len);
  3264. }
  3265. #endif /* BCMFW_ROAM_ENABLE */
  3266. else if (strnicmp(command, CMD_MIRACAST, strlen(CMD_MIRACAST)) == 0)
  3267. bytes_written = wl_android_set_miracast(net, command, priv_cmd.total_len);
  3268. else if (strnicmp(command, CMD_SETIBSSBEACONOUIDATA, strlen(CMD_SETIBSSBEACONOUIDATA)) == 0)
  3269. bytes_written = wl_android_set_ibss_beacon_ouidata(net,
  3270. command, priv_cmd.total_len);
  3271. #ifdef WLAIBSS
  3272. else if (strnicmp(command, CMD_SETIBSSTXFAILEVENT,
  3273. strlen(CMD_SETIBSSTXFAILEVENT)) == 0)
  3274. bytes_written = wl_android_set_ibss_txfail_event(net, command, priv_cmd.total_len);
  3275. else if (strnicmp(command, CMD_GET_IBSS_PEER_INFO_ALL,
  3276. strlen(CMD_GET_IBSS_PEER_INFO_ALL)) == 0)
  3277. bytes_written = wl_android_get_ibss_peer_info(net, command, priv_cmd.total_len,
  3278. TRUE);
  3279. else if (strnicmp(command, CMD_GET_IBSS_PEER_INFO,
  3280. strlen(CMD_GET_IBSS_PEER_INFO)) == 0)
  3281. bytes_written = wl_android_get_ibss_peer_info(net, command, priv_cmd.total_len,
  3282. FALSE);
  3283. else if (strnicmp(command, CMD_SETIBSSROUTETABLE,
  3284. strlen(CMD_SETIBSSROUTETABLE)) == 0)
  3285. bytes_written = wl_android_set_ibss_routetable(net, command,
  3286. priv_cmd.total_len);
  3287. else if (strnicmp(command, CMD_SETIBSSAMPDU, strlen(CMD_SETIBSSAMPDU)) == 0)
  3288. bytes_written = wl_android_set_ibss_ampdu(net, command, priv_cmd.total_len);
  3289. else if (strnicmp(command, CMD_SETIBSSANTENNAMODE, strlen(CMD_SETIBSSANTENNAMODE)) == 0)
  3290. bytes_written = wl_android_set_ibss_antenna(net, command, priv_cmd.total_len);
  3291. #endif /* WLAIBSS */
  3292. else if (strnicmp(command, CMD_KEEP_ALIVE, strlen(CMD_KEEP_ALIVE)) == 0) {
  3293. int skip = strlen(CMD_KEEP_ALIVE) + 1;
  3294. bytes_written = wl_keep_alive_set(net, command + skip, priv_cmd.total_len - skip);
  3295. }
  3296. else if (strnicmp(command, CMD_ROAM_OFFLOAD, strlen(CMD_ROAM_OFFLOAD)) == 0) {
  3297. int enable = *(command + strlen(CMD_ROAM_OFFLOAD) + 1) - '0';
  3298. bytes_written = wl_cfg80211_enable_roam_offload(net, enable);
  3299. }
  3300. #ifdef CONNECTION_STATISTICS
  3301. else if (strnicmp(command, CMD_GET_CONNECTION_STATS,
  3302. strlen(CMD_GET_CONNECTION_STATS)) == 0) {
  3303. bytes_written = wl_android_get_connection_stats(net, command,
  3304. priv_cmd.total_len);
  3305. }
  3306. #endif
  3307. else {
  3308. DHD_ERROR(("Unknown PRIVATE command %s - ignored\n", command));
  3309. snprintf(command, 3, "OK");
  3310. bytes_written = strlen("OK");
  3311. }
  3312. if (bytes_written >= 0) {
  3313. if ((bytes_written == 0) && (priv_cmd.total_len > 0))
  3314. command[0] = '\0';
  3315. if (bytes_written >= priv_cmd.total_len) {
  3316. DHD_ERROR(("%s: bytes_written = %d\n", __FUNCTION__, bytes_written));
  3317. bytes_written = priv_cmd.total_len;
  3318. } else {
  3319. bytes_written++;
  3320. }
  3321. priv_cmd.used_len = bytes_written;
  3322. if (copy_to_user(priv_cmd.buf, command, bytes_written)) {
  3323. DHD_ERROR(("%s: failed to copy data to user buffer\n", __FUNCTION__));
  3324. ret = -EFAULT;
  3325. }
  3326. }
  3327. else {
  3328. ret = bytes_written;
  3329. }
  3330. exit:
  3331. net_os_wake_unlock(net);
  3332. if (command) {
  3333. kfree(command);
  3334. }
  3335. return ret;
  3336. }
  3337. int wl_android_init(void)
  3338. {
  3339. int ret = 0;
  3340. #ifdef ENABLE_INSMOD_NO_FW_LOAD
  3341. dhd_download_fw_on_driverload = FALSE;
  3342. #endif /* ENABLE_INSMOD_NO_FW_LOAD */
  3343. #if defined(CUSTOMER_HW2) || defined(CUSTOMER_HW4)
  3344. if (!iface_name[0]) {
  3345. memset(iface_name, 0, IFNAMSIZ);
  3346. bcm_strncpy_s(iface_name, IFNAMSIZ, "wlan", IFNAMSIZ);
  3347. }
  3348. #endif /* CUSTOMER_HW2 || CUSTOMER_HW4 */
  3349. #ifdef WL_GENL
  3350. wl_genl_init();
  3351. #endif
  3352. wl_netlink_init();
  3353. return ret;
  3354. }
  3355. int wl_android_exit(void)
  3356. {
  3357. int ret = 0;
  3358. struct io_cfg *cur, *q;
  3359. #ifdef WL_GENL
  3360. wl_genl_deinit();
  3361. #endif /* WL_GENL */
  3362. wl_netlink_deinit();
  3363. list_for_each_entry_safe(cur, q, &miracast_resume_list, list) {
  3364. list_del(&cur->list);
  3365. kfree(cur);
  3366. }
  3367. return ret;
  3368. }
  3369. void wl_android_post_init(void)
  3370. {
  3371. #ifdef ENABLE_4335BT_WAR
  3372. bcm_bt_unlock(lock_cookie_wifi);
  3373. printk("%s: btlock released\n", __FUNCTION__);
  3374. #endif /* ENABLE_4335BT_WAR */
  3375. if (!dhd_download_fw_on_driverload)
  3376. g_wifi_on = FALSE;
  3377. }
  3378. #ifdef WL_GENL
  3379. /* Generic Netlink Initializaiton */
  3380. static int wl_genl_init(void)
  3381. {
  3382. int ret;
  3383. WL_DBG(("GEN Netlink Init\n\n"));
  3384. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
  3385. /* register new family */
  3386. ret = genl_register_family(&wl_genl_family);
  3387. if (ret != 0)
  3388. goto failure;
  3389. /* register functions (commands) of the new family */
  3390. ret = genl_register_ops(&wl_genl_family, &wl_genl_ops);
  3391. if (ret != 0) {
  3392. WL_ERR(("register ops failed: %i\n", ret));
  3393. genl_unregister_family(&wl_genl_family);
  3394. goto failure;
  3395. }
  3396. ret = genl_register_mc_group(&wl_genl_family, &wl_genl_mcast);
  3397. #else
  3398. ret = genl_register_family_with_ops_groups(&wl_genl_family, wl_genl_ops, wl_genl_mcast);
  3399. #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) */
  3400. if (ret != 0) {
  3401. WL_ERR(("register mc_group failed: %i\n", ret));
  3402. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
  3403. genl_unregister_ops(&wl_genl_family, &wl_genl_ops);
  3404. #endif
  3405. genl_unregister_family(&wl_genl_family);
  3406. goto failure;
  3407. }
  3408. return 0;
  3409. failure:
  3410. WL_ERR(("Registering Netlink failed!!\n"));
  3411. return -1;
  3412. }
  3413. /* Generic netlink deinit */
  3414. static int wl_genl_deinit(void)
  3415. {
  3416. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
  3417. if (genl_unregister_ops(&wl_genl_family, &wl_genl_ops) < 0)
  3418. WL_ERR(("Unregister wl_genl_ops failed\n"));
  3419. #endif
  3420. if (genl_unregister_family(&wl_genl_family) < 0)
  3421. WL_ERR(("Unregister wl_genl_ops failed\n"));
  3422. return 0;
  3423. }
  3424. s32 wl_event_to_bcm_event(u16 event_type)
  3425. {
  3426. u16 event = -1;
  3427. switch (event_type) {
  3428. case WLC_E_SERVICE_FOUND:
  3429. event = BCM_E_SVC_FOUND;
  3430. break;
  3431. case WLC_E_P2PO_ADD_DEVICE:
  3432. event = BCM_E_DEV_FOUND;
  3433. break;
  3434. case WLC_E_P2PO_DEL_DEVICE:
  3435. event = BCM_E_DEV_LOST;
  3436. break;
  3437. /* Above events are supported from BCM Supp ver 47 Onwards */
  3438. default:
  3439. WL_ERR(("Event not supported\n"));
  3440. }
  3441. return event;
  3442. }
  3443. s32
  3444. wl_genl_send_msg(
  3445. struct net_device *ndev,
  3446. u32 event_type,
  3447. u8 *buf,
  3448. u16 len,
  3449. u8 *subhdr,
  3450. u16 subhdr_len)
  3451. {
  3452. int ret = 0;
  3453. struct sk_buff *skb;
  3454. void *msg;
  3455. u32 attr_type = 0;
  3456. bcm_event_hdr_t *hdr = NULL;
  3457. int mcast = 1; /* By default sent as mutlicast type */
  3458. int pid = 0;
  3459. u8 *ptr = NULL, *p = NULL;
  3460. u32 tot_len = sizeof(bcm_event_hdr_t) + subhdr_len + len;
  3461. u16 kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
  3462. WL_DBG(("Enter \n"));
  3463. /* Decide between STRING event and Data event */
  3464. if (event_type == 0)
  3465. attr_type = BCM_GENL_ATTR_STRING;
  3466. else
  3467. attr_type = BCM_GENL_ATTR_MSG;
  3468. skb = genlmsg_new(NLMSG_GOODSIZE, kflags);
  3469. if (skb == NULL) {
  3470. ret = -ENOMEM;
  3471. goto out;
  3472. }
  3473. msg = genlmsg_put(skb, 0, 0, &wl_genl_family, 0, BCM_GENL_CMD_MSG);
  3474. if (msg == NULL) {
  3475. ret = -ENOMEM;
  3476. goto out;
  3477. }
  3478. if (attr_type == BCM_GENL_ATTR_STRING) {
  3479. /* Add a BCM_GENL_MSG attribute. Since it is specified as a string.
  3480. * make sure it is null terminated
  3481. */
  3482. if (subhdr || subhdr_len) {
  3483. WL_ERR(("No sub hdr support for the ATTR STRING type \n"));
  3484. ret = -EINVAL;
  3485. goto out;
  3486. }
  3487. ret = nla_put_string(skb, BCM_GENL_ATTR_STRING, buf);
  3488. if (ret != 0) {
  3489. WL_ERR(("nla_put_string failed\n"));
  3490. goto out;
  3491. }
  3492. } else {
  3493. /* ATTR_MSG */
  3494. /* Create a single buffer for all */
  3495. p = ptr = kzalloc(tot_len, kflags);
  3496. if (!ptr) {
  3497. ret = -ENOMEM;
  3498. WL_ERR(("ENOMEM!!\n"));
  3499. goto out;
  3500. }
  3501. /* Include the bcm event header */
  3502. hdr = (bcm_event_hdr_t *)ptr;
  3503. hdr->event_type = wl_event_to_bcm_event(event_type);
  3504. hdr->len = len + subhdr_len;
  3505. ptr += sizeof(bcm_event_hdr_t);
  3506. /* Copy subhdr (if any) */
  3507. if (subhdr && subhdr_len) {
  3508. memcpy(ptr, subhdr, subhdr_len);
  3509. ptr += subhdr_len;
  3510. }
  3511. /* Copy the data */
  3512. if (buf && len) {
  3513. memcpy(ptr, buf, len);
  3514. }
  3515. ret = nla_put(skb, BCM_GENL_ATTR_MSG, tot_len, p);
  3516. if (ret != 0) {
  3517. WL_ERR(("nla_put_string failed\n"));
  3518. goto out;
  3519. }
  3520. }
  3521. if (mcast) {
  3522. int err = 0;
  3523. /* finalize the message */
  3524. genlmsg_end(skb, msg);
  3525. /* NETLINK_CB(skb).dst_group = 1; */
  3526. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
  3527. if ((err = genlmsg_multicast(skb, 0, wl_genl_mcast.id, GFP_ATOMIC)) < 0)
  3528. #else
  3529. if ((err = genlmsg_multicast(&wl_genl_family, skb, 0, 0, GFP_ATOMIC)) < 0)
  3530. #endif
  3531. WL_ERR(("genlmsg_multicast for attr(%d) failed. Error:%d \n",
  3532. attr_type, err));
  3533. else
  3534. WL_DBG(("Multicast msg sent successfully. attr_type:%d len:%d \n",
  3535. attr_type, tot_len));
  3536. } else {
  3537. NETLINK_CB(skb).dst_group = 0; /* Not in multicast group */
  3538. /* finalize the message */
  3539. genlmsg_end(skb, msg);
  3540. /* send the message back */
  3541. if (genlmsg_unicast(&init_net, skb, pid) < 0)
  3542. WL_ERR(("genlmsg_unicast failed\n"));
  3543. }
  3544. out:
  3545. if (p)
  3546. kfree(p);
  3547. if (ret)
  3548. nlmsg_free(skb);
  3549. return ret;
  3550. }
  3551. static s32
  3552. wl_genl_handle_msg(
  3553. struct sk_buff *skb,
  3554. struct genl_info *info)
  3555. {
  3556. struct nlattr *na;
  3557. u8 *data = NULL;
  3558. WL_DBG(("Enter \n"));
  3559. if (info == NULL) {
  3560. return -EINVAL;
  3561. }
  3562. na = info->attrs[BCM_GENL_ATTR_MSG];
  3563. if (!na) {
  3564. WL_ERR(("nlattribute NULL\n"));
  3565. return -EINVAL;
  3566. }
  3567. data = (char *)nla_data(na);
  3568. if (!data) {
  3569. WL_ERR(("Invalid data\n"));
  3570. return -EINVAL;
  3571. } else {
  3572. /* Handle the data */
  3573. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)) || defined(WL_COMPAT_WIRELESS)
  3574. WL_DBG(("%s: Data received from pid (%d) \n", __func__,
  3575. info->snd_pid));
  3576. #else
  3577. WL_DBG(("%s: Data received from pid (%d) \n", __func__,
  3578. info->snd_portid));
  3579. #endif /* (LINUX_VERSION < VERSION(3, 7, 0) || WL_COMPAT_WIRELESS */
  3580. }
  3581. return 0;
  3582. }
  3583. #endif /* WL_GENL */