cfg80211.c 102 KB

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