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