cfg80211.c 48 KB

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