diff options
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-sta.c')
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-sta.c | 840 |
1 files changed, 110 insertions, 730 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c index 7e0829be5e78..7df2814fd4f8 100644 --- a/drivers/net/wireless/iwlwifi/iwl-sta.c +++ b/drivers/net/wireless/iwlwifi/iwl-sta.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | 2 | * |
3 | * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved. | 3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. |
4 | * | 4 | * |
5 | * Portions of this file are derived from the ipw3945 project, as well | 5 | * Portions of this file are derived from the ipw3945 project, as well |
6 | * as portions of the ieee80211 subsystem header files. | 6 | * as portions of the ieee80211 subsystem header files. |
@@ -107,7 +107,7 @@ static int iwl_process_add_sta_resp(struct iwl_priv *priv, | |||
107 | /* | 107 | /* |
108 | * XXX: The MAC address in the command buffer is often changed from | 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 | 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 | 110 | * written to the command buffer often is not the same MAC address |
111 | * read from the command buffer when the command returns. This | 111 | * read from the command buffer when the command returns. This |
112 | * issue has not yet been resolved and this debugging is left to | 112 | * issue has not yet been resolved and this debugging is left to |
113 | * observe the problem. | 113 | * observe the problem. |
@@ -141,7 +141,7 @@ int iwl_send_add_sta(struct iwl_priv *priv, | |||
141 | struct iwl_host_cmd cmd = { | 141 | struct iwl_host_cmd cmd = { |
142 | .id = REPLY_ADD_STA, | 142 | .id = REPLY_ADD_STA, |
143 | .flags = flags, | 143 | .flags = flags, |
144 | .data = data, | 144 | .data = { data, }, |
145 | }; | 145 | }; |
146 | u8 sta_id __maybe_unused = sta->sta.sta_id; | 146 | u8 sta_id __maybe_unused = sta->sta.sta_id; |
147 | 147 | ||
@@ -155,7 +155,7 @@ int iwl_send_add_sta(struct iwl_priv *priv, | |||
155 | might_sleep(); | 155 | might_sleep(); |
156 | } | 156 | } |
157 | 157 | ||
158 | cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data); | 158 | cmd.len[0] = priv->cfg->ops->utils->build_addsta_hcmd(sta, data); |
159 | ret = iwl_send_cmd(priv, &cmd); | 159 | ret = iwl_send_cmd(priv, &cmd); |
160 | 160 | ||
161 | if (ret || (flags & CMD_ASYNC)) | 161 | if (ret || (flags & CMD_ASYNC)) |
@@ -169,15 +169,16 @@ int iwl_send_add_sta(struct iwl_priv *priv, | |||
169 | 169 | ||
170 | return ret; | 170 | return ret; |
171 | } | 171 | } |
172 | EXPORT_SYMBOL(iwl_send_add_sta); | ||
173 | 172 | ||
174 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, | 173 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, |
175 | struct ieee80211_sta_ht_cap *sta_ht_inf) | 174 | struct ieee80211_sta *sta, |
175 | struct iwl_rxon_context *ctx) | ||
176 | { | 176 | { |
177 | struct ieee80211_sta_ht_cap *sta_ht_inf = &sta->ht_cap; | ||
177 | __le32 sta_flags; | 178 | __le32 sta_flags; |
178 | u8 mimo_ps_mode; | 179 | u8 mimo_ps_mode; |
179 | 180 | ||
180 | if (!sta_ht_inf || !sta_ht_inf->ht_supported) | 181 | if (!sta || !sta_ht_inf->ht_supported) |
181 | goto done; | 182 | goto done; |
182 | 183 | ||
183 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; | 184 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; |
@@ -211,7 +212,7 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, | |||
211 | sta_flags |= cpu_to_le32( | 212 | sta_flags |= cpu_to_le32( |
212 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); | 213 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); |
213 | 214 | ||
214 | if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf)) | 215 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) |
215 | sta_flags |= STA_FLG_HT40_EN_MSK; | 216 | sta_flags |= STA_FLG_HT40_EN_MSK; |
216 | else | 217 | else |
217 | sta_flags &= ~STA_FLG_HT40_EN_MSK; | 218 | sta_flags &= ~STA_FLG_HT40_EN_MSK; |
@@ -226,19 +227,17 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, | |||
226 | * | 227 | * |
227 | * should be called with sta_lock held | 228 | * should be called with sta_lock held |
228 | */ | 229 | */ |
229 | static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr, | 230 | u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
230 | bool is_ap, | 231 | const u8 *addr, bool is_ap, struct ieee80211_sta *sta) |
231 | struct ieee80211_sta_ht_cap *ht_info) | ||
232 | { | 232 | { |
233 | struct iwl_station_entry *station; | 233 | struct iwl_station_entry *station; |
234 | int i; | 234 | int i; |
235 | u8 sta_id = IWL_INVALID_STATION; | 235 | u8 sta_id = IWL_INVALID_STATION; |
236 | u16 rate; | ||
237 | 236 | ||
238 | if (is_ap) | 237 | if (is_ap) |
239 | sta_id = IWL_AP_ID; | 238 | sta_id = ctx->ap_sta_id; |
240 | else if (is_broadcast_ether_addr(addr)) | 239 | else if (is_broadcast_ether_addr(addr)) |
241 | sta_id = priv->hw_params.bcast_sta_id; | 240 | sta_id = ctx->bcast_sta_id; |
242 | else | 241 | else |
243 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { | 242 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
244 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, | 243 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
@@ -289,20 +288,22 @@ static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr, | |||
289 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); | 288 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
290 | station->sta.mode = 0; | 289 | station->sta.mode = 0; |
291 | station->sta.sta.sta_id = sta_id; | 290 | station->sta.sta.sta_id = sta_id; |
292 | station->sta.station_flags = 0; | 291 | station->sta.station_flags = ctx->station_flags; |
292 | station->ctxid = ctx->ctxid; | ||
293 | |||
294 | if (sta) { | ||
295 | struct iwl_station_priv_common *sta_priv; | ||
296 | |||
297 | sta_priv = (void *)sta->drv_priv; | ||
298 | sta_priv->ctx = ctx; | ||
299 | } | ||
293 | 300 | ||
294 | /* | 301 | /* |
295 | * OK to call unconditionally, since local stations (IBSS BSSID | 302 | * OK to call unconditionally, since local stations (IBSS BSSID |
296 | * STA and broadcast STA) pass in a NULL ht_info, and mac80211 | 303 | * STA and broadcast STA) pass in a NULL sta, and mac80211 |
297 | * doesn't allow HT IBSS. | 304 | * doesn't allow HT IBSS. |
298 | */ | 305 | */ |
299 | iwl_set_ht_add_station(priv, sta_id, ht_info); | 306 | iwl_set_ht_add_station(priv, sta_id, sta, ctx); |
300 | |||
301 | /* 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 | 307 | ||
307 | return sta_id; | 308 | return sta_id; |
308 | 309 | ||
@@ -313,10 +314,9 @@ static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr, | |||
313 | /** | 314 | /** |
314 | * iwl_add_station_common - | 315 | * iwl_add_station_common - |
315 | */ | 316 | */ |
316 | int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr, | 317 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
317 | bool is_ap, | 318 | const u8 *addr, bool is_ap, |
318 | struct ieee80211_sta_ht_cap *ht_info, | 319 | struct ieee80211_sta *sta, u8 *sta_id_r) |
319 | u8 *sta_id_r) | ||
320 | { | 320 | { |
321 | unsigned long flags_spin; | 321 | unsigned long flags_spin; |
322 | int ret = 0; | 322 | int ret = 0; |
@@ -325,7 +325,7 @@ int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr, | |||
325 | 325 | ||
326 | *sta_id_r = 0; | 326 | *sta_id_r = 0; |
327 | spin_lock_irqsave(&priv->sta_lock, flags_spin); | 327 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
328 | sta_id = iwl_prep_station(priv, addr, is_ap, ht_info); | 328 | sta_id = iwl_prep_station(priv, ctx, addr, is_ap, sta); |
329 | if (sta_id == IWL_INVALID_STATION) { | 329 | if (sta_id == IWL_INVALID_STATION) { |
330 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", | 330 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", |
331 | addr); | 331 | addr); |
@@ -370,112 +370,6 @@ int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr, | |||
370 | *sta_id_r = sta_id; | 370 | *sta_id_r = sta_id; |
371 | return ret; | 371 | return ret; |
372 | } | 372 | } |
373 | EXPORT_SYMBOL(iwl_add_station_common); | ||
374 | |||
375 | static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv, | ||
376 | u8 sta_id) | ||
377 | { | ||
378 | int i, r; | ||
379 | struct iwl_link_quality_cmd *link_cmd; | ||
380 | u32 rate_flags; | ||
381 | |||
382 | link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL); | ||
383 | if (!link_cmd) { | ||
384 | IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n"); | ||
385 | return NULL; | ||
386 | } | ||
387 | /* Set up the rate scaling to start at selected rate, fall back | ||
388 | * all the way down to 1M in IEEE order, and then spin on 1M */ | ||
389 | if (priv->band == IEEE80211_BAND_5GHZ) | ||
390 | r = IWL_RATE_6M_INDEX; | ||
391 | else | ||
392 | r = IWL_RATE_1M_INDEX; | ||
393 | |||
394 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { | ||
395 | rate_flags = 0; | ||
396 | if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) | ||
397 | rate_flags |= RATE_MCS_CCK_MSK; | ||
398 | |||
399 | rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) << | ||
400 | RATE_MCS_ANT_POS; | ||
401 | |||
402 | link_cmd->rs_table[i].rate_n_flags = | ||
403 | iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); | ||
404 | r = iwl_get_prev_ieee_rate(r); | ||
405 | } | ||
406 | |||
407 | link_cmd->general_params.single_stream_ant_msk = | ||
408 | first_antenna(priv->hw_params.valid_tx_ant); | ||
409 | |||
410 | link_cmd->general_params.dual_stream_ant_msk = | ||
411 | priv->hw_params.valid_tx_ant & | ||
412 | ~first_antenna(priv->hw_params.valid_tx_ant); | ||
413 | if (!link_cmd->general_params.dual_stream_ant_msk) { | ||
414 | link_cmd->general_params.dual_stream_ant_msk = ANT_AB; | ||
415 | } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) { | ||
416 | link_cmd->general_params.dual_stream_ant_msk = | ||
417 | priv->hw_params.valid_tx_ant; | ||
418 | } | ||
419 | |||
420 | link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; | ||
421 | link_cmd->agg_params.agg_time_limit = | ||
422 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); | ||
423 | |||
424 | link_cmd->sta_id = sta_id; | ||
425 | |||
426 | return link_cmd; | ||
427 | } | ||
428 | |||
429 | /* | ||
430 | * iwl_add_bssid_station - Add the special IBSS BSSID station | ||
431 | * | ||
432 | * Function sleeps. | ||
433 | */ | ||
434 | int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs, | ||
435 | u8 *sta_id_r) | ||
436 | { | ||
437 | int ret; | ||
438 | u8 sta_id; | ||
439 | struct iwl_link_quality_cmd *link_cmd; | ||
440 | unsigned long flags; | ||
441 | |||
442 | if (sta_id_r) | ||
443 | *sta_id_r = IWL_INVALID_STATION; | ||
444 | |||
445 | ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id); | ||
446 | if (ret) { | ||
447 | IWL_ERR(priv, "Unable to add station %pM\n", addr); | ||
448 | return ret; | ||
449 | } | ||
450 | |||
451 | if (sta_id_r) | ||
452 | *sta_id_r = sta_id; | ||
453 | |||
454 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
455 | priv->stations[sta_id].used |= IWL_STA_LOCAL; | ||
456 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
457 | |||
458 | if (init_rs) { | ||
459 | /* Set up default rate scaling table in device's station table */ | ||
460 | link_cmd = iwl_sta_alloc_lq(priv, sta_id); | ||
461 | if (!link_cmd) { | ||
462 | IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n", | ||
463 | addr); | ||
464 | return -ENOMEM; | ||
465 | } | ||
466 | |||
467 | ret = iwl_send_lq_cmd(priv, link_cmd, CMD_SYNC, true); | ||
468 | if (ret) | ||
469 | IWL_ERR(priv, "Link quality command failed (%d)\n", ret); | ||
470 | |||
471 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
472 | priv->stations[sta_id].lq = link_cmd; | ||
473 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
474 | } | ||
475 | |||
476 | return 0; | ||
477 | } | ||
478 | EXPORT_SYMBOL(iwl_add_bssid_station); | ||
479 | 373 | ||
480 | /** | 374 | /** |
481 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station | 375 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station |
@@ -496,7 +390,8 @@ static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id) | |||
496 | } | 390 | } |
497 | 391 | ||
498 | static int iwl_send_remove_station(struct iwl_priv *priv, | 392 | static int iwl_send_remove_station(struct iwl_priv *priv, |
499 | const u8 *addr, int sta_id) | 393 | const u8 *addr, int sta_id, |
394 | bool temporary) | ||
500 | { | 395 | { |
501 | struct iwl_rx_packet *pkt; | 396 | struct iwl_rx_packet *pkt; |
502 | int ret; | 397 | int ret; |
@@ -506,9 +401,9 @@ static int iwl_send_remove_station(struct iwl_priv *priv, | |||
506 | 401 | ||
507 | struct iwl_host_cmd cmd = { | 402 | struct iwl_host_cmd cmd = { |
508 | .id = REPLY_REMOVE_STA, | 403 | .id = REPLY_REMOVE_STA, |
509 | .len = sizeof(struct iwl_rem_sta_cmd), | 404 | .len = { sizeof(struct iwl_rem_sta_cmd), }, |
510 | .flags = CMD_SYNC, | 405 | .flags = CMD_SYNC, |
511 | .data = &rm_sta_cmd, | 406 | .data = { &rm_sta_cmd, }, |
512 | }; | 407 | }; |
513 | 408 | ||
514 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); | 409 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); |
@@ -532,9 +427,11 @@ static int iwl_send_remove_station(struct iwl_priv *priv, | |||
532 | if (!ret) { | 427 | if (!ret) { |
533 | switch (pkt->u.rem_sta.status) { | 428 | switch (pkt->u.rem_sta.status) { |
534 | case REM_STA_SUCCESS_MSK: | 429 | case REM_STA_SUCCESS_MSK: |
535 | spin_lock_irqsave(&priv->sta_lock, flags_spin); | 430 | if (!temporary) { |
536 | iwl_sta_ucode_deactivate(priv, sta_id); | 431 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
537 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | 432 | iwl_sta_ucode_deactivate(priv, sta_id); |
433 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | ||
434 | } | ||
538 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); | 435 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); |
539 | break; | 436 | break; |
540 | default: | 437 | default: |
@@ -597,16 +494,16 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, | |||
597 | 494 | ||
598 | priv->num_stations--; | 495 | priv->num_stations--; |
599 | 496 | ||
600 | BUG_ON(priv->num_stations < 0); | 497 | if (WARN_ON(priv->num_stations < 0)) |
498 | priv->num_stations = 0; | ||
601 | 499 | ||
602 | spin_unlock_irqrestore(&priv->sta_lock, flags); | 500 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
603 | 501 | ||
604 | return iwl_send_remove_station(priv, addr, sta_id); | 502 | return iwl_send_remove_station(priv, addr, sta_id, false); |
605 | out_err: | 503 | out_err: |
606 | spin_unlock_irqrestore(&priv->sta_lock, flags); | 504 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
607 | return -EINVAL; | 505 | return -EINVAL; |
608 | } | 506 | } |
609 | EXPORT_SYMBOL_GPL(iwl_remove_station); | ||
610 | 507 | ||
611 | /** | 508 | /** |
612 | * iwl_clear_ucode_stations - clear ucode station table bits | 509 | * iwl_clear_ucode_stations - clear ucode station table bits |
@@ -616,7 +513,8 @@ EXPORT_SYMBOL_GPL(iwl_remove_station); | |||
616 | * other than explicit station management would cause this in | 513 | * other than explicit station management would cause this in |
617 | * the ucode, e.g. unassociated RXON. | 514 | * the ucode, e.g. unassociated RXON. |
618 | */ | 515 | */ |
619 | void iwl_clear_ucode_stations(struct iwl_priv *priv) | 516 | void iwl_clear_ucode_stations(struct iwl_priv *priv, |
517 | struct iwl_rxon_context *ctx) | ||
620 | { | 518 | { |
621 | int i; | 519 | int i; |
622 | unsigned long flags_spin; | 520 | unsigned long flags_spin; |
@@ -626,6 +524,9 @@ void iwl_clear_ucode_stations(struct iwl_priv *priv) | |||
626 | 524 | ||
627 | spin_lock_irqsave(&priv->sta_lock, flags_spin); | 525 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
628 | for (i = 0; i < priv->hw_params.max_stations; i++) { | 526 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
527 | if (ctx && ctx->ctxid != priv->stations[i].ctxid) | ||
528 | continue; | ||
529 | |||
629 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { | 530 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { |
630 | IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i); | 531 | IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i); |
631 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | 532 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; |
@@ -637,7 +538,6 @@ void iwl_clear_ucode_stations(struct iwl_priv *priv) | |||
637 | if (!cleared) | 538 | if (!cleared) |
638 | IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n"); | 539 | IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n"); |
639 | } | 540 | } |
640 | EXPORT_SYMBOL(iwl_clear_ucode_stations); | ||
641 | 541 | ||
642 | /** | 542 | /** |
643 | * iwl_restore_stations() - Restore driver known stations to device | 543 | * iwl_restore_stations() - Restore driver known stations to device |
@@ -647,7 +547,7 @@ EXPORT_SYMBOL(iwl_clear_ucode_stations); | |||
647 | * | 547 | * |
648 | * Function sleeps. | 548 | * Function sleeps. |
649 | */ | 549 | */ |
650 | void iwl_restore_stations(struct iwl_priv *priv) | 550 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
651 | { | 551 | { |
652 | struct iwl_addsta_cmd sta_cmd; | 552 | struct iwl_addsta_cmd sta_cmd; |
653 | struct iwl_link_quality_cmd lq; | 553 | struct iwl_link_quality_cmd lq; |
@@ -665,6 +565,8 @@ void iwl_restore_stations(struct iwl_priv *priv) | |||
665 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); | 565 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); |
666 | spin_lock_irqsave(&priv->sta_lock, flags_spin); | 566 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
667 | for (i = 0; i < priv->hw_params.max_stations; i++) { | 567 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
568 | if (ctx->ctxid != priv->stations[i].ctxid) | ||
569 | continue; | ||
668 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && | 570 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && |
669 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { | 571 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { |
670 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", | 572 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", |
@@ -700,7 +602,7 @@ void iwl_restore_stations(struct iwl_priv *priv) | |||
700 | * current LQ command | 602 | * current LQ command |
701 | */ | 603 | */ |
702 | if (send_lq) | 604 | if (send_lq) |
703 | iwl_send_lq_cmd(priv, &lq, CMD_SYNC, true); | 605 | iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true); |
704 | spin_lock_irqsave(&priv->sta_lock, flags_spin); | 606 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
705 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; | 607 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; |
706 | } | 608 | } |
@@ -712,407 +614,79 @@ void iwl_restore_stations(struct iwl_priv *priv) | |||
712 | else | 614 | else |
713 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n"); | 615 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n"); |
714 | } | 616 | } |
715 | EXPORT_SYMBOL(iwl_restore_stations); | ||
716 | |||
717 | int iwl_get_free_ucode_key_index(struct iwl_priv *priv) | ||
718 | { | ||
719 | int i; | ||
720 | |||
721 | for (i = 0; i < STA_KEY_MAX_NUM; i++) | ||
722 | if (!test_and_set_bit(i, &priv->ucode_key_table)) | ||
723 | return i; | ||
724 | |||
725 | return WEP_INVALID_OFFSET; | ||
726 | } | ||
727 | EXPORT_SYMBOL(iwl_get_free_ucode_key_index); | ||
728 | |||
729 | static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty) | ||
730 | { | ||
731 | int i, not_empty = 0; | ||
732 | u8 buff[sizeof(struct iwl_wep_cmd) + | ||
733 | sizeof(struct iwl_wep_key) * WEP_KEYS_MAX]; | ||
734 | struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; | ||
735 | size_t cmd_size = sizeof(struct iwl_wep_cmd); | ||
736 | struct iwl_host_cmd cmd = { | ||
737 | .id = REPLY_WEPKEY, | ||
738 | .data = wep_cmd, | ||
739 | .flags = CMD_SYNC, | ||
740 | }; | ||
741 | |||
742 | might_sleep(); | ||
743 | |||
744 | memset(wep_cmd, 0, cmd_size + | ||
745 | (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); | ||
746 | |||
747 | for (i = 0; i < WEP_KEYS_MAX ; i++) { | ||
748 | wep_cmd->key[i].key_index = i; | ||
749 | if (priv->wep_keys[i].key_size) { | ||
750 | wep_cmd->key[i].key_offset = i; | ||
751 | not_empty = 1; | ||
752 | } else { | ||
753 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; | ||
754 | } | ||
755 | |||
756 | wep_cmd->key[i].key_size = priv->wep_keys[i].key_size; | ||
757 | memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key, | ||
758 | priv->wep_keys[i].key_size); | ||
759 | } | ||
760 | |||
761 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; | ||
762 | wep_cmd->num_keys = WEP_KEYS_MAX; | ||
763 | |||
764 | cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX; | ||
765 | |||
766 | cmd.len = cmd_size; | ||
767 | |||
768 | if (not_empty || send_if_empty) | ||
769 | return iwl_send_cmd(priv, &cmd); | ||
770 | else | ||
771 | return 0; | ||
772 | } | ||
773 | 617 | ||
774 | int iwl_restore_default_wep_keys(struct iwl_priv *priv) | 618 | void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
775 | { | ||
776 | lockdep_assert_held(&priv->mutex); | ||
777 | |||
778 | return iwl_send_static_wepkey_cmd(priv, 0); | ||
779 | } | ||
780 | EXPORT_SYMBOL(iwl_restore_default_wep_keys); | ||
781 | |||
782 | int iwl_remove_default_wep_key(struct iwl_priv *priv, | ||
783 | struct ieee80211_key_conf *keyconf) | ||
784 | { | ||
785 | int ret; | ||
786 | |||
787 | lockdep_assert_held(&priv->mutex); | ||
788 | |||
789 | IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", | ||
790 | keyconf->keyidx); | ||
791 | |||
792 | memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0])); | ||
793 | if (iwl_is_rfkill(priv)) { | ||
794 | IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n"); | ||
795 | /* but keys in device are clear anyway so return success */ | ||
796 | return 0; | ||
797 | } | ||
798 | ret = iwl_send_static_wepkey_cmd(priv, 1); | ||
799 | IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", | ||
800 | keyconf->keyidx, ret); | ||
801 | |||
802 | return ret; | ||
803 | } | ||
804 | EXPORT_SYMBOL(iwl_remove_default_wep_key); | ||
805 | |||
806 | int iwl_set_default_wep_key(struct iwl_priv *priv, | ||
807 | struct ieee80211_key_conf *keyconf) | ||
808 | { | ||
809 | int ret; | ||
810 | |||
811 | lockdep_assert_held(&priv->mutex); | ||
812 | |||
813 | if (keyconf->keylen != WEP_KEY_LEN_128 && | ||
814 | keyconf->keylen != WEP_KEY_LEN_64) { | ||
815 | IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen); | ||
816 | return -EINVAL; | ||
817 | } | ||
818 | |||
819 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; | ||
820 | keyconf->hw_key_idx = HW_KEY_DEFAULT; | ||
821 | priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; | ||
822 | |||
823 | priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; | ||
824 | memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key, | ||
825 | keyconf->keylen); | ||
826 | |||
827 | ret = iwl_send_static_wepkey_cmd(priv, 0); | ||
828 | IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", | ||
829 | keyconf->keylen, keyconf->keyidx, ret); | ||
830 | |||
831 | return ret; | ||
832 | } | ||
833 | EXPORT_SYMBOL(iwl_set_default_wep_key); | ||
834 | |||
835 | static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv, | ||
836 | struct ieee80211_key_conf *keyconf, | ||
837 | u8 sta_id) | ||
838 | { | ||
839 | unsigned long flags; | ||
840 | __le16 key_flags = 0; | ||
841 | struct iwl_addsta_cmd sta_cmd; | ||
842 | |||
843 | lockdep_assert_held(&priv->mutex); | ||
844 | |||
845 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; | ||
846 | |||
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 | |||
854 | if (sta_id == priv->hw_params.bcast_sta_id) | ||
855 | key_flags |= STA_KEY_MULTICAST_MSK; | ||
856 | |||
857 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
858 | |||
859 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; | ||
860 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; | ||
861 | priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; | ||
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 | |||
869 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) | ||
870 | == STA_KEY_FLG_NO_ENC) | ||
871 | priv->stations[sta_id].sta.key.key_offset = | ||
872 | iwl_get_free_ucode_key_index(priv); | ||
873 | /* else, we are overriding an existing key => no need to allocated room | ||
874 | * in uCode. */ | ||
875 | |||
876 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, | ||
877 | "no space for a new key"); | ||
878 | |||
879 | priv->stations[sta_id].sta.key.key_flags = key_flags; | ||
880 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; | ||
881 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
882 | |||
883 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | ||
884 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
885 | |||
886 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
887 | } | ||
888 | |||
889 | static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv, | ||
890 | struct ieee80211_key_conf *keyconf, | ||
891 | u8 sta_id) | ||
892 | { | 619 | { |
893 | unsigned long flags; | 620 | unsigned long flags; |
894 | __le16 key_flags = 0; | 621 | int sta_id = ctx->ap_sta_id; |
622 | int ret; | ||
895 | struct iwl_addsta_cmd sta_cmd; | 623 | struct iwl_addsta_cmd sta_cmd; |
896 | 624 | struct iwl_link_quality_cmd lq; | |
897 | lockdep_assert_held(&priv->mutex); | 625 | bool active; |
898 | |||
899 | key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); | ||
900 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); | ||
901 | key_flags &= ~STA_KEY_FLG_INVALID; | ||
902 | |||
903 | if (sta_id == priv->hw_params.bcast_sta_id) | ||
904 | key_flags |= STA_KEY_MULTICAST_MSK; | ||
905 | |||
906 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | ||
907 | 626 | ||
908 | spin_lock_irqsave(&priv->sta_lock, flags); | 627 | spin_lock_irqsave(&priv->sta_lock, flags); |
909 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; | 628 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { |
910 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; | 629 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
911 | 630 | return; | |
912 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, | 631 | } |
913 | keyconf->keylen); | ||
914 | |||
915 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, | ||
916 | keyconf->keylen); | ||
917 | |||
918 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) | ||
919 | == STA_KEY_FLG_NO_ENC) | ||
920 | priv->stations[sta_id].sta.key.key_offset = | ||
921 | iwl_get_free_ucode_key_index(priv); | ||
922 | /* else, we are overriding an existing key => no need to allocated room | ||
923 | * in uCode. */ | ||
924 | |||
925 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, | ||
926 | "no space for a new key"); | ||
927 | 632 | ||
928 | priv->stations[sta_id].sta.key.key_flags = key_flags; | 633 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); |
929 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; | 634 | sta_cmd.mode = 0; |
930 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | 635 | memcpy(&lq, priv->stations[sta_id].lq, sizeof(lq)); |
931 | 636 | ||
932 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | 637 | active = priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE; |
638 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
933 | spin_unlock_irqrestore(&priv->sta_lock, flags); | 639 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
934 | 640 | ||
935 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | 641 | if (active) { |
936 | } | 642 | ret = iwl_send_remove_station( |
937 | 643 | priv, priv->stations[sta_id].sta.sta.addr, | |
938 | static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv, | 644 | sta_id, true); |
939 | struct ieee80211_key_conf *keyconf, | 645 | if (ret) |
940 | u8 sta_id) | 646 | IWL_ERR(priv, "failed to remove STA %pM (%d)\n", |
941 | { | 647 | priv->stations[sta_id].sta.sta.addr, ret); |
942 | unsigned long flags; | 648 | } |
943 | int ret = 0; | ||
944 | __le16 key_flags = 0; | ||
945 | |||
946 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); | ||
947 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); | ||
948 | key_flags &= ~STA_KEY_FLG_INVALID; | ||
949 | |||
950 | if (sta_id == priv->hw_params.bcast_sta_id) | ||
951 | key_flags |= STA_KEY_MULTICAST_MSK; | ||
952 | |||
953 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | ||
954 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | ||
955 | |||
956 | spin_lock_irqsave(&priv->sta_lock, flags); | 649 | spin_lock_irqsave(&priv->sta_lock, flags); |
957 | 650 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; | |
958 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; | ||
959 | priv->stations[sta_id].keyinfo.keylen = 16; | ||
960 | |||
961 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) | ||
962 | == STA_KEY_FLG_NO_ENC) | ||
963 | priv->stations[sta_id].sta.key.key_offset = | ||
964 | iwl_get_free_ucode_key_index(priv); | ||
965 | /* else, we are overriding an existing key => no need to allocated room | ||
966 | * in uCode. */ | ||
967 | |||
968 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, | ||
969 | "no space for a new key"); | ||
970 | |||
971 | priv->stations[sta_id].sta.key.key_flags = key_flags; | ||
972 | |||
973 | |||
974 | /* This copy is acutally not needed: we get the key with each TX */ | ||
975 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16); | ||
976 | |||
977 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16); | ||
978 | |||
979 | spin_unlock_irqrestore(&priv->sta_lock, flags); | 651 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
980 | 652 | ||
981 | return ret; | 653 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
654 | if (ret) | ||
655 | IWL_ERR(priv, "failed to re-add STA %pM (%d)\n", | ||
656 | priv->stations[sta_id].sta.sta.addr, ret); | ||
657 | iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true); | ||
982 | } | 658 | } |
983 | 659 | ||
984 | void iwl_update_tkip_key(struct iwl_priv *priv, | 660 | int iwl_get_free_ucode_key_index(struct iwl_priv *priv) |
985 | struct ieee80211_key_conf *keyconf, | ||
986 | struct ieee80211_sta *sta, u32 iv32, u16 *phase1key) | ||
987 | { | 661 | { |
988 | u8 sta_id; | ||
989 | unsigned long flags; | ||
990 | int i; | 662 | int i; |
991 | 663 | ||
992 | if (iwl_scan_cancel(priv)) { | 664 | for (i = 0; i < priv->sta_key_max_num; i++) |
993 | /* cancel scan failed, just live w/ bad key and rely | 665 | if (!test_and_set_bit(i, &priv->ucode_key_table)) |
994 | briefly on SW decryption */ | 666 | return i; |
995 | return; | ||
996 | } | ||
997 | |||
998 | sta_id = iwl_sta_id_or_broadcast(priv, sta); | ||
999 | if (sta_id == IWL_INVALID_STATION) | ||
1000 | return; | ||
1001 | |||
1002 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1003 | |||
1004 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; | ||
1005 | |||
1006 | for (i = 0; i < 5; i++) | ||
1007 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = | ||
1008 | cpu_to_le16(phase1key[i]); | ||
1009 | |||
1010 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; | ||
1011 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1012 | |||
1013 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); | ||
1014 | |||
1015 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1016 | 667 | ||
668 | return WEP_INVALID_OFFSET; | ||
1017 | } | 669 | } |
1018 | EXPORT_SYMBOL(iwl_update_tkip_key); | ||
1019 | 670 | ||
1020 | int iwl_remove_dynamic_key(struct iwl_priv *priv, | 671 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv) |
1021 | struct ieee80211_key_conf *keyconf, | ||
1022 | u8 sta_id) | ||
1023 | { | 672 | { |
1024 | unsigned long flags; | 673 | unsigned long flags; |
1025 | u16 key_flags; | 674 | int i; |
1026 | u8 keyidx; | ||
1027 | struct iwl_addsta_cmd sta_cmd; | ||
1028 | |||
1029 | lockdep_assert_held(&priv->mutex); | ||
1030 | |||
1031 | priv->key_mapping_key--; | ||
1032 | 675 | ||
1033 | spin_lock_irqsave(&priv->sta_lock, flags); | 676 | spin_lock_irqsave(&priv->sta_lock, flags); |
1034 | key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); | 677 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
1035 | keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3; | 678 | if (!(priv->stations[i].used & IWL_STA_BCAST)) |
1036 | 679 | continue; | |
1037 | IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n", | ||
1038 | keyconf->keyidx, sta_id); | ||
1039 | |||
1040 | if (keyconf->keyidx != keyidx) { | ||
1041 | /* We need to remove a key with index different that the one | ||
1042 | * in the uCode. This means that the key we need to remove has | ||
1043 | * been replaced by another one with different index. | ||
1044 | * Don't do anything and return ok | ||
1045 | */ | ||
1046 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1047 | return 0; | ||
1048 | } | ||
1049 | |||
1050 | if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) { | ||
1051 | IWL_WARN(priv, "Removing wrong key %d 0x%x\n", | ||
1052 | keyconf->keyidx, key_flags); | ||
1053 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1054 | return 0; | ||
1055 | } | ||
1056 | 680 | ||
1057 | if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset, | 681 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; |
1058 | &priv->ucode_key_table)) | 682 | priv->num_stations--; |
1059 | IWL_ERR(priv, "index %d not used in uCode key table.\n", | 683 | if (WARN_ON(priv->num_stations < 0)) |
1060 | priv->stations[sta_id].sta.key.key_offset); | 684 | priv->num_stations = 0; |
1061 | memset(&priv->stations[sta_id].keyinfo, 0, | 685 | kfree(priv->stations[i].lq); |
1062 | sizeof(struct iwl_hw_key)); | 686 | priv->stations[i].lq = NULL; |
1063 | memset(&priv->stations[sta_id].sta.key, 0, | ||
1064 | sizeof(struct iwl4965_keyinfo)); | ||
1065 | priv->stations[sta_id].sta.key.key_flags = | ||
1066 | STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID; | ||
1067 | priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET; | ||
1068 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; | ||
1069 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1070 | |||
1071 | if (iwl_is_rfkill(priv)) { | ||
1072 | IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n"); | ||
1073 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1074 | return 0; | ||
1075 | } | 687 | } |
1076 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | ||
1077 | spin_unlock_irqrestore(&priv->sta_lock, flags); | 688 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
1078 | |||
1079 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
1080 | } | 689 | } |
1081 | EXPORT_SYMBOL(iwl_remove_dynamic_key); | ||
1082 | |||
1083 | int iwl_set_dynamic_key(struct iwl_priv *priv, | ||
1084 | struct ieee80211_key_conf *keyconf, u8 sta_id) | ||
1085 | { | ||
1086 | int ret; | ||
1087 | |||
1088 | lockdep_assert_held(&priv->mutex); | ||
1089 | |||
1090 | priv->key_mapping_key++; | ||
1091 | keyconf->hw_key_idx = HW_KEY_DYNAMIC; | ||
1092 | |||
1093 | switch (keyconf->alg) { | ||
1094 | case ALG_CCMP: | ||
1095 | ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); | ||
1096 | break; | ||
1097 | case ALG_TKIP: | ||
1098 | ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id); | ||
1099 | break; | ||
1100 | case ALG_WEP: | ||
1101 | ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id); | ||
1102 | break; | ||
1103 | default: | ||
1104 | IWL_ERR(priv, | ||
1105 | "Unknown alg: %s alg = %d\n", __func__, keyconf->alg); | ||
1106 | ret = -EINVAL; | ||
1107 | } | ||
1108 | |||
1109 | IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n", | ||
1110 | keyconf->alg, keyconf->keylen, keyconf->keyidx, | ||
1111 | sta_id, ret); | ||
1112 | |||
1113 | return ret; | ||
1114 | } | ||
1115 | EXPORT_SYMBOL(iwl_set_dynamic_key); | ||
1116 | 690 | ||
1117 | #ifdef CONFIG_IWLWIFI_DEBUG | 691 | #ifdef CONFIG_IWLWIFI_DEBUG |
1118 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, | 692 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, |
@@ -1147,16 +721,16 @@ static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, | |||
1147 | * RXON flags are updated and when LQ command is updated. | 721 | * RXON flags are updated and when LQ command is updated. |
1148 | */ | 722 | */ |
1149 | static bool is_lq_table_valid(struct iwl_priv *priv, | 723 | static bool is_lq_table_valid(struct iwl_priv *priv, |
724 | struct iwl_rxon_context *ctx, | ||
1150 | struct iwl_link_quality_cmd *lq) | 725 | struct iwl_link_quality_cmd *lq) |
1151 | { | 726 | { |
1152 | int i; | 727 | int i; |
1153 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; | ||
1154 | 728 | ||
1155 | if (ht_conf->is_ht) | 729 | if (ctx->ht.enabled) |
1156 | return true; | 730 | return true; |
1157 | 731 | ||
1158 | IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", | 732 | IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", |
1159 | priv->active_rxon.channel); | 733 | ctx->active.channel); |
1160 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { | 734 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
1161 | if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) { | 735 | if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) { |
1162 | IWL_DEBUG_INFO(priv, | 736 | IWL_DEBUG_INFO(priv, |
@@ -1178,7 +752,7 @@ static bool is_lq_table_valid(struct iwl_priv *priv, | |||
1178 | * this case to clear the state indicating that station creation is in | 752 | * this case to clear the state indicating that station creation is in |
1179 | * progress. | 753 | * progress. |
1180 | */ | 754 | */ |
1181 | int iwl_send_lq_cmd(struct iwl_priv *priv, | 755 | int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
1182 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) | 756 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) |
1183 | { | 757 | { |
1184 | int ret = 0; | 758 | int ret = 0; |
@@ -1186,18 +760,27 @@ int iwl_send_lq_cmd(struct iwl_priv *priv, | |||
1186 | 760 | ||
1187 | struct iwl_host_cmd cmd = { | 761 | struct iwl_host_cmd cmd = { |
1188 | .id = REPLY_TX_LINK_QUALITY_CMD, | 762 | .id = REPLY_TX_LINK_QUALITY_CMD, |
1189 | .len = sizeof(struct iwl_link_quality_cmd), | 763 | .len = { sizeof(struct iwl_link_quality_cmd), }, |
1190 | .flags = flags, | 764 | .flags = flags, |
1191 | .data = lq, | 765 | .data = { lq, }, |
1192 | }; | 766 | }; |
1193 | 767 | ||
1194 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) | 768 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) |
1195 | return -EINVAL; | 769 | return -EINVAL; |
1196 | 770 | ||
771 | |||
772 | spin_lock_irqsave(&priv->sta_lock, flags_spin); | ||
773 | if (!(priv->stations[lq->sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | ||
774 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | ||
775 | return -EINVAL; | ||
776 | } | ||
777 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | ||
778 | |||
1197 | iwl_dump_lq_cmd(priv, lq); | 779 | iwl_dump_lq_cmd(priv, lq); |
1198 | BUG_ON(init && (cmd.flags & CMD_ASYNC)); | 780 | if (WARN_ON(init && (cmd.flags & CMD_ASYNC))) |
781 | return -EINVAL; | ||
1199 | 782 | ||
1200 | if (is_lq_table_valid(priv, lq)) | 783 | if (is_lq_table_valid(priv, ctx, lq)) |
1201 | ret = iwl_send_cmd(priv, &cmd); | 784 | ret = iwl_send_cmd(priv, &cmd); |
1202 | else | 785 | else |
1203 | ret = -EINVAL; | 786 | ret = -EINVAL; |
@@ -1214,208 +797,6 @@ int iwl_send_lq_cmd(struct iwl_priv *priv, | |||
1214 | } | 797 | } |
1215 | return ret; | 798 | return ret; |
1216 | } | 799 | } |
1217 | EXPORT_SYMBOL(iwl_send_lq_cmd); | ||
1218 | |||
1219 | /** | ||
1220 | * iwl_alloc_bcast_station - add broadcast station into driver's station table. | ||
1221 | * | ||
1222 | * This adds the broadcast station into the driver's station table | ||
1223 | * and marks it driver active, so that it will be restored to the | ||
1224 | * device at the next best time. | ||
1225 | */ | ||
1226 | int iwl_alloc_bcast_station(struct iwl_priv *priv, bool init_lq) | ||
1227 | { | ||
1228 | struct iwl_link_quality_cmd *link_cmd; | ||
1229 | unsigned long flags; | ||
1230 | u8 sta_id; | ||
1231 | |||
1232 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1233 | sta_id = iwl_prep_station(priv, iwl_bcast_addr, false, NULL); | ||
1234 | if (sta_id == IWL_INVALID_STATION) { | ||
1235 | IWL_ERR(priv, "Unable to prepare broadcast station\n"); | ||
1236 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1237 | |||
1238 | return -EINVAL; | ||
1239 | } | ||
1240 | |||
1241 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; | ||
1242 | priv->stations[sta_id].used |= IWL_STA_BCAST; | ||
1243 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1244 | |||
1245 | if (init_lq) { | ||
1246 | link_cmd = iwl_sta_alloc_lq(priv, sta_id); | ||
1247 | if (!link_cmd) { | ||
1248 | IWL_ERR(priv, | ||
1249 | "Unable to initialize rate scaling for bcast station.\n"); | ||
1250 | return -ENOMEM; | ||
1251 | } | ||
1252 | |||
1253 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1254 | priv->stations[sta_id].lq = link_cmd; | ||
1255 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1256 | } | ||
1257 | |||
1258 | return 0; | ||
1259 | } | ||
1260 | EXPORT_SYMBOL_GPL(iwl_alloc_bcast_station); | ||
1261 | |||
1262 | /** | ||
1263 | * iwl_update_bcast_station - update broadcast station's LQ command | ||
1264 | * | ||
1265 | * Only used by iwlagn. Placed here to have all bcast station management | ||
1266 | * code together. | ||
1267 | */ | ||
1268 | int iwl_update_bcast_station(struct iwl_priv *priv) | ||
1269 | { | ||
1270 | unsigned long flags; | ||
1271 | struct iwl_link_quality_cmd *link_cmd; | ||
1272 | u8 sta_id = priv->hw_params.bcast_sta_id; | ||
1273 | |||
1274 | link_cmd = iwl_sta_alloc_lq(priv, sta_id); | ||
1275 | if (!link_cmd) { | ||
1276 | IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n"); | ||
1277 | return -ENOMEM; | ||
1278 | } | ||
1279 | |||
1280 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1281 | if (priv->stations[sta_id].lq) | ||
1282 | kfree(priv->stations[sta_id].lq); | ||
1283 | else | ||
1284 | IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n"); | ||
1285 | priv->stations[sta_id].lq = link_cmd; | ||
1286 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1287 | |||
1288 | return 0; | ||
1289 | } | ||
1290 | EXPORT_SYMBOL_GPL(iwl_update_bcast_station); | ||
1291 | |||
1292 | void iwl_dealloc_bcast_station(struct iwl_priv *priv) | ||
1293 | { | ||
1294 | unsigned long flags; | ||
1295 | int i; | ||
1296 | |||
1297 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1298 | for (i = 0; i < priv->hw_params.max_stations; i++) { | ||
1299 | if (!(priv->stations[i].used & IWL_STA_BCAST)) | ||
1300 | continue; | ||
1301 | |||
1302 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | ||
1303 | priv->num_stations--; | ||
1304 | BUG_ON(priv->num_stations < 0); | ||
1305 | kfree(priv->stations[i].lq); | ||
1306 | priv->stations[i].lq = NULL; | ||
1307 | } | ||
1308 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1309 | } | ||
1310 | EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_station); | ||
1311 | |||
1312 | /** | ||
1313 | * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table | ||
1314 | */ | ||
1315 | int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid) | ||
1316 | { | ||
1317 | unsigned long flags; | ||
1318 | struct iwl_addsta_cmd sta_cmd; | ||
1319 | |||
1320 | lockdep_assert_held(&priv->mutex); | ||
1321 | |||
1322 | /* Remove "disable" flag, to enable Tx for this TID */ | ||
1323 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1324 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; | ||
1325 | priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); | ||
1326 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1327 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | ||
1328 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1329 | |||
1330 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
1331 | } | ||
1332 | EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid); | ||
1333 | |||
1334 | int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta, | ||
1335 | int tid, u16 ssn) | ||
1336 | { | ||
1337 | unsigned long flags; | ||
1338 | int sta_id; | ||
1339 | struct iwl_addsta_cmd sta_cmd; | ||
1340 | |||
1341 | lockdep_assert_held(&priv->mutex); | ||
1342 | |||
1343 | sta_id = iwl_sta_id(sta); | ||
1344 | if (sta_id == IWL_INVALID_STATION) | ||
1345 | return -ENXIO; | ||
1346 | |||
1347 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1348 | priv->stations[sta_id].sta.station_flags_msk = 0; | ||
1349 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; | ||
1350 | priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid; | ||
1351 | priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); | ||
1352 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1353 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | ||
1354 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1355 | |||
1356 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
1357 | } | ||
1358 | EXPORT_SYMBOL(iwl_sta_rx_agg_start); | ||
1359 | |||
1360 | int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta, | ||
1361 | int tid) | ||
1362 | { | ||
1363 | unsigned long flags; | ||
1364 | int sta_id; | ||
1365 | struct iwl_addsta_cmd sta_cmd; | ||
1366 | |||
1367 | lockdep_assert_held(&priv->mutex); | ||
1368 | |||
1369 | sta_id = iwl_sta_id(sta); | ||
1370 | if (sta_id == IWL_INVALID_STATION) { | ||
1371 | IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); | ||
1372 | return -ENXIO; | ||
1373 | } | ||
1374 | |||
1375 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1376 | priv->stations[sta_id].sta.station_flags_msk = 0; | ||
1377 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; | ||
1378 | priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid; | ||
1379 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1380 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | ||
1381 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1382 | |||
1383 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
1384 | } | ||
1385 | EXPORT_SYMBOL(iwl_sta_rx_agg_stop); | ||
1386 | |||
1387 | void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) | ||
1388 | { | ||
1389 | unsigned long flags; | ||
1390 | |||
1391 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1392 | priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK; | ||
1393 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; | ||
1394 | priv->stations[sta_id].sta.sta.modify_mask = 0; | ||
1395 | priv->stations[sta_id].sta.sleep_tx_count = 0; | ||
1396 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1397 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); | ||
1398 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1399 | |||
1400 | } | ||
1401 | EXPORT_SYMBOL(iwl_sta_modify_ps_wake); | ||
1402 | |||
1403 | void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt) | ||
1404 | { | ||
1405 | unsigned long flags; | ||
1406 | |||
1407 | spin_lock_irqsave(&priv->sta_lock, flags); | ||
1408 | priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK; | ||
1409 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; | ||
1410 | priv->stations[sta_id].sta.sta.modify_mask = | ||
1411 | STA_MODIFY_SLEEP_TX_COUNT_MSK; | ||
1412 | priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt); | ||
1413 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | ||
1414 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); | ||
1415 | spin_unlock_irqrestore(&priv->sta_lock, flags); | ||
1416 | |||
1417 | } | ||
1418 | EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count); | ||
1419 | 800 | ||
1420 | int iwl_mac_sta_remove(struct ieee80211_hw *hw, | 801 | int iwl_mac_sta_remove(struct ieee80211_hw *hw, |
1421 | struct ieee80211_vif *vif, | 802 | struct ieee80211_vif *vif, |
@@ -1437,4 +818,3 @@ int iwl_mac_sta_remove(struct ieee80211_hw *hw, | |||
1437 | mutex_unlock(&priv->mutex); | 818 | mutex_unlock(&priv->mutex); |
1438 | return ret; | 819 | return ret; |
1439 | } | 820 | } |
1440 | EXPORT_SYMBOL(iwl_mac_sta_remove); | ||