cfg80211.c 79 KB

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