gl_p2p.c 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual license. When you use or
  4. * distribute this software, you may choose to be licensed under
  5. * version 2 of the GNU General Public License ("GPLv2 License")
  6. * or BSD License.
  7. *
  8. * GPLv2 License
  9. *
  10. * Copyright(C) 2016 MediaTek Inc.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. * See http://www.gnu.org/licenses/gpl-2.0.html for more details.
  20. *
  21. * BSD LICENSE
  22. *
  23. * Copyright(C) 2016 MediaTek Inc. All rights reserved.
  24. *
  25. * Redistribution and use in source and binary forms, with or without
  26. * modification, are permitted provided that the following conditions
  27. * are met:
  28. *
  29. * * Redistributions of source code must retain the above copyright
  30. * notice, this list of conditions and the following disclaimer.
  31. * * Redistributions in binary form must reproduce the above copyright
  32. * notice, this list of conditions and the following disclaimer in
  33. * the documentation and/or other materials provided with the
  34. * distribution.
  35. * * Neither the name of the copyright holder nor the names of its
  36. * contributors may be used to endorse or promote products derived
  37. * from this software without specific prior written permission.
  38. *
  39. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  40. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  41. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  42. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  43. * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  44. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  45. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  46. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  47. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  48. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  49. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50. *
  51. *****************************************************************************/
  52. /*
  53. ** Id: @(#) gl_p2p.c@@
  54. */
  55. /*! \file gl_p2p.c
  56. \brief Main routines of Linux driver interface for Wi-Fi Direct
  57. This file contains the main routines of Linux driver for MediaTek Inc. 802.11
  58. Wireless LAN Adapters.
  59. */
  60. /*
  61. ** Log: gl_p2p.c
  62. **
  63. ** 09 12 2012 wcpadmin
  64. ** [ALPS00276400] Remove MTK copyright and legal header on GPL/LGPL related packages
  65. ** .
  66. **
  67. ** 08 17 2012 yuche.tsai
  68. ** NULL
  69. ** Fix compile warning.
  70. **
  71. ** 08 16 2012 yuche.tsai
  72. ** NULL
  73. ** Fix compile warning.
  74. **
  75. ** 08 14 2012 yuche.tsai
  76. ** NULL
  77. ** FPB from ALPS.JB to phase 2 release.
  78. **
  79. ** 07 26 2012 yuche.tsai
  80. ** [ALPS00324337] [ALPS.JB][Hot-Spot] Driver update for Hot-Spot
  81. ** Update driver code of ALPS.JB for hot-spot.
  82. **
  83. ** 07 19 2012 yuche.tsai
  84. ** NULL
  85. ** Code update for JB.
  86. *
  87. * 07 17 2012 yuche.tsai
  88. * NULL
  89. * Fix compile error for JB.
  90. *
  91. * 07 17 2012 yuche.tsai
  92. * NULL
  93. * Let netdev bring up.
  94. *
  95. * 07 17 2012 yuche.tsai
  96. * NULL
  97. * Compile no error before trial run.
  98. *
  99. * 01 09 2012 terry.wu
  100. * [WCXRP00001166] [Wi-Fi] [Driver] cfg80211 integration for p2p newtork
  101. * cfg80211 integration for p2p network.
  102. *
  103. * 12 19 2011 terry.wu
  104. * [WCXRP00001142] [Wi-Fi] [P2P Driver] XOR local admin bit to generate p2p net device MAC
  105. * XOR local administrated bit to generate net device MAC of p2p network.
  106. *
  107. * 12 02 2011 yuche.tsai
  108. * NULL
  109. * Fix possible KE when unload p2p.
  110. *
  111. * 11 24 2011 yuche.tsai
  112. * NULL
  113. * Fix P2P IOCTL of multicast address bug, add low power driver stop control.
  114. *
  115. * 11 22 2011 yuche.tsai
  116. * NULL
  117. * Update RSSI link quality of P2P Network query method. (Bug fix)
  118. *
  119. * 11 19 2011 yuche.tsai
  120. * NULL
  121. * Add RSSI support for P2P network.
  122. *
  123. * 11 16 2011 yuche.tsai
  124. * [WCXRP00001107] [Volunteer Patch][Driver] Large Network Type index assert in FW issue.
  125. * Avoid using work thread in set p2p multicast address callback.
  126. *
  127. * 11 11 2011 yuche.tsai
  128. * NULL
  129. * Fix work thread cancel issue.
  130. *
  131. * 11 11 2011 yuche.tsai
  132. * NULL
  133. * Fix default device name issue.
  134. *
  135. * 11 08 2011 yuche.tsai
  136. * [WCXRP00001094] [Volunteer Patch][Driver] Driver version & supplicant version query & set support for service
  137. * discovery version check.
  138. * Add support for driver version query & p2p supplicant verseion set.
  139. * For new service discovery mechanism sync.
  140. *
  141. * 11 07 2011 yuche.tsai
  142. * NULL
  143. * [ALPS 00087243] KE in worker thread.
  144. * The multicast address list is scheduled in worker thread.
  145. * Before the worker thread is excuted, if P2P is unloaded, a KE may occur.
  146. *
  147. * 10 26 2011 terry.wu
  148. * [WCXRP00001066] [MT6620 Wi-Fi] [P2P Driver] Fix P2P Oid Issue
  149. * Fix some P2P OID functions didn't raise its flag "fgIsP2pOid" issue.
  150. *
  151. * 10 25 2011 cm.chang
  152. * [WCXRP00001058] [All Wi-Fi][Driver] Fix sta_rec's phyTypeSet and OBSS scan in AP mode
  153. * .
  154. *
  155. * 10 18 2011 yuche.tsai
  156. * [WCXRP00001045] [WiFi Direct][Driver] Check 2.1 branch.
  157. * Support Channel Query.
  158. *
  159. * 10 18 2011 yuche.tsai
  160. * [WCXRP00001045] [WiFi Direct][Driver] Check 2.1 branch.
  161. * New 2.1 branch
  162. *
  163. * 08 26 2011 yuche.tsai
  164. * NULL
  165. * Fix bug of parsing secondary device list type issue.
  166. *
  167. * 08 24 2011 yuche.tsai
  168. * [WCXRP00000919] [Volunteer Patch][WiFi Direct][Driver] Invitation New Feature.
  169. * Invitation Abort.
  170. *
  171. * 08 23 2011 yuche.tsai
  172. * NULL
  173. * Fix multicast address list issue of P2P.
  174. *
  175. * 08 22 2011 chinglan.wang
  176. * NULL
  177. * Fix invitation indication bug..
  178. *
  179. * 08 16 2011 cp.wu
  180. * [WCXRP00000934] [MT6620 Wi-Fi][Driver][P2P] Wi-Fi hot spot with auto sparse channel residence
  181. * auto channel decision for 2.4GHz hot spot mode
  182. *
  183. * 08 16 2011 chinglan.wang
  184. * NULL
  185. * Add the group id information in the invitation indication.
  186. *
  187. * 08 09 2011 yuche.tsai
  188. * [WCXRP00000919] [Volunteer Patch][WiFi Direct][Driver] Invitation New Feature.
  189. * Invitation Feature add on.
  190. *
  191. * 08 05 2011 yuche.tsai
  192. * [WCXRP00000856] [Volunteer Patch][WiFi Direct][Driver] MT6620 WiFi Direct IOT Issue with BCM solution.
  193. * Add Password ID check for quick connection.
  194. * Also modify some connection policy.
  195. *
  196. * 07 18 2011 chinglan.wang
  197. * NULL
  198. * Add IOC_P2P_GO_WSC_IE (p2p capability).
  199. *
  200. * 06 14 2011 yuche.tsai
  201. * NULL
  202. * Add compile flag to disable persistent group support.
  203. *
  204. * 05 04 2011 chinglan.wang
  205. * [WCXRP00000698] [MT6620 Wi-Fi][P2P][Driver] Add p2p invitation command for the p2p driver
  206. * .
  207. *
  208. * 05 02 2011 yuche.tsai
  209. * [WCXRP00000693] [Volunteer Patch][MT6620][Driver] Clear Formation Flag after TX lifetime timeout.
  210. * Clear formation flag after formation timeout.
  211. *
  212. * 04 22 2011 george.huang
  213. * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
  214. * .
  215. *
  216. * 04 21 2011 george.huang
  217. * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
  218. * 1. Revise P2P power mode setting.
  219. * 2. Revise fast-PS for concurrent
  220. *
  221. * 04 19 2011 wh.su
  222. * NULL
  223. * Adding length check before doing WPA RSN IE parsing for scan results indicate.
  224. *
  225. * 04 14 2011 yuche.tsai
  226. * [WCXRP00000646] [Volunteer Patch][MT6620][FW/Driver] Sigma Test Modification for some test case.
  227. * Connection flow refine for Sigma test.
  228. *
  229. * 04 08 2011 yuche.tsai
  230. * [WCXRP00000624] [Volunteer Patch][MT6620][Driver] Add device discoverability support for GO.
  231. * Add device discoverability support.
  232. *
  233. * 04 08 2011 george.huang
  234. * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
  235. * separate settings of P2P and AIS
  236. *
  237. * 04 07 2011 terry.wu
  238. * [WCXRP00000619] [MT6620 Wi-Fi][Driver] fix kernel panic may occur when removing wlan
  239. * Fix kernel panic may occur when removing wlan driver.
  240. *
  241. * 03 31 2011 wh.su
  242. * [WCXRP00000614] [MT6620 Wi-Fi][Driver] P2P: Update beacon content while setting WSC IE
  243. * Update the wsc ie to beacon content.
  244. *
  245. * 03 25 2011 wh.su
  246. * NULL
  247. * add the sample code for set power mode and get power mode.
  248. *
  249. * 03 25 2011 yuche.tsai
  250. * NULL
  251. * Improve some error handleing.
  252. *
  253. * 03 22 2011 george.huang
  254. * [WCXRP00000504] [MT6620 Wi-Fi][FW] Support Sigma CAPI for power saving related command
  255. * link with supplicant commands
  256. *
  257. * 03 22 2011 yuche.tsai
  258. * [WCXRP00000584] [Volunteer Patch][MT6620][Driver] Add beacon timeout support for WiFi Direct.
  259. * Modify formation policy.
  260. *
  261. * 03 22 2011 yuche.tsai
  262. * NULL
  263. * Modify formation policy setting.
  264. *
  265. * 03 18 2011 yuche.tsai
  266. * [WCXRP00000574] [Volunteer Patch][MT6620][Driver] Modify P2P FSM Connection Flow
  267. * Modify connection flow after Group Formation Complete, or device connect to a GO.
  268. * Instead of request channel & connect directly, we use scan to allocate channel bandwidth & connect after RX BCN.
  269. *
  270. * 03 15 2011 wh.su
  271. * [WCXRP00000563] [MT6620 Wi-Fi] [P2P] Set local config method while set password Id ready
  272. * set lccal config method method while set password Id ready.
  273. *
  274. * 03 15 2011 yuche.tsai
  275. * [WCXRP00000560] [Volunteer Patch][MT6620][Driver] P2P Connection from UI using KEY/DISPLAY issue
  276. * Fix some configure method issue.
  277. *
  278. * 03 15 2011 jeffrey.chang
  279. * [WCXRP00000558] [MT6620 Wi-Fi][MT6620 Wi-Fi][Driver] refine the queue selection algorithm for WMM
  280. * refine queue_select function
  281. *
  282. * 03 13 2011 wh.su
  283. * [WCXRP00000530] [MT6620 Wi-Fi] [Driver] skip doing p2pRunEventAAAComplete after send assoc response Tx Done
  284. * add code for avoid compiling warning.
  285. *
  286. * 03 10 2011 yuche.tsai
  287. * NULL
  288. * Add P2P API.
  289. *
  290. * 03 10 2011 terry.wu
  291. * [WCXRP00000505] [MT6620 Wi-Fi][Driver/FW] WiFi Direct Integration
  292. * Remove unnecessary assert and message.
  293. *
  294. * 03 08 2011 wh.su
  295. * [WCXRP00000488] [MT6620 Wi-Fi][Driver] Support the SIGMA set p2p parameter to driver
  296. * support the power save related p2p setting.
  297. *
  298. * 03 07 2011 wh.su
  299. * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
  300. * rename the define to anti_pviracy.
  301. *
  302. * 03 05 2011 wh.su
  303. * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
  304. * add the code to get the check rsponse and indicate to app.
  305. *
  306. * 03 03 2011 jeffrey.chang
  307. * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
  308. * support concurrent network
  309. *
  310. * 03 03 2011 jeffrey.chang
  311. * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
  312. * modify P2P's netdevice functions to support multiple H/W queues
  313. *
  314. * 03 03 2011 cp.wu
  315. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  316. * Discovery
  317. * for get request, the buffer length to be copied is header + payload.
  318. *
  319. * 03 02 2011 wh.su
  320. * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
  321. * add code to let the beacon and probe response for Auto GO WSC .
  322. *
  323. * 03 02 2011 cp.wu
  324. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  325. * Discovery
  326. * add a missed break.
  327. *
  328. * 03 01 2011 yuche.tsai
  329. * [WCXRP00000501] [Volunteer Patch][MT6620][Driver] No common channel issue when doing GO formation
  330. * Update channel issue when doing GO formation..
  331. *
  332. * 02 25 2011 wh.su
  333. * [WCXRP00000488] [MT6620 Wi-Fi][Driver] Support the SIGMA set p2p parameter to driver
  334. * add the Operation channel setting.
  335. *
  336. * 02 23 2011 wh.su
  337. * [WCXRP00000488] [MT6620 Wi-Fi][Driver] Support the SIGMA set p2p parameter to driver
  338. * fixed the set int ioctl set index and value map to driver issue.
  339. *
  340. * 02 22 2011 wh.su
  341. * [WCXRP00000488] [MT6620 Wi-Fi][Driver] Support the SIGMA set p2p parameter to driver
  342. * adding the ioctl set int from supplicant, and can used to set the p2p parameters
  343. *
  344. * 02 21 2011 terry.wu
  345. * [WCXRP00000476] [MT6620 Wi-Fi][Driver] Clean P2P scan list while removing P2P
  346. * Clean P2P scan list while removing P2P.
  347. *
  348. * 02 18 2011 wh.su
  349. * [WCXRP00000471] [MT6620 Wi-Fi][Driver] Add P2P Provison discovery append Config Method attribute at WSC IE
  350. * fixed the ioctl setting that index not map to spec defined config method.
  351. *
  352. * 02 17 2011 wh.su
  353. * [WCXRP00000471] [MT6620 Wi-Fi][Driver] Add P2P Provison discovery append Config Method attribute at WSC IE
  354. * append the WSC IE config method attribute at provision discovery request.
  355. *
  356. * 02 17 2011 wh.su
  357. * [WCXRP00000448] [MT6620 Wi-Fi][Driver] Fixed WSC IE not send out at probe request
  358. * modify the structure pointer for set WSC IE.
  359. *
  360. * 02 16 2011 wh.su
  361. * [WCXRP00000448] [MT6620 Wi-Fi][Driver] Fixed WSC IE not send out at probe request
  362. * fixed the probe request send out without WSC IE issue (at P2P).
  363. *
  364. * 02 09 2011 cp.wu
  365. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  366. * Discovery
  367. * fix typo
  368. *
  369. * 02 09 2011 yuche.tsai
  370. * [WCXRP00000431] [Volunteer Patch][MT6620][Driver] Add MLME support for deauthentication under AP(Hot-Spot) mode.
  371. * Add Support for MLME deauthentication for Hot-Spot.
  372. *
  373. * 01 25 2011 terry.wu
  374. * [WCXRP00000393] [MT6620 Wi-Fi][Driver] Add new module insert parameter
  375. * Add a new module parameter to indicate current runnig mode, P2P or AP.
  376. *
  377. * 01 12 2011 yuche.tsai
  378. * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
  379. * 1. Modify Channel Acquire Time of AP mode from 5s to 1s.
  380. * 2. Call cnmP2pIsPermit() before active P2P network.
  381. * 3. Add channel selection support for AP mode.
  382. *
  383. * 01 05 2011 cp.wu
  384. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  385. * Discovery
  386. * ioctl implementations for P2P Service Discovery
  387. *
  388. * 01 04 2011 cp.wu
  389. * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease
  390. * physically continuous memory demands
  391. * separate kalMemAlloc() into virtually-continuous and physically-continuous type to ease slab system pressure
  392. *
  393. * 12 22 2010 cp.wu
  394. * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service
  395. * Discovery
  396. * 1. header file restructure for more clear module isolation
  397. * 2. add function interface definition for implementing Service Discovery callbacks
  398. *
  399. * 12 15 2010 cp.wu
  400. * NULL
  401. * invoke nicEnableInterrupt() before leaving from wlanAdapterStart()
  402. *
  403. * 12 08 2010 yuche.tsai
  404. * [WCXRP00000245] [MT6620][Driver] Invitation & Provision Discovery Feature Check-in
  405. * [WCXRP000000245][MT6620][Driver] Invitation Request Feature Add
  406. *
  407. * 11 30 2010 yuche.tsai
  408. * NULL
  409. * Invitation & Provision Discovery Indication.
  410. *
  411. * 11 17 2010 wh.su
  412. * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID[WCXRP00000179] [MT6620 Wi-Fi][FW] Set the Tx
  413. * lowest rate at wlan table for normal operation
  414. * fixed some ASSERT check.
  415. *
  416. * 11 04 2010 wh.su
  417. * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID
  418. * adding the p2p random ssid support.
  419. *
  420. * 10 20 2010 wh.su
  421. * [WCXRP00000124] [MT6620 Wi-Fi] [Driver] Support the dissolve P2P Group
  422. * Add the code to support disconnect p2p group
  423. *
  424. * 10 04 2010 wh.su
  425. * [WCXRP00000081] [MT6620][Driver] Fix the compiling error at WinXP while enable P2P
  426. * add a kal function for set cipher.
  427. *
  428. * 10 04 2010 wh.su
  429. * [WCXRP00000081] [MT6620][Driver] Fix the compiling error at WinXP while enable P2P
  430. * fixed compiling error while enable p2p.
  431. *
  432. * 09 28 2010 wh.su
  433. * NULL
  434. * [WCXRP00000069][MT6620 Wi-Fi][Driver] Fix some code for phase 1 P2P Demo.
  435. *
  436. * 09 21 2010 kevin.huang
  437. * [WCXRP00000054] [MT6620 Wi-Fi][Driver] Restructure driver for second Interface
  438. * Isolate P2P related function for Hardware Software Bundle
  439. *
  440. * 09 21 2010 kevin.huang
  441. * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
  442. * Eliminate Linux Compile Warning
  443. *
  444. * 09 10 2010 george.huang
  445. * NULL
  446. * update iwpriv LP related
  447. *
  448. * 09 10 2010 wh.su
  449. * NULL
  450. * fixed the compiling error at win XP.
  451. *
  452. * 09 09 2010 cp.wu
  453. * NULL
  454. * add WPS/WPA/RSN IE for Wi-Fi Direct scanning result.
  455. *
  456. * 09 07 2010 wh.su
  457. * NULL
  458. * adding the code for beacon/probe req/ probe rsp wsc ie at p2p.
  459. *
  460. * 09 06 2010 wh.su
  461. * NULL
  462. * let the p2p can set the privacy bit at beacon and rsn ie at assoc req at key handshake state.
  463. *
  464. * 08 25 2010 cp.wu
  465. * NULL
  466. * add netdev_ops(NDO) for linux kernel 2.6.31 or greater
  467. *
  468. * 08 23 2010 cp.wu
  469. * NULL
  470. * revise constant definitions to be matched with implementation (original cmd-event definition is deprecated)
  471. *
  472. * 08 20 2010 cp.wu
  473. * NULL
  474. * correct typo.
  475. *
  476. * 08 20 2010 yuche.tsai
  477. * NULL
  478. * Invert Connection request provision status parameter.
  479. *
  480. * 08 19 2010 cp.wu
  481. * NULL
  482. * add set mac address interface for further possibilities of wpa_supplicant overriding interface address.
  483. *
  484. * 08 18 2010 cp.wu
  485. * NULL
  486. * modify pwp ioctls attribution by removing FIXED_SIZE.
  487. *
  488. * 08 18 2010 jeffrey.chang
  489. * NULL
  490. * support multi-function sdio
  491. *
  492. * 08 17 2010 cp.wu
  493. * NULL
  494. * correct p2p net device registration with NULL pointer access issue.
  495. *
  496. * 08 16 2010 cp.wu
  497. * NULL
  498. * P2P packets are now marked when being queued into driver, and identified later without checking MAC address
  499. *
  500. * 08 16 2010 cp.wu
  501. * NULL
  502. * add subroutines for P2P to set multicast list.
  503. *
  504. * 08 16 2010 george.huang
  505. * NULL
  506. * add wext handlers to link P2P set PS profile/ network address function (TBD)
  507. *
  508. * 08 16 2010 cp.wu
  509. * NULL
  510. * revised implementation of Wi-Fi Direct io controls.
  511. *
  512. * 08 12 2010 cp.wu
  513. * NULL
  514. * follow-up with ioctl interface update for Wi-Fi Direct application
  515. *
  516. * 08 06 2010 cp.wu
  517. * NULL
  518. * driver hook modifications corresponding to ioctl interface change.
  519. *
  520. * 08 03 2010 cp.wu
  521. * NULL
  522. * add basic support for ioctl of getting scan result. (only address and SSID are reporterd though)
  523. *
  524. * 08 03 2010 cp.wu
  525. * NULL
  526. * [Wi-Fi Direct Driver Hook] change event indication API to be consistent with supplicant
  527. *
  528. * 08 03 2010 cp.wu
  529. * NULL
  530. * surpress compilation warning.
  531. *
  532. * 08 03 2010 cp.wu
  533. * NULL
  534. * [Wi-Fi Direct] add framework for driver hooks
  535. *
  536. * 07 08 2010 cp.wu
  537. *
  538. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  539. *
  540. * 06 23 2010 cp.wu
  541. * [WPD00003833][MT6620 and MT5931] Driver migration
  542. * p2p interface revised to be sync. with HAL
  543. *
  544. * 06 06 2010 kevin.huang
  545. * [WPD00003832][MT6620 5931] Create driver base
  546. * [MT6620 5931] Create driver base
  547. *
  548. * 06 01 2010 cp.wu
  549. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  550. * add ioctl to configure scan mode for p2p connection
  551. *
  552. * 05 31 2010 cp.wu
  553. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  554. * add cfg80211 interface, which is to replace WE, for further extension
  555. *
  556. * 05 17 2010 cp.wu
  557. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  558. * implement private io controls for Wi-Fi Direct
  559. *
  560. * 05 17 2010 cp.wu
  561. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  562. * implement get scan result.
  563. *
  564. * 05 17 2010 cp.wu
  565. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  566. * add basic handling framework for wireless extension ioctls.
  567. *
  568. * 05 17 2010 cp.wu
  569. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  570. * 1) add timeout handler mechanism for pending command packets
  571. * 2) add p2p add/removal key
  572. *
  573. * 05 14 2010 cp.wu
  574. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  575. * implement wireless extension ioctls in iw_handler form.
  576. *
  577. * 05 14 2010 cp.wu
  578. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  579. * add ioctl framework for Wi-Fi Direct by reusing wireless extension ioctls as well
  580. *
  581. * 05 11 2010 cp.wu
  582. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  583. * p2p ioctls revised.
  584. *
  585. * 05 11 2010 cp.wu
  586. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  587. * add ioctl for controlling p2p scan phase parameters
  588. *
  589. * 05 10 2010 cp.wu
  590. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  591. * implement basic wi-fi direct framework
  592. *
  593. * 05 07 2010 cp.wu
  594. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  595. * add basic framework for implementating P2P driver hook.
  596. *
  597. **
  598. */
  599. /*******************************************************************************
  600. * C O M P I L E R F L A G S
  601. ********************************************************************************
  602. */
  603. /*******************************************************************************
  604. * E X T E R N A L R E F E R E N C E S
  605. ********************************************************************************
  606. */
  607. #include "gl_os.h"
  608. #include "debug.h"
  609. #include "wlan_lib.h"
  610. #include "gl_wext.h"
  611. #include <linux/poll.h>
  612. #include <linux/kmod.h>
  613. /* #include <net/cfg80211.h> */
  614. #include "gl_p2p_ioctl.h"
  615. #include "precomp.h"
  616. /*******************************************************************************
  617. * C O N S T A N T S
  618. ********************************************************************************
  619. */
  620. #define ARGV_MAX_NUM (4)
  621. /*For CFG80211 - wiphy parameters*/
  622. #define MAX_SCAN_LIST_NUM (1)
  623. #define MAX_SCAN_IE_LEN (512)
  624. /*******************************************************************************
  625. * D A T A T Y P E S
  626. ********************************************************************************
  627. */
  628. /*******************************************************************************
  629. * P U B L I C D A T A
  630. ********************************************************************************
  631. */
  632. /*******************************************************************************
  633. * P R I V A T E D A T A
  634. ********************************************************************************
  635. */
  636. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  637. /* for cfg80211 - frequency table */
  638. static struct ieee80211_channel mtk_2ghz_channels[] = {
  639. CHAN2G(1, 2412, 0),
  640. CHAN2G(2, 2417, 0),
  641. CHAN2G(3, 2422, 0),
  642. CHAN2G(4, 2427, 0),
  643. CHAN2G(5, 2432, 0),
  644. CHAN2G(6, 2437, 0),
  645. CHAN2G(7, 2442, 0),
  646. CHAN2G(8, 2447, 0),
  647. CHAN2G(9, 2452, 0),
  648. CHAN2G(10, 2457, 0),
  649. CHAN2G(11, 2462, 0),
  650. CHAN2G(12, 2467, 0),
  651. CHAN2G(13, 2472, 0),
  652. CHAN2G(14, 2484, 0),
  653. };
  654. static struct ieee80211_channel mtk_5ghz_a_channels[] = {
  655. CHAN5G(34, 0), CHAN5G(36, 0),
  656. CHAN5G(38, 0), CHAN5G(40, 0),
  657. CHAN5G(42, 0), CHAN5G(44, 0),
  658. CHAN5G(46, 0), CHAN5G(48, 0),
  659. CHAN5G(52, 0), CHAN5G(56, 0),
  660. CHAN5G(60, 0), CHAN5G(64, 0),
  661. CHAN5G(100, 0), CHAN5G(104, 0),
  662. CHAN5G(108, 0), CHAN5G(112, 0),
  663. CHAN5G(116, 0), CHAN5G(120, 0),
  664. CHAN5G(124, 0), CHAN5G(128, 0),
  665. CHAN5G(132, 0), CHAN5G(136, 0),
  666. CHAN5G(140, 0), CHAN5G(149, 0),
  667. CHAN5G(153, 0), CHAN5G(157, 0),
  668. CHAN5G(161, 0), CHAN5G(165, 0),
  669. CHAN5G(169, 0), CHAN5G(173, 0),
  670. CHAN5G(184, 0), CHAN5G(188, 0),
  671. CHAN5G(192, 0), CHAN5G(196, 0),
  672. CHAN5G(200, 0), CHAN5G(204, 0),
  673. CHAN5G(208, 0), CHAN5G(212, 0),
  674. CHAN5G(216, 0),
  675. };
  676. /* for cfg80211 - rate table */
  677. static struct ieee80211_rate mtk_rates[] = {
  678. RATETAB_ENT(10, 0x1000, 0),
  679. RATETAB_ENT(20, 0x1001, 0),
  680. RATETAB_ENT(55, 0x1002, 0),
  681. RATETAB_ENT(110, 0x1003, 0), /* 802.11b */
  682. RATETAB_ENT(60, 0x2000, 0),
  683. RATETAB_ENT(90, 0x2001, 0),
  684. RATETAB_ENT(120, 0x2002, 0),
  685. RATETAB_ENT(180, 0x2003, 0),
  686. RATETAB_ENT(240, 0x2004, 0),
  687. RATETAB_ENT(360, 0x2005, 0),
  688. RATETAB_ENT(480, 0x2006, 0),
  689. RATETAB_ENT(540, 0x2007, 0), /* 802.11a/g */
  690. };
  691. #define mtk_a_rates (mtk_rates + 4)
  692. #define mtk_a_rates_size (sizeof(mtk_rates) / sizeof(mtk_rates[0]) - 4)
  693. #define mtk_g_rates (mtk_rates + 0)
  694. #define mtk_g_rates_size (sizeof(mtk_rates) / sizeof(mtk_rates[0]) - 0)
  695. #define MT6620_MCS_INFO \
  696. { \
  697. /* MCS1~7*/ \
  698. .rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0},\
  699. .rx_highest = 0, \
  700. .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
  701. }
  702. #if 0
  703. /*Bandwidth 20Mhz Only*/
  704. #define MT6620_HT_CAP \
  705. { \
  706. .ht_supported = true, \
  707. .cap = IEEE80211_HT_CAP_SM_PS \
  708. | IEEE80211_HT_CAP_GRN_FLD \
  709. | IEEE80211_HT_CAP_SGI_20, \
  710. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, \
  711. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE, \
  712. .mcs = MT6620_MCS_INFO, \
  713. }
  714. #else
  715. /*Bandwidth 20/40Mhz*/
  716. #define MT6620_HT_CAP \
  717. { \
  718. .ht_supported = true, \
  719. .cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 \
  720. | IEEE80211_HT_CAP_SM_PS \
  721. | IEEE80211_HT_CAP_GRN_FLD \
  722. | IEEE80211_HT_CAP_SGI_20 \
  723. | IEEE80211_HT_CAP_SGI_40, \
  724. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, \
  725. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE, \
  726. .mcs = MT6620_MCS_INFO, \
  727. }
  728. #endif
  729. static struct ieee80211_supported_band mtk_band_2ghz = {
  730. .band = IEEE80211_BAND_2GHZ,
  731. .channels = mtk_2ghz_channels,
  732. .n_channels = ARRAY_SIZE(mtk_2ghz_channels),
  733. .bitrates = mtk_g_rates,
  734. .n_bitrates = mtk_g_rates_size,
  735. .ht_cap = MT6620_HT_CAP,
  736. };
  737. static struct ieee80211_supported_band mtk_band_5ghz = {
  738. .band = IEEE80211_BAND_5GHZ,
  739. .channels = mtk_5ghz_a_channels,
  740. .n_channels = ARRAY_SIZE(mtk_5ghz_a_channels),
  741. .bitrates = mtk_a_rates,
  742. .n_bitrates = mtk_a_rates_size,
  743. .ht_cap = MT6620_HT_CAP,
  744. };
  745. static const UINT_32 cipher_suites[] = {
  746. /* keep WEP first, it may be removed below */
  747. WLAN_CIPHER_SUITE_WEP40,
  748. WLAN_CIPHER_SUITE_WEP104,
  749. WLAN_CIPHER_SUITE_TKIP,
  750. WLAN_CIPHER_SUITE_CCMP,
  751. /* keep last -- depends on hw flags! */
  752. WLAN_CIPHER_SUITE_AES_CMAC
  753. };
  754. static struct cfg80211_ops mtk_p2p_config_ops = {
  755. #if (CFG_ENABLE_WIFI_DIRECT_CFG_80211 != 0)
  756. /* Froyo */
  757. .change_virtual_intf = mtk_p2p_cfg80211_change_iface, /* 1 st */
  758. .change_bss = mtk_p2p_cfg80211_change_bss,
  759. .scan = mtk_p2p_cfg80211_scan,
  760. .remain_on_channel = mtk_p2p_cfg80211_remain_on_channel,
  761. .cancel_remain_on_channel = mtk_p2p_cfg80211_cancel_remain_on_channel,
  762. .mgmt_tx = mtk_p2p_cfg80211_mgmt_tx,
  763. .connect = mtk_p2p_cfg80211_connect,
  764. .disconnect = mtk_p2p_cfg80211_disconnect,
  765. .deauth = mtk_p2p_cfg80211_deauth,
  766. .disassoc = mtk_p2p_cfg80211_disassoc,
  767. .start_ap = mtk_p2p_cfg80211_start_ap,
  768. .change_beacon = mtk_p2p_cfg80211_change_beacon,
  769. .stop_ap = mtk_p2p_cfg80211_stop_ap,
  770. .set_wiphy_params = mtk_p2p_cfg80211_set_wiphy_params,
  771. .del_station = mtk_p2p_cfg80211_del_station,
  772. .set_monitor_channel = mtk_p2p_cfg80211_set_channel,
  773. .set_bitrate_mask = mtk_p2p_cfg80211_set_bitrate_mask,
  774. .mgmt_frame_register = mtk_p2p_cfg80211_mgmt_frame_register,
  775. .get_station = mtk_p2p_cfg80211_get_station,
  776. /* ================ */
  777. .add_key = mtk_p2p_cfg80211_add_key,
  778. .get_key = mtk_p2p_cfg80211_get_key,
  779. .del_key = mtk_p2p_cfg80211_del_key,
  780. .set_default_key = mtk_p2p_cfg80211_set_default_key,
  781. .join_ibss = mtk_p2p_cfg80211_join_ibss,
  782. .leave_ibss = mtk_p2p_cfg80211_leave_ibss,
  783. .set_tx_power = mtk_p2p_cfg80211_set_txpower,
  784. .get_tx_power = mtk_p2p_cfg80211_get_txpower,
  785. .set_power_mgmt = mtk_p2p_cfg80211_set_power_mgmt,
  786. #ifdef CONFIG_NL80211_TESTMODE
  787. .testmode_cmd = mtk_p2p_cfg80211_testmode_cmd,
  788. #endif
  789. #endif
  790. };
  791. /* There isn't a lot of sense in it, but you can transmit anything you like */
  792. static const struct ieee80211_txrx_stypes
  793. mtk_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  794. [NL80211_IFTYPE_ADHOC] = {
  795. .tx = 0xffff,
  796. .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
  797. },
  798. [NL80211_IFTYPE_STATION] = {
  799. .tx = 0xffff,
  800. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  801. },
  802. [NL80211_IFTYPE_AP] = {
  803. .tx = 0xffff,
  804. .rx = BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | BIT(IEEE80211_STYPE_ACTION >> 4)
  805. },
  806. [NL80211_IFTYPE_AP_VLAN] = {
  807. /* copy AP */
  808. .tx = 0xffff,
  809. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  810. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  811. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  812. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  813. BIT(IEEE80211_STYPE_AUTH >> 4) |
  814. BIT(IEEE80211_STYPE_DEAUTH >> 4) | BIT(IEEE80211_STYPE_ACTION >> 4)
  815. },
  816. [NL80211_IFTYPE_P2P_CLIENT] = {
  817. .tx = 0xffff,
  818. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  819. },
  820. [NL80211_IFTYPE_P2P_GO] = {
  821. .tx = 0xffff,
  822. .rx = BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | BIT(IEEE80211_STYPE_ACTION >> 4)
  823. }
  824. };
  825. #endif
  826. #if 0
  827. /* the legacy wireless extension stuff */
  828. static const iw_handler rP2PIwStandardHandler[] = {
  829. [SIOCGIWPRIV - SIOCIWFIRST] = mtk_p2p_wext_get_priv,
  830. [SIOCGIWSCAN - SIOCIWFIRST] = mtk_p2p_wext_discovery_results,
  831. [SIOCSIWESSID - SIOCIWFIRST] = mtk_p2p_wext_reconnect,
  832. [SIOCSIWAUTH - SIOCIWFIRST] = mtk_p2p_wext_set_auth,
  833. [SIOCSIWENCODEEXT - SIOCIWFIRST] = mtk_p2p_wext_set_key,
  834. [SIOCSIWPOWER - SIOCIWFIRST] = mtk_p2p_wext_set_powermode,
  835. [SIOCGIWPOWER - SIOCIWFIRST] = mtk_p2p_wext_get_powermode,
  836. [SIOCSIWTXPOW - SIOCIWFIRST] = mtk_p2p_wext_set_txpow,
  837. #if CFG_SUPPORT_P2P_RSSI_QUERY
  838. [SIOCGIWSTATS - SIOCIWFIRST] = mtk_p2p_wext_get_rssi,
  839. #endif
  840. [SIOCSIWMLME - SIOCIWFIRST] = mtk_p2p_wext_mlme_handler,
  841. };
  842. #endif
  843. #if 0
  844. static const iw_handler rP2PIwPrivHandler[] = {
  845. [IOC_P2P_CFG_DEVICE - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_local_dev_info,
  846. [IOC_P2P_PROVISION_COMPLETE - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_provision_complete,
  847. [IOC_P2P_START_STOP_DISCOVERY - SIOCIWFIRSTPRIV] = mtk_p2p_wext_start_stop_discovery,
  848. [IOC_P2P_DISCOVERY_RESULTS - SIOCIWFIRSTPRIV] = mtk_p2p_wext_discovery_results,
  849. [IOC_P2P_WSC_BEACON_PROBE_RSP_IE - SIOCIWFIRSTPRIV] = mtk_p2p_wext_wsc_ie,
  850. [IOC_P2P_CONNECT_DISCONNECT - SIOCIWFIRSTPRIV] = mtk_p2p_wext_connect_disconnect,
  851. [IOC_P2P_PASSWORD_READY - SIOCIWFIRSTPRIV] = mtk_p2p_wext_password_ready,
  852. /* [IOC_P2P_SET_PWR_MGMT_PARAM - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_pm_param, */
  853. [IOC_P2P_SET_INT - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_int,
  854. [IOC_P2P_GET_STRUCT - SIOCIWFIRSTPRIV] = mtk_p2p_wext_get_struct,
  855. [IOC_P2P_SET_STRUCT - SIOCIWFIRSTPRIV] = mtk_p2p_wext_set_struct,
  856. [IOC_P2P_GET_REQ_DEVICE_INFO - SIOCIWFIRSTPRIV] = mtk_p2p_wext_request_dev_info,
  857. };
  858. #endif
  859. static const struct iw_priv_args rP2PIwPrivTable[] = {
  860. {
  861. .cmd = IOC_P2P_CFG_DEVICE,
  862. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_CFG_DEVICE_TYPE),
  863. .get_args = IW_PRIV_TYPE_NONE,
  864. .name = "P2P_CFG_DEVICE"}
  865. ,
  866. {
  867. .cmd = IOC_P2P_START_STOP_DISCOVERY,
  868. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_REQ_DEVICE_TYPE),
  869. .get_args = IW_PRIV_TYPE_NONE,
  870. .name = "P2P_DISCOVERY"}
  871. ,
  872. {
  873. .cmd = IOC_P2P_DISCOVERY_RESULTS,
  874. .set_args = IW_PRIV_TYPE_NONE,
  875. .get_args = IW_PRIV_TYPE_NONE,
  876. .name = "P2P_RESULT"}
  877. ,
  878. {
  879. .cmd = IOC_P2P_WSC_BEACON_PROBE_RSP_IE,
  880. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_HOSTAPD_PARAM),
  881. .get_args = IW_PRIV_TYPE_NONE,
  882. .name = "P2P_WSC_IE"}
  883. ,
  884. {
  885. .cmd = IOC_P2P_CONNECT_DISCONNECT,
  886. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_CONNECT_DEVICE),
  887. .get_args = IW_PRIV_TYPE_NONE,
  888. .name = "P2P_CONNECT"}
  889. ,
  890. {
  891. .cmd = IOC_P2P_PASSWORD_READY,
  892. .set_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_PASSWORD_READY),
  893. .get_args = IW_PRIV_TYPE_NONE,
  894. .name = "P2P_PASSWD_RDY"}
  895. ,
  896. {
  897. .cmd = IOC_P2P_GET_STRUCT,
  898. .set_args = IW_PRIV_TYPE_NONE,
  899. .get_args = 256,
  900. .name = "P2P_GET_STRUCT"}
  901. ,
  902. {
  903. .cmd = IOC_P2P_SET_STRUCT,
  904. .set_args = 256,
  905. .get_args = IW_PRIV_TYPE_NONE,
  906. .name = "P2P_SET_STRUCT"}
  907. ,
  908. {
  909. .cmd = IOC_P2P_GET_REQ_DEVICE_INFO,
  910. .set_args = IW_PRIV_TYPE_NONE,
  911. .get_args = IW_PRIV_TYPE_BYTE | (__u16) sizeof(IW_P2P_DEVICE_REQ),
  912. .name = "P2P_GET_REQDEV"}
  913. ,
  914. {
  915. /* SET STRUCT sub-ioctls commands */
  916. .cmd = PRIV_CMD_OID,
  917. .set_args = 256,
  918. .get_args = IW_PRIV_TYPE_NONE,
  919. .name = "set_oid"}
  920. ,
  921. {
  922. /* GET STRUCT sub-ioctls commands */
  923. .cmd = PRIV_CMD_OID,
  924. .set_args = IW_PRIV_TYPE_NONE,
  925. .get_args = 256,
  926. .name = "get_oid"}
  927. };
  928. #if 0
  929. const struct iw_handler_def mtk_p2p_wext_handler_def = {
  930. .num_standard = (__u16) sizeof(rP2PIwStandardHandler) / sizeof(iw_handler),
  931. .num_private = (__u16) sizeof(rP2PIwPrivHandler) / sizeof(iw_handler),
  932. .num_private_args = (__u16) sizeof(rP2PIwPrivTable) / sizeof(struct iw_priv_args),
  933. .standard = rP2PIwStandardHandler,
  934. .private = rP2PIwPrivHandler,
  935. .private_args = rP2PIwPrivTable,
  936. #if CFG_SUPPORT_P2P_RSSI_QUERY
  937. .get_wireless_stats = mtk_p2p_wext_get_wireless_stats,
  938. #else
  939. .get_wireless_stats = NULL,
  940. #endif
  941. };
  942. #endif
  943. #ifdef CONFIG_PM
  944. static const struct wiphy_wowlan_support p2p_wowlan_support = {
  945. .flags = WIPHY_WOWLAN_DISCONNECT | WIPHY_WOWLAN_ANY,
  946. };
  947. #endif
  948. /*******************************************************************************
  949. * M A C R O S
  950. ********************************************************************************
  951. */
  952. /*******************************************************************************
  953. * F U N C T I O N D E C L A R A T I O N S
  954. ********************************************************************************
  955. */
  956. /* for IE Searching */
  957. extern BOOLEAN
  958. wextSrchDesiredWPAIE(IN PUINT_8 pucIEStart,
  959. IN INT_32 i4TotalIeLen, IN UINT_8 ucDesiredElemId, OUT PUINT_8 *ppucDesiredIE);
  960. #if CFG_SUPPORT_WPS
  961. extern BOOLEAN
  962. wextSrchDesiredWPSIE(IN PUINT_8 pucIEStart,
  963. IN INT_32 i4TotalIeLen, IN UINT_8 ucDesiredElemId, OUT PUINT_8 *ppucDesiredIE);
  964. #endif
  965. /* Net Device Hooks */
  966. static int p2pOpen(IN struct net_device *prDev);
  967. static int p2pStop(IN struct net_device *prDev);
  968. static struct net_device_stats *p2pGetStats(IN struct net_device *prDev);
  969. static void p2pSetMulticastList(IN struct net_device *prDev);
  970. static int p2pHardStartXmit(IN struct sk_buff *prSkb, IN struct net_device *prDev);
  971. static int p2pDoIOCTL(struct net_device *prDev, struct ifreq *prIFReq, int i4Cmd);
  972. static int p2pSetMACAddress(IN struct net_device *prDev, void *addr);
  973. /*----------------------------------------------------------------------------*/
  974. /*!
  975. * \brief Override the implementation of select queue
  976. *
  977. * \param[in] dev Pointer to struct net_device
  978. * \param[in] skb Pointer to struct skb_buff
  979. *
  980. * \return (none)
  981. */
  982. /*----------------------------------------------------------------------------*/
  983. unsigned int _p2p_cfg80211_classify8021d(struct sk_buff *skb)
  984. {
  985. unsigned int dscp = 0;
  986. /* skb->priority values from 256->263 are magic values
  987. * directly indicate a specific 802.1d priority. This is
  988. * to allow 802.1d priority to be passed directly in from
  989. * tags
  990. */
  991. if (skb->priority >= 256 && skb->priority <= 263)
  992. return skb->priority - 256;
  993. switch (skb->protocol) {
  994. case htons(ETH_P_IP):
  995. dscp = ip_hdr(skb)->tos & 0xfc;
  996. break;
  997. }
  998. return dscp >> 5;
  999. }
  1000. static const UINT_16 au16Wlan1dToQueueIdx[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
  1001. static UINT_16 p2pSelectQueue(struct net_device *dev, struct sk_buff *skb,
  1002. void *accel_priv, select_queue_fallback_t fallback)
  1003. {
  1004. skb->priority = _p2p_cfg80211_classify8021d(skb);
  1005. return au16Wlan1dToQueueIdx[skb->priority];
  1006. }
  1007. static struct net_device *g_P2pPrDev;
  1008. static struct wireless_dev *gprP2pWdev;
  1009. /*----------------------------------------------------------------------------*/
  1010. /*!
  1011. * \brief A function for prDev->init
  1012. *
  1013. * \param[in] prDev Pointer to struct net_device.
  1014. *
  1015. * \retval 0 The execution of wlanInit succeeds.
  1016. * \retval -ENXIO No such device.
  1017. */
  1018. /*----------------------------------------------------------------------------*/
  1019. static int p2pInit(struct net_device *prDev)
  1020. {
  1021. /* P_GLUE_INFO_T prGlueInfo; */
  1022. if (!prDev)
  1023. return -ENXIO;
  1024. DBGLOG(P2P, INFO, "dev name=%s\n", prDev->name);
  1025. return 0; /* success */
  1026. } /* end of p2pInit() */
  1027. /*----------------------------------------------------------------------------*/
  1028. /*!
  1029. * \brief A function for prDev->uninit
  1030. *
  1031. * \param[in] prDev Pointer to struct net_device.
  1032. *
  1033. * \return (none)
  1034. */
  1035. /*----------------------------------------------------------------------------*/
  1036. static void p2pUninit(IN struct net_device *prDev)
  1037. {
  1038. } /* end of p2pUninit() */
  1039. static const struct net_device_ops p2p_netdev_ops = {
  1040. .ndo_open = p2pOpen,
  1041. .ndo_stop = p2pStop,
  1042. .ndo_set_mac_address = p2pSetMACAddress,
  1043. .ndo_set_rx_mode = p2pSetMulticastList,
  1044. .ndo_get_stats = p2pGetStats,
  1045. .ndo_do_ioctl = p2pDoIOCTL,
  1046. .ndo_start_xmit = p2pHardStartXmit,
  1047. .ndo_select_queue = p2pSelectQueue,
  1048. .ndo_init = p2pInit,
  1049. .ndo_uninit = p2pUninit,
  1050. };
  1051. /*******************************************************************************
  1052. * F U N C T I O N S
  1053. ********************************************************************************
  1054. */
  1055. /*----------------------------------------------------------------------------*/
  1056. /*!
  1057. * \brief Allocate memory for P2P_INFO, GL_P2P_INFO, P2P_CONNECTION_SETTINGS
  1058. * P2P_SPECIFIC_BSS_INFO, P2P_FSM_INFO
  1059. *
  1060. * \param[in] prGlueInfo Pointer to glue info
  1061. *
  1062. * \return TRUE
  1063. * FALSE
  1064. */
  1065. /*----------------------------------------------------------------------------*/
  1066. BOOLEAN p2PAllocInfo(IN P_GLUE_INFO_T prGlueInfo)
  1067. {
  1068. P_ADAPTER_T prAdapter = NULL;
  1069. P_WIFI_VAR_T prWifiVar = NULL;
  1070. if ((!prGlueInfo) || (!prGlueInfo->prAdapter)) {
  1071. ASSERT(FALSE);
  1072. return FALSE;
  1073. }
  1074. prAdapter = prGlueInfo->prAdapter;
  1075. prWifiVar = &(prAdapter->rWifiVar);
  1076. if (!prWifiVar) {
  1077. ASSERT(FALSE);
  1078. return FALSE;
  1079. }
  1080. do {
  1081. if (prGlueInfo->prP2PInfo == NULL) {
  1082. /*alloc memory for p2p info */
  1083. prGlueInfo->prP2PInfo = kalMemAlloc(sizeof(GL_P2P_INFO_T), VIR_MEM_TYPE);
  1084. prAdapter->prP2pInfo = kalMemAlloc(sizeof(P2P_INFO_T), VIR_MEM_TYPE);
  1085. prWifiVar->prP2PConnSettings = kalMemAlloc(sizeof(P2P_CONNECTION_SETTINGS_T), VIR_MEM_TYPE);
  1086. prWifiVar->prP2pFsmInfo = kalMemAlloc(sizeof(P2P_FSM_INFO_T), VIR_MEM_TYPE);
  1087. prWifiVar->prP2pSpecificBssInfo = kalMemAlloc(sizeof(P2P_SPECIFIC_BSS_INFO_T), VIR_MEM_TYPE);
  1088. } else {
  1089. ASSERT(prAdapter->prP2pInfo != NULL);
  1090. ASSERT(prWifiVar->prP2PConnSettings != NULL);
  1091. ASSERT(prWifiVar->prP2pFsmInfo != NULL);
  1092. ASSERT(prWifiVar->prP2pSpecificBssInfo != NULL);
  1093. }
  1094. /*MUST set memory to 0 */
  1095. if (prGlueInfo->prP2PInfo)
  1096. kalMemZero(prGlueInfo->prP2PInfo, sizeof(GL_P2P_INFO_T));
  1097. if (prAdapter->prP2pInfo)
  1098. kalMemZero(prAdapter->prP2pInfo, sizeof(P2P_INFO_T));
  1099. if (prWifiVar->prP2PConnSettings)
  1100. kalMemZero(prWifiVar->prP2PConnSettings, sizeof(P2P_CONNECTION_SETTINGS_T));
  1101. if (prWifiVar->prP2pFsmInfo)
  1102. kalMemZero(prWifiVar->prP2pFsmInfo, sizeof(P2P_FSM_INFO_T));
  1103. if (prWifiVar->prP2pSpecificBssInfo)
  1104. kalMemZero(prWifiVar->prP2pSpecificBssInfo, sizeof(P2P_SPECIFIC_BSS_INFO_T));
  1105. } while (FALSE);
  1106. /* chk if alloc successful or not */
  1107. if (prGlueInfo->prP2PInfo &&
  1108. prAdapter->prP2pInfo &&
  1109. prWifiVar->prP2PConnSettings && prWifiVar->prP2pFsmInfo && prWifiVar->prP2pSpecificBssInfo) {
  1110. return TRUE;
  1111. }
  1112. if (prWifiVar->prP2pSpecificBssInfo) {
  1113. kalMemFree(prWifiVar->prP2pSpecificBssInfo, VIR_MEM_TYPE, sizeof(P2P_SPECIFIC_BSS_INFO_T));
  1114. prWifiVar->prP2pSpecificBssInfo = NULL;
  1115. }
  1116. if (prWifiVar->prP2pFsmInfo) {
  1117. kalMemFree(prWifiVar->prP2pFsmInfo, VIR_MEM_TYPE, sizeof(P2P_FSM_INFO_T));
  1118. prWifiVar->prP2pFsmInfo = NULL;
  1119. }
  1120. if (prWifiVar->prP2PConnSettings) {
  1121. kalMemFree(prWifiVar->prP2PConnSettings, VIR_MEM_TYPE, sizeof(P2P_CONNECTION_SETTINGS_T));
  1122. prWifiVar->prP2PConnSettings = NULL;
  1123. }
  1124. if (prGlueInfo->prP2PInfo) {
  1125. kalMemFree(prGlueInfo->prP2PInfo, VIR_MEM_TYPE, sizeof(GL_P2P_INFO_T));
  1126. prGlueInfo->prP2PInfo = NULL;
  1127. }
  1128. if (prAdapter->prP2pInfo) {
  1129. kalMemFree(prAdapter->prP2pInfo, VIR_MEM_TYPE, sizeof(P2P_INFO_T));
  1130. prAdapter->prP2pInfo = NULL;
  1131. }
  1132. return FALSE;
  1133. }
  1134. /*----------------------------------------------------------------------------*/
  1135. /*!
  1136. * \brief Free memory for P2P_INFO, GL_P2P_INFO, P2P_CONNECTION_SETTINGS
  1137. * P2P_SPECIFIC_BSS_INFO, P2P_FSM_INFO
  1138. *
  1139. * \param[in] prGlueInfo Pointer to glue info
  1140. *
  1141. * \return TRUE
  1142. * FALSE
  1143. */
  1144. /*----------------------------------------------------------------------------*/
  1145. BOOLEAN p2PFreeInfo(P_GLUE_INFO_T prGlueInfo)
  1146. {
  1147. if ((!prGlueInfo) || (!prGlueInfo->prAdapter)) {
  1148. ASSERT(FALSE);
  1149. return FALSE;
  1150. }
  1151. /* free memory after p2p module is ALREADY unregistered */
  1152. if (prGlueInfo->prAdapter->fgIsP2PRegistered == FALSE) {
  1153. kalMemFree(prGlueInfo->prAdapter->prP2pInfo, VIR_MEM_TYPE, sizeof(P2P_INFO_T));
  1154. kalMemFree(prGlueInfo->prP2PInfo, VIR_MEM_TYPE, sizeof(GL_P2P_INFO_T));
  1155. kalMemFree(prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings, VIR_MEM_TYPE,
  1156. sizeof(P2P_CONNECTION_SETTINGS_T));
  1157. kalMemFree(prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo, VIR_MEM_TYPE, sizeof(P2P_FSM_INFO_T));
  1158. kalMemFree(prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo, VIR_MEM_TYPE,
  1159. sizeof(P2P_SPECIFIC_BSS_INFO_T));
  1160. /*Reomve p2p bss scan list */
  1161. scanRemoveAllP2pBssDesc(prGlueInfo->prAdapter);
  1162. /*reset all pointer to NULL */
  1163. prGlueInfo->prP2PInfo = NULL;
  1164. prGlueInfo->prAdapter->prP2pInfo = NULL;
  1165. prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings = NULL;
  1166. prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo = NULL;
  1167. prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo = NULL;
  1168. return TRUE;
  1169. } else {
  1170. return FALSE;
  1171. }
  1172. }
  1173. /*----------------------------------------------------------------------------*/
  1174. /*!
  1175. * \brief Enable Channel for cfg80211 for Wi-Fi Direct based on current country code
  1176. *
  1177. * \param[in] prGlueInfo Pointer to glue info
  1178. *
  1179. * \return TRUE
  1180. * FALSE
  1181. */
  1182. /*----------------------------------------------------------------------------*/
  1183. VOID
  1184. p2pEnableChannel(PUINT_8 pucChIdx, UINT_8 ucChannelNum, struct ieee80211_channel *mtk_channels, UINT_8 mtk_channel_sz)
  1185. {
  1186. UINT_8 ucCurChIdx = *pucChIdx;
  1187. while (TRUE) {
  1188. (*pucChIdx)++;
  1189. (*pucChIdx) %= mtk_channel_sz;
  1190. if (ucChannelNum == mtk_channels[*pucChIdx].hw_value) {
  1191. mtk_channels[*pucChIdx].flags &= ~IEEE80211_CHAN_DISABLED;
  1192. mtk_channels[*pucChIdx].orig_flags &= ~IEEE80211_CHAN_DISABLED;
  1193. break;
  1194. }
  1195. if (*pucChIdx == ucCurChIdx) {
  1196. DBGLOG(P2P, INFO, "Orphan channel [%d]\n", ucChannelNum);
  1197. break;
  1198. }
  1199. }
  1200. }
  1201. #if !CFG_SUPPORT_PERSIST_NETDEV
  1202. BOOLEAN p2pNetRegister(P_GLUE_INFO_T prGlueInfo, BOOLEAN fgIsRtnlLockAcquired)
  1203. {
  1204. BOOLEAN fgDoRegister = FALSE;
  1205. /* BOOLEAN fgRollbackRtnlLock = FALSE; */
  1206. BOOLEAN ret;
  1207. GLUE_SPIN_LOCK_DECLARATION();
  1208. if ((!prGlueInfo) || (!prGlueInfo->prAdapter)) {
  1209. ASSERT(FALSE);
  1210. return FALSE;
  1211. }
  1212. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1213. if (prGlueInfo->prAdapter->rP2PNetRegState == ENUM_NET_REG_STATE_UNREGISTERED) {
  1214. prGlueInfo->prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_REGISTERING;
  1215. fgDoRegister = TRUE;
  1216. }
  1217. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1218. if (!fgDoRegister)
  1219. return TRUE;
  1220. /* net device initialize */
  1221. netif_carrier_off(prGlueInfo->prP2PInfo->prDevHandler);
  1222. netif_tx_stop_all_queues(prGlueInfo->prP2PInfo->prDevHandler);
  1223. /* register for net device */
  1224. if (register_netdev(prGlueInfo->prP2PInfo->prDevHandler) < 0) {
  1225. DBGLOG(P2P, WARN, "unable to register netdevice for p2p\n");
  1226. free_netdev(prGlueInfo->prP2PInfo->prDevHandler);
  1227. ret = FALSE;
  1228. } else {
  1229. prGlueInfo->prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_REGISTERED;
  1230. ret = TRUE;
  1231. }
  1232. return ret;
  1233. }
  1234. BOOLEAN p2pNetUnregister(P_GLUE_INFO_T prGlueInfo, BOOLEAN fgIsRtnlLockAcquired)
  1235. {
  1236. BOOLEAN fgDoUnregister = FALSE;
  1237. /* BOOLEAN fgRollbackRtnlLock = FALSE; */
  1238. GLUE_SPIN_LOCK_DECLARATION();
  1239. if ((!prGlueInfo) || (!prGlueInfo->prAdapter)) {
  1240. ASSERT(FALSE);
  1241. return FALSE;
  1242. }
  1243. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1244. if (prGlueInfo->prAdapter->rP2PNetRegState == ENUM_NET_REG_STATE_REGISTERED) {
  1245. prGlueInfo->prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_UNREGISTERING;
  1246. fgDoUnregister = TRUE;
  1247. }
  1248. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1249. if (!fgDoUnregister)
  1250. return TRUE;
  1251. /* prepare for removal */
  1252. if (netif_carrier_ok(prGlueInfo->prP2PInfo->prDevHandler))
  1253. netif_carrier_off(prGlueInfo->prP2PInfo->prDevHandler);
  1254. netif_tx_stop_all_queues(prGlueInfo->prP2PInfo->prDevHandler);
  1255. DBGLOG(P2P, INFO, "P2P unregister_netdev 0x%p\n", prGlueInfo->prP2PInfo->prDevHandler);
  1256. unregister_netdev(prGlueInfo->prP2PInfo->prDevHandler);
  1257. prGlueInfo->prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_UNREGISTERED;
  1258. return TRUE;
  1259. }
  1260. #endif
  1261. /*----------------------------------------------------------------------------*/
  1262. /*!
  1263. * \brief Update Channel table for cfg80211 for Wi-Fi Direct based on current country code
  1264. *
  1265. * \param[in] prGlueInfo Pointer to glue info
  1266. *
  1267. * \return TRUE
  1268. * FALSE
  1269. */
  1270. /*----------------------------------------------------------------------------*/
  1271. VOID p2pUpdateChannelTableByDomain(P_GLUE_INFO_T prGlueInfo)
  1272. {
  1273. UINT_8 i, j;
  1274. UINT_8 ucMaxChannelNum = ARRAY_SIZE(mtk_2ghz_channels) + ARRAY_SIZE(mtk_5ghz_a_channels);
  1275. UINT_8 ucNumOfChannel = ucMaxChannelNum;
  1276. RF_CHANNEL_INFO_T aucChannelList[ucMaxChannelNum];
  1277. /* 1. Disable all channel */
  1278. for (i = 0; i < ARRAY_SIZE(mtk_2ghz_channels); i++) {
  1279. mtk_2ghz_channels[i].flags |= IEEE80211_CHAN_DISABLED;
  1280. mtk_2ghz_channels[i].orig_flags |= IEEE80211_CHAN_DISABLED;
  1281. }
  1282. for (i = 0; i < ARRAY_SIZE(mtk_5ghz_a_channels); i++) {
  1283. mtk_5ghz_a_channels[i].flags |= IEEE80211_CHAN_DISABLED;
  1284. mtk_5ghz_a_channels[i].orig_flags |= IEEE80211_CHAN_DISABLED;
  1285. }
  1286. /* 2. Get current domain channel list */
  1287. rlmDomainGetChnlList(prGlueInfo->prAdapter, BAND_NULL, ucMaxChannelNum, &ucNumOfChannel, aucChannelList);
  1288. /* 3. Enable specific channel based on domain channel list */
  1289. for (i = 0; i < ucNumOfChannel; i++) {
  1290. switch (aucChannelList[i].eBand) {
  1291. case BAND_2G4:
  1292. for (j = 0; j < ARRAY_SIZE(mtk_2ghz_channels); j++) {
  1293. if (mtk_2ghz_channels[j].hw_value == aucChannelList[i].ucChannelNum) {
  1294. mtk_2ghz_channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
  1295. mtk_2ghz_channels[j].orig_flags &= ~IEEE80211_CHAN_DISABLED;
  1296. break;
  1297. }
  1298. }
  1299. break;
  1300. case BAND_5G:
  1301. for (j = 0; j < ARRAY_SIZE(mtk_5ghz_a_channels); j++) {
  1302. if (mtk_5ghz_a_channels[j].hw_value == aucChannelList[i].ucChannelNum) {
  1303. mtk_5ghz_a_channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
  1304. mtk_5ghz_a_channels[j].orig_flags &= ~IEEE80211_CHAN_DISABLED;
  1305. break;
  1306. }
  1307. }
  1308. break;
  1309. default:
  1310. DBGLOG(P2P, WARN, "Unknown band.\n");
  1311. break;
  1312. }
  1313. }
  1314. }
  1315. BOOLEAN glP2pCreateWirelessDevice(P_GLUE_INFO_T prGlueInfo)
  1316. {
  1317. struct wiphy *prWiphy = NULL;
  1318. struct wireless_dev *prWdev = NULL;
  1319. #if CFG_SUPPORT_PERSIST_NETDEV
  1320. struct net_device *prNetDev = NULL;
  1321. #endif
  1322. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1323. prWdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1324. if (!prWdev) {
  1325. DBGLOG(P2P, ERROR, "allocate p2p wireless device fail, no memory\n");
  1326. return FALSE;
  1327. }
  1328. /* 1. allocate WIPHY */
  1329. prWiphy = wiphy_new(&mtk_p2p_config_ops, sizeof(P_GLUE_INFO_T));
  1330. if (!prWiphy) {
  1331. DBGLOG(P2P, ERROR, "unable to allocate wiphy for p2p\n");
  1332. goto free_wdev;
  1333. }
  1334. prWiphy->interface_modes = BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_P2P_CLIENT) |
  1335. BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_STATION);
  1336. prWiphy->bands[IEEE80211_BAND_2GHZ] = &mtk_band_2ghz;
  1337. prWiphy->bands[IEEE80211_BAND_5GHZ] = &mtk_band_5ghz;
  1338. prWiphy->mgmt_stypes = mtk_cfg80211_default_mgmt_stypes;
  1339. prWiphy->max_remain_on_channel_duration = 5000;
  1340. prWiphy->n_cipher_suites = 5;
  1341. prWiphy->cipher_suites = (const PUINT_32)cipher_suites;
  1342. prWiphy->flags = WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | WIPHY_FLAG_HAVE_AP_SME;
  1343. prWiphy->regulatory_flags = REGULATORY_CUSTOM_REG;
  1344. prWiphy->ap_sme_capa = 1;
  1345. prWiphy->max_scan_ssids = MAX_SCAN_LIST_NUM;
  1346. prWiphy->max_scan_ie_len = MAX_SCAN_IE_LEN;
  1347. prWiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1348. #ifdef CONFIG_PM
  1349. prWiphy->wowlan = &p2p_wowlan_support;
  1350. #endif
  1351. /* 2.1 set priv as pointer to glue structure */
  1352. *((P_GLUE_INFO_T *) wiphy_priv(prWiphy)) = prGlueInfo;
  1353. if (wiphy_register(prWiphy) < 0) {
  1354. DBGLOG(P2P, ERROR, "fail to register wiphy for p2p\n");
  1355. goto free_wiphy;
  1356. }
  1357. prWdev->wiphy = prWiphy;
  1358. #if CFG_SUPPORT_PERSIST_NETDEV
  1359. /* 3. allocate netdev */
  1360. prNetDev = alloc_netdev_mq(sizeof(P_GLUE_INFO_T), P2P_MODE_INF_NAME, NET_NAME_PREDICTABLE,
  1361. ether_setup, CFG_MAX_TXQ_NUM);
  1362. if (!prNetDev) {
  1363. DBGLOG(P2P, ERROR, "unable to allocate netdevice for p2p\n");
  1364. goto unregister_wiphy;
  1365. }
  1366. /* 4. setup netdev */
  1367. /* 4.1 Point to shared glue structure */
  1368. *((P_GLUE_INFO_T *) netdev_priv(prNetDev)) = prGlueInfo;
  1369. /* 4.2 fill hardware address */
  1370. /* COPY_MAC_ADDR(rMacAddr, prAdapter->rMyMacAddr);
  1371. rMacAddr[0] ^= 0x2; // change to local administrated address
  1372. memcpy(prGlueInfo->prP2PInfo->prDevHandler->dev_addr, rMacAddr, ETH_ALEN);
  1373. memcpy(prGlueInfo->prP2PInfo->prDevHandler->perm_addr,
  1374. prGlueInfo->prP2PInfo->prDevHandler->dev_addr, ETH_ALEN);*/
  1375. /* 4.3 register callback functions */
  1376. prNetDev->netdev_ops = &p2p_netdev_ops;
  1377. /* prGlueInfo->prP2PInfo->prDevHandler->wireless_handlers = &mtk_p2p_wext_handler_def;*/
  1378. prNetDev->ieee80211_ptr = prWdev;
  1379. prWdev->netdev = prNetDev;
  1380. #if CFG_TCP_IP_CHKSUM_OFFLOAD
  1381. prNetDev->features = NETIF_F_IP_CSUM;
  1382. #endif /* CFG_TCP_IP_CHKSUM_OFFLOAD */
  1383. /* net device initialize */
  1384. netif_carrier_off(prNetDev);
  1385. netif_tx_stop_all_queues(prNetDev);
  1386. /* register for net device */
  1387. if (register_netdev(prNetDev) < 0) {
  1388. DBGLOG(P2P, ERROR, "unable to register netdevice for p2p\n");
  1389. free_netdev(prNetDev);
  1390. goto unregister_wiphy;
  1391. }
  1392. #endif
  1393. gprP2pWdev = prWdev;
  1394. return TRUE;
  1395. #if CFG_SUPPORT_PERSIST_NETDEV
  1396. unregister_wiphy:
  1397. wiphy_unregister(prWiphy);
  1398. #endif
  1399. free_wiphy:
  1400. wiphy_free(prWiphy);
  1401. free_wdev:
  1402. kfree(prWdev);
  1403. #endif
  1404. return FALSE;
  1405. }
  1406. void glP2pDestroyWirelessDevice(VOID)
  1407. {
  1408. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1409. #if CFG_SUPPORT_PERSIST_NETDEV
  1410. unregister_netdev(gprP2pWdev->netdev);
  1411. free_netdev(gprP2pWdev->netdev);
  1412. #endif
  1413. wiphy_unregister(gprP2pWdev->wiphy);
  1414. wiphy_free(gprP2pWdev->wiphy);
  1415. kfree(gprP2pWdev);
  1416. gprP2pWdev = NULL;
  1417. #endif
  1418. }
  1419. /*----------------------------------------------------------------------------*/
  1420. /*!
  1421. * \brief Register for cfg80211 for Wi-Fi Direct
  1422. *
  1423. * \param[in] prGlueInfo Pointer to glue info
  1424. *
  1425. * \return TRUE
  1426. * FALSE
  1427. */
  1428. /*----------------------------------------------------------------------------*/
  1429. BOOLEAN glRegisterP2P(P_GLUE_INFO_T prGlueInfo, const char *prDevName, BOOLEAN fgIsApMode)
  1430. {
  1431. P_ADAPTER_T prAdapter = NULL;
  1432. P_GL_HIF_INFO_T prHif = NULL;
  1433. PARAM_MAC_ADDRESS rMacAddr;
  1434. struct net_device *prDevHandler = NULL;
  1435. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1436. struct device *prDev;
  1437. #endif
  1438. ASSERT(prGlueInfo);
  1439. prAdapter = prGlueInfo->prAdapter;
  1440. ASSERT(prAdapter);
  1441. prHif = &prGlueInfo->rHifInfo;
  1442. ASSERT(prHif);
  1443. DBGLOG(P2P, INFO, "glRegisterP2P\n");
  1444. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1445. if (!gprP2pWdev) {
  1446. DBGLOG(P2P, ERROR, "gl_p2p, wireless device is not exist\n");
  1447. return FALSE;
  1448. }
  1449. #endif
  1450. /*0. allocate p2pinfo */
  1451. if (!p2PAllocInfo(prGlueInfo)) {
  1452. DBGLOG(P2P, ERROR, "Allocate memory for p2p FAILED\n");
  1453. ASSERT(0);
  1454. return FALSE;
  1455. }
  1456. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1457. prGlueInfo->prP2PInfo->prWdev = gprP2pWdev;
  1458. /* 1. fill wiphy parameters */
  1459. #if MTK_WCN_HIF_SDIO
  1460. mtk_wcn_hif_sdio_get_dev(prHif->cltCtx, &prDev);
  1461. if (!prDev)
  1462. DBGLOG(P2P, WARN, "unable to get struct dev for p2p\n");
  1463. #else
  1464. prDev = prHif->Dev;
  1465. #endif
  1466. /*set_wiphy_dev(gprP2pWdev->wiphy, prDev);*/
  1467. if (!prGlueInfo->prAdapter->fgEnable5GBand)
  1468. gprP2pWdev->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  1469. p2pUpdateChannelTableByDomain(prGlueInfo);
  1470. /* 2 set priv as pointer to glue structure */
  1471. *(P_GLUE_INFO_T *) wiphy_priv(gprP2pWdev->wiphy) = prGlueInfo;
  1472. if (fgIsApMode) {
  1473. gprP2pWdev->iftype = NL80211_IFTYPE_AP;
  1474. #if CFG_SUPPORT_PERSIST_NETDEV
  1475. if (kalStrnCmp(gprP2pWdev->netdev->name, AP_MODE_INF_NAME, 2)) {
  1476. rtnl_lock();
  1477. dev_change_name(gprP2pWdev->netdev->name, AP_MODE_INF_NAME);
  1478. rtnl_unlock();
  1479. }
  1480. #endif
  1481. } else {
  1482. #if CFG_SUPPORT_PERSIST_NETDEV
  1483. if (kalStrnCmp(gprP2pWdev->netdev->name, P2P_MODE_INF_NAME, 3)) {
  1484. rtnl_lock();
  1485. dev_change_name(gprP2pWdev->netdev->name, P2P_MODE_INF_NAME);
  1486. rtnl_unlock();
  1487. }
  1488. #endif
  1489. gprP2pWdev->iftype = NL80211_IFTYPE_P2P_CLIENT;
  1490. }
  1491. #endif /* CFG_ENABLE_WIFI_DIRECT_CFG_80211 */
  1492. #if CFG_SUPPORT_PERSIST_NETDEV
  1493. prP2PInfo->prDevHandler = gprP2pWdev->netdev;
  1494. #else /* CFG_SUPPORT_PERSIST_NETDEV */
  1495. /* 3. allocate netdev */
  1496. prDevHandler =
  1497. alloc_netdev_mq(sizeof(P_GLUE_INFO_T), prDevName, NET_NAME_PREDICTABLE, ether_setup, CFG_MAX_TXQ_NUM);
  1498. if (!prDevHandler) {
  1499. DBGLOG(P2P, ERROR, "unable to allocate netdevice for p2p\n");
  1500. return FALSE;
  1501. }
  1502. prGlueInfo->prP2PInfo->prDevHandler = prDevHandler;
  1503. /* 4. setup netdev */
  1504. /* 4.1 Point to shared glue structure */
  1505. *((P_GLUE_INFO_T *) netdev_priv(prDevHandler)) = prGlueInfo;
  1506. /* 4.2 fill hardware address */
  1507. COPY_MAC_ADDR(rMacAddr, prAdapter->rMyMacAddr);
  1508. rMacAddr[0] ^= 0x2; /* change to local administrated address */
  1509. ether_addr_copy(prDevHandler->dev_addr, rMacAddr);
  1510. ether_addr_copy(prDevHandler->perm_addr, prDevHandler->dev_addr);
  1511. /* 4.3 register callback functions */
  1512. prDevHandler->netdev_ops = &p2p_netdev_ops;
  1513. /* prGlueInfo->prP2PInfo->prDevHandler->wireless_handlers = &mtk_p2p_wext_handler_def; */
  1514. #if (MTK_WCN_HIF_SDIO == 0)
  1515. SET_NETDEV_DEV(prDevHandler, prHif->Dev);
  1516. #endif
  1517. #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
  1518. prDevHandler->ieee80211_ptr = gprP2pWdev;
  1519. gprP2pWdev->netdev = prDevHandler;
  1520. #endif
  1521. #if CFG_TCP_IP_CHKSUM_OFFLOAD
  1522. prDevHandler->features = NETIF_F_IP_CSUM;
  1523. #endif /* CFG_TCP_IP_CHKSUM_OFFLOAD */
  1524. #endif /* CFG_SUPPORT_PERSIST_NETDEV */
  1525. /* 5. set p2p net device register state */
  1526. prAdapter->rP2PNetRegState = ENUM_NET_REG_STATE_UNREGISTERED;
  1527. /* 6. setup running mode */
  1528. prAdapter->rWifiVar.prP2pFsmInfo->fgIsApMode = fgIsApMode;
  1529. /* 7. finish */
  1530. p2pFsmInit(prAdapter);
  1531. p2pFuncInitConnectionSettings(prAdapter, prAdapter->rWifiVar.prP2PConnSettings);
  1532. /* Active network too early would cause HW not able to sleep.
  1533. * Defer the network active time.
  1534. */
  1535. /* nicActivateNetwork(prAdapter, NETWORK_TYPE_P2P_INDEX); */
  1536. return TRUE;
  1537. } /* end of glRegisterP2P() */
  1538. /*----------------------------------------------------------------------------*/
  1539. /*!
  1540. * \brief Unregister Net Device for Wi-Fi Direct
  1541. *
  1542. * \param[in] prGlueInfo Pointer to glue info
  1543. *
  1544. * \return TRUE
  1545. * FALSE
  1546. */
  1547. /*----------------------------------------------------------------------------*/
  1548. BOOLEAN glUnregisterP2P(P_GLUE_INFO_T prGlueInfo)
  1549. {
  1550. ASSERT(prGlueInfo);
  1551. /* normal flow: this func will called first before wlanRemove, and it can do fsmUninit/deactivateNetwork
  1552. gracefully. */
  1553. /* when reset: because tx_thread with fw has stopped, so it can't do these job and the recovery will be
  1554. dependent on chip system reset. */
  1555. /* if so, just skip it by flag GLUE_FLAG_HALT(warning: when tx_thread was stop, this flag was not cleared,
  1556. and NEED TO KEEP IT NOT CLEARED!). */
  1557. if (!(prGlueInfo->ulFlag & GLUE_FLAG_HALT)) {
  1558. p2pFsmUninit(prGlueInfo->prAdapter);
  1559. nicDeactivateNetwork(prGlueInfo->prAdapter, NETWORK_TYPE_P2P_INDEX);
  1560. }
  1561. #if CFG_SUPPORT_PERSIST_NETDEV
  1562. dev_close(prGlueInfo->prP2PInfo->prDevHandler);
  1563. #else
  1564. free_netdev(prGlueInfo->prP2PInfo->prDevHandler);
  1565. prGlueInfo->prP2PInfo->prDevHandler = NULL;
  1566. #endif
  1567. /* Free p2p memory */
  1568. if (!p2PFreeInfo(prGlueInfo)) {
  1569. DBGLOG(P2P, ERROR, "Free memory for p2p FAILED\n");
  1570. ASSERT(0);
  1571. return FALSE;
  1572. }
  1573. return TRUE;
  1574. } /* end of glUnregisterP2P() */
  1575. /*----------------------------------------------------------------------------*/
  1576. /*!
  1577. * \brief A function for stop p2p fsm immediate
  1578. *
  1579. * \param[in] prGlueInfo Pointer to struct P_GLUE_INFO_T.
  1580. *
  1581. * \retval TRUE The execution succeeds.
  1582. * \retval FALSE The execution failed.
  1583. */
  1584. /*----------------------------------------------------------------------------*/
  1585. BOOLEAN p2pStopImmediate(P_GLUE_INFO_T prGlueInfo)
  1586. {
  1587. /* P_ADAPTER_T prAdapter = NULL; */
  1588. /* P_MSG_P2P_FUNCTION_SWITCH_T prFuncSwitch; */
  1589. ASSERT(prGlueInfo);
  1590. /* prAdapter = prGlueInfo->prAdapter; */
  1591. /* ASSERT(prAdapter); */
  1592. /* 1. stop TX queue */
  1593. netif_tx_stop_all_queues(prGlueInfo->prP2PInfo->prDevHandler);
  1594. #if 0
  1595. /* 2. switch P2P-FSM off */
  1596. /* 2.1 allocate for message */
  1597. prFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter,
  1598. RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  1599. if (!prFuncSwitch) {
  1600. ASSERT(0); /* Can't trigger P2P FSM */
  1601. DBGLOG(P2P, ERROR, "Allocate for p2p mesasage FAILED\n");
  1602. /* return -ENOMEM; */
  1603. }
  1604. /* 2.2 fill message */
  1605. prFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  1606. prFuncSwitch->fgIsFuncOn = FALSE;
  1607. /* 2.3 send message */
  1608. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prFuncSwitch, MSG_SEND_METHOD_UNBUF);
  1609. #endif
  1610. /* 3. stop queue and turn off carrier */
  1611. prGlueInfo->prP2PInfo->eState = PARAM_MEDIA_STATE_DISCONNECTED;
  1612. return TRUE;
  1613. } /* end of p2pStop() */
  1614. /* Net Device Hooks */
  1615. /*----------------------------------------------------------------------------*/
  1616. /*!
  1617. * \brief A function for net_device open (ifup)
  1618. *
  1619. * \param[in] prDev Pointer to struct net_device.
  1620. *
  1621. * \retval 0 The execution succeeds.
  1622. * \retval < 0 The execution failed.
  1623. */
  1624. /*----------------------------------------------------------------------------*/
  1625. static int p2pOpen(IN struct net_device *prDev)
  1626. {
  1627. /* P_GLUE_INFO_T prGlueInfo = NULL; */
  1628. /* P_ADAPTER_T prAdapter = NULL; */
  1629. /* P_MSG_P2P_FUNCTION_SWITCH_T prFuncSwitch; */
  1630. ASSERT(prDev);
  1631. #if 0 /* Move after device name set. (mtk_p2p_set_local_dev_info) */
  1632. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1633. ASSERT(prGlueInfo);
  1634. prAdapter = prGlueInfo->prAdapter;
  1635. ASSERT(prAdapter);
  1636. /* 1. switch P2P-FSM on */
  1637. /* 1.1 allocate for message */
  1638. prFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter,
  1639. RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  1640. if (!prFuncSwitch) {
  1641. ASSERT(0); /* Can't trigger P2P FSM */
  1642. return -ENOMEM;
  1643. }
  1644. /* 1.2 fill message */
  1645. prFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  1646. prFuncSwitch->fgIsFuncOn = TRUE;
  1647. /* 1.3 send message */
  1648. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prFuncSwitch, MSG_SEND_METHOD_BUF);
  1649. #endif
  1650. /* 2. carrier on & start TX queue */
  1651. netif_carrier_on(prDev);
  1652. netif_tx_start_all_queues(prDev);
  1653. return 0; /* success */
  1654. } /* end of p2pOpen() */
  1655. /*----------------------------------------------------------------------------*/
  1656. /*!
  1657. * \brief A function for net_device stop (ifdown)
  1658. *
  1659. * \param[in] prDev Pointer to struct net_device.
  1660. *
  1661. * \retval 0 The execution succeeds.
  1662. * \retval < 0 The execution failed.
  1663. */
  1664. /*----------------------------------------------------------------------------*/
  1665. static int p2pStop(IN struct net_device *prDev)
  1666. {
  1667. P_GLUE_INFO_T prGlueInfo = NULL;
  1668. /* P_ADAPTER_T prAdapter = NULL; */
  1669. /* P_MSG_P2P_FUNCTION_SWITCH_T prFuncSwitch; */
  1670. P_GL_P2P_INFO_T prGlueP2pInfo = (P_GL_P2P_INFO_T) NULL;
  1671. struct cfg80211_scan_request *prScanRequest = NULL;
  1672. GLUE_SPIN_LOCK_DECLARATION();
  1673. ASSERT(prDev);
  1674. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1675. ASSERT(prGlueInfo);
  1676. prGlueP2pInfo = prGlueInfo->prP2PInfo;
  1677. ASSERT(prGlueP2pInfo);
  1678. /* CFG80211 down */
  1679. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1680. if (prGlueP2pInfo->prScanRequest != NULL) {
  1681. prScanRequest = prGlueP2pInfo->prScanRequest;
  1682. prGlueP2pInfo->prScanRequest = NULL;
  1683. }
  1684. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1685. if (prScanRequest)
  1686. cfg80211_scan_done(prScanRequest, TRUE);
  1687. #if 0
  1688. /* 1. stop TX queue */
  1689. netif_tx_stop_all_queues(prDev);
  1690. /* 2. switch P2P-FSM off */
  1691. /* 2.1 allocate for message */
  1692. prFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter,
  1693. RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  1694. if (!prFuncSwitch) {
  1695. ASSERT(0); /* Can't trigger P2P FSM */
  1696. return -ENOMEM;
  1697. }
  1698. /* 2.2 fill message */
  1699. prFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  1700. prFuncSwitch->fgIsFuncOn = FALSE;
  1701. /* 2.3 send message */
  1702. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prFuncSwitch, MSG_SEND_METHOD_BUF);
  1703. #endif
  1704. /* 3. stop queue and turn off carrier */
  1705. prGlueInfo->prP2PInfo->eState = PARAM_MEDIA_STATE_DISCONNECTED;
  1706. netif_tx_stop_all_queues(prDev);
  1707. if (netif_carrier_ok(prDev))
  1708. netif_carrier_off(prDev);
  1709. return 0;
  1710. } /* end of p2pStop() */
  1711. /*----------------------------------------------------------------------------*/
  1712. /*!
  1713. * \brief A method of struct net_device, to get the network interface statistical
  1714. * information.
  1715. *
  1716. * Whenever an application needs to get statistics for the interface, this method
  1717. * is called. This happens, for example, when ifconfig or netstat -i is run.
  1718. *
  1719. * \param[in] prDev Pointer to struct net_device.
  1720. *
  1721. * \return net_device_stats buffer pointer.
  1722. */
  1723. /*----------------------------------------------------------------------------*/
  1724. struct net_device_stats *p2pGetStats(IN struct net_device *prDev)
  1725. {
  1726. P_GLUE_INFO_T prGlueInfo = NULL;
  1727. ASSERT(prDev);
  1728. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1729. #if CFG_SUPPORT_PERSIST_NETDEV
  1730. /* @FIXME */
  1731. /* prDev->stats.rx_packets = 0; */
  1732. /* prDev->stats.tx_packets = 0; */
  1733. prDev->stats.tx_errors = 0;
  1734. prDev->stats.rx_errors = 0;
  1735. /* prDev->stats.rx_bytes = 0; */
  1736. /* prDev->stats.tx_bytes = 0; */
  1737. prDev->stats.multicast = 0;
  1738. return &prDev->stats;
  1739. #else
  1740. /* prGlueInfo->prP2PInfo->rNetDevStats.rx_packets = 0; */
  1741. /* prGlueInfo->prP2PInfo->rNetDevStats.tx_packets = 0; */
  1742. prGlueInfo->prP2PInfo->rNetDevStats.tx_errors = 0;
  1743. prGlueInfo->prP2PInfo->rNetDevStats.rx_errors = 0;
  1744. /* prGlueInfo->prP2PInfo->rNetDevStats.rx_bytes = 0; */
  1745. /* prGlueInfo->prP2PInfo->rNetDevStats.tx_bytes = 0; */
  1746. /* prGlueInfo->prP2PInfo->rNetDevStats.rx_errors = 0; */
  1747. prGlueInfo->prP2PInfo->rNetDevStats.multicast = 0;
  1748. return &prGlueInfo->prP2PInfo->rNetDevStats;
  1749. #endif
  1750. } /* end of p2pGetStats() */
  1751. static void p2pSetMulticastList(IN struct net_device *prDev)
  1752. {
  1753. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  1754. prGlueInfo = (NULL != prDev) ? *((P_GLUE_INFO_T *) netdev_priv(prDev)) : NULL;
  1755. ASSERT(prDev);
  1756. ASSERT(prGlueInfo);
  1757. if (!prDev || !prGlueInfo) {
  1758. DBGLOG(P2P, WARN, "abnormal dev or skb: prDev(0x%p), prGlueInfo(0x%p)\n", prDev, prGlueInfo);
  1759. return;
  1760. }
  1761. g_P2pPrDev = prDev;
  1762. /* 4 Mark HALT, notify main thread to finish current job */
  1763. /* prGlueInfo->u4Flag |= GLUE_FLAG_SUB_MOD_MULTICAST; */
  1764. set_bit(GLUE_FLAG_SUB_MOD_MULTICAST_BIT, &prGlueInfo->ulFlag);
  1765. /* wake up main thread */
  1766. wake_up_interruptible(&prGlueInfo->waitq);
  1767. } /* p2pSetMulticastList */
  1768. /*----------------------------------------------------------------------------*/
  1769. /*!
  1770. * \brief This function is to set multicast list and set rx mode.
  1771. *
  1772. * \param[in] prDev Pointer to struct net_device
  1773. *
  1774. * \return (none)
  1775. */
  1776. /*----------------------------------------------------------------------------*/
  1777. void mtk_p2p_wext_set_Multicastlist(P_GLUE_INFO_T prGlueInfo)
  1778. {
  1779. UINT_32 u4SetInfoLen = 0;
  1780. struct net_device *prDev = g_P2pPrDev;
  1781. prGlueInfo = (NULL != prDev) ? *((P_GLUE_INFO_T *) netdev_priv(prDev)) : NULL;
  1782. ASSERT(prDev);
  1783. ASSERT(prGlueInfo);
  1784. if (!prDev || !prGlueInfo) {
  1785. DBGLOG(P2P, WARN, "abnormal dev or skb: prDev(0x%p), prGlueInfo(0x%p)\n", prDev, prGlueInfo);
  1786. return;
  1787. }
  1788. if (prDev->flags & IFF_PROMISC)
  1789. prGlueInfo->prP2PInfo->u4PacketFilter |= PARAM_PACKET_FILTER_PROMISCUOUS;
  1790. if (prDev->flags & IFF_BROADCAST)
  1791. prGlueInfo->prP2PInfo->u4PacketFilter |= PARAM_PACKET_FILTER_BROADCAST;
  1792. if (prDev->flags & IFF_MULTICAST) {
  1793. if ((prDev->flags & IFF_ALLMULTI) ||
  1794. (netdev_mc_count(prDev) > MAX_NUM_GROUP_ADDR)) {
  1795. prGlueInfo->prP2PInfo->u4PacketFilter |= PARAM_PACKET_FILTER_ALL_MULTICAST;
  1796. } else {
  1797. prGlueInfo->prP2PInfo->u4PacketFilter |= PARAM_PACKET_FILTER_MULTICAST;
  1798. }
  1799. }
  1800. if (prGlueInfo->prP2PInfo->u4PacketFilter & PARAM_PACKET_FILTER_MULTICAST) {
  1801. /* Prepare multicast address list */
  1802. struct netdev_hw_addr *ha;
  1803. UINT_32 i = 0;
  1804. netdev_for_each_mc_addr(ha, prDev) {
  1805. if (i < MAX_NUM_GROUP_ADDR) {
  1806. COPY_MAC_ADDR(&(prGlueInfo->prP2PInfo->aucMCAddrList[i]), ha->addr);
  1807. i++;
  1808. }
  1809. }
  1810. DBGLOG(P2P, TRACE, "SEt Multicast Address List\n");
  1811. if (i >= MAX_NUM_GROUP_ADDR)
  1812. return;
  1813. wlanoidSetP2PMulticastList(prGlueInfo->prAdapter,
  1814. &(prGlueInfo->prP2PInfo->aucMCAddrList[0]), (i * ETH_ALEN), &u4SetInfoLen);
  1815. }
  1816. } /* end of p2pSetMulticastList() */
  1817. /*----------------------------------------------------------------------------*/
  1818. /*!
  1819. * * \brief This function is TX entry point of NET DEVICE.
  1820. * *
  1821. * * \param[in] prSkb Pointer of the sk_buff to be sent
  1822. * * \param[in] prDev Pointer to struct net_device
  1823. * *
  1824. * * \retval NETDEV_TX_OK - on success.
  1825. * * \retval NETDEV_TX_BUSY - on failure, packet will be discarded by upper layer.
  1826. * */
  1827. /*----------------------------------------------------------------------------*/
  1828. int p2pHardStartXmit(IN struct sk_buff *prSkb, IN struct net_device *prDev)
  1829. {
  1830. P_QUE_ENTRY_T prQueueEntry = NULL;
  1831. P_QUE_T prTxQueue = NULL;
  1832. P_GLUE_INFO_T prGlueInfo = NULL;
  1833. UINT_16 u2QueueIdx = 0;
  1834. P_BSS_INFO_T prP2pBssInfo = NULL;
  1835. GLUE_SPIN_LOCK_DECLARATION();
  1836. ASSERT(prSkb);
  1837. ASSERT(prDev);
  1838. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1839. if (prGlueInfo->ulFlag & GLUE_FLAG_HALT) {
  1840. DBGLOG(P2P, ERROR, "GLUE_FLAG_HALT skip tx\n");
  1841. dev_kfree_skb(prSkb);
  1842. return NETDEV_TX_OK;
  1843. }
  1844. #if (CFG_SUPPORT_MET_PROFILING == 1)
  1845. kalMetProfilingStart(prGlueInfo, prSkb);
  1846. #endif
  1847. /* mark as P2P packets */
  1848. GLUE_SET_PKT_FLAG_P2P(prSkb);
  1849. #if CFG_ENABLE_PKT_LIFETIME_PROFILE
  1850. GLUE_SET_PKT_ARRIVAL_TIME(prSkb, kalGetTimeTick());
  1851. #endif
  1852. STATS_TX_TIME_ARRIVE(prSkb);
  1853. prQueueEntry = (P_QUE_ENTRY_T) GLUE_GET_PKT_QUEUE_ENTRY(prSkb);
  1854. prTxQueue = &prGlueInfo->rTxQueue;
  1855. /* Statistic usage. */
  1856. prGlueInfo->prP2PInfo->rNetDevStats.tx_bytes += prSkb->len;
  1857. prGlueInfo->prP2PInfo->rNetDevStats.tx_packets++;
  1858. /* prDev->stats.tx_packets++; */
  1859. if (wlanProcessSecurityFrame(prGlueInfo->prAdapter, (P_NATIVE_PACKET) prSkb) == FALSE) {
  1860. u2QueueIdx = skb_get_queue_mapping(prSkb);
  1861. ASSERT(u2QueueIdx < CFG_MAX_TXQ_NUM);
  1862. if (u2QueueIdx >= CFG_MAX_TXQ_NUM) {
  1863. DBGLOG(P2P, ERROR, "Incorrect queue index, skip this frame\n");
  1864. prGlueInfo->prP2PInfo->rNetDevStats.tx_bytes -= prSkb->len;
  1865. prGlueInfo->prP2PInfo->rNetDevStats.tx_packets--;
  1866. dev_kfree_skb(prSkb);
  1867. return NETDEV_TX_OK;
  1868. }
  1869. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_TX_QUE);
  1870. QUEUE_INSERT_TAIL(prTxQueue, prQueueEntry);
  1871. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_TX_QUE);
  1872. GLUE_INC_REF_CNT(prGlueInfo->i4TxPendingFrameNum);
  1873. GLUE_INC_REF_CNT(prGlueInfo->ai4TxPendingFrameNumPerQueue[NETWORK_TYPE_P2P_INDEX][u2QueueIdx]);
  1874. if (prGlueInfo->ai4TxPendingFrameNumPerQueue[NETWORK_TYPE_P2P_INDEX][u2QueueIdx] >=
  1875. CFG_TX_STOP_NETIF_PER_QUEUE_THRESHOLD) {
  1876. netif_stop_subqueue(prDev, u2QueueIdx);
  1877. }
  1878. } else {
  1879. GLUE_INC_REF_CNT(prGlueInfo->i4TxPendingSecurityFrameNum);
  1880. }
  1881. kalSetEvent(prGlueInfo);
  1882. prP2pBssInfo = &prGlueInfo->prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX];
  1883. if ((prP2pBssInfo->eConnectionState == PARAM_MEDIA_STATE_CONNECTED) ||
  1884. (prP2pBssInfo->rStaRecOfClientList.u4NumElem > 0))
  1885. kalPerMonStart(prGlueInfo);
  1886. return NETDEV_TX_OK;
  1887. } /* end of p2pHardStartXmit() */
  1888. /*----------------------------------------------------------------------------*/
  1889. /*!
  1890. * \brief A method of struct net_device, a primary SOCKET interface to configure
  1891. * the interface lively. Handle an ioctl call on one of our devices.
  1892. * Everything Linux ioctl specific is done here. Then we pass the contents
  1893. * of the ifr->data to the request message handler.
  1894. *
  1895. * \param[in] prDev Linux kernel netdevice
  1896. *
  1897. * \param[in] prIFReq Our private ioctl request structure, typed for the generic
  1898. * struct ifreq so we can use ptr to function
  1899. *
  1900. * \param[in] cmd Command ID
  1901. *
  1902. * \retval WLAN_STATUS_SUCCESS The IOCTL command is executed successfully.
  1903. * \retval OTHER The execution of IOCTL command is failed.
  1904. */
  1905. /*----------------------------------------------------------------------------*/
  1906. int p2pDoIOCTL(struct net_device *prDev, struct ifreq *prIFReq, int i4Cmd)
  1907. {
  1908. P_GLUE_INFO_T prGlueInfo = NULL;
  1909. int ret = 0;
  1910. #if 0
  1911. char *prExtraBuf = NULL;
  1912. UINT_32 u4ExtraSize = 0;
  1913. struct iwreq *prIwReq = (struct iwreq *)prIFReq;
  1914. struct iw_request_info rIwReqInfo;
  1915. #endif
  1916. ASSERT(prDev && prIFReq);
  1917. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1918. if (prGlueInfo->u4ReadyFlag == 0) {
  1919. /* adapter not ready yet */
  1920. return -EINVAL;
  1921. }
  1922. if (i4Cmd == SIOCDEVPRIVATE + 1) {
  1923. ret = priv_support_driver_cmd(prDev, prIFReq, i4Cmd);
  1924. } else {
  1925. DBGLOG(INIT, WARN, "Unexpected ioctl command: 0x%04x\n", i4Cmd);
  1926. ret = -1;
  1927. }
  1928. #if 0
  1929. rIwReqInfo.cmd = (__u16) i4Cmd;
  1930. rIwReqInfo.flags = 0;
  1931. switch (i4Cmd) {
  1932. case SIOCSIWENCODEEXT:
  1933. /* Set Encryption Material after 4-way handshaking is done */
  1934. if (prIwReq->u.encoding.pointer) {
  1935. u4ExtraSize = prIwReq->u.encoding.length;
  1936. if (u4ExtraSize > sizeof(struct iw_encode_ext)) {
  1937. ret = -EINVAL;
  1938. break;
  1939. }
  1940. prExtraBuf = kalMemAlloc(u4ExtraSize, VIR_MEM_TYPE);
  1941. if (!prExtraBuf) {
  1942. ret = -ENOMEM;
  1943. break;
  1944. }
  1945. if (copy_from_user(prExtraBuf, prIwReq->u.encoding.pointer, u4ExtraSize))
  1946. ret = -EFAULT;
  1947. } else if (prIwReq->u.encoding.length != 0) {
  1948. ret = -EINVAL;
  1949. break;
  1950. }
  1951. if (ret == 0)
  1952. ret = mtk_p2p_wext_set_key(prDev, &rIwReqInfo, &(prIwReq->u), prExtraBuf);
  1953. kalMemFree(prExtraBuf, VIR_MEM_TYPE, u4ExtraSize);
  1954. prExtraBuf = NULL;
  1955. break;
  1956. case SIOCSIWMLME:
  1957. /* IW_MLME_DISASSOC used for disconnection */
  1958. if (prIwReq->u.data.length != sizeof(struct iw_mlme)) {
  1959. DBGLOG(P2P, WARN, "MLME buffer strange:%d\n", prIwReq->u.data.length);
  1960. ret = -EINVAL;
  1961. break;
  1962. }
  1963. if (!prIwReq->u.data.pointer) {
  1964. ret = -EINVAL;
  1965. break;
  1966. }
  1967. prExtraBuf = kalMemAlloc(sizeof(struct iw_mlme), VIR_MEM_TYPE);
  1968. if (!prExtraBuf) {
  1969. ret = -ENOMEM;
  1970. break;
  1971. }
  1972. if (copy_from_user(prExtraBuf, prIwReq->u.data.pointer, sizeof(struct iw_mlme)))
  1973. ret = -EFAULT;
  1974. else
  1975. ret = mtk_p2p_wext_mlme_handler(prDev, &rIwReqInfo, &(prIwReq->u), prExtraBuf);
  1976. kalMemFree(prExtraBuf, VIR_MEM_TYPE, sizeof(struct iw_mlme));
  1977. prExtraBuf = NULL;
  1978. break;
  1979. case SIOCGIWPRIV:
  1980. /* This ioctl is used to list all IW privilege ioctls */
  1981. ret = mtk_p2p_wext_get_priv(prDev, &rIwReqInfo, &(prIwReq->u), NULL);
  1982. break;
  1983. case SIOCGIWSCAN:
  1984. ret = mtk_p2p_wext_discovery_results(prDev, &rIwReqInfo, &(prIwReq->u), NULL);
  1985. break;
  1986. case SIOCSIWAUTH:
  1987. ret = mtk_p2p_wext_set_auth(prDev, &rIwReqInfo, &(prIwReq->u), NULL);
  1988. break;
  1989. case IOC_P2P_CFG_DEVICE:
  1990. case IOC_P2P_PROVISION_COMPLETE:
  1991. case IOC_P2P_START_STOP_DISCOVERY:
  1992. case IOC_P2P_DISCOVERY_RESULTS:
  1993. case IOC_P2P_WSC_BEACON_PROBE_RSP_IE:
  1994. case IOC_P2P_CONNECT_DISCONNECT:
  1995. case IOC_P2P_PASSWORD_READY:
  1996. case IOC_P2P_GET_STRUCT:
  1997. case IOC_P2P_SET_STRUCT:
  1998. case IOC_P2P_GET_REQ_DEVICE_INFO:
  1999. ret =
  2000. rP2PIwPrivHandler[i4Cmd - SIOCIWFIRSTPRIV] (prDev, &rIwReqInfo, &(prIwReq->u),
  2001. (char *)&(prIwReq->u));
  2002. break;
  2003. #if CFG_SUPPORT_P2P_RSSI_QUERY
  2004. case SIOCGIWSTATS:
  2005. ret = mtk_p2p_wext_get_rssi(prDev, &rIwReqInfo, &(prIwReq->u), NULL);
  2006. break;
  2007. #endif
  2008. case IOC_GET_PRIVATE_IOCTL_CMD:
  2009. ret = priv_support_driver_cmd(prDev, prIFReq, i4Cmd);
  2010. break;
  2011. default:
  2012. ret = -ENOTTY;
  2013. }
  2014. #endif
  2015. return ret;
  2016. } /* end of p2pDoIOCTL() */
  2017. /*----------------------------------------------------------------------------*/
  2018. /*!
  2019. * \brief To override p2p interface address
  2020. *
  2021. * \param[in] prDev Net device requested.
  2022. * \param[in] addr Pointer to address
  2023. *
  2024. * \retval 0 For success.
  2025. * \retval -E2BIG For user's buffer size is too small.
  2026. * \retval -EFAULT For fail.
  2027. *
  2028. */
  2029. /*----------------------------------------------------------------------------*/
  2030. int p2pSetMACAddress(IN struct net_device *prDev, void *addr)
  2031. {
  2032. P_ADAPTER_T prAdapter = NULL;
  2033. P_GLUE_INFO_T prGlueInfo = NULL;
  2034. ASSERT(prDev);
  2035. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2036. ASSERT(prGlueInfo);
  2037. prAdapter = prGlueInfo->prAdapter;
  2038. ASSERT(prAdapter);
  2039. /* @FIXME */
  2040. return eth_mac_addr(prDev, addr);
  2041. }
  2042. /*----------------------------------------------------------------------------*/
  2043. /*!
  2044. * \brief indicate an event to supplicant for device found
  2045. *
  2046. * \param[in] prGlueInfo Pointer of GLUE_INFO_T
  2047. *
  2048. * \retval TRUE Success.
  2049. * \retval FALSE Failure
  2050. */
  2051. /*----------------------------------------------------------------------------*/
  2052. BOOLEAN kalP2PIndicateFound(IN P_GLUE_INFO_T prGlueInfo)
  2053. {
  2054. union iwreq_data evt;
  2055. UINT_8 aucBuffer[IW_CUSTOM_MAX];
  2056. ASSERT(prGlueInfo);
  2057. memset(&evt, 0, sizeof(evt));
  2058. snprintf(aucBuffer, IW_CUSTOM_MAX - 1, "P2P_DVC_FND");
  2059. evt.data.length = strlen(aucBuffer);
  2060. /* indicate IWEVP2PDVCFND event */
  2061. wireless_send_event(prGlueInfo->prP2PInfo->prDevHandler, IWEVCUSTOM, &evt, aucBuffer);
  2062. return FALSE;
  2063. } /* end of kalP2PIndicateFound() */
  2064. #if 0
  2065. /*----------------------------------------------------------------------------*/
  2066. /*!
  2067. * \brief To report the private supported IOCTLs table to user space.
  2068. *
  2069. * \param[in] prDev Net device requested.
  2070. * \param[out] prIfReq Pointer to ifreq structure, content is copied back to
  2071. * user space buffer in gl_iwpriv_table.
  2072. *
  2073. * \retval 0 For success.
  2074. * \retval -E2BIG For user's buffer size is too small.
  2075. * \retval -EFAULT For fail.
  2076. *
  2077. */
  2078. /*----------------------------------------------------------------------------*/
  2079. int
  2080. mtk_p2p_wext_get_priv(IN struct net_device *prDev,
  2081. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2082. {
  2083. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  2084. UINT_16 u2BufferSize = 0;
  2085. ASSERT(prDev);
  2086. u2BufferSize = prData->length;
  2087. /* update our private table size */
  2088. prData->length = (__u16) sizeof(rP2PIwPrivTable) / sizeof(struct iw_priv_args);
  2089. if (u2BufferSize < prData->length)
  2090. return -E2BIG;
  2091. if (prData->length) {
  2092. if (copy_to_user(prData->pointer, rP2PIwPrivTable, sizeof(rP2PIwPrivTable)))
  2093. return -EFAULT;
  2094. }
  2095. return 0;
  2096. } /* end of mtk_p2p_wext_get_priv() */
  2097. /*----------------------------------------------------------------------------*/
  2098. /*!
  2099. * \brief To indicate P2P-FSM for re-associate to the connecting device
  2100. *
  2101. * \param[in] prDev Net device requested.
  2102. * \param[inout] wrqu Pointer to iwreq_data
  2103. *
  2104. * \retval 0 For success.
  2105. * \retval -EFAULT For fail.
  2106. *
  2107. */
  2108. /*----------------------------------------------------------------------------*/
  2109. int
  2110. mtk_p2p_wext_reconnect(IN struct net_device *prDev,
  2111. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2112. {
  2113. #if 0
  2114. P_ADAPTER_T prAdapter = NULL;
  2115. P_GLUE_INFO_T prGlueInfo = NULL;
  2116. P_MSG_HDR_T prMsgHdr;
  2117. ASSERT(prDev);
  2118. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2119. ASSERT(prGlueInfo);
  2120. prAdapter = prGlueInfo->prAdapter;
  2121. ASSERT(prAdapter);
  2122. prMsgHdr = (P_MSG_HDR_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_HDR_T));
  2123. if (!prMsgHdr) {
  2124. ASSERT(0); /* Can't trigger P2P FSM */
  2125. return -ENOMEM;
  2126. }
  2127. /* 1.2 fill message */
  2128. DBGLOG(P2P, TRACE, "mtk_p2p_wext_reconnect: P2P Reconnect\n");
  2129. /* 1.3 send message */
  2130. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgHdr, MSG_SEND_METHOD_BUF);
  2131. #endif
  2132. return 0;
  2133. } /* end of mtk_p2p_wext_reconnect() */
  2134. /*----------------------------------------------------------------------------*/
  2135. /*!
  2136. * \brief MLME command handler
  2137. *
  2138. * \param[in] prDev Net device requested.
  2139. * \param[inout] wrqu Pointer to iwreq_data
  2140. *
  2141. * \retval 0 Success.
  2142. * \retval -EFAULT Setting parameters to driver fail.
  2143. * \retval -EOPNOTSUPP Key size not supported.
  2144. *
  2145. * \note
  2146. */
  2147. /*----------------------------------------------------------------------------*/
  2148. int
  2149. mtk_p2p_wext_mlme_handler(IN struct net_device *prDev,
  2150. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2151. {
  2152. #if 0
  2153. P_ADAPTER_T prAdapter = NULL;
  2154. P_GLUE_INFO_T prGlueInfo = NULL;
  2155. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  2156. P_MSG_P2P_CONNECTION_ABORT_T prMsgP2PConnAbt = (P_MSG_P2P_CONNECTION_ABORT_T) NULL;
  2157. P_BSS_INFO_T prP2pBssInfo = (P_BSS_INFO_T) NULL;
  2158. ASSERT(prDev);
  2159. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2160. ASSERT(prGlueInfo);
  2161. prAdapter = prGlueInfo->prAdapter;
  2162. ASSERT(prAdapter);
  2163. prP2pBssInfo = &(prAdapter->rWifiVar.arBssInfo[NETWORK_TYPE_P2P_INDEX]);
  2164. DBGLOG(P2P, TRACE, "mtk_p2p_wext_mlme_handler:\n");
  2165. switch (mlme->cmd) {
  2166. case IW_MLME_DISASSOC:
  2167. prMsgP2PConnAbt =
  2168. (P_MSG_HDR_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_ABORT_T));
  2169. if (!prMsgP2PConnAbt) {
  2170. ASSERT(0); /* Can't trigger P2P FSM */
  2171. return -ENOMEM;
  2172. }
  2173. COPY_MAC_ADDR(prMsgP2PConnAbt->aucTargetID, mlme->addr.sa_data);
  2174. prMsgP2PConnAbt->u2ReasonCode = mlme->reason_code;
  2175. if (EQUAL_MAC_ADDR(prMsgP2PConnAbt->aucTargetID, prP2pBssInfo->aucOwnMacAddr)) {
  2176. DBGLOG(P2P, TRACE, "P2P Connection Abort:\n");
  2177. /* 1.2 fill message */
  2178. prMsgP2PConnAbt->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_ABORT;
  2179. } else {
  2180. DBGLOG(P2P, TRACE, "P2P Connection Pause:\n");
  2181. /* 1.2 fill message */
  2182. }
  2183. /* 1.3 send message */
  2184. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PConnAbt, MSG_SEND_METHOD_BUF);
  2185. break;
  2186. default:
  2187. return -EOPNOTSUPP;
  2188. }
  2189. #endif
  2190. return 0;
  2191. } /* end of mtk_p2p_wext_mlme_handler() */
  2192. /*----------------------------------------------------------------------------*/
  2193. /*!
  2194. * \brief P2P Private I/O Control handler (IOC_P2P_PROVISION_COMPLETE)
  2195. *
  2196. * \param[in] prDev Net device requested.
  2197. * \param[inout] wrqu Pointer to iwreq_data
  2198. *
  2199. * \retval 0 Success.
  2200. * \retval -EFAULT Setting parameters to driver fail.
  2201. * \retval -EOPNOTSUPP Key size not supported.
  2202. *
  2203. * \note
  2204. */
  2205. /*----------------------------------------------------------------------------*/
  2206. int
  2207. mtk_p2p_wext_set_provision_complete(IN struct net_device *prDev,
  2208. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2209. {
  2210. #if 0
  2211. P_ADAPTER_T prAdapter = NULL;
  2212. P_GLUE_INFO_T prGlueInfo = NULL;
  2213. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  2214. P_MSG_HDR_T prMsgHdr;
  2215. ASSERT(prDev);
  2216. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2217. ASSERT(prGlueInfo);
  2218. prAdapter = prGlueInfo->prAdapter;
  2219. ASSERT(prAdapter);
  2220. switch (prData->flags) {
  2221. case P2P_PROVISIONING_SUCCESS:
  2222. prMsgHdr = (P_MSG_HDR_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_HDR_T));
  2223. if (!prMsgHdr) {
  2224. ASSERT(0); /* Can't trigger P2P FSM */
  2225. return -ENOMEM;
  2226. }
  2227. /* 1.2 fill message */
  2228. prGlueInfo->prP2PInfo->u4CipherPairwise = IW_AUTH_CIPHER_CCMP;
  2229. /* 1.3 send message */
  2230. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgHdr, MSG_SEND_METHOD_BUF);
  2231. break;
  2232. case P2P_PROVISIONING_FAIL:
  2233. break;
  2234. default:
  2235. return -EOPNOTSUPP;
  2236. }
  2237. #endif
  2238. return 0;
  2239. } /* end of mtk_p2p_wext_set_provision_complete() */
  2240. /*----------------------------------------------------------------------------*/
  2241. /*!
  2242. * \brief P2P Private I/O Control handler (IOC_P2P_START_STOP_DISCOVERY)
  2243. *
  2244. * \param[in] prDev Net device requested.
  2245. * \param[inout] wrqu Pointer to iwreq_data
  2246. *
  2247. * \retval 0 Success.
  2248. * \retval -EFAULT Setting parameters to driver fail.
  2249. * \retval -EOPNOTSUPP Key size not supported.
  2250. *
  2251. * \note
  2252. */
  2253. /*----------------------------------------------------------------------------*/
  2254. int
  2255. mtk_p2p_wext_start_stop_discovery(IN struct net_device *prDev,
  2256. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2257. {
  2258. #if 0
  2259. P_ADAPTER_T prAdapter = NULL;
  2260. P_GLUE_INFO_T prGlueInfo = NULL;
  2261. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  2262. P_IW_P2P_REQ_DEVICE_TYPE prReqDeviceType = (P_IW_P2P_REQ_DEVICE_TYPE) extra;
  2263. UINT_8 au4IeBuf[MAX_IE_LENGTH];
  2264. P_MSG_HDR_T prMsgHdr;
  2265. P_MSG_P2P_DEVICE_DISCOVER_T prDiscoverMsg;
  2266. P_P2P_CONNECTION_SETTINGS_T prConnSettings;
  2267. UINT_8 aucNullAddr[] = NULL_MAC_ADDR;
  2268. ASSERT(prDev);
  2269. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2270. ASSERT(prGlueInfo);
  2271. prAdapter = prGlueInfo->prAdapter;
  2272. ASSERT(prAdapter);
  2273. prConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
  2274. if (prData->flags == P2P_STOP_DISCOVERY) {
  2275. prMsgHdr = (P_MSG_HDR_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_HDR_T));
  2276. if (!prMsgHdr) {
  2277. ASSERT(0); /* Can't trigger P2P FSM */
  2278. return -ENOMEM;
  2279. }
  2280. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgHdr, MSG_SEND_METHOD_BUF);
  2281. } else if (prData->flags == P2P_START_DISCOVERY) {
  2282. /* retrieve IE for Probe Response */
  2283. if (prReqDeviceType->probe_rsp_len > 0) {
  2284. if (prReqDeviceType->probe_rsp_len <= MAX_IE_LENGTH) {
  2285. if (copy_from_user
  2286. (prGlueInfo->prP2PInfo->aucWSCIE[2], prReqDeviceType->probe_rsp_ie,
  2287. prReqDeviceType->probe_rsp_len)) {
  2288. return -EFAULT;
  2289. }
  2290. prGlueInfo->prP2PInfo->u2WSCIELen[2] = prReqDeviceType->probe_rsp_len;
  2291. } else {
  2292. return -E2BIG;
  2293. }
  2294. }
  2295. /* retrieve IE for Probe Request */
  2296. if (prReqDeviceType->probe_req_len > 0) {
  2297. if (prReqDeviceType->probe_req_len <= MAX_IE_LENGTH) {
  2298. if (copy_from_user
  2299. (prGlueInfo->prP2PInfo->aucWSCIE[1], prReqDeviceType->probe_req_ie,
  2300. prReqDeviceType->probe_req_len)) {
  2301. return -EFAULT;
  2302. }
  2303. prGlueInfo->prP2PInfo->u2WSCIELen[1] = prReqDeviceType->probe_req_len;
  2304. } else {
  2305. return -E2BIG;
  2306. }
  2307. }
  2308. /* update IE for Probe Request */
  2309. if (prReqDeviceType->scan_type == P2P_LISTEN) {
  2310. /* update listening parameter */
  2311. /* @TODO: update prConnSettings for Probe Response IE */
  2312. } else {
  2313. /* indicate P2P-FSM with MID_MNY_P2P_DEVICE_DISCOVERY */
  2314. prDiscoverMsg = (P_MSG_P2P_DEVICE_DISCOVER_T) cnmMemAlloc(prAdapter,
  2315. RAM_TYPE_MSG,
  2316. sizeof(MSG_P2P_DEVICE_DISCOVER_T));
  2317. if (!prDiscoverMsg) {
  2318. ASSERT(0); /* Can't trigger P2P FSM */
  2319. return -ENOMEM;
  2320. }
  2321. prDiscoverMsg->rMsgHdr.eMsgId = MID_MNY_P2P_DEVICE_DISCOVERY;
  2322. prDiscoverMsg->u4DevDiscoverTime = 0; /* unlimited */
  2323. prDiscoverMsg->fgIsSpecificType = TRUE;
  2324. prDiscoverMsg->rTargetDeviceType.u2CategoryID =
  2325. *(PUINT_16) (&(prReqDeviceType->pri_device_type[0]));
  2326. prDiscoverMsg->rTargetDeviceType.u2SubCategoryID =
  2327. *(PUINT_16) (&(prReqDeviceType->pri_device_type[6]));
  2328. COPY_MAC_ADDR(prDiscoverMsg->aucTargetDeviceID, aucNullAddr);
  2329. /* @FIXME: parameter to be refined, where to pass IE buffer ? */
  2330. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prDiscoverMsg, MSG_SEND_METHOD_BUF);
  2331. }
  2332. } else {
  2333. return -EINVAL;
  2334. }
  2335. #endif
  2336. return 0;
  2337. } /* end of mtk_p2p_wext_start_stop_discovery() */
  2338. /*----------------------------------------------------------------------------*/
  2339. /*!
  2340. * \brief P2P Private I/O Control handler (IOC_P2P_SET_INT)
  2341. *
  2342. * \param[in] prDev Net device requested.
  2343. * \param[inout] wrqu Pointer to iwreq_data
  2344. *
  2345. * \retval 0 Success.
  2346. * \retval -EFAULT Setting parameters to driver fail.
  2347. * \retval -EOPNOTSUPP Setting parameters not support.
  2348. *
  2349. * \note
  2350. */
  2351. /*----------------------------------------------------------------------------*/
  2352. int
  2353. mtk_p2p_wext_invitation_request(IN struct net_device *prDev,
  2354. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2355. {
  2356. int i4Status = 0;
  2357. #if 0
  2358. P_ADAPTER_T prAdapter = (P_ADAPTER_T) NULL;
  2359. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  2360. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  2361. P_IW_P2P_IOCTL_INVITATION_STRUCT prIoctlInvitation = (P_IW_P2P_IOCTL_INVITATION_STRUCT) NULL;
  2362. do {
  2363. if ((prDev == NULL) || (extra == NULL)) {
  2364. ASSERT(FALSE);
  2365. i4Status = -EINVAL;
  2366. break;
  2367. }
  2368. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2369. prIoctlInvitation = (P_IW_P2P_IOCTL_INVITATION_STRUCT) extra;
  2370. if (prGlueInfo == NULL) {
  2371. i4Status = -EINVAL;
  2372. break;
  2373. }
  2374. prAdapter = prGlueInfo->prAdapter;
  2375. if (prAdapter == NULL) {
  2376. i4Status = -EINVAL;
  2377. break;
  2378. }
  2379. if (prIoctlInvitation->ucReinvoke == 1) {
  2380. /* TODO: Set Group ID */
  2381. p2pFuncSetGroupID(prAdapter, prIoctlInvitation->aucGroupID, prIoctlInvitation->aucSsid,
  2382. prIoctlInvitation->u4SsidLen);
  2383. }
  2384. else {
  2385. P_MSG_P2P_INVITATION_REQUEST_T prMsgP2PInvitationReq = (P_MSG_P2P_INVITATION_REQUEST_T) NULL;
  2386. /* TODO: Do Invitation. */
  2387. prMsgP2PInvitationReq =
  2388. (P_MSG_P2P_INVITATION_REQUEST_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG,
  2389. sizeof(MSG_P2P_INVITATION_REQUEST_T));
  2390. if (!prMsgP2PInvitationReq) {
  2391. ASSERT(0); /* Can't trigger P2P FSM */
  2392. i4Status = -ENOMEM;
  2393. break;
  2394. }
  2395. /* 1.2 fill message */
  2396. kalMemCopy(prMsgP2PInvitationReq->aucDeviceID, prIoctlInvitation->aucDeviceID, MAC_ADDR_LEN);
  2397. DBGLOG(P2P, TRACE, "mtk_p2p_wext_invitation_request: P2P Invitation Req\n");
  2398. /* 1.3 send message */
  2399. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PInvitationReq, MSG_SEND_METHOD_BUF);
  2400. }
  2401. } while (FALSE);
  2402. #endif
  2403. return i4Status;
  2404. }
  2405. /* mtk_p2p_wext_invitation_request */
  2406. /*----------------------------------------------------------------------------*/
  2407. /*!
  2408. * \brief P2P Private I/O Control handler (IOC_P2P_SET_INT)
  2409. *
  2410. * \param[in] prDev Net device requested.
  2411. * \param[inout] wrqu Pointer to iwreq_data
  2412. *
  2413. * \retval 0 Success.
  2414. * \retval -EFAULT Setting parameters to driver fail.
  2415. * \retval -EOPNOTSUPP Setting parameters not support.
  2416. *
  2417. * \note
  2418. */
  2419. /*----------------------------------------------------------------------------*/
  2420. int
  2421. mtk_p2p_wext_invitation_abort(IN struct net_device *prDev,
  2422. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2423. {
  2424. int i4Status = 0;
  2425. #if 0
  2426. P_ADAPTER_T prAdapter = (P_ADAPTER_T) NULL;
  2427. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  2428. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  2429. P_IW_P2P_IOCTL_ABORT_INVITATION prIoctlInvitationAbort = (P_IW_P2P_IOCTL_ABORT_INVITATION) NULL;
  2430. UINT_8 bssid[MAC_ADDR_LEN];
  2431. do {
  2432. if ((prDev == NULL) || (extra == NULL)) {
  2433. ASSERT(FALSE);
  2434. i4Status = -EINVAL;
  2435. break;
  2436. }
  2437. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2438. prIoctlInvitationAbort = (P_IW_P2P_IOCTL_ABORT_INVITATION) extra;
  2439. if (prGlueInfo == NULL) {
  2440. i4Status = -EINVAL;
  2441. break;
  2442. }
  2443. prAdapter = prGlueInfo->prAdapter;
  2444. if (prAdapter == NULL) {
  2445. i4Status = -EINVAL;
  2446. break;
  2447. }
  2448. P_MSG_P2P_INVITATION_REQUEST_T prMsgP2PInvitationAbort = (P_MSG_P2P_INVITATION_REQUEST_T) NULL;
  2449. prMsgP2PInvitationAbort =
  2450. (P_MSG_P2P_INVITATION_REQUEST_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG,
  2451. sizeof(MSG_P2P_INVITATION_REQUEST_T));
  2452. if (!prMsgP2PInvitationAbort) {
  2453. ASSERT(0); /* Can't trigger P2P FSM */
  2454. i4Status = -ENOMEM;
  2455. break;
  2456. }
  2457. /* 1.2 fill message */
  2458. kalMemCopy(prMsgP2PInvitationAbort->aucDeviceID, prIoctlInvitationAbort->dev_addr,
  2459. MAC_ADDR_LEN);
  2460. DBGLOG(P2P, TRACE, "mtk_p2p_wext_invitation_request: P2P Invitation Req\n");
  2461. /* 1.3 send message */
  2462. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PInvitationAbort, MSG_SEND_METHOD_BUF);
  2463. } while (FALSE);
  2464. #endif
  2465. return i4Status;
  2466. }
  2467. /* mtk_p2p_wext_invitation_abort */
  2468. /*----------------------------------------------------------------------------*/
  2469. /*!
  2470. * \brief To set encryption cipher suite
  2471. *
  2472. * \param[in] prDev Net device requested.
  2473. * \param[out]
  2474. *
  2475. * \retval 0 Success.
  2476. * \retval -EINVAL Invalid parameter
  2477. * \retval -EOPNOTSUPP Key size not supported.
  2478. *
  2479. * \note
  2480. */
  2481. /*----------------------------------------------------------------------------*/
  2482. int
  2483. mtk_p2p_wext_set_auth(IN struct net_device *prDev,
  2484. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2485. {
  2486. P_GLUE_INFO_T prGlueInfo = NULL;
  2487. struct iw_param *prAuth = (struct iw_param *)wrqu;
  2488. ASSERT(prDev);
  2489. ASSERT(prAuth);
  2490. if (FALSE == GLUE_CHK_PR2(prDev, prAuth))
  2491. return -EINVAL;
  2492. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2493. /* Save information to glue info and process later when ssid is set. */
  2494. switch (prAuth->flags & IW_AUTH_INDEX) {
  2495. case IW_AUTH_WPA_VERSION:
  2496. break;
  2497. case IW_AUTH_CIPHER_PAIRWISE:
  2498. prGlueInfo->prP2PInfo->u4CipherPairwise = prAuth->value;
  2499. break;
  2500. case IW_AUTH_CIPHER_GROUP:
  2501. case IW_AUTH_KEY_MGMT:
  2502. case IW_AUTH_TKIP_COUNTERMEASURES:
  2503. case IW_AUTH_DROP_UNENCRYPTED:
  2504. case IW_AUTH_80211_AUTH_ALG:
  2505. case IW_AUTH_WPA_ENABLED:
  2506. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  2507. case IW_AUTH_ROAMING_CONTROL:
  2508. case IW_AUTH_PRIVACY_INVOKED:
  2509. default:
  2510. /* @TODO */
  2511. break;
  2512. }
  2513. return 0;
  2514. } /* end of mtk_p2p_wext_set_auth() */
  2515. /*----------------------------------------------------------------------------*/
  2516. /*!
  2517. * \brief To set encryption cipher and key.
  2518. *
  2519. * \param[in] prDev Net device requested.
  2520. * \param[out] prIfReq Pointer to ifreq structure, content is copied back to
  2521. * user space buffer in gl_iwpriv_table.
  2522. *
  2523. * \retval 0 Success.
  2524. * \retval -EFAULT Setting parameters to driver fail.
  2525. * \retval -EOPNOTSUPP Key size not supported.
  2526. *
  2527. * \note Securiry information is stored in pEnc.
  2528. */
  2529. /*----------------------------------------------------------------------------*/
  2530. int
  2531. mtk_p2p_wext_set_key(IN struct net_device *prDev,
  2532. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2533. {
  2534. int ret = 0;
  2535. struct iw_encode_ext *prIWEncExt;
  2536. struct iw_point *prEnc;
  2537. char *prExtraBuf = NULL;
  2538. UINT_32 u4ExtraSize = 0;
  2539. UINT_8 keyStructBuf[100];
  2540. P_PARAM_REMOVE_KEY_T prRemoveKey = (P_PARAM_REMOVE_KEY_T) keyStructBuf;
  2541. P_PARAM_KEY_T prKey = (P_PARAM_KEY_T) keyStructBuf;
  2542. P_GLUE_INFO_T prGlueInfo;
  2543. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2544. UINT_32 u4BufLen = 0;
  2545. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2546. do {
  2547. if (wrqu->encoding.pointer) {
  2548. u4ExtraSize = wrqu->encoding.length;
  2549. if (u4ExtraSize > sizeof(struct iw_encode_ext)) {
  2550. ret = -EINVAL;
  2551. break;
  2552. }
  2553. prExtraBuf = kalMemAlloc(u4ExtraSize, VIR_MEM_TYPE);
  2554. if (!prExtraBuf) {
  2555. ret = -ENOMEM;
  2556. break;
  2557. }
  2558. /* here should set prExtraBuf default value */
  2559. memset(prExtraBuf, 0, u4ExtraSize);
  2560. if (copy_from_user(prExtraBuf, wrqu->encoding.pointer, u4ExtraSize)) {
  2561. ret = -EFAULT;
  2562. break;
  2563. }
  2564. } else if (wrqu->encoding.length != 0) {
  2565. ret = -EINVAL;
  2566. break;
  2567. }
  2568. prEnc = &wrqu->encoding;
  2569. prIWEncExt = (struct iw_encode_ext *)prExtraBuf;
  2570. if (GLUE_CHK_PR3(prDev, prEnc, prExtraBuf) != TRUE) {
  2571. ret = -EINVAL;
  2572. break;
  2573. }
  2574. memset(keyStructBuf, 0, sizeof(keyStructBuf));
  2575. if ((prEnc->flags & IW_ENCODE_MODE) == IW_ENCODE_DISABLED) { /* Key Removal */
  2576. prRemoveKey->u4Length = sizeof(*prRemoveKey);
  2577. memcpy(prRemoveKey->arBSSID, prIWEncExt->addr.sa_data, 6);
  2578. rStatus = kalIoctl(prGlueInfo,
  2579. wlanoidSetRemoveP2PKey,
  2580. prRemoveKey,
  2581. prRemoveKey->u4Length, FALSE, FALSE, TRUE, TRUE, &u4BufLen);
  2582. if (rStatus != WLAN_STATUS_SUCCESS)
  2583. ret = -EFAULT;
  2584. } else {
  2585. if (prIWEncExt->alg == IW_ENCODE_ALG_CCMP) {
  2586. /* KeyID */
  2587. prKey->u4KeyIndex = (prEnc->flags & IW_ENCODE_INDEX) ?
  2588. ((prEnc->flags & IW_ENCODE_INDEX) - 1) : 0;
  2589. if (prKey->u4KeyIndex <= 3) {
  2590. /* bit(31) and bit(30) are shared by pKey and pRemoveKey */
  2591. /* Tx Key Bit(31) */
  2592. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  2593. prKey->u4KeyIndex |= 0x1UL << 31;
  2594. /* Pairwise Key Bit(30) */
  2595. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  2596. /* group key */
  2597. } else {
  2598. /* pairwise key */
  2599. prKey->u4KeyIndex |= 0x1UL << 30;
  2600. }
  2601. /* Rx SC Bit(29) */
  2602. if (prIWEncExt->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
  2603. prKey->u4KeyIndex |= 0x1UL << 29;
  2604. memcpy(&prKey->rKeyRSC, prIWEncExt->rx_seq,
  2605. IW_ENCODE_SEQ_MAX_SIZE);
  2606. }
  2607. /* BSSID */
  2608. memcpy(prKey->arBSSID, prIWEncExt->addr.sa_data, 6);
  2609. if (prIWEncExt->key_len >= 32) {
  2610. ret = -EINVAL;
  2611. break;
  2612. }
  2613. memcpy(prKey->aucKeyMaterial, prIWEncExt->key, prIWEncExt->key_len);
  2614. prKey->u4KeyLength = prIWEncExt->key_len;
  2615. prKey->u4Length =
  2616. ((ULONG)&(((P_PARAM_KEY_T) 0)->aucKeyMaterial)) +
  2617. prKey->u4KeyLength;
  2618. rStatus = kalIoctl(prGlueInfo,
  2619. wlanoidSetAddP2PKey,
  2620. prKey,
  2621. prKey->u4Length,
  2622. FALSE, FALSE, TRUE, TRUE, &u4BufLen);
  2623. if (rStatus != WLAN_STATUS_SUCCESS)
  2624. ret = -EFAULT;
  2625. } else {
  2626. ret = -EINVAL;
  2627. }
  2628. } else {
  2629. ret = -EINVAL;
  2630. }
  2631. }
  2632. } while (FALSE);
  2633. if (prExtraBuf) {
  2634. kalMemFree(prExtraBuf, VIR_MEM_TYPE, u4ExtraSize);
  2635. prExtraBuf = NULL;
  2636. }
  2637. return ret;
  2638. } /* end of mtk_p2p_wext_set_key() */
  2639. /*----------------------------------------------------------------------------*/
  2640. /*!
  2641. * \brief set the p2p gc power mode
  2642. *
  2643. * \param[in] prDev Net device requested.
  2644. * \param[inout] wrqu Pointer to iwreq_data
  2645. *
  2646. * \retval 0 Success.
  2647. * \retval -EFAULT Setting parameters to driver fail.
  2648. * \retval -EOPNOTSUPP Key size not supported.
  2649. *
  2650. * \note
  2651. */
  2652. /*----------------------------------------------------------------------------*/
  2653. int
  2654. mtk_p2p_wext_set_powermode(IN struct net_device *prNetDev,
  2655. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2656. {
  2657. /* printk("set_powermode = %d, value = %d\n", wrqu->power.disabled, wrqu->power.value); */
  2658. struct iw_param *prPower = (struct iw_param *)&wrqu->power;
  2659. #if 1
  2660. PARAM_POWER_MODE ePowerMode;
  2661. INT_32 i4PowerValue;
  2662. P_GLUE_INFO_T prGlueInfo = NULL;
  2663. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2664. UINT_32 u4BufLen = 0;
  2665. ASSERT(prNetDev);
  2666. ASSERT(prPower);
  2667. if (FALSE == GLUE_CHK_PR2(prNetDev, prPower))
  2668. return -EINVAL;
  2669. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2670. /* printk(KERN_INFO "wext_set_power value(%d) disabled(%d) flag(0x%x)\n", */
  2671. /* prPower->value, prPower->disabled, prPower->flags); */
  2672. if (prPower->disabled) {
  2673. ePowerMode = Param_PowerModeCAM;
  2674. } else {
  2675. i4PowerValue = prPower->value;
  2676. #if WIRELESS_EXT < 21
  2677. i4PowerValue /= 1000000;
  2678. #endif
  2679. if (i4PowerValue == 0) {
  2680. ePowerMode = Param_PowerModeCAM;
  2681. } else if (i4PowerValue == 1) {
  2682. ePowerMode = Param_PowerModeMAX_PSP;
  2683. } else if (i4PowerValue == 2) {
  2684. ePowerMode = Param_PowerModeFast_PSP;
  2685. } else {
  2686. DBGLOG(P2P, ERROR, "%s(): unsupported power management mode value = %d.\n",
  2687. __func__, prPower->value);
  2688. return -EINVAL;
  2689. }
  2690. }
  2691. rStatus = kalIoctl(prGlueInfo,
  2692. wlanoidSetP2pPowerSaveProfile,
  2693. &ePowerMode, sizeof(ePowerMode), FALSE, FALSE, TRUE, TRUE, &u4BufLen);
  2694. if (rStatus != WLAN_STATUS_SUCCESS) {
  2695. /* printk(KERN_INFO DRV_NAME"wlanoidSet802dot11PowerSaveProfile fail 0x%lx\n", rStatus); */
  2696. return -EFAULT;
  2697. }
  2698. #endif
  2699. return 0;
  2700. }
  2701. /*----------------------------------------------------------------------------*/
  2702. /*!
  2703. * \brief get the p2p gc power mode
  2704. *
  2705. * \param[in] prDev Net device requested.
  2706. * \param[inout] wrqu Pointer to iwreq_data
  2707. *
  2708. * \retval 0 Success.
  2709. * \retval -EFAULT Setting parameters to driver fail.
  2710. * \retval -EOPNOTSUPP Key size not supported.
  2711. *
  2712. * \note
  2713. */
  2714. /*----------------------------------------------------------------------------*/
  2715. int
  2716. mtk_p2p_wext_get_powermode(IN struct net_device *prNetDev,
  2717. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2718. {
  2719. /* printk("mtk_p2p_wext_get_powermode\n"); */
  2720. /* wrqu->power.disabled = 0; */
  2721. /* wrqu->power.value = 1; */
  2722. struct iw_param *prPower = (struct iw_param *)&wrqu->power;
  2723. PARAM_POWER_MODE ePowerMode = Param_PowerModeMax;
  2724. P_GLUE_INFO_T prGlueInfo = NULL;
  2725. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  2726. UINT_32 u4BufLen = 0;
  2727. ASSERT(prNetDev);
  2728. ASSERT(prPower);
  2729. if (FALSE == GLUE_CHK_PR2(prNetDev, prPower))
  2730. return -EINVAL;
  2731. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prNetDev));
  2732. ASSERT(prGlueInfo);
  2733. #if 1
  2734. rStatus = kalIoctl(prGlueInfo,
  2735. wlanoidQueryP2pPowerSaveProfile,
  2736. &ePowerMode, sizeof(ePowerMode), TRUE, FALSE, FALSE, TRUE, &u4BufLen);
  2737. #else
  2738. rStatus = wlanQueryInformation(prGlueInfo->prAdapter,
  2739. wlanoidQueryP2pPowerSaveProfile, &ePowerMode, sizeof(ePowerMode), &u4BufLen);
  2740. #endif
  2741. prPower->value = 0;
  2742. prPower->disabled = 1;
  2743. if (Param_PowerModeCAM == ePowerMode) {
  2744. prPower->value = 0;
  2745. prPower->disabled = 1;
  2746. } else if (Param_PowerModeMAX_PSP == ePowerMode) {
  2747. prPower->value = 1;
  2748. prPower->disabled = 0;
  2749. } else if (Param_PowerModeFast_PSP == ePowerMode) {
  2750. prPower->value = 2;
  2751. prPower->disabled = 0;
  2752. }
  2753. prPower->flags = IW_POWER_PERIOD | IW_POWER_RELATIVE;
  2754. #if WIRELESS_EXT < 21
  2755. prPower->value *= 1000000;
  2756. #endif
  2757. return 0;
  2758. }
  2759. /*----------------------------------------------------------------------------*/
  2760. /*!
  2761. * \brief P2P Private I/O Control handler (IOC_P2P_CFG_DEVICE)
  2762. *
  2763. * \param[in] prDev Net device requested.
  2764. * \param[inout] wrqu Pointer to iwreq_data
  2765. *
  2766. * \retval 0 Success.
  2767. * \retval -EFAULT Setting parameters to driver fail.
  2768. * \retval -EOPNOTSUPP Key size not supported.
  2769. *
  2770. * \note
  2771. */
  2772. /*----------------------------------------------------------------------------*/
  2773. int
  2774. mtk_p2p_wext_set_local_dev_info(IN struct net_device *prDev,
  2775. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2776. {
  2777. P_ADAPTER_T prAdapter = NULL;
  2778. P_GLUE_INFO_T prGlueInfo = NULL;
  2779. P_IW_P2P_CFG_DEVICE_TYPE prDeviceCfg = (P_IW_P2P_CFG_DEVICE_TYPE) extra;
  2780. P_P2P_CONNECTION_SETTINGS_T prConnSettings;
  2781. P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T) NULL;
  2782. /* P_MSG_P2P_FUNCTION_SWITCH_T prFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T)NULL; */
  2783. ASSERT(prDev);
  2784. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2785. ASSERT(prGlueInfo);
  2786. prAdapter = prGlueInfo->prAdapter;
  2787. ASSERT(prAdapter);
  2788. prConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
  2789. prP2pSpecificBssInfo = prAdapter->rWifiVar.prP2pSpecificBssInfo;
  2790. /* update connection settings for P2P-FSM */
  2791. /* 1. update SSID */
  2792. if (prDeviceCfg->ssid_len > ELEM_MAX_LEN_SSID)
  2793. prConnSettings->ucSSIDLen = ELEM_MAX_LEN_SSID;
  2794. else
  2795. prConnSettings->ucSSIDLen = prDeviceCfg->ssid_len;
  2796. if (copy_from_user(prConnSettings->aucSSID, prDeviceCfg->ssid, prConnSettings->ucSSIDLen))
  2797. return -EFAULT;
  2798. /* 2. update device type (WPS IE) */
  2799. kalMemCopy(&(prConnSettings->rPrimaryDevTypeBE), &(prDeviceCfg->pri_device_type), sizeof(DEVICE_TYPE_T));
  2800. #if P2P_MAX_SUPPORTED_SEC_DEV_TYPE_COUNT
  2801. kalMemCopy(&(prConnSettings->arSecondaryDevTypeBE[0]), &(prDeviceCfg->snd_device_type), sizeof(DEVICE_TYPE_T));
  2802. #endif
  2803. /* 3. update device name */
  2804. if (prDeviceCfg->device_name_len > WPS_ATTRI_MAX_LEN_DEVICE_NAME)
  2805. prConnSettings->ucDevNameLen = WPS_ATTRI_MAX_LEN_DEVICE_NAME;
  2806. else
  2807. prConnSettings->ucDevNameLen = prDeviceCfg->device_name_len;
  2808. if (copy_from_user(prConnSettings->aucDevName, prDeviceCfg->device_name, prConnSettings->ucDevNameLen))
  2809. return -EFAULT;
  2810. /* 4. update GO intent */
  2811. prConnSettings->ucGoIntent = prDeviceCfg->intend;
  2812. /* Preferred channel bandwidth */
  2813. prAdapter->rWifiVar.rConnSettings.uc2G4BandwidthMode = prDeviceCfg->ch_width ? CONFIG_BW_20_40M : CONFIG_BW_20M;
  2814. prAdapter->rWifiVar.rConnSettings.uc5GBandwidthMode = prDeviceCfg->ch_width ? CONFIG_BW_20_40M : CONFIG_BW_20M;
  2815. #if 0
  2816. /* 1. switch P2P-FSM on */
  2817. /* 1.1 allocate for message */
  2818. prFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter,
  2819. RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  2820. if (!prFuncSwitch) {
  2821. ASSERT(0); /* Can't trigger P2P FSM */
  2822. return -ENOMEM;
  2823. }
  2824. /* 1.2 fill message */
  2825. prFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  2826. prFuncSwitch->fgIsFuncOn = TRUE;
  2827. /* 1.3 send message */
  2828. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prFuncSwitch, MSG_SEND_METHOD_BUF);
  2829. #endif
  2830. return 0;
  2831. } /* end of mtk_p2p_wext_set_local_dev_info() */
  2832. /*----------------------------------------------------------------------------*/
  2833. /*!
  2834. * \brief I/O Control handler for both
  2835. * IOC_P2P_START_STOP_DISCOVERY & SIOCGIWSCAN
  2836. *
  2837. * \param[in] prDev Net device requested.
  2838. * \param[inout] wrqu Pointer to iwreq_data
  2839. *
  2840. * \retval 0 Success.
  2841. * \retval -EFAULT Setting parameters to driver fail.
  2842. * \retval -EOPNOTSUPP Key size not supported.
  2843. *
  2844. * \note
  2845. */
  2846. /*----------------------------------------------------------------------------*/
  2847. int
  2848. mtk_p2p_wext_discovery_results(IN struct net_device *prDev,
  2849. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2850. {
  2851. struct iw_event iwe;
  2852. char *current_ev = extra;
  2853. UINT_32 i;
  2854. P_GLUE_INFO_T prGlueInfo = NULL;
  2855. P_ADAPTER_T prAdapter = NULL;
  2856. P_P2P_INFO_T prP2PInfo = (P_P2P_INFO_T) NULL;
  2857. P_EVENT_P2P_DEV_DISCOVER_RESULT_T prTargetResult = (P_EVENT_P2P_DEV_DISCOVER_RESULT_T) NULL;
  2858. P_PARAM_VARIABLE_IE_T prDesiredIE = NULL;
  2859. ASSERT(prDev);
  2860. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2861. ASSERT(prGlueInfo);
  2862. prAdapter = prGlueInfo->prAdapter;
  2863. ASSERT(prAdapter);
  2864. prP2PInfo = prAdapter->prP2pInfo;
  2865. for (i = 0; i < prP2PInfo->u4DeviceNum; i++) {
  2866. prTargetResult = &prP2PInfo->arP2pDiscoverResult[i];
  2867. /* SIOCGIWAP */
  2868. iwe.cmd = SIOCGIWAP;
  2869. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  2870. memcpy(iwe.u.ap_addr.sa_data, prTargetResult->aucInterfaceAddr, 6);
  2871. current_ev = iwe_stream_add_event(info, current_ev, extra + IW_SCAN_MAX_DATA, &iwe, IW_EV_ADDR_LEN);
  2872. /* SIOCGIWESSID */
  2873. iwe.cmd = SIOCGIWESSID;
  2874. iwe.u.data.flags = 1;
  2875. iwe.u.data.length = prTargetResult->u2NameLength;
  2876. current_ev = iwe_stream_add_point(info, current_ev,
  2877. extra + IW_SCAN_MAX_DATA, &iwe, prTargetResult->aucName);
  2878. /* IWEVGENIE for WPA IE */
  2879. if (prTargetResult->u2IELength <= 600 && wextSrchDesiredWPAIE(prTargetResult->pucIeBuf,
  2880. prTargetResult->u2IELength,
  2881. 0xDD, (PUINT_8 *) &prDesiredIE)) {
  2882. iwe.cmd = IWEVGENIE;
  2883. iwe.u.data.flags = 1;
  2884. iwe.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  2885. current_ev = iwe_stream_add_point(info, current_ev,
  2886. extra + IW_SCAN_MAX_DATA, &iwe, (char *)prDesiredIE);
  2887. }
  2888. #if CFG_SUPPORT_WPS
  2889. /* IWEVGENIE for WPS IE */
  2890. if ((prTargetResult->u2IELength <= 600) && wextSrchDesiredWPSIE(prTargetResult->pucIeBuf,
  2891. prTargetResult->u2IELength,
  2892. 0xDD, (PUINT_8 *) &prDesiredIE)) {
  2893. iwe.cmd = IWEVGENIE;
  2894. iwe.u.data.flags = 1;
  2895. iwe.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  2896. current_ev = iwe_stream_add_point(info, current_ev,
  2897. extra + IW_SCAN_MAX_DATA, &iwe, (char *)prDesiredIE);
  2898. }
  2899. #endif
  2900. /* IWEVGENIE for RSN IE */
  2901. if ((prTargetResult->u2IELength <= 600) && wextSrchDesiredWPAIE(prTargetResult->pucIeBuf,
  2902. prTargetResult->u2IELength,
  2903. 0x30, (PUINT_8 *) &prDesiredIE)) {
  2904. iwe.cmd = IWEVGENIE;
  2905. iwe.u.data.flags = 1;
  2906. iwe.u.data.length = 2 + (__u16) prDesiredIE->ucLength;
  2907. current_ev = iwe_stream_add_point(info, current_ev,
  2908. extra + IW_SCAN_MAX_DATA, &iwe, (char *)prDesiredIE);
  2909. }
  2910. /* IOC_P2P_GO_WSC_IE */
  2911. #if 1
  2912. /* device capability */
  2913. if (1) {
  2914. UINT_8 data[40];
  2915. iwe.cmd = IWEVCUSTOM;
  2916. iwe.u.data.flags = 0;
  2917. iwe.u.data.length = 8 + sizeof("p2p_cap=");
  2918. if (iwe.u.data.length > 40)
  2919. iwe.u.data.length = 40;
  2920. snprintf(data, iwe.u.data.length, "p2p_cap=%02x%02x%02x%02x%c",
  2921. prTargetResult->ucDeviceCapabilityBitmap, prTargetResult->ucGroupCapabilityBitmap,
  2922. (UINT_8) prTargetResult->u2ConfigMethod,
  2923. (UINT_8) (prTargetResult->u2ConfigMethod >> 8), '\0');
  2924. current_ev =
  2925. iwe_stream_add_point(info, current_ev, extra + IW_SCAN_MAX_DATA, &iwe, (char *)data);
  2926. /* printk("%s\n", data); */
  2927. kalMemZero(data, 40);
  2928. iwe.cmd = IWEVCUSTOM;
  2929. iwe.u.data.flags = 0;
  2930. iwe.u.data.length = 12 + sizeof("p2p_dev_type=");
  2931. if (iwe.u.data.length > 40)
  2932. iwe.u.data.length = 40;
  2933. snprintf(data, iwe.u.data.length, "p2p_dev_type=%02x%02x%02x%02x%02x%02x%c",
  2934. (UINT_8) prTargetResult->rPriDevType.u2CategoryID,
  2935. (UINT_8) prTargetResult->rPriDevType.u2SubCategoryID,
  2936. (UINT_8) prTargetResult->arSecDevType[0].u2CategoryID,
  2937. (UINT_8) prTargetResult->arSecDevType[0].u2SubCategoryID,
  2938. (UINT_8) prTargetResult->arSecDevType[1].u2CategoryID,
  2939. (UINT_8) prTargetResult->arSecDevType[1].u2SubCategoryID, '\0');
  2940. current_ev =
  2941. iwe_stream_add_point(info, current_ev, extra + IW_SCAN_MAX_DATA, &iwe, (char *)data);
  2942. /* printk("%s\n", data); */
  2943. kalMemZero(data, 40);
  2944. iwe.cmd = IWEVCUSTOM;
  2945. iwe.u.data.flags = 0;
  2946. iwe.u.data.length = 17 + sizeof("p2p_grp_bssid=");
  2947. if (iwe.u.data.length > 40)
  2948. iwe.u.data.length = 40;
  2949. snprintf(data, iwe.u.data.length, "p2p_grp_bssid= %pM %c",
  2950. prTargetResult->aucBSSID, '\0');
  2951. current_ev = iwe_stream_add_point(info, current_ev,
  2952. extra + IW_SCAN_MAX_DATA, &iwe, (char *)data);
  2953. /* printk("%s\n", data); */
  2954. }
  2955. #endif
  2956. }
  2957. /* Length of data */
  2958. wrqu->data.length = (current_ev - extra);
  2959. wrqu->data.flags = 0;
  2960. return 0;
  2961. } /* end of mtk_p2p_wext_discovery_results() */
  2962. /*----------------------------------------------------------------------------*/
  2963. /*!
  2964. * \brief P2P Private I/O Control handler (IOC_P2P_WSC_BEACON_PROBE_RSP_IE)
  2965. *
  2966. * \param[in] prDev Net device requested.
  2967. * \param[inout] wrqu Pointer to iwreq_data
  2968. *
  2969. * \retval 0 Success.
  2970. * \retval -EFAULT Setting parameters to driver fail.
  2971. * \retval -EOPNOTSUPP Key size not supported.
  2972. *
  2973. * \note
  2974. */
  2975. /*----------------------------------------------------------------------------*/
  2976. int
  2977. mtk_p2p_wext_wsc_ie(IN struct net_device *prDev,
  2978. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  2979. {
  2980. P_ADAPTER_T prAdapter = NULL;
  2981. P_GLUE_INFO_T prGlueInfo = NULL;
  2982. P_IW_P2P_HOSTAPD_PARAM prHostapdParam = (P_IW_P2P_HOSTAPD_PARAM) extra;
  2983. ASSERT(prDev);
  2984. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2985. ASSERT(prGlueInfo);
  2986. if (prHostapdParam->len > 0) {
  2987. if (prHostapdParam->len <= MAX_WSC_IE_LENGTH) {
  2988. if (copy_from_user
  2989. (prGlueInfo->prP2PInfo->aucWSCIE[0], prHostapdParam->data, prHostapdParam->len)) {
  2990. return -EFAULT;
  2991. }
  2992. if (copy_from_user
  2993. (prGlueInfo->prP2PInfo->aucWSCIE[2], prHostapdParam->data, prHostapdParam->len)) {
  2994. return -EFAULT;
  2995. }
  2996. } else {
  2997. return -E2BIG;
  2998. }
  2999. }
  3000. prGlueInfo->prP2PInfo->u2WSCIELen[0] = prHostapdParam->len;
  3001. prGlueInfo->prP2PInfo->u2WSCIELen[2] = prHostapdParam->len;
  3002. prAdapter = prGlueInfo->prAdapter;
  3003. ASSERT(prAdapter);
  3004. bssUpdateBeaconContent(prAdapter, NETWORK_TYPE_P2P_INDEX);
  3005. /* @TODO: send message to P2P-FSM */
  3006. return 0;
  3007. } /* end of mtk_p2p_wext_wsc_ie() */
  3008. /*----------------------------------------------------------------------------*/
  3009. /*!
  3010. * \brief P2P Private I/O Control handler (IOC_P2P_CONNECT_DISCONNECT)
  3011. *
  3012. * \param[in] prDev Net device requested.
  3013. * \param[inout] wrqu Pointer to iwreq_data
  3014. *
  3015. * \retval 0 Success.
  3016. * \retval -EFAULT Setting parameters to driver fail.
  3017. * \retval -EOPNOTSUPP Key size not supported.
  3018. *
  3019. * \note
  3020. */
  3021. /*----------------------------------------------------------------------------*/
  3022. int
  3023. mtk_p2p_wext_connect_disconnect(IN struct net_device *prDev,
  3024. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3025. {
  3026. P_ADAPTER_T prAdapter = NULL;
  3027. P_GLUE_INFO_T prGlueInfo = NULL;
  3028. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  3029. /* P_IW_P2P_CONNECT_DEVICE prConnectDevice = (P_IW_P2P_CONNECT_DEVICE)extra; */
  3030. /* P_MSG_HDR_T prMsgHdr; */
  3031. /* P_MSG_P2P_CONNECTION_REQUEST_T prMsgP2PConnReq; */
  3032. /* P_MSG_P2P_CONNECTION_ABORT_T prMsgP2PConnAbt; */
  3033. /* UINT_8 aucBCAddr[] = BC_MAC_ADDR; */
  3034. ASSERT(prDev);
  3035. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3036. ASSERT(prGlueInfo);
  3037. prAdapter = prGlueInfo->prAdapter;
  3038. ASSERT(prAdapter);
  3039. if (prData->flags == P2P_CONNECT) {
  3040. #if 0
  3041. /* indicate P2P-FSM with MID_MNY_P2P_CONNECTION_REQ */
  3042. prMsgP2PConnReq = (P_MSG_P2P_CONNECTION_REQUEST_T) cnmMemAlloc(prAdapter,
  3043. RAM_TYPE_MSG,
  3044. sizeof(MSG_P2P_CONNECTION_REQUEST_T));
  3045. if (!prMsgP2PConnReq) {
  3046. ASSERT(0); /* Can't trigger P2P FSM */
  3047. return -ENOMEM;
  3048. }
  3049. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PConnReq, MSG_SEND_METHOD_BUF);
  3050. #endif
  3051. } else if (prData->flags == P2P_DISCONNECT) {
  3052. #if 0
  3053. /* indicate P2P-FSM with MID_MNY_P2P_CONNECTION_ABORT */
  3054. prMsgP2PConnAbt = (P_MSG_HDR_T) cnmMemAlloc(prAdapter,
  3055. RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_ABORT_T));
  3056. if (!prMsgP2PConnAbt) {
  3057. ASSERT(0); /* Can't trigger P2P FSM */
  3058. return -ENOMEM;
  3059. }
  3060. COPY_MAC_ADDR(prMsgP2PConnAbt->aucTargetID, prConnectDevice->sta_addr);
  3061. prMsgP2PConnAbt->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_ABORT;
  3062. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgP2PConnAbt, MSG_SEND_METHOD_BUF);
  3063. #endif
  3064. } else {
  3065. return -EINVAL;
  3066. }
  3067. return 0;
  3068. } /* end of mtk_p2p_wext_connect_disconnect() */
  3069. /*----------------------------------------------------------------------------*/
  3070. /*!
  3071. * \brief P2P Private I/O Control handler (IOC_P2P_PASSWORD_READY)
  3072. *
  3073. * \param[in] prDev Net device requested.
  3074. * \param[inout] wrqu Pointer to iwreq_data
  3075. *
  3076. * \retval 0 Success.
  3077. * \retval -EFAULT Setting parameters to driver fail.
  3078. * \retval -EOPNOTSUPP Key size not supported.
  3079. *
  3080. * \note
  3081. */
  3082. /*----------------------------------------------------------------------------*/
  3083. int
  3084. mtk_p2p_wext_password_ready(IN struct net_device *prDev,
  3085. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3086. {
  3087. P_ADAPTER_T prAdapter = NULL;
  3088. P_GLUE_INFO_T prGlueInfo = NULL;
  3089. P_IW_P2P_PASSWORD_READY prPasswordReady = (P_IW_P2P_PASSWORD_READY) extra;
  3090. P_P2P_CONNECTION_SETTINGS_T prConnSettings;
  3091. UINT_16 u2CmdLen = 0;
  3092. ASSERT(prDev);
  3093. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3094. ASSERT(prGlueInfo);
  3095. prAdapter = prGlueInfo->prAdapter;
  3096. ASSERT(prAdapter);
  3097. prConnSettings = prAdapter->rWifiVar.prP2PConnSettings;
  3098. u2CmdLen = prPasswordReady->probe_req_len;
  3099. /* retrieve IE for Probe Request */
  3100. if (u2CmdLen > 0) {
  3101. if (u2CmdLen <= MAX_WSC_IE_LENGTH) {
  3102. if (copy_from_user
  3103. (prGlueInfo->prP2PInfo->aucWSCIE[1], prPasswordReady->probe_req_ie,
  3104. u2CmdLen)) {
  3105. return -EFAULT;
  3106. }
  3107. } else {
  3108. return -E2BIG;
  3109. }
  3110. }
  3111. prGlueInfo->prP2PInfo->u2WSCIELen[1] = u2CmdLen;
  3112. /* retrieve IE for Probe Response */
  3113. u2CmdLen = prPasswordReady->probe_rsp_len;
  3114. if (u2CmdLen > 0) {
  3115. if (u2CmdLen <= MAX_WSC_IE_LENGTH) {
  3116. if (copy_from_user
  3117. (prGlueInfo->prP2PInfo->aucWSCIE[2], prPasswordReady->probe_rsp_ie, u2CmdLen)) {
  3118. return -EFAULT;
  3119. }
  3120. } else {
  3121. return -E2BIG;
  3122. }
  3123. }
  3124. prGlueInfo->prP2PInfo->u2WSCIELen[2] = u2CmdLen;
  3125. switch (prPasswordReady->active_config_method) {
  3126. case 1:
  3127. prConnSettings->u2LocalConfigMethod = WPS_ATTRI_CFG_METHOD_PUSH_BUTTON;
  3128. break;
  3129. case 2:
  3130. prConnSettings->u2LocalConfigMethod = WPS_ATTRI_CFG_METHOD_KEYPAD;
  3131. break;
  3132. case 3:
  3133. prConnSettings->u2LocalConfigMethod = WPS_ATTRI_CFG_METHOD_DISPLAY;
  3134. break;
  3135. default:
  3136. break;
  3137. }
  3138. prConnSettings->fgIsPasswordIDRdy = TRUE;
  3139. return 0;
  3140. } /* end of mtk_p2p_wext_password_ready() */
  3141. /*----------------------------------------------------------------------------*/
  3142. /*!
  3143. * \brief P2P Private I/O Control handler (IOC_P2P_GET_REQ_DEVICE_INFO)
  3144. *
  3145. * \param[in] prDev Net device requested.
  3146. * \param[inout] wrqu Pointer to iwreq_data
  3147. *
  3148. * \retval 0 Success.
  3149. * \retval -EFAULT Setting parameters to driver fail.
  3150. * \retval -EOPNOTSUPP Key size not supported.
  3151. *
  3152. * \note
  3153. */
  3154. /*----------------------------------------------------------------------------*/
  3155. int
  3156. mtk_p2p_wext_request_dev_info(IN struct net_device *prDev,
  3157. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3158. {
  3159. P_ADAPTER_T prAdapter = NULL;
  3160. P_GLUE_INFO_T prGlueInfo = NULL;
  3161. P_IW_P2P_DEVICE_REQ prDeviceReq = (P_IW_P2P_DEVICE_REQ) extra;
  3162. ASSERT(prDev);
  3163. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3164. ASSERT(prGlueInfo);
  3165. prAdapter = prGlueInfo->prAdapter;
  3166. ASSERT(prAdapter);
  3167. /* specify data length */
  3168. wrqu->data.length = sizeof(IW_P2P_DEVICE_REQ);
  3169. /* copy to upper-layer supplied buffer */
  3170. kalMemCopy(prDeviceReq->name, prGlueInfo->prP2PInfo->aucConnReqDevName,
  3171. prGlueInfo->prP2PInfo->u4ConnReqNameLength);
  3172. prDeviceReq->name_len = prGlueInfo->prP2PInfo->u4ConnReqNameLength;
  3173. prDeviceReq->name[prDeviceReq->name_len] = '\0';
  3174. COPY_MAC_ADDR(prDeviceReq->device_addr, prGlueInfo->prP2PInfo->rConnReqPeerAddr);
  3175. prDeviceReq->device_type = prGlueInfo->prP2PInfo->ucConnReqDevType;
  3176. prDeviceReq->config_method = prGlueInfo->prP2PInfo->i4ConnReqConfigMethod;
  3177. prDeviceReq->active_config_method = prGlueInfo->prP2PInfo->i4ConnReqActiveConfigMethod;
  3178. return 0;
  3179. } /* end of mtk_p2p_wext_request_dev_info() */
  3180. /*----------------------------------------------------------------------------*/
  3181. /*!
  3182. * \brief P2P Private I/O Control handler (IOC_P2P_GET_STRUCT)
  3183. *
  3184. * \param[in] prDev Net device requested.
  3185. * \param[inout] wrqu Pointer to iwreq_data
  3186. *
  3187. * \retval 0 Success.
  3188. * \retval -EFAULT Setting parameters to driver fail.
  3189. * \retval -EOPNOTSUPP Key size not supported.
  3190. *
  3191. * \note
  3192. */
  3193. /*----------------------------------------------------------------------------*/
  3194. int
  3195. mtk_p2p_wext_invitation_indicate(IN struct net_device *prDev,
  3196. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3197. {
  3198. P_ADAPTER_T prAdapter = NULL;
  3199. P_GLUE_INFO_T prGlueInfo = NULL;
  3200. P_IW_P2P_IOCTL_INVITATION_INDICATE prInvIndicate = (P_IW_P2P_IOCTL_INVITATION_INDICATE) extra;
  3201. ASSERT(prDev);
  3202. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3203. ASSERT(prGlueInfo);
  3204. prAdapter = prGlueInfo->prAdapter;
  3205. ASSERT(prAdapter);
  3206. /* specify data length */
  3207. wrqu->data.length = sizeof(IW_P2P_IOCTL_INVITATION_INDICATE);
  3208. /* copy to upper-layer supplied buffer */
  3209. kalMemCopy(prInvIndicate->dev_name, prGlueInfo->prP2PInfo->aucConnReqDevName,
  3210. prGlueInfo->prP2PInfo->u4ConnReqNameLength);
  3211. kalMemCopy(prInvIndicate->group_bssid, prGlueInfo->prP2PInfo->rConnReqGroupAddr, MAC_ADDR_LEN);
  3212. prInvIndicate->name_len = prGlueInfo->prP2PInfo->u4ConnReqNameLength;
  3213. prInvIndicate->dev_name[prInvIndicate->name_len] = '\0';
  3214. COPY_MAC_ADDR(prInvIndicate->dev_addr, prGlueInfo->prP2PInfo->rConnReqPeerAddr);
  3215. prInvIndicate->config_method = prGlueInfo->prP2PInfo->i4ConnReqConfigMethod;
  3216. prInvIndicate->operating_channel = prGlueInfo->prP2PInfo->ucOperatingChnl;
  3217. prInvIndicate->invitation_type = prGlueInfo->prP2PInfo->ucInvitationType;
  3218. return 0;
  3219. } /* end of mtk_p2p_wext_invitation_indicate() */
  3220. /*----------------------------------------------------------------------------*/
  3221. /*!
  3222. * \brief P2P Private I/O Control handler (IOC_P2P_GET_STRUCT)
  3223. *
  3224. * \param[in] prDev Net device requested.
  3225. * \param[inout] wrqu Pointer to iwreq_data
  3226. *
  3227. * \retval 0 Success.
  3228. * \retval -EFAULT Setting parameters to driver fail.
  3229. * \retval -EOPNOTSUPP Key size not supported.
  3230. *
  3231. * \note
  3232. */
  3233. /*----------------------------------------------------------------------------*/
  3234. int
  3235. mtk_p2p_wext_invitation_status(IN struct net_device *prDev,
  3236. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3237. {
  3238. P_ADAPTER_T prAdapter = NULL;
  3239. P_GLUE_INFO_T prGlueInfo = NULL;
  3240. P_IW_P2P_IOCTL_INVITATION_STATUS prInvStatus = (P_IW_P2P_IOCTL_INVITATION_STATUS) extra;
  3241. ASSERT(prDev);
  3242. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3243. ASSERT(prGlueInfo);
  3244. prAdapter = prGlueInfo->prAdapter;
  3245. ASSERT(prAdapter);
  3246. /* specify data length */
  3247. wrqu->data.length = sizeof(IW_P2P_IOCTL_INVITATION_STATUS);
  3248. /* copy to upper-layer supplied buffer */
  3249. prInvStatus->status_code = prGlueInfo->prP2PInfo->u4InvStatus;
  3250. return 0;
  3251. } /* end of mtk_p2p_wext_invitation_status() */
  3252. int
  3253. mtk_p2p_wext_set_network_address(IN struct net_device *prDev,
  3254. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3255. {
  3256. P_ADAPTER_T prAdapter = NULL;
  3257. P_GLUE_INFO_T prGlueInfo = NULL;
  3258. ASSERT(prDev);
  3259. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3260. ASSERT(prGlueInfo);
  3261. prAdapter = prGlueInfo->prAdapter;
  3262. ASSERT(prAdapter);
  3263. /* @TODO: invoke wlan_p2p functions */
  3264. #if 0
  3265. rStatus = kalIoctl(prGlueInfo,
  3266. (PFN_OID_HANDLER_FUNC_REQ) wlanoidSetP2pNetworkAddress,
  3267. prKey, prKey->u4Length, FALSE, FALSE, TRUE, &u4BufLen);
  3268. #endif
  3269. return 0;
  3270. }
  3271. int
  3272. mtk_p2p_wext_set_ps_profile(IN struct net_device *prDev,
  3273. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3274. {
  3275. P_ADAPTER_T prAdapter = NULL;
  3276. P_GLUE_INFO_T prGlueInfo = NULL;
  3277. ASSERT(prDev);
  3278. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3279. ASSERT(prGlueInfo);
  3280. prAdapter = prGlueInfo->prAdapter;
  3281. ASSERT(prAdapter);
  3282. /* @TODO: invoke wlan_p2p functions */
  3283. #if 0
  3284. rStatus = kalIoctl(prGlueInfo,
  3285. (PFN_OID_HANDLER_FUNC_REQ) wlanoidSetP2pPowerSaveProfile,
  3286. prKey, prKey->u4Length, FALSE, FALSE, TRUE, &u4BufLen);
  3287. #endif
  3288. return 0;
  3289. }
  3290. int
  3291. mtk_p2p_wext_set_pm_param(IN struct net_device *prDev,
  3292. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3293. {
  3294. P_ADAPTER_T prAdapter = NULL;
  3295. P_GLUE_INFO_T prGlueInfo = NULL;
  3296. ASSERT(prDev);
  3297. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3298. ASSERT(prGlueInfo);
  3299. prAdapter = prGlueInfo->prAdapter;
  3300. ASSERT(prAdapter);
  3301. /* @TODO: invoke wlan_p2p functions */
  3302. #if 0
  3303. rStatus = kalIoctl(prGlueInfo,
  3304. (PFN_OID_HANDLER_FUNC_REQ) wlanoidSetP2pPowerSaveProfile,
  3305. prKey, prKey->u4Length, FALSE, FALSE, TRUE, &u4BufLen);
  3306. #endif
  3307. return 0;
  3308. }
  3309. /*----------------------------------------------------------------------------*/
  3310. /*!
  3311. * \brief P2P Private I/O Control handler (IOC_P2P_SET_INT)
  3312. *
  3313. * \param[in] prDev Net device requested.
  3314. * \param[inout] wrqu Pointer to iwreq_data
  3315. *
  3316. * \retval 0 Success.
  3317. * \retval -EFAULT Setting parameters to driver fail.
  3318. * \retval -EOPNOTSUPP Setting parameters not support.
  3319. *
  3320. * \note
  3321. */
  3322. /*----------------------------------------------------------------------------*/
  3323. int
  3324. mtk_p2p_wext_start_formation(IN struct net_device *prDev,
  3325. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3326. {
  3327. int i4Status = 0;
  3328. P_ADAPTER_T prAdapter = (P_ADAPTER_T) NULL;
  3329. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  3330. /* struct iw_point *prData = (struct iw_point*)&wrqu->data; */
  3331. P_IW_P2P_IOCTL_START_FORMATION prIoctlStartFormation = (P_IW_P2P_IOCTL_START_FORMATION) NULL;
  3332. do {
  3333. if ((prDev == NULL) || (extra == NULL)) {
  3334. ASSERT(FALSE);
  3335. i4Status = -EINVAL;
  3336. break;
  3337. }
  3338. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3339. prIoctlStartFormation = (P_IW_P2P_IOCTL_START_FORMATION) extra;
  3340. if (prGlueInfo == NULL) {
  3341. i4Status = -EINVAL;
  3342. break;
  3343. }
  3344. prAdapter = prGlueInfo->prAdapter;
  3345. if (prAdapter == NULL) {
  3346. i4Status = -EINVAL;
  3347. break;
  3348. }
  3349. } while (FALSE);
  3350. return i4Status;
  3351. }
  3352. /* mtk_p2p_wext_start_formation */
  3353. /*----------------------------------------------------------------------------*/
  3354. /*!
  3355. * \brief P2P Private I/O Control handler (IOC_P2P_SET_INT)
  3356. *
  3357. * \param[in] prDev Net device requested.
  3358. * \param[inout] wrqu Pointer to iwreq_data
  3359. *
  3360. * \retval 0 Success.
  3361. * \retval -EFAULT Setting parameters to driver fail.
  3362. * \retval -EOPNOTSUPP Setting parameters not support.
  3363. *
  3364. * \note
  3365. */
  3366. /*----------------------------------------------------------------------------*/
  3367. int
  3368. mtk_p2p_wext_set_int(IN struct net_device *prDev,
  3369. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3370. {
  3371. int status = 0;
  3372. UINT_32 u4SubCmd = 0;
  3373. P_GLUE_INFO_T prGlueInfo = NULL;
  3374. UINT_32 index;
  3375. INT_32 value;
  3376. PUINT_32 pu4IntBuf;
  3377. P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo = (P_P2P_SPECIFIC_BSS_INFO_T) NULL;
  3378. P_P2P_CONNECTION_SETTINGS_T prP2pConnSettings = (P_P2P_CONNECTION_SETTINGS_T) NULL;
  3379. P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T) NULL;
  3380. UINT_32 u4Leng;
  3381. ASSERT(prDev);
  3382. ASSERT(wrqu);
  3383. /* printk("mtk_p2p_wext_set_int\n"); */
  3384. pu4IntBuf = (PUINT_32) extra;
  3385. if (FALSE == GLUE_CHK_PR2(prDev, wrqu))
  3386. return -EINVAL;
  3387. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3388. ASSERT(prGlueInfo);
  3389. prP2pSpecificBssInfo = prGlueInfo->prAdapter->rWifiVar.prP2pSpecificBssInfo;
  3390. prP2pConnSettings = prGlueInfo->prAdapter->rWifiVar.prP2PConnSettings;
  3391. prP2pFsmInfo = prGlueInfo->prAdapter->rWifiVar.prP2pFsmInfo;
  3392. u4SubCmd = (UINT_32) wrqu->mode;
  3393. index = pu4IntBuf[1];
  3394. value = pu4IntBuf[2];
  3395. DBGLOG(P2P, INFO, "set parameter, u4SubCmd=%d idx=%d value=%d\n", (INT_16) u4SubCmd, (INT_16) index, value);
  3396. switch (u4SubCmd) {
  3397. case PRIV_CMD_INT_P2P_SET:
  3398. switch (index) {
  3399. case 0: /* Listen CH */
  3400. {
  3401. UINT_8 ucSuggestChnl = 0;
  3402. prP2pConnSettings->ucListenChnl = value;
  3403. /* 20110920 - frog: User configurations are placed in ConnSettings. */
  3404. if (rlmFuncFindAvailableChannel
  3405. (prGlueInfo->prAdapter, value, &ucSuggestChnl, TRUE, TRUE)) {
  3406. prP2pSpecificBssInfo->ucListenChannel = value;
  3407. } else {
  3408. prP2pSpecificBssInfo->ucListenChannel = ucSuggestChnl;
  3409. }
  3410. break;
  3411. }
  3412. case 1: /* P2p mode */
  3413. break;
  3414. case 4: /* Noa duration */
  3415. prP2pSpecificBssInfo->rNoaParam.u4NoaDurationMs = value;
  3416. /* only to apply setting when setting NOA count */
  3417. /* status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu,
  3418. (char *)&prP2pSpecificBssInfo->rNoaParam); */
  3419. break;
  3420. case 5: /* Noa interval */
  3421. prP2pSpecificBssInfo->rNoaParam.u4NoaIntervalMs = value;
  3422. /* only to apply setting when setting NOA count */
  3423. /* status = mtk_p2p_wext_set_noa_param(prDev, info, wrqu,
  3424. (char *)&prP2pSpecificBssInfo->rNoaParam); */
  3425. break;
  3426. case 6: /* Noa count */
  3427. prP2pSpecificBssInfo->rNoaParam.u4NoaCount = value;
  3428. status =
  3429. mtk_p2p_wext_set_noa_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rNoaParam);
  3430. break;
  3431. case 100: /* Oper CH */
  3432. /* 20110920 - frog: User configurations are placed in ConnSettings. */
  3433. prP2pConnSettings->ucOperatingChnl = value;
  3434. break;
  3435. case 101: /* Local config Method, for P2P SDK */
  3436. /* prP2pConnSettings->u2LocalConfigMethod; */
  3437. break;
  3438. case 102: /* Sigma P2p reset */
  3439. kalMemZero(prP2pConnSettings->aucTargetDevAddr, MAC_ADDR_LEN);
  3440. /* prP2pConnSettings->eConnectionPolicy = ENUM_P2P_CONNECTION_POLICY_AUTO; */
  3441. break;
  3442. case 103: /* WPS MODE */
  3443. kalP2PSetWscMode(prGlueInfo, value);
  3444. break;
  3445. case 104: /* P2p send persence, duration */
  3446. break;
  3447. case 105: /* P2p send persence, interval */
  3448. break;
  3449. case 106: /* P2P set sleep */
  3450. value = 1;
  3451. kalIoctl(prGlueInfo,
  3452. wlanoidSetP2pPowerSaveProfile,
  3453. &value, sizeof(value), FALSE, FALSE, TRUE, TRUE, &u4Leng);
  3454. break;
  3455. case 107: /* P2P set opps, CTWindowl */
  3456. prP2pSpecificBssInfo->rOppPsParam.u4CTwindowMs = value;
  3457. status =
  3458. mtk_p2p_wext_set_oppps_param(prDev, info, wrqu, (char *)&prP2pSpecificBssInfo->rOppPsParam);
  3459. break;
  3460. case 108: /* p2p_set_power_save */
  3461. kalIoctl(prGlueInfo,
  3462. wlanoidSetP2pPowerSaveProfile,
  3463. &value, sizeof(value), FALSE, FALSE, TRUE, TRUE, &u4Leng);
  3464. break;
  3465. default:
  3466. break;
  3467. }
  3468. break;
  3469. default:
  3470. break;
  3471. }
  3472. return status;
  3473. }
  3474. /*----------------------------------------------------------------------------*/
  3475. /*!
  3476. * \brief P2P Private I/O Control handler (IOC_P2P_SET_STRUCT)
  3477. *
  3478. * \param[in] prDev Net device requested.
  3479. * \param[inout] wrqu Pointer to iwreq_data
  3480. *
  3481. * \retval 0 Success.
  3482. * \retval -EFAULT Setting parameters to driver fail.
  3483. * \retval -EOPNOTSUPP Key size not supported.
  3484. *
  3485. * \note
  3486. */
  3487. /*----------------------------------------------------------------------------*/
  3488. int
  3489. mtk_p2p_wext_set_struct(IN struct net_device *prDev,
  3490. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3491. {
  3492. int status = 0;
  3493. UINT_32 u4SubCmd = 0;
  3494. UINT_32 u4CmdLen = 0;
  3495. P_GLUE_INFO_T prGlueInfo = NULL;
  3496. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = NULL;
  3497. ASSERT(prDev);
  3498. ASSERT(wrqu);
  3499. if (FALSE == GLUE_CHK_PR2(prDev, wrqu))
  3500. return -EINVAL;
  3501. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3502. ASSERT(prGlueInfo);
  3503. u4SubCmd = (UINT_32) wrqu->data.flags;
  3504. u4CmdLen = (UINT_32) wrqu->data.length;
  3505. kalMemZero(&prGlueInfo->prP2PInfo->aucOidBuf[0], sizeof(prGlueInfo->prP2PInfo->aucOidBuf));
  3506. switch (u4SubCmd) {
  3507. case PRIV_CMD_OID:
  3508. if (u4CmdLen > OID_SET_GET_STRUCT_LENGTH) {
  3509. DBGLOG(P2P, ERROR, "input data length invalid %u\n", u4CmdLen);
  3510. status = -EINVAL;
  3511. break;
  3512. }
  3513. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), wrqu->data.pointer, u4CmdLen)) {
  3514. status = -EFAULT;
  3515. break;
  3516. }
  3517. if (!kalMemCmp(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), extra, u4CmdLen))
  3518. DBGLOG(P2P, INFO, "extra buffer is valid\n");
  3519. else
  3520. DBGLOG(P2P, INFO, "extra 0x%p\n", extra);
  3521. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucOidBuf[0]));
  3522. switch (prP2PReq->u4CmdId) {
  3523. case P2P_CMD_ID_SEND_SD_RESPONSE:
  3524. status = mtk_p2p_wext_send_service_discovery_response(prDev, info, wrqu, (char *)prP2PReq);
  3525. break;
  3526. case P2P_CMD_ID_SEND_SD_REQUEST:
  3527. status = mtk_p2p_wext_send_service_discovery_request(prDev, info, wrqu, (char *)prP2PReq);
  3528. break;
  3529. case P2P_CMD_ID_TERMINATE_SD_PHASE:
  3530. status = mtk_p2p_wext_terminate_service_discovery_phase(prDev, info, wrqu, (char *)prP2PReq);
  3531. break;
  3532. case P2P_CMD_ID_INVITATION:
  3533. if (prP2PReq->inBufferLength == sizeof(IW_P2P_IOCTL_INVITATION_STRUCT)) {
  3534. /* Do nothing */
  3535. /* status = mtk_p2p_wext_invitation_request(prDev, info, wrqu,
  3536. (char *)(prP2PReq->aucBuffer)); */
  3537. }
  3538. break;
  3539. case P2P_CMD_ID_INVITATION_ABORT:
  3540. if (prP2PReq->inBufferLength == sizeof(IW_P2P_IOCTL_ABORT_INVITATION)) {
  3541. /* Do nothing */
  3542. /* status = mtk_p2p_wext_invitation_abort(prDev, info, wrqu,
  3543. (char *)(prP2PReq->aucBuffer)); */
  3544. }
  3545. break;
  3546. case P2P_CMD_ID_START_FORMATION:
  3547. if (prP2PReq->inBufferLength == sizeof(IW_P2P_IOCTL_START_FORMATION))
  3548. status = mtk_p2p_wext_start_formation(prDev, info, wrqu, (char *)(prP2PReq->aucBuffer));
  3549. break;
  3550. default:
  3551. status = -EOPNOTSUPP;
  3552. }
  3553. break;
  3554. #if CFG_SUPPORT_ANTI_PIRACY
  3555. case PRIV_SEC_CHECK_OID:
  3556. if (u4CmdLen > 256) {
  3557. status = -EOPNOTSUPP;
  3558. break;
  3559. }
  3560. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucSecCheck[0]), wrqu->data.pointer, u4CmdLen)) {
  3561. status = -EFAULT;
  3562. break;
  3563. }
  3564. if (!kalMemCmp(&(prGlueInfo->prP2PInfo->aucSecCheck[0]), extra, u4CmdLen))
  3565. DBGLOG(P2P, INFO, "extra buffer is valid\n");
  3566. else
  3567. DBGLOG(P2P, INFO, "extra 0x%p\n", extra);
  3568. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucSecCheck[0]));
  3569. switch (prP2PReq->u4CmdId) {
  3570. case P2P_CMD_ID_SEC_CHECK:
  3571. status = mtk_p2p_wext_set_sec_check_request(prDev, info, wrqu, (char *)prP2PReq);
  3572. break;
  3573. default:
  3574. status = -EOPNOTSUPP;
  3575. }
  3576. break;
  3577. #endif
  3578. case PRIV_CMD_P2P_VERSION:
  3579. if (u4CmdLen > OID_SET_GET_STRUCT_LENGTH) {
  3580. DBGLOG(P2P, ERROR, "input data length invalid %u\n", u4CmdLen);
  3581. status = -EINVAL;
  3582. break;
  3583. }
  3584. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), wrqu->data.pointer, u4CmdLen)) {
  3585. status = -EFAULT;
  3586. break;
  3587. }
  3588. if (!kalMemCmp(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), extra, u4CmdLen))
  3589. DBGLOG(P2P, INFO, "extra buffer is valid\n");
  3590. else
  3591. DBGLOG(P2P, INFO, "extra 0x%p\n", extra);
  3592. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucOidBuf[0]));
  3593. switch (prP2PReq->u4CmdId) {
  3594. case P2P_CMD_ID_P2P_VERSION:
  3595. status = mtk_p2p_wext_set_p2p_version(prDev, info, wrqu, (char *)prP2PReq);
  3596. break;
  3597. default:
  3598. status = -EOPNOTSUPP;
  3599. break;
  3600. }
  3601. break;
  3602. default:
  3603. status = -EOPNOTSUPP;
  3604. break;
  3605. }
  3606. return status;
  3607. }
  3608. /*----------------------------------------------------------------------------*/
  3609. /*!
  3610. * \brief P2P Private I/O Control handler (IOC_P2P_GET_STRUCT)
  3611. *
  3612. * \param[in] prDev Net device requested.
  3613. * \param[inout] wrqu Pointer to iwreq_data
  3614. *
  3615. * \retval 0 Success.
  3616. * \retval -EFAULT Setting parameters to driver fail.
  3617. * \retval -EOPNOTSUPP Key size not supported.
  3618. *
  3619. * \note
  3620. */
  3621. /*----------------------------------------------------------------------------*/
  3622. int
  3623. mtk_p2p_wext_get_struct(IN struct net_device *prDev,
  3624. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3625. {
  3626. int status = 0;
  3627. UINT_32 u4SubCmd = 0;
  3628. UINT_32 u4CmdLen = 0;
  3629. P_GLUE_INFO_T prGlueInfo = NULL;
  3630. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = NULL;
  3631. ASSERT(prDev);
  3632. ASSERT(wrqu);
  3633. if (!prDev || !wrqu) {
  3634. DBGLOG(P2P, WARN, "%s(): invalid param(0x%p, 0x%p)\n", __func__, prDev, wrqu);
  3635. return -EINVAL;
  3636. }
  3637. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3638. ASSERT(prGlueInfo);
  3639. u4SubCmd = (UINT_32) wrqu->data.flags;
  3640. u4CmdLen = (UINT_32) wrqu->data.length;
  3641. kalMemZero(&(prGlueInfo->prP2PInfo->aucOidBuf[0]), sizeof(prGlueInfo->prP2PInfo->aucOidBuf));
  3642. switch (u4SubCmd) {
  3643. case PRIV_CMD_OID:
  3644. if (u4CmdLen > sizeof(IW_P2P_TRANSPORT_STRUCT)) {
  3645. DBGLOG(P2P, ERROR, "input data length invalid %u\n", u4CmdLen);
  3646. status = -EINVAL;
  3647. break;
  3648. }
  3649. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3650. wrqu->data.pointer, sizeof(IW_P2P_TRANSPORT_STRUCT))) {
  3651. DBGLOG(P2P, ERROR, "%s() copy_from_user oidBuf fail\n", __func__);
  3652. return -EFAULT;
  3653. }
  3654. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucOidBuf[0]));
  3655. switch (prP2PReq->u4CmdId) {
  3656. case P2P_CMD_ID_GET_SD_REQUEST:
  3657. status = mtk_p2p_wext_get_service_discovery_request(prDev, info, wrqu, (char *)prP2PReq);
  3658. break;
  3659. case P2P_CMD_ID_GET_SD_RESPONSE:
  3660. status = mtk_p2p_wext_get_service_discovery_response(prDev, info, wrqu, (char *)prP2PReq);
  3661. break;
  3662. case P2P_CMD_ID_INVITATION_INDICATE:
  3663. {
  3664. status =
  3665. mtk_p2p_wext_invitation_indicate(prDev, info, wrqu, (char *)(prP2PReq->aucBuffer));
  3666. prP2PReq->outBufferLength = wrqu->data.length;
  3667. if (copy_to_user(wrqu->data.pointer,
  3668. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3669. wrqu->data.length + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3670. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  3671. return -EIO;
  3672. } else {
  3673. return 0;
  3674. }
  3675. break;
  3676. }
  3677. case P2P_CMD_ID_INVITATION_STATUS:
  3678. {
  3679. status =
  3680. mtk_p2p_wext_invitation_status(prDev, info, wrqu, (char *)(prP2PReq->aucBuffer));
  3681. prP2PReq->outBufferLength = wrqu->data.length;
  3682. if (copy_to_user(wrqu->data.pointer,
  3683. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3684. wrqu->data.length + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3685. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  3686. return -EIO;
  3687. } else {
  3688. return 0;
  3689. }
  3690. break;
  3691. }
  3692. case P2P_CMD_ID_GET_CH_LIST:
  3693. {
  3694. UINT_16 i;
  3695. UINT_8 NumOfChannel = 50;
  3696. RF_CHANNEL_INFO_T aucChannelList[50];
  3697. UINT_8 ucMaxChannelNum = 50;
  3698. PUINT_8 pucChnlList = (PUINT_8) prP2PReq->aucBuffer;
  3699. kalGetChnlList(prGlueInfo, BAND_NULL, ucMaxChannelNum, &NumOfChannel, aucChannelList);
  3700. if (NumOfChannel > 50)
  3701. NumOfChannel = 50;
  3702. prP2PReq->outBufferLength = NumOfChannel;
  3703. /*here must confirm NumOfChannel < 16, for prP2PReq->aucBuffer 16 byte*/
  3704. if (NumOfChannel >= 15) {
  3705. /*DBGLOG(P2P, ERROR, "channel num > 15\n", __func__);*/
  3706. ASSERT(FALSE);
  3707. }
  3708. for (i = 0; i < NumOfChannel; i++) {
  3709. #if 0
  3710. /* 20120208 frog: modify to avoid clockwork warning. */
  3711. prP2PReq->aucBuffer[i] = aucChannelList[i].ucChannelNum;
  3712. #else
  3713. *pucChnlList = aucChannelList[i].ucChannelNum;
  3714. pucChnlList++;
  3715. #endif
  3716. }
  3717. if (copy_to_user(wrqu->data.pointer,
  3718. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3719. NumOfChannel + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3720. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  3721. return -EIO;
  3722. } else {
  3723. return 0;
  3724. }
  3725. break;
  3726. }
  3727. case P2P_CMD_ID_GET_OP_CH:
  3728. {
  3729. prP2PReq->inBufferLength = 4;
  3730. status = wlanoidQueryP2pOpChannel(prGlueInfo->prAdapter,
  3731. prP2PReq->aucBuffer,
  3732. prP2PReq->inBufferLength, &prP2PReq->outBufferLength);
  3733. if (status == 0) { /* WLAN_STATUS_SUCCESS */
  3734. if (copy_to_user(wrqu->data.pointer,
  3735. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3736. prP2PReq->outBufferLength + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT,
  3737. aucBuffer))) {
  3738. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  3739. return -EIO;
  3740. }
  3741. } else {
  3742. if (copy_to_user(wrqu->data.pointer,
  3743. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3744. OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3745. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  3746. return -EIO;
  3747. }
  3748. }
  3749. break;
  3750. }
  3751. default:
  3752. status = -EOPNOTSUPP;
  3753. }
  3754. break;
  3755. #if CFG_SUPPORT_ANTI_PIRACY
  3756. case PRIV_SEC_CHECK_OID:
  3757. if (u4CmdLen > sizeof(IW_P2P_TRANSPORT_STRUCT)) {
  3758. status = -EINVAL;
  3759. break;
  3760. }
  3761. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucSecCheck[0]),
  3762. wrqu->data.pointer, sizeof(IW_P2P_TRANSPORT_STRUCT))) {
  3763. DBGLOG(P2P, ERROR, "%s() copy_from_user oidBuf fail\n", __func__);
  3764. return -EFAULT;
  3765. }
  3766. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucSecCheck[0]));
  3767. switch (prP2PReq->u4CmdId) {
  3768. case P2P_CMD_ID_SEC_CHECK:
  3769. status = mtk_p2p_wext_get_sec_check_response(prDev, info, wrqu, (char *)prP2PReq);
  3770. break;
  3771. default:
  3772. status = -EOPNOTSUPP;
  3773. }
  3774. break;
  3775. #endif
  3776. case PRIV_CMD_P2P_VERSION:
  3777. if (u4CmdLen > sizeof(IW_P2P_TRANSPORT_STRUCT)) {
  3778. status = -EINVAL;
  3779. break;
  3780. }
  3781. if (copy_from_user(&(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3782. wrqu->data.pointer, sizeof(IW_P2P_TRANSPORT_STRUCT))) {
  3783. DBGLOG(P2P, ERROR, "%s() copy_from_user oidBuf fail\n", __func__);
  3784. return -EFAULT;
  3785. }
  3786. prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) (&(prGlueInfo->prP2PInfo->aucOidBuf[0]));
  3787. switch (prP2PReq->u4CmdId) {
  3788. case P2P_CMD_ID_P2P_VERSION:
  3789. status = mtk_p2p_wext_get_p2p_version(prDev, info, wrqu, (char *)prP2PReq);
  3790. break;
  3791. default:
  3792. status = -EOPNOTSUPP;
  3793. break;
  3794. }
  3795. /* Copy queried data to user. */
  3796. if (status == 0) { /* WLAN_STATUS_SUCCESS */
  3797. if (copy_to_user(wrqu->data.pointer,
  3798. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3799. prP2PReq->outBufferLength + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3800. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  3801. return -EIO;
  3802. }
  3803. }
  3804. else {
  3805. if (copy_to_user(wrqu->data.pointer,
  3806. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3807. OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3808. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  3809. return -EIO;
  3810. }
  3811. }
  3812. break;
  3813. default:
  3814. return -EOPNOTSUPP;
  3815. }
  3816. return status;
  3817. }
  3818. /*----------------------------------------------------------------------------*/
  3819. /*!
  3820. * \brief P2P Private I/O Control handler for
  3821. * getting service discovery request frame from driver
  3822. *
  3823. * \param[in] prDev Net device requested.
  3824. * \param[inout] wrqu Pointer to iwreq_data
  3825. *
  3826. * \retval 0 Success.
  3827. * \retval -EFAULT Setting parameters to driver fail.
  3828. * \retval -EOPNOTSUPP Key size not supported.
  3829. *
  3830. * \note
  3831. */
  3832. /*----------------------------------------------------------------------------*/
  3833. int
  3834. mtk_p2p_wext_get_service_discovery_request(IN struct net_device *prDev,
  3835. IN struct iw_request_info *info,
  3836. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3837. {
  3838. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3839. UINT_32 u4QueryInfoLen = 0;
  3840. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3841. P_GLUE_INFO_T prGlueInfo = NULL;
  3842. ASSERT(prDev);
  3843. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3844. ASSERT(prGlueInfo);
  3845. rStatus = kalIoctl(prGlueInfo,
  3846. wlanoidGetP2PSDRequest,
  3847. prP2PReq->aucBuffer, prP2PReq->outBufferLength, TRUE, FALSE, TRUE, TRUE, &u4QueryInfoLen);
  3848. if (rStatus != WLAN_STATUS_SUCCESS)
  3849. return -EFAULT;
  3850. prP2PReq->outBufferLength = u4QueryInfoLen;
  3851. if (copy_to_user(wrqu->data.pointer,
  3852. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3853. u4QueryInfoLen + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3854. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  3855. return -EIO;
  3856. } else {
  3857. return 0;
  3858. }
  3859. }
  3860. /*----------------------------------------------------------------------------*/
  3861. /*!
  3862. * \brief P2P Private I/O Control handler for
  3863. * getting service discovery response frame from driver
  3864. *
  3865. * \param[in] prDev Net device requested.
  3866. * \param[inout] wrqu Pointer to iwreq_data
  3867. *
  3868. * \retval 0 Success.
  3869. * \retval -EFAULT Setting parameters to driver fail.
  3870. * \retval -EOPNOTSUPP Key size not supported.
  3871. *
  3872. * \note
  3873. */
  3874. /*----------------------------------------------------------------------------*/
  3875. int
  3876. mtk_p2p_wext_get_service_discovery_response(IN struct net_device *prDev,
  3877. IN struct iw_request_info *info,
  3878. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3879. {
  3880. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3881. UINT_32 u4QueryInfoLen = 0;
  3882. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3883. P_GLUE_INFO_T prGlueInfo = NULL;
  3884. ASSERT(prDev);
  3885. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3886. ASSERT(prGlueInfo);
  3887. rStatus = kalIoctl(prGlueInfo,
  3888. wlanoidGetP2PSDResponse,
  3889. prP2PReq->aucBuffer, prP2PReq->outBufferLength, TRUE, FALSE, TRUE, TRUE, &u4QueryInfoLen);
  3890. if (rStatus != WLAN_STATUS_SUCCESS)
  3891. return -EFAULT;
  3892. prP2PReq->outBufferLength = u4QueryInfoLen;
  3893. if (copy_to_user(wrqu->data.pointer,
  3894. &(prGlueInfo->prP2PInfo->aucOidBuf[0]),
  3895. u4QueryInfoLen + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  3896. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  3897. return -EIO;
  3898. }
  3899. return 0;
  3900. }
  3901. /*----------------------------------------------------------------------------*/
  3902. /*!
  3903. * \brief P2P Private I/O Control handler for
  3904. * sending service discovery request frame
  3905. *
  3906. * \param[in] prDev Net device requested.
  3907. * \param[inout] wrqu Pointer to iwreq_data
  3908. *
  3909. * \retval 0 Success.
  3910. * \retval -EFAULT Setting parameters to driver fail.
  3911. * \retval -EOPNOTSUPP Key size not supported.
  3912. *
  3913. * \note
  3914. */
  3915. /*----------------------------------------------------------------------------*/
  3916. int
  3917. mtk_p2p_wext_send_service_discovery_request(IN struct net_device *prDev,
  3918. IN struct iw_request_info *info,
  3919. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3920. {
  3921. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3922. UINT_32 u4SetInfoLen;
  3923. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3924. P_GLUE_INFO_T prGlueInfo = NULL;
  3925. ASSERT(prDev);
  3926. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3927. ASSERT(prGlueInfo);
  3928. rStatus = kalIoctl(prGlueInfo,
  3929. wlanoidSendP2PSDRequest,
  3930. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  3931. if (rStatus != WLAN_STATUS_SUCCESS)
  3932. return -EFAULT;
  3933. else
  3934. return 0;
  3935. }
  3936. /*----------------------------------------------------------------------------*/
  3937. /*!
  3938. * \brief P2P Private I/O Control handler for
  3939. * sending service discovery response frame
  3940. *
  3941. * \param[in] prDev Net device requested.
  3942. * \param[inout] wrqu Pointer to iwreq_data
  3943. *
  3944. * \retval 0 Success.
  3945. * \retval -EFAULT Setting parameters to driver fail.
  3946. * \retval -EOPNOTSUPP Key size not supported.
  3947. *
  3948. * \note
  3949. */
  3950. /*----------------------------------------------------------------------------*/
  3951. int
  3952. mtk_p2p_wext_send_service_discovery_response(IN struct net_device *prDev,
  3953. IN struct iw_request_info *info,
  3954. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3955. {
  3956. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3957. UINT_32 u4SetInfoLen;
  3958. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3959. P_GLUE_INFO_T prGlueInfo = NULL;
  3960. ASSERT(prDev);
  3961. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3962. ASSERT(prGlueInfo);
  3963. rStatus = kalIoctl(prGlueInfo,
  3964. wlanoidSendP2PSDResponse,
  3965. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  3966. if (rStatus != WLAN_STATUS_SUCCESS)
  3967. return -EFAULT;
  3968. else
  3969. return 0;
  3970. }
  3971. #if CFG_SUPPORT_ANTI_PIRACY
  3972. /*----------------------------------------------------------------------------*/
  3973. /*!
  3974. * \brief P2P Private I/O Control handler for
  3975. *
  3976. * \param[in] prDev Net device requested.
  3977. * \param[inout] wrqu Pointer to iwreq_data
  3978. *
  3979. * \retval 0 Success.
  3980. * \retval -EFAULT Setting parameters to driver fail.
  3981. * \retval -EOPNOTSUPP Key size not supported.
  3982. *
  3983. * \note
  3984. */
  3985. /*----------------------------------------------------------------------------*/
  3986. int
  3987. mtk_p2p_wext_set_sec_check_request(IN struct net_device *prDev,
  3988. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  3989. {
  3990. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  3991. UINT_32 u4SetInfoLen;
  3992. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  3993. P_GLUE_INFO_T prGlueInfo = NULL;
  3994. ASSERT(prDev);
  3995. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  3996. ASSERT(prGlueInfo);
  3997. rStatus = kalIoctl(prGlueInfo,
  3998. wlanoidSetSecCheckRequest,
  3999. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  4000. if (rStatus != WLAN_STATUS_SUCCESS)
  4001. return -EFAULT;
  4002. else
  4003. return 0;
  4004. }
  4005. /*----------------------------------------------------------------------------*/
  4006. /*!
  4007. * \brief P2P Private I/O Control handler for
  4008. *
  4009. * \param[in] prDev Net device requested.
  4010. * \param[inout] wrqu Pointer to iwreq_data
  4011. *
  4012. * \retval 0 Success.
  4013. * \retval -EFAULT Setting parameters to driver fail.
  4014. * \retval -EOPNOTSUPP Key size not supported.
  4015. *
  4016. * \note
  4017. */
  4018. /*----------------------------------------------------------------------------*/
  4019. int
  4020. mtk_p2p_wext_get_sec_check_response(IN struct net_device *prDev,
  4021. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  4022. {
  4023. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  4024. UINT_32 u4QueryInfoLen = 0;
  4025. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  4026. P_GLUE_INFO_T prGlueInfo = NULL;
  4027. ASSERT(prDev);
  4028. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  4029. ASSERT(prGlueInfo);
  4030. DBGLOG(P2P, INFO, "mtk_p2p_wext_get_sec_check_response\n");
  4031. rStatus = kalIoctl(prGlueInfo,
  4032. wlanoidGetSecCheckResponse,
  4033. prP2PReq->aucBuffer, prP2PReq->outBufferLength, TRUE, FALSE, TRUE, TRUE, &u4QueryInfoLen);
  4034. if (rStatus != WLAN_STATUS_SUCCESS)
  4035. return -EFAULT;
  4036. prP2PReq->outBufferLength = u4QueryInfoLen;
  4037. if (copy_to_user(wrqu->data.pointer,
  4038. prP2PReq->aucBuffer, u4QueryInfoLen + OFFSET_OF(IW_P2P_TRANSPORT_STRUCT, aucBuffer))) {
  4039. DBGLOG(P2P, ERROR, "%s() copy_to_user() fail\n", __func__);
  4040. return -EIO;
  4041. }
  4042. return 0;
  4043. }
  4044. #endif
  4045. /*----------------------------------------------------------------------------*/
  4046. /*!
  4047. * \brief P2P Private I/O Control handler for
  4048. * terminating service discovery phase
  4049. *
  4050. * \param[in] prDev Net device requested.
  4051. * \param[inout] wrqu Pointer to iwreq_data
  4052. *
  4053. * \retval 0 Success.
  4054. * \retval -EFAULT Setting parameters to driver fail.
  4055. * \retval -EOPNOTSUPP Key size not supported.
  4056. *
  4057. * \note
  4058. */
  4059. /*----------------------------------------------------------------------------*/
  4060. int
  4061. mtk_p2p_wext_terminate_service_discovery_phase(IN struct net_device *prDev,
  4062. IN struct iw_request_info *info,
  4063. IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  4064. {
  4065. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  4066. UINT_32 u4SetInfoLen;
  4067. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  4068. P_GLUE_INFO_T prGlueInfo = NULL;
  4069. ASSERT(prDev);
  4070. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  4071. ASSERT(prGlueInfo);
  4072. rStatus = kalIoctl(prGlueInfo,
  4073. wlanoidSetP2PTerminateSDPhase,
  4074. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  4075. if (rStatus != WLAN_STATUS_SUCCESS)
  4076. return -EFAULT;
  4077. else
  4078. return 0;
  4079. }
  4080. /*----------------------------------------------------------------------------*/
  4081. /*!
  4082. * \brief P2P Private I/O Control handler for
  4083. *
  4084. * \param[in] prDev Net device requested.
  4085. * \param[inout] wrqu Pointer to iwreq_data
  4086. *
  4087. * \retval 0 Success.
  4088. * \retval -EFAULT Setting parameters to driver fail.
  4089. * \retval -EOPNOTSUPP Key size not supported.
  4090. *
  4091. * \note
  4092. */
  4093. /*----------------------------------------------------------------------------*/
  4094. int
  4095. mtk_p2p_wext_set_noa_param(IN struct net_device *prDev,
  4096. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  4097. {
  4098. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  4099. UINT_32 u4SetInfoLen;
  4100. /* P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT)extra; */
  4101. P_PARAM_CUSTOM_NOA_PARAM_STRUCT_T prNoaParam = (P_PARAM_CUSTOM_NOA_PARAM_STRUCT_T) extra;
  4102. P_GLUE_INFO_T prGlueInfo = NULL;
  4103. ASSERT(prDev);
  4104. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  4105. ASSERT(prGlueInfo);
  4106. DBGLOG(P2P, INFO, "mtk_p2p_wext_set_noa_param\n");
  4107. rStatus = kalIoctl(prGlueInfo, wlanoidSetNoaParam, prNoaParam, /* prP2PReq->aucBuffer, */
  4108. sizeof(PARAM_CUSTOM_NOA_PARAM_STRUCT_T), /* prP2PReq->inBufferLength, */
  4109. FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  4110. if (rStatus != WLAN_STATUS_SUCCESS)
  4111. return -EFAULT;
  4112. else
  4113. return 0;
  4114. }
  4115. /*----------------------------------------------------------------------------*/
  4116. /*!
  4117. * \brief P2P Private I/O Control handler for
  4118. *
  4119. * \param[in] prDev Net device requested.
  4120. * \param[inout] wrqu Pointer to iwreq_data
  4121. *
  4122. * \retval 0 Success.
  4123. * \retval -EFAULT Setting parameters to driver fail.
  4124. * \retval -EOPNOTSUPP Key size not supported.
  4125. *
  4126. * \note
  4127. */
  4128. /*----------------------------------------------------------------------------*/
  4129. int
  4130. mtk_p2p_wext_set_oppps_param(IN struct net_device *prDev,
  4131. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  4132. {
  4133. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  4134. UINT_32 u4SetInfoLen;
  4135. /* P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT)extra; */
  4136. P_PARAM_CUSTOM_OPPPS_PARAM_STRUCT_T prOppPsParam = (P_PARAM_CUSTOM_OPPPS_PARAM_STRUCT_T) extra;
  4137. P_GLUE_INFO_T prGlueInfo = NULL;
  4138. ASSERT(prDev);
  4139. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  4140. ASSERT(prGlueInfo);
  4141. DBGLOG(P2P, INFO, "mtk_p2p_wext_set_oppps_param\n");
  4142. rStatus = kalIoctl(prGlueInfo, wlanoidSetOppPsParam, prOppPsParam, /* prP2PReq->aucBuffer, */
  4143. sizeof(PARAM_CUSTOM_OPPPS_PARAM_STRUCT_T), /* prP2PReq->inBufferLength, */
  4144. FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  4145. if (rStatus != WLAN_STATUS_SUCCESS)
  4146. return -EFAULT;
  4147. else
  4148. return 0;
  4149. }
  4150. int
  4151. mtk_p2p_wext_set_p2p_version(IN struct net_device *prDev,
  4152. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  4153. {
  4154. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  4155. P_GLUE_INFO_T prGlueInfo = NULL;
  4156. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  4157. UINT_32 u4SetInfoLen;
  4158. ASSERT(prDev);
  4159. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  4160. ASSERT(prGlueInfo);
  4161. rStatus = kalIoctl(prGlueInfo,
  4162. wlanoidSetP2pSupplicantVersion,
  4163. prP2PReq->aucBuffer, prP2PReq->inBufferLength, FALSE, FALSE, TRUE, TRUE, &u4SetInfoLen);
  4164. if (rStatus != WLAN_STATUS_SUCCESS)
  4165. return -EFAULT;
  4166. else
  4167. return rStatus;
  4168. }
  4169. /* mtk_p2p_wext_set_p2p_version */
  4170. int
  4171. mtk_p2p_wext_get_p2p_version(IN struct net_device *prDev,
  4172. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  4173. {
  4174. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  4175. UINT_32 u4QueryInfoLen;
  4176. P_IW_P2P_TRANSPORT_STRUCT prP2PReq = (P_IW_P2P_TRANSPORT_STRUCT) extra;
  4177. P_GLUE_INFO_T prGlueInfo = NULL;
  4178. ASSERT(prDev);
  4179. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  4180. ASSERT(prGlueInfo);
  4181. rStatus = kalIoctl(prGlueInfo,
  4182. wlanoidQueryP2pVersion,
  4183. prP2PReq->aucBuffer, prP2PReq->outBufferLength, TRUE, FALSE, TRUE, TRUE, &u4QueryInfoLen);
  4184. if (rStatus != WLAN_STATUS_SUCCESS)
  4185. return -EFAULT;
  4186. else
  4187. return rStatus;
  4188. } /* mtk_p2p_wext_get_p2p_version */
  4189. #if CFG_SUPPORT_P2P_RSSI_QUERY
  4190. int
  4191. mtk_p2p_wext_get_rssi(IN struct net_device *prDev,
  4192. IN struct iw_request_info *info, IN OUT union iwreq_data *wrqu, IN OUT char *extra)
  4193. {
  4194. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  4195. UINT_32 u4QueryInfoLen;
  4196. struct iw_point *prData = (struct iw_point *)&wrqu->data;
  4197. UINT_16 u2BufferSize = 0;
  4198. P_GLUE_INFO_T prGlueInfo = NULL;
  4199. INT_32 i4Rssi;
  4200. struct iw_statistics *pStats = NULL;
  4201. ASSERT(prDev);
  4202. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  4203. ASSERT(prGlueInfo);
  4204. if (!prGlueInfo) {
  4205. rStatus = WLAN_STATUS_FAILURE;
  4206. goto stat_out;
  4207. }
  4208. pStats = (struct iw_statistics *)(&(prGlueInfo->rP2pIwStats));
  4209. rStatus = kalIoctl(prGlueInfo,
  4210. wlanoidQueryP2pRssi, &i4Rssi, sizeof(i4Rssi), TRUE, TRUE, TRUE, TRUE, &u4QueryInfoLen);
  4211. u2BufferSize = prData->length;
  4212. if (u2BufferSize < sizeof(struct iw_statistics))
  4213. return -E2BIG;
  4214. if (copy_to_user(prData->pointer, pStats, sizeof(struct iw_statistics)))
  4215. rStatus = WLAN_STATUS_FAILURE;
  4216. stat_out:
  4217. if (rStatus != WLAN_STATUS_SUCCESS)
  4218. return -EFAULT;
  4219. else
  4220. return rStatus;
  4221. } /* mtk_p2p_wext_get_rssi */
  4222. struct iw_statistics *mtk_p2p_wext_get_wireless_stats(struct net_device *prDev)
  4223. {
  4224. WLAN_STATUS rStatus = WLAN_STATUS_FAILURE;
  4225. P_GLUE_INFO_T prGlueInfo = NULL;
  4226. struct iw_statistics *pStats = NULL;
  4227. INT_32 i4Rssi;
  4228. UINT_32 bufLen = 0;
  4229. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  4230. ASSERT(prGlueInfo);
  4231. if (!prGlueInfo)
  4232. goto stat_out;
  4233. pStats = (struct iw_statistics *)(&(prGlueInfo->rP2pIwStats));
  4234. if (!prDev || !netif_carrier_ok(prDev)) {
  4235. /* network not connected */
  4236. goto stat_out;
  4237. }
  4238. rStatus = kalIoctl(prGlueInfo, wlanoidQueryP2pRssi, &i4Rssi, sizeof(i4Rssi), TRUE, TRUE, TRUE, TRUE, &bufLen);
  4239. stat_out:
  4240. return pStats;
  4241. } /* mtk_p2p_wext_get_wireless_stats */
  4242. #endif /* CFG_SUPPORT_P2P_RSSI_QUERY */
  4243. int
  4244. mtk_p2p_wext_set_txpow(IN struct net_device *prDev,
  4245. IN struct iw_request_info *prIwrInfo, IN OUT union iwreq_data *prTxPow, IN char *pcExtra)
  4246. {
  4247. P_GLUE_INFO_T prGlueInfo = (P_GLUE_INFO_T) NULL;
  4248. P_ADAPTER_T prAdapter = (P_ADAPTER_T) NULL;
  4249. #if 0
  4250. P_MSG_P2P_FUNCTION_SWITCH_T prMsgFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) NULL;
  4251. #endif
  4252. int i4Ret = 0;
  4253. ASSERT(prDev);
  4254. ASSERT(prTxPow);
  4255. do {
  4256. if ((!prDev) || (!prTxPow)) {
  4257. i4Ret = -EINVAL;
  4258. break;
  4259. }
  4260. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  4261. if (!prGlueInfo) {
  4262. i4Ret = -EINVAL;
  4263. break;
  4264. }
  4265. prAdapter = prGlueInfo->prAdapter;
  4266. #if 0
  4267. prMsgFuncSwitch =
  4268. (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG,
  4269. sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  4270. if (!prMsgFuncSwitch) {
  4271. ASSERT(0);
  4272. return -ENOMEM;
  4273. }
  4274. prMsgFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  4275. if (prTxPow->disabled) {
  4276. /* Dissolve. */
  4277. prMsgFuncSwitch->fgIsFuncOn = FALSE;
  4278. } else {
  4279. /* Re-enable function. */
  4280. prMsgFuncSwitch->fgIsFuncOn = TRUE;
  4281. }
  4282. /* 1.3 send message */
  4283. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgFuncSwitch, MSG_SEND_METHOD_BUF);
  4284. #endif
  4285. } while (FALSE);
  4286. return i4Ret;
  4287. } /* mtk_p2p_wext_set_txpow */
  4288. #endif