cfg80211.c 95 KB

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