cfg80211.c 102 KB

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