cfg80211.c 81 KB

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