cfg80211.c 87 KB

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