main.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  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. if (!ik->valid || ik->key_type != WAPI_CRYPT)
  322. break;
  323. /* for WAPI, we need to set the delayed group key, continue: */
  324. case WPA_PSK_AUTH:
  325. case WPA2_PSK_AUTH:
  326. case (WPA_PSK_AUTH | WPA2_PSK_AUTH):
  327. if (!ik->valid)
  328. break;
  329. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey for "
  330. "the initial group key for AP mode\n");
  331. memset(key_rsc, 0, sizeof(key_rsc));
  332. res = ath6kl_wmi_addkey_cmd(
  333. ar->wmi, vif->fw_vif_idx, ik->key_index, ik->key_type,
  334. GROUP_USAGE, ik->key_len, key_rsc, ATH6KL_KEY_SEQ_LEN,
  335. ik->key,
  336. KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG);
  337. if (res) {
  338. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed "
  339. "addkey failed: %d\n", res);
  340. }
  341. break;
  342. }
  343. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0);
  344. set_bit(CONNECTED, &vif->flags);
  345. netif_carrier_on(vif->ndev);
  346. }
  347. void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
  348. u8 keymgmt, u8 ucipher, u8 auth,
  349. u8 assoc_req_len, u8 *assoc_info)
  350. {
  351. struct ath6kl *ar = vif->ar;
  352. u8 *ies = NULL, *wpa_ie = NULL, *pos;
  353. size_t ies_len = 0;
  354. struct station_info sinfo;
  355. ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid);
  356. if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) {
  357. struct ieee80211_mgmt *mgmt =
  358. (struct ieee80211_mgmt *) assoc_info;
  359. if (ieee80211_is_assoc_req(mgmt->frame_control) &&
  360. assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) +
  361. sizeof(mgmt->u.assoc_req)) {
  362. ies = mgmt->u.assoc_req.variable;
  363. ies_len = assoc_info + assoc_req_len - ies;
  364. } else if (ieee80211_is_reassoc_req(mgmt->frame_control) &&
  365. assoc_req_len >= sizeof(struct ieee80211_hdr_3addr)
  366. + sizeof(mgmt->u.reassoc_req)) {
  367. ies = mgmt->u.reassoc_req.variable;
  368. ies_len = assoc_info + assoc_req_len - ies;
  369. }
  370. }
  371. pos = ies;
  372. while (pos && pos + 1 < ies + ies_len) {
  373. if (pos + 2 + pos[1] > ies + ies_len)
  374. break;
  375. if (pos[0] == WLAN_EID_RSN)
  376. wpa_ie = pos; /* RSN IE */
  377. else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  378. pos[1] >= 4 &&
  379. pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) {
  380. if (pos[5] == 0x01)
  381. wpa_ie = pos; /* WPA IE */
  382. else if (pos[5] == 0x04) {
  383. wpa_ie = pos; /* WPS IE */
  384. break; /* overrides WPA/RSN IE */
  385. }
  386. } else if (pos[0] == 0x44 && wpa_ie == NULL) {
  387. /*
  388. * Note: WAPI Parameter Set IE re-uses Element ID that
  389. * was officially allocated for BSS AC Access Delay. As
  390. * such, we need to be a bit more careful on when
  391. * parsing the frame. However, BSS AC Access Delay
  392. * element is not supposed to be included in
  393. * (Re)Association Request frames, so this should not
  394. * cause problems.
  395. */
  396. wpa_ie = pos; /* WAPI IE */
  397. break;
  398. }
  399. pos += 2 + pos[1];
  400. }
  401. ath6kl_add_new_sta(ar, mac_addr, aid, wpa_ie,
  402. wpa_ie ? 2 + wpa_ie[1] : 0,
  403. keymgmt, ucipher, auth);
  404. /* send event to application */
  405. memset(&sinfo, 0, sizeof(sinfo));
  406. /* TODO: sinfo.generation */
  407. sinfo.assoc_req_ies = ies;
  408. sinfo.assoc_req_ies_len = ies_len;
  409. sinfo.filled |= STATION_INFO_ASSOC_REQ_IES;
  410. cfg80211_new_sta(vif->ndev, mac_addr, &sinfo, GFP_KERNEL);
  411. netif_wake_queue(vif->ndev);
  412. }
  413. void disconnect_timer_handler(unsigned long ptr)
  414. {
  415. struct net_device *dev = (struct net_device *)ptr;
  416. struct ath6kl_vif *vif = netdev_priv(dev);
  417. ath6kl_init_profile_info(vif);
  418. ath6kl_disconnect(vif);
  419. }
  420. void ath6kl_disconnect(struct ath6kl_vif *vif)
  421. {
  422. if (test_bit(CONNECTED, &vif->flags) ||
  423. test_bit(CONNECT_PEND, &vif->flags)) {
  424. ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
  425. /*
  426. * Disconnect command is issued, clear the connect pending
  427. * flag. The connected flag will be cleared in
  428. * disconnect event notification.
  429. */
  430. clear_bit(CONNECT_PEND, &vif->flags);
  431. }
  432. }
  433. /* WMI Event handlers */
  434. void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver)
  435. {
  436. struct ath6kl *ar = devt;
  437. memcpy(ar->mac_addr, datap, ETH_ALEN);
  438. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n",
  439. __func__, ar->mac_addr);
  440. ar->version.wlan_ver = sw_ver;
  441. ar->version.abi_ver = abi_ver;
  442. snprintf(ar->wiphy->fw_version,
  443. sizeof(ar->wiphy->fw_version),
  444. "%u.%u.%u.%u",
  445. (ar->version.wlan_ver & 0xf0000000) >> 28,
  446. (ar->version.wlan_ver & 0x0f000000) >> 24,
  447. (ar->version.wlan_ver & 0x00ff0000) >> 16,
  448. (ar->version.wlan_ver & 0x0000ffff));
  449. /* indicate to the waiting thread that the ready event was received */
  450. set_bit(WMI_READY, &ar->flag);
  451. wake_up(&ar->event_wq);
  452. }
  453. void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
  454. {
  455. struct ath6kl *ar = vif->ar;
  456. bool aborted = false;
  457. if (status != WMI_SCAN_STATUS_SUCCESS)
  458. aborted = true;
  459. ath6kl_cfg80211_scan_complete_event(vif, aborted);
  460. if (!ar->usr_bss_filter) {
  461. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  462. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  463. NONE_BSS_FILTER, 0);
  464. }
  465. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "scan complete: %d\n", status);
  466. }
  467. void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid,
  468. u16 listen_int, u16 beacon_int,
  469. enum network_type net_type, u8 beacon_ie_len,
  470. u8 assoc_req_len, u8 assoc_resp_len,
  471. u8 *assoc_info)
  472. {
  473. struct ath6kl *ar = vif->ar;
  474. ath6kl_cfg80211_connect_event(vif, channel, bssid,
  475. listen_int, beacon_int,
  476. net_type, beacon_ie_len,
  477. assoc_req_len, assoc_resp_len,
  478. assoc_info);
  479. memcpy(vif->bssid, bssid, sizeof(vif->bssid));
  480. vif->bss_ch = channel;
  481. if ((vif->nw_type == INFRA_NETWORK))
  482. ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  483. ar->listen_intvl_t,
  484. ar->listen_intvl_b);
  485. netif_wake_queue(vif->ndev);
  486. /* Update connect & link status atomically */
  487. spin_lock_bh(&vif->if_lock);
  488. set_bit(CONNECTED, &vif->flags);
  489. clear_bit(CONNECT_PEND, &vif->flags);
  490. netif_carrier_on(vif->ndev);
  491. spin_unlock_bh(&vif->if_lock);
  492. aggr_reset_state(vif->aggr_cntxt);
  493. vif->reconnect_flag = 0;
  494. if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
  495. memset(ar->node_map, 0, sizeof(ar->node_map));
  496. ar->node_num = 0;
  497. ar->next_ep_id = ENDPOINT_2;
  498. }
  499. if (!ar->usr_bss_filter) {
  500. set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  501. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  502. CURRENT_BSS_FILTER, 0);
  503. }
  504. }
  505. void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast)
  506. {
  507. struct ath6kl_sta *sta;
  508. struct ath6kl *ar = vif->ar;
  509. u8 tsc[6];
  510. /*
  511. * For AP case, keyid will have aid of STA which sent pkt with
  512. * MIC error. Use this aid to get MAC & send it to hostapd.
  513. */
  514. if (vif->nw_type == AP_NETWORK) {
  515. sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
  516. if (!sta)
  517. return;
  518. ath6kl_dbg(ATH6KL_DBG_TRC,
  519. "ap tkip mic error received from aid=%d\n", keyid);
  520. memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */
  521. cfg80211_michael_mic_failure(vif->ndev, sta->mac,
  522. NL80211_KEYTYPE_PAIRWISE, keyid,
  523. tsc, GFP_KERNEL);
  524. } else
  525. ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast);
  526. }
  527. static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
  528. {
  529. struct wmi_target_stats *tgt_stats =
  530. (struct wmi_target_stats *) ptr;
  531. struct ath6kl *ar = vif->ar;
  532. struct target_stats *stats = &vif->target_stats;
  533. struct tkip_ccmp_stats *ccmp_stats;
  534. u8 ac;
  535. if (len < sizeof(*tgt_stats))
  536. return;
  537. ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
  538. stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
  539. stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
  540. stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
  541. stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
  542. stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
  543. stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
  544. stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
  545. stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
  546. stats->tx_rts_success_cnt +=
  547. le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
  548. for (ac = 0; ac < WMM_NUM_AC; ac++)
  549. stats->tx_pkt_per_ac[ac] +=
  550. le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
  551. stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
  552. stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
  553. stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
  554. stats->tx_mult_retry_cnt +=
  555. le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
  556. stats->tx_rts_fail_cnt +=
  557. le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
  558. stats->tx_ucast_rate =
  559. ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate));
  560. stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
  561. stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
  562. stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
  563. stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
  564. stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
  565. stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
  566. stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
  567. stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
  568. stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
  569. stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
  570. stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
  571. stats->rx_key_cache_miss +=
  572. le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
  573. stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
  574. stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
  575. stats->rx_ucast_rate =
  576. ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate));
  577. ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
  578. stats->tkip_local_mic_fail +=
  579. le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
  580. stats->tkip_cnter_measures_invoked +=
  581. le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
  582. stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
  583. stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
  584. stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
  585. stats->pwr_save_fail_cnt +=
  586. le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
  587. stats->noise_floor_calib =
  588. a_sle32_to_cpu(tgt_stats->noise_floor_calib);
  589. stats->cs_bmiss_cnt +=
  590. le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
  591. stats->cs_low_rssi_cnt +=
  592. le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
  593. stats->cs_connect_cnt +=
  594. le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
  595. stats->cs_discon_cnt +=
  596. le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
  597. stats->cs_ave_beacon_rssi =
  598. a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
  599. stats->cs_last_roam_msec =
  600. tgt_stats->cserv_stats.cs_last_roam_msec;
  601. stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
  602. stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
  603. stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
  604. stats->wow_pkt_dropped +=
  605. le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
  606. stats->wow_host_pkt_wakeups +=
  607. tgt_stats->wow_stats.wow_host_pkt_wakeups;
  608. stats->wow_host_evt_wakeups +=
  609. tgt_stats->wow_stats.wow_host_evt_wakeups;
  610. stats->wow_evt_discarded +=
  611. le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
  612. if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
  613. clear_bit(STATS_UPDATE_PEND, &vif->flags);
  614. wake_up(&ar->event_wq);
  615. }
  616. }
  617. static void ath6kl_add_le32(__le32 *var, __le32 val)
  618. {
  619. *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
  620. }
  621. void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len)
  622. {
  623. struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
  624. struct ath6kl *ar = vif->ar;
  625. struct wmi_ap_mode_stat *ap = &ar->ap_stats;
  626. struct wmi_per_sta_stat *st_ap, *st_p;
  627. u8 ac;
  628. if (vif->nw_type == AP_NETWORK) {
  629. if (len < sizeof(*p))
  630. return;
  631. for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
  632. st_ap = &ap->sta[ac];
  633. st_p = &p->sta[ac];
  634. ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
  635. ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
  636. ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
  637. ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
  638. ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
  639. ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
  640. ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
  641. ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
  642. }
  643. } else {
  644. ath6kl_update_target_stats(vif, ptr, len);
  645. }
  646. }
  647. void ath6kl_wakeup_event(void *dev)
  648. {
  649. struct ath6kl *ar = (struct ath6kl *) dev;
  650. wake_up(&ar->event_wq);
  651. }
  652. void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
  653. {
  654. struct ath6kl *ar = (struct ath6kl *) devt;
  655. ar->tx_pwr = tx_pwr;
  656. wake_up(&ar->event_wq);
  657. }
  658. void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid)
  659. {
  660. struct ath6kl_sta *conn;
  661. struct sk_buff *skb;
  662. bool psq_empty = false;
  663. struct ath6kl *ar = vif->ar;
  664. conn = ath6kl_find_sta_by_aid(ar, aid);
  665. if (!conn)
  666. return;
  667. /*
  668. * Send out a packet queued on ps queue. When the ps queue
  669. * becomes empty update the PVB for this station.
  670. */
  671. spin_lock_bh(&conn->psq_lock);
  672. psq_empty = skb_queue_empty(&conn->psq);
  673. spin_unlock_bh(&conn->psq_lock);
  674. if (psq_empty)
  675. /* TODO: Send out a NULL data frame */
  676. return;
  677. spin_lock_bh(&conn->psq_lock);
  678. skb = skb_dequeue(&conn->psq);
  679. spin_unlock_bh(&conn->psq_lock);
  680. conn->sta_flags |= STA_PS_POLLED;
  681. ath6kl_data_tx(skb, vif->ndev);
  682. conn->sta_flags &= ~STA_PS_POLLED;
  683. spin_lock_bh(&conn->psq_lock);
  684. psq_empty = skb_queue_empty(&conn->psq);
  685. spin_unlock_bh(&conn->psq_lock);
  686. if (psq_empty)
  687. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, conn->aid, 0);
  688. }
  689. void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif)
  690. {
  691. bool mcastq_empty = false;
  692. struct sk_buff *skb;
  693. struct ath6kl *ar = vif->ar;
  694. /*
  695. * If there are no associated STAs, ignore the DTIM expiry event.
  696. * There can be potential race conditions where the last associated
  697. * STA may disconnect & before the host could clear the 'Indicate
  698. * DTIM' request to the firmware, the firmware would have just
  699. * indicated a DTIM expiry event. The race is between 'clear DTIM
  700. * expiry cmd' going from the host to the firmware & the DTIM
  701. * expiry event happening from the firmware to the host.
  702. */
  703. if (!ar->sta_list_index)
  704. return;
  705. spin_lock_bh(&ar->mcastpsq_lock);
  706. mcastq_empty = skb_queue_empty(&ar->mcastpsq);
  707. spin_unlock_bh(&ar->mcastpsq_lock);
  708. if (mcastq_empty)
  709. return;
  710. /* set the STA flag to dtim_expired for the frame to go out */
  711. set_bit(DTIM_EXPIRED, &vif->flags);
  712. spin_lock_bh(&ar->mcastpsq_lock);
  713. while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
  714. spin_unlock_bh(&ar->mcastpsq_lock);
  715. ath6kl_data_tx(skb, vif->ndev);
  716. spin_lock_bh(&ar->mcastpsq_lock);
  717. }
  718. spin_unlock_bh(&ar->mcastpsq_lock);
  719. clear_bit(DTIM_EXPIRED, &vif->flags);
  720. /* clear the LSB of the BitMapCtl field of the TIM IE */
  721. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, MCAST_AID, 0);
  722. }
  723. void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *bssid,
  724. u8 assoc_resp_len, u8 *assoc_info,
  725. u16 prot_reason_status)
  726. {
  727. struct ath6kl *ar = vif->ar;
  728. if (vif->nw_type == AP_NETWORK) {
  729. if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
  730. return;
  731. /* if no more associated STAs, empty the mcast PS q */
  732. if (ar->sta_list_index == 0) {
  733. spin_lock_bh(&ar->mcastpsq_lock);
  734. skb_queue_purge(&ar->mcastpsq);
  735. spin_unlock_bh(&ar->mcastpsq_lock);
  736. /* clear the LSB of the TIM IE's BitMapCtl field */
  737. if (test_bit(WMI_READY, &ar->flag))
  738. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
  739. MCAST_AID, 0);
  740. }
  741. if (!is_broadcast_ether_addr(bssid)) {
  742. /* send event to application */
  743. cfg80211_del_sta(vif->ndev, bssid, GFP_KERNEL);
  744. }
  745. if (memcmp(vif->ndev->dev_addr, bssid, ETH_ALEN) == 0) {
  746. memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
  747. clear_bit(CONNECTED, &vif->flags);
  748. }
  749. return;
  750. }
  751. ath6kl_cfg80211_disconnect_event(vif, reason, bssid,
  752. assoc_resp_len, assoc_info,
  753. prot_reason_status);
  754. aggr_reset_state(vif->aggr_cntxt);
  755. del_timer(&vif->disconnect_timer);
  756. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "disconnect reason is %d\n", reason);
  757. /*
  758. * If the event is due to disconnect cmd from the host, only they
  759. * the target would stop trying to connect. Under any other
  760. * condition, target would keep trying to connect.
  761. */
  762. if (reason == DISCONNECT_CMD) {
  763. if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
  764. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  765. NONE_BSS_FILTER, 0);
  766. } else {
  767. set_bit(CONNECT_PEND, &vif->flags);
  768. if (((reason == ASSOC_FAILED) &&
  769. (prot_reason_status == 0x11)) ||
  770. ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0)
  771. && (vif->reconnect_flag == 1))) {
  772. set_bit(CONNECTED, &vif->flags);
  773. return;
  774. }
  775. }
  776. /* update connect & link status atomically */
  777. spin_lock_bh(&vif->if_lock);
  778. clear_bit(CONNECTED, &vif->flags);
  779. netif_carrier_off(vif->ndev);
  780. spin_unlock_bh(&vif->if_lock);
  781. if ((reason != CSERV_DISCONNECT) || (vif->reconnect_flag != 1))
  782. vif->reconnect_flag = 0;
  783. if (reason != CSERV_DISCONNECT)
  784. ar->user_key_ctrl = 0;
  785. netif_stop_queue(vif->ndev);
  786. memset(vif->bssid, 0, sizeof(vif->bssid));
  787. vif->bss_ch = 0;
  788. ath6kl_tx_data_cleanup(ar);
  789. }
  790. struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar)
  791. {
  792. struct ath6kl_vif *vif;
  793. spin_lock_bh(&ar->list_lock);
  794. if (list_empty(&ar->vif_list)) {
  795. spin_unlock_bh(&ar->list_lock);
  796. return NULL;
  797. }
  798. vif = list_first_entry(&ar->vif_list, struct ath6kl_vif, list);
  799. spin_unlock_bh(&ar->list_lock);
  800. return vif;
  801. }
  802. static int ath6kl_open(struct net_device *dev)
  803. {
  804. struct ath6kl_vif *vif = netdev_priv(dev);
  805. set_bit(WLAN_ENABLED, &vif->flags);
  806. if (test_bit(CONNECTED, &vif->flags)) {
  807. netif_carrier_on(dev);
  808. netif_wake_queue(dev);
  809. } else
  810. netif_carrier_off(dev);
  811. return 0;
  812. }
  813. static int ath6kl_close(struct net_device *dev)
  814. {
  815. struct ath6kl_vif *vif = netdev_priv(dev);
  816. netif_stop_queue(dev);
  817. ath6kl_cfg80211_stop(vif);
  818. clear_bit(WLAN_ENABLED, &vif->flags);
  819. return 0;
  820. }
  821. static struct net_device_stats *ath6kl_get_stats(struct net_device *dev)
  822. {
  823. struct ath6kl_vif *vif = netdev_priv(dev);
  824. return &vif->net_stats;
  825. }
  826. static struct net_device_ops ath6kl_netdev_ops = {
  827. .ndo_open = ath6kl_open,
  828. .ndo_stop = ath6kl_close,
  829. .ndo_start_xmit = ath6kl_data_tx,
  830. .ndo_get_stats = ath6kl_get_stats,
  831. };
  832. void init_netdev(struct net_device *dev)
  833. {
  834. dev->netdev_ops = &ath6kl_netdev_ops;
  835. dev->destructor = free_netdev;
  836. dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
  837. dev->needed_headroom = ETH_HLEN;
  838. dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) +
  839. sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH
  840. + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES;
  841. return;
  842. }