blob: 17e76ac4179cd831b03d04d0f696c8f4e861f7e4 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/* Copyright (C) 2006, Red Hat, Inc. */
2
John W. Linville7e272fc2008-09-24 18:13:14 -04003#include <linux/types.h>
Dan Williams3cf20932007-05-25 17:28:30 -04004#include <linux/etherdevice.h>
Johannes Berg2c7060022008-10-30 22:09:54 +01005#include <linux/ieee80211.h>
6#include <linux/if_arp.h>
John W. Linville7e272fc2008-09-24 18:13:14 -04007#include <net/lib80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02008
9#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010#include "decl.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020011#include "host.h"
Holger Schurig245bf202008-04-02 16:27:42 +020012#include "scan.h"
Dan Williams2dd4b262007-12-11 16:54:15 -050013#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020014
Ihar Hrachyshka5a6e0432008-01-25 14:15:00 +010015static const u8 bssid_any[ETH_ALEN] __attribute__ ((aligned (2))) =
16 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
17static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) =
18 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019
Dan Williamsbe0d76e2009-05-22 20:05:25 -040020/* The firmware needs the following bits masked out of the beacon-derived
21 * capability field when associating/joining to a BSS:
22 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
Holger Schurig697900a2008-04-02 16:27:10 +020023 */
24#define CAPINFO_MASK (~(0xda00))
25
Holger Schurig2d465022009-10-22 15:30:48 +020026/**
27 * 802.11b/g supported bitrates (in 500Kb/s units)
28 */
29u8 lbs_bg_rates[MAX_RATES] =
30 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
310x00, 0x00 };
32
Holger Schurig697900a2008-04-02 16:27:10 +020033
Dan Williamsf5fe1fd2008-08-21 21:46:59 -040034/**
35 * @brief This function finds common rates between rates and card rates.
36 *
37 * It will fill common rates in rates as output if found.
38 *
39 * NOTE: Setting the MSB of the basic rates need to be taken
40 * care, either before or after calling this function
41 *
42 * @param priv A pointer to struct lbs_private structure
43 * @param rates the buffer which keeps input and output
Dan Williamsca4fe302009-08-21 09:35:20 -050044 * @param rates_size the size of rates buffer; new size of buffer on return,
45 * which will be less than or equal to original rates_size
Dan Williamsf5fe1fd2008-08-21 21:46:59 -040046 *
47 * @return 0 on success, or -1 on error
48 */
49static int get_common_rates(struct lbs_private *priv,
50 u8 *rates,
51 u16 *rates_size)
52{
Roel Kluin1e3d31c2009-08-02 09:44:12 +020053 int i, j;
Dan Williamsca4fe302009-08-21 09:35:20 -050054 u8 intersection[MAX_RATES];
55 u16 intersection_size;
56 u16 num_rates = 0;
Dan Williamsf5fe1fd2008-08-21 21:46:59 -040057
Dan Williamsca4fe302009-08-21 09:35:20 -050058 intersection_size = min_t(u16, *rates_size, ARRAY_SIZE(intersection));
Andrey Yurovsky6f632d52009-08-13 17:34:40 -070059
Dan Williamsca4fe302009-08-21 09:35:20 -050060 /* Allow each rate from 'rates' that is supported by the hardware */
61 for (i = 0; i < ARRAY_SIZE(lbs_bg_rates) && lbs_bg_rates[i]; i++) {
62 for (j = 0; j < intersection_size && rates[j]; j++) {
63 if (rates[j] == lbs_bg_rates[i])
64 intersection[num_rates++] = rates[j];
Dan Williamsf5fe1fd2008-08-21 21:46:59 -040065 }
66 }
67
68 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size);
Dan Williamsca4fe302009-08-21 09:35:20 -050069 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", lbs_bg_rates,
70 ARRAY_SIZE(lbs_bg_rates));
71 lbs_deb_hex(LBS_DEB_JOIN, "common rates", intersection, num_rates);
Dan Williamsf5fe1fd2008-08-21 21:46:59 -040072 lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate);
73
74 if (!priv->enablehwauto) {
Dan Williamsca4fe302009-08-21 09:35:20 -050075 for (i = 0; i < num_rates; i++) {
76 if (intersection[i] == priv->cur_rate)
77 goto done;
Dan Williamsf5fe1fd2008-08-21 21:46:59 -040078 }
Dan Williamsca4fe302009-08-21 09:35:20 -050079 lbs_pr_alert("Previously set fixed data rate %#x isn't "
80 "compatible with the network.\n", priv->cur_rate);
81 return -1;
Dan Williamsf5fe1fd2008-08-21 21:46:59 -040082 }
Dan Williamsca4fe302009-08-21 09:35:20 -050083
84done:
85 memset(rates, 0, *rates_size);
86 *rates_size = num_rates;
87 memcpy(rates, intersection, num_rates);
Roel Kluin1e3d31c2009-08-02 09:44:12 +020088 return 0;
Dan Williamsf5fe1fd2008-08-21 21:46:59 -040089}
90
91
92/**
93 * @brief Sets the MSB on basic rates as the firmware requires
94 *
95 * Scan through an array and set the MSB for basic data rates.
96 *
97 * @param rates buffer of data rates
98 * @param len size of buffer
99 */
100static void lbs_set_basic_rate_flags(u8 *rates, size_t len)
101{
102 int i;
103
104 for (i = 0; i < len; i++) {
105 if (rates[i] == 0x02 || rates[i] == 0x04 ||
106 rates[i] == 0x0b || rates[i] == 0x16)
107 rates[i] |= 0x80;
108 }
109}
110
Holger Schurig697900a2008-04-02 16:27:10 +0200111
Dan Williamsbe0d76e2009-05-22 20:05:25 -0400112static u8 iw_auth_to_ieee_auth(u8 auth)
113{
114 if (auth == IW_AUTH_ALG_OPEN_SYSTEM)
115 return 0x00;
116 else if (auth == IW_AUTH_ALG_SHARED_KEY)
117 return 0x01;
118 else if (auth == IW_AUTH_ALG_LEAP)
119 return 0x80;
120
121 lbs_deb_join("%s: invalid auth alg 0x%X\n", __func__, auth);
122 return 0;
123}
124
125/**
126 * @brief This function prepares the authenticate command. AUTHENTICATE only
127 * sets the authentication suite for future associations, as the firmware
128 * handles authentication internally during the ASSOCIATE command.
129 *
130 * @param priv A pointer to struct lbs_private structure
131 * @param bssid The peer BSSID with which to authenticate
132 * @param auth The authentication mode to use (from wireless.h)
133 *
134 * @return 0 or -1
135 */
136static int lbs_set_authentication(struct lbs_private *priv, u8 bssid[6], u8 auth)
137{
138 struct cmd_ds_802_11_authenticate cmd;
139 int ret = -1;
Dan Williamsbe0d76e2009-05-22 20:05:25 -0400140
141 lbs_deb_enter(LBS_DEB_JOIN);
142
143 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
144 memcpy(cmd.bssid, bssid, ETH_ALEN);
145
146 cmd.authtype = iw_auth_to_ieee_auth(auth);
147
Johannes Berge91d8332009-07-15 17:21:41 +0200148 lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n", bssid, cmd.authtype);
Dan Williamsbe0d76e2009-05-22 20:05:25 -0400149
150 ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
151
152 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
153 return ret;
154}
155
Dan Williams822ac032009-05-22 20:07:14 -0400156
Holger Schurigd0de3742009-10-22 15:30:51 +0200157int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
158 struct assoc_request *assoc)
159{
160 struct cmd_ds_802_11_set_wep cmd;
161 int ret = 0;
162
163 lbs_deb_enter(LBS_DEB_CMD);
164
165 memset(&cmd, 0, sizeof(cmd));
166 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
167 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
168
169 cmd.action = cpu_to_le16(cmd_action);
170
171 if (cmd_action == CMD_ACT_ADD) {
172 int i;
173
174 /* default tx key index */
175 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
176 CMD_WEP_KEY_INDEX_MASK);
177
178 /* Copy key types and material to host command structure */
179 for (i = 0; i < 4; i++) {
180 struct enc_key *pkey = &assoc->wep_keys[i];
181
182 switch (pkey->len) {
183 case KEY_LEN_WEP_40:
184 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
185 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
186 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
187 break;
188 case KEY_LEN_WEP_104:
189 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
190 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
191 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
192 break;
193 case 0:
194 break;
195 default:
196 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
197 i, pkey->len);
198 ret = -1;
199 goto done;
200 break;
201 }
202 }
203 } else if (cmd_action == CMD_ACT_REMOVE) {
204 /* ACT_REMOVE clears _all_ WEP keys */
205
206 /* default tx key index */
207 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
208 CMD_WEP_KEY_INDEX_MASK);
209 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
210 }
211
212 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
213done:
214 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
215 return ret;
216}
217
218int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
219 uint16_t *enable)
220{
221 struct cmd_ds_802_11_enable_rsn cmd;
222 int ret;
223
224 lbs_deb_enter(LBS_DEB_CMD);
225
226 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
227 cmd.action = cpu_to_le16(cmd_action);
228
229 if (cmd_action == CMD_ACT_GET)
230 cmd.enable = 0;
231 else {
232 if (*enable)
233 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
234 else
235 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
236 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
237 }
238
239 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
240 if (!ret && cmd_action == CMD_ACT_GET)
241 *enable = le16_to_cpu(cmd.enable);
242
243 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
244 return ret;
245}
246
247static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
248 struct enc_key *key)
249{
250 lbs_deb_enter(LBS_DEB_CMD);
251
252 if (key->flags & KEY_INFO_WPA_ENABLED)
253 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
254 if (key->flags & KEY_INFO_WPA_UNICAST)
255 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
256 if (key->flags & KEY_INFO_WPA_MCAST)
257 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
258
259 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
260 keyparam->keytypeid = cpu_to_le16(key->type);
261 keyparam->keylen = cpu_to_le16(key->len);
262 memcpy(keyparam->key, key->key, key->len);
263
264 /* Length field doesn't include the {type,length} header */
265 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
266 lbs_deb_leave(LBS_DEB_CMD);
267}
268
269int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
270 struct assoc_request *assoc)
271{
272 struct cmd_ds_802_11_key_material cmd;
273 int ret = 0;
274 int index = 0;
275
276 lbs_deb_enter(LBS_DEB_CMD);
277
278 cmd.action = cpu_to_le16(cmd_action);
279 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
280
281 if (cmd_action == CMD_ACT_GET) {
282 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
283 } else {
284 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
285
286 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
287 set_one_wpa_key(&cmd.keyParamSet[index],
288 &assoc->wpa_unicast_key);
289 index++;
290 }
291
292 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
293 set_one_wpa_key(&cmd.keyParamSet[index],
294 &assoc->wpa_mcast_key);
295 index++;
296 }
297
298 /* The common header and as many keys as we included */
299 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
300 keyParamSet[index]));
301 }
302 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
303 /* Copy the returned key to driver private data */
304 if (!ret && cmd_action == CMD_ACT_GET) {
305 void *buf_ptr = cmd.keyParamSet;
306 void *resp_end = &(&cmd)[1];
307
308 while (buf_ptr < resp_end) {
309 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
310 struct enc_key *key;
311 uint16_t param_set_len = le16_to_cpu(keyparam->length);
312 uint16_t key_len = le16_to_cpu(keyparam->keylen);
313 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
314 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
315 void *end;
316
317 end = (void *)keyparam + sizeof(keyparam->type)
318 + sizeof(keyparam->length) + param_set_len;
319
320 /* Make sure we don't access past the end of the IEs */
321 if (end > resp_end)
322 break;
323
324 if (key_flags & KEY_INFO_WPA_UNICAST)
325 key = &priv->wpa_unicast_key;
326 else if (key_flags & KEY_INFO_WPA_MCAST)
327 key = &priv->wpa_mcast_key;
328 else
329 break;
330
331 /* Copy returned key into driver */
332 memset(key, 0, sizeof(struct enc_key));
333 if (key_len > sizeof(key->key))
334 break;
335 key->type = key_type;
336 key->flags = key_flags;
337 key->len = key_len;
338 memcpy(key->key, keyparam->key, key->len);
339
340 buf_ptr = end + 1;
341 }
342 }
343
344 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
345 return ret;
346}
347
348static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
349{
350/* Bit Rate
351* 15:13 Reserved
352* 12 54 Mbps
353* 11 48 Mbps
354* 10 36 Mbps
355* 9 24 Mbps
356* 8 18 Mbps
357* 7 12 Mbps
358* 6 9 Mbps
359* 5 6 Mbps
360* 4 Reserved
361* 3 11 Mbps
362* 2 5.5 Mbps
363* 1 2 Mbps
364* 0 1 Mbps
365**/
366
367 uint16_t ratemask;
368 int i = lbs_data_rate_to_fw_index(rate);
369 if (lower_rates_ok)
370 ratemask = (0x1fef >> (12 - i));
371 else
372 ratemask = (1 << i);
373 return cpu_to_le16(ratemask);
374}
375
376int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
377 uint16_t cmd_action)
378{
379 struct cmd_ds_802_11_rate_adapt_rateset cmd;
380 int ret;
381
382 lbs_deb_enter(LBS_DEB_CMD);
383
384 if (!priv->cur_rate && !priv->enablehwauto)
385 return -EINVAL;
386
387 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
388
389 cmd.action = cpu_to_le16(cmd_action);
390 cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
391 cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
392 ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
393 if (!ret && cmd_action == CMD_ACT_GET) {
394 priv->ratebitmap = le16_to_cpu(cmd.bitmap);
395 priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
396 }
397
398 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
399 return ret;
400}
401
402/**
403 * @brief Set the data rate
404 *
405 * @param priv A pointer to struct lbs_private structure
406 * @param rate The desired data rate, or 0 to clear a locked rate
407 *
408 * @return 0 on success, error on failure
409 */
410int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
411{
412 struct cmd_ds_802_11_data_rate cmd;
413 int ret = 0;
414
415 lbs_deb_enter(LBS_DEB_CMD);
416
417 memset(&cmd, 0, sizeof(cmd));
418 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
419
420 if (rate > 0) {
421 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
422 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
423 if (cmd.rates[0] == 0) {
424 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
425 " 0x%02X\n", rate);
426 ret = 0;
427 goto out;
428 }
429 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
430 } else {
431 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
432 lbs_deb_cmd("DATA_RATE: setting auto\n");
433 }
434
435 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
436 if (ret)
437 goto out;
438
439 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof(cmd));
440
441 /* FIXME: get actual rates FW can do if this command actually returns
442 * all data rates supported.
443 */
444 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
445 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
446
447out:
448 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
449 return ret;
450}
451
452
453int lbs_cmd_802_11_rssi(struct lbs_private *priv,
454 struct cmd_ds_command *cmd)
455{
456
457 lbs_deb_enter(LBS_DEB_CMD);
458 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
459 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
460 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
461
462 /* reset Beacon SNR/NF/RSSI values */
463 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
464 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
465 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
466 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
467 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
468 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
469
470 lbs_deb_leave(LBS_DEB_CMD);
471 return 0;
472}
473
474int lbs_ret_802_11_rssi(struct lbs_private *priv,
475 struct cmd_ds_command *resp)
476{
477 struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp;
478
479 lbs_deb_enter(LBS_DEB_CMD);
480
481 /* store the non average value */
482 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = get_unaligned_le16(&rssirsp->SNR);
483 priv->NF[TYPE_BEACON][TYPE_NOAVG] =
484 get_unaligned_le16(&rssirsp->noisefloor);
485
486 priv->SNR[TYPE_BEACON][TYPE_AVG] = get_unaligned_le16(&rssirsp->avgSNR);
487 priv->NF[TYPE_BEACON][TYPE_AVG] =
488 get_unaligned_le16(&rssirsp->avgnoisefloor);
489
490 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] =
491 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
492 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
493
494 priv->RSSI[TYPE_BEACON][TYPE_AVG] =
495 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE,
496 priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE);
497
498 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
499 priv->RSSI[TYPE_BEACON][TYPE_NOAVG],
500 priv->RSSI[TYPE_BEACON][TYPE_AVG]);
501
502 lbs_deb_leave(LBS_DEB_CMD);
503 return 0;
504}
505
506
507int lbs_cmd_bcn_ctrl(struct lbs_private *priv,
508 struct cmd_ds_command *cmd,
509 u16 cmd_action)
510{
511 struct cmd_ds_802_11_beacon_control
512 *bcn_ctrl = &cmd->params.bcn_ctrl;
513
514 lbs_deb_enter(LBS_DEB_CMD);
515 cmd->size =
516 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
517 + S_DS_GEN);
518 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
519
520 bcn_ctrl->action = cpu_to_le16(cmd_action);
521 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
522 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
523
524 lbs_deb_leave(LBS_DEB_CMD);
525 return 0;
526}
527
528int lbs_ret_802_11_bcn_ctrl(struct lbs_private *priv,
529 struct cmd_ds_command *resp)
530{
531 struct cmd_ds_802_11_beacon_control *bcn_ctrl =
532 &resp->params.bcn_ctrl;
533
534 lbs_deb_enter(LBS_DEB_CMD);
535
536 if (bcn_ctrl->action == CMD_ACT_GET) {
537 priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable);
538 priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period);
539 }
540
541 lbs_deb_enter(LBS_DEB_CMD);
542 return 0;
543}
544
545
546
Dan Williams822ac032009-05-22 20:07:14 -0400547static int lbs_assoc_post(struct lbs_private *priv,
548 struct cmd_ds_802_11_associate_response *resp)
549{
550 int ret = 0;
551 union iwreq_data wrqu;
552 struct bss_descriptor *bss;
553 u16 status_code;
554
555 lbs_deb_enter(LBS_DEB_ASSOC);
556
557 if (!priv->in_progress_assoc_req) {
558 lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n");
559 ret = -1;
560 goto done;
561 }
562 bss = &priv->in_progress_assoc_req->bss;
563
564 /*
565 * Older FW versions map the IEEE 802.11 Status Code in the association
566 * response to the following values returned in resp->statuscode:
567 *
568 * IEEE Status Code Marvell Status Code
569 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
570 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
571 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
572 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
573 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
574 * others -> 0x0003 ASSOC_RESULT_REFUSED
575 *
576 * Other response codes:
577 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
578 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
579 * association response from the AP)
580 */
581
582 status_code = le16_to_cpu(resp->statuscode);
583 if (priv->fwrelease < 0x09000000) {
584 switch (status_code) {
585 case 0x00:
586 break;
587 case 0x01:
588 lbs_deb_assoc("ASSOC_RESP: invalid parameters\n");
589 break;
590 case 0x02:
591 lbs_deb_assoc("ASSOC_RESP: internal timer "
592 "expired while waiting for the AP\n");
593 break;
594 case 0x03:
595 lbs_deb_assoc("ASSOC_RESP: association "
596 "refused by AP\n");
597 break;
598 case 0x04:
599 lbs_deb_assoc("ASSOC_RESP: authentication "
600 "refused by AP\n");
601 break;
602 default:
603 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x "
604 " unknown\n", status_code);
605 break;
606 }
607 } else {
608 /* v9+ returns the AP's association response */
609 lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x\n", status_code);
610 }
611
612 if (status_code) {
613 lbs_mac_event_disconnected(priv);
614 ret = -1;
615 goto done;
616 }
617
618 lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP",
619 (void *) (resp + sizeof (resp->hdr)),
620 le16_to_cpu(resp->hdr.size) - sizeof (resp->hdr));
621
622 /* Send a Media Connected event, according to the Spec */
623 priv->connect_status = LBS_CONNECTED;
624
625 /* Update current SSID and BSSID */
Holger Schurig243e84e2009-10-22 15:30:47 +0200626 memcpy(&priv->curbssparams.ssid, &bss->ssid, IEEE80211_MAX_SSID_LEN);
Dan Williams822ac032009-05-22 20:07:14 -0400627 priv->curbssparams.ssid_len = bss->ssid_len;
628 memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN);
629
630 priv->SNR[TYPE_RXPD][TYPE_AVG] = 0;
631 priv->NF[TYPE_RXPD][TYPE_AVG] = 0;
632
633 memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR));
634 memset(priv->rawNF, 0x00, sizeof(priv->rawNF));
635 priv->nextSNRNF = 0;
636 priv->numSNRNF = 0;
637
638 netif_carrier_on(priv->dev);
639 if (!priv->tx_pending_len)
640 netif_wake_queue(priv->dev);
641
642 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN);
643 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
644 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
645
646done:
647 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
648 return ret;
649}
650
651/**
652 * @brief This function prepares an association-class command.
653 *
654 * @param priv A pointer to struct lbs_private structure
655 * @param assoc_req The association request describing the BSS to associate
656 * or reassociate with
657 * @param command The actual command, either CMD_802_11_ASSOCIATE or
658 * CMD_802_11_REASSOCIATE
659 *
660 * @return 0 or -1
661 */
662static int lbs_associate(struct lbs_private *priv,
663 struct assoc_request *assoc_req,
664 u16 command)
665{
666 struct cmd_ds_802_11_associate cmd;
667 int ret = 0;
668 struct bss_descriptor *bss = &assoc_req->bss;
669 u8 *pos = &(cmd.iebuf[0]);
670 u16 tmpcap, tmplen, tmpauth;
671 struct mrvl_ie_ssid_param_set *ssid;
672 struct mrvl_ie_ds_param_set *ds;
673 struct mrvl_ie_cf_param_set *cf;
674 struct mrvl_ie_rates_param_set *rates;
675 struct mrvl_ie_rsn_param_set *rsn;
676 struct mrvl_ie_auth_type *auth;
677
678 lbs_deb_enter(LBS_DEB_ASSOC);
679
680 BUG_ON((command != CMD_802_11_ASSOCIATE) &&
681 (command != CMD_802_11_REASSOCIATE));
682
683 memset(&cmd, 0, sizeof(cmd));
684 cmd.hdr.command = cpu_to_le16(command);
685
686 /* Fill in static fields */
687 memcpy(cmd.bssid, bss->bssid, ETH_ALEN);
688 cmd.listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
689
690 /* Capability info */
691 tmpcap = (bss->capability & CAPINFO_MASK);
692 if (bss->mode == IW_MODE_INFRA)
693 tmpcap |= WLAN_CAPABILITY_ESS;
694 cmd.capability = cpu_to_le16(tmpcap);
695 lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap);
696
697 /* SSID */
698 ssid = (struct mrvl_ie_ssid_param_set *) pos;
699 ssid->header.type = cpu_to_le16(TLV_TYPE_SSID);
700 tmplen = bss->ssid_len;
701 ssid->header.len = cpu_to_le16(tmplen);
702 memcpy(ssid->ssid, bss->ssid, tmplen);
703 pos += sizeof(ssid->header) + tmplen;
704
705 ds = (struct mrvl_ie_ds_param_set *) pos;
706 ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
707 ds->header.len = cpu_to_le16(1);
708 ds->channel = bss->phy.ds.channel;
709 pos += sizeof(ds->header) + 1;
710
711 cf = (struct mrvl_ie_cf_param_set *) pos;
712 cf->header.type = cpu_to_le16(TLV_TYPE_CF);
713 tmplen = sizeof(*cf) - sizeof (cf->header);
714 cf->header.len = cpu_to_le16(tmplen);
715 /* IE payload should be zeroed, firmware fills it in for us */
716 pos += sizeof(*cf);
717
718 rates = (struct mrvl_ie_rates_param_set *) pos;
719 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
Dan Williamsca4fe302009-08-21 09:35:20 -0500720 tmplen = min_t(u16, ARRAY_SIZE(bss->rates), MAX_RATES);
Roel Kluin1e3d31c2009-08-02 09:44:12 +0200721 memcpy(&rates->rates, &bss->rates, tmplen);
Dan Williams822ac032009-05-22 20:07:14 -0400722 if (get_common_rates(priv, rates->rates, &tmplen)) {
723 ret = -1;
724 goto done;
725 }
726 pos += sizeof(rates->header) + tmplen;
727 rates->header.len = cpu_to_le16(tmplen);
728 lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen);
729
730 /* Copy the infra. association rates into Current BSS state structure */
731 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
732 memcpy(&priv->curbssparams.rates, &rates->rates, tmplen);
733
734 /* Set MSB on basic rates as the firmware requires, but _after_
735 * copying to current bss rates.
736 */
737 lbs_set_basic_rate_flags(rates->rates, tmplen);
738
739 /* Firmware v9+ indicate authentication suites as a TLV */
740 if (priv->fwrelease >= 0x09000000) {
Dan Williams822ac032009-05-22 20:07:14 -0400741 auth = (struct mrvl_ie_auth_type *) pos;
742 auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
743 auth->header.len = cpu_to_le16(2);
744 tmpauth = iw_auth_to_ieee_auth(priv->secinfo.auth_mode);
745 auth->auth = cpu_to_le16(tmpauth);
746 pos += sizeof(auth->header) + 2;
747
Johannes Berge91d8332009-07-15 17:21:41 +0200748 lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n",
749 bss->bssid, priv->secinfo.auth_mode);
Dan Williams822ac032009-05-22 20:07:14 -0400750 }
751
752 /* WPA/WPA2 IEs */
753 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
754 rsn = (struct mrvl_ie_rsn_param_set *) pos;
755 /* WPA_IE or WPA2_IE */
756 rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]);
757 tmplen = (u16) assoc_req->wpa_ie[1];
758 rsn->header.len = cpu_to_le16(tmplen);
759 memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen);
760 lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: WPA/RSN IE", (u8 *) rsn,
761 sizeof(rsn->header) + tmplen);
762 pos += sizeof(rsn->header) + tmplen;
763 }
764
765 cmd.hdr.size = cpu_to_le16((sizeof(cmd) - sizeof(cmd.iebuf)) +
766 (u16)(pos - (u8 *) &cmd.iebuf));
767
768 /* update curbssparams */
Holger Schurigc14951f2009-10-22 15:30:50 +0200769 priv->channel = bss->phy.ds.channel;
Dan Williams822ac032009-05-22 20:07:14 -0400770
Dan Williams822ac032009-05-22 20:07:14 -0400771 ret = lbs_cmd_with_response(priv, command, &cmd);
772 if (ret == 0) {
773 ret = lbs_assoc_post(priv,
774 (struct cmd_ds_802_11_associate_response *) &cmd);
775 }
776
777done:
778 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
779 return ret;
780}
781
Holger Schurig697900a2008-04-02 16:27:10 +0200782/**
783 * @brief Associate to a specific BSS discovered in a scan
784 *
785 * @param priv A pointer to struct lbs_private structure
Dan Williamsd5db2df2008-08-21 17:51:07 -0400786 * @param assoc_req The association request describing the BSS to associate with
Holger Schurig697900a2008-04-02 16:27:10 +0200787 *
788 * @return 0-success, otherwise fail
789 */
Dan Williams822ac032009-05-22 20:07:14 -0400790static int lbs_try_associate(struct lbs_private *priv,
Holger Schurig697900a2008-04-02 16:27:10 +0200791 struct assoc_request *assoc_req)
792{
793 int ret;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400794 u8 preamble = RADIO_PREAMBLE_LONG;
Holger Schurig697900a2008-04-02 16:27:10 +0200795
796 lbs_deb_enter(LBS_DEB_ASSOC);
797
Dan Williamsbe0d76e2009-05-22 20:05:25 -0400798 /* FW v9 and higher indicate authentication suites as a TLV in the
799 * association command, not as a separate authentication command.
800 */
801 if (priv->fwrelease < 0x09000000) {
802 ret = lbs_set_authentication(priv, assoc_req->bss.bssid,
803 priv->secinfo.auth_mode);
804 if (ret)
805 goto out;
806 }
Holger Schurig697900a2008-04-02 16:27:10 +0200807
Dan Williamsd5db2df2008-08-21 17:51:07 -0400808 /* Use short preamble only when both the BSS and firmware support it */
Holger Schurig697900a2008-04-02 16:27:10 +0200809 if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
810 (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
Dan Williamsd5db2df2008-08-21 17:51:07 -0400811 preamble = RADIO_PREAMBLE_SHORT;
Holger Schurig697900a2008-04-02 16:27:10 +0200812
Dan Williamsd5db2df2008-08-21 17:51:07 -0400813 ret = lbs_set_radio(priv, preamble, 1);
814 if (ret)
815 goto out;
Holger Schurig697900a2008-04-02 16:27:10 +0200816
Dan Williams822ac032009-05-22 20:07:14 -0400817 ret = lbs_associate(priv, assoc_req, CMD_802_11_ASSOCIATE);
Holger Schurig697900a2008-04-02 16:27:10 +0200818
Dan Williamsd5db2df2008-08-21 17:51:07 -0400819out:
Holger Schurig697900a2008-04-02 16:27:10 +0200820 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
821 return ret;
822}
823
Dan Williams822ac032009-05-22 20:07:14 -0400824static int lbs_adhoc_post(struct lbs_private *priv,
825 struct cmd_ds_802_11_ad_hoc_result *resp)
826{
827 int ret = 0;
828 u16 command = le16_to_cpu(resp->hdr.command);
829 u16 result = le16_to_cpu(resp->hdr.result);
830 union iwreq_data wrqu;
831 struct bss_descriptor *bss;
832 DECLARE_SSID_BUF(ssid);
833
834 lbs_deb_enter(LBS_DEB_JOIN);
835
836 if (!priv->in_progress_assoc_req) {
837 lbs_deb_join("ADHOC_RESP: no in-progress association "
838 "request\n");
839 ret = -1;
840 goto done;
841 }
842 bss = &priv->in_progress_assoc_req->bss;
843
844 /*
845 * Join result code 0 --> SUCCESS
846 */
847 if (result) {
848 lbs_deb_join("ADHOC_RESP: failed (result 0x%X)\n", result);
849 if (priv->connect_status == LBS_CONNECTED)
850 lbs_mac_event_disconnected(priv);
851 ret = -1;
852 goto done;
853 }
854
855 /* Send a Media Connected event, according to the Spec */
856 priv->connect_status = LBS_CONNECTED;
857
858 if (command == CMD_RET(CMD_802_11_AD_HOC_START)) {
859 /* Update the created network descriptor with the new BSSID */
860 memcpy(bss->bssid, resp->bssid, ETH_ALEN);
861 }
862
863 /* Set the BSSID from the joined/started descriptor */
864 memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN);
865
866 /* Set the new SSID to current SSID */
Holger Schurig243e84e2009-10-22 15:30:47 +0200867 memcpy(&priv->curbssparams.ssid, &bss->ssid, IEEE80211_MAX_SSID_LEN);
Dan Williams822ac032009-05-22 20:07:14 -0400868 priv->curbssparams.ssid_len = bss->ssid_len;
869
870 netif_carrier_on(priv->dev);
871 if (!priv->tx_pending_len)
872 netif_wake_queue(priv->dev);
873
874 memset(&wrqu, 0, sizeof(wrqu));
875 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN);
876 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
877 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
878
879 lbs_deb_join("ADHOC_RESP: Joined/started '%s', BSSID %pM, channel %d\n",
880 print_ssid(ssid, bss->ssid, bss->ssid_len),
881 priv->curbssparams.bssid,
Holger Schurigc14951f2009-10-22 15:30:50 +0200882 priv->channel);
Dan Williams822ac032009-05-22 20:07:14 -0400883
884done:
885 lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret);
886 return ret;
887}
888
Holger Schurig697900a2008-04-02 16:27:10 +0200889/**
890 * @brief Join an adhoc network found in a previous scan
891 *
892 * @param priv A pointer to struct lbs_private structure
Dan Williamsd5db2df2008-08-21 17:51:07 -0400893 * @param assoc_req The association request describing the BSS to join
Holger Schurig697900a2008-04-02 16:27:10 +0200894 *
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400895 * @return 0 on success, error on failure
Holger Schurig697900a2008-04-02 16:27:10 +0200896 */
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400897static int lbs_adhoc_join(struct lbs_private *priv,
Holger Schurig697900a2008-04-02 16:27:10 +0200898 struct assoc_request *assoc_req)
899{
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400900 struct cmd_ds_802_11_ad_hoc_join cmd;
Holger Schurig697900a2008-04-02 16:27:10 +0200901 struct bss_descriptor *bss = &assoc_req->bss;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400902 u8 preamble = RADIO_PREAMBLE_LONG;
John W. Linville9387b7c2008-09-30 20:59:05 -0400903 DECLARE_SSID_BUF(ssid);
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400904 u16 ratesize = 0;
905 int ret = 0;
Dan Williamsd5db2df2008-08-21 17:51:07 -0400906
907 lbs_deb_enter(LBS_DEB_ASSOC);
Holger Schurig697900a2008-04-02 16:27:10 +0200908
909 lbs_deb_join("current SSID '%s', ssid length %u\n",
John W. Linville9387b7c2008-09-30 20:59:05 -0400910 print_ssid(ssid, priv->curbssparams.ssid,
Holger Schurig697900a2008-04-02 16:27:10 +0200911 priv->curbssparams.ssid_len),
912 priv->curbssparams.ssid_len);
913 lbs_deb_join("requested ssid '%s', ssid length %u\n",
John W. Linville9387b7c2008-09-30 20:59:05 -0400914 print_ssid(ssid, bss->ssid, bss->ssid_len),
Holger Schurig697900a2008-04-02 16:27:10 +0200915 bss->ssid_len);
916
917 /* check if the requested SSID is already joined */
918 if (priv->curbssparams.ssid_len &&
919 !lbs_ssid_cmp(priv->curbssparams.ssid,
920 priv->curbssparams.ssid_len,
921 bss->ssid, bss->ssid_len) &&
922 (priv->mode == IW_MODE_ADHOC) &&
923 (priv->connect_status == LBS_CONNECTED)) {
924 union iwreq_data wrqu;
925
926 lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as "
927 "current, not attempting to re-join");
928
929 /* Send the re-association event though, because the association
930 * request really was successful, even if just a null-op.
931 */
932 memset(&wrqu, 0, sizeof(wrqu));
933 memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid,
934 ETH_ALEN);
935 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
936 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
937 goto out;
938 }
939
Dan Williamsd5db2df2008-08-21 17:51:07 -0400940 /* Use short preamble only when both the BSS and firmware support it */
941 if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
942 (bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) {
Holger Schurig697900a2008-04-02 16:27:10 +0200943 lbs_deb_join("AdhocJoin: Short preamble\n");
Dan Williamsd5db2df2008-08-21 17:51:07 -0400944 preamble = RADIO_PREAMBLE_SHORT;
Holger Schurig697900a2008-04-02 16:27:10 +0200945 }
946
Dan Williamsd5db2df2008-08-21 17:51:07 -0400947 ret = lbs_set_radio(priv, preamble, 1);
948 if (ret)
949 goto out;
Holger Schurig697900a2008-04-02 16:27:10 +0200950
951 lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel);
952 lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band);
953
954 priv->adhoccreate = 0;
Holger Schurigc14951f2009-10-22 15:30:50 +0200955 priv->channel = bss->channel;
Holger Schurig697900a2008-04-02 16:27:10 +0200956
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400957 /* Build the join command */
958 memset(&cmd, 0, sizeof(cmd));
959 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
960
961 cmd.bss.type = CMD_BSS_TYPE_IBSS;
962 cmd.bss.beaconperiod = cpu_to_le16(bss->beaconperiod);
963
964 memcpy(&cmd.bss.bssid, &bss->bssid, ETH_ALEN);
965 memcpy(&cmd.bss.ssid, &bss->ssid, bss->ssid_len);
966
Dan Williams5fd164e2009-05-22 20:01:21 -0400967 memcpy(&cmd.bss.ds, &bss->phy.ds, sizeof(struct ieee_ie_ds_param_set));
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400968
Dan Williams5fd164e2009-05-22 20:01:21 -0400969 memcpy(&cmd.bss.ibss, &bss->ss.ibss,
970 sizeof(struct ieee_ie_ibss_param_set));
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400971
972 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
973 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n",
974 bss->capability, CAPINFO_MASK);
975
976 /* information on BSSID descriptor passed to FW */
Johannes Berge1749612008-10-27 15:59:26 -0700977 lbs_deb_join("ADHOC_J_CMD: BSSID = %pM, SSID = '%s'\n",
978 cmd.bss.bssid, cmd.bss.ssid);
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400979
980 /* Only v8 and below support setting these */
981 if (priv->fwrelease < 0x09000000) {
982 /* failtimeout */
983 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
984 /* probedelay */
985 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
986 }
987
988 /* Copy Data rates from the rates recorded in scan response */
989 memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates));
Dan Williamsca4fe302009-08-21 09:35:20 -0500990 ratesize = min_t(u16, ARRAY_SIZE(cmd.bss.rates), ARRAY_SIZE (bss->rates));
Dan Williamsf5fe1fd2008-08-21 21:46:59 -0400991 memcpy(cmd.bss.rates, bss->rates, ratesize);
992 if (get_common_rates(priv, cmd.bss.rates, &ratesize)) {
993 lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n");
994 ret = -1;
995 goto out;
996 }
997
998 /* Copy the ad-hoc creation rates into Current BSS state structure */
999 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
1000 memcpy(&priv->curbssparams.rates, cmd.bss.rates, ratesize);
1001
1002 /* Set MSB on basic rates as the firmware requires, but _after_
1003 * copying to current bss rates.
1004 */
1005 lbs_set_basic_rate_flags(cmd.bss.rates, ratesize);
1006
Dan Williams5fd164e2009-05-22 20:01:21 -04001007 cmd.bss.ibss.atimwindow = bss->atimwindow;
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001008
1009 if (assoc_req->secinfo.wep_enabled) {
1010 u16 tmp = le16_to_cpu(cmd.bss.capability);
1011 tmp |= WLAN_CAPABILITY_PRIVACY;
1012 cmd.bss.capability = cpu_to_le16(tmp);
1013 }
1014
1015 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
1016 __le32 local_ps_mode = cpu_to_le32(LBS802_11POWERMODECAM);
1017
1018 /* wake up first */
1019 ret = lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1020 CMD_ACT_SET, 0, 0,
1021 &local_ps_mode);
1022 if (ret) {
1023 ret = -1;
1024 goto out;
1025 }
1026 }
1027
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001028 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
Dan Williams822ac032009-05-22 20:07:14 -04001029 if (ret == 0) {
1030 ret = lbs_adhoc_post(priv,
1031 (struct cmd_ds_802_11_ad_hoc_result *)&cmd);
1032 }
Holger Schurig697900a2008-04-02 16:27:10 +02001033
1034out:
Dan Williamsd5db2df2008-08-21 17:51:07 -04001035 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Holger Schurig697900a2008-04-02 16:27:10 +02001036 return ret;
1037}
1038
1039/**
1040 * @brief Start an Adhoc Network
1041 *
1042 * @param priv A pointer to struct lbs_private structure
Dan Williamsd5db2df2008-08-21 17:51:07 -04001043 * @param assoc_req The association request describing the BSS to start
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001044 *
1045 * @return 0 on success, error on failure
Holger Schurig697900a2008-04-02 16:27:10 +02001046 */
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001047static int lbs_adhoc_start(struct lbs_private *priv,
Holger Schurig697900a2008-04-02 16:27:10 +02001048 struct assoc_request *assoc_req)
1049{
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001050 struct cmd_ds_802_11_ad_hoc_start cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001051 u8 preamble = RADIO_PREAMBLE_LONG;
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001052 size_t ratesize = 0;
1053 u16 tmpcap = 0;
1054 int ret = 0;
John W. Linville9387b7c2008-09-30 20:59:05 -04001055 DECLARE_SSID_BUF(ssid);
Dan Williamsd5db2df2008-08-21 17:51:07 -04001056
1057 lbs_deb_enter(LBS_DEB_ASSOC);
Holger Schurig697900a2008-04-02 16:27:10 +02001058
Holger Schurig697900a2008-04-02 16:27:10 +02001059 if (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) {
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001060 lbs_deb_join("ADHOC_START: Will use short preamble\n");
Dan Williamsd5db2df2008-08-21 17:51:07 -04001061 preamble = RADIO_PREAMBLE_SHORT;
Holger Schurig697900a2008-04-02 16:27:10 +02001062 }
1063
Dan Williamsd5db2df2008-08-21 17:51:07 -04001064 ret = lbs_set_radio(priv, preamble, 1);
1065 if (ret)
1066 goto out;
Holger Schurig697900a2008-04-02 16:27:10 +02001067
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001068 /* Build the start command */
1069 memset(&cmd, 0, sizeof(cmd));
1070 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurig697900a2008-04-02 16:27:10 +02001071
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001072 memcpy(cmd.ssid, assoc_req->ssid, assoc_req->ssid_len);
1073
1074 lbs_deb_join("ADHOC_START: SSID '%s', ssid length %u\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001075 print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len),
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001076 assoc_req->ssid_len);
1077
1078 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1079
1080 if (priv->beacon_period == 0)
1081 priv->beacon_period = MRVDRV_BEACON_INTERVAL;
1082 cmd.beaconperiod = cpu_to_le16(priv->beacon_period);
1083
1084 WARN_ON(!assoc_req->channel);
1085
1086 /* set Physical parameter set */
Dan Williams75b6a612009-05-22 20:03:09 -04001087 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1088 cmd.ds.header.len = 1;
Dan Williams5fd164e2009-05-22 20:01:21 -04001089 cmd.ds.channel = assoc_req->channel;
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001090
1091 /* set IBSS parameter set */
Dan Williams75b6a612009-05-22 20:03:09 -04001092 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1093 cmd.ibss.header.len = 2;
Dan Williams5fd164e2009-05-22 20:01:21 -04001094 cmd.ibss.atimwindow = cpu_to_le16(0);
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001095
1096 /* set capability info */
1097 tmpcap = WLAN_CAPABILITY_IBSS;
Dan Williams2fa7a982009-05-22 20:09:58 -04001098 if (assoc_req->secinfo.wep_enabled ||
1099 assoc_req->secinfo.WPAenabled ||
1100 assoc_req->secinfo.WPA2enabled) {
1101 lbs_deb_join("ADHOC_START: WEP/WPA enabled, privacy on\n");
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001102 tmpcap |= WLAN_CAPABILITY_PRIVACY;
1103 } else
Dan Williams2fa7a982009-05-22 20:09:58 -04001104 lbs_deb_join("ADHOC_START: WEP disabled, privacy off\n");
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001105
1106 cmd.capability = cpu_to_le16(tmpcap);
1107
1108 /* Only v8 and below support setting probe delay */
1109 if (priv->fwrelease < 0x09000000)
1110 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1111
1112 ratesize = min(sizeof(cmd.rates), sizeof(lbs_bg_rates));
1113 memcpy(cmd.rates, lbs_bg_rates, ratesize);
1114
1115 /* Copy the ad-hoc creating rates into Current BSS state structure */
1116 memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates));
1117 memcpy(&priv->curbssparams.rates, &cmd.rates, ratesize);
1118
1119 /* Set MSB on basic rates as the firmware requires, but _after_
1120 * copying to current bss rates.
1121 */
1122 lbs_set_basic_rate_flags(cmd.rates, ratesize);
1123
1124 lbs_deb_join("ADHOC_START: rates=%02x %02x %02x %02x\n",
1125 cmd.rates[0], cmd.rates[1], cmd.rates[2], cmd.rates[3]);
1126
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001127 lbs_deb_join("ADHOC_START: Starting Ad-Hoc BSS on channel %d, band %d\n",
1128 assoc_req->channel, assoc_req->band);
1129
1130 priv->adhoccreate = 1;
1131 priv->mode = IW_MODE_ADHOC;
1132
1133 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1134 if (ret == 0)
Dan Williams822ac032009-05-22 20:07:14 -04001135 ret = lbs_adhoc_post(priv,
1136 (struct cmd_ds_802_11_ad_hoc_result *)&cmd);
Holger Schurig697900a2008-04-02 16:27:10 +02001137
Dan Williamsd5db2df2008-08-21 17:51:07 -04001138out:
1139 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Holger Schurig697900a2008-04-02 16:27:10 +02001140 return ret;
1141}
1142
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001143/**
1144 * @brief Stop and Ad-Hoc network and exit Ad-Hoc mode
1145 *
1146 * @param priv A pointer to struct lbs_private structure
1147 * @return 0 on success, or an error
1148 */
1149int lbs_adhoc_stop(struct lbs_private *priv)
Holger Schurig697900a2008-04-02 16:27:10 +02001150{
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001151 struct cmd_ds_802_11_ad_hoc_stop cmd;
1152 int ret;
1153
1154 lbs_deb_enter(LBS_DEB_JOIN);
1155
1156 memset(&cmd, 0, sizeof (cmd));
1157 cmd.hdr.size = cpu_to_le16 (sizeof (cmd));
1158
1159 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
1160
1161 /* Clean up everything even if there was an error */
1162 lbs_mac_event_disconnected(priv);
1163
1164 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1165 return ret;
Holger Schurig697900a2008-04-02 16:27:10 +02001166}
Dan Williamse76850d2007-05-25 17:09:41 -04001167
Holger Schurig245bf202008-04-02 16:27:42 +02001168static inline int match_bss_no_security(struct lbs_802_11_security *secinfo,
1169 struct bss_descriptor *match_bss)
1170{
1171 if (!secinfo->wep_enabled && !secinfo->WPAenabled
1172 && !secinfo->WPA2enabled
Johannes Berg2c7060022008-10-30 22:09:54 +01001173 && match_bss->wpa_ie[0] != WLAN_EID_GENERIC
1174 && match_bss->rsn_ie[0] != WLAN_EID_RSN
Holger Schurig245bf202008-04-02 16:27:42 +02001175 && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY))
1176 return 1;
1177 else
1178 return 0;
1179}
1180
1181static inline int match_bss_static_wep(struct lbs_802_11_security *secinfo,
1182 struct bss_descriptor *match_bss)
1183{
1184 if (secinfo->wep_enabled && !secinfo->WPAenabled
1185 && !secinfo->WPA2enabled
1186 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY))
1187 return 1;
1188 else
1189 return 0;
1190}
1191
1192static inline int match_bss_wpa(struct lbs_802_11_security *secinfo,
1193 struct bss_descriptor *match_bss)
1194{
1195 if (!secinfo->wep_enabled && secinfo->WPAenabled
Johannes Berg2c7060022008-10-30 22:09:54 +01001196 && (match_bss->wpa_ie[0] == WLAN_EID_GENERIC)
Holger Schurig245bf202008-04-02 16:27:42 +02001197 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
1198 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
1199 )
1200 return 1;
1201 else
1202 return 0;
1203}
1204
1205static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo,
1206 struct bss_descriptor *match_bss)
1207{
1208 if (!secinfo->wep_enabled && secinfo->WPA2enabled &&
Johannes Berg2c7060022008-10-30 22:09:54 +01001209 (match_bss->rsn_ie[0] == WLAN_EID_RSN)
Holger Schurig245bf202008-04-02 16:27:42 +02001210 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
1211 (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
1212 )
1213 return 1;
1214 else
1215 return 0;
1216}
1217
1218static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo,
1219 struct bss_descriptor *match_bss)
1220{
1221 if (!secinfo->wep_enabled && !secinfo->WPAenabled
1222 && !secinfo->WPA2enabled
Johannes Berg2c7060022008-10-30 22:09:54 +01001223 && (match_bss->wpa_ie[0] != WLAN_EID_GENERIC)
1224 && (match_bss->rsn_ie[0] != WLAN_EID_RSN)
Holger Schurig245bf202008-04-02 16:27:42 +02001225 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY))
1226 return 1;
1227 else
1228 return 0;
1229}
1230
1231/**
1232 * @brief Check if a scanned network compatible with the driver settings
1233 *
1234 * WEP WPA WPA2 ad-hoc encrypt Network
1235 * enabled enabled enabled AES mode privacy WPA WPA2 Compatible
1236 * 0 0 0 0 NONE 0 0 0 yes No security
1237 * 1 0 0 0 NONE 1 0 0 yes Static WEP
1238 * 0 1 0 0 x 1x 1 x yes WPA
1239 * 0 0 1 0 x 1x x 1 yes WPA2
1240 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
1241 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
1242 *
1243 *
1244 * @param priv A pointer to struct lbs_private
1245 * @param index Index in scantable to check against current driver settings
1246 * @param mode Network mode: Infrastructure or IBSS
1247 *
1248 * @return Index in scantable, or error code if negative
1249 */
1250static int is_network_compatible(struct lbs_private *priv,
1251 struct bss_descriptor *bss, uint8_t mode)
1252{
1253 int matched = 0;
1254
1255 lbs_deb_enter(LBS_DEB_SCAN);
1256
1257 if (bss->mode != mode)
1258 goto done;
1259
1260 matched = match_bss_no_security(&priv->secinfo, bss);
1261 if (matched)
1262 goto done;
1263 matched = match_bss_static_wep(&priv->secinfo, bss);
1264 if (matched)
1265 goto done;
1266 matched = match_bss_wpa(&priv->secinfo, bss);
1267 if (matched) {
1268 lbs_deb_scan("is_network_compatible() WPA: wpa_ie 0x%x "
1269 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
1270 "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
1271 priv->secinfo.wep_enabled ? "e" : "d",
1272 priv->secinfo.WPAenabled ? "e" : "d",
1273 priv->secinfo.WPA2enabled ? "e" : "d",
1274 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1275 goto done;
1276 }
1277 matched = match_bss_wpa2(&priv->secinfo, bss);
1278 if (matched) {
1279 lbs_deb_scan("is_network_compatible() WPA2: wpa_ie 0x%x "
1280 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
1281 "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
1282 priv->secinfo.wep_enabled ? "e" : "d",
1283 priv->secinfo.WPAenabled ? "e" : "d",
1284 priv->secinfo.WPA2enabled ? "e" : "d",
1285 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1286 goto done;
1287 }
1288 matched = match_bss_dynamic_wep(&priv->secinfo, bss);
1289 if (matched) {
1290 lbs_deb_scan("is_network_compatible() dynamic WEP: "
1291 "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n",
1292 bss->wpa_ie[0], bss->rsn_ie[0],
1293 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1294 goto done;
1295 }
1296
1297 /* bss security settings don't match those configured on card */
1298 lbs_deb_scan("is_network_compatible() FAILED: wpa_ie 0x%x "
1299 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n",
1300 bss->wpa_ie[0], bss->rsn_ie[0],
1301 priv->secinfo.wep_enabled ? "e" : "d",
1302 priv->secinfo.WPAenabled ? "e" : "d",
1303 priv->secinfo.WPA2enabled ? "e" : "d",
1304 (bss->capability & WLAN_CAPABILITY_PRIVACY));
1305
1306done:
1307 lbs_deb_leave_args(LBS_DEB_SCAN, "matched: %d", matched);
1308 return matched;
1309}
1310
1311/**
1312 * @brief This function finds a specific compatible BSSID in the scan list
1313 *
1314 * Used in association code
1315 *
1316 * @param priv A pointer to struct lbs_private
1317 * @param bssid BSSID to find in the scan list
1318 * @param mode Network mode: Infrastructure or IBSS
1319 *
1320 * @return index in BSSID list, or error return code (< 0)
1321 */
1322static struct bss_descriptor *lbs_find_bssid_in_list(struct lbs_private *priv,
1323 uint8_t *bssid, uint8_t mode)
1324{
1325 struct bss_descriptor *iter_bss;
1326 struct bss_descriptor *found_bss = NULL;
1327
1328 lbs_deb_enter(LBS_DEB_SCAN);
1329
1330 if (!bssid)
1331 goto out;
1332
1333 lbs_deb_hex(LBS_DEB_SCAN, "looking for", bssid, ETH_ALEN);
1334
1335 /* Look through the scan table for a compatible match. The loop will
1336 * continue past a matched bssid that is not compatible in case there
1337 * is an AP with multiple SSIDs assigned to the same BSSID
1338 */
1339 mutex_lock(&priv->lock);
1340 list_for_each_entry(iter_bss, &priv->network_list, list) {
1341 if (compare_ether_addr(iter_bss->bssid, bssid))
1342 continue; /* bssid doesn't match */
1343 switch (mode) {
1344 case IW_MODE_INFRA:
1345 case IW_MODE_ADHOC:
1346 if (!is_network_compatible(priv, iter_bss, mode))
1347 break;
1348 found_bss = iter_bss;
1349 break;
1350 default:
1351 found_bss = iter_bss;
1352 break;
1353 }
1354 }
1355 mutex_unlock(&priv->lock);
1356
1357out:
1358 lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
1359 return found_bss;
1360}
1361
1362/**
1363 * @brief This function finds ssid in ssid list.
1364 *
1365 * Used in association code
1366 *
1367 * @param priv A pointer to struct lbs_private
1368 * @param ssid SSID to find in the list
1369 * @param bssid BSSID to qualify the SSID selection (if provided)
1370 * @param mode Network mode: Infrastructure or IBSS
1371 *
1372 * @return index in BSSID list
1373 */
1374static struct bss_descriptor *lbs_find_ssid_in_list(struct lbs_private *priv,
1375 uint8_t *ssid, uint8_t ssid_len,
1376 uint8_t *bssid, uint8_t mode,
1377 int channel)
1378{
1379 u32 bestrssi = 0;
1380 struct bss_descriptor *iter_bss = NULL;
1381 struct bss_descriptor *found_bss = NULL;
1382 struct bss_descriptor *tmp_oldest = NULL;
1383
1384 lbs_deb_enter(LBS_DEB_SCAN);
1385
1386 mutex_lock(&priv->lock);
1387
1388 list_for_each_entry(iter_bss, &priv->network_list, list) {
1389 if (!tmp_oldest ||
1390 (iter_bss->last_scanned < tmp_oldest->last_scanned))
1391 tmp_oldest = iter_bss;
1392
1393 if (lbs_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len,
1394 ssid, ssid_len) != 0)
1395 continue; /* ssid doesn't match */
1396 if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0)
1397 continue; /* bssid doesn't match */
1398 if ((channel > 0) && (iter_bss->channel != channel))
1399 continue; /* channel doesn't match */
1400
1401 switch (mode) {
1402 case IW_MODE_INFRA:
1403 case IW_MODE_ADHOC:
1404 if (!is_network_compatible(priv, iter_bss, mode))
1405 break;
1406
1407 if (bssid) {
1408 /* Found requested BSSID */
1409 found_bss = iter_bss;
1410 goto out;
1411 }
1412
1413 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
1414 bestrssi = SCAN_RSSI(iter_bss->rssi);
1415 found_bss = iter_bss;
1416 }
1417 break;
1418 case IW_MODE_AUTO:
1419 default:
1420 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
1421 bestrssi = SCAN_RSSI(iter_bss->rssi);
1422 found_bss = iter_bss;
1423 }
1424 break;
1425 }
1426 }
1427
1428out:
1429 mutex_unlock(&priv->lock);
1430 lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
1431 return found_bss;
1432}
1433
Holger Schurig69f90322007-11-23 15:43:44 +01001434static int assoc_helper_essid(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001435 struct assoc_request * assoc_req)
1436{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001437 int ret = 0;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001438 struct bss_descriptor * bss;
Dan Williamsaeea0ab2007-05-25 22:30:48 -04001439 int channel = -1;
John W. Linville9387b7c2008-09-30 20:59:05 -04001440 DECLARE_SSID_BUF(ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001441
Holger Schurig9012b282007-05-25 11:27:16 -04001442 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001443
Dan Williamsef9a2642007-05-25 16:46:33 -04001444 /* FIXME: take channel into account when picking SSIDs if a channel
1445 * is set.
1446 */
1447
Dan Williamsaeea0ab2007-05-25 22:30:48 -04001448 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
1449 channel = assoc_req->channel;
1450
Holger Schurig0765af42007-10-15 12:55:56 +02001451 lbs_deb_assoc("SSID '%s' requested\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04001452 print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len));
Dan Williams0dc5a292007-05-10 22:58:02 -04001453 if (assoc_req->mode == IW_MODE_INFRA) {
Holger Schurig10078322007-11-15 18:05:47 -05001454 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
Holger Schurig52933d82008-03-05 07:05:32 +01001455 assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001456
David Woodhouseaa21c002007-12-08 20:04:36 +00001457 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -04001458 assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001459 if (bss != NULL) {
Dan Williamse76850d2007-05-25 17:09:41 -04001460 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Dan Williams822ac032009-05-22 20:07:14 -04001461 ret = lbs_try_associate(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001462 } else {
Dan Williamsd8efea22007-05-28 23:54:55 -04001463 lbs_deb_assoc("SSID not found; cannot associate\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001464 }
Dan Williams0dc5a292007-05-10 22:58:02 -04001465 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001466 /* Scan for the network, do not save previous results. Stale
1467 * scan data will cause us to join a non-existant adhoc network
1468 */
Holger Schurig10078322007-11-15 18:05:47 -05001469 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
Holger Schurig52933d82008-03-05 07:05:32 +01001470 assoc_req->ssid_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001471
1472 /* Search for the requested SSID in the scan table */
David Woodhouseaa21c002007-12-08 20:04:36 +00001473 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -04001474 assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001475 if (bss != NULL) {
Dan Williamsd8efea22007-05-28 23:54:55 -04001476 lbs_deb_assoc("SSID found, will join\n");
Dan Williamse76850d2007-05-25 17:09:41 -04001477 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001478 lbs_adhoc_join(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001479 } else {
1480 /* else send START command */
Dan Williamsd8efea22007-05-28 23:54:55 -04001481 lbs_deb_assoc("SSID not found, creating adhoc network\n");
Dan Williamse76850d2007-05-25 17:09:41 -04001482 memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
Holger Schurig243e84e2009-10-22 15:30:47 +02001483 IEEE80211_MAX_SSID_LEN);
Dan Williamsd8efea22007-05-28 23:54:55 -04001484 assoc_req->bss.ssid_len = assoc_req->ssid_len;
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001485 lbs_adhoc_start(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001486 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487 }
1488
Holger Schurig9012b282007-05-25 11:27:16 -04001489 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001490 return ret;
1491}
1492
1493
Holger Schurig69f90322007-11-23 15:43:44 +01001494static int assoc_helper_bssid(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001495 struct assoc_request * assoc_req)
1496{
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001497 int ret = 0;
1498 struct bss_descriptor * bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001499
Johannes Berge1749612008-10-27 15:59:26 -07001500 lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %pM", assoc_req->bssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001501
1502 /* Search for index position in list for requested MAC */
David Woodhouseaa21c002007-12-08 20:04:36 +00001503 bss = lbs_find_bssid_in_list(priv, assoc_req->bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001504 assoc_req->mode);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001505 if (bss == NULL) {
Johannes Berge1749612008-10-27 15:59:26 -07001506 lbs_deb_assoc("ASSOC: WAP: BSSID %pM not found, "
1507 "cannot associate.\n", assoc_req->bssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508 goto out;
1509 }
1510
Dan Williamse76850d2007-05-25 17:09:41 -04001511 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Dan Williams0dc5a292007-05-10 22:58:02 -04001512 if (assoc_req->mode == IW_MODE_INFRA) {
Dan Williams822ac032009-05-22 20:07:14 -04001513 ret = lbs_try_associate(priv, assoc_req);
1514 lbs_deb_assoc("ASSOC: lbs_try_associate(bssid) returned %d\n",
1515 ret);
Dan Williams0dc5a292007-05-10 22:58:02 -04001516 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04001517 lbs_adhoc_join(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001518 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001519
1520out:
Holger Schurig9012b282007-05-25 11:27:16 -04001521 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522 return ret;
1523}
1524
1525
Holger Schurig69f90322007-11-23 15:43:44 +01001526static int assoc_helper_associate(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001527 struct assoc_request * assoc_req)
1528{
1529 int ret = 0, done = 0;
1530
Holger Schurig0765af42007-10-15 12:55:56 +02001531 lbs_deb_enter(LBS_DEB_ASSOC);
1532
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001533 /* If we're given and 'any' BSSID, try associating based on SSID */
1534
1535 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf20932007-05-25 17:28:30 -04001536 if (compare_ether_addr(bssid_any, assoc_req->bssid)
1537 && compare_ether_addr(bssid_off, assoc_req->bssid)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001538 ret = assoc_helper_bssid(priv, assoc_req);
1539 done = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001540 }
1541 }
1542
1543 if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
1544 ret = assoc_helper_essid(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001545 }
1546
Holger Schurig0765af42007-10-15 12:55:56 +02001547 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001548 return ret;
1549}
1550
1551
Holger Schurig69f90322007-11-23 15:43:44 +01001552static int assoc_helper_mode(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001553 struct assoc_request * assoc_req)
1554{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001555 int ret = 0;
1556
Holger Schurig9012b282007-05-25 11:27:16 -04001557 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001558
David Woodhouseaa21c002007-12-08 20:04:36 +00001559 if (assoc_req->mode == priv->mode)
Holger Schurig9012b282007-05-25 11:27:16 -04001560 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001561
Dan Williams0dc5a292007-05-10 22:58:02 -04001562 if (assoc_req->mode == IW_MODE_INFRA) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001563 if (priv->psstate != PS_STATE_FULL_POWER)
Holger Schurig10078322007-11-15 18:05:47 -05001564 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
David Woodhouseaa21c002007-12-08 20:04:36 +00001565 priv->psmode = LBS802_11POWERMODECAM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001566 }
1567
David Woodhouseaa21c002007-12-08 20:04:36 +00001568 priv->mode = assoc_req->mode;
Dan Williams39fcf7a2008-09-10 12:49:00 -04001569 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, assoc_req->mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001570
Holger Schurig9012b282007-05-25 11:27:16 -04001571done:
1572 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001573 return ret;
1574}
1575
Holger Schurig69f90322007-11-23 15:43:44 +01001576static int assoc_helper_channel(struct lbs_private *priv,
Dan Williamsef9a2642007-05-25 16:46:33 -04001577 struct assoc_request * assoc_req)
1578{
Dan Williamsef9a2642007-05-25 16:46:33 -04001579 int ret = 0;
1580
1581 lbs_deb_enter(LBS_DEB_ASSOC);
1582
David Woodhouse9f462572007-12-12 22:50:21 -05001583 ret = lbs_update_channel(priv);
David Woodhoused1a469f2007-12-16 17:21:00 -05001584 if (ret) {
David Woodhouse23d36ee2007-12-12 00:14:21 -05001585 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
David Woodhoused1a469f2007-12-16 17:21:00 -05001586 goto done;
Dan Williamsef9a2642007-05-25 16:46:33 -04001587 }
1588
Holger Schurigc14951f2009-10-22 15:30:50 +02001589 if (assoc_req->channel == priv->channel)
Dan Williamsef9a2642007-05-25 16:46:33 -04001590 goto done;
1591
David Woodhouse8642f1f2007-12-11 20:03:01 -05001592 if (priv->mesh_dev) {
David Woodhouse86062132007-12-13 00:32:36 -05001593 /* Change mesh channel first; 21.p21 firmware won't let
1594 you change channel otherwise (even though it'll return
1595 an error to this */
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001596 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP,
1597 assoc_req->channel);
David Woodhouse8642f1f2007-12-11 20:03:01 -05001598 }
1599
Dan Williamsef9a2642007-05-25 16:46:33 -04001600 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
Holger Schurigc14951f2009-10-22 15:30:50 +02001601 priv->channel, assoc_req->channel);
Dan Williamsef9a2642007-05-25 16:46:33 -04001602
Dan Williams2dd4b262007-12-11 16:54:15 -05001603 ret = lbs_set_channel(priv, assoc_req->channel);
1604 if (ret < 0)
David Woodhouse23d36ee2007-12-12 00:14:21 -05001605 lbs_deb_assoc("ASSOC: channel: error setting channel.\n");
Dan Williamsef9a2642007-05-25 16:46:33 -04001606
Dan Williams2dd4b262007-12-11 16:54:15 -05001607 /* FIXME: shouldn't need to grab the channel _again_ after setting
1608 * it since the firmware is supposed to return the new channel, but
1609 * whatever... */
David Woodhouse9f462572007-12-12 22:50:21 -05001610 ret = lbs_update_channel(priv);
David Woodhoused1a469f2007-12-16 17:21:00 -05001611 if (ret) {
David Woodhouse23d36ee2007-12-12 00:14:21 -05001612 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
David Woodhoused1a469f2007-12-16 17:21:00 -05001613 goto done;
1614 }
Dan Williamsef9a2642007-05-25 16:46:33 -04001615
Holger Schurigc14951f2009-10-22 15:30:50 +02001616 if (assoc_req->channel != priv->channel) {
David Woodhouse88ae2912007-12-11 19:57:05 -05001617 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n",
Dan Williamsef9a2642007-05-25 16:46:33 -04001618 assoc_req->channel);
David Woodhouse8642f1f2007-12-11 20:03:01 -05001619 goto restore_mesh;
Dan Williamsef9a2642007-05-25 16:46:33 -04001620 }
1621
1622 if ( assoc_req->secinfo.wep_enabled
1623 && (assoc_req->wep_keys[0].len
1624 || assoc_req->wep_keys[1].len
1625 || assoc_req->wep_keys[2].len
1626 || assoc_req->wep_keys[3].len)) {
1627 /* Make sure WEP keys are re-sent to firmware */
1628 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1629 }
1630
1631 /* Must restart/rejoin adhoc networks after channel change */
David Woodhouse23d36ee2007-12-12 00:14:21 -05001632 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Dan Williamsef9a2642007-05-25 16:46:33 -04001633
David Woodhouse8642f1f2007-12-11 20:03:01 -05001634 restore_mesh:
1635 if (priv->mesh_dev)
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001636 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
Holger Schurigc14951f2009-10-22 15:30:50 +02001637 priv->channel);
David Woodhouse8642f1f2007-12-11 20:03:01 -05001638
1639 done:
Dan Williamsef9a2642007-05-25 16:46:33 -04001640 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
1641 return ret;
1642}
1643
1644
Holger Schurig69f90322007-11-23 15:43:44 +01001645static int assoc_helper_wep_keys(struct lbs_private *priv,
David Woodhousef70dd452007-12-18 00:18:05 -05001646 struct assoc_request *assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001647{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001648 int i;
1649 int ret = 0;
1650
Holger Schurig9012b282007-05-25 11:27:16 -04001651 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001652
1653 /* Set or remove WEP keys */
David Woodhousef70dd452007-12-18 00:18:05 -05001654 if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len ||
1655 assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len)
1656 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req);
1657 else
1658 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001659
1660 if (ret)
1661 goto out;
1662
1663 /* enable/disable the MAC's WEP packet filter */
Dan Williams889c05b2007-05-10 22:57:23 -04001664 if (assoc_req->secinfo.wep_enabled)
Holger Schurigd9e97782008-03-12 16:06:43 +01001665 priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001666 else
Holger Schurigd9e97782008-03-12 16:06:43 +01001667 priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
David Woodhousef70dd452007-12-18 00:18:05 -05001668
Holger Schurigc97329e2008-03-18 11:20:21 +01001669 lbs_set_mac_control(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001670
David Woodhouseaa21c002007-12-08 20:04:36 +00001671 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001672
David Woodhouseaa21c002007-12-08 20:04:36 +00001673 /* Copy WEP keys into priv wep key fields */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001674 for (i = 0; i < 4; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001675 memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
David Woodhousef70dd452007-12-18 00:18:05 -05001676 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001677 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001678 priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001679
David Woodhouseaa21c002007-12-08 20:04:36 +00001680 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001681
1682out:
Holger Schurig9012b282007-05-25 11:27:16 -04001683 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001684 return ret;
1685}
1686
Holger Schurig69f90322007-11-23 15:43:44 +01001687static int assoc_helper_secinfo(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001688 struct assoc_request * assoc_req)
1689{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001690 int ret = 0;
David Woodhouse4f59abf2007-12-18 00:47:17 -05001691 uint16_t do_wpa;
1692 uint16_t rsn = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001693
Holger Schurig9012b282007-05-25 11:27:16 -04001694 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001695
David Woodhouseaa21c002007-12-08 20:04:36 +00001696 memcpy(&priv->secinfo, &assoc_req->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -05001697 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001698
Holger Schurigc97329e2008-03-18 11:20:21 +01001699 lbs_set_mac_control(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001700
Dan Williams18c96c342007-06-18 12:01:12 -04001701 /* If RSN is already enabled, don't try to enable it again, since
1702 * ENABLE_RSN resets internal state machines and will clobber the
1703 * 4-way WPA handshake.
1704 */
1705
1706 /* Get RSN enabled/disabled */
David Woodhouse4f59abf2007-12-18 00:47:17 -05001707 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn);
Dan Williams18c96c342007-06-18 12:01:12 -04001708 if (ret) {
David Woodhouse23d36ee2007-12-12 00:14:21 -05001709 lbs_deb_assoc("Failed to get RSN status: %d\n", ret);
Dan Williams18c96c342007-06-18 12:01:12 -04001710 goto out;
1711 }
1712
1713 /* Don't re-enable RSN if it's already enabled */
David Woodhouse4f59abf2007-12-18 00:47:17 -05001714 do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled;
Dan Williams18c96c342007-06-18 12:01:12 -04001715 if (do_wpa == rsn)
1716 goto out;
1717
1718 /* Set RSN enabled/disabled */
David Woodhouse4f59abf2007-12-18 00:47:17 -05001719 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa);
Dan Williams90a42212007-05-25 23:01:24 -04001720
1721out:
Holger Schurig9012b282007-05-25 11:27:16 -04001722 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723 return ret;
1724}
1725
1726
Holger Schurig69f90322007-11-23 15:43:44 +01001727static int assoc_helper_wpa_keys(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001728 struct assoc_request * assoc_req)
1729{
1730 int ret = 0;
Dan Williams2bcde512007-10-03 10:37:45 -04001731 unsigned int flags = assoc_req->flags;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001732
Holger Schurig9012b282007-05-25 11:27:16 -04001733 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001734
Dan Williams2bcde512007-10-03 10:37:45 -04001735 /* Work around older firmware bug where WPA unicast and multicast
1736 * keys must be set independently. Seen in SDIO parts with firmware
1737 * version 5.0.11p0.
1738 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001739
Dan Williams2bcde512007-10-03 10:37:45 -04001740 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
1741 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
David Woodhouse9e1228d2008-03-03 12:15:39 +01001742 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
Dan Williams2bcde512007-10-03 10:37:45 -04001743 assoc_req->flags = flags;
1744 }
1745
1746 if (ret)
1747 goto out;
1748
Andrey Yurovskyce8d0962009-06-17 18:45:34 -07001749 memcpy(&priv->wpa_unicast_key, &assoc_req->wpa_unicast_key,
1750 sizeof(struct enc_key));
1751
Dan Williams2bcde512007-10-03 10:37:45 -04001752 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
1753 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1754
David Woodhouse9e1228d2008-03-03 12:15:39 +01001755 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
Dan Williams2bcde512007-10-03 10:37:45 -04001756 assoc_req->flags = flags;
Andrey Yurovskyce8d0962009-06-17 18:45:34 -07001757
1758 memcpy(&priv->wpa_mcast_key, &assoc_req->wpa_mcast_key,
1759 sizeof(struct enc_key));
Dan Williams2bcde512007-10-03 10:37:45 -04001760 }
1761
1762out:
Holger Schurig9012b282007-05-25 11:27:16 -04001763 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001764 return ret;
1765}
1766
1767
Holger Schurig69f90322007-11-23 15:43:44 +01001768static int assoc_helper_wpa_ie(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001769 struct assoc_request * assoc_req)
1770{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001771 int ret = 0;
1772
Holger Schurig9012b282007-05-25 11:27:16 -04001773 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001774
1775 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001776 memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
1777 priv->wpa_ie_len = assoc_req->wpa_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001778 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +00001779 memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
1780 priv->wpa_ie_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001781 }
1782
Holger Schurig9012b282007-05-25 11:27:16 -04001783 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001784 return ret;
1785}
1786
1787
David Woodhouseaa21c002007-12-08 20:04:36 +00001788static int should_deauth_infrastructure(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001789 struct assoc_request * assoc_req)
1790{
Holger Schurig0765af42007-10-15 12:55:56 +02001791 int ret = 0;
1792
David Woodhouseaa21c002007-12-08 20:04:36 +00001793 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001794 return 0;
1795
Holger Schurig52507c22008-01-28 17:25:53 +01001796 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001797 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +02001798 lbs_deb_assoc("Deauthenticating due to new SSID\n");
1799 ret = 1;
1800 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001801 }
1802
1803 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001804 if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
Holger Schurig0765af42007-10-15 12:55:56 +02001805 lbs_deb_assoc("Deauthenticating due to new security\n");
1806 ret = 1;
1807 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001808 }
1809 }
1810
1811 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +02001812 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
1813 ret = 1;
1814 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001815 }
1816
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -04001817 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +02001818 lbs_deb_assoc("Deauthenticating due to channel switch\n");
1819 ret = 1;
1820 goto out;
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -04001821 }
1822
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001823 /* FIXME: deal with 'auto' mode somehow */
1824 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +02001825 if (assoc_req->mode != IW_MODE_INFRA) {
1826 lbs_deb_assoc("Deauthenticating due to leaving "
1827 "infra mode\n");
1828 ret = 1;
1829 goto out;
1830 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001831 }
1832
Holger Schurig0765af42007-10-15 12:55:56 +02001833out:
1834 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Holger Schurig52507c22008-01-28 17:25:53 +01001835 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001836}
1837
1838
David Woodhouseaa21c002007-12-08 20:04:36 +00001839static int should_stop_adhoc(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001840 struct assoc_request * assoc_req)
1841{
Holger Schurig0765af42007-10-15 12:55:56 +02001842 lbs_deb_enter(LBS_DEB_ASSOC);
1843
David Woodhouseaa21c002007-12-08 20:04:36 +00001844 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 return 0;
1846
David Woodhouseaa21c002007-12-08 20:04:36 +00001847 if (lbs_ssid_cmp(priv->curbssparams.ssid,
1848 priv->curbssparams.ssid_len,
Dan Williamsd8efea22007-05-28 23:54:55 -04001849 assoc_req->ssid, assoc_req->ssid_len) != 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001850 return 1;
1851
1852 /* FIXME: deal with 'auto' mode somehow */
1853 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001854 if (assoc_req->mode != IW_MODE_ADHOC)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001855 return 1;
1856 }
1857
Dan Williamsef9a2642007-05-25 16:46:33 -04001858 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
Holger Schurigc14951f2009-10-22 15:30:50 +02001859 if (assoc_req->channel != priv->channel)
Dan Williamsef9a2642007-05-25 16:46:33 -04001860 return 1;
1861 }
1862
Holger Schurig0765af42007-10-15 12:55:56 +02001863 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001864 return 0;
1865}
1866
1867
Holger Schurig245bf202008-04-02 16:27:42 +02001868/**
1869 * @brief This function finds the best SSID in the Scan List
1870 *
1871 * Search the scan table for the best SSID that also matches the current
1872 * adapter network preference (infrastructure or adhoc)
1873 *
1874 * @param priv A pointer to struct lbs_private
1875 *
1876 * @return index in BSSID list
1877 */
1878static struct bss_descriptor *lbs_find_best_ssid_in_list(
1879 struct lbs_private *priv, uint8_t mode)
1880{
1881 uint8_t bestrssi = 0;
1882 struct bss_descriptor *iter_bss;
1883 struct bss_descriptor *best_bss = NULL;
1884
1885 lbs_deb_enter(LBS_DEB_SCAN);
1886
1887 mutex_lock(&priv->lock);
1888
1889 list_for_each_entry(iter_bss, &priv->network_list, list) {
1890 switch (mode) {
1891 case IW_MODE_INFRA:
1892 case IW_MODE_ADHOC:
1893 if (!is_network_compatible(priv, iter_bss, mode))
1894 break;
1895 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
1896 break;
1897 bestrssi = SCAN_RSSI(iter_bss->rssi);
1898 best_bss = iter_bss;
1899 break;
1900 case IW_MODE_AUTO:
1901 default:
1902 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
1903 break;
1904 bestrssi = SCAN_RSSI(iter_bss->rssi);
1905 best_bss = iter_bss;
1906 break;
1907 }
1908 }
1909
1910 mutex_unlock(&priv->lock);
1911 lbs_deb_leave_args(LBS_DEB_SCAN, "best_bss %p", best_bss);
1912 return best_bss;
1913}
1914
1915/**
1916 * @brief Find the best AP
1917 *
1918 * Used from association worker.
1919 *
1920 * @param priv A pointer to struct lbs_private structure
1921 * @param pSSID A pointer to AP's ssid
1922 *
1923 * @return 0--success, otherwise--fail
1924 */
1925static int lbs_find_best_network_ssid(struct lbs_private *priv,
1926 uint8_t *out_ssid, uint8_t *out_ssid_len, uint8_t preferred_mode,
1927 uint8_t *out_mode)
1928{
1929 int ret = -1;
1930 struct bss_descriptor *found;
1931
1932 lbs_deb_enter(LBS_DEB_SCAN);
1933
1934 priv->scan_ssid_len = 0;
1935 lbs_scan_networks(priv, 1);
1936 if (priv->surpriseremoved)
1937 goto out;
1938
1939 found = lbs_find_best_ssid_in_list(priv, preferred_mode);
1940 if (found && (found->ssid_len > 0)) {
Holger Schurig243e84e2009-10-22 15:30:47 +02001941 memcpy(out_ssid, &found->ssid, IEEE80211_MAX_SSID_LEN);
Holger Schurig245bf202008-04-02 16:27:42 +02001942 *out_ssid_len = found->ssid_len;
1943 *out_mode = found->mode;
1944 ret = 0;
1945 }
1946
1947out:
1948 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
1949 return ret;
1950}
1951
1952
Holger Schurig10078322007-11-15 18:05:47 -05001953void lbs_association_worker(struct work_struct *work)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001954{
Holger Schurig69f90322007-11-23 15:43:44 +01001955 struct lbs_private *priv = container_of(work, struct lbs_private,
1956 assoc_work.work);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001957 struct assoc_request * assoc_req = NULL;
1958 int ret = 0;
1959 int find_any_ssid = 0;
John W. Linville9387b7c2008-09-30 20:59:05 -04001960 DECLARE_SSID_BUF(ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001961
Holger Schurig9012b282007-05-25 11:27:16 -04001962 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001963
David Woodhouseaa21c002007-12-08 20:04:36 +00001964 mutex_lock(&priv->lock);
1965 assoc_req = priv->pending_assoc_req;
1966 priv->pending_assoc_req = NULL;
1967 priv->in_progress_assoc_req = assoc_req;
1968 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001969
Holger Schurig9012b282007-05-25 11:27:16 -04001970 if (!assoc_req)
1971 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001972
Holger Schurig0765af42007-10-15 12:55:56 +02001973 lbs_deb_assoc(
1974 "Association Request:\n"
1975 " flags: 0x%08lx\n"
1976 " SSID: '%s'\n"
1977 " chann: %d\n"
1978 " band: %d\n"
1979 " mode: %d\n"
Johannes Berge1749612008-10-27 15:59:26 -07001980 " BSSID: %pM\n"
Holger Schurig0765af42007-10-15 12:55:56 +02001981 " secinfo: %s%s%s\n"
1982 " auth_mode: %d\n",
1983 assoc_req->flags,
John W. Linville9387b7c2008-09-30 20:59:05 -04001984 print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len),
Holger Schurig0765af42007-10-15 12:55:56 +02001985 assoc_req->channel, assoc_req->band, assoc_req->mode,
Johannes Berge1749612008-10-27 15:59:26 -07001986 assoc_req->bssid,
Holger Schurig0765af42007-10-15 12:55:56 +02001987 assoc_req->secinfo.WPAenabled ? " WPA" : "",
1988 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
1989 assoc_req->secinfo.wep_enabled ? " WEP" : "",
1990 assoc_req->secinfo.auth_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001991
1992 /* If 'any' SSID was specified, find an SSID to associate with */
1993 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
Dan Williamsd8efea22007-05-28 23:54:55 -04001994 && !assoc_req->ssid_len)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001995 find_any_ssid = 1;
1996
1997 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
1998 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf20932007-05-25 17:28:30 -04001999 if (compare_ether_addr(assoc_req->bssid, bssid_any)
2000 && compare_ether_addr(assoc_req->bssid, bssid_off))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002001 find_any_ssid = 0;
2002 }
2003
2004 if (find_any_ssid) {
Holger Schurig877cb0d2008-04-02 16:34:51 +02002005 u8 new_mode = assoc_req->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002006
Holger Schurig10078322007-11-15 18:05:47 -05002007 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -04002008 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002009 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -04002010 lbs_deb_assoc("Could not find best network\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002011 ret = -ENETUNREACH;
2012 goto out;
2013 }
2014
2015 /* Ensure we switch to the mode of the AP */
Dan Williams0dc5a292007-05-10 22:58:02 -04002016 if (assoc_req->mode == IW_MODE_AUTO) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002017 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
2018 assoc_req->mode = new_mode;
2019 }
2020 }
2021
2022 /*
2023 * Check if the attributes being changing require deauthentication
2024 * from the currently associated infrastructure access point.
2025 */
David Woodhouseaa21c002007-12-08 20:04:36 +00002026 if (priv->mode == IW_MODE_INFRA) {
2027 if (should_deauth_infrastructure(priv, assoc_req)) {
Dan Williams191bb402008-08-21 17:46:18 -04002028 ret = lbs_cmd_80211_deauthenticate(priv,
2029 priv->curbssparams.bssid,
2030 WLAN_REASON_DEAUTH_LEAVING);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002031 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -04002032 lbs_deb_assoc("Deauthentication due to new "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002033 "configuration request failed: %d\n",
2034 ret);
2035 }
2036 }
David Woodhouseaa21c002007-12-08 20:04:36 +00002037 } else if (priv->mode == IW_MODE_ADHOC) {
2038 if (should_stop_adhoc(priv, assoc_req)) {
Dan Williamsf5fe1fd2008-08-21 21:46:59 -04002039 ret = lbs_adhoc_stop(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002040 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -04002041 lbs_deb_assoc("Teardown of AdHoc network due to "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002042 "new configuration request failed: %d\n",
2043 ret);
2044 }
2045
2046 }
2047 }
2048
2049 /* Send the various configuration bits to the firmware */
2050 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
2051 ret = assoc_helper_mode(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +02002052 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002053 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002054 }
2055
Dan Williamsef9a2642007-05-25 16:46:33 -04002056 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
2057 ret = assoc_helper_channel(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +02002058 if (ret)
Dan Williamsef9a2642007-05-25 16:46:33 -04002059 goto out;
Dan Williamsef9a2642007-05-25 16:46:33 -04002060 }
2061
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002062 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
2063 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
2064 ret = assoc_helper_wep_keys(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +02002065 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002066 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002067 }
2068
2069 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
2070 ret = assoc_helper_secinfo(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +02002071 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002072 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002073 }
2074
2075 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
2076 ret = assoc_helper_wpa_ie(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +02002077 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002078 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002079 }
2080
2081 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
2082 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
2083 ret = assoc_helper_wpa_keys(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +02002084 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002085 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002086 }
2087
2088 /* SSID/BSSID should be the _last_ config option set, because they
2089 * trigger the association attempt.
2090 */
2091 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
2092 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
2093 int success = 1;
2094
2095 ret = assoc_helper_associate(priv, assoc_req);
2096 if (ret) {
Holger Schurig91843462007-11-28 14:05:02 +01002097 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002098 ret);
2099 success = 0;
2100 }
2101
David Woodhouseaa21c002007-12-08 20:04:36 +00002102 if (priv->connect_status != LBS_CONNECTED) {
Holger Schurig91843462007-11-28 14:05:02 +01002103 lbs_deb_assoc("ASSOC: association unsuccessful, "
2104 "not connected\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002105 success = 0;
2106 }
2107
2108 if (success) {
Johannes Berge1749612008-10-27 15:59:26 -07002109 lbs_deb_assoc("associated to %pM\n",
2110 priv->curbssparams.bssid);
Holger Schurig10078322007-11-15 18:05:47 -05002111 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -04002112 CMD_802_11_RSSI,
2113 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002114 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002115 ret = -1;
2116 }
2117 }
2118
2119out:
2120 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -04002121 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002122 ret);
2123 }
Dan Williamse76850d2007-05-25 17:09:41 -04002124
David Woodhouseaa21c002007-12-08 20:04:36 +00002125 mutex_lock(&priv->lock);
2126 priv->in_progress_assoc_req = NULL;
2127 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002128 kfree(assoc_req);
Holger Schurig9012b282007-05-25 11:27:16 -04002129
2130done:
2131 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002132}
2133
2134
2135/*
2136 * Caller MUST hold any necessary locks
2137 */
David Woodhouseaa21c002007-12-08 20:04:36 +00002138struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002139{
2140 struct assoc_request * assoc_req;
2141
Holger Schurig0765af42007-10-15 12:55:56 +02002142 lbs_deb_enter(LBS_DEB_ASSOC);
David Woodhouseaa21c002007-12-08 20:04:36 +00002143 if (!priv->pending_assoc_req) {
2144 priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
Dan Williamse76850d2007-05-25 17:09:41 -04002145 GFP_KERNEL);
David Woodhouseaa21c002007-12-08 20:04:36 +00002146 if (!priv->pending_assoc_req) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002147 lbs_pr_info("Not enough memory to allocate association"
2148 " request!\n");
2149 return NULL;
2150 }
2151 }
2152
2153 /* Copy current configuration attributes to the association request,
2154 * but don't overwrite any that are already set.
2155 */
David Woodhouseaa21c002007-12-08 20:04:36 +00002156 assoc_req = priv->pending_assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002157 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00002158 memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
Holger Schurig243e84e2009-10-22 15:30:47 +02002159 IEEE80211_MAX_SSID_LEN);
David Woodhouseaa21c002007-12-08 20:04:36 +00002160 assoc_req->ssid_len = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002161 }
2162
2163 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
Holger Schurigc14951f2009-10-22 15:30:50 +02002164 assoc_req->channel = priv->channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002165
Dan Williamse76850d2007-05-25 17:09:41 -04002166 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +00002167 assoc_req->band = priv->curbssparams.band;
Dan Williamse76850d2007-05-25 17:09:41 -04002168
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002169 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +00002170 assoc_req->mode = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002171
2172 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00002173 memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002174 ETH_ALEN);
2175 }
2176
2177 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
2178 int i;
2179 for (i = 0; i < 4; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +00002180 memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
Dan Williams1443b652007-08-02 10:45:55 -04002181 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002182 }
2183 }
2184
2185 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +00002186 assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002187
2188 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00002189 memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
Dan Williams1443b652007-08-02 10:45:55 -04002190 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002191 }
2192
2193 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00002194 memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
Dan Williams1443b652007-08-02 10:45:55 -04002195 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002196 }
2197
2198 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00002199 memcpy(&assoc_req->secinfo, &priv->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -05002200 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002201 }
2202
2203 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00002204 memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002205 MAX_WPA_IE_LEN);
David Woodhouseaa21c002007-12-08 20:04:36 +00002206 assoc_req->wpa_ie_len = priv->wpa_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002207 }
2208
Holger Schurig0765af42007-10-15 12:55:56 +02002209 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002210 return assoc_req;
2211}
Holger Schurig697900a2008-04-02 16:27:10 +02002212
2213
2214/**
Dan Williams191bb402008-08-21 17:46:18 -04002215 * @brief Deauthenticate from a specific BSS
2216 *
2217 * @param priv A pointer to struct lbs_private structure
2218 * @param bssid The specific BSS to deauthenticate from
2219 * @param reason The 802.11 sec. 7.3.1.7 Reason Code for deauthenticating
2220 *
2221 * @return 0 on success, error on failure
2222 */
2223int lbs_cmd_80211_deauthenticate(struct lbs_private *priv, u8 bssid[ETH_ALEN],
2224 u16 reason)
Holger Schurig697900a2008-04-02 16:27:10 +02002225{
Dan Williams191bb402008-08-21 17:46:18 -04002226 struct cmd_ds_802_11_deauthenticate cmd;
2227 int ret;
Holger Schurig697900a2008-04-02 16:27:10 +02002228
2229 lbs_deb_enter(LBS_DEB_JOIN);
2230
Dan Williams191bb402008-08-21 17:46:18 -04002231 memset(&cmd, 0, sizeof(cmd));
2232 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2233 memcpy(cmd.macaddr, &bssid[0], ETH_ALEN);
2234 cmd.reasoncode = cpu_to_le16(reason);
Holger Schurig697900a2008-04-02 16:27:10 +02002235
Dan Williams191bb402008-08-21 17:46:18 -04002236 ret = lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd);
Holger Schurig697900a2008-04-02 16:27:10 +02002237
Dan Williams191bb402008-08-21 17:46:18 -04002238 /* Clean up everything even if there was an error; can't assume that
2239 * we're still authenticated to the AP after trying to deauth.
2240 */
2241 lbs_mac_event_disconnected(priv);
Holger Schurig697900a2008-04-02 16:27:10 +02002242
2243 lbs_deb_leave(LBS_DEB_JOIN);
Dan Williams191bb402008-08-21 17:46:18 -04002244 return ret;
Holger Schurig697900a2008-04-02 16:27:10 +02002245}
2246