cfg80211.c 66 KB

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