1 /******************************************************************************
3 * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <net/mac80211.h>
31 #include <linux/etherdevice.h>
32 #include <linux/sched.h>
38 u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
42 int ret = IWL_INVALID_STATION;
45 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) ||
46 (priv->iw_mode == NL80211_IFTYPE_AP))
49 if (is_broadcast_ether_addr(addr))
50 return priv->hw_params.bcast_sta_id;
52 spin_lock_irqsave(&priv->sta_lock, flags);
53 for (i = start; i < priv->hw_params.max_stations; i++)
54 if (priv->stations[i].used &&
55 (!compare_ether_addr(priv->stations[i].sta.sta.addr,
61 IWL_DEBUG_ASSOC_LIMIT(priv, "can not find STA %pM total %d\n",
62 addr, priv->num_stations);
66 * It may be possible that more commands interacting with stations
67 * arrive before we completed processing the adding of
70 if (ret != IWL_INVALID_STATION &&
71 (!(priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) ||
72 ((priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) &&
73 (priv->stations[ret].used & IWL_STA_UCODE_INPROGRESS)))) {
74 IWL_ERR(priv, "Requested station info for sta %d before ready.\n",
76 ret = IWL_INVALID_STATION;
78 spin_unlock_irqrestore(&priv->sta_lock, flags);
81 EXPORT_SYMBOL(iwl_find_station);
83 /* priv->sta_lock must be held */
84 static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
87 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE))
88 IWL_ERR(priv, "ACTIVATE a non DRIVER active station id %u addr %pM\n",
89 sta_id, priv->stations[sta_id].sta.sta.addr);
91 if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) {
93 "STA id %u addr %pM already present in uCode (according to driver)\n",
94 sta_id, priv->stations[sta_id].sta.sta.addr);
96 priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE;
97 IWL_DEBUG_ASSOC(priv, "Added STA id %u addr %pM to uCode\n",
98 sta_id, priv->stations[sta_id].sta.sta.addr);
102 static void iwl_process_add_sta_resp(struct iwl_priv *priv,
103 struct iwl_addsta_cmd *addsta,
104 struct iwl_rx_packet *pkt,
107 u8 sta_id = addsta->sta.sta_id;
110 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
111 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
116 IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n",
119 spin_lock_irqsave(&priv->sta_lock, flags);
121 switch (pkt->u.add_sta.status) {
122 case ADD_STA_SUCCESS_MSK:
123 IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n");
124 iwl_sta_ucode_activate(priv, sta_id);
126 case ADD_STA_NO_ROOM_IN_TABLE:
127 IWL_ERR(priv, "Adding station %d failed, no room in table.\n",
130 case ADD_STA_NO_BLOCK_ACK_RESOURCE:
131 IWL_ERR(priv, "Adding station %d failed, no block ack resource.\n",
134 case ADD_STA_MODIFY_NON_EXIST_STA:
135 IWL_ERR(priv, "Attempting to modify non-existing station %d\n",
139 IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n",
140 pkt->u.add_sta.status);
144 IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n",
145 priv->stations[sta_id].sta.mode ==
146 STA_CONTROL_MODIFY_MSK ? "Modified" : "Added",
147 sta_id, priv->stations[sta_id].sta.sta.addr);
150 * XXX: The MAC address in the command buffer is often changed from
151 * the original sent to the device. That is, the MAC address
152 * written to the command buffer often is not the same MAC adress
153 * read from the command buffer when the command returns. This
154 * issue has not yet been resolved and this debugging is left to
155 * observe the problem.
157 IWL_DEBUG_INFO(priv, "%s station according to cmd buffer %pM\n",
158 priv->stations[sta_id].sta.mode ==
159 STA_CONTROL_MODIFY_MSK ? "Modified" : "Added",
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
164 static void iwl_add_sta_callback(struct iwl_priv *priv,
165 struct iwl_device_cmd *cmd,
166 struct iwl_rx_packet *pkt)
168 struct iwl_addsta_cmd *addsta =
169 (struct iwl_addsta_cmd *)cmd->cmd.payload;
171 iwl_process_add_sta_resp(priv, addsta, pkt, false);
175 int iwl_send_add_sta(struct iwl_priv *priv,
176 struct iwl_addsta_cmd *sta, u8 flags)
178 struct iwl_rx_packet *pkt = NULL;
180 u8 data[sizeof(*sta)];
181 struct iwl_host_cmd cmd = {
186 u8 sta_id __maybe_unused = sta->sta.sta_id;
188 IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n",
189 sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : "");
191 if (flags & CMD_ASYNC)
192 cmd.callback = iwl_add_sta_callback;
194 cmd.flags |= CMD_WANT_SKB;
196 cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
197 ret = iwl_send_cmd(priv, &cmd);
199 if (ret || (flags & CMD_ASYNC))
203 pkt = (struct iwl_rx_packet *)cmd.reply_page;
204 iwl_process_add_sta_resp(priv, sta, pkt, true);
206 iwl_free_pages(priv, cmd.reply_page);
210 EXPORT_SYMBOL(iwl_send_add_sta);
212 static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
213 struct ieee80211_sta_ht_cap *sta_ht_inf)
218 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
221 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
222 IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n",
223 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ?
225 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ?
226 "dynamic" : "disabled");
228 sta_flags = priv->stations[index].sta.station_flags;
230 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
232 switch (mimo_ps_mode) {
233 case WLAN_HT_CAP_SM_PS_STATIC:
234 sta_flags |= STA_FLG_MIMO_DIS_MSK;
236 case WLAN_HT_CAP_SM_PS_DYNAMIC:
237 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
239 case WLAN_HT_CAP_SM_PS_DISABLED:
242 IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode);
246 sta_flags |= cpu_to_le32(
247 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
249 sta_flags |= cpu_to_le32(
250 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
252 if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf))
253 sta_flags |= STA_FLG_HT40_EN_MSK;
255 sta_flags &= ~STA_FLG_HT40_EN_MSK;
257 priv->stations[index].sta.station_flags = sta_flags;
263 * iwl_prep_station - Prepare station information for addition
265 * should be called with sta_lock held
267 static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
269 struct ieee80211_sta_ht_cap *ht_info)
271 struct iwl_station_entry *station;
273 u8 sta_id = IWL_INVALID_STATION;
278 else if (is_broadcast_ether_addr(addr))
279 sta_id = priv->hw_params.bcast_sta_id;
281 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
282 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
288 if (!priv->stations[i].used &&
289 sta_id == IWL_INVALID_STATION)
294 * These two conditions have the same outcome, but keep them
297 if (unlikely(sta_id == IWL_INVALID_STATION))
301 * uCode is not able to deal with multiple requests to add a
302 * station. Keep track if one is in progress so that we do not send
305 if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
306 IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
311 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
312 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) &&
313 !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) {
314 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
319 station = &priv->stations[sta_id];
320 station->used = IWL_STA_DRIVER_ACTIVE;
321 IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n",
323 priv->num_stations++;
325 /* Set up the REPLY_ADD_STA command to send to device */
326 memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
327 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
328 station->sta.mode = 0;
329 station->sta.sta.sta_id = sta_id;
330 station->sta.station_flags = 0;
332 /* BCAST station and IBSS stations do not work in HT mode */
333 if (sta_id != priv->hw_params.bcast_sta_id &&
334 priv->iw_mode != NL80211_IFTYPE_ADHOC)
335 iwl_set_ht_add_station(priv, sta_id, ht_info);
338 rate = (priv->band == IEEE80211_BAND_5GHZ) ?
339 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP;
340 /* Turn on both antennas for the station... */
341 station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK);
347 #define STA_WAIT_TIMEOUT (HZ/2)
350 * iwl_add_station_common -
352 int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr,
354 struct ieee80211_sta_ht_cap *ht_info,
357 struct iwl_station_entry *station;
358 unsigned long flags_spin;
363 spin_lock_irqsave(&priv->sta_lock, flags_spin);
364 sta_id = iwl_prep_station(priv, addr, is_ap, ht_info);
365 if (sta_id == IWL_INVALID_STATION) {
366 IWL_ERR(priv, "Unable to prepare station %pM for addition\n",
368 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
373 * uCode is not able to deal with multiple requests to add a
374 * station. Keep track if one is in progress so that we do not send
377 if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
378 IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
380 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
384 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
385 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
386 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
388 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
392 priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS;
393 station = &priv->stations[sta_id];
394 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
396 /* Add station to device's station table */
397 ret = iwl_send_add_sta(priv, &station->sta, CMD_SYNC);
399 IWL_ERR(priv, "Adding station %pM failed.\n", station->sta.sta.addr);
400 spin_lock_irqsave(&priv->sta_lock, flags_spin);
401 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
402 priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
403 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
408 EXPORT_SYMBOL(iwl_add_station_common);
410 static struct iwl_link_quality_cmd *iwl_sta_init_lq(struct iwl_priv *priv,
414 struct iwl_link_quality_cmd *link_cmd;
418 link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
420 IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n");
423 /* Set up the rate scaling to start at selected rate, fall back
424 * all the way down to 1M in IEEE order, and then spin on 1M */
425 if (priv->band == IEEE80211_BAND_5GHZ)
426 r = IWL_RATE_6M_INDEX;
428 r = IWL_RATE_1M_INDEX;
430 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
432 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
433 rate_flags |= RATE_MCS_CCK_MSK;
435 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
438 link_cmd->rs_table[i].rate_n_flags =
439 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
440 r = iwl_get_prev_ieee_rate(r);
443 link_cmd->general_params.single_stream_ant_msk =
444 first_antenna(priv->hw_params.valid_tx_ant);
446 link_cmd->general_params.dual_stream_ant_msk =
447 priv->hw_params.valid_tx_ant &
448 ~first_antenna(priv->hw_params.valid_tx_ant);
449 if (!link_cmd->general_params.dual_stream_ant_msk) {
450 link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
451 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
452 link_cmd->general_params.dual_stream_ant_msk =
453 priv->hw_params.valid_tx_ant;
456 link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
457 link_cmd->agg_params.agg_time_limit =
458 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
460 link_cmd->sta_id = sta_id;
462 ret = iwl_send_lq_cmd(priv, link_cmd, CMD_SYNC, true);
464 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
470 * iwl_add_local_stations - Add stations not requested by mac80211
472 * This will be either the broadcast station or the bssid station needed by
477 int iwl_add_local_station(struct iwl_priv *priv, const u8 *addr, bool init_rs)
481 struct iwl_link_quality_cmd *link_cmd;
484 ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id);
486 IWL_ERR(priv, "Unable to add station %pM\n", addr);
490 spin_lock_irqsave(&priv->sta_lock, flags);
491 priv->stations[sta_id].used |= IWL_STA_LOCAL;
492 spin_unlock_irqrestore(&priv->sta_lock, flags);
495 /* Set up default rate scaling table in device's station table */
496 link_cmd = iwl_sta_init_lq(priv, sta_id);
498 IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n",
502 spin_lock_irqsave(&priv->sta_lock, flags);
503 priv->stations[sta_id].lq = link_cmd;
504 spin_unlock_irqrestore(&priv->sta_lock, flags);
509 EXPORT_SYMBOL(iwl_add_local_station);
512 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
514 * priv->sta_lock must be held
516 static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id)
518 /* Ucode must be active and driver must be non active */
519 if ((priv->stations[sta_id].used &
520 (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != IWL_STA_UCODE_ACTIVE)
521 IWL_ERR(priv, "removed non active STA %u\n", sta_id);
523 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
525 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
526 IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id);
529 static int iwl_send_remove_station(struct iwl_priv *priv,
530 struct iwl_station_entry *station)
532 struct iwl_rx_packet *pkt;
535 unsigned long flags_spin;
536 struct iwl_rem_sta_cmd rm_sta_cmd;
538 struct iwl_host_cmd cmd = {
539 .id = REPLY_REMOVE_STA,
540 .len = sizeof(struct iwl_rem_sta_cmd),
545 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
546 rm_sta_cmd.num_sta = 1;
547 memcpy(&rm_sta_cmd.addr, &station->sta.sta.addr , ETH_ALEN);
549 cmd.flags |= CMD_WANT_SKB;
551 ret = iwl_send_cmd(priv, &cmd);
556 pkt = (struct iwl_rx_packet *)cmd.reply_page;
557 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
558 IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
564 switch (pkt->u.rem_sta.status) {
565 case REM_STA_SUCCESS_MSK:
566 spin_lock_irqsave(&priv->sta_lock, flags_spin);
567 iwl_sta_ucode_deactivate(priv, station->sta.sta.sta_id);
568 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
569 IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n");
573 IWL_ERR(priv, "REPLY_REMOVE_STA failed\n");
577 iwl_free_pages(priv, cmd.reply_page);
583 * iwl_remove_station - Remove driver's knowledge of station.
585 int iwl_remove_station(struct iwl_priv *priv, const u8 *addr)
587 int sta_id = IWL_INVALID_STATION;
588 int i, ret = -EINVAL;
590 bool is_ap = priv->iw_mode == NL80211_IFTYPE_STATION;
591 struct iwl_station_entry *station;
593 if (!iwl_is_ready(priv)) {
595 "Unable to remove station %pM, device not ready.\n",
598 * It is typical for stations to be removed when we are
599 * going down. Return success since device will be down
605 spin_lock_irqsave(&priv->sta_lock, flags);
610 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
611 if (priv->stations[i].used &&
612 !compare_ether_addr(priv->stations[i].sta.sta.addr,
618 if (unlikely(sta_id == IWL_INVALID_STATION))
621 IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n",
624 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
625 IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n",
630 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
631 IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n",
636 if (priv->stations[sta_id].used & IWL_STA_LOCAL) {
637 kfree(priv->stations[sta_id].lq);
638 priv->stations[sta_id].lq = NULL;
641 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
643 priv->num_stations--;
645 BUG_ON(priv->num_stations < 0);
647 station = &priv->stations[sta_id];
648 spin_unlock_irqrestore(&priv->sta_lock, flags);
650 ret = iwl_send_remove_station(priv, station);
653 spin_unlock_irqrestore(&priv->sta_lock, flags);
656 EXPORT_SYMBOL_GPL(iwl_remove_station);
659 * iwl_clear_ucode_stations() - clear entire station table driver and/or ucode
661 * @force: If set then the uCode station table needs to be cleared here. If
662 * not set then the uCode station table has already been cleared,
663 * for example after sending it a RXON command without ASSOC bit
664 * set, and we just need to change driver state here.
666 void iwl_clear_ucode_stations(struct iwl_priv *priv, bool force)
669 unsigned long flags_spin;
670 bool cleared = false;
672 IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver%s\n",
673 force ? " and ucode" : "");
676 if (!iwl_is_ready(priv)) {
678 * If device is not ready at this point the station
679 * table is likely already empty (uCode not ready
680 * to receive station requests) or will soon be
681 * due to interface going down.
683 IWL_DEBUG_INFO(priv, "Unable to remove stations from device - device not ready\n");
685 iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL);
689 spin_lock_irqsave(&priv->sta_lock, flags_spin);
691 IWL_DEBUG_INFO(priv, "Clearing all station information in driver\n");
693 * The station entry contains a link to the LQ command. For
694 * all stations managed by mac80211 this memory will be
695 * managed by it also. For local stations (broadcast and
696 * bssid station when in adhoc mode) we need to maintain
697 * this lq command separately. This memory is created when
698 * these stations are added.
700 for (i = 0; i < priv->hw_params.max_stations; i++) {
701 if (priv->stations[i].used & IWL_STA_LOCAL) {
702 kfree(priv->stations[i].lq);
703 priv->stations[i].lq = NULL;
706 priv->num_stations = 0;
707 memset(priv->stations, 0, sizeof(priv->stations));
710 for (i = 0; i < priv->hw_params.max_stations; i++) {
711 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) {
712 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i);
713 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
718 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
721 IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n");
723 EXPORT_SYMBOL(iwl_clear_ucode_stations);
726 * iwl_restore_stations() - Restore driver known stations to device
728 * All stations considered active by driver, but not present in ucode, is
733 void iwl_restore_stations(struct iwl_priv *priv)
735 struct iwl_station_entry *station;
736 unsigned long flags_spin;
741 if (!iwl_is_ready(priv)) {
742 IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n");
746 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n");
747 spin_lock_irqsave(&priv->sta_lock, flags_spin);
748 for (i = 0; i < priv->hw_params.max_stations; i++) {
749 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) &&
750 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) {
751 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n",
752 priv->stations[i].sta.sta.addr);
753 priv->stations[i].sta.mode = 0;
754 priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS;
759 for (i = 0; i < priv->hw_params.max_stations; i++) {
760 if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) {
761 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
762 station = &priv->stations[i];
763 ret = iwl_send_add_sta(priv, &priv->stations[i].sta, CMD_SYNC);
765 IWL_ERR(priv, "Adding station %pM failed.\n",
766 station->sta.sta.addr);
767 spin_lock_irqsave(&priv->sta_lock, flags_spin);
768 priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE;
769 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
770 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
773 * Rate scaling has already been initialized, send
777 iwl_send_lq_cmd(priv, station->lq, CMD_SYNC, true);
778 spin_lock_irqsave(&priv->sta_lock, flags_spin);
779 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
783 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
785 IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n");
787 IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n");
789 EXPORT_SYMBOL(iwl_restore_stations);
791 int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
795 for (i = 0; i < STA_KEY_MAX_NUM; i++)
796 if (!test_and_set_bit(i, &priv->ucode_key_table))
799 return WEP_INVALID_OFFSET;
801 EXPORT_SYMBOL(iwl_get_free_ucode_key_index);
803 static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
805 int i, not_empty = 0;
806 u8 buff[sizeof(struct iwl_wep_cmd) +
807 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
808 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
809 size_t cmd_size = sizeof(struct iwl_wep_cmd);
810 struct iwl_host_cmd cmd = {
818 memset(wep_cmd, 0, cmd_size +
819 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
821 for (i = 0; i < WEP_KEYS_MAX ; i++) {
822 wep_cmd->key[i].key_index = i;
823 if (priv->wep_keys[i].key_size) {
824 wep_cmd->key[i].key_offset = i;
827 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
830 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
831 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
832 priv->wep_keys[i].key_size);
835 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
836 wep_cmd->num_keys = WEP_KEYS_MAX;
838 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
842 if (not_empty || send_if_empty)
843 return iwl_send_cmd(priv, &cmd);
848 int iwl_restore_default_wep_keys(struct iwl_priv *priv)
850 WARN_ON(!mutex_is_locked(&priv->mutex));
852 return iwl_send_static_wepkey_cmd(priv, 0);
854 EXPORT_SYMBOL(iwl_restore_default_wep_keys);
856 int iwl_remove_default_wep_key(struct iwl_priv *priv,
857 struct ieee80211_key_conf *keyconf)
861 WARN_ON(!mutex_is_locked(&priv->mutex));
863 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
866 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
867 if (iwl_is_rfkill(priv)) {
868 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
869 /* but keys in device are clear anyway so return success */
872 ret = iwl_send_static_wepkey_cmd(priv, 1);
873 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
874 keyconf->keyidx, ret);
878 EXPORT_SYMBOL(iwl_remove_default_wep_key);
880 int iwl_set_default_wep_key(struct iwl_priv *priv,
881 struct ieee80211_key_conf *keyconf)
885 WARN_ON(!mutex_is_locked(&priv->mutex));
887 if (keyconf->keylen != WEP_KEY_LEN_128 &&
888 keyconf->keylen != WEP_KEY_LEN_64) {
889 IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
893 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
894 keyconf->hw_key_idx = HW_KEY_DEFAULT;
895 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
897 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
898 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
901 ret = iwl_send_static_wepkey_cmd(priv, 0);
902 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
903 keyconf->keylen, keyconf->keyidx, ret);
907 EXPORT_SYMBOL(iwl_set_default_wep_key);
909 static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
910 struct ieee80211_key_conf *keyconf,
914 __le16 key_flags = 0;
917 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
919 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
920 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
921 key_flags &= ~STA_KEY_FLG_INVALID;
923 if (keyconf->keylen == WEP_KEY_LEN_128)
924 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
926 if (sta_id == priv->hw_params.bcast_sta_id)
927 key_flags |= STA_KEY_MULTICAST_MSK;
929 spin_lock_irqsave(&priv->sta_lock, flags);
931 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
932 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
933 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
935 memcpy(priv->stations[sta_id].keyinfo.key,
936 keyconf->key, keyconf->keylen);
938 memcpy(&priv->stations[sta_id].sta.key.key[3],
939 keyconf->key, keyconf->keylen);
941 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
942 == STA_KEY_FLG_NO_ENC)
943 priv->stations[sta_id].sta.key.key_offset =
944 iwl_get_free_ucode_key_index(priv);
945 /* else, we are overriding an existing key => no need to allocated room
948 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
949 "no space for a new key");
951 priv->stations[sta_id].sta.key.key_flags = key_flags;
952 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
953 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
955 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
957 spin_unlock_irqrestore(&priv->sta_lock, flags);
962 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
963 struct ieee80211_key_conf *keyconf,
967 __le16 key_flags = 0;
970 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
971 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
972 key_flags &= ~STA_KEY_FLG_INVALID;
974 if (sta_id == priv->hw_params.bcast_sta_id)
975 key_flags |= STA_KEY_MULTICAST_MSK;
977 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
979 spin_lock_irqsave(&priv->sta_lock, flags);
980 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
981 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
983 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
986 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
989 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
990 == STA_KEY_FLG_NO_ENC)
991 priv->stations[sta_id].sta.key.key_offset =
992 iwl_get_free_ucode_key_index(priv);
993 /* else, we are overriding an existing key => no need to allocated room
996 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
997 "no space for a new key");
999 priv->stations[sta_id].sta.key.key_flags = key_flags;
1000 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1001 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1003 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1005 spin_unlock_irqrestore(&priv->sta_lock, flags);
1010 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
1011 struct ieee80211_key_conf *keyconf,
1014 unsigned long flags;
1016 __le16 key_flags = 0;
1018 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
1019 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1020 key_flags &= ~STA_KEY_FLG_INVALID;
1022 if (sta_id == priv->hw_params.bcast_sta_id)
1023 key_flags |= STA_KEY_MULTICAST_MSK;
1025 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1026 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1028 spin_lock_irqsave(&priv->sta_lock, flags);
1030 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1031 priv->stations[sta_id].keyinfo.keylen = 16;
1033 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
1034 == STA_KEY_FLG_NO_ENC)
1035 priv->stations[sta_id].sta.key.key_offset =
1036 iwl_get_free_ucode_key_index(priv);
1037 /* else, we are overriding an existing key => no need to allocated room
1040 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
1041 "no space for a new key");
1043 priv->stations[sta_id].sta.key.key_flags = key_flags;
1046 /* This copy is acutally not needed: we get the key with each TX */
1047 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
1049 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
1051 spin_unlock_irqrestore(&priv->sta_lock, flags);
1056 void iwl_update_tkip_key(struct iwl_priv *priv,
1057 struct ieee80211_key_conf *keyconf,
1058 const u8 *addr, u32 iv32, u16 *phase1key)
1060 u8 sta_id = IWL_INVALID_STATION;
1061 unsigned long flags;
1064 sta_id = iwl_find_station(priv, addr);
1065 if (sta_id == IWL_INVALID_STATION) {
1066 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
1071 if (iwl_scan_cancel(priv)) {
1072 /* cancel scan failed, just live w/ bad key and rely
1073 briefly on SW decryption */
1077 spin_lock_irqsave(&priv->sta_lock, flags);
1079 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
1081 for (i = 0; i < 5; i++)
1082 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
1083 cpu_to_le16(phase1key[i]);
1085 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1086 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1088 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1090 spin_unlock_irqrestore(&priv->sta_lock, flags);
1093 EXPORT_SYMBOL(iwl_update_tkip_key);
1095 int iwl_remove_dynamic_key(struct iwl_priv *priv,
1096 struct ieee80211_key_conf *keyconf,
1099 unsigned long flags;
1104 priv->key_mapping_key--;
1106 spin_lock_irqsave(&priv->sta_lock, flags);
1107 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
1108 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
1110 IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
1111 keyconf->keyidx, sta_id);
1113 if (keyconf->keyidx != keyidx) {
1114 /* We need to remove a key with index different that the one
1115 * in the uCode. This means that the key we need to remove has
1116 * been replaced by another one with different index.
1117 * Don't do anything and return ok
1119 spin_unlock_irqrestore(&priv->sta_lock, flags);
1123 if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
1124 IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
1125 keyconf->keyidx, key_flags);
1126 spin_unlock_irqrestore(&priv->sta_lock, flags);
1130 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
1131 &priv->ucode_key_table))
1132 IWL_ERR(priv, "index %d not used in uCode key table.\n",
1133 priv->stations[sta_id].sta.key.key_offset);
1134 memset(&priv->stations[sta_id].keyinfo, 0,
1135 sizeof(struct iwl_hw_key));
1136 memset(&priv->stations[sta_id].sta.key, 0,
1137 sizeof(struct iwl4965_keyinfo));
1138 priv->stations[sta_id].sta.key.key_flags =
1139 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
1140 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
1141 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1142 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1144 if (iwl_is_rfkill(priv)) {
1145 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
1146 spin_unlock_irqrestore(&priv->sta_lock, flags);
1149 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1150 spin_unlock_irqrestore(&priv->sta_lock, flags);
1153 EXPORT_SYMBOL(iwl_remove_dynamic_key);
1155 int iwl_set_dynamic_key(struct iwl_priv *priv,
1156 struct ieee80211_key_conf *keyconf, u8 sta_id)
1160 priv->key_mapping_key++;
1161 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
1163 switch (keyconf->alg) {
1165 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
1168 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
1171 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
1175 "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
1179 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
1180 keyconf->alg, keyconf->keylen, keyconf->keyidx,
1185 EXPORT_SYMBOL(iwl_set_dynamic_key);
1187 #ifdef CONFIG_IWLWIFI_DEBUG
1188 static void iwl_dump_lq_cmd(struct iwl_priv *priv,
1189 struct iwl_link_quality_cmd *lq)
1192 IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id);
1193 IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n",
1194 lq->general_params.single_stream_ant_msk,
1195 lq->general_params.dual_stream_ant_msk);
1197 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
1198 IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n",
1199 i, lq->rs_table[i].rate_n_flags);
1202 static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
1203 struct iwl_link_quality_cmd *lq)
1209 * iwl_send_lq_cmd() - Send link quality command
1210 * @init: This command is sent as part of station initialization right
1211 * after station has been added.
1213 * The link quality command is sent as the last step of station creation.
1214 * This is the special case in which init is set and we call a callback in
1215 * this case to clear the state indicating that station creation is in
1218 int iwl_send_lq_cmd(struct iwl_priv *priv,
1219 struct iwl_link_quality_cmd *lq, u8 flags, bool init)
1222 unsigned long flags_spin;
1224 struct iwl_host_cmd cmd = {
1225 .id = REPLY_TX_LINK_QUALITY_CMD,
1226 .len = sizeof(struct iwl_link_quality_cmd),
1231 if (WARN_ON(lq->sta_id == IWL_INVALID_STATION))
1234 iwl_dump_lq_cmd(priv, lq);
1235 BUG_ON(init && (cmd.flags & CMD_ASYNC));
1237 ret = iwl_send_cmd(priv, &cmd);
1239 if (cmd.flags & CMD_ASYNC)
1243 IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n",
1245 spin_lock_irqsave(&priv->sta_lock, flags_spin);
1246 priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1247 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
1251 EXPORT_SYMBOL(iwl_send_lq_cmd);
1254 * iwl_add_bcast_station - add broadcast station into station table.
1256 int iwl_add_bcast_station(struct iwl_priv *priv)
1258 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n");
1259 return iwl_add_local_station(priv, iwl_bcast_addr, true);
1261 EXPORT_SYMBOL(iwl_add_bcast_station);
1264 * iwl3945_add_bcast_station - add broadcast station into station table.
1266 int iwl3945_add_bcast_station(struct iwl_priv *priv)
1270 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n");
1271 ret = iwl_add_local_station(priv, iwl_bcast_addr, false);
1273 * It is assumed that when station is added more initialization
1274 * needs to be done, but for 3945 it is not the case and we can
1275 * just release station table access right here.
1277 priv->stations[priv->hw_params.bcast_sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1281 EXPORT_SYMBOL(iwl3945_add_bcast_station);
1284 * iwl_get_sta_id - Find station's index within station table
1286 * If new IBSS station, create new entry in station table
1288 int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1291 __le16 fc = hdr->frame_control;
1293 /* If this frame is broadcast or management, use broadcast station id */
1294 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
1295 return priv->hw_params.bcast_sta_id;
1297 switch (priv->iw_mode) {
1299 /* If we are a client station in a BSS network, use the special
1300 * AP station entry (that's the only station we communicate with) */
1301 case NL80211_IFTYPE_STATION:
1303 * If addition of station not complete yet, which means
1304 * that rate scaling has not been initialized, then return
1305 * the broadcast station.
1307 if (!(priv->stations[IWL_AP_ID].used & IWL_STA_UCODE_ACTIVE))
1308 return priv->hw_params.bcast_sta_id;
1311 /* If we are an AP, then find the station, or use BCAST */
1312 case NL80211_IFTYPE_AP:
1313 sta_id = iwl_find_station(priv, hdr->addr1);
1314 if (sta_id != IWL_INVALID_STATION)
1316 return priv->hw_params.bcast_sta_id;
1318 /* If this frame is going out to an IBSS network, find the station,
1319 * or create a new station table entry */
1320 case NL80211_IFTYPE_ADHOC:
1321 sta_id = iwl_find_station(priv, hdr->addr1);
1322 if (sta_id != IWL_INVALID_STATION)
1325 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
1326 "Defaulting to broadcast...\n",
1328 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
1329 return priv->hw_params.bcast_sta_id;
1332 IWL_WARN(priv, "Unknown mode of operation: %d\n",
1334 return priv->hw_params.bcast_sta_id;
1337 EXPORT_SYMBOL(iwl_get_sta_id);
1340 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1342 void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
1344 unsigned long flags;
1346 /* Remove "disable" flag, to enable Tx for this TID */
1347 spin_lock_irqsave(&priv->sta_lock, flags);
1348 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
1349 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
1350 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1351 spin_unlock_irqrestore(&priv->sta_lock, flags);
1353 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1355 EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid);
1357 int iwl_sta_rx_agg_start(struct iwl_priv *priv,
1358 const u8 *addr, int tid, u16 ssn)
1360 unsigned long flags;
1363 sta_id = iwl_find_station(priv, addr);
1364 if (sta_id == IWL_INVALID_STATION)
1367 spin_lock_irqsave(&priv->sta_lock, flags);
1368 priv->stations[sta_id].sta.station_flags_msk = 0;
1369 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
1370 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
1371 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
1372 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1373 spin_unlock_irqrestore(&priv->sta_lock, flags);
1375 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
1378 EXPORT_SYMBOL(iwl_sta_rx_agg_start);
1380 int iwl_sta_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid)
1382 unsigned long flags;
1385 sta_id = iwl_find_station(priv, addr);
1386 if (sta_id == IWL_INVALID_STATION) {
1387 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
1391 spin_lock_irqsave(&priv->sta_lock, flags);
1392 priv->stations[sta_id].sta.station_flags_msk = 0;
1393 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
1394 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
1395 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1396 spin_unlock_irqrestore(&priv->sta_lock, flags);
1398 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
1401 EXPORT_SYMBOL(iwl_sta_rx_agg_stop);
1403 void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1405 unsigned long flags;
1407 spin_lock_irqsave(&priv->sta_lock, flags);
1408 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
1409 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1410 priv->stations[sta_id].sta.sta.modify_mask = 0;
1411 priv->stations[sta_id].sta.sleep_tx_count = 0;
1412 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1413 spin_unlock_irqrestore(&priv->sta_lock, flags);
1415 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1417 EXPORT_SYMBOL(iwl_sta_modify_ps_wake);
1419 void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
1421 unsigned long flags;
1423 spin_lock_irqsave(&priv->sta_lock, flags);
1424 priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
1425 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1426 priv->stations[sta_id].sta.sta.modify_mask =
1427 STA_MODIFY_SLEEP_TX_COUNT_MSK;
1428 priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
1429 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1430 spin_unlock_irqrestore(&priv->sta_lock, flags);
1432 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1434 EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count);
1436 int iwl_mac_sta_remove(struct ieee80211_hw *hw,
1437 struct ieee80211_vif *vif,
1438 struct ieee80211_sta *sta)
1441 struct iwl_priv *priv = hw->priv;
1442 IWL_DEBUG_INFO(priv, "received request to remove station %pM\n",
1444 ret = iwl_remove_station(priv, sta->addr);
1446 IWL_ERR(priv, "Error removing station %pM\n",
1450 EXPORT_SYMBOL(iwl_mac_sta_remove);