main.c 34 KB

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