ioctl_cfg80211.c 155 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _IOCTL_CFG80211_C_
  21. #include <drv_types.h>
  22. #ifdef CONFIG_IOCTL_CFG80211
  23. #define RTW_MAX_MGMT_TX_CNT (8)
  24. #define RTW_SCAN_IE_LEN_MAX 2304
  25. #define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 65535 //ms
  26. #define RTW_MAX_NUM_PMKIDS 4
  27. #define RTW_CH_MAX_2G_CHANNEL 14 /* Max channel in 2G band */
  28. static const u32 rtw_cipher_suites[] = {
  29. WLAN_CIPHER_SUITE_WEP40,
  30. WLAN_CIPHER_SUITE_WEP104,
  31. WLAN_CIPHER_SUITE_TKIP,
  32. WLAN_CIPHER_SUITE_CCMP,
  33. #ifdef CONFIG_WAPI_SUPPORT
  34. WLAN_CIPHER_SUITE_SMS4,
  35. #endif // CONFIG_WAPI_SUPPORT
  36. };
  37. #define RATETAB_ENT(_rate, _rateid, _flags) \
  38. { \
  39. .bitrate = (_rate), \
  40. .hw_value = (_rateid), \
  41. .flags = (_flags), \
  42. }
  43. #define CHAN2G(_channel, _freq, _flags) { \
  44. .band = IEEE80211_BAND_2GHZ, \
  45. .center_freq = (_freq), \
  46. .hw_value = (_channel), \
  47. .flags = (_flags), \
  48. .max_antenna_gain = 0, \
  49. .max_power = 30, \
  50. }
  51. #define CHAN5G(_channel, _flags) { \
  52. .band = IEEE80211_BAND_5GHZ, \
  53. .center_freq = 5000 + (5 * (_channel)), \
  54. .hw_value = (_channel), \
  55. .flags = (_flags), \
  56. .max_antenna_gain = 0, \
  57. .max_power = 30, \
  58. }
  59. static struct ieee80211_rate rtw_rates[] = {
  60. RATETAB_ENT(10, 0x1, 0),
  61. RATETAB_ENT(20, 0x2, 0),
  62. RATETAB_ENT(55, 0x4, 0),
  63. RATETAB_ENT(110, 0x8, 0),
  64. RATETAB_ENT(60, 0x10, 0),
  65. RATETAB_ENT(90, 0x20, 0),
  66. RATETAB_ENT(120, 0x40, 0),
  67. RATETAB_ENT(180, 0x80, 0),
  68. RATETAB_ENT(240, 0x100, 0),
  69. RATETAB_ENT(360, 0x200, 0),
  70. RATETAB_ENT(480, 0x400, 0),
  71. RATETAB_ENT(540, 0x800, 0),
  72. };
  73. #define rtw_a_rates (rtw_rates + 4)
  74. #define RTW_A_RATES_NUM 8
  75. #define rtw_g_rates (rtw_rates + 0)
  76. #define RTW_G_RATES_NUM 12
  77. #define RTW_2G_CHANNELS_NUM 14
  78. #define RTW_5G_CHANNELS_NUM 37
  79. static struct ieee80211_channel rtw_2ghz_channels[] = {
  80. CHAN2G(1, 2412, 0),
  81. CHAN2G(2, 2417, 0),
  82. CHAN2G(3, 2422, 0),
  83. CHAN2G(4, 2427, 0),
  84. CHAN2G(5, 2432, 0),
  85. CHAN2G(6, 2437, 0),
  86. CHAN2G(7, 2442, 0),
  87. CHAN2G(8, 2447, 0),
  88. CHAN2G(9, 2452, 0),
  89. CHAN2G(10, 2457, 0),
  90. CHAN2G(11, 2462, 0),
  91. CHAN2G(12, 2467, 0),
  92. CHAN2G(13, 2472, 0),
  93. CHAN2G(14, 2484, 0),
  94. };
  95. static struct ieee80211_channel rtw_5ghz_a_channels[] = {
  96. CHAN5G(34, 0), CHAN5G(36, 0),
  97. CHAN5G(38, 0), CHAN5G(40, 0),
  98. CHAN5G(42, 0), CHAN5G(44, 0),
  99. CHAN5G(46, 0), CHAN5G(48, 0),
  100. CHAN5G(52, 0), CHAN5G(56, 0),
  101. CHAN5G(60, 0), CHAN5G(64, 0),
  102. CHAN5G(100, 0), CHAN5G(104, 0),
  103. CHAN5G(108, 0), CHAN5G(112, 0),
  104. CHAN5G(116, 0), CHAN5G(120, 0),
  105. CHAN5G(124, 0), CHAN5G(128, 0),
  106. CHAN5G(132, 0), CHAN5G(136, 0),
  107. CHAN5G(140, 0), CHAN5G(149, 0),
  108. CHAN5G(153, 0), CHAN5G(157, 0),
  109. CHAN5G(161, 0), CHAN5G(165, 0),
  110. CHAN5G(184, 0), CHAN5G(188, 0),
  111. CHAN5G(192, 0), CHAN5G(196, 0),
  112. CHAN5G(200, 0), CHAN5G(204, 0),
  113. CHAN5G(208, 0), CHAN5G(212, 0),
  114. CHAN5G(216, 0),
  115. };
  116. void rtw_2g_channels_init(struct ieee80211_channel *channels)
  117. {
  118. _rtw_memcpy((void*)channels, (void*)rtw_2ghz_channels,
  119. sizeof(struct ieee80211_channel)*RTW_2G_CHANNELS_NUM
  120. );
  121. }
  122. void rtw_5g_channels_init(struct ieee80211_channel *channels)
  123. {
  124. _rtw_memcpy((void*)channels, (void*)rtw_5ghz_a_channels,
  125. sizeof(struct ieee80211_channel)*RTW_5G_CHANNELS_NUM
  126. );
  127. }
  128. void rtw_2g_rates_init(struct ieee80211_rate *rates)
  129. {
  130. _rtw_memcpy(rates, rtw_g_rates,
  131. sizeof(struct ieee80211_rate)*RTW_G_RATES_NUM
  132. );
  133. }
  134. void rtw_5g_rates_init(struct ieee80211_rate *rates)
  135. {
  136. _rtw_memcpy(rates, rtw_a_rates,
  137. sizeof(struct ieee80211_rate)*RTW_A_RATES_NUM
  138. );
  139. }
  140. struct ieee80211_supported_band *rtw_spt_band_alloc(
  141. enum ieee80211_band band
  142. )
  143. {
  144. struct ieee80211_supported_band *spt_band = NULL;
  145. int n_channels, n_bitrates;
  146. if(band == IEEE80211_BAND_2GHZ)
  147. {
  148. n_channels = RTW_2G_CHANNELS_NUM;
  149. n_bitrates = RTW_G_RATES_NUM;
  150. }
  151. else if(band == IEEE80211_BAND_5GHZ)
  152. {
  153. n_channels = RTW_5G_CHANNELS_NUM;
  154. n_bitrates = RTW_A_RATES_NUM;
  155. }
  156. else
  157. {
  158. goto exit;
  159. }
  160. spt_band = (struct ieee80211_supported_band *)rtw_zmalloc(
  161. sizeof(struct ieee80211_supported_band)
  162. + sizeof(struct ieee80211_channel)*n_channels
  163. + sizeof(struct ieee80211_rate)*n_bitrates
  164. );
  165. if(!spt_band)
  166. goto exit;
  167. spt_band->channels = (struct ieee80211_channel*)(((u8*)spt_band)+sizeof(struct ieee80211_supported_band));
  168. spt_band->bitrates= (struct ieee80211_rate*)(((u8*)spt_band->channels)+sizeof(struct ieee80211_channel)*n_channels);
  169. spt_band->band = band;
  170. spt_band->n_channels = n_channels;
  171. spt_band->n_bitrates = n_bitrates;
  172. if(band == IEEE80211_BAND_2GHZ)
  173. {
  174. rtw_2g_channels_init(spt_band->channels);
  175. rtw_2g_rates_init(spt_band->bitrates);
  176. }
  177. else if(band == IEEE80211_BAND_5GHZ)
  178. {
  179. rtw_5g_channels_init(spt_band->channels);
  180. rtw_5g_rates_init(spt_band->bitrates);
  181. }
  182. //spt_band.ht_cap
  183. exit:
  184. return spt_band;
  185. }
  186. void rtw_spt_band_free(struct ieee80211_supported_band *spt_band)
  187. {
  188. u32 size;
  189. if(!spt_band)
  190. return;
  191. if(spt_band->band == IEEE80211_BAND_2GHZ)
  192. {
  193. size = sizeof(struct ieee80211_supported_band)
  194. + sizeof(struct ieee80211_channel)*RTW_2G_CHANNELS_NUM
  195. + sizeof(struct ieee80211_rate)*RTW_G_RATES_NUM;
  196. }
  197. else if(spt_band->band == IEEE80211_BAND_5GHZ)
  198. {
  199. size = sizeof(struct ieee80211_supported_band)
  200. + sizeof(struct ieee80211_channel)*RTW_5G_CHANNELS_NUM
  201. + sizeof(struct ieee80211_rate)*RTW_A_RATES_NUM;
  202. }
  203. else
  204. {
  205. }
  206. rtw_mfree((u8*)spt_band, size);
  207. }
  208. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  209. static const struct ieee80211_txrx_stypes
  210. rtw_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  211. [NL80211_IFTYPE_ADHOC] = {
  212. .tx = 0xffff,
  213. .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
  214. },
  215. [NL80211_IFTYPE_STATION] = {
  216. .tx = 0xffff,
  217. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  218. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  219. },
  220. [NL80211_IFTYPE_AP] = {
  221. .tx = 0xffff,
  222. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  223. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  224. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  225. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  226. BIT(IEEE80211_STYPE_AUTH >> 4) |
  227. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  228. BIT(IEEE80211_STYPE_ACTION >> 4)
  229. },
  230. [NL80211_IFTYPE_AP_VLAN] = {
  231. /* copy AP */
  232. .tx = 0xffff,
  233. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  234. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  235. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  236. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  237. BIT(IEEE80211_STYPE_AUTH >> 4) |
  238. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  239. BIT(IEEE80211_STYPE_ACTION >> 4)
  240. },
  241. [NL80211_IFTYPE_P2P_CLIENT] = {
  242. .tx = 0xffff,
  243. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  244. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  245. },
  246. [NL80211_IFTYPE_P2P_GO] = {
  247. .tx = 0xffff,
  248. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  249. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  250. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  251. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  252. BIT(IEEE80211_STYPE_AUTH >> 4) |
  253. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  254. BIT(IEEE80211_STYPE_ACTION >> 4)
  255. },
  256. };
  257. #endif
  258. static int rtw_ieee80211_channel_to_frequency(int chan, int band)
  259. {
  260. /* see 802.11 17.3.8.3.2 and Annex J
  261. * there are overlapping channel numbers in 5GHz and 2GHz bands */
  262. if (band == IEEE80211_BAND_5GHZ) {
  263. if (chan >= 182 && chan <= 196)
  264. return 4000 + chan * 5;
  265. else
  266. return 5000 + chan * 5;
  267. } else { /* IEEE80211_BAND_2GHZ */
  268. if (chan == 14)
  269. return 2484;
  270. else if (chan < 14)
  271. return 2407 + chan * 5;
  272. else
  273. return 0; /* not supported */
  274. }
  275. }
  276. #define MAX_BSSINFO_LEN 1000
  277. static int rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnetwork)
  278. {
  279. int ret=0;
  280. struct ieee80211_channel *notify_channel;
  281. struct cfg80211_bss *bss;
  282. //struct ieee80211_supported_band *band;
  283. u16 channel;
  284. u32 freq;
  285. u64 notify_timestamp;
  286. u16 notify_capability;
  287. u16 notify_interval;
  288. u8 *notify_ie;
  289. size_t notify_ielen;
  290. s32 notify_signal;
  291. u8 buf[MAX_BSSINFO_LEN], *pbuf;
  292. size_t len,bssinf_len=0;
  293. struct rtw_ieee80211_hdr *pwlanhdr;
  294. unsigned short *fctrl;
  295. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  296. struct wireless_dev *wdev = padapter->rtw_wdev;
  297. struct wiphy *wiphy = wdev->wiphy;
  298. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  299. //DBG_8192C("%s\n", __func__);
  300. bssinf_len = pnetwork->network.IELength+sizeof (struct rtw_ieee80211_hdr_3addr);
  301. if(bssinf_len > MAX_BSSINFO_LEN){
  302. DBG_871X("%s IE Length too long > %d byte \n",__FUNCTION__,MAX_BSSINFO_LEN);
  303. goto exit;
  304. }
  305. channel = pnetwork->network.Configuration.DSConfig;
  306. if (channel <= RTW_CH_MAX_2G_CHANNEL)
  307. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
  308. else
  309. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
  310. notify_channel = ieee80211_get_channel(wiphy, freq);
  311. //rtw_get_timestampe_from_ie()
  312. notify_timestamp = jiffies_to_msecs(jiffies)*1000; /* uSec */
  313. notify_interval = le16_to_cpu(*(u16*)rtw_get_beacon_interval_from_ie(pnetwork->network.IEs));
  314. notify_capability = le16_to_cpu(*(u16*)rtw_get_capability_from_ie(pnetwork->network.IEs));
  315. notify_ie = pnetwork->network.IEs+_FIXED_IE_LENGTH_;
  316. notify_ielen = pnetwork->network.IELength-_FIXED_IE_LENGTH_;
  317. //We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM: signal strength in mBm (100*dBm)
  318. if ( check_fwstate(pmlmepriv, _FW_LINKED)== _TRUE &&
  319. is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network)) {
  320. notify_signal = 100*translate_percentage_to_dbm(padapter->recvpriv.signal_strength);//dbm
  321. } else {
  322. notify_signal = 100*translate_percentage_to_dbm(pnetwork->network.PhyInfo.SignalStrength);//dbm
  323. }
  324. /*
  325. DBG_8192C("bssid: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
  326. pnetwork->network.MacAddress[0], pnetwork->network.MacAddress[1], pnetwork->network.MacAddress[2],
  327. pnetwork->network.MacAddress[3], pnetwork->network.MacAddress[4], pnetwork->network.MacAddress[5]);
  328. DBG_8192C("Channel: %d(%d)\n", channel, freq);
  329. DBG_8192C("Capability: %X\n", notify_capability);
  330. DBG_8192C("Beacon interval: %d\n", notify_interval);
  331. DBG_8192C("Signal: %d\n", notify_signal);
  332. DBG_8192C("notify_timestamp: %#018llx\n", notify_timestamp);
  333. */
  334. pbuf = buf;
  335. pwlanhdr = (struct rtw_ieee80211_hdr *)pbuf;
  336. fctrl = &(pwlanhdr->frame_ctl);
  337. *(fctrl) = 0;
  338. SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
  339. //pmlmeext->mgnt_seq++;
  340. if (pnetwork->network.Reserved[0] == 1) { // WIFI_BEACON
  341. _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
  342. SetFrameSubType(pbuf, WIFI_BEACON);
  343. } else {
  344. _rtw_memcpy(pwlanhdr->addr1, myid(&(padapter->eeprompriv)), ETH_ALEN);
  345. SetFrameSubType(pbuf, WIFI_PROBERSP);
  346. }
  347. _rtw_memcpy(pwlanhdr->addr2, pnetwork->network.MacAddress, ETH_ALEN);
  348. _rtw_memcpy(pwlanhdr->addr3, pnetwork->network.MacAddress, ETH_ALEN);
  349. pbuf += sizeof(struct rtw_ieee80211_hdr_3addr);
  350. len = sizeof (struct rtw_ieee80211_hdr_3addr);
  351. _rtw_memcpy(pbuf, pnetwork->network.IEs, pnetwork->network.IELength);
  352. len += pnetwork->network.IELength;
  353. //#ifdef CONFIG_P2P
  354. //if(rtw_get_p2p_ie(pnetwork->network.IEs+12, pnetwork->network.IELength-12, NULL, NULL))
  355. //{
  356. // DBG_8192C("%s, got p2p_ie\n", __func__);
  357. //}
  358. //#endif
  359. #if 1
  360. bss = cfg80211_inform_bss_frame(wiphy, notify_channel, (struct ieee80211_mgmt *)buf,
  361. len, notify_signal, GFP_ATOMIC);
  362. #else
  363. bss = cfg80211_inform_bss(wiphy, notify_channel, (const u8 *)pnetwork->network.MacAddress,
  364. notify_timestamp, notify_capability, notify_interval, notify_ie,
  365. notify_ielen, notify_signal, GFP_ATOMIC/*GFP_KERNEL*/);
  366. #endif
  367. if (unlikely(!bss)) {
  368. DBG_8192C("rtw_cfg80211_inform_bss error\n");
  369. return -EINVAL;
  370. }
  371. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38))
  372. #ifndef COMPAT_KERNEL_RELEASE
  373. //patch for cfg80211, update beacon ies to information_elements
  374. if (pnetwork->network.Reserved[0] == 1) { // WIFI_BEACON
  375. if(bss->len_information_elements != bss->len_beacon_ies)
  376. {
  377. bss->information_elements = bss->beacon_ies;
  378. bss->len_information_elements = bss->len_beacon_ies;
  379. }
  380. }
  381. #endif //COMPAT_KERNEL_RELEASE
  382. #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)
  383. /*
  384. {
  385. if( bss->information_elements == bss->proberesp_ies)
  386. {
  387. if( bss->len_information_elements != bss->len_proberesp_ies)
  388. {
  389. DBG_8192C("error!, len_information_elements != bss->len_proberesp_ies\n");
  390. }
  391. }
  392. else if(bss->len_information_elements < bss->len_beacon_ies)
  393. {
  394. bss->information_elements = bss->beacon_ies;
  395. bss->len_information_elements = bss->len_beacon_ies;
  396. }
  397. }
  398. */
  399. cfg80211_put_bss(bss);
  400. exit:
  401. return ret;
  402. }
  403. void rtw_cfg80211_indicate_connect(_adapter *padapter)
  404. {
  405. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  406. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  407. struct wireless_dev *pwdev = padapter->rtw_wdev;
  408. #ifdef CONFIG_P2P
  409. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  410. #endif
  411. DBG_8192C("%s(padapter=%p)\n", __func__, padapter);
  412. if (pwdev->iftype != NL80211_IFTYPE_STATION
  413. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  414. && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT
  415. #endif
  416. ) {
  417. return;
  418. }
  419. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  420. return;
  421. #ifdef CONFIG_P2P
  422. if(pwdinfo->driver_interface == DRIVER_CFG80211 )
  423. {
  424. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  425. {
  426. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  427. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  428. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  429. DBG_8192C("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
  430. }
  431. }
  432. #endif //CONFIG_P2P
  433. #ifdef CONFIG_LAYER2_ROAMING
  434. if (rtw_to_roaming(padapter) > 0) {
  435. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39) || defined(COMPAT_KERNEL_RELEASE)
  436. struct wiphy *wiphy = pwdev->wiphy;
  437. struct ieee80211_channel *notify_channel;
  438. u32 freq;
  439. u16 channel = cur_network->network.Configuration.DSConfig;
  440. if (channel <= RTW_CH_MAX_2G_CHANNEL)
  441. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
  442. else
  443. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
  444. notify_channel = ieee80211_get_channel(wiphy, freq);
  445. #endif
  446. DBG_871X("%s call cfg80211_roamed\n", __FUNCTION__);
  447. cfg80211_roamed(padapter->pnetdev
  448. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39) || defined(COMPAT_KERNEL_RELEASE)
  449. , notify_channel
  450. #endif
  451. , cur_network->network.MacAddress
  452. , pmlmepriv->assoc_req+sizeof(struct rtw_ieee80211_hdr_3addr)+2
  453. , pmlmepriv->assoc_req_len-sizeof(struct rtw_ieee80211_hdr_3addr)-2
  454. , pmlmepriv->assoc_rsp+sizeof(struct rtw_ieee80211_hdr_3addr)+6
  455. , pmlmepriv->assoc_rsp_len-sizeof(struct rtw_ieee80211_hdr_3addr)-6
  456. , GFP_ATOMIC);
  457. }
  458. else
  459. #endif
  460. {
  461. DBG_8192C("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
  462. cfg80211_connect_result(padapter->pnetdev, cur_network->network.MacAddress
  463. , pmlmepriv->assoc_req+sizeof(struct rtw_ieee80211_hdr_3addr)+2
  464. , pmlmepriv->assoc_req_len-sizeof(struct rtw_ieee80211_hdr_3addr)-2
  465. , pmlmepriv->assoc_rsp+sizeof(struct rtw_ieee80211_hdr_3addr)+6
  466. , pmlmepriv->assoc_rsp_len-sizeof(struct rtw_ieee80211_hdr_3addr)-6
  467. , WLAN_STATUS_SUCCESS, GFP_ATOMIC);
  468. DBG_8192C("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
  469. }
  470. }
  471. void rtw_cfg80211_indicate_disconnect(_adapter *padapter)
  472. {
  473. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  474. struct wireless_dev *pwdev = padapter->rtw_wdev;
  475. #ifdef CONFIG_P2P
  476. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  477. #endif
  478. DBG_8192C("%s(padapter=%p)\n", __func__, padapter);
  479. if (pwdev->iftype != NL80211_IFTYPE_STATION
  480. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  481. && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT
  482. #endif
  483. ) {
  484. return;
  485. }
  486. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  487. return;
  488. #ifdef CONFIG_P2P
  489. if( pwdinfo->driver_interface == DRIVER_CFG80211 )
  490. {
  491. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  492. {
  493. _cancel_timer_ex( &pwdinfo->find_phase_timer );
  494. _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
  495. _cancel_timer_ex( &pwdinfo->pre_tx_scan_timer);
  496. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  497. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  498. DBG_8192C("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
  499. }
  500. }
  501. #endif //CONFIG_P2P
  502. if (!padapter->mlmepriv.not_indic_disco) {
  503. DBG_8192C("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
  504. if(pwdev->sme_state==CFG80211_SME_CONNECTING)
  505. cfg80211_connect_result(padapter->pnetdev, NULL, NULL, 0, NULL, 0,
  506. WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_ATOMIC/*GFP_KERNEL*/);
  507. else if(pwdev->sme_state==CFG80211_SME_CONNECTED)
  508. cfg80211_disconnected(padapter->pnetdev, 0, NULL, 0, GFP_ATOMIC);
  509. //else
  510. //DBG_8192C("pwdev->sme_state=%d\n", pwdev->sme_state);
  511. DBG_8192C("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
  512. }
  513. }
  514. #ifdef CONFIG_AP_MODE
  515. static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
  516. {
  517. int ret = 0;
  518. u32 wep_key_idx, wep_key_len,wep_total_len;
  519. struct sta_info *psta = NULL, *pbcmc_sta = NULL;
  520. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  521. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  522. struct security_priv* psecuritypriv=&(padapter->securitypriv);
  523. struct sta_priv *pstapriv = &padapter->stapriv;
  524. DBG_8192C("%s\n", __FUNCTION__);
  525. param->u.crypt.err = 0;
  526. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  527. //sizeof(struct ieee_param) = 64 bytes;
  528. //if (param_len != (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len)
  529. if (param_len != sizeof(struct ieee_param) + param->u.crypt.key_len)
  530. {
  531. ret = -EINVAL;
  532. goto exit;
  533. }
  534. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  535. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  536. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  537. {
  538. if (param->u.crypt.idx >= WEP_KEYS)
  539. {
  540. ret = -EINVAL;
  541. goto exit;
  542. }
  543. }
  544. else
  545. {
  546. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  547. if(!psta)
  548. {
  549. //ret = -EINVAL;
  550. DBG_8192C("rtw_set_encryption(), sta has already been removed or never been added\n");
  551. goto exit;
  552. }
  553. }
  554. if (strcmp(param->u.crypt.alg, "none") == 0 && (psta==NULL))
  555. {
  556. //todo:clear default encryption keys
  557. DBG_8192C("clear default encryption keys, keyid=%d\n", param->u.crypt.idx);
  558. goto exit;
  559. }
  560. if (strcmp(param->u.crypt.alg, "WEP") == 0 && (psta==NULL))
  561. {
  562. DBG_8192C("r871x_set_encryption, crypt.alg = WEP\n");
  563. wep_key_idx = param->u.crypt.idx;
  564. wep_key_len = param->u.crypt.key_len;
  565. DBG_8192C("r871x_set_encryption, wep_key_idx=%d, len=%d\n", wep_key_idx, wep_key_len);
  566. if((wep_key_idx >= WEP_KEYS) || (wep_key_len<=0))
  567. {
  568. ret = -EINVAL;
  569. goto exit;
  570. }
  571. if (wep_key_len > 0)
  572. {
  573. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  574. }
  575. if (psecuritypriv->bWepDefaultKeyIdxSet == 0)
  576. {
  577. //wep default key has not been set, so use this key index as default key.
  578. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  579. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  580. psecuritypriv->dot11PrivacyAlgrthm=_WEP40_;
  581. psecuritypriv->dot118021XGrpPrivacy=_WEP40_;
  582. if(wep_key_len == 13)
  583. {
  584. psecuritypriv->dot11PrivacyAlgrthm=_WEP104_;
  585. psecuritypriv->dot118021XGrpPrivacy=_WEP104_;
  586. }
  587. psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
  588. }
  589. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
  590. psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
  591. rtw_ap_set_wep_key(padapter, param->u.crypt.key, wep_key_len, wep_key_idx, 1);
  592. goto exit;
  593. }
  594. if(!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) // //group key
  595. {
  596. if(param->u.crypt.set_tx == 0) //group key
  597. {
  598. if(strcmp(param->u.crypt.alg, "WEP") == 0)
  599. {
  600. DBG_8192C("%s, set group_key, WEP\n", __FUNCTION__);
  601. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  602. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  603. if(param->u.crypt.key_len==13)
  604. {
  605. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  606. }
  607. }
  608. else if(strcmp(param->u.crypt.alg, "TKIP") == 0)
  609. {
  610. DBG_8192C("%s, set group_key, TKIP\n", __FUNCTION__);
  611. psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
  612. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  613. //DEBUG_ERR("set key length :param->u.crypt.key_len=%d\n", param->u.crypt.key_len);
  614. //set mic key
  615. _rtw_memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  616. _rtw_memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  617. psecuritypriv->busetkipkey = _TRUE;
  618. }
  619. else if(strcmp(param->u.crypt.alg, "CCMP") == 0)
  620. {
  621. DBG_8192C("%s, set group_key, CCMP\n", __FUNCTION__);
  622. psecuritypriv->dot118021XGrpPrivacy = _AES_;
  623. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  624. }
  625. else
  626. {
  627. DBG_8192C("%s, set group_key, none\n", __FUNCTION__);
  628. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  629. }
  630. psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
  631. psecuritypriv->binstallGrpkey = _TRUE;
  632. psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;//!!!
  633. rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
  634. pbcmc_sta=rtw_get_bcmc_stainfo(padapter);
  635. if(pbcmc_sta)
  636. {
  637. pbcmc_sta->ieee8021x_blocked = _FALSE;
  638. pbcmc_sta->dot118021XPrivacy= psecuritypriv->dot118021XGrpPrivacy;//rx will use bmc_sta's dot118021XPrivacy
  639. }
  640. }
  641. goto exit;
  642. }
  643. if(psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) // psk/802_1x
  644. {
  645. if(check_fwstate(pmlmepriv, WIFI_AP_STATE))
  646. {
  647. if(param->u.crypt.set_tx ==1) //pairwise key
  648. {
  649. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  650. if(strcmp(param->u.crypt.alg, "WEP") == 0)
  651. {
  652. DBG_8192C("%s, set pairwise key, WEP\n", __FUNCTION__);
  653. psta->dot118021XPrivacy = _WEP40_;
  654. if(param->u.crypt.key_len==13)
  655. {
  656. psta->dot118021XPrivacy = _WEP104_;
  657. }
  658. }
  659. else if(strcmp(param->u.crypt.alg, "TKIP") == 0)
  660. {
  661. DBG_8192C("%s, set pairwise key, TKIP\n", __FUNCTION__);
  662. psta->dot118021XPrivacy = _TKIP_;
  663. //DEBUG_ERR("set key length :param->u.crypt.key_len=%d\n", param->u.crypt.key_len);
  664. //set mic key
  665. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  666. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  667. psecuritypriv->busetkipkey = _TRUE;
  668. }
  669. else if(strcmp(param->u.crypt.alg, "CCMP") == 0)
  670. {
  671. DBG_8192C("%s, set pairwise key, CCMP\n", __FUNCTION__);
  672. psta->dot118021XPrivacy = _AES_;
  673. }
  674. else
  675. {
  676. DBG_8192C("%s, set pairwise key, none\n", __FUNCTION__);
  677. psta->dot118021XPrivacy = _NO_PRIVACY_;
  678. }
  679. rtw_ap_set_pairwise_key(padapter, psta);
  680. psta->ieee8021x_blocked = _FALSE;
  681. psta->bpairwise_key_installed = _TRUE;
  682. }
  683. else//group key???
  684. {
  685. if(strcmp(param->u.crypt.alg, "WEP") == 0)
  686. {
  687. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  688. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  689. if(param->u.crypt.key_len==13)
  690. {
  691. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  692. }
  693. }
  694. else if(strcmp(param->u.crypt.alg, "TKIP") == 0)
  695. {
  696. psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
  697. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  698. //DEBUG_ERR("set key length :param->u.crypt.key_len=%d\n", param->u.crypt.key_len);
  699. //set mic key
  700. _rtw_memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  701. _rtw_memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  702. psecuritypriv->busetkipkey = _TRUE;
  703. }
  704. else if(strcmp(param->u.crypt.alg, "CCMP") == 0)
  705. {
  706. psecuritypriv->dot118021XGrpPrivacy = _AES_;
  707. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  708. }
  709. else
  710. {
  711. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  712. }
  713. psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
  714. psecuritypriv->binstallGrpkey = _TRUE;
  715. psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;//!!!
  716. rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
  717. pbcmc_sta=rtw_get_bcmc_stainfo(padapter);
  718. if(pbcmc_sta)
  719. {
  720. pbcmc_sta->ieee8021x_blocked = _FALSE;
  721. pbcmc_sta->dot118021XPrivacy= psecuritypriv->dot118021XGrpPrivacy;//rx will use bmc_sta's dot118021XPrivacy
  722. }
  723. }
  724. }
  725. }
  726. exit:
  727. return ret;
  728. }
  729. #endif
  730. static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
  731. {
  732. int ret = 0;
  733. u32 wep_key_idx, wep_key_len,wep_total_len;
  734. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  735. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  736. struct security_priv *psecuritypriv = &padapter->securitypriv;
  737. #ifdef CONFIG_P2P
  738. struct wifidirect_info* pwdinfo = &padapter->wdinfo;
  739. #endif //CONFIG_P2P
  740. _func_enter_;
  741. DBG_8192C("%s\n", __func__);
  742. param->u.crypt.err = 0;
  743. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  744. if (param_len < (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len)
  745. {
  746. ret = -EINVAL;
  747. goto exit;
  748. }
  749. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  750. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  751. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  752. {
  753. if (param->u.crypt.idx >= WEP_KEYS)
  754. {
  755. ret = -EINVAL;
  756. goto exit;
  757. }
  758. } else {
  759. #ifdef CONFIG_WAPI_SUPPORT
  760. if (strcmp(param->u.crypt.alg, "SMS4"))
  761. #endif
  762. {
  763. ret = -EINVAL;
  764. goto exit;
  765. }
  766. }
  767. if (strcmp(param->u.crypt.alg, "WEP") == 0)
  768. {
  769. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("wpa_set_encryption, crypt.alg = WEP\n"));
  770. DBG_8192C("wpa_set_encryption, crypt.alg = WEP\n");
  771. wep_key_idx = param->u.crypt.idx;
  772. wep_key_len = param->u.crypt.key_len;
  773. if ((wep_key_idx > WEP_KEYS) || (wep_key_len <= 0))
  774. {
  775. ret = -EINVAL;
  776. goto exit;
  777. }
  778. if (psecuritypriv->bWepDefaultKeyIdxSet == 0)
  779. {
  780. //wep default key has not been set, so use this key index as default key.
  781. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  782. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  783. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  784. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  785. if(wep_key_len==13)
  786. {
  787. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  788. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  789. }
  790. psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
  791. }
  792. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
  793. psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
  794. rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0);
  795. goto exit;
  796. }
  797. if(padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) // 802_1x
  798. {
  799. struct sta_info * psta,*pbcmc_sta;
  800. struct sta_priv * pstapriv = &padapter->stapriv;
  801. //DBG_8192C("%s, : dot11AuthAlgrthm == dot11AuthAlgrthm_8021X \n", __func__);
  802. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == _TRUE) //sta mode
  803. {
  804. psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
  805. if (psta == NULL) {
  806. //DEBUG_ERR( ("Set wpa_set_encryption: Obtain Sta_info fail \n"));
  807. DBG_8192C("%s, : Obtain Sta_info fail \n", __func__);
  808. }
  809. else
  810. {
  811. //Jeff: don't disable ieee8021x_blocked while clearing key
  812. if (strcmp(param->u.crypt.alg, "none") != 0)
  813. psta->ieee8021x_blocked = _FALSE;
  814. if((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)||
  815. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  816. {
  817. psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  818. }
  819. if(param->u.crypt.set_tx ==1)//pairwise key
  820. {
  821. DBG_8192C("%s, : param->u.crypt.set_tx ==1 \n", __func__);
  822. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  823. if(strcmp(param->u.crypt.alg, "TKIP") == 0)//set mic key
  824. {
  825. //DEBUG_ERR(("\nset key length :param->u.crypt.key_len=%d\n", param->u.crypt.key_len));
  826. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  827. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  828. padapter->securitypriv.busetkipkey=_FALSE;
  829. //_set_timer(&padapter->securitypriv.tkip_timer, 50);
  830. }
  831. //DEBUG_ERR((" param->u.crypt.key_len=%d\n",param->u.crypt.key_len));
  832. DBG_871X(" ~~~~set sta key:unicastkey\n");
  833. rtw_setstakey_cmd(padapter, (unsigned char *)psta, _TRUE);
  834. }
  835. else//group key
  836. {
  837. _rtw_memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key,(param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  838. _rtw_memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[16]),8);
  839. _rtw_memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[24]),8);
  840. padapter->securitypriv.binstallGrpkey = _TRUE;
  841. //DEBUG_ERR((" param->u.crypt.key_len=%d\n", param->u.crypt.key_len));
  842. DBG_871X(" ~~~~set sta key:groupkey\n");
  843. padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
  844. rtw_set_key(padapter,&padapter->securitypriv,param->u.crypt.idx, 1);
  845. #ifdef CONFIG_P2P
  846. if(pwdinfo->driver_interface == DRIVER_CFG80211 )
  847. {
  848. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
  849. {
  850. rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_DONE);
  851. }
  852. }
  853. #endif //CONFIG_P2P
  854. }
  855. }
  856. pbcmc_sta=rtw_get_bcmc_stainfo(padapter);
  857. if(pbcmc_sta==NULL)
  858. {
  859. //DEBUG_ERR( ("Set OID_802_11_ADD_KEY: bcmc stainfo is null \n"));
  860. }
  861. else
  862. {
  863. //Jeff: don't disable ieee8021x_blocked while clearing key
  864. if (strcmp(param->u.crypt.alg, "none") != 0)
  865. pbcmc_sta->ieee8021x_blocked = _FALSE;
  866. if((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)||
  867. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  868. {
  869. pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  870. }
  871. }
  872. }
  873. else if(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) //adhoc mode
  874. {
  875. }
  876. }
  877. #ifdef CONFIG_WAPI_SUPPORT
  878. if (strcmp(param->u.crypt.alg, "SMS4") == 0)
  879. {
  880. PRT_WAPI_T pWapiInfo = &padapter->wapiInfo;
  881. PRT_WAPI_STA_INFO pWapiSta;
  882. u8 WapiASUEPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  883. u8 WapiAEPNInitialValueSrc[16] = {0x37,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  884. u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  885. if(param->u.crypt.set_tx == 1)
  886. {
  887. list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) {
  888. if(_rtw_memcmp(pWapiSta->PeerMacAddr,param->sta_addr,6))
  889. {
  890. _rtw_memcpy(pWapiSta->lastTxUnicastPN,WapiASUEPNInitialValueSrc,16);
  891. pWapiSta->wapiUsk.bSet = true;
  892. _rtw_memcpy(pWapiSta->wapiUsk.dataKey,param->u.crypt.key,16);
  893. _rtw_memcpy(pWapiSta->wapiUsk.micKey,param->u.crypt.key+16,16);
  894. pWapiSta->wapiUsk.keyId = param->u.crypt.idx ;
  895. pWapiSta->wapiUsk.bTxEnable = true;
  896. _rtw_memcpy(pWapiSta->lastRxUnicastPNBEQueue,WapiAEPNInitialValueSrc,16);
  897. _rtw_memcpy(pWapiSta->lastRxUnicastPNBKQueue,WapiAEPNInitialValueSrc,16);
  898. _rtw_memcpy(pWapiSta->lastRxUnicastPNVIQueue,WapiAEPNInitialValueSrc,16);
  899. _rtw_memcpy(pWapiSta->lastRxUnicastPNVOQueue,WapiAEPNInitialValueSrc,16);
  900. _rtw_memcpy(pWapiSta->lastRxUnicastPN,WapiAEPNInitialValueSrc,16);
  901. pWapiSta->wapiUskUpdate.bTxEnable = false;
  902. pWapiSta->wapiUskUpdate.bSet = false;
  903. if (psecuritypriv->sw_encrypt== false || psecuritypriv->sw_decrypt == false)
  904. {
  905. //set unicast key for ASUE
  906. rtw_wapi_set_key(padapter, &pWapiSta->wapiUsk, pWapiSta, false, false);
  907. }
  908. }
  909. }
  910. }
  911. else
  912. {
  913. list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) {
  914. if(_rtw_memcmp(pWapiSta->PeerMacAddr,get_bssid(pmlmepriv),6))
  915. {
  916. pWapiSta->wapiMsk.bSet = true;
  917. _rtw_memcpy(pWapiSta->wapiMsk.dataKey,param->u.crypt.key,16);
  918. _rtw_memcpy(pWapiSta->wapiMsk.micKey,param->u.crypt.key+16,16);
  919. pWapiSta->wapiMsk.keyId = param->u.crypt.idx ;
  920. pWapiSta->wapiMsk.bTxEnable = false;
  921. if(!pWapiSta->bSetkeyOk)
  922. pWapiSta->bSetkeyOk = true;
  923. pWapiSta->bAuthenticateInProgress = false;
  924. _rtw_memcpy(pWapiSta->lastRxMulticastPN, WapiAEMultiCastPNInitialValueSrc, 16);
  925. if (psecuritypriv->sw_decrypt == false)
  926. {
  927. //set rx broadcast key for ASUE
  928. rtw_wapi_set_key(padapter, &pWapiSta->wapiMsk, pWapiSta, true, false);
  929. }
  930. }
  931. }
  932. }
  933. }
  934. #endif
  935. exit:
  936. DBG_8192C("%s, ret=%d\n", __func__, ret);
  937. _func_exit_;
  938. return ret;
  939. }
  940. static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
  941. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  942. u8 key_index, bool pairwise, const u8 *mac_addr,
  943. #else // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
  944. u8 key_index, const u8 *mac_addr,
  945. #endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
  946. struct key_params *params)
  947. {
  948. char *alg_name;
  949. u32 param_len;
  950. struct ieee_param *param = NULL;
  951. int ret=0;
  952. struct wireless_dev *rtw_wdev = wiphy_to_wdev(wiphy);
  953. _adapter *padapter = wiphy_to_adapter(wiphy);
  954. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  955. DBG_871X(FUNC_NDEV_FMT" adding key for %pM\n", FUNC_NDEV_ARG(ndev), mac_addr);
  956. DBG_871X("cipher=0x%x\n", params->cipher);
  957. DBG_871X("key_len=0x%x\n", params->key_len);
  958. DBG_871X("seq_len=0x%x\n", params->seq_len);
  959. DBG_871X("key_index=%d\n", key_index);
  960. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  961. DBG_871X("pairwise=%d\n", pairwise);
  962. #endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
  963. param_len = sizeof(struct ieee_param) + params->key_len;
  964. param = (struct ieee_param *)rtw_malloc(param_len);
  965. if (param == NULL)
  966. return -1;
  967. _rtw_memset(param, 0, param_len);
  968. param->cmd = IEEE_CMD_SET_ENCRYPTION;
  969. _rtw_memset(param->sta_addr, 0xff, ETH_ALEN);
  970. switch (params->cipher) {
  971. case IW_AUTH_CIPHER_NONE:
  972. //todo: remove key
  973. //remove = 1;
  974. alg_name = "none";
  975. break;
  976. case WLAN_CIPHER_SUITE_WEP40:
  977. case WLAN_CIPHER_SUITE_WEP104:
  978. alg_name = "WEP";
  979. break;
  980. case WLAN_CIPHER_SUITE_TKIP:
  981. alg_name = "TKIP";
  982. break;
  983. case WLAN_CIPHER_SUITE_CCMP:
  984. alg_name = "CCMP";
  985. break;
  986. #ifdef CONFIG_WAPI_SUPPORT
  987. case WLAN_CIPHER_SUITE_SMS4:
  988. alg_name= "SMS4";
  989. if(pairwise == NL80211_KEYTYPE_PAIRWISE) {
  990. if (key_index != 0 && key_index != 1) {
  991. ret = -ENOTSUPP;
  992. goto addkey_end;
  993. }
  994. _rtw_memcpy((void*)param->sta_addr, (void*)mac_addr, ETH_ALEN);
  995. } else {
  996. DBG_871X("mac_addr is null \n");
  997. }
  998. DBG_871X("rtw_wx_set_enc_ext: SMS4 case \n");
  999. break;
  1000. #endif
  1001. default:
  1002. ret = -ENOTSUPP;
  1003. goto addkey_end;
  1004. }
  1005. strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
  1006. if (!mac_addr || is_broadcast_ether_addr(mac_addr))
  1007. {
  1008. param->u.crypt.set_tx = 0; //for wpa/wpa2 group key
  1009. } else {
  1010. param->u.crypt.set_tx = 1; //for wpa/wpa2 pairwise key
  1011. }
  1012. //param->u.crypt.idx = key_index - 1;
  1013. param->u.crypt.idx = key_index;
  1014. if (params->seq_len && params->seq)
  1015. {
  1016. _rtw_memcpy(param->u.crypt.seq, params->seq, params->seq_len);
  1017. }
  1018. if(params->key_len && params->key)
  1019. {
  1020. param->u.crypt.key_len = params->key_len;
  1021. _rtw_memcpy(param->u.crypt.key, params->key, params->key_len);
  1022. }
  1023. if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
  1024. {
  1025. ret = rtw_cfg80211_set_encryption(ndev, param, param_len);
  1026. }
  1027. else if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1028. {
  1029. #ifdef CONFIG_AP_MODE
  1030. if(mac_addr)
  1031. _rtw_memcpy(param->sta_addr, (void*)mac_addr, ETH_ALEN);
  1032. ret = rtw_cfg80211_ap_set_encryption(ndev, param, param_len);
  1033. #endif
  1034. }
  1035. else
  1036. {
  1037. DBG_8192C("error! fw_state=0x%x, iftype=%d\n", pmlmepriv->fw_state, rtw_wdev->iftype);
  1038. }
  1039. addkey_end:
  1040. if(param)
  1041. {
  1042. rtw_mfree((u8*)param, param_len);
  1043. }
  1044. return ret;
  1045. }
  1046. static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev,
  1047. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  1048. u8 key_index, bool pairwise, const u8 *mac_addr,
  1049. #else // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
  1050. u8 key_index, const u8 *mac_addr,
  1051. #endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
  1052. void *cookie,
  1053. void (*callback)(void *cookie,
  1054. struct key_params*))
  1055. {
  1056. #if 0
  1057. struct iwm_priv *iwm = ndev_to_iwm(ndev);
  1058. struct iwm_key *key = &iwm->keys[key_index];
  1059. struct key_params params;
  1060. IWM_DBG_WEXT(iwm, DBG, "Getting key %d\n", key_index);
  1061. memset(&params, 0, sizeof(params));
  1062. params.cipher = key->cipher;
  1063. params.key_len = key->key_len;
  1064. params.seq_len = key->seq_len;
  1065. params.seq = key->seq;
  1066. params.key = key->key;
  1067. callback(cookie, &params);
  1068. return key->key_len ? 0 : -ENOENT;
  1069. #endif
  1070. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  1071. return 0;
  1072. }
  1073. static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev,
  1074. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  1075. u8 key_index, bool pairwise, const u8 *mac_addr)
  1076. #else // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
  1077. u8 key_index, const u8 *mac_addr)
  1078. #endif // (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
  1079. {
  1080. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1081. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1082. DBG_871X(FUNC_NDEV_FMT" key_index=%d\n", FUNC_NDEV_ARG(ndev), key_index);
  1083. if (key_index == psecuritypriv->dot11PrivacyKeyIndex)
  1084. {
  1085. //clear the flag of wep default key set.
  1086. psecuritypriv->bWepDefaultKeyIdxSet = 0;
  1087. }
  1088. return 0;
  1089. }
  1090. static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
  1091. struct net_device *ndev, u8 key_index
  1092. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
  1093. , bool unicast, bool multicast
  1094. #endif
  1095. )
  1096. {
  1097. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1098. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1099. DBG_871X(FUNC_NDEV_FMT" key_index=%d"
  1100. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
  1101. ", unicast=%d, multicast=%d"
  1102. #endif
  1103. ".\n", FUNC_NDEV_ARG(ndev), key_index
  1104. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
  1105. , unicast, multicast
  1106. #endif
  1107. );
  1108. if ((key_index < WEP_KEYS) && ((psecuritypriv->dot11PrivacyAlgrthm == _WEP40_) || (psecuritypriv->dot11PrivacyAlgrthm == _WEP104_))) //set wep default key
  1109. {
  1110. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1111. psecuritypriv->dot11PrivacyKeyIndex = key_index;
  1112. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  1113. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  1114. if (psecuritypriv->dot11DefKeylen[key_index] == 13)
  1115. {
  1116. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  1117. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  1118. }
  1119. psecuritypriv->bWepDefaultKeyIdxSet = 1; //set the flag to represent that wep default key has been set
  1120. }
  1121. return 0;
  1122. }
  1123. static int cfg80211_rtw_get_station(struct wiphy *wiphy,
  1124. struct net_device *ndev,
  1125. u8 *mac, struct station_info *sinfo)
  1126. {
  1127. int ret = 0;
  1128. _adapter *padapter = wiphy_to_adapter(wiphy);
  1129. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1130. struct sta_info *psta = NULL;
  1131. struct sta_priv *pstapriv = &padapter->stapriv;
  1132. sinfo->filled = 0;
  1133. if (!mac) {
  1134. DBG_871X(FUNC_NDEV_FMT" mac==%p\n", FUNC_NDEV_ARG(ndev), mac);
  1135. ret = -ENOENT;
  1136. goto exit;
  1137. }
  1138. psta = rtw_get_stainfo(pstapriv, mac);
  1139. if (psta == NULL) {
  1140. DBG_8192C("%s, sta_info is null\n", __func__);
  1141. ret = -ENOENT;
  1142. goto exit;
  1143. }
  1144. #ifdef CONFIG_DEBUG_CFG80211
  1145. DBG_871X(FUNC_NDEV_FMT" mac="MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
  1146. #endif
  1147. //for infra./P2PClient mode
  1148. if( check_fwstate(pmlmepriv, WIFI_STATION_STATE)
  1149. && check_fwstate(pmlmepriv, _FW_LINKED)
  1150. )
  1151. {
  1152. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  1153. if (_rtw_memcmp(mac, cur_network->network.MacAddress, ETH_ALEN) == _FALSE) {
  1154. DBG_871X("%s, mismatch bssid="MAC_FMT"\n", __func__, MAC_ARG(cur_network->network.MacAddress));
  1155. ret = -ENOENT;
  1156. goto exit;
  1157. }
  1158. sinfo->filled |= STATION_INFO_SIGNAL;
  1159. sinfo->signal = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);
  1160. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1161. sinfo->txrate.legacy = rtw_get_cur_max_rate(padapter);
  1162. sinfo->filled |= STATION_INFO_RX_PACKETS;
  1163. sinfo->rx_packets = sta_rx_data_pkts(psta);
  1164. sinfo->filled |= STATION_INFO_TX_PACKETS;
  1165. sinfo->tx_packets = psta->sta_stats.tx_pkts;
  1166. }
  1167. //for Ad-Hoc/AP mode
  1168. if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)
  1169. ||check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)
  1170. ||check_fwstate(pmlmepriv, WIFI_AP_STATE))
  1171. && check_fwstate(pmlmepriv, _FW_LINKED)
  1172. )
  1173. {
  1174. //TODO: should acquire station info...
  1175. }
  1176. exit:
  1177. return ret;
  1178. }
  1179. extern int netdev_open(struct net_device *pnetdev);
  1180. #ifdef CONFIG_CONCURRENT_MODE
  1181. extern int netdev_if2_open(struct net_device *pnetdev);
  1182. #endif
  1183. /*
  1184. enum nl80211_iftype {
  1185. NL80211_IFTYPE_UNSPECIFIED,
  1186. NL80211_IFTYPE_ADHOC, //1
  1187. NL80211_IFTYPE_STATION, //2
  1188. NL80211_IFTYPE_AP, //3
  1189. NL80211_IFTYPE_AP_VLAN,
  1190. NL80211_IFTYPE_WDS,
  1191. NL80211_IFTYPE_MONITOR, //6
  1192. NL80211_IFTYPE_MESH_POINT,
  1193. NL80211_IFTYPE_P2P_CLIENT, //8
  1194. NL80211_IFTYPE_P2P_GO, //9
  1195. //keep last
  1196. NUM_NL80211_IFTYPES,
  1197. NL80211_IFTYPE_MAX = NUM_NL80211_IFTYPES - 1
  1198. };
  1199. */
  1200. static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
  1201. struct net_device *ndev,
  1202. enum nl80211_iftype type, u32 *flags,
  1203. struct vif_params *params)
  1204. {
  1205. enum nl80211_iftype old_type;
  1206. NDIS_802_11_NETWORK_INFRASTRUCTURE networkType ;
  1207. _adapter *padapter = wiphy_to_adapter(wiphy);
  1208. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1209. struct wireless_dev *rtw_wdev = wiphy_to_wdev(wiphy);
  1210. #ifdef CONFIG_P2P
  1211. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  1212. #endif
  1213. int ret = 0;
  1214. u8 change = _FALSE;
  1215. #ifdef CONFIG_CONCURRENT_MODE
  1216. if(padapter->adapter_type == SECONDARY_ADAPTER)
  1217. {
  1218. DBG_871X(FUNC_NDEV_FMT" call netdev_if2_open\n", FUNC_NDEV_ARG(ndev));
  1219. if(netdev_if2_open(ndev) != 0) {
  1220. ret= -EPERM;
  1221. goto exit;
  1222. }
  1223. }
  1224. else if(padapter->adapter_type == PRIMARY_ADAPTER)
  1225. #endif //CONFIG_CONCURRENT_MODE
  1226. {
  1227. DBG_871X(FUNC_NDEV_FMT" call netdev_open\n", FUNC_NDEV_ARG(ndev));
  1228. if(netdev_open(ndev) != 0) {
  1229. ret= -EPERM;
  1230. goto exit;
  1231. }
  1232. }
  1233. if(_FAIL == rtw_pwr_wakeup(padapter)) {
  1234. ret= -EPERM;
  1235. goto exit;
  1236. }
  1237. old_type = rtw_wdev->iftype;
  1238. DBG_871X(FUNC_NDEV_FMT" old_iftype=%d, new_iftype=%d\n",
  1239. FUNC_NDEV_ARG(ndev), old_type, type);
  1240. if(old_type != type)
  1241. {
  1242. change = _TRUE;
  1243. pmlmeext->action_public_rxseq = 0xffff;
  1244. pmlmeext->action_public_dialog_token = 0xff;
  1245. }
  1246. switch (type) {
  1247. case NL80211_IFTYPE_ADHOC:
  1248. networkType = Ndis802_11IBSS;
  1249. break;
  1250. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE))
  1251. case NL80211_IFTYPE_P2P_CLIENT:
  1252. #endif
  1253. case NL80211_IFTYPE_STATION:
  1254. networkType = Ndis802_11Infrastructure;
  1255. #ifdef CONFIG_P2P
  1256. if(pwdinfo->driver_interface == DRIVER_CFG80211 )
  1257. {
  1258. if(change && rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
  1259. {
  1260. _cancel_timer_ex( &pwdinfo->find_phase_timer );
  1261. _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
  1262. _cancel_timer_ex( &pwdinfo->pre_tx_scan_timer);
  1263. //it means remove GO and change mode from AP(GO) to station(P2P DEVICE)
  1264. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  1265. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  1266. DBG_8192C("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
  1267. }
  1268. }
  1269. #endif //CONFIG_P2P
  1270. break;
  1271. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE))
  1272. case NL80211_IFTYPE_P2P_GO:
  1273. #endif
  1274. case NL80211_IFTYPE_AP:
  1275. networkType = Ndis802_11APMode;
  1276. #ifdef CONFIG_P2P
  1277. if(pwdinfo->driver_interface == DRIVER_CFG80211 )
  1278. {
  1279. if(change && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  1280. {
  1281. //it means P2P Group created, we will be GO and change mode from P2P DEVICE to AP(GO)
  1282. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  1283. }
  1284. }
  1285. #endif //CONFIG_P2P
  1286. break;
  1287. default:
  1288. return -EOPNOTSUPP;
  1289. }
  1290. rtw_wdev->iftype = type;
  1291. if (rtw_set_802_11_infrastructure_mode(padapter, networkType) ==_FALSE)
  1292. {
  1293. rtw_wdev->iftype = old_type;
  1294. ret = -EPERM;
  1295. goto exit;
  1296. }
  1297. rtw_setopmode_cmd(padapter, networkType);
  1298. exit:
  1299. return ret;
  1300. }
  1301. void rtw_cfg80211_indicate_scan_done(struct rtw_wdev_priv *pwdev_priv, bool aborted)
  1302. {
  1303. _irqL irqL;
  1304. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  1305. if(pwdev_priv->scan_request != NULL)
  1306. {
  1307. //struct cfg80211_scan_request *scan_request = pwdev_priv->scan_request;
  1308. #ifdef CONFIG_DEBUG_CFG80211
  1309. DBG_871X("%s with scan req\n", __FUNCTION__);
  1310. #endif
  1311. //avoid WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req);
  1312. //if(scan_request == wiphy_to_dev(scan_request->wiphy)->scan_req)
  1313. if(pwdev_priv->scan_request->wiphy != pwdev_priv->rtw_wdev->wiphy)
  1314. {
  1315. DBG_8192C("error wiphy compare\n");
  1316. }
  1317. else
  1318. {
  1319. cfg80211_scan_done(pwdev_priv->scan_request, aborted);
  1320. }
  1321. pwdev_priv->scan_request = NULL;
  1322. } else {
  1323. #ifdef CONFIG_DEBUG_CFG80211
  1324. DBG_871X("%s without scan req\n", __FUNCTION__);
  1325. #endif
  1326. }
  1327. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  1328. }
  1329. void rtw_cfg80211_surveydone_event_callback(_adapter *padapter)
  1330. {
  1331. _irqL irqL;
  1332. _list *plist, *phead;
  1333. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1334. _queue *queue = &(pmlmepriv->scanned_queue);
  1335. struct wlan_network *pnetwork = NULL;
  1336. u32 cnt=0;
  1337. u32 wait_for_surveydone;
  1338. sint wait_status;
  1339. #ifdef CONFIG_P2P
  1340. struct wifidirect_info* pwdinfo = &padapter->wdinfo;
  1341. #endif //CONFIG_P2P
  1342. struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
  1343. struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
  1344. #ifdef CONFIG_DEBUG_CFG80211
  1345. DBG_8192C("%s\n", __func__);
  1346. #endif
  1347. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1348. phead = get_list_head(queue);
  1349. plist = get_next(phead);
  1350. while(1)
  1351. {
  1352. if (rtw_end_of_queue_search(phead,plist)== _TRUE)
  1353. break;
  1354. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  1355. //report network only if the current channel set contains the channel to which this network belongs
  1356. if(rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0
  1357. #ifdef CONFIG_VALIDATE_SSID
  1358. && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))
  1359. #endif
  1360. )
  1361. {
  1362. //ev=translate_scan(padapter, a, pnetwork, ev, stop);
  1363. rtw_cfg80211_inform_bss(padapter, pnetwork);
  1364. }
  1365. plist = get_next(plist);
  1366. }
  1367. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1368. //call this after other things have been done
  1369. rtw_cfg80211_indicate_scan_done(wdev_to_priv(padapter->rtw_wdev), _FALSE);
  1370. }
  1371. static int rtw_cfg80211_set_probe_req_wpsp2pie(_adapter *padapter, char *buf, int len)
  1372. {
  1373. int ret = 0;
  1374. uint wps_ielen = 0;
  1375. u8 *wps_ie;
  1376. u32 p2p_ielen = 0;
  1377. u8 *p2p_ie;
  1378. u32 wfd_ielen = 0;
  1379. u8 *wfd_ie;
  1380. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1381. #ifdef CONFIG_DEBUG_CFG80211
  1382. DBG_8192C("%s, ielen=%d\n", __func__, len);
  1383. #endif
  1384. if(len>0)
  1385. {
  1386. if((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen)))
  1387. {
  1388. #ifdef CONFIG_DEBUG_CFG80211
  1389. DBG_8192C("probe_req_wps_ielen=%d\n", wps_ielen);
  1390. #endif
  1391. if(pmlmepriv->wps_probe_req_ie)
  1392. {
  1393. u32 free_len = pmlmepriv->wps_probe_req_ie_len;
  1394. pmlmepriv->wps_probe_req_ie_len = 0;
  1395. rtw_mfree(pmlmepriv->wps_probe_req_ie, free_len);
  1396. pmlmepriv->wps_probe_req_ie = NULL;
  1397. }
  1398. pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen);
  1399. if ( pmlmepriv->wps_probe_req_ie == NULL) {
  1400. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  1401. return -EINVAL;
  1402. }
  1403. _rtw_memcpy(pmlmepriv->wps_probe_req_ie, wps_ie, wps_ielen);
  1404. pmlmepriv->wps_probe_req_ie_len = wps_ielen;
  1405. }
  1406. //buf += wps_ielen;
  1407. //len -= wps_ielen;
  1408. #ifdef CONFIG_P2P
  1409. if((p2p_ie=rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen)))
  1410. {
  1411. #ifdef CONFIG_DEBUG_CFG80211
  1412. DBG_8192C("probe_req_p2p_ielen=%d\n", p2p_ielen);
  1413. #endif
  1414. if(pmlmepriv->p2p_probe_req_ie)
  1415. {
  1416. u32 free_len = pmlmepriv->p2p_probe_req_ie_len;
  1417. pmlmepriv->p2p_probe_req_ie_len = 0;
  1418. rtw_mfree(pmlmepriv->p2p_probe_req_ie, free_len);
  1419. pmlmepriv->p2p_probe_req_ie = NULL;
  1420. }
  1421. pmlmepriv->p2p_probe_req_ie = rtw_malloc(p2p_ielen);
  1422. if ( pmlmepriv->p2p_probe_req_ie == NULL) {
  1423. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  1424. return -EINVAL;
  1425. }
  1426. _rtw_memcpy(pmlmepriv->p2p_probe_req_ie, p2p_ie, p2p_ielen);
  1427. pmlmepriv->p2p_probe_req_ie_len = p2p_ielen;
  1428. }
  1429. #endif //CONFIG_P2P
  1430. //buf += p2p_ielen;
  1431. //len -= p2p_ielen;
  1432. #ifdef CONFIG_WFD
  1433. if(rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen))
  1434. {
  1435. #ifdef CONFIG_DEBUG_CFG80211
  1436. DBG_8192C("probe_req_wfd_ielen=%d\n", wfd_ielen);
  1437. #endif
  1438. if(pmlmepriv->wfd_probe_req_ie)
  1439. {
  1440. u32 free_len = pmlmepriv->wfd_probe_req_ie_len;
  1441. pmlmepriv->wfd_probe_req_ie_len = 0;
  1442. rtw_mfree(pmlmepriv->wfd_probe_req_ie, free_len);
  1443. pmlmepriv->wfd_probe_req_ie = NULL;
  1444. }
  1445. pmlmepriv->wfd_probe_req_ie = rtw_malloc(wfd_ielen);
  1446. if ( pmlmepriv->wfd_probe_req_ie == NULL) {
  1447. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  1448. return -EINVAL;
  1449. }
  1450. rtw_get_wfd_ie(buf, len, pmlmepriv->wfd_probe_req_ie, &pmlmepriv->wfd_probe_req_ie_len);
  1451. }
  1452. #endif //CONFIG_WFD
  1453. }
  1454. return ret;
  1455. }
  1456. static int cfg80211_rtw_scan(struct wiphy *wiphy
  1457. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
  1458. , struct net_device *ndev
  1459. #endif
  1460. , struct cfg80211_scan_request *request)
  1461. {
  1462. int i;
  1463. u8 _status = _FALSE;
  1464. int ret = 0;
  1465. _adapter *padapter = wiphy_to_adapter(wiphy);
  1466. struct mlme_priv *pmlmepriv= &padapter->mlmepriv;
  1467. NDIS_802_11_SSID ssid[RTW_SSID_SCAN_AMOUNT];
  1468. struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
  1469. _irqL irqL;
  1470. u8 *wps_ie=NULL;
  1471. uint wps_ielen=0;
  1472. u8 *p2p_ie=NULL;
  1473. uint p2p_ielen=0;
  1474. u8 survey_times=3;
  1475. #ifdef CONFIG_P2P
  1476. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  1477. #endif //CONFIG_P2P
  1478. struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
  1479. struct cfg80211_ssid *ssids = request->ssids;
  1480. int social_channel = 0, j = 0;
  1481. bool need_indicate_scan_done = _FALSE;
  1482. #ifdef CONFIG_CONCURRENT_MODE
  1483. PADAPTER pbuddy_adapter = NULL;
  1484. struct mlme_priv *pbuddy_mlmepriv = NULL;
  1485. #endif //CONFIG_CONCURRENT_MODE
  1486. #ifdef CONFIG_DEBUG_CFG80211
  1487. DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  1488. #endif
  1489. #ifdef CONFIG_CONCURRENT_MODE
  1490. if (padapter->pbuddy_adapter) {
  1491. pbuddy_adapter = padapter->pbuddy_adapter;
  1492. pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
  1493. }
  1494. #endif //CONFIG_CONCURRENT_MODE
  1495. #ifdef CONFIG_MP_INCLUDED
  1496. if (padapter->registrypriv.mp_mode == 1)
  1497. {
  1498. if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
  1499. {
  1500. ret = -EPERM;
  1501. goto exit;
  1502. }
  1503. }
  1504. #endif
  1505. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  1506. pwdev_priv->scan_request = request;
  1507. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  1508. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1509. {
  1510. #ifdef CONFIG_DEBUG_CFG80211
  1511. DBG_871X("%s under WIFI_AP_STATE\n", __FUNCTION__);
  1512. #endif
  1513. //need_indicate_scan_done = _TRUE;
  1514. //goto check_need_indicate_scan_done;
  1515. }
  1516. if(_FAIL == rtw_pwr_wakeup(padapter)) {
  1517. need_indicate_scan_done = _TRUE;
  1518. goto check_need_indicate_scan_done;
  1519. }
  1520. #ifdef CONFIG_P2P
  1521. if( pwdinfo->driver_interface == DRIVER_CFG80211 )
  1522. {
  1523. if(ssids->ssid != NULL
  1524. && _rtw_memcmp(ssids->ssid, "DIRECT-", 7)
  1525. && rtw_get_p2p_ie((u8 *)request->ie, request->ie_len, NULL, NULL)
  1526. )
  1527. {
  1528. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  1529. {
  1530. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  1531. wdev_to_priv(padapter->rtw_wdev)->p2p_enabled = _TRUE;
  1532. }
  1533. else
  1534. {
  1535. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  1536. #ifdef CONFIG_DEBUG_CFG80211
  1537. DBG_8192C("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  1538. #endif
  1539. }
  1540. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  1541. if(request->n_channels == 3 &&
  1542. request->channels[0]->hw_value == 1 &&
  1543. request->channels[1]->hw_value == 6 &&
  1544. request->channels[2]->hw_value == 11
  1545. )
  1546. {
  1547. social_channel = 1;
  1548. }
  1549. }
  1550. }
  1551. #endif //CONFIG_P2P
  1552. if(request->ie && request->ie_len>0)
  1553. {
  1554. rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len );
  1555. }
  1556. if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE)
  1557. {
  1558. DBG_8192C("%s, bBusyTraffic == _TRUE\n", __func__);
  1559. need_indicate_scan_done = _TRUE;
  1560. goto check_need_indicate_scan_done;
  1561. }
  1562. if (rtw_is_scan_deny(padapter)){
  1563. DBG_871X(FUNC_ADPT_FMT ": scan deny\n", FUNC_ADPT_ARG(padapter));
  1564. need_indicate_scan_done = _TRUE;
  1565. goto check_need_indicate_scan_done;
  1566. }
  1567. #ifdef CONFIG_CONCURRENT_MODE
  1568. if(pbuddy_mlmepriv && (pbuddy_mlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE))
  1569. {
  1570. DBG_8192C("%s, bBusyTraffic == _TRUE at buddy_intf\n", __func__);
  1571. need_indicate_scan_done = _TRUE;
  1572. goto check_need_indicate_scan_done;
  1573. }
  1574. #endif //CONFIG_CONCURRENT_MODE
  1575. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == _TRUE)
  1576. {
  1577. DBG_8192C("%s, fwstate=0x%x\n", __func__, pmlmepriv->fw_state);
  1578. need_indicate_scan_done = _TRUE;
  1579. goto check_need_indicate_scan_done;
  1580. }
  1581. #ifdef CONFIG_CONCURRENT_MODE
  1582. if (check_buddy_fwstate(padapter,
  1583. _FW_UNDER_SURVEY|_FW_UNDER_LINKING|WIFI_UNDER_WPS) == _TRUE)
  1584. {
  1585. if(check_buddy_fwstate(padapter, _FW_UNDER_SURVEY))
  1586. {
  1587. DBG_8192C("scanning_via_buddy_intf\n");
  1588. pmlmepriv->scanning_via_buddy_intf = _TRUE;
  1589. }
  1590. DBG_8192C("buddy_intf's mlme state:0x%x\n", pbuddy_mlmepriv->fw_state);
  1591. need_indicate_scan_done = _TRUE;
  1592. goto check_need_indicate_scan_done;
  1593. }
  1594. #endif
  1595. #ifdef CONFIG_P2P
  1596. if( pwdinfo->driver_interface == DRIVER_CFG80211 )
  1597. {
  1598. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
  1599. {
  1600. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  1601. rtw_free_network_queue(padapter, _TRUE);
  1602. if(social_channel == 0)
  1603. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
  1604. else
  1605. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_SOCIAL_LAST);
  1606. }
  1607. }
  1608. #endif //CONFIG_P2P
  1609. _rtw_memset(ssid, 0, sizeof(NDIS_802_11_SSID)*RTW_SSID_SCAN_AMOUNT);
  1610. //parsing request ssids, n_ssids
  1611. for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) {
  1612. #ifdef CONFIG_DEBUG_CFG80211
  1613. DBG_8192C("ssid=%s, len=%d\n", ssids[i].ssid, ssids[i].ssid_len);
  1614. #endif
  1615. _rtw_memcpy(ssid[i].Ssid, ssids[i].ssid, ssids[i].ssid_len);
  1616. ssid[i].SsidLength = ssids[i].ssid_len;
  1617. }
  1618. /* parsing channels, n_channels */
  1619. _rtw_memset(ch, 0, sizeof(struct rtw_ieee80211_channel)*RTW_CHANNEL_SCAN_AMOUNT);
  1620. for (i=0;i<request->n_channels && i<RTW_CHANNEL_SCAN_AMOUNT;i++) {
  1621. #ifdef CONFIG_DEBUG_CFG80211
  1622. DBG_871X(FUNC_ADPT_FMT CHAN_FMT"\n", FUNC_ADPT_ARG(padapter), CHAN_ARG(request->channels[i]));
  1623. #endif
  1624. ch[i].hw_value = request->channels[i]->hw_value;
  1625. ch[i].flags = request->channels[i]->flags;
  1626. }
  1627. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  1628. if (request->n_channels == 1) {
  1629. for(i=1;i<survey_times;i++)
  1630. _rtw_memcpy(&ch[i], &ch[0], sizeof(struct rtw_ieee80211_channel));
  1631. _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, survey_times);
  1632. } else if (request->n_channels == 2) {
  1633. _rtw_memcpy(&ch[survey_times], &ch[1], sizeof(struct rtw_ieee80211_channel));
  1634. for(i=1;i<survey_times;i++) {
  1635. _rtw_memcpy(&ch[i], &ch[0], sizeof(struct rtw_ieee80211_channel));
  1636. _rtw_memcpy(&ch[i+survey_times], &ch[survey_times], sizeof(struct rtw_ieee80211_channel));
  1637. }
  1638. _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, survey_times * 2);
  1639. } else {
  1640. _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, NULL, 0);
  1641. }
  1642. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  1643. if(_status == _FALSE)
  1644. {
  1645. ret = -1;
  1646. }
  1647. check_need_indicate_scan_done:
  1648. if(need_indicate_scan_done)
  1649. rtw_cfg80211_surveydone_event_callback(padapter);
  1650. exit:
  1651. return ret;
  1652. }
  1653. static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1654. {
  1655. #if 0
  1656. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  1657. if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
  1658. (iwm->conf.rts_threshold != wiphy->rts_threshold)) {
  1659. int ret;
  1660. iwm->conf.rts_threshold = wiphy->rts_threshold;
  1661. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  1662. CFG_RTS_THRESHOLD,
  1663. iwm->conf.rts_threshold);
  1664. if (ret < 0)
  1665. return ret;
  1666. }
  1667. if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
  1668. (iwm->conf.frag_threshold != wiphy->frag_threshold)) {
  1669. int ret;
  1670. iwm->conf.frag_threshold = wiphy->frag_threshold;
  1671. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX,
  1672. CFG_FRAG_THRESHOLD,
  1673. iwm->conf.frag_threshold);
  1674. if (ret < 0)
  1675. return ret;
  1676. }
  1677. #endif
  1678. DBG_8192C("%s\n", __func__);
  1679. return 0;
  1680. }
  1681. static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
  1682. struct cfg80211_ibss_params *params)
  1683. {
  1684. #if 0
  1685. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  1686. struct ieee80211_channel *chan = params->channel;
  1687. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  1688. return -EIO;
  1689. /* UMAC doesn't support creating or joining an IBSS network
  1690. * with specified bssid. */
  1691. if (params->bssid)
  1692. return -EOPNOTSUPP;
  1693. iwm->channel = ieee80211_frequency_to_channel(chan->center_freq);
  1694. iwm->umac_profile->ibss.band = chan->band;
  1695. iwm->umac_profile->ibss.channel = iwm->channel;
  1696. iwm->umac_profile->ssid.ssid_len = params->ssid_len;
  1697. memcpy(iwm->umac_profile->ssid.ssid, params->ssid, params->ssid_len);
  1698. return iwm_send_mlme_profile(iwm);
  1699. #endif
  1700. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  1701. return 0;
  1702. }
  1703. static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
  1704. {
  1705. #if 0
  1706. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  1707. if (iwm->umac_profile_active)
  1708. return iwm_invalidate_mlme_profile(iwm);
  1709. #endif
  1710. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  1711. return 0;
  1712. }
  1713. static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv, u32 wpa_version)
  1714. {
  1715. DBG_8192C("%s, wpa_version=%d\n", __func__, wpa_version);
  1716. if (!wpa_version) {
  1717. psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
  1718. return 0;
  1719. }
  1720. if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
  1721. {
  1722. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK;
  1723. }
  1724. /*
  1725. if (wpa_version & NL80211_WPA_VERSION_2)
  1726. {
  1727. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
  1728. }
  1729. */
  1730. return 0;
  1731. }
  1732. static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv,
  1733. enum nl80211_auth_type sme_auth_type)
  1734. {
  1735. DBG_8192C("%s, nl80211_auth_type=%d\n", __func__, sme_auth_type);
  1736. switch (sme_auth_type) {
  1737. case NL80211_AUTHTYPE_AUTOMATIC:
  1738. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  1739. break;
  1740. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  1741. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  1742. if(psecuritypriv->ndisauthtype>Ndis802_11AuthModeWPA)
  1743. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  1744. #ifdef CONFIG_WAPI_SUPPORT
  1745. if(psecuritypriv->ndisauthtype == Ndis802_11AuthModeWAPI)
  1746. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  1747. #endif
  1748. break;
  1749. case NL80211_AUTHTYPE_SHARED_KEY:
  1750. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
  1751. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1752. break;
  1753. default:
  1754. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  1755. //return -ENOTSUPP;
  1756. }
  1757. return 0;
  1758. }
  1759. static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 cipher, bool ucast)
  1760. {
  1761. u32 ndisencryptstatus = Ndis802_11EncryptionDisabled;
  1762. u32 *profile_cipher = ucast ? &psecuritypriv->dot11PrivacyAlgrthm :
  1763. &psecuritypriv->dot118021XGrpPrivacy;
  1764. DBG_8192C("%s, ucast=%d, cipher=0x%x\n", __func__, ucast, cipher);
  1765. if (!cipher) {
  1766. *profile_cipher = _NO_PRIVACY_;
  1767. psecuritypriv->ndisencryptstatus = ndisencryptstatus;
  1768. return 0;
  1769. }
  1770. switch (cipher) {
  1771. case IW_AUTH_CIPHER_NONE:
  1772. *profile_cipher = _NO_PRIVACY_;
  1773. ndisencryptstatus = Ndis802_11EncryptionDisabled;
  1774. #ifdef CONFIG_WAPI_SUPPORT
  1775. if(psecuritypriv->dot11PrivacyAlgrthm ==_SMS4_ )
  1776. {
  1777. *profile_cipher = _SMS4_;
  1778. }
  1779. #endif
  1780. break;
  1781. case WLAN_CIPHER_SUITE_WEP40:
  1782. *profile_cipher = _WEP40_;
  1783. ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1784. break;
  1785. case WLAN_CIPHER_SUITE_WEP104:
  1786. *profile_cipher = _WEP104_;
  1787. ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1788. break;
  1789. case WLAN_CIPHER_SUITE_TKIP:
  1790. *profile_cipher = _TKIP_;
  1791. ndisencryptstatus = Ndis802_11Encryption2Enabled;
  1792. break;
  1793. case WLAN_CIPHER_SUITE_CCMP:
  1794. *profile_cipher = _AES_;
  1795. ndisencryptstatus = Ndis802_11Encryption3Enabled;
  1796. break;
  1797. #ifdef CONFIG_WAPI_SUPPORT
  1798. case WLAN_CIPHER_SUITE_SMS4:
  1799. *profile_cipher = _SMS4_;
  1800. ndisencryptstatus = Ndis802_11_EncrypteionWAPI;
  1801. break;
  1802. #endif
  1803. default:
  1804. DBG_8192C("Unsupported cipher: 0x%x\n", cipher);
  1805. return -ENOTSUPP;
  1806. }
  1807. if(ucast)
  1808. {
  1809. psecuritypriv->ndisencryptstatus = ndisencryptstatus;
  1810. //if(psecuritypriv->dot11PrivacyAlgrthm >= _AES_)
  1811. // psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
  1812. }
  1813. return 0;
  1814. }
  1815. static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv, u32 key_mgt)
  1816. {
  1817. DBG_8192C("%s, key_mgt=0x%x\n", __func__, key_mgt);
  1818. if (key_mgt == WLAN_AKM_SUITE_8021X)
  1819. //*auth_type = UMAC_AUTH_TYPE_8021X;
  1820. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  1821. else if (key_mgt == WLAN_AKM_SUITE_PSK) {
  1822. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  1823. }
  1824. #ifdef CONFIG_WAPI_SUPPORT
  1825. else if(key_mgt ==WLAN_AKM_SUITE_WAPI_PSK){
  1826. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  1827. }
  1828. else if(key_mgt ==WLAN_AKM_SUITE_WAPI_CERT){
  1829. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  1830. }
  1831. #endif
  1832. else {
  1833. DBG_8192C("Invalid key mgt: 0x%x\n", key_mgt);
  1834. //return -EINVAL;
  1835. }
  1836. return 0;
  1837. }
  1838. static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
  1839. {
  1840. u8 *buf=NULL, *pos=NULL;
  1841. u32 left;
  1842. int group_cipher = 0, pairwise_cipher = 0;
  1843. int ret = 0;
  1844. int wpa_ielen=0;
  1845. int wpa2_ielen=0;
  1846. u8 *pwpa, *pwpa2;
  1847. u8 null_addr[]= {0,0,0,0,0,0};
  1848. if (pie == NULL || !ielen) {
  1849. /* Treat this as normal case, but need to clear WIFI_UNDER_WPS */
  1850. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  1851. goto exit;
  1852. }
  1853. if (ielen > MAX_WPA_IE_LEN+MAX_WPS_IE_LEN+MAX_P2P_IE_LEN) {
  1854. ret = -EINVAL;
  1855. goto exit;
  1856. }
  1857. buf = rtw_zmalloc(ielen);
  1858. if (buf == NULL){
  1859. ret = -ENOMEM;
  1860. goto exit;
  1861. }
  1862. _rtw_memcpy(buf, pie , ielen);
  1863. //dump
  1864. {
  1865. int i;
  1866. DBG_8192C("set wpa_ie(length:%zu):\n", ielen);
  1867. for(i=0;i<ielen;i=i+8)
  1868. DBG_8192C("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x \n",buf[i],buf[i+1],buf[i+2],buf[i+3],buf[i+4],buf[i+5],buf[i+6],buf[i+7]);
  1869. }
  1870. pos = buf;
  1871. if(ielen < RSN_HEADER_LEN){
  1872. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("Ie len too short %d\n", ielen));
  1873. ret = -1;
  1874. goto exit;
  1875. }
  1876. pwpa = rtw_get_wpa_ie(buf, &wpa_ielen, ielen);
  1877. if(pwpa && wpa_ielen>0)
  1878. {
  1879. if(rtw_parse_wpa_ie(pwpa, wpa_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
  1880. {
  1881. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_8021X;
  1882. padapter->securitypriv.ndisauthtype=Ndis802_11AuthModeWPAPSK;
  1883. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &pwpa[0], wpa_ielen+2);
  1884. DBG_8192C("got wpa_ie, wpa_ielen:%u\n", wpa_ielen);
  1885. }
  1886. }
  1887. pwpa2 = rtw_get_wpa2_ie(buf, &wpa2_ielen, ielen);
  1888. if(pwpa2 && wpa2_ielen>0)
  1889. {
  1890. if(rtw_parse_wpa2_ie(pwpa2, wpa2_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
  1891. {
  1892. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_8021X;
  1893. padapter->securitypriv.ndisauthtype=Ndis802_11AuthModeWPA2PSK;
  1894. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &pwpa2[0], wpa2_ielen+2);
  1895. DBG_8192C("got wpa2_ie, wpa2_ielen:%u\n", wpa2_ielen);
  1896. }
  1897. }
  1898. if (group_cipher == 0)
  1899. {
  1900. group_cipher = WPA_CIPHER_NONE;
  1901. }
  1902. if (pairwise_cipher == 0)
  1903. {
  1904. pairwise_cipher = WPA_CIPHER_NONE;
  1905. }
  1906. switch(group_cipher)
  1907. {
  1908. case WPA_CIPHER_NONE:
  1909. padapter->securitypriv.dot118021XGrpPrivacy=_NO_PRIVACY_;
  1910. padapter->securitypriv.ndisencryptstatus=Ndis802_11EncryptionDisabled;
  1911. break;
  1912. case WPA_CIPHER_WEP40:
  1913. padapter->securitypriv.dot118021XGrpPrivacy=_WEP40_;
  1914. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1915. break;
  1916. case WPA_CIPHER_TKIP:
  1917. padapter->securitypriv.dot118021XGrpPrivacy=_TKIP_;
  1918. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  1919. break;
  1920. case WPA_CIPHER_CCMP:
  1921. padapter->securitypriv.dot118021XGrpPrivacy=_AES_;
  1922. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  1923. break;
  1924. case WPA_CIPHER_WEP104:
  1925. padapter->securitypriv.dot118021XGrpPrivacy=_WEP104_;
  1926. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1927. break;
  1928. }
  1929. switch(pairwise_cipher)
  1930. {
  1931. case WPA_CIPHER_NONE:
  1932. padapter->securitypriv.dot11PrivacyAlgrthm=_NO_PRIVACY_;
  1933. padapter->securitypriv.ndisencryptstatus=Ndis802_11EncryptionDisabled;
  1934. break;
  1935. case WPA_CIPHER_WEP40:
  1936. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP40_;
  1937. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1938. break;
  1939. case WPA_CIPHER_TKIP:
  1940. padapter->securitypriv.dot11PrivacyAlgrthm=_TKIP_;
  1941. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  1942. break;
  1943. case WPA_CIPHER_CCMP:
  1944. padapter->securitypriv.dot11PrivacyAlgrthm=_AES_;
  1945. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  1946. break;
  1947. case WPA_CIPHER_WEP104:
  1948. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP104_;
  1949. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1950. break;
  1951. }
  1952. {/* handle wps_ie */
  1953. uint wps_ielen;
  1954. u8 *wps_ie;
  1955. wps_ie = rtw_get_wps_ie(buf, ielen, NULL, &wps_ielen);
  1956. if (wps_ie && wps_ielen > 0) {
  1957. DBG_8192C("got wps_ie, wps_ielen:%u\n", wps_ielen);
  1958. padapter->securitypriv.wps_ie_len = wps_ielen<MAX_WPS_IE_LEN?wps_ielen:MAX_WPS_IE_LEN;
  1959. _rtw_memcpy(padapter->securitypriv.wps_ie, wps_ie, padapter->securitypriv.wps_ie_len);
  1960. set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
  1961. } else {
  1962. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  1963. }
  1964. }
  1965. #ifdef CONFIG_P2P
  1966. {//check p2p_ie for assoc req;
  1967. uint p2p_ielen=0;
  1968. u8 *p2p_ie;
  1969. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1970. if((p2p_ie=rtw_get_p2p_ie(buf, ielen, NULL, &p2p_ielen)))
  1971. {
  1972. #ifdef CONFIG_DEBUG_CFG80211
  1973. DBG_8192C("%s p2p_assoc_req_ielen=%d\n", __FUNCTION__, p2p_ielen);
  1974. #endif
  1975. if(pmlmepriv->p2p_assoc_req_ie)
  1976. {
  1977. u32 free_len = pmlmepriv->p2p_assoc_req_ie_len;
  1978. pmlmepriv->p2p_assoc_req_ie_len = 0;
  1979. rtw_mfree(pmlmepriv->p2p_assoc_req_ie, free_len);
  1980. pmlmepriv->p2p_assoc_req_ie = NULL;
  1981. }
  1982. pmlmepriv->p2p_assoc_req_ie = rtw_malloc(p2p_ielen);
  1983. if ( pmlmepriv->p2p_assoc_req_ie == NULL) {
  1984. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  1985. goto exit;
  1986. }
  1987. _rtw_memcpy(pmlmepriv->p2p_assoc_req_ie, p2p_ie, p2p_ielen);
  1988. pmlmepriv->p2p_assoc_req_ie_len = p2p_ielen;
  1989. }
  1990. }
  1991. #endif //CONFIG_P2P
  1992. #ifdef CONFIG_WFD
  1993. {//check wfd_ie for assoc req;
  1994. uint wfd_ielen=0;
  1995. u8 *wfd_ie;
  1996. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1997. if(rtw_get_wfd_ie(buf, ielen, NULL, &wfd_ielen))
  1998. {
  1999. #ifdef CONFIG_DEBUG_CFG80211
  2000. DBG_8192C("%s wfd_assoc_req_ielen=%d\n", __FUNCTION__, wfd_ielen);
  2001. #endif
  2002. if(pmlmepriv->wfd_assoc_req_ie)
  2003. {
  2004. u32 free_len = pmlmepriv->wfd_assoc_req_ie_len;
  2005. pmlmepriv->wfd_assoc_req_ie_len = 0;
  2006. rtw_mfree(pmlmepriv->wfd_assoc_req_ie, free_len);
  2007. pmlmepriv->wfd_assoc_req_ie = NULL;
  2008. }
  2009. pmlmepriv->wfd_assoc_req_ie = rtw_malloc(wfd_ielen);
  2010. if ( pmlmepriv->wfd_assoc_req_ie == NULL) {
  2011. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  2012. goto exit;
  2013. }
  2014. rtw_get_wfd_ie(buf, ielen, pmlmepriv->wfd_assoc_req_ie, &pmlmepriv->wfd_assoc_req_ie_len);
  2015. }
  2016. }
  2017. #endif //CONFIG_WFD
  2018. //TKIP and AES disallow multicast packets until installing group key
  2019. if(padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_
  2020. || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_
  2021. || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)
  2022. //WPS open need to enable multicast
  2023. //|| check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == _TRUE)
  2024. rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr);
  2025. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
  2026. ("rtw_set_wpa_ie: pairwise_cipher=0x%08x padapter->securitypriv.ndisencryptstatus=%d padapter->securitypriv.ndisauthtype=%d\n",
  2027. pairwise_cipher, padapter->securitypriv.ndisencryptstatus, padapter->securitypriv.ndisauthtype));
  2028. exit:
  2029. if (buf)
  2030. rtw_mfree(buf, ielen);
  2031. if (ret)
  2032. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  2033. return ret;
  2034. }
  2035. static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
  2036. struct cfg80211_connect_params *sme)
  2037. {
  2038. int ret=0;
  2039. _irqL irqL;
  2040. _list *phead;
  2041. struct wlan_network *pnetwork = NULL;
  2042. NDIS_802_11_AUTHENTICATION_MODE authmode;
  2043. NDIS_802_11_SSID ndis_ssid;
  2044. u8 *dst_ssid, *src_ssid;
  2045. u8 *dst_bssid, *src_bssid;
  2046. //u8 matched_by_bssid=_FALSE;
  2047. //u8 matched_by_ssid=_FALSE;
  2048. u8 matched=_FALSE;
  2049. _adapter *padapter = wiphy_to_adapter(wiphy);
  2050. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2051. struct security_priv *psecuritypriv = &padapter->securitypriv;
  2052. _queue *queue = &pmlmepriv->scanned_queue;
  2053. DBG_871X("=>"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  2054. DBG_871X("privacy=%d, key=%p, key_len=%d, key_idx=%d\n",
  2055. sme->privacy, sme->key, sme->key_len, sme->key_idx);
  2056. if(wdev_to_priv(padapter->rtw_wdev)->block == _TRUE)
  2057. {
  2058. ret = -EBUSY;
  2059. DBG_871X("%s wdev_priv.block is set\n", __FUNCTION__);
  2060. goto exit;
  2061. }
  2062. #ifdef CONFIG_PLATFORM_MSTAR_TITANIA12
  2063. printk("MStar Android!\n");
  2064. if((wdev_to_priv(padapter->rtw_wdev))->bandroid_scan == _FALSE)
  2065. {
  2066. #ifdef CONFIG_P2P
  2067. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  2068. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  2069. #endif //CONFIG_P2P
  2070. {
  2071. ret = -EBUSY;
  2072. printk("Android hasn't attached yet!\n");
  2073. goto exit;
  2074. }
  2075. }
  2076. #endif
  2077. if(_FAIL == rtw_pwr_wakeup(padapter)) {
  2078. ret= -EPERM;
  2079. goto exit;
  2080. }
  2081. if(check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  2082. ret = -EPERM;
  2083. goto exit;
  2084. }
  2085. #ifdef CONFIG_CONCURRENT_MODE
  2086. if (check_buddy_fwstate(padapter, _FW_UNDER_LINKING) == _TRUE) {
  2087. DBG_8192C("%s, but buddy_intf is under linking\n", __FUNCTION__);
  2088. ret = -EINVAL;
  2089. goto exit;
  2090. }
  2091. if (check_buddy_fwstate(padapter, _FW_UNDER_SURVEY) == _TRUE) {
  2092. rtw_scan_abort(padapter->pbuddy_adapter);
  2093. }
  2094. #endif
  2095. if (!sme->ssid || !sme->ssid_len)
  2096. {
  2097. ret = -EINVAL;
  2098. goto exit;
  2099. }
  2100. if (sme->ssid_len > IW_ESSID_MAX_SIZE){
  2101. ret= -E2BIG;
  2102. goto exit;
  2103. }
  2104. _rtw_memset(&ndis_ssid, 0, sizeof(NDIS_802_11_SSID));
  2105. ndis_ssid.SsidLength = sme->ssid_len;
  2106. _rtw_memcpy(ndis_ssid.Ssid, sme->ssid, sme->ssid_len);
  2107. DBG_8192C("ssid=%s, len=%zu\n", ndis_ssid.Ssid, sme->ssid_len);
  2108. if (sme->bssid)
  2109. DBG_8192C("bssid="MAC_FMT"\n", MAC_ARG(sme->bssid));
  2110. if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE) {
  2111. ret = -EBUSY;
  2112. DBG_8192C("%s, fw_state=0x%x, goto exit\n", __FUNCTION__, pmlmepriv->fw_state);
  2113. goto exit;
  2114. }
  2115. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
  2116. rtw_scan_abort(padapter);
  2117. }
  2118. _enter_critical_bh(&queue->lock, &irqL);
  2119. phead = get_list_head(queue);
  2120. pmlmepriv->pscanned = get_next(phead);
  2121. while (1)
  2122. {
  2123. if (rtw_end_of_queue_search(phead, pmlmepriv->pscanned) == _TRUE)
  2124. {
  2125. break;
  2126. }
  2127. pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned, struct wlan_network, list);
  2128. pmlmepriv->pscanned = get_next(pmlmepriv->pscanned);
  2129. dst_ssid = pnetwork->network.Ssid.Ssid;
  2130. dst_bssid = pnetwork->network.MacAddress;
  2131. if(sme->bssid) {
  2132. if(_rtw_memcmp(pnetwork->network.MacAddress, sme->bssid, ETH_ALEN) == _FALSE)
  2133. continue;
  2134. }
  2135. if(sme->ssid && sme->ssid_len) {
  2136. if( pnetwork->network.Ssid.SsidLength != sme->ssid_len
  2137. || _rtw_memcmp(pnetwork->network.Ssid.Ssid, sme->ssid, sme->ssid_len) == _FALSE
  2138. )
  2139. continue;
  2140. }
  2141. if (sme->bssid)
  2142. {
  2143. src_bssid = sme->bssid;
  2144. if ((_rtw_memcmp(dst_bssid, src_bssid, ETH_ALEN)) == _TRUE)
  2145. {
  2146. DBG_8192C("matched by bssid\n");
  2147. ndis_ssid.SsidLength = pnetwork->network.Ssid.SsidLength;
  2148. _rtw_memcpy(ndis_ssid.Ssid, pnetwork->network.Ssid.Ssid, pnetwork->network.Ssid.SsidLength);
  2149. matched=_TRUE;
  2150. break;
  2151. }
  2152. }
  2153. else if (sme->ssid && sme->ssid_len)
  2154. {
  2155. src_ssid = ndis_ssid.Ssid;
  2156. if ((_rtw_memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength) == _TRUE) &&
  2157. (pnetwork->network.Ssid.SsidLength==ndis_ssid.SsidLength))
  2158. {
  2159. DBG_8192C("matched by ssid\n");
  2160. matched=_TRUE;
  2161. break;
  2162. }
  2163. }
  2164. }
  2165. _exit_critical_bh(&queue->lock, &irqL);
  2166. if((matched == _FALSE) || (pnetwork== NULL))
  2167. {
  2168. ret = -ENOENT;
  2169. DBG_8192C("connect, matched == _FALSE, goto exit\n");
  2170. goto exit;
  2171. }
  2172. if (rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode) == _FALSE)
  2173. {
  2174. ret = -EPERM;
  2175. goto exit;
  2176. }
  2177. psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2178. psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
  2179. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  2180. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; //open system
  2181. psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
  2182. #ifdef CONFIG_WAPI_SUPPORT
  2183. padapter->wapiInfo.bWapiEnable = false;
  2184. #endif
  2185. ret = rtw_cfg80211_set_wpa_version(psecuritypriv, sme->crypto.wpa_versions);
  2186. if (ret < 0)
  2187. goto exit;
  2188. #ifdef CONFIG_WAPI_SUPPORT
  2189. if(sme->crypto.wpa_versions & NL80211_WAPI_VERSION_1)
  2190. {
  2191. padapter->wapiInfo.bWapiEnable = true;
  2192. padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN;
  2193. padapter->wapiInfo.extra_postfix_len = SMS4_MIC_LEN;
  2194. }
  2195. #endif
  2196. ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme->auth_type);
  2197. #ifdef CONFIG_WAPI_SUPPORT
  2198. if(psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_WAPI)
  2199. padapter->mlmeextpriv.mlmext_info.auth_algo = psecuritypriv->dot11AuthAlgrthm;
  2200. #endif
  2201. if (ret < 0)
  2202. goto exit;
  2203. DBG_8192C("%s, ie_len=%zu\n", __func__, sme->ie_len);
  2204. ret = rtw_cfg80211_set_wpa_ie(padapter, sme->ie, sme->ie_len);
  2205. if (ret < 0)
  2206. goto exit;
  2207. if (sme->crypto.n_ciphers_pairwise) {
  2208. ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.ciphers_pairwise[0], _TRUE);
  2209. if (ret < 0)
  2210. goto exit;
  2211. }
  2212. //For WEP Shared auth
  2213. if((psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Shared
  2214. || psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Auto) && sme->key
  2215. )
  2216. {
  2217. u32 wep_key_idx, wep_key_len,wep_total_len;
  2218. NDIS_802_11_WEP *pwep = NULL;
  2219. DBG_871X("%s(): Shared/Auto WEP\n",__FUNCTION__);
  2220. wep_key_idx = sme->key_idx;
  2221. wep_key_len = sme->key_len;
  2222. if (sme->key_idx > WEP_KEYS) {
  2223. ret = -EINVAL;
  2224. goto exit;
  2225. }
  2226. if (wep_key_len > 0)
  2227. {
  2228. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  2229. wep_total_len = wep_key_len + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
  2230. pwep =(NDIS_802_11_WEP *) rtw_malloc(wep_total_len);
  2231. if(pwep == NULL){
  2232. DBG_871X(" wpa_set_encryption: pwep allocate fail !!!\n");
  2233. ret = -ENOMEM;
  2234. goto exit;
  2235. }
  2236. _rtw_memset(pwep, 0, wep_total_len);
  2237. pwep->KeyLength = wep_key_len;
  2238. pwep->Length = wep_total_len;
  2239. if(wep_key_len==13)
  2240. {
  2241. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP104_;
  2242. padapter->securitypriv.dot118021XGrpPrivacy=_WEP104_;
  2243. }
  2244. }
  2245. else {
  2246. ret = -EINVAL;
  2247. goto exit;
  2248. }
  2249. pwep->KeyIndex = wep_key_idx;
  2250. pwep->KeyIndex |= 0x80000000;
  2251. _rtw_memcpy(pwep->KeyMaterial, (void *)sme->key, pwep->KeyLength);
  2252. if(rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL)
  2253. {
  2254. ret = -EOPNOTSUPP ;
  2255. }
  2256. if (pwep) {
  2257. rtw_mfree((u8 *)pwep,wep_total_len);
  2258. }
  2259. if(ret < 0)
  2260. goto exit;
  2261. }
  2262. ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.cipher_group, _FALSE);
  2263. if (ret < 0)
  2264. return ret;
  2265. if (sme->crypto.n_akm_suites) {
  2266. ret = rtw_cfg80211_set_key_mgt(psecuritypriv, sme->crypto.akm_suites[0]);
  2267. if (ret < 0)
  2268. goto exit;
  2269. }
  2270. #ifdef CONFIG_WAPI_SUPPORT
  2271. if(sme->crypto.akm_suites[0] ==WLAN_AKM_SUITE_WAPI_PSK){
  2272. padapter->wapiInfo.bWapiPSK = true;
  2273. }
  2274. else if(sme->crypto.akm_suites[0] ==WLAN_AKM_SUITE_WAPI_CERT){
  2275. padapter->wapiInfo.bWapiPSK = false;
  2276. }
  2277. #endif
  2278. authmode = psecuritypriv->ndisauthtype;
  2279. rtw_set_802_11_authentication_mode(padapter, authmode);
  2280. //rtw_set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus);
  2281. if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == _FALSE) {
  2282. ret = -1;
  2283. goto exit;
  2284. }
  2285. DBG_8192C("set ssid:dot11AuthAlgrthm=%d, dot11PrivacyAlgrthm=%d, dot118021XGrpPrivacy=%d\n", psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm, psecuritypriv->dot118021XGrpPrivacy);
  2286. exit:
  2287. DBG_8192C("<=%s, ret %d\n",__FUNCTION__, ret);
  2288. return ret;
  2289. }
  2290. static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
  2291. u16 reason_code)
  2292. {
  2293. _adapter *padapter = wiphy_to_adapter(wiphy);
  2294. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  2295. rtw_set_roaming(padapter, 0);
  2296. if(check_fwstate(&padapter->mlmepriv, _FW_LINKED))
  2297. {
  2298. rtw_scan_abort(padapter);
  2299. LeaveAllPowerSaveMode(padapter);
  2300. rtw_disassoc_cmd(padapter, 500, _FALSE);
  2301. DBG_871X("%s...call rtw_indicate_disconnect\n", __FUNCTION__);
  2302. padapter->mlmepriv.not_indic_disco = _TRUE;
  2303. rtw_indicate_disconnect(padapter);
  2304. padapter->mlmepriv.not_indic_disco = _FALSE;
  2305. rtw_free_assoc_resources(padapter, 1);
  2306. rtw_pwr_wakeup(padapter);
  2307. }
  2308. return 0;
  2309. }
  2310. static int cfg80211_rtw_set_txpower(struct wiphy *wiphy,
  2311. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
  2312. struct wireless_dev *wdev,
  2313. #endif
  2314. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)) || defined(COMPAT_KERNEL_RELEASE)
  2315. enum nl80211_tx_power_setting type, int mbm)
  2316. #else
  2317. enum tx_power_setting type, int dbm)
  2318. #endif
  2319. {
  2320. #if 0
  2321. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  2322. int ret;
  2323. switch (type) {
  2324. case NL80211_TX_POWER_AUTOMATIC:
  2325. return 0;
  2326. case NL80211_TX_POWER_FIXED:
  2327. if (mbm < 0 || (mbm % 100))
  2328. return -EOPNOTSUPP;
  2329. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  2330. return 0;
  2331. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  2332. CFG_TX_PWR_LIMIT_USR,
  2333. MBM_TO_DBM(mbm) * 2);
  2334. if (ret < 0)
  2335. return ret;
  2336. return iwm_tx_power_trigger(iwm);
  2337. default:
  2338. IWM_ERR(iwm, "Unsupported power type: %d\n", type);
  2339. return -EOPNOTSUPP;
  2340. }
  2341. #endif
  2342. DBG_8192C("%s\n", __func__);
  2343. return 0;
  2344. }
  2345. static int cfg80211_rtw_get_txpower(struct wiphy *wiphy,
  2346. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
  2347. struct wireless_dev *wdev,
  2348. #endif
  2349. int *dbm)
  2350. {
  2351. //_adapter *padapter = wiphy_to_adapter(wiphy);
  2352. DBG_8192C("%s\n", __func__);
  2353. *dbm = (12);
  2354. return 0;
  2355. }
  2356. inline bool rtw_cfg80211_pwr_mgmt(_adapter *adapter)
  2357. {
  2358. struct rtw_wdev_priv *rtw_wdev_priv = wdev_to_priv(adapter->rtw_wdev);
  2359. return rtw_wdev_priv->power_mgmt;
  2360. }
  2361. static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy,
  2362. struct net_device *ndev,
  2363. bool enabled, int timeout)
  2364. {
  2365. _adapter *padapter = wiphy_to_adapter(wiphy);
  2366. struct rtw_wdev_priv *rtw_wdev_priv = wdev_to_priv(padapter->rtw_wdev);
  2367. DBG_871X(FUNC_NDEV_FMT" enabled:%u, timeout:%d\n", FUNC_NDEV_ARG(ndev),
  2368. enabled, timeout);
  2369. rtw_wdev_priv->power_mgmt = enabled;
  2370. #ifdef CONFIG_LPS
  2371. if (!enabled)
  2372. LPS_Leave(padapter);
  2373. #endif
  2374. return 0;
  2375. }
  2376. static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy,
  2377. struct net_device *netdev,
  2378. struct cfg80211_pmksa *pmksa)
  2379. {
  2380. u8 index,blInserted = _FALSE;
  2381. _adapter *padapter = wiphy_to_adapter(wiphy);
  2382. struct security_priv *psecuritypriv = &padapter->securitypriv;
  2383. u8 strZeroMacAddress[ ETH_ALEN ] = { 0x00 };
  2384. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(netdev));
  2385. if ( _rtw_memcmp( pmksa->bssid, strZeroMacAddress, ETH_ALEN ) == _TRUE )
  2386. {
  2387. return -EINVAL;
  2388. }
  2389. blInserted = _FALSE;
  2390. //overwrite PMKID
  2391. for(index=0 ; index<NUM_PMKID_CACHE; index++)
  2392. {
  2393. if( _rtw_memcmp( psecuritypriv->PMKIDList[index].Bssid, pmksa->bssid, ETH_ALEN) ==_TRUE )
  2394. { // BSSID is matched, the same AP => rewrite with new PMKID.
  2395. DBG_871X(FUNC_NDEV_FMT" BSSID exists in the PMKList.\n", FUNC_NDEV_ARG(netdev));
  2396. _rtw_memcpy( psecuritypriv->PMKIDList[index].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
  2397. psecuritypriv->PMKIDList[index].bUsed = _TRUE;
  2398. psecuritypriv->PMKIDIndex = index+1;
  2399. blInserted = _TRUE;
  2400. break;
  2401. }
  2402. }
  2403. if(!blInserted)
  2404. {
  2405. // Find a new entry
  2406. DBG_871X(FUNC_NDEV_FMT" Use the new entry index = %d for this PMKID.\n",
  2407. FUNC_NDEV_ARG(netdev), psecuritypriv->PMKIDIndex );
  2408. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, pmksa->bssid, ETH_ALEN);
  2409. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
  2410. psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = _TRUE;
  2411. psecuritypriv->PMKIDIndex++ ;
  2412. if(psecuritypriv->PMKIDIndex==16)
  2413. {
  2414. psecuritypriv->PMKIDIndex =0;
  2415. }
  2416. }
  2417. return 0;
  2418. }
  2419. static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy,
  2420. struct net_device *netdev,
  2421. struct cfg80211_pmksa *pmksa)
  2422. {
  2423. u8 index, bMatched = _FALSE;
  2424. _adapter *padapter = wiphy_to_adapter(wiphy);
  2425. struct security_priv *psecuritypriv = &padapter->securitypriv;
  2426. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(netdev));
  2427. for(index=0 ; index<NUM_PMKID_CACHE; index++)
  2428. {
  2429. if( _rtw_memcmp( psecuritypriv->PMKIDList[index].Bssid, pmksa->bssid, ETH_ALEN) ==_TRUE )
  2430. { // BSSID is matched, the same AP => Remove this PMKID information and reset it.
  2431. _rtw_memset( psecuritypriv->PMKIDList[index].Bssid, 0x00, ETH_ALEN );
  2432. _rtw_memset( psecuritypriv->PMKIDList[index].PMKID, 0x00, WLAN_PMKID_LEN );
  2433. psecuritypriv->PMKIDList[index].bUsed = _FALSE;
  2434. bMatched = _TRUE;
  2435. break;
  2436. }
  2437. }
  2438. if(_FALSE == bMatched)
  2439. {
  2440. DBG_871X(FUNC_NDEV_FMT" do not have matched BSSID\n"
  2441. , FUNC_NDEV_ARG(netdev));
  2442. return -EINVAL;
  2443. }
  2444. return 0;
  2445. }
  2446. static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy,
  2447. struct net_device *netdev)
  2448. {
  2449. _adapter *padapter = wiphy_to_adapter(wiphy);
  2450. struct security_priv *psecuritypriv = &padapter->securitypriv;
  2451. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(netdev));
  2452. _rtw_memset( &psecuritypriv->PMKIDList[ 0 ], 0x00, sizeof( RT_PMKID_LIST ) * NUM_PMKID_CACHE );
  2453. psecuritypriv->PMKIDIndex = 0;
  2454. return 0;
  2455. }
  2456. #ifdef CONFIG_AP_MODE
  2457. void rtw_cfg80211_indicate_sta_assoc(_adapter *padapter, u8 *pmgmt_frame, uint frame_len)
  2458. {
  2459. s32 freq;
  2460. int channel;
  2461. struct wireless_dev *pwdev = padapter->rtw_wdev;
  2462. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2463. struct net_device *ndev = padapter->pnetdev;
  2464. DBG_8192C("%s(padapter=%p,%s)\n", __func__, padapter, ndev->name);
  2465. #if defined(RTW_USE_CFG80211_STA_EVENT) || defined(COMPAT_KERNEL_RELEASE)
  2466. {
  2467. struct station_info sinfo;
  2468. u8 ie_offset;
  2469. if (GetFrameSubType(pmgmt_frame) == WIFI_ASSOCREQ)
  2470. ie_offset = _ASOCREQ_IE_OFFSET_;
  2471. else // WIFI_REASSOCREQ
  2472. ie_offset = _REASOCREQ_IE_OFFSET_;
  2473. sinfo.filled = 0;
  2474. sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
  2475. sinfo.assoc_req_ies = pmgmt_frame + WLAN_HDR_A3_LEN + ie_offset;
  2476. sinfo.assoc_req_ies_len = frame_len - WLAN_HDR_A3_LEN - ie_offset;
  2477. cfg80211_new_sta(ndev, GetAddr2Ptr(pmgmt_frame), &sinfo, GFP_ATOMIC);
  2478. }
  2479. #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
  2480. channel = pmlmeext->cur_channel;
  2481. if (channel <= RTW_CH_MAX_2G_CHANNEL)
  2482. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
  2483. else
  2484. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
  2485. #ifdef COMPAT_KERNEL_RELEASE
  2486. rtw_cfg80211_rx_mgmt(padapter, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
  2487. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  2488. rtw_cfg80211_rx_mgmt(padapter, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
  2489. #else //COMPAT_KERNEL_RELEASE
  2490. {
  2491. //to avoid WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION) when calling cfg80211_send_rx_assoc()
  2492. #ifndef CONFIG_PLATFORM_MSTAR_TITANIA12
  2493. pwdev->iftype = NL80211_IFTYPE_STATION;
  2494. #endif //CONFIG_PLATFORM_MSTAR_TITANIA12
  2495. DBG_8192C("iftype=%d before call cfg80211_send_rx_assoc()\n", pwdev->iftype);
  2496. rtw_cfg80211_send_rx_assoc(padapter, NULL, pmgmt_frame, frame_len);
  2497. DBG_8192C("iftype=%d after call cfg80211_send_rx_assoc()\n", pwdev->iftype);
  2498. pwdev->iftype = NL80211_IFTYPE_AP;
  2499. //cfg80211_rx_action(padapter->pnetdev, freq, pmgmt_frame, frame_len, GFP_ATOMIC);
  2500. }
  2501. #endif //COMPAT_KERNEL_RELEASE
  2502. #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
  2503. }
  2504. void rtw_cfg80211_indicate_sta_disassoc(_adapter *padapter, unsigned char *da, unsigned short reason)
  2505. {
  2506. s32 freq;
  2507. int channel;
  2508. u8 *pmgmt_frame;
  2509. uint frame_len;
  2510. struct rtw_ieee80211_hdr *pwlanhdr;
  2511. unsigned short *fctrl;
  2512. u8 mgmt_buf[128] = {0};
  2513. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2514. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2515. struct net_device *ndev = padapter->pnetdev;
  2516. DBG_8192C("%s(padapter=%p,%s)\n", __func__, padapter, ndev->name);
  2517. #if defined(RTW_USE_CFG80211_STA_EVENT) || defined(COMPAT_KERNEL_RELEASE)
  2518. cfg80211_del_sta(ndev, da, GFP_ATOMIC);
  2519. #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
  2520. channel = pmlmeext->cur_channel;
  2521. if (channel <= RTW_CH_MAX_2G_CHANNEL)
  2522. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
  2523. else
  2524. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
  2525. pmgmt_frame = mgmt_buf;
  2526. pwlanhdr = (struct rtw_ieee80211_hdr *)pmgmt_frame;
  2527. fctrl = &(pwlanhdr->frame_ctl);
  2528. *(fctrl) = 0;
  2529. //_rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
  2530. //_rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
  2531. _rtw_memcpy(pwlanhdr->addr1, myid(&(padapter->eeprompriv)), ETH_ALEN);
  2532. _rtw_memcpy(pwlanhdr->addr2, da, ETH_ALEN);
  2533. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  2534. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  2535. pmlmeext->mgnt_seq++;
  2536. SetFrameSubType(pmgmt_frame, WIFI_DEAUTH);
  2537. pmgmt_frame += sizeof(struct rtw_ieee80211_hdr_3addr);
  2538. frame_len = sizeof(struct rtw_ieee80211_hdr_3addr);
  2539. reason = cpu_to_le16(reason);
  2540. pmgmt_frame = rtw_set_fixed_ie(pmgmt_frame, _RSON_CODE_ , (unsigned char *)&reason, &frame_len);
  2541. #ifdef COMPAT_KERNEL_RELEASE
  2542. rtw_cfg80211_rx_mgmt(padapter, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
  2543. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  2544. rtw_cfg80211_rx_mgmt(padapter, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
  2545. #else //COMPAT_KERNEL_RELEASE
  2546. cfg80211_send_disassoc(padapter->pnetdev, mgmt_buf, frame_len);
  2547. //cfg80211_rx_action(padapter->pnetdev, freq, mgmt_buf, frame_len, GFP_ATOMIC);
  2548. #endif //COMPAT_KERNEL_RELEASE
  2549. #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
  2550. }
  2551. static int rtw_cfg80211_monitor_if_open(struct net_device *ndev)
  2552. {
  2553. int ret = 0;
  2554. DBG_8192C("%s\n", __func__);
  2555. return ret;
  2556. }
  2557. static int rtw_cfg80211_monitor_if_close(struct net_device *ndev)
  2558. {
  2559. int ret = 0;
  2560. DBG_8192C("%s\n", __func__);
  2561. return ret;
  2562. }
  2563. static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_device *ndev)
  2564. {
  2565. int ret = 0;
  2566. int rtap_len;
  2567. int qos_len = 0;
  2568. int dot11_hdr_len = 24;
  2569. int snap_len = 6;
  2570. unsigned char *pdata;
  2571. u16 frame_ctl;
  2572. unsigned char src_mac_addr[6];
  2573. unsigned char dst_mac_addr[6];
  2574. struct ieee80211_hdr *dot11_hdr;
  2575. struct ieee80211_radiotap_header *rtap_hdr;
  2576. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  2577. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  2578. if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
  2579. goto fail;
  2580. rtap_hdr = (struct ieee80211_radiotap_header *)skb->data;
  2581. if (unlikely(rtap_hdr->it_version))
  2582. goto fail;
  2583. rtap_len = ieee80211_get_radiotap_len(skb->data);
  2584. if (unlikely(skb->len < rtap_len))
  2585. goto fail;
  2586. if(rtap_len != 14)
  2587. {
  2588. DBG_8192C("radiotap len (should be 14): %d\n", rtap_len);
  2589. goto fail;
  2590. }
  2591. /* Skip the ratio tap header */
  2592. skb_pull(skb, rtap_len);
  2593. dot11_hdr = (struct ieee80211_hdr *)skb->data;
  2594. frame_ctl = le16_to_cpu(dot11_hdr->frame_control);
  2595. /* Check if the QoS bit is set */
  2596. if ((frame_ctl & RTW_IEEE80211_FCTL_FTYPE) == RTW_IEEE80211_FTYPE_DATA) {
  2597. /* Check if this ia a Wireless Distribution System (WDS) frame
  2598. * which has 4 MAC addresses
  2599. */
  2600. if (dot11_hdr->frame_control & 0x0080)
  2601. qos_len = 2;
  2602. if ((dot11_hdr->frame_control & 0x0300) == 0x0300)
  2603. dot11_hdr_len += 6;
  2604. memcpy(dst_mac_addr, dot11_hdr->addr1, sizeof(dst_mac_addr));
  2605. memcpy(src_mac_addr, dot11_hdr->addr2, sizeof(src_mac_addr));
  2606. /* Skip the 802.11 header, QoS (if any) and SNAP, but leave spaces for
  2607. * for two MAC addresses
  2608. */
  2609. skb_pull(skb, dot11_hdr_len + qos_len + snap_len - sizeof(src_mac_addr) * 2);
  2610. pdata = (unsigned char*)skb->data;
  2611. memcpy(pdata, dst_mac_addr, sizeof(dst_mac_addr));
  2612. memcpy(pdata + sizeof(dst_mac_addr), src_mac_addr, sizeof(src_mac_addr));
  2613. DBG_8192C("should be eapol packet\n");
  2614. /* Use the real net device to transmit the packet */
  2615. ret = rtw_xmit_entry(skb, padapter->pnetdev);
  2616. return ret;
  2617. }
  2618. else if ((frame_ctl & (RTW_IEEE80211_FCTL_FTYPE|RTW_IEEE80211_FCTL_STYPE))
  2619. == (RTW_IEEE80211_FTYPE_MGMT|RTW_IEEE80211_STYPE_ACTION)
  2620. )
  2621. {
  2622. //only for action frames
  2623. struct xmit_frame *pmgntframe;
  2624. struct pkt_attrib *pattrib;
  2625. unsigned char *pframe;
  2626. //u8 category, action, OUI_Subtype, dialogToken=0;
  2627. //unsigned char *frame_body;
  2628. struct rtw_ieee80211_hdr *pwlanhdr;
  2629. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  2630. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2631. u8 *buf = skb->data;
  2632. u32 len = skb->len;
  2633. u8 category, action;
  2634. int type = -1;
  2635. if (rtw_action_frame_parse(buf, len, &category, &action) == _FALSE) {
  2636. DBG_8192C(FUNC_NDEV_FMT" frame_control:0x%x\n", FUNC_NDEV_ARG(ndev),
  2637. le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl));
  2638. goto fail;
  2639. }
  2640. DBG_8192C("RTW_Tx:da="MAC_FMT" via "FUNC_NDEV_FMT"\n",
  2641. MAC_ARG(GetAddr1Ptr(buf)), FUNC_NDEV_ARG(ndev));
  2642. #ifdef CONFIG_P2P
  2643. if((type = rtw_p2p_check_frames(padapter, buf, len, _TRUE)) >= 0)
  2644. goto dump;
  2645. #endif
  2646. if (category == RTW_WLAN_CATEGORY_PUBLIC)
  2647. DBG_871X("RTW_Tx:%s\n", action_public_str(action));
  2648. else
  2649. DBG_871X("RTW_Tx:category(%u), action(%u)\n", category, action);
  2650. dump:
  2651. //starting alloc mgmt frame to dump it
  2652. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  2653. {
  2654. goto fail;
  2655. }
  2656. //update attribute
  2657. pattrib = &pmgntframe->attrib;
  2658. update_mgntframe_attrib(padapter, pattrib);
  2659. pattrib->retry_ctrl = _FALSE;
  2660. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  2661. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  2662. _rtw_memcpy(pframe, (void*)buf, len);
  2663. #ifdef CONFIG_WFD
  2664. if (type >= 0)
  2665. {
  2666. struct wifi_display_info *pwfd_info;
  2667. pwfd_info = padapter->wdinfo.wfd_info;
  2668. if ( _TRUE == pwfd_info->wfd_enable )
  2669. {
  2670. rtw_append_wfd_ie( padapter, pframe, &len );
  2671. }
  2672. }
  2673. #endif // CONFIG_WFD
  2674. pattrib->pktlen = len;
  2675. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  2676. //update seq number
  2677. pmlmeext->mgnt_seq = GetSequence(pwlanhdr);
  2678. pattrib->seqnum = pmlmeext->mgnt_seq;
  2679. pmlmeext->mgnt_seq++;
  2680. pattrib->last_txcmdsz = pattrib->pktlen;
  2681. dump_mgntframe(padapter, pmgntframe);
  2682. }
  2683. else
  2684. {
  2685. DBG_8192C("frame_ctl=0x%x\n", frame_ctl & (RTW_IEEE80211_FCTL_FTYPE|RTW_IEEE80211_FCTL_STYPE));
  2686. }
  2687. fail:
  2688. dev_kfree_skb(skb);
  2689. return 0;
  2690. }
  2691. static void rtw_cfg80211_monitor_if_set_multicast_list(struct net_device *ndev)
  2692. {
  2693. DBG_8192C("%s\n", __func__);
  2694. }
  2695. static int rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr)
  2696. {
  2697. int ret = 0;
  2698. DBG_8192C("%s\n", __func__);
  2699. return ret;
  2700. }
  2701. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,29))
  2702. static const struct net_device_ops rtw_cfg80211_monitor_if_ops = {
  2703. .ndo_open = rtw_cfg80211_monitor_if_open,
  2704. .ndo_stop = rtw_cfg80211_monitor_if_close,
  2705. .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry,
  2706. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0))
  2707. .ndo_set_multicast_list = rtw_cfg80211_monitor_if_set_multicast_list,
  2708. #endif
  2709. .ndo_set_mac_address = rtw_cfg80211_monitor_if_set_mac_address,
  2710. };
  2711. #endif
  2712. static int rtw_cfg80211_add_monitor_if(_adapter *padapter, char *name, struct net_device **ndev)
  2713. {
  2714. int ret = 0;
  2715. struct net_device* mon_ndev = NULL;
  2716. struct wireless_dev* mon_wdev = NULL;
  2717. struct rtw_netdev_priv_indicator *pnpi;
  2718. struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
  2719. if (!name ) {
  2720. DBG_871X(FUNC_ADPT_FMT" without specific name\n", FUNC_ADPT_ARG(padapter));
  2721. ret = -EINVAL;
  2722. goto out;
  2723. }
  2724. if (pwdev_priv->pmon_ndev) {
  2725. DBG_871X(FUNC_ADPT_FMT" monitor interface exist: "NDEV_FMT"\n",
  2726. FUNC_ADPT_ARG(padapter), NDEV_ARG(pwdev_priv->pmon_ndev));
  2727. ret = -EBUSY;
  2728. goto out;
  2729. }
  2730. mon_ndev = alloc_etherdev(sizeof(struct rtw_netdev_priv_indicator));
  2731. if (!mon_ndev) {
  2732. DBG_871X(FUNC_ADPT_FMT" allocate ndev fail\n", FUNC_ADPT_ARG(padapter));
  2733. ret = -ENOMEM;
  2734. goto out;
  2735. }
  2736. mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP;
  2737. strncpy(mon_ndev->name, name, IFNAMSIZ);
  2738. mon_ndev->name[IFNAMSIZ - 1] = 0;
  2739. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(4,11,9))
  2740. mon_ndev->needs_free_netdev = false;
  2741. mon_ndev->priv_destructor = rtw_ndev_destructor;
  2742. #else
  2743. mon_ndev->destructor = rtw_ndev_destructor;
  2744. #endif
  2745. #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,29))
  2746. mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops;
  2747. #else
  2748. mon_ndev->open = rtw_cfg80211_monitor_if_open;
  2749. mon_ndev->stop = rtw_cfg80211_monitor_if_close;
  2750. mon_ndev->hard_start_xmit = rtw_cfg80211_monitor_if_xmit_entry;
  2751. mon_ndev->set_mac_address = rtw_cfg80211_monitor_if_set_mac_address;
  2752. #endif
  2753. pnpi = netdev_priv(mon_ndev);
  2754. pnpi->priv = padapter;
  2755. pnpi->sizeof_priv = sizeof(_adapter);
  2756. /* wdev */
  2757. mon_wdev = (struct wireless_dev *)rtw_zmalloc(sizeof(struct wireless_dev));
  2758. if (!mon_wdev) {
  2759. DBG_871X(FUNC_ADPT_FMT" allocate mon_wdev fail\n", FUNC_ADPT_ARG(padapter));
  2760. ret = -ENOMEM;
  2761. goto out;
  2762. }
  2763. mon_wdev->wiphy = padapter->rtw_wdev->wiphy;
  2764. mon_wdev->netdev = mon_ndev;
  2765. mon_wdev->iftype = NL80211_IFTYPE_MONITOR;
  2766. mon_ndev->ieee80211_ptr = mon_wdev;
  2767. ret = register_netdevice(mon_ndev);
  2768. if (ret) {
  2769. goto out;
  2770. }
  2771. *ndev = pwdev_priv->pmon_ndev = mon_ndev;
  2772. _rtw_memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ+1);
  2773. out:
  2774. if (ret && mon_wdev) {
  2775. rtw_mfree((u8*)mon_wdev, sizeof(struct wireless_dev));
  2776. mon_wdev = NULL;
  2777. }
  2778. if (ret && mon_ndev) {
  2779. free_netdev(mon_ndev);
  2780. *ndev = mon_ndev = NULL;
  2781. }
  2782. return ret;
  2783. }
  2784. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
  2785. static struct wireless_dev *
  2786. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
  2787. static struct net_device *
  2788. #else
  2789. static int
  2790. #endif
  2791. cfg80211_rtw_add_virtual_intf(
  2792. struct wiphy *wiphy,
  2793. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0))
  2794. const char *name,
  2795. #else
  2796. char *name,
  2797. #endif
  2798. enum nl80211_iftype type, u32 *flags, struct vif_params *params)
  2799. {
  2800. int ret = 0;
  2801. struct net_device* ndev = NULL;
  2802. _adapter *padapter = wiphy_to_adapter(wiphy);
  2803. DBG_871X(FUNC_ADPT_FMT " wiphy:%s, name:%s, type:%d\n",
  2804. FUNC_ADPT_ARG(padapter), wiphy_name(wiphy), name, type);
  2805. switch (type) {
  2806. case NL80211_IFTYPE_ADHOC:
  2807. case NL80211_IFTYPE_AP_VLAN:
  2808. case NL80211_IFTYPE_WDS:
  2809. case NL80211_IFTYPE_MESH_POINT:
  2810. ret = -ENODEV;
  2811. break;
  2812. case NL80211_IFTYPE_MONITOR:
  2813. ret = rtw_cfg80211_add_monitor_if(padapter, (char *)name, &ndev);
  2814. break;
  2815. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  2816. case NL80211_IFTYPE_P2P_CLIENT:
  2817. #endif
  2818. case NL80211_IFTYPE_STATION:
  2819. ret = -ENODEV;
  2820. break;
  2821. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  2822. case NL80211_IFTYPE_P2P_GO:
  2823. #endif
  2824. case NL80211_IFTYPE_AP:
  2825. ret = -ENODEV;
  2826. break;
  2827. default:
  2828. ret = -ENODEV;
  2829. DBG_871X("Unsupported interface type\n");
  2830. break;
  2831. }
  2832. DBG_871X(FUNC_ADPT_FMT" ndev:%p, ret:%d\n", FUNC_ADPT_ARG(padapter), ndev, ret);
  2833. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
  2834. return ndev ? ndev->ieee80211_ptr : ERR_PTR(ret);
  2835. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
  2836. return ndev ? ndev : ERR_PTR(ret);
  2837. #else
  2838. return ret;
  2839. #endif
  2840. }
  2841. static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy,
  2842. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
  2843. struct wireless_dev *wdev
  2844. #else
  2845. struct net_device *ndev
  2846. #endif
  2847. )
  2848. {
  2849. struct rtw_wdev_priv *pwdev_priv = (struct rtw_wdev_priv *)wiphy_priv(wiphy);
  2850. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
  2851. struct net_device *ndev;
  2852. ndev = wdev ? wdev->netdev : NULL;
  2853. #endif
  2854. if (!ndev)
  2855. goto exit;
  2856. unregister_netdevice(ndev);
  2857. if (ndev == pwdev_priv->pmon_ndev) {
  2858. pwdev_priv->pmon_ndev = NULL;
  2859. pwdev_priv->ifname_mon[0] = '\0';
  2860. DBG_871X(FUNC_NDEV_FMT" remove monitor interface\n", FUNC_NDEV_ARG(ndev));
  2861. }
  2862. exit:
  2863. return 0;
  2864. }
  2865. static int rtw_add_beacon(_adapter *adapter, const u8 *head, size_t head_len, const u8 *tail, size_t tail_len)
  2866. {
  2867. int ret=0;
  2868. u8 *pbuf = NULL;
  2869. uint len, wps_ielen=0;
  2870. uint p2p_ielen=0;
  2871. u8 *p2p_ie;
  2872. u8 got_p2p_ie = _FALSE;
  2873. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  2874. //struct sta_priv *pstapriv = &padapter->stapriv;
  2875. DBG_8192C("%s beacon_head_len=%zu, beacon_tail_len=%zu\n", __FUNCTION__, head_len, tail_len);
  2876. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  2877. return -EINVAL;
  2878. if(head_len<24)
  2879. return -EINVAL;
  2880. pbuf = rtw_zmalloc(head_len+tail_len);
  2881. if(!pbuf)
  2882. return -ENOMEM;
  2883. //_rtw_memcpy(&pstapriv->max_num_sta, param->u.bcn_ie.reserved, 2);
  2884. //if((pstapriv->max_num_sta>NUM_STA) || (pstapriv->max_num_sta<=0))
  2885. // pstapriv->max_num_sta = NUM_STA;
  2886. _rtw_memcpy(pbuf, (void *)head+24, head_len-24);// 24=beacon header len.
  2887. _rtw_memcpy(pbuf+head_len-24, (void *)tail, tail_len);
  2888. len = head_len+tail_len-24;
  2889. //check wps ie if inclued
  2890. if(rtw_get_wps_ie(pbuf+_FIXED_IE_LENGTH_, len-_FIXED_IE_LENGTH_, NULL, &wps_ielen))
  2891. DBG_8192C("add bcn, wps_ielen=%d\n", wps_ielen);
  2892. #ifdef CONFIG_P2P
  2893. if( adapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  2894. {
  2895. if(rtw_get_p2p_ie(pbuf+_FIXED_IE_LENGTH_, len-_FIXED_IE_LENGTH_, NULL, &p2p_ielen))
  2896. {
  2897. DBG_8192C("got p2p_ie, len=%d\n", p2p_ielen);
  2898. got_p2p_ie = _TRUE;
  2899. }
  2900. }
  2901. #endif
  2902. /* pbss_network->IEs will not include p2p_ie, wfd ie */
  2903. rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, P2P_OUI, 4);
  2904. rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, WFD_OUI, 4);
  2905. if (rtw_check_beacon_data(adapter, pbuf, len) == _SUCCESS) {
  2906. #ifdef CONFIG_P2P
  2907. //check p2p if enable
  2908. if(got_p2p_ie == _TRUE)
  2909. {
  2910. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  2911. struct wifidirect_info *pwdinfo= &(adapter->wdinfo);
  2912. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  2913. {
  2914. DBG_8192C("Enable P2P function for the first time\n");
  2915. rtw_p2p_enable(adapter, P2P_ROLE_GO);
  2916. wdev_to_priv(adapter->rtw_wdev)->p2p_enabled = _TRUE;
  2917. }
  2918. else
  2919. {
  2920. _cancel_timer_ex( &pwdinfo->find_phase_timer );
  2921. _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
  2922. _cancel_timer_ex( &pwdinfo->pre_tx_scan_timer);
  2923. DBG_8192C("enter GO Mode, p2p_ielen=%d\n", p2p_ielen);
  2924. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  2925. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  2926. pwdinfo->intent = 15;
  2927. }
  2928. pwdinfo->operating_channel = pmlmeext->cur_channel;
  2929. }
  2930. #endif //CONFIG_P2P
  2931. ret = 0;
  2932. }
  2933. else
  2934. {
  2935. ret = -EINVAL;
  2936. }
  2937. rtw_mfree(pbuf, head_len+tail_len);
  2938. return ret;
  2939. }
  2940. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) && !defined(COMPAT_KERNEL_RELEASE)
  2941. static int cfg80211_rtw_add_beacon(struct wiphy *wiphy, struct net_device *ndev,
  2942. struct beacon_parameters *info)
  2943. {
  2944. int ret=0;
  2945. _adapter *adapter = wiphy_to_adapter(wiphy);
  2946. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  2947. ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
  2948. return ret;
  2949. }
  2950. static int cfg80211_rtw_set_beacon(struct wiphy *wiphy, struct net_device *ndev,
  2951. struct beacon_parameters *info)
  2952. {
  2953. _adapter *padapter = wiphy_to_adapter(wiphy);
  2954. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2955. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  2956. pmlmeext->bstart_bss = _TRUE;
  2957. cfg80211_rtw_add_beacon(wiphy, ndev, info);
  2958. return 0;
  2959. }
  2960. static int cfg80211_rtw_del_beacon(struct wiphy *wiphy, struct net_device *ndev)
  2961. {
  2962. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  2963. return 0;
  2964. }
  2965. #else
  2966. static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev,
  2967. struct cfg80211_ap_settings *settings)
  2968. {
  2969. int ret = 0;
  2970. _adapter *adapter = wiphy_to_adapter(wiphy);
  2971. DBG_871X(FUNC_NDEV_FMT" hidden_ssid:%d, auth_type:%d\n", FUNC_NDEV_ARG(ndev),
  2972. settings->hidden_ssid, settings->auth_type);
  2973. ret = rtw_add_beacon(adapter, settings->beacon.head, settings->beacon.head_len,
  2974. settings->beacon.tail, settings->beacon.tail_len);
  2975. adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode = settings->hidden_ssid;
  2976. if (settings->ssid && settings->ssid_len) {
  2977. WLAN_BSSID_EX *pbss_network = &adapter->mlmepriv.cur_network.network;
  2978. WLAN_BSSID_EX *pbss_network_ext = &adapter->mlmeextpriv.mlmext_info.network;
  2979. if(0)
  2980. DBG_871X(FUNC_ADPT_FMT" ssid:(%s,%d), from ie:(%s,%d)\n", FUNC_ADPT_ARG(adapter),
  2981. settings->ssid, settings->ssid_len,
  2982. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength);
  2983. _rtw_memcpy(pbss_network->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len);
  2984. pbss_network->Ssid.SsidLength = settings->ssid_len;
  2985. _rtw_memcpy(pbss_network_ext->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len);
  2986. pbss_network_ext->Ssid.SsidLength = settings->ssid_len;
  2987. if(0)
  2988. DBG_871X(FUNC_ADPT_FMT" after ssid:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
  2989. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
  2990. pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
  2991. }
  2992. return ret;
  2993. }
  2994. static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
  2995. struct cfg80211_beacon_data *info)
  2996. {
  2997. int ret = 0;
  2998. _adapter *adapter = wiphy_to_adapter(wiphy);
  2999. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3000. ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
  3001. return ret;
  3002. }
  3003. static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
  3004. {
  3005. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3006. return 0;
  3007. }
  3008. #endif //(LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
  3009. static int cfg80211_rtw_add_station(struct wiphy *wiphy, struct net_device *ndev,
  3010. u8 *mac, struct station_parameters *params)
  3011. {
  3012. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3013. return 0;
  3014. }
  3015. static int cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev,
  3016. u8 *mac)
  3017. {
  3018. int ret=0;
  3019. _irqL irqL;
  3020. _list *phead, *plist;
  3021. u8 updated;
  3022. struct sta_info *psta = NULL;
  3023. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3024. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3025. struct sta_priv *pstapriv = &padapter->stapriv;
  3026. DBG_871X("+"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3027. if(check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != _TRUE)
  3028. {
  3029. DBG_8192C("%s, fw_state != FW_LINKED|WIFI_AP_STATE\n", __func__);
  3030. return -EINVAL;
  3031. }
  3032. if(!mac)
  3033. {
  3034. DBG_8192C("flush all sta, and cam_entry\n");
  3035. flush_all_cam_entry(padapter); //clear CAM
  3036. ret = rtw_sta_flush(padapter);
  3037. return ret;
  3038. }
  3039. DBG_8192C("free sta macaddr =" MAC_FMT "\n", MAC_ARG(mac));
  3040. if (mac[0] == 0xff && mac[1] == 0xff &&
  3041. mac[2] == 0xff && mac[3] == 0xff &&
  3042. mac[4] == 0xff && mac[5] == 0xff)
  3043. {
  3044. return -EINVAL;
  3045. }
  3046. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3047. phead = &pstapriv->asoc_list;
  3048. plist = get_next(phead);
  3049. //check asoc_queue
  3050. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  3051. {
  3052. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  3053. plist = get_next(plist);
  3054. if(_rtw_memcmp(mac, psta->hwaddr, ETH_ALEN))
  3055. {
  3056. if(psta->dot8021xalg == 1 && psta->bpairwise_key_installed == _FALSE)
  3057. {
  3058. DBG_8192C("%s, sta's dot8021xalg = 1 and key_installed = _FALSE\n", __func__);
  3059. }
  3060. else
  3061. {
  3062. DBG_8192C("free psta=%p, aid=%d\n", psta, psta->aid);
  3063. rtw_list_delete(&psta->asoc_list);
  3064. pstapriv->asoc_list_cnt--;
  3065. //_exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3066. updated = ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING);
  3067. //_enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3068. psta = NULL;
  3069. break;
  3070. }
  3071. }
  3072. }
  3073. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3074. associated_clients_update(padapter, updated);
  3075. DBG_871X("-"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3076. return ret;
  3077. }
  3078. static int cfg80211_rtw_change_station(struct wiphy *wiphy, struct net_device *ndev,
  3079. u8 *mac, struct station_parameters *params)
  3080. {
  3081. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3082. return 0;
  3083. }
  3084. static int cfg80211_rtw_dump_station(struct wiphy *wiphy, struct net_device *ndev,
  3085. int idx, u8 *mac, struct station_info *sinfo)
  3086. {
  3087. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3088. //TODO: dump scanned queue
  3089. return -ENOENT;
  3090. }
  3091. static int cfg80211_rtw_change_bss(struct wiphy *wiphy, struct net_device *ndev,
  3092. struct bss_parameters *params)
  3093. {
  3094. u8 i;
  3095. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3096. /*
  3097. DBG_8192C("use_cts_prot=%d\n", params->use_cts_prot);
  3098. DBG_8192C("use_short_preamble=%d\n", params->use_short_preamble);
  3099. DBG_8192C("use_short_slot_time=%d\n", params->use_short_slot_time);
  3100. DBG_8192C("ap_isolate=%d\n", params->ap_isolate);
  3101. DBG_8192C("basic_rates_len=%d\n", params->basic_rates_len);
  3102. for(i=0; i<params->basic_rates_len; i++)
  3103. {
  3104. DBG_8192C("basic_rates=%d\n", params->basic_rates[i]);
  3105. }
  3106. */
  3107. return 0;
  3108. }
  3109. static int cfg80211_rtw_set_channel(struct wiphy *wiphy
  3110. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
  3111. , struct net_device *ndev
  3112. #endif
  3113. , struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
  3114. {
  3115. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
  3116. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3117. #endif
  3118. return 0;
  3119. }
  3120. static int cfg80211_rtw_auth(struct wiphy *wiphy, struct net_device *ndev,
  3121. struct cfg80211_auth_request *req)
  3122. {
  3123. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3124. return 0;
  3125. }
  3126. static int cfg80211_rtw_assoc(struct wiphy *wiphy, struct net_device *ndev,
  3127. struct cfg80211_assoc_request *req)
  3128. {
  3129. DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3130. return 0;
  3131. }
  3132. #endif //CONFIG_AP_MODE
  3133. void rtw_cfg80211_rx_action_p2p(_adapter *padapter, u8 *pmgmt_frame, uint frame_len)
  3134. {
  3135. int type;
  3136. s32 freq;
  3137. int channel;
  3138. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3139. u8 category, action;
  3140. channel = rtw_get_oper_ch(padapter);
  3141. DBG_8192C("RTW_Rx:cur_ch=%d\n", channel);
  3142. #ifdef CONFIG_P2P
  3143. type = rtw_p2p_check_frames(padapter, pmgmt_frame, frame_len, _FALSE);
  3144. if (type >= 0)
  3145. goto indicate;
  3146. #endif
  3147. rtw_action_frame_parse(pmgmt_frame, frame_len, &category, &action);
  3148. DBG_871X("RTW_Rx:category(%u), action(%u)\n", category, action);
  3149. indicate:
  3150. if (channel <= RTW_CH_MAX_2G_CHANNEL)
  3151. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
  3152. else
  3153. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
  3154. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  3155. rtw_cfg80211_rx_mgmt(padapter, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
  3156. #else
  3157. cfg80211_rx_action(padapter->pnetdev, freq, pmgmt_frame, frame_len, GFP_ATOMIC);
  3158. #endif
  3159. }
  3160. void rtw_cfg80211_rx_p2p_action_public(_adapter *padapter, u8 *pmgmt_frame, uint frame_len)
  3161. {
  3162. int type;
  3163. s32 freq;
  3164. int channel;
  3165. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3166. u8 category, action;
  3167. channel = rtw_get_oper_ch(padapter);
  3168. DBG_8192C("RTW_Rx:cur_ch=%d\n", channel);
  3169. #ifdef CONFIG_P2P
  3170. type = rtw_p2p_check_frames(padapter, pmgmt_frame, frame_len, _FALSE);
  3171. if (type >= 0) {
  3172. switch (type) {
  3173. case P2P_GO_NEGO_CONF:
  3174. case P2P_PROVISION_DISC_RESP:
  3175. rtw_clear_scan_deny(padapter);
  3176. }
  3177. goto indicate;
  3178. }
  3179. #endif
  3180. rtw_action_frame_parse(pmgmt_frame, frame_len, &category, &action);
  3181. DBG_871X("RTW_Rx:category(%u), action(%u)\n", category, action);
  3182. indicate:
  3183. if (channel <= RTW_CH_MAX_2G_CHANNEL)
  3184. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
  3185. else
  3186. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
  3187. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  3188. rtw_cfg80211_rx_mgmt(padapter, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
  3189. #else
  3190. cfg80211_rx_action(padapter->pnetdev, freq, pmgmt_frame, frame_len, GFP_ATOMIC);
  3191. #endif
  3192. }
  3193. void rtw_cfg80211_rx_action(_adapter *adapter, u8 *frame, uint frame_len, const char*msg)
  3194. {
  3195. s32 freq;
  3196. int channel;
  3197. struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
  3198. struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(adapter->rtw_wdev);
  3199. u8 category, action;
  3200. channel = rtw_get_oper_ch(adapter);
  3201. rtw_action_frame_parse(frame, frame_len, &category, &action);
  3202. DBG_8192C("RTW_Rx:cur_ch=%d\n", channel);
  3203. if (msg)
  3204. DBG_871X("RTW_Rx:%s\n", msg);
  3205. else
  3206. DBG_871X("RTW_Rx:category(%u), action(%u)\n", category, action);
  3207. if (channel <= RTW_CH_MAX_2G_CHANNEL)
  3208. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
  3209. else
  3210. freq = rtw_ieee80211_channel_to_frequency(channel, IEEE80211_BAND_5GHZ);
  3211. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  3212. rtw_cfg80211_rx_mgmt(adapter, freq, 0, frame, frame_len, GFP_ATOMIC);
  3213. #else
  3214. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  3215. #endif
  3216. }
  3217. #ifdef CONFIG_P2P
  3218. void rtw_cfg80211_issue_p2p_provision_request(_adapter *padapter, const u8 *buf, size_t len)
  3219. {
  3220. u16 wps_devicepassword_id = 0x0000;
  3221. uint wps_devicepassword_id_len = 0;
  3222. u8 wpsie[ 255 ] = { 0x00 }, p2p_ie[ 255 ] = { 0x00 };
  3223. uint p2p_ielen = 0;
  3224. uint wpsielen = 0;
  3225. u32 devinfo_contentlen = 0;
  3226. u8 devinfo_content[64] = { 0x00 };
  3227. u16 capability = 0;
  3228. uint capability_len = 0;
  3229. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  3230. u8 action = P2P_PUB_ACTION_ACTION;
  3231. u8 dialogToken = 1;
  3232. u32 p2poui = cpu_to_be32(P2POUI);
  3233. u8 oui_subtype = P2P_PROVISION_DISC_REQ;
  3234. u32 p2pielen = 0;
  3235. #ifdef CONFIG_WFD
  3236. u32 wfdielen = 0;
  3237. #endif //CONFIG_WFD
  3238. struct xmit_frame *pmgntframe;
  3239. struct pkt_attrib *pattrib;
  3240. unsigned char *pframe;
  3241. struct rtw_ieee80211_hdr *pwlanhdr;
  3242. unsigned short *fctrl;
  3243. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  3244. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3245. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3246. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3247. u8 *frame_body = (unsigned char *)(buf + sizeof(struct rtw_ieee80211_hdr_3addr));
  3248. size_t frame_body_len = len - sizeof(struct rtw_ieee80211_hdr_3addr);
  3249. DBG_871X( "[%s] In\n", __FUNCTION__ );
  3250. //prepare for building provision_request frame
  3251. _rtw_memcpy(pwdinfo->tx_prov_disc_info.peerIFAddr, GetAddr1Ptr(buf), ETH_ALEN);
  3252. _rtw_memcpy(pwdinfo->tx_prov_disc_info.peerDevAddr, GetAddr1Ptr(buf), ETH_ALEN);
  3253. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
  3254. rtw_get_wps_ie( frame_body + _PUBLIC_ACTION_IE_OFFSET_, frame_body_len - _PUBLIC_ACTION_IE_OFFSET_, wpsie, &wpsielen);
  3255. rtw_get_wps_attr_content( wpsie, wpsielen, WPS_ATTR_DEVICE_PWID, (u8*) &wps_devicepassword_id, &wps_devicepassword_id_len);
  3256. wps_devicepassword_id = be16_to_cpu( wps_devicepassword_id );
  3257. switch(wps_devicepassword_id)
  3258. {
  3259. case WPS_DPID_PIN:
  3260. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_LABEL;
  3261. break;
  3262. case WPS_DPID_USER_SPEC:
  3263. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_DISPLYA;
  3264. break;
  3265. case WPS_DPID_MACHINE_SPEC:
  3266. break;
  3267. case WPS_DPID_REKEY:
  3268. break;
  3269. case WPS_DPID_PBC:
  3270. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
  3271. break;
  3272. case WPS_DPID_REGISTRAR_SPEC:
  3273. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_KEYPAD;
  3274. break;
  3275. default:
  3276. break;
  3277. }
  3278. if ( rtw_get_p2p_ie( frame_body + _PUBLIC_ACTION_IE_OFFSET_, frame_body_len - _PUBLIC_ACTION_IE_OFFSET_, p2p_ie, &p2p_ielen ) )
  3279. {
  3280. rtw_get_p2p_attr_content( p2p_ie, p2p_ielen, P2P_ATTR_DEVICE_INFO, devinfo_content, &devinfo_contentlen);
  3281. rtw_get_p2p_attr_content( p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8*)&capability, &capability_len);
  3282. }
  3283. //start to build provision_request frame
  3284. _rtw_memset(wpsie, 0, sizeof(wpsie));
  3285. _rtw_memset(p2p_ie, 0, sizeof(p2p_ie));
  3286. p2p_ielen = 0;
  3287. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  3288. {
  3289. return;
  3290. }
  3291. //update attribute
  3292. pattrib = &pmgntframe->attrib;
  3293. update_mgntframe_attrib(padapter, pattrib);
  3294. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  3295. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  3296. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  3297. fctrl = &(pwlanhdr->frame_ctl);
  3298. *(fctrl) = 0;
  3299. _rtw_memcpy(pwlanhdr->addr1, pwdinfo->tx_prov_disc_info.peerDevAddr, ETH_ALEN);
  3300. _rtw_memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
  3301. _rtw_memcpy(pwlanhdr->addr3, pwdinfo->tx_prov_disc_info.peerDevAddr, ETH_ALEN);
  3302. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  3303. pmlmeext->mgnt_seq++;
  3304. SetFrameSubType(pframe, WIFI_ACTION);
  3305. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  3306. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  3307. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  3308. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  3309. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  3310. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  3311. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  3312. //build_prov_disc_request_p2p_ie
  3313. // P2P OUI
  3314. p2pielen = 0;
  3315. p2p_ie[ p2pielen++ ] = 0x50;
  3316. p2p_ie[ p2pielen++ ] = 0x6F;
  3317. p2p_ie[ p2pielen++ ] = 0x9A;
  3318. p2p_ie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
  3319. // Commented by Albert 20110301
  3320. // According to the P2P Specification, the provision discovery request frame should contain 3 P2P attributes
  3321. // 1. P2P Capability
  3322. // 2. Device Info
  3323. // 3. Group ID ( When joining an operating P2P Group )
  3324. // P2P Capability ATTR
  3325. // Type:
  3326. p2p_ie[ p2pielen++ ] = P2P_ATTR_CAPABILITY;
  3327. // Length:
  3328. //*(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 );
  3329. RTW_PUT_LE16(p2p_ie + p2pielen, 0x0002);
  3330. p2pielen += 2;
  3331. // Value:
  3332. // Device Capability Bitmap, 1 byte
  3333. // Group Capability Bitmap, 1 byte
  3334. _rtw_memcpy(p2p_ie + p2pielen, &capability, 2);
  3335. p2pielen += 2;
  3336. // Device Info ATTR
  3337. // Type:
  3338. p2p_ie[ p2pielen++ ] = P2P_ATTR_DEVICE_INFO;
  3339. // Length:
  3340. // 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes)
  3341. // + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes)
  3342. //*(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 21 + pwdinfo->device_name_len );
  3343. RTW_PUT_LE16(p2p_ie + p2pielen, devinfo_contentlen);
  3344. p2pielen += 2;
  3345. // Value:
  3346. _rtw_memcpy(p2p_ie + p2pielen, devinfo_content, devinfo_contentlen);
  3347. p2pielen += devinfo_contentlen;
  3348. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2p_ie, &p2p_ielen);
  3349. //p2pielen = build_prov_disc_request_p2p_ie( pwdinfo, pframe, NULL, 0, pwdinfo->tx_prov_disc_info.peerDevAddr);
  3350. //pframe += p2pielen;
  3351. pattrib->pktlen += p2p_ielen;
  3352. wpsielen = 0;
  3353. // WPS OUI
  3354. *(u32*) ( wpsie ) = cpu_to_be32( WPSOUI );
  3355. wpsielen += 4;
  3356. // WPS version
  3357. // Type:
  3358. *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_VER1 );
  3359. wpsielen += 2;
  3360. // Length:
  3361. *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
  3362. wpsielen += 2;
  3363. // Value:
  3364. wpsie[wpsielen++] = WPS_VERSION_1; // Version 1.0
  3365. // Config Method
  3366. // Type:
  3367. *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_CONF_METHOD );
  3368. wpsielen += 2;
  3369. // Length:
  3370. *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0002 );
  3371. wpsielen += 2;
  3372. // Value:
  3373. *(u16*) ( wpsie + wpsielen ) = cpu_to_be16( pwdinfo->tx_prov_disc_info.wps_config_method_request );
  3374. wpsielen += 2;
  3375. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen );
  3376. #ifdef CONFIG_WFD
  3377. wfdielen = build_provdisc_req_wfd_ie(pwdinfo, pframe);
  3378. pframe += wfdielen;
  3379. pattrib->pktlen += wfdielen;
  3380. #endif //CONFIG_WFD
  3381. pattrib->last_txcmdsz = pattrib->pktlen;
  3382. //dump_mgntframe(padapter, pmgntframe);
  3383. if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS)
  3384. DBG_8192C("%s, ack to\n", __func__);
  3385. //if(wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
  3386. //{
  3387. // DBG_8192C("waiting for p2p peer key-in PIN CODE\n");
  3388. // rtw_msleep_os(15000); // 15 sec for key in PIN CODE, workaround for GS2 before issuing Nego Req.
  3389. //}
  3390. }
  3391. static s32 cfg80211_rtw_remain_on_channel(struct wiphy *wiphy,
  3392. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
  3393. struct wireless_dev *wdev,
  3394. #else
  3395. struct net_device *ndev,
  3396. #endif
  3397. struct ieee80211_channel * channel,
  3398. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
  3399. enum nl80211_channel_type channel_type,
  3400. #endif
  3401. unsigned int duration, u64 *cookie)
  3402. {
  3403. s32 err = 0;
  3404. _adapter *padapter = wiphy_to_adapter(wiphy);
  3405. struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
  3406. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3407. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  3408. struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  3409. u8 remain_ch = (u8) ieee80211_frequency_to_channel(channel->center_freq);
  3410. u8 ready_on_channel = _FALSE;
  3411. DBG_871X(FUNC_ADPT_FMT" ch:%u duration:%d\n", FUNC_ADPT_ARG(padapter), remain_ch, duration);
  3412. if(pcfg80211_wdinfo->is_ro_ch == _TRUE)
  3413. {
  3414. DBG_8192C("%s, cancel ro ch timer\n", __func__);
  3415. _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
  3416. #ifdef CONFIG_CONCURRENT_MODE
  3417. ATOMIC_SET(&pwdev_priv->ro_ch_to, 1);
  3418. #endif //CONFIG_CONCURRENT_MODE
  3419. p2p_protocol_wk_hdl(padapter, P2P_RO_CH_WK);
  3420. }
  3421. pcfg80211_wdinfo->is_ro_ch = _TRUE;
  3422. if(_FAIL == rtw_pwr_wakeup(padapter)) {
  3423. err = -EFAULT;
  3424. goto exit;
  3425. }
  3426. _rtw_memcpy(&pcfg80211_wdinfo->remain_on_ch_channel, channel, sizeof(struct ieee80211_channel));
  3427. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
  3428. pcfg80211_wdinfo->remain_on_ch_type= channel_type;
  3429. #endif
  3430. pcfg80211_wdinfo->remain_on_ch_cookie= *cookie;
  3431. rtw_scan_abort(padapter);
  3432. #ifdef CONFIG_CONCURRENT_MODE
  3433. if(rtw_buddy_adapter_up(padapter))
  3434. rtw_scan_abort(padapter->pbuddy_adapter);
  3435. #endif //CONFIG_CONCURRENT_MODE
  3436. //if(!rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) && !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
  3437. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3438. {
  3439. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  3440. wdev_to_priv(padapter->rtw_wdev)->p2p_enabled = _TRUE;
  3441. }
  3442. else
  3443. {
  3444. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  3445. #ifdef CONFIG_DEBUG_CFG80211
  3446. DBG_8192C("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  3447. #endif
  3448. }
  3449. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  3450. if(duration < 400)
  3451. duration = duration*3;//extend from exper.
  3452. #ifdef CONFIG_CONCURRENT_MODE
  3453. if(check_buddy_fwstate(padapter, _FW_LINKED) &&
  3454. (duration<pwdinfo->ext_listen_interval))
  3455. {
  3456. duration = duration + pwdinfo->ext_listen_interval;
  3457. }
  3458. #endif
  3459. pcfg80211_wdinfo->restore_channel = pmlmeext->cur_channel;
  3460. if(rtw_ch_set_search_ch(pmlmeext->channel_set, remain_ch) >= 0) {
  3461. #ifdef CONFIG_CONCURRENT_MODE
  3462. if ( check_buddy_fwstate(padapter, _FW_LINKED ) )
  3463. {
  3464. PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
  3465. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  3466. if(remain_ch != pbuddy_mlmeext->cur_channel)
  3467. {
  3468. if(ATOMIC_READ(&pwdev_priv->switch_ch_to)==1 ||
  3469. (remain_ch != pmlmeext->cur_channel))
  3470. {
  3471. DBG_8192C("%s, issue nulldata pwrbit=1\n", __func__);
  3472. issue_nulldata(padapter->pbuddy_adapter, NULL, 1, 3, 500);
  3473. ATOMIC_SET(&pwdev_priv->switch_ch_to, 0);
  3474. DBG_8192C("%s, set switch ch timer, duration=%d\n", __func__, duration-pwdinfo->ext_listen_interval);
  3475. _set_timer(&pwdinfo->ap_p2p_switch_timer, duration-pwdinfo->ext_listen_interval);
  3476. }
  3477. }
  3478. ready_on_channel = _TRUE;
  3479. //pmlmeext->cur_channel = remain_ch;
  3480. //set_channel_bwmode(padapter, remain_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  3481. }else
  3482. #endif //CONFIG_CONCURRENT_MODE
  3483. if(remain_ch != pmlmeext->cur_channel )
  3484. {
  3485. ready_on_channel = _TRUE;
  3486. //pmlmeext->cur_channel = remain_ch;
  3487. //set_channel_bwmode(padapter, remain_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  3488. }
  3489. } else {
  3490. DBG_871X("%s remain_ch:%u not in channel plan!!!!\n", __FUNCTION__, remain_ch);
  3491. }
  3492. //call this after other things have been done
  3493. #ifdef CONFIG_CONCURRENT_MODE
  3494. if(ATOMIC_READ(&pwdev_priv->ro_ch_to)==1 ||
  3495. (remain_ch != pmlmeext->cur_channel))
  3496. {
  3497. u8 co_channel = 0xff;
  3498. ATOMIC_SET(&pwdev_priv->ro_ch_to, 0);
  3499. #endif
  3500. if(ready_on_channel == _TRUE)
  3501. {
  3502. if ( !check_fwstate(&padapter->mlmepriv, _FW_LINKED ) )
  3503. pmlmeext->cur_channel = remain_ch;
  3504. #ifdef CONFIG_CONCURRENT_MODE
  3505. co_channel = rtw_get_oper_ch(padapter);
  3506. if(co_channel !=remain_ch)
  3507. #endif
  3508. {
  3509. if (!padapter->mlmepriv.LinkDetectInfo.bBusyTraffic)
  3510. set_channel_bwmode(padapter, remain_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  3511. }
  3512. }
  3513. DBG_8192C("%s, set ro ch timer, duration=%d\n", __func__, duration);
  3514. _set_timer( &pcfg80211_wdinfo->remain_on_ch_timer, duration);
  3515. #ifdef CONFIG_CONCURRENT_MODE
  3516. }
  3517. #endif
  3518. rtw_cfg80211_ready_on_channel(padapter, *cookie, channel, channel_type, duration, GFP_KERNEL);
  3519. pwdinfo->listen_channel = pmlmeext->cur_channel;
  3520. exit:
  3521. if (err)
  3522. pcfg80211_wdinfo->is_ro_ch = _FALSE;
  3523. return err;
  3524. }
  3525. static s32 cfg80211_rtw_cancel_remain_on_channel(struct wiphy *wiphy,
  3526. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
  3527. struct wireless_dev *wdev,
  3528. #else
  3529. struct net_device *ndev,
  3530. #endif
  3531. u64 cookie)
  3532. {
  3533. s32 err = 0;
  3534. _adapter *padapter = wiphy_to_adapter(wiphy);
  3535. struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
  3536. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  3537. struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
  3538. struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  3539. DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  3540. if (pcfg80211_wdinfo->is_ro_ch == _TRUE) {
  3541. DBG_8192C("%s, cancel ro ch timer\n", __func__);
  3542. _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
  3543. #ifdef CONFIG_CONCURRENT_MODE
  3544. ATOMIC_SET(&pwdev_priv->ro_ch_to, 1);
  3545. #endif
  3546. p2p_protocol_wk_hdl(padapter, P2P_RO_CH_WK);
  3547. }
  3548. #if 0
  3549. // Disable P2P Listen State
  3550. if(!rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) && !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
  3551. {
  3552. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3553. {
  3554. _cancel_timer_ex( &pwdinfo->find_phase_timer );
  3555. _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
  3556. _cancel_timer_ex( &pwdinfo->pre_tx_scan_timer);
  3557. rtw_p2p_set_state(pwdinfo, P2P_STATE_NONE);
  3558. _rtw_memset(pwdinfo, 0x00, sizeof(struct wifidirect_info));
  3559. }
  3560. }
  3561. else
  3562. #endif
  3563. {
  3564. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  3565. #ifdef CONFIG_DEBUG_CFG80211
  3566. DBG_8192C("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  3567. #endif
  3568. }
  3569. pcfg80211_wdinfo->is_ro_ch = _FALSE;
  3570. return err;
  3571. }
  3572. #endif //CONFIG_P2P
  3573. static int _cfg80211_rtw_mgmt_tx(_adapter *padapter, u8 tx_ch, const u8 *buf, size_t len)
  3574. {
  3575. struct xmit_frame *pmgntframe;
  3576. struct pkt_attrib *pattrib;
  3577. unsigned char *pframe;
  3578. int ret = _FAIL;
  3579. bool ack = _TRUE;
  3580. struct rtw_ieee80211_hdr *pwlanhdr;
  3581. struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
  3582. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  3583. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3584. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3585. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  3586. //struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  3587. if(_FAIL == rtw_pwr_wakeup(padapter)) {
  3588. ret = -EFAULT;
  3589. goto exit;
  3590. }
  3591. rtw_set_scan_deny(padapter, 1000);
  3592. rtw_scan_abort(padapter);
  3593. #ifdef CONFIG_CONCURRENT_MODE
  3594. if(rtw_buddy_adapter_up(padapter))
  3595. rtw_scan_abort(padapter->pbuddy_adapter);
  3596. #endif /* CONFIG_CONCURRENT_MODE */
  3597. if (padapter->cfg80211_wdinfo.is_ro_ch == _TRUE) {
  3598. //DBG_8192C("%s, cancel ro ch timer\n", __func__);
  3599. //_cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
  3600. //padapter->cfg80211_wdinfo.is_ro_ch = _FALSE;
  3601. #ifdef CONFIG_CONCURRENT_MODE
  3602. DBG_8192C("%s, extend ro ch time\n", __func__);
  3603. _set_timer( &padapter->cfg80211_wdinfo.remain_on_ch_timer, pwdinfo->ext_listen_period);
  3604. #endif //CONFIG_CONCURRENT_MODE
  3605. }
  3606. #ifdef CONFIG_CONCURRENT_MODE
  3607. if (check_buddy_fwstate(padapter, _FW_LINKED )) {
  3608. u8 co_channel=0xff;
  3609. PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
  3610. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  3611. co_channel = rtw_get_oper_ch(padapter);
  3612. if (tx_ch != pbuddy_mlmeext->cur_channel) {
  3613. if (ATOMIC_READ(&pwdev_priv->switch_ch_to)==1) {
  3614. DBG_8192C("%s, issue nulldata pwrbit=1\n", __func__);
  3615. issue_nulldata(padapter->pbuddy_adapter, NULL, 1, 3, 500);
  3616. ATOMIC_SET(&pwdev_priv->switch_ch_to, 0);
  3617. //DBG_8192C("%s, set switch ch timer, period=%d\n", __func__, pwdinfo->ext_listen_period);
  3618. //_set_timer(&pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_period);
  3619. }
  3620. DBG_8192C("%s, set switch ch timer, period=%d\n", __func__, pwdinfo->ext_listen_period);
  3621. _set_timer(&pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_period);
  3622. }
  3623. if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED ))
  3624. pmlmeext->cur_channel = tx_ch;
  3625. if (tx_ch != co_channel)
  3626. set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  3627. }else
  3628. #endif //CONFIG_CONCURRENT_MODE
  3629. //if (tx_ch != pmlmeext->cur_channel) {
  3630. if(tx_ch != rtw_get_oper_ch(padapter)) {
  3631. if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED ))
  3632. pmlmeext->cur_channel = tx_ch;
  3633. set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  3634. }
  3635. //starting alloc mgmt frame to dump it
  3636. if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
  3637. {
  3638. //ret = -ENOMEM;
  3639. ret = _FAIL;
  3640. goto exit;
  3641. }
  3642. //update attribute
  3643. pattrib = &pmgntframe->attrib;
  3644. update_mgntframe_attrib(padapter, pattrib);
  3645. pattrib->retry_ctrl = _FALSE;
  3646. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  3647. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  3648. _rtw_memcpy(pframe, (void*)buf, len);
  3649. pattrib->pktlen = len;
  3650. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  3651. //update seq number
  3652. pmlmeext->mgnt_seq = GetSequence(pwlanhdr);
  3653. pattrib->seqnum = pmlmeext->mgnt_seq;
  3654. pmlmeext->mgnt_seq++;
  3655. #ifdef CONFIG_WFD
  3656. {
  3657. struct wifi_display_info *pwfd_info;
  3658. pwfd_info = padapter->wdinfo.wfd_info;
  3659. if ( _TRUE == pwfd_info->wfd_enable )
  3660. {
  3661. rtw_append_wfd_ie( padapter, pframe, &pattrib->pktlen );
  3662. }
  3663. }
  3664. #endif // CONFIG_WFD
  3665. pattrib->last_txcmdsz = pattrib->pktlen;
  3666. if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS)
  3667. {
  3668. ack = _FALSE;
  3669. ret = _FAIL;
  3670. #ifdef CONFIG_DEBUG_CFG80211
  3671. DBG_8192C("%s, ack == _FAIL\n", __func__);
  3672. #endif
  3673. }
  3674. else
  3675. {
  3676. #ifdef CONFIG_DEBUG_CFG80211
  3677. DBG_8192C("%s, ack=%d, ok!\n", __func__, ack);
  3678. #endif
  3679. ret = _SUCCESS;
  3680. }
  3681. exit:
  3682. #ifdef CONFIG_DEBUG_CFG80211
  3683. DBG_8192C("%s, ret=%d\n", __func__, ret);
  3684. #endif
  3685. return ret;
  3686. }
  3687. static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy,
  3688. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
  3689. struct wireless_dev *wdev,
  3690. #else
  3691. struct net_device *ndev,
  3692. #endif
  3693. struct ieee80211_channel *chan,
  3694. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
  3695. bool offchan,
  3696. #endif
  3697. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
  3698. enum nl80211_channel_type channel_type,
  3699. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  3700. bool channel_type_valid,
  3701. #endif
  3702. #endif
  3703. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
  3704. unsigned int wait,
  3705. #endif
  3706. const u8 *buf, size_t len,
  3707. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
  3708. bool no_cck,
  3709. #endif
  3710. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
  3711. bool dont_wait_for_ack,
  3712. #endif
  3713. u64 *cookie)
  3714. {
  3715. _adapter *padapter = (_adapter *)wiphy_to_adapter(wiphy);
  3716. struct rtw_wdev_priv *pwdev_priv = wdev_to_priv(padapter->rtw_wdev);
  3717. int ret = 0;
  3718. int tx_ret;
  3719. u32 dump_limit = RTW_MAX_MGMT_TX_CNT;
  3720. u32 dump_cnt = 0;
  3721. bool ack = _TRUE;
  3722. u8 tx_ch = (u8)ieee80211_frequency_to_channel(chan->center_freq);
  3723. u8 category, action;
  3724. int type = (-1);
  3725. u32 start = rtw_get_current_time();
  3726. /* cookie generation */
  3727. *cookie = (unsigned long) buf;
  3728. #ifdef CONFIG_DEBUG_CFG80211
  3729. DBG_871X(FUNC_ADPT_FMT" len=%zu, ch=%d"
  3730. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
  3731. ", ch_type=%d"
  3732. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  3733. ", channel_type_valid=%d"
  3734. #endif
  3735. #endif
  3736. "\n", FUNC_ADPT_ARG(padapter),
  3737. len, tx_ch
  3738. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
  3739. , channel_type
  3740. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  3741. , channel_type_valid
  3742. #endif
  3743. #endif
  3744. );
  3745. #endif /* CONFIG_DEBUG_CFG80211 */
  3746. /* indicate ack before issue frame to avoid racing with rsp frame */
  3747. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  3748. rtw_cfg80211_mgmt_tx_status(padapter, *cookie, buf, len, ack, GFP_KERNEL);
  3749. #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,34) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,35))
  3750. cfg80211_action_tx_status(ndev, *cookie, buf, len, ack, GFP_KERNEL);
  3751. #endif
  3752. if (rtw_action_frame_parse(buf, len, &category, &action) == _FALSE) {
  3753. DBG_8192C(FUNC_ADPT_FMT" frame_control:0x%x\n", FUNC_ADPT_ARG(padapter),
  3754. le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl));
  3755. goto exit;
  3756. }
  3757. DBG_8192C("RTW_Tx:tx_ch=%d, da="MAC_FMT"\n", tx_ch, MAC_ARG(GetAddr1Ptr(buf)));
  3758. #ifdef CONFIG_P2P
  3759. if((type = rtw_p2p_check_frames(padapter, buf, len, _TRUE)) >= 0)
  3760. goto dump;
  3761. #endif
  3762. if (category == RTW_WLAN_CATEGORY_PUBLIC)
  3763. DBG_871X("RTW_Tx:%s\n", action_public_str(action));
  3764. else
  3765. DBG_871X("RTW_Tx:category(%u), action(%u)\n", category, action);
  3766. dump:
  3767. do {
  3768. dump_cnt++;
  3769. tx_ret = _cfg80211_rtw_mgmt_tx(padapter, tx_ch, buf, len);
  3770. } while (dump_cnt < dump_limit && tx_ret != _SUCCESS);
  3771. if (tx_ret != _SUCCESS || dump_cnt > 1) {
  3772. DBG_871X(FUNC_ADPT_FMT" %s (%d/%d) in %d ms\n", FUNC_ADPT_ARG(padapter),
  3773. tx_ret==_SUCCESS?"OK":"FAIL", dump_cnt, dump_limit, rtw_get_passing_time_ms(start));
  3774. }
  3775. switch (type) {
  3776. case P2P_GO_NEGO_CONF:
  3777. rtw_clear_scan_deny(padapter);
  3778. break;
  3779. case P2P_INVIT_RESP:
  3780. if (pwdev_priv->invit_info.flags & BIT(0)
  3781. && pwdev_priv->invit_info.status == 0)
  3782. {
  3783. DBG_871X(FUNC_ADPT_FMT" agree with invitation of persistent group\n",
  3784. FUNC_ADPT_ARG(padapter));
  3785. rtw_set_scan_deny(padapter, 5000);
  3786. rtw_pwr_wakeup_ex(padapter, 5000);
  3787. rtw_clear_scan_deny(padapter);
  3788. }
  3789. break;
  3790. }
  3791. exit:
  3792. return ret;
  3793. }
  3794. static void cfg80211_rtw_mgmt_frame_register(struct wiphy *wiphy,
  3795. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  3796. struct wireless_dev *wdev,
  3797. #else
  3798. struct net_device *ndev,
  3799. #endif
  3800. u16 frame_type, bool reg)
  3801. {
  3802. _adapter *adapter = wiphy_to_adapter(wiphy);
  3803. #ifdef CONFIG_DEBUG_CFG80211
  3804. DBG_871X(FUNC_ADPT_FMT" frame_type:%x, reg:%d\n", FUNC_ADPT_ARG(adapter),
  3805. frame_type, reg);
  3806. #endif
  3807. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  3808. return;
  3809. return;
  3810. }
  3811. static int rtw_cfg80211_set_beacon_wpsp2pie(struct net_device *ndev, char *buf, int len)
  3812. {
  3813. int ret = 0;
  3814. uint wps_ielen = 0;
  3815. u8 *wps_ie;
  3816. u32 p2p_ielen = 0;
  3817. u8 wps_oui[8]={0x0,0x50,0xf2,0x04};
  3818. u8 *p2p_ie;
  3819. u32 wfd_ielen = 0;
  3820. u8 *wfd_ie;
  3821. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3822. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3823. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3824. DBG_871X(FUNC_NDEV_FMT" ielen=%d\n", FUNC_NDEV_ARG(ndev), len);
  3825. if(len>0)
  3826. {
  3827. if((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen)))
  3828. {
  3829. #ifdef CONFIG_DEBUG_CFG80211
  3830. DBG_8192C("bcn_wps_ielen=%d\n", wps_ielen);
  3831. #endif
  3832. if(pmlmepriv->wps_beacon_ie)
  3833. {
  3834. u32 free_len = pmlmepriv->wps_beacon_ie_len;
  3835. pmlmepriv->wps_beacon_ie_len = 0;
  3836. rtw_mfree(pmlmepriv->wps_beacon_ie, free_len);
  3837. pmlmepriv->wps_beacon_ie = NULL;
  3838. }
  3839. pmlmepriv->wps_beacon_ie = rtw_malloc(wps_ielen);
  3840. if ( pmlmepriv->wps_beacon_ie == NULL) {
  3841. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  3842. return -EINVAL;
  3843. }
  3844. _rtw_memcpy(pmlmepriv->wps_beacon_ie, wps_ie, wps_ielen);
  3845. pmlmepriv->wps_beacon_ie_len = wps_ielen;
  3846. update_beacon(padapter, _VENDOR_SPECIFIC_IE_, wps_oui, _TRUE);
  3847. }
  3848. //buf += wps_ielen;
  3849. //len -= wps_ielen;
  3850. #ifdef CONFIG_P2P
  3851. if((p2p_ie=rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen)))
  3852. {
  3853. #ifdef CONFIG_DEBUG_CFG80211
  3854. DBG_8192C("bcn_p2p_ielen=%d\n", p2p_ielen);
  3855. #endif
  3856. if(pmlmepriv->p2p_beacon_ie)
  3857. {
  3858. u32 free_len = pmlmepriv->p2p_beacon_ie_len;
  3859. pmlmepriv->p2p_beacon_ie_len = 0;
  3860. rtw_mfree(pmlmepriv->p2p_beacon_ie, free_len);
  3861. pmlmepriv->p2p_beacon_ie = NULL;
  3862. }
  3863. pmlmepriv->p2p_beacon_ie = rtw_malloc(p2p_ielen);
  3864. if ( pmlmepriv->p2p_beacon_ie == NULL) {
  3865. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  3866. return -EINVAL;
  3867. }
  3868. _rtw_memcpy(pmlmepriv->p2p_beacon_ie, p2p_ie, p2p_ielen);
  3869. pmlmepriv->p2p_beacon_ie_len = p2p_ielen;
  3870. }
  3871. #endif //CONFIG_P2P
  3872. //buf += p2p_ielen;
  3873. //len -= p2p_ielen;
  3874. #ifdef CONFIG_WFD
  3875. if(rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen))
  3876. {
  3877. #ifdef CONFIG_DEBUG_CFG80211
  3878. DBG_8192C("bcn_wfd_ielen=%d\n", wfd_ielen);
  3879. #endif
  3880. if(pmlmepriv->wfd_beacon_ie)
  3881. {
  3882. u32 free_len = pmlmepriv->wfd_beacon_ie_len;
  3883. pmlmepriv->wfd_beacon_ie_len = 0;
  3884. rtw_mfree(pmlmepriv->wfd_beacon_ie, free_len);
  3885. pmlmepriv->wfd_beacon_ie = NULL;
  3886. }
  3887. pmlmepriv->wfd_beacon_ie = rtw_malloc(wfd_ielen);
  3888. if ( pmlmepriv->wfd_beacon_ie == NULL) {
  3889. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  3890. return -EINVAL;
  3891. }
  3892. rtw_get_wfd_ie(buf, len, pmlmepriv->wfd_beacon_ie, &pmlmepriv->wfd_beacon_ie_len);
  3893. }
  3894. #endif //CONFIG_WFD
  3895. pmlmeext->bstart_bss = _TRUE;
  3896. }
  3897. return ret;
  3898. }
  3899. static int rtw_cfg80211_set_probe_resp_wpsp2pie(struct net_device *net, char *buf, int len)
  3900. {
  3901. int ret = 0;
  3902. uint wps_ielen = 0;
  3903. u8 *wps_ie;
  3904. u32 p2p_ielen = 0;
  3905. u8 *p2p_ie;
  3906. u32 wfd_ielen = 0;
  3907. u8 *wfd_ie;
  3908. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  3909. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3910. #ifdef CONFIG_DEBUG_CFG80211
  3911. DBG_8192C("%s, ielen=%d\n", __func__, len);
  3912. #endif
  3913. if(len>0)
  3914. {
  3915. if((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen)))
  3916. {
  3917. uint attr_contentlen = 0;
  3918. u16 uconfig_method, *puconfig_method = NULL;
  3919. #ifdef CONFIG_DEBUG_CFG80211
  3920. DBG_8192C("probe_resp_wps_ielen=%d\n", wps_ielen);
  3921. #endif
  3922. if(pmlmepriv->wps_probe_resp_ie)
  3923. {
  3924. u32 free_len = pmlmepriv->wps_probe_resp_ie_len;
  3925. pmlmepriv->wps_probe_resp_ie_len = 0;
  3926. rtw_mfree(pmlmepriv->wps_probe_resp_ie, free_len);
  3927. pmlmepriv->wps_probe_resp_ie = NULL;
  3928. }
  3929. pmlmepriv->wps_probe_resp_ie = rtw_malloc(wps_ielen);
  3930. if ( pmlmepriv->wps_probe_resp_ie == NULL) {
  3931. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  3932. return -EINVAL;
  3933. }
  3934. //add PUSH_BUTTON config_method by driver self in wpsie of probe_resp at GO Mode
  3935. if ( (puconfig_method = (u16*)rtw_get_wps_attr_content( wps_ie, wps_ielen, WPS_ATTR_CONF_METHOD , NULL, &attr_contentlen)) != NULL )
  3936. {
  3937. #ifdef CONFIG_DEBUG_CFG80211
  3938. //printk("config_method in wpsie of probe_resp = 0x%x\n", be16_to_cpu(*puconfig_method));
  3939. #endif
  3940. uconfig_method = WPS_CM_PUSH_BUTTON;
  3941. uconfig_method = cpu_to_be16( uconfig_method );
  3942. *puconfig_method |= uconfig_method;
  3943. }
  3944. _rtw_memcpy(pmlmepriv->wps_probe_resp_ie, wps_ie, wps_ielen);
  3945. pmlmepriv->wps_probe_resp_ie_len = wps_ielen;
  3946. }
  3947. //buf += wps_ielen;
  3948. //len -= wps_ielen;
  3949. #ifdef CONFIG_P2P
  3950. if((p2p_ie=rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen)))
  3951. {
  3952. u8 is_GO = _FALSE;
  3953. u32 attr_contentlen = 0;
  3954. u16 cap_attr=0;
  3955. #ifdef CONFIG_DEBUG_CFG80211
  3956. DBG_8192C("probe_resp_p2p_ielen=%d\n", p2p_ielen);
  3957. #endif
  3958. //Check P2P Capability ATTR
  3959. if( rtw_get_p2p_attr_content( p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8*)&cap_attr, (uint*) &attr_contentlen) )
  3960. {
  3961. u8 grp_cap=0;
  3962. //DBG_8192C( "[%s] Got P2P Capability Attr!!\n", __FUNCTION__ );
  3963. cap_attr = le16_to_cpu(cap_attr);
  3964. grp_cap = (u8)((cap_attr >> 8)&0xff);
  3965. is_GO = (grp_cap&BIT(0)) ? _TRUE:_FALSE;
  3966. if(is_GO)
  3967. DBG_8192C("Got P2P Capability Attr, grp_cap=0x%x, is_GO\n", grp_cap);
  3968. }
  3969. if(is_GO == _FALSE)
  3970. {
  3971. if(pmlmepriv->p2p_probe_resp_ie)
  3972. {
  3973. u32 free_len = pmlmepriv->p2p_probe_resp_ie_len;
  3974. pmlmepriv->p2p_probe_resp_ie_len = 0;
  3975. rtw_mfree(pmlmepriv->p2p_probe_resp_ie, free_len);
  3976. pmlmepriv->p2p_probe_resp_ie = NULL;
  3977. }
  3978. pmlmepriv->p2p_probe_resp_ie = rtw_malloc(p2p_ielen);
  3979. if ( pmlmepriv->p2p_probe_resp_ie == NULL) {
  3980. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  3981. return -EINVAL;
  3982. }
  3983. _rtw_memcpy(pmlmepriv->p2p_probe_resp_ie, p2p_ie, p2p_ielen);
  3984. pmlmepriv->p2p_probe_resp_ie_len = p2p_ielen;
  3985. }
  3986. else
  3987. {
  3988. if(pmlmepriv->p2p_go_probe_resp_ie)
  3989. {
  3990. u32 free_len = pmlmepriv->p2p_go_probe_resp_ie_len;
  3991. pmlmepriv->p2p_go_probe_resp_ie_len = 0;
  3992. rtw_mfree(pmlmepriv->p2p_go_probe_resp_ie, free_len);
  3993. pmlmepriv->p2p_go_probe_resp_ie = NULL;
  3994. }
  3995. pmlmepriv->p2p_go_probe_resp_ie = rtw_malloc(p2p_ielen);
  3996. if ( pmlmepriv->p2p_go_probe_resp_ie == NULL) {
  3997. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  3998. return -EINVAL;
  3999. }
  4000. _rtw_memcpy(pmlmepriv->p2p_go_probe_resp_ie, p2p_ie, p2p_ielen);
  4001. pmlmepriv->p2p_go_probe_resp_ie_len = p2p_ielen;
  4002. }
  4003. }
  4004. #endif //CONFIG_P2P
  4005. //buf += p2p_ielen;
  4006. //len -= p2p_ielen;
  4007. #ifdef CONFIG_WFD
  4008. if(rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen))
  4009. {
  4010. #ifdef CONFIG_DEBUG_CFG80211
  4011. DBG_8192C("probe_resp_wfd_ielen=%d\n", wfd_ielen);
  4012. #endif
  4013. if(pmlmepriv->wfd_probe_resp_ie)
  4014. {
  4015. u32 free_len = pmlmepriv->wfd_probe_resp_ie_len;
  4016. pmlmepriv->wfd_probe_resp_ie_len = 0;
  4017. rtw_mfree(pmlmepriv->wfd_probe_resp_ie, free_len);
  4018. pmlmepriv->wfd_probe_resp_ie = NULL;
  4019. }
  4020. pmlmepriv->wfd_probe_resp_ie = rtw_malloc(wfd_ielen);
  4021. if ( pmlmepriv->wfd_probe_resp_ie == NULL) {
  4022. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  4023. return -EINVAL;
  4024. }
  4025. rtw_get_wfd_ie(buf, len, pmlmepriv->wfd_probe_resp_ie, &pmlmepriv->wfd_probe_resp_ie_len);
  4026. }
  4027. #endif //CONFIG_WFD
  4028. }
  4029. return ret;
  4030. }
  4031. static int rtw_cfg80211_set_assoc_resp_wpsp2pie(struct net_device *net, char *buf, int len)
  4032. {
  4033. int ret = 0;
  4034. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  4035. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  4036. DBG_8192C("%s, ielen=%d\n", __func__, len);
  4037. if(len>0)
  4038. {
  4039. if(pmlmepriv->wps_assoc_resp_ie)
  4040. {
  4041. u32 free_len = pmlmepriv->wps_assoc_resp_ie_len;
  4042. pmlmepriv->wps_assoc_resp_ie_len = 0;
  4043. rtw_mfree(pmlmepriv->wps_assoc_resp_ie, free_len);
  4044. pmlmepriv->wps_assoc_resp_ie = NULL;
  4045. }
  4046. pmlmepriv->wps_assoc_resp_ie = rtw_malloc(len);
  4047. if ( pmlmepriv->wps_assoc_resp_ie == NULL) {
  4048. DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  4049. return -EINVAL;
  4050. }
  4051. _rtw_memcpy(pmlmepriv->wps_assoc_resp_ie, buf, len);
  4052. pmlmepriv->wps_assoc_resp_ie_len = len;
  4053. }
  4054. return ret;
  4055. }
  4056. int rtw_cfg80211_set_mgnt_wpsp2pie(struct net_device *net, char *buf, int len,
  4057. int type)
  4058. {
  4059. int ret = 0;
  4060. uint wps_ielen = 0;
  4061. u32 p2p_ielen = 0;
  4062. #ifdef CONFIG_DEBUG_CFG80211
  4063. DBG_8192C("%s, ielen=%d\n", __func__, len);
  4064. #endif
  4065. if( (rtw_get_wps_ie(buf, len, NULL, &wps_ielen) && (wps_ielen>0))
  4066. #ifdef CONFIG_P2P
  4067. || (rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen) && (p2p_ielen>0))
  4068. #endif
  4069. )
  4070. {
  4071. if (net != NULL)
  4072. {
  4073. switch (type)
  4074. {
  4075. case 0x1: //BEACON
  4076. ret = rtw_cfg80211_set_beacon_wpsp2pie(net, buf, len);
  4077. break;
  4078. case 0x2: //PROBE_RESP
  4079. ret = rtw_cfg80211_set_probe_resp_wpsp2pie(net, buf, len);
  4080. break;
  4081. case 0x4: //ASSOC_RESP
  4082. ret = rtw_cfg80211_set_assoc_resp_wpsp2pie(net, buf, len);
  4083. break;
  4084. }
  4085. }
  4086. }
  4087. return ret;
  4088. }
  4089. static struct cfg80211_ops rtw_cfg80211_ops = {
  4090. .change_virtual_intf = cfg80211_rtw_change_iface,
  4091. .add_key = cfg80211_rtw_add_key,
  4092. .get_key = cfg80211_rtw_get_key,
  4093. .del_key = cfg80211_rtw_del_key,
  4094. .set_default_key = cfg80211_rtw_set_default_key,
  4095. .get_station = cfg80211_rtw_get_station,
  4096. .scan = cfg80211_rtw_scan,
  4097. .set_wiphy_params = cfg80211_rtw_set_wiphy_params,
  4098. .connect = cfg80211_rtw_connect,
  4099. .disconnect = cfg80211_rtw_disconnect,
  4100. .join_ibss = cfg80211_rtw_join_ibss,
  4101. .leave_ibss = cfg80211_rtw_leave_ibss,
  4102. .set_tx_power = cfg80211_rtw_set_txpower,
  4103. .get_tx_power = cfg80211_rtw_get_txpower,
  4104. .set_power_mgmt = cfg80211_rtw_set_power_mgmt,
  4105. .set_pmksa = cfg80211_rtw_set_pmksa,
  4106. .del_pmksa = cfg80211_rtw_del_pmksa,
  4107. .flush_pmksa = cfg80211_rtw_flush_pmksa,
  4108. #ifdef CONFIG_AP_MODE
  4109. .add_virtual_intf = cfg80211_rtw_add_virtual_intf,
  4110. .del_virtual_intf = cfg80211_rtw_del_virtual_intf,
  4111. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)) && !defined(COMPAT_KERNEL_RELEASE)
  4112. .add_beacon = cfg80211_rtw_add_beacon,
  4113. .set_beacon = cfg80211_rtw_set_beacon,
  4114. .del_beacon = cfg80211_rtw_del_beacon,
  4115. #else
  4116. .start_ap = cfg80211_rtw_start_ap,
  4117. .change_beacon = cfg80211_rtw_change_beacon,
  4118. .stop_ap = cfg80211_rtw_stop_ap,
  4119. #endif
  4120. .add_station = cfg80211_rtw_add_station,
  4121. .del_station = cfg80211_rtw_del_station,
  4122. .change_station = cfg80211_rtw_change_station,
  4123. .dump_station = cfg80211_rtw_dump_station,
  4124. .change_bss = cfg80211_rtw_change_bss,
  4125. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
  4126. .set_channel = cfg80211_rtw_set_channel,
  4127. #endif
  4128. //.auth = cfg80211_rtw_auth,
  4129. //.assoc = cfg80211_rtw_assoc,
  4130. #endif //CONFIG_AP_MODE
  4131. #ifdef CONFIG_P2P
  4132. .remain_on_channel = cfg80211_rtw_remain_on_channel,
  4133. .cancel_remain_on_channel = cfg80211_rtw_cancel_remain_on_channel,
  4134. #endif
  4135. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  4136. .mgmt_tx = cfg80211_rtw_mgmt_tx,
  4137. .mgmt_frame_register = cfg80211_rtw_mgmt_frame_register,
  4138. #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,34) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,35))
  4139. .action = cfg80211_rtw_mgmt_tx,
  4140. #endif
  4141. };
  4142. static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum ieee80211_band band, u8 rf_type)
  4143. {
  4144. #define MAX_BIT_RATE_40MHZ_MCS15 300 /* Mbps */
  4145. #define MAX_BIT_RATE_40MHZ_MCS7 150 /* Mbps */
  4146. ht_cap->ht_supported = _TRUE;
  4147. ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  4148. IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 |
  4149. IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
  4150. /*
  4151. *Maximum length of AMPDU that the STA can receive.
  4152. *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
  4153. */
  4154. ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  4155. /*Minimum MPDU start spacing , */
  4156. ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
  4157. ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  4158. /*
  4159. *hw->wiphy->bands[IEEE80211_BAND_2GHZ]
  4160. *base on ant_num
  4161. *rx_mask: RX mask
  4162. *if rx_ant =1 rx_mask[0]=0xff;==>MCS0-MCS7
  4163. *if rx_ant =2 rx_mask[1]=0xff;==>MCS8-MCS15
  4164. *if rx_ant >=3 rx_mask[2]=0xff;
  4165. *if BW_40 rx_mask[4]=0x01;
  4166. *highest supported RX rate
  4167. */
  4168. if(rf_type == RF_1T1R)
  4169. {
  4170. ht_cap->mcs.rx_mask[0] = 0xFF;
  4171. ht_cap->mcs.rx_mask[1] = 0x00;
  4172. ht_cap->mcs.rx_mask[4] = 0x01;
  4173. ht_cap->mcs.rx_highest = MAX_BIT_RATE_40MHZ_MCS7;
  4174. }
  4175. else if((rf_type == RF_1T2R) || (rf_type==RF_2T2R))
  4176. {
  4177. ht_cap->mcs.rx_mask[0] = 0xFF;
  4178. ht_cap->mcs.rx_mask[1] = 0xFF;
  4179. ht_cap->mcs.rx_mask[4] = 0x01;
  4180. ht_cap->mcs.rx_highest = MAX_BIT_RATE_40MHZ_MCS15;
  4181. }
  4182. else
  4183. {
  4184. DBG_8192C("%s, error rf_type=%d\n", __func__, rf_type);
  4185. }
  4186. }
  4187. void rtw_cfg80211_init_wiphy(_adapter *padapter)
  4188. {
  4189. u8 rf_type;
  4190. struct ieee80211_supported_band *bands;
  4191. struct wireless_dev *pwdev = padapter->rtw_wdev;
  4192. struct wiphy *wiphy = pwdev->wiphy;
  4193. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  4194. DBG_8192C("%s:rf_type=%d\n", __func__, rf_type);
  4195. /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */
  4196. {
  4197. bands = wiphy->bands[IEEE80211_BAND_2GHZ];
  4198. if(bands)
  4199. rtw_cfg80211_init_ht_capab(&bands->ht_cap, IEEE80211_BAND_2GHZ, rf_type);
  4200. }
  4201. /* if (padapter->registrypriv.wireless_mode & WIRELESS_11A) */
  4202. {
  4203. bands = wiphy->bands[IEEE80211_BAND_5GHZ];
  4204. if(bands)
  4205. rtw_cfg80211_init_ht_capab(&bands->ht_cap, IEEE80211_BAND_5GHZ, rf_type);
  4206. }
  4207. }
  4208. /*
  4209. struct ieee80211_iface_limit rtw_limits[] = {
  4210. { .max = 1, .types = BIT(NL80211_IFTYPE_STATION)
  4211. | BIT(NL80211_IFTYPE_ADHOC)
  4212. #ifdef CONFIG_AP_MODE
  4213. | BIT(NL80211_IFTYPE_AP)
  4214. #endif
  4215. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE))
  4216. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  4217. | BIT(NL80211_IFTYPE_P2P_GO)
  4218. #endif
  4219. },
  4220. {.max = 1, .types = BIT(NL80211_IFTYPE_MONITOR)},
  4221. };
  4222. struct ieee80211_iface_combination rtw_combinations = {
  4223. .limits = rtw_limits,
  4224. .n_limits = ARRAY_SIZE(rtw_limits),
  4225. .max_interfaces = 2,
  4226. .num_different_channels = 1,
  4227. };
  4228. */
  4229. static void rtw_cfg80211_preinit_wiphy(_adapter *padapter, struct wiphy *wiphy)
  4230. {
  4231. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  4232. wiphy->max_scan_ssids = RTW_SSID_SCAN_AMOUNT;
  4233. wiphy->max_scan_ie_len = RTW_SCAN_IE_LEN_MAX;
  4234. wiphy->max_num_pmkids = RTW_MAX_NUM_PMKIDS;
  4235. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) || defined(COMPAT_KERNEL_RELEASE)
  4236. wiphy->max_remain_on_channel_duration = RTW_MAX_REMAIN_ON_CHANNEL_DURATION;
  4237. #endif
  4238. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
  4239. | BIT(NL80211_IFTYPE_ADHOC)
  4240. #ifdef CONFIG_AP_MODE
  4241. | BIT(NL80211_IFTYPE_AP)
  4242. | BIT(NL80211_IFTYPE_MONITOR)
  4243. #endif
  4244. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE))
  4245. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  4246. | BIT(NL80211_IFTYPE_P2P_GO)
  4247. #endif
  4248. ;
  4249. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  4250. #ifdef CONFIG_AP_MODE
  4251. wiphy->mgmt_stypes = rtw_cfg80211_default_mgmt_stypes;
  4252. #endif //CONFIG_AP_MODE
  4253. #endif
  4254. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0))
  4255. wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
  4256. #endif
  4257. /*
  4258. wiphy->iface_combinations = &rtw_combinations;
  4259. wiphy->n_iface_combinations = 1;
  4260. */
  4261. wiphy->cipher_suites = rtw_cipher_suites;
  4262. wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites);
  4263. /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */
  4264. wiphy->bands[IEEE80211_BAND_2GHZ] = rtw_spt_band_alloc(IEEE80211_BAND_2GHZ);
  4265. /* if (padapter->registrypriv.wireless_mode & WIRELESS_11A) */
  4266. wiphy->bands[IEEE80211_BAND_5GHZ] = rtw_spt_band_alloc(IEEE80211_BAND_5GHZ);
  4267. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38) && LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0))
  4268. wiphy->flags |= WIPHY_FLAG_SUPPORTS_SEPARATE_DEFAULT_KEYS;
  4269. #endif
  4270. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
  4271. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  4272. wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME;
  4273. #endif
  4274. if(padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
  4275. wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  4276. else
  4277. wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  4278. }
  4279. int rtw_wdev_alloc(_adapter *padapter, struct device *dev)
  4280. {
  4281. int ret = 0;
  4282. struct wiphy *wiphy;
  4283. struct wireless_dev *wdev;
  4284. struct rtw_wdev_priv *pwdev_priv;
  4285. struct net_device *pnetdev = padapter->pnetdev;
  4286. DBG_8192C("%s(padapter=%p)\n", __func__, padapter);
  4287. /* wiphy */
  4288. wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct rtw_wdev_priv));
  4289. if (!wiphy) {
  4290. DBG_8192C("Couldn't allocate wiphy device\n");
  4291. ret = -ENOMEM;
  4292. goto exit;
  4293. }
  4294. set_wiphy_dev(wiphy, dev);
  4295. rtw_cfg80211_preinit_wiphy(padapter, wiphy);
  4296. ret = wiphy_register(wiphy);
  4297. if (ret < 0) {
  4298. DBG_8192C("Couldn't register wiphy device\n");
  4299. goto free_wiphy;
  4300. }
  4301. /* wdev */
  4302. wdev = (struct wireless_dev *)rtw_zmalloc(sizeof(struct wireless_dev));
  4303. if (!wdev) {
  4304. DBG_8192C("Couldn't allocate wireless device\n");
  4305. ret = -ENOMEM;
  4306. goto unregister_wiphy;
  4307. }
  4308. wdev->wiphy = wiphy;
  4309. wdev->netdev = pnetdev;
  4310. //wdev->iftype = NL80211_IFTYPE_STATION;
  4311. wdev->iftype = NL80211_IFTYPE_MONITOR; // for rtw_setopmode_cmd() in cfg80211_rtw_change_iface()
  4312. padapter->rtw_wdev = wdev;
  4313. pnetdev->ieee80211_ptr = wdev;
  4314. //init pwdev_priv
  4315. pwdev_priv = wdev_to_priv(wdev);
  4316. pwdev_priv->rtw_wdev = wdev;
  4317. pwdev_priv->pmon_ndev = NULL;
  4318. pwdev_priv->ifname_mon[0] = '\0';
  4319. pwdev_priv->padapter = padapter;
  4320. pwdev_priv->scan_request = NULL;
  4321. _rtw_spinlock_init(&pwdev_priv->scan_req_lock);
  4322. pwdev_priv->p2p_enabled = _FALSE;
  4323. pwdev_priv->provdisc_req_issued = _FALSE;
  4324. rtw_wdev_invit_info_init(&pwdev_priv->invit_info);
  4325. pwdev_priv->bandroid_scan = _FALSE;
  4326. if(padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
  4327. pwdev_priv->power_mgmt = _TRUE;
  4328. else
  4329. pwdev_priv->power_mgmt = _FALSE;
  4330. #ifdef CONFIG_CONCURRENT_MODE
  4331. ATOMIC_SET(&pwdev_priv->switch_ch_to, 1);
  4332. ATOMIC_SET(&pwdev_priv->ro_ch_to, 1);
  4333. #endif
  4334. return ret;
  4335. rtw_mfree((u8*)wdev, sizeof(struct wireless_dev));
  4336. unregister_wiphy:
  4337. wiphy_unregister(wiphy);
  4338. free_wiphy:
  4339. wiphy_free(wiphy);
  4340. exit:
  4341. return ret;
  4342. }
  4343. void rtw_wdev_free(struct wireless_dev *wdev)
  4344. {
  4345. struct rtw_wdev_priv *pwdev_priv;
  4346. DBG_8192C("%s(wdev=%p)\n", __func__, wdev);
  4347. if (!wdev)
  4348. return;
  4349. pwdev_priv = wdev_to_priv(wdev);
  4350. rtw_spt_band_free(wdev->wiphy->bands[IEEE80211_BAND_2GHZ]);
  4351. rtw_spt_band_free(wdev->wiphy->bands[IEEE80211_BAND_5GHZ]);
  4352. wiphy_free(wdev->wiphy);
  4353. rtw_mfree((u8*)wdev, sizeof(struct wireless_dev));
  4354. }
  4355. void rtw_wdev_unregister(struct wireless_dev *wdev)
  4356. {
  4357. struct rtw_wdev_priv *pwdev_priv;
  4358. DBG_8192C("%s(wdev=%p)\n", __func__, wdev);
  4359. if (!wdev)
  4360. return;
  4361. pwdev_priv = wdev_to_priv(wdev);
  4362. rtw_cfg80211_indicate_scan_done(pwdev_priv, _TRUE);
  4363. if (pwdev_priv->pmon_ndev) {
  4364. DBG_8192C("%s, unregister monitor interface\n", __func__);
  4365. unregister_netdev(pwdev_priv->pmon_ndev);
  4366. }
  4367. wiphy_unregister(wdev->wiphy);
  4368. }
  4369. #endif //CONFIG_IOCTL_CFG80211