cfg80211.c 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/moduleparam.h>
  19. #include <linux/inetdevice.h>
  20. #include <linux/export.h>
  21. #include "core.h"
  22. #include "cfg80211.h"
  23. #include "debug.h"
  24. #include "hif-ops.h"
  25. #include "testmode.h"
  26. #define RATETAB_ENT(_rate, _rateid, _flags) { \
  27. .bitrate = (_rate), \
  28. .flags = (_flags), \
  29. .hw_value = (_rateid), \
  30. }
  31. #define CHAN2G(_channel, _freq, _flags) { \
  32. .band = IEEE80211_BAND_2GHZ, \
  33. .hw_value = (_channel), \
  34. .center_freq = (_freq), \
  35. .flags = (_flags), \
  36. .max_antenna_gain = 0, \
  37. .max_power = 30, \
  38. }
  39. #define CHAN5G(_channel, _flags) { \
  40. .band = IEEE80211_BAND_5GHZ, \
  41. .hw_value = (_channel), \
  42. .center_freq = 5000 + (5 * (_channel)), \
  43. .flags = (_flags), \
  44. .max_antenna_gain = 0, \
  45. .max_power = 30, \
  46. }
  47. #define DEFAULT_BG_SCAN_PERIOD 60
  48. struct ath6kl_cfg80211_match_probe_ssid {
  49. struct cfg80211_ssid ssid;
  50. u8 flag;
  51. };
  52. static struct ieee80211_rate ath6kl_rates[] = {
  53. RATETAB_ENT(10, 0x1, 0),
  54. RATETAB_ENT(20, 0x2, 0),
  55. RATETAB_ENT(55, 0x4, 0),
  56. RATETAB_ENT(110, 0x8, 0),
  57. RATETAB_ENT(60, 0x10, 0),
  58. RATETAB_ENT(90, 0x20, 0),
  59. RATETAB_ENT(120, 0x40, 0),
  60. RATETAB_ENT(180, 0x80, 0),
  61. RATETAB_ENT(240, 0x100, 0),
  62. RATETAB_ENT(360, 0x200, 0),
  63. RATETAB_ENT(480, 0x400, 0),
  64. RATETAB_ENT(540, 0x800, 0),
  65. };
  66. #define ath6kl_a_rates (ath6kl_rates + 4)
  67. #define ath6kl_a_rates_size 8
  68. #define ath6kl_g_rates (ath6kl_rates + 0)
  69. #define ath6kl_g_rates_size 12
  70. #define ath6kl_g_htcap IEEE80211_HT_CAP_SGI_20
  71. #define ath6kl_a_htcap (IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
  72. IEEE80211_HT_CAP_SGI_20 | \
  73. IEEE80211_HT_CAP_SGI_40)
  74. static struct ieee80211_channel ath6kl_2ghz_channels[] = {
  75. CHAN2G(1, 2412, 0),
  76. CHAN2G(2, 2417, 0),
  77. CHAN2G(3, 2422, 0),
  78. CHAN2G(4, 2427, 0),
  79. CHAN2G(5, 2432, 0),
  80. CHAN2G(6, 2437, 0),
  81. CHAN2G(7, 2442, 0),
  82. CHAN2G(8, 2447, 0),
  83. CHAN2G(9, 2452, 0),
  84. CHAN2G(10, 2457, 0),
  85. CHAN2G(11, 2462, 0),
  86. CHAN2G(12, 2467, 0),
  87. CHAN2G(13, 2472, 0),
  88. CHAN2G(14, 2484, 0),
  89. };
  90. static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
  91. CHAN5G(34, 0), CHAN5G(36, 0),
  92. CHAN5G(38, 0), CHAN5G(40, 0),
  93. CHAN5G(42, 0), CHAN5G(44, 0),
  94. CHAN5G(46, 0), CHAN5G(48, 0),
  95. CHAN5G(52, 0), CHAN5G(56, 0),
  96. CHAN5G(60, 0), CHAN5G(64, 0),
  97. CHAN5G(100, 0), CHAN5G(104, 0),
  98. CHAN5G(108, 0), CHAN5G(112, 0),
  99. CHAN5G(116, 0), CHAN5G(120, 0),
  100. CHAN5G(124, 0), CHAN5G(128, 0),
  101. CHAN5G(132, 0), CHAN5G(136, 0),
  102. CHAN5G(140, 0), CHAN5G(149, 0),
  103. CHAN5G(153, 0), CHAN5G(157, 0),
  104. CHAN5G(161, 0), CHAN5G(165, 0),
  105. CHAN5G(184, 0), CHAN5G(188, 0),
  106. CHAN5G(192, 0), CHAN5G(196, 0),
  107. CHAN5G(200, 0), CHAN5G(204, 0),
  108. CHAN5G(208, 0), CHAN5G(212, 0),
  109. CHAN5G(216, 0),
  110. };
  111. static struct ieee80211_supported_band ath6kl_band_2ghz = {
  112. .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
  113. .channels = ath6kl_2ghz_channels,
  114. .n_bitrates = ath6kl_g_rates_size,
  115. .bitrates = ath6kl_g_rates,
  116. .ht_cap.cap = ath6kl_g_htcap,
  117. .ht_cap.ht_supported = true,
  118. };
  119. static struct ieee80211_supported_band ath6kl_band_5ghz = {
  120. .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
  121. .channels = ath6kl_5ghz_a_channels,
  122. .n_bitrates = ath6kl_a_rates_size,
  123. .bitrates = ath6kl_a_rates,
  124. .ht_cap.cap = ath6kl_a_htcap,
  125. .ht_cap.ht_supported = true,
  126. };
  127. #define CCKM_KRK_CIPHER_SUITE 0x004096ff /* use for KRK */
  128. /* returns true if scheduled scan was stopped */
  129. static bool __ath6kl_cfg80211_sscan_stop(struct ath6kl_vif *vif)
  130. {
  131. struct ath6kl *ar = vif->ar;
  132. if (!test_and_clear_bit(SCHED_SCANNING, &vif->flags))
  133. return false;
  134. del_timer_sync(&vif->sched_scan_timer);
  135. if (ar->state == ATH6KL_STATE_RECOVERY)
  136. return true;
  137. ath6kl_wmi_enable_sched_scan_cmd(ar->wmi, vif->fw_vif_idx, false);
  138. return true;
  139. }
  140. static void ath6kl_cfg80211_sscan_disable(struct ath6kl_vif *vif)
  141. {
  142. struct ath6kl *ar = vif->ar;
  143. bool stopped;
  144. stopped = __ath6kl_cfg80211_sscan_stop(vif);
  145. if (!stopped)
  146. return;
  147. cfg80211_sched_scan_stopped(ar->wiphy);
  148. }
  149. static int ath6kl_set_wpa_version(struct ath6kl_vif *vif,
  150. enum nl80211_wpa_versions wpa_version)
  151. {
  152. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);
  153. if (!wpa_version) {
  154. vif->auth_mode = NONE_AUTH;
  155. } else if (wpa_version & NL80211_WPA_VERSION_2) {
  156. vif->auth_mode = WPA2_AUTH;
  157. } else if (wpa_version & NL80211_WPA_VERSION_1) {
  158. vif->auth_mode = WPA_AUTH;
  159. } else {
  160. ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
  161. return -ENOTSUPP;
  162. }
  163. return 0;
  164. }
  165. static int ath6kl_set_auth_type(struct ath6kl_vif *vif,
  166. enum nl80211_auth_type auth_type)
  167. {
  168. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
  169. switch (auth_type) {
  170. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  171. vif->dot11_auth_mode = OPEN_AUTH;
  172. break;
  173. case NL80211_AUTHTYPE_SHARED_KEY:
  174. vif->dot11_auth_mode = SHARED_AUTH;
  175. break;
  176. case NL80211_AUTHTYPE_NETWORK_EAP:
  177. vif->dot11_auth_mode = LEAP_AUTH;
  178. break;
  179. case NL80211_AUTHTYPE_AUTOMATIC:
  180. vif->dot11_auth_mode = OPEN_AUTH | SHARED_AUTH;
  181. break;
  182. default:
  183. ath6kl_err("%s: 0x%x not supported\n", __func__, auth_type);
  184. return -ENOTSUPP;
  185. }
  186. return 0;
  187. }
  188. static int ath6kl_set_cipher(struct ath6kl_vif *vif, u32 cipher, bool ucast)
  189. {
  190. u8 *ar_cipher = ucast ? &vif->prwise_crypto : &vif->grp_crypto;
  191. u8 *ar_cipher_len = ucast ? &vif->prwise_crypto_len :
  192. &vif->grp_crypto_len;
  193. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
  194. __func__, cipher, ucast);
  195. switch (cipher) {
  196. case 0:
  197. /* our own hack to use value 0 as no crypto used */
  198. *ar_cipher = NONE_CRYPT;
  199. *ar_cipher_len = 0;
  200. break;
  201. case WLAN_CIPHER_SUITE_WEP40:
  202. *ar_cipher = WEP_CRYPT;
  203. *ar_cipher_len = 5;
  204. break;
  205. case WLAN_CIPHER_SUITE_WEP104:
  206. *ar_cipher = WEP_CRYPT;
  207. *ar_cipher_len = 13;
  208. break;
  209. case WLAN_CIPHER_SUITE_TKIP:
  210. *ar_cipher = TKIP_CRYPT;
  211. *ar_cipher_len = 0;
  212. break;
  213. case WLAN_CIPHER_SUITE_CCMP:
  214. *ar_cipher = AES_CRYPT;
  215. *ar_cipher_len = 0;
  216. break;
  217. case WLAN_CIPHER_SUITE_SMS4:
  218. *ar_cipher = WAPI_CRYPT;
  219. *ar_cipher_len = 0;
  220. break;
  221. default:
  222. ath6kl_err("cipher 0x%x not supported\n", cipher);
  223. return -ENOTSUPP;
  224. }
  225. return 0;
  226. }
  227. static void ath6kl_set_key_mgmt(struct ath6kl_vif *vif, u32 key_mgmt)
  228. {
  229. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
  230. if (key_mgmt == WLAN_AKM_SUITE_PSK) {
  231. if (vif->auth_mode == WPA_AUTH)
  232. vif->auth_mode = WPA_PSK_AUTH;
  233. else if (vif->auth_mode == WPA2_AUTH)
  234. vif->auth_mode = WPA2_PSK_AUTH;
  235. } else if (key_mgmt == 0x00409600) {
  236. if (vif->auth_mode == WPA_AUTH)
  237. vif->auth_mode = WPA_AUTH_CCKM;
  238. else if (vif->auth_mode == WPA2_AUTH)
  239. vif->auth_mode = WPA2_AUTH_CCKM;
  240. } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
  241. vif->auth_mode = NONE_AUTH;
  242. }
  243. }
  244. static bool ath6kl_cfg80211_ready(struct ath6kl_vif *vif)
  245. {
  246. struct ath6kl *ar = vif->ar;
  247. if (!test_bit(WMI_READY, &ar->flag)) {
  248. ath6kl_err("wmi is not ready\n");
  249. return false;
  250. }
  251. if (!test_bit(WLAN_ENABLED, &vif->flags)) {
  252. ath6kl_err("wlan disabled\n");
  253. return false;
  254. }
  255. return true;
  256. }
  257. static bool ath6kl_is_wpa_ie(const u8 *pos)
  258. {
  259. return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  260. pos[2] == 0x00 && pos[3] == 0x50 &&
  261. pos[4] == 0xf2 && pos[5] == 0x01;
  262. }
  263. static bool ath6kl_is_rsn_ie(const u8 *pos)
  264. {
  265. return pos[0] == WLAN_EID_RSN;
  266. }
  267. static bool ath6kl_is_wps_ie(const u8 *pos)
  268. {
  269. return (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  270. pos[1] >= 4 &&
  271. pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2 &&
  272. pos[5] == 0x04);
  273. }
  274. static int ath6kl_set_assoc_req_ies(struct ath6kl_vif *vif, const u8 *ies,
  275. size_t ies_len)
  276. {
  277. struct ath6kl *ar = vif->ar;
  278. const u8 *pos;
  279. u8 *buf = NULL;
  280. size_t len = 0;
  281. int ret;
  282. /*
  283. * Clear previously set flag
  284. */
  285. ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG;
  286. /*
  287. * Filter out RSN/WPA IE(s)
  288. */
  289. if (ies && ies_len) {
  290. buf = kmalloc(ies_len, GFP_KERNEL);
  291. if (buf == NULL)
  292. return -ENOMEM;
  293. pos = ies;
  294. while (pos + 1 < ies + ies_len) {
  295. if (pos + 2 + pos[1] > ies + ies_len)
  296. break;
  297. if (!(ath6kl_is_wpa_ie(pos) || ath6kl_is_rsn_ie(pos))) {
  298. memcpy(buf + len, pos, 2 + pos[1]);
  299. len += 2 + pos[1];
  300. }
  301. if (ath6kl_is_wps_ie(pos))
  302. ar->connect_ctrl_flags |= CONNECT_WPS_FLAG;
  303. pos += 2 + pos[1];
  304. }
  305. }
  306. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  307. WMI_FRAME_ASSOC_REQ, buf, len);
  308. kfree(buf);
  309. return ret;
  310. }
  311. static int ath6kl_nliftype_to_drv_iftype(enum nl80211_iftype type, u8 *nw_type)
  312. {
  313. switch (type) {
  314. case NL80211_IFTYPE_STATION:
  315. case NL80211_IFTYPE_P2P_CLIENT:
  316. *nw_type = INFRA_NETWORK;
  317. break;
  318. case NL80211_IFTYPE_ADHOC:
  319. *nw_type = ADHOC_NETWORK;
  320. break;
  321. case NL80211_IFTYPE_AP:
  322. case NL80211_IFTYPE_P2P_GO:
  323. *nw_type = AP_NETWORK;
  324. break;
  325. default:
  326. ath6kl_err("invalid interface type %u\n", type);
  327. return -ENOTSUPP;
  328. }
  329. return 0;
  330. }
  331. static bool ath6kl_is_valid_iftype(struct ath6kl *ar, enum nl80211_iftype type,
  332. u8 *if_idx, u8 *nw_type)
  333. {
  334. int i;
  335. if (ath6kl_nliftype_to_drv_iftype(type, nw_type))
  336. return false;
  337. if (ar->ibss_if_active || ((type == NL80211_IFTYPE_ADHOC) &&
  338. ar->num_vif))
  339. return false;
  340. if (type == NL80211_IFTYPE_STATION ||
  341. type == NL80211_IFTYPE_AP || type == NL80211_IFTYPE_ADHOC) {
  342. for (i = 0; i < ar->vif_max; i++) {
  343. if ((ar->avail_idx_map) & BIT(i)) {
  344. *if_idx = i;
  345. return true;
  346. }
  347. }
  348. }
  349. if (type == NL80211_IFTYPE_P2P_CLIENT ||
  350. type == NL80211_IFTYPE_P2P_GO) {
  351. for (i = ar->max_norm_iface; i < ar->vif_max; i++) {
  352. if ((ar->avail_idx_map) & BIT(i)) {
  353. *if_idx = i;
  354. return true;
  355. }
  356. }
  357. }
  358. return false;
  359. }
  360. static bool ath6kl_is_tx_pending(struct ath6kl *ar)
  361. {
  362. return ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0;
  363. }
  364. static void ath6kl_cfg80211_sta_bmiss_enhance(struct ath6kl_vif *vif,
  365. bool enable)
  366. {
  367. int err;
  368. if (WARN_ON(!test_bit(WMI_READY, &vif->ar->flag)))
  369. return;
  370. if (vif->nw_type != INFRA_NETWORK)
  371. return;
  372. if (!test_bit(ATH6KL_FW_CAPABILITY_BMISS_ENHANCE,
  373. vif->ar->fw_capabilities))
  374. return;
  375. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s fw bmiss enhance\n",
  376. enable ? "enable" : "disable");
  377. err = ath6kl_wmi_sta_bmiss_enhance_cmd(vif->ar->wmi,
  378. vif->fw_vif_idx, enable);
  379. if (err)
  380. ath6kl_err("failed to %s enhanced bmiss detection: %d\n",
  381. enable ? "enable" : "disable", err);
  382. }
  383. static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  384. struct cfg80211_connect_params *sme)
  385. {
  386. struct ath6kl *ar = ath6kl_priv(dev);
  387. struct ath6kl_vif *vif = netdev_priv(dev);
  388. int status;
  389. u8 nw_subtype = (ar->p2p) ? SUBTYPE_P2PDEV : SUBTYPE_NONE;
  390. u16 interval;
  391. ath6kl_cfg80211_sscan_disable(vif);
  392. vif->sme_state = SME_CONNECTING;
  393. if (!ath6kl_cfg80211_ready(vif))
  394. return -EIO;
  395. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  396. ath6kl_err("destroy in progress\n");
  397. return -EBUSY;
  398. }
  399. if (test_bit(SKIP_SCAN, &ar->flag) &&
  400. ((sme->channel && sme->channel->center_freq == 0) ||
  401. (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
  402. ath6kl_err("SkipScan: channel or bssid invalid\n");
  403. return -EINVAL;
  404. }
  405. if (down_interruptible(&ar->sem)) {
  406. ath6kl_err("busy, couldn't get access\n");
  407. return -ERESTARTSYS;
  408. }
  409. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  410. ath6kl_err("busy, destroy in progress\n");
  411. up(&ar->sem);
  412. return -EBUSY;
  413. }
  414. if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
  415. /*
  416. * sleep until the command queue drains
  417. */
  418. wait_event_interruptible_timeout(ar->event_wq,
  419. ath6kl_is_tx_pending(ar),
  420. WMI_TIMEOUT);
  421. if (signal_pending(current)) {
  422. ath6kl_err("cmd queue drain timeout\n");
  423. up(&ar->sem);
  424. return -EINTR;
  425. }
  426. }
  427. status = ath6kl_set_assoc_req_ies(vif, sme->ie, sme->ie_len);
  428. if (status) {
  429. up(&ar->sem);
  430. return status;
  431. }
  432. if (sme->ie == NULL || sme->ie_len == 0)
  433. ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG;
  434. if (test_bit(CONNECTED, &vif->flags) &&
  435. vif->ssid_len == sme->ssid_len &&
  436. !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
  437. vif->reconnect_flag = true;
  438. status = ath6kl_wmi_reconnect_cmd(ar->wmi, vif->fw_vif_idx,
  439. vif->req_bssid,
  440. vif->ch_hint);
  441. up(&ar->sem);
  442. if (status) {
  443. ath6kl_err("wmi_reconnect_cmd failed\n");
  444. return -EIO;
  445. }
  446. return 0;
  447. } else if (vif->ssid_len == sme->ssid_len &&
  448. !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
  449. ath6kl_disconnect(vif);
  450. }
  451. memset(vif->ssid, 0, sizeof(vif->ssid));
  452. vif->ssid_len = sme->ssid_len;
  453. memcpy(vif->ssid, sme->ssid, sme->ssid_len);
  454. if (sme->channel)
  455. vif->ch_hint = sme->channel->center_freq;
  456. memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
  457. if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
  458. memcpy(vif->req_bssid, sme->bssid, sizeof(vif->req_bssid));
  459. ath6kl_set_wpa_version(vif, sme->crypto.wpa_versions);
  460. status = ath6kl_set_auth_type(vif, sme->auth_type);
  461. if (status) {
  462. up(&ar->sem);
  463. return status;
  464. }
  465. if (sme->crypto.n_ciphers_pairwise)
  466. ath6kl_set_cipher(vif, sme->crypto.ciphers_pairwise[0], true);
  467. else
  468. ath6kl_set_cipher(vif, 0, true);
  469. ath6kl_set_cipher(vif, sme->crypto.cipher_group, false);
  470. if (sme->crypto.n_akm_suites)
  471. ath6kl_set_key_mgmt(vif, sme->crypto.akm_suites[0]);
  472. if ((sme->key_len) &&
  473. (vif->auth_mode == NONE_AUTH) &&
  474. (vif->prwise_crypto == WEP_CRYPT)) {
  475. struct ath6kl_key *key = NULL;
  476. if (sme->key_idx > WMI_MAX_KEY_INDEX) {
  477. ath6kl_err("key index %d out of bounds\n",
  478. sme->key_idx);
  479. up(&ar->sem);
  480. return -ENOENT;
  481. }
  482. key = &vif->keys[sme->key_idx];
  483. key->key_len = sme->key_len;
  484. memcpy(key->key, sme->key, key->key_len);
  485. key->cipher = vif->prwise_crypto;
  486. vif->def_txkey_index = sme->key_idx;
  487. ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, sme->key_idx,
  488. vif->prwise_crypto,
  489. GROUP_USAGE | TX_USAGE,
  490. key->key_len,
  491. NULL, 0,
  492. key->key, KEY_OP_INIT_VAL, NULL,
  493. NO_SYNC_WMIFLAG);
  494. }
  495. if (!ar->usr_bss_filter) {
  496. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  497. if (ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  498. ALL_BSS_FILTER, 0) != 0) {
  499. ath6kl_err("couldn't set bss filtering\n");
  500. up(&ar->sem);
  501. return -EIO;
  502. }
  503. }
  504. vif->nw_type = vif->next_mode;
  505. /* enable enhanced bmiss detection if applicable */
  506. ath6kl_cfg80211_sta_bmiss_enhance(vif, true);
  507. if (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
  508. nw_subtype = SUBTYPE_P2PCLIENT;
  509. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  510. "%s: connect called with authmode %d dot11 auth %d"
  511. " PW crypto %d PW crypto len %d GRP crypto %d"
  512. " GRP crypto len %d channel hint %u\n",
  513. __func__,
  514. vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
  515. vif->prwise_crypto_len, vif->grp_crypto,
  516. vif->grp_crypto_len, vif->ch_hint);
  517. vif->reconnect_flag = 0;
  518. if (vif->nw_type == INFRA_NETWORK) {
  519. interval = max_t(u16, vif->listen_intvl_t,
  520. ATH6KL_MAX_WOW_LISTEN_INTL);
  521. status = ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  522. interval,
  523. 0);
  524. if (status) {
  525. ath6kl_err("couldn't set listen intervel\n");
  526. up(&ar->sem);
  527. return status;
  528. }
  529. }
  530. status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
  531. vif->dot11_auth_mode, vif->auth_mode,
  532. vif->prwise_crypto,
  533. vif->prwise_crypto_len,
  534. vif->grp_crypto, vif->grp_crypto_len,
  535. vif->ssid_len, vif->ssid,
  536. vif->req_bssid, vif->ch_hint,
  537. ar->connect_ctrl_flags, nw_subtype);
  538. if (sme->bg_scan_period == 0) {
  539. /* disable background scan if period is 0 */
  540. sme->bg_scan_period = 0xffff;
  541. } else if (sme->bg_scan_period == -1) {
  542. /* configure default value if not specified */
  543. sme->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
  544. }
  545. ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0, 0,
  546. sme->bg_scan_period, 0, 0, 0, 3, 0, 0, 0);
  547. up(&ar->sem);
  548. if (status == -EINVAL) {
  549. memset(vif->ssid, 0, sizeof(vif->ssid));
  550. vif->ssid_len = 0;
  551. ath6kl_err("invalid request\n");
  552. return -ENOENT;
  553. } else if (status) {
  554. ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
  555. return -EIO;
  556. }
  557. if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
  558. ((vif->auth_mode == WPA_PSK_AUTH) ||
  559. (vif->auth_mode == WPA2_PSK_AUTH))) {
  560. mod_timer(&vif->disconnect_timer,
  561. jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
  562. }
  563. ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
  564. set_bit(CONNECT_PEND, &vif->flags);
  565. return 0;
  566. }
  567. static struct cfg80211_bss *
  568. ath6kl_add_bss_if_needed(struct ath6kl_vif *vif,
  569. enum network_type nw_type,
  570. const u8 *bssid,
  571. struct ieee80211_channel *chan,
  572. const u8 *beacon_ie,
  573. size_t beacon_ie_len)
  574. {
  575. struct ath6kl *ar = vif->ar;
  576. struct cfg80211_bss *bss;
  577. u16 cap_mask, cap_val;
  578. u8 *ie;
  579. if (nw_type & ADHOC_NETWORK) {
  580. cap_mask = WLAN_CAPABILITY_IBSS;
  581. cap_val = WLAN_CAPABILITY_IBSS;
  582. } else {
  583. cap_mask = WLAN_CAPABILITY_ESS;
  584. cap_val = WLAN_CAPABILITY_ESS;
  585. }
  586. bss = cfg80211_get_bss(ar->wiphy, chan, bssid,
  587. vif->ssid, vif->ssid_len,
  588. cap_mask, cap_val);
  589. if (bss == NULL) {
  590. /*
  591. * Since cfg80211 may not yet know about the BSS,
  592. * generate a partial entry until the first BSS info
  593. * event becomes available.
  594. *
  595. * Prepend SSID element since it is not included in the Beacon
  596. * IEs from the target.
  597. */
  598. ie = kmalloc(2 + vif->ssid_len + beacon_ie_len, GFP_KERNEL);
  599. if (ie == NULL)
  600. return NULL;
  601. ie[0] = WLAN_EID_SSID;
  602. ie[1] = vif->ssid_len;
  603. memcpy(ie + 2, vif->ssid, vif->ssid_len);
  604. memcpy(ie + 2 + vif->ssid_len, beacon_ie, beacon_ie_len);
  605. bss = cfg80211_inform_bss(ar->wiphy, chan,
  606. bssid, 0, cap_val, 100,
  607. ie, 2 + vif->ssid_len + beacon_ie_len,
  608. 0, GFP_KERNEL);
  609. if (bss)
  610. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  611. "added bss %pM to cfg80211\n", bssid);
  612. kfree(ie);
  613. } else
  614. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "cfg80211 already has a bss\n");
  615. return bss;
  616. }
  617. void ath6kl_cfg80211_connect_event(struct ath6kl_vif *vif, u16 channel,
  618. u8 *bssid, u16 listen_intvl,
  619. u16 beacon_intvl,
  620. enum network_type nw_type,
  621. u8 beacon_ie_len, u8 assoc_req_len,
  622. u8 assoc_resp_len, u8 *assoc_info)
  623. {
  624. struct ieee80211_channel *chan;
  625. struct ath6kl *ar = vif->ar;
  626. struct cfg80211_bss *bss;
  627. /* capinfo + listen interval */
  628. u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
  629. /* capinfo + status code + associd */
  630. u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
  631. u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
  632. u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
  633. assoc_resp_ie_offset;
  634. assoc_req_len -= assoc_req_ie_offset;
  635. assoc_resp_len -= assoc_resp_ie_offset;
  636. /*
  637. * Store Beacon interval here; DTIM period will be available only once
  638. * a Beacon frame from the AP is seen.
  639. */
  640. vif->assoc_bss_beacon_int = beacon_intvl;
  641. clear_bit(DTIM_PERIOD_AVAIL, &vif->flags);
  642. if (nw_type & ADHOC_NETWORK) {
  643. if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
  644. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  645. "%s: ath6k not in ibss mode\n", __func__);
  646. return;
  647. }
  648. }
  649. if (nw_type & INFRA_NETWORK) {
  650. if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
  651. vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
  652. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  653. "%s: ath6k not in station mode\n", __func__);
  654. return;
  655. }
  656. }
  657. chan = ieee80211_get_channel(ar->wiphy, (int) channel);
  658. bss = ath6kl_add_bss_if_needed(vif, nw_type, bssid, chan,
  659. assoc_info, beacon_ie_len);
  660. if (!bss) {
  661. ath6kl_err("could not add cfg80211 bss entry\n");
  662. return;
  663. }
  664. if (nw_type & ADHOC_NETWORK) {
  665. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "ad-hoc %s selected\n",
  666. nw_type & ADHOC_CREATOR ? "creator" : "joiner");
  667. cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
  668. cfg80211_put_bss(ar->wiphy, bss);
  669. return;
  670. }
  671. if (vif->sme_state == SME_CONNECTING) {
  672. /* inform connect result to cfg80211 */
  673. vif->sme_state = SME_CONNECTED;
  674. cfg80211_connect_result(vif->ndev, bssid,
  675. assoc_req_ie, assoc_req_len,
  676. assoc_resp_ie, assoc_resp_len,
  677. WLAN_STATUS_SUCCESS, GFP_KERNEL);
  678. cfg80211_put_bss(ar->wiphy, bss);
  679. } else if (vif->sme_state == SME_CONNECTED) {
  680. /* inform roam event to cfg80211 */
  681. cfg80211_roamed_bss(vif->ndev, bss, assoc_req_ie, assoc_req_len,
  682. assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
  683. }
  684. }
  685. static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
  686. struct net_device *dev, u16 reason_code)
  687. {
  688. struct ath6kl *ar = ath6kl_priv(dev);
  689. struct ath6kl_vif *vif = netdev_priv(dev);
  690. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
  691. reason_code);
  692. ath6kl_cfg80211_sscan_disable(vif);
  693. if (!ath6kl_cfg80211_ready(vif))
  694. return -EIO;
  695. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  696. ath6kl_err("busy, destroy in progress\n");
  697. return -EBUSY;
  698. }
  699. if (down_interruptible(&ar->sem)) {
  700. ath6kl_err("busy, couldn't get access\n");
  701. return -ERESTARTSYS;
  702. }
  703. vif->reconnect_flag = 0;
  704. ath6kl_disconnect(vif);
  705. memset(vif->ssid, 0, sizeof(vif->ssid));
  706. vif->ssid_len = 0;
  707. if (!test_bit(SKIP_SCAN, &ar->flag))
  708. memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
  709. up(&ar->sem);
  710. vif->sme_state = SME_DISCONNECTED;
  711. return 0;
  712. }
  713. void ath6kl_cfg80211_disconnect_event(struct ath6kl_vif *vif, u8 reason,
  714. u8 *bssid, u8 assoc_resp_len,
  715. u8 *assoc_info, u16 proto_reason)
  716. {
  717. struct ath6kl *ar = vif->ar;
  718. if (vif->scan_req) {
  719. cfg80211_scan_done(vif->scan_req, true);
  720. vif->scan_req = NULL;
  721. }
  722. if (vif->nw_type & ADHOC_NETWORK) {
  723. if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
  724. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  725. "%s: ath6k not in ibss mode\n", __func__);
  726. return;
  727. }
  728. memset(bssid, 0, ETH_ALEN);
  729. cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
  730. return;
  731. }
  732. if (vif->nw_type & INFRA_NETWORK) {
  733. if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
  734. vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
  735. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  736. "%s: ath6k not in station mode\n", __func__);
  737. return;
  738. }
  739. }
  740. clear_bit(CONNECT_PEND, &vif->flags);
  741. if (vif->sme_state == SME_CONNECTING) {
  742. cfg80211_connect_result(vif->ndev,
  743. bssid, NULL, 0,
  744. NULL, 0,
  745. WLAN_STATUS_UNSPECIFIED_FAILURE,
  746. GFP_KERNEL);
  747. } else if (vif->sme_state == SME_CONNECTED) {
  748. cfg80211_disconnected(vif->ndev, proto_reason,
  749. NULL, 0, GFP_KERNEL);
  750. }
  751. vif->sme_state = SME_DISCONNECTED;
  752. /*
  753. * Send a disconnect command to target when a disconnect event is
  754. * received with reason code other than 3 (DISCONNECT_CMD - disconnect
  755. * request from host) to make the firmware stop trying to connect even
  756. * after giving disconnect event. There will be one more disconnect
  757. * event for this disconnect command with reason code DISCONNECT_CMD
  758. * which won't be notified to cfg80211.
  759. */
  760. if (reason != DISCONNECT_CMD)
  761. ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
  762. }
  763. static int ath6kl_set_probed_ssids(struct ath6kl *ar,
  764. struct ath6kl_vif *vif,
  765. struct cfg80211_ssid *ssids, int n_ssids,
  766. struct cfg80211_match_set *match_set,
  767. int n_match_ssid)
  768. {
  769. u8 i, j, index_to_add, ssid_found = false;
  770. struct ath6kl_cfg80211_match_probe_ssid ssid_list[MAX_PROBED_SSIDS];
  771. memset(ssid_list, 0, sizeof(ssid_list));
  772. if (n_ssids > MAX_PROBED_SSIDS ||
  773. n_match_ssid > MAX_PROBED_SSIDS)
  774. return -EINVAL;
  775. for (i = 0; i < n_ssids; i++) {
  776. memcpy(ssid_list[i].ssid.ssid,
  777. ssids[i].ssid,
  778. ssids[i].ssid_len);
  779. ssid_list[i].ssid.ssid_len = ssids[i].ssid_len;
  780. if (ssids[i].ssid_len)
  781. ssid_list[i].flag = SPECIFIC_SSID_FLAG;
  782. else
  783. ssid_list[i].flag = ANY_SSID_FLAG;
  784. if (n_match_ssid == 0)
  785. ssid_list[i].flag |= MATCH_SSID_FLAG;
  786. }
  787. index_to_add = i;
  788. for (i = 0; i < n_match_ssid; i++) {
  789. ssid_found = false;
  790. for (j = 0; j < n_ssids; j++) {
  791. if ((match_set[i].ssid.ssid_len ==
  792. ssid_list[j].ssid.ssid_len) &&
  793. (!memcmp(ssid_list[j].ssid.ssid,
  794. match_set[i].ssid.ssid,
  795. match_set[i].ssid.ssid_len))) {
  796. ssid_list[j].flag |= MATCH_SSID_FLAG;
  797. ssid_found = true;
  798. break;
  799. }
  800. }
  801. if (ssid_found)
  802. continue;
  803. if (index_to_add >= MAX_PROBED_SSIDS)
  804. continue;
  805. ssid_list[index_to_add].ssid.ssid_len =
  806. match_set[i].ssid.ssid_len;
  807. memcpy(ssid_list[index_to_add].ssid.ssid,
  808. match_set[i].ssid.ssid,
  809. match_set[i].ssid.ssid_len);
  810. ssid_list[index_to_add].flag |= MATCH_SSID_FLAG;
  811. index_to_add++;
  812. }
  813. for (i = 0; i < index_to_add; i++) {
  814. ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx, i,
  815. ssid_list[i].flag,
  816. ssid_list[i].ssid.ssid_len,
  817. ssid_list[i].ssid.ssid);
  818. }
  819. /* Make sure no old entries are left behind */
  820. for (i = index_to_add; i < MAX_PROBED_SSIDS; i++) {
  821. ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx, i,
  822. DISABLE_SSID_FLAG, 0, NULL);
  823. }
  824. return 0;
  825. }
  826. static int ath6kl_cfg80211_scan(struct wiphy *wiphy,
  827. struct cfg80211_scan_request *request)
  828. {
  829. struct ath6kl_vif *vif = ath6kl_vif_from_wdev(request->wdev);
  830. struct ath6kl *ar = ath6kl_priv(vif->ndev);
  831. s8 n_channels = 0;
  832. u16 *channels = NULL;
  833. int ret = 0;
  834. u32 force_fg_scan = 0;
  835. if (!ath6kl_cfg80211_ready(vif))
  836. return -EIO;
  837. ath6kl_cfg80211_sscan_disable(vif);
  838. if (!ar->usr_bss_filter) {
  839. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  840. ret = ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  841. ALL_BSS_FILTER, 0);
  842. if (ret) {
  843. ath6kl_err("couldn't set bss filtering\n");
  844. return ret;
  845. }
  846. }
  847. ret = ath6kl_set_probed_ssids(ar, vif, request->ssids,
  848. request->n_ssids, NULL, 0);
  849. if (ret < 0)
  850. return ret;
  851. /* this also clears IE in fw if it's not set */
  852. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  853. WMI_FRAME_PROBE_REQ,
  854. request->ie, request->ie_len);
  855. if (ret) {
  856. ath6kl_err("failed to set Probe Request appie for scan\n");
  857. return ret;
  858. }
  859. /*
  860. * Scan only the requested channels if the request specifies a set of
  861. * channels. If the list is longer than the target supports, do not
  862. * configure the list and instead, scan all available channels.
  863. */
  864. if (request->n_channels > 0 &&
  865. request->n_channels <= WMI_MAX_CHANNELS) {
  866. u8 i;
  867. n_channels = request->n_channels;
  868. channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
  869. if (channels == NULL) {
  870. ath6kl_warn("failed to set scan channels, scan all channels");
  871. n_channels = 0;
  872. }
  873. for (i = 0; i < n_channels; i++)
  874. channels[i] = request->channels[i]->center_freq;
  875. }
  876. if (test_bit(CONNECTED, &vif->flags))
  877. force_fg_scan = 1;
  878. vif->scan_req = request;
  879. ret = ath6kl_wmi_beginscan_cmd(ar->wmi, vif->fw_vif_idx,
  880. WMI_LONG_SCAN, force_fg_scan,
  881. false, 0,
  882. ATH6KL_FG_SCAN_INTERVAL,
  883. n_channels, channels,
  884. request->no_cck,
  885. request->rates);
  886. if (ret) {
  887. ath6kl_err("failed to start scan: %d\n", ret);
  888. vif->scan_req = NULL;
  889. }
  890. kfree(channels);
  891. return ret;
  892. }
  893. void ath6kl_cfg80211_scan_complete_event(struct ath6kl_vif *vif, bool aborted)
  894. {
  895. struct ath6kl *ar = vif->ar;
  896. int i;
  897. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status%s\n", __func__,
  898. aborted ? " aborted" : "");
  899. if (!vif->scan_req)
  900. return;
  901. if (aborted)
  902. goto out;
  903. if (vif->scan_req->n_ssids && vif->scan_req->ssids[0].ssid_len) {
  904. for (i = 0; i < vif->scan_req->n_ssids; i++) {
  905. ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
  906. i + 1, DISABLE_SSID_FLAG,
  907. 0, NULL);
  908. }
  909. }
  910. out:
  911. cfg80211_scan_done(vif->scan_req, aborted);
  912. vif->scan_req = NULL;
  913. }
  914. void ath6kl_cfg80211_ch_switch_notify(struct ath6kl_vif *vif, int freq,
  915. enum wmi_phy_mode mode)
  916. {
  917. struct cfg80211_chan_def chandef;
  918. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  919. "channel switch notify nw_type %d freq %d mode %d\n",
  920. vif->nw_type, freq, mode);
  921. cfg80211_chandef_create(&chandef,
  922. ieee80211_get_channel(vif->ar->wiphy, freq),
  923. (mode == WMI_11G_HT20) ?
  924. NL80211_CHAN_HT20 : NL80211_CHAN_NO_HT);
  925. cfg80211_ch_switch_notify(vif->ndev, &chandef);
  926. }
  927. static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
  928. u8 key_index, bool pairwise,
  929. const u8 *mac_addr,
  930. struct key_params *params)
  931. {
  932. struct ath6kl *ar = ath6kl_priv(ndev);
  933. struct ath6kl_vif *vif = netdev_priv(ndev);
  934. struct ath6kl_key *key = NULL;
  935. int seq_len;
  936. u8 key_usage;
  937. u8 key_type;
  938. if (!ath6kl_cfg80211_ready(vif))
  939. return -EIO;
  940. if (params->cipher == CCKM_KRK_CIPHER_SUITE) {
  941. if (params->key_len != WMI_KRK_LEN)
  942. return -EINVAL;
  943. return ath6kl_wmi_add_krk_cmd(ar->wmi, vif->fw_vif_idx,
  944. params->key);
  945. }
  946. if (key_index > WMI_MAX_KEY_INDEX) {
  947. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  948. "%s: key index %d out of bounds\n", __func__,
  949. key_index);
  950. return -ENOENT;
  951. }
  952. key = &vif->keys[key_index];
  953. memset(key, 0, sizeof(struct ath6kl_key));
  954. if (pairwise)
  955. key_usage = PAIRWISE_USAGE;
  956. else
  957. key_usage = GROUP_USAGE;
  958. seq_len = params->seq_len;
  959. if (params->cipher == WLAN_CIPHER_SUITE_SMS4 &&
  960. seq_len > ATH6KL_KEY_SEQ_LEN) {
  961. /* Only first half of the WPI PN is configured */
  962. seq_len = ATH6KL_KEY_SEQ_LEN;
  963. }
  964. if (params->key_len > WLAN_MAX_KEY_LEN ||
  965. seq_len > sizeof(key->seq))
  966. return -EINVAL;
  967. key->key_len = params->key_len;
  968. memcpy(key->key, params->key, key->key_len);
  969. key->seq_len = seq_len;
  970. memcpy(key->seq, params->seq, key->seq_len);
  971. key->cipher = params->cipher;
  972. switch (key->cipher) {
  973. case WLAN_CIPHER_SUITE_WEP40:
  974. case WLAN_CIPHER_SUITE_WEP104:
  975. key_type = WEP_CRYPT;
  976. break;
  977. case WLAN_CIPHER_SUITE_TKIP:
  978. key_type = TKIP_CRYPT;
  979. break;
  980. case WLAN_CIPHER_SUITE_CCMP:
  981. key_type = AES_CRYPT;
  982. break;
  983. case WLAN_CIPHER_SUITE_SMS4:
  984. key_type = WAPI_CRYPT;
  985. break;
  986. default:
  987. return -ENOTSUPP;
  988. }
  989. if (((vif->auth_mode == WPA_PSK_AUTH) ||
  990. (vif->auth_mode == WPA2_PSK_AUTH)) &&
  991. (key_usage & GROUP_USAGE))
  992. del_timer(&vif->disconnect_timer);
  993. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  994. "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
  995. __func__, key_index, key->key_len, key_type,
  996. key_usage, key->seq_len);
  997. if (vif->nw_type == AP_NETWORK && !pairwise &&
  998. (key_type == TKIP_CRYPT || key_type == AES_CRYPT ||
  999. key_type == WAPI_CRYPT)) {
  1000. ar->ap_mode_bkey.valid = true;
  1001. ar->ap_mode_bkey.key_index = key_index;
  1002. ar->ap_mode_bkey.key_type = key_type;
  1003. ar->ap_mode_bkey.key_len = key->key_len;
  1004. memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
  1005. if (!test_bit(CONNECTED, &vif->flags)) {
  1006. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1007. "Delay initial group key configuration until AP mode has been started\n");
  1008. /*
  1009. * The key will be set in ath6kl_connect_ap_mode() once
  1010. * the connected event is received from the target.
  1011. */
  1012. return 0;
  1013. }
  1014. }
  1015. if (vif->next_mode == AP_NETWORK && key_type == WEP_CRYPT &&
  1016. !test_bit(CONNECTED, &vif->flags)) {
  1017. /*
  1018. * Store the key locally so that it can be re-configured after
  1019. * the AP mode has properly started
  1020. * (ath6kl_install_statioc_wep_keys).
  1021. */
  1022. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1023. "Delay WEP key configuration until AP mode has been started\n");
  1024. vif->wep_key_list[key_index].key_len = key->key_len;
  1025. memcpy(vif->wep_key_list[key_index].key, key->key,
  1026. key->key_len);
  1027. return 0;
  1028. }
  1029. return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, key_index,
  1030. key_type, key_usage, key->key_len,
  1031. key->seq, key->seq_len, key->key,
  1032. KEY_OP_INIT_VAL,
  1033. (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
  1034. }
  1035. static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  1036. u8 key_index, bool pairwise,
  1037. const u8 *mac_addr)
  1038. {
  1039. struct ath6kl *ar = ath6kl_priv(ndev);
  1040. struct ath6kl_vif *vif = netdev_priv(ndev);
  1041. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  1042. if (!ath6kl_cfg80211_ready(vif))
  1043. return -EIO;
  1044. if (key_index > WMI_MAX_KEY_INDEX) {
  1045. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1046. "%s: key index %d out of bounds\n", __func__,
  1047. key_index);
  1048. return -ENOENT;
  1049. }
  1050. if (!vif->keys[key_index].key_len) {
  1051. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1052. "%s: index %d is empty\n", __func__, key_index);
  1053. return 0;
  1054. }
  1055. vif->keys[key_index].key_len = 0;
  1056. return ath6kl_wmi_deletekey_cmd(ar->wmi, vif->fw_vif_idx, key_index);
  1057. }
  1058. static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
  1059. u8 key_index, bool pairwise,
  1060. const u8 *mac_addr, void *cookie,
  1061. void (*callback) (void *cookie,
  1062. struct key_params *))
  1063. {
  1064. struct ath6kl_vif *vif = netdev_priv(ndev);
  1065. struct ath6kl_key *key = NULL;
  1066. struct key_params params;
  1067. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  1068. if (!ath6kl_cfg80211_ready(vif))
  1069. return -EIO;
  1070. if (key_index > WMI_MAX_KEY_INDEX) {
  1071. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1072. "%s: key index %d out of bounds\n", __func__,
  1073. key_index);
  1074. return -ENOENT;
  1075. }
  1076. key = &vif->keys[key_index];
  1077. memset(&params, 0, sizeof(params));
  1078. params.cipher = key->cipher;
  1079. params.key_len = key->key_len;
  1080. params.seq_len = key->seq_len;
  1081. params.seq = key->seq;
  1082. params.key = key->key;
  1083. callback(cookie, &params);
  1084. return key->key_len ? 0 : -ENOENT;
  1085. }
  1086. static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
  1087. struct net_device *ndev,
  1088. u8 key_index, bool unicast,
  1089. bool multicast)
  1090. {
  1091. struct ath6kl *ar = ath6kl_priv(ndev);
  1092. struct ath6kl_vif *vif = netdev_priv(ndev);
  1093. struct ath6kl_key *key = NULL;
  1094. u8 key_usage;
  1095. enum crypto_type key_type = NONE_CRYPT;
  1096. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  1097. if (!ath6kl_cfg80211_ready(vif))
  1098. return -EIO;
  1099. if (key_index > WMI_MAX_KEY_INDEX) {
  1100. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1101. "%s: key index %d out of bounds\n",
  1102. __func__, key_index);
  1103. return -ENOENT;
  1104. }
  1105. if (!vif->keys[key_index].key_len) {
  1106. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
  1107. __func__, key_index);
  1108. return -EINVAL;
  1109. }
  1110. vif->def_txkey_index = key_index;
  1111. key = &vif->keys[vif->def_txkey_index];
  1112. key_usage = GROUP_USAGE;
  1113. if (vif->prwise_crypto == WEP_CRYPT)
  1114. key_usage |= TX_USAGE;
  1115. if (unicast)
  1116. key_type = vif->prwise_crypto;
  1117. if (multicast)
  1118. key_type = vif->grp_crypto;
  1119. if (vif->next_mode == AP_NETWORK && !test_bit(CONNECTED, &vif->flags))
  1120. return 0; /* Delay until AP mode has been started */
  1121. return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx,
  1122. vif->def_txkey_index,
  1123. key_type, key_usage,
  1124. key->key_len, key->seq, key->seq_len,
  1125. key->key,
  1126. KEY_OP_INIT_VAL, NULL,
  1127. SYNC_BOTH_WMIFLAG);
  1128. }
  1129. void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid,
  1130. bool ismcast)
  1131. {
  1132. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1133. "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
  1134. cfg80211_michael_mic_failure(vif->ndev, vif->bssid,
  1135. (ismcast ? NL80211_KEYTYPE_GROUP :
  1136. NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
  1137. GFP_KERNEL);
  1138. }
  1139. static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1140. {
  1141. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  1142. struct ath6kl_vif *vif;
  1143. int ret;
  1144. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
  1145. changed);
  1146. vif = ath6kl_vif_first(ar);
  1147. if (!vif)
  1148. return -EIO;
  1149. if (!ath6kl_cfg80211_ready(vif))
  1150. return -EIO;
  1151. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1152. ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
  1153. if (ret != 0) {
  1154. ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
  1155. return -EIO;
  1156. }
  1157. }
  1158. return 0;
  1159. }
  1160. static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
  1161. struct wireless_dev *wdev,
  1162. enum nl80211_tx_power_setting type,
  1163. int mbm)
  1164. {
  1165. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  1166. struct ath6kl_vif *vif;
  1167. int dbm = MBM_TO_DBM(mbm);
  1168. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
  1169. type, dbm);
  1170. vif = ath6kl_vif_first(ar);
  1171. if (!vif)
  1172. return -EIO;
  1173. if (!ath6kl_cfg80211_ready(vif))
  1174. return -EIO;
  1175. switch (type) {
  1176. case NL80211_TX_POWER_AUTOMATIC:
  1177. return 0;
  1178. case NL80211_TX_POWER_LIMITED:
  1179. ar->tx_pwr = dbm;
  1180. break;
  1181. default:
  1182. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
  1183. __func__, type);
  1184. return -EOPNOTSUPP;
  1185. }
  1186. ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx, dbm);
  1187. return 0;
  1188. }
  1189. static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy,
  1190. struct wireless_dev *wdev,
  1191. int *dbm)
  1192. {
  1193. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  1194. struct ath6kl_vif *vif;
  1195. vif = ath6kl_vif_first(ar);
  1196. if (!vif)
  1197. return -EIO;
  1198. if (!ath6kl_cfg80211_ready(vif))
  1199. return -EIO;
  1200. if (test_bit(CONNECTED, &vif->flags)) {
  1201. ar->tx_pwr = 0;
  1202. if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx) != 0) {
  1203. ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
  1204. return -EIO;
  1205. }
  1206. wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
  1207. 5 * HZ);
  1208. if (signal_pending(current)) {
  1209. ath6kl_err("target did not respond\n");
  1210. return -EINTR;
  1211. }
  1212. }
  1213. *dbm = ar->tx_pwr;
  1214. return 0;
  1215. }
  1216. static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  1217. struct net_device *dev,
  1218. bool pmgmt, int timeout)
  1219. {
  1220. struct ath6kl *ar = ath6kl_priv(dev);
  1221. struct wmi_power_mode_cmd mode;
  1222. struct ath6kl_vif *vif = netdev_priv(dev);
  1223. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
  1224. __func__, pmgmt, timeout);
  1225. if (!ath6kl_cfg80211_ready(vif))
  1226. return -EIO;
  1227. if (pmgmt) {
  1228. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
  1229. mode.pwr_mode = REC_POWER;
  1230. } else {
  1231. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
  1232. mode.pwr_mode = MAX_PERF_POWER;
  1233. }
  1234. if (ath6kl_wmi_powermode_cmd(ar->wmi, vif->fw_vif_idx,
  1235. mode.pwr_mode) != 0) {
  1236. ath6kl_err("wmi_powermode_cmd failed\n");
  1237. return -EIO;
  1238. }
  1239. return 0;
  1240. }
  1241. static struct wireless_dev *ath6kl_cfg80211_add_iface(struct wiphy *wiphy,
  1242. const char *name,
  1243. enum nl80211_iftype type,
  1244. u32 *flags,
  1245. struct vif_params *params)
  1246. {
  1247. struct ath6kl *ar = wiphy_priv(wiphy);
  1248. struct wireless_dev *wdev;
  1249. u8 if_idx, nw_type;
  1250. if (ar->num_vif == ar->vif_max) {
  1251. ath6kl_err("Reached maximum number of supported vif\n");
  1252. return ERR_PTR(-EINVAL);
  1253. }
  1254. if (!ath6kl_is_valid_iftype(ar, type, &if_idx, &nw_type)) {
  1255. ath6kl_err("Not a supported interface type\n");
  1256. return ERR_PTR(-EINVAL);
  1257. }
  1258. wdev = ath6kl_interface_add(ar, name, type, if_idx, nw_type);
  1259. if (!wdev)
  1260. return ERR_PTR(-ENOMEM);
  1261. ar->num_vif++;
  1262. return wdev;
  1263. }
  1264. static int ath6kl_cfg80211_del_iface(struct wiphy *wiphy,
  1265. struct wireless_dev *wdev)
  1266. {
  1267. struct ath6kl *ar = wiphy_priv(wiphy);
  1268. struct ath6kl_vif *vif = netdev_priv(wdev->netdev);
  1269. spin_lock_bh(&ar->list_lock);
  1270. list_del(&vif->list);
  1271. spin_unlock_bh(&ar->list_lock);
  1272. ath6kl_cfg80211_vif_stop(vif, test_bit(WMI_READY, &ar->flag));
  1273. rtnl_lock();
  1274. ath6kl_cfg80211_vif_cleanup(vif);
  1275. rtnl_unlock();
  1276. return 0;
  1277. }
  1278. static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
  1279. struct net_device *ndev,
  1280. enum nl80211_iftype type, u32 *flags,
  1281. struct vif_params *params)
  1282. {
  1283. struct ath6kl_vif *vif = netdev_priv(ndev);
  1284. int i;
  1285. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
  1286. /*
  1287. * Don't bring up p2p on an interface which is not initialized
  1288. * for p2p operation where fw does not have capability to switch
  1289. * dynamically between non-p2p and p2p type interface.
  1290. */
  1291. if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  1292. vif->ar->fw_capabilities) &&
  1293. (type == NL80211_IFTYPE_P2P_CLIENT ||
  1294. type == NL80211_IFTYPE_P2P_GO)) {
  1295. if (vif->ar->vif_max == 1) {
  1296. if (vif->fw_vif_idx != 0)
  1297. return -EINVAL;
  1298. else
  1299. goto set_iface_type;
  1300. }
  1301. for (i = vif->ar->max_norm_iface; i < vif->ar->vif_max; i++) {
  1302. if (i == vif->fw_vif_idx)
  1303. break;
  1304. }
  1305. if (i == vif->ar->vif_max) {
  1306. ath6kl_err("Invalid interface to bring up P2P\n");
  1307. return -EINVAL;
  1308. }
  1309. }
  1310. /* need to clean up enhanced bmiss detection fw state */
  1311. ath6kl_cfg80211_sta_bmiss_enhance(vif, false);
  1312. set_iface_type:
  1313. switch (type) {
  1314. case NL80211_IFTYPE_STATION:
  1315. case NL80211_IFTYPE_P2P_CLIENT:
  1316. vif->next_mode = INFRA_NETWORK;
  1317. break;
  1318. case NL80211_IFTYPE_ADHOC:
  1319. vif->next_mode = ADHOC_NETWORK;
  1320. break;
  1321. case NL80211_IFTYPE_AP:
  1322. case NL80211_IFTYPE_P2P_GO:
  1323. vif->next_mode = AP_NETWORK;
  1324. break;
  1325. default:
  1326. ath6kl_err("invalid interface type %u\n", type);
  1327. return -EOPNOTSUPP;
  1328. }
  1329. vif->wdev.iftype = type;
  1330. return 0;
  1331. }
  1332. static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
  1333. struct net_device *dev,
  1334. struct cfg80211_ibss_params *ibss_param)
  1335. {
  1336. struct ath6kl *ar = ath6kl_priv(dev);
  1337. struct ath6kl_vif *vif = netdev_priv(dev);
  1338. int status;
  1339. if (!ath6kl_cfg80211_ready(vif))
  1340. return -EIO;
  1341. vif->ssid_len = ibss_param->ssid_len;
  1342. memcpy(vif->ssid, ibss_param->ssid, vif->ssid_len);
  1343. if (ibss_param->chandef.chan)
  1344. vif->ch_hint = ibss_param->chandef.chan->center_freq;
  1345. if (ibss_param->channel_fixed) {
  1346. /*
  1347. * TODO: channel_fixed: The channel should be fixed, do not
  1348. * search for IBSSs to join on other channels. Target
  1349. * firmware does not support this feature, needs to be
  1350. * updated.
  1351. */
  1352. return -EOPNOTSUPP;
  1353. }
  1354. memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
  1355. if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
  1356. memcpy(vif->req_bssid, ibss_param->bssid,
  1357. sizeof(vif->req_bssid));
  1358. ath6kl_set_wpa_version(vif, 0);
  1359. status = ath6kl_set_auth_type(vif, NL80211_AUTHTYPE_OPEN_SYSTEM);
  1360. if (status)
  1361. return status;
  1362. if (ibss_param->privacy) {
  1363. ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, true);
  1364. ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, false);
  1365. } else {
  1366. ath6kl_set_cipher(vif, 0, true);
  1367. ath6kl_set_cipher(vif, 0, false);
  1368. }
  1369. vif->nw_type = vif->next_mode;
  1370. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1371. "%s: connect called with authmode %d dot11 auth %d"
  1372. " PW crypto %d PW crypto len %d GRP crypto %d"
  1373. " GRP crypto len %d channel hint %u\n",
  1374. __func__,
  1375. vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
  1376. vif->prwise_crypto_len, vif->grp_crypto,
  1377. vif->grp_crypto_len, vif->ch_hint);
  1378. status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
  1379. vif->dot11_auth_mode, vif->auth_mode,
  1380. vif->prwise_crypto,
  1381. vif->prwise_crypto_len,
  1382. vif->grp_crypto, vif->grp_crypto_len,
  1383. vif->ssid_len, vif->ssid,
  1384. vif->req_bssid, vif->ch_hint,
  1385. ar->connect_ctrl_flags, SUBTYPE_NONE);
  1386. set_bit(CONNECT_PEND, &vif->flags);
  1387. return 0;
  1388. }
  1389. static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
  1390. struct net_device *dev)
  1391. {
  1392. struct ath6kl_vif *vif = netdev_priv(dev);
  1393. if (!ath6kl_cfg80211_ready(vif))
  1394. return -EIO;
  1395. ath6kl_disconnect(vif);
  1396. memset(vif->ssid, 0, sizeof(vif->ssid));
  1397. vif->ssid_len = 0;
  1398. return 0;
  1399. }
  1400. static const u32 cipher_suites[] = {
  1401. WLAN_CIPHER_SUITE_WEP40,
  1402. WLAN_CIPHER_SUITE_WEP104,
  1403. WLAN_CIPHER_SUITE_TKIP,
  1404. WLAN_CIPHER_SUITE_CCMP,
  1405. CCKM_KRK_CIPHER_SUITE,
  1406. WLAN_CIPHER_SUITE_SMS4,
  1407. };
  1408. static bool is_rate_legacy(s32 rate)
  1409. {
  1410. static const s32 legacy[] = { 1000, 2000, 5500, 11000,
  1411. 6000, 9000, 12000, 18000, 24000,
  1412. 36000, 48000, 54000
  1413. };
  1414. u8 i;
  1415. for (i = 0; i < ARRAY_SIZE(legacy); i++)
  1416. if (rate == legacy[i])
  1417. return true;
  1418. return false;
  1419. }
  1420. static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
  1421. {
  1422. static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
  1423. 52000, 58500, 65000, 72200
  1424. };
  1425. u8 i;
  1426. for (i = 0; i < ARRAY_SIZE(ht20); i++) {
  1427. if (rate == ht20[i]) {
  1428. if (i == ARRAY_SIZE(ht20) - 1)
  1429. /* last rate uses sgi */
  1430. *sgi = true;
  1431. else
  1432. *sgi = false;
  1433. *mcs = i;
  1434. return true;
  1435. }
  1436. }
  1437. return false;
  1438. }
  1439. static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
  1440. {
  1441. static const s32 ht40[] = { 13500, 27000, 40500, 54000,
  1442. 81000, 108000, 121500, 135000,
  1443. 150000
  1444. };
  1445. u8 i;
  1446. for (i = 0; i < ARRAY_SIZE(ht40); i++) {
  1447. if (rate == ht40[i]) {
  1448. if (i == ARRAY_SIZE(ht40) - 1)
  1449. /* last rate uses sgi */
  1450. *sgi = true;
  1451. else
  1452. *sgi = false;
  1453. *mcs = i;
  1454. return true;
  1455. }
  1456. }
  1457. return false;
  1458. }
  1459. static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
  1460. u8 *mac, struct station_info *sinfo)
  1461. {
  1462. struct ath6kl *ar = ath6kl_priv(dev);
  1463. struct ath6kl_vif *vif = netdev_priv(dev);
  1464. long left;
  1465. bool sgi;
  1466. s32 rate;
  1467. int ret;
  1468. u8 mcs;
  1469. if (memcmp(mac, vif->bssid, ETH_ALEN) != 0)
  1470. return -ENOENT;
  1471. if (down_interruptible(&ar->sem))
  1472. return -EBUSY;
  1473. set_bit(STATS_UPDATE_PEND, &vif->flags);
  1474. ret = ath6kl_wmi_get_stats_cmd(ar->wmi, vif->fw_vif_idx);
  1475. if (ret != 0) {
  1476. up(&ar->sem);
  1477. return -EIO;
  1478. }
  1479. left = wait_event_interruptible_timeout(ar->event_wq,
  1480. !test_bit(STATS_UPDATE_PEND,
  1481. &vif->flags),
  1482. WMI_TIMEOUT);
  1483. up(&ar->sem);
  1484. if (left == 0)
  1485. return -ETIMEDOUT;
  1486. else if (left < 0)
  1487. return left;
  1488. if (vif->target_stats.rx_byte) {
  1489. sinfo->rx_bytes = vif->target_stats.rx_byte;
  1490. sinfo->filled |= STATION_INFO_RX_BYTES64;
  1491. sinfo->rx_packets = vif->target_stats.rx_pkt;
  1492. sinfo->filled |= STATION_INFO_RX_PACKETS;
  1493. }
  1494. if (vif->target_stats.tx_byte) {
  1495. sinfo->tx_bytes = vif->target_stats.tx_byte;
  1496. sinfo->filled |= STATION_INFO_TX_BYTES64;
  1497. sinfo->tx_packets = vif->target_stats.tx_pkt;
  1498. sinfo->filled |= STATION_INFO_TX_PACKETS;
  1499. }
  1500. sinfo->signal = vif->target_stats.cs_rssi;
  1501. sinfo->filled |= STATION_INFO_SIGNAL;
  1502. rate = vif->target_stats.tx_ucast_rate;
  1503. if (is_rate_legacy(rate)) {
  1504. sinfo->txrate.legacy = rate / 100;
  1505. } else if (is_rate_ht20(rate, &mcs, &sgi)) {
  1506. if (sgi) {
  1507. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1508. sinfo->txrate.mcs = mcs - 1;
  1509. } else {
  1510. sinfo->txrate.mcs = mcs;
  1511. }
  1512. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1513. } else if (is_rate_ht40(rate, &mcs, &sgi)) {
  1514. if (sgi) {
  1515. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1516. sinfo->txrate.mcs = mcs - 1;
  1517. } else {
  1518. sinfo->txrate.mcs = mcs;
  1519. }
  1520. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  1521. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1522. } else {
  1523. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1524. "invalid rate from stats: %d\n", rate);
  1525. ath6kl_debug_war(ar, ATH6KL_WAR_INVALID_RATE);
  1526. return 0;
  1527. }
  1528. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1529. if (test_bit(CONNECTED, &vif->flags) &&
  1530. test_bit(DTIM_PERIOD_AVAIL, &vif->flags) &&
  1531. vif->nw_type == INFRA_NETWORK) {
  1532. sinfo->filled |= STATION_INFO_BSS_PARAM;
  1533. sinfo->bss_param.flags = 0;
  1534. sinfo->bss_param.dtim_period = vif->assoc_bss_dtim_period;
  1535. sinfo->bss_param.beacon_interval = vif->assoc_bss_beacon_int;
  1536. }
  1537. return 0;
  1538. }
  1539. static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1540. struct cfg80211_pmksa *pmksa)
  1541. {
  1542. struct ath6kl *ar = ath6kl_priv(netdev);
  1543. struct ath6kl_vif *vif = netdev_priv(netdev);
  1544. return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
  1545. pmksa->pmkid, true);
  1546. }
  1547. static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1548. struct cfg80211_pmksa *pmksa)
  1549. {
  1550. struct ath6kl *ar = ath6kl_priv(netdev);
  1551. struct ath6kl_vif *vif = netdev_priv(netdev);
  1552. return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
  1553. pmksa->pmkid, false);
  1554. }
  1555. static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
  1556. {
  1557. struct ath6kl *ar = ath6kl_priv(netdev);
  1558. struct ath6kl_vif *vif = netdev_priv(netdev);
  1559. if (test_bit(CONNECTED, &vif->flags))
  1560. return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx,
  1561. vif->bssid, NULL, false);
  1562. return 0;
  1563. }
  1564. static int ath6kl_wow_usr(struct ath6kl *ar, struct ath6kl_vif *vif,
  1565. struct cfg80211_wowlan *wow, u32 *filter)
  1566. {
  1567. int ret, pos;
  1568. u8 mask[WOW_PATTERN_SIZE];
  1569. u16 i;
  1570. /* Configure the patterns that we received from the user. */
  1571. for (i = 0; i < wow->n_patterns; i++) {
  1572. /*
  1573. * Convert given nl80211 specific mask value to equivalent
  1574. * driver specific mask value and send it to the chip along
  1575. * with patterns. For example, If the mask value defined in
  1576. * struct cfg80211_wowlan is 0xA (equivalent binary is 1010),
  1577. * then equivalent driver specific mask value is
  1578. * "0xFF 0x00 0xFF 0x00".
  1579. */
  1580. memset(&mask, 0, sizeof(mask));
  1581. for (pos = 0; pos < wow->patterns[i].pattern_len; pos++) {
  1582. if (wow->patterns[i].mask[pos / 8] & (0x1 << (pos % 8)))
  1583. mask[pos] = 0xFF;
  1584. }
  1585. /*
  1586. * Note: Pattern's offset is not passed as part of wowlan
  1587. * parameter from CFG layer. So it's always passed as ZERO
  1588. * to the firmware. It means, given WOW patterns are always
  1589. * matched from the first byte of received pkt in the firmware.
  1590. */
  1591. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1592. vif->fw_vif_idx, WOW_LIST_ID,
  1593. wow->patterns[i].pattern_len,
  1594. 0 /* pattern offset */,
  1595. wow->patterns[i].pattern, mask);
  1596. if (ret)
  1597. return ret;
  1598. }
  1599. if (wow->disconnect)
  1600. *filter |= WOW_FILTER_OPTION_NWK_DISASSOC;
  1601. if (wow->magic_pkt)
  1602. *filter |= WOW_FILTER_OPTION_MAGIC_PACKET;
  1603. if (wow->gtk_rekey_failure)
  1604. *filter |= WOW_FILTER_OPTION_GTK_ERROR;
  1605. if (wow->eap_identity_req)
  1606. *filter |= WOW_FILTER_OPTION_EAP_REQ;
  1607. if (wow->four_way_handshake)
  1608. *filter |= WOW_FILTER_OPTION_8021X_4WAYHS;
  1609. return 0;
  1610. }
  1611. static int ath6kl_wow_ap(struct ath6kl *ar, struct ath6kl_vif *vif)
  1612. {
  1613. static const u8 unicst_pattern[] = { 0x00, 0x00, 0x00,
  1614. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1615. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1616. 0x00, 0x08 };
  1617. static const u8 unicst_mask[] = { 0x01, 0x00, 0x00,
  1618. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1619. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1620. 0x00, 0x7f };
  1621. u8 unicst_offset = 0;
  1622. static const u8 arp_pattern[] = { 0x08, 0x06 };
  1623. static const u8 arp_mask[] = { 0xff, 0xff };
  1624. u8 arp_offset = 20;
  1625. static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 };
  1626. static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 };
  1627. u8 discvr_offset = 38;
  1628. static const u8 dhcp_pattern[] = { 0xff, 0xff, 0xff, 0xff,
  1629. 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1630. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
  1631. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1632. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1633. 0x00, 0x00, 0x00, 0x00, 0x00, 0x43 /* port 67 */ };
  1634. static const u8 dhcp_mask[] = { 0xff, 0xff, 0xff, 0xff,
  1635. 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1636. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
  1637. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1638. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1639. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff /* port 67 */ };
  1640. u8 dhcp_offset = 0;
  1641. int ret;
  1642. /* Setup unicast IP, EAPOL-like and ARP pkt pattern */
  1643. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1644. vif->fw_vif_idx, WOW_LIST_ID,
  1645. sizeof(unicst_pattern), unicst_offset,
  1646. unicst_pattern, unicst_mask);
  1647. if (ret) {
  1648. ath6kl_err("failed to add WOW unicast IP pattern\n");
  1649. return ret;
  1650. }
  1651. /* Setup all ARP pkt pattern */
  1652. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1653. vif->fw_vif_idx, WOW_LIST_ID,
  1654. sizeof(arp_pattern), arp_offset,
  1655. arp_pattern, arp_mask);
  1656. if (ret) {
  1657. ath6kl_err("failed to add WOW ARP pattern\n");
  1658. return ret;
  1659. }
  1660. /*
  1661. * Setup multicast pattern for mDNS 224.0.0.251,
  1662. * SSDP 239.255.255.250 and LLMNR 224.0.0.252
  1663. */
  1664. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1665. vif->fw_vif_idx, WOW_LIST_ID,
  1666. sizeof(discvr_pattern), discvr_offset,
  1667. discvr_pattern, discvr_mask);
  1668. if (ret) {
  1669. ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR pattern\n");
  1670. return ret;
  1671. }
  1672. /* Setup all DHCP broadcast pkt pattern */
  1673. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1674. vif->fw_vif_idx, WOW_LIST_ID,
  1675. sizeof(dhcp_pattern), dhcp_offset,
  1676. dhcp_pattern, dhcp_mask);
  1677. if (ret) {
  1678. ath6kl_err("failed to add WOW DHCP broadcast pattern\n");
  1679. return ret;
  1680. }
  1681. return 0;
  1682. }
  1683. static int ath6kl_wow_sta(struct ath6kl *ar, struct ath6kl_vif *vif)
  1684. {
  1685. struct net_device *ndev = vif->ndev;
  1686. static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 };
  1687. static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 };
  1688. u8 discvr_offset = 38;
  1689. u8 mac_mask[ETH_ALEN];
  1690. int ret;
  1691. /* Setup unicast pkt pattern */
  1692. memset(mac_mask, 0xff, ETH_ALEN);
  1693. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1694. vif->fw_vif_idx, WOW_LIST_ID,
  1695. ETH_ALEN, 0, ndev->dev_addr,
  1696. mac_mask);
  1697. if (ret) {
  1698. ath6kl_err("failed to add WOW unicast pattern\n");
  1699. return ret;
  1700. }
  1701. /*
  1702. * Setup multicast pattern for mDNS 224.0.0.251,
  1703. * SSDP 239.255.255.250 and LLMNR 224.0.0.252
  1704. */
  1705. if ((ndev->flags & IFF_ALLMULTI) ||
  1706. (ndev->flags & IFF_MULTICAST && netdev_mc_count(ndev) > 0)) {
  1707. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1708. vif->fw_vif_idx, WOW_LIST_ID,
  1709. sizeof(discvr_pattern), discvr_offset,
  1710. discvr_pattern, discvr_mask);
  1711. if (ret) {
  1712. ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR pattern\n");
  1713. return ret;
  1714. }
  1715. }
  1716. return 0;
  1717. }
  1718. static int is_hsleep_mode_procsed(struct ath6kl_vif *vif)
  1719. {
  1720. return test_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
  1721. }
  1722. static bool is_ctrl_ep_empty(struct ath6kl *ar)
  1723. {
  1724. return !ar->tx_pending[ar->ctrl_ep];
  1725. }
  1726. static int ath6kl_cfg80211_host_sleep(struct ath6kl *ar, struct ath6kl_vif *vif)
  1727. {
  1728. int ret, left;
  1729. clear_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
  1730. ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1731. ATH6KL_HOST_MODE_ASLEEP);
  1732. if (ret)
  1733. return ret;
  1734. left = wait_event_interruptible_timeout(ar->event_wq,
  1735. is_hsleep_mode_procsed(vif),
  1736. WMI_TIMEOUT);
  1737. if (left == 0) {
  1738. ath6kl_warn("timeout, didn't get host sleep cmd processed event\n");
  1739. ret = -ETIMEDOUT;
  1740. } else if (left < 0) {
  1741. ath6kl_warn("error while waiting for host sleep cmd processed event %d\n",
  1742. left);
  1743. ret = left;
  1744. }
  1745. if (ar->tx_pending[ar->ctrl_ep]) {
  1746. left = wait_event_interruptible_timeout(ar->event_wq,
  1747. is_ctrl_ep_empty(ar),
  1748. WMI_TIMEOUT);
  1749. if (left == 0) {
  1750. ath6kl_warn("clear wmi ctrl data timeout\n");
  1751. ret = -ETIMEDOUT;
  1752. } else if (left < 0) {
  1753. ath6kl_warn("clear wmi ctrl data failed: %d\n", left);
  1754. ret = left;
  1755. }
  1756. }
  1757. return ret;
  1758. }
  1759. static int ath6kl_wow_suspend_vif(struct ath6kl_vif *vif,
  1760. struct cfg80211_wowlan *wow, u32 *filter)
  1761. {
  1762. struct ath6kl *ar = vif->ar;
  1763. struct in_device *in_dev;
  1764. struct in_ifaddr *ifa;
  1765. int ret;
  1766. u16 i, bmiss_time;
  1767. __be32 ips[MAX_IP_ADDRS];
  1768. u8 index = 0;
  1769. if (!test_bit(NETDEV_MCAST_ALL_ON, &vif->flags) &&
  1770. test_bit(ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER,
  1771. ar->fw_capabilities)) {
  1772. ret = ath6kl_wmi_mcast_filter_cmd(vif->ar->wmi,
  1773. vif->fw_vif_idx, false);
  1774. if (ret)
  1775. return ret;
  1776. }
  1777. /* Clear existing WOW patterns */
  1778. for (i = 0; i < WOW_MAX_FILTERS_PER_LIST; i++)
  1779. ath6kl_wmi_del_wow_pattern_cmd(ar->wmi, vif->fw_vif_idx,
  1780. WOW_LIST_ID, i);
  1781. /*
  1782. * Skip the default WOW pattern configuration
  1783. * if the driver receives any WOW patterns from
  1784. * the user.
  1785. */
  1786. if (wow)
  1787. ret = ath6kl_wow_usr(ar, vif, wow, filter);
  1788. else if (vif->nw_type == AP_NETWORK)
  1789. ret = ath6kl_wow_ap(ar, vif);
  1790. else
  1791. ret = ath6kl_wow_sta(ar, vif);
  1792. if (ret)
  1793. return ret;
  1794. netif_stop_queue(vif->ndev);
  1795. if (vif->nw_type != AP_NETWORK) {
  1796. ret = ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  1797. ATH6KL_MAX_WOW_LISTEN_INTL,
  1798. 0);
  1799. if (ret)
  1800. return ret;
  1801. /* Set listen interval x 15 times as bmiss time */
  1802. bmiss_time = ATH6KL_MAX_WOW_LISTEN_INTL * 15;
  1803. if (bmiss_time > ATH6KL_MAX_BMISS_TIME)
  1804. bmiss_time = ATH6KL_MAX_BMISS_TIME;
  1805. ret = ath6kl_wmi_bmisstime_cmd(ar->wmi, vif->fw_vif_idx,
  1806. bmiss_time, 0);
  1807. if (ret)
  1808. return ret;
  1809. ret = ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
  1810. 0xFFFF, 0, 0xFFFF, 0, 0, 0,
  1811. 0, 0, 0, 0);
  1812. if (ret)
  1813. return ret;
  1814. }
  1815. /* Setup own IP addr for ARP agent. */
  1816. in_dev = __in_dev_get_rtnl(vif->ndev);
  1817. if (!in_dev)
  1818. return 0;
  1819. ifa = in_dev->ifa_list;
  1820. memset(&ips, 0, sizeof(ips));
  1821. /* Configure IP addr only if IP address count < MAX_IP_ADDRS */
  1822. while (index < MAX_IP_ADDRS && ifa) {
  1823. ips[index] = ifa->ifa_local;
  1824. ifa = ifa->ifa_next;
  1825. index++;
  1826. }
  1827. if (ifa) {
  1828. ath6kl_err("total IP addr count is exceeding fw limit\n");
  1829. return -EINVAL;
  1830. }
  1831. ret = ath6kl_wmi_set_ip_cmd(ar->wmi, vif->fw_vif_idx, ips[0], ips[1]);
  1832. if (ret) {
  1833. ath6kl_err("fail to setup ip for arp agent\n");
  1834. return ret;
  1835. }
  1836. return ret;
  1837. }
  1838. static int ath6kl_wow_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
  1839. {
  1840. struct ath6kl_vif *first_vif, *vif;
  1841. int ret = 0;
  1842. u32 filter = 0;
  1843. bool connected = false;
  1844. /* enter / leave wow suspend on first vif always */
  1845. first_vif = ath6kl_vif_first(ar);
  1846. if (WARN_ON(unlikely(!first_vif)) ||
  1847. !ath6kl_cfg80211_ready(first_vif))
  1848. return -EIO;
  1849. if (wow && (wow->n_patterns > WOW_MAX_FILTERS_PER_LIST))
  1850. return -EINVAL;
  1851. /* install filters for each connected vif */
  1852. spin_lock_bh(&ar->list_lock);
  1853. list_for_each_entry(vif, &ar->vif_list, list) {
  1854. if (!test_bit(CONNECTED, &vif->flags) ||
  1855. !ath6kl_cfg80211_ready(vif))
  1856. continue;
  1857. connected = true;
  1858. ret = ath6kl_wow_suspend_vif(vif, wow, &filter);
  1859. if (ret)
  1860. break;
  1861. }
  1862. spin_unlock_bh(&ar->list_lock);
  1863. if (!connected)
  1864. return -ENOTCONN;
  1865. else if (ret)
  1866. return ret;
  1867. ar->state = ATH6KL_STATE_SUSPENDING;
  1868. ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, first_vif->fw_vif_idx,
  1869. ATH6KL_WOW_MODE_ENABLE,
  1870. filter,
  1871. WOW_HOST_REQ_DELAY);
  1872. if (ret)
  1873. return ret;
  1874. return ath6kl_cfg80211_host_sleep(ar, first_vif);
  1875. }
  1876. static int ath6kl_wow_resume_vif(struct ath6kl_vif *vif)
  1877. {
  1878. struct ath6kl *ar = vif->ar;
  1879. int ret;
  1880. if (vif->nw_type != AP_NETWORK) {
  1881. ret = ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
  1882. 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
  1883. if (ret)
  1884. return ret;
  1885. ret = ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  1886. vif->listen_intvl_t, 0);
  1887. if (ret)
  1888. return ret;
  1889. ret = ath6kl_wmi_bmisstime_cmd(ar->wmi, vif->fw_vif_idx,
  1890. vif->bmiss_time_t, 0);
  1891. if (ret)
  1892. return ret;
  1893. }
  1894. if (!test_bit(NETDEV_MCAST_ALL_OFF, &vif->flags) &&
  1895. test_bit(ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER,
  1896. ar->fw_capabilities)) {
  1897. ret = ath6kl_wmi_mcast_filter_cmd(vif->ar->wmi,
  1898. vif->fw_vif_idx, true);
  1899. if (ret)
  1900. return ret;
  1901. }
  1902. netif_wake_queue(vif->ndev);
  1903. return 0;
  1904. }
  1905. static int ath6kl_wow_resume(struct ath6kl *ar)
  1906. {
  1907. struct ath6kl_vif *vif;
  1908. int ret;
  1909. vif = ath6kl_vif_first(ar);
  1910. if (WARN_ON(unlikely(!vif)) ||
  1911. !ath6kl_cfg80211_ready(vif))
  1912. return -EIO;
  1913. ar->state = ATH6KL_STATE_RESUMING;
  1914. ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1915. ATH6KL_HOST_MODE_AWAKE);
  1916. if (ret) {
  1917. ath6kl_warn("Failed to configure host sleep mode for wow resume: %d\n",
  1918. ret);
  1919. goto cleanup;
  1920. }
  1921. spin_lock_bh(&ar->list_lock);
  1922. list_for_each_entry(vif, &ar->vif_list, list) {
  1923. if (!test_bit(CONNECTED, &vif->flags) ||
  1924. !ath6kl_cfg80211_ready(vif))
  1925. continue;
  1926. ret = ath6kl_wow_resume_vif(vif);
  1927. if (ret)
  1928. break;
  1929. }
  1930. spin_unlock_bh(&ar->list_lock);
  1931. if (ret)
  1932. goto cleanup;
  1933. ar->state = ATH6KL_STATE_ON;
  1934. return 0;
  1935. cleanup:
  1936. ar->state = ATH6KL_STATE_WOW;
  1937. return ret;
  1938. }
  1939. static int ath6kl_cfg80211_deepsleep_suspend(struct ath6kl *ar)
  1940. {
  1941. struct ath6kl_vif *vif;
  1942. int ret;
  1943. vif = ath6kl_vif_first(ar);
  1944. if (!vif)
  1945. return -EIO;
  1946. if (!test_bit(WMI_READY, &ar->flag)) {
  1947. ath6kl_err("deepsleep failed as wmi is not ready\n");
  1948. return -EIO;
  1949. }
  1950. ath6kl_cfg80211_stop_all(ar);
  1951. /* Save the current power mode before enabling power save */
  1952. ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
  1953. ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER);
  1954. if (ret)
  1955. return ret;
  1956. /* Disable WOW mode */
  1957. ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1958. ATH6KL_WOW_MODE_DISABLE,
  1959. 0, 0);
  1960. if (ret)
  1961. return ret;
  1962. /* Flush all non control pkts in TX path */
  1963. ath6kl_tx_data_cleanup(ar);
  1964. ret = ath6kl_cfg80211_host_sleep(ar, vif);
  1965. if (ret)
  1966. return ret;
  1967. return 0;
  1968. }
  1969. static int ath6kl_cfg80211_deepsleep_resume(struct ath6kl *ar)
  1970. {
  1971. struct ath6kl_vif *vif;
  1972. int ret;
  1973. vif = ath6kl_vif_first(ar);
  1974. if (!vif)
  1975. return -EIO;
  1976. if (ar->wmi->pwr_mode != ar->wmi->saved_pwr_mode) {
  1977. ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0,
  1978. ar->wmi->saved_pwr_mode);
  1979. if (ret)
  1980. return ret;
  1981. }
  1982. ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1983. ATH6KL_HOST_MODE_AWAKE);
  1984. if (ret)
  1985. return ret;
  1986. ar->state = ATH6KL_STATE_ON;
  1987. /* Reset scan parameter to default values */
  1988. ret = ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
  1989. 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
  1990. if (ret)
  1991. return ret;
  1992. return 0;
  1993. }
  1994. int ath6kl_cfg80211_suspend(struct ath6kl *ar,
  1995. enum ath6kl_cfg_suspend_mode mode,
  1996. struct cfg80211_wowlan *wow)
  1997. {
  1998. struct ath6kl_vif *vif;
  1999. enum ath6kl_state prev_state;
  2000. int ret;
  2001. switch (mode) {
  2002. case ATH6KL_CFG_SUSPEND_WOW:
  2003. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode suspend\n");
  2004. /* Flush all non control pkts in TX path */
  2005. ath6kl_tx_data_cleanup(ar);
  2006. prev_state = ar->state;
  2007. ret = ath6kl_wow_suspend(ar, wow);
  2008. if (ret) {
  2009. ar->state = prev_state;
  2010. return ret;
  2011. }
  2012. ar->state = ATH6KL_STATE_WOW;
  2013. break;
  2014. case ATH6KL_CFG_SUSPEND_DEEPSLEEP:
  2015. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "deep sleep suspend\n");
  2016. ret = ath6kl_cfg80211_deepsleep_suspend(ar);
  2017. if (ret) {
  2018. ath6kl_err("deepsleep suspend failed: %d\n", ret);
  2019. return ret;
  2020. }
  2021. ar->state = ATH6KL_STATE_DEEPSLEEP;
  2022. break;
  2023. case ATH6KL_CFG_SUSPEND_CUTPOWER:
  2024. ath6kl_cfg80211_stop_all(ar);
  2025. if (ar->state == ATH6KL_STATE_OFF) {
  2026. ath6kl_dbg(ATH6KL_DBG_SUSPEND,
  2027. "suspend hw off, no action for cutpower\n");
  2028. break;
  2029. }
  2030. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "suspend cutting power\n");
  2031. ret = ath6kl_init_hw_stop(ar);
  2032. if (ret) {
  2033. ath6kl_warn("failed to stop hw during suspend: %d\n",
  2034. ret);
  2035. }
  2036. ar->state = ATH6KL_STATE_CUTPOWER;
  2037. break;
  2038. default:
  2039. break;
  2040. }
  2041. list_for_each_entry(vif, &ar->vif_list, list)
  2042. ath6kl_cfg80211_scan_complete_event(vif, true);
  2043. return 0;
  2044. }
  2045. EXPORT_SYMBOL(ath6kl_cfg80211_suspend);
  2046. int ath6kl_cfg80211_resume(struct ath6kl *ar)
  2047. {
  2048. int ret;
  2049. switch (ar->state) {
  2050. case ATH6KL_STATE_WOW:
  2051. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode resume\n");
  2052. ret = ath6kl_wow_resume(ar);
  2053. if (ret) {
  2054. ath6kl_warn("wow mode resume failed: %d\n", ret);
  2055. return ret;
  2056. }
  2057. break;
  2058. case ATH6KL_STATE_DEEPSLEEP:
  2059. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "deep sleep resume\n");
  2060. ret = ath6kl_cfg80211_deepsleep_resume(ar);
  2061. if (ret) {
  2062. ath6kl_warn("deep sleep resume failed: %d\n", ret);
  2063. return ret;
  2064. }
  2065. break;
  2066. case ATH6KL_STATE_CUTPOWER:
  2067. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "resume restoring power\n");
  2068. ret = ath6kl_init_hw_start(ar);
  2069. if (ret) {
  2070. ath6kl_warn("Failed to boot hw in resume: %d\n", ret);
  2071. return ret;
  2072. }
  2073. break;
  2074. default:
  2075. break;
  2076. }
  2077. return 0;
  2078. }
  2079. EXPORT_SYMBOL(ath6kl_cfg80211_resume);
  2080. #ifdef CONFIG_PM
  2081. /* hif layer decides what suspend mode to use */
  2082. static int __ath6kl_cfg80211_suspend(struct wiphy *wiphy,
  2083. struct cfg80211_wowlan *wow)
  2084. {
  2085. struct ath6kl *ar = wiphy_priv(wiphy);
  2086. ath6kl_recovery_suspend(ar);
  2087. return ath6kl_hif_suspend(ar, wow);
  2088. }
  2089. static int __ath6kl_cfg80211_resume(struct wiphy *wiphy)
  2090. {
  2091. struct ath6kl *ar = wiphy_priv(wiphy);
  2092. int err;
  2093. err = ath6kl_hif_resume(ar);
  2094. if (err)
  2095. return err;
  2096. ath6kl_recovery_resume(ar);
  2097. return 0;
  2098. }
  2099. /*
  2100. * FIXME: WOW suspend mode is selected if the host sdio controller supports
  2101. * both sdio irq wake up and keep power. The target pulls sdio data line to
  2102. * wake up the host when WOW pattern matches. This causes sdio irq handler
  2103. * is being called in the host side which internally hits ath6kl's RX path.
  2104. *
  2105. * Since sdio interrupt is not disabled, RX path executes even before
  2106. * the host executes the actual resume operation from PM module.
  2107. *
  2108. * In the current scenario, WOW resume should happen before start processing
  2109. * any data from the target. So It's required to perform WOW resume in RX path.
  2110. * Ideally we should perform WOW resume only in the actual platform
  2111. * resume path. This area needs bit rework to avoid WOW resume in RX path.
  2112. *
  2113. * ath6kl_check_wow_status() is called from ath6kl_rx().
  2114. */
  2115. void ath6kl_check_wow_status(struct ath6kl *ar)
  2116. {
  2117. if (ar->state == ATH6KL_STATE_SUSPENDING)
  2118. return;
  2119. if (ar->state == ATH6KL_STATE_WOW)
  2120. ath6kl_cfg80211_resume(ar);
  2121. }
  2122. #else
  2123. void ath6kl_check_wow_status(struct ath6kl *ar)
  2124. {
  2125. }
  2126. #endif
  2127. static int ath6kl_set_htcap(struct ath6kl_vif *vif, enum ieee80211_band band,
  2128. bool ht_enable)
  2129. {
  2130. struct ath6kl_htcap *htcap = &vif->htcap[band];
  2131. if (htcap->ht_enable == ht_enable)
  2132. return 0;
  2133. if (ht_enable) {
  2134. /* Set default ht capabilities */
  2135. htcap->ht_enable = true;
  2136. htcap->cap_info = (band == IEEE80211_BAND_2GHZ) ?
  2137. ath6kl_g_htcap : ath6kl_a_htcap;
  2138. htcap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K;
  2139. } else /* Disable ht */
  2140. memset(htcap, 0, sizeof(*htcap));
  2141. return ath6kl_wmi_set_htcap_cmd(vif->ar->wmi, vif->fw_vif_idx,
  2142. band, htcap);
  2143. }
  2144. static int ath6kl_restore_htcap(struct ath6kl_vif *vif)
  2145. {
  2146. struct wiphy *wiphy = vif->ar->wiphy;
  2147. int band, ret = 0;
  2148. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  2149. if (!wiphy->bands[band])
  2150. continue;
  2151. ret = ath6kl_set_htcap(vif, band,
  2152. wiphy->bands[band]->ht_cap.ht_supported);
  2153. if (ret)
  2154. return ret;
  2155. }
  2156. return ret;
  2157. }
  2158. static bool ath6kl_is_p2p_ie(const u8 *pos)
  2159. {
  2160. return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  2161. pos[2] == 0x50 && pos[3] == 0x6f &&
  2162. pos[4] == 0x9a && pos[5] == 0x09;
  2163. }
  2164. static int ath6kl_set_ap_probe_resp_ies(struct ath6kl_vif *vif,
  2165. const u8 *ies, size_t ies_len)
  2166. {
  2167. struct ath6kl *ar = vif->ar;
  2168. const u8 *pos;
  2169. u8 *buf = NULL;
  2170. size_t len = 0;
  2171. int ret;
  2172. /*
  2173. * Filter out P2P IE(s) since they will be included depending on
  2174. * the Probe Request frame in ath6kl_send_go_probe_resp().
  2175. */
  2176. if (ies && ies_len) {
  2177. buf = kmalloc(ies_len, GFP_KERNEL);
  2178. if (buf == NULL)
  2179. return -ENOMEM;
  2180. pos = ies;
  2181. while (pos + 1 < ies + ies_len) {
  2182. if (pos + 2 + pos[1] > ies + ies_len)
  2183. break;
  2184. if (!ath6kl_is_p2p_ie(pos)) {
  2185. memcpy(buf + len, pos, 2 + pos[1]);
  2186. len += 2 + pos[1];
  2187. }
  2188. pos += 2 + pos[1];
  2189. }
  2190. }
  2191. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  2192. WMI_FRAME_PROBE_RESP, buf, len);
  2193. kfree(buf);
  2194. return ret;
  2195. }
  2196. static int ath6kl_set_ies(struct ath6kl_vif *vif,
  2197. struct cfg80211_beacon_data *info)
  2198. {
  2199. struct ath6kl *ar = vif->ar;
  2200. int res;
  2201. /* this also clears IE in fw if it's not set */
  2202. res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  2203. WMI_FRAME_BEACON,
  2204. info->beacon_ies,
  2205. info->beacon_ies_len);
  2206. if (res)
  2207. return res;
  2208. /* this also clears IE in fw if it's not set */
  2209. res = ath6kl_set_ap_probe_resp_ies(vif, info->proberesp_ies,
  2210. info->proberesp_ies_len);
  2211. if (res)
  2212. return res;
  2213. /* this also clears IE in fw if it's not set */
  2214. res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  2215. WMI_FRAME_ASSOC_RESP,
  2216. info->assocresp_ies,
  2217. info->assocresp_ies_len);
  2218. if (res)
  2219. return res;
  2220. return 0;
  2221. }
  2222. static int ath6kl_get_rsn_capab(struct cfg80211_beacon_data *beacon,
  2223. u8 *rsn_capab)
  2224. {
  2225. const u8 *rsn_ie;
  2226. size_t rsn_ie_len;
  2227. u16 cnt;
  2228. if (!beacon->tail)
  2229. return -EINVAL;
  2230. rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, beacon->tail, beacon->tail_len);
  2231. if (!rsn_ie)
  2232. return -EINVAL;
  2233. rsn_ie_len = *(rsn_ie + 1);
  2234. /* skip element id and length */
  2235. rsn_ie += 2;
  2236. /* skip version */
  2237. if (rsn_ie_len < 2)
  2238. return -EINVAL;
  2239. rsn_ie += 2;
  2240. rsn_ie_len -= 2;
  2241. /* skip group cipher suite */
  2242. if (rsn_ie_len < 4)
  2243. return 0;
  2244. rsn_ie += 4;
  2245. rsn_ie_len -= 4;
  2246. /* skip pairwise cipher suite */
  2247. if (rsn_ie_len < 2)
  2248. return 0;
  2249. cnt = get_unaligned_le16(rsn_ie);
  2250. rsn_ie += (2 + cnt * 4);
  2251. rsn_ie_len -= (2 + cnt * 4);
  2252. /* skip akm suite */
  2253. if (rsn_ie_len < 2)
  2254. return 0;
  2255. cnt = get_unaligned_le16(rsn_ie);
  2256. rsn_ie += (2 + cnt * 4);
  2257. rsn_ie_len -= (2 + cnt * 4);
  2258. if (rsn_ie_len < 2)
  2259. return 0;
  2260. memcpy(rsn_capab, rsn_ie, 2);
  2261. return 0;
  2262. }
  2263. static int ath6kl_start_ap(struct wiphy *wiphy, struct net_device *dev,
  2264. struct cfg80211_ap_settings *info)
  2265. {
  2266. struct ath6kl *ar = ath6kl_priv(dev);
  2267. struct ath6kl_vif *vif = netdev_priv(dev);
  2268. struct ieee80211_mgmt *mgmt;
  2269. bool hidden = false;
  2270. u8 *ies;
  2271. int ies_len;
  2272. struct wmi_connect_cmd p;
  2273. int res;
  2274. int i, ret;
  2275. u16 rsn_capab = 0;
  2276. int inactivity_timeout = 0;
  2277. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s:\n", __func__);
  2278. if (!ath6kl_cfg80211_ready(vif))
  2279. return -EIO;
  2280. if (vif->next_mode != AP_NETWORK)
  2281. return -EOPNOTSUPP;
  2282. res = ath6kl_set_ies(vif, &info->beacon);
  2283. ar->ap_mode_bkey.valid = false;
  2284. ret = ath6kl_wmi_ap_set_beacon_intvl_cmd(ar->wmi, vif->fw_vif_idx,
  2285. info->beacon_interval);
  2286. if (ret)
  2287. ath6kl_warn("Failed to set beacon interval: %d\n", ret);
  2288. ret = ath6kl_wmi_ap_set_dtim_cmd(ar->wmi, vif->fw_vif_idx,
  2289. info->dtim_period);
  2290. /* ignore error, just print a warning and continue normally */
  2291. if (ret)
  2292. ath6kl_warn("Failed to set dtim_period in beacon: %d\n", ret);
  2293. if (info->beacon.head == NULL)
  2294. return -EINVAL;
  2295. mgmt = (struct ieee80211_mgmt *) info->beacon.head;
  2296. ies = mgmt->u.beacon.variable;
  2297. if (ies > info->beacon.head + info->beacon.head_len)
  2298. return -EINVAL;
  2299. ies_len = info->beacon.head + info->beacon.head_len - ies;
  2300. if (info->ssid == NULL)
  2301. return -EINVAL;
  2302. memcpy(vif->ssid, info->ssid, info->ssid_len);
  2303. vif->ssid_len = info->ssid_len;
  2304. if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
  2305. hidden = true;
  2306. res = ath6kl_wmi_ap_hidden_ssid(ar->wmi, vif->fw_vif_idx, hidden);
  2307. if (res)
  2308. return res;
  2309. ret = ath6kl_set_auth_type(vif, info->auth_type);
  2310. if (ret)
  2311. return ret;
  2312. memset(&p, 0, sizeof(p));
  2313. for (i = 0; i < info->crypto.n_akm_suites; i++) {
  2314. switch (info->crypto.akm_suites[i]) {
  2315. case WLAN_AKM_SUITE_8021X:
  2316. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  2317. p.auth_mode |= WPA_AUTH;
  2318. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  2319. p.auth_mode |= WPA2_AUTH;
  2320. break;
  2321. case WLAN_AKM_SUITE_PSK:
  2322. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  2323. p.auth_mode |= WPA_PSK_AUTH;
  2324. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  2325. p.auth_mode |= WPA2_PSK_AUTH;
  2326. break;
  2327. }
  2328. }
  2329. if (p.auth_mode == 0)
  2330. p.auth_mode = NONE_AUTH;
  2331. vif->auth_mode = p.auth_mode;
  2332. for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
  2333. switch (info->crypto.ciphers_pairwise[i]) {
  2334. case WLAN_CIPHER_SUITE_WEP40:
  2335. case WLAN_CIPHER_SUITE_WEP104:
  2336. p.prwise_crypto_type |= WEP_CRYPT;
  2337. break;
  2338. case WLAN_CIPHER_SUITE_TKIP:
  2339. p.prwise_crypto_type |= TKIP_CRYPT;
  2340. break;
  2341. case WLAN_CIPHER_SUITE_CCMP:
  2342. p.prwise_crypto_type |= AES_CRYPT;
  2343. break;
  2344. case WLAN_CIPHER_SUITE_SMS4:
  2345. p.prwise_crypto_type |= WAPI_CRYPT;
  2346. break;
  2347. }
  2348. }
  2349. if (p.prwise_crypto_type == 0) {
  2350. p.prwise_crypto_type = NONE_CRYPT;
  2351. ath6kl_set_cipher(vif, 0, true);
  2352. } else if (info->crypto.n_ciphers_pairwise == 1)
  2353. ath6kl_set_cipher(vif, info->crypto.ciphers_pairwise[0], true);
  2354. switch (info->crypto.cipher_group) {
  2355. case WLAN_CIPHER_SUITE_WEP40:
  2356. case WLAN_CIPHER_SUITE_WEP104:
  2357. p.grp_crypto_type = WEP_CRYPT;
  2358. break;
  2359. case WLAN_CIPHER_SUITE_TKIP:
  2360. p.grp_crypto_type = TKIP_CRYPT;
  2361. break;
  2362. case WLAN_CIPHER_SUITE_CCMP:
  2363. p.grp_crypto_type = AES_CRYPT;
  2364. break;
  2365. case WLAN_CIPHER_SUITE_SMS4:
  2366. p.grp_crypto_type = WAPI_CRYPT;
  2367. break;
  2368. default:
  2369. p.grp_crypto_type = NONE_CRYPT;
  2370. break;
  2371. }
  2372. ath6kl_set_cipher(vif, info->crypto.cipher_group, false);
  2373. p.nw_type = AP_NETWORK;
  2374. vif->nw_type = vif->next_mode;
  2375. p.ssid_len = vif->ssid_len;
  2376. memcpy(p.ssid, vif->ssid, vif->ssid_len);
  2377. p.dot11_auth_mode = vif->dot11_auth_mode;
  2378. p.ch = cpu_to_le16(info->chandef.chan->center_freq);
  2379. /* Enable uAPSD support by default */
  2380. res = ath6kl_wmi_ap_set_apsd(ar->wmi, vif->fw_vif_idx, true);
  2381. if (res < 0)
  2382. return res;
  2383. if (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
  2384. p.nw_subtype = SUBTYPE_P2PGO;
  2385. } else {
  2386. /*
  2387. * Due to firmware limitation, it is not possible to
  2388. * do P2P mgmt operations in AP mode
  2389. */
  2390. p.nw_subtype = SUBTYPE_NONE;
  2391. }
  2392. if (info->inactivity_timeout) {
  2393. inactivity_timeout = info->inactivity_timeout;
  2394. if (ar->hw.flags & ATH6KL_HW_AP_INACTIVITY_MINS)
  2395. inactivity_timeout = DIV_ROUND_UP(inactivity_timeout,
  2396. 60);
  2397. res = ath6kl_wmi_set_inact_period(ar->wmi, vif->fw_vif_idx,
  2398. inactivity_timeout);
  2399. if (res < 0)
  2400. return res;
  2401. }
  2402. if (ath6kl_set_htcap(vif, info->chandef.chan->band,
  2403. cfg80211_get_chandef_type(&info->chandef)
  2404. != NL80211_CHAN_NO_HT))
  2405. return -EIO;
  2406. /*
  2407. * Get the PTKSA replay counter in the RSN IE. Supplicant
  2408. * will use the RSN IE in M3 message and firmware has to
  2409. * advertise the same in beacon/probe response. Send
  2410. * the complete RSN IE capability field to firmware
  2411. */
  2412. if (!ath6kl_get_rsn_capab(&info->beacon, (u8 *) &rsn_capab) &&
  2413. test_bit(ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
  2414. ar->fw_capabilities)) {
  2415. res = ath6kl_wmi_set_ie_cmd(ar->wmi, vif->fw_vif_idx,
  2416. WLAN_EID_RSN, WMI_RSN_IE_CAPB,
  2417. (const u8 *) &rsn_capab,
  2418. sizeof(rsn_capab));
  2419. vif->rsn_capab = rsn_capab;
  2420. if (res < 0)
  2421. return res;
  2422. }
  2423. memcpy(&vif->profile, &p, sizeof(p));
  2424. res = ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx, &p);
  2425. if (res < 0)
  2426. return res;
  2427. return 0;
  2428. }
  2429. static int ath6kl_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  2430. struct cfg80211_beacon_data *beacon)
  2431. {
  2432. struct ath6kl_vif *vif = netdev_priv(dev);
  2433. if (!ath6kl_cfg80211_ready(vif))
  2434. return -EIO;
  2435. if (vif->next_mode != AP_NETWORK)
  2436. return -EOPNOTSUPP;
  2437. return ath6kl_set_ies(vif, beacon);
  2438. }
  2439. static int ath6kl_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  2440. {
  2441. struct ath6kl *ar = ath6kl_priv(dev);
  2442. struct ath6kl_vif *vif = netdev_priv(dev);
  2443. if (vif->nw_type != AP_NETWORK)
  2444. return -EOPNOTSUPP;
  2445. if (!test_bit(CONNECTED, &vif->flags))
  2446. return -ENOTCONN;
  2447. ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
  2448. clear_bit(CONNECTED, &vif->flags);
  2449. /* Restore ht setting in firmware */
  2450. return ath6kl_restore_htcap(vif);
  2451. }
  2452. static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  2453. static int ath6kl_del_station(struct wiphy *wiphy, struct net_device *dev,
  2454. u8 *mac)
  2455. {
  2456. struct ath6kl *ar = ath6kl_priv(dev);
  2457. struct ath6kl_vif *vif = netdev_priv(dev);
  2458. const u8 *addr = mac ? mac : bcast_addr;
  2459. return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, WMI_AP_DEAUTH,
  2460. addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
  2461. }
  2462. static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
  2463. u8 *mac, struct station_parameters *params)
  2464. {
  2465. struct ath6kl *ar = ath6kl_priv(dev);
  2466. struct ath6kl_vif *vif = netdev_priv(dev);
  2467. int err;
  2468. if (vif->nw_type != AP_NETWORK)
  2469. return -EOPNOTSUPP;
  2470. err = cfg80211_check_station_change(wiphy, params,
  2471. CFG80211_STA_AP_MLME_CLIENT);
  2472. if (err)
  2473. return err;
  2474. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  2475. return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
  2476. WMI_AP_MLME_AUTHORIZE, mac, 0);
  2477. return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
  2478. WMI_AP_MLME_UNAUTHORIZE, mac, 0);
  2479. }
  2480. static int ath6kl_remain_on_channel(struct wiphy *wiphy,
  2481. struct wireless_dev *wdev,
  2482. struct ieee80211_channel *chan,
  2483. unsigned int duration,
  2484. u64 *cookie)
  2485. {
  2486. struct ath6kl_vif *vif = ath6kl_vif_from_wdev(wdev);
  2487. struct ath6kl *ar = ath6kl_priv(vif->ndev);
  2488. u32 id;
  2489. /* TODO: if already pending or ongoing remain-on-channel,
  2490. * return -EBUSY */
  2491. id = ++vif->last_roc_id;
  2492. if (id == 0) {
  2493. /* Do not use 0 as the cookie value */
  2494. id = ++vif->last_roc_id;
  2495. }
  2496. *cookie = id;
  2497. return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx,
  2498. chan->center_freq, duration);
  2499. }
  2500. static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
  2501. struct wireless_dev *wdev,
  2502. u64 cookie)
  2503. {
  2504. struct ath6kl_vif *vif = ath6kl_vif_from_wdev(wdev);
  2505. struct ath6kl *ar = ath6kl_priv(vif->ndev);
  2506. if (cookie != vif->last_roc_id)
  2507. return -ENOENT;
  2508. vif->last_cancel_roc_id = cookie;
  2509. return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx);
  2510. }
  2511. static int ath6kl_send_go_probe_resp(struct ath6kl_vif *vif,
  2512. const u8 *buf, size_t len,
  2513. unsigned int freq)
  2514. {
  2515. struct ath6kl *ar = vif->ar;
  2516. const u8 *pos;
  2517. u8 *p2p;
  2518. int p2p_len;
  2519. int ret;
  2520. const struct ieee80211_mgmt *mgmt;
  2521. mgmt = (const struct ieee80211_mgmt *) buf;
  2522. /* Include P2P IE(s) from the frame generated in user space. */
  2523. p2p = kmalloc(len, GFP_KERNEL);
  2524. if (p2p == NULL)
  2525. return -ENOMEM;
  2526. p2p_len = 0;
  2527. pos = mgmt->u.probe_resp.variable;
  2528. while (pos + 1 < buf + len) {
  2529. if (pos + 2 + pos[1] > buf + len)
  2530. break;
  2531. if (ath6kl_is_p2p_ie(pos)) {
  2532. memcpy(p2p + p2p_len, pos, 2 + pos[1]);
  2533. p2p_len += 2 + pos[1];
  2534. }
  2535. pos += 2 + pos[1];
  2536. }
  2537. ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, vif->fw_vif_idx, freq,
  2538. mgmt->da, p2p, p2p_len);
  2539. kfree(p2p);
  2540. return ret;
  2541. }
  2542. static bool ath6kl_mgmt_powersave_ap(struct ath6kl_vif *vif,
  2543. u32 id,
  2544. u32 freq,
  2545. u32 wait,
  2546. const u8 *buf,
  2547. size_t len,
  2548. bool *more_data,
  2549. bool no_cck)
  2550. {
  2551. struct ieee80211_mgmt *mgmt;
  2552. struct ath6kl_sta *conn;
  2553. bool is_psq_empty = false;
  2554. struct ath6kl_mgmt_buff *mgmt_buf;
  2555. size_t mgmt_buf_size;
  2556. struct ath6kl *ar = vif->ar;
  2557. mgmt = (struct ieee80211_mgmt *) buf;
  2558. if (is_multicast_ether_addr(mgmt->da))
  2559. return false;
  2560. conn = ath6kl_find_sta(vif, mgmt->da);
  2561. if (!conn)
  2562. return false;
  2563. if (conn->sta_flags & STA_PS_SLEEP) {
  2564. if (!(conn->sta_flags & STA_PS_POLLED)) {
  2565. /* Queue the frames if the STA is sleeping */
  2566. mgmt_buf_size = len + sizeof(struct ath6kl_mgmt_buff);
  2567. mgmt_buf = kmalloc(mgmt_buf_size, GFP_KERNEL);
  2568. if (!mgmt_buf)
  2569. return false;
  2570. INIT_LIST_HEAD(&mgmt_buf->list);
  2571. mgmt_buf->id = id;
  2572. mgmt_buf->freq = freq;
  2573. mgmt_buf->wait = wait;
  2574. mgmt_buf->len = len;
  2575. mgmt_buf->no_cck = no_cck;
  2576. memcpy(mgmt_buf->buf, buf, len);
  2577. spin_lock_bh(&conn->psq_lock);
  2578. is_psq_empty = skb_queue_empty(&conn->psq) &&
  2579. (conn->mgmt_psq_len == 0);
  2580. list_add_tail(&mgmt_buf->list, &conn->mgmt_psq);
  2581. conn->mgmt_psq_len++;
  2582. spin_unlock_bh(&conn->psq_lock);
  2583. /*
  2584. * If this is the first pkt getting queued
  2585. * for this STA, update the PVB for this
  2586. * STA.
  2587. */
  2588. if (is_psq_empty)
  2589. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
  2590. conn->aid, 1);
  2591. return true;
  2592. }
  2593. /*
  2594. * This tx is because of a PsPoll.
  2595. * Determine if MoreData bit has to be set.
  2596. */
  2597. spin_lock_bh(&conn->psq_lock);
  2598. if (!skb_queue_empty(&conn->psq) || (conn->mgmt_psq_len != 0))
  2599. *more_data = true;
  2600. spin_unlock_bh(&conn->psq_lock);
  2601. }
  2602. return false;
  2603. }
  2604. /* Check if SSID length is greater than DIRECT- */
  2605. static bool ath6kl_is_p2p_go_ssid(const u8 *buf, size_t len)
  2606. {
  2607. const struct ieee80211_mgmt *mgmt;
  2608. mgmt = (const struct ieee80211_mgmt *) buf;
  2609. /* variable[1] contains the SSID tag length */
  2610. if (buf + len >= &mgmt->u.probe_resp.variable[1] &&
  2611. (mgmt->u.probe_resp.variable[1] > P2P_WILDCARD_SSID_LEN)) {
  2612. return true;
  2613. }
  2614. return false;
  2615. }
  2616. static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  2617. struct ieee80211_channel *chan, bool offchan,
  2618. unsigned int wait, const u8 *buf, size_t len,
  2619. bool no_cck, bool dont_wait_for_ack, u64 *cookie)
  2620. {
  2621. struct ath6kl_vif *vif = ath6kl_vif_from_wdev(wdev);
  2622. struct ath6kl *ar = ath6kl_priv(vif->ndev);
  2623. u32 id;
  2624. const struct ieee80211_mgmt *mgmt;
  2625. bool more_data, queued;
  2626. mgmt = (const struct ieee80211_mgmt *) buf;
  2627. if (vif->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) &&
  2628. ieee80211_is_probe_resp(mgmt->frame_control) &&
  2629. ath6kl_is_p2p_go_ssid(buf, len)) {
  2630. /*
  2631. * Send Probe Response frame in GO mode using a separate WMI
  2632. * command to allow the target to fill in the generic IEs.
  2633. */
  2634. *cookie = 0; /* TX status not supported */
  2635. return ath6kl_send_go_probe_resp(vif, buf, len,
  2636. chan->center_freq);
  2637. }
  2638. id = vif->send_action_id++;
  2639. if (id == 0) {
  2640. /*
  2641. * 0 is a reserved value in the WMI command and shall not be
  2642. * used for the command.
  2643. */
  2644. id = vif->send_action_id++;
  2645. }
  2646. *cookie = id;
  2647. /* AP mode Power saving processing */
  2648. if (vif->nw_type == AP_NETWORK) {
  2649. queued = ath6kl_mgmt_powersave_ap(vif,
  2650. id, chan->center_freq,
  2651. wait, buf,
  2652. len, &more_data, no_cck);
  2653. if (queued)
  2654. return 0;
  2655. }
  2656. return ath6kl_wmi_send_mgmt_cmd(ar->wmi, vif->fw_vif_idx, id,
  2657. chan->center_freq, wait,
  2658. buf, len, no_cck);
  2659. }
  2660. static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
  2661. struct wireless_dev *wdev,
  2662. u16 frame_type, bool reg)
  2663. {
  2664. struct ath6kl_vif *vif = ath6kl_vif_from_wdev(wdev);
  2665. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
  2666. __func__, frame_type, reg);
  2667. if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
  2668. /*
  2669. * Note: This notification callback is not allowed to sleep, so
  2670. * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
  2671. * hardcode target to report Probe Request frames all the time.
  2672. */
  2673. vif->probe_req_report = reg;
  2674. }
  2675. }
  2676. static int ath6kl_cfg80211_sscan_start(struct wiphy *wiphy,
  2677. struct net_device *dev,
  2678. struct cfg80211_sched_scan_request *request)
  2679. {
  2680. struct ath6kl *ar = ath6kl_priv(dev);
  2681. struct ath6kl_vif *vif = netdev_priv(dev);
  2682. u16 interval;
  2683. int ret, rssi_thold;
  2684. if (ar->state != ATH6KL_STATE_ON)
  2685. return -EIO;
  2686. if (vif->sme_state != SME_DISCONNECTED)
  2687. return -EBUSY;
  2688. ath6kl_cfg80211_scan_complete_event(vif, true);
  2689. ret = ath6kl_set_probed_ssids(ar, vif, request->ssids,
  2690. request->n_ssids,
  2691. request->match_sets,
  2692. request->n_match_sets);
  2693. if (ret < 0)
  2694. return ret;
  2695. if (!request->n_match_sets) {
  2696. ret = ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  2697. ALL_BSS_FILTER, 0);
  2698. if (ret < 0)
  2699. return ret;
  2700. } else {
  2701. ret = ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  2702. MATCHED_SSID_FILTER, 0);
  2703. if (ret < 0)
  2704. return ret;
  2705. }
  2706. if (test_bit(ATH6KL_FW_CAPABILITY_RSSI_SCAN_THOLD,
  2707. ar->fw_capabilities)) {
  2708. if (request->rssi_thold <= NL80211_SCAN_RSSI_THOLD_OFF)
  2709. rssi_thold = 0;
  2710. else if (request->rssi_thold < -127)
  2711. rssi_thold = -127;
  2712. else
  2713. rssi_thold = request->rssi_thold;
  2714. ret = ath6kl_wmi_set_rssi_filter_cmd(ar->wmi, vif->fw_vif_idx,
  2715. rssi_thold);
  2716. if (ret) {
  2717. ath6kl_err("failed to set RSSI threshold for scan\n");
  2718. return ret;
  2719. }
  2720. }
  2721. /* fw uses seconds, also make sure that it's >0 */
  2722. interval = max_t(u16, 1, request->interval / 1000);
  2723. ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
  2724. interval, interval,
  2725. vif->bg_scan_period, 0, 0, 0, 3, 0, 0, 0);
  2726. /* this also clears IE in fw if it's not set */
  2727. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  2728. WMI_FRAME_PROBE_REQ,
  2729. request->ie, request->ie_len);
  2730. if (ret) {
  2731. ath6kl_warn("Failed to set probe request IE for scheduled scan: %d\n",
  2732. ret);
  2733. return ret;
  2734. }
  2735. ret = ath6kl_wmi_enable_sched_scan_cmd(ar->wmi, vif->fw_vif_idx, true);
  2736. if (ret)
  2737. return ret;
  2738. set_bit(SCHED_SCANNING, &vif->flags);
  2739. return 0;
  2740. }
  2741. static int ath6kl_cfg80211_sscan_stop(struct wiphy *wiphy,
  2742. struct net_device *dev)
  2743. {
  2744. struct ath6kl_vif *vif = netdev_priv(dev);
  2745. bool stopped;
  2746. stopped = __ath6kl_cfg80211_sscan_stop(vif);
  2747. if (!stopped)
  2748. return -EIO;
  2749. return 0;
  2750. }
  2751. static int ath6kl_cfg80211_set_bitrate(struct wiphy *wiphy,
  2752. struct net_device *dev,
  2753. const u8 *addr,
  2754. const struct cfg80211_bitrate_mask *mask)
  2755. {
  2756. struct ath6kl *ar = ath6kl_priv(dev);
  2757. struct ath6kl_vif *vif = netdev_priv(dev);
  2758. return ath6kl_wmi_set_bitrate_mask(ar->wmi, vif->fw_vif_idx,
  2759. mask);
  2760. }
  2761. static int ath6kl_cfg80211_set_txe_config(struct wiphy *wiphy,
  2762. struct net_device *dev,
  2763. u32 rate, u32 pkts, u32 intvl)
  2764. {
  2765. struct ath6kl *ar = ath6kl_priv(dev);
  2766. struct ath6kl_vif *vif = netdev_priv(dev);
  2767. if (vif->nw_type != INFRA_NETWORK ||
  2768. !test_bit(ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY, ar->fw_capabilities))
  2769. return -EOPNOTSUPP;
  2770. if (vif->sme_state != SME_CONNECTED)
  2771. return -ENOTCONN;
  2772. /* save this since the firmware won't report the interval */
  2773. vif->txe_intvl = intvl;
  2774. return ath6kl_wmi_set_txe_notify(ar->wmi, vif->fw_vif_idx,
  2775. rate, pkts, intvl);
  2776. }
  2777. static const struct ieee80211_txrx_stypes
  2778. ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  2779. [NL80211_IFTYPE_STATION] = {
  2780. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2781. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  2782. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2783. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  2784. },
  2785. [NL80211_IFTYPE_AP] = {
  2786. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2787. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  2788. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2789. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  2790. },
  2791. [NL80211_IFTYPE_P2P_CLIENT] = {
  2792. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2793. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  2794. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2795. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  2796. },
  2797. [NL80211_IFTYPE_P2P_GO] = {
  2798. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2799. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  2800. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2801. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  2802. },
  2803. };
  2804. static struct cfg80211_ops ath6kl_cfg80211_ops = {
  2805. .add_virtual_intf = ath6kl_cfg80211_add_iface,
  2806. .del_virtual_intf = ath6kl_cfg80211_del_iface,
  2807. .change_virtual_intf = ath6kl_cfg80211_change_iface,
  2808. .scan = ath6kl_cfg80211_scan,
  2809. .connect = ath6kl_cfg80211_connect,
  2810. .disconnect = ath6kl_cfg80211_disconnect,
  2811. .add_key = ath6kl_cfg80211_add_key,
  2812. .get_key = ath6kl_cfg80211_get_key,
  2813. .del_key = ath6kl_cfg80211_del_key,
  2814. .set_default_key = ath6kl_cfg80211_set_default_key,
  2815. .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
  2816. .set_tx_power = ath6kl_cfg80211_set_txpower,
  2817. .get_tx_power = ath6kl_cfg80211_get_txpower,
  2818. .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
  2819. .join_ibss = ath6kl_cfg80211_join_ibss,
  2820. .leave_ibss = ath6kl_cfg80211_leave_ibss,
  2821. .get_station = ath6kl_get_station,
  2822. .set_pmksa = ath6kl_set_pmksa,
  2823. .del_pmksa = ath6kl_del_pmksa,
  2824. .flush_pmksa = ath6kl_flush_pmksa,
  2825. CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
  2826. #ifdef CONFIG_PM
  2827. .suspend = __ath6kl_cfg80211_suspend,
  2828. .resume = __ath6kl_cfg80211_resume,
  2829. #endif
  2830. .start_ap = ath6kl_start_ap,
  2831. .change_beacon = ath6kl_change_beacon,
  2832. .stop_ap = ath6kl_stop_ap,
  2833. .del_station = ath6kl_del_station,
  2834. .change_station = ath6kl_change_station,
  2835. .remain_on_channel = ath6kl_remain_on_channel,
  2836. .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
  2837. .mgmt_tx = ath6kl_mgmt_tx,
  2838. .mgmt_frame_register = ath6kl_mgmt_frame_register,
  2839. .sched_scan_start = ath6kl_cfg80211_sscan_start,
  2840. .sched_scan_stop = ath6kl_cfg80211_sscan_stop,
  2841. .set_bitrate_mask = ath6kl_cfg80211_set_bitrate,
  2842. .set_cqm_txe_config = ath6kl_cfg80211_set_txe_config,
  2843. };
  2844. void ath6kl_cfg80211_stop(struct ath6kl_vif *vif)
  2845. {
  2846. ath6kl_cfg80211_sscan_disable(vif);
  2847. switch (vif->sme_state) {
  2848. case SME_DISCONNECTED:
  2849. break;
  2850. case SME_CONNECTING:
  2851. cfg80211_connect_result(vif->ndev, vif->bssid, NULL, 0,
  2852. NULL, 0,
  2853. WLAN_STATUS_UNSPECIFIED_FAILURE,
  2854. GFP_KERNEL);
  2855. break;
  2856. case SME_CONNECTED:
  2857. cfg80211_disconnected(vif->ndev, 0, NULL, 0, GFP_KERNEL);
  2858. break;
  2859. }
  2860. if (vif->ar->state != ATH6KL_STATE_RECOVERY &&
  2861. (test_bit(CONNECTED, &vif->flags) ||
  2862. test_bit(CONNECT_PEND, &vif->flags)))
  2863. ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
  2864. vif->sme_state = SME_DISCONNECTED;
  2865. clear_bit(CONNECTED, &vif->flags);
  2866. clear_bit(CONNECT_PEND, &vif->flags);
  2867. /* Stop netdev queues, needed during recovery */
  2868. netif_stop_queue(vif->ndev);
  2869. netif_carrier_off(vif->ndev);
  2870. /* disable scanning */
  2871. if (vif->ar->state != ATH6KL_STATE_RECOVERY &&
  2872. ath6kl_wmi_scanparams_cmd(vif->ar->wmi, vif->fw_vif_idx, 0xFFFF,
  2873. 0, 0, 0, 0, 0, 0, 0, 0, 0) != 0)
  2874. ath6kl_warn("failed to disable scan during stop\n");
  2875. ath6kl_cfg80211_scan_complete_event(vif, true);
  2876. }
  2877. void ath6kl_cfg80211_stop_all(struct ath6kl *ar)
  2878. {
  2879. struct ath6kl_vif *vif;
  2880. vif = ath6kl_vif_first(ar);
  2881. if (!vif && ar->state != ATH6KL_STATE_RECOVERY) {
  2882. /* save the current power mode before enabling power save */
  2883. ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
  2884. if (ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER) != 0)
  2885. ath6kl_warn("ath6kl_deep_sleep_enable: wmi_powermode_cmd failed\n");
  2886. return;
  2887. }
  2888. /*
  2889. * FIXME: we should take ar->list_lock to protect changes in the
  2890. * vif_list, but that's not trivial to do as ath6kl_cfg80211_stop()
  2891. * sleeps.
  2892. */
  2893. list_for_each_entry(vif, &ar->vif_list, list)
  2894. ath6kl_cfg80211_stop(vif);
  2895. }
  2896. static void ath6kl_cfg80211_reg_notify(struct wiphy *wiphy,
  2897. struct regulatory_request *request)
  2898. {
  2899. struct ath6kl *ar = wiphy_priv(wiphy);
  2900. u32 rates[IEEE80211_NUM_BANDS];
  2901. int ret, i;
  2902. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  2903. "cfg reg_notify %c%c%s%s initiator %d hint_type %d\n",
  2904. request->alpha2[0], request->alpha2[1],
  2905. request->intersect ? " intersect" : "",
  2906. request->processed ? " processed" : "",
  2907. request->initiator, request->user_reg_hint_type);
  2908. if (request->user_reg_hint_type != NL80211_USER_REG_HINT_CELL_BASE)
  2909. return;
  2910. ret = ath6kl_wmi_set_regdomain_cmd(ar->wmi, request->alpha2);
  2911. if (ret) {
  2912. ath6kl_err("failed to set regdomain: %d\n", ret);
  2913. return;
  2914. }
  2915. /*
  2916. * Firmware will apply the regdomain change only after a scan is
  2917. * issued and it will send a WMI_REGDOMAIN_EVENTID when it has been
  2918. * changed.
  2919. */
  2920. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  2921. if (wiphy->bands[i])
  2922. rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1;
  2923. ret = ath6kl_wmi_beginscan_cmd(ar->wmi, 0, WMI_LONG_SCAN, false,
  2924. false, 0, ATH6KL_FG_SCAN_INTERVAL,
  2925. 0, NULL, false, rates);
  2926. if (ret) {
  2927. ath6kl_err("failed to start scan for a regdomain change: %d\n",
  2928. ret);
  2929. return;
  2930. }
  2931. }
  2932. static int ath6kl_cfg80211_vif_init(struct ath6kl_vif *vif)
  2933. {
  2934. vif->aggr_cntxt = aggr_init(vif);
  2935. if (!vif->aggr_cntxt) {
  2936. ath6kl_err("failed to initialize aggr\n");
  2937. return -ENOMEM;
  2938. }
  2939. setup_timer(&vif->disconnect_timer, disconnect_timer_handler,
  2940. (unsigned long) vif->ndev);
  2941. setup_timer(&vif->sched_scan_timer, ath6kl_wmi_sscan_timer,
  2942. (unsigned long) vif);
  2943. set_bit(WMM_ENABLED, &vif->flags);
  2944. spin_lock_init(&vif->if_lock);
  2945. INIT_LIST_HEAD(&vif->mc_filter);
  2946. return 0;
  2947. }
  2948. void ath6kl_cfg80211_vif_stop(struct ath6kl_vif *vif, bool wmi_ready)
  2949. {
  2950. static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  2951. bool discon_issued;
  2952. netif_stop_queue(vif->ndev);
  2953. clear_bit(WLAN_ENABLED, &vif->flags);
  2954. if (wmi_ready) {
  2955. discon_issued = test_bit(CONNECTED, &vif->flags) ||
  2956. test_bit(CONNECT_PEND, &vif->flags);
  2957. ath6kl_disconnect(vif);
  2958. del_timer(&vif->disconnect_timer);
  2959. if (discon_issued)
  2960. ath6kl_disconnect_event(vif, DISCONNECT_CMD,
  2961. (vif->nw_type & AP_NETWORK) ?
  2962. bcast_mac : vif->bssid,
  2963. 0, NULL, 0);
  2964. }
  2965. if (vif->scan_req) {
  2966. cfg80211_scan_done(vif->scan_req, true);
  2967. vif->scan_req = NULL;
  2968. }
  2969. /* need to clean up enhanced bmiss detection fw state */
  2970. ath6kl_cfg80211_sta_bmiss_enhance(vif, false);
  2971. }
  2972. void ath6kl_cfg80211_vif_cleanup(struct ath6kl_vif *vif)
  2973. {
  2974. struct ath6kl *ar = vif->ar;
  2975. struct ath6kl_mc_filter *mc_filter, *tmp;
  2976. aggr_module_destroy(vif->aggr_cntxt);
  2977. ar->avail_idx_map |= BIT(vif->fw_vif_idx);
  2978. if (vif->nw_type == ADHOC_NETWORK)
  2979. ar->ibss_if_active = false;
  2980. list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) {
  2981. list_del(&mc_filter->list);
  2982. kfree(mc_filter);
  2983. }
  2984. unregister_netdevice(vif->ndev);
  2985. ar->num_vif--;
  2986. }
  2987. struct wireless_dev *ath6kl_interface_add(struct ath6kl *ar, const char *name,
  2988. enum nl80211_iftype type,
  2989. u8 fw_vif_idx, u8 nw_type)
  2990. {
  2991. struct net_device *ndev;
  2992. struct ath6kl_vif *vif;
  2993. ndev = alloc_netdev(sizeof(*vif), name, ether_setup);
  2994. if (!ndev)
  2995. return NULL;
  2996. vif = netdev_priv(ndev);
  2997. ndev->ieee80211_ptr = &vif->wdev;
  2998. vif->wdev.wiphy = ar->wiphy;
  2999. vif->ar = ar;
  3000. vif->ndev = ndev;
  3001. SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy));
  3002. vif->wdev.netdev = ndev;
  3003. vif->wdev.iftype = type;
  3004. vif->fw_vif_idx = fw_vif_idx;
  3005. vif->nw_type = nw_type;
  3006. vif->next_mode = nw_type;
  3007. vif->listen_intvl_t = ATH6KL_DEFAULT_LISTEN_INTVAL;
  3008. vif->bmiss_time_t = ATH6KL_DEFAULT_BMISS_TIME;
  3009. vif->bg_scan_period = 0;
  3010. vif->htcap[IEEE80211_BAND_2GHZ].ht_enable = true;
  3011. vif->htcap[IEEE80211_BAND_5GHZ].ht_enable = true;
  3012. memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
  3013. if (fw_vif_idx != 0) {
  3014. ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << fw_vif_idx)) |
  3015. 0x2;
  3016. if (test_bit(ATH6KL_FW_CAPABILITY_CUSTOM_MAC_ADDR,
  3017. ar->fw_capabilities))
  3018. ndev->dev_addr[4] ^= 0x80;
  3019. }
  3020. init_netdev(ndev);
  3021. ath6kl_init_control_info(vif);
  3022. if (ath6kl_cfg80211_vif_init(vif))
  3023. goto err;
  3024. if (register_netdevice(ndev))
  3025. goto err;
  3026. ar->avail_idx_map &= ~BIT(fw_vif_idx);
  3027. vif->sme_state = SME_DISCONNECTED;
  3028. set_bit(WLAN_ENABLED, &vif->flags);
  3029. ar->wlan_pwr_state = WLAN_POWER_STATE_ON;
  3030. if (type == NL80211_IFTYPE_ADHOC)
  3031. ar->ibss_if_active = true;
  3032. spin_lock_bh(&ar->list_lock);
  3033. list_add_tail(&vif->list, &ar->vif_list);
  3034. spin_unlock_bh(&ar->list_lock);
  3035. return &vif->wdev;
  3036. err:
  3037. aggr_module_destroy(vif->aggr_cntxt);
  3038. free_netdev(ndev);
  3039. return NULL;
  3040. }
  3041. int ath6kl_cfg80211_init(struct ath6kl *ar)
  3042. {
  3043. struct wiphy *wiphy = ar->wiphy;
  3044. bool band_2gig = false, band_5gig = false, ht = false;
  3045. int ret;
  3046. wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
  3047. wiphy->max_remain_on_channel_duration = 5000;
  3048. /* set device pointer for wiphy */
  3049. set_wiphy_dev(wiphy, ar->dev);
  3050. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  3051. BIT(NL80211_IFTYPE_ADHOC) |
  3052. BIT(NL80211_IFTYPE_AP);
  3053. if (ar->p2p) {
  3054. wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) |
  3055. BIT(NL80211_IFTYPE_P2P_CLIENT);
  3056. }
  3057. if (config_enabled(CONFIG_ATH6KL_REGDOMAIN) &&
  3058. test_bit(ATH6KL_FW_CAPABILITY_REGDOMAIN, ar->fw_capabilities)) {
  3059. wiphy->reg_notifier = ath6kl_cfg80211_reg_notify;
  3060. ar->wiphy->features |= NL80211_FEATURE_CELL_BASE_REG_HINTS;
  3061. }
  3062. /* max num of ssids that can be probed during scanning */
  3063. wiphy->max_scan_ssids = MAX_PROBED_SSIDS;
  3064. /* max num of ssids that can be matched after scan */
  3065. if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN_MATCH_LIST,
  3066. ar->fw_capabilities))
  3067. wiphy->max_match_sets = MAX_PROBED_SSIDS;
  3068. wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
  3069. switch (ar->hw.cap) {
  3070. case WMI_11AN_CAP:
  3071. ht = true;
  3072. case WMI_11A_CAP:
  3073. band_5gig = true;
  3074. break;
  3075. case WMI_11GN_CAP:
  3076. ht = true;
  3077. case WMI_11G_CAP:
  3078. band_2gig = true;
  3079. break;
  3080. case WMI_11AGN_CAP:
  3081. ht = true;
  3082. case WMI_11AG_CAP:
  3083. band_2gig = true;
  3084. band_5gig = true;
  3085. break;
  3086. default:
  3087. ath6kl_err("invalid phy capability!\n");
  3088. return -EINVAL;
  3089. }
  3090. /*
  3091. * Even if the fw has HT support, advertise HT cap only when
  3092. * the firmware has support to override RSN capability, otherwise
  3093. * 4-way handshake would fail.
  3094. */
  3095. if (!(ht &&
  3096. test_bit(ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
  3097. ar->fw_capabilities))) {
  3098. ath6kl_band_2ghz.ht_cap.cap = 0;
  3099. ath6kl_band_2ghz.ht_cap.ht_supported = false;
  3100. ath6kl_band_5ghz.ht_cap.cap = 0;
  3101. ath6kl_band_5ghz.ht_cap.ht_supported = false;
  3102. }
  3103. if (ar->hw.flags & ATH6KL_HW_64BIT_RATES) {
  3104. ath6kl_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
  3105. ath6kl_band_5ghz.ht_cap.mcs.rx_mask[0] = 0xff;
  3106. ath6kl_band_2ghz.ht_cap.mcs.rx_mask[1] = 0xff;
  3107. ath6kl_band_5ghz.ht_cap.mcs.rx_mask[1] = 0xff;
  3108. } else {
  3109. ath6kl_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
  3110. ath6kl_band_5ghz.ht_cap.mcs.rx_mask[0] = 0xff;
  3111. }
  3112. if (band_2gig)
  3113. wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
  3114. if (band_5gig)
  3115. wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
  3116. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  3117. wiphy->cipher_suites = cipher_suites;
  3118. wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  3119. #ifdef CONFIG_PM
  3120. wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  3121. WIPHY_WOWLAN_DISCONNECT |
  3122. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  3123. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  3124. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  3125. WIPHY_WOWLAN_4WAY_HANDSHAKE;
  3126. wiphy->wowlan.n_patterns = WOW_MAX_FILTERS_PER_LIST;
  3127. wiphy->wowlan.pattern_min_len = 1;
  3128. wiphy->wowlan.pattern_max_len = WOW_PATTERN_SIZE;
  3129. #endif
  3130. wiphy->max_sched_scan_ssids = MAX_PROBED_SSIDS;
  3131. ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
  3132. WIPHY_FLAG_HAVE_AP_SME |
  3133. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  3134. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  3135. if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN_V2, ar->fw_capabilities))
  3136. ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
  3137. if (test_bit(ATH6KL_FW_CAPABILITY_INACTIVITY_TIMEOUT,
  3138. ar->fw_capabilities))
  3139. ar->wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
  3140. ar->wiphy->probe_resp_offload =
  3141. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  3142. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  3143. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  3144. ret = wiphy_register(wiphy);
  3145. if (ret < 0) {
  3146. ath6kl_err("couldn't register wiphy device\n");
  3147. return ret;
  3148. }
  3149. ar->wiphy_registered = true;
  3150. return 0;
  3151. }
  3152. void ath6kl_cfg80211_cleanup(struct ath6kl *ar)
  3153. {
  3154. wiphy_unregister(ar->wiphy);
  3155. ar->wiphy_registered = false;
  3156. }
  3157. struct ath6kl *ath6kl_cfg80211_create(void)
  3158. {
  3159. struct ath6kl *ar;
  3160. struct wiphy *wiphy;
  3161. /* create a new wiphy for use with cfg80211 */
  3162. wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
  3163. if (!wiphy) {
  3164. ath6kl_err("couldn't allocate wiphy device\n");
  3165. return NULL;
  3166. }
  3167. ar = wiphy_priv(wiphy);
  3168. ar->wiphy = wiphy;
  3169. return ar;
  3170. }
  3171. /* Note: ar variable must not be accessed after calling this! */
  3172. void ath6kl_cfg80211_destroy(struct ath6kl *ar)
  3173. {
  3174. int i;
  3175. for (i = 0; i < AP_MAX_NUM_STA; i++)
  3176. kfree(ar->sta_list[i].aggr_conn);
  3177. wiphy_free(ar->wiphy);
  3178. }