cfg80211.c 67 KB

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