main.c 31 KB

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