cfg80211.c 95 KB

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