1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *****************************************************************************/
64 #include <linux/etherdevice.h>
65 #include <net/cfg80211.h>
67 #include "iwl-modparams.h"
71 void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw,
72 struct ieee80211_vif *vif,
73 struct cfg80211_gtk_rekey_data *data)
75 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
76 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
78 if (iwlwifi_mod_params.sw_crypto)
81 mutex_lock(&mvm->mutex);
83 memcpy(mvmvif->rekey_data.kek, data->kek, NL80211_KEK_LEN);
84 memcpy(mvmvif->rekey_data.kck, data->kck, NL80211_KCK_LEN);
85 mvmvif->rekey_data.replay_ctr =
86 cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
87 mvmvif->rekey_data.valid = true;
89 mutex_unlock(&mvm->mutex);
92 #if IS_ENABLED(CONFIG_IPV6)
93 void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw,
94 struct ieee80211_vif *vif,
95 struct inet6_dev *idev)
97 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
98 struct inet6_ifaddr *ifa;
101 read_lock_bh(&idev->lock);
102 list_for_each_entry(ifa, &idev->addr_list, if_list) {
103 mvmvif->target_ipv6_addrs[idx] = ifa->addr;
105 if (idx >= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS)
108 read_unlock_bh(&idev->lock);
110 mvmvif->num_target_ipv6_addrs = idx;
114 void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw,
115 struct ieee80211_vif *vif, int idx)
117 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
119 mvmvif->tx_key_idx = idx;
122 static void iwl_mvm_convert_p1k(u16 *p1k, __le16 *out)
126 for (i = 0; i < IWL_P1K_SIZE; i++)
127 out[i] = cpu_to_le16(p1k[i]);
130 struct wowlan_key_data {
131 struct iwl_wowlan_rsc_tsc_params_cmd *rsc_tsc;
132 struct iwl_wowlan_tkip_params_cmd *tkip;
133 bool error, use_rsc_tsc, use_tkip;
137 static void iwl_mvm_wowlan_program_keys(struct ieee80211_hw *hw,
138 struct ieee80211_vif *vif,
139 struct ieee80211_sta *sta,
140 struct ieee80211_key_conf *key,
143 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
144 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
145 struct wowlan_key_data *data = _data;
146 struct aes_sc *aes_sc, *aes_tx_sc = NULL;
147 struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL;
148 struct iwl_p1k_cache *rx_p1ks;
150 struct ieee80211_key_seq seq;
152 u16 p1k[IWL_P1K_SIZE];
155 mutex_lock(&mvm->mutex);
157 switch (key->cipher) {
158 case WLAN_CIPHER_SUITE_WEP40:
159 case WLAN_CIPHER_SUITE_WEP104: { /* hack it for now */
161 struct iwl_mvm_wep_key_cmd wep_key_cmd;
162 struct iwl_mvm_wep_key wep_key;
164 .wep_key_cmd.mac_id_n_color =
165 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
167 .wep_key_cmd.num_keys = 1,
168 /* firmware sets STA_KEY_FLG_WEP_13BYTES */
169 .wep_key_cmd.decryption_type = STA_KEY_FLG_WEP,
170 .wep_key.key_index = key->keyidx,
171 .wep_key.key_size = key->keylen,
175 * This will fail -- the key functions don't set support
176 * pairwise WEP keys. However, that's better than silently
177 * failing WoWLAN. Or maybe not?
179 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
182 memcpy(&wkc.wep_key.key[3], key->key, key->keylen);
183 if (key->keyidx == mvmvif->tx_key_idx) {
184 /* TX key must be at offset 0 */
185 wkc.wep_key.key_offset = 0;
187 /* others start at 1 */
189 wkc.wep_key.key_offset = data->gtk_key_idx;
192 ret = iwl_mvm_send_cmd_pdu(mvm, WEP_KEY, CMD_SYNC,
194 data->error = ret != 0;
196 mvm->ptk_ivlen = key->iv_len;
197 mvm->ptk_icvlen = key->icv_len;
198 mvm->gtk_ivlen = key->iv_len;
199 mvm->gtk_icvlen = key->icv_len;
201 /* don't upload key again */
207 case WLAN_CIPHER_SUITE_AES_CMAC:
209 * Ignore CMAC keys -- the WoWLAN firmware doesn't support them
210 * but we also shouldn't abort suspend due to that. It does have
211 * support for the IGTK key renewal, but doesn't really use the
212 * IGTK for anything. This means we could spuriously wake up or
213 * be deauthenticated, but that was considered acceptable.
216 case WLAN_CIPHER_SUITE_TKIP:
218 tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc;
219 tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc;
221 rx_p1ks = data->tkip->rx_uni;
223 ieee80211_get_key_tx_seq(key, &seq);
224 tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16);
225 tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32);
227 ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k);
228 iwl_mvm_convert_p1k(p1k, data->tkip->tx.p1k);
230 memcpy(data->tkip->mic_keys.tx,
231 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
234 rx_mic_key = data->tkip->mic_keys.rx_unicast;
237 data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc;
238 rx_p1ks = data->tkip->rx_multi;
239 rx_mic_key = data->tkip->mic_keys.rx_mcast;
243 * For non-QoS this relies on the fact that both the uCode and
244 * mac80211 use TID 0 (as they need to to avoid replay attacks)
245 * for checking the IV in the frames.
247 for (i = 0; i < IWL_NUM_RSC; i++) {
248 ieee80211_get_key_rx_seq(key, i, &seq);
249 tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16);
250 tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32);
251 /* wrapping isn't allowed, AP must rekey */
252 if (seq.tkip.iv32 > cur_rx_iv32)
253 cur_rx_iv32 = seq.tkip.iv32;
256 ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid,
258 iwl_mvm_convert_p1k(p1k, rx_p1ks[0].p1k);
259 ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid,
260 cur_rx_iv32 + 1, p1k);
261 iwl_mvm_convert_p1k(p1k, rx_p1ks[1].p1k);
264 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
267 data->use_tkip = true;
268 data->use_rsc_tsc = true;
270 case WLAN_CIPHER_SUITE_CCMP:
272 u8 *pn = seq.ccmp.pn;
274 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc;
275 aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc;
277 ieee80211_get_key_tx_seq(key, &seq);
278 aes_tx_sc->pn = cpu_to_le64((u64)pn[5] |
285 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc;
289 * For non-QoS this relies on the fact that both the uCode and
290 * mac80211 use TID 0 for checking the IV in the frames.
292 for (i = 0; i < IWL_NUM_RSC; i++) {
293 u8 *pn = seq.ccmp.pn;
295 ieee80211_get_key_rx_seq(key, i, &seq);
296 aes_sc->pn = cpu_to_le64((u64)pn[5] |
303 data->use_rsc_tsc = true;
308 * The D3 firmware hardcodes the key offset 0 as the key it uses
309 * to transmit packets to the AP, i.e. the PTK.
311 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
313 mvm->ptk_ivlen = key->iv_len;
314 mvm->ptk_icvlen = key->icv_len;
317 key->hw_key_idx = data->gtk_key_idx;
318 mvm->gtk_ivlen = key->iv_len;
319 mvm->gtk_icvlen = key->icv_len;
322 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, true);
323 data->error = ret != 0;
325 mutex_unlock(&mvm->mutex);
328 static int iwl_mvm_send_patterns(struct iwl_mvm *mvm,
329 struct cfg80211_wowlan *wowlan)
331 struct iwl_wowlan_patterns_cmd *pattern_cmd;
332 struct iwl_host_cmd cmd = {
333 .id = WOWLAN_PATTERNS,
334 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
339 if (!wowlan->n_patterns)
342 cmd.len[0] = sizeof(*pattern_cmd) +
343 wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern);
345 pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
349 pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
351 for (i = 0; i < wowlan->n_patterns; i++) {
352 int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
354 memcpy(&pattern_cmd->patterns[i].mask,
355 wowlan->patterns[i].mask, mask_len);
356 memcpy(&pattern_cmd->patterns[i].pattern,
357 wowlan->patterns[i].pattern,
358 wowlan->patterns[i].pattern_len);
359 pattern_cmd->patterns[i].mask_size = mask_len;
360 pattern_cmd->patterns[i].pattern_size =
361 wowlan->patterns[i].pattern_len;
364 cmd.data[0] = pattern_cmd;
365 err = iwl_mvm_send_cmd(mvm, &cmd);
370 static int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm,
371 struct ieee80211_vif *vif)
373 struct iwl_proto_offload_cmd cmd = {};
374 #if IS_ENABLED(CONFIG_IPV6)
375 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
378 if (mvmvif->num_target_ipv6_addrs) {
379 cmd.enabled |= cpu_to_le32(IWL_D3_PROTO_OFFLOAD_NS);
380 memcpy(cmd.ndp_mac_addr, vif->addr, ETH_ALEN);
383 BUILD_BUG_ON(sizeof(cmd.target_ipv6_addr[i]) !=
384 sizeof(mvmvif->target_ipv6_addrs[i]));
386 for (i = 0; i < mvmvif->num_target_ipv6_addrs; i++)
387 memcpy(cmd.target_ipv6_addr[i],
388 &mvmvif->target_ipv6_addrs[i],
389 sizeof(cmd.target_ipv6_addr[i]));
392 if (vif->bss_conf.arp_addr_cnt) {
393 cmd.enabled |= cpu_to_le32(IWL_D3_PROTO_OFFLOAD_ARP);
394 cmd.host_ipv4_addr = vif->bss_conf.arp_addr_list[0];
395 memcpy(cmd.arp_mac_addr, vif->addr, ETH_ALEN);
401 return iwl_mvm_send_cmd_pdu(mvm, PROT_OFFLOAD_CONFIG_CMD, CMD_SYNC,
405 struct iwl_d3_iter_data {
407 struct ieee80211_vif *vif;
411 static void iwl_mvm_d3_iface_iterator(void *_data, u8 *mac,
412 struct ieee80211_vif *vif)
414 struct iwl_d3_iter_data *data = _data;
415 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
417 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
420 if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
424 IWL_ERR(data->mvm, "More than one managed interface active!\n");
432 static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
433 struct ieee80211_sta *ap_sta)
435 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
436 struct ieee80211_chanctx_conf *ctx;
437 u8 chains_static, chains_dynamic;
438 struct cfg80211_chan_def chandef;
440 struct iwl_binding_cmd binding_cmd = {};
441 struct iwl_time_quota_cmd quota_cmd = {};
444 /* add back the PHY */
445 if (WARN_ON(!mvmvif->phy_ctxt))
449 ctx = rcu_dereference(vif->chanctx_conf);
455 chains_static = ctx->rx_chains_static;
456 chains_dynamic = ctx->rx_chains_dynamic;
459 ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt, &chandef,
460 chains_static, chains_dynamic);
464 /* add back the MAC */
465 mvmvif->uploaded = false;
467 if (WARN_ON(!vif->bss_conf.assoc))
470 vif->bss_conf.assoc = false;
471 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
472 vif->bss_conf.assoc = true;
476 /* add back binding - XXX refactor? */
477 binding_cmd.id_and_color =
478 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
479 mvmvif->phy_ctxt->color));
480 binding_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
482 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
483 mvmvif->phy_ctxt->color));
484 binding_cmd.macs[0] = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
486 for (i = 1; i < MAX_MACS_IN_BINDING; i++)
487 binding_cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID);
490 ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD,
491 sizeof(binding_cmd), &binding_cmd,
494 IWL_ERR(mvm, "Failed to add binding: %d\n", ret);
499 IWL_ERR(mvm, "Binding command failed: %u\n", status);
503 ret = iwl_mvm_sta_send_to_fw(mvm, ap_sta, false);
506 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], ap_sta);
508 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
513 quota_cmd.quotas[0].id_and_color =
514 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
515 mvmvif->phy_ctxt->color));
516 quota_cmd.quotas[0].quota = cpu_to_le32(100);
517 quota_cmd.quotas[0].max_duration = cpu_to_le32(1000);
519 for (i = 1; i < MAX_BINDINGS; i++)
520 quota_cmd.quotas[i].id_and_color = cpu_to_le32(FW_CTXT_INVALID);
522 ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, CMD_SYNC,
523 sizeof(quota_cmd), "a_cmd);
525 IWL_ERR(mvm, "Failed to send quota: %d\n", ret);
530 int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
532 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
533 struct iwl_d3_iter_data suspend_iter_data = {
536 struct ieee80211_vif *vif;
537 struct iwl_mvm_vif *mvmvif;
538 struct ieee80211_sta *ap_sta;
539 struct iwl_mvm_sta *mvm_ap_sta;
540 struct iwl_wowlan_config_cmd wowlan_config_cmd = {};
541 struct iwl_wowlan_kek_kck_material_cmd kek_kck_cmd = {};
542 struct iwl_wowlan_tkip_params_cmd tkip_cmd = {};
543 struct iwl_d3_manager_config d3_cfg_cmd = {};
544 struct wowlan_key_data key_data = {
545 .use_rsc_tsc = false,
551 u8 old_aux_sta_id, old_ap_sta_id = IWL_MVM_STATION_COUNT;
553 if (WARN_ON(!wowlan))
556 key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
557 if (!key_data.rsc_tsc)
560 mutex_lock(&mvm->mutex);
562 old_aux_sta_id = mvm->aux_sta.sta_id;
564 /* see if there's only a single BSS vif and it's associated */
565 ieee80211_iterate_active_interfaces_atomic(
566 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
567 iwl_mvm_d3_iface_iterator, &suspend_iter_data);
569 if (suspend_iter_data.error || !suspend_iter_data.vif) {
574 vif = suspend_iter_data.vif;
575 mvmvif = iwl_mvm_vif_from_mac80211(vif);
577 ap_sta = rcu_dereference_protected(
578 mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
579 lockdep_is_held(&mvm->mutex));
580 if (IS_ERR_OR_NULL(ap_sta)) {
585 mvm_ap_sta = (struct iwl_mvm_sta *)ap_sta->drv_priv;
588 * The D3 firmware still hardcodes the AP station ID for the
589 * BSS we're associated with as 0. Store the real STA ID here
590 * and assign 0. When we leave this function, we'll restore
591 * the original value for the resume code.
593 old_ap_sta_id = mvm_ap_sta->sta_id;
594 mvm_ap_sta->sta_id = 0;
595 mvmvif->ap_sta_id = 0;
597 /* TODO: wowlan_config_cmd.wowlan_ba_teardown_tids */
599 wowlan_config_cmd.is_11n_connection = ap_sta->ht_cap.ht_supported;
602 * We know the last used seqno, and the uCode expects to know that
603 * one, it will increment before TX.
605 seq = mvm_ap_sta->last_seq_ctl & IEEE80211_SCTL_SEQ;
606 wowlan_config_cmd.non_qos_seq = cpu_to_le16(seq);
609 * For QoS counters, we store the one to use next, so subtract 0x10
610 * since the uCode will add 0x10 *before* using the value while we
611 * increment after using the value (i.e. store the next value to use).
613 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
614 seq = mvm_ap_sta->tid_data[i].seq_number;
616 wowlan_config_cmd.qos_seq[i] = cpu_to_le16(seq);
619 if (wowlan->disconnect)
620 wowlan_config_cmd.wakeup_filter |=
621 cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS |
622 IWL_WOWLAN_WAKEUP_LINK_CHANGE);
623 if (wowlan->magic_pkt)
624 wowlan_config_cmd.wakeup_filter |=
625 cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET);
626 if (wowlan->gtk_rekey_failure)
627 wowlan_config_cmd.wakeup_filter |=
628 cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
629 if (wowlan->eap_identity_req)
630 wowlan_config_cmd.wakeup_filter |=
631 cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ);
632 if (wowlan->four_way_handshake)
633 wowlan_config_cmd.wakeup_filter |=
634 cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
635 if (wowlan->n_patterns)
636 wowlan_config_cmd.wakeup_filter |=
637 cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH);
639 if (wowlan->rfkill_release)
640 d3_cfg_cmd.wakeup_flags |=
641 cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT);
643 iwl_mvm_cancel_scan(mvm);
645 iwl_trans_stop_device(mvm->trans);
648 * Set the HW restart bit -- this is mostly true as we're
649 * going to load new firmware and reprogram that, though
650 * the reprogramming is going to be manual to avoid adding
651 * all the MACs that aren't support.
652 * We don't have to clear up everything though because the
653 * reprogramming is manual. When we resume, we'll actually
654 * go through a proper restart sequence again to switch
655 * back to the runtime firmware image.
657 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
659 /* We reprogram keys and shouldn't allocate new key indices */
660 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
668 * The D3 firmware still hardcodes the AP station ID for the
669 * BSS we're associated with as 0. As a result, we have to move
670 * the auxiliary station to ID 1 so the ID 0 remains free for
671 * the AP station for later.
672 * We set the sta_id to 1 here, and reset it to its previous
673 * value (that we stored above) later.
675 mvm->aux_sta.sta_id = 1;
677 ret = iwl_mvm_load_d3_fw(mvm);
681 ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta);
685 if (!iwlwifi_mod_params.sw_crypto) {
687 * This needs to be unlocked due to lock ordering
688 * constraints. Since we're in the suspend path
689 * that isn't really a problem though.
691 mutex_unlock(&mvm->mutex);
692 ieee80211_iter_keys(mvm->hw, vif,
693 iwl_mvm_wowlan_program_keys,
695 mutex_lock(&mvm->mutex);
696 if (key_data.error) {
701 if (key_data.use_rsc_tsc) {
702 struct iwl_host_cmd rsc_tsc_cmd = {
703 .id = WOWLAN_TSC_RSC_PARAM,
705 .data[0] = key_data.rsc_tsc,
706 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
707 .len[0] = sizeof(*key_data.rsc_tsc),
710 ret = iwl_mvm_send_cmd(mvm, &rsc_tsc_cmd);
715 if (key_data.use_tkip) {
716 ret = iwl_mvm_send_cmd_pdu(mvm,
718 CMD_SYNC, sizeof(tkip_cmd),
724 if (mvmvif->rekey_data.valid) {
725 memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd));
726 memcpy(kek_kck_cmd.kck, mvmvif->rekey_data.kck,
728 kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN);
729 memcpy(kek_kck_cmd.kek, mvmvif->rekey_data.kek,
731 kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN);
732 kek_kck_cmd.replay_ctr = mvmvif->rekey_data.replay_ctr;
734 ret = iwl_mvm_send_cmd_pdu(mvm,
735 WOWLAN_KEK_KCK_MATERIAL,
744 ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION,
745 CMD_SYNC, sizeof(wowlan_config_cmd),
750 ret = iwl_mvm_send_patterns(mvm, wowlan);
754 ret = iwl_mvm_send_proto_offload(mvm, vif);
758 /* must be last -- this switches firmware state */
759 ret = iwl_mvm_send_cmd_pdu(mvm, D3_CONFIG_CMD, CMD_SYNC,
760 sizeof(d3_cfg_cmd), &d3_cfg_cmd);
764 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
766 iwl_trans_d3_suspend(mvm->trans);
768 mvm->aux_sta.sta_id = old_aux_sta_id;
769 mvm_ap_sta->sta_id = old_ap_sta_id;
770 mvmvif->ap_sta_id = old_ap_sta_id;
772 kfree(key_data.rsc_tsc);
774 ieee80211_restart_hw(mvm->hw);
776 mutex_unlock(&mvm->mutex);
781 static void iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm,
782 struct ieee80211_vif *vif)
784 u32 base = mvm->error_event_table;
785 struct error_table_start {
786 /* cf. struct iwl_error_event_table */
790 struct cfg80211_wowlan_wakeup wakeup = {
793 struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup;
794 struct iwl_host_cmd cmd = {
795 .id = WOWLAN_GET_STATUSES,
796 .flags = CMD_SYNC | CMD_WANT_SKB,
798 struct iwl_wowlan_status *status;
801 struct sk_buff *pkt = NULL;
803 iwl_trans_read_mem_bytes(mvm->trans, base,
804 &err_info, sizeof(err_info));
806 if (err_info.valid) {
807 IWL_INFO(mvm, "error table is valid (%d)\n",
809 if (err_info.error_id == RF_KILL_INDICATOR_FOR_WOWLAN) {
810 wakeup.rfkill_release = true;
811 ieee80211_report_wowlan_wakeup(vif, &wakeup,
817 /* only for tracing for now */
818 ret = iwl_mvm_send_cmd_pdu(mvm, OFFLOADS_QUERY_CMD, CMD_SYNC, 0, NULL);
820 IWL_ERR(mvm, "failed to query offload statistics (%d)\n", ret);
822 ret = iwl_mvm_send_cmd(mvm, &cmd);
824 IWL_ERR(mvm, "failed to query status (%d)\n", ret);
828 /* RF-kill already asserted again... */
832 len = le32_to_cpu(cmd.resp_pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
833 if (len - sizeof(struct iwl_cmd_header) < sizeof(*status)) {
834 IWL_ERR(mvm, "Invalid WoWLAN status response!\n");
838 status = (void *)cmd.resp_pkt->data;
840 if (len - sizeof(struct iwl_cmd_header) !=
842 ALIGN(le32_to_cpu(status->wake_packet_bufsize), 4)) {
843 IWL_ERR(mvm, "Invalid WoWLAN status response!\n");
847 reasons = le32_to_cpu(status->wakeup_reasons);
849 if (reasons == IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) {
850 wakeup_report = NULL;
854 if (reasons & IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET)
855 wakeup.magic_pkt = true;
857 if (reasons & IWL_WOWLAN_WAKEUP_BY_PATTERN)
859 le16_to_cpu(status->pattern_number);
861 if (reasons & (IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON |
862 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH))
863 wakeup.disconnect = true;
865 if (reasons & IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE)
866 wakeup.gtk_rekey_failure = true;
868 if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED)
869 wakeup.rfkill_release = true;
871 if (reasons & IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST)
872 wakeup.eap_identity_req = true;
874 if (reasons & IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE)
875 wakeup.four_way_handshake = true;
877 if (status->wake_packet_bufsize) {
878 int pktsize = le32_to_cpu(status->wake_packet_bufsize);
879 int pktlen = le32_to_cpu(status->wake_packet_length);
880 const u8 *pktdata = status->wake_packet;
881 struct ieee80211_hdr *hdr = (void *)pktdata;
882 int truncated = pktlen - pktsize;
884 /* this would be a firmware bug */
885 if (WARN_ON_ONCE(truncated < 0))
888 if (ieee80211_is_data(hdr->frame_control)) {
889 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
890 int ivlen = 0, icvlen = 4; /* also FCS */
892 pkt = alloc_skb(pktsize, GFP_KERNEL);
896 memcpy(skb_put(pkt, hdrlen), pktdata, hdrlen);
900 if (ieee80211_has_protected(hdr->frame_control)) {
901 if (is_multicast_ether_addr(hdr->addr1)) {
902 ivlen = mvm->gtk_ivlen;
903 icvlen += mvm->gtk_icvlen;
905 ivlen = mvm->ptk_ivlen;
906 icvlen += mvm->ptk_icvlen;
910 /* if truncated, FCS/ICV is (partially) gone */
911 if (truncated >= icvlen) {
919 pktsize -= ivlen + icvlen;
922 memcpy(skb_put(pkt, pktsize), pktdata, pktsize);
924 if (ieee80211_data_to_8023(pkt, vif->addr, vif->type))
926 wakeup.packet = pkt->data;
927 wakeup.packet_present_len = pkt->len;
928 wakeup.packet_len = pkt->len - truncated;
929 wakeup.packet_80211 = false;
933 if (truncated >= 4) {
941 wakeup.packet = status->wake_packet;
942 wakeup.packet_present_len = pktsize;
943 wakeup.packet_len = pktlen - truncated;
944 wakeup.packet_80211 = true;
949 ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL);
956 int iwl_mvm_resume(struct ieee80211_hw *hw)
958 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
959 struct iwl_d3_iter_data resume_iter_data = {
962 struct ieee80211_vif *vif = NULL;
964 enum iwl_d3_status d3_status;
966 mutex_lock(&mvm->mutex);
968 /* get the BSS vif pointer again */
969 ieee80211_iterate_active_interfaces_atomic(
970 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
971 iwl_mvm_d3_iface_iterator, &resume_iter_data);
973 if (WARN_ON(resume_iter_data.error || !resume_iter_data.vif))
976 vif = resume_iter_data.vif;
978 ret = iwl_trans_d3_resume(mvm->trans, &d3_status);
982 if (d3_status != IWL_D3_STATUS_ALIVE) {
983 IWL_INFO(mvm, "Device was reset during suspend\n");
987 iwl_mvm_query_wakeup_reasons(mvm, vif);
990 mutex_unlock(&mvm->mutex);
993 ieee80211_resume_disconnect(vif);
995 /* return 1 to reconfigure the device */
996 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1000 void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1002 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1004 device_set_wakeup_enable(mvm->trans->dev, enabled);