cfg80211.c 55 KB

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