cfg80211.c 76 KB

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