cfg80211.c 101 KB

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