main.c 31 KB

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