cfg80211.c 95 KB

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