blob: 10af82170f6b13ef36542af43607a2fce71fba9b [file] [log] [blame]
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07001/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
4 *
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:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * 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>
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070032
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070033#include "iwl-dev.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070034#include "iwl-core.h"
35#include "iwl-sta.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070036#include "iwl-helpers.h"
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -070037
Tomas Winkler7a999bf2008-05-29 16:35:02 +080038
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +080039#define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
40#define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
Tomas Winkler7a999bf2008-05-29 16:35:02 +080041
Tomas Winkler947b13a2008-04-16 16:34:48 -070042u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
43{
44 int i;
45 int start = 0;
46 int ret = IWL_INVALID_STATION;
47 unsigned long flags;
48 DECLARE_MAC_BUF(mac);
49
50 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) ||
51 (priv->iw_mode == IEEE80211_IF_TYPE_AP))
52 start = IWL_STA_ID;
53
54 if (is_broadcast_ether_addr(addr))
55 return priv->hw_params.bcast_sta_id;
56
57 spin_lock_irqsave(&priv->sta_lock, flags);
58 for (i = start; i < priv->hw_params.max_stations; i++)
59 if (priv->stations[i].used &&
60 (!compare_ether_addr(priv->stations[i].sta.sta.addr,
61 addr))) {
62 ret = i;
63 goto out;
64 }
65
66 IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n",
67 print_mac(mac, addr), priv->num_stations);
68
69 out:
70 spin_unlock_irqrestore(&priv->sta_lock, flags);
71 return ret;
72}
73EXPORT_SYMBOL(iwl_find_station);
74
Emmanuel Grumbachbe1f3ab62008-06-12 09:47:18 +080075int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
76{
77 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
78 return IWL_AP_ID;
79 } else {
80 u8 *da = ieee80211_get_DA(hdr);
81 return iwl_find_station(priv, da);
82 }
83}
84EXPORT_SYMBOL(iwl_get_ra_sta_id);
85
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +080086static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
87{
88 unsigned long flags;
89 DECLARE_MAC_BUF(mac);
90
91 spin_lock_irqsave(&priv->sta_lock, flags);
92
93 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE))
94 IWL_ERROR("ACTIVATE a non DRIVER active station %d\n", sta_id);
95
96 priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE;
97 IWL_DEBUG_ASSOC("Added STA to Ucode: %s\n",
98 print_mac(mac, priv->stations[sta_id].sta.sta.addr));
99
100 spin_unlock_irqrestore(&priv->sta_lock, flags);
101}
102
Tomas Winkler42132bc2008-05-29 16:35:03 +0800103static int iwl_add_sta_callback(struct iwl_priv *priv,
104 struct iwl_cmd *cmd, struct sk_buff *skb)
105{
106 struct iwl_rx_packet *res = NULL;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800107 u8 sta_id = cmd->cmd.addsta.sta.sta_id;
Tomas Winkler42132bc2008-05-29 16:35:03 +0800108
109 if (!skb) {
110 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
111 return 1;
112 }
113
114 res = (struct iwl_rx_packet *)skb->data;
115 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
116 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
117 res->hdr.flags);
118 return 1;
119 }
120
121 switch (res->u.add_sta.status) {
122 case ADD_STA_SUCCESS_MSK:
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800123 iwl_sta_ucode_activate(priv, sta_id);
124 /* fall through */
Tomas Winkler42132bc2008-05-29 16:35:03 +0800125 default:
126 IWL_DEBUG_HC("Received REPLY_ADD_STA:(0x%08X)\n",
127 res->u.add_sta.status);
128 break;
129 }
130
131 /* We didn't cache the SKB; let the caller free it */
132 return 1;
133}
134
Tomas Winkler133636d2008-05-05 10:22:34 +0800135int iwl_send_add_sta(struct iwl_priv *priv,
136 struct iwl_addsta_cmd *sta, u8 flags)
137{
138 struct iwl_rx_packet *res = NULL;
139 int ret = 0;
140 u8 data[sizeof(*sta)];
141 struct iwl_host_cmd cmd = {
142 .id = REPLY_ADD_STA,
143 .meta.flags = flags,
144 .data = data,
145 };
146
Tomas Winkler42132bc2008-05-29 16:35:03 +0800147 if (flags & CMD_ASYNC)
148 cmd.meta.u.callback = iwl_add_sta_callback;
149 else
Tomas Winkler133636d2008-05-05 10:22:34 +0800150 cmd.meta.flags |= CMD_WANT_SKB;
151
152 cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
153 ret = iwl_send_cmd(priv, &cmd);
154
155 if (ret || (flags & CMD_ASYNC))
156 return ret;
157
158 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
159 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
160 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
161 res->hdr.flags);
162 ret = -EIO;
163 }
164
165 if (ret == 0) {
166 switch (res->u.add_sta.status) {
167 case ADD_STA_SUCCESS_MSK:
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800168 iwl_sta_ucode_activate(priv, sta->sta.sta_id);
Tomas Winkler133636d2008-05-05 10:22:34 +0800169 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
170 break;
171 default:
172 ret = -EIO;
173 IWL_WARNING("REPLY_ADD_STA failed\n");
174 break;
175 }
176 }
177
178 priv->alloc_rxb_skb--;
179 dev_kfree_skb_any(cmd.meta.u.skb);
180
181 return ret;
182}
183EXPORT_SYMBOL(iwl_send_add_sta);
Tomas Winkler947b13a2008-04-16 16:34:48 -0700184
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800185static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
186 struct ieee80211_ht_info *sta_ht_inf)
187{
188 __le32 sta_flags;
189 u8 mimo_ps_mode;
190
191 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
192 goto done;
193
194 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2;
195
196 sta_flags = priv->stations[index].sta.station_flags;
197
198 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
199
200 switch (mimo_ps_mode) {
201 case WLAN_HT_CAP_MIMO_PS_STATIC:
202 sta_flags |= STA_FLG_MIMO_DIS_MSK;
203 break;
204 case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
205 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
206 break;
207 case WLAN_HT_CAP_MIMO_PS_DISABLED:
208 break;
209 default:
210 IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
211 break;
212 }
213
214 sta_flags |= cpu_to_le32(
215 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
216
217 sta_flags |= cpu_to_le32(
218 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
219
220 if (iwl_is_fat_tx_allowed(priv, sta_ht_inf))
221 sta_flags |= STA_FLG_FAT_EN_MSK;
222 else
223 sta_flags &= ~STA_FLG_FAT_EN_MSK;
224
225 priv->stations[index].sta.station_flags = sta_flags;
226 done:
227 return;
228}
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800229
230/**
231 * iwl_add_station_flags - Add station to tables in driver and device
232 */
233u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
234 u8 flags, struct ieee80211_ht_info *ht_info)
235{
236 int i;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800237 int sta_id = IWL_INVALID_STATION;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800238 struct iwl_station_entry *station;
239 unsigned long flags_spin;
240 DECLARE_MAC_BUF(mac);
241
242 spin_lock_irqsave(&priv->sta_lock, flags_spin);
243 if (is_ap)
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800244 sta_id = IWL_AP_ID;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800245 else if (is_broadcast_ether_addr(addr))
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800246 sta_id = priv->hw_params.bcast_sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800247 else
248 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
249 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
250 addr)) {
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800251 sta_id = i;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800252 break;
253 }
254
255 if (!priv->stations[i].used &&
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800256 sta_id == IWL_INVALID_STATION)
257 sta_id = i;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800258 }
259
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800260 /* These two conditions have the same outcome, but keep them separate
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800261 since they have different meanings */
262 if (unlikely(sta_id == IWL_INVALID_STATION)) {
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800263 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800264 return sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800265 }
266
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800267 if (priv->stations[sta_id].used &&
268 !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) {
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800269 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800270 return sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800271 }
272
273
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800274 station = &priv->stations[sta_id];
275 station->used = IWL_STA_DRIVER_ACTIVE;
276 IWL_DEBUG_ASSOC("Add STA to driver ID %d: %s\n",
277 sta_id, print_mac(mac, addr));
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800278 priv->num_stations++;
279
280 /* Set up the REPLY_ADD_STA command to send to device */
281 memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
282 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
283 station->sta.mode = 0;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800284 station->sta.sta.sta_id = sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800285 station->sta.station_flags = 0;
286
287 /* BCAST station and IBSS stations do not work in HT mode */
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800288 if (sta_id != priv->hw_params.bcast_sta_id &&
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800289 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800290 iwl_set_ht_add_station(priv, sta_id, ht_info);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800291
292 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
293
294 /* Add station to device's station table */
295 iwl_send_add_sta(priv, &station->sta, flags);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800296 return sta_id;
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800297
298}
299EXPORT_SYMBOL(iwl_add_station_flags);
300
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800301static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr)
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800302{
303 unsigned long flags;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800304 DECLARE_MAC_BUF(mac);
305
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800306 u8 sta_id = iwl_find_station(priv, addr);
307
308 BUG_ON(sta_id == IWL_INVALID_STATION);
309
310 IWL_DEBUG_ASSOC("Removed STA from Ucode: %s\n",
311 print_mac(mac, addr));
312
313 spin_lock_irqsave(&priv->sta_lock, flags);
314
315 /* Ucode must be active and driver must be non active */
316 if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE)
317 IWL_ERROR("removed non active STA %d\n", sta_id);
318
319 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
320
321 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
322 spin_unlock_irqrestore(&priv->sta_lock, flags);
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800323}
324
325static int iwl_remove_sta_callback(struct iwl_priv *priv,
326 struct iwl_cmd *cmd, struct sk_buff *skb)
327{
328 struct iwl_rx_packet *res = NULL;
329 const char *addr = cmd->cmd.rm_sta.addr;
330
331 if (!skb) {
332 IWL_ERROR("Error: Response NULL in REPLY_REMOVE_STA.\n");
333 return 1;
334 }
335
336 res = (struct iwl_rx_packet *)skb->data;
337 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
338 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
339 res->hdr.flags);
340 return 1;
341 }
342
343 switch (res->u.rem_sta.status) {
344 case REM_STA_SUCCESS_MSK:
345 iwl_sta_ucode_deactivate(priv, addr);
346 break;
347 default:
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800348 IWL_ERROR("REPLY_REMOVE_STA failed\n");
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800349 break;
350 }
351
352 /* We didn't cache the SKB; let the caller free it */
353 return 1;
354}
355
356static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
357 u8 flags)
358{
359 struct iwl_rx_packet *res = NULL;
360 int ret;
361
362 struct iwl_rem_sta_cmd rm_sta_cmd;
363
364 struct iwl_host_cmd cmd = {
365 .id = REPLY_REMOVE_STA,
366 .len = sizeof(struct iwl_rem_sta_cmd),
367 .meta.flags = flags,
368 .data = &rm_sta_cmd,
369 };
370
371 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
372 rm_sta_cmd.num_sta = 1;
373 memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN);
374
375 if (flags & CMD_ASYNC)
376 cmd.meta.u.callback = iwl_remove_sta_callback;
377 else
378 cmd.meta.flags |= CMD_WANT_SKB;
379 ret = iwl_send_cmd(priv, &cmd);
380
381 if (ret || (flags & CMD_ASYNC))
382 return ret;
383
384 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
385 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
386 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
387 res->hdr.flags);
388 ret = -EIO;
389 }
390
391 if (!ret) {
392 switch (res->u.rem_sta.status) {
393 case REM_STA_SUCCESS_MSK:
394 iwl_sta_ucode_deactivate(priv, addr);
395 IWL_DEBUG_ASSOC("REPLY_REMOVE_STA PASSED\n");
396 break;
397 default:
398 ret = -EIO;
399 IWL_ERROR("REPLY_REMOVE_STA failed\n");
400 break;
401 }
402 }
403
404 priv->alloc_rxb_skb--;
405 dev_kfree_skb_any(cmd.meta.u.skb);
406
407 return ret;
408}
Emmanuel Grumbachbe1f3ab62008-06-12 09:47:18 +0800409
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800410/**
411 * iwl_remove_station - Remove driver's knowledge of station.
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800412 */
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800413int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800414{
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800415 int sta_id = IWL_INVALID_STATION;
416 int i, ret = -EINVAL;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800417 unsigned long flags;
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800418 DECLARE_MAC_BUF(mac);
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800419
420 spin_lock_irqsave(&priv->sta_lock, flags);
421
422 if (is_ap)
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800423 sta_id = IWL_AP_ID;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800424 else if (is_broadcast_ether_addr(addr))
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800425 sta_id = priv->hw_params.bcast_sta_id;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800426 else
427 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
428 if (priv->stations[i].used &&
429 !compare_ether_addr(priv->stations[i].sta.sta.addr,
430 addr)) {
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800431 sta_id = i;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800432 break;
433 }
434
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800435 if (unlikely(sta_id == IWL_INVALID_STATION))
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800436 goto out;
437
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800438 IWL_DEBUG_ASSOC("Removing STA from driver:%d %s\n",
439 sta_id, print_mac(mac, addr));
440
441 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
442 IWL_ERROR("Removing %s but non DRIVER active\n",
443 print_mac(mac, addr));
444 goto out;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800445 }
446
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800447 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
448 IWL_ERROR("Removing %s but non UCODE active\n",
449 print_mac(mac, addr));
450 goto out;
451 }
452
453
454 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
455
456 priv->num_stations--;
457
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800458 BUG_ON(priv->num_stations < 0);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800459
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800460 spin_unlock_irqrestore(&priv->sta_lock, flags);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800461
462 ret = iwl_send_remove_station(priv, addr, CMD_ASYNC);
463 return ret;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800464out:
465 spin_unlock_irqrestore(&priv->sta_lock, flags);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800466 return ret;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800467}
468EXPORT_SYMBOL(iwl_remove_station);
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800469
Emmanuel Grumbachbe1f3ab62008-06-12 09:47:18 +0800470static int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700471{
472 int i;
473
474 for (i = 0; i < STA_KEY_MAX_NUM; i++)
Emmanuel Grumbach77bab602008-04-15 16:01:44 -0700475 if (!test_and_set_bit(i, &priv->ucode_key_table))
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700476 return i;
477
478 return -1;
479}
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700480
481int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
482{
483 int i, not_empty = 0;
484 u8 buff[sizeof(struct iwl_wep_cmd) +
485 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
486 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
487 size_t cmd_size = sizeof(struct iwl_wep_cmd);
488 struct iwl_host_cmd cmd = {
489 .id = REPLY_WEPKEY,
490 .data = wep_cmd,
491 .meta.flags = CMD_ASYNC,
492 };
493
494 memset(wep_cmd, 0, cmd_size +
495 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
496
497 for (i = 0; i < WEP_KEYS_MAX ; i++) {
498 wep_cmd->key[i].key_index = i;
499 if (priv->wep_keys[i].key_size) {
500 wep_cmd->key[i].key_offset = i;
501 not_empty = 1;
502 } else {
503 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
504 }
505
506 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
507 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
508 priv->wep_keys[i].key_size);
509 }
510
511 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
512 wep_cmd->num_keys = WEP_KEYS_MAX;
513
514 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
515
516 cmd.len = cmd_size;
517
518 if (not_empty || send_if_empty)
519 return iwl_send_cmd(priv, &cmd);
520 else
521 return 0;
522}
Tomas Winkler27aaba02008-05-05 10:22:44 +0800523EXPORT_SYMBOL(iwl_send_static_wepkey_cmd);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700524
525int iwl_remove_default_wep_key(struct iwl_priv *priv,
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700526 struct ieee80211_key_conf *keyconf)
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700527{
528 int ret;
529 unsigned long flags;
530
531 spin_lock_irqsave(&priv->sta_lock, flags);
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700532
533 if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table))
534 IWL_ERROR("index %d not used in uCode key table.\n",
535 keyconf->keyidx);
536
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700537 priv->default_wep_key--;
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700538 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700539 ret = iwl_send_static_wepkey_cmd(priv, 1);
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +0800540 IWL_DEBUG_WEP("Remove default WEP key: idx=%d ret=%d\n",
541 keyconf->keyidx, ret);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700542 spin_unlock_irqrestore(&priv->sta_lock, flags);
543
544 return ret;
545}
Tomas Winkler27aaba02008-05-05 10:22:44 +0800546EXPORT_SYMBOL(iwl_remove_default_wep_key);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700547
548int iwl_set_default_wep_key(struct iwl_priv *priv,
549 struct ieee80211_key_conf *keyconf)
550{
551 int ret;
552 unsigned long flags;
553
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +0800554 if (keyconf->keylen != WEP_KEY_LEN_128 &&
555 keyconf->keylen != WEP_KEY_LEN_64) {
556 IWL_DEBUG_WEP("Bad WEP key length %d\n", keyconf->keylen);
557 return -EINVAL;
558 }
559
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700560 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800561 keyconf->hw_key_idx = HW_KEY_DEFAULT;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700562 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
563
564 spin_lock_irqsave(&priv->sta_lock, flags);
565 priv->default_wep_key++;
566
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700567 if (test_and_set_bit(keyconf->keyidx, &priv->ucode_key_table))
568 IWL_ERROR("index %d already used in uCode key table.\n",
569 keyconf->keyidx);
570
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700571 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
572 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
573 keyconf->keylen);
574
575 ret = iwl_send_static_wepkey_cmd(priv, 0);
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +0800576 IWL_DEBUG_WEP("Set default WEP key: len=%d idx=%d ret=%d\n",
577 keyconf->keylen, keyconf->keyidx, ret);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700578 spin_unlock_irqrestore(&priv->sta_lock, flags);
579
580 return ret;
581}
Tomas Winkler27aaba02008-05-05 10:22:44 +0800582EXPORT_SYMBOL(iwl_set_default_wep_key);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700583
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700584static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700585 struct ieee80211_key_conf *keyconf,
586 u8 sta_id)
587{
588 unsigned long flags;
589 __le16 key_flags = 0;
590 int ret;
591
592 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700593
594 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
595 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
596 key_flags &= ~STA_KEY_FLG_INVALID;
597
598 if (keyconf->keylen == WEP_KEY_LEN_128)
599 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
600
Tomas Winkler5425e492008-04-15 16:01:38 -0700601 if (sta_id == priv->hw_params.bcast_sta_id)
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700602 key_flags |= STA_KEY_MULTICAST_MSK;
603
604 spin_lock_irqsave(&priv->sta_lock, flags);
605
606 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
607 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
608 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
609
610 memcpy(priv->stations[sta_id].keyinfo.key,
611 keyconf->key, keyconf->keylen);
612
613 memcpy(&priv->stations[sta_id].sta.key.key[3],
614 keyconf->key, keyconf->keylen);
615
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700616 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
617 == STA_KEY_FLG_NO_ENC)
618 priv->stations[sta_id].sta.key.key_offset =
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -0700619 iwl_get_free_ucode_key_index(priv);
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700620 /* else, we are overriding an existing key => no need to allocated room
621 * in uCode. */
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700622
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700623 priv->stations[sta_id].sta.key.key_flags = key_flags;
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700624 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
625 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
626
Tomas Winkler133636d2008-05-05 10:22:34 +0800627 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700628
629 spin_unlock_irqrestore(&priv->sta_lock, flags);
630
631 return ret;
632}
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700633
634static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
635 struct ieee80211_key_conf *keyconf,
636 u8 sta_id)
637{
638 unsigned long flags;
639 __le16 key_flags = 0;
640
641 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
642 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
643 key_flags &= ~STA_KEY_FLG_INVALID;
644
Tomas Winkler5425e492008-04-15 16:01:38 -0700645 if (sta_id == priv->hw_params.bcast_sta_id)
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700646 key_flags |= STA_KEY_MULTICAST_MSK;
647
648 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700649
650 spin_lock_irqsave(&priv->sta_lock, flags);
651 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
652 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
653
654 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
655 keyconf->keylen);
656
657 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
658 keyconf->keylen);
659
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700660 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
661 == STA_KEY_FLG_NO_ENC)
662 priv->stations[sta_id].sta.key.key_offset =
663 iwl_get_free_ucode_key_index(priv);
664 /* else, we are overriding an existing key => no need to allocated room
665 * in uCode. */
666
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700667 priv->stations[sta_id].sta.key.key_flags = key_flags;
668 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
669 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
670
671 spin_unlock_irqrestore(&priv->sta_lock, flags);
672
673 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
Tomas Winkler133636d2008-05-05 10:22:34 +0800674 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700675}
676
677static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
678 struct ieee80211_key_conf *keyconf,
679 u8 sta_id)
680{
681 unsigned long flags;
682 int ret = 0;
683
684 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
685 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700686
687 spin_lock_irqsave(&priv->sta_lock, flags);
688
689 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700690 priv->stations[sta_id].keyinfo.keylen = 16;
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700691
692 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
693 == STA_KEY_FLG_NO_ENC)
694 priv->stations[sta_id].sta.key.key_offset =
Emmanuel Grumbach77bab602008-04-15 16:01:44 -0700695 iwl_get_free_ucode_key_index(priv);
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700696 /* else, we are overriding an existing key => no need to allocated room
697 * in uCode. */
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700698
699 /* This copy is acutally not needed: we get the key with each TX */
700 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
701
702 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
703
704 spin_unlock_irqrestore(&priv->sta_lock, flags);
705
706 return ret;
707}
708
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700709int iwl_remove_dynamic_key(struct iwl_priv *priv,
710 struct ieee80211_key_conf *keyconf,
711 u8 sta_id)
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700712{
713 unsigned long flags;
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700714 int ret = 0;
715 u16 key_flags;
716 u8 keyidx;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700717
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800718 priv->key_mapping_key--;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700719
720 spin_lock_irqsave(&priv->sta_lock, flags);
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700721 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
722 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
723
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +0800724 IWL_DEBUG_WEP("Remove dynamic key: idx=%d sta=%d\n",
725 keyconf->keyidx, sta_id);
726
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700727 if (keyconf->keyidx != keyidx) {
728 /* We need to remove a key with index different that the one
729 * in the uCode. This means that the key we need to remove has
730 * been replaced by another one with different index.
731 * Don't do anything and return ok
732 */
733 spin_unlock_irqrestore(&priv->sta_lock, flags);
734 return 0;
735 }
736
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700737 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
738 &priv->ucode_key_table))
739 IWL_ERROR("index %d not used in uCode key table.\n",
740 priv->stations[sta_id].sta.key.key_offset);
741 memset(&priv->stations[sta_id].keyinfo, 0,
Tomas Winkler6def9762008-05-05 10:22:31 +0800742 sizeof(struct iwl_hw_key));
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700743 memset(&priv->stations[sta_id].sta.key, 0,
744 sizeof(struct iwl4965_keyinfo));
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700745 priv->stations[sta_id].sta.key.key_flags =
746 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
747 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700748 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
749 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700750
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800751 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -0700752 spin_unlock_irqrestore(&priv->sta_lock, flags);
753 return ret;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700754}
Tomas Winkler27aaba02008-05-05 10:22:44 +0800755EXPORT_SYMBOL(iwl_remove_dynamic_key);
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700756
757int iwl_set_dynamic_key(struct iwl_priv *priv,
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800758 struct ieee80211_key_conf *keyconf, u8 sta_id)
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700759{
760 int ret;
761
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800762 priv->key_mapping_key++;
763 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700764
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800765 switch (keyconf->alg) {
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700766 case ALG_CCMP:
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800767 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700768 break;
769 case ALG_TKIP:
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800770 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700771 break;
772 case ALG_WEP:
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800773 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700774 break;
775 default:
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +0800776 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700777 ret = -EINVAL;
778 }
779
Emmanuel Grumbach4564ce82008-06-12 09:47:09 +0800780 IWL_DEBUG_WEP("Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
781 keyconf->alg, keyconf->keylen, keyconf->keyidx,
782 sta_id, ret);
783
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700784 return ret;
785}
Tomas Winkler27aaba02008-05-05 10:22:44 +0800786EXPORT_SYMBOL(iwl_set_dynamic_key);
Emmanuel Grumbach74805132008-04-14 21:16:09 -0700787
Tomas Winkler66c73db2008-04-15 16:01:40 -0700788#ifdef CONFIG_IWLWIFI_DEBUG
789static void iwl_dump_lq_cmd(struct iwl_priv *priv,
790 struct iwl_link_quality_cmd *lq)
791{
792 int i;
793 IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
794 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
795 lq->general_params.single_stream_ant_msk,
796 lq->general_params.dual_stream_ant_msk);
797
798 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
799 IWL_DEBUG_RATE("lq index %d 0x%X\n",
800 i, lq->rs_table[i].rate_n_flags);
801}
802#else
803static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
804 struct iwl_link_quality_cmd *lq)
805{
806}
807#endif
808
809int iwl_send_lq_cmd(struct iwl_priv *priv,
810 struct iwl_link_quality_cmd *lq, u8 flags)
811{
812 struct iwl_host_cmd cmd = {
813 .id = REPLY_TX_LINK_QUALITY_CMD,
814 .len = sizeof(struct iwl_link_quality_cmd),
815 .meta.flags = flags,
816 .data = lq,
817 };
818
819 if ((lq->sta_id == 0xFF) &&
820 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
821 return -EINVAL;
822
823 if (lq->sta_id == 0xFF)
824 lq->sta_id = IWL_AP_ID;
825
826 iwl_dump_lq_cmd(priv,lq);
827
Ron Rindjunsky36e1f162008-06-30 17:23:13 +0800828 if (iwl_is_associated(priv) && priv->assoc_station_added)
Tomas Winkler66c73db2008-04-15 16:01:40 -0700829 return iwl_send_cmd(priv, &cmd);
830
831 return 0;
832}
833EXPORT_SYMBOL(iwl_send_lq_cmd);
834
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800835/**
836 * iwl_sta_init_lq - Initialize a station's hardware rate table
837 *
838 * The uCode's station table contains a table of fallback rates
839 * for automatic fallback during transmission.
840 *
841 * NOTE: This sets up a default set of values. These will be replaced later
Tomas Winklere227cea2008-07-18 13:53:05 +0800842 * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800843 * rc80211_simple.
844 *
845 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
846 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
847 * which requires station table entry to exist).
848 */
849static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
850{
851 int i, r;
852 struct iwl_link_quality_cmd link_cmd = {
853 .reserved1 = 0,
854 };
855 u16 rate_flags;
856
857 /* Set up the rate scaling to start at selected rate, fall back
858 * all the way down to 1M in IEEE order, and then spin on 1M */
859 if (is_ap)
860 r = IWL_RATE_54M_INDEX;
861 else if (priv->band == IEEE80211_BAND_5GHZ)
862 r = IWL_RATE_6M_INDEX;
863 else
864 r = IWL_RATE_1M_INDEX;
865
866 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
867 rate_flags = 0;
868 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
869 rate_flags |= RATE_MCS_CCK_MSK;
870
871 /* Use Tx antenna B only */
872 rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
873
874 link_cmd.rs_table[i].rate_n_flags =
Tomas Winklere7d326ac2008-06-12 09:47:11 +0800875 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800876 r = iwl4965_get_prev_ieee_rate(r);
877 }
878
879 link_cmd.general_params.single_stream_ant_msk = 2;
880 link_cmd.general_params.dual_stream_ant_msk = 3;
881 link_cmd.agg_params.agg_dis_start_th = 3;
882 link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
883
884 /* Update the rate scaling for control frame Tx to AP */
885 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
886
887 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
888 sizeof(link_cmd), &link_cmd, NULL);
889}
Emmanuel Grumbach24e5c402008-06-30 17:23:03 +0800890
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800891/**
892 * iwl_rxon_add_station - add station into station table.
893 *
894 * there is only one AP station with id= IWL_AP_ID
895 * NOTE: mutex must be held before calling this fnction
896 */
897int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
898{
899 u8 sta_id;
900
901 /* Add station to device's station table */
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800902 struct ieee80211_conf *conf = &priv->hw->conf;
903 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
904
905 if ((is_ap) &&
906 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
907 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
908 sta_id = iwl_add_station_flags(priv, addr, is_ap,
909 0, cur_ht_config);
910 else
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800911 sta_id = iwl_add_station_flags(priv, addr, is_ap,
912 0, NULL);
913
914 /* Set up default rate scaling table in device's station table */
915 iwl_sta_init_lq(priv, addr, is_ap);
916
917 return sta_id;
918}
919EXPORT_SYMBOL(iwl_rxon_add_station);
920
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800921/**
922 * iwl_get_sta_id - Find station's index within station table
923 *
924 * If new IBSS station, create new entry in station table
925 */
926int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
927{
928 int sta_id;
929 u16 fc = le16_to_cpu(hdr->frame_control);
930 DECLARE_MAC_BUF(mac);
931
932 /* If this frame is broadcast or management, use broadcast station id */
933 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
934 is_multicast_ether_addr(hdr->addr1))
935 return priv->hw_params.bcast_sta_id;
936
937 switch (priv->iw_mode) {
938
939 /* If we are a client station in a BSS network, use the special
940 * AP station entry (that's the only station we communicate with) */
941 case IEEE80211_IF_TYPE_STA:
942 return IWL_AP_ID;
943
944 /* If we are an AP, then find the station, or use BCAST */
945 case IEEE80211_IF_TYPE_AP:
946 sta_id = iwl_find_station(priv, hdr->addr1);
947 if (sta_id != IWL_INVALID_STATION)
948 return sta_id;
949 return priv->hw_params.bcast_sta_id;
950
951 /* If this frame is going out to an IBSS network, find the station,
952 * or create a new station table entry */
953 case IEEE80211_IF_TYPE_IBSS:
954 sta_id = iwl_find_station(priv, hdr->addr1);
955 if (sta_id != IWL_INVALID_STATION)
956 return sta_id;
957
958 /* Create new station table entry */
959 sta_id = iwl_add_station_flags(priv, hdr->addr1,
960 0, CMD_ASYNC, NULL);
961
962 if (sta_id != IWL_INVALID_STATION)
963 return sta_id;
964
965 IWL_DEBUG_DROP("Station %s not in station map. "
966 "Defaulting to broadcast...\n",
967 print_mac(mac, hdr->addr1));
968 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
969 return priv->hw_params.bcast_sta_id;
970
971 default:
972 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
973 return priv->hw_params.bcast_sta_id;
974 }
975}
976EXPORT_SYMBOL(iwl_get_sta_id);
977
Tomas Winkler5083e562008-05-29 16:35:15 +0800978/**
979 * iwl_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
980 */
981void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv, int sta_id, int tid)
982{
983 unsigned long flags;
984
985 /* Remove "disable" flag, to enable Tx for this TID */
986 spin_lock_irqsave(&priv->sta_lock, flags);
987 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
988 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
989 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
990 spin_unlock_irqrestore(&priv->sta_lock, flags);
991
992 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
993}
994EXPORT_SYMBOL(iwl_sta_modify_enable_tid_tx);
995