cfg80211.c 95 KB

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