main.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include "core.h"
  19. #include "hif-ops.h"
  20. #include "cfg80211.h"
  21. #include "target.h"
  22. #include "debug.h"
  23. struct ath6kl_sta *ath6kl_find_sta(struct ath6kl_vif *vif, u8 *node_addr)
  24. {
  25. struct ath6kl *ar = vif->ar;
  26. struct ath6kl_sta *conn = NULL;
  27. u8 i, max_conn;
  28. if (is_zero_ether_addr(node_addr))
  29. return NULL;
  30. max_conn = (vif->nw_type == AP_NETWORK) ? AP_MAX_NUM_STA : 0;
  31. for (i = 0; i < max_conn; i++) {
  32. if (memcmp(node_addr, ar->sta_list[i].mac, ETH_ALEN) == 0) {
  33. conn = &ar->sta_list[i];
  34. break;
  35. }
  36. }
  37. return conn;
  38. }
  39. struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid)
  40. {
  41. struct ath6kl_sta *conn = NULL;
  42. u8 ctr;
  43. for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
  44. if (ar->sta_list[ctr].aid == aid) {
  45. conn = &ar->sta_list[ctr];
  46. break;
  47. }
  48. }
  49. return conn;
  50. }
  51. static void ath6kl_add_new_sta(struct ath6kl_vif *vif, u8 *mac, u16 aid,
  52. u8 *wpaie, size_t ielen, u8 keymgmt,
  53. u8 ucipher, u8 auth, u8 apsd_info)
  54. {
  55. struct ath6kl *ar = vif->ar;
  56. struct ath6kl_sta *sta;
  57. u8 free_slot;
  58. free_slot = aid - 1;
  59. sta = &ar->sta_list[free_slot];
  60. memcpy(sta->mac, mac, ETH_ALEN);
  61. if (ielen <= ATH6KL_MAX_IE)
  62. memcpy(sta->wpa_ie, wpaie, ielen);
  63. sta->aid = aid;
  64. sta->keymgmt = keymgmt;
  65. sta->ucipher = ucipher;
  66. sta->auth = auth;
  67. sta->apsd_info = apsd_info;
  68. ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
  69. ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid);
  70. aggr_conn_init(vif, vif->aggr_cntxt, sta->aggr_conn);
  71. }
  72. static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i)
  73. {
  74. struct ath6kl_sta *sta = &ar->sta_list[i];
  75. struct ath6kl_mgmt_buff *entry, *tmp;
  76. /* empty the queued pkts in the PS queue if any */
  77. spin_lock_bh(&sta->psq_lock);
  78. skb_queue_purge(&sta->psq);
  79. skb_queue_purge(&sta->apsdq);
  80. if (sta->mgmt_psq_len != 0) {
  81. list_for_each_entry_safe(entry, tmp, &sta->mgmt_psq, list) {
  82. kfree(entry);
  83. }
  84. INIT_LIST_HEAD(&sta->mgmt_psq);
  85. sta->mgmt_psq_len = 0;
  86. }
  87. spin_unlock_bh(&sta->psq_lock);
  88. memset(&ar->ap_stats.sta[sta->aid - 1], 0,
  89. sizeof(struct wmi_per_sta_stat));
  90. eth_zero_addr(sta->mac);
  91. memset(sta->wpa_ie, 0, ATH6KL_MAX_IE);
  92. sta->aid = 0;
  93. sta->sta_flags = 0;
  94. ar->sta_list_index = ar->sta_list_index & ~(1 << i);
  95. aggr_reset_state(sta->aggr_conn);
  96. }
  97. static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason)
  98. {
  99. u8 i, removed = 0;
  100. if (is_zero_ether_addr(mac))
  101. return removed;
  102. if (is_broadcast_ether_addr(mac)) {
  103. ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n");
  104. for (i = 0; i < AP_MAX_NUM_STA; i++) {
  105. if (!is_zero_ether_addr(ar->sta_list[i].mac)) {
  106. ath6kl_sta_cleanup(ar, i);
  107. removed = 1;
  108. }
  109. }
  110. } else {
  111. for (i = 0; i < AP_MAX_NUM_STA; i++) {
  112. if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) {
  113. ath6kl_dbg(ATH6KL_DBG_TRC,
  114. "deleting station %pM aid=%d reason=%d\n",
  115. mac, ar->sta_list[i].aid, reason);
  116. ath6kl_sta_cleanup(ar, i);
  117. removed = 1;
  118. break;
  119. }
  120. }
  121. }
  122. return removed;
  123. }
  124. enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac)
  125. {
  126. struct ath6kl *ar = devt;
  127. return ar->ac2ep_map[ac];
  128. }
  129. struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar)
  130. {
  131. struct ath6kl_cookie *cookie;
  132. cookie = ar->cookie_list;
  133. if (cookie != NULL) {
  134. ar->cookie_list = cookie->arc_list_next;
  135. ar->cookie_count--;
  136. }
  137. return cookie;
  138. }
  139. void ath6kl_cookie_init(struct ath6kl *ar)
  140. {
  141. u32 i;
  142. ar->cookie_list = NULL;
  143. ar->cookie_count = 0;
  144. memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem));
  145. for (i = 0; i < MAX_COOKIE_NUM; i++)
  146. ath6kl_free_cookie(ar, &ar->cookie_mem[i]);
  147. }
  148. void ath6kl_cookie_cleanup(struct ath6kl *ar)
  149. {
  150. ar->cookie_list = NULL;
  151. ar->cookie_count = 0;
  152. }
  153. void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie)
  154. {
  155. /* Insert first */
  156. if (!ar || !cookie)
  157. return;
  158. cookie->arc_list_next = ar->cookie_list;
  159. ar->cookie_list = cookie;
  160. ar->cookie_count++;
  161. }
  162. /*
  163. * Read from the hardware through its diagnostic window. No cooperation
  164. * from the firmware is required for this.
  165. */
  166. int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value)
  167. {
  168. int ret;
  169. ret = ath6kl_hif_diag_read32(ar, address, value);
  170. if (ret) {
  171. ath6kl_warn("failed to read32 through diagnose window: %d\n",
  172. ret);
  173. return ret;
  174. }
  175. return 0;
  176. }
  177. /*
  178. * Write to the ATH6KL through its diagnostic window. No cooperation from
  179. * the Target is required for this.
  180. */
  181. int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value)
  182. {
  183. int ret;
  184. ret = ath6kl_hif_diag_write32(ar, address, value);
  185. if (ret) {
  186. ath6kl_err("failed to write 0x%x during diagnose window to 0x%x\n",
  187. address, value);
  188. return ret;
  189. }
  190. return 0;
  191. }
  192. int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length)
  193. {
  194. u32 count, *buf = data;
  195. int ret;
  196. if (WARN_ON(length % 4))
  197. return -EINVAL;
  198. for (count = 0; count < length / 4; count++, address += 4) {
  199. ret = ath6kl_diag_read32(ar, address, &buf[count]);
  200. if (ret)
  201. return ret;
  202. }
  203. return 0;
  204. }
  205. int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length)
  206. {
  207. u32 count;
  208. __le32 *buf = data;
  209. int ret;
  210. if (WARN_ON(length % 4))
  211. return -EINVAL;
  212. for (count = 0; count < length / 4; count++, address += 4) {
  213. ret = ath6kl_diag_write32(ar, address, buf[count]);
  214. if (ret)
  215. return ret;
  216. }
  217. return 0;
  218. }
  219. int ath6kl_read_fwlogs(struct ath6kl *ar)
  220. {
  221. struct ath6kl_dbglog_hdr debug_hdr;
  222. struct ath6kl_dbglog_buf debug_buf;
  223. u32 address, length, firstbuf, debug_hdr_addr;
  224. int ret, loop;
  225. u8 *buf;
  226. buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL);
  227. if (!buf)
  228. return -ENOMEM;
  229. address = TARG_VTOP(ar->target_type,
  230. ath6kl_get_hi_item_addr(ar,
  231. HI_ITEM(hi_dbglog_hdr)));
  232. ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr);
  233. if (ret)
  234. goto out;
  235. /* Get the contents of the ring buffer */
  236. if (debug_hdr_addr == 0) {
  237. ath6kl_warn("Invalid address for debug_hdr_addr\n");
  238. ret = -EINVAL;
  239. goto out;
  240. }
  241. address = TARG_VTOP(ar->target_type, debug_hdr_addr);
  242. ret = ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr));
  243. if (ret)
  244. goto out;
  245. address = TARG_VTOP(ar->target_type,
  246. le32_to_cpu(debug_hdr.dbuf_addr));
  247. firstbuf = address;
  248. ret = ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
  249. if (ret)
  250. goto out;
  251. loop = 100;
  252. do {
  253. address = TARG_VTOP(ar->target_type,
  254. le32_to_cpu(debug_buf.buffer_addr));
  255. length = le32_to_cpu(debug_buf.length);
  256. if (length != 0 && (le32_to_cpu(debug_buf.length) <=
  257. le32_to_cpu(debug_buf.bufsize))) {
  258. length = ALIGN(length, 4);
  259. ret = ath6kl_diag_read(ar, address,
  260. buf, length);
  261. if (ret)
  262. goto out;
  263. ath6kl_debug_fwlog_event(ar, buf, length);
  264. }
  265. address = TARG_VTOP(ar->target_type,
  266. le32_to_cpu(debug_buf.next));
  267. ret = ath6kl_diag_read(ar, address, &debug_buf,
  268. sizeof(debug_buf));
  269. if (ret)
  270. goto out;
  271. loop--;
  272. if (WARN_ON(loop == 0)) {
  273. ret = -ETIMEDOUT;
  274. goto out;
  275. }
  276. } while (address != firstbuf);
  277. out:
  278. kfree(buf);
  279. return ret;
  280. }
  281. static void ath6kl_install_static_wep_keys(struct ath6kl_vif *vif)
  282. {
  283. u8 index;
  284. u8 keyusage;
  285. for (index = 0; index <= WMI_MAX_KEY_INDEX; index++) {
  286. if (vif->wep_key_list[index].key_len) {
  287. keyusage = GROUP_USAGE;
  288. if (index == vif->def_txkey_index)
  289. keyusage |= TX_USAGE;
  290. ath6kl_wmi_addkey_cmd(vif->ar->wmi, vif->fw_vif_idx,
  291. index,
  292. WEP_CRYPT,
  293. keyusage,
  294. vif->wep_key_list[index].key_len,
  295. NULL, 0,
  296. vif->wep_key_list[index].key,
  297. KEY_OP_INIT_VAL, NULL,
  298. NO_SYNC_WMIFLAG);
  299. }
  300. }
  301. }
  302. void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel)
  303. {
  304. struct ath6kl *ar = vif->ar;
  305. struct ath6kl_req_key *ik;
  306. int res;
  307. u8 key_rsc[ATH6KL_KEY_SEQ_LEN];
  308. ik = &ar->ap_mode_bkey;
  309. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", channel);
  310. switch (vif->auth_mode) {
  311. case NONE_AUTH:
  312. if (vif->prwise_crypto == WEP_CRYPT)
  313. ath6kl_install_static_wep_keys(vif);
  314. if (!ik->valid || ik->key_type != WAPI_CRYPT)
  315. break;
  316. /* for WAPI, we need to set the delayed group key, continue: */
  317. case WPA_PSK_AUTH:
  318. case WPA2_PSK_AUTH:
  319. case (WPA_PSK_AUTH | WPA2_PSK_AUTH):
  320. if (!ik->valid)
  321. break;
  322. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  323. "Delayed addkey for the initial group key for AP mode\n");
  324. memset(key_rsc, 0, sizeof(key_rsc));
  325. res = ath6kl_wmi_addkey_cmd(
  326. ar->wmi, vif->fw_vif_idx, ik->key_index, ik->key_type,
  327. GROUP_USAGE, ik->key_len, key_rsc, ATH6KL_KEY_SEQ_LEN,
  328. ik->key,
  329. KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG);
  330. if (res) {
  331. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
  332. "Delayed addkey failed: %d\n", res);
  333. }
  334. break;
  335. }
  336. if (ar->last_ch != channel)
  337. /* we actually don't know the phymode, default to HT20 */
  338. ath6kl_cfg80211_ch_switch_notify(vif, channel, WMI_11G_HT20);
  339. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0);
  340. set_bit(CONNECTED, &vif->flags);
  341. netif_carrier_on(vif->ndev);
  342. }
  343. void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
  344. u8 keymgmt, u8 ucipher, u8 auth,
  345. u8 assoc_req_len, u8 *assoc_info, u8 apsd_info)
  346. {
  347. u8 *ies = NULL, *wpa_ie = NULL, *pos;
  348. size_t ies_len = 0;
  349. struct station_info *sinfo;
  350. ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid);
  351. if (aid < 1 || aid > AP_MAX_NUM_STA)
  352. return;
  353. if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) {
  354. struct ieee80211_mgmt *mgmt =
  355. (struct ieee80211_mgmt *) assoc_info;
  356. if (ieee80211_is_assoc_req(mgmt->frame_control) &&
  357. assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) +
  358. sizeof(mgmt->u.assoc_req)) {
  359. ies = mgmt->u.assoc_req.variable;
  360. ies_len = assoc_info + assoc_req_len - ies;
  361. } else if (ieee80211_is_reassoc_req(mgmt->frame_control) &&
  362. assoc_req_len >= sizeof(struct ieee80211_hdr_3addr)
  363. + sizeof(mgmt->u.reassoc_req)) {
  364. ies = mgmt->u.reassoc_req.variable;
  365. ies_len = assoc_info + assoc_req_len - ies;
  366. }
  367. }
  368. pos = ies;
  369. while (pos && pos + 1 < ies + ies_len) {
  370. if (pos + 2 + pos[1] > ies + ies_len)
  371. break;
  372. if (pos[0] == WLAN_EID_RSN)
  373. wpa_ie = pos; /* RSN IE */
  374. else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  375. pos[1] >= 4 &&
  376. pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) {
  377. if (pos[5] == 0x01)
  378. wpa_ie = pos; /* WPA IE */
  379. else if (pos[5] == 0x04) {
  380. wpa_ie = pos; /* WPS IE */
  381. break; /* overrides WPA/RSN IE */
  382. }
  383. } else if (pos[0] == 0x44 && wpa_ie == NULL) {
  384. /*
  385. * Note: WAPI Parameter Set IE re-uses Element ID that
  386. * was officially allocated for BSS AC Access Delay. As
  387. * such, we need to be a bit more careful on when
  388. * parsing the frame. However, BSS AC Access Delay
  389. * element is not supposed to be included in
  390. * (Re)Association Request frames, so this should not
  391. * cause problems.
  392. */
  393. wpa_ie = pos; /* WAPI IE */
  394. break;
  395. }
  396. pos += 2 + pos[1];
  397. }
  398. ath6kl_add_new_sta(vif, mac_addr, aid, wpa_ie,
  399. wpa_ie ? 2 + wpa_ie[1] : 0,
  400. keymgmt, ucipher, auth, apsd_info);
  401. /* send event to application */
  402. sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
  403. if (!sinfo)
  404. return;
  405. /* TODO: sinfo.generation */
  406. sinfo->assoc_req_ies = ies;
  407. sinfo->assoc_req_ies_len = ies_len;
  408. cfg80211_new_sta(vif->ndev, mac_addr, sinfo, GFP_KERNEL);
  409. netif_wake_queue(vif->ndev);
  410. kfree(sinfo);
  411. }
  412. void disconnect_timer_handler(struct timer_list *t)
  413. {
  414. struct ath6kl_vif *vif = from_timer(vif, t, disconnect_timer);
  415. ath6kl_init_profile_info(vif);
  416. ath6kl_disconnect(vif);
  417. }
  418. void ath6kl_disconnect(struct ath6kl_vif *vif)
  419. {
  420. if (test_bit(CONNECTED, &vif->flags) ||
  421. test_bit(CONNECT_PEND, &vif->flags)) {
  422. ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
  423. /*
  424. * Disconnect command is issued, clear the connect pending
  425. * flag. The connected flag will be cleared in
  426. * disconnect event notification.
  427. */
  428. clear_bit(CONNECT_PEND, &vif->flags);
  429. }
  430. }
  431. /* WMI Event handlers */
  432. void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver,
  433. enum wmi_phy_cap cap)
  434. {
  435. struct ath6kl *ar = devt;
  436. memcpy(ar->mac_addr, datap, ETH_ALEN);
  437. ath6kl_dbg(ATH6KL_DBG_BOOT,
  438. "ready event mac addr %pM sw_ver 0x%x abi_ver 0x%x cap 0x%x\n",
  439. ar->mac_addr, sw_ver, abi_ver, cap);
  440. ar->version.wlan_ver = sw_ver;
  441. ar->version.abi_ver = abi_ver;
  442. ar->hw.cap = cap;
  443. if (strlen(ar->wiphy->fw_version) == 0) {
  444. snprintf(ar->wiphy->fw_version,
  445. sizeof(ar->wiphy->fw_version),
  446. "%u.%u.%u.%u",
  447. (ar->version.wlan_ver & 0xf0000000) >> 28,
  448. (ar->version.wlan_ver & 0x0f000000) >> 24,
  449. (ar->version.wlan_ver & 0x00ff0000) >> 16,
  450. (ar->version.wlan_ver & 0x0000ffff));
  451. }
  452. /* indicate to the waiting thread that the ready event was received */
  453. set_bit(WMI_READY, &ar->flag);
  454. wake_up(&ar->event_wq);
  455. }
  456. void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
  457. {
  458. struct ath6kl *ar = vif->ar;
  459. bool aborted = false;
  460. if (status != WMI_SCAN_STATUS_SUCCESS)
  461. aborted = true;
  462. ath6kl_cfg80211_scan_complete_event(vif, aborted);
  463. if (!ar->usr_bss_filter) {
  464. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  465. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  466. NONE_BSS_FILTER, 0);
  467. }
  468. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "scan complete: %d\n", status);
  469. }
  470. static int ath6kl_commit_ch_switch(struct ath6kl_vif *vif, u16 channel)
  471. {
  472. struct ath6kl *ar = vif->ar;
  473. vif->profile.ch = cpu_to_le16(channel);
  474. switch (vif->nw_type) {
  475. case AP_NETWORK:
  476. /*
  477. * reconfigure any saved RSN IE capabilites in the beacon /
  478. * probe response to stay in sync with the supplicant.
  479. */
  480. if (vif->rsn_capab &&
  481. test_bit(ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
  482. ar->fw_capabilities))
  483. ath6kl_wmi_set_ie_cmd(ar->wmi, vif->fw_vif_idx,
  484. WLAN_EID_RSN, WMI_RSN_IE_CAPB,
  485. (const u8 *) &vif->rsn_capab,
  486. sizeof(vif->rsn_capab));
  487. return ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx,
  488. &vif->profile);
  489. default:
  490. ath6kl_err("won't switch channels nw_type=%d\n", vif->nw_type);
  491. return -ENOTSUPP;
  492. }
  493. }
  494. static void ath6kl_check_ch_switch(struct ath6kl *ar, u16 channel)
  495. {
  496. struct ath6kl_vif *vif;
  497. int res = 0;
  498. if (!ar->want_ch_switch)
  499. return;
  500. spin_lock_bh(&ar->list_lock);
  501. list_for_each_entry(vif, &ar->vif_list, list) {
  502. if (ar->want_ch_switch & (1 << vif->fw_vif_idx))
  503. res = ath6kl_commit_ch_switch(vif, channel);
  504. /* if channel switch failed, oh well we tried */
  505. ar->want_ch_switch &= ~(1 << vif->fw_vif_idx);
  506. if (res)
  507. ath6kl_err("channel switch failed nw_type %d res %d\n",
  508. vif->nw_type, res);
  509. }
  510. spin_unlock_bh(&ar->list_lock);
  511. }
  512. void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid,
  513. u16 listen_int, u16 beacon_int,
  514. enum network_type net_type, u8 beacon_ie_len,
  515. u8 assoc_req_len, u8 assoc_resp_len,
  516. u8 *assoc_info)
  517. {
  518. struct ath6kl *ar = vif->ar;
  519. ath6kl_cfg80211_connect_event(vif, channel, bssid,
  520. listen_int, beacon_int,
  521. net_type, beacon_ie_len,
  522. assoc_req_len, assoc_resp_len,
  523. assoc_info);
  524. memcpy(vif->bssid, bssid, sizeof(vif->bssid));
  525. vif->bss_ch = channel;
  526. if ((vif->nw_type == INFRA_NETWORK)) {
  527. ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  528. vif->listen_intvl_t, 0);
  529. ath6kl_check_ch_switch(ar, channel);
  530. }
  531. netif_wake_queue(vif->ndev);
  532. /* Update connect & link status atomically */
  533. spin_lock_bh(&vif->if_lock);
  534. set_bit(CONNECTED, &vif->flags);
  535. clear_bit(CONNECT_PEND, &vif->flags);
  536. netif_carrier_on(vif->ndev);
  537. spin_unlock_bh(&vif->if_lock);
  538. aggr_reset_state(vif->aggr_cntxt->aggr_conn);
  539. vif->reconnect_flag = 0;
  540. if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
  541. memset(ar->node_map, 0, sizeof(ar->node_map));
  542. ar->node_num = 0;
  543. ar->next_ep_id = ENDPOINT_2;
  544. }
  545. if (!ar->usr_bss_filter) {
  546. set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  547. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  548. CURRENT_BSS_FILTER, 0);
  549. }
  550. }
  551. void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast)
  552. {
  553. struct ath6kl_sta *sta;
  554. struct ath6kl *ar = vif->ar;
  555. u8 tsc[6];
  556. /*
  557. * For AP case, keyid will have aid of STA which sent pkt with
  558. * MIC error. Use this aid to get MAC & send it to hostapd.
  559. */
  560. if (vif->nw_type == AP_NETWORK) {
  561. sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
  562. if (!sta)
  563. return;
  564. ath6kl_dbg(ATH6KL_DBG_TRC,
  565. "ap tkip mic error received from aid=%d\n", keyid);
  566. memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */
  567. cfg80211_michael_mic_failure(vif->ndev, sta->mac,
  568. NL80211_KEYTYPE_PAIRWISE, keyid,
  569. tsc, GFP_KERNEL);
  570. } else {
  571. ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast);
  572. }
  573. }
  574. static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
  575. {
  576. struct wmi_target_stats *tgt_stats =
  577. (struct wmi_target_stats *) ptr;
  578. struct ath6kl *ar = vif->ar;
  579. struct target_stats *stats = &vif->target_stats;
  580. struct tkip_ccmp_stats *ccmp_stats;
  581. s32 rate;
  582. u8 ac;
  583. if (len < sizeof(*tgt_stats))
  584. return;
  585. ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
  586. stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
  587. stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
  588. stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
  589. stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
  590. stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
  591. stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
  592. stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
  593. stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
  594. stats->tx_rts_success_cnt +=
  595. le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
  596. for (ac = 0; ac < WMM_NUM_AC; ac++)
  597. stats->tx_pkt_per_ac[ac] +=
  598. le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
  599. stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
  600. stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
  601. stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
  602. stats->tx_mult_retry_cnt +=
  603. le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
  604. stats->tx_rts_fail_cnt +=
  605. le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
  606. rate = a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate);
  607. stats->tx_ucast_rate = ath6kl_wmi_get_rate(ar->wmi, rate);
  608. stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
  609. stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
  610. stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
  611. stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
  612. stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
  613. stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
  614. stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
  615. stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
  616. stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
  617. stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
  618. stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
  619. stats->rx_key_cache_miss +=
  620. le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
  621. stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
  622. stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
  623. rate = a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate);
  624. stats->rx_ucast_rate = ath6kl_wmi_get_rate(ar->wmi, rate);
  625. ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
  626. stats->tkip_local_mic_fail +=
  627. le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
  628. stats->tkip_cnter_measures_invoked +=
  629. le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
  630. stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
  631. stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
  632. stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
  633. stats->pwr_save_fail_cnt +=
  634. le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
  635. stats->noise_floor_calib =
  636. a_sle32_to_cpu(tgt_stats->noise_floor_calib);
  637. stats->cs_bmiss_cnt +=
  638. le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
  639. stats->cs_low_rssi_cnt +=
  640. le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
  641. stats->cs_connect_cnt +=
  642. le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
  643. stats->cs_discon_cnt +=
  644. le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
  645. stats->cs_ave_beacon_rssi =
  646. a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
  647. stats->cs_last_roam_msec =
  648. tgt_stats->cserv_stats.cs_last_roam_msec;
  649. stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
  650. stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
  651. stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
  652. stats->wow_pkt_dropped +=
  653. le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
  654. stats->wow_host_pkt_wakeups +=
  655. tgt_stats->wow_stats.wow_host_pkt_wakeups;
  656. stats->wow_host_evt_wakeups +=
  657. tgt_stats->wow_stats.wow_host_evt_wakeups;
  658. stats->wow_evt_discarded +=
  659. le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
  660. stats->arp_received = le32_to_cpu(tgt_stats->arp_stats.arp_received);
  661. stats->arp_replied = le32_to_cpu(tgt_stats->arp_stats.arp_replied);
  662. stats->arp_matched = le32_to_cpu(tgt_stats->arp_stats.arp_matched);
  663. if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
  664. clear_bit(STATS_UPDATE_PEND, &vif->flags);
  665. wake_up(&ar->event_wq);
  666. }
  667. }
  668. static void ath6kl_add_le32(__le32 *var, __le32 val)
  669. {
  670. *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
  671. }
  672. void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len)
  673. {
  674. struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
  675. struct ath6kl *ar = vif->ar;
  676. struct wmi_ap_mode_stat *ap = &ar->ap_stats;
  677. struct wmi_per_sta_stat *st_ap, *st_p;
  678. u8 ac;
  679. if (vif->nw_type == AP_NETWORK) {
  680. if (len < sizeof(*p))
  681. return;
  682. for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
  683. st_ap = &ap->sta[ac];
  684. st_p = &p->sta[ac];
  685. ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
  686. ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
  687. ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
  688. ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
  689. ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
  690. ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
  691. ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
  692. ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
  693. }
  694. } else {
  695. ath6kl_update_target_stats(vif, ptr, len);
  696. }
  697. }
  698. void ath6kl_wakeup_event(void *dev)
  699. {
  700. struct ath6kl *ar = (struct ath6kl *) dev;
  701. wake_up(&ar->event_wq);
  702. }
  703. void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
  704. {
  705. struct ath6kl *ar = (struct ath6kl *) devt;
  706. ar->tx_pwr = tx_pwr;
  707. wake_up(&ar->event_wq);
  708. }
  709. void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid)
  710. {
  711. struct ath6kl_sta *conn;
  712. struct sk_buff *skb;
  713. bool psq_empty = false;
  714. struct ath6kl *ar = vif->ar;
  715. struct ath6kl_mgmt_buff *mgmt_buf;
  716. conn = ath6kl_find_sta_by_aid(ar, aid);
  717. if (!conn)
  718. return;
  719. /*
  720. * Send out a packet queued on ps queue. When the ps queue
  721. * becomes empty update the PVB for this station.
  722. */
  723. spin_lock_bh(&conn->psq_lock);
  724. psq_empty = skb_queue_empty(&conn->psq) && (conn->mgmt_psq_len == 0);
  725. spin_unlock_bh(&conn->psq_lock);
  726. if (psq_empty)
  727. /* TODO: Send out a NULL data frame */
  728. return;
  729. spin_lock_bh(&conn->psq_lock);
  730. if (conn->mgmt_psq_len > 0) {
  731. mgmt_buf = list_first_entry(&conn->mgmt_psq,
  732. struct ath6kl_mgmt_buff, list);
  733. list_del(&mgmt_buf->list);
  734. conn->mgmt_psq_len--;
  735. spin_unlock_bh(&conn->psq_lock);
  736. conn->sta_flags |= STA_PS_POLLED;
  737. ath6kl_wmi_send_mgmt_cmd(ar->wmi, vif->fw_vif_idx,
  738. mgmt_buf->id, mgmt_buf->freq,
  739. mgmt_buf->wait, mgmt_buf->buf,
  740. mgmt_buf->len, mgmt_buf->no_cck);
  741. conn->sta_flags &= ~STA_PS_POLLED;
  742. kfree(mgmt_buf);
  743. } else {
  744. skb = skb_dequeue(&conn->psq);
  745. spin_unlock_bh(&conn->psq_lock);
  746. conn->sta_flags |= STA_PS_POLLED;
  747. ath6kl_data_tx(skb, vif->ndev);
  748. conn->sta_flags &= ~STA_PS_POLLED;
  749. }
  750. spin_lock_bh(&conn->psq_lock);
  751. psq_empty = skb_queue_empty(&conn->psq) && (conn->mgmt_psq_len == 0);
  752. spin_unlock_bh(&conn->psq_lock);
  753. if (psq_empty)
  754. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, conn->aid, 0);
  755. }
  756. void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif)
  757. {
  758. bool mcastq_empty = false;
  759. struct sk_buff *skb;
  760. struct ath6kl *ar = vif->ar;
  761. /*
  762. * If there are no associated STAs, ignore the DTIM expiry event.
  763. * There can be potential race conditions where the last associated
  764. * STA may disconnect & before the host could clear the 'Indicate
  765. * DTIM' request to the firmware, the firmware would have just
  766. * indicated a DTIM expiry event. The race is between 'clear DTIM
  767. * expiry cmd' going from the host to the firmware & the DTIM
  768. * expiry event happening from the firmware to the host.
  769. */
  770. if (!ar->sta_list_index)
  771. return;
  772. spin_lock_bh(&ar->mcastpsq_lock);
  773. mcastq_empty = skb_queue_empty(&ar->mcastpsq);
  774. spin_unlock_bh(&ar->mcastpsq_lock);
  775. if (mcastq_empty)
  776. return;
  777. /* set the STA flag to dtim_expired for the frame to go out */
  778. set_bit(DTIM_EXPIRED, &vif->flags);
  779. spin_lock_bh(&ar->mcastpsq_lock);
  780. while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
  781. spin_unlock_bh(&ar->mcastpsq_lock);
  782. ath6kl_data_tx(skb, vif->ndev);
  783. spin_lock_bh(&ar->mcastpsq_lock);
  784. }
  785. spin_unlock_bh(&ar->mcastpsq_lock);
  786. clear_bit(DTIM_EXPIRED, &vif->flags);
  787. /* clear the LSB of the BitMapCtl field of the TIM IE */
  788. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, MCAST_AID, 0);
  789. }
  790. void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *bssid,
  791. u8 assoc_resp_len, u8 *assoc_info,
  792. u16 prot_reason_status)
  793. {
  794. struct ath6kl *ar = vif->ar;
  795. if (vif->nw_type == AP_NETWORK) {
  796. /* disconnect due to other STA vif switching channels */
  797. if (reason == BSS_DISCONNECTED &&
  798. prot_reason_status == WMI_AP_REASON_STA_ROAM) {
  799. ar->want_ch_switch |= 1 << vif->fw_vif_idx;
  800. /* bail back to this channel if STA vif fails connect */
  801. ar->last_ch = le16_to_cpu(vif->profile.ch);
  802. }
  803. if (prot_reason_status == WMI_AP_REASON_MAX_STA) {
  804. /* send max client reached notification to user space */
  805. cfg80211_conn_failed(vif->ndev, bssid,
  806. NL80211_CONN_FAIL_MAX_CLIENTS,
  807. GFP_KERNEL);
  808. }
  809. if (prot_reason_status == WMI_AP_REASON_ACL) {
  810. /* send blocked client notification to user space */
  811. cfg80211_conn_failed(vif->ndev, bssid,
  812. NL80211_CONN_FAIL_BLOCKED_CLIENT,
  813. GFP_KERNEL);
  814. }
  815. if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
  816. return;
  817. /* if no more associated STAs, empty the mcast PS q */
  818. if (ar->sta_list_index == 0) {
  819. spin_lock_bh(&ar->mcastpsq_lock);
  820. skb_queue_purge(&ar->mcastpsq);
  821. spin_unlock_bh(&ar->mcastpsq_lock);
  822. /* clear the LSB of the TIM IE's BitMapCtl field */
  823. if (test_bit(WMI_READY, &ar->flag))
  824. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
  825. MCAST_AID, 0);
  826. }
  827. if (!is_broadcast_ether_addr(bssid)) {
  828. /* send event to application */
  829. cfg80211_del_sta(vif->ndev, bssid, GFP_KERNEL);
  830. }
  831. if (memcmp(vif->ndev->dev_addr, bssid, ETH_ALEN) == 0) {
  832. memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
  833. clear_bit(CONNECTED, &vif->flags);
  834. }
  835. return;
  836. }
  837. ath6kl_cfg80211_disconnect_event(vif, reason, bssid,
  838. assoc_resp_len, assoc_info,
  839. prot_reason_status);
  840. aggr_reset_state(vif->aggr_cntxt->aggr_conn);
  841. del_timer(&vif->disconnect_timer);
  842. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "disconnect reason is %d\n", reason);
  843. /*
  844. * If the event is due to disconnect cmd from the host, only they
  845. * the target would stop trying to connect. Under any other
  846. * condition, target would keep trying to connect.
  847. */
  848. if (reason == DISCONNECT_CMD) {
  849. if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
  850. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  851. NONE_BSS_FILTER, 0);
  852. } else {
  853. set_bit(CONNECT_PEND, &vif->flags);
  854. if (((reason == ASSOC_FAILED) &&
  855. (prot_reason_status == 0x11)) ||
  856. ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0) &&
  857. (vif->reconnect_flag == 1))) {
  858. set_bit(CONNECTED, &vif->flags);
  859. return;
  860. }
  861. }
  862. /* restart disconnected concurrent vifs waiting for new channel */
  863. ath6kl_check_ch_switch(ar, ar->last_ch);
  864. /* update connect & link status atomically */
  865. spin_lock_bh(&vif->if_lock);
  866. clear_bit(CONNECTED, &vif->flags);
  867. netif_carrier_off(vif->ndev);
  868. spin_unlock_bh(&vif->if_lock);
  869. if ((reason != CSERV_DISCONNECT) || (vif->reconnect_flag != 1))
  870. vif->reconnect_flag = 0;
  871. if (reason != CSERV_DISCONNECT)
  872. ar->user_key_ctrl = 0;
  873. netif_stop_queue(vif->ndev);
  874. memset(vif->bssid, 0, sizeof(vif->bssid));
  875. vif->bss_ch = 0;
  876. ath6kl_tx_data_cleanup(ar);
  877. }
  878. struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar)
  879. {
  880. struct ath6kl_vif *vif;
  881. spin_lock_bh(&ar->list_lock);
  882. if (list_empty(&ar->vif_list)) {
  883. spin_unlock_bh(&ar->list_lock);
  884. return NULL;
  885. }
  886. vif = list_first_entry(&ar->vif_list, struct ath6kl_vif, list);
  887. spin_unlock_bh(&ar->list_lock);
  888. return vif;
  889. }
  890. static int ath6kl_open(struct net_device *dev)
  891. {
  892. struct ath6kl_vif *vif = netdev_priv(dev);
  893. set_bit(WLAN_ENABLED, &vif->flags);
  894. if (test_bit(CONNECTED, &vif->flags)) {
  895. netif_carrier_on(dev);
  896. netif_wake_queue(dev);
  897. } else {
  898. netif_carrier_off(dev);
  899. }
  900. return 0;
  901. }
  902. static int ath6kl_close(struct net_device *dev)
  903. {
  904. struct ath6kl_vif *vif = netdev_priv(dev);
  905. netif_stop_queue(dev);
  906. ath6kl_cfg80211_stop(vif);
  907. clear_bit(WLAN_ENABLED, &vif->flags);
  908. return 0;
  909. }
  910. static int ath6kl_set_features(struct net_device *dev,
  911. netdev_features_t features)
  912. {
  913. struct ath6kl_vif *vif = netdev_priv(dev);
  914. struct ath6kl *ar = vif->ar;
  915. int err = 0;
  916. if ((features & NETIF_F_RXCSUM) &&
  917. (ar->rx_meta_ver != WMI_META_VERSION_2)) {
  918. ar->rx_meta_ver = WMI_META_VERSION_2;
  919. err = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
  920. vif->fw_vif_idx,
  921. ar->rx_meta_ver, 0, 0);
  922. if (err) {
  923. dev->features = features & ~NETIF_F_RXCSUM;
  924. return err;
  925. }
  926. } else if (!(features & NETIF_F_RXCSUM) &&
  927. (ar->rx_meta_ver == WMI_META_VERSION_2)) {
  928. ar->rx_meta_ver = 0;
  929. err = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
  930. vif->fw_vif_idx,
  931. ar->rx_meta_ver, 0, 0);
  932. if (err) {
  933. dev->features = features | NETIF_F_RXCSUM;
  934. return err;
  935. }
  936. }
  937. return err;
  938. }
  939. static void ath6kl_set_multicast_list(struct net_device *ndev)
  940. {
  941. struct ath6kl_vif *vif = netdev_priv(ndev);
  942. bool mc_all_on = false;
  943. int mc_count = netdev_mc_count(ndev);
  944. struct netdev_hw_addr *ha;
  945. bool found;
  946. struct ath6kl_mc_filter *mc_filter, *tmp;
  947. struct list_head mc_filter_new;
  948. int ret;
  949. if (!test_bit(WMI_READY, &vif->ar->flag) ||
  950. !test_bit(WLAN_ENABLED, &vif->flags))
  951. return;
  952. /* Enable multicast-all filter. */
  953. mc_all_on = !!(ndev->flags & IFF_PROMISC) ||
  954. !!(ndev->flags & IFF_ALLMULTI) ||
  955. !!(mc_count > ATH6K_MAX_MC_FILTERS_PER_LIST);
  956. if (mc_all_on)
  957. set_bit(NETDEV_MCAST_ALL_ON, &vif->flags);
  958. else
  959. clear_bit(NETDEV_MCAST_ALL_ON, &vif->flags);
  960. if (test_bit(ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER,
  961. vif->ar->fw_capabilities)) {
  962. mc_all_on = mc_all_on || (vif->ar->state == ATH6KL_STATE_ON);
  963. }
  964. if (!(ndev->flags & IFF_MULTICAST)) {
  965. mc_all_on = false;
  966. set_bit(NETDEV_MCAST_ALL_OFF, &vif->flags);
  967. } else {
  968. clear_bit(NETDEV_MCAST_ALL_OFF, &vif->flags);
  969. }
  970. /* Enable/disable "multicast-all" filter*/
  971. ath6kl_dbg(ATH6KL_DBG_TRC, "%s multicast-all filter\n",
  972. mc_all_on ? "enabling" : "disabling");
  973. ret = ath6kl_wmi_mcast_filter_cmd(vif->ar->wmi, vif->fw_vif_idx,
  974. mc_all_on);
  975. if (ret) {
  976. ath6kl_warn("Failed to %s multicast-all receive\n",
  977. mc_all_on ? "enable" : "disable");
  978. return;
  979. }
  980. if (test_bit(NETDEV_MCAST_ALL_ON, &vif->flags))
  981. return;
  982. /* Keep the driver and firmware mcast list in sync. */
  983. list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) {
  984. found = false;
  985. netdev_for_each_mc_addr(ha, ndev) {
  986. if (memcmp(ha->addr, mc_filter->hw_addr,
  987. ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE) == 0) {
  988. found = true;
  989. break;
  990. }
  991. }
  992. if (!found) {
  993. /*
  994. * Delete the filter which was previously set
  995. * but not in the new request.
  996. */
  997. ath6kl_dbg(ATH6KL_DBG_TRC,
  998. "Removing %pM from multicast filter\n",
  999. mc_filter->hw_addr);
  1000. ret = ath6kl_wmi_add_del_mcast_filter_cmd(vif->ar->wmi,
  1001. vif->fw_vif_idx, mc_filter->hw_addr,
  1002. false);
  1003. if (ret) {
  1004. ath6kl_warn("Failed to remove multicast filter:%pM\n",
  1005. mc_filter->hw_addr);
  1006. return;
  1007. }
  1008. list_del(&mc_filter->list);
  1009. kfree(mc_filter);
  1010. }
  1011. }
  1012. INIT_LIST_HEAD(&mc_filter_new);
  1013. netdev_for_each_mc_addr(ha, ndev) {
  1014. found = false;
  1015. list_for_each_entry(mc_filter, &vif->mc_filter, list) {
  1016. if (memcmp(ha->addr, mc_filter->hw_addr,
  1017. ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE) == 0) {
  1018. found = true;
  1019. break;
  1020. }
  1021. }
  1022. if (!found) {
  1023. mc_filter = kzalloc(sizeof(struct ath6kl_mc_filter),
  1024. GFP_ATOMIC);
  1025. if (!mc_filter) {
  1026. WARN_ON(1);
  1027. goto out;
  1028. }
  1029. memcpy(mc_filter->hw_addr, ha->addr,
  1030. ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
  1031. /* Set the multicast filter */
  1032. ath6kl_dbg(ATH6KL_DBG_TRC,
  1033. "Adding %pM to multicast filter list\n",
  1034. mc_filter->hw_addr);
  1035. ret = ath6kl_wmi_add_del_mcast_filter_cmd(vif->ar->wmi,
  1036. vif->fw_vif_idx, mc_filter->hw_addr,
  1037. true);
  1038. if (ret) {
  1039. ath6kl_warn("Failed to add multicast filter :%pM\n",
  1040. mc_filter->hw_addr);
  1041. kfree(mc_filter);
  1042. goto out;
  1043. }
  1044. list_add_tail(&mc_filter->list, &mc_filter_new);
  1045. }
  1046. }
  1047. out:
  1048. list_splice_tail(&mc_filter_new, &vif->mc_filter);
  1049. }
  1050. static const struct net_device_ops ath6kl_netdev_ops = {
  1051. .ndo_open = ath6kl_open,
  1052. .ndo_stop = ath6kl_close,
  1053. .ndo_start_xmit = ath6kl_data_tx,
  1054. .ndo_set_features = ath6kl_set_features,
  1055. .ndo_set_rx_mode = ath6kl_set_multicast_list,
  1056. };
  1057. void init_netdev(struct net_device *dev)
  1058. {
  1059. struct ath6kl *ar = ath6kl_priv(dev);
  1060. dev->netdev_ops = &ath6kl_netdev_ops;
  1061. dev->needs_free_netdev = true;
  1062. dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
  1063. dev->needed_headroom = ETH_HLEN;
  1064. dev->needed_headroom += roundup(sizeof(struct ath6kl_llc_snap_hdr) +
  1065. sizeof(struct wmi_data_hdr) +
  1066. HTC_HDR_LENGTH +
  1067. WMI_MAX_TX_META_SZ +
  1068. ATH6KL_HTC_ALIGN_BYTES, 4);
  1069. if (!test_bit(ATH6KL_FW_CAPABILITY_NO_IP_CHECKSUM,
  1070. ar->fw_capabilities))
  1071. dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
  1072. return;
  1073. }