cfg80211.c 55 KB

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