cfg80211.c 87 KB

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