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 COPYING.
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 *****************************************************************************/
63 #include <net/mac80211.h>
69 static void iwl_mvm_add_sta_cmd_v6_to_v5(struct iwl_mvm_add_sta_cmd_v6
*cmd_v6
,
70 struct iwl_mvm_add_sta_cmd_v5
*cmd_v5
)
72 memset(cmd_v5
, 0, sizeof(*cmd_v5
));
74 cmd_v5
->add_modify
= cmd_v6
->add_modify
;
75 cmd_v5
->tid_disable_tx
= cmd_v6
->tid_disable_tx
;
76 cmd_v5
->mac_id_n_color
= cmd_v6
->mac_id_n_color
;
77 memcpy(cmd_v5
->addr
, cmd_v6
->addr
, ETH_ALEN
);
78 cmd_v5
->sta_id
= cmd_v6
->sta_id
;
79 cmd_v5
->modify_mask
= cmd_v6
->modify_mask
;
80 cmd_v5
->station_flags
= cmd_v6
->station_flags
;
81 cmd_v5
->station_flags_msk
= cmd_v6
->station_flags_msk
;
82 cmd_v5
->add_immediate_ba_tid
= cmd_v6
->add_immediate_ba_tid
;
83 cmd_v5
->remove_immediate_ba_tid
= cmd_v6
->remove_immediate_ba_tid
;
84 cmd_v5
->add_immediate_ba_ssn
= cmd_v6
->add_immediate_ba_ssn
;
85 cmd_v5
->sleep_tx_count
= cmd_v6
->sleep_tx_count
;
86 cmd_v5
->sleep_state_flags
= cmd_v6
->sleep_state_flags
;
87 cmd_v5
->assoc_id
= cmd_v6
->assoc_id
;
88 cmd_v5
->beamform_flags
= cmd_v6
->beamform_flags
;
89 cmd_v5
->tfd_queue_msk
= cmd_v6
->tfd_queue_msk
;
93 iwl_mvm_add_sta_key_to_add_sta_cmd_v5(struct iwl_mvm_add_sta_key_cmd
*key_cmd
,
94 struct iwl_mvm_add_sta_cmd_v5
*sta_cmd
,
97 memset(sta_cmd
, 0, sizeof(*sta_cmd
));
99 sta_cmd
->sta_id
= key_cmd
->sta_id
;
100 sta_cmd
->add_modify
= STA_MODE_MODIFY
;
101 sta_cmd
->modify_mask
= STA_MODIFY_KEY
;
102 sta_cmd
->mac_id_n_color
= cpu_to_le32(mac_id_n_color
);
104 sta_cmd
->key
.key_offset
= key_cmd
->key_offset
;
105 sta_cmd
->key
.key_flags
= key_cmd
->key_flags
;
106 memcpy(sta_cmd
->key
.key
, key_cmd
->key
, sizeof(sta_cmd
->key
.key
));
107 sta_cmd
->key
.tkip_rx_tsc_byte2
= key_cmd
->tkip_rx_tsc_byte2
;
108 memcpy(sta_cmd
->key
.tkip_rx_ttak
, key_cmd
->tkip_rx_ttak
,
109 sizeof(sta_cmd
->key
.tkip_rx_ttak
));
112 static int iwl_mvm_send_add_sta_cmd_status(struct iwl_mvm
*mvm
,
113 struct iwl_mvm_add_sta_cmd_v6
*cmd
,
116 struct iwl_mvm_add_sta_cmd_v5 cmd_v5
;
118 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_STA_KEY_CMD
)
119 return iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(*cmd
),
122 iwl_mvm_add_sta_cmd_v6_to_v5(cmd
, &cmd_v5
);
124 return iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd_v5
),
128 static int iwl_mvm_send_add_sta_cmd(struct iwl_mvm
*mvm
, u32 flags
,
129 struct iwl_mvm_add_sta_cmd_v6
*cmd
)
131 struct iwl_mvm_add_sta_cmd_v5 cmd_v5
;
133 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_STA_KEY_CMD
)
134 return iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, flags
,
137 iwl_mvm_add_sta_cmd_v6_to_v5(cmd
, &cmd_v5
);
139 return iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, flags
, sizeof(cmd_v5
),
144 iwl_mvm_send_add_sta_key_cmd_status(struct iwl_mvm
*mvm
,
145 struct iwl_mvm_add_sta_key_cmd
*cmd
,
149 struct iwl_mvm_add_sta_cmd_v5 sta_cmd
;
151 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_STA_KEY_CMD
)
152 return iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
,
153 sizeof(*cmd
), cmd
, status
);
155 iwl_mvm_add_sta_key_to_add_sta_cmd_v5(cmd
, &sta_cmd
, mac_id_n_color
);
157 return iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(sta_cmd
),
161 static int iwl_mvm_send_add_sta_key_cmd(struct iwl_mvm
*mvm
,
163 struct iwl_mvm_add_sta_key_cmd
*cmd
,
166 struct iwl_mvm_add_sta_cmd_v5 sta_cmd
;
168 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_STA_KEY_CMD
)
169 return iwl_mvm_send_cmd_pdu(mvm
, ADD_STA_KEY
, flags
,
172 iwl_mvm_add_sta_key_to_add_sta_cmd_v5(cmd
, &sta_cmd
, mac_id_n_color
);
174 return iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, flags
, sizeof(sta_cmd
),
178 static int iwl_mvm_find_free_sta_id(struct iwl_mvm
*mvm
)
182 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
));
184 lockdep_assert_held(&mvm
->mutex
);
186 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
187 for (sta_id
= 0; sta_id
< IWL_MVM_STATION_COUNT
; sta_id
++)
188 if (!rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
189 lockdep_is_held(&mvm
->mutex
)))
191 return IWL_MVM_STATION_COUNT
;
194 /* send station add/update command to firmware */
195 int iwl_mvm_sta_send_to_fw(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
198 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
199 struct iwl_mvm_add_sta_cmd_v6 add_sta_cmd
;
202 u32 agg_size
= 0, mpdu_dens
= 0;
204 memset(&add_sta_cmd
, 0, sizeof(add_sta_cmd
));
206 add_sta_cmd
.sta_id
= mvm_sta
->sta_id
;
207 add_sta_cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
209 add_sta_cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
210 memcpy(&add_sta_cmd
.addr
, sta
->addr
, ETH_ALEN
);
212 add_sta_cmd
.add_modify
= update
? 1 : 0;
214 add_sta_cmd
.station_flags_msk
|= cpu_to_le32(STA_FLG_FAT_EN_MSK
|
215 STA_FLG_MIMO_EN_MSK
);
217 switch (sta
->bandwidth
) {
218 case IEEE80211_STA_RX_BW_160
:
219 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_160MHZ
);
221 case IEEE80211_STA_RX_BW_80
:
222 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_80MHZ
);
224 case IEEE80211_STA_RX_BW_40
:
225 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_40MHZ
);
227 case IEEE80211_STA_RX_BW_20
:
228 if (sta
->ht_cap
.ht_supported
)
229 add_sta_cmd
.station_flags
|=
230 cpu_to_le32(STA_FLG_FAT_EN_20MHZ
);
234 switch (sta
->rx_nss
) {
236 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_SISO
);
239 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2
);
242 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3
);
246 switch (sta
->smps_mode
) {
247 case IEEE80211_SMPS_AUTOMATIC
:
248 case IEEE80211_SMPS_NUM_MODES
:
251 case IEEE80211_SMPS_STATIC
:
253 add_sta_cmd
.station_flags
&= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK
);
254 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_SISO
);
256 case IEEE80211_SMPS_DYNAMIC
:
257 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_RTS_MIMO_PROT
);
259 case IEEE80211_SMPS_OFF
:
264 if (sta
->ht_cap
.ht_supported
) {
265 add_sta_cmd
.station_flags_msk
|=
266 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK
|
267 STA_FLG_AGG_MPDU_DENS_MSK
);
269 mpdu_dens
= sta
->ht_cap
.ampdu_density
;
272 if (sta
->vht_cap
.vht_supported
) {
273 agg_size
= sta
->vht_cap
.cap
&
274 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
;
276 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
277 } else if (sta
->ht_cap
.ht_supported
) {
278 agg_size
= sta
->ht_cap
.ampdu_factor
;
281 add_sta_cmd
.station_flags
|=
282 cpu_to_le32(agg_size
<< STA_FLG_MAX_AGG_SIZE_SHIFT
);
283 add_sta_cmd
.station_flags
|=
284 cpu_to_le32(mpdu_dens
<< STA_FLG_AGG_MPDU_DENS_SHIFT
);
286 status
= ADD_STA_SUCCESS
;
287 ret
= iwl_mvm_send_add_sta_cmd_status(mvm
, &add_sta_cmd
, &status
);
292 case ADD_STA_SUCCESS
:
293 IWL_DEBUG_ASSOC(mvm
, "ADD_STA PASSED\n");
297 IWL_ERR(mvm
, "ADD_STA failed\n");
304 int iwl_mvm_add_sta(struct iwl_mvm
*mvm
,
305 struct ieee80211_vif
*vif
,
306 struct ieee80211_sta
*sta
)
308 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
309 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
312 lockdep_assert_held(&mvm
->mutex
);
314 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
315 sta_id
= iwl_mvm_find_free_sta_id(mvm
);
317 sta_id
= mvm_sta
->sta_id
;
319 if (WARN_ON_ONCE(sta_id
== IWL_MVM_STATION_COUNT
))
322 spin_lock_init(&mvm_sta
->lock
);
324 mvm_sta
->sta_id
= sta_id
;
325 mvm_sta
->mac_id_n_color
= FW_CMD_ID_AND_COLOR(mvmvif
->id
,
328 mvm_sta
->max_agg_bufsize
= LINK_QUAL_AGG_FRAME_LIMIT_DEF
;
329 mvm_sta
->tx_protection
= 0;
330 mvm_sta
->tt_tx_protection
= false;
332 /* HW restart, don't assume the memory has been zeroed */
333 atomic_set(&mvm
->pending_frames
[sta_id
], 0);
334 mvm_sta
->tid_disable_agg
= 0;
335 mvm_sta
->tfd_queue_msk
= 0;
336 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
337 if (vif
->hw_queue
[i
] != IEEE80211_INVAL_HW_QUEUE
)
338 mvm_sta
->tfd_queue_msk
|= BIT(vif
->hw_queue
[i
]);
340 /* for HW restart - reset everything but the sequence number */
341 for (i
= 0; i
< IWL_MAX_TID_COUNT
; i
++) {
342 u16 seq
= mvm_sta
->tid_data
[i
].seq_number
;
343 memset(&mvm_sta
->tid_data
[i
], 0, sizeof(mvm_sta
->tid_data
[i
]));
344 mvm_sta
->tid_data
[i
].seq_number
= seq
;
347 ret
= iwl_mvm_sta_send_to_fw(mvm
, sta
, false);
351 /* The first station added is the AP, the others are TDLS STAs */
352 if (vif
->type
== NL80211_IFTYPE_STATION
&&
353 mvmvif
->ap_sta_id
== IWL_MVM_STATION_COUNT
)
354 mvmvif
->ap_sta_id
= sta_id
;
356 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta_id
], sta
);
361 int iwl_mvm_update_sta(struct iwl_mvm
*mvm
,
362 struct ieee80211_vif
*vif
,
363 struct ieee80211_sta
*sta
)
365 return iwl_mvm_sta_send_to_fw(mvm
, sta
, true);
368 int iwl_mvm_drain_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_sta
*mvmsta
,
371 struct iwl_mvm_add_sta_cmd_v6 cmd
= {};
375 lockdep_assert_held(&mvm
->mutex
);
377 cmd
.mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
);
378 cmd
.sta_id
= mvmsta
->sta_id
;
379 cmd
.add_modify
= STA_MODE_MODIFY
;
380 cmd
.station_flags
= drain
? cpu_to_le32(STA_FLG_DRAIN_FLOW
) : 0;
381 cmd
.station_flags_msk
= cpu_to_le32(STA_FLG_DRAIN_FLOW
);
383 status
= ADD_STA_SUCCESS
;
384 ret
= iwl_mvm_send_add_sta_cmd_status(mvm
, &cmd
, &status
);
389 case ADD_STA_SUCCESS
:
390 IWL_DEBUG_INFO(mvm
, "Frames for staid %d will drained in fw\n",
395 IWL_ERR(mvm
, "Couldn't drain frames for staid %d\n",
404 * Remove a station from the FW table. Before sending the command to remove
405 * the station validate that the station is indeed known to the driver (sanity
408 static int iwl_mvm_rm_sta_common(struct iwl_mvm
*mvm
, u8 sta_id
)
410 struct ieee80211_sta
*sta
;
411 struct iwl_mvm_rm_sta_cmd rm_sta_cmd
= {
416 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
417 lockdep_is_held(&mvm
->mutex
));
419 /* Note: internal stations are marked as error values */
421 IWL_ERR(mvm
, "Invalid station id\n");
425 ret
= iwl_mvm_send_cmd_pdu(mvm
, REMOVE_STA
, CMD_SYNC
,
426 sizeof(rm_sta_cmd
), &rm_sta_cmd
);
428 IWL_ERR(mvm
, "Failed to remove station. Id=%d\n", sta_id
);
435 void iwl_mvm_sta_drained_wk(struct work_struct
*wk
)
437 struct iwl_mvm
*mvm
= container_of(wk
, struct iwl_mvm
, sta_drained_wk
);
441 * The mutex is needed because of the SYNC cmd, but not only: if the
442 * work would run concurrently with iwl_mvm_rm_sta, it would run before
443 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
444 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
447 mutex_lock(&mvm
->mutex
);
449 for_each_set_bit(sta_id
, mvm
->sta_drained
, IWL_MVM_STATION_COUNT
) {
451 struct ieee80211_sta
*sta
=
452 rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
453 lockdep_is_held(&mvm
->mutex
));
455 /* This station is in use */
459 if (PTR_ERR(sta
) == -EINVAL
) {
460 IWL_ERR(mvm
, "Drained sta %d, but it is internal?\n",
466 IWL_ERR(mvm
, "Drained sta %d, but it was NULL?\n",
471 WARN_ON(PTR_ERR(sta
) != -EBUSY
);
472 /* This station was removed and we waited until it got drained,
473 * we can now proceed and remove it.
475 ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
478 "Couldn't remove sta %d after it was drained\n",
482 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
483 clear_bit(sta_id
, mvm
->sta_drained
);
486 mutex_unlock(&mvm
->mutex
);
489 int iwl_mvm_rm_sta(struct iwl_mvm
*mvm
,
490 struct ieee80211_vif
*vif
,
491 struct ieee80211_sta
*sta
)
493 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
494 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
497 lockdep_assert_held(&mvm
->mutex
);
499 if (vif
->type
== NL80211_IFTYPE_STATION
&&
500 mvmvif
->ap_sta_id
== mvm_sta
->sta_id
) {
501 /* flush its queues here since we are freeing mvm_sta */
502 ret
= iwl_mvm_flush_tx_path(mvm
, mvm_sta
->tfd_queue_msk
, true);
505 * Put a non-NULL since the fw station isn't removed.
506 * It will be removed after the MAC will be set as
509 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
512 /* if we are associated - we can't remove the AP STA now */
513 if (vif
->bss_conf
.assoc
)
516 /* unassoc - go ahead - remove the AP STA now */
517 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
521 * Make sure that the tx response code sees the station as -EBUSY and
522 * calls the drain worker.
524 spin_lock_bh(&mvm_sta
->lock
);
526 * There are frames pending on the AC queues for this station.
527 * We need to wait until all the frames are drained...
529 if (atomic_read(&mvm
->pending_frames
[mvm_sta
->sta_id
])) {
530 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
532 spin_unlock_bh(&mvm_sta
->lock
);
533 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, true);
535 spin_unlock_bh(&mvm_sta
->lock
);
536 ret
= iwl_mvm_rm_sta_common(mvm
, mvm_sta
->sta_id
);
537 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
], NULL
);
543 int iwl_mvm_rm_sta_id(struct iwl_mvm
*mvm
,
544 struct ieee80211_vif
*vif
,
547 int ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
549 lockdep_assert_held(&mvm
->mutex
);
551 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
555 int iwl_mvm_allocate_int_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_int_sta
*sta
,
558 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
559 sta
->sta_id
= iwl_mvm_find_free_sta_id(mvm
);
560 if (WARN_ON_ONCE(sta
->sta_id
== IWL_MVM_STATION_COUNT
))
564 sta
->tfd_queue_msk
= qmask
;
566 /* put a non-NULL value so iterating over the stations won't stop */
567 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta
->sta_id
], ERR_PTR(-EINVAL
));
571 void iwl_mvm_dealloc_int_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_int_sta
*sta
)
573 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta
->sta_id
], NULL
);
574 memset(sta
, 0, sizeof(struct iwl_mvm_int_sta
));
575 sta
->sta_id
= IWL_MVM_STATION_COUNT
;
578 static int iwl_mvm_add_int_sta_common(struct iwl_mvm
*mvm
,
579 struct iwl_mvm_int_sta
*sta
,
581 u16 mac_id
, u16 color
)
583 struct iwl_mvm_add_sta_cmd_v6 cmd
;
587 lockdep_assert_held(&mvm
->mutex
);
589 memset(&cmd
, 0, sizeof(struct iwl_mvm_add_sta_cmd_v6
));
590 cmd
.sta_id
= sta
->sta_id
;
591 cmd
.mac_id_n_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id
,
594 cmd
.tfd_queue_msk
= cpu_to_le32(sta
->tfd_queue_msk
);
597 memcpy(cmd
.addr
, addr
, ETH_ALEN
);
599 ret
= iwl_mvm_send_add_sta_cmd_status(mvm
, &cmd
, &status
);
604 case ADD_STA_SUCCESS
:
605 IWL_DEBUG_INFO(mvm
, "Internal station added.\n");
609 IWL_ERR(mvm
, "Add internal station failed, status=0x%x\n",
616 int iwl_mvm_add_aux_sta(struct iwl_mvm
*mvm
)
620 lockdep_assert_held(&mvm
->mutex
);
622 /* Add the aux station, but without any queues */
623 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvm
->aux_sta
, 0);
627 ret
= iwl_mvm_add_int_sta_common(mvm
, &mvm
->aux_sta
, NULL
,
631 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
636 * Send the add station command for the vif's broadcast station.
637 * Assumes that the station was already allocated.
639 * @mvm: the mvm component
640 * @vif: the interface to which the broadcast station is added
641 * @bsta: the broadcast station to add.
643 int iwl_mvm_send_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
644 struct iwl_mvm_int_sta
*bsta
)
646 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
647 static const u8 baddr
[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
649 lockdep_assert_held(&mvm
->mutex
);
651 if (WARN_ON_ONCE(bsta
->sta_id
== IWL_MVM_STATION_COUNT
))
654 return iwl_mvm_add_int_sta_common(mvm
, bsta
, baddr
,
655 mvmvif
->id
, mvmvif
->color
);
658 /* Send the FW a request to remove the station from it's internal data
659 * structures, but DO NOT remove the entry from the local data structures. */
660 int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm
*mvm
,
661 struct iwl_mvm_int_sta
*bsta
)
665 lockdep_assert_held(&mvm
->mutex
);
667 ret
= iwl_mvm_rm_sta_common(mvm
, bsta
->sta_id
);
669 IWL_WARN(mvm
, "Failed sending remove station\n");
673 /* Allocate a new station entry for the broadcast station to the given vif,
674 * and send it to the FW.
675 * Note that each P2P mac should have its own broadcast station.
677 * @mvm: the mvm component
678 * @vif: the interface to which the broadcast station is added
679 * @bsta: the broadcast station to add. */
680 int iwl_mvm_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
681 struct iwl_mvm_int_sta
*bsta
)
683 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
684 static const u8 baddr
[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
688 lockdep_assert_held(&mvm
->mutex
);
690 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
691 ret
= iwl_mvm_allocate_int_sta(mvm
, bsta
, qmask
);
695 ret
= iwl_mvm_add_int_sta_common(mvm
, bsta
, baddr
,
696 mvmvif
->id
, mvmvif
->color
);
699 iwl_mvm_dealloc_int_sta(mvm
, bsta
);
704 * Send the FW a request to remove the station from it's internal data
705 * structures, and in addition remove it from the local data structure.
707 int iwl_mvm_rm_bcast_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_int_sta
*bsta
)
711 lockdep_assert_held(&mvm
->mutex
);
713 ret
= iwl_mvm_rm_sta_common(mvm
, bsta
->sta_id
);
717 iwl_mvm_dealloc_int_sta(mvm
, bsta
);
721 #define IWL_MAX_RX_BA_SESSIONS 16
723 int iwl_mvm_sta_rx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
724 int tid
, u16 ssn
, bool start
)
726 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
727 struct iwl_mvm_add_sta_cmd_v6 cmd
= {};
731 lockdep_assert_held(&mvm
->mutex
);
733 if (start
&& mvm
->rx_ba_sessions
>= IWL_MAX_RX_BA_SESSIONS
) {
734 IWL_WARN(mvm
, "Not enough RX BA SESSIONS\n");
738 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
739 cmd
.sta_id
= mvm_sta
->sta_id
;
740 cmd
.add_modify
= STA_MODE_MODIFY
;
742 cmd
.add_immediate_ba_tid
= (u8
) tid
;
743 cmd
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
745 cmd
.remove_immediate_ba_tid
= (u8
) tid
;
747 cmd
.modify_mask
= start
? STA_MODIFY_ADD_BA_TID
:
748 STA_MODIFY_REMOVE_BA_TID
;
750 status
= ADD_STA_SUCCESS
;
751 ret
= iwl_mvm_send_add_sta_cmd_status(mvm
, &cmd
, &status
);
756 case ADD_STA_SUCCESS
:
757 IWL_DEBUG_INFO(mvm
, "RX BA Session %sed in fw\n",
758 start
? "start" : "stopp");
760 case ADD_STA_IMMEDIATE_BA_FAILURE
:
761 IWL_WARN(mvm
, "RX BA Session refused by fw\n");
766 IWL_ERR(mvm
, "RX BA Session failed %sing, status 0x%x\n",
767 start
? "start" : "stopp", status
);
773 mvm
->rx_ba_sessions
++;
774 else if (mvm
->rx_ba_sessions
> 0)
775 /* check that restart flow didn't zero the counter */
776 mvm
->rx_ba_sessions
--;
782 static int iwl_mvm_sta_tx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
783 int tid
, u8 queue
, bool start
)
785 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
786 struct iwl_mvm_add_sta_cmd_v6 cmd
= {};
790 lockdep_assert_held(&mvm
->mutex
);
793 mvm_sta
->tfd_queue_msk
|= BIT(queue
);
794 mvm_sta
->tid_disable_agg
&= ~BIT(tid
);
796 mvm_sta
->tfd_queue_msk
&= ~BIT(queue
);
797 mvm_sta
->tid_disable_agg
|= BIT(tid
);
800 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
801 cmd
.sta_id
= mvm_sta
->sta_id
;
802 cmd
.add_modify
= STA_MODE_MODIFY
;
803 cmd
.modify_mask
= STA_MODIFY_QUEUES
| STA_MODIFY_TID_DISABLE_TX
;
804 cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
805 cmd
.tid_disable_tx
= cpu_to_le16(mvm_sta
->tid_disable_agg
);
807 status
= ADD_STA_SUCCESS
;
808 ret
= iwl_mvm_send_add_sta_cmd_status(mvm
, &cmd
, &status
);
813 case ADD_STA_SUCCESS
:
817 IWL_ERR(mvm
, "TX BA Session failed %sing, status 0x%x\n",
818 start
? "start" : "stopp", status
);
825 static const u8 tid_to_ac
[] = {
836 int iwl_mvm_sta_tx_agg_start(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
837 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
839 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
840 struct iwl_mvm_tid_data
*tid_data
;
843 if (WARN_ON_ONCE(tid
>= IWL_MAX_TID_COUNT
))
846 if (mvmsta
->tid_data
[tid
].state
!= IWL_AGG_OFF
) {
847 IWL_ERR(mvm
, "Start AGG when state is not IWL_AGG_OFF %d!\n",
848 mvmsta
->tid_data
[tid
].state
);
852 lockdep_assert_held(&mvm
->mutex
);
854 for (txq_id
= mvm
->first_agg_queue
;
855 txq_id
<= mvm
->last_agg_queue
; txq_id
++)
856 if (mvm
->queue_to_mac80211
[txq_id
] ==
857 IWL_INVALID_MAC80211_QUEUE
)
860 if (txq_id
> mvm
->last_agg_queue
) {
861 IWL_ERR(mvm
, "Failed to allocate agg queue\n");
865 /* the new tx queue is still connected to the same mac80211 queue */
866 mvm
->queue_to_mac80211
[txq_id
] = vif
->hw_queue
[tid_to_ac
[tid
]];
868 spin_lock_bh(&mvmsta
->lock
);
869 tid_data
= &mvmsta
->tid_data
[tid
];
870 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
871 tid_data
->txq_id
= txq_id
;
872 *ssn
= tid_data
->ssn
;
874 IWL_DEBUG_TX_QUEUES(mvm
,
875 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
876 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->ssn
,
877 tid_data
->next_reclaimed
);
879 if (tid_data
->ssn
== tid_data
->next_reclaimed
) {
880 tid_data
->state
= IWL_AGG_STARTING
;
881 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
883 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_ADDBA
;
886 spin_unlock_bh(&mvmsta
->lock
);
891 int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
892 struct ieee80211_sta
*sta
, u16 tid
, u8 buf_size
)
894 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
895 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
896 int queue
, fifo
, ret
;
899 buf_size
= min_t(int, buf_size
, LINK_QUAL_AGG_FRAME_LIMIT_DEF
);
901 spin_lock_bh(&mvmsta
->lock
);
903 queue
= tid_data
->txq_id
;
904 tid_data
->state
= IWL_AGG_ON
;
905 tid_data
->ssn
= 0xffff;
906 spin_unlock_bh(&mvmsta
->lock
);
908 fifo
= iwl_mvm_ac_to_tx_fifo
[tid_to_ac
[tid
]];
910 ret
= iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, queue
, true);
914 iwl_trans_txq_enable(mvm
->trans
, queue
, fifo
, mvmsta
->sta_id
, tid
,
918 * Even though in theory the peer could have different
919 * aggregation reorder buffer sizes for different sessions,
920 * our ucode doesn't allow for that and has a global limit
921 * for each station. Therefore, use the minimum of all the
922 * aggregation sessions and our default value.
924 mvmsta
->max_agg_bufsize
=
925 min(mvmsta
->max_agg_bufsize
, buf_size
);
926 mvmsta
->lq_sta
.lq
.agg_frame_cnt_limit
= mvmsta
->max_agg_bufsize
;
928 IWL_DEBUG_HT(mvm
, "Tx aggregation enabled on ra = %pM tid = %d\n",
931 if (mvm
->cfg
->ht_params
->use_rts_for_aggregation
) {
933 * switch to RTS/CTS if it is the prefer protection
934 * method for HT traffic
935 * this function also sends the LQ command
937 return iwl_mvm_tx_protection(mvm
, mvmsta
, true);
939 * TODO: remove the TLC_RTS flag when we tear down the last
940 * AGG session (agg_tids_count in DVM)
944 return iwl_mvm_send_lq_cmd(mvm
, &mvmsta
->lq_sta
.lq
, CMD_ASYNC
, false);
947 int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
948 struct ieee80211_sta
*sta
, u16 tid
)
950 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
951 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
957 * If mac80211 is cleaning its state, then say that we finished since
958 * our state has been cleared anyway.
960 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
961 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
965 spin_lock_bh(&mvmsta
->lock
);
967 txq_id
= tid_data
->txq_id
;
969 IWL_DEBUG_TX_QUEUES(mvm
, "Stop AGG: sta %d tid %d q %d state %d\n",
970 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
972 switch (tid_data
->state
) {
974 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
976 IWL_DEBUG_TX_QUEUES(mvm
,
977 "ssn = %d, next_recl = %d\n",
978 tid_data
->ssn
, tid_data
->next_reclaimed
);
980 /* There are still packets for this RA / TID in the HW */
981 if (tid_data
->ssn
!= tid_data
->next_reclaimed
) {
982 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_DELBA
;
987 tid_data
->ssn
= 0xffff;
988 iwl_trans_txq_disable(mvm
->trans
, txq_id
);
990 case IWL_AGG_STARTING
:
991 case IWL_EMPTYING_HW_QUEUE_ADDBA
:
993 * The agg session has been stopped before it was set up. This
994 * can happen when the AddBA timer times out for example.
997 /* No barriers since we are under mutex */
998 lockdep_assert_held(&mvm
->mutex
);
999 mvm
->queue_to_mac80211
[txq_id
] = IWL_INVALID_MAC80211_QUEUE
;
1001 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1002 tid_data
->state
= IWL_AGG_OFF
;
1007 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
1008 mvmsta
->sta_id
, tid
, tid_data
->state
);
1010 "\ttid_data->txq_id = %d\n", tid_data
->txq_id
);
1014 spin_unlock_bh(&mvmsta
->lock
);
1019 int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1020 struct ieee80211_sta
*sta
, u16 tid
)
1022 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
1023 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
1025 enum iwl_mvm_agg_state old_state
;
1028 * First set the agg state to OFF to avoid calling
1029 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
1031 spin_lock_bh(&mvmsta
->lock
);
1032 txq_id
= tid_data
->txq_id
;
1033 IWL_DEBUG_TX_QUEUES(mvm
, "Flush AGG: sta %d tid %d q %d state %d\n",
1034 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
1035 old_state
= tid_data
->state
;
1036 tid_data
->state
= IWL_AGG_OFF
;
1037 spin_unlock_bh(&mvmsta
->lock
);
1039 if (old_state
>= IWL_AGG_ON
) {
1040 if (iwl_mvm_flush_tx_path(mvm
, BIT(txq_id
), true))
1041 IWL_ERR(mvm
, "Couldn't flush the AGG queue\n");
1043 iwl_trans_txq_disable(mvm
->trans
, tid_data
->txq_id
);
1046 mvm
->queue_to_mac80211
[tid_data
->txq_id
] =
1047 IWL_INVALID_MAC80211_QUEUE
;
1052 static int iwl_mvm_set_fw_key_idx(struct iwl_mvm
*mvm
)
1056 lockdep_assert_held(&mvm
->mutex
);
1058 i
= find_first_zero_bit(mvm
->fw_key_table
, STA_KEY_MAX_NUM
);
1060 if (i
== STA_KEY_MAX_NUM
)
1061 return STA_KEY_IDX_INVALID
;
1063 __set_bit(i
, mvm
->fw_key_table
);
1068 static u8
iwl_mvm_get_key_sta_id(struct ieee80211_vif
*vif
,
1069 struct ieee80211_sta
*sta
)
1071 struct iwl_mvm_vif
*mvmvif
= (void *)vif
->drv_priv
;
1074 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1076 return mvm_sta
->sta_id
;
1080 * The device expects GTKs for station interfaces to be
1081 * installed as GTKs for the AP station. If we have no
1082 * station ID, then use AP's station ID.
1084 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1085 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
)
1086 return mvmvif
->ap_sta_id
;
1088 return IWL_MVM_STATION_COUNT
;
1091 static int iwl_mvm_send_sta_key(struct iwl_mvm
*mvm
,
1092 struct iwl_mvm_sta
*mvm_sta
,
1093 struct ieee80211_key_conf
*keyconf
,
1094 u8 sta_id
, u32 tkip_iv32
, u16
*tkip_p1k
,
1098 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1102 u32 mac_id_n_color
= mvm_sta
->mac_id_n_color
;
1104 keyidx
= (keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1105 STA_KEY_FLG_KEYID_MSK
;
1106 key_flags
= cpu_to_le16(keyidx
);
1107 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP
);
1109 switch (keyconf
->cipher
) {
1110 case WLAN_CIPHER_SUITE_TKIP
:
1111 key_flags
|= cpu_to_le16(STA_KEY_FLG_TKIP
);
1112 cmd
.tkip_rx_tsc_byte2
= tkip_iv32
;
1113 for (i
= 0; i
< 5; i
++)
1114 cmd
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1115 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1117 case WLAN_CIPHER_SUITE_CCMP
:
1118 key_flags
|= cpu_to_le16(STA_KEY_FLG_CCM
);
1119 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1126 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1127 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1129 cmd
.key_offset
= keyconf
->hw_key_idx
;
1130 cmd
.key_flags
= key_flags
;
1131 cmd
.sta_id
= sta_id
;
1133 status
= ADD_STA_SUCCESS
;
1134 if (cmd_flags
== CMD_SYNC
)
1135 ret
= iwl_mvm_send_add_sta_key_cmd_status(mvm
, &cmd
,
1139 ret
= iwl_mvm_send_add_sta_key_cmd(mvm
, CMD_ASYNC
, &cmd
,
1143 case ADD_STA_SUCCESS
:
1144 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: set dynamic key passed\n");
1148 IWL_ERR(mvm
, "MODIFY_STA: set dynamic key failed\n");
1155 static int iwl_mvm_send_sta_igtk(struct iwl_mvm
*mvm
,
1156 struct ieee80211_key_conf
*keyconf
,
1157 u8 sta_id
, bool remove_key
)
1159 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd
= {};
1161 /* verify the key details match the required command's expectations */
1162 if (WARN_ON((keyconf
->cipher
!= WLAN_CIPHER_SUITE_AES_CMAC
) ||
1163 (keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) ||
1164 (keyconf
->keyidx
!= 4 && keyconf
->keyidx
!= 5)))
1167 igtk_cmd
.key_id
= cpu_to_le32(keyconf
->keyidx
);
1168 igtk_cmd
.sta_id
= cpu_to_le32(sta_id
);
1171 igtk_cmd
.ctrl_flags
|= cpu_to_le32(STA_KEY_NOT_VALID
);
1173 struct ieee80211_key_seq seq
;
1176 memcpy(igtk_cmd
.IGTK
, keyconf
->key
, keyconf
->keylen
);
1177 ieee80211_aes_cmac_calculate_k1_k2(keyconf
,
1178 igtk_cmd
.K1
, igtk_cmd
.K2
);
1179 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1180 pn
= seq
.aes_cmac
.pn
;
1181 igtk_cmd
.receive_seq_cnt
= cpu_to_le64(((u64
) pn
[5] << 0) |
1182 ((u64
) pn
[4] << 8) |
1183 ((u64
) pn
[3] << 16) |
1184 ((u64
) pn
[2] << 24) |
1185 ((u64
) pn
[1] << 32) |
1186 ((u64
) pn
[0] << 40));
1189 IWL_DEBUG_INFO(mvm
, "%s igtk for sta %u\n",
1190 remove_key
? "removing" : "installing",
1193 return iwl_mvm_send_cmd_pdu(mvm
, MGMT_MCAST_KEY
, CMD_SYNC
,
1194 sizeof(igtk_cmd
), &igtk_cmd
);
1198 static inline u8
*iwl_mvm_get_mac_addr(struct iwl_mvm
*mvm
,
1199 struct ieee80211_vif
*vif
,
1200 struct ieee80211_sta
*sta
)
1202 struct iwl_mvm_vif
*mvmvif
= (void *)vif
->drv_priv
;
1207 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1208 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
1209 u8 sta_id
= mvmvif
->ap_sta_id
;
1210 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1211 lockdep_is_held(&mvm
->mutex
));
1219 int iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
1220 struct ieee80211_vif
*vif
,
1221 struct ieee80211_sta
*sta
,
1222 struct ieee80211_key_conf
*keyconf
,
1223 bool have_key_offset
)
1225 struct iwl_mvm_sta
*mvm_sta
;
1228 struct ieee80211_key_seq seq
;
1231 lockdep_assert_held(&mvm
->mutex
);
1233 /* Get the station id from the mvm local station table */
1234 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1235 if (sta_id
== IWL_MVM_STATION_COUNT
) {
1236 IWL_ERR(mvm
, "Failed to find station id\n");
1240 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
) {
1241 ret
= iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, false);
1246 * It is possible that the 'sta' parameter is NULL, and thus
1247 * there is a need to retrieve the sta from the local station table.
1250 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1251 lockdep_is_held(&mvm
->mutex
));
1252 if (IS_ERR_OR_NULL(sta
)) {
1253 IWL_ERR(mvm
, "Invalid station id\n");
1258 mvm_sta
= (struct iwl_mvm_sta
*)sta
->drv_priv
;
1259 if (WARN_ON_ONCE(mvm_sta
->vif
!= vif
))
1262 if (!have_key_offset
) {
1264 * The D3 firmware hardcodes the PTK offset to 0, so we have to
1265 * configure it there. As a result, this workaround exists to
1266 * let the caller set the key offset (hw_key_idx), see d3.c.
1268 keyconf
->hw_key_idx
= iwl_mvm_set_fw_key_idx(mvm
);
1269 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
1273 switch (keyconf
->cipher
) {
1274 case WLAN_CIPHER_SUITE_TKIP
:
1275 addr
= iwl_mvm_get_mac_addr(mvm
, vif
, sta
);
1276 /* get phase 1 key from mac80211 */
1277 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1278 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1279 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, sta_id
,
1280 seq
.tkip
.iv32
, p1k
, CMD_SYNC
);
1282 case WLAN_CIPHER_SUITE_CCMP
:
1283 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, sta_id
,
1287 IWL_ERR(mvm
, "Unknown cipher %x\n", keyconf
->cipher
);
1292 __clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
);
1295 IWL_DEBUG_WEP(mvm
, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1296 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1301 int iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
,
1302 struct ieee80211_vif
*vif
,
1303 struct ieee80211_sta
*sta
,
1304 struct ieee80211_key_conf
*keyconf
)
1306 struct iwl_mvm_sta
*mvm_sta
;
1307 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1312 lockdep_assert_held(&mvm
->mutex
);
1314 /* Get the station id from the mvm local station table */
1315 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1317 IWL_DEBUG_WEP(mvm
, "mvm remove dynamic key: idx=%d sta=%d\n",
1318 keyconf
->keyidx
, sta_id
);
1320 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
1321 return iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, true);
1323 ret
= __test_and_clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
);
1325 IWL_ERR(mvm
, "offset %d not used in fw key table.\n",
1326 keyconf
->hw_key_idx
);
1330 if (sta_id
== IWL_MVM_STATION_COUNT
) {
1331 IWL_DEBUG_WEP(mvm
, "station non-existent, early return.\n");
1336 * It is possible that the 'sta' parameter is NULL, and thus
1337 * there is a need to retrieve the sta from the local station table,
1338 * for example when a GTK is removed (where the sta_id will then be
1339 * the AP ID, and no station was passed by mac80211.)
1342 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1343 lockdep_is_held(&mvm
->mutex
));
1345 IWL_ERR(mvm
, "Invalid station id\n");
1350 mvm_sta
= (struct iwl_mvm_sta
*)sta
->drv_priv
;
1351 if (WARN_ON_ONCE(mvm_sta
->vif
!= vif
))
1354 key_flags
= cpu_to_le16((keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1355 STA_KEY_FLG_KEYID_MSK
);
1356 key_flags
|= cpu_to_le16(STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_WEP_KEY_MAP
);
1357 key_flags
|= cpu_to_le16(STA_KEY_NOT_VALID
);
1359 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1360 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1362 cmd
.key_flags
= key_flags
;
1363 cmd
.key_offset
= keyconf
->hw_key_idx
;
1364 cmd
.sta_id
= sta_id
;
1366 status
= ADD_STA_SUCCESS
;
1367 ret
= iwl_mvm_send_add_sta_key_cmd_status(mvm
, &cmd
,
1368 mvm_sta
->mac_id_n_color
,
1372 case ADD_STA_SUCCESS
:
1373 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: remove sta key passed\n");
1377 IWL_ERR(mvm
, "MODIFY_STA: remove sta key failed\n");
1384 void iwl_mvm_update_tkip_key(struct iwl_mvm
*mvm
,
1385 struct ieee80211_vif
*vif
,
1386 struct ieee80211_key_conf
*keyconf
,
1387 struct ieee80211_sta
*sta
, u32 iv32
,
1390 struct iwl_mvm_sta
*mvm_sta
;
1391 u8 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1393 if (WARN_ON_ONCE(sta_id
== IWL_MVM_STATION_COUNT
))
1399 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1400 if (WARN_ON(IS_ERR_OR_NULL(sta
))) {
1406 mvm_sta
= (void *)sta
->drv_priv
;
1407 iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, sta_id
,
1408 iv32
, phase1key
, CMD_ASYNC
);
1412 void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm
*mvm
,
1413 struct ieee80211_sta
*sta
)
1415 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
1416 struct iwl_mvm_add_sta_cmd_v6 cmd
= {
1417 .add_modify
= STA_MODE_MODIFY
,
1418 .sta_id
= mvmsta
->sta_id
,
1419 .station_flags_msk
= cpu_to_le32(STA_FLG_PS
),
1420 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1424 ret
= iwl_mvm_send_add_sta_cmd(mvm
, CMD_ASYNC
, &cmd
);
1426 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
1429 void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm
*mvm
,
1430 struct ieee80211_sta
*sta
,
1431 enum ieee80211_frame_release_type reason
,
1434 u16 sleep_state_flags
=
1435 (reason
== IEEE80211_FRAME_RELEASE_UAPSD
) ?
1436 STA_SLEEP_STATE_UAPSD
: STA_SLEEP_STATE_PS_POLL
;
1437 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
1438 struct iwl_mvm_add_sta_cmd_v6 cmd
= {
1439 .add_modify
= STA_MODE_MODIFY
,
1440 .sta_id
= mvmsta
->sta_id
,
1441 .modify_mask
= STA_MODIFY_SLEEPING_STA_TX_COUNT
,
1442 .sleep_tx_count
= cpu_to_le16(cnt
),
1443 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1445 * Same modify mask for sleep_tx_count and sleep_state_flags so
1446 * we must set the sleep_state_flags too.
1448 .sleep_state_flags
= cpu_to_le16(sleep_state_flags
),
1452 /* TODO: somehow the fw doesn't seem to take PS_POLL into account */
1453 ret
= iwl_mvm_send_add_sta_cmd(mvm
, CMD_ASYNC
, &cmd
);
1455 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);