cfg80211.c 71 KB

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