main.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  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. static const char *get_hw_id_string(u32 id)
  433. {
  434. switch (id) {
  435. case AR6003_REV1_VERSION:
  436. return "1.0";
  437. case AR6003_REV2_VERSION:
  438. return "2.0";
  439. case AR6003_REV3_VERSION:
  440. return "2.1.1";
  441. default:
  442. return "unknown";
  443. }
  444. }
  445. void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver)
  446. {
  447. struct ath6kl *ar = devt;
  448. memcpy(ar->mac_addr, datap, ETH_ALEN);
  449. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n",
  450. __func__, ar->mac_addr);
  451. ar->version.wlan_ver = sw_ver;
  452. ar->version.abi_ver = abi_ver;
  453. snprintf(ar->wiphy->fw_version,
  454. sizeof(ar->wiphy->fw_version),
  455. "%u.%u.%u.%u",
  456. (ar->version.wlan_ver & 0xf0000000) >> 28,
  457. (ar->version.wlan_ver & 0x0f000000) >> 24,
  458. (ar->version.wlan_ver & 0x00ff0000) >> 16,
  459. (ar->version.wlan_ver & 0x0000ffff));
  460. /* indicate to the waiting thread that the ready event was received */
  461. set_bit(WMI_READY, &ar->flag);
  462. wake_up(&ar->event_wq);
  463. if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
  464. ath6kl_info("hw %s fw %s%s\n",
  465. get_hw_id_string(ar->wiphy->hw_version),
  466. ar->wiphy->fw_version,
  467. test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
  468. }
  469. }
  470. void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
  471. {
  472. struct ath6kl *ar = vif->ar;
  473. bool aborted = false;
  474. if (status != WMI_SCAN_STATUS_SUCCESS)
  475. aborted = true;
  476. ath6kl_cfg80211_scan_complete_event(vif, aborted);
  477. if (!ar->usr_bss_filter) {
  478. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  479. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  480. NONE_BSS_FILTER, 0);
  481. }
  482. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "scan complete: %d\n", status);
  483. }
  484. void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid,
  485. u16 listen_int, u16 beacon_int,
  486. enum network_type net_type, u8 beacon_ie_len,
  487. u8 assoc_req_len, u8 assoc_resp_len,
  488. u8 *assoc_info)
  489. {
  490. struct ath6kl *ar = vif->ar;
  491. ath6kl_cfg80211_connect_event(vif, channel, bssid,
  492. listen_int, beacon_int,
  493. net_type, beacon_ie_len,
  494. assoc_req_len, assoc_resp_len,
  495. assoc_info);
  496. memcpy(vif->bssid, bssid, sizeof(vif->bssid));
  497. vif->bss_ch = channel;
  498. if ((vif->nw_type == INFRA_NETWORK))
  499. ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  500. ar->listen_intvl_t,
  501. ar->listen_intvl_b);
  502. netif_wake_queue(vif->ndev);
  503. /* Update connect & link status atomically */
  504. spin_lock_bh(&vif->if_lock);
  505. set_bit(CONNECTED, &vif->flags);
  506. clear_bit(CONNECT_PEND, &vif->flags);
  507. netif_carrier_on(vif->ndev);
  508. spin_unlock_bh(&vif->if_lock);
  509. aggr_reset_state(vif->aggr_cntxt);
  510. vif->reconnect_flag = 0;
  511. if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
  512. memset(ar->node_map, 0, sizeof(ar->node_map));
  513. ar->node_num = 0;
  514. ar->next_ep_id = ENDPOINT_2;
  515. }
  516. if (!ar->usr_bss_filter) {
  517. set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  518. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  519. CURRENT_BSS_FILTER, 0);
  520. }
  521. }
  522. void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast)
  523. {
  524. struct ath6kl_sta *sta;
  525. struct ath6kl *ar = vif->ar;
  526. u8 tsc[6];
  527. /*
  528. * For AP case, keyid will have aid of STA which sent pkt with
  529. * MIC error. Use this aid to get MAC & send it to hostapd.
  530. */
  531. if (vif->nw_type == AP_NETWORK) {
  532. sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
  533. if (!sta)
  534. return;
  535. ath6kl_dbg(ATH6KL_DBG_TRC,
  536. "ap tkip mic error received from aid=%d\n", keyid);
  537. memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */
  538. cfg80211_michael_mic_failure(vif->ndev, sta->mac,
  539. NL80211_KEYTYPE_PAIRWISE, keyid,
  540. tsc, GFP_KERNEL);
  541. } else
  542. ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast);
  543. }
  544. static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
  545. {
  546. struct wmi_target_stats *tgt_stats =
  547. (struct wmi_target_stats *) ptr;
  548. struct ath6kl *ar = vif->ar;
  549. struct target_stats *stats = &vif->target_stats;
  550. struct tkip_ccmp_stats *ccmp_stats;
  551. u8 ac;
  552. if (len < sizeof(*tgt_stats))
  553. return;
  554. ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
  555. stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
  556. stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
  557. stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
  558. stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
  559. stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
  560. stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
  561. stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
  562. stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
  563. stats->tx_rts_success_cnt +=
  564. le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
  565. for (ac = 0; ac < WMM_NUM_AC; ac++)
  566. stats->tx_pkt_per_ac[ac] +=
  567. le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
  568. stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
  569. stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
  570. stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
  571. stats->tx_mult_retry_cnt +=
  572. le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
  573. stats->tx_rts_fail_cnt +=
  574. le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
  575. stats->tx_ucast_rate =
  576. ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate));
  577. stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
  578. stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
  579. stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
  580. stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
  581. stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
  582. stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
  583. stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
  584. stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
  585. stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
  586. stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
  587. stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
  588. stats->rx_key_cache_miss +=
  589. le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
  590. stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
  591. stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
  592. stats->rx_ucast_rate =
  593. ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate));
  594. ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
  595. stats->tkip_local_mic_fail +=
  596. le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
  597. stats->tkip_cnter_measures_invoked +=
  598. le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
  599. stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
  600. stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
  601. stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
  602. stats->pwr_save_fail_cnt +=
  603. le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
  604. stats->noise_floor_calib =
  605. a_sle32_to_cpu(tgt_stats->noise_floor_calib);
  606. stats->cs_bmiss_cnt +=
  607. le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
  608. stats->cs_low_rssi_cnt +=
  609. le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
  610. stats->cs_connect_cnt +=
  611. le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
  612. stats->cs_discon_cnt +=
  613. le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
  614. stats->cs_ave_beacon_rssi =
  615. a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
  616. stats->cs_last_roam_msec =
  617. tgt_stats->cserv_stats.cs_last_roam_msec;
  618. stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
  619. stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
  620. stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
  621. stats->wow_pkt_dropped +=
  622. le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
  623. stats->wow_host_pkt_wakeups +=
  624. tgt_stats->wow_stats.wow_host_pkt_wakeups;
  625. stats->wow_host_evt_wakeups +=
  626. tgt_stats->wow_stats.wow_host_evt_wakeups;
  627. stats->wow_evt_discarded +=
  628. le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
  629. if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
  630. clear_bit(STATS_UPDATE_PEND, &vif->flags);
  631. wake_up(&ar->event_wq);
  632. }
  633. }
  634. static void ath6kl_add_le32(__le32 *var, __le32 val)
  635. {
  636. *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
  637. }
  638. void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len)
  639. {
  640. struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
  641. struct ath6kl *ar = vif->ar;
  642. struct wmi_ap_mode_stat *ap = &ar->ap_stats;
  643. struct wmi_per_sta_stat *st_ap, *st_p;
  644. u8 ac;
  645. if (vif->nw_type == AP_NETWORK) {
  646. if (len < sizeof(*p))
  647. return;
  648. for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
  649. st_ap = &ap->sta[ac];
  650. st_p = &p->sta[ac];
  651. ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
  652. ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
  653. ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
  654. ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
  655. ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
  656. ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
  657. ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
  658. ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
  659. }
  660. } else {
  661. ath6kl_update_target_stats(vif, ptr, len);
  662. }
  663. }
  664. void ath6kl_wakeup_event(void *dev)
  665. {
  666. struct ath6kl *ar = (struct ath6kl *) dev;
  667. wake_up(&ar->event_wq);
  668. }
  669. void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
  670. {
  671. struct ath6kl *ar = (struct ath6kl *) devt;
  672. ar->tx_pwr = tx_pwr;
  673. wake_up(&ar->event_wq);
  674. }
  675. void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid)
  676. {
  677. struct ath6kl_sta *conn;
  678. struct sk_buff *skb;
  679. bool psq_empty = false;
  680. struct ath6kl *ar = vif->ar;
  681. conn = ath6kl_find_sta_by_aid(ar, aid);
  682. if (!conn)
  683. return;
  684. /*
  685. * Send out a packet queued on ps queue. When the ps queue
  686. * becomes empty update the PVB for this station.
  687. */
  688. spin_lock_bh(&conn->psq_lock);
  689. psq_empty = skb_queue_empty(&conn->psq);
  690. spin_unlock_bh(&conn->psq_lock);
  691. if (psq_empty)
  692. /* TODO: Send out a NULL data frame */
  693. return;
  694. spin_lock_bh(&conn->psq_lock);
  695. skb = skb_dequeue(&conn->psq);
  696. spin_unlock_bh(&conn->psq_lock);
  697. conn->sta_flags |= STA_PS_POLLED;
  698. ath6kl_data_tx(skb, vif->ndev);
  699. conn->sta_flags &= ~STA_PS_POLLED;
  700. spin_lock_bh(&conn->psq_lock);
  701. psq_empty = skb_queue_empty(&conn->psq);
  702. spin_unlock_bh(&conn->psq_lock);
  703. if (psq_empty)
  704. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, conn->aid, 0);
  705. }
  706. void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif)
  707. {
  708. bool mcastq_empty = false;
  709. struct sk_buff *skb;
  710. struct ath6kl *ar = vif->ar;
  711. /*
  712. * If there are no associated STAs, ignore the DTIM expiry event.
  713. * There can be potential race conditions where the last associated
  714. * STA may disconnect & before the host could clear the 'Indicate
  715. * DTIM' request to the firmware, the firmware would have just
  716. * indicated a DTIM expiry event. The race is between 'clear DTIM
  717. * expiry cmd' going from the host to the firmware & the DTIM
  718. * expiry event happening from the firmware to the host.
  719. */
  720. if (!ar->sta_list_index)
  721. return;
  722. spin_lock_bh(&ar->mcastpsq_lock);
  723. mcastq_empty = skb_queue_empty(&ar->mcastpsq);
  724. spin_unlock_bh(&ar->mcastpsq_lock);
  725. if (mcastq_empty)
  726. return;
  727. /* set the STA flag to dtim_expired for the frame to go out */
  728. set_bit(DTIM_EXPIRED, &vif->flags);
  729. spin_lock_bh(&ar->mcastpsq_lock);
  730. while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
  731. spin_unlock_bh(&ar->mcastpsq_lock);
  732. ath6kl_data_tx(skb, vif->ndev);
  733. spin_lock_bh(&ar->mcastpsq_lock);
  734. }
  735. spin_unlock_bh(&ar->mcastpsq_lock);
  736. clear_bit(DTIM_EXPIRED, &vif->flags);
  737. /* clear the LSB of the BitMapCtl field of the TIM IE */
  738. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, MCAST_AID, 0);
  739. }
  740. void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *bssid,
  741. u8 assoc_resp_len, u8 *assoc_info,
  742. u16 prot_reason_status)
  743. {
  744. struct ath6kl *ar = vif->ar;
  745. if (vif->nw_type == AP_NETWORK) {
  746. if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
  747. return;
  748. /* if no more associated STAs, empty the mcast PS q */
  749. if (ar->sta_list_index == 0) {
  750. spin_lock_bh(&ar->mcastpsq_lock);
  751. skb_queue_purge(&ar->mcastpsq);
  752. spin_unlock_bh(&ar->mcastpsq_lock);
  753. /* clear the LSB of the TIM IE's BitMapCtl field */
  754. if (test_bit(WMI_READY, &ar->flag))
  755. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
  756. MCAST_AID, 0);
  757. }
  758. if (!is_broadcast_ether_addr(bssid)) {
  759. /* send event to application */
  760. cfg80211_del_sta(vif->ndev, bssid, GFP_KERNEL);
  761. }
  762. if (memcmp(vif->ndev->dev_addr, bssid, ETH_ALEN) == 0) {
  763. memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
  764. clear_bit(CONNECTED, &vif->flags);
  765. }
  766. return;
  767. }
  768. ath6kl_cfg80211_disconnect_event(vif, reason, bssid,
  769. assoc_resp_len, assoc_info,
  770. prot_reason_status);
  771. aggr_reset_state(vif->aggr_cntxt);
  772. del_timer(&vif->disconnect_timer);
  773. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "disconnect reason is %d\n", reason);
  774. /*
  775. * If the event is due to disconnect cmd from the host, only they
  776. * the target would stop trying to connect. Under any other
  777. * condition, target would keep trying to connect.
  778. */
  779. if (reason == DISCONNECT_CMD) {
  780. if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
  781. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  782. NONE_BSS_FILTER, 0);
  783. } else {
  784. set_bit(CONNECT_PEND, &vif->flags);
  785. if (((reason == ASSOC_FAILED) &&
  786. (prot_reason_status == 0x11)) ||
  787. ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0)
  788. && (vif->reconnect_flag == 1))) {
  789. set_bit(CONNECTED, &vif->flags);
  790. return;
  791. }
  792. }
  793. /* update connect & link status atomically */
  794. spin_lock_bh(&vif->if_lock);
  795. clear_bit(CONNECTED, &vif->flags);
  796. netif_carrier_off(vif->ndev);
  797. spin_unlock_bh(&vif->if_lock);
  798. if ((reason != CSERV_DISCONNECT) || (vif->reconnect_flag != 1))
  799. vif->reconnect_flag = 0;
  800. if (reason != CSERV_DISCONNECT)
  801. ar->user_key_ctrl = 0;
  802. netif_stop_queue(vif->ndev);
  803. memset(vif->bssid, 0, sizeof(vif->bssid));
  804. vif->bss_ch = 0;
  805. ath6kl_tx_data_cleanup(ar);
  806. }
  807. struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar)
  808. {
  809. struct ath6kl_vif *vif;
  810. spin_lock_bh(&ar->list_lock);
  811. if (list_empty(&ar->vif_list)) {
  812. spin_unlock_bh(&ar->list_lock);
  813. return NULL;
  814. }
  815. vif = list_first_entry(&ar->vif_list, struct ath6kl_vif, list);
  816. spin_unlock_bh(&ar->list_lock);
  817. return vif;
  818. }
  819. static int ath6kl_open(struct net_device *dev)
  820. {
  821. struct ath6kl_vif *vif = netdev_priv(dev);
  822. set_bit(WLAN_ENABLED, &vif->flags);
  823. if (test_bit(CONNECTED, &vif->flags)) {
  824. netif_carrier_on(dev);
  825. netif_wake_queue(dev);
  826. } else
  827. netif_carrier_off(dev);
  828. return 0;
  829. }
  830. static int ath6kl_close(struct net_device *dev)
  831. {
  832. struct ath6kl *ar = ath6kl_priv(dev);
  833. struct ath6kl_vif *vif = netdev_priv(dev);
  834. netif_stop_queue(dev);
  835. ath6kl_disconnect(vif);
  836. if (test_bit(WMI_READY, &ar->flag)) {
  837. if (ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0xFFFF,
  838. 0, 0, 0, 0, 0, 0, 0, 0, 0))
  839. return -EIO;
  840. }
  841. ath6kl_cfg80211_scan_complete_event(vif, true);
  842. clear_bit(WLAN_ENABLED, &vif->flags);
  843. return 0;
  844. }
  845. static struct net_device_stats *ath6kl_get_stats(struct net_device *dev)
  846. {
  847. struct ath6kl_vif *vif = netdev_priv(dev);
  848. return &vif->net_stats;
  849. }
  850. static struct net_device_ops ath6kl_netdev_ops = {
  851. .ndo_open = ath6kl_open,
  852. .ndo_stop = ath6kl_close,
  853. .ndo_start_xmit = ath6kl_data_tx,
  854. .ndo_get_stats = ath6kl_get_stats,
  855. };
  856. void init_netdev(struct net_device *dev)
  857. {
  858. dev->netdev_ops = &ath6kl_netdev_ops;
  859. dev->destructor = free_netdev;
  860. dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
  861. dev->needed_headroom = ETH_HLEN;
  862. dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) +
  863. sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH
  864. + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES;
  865. return;
  866. }