/drivers/powercap/

d) { conn = &ar->sta_list[ctr]; break; } } return conn; } static void ath6kl_add_new_sta(struct ath6kl_vif *vif, u8 *mac, u16 aid, u8 *wpaie, size_t ielen, u8 keymgmt, u8 ucipher, u8 auth, u8 apsd_info) { struct ath6kl *ar = vif->ar; struct ath6kl_sta *sta; u8 free_slot; free_slot = aid - 1; sta = &ar->sta_list[free_slot]; memcpy(sta->mac, mac, ETH_ALEN); if (ielen <= ATH6KL_MAX_IE) memcpy(sta->wpa_ie, wpaie, ielen); sta->aid = aid; sta->keymgmt = keymgmt; sta->ucipher = ucipher; sta->auth = auth; sta->apsd_info = apsd_info; ar->sta_list_index = ar->sta_list_index | (1 << free_slot); ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid); aggr_conn_init(vif, vif->aggr_cntxt, sta->aggr_conn); } static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i) { struct ath6kl_sta *sta = &ar->sta_list[i]; struct ath6kl_mgmt_buff *entry, *tmp; /* empty the queued pkts in the PS queue if any */ spin_lock_bh(&sta->psq_lock); skb_queue_purge(&sta->psq); skb_queue_purge(&sta->apsdq); if (sta->mgmt_psq_len != 0) { list_for_each_entry_safe(entry, tmp, &sta->mgmt_psq, list) { kfree(entry); } INIT_LIST_HEAD(&sta->mgmt_psq); sta->mgmt_psq_len = 0; } spin_unlock_bh(&sta->psq_lock); memset(&ar->ap_stats.sta[sta->aid - 1], 0, sizeof(struct wmi_per_sta_stat)); eth_zero_addr(sta->mac); memset(sta->wpa_ie, 0, ATH6KL_MAX_IE); sta->aid = 0; sta->sta_flags = 0; ar->sta_list_index = ar->sta_list_index & ~(1 << i); aggr_reset_state(sta->aggr_conn); } static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason) { u8 i, removed = 0; if (is_zero_ether_addr(mac)) return removed; if (is_broadcast_ether_addr(mac)) { ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n"); for (i = 0; i < AP_MAX_NUM_STA; i++) { if (!is_zero_ether_addr(ar->sta_list[i].mac)) { ath6kl_sta_cleanup(ar, i); removed = 1; } } } else { for (i = 0; i < AP_MAX_NUM_STA; i++) { if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) { ath6kl_dbg(ATH6KL_DBG_TRC, "deleting station %pM aid=%d reason=%d\n", mac, ar->sta_list[i].aid, reason); ath6kl_sta_cleanup(ar, i); removed = 1; break; } } } return removed; } enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac) { struct ath6kl *ar = devt; return ar->ac2ep_map[ac]; } struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar) { struct ath6kl_cookie *cookie; cookie = ar->cookie_list; if (cookie != NULL) { ar->cookie_list = cookie->arc_list_next; ar->cookie_count--; } return cookie; } void ath6kl_cookie_init(struct ath6kl *ar) { u32 i; ar->cookie_list = NULL; ar->cookie_count = 0; memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem)); for (i = 0; i < MAX_COOKIE_NUM; i++) ath6kl_free_cookie(ar, &ar->cookie_mem[i]); } void ath6kl_cookie_cleanup(struct ath6kl *ar) { ar->cookie_list = NULL; ar->cookie_count = 0; } void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie) { /* Insert first */ if (!ar || !cookie) return; cookie->arc_list_next = ar->cookie_list; ar->cookie_list = cookie; ar->cookie_count++; } /* * Read from the hardware through its diagnostic window. No cooperation * from the firmware is required for this. */ int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value) { int ret; ret = ath6kl_hif_diag_read32(ar, address, value); if (ret) { ath6kl_warn("failed to read32 through diagnose window: %d\n", ret); return ret; } return 0; } /* * Write to the ATH6KL through its diagnostic window. No cooperation from * the Target is required for this. */ int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value) { int ret; ret = ath6kl_hif_diag_write32(ar, address, value); if (ret) { ath6kl_err("failed to write 0x%x during diagnose window to 0x%x\n", address, value); return ret; } return 0; } int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length) { u32 count, *buf = data; int ret; if (WARN_ON(length % 4)) return -EINVAL; for (count = 0; count < length / 4; count++, address += 4) { ret = ath6kl_diag_read32(ar, address, &buf[count]); if (ret) return ret; } return 0; } int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length) { u32 count; __le32 *buf = data; int ret; if (WARN_ON(length % 4)) return -EINVAL; for (count = 0; count < length / 4; count++, address += 4) { ret = ath6kl_diag_write32(ar, address, buf[count]); if (ret) return ret; } return 0; } int ath6kl_read_fwlogs(struct ath6kl *ar) { struct ath6kl_dbglog_hdr debug_hdr; struct ath6kl_dbglog_buf debug_buf; u32 address, length, firstbuf, debug_hdr_addr; int ret, loop; u8 *buf; buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL); if (!buf) return -ENOMEM; address = TARG_VTOP(ar->target_type, ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_dbglog_hdr))); ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr); if (ret) goto out; /* Get the contents of the ring buffer */ if (debug_hdr_addr == 0) { ath6kl_warn("Invalid address for debug_hdr_addr\n"); ret = -EINVAL; goto out; } address = TARG_VTOP(ar->target_type, debug_hdr_addr); ret = ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr)); if (ret) goto out; address = TARG_VTOP(ar->target_type, le32_to_cpu(debug_hdr.dbuf_addr)); firstbuf = address; ret = ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf)); if (ret) goto out; loop = 100; do { address = TARG_VTOP(ar->target_type, le32_to_cpu(debug_buf.buffer_addr)); length = le32_to_cpu(debug_buf.length); if (length != 0 && (le32_to_cpu(debug_buf.length) <= le32_to_cpu(debug_buf.bufsize))) { length = ALIGN(length, 4); ret = ath6kl_diag_read(ar, address, buf, length); if (ret) goto out; ath6kl_debug_fwlog_event(ar, buf, length); } address = TARG_VTOP(ar->target_type, le32_to_cpu(debug_buf.next)); ret = ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf)); if (ret) goto out; loop--; if (WARN_ON(loop == 0)) { ret = -ETIMEDOUT; goto out; } } while (address != firstbuf); out: kfree(buf); return ret; } static void ath6kl_install_static_wep_keys(struct ath6kl_vif *vif) { u8 index; u8 keyusage; for (index = 0; index <= WMI_MAX_KEY_INDEX; index++) { if (vif->wep_key_list[index].key_len) { keyusage = GROUP_USAGE; if (index == vif->def_txkey_index) keyusage |= TX_USAGE; ath6kl_wmi_addkey_cmd(vif->ar->wmi, vif->fw_vif_idx, index, WEP_CRYPT, keyusage, vif->wep_key_list[index].key_len, NULL, 0, vif->wep_key_list[index].key, KEY_OP_INIT_VAL, NULL, NO_SYNC_WMIFLAG); } } } void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel) { struct ath6kl *ar = vif->ar; struct ath6kl_req_key *ik; int res; u8 key_rsc[ATH6KL_KEY_SEQ_LEN]; ik = &ar->ap_mode_bkey; ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", channel); switch (vif->auth_mode) { case NONE_AUTH: if (vif->prwise_crypto == WEP_CRYPT) ath6kl_install_static_wep_keys(vif); if (!ik->valid || ik->key_type != WAPI_CRYPT) break; /* for WAPI, we need to set the delayed group key, continue: */ case WPA_PSK_AUTH: case WPA2_PSK_AUTH: case (WPA_PSK_AUTH | WPA2_PSK_AUTH): if (!ik->valid) break; ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey for the initial group key for AP mode\n"); memset(key_rsc, 0, sizeof(key_rsc)); res = ath6kl_wmi_addkey_cmd( ar->wmi, vif->fw_vif_idx, ik->key_index, ik->key_type, GROUP_USAGE, ik->key_len, key_rsc, ATH6KL_KEY_SEQ_LEN, ik->key, KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG); if (res) { ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey failed: %d\n", res); } break; } if (ar->last_ch != channel) /* we actually don't know the phymode, default to HT20 */ ath6kl_cfg80211_ch_switch_notify(vif, channel, WMI_11G_HT20); ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0); set_bit(CONNECTED, &vif->flags); netif_carrier_on(vif->ndev); } void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr, u8 keymgmt, u8 ucipher, u8 auth, u8 assoc_req_len, u8 *assoc_info, u8 apsd_info) { u8 *ies = NULL, *wpa_ie = NULL, *pos; size_t ies_len = 0; struct station_info *sinfo; ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid); if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) { struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) assoc_info; if (ieee80211_is_assoc_req(mgmt->frame_control) && assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) + sizeof(mgmt->u.assoc_req)) { ies = mgmt->u.assoc_req.variable; ies_len = assoc_info + assoc_req_len - ies; } else if (ieee80211_is_reassoc_req(mgmt->frame_control) && assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) + sizeof(mgmt->u.reassoc_req)) { ies = mgmt->u.reassoc_req.variable; ies_len = assoc_info + assoc_req_len - ies; } } pos = ies; while (pos && pos + 1 < ies + ies_len) { if (pos + 2 + pos[1] > ies + ies_len) break; if (pos[0] == WLAN_EID_RSN) wpa_ie = pos; /* RSN IE */ else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 && pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) { if (pos[5] == 0x01) wpa_ie = pos; /* WPA IE */ else if (pos[5] == 0x04) { wpa_ie = pos; /* WPS IE */ break; /* overrides WPA/RSN IE */ } } else if (pos[0] == 0x44 && wpa_ie == NULL) { /* * Note: WAPI Parameter Set IE re-uses Element ID that * was officially allocated for BSS AC Access Delay. As * such, we need to be a bit more careful on when * parsing the frame. However, BSS AC Access Delay * element is not supposed to be included in * (Re)Association Request frames, so this should not * cause problems. */ wpa_ie = pos; /* WAPI IE */ break; } pos += 2 + pos[1]; } ath6kl_add_new_sta(vif, mac_addr, aid, wpa_ie, wpa_ie ? 2 + wpa_ie[1] : 0, keymgmt, ucipher, auth, apsd_info); /* send event to application */ sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL); if (!sinfo) return; /* TODO: sinfo.generation */ sinfo->assoc_req_ies = ies; sinfo->assoc_req_ies_len = ies_len; cfg80211_new_sta(vif->ndev, mac_addr, sinfo, GFP_KERNEL); netif_wake_queue(vif->ndev); kfree(sinfo); } void disconnect_timer_handler(struct timer_list *t) { struct ath6kl_vif *vif = from_timer(vif, t, disconnect_timer); ath6kl_init_profile_info(vif); ath6kl_disconnect(vif); } void ath6kl_disconnect(struct ath6kl_vif *vif) { if (test_bit(CONNECTED, &vif->flags) || test_bit(CONNECT_PEND, &vif->flags)) { ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx); /* * Disconnect command is issued, clear the connect pending * flag. The connected flag will be cleared in * disconnect event notification. */ clear_bit(CONNECT_PEND, &vif->flags); } } /* WMI Event handlers */ void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver, enum wmi_phy_cap cap) { struct ath6kl *ar = devt; memcpy(ar->mac_addr, datap, ETH_ALEN); ath6kl_dbg(ATH6KL_DBG_BOOT, "ready event mac addr %pM sw_ver 0x%x abi_ver 0x%x cap 0x%x\n", ar->mac_addr, sw_ver, abi_ver, cap); ar->version.wlan_ver = sw_ver; ar->version.abi_ver = abi_ver; ar->hw.cap = cap; if (strlen(ar->wiphy->fw_version) == 0) { snprintf(ar->wiphy->fw_version, sizeof(ar->wiphy->fw_version), "%u.%u.%u.%u", (ar->version.wlan_ver & 0xf0000000) >> 28, (ar->version.wlan_ver & 0x0f000000) >> 24, (ar->version.wlan_ver & 0x00ff0000) >> 16, (ar->version.wlan_ver & 0x0000ffff)); } /* indicate to the waiting thread that the ready event was received */ set_bit(WMI_READY, &ar->flag); wake_up(&ar->event_wq); } void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status) { struct ath6kl *ar = vif->ar; bool aborted = false; if (status != WMI_SCAN_STATUS_SUCCESS) aborted = true; ath6kl_cfg80211_scan_complete_event(vif, aborted); if (!ar->usr_bss_filter) { clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags); ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0); } ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "scan complete: %d\n", status); } static int ath6kl_commit_ch_switch(struct ath6kl_vif *vif, u16 channel) { struct ath6kl *ar = vif->ar; vif->profile.ch = cpu_to_le16(channel); switch (vif->nw_type) { case AP_NETWORK: /* * reconfigure any saved RSN IE capabilites in the beacon / * probe response to stay in sync with the supplicant. */ if (vif->rsn_capab && test_bit(ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE, ar->fw_capabilities)) ath6kl_wmi_set_ie_cmd(ar->wmi, vif->fw_vif_idx, WLAN_EID_RSN, WMI_RSN_IE_CAPB, (const u8 *) &vif->rsn_capab, sizeof(vif->rsn_capab)); return ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx, &vif->profile); default: ath6kl_err("won't switch channels nw_type=%d\n", vif->nw_type); return -ENOTSUPP; } } static void ath6kl_check_ch_switch(struct ath6kl *ar, u16 channel) { struct ath6kl_vif *vif; int res = 0; if (!ar->want_ch_switch) return; spin_lock_bh(&ar->list_lock); list_for_each_entry(vif, &ar->vif_list, list) { if (ar->want_ch_switch & (1 << vif->fw_vif_idx)) res = ath6kl_commit_ch_switch(vif, channel); /* if channel switch failed, oh well we tried */ ar->want_ch_switch &= ~(1 << vif->fw_vif_idx); if (res) ath6kl_err("channel switch failed nw_type %d res %d\n", vif->nw_type, res); } spin_unlock_bh(&ar->list_lock); } void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid, u16 listen_int, u16 beacon_int, enum network_type net_type, u8 beacon_ie_len, u8 assoc_req_len, u8 assoc_resp_len, u8 *assoc_info) { struct ath6kl *ar = vif->ar; ath6kl_cfg80211_connect_event(vif, channel, bssid, listen_int, beacon_int, net_type, beacon_ie_len, assoc_req_len, assoc_resp_len, assoc_info); memcpy(vif->bssid, bssid, sizeof(vif->bssid)); vif->bss_ch = channel; if (vif->nw_type == INFRA_NETWORK) { ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx, vif->listen_intvl_t, 0); ath6kl_check_ch_switch(ar, channel); } netif_wake_queue(vif->ndev); /* Update connect & link status atomically */ spin_lock_bh(&vif->if_lock); set_bit(CONNECTED, &vif->flags); clear_bit(CONNECT_PEND, &vif->flags); netif_carrier_on(vif->ndev); spin_unlock_bh(&vif->if_lock); aggr_reset_state(vif->aggr_cntxt->aggr_conn); vif->reconnect_flag = 0; if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) { memset(ar->node_map, 0, sizeof(ar->node_map)); ar->node_num = 0; ar->next_ep_id = ENDPOINT_2; } if (!ar->usr_bss_filter) { set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags); ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, CURRENT_BSS_FILTER, 0); } } void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast) { struct ath6kl_sta *sta; struct ath6kl *ar = vif->ar; u8 tsc[6]; /* * For AP case, keyid will have aid of STA which sent pkt with * MIC error. Use this aid to get MAC & send it to hostapd. */ if (vif->nw_type == AP_NETWORK) { sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2)); if (!sta) return; ath6kl_dbg(ATH6KL_DBG_TRC, "ap tkip mic error received from aid=%d\n", keyid); memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */ cfg80211_michael_mic_failure(vif->ndev, sta->mac, NL80211_KEYTYPE_PAIRWISE, keyid, tsc, GFP_KERNEL); } else { ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast); } } static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len) { struct wmi_target_stats *tgt_stats = (struct wmi_target_stats *) ptr; struct ath6kl *ar = vif->ar; struct target_stats *stats = &vif->target_stats; struct tkip_ccmp_stats *ccmp_stats; s32 rate; u8 ac; if (len < sizeof(*tgt_stats)) return; ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n"); stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt); stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte); stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt); stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte); stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt); stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte); stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt); stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte); stats->tx_rts_success_cnt += le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt); for (ac = 0; ac < WMM_NUM_AC; ac++) stats->tx_pkt_per_ac[ac] += le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]); stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err); stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt); stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt); stats->tx_mult_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt); stats->tx_rts_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt); rate = a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate); stats->tx_ucast_rate = ath6kl_wmi_get_rate(ar->wmi, rate); stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt); stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte); stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt); stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte); stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt); stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte); stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt); stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte); stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt); stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err); stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err); stats->rx_key_cache_miss += le32_to_cpu(tgt_stats->stats.rx.key_cache_miss); stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err); stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame); rate = a_sle3