cfg80211.c 92 KB

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