main.c 27 KB

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