cfg80211.c 97 KB

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