cfg80211.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "core.h"
  17. #include "cfg80211.h"
  18. #include "debug.h"
  19. #include "hif-ops.h"
  20. #include "testmode.h"
  21. static unsigned int ath6kl_p2p;
  22. static unsigned int multi_norm_if_support;
  23. module_param(ath6kl_p2p, uint, 0644);
  24. module_param(multi_norm_if_support, uint, 0644);
  25. #define RATETAB_ENT(_rate, _rateid, _flags) { \
  26. .bitrate = (_rate), \
  27. .flags = (_flags), \
  28. .hw_value = (_rateid), \
  29. }
  30. #define CHAN2G(_channel, _freq, _flags) { \
  31. .band = IEEE80211_BAND_2GHZ, \
  32. .hw_value = (_channel), \
  33. .center_freq = (_freq), \
  34. .flags = (_flags), \
  35. .max_antenna_gain = 0, \
  36. .max_power = 30, \
  37. }
  38. #define CHAN5G(_channel, _flags) { \
  39. .band = IEEE80211_BAND_5GHZ, \
  40. .hw_value = (_channel), \
  41. .center_freq = 5000 + (5 * (_channel)), \
  42. .flags = (_flags), \
  43. .max_antenna_gain = 0, \
  44. .max_power = 30, \
  45. }
  46. static struct ieee80211_rate ath6kl_rates[] = {
  47. RATETAB_ENT(10, 0x1, 0),
  48. RATETAB_ENT(20, 0x2, 0),
  49. RATETAB_ENT(55, 0x4, 0),
  50. RATETAB_ENT(110, 0x8, 0),
  51. RATETAB_ENT(60, 0x10, 0),
  52. RATETAB_ENT(90, 0x20, 0),
  53. RATETAB_ENT(120, 0x40, 0),
  54. RATETAB_ENT(180, 0x80, 0),
  55. RATETAB_ENT(240, 0x100, 0),
  56. RATETAB_ENT(360, 0x200, 0),
  57. RATETAB_ENT(480, 0x400, 0),
  58. RATETAB_ENT(540, 0x800, 0),
  59. };
  60. #define ath6kl_a_rates (ath6kl_rates + 4)
  61. #define ath6kl_a_rates_size 8
  62. #define ath6kl_g_rates (ath6kl_rates + 0)
  63. #define ath6kl_g_rates_size 12
  64. static struct ieee80211_channel ath6kl_2ghz_channels[] = {
  65. CHAN2G(1, 2412, 0),
  66. CHAN2G(2, 2417, 0),
  67. CHAN2G(3, 2422, 0),
  68. CHAN2G(4, 2427, 0),
  69. CHAN2G(5, 2432, 0),
  70. CHAN2G(6, 2437, 0),
  71. CHAN2G(7, 2442, 0),
  72. CHAN2G(8, 2447, 0),
  73. CHAN2G(9, 2452, 0),
  74. CHAN2G(10, 2457, 0),
  75. CHAN2G(11, 2462, 0),
  76. CHAN2G(12, 2467, 0),
  77. CHAN2G(13, 2472, 0),
  78. CHAN2G(14, 2484, 0),
  79. };
  80. static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
  81. CHAN5G(34, 0), CHAN5G(36, 0),
  82. CHAN5G(38, 0), CHAN5G(40, 0),
  83. CHAN5G(42, 0), CHAN5G(44, 0),
  84. CHAN5G(46, 0), CHAN5G(48, 0),
  85. CHAN5G(52, 0), CHAN5G(56, 0),
  86. CHAN5G(60, 0), CHAN5G(64, 0),
  87. CHAN5G(100, 0), CHAN5G(104, 0),
  88. CHAN5G(108, 0), CHAN5G(112, 0),
  89. CHAN5G(116, 0), CHAN5G(120, 0),
  90. CHAN5G(124, 0), CHAN5G(128, 0),
  91. CHAN5G(132, 0), CHAN5G(136, 0),
  92. CHAN5G(140, 0), CHAN5G(149, 0),
  93. CHAN5G(153, 0), CHAN5G(157, 0),
  94. CHAN5G(161, 0), CHAN5G(165, 0),
  95. CHAN5G(184, 0), CHAN5G(188, 0),
  96. CHAN5G(192, 0), CHAN5G(196, 0),
  97. CHAN5G(200, 0), CHAN5G(204, 0),
  98. CHAN5G(208, 0), CHAN5G(212, 0),
  99. CHAN5G(216, 0),
  100. };
  101. static struct ieee80211_supported_band ath6kl_band_2ghz = {
  102. .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
  103. .channels = ath6kl_2ghz_channels,
  104. .n_bitrates = ath6kl_g_rates_size,
  105. .bitrates = ath6kl_g_rates,
  106. };
  107. static struct ieee80211_supported_band ath6kl_band_5ghz = {
  108. .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
  109. .channels = ath6kl_5ghz_a_channels,
  110. .n_bitrates = ath6kl_a_rates_size,
  111. .bitrates = ath6kl_a_rates,
  112. };
  113. #define CCKM_KRK_CIPHER_SUITE 0x004096ff /* use for KRK */
  114. static int ath6kl_set_wpa_version(struct ath6kl_vif *vif,
  115. enum nl80211_wpa_versions wpa_version)
  116. {
  117. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);
  118. if (!wpa_version) {
  119. vif->auth_mode = NONE_AUTH;
  120. } else if (wpa_version & NL80211_WPA_VERSION_2) {
  121. vif->auth_mode = WPA2_AUTH;
  122. } else if (wpa_version & NL80211_WPA_VERSION_1) {
  123. vif->auth_mode = WPA_AUTH;
  124. } else {
  125. ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
  126. return -ENOTSUPP;
  127. }
  128. return 0;
  129. }
  130. static int ath6kl_set_auth_type(struct ath6kl_vif *vif,
  131. enum nl80211_auth_type auth_type)
  132. {
  133. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
  134. switch (auth_type) {
  135. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  136. vif->dot11_auth_mode = OPEN_AUTH;
  137. break;
  138. case NL80211_AUTHTYPE_SHARED_KEY:
  139. vif->dot11_auth_mode = SHARED_AUTH;
  140. break;
  141. case NL80211_AUTHTYPE_NETWORK_EAP:
  142. vif->dot11_auth_mode = LEAP_AUTH;
  143. break;
  144. case NL80211_AUTHTYPE_AUTOMATIC:
  145. vif->dot11_auth_mode = OPEN_AUTH | SHARED_AUTH;
  146. break;
  147. default:
  148. ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type);
  149. return -ENOTSUPP;
  150. }
  151. return 0;
  152. }
  153. static int ath6kl_set_cipher(struct ath6kl_vif *vif, u32 cipher, bool ucast)
  154. {
  155. u8 *ar_cipher = ucast ? &vif->prwise_crypto : &vif->grp_crypto;
  156. u8 *ar_cipher_len = ucast ? &vif->prwise_crypto_len :
  157. &vif->grp_crypto_len;
  158. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
  159. __func__, cipher, ucast);
  160. switch (cipher) {
  161. case 0:
  162. /* our own hack to use value 0 as no crypto used */
  163. *ar_cipher = NONE_CRYPT;
  164. *ar_cipher_len = 0;
  165. break;
  166. case WLAN_CIPHER_SUITE_WEP40:
  167. *ar_cipher = WEP_CRYPT;
  168. *ar_cipher_len = 5;
  169. break;
  170. case WLAN_CIPHER_SUITE_WEP104:
  171. *ar_cipher = WEP_CRYPT;
  172. *ar_cipher_len = 13;
  173. break;
  174. case WLAN_CIPHER_SUITE_TKIP:
  175. *ar_cipher = TKIP_CRYPT;
  176. *ar_cipher_len = 0;
  177. break;
  178. case WLAN_CIPHER_SUITE_CCMP:
  179. *ar_cipher = AES_CRYPT;
  180. *ar_cipher_len = 0;
  181. break;
  182. default:
  183. ath6kl_err("cipher 0x%x not supported\n", cipher);
  184. return -ENOTSUPP;
  185. }
  186. return 0;
  187. }
  188. static void ath6kl_set_key_mgmt(struct ath6kl_vif *vif, u32 key_mgmt)
  189. {
  190. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
  191. if (key_mgmt == WLAN_AKM_SUITE_PSK) {
  192. if (vif->auth_mode == WPA_AUTH)
  193. vif->auth_mode = WPA_PSK_AUTH;
  194. else if (vif->auth_mode == WPA2_AUTH)
  195. vif->auth_mode = WPA2_PSK_AUTH;
  196. } else if (key_mgmt == 0x00409600) {
  197. if (vif->auth_mode == WPA_AUTH)
  198. vif->auth_mode = WPA_AUTH_CCKM;
  199. else if (vif->auth_mode == WPA2_AUTH)
  200. vif->auth_mode = WPA2_AUTH_CCKM;
  201. } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
  202. vif->auth_mode = NONE_AUTH;
  203. }
  204. }
  205. static bool ath6kl_cfg80211_ready(struct ath6kl_vif *vif)
  206. {
  207. struct ath6kl *ar = vif->ar;
  208. if (!test_bit(WMI_READY, &ar->flag)) {
  209. ath6kl_err("wmi is not ready\n");
  210. return false;
  211. }
  212. if (!test_bit(WLAN_ENABLED, &vif->flags)) {
  213. ath6kl_err("wlan disabled\n");
  214. return false;
  215. }
  216. return true;
  217. }
  218. static bool ath6kl_is_wpa_ie(const u8 *pos)
  219. {
  220. return pos[0] == WLAN_EID_WPA && pos[1] >= 4 &&
  221. pos[2] == 0x00 && pos[3] == 0x50 &&
  222. pos[4] == 0xf2 && pos[5] == 0x01;
  223. }
  224. static bool ath6kl_is_rsn_ie(const u8 *pos)
  225. {
  226. return pos[0] == WLAN_EID_RSN;
  227. }
  228. static bool ath6kl_is_wps_ie(const u8 *pos)
  229. {
  230. return (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  231. pos[1] >= 4 &&
  232. pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2 &&
  233. pos[5] == 0x04);
  234. }
  235. static int ath6kl_set_assoc_req_ies(struct ath6kl_vif *vif, const u8 *ies,
  236. size_t ies_len)
  237. {
  238. struct ath6kl *ar = vif->ar;
  239. const u8 *pos;
  240. u8 *buf = NULL;
  241. size_t len = 0;
  242. int ret;
  243. /*
  244. * Clear previously set flag
  245. */
  246. ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG;
  247. /*
  248. * Filter out RSN/WPA IE(s)
  249. */
  250. if (ies && ies_len) {
  251. buf = kmalloc(ies_len, GFP_KERNEL);
  252. if (buf == NULL)
  253. return -ENOMEM;
  254. pos = ies;
  255. while (pos + 1 < ies + ies_len) {
  256. if (pos + 2 + pos[1] > ies + ies_len)
  257. break;
  258. if (!(ath6kl_is_wpa_ie(pos) || ath6kl_is_rsn_ie(pos))) {
  259. memcpy(buf + len, pos, 2 + pos[1]);
  260. len += 2 + pos[1];
  261. }
  262. if (ath6kl_is_wps_ie(pos))
  263. ar->connect_ctrl_flags |= CONNECT_WPS_FLAG;
  264. pos += 2 + pos[1];
  265. }
  266. }
  267. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  268. WMI_FRAME_ASSOC_REQ, buf, len);
  269. kfree(buf);
  270. return ret;
  271. }
  272. static int ath6kl_nliftype_to_drv_iftype(enum nl80211_iftype type, u8 *nw_type)
  273. {
  274. switch (type) {
  275. case NL80211_IFTYPE_STATION:
  276. *nw_type = INFRA_NETWORK;
  277. break;
  278. case NL80211_IFTYPE_ADHOC:
  279. *nw_type = ADHOC_NETWORK;
  280. break;
  281. case NL80211_IFTYPE_AP:
  282. *nw_type = AP_NETWORK;
  283. break;
  284. case NL80211_IFTYPE_P2P_CLIENT:
  285. *nw_type = INFRA_NETWORK;
  286. break;
  287. case NL80211_IFTYPE_P2P_GO:
  288. *nw_type = AP_NETWORK;
  289. break;
  290. default:
  291. ath6kl_err("invalid interface type %u\n", type);
  292. return -ENOTSUPP;
  293. }
  294. return 0;
  295. }
  296. static bool ath6kl_is_valid_iftype(struct ath6kl *ar, enum nl80211_iftype type,
  297. u8 *if_idx, u8 *nw_type)
  298. {
  299. int i;
  300. if (ath6kl_nliftype_to_drv_iftype(type, nw_type))
  301. return false;
  302. if (ar->ibss_if_active || ((type == NL80211_IFTYPE_ADHOC) &&
  303. ar->num_vif))
  304. return false;
  305. if (type == NL80211_IFTYPE_STATION ||
  306. type == NL80211_IFTYPE_AP || type == NL80211_IFTYPE_ADHOC) {
  307. for (i = 0; i < MAX_NUM_VIF; i++) {
  308. if ((ar->avail_idx_map >> i) & BIT(0)) {
  309. *if_idx = i;
  310. return true;
  311. }
  312. }
  313. }
  314. if (type == NL80211_IFTYPE_P2P_CLIENT ||
  315. type == NL80211_IFTYPE_P2P_GO) {
  316. for (i = ar->max_norm_iface; i < MAX_NUM_VIF; i++) {
  317. if ((ar->avail_idx_map >> i) & BIT(0)) {
  318. *if_idx = i;
  319. return true;
  320. }
  321. }
  322. }
  323. return false;
  324. }
  325. static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  326. struct cfg80211_connect_params *sme)
  327. {
  328. struct ath6kl *ar = ath6kl_priv(dev);
  329. struct ath6kl_vif *vif = netdev_priv(dev);
  330. int status;
  331. vif->sme_state = SME_CONNECTING;
  332. if (!ath6kl_cfg80211_ready(vif))
  333. return -EIO;
  334. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  335. ath6kl_err("destroy in progress\n");
  336. return -EBUSY;
  337. }
  338. if (test_bit(SKIP_SCAN, &ar->flag) &&
  339. ((sme->channel && sme->channel->center_freq == 0) ||
  340. (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
  341. ath6kl_err("SkipScan: channel or bssid invalid\n");
  342. return -EINVAL;
  343. }
  344. if (down_interruptible(&ar->sem)) {
  345. ath6kl_err("busy, couldn't get access\n");
  346. return -ERESTARTSYS;
  347. }
  348. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  349. ath6kl_err("busy, destroy in progress\n");
  350. up(&ar->sem);
  351. return -EBUSY;
  352. }
  353. if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
  354. /*
  355. * sleep until the command queue drains
  356. */
  357. wait_event_interruptible_timeout(ar->event_wq,
  358. ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
  359. WMI_TIMEOUT);
  360. if (signal_pending(current)) {
  361. ath6kl_err("cmd queue drain timeout\n");
  362. up(&ar->sem);
  363. return -EINTR;
  364. }
  365. }
  366. if (sme->ie && (sme->ie_len > 0)) {
  367. status = ath6kl_set_assoc_req_ies(vif, sme->ie, sme->ie_len);
  368. if (status)
  369. return status;
  370. }
  371. if (test_bit(CONNECTED, &vif->flags) &&
  372. vif->ssid_len == sme->ssid_len &&
  373. !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
  374. vif->reconnect_flag = true;
  375. status = ath6kl_wmi_reconnect_cmd(ar->wmi, vif->fw_vif_idx,
  376. vif->req_bssid,
  377. vif->ch_hint);
  378. up(&ar->sem);
  379. if (status) {
  380. ath6kl_err("wmi_reconnect_cmd failed\n");
  381. return -EIO;
  382. }
  383. return 0;
  384. } else if (vif->ssid_len == sme->ssid_len &&
  385. !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
  386. ath6kl_disconnect(vif);
  387. }
  388. memset(vif->ssid, 0, sizeof(vif->ssid));
  389. vif->ssid_len = sme->ssid_len;
  390. memcpy(vif->ssid, sme->ssid, sme->ssid_len);
  391. if (sme->channel)
  392. vif->ch_hint = sme->channel->center_freq;
  393. memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
  394. if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
  395. memcpy(vif->req_bssid, sme->bssid, sizeof(vif->req_bssid));
  396. ath6kl_set_wpa_version(vif, sme->crypto.wpa_versions);
  397. status = ath6kl_set_auth_type(vif, sme->auth_type);
  398. if (status) {
  399. up(&ar->sem);
  400. return status;
  401. }
  402. if (sme->crypto.n_ciphers_pairwise)
  403. ath6kl_set_cipher(vif, sme->crypto.ciphers_pairwise[0], true);
  404. else
  405. ath6kl_set_cipher(vif, 0, true);
  406. ath6kl_set_cipher(vif, sme->crypto.cipher_group, false);
  407. if (sme->crypto.n_akm_suites)
  408. ath6kl_set_key_mgmt(vif, sme->crypto.akm_suites[0]);
  409. if ((sme->key_len) &&
  410. (vif->auth_mode == NONE_AUTH) &&
  411. (vif->prwise_crypto == WEP_CRYPT)) {
  412. struct ath6kl_key *key = NULL;
  413. if (sme->key_idx < WMI_MIN_KEY_INDEX ||
  414. sme->key_idx > WMI_MAX_KEY_INDEX) {
  415. ath6kl_err("key index %d out of bounds\n",
  416. sme->key_idx);
  417. up(&ar->sem);
  418. return -ENOENT;
  419. }
  420. key = &vif->keys[sme->key_idx];
  421. key->key_len = sme->key_len;
  422. memcpy(key->key, sme->key, key->key_len);
  423. key->cipher = vif->prwise_crypto;
  424. vif->def_txkey_index = sme->key_idx;
  425. ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, sme->key_idx,
  426. vif->prwise_crypto,
  427. GROUP_USAGE | TX_USAGE,
  428. key->key_len,
  429. NULL, 0,
  430. key->key, KEY_OP_INIT_VAL, NULL,
  431. NO_SYNC_WMIFLAG);
  432. }
  433. if (!ar->usr_bss_filter) {
  434. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  435. if (ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  436. ALL_BSS_FILTER, 0) != 0) {
  437. ath6kl_err("couldn't set bss filtering\n");
  438. up(&ar->sem);
  439. return -EIO;
  440. }
  441. }
  442. vif->nw_type = vif->next_mode;
  443. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  444. "%s: connect called with authmode %d dot11 auth %d"
  445. " PW crypto %d PW crypto len %d GRP crypto %d"
  446. " GRP crypto len %d channel hint %u\n",
  447. __func__,
  448. vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
  449. vif->prwise_crypto_len, vif->grp_crypto,
  450. vif->grp_crypto_len, vif->ch_hint);
  451. vif->reconnect_flag = 0;
  452. status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
  453. vif->dot11_auth_mode, vif->auth_mode,
  454. vif->prwise_crypto,
  455. vif->prwise_crypto_len,
  456. vif->grp_crypto, vif->grp_crypto_len,
  457. vif->ssid_len, vif->ssid,
  458. vif->req_bssid, vif->ch_hint,
  459. ar->connect_ctrl_flags);
  460. up(&ar->sem);
  461. if (status == -EINVAL) {
  462. memset(vif->ssid, 0, sizeof(vif->ssid));
  463. vif->ssid_len = 0;
  464. ath6kl_err("invalid request\n");
  465. return -ENOENT;
  466. } else if (status) {
  467. ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
  468. return -EIO;
  469. }
  470. if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
  471. ((vif->auth_mode == WPA_PSK_AUTH)
  472. || (vif->auth_mode == WPA2_PSK_AUTH))) {
  473. mod_timer(&vif->disconnect_timer,
  474. jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
  475. }
  476. ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
  477. set_bit(CONNECT_PEND, &vif->flags);
  478. return 0;
  479. }
  480. static int ath6kl_add_bss_if_needed(struct ath6kl_vif *vif, const u8 *bssid,
  481. struct ieee80211_channel *chan,
  482. const u8 *beacon_ie, size_t beacon_ie_len)
  483. {
  484. struct ath6kl *ar = vif->ar;
  485. struct cfg80211_bss *bss;
  486. u8 *ie;
  487. bss = cfg80211_get_bss(ar->wiphy, chan, bssid,
  488. vif->ssid, vif->ssid_len, WLAN_CAPABILITY_ESS,
  489. WLAN_CAPABILITY_ESS);
  490. if (bss == NULL) {
  491. /*
  492. * Since cfg80211 may not yet know about the BSS,
  493. * generate a partial entry until the first BSS info
  494. * event becomes available.
  495. *
  496. * Prepend SSID element since it is not included in the Beacon
  497. * IEs from the target.
  498. */
  499. ie = kmalloc(2 + vif->ssid_len + beacon_ie_len, GFP_KERNEL);
  500. if (ie == NULL)
  501. return -ENOMEM;
  502. ie[0] = WLAN_EID_SSID;
  503. ie[1] = vif->ssid_len;
  504. memcpy(ie + 2, vif->ssid, vif->ssid_len);
  505. memcpy(ie + 2 + vif->ssid_len, beacon_ie, beacon_ie_len);
  506. bss = cfg80211_inform_bss(ar->wiphy, chan,
  507. bssid, 0, WLAN_CAPABILITY_ESS, 100,
  508. ie, 2 + vif->ssid_len + beacon_ie_len,
  509. 0, GFP_KERNEL);
  510. if (bss)
  511. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "added dummy bss for "
  512. "%pM prior to indicating connect/roamed "
  513. "event\n", bssid);
  514. kfree(ie);
  515. } else
  516. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "cfg80211 already has a bss "
  517. "entry\n");
  518. if (bss == NULL)
  519. return -ENOMEM;
  520. cfg80211_put_bss(bss);
  521. return 0;
  522. }
  523. void ath6kl_cfg80211_connect_event(struct ath6kl_vif *vif, u16 channel,
  524. u8 *bssid, u16 listen_intvl,
  525. u16 beacon_intvl,
  526. enum network_type nw_type,
  527. u8 beacon_ie_len, u8 assoc_req_len,
  528. u8 assoc_resp_len, u8 *assoc_info)
  529. {
  530. struct ieee80211_channel *chan;
  531. struct ath6kl *ar = vif->ar;
  532. /* capinfo + listen interval */
  533. u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
  534. /* capinfo + status code + associd */
  535. u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
  536. u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
  537. u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
  538. assoc_resp_ie_offset;
  539. assoc_req_len -= assoc_req_ie_offset;
  540. assoc_resp_len -= assoc_resp_ie_offset;
  541. /*
  542. * Store Beacon interval here; DTIM period will be available only once
  543. * a Beacon frame from the AP is seen.
  544. */
  545. vif->assoc_bss_beacon_int = beacon_intvl;
  546. clear_bit(DTIM_PERIOD_AVAIL, &vif->flags);
  547. if (nw_type & ADHOC_NETWORK) {
  548. if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
  549. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  550. "%s: ath6k not in ibss mode\n", __func__);
  551. return;
  552. }
  553. }
  554. if (nw_type & INFRA_NETWORK) {
  555. if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
  556. vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
  557. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  558. "%s: ath6k not in station mode\n", __func__);
  559. return;
  560. }
  561. }
  562. chan = ieee80211_get_channel(ar->wiphy, (int) channel);
  563. if (nw_type & ADHOC_NETWORK) {
  564. cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
  565. return;
  566. }
  567. if (ath6kl_add_bss_if_needed(vif, bssid, chan, assoc_info,
  568. beacon_ie_len) < 0) {
  569. ath6kl_err("could not add cfg80211 bss entry for "
  570. "connect/roamed notification\n");
  571. return;
  572. }
  573. if (vif->sme_state == SME_CONNECTING) {
  574. /* inform connect result to cfg80211 */
  575. vif->sme_state = SME_CONNECTED;
  576. cfg80211_connect_result(vif->ndev, bssid,
  577. assoc_req_ie, assoc_req_len,
  578. assoc_resp_ie, assoc_resp_len,
  579. WLAN_STATUS_SUCCESS, GFP_KERNEL);
  580. } else if (vif->sme_state == SME_CONNECTED) {
  581. /* inform roam event to cfg80211 */
  582. cfg80211_roamed(vif->ndev, chan, bssid,
  583. assoc_req_ie, assoc_req_len,
  584. assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
  585. }
  586. }
  587. static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
  588. struct net_device *dev, u16 reason_code)
  589. {
  590. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
  591. struct ath6kl_vif *vif = netdev_priv(dev);
  592. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
  593. reason_code);
  594. if (!ath6kl_cfg80211_ready(vif))
  595. return -EIO;
  596. if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
  597. ath6kl_err("busy, destroy in progress\n");
  598. return -EBUSY;
  599. }
  600. if (down_interruptible(&ar->sem)) {
  601. ath6kl_err("busy, couldn't get access\n");
  602. return -ERESTARTSYS;
  603. }
  604. vif->reconnect_flag = 0;
  605. ath6kl_disconnect(vif);
  606. memset(vif->ssid, 0, sizeof(vif->ssid));
  607. vif->ssid_len = 0;
  608. if (!test_bit(SKIP_SCAN, &ar->flag))
  609. memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
  610. up(&ar->sem);
  611. vif->sme_state = SME_DISCONNECTED;
  612. return 0;
  613. }
  614. void ath6kl_cfg80211_disconnect_event(struct ath6kl_vif *vif, u8 reason,
  615. u8 *bssid, u8 assoc_resp_len,
  616. u8 *assoc_info, u16 proto_reason)
  617. {
  618. struct ath6kl *ar = vif->ar;
  619. if (vif->scan_req) {
  620. cfg80211_scan_done(vif->scan_req, true);
  621. vif->scan_req = NULL;
  622. }
  623. if (vif->nw_type & ADHOC_NETWORK) {
  624. if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
  625. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  626. "%s: ath6k not in ibss mode\n", __func__);
  627. return;
  628. }
  629. memset(bssid, 0, ETH_ALEN);
  630. cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
  631. return;
  632. }
  633. if (vif->nw_type & INFRA_NETWORK) {
  634. if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
  635. vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
  636. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  637. "%s: ath6k not in station mode\n", __func__);
  638. return;
  639. }
  640. }
  641. /*
  642. * Send a disconnect command to target when a disconnect event is
  643. * received with reason code other than 3 (DISCONNECT_CMD - disconnect
  644. * request from host) to make the firmware stop trying to connect even
  645. * after giving disconnect event. There will be one more disconnect
  646. * event for this disconnect command with reason code DISCONNECT_CMD
  647. * which will be notified to cfg80211.
  648. */
  649. if (reason != DISCONNECT_CMD) {
  650. ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
  651. return;
  652. }
  653. clear_bit(CONNECT_PEND, &vif->flags);
  654. if (vif->sme_state == SME_CONNECTING) {
  655. cfg80211_connect_result(vif->ndev,
  656. bssid, NULL, 0,
  657. NULL, 0,
  658. WLAN_STATUS_UNSPECIFIED_FAILURE,
  659. GFP_KERNEL);
  660. } else if (vif->sme_state == SME_CONNECTED) {
  661. cfg80211_disconnected(vif->ndev, reason,
  662. NULL, 0, GFP_KERNEL);
  663. }
  664. vif->sme_state = SME_DISCONNECTED;
  665. }
  666. static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
  667. struct cfg80211_scan_request *request)
  668. {
  669. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  670. struct ath6kl_vif *vif = netdev_priv(ndev);
  671. s8 n_channels = 0;
  672. u16 *channels = NULL;
  673. int ret = 0;
  674. u32 force_fg_scan = 0;
  675. if (!ath6kl_cfg80211_ready(vif))
  676. return -EIO;
  677. if (!ar->usr_bss_filter) {
  678. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  679. ret = ath6kl_wmi_bssfilter_cmd(
  680. ar->wmi, vif->fw_vif_idx,
  681. (test_bit(CONNECTED, &vif->flags) ?
  682. ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), 0);
  683. if (ret) {
  684. ath6kl_err("couldn't set bss filtering\n");
  685. return ret;
  686. }
  687. }
  688. if (request->n_ssids && request->ssids[0].ssid_len) {
  689. u8 i;
  690. if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
  691. request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
  692. for (i = 0; i < request->n_ssids; i++)
  693. ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
  694. i + 1, SPECIFIC_SSID_FLAG,
  695. request->ssids[i].ssid_len,
  696. request->ssids[i].ssid);
  697. }
  698. if (request->ie) {
  699. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  700. WMI_FRAME_PROBE_REQ,
  701. request->ie, request->ie_len);
  702. if (ret) {
  703. ath6kl_err("failed to set Probe Request appie for "
  704. "scan");
  705. return ret;
  706. }
  707. }
  708. /*
  709. * Scan only the requested channels if the request specifies a set of
  710. * channels. If the list is longer than the target supports, do not
  711. * configure the list and instead, scan all available channels.
  712. */
  713. if (request->n_channels > 0 &&
  714. request->n_channels <= WMI_MAX_CHANNELS) {
  715. u8 i;
  716. n_channels = request->n_channels;
  717. channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
  718. if (channels == NULL) {
  719. ath6kl_warn("failed to set scan channels, "
  720. "scan all channels");
  721. n_channels = 0;
  722. }
  723. for (i = 0; i < n_channels; i++)
  724. channels[i] = request->channels[i]->center_freq;
  725. }
  726. if (test_bit(CONNECTED, &vif->flags))
  727. force_fg_scan = 1;
  728. ret = ath6kl_wmi_startscan_cmd(ar->wmi, vif->fw_vif_idx, WMI_LONG_SCAN,
  729. force_fg_scan, false, 0, 0, n_channels,
  730. channels);
  731. if (ret)
  732. ath6kl_err("wmi_startscan_cmd failed\n");
  733. else
  734. vif->scan_req = request;
  735. kfree(channels);
  736. return ret;
  737. }
  738. void ath6kl_cfg80211_scan_complete_event(struct ath6kl_vif *vif, bool aborted)
  739. {
  740. struct ath6kl *ar = vif->ar;
  741. int i;
  742. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status%s\n", __func__,
  743. aborted ? " aborted" : "");
  744. if (!vif->scan_req)
  745. return;
  746. if (aborted)
  747. goto out;
  748. if (vif->scan_req->n_ssids && vif->scan_req->ssids[0].ssid_len) {
  749. for (i = 0; i < vif->scan_req->n_ssids; i++) {
  750. ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
  751. i + 1, DISABLE_SSID_FLAG,
  752. 0, NULL);
  753. }
  754. }
  755. out:
  756. cfg80211_scan_done(vif->scan_req, aborted);
  757. vif->scan_req = NULL;
  758. }
  759. static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
  760. u8 key_index, bool pairwise,
  761. const u8 *mac_addr,
  762. struct key_params *params)
  763. {
  764. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  765. struct ath6kl_vif *vif = netdev_priv(ndev);
  766. struct ath6kl_key *key = NULL;
  767. u8 key_usage;
  768. u8 key_type;
  769. if (!ath6kl_cfg80211_ready(vif))
  770. return -EIO;
  771. if (params->cipher == CCKM_KRK_CIPHER_SUITE) {
  772. if (params->key_len != WMI_KRK_LEN)
  773. return -EINVAL;
  774. return ath6kl_wmi_add_krk_cmd(ar->wmi, vif->fw_vif_idx,
  775. params->key);
  776. }
  777. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  778. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  779. "%s: key index %d out of bounds\n", __func__,
  780. key_index);
  781. return -ENOENT;
  782. }
  783. key = &vif->keys[key_index];
  784. memset(key, 0, sizeof(struct ath6kl_key));
  785. if (pairwise)
  786. key_usage = PAIRWISE_USAGE;
  787. else
  788. key_usage = GROUP_USAGE;
  789. if (params) {
  790. if (params->key_len > WLAN_MAX_KEY_LEN ||
  791. params->seq_len > sizeof(key->seq))
  792. return -EINVAL;
  793. key->key_len = params->key_len;
  794. memcpy(key->key, params->key, key->key_len);
  795. key->seq_len = params->seq_len;
  796. memcpy(key->seq, params->seq, key->seq_len);
  797. key->cipher = params->cipher;
  798. }
  799. switch (key->cipher) {
  800. case WLAN_CIPHER_SUITE_WEP40:
  801. case WLAN_CIPHER_SUITE_WEP104:
  802. key_type = WEP_CRYPT;
  803. break;
  804. case WLAN_CIPHER_SUITE_TKIP:
  805. key_type = TKIP_CRYPT;
  806. break;
  807. case WLAN_CIPHER_SUITE_CCMP:
  808. key_type = AES_CRYPT;
  809. break;
  810. default:
  811. return -ENOTSUPP;
  812. }
  813. if (((vif->auth_mode == WPA_PSK_AUTH)
  814. || (vif->auth_mode == WPA2_PSK_AUTH))
  815. && (key_usage & GROUP_USAGE))
  816. del_timer(&vif->disconnect_timer);
  817. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  818. "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
  819. __func__, key_index, key->key_len, key_type,
  820. key_usage, key->seq_len);
  821. vif->def_txkey_index = key_index;
  822. if (vif->nw_type == AP_NETWORK && !pairwise &&
  823. (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
  824. ar->ap_mode_bkey.valid = true;
  825. ar->ap_mode_bkey.key_index = key_index;
  826. ar->ap_mode_bkey.key_type = key_type;
  827. ar->ap_mode_bkey.key_len = key->key_len;
  828. memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
  829. if (!test_bit(CONNECTED, &vif->flags)) {
  830. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
  831. "key configuration until AP mode has been "
  832. "started\n");
  833. /*
  834. * The key will be set in ath6kl_connect_ap_mode() once
  835. * the connected event is received from the target.
  836. */
  837. return 0;
  838. }
  839. }
  840. if (vif->next_mode == AP_NETWORK && key_type == WEP_CRYPT &&
  841. !test_bit(CONNECTED, &vif->flags)) {
  842. /*
  843. * Store the key locally so that it can be re-configured after
  844. * the AP mode has properly started
  845. * (ath6kl_install_statioc_wep_keys).
  846. */
  847. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay WEP key configuration "
  848. "until AP mode has been started\n");
  849. vif->wep_key_list[key_index].key_len = key->key_len;
  850. memcpy(vif->wep_key_list[key_index].key, key->key,
  851. key->key_len);
  852. return 0;
  853. }
  854. return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx,
  855. vif->def_txkey_index,
  856. key_type, key_usage, key->key_len,
  857. key->seq, key->seq_len, key->key,
  858. KEY_OP_INIT_VAL,
  859. (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
  860. }
  861. static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  862. u8 key_index, bool pairwise,
  863. const u8 *mac_addr)
  864. {
  865. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  866. struct ath6kl_vif *vif = netdev_priv(ndev);
  867. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  868. if (!ath6kl_cfg80211_ready(vif))
  869. return -EIO;
  870. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  871. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  872. "%s: key index %d out of bounds\n", __func__,
  873. key_index);
  874. return -ENOENT;
  875. }
  876. if (!vif->keys[key_index].key_len) {
  877. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  878. "%s: index %d is empty\n", __func__, key_index);
  879. return 0;
  880. }
  881. vif->keys[key_index].key_len = 0;
  882. return ath6kl_wmi_deletekey_cmd(ar->wmi, vif->fw_vif_idx, key_index);
  883. }
  884. static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
  885. u8 key_index, bool pairwise,
  886. const u8 *mac_addr, void *cookie,
  887. void (*callback) (void *cookie,
  888. struct key_params *))
  889. {
  890. struct ath6kl_vif *vif = netdev_priv(ndev);
  891. struct ath6kl_key *key = NULL;
  892. struct key_params params;
  893. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  894. if (!ath6kl_cfg80211_ready(vif))
  895. return -EIO;
  896. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  897. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  898. "%s: key index %d out of bounds\n", __func__,
  899. key_index);
  900. return -ENOENT;
  901. }
  902. key = &vif->keys[key_index];
  903. memset(&params, 0, sizeof(params));
  904. params.cipher = key->cipher;
  905. params.key_len = key->key_len;
  906. params.seq_len = key->seq_len;
  907. params.seq = key->seq;
  908. params.key = key->key;
  909. callback(cookie, &params);
  910. return key->key_len ? 0 : -ENOENT;
  911. }
  912. static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
  913. struct net_device *ndev,
  914. u8 key_index, bool unicast,
  915. bool multicast)
  916. {
  917. struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
  918. struct ath6kl_vif *vif = netdev_priv(ndev);
  919. struct ath6kl_key *key = NULL;
  920. u8 key_usage;
  921. enum crypto_type key_type = NONE_CRYPT;
  922. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
  923. if (!ath6kl_cfg80211_ready(vif))
  924. return -EIO;
  925. if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
  926. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  927. "%s: key index %d out of bounds\n",
  928. __func__, key_index);
  929. return -ENOENT;
  930. }
  931. if (!vif->keys[key_index].key_len) {
  932. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
  933. __func__, key_index);
  934. return -EINVAL;
  935. }
  936. vif->def_txkey_index = key_index;
  937. key = &vif->keys[vif->def_txkey_index];
  938. key_usage = GROUP_USAGE;
  939. if (vif->prwise_crypto == WEP_CRYPT)
  940. key_usage |= TX_USAGE;
  941. if (unicast)
  942. key_type = vif->prwise_crypto;
  943. if (multicast)
  944. key_type = vif->grp_crypto;
  945. if (vif->next_mode == AP_NETWORK && !test_bit(CONNECTED, &vif->flags))
  946. return 0; /* Delay until AP mode has been started */
  947. return ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx,
  948. vif->def_txkey_index,
  949. key_type, key_usage,
  950. key->key_len, key->seq, key->seq_len,
  951. key->key,
  952. KEY_OP_INIT_VAL, NULL,
  953. SYNC_BOTH_WMIFLAG);
  954. }
  955. void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid,
  956. bool ismcast)
  957. {
  958. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  959. "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
  960. cfg80211_michael_mic_failure(vif->ndev, vif->bssid,
  961. (ismcast ? NL80211_KEYTYPE_GROUP :
  962. NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
  963. GFP_KERNEL);
  964. }
  965. static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  966. {
  967. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  968. struct ath6kl_vif *vif;
  969. int ret;
  970. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
  971. changed);
  972. vif = ath6kl_vif_first(ar);
  973. if (!vif)
  974. return -EIO;
  975. if (!ath6kl_cfg80211_ready(vif))
  976. return -EIO;
  977. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  978. ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
  979. if (ret != 0) {
  980. ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
  981. return -EIO;
  982. }
  983. }
  984. return 0;
  985. }
  986. /*
  987. * The type nl80211_tx_power_setting replaces the following
  988. * data type from 2.6.36 onwards
  989. */
  990. static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
  991. enum nl80211_tx_power_setting type,
  992. int dbm)
  993. {
  994. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  995. struct ath6kl_vif *vif;
  996. u8 ath6kl_dbm;
  997. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
  998. type, dbm);
  999. vif = ath6kl_vif_first(ar);
  1000. if (!vif)
  1001. return -EIO;
  1002. if (!ath6kl_cfg80211_ready(vif))
  1003. return -EIO;
  1004. switch (type) {
  1005. case NL80211_TX_POWER_AUTOMATIC:
  1006. return 0;
  1007. case NL80211_TX_POWER_LIMITED:
  1008. ar->tx_pwr = ath6kl_dbm = dbm;
  1009. break;
  1010. default:
  1011. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
  1012. __func__, type);
  1013. return -EOPNOTSUPP;
  1014. }
  1015. ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx, ath6kl_dbm);
  1016. return 0;
  1017. }
  1018. static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
  1019. {
  1020. struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
  1021. struct ath6kl_vif *vif;
  1022. vif = ath6kl_vif_first(ar);
  1023. if (!vif)
  1024. return -EIO;
  1025. if (!ath6kl_cfg80211_ready(vif))
  1026. return -EIO;
  1027. if (test_bit(CONNECTED, &vif->flags)) {
  1028. ar->tx_pwr = 0;
  1029. if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi, vif->fw_vif_idx) != 0) {
  1030. ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
  1031. return -EIO;
  1032. }
  1033. wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
  1034. 5 * HZ);
  1035. if (signal_pending(current)) {
  1036. ath6kl_err("target did not respond\n");
  1037. return -EINTR;
  1038. }
  1039. }
  1040. *dbm = ar->tx_pwr;
  1041. return 0;
  1042. }
  1043. static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  1044. struct net_device *dev,
  1045. bool pmgmt, int timeout)
  1046. {
  1047. struct ath6kl *ar = ath6kl_priv(dev);
  1048. struct wmi_power_mode_cmd mode;
  1049. struct ath6kl_vif *vif = netdev_priv(dev);
  1050. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
  1051. __func__, pmgmt, timeout);
  1052. if (!ath6kl_cfg80211_ready(vif))
  1053. return -EIO;
  1054. if (pmgmt) {
  1055. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
  1056. mode.pwr_mode = REC_POWER;
  1057. } else {
  1058. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
  1059. mode.pwr_mode = MAX_PERF_POWER;
  1060. }
  1061. if (ath6kl_wmi_powermode_cmd(ar->wmi, vif->fw_vif_idx,
  1062. mode.pwr_mode) != 0) {
  1063. ath6kl_err("wmi_powermode_cmd failed\n");
  1064. return -EIO;
  1065. }
  1066. return 0;
  1067. }
  1068. static struct net_device *ath6kl_cfg80211_add_iface(struct wiphy *wiphy,
  1069. char *name,
  1070. enum nl80211_iftype type,
  1071. u32 *flags,
  1072. struct vif_params *params)
  1073. {
  1074. struct ath6kl *ar = wiphy_priv(wiphy);
  1075. struct net_device *ndev;
  1076. u8 if_idx, nw_type;
  1077. if (ar->num_vif == MAX_NUM_VIF) {
  1078. ath6kl_err("Reached maximum number of supported vif\n");
  1079. return ERR_PTR(-EINVAL);
  1080. }
  1081. if (!ath6kl_is_valid_iftype(ar, type, &if_idx, &nw_type)) {
  1082. ath6kl_err("Not a supported interface type\n");
  1083. return ERR_PTR(-EINVAL);
  1084. }
  1085. ndev = ath6kl_interface_add(ar, name, type, if_idx, nw_type);
  1086. if (!ndev)
  1087. return ERR_PTR(-ENOMEM);
  1088. ar->num_vif++;
  1089. return ndev;
  1090. }
  1091. static int ath6kl_cfg80211_del_iface(struct wiphy *wiphy,
  1092. struct net_device *ndev)
  1093. {
  1094. struct ath6kl *ar = wiphy_priv(wiphy);
  1095. struct ath6kl_vif *vif = netdev_priv(ndev);
  1096. spin_lock_bh(&ar->list_lock);
  1097. list_del(&vif->list);
  1098. spin_unlock_bh(&ar->list_lock);
  1099. ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
  1100. ath6kl_deinit_if_data(vif);
  1101. return 0;
  1102. }
  1103. static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
  1104. struct net_device *ndev,
  1105. enum nl80211_iftype type, u32 *flags,
  1106. struct vif_params *params)
  1107. {
  1108. struct ath6kl_vif *vif = netdev_priv(ndev);
  1109. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
  1110. if (!ath6kl_cfg80211_ready(vif))
  1111. return -EIO;
  1112. switch (type) {
  1113. case NL80211_IFTYPE_STATION:
  1114. vif->next_mode = INFRA_NETWORK;
  1115. break;
  1116. case NL80211_IFTYPE_ADHOC:
  1117. vif->next_mode = ADHOC_NETWORK;
  1118. break;
  1119. case NL80211_IFTYPE_AP:
  1120. vif->next_mode = AP_NETWORK;
  1121. break;
  1122. case NL80211_IFTYPE_P2P_CLIENT:
  1123. vif->next_mode = INFRA_NETWORK;
  1124. break;
  1125. case NL80211_IFTYPE_P2P_GO:
  1126. vif->next_mode = AP_NETWORK;
  1127. break;
  1128. default:
  1129. ath6kl_err("invalid interface type %u\n", type);
  1130. return -EOPNOTSUPP;
  1131. }
  1132. vif->wdev.iftype = type;
  1133. return 0;
  1134. }
  1135. static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
  1136. struct net_device *dev,
  1137. struct cfg80211_ibss_params *ibss_param)
  1138. {
  1139. struct ath6kl *ar = ath6kl_priv(dev);
  1140. struct ath6kl_vif *vif = netdev_priv(dev);
  1141. int status;
  1142. if (!ath6kl_cfg80211_ready(vif))
  1143. return -EIO;
  1144. vif->ssid_len = ibss_param->ssid_len;
  1145. memcpy(vif->ssid, ibss_param->ssid, vif->ssid_len);
  1146. if (ibss_param->channel)
  1147. vif->ch_hint = ibss_param->channel->center_freq;
  1148. if (ibss_param->channel_fixed) {
  1149. /*
  1150. * TODO: channel_fixed: The channel should be fixed, do not
  1151. * search for IBSSs to join on other channels. Target
  1152. * firmware does not support this feature, needs to be
  1153. * updated.
  1154. */
  1155. return -EOPNOTSUPP;
  1156. }
  1157. memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
  1158. if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
  1159. memcpy(vif->req_bssid, ibss_param->bssid,
  1160. sizeof(vif->req_bssid));
  1161. ath6kl_set_wpa_version(vif, 0);
  1162. status = ath6kl_set_auth_type(vif, NL80211_AUTHTYPE_OPEN_SYSTEM);
  1163. if (status)
  1164. return status;
  1165. if (ibss_param->privacy) {
  1166. ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, true);
  1167. ath6kl_set_cipher(vif, WLAN_CIPHER_SUITE_WEP40, false);
  1168. } else {
  1169. ath6kl_set_cipher(vif, 0, true);
  1170. ath6kl_set_cipher(vif, 0, false);
  1171. }
  1172. vif->nw_type = vif->next_mode;
  1173. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1174. "%s: connect called with authmode %d dot11 auth %d"
  1175. " PW crypto %d PW crypto len %d GRP crypto %d"
  1176. " GRP crypto len %d channel hint %u\n",
  1177. __func__,
  1178. vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
  1179. vif->prwise_crypto_len, vif->grp_crypto,
  1180. vif->grp_crypto_len, vif->ch_hint);
  1181. status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
  1182. vif->dot11_auth_mode, vif->auth_mode,
  1183. vif->prwise_crypto,
  1184. vif->prwise_crypto_len,
  1185. vif->grp_crypto, vif->grp_crypto_len,
  1186. vif->ssid_len, vif->ssid,
  1187. vif->req_bssid, vif->ch_hint,
  1188. ar->connect_ctrl_flags);
  1189. set_bit(CONNECT_PEND, &vif->flags);
  1190. return 0;
  1191. }
  1192. static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
  1193. struct net_device *dev)
  1194. {
  1195. struct ath6kl_vif *vif = netdev_priv(dev);
  1196. if (!ath6kl_cfg80211_ready(vif))
  1197. return -EIO;
  1198. ath6kl_disconnect(vif);
  1199. memset(vif->ssid, 0, sizeof(vif->ssid));
  1200. vif->ssid_len = 0;
  1201. return 0;
  1202. }
  1203. static const u32 cipher_suites[] = {
  1204. WLAN_CIPHER_SUITE_WEP40,
  1205. WLAN_CIPHER_SUITE_WEP104,
  1206. WLAN_CIPHER_SUITE_TKIP,
  1207. WLAN_CIPHER_SUITE_CCMP,
  1208. CCKM_KRK_CIPHER_SUITE,
  1209. };
  1210. static bool is_rate_legacy(s32 rate)
  1211. {
  1212. static const s32 legacy[] = { 1000, 2000, 5500, 11000,
  1213. 6000, 9000, 12000, 18000, 24000,
  1214. 36000, 48000, 54000
  1215. };
  1216. u8 i;
  1217. for (i = 0; i < ARRAY_SIZE(legacy); i++)
  1218. if (rate == legacy[i])
  1219. return true;
  1220. return false;
  1221. }
  1222. static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
  1223. {
  1224. static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
  1225. 52000, 58500, 65000, 72200
  1226. };
  1227. u8 i;
  1228. for (i = 0; i < ARRAY_SIZE(ht20); i++) {
  1229. if (rate == ht20[i]) {
  1230. if (i == ARRAY_SIZE(ht20) - 1)
  1231. /* last rate uses sgi */
  1232. *sgi = true;
  1233. else
  1234. *sgi = false;
  1235. *mcs = i;
  1236. return true;
  1237. }
  1238. }
  1239. return false;
  1240. }
  1241. static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
  1242. {
  1243. static const s32 ht40[] = { 13500, 27000, 40500, 54000,
  1244. 81000, 108000, 121500, 135000,
  1245. 150000
  1246. };
  1247. u8 i;
  1248. for (i = 0; i < ARRAY_SIZE(ht40); i++) {
  1249. if (rate == ht40[i]) {
  1250. if (i == ARRAY_SIZE(ht40) - 1)
  1251. /* last rate uses sgi */
  1252. *sgi = true;
  1253. else
  1254. *sgi = false;
  1255. *mcs = i;
  1256. return true;
  1257. }
  1258. }
  1259. return false;
  1260. }
  1261. static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
  1262. u8 *mac, struct station_info *sinfo)
  1263. {
  1264. struct ath6kl *ar = ath6kl_priv(dev);
  1265. struct ath6kl_vif *vif = netdev_priv(dev);
  1266. long left;
  1267. bool sgi;
  1268. s32 rate;
  1269. int ret;
  1270. u8 mcs;
  1271. if (memcmp(mac, vif->bssid, ETH_ALEN) != 0)
  1272. return -ENOENT;
  1273. if (down_interruptible(&ar->sem))
  1274. return -EBUSY;
  1275. set_bit(STATS_UPDATE_PEND, &vif->flags);
  1276. ret = ath6kl_wmi_get_stats_cmd(ar->wmi, vif->fw_vif_idx);
  1277. if (ret != 0) {
  1278. up(&ar->sem);
  1279. return -EIO;
  1280. }
  1281. left = wait_event_interruptible_timeout(ar->event_wq,
  1282. !test_bit(STATS_UPDATE_PEND,
  1283. &vif->flags),
  1284. WMI_TIMEOUT);
  1285. up(&ar->sem);
  1286. if (left == 0)
  1287. return -ETIMEDOUT;
  1288. else if (left < 0)
  1289. return left;
  1290. if (vif->target_stats.rx_byte) {
  1291. sinfo->rx_bytes = vif->target_stats.rx_byte;
  1292. sinfo->filled |= STATION_INFO_RX_BYTES;
  1293. sinfo->rx_packets = vif->target_stats.rx_pkt;
  1294. sinfo->filled |= STATION_INFO_RX_PACKETS;
  1295. }
  1296. if (vif->target_stats.tx_byte) {
  1297. sinfo->tx_bytes = vif->target_stats.tx_byte;
  1298. sinfo->filled |= STATION_INFO_TX_BYTES;
  1299. sinfo->tx_packets = vif->target_stats.tx_pkt;
  1300. sinfo->filled |= STATION_INFO_TX_PACKETS;
  1301. }
  1302. sinfo->signal = vif->target_stats.cs_rssi;
  1303. sinfo->filled |= STATION_INFO_SIGNAL;
  1304. rate = vif->target_stats.tx_ucast_rate;
  1305. if (is_rate_legacy(rate)) {
  1306. sinfo->txrate.legacy = rate / 100;
  1307. } else if (is_rate_ht20(rate, &mcs, &sgi)) {
  1308. if (sgi) {
  1309. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1310. sinfo->txrate.mcs = mcs - 1;
  1311. } else {
  1312. sinfo->txrate.mcs = mcs;
  1313. }
  1314. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1315. } else if (is_rate_ht40(rate, &mcs, &sgi)) {
  1316. if (sgi) {
  1317. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1318. sinfo->txrate.mcs = mcs - 1;
  1319. } else {
  1320. sinfo->txrate.mcs = mcs;
  1321. }
  1322. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  1323. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  1324. } else {
  1325. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  1326. "invalid rate from stats: %d\n", rate);
  1327. ath6kl_debug_war(ar, ATH6KL_WAR_INVALID_RATE);
  1328. return 0;
  1329. }
  1330. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1331. if (test_bit(CONNECTED, &vif->flags) &&
  1332. test_bit(DTIM_PERIOD_AVAIL, &vif->flags) &&
  1333. vif->nw_type == INFRA_NETWORK) {
  1334. sinfo->filled |= STATION_INFO_BSS_PARAM;
  1335. sinfo->bss_param.flags = 0;
  1336. sinfo->bss_param.dtim_period = vif->assoc_bss_dtim_period;
  1337. sinfo->bss_param.beacon_interval = vif->assoc_bss_beacon_int;
  1338. }
  1339. return 0;
  1340. }
  1341. static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1342. struct cfg80211_pmksa *pmksa)
  1343. {
  1344. struct ath6kl *ar = ath6kl_priv(netdev);
  1345. struct ath6kl_vif *vif = netdev_priv(netdev);
  1346. return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
  1347. pmksa->pmkid, true);
  1348. }
  1349. static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  1350. struct cfg80211_pmksa *pmksa)
  1351. {
  1352. struct ath6kl *ar = ath6kl_priv(netdev);
  1353. struct ath6kl_vif *vif = netdev_priv(netdev);
  1354. return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx, pmksa->bssid,
  1355. pmksa->pmkid, false);
  1356. }
  1357. static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
  1358. {
  1359. struct ath6kl *ar = ath6kl_priv(netdev);
  1360. struct ath6kl_vif *vif = netdev_priv(netdev);
  1361. if (test_bit(CONNECTED, &vif->flags))
  1362. return ath6kl_wmi_setpmkid_cmd(ar->wmi, vif->fw_vif_idx,
  1363. vif->bssid, NULL, false);
  1364. return 0;
  1365. }
  1366. static int ath6kl_wow_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
  1367. {
  1368. struct ath6kl_vif *vif;
  1369. int ret, pos, left;
  1370. u32 filter = 0;
  1371. u16 i;
  1372. u8 mask[WOW_MASK_SIZE];
  1373. vif = ath6kl_vif_first(ar);
  1374. if (!vif)
  1375. return -EIO;
  1376. if (!ath6kl_cfg80211_ready(vif))
  1377. return -EIO;
  1378. if (!test_bit(CONNECTED, &vif->flags))
  1379. return -EINVAL;
  1380. /* Clear existing WOW patterns */
  1381. for (i = 0; i < WOW_MAX_FILTERS_PER_LIST; i++)
  1382. ath6kl_wmi_del_wow_pattern_cmd(ar->wmi, vif->fw_vif_idx,
  1383. WOW_LIST_ID, i);
  1384. /* Configure new WOW patterns */
  1385. for (i = 0; i < wow->n_patterns; i++) {
  1386. /*
  1387. * Convert given nl80211 specific mask value to equivalent
  1388. * driver specific mask value and send it to the chip along
  1389. * with patterns. For example, If the mask value defined in
  1390. * struct cfg80211_wowlan is 0xA (equivalent binary is 1010),
  1391. * then equivalent driver specific mask value is
  1392. * "0xFF 0x00 0xFF 0x00".
  1393. */
  1394. memset(&mask, 0, sizeof(mask));
  1395. for (pos = 0; pos < wow->patterns[i].pattern_len; pos++) {
  1396. if (wow->patterns[i].mask[pos / 8] & (0x1 << (pos % 8)))
  1397. mask[pos] = 0xFF;
  1398. }
  1399. /*
  1400. * Note: Pattern's offset is not passed as part of wowlan
  1401. * parameter from CFG layer. So it's always passed as ZERO
  1402. * to the firmware. It means, given WOW patterns are always
  1403. * matched from the first byte of received pkt in the firmware.
  1404. */
  1405. ret = ath6kl_wmi_add_wow_pattern_cmd(ar->wmi,
  1406. vif->fw_vif_idx, WOW_LIST_ID,
  1407. wow->patterns[i].pattern_len,
  1408. 0 /* pattern offset */,
  1409. wow->patterns[i].pattern, mask);
  1410. if (ret)
  1411. return ret;
  1412. }
  1413. if (wow->disconnect)
  1414. filter |= WOW_FILTER_OPTION_NWK_DISASSOC;
  1415. if (wow->magic_pkt)
  1416. filter |= WOW_FILTER_OPTION_MAGIC_PACKET;
  1417. if (wow->gtk_rekey_failure)
  1418. filter |= WOW_FILTER_OPTION_GTK_ERROR;
  1419. if (wow->eap_identity_req)
  1420. filter |= WOW_FILTER_OPTION_EAP_REQ;
  1421. if (wow->four_way_handshake)
  1422. filter |= WOW_FILTER_OPTION_8021X_4WAYHS;
  1423. ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1424. ATH6KL_WOW_MODE_ENABLE,
  1425. filter,
  1426. WOW_HOST_REQ_DELAY);
  1427. if (ret)
  1428. return ret;
  1429. ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1430. ATH6KL_HOST_MODE_ASLEEP);
  1431. if (ret)
  1432. return ret;
  1433. if (ar->tx_pending[ar->ctrl_ep]) {
  1434. left = wait_event_interruptible_timeout(ar->event_wq,
  1435. ar->tx_pending[ar->ctrl_ep] == 0, WMI_TIMEOUT);
  1436. if (left == 0) {
  1437. ath6kl_warn("clear wmi ctrl data timeout\n");
  1438. ret = -ETIMEDOUT;
  1439. } else if (left < 0) {
  1440. ath6kl_warn("clear wmi ctrl data failed: %d\n", left);
  1441. ret = left;
  1442. }
  1443. }
  1444. return ret;
  1445. }
  1446. static int ath6kl_wow_resume(struct ath6kl *ar)
  1447. {
  1448. struct ath6kl_vif *vif;
  1449. int ret;
  1450. vif = ath6kl_vif_first(ar);
  1451. if (!vif)
  1452. return -EIO;
  1453. ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
  1454. ATH6KL_HOST_MODE_AWAKE);
  1455. return ret;
  1456. }
  1457. int ath6kl_cfg80211_suspend(struct ath6kl *ar,
  1458. enum ath6kl_cfg_suspend_mode mode,
  1459. struct cfg80211_wowlan *wow)
  1460. {
  1461. int ret;
  1462. switch (mode) {
  1463. case ATH6KL_CFG_SUSPEND_WOW:
  1464. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode suspend\n");
  1465. /* Flush all non control pkts in TX path */
  1466. ath6kl_tx_data_cleanup(ar);
  1467. ret = ath6kl_wow_suspend(ar, wow);
  1468. if (ret) {
  1469. ath6kl_err("wow suspend failed: %d\n", ret);
  1470. return ret;
  1471. }
  1472. ar->state = ATH6KL_STATE_WOW;
  1473. break;
  1474. case ATH6KL_CFG_SUSPEND_DEEPSLEEP:
  1475. ath6kl_cfg80211_stop(ar);
  1476. /* save the current power mode before enabling power save */
  1477. ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
  1478. ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER);
  1479. if (ret) {
  1480. ath6kl_warn("wmi powermode command failed during suspend: %d\n",
  1481. ret);
  1482. }
  1483. ar->state = ATH6KL_STATE_DEEPSLEEP;
  1484. break;
  1485. case ATH6KL_CFG_SUSPEND_CUTPOWER:
  1486. ath6kl_cfg80211_stop(ar);
  1487. if (ar->state == ATH6KL_STATE_OFF) {
  1488. ath6kl_dbg(ATH6KL_DBG_SUSPEND,
  1489. "suspend hw off, no action for cutpower\n");
  1490. break;
  1491. }
  1492. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "suspend cutting power\n");
  1493. ret = ath6kl_init_hw_stop(ar);
  1494. if (ret) {
  1495. ath6kl_warn("failed to stop hw during suspend: %d\n",
  1496. ret);
  1497. }
  1498. ar->state = ATH6KL_STATE_CUTPOWER;
  1499. break;
  1500. default:
  1501. break;
  1502. }
  1503. return 0;
  1504. }
  1505. int ath6kl_cfg80211_resume(struct ath6kl *ar)
  1506. {
  1507. int ret;
  1508. switch (ar->state) {
  1509. case ATH6KL_STATE_WOW:
  1510. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "wow mode resume\n");
  1511. ret = ath6kl_wow_resume(ar);
  1512. if (ret) {
  1513. ath6kl_warn("wow mode resume failed: %d\n", ret);
  1514. return ret;
  1515. }
  1516. ar->state = ATH6KL_STATE_ON;
  1517. break;
  1518. case ATH6KL_STATE_DEEPSLEEP:
  1519. if (ar->wmi->pwr_mode != ar->wmi->saved_pwr_mode) {
  1520. ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0,
  1521. ar->wmi->saved_pwr_mode);
  1522. if (ret) {
  1523. ath6kl_warn("wmi powermode command failed during resume: %d\n",
  1524. ret);
  1525. }
  1526. }
  1527. ar->state = ATH6KL_STATE_ON;
  1528. break;
  1529. case ATH6KL_STATE_CUTPOWER:
  1530. ath6kl_dbg(ATH6KL_DBG_SUSPEND, "resume restoring power\n");
  1531. ret = ath6kl_init_hw_start(ar);
  1532. if (ret) {
  1533. ath6kl_warn("Failed to boot hw in resume: %d\n", ret);
  1534. return ret;
  1535. }
  1536. break;
  1537. default:
  1538. break;
  1539. }
  1540. return 0;
  1541. }
  1542. #ifdef CONFIG_PM
  1543. /* hif layer decides what suspend mode to use */
  1544. static int __ath6kl_cfg80211_suspend(struct wiphy *wiphy,
  1545. struct cfg80211_wowlan *wow)
  1546. {
  1547. struct ath6kl *ar = wiphy_priv(wiphy);
  1548. return ath6kl_hif_suspend(ar, wow);
  1549. }
  1550. static int __ath6kl_cfg80211_resume(struct wiphy *wiphy)
  1551. {
  1552. struct ath6kl *ar = wiphy_priv(wiphy);
  1553. return ath6kl_hif_resume(ar);
  1554. }
  1555. #endif
  1556. static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
  1557. struct ieee80211_channel *chan,
  1558. enum nl80211_channel_type channel_type)
  1559. {
  1560. struct ath6kl_vif *vif = netdev_priv(dev);
  1561. if (!ath6kl_cfg80211_ready(vif))
  1562. return -EIO;
  1563. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
  1564. __func__, chan->center_freq, chan->hw_value);
  1565. vif->next_chan = chan->center_freq;
  1566. return 0;
  1567. }
  1568. static bool ath6kl_is_p2p_ie(const u8 *pos)
  1569. {
  1570. return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  1571. pos[2] == 0x50 && pos[3] == 0x6f &&
  1572. pos[4] == 0x9a && pos[5] == 0x09;
  1573. }
  1574. static int ath6kl_set_ap_probe_resp_ies(struct ath6kl_vif *vif,
  1575. const u8 *ies, size_t ies_len)
  1576. {
  1577. struct ath6kl *ar = vif->ar;
  1578. const u8 *pos;
  1579. u8 *buf = NULL;
  1580. size_t len = 0;
  1581. int ret;
  1582. /*
  1583. * Filter out P2P IE(s) since they will be included depending on
  1584. * the Probe Request frame in ath6kl_send_go_probe_resp().
  1585. */
  1586. if (ies && ies_len) {
  1587. buf = kmalloc(ies_len, GFP_KERNEL);
  1588. if (buf == NULL)
  1589. return -ENOMEM;
  1590. pos = ies;
  1591. while (pos + 1 < ies + ies_len) {
  1592. if (pos + 2 + pos[1] > ies + ies_len)
  1593. break;
  1594. if (!ath6kl_is_p2p_ie(pos)) {
  1595. memcpy(buf + len, pos, 2 + pos[1]);
  1596. len += 2 + pos[1];
  1597. }
  1598. pos += 2 + pos[1];
  1599. }
  1600. }
  1601. ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  1602. WMI_FRAME_PROBE_RESP, buf, len);
  1603. kfree(buf);
  1604. return ret;
  1605. }
  1606. static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
  1607. struct beacon_parameters *info, bool add)
  1608. {
  1609. struct ath6kl *ar = ath6kl_priv(dev);
  1610. struct ath6kl_vif *vif = netdev_priv(dev);
  1611. struct ieee80211_mgmt *mgmt;
  1612. u8 *ies;
  1613. int ies_len;
  1614. struct wmi_connect_cmd p;
  1615. int res;
  1616. int i;
  1617. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
  1618. if (!ath6kl_cfg80211_ready(vif))
  1619. return -EIO;
  1620. if (vif->next_mode != AP_NETWORK)
  1621. return -EOPNOTSUPP;
  1622. if (info->beacon_ies) {
  1623. res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  1624. WMI_FRAME_BEACON,
  1625. info->beacon_ies,
  1626. info->beacon_ies_len);
  1627. if (res)
  1628. return res;
  1629. }
  1630. if (info->proberesp_ies) {
  1631. res = ath6kl_set_ap_probe_resp_ies(vif, info->proberesp_ies,
  1632. info->proberesp_ies_len);
  1633. if (res)
  1634. return res;
  1635. }
  1636. if (info->assocresp_ies) {
  1637. res = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
  1638. WMI_FRAME_ASSOC_RESP,
  1639. info->assocresp_ies,
  1640. info->assocresp_ies_len);
  1641. if (res)
  1642. return res;
  1643. }
  1644. if (!add)
  1645. return 0;
  1646. ar->ap_mode_bkey.valid = false;
  1647. /* TODO:
  1648. * info->interval
  1649. * info->dtim_period
  1650. */
  1651. if (info->head == NULL)
  1652. return -EINVAL;
  1653. mgmt = (struct ieee80211_mgmt *) info->head;
  1654. ies = mgmt->u.beacon.variable;
  1655. if (ies > info->head + info->head_len)
  1656. return -EINVAL;
  1657. ies_len = info->head + info->head_len - ies;
  1658. if (info->ssid == NULL)
  1659. return -EINVAL;
  1660. memcpy(vif->ssid, info->ssid, info->ssid_len);
  1661. vif->ssid_len = info->ssid_len;
  1662. if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
  1663. return -EOPNOTSUPP; /* TODO */
  1664. vif->dot11_auth_mode = OPEN_AUTH;
  1665. memset(&p, 0, sizeof(p));
  1666. for (i = 0; i < info->crypto.n_akm_suites; i++) {
  1667. switch (info->crypto.akm_suites[i]) {
  1668. case WLAN_AKM_SUITE_8021X:
  1669. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  1670. p.auth_mode |= WPA_AUTH;
  1671. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  1672. p.auth_mode |= WPA2_AUTH;
  1673. break;
  1674. case WLAN_AKM_SUITE_PSK:
  1675. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  1676. p.auth_mode |= WPA_PSK_AUTH;
  1677. if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  1678. p.auth_mode |= WPA2_PSK_AUTH;
  1679. break;
  1680. }
  1681. }
  1682. if (p.auth_mode == 0)
  1683. p.auth_mode = NONE_AUTH;
  1684. vif->auth_mode = p.auth_mode;
  1685. for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
  1686. switch (info->crypto.ciphers_pairwise[i]) {
  1687. case WLAN_CIPHER_SUITE_WEP40:
  1688. case WLAN_CIPHER_SUITE_WEP104:
  1689. p.prwise_crypto_type |= WEP_CRYPT;
  1690. break;
  1691. case WLAN_CIPHER_SUITE_TKIP:
  1692. p.prwise_crypto_type |= TKIP_CRYPT;
  1693. break;
  1694. case WLAN_CIPHER_SUITE_CCMP:
  1695. p.prwise_crypto_type |= AES_CRYPT;
  1696. break;
  1697. }
  1698. }
  1699. if (p.prwise_crypto_type == 0) {
  1700. p.prwise_crypto_type = NONE_CRYPT;
  1701. ath6kl_set_cipher(vif, 0, true);
  1702. } else if (info->crypto.n_ciphers_pairwise == 1)
  1703. ath6kl_set_cipher(vif, info->crypto.ciphers_pairwise[0], true);
  1704. switch (info->crypto.cipher_group) {
  1705. case WLAN_CIPHER_SUITE_WEP40:
  1706. case WLAN_CIPHER_SUITE_WEP104:
  1707. p.grp_crypto_type = WEP_CRYPT;
  1708. break;
  1709. case WLAN_CIPHER_SUITE_TKIP:
  1710. p.grp_crypto_type = TKIP_CRYPT;
  1711. break;
  1712. case WLAN_CIPHER_SUITE_CCMP:
  1713. p.grp_crypto_type = AES_CRYPT;
  1714. break;
  1715. default:
  1716. p.grp_crypto_type = NONE_CRYPT;
  1717. break;
  1718. }
  1719. ath6kl_set_cipher(vif, info->crypto.cipher_group, false);
  1720. p.nw_type = AP_NETWORK;
  1721. vif->nw_type = vif->next_mode;
  1722. p.ssid_len = vif->ssid_len;
  1723. memcpy(p.ssid, vif->ssid, vif->ssid_len);
  1724. p.dot11_auth_mode = vif->dot11_auth_mode;
  1725. p.ch = cpu_to_le16(vif->next_chan);
  1726. res = ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx, &p);
  1727. if (res < 0)
  1728. return res;
  1729. return 0;
  1730. }
  1731. static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  1732. struct beacon_parameters *info)
  1733. {
  1734. return ath6kl_ap_beacon(wiphy, dev, info, true);
  1735. }
  1736. static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  1737. struct beacon_parameters *info)
  1738. {
  1739. return ath6kl_ap_beacon(wiphy, dev, info, false);
  1740. }
  1741. static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  1742. {
  1743. struct ath6kl *ar = ath6kl_priv(dev);
  1744. struct ath6kl_vif *vif = netdev_priv(dev);
  1745. if (vif->nw_type != AP_NETWORK)
  1746. return -EOPNOTSUPP;
  1747. if (!test_bit(CONNECTED, &vif->flags))
  1748. return -ENOTCONN;
  1749. ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
  1750. clear_bit(CONNECTED, &vif->flags);
  1751. return 0;
  1752. }
  1753. static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
  1754. u8 *mac, struct station_parameters *params)
  1755. {
  1756. struct ath6kl *ar = ath6kl_priv(dev);
  1757. struct ath6kl_vif *vif = netdev_priv(dev);
  1758. if (vif->nw_type != AP_NETWORK)
  1759. return -EOPNOTSUPP;
  1760. /* Use this only for authorizing/unauthorizing a station */
  1761. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  1762. return -EOPNOTSUPP;
  1763. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  1764. return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
  1765. WMI_AP_MLME_AUTHORIZE, mac, 0);
  1766. return ath6kl_wmi_ap_set_mlme(ar->wmi, vif->fw_vif_idx,
  1767. WMI_AP_MLME_UNAUTHORIZE, mac, 0);
  1768. }
  1769. static int ath6kl_remain_on_channel(struct wiphy *wiphy,
  1770. struct net_device *dev,
  1771. struct ieee80211_channel *chan,
  1772. enum nl80211_channel_type channel_type,
  1773. unsigned int duration,
  1774. u64 *cookie)
  1775. {
  1776. struct ath6kl *ar = ath6kl_priv(dev);
  1777. struct ath6kl_vif *vif = netdev_priv(dev);
  1778. u32 id;
  1779. /* TODO: if already pending or ongoing remain-on-channel,
  1780. * return -EBUSY */
  1781. id = ++vif->last_roc_id;
  1782. if (id == 0) {
  1783. /* Do not use 0 as the cookie value */
  1784. id = ++vif->last_roc_id;
  1785. }
  1786. *cookie = id;
  1787. return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx,
  1788. chan->center_freq, duration);
  1789. }
  1790. static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
  1791. struct net_device *dev,
  1792. u64 cookie)
  1793. {
  1794. struct ath6kl *ar = ath6kl_priv(dev);
  1795. struct ath6kl_vif *vif = netdev_priv(dev);
  1796. if (cookie != vif->last_roc_id)
  1797. return -ENOENT;
  1798. vif->last_cancel_roc_id = cookie;
  1799. return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi, vif->fw_vif_idx);
  1800. }
  1801. static int ath6kl_send_go_probe_resp(struct ath6kl_vif *vif,
  1802. const u8 *buf, size_t len,
  1803. unsigned int freq)
  1804. {
  1805. struct ath6kl *ar = vif->ar;
  1806. const u8 *pos;
  1807. u8 *p2p;
  1808. int p2p_len;
  1809. int ret;
  1810. const struct ieee80211_mgmt *mgmt;
  1811. mgmt = (const struct ieee80211_mgmt *) buf;
  1812. /* Include P2P IE(s) from the frame generated in user space. */
  1813. p2p = kmalloc(len, GFP_KERNEL);
  1814. if (p2p == NULL)
  1815. return -ENOMEM;
  1816. p2p_len = 0;
  1817. pos = mgmt->u.probe_resp.variable;
  1818. while (pos + 1 < buf + len) {
  1819. if (pos + 2 + pos[1] > buf + len)
  1820. break;
  1821. if (ath6kl_is_p2p_ie(pos)) {
  1822. memcpy(p2p + p2p_len, pos, 2 + pos[1]);
  1823. p2p_len += 2 + pos[1];
  1824. }
  1825. pos += 2 + pos[1];
  1826. }
  1827. ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, vif->fw_vif_idx, freq,
  1828. mgmt->da, p2p, p2p_len);
  1829. kfree(p2p);
  1830. return ret;
  1831. }
  1832. static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1833. struct ieee80211_channel *chan, bool offchan,
  1834. enum nl80211_channel_type channel_type,
  1835. bool channel_type_valid, unsigned int wait,
  1836. const u8 *buf, size_t len, bool no_cck,
  1837. bool dont_wait_for_ack, u64 *cookie)
  1838. {
  1839. struct ath6kl *ar = ath6kl_priv(dev);
  1840. struct ath6kl_vif *vif = netdev_priv(dev);
  1841. u32 id;
  1842. const struct ieee80211_mgmt *mgmt;
  1843. mgmt = (const struct ieee80211_mgmt *) buf;
  1844. if (buf + len >= mgmt->u.probe_resp.variable &&
  1845. vif->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) &&
  1846. ieee80211_is_probe_resp(mgmt->frame_control)) {
  1847. /*
  1848. * Send Probe Response frame in AP mode using a separate WMI
  1849. * command to allow the target to fill in the generic IEs.
  1850. */
  1851. *cookie = 0; /* TX status not supported */
  1852. return ath6kl_send_go_probe_resp(vif, buf, len,
  1853. chan->center_freq);
  1854. }
  1855. id = vif->send_action_id++;
  1856. if (id == 0) {
  1857. /*
  1858. * 0 is a reserved value in the WMI command and shall not be
  1859. * used for the command.
  1860. */
  1861. id = vif->send_action_id++;
  1862. }
  1863. *cookie = id;
  1864. return ath6kl_wmi_send_action_cmd(ar->wmi, vif->fw_vif_idx, id,
  1865. chan->center_freq, wait,
  1866. buf, len);
  1867. }
  1868. static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
  1869. struct net_device *dev,
  1870. u16 frame_type, bool reg)
  1871. {
  1872. struct ath6kl_vif *vif = netdev_priv(dev);
  1873. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
  1874. __func__, frame_type, reg);
  1875. if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
  1876. /*
  1877. * Note: This notification callback is not allowed to sleep, so
  1878. * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
  1879. * hardcode target to report Probe Request frames all the time.
  1880. */
  1881. vif->probe_req_report = reg;
  1882. }
  1883. }
  1884. static const struct ieee80211_txrx_stypes
  1885. ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  1886. [NL80211_IFTYPE_STATION] = {
  1887. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1888. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1889. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1890. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1891. },
  1892. [NL80211_IFTYPE_P2P_CLIENT] = {
  1893. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1894. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1895. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1896. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1897. },
  1898. [NL80211_IFTYPE_P2P_GO] = {
  1899. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1900. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1901. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1902. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1903. },
  1904. };
  1905. static struct cfg80211_ops ath6kl_cfg80211_ops = {
  1906. .add_virtual_intf = ath6kl_cfg80211_add_iface,
  1907. .del_virtual_intf = ath6kl_cfg80211_del_iface,
  1908. .change_virtual_intf = ath6kl_cfg80211_change_iface,
  1909. .scan = ath6kl_cfg80211_scan,
  1910. .connect = ath6kl_cfg80211_connect,
  1911. .disconnect = ath6kl_cfg80211_disconnect,
  1912. .add_key = ath6kl_cfg80211_add_key,
  1913. .get_key = ath6kl_cfg80211_get_key,
  1914. .del_key = ath6kl_cfg80211_del_key,
  1915. .set_default_key = ath6kl_cfg80211_set_default_key,
  1916. .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
  1917. .set_tx_power = ath6kl_cfg80211_set_txpower,
  1918. .get_tx_power = ath6kl_cfg80211_get_txpower,
  1919. .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
  1920. .join_ibss = ath6kl_cfg80211_join_ibss,
  1921. .leave_ibss = ath6kl_cfg80211_leave_ibss,
  1922. .get_station = ath6kl_get_station,
  1923. .set_pmksa = ath6kl_set_pmksa,
  1924. .del_pmksa = ath6kl_del_pmksa,
  1925. .flush_pmksa = ath6kl_flush_pmksa,
  1926. CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
  1927. #ifdef CONFIG_PM
  1928. .suspend = __ath6kl_cfg80211_suspend,
  1929. .resume = __ath6kl_cfg80211_resume,
  1930. #endif
  1931. .set_channel = ath6kl_set_channel,
  1932. .add_beacon = ath6kl_add_beacon,
  1933. .set_beacon = ath6kl_set_beacon,
  1934. .del_beacon = ath6kl_del_beacon,
  1935. .change_station = ath6kl_change_station,
  1936. .remain_on_channel = ath6kl_remain_on_channel,
  1937. .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
  1938. .mgmt_tx = ath6kl_mgmt_tx,
  1939. .mgmt_frame_register = ath6kl_mgmt_frame_register,
  1940. };
  1941. void ath6kl_cfg80211_stop(struct ath6kl *ar)
  1942. {
  1943. struct ath6kl_vif *vif;
  1944. /* FIXME: for multi vif */
  1945. vif = ath6kl_vif_first(ar);
  1946. if (!vif) {
  1947. /* save the current power mode before enabling power save */
  1948. ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
  1949. if (ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER) != 0)
  1950. ath6kl_warn("ath6kl_deep_sleep_enable: "
  1951. "wmi_powermode_cmd failed\n");
  1952. return;
  1953. }
  1954. switch (vif->sme_state) {
  1955. case SME_CONNECTING:
  1956. cfg80211_connect_result(vif->ndev, vif->bssid, NULL, 0,
  1957. NULL, 0,
  1958. WLAN_STATUS_UNSPECIFIED_FAILURE,
  1959. GFP_KERNEL);
  1960. break;
  1961. case SME_CONNECTED:
  1962. default:
  1963. /*
  1964. * FIXME: oddly enough smeState is in DISCONNECTED during
  1965. * suspend, why? Need to send disconnected event in that
  1966. * state.
  1967. */
  1968. cfg80211_disconnected(vif->ndev, 0, NULL, 0, GFP_KERNEL);
  1969. break;
  1970. }
  1971. if (test_bit(CONNECTED, &vif->flags) ||
  1972. test_bit(CONNECT_PEND, &vif->flags))
  1973. ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
  1974. vif->sme_state = SME_DISCONNECTED;
  1975. clear_bit(CONNECTED, &vif->flags);
  1976. clear_bit(CONNECT_PEND, &vif->flags);
  1977. /* disable scanning */
  1978. if (ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0xFFFF, 0, 0,
  1979. 0, 0, 0, 0, 0, 0, 0) != 0)
  1980. printk(KERN_WARNING "ath6kl: failed to disable scan "
  1981. "during suspend\n");
  1982. ath6kl_cfg80211_scan_complete_event(vif, true);
  1983. }
  1984. struct ath6kl *ath6kl_core_alloc(struct device *dev)
  1985. {
  1986. struct ath6kl *ar;
  1987. struct wiphy *wiphy;
  1988. u8 ctr;
  1989. /* create a new wiphy for use with cfg80211 */
  1990. wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
  1991. if (!wiphy) {
  1992. ath6kl_err("couldn't allocate wiphy device\n");
  1993. return NULL;
  1994. }
  1995. ar = wiphy_priv(wiphy);
  1996. if (!multi_norm_if_support)
  1997. ar->p2p = !!ath6kl_p2p;
  1998. ar->wiphy = wiphy;
  1999. ar->dev = dev;
  2000. if (multi_norm_if_support)
  2001. ar->max_norm_iface = 2;
  2002. else
  2003. ar->max_norm_iface = 1;
  2004. /* FIXME: Remove this once the multivif support is enabled */
  2005. ar->max_norm_iface = 1;
  2006. spin_lock_init(&ar->lock);
  2007. spin_lock_init(&ar->mcastpsq_lock);
  2008. spin_lock_init(&ar->list_lock);
  2009. init_waitqueue_head(&ar->event_wq);
  2010. sema_init(&ar->sem, 1);
  2011. INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
  2012. INIT_LIST_HEAD(&ar->vif_list);
  2013. clear_bit(WMI_ENABLED, &ar->flag);
  2014. clear_bit(SKIP_SCAN, &ar->flag);
  2015. clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
  2016. ar->listen_intvl_t = A_DEFAULT_LISTEN_INTERVAL;
  2017. ar->listen_intvl_b = 0;
  2018. ar->tx_pwr = 0;
  2019. ar->intra_bss = 1;
  2020. memset(&ar->sc_params, 0, sizeof(ar->sc_params));
  2021. ar->sc_params.short_scan_ratio = WMI_SHORTSCANRATIO_DEFAULT;
  2022. ar->sc_params.scan_ctrl_flags = DEFAULT_SCAN_CTRL_FLAGS;
  2023. ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD;
  2024. ar->state = ATH6KL_STATE_OFF;
  2025. memset((u8 *)ar->sta_list, 0,
  2026. AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
  2027. /* Init the PS queues */
  2028. for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
  2029. spin_lock_init(&ar->sta_list[ctr].psq_lock);
  2030. skb_queue_head_init(&ar->sta_list[ctr].psq);
  2031. }
  2032. skb_queue_head_init(&ar->mcastpsq);
  2033. memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
  2034. return ar;
  2035. }
  2036. int ath6kl_register_ieee80211_hw(struct ath6kl *ar)
  2037. {
  2038. struct wiphy *wiphy = ar->wiphy;
  2039. int ret;
  2040. wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
  2041. wiphy->max_remain_on_channel_duration = 5000;
  2042. /* set device pointer for wiphy */
  2043. set_wiphy_dev(wiphy, ar->dev);
  2044. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  2045. BIT(NL80211_IFTYPE_ADHOC) |
  2046. BIT(NL80211_IFTYPE_AP);
  2047. if (ar->p2p) {
  2048. wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) |
  2049. BIT(NL80211_IFTYPE_P2P_CLIENT);
  2050. }
  2051. /* max num of ssids that can be probed during scanning */
  2052. wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
  2053. wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
  2054. wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
  2055. wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
  2056. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  2057. wiphy->cipher_suites = cipher_suites;
  2058. wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  2059. ret = wiphy_register(wiphy);
  2060. if (ret < 0) {
  2061. ath6kl_err("couldn't register wiphy device\n");
  2062. return ret;
  2063. }
  2064. return 0;
  2065. }
  2066. static int ath6kl_init_if_data(struct ath6kl_vif *vif)
  2067. {
  2068. vif->aggr_cntxt = aggr_init(vif->ndev);
  2069. if (!vif->aggr_cntxt) {
  2070. ath6kl_err("failed to initialize aggr\n");
  2071. return -ENOMEM;
  2072. }
  2073. setup_timer(&vif->disconnect_timer, disconnect_timer_handler,
  2074. (unsigned long) vif->ndev);
  2075. set_bit(WMM_ENABLED, &vif->flags);
  2076. spin_lock_init(&vif->if_lock);
  2077. return 0;
  2078. }
  2079. void ath6kl_deinit_if_data(struct ath6kl_vif *vif)
  2080. {
  2081. struct ath6kl *ar = vif->ar;
  2082. aggr_module_destroy(vif->aggr_cntxt);
  2083. ar->avail_idx_map |= BIT(vif->fw_vif_idx);
  2084. if (vif->nw_type == ADHOC_NETWORK)
  2085. ar->ibss_if_active = false;
  2086. unregister_netdevice(vif->ndev);
  2087. ar->num_vif--;
  2088. }
  2089. struct net_device *ath6kl_interface_add(struct ath6kl *ar, char *name,
  2090. enum nl80211_iftype type, u8 fw_vif_idx,
  2091. u8 nw_type)
  2092. {
  2093. struct net_device *ndev;
  2094. struct ath6kl_vif *vif;
  2095. ndev = alloc_netdev(sizeof(*vif), name, ether_setup);
  2096. if (!ndev)
  2097. return NULL;
  2098. vif = netdev_priv(ndev);
  2099. ndev->ieee80211_ptr = &vif->wdev;
  2100. vif->wdev.wiphy = ar->wiphy;
  2101. vif->ar = ar;
  2102. vif->ndev = ndev;
  2103. SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy));
  2104. vif->wdev.netdev = ndev;
  2105. vif->wdev.iftype = type;
  2106. vif->fw_vif_idx = fw_vif_idx;
  2107. vif->nw_type = vif->next_mode = nw_type;
  2108. memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
  2109. if (fw_vif_idx != 0)
  2110. ndev->dev_addr[0] = (ndev->dev_addr[0] ^ (1 << fw_vif_idx)) |
  2111. 0x2;
  2112. init_netdev(ndev);
  2113. ath6kl_init_control_info(vif);
  2114. /* TODO: Pass interface specific pointer instead of ar */
  2115. if (ath6kl_init_if_data(vif))
  2116. goto err;
  2117. if (register_netdevice(ndev))
  2118. goto err;
  2119. ar->avail_idx_map &= ~BIT(fw_vif_idx);
  2120. vif->sme_state = SME_DISCONNECTED;
  2121. set_bit(WLAN_ENABLED, &vif->flags);
  2122. ar->wlan_pwr_state = WLAN_POWER_STATE_ON;
  2123. set_bit(NETDEV_REGISTERED, &vif->flags);
  2124. if (type == NL80211_IFTYPE_ADHOC)
  2125. ar->ibss_if_active = true;
  2126. spin_lock_bh(&ar->list_lock);
  2127. list_add_tail(&vif->list, &ar->vif_list);
  2128. spin_unlock_bh(&ar->list_lock);
  2129. return ndev;
  2130. err:
  2131. aggr_module_destroy(vif->aggr_cntxt);
  2132. free_netdev(ndev);
  2133. return NULL;
  2134. }
  2135. void ath6kl_deinit_ieee80211_hw(struct ath6kl *ar)
  2136. {
  2137. wiphy_unregister(ar->wiphy);
  2138. wiphy_free(ar->wiphy);
  2139. }