cfg80211.c 54 KB

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