main.c 31 KB

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