cfg80211.c 88 KB

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