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 int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
85 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
88 u8 *da = ieee80211_get_DA(hdr);
89 return iwl_find_station(priv, da);
92 EXPORT_SYMBOL(iwl_get_ra_sta_id);
94 /* priv->sta_lock must be held */
95 static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
98 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE))
99 IWL_ERR(priv, "ACTIVATE a non DRIVER active station id %u addr %pM\n",
100 sta_id, priv->stations[sta_id].sta.sta.addr);
102 if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) {
103 IWL_DEBUG_ASSOC(priv,
104 "STA id %u addr %pM already present in uCode (according to driver)\n",
105 sta_id, priv->stations[sta_id].sta.sta.addr);
107 priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE;
108 IWL_DEBUG_ASSOC(priv, "Added STA id %u addr %pM to uCode\n",
109 sta_id, priv->stations[sta_id].sta.sta.addr);
113 static void iwl_process_add_sta_resp(struct iwl_priv *priv,
114 struct iwl_addsta_cmd *addsta,
115 struct iwl_rx_packet *pkt,
118 u8 sta_id = addsta->sta.sta_id;
121 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
122 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
127 IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n",
130 spin_lock_irqsave(&priv->sta_lock, flags);
132 switch (pkt->u.add_sta.status) {
133 case ADD_STA_SUCCESS_MSK:
134 IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n");
135 iwl_sta_ucode_activate(priv, sta_id);
137 case ADD_STA_NO_ROOM_IN_TABLE:
138 IWL_ERR(priv, "Adding station %d failed, no room in table.\n",
141 case ADD_STA_NO_BLOCK_ACK_RESOURCE:
142 IWL_ERR(priv, "Adding station %d failed, no block ack resource.\n",
145 case ADD_STA_MODIFY_NON_EXIST_STA:
146 IWL_ERR(priv, "Attempting to modify non-existing station %d\n",
150 IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n",
151 pkt->u.add_sta.status);
155 IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n",
156 priv->stations[sta_id].sta.mode ==
157 STA_CONTROL_MODIFY_MSK ? "Modified" : "Added",
158 sta_id, priv->stations[sta_id].sta.sta.addr);
161 * XXX: The MAC address in the command buffer is often changed from
162 * the original sent to the device. That is, the MAC address
163 * written to the command buffer often is not the same MAC adress
164 * read from the command buffer when the command returns. This
165 * issue has not yet been resolved and this debugging is left to
166 * observe the problem.
168 IWL_DEBUG_INFO(priv, "%s station according to cmd buffer %pM\n",
169 priv->stations[sta_id].sta.mode ==
170 STA_CONTROL_MODIFY_MSK ? "Modified" : "Added",
172 spin_unlock_irqrestore(&priv->sta_lock, flags);
175 static void iwl_add_sta_callback(struct iwl_priv *priv,
176 struct iwl_device_cmd *cmd,
177 struct iwl_rx_packet *pkt)
179 struct iwl_addsta_cmd *addsta =
180 (struct iwl_addsta_cmd *)cmd->cmd.payload;
182 iwl_process_add_sta_resp(priv, addsta, pkt, false);
186 int iwl_send_add_sta(struct iwl_priv *priv,
187 struct iwl_addsta_cmd *sta, u8 flags)
189 struct iwl_rx_packet *pkt = NULL;
191 u8 data[sizeof(*sta)];
192 struct iwl_host_cmd cmd = {
197 u8 sta_id __maybe_unused = sta->sta.sta_id;
199 IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n",
200 sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : "");
202 if (flags & CMD_ASYNC)
203 cmd.callback = iwl_add_sta_callback;
205 cmd.flags |= CMD_WANT_SKB;
207 cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
208 ret = iwl_send_cmd(priv, &cmd);
210 if (ret || (flags & CMD_ASYNC))
214 pkt = (struct iwl_rx_packet *)cmd.reply_page;
215 iwl_process_add_sta_resp(priv, sta, pkt, true);
217 iwl_free_pages(priv, cmd.reply_page);
221 EXPORT_SYMBOL(iwl_send_add_sta);
223 static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
224 struct ieee80211_sta_ht_cap *sta_ht_inf)
229 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
232 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
233 IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n",
234 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ?
236 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ?
237 "dynamic" : "disabled");
239 sta_flags = priv->stations[index].sta.station_flags;
241 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
243 switch (mimo_ps_mode) {
244 case WLAN_HT_CAP_SM_PS_STATIC:
245 sta_flags |= STA_FLG_MIMO_DIS_MSK;
247 case WLAN_HT_CAP_SM_PS_DYNAMIC:
248 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
250 case WLAN_HT_CAP_SM_PS_DISABLED:
253 IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode);
257 sta_flags |= cpu_to_le32(
258 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
260 sta_flags |= cpu_to_le32(
261 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
263 if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf))
264 sta_flags |= STA_FLG_HT40_EN_MSK;
266 sta_flags &= ~STA_FLG_HT40_EN_MSK;
268 priv->stations[index].sta.station_flags = sta_flags;
274 * iwl_prep_station - Prepare station information for addition
276 * should be called with sta_lock held
278 static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
280 struct ieee80211_sta_ht_cap *ht_info)
282 struct iwl_station_entry *station;
284 u8 sta_id = IWL_INVALID_STATION;
289 else if (is_broadcast_ether_addr(addr))
290 sta_id = priv->hw_params.bcast_sta_id;
292 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
293 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
299 if (!priv->stations[i].used &&
300 sta_id == IWL_INVALID_STATION)
305 * These two conditions have the same outcome, but keep them
308 if (unlikely(sta_id == IWL_INVALID_STATION))
312 * uCode is not able to deal with multiple requests to add a
313 * station. Keep track if one is in progress so that we do not send
316 if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
317 IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
322 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
323 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) &&
324 !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) {
325 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
330 station = &priv->stations[sta_id];
331 station->used = IWL_STA_DRIVER_ACTIVE;
332 IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n",
334 priv->num_stations++;
336 /* Set up the REPLY_ADD_STA command to send to device */
337 memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
338 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
339 station->sta.mode = 0;
340 station->sta.sta.sta_id = sta_id;
341 station->sta.station_flags = 0;
343 /* BCAST station and IBSS stations do not work in HT mode */
344 if (sta_id != priv->hw_params.bcast_sta_id &&
345 priv->iw_mode != NL80211_IFTYPE_ADHOC)
346 iwl_set_ht_add_station(priv, sta_id, ht_info);
349 rate = (priv->band == IEEE80211_BAND_5GHZ) ?
350 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP;
351 /* Turn on both antennas for the station... */
352 station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK);
358 #define STA_WAIT_TIMEOUT (HZ/2)
361 * iwl_add_station_common -
363 int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr,
365 struct ieee80211_sta_ht_cap *ht_info,
368 struct iwl_station_entry *station;
369 unsigned long flags_spin;
374 spin_lock_irqsave(&priv->sta_lock, flags_spin);
375 sta_id = iwl_prep_station(priv, addr, is_ap, ht_info);
376 if (sta_id == IWL_INVALID_STATION) {
377 IWL_ERR(priv, "Unable to prepare station %pM for addition\n",
379 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
384 * uCode is not able to deal with multiple requests to add a
385 * station. Keep track if one is in progress so that we do not send
388 if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
389 IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
391 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
395 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
396 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
397 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
399 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
403 priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS;
404 station = &priv->stations[sta_id];
405 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
407 /* Add station to device's station table */
408 ret = iwl_send_add_sta(priv, &station->sta, CMD_SYNC);
410 IWL_ERR(priv, "Adding station %pM failed.\n", station->sta.sta.addr);
411 spin_lock_irqsave(&priv->sta_lock, flags_spin);
412 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
413 priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
414 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
419 EXPORT_SYMBOL(iwl_add_station_common);
421 static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, bool is_ap)
424 struct iwl_link_quality_cmd link_cmd = {
430 /* Set up the rate scaling to start at selected rate, fall back
431 * all the way down to 1M in IEEE order, and then spin on 1M */
433 r = IWL_RATE_54M_INDEX;
434 else if (priv->band == IEEE80211_BAND_5GHZ)
435 r = IWL_RATE_6M_INDEX;
437 r = IWL_RATE_1M_INDEX;
439 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
441 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
442 rate_flags |= RATE_MCS_CCK_MSK;
444 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
447 link_cmd.rs_table[i].rate_n_flags =
448 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
449 r = iwl_get_prev_ieee_rate(r);
452 link_cmd.general_params.single_stream_ant_msk =
453 first_antenna(priv->hw_params.valid_tx_ant);
455 link_cmd.general_params.dual_stream_ant_msk =
456 priv->hw_params.valid_tx_ant &
457 ~first_antenna(priv->hw_params.valid_tx_ant);
458 if (!link_cmd.general_params.dual_stream_ant_msk) {
459 link_cmd.general_params.dual_stream_ant_msk = ANT_AB;
460 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
461 link_cmd.general_params.dual_stream_ant_msk =
462 priv->hw_params.valid_tx_ant;
465 link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
466 link_cmd.agg_params.agg_time_limit =
467 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
469 /* Update the rate scaling for control frame Tx to AP */
470 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
472 ret = iwl_send_cmd_pdu(priv, REPLY_TX_LINK_QUALITY_CMD,
473 sizeof(link_cmd), &link_cmd);
475 IWL_ERR(priv, "REPLY_TX_LINK_QUALITY_CMD failed (%d)\n", ret);
479 * iwl_add_local_stations - Add stations not requested by mac80211
481 * This will be either the broadcast station or the bssid station needed by
486 int iwl_add_local_station(struct iwl_priv *priv, const u8 *addr, bool init_rs)
491 ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id);
493 IWL_ERR(priv, "Unable to add station %pM\n", addr);
498 /* Set up default rate scaling table in device's station table */
499 iwl_sta_init_lq(priv, addr, false);
502 EXPORT_SYMBOL(iwl_add_local_station);
505 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
507 * priv->sta_lock must be held
509 static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id)
511 /* Ucode must be active and driver must be non active */
512 if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE)
513 IWL_ERR(priv, "removed non active STA %u\n", sta_id);
515 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
517 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
518 IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id);
521 static int iwl_send_remove_station(struct iwl_priv *priv,
522 struct iwl_station_entry *station)
524 struct iwl_rx_packet *pkt;
527 unsigned long flags_spin;
528 struct iwl_rem_sta_cmd rm_sta_cmd;
530 struct iwl_host_cmd cmd = {
531 .id = REPLY_REMOVE_STA,
532 .len = sizeof(struct iwl_rem_sta_cmd),
537 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
538 rm_sta_cmd.num_sta = 1;
539 memcpy(&rm_sta_cmd.addr, &station->sta.sta.addr , ETH_ALEN);
541 cmd.flags |= CMD_WANT_SKB;
543 ret = iwl_send_cmd(priv, &cmd);
548 pkt = (struct iwl_rx_packet *)cmd.reply_page;
549 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
550 IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
556 switch (pkt->u.rem_sta.status) {
557 case REM_STA_SUCCESS_MSK:
558 spin_lock_irqsave(&priv->sta_lock, flags_spin);
559 iwl_sta_ucode_deactivate(priv, station->sta.sta.sta_id);
560 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
561 IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n");
565 IWL_ERR(priv, "REPLY_REMOVE_STA failed\n");
569 iwl_free_pages(priv, cmd.reply_page);
575 * iwl_remove_station - Remove driver's knowledge of station.
577 static int iwl_remove_station(struct iwl_priv *priv, struct ieee80211_sta *sta)
579 int sta_id = IWL_INVALID_STATION;
580 int i, ret = -EINVAL;
582 bool is_ap = priv->iw_mode == NL80211_IFTYPE_STATION;
583 struct iwl_station_entry *station;
585 if (!iwl_is_ready(priv)) {
587 "Unable to remove station %pM, device not ready.\n",
590 * It is typical for stations to be removed when we are
591 * going down. Return success since device will be down
597 spin_lock_irqsave(&priv->sta_lock, flags);
602 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
603 if (priv->stations[i].used &&
604 !compare_ether_addr(priv->stations[i].sta.sta.addr,
610 if (unlikely(sta_id == IWL_INVALID_STATION))
613 IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n",
616 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
617 IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n",
622 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
623 IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n",
629 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
631 priv->num_stations--;
633 BUG_ON(priv->num_stations < 0);
635 station = &priv->stations[sta_id];
636 spin_unlock_irqrestore(&priv->sta_lock, flags);
638 ret = iwl_send_remove_station(priv, station);
641 spin_unlock_irqrestore(&priv->sta_lock, flags);
646 * iwl_clear_ucode_stations() - clear entire station table driver and/or ucode
648 * @force: If set then the uCode station table needs to be cleared here. If
649 * not set then the uCode station table has already been cleared,
650 * for example after sending it a RXON command without ASSOC bit
651 * set, and we just need to change driver state here.
653 void iwl_clear_ucode_stations(struct iwl_priv *priv, bool force)
656 unsigned long flags_spin;
657 bool cleared = false;
659 IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver%s\n",
660 force ? " and ucode" : "");
663 if (!iwl_is_ready(priv)) {
665 * If device is not ready at this point the station
666 * table is likely already empty (uCode not ready
667 * to receive station requests) or will soon be
668 * due to interface going down.
670 IWL_DEBUG_INFO(priv, "Unable to remove stations from device - device not ready\n");
672 iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL);
676 spin_lock_irqsave(&priv->sta_lock, flags_spin);
678 IWL_DEBUG_INFO(priv, "Clearing all station information in driver\n");
679 priv->num_stations = 0;
680 memset(priv->stations, 0, sizeof(priv->stations));
682 for (i = 0; i < priv->hw_params.max_stations; i++) {
683 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) {
684 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i);
685 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
690 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
693 IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n");
695 EXPORT_SYMBOL(iwl_clear_ucode_stations);
698 * iwl_restore_stations() - Restore driver known stations to device
700 * All stations considered active by driver, but not present in ucode, is
705 void iwl_restore_stations(struct iwl_priv *priv)
707 struct iwl_station_entry *station;
708 unsigned long flags_spin;
713 if (!iwl_is_ready(priv)) {
714 IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n");
718 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n");
719 spin_lock_irqsave(&priv->sta_lock, flags_spin);
720 for (i = 0; i < priv->hw_params.max_stations; i++) {
721 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) &&
722 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) {
723 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n",
724 priv->stations[i].sta.sta.addr);
725 priv->stations[i].sta.mode = 0;
726 priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS;
731 for (i = 0; i < priv->hw_params.max_stations; i++) {
732 if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) {
733 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
734 station = &priv->stations[i];
735 ret = iwl_send_add_sta(priv, &priv->stations[i].sta, CMD_SYNC);
737 IWL_ERR(priv, "Adding station %pM failed.\n",
738 station->sta.sta.addr);
739 spin_lock_irqsave(&priv->sta_lock, flags_spin);
740 priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE;
741 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
742 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
745 * Rate scaling has already been initialized, send
749 iwl_send_lq_cmd(priv, station->lq, CMD_SYNC, true);
750 spin_lock_irqsave(&priv->sta_lock, flags_spin);
751 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
755 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
757 IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n");
759 IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n");
761 EXPORT_SYMBOL(iwl_restore_stations);
763 int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
767 for (i = 0; i < STA_KEY_MAX_NUM; i++)
768 if (!test_and_set_bit(i, &priv->ucode_key_table))
771 return WEP_INVALID_OFFSET;
773 EXPORT_SYMBOL(iwl_get_free_ucode_key_index);
775 static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
777 int i, not_empty = 0;
778 u8 buff[sizeof(struct iwl_wep_cmd) +
779 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
780 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
781 size_t cmd_size = sizeof(struct iwl_wep_cmd);
782 struct iwl_host_cmd cmd = {
790 memset(wep_cmd, 0, cmd_size +
791 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
793 for (i = 0; i < WEP_KEYS_MAX ; i++) {
794 wep_cmd->key[i].key_index = i;
795 if (priv->wep_keys[i].key_size) {
796 wep_cmd->key[i].key_offset = i;
799 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
802 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
803 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
804 priv->wep_keys[i].key_size);
807 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
808 wep_cmd->num_keys = WEP_KEYS_MAX;
810 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
814 if (not_empty || send_if_empty)
815 return iwl_send_cmd(priv, &cmd);
820 int iwl_restore_default_wep_keys(struct iwl_priv *priv)
822 WARN_ON(!mutex_is_locked(&priv->mutex));
824 return iwl_send_static_wepkey_cmd(priv, 0);
826 EXPORT_SYMBOL(iwl_restore_default_wep_keys);
828 int iwl_remove_default_wep_key(struct iwl_priv *priv,
829 struct ieee80211_key_conf *keyconf)
833 WARN_ON(!mutex_is_locked(&priv->mutex));
835 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
838 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
839 if (iwl_is_rfkill(priv)) {
840 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
841 /* but keys in device are clear anyway so return success */
844 ret = iwl_send_static_wepkey_cmd(priv, 1);
845 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
846 keyconf->keyidx, ret);
850 EXPORT_SYMBOL(iwl_remove_default_wep_key);
852 int iwl_set_default_wep_key(struct iwl_priv *priv,
853 struct ieee80211_key_conf *keyconf)
857 WARN_ON(!mutex_is_locked(&priv->mutex));
859 if (keyconf->keylen != WEP_KEY_LEN_128 &&
860 keyconf->keylen != WEP_KEY_LEN_64) {
861 IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
865 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
866 keyconf->hw_key_idx = HW_KEY_DEFAULT;
867 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
869 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
870 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
873 ret = iwl_send_static_wepkey_cmd(priv, 0);
874 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
875 keyconf->keylen, keyconf->keyidx, ret);
879 EXPORT_SYMBOL(iwl_set_default_wep_key);
881 static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
882 struct ieee80211_key_conf *keyconf,
886 __le16 key_flags = 0;
889 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
891 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
892 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
893 key_flags &= ~STA_KEY_FLG_INVALID;
895 if (keyconf->keylen == WEP_KEY_LEN_128)
896 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
898 if (sta_id == priv->hw_params.bcast_sta_id)
899 key_flags |= STA_KEY_MULTICAST_MSK;
901 spin_lock_irqsave(&priv->sta_lock, flags);
903 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
904 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
905 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
907 memcpy(priv->stations[sta_id].keyinfo.key,
908 keyconf->key, keyconf->keylen);
910 memcpy(&priv->stations[sta_id].sta.key.key[3],
911 keyconf->key, keyconf->keylen);
913 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
914 == STA_KEY_FLG_NO_ENC)
915 priv->stations[sta_id].sta.key.key_offset =
916 iwl_get_free_ucode_key_index(priv);
917 /* else, we are overriding an existing key => no need to allocated room
920 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
921 "no space for a new key");
923 priv->stations[sta_id].sta.key.key_flags = key_flags;
924 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
925 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
927 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
929 spin_unlock_irqrestore(&priv->sta_lock, flags);
934 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
935 struct ieee80211_key_conf *keyconf,
939 __le16 key_flags = 0;
942 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
943 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
944 key_flags &= ~STA_KEY_FLG_INVALID;
946 if (sta_id == priv->hw_params.bcast_sta_id)
947 key_flags |= STA_KEY_MULTICAST_MSK;
949 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
951 spin_lock_irqsave(&priv->sta_lock, flags);
952 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
953 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
955 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
958 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
961 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
962 == STA_KEY_FLG_NO_ENC)
963 priv->stations[sta_id].sta.key.key_offset =
964 iwl_get_free_ucode_key_index(priv);
965 /* else, we are overriding an existing key => no need to allocated room
968 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
969 "no space for a new key");
971 priv->stations[sta_id].sta.key.key_flags = key_flags;
972 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
973 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
975 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
977 spin_unlock_irqrestore(&priv->sta_lock, flags);
982 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
983 struct ieee80211_key_conf *keyconf,
988 __le16 key_flags = 0;
990 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
991 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
992 key_flags &= ~STA_KEY_FLG_INVALID;
994 if (sta_id == priv->hw_params.bcast_sta_id)
995 key_flags |= STA_KEY_MULTICAST_MSK;
997 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
998 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1000 spin_lock_irqsave(&priv->sta_lock, flags);
1002 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1003 priv->stations[sta_id].keyinfo.keylen = 16;
1005 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
1006 == STA_KEY_FLG_NO_ENC)
1007 priv->stations[sta_id].sta.key.key_offset =
1008 iwl_get_free_ucode_key_index(priv);
1009 /* else, we are overriding an existing key => no need to allocated room
1012 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
1013 "no space for a new key");
1015 priv->stations[sta_id].sta.key.key_flags = key_flags;
1018 /* This copy is acutally not needed: we get the key with each TX */
1019 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
1021 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
1023 spin_unlock_irqrestore(&priv->sta_lock, flags);
1028 void iwl_update_tkip_key(struct iwl_priv *priv,
1029 struct ieee80211_key_conf *keyconf,
1030 const u8 *addr, u32 iv32, u16 *phase1key)
1032 u8 sta_id = IWL_INVALID_STATION;
1033 unsigned long flags;
1036 sta_id = iwl_find_station(priv, addr);
1037 if (sta_id == IWL_INVALID_STATION) {
1038 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
1043 if (iwl_scan_cancel(priv)) {
1044 /* cancel scan failed, just live w/ bad key and rely
1045 briefly on SW decryption */
1049 spin_lock_irqsave(&priv->sta_lock, flags);
1051 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
1053 for (i = 0; i < 5; i++)
1054 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
1055 cpu_to_le16(phase1key[i]);
1057 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1058 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1060 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1062 spin_unlock_irqrestore(&priv->sta_lock, flags);
1065 EXPORT_SYMBOL(iwl_update_tkip_key);
1067 int iwl_remove_dynamic_key(struct iwl_priv *priv,
1068 struct ieee80211_key_conf *keyconf,
1071 unsigned long flags;
1076 priv->key_mapping_key--;
1078 spin_lock_irqsave(&priv->sta_lock, flags);
1079 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
1080 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
1082 IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
1083 keyconf->keyidx, sta_id);
1085 if (keyconf->keyidx != keyidx) {
1086 /* We need to remove a key with index different that the one
1087 * in the uCode. This means that the key we need to remove has
1088 * been replaced by another one with different index.
1089 * Don't do anything and return ok
1091 spin_unlock_irqrestore(&priv->sta_lock, flags);
1095 if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
1096 IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
1097 keyconf->keyidx, key_flags);
1098 spin_unlock_irqrestore(&priv->sta_lock, flags);
1102 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
1103 &priv->ucode_key_table))
1104 IWL_ERR(priv, "index %d not used in uCode key table.\n",
1105 priv->stations[sta_id].sta.key.key_offset);
1106 memset(&priv->stations[sta_id].keyinfo, 0,
1107 sizeof(struct iwl_hw_key));
1108 memset(&priv->stations[sta_id].sta.key, 0,
1109 sizeof(struct iwl4965_keyinfo));
1110 priv->stations[sta_id].sta.key.key_flags =
1111 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
1112 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
1113 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1114 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1116 if (iwl_is_rfkill(priv)) {
1117 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
1118 spin_unlock_irqrestore(&priv->sta_lock, flags);
1121 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1122 spin_unlock_irqrestore(&priv->sta_lock, flags);
1125 EXPORT_SYMBOL(iwl_remove_dynamic_key);
1127 int iwl_set_dynamic_key(struct iwl_priv *priv,
1128 struct ieee80211_key_conf *keyconf, u8 sta_id)
1132 priv->key_mapping_key++;
1133 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
1135 switch (keyconf->alg) {
1137 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
1140 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
1143 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
1147 "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
1151 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
1152 keyconf->alg, keyconf->keylen, keyconf->keyidx,
1157 EXPORT_SYMBOL(iwl_set_dynamic_key);
1159 #ifdef CONFIG_IWLWIFI_DEBUG
1160 static void iwl_dump_lq_cmd(struct iwl_priv *priv,
1161 struct iwl_link_quality_cmd *lq)
1164 IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id);
1165 IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n",
1166 lq->general_params.single_stream_ant_msk,
1167 lq->general_params.dual_stream_ant_msk);
1169 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
1170 IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n",
1171 i, lq->rs_table[i].rate_n_flags);
1174 static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
1175 struct iwl_link_quality_cmd *lq)
1181 * iwl_send_lq_cmd() - Send link quality command
1182 * @init: This command is sent as part of station initialization right
1183 * after station has been added.
1185 * The link quality command is sent as the last step of station creation.
1186 * This is the special case in which init is set and we call a callback in
1187 * this case to clear the state indicating that station creation is in
1190 int iwl_send_lq_cmd(struct iwl_priv *priv,
1191 struct iwl_link_quality_cmd *lq, u8 flags, bool init)
1194 unsigned long flags_spin;
1196 struct iwl_host_cmd cmd = {
1197 .id = REPLY_TX_LINK_QUALITY_CMD,
1198 .len = sizeof(struct iwl_link_quality_cmd),
1203 if (WARN_ON(lq->sta_id == IWL_INVALID_STATION))
1206 iwl_dump_lq_cmd(priv, lq);
1207 BUG_ON(init && (cmd.flags & CMD_ASYNC));
1209 ret = iwl_send_cmd(priv, &cmd);
1210 if (ret || (cmd.flags & CMD_ASYNC))
1214 IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n",
1216 spin_lock_irqsave(&priv->sta_lock, flags_spin);
1217 priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1218 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
1222 EXPORT_SYMBOL(iwl_send_lq_cmd);
1225 * iwl_add_bcast_station - add broadcast station into station table.
1227 void iwl_add_bcast_station(struct iwl_priv *priv)
1229 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n");
1230 iwl_add_local_station(priv, iwl_bcast_addr, true);
1232 EXPORT_SYMBOL(iwl_add_bcast_station);
1235 * iwl3945_add_bcast_station - add broadcast station into station table.
1237 void iwl3945_add_bcast_station(struct iwl_priv *priv)
1239 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n");
1240 iwl_add_local_station(priv, iwl_bcast_addr, false);
1242 * It is assumed that when station is added more initialization
1243 * needs to be done, but for 3945 it is not the case and we can
1244 * just release station table access right here.
1246 priv->stations[priv->hw_params.bcast_sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1249 EXPORT_SYMBOL(iwl3945_add_bcast_station);
1252 * iwl_get_sta_id - Find station's index within station table
1254 * If new IBSS station, create new entry in station table
1256 int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1259 __le16 fc = hdr->frame_control;
1261 /* If this frame is broadcast or management, use broadcast station id */
1262 if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
1263 return priv->hw_params.bcast_sta_id;
1265 switch (priv->iw_mode) {
1267 /* If we are a client station in a BSS network, use the special
1268 * AP station entry (that's the only station we communicate with) */
1269 case NL80211_IFTYPE_STATION:
1271 * If addition of station not complete yet, which means
1272 * that rate scaling has not been initialized, then return
1273 * the broadcast station.
1275 if (!(priv->stations[IWL_AP_ID].used & IWL_STA_UCODE_ACTIVE))
1276 return priv->hw_params.bcast_sta_id;
1279 /* If we are an AP, then find the station, or use BCAST */
1280 case NL80211_IFTYPE_AP:
1281 sta_id = iwl_find_station(priv, hdr->addr1);
1282 if (sta_id != IWL_INVALID_STATION)
1284 return priv->hw_params.bcast_sta_id;
1286 /* If this frame is going out to an IBSS network, find the station,
1287 * or create a new station table entry */
1288 case NL80211_IFTYPE_ADHOC:
1289 sta_id = iwl_find_station(priv, hdr->addr1);
1290 if (sta_id != IWL_INVALID_STATION)
1293 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
1294 "Defaulting to broadcast...\n",
1296 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
1297 return priv->hw_params.bcast_sta_id;
1300 IWL_WARN(priv, "Unknown mode of operation: %d\n",
1302 return priv->hw_params.bcast_sta_id;
1305 EXPORT_SYMBOL(iwl_get_sta_id);
1308 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1310 void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
1312 unsigned long flags;
1314 /* Remove "disable" flag, to enable Tx for this TID */
1315 spin_lock_irqsave(&priv->sta_lock, flags);
1316 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
1317 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
1318 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1319 spin_unlock_irqrestore(&priv->sta_lock, flags);
1321 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1323 EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid);
1325 int iwl_sta_rx_agg_start(struct iwl_priv *priv,
1326 const u8 *addr, int tid, u16 ssn)
1328 unsigned long flags;
1331 sta_id = iwl_find_station(priv, addr);
1332 if (sta_id == IWL_INVALID_STATION)
1335 spin_lock_irqsave(&priv->sta_lock, flags);
1336 priv->stations[sta_id].sta.station_flags_msk = 0;
1337 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
1338 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
1339 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
1340 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1341 spin_unlock_irqrestore(&priv->sta_lock, flags);
1343 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
1346 EXPORT_SYMBOL(iwl_sta_rx_agg_start);
1348 int iwl_sta_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid)
1350 unsigned long flags;
1353 sta_id = iwl_find_station(priv, addr);
1354 if (sta_id == IWL_INVALID_STATION) {
1355 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
1359 spin_lock_irqsave(&priv->sta_lock, flags);
1360 priv->stations[sta_id].sta.station_flags_msk = 0;
1361 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
1362 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
1363 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1364 spin_unlock_irqrestore(&priv->sta_lock, flags);
1366 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
1369 EXPORT_SYMBOL(iwl_sta_rx_agg_stop);
1371 void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1373 unsigned long flags;
1375 spin_lock_irqsave(&priv->sta_lock, flags);
1376 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
1377 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1378 priv->stations[sta_id].sta.sta.modify_mask = 0;
1379 priv->stations[sta_id].sta.sleep_tx_count = 0;
1380 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1381 spin_unlock_irqrestore(&priv->sta_lock, flags);
1383 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1385 EXPORT_SYMBOL(iwl_sta_modify_ps_wake);
1387 void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
1389 unsigned long flags;
1391 spin_lock_irqsave(&priv->sta_lock, flags);
1392 priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
1393 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1394 priv->stations[sta_id].sta.sta.modify_mask =
1395 STA_MODIFY_SLEEP_TX_COUNT_MSK;
1396 priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
1397 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1398 spin_unlock_irqrestore(&priv->sta_lock, flags);
1400 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1402 EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count);
1404 int iwl_mac_sta_remove(struct ieee80211_hw *hw,
1405 struct ieee80211_vif *vif,
1406 struct ieee80211_sta *sta)
1409 struct iwl_priv *priv = hw->priv;
1410 IWL_DEBUG_INFO(priv, "received request to remove station %pM\n",
1412 ret = iwl_remove_station(priv, sta);
1414 IWL_ERR(priv, "Error removing station %pM\n",
1418 EXPORT_SYMBOL(iwl_mac_sta_remove);