cfg80211.c 66 KB

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