blob: b1275e34520d00485da6c75e83e5376ddac4943a [file] [log] [blame]
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07001/******************************************************************************
2 *
Reinette Chatre1f447802010-01-15 13:43:41 -08003 * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved.
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
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.
11 *
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
15 * more details.
16 *
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
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
30#include <net/mac80211.h>
Tomas Winkler947b13a2008-04-16 16:34:48 -070031#include <linux/etherdevice.h>
Reinette Chatrefe6b23d2010-02-22 16:24:47 -080032#include <linux/sched.h>
Johannes Berg4620fef2010-06-16 03:30:27 -070033#include <linux/lockdep.h>
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070034
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070035#include "iwl-dev.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070036#include "iwl-core.h"
37#include "iwl-sta.h"
Tomas Winkler7a999bf2008-05-29 16:35:02 +080038
Reinette Chatre1fa97aa2010-01-22 14:22:48 -080039/* priv->sta_lock must be held */
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +080040static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
41{
Reinette Chatre1fa97aa2010-01-22 14:22:48 -080042
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);
46
47 if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) {
48 IWL_DEBUG_ASSOC(priv,
49 "STA id %u addr %pM already present in uCode (according to driver)\n",
50 sta_id, priv->stations[sta_id].sta.sta.addr);
51 } else {
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);
55 }
56}
57
Johannes Berg09034cb2010-06-14 08:32:38 -070058static int iwl_process_add_sta_resp(struct iwl_priv *priv,
59 struct iwl_addsta_cmd *addsta,
60 struct iwl_rx_packet *pkt,
61 bool sync)
Reinette Chatre1fa97aa2010-01-22 14:22:48 -080062{
63 u8 sta_id = addsta->sta.sta_id;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +080064 unsigned long flags;
Johannes Berg09034cb2010-06-14 08:32:38 -070065 int ret = -EIO;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +080066
Reinette Chatre1fa97aa2010-01-22 14:22:48 -080067 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
68 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
69 pkt->hdr.flags);
Johannes Berg09034cb2010-06-14 08:32:38 -070070 return ret;
Reinette Chatre1fa97aa2010-01-22 14:22:48 -080071 }
72
73 IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n",
74 sta_id);
75
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +080076 spin_lock_irqsave(&priv->sta_lock, flags);
77
Reinette Chatre1fa97aa2010-01-22 14:22:48 -080078 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);
Johannes Berg09034cb2010-06-14 08:32:38 -070082 ret = 0;
Reinette Chatre1fa97aa2010-01-22 14:22:48 -080083 break;
84 case ADD_STA_NO_ROOM_IN_TABLE:
85 IWL_ERR(priv, "Adding station %d failed, no room in table.\n",
Winkler, Tomas15b16872008-12-19 10:37:33 +080086 sta_id);
Reinette Chatre1fa97aa2010-01-22 14:22:48 -080087 break;
88 case ADD_STA_NO_BLOCK_ACK_RESOURCE:
89 IWL_ERR(priv, "Adding station %d failed, no block ack resource.\n",
90 sta_id);
91 break;
92 case ADD_STA_MODIFY_NON_EXIST_STA:
Frans Pop91dd6c22010-03-24 14:19:58 -070093 IWL_ERR(priv, "Attempting to modify non-existing station %d\n",
Reinette Chatre1fa97aa2010-01-22 14:22:48 -080094 sta_id);
95 break;
96 default:
97 IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n",
98 pkt->u.add_sta.status);
99 break;
100 }
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800101
Reinette Chatre1fa97aa2010-01-22 14:22:48 -0800102 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);
106
107 /*
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.
114 */
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",
118 addsta->sta.addr);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800119 spin_unlock_irqrestore(&priv->sta_lock, flags);
Johannes Berg09034cb2010-06-14 08:32:38 -0700120
121 return ret;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800122}
123
Johannes Berg5696aea2009-07-24 11:13:06 -0700124static void iwl_add_sta_callback(struct iwl_priv *priv,
125 struct iwl_device_cmd *cmd,
Zhu Yi2f301222009-10-09 17:19:45 +0800126 struct iwl_rx_packet *pkt)
Tomas Winkler42132bc2008-05-29 16:35:03 +0800127{
Tomas Winkler3257e5d2008-10-14 12:32:43 -0700128 struct iwl_addsta_cmd *addsta =
129 (struct iwl_addsta_cmd *)cmd->cmd.payload;
Tomas Winkler42132bc2008-05-29 16:35:03 +0800130
Reinette Chatre1fa97aa2010-01-22 14:22:48 -0800131 iwl_process_add_sta_resp(priv, addsta, pkt, false);
Tomas Winkler42132bc2008-05-29 16:35:03 +0800132
Tomas Winkler42132bc2008-05-29 16:35:03 +0800133}
134
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800135int iwl_send_add_sta(struct iwl_priv *priv,
Tomas Winkler133636d2008-05-05 10:22:34 +0800136 struct iwl_addsta_cmd *sta, u8 flags)
137{
Zhu Yi2f301222009-10-09 17:19:45 +0800138 struct iwl_rx_packet *pkt = NULL;
Tomas Winkler133636d2008-05-05 10:22:34 +0800139 int ret = 0;
140 u8 data[sizeof(*sta)];
141 struct iwl_host_cmd cmd = {
142 .id = REPLY_ADD_STA,
Johannes Bergc2acea82009-07-24 11:13:05 -0700143 .flags = flags,
Tomas Winkler133636d2008-05-05 10:22:34 +0800144 .data = data,
145 };
Reinette Chatref875f512010-04-05 10:43:10 -0700146 u8 sta_id __maybe_unused = sta->sta.sta_id;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800147
148 IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n",
149 sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : "");
Tomas Winkler133636d2008-05-05 10:22:34 +0800150
Tomas Winkler42132bc2008-05-29 16:35:03 +0800151 if (flags & CMD_ASYNC)
Johannes Bergc2acea82009-07-24 11:13:05 -0700152 cmd.callback = iwl_add_sta_callback;
Johannes Berg4620fef2010-06-16 03:30:27 -0700153 else {
Johannes Bergc2acea82009-07-24 11:13:05 -0700154 cmd.flags |= CMD_WANT_SKB;
Johannes Berg4620fef2010-06-16 03:30:27 -0700155 might_sleep();
156 }
Tomas Winkler133636d2008-05-05 10:22:34 +0800157
158 cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
159 ret = iwl_send_cmd(priv, &cmd);
160
161 if (ret || (flags & CMD_ASYNC))
162 return ret;
163
Tomas Winkler133636d2008-05-05 10:22:34 +0800164 if (ret == 0) {
Reinette Chatre1fa97aa2010-01-22 14:22:48 -0800165 pkt = (struct iwl_rx_packet *)cmd.reply_page;
Johannes Berg09034cb2010-06-14 08:32:38 -0700166 ret = iwl_process_add_sta_resp(priv, sta, pkt, true);
Tomas Winkler133636d2008-05-05 10:22:34 +0800167 }
Zhu Yi64a76b52009-12-10 14:37:21 -0800168 iwl_free_pages(priv, cmd.reply_page);
Tomas Winkler133636d2008-05-05 10:22:34 +0800169
170 return ret;
171}
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800172EXPORT_SYMBOL(iwl_send_add_sta);
Tomas Winkler947b13a2008-04-16 16:34:48 -0700173
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800174static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200175 struct ieee80211_sta_ht_cap *sta_ht_inf)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800176{
177 __le32 sta_flags;
178 u8 mimo_ps_mode;
179
180 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
181 goto done;
182
Tomas Winkler00c5ae22008-09-03 11:26:42 +0800183 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
Wey-Yi Guy3f3e0372009-10-30 14:36:17 -0700184 IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n",
185 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ?
186 "static" :
187 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ?
188 "dynamic" : "disabled");
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800189
190 sta_flags = priv->stations[index].sta.station_flags;
191
192 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
193
194 switch (mimo_ps_mode) {
Tomas Winkler00c5ae22008-09-03 11:26:42 +0800195 case WLAN_HT_CAP_SM_PS_STATIC:
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800196 sta_flags |= STA_FLG_MIMO_DIS_MSK;
197 break;
Tomas Winkler00c5ae22008-09-03 11:26:42 +0800198 case WLAN_HT_CAP_SM_PS_DYNAMIC:
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800199 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
200 break;
Tomas Winkler00c5ae22008-09-03 11:26:42 +0800201 case WLAN_HT_CAP_SM_PS_DISABLED:
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800202 break;
203 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800204 IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800205 break;
206 }
207
208 sta_flags |= cpu_to_le32(
209 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
210
211 sta_flags |= cpu_to_le32(
212 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
213
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700214 if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf))
215 sta_flags |= STA_FLG_HT40_EN_MSK;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800216 else
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700217 sta_flags &= ~STA_FLG_HT40_EN_MSK;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800218
219 priv->stations[index].sta.station_flags = sta_flags;
220 done:
221 return;
222}
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800223
224/**
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800225 * iwl_prep_station - Prepare station information for addition
226 *
227 * should be called with sta_lock held
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800228 */
Johannes Berga194e322010-08-27 08:53:46 -0700229static u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
230 const u8 *addr, bool is_ap,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800231 struct ieee80211_sta_ht_cap *ht_info)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800232{
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800233 struct iwl_station_entry *station;
Tomas Winklerc587de02009-06-03 11:44:07 -0700234 int i;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800235 u8 sta_id = IWL_INVALID_STATION;
Tomas Winklerc587de02009-06-03 11:44:07 -0700236 u16 rate;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800237
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800238 if (is_ap)
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800239 sta_id = IWL_AP_ID;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800240 else if (is_broadcast_ether_addr(addr))
Johannes Berga194e322010-08-27 08:53:46 -0700241 sta_id = ctx->bcast_sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800242 else
243 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
244 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
245 addr)) {
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800246 sta_id = i;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800247 break;
248 }
249
250 if (!priv->stations[i].used &&
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800251 sta_id == IWL_INVALID_STATION)
252 sta_id = i;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800253 }
254
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800255 /*
256 * These two conditions have the same outcome, but keep them
257 * separate
258 */
259 if (unlikely(sta_id == IWL_INVALID_STATION))
260 return sta_id;
261
262 /*
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
265 * another.
266 */
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",
269 sta_id);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800270 return sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800271 }
272
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800273 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
274 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) &&
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800275 !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) {
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800276 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
277 sta_id, addr);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800278 return sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800279 }
280
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800281 station = &priv->stations[sta_id];
282 station->used = IWL_STA_DRIVER_ACTIVE;
Tomas Winklere1623442009-01-27 14:27:56 -0800283 IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -0700284 sta_id, addr);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800285 priv->num_stations++;
286
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;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800291 station->sta.sta.sta_id = sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800292 station->sta.station_flags = 0;
293
Johannes Berg63d41762010-04-30 11:30:50 -0700294 /*
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.
298 */
299 iwl_set_ht_add_station(priv, sta_id, ht_info);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800300
Tomas Winklerc587de02009-06-03 11:44:07 -0700301 /* 3945 only */
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);
306
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800307 return sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800308
309}
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800310
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800311#define STA_WAIT_TIMEOUT (HZ/2)
312
313/**
314 * iwl_add_station_common -
315 */
Johannes Berga194e322010-08-27 08:53:46 -0700316int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
317 const u8 *addr, bool is_ap,
318 struct ieee80211_sta_ht_cap *ht_info, u8 *sta_id_r)
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800319{
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800320 unsigned long flags_spin;
321 int ret = 0;
322 u8 sta_id;
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700323 struct iwl_addsta_cmd sta_cmd;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800324
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800325 *sta_id_r = 0;
326 spin_lock_irqsave(&priv->sta_lock, flags_spin);
Johannes Berga194e322010-08-27 08:53:46 -0700327 sta_id = iwl_prep_station(priv, ctx, addr, is_ap, ht_info);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800328 if (sta_id == IWL_INVALID_STATION) {
329 IWL_ERR(priv, "Unable to prepare station %pM for addition\n",
330 addr);
331 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
332 return -EINVAL;
333 }
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800334
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800335 /*
336 * uCode is not able to deal with multiple requests to add a
337 * station. Keep track if one is in progress so that we do not send
338 * another.
339 */
340 if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
341 IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
342 sta_id);
343 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
344 return -EEXIST;
345 }
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800346
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800347 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
348 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
349 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
350 sta_id, addr);
351 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
352 return -EEXIST;
353 }
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800354
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800355 priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS;
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700356 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800357 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
358
359 /* Add station to device's station table */
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700360 ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800361 if (ret) {
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800362 spin_lock_irqsave(&priv->sta_lock, flags_spin);
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700363 IWL_ERR(priv, "Adding station %pM failed.\n",
364 priv->stations[sta_id].sta.sta.addr);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800365 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
366 priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
367 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
368 }
369 *sta_id_r = sta_id;
370 return ret;
371}
372EXPORT_SYMBOL(iwl_add_station_common);
373
Johannes Berga6a03452010-04-29 10:41:07 -0700374static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv,
375 u8 sta_id)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800376{
377 int i, r;
Reinette Chatred2e210a2010-04-23 10:33:33 -0700378 struct iwl_link_quality_cmd *link_cmd;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800379 u32 rate_flags;
380
Reinette Chatred2e210a2010-04-23 10:33:33 -0700381 link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
382 if (!link_cmd) {
383 IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n");
384 return NULL;
385 }
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800386 /* Set up the rate scaling to start at selected rate, fall back
387 * all the way down to 1M in IEEE order, and then spin on 1M */
Johannes Berg156b70d2010-04-28 14:44:45 -0700388 if (priv->band == IEEE80211_BAND_5GHZ)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800389 r = IWL_RATE_6M_INDEX;
390 else
391 r = IWL_RATE_1M_INDEX;
392
393 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
394 rate_flags = 0;
395 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
396 rate_flags |= RATE_MCS_CCK_MSK;
397
398 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
399 RATE_MCS_ANT_POS;
400
Reinette Chatred2e210a2010-04-23 10:33:33 -0700401 link_cmd->rs_table[i].rate_n_flags =
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800402 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
403 r = iwl_get_prev_ieee_rate(r);
404 }
405
Reinette Chatred2e210a2010-04-23 10:33:33 -0700406 link_cmd->general_params.single_stream_ant_msk =
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800407 first_antenna(priv->hw_params.valid_tx_ant);
Wey-Yi Guy3a23d692010-04-03 16:44:39 -0700408
Reinette Chatred2e210a2010-04-23 10:33:33 -0700409 link_cmd->general_params.dual_stream_ant_msk =
Wey-Yi Guy3a23d692010-04-03 16:44:39 -0700410 priv->hw_params.valid_tx_ant &
411 ~first_antenna(priv->hw_params.valid_tx_ant);
Reinette Chatred2e210a2010-04-23 10:33:33 -0700412 if (!link_cmd->general_params.dual_stream_ant_msk) {
413 link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
Wey-Yi Guy3a23d692010-04-03 16:44:39 -0700414 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
Reinette Chatred2e210a2010-04-23 10:33:33 -0700415 link_cmd->general_params.dual_stream_ant_msk =
Wey-Yi Guy3a23d692010-04-03 16:44:39 -0700416 priv->hw_params.valid_tx_ant;
417 }
418
Reinette Chatred2e210a2010-04-23 10:33:33 -0700419 link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
420 link_cmd->agg_params.agg_time_limit =
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800421 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
422
Johannes Berg156b70d2010-04-28 14:44:45 -0700423 link_cmd->sta_id = sta_id;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800424
Reinette Chatred2e210a2010-04-23 10:33:33 -0700425 return link_cmd;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800426}
427
428/*
Johannes Berg57f8db82010-04-30 11:30:49 -0700429 * iwl_add_bssid_station - Add the special IBSS BSSID station
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800430 *
431 * Function sleeps.
432 */
Johannes Berga194e322010-08-27 08:53:46 -0700433int iwl_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
434 const u8 *addr, bool init_rs, u8 *sta_id_r)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800435{
436 int ret;
437 u8 sta_id;
Reinette Chatred2e210a2010-04-23 10:33:33 -0700438 struct iwl_link_quality_cmd *link_cmd;
439 unsigned long flags;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800440
Dan Carpenter96900c72010-05-14 16:53:46 +0200441 if (sta_id_r)
Johannes Bergfd1af152010-04-30 11:30:43 -0700442 *sta_id_r = IWL_INVALID_STATION;
443
Johannes Berga194e322010-08-27 08:53:46 -0700444 ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800445 if (ret) {
446 IWL_ERR(priv, "Unable to add station %pM\n", addr);
447 return ret;
448 }
449
Johannes Bergfd1af152010-04-30 11:30:43 -0700450 if (sta_id_r)
451 *sta_id_r = sta_id;
452
Reinette Chatred2e210a2010-04-23 10:33:33 -0700453 spin_lock_irqsave(&priv->sta_lock, flags);
454 priv->stations[sta_id].used |= IWL_STA_LOCAL;
455 spin_unlock_irqrestore(&priv->sta_lock, flags);
456
457 if (init_rs) {
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800458 /* Set up default rate scaling table in device's station table */
Johannes Berga6a03452010-04-29 10:41:07 -0700459 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
Reinette Chatred2e210a2010-04-23 10:33:33 -0700460 if (!link_cmd) {
461 IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n",
462 addr);
463 return -ENOMEM;
464 }
Johannes Berga6a03452010-04-29 10:41:07 -0700465
466 ret = iwl_send_lq_cmd(priv, link_cmd, CMD_SYNC, true);
467 if (ret)
468 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
469
Reinette Chatred2e210a2010-04-23 10:33:33 -0700470 spin_lock_irqsave(&priv->sta_lock, flags);
471 priv->stations[sta_id].lq = link_cmd;
472 spin_unlock_irqrestore(&priv->sta_lock, flags);
473 }
474
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800475 return 0;
476}
Johannes Berg57f8db82010-04-30 11:30:49 -0700477EXPORT_SYMBOL(iwl_add_bssid_station);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800478
479/**
480 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
481 *
482 * priv->sta_lock must be held
483 */
484static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id)
485{
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800486 /* Ucode must be active and driver must be non active */
Reinette Chatred2e210a2010-04-23 10:33:33 -0700487 if ((priv->stations[sta_id].used &
488 (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != IWL_STA_UCODE_ACTIVE)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800489 IWL_ERR(priv, "removed non active STA %u\n", sta_id);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800490
491 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
492
493 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800494 IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id);
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800495}
496
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800497static int iwl_send_remove_station(struct iwl_priv *priv,
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700498 const u8 *addr, int sta_id)
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800499{
Zhu Yi2f301222009-10-09 17:19:45 +0800500 struct iwl_rx_packet *pkt;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800501 int ret;
502
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800503 unsigned long flags_spin;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800504 struct iwl_rem_sta_cmd rm_sta_cmd;
505
506 struct iwl_host_cmd cmd = {
507 .id = REPLY_REMOVE_STA,
508 .len = sizeof(struct iwl_rem_sta_cmd),
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800509 .flags = CMD_SYNC,
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800510 .data = &rm_sta_cmd,
511 };
512
513 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
514 rm_sta_cmd.num_sta = 1;
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700515 memcpy(&rm_sta_cmd.addr, addr, ETH_ALEN);
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800516
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800517 cmd.flags |= CMD_WANT_SKB;
518
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800519 ret = iwl_send_cmd(priv, &cmd);
520
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800521 if (ret)
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800522 return ret;
523
Zhu Yi2f301222009-10-09 17:19:45 +0800524 pkt = (struct iwl_rx_packet *)cmd.reply_page;
525 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800526 IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
Zhu Yi2f301222009-10-09 17:19:45 +0800527 pkt->hdr.flags);
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800528 ret = -EIO;
529 }
530
531 if (!ret) {
Zhu Yi2f301222009-10-09 17:19:45 +0800532 switch (pkt->u.rem_sta.status) {
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800533 case REM_STA_SUCCESS_MSK:
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800534 spin_lock_irqsave(&priv->sta_lock, flags_spin);
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700535 iwl_sta_ucode_deactivate(priv, sta_id);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800536 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Tomas Winklere1623442009-01-27 14:27:56 -0800537 IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n");
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800538 break;
539 default:
540 ret = -EIO;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800541 IWL_ERR(priv, "REPLY_REMOVE_STA failed\n");
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800542 break;
543 }
544 }
Zhu Yi64a76b52009-12-10 14:37:21 -0800545 iwl_free_pages(priv, cmd.reply_page);
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800546
547 return ret;
548}
Emmanuel Grumbachbe1f3ab62008-06-12 09:47:18 +0800549
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800550/**
551 * iwl_remove_station - Remove driver's knowledge of station.
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800552 */
Johannes Bergfd1af152010-04-30 11:30:43 -0700553int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id,
554 const u8 *addr)
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800555{
Johannes Bergfd1af152010-04-30 11:30:43 -0700556 unsigned long flags;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800557
558 if (!iwl_is_ready(priv)) {
559 IWL_DEBUG_INFO(priv,
Frans Pop91dd6c22010-03-24 14:19:58 -0700560 "Unable to remove station %pM, device not ready.\n",
Johannes Bergc0222df2010-04-28 08:44:51 -0700561 addr);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800562 /*
563 * It is typical for stations to be removed when we are
564 * going down. Return success since device will be down
565 * soon anyway
566 */
567 return 0;
568 }
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800569
Tomas Winklere1623442009-01-27 14:27:56 -0800570 IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n",
Johannes Bergfd1af152010-04-30 11:30:43 -0700571 sta_id, addr);
572
573 if (WARN_ON(sta_id == IWL_INVALID_STATION))
574 return -EINVAL;
575
576 spin_lock_irqsave(&priv->sta_lock, flags);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800577
578 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800579 IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n",
Johannes Bergc0222df2010-04-28 08:44:51 -0700580 addr);
Johannes Bergfd1af152010-04-30 11:30:43 -0700581 goto out_err;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800582 }
583
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800584 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800585 IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n",
Johannes Bergc0222df2010-04-28 08:44:51 -0700586 addr);
Johannes Bergfd1af152010-04-30 11:30:43 -0700587 goto out_err;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800588 }
589
Johannes Berg1fa61b22010-04-28 08:44:52 -0700590 if (priv->stations[sta_id].used & IWL_STA_LOCAL) {
591 kfree(priv->stations[sta_id].lq);
592 priv->stations[sta_id].lq = NULL;
593 }
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800594
595 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
596
597 priv->num_stations--;
598
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800599 BUG_ON(priv->num_stations < 0);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800600
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800601 spin_unlock_irqrestore(&priv->sta_lock, flags);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800602
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700603 return iwl_send_remove_station(priv, addr, sta_id);
Johannes Bergfd1af152010-04-30 11:30:43 -0700604out_err:
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800605 spin_unlock_irqrestore(&priv->sta_lock, flags);
Johannes Bergfd1af152010-04-30 11:30:43 -0700606 return -EINVAL;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800607}
Johannes Berg1fa61b22010-04-28 08:44:52 -0700608EXPORT_SYMBOL_GPL(iwl_remove_station);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800609
Winkler, Tomas83dde8c2008-11-19 15:32:23 -0800610/**
Johannes Berg2c810cc2010-04-29 00:53:29 -0700611 * iwl_clear_ucode_stations - clear ucode station table bits
612 *
613 * This function clears all the bits in the driver indicating
614 * which stations are active in the ucode. Call when something
615 * other than explicit station management would cause this in
616 * the ucode, e.g. unassociated RXON.
Winkler, Tomas83dde8c2008-11-19 15:32:23 -0800617 */
Johannes Berg2c810cc2010-04-29 00:53:29 -0700618void iwl_clear_ucode_stations(struct iwl_priv *priv)
Winkler, Tomas83dde8c2008-11-19 15:32:23 -0800619{
Mohamed Abbas48676eb2009-03-11 11:17:59 -0700620 int i;
Reinette Chatre7e246192010-02-18 22:58:32 -0800621 unsigned long flags_spin;
622 bool cleared = false;
Winkler, Tomas83dde8c2008-11-19 15:32:23 -0800623
Johannes Berg2c810cc2010-04-29 00:53:29 -0700624 IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n");
Mohamed Abbas48676eb2009-03-11 11:17:59 -0700625
Reinette Chatre7e246192010-02-18 22:58:32 -0800626 spin_lock_irqsave(&priv->sta_lock, flags_spin);
Johannes Berg2c810cc2010-04-29 00:53:29 -0700627 for (i = 0; i < priv->hw_params.max_stations; i++) {
628 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) {
629 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i);
630 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
631 cleared = true;
Reinette Chatre7e246192010-02-18 22:58:32 -0800632 }
633 }
634 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
635
636 if (!cleared)
637 IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n");
Winkler, Tomas83dde8c2008-11-19 15:32:23 -0800638}
Reinette Chatre7e246192010-02-18 22:58:32 -0800639EXPORT_SYMBOL(iwl_clear_ucode_stations);
640
641/**
642 * iwl_restore_stations() - Restore driver known stations to device
643 *
644 * All stations considered active by driver, but not present in ucode, is
645 * restored.
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800646 *
647 * Function sleeps.
Reinette Chatre7e246192010-02-18 22:58:32 -0800648 */
649void iwl_restore_stations(struct iwl_priv *priv)
650{
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700651 struct iwl_addsta_cmd sta_cmd;
652 struct iwl_link_quality_cmd lq;
Reinette Chatre7e246192010-02-18 22:58:32 -0800653 unsigned long flags_spin;
654 int i;
655 bool found = false;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800656 int ret;
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700657 bool send_lq;
Reinette Chatre7e246192010-02-18 22:58:32 -0800658
659 if (!iwl_is_ready(priv)) {
660 IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n");
661 return;
662 }
663
664 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n");
665 spin_lock_irqsave(&priv->sta_lock, flags_spin);
666 for (i = 0; i < priv->hw_params.max_stations; i++) {
667 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) &&
668 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) {
669 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n",
670 priv->stations[i].sta.sta.addr);
671 priv->stations[i].sta.mode = 0;
672 priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS;
673 found = true;
674 }
675 }
676
677 for (i = 0; i < priv->hw_params.max_stations; i++) {
678 if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) {
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700679 memcpy(&sta_cmd, &priv->stations[i].sta,
680 sizeof(struct iwl_addsta_cmd));
681 send_lq = false;
682 if (priv->stations[i].lq) {
683 memcpy(&lq, priv->stations[i].lq,
684 sizeof(struct iwl_link_quality_cmd));
685 send_lq = true;
686 }
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800687 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700688 ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800689 if (ret) {
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800690 spin_lock_irqsave(&priv->sta_lock, flags_spin);
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700691 IWL_ERR(priv, "Adding station %pM failed.\n",
692 priv->stations[i].sta.sta.addr);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800693 priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE;
694 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
695 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
696 }
697 /*
698 * Rate scaling has already been initialized, send
699 * current LQ command
700 */
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700701 if (send_lq)
702 iwl_send_lq_cmd(priv, &lq, CMD_SYNC, true);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800703 spin_lock_irqsave(&priv->sta_lock, flags_spin);
Reinette Chatre7e246192010-02-18 22:58:32 -0800704 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
705 }
706 }
707
708 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
709 if (!found)
710 IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n");
711 else
Reinette Chatrefe6b23d2010-02-22 16:24:47 -0800712 IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n");
Reinette Chatre7e246192010-02-18 22:58:32 -0800713}
714EXPORT_SYMBOL(iwl_restore_stations);
Winkler, Tomas83dde8c2008-11-19 15:32:23 -0800715
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800716int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700717{
718 int i;
719
720 for (i = 0; i < STA_KEY_MAX_NUM; i++)
Emmanuel Grumbach77bab602008-04-15 16:01:44 -0700721 if (!test_and_set_bit(i, &priv->ucode_key_table))
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700722 return i;
723
Tomas Winkler40a9a822008-11-25 23:29:03 +0200724 return WEP_INVALID_OFFSET;
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700725}
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800726EXPORT_SYMBOL(iwl_get_free_ucode_key_index);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700727
Johannes Berg335348b2010-03-30 10:11:46 -0700728static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700729{
730 int i, not_empty = 0;
731 u8 buff[sizeof(struct iwl_wep_cmd) +
732 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
733 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
734 size_t cmd_size = sizeof(struct iwl_wep_cmd);
735 struct iwl_host_cmd cmd = {
736 .id = REPLY_WEPKEY,
737 .data = wep_cmd,
Johannes Berg72e15d72010-02-19 11:42:32 -0800738 .flags = CMD_SYNC,
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700739 };
740
Johannes Berg72e15d72010-02-19 11:42:32 -0800741 might_sleep();
742
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700743 memset(wep_cmd, 0, cmd_size +
744 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
745
746 for (i = 0; i < WEP_KEYS_MAX ; i++) {
747 wep_cmd->key[i].key_index = i;
748 if (priv->wep_keys[i].key_size) {
749 wep_cmd->key[i].key_offset = i;
750 not_empty = 1;
751 } else {
752 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
753 }
754
755 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
756 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
757 priv->wep_keys[i].key_size);
758 }
759
760 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
761 wep_cmd->num_keys = WEP_KEYS_MAX;
762
763 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
764
765 cmd.len = cmd_size;
766
767 if (not_empty || send_if_empty)
768 return iwl_send_cmd(priv, &cmd);
769 else
770 return 0;
771}
Johannes Berg335348b2010-03-30 10:11:46 -0700772
773int iwl_restore_default_wep_keys(struct iwl_priv *priv)
774{
Johannes Berga24d52f2010-08-06 16:17:53 +0200775 lockdep_assert_held(&priv->mutex);
Johannes Berg335348b2010-03-30 10:11:46 -0700776
777 return iwl_send_static_wepkey_cmd(priv, 0);
778}
779EXPORT_SYMBOL(iwl_restore_default_wep_keys);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700780
781int iwl_remove_default_wep_key(struct iwl_priv *priv,
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700782 struct ieee80211_key_conf *keyconf)
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700783{
784 int ret;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700785
Johannes Berga24d52f2010-08-06 16:17:53 +0200786 lockdep_assert_held(&priv->mutex);
Johannes Berg72e15d72010-02-19 11:42:32 -0800787
Reinette Chatre2d1bb9e2009-07-17 09:30:18 -0700788 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
789 keyconf->keyidx);
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700790
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700791 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
Reinette Chatre2d1bb9e2009-07-17 09:30:18 -0700792 if (iwl_is_rfkill(priv)) {
793 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
Johannes Berg72e15d72010-02-19 11:42:32 -0800794 /* but keys in device are clear anyway so return success */
Reinette Chatre2d1bb9e2009-07-17 09:30:18 -0700795 return 0;
796 }
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700797 ret = iwl_send_static_wepkey_cmd(priv, 1);
Tomas Winklere1623442009-01-27 14:27:56 -0800798 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +0800799 keyconf->keyidx, ret);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700800
801 return ret;
802}
Tomas Winkler27aaba02008-05-05 10:22:44 +0800803EXPORT_SYMBOL(iwl_remove_default_wep_key);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700804
805int iwl_set_default_wep_key(struct iwl_priv *priv,
806 struct ieee80211_key_conf *keyconf)
807{
808 int ret;
Johannes Berg72e15d72010-02-19 11:42:32 -0800809
Johannes Berga24d52f2010-08-06 16:17:53 +0200810 lockdep_assert_held(&priv->mutex);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700811
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +0800812 if (keyconf->keylen != WEP_KEY_LEN_128 &&
813 keyconf->keylen != WEP_KEY_LEN_64) {
Tomas Winklere1623442009-01-27 14:27:56 -0800814 IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +0800815 return -EINVAL;
816 }
817
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700818 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800819 keyconf->hw_key_idx = HW_KEY_DEFAULT;
Johannes Berg97359d12010-08-10 09:46:38 +0200820 priv->stations[IWL_AP_ID].keyinfo.cipher = keyconf->cipher;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700821
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700822 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
823 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
824 keyconf->keylen);
825
826 ret = iwl_send_static_wepkey_cmd(priv, 0);
Tomas Winklere1623442009-01-27 14:27:56 -0800827 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +0800828 keyconf->keylen, keyconf->keyidx, ret);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700829
830 return ret;
831}
Tomas Winkler27aaba02008-05-05 10:22:44 +0800832EXPORT_SYMBOL(iwl_set_default_wep_key);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700833
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700834static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
Johannes Berga194e322010-08-27 08:53:46 -0700835 struct iwl_rxon_context *ctx,
836 struct ieee80211_key_conf *keyconf,
837 u8 sta_id)
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700838{
839 unsigned long flags;
840 __le16 key_flags = 0;
Johannes Berge6666742010-06-14 08:32:24 -0700841 struct iwl_addsta_cmd sta_cmd;
842
843 lockdep_assert_held(&priv->mutex);
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700844
845 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700846
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;
850
851 if (keyconf->keylen == WEP_KEY_LEN_128)
852 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
853
Johannes Berga194e322010-08-27 08:53:46 -0700854 if (sta_id == ctx->bcast_sta_id)
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700855 key_flags |= STA_KEY_MULTICAST_MSK;
856
857 spin_lock_irqsave(&priv->sta_lock, flags);
858
Johannes Berg97359d12010-08-10 09:46:38 +0200859 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700860 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
861 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
862
863 memcpy(priv->stations[sta_id].keyinfo.key,
864 keyconf->key, keyconf->keylen);
865
866 memcpy(&priv->stations[sta_id].sta.key.key[3],
867 keyconf->key, keyconf->keylen);
868
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700869 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 =
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700872 iwl_get_free_ucode_key_index(priv);
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700873 /* else, we are overriding an existing key => no need to allocated room
874 * in uCode. */
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700875
Tomas Winkler40a9a822008-11-25 23:29:03 +0200876 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
Jiri Slabye724b8f2009-01-05 17:06:06 +0100877 "no space for a new key");
Tomas Winkler40a9a822008-11-25 23:29:03 +0200878
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700879 priv->stations[sta_id].sta.key.key_flags = key_flags;
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700880 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
881 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
882
Johannes Berge6666742010-06-14 08:32:24 -0700883 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700884 spin_unlock_irqrestore(&priv->sta_lock, flags);
885
Johannes Berge6666742010-06-14 08:32:24 -0700886 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700887}
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700888
889static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
Johannes Berga194e322010-08-27 08:53:46 -0700890 struct iwl_rxon_context *ctx,
891 struct ieee80211_key_conf *keyconf,
892 u8 sta_id)
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700893{
894 unsigned long flags;
895 __le16 key_flags = 0;
Johannes Berge6666742010-06-14 08:32:24 -0700896 struct iwl_addsta_cmd sta_cmd;
897
898 lockdep_assert_held(&priv->mutex);
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700899
900 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
901 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
902 key_flags &= ~STA_KEY_FLG_INVALID;
903
Johannes Berga194e322010-08-27 08:53:46 -0700904 if (sta_id == ctx->bcast_sta_id)
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700905 key_flags |= STA_KEY_MULTICAST_MSK;
906
907 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700908
909 spin_lock_irqsave(&priv->sta_lock, flags);
Johannes Berg97359d12010-08-10 09:46:38 +0200910 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700911 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
912
913 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
914 keyconf->keylen);
915
916 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
917 keyconf->keylen);
918
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700919 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
920 == STA_KEY_FLG_NO_ENC)
921 priv->stations[sta_id].sta.key.key_offset =
922 iwl_get_free_ucode_key_index(priv);
923 /* else, we are overriding an existing key => no need to allocated room
924 * in uCode. */
925
Tomas Winkler40a9a822008-11-25 23:29:03 +0200926 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
Jiri Slabye724b8f2009-01-05 17:06:06 +0100927 "no space for a new key");
Tomas Winkler40a9a822008-11-25 23:29:03 +0200928
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700929 priv->stations[sta_id].sta.key.key_flags = key_flags;
930 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
931 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
932
Johannes Berge6666742010-06-14 08:32:24 -0700933 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700934 spin_unlock_irqrestore(&priv->sta_lock, flags);
935
Johannes Berge6666742010-06-14 08:32:24 -0700936 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700937}
938
939static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
Johannes Berga194e322010-08-27 08:53:46 -0700940 struct iwl_rxon_context *ctx,
941 struct ieee80211_key_conf *keyconf,
942 u8 sta_id)
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700943{
944 unsigned long flags;
945 int ret = 0;
Reinette Chatre299f5462009-04-30 13:56:31 -0700946 __le16 key_flags = 0;
947
948 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
949 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
950 key_flags &= ~STA_KEY_FLG_INVALID;
951
Johannes Berga194e322010-08-27 08:53:46 -0700952 if (sta_id == ctx->bcast_sta_id)
Reinette Chatre299f5462009-04-30 13:56:31 -0700953 key_flags |= STA_KEY_MULTICAST_MSK;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700954
955 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
956 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700957
958 spin_lock_irqsave(&priv->sta_lock, flags);
959
Johannes Berg97359d12010-08-10 09:46:38 +0200960 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700961 priv->stations[sta_id].keyinfo.keylen = 16;
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700962
963 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
964 == STA_KEY_FLG_NO_ENC)
965 priv->stations[sta_id].sta.key.key_offset =
Emmanuel Grumbach77bab602008-04-15 16:01:44 -0700966 iwl_get_free_ucode_key_index(priv);
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700967 /* else, we are overriding an existing key => no need to allocated room
968 * in uCode. */
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700969
Tomas Winkler40a9a822008-11-25 23:29:03 +0200970 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
Jiri Slabye724b8f2009-01-05 17:06:06 +0100971 "no space for a new key");
Tomas Winkler40a9a822008-11-25 23:29:03 +0200972
Reinette Chatre299f5462009-04-30 13:56:31 -0700973 priv->stations[sta_id].sta.key.key_flags = key_flags;
974
975
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700976 /* This copy is acutally not needed: we get the key with each TX */
977 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
978
979 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
980
981 spin_unlock_irqrestore(&priv->sta_lock, flags);
982
983 return ret;
984}
985
Tomas Winkler9f586712008-11-12 13:14:05 -0800986void iwl_update_tkip_key(struct iwl_priv *priv,
Johannes Berga194e322010-08-27 08:53:46 -0700987 struct iwl_rxon_context *ctx,
988 struct ieee80211_key_conf *keyconf,
989 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
Tomas Winkler9f586712008-11-12 13:14:05 -0800990{
Johannes Bergbdbb6122010-04-30 13:53:37 -0700991 u8 sta_id;
Tomas Winkler9f586712008-11-12 13:14:05 -0800992 unsigned long flags;
Tomas Winkler9f586712008-11-12 13:14:05 -0800993 int i;
Tomas Winkler9f586712008-11-12 13:14:05 -0800994
Tomas Winkler9f586712008-11-12 13:14:05 -0800995 if (iwl_scan_cancel(priv)) {
996 /* cancel scan failed, just live w/ bad key and rely
997 briefly on SW decryption */
998 return;
999 }
1000
Johannes Berga194e322010-08-27 08:53:46 -07001001 sta_id = iwl_sta_id_or_broadcast(priv, ctx, sta);
Johannes Berg0af8bca2010-04-30 14:08:00 -07001002 if (sta_id == IWL_INVALID_STATION)
1003 return;
1004
Tomas Winkler9f586712008-11-12 13:14:05 -08001005 spin_lock_irqsave(&priv->sta_lock, flags);
1006
Tomas Winkler9f586712008-11-12 13:14:05 -08001007 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
1008
1009 for (i = 0; i < 5; i++)
1010 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
1011 cpu_to_le16(phase1key[i]);
1012
1013 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1014 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1015
1016 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1017
1018 spin_unlock_irqrestore(&priv->sta_lock, flags);
1019
1020}
1021EXPORT_SYMBOL(iwl_update_tkip_key);
1022
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07001023int iwl_remove_dynamic_key(struct iwl_priv *priv,
1024 struct ieee80211_key_conf *keyconf,
1025 u8 sta_id)
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001026{
1027 unsigned long flags;
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07001028 u16 key_flags;
1029 u8 keyidx;
Johannes Berge6666742010-06-14 08:32:24 -07001030 struct iwl_addsta_cmd sta_cmd;
1031
1032 lockdep_assert_held(&priv->mutex);
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001033
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08001034 priv->key_mapping_key--;
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001035
1036 spin_lock_irqsave(&priv->sta_lock, flags);
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07001037 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
1038 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
1039
Tomas Winklere1623442009-01-27 14:27:56 -08001040 IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +08001041 keyconf->keyidx, sta_id);
1042
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07001043 if (keyconf->keyidx != keyidx) {
1044 /* We need to remove a key with index different that the one
1045 * in the uCode. This means that the key we need to remove has
1046 * been replaced by another one with different index.
1047 * Don't do anything and return ok
1048 */
1049 spin_unlock_irqrestore(&priv->sta_lock, flags);
1050 return 0;
1051 }
1052
Tomas Winkler40a9a822008-11-25 23:29:03 +02001053 if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001054 IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
Tomas Winkler40a9a822008-11-25 23:29:03 +02001055 keyconf->keyidx, key_flags);
1056 spin_unlock_irqrestore(&priv->sta_lock, flags);
1057 return 0;
1058 }
1059
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001060 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
1061 &priv->ucode_key_table))
Winkler, Tomas15b16872008-12-19 10:37:33 +08001062 IWL_ERR(priv, "index %d not used in uCode key table.\n",
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001063 priv->stations[sta_id].sta.key.key_offset);
1064 memset(&priv->stations[sta_id].keyinfo, 0,
Tomas Winkler6def9762008-05-05 10:22:31 +08001065 sizeof(struct iwl_hw_key));
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001066 memset(&priv->stations[sta_id].sta.key, 0,
1067 sizeof(struct iwl4965_keyinfo));
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07001068 priv->stations[sta_id].sta.key.key_flags =
1069 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
1070 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001071 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1072 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001073
Reinette Chatre2d1bb9e2009-07-17 09:30:18 -07001074 if (iwl_is_rfkill(priv)) {
Frans Pop91dd6c22010-03-24 14:19:58 -07001075 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
Reinette Chatre2d1bb9e2009-07-17 09:30:18 -07001076 spin_unlock_irqrestore(&priv->sta_lock, flags);
1077 return 0;
1078 }
Johannes Berge6666742010-06-14 08:32:24 -07001079 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07001080 spin_unlock_irqrestore(&priv->sta_lock, flags);
Johannes Berge6666742010-06-14 08:32:24 -07001081
1082 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001083}
Tomas Winkler27aaba02008-05-05 10:22:44 +08001084EXPORT_SYMBOL(iwl_remove_dynamic_key);
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001085
Johannes Berga194e322010-08-27 08:53:46 -07001086int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1087 struct ieee80211_key_conf *keyconf, u8 sta_id)
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001088{
1089 int ret;
1090
Johannes Berge6666742010-06-14 08:32:24 -07001091 lockdep_assert_held(&priv->mutex);
1092
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08001093 priv->key_mapping_key++;
1094 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001095
Johannes Berg97359d12010-08-10 09:46:38 +02001096 switch (keyconf->cipher) {
1097 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berga194e322010-08-27 08:53:46 -07001098 ret = iwl_set_ccmp_dynamic_key_info(priv, ctx, keyconf, sta_id);
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001099 break;
Johannes Berg97359d12010-08-10 09:46:38 +02001100 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berga194e322010-08-27 08:53:46 -07001101 ret = iwl_set_tkip_dynamic_key_info(priv, ctx, keyconf, sta_id);
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001102 break;
Johannes Berg97359d12010-08-10 09:46:38 +02001103 case WLAN_CIPHER_SUITE_WEP40:
1104 case WLAN_CIPHER_SUITE_WEP104:
Johannes Berga194e322010-08-27 08:53:46 -07001105 ret = iwl_set_wep_dynamic_key_info(priv, ctx, keyconf, sta_id);
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001106 break;
1107 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001108 IWL_ERR(priv,
Johannes Berg97359d12010-08-10 09:46:38 +02001109 "Unknown alg: %s cipher = %x\n", __func__,
1110 keyconf->cipher);
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001111 ret = -EINVAL;
1112 }
1113
Johannes Berg97359d12010-08-10 09:46:38 +02001114 IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
1115 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +08001116 sta_id, ret);
1117
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001118 return ret;
1119}
Tomas Winkler27aaba02008-05-05 10:22:44 +08001120EXPORT_SYMBOL(iwl_set_dynamic_key);
Emmanuel Grumbach74805132008-04-14 21:16:09 -07001121
Tomas Winkler66c73db2008-04-15 16:01:40 -07001122#ifdef CONFIG_IWLWIFI_DEBUG
1123static void iwl_dump_lq_cmd(struct iwl_priv *priv,
1124 struct iwl_link_quality_cmd *lq)
1125{
1126 int i;
Tomas Winklere1623442009-01-27 14:27:56 -08001127 IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id);
1128 IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n",
Tomas Winkler66c73db2008-04-15 16:01:40 -07001129 lq->general_params.single_stream_ant_msk,
1130 lq->general_params.dual_stream_ant_msk);
1131
1132 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
Tomas Winklere1623442009-01-27 14:27:56 -08001133 IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n",
Tomas Winkler66c73db2008-04-15 16:01:40 -07001134 i, lq->rs_table[i].rate_n_flags);
1135}
1136#else
1137static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
1138 struct iwl_link_quality_cmd *lq)
1139{
1140}
1141#endif
1142
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001143/**
Reinette Chatre3bce6062010-04-13 16:11:19 -07001144 * is_lq_table_valid() - Test one aspect of LQ cmd for validity
1145 *
1146 * It sometimes happens when a HT rate has been in use and we
1147 * loose connectivity with AP then mac80211 will first tell us that the
1148 * current channel is not HT anymore before removing the station. In such a
1149 * scenario the RXON flags will be updated to indicate we are not
1150 * communicating HT anymore, but the LQ command may still contain HT rates.
1151 * Test for this to prevent driver from sending LQ command between the time
1152 * RXON flags are updated and when LQ command is updated.
1153 */
1154static bool is_lq_table_valid(struct iwl_priv *priv,
1155 struct iwl_link_quality_cmd *lq)
1156{
1157 int i;
1158 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg246ed352010-08-23 10:46:32 +02001159#if !TODO
1160 struct iwl_rxon_context *ctx =
1161 &priv->contexts[IWL_RXON_CTX_BSS];
1162#endif
Reinette Chatre3bce6062010-04-13 16:11:19 -07001163
1164 if (ht_conf->is_ht)
1165 return true;
1166
1167 IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n",
Johannes Berg246ed352010-08-23 10:46:32 +02001168 ctx->active.channel);
Reinette Chatre3bce6062010-04-13 16:11:19 -07001169 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
1170 if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) {
1171 IWL_DEBUG_INFO(priv,
1172 "index %d of LQ expects HT channel\n",
1173 i);
1174 return false;
1175 }
1176 }
1177 return true;
1178}
1179
1180/**
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001181 * 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.
1184 *
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
1188 * progress.
1189 */
Tomas Winkler66c73db2008-04-15 16:01:40 -07001190int iwl_send_lq_cmd(struct iwl_priv *priv,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001191 struct iwl_link_quality_cmd *lq, u8 flags, bool init)
Tomas Winkler66c73db2008-04-15 16:01:40 -07001192{
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001193 int ret = 0;
1194 unsigned long flags_spin;
1195
Tomas Winkler66c73db2008-04-15 16:01:40 -07001196 struct iwl_host_cmd cmd = {
1197 .id = REPLY_TX_LINK_QUALITY_CMD,
1198 .len = sizeof(struct iwl_link_quality_cmd),
Johannes Bergc2acea82009-07-24 11:13:05 -07001199 .flags = flags,
Tomas Winkler66c73db2008-04-15 16:01:40 -07001200 .data = lq,
1201 };
1202
Johannes Berg76c3c692010-03-30 02:46:29 -07001203 if (WARN_ON(lq->sta_id == IWL_INVALID_STATION))
Tomas Winkler66c73db2008-04-15 16:01:40 -07001204 return -EINVAL;
1205
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001206 iwl_dump_lq_cmd(priv, lq);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001207 BUG_ON(init && (cmd.flags & CMD_ASYNC));
Tomas Winkler66c73db2008-04-15 16:01:40 -07001208
Reinette Chatre3bce6062010-04-13 16:11:19 -07001209 if (is_lq_table_valid(priv, lq))
1210 ret = iwl_send_cmd(priv, &cmd);
1211 else
1212 ret = -EINVAL;
Reinette Chatred2e210a2010-04-23 10:33:33 -07001213
1214 if (cmd.flags & CMD_ASYNC)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001215 return ret;
Tomas Winkler66c73db2008-04-15 16:01:40 -07001216
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001217 if (init) {
Frans Pop91dd6c22010-03-24 14:19:58 -07001218 IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n",
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001219 lq->sta_id);
1220 spin_lock_irqsave(&priv->sta_lock, flags_spin);
1221 priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1222 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
1223 }
Reinette Chatred2e210a2010-04-23 10:33:33 -07001224 return ret;
Tomas Winkler66c73db2008-04-15 16:01:40 -07001225}
1226EXPORT_SYMBOL(iwl_send_lq_cmd);
1227
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001228/**
Johannes Berg2c810cc2010-04-29 00:53:29 -07001229 * iwl_alloc_bcast_station - add broadcast station into driver's station table.
1230 *
1231 * This adds the broadcast station into the driver's station table
1232 * and marks it driver active, so that it will be restored to the
1233 * device at the next best time.
Reinette Chatre9a9ca652009-10-30 14:36:12 -07001234 */
Johannes Berga194e322010-08-27 08:53:46 -07001235int iwl_alloc_bcast_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1236 bool init_lq)
Reinette Chatre9a9ca652009-10-30 14:36:12 -07001237{
Johannes Berg2c810cc2010-04-29 00:53:29 -07001238 struct iwl_link_quality_cmd *link_cmd;
1239 unsigned long flags;
1240 u8 sta_id;
Reinette Chatre9a9ca652009-10-30 14:36:12 -07001241
Johannes Berg2c810cc2010-04-29 00:53:29 -07001242 spin_lock_irqsave(&priv->sta_lock, flags);
Johannes Berga194e322010-08-27 08:53:46 -07001243 sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL);
Johannes Berg2c810cc2010-04-29 00:53:29 -07001244 if (sta_id == IWL_INVALID_STATION) {
1245 IWL_ERR(priv, "Unable to prepare broadcast station\n");
1246 spin_unlock_irqrestore(&priv->sta_lock, flags);
1247
1248 return -EINVAL;
1249 }
1250
1251 priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
1252 priv->stations[sta_id].used |= IWL_STA_BCAST;
1253 spin_unlock_irqrestore(&priv->sta_lock, flags);
1254
1255 if (init_lq) {
1256 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
1257 if (!link_cmd) {
1258 IWL_ERR(priv,
1259 "Unable to initialize rate scaling for bcast station.\n");
1260 return -ENOMEM;
1261 }
1262
1263 spin_lock_irqsave(&priv->sta_lock, flags);
1264 priv->stations[sta_id].lq = link_cmd;
1265 spin_unlock_irqrestore(&priv->sta_lock, flags);
1266 }
1267
1268 return 0;
1269}
1270EXPORT_SYMBOL_GPL(iwl_alloc_bcast_station);
1271
Daniel Halperin278c2f62010-06-14 13:10:29 -07001272/**
1273 * iwl_update_bcast_station - update broadcast station's LQ command
1274 *
1275 * Only used by iwlagn. Placed here to have all bcast station management
1276 * code together.
1277 */
Johannes Berga194e322010-08-27 08:53:46 -07001278static int iwl_update_bcast_station(struct iwl_priv *priv,
1279 struct iwl_rxon_context *ctx)
Daniel Halperin278c2f62010-06-14 13:10:29 -07001280{
1281 unsigned long flags;
1282 struct iwl_link_quality_cmd *link_cmd;
Johannes Berga194e322010-08-27 08:53:46 -07001283 u8 sta_id = ctx->bcast_sta_id;
Daniel Halperin278c2f62010-06-14 13:10:29 -07001284
1285 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
1286 if (!link_cmd) {
1287 IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n");
1288 return -ENOMEM;
1289 }
1290
1291 spin_lock_irqsave(&priv->sta_lock, flags);
1292 if (priv->stations[sta_id].lq)
1293 kfree(priv->stations[sta_id].lq);
1294 else
1295 IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n");
1296 priv->stations[sta_id].lq = link_cmd;
1297 spin_unlock_irqrestore(&priv->sta_lock, flags);
1298
1299 return 0;
1300}
Daniel Halperin278c2f62010-06-14 13:10:29 -07001301
Johannes Berga194e322010-08-27 08:53:46 -07001302int iwl_update_bcast_stations(struct iwl_priv *priv)
1303{
1304 struct iwl_rxon_context *ctx;
1305 int ret = 0;
1306
1307 for_each_context(priv, ctx) {
1308 ret = iwl_update_bcast_station(priv, ctx);
1309 if (ret)
1310 break;
1311 }
1312
1313 return ret;
1314}
1315EXPORT_SYMBOL_GPL(iwl_update_bcast_stations);
1316
1317void iwl_dealloc_bcast_stations(struct iwl_priv *priv)
Reinette Chatre3459ab52010-01-22 14:22:49 -08001318{
Johannes Berg2c810cc2010-04-29 00:53:29 -07001319 unsigned long flags;
1320 int i;
Reinette Chatred2e210a2010-04-23 10:33:33 -07001321
Johannes Berg2c810cc2010-04-29 00:53:29 -07001322 spin_lock_irqsave(&priv->sta_lock, flags);
1323 for (i = 0; i < priv->hw_params.max_stations; i++) {
1324 if (!(priv->stations[i].used & IWL_STA_BCAST))
1325 continue;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001326
Johannes Berg2c810cc2010-04-29 00:53:29 -07001327 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
1328 priv->num_stations--;
1329 BUG_ON(priv->num_stations < 0);
1330 kfree(priv->stations[i].lq);
1331 priv->stations[i].lq = NULL;
1332 }
1333 spin_unlock_irqrestore(&priv->sta_lock, flags);
Reinette Chatre3459ab52010-01-22 14:22:49 -08001334}
Johannes Berga194e322010-08-27 08:53:46 -07001335EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_stations);
Reinette Chatre3459ab52010-01-22 14:22:49 -08001336
1337/**
Tomas Winkler9f586712008-11-12 13:14:05 -08001338 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
Tomas Winkler5083e562008-05-29 16:35:15 +08001339 */
Johannes Berg4620fef2010-06-16 03:30:27 -07001340int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
Tomas Winkler5083e562008-05-29 16:35:15 +08001341{
1342 unsigned long flags;
Johannes Berg4620fef2010-06-16 03:30:27 -07001343 struct iwl_addsta_cmd sta_cmd;
1344
1345 lockdep_assert_held(&priv->mutex);
Tomas Winkler5083e562008-05-29 16:35:15 +08001346
1347 /* Remove "disable" flag, to enable Tx for this TID */
1348 spin_lock_irqsave(&priv->sta_lock, flags);
1349 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
1350 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
1351 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Johannes Berg4620fef2010-06-16 03:30:27 -07001352 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
Reinette Chatre9c5ac092010-05-05 02:26:06 -07001353 spin_unlock_irqrestore(&priv->sta_lock, flags);
Johannes Berg4620fef2010-06-16 03:30:27 -07001354
1355 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
Tomas Winkler5083e562008-05-29 16:35:15 +08001356}
Tomas Winkler9f586712008-11-12 13:14:05 -08001357EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid);
1358
Johannes Berg619753f2010-04-30 11:30:46 -07001359int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
1360 int tid, u16 ssn)
Tomas Winkler9f586712008-11-12 13:14:05 -08001361{
1362 unsigned long flags;
1363 int sta_id;
Johannes Berg4620fef2010-06-16 03:30:27 -07001364 struct iwl_addsta_cmd sta_cmd;
1365
1366 lockdep_assert_held(&priv->mutex);
Tomas Winkler9f586712008-11-12 13:14:05 -08001367
Johannes Berg619753f2010-04-30 11:30:46 -07001368 sta_id = iwl_sta_id(sta);
Tomas Winkler9f586712008-11-12 13:14:05 -08001369 if (sta_id == IWL_INVALID_STATION)
1370 return -ENXIO;
1371
1372 spin_lock_irqsave(&priv->sta_lock, flags);
1373 priv->stations[sta_id].sta.station_flags_msk = 0;
1374 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
1375 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
1376 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
1377 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Johannes Berg4620fef2010-06-16 03:30:27 -07001378 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
Tomas Winkler9f586712008-11-12 13:14:05 -08001379 spin_unlock_irqrestore(&priv->sta_lock, flags);
1380
Johannes Berg4620fef2010-06-16 03:30:27 -07001381 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
Tomas Winkler9f586712008-11-12 13:14:05 -08001382}
1383EXPORT_SYMBOL(iwl_sta_rx_agg_start);
1384
Johannes Berg619753f2010-04-30 11:30:46 -07001385int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
1386 int tid)
Tomas Winkler9f586712008-11-12 13:14:05 -08001387{
1388 unsigned long flags;
Johannes Berg4620fef2010-06-16 03:30:27 -07001389 int sta_id;
1390 struct iwl_addsta_cmd sta_cmd;
1391
1392 lockdep_assert_held(&priv->mutex);
Tomas Winkler9f586712008-11-12 13:14:05 -08001393
Johannes Berg619753f2010-04-30 11:30:46 -07001394 sta_id = iwl_sta_id(sta);
Wey-Yi Guya2f1cbe2009-03-17 21:51:52 -07001395 if (sta_id == IWL_INVALID_STATION) {
1396 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
Tomas Winkler9f586712008-11-12 13:14:05 -08001397 return -ENXIO;
Wey-Yi Guya2f1cbe2009-03-17 21:51:52 -07001398 }
Tomas Winkler9f586712008-11-12 13:14:05 -08001399
1400 spin_lock_irqsave(&priv->sta_lock, flags);
1401 priv->stations[sta_id].sta.station_flags_msk = 0;
1402 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
1403 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
1404 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Johannes Berg4620fef2010-06-16 03:30:27 -07001405 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
Tomas Winkler9f586712008-11-12 13:14:05 -08001406 spin_unlock_irqrestore(&priv->sta_lock, flags);
1407
Johannes Berg4620fef2010-06-16 03:30:27 -07001408 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
Tomas Winkler9f586712008-11-12 13:14:05 -08001409}
1410EXPORT_SYMBOL(iwl_sta_rx_agg_stop);
1411
Johannes Berg6ab10ff2009-11-13 11:56:37 -08001412void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
Tomas Winkler9f586712008-11-12 13:14:05 -08001413{
1414 unsigned long flags;
1415
1416 spin_lock_irqsave(&priv->sta_lock, flags);
1417 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
1418 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1419 priv->stations[sta_id].sta.sta.modify_mask = 0;
Johannes Berg6ab10ff2009-11-13 11:56:37 -08001420 priv->stations[sta_id].sta.sleep_tx_count = 0;
Tomas Winkler9f586712008-11-12 13:14:05 -08001421 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Reinette Chatre9c5ac092010-05-05 02:26:06 -07001422 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Tomas Winkler9f586712008-11-12 13:14:05 -08001423 spin_unlock_irqrestore(&priv->sta_lock, flags);
1424
Tomas Winkler9f586712008-11-12 13:14:05 -08001425}
Johannes Berg6ab10ff2009-11-13 11:56:37 -08001426EXPORT_SYMBOL(iwl_sta_modify_ps_wake);
Tomas Winkler9f586712008-11-12 13:14:05 -08001427
Johannes Berg6ab10ff2009-11-13 11:56:37 -08001428void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
Tomas Winkler9f586712008-11-12 13:14:05 -08001429{
Johannes Berg6ab10ff2009-11-13 11:56:37 -08001430 unsigned long flags;
Tomas Winkler9f586712008-11-12 13:14:05 -08001431
Johannes Berg6ab10ff2009-11-13 11:56:37 -08001432 spin_lock_irqsave(&priv->sta_lock, flags);
1433 priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
1434 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1435 priv->stations[sta_id].sta.sta.modify_mask =
1436 STA_MODIFY_SLEEP_TX_COUNT_MSK;
1437 priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
1438 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Reinette Chatre9c5ac092010-05-05 02:26:06 -07001439 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Johannes Berg6ab10ff2009-11-13 11:56:37 -08001440 spin_unlock_irqrestore(&priv->sta_lock, flags);
Tomas Winkler9f586712008-11-12 13:14:05 -08001441
Tomas Winkler9f586712008-11-12 13:14:05 -08001442}
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07001443EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001444
1445int iwl_mac_sta_remove(struct ieee80211_hw *hw,
Johannes Bergfd1af152010-04-30 11:30:43 -07001446 struct ieee80211_vif *vif,
1447 struct ieee80211_sta *sta)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001448{
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001449 struct iwl_priv *priv = hw->priv;
Johannes Bergfd1af152010-04-30 11:30:43 -07001450 struct iwl_station_priv_common *sta_common = (void *)sta->drv_priv;
1451 int ret;
1452
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001453 IWL_DEBUG_INFO(priv, "received request to remove station %pM\n",
1454 sta->addr);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07001455 mutex_lock(&priv->mutex);
1456 IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n",
1457 sta->addr);
Johannes Bergfd1af152010-04-30 11:30:43 -07001458 ret = iwl_remove_station(priv, sta_common->sta_id, sta->addr);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001459 if (ret)
1460 IWL_ERR(priv, "Error removing station %pM\n",
1461 sta->addr);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07001462 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08001463 return ret;
1464}
1465EXPORT_SYMBOL(iwl_mac_sta_remove);