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>
33 #include <linux/lockdep.h>
39 /* priv->sta_lock must be held */
40 static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
43 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE))
44 IWL_ERR(priv, "ACTIVATE a non DRIVER active station id %u addr %pM\n",
45 sta_id, priv->stations[sta_id].sta.sta.addr);
47 if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) {
49 "STA id %u addr %pM already present in uCode (according to driver)\n",
50 sta_id, priv->stations[sta_id].sta.sta.addr);
52 priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE;
53 IWL_DEBUG_ASSOC(priv, "Added STA id %u addr %pM to uCode\n",
54 sta_id, priv->stations[sta_id].sta.sta.addr);
58 static int iwl_process_add_sta_resp(struct iwl_priv *priv,
59 struct iwl_addsta_cmd *addsta,
60 struct iwl_rx_packet *pkt,
63 u8 sta_id = addsta->sta.sta_id;
67 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
68 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
73 IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n",
76 spin_lock_irqsave(&priv->sta_lock, flags);
78 switch (pkt->u.add_sta.status) {
79 case ADD_STA_SUCCESS_MSK:
80 IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n");
81 iwl_sta_ucode_activate(priv, sta_id);
84 case ADD_STA_NO_ROOM_IN_TABLE:
85 IWL_ERR(priv, "Adding station %d failed, no room in table.\n",
88 case ADD_STA_NO_BLOCK_ACK_RESOURCE:
89 IWL_ERR(priv, "Adding station %d failed, no block ack resource.\n",
92 case ADD_STA_MODIFY_NON_EXIST_STA:
93 IWL_ERR(priv, "Attempting to modify non-existing station %d\n",
97 IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n",
98 pkt->u.add_sta.status);
102 IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n",
103 priv->stations[sta_id].sta.mode ==
104 STA_CONTROL_MODIFY_MSK ? "Modified" : "Added",
105 sta_id, priv->stations[sta_id].sta.sta.addr);
108 * XXX: The MAC address in the command buffer is often changed from
109 * the original sent to the device. That is, the MAC address
110 * written to the command buffer often is not the same MAC adress
111 * read from the command buffer when the command returns. This
112 * issue has not yet been resolved and this debugging is left to
113 * observe the problem.
115 IWL_DEBUG_INFO(priv, "%s station according to cmd buffer %pM\n",
116 priv->stations[sta_id].sta.mode ==
117 STA_CONTROL_MODIFY_MSK ? "Modified" : "Added",
119 spin_unlock_irqrestore(&priv->sta_lock, flags);
124 static void iwl_add_sta_callback(struct iwl_priv *priv,
125 struct iwl_device_cmd *cmd,
126 struct iwl_rx_packet *pkt)
128 struct iwl_addsta_cmd *addsta =
129 (struct iwl_addsta_cmd *)cmd->cmd.payload;
131 iwl_process_add_sta_resp(priv, addsta, pkt, false);
135 int iwl_send_add_sta(struct iwl_priv *priv,
136 struct iwl_addsta_cmd *sta, u8 flags)
138 struct iwl_rx_packet *pkt = NULL;
140 u8 data[sizeof(*sta)];
141 struct iwl_host_cmd cmd = {
146 u8 sta_id __maybe_unused = sta->sta.sta_id;
148 IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n",
149 sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : "");
151 if (flags & CMD_ASYNC)
152 cmd.callback = iwl_add_sta_callback;
154 cmd.flags |= CMD_WANT_SKB;
158 cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
159 ret = iwl_send_cmd(priv, &cmd);
161 if (ret || (flags & CMD_ASYNC))
165 pkt = (struct iwl_rx_packet *)cmd.reply_page;
166 ret = iwl_process_add_sta_resp(priv, sta, pkt, true);
168 iwl_free_pages(priv, cmd.reply_page);
172 EXPORT_SYMBOL(iwl_send_add_sta);
174 static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
175 struct ieee80211_sta_ht_cap *sta_ht_inf)
180 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
183 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
184 IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n",
185 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ?
187 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ?
188 "dynamic" : "disabled");
190 sta_flags = priv->stations[index].sta.station_flags;
192 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
194 switch (mimo_ps_mode) {
195 case WLAN_HT_CAP_SM_PS_STATIC:
196 sta_flags |= STA_FLG_MIMO_DIS_MSK;
198 case WLAN_HT_CAP_SM_PS_DYNAMIC:
199 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
201 case WLAN_HT_CAP_SM_PS_DISABLED:
204 IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode);
208 sta_flags |= cpu_to_le32(
209 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
211 sta_flags |= cpu_to_le32(
212 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
214 if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf))
215 sta_flags |= STA_FLG_HT40_EN_MSK;
217 sta_flags &= ~STA_FLG_HT40_EN_MSK;
219 priv->stations[index].sta.station_flags = sta_flags;
225 * iwl_prep_station - Prepare station information for addition
227 * should be called with sta_lock held
229 static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
231 struct ieee80211_sta_ht_cap *ht_info)
233 struct iwl_station_entry *station;
235 u8 sta_id = IWL_INVALID_STATION;
240 else if (is_broadcast_ether_addr(addr))
241 sta_id = priv->hw_params.bcast_sta_id;
243 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
244 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
250 if (!priv->stations[i].used &&
251 sta_id == IWL_INVALID_STATION)
256 * These two conditions have the same outcome, but keep them
259 if (unlikely(sta_id == IWL_INVALID_STATION))
263 * uCode is not able to deal with multiple requests to add a
264 * station. Keep track if one is in progress so that we do not send
267 if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
268 IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
273 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
274 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) &&
275 !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) {
276 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
281 station = &priv->stations[sta_id];
282 station->used = IWL_STA_DRIVER_ACTIVE;
283 IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n",
285 priv->num_stations++;
287 /* Set up the REPLY_ADD_STA command to send to device */
288 memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
289 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
290 station->sta.mode = 0;
291 station->sta.sta.sta_id = sta_id;
292 station->sta.station_flags = 0;
295 * OK to call unconditionally, since local stations (IBSS BSSID
296 * STA and broadcast STA) pass in a NULL ht_info, and mac80211
297 * doesn't allow HT IBSS.
299 iwl_set_ht_add_station(priv, sta_id, ht_info);
302 rate = (priv->band == IEEE80211_BAND_5GHZ) ?
303 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP;
304 /* Turn on both antennas for the station... */
305 station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK);
311 #define STA_WAIT_TIMEOUT (HZ/2)
314 * iwl_add_station_common -
316 int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr,
318 struct ieee80211_sta_ht_cap *ht_info,
321 unsigned long flags_spin;
324 struct iwl_addsta_cmd sta_cmd;
327 spin_lock_irqsave(&priv->sta_lock, flags_spin);
328 sta_id = iwl_prep_station(priv, addr, is_ap, ht_info);
329 if (sta_id == IWL_INVALID_STATION) {
330 IWL_ERR(priv, "Unable to prepare station %pM for addition\n",
332 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
337 * uCode is not able to deal with multiple requests to add a
338 * station. Keep track if one is in progress so that we do not send
341 if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
342 IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
344 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
348 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
349 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
350 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
352 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
356 priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS;
357 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
358 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
360 /* Add station to device's station table */
361 ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
363 spin_lock_irqsave(&priv->sta_lock, flags_spin);
364 IWL_ERR(priv, "Adding station %pM failed.\n",
365 priv->stations[sta_id].sta.sta.addr);
366 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
367 priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
368 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
373 EXPORT_SYMBOL(iwl_add_station_common);
375 static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv,
379 struct iwl_link_quality_cmd *link_cmd;
382 link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
384 IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n");
387 /* Set up the rate scaling to start at selected rate, fall back
388 * all the way down to 1M in IEEE order, and then spin on 1M */
389 if (priv->band == IEEE80211_BAND_5GHZ)
390 r = IWL_RATE_6M_INDEX;
392 r = IWL_RATE_1M_INDEX;
394 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
396 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
397 rate_flags |= RATE_MCS_CCK_MSK;
399 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
402 link_cmd->rs_table[i].rate_n_flags =
403 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
404 r = iwl_get_prev_ieee_rate(r);
407 link_cmd->general_params.single_stream_ant_msk =
408 first_antenna(priv->hw_params.valid_tx_ant);
410 link_cmd->general_params.dual_stream_ant_msk =
411 priv->hw_params.valid_tx_ant &
412 ~first_antenna(priv->hw_params.valid_tx_ant);
413 if (!link_cmd->general_params.dual_stream_ant_msk) {
414 link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
415 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
416 link_cmd->general_params.dual_stream_ant_msk =
417 priv->hw_params.valid_tx_ant;
420 link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
421 link_cmd->agg_params.agg_time_limit =
422 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
424 link_cmd->sta_id = sta_id;
430 * iwl_add_bssid_station - Add the special IBSS BSSID station
434 int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs,
439 struct iwl_link_quality_cmd *link_cmd;
443 *sta_id_r = IWL_INVALID_STATION;
445 ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id);
447 IWL_ERR(priv, "Unable to add station %pM\n", addr);
454 spin_lock_irqsave(&priv->sta_lock, flags);
455 priv->stations[sta_id].used |= IWL_STA_LOCAL;
456 spin_unlock_irqrestore(&priv->sta_lock, flags);
459 /* Set up default rate scaling table in device's station table */
460 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
462 IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n",
467 ret = iwl_send_lq_cmd(priv, link_cmd, CMD_SYNC, true);
469 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
471 spin_lock_irqsave(&priv->sta_lock, flags);
472 priv->stations[sta_id].lq = link_cmd;
473 spin_unlock_irqrestore(&priv->sta_lock, flags);
478 EXPORT_SYMBOL(iwl_add_bssid_station);
481 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
483 * priv->sta_lock must be held
485 static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id)
487 /* Ucode must be active and driver must be non active */
488 if ((priv->stations[sta_id].used &
489 (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != IWL_STA_UCODE_ACTIVE)
490 IWL_ERR(priv, "removed non active STA %u\n", sta_id);
492 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
494 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
495 IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id);
498 static int iwl_send_remove_station(struct iwl_priv *priv,
499 const u8 *addr, int sta_id)
501 struct iwl_rx_packet *pkt;
504 unsigned long flags_spin;
505 struct iwl_rem_sta_cmd rm_sta_cmd;
507 struct iwl_host_cmd cmd = {
508 .id = REPLY_REMOVE_STA,
509 .len = sizeof(struct iwl_rem_sta_cmd),
514 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
515 rm_sta_cmd.num_sta = 1;
516 memcpy(&rm_sta_cmd.addr, addr, ETH_ALEN);
518 cmd.flags |= CMD_WANT_SKB;
520 ret = iwl_send_cmd(priv, &cmd);
525 pkt = (struct iwl_rx_packet *)cmd.reply_page;
526 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
527 IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
533 switch (pkt->u.rem_sta.status) {
534 case REM_STA_SUCCESS_MSK:
535 spin_lock_irqsave(&priv->sta_lock, flags_spin);
536 iwl_sta_ucode_deactivate(priv, sta_id);
537 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
538 IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n");
542 IWL_ERR(priv, "REPLY_REMOVE_STA failed\n");
546 iwl_free_pages(priv, cmd.reply_page);
552 * iwl_remove_station - Remove driver's knowledge of station.
554 int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id,
559 if (!iwl_is_ready(priv)) {
561 "Unable to remove station %pM, device not ready.\n",
564 * It is typical for stations to be removed when we are
565 * going down. Return success since device will be down
571 IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n",
574 if (WARN_ON(sta_id == IWL_INVALID_STATION))
577 spin_lock_irqsave(&priv->sta_lock, flags);
579 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
580 IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n",
585 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
586 IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n",
591 if (priv->stations[sta_id].used & IWL_STA_LOCAL) {
592 kfree(priv->stations[sta_id].lq);
593 priv->stations[sta_id].lq = NULL;
596 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
598 priv->num_stations--;
600 BUG_ON(priv->num_stations < 0);
602 spin_unlock_irqrestore(&priv->sta_lock, flags);
604 return iwl_send_remove_station(priv, addr, sta_id);
606 spin_unlock_irqrestore(&priv->sta_lock, flags);
609 EXPORT_SYMBOL_GPL(iwl_remove_station);
612 * iwl_clear_ucode_stations - clear ucode station table bits
614 * This function clears all the bits in the driver indicating
615 * which stations are active in the ucode. Call when something
616 * other than explicit station management would cause this in
617 * the ucode, e.g. unassociated RXON.
619 void iwl_clear_ucode_stations(struct iwl_priv *priv)
622 unsigned long flags_spin;
623 bool cleared = false;
625 IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n");
627 spin_lock_irqsave(&priv->sta_lock, flags_spin);
628 for (i = 0; i < priv->hw_params.max_stations; i++) {
629 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) {
630 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i);
631 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
635 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
638 IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n");
640 EXPORT_SYMBOL(iwl_clear_ucode_stations);
643 * iwl_restore_stations() - Restore driver known stations to device
645 * All stations considered active by driver, but not present in ucode, is
650 void iwl_restore_stations(struct iwl_priv *priv)
652 struct iwl_addsta_cmd sta_cmd;
653 struct iwl_link_quality_cmd lq;
654 unsigned long flags_spin;
660 if (!iwl_is_ready(priv)) {
661 IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n");
665 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n");
666 spin_lock_irqsave(&priv->sta_lock, flags_spin);
667 for (i = 0; i < priv->hw_params.max_stations; i++) {
668 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) &&
669 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) {
670 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n",
671 priv->stations[i].sta.sta.addr);
672 priv->stations[i].sta.mode = 0;
673 priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS;
678 for (i = 0; i < priv->hw_params.max_stations; i++) {
679 if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) {
680 memcpy(&sta_cmd, &priv->stations[i].sta,
681 sizeof(struct iwl_addsta_cmd));
683 if (priv->stations[i].lq) {
684 memcpy(&lq, priv->stations[i].lq,
685 sizeof(struct iwl_link_quality_cmd));
688 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
689 ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
691 spin_lock_irqsave(&priv->sta_lock, flags_spin);
692 IWL_ERR(priv, "Adding station %pM failed.\n",
693 priv->stations[i].sta.sta.addr);
694 priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE;
695 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
696 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
699 * Rate scaling has already been initialized, send
703 iwl_send_lq_cmd(priv, &lq, CMD_SYNC, true);
704 spin_lock_irqsave(&priv->sta_lock, flags_spin);
705 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
709 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
711 IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n");
713 IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n");
715 EXPORT_SYMBOL(iwl_restore_stations);
717 int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
721 for (i = 0; i < STA_KEY_MAX_NUM; i++)
722 if (!test_and_set_bit(i, &priv->ucode_key_table))
725 return WEP_INVALID_OFFSET;
727 EXPORT_SYMBOL(iwl_get_free_ucode_key_index);
729 static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
731 int i, not_empty = 0;
732 u8 buff[sizeof(struct iwl_wep_cmd) +
733 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
734 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
735 size_t cmd_size = sizeof(struct iwl_wep_cmd);
736 struct iwl_host_cmd cmd = {
744 memset(wep_cmd, 0, cmd_size +
745 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
747 for (i = 0; i < WEP_KEYS_MAX ; i++) {
748 wep_cmd->key[i].key_index = i;
749 if (priv->wep_keys[i].key_size) {
750 wep_cmd->key[i].key_offset = i;
753 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
756 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
757 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
758 priv->wep_keys[i].key_size);
761 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
762 wep_cmd->num_keys = WEP_KEYS_MAX;
764 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
768 if (not_empty || send_if_empty)
769 return iwl_send_cmd(priv, &cmd);
774 int iwl_restore_default_wep_keys(struct iwl_priv *priv)
776 WARN_ON(!mutex_is_locked(&priv->mutex));
778 return iwl_send_static_wepkey_cmd(priv, 0);
780 EXPORT_SYMBOL(iwl_restore_default_wep_keys);
782 int iwl_remove_default_wep_key(struct iwl_priv *priv,
783 struct ieee80211_key_conf *keyconf)
787 WARN_ON(!mutex_is_locked(&priv->mutex));
789 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
792 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
793 if (iwl_is_rfkill(priv)) {
794 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
795 /* but keys in device are clear anyway so return success */
798 ret = iwl_send_static_wepkey_cmd(priv, 1);
799 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
800 keyconf->keyidx, ret);
804 EXPORT_SYMBOL(iwl_remove_default_wep_key);
806 int iwl_set_default_wep_key(struct iwl_priv *priv,
807 struct ieee80211_key_conf *keyconf)
811 WARN_ON(!mutex_is_locked(&priv->mutex));
813 if (keyconf->keylen != WEP_KEY_LEN_128 &&
814 keyconf->keylen != WEP_KEY_LEN_64) {
815 IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
819 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
820 keyconf->hw_key_idx = HW_KEY_DEFAULT;
821 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
823 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
824 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
827 ret = iwl_send_static_wepkey_cmd(priv, 0);
828 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
829 keyconf->keylen, keyconf->keyidx, ret);
833 EXPORT_SYMBOL(iwl_set_default_wep_key);
835 static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
836 struct ieee80211_key_conf *keyconf,
840 __le16 key_flags = 0;
841 struct iwl_addsta_cmd sta_cmd;
843 lockdep_assert_held(&priv->mutex);
845 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
847 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
848 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
849 key_flags &= ~STA_KEY_FLG_INVALID;
851 if (keyconf->keylen == WEP_KEY_LEN_128)
852 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
854 if (sta_id == priv->hw_params.bcast_sta_id)
855 key_flags |= STA_KEY_MULTICAST_MSK;
857 spin_lock_irqsave(&priv->sta_lock, flags);
859 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
860 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
861 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
863 memcpy(priv->stations[sta_id].keyinfo.key,
864 keyconf->key, keyconf->keylen);
866 memcpy(&priv->stations[sta_id].sta.key.key[3],
867 keyconf->key, keyconf->keylen);
869 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
870 == STA_KEY_FLG_NO_ENC)
871 priv->stations[sta_id].sta.key.key_offset =
872 iwl_get_free_ucode_key_index(priv);
873 /* else, we are overriding an existing key => no need to allocated room
876 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
877 "no space for a new key");
879 priv->stations[sta_id].sta.key.key_flags = key_flags;
880 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
881 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
883 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
884 spin_unlock_irqrestore(&priv->sta_lock, flags);
886 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
889 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
890 struct ieee80211_key_conf *keyconf,
894 __le16 key_flags = 0;
895 struct iwl_addsta_cmd sta_cmd;
897 lockdep_assert_held(&priv->mutex);
899 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
900 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
901 key_flags &= ~STA_KEY_FLG_INVALID;
903 if (sta_id == priv->hw_params.bcast_sta_id)
904 key_flags |= STA_KEY_MULTICAST_MSK;
906 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
908 spin_lock_irqsave(&priv->sta_lock, flags);
909 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
910 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
912 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
915 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
918 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
919 == STA_KEY_FLG_NO_ENC)
920 priv->stations[sta_id].sta.key.key_offset =
921 iwl_get_free_ucode_key_index(priv);
922 /* else, we are overriding an existing key => no need to allocated room
925 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
926 "no space for a new key");
928 priv->stations[sta_id].sta.key.key_flags = key_flags;
929 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
930 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
932 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
933 spin_unlock_irqrestore(&priv->sta_lock, flags);
935 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
938 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
939 struct ieee80211_key_conf *keyconf,
944 __le16 key_flags = 0;
946 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
947 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
948 key_flags &= ~STA_KEY_FLG_INVALID;
950 if (sta_id == priv->hw_params.bcast_sta_id)
951 key_flags |= STA_KEY_MULTICAST_MSK;
953 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
954 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
956 spin_lock_irqsave(&priv->sta_lock, flags);
958 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
959 priv->stations[sta_id].keyinfo.keylen = 16;
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;
974 /* This copy is acutally not needed: we get the key with each TX */
975 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
977 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
979 spin_unlock_irqrestore(&priv->sta_lock, flags);
984 void iwl_update_tkip_key(struct iwl_priv *priv,
985 struct ieee80211_key_conf *keyconf,
986 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
992 if (iwl_scan_cancel(priv)) {
993 /* cancel scan failed, just live w/ bad key and rely
994 briefly on SW decryption */
998 sta_id = iwl_sta_id_or_broadcast(priv, sta);
999 if (sta_id == IWL_INVALID_STATION)
1002 spin_lock_irqsave(&priv->sta_lock, flags);
1004 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
1006 for (i = 0; i < 5; i++)
1007 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
1008 cpu_to_le16(phase1key[i]);
1010 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1011 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1013 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1015 spin_unlock_irqrestore(&priv->sta_lock, flags);
1018 EXPORT_SYMBOL(iwl_update_tkip_key);
1020 int iwl_remove_dynamic_key(struct iwl_priv *priv,
1021 struct ieee80211_key_conf *keyconf,
1024 unsigned long flags;
1027 struct iwl_addsta_cmd sta_cmd;
1029 lockdep_assert_held(&priv->mutex);
1031 priv->key_mapping_key--;
1033 spin_lock_irqsave(&priv->sta_lock, flags);
1034 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
1035 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
1037 IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
1038 keyconf->keyidx, sta_id);
1040 if (keyconf->keyidx != keyidx) {
1041 /* We need to remove a key with index different that the one
1042 * in the uCode. This means that the key we need to remove has
1043 * been replaced by another one with different index.
1044 * Don't do anything and return ok
1046 spin_unlock_irqrestore(&priv->sta_lock, flags);
1050 if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
1051 IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
1052 keyconf->keyidx, key_flags);
1053 spin_unlock_irqrestore(&priv->sta_lock, flags);
1057 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
1058 &priv->ucode_key_table))
1059 IWL_ERR(priv, "index %d not used in uCode key table.\n",
1060 priv->stations[sta_id].sta.key.key_offset);
1061 memset(&priv->stations[sta_id].keyinfo, 0,
1062 sizeof(struct iwl_hw_key));
1063 memset(&priv->stations[sta_id].sta.key, 0,
1064 sizeof(struct iwl4965_keyinfo));
1065 priv->stations[sta_id].sta.key.key_flags =
1066 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
1067 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
1068 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1069 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1071 if (iwl_is_rfkill(priv)) {
1072 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
1073 spin_unlock_irqrestore(&priv->sta_lock, flags);
1076 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
1077 spin_unlock_irqrestore(&priv->sta_lock, flags);
1079 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
1081 EXPORT_SYMBOL(iwl_remove_dynamic_key);
1083 int iwl_set_dynamic_key(struct iwl_priv *priv,
1084 struct ieee80211_key_conf *keyconf, u8 sta_id)
1088 lockdep_assert_held(&priv->mutex);
1090 priv->key_mapping_key++;
1091 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
1093 switch (keyconf->alg) {
1095 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
1098 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
1101 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
1105 "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
1109 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
1110 keyconf->alg, keyconf->keylen, keyconf->keyidx,
1115 EXPORT_SYMBOL(iwl_set_dynamic_key);
1117 #ifdef CONFIG_IWLWIFI_DEBUG
1118 static void iwl_dump_lq_cmd(struct iwl_priv *priv,
1119 struct iwl_link_quality_cmd *lq)
1122 IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id);
1123 IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n",
1124 lq->general_params.single_stream_ant_msk,
1125 lq->general_params.dual_stream_ant_msk);
1127 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
1128 IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n",
1129 i, lq->rs_table[i].rate_n_flags);
1132 static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
1133 struct iwl_link_quality_cmd *lq)
1139 * is_lq_table_valid() - Test one aspect of LQ cmd for validity
1141 * It sometimes happens when a HT rate has been in use and we
1142 * loose connectivity with AP then mac80211 will first tell us that the
1143 * current channel is not HT anymore before removing the station. In such a
1144 * scenario the RXON flags will be updated to indicate we are not
1145 * communicating HT anymore, but the LQ command may still contain HT rates.
1146 * Test for this to prevent driver from sending LQ command between the time
1147 * RXON flags are updated and when LQ command is updated.
1149 static bool is_lq_table_valid(struct iwl_priv *priv,
1150 struct iwl_link_quality_cmd *lq)
1153 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1158 IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n",
1159 priv->active_rxon.channel);
1160 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
1161 if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) {
1162 IWL_DEBUG_INFO(priv,
1163 "index %d of LQ expects HT channel\n",
1172 * iwl_send_lq_cmd() - Send link quality command
1173 * @init: This command is sent as part of station initialization right
1174 * after station has been added.
1176 * The link quality command is sent as the last step of station creation.
1177 * This is the special case in which init is set and we call a callback in
1178 * this case to clear the state indicating that station creation is in
1181 int iwl_send_lq_cmd(struct iwl_priv *priv,
1182 struct iwl_link_quality_cmd *lq, u8 flags, bool init)
1185 unsigned long flags_spin;
1187 struct iwl_host_cmd cmd = {
1188 .id = REPLY_TX_LINK_QUALITY_CMD,
1189 .len = sizeof(struct iwl_link_quality_cmd),
1194 if (WARN_ON(lq->sta_id == IWL_INVALID_STATION))
1197 iwl_dump_lq_cmd(priv, lq);
1198 BUG_ON(init && (cmd.flags & CMD_ASYNC));
1200 if (is_lq_table_valid(priv, lq))
1201 ret = iwl_send_cmd(priv, &cmd);
1205 if (cmd.flags & CMD_ASYNC)
1209 IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n",
1211 spin_lock_irqsave(&priv->sta_lock, flags_spin);
1212 priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1213 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
1217 EXPORT_SYMBOL(iwl_send_lq_cmd);
1220 * iwl_alloc_bcast_station - add broadcast station into driver's station table.
1222 * This adds the broadcast station into the driver's station table
1223 * and marks it driver active, so that it will be restored to the
1224 * device at the next best time.
1226 int iwl_alloc_bcast_station(struct iwl_priv *priv, bool init_lq)
1228 struct iwl_link_quality_cmd *link_cmd;
1229 unsigned long flags;
1232 spin_lock_irqsave(&priv->sta_lock, flags);
1233 sta_id = iwl_prep_station(priv, iwl_bcast_addr, false, NULL);
1234 if (sta_id == IWL_INVALID_STATION) {
1235 IWL_ERR(priv, "Unable to prepare broadcast station\n");
1236 spin_unlock_irqrestore(&priv->sta_lock, flags);
1241 priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
1242 priv->stations[sta_id].used |= IWL_STA_BCAST;
1243 spin_unlock_irqrestore(&priv->sta_lock, flags);
1246 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
1249 "Unable to initialize rate scaling for bcast station.\n");
1253 spin_lock_irqsave(&priv->sta_lock, flags);
1254 priv->stations[sta_id].lq = link_cmd;
1255 spin_unlock_irqrestore(&priv->sta_lock, flags);
1260 EXPORT_SYMBOL_GPL(iwl_alloc_bcast_station);
1262 void iwl_dealloc_bcast_station(struct iwl_priv *priv)
1264 unsigned long flags;
1267 spin_lock_irqsave(&priv->sta_lock, flags);
1268 for (i = 0; i < priv->hw_params.max_stations; i++) {
1269 if (!(priv->stations[i].used & IWL_STA_BCAST))
1272 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
1273 priv->num_stations--;
1274 BUG_ON(priv->num_stations < 0);
1275 kfree(priv->stations[i].lq);
1276 priv->stations[i].lq = NULL;
1278 spin_unlock_irqrestore(&priv->sta_lock, flags);
1280 EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_station);
1283 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1285 int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
1287 unsigned long flags;
1288 struct iwl_addsta_cmd sta_cmd;
1290 lockdep_assert_held(&priv->mutex);
1292 /* Remove "disable" flag, to enable Tx for this TID */
1293 spin_lock_irqsave(&priv->sta_lock, flags);
1294 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
1295 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
1296 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1297 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
1298 spin_unlock_irqrestore(&priv->sta_lock, flags);
1300 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
1302 EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid);
1304 int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
1307 unsigned long flags;
1309 struct iwl_addsta_cmd sta_cmd;
1311 lockdep_assert_held(&priv->mutex);
1313 sta_id = iwl_sta_id(sta);
1314 if (sta_id == IWL_INVALID_STATION)
1317 spin_lock_irqsave(&priv->sta_lock, flags);
1318 priv->stations[sta_id].sta.station_flags_msk = 0;
1319 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
1320 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
1321 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
1322 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1323 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
1324 spin_unlock_irqrestore(&priv->sta_lock, flags);
1326 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
1328 EXPORT_SYMBOL(iwl_sta_rx_agg_start);
1330 int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
1333 unsigned long flags;
1335 struct iwl_addsta_cmd sta_cmd;
1337 lockdep_assert_held(&priv->mutex);
1339 sta_id = iwl_sta_id(sta);
1340 if (sta_id == IWL_INVALID_STATION) {
1341 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
1345 spin_lock_irqsave(&priv->sta_lock, flags);
1346 priv->stations[sta_id].sta.station_flags_msk = 0;
1347 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
1348 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
1349 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1350 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
1351 spin_unlock_irqrestore(&priv->sta_lock, flags);
1353 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
1355 EXPORT_SYMBOL(iwl_sta_rx_agg_stop);
1357 void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1359 unsigned long flags;
1361 spin_lock_irqsave(&priv->sta_lock, flags);
1362 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
1363 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1364 priv->stations[sta_id].sta.sta.modify_mask = 0;
1365 priv->stations[sta_id].sta.sleep_tx_count = 0;
1366 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1367 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1368 spin_unlock_irqrestore(&priv->sta_lock, flags);
1371 EXPORT_SYMBOL(iwl_sta_modify_ps_wake);
1373 void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
1375 unsigned long flags;
1377 spin_lock_irqsave(&priv->sta_lock, flags);
1378 priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
1379 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1380 priv->stations[sta_id].sta.sta.modify_mask =
1381 STA_MODIFY_SLEEP_TX_COUNT_MSK;
1382 priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
1383 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1384 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1385 spin_unlock_irqrestore(&priv->sta_lock, flags);
1388 EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count);
1390 int iwl_mac_sta_remove(struct ieee80211_hw *hw,
1391 struct ieee80211_vif *vif,
1392 struct ieee80211_sta *sta)
1394 struct iwl_priv *priv = hw->priv;
1395 struct iwl_station_priv_common *sta_common = (void *)sta->drv_priv;
1398 IWL_DEBUG_INFO(priv, "received request to remove station %pM\n",
1400 mutex_lock(&priv->mutex);
1401 IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n",
1403 ret = iwl_remove_station(priv, sta_common->sta_id, sta->addr);
1405 IWL_ERR(priv, "Error removing station %pM\n",
1407 mutex_unlock(&priv->mutex);
1410 EXPORT_SYMBOL(iwl_mac_sta_remove);