cfg80211.c 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849
  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 >> i) & BIT(0)) {
  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 >> i) & BIT(0)) {
  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. ath6kl_cfg80211_vif_cleanup(vif);
  1274. return 0;
  1275. }
  1276. static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
  1277. struct net_device *ndev,
  1278. enum nl80211_iftype type, u32 *flags,
  1279. struct vif_params *params)
  1280. {
  1281. struct ath6kl_vif *vif = netdev_priv(ndev);
  1282. int i;
  1283. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
  1284. /*
  1285. * Don't bring up p2p on an interface which is not initialized
  1286. * for p2p operation where fw does not have capability to switch
  1287. * dynamically between non-p2p and p2p type interface.
  1288. */
  1289. if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  1290. vif->ar->fw_capabilities) &&
  1291. (type == NL80211_IFTYPE_P2P_CLIENT ||
  1292. type == NL80211_IFTYPE_P2P_GO)) {
  1293. if (vif->ar->vif_max == 1) {
  1294. if (vif->fw_vif_idx != 0)
  1295. return -EINVAL;
  1296. else
  1297. goto set_iface_type;
  1298. }
  1299. for (i = vif->ar->max_norm_iface; i < vif->ar->vif_max; i++) {
  1300. if (i == vif->fw_vif_idx)
  1301. break;
  1302. }
  1303. if (i == vif->ar->vif_max) {
  1304. ath6kl_err("Invalid interface to bring up P2P\n");
  1305. return -EINVAL;
  1306. }
  1307. }
  1308. /* need to clean up enhanced bmiss detection fw state */
  1309. ath6kl_cfg80211_sta_bmiss_enhance(vif, false);
  1310. set_iface_type:
  1311. switch (type) {
  1312. case NL80211_IFTYPE_STATION:
  1313. case NL80211_IFTYPE_P2P_CLIENT:
  1314. vif->next_mode = INFRA_NETWORK;
  1315. break;
  1316. case NL80211_IFTYPE_ADHOC:
  1317. vif->next_mode = ADHOC_NETWORK;
  1318. break;
  1319. case NL80211_IFTYPE_AP:
  1320. case NL80211_IFTYPE_P2P_GO:
  1321. vif->next_mode = AP_NETWORK;
  1322. break;
  1323. default:
  1324. ath6kl_err("invalid interface type %u\n", type);
  1325. return -EOPNOTSUPP;
  1326. }
  1327. vif->wdev.iftype = type;
  1328. return 0;
  1329. }
  1330. static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
  1331. struct net_device *dev,
  1332. struct cfg80211_ibss_params *ibss_param)
  1333. {
  1334. struct ath6kl *ar = ath6kl_priv(dev);
  1335. struct ath6kl_vif *vif = netdev_priv(dev);
  1336. int status;
  1337. if (!ath6kl_cfg80211_ready(vif))
  1338. return -EIO;
  1339. vif->ssid_len = ibss_param->ssid_len;
  1340. memcpy(vif->ssid, ibss_param->ssid, vif->ssid_len);
  1341. if (ibss_param->chandef.chan)
  1342. vif->ch_hint = ibss_param->chandef.chan->center_freq;
  1343. if (ibss_param->channel_fixed) {
  1344. /*
  1345. * TODO: channel_fixed: The channel should be fixed, do not
  1346. * search for IBSSs to join on other channels. Target
  1347. * firmware does not support this feature, needs to be
  1348. * updated.
  1349. */
  1350. return -EOPNOTSUPP;
  1351. }
  1352. memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
  1353. if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
  1354. memcpy(vif->req_bssid, ibss_param->bssid,
  1355. sizeof(vif->req_bssid));
  1356. ath6kl_set_wpa_version(vif, 0);
  1357. status = ath6kl_set_auth_type(vif, NL80211_AUTHTYPE_OPEN_SYSTEM);
  1358. if (status)
  1359. return status;
  1360. if (ibss_param->privacy) {
  1361. ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, true);
  1362. ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, false);
  1363. } else {
  1364. ath6kl_set_cipher(vif, 0, true);
  1365. ath6kl_set_cipher(vif, 0, false);
  1366. }
  1367. vif->nw_type = vif->next_mode;
  1368. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1369. "%s: connect called with authmode %d dot11 auth %d"
  1370. " PW crypto %d PW crypto len %d GRP crypto %d"
  1371. " GRP crypto len %d channel hint %u\n",
  1372. __func__,
  1373. vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
  1374. vif->prwise_crypto_len, vif->grp_crypto,
  1375. vif->grp_crypto_len, vif->ch_hint);
  1376. status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
  1377. vif->dot11_auth_mode, vif->auth_mode,
  1378. vif->prwise_crypto,
  1379. vif->prwise_crypto_len,
  1380. vif->grp_crypto, vif->grp_crypto_len,
  1381. vif->ssid_len, vif->ssid,
  1382. vif->req_bssid, vif->ch_hint,
  1383. ar->connect_ctrl_flags, SUBTYPE_NONE);
  1384. set_bit(CONNECT_PEND, &vif->flags);
  1385. return 0;
  1386. }
  1387. static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
  1388. struct net_device *dev)
  1389. {
  1390. struct ath6kl_vif *vif = netdev_priv(dev);
  1391. if (!ath6kl_cfg80211_ready(vif))
  1392. return -EIO;
  1393. ath6kl_disconnect(vif);
  1394. memset(vif->ssid, 0, sizeof(vif->ssid));
  1395. vif->ssid_len = 0;
  1396. return 0;
  1397. }
  1398. static const u32 cipher_suites[] = {
  1399. WLAN_CIPHER_SUITE_WEP40,
  1400. WLAN_CIPHER_SUITE_WEP104,
  1401. WLAN_CIPHER_SUITE_TKIP,
  1402. WLAN_CIPHER_SUITE_CCMP,
  1403. CCKM_KRK_CIPHER_SUITE,
  1404. WLAN_CIPHER_SUITE_SMS4,
  1405. };
  1406. static bool is_rate_legacy(s32 rate)
  1407. {
  1408. static const s32 legacy[] = { 1000, 2000, 5500, 11000,
  1409. 6000, 9000, 12000, 18000, 24000,
  1410. 36000, 48000, 54000
  1411. };
  1412. u8 i;
  1413. for (i = 0; i < ARRAY_SIZE(legacy); i++)
  1414. if (rate == legacy[i])
  1415. return true;
  1416. return false;
  1417. }
  1418. static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
  1419. {
  1420. static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
  1421. 52000, 58500, 65000, 72200
  1422. };
  1423. u8 i;
  1424. for (i = 0; i < ARRAY_SIZE(ht20); i++) {
  1425. if (rate == ht20[i]) {
  1426. if (i == ARRAY_SIZE(ht20) - 1)
  1427. /* last rate uses sgi */
  1428. *sgi = true;
  1429. else
  1430. *sgi = false;
  1431. *mcs = i;
  1432. return true;
  1433. }
  1434. }
  1435. return false;
  1436. }
  1437. static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
  1438. {
  1439. static const s32 ht40[] = { 13500, 27000, 40500, 54000,
  1440. 81000, 108000, 121500, 135000,
  1441. 150000
  1442. };
  1443. u8 i;
  1444. for (i = 0; i < ARRAY_SIZE(ht40); i++) {
  1445. if (rate == ht40[i]) {
  1446. if (i == ARRAY_SIZE(ht40) - 1)
  1447. /* last rate uses sgi */
  1448. *sgi = true;
  1449. else
  1450. *sgi = false;
  1451. *mcs = i;
  1452. return true;
  1453. }
  1454. }
  1455. return false;
  1456. }
  1457. static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
  1458. u8 *mac, struct station_info *sinfo)
  1459. {
  1460. struct ath6kl *ar = ath6kl_priv(dev);
  1461. struct ath6kl_vif *vif = netdev_priv(dev);
  1462. long left;
  1463. bool sgi;
  1464. s32 rate;
  1465. int ret;
  1466. u8 mcs;
  1467. if (memcmp(mac, vif->bssid, ETH_ALEN) != 0)
  1468. return -ENOENT;
  1469. if (down_interruptible(&ar->sem))
  1470. return -EBUSY;
  1471. set_bit(STATS_UPDATE_PEND, &vif->flags);
  1472. ret = ath6kl_wmi_get_stats_cmd(ar->wmi, vif->fw_vif_idx);
  1473. if (ret != 0) {
  1474. up(&ar->sem);
  1475. return -EIO;
  1476. }
  1477. left = wait_event_interruptible_timeout(ar->event_wq,
  1478. !test_bit(STATS_UPDATE_PEND,
  1479. &vif->flags),
  1480. WMI_TIMEOUT);
  1481. up(&ar->sem);
  1482. if (left == 0)
  1483. return -ETIMEDOUT;
  1484. else if (left < 0)
  1485. return left;
  1486. if (vif->target_stats.rx_byte) {
  1487. sinfo->rx_bytes = vif->target_stats.rx_byte;
  1488. sinfo->filled |= STATION_INFO_RX_BYTES64;
  1489. sinfo->rx_packets = vif->target_stats.rx_pkt;
  1490. sinfo->filled |= STATION_INFO_RX_PACKETS;
  1491. }
  1492. if (vif->target_stats.tx_byte) {
  1493. sinfo->tx_bytes = vif->target_stats.tx_byte;
  1494. sinfo->filled |= STATION_INFO_TX_BYTES64;
  1495. sinfo->tx_packets = vif->target_stats.tx_pkt;
  1496. sinfo->filled |= STATION_INFO_TX_PACKETS;
  1497. }
  1498. sinfo->signal = vif->target_stats.cs_rssi;
  1499. sinfo->filled |= STATION_INFO_SIGNAL;
  1500. rate = vif->target_stats.tx_ucast_rate;
  1501. if (is_rate_legacy(rate)) {
  1502. sinfo->txrate.legacy = rate / 100;
  1503. } else if (is_rate_ht20(rate, &mcs, &sgi)) {
  1504. if (sgi) {
  1505. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1506. sinfo->txrate.mcs = mcs - 1;
  1507. } else {
  1508. sinfo->txrate.mcs = mcs;
  1509. }
  1510. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1511. } else if (is_rate_ht40(rate, &mcs, &sgi)) {
  1512. if (sgi) {
  1513. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1514. sinfo->txrate.mcs = mcs - 1;
  1515. } else {
  1516. sinfo->txrate.mcs = mcs;
  1517. }
  1518. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  1519. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1520. } else {
  1521. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1522. "invalid rate from stats: %d\n", rate);
  1523. ath6kl_debug_war(ar, ATH6KL_WAR_INVALID_RATE);
  1524. return 0;
  1525. }
  1526. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1527. if (test_bit(CONNECTED, &vif->flags) &&
  1528. test_bit(DTIM_PERIOD_AVAIL, &vif->flags) &&
  1529. vif->nw_type == INFRA_NETWORK) {
  1530. sinfo->filled |= STATION_INFO_BSS_PARAM;
  1531. sinfo->bss_param.flags = 0;
  1532. sinfo->bss_param.dtim_period = vif->assoc_bss_dtim_period;
  1533. sinfo->bss_param.beacon_interval = vif->assoc_bss_beacon_int;
  1534. }
  1535. return 0;
  1536. }
  1537. static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1538. struct cfg80211_pmksa *pmksa)
  1539. {
  1540. struct ath6kl *ar = ath6kl_priv(netdev);
  1541. struct ath6kl_vif *vif = netdev_priv(netdev);
  1542. return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
  1543. pmksa->pmkid, true);
  1544. }
  1545. static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1546. struct cfg80211_pmksa *pmksa)
  1547. {
  1548. struct ath6kl *ar = ath6kl_priv(netdev);
  1549. struct ath6kl_vif *vif = netdev_priv(netdev);
  1550. return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
  1551. pmksa->pmkid, false);
  1552. }
  1553. static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
  1554. {
  1555. struct ath6kl *ar = ath6kl_priv(netdev);
  1556. struct ath6kl_vif *vif = netdev_priv(netdev);
  1557. if (test_bit(CONNECTED, &vif->flags))
  1558. return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx,
  1559. vif->bssid, NULL, false);
  1560. return 0;
  1561. }
  1562. static int ath6kl_wow_usr(struct ath6kl *ar, struct ath6kl_vif *vif,
  1563. struct cfg80211_wowlan *wow, u32 *filter)
  1564. {
  1565. int ret, pos;
  1566. u8 mask[WOW_PATTERN_SIZE];
  1567. u16 i;
  1568. /* Configure the patterns that we received from the user. */
  1569. for (i = 0; i < wow->n_patterns; i++) {
  1570. /*
  1571. * Convert given nl80211 specific mask value to equivalent
  1572. * driver specific mask value and send it to the chip along
  1573. * with patterns. For example, If the mask value defined in
  1574. * struct cfg80211_wowlan is 0xA (equivalent binary is 1010),
  1575. * then equivalent driver specific mask value is
  1576. * "0xFF 0x00 0xFF 0x00".
  1577. */
  1578. memset(&mask, 0, sizeof(mask));
  1579. for (pos = 0; pos < wow->patterns[i].pattern_len; pos++) {
  1580. if (wow->patterns[i].mask[pos / 8] & (0x1 << (pos % 8)))
  1581. mask[pos] = 0xFF;
  1582. }
  1583. /*
  1584. * Note: Pattern's offset is not passed as part of wowlan
  1585. * parameter from CFG layer. So it's always passed as ZERO
  1586. * to the firmware. It means, given WOW patterns are always
  1587. * matched from the first byte of received pkt in the firmware.
  1588. */
  1589. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1590. vif->fw_vif_idx, WOW_LIST_ID,
  1591. wow->patterns[i].pattern_len,
  1592. 0 /* pattern offset */,
  1593. wow->patterns[i].pattern, mask);
  1594. if (ret)
  1595. return ret;
  1596. }
  1597. if (wow->disconnect)
  1598. *filter |= WOW_FILTER_OPTION_NWK_DISASSOC;
  1599. if (wow->magic_pkt)
  1600. *filter |= WOW_FILTER_OPTION_MAGIC_PACKET;
  1601. if (wow->gtk_rekey_failure)
  1602. *filter |= WOW_FILTER_OPTION_GTK_ERROR;
  1603. if (wow->eap_identity_req)
  1604. *filter |= WOW_FILTER_OPTION_EAP_REQ;
  1605. if (wow->four_way_handshake)
  1606. *filter |= WOW_FILTER_OPTION_8021X_4WAYHS;
  1607. return 0;
  1608. }
  1609. static int ath6kl_wow_ap(struct ath6kl *ar, struct ath6kl_vif *vif)
  1610. {
  1611. static const u8 unicst_pattern[] = { 0x00, 0x00, 0x00,
  1612. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1613. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1614. 0x00, 0x08 };
  1615. static const u8 unicst_mask[] = { 0x01, 0x00, 0x00,
  1616. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1617. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1618. 0x00, 0x7f };
  1619. u8 unicst_offset = 0;
  1620. static const u8 arp_pattern[] = { 0x08, 0x06 };
  1621. static const u8 arp_mask[] = { 0xff, 0xff };
  1622. u8 arp_offset = 20;
  1623. static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 };
  1624. static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 };
  1625. u8 discvr_offset = 38;
  1626. static const u8 dhcp_pattern[] = { 0xff, 0xff, 0xff, 0xff,
  1627. 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1628. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
  1629. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1630. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1631. 0x00, 0x00, 0x00, 0x00, 0x00, 0x43 /* port 67 */ };
  1632. static const u8 dhcp_mask[] = { 0xff, 0xff, 0xff, 0xff,
  1633. 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1634. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
  1635. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1636. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1637. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff /* port 67 */ };
  1638. u8 dhcp_offset = 0;
  1639. int ret;
  1640. /* Setup unicast IP, EAPOL-like and ARP pkt pattern */
  1641. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1642. vif->fw_vif_idx, WOW_LIST_ID,
  1643. sizeof(unicst_pattern), unicst_offset,
  1644. unicst_pattern, unicst_mask);
  1645. if (ret) {
  1646. ath6kl_err("failed to add WOW unicast IP pattern\n");
  1647. return ret;
  1648. }
  1649. /* Setup all ARP pkt pattern */
  1650. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1651. vif->fw_vif_idx, WOW_LIST_ID,
  1652. sizeof(arp_pattern), arp_offset,
  1653. arp_pattern, arp_mask);
  1654. if (ret) {
  1655. ath6kl_err("failed to add WOW ARP pattern\n");
  1656. return ret;
  1657. }
  1658. /*
  1659. * Setup multicast pattern for mDNS 224.0.0.251,
  1660. * SSDP 239.255.255.250 and LLMNR 224.0.0.252
  1661. */
  1662. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1663. vif->fw_vif_idx, WOW_LIST_ID,
  1664. sizeof(discvr_pattern), discvr_offset,
  1665. discvr_pattern, discvr_mask);
  1666. if (ret) {
  1667. ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR pattern\n");
  1668. return ret;
  1669. }
  1670. /* Setup all DHCP broadcast pkt pattern */
  1671. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1672. vif->fw_vif_idx, WOW_LIST_ID,
  1673. sizeof(dhcp_pattern), dhcp_offset,
  1674. dhcp_pattern, dhcp_mask);
  1675. if (ret) {
  1676. ath6kl_err("failed to add WOW DHCP broadcast pattern\n");
  1677. return ret;
  1678. }
  1679. return 0;
  1680. }
  1681. static int ath6kl_wow_sta(struct ath6kl *ar, struct ath6kl_vif *vif)
  1682. {
  1683. struct net_device *ndev = vif->ndev;
  1684. static const u8 discvr_pattern[] = { 0xe0, 0x00, 0x00, 0xf8 };
  1685. static const u8 discvr_mask[] = { 0xf0, 0x00, 0x00, 0xf8 };
  1686. u8 discvr_offset = 38;
  1687. u8 mac_mask[ETH_ALEN];
  1688. int ret;
  1689. /* Setup unicast pkt pattern */
  1690. memset(mac_mask, 0xff, ETH_ALEN);
  1691. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1692. vif->fw_vif_idx, WOW_LIST_ID,
  1693. ETH_ALEN, 0, ndev->dev_addr,
  1694. mac_mask);
  1695. if (ret) {
  1696. ath6kl_err("failed to add WOW unicast pattern\n");
  1697. return ret;
  1698. }
  1699. /*
  1700. * Setup multicast pattern for mDNS 224.0.0.251,
  1701. * SSDP 239.255.255.250 and LLMNR 224.0.0.252
  1702. */
  1703. if ((ndev->flags & IFF_ALLMULTI) ||
  1704. (ndev->flags & IFF_MULTICAST && netdev_mc_count(ndev) > 0)) {
  1705. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1706. vif->fw_vif_idx, WOW_LIST_ID,
  1707. sizeof(discvr_pattern), discvr_offset,
  1708. discvr_pattern, discvr_mask);
  1709. if (ret) {
  1710. ath6kl_err("failed to add WOW mDNS/SSDP/LLMNR pattern\n");
  1711. return ret;
  1712. }
  1713. }
  1714. return 0;
  1715. }
  1716. static int is_hsleep_mode_procsed(struct ath6kl_vif *vif)
  1717. {
  1718. return test_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
  1719. }
  1720. static bool is_ctrl_ep_empty(struct ath6kl *ar)
  1721. {
  1722. return !ar->tx_pending[ar->ctrl_ep];
  1723. }
  1724. static int ath6kl_cfg80211_host_sleep(struct ath6kl *ar, struct ath6kl_vif *vif)
  1725. {
  1726. int ret, left;
  1727. clear_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
  1728. ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1729. ATH6KL_HOST_MODE_ASLEEP);
  1730. if (ret)
  1731. return ret;
  1732. left = wait_event_interruptible_timeout(ar->event_wq,
  1733. is_hsleep_mode_procsed(vif),
  1734. WMI_TIMEOUT);
  1735. if (left == 0) {
  1736. ath6kl_warn("timeout, didn't get host sleep cmd processed event\n");
  1737. ret = -ETIMEDOUT;
  1738. } else if (left < 0) {
  1739. ath6kl_warn("error while waiting for host sleep cmd processed event %d\n",
  1740. left);
  1741. ret = left;
  1742. }
  1743. if (ar->tx_pending[ar->ctrl_ep]) {
  1744. left = wait_event_interruptible_timeout(ar->event_wq,
  1745. is_ctrl_ep_empty(ar),
  1746. WMI_TIMEOUT);
  1747. if (left == 0) {
  1748. ath6kl_warn("clear wmi ctrl data timeout\n");
  1749. ret = -ETIMEDOUT;
  1750. } else if (left < 0) {
  1751. ath6kl_warn("clear wmi ctrl data failed: %d\n", left);
  1752. ret = left;
  1753. }
  1754. }
  1755. return ret;
  1756. }
  1757. static int ath6kl_wow_suspend_vif(struct ath6kl_vif *vif,
  1758. struct cfg80211_wowlan *wow, u32 *filter)
  1759. {
  1760. struct ath6kl *ar = vif->ar;
  1761. struct in_device *in_dev;
  1762. struct in_ifaddr *ifa;
  1763. int ret;
  1764. u16 i, bmiss_time;
  1765. __be32 ips[MAX_IP_ADDRS];
  1766. u8 index = 0;
  1767. if (!test_bit(NETDEV_MCAST_ALL_ON, &vif->flags) &&
  1768. test_bit(ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER,
  1769. ar->fw_capabilities)) {
  1770. ret = ath6kl_wmi_mcast_filter_cmd(vif->ar->wmi,
  1771. vif->fw_vif_idx, false);
  1772. if (ret)
  1773. return ret;
  1774. }
  1775. /* Clear existing WOW patterns */
  1776. for (i = 0; i < WOW_MAX_FILTERS_PER_LIST; i++)
  1777. ath6kl_wmi_del_wow_pattern_cmd(ar->wmi, vif->fw_vif_idx,
  1778. WOW_LIST_ID, i);
  1779. /*
  1780. * Skip the default WOW pattern configuration
  1781. * if the driver receives any WOW patterns from
  1782. * the user.
  1783. */
  1784. if (wow)
  1785. ret = ath6kl_wow_usr(ar, vif, wow, filter);
  1786. else if (vif->nw_type == AP_NETWORK)
  1787. ret = ath6kl_wow_ap(ar, vif);
  1788. else
  1789. ret = ath6kl_wow_sta(ar, vif);
  1790. if (ret)
  1791. return ret;
  1792. netif_stop_queue(vif->ndev);
  1793. if (vif->nw_type != AP_NETWORK) {
  1794. ret = ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  1795. ATH6KL_MAX_WOW_LISTEN_INTL,
  1796. 0);
  1797. if (ret)
  1798. return ret;
  1799. /* Set listen interval x 15 times as bmiss time */
  1800. bmiss_time = ATH6KL_MAX_WOW_LISTEN_INTL * 15;
  1801. if (bmiss_time > ATH6KL_MAX_BMISS_TIME)
  1802. bmiss_time = ATH6KL_MAX_BMISS_TIME;
  1803. ret = ath6kl_wmi_bmisstime_cmd(ar->wmi, vif->fw_vif_idx,
  1804. bmiss_time, 0);
  1805. if (ret)
  1806. return ret;
  1807. ret = ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
  1808. 0xFFFF, 0, 0xFFFF, 0, 0, 0,
  1809. 0, 0, 0, 0);
  1810. if (ret)
  1811. return ret;
  1812. }
  1813. /* Setup own IP addr for ARP agent. */
  1814. in_dev = __in_dev_get_rtnl(vif->ndev);
  1815. if (!in_dev)
  1816. return 0;
  1817. ifa = in_dev->ifa_list;
  1818. memset(&ips, 0, sizeof(ips));
  1819. /* Configure IP addr only if IP address count < MAX_IP_ADDRS */
  1820. while (index < MAX_IP_ADDRS && ifa) {
  1821. ips[index] = ifa->ifa_local;
  1822. ifa = ifa->ifa_next;
  1823. index++;
  1824. }
  1825. if (ifa) {
  1826. ath6kl_err("total IP addr count is exceeding fw limit\n");
  1827. return -EINVAL;
  1828. }
  1829. ret = ath6kl_wmi_set_ip_cmd(ar->wmi, vif->fw_vif_idx, ips[0], ips[1]);
  1830. if (ret) {
  1831. ath6kl_err("fail to setup ip for arp agent\n");
  1832. return ret;
  1833. }
  1834. return ret;
  1835. }
  1836. static int ath6kl_wow_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
  1837. {
  1838. struct ath6kl_vif *first_vif, *vif;
  1839. int ret = 0;
  1840. u32 filter = 0;
  1841. bool connected = false;
  1842. /* enter / leave wow suspend on first vif always */
  1843. first_vif = ath6kl_vif_first(ar);
  1844. if (WARN_ON(unlikely(!first_vif)) ||
  1845. !ath6kl_cfg80211_ready(first_vif))
  1846. return -EIO;
  1847. if (wow && (wow->n_patterns > WOW_MAX_FILTERS_PER_LIST))
  1848. return -EINVAL;
  1849. /* install filters for each connected vif */
  1850. spin_lock_bh(&ar->list_lock);
  1851. list_for_each_entry(vif, &ar->vif_list, list) {
  1852. if (!test_bit(CONNECTED, &vif->flags) ||
  1853. !ath6kl_cfg80211_ready(vif))
  1854. continue;
  1855. connected = true;
  1856. ret = ath6kl_wow_suspend_vif(vif, wow, &filter);
  1857. if (ret)
  1858. break;
  1859. }
  1860. spin_unlock_bh(&ar->list_lock);
  1861. if (!connected)
  1862. return -ENOTCONN;
  1863. else if (ret)
  1864. return ret;
  1865. ar->state = ATH6KL_STATE_SUSPENDING;
  1866. ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, first_vif->fw_vif_idx,
  1867. ATH6KL_WOW_MODE_ENABLE,
  1868. filter,
  1869. WOW_HOST_REQ_DELAY);
  1870. if (ret)
  1871. return ret;
  1872. return ath6kl_cfg80211_host_sleep(ar, first_vif);
  1873. }
  1874. static int ath6kl_wow_resume_vif(struct ath6kl_vif *vif)
  1875. {
  1876. struct ath6kl *ar = vif->ar;
  1877. int ret;
  1878. if (vif->nw_type != AP_NETWORK) {
  1879. ret = ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
  1880. 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
  1881. if (ret)
  1882. return ret;
  1883. ret = ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  1884. vif->listen_intvl_t, 0);
  1885. if (ret)
  1886. return ret;
  1887. ret = ath6kl_wmi_bmisstime_cmd(ar->wmi, vif->fw_vif_idx,
  1888. vif->bmiss_time_t, 0);
  1889. if (ret)
  1890. return ret;
  1891. }
  1892. if (!test_bit(NETDEV_MCAST_ALL_OFF, &vif->flags) &&
  1893. test_bit(ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER,
  1894. ar->fw_capabilities)) {
  1895. ret = ath6kl_wmi_mcast_filter_cmd(vif->ar->wmi,
  1896. vif->fw_vif_idx, true);
  1897. if (ret)
  1898. return ret;
  1899. }
  1900. netif_wake_queue(vif->ndev);
  1901. return 0;
  1902. }
  1903. static int ath6kl_wow_resume(struct ath6kl *ar)
  1904. {
  1905. struct ath6kl_vif *vif;
  1906. int ret;
  1907. vif = ath6kl_vif_first(ar);
  1908. if (WARN_ON(unlikely(!vif)) ||
  1909. !ath6kl_cfg80211_ready(vif))
  1910. return -EIO;
  1911. ar->state = ATH6KL_STATE_RESUMING;
  1912. ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1913. ATH6KL_HOST_MODE_AWAKE);
  1914. if (ret) {
  1915. ath6kl_warn("Failed to configure host sleep mode for wow resume: %d\n",
  1916. ret);
  1917. goto cleanup;
  1918. }
  1919. spin_lock_bh(&ar->list_lock);
  1920. list_for_each_entry(vif, &ar->vif_list, list) {
  1921. if (!test_bit(CONNECTED, &vif->flags) ||
  1922. !ath6kl_cfg80211_ready(vif))
  1923. continue;
  1924. ret = ath6kl_wow_resume_vif(vif);
  1925. if (ret)
  1926. break;
  1927. }
  1928. spin_unlock_bh(&ar->list_lock);
  1929. if (ret)
  1930. goto cleanup;
  1931. ar->state = ATH6KL_STATE_ON;
  1932. return 0;
  1933. cleanup:
  1934. ar->state = ATH6KL_STATE_WOW;
  1935. return ret;
  1936. }
  1937. static int ath6kl_cfg80211_deepsleep_suspend(struct ath6kl *ar)
  1938. {
  1939. struct ath6kl_vif *vif;
  1940. int ret;
  1941. vif = ath6kl_vif_first(ar);
  1942. if (!vif)
  1943. return -EIO;
  1944. if (!test_bit(WMI_READY, &ar->flag)) {
  1945. ath6kl_err("deepsleep failed as wmi is not ready\n");
  1946. return -EIO;
  1947. }
  1948. ath6kl_cfg80211_stop_all(ar);
  1949. /* Save the current power mode before enabling power save */
  1950. ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
  1951. ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER);
  1952. if (ret)
  1953. return ret;
  1954. /* Disable WOW mode */
  1955. ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1956. ATH6KL_WOW_MODE_DISABLE,
  1957. 0, 0);
  1958. if (ret)
  1959. return ret;
  1960. /* Flush all non control pkts in TX path */
  1961. ath6kl_tx_data_cleanup(ar);
  1962. ret = ath6kl_cfg80211_host_sleep(ar, vif);
  1963. if (ret)
  1964. return ret;
  1965. return 0;
  1966. }
  1967. static int ath6kl_cfg80211_deepsleep_resume(struct ath6kl *ar)
  1968. {
  1969. struct ath6kl_vif *vif;
  1970. int ret;
  1971. vif = ath6kl_vif_first(ar);
  1972. if (!vif)
  1973. return -EIO;
  1974. if (ar->wmi->pwr_mode != ar->wmi->saved_pwr_mode) {
  1975. ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0,
  1976. ar->wmi->saved_pwr_mode);
  1977. if (ret)
  1978. return ret;
  1979. }
  1980. ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1981. ATH6KL_HOST_MODE_AWAKE);
  1982. if (ret)
  1983. return ret;
  1984. ar->state = ATH6KL_STATE_ON;
  1985. /* Reset scan parameter to default values */
  1986. ret = ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
  1987. 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
  1988. if (ret)
  1989. return ret;
  1990. return 0;
  1991. }
  1992. int ath6kl_cfg80211_suspend(struct ath6kl *ar,
  1993. enum ath6kl_cfg_suspend_mode mode,
  1994. struct cfg80211_wowlan *wow)
  1995. {
  1996. struct ath6kl_vif *vif;
  1997. enum ath6kl_state prev_state;
  1998. int ret;
  1999. switch (mode) {
  2000. case ATH6KL_CFG_SUSPEND_WOW:
  2001. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode suspend\n");
  2002. /* Flush all non control pkts in TX path */
  2003. ath6kl_tx_data_cleanup(ar);
  2004. prev_state = ar->state;
  2005. ret = ath6kl_wow_suspend(ar, wow);
  2006. if (ret) {
  2007. ar->state = prev_state;
  2008. return ret;
  2009. }
  2010. ar->state = ATH6KL_STATE_WOW;
  2011. break;
  2012. case ATH6KL_CFG_SUSPEND_DEEPSLEEP:
  2013. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "deep sleep suspend\n");
  2014. ret = ath6kl_cfg80211_deepsleep_suspend(ar);
  2015. if (ret) {
  2016. ath6kl_err("deepsleep suspend failed: %d\n", ret);
  2017. return ret;
  2018. }
  2019. ar->state = ATH6KL_STATE_DEEPSLEEP;
  2020. break;
  2021. case ATH6KL_CFG_SUSPEND_CUTPOWER:
  2022. ath6kl_cfg80211_stop_all(ar);
  2023. if (ar->state == ATH6KL_STATE_OFF) {
  2024. ath6kl_dbg(ATH6KL_DBG_SUSPEND,
  2025. "suspend hw off, no action for cutpower\n");
  2026. break;
  2027. }
  2028. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "suspend cutting power\n");
  2029. ret = ath6kl_init_hw_stop(ar);
  2030. if (ret) {
  2031. ath6kl_warn("failed to stop hw during suspend: %d\n",
  2032. ret);
  2033. }
  2034. ar->state = ATH6KL_STATE_CUTPOWER;
  2035. break;
  2036. default:
  2037. break;
  2038. }
  2039. list_for_each_entry(vif, &ar->vif_list, list)
  2040. ath6kl_cfg80211_scan_complete_event(vif, true);
  2041. return 0;
  2042. }
  2043. EXPORT_SYMBOL(ath6kl_cfg80211_suspend);
  2044. int ath6kl_cfg80211_resume(struct ath6kl *ar)
  2045. {
  2046. int ret;
  2047. switch (ar->state) {
  2048. case ATH6KL_STATE_WOW:
  2049. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode resume\n");
  2050. ret = ath6kl_wow_resume(ar);
  2051. if (ret) {
  2052. ath6kl_warn("wow mode resume failed: %d\n", ret);
  2053. return ret;
  2054. }
  2055. break;
  2056. case ATH6KL_STATE_DEEPSLEEP:
  2057. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "deep sleep resume\n");
  2058. ret = ath6kl_cfg80211_deepsleep_resume(ar);
  2059. if (ret) {
  2060. ath6kl_warn("deep sleep resume failed: %d\n", ret);
  2061. return ret;
  2062. }
  2063. break;
  2064. case ATH6KL_STATE_CUTPOWER:
  2065. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "resume restoring power\n");
  2066. ret = ath6kl_init_hw_start(ar);
  2067. if (ret) {
  2068. ath6kl_warn("Failed to boot hw in resume: %d\n", ret);
  2069. return ret;
  2070. }
  2071. break;
  2072. default:
  2073. break;
  2074. }
  2075. return 0;
  2076. }
  2077. EXPORT_SYMBOL(ath6kl_cfg80211_resume);
  2078. #ifdef CONFIG_PM
  2079. /* hif layer decides what suspend mode to use */
  2080. static int __ath6kl_cfg80211_suspend(struct wiphy *wiphy,
  2081. struct cfg80211_wowlan *wow)
  2082. {
  2083. struct ath6kl *ar = wiphy_priv(wiphy);
  2084. ath6kl_recovery_suspend(ar);
  2085. return ath6kl_hif_suspend(ar, wow);
  2086. }
  2087. static int __ath6kl_cfg80211_resume(struct wiphy *wiphy)
  2088. {
  2089. struct ath6kl *ar = wiphy_priv(wiphy);
  2090. int err;
  2091. err = ath6kl_hif_resume(ar);
  2092. if (err)
  2093. return err;
  2094. ath6kl_recovery_resume(ar);
  2095. return 0;
  2096. }
  2097. /*
  2098. * FIXME: WOW suspend mode is selected if the host sdio controller supports
  2099. * both sdio irq wake up and keep power. The target pulls sdio data line to
  2100. * wake up the host when WOW pattern matches. This causes sdio irq handler
  2101. * is being called in the host side which internally hits ath6kl's RX path.
  2102. *
  2103. * Since sdio interrupt is not disabled, RX path executes even before
  2104. * the host executes the actual resume operation from PM module.
  2105. *
  2106. * In the current scenario, WOW resume should happen before start processing
  2107. * any data from the target. So It's required to perform WOW resume in RX path.
  2108. * Ideally we should perform WOW resume only in the actual platform
  2109. * resume path. This area needs bit rework to avoid WOW resume in RX path.
  2110. *
  2111. * ath6kl_check_wow_status() is called from ath6kl_rx().
  2112. */
  2113. void ath6kl_check_wow_status(struct ath6kl *ar)
  2114. {
  2115. if (ar->state == ATH6KL_STATE_SUSPENDING)
  2116. return;
  2117. if (ar->state == ATH6KL_STATE_WOW)
  2118. ath6kl_cfg80211_resume(ar);
  2119. }
  2120. #else
  2121. void ath6kl_check_wow_status(struct ath6kl *ar)
  2122. {
  2123. }
  2124. #endif
  2125. static int ath6kl_set_htcap(struct ath6kl_vif *vif, enum ieee80211_band band,
  2126. bool ht_enable)
  2127. {
  2128. struct ath6kl_htcap *htcap = &vif->htcap[band];
  2129. if (htcap->ht_enable == ht_enable)
  2130. return 0;
  2131. if (ht_enable) {
  2132. /* Set default ht capabilities */
  2133. htcap->ht_enable = true;
  2134. htcap->cap_info = (band == IEEE80211_BAND_2GHZ) ?
  2135. ath6kl_g_htcap : ath6kl_a_htcap;
  2136. htcap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K;
  2137. } else /* Disable ht */
  2138. memset(htcap, 0, sizeof(*htcap));
  2139. return ath6kl_wmi_set_htcap_cmd(vif->ar->wmi, vif->fw_vif_idx,
  2140. band, htcap);
  2141. }
  2142. static int ath6kl_restore_htcap(struct ath6kl_vif *vif)
  2143. {
  2144. struct wiphy *wiphy = vif->ar->wiphy;
  2145. int band, ret = 0;
  2146. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  2147. if (!wiphy->bands[band])
  2148. continue;
  2149. ret = ath6kl_set_htcap(vif, band,
  2150. wiphy->bands[band]->ht_cap.ht_supported);
  2151. if (ret)
  2152. return ret;
  2153. }
  2154. return ret;
  2155. }
  2156. static bool ath6kl_is_p2p_ie(const u8 *pos)
  2157. {
  2158. return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  2159. pos[2] == 0x50 && pos[3] == 0x6f &&
  2160. pos[4] == 0x9a && pos[5] == 0x09;
  2161. }
  2162. static int ath6kl_set_ap_probe_resp_ies(struct ath6kl_vif *vif,
  2163. const u8 *ies, size_t ies_len)
  2164. {
  2165. struct ath6kl *ar = vif->ar;
  2166. const u8 *pos;
  2167. u8 *buf = NULL;
  2168. size_t len = 0;
  2169. int ret;
  2170. /*
  2171. * Filter out P2P IE(s) since they will be included depending on
  2172. * the Probe Request frame in ath6kl_send_go_probe_resp().
  2173. */
  2174. if (ies && ies_len) {
  2175. buf = kmalloc(ies_len, GFP_KERNEL);
  2176. if (buf == NULL)
  2177. return -ENOMEM;
  2178. pos = ies;
  2179. while (pos + 1 < ies + ies_len) {
  2180. if (pos + 2 + pos[1] > ies + ies_len)
  2181. break;
  2182. if (!ath6kl_is_p2p_ie(pos)) {
  2183. memcpy(buf + len, pos, 2 + pos[1]);
  2184. len += 2 + pos[1];
  2185. }
  2186. pos += 2 + pos[1];
  2187. }
  2188. }
  2189. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  2190. WMI_FRAME_PROBE_RESP, buf, len);
  2191. kfree(buf);
  2192. return ret;
  2193. }
  2194. static int ath6kl_set_ies(struct ath6kl_vif *vif,
  2195. struct cfg80211_beacon_data *info)
  2196. {
  2197. struct ath6kl *ar = vif->ar;
  2198. int res;
  2199. /* this also clears IE in fw if it's not set */
  2200. res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  2201. WMI_FRAME_BEACON,
  2202. info->beacon_ies,
  2203. info->beacon_ies_len);
  2204. if (res)
  2205. return res;
  2206. /* this also clears IE in fw if it's not set */
  2207. res = ath6kl_set_ap_probe_resp_ies(vif, info->proberesp_ies,
  2208. info->proberesp_ies_len);
  2209. if (res)
  2210. return res;
  2211. /* this also clears IE in fw if it's not set */
  2212. res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  2213. WMI_FRAME_ASSOC_RESP,
  2214. info->assocresp_ies,
  2215. info->assocresp_ies_len);
  2216. if (res)
  2217. return res;
  2218. return 0;
  2219. }
  2220. static int ath6kl_get_rsn_capab(struct cfg80211_beacon_data *beacon,
  2221. u8 *rsn_capab)
  2222. {
  2223. const u8 *rsn_ie;
  2224. size_t rsn_ie_len;
  2225. u16 cnt;
  2226. if (!beacon->tail)
  2227. return -EINVAL;
  2228. rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, beacon->tail, beacon->tail_len);
  2229. if (!rsn_ie)
  2230. return -EINVAL;
  2231. rsn_ie_len = *(rsn_ie + 1);
  2232. /* skip element id and length */
  2233. rsn_ie += 2;
  2234. /* skip version */
  2235. if (rsn_ie_len < 2)
  2236. return -EINVAL;
  2237. rsn_ie += 2;
  2238. rsn_ie_len -= 2;
  2239. /* skip group cipher suite */
  2240. if (rsn_ie_len < 4)
  2241. return 0;
  2242. rsn_ie += 4;
  2243. rsn_ie_len -= 4;
  2244. /* skip pairwise cipher suite */
  2245. if (rsn_ie_len < 2)
  2246. return 0;
  2247. cnt = get_unaligned_le16(rsn_ie);
  2248. rsn_ie += (2 + cnt * 4);
  2249. rsn_ie_len -= (2 + cnt * 4);
  2250. /* skip akm suite */
  2251. if (rsn_ie_len < 2)
  2252. return 0;
  2253. cnt = get_unaligned_le16(rsn_ie);
  2254. rsn_ie += (2 + cnt * 4);
  2255. rsn_ie_len -= (2 + cnt * 4);
  2256. if (rsn_ie_len < 2)
  2257. return 0;
  2258. memcpy(rsn_capab, rsn_ie, 2);
  2259. return 0;
  2260. }
  2261. static int ath6kl_start_ap(struct wiphy *wiphy, struct net_device *dev,
  2262. struct cfg80211_ap_settings *info)
  2263. {
  2264. struct ath6kl *ar = ath6kl_priv(dev);
  2265. struct ath6kl_vif *vif = netdev_priv(dev);
  2266. struct ieee80211_mgmt *mgmt;
  2267. bool hidden = false;
  2268. u8 *ies;
  2269. int ies_len;
  2270. struct wmi_connect_cmd p;
  2271. int res;
  2272. int i, ret;
  2273. u16 rsn_capab = 0;
  2274. int inactivity_timeout = 0;
  2275. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s:\n", __func__);
  2276. if (!ath6kl_cfg80211_ready(vif))
  2277. return -EIO;
  2278. if (vif->next_mode != AP_NETWORK)
  2279. return -EOPNOTSUPP;
  2280. res = ath6kl_set_ies(vif, &info->beacon);
  2281. ar->ap_mode_bkey.valid = false;
  2282. ret = ath6kl_wmi_ap_set_beacon_intvl_cmd(ar->wmi, vif->fw_vif_idx,
  2283. info->beacon_interval);
  2284. if (ret)
  2285. ath6kl_warn("Failed to set beacon interval: %d\n", ret);
  2286. ret = ath6kl_wmi_ap_set_dtim_cmd(ar->wmi, vif->fw_vif_idx,
  2287. info->dtim_period);
  2288. /* ignore error, just print a warning and continue normally */
  2289. if (ret)
  2290. ath6kl_warn("Failed to set dtim_period in beacon: %d\n", ret);
  2291. if (info->beacon.head == NULL)
  2292. return -EINVAL;
  2293. mgmt = (struct ieee80211_mgmt *) info->beacon.head;
  2294. ies = mgmt->u.beacon.variable;
  2295. if (ies > info->beacon.head + info->beacon.head_len)
  2296. return -EINVAL;
  2297. ies_len = info->beacon.head + info->beacon.head_len - ies;
  2298. if (info->ssid == NULL)
  2299. return -EINVAL;
  2300. memcpy(vif->ssid, info->ssid, info->ssid_len);
  2301. vif->ssid_len = info->ssid_len;
  2302. if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
  2303. hidden = true;
  2304. res = ath6kl_wmi_ap_hidden_ssid(ar->wmi, vif->fw_vif_idx, hidden);
  2305. if (res)
  2306. return res;
  2307. ret = ath6kl_set_auth_type(vif, info->auth_type);
  2308. if (ret)
  2309. return ret;
  2310. memset(&p, 0, sizeof(p));
  2311. for (i = 0; i < info->crypto.n_akm_suites; i++) {
  2312. switch (info->crypto.akm_suites[i]) {
  2313. case WLAN_AKM_SUITE_8021X:
  2314. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  2315. p.auth_mode |= WPA_AUTH;
  2316. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  2317. p.auth_mode |= WPA2_AUTH;
  2318. break;
  2319. case WLAN_AKM_SUITE_PSK:
  2320. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  2321. p.auth_mode |= WPA_PSK_AUTH;
  2322. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  2323. p.auth_mode |= WPA2_PSK_AUTH;
  2324. break;
  2325. }
  2326. }
  2327. if (p.auth_mode == 0)
  2328. p.auth_mode = NONE_AUTH;
  2329. vif->auth_mode = p.auth_mode;
  2330. for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
  2331. switch (info->crypto.ciphers_pairwise[i]) {
  2332. case WLAN_CIPHER_SUITE_WEP40:
  2333. case WLAN_CIPHER_SUITE_WEP104:
  2334. p.prwise_crypto_type |= WEP_CRYPT;
  2335. break;
  2336. case WLAN_CIPHER_SUITE_TKIP:
  2337. p.prwise_crypto_type |= TKIP_CRYPT;
  2338. break;
  2339. case WLAN_CIPHER_SUITE_CCMP:
  2340. p.prwise_crypto_type |= AES_CRYPT;
  2341. break;
  2342. case WLAN_CIPHER_SUITE_SMS4:
  2343. p.prwise_crypto_type |= WAPI_CRYPT;
  2344. break;
  2345. }
  2346. }
  2347. if (p.prwise_crypto_type == 0) {
  2348. p.prwise_crypto_type = NONE_CRYPT;
  2349. ath6kl_set_cipher(vif, 0, true);
  2350. } else if (info->crypto.n_ciphers_pairwise == 1)
  2351. ath6kl_set_cipher(vif, info->crypto.ciphers_pairwise[0], true);
  2352. switch (info->crypto.cipher_group) {
  2353. case WLAN_CIPHER_SUITE_WEP40:
  2354. case WLAN_CIPHER_SUITE_WEP104:
  2355. p.grp_crypto_type = WEP_CRYPT;
  2356. break;
  2357. case WLAN_CIPHER_SUITE_TKIP:
  2358. p.grp_crypto_type = TKIP_CRYPT;
  2359. break;
  2360. case WLAN_CIPHER_SUITE_CCMP:
  2361. p.grp_crypto_type = AES_CRYPT;
  2362. break;
  2363. case WLAN_CIPHER_SUITE_SMS4:
  2364. p.grp_crypto_type = WAPI_CRYPT;
  2365. break;
  2366. default:
  2367. p.grp_crypto_type = NONE_CRYPT;
  2368. break;
  2369. }
  2370. ath6kl_set_cipher(vif, info->crypto.cipher_group, false);
  2371. p.nw_type = AP_NETWORK;
  2372. vif->nw_type = vif->next_mode;
  2373. p.ssid_len = vif->ssid_len;
  2374. memcpy(p.ssid, vif->ssid, vif->ssid_len);
  2375. p.dot11_auth_mode = vif->dot11_auth_mode;
  2376. p.ch = cpu_to_le16(info->chandef.chan->center_freq);
  2377. /* Enable uAPSD support by default */
  2378. res = ath6kl_wmi_ap_set_apsd(ar->wmi, vif->fw_vif_idx, true);
  2379. if (res < 0)
  2380. return res;
  2381. if (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
  2382. p.nw_subtype = SUBTYPE_P2PGO;
  2383. } else {
  2384. /*
  2385. * Due to firmware limitation, it is not possible to
  2386. * do P2P mgmt operations in AP mode
  2387. */
  2388. p.nw_subtype = SUBTYPE_NONE;
  2389. }
  2390. if (info->inactivity_timeout) {
  2391. inactivity_timeout = info->inactivity_timeout;
  2392. if (ar->hw.flags & ATH6KL_HW_AP_INACTIVITY_MINS)
  2393. inactivity_timeout = DIV_ROUND_UP(inactivity_timeout,
  2394. 60);
  2395. res = ath6kl_wmi_set_inact_period(ar->wmi, vif->fw_vif_idx,
  2396. inactivity_timeout);
  2397. if (res < 0)
  2398. return res;
  2399. }
  2400. if (ath6kl_set_htcap(vif, info->chandef.chan->band,
  2401. cfg80211_get_chandef_type(&info->chandef)
  2402. != NL80211_CHAN_NO_HT))
  2403. return -EIO;
  2404. /*
  2405. * Get the PTKSA replay counter in the RSN IE. Supplicant
  2406. * will use the RSN IE in M3 message and firmware has to
  2407. * advertise the same in beacon/probe response. Send
  2408. * the complete RSN IE capability field to firmware
  2409. */
  2410. if (!ath6kl_get_rsn_capab(&info->beacon, (u8 *) &rsn_capab) &&
  2411. test_bit(ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
  2412. ar->fw_capabilities)) {
  2413. res = ath6kl_wmi_set_ie_cmd(ar->wmi, vif->fw_vif_idx,
  2414. WLAN_EID_RSN, WMI_RSN_IE_CAPB,
  2415. (const u8 *) &rsn_capab,
  2416. sizeof(rsn_capab));
  2417. vif->rsn_capab = rsn_capab;
  2418. if (res < 0)
  2419. return res;
  2420. }
  2421. memcpy(&vif->profile, &p, sizeof(p));
  2422. res = ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx, &p);
  2423. if (res < 0)
  2424. return res;
  2425. return 0;
  2426. }
  2427. static int ath6kl_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  2428. struct cfg80211_beacon_data *beacon)
  2429. {
  2430. struct ath6kl_vif *vif = netdev_priv(dev);
  2431. if (!ath6kl_cfg80211_ready(vif))
  2432. return -EIO;
  2433. if (vif->next_mode != AP_NETWORK)
  2434. return -EOPNOTSUPP;
  2435. return ath6kl_set_ies(vif, beacon);
  2436. }
  2437. static int ath6kl_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  2438. {
  2439. struct ath6kl *ar = ath6kl_priv(dev);
  2440. struct ath6kl_vif *vif = netdev_priv(dev);
  2441. if (vif->nw_type != AP_NETWORK)
  2442. return -EOPNOTSUPP;
  2443. if (!test_bit(CONNECTED, &vif->flags))
  2444. return -ENOTCONN;
  2445. ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
  2446. clear_bit(CONNECTED, &vif->flags);
  2447. /* Restore ht setting in firmware */
  2448. return ath6kl_restore_htcap(vif);
  2449. }
  2450. static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  2451. static int ath6kl_del_station(struct wiphy *wiphy, struct net_device *dev,
  2452. u8 *mac)
  2453. {
  2454. struct ath6kl *ar = ath6kl_priv(dev);
  2455. struct ath6kl_vif *vif = netdev_priv(dev);
  2456. const u8 *addr = mac ? mac : bcast_addr;
  2457. return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx, WMI_AP_DEAUTH,
  2458. addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
  2459. }
  2460. static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
  2461. u8 *mac, struct station_parameters *params)
  2462. {
  2463. struct ath6kl *ar = ath6kl_priv(dev);
  2464. struct ath6kl_vif *vif = netdev_priv(dev);
  2465. if (vif->nw_type != AP_NETWORK)
  2466. return -EOPNOTSUPP;
  2467. /* Use this only for authorizing/unauthorizing a station */
  2468. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  2469. return -EOPNOTSUPP;
  2470. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  2471. return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
  2472. WMI_AP_MLME_AUTHORIZE, mac, 0);
  2473. return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
  2474. WMI_AP_MLME_UNAUTHORIZE, mac, 0);
  2475. }
  2476. static int ath6kl_remain_on_channel(struct wiphy *wiphy,
  2477. struct wireless_dev *wdev,
  2478. struct ieee80211_channel *chan,
  2479. unsigned int duration,
  2480. u64 *cookie)
  2481. {
  2482. struct ath6kl_vif *vif = ath6kl_vif_from_wdev(wdev);
  2483. struct ath6kl *ar = ath6kl_priv(vif->ndev);
  2484. u32 id;
  2485. /* TODO: if already pending or ongoing remain-on-channel,
  2486. * return -EBUSY */
  2487. id = ++vif->last_roc_id;
  2488. if (id == 0) {
  2489. /* Do not use 0 as the cookie value */
  2490. id = ++vif->last_roc_id;
  2491. }
  2492. *cookie = id;
  2493. return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx,
  2494. chan->center_freq, duration);
  2495. }
  2496. static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
  2497. struct wireless_dev *wdev,
  2498. u64 cookie)
  2499. {
  2500. struct ath6kl_vif *vif = ath6kl_vif_from_wdev(wdev);
  2501. struct ath6kl *ar = ath6kl_priv(vif->ndev);
  2502. if (cookie != vif->last_roc_id)
  2503. return -ENOENT;
  2504. vif->last_cancel_roc_id = cookie;
  2505. return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx);
  2506. }
  2507. static int ath6kl_send_go_probe_resp(struct ath6kl_vif *vif,
  2508. const u8 *buf, size_t len,
  2509. unsigned int freq)
  2510. {
  2511. struct ath6kl *ar = vif->ar;
  2512. const u8 *pos;
  2513. u8 *p2p;
  2514. int p2p_len;
  2515. int ret;
  2516. const struct ieee80211_mgmt *mgmt;
  2517. mgmt = (const struct ieee80211_mgmt *) buf;
  2518. /* Include P2P IE(s) from the frame generated in user space. */
  2519. p2p = kmalloc(len, GFP_KERNEL);
  2520. if (p2p == NULL)
  2521. return -ENOMEM;
  2522. p2p_len = 0;
  2523. pos = mgmt->u.probe_resp.variable;
  2524. while (pos + 1 < buf + len) {
  2525. if (pos + 2 + pos[1] > buf + len)
  2526. break;
  2527. if (ath6kl_is_p2p_ie(pos)) {
  2528. memcpy(p2p + p2p_len, pos, 2 + pos[1]);
  2529. p2p_len += 2 + pos[1];
  2530. }
  2531. pos += 2 + pos[1];
  2532. }
  2533. ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, vif->fw_vif_idx, freq,
  2534. mgmt->da, p2p, p2p_len);
  2535. kfree(p2p);
  2536. return ret;
  2537. }
  2538. static bool ath6kl_mgmt_powersave_ap(struct ath6kl_vif *vif,
  2539. u32 id,
  2540. u32 freq,
  2541. u32 wait,
  2542. const u8 *buf,
  2543. size_t len,
  2544. bool *more_data,
  2545. bool no_cck)
  2546. {
  2547. struct ieee80211_mgmt *mgmt;
  2548. struct ath6kl_sta *conn;
  2549. bool is_psq_empty = false;
  2550. struct ath6kl_mgmt_buff *mgmt_buf;
  2551. size_t mgmt_buf_size;
  2552. struct ath6kl *ar = vif->ar;
  2553. mgmt = (struct ieee80211_mgmt *) buf;
  2554. if (is_multicast_ether_addr(mgmt->da))
  2555. return false;
  2556. conn = ath6kl_find_sta(vif, mgmt->da);
  2557. if (!conn)
  2558. return false;
  2559. if (conn->sta_flags & STA_PS_SLEEP) {
  2560. if (!(conn->sta_flags & STA_PS_POLLED)) {
  2561. /* Queue the frames if the STA is sleeping */
  2562. mgmt_buf_size = len + sizeof(struct ath6kl_mgmt_buff);
  2563. mgmt_buf = kmalloc(mgmt_buf_size, GFP_KERNEL);
  2564. if (!mgmt_buf)
  2565. return false;
  2566. INIT_LIST_HEAD(&mgmt_buf->list);
  2567. mgmt_buf->id = id;
  2568. mgmt_buf->freq = freq;
  2569. mgmt_buf->wait = wait;
  2570. mgmt_buf->len = len;
  2571. mgmt_buf->no_cck = no_cck;
  2572. memcpy(mgmt_buf->buf, buf, len);
  2573. spin_lock_bh(&conn->psq_lock);
  2574. is_psq_empty = skb_queue_empty(&conn->psq) &&
  2575. (conn->mgmt_psq_len == 0);
  2576. list_add_tail(&mgmt_buf->list, &conn->mgmt_psq);
  2577. conn->mgmt_psq_len++;
  2578. spin_unlock_bh(&conn->psq_lock);
  2579. /*
  2580. * If this is the first pkt getting queued
  2581. * for this STA, update the PVB for this
  2582. * STA.
  2583. */
  2584. if (is_psq_empty)
  2585. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
  2586. conn->aid, 1);
  2587. return true;
  2588. }
  2589. /*
  2590. * This tx is because of a PsPoll.
  2591. * Determine if MoreData bit has to be set.
  2592. */
  2593. spin_lock_bh(&conn->psq_lock);
  2594. if (!skb_queue_empty(&conn->psq) || (conn->mgmt_psq_len != 0))
  2595. *more_data = true;
  2596. spin_unlock_bh(&conn->psq_lock);
  2597. }
  2598. return false;
  2599. }
  2600. /* Check if SSID length is greater than DIRECT- */
  2601. static bool ath6kl_is_p2p_go_ssid(const u8 *buf, size_t len)
  2602. {
  2603. const struct ieee80211_mgmt *mgmt;
  2604. mgmt = (const struct ieee80211_mgmt *) buf;
  2605. /* variable[1] contains the SSID tag length */
  2606. if (buf + len >= &mgmt->u.probe_resp.variable[1] &&
  2607. (mgmt->u.probe_resp.variable[1] > P2P_WILDCARD_SSID_LEN)) {
  2608. return true;
  2609. }
  2610. return false;
  2611. }
  2612. static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  2613. struct ieee80211_channel *chan, bool offchan,
  2614. unsigned int wait, const u8 *buf, size_t len,
  2615. bool no_cck, bool dont_wait_for_ack, u64 *cookie)
  2616. {
  2617. struct ath6kl_vif *vif = ath6kl_vif_from_wdev(wdev);
  2618. struct ath6kl *ar = ath6kl_priv(vif->ndev);
  2619. u32 id;
  2620. const struct ieee80211_mgmt *mgmt;
  2621. bool more_data, queued;
  2622. mgmt = (const struct ieee80211_mgmt *) buf;
  2623. if (vif->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) &&
  2624. ieee80211_is_probe_resp(mgmt->frame_control) &&
  2625. ath6kl_is_p2p_go_ssid(buf, len)) {
  2626. /*
  2627. * Send Probe Response frame in GO mode using a separate WMI
  2628. * command to allow the target to fill in the generic IEs.
  2629. */
  2630. *cookie = 0; /* TX status not supported */
  2631. return ath6kl_send_go_probe_resp(vif, buf, len,
  2632. chan->center_freq);
  2633. }
  2634. id = vif->send_action_id++;
  2635. if (id == 0) {
  2636. /*
  2637. * 0 is a reserved value in the WMI command and shall not be
  2638. * used for the command.
  2639. */
  2640. id = vif->send_action_id++;
  2641. }
  2642. *cookie = id;
  2643. /* AP mode Power saving processing */
  2644. if (vif->nw_type == AP_NETWORK) {
  2645. queued = ath6kl_mgmt_powersave_ap(vif,
  2646. id, chan->center_freq,
  2647. wait, buf,
  2648. len, &more_data, no_cck);
  2649. if (queued)
  2650. return 0;
  2651. }
  2652. return ath6kl_wmi_send_mgmt_cmd(ar->wmi, vif->fw_vif_idx, id,
  2653. chan->center_freq, wait,
  2654. buf, len, no_cck);
  2655. }
  2656. static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
  2657. struct wireless_dev *wdev,
  2658. u16 frame_type, bool reg)
  2659. {
  2660. struct ath6kl_vif *vif = ath6kl_vif_from_wdev(wdev);
  2661. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
  2662. __func__, frame_type, reg);
  2663. if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
  2664. /*
  2665. * Note: This notification callback is not allowed to sleep, so
  2666. * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
  2667. * hardcode target to report Probe Request frames all the time.
  2668. */
  2669. vif->probe_req_report = reg;
  2670. }
  2671. }
  2672. static int ath6kl_cfg80211_sscan_start(struct wiphy *wiphy,
  2673. struct net_device *dev,
  2674. struct cfg80211_sched_scan_request *request)
  2675. {
  2676. struct ath6kl *ar = ath6kl_priv(dev);
  2677. struct ath6kl_vif *vif = netdev_priv(dev);
  2678. u16 interval;
  2679. int ret, rssi_thold;
  2680. if (ar->state != ATH6KL_STATE_ON)
  2681. return -EIO;
  2682. if (vif->sme_state != SME_DISCONNECTED)
  2683. return -EBUSY;
  2684. ath6kl_cfg80211_scan_complete_event(vif, true);
  2685. ret = ath6kl_set_probed_ssids(ar, vif, request->ssids,
  2686. request->n_ssids,
  2687. request->match_sets,
  2688. request->n_match_sets);
  2689. if (ret < 0)
  2690. return ret;
  2691. if (!request->n_match_sets) {
  2692. ret = ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  2693. ALL_BSS_FILTER, 0);
  2694. if (ret < 0)
  2695. return ret;
  2696. } else {
  2697. ret = ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  2698. MATCHED_SSID_FILTER, 0);
  2699. if (ret < 0)
  2700. return ret;
  2701. }
  2702. if (test_bit(ATH6KL_FW_CAPABILITY_RSSI_SCAN_THOLD,
  2703. ar->fw_capabilities)) {
  2704. if (request->rssi_thold <= NL80211_SCAN_RSSI_THOLD_OFF)
  2705. rssi_thold = 0;
  2706. else if (request->rssi_thold < -127)
  2707. rssi_thold = -127;
  2708. else
  2709. rssi_thold = request->rssi_thold;
  2710. ret = ath6kl_wmi_set_rssi_filter_cmd(ar->wmi, vif->fw_vif_idx,
  2711. rssi_thold);
  2712. if (ret) {
  2713. ath6kl_err("failed to set RSSI threshold for scan\n");
  2714. return ret;
  2715. }
  2716. }
  2717. /* fw uses seconds, also make sure that it's >0 */
  2718. interval = max_t(u16, 1, request->interval / 1000);
  2719. ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
  2720. interval, interval,
  2721. vif->bg_scan_period, 0, 0, 0, 3, 0, 0, 0);
  2722. /* this also clears IE in fw if it's not set */
  2723. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  2724. WMI_FRAME_PROBE_REQ,
  2725. request->ie, request->ie_len);
  2726. if (ret) {
  2727. ath6kl_warn("Failed to set probe request IE for scheduled scan: %d\n",
  2728. ret);
  2729. return ret;
  2730. }
  2731. ret = ath6kl_wmi_enable_sched_scan_cmd(ar->wmi, vif->fw_vif_idx, true);
  2732. if (ret)
  2733. return ret;
  2734. set_bit(SCHED_SCANNING, &vif->flags);
  2735. return 0;
  2736. }
  2737. static int ath6kl_cfg80211_sscan_stop(struct wiphy *wiphy,
  2738. struct net_device *dev)
  2739. {
  2740. struct ath6kl_vif *vif = netdev_priv(dev);
  2741. bool stopped;
  2742. stopped = __ath6kl_cfg80211_sscan_stop(vif);
  2743. if (!stopped)
  2744. return -EIO;
  2745. return 0;
  2746. }
  2747. static int ath6kl_cfg80211_set_bitrate(struct wiphy *wiphy,
  2748. struct net_device *dev,
  2749. const u8 *addr,
  2750. const struct cfg80211_bitrate_mask *mask)
  2751. {
  2752. struct ath6kl *ar = ath6kl_priv(dev);
  2753. struct ath6kl_vif *vif = netdev_priv(dev);
  2754. return ath6kl_wmi_set_bitrate_mask(ar->wmi, vif->fw_vif_idx,
  2755. mask);
  2756. }
  2757. static int ath6kl_cfg80211_set_txe_config(struct wiphy *wiphy,
  2758. struct net_device *dev,
  2759. u32 rate, u32 pkts, u32 intvl)
  2760. {
  2761. struct ath6kl *ar = ath6kl_priv(dev);
  2762. struct ath6kl_vif *vif = netdev_priv(dev);
  2763. if (vif->nw_type != INFRA_NETWORK ||
  2764. !test_bit(ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY, ar->fw_capabilities))
  2765. return -EOPNOTSUPP;
  2766. if (vif->sme_state != SME_CONNECTED)
  2767. return -ENOTCONN;
  2768. /* save this since the firmware won't report the interval */
  2769. vif->txe_intvl = intvl;
  2770. return ath6kl_wmi_set_txe_notify(ar->wmi, vif->fw_vif_idx,
  2771. rate, pkts, intvl);
  2772. }
  2773. static const struct ieee80211_txrx_stypes
  2774. ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  2775. [NL80211_IFTYPE_STATION] = {
  2776. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2777. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  2778. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2779. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  2780. },
  2781. [NL80211_IFTYPE_AP] = {
  2782. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2783. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  2784. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2785. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  2786. },
  2787. [NL80211_IFTYPE_P2P_CLIENT] = {
  2788. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2789. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  2790. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2791. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  2792. },
  2793. [NL80211_IFTYPE_P2P_GO] = {
  2794. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2795. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  2796. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  2797. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  2798. },
  2799. };
  2800. static struct cfg80211_ops ath6kl_cfg80211_ops = {
  2801. .add_virtual_intf = ath6kl_cfg80211_add_iface,
  2802. .del_virtual_intf = ath6kl_cfg80211_del_iface,
  2803. .change_virtual_intf = ath6kl_cfg80211_change_iface,
  2804. .scan = ath6kl_cfg80211_scan,
  2805. .connect = ath6kl_cfg80211_connect,
  2806. .disconnect = ath6kl_cfg80211_disconnect,
  2807. .add_key = ath6kl_cfg80211_add_key,
  2808. .get_key = ath6kl_cfg80211_get_key,
  2809. .del_key = ath6kl_cfg80211_del_key,
  2810. .set_default_key = ath6kl_cfg80211_set_default_key,
  2811. .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
  2812. .set_tx_power = ath6kl_cfg80211_set_txpower,
  2813. .get_tx_power = ath6kl_cfg80211_get_txpower,
  2814. .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
  2815. .join_ibss = ath6kl_cfg80211_join_ibss,
  2816. .leave_ibss = ath6kl_cfg80211_leave_ibss,
  2817. .get_station = ath6kl_get_station,
  2818. .set_pmksa = ath6kl_set_pmksa,
  2819. .del_pmksa = ath6kl_del_pmksa,
  2820. .flush_pmksa = ath6kl_flush_pmksa,
  2821. CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
  2822. #ifdef CONFIG_PM
  2823. .suspend = __ath6kl_cfg80211_suspend,
  2824. .resume = __ath6kl_cfg80211_resume,
  2825. #endif
  2826. .start_ap = ath6kl_start_ap,
  2827. .change_beacon = ath6kl_change_beacon,
  2828. .stop_ap = ath6kl_stop_ap,
  2829. .del_station = ath6kl_del_station,
  2830. .change_station = ath6kl_change_station,
  2831. .remain_on_channel = ath6kl_remain_on_channel,
  2832. .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
  2833. .mgmt_tx = ath6kl_mgmt_tx,
  2834. .mgmt_frame_register = ath6kl_mgmt_frame_register,
  2835. .sched_scan_start = ath6kl_cfg80211_sscan_start,
  2836. .sched_scan_stop = ath6kl_cfg80211_sscan_stop,
  2837. .set_bitrate_mask = ath6kl_cfg80211_set_bitrate,
  2838. .set_cqm_txe_config = ath6kl_cfg80211_set_txe_config,
  2839. };
  2840. void ath6kl_cfg80211_stop(struct ath6kl_vif *vif)
  2841. {
  2842. ath6kl_cfg80211_sscan_disable(vif);
  2843. switch (vif->sme_state) {
  2844. case SME_DISCONNECTED:
  2845. break;
  2846. case SME_CONNECTING:
  2847. cfg80211_connect_result(vif->ndev, vif->bssid, NULL, 0,
  2848. NULL, 0,
  2849. WLAN_STATUS_UNSPECIFIED_FAILURE,
  2850. GFP_KERNEL);
  2851. break;
  2852. case SME_CONNECTED:
  2853. cfg80211_disconnected(vif->ndev, 0, NULL, 0, GFP_KERNEL);
  2854. break;
  2855. }
  2856. if (vif->ar->state != ATH6KL_STATE_RECOVERY &&
  2857. (test_bit(CONNECTED, &vif->flags) ||
  2858. test_bit(CONNECT_PEND, &vif->flags)))
  2859. ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
  2860. vif->sme_state = SME_DISCONNECTED;
  2861. clear_bit(CONNECTED, &vif->flags);
  2862. clear_bit(CONNECT_PEND, &vif->flags);
  2863. /* Stop netdev queues, needed during recovery */
  2864. netif_stop_queue(vif->ndev);
  2865. netif_carrier_off(vif->ndev);
  2866. /* disable scanning */
  2867. if (vif->ar->state != ATH6KL_STATE_RECOVERY &&
  2868. ath6kl_wmi_scanparams_cmd(vif->ar->wmi, vif->fw_vif_idx, 0xFFFF,
  2869. 0, 0, 0, 0, 0, 0, 0, 0, 0) != 0)
  2870. ath6kl_warn("failed to disable scan during stop\n");
  2871. ath6kl_cfg80211_scan_complete_event(vif, true);
  2872. }
  2873. void ath6kl_cfg80211_stop_all(struct ath6kl *ar)
  2874. {
  2875. struct ath6kl_vif *vif;
  2876. vif = ath6kl_vif_first(ar);
  2877. if (!vif && ar->state != ATH6KL_STATE_RECOVERY) {
  2878. /* save the current power mode before enabling power save */
  2879. ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
  2880. if (ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER) != 0)
  2881. ath6kl_warn("ath6kl_deep_sleep_enable: wmi_powermode_cmd failed\n");
  2882. return;
  2883. }
  2884. /*
  2885. * FIXME: we should take ar->list_lock to protect changes in the
  2886. * vif_list, but that's not trivial to do as ath6kl_cfg80211_stop()
  2887. * sleeps.
  2888. */
  2889. list_for_each_entry(vif, &ar->vif_list, list)
  2890. ath6kl_cfg80211_stop(vif);
  2891. }
  2892. static void ath6kl_cfg80211_reg_notify(struct wiphy *wiphy,
  2893. struct regulatory_request *request)
  2894. {
  2895. struct ath6kl *ar = wiphy_priv(wiphy);
  2896. u32 rates[IEEE80211_NUM_BANDS];
  2897. int ret, i;
  2898. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  2899. "cfg reg_notify %c%c%s%s initiator %d hint_type %d\n",
  2900. request->alpha2[0], request->alpha2[1],
  2901. request->intersect ? " intersect" : "",
  2902. request->processed ? " processed" : "",
  2903. request->initiator, request->user_reg_hint_type);
  2904. if (request->user_reg_hint_type != NL80211_USER_REG_HINT_CELL_BASE)
  2905. return;
  2906. ret = ath6kl_wmi_set_regdomain_cmd(ar->wmi, request->alpha2);
  2907. if (ret) {
  2908. ath6kl_err("failed to set regdomain: %d\n", ret);
  2909. return;
  2910. }
  2911. /*
  2912. * Firmware will apply the regdomain change only after a scan is
  2913. * issued and it will send a WMI_REGDOMAIN_EVENTID when it has been
  2914. * changed.
  2915. */
  2916. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  2917. if (wiphy->bands[i])
  2918. rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1;
  2919. ret = ath6kl_wmi_beginscan_cmd(ar->wmi, 0, WMI_LONG_SCAN, false,
  2920. false, 0, ATH6KL_FG_SCAN_INTERVAL,
  2921. 0, NULL, false, rates);
  2922. if (ret) {
  2923. ath6kl_err("failed to start scan for a regdomain change: %d\n",
  2924. ret);
  2925. return;
  2926. }
  2927. }
  2928. static int ath6kl_cfg80211_vif_init(struct ath6kl_vif *vif)
  2929. {
  2930. vif->aggr_cntxt = aggr_init(vif);
  2931. if (!vif->aggr_cntxt) {
  2932. ath6kl_err("failed to initialize aggr\n");
  2933. return -ENOMEM;
  2934. }
  2935. setup_timer(&vif->disconnect_timer, disconnect_timer_handler,
  2936. (unsigned long) vif->ndev);
  2937. setup_timer(&vif->sched_scan_timer, ath6kl_wmi_sscan_timer,
  2938. (unsigned long) vif);
  2939. set_bit(WMM_ENABLED, &vif->flags);
  2940. spin_lock_init(&vif->if_lock);
  2941. INIT_LIST_HEAD(&vif->mc_filter);
  2942. return 0;
  2943. }
  2944. void ath6kl_cfg80211_vif_stop(struct ath6kl_vif *vif, bool wmi_ready)
  2945. {
  2946. static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  2947. bool discon_issued;
  2948. netif_stop_queue(vif->ndev);
  2949. clear_bit(WLAN_ENABLED, &vif->flags);
  2950. if (wmi_ready) {
  2951. discon_issued = test_bit(CONNECTED, &vif->flags) ||
  2952. test_bit(CONNECT_PEND, &vif->flags);
  2953. ath6kl_disconnect(vif);
  2954. del_timer(&vif->disconnect_timer);
  2955. if (discon_issued)
  2956. ath6kl_disconnect_event(vif, DISCONNECT_CMD,
  2957. (vif->nw_type & AP_NETWORK) ?
  2958. bcast_mac : vif->bssid,
  2959. 0, NULL, 0);
  2960. }
  2961. if (vif->scan_req) {
  2962. cfg80211_scan_done(vif->scan_req, true);
  2963. vif->scan_req = NULL;
  2964. }
  2965. /* need to clean up enhanced bmiss detection fw state */
  2966. ath6kl_cfg80211_sta_bmiss_enhance(vif, false);
  2967. }
  2968. void ath6kl_cfg80211_vif_cleanup(struct ath6kl_vif *vif)
  2969. {
  2970. struct ath6kl *ar = vif->ar;
  2971. struct ath6kl_mc_filter *mc_filter, *tmp;
  2972. aggr_module_destroy(vif->aggr_cntxt);
  2973. ar->avail_idx_map |= BIT(vif->fw_vif_idx);
  2974. if (vif->nw_type == ADHOC_NETWORK)
  2975. ar->ibss_if_active = false;
  2976. list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) {
  2977. list_del(&mc_filter->list);
  2978. kfree(mc_filter);
  2979. }
  2980. unregister_netdevice(vif->ndev);
  2981. ar->num_vif--;
  2982. }
  2983. struct wireless_dev *ath6kl_interface_add(struct ath6kl *ar, const char *name,
  2984. enum nl80211_iftype type,
  2985. u8 fw_vif_idx, u8 nw_type)
  2986. {
  2987. struct net_device *ndev;
  2988. struct ath6kl_vif *vif;
  2989. ndev = alloc_netdev(sizeof(*vif), name, ether_setup);
  2990. if (!ndev)
  2991. return NULL;
  2992. vif = netdev_priv(ndev);
  2993. ndev->ieee80211_ptr = &vif->wdev;
  2994. vif->wdev.wiphy = ar->wiphy;
  2995. vif->ar = ar;
  2996. vif->ndev = ndev;
  2997. SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy));
  2998. vif->wdev.netdev = ndev;
  2999. vif->wdev.iftype = type;
  3000. vif->fw_vif_idx = fw_vif_idx;
  3001. vif->nw_type = nw_type;
  3002. vif->next_mode = nw_type;
  3003. vif->listen_intvl_t = ATH6KL_DEFAULT_LISTEN_INTVAL;
  3004. vif->bmiss_time_t = ATH6KL_DEFAULT_BMISS_TIME;
  3005. vif->bg_scan_period = 0;
  3006. vif->htcap[IEEE80211_BAND_2GHZ].ht_enable = true;
  3007. vif->htcap[IEEE80211_BAND_5GHZ].ht_enable = true;
  3008. memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
  3009. if (fw_vif_idx != 0) {
  3010. ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << fw_vif_idx)) |
  3011. 0x2;
  3012. if (test_bit(ATH6KL_FW_CAPABILITY_CUSTOM_MAC_ADDR,
  3013. ar->fw_capabilities))
  3014. ndev->dev_addr[4] ^= 0x80;
  3015. }
  3016. init_netdev(ndev);
  3017. ath6kl_init_control_info(vif);
  3018. if (ath6kl_cfg80211_vif_init(vif))
  3019. goto err;
  3020. if (register_netdevice(ndev))
  3021. goto err;
  3022. ar->avail_idx_map &= ~BIT(fw_vif_idx);
  3023. vif->sme_state = SME_DISCONNECTED;
  3024. set_bit(WLAN_ENABLED, &vif->flags);
  3025. ar->wlan_pwr_state = WLAN_POWER_STATE_ON;
  3026. set_bit(NETDEV_REGISTERED, &vif->flags);
  3027. if (type == NL80211_IFTYPE_ADHOC)
  3028. ar->ibss_if_active = true;
  3029. spin_lock_bh(&ar->list_lock);
  3030. list_add_tail(&vif->list, &ar->vif_list);
  3031. spin_unlock_bh(&ar->list_lock);
  3032. return &vif->wdev;
  3033. err:
  3034. aggr_module_destroy(vif->aggr_cntxt);
  3035. free_netdev(ndev);
  3036. return NULL;
  3037. }
  3038. int ath6kl_cfg80211_init(struct ath6kl *ar)
  3039. {
  3040. struct wiphy *wiphy = ar->wiphy;
  3041. bool band_2gig = false, band_5gig = false, ht = false;
  3042. int ret;
  3043. wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
  3044. wiphy->max_remain_on_channel_duration = 5000;
  3045. /* set device pointer for wiphy */
  3046. set_wiphy_dev(wiphy, ar->dev);
  3047. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  3048. BIT(NL80211_IFTYPE_ADHOC) |
  3049. BIT(NL80211_IFTYPE_AP);
  3050. if (ar->p2p) {
  3051. wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) |
  3052. BIT(NL80211_IFTYPE_P2P_CLIENT);
  3053. }
  3054. if (config_enabled(CONFIG_ATH6KL_REGDOMAIN) &&
  3055. test_bit(ATH6KL_FW_CAPABILITY_REGDOMAIN, ar->fw_capabilities)) {
  3056. wiphy->reg_notifier = ath6kl_cfg80211_reg_notify;
  3057. ar->wiphy->features |= NL80211_FEATURE_CELL_BASE_REG_HINTS;
  3058. }
  3059. /* max num of ssids that can be probed during scanning */
  3060. wiphy->max_scan_ssids = MAX_PROBED_SSIDS;
  3061. /* max num of ssids that can be matched after scan */
  3062. if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN_MATCH_LIST,
  3063. ar->fw_capabilities))
  3064. wiphy->max_match_sets = MAX_PROBED_SSIDS;
  3065. wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
  3066. switch (ar->hw.cap) {
  3067. case WMI_11AN_CAP:
  3068. ht = true;
  3069. case WMI_11A_CAP:
  3070. band_5gig = true;
  3071. break;
  3072. case WMI_11GN_CAP:
  3073. ht = true;
  3074. case WMI_11G_CAP:
  3075. band_2gig = true;
  3076. break;
  3077. case WMI_11AGN_CAP:
  3078. ht = true;
  3079. case WMI_11AG_CAP:
  3080. band_2gig = true;
  3081. band_5gig = true;
  3082. break;
  3083. default:
  3084. ath6kl_err("invalid phy capability!\n");
  3085. return -EINVAL;
  3086. }
  3087. /*
  3088. * Even if the fw has HT support, advertise HT cap only when
  3089. * the firmware has support to override RSN capability, otherwise
  3090. * 4-way handshake would fail.
  3091. */
  3092. if (!(ht &&
  3093. test_bit(ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
  3094. ar->fw_capabilities))) {
  3095. ath6kl_band_2ghz.ht_cap.cap = 0;
  3096. ath6kl_band_2ghz.ht_cap.ht_supported = false;
  3097. ath6kl_band_5ghz.ht_cap.cap = 0;
  3098. ath6kl_band_5ghz.ht_cap.ht_supported = false;
  3099. }
  3100. if (ar->hw.flags & ATH6KL_HW_64BIT_RATES) {
  3101. ath6kl_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
  3102. ath6kl_band_5ghz.ht_cap.mcs.rx_mask[0] = 0xff;
  3103. ath6kl_band_2ghz.ht_cap.mcs.rx_mask[1] = 0xff;
  3104. ath6kl_band_5ghz.ht_cap.mcs.rx_mask[1] = 0xff;
  3105. } else {
  3106. ath6kl_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
  3107. ath6kl_band_5ghz.ht_cap.mcs.rx_mask[0] = 0xff;
  3108. }
  3109. if (band_2gig)
  3110. wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
  3111. if (band_5gig)
  3112. wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
  3113. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  3114. wiphy->cipher_suites = cipher_suites;
  3115. wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  3116. #ifdef CONFIG_PM
  3117. wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  3118. WIPHY_WOWLAN_DISCONNECT |
  3119. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  3120. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  3121. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  3122. WIPHY_WOWLAN_4WAY_HANDSHAKE;
  3123. wiphy->wowlan.n_patterns = WOW_MAX_FILTERS_PER_LIST;
  3124. wiphy->wowlan.pattern_min_len = 1;
  3125. wiphy->wowlan.pattern_max_len = WOW_PATTERN_SIZE;
  3126. #endif
  3127. wiphy->max_sched_scan_ssids = MAX_PROBED_SSIDS;
  3128. ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
  3129. WIPHY_FLAG_HAVE_AP_SME |
  3130. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  3131. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  3132. if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN_V2, ar->fw_capabilities))
  3133. ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
  3134. if (test_bit(ATH6KL_FW_CAPABILITY_INACTIVITY_TIMEOUT,
  3135. ar->fw_capabilities))
  3136. ar->wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
  3137. ar->wiphy->probe_resp_offload =
  3138. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  3139. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  3140. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  3141. ret = wiphy_register(wiphy);
  3142. if (ret < 0) {
  3143. ath6kl_err("couldn't register wiphy device\n");
  3144. return ret;
  3145. }
  3146. ar->wiphy_registered = true;
  3147. return 0;
  3148. }
  3149. void ath6kl_cfg80211_cleanup(struct ath6kl *ar)
  3150. {
  3151. wiphy_unregister(ar->wiphy);
  3152. ar->wiphy_registered = false;
  3153. }
  3154. struct ath6kl *ath6kl_cfg80211_create(void)
  3155. {
  3156. struct ath6kl *ar;
  3157. struct wiphy *wiphy;
  3158. /* create a new wiphy for use with cfg80211 */
  3159. wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
  3160. if (!wiphy) {
  3161. ath6kl_err("couldn't allocate wiphy device\n");
  3162. return NULL;
  3163. }
  3164. ar = wiphy_priv(wiphy);
  3165. ar->wiphy = wiphy;
  3166. return ar;
  3167. }
  3168. /* Note: ar variable must not be accessed after calling this! */
  3169. void ath6kl_cfg80211_destroy(struct ath6kl *ar)
  3170. {
  3171. int i;
  3172. for (i = 0; i < AP_MAX_NUM_STA; i++)
  3173. kfree(ar->sta_list[i].aggr_conn);
  3174. wiphy_free(ar->wiphy);
  3175. }