main.c 34 KB

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