]>
Commit | Line | Data |
---|---|---|
6974e363 EG |
1 | /****************************************************************************** |
2 | * | |
1f447808 | 3 | * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved. |
6974e363 EG |
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: | |
759ef89f | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
6974e363 EG |
26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
27 | * | |
28 | *****************************************************************************/ | |
29 | ||
30 | #include <net/mac80211.h> | |
947b13a7 | 31 | #include <linux/etherdevice.h> |
fe6b23dd | 32 | #include <linux/sched.h> |
4620fefa | 33 | #include <linux/lockdep.h> |
6974e363 | 34 | |
3e0d4cb1 | 35 | #include "iwl-dev.h" |
6974e363 EG |
36 | #include "iwl-core.h" |
37 | #include "iwl-sta.h" | |
7a999bf0 | 38 | |
1fa97aae | 39 | /* priv->sta_lock must be held */ |
24e5c401 EG |
40 | static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id) |
41 | { | |
24e5c401 | 42 | |
c587de0b | 43 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) |
1fa97aae RC |
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); | |
24e5c401 | 46 | |
1fa97aae RC |
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 | } | |
24e5c401 EG |
56 | } |
57 | ||
09034cb7 JB |
58 | static 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) | |
42132bce | 62 | { |
3257e5d4 | 63 | u8 sta_id = addsta->sta.sta_id; |
1fa97aae | 64 | unsigned long flags; |
09034cb7 | 65 | int ret = -EIO; |
42132bce | 66 | |
2f301227 | 67 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
15b1687c | 68 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
1fa97aae | 69 | pkt->hdr.flags); |
09034cb7 | 70 | return ret; |
42132bce TW |
71 | } |
72 | ||
1fa97aae RC |
73 | IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n", |
74 | sta_id); | |
75 | ||
76 | spin_lock_irqsave(&priv->sta_lock, flags); | |
77 | ||
2f301227 | 78 | switch (pkt->u.add_sta.status) { |
42132bce | 79 | case ADD_STA_SUCCESS_MSK: |
1fa97aae | 80 | IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n"); |
24e5c401 | 81 | iwl_sta_ucode_activate(priv, sta_id); |
09034cb7 | 82 | ret = 0; |
1fa97aae RC |
83 | break; |
84 | case ADD_STA_NO_ROOM_IN_TABLE: | |
85 | IWL_ERR(priv, "Adding station %d failed, no room in table.\n", | |
86 | sta_id); | |
87 | 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: | |
91dd6c27 | 93 | IWL_ERR(priv, "Attempting to modify non-existing station %d\n", |
1fa97aae RC |
94 | sta_id); |
95 | break; | |
42132bce | 96 | default: |
1fa97aae RC |
97 | IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n", |
98 | pkt->u.add_sta.status); | |
42132bce TW |
99 | break; |
100 | } | |
1fa97aae RC |
101 | |
102 | IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n", | |
103 | priv->stations[sta_id].sta.mode == | |
104 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", | |
105 | sta_id, priv->stations[sta_id].sta.sta.addr); | |
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); | |
1fa97aae | 119 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
09034cb7 JB |
120 | |
121 | return ret; | |
1fa97aae RC |
122 | } |
123 | ||
124 | static void iwl_add_sta_callback(struct iwl_priv *priv, | |
125 | struct iwl_device_cmd *cmd, | |
126 | struct iwl_rx_packet *pkt) | |
127 | { | |
128 | struct iwl_addsta_cmd *addsta = | |
129 | (struct iwl_addsta_cmd *)cmd->cmd.payload; | |
130 | ||
131 | iwl_process_add_sta_resp(priv, addsta, pkt, false); | |
132 | ||
42132bce TW |
133 | } |
134 | ||
17f841cd | 135 | int iwl_send_add_sta(struct iwl_priv *priv, |
133636de TW |
136 | struct iwl_addsta_cmd *sta, u8 flags) |
137 | { | |
2f301227 | 138 | struct iwl_rx_packet *pkt = NULL; |
133636de TW |
139 | int ret = 0; |
140 | u8 data[sizeof(*sta)]; | |
141 | struct iwl_host_cmd cmd = { | |
142 | .id = REPLY_ADD_STA, | |
c2acea8e | 143 | .flags = flags, |
133636de TW |
144 | .data = data, |
145 | }; | |
f875f518 | 146 | u8 sta_id __maybe_unused = sta->sta.sta_id; |
fe6b23dd RC |
147 | |
148 | IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n", | |
149 | sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : ""); | |
133636de | 150 | |
42132bce | 151 | if (flags & CMD_ASYNC) |
c2acea8e | 152 | cmd.callback = iwl_add_sta_callback; |
4620fefa | 153 | else { |
c2acea8e | 154 | cmd.flags |= CMD_WANT_SKB; |
4620fefa JB |
155 | might_sleep(); |
156 | } | |
133636de TW |
157 | |
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 | ||
133636de | 164 | if (ret == 0) { |
1fa97aae | 165 | pkt = (struct iwl_rx_packet *)cmd.reply_page; |
09034cb7 | 166 | ret = iwl_process_add_sta_resp(priv, sta, pkt, true); |
133636de | 167 | } |
64a76b50 | 168 | iwl_free_pages(priv, cmd.reply_page); |
133636de TW |
169 | |
170 | return ret; | |
171 | } | |
17f841cd | 172 | EXPORT_SYMBOL(iwl_send_add_sta); |
947b13a7 | 173 | |
4f40e4d9 | 174 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, |
d9fe60de | 175 | struct ieee80211_sta_ht_cap *sta_ht_inf) |
4f40e4d9 TW |
176 | { |
177 | __le32 sta_flags; | |
178 | u8 mimo_ps_mode; | |
179 | ||
180 | if (!sta_ht_inf || !sta_ht_inf->ht_supported) | |
181 | goto done; | |
182 | ||
00c5ae2f | 183 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; |
3f3e0376 WYG |
184 | 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"); | |
4f40e4d9 TW |
189 | |
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) { | |
00c5ae2f | 195 | case WLAN_HT_CAP_SM_PS_STATIC: |
4f40e4d9 TW |
196 | sta_flags |= STA_FLG_MIMO_DIS_MSK; |
197 | break; | |
00c5ae2f | 198 | case WLAN_HT_CAP_SM_PS_DYNAMIC: |
4f40e4d9 TW |
199 | sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; |
200 | break; | |
00c5ae2f | 201 | case WLAN_HT_CAP_SM_PS_DISABLED: |
4f40e4d9 TW |
202 | break; |
203 | default: | |
39aadf8c | 204 | IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode); |
4f40e4d9 TW |
205 | 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 | ||
7aafef1c WYG |
214 | if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf)) |
215 | sta_flags |= STA_FLG_HT40_EN_MSK; | |
4f40e4d9 | 216 | else |
7aafef1c | 217 | sta_flags &= ~STA_FLG_HT40_EN_MSK; |
4f40e4d9 TW |
218 | |
219 | priv->stations[index].sta.station_flags = sta_flags; | |
220 | done: | |
221 | return; | |
222 | } | |
4f40e4d9 TW |
223 | |
224 | /** | |
fe6b23dd RC |
225 | * iwl_prep_station - Prepare station information for addition |
226 | * | |
227 | * should be called with sta_lock held | |
4f40e4d9 | 228 | */ |
a194e324 JB |
229 | static u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
230 | const u8 *addr, bool is_ap, | |
fe6b23dd | 231 | struct ieee80211_sta_ht_cap *ht_info) |
4f40e4d9 | 232 | { |
4f40e4d9 | 233 | struct iwl_station_entry *station; |
c587de0b | 234 | int i; |
fe6b23dd | 235 | u8 sta_id = IWL_INVALID_STATION; |
c587de0b | 236 | u16 rate; |
4f40e4d9 | 237 | |
4f40e4d9 | 238 | if (is_ap) |
2995bafa | 239 | sta_id = ctx->ap_sta_id; |
4f40e4d9 | 240 | else if (is_broadcast_ether_addr(addr)) |
a194e324 | 241 | sta_id = ctx->bcast_sta_id; |
4f40e4d9 TW |
242 | 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)) { | |
24e5c401 | 246 | sta_id = i; |
4f40e4d9 TW |
247 | break; |
248 | } | |
249 | ||
250 | if (!priv->stations[i].used && | |
24e5c401 EG |
251 | sta_id == IWL_INVALID_STATION) |
252 | sta_id = i; | |
4f40e4d9 TW |
253 | } |
254 | ||
fe6b23dd RC |
255 | /* |
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); | |
24e5c401 | 270 | return sta_id; |
4f40e4d9 TW |
271 | } |
272 | ||
fe6b23dd RC |
273 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && |
274 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) && | |
24e5c401 | 275 | !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) { |
fe6b23dd RC |
276 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", |
277 | sta_id, addr); | |
24e5c401 | 278 | return sta_id; |
4f40e4d9 TW |
279 | } |
280 | ||
24e5c401 EG |
281 | station = &priv->stations[sta_id]; |
282 | station->used = IWL_STA_DRIVER_ACTIVE; | |
e1623446 | 283 | IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n", |
e174961c | 284 | sta_id, addr); |
4f40e4d9 TW |
285 | 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; | |
24e5c401 | 291 | station->sta.sta.sta_id = sta_id; |
770e13bd | 292 | station->sta.station_flags = ctx->station_flags; |
dcef732c | 293 | station->ctxid = ctx->ctxid; |
4f40e4d9 | 294 | |
63d41769 JB |
295 | /* |
296 | * OK to call unconditionally, since local stations (IBSS BSSID | |
297 | * STA and broadcast STA) pass in a NULL ht_info, and mac80211 | |
298 | * doesn't allow HT IBSS. | |
299 | */ | |
300 | iwl_set_ht_add_station(priv, sta_id, ht_info); | |
4f40e4d9 | 301 | |
c587de0b TW |
302 | /* 3945 only */ |
303 | rate = (priv->band == IEEE80211_BAND_5GHZ) ? | |
304 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP; | |
305 | /* Turn on both antennas for the station... */ | |
306 | station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK); | |
307 | ||
fe6b23dd RC |
308 | return sta_id; |
309 | ||
310 | } | |
311 | ||
312 | #define STA_WAIT_TIMEOUT (HZ/2) | |
313 | ||
314 | /** | |
315 | * iwl_add_station_common - | |
316 | */ | |
a194e324 JB |
317 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
318 | const u8 *addr, bool is_ap, | |
319 | struct ieee80211_sta_ht_cap *ht_info, u8 *sta_id_r) | |
fe6b23dd | 320 | { |
fe6b23dd RC |
321 | unsigned long flags_spin; |
322 | int ret = 0; | |
323 | u8 sta_id; | |
9c5ac091 | 324 | struct iwl_addsta_cmd sta_cmd; |
fe6b23dd RC |
325 | |
326 | *sta_id_r = 0; | |
327 | spin_lock_irqsave(&priv->sta_lock, flags_spin); | |
a194e324 | 328 | sta_id = iwl_prep_station(priv, ctx, addr, is_ap, ht_info); |
fe6b23dd RC |
329 | if (sta_id == IWL_INVALID_STATION) { |
330 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", | |
331 | addr); | |
332 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | |
333 | return -EINVAL; | |
334 | } | |
335 | ||
336 | /* | |
337 | * uCode is not able to deal with multiple requests to add a | |
338 | * station. Keep track if one is in progress so that we do not send | |
339 | * another. | |
340 | */ | |
341 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { | |
342 | IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n", | |
343 | sta_id); | |
344 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | |
345 | return -EEXIST; | |
346 | } | |
347 | ||
348 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && | |
349 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { | |
350 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", | |
351 | sta_id, addr); | |
352 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | |
353 | return -EEXIST; | |
354 | } | |
355 | ||
356 | priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS; | |
9c5ac091 | 357 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
4f40e4d9 TW |
358 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
359 | ||
360 | /* Add station to device's station table */ | |
9c5ac091 | 361 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
fe6b23dd | 362 | if (ret) { |
fe6b23dd | 363 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
9c5ac091 RC |
364 | IWL_ERR(priv, "Adding station %pM failed.\n", |
365 | priv->stations[sta_id].sta.sta.addr); | |
fe6b23dd RC |
366 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
367 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; | |
368 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | |
369 | } | |
370 | *sta_id_r = sta_id; | |
371 | return ret; | |
4f40e4d9 | 372 | } |
fe6b23dd | 373 | EXPORT_SYMBOL(iwl_add_station_common); |
4f40e4d9 | 374 | |
a6a0345c JB |
375 | static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv, |
376 | u8 sta_id) | |
7a999bf0 | 377 | { |
fe6b23dd | 378 | int i, r; |
d2e210ae | 379 | struct iwl_link_quality_cmd *link_cmd; |
fe6b23dd RC |
380 | u32 rate_flags; |
381 | ||
d2e210ae RC |
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 | } | |
fe6b23dd RC |
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 */ | |
156b70d1 | 389 | if (priv->band == IEEE80211_BAND_5GHZ) |
fe6b23dd RC |
390 | r = IWL_RATE_6M_INDEX; |
391 | else | |
392 | r = IWL_RATE_1M_INDEX; | |
24e5c401 | 393 | |
fe6b23dd RC |
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; | |
24e5c401 | 398 | |
fe6b23dd RC |
399 | rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) << |
400 | RATE_MCS_ANT_POS; | |
24e5c401 | 401 | |
d2e210ae | 402 | link_cmd->rs_table[i].rate_n_flags = |
fe6b23dd RC |
403 | iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); |
404 | r = iwl_get_prev_ieee_rate(r); | |
405 | } | |
24e5c401 | 406 | |
d2e210ae | 407 | link_cmd->general_params.single_stream_ant_msk = |
fe6b23dd | 408 | first_antenna(priv->hw_params.valid_tx_ant); |
3a23d695 | 409 | |
d2e210ae | 410 | link_cmd->general_params.dual_stream_ant_msk = |
3a23d695 WYG |
411 | priv->hw_params.valid_tx_ant & |
412 | ~first_antenna(priv->hw_params.valid_tx_ant); | |
d2e210ae RC |
413 | if (!link_cmd->general_params.dual_stream_ant_msk) { |
414 | link_cmd->general_params.dual_stream_ant_msk = ANT_AB; | |
3a23d695 | 415 | } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) { |
d2e210ae | 416 | link_cmd->general_params.dual_stream_ant_msk = |
3a23d695 WYG |
417 | priv->hw_params.valid_tx_ant; |
418 | } | |
419 | ||
d2e210ae RC |
420 | link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; |
421 | link_cmd->agg_params.agg_time_limit = | |
fe6b23dd | 422 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
24e5c401 | 423 | |
156b70d1 | 424 | link_cmd->sta_id = sta_id; |
24e5c401 | 425 | |
d2e210ae | 426 | return link_cmd; |
7a999bf0 TW |
427 | } |
428 | ||
fe6b23dd | 429 | /* |
57f8db89 | 430 | * iwl_add_bssid_station - Add the special IBSS BSSID station |
fe6b23dd RC |
431 | * |
432 | * Function sleeps. | |
433 | */ | |
a194e324 JB |
434 | int iwl_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
435 | const u8 *addr, bool init_rs, u8 *sta_id_r) | |
7a999bf0 | 436 | { |
fe6b23dd RC |
437 | int ret; |
438 | u8 sta_id; | |
d2e210ae RC |
439 | struct iwl_link_quality_cmd *link_cmd; |
440 | unsigned long flags; | |
7a999bf0 | 441 | |
96900c75 | 442 | if (sta_id_r) |
fd1af15d JB |
443 | *sta_id_r = IWL_INVALID_STATION; |
444 | ||
a194e324 | 445 | ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id); |
fe6b23dd RC |
446 | if (ret) { |
447 | IWL_ERR(priv, "Unable to add station %pM\n", addr); | |
448 | return ret; | |
7a999bf0 TW |
449 | } |
450 | ||
fd1af15d JB |
451 | if (sta_id_r) |
452 | *sta_id_r = sta_id; | |
453 | ||
d2e210ae RC |
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) { | |
fe6b23dd | 459 | /* Set up default rate scaling table in device's station table */ |
a6a0345c | 460 | link_cmd = iwl_sta_alloc_lq(priv, sta_id); |
d2e210ae RC |
461 | if (!link_cmd) { |
462 | IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n", | |
463 | addr); | |
464 | return -ENOMEM; | |
465 | } | |
a6a0345c JB |
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 | ||
d2e210ae RC |
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 | ||
fe6b23dd RC |
476 | return 0; |
477 | } | |
57f8db89 | 478 | EXPORT_SYMBOL(iwl_add_bssid_station); |
fe6b23dd RC |
479 | |
480 | /** | |
481 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station | |
482 | * | |
483 | * priv->sta_lock must be held | |
484 | */ | |
485 | static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id) | |
486 | { | |
487 | /* Ucode must be active and driver must be non active */ | |
d2e210ae RC |
488 | if ((priv->stations[sta_id].used & |
489 | (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != IWL_STA_UCODE_ACTIVE) | |
fe6b23dd RC |
490 | IWL_ERR(priv, "removed non active STA %u\n", sta_id); |
491 | ||
492 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; | |
493 | ||
494 | memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); | |
495 | IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id); | |
7a999bf0 TW |
496 | } |
497 | ||
fe6b23dd | 498 | static int iwl_send_remove_station(struct iwl_priv *priv, |
9c5ac091 | 499 | const u8 *addr, int sta_id) |
7a999bf0 | 500 | { |
2f301227 | 501 | struct iwl_rx_packet *pkt; |
7a999bf0 TW |
502 | int ret; |
503 | ||
fe6b23dd | 504 | unsigned long flags_spin; |
7a999bf0 TW |
505 | struct iwl_rem_sta_cmd rm_sta_cmd; |
506 | ||
507 | struct iwl_host_cmd cmd = { | |
508 | .id = REPLY_REMOVE_STA, | |
509 | .len = sizeof(struct iwl_rem_sta_cmd), | |
fe6b23dd | 510 | .flags = CMD_SYNC, |
7a999bf0 TW |
511 | .data = &rm_sta_cmd, |
512 | }; | |
513 | ||
514 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); | |
515 | rm_sta_cmd.num_sta = 1; | |
9c5ac091 | 516 | memcpy(&rm_sta_cmd.addr, addr, ETH_ALEN); |
fe6b23dd RC |
517 | |
518 | cmd.flags |= CMD_WANT_SKB; | |
7a999bf0 | 519 | |
7a999bf0 TW |
520 | ret = iwl_send_cmd(priv, &cmd); |
521 | ||
fe6b23dd | 522 | if (ret) |
7a999bf0 TW |
523 | return ret; |
524 | ||
2f301227 ZY |
525 | pkt = (struct iwl_rx_packet *)cmd.reply_page; |
526 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { | |
15b1687c | 527 | IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", |
2f301227 | 528 | pkt->hdr.flags); |
7a999bf0 TW |
529 | ret = -EIO; |
530 | } | |
531 | ||
532 | if (!ret) { | |
2f301227 | 533 | switch (pkt->u.rem_sta.status) { |
7a999bf0 | 534 | case REM_STA_SUCCESS_MSK: |
fe6b23dd | 535 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
9c5ac091 | 536 | iwl_sta_ucode_deactivate(priv, sta_id); |
fe6b23dd | 537 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
e1623446 | 538 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); |
7a999bf0 TW |
539 | break; |
540 | default: | |
541 | ret = -EIO; | |
15b1687c | 542 | IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); |
7a999bf0 TW |
543 | break; |
544 | } | |
545 | } | |
64a76b50 | 546 | iwl_free_pages(priv, cmd.reply_page); |
7a999bf0 TW |
547 | |
548 | return ret; | |
549 | } | |
be1f3ab6 | 550 | |
7a999bf0 TW |
551 | /** |
552 | * iwl_remove_station - Remove driver's knowledge of station. | |
7a999bf0 | 553 | */ |
fd1af15d JB |
554 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, |
555 | const u8 *addr) | |
7a999bf0 | 556 | { |
fd1af15d | 557 | unsigned long flags; |
fe6b23dd RC |
558 | |
559 | if (!iwl_is_ready(priv)) { | |
560 | IWL_DEBUG_INFO(priv, | |
91dd6c27 | 561 | "Unable to remove station %pM, device not ready.\n", |
c0222df8 | 562 | addr); |
fe6b23dd RC |
563 | /* |
564 | * It is typical for stations to be removed when we are | |
565 | * going down. Return success since device will be down | |
566 | * soon anyway | |
567 | */ | |
568 | return 0; | |
569 | } | |
7a999bf0 | 570 | |
fd1af15d JB |
571 | IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", |
572 | sta_id, addr); | |
7a999bf0 | 573 | |
fd1af15d JB |
574 | if (WARN_ON(sta_id == IWL_INVALID_STATION)) |
575 | return -EINVAL; | |
7a999bf0 | 576 | |
fd1af15d | 577 | spin_lock_irqsave(&priv->sta_lock, flags); |
24e5c401 EG |
578 | |
579 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | |
fe6b23dd | 580 | IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n", |
c0222df8 | 581 | addr); |
fd1af15d | 582 | goto out_err; |
24e5c401 EG |
583 | } |
584 | ||
585 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { | |
fe6b23dd | 586 | IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n", |
c0222df8 | 587 | addr); |
fd1af15d | 588 | goto out_err; |
7a999bf0 TW |
589 | } |
590 | ||
1fa61b2e JB |
591 | if (priv->stations[sta_id].used & IWL_STA_LOCAL) { |
592 | kfree(priv->stations[sta_id].lq); | |
593 | priv->stations[sta_id].lq = NULL; | |
594 | } | |
24e5c401 EG |
595 | |
596 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | |
597 | ||
598 | priv->num_stations--; | |
599 | ||
7a999bf0 | 600 | BUG_ON(priv->num_stations < 0); |
24e5c401 | 601 | |
7a999bf0 | 602 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
24e5c401 | 603 | |
9c5ac091 | 604 | return iwl_send_remove_station(priv, addr, sta_id); |
fd1af15d | 605 | out_err: |
7a999bf0 | 606 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
fd1af15d | 607 | return -EINVAL; |
7a999bf0 | 608 | } |
1fa61b2e | 609 | EXPORT_SYMBOL_GPL(iwl_remove_station); |
24e5c401 | 610 | |
83dde8c9 | 611 | /** |
2c810ccd JB |
612 | * iwl_clear_ucode_stations - clear ucode station table bits |
613 | * | |
614 | * This function clears all the bits in the driver indicating | |
615 | * which stations are active in the ucode. Call when something | |
616 | * other than explicit station management would cause this in | |
617 | * the ucode, e.g. unassociated RXON. | |
83dde8c9 | 618 | */ |
dcef732c JB |
619 | void iwl_clear_ucode_stations(struct iwl_priv *priv, |
620 | struct iwl_rxon_context *ctx) | |
83dde8c9 | 621 | { |
48676eb3 | 622 | int i; |
7e246191 RC |
623 | unsigned long flags_spin; |
624 | bool cleared = false; | |
625 | ||
2c810ccd | 626 | IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n"); |
83dde8c9 | 627 | |
7e246191 | 628 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
2c810ccd | 629 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
dcef732c JB |
630 | if (ctx && ctx->ctxid != priv->stations[i].ctxid) |
631 | continue; | |
632 | ||
2c810ccd JB |
633 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { |
634 | IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i); | |
635 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | |
636 | cleared = true; | |
7e246191 RC |
637 | } |
638 | } | |
639 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | |
640 | ||
641 | if (!cleared) | |
642 | IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n"); | |
643 | } | |
644 | EXPORT_SYMBOL(iwl_clear_ucode_stations); | |
83dde8c9 | 645 | |
7e246191 RC |
646 | /** |
647 | * iwl_restore_stations() - Restore driver known stations to device | |
648 | * | |
649 | * All stations considered active by driver, but not present in ucode, is | |
650 | * restored. | |
fe6b23dd RC |
651 | * |
652 | * Function sleeps. | |
7e246191 | 653 | */ |
dcef732c | 654 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
7e246191 | 655 | { |
9c5ac091 RC |
656 | struct iwl_addsta_cmd sta_cmd; |
657 | struct iwl_link_quality_cmd lq; | |
7e246191 RC |
658 | unsigned long flags_spin; |
659 | int i; | |
660 | bool found = false; | |
fe6b23dd | 661 | int ret; |
9c5ac091 | 662 | bool send_lq; |
83dde8c9 | 663 | |
7e246191 RC |
664 | if (!iwl_is_ready(priv)) { |
665 | IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n"); | |
666 | return; | |
667 | } | |
83dde8c9 | 668 | |
7e246191 RC |
669 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); |
670 | spin_lock_irqsave(&priv->sta_lock, flags_spin); | |
671 | for (i = 0; i < priv->hw_params.max_stations; i++) { | |
dcef732c JB |
672 | if (ctx->ctxid != priv->stations[i].ctxid) |
673 | continue; | |
7e246191 RC |
674 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && |
675 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { | |
676 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", | |
677 | priv->stations[i].sta.sta.addr); | |
678 | priv->stations[i].sta.mode = 0; | |
679 | priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS; | |
680 | found = true; | |
681 | } | |
682 | } | |
5e46882e | 683 | |
7e246191 RC |
684 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
685 | if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) { | |
9c5ac091 RC |
686 | memcpy(&sta_cmd, &priv->stations[i].sta, |
687 | sizeof(struct iwl_addsta_cmd)); | |
688 | send_lq = false; | |
689 | if (priv->stations[i].lq) { | |
690 | memcpy(&lq, priv->stations[i].lq, | |
691 | sizeof(struct iwl_link_quality_cmd)); | |
692 | send_lq = true; | |
693 | } | |
fe6b23dd | 694 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
9c5ac091 | 695 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
fe6b23dd | 696 | if (ret) { |
fe6b23dd | 697 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
9c5ac091 RC |
698 | IWL_ERR(priv, "Adding station %pM failed.\n", |
699 | priv->stations[i].sta.sta.addr); | |
fe6b23dd RC |
700 | priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE; |
701 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; | |
702 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | |
703 | } | |
704 | /* | |
705 | * Rate scaling has already been initialized, send | |
706 | * current LQ command | |
707 | */ | |
9c5ac091 RC |
708 | if (send_lq) |
709 | iwl_send_lq_cmd(priv, &lq, CMD_SYNC, true); | |
fe6b23dd | 710 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
7e246191 RC |
711 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; |
712 | } | |
48676eb3 MA |
713 | } |
714 | ||
7e246191 RC |
715 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
716 | if (!found) | |
717 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n"); | |
718 | else | |
fe6b23dd | 719 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n"); |
83dde8c9 | 720 | } |
7e246191 | 721 | EXPORT_SYMBOL(iwl_restore_stations); |
83dde8c9 | 722 | |
6e21f15c | 723 | int iwl_get_free_ucode_key_index(struct iwl_priv *priv) |
80fb47a1 EG |
724 | { |
725 | int i; | |
726 | ||
c10afb6e | 727 | for (i = 0; i < priv->sta_key_max_num; i++) |
77bab602 | 728 | if (!test_and_set_bit(i, &priv->ucode_key_table)) |
80fb47a1 EG |
729 | return i; |
730 | ||
40a9a829 | 731 | return WEP_INVALID_OFFSET; |
80fb47a1 | 732 | } |
6e21f15c | 733 | EXPORT_SYMBOL(iwl_get_free_ucode_key_index); |
6974e363 | 734 | |
c10afb6e JB |
735 | static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, |
736 | struct iwl_rxon_context *ctx, | |
737 | bool send_if_empty) | |
6974e363 EG |
738 | { |
739 | int i, not_empty = 0; | |
740 | u8 buff[sizeof(struct iwl_wep_cmd) + | |
741 | sizeof(struct iwl_wep_key) * WEP_KEYS_MAX]; | |
742 | struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; | |
743 | size_t cmd_size = sizeof(struct iwl_wep_cmd); | |
744 | struct iwl_host_cmd cmd = { | |
c10afb6e | 745 | .id = ctx->wep_key_cmd, |
6974e363 | 746 | .data = wep_cmd, |
72e15d71 | 747 | .flags = CMD_SYNC, |
6974e363 EG |
748 | }; |
749 | ||
72e15d71 JB |
750 | might_sleep(); |
751 | ||
6974e363 EG |
752 | memset(wep_cmd, 0, cmd_size + |
753 | (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); | |
754 | ||
755 | for (i = 0; i < WEP_KEYS_MAX ; i++) { | |
756 | wep_cmd->key[i].key_index = i; | |
c10afb6e | 757 | if (ctx->wep_keys[i].key_size) { |
6974e363 EG |
758 | wep_cmd->key[i].key_offset = i; |
759 | not_empty = 1; | |
760 | } else { | |
761 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; | |
762 | } | |
763 | ||
c10afb6e JB |
764 | wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size; |
765 | memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key, | |
766 | ctx->wep_keys[i].key_size); | |
6974e363 EG |
767 | } |
768 | ||
769 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; | |
770 | wep_cmd->num_keys = WEP_KEYS_MAX; | |
771 | ||
772 | cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX; | |
773 | ||
774 | cmd.len = cmd_size; | |
775 | ||
776 | if (not_empty || send_if_empty) | |
777 | return iwl_send_cmd(priv, &cmd); | |
778 | else | |
779 | return 0; | |
780 | } | |
335348b1 | 781 | |
c10afb6e JB |
782 | int iwl_restore_default_wep_keys(struct iwl_priv *priv, |
783 | struct iwl_rxon_context *ctx) | |
335348b1 | 784 | { |
a24d52f3 | 785 | lockdep_assert_held(&priv->mutex); |
335348b1 | 786 | |
c10afb6e | 787 | return iwl_send_static_wepkey_cmd(priv, ctx, false); |
335348b1 JB |
788 | } |
789 | EXPORT_SYMBOL(iwl_restore_default_wep_keys); | |
6974e363 EG |
790 | |
791 | int iwl_remove_default_wep_key(struct iwl_priv *priv, | |
c10afb6e | 792 | struct iwl_rxon_context *ctx, |
80fb47a1 | 793 | struct ieee80211_key_conf *keyconf) |
6974e363 EG |
794 | { |
795 | int ret; | |
6974e363 | 796 | |
a24d52f3 | 797 | lockdep_assert_held(&priv->mutex); |
72e15d71 | 798 | |
2d1bb9e5 RC |
799 | IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", |
800 | keyconf->keyidx); | |
80fb47a1 | 801 | |
c10afb6e | 802 | memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0])); |
2d1bb9e5 RC |
803 | if (iwl_is_rfkill(priv)) { |
804 | IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n"); | |
72e15d71 | 805 | /* but keys in device are clear anyway so return success */ |
2d1bb9e5 RC |
806 | return 0; |
807 | } | |
c10afb6e | 808 | ret = iwl_send_static_wepkey_cmd(priv, ctx, 1); |
e1623446 | 809 | IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", |
4564ce8b | 810 | keyconf->keyidx, ret); |
6974e363 EG |
811 | |
812 | return ret; | |
813 | } | |
27aaba0c | 814 | EXPORT_SYMBOL(iwl_remove_default_wep_key); |
6974e363 EG |
815 | |
816 | int iwl_set_default_wep_key(struct iwl_priv *priv, | |
2995bafa | 817 | struct iwl_rxon_context *ctx, |
6974e363 EG |
818 | struct ieee80211_key_conf *keyconf) |
819 | { | |
820 | int ret; | |
72e15d71 | 821 | |
a24d52f3 | 822 | lockdep_assert_held(&priv->mutex); |
6974e363 | 823 | |
4564ce8b EG |
824 | if (keyconf->keylen != WEP_KEY_LEN_128 && |
825 | keyconf->keylen != WEP_KEY_LEN_64) { | |
e1623446 | 826 | IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen); |
4564ce8b EG |
827 | return -EINVAL; |
828 | } | |
829 | ||
6974e363 | 830 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
ccc038ab | 831 | keyconf->hw_key_idx = HW_KEY_DEFAULT; |
2995bafa | 832 | priv->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher; |
6974e363 | 833 | |
c10afb6e JB |
834 | ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; |
835 | memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key, | |
6974e363 EG |
836 | keyconf->keylen); |
837 | ||
c10afb6e | 838 | ret = iwl_send_static_wepkey_cmd(priv, ctx, false); |
e1623446 | 839 | IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", |
4564ce8b | 840 | keyconf->keylen, keyconf->keyidx, ret); |
6974e363 EG |
841 | |
842 | return ret; | |
843 | } | |
27aaba0c | 844 | EXPORT_SYMBOL(iwl_set_default_wep_key); |
6974e363 | 845 | |
7480513f | 846 | static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv, |
a194e324 JB |
847 | struct iwl_rxon_context *ctx, |
848 | struct ieee80211_key_conf *keyconf, | |
849 | u8 sta_id) | |
0211ddda EG |
850 | { |
851 | unsigned long flags; | |
852 | __le16 key_flags = 0; | |
e666674e JB |
853 | struct iwl_addsta_cmd sta_cmd; |
854 | ||
855 | lockdep_assert_held(&priv->mutex); | |
0211ddda EG |
856 | |
857 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; | |
0211ddda EG |
858 | |
859 | key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK); | |
860 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); | |
861 | key_flags &= ~STA_KEY_FLG_INVALID; | |
862 | ||
863 | if (keyconf->keylen == WEP_KEY_LEN_128) | |
864 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; | |
865 | ||
a194e324 | 866 | if (sta_id == ctx->bcast_sta_id) |
0211ddda EG |
867 | key_flags |= STA_KEY_MULTICAST_MSK; |
868 | ||
869 | spin_lock_irqsave(&priv->sta_lock, flags); | |
870 | ||
97359d12 | 871 | priv->stations[sta_id].keyinfo.cipher = keyconf->cipher; |
0211ddda EG |
872 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
873 | priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; | |
874 | ||
875 | memcpy(priv->stations[sta_id].keyinfo.key, | |
876 | keyconf->key, keyconf->keylen); | |
877 | ||
878 | memcpy(&priv->stations[sta_id].sta.key.key[3], | |
879 | keyconf->key, keyconf->keylen); | |
880 | ||
3ec47732 EG |
881 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
882 | == STA_KEY_FLG_NO_ENC) | |
883 | priv->stations[sta_id].sta.key.key_offset = | |
80fb47a1 | 884 | iwl_get_free_ucode_key_index(priv); |
3ec47732 EG |
885 | /* else, we are overriding an existing key => no need to allocated room |
886 | * in uCode. */ | |
0211ddda | 887 | |
40a9a829 | 888 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
e724b8fe | 889 | "no space for a new key"); |
40a9a829 | 890 | |
3ec47732 | 891 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
0211ddda EG |
892 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
893 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | |
894 | ||
e666674e | 895 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
0211ddda EG |
896 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
897 | ||
e666674e | 898 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
0211ddda | 899 | } |
7480513f EG |
900 | |
901 | static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv, | |
a194e324 JB |
902 | struct iwl_rxon_context *ctx, |
903 | struct ieee80211_key_conf *keyconf, | |
904 | u8 sta_id) | |
7480513f EG |
905 | { |
906 | unsigned long flags; | |
907 | __le16 key_flags = 0; | |
e666674e JB |
908 | struct iwl_addsta_cmd sta_cmd; |
909 | ||
910 | lockdep_assert_held(&priv->mutex); | |
7480513f EG |
911 | |
912 | key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); | |
913 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); | |
914 | key_flags &= ~STA_KEY_FLG_INVALID; | |
915 | ||
a194e324 | 916 | if (sta_id == ctx->bcast_sta_id) |
7480513f EG |
917 | key_flags |= STA_KEY_MULTICAST_MSK; |
918 | ||
919 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
7480513f EG |
920 | |
921 | spin_lock_irqsave(&priv->sta_lock, flags); | |
97359d12 | 922 | priv->stations[sta_id].keyinfo.cipher = keyconf->cipher; |
7480513f EG |
923 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
924 | ||
925 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, | |
926 | keyconf->keylen); | |
927 | ||
928 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, | |
929 | keyconf->keylen); | |
930 | ||
3ec47732 EG |
931 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
932 | == STA_KEY_FLG_NO_ENC) | |
933 | priv->stations[sta_id].sta.key.key_offset = | |
934 | iwl_get_free_ucode_key_index(priv); | |
935 | /* else, we are overriding an existing key => no need to allocated room | |
936 | * in uCode. */ | |
937 | ||
40a9a829 | 938 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
e724b8fe | 939 | "no space for a new key"); |
40a9a829 | 940 | |
7480513f EG |
941 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
942 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; | |
943 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | |
944 | ||
e666674e | 945 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
7480513f EG |
946 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
947 | ||
e666674e | 948 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
7480513f EG |
949 | } |
950 | ||
951 | static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv, | |
a194e324 JB |
952 | struct iwl_rxon_context *ctx, |
953 | struct ieee80211_key_conf *keyconf, | |
954 | u8 sta_id) | |
7480513f EG |
955 | { |
956 | unsigned long flags; | |
957 | int ret = 0; | |
299f5462 RC |
958 | __le16 key_flags = 0; |
959 | ||
960 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); | |
961 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); | |
962 | key_flags &= ~STA_KEY_FLG_INVALID; | |
963 | ||
a194e324 | 964 | if (sta_id == ctx->bcast_sta_id) |
299f5462 | 965 | key_flags |= STA_KEY_MULTICAST_MSK; |
7480513f EG |
966 | |
967 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
968 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | |
7480513f EG |
969 | |
970 | spin_lock_irqsave(&priv->sta_lock, flags); | |
971 | ||
97359d12 | 972 | priv->stations[sta_id].keyinfo.cipher = keyconf->cipher; |
7480513f | 973 | priv->stations[sta_id].keyinfo.keylen = 16; |
3ec47732 EG |
974 | |
975 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) | |
976 | == STA_KEY_FLG_NO_ENC) | |
977 | priv->stations[sta_id].sta.key.key_offset = | |
77bab602 | 978 | iwl_get_free_ucode_key_index(priv); |
3ec47732 EG |
979 | /* else, we are overriding an existing key => no need to allocated room |
980 | * in uCode. */ | |
7480513f | 981 | |
40a9a829 | 982 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
e724b8fe | 983 | "no space for a new key"); |
40a9a829 | 984 | |
299f5462 RC |
985 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
986 | ||
987 | ||
7480513f EG |
988 | /* This copy is acutally not needed: we get the key with each TX */ |
989 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16); | |
990 | ||
991 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16); | |
992 | ||
993 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
994 | ||
995 | return ret; | |
996 | } | |
997 | ||
9f58671e | 998 | void iwl_update_tkip_key(struct iwl_priv *priv, |
a194e324 JB |
999 | struct iwl_rxon_context *ctx, |
1000 | struct ieee80211_key_conf *keyconf, | |
1001 | struct ieee80211_sta *sta, u32 iv32, u16 *phase1key) | |
9f58671e | 1002 | { |
bdbb612f | 1003 | u8 sta_id; |
9f58671e | 1004 | unsigned long flags; |
9f58671e | 1005 | int i; |
9f58671e | 1006 | |
9f58671e TW |
1007 | if (iwl_scan_cancel(priv)) { |
1008 | /* cancel scan failed, just live w/ bad key and rely | |
1009 | briefly on SW decryption */ | |
1010 | return; | |
1011 | } | |
1012 | ||
a194e324 | 1013 | sta_id = iwl_sta_id_or_broadcast(priv, ctx, sta); |
0af8bcae JB |
1014 | if (sta_id == IWL_INVALID_STATION) |
1015 | return; | |
1016 | ||
9f58671e TW |
1017 | spin_lock_irqsave(&priv->sta_lock, flags); |
1018 | ||
9f58671e TW |
1019 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
1020 | ||
1021 | for (i = 0; i < 5; i++) | |
1022 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = | |
1023 | cpu_to_le16(phase1key[i]); | |
1024 | ||
1025 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; | |
1026 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | |
1027 | ||
1028 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); | |
1029 | ||
1030 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
1031 | ||
1032 | } | |
1033 | EXPORT_SYMBOL(iwl_update_tkip_key); | |
1034 | ||
3ec47732 | 1035 | int iwl_remove_dynamic_key(struct iwl_priv *priv, |
c10afb6e JB |
1036 | struct iwl_rxon_context *ctx, |
1037 | struct ieee80211_key_conf *keyconf, | |
1038 | u8 sta_id) | |
7480513f EG |
1039 | { |
1040 | unsigned long flags; | |
3ec47732 EG |
1041 | u16 key_flags; |
1042 | u8 keyidx; | |
e666674e JB |
1043 | struct iwl_addsta_cmd sta_cmd; |
1044 | ||
1045 | lockdep_assert_held(&priv->mutex); | |
7480513f | 1046 | |
c10afb6e | 1047 | ctx->key_mapping_keys--; |
7480513f EG |
1048 | |
1049 | spin_lock_irqsave(&priv->sta_lock, flags); | |
3ec47732 EG |
1050 | key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); |
1051 | keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3; | |
1052 | ||
e1623446 | 1053 | IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n", |
4564ce8b EG |
1054 | keyconf->keyidx, sta_id); |
1055 | ||
3ec47732 EG |
1056 | if (keyconf->keyidx != keyidx) { |
1057 | /* We need to remove a key with index different that the one | |
1058 | * in the uCode. This means that the key we need to remove has | |
1059 | * been replaced by another one with different index. | |
1060 | * Don't do anything and return ok | |
1061 | */ | |
1062 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
1063 | return 0; | |
1064 | } | |
1065 | ||
40a9a829 | 1066 | if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) { |
39aadf8c | 1067 | IWL_WARN(priv, "Removing wrong key %d 0x%x\n", |
40a9a829 TW |
1068 | keyconf->keyidx, key_flags); |
1069 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
1070 | return 0; | |
1071 | } | |
1072 | ||
7480513f EG |
1073 | if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset, |
1074 | &priv->ucode_key_table)) | |
15b1687c | 1075 | IWL_ERR(priv, "index %d not used in uCode key table.\n", |
7480513f EG |
1076 | priv->stations[sta_id].sta.key.key_offset); |
1077 | memset(&priv->stations[sta_id].keyinfo, 0, | |
6def9761 | 1078 | sizeof(struct iwl_hw_key)); |
7480513f EG |
1079 | memset(&priv->stations[sta_id].sta.key, 0, |
1080 | sizeof(struct iwl4965_keyinfo)); | |
3ec47732 EG |
1081 | priv->stations[sta_id].sta.key.key_flags = |
1082 | STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID; | |
1083 | priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET; | |
7480513f EG |
1084 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
1085 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | |
7480513f | 1086 | |
2d1bb9e5 | 1087 | if (iwl_is_rfkill(priv)) { |
91dd6c27 | 1088 | IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n"); |
2d1bb9e5 RC |
1089 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
1090 | return 0; | |
1091 | } | |
e666674e | 1092 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
3ec47732 | 1093 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
e666674e JB |
1094 | |
1095 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | |
7480513f | 1096 | } |
27aaba0c | 1097 | EXPORT_SYMBOL(iwl_remove_dynamic_key); |
7480513f | 1098 | |
a194e324 JB |
1099 | int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
1100 | struct ieee80211_key_conf *keyconf, u8 sta_id) | |
7480513f EG |
1101 | { |
1102 | int ret; | |
1103 | ||
e666674e JB |
1104 | lockdep_assert_held(&priv->mutex); |
1105 | ||
c10afb6e | 1106 | ctx->key_mapping_keys++; |
ccc038ab | 1107 | keyconf->hw_key_idx = HW_KEY_DYNAMIC; |
7480513f | 1108 | |
97359d12 JB |
1109 | switch (keyconf->cipher) { |
1110 | case WLAN_CIPHER_SUITE_CCMP: | |
a194e324 | 1111 | ret = iwl_set_ccmp_dynamic_key_info(priv, ctx, keyconf, sta_id); |
7480513f | 1112 | break; |
97359d12 | 1113 | case WLAN_CIPHER_SUITE_TKIP: |
a194e324 | 1114 | ret = iwl_set_tkip_dynamic_key_info(priv, ctx, keyconf, sta_id); |
7480513f | 1115 | break; |
97359d12 JB |
1116 | case WLAN_CIPHER_SUITE_WEP40: |
1117 | case WLAN_CIPHER_SUITE_WEP104: | |
a194e324 | 1118 | ret = iwl_set_wep_dynamic_key_info(priv, ctx, keyconf, sta_id); |
7480513f EG |
1119 | break; |
1120 | default: | |
15b1687c | 1121 | IWL_ERR(priv, |
97359d12 JB |
1122 | "Unknown alg: %s cipher = %x\n", __func__, |
1123 | keyconf->cipher); | |
7480513f EG |
1124 | ret = -EINVAL; |
1125 | } | |
1126 | ||
97359d12 JB |
1127 | IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n", |
1128 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, | |
4564ce8b EG |
1129 | sta_id, ret); |
1130 | ||
7480513f EG |
1131 | return ret; |
1132 | } | |
27aaba0c | 1133 | EXPORT_SYMBOL(iwl_set_dynamic_key); |
7480513f | 1134 | |
66c73db7 TW |
1135 | #ifdef CONFIG_IWLWIFI_DEBUG |
1136 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, | |
1137 | struct iwl_link_quality_cmd *lq) | |
1138 | { | |
1139 | int i; | |
e1623446 TW |
1140 | IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id); |
1141 | IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n", | |
66c73db7 TW |
1142 | lq->general_params.single_stream_ant_msk, |
1143 | lq->general_params.dual_stream_ant_msk); | |
1144 | ||
1145 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) | |
e1623446 | 1146 | IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n", |
66c73db7 TW |
1147 | i, lq->rs_table[i].rate_n_flags); |
1148 | } | |
1149 | #else | |
1150 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, | |
1151 | struct iwl_link_quality_cmd *lq) | |
1152 | { | |
1153 | } | |
1154 | #endif | |
1155 | ||
3bce6066 RC |
1156 | /** |
1157 | * is_lq_table_valid() - Test one aspect of LQ cmd for validity | |
1158 | * | |
1159 | * It sometimes happens when a HT rate has been in use and we | |
1160 | * loose connectivity with AP then mac80211 will first tell us that the | |
1161 | * current channel is not HT anymore before removing the station. In such a | |
1162 | * scenario the RXON flags will be updated to indicate we are not | |
1163 | * communicating HT anymore, but the LQ command may still contain HT rates. | |
1164 | * Test for this to prevent driver from sending LQ command between the time | |
1165 | * RXON flags are updated and when LQ command is updated. | |
1166 | */ | |
1167 | static bool is_lq_table_valid(struct iwl_priv *priv, | |
1168 | struct iwl_link_quality_cmd *lq) | |
1169 | { | |
1170 | int i; | |
1171 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; | |
246ed355 JB |
1172 | #if !TODO |
1173 | struct iwl_rxon_context *ctx = | |
1174 | &priv->contexts[IWL_RXON_CTX_BSS]; | |
1175 | #endif | |
3bce6066 RC |
1176 | |
1177 | if (ht_conf->is_ht) | |
1178 | return true; | |
1179 | ||
1180 | IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", | |
246ed355 | 1181 | ctx->active.channel); |
3bce6066 RC |
1182 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
1183 | if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) { | |
1184 | IWL_DEBUG_INFO(priv, | |
1185 | "index %d of LQ expects HT channel\n", | |
1186 | i); | |
1187 | return false; | |
1188 | } | |
1189 | } | |
1190 | return true; | |
1191 | } | |
1192 | ||
fe6b23dd RC |
1193 | /** |
1194 | * iwl_send_lq_cmd() - Send link quality command | |
1195 | * @init: This command is sent as part of station initialization right | |
1196 | * after station has been added. | |
1197 | * | |
1198 | * The link quality command is sent as the last step of station creation. | |
1199 | * This is the special case in which init is set and we call a callback in | |
1200 | * this case to clear the state indicating that station creation is in | |
1201 | * progress. | |
1202 | */ | |
66c73db7 | 1203 | int iwl_send_lq_cmd(struct iwl_priv *priv, |
fe6b23dd | 1204 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) |
66c73db7 | 1205 | { |
fe6b23dd RC |
1206 | int ret = 0; |
1207 | unsigned long flags_spin; | |
1208 | ||
66c73db7 TW |
1209 | struct iwl_host_cmd cmd = { |
1210 | .id = REPLY_TX_LINK_QUALITY_CMD, | |
1211 | .len = sizeof(struct iwl_link_quality_cmd), | |
c2acea8e | 1212 | .flags = flags, |
66c73db7 TW |
1213 | .data = lq, |
1214 | }; | |
1215 | ||
76c3c698 | 1216 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) |
66c73db7 TW |
1217 | return -EINVAL; |
1218 | ||
3ac7f146 | 1219 | iwl_dump_lq_cmd(priv, lq); |
fe6b23dd | 1220 | BUG_ON(init && (cmd.flags & CMD_ASYNC)); |
66c73db7 | 1221 | |
3bce6066 RC |
1222 | if (is_lq_table_valid(priv, lq)) |
1223 | ret = iwl_send_cmd(priv, &cmd); | |
1224 | else | |
1225 | ret = -EINVAL; | |
d2e210ae RC |
1226 | |
1227 | if (cmd.flags & CMD_ASYNC) | |
fe6b23dd | 1228 | return ret; |
66c73db7 | 1229 | |
fe6b23dd | 1230 | if (init) { |
91dd6c27 | 1231 | IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n", |
fe6b23dd RC |
1232 | lq->sta_id); |
1233 | spin_lock_irqsave(&priv->sta_lock, flags_spin); | |
1234 | priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; | |
1235 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); | |
1236 | } | |
d2e210ae | 1237 | return ret; |
66c73db7 TW |
1238 | } |
1239 | EXPORT_SYMBOL(iwl_send_lq_cmd); | |
1240 | ||
9a9ca65f | 1241 | /** |
2c810ccd JB |
1242 | * iwl_alloc_bcast_station - add broadcast station into driver's station table. |
1243 | * | |
1244 | * This adds the broadcast station into the driver's station table | |
1245 | * and marks it driver active, so that it will be restored to the | |
1246 | * device at the next best time. | |
9a9ca65f | 1247 | */ |
a194e324 JB |
1248 | int iwl_alloc_bcast_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
1249 | bool init_lq) | |
9a9ca65f | 1250 | { |
2c810ccd JB |
1251 | struct iwl_link_quality_cmd *link_cmd; |
1252 | unsigned long flags; | |
1253 | u8 sta_id; | |
1254 | ||
1255 | spin_lock_irqsave(&priv->sta_lock, flags); | |
a194e324 | 1256 | sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL); |
2c810ccd JB |
1257 | if (sta_id == IWL_INVALID_STATION) { |
1258 | IWL_ERR(priv, "Unable to prepare broadcast station\n"); | |
1259 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
1260 | ||
1261 | return -EINVAL; | |
1262 | } | |
1263 | ||
1264 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; | |
1265 | priv->stations[sta_id].used |= IWL_STA_BCAST; | |
1266 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
1267 | ||
1268 | if (init_lq) { | |
1269 | link_cmd = iwl_sta_alloc_lq(priv, sta_id); | |
1270 | if (!link_cmd) { | |
1271 | IWL_ERR(priv, | |
1272 | "Unable to initialize rate scaling for bcast station.\n"); | |
1273 | return -ENOMEM; | |
1274 | } | |
1275 | ||
1276 | spin_lock_irqsave(&priv->sta_lock, flags); | |
1277 | priv->stations[sta_id].lq = link_cmd; | |
1278 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
1279 | } | |
1280 | ||
1281 | return 0; | |
9a9ca65f | 1282 | } |
2c810ccd | 1283 | EXPORT_SYMBOL_GPL(iwl_alloc_bcast_station); |
9a9ca65f | 1284 | |
278c2f6f DH |
1285 | /** |
1286 | * iwl_update_bcast_station - update broadcast station's LQ command | |
1287 | * | |
1288 | * Only used by iwlagn. Placed here to have all bcast station management | |
1289 | * code together. | |
1290 | */ | |
a194e324 JB |
1291 | static int iwl_update_bcast_station(struct iwl_priv *priv, |
1292 | struct iwl_rxon_context *ctx) | |
278c2f6f DH |
1293 | { |
1294 | unsigned long flags; | |
1295 | struct iwl_link_quality_cmd *link_cmd; | |
a194e324 | 1296 | u8 sta_id = ctx->bcast_sta_id; |
278c2f6f DH |
1297 | |
1298 | link_cmd = iwl_sta_alloc_lq(priv, sta_id); | |
1299 | if (!link_cmd) { | |
1300 | IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n"); | |
1301 | return -ENOMEM; | |
1302 | } | |
1303 | ||
1304 | spin_lock_irqsave(&priv->sta_lock, flags); | |
1305 | if (priv->stations[sta_id].lq) | |
1306 | kfree(priv->stations[sta_id].lq); | |
1307 | else | |
1308 | IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n"); | |
1309 | priv->stations[sta_id].lq = link_cmd; | |
1310 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
1311 | ||
1312 | return 0; | |
1313 | } | |
278c2f6f | 1314 | |
a194e324 JB |
1315 | int iwl_update_bcast_stations(struct iwl_priv *priv) |
1316 | { | |
1317 | struct iwl_rxon_context *ctx; | |
1318 | int ret = 0; | |
1319 | ||
1320 | for_each_context(priv, ctx) { | |
1321 | ret = iwl_update_bcast_station(priv, ctx); | |
1322 | if (ret) | |
1323 | break; | |
1324 | } | |
1325 | ||
1326 | return ret; | |
1327 | } | |
1328 | EXPORT_SYMBOL_GPL(iwl_update_bcast_stations); | |
1329 | ||
1330 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv) | |
3459ab5a | 1331 | { |
2c810ccd JB |
1332 | unsigned long flags; |
1333 | int i; | |
fe6b23dd | 1334 | |
2c810ccd JB |
1335 | spin_lock_irqsave(&priv->sta_lock, flags); |
1336 | for (i = 0; i < priv->hw_params.max_stations; i++) { | |
1337 | if (!(priv->stations[i].used & IWL_STA_BCAST)) | |
1338 | continue; | |
1339 | ||
1340 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | |
1341 | priv->num_stations--; | |
1342 | BUG_ON(priv->num_stations < 0); | |
1343 | kfree(priv->stations[i].lq); | |
1344 | priv->stations[i].lq = NULL; | |
1345 | } | |
1346 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
3459ab5a | 1347 | } |
a194e324 | 1348 | EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_stations); |
3459ab5a | 1349 | |
5083e563 | 1350 | /** |
9f58671e | 1351 | * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table |
5083e563 | 1352 | */ |
4620fefa | 1353 | int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid) |
5083e563 TW |
1354 | { |
1355 | unsigned long flags; | |
4620fefa JB |
1356 | struct iwl_addsta_cmd sta_cmd; |
1357 | ||
1358 | lockdep_assert_held(&priv->mutex); | |
5083e563 TW |
1359 | |
1360 | /* Remove "disable" flag, to enable Tx for this TID */ | |
1361 | spin_lock_irqsave(&priv->sta_lock, flags); | |
1362 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; | |
1363 | priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); | |
1364 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | |
4620fefa | 1365 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
9c5ac091 | 1366 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
4620fefa JB |
1367 | |
1368 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | |
5083e563 | 1369 | } |
9f58671e TW |
1370 | EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid); |
1371 | ||
619753ff JB |
1372 | int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta, |
1373 | int tid, u16 ssn) | |
9f58671e TW |
1374 | { |
1375 | unsigned long flags; | |
1376 | int sta_id; | |
4620fefa JB |
1377 | struct iwl_addsta_cmd sta_cmd; |
1378 | ||
1379 | lockdep_assert_held(&priv->mutex); | |
9f58671e | 1380 | |
619753ff | 1381 | sta_id = iwl_sta_id(sta); |
9f58671e TW |
1382 | if (sta_id == IWL_INVALID_STATION) |
1383 | return -ENXIO; | |
1384 | ||
1385 | spin_lock_irqsave(&priv->sta_lock, flags); | |
1386 | priv->stations[sta_id].sta.station_flags_msk = 0; | |
1387 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; | |
1388 | priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid; | |
1389 | priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); | |
1390 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | |
4620fefa | 1391 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
9f58671e TW |
1392 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
1393 | ||
4620fefa | 1394 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
9f58671e TW |
1395 | } |
1396 | EXPORT_SYMBOL(iwl_sta_rx_agg_start); | |
1397 | ||
619753ff JB |
1398 | int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta, |
1399 | int tid) | |
9f58671e TW |
1400 | { |
1401 | unsigned long flags; | |
4620fefa JB |
1402 | int sta_id; |
1403 | struct iwl_addsta_cmd sta_cmd; | |
1404 | ||
1405 | lockdep_assert_held(&priv->mutex); | |
9f58671e | 1406 | |
619753ff | 1407 | sta_id = iwl_sta_id(sta); |
a2f1cbeb WYG |
1408 | if (sta_id == IWL_INVALID_STATION) { |
1409 | IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); | |
9f58671e | 1410 | return -ENXIO; |
a2f1cbeb | 1411 | } |
9f58671e TW |
1412 | |
1413 | spin_lock_irqsave(&priv->sta_lock, flags); | |
1414 | priv->stations[sta_id].sta.station_flags_msk = 0; | |
1415 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; | |
1416 | priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid; | |
1417 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | |
4620fefa | 1418 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
9f58671e TW |
1419 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
1420 | ||
4620fefa | 1421 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
9f58671e TW |
1422 | } |
1423 | EXPORT_SYMBOL(iwl_sta_rx_agg_stop); | |
1424 | ||
6ab10ff8 | 1425 | void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) |
9f58671e TW |
1426 | { |
1427 | unsigned long flags; | |
1428 | ||
1429 | spin_lock_irqsave(&priv->sta_lock, flags); | |
1430 | priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK; | |
1431 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; | |
1432 | priv->stations[sta_id].sta.sta.modify_mask = 0; | |
6ab10ff8 | 1433 | priv->stations[sta_id].sta.sleep_tx_count = 0; |
9f58671e | 1434 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
9c5ac091 | 1435 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
9f58671e TW |
1436 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
1437 | ||
9f58671e | 1438 | } |
6ab10ff8 | 1439 | EXPORT_SYMBOL(iwl_sta_modify_ps_wake); |
9f58671e | 1440 | |
6ab10ff8 | 1441 | void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt) |
9f58671e | 1442 | { |
6ab10ff8 | 1443 | unsigned long flags; |
9f58671e | 1444 | |
6ab10ff8 JB |
1445 | spin_lock_irqsave(&priv->sta_lock, flags); |
1446 | priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK; | |
1447 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; | |
1448 | priv->stations[sta_id].sta.sta.modify_mask = | |
1449 | STA_MODIFY_SLEEP_TX_COUNT_MSK; | |
1450 | priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt); | |
1451 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | |
9c5ac091 | 1452 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
6ab10ff8 | 1453 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
9f58671e | 1454 | |
9f58671e | 1455 | } |
74bcdb33 | 1456 | EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count); |
fe6b23dd RC |
1457 | |
1458 | int iwl_mac_sta_remove(struct ieee80211_hw *hw, | |
fd1af15d JB |
1459 | struct ieee80211_vif *vif, |
1460 | struct ieee80211_sta *sta) | |
fe6b23dd | 1461 | { |
fe6b23dd | 1462 | struct iwl_priv *priv = hw->priv; |
fd1af15d JB |
1463 | struct iwl_station_priv_common *sta_common = (void *)sta->drv_priv; |
1464 | int ret; | |
1465 | ||
fe6b23dd RC |
1466 | IWL_DEBUG_INFO(priv, "received request to remove station %pM\n", |
1467 | sta->addr); | |
da5ae1cf RC |
1468 | mutex_lock(&priv->mutex); |
1469 | IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", | |
1470 | sta->addr); | |
fd1af15d | 1471 | ret = iwl_remove_station(priv, sta_common->sta_id, sta->addr); |
fe6b23dd RC |
1472 | if (ret) |
1473 | IWL_ERR(priv, "Error removing station %pM\n", | |
1474 | sta->addr); | |
da5ae1cf | 1475 | mutex_unlock(&priv->mutex); |
fe6b23dd RC |
1476 | return ret; |
1477 | } | |
1478 | EXPORT_SYMBOL(iwl_mac_sta_remove); |