cfg80211.c 73 KB

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