blob: 63bd692c7239ad9d3acfd8d3c8fda3ce487f40a4 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/* Copyright (C) 2006, Red Hat, Inc. */
2
3#include <linux/bitops.h>
4#include <net/ieee80211.h>
Dan Williams3cf209312007-05-25 17:28:30 -04005#include <linux/etherdevice.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02006
7#include "assoc.h"
8#include "join.h"
9#include "decl.h"
10#include "hostcmd.h"
11#include "host.h"
12
13
14static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
15static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
16
Dan Williamse76850d2007-05-25 17:09:41 -040017
Holger Schurig69f90322007-11-23 15:43:44 +010018static int assoc_helper_essid(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019 struct assoc_request * assoc_req)
20{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021 int ret = 0;
Dan Williamsfcdb53d2007-05-25 16:15:56 -040022 struct bss_descriptor * bss;
Dan Williamsaeea0ab2007-05-25 22:30:48 -040023 int channel = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024
Holger Schurig9012b282007-05-25 11:27:16 -040025 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020026
Dan Williamsef9a2642007-05-25 16:46:33 -040027 /* FIXME: take channel into account when picking SSIDs if a channel
28 * is set.
29 */
30
Dan Williamsaeea0ab2007-05-25 22:30:48 -040031 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
32 channel = assoc_req->channel;
33
Holger Schurig0765af42007-10-15 12:55:56 +020034 lbs_deb_assoc("SSID '%s' requested\n",
Dan Williamsd8efea22007-05-28 23:54:55 -040035 escape_essid(assoc_req->ssid, assoc_req->ssid_len));
Dan Williams0dc5a292007-05-10 22:58:02 -040036 if (assoc_req->mode == IW_MODE_INFRA) {
Holger Schurig10078322007-11-15 18:05:47 -050037 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
Holger Schurig6e22a852007-08-02 13:05:32 -040038 assoc_req->ssid_len, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020039
David Woodhouseaa21c002007-12-08 20:04:36 +000040 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040041 assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040042 if (bss != NULL) {
Dan Williamse76850d2007-05-25 17:09:41 -040043 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Holger Schurig10078322007-11-15 18:05:47 -050044 ret = lbs_associate(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020045 } else {
Dan Williamsd8efea22007-05-28 23:54:55 -040046 lbs_deb_assoc("SSID not found; cannot associate\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020047 }
Dan Williams0dc5a292007-05-10 22:58:02 -040048 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020049 /* Scan for the network, do not save previous results. Stale
50 * scan data will cause us to join a non-existant adhoc network
51 */
Holger Schurig10078322007-11-15 18:05:47 -050052 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040053 assoc_req->ssid_len, 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020054
55 /* Search for the requested SSID in the scan table */
David Woodhouseaa21c002007-12-08 20:04:36 +000056 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040057 assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040058 if (bss != NULL) {
Dan Williamsd8efea22007-05-28 23:54:55 -040059 lbs_deb_assoc("SSID found, will join\n");
Dan Williamse76850d2007-05-25 17:09:41 -040060 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Holger Schurig10078322007-11-15 18:05:47 -050061 lbs_join_adhoc_network(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062 } else {
63 /* else send START command */
Dan Williamsd8efea22007-05-28 23:54:55 -040064 lbs_deb_assoc("SSID not found, creating adhoc network\n");
Dan Williamse76850d2007-05-25 17:09:41 -040065 memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040066 IW_ESSID_MAX_SIZE);
67 assoc_req->bss.ssid_len = assoc_req->ssid_len;
Holger Schurig10078322007-11-15 18:05:47 -050068 lbs_start_adhoc_network(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020069 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020070 }
71
Holger Schurig9012b282007-05-25 11:27:16 -040072 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020073 return ret;
74}
75
76
Holger Schurig69f90322007-11-23 15:43:44 +010077static int assoc_helper_bssid(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020078 struct assoc_request * assoc_req)
79{
Dan Williamsfcdb53d2007-05-25 16:15:56 -040080 int ret = 0;
81 struct bss_descriptor * bss;
Joe Perches0795af52007-10-03 17:59:30 -070082 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020083
Joe Perches0795af52007-10-03 17:59:30 -070084 lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %s",
85 print_mac(mac, assoc_req->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020086
87 /* Search for index position in list for requested MAC */
David Woodhouseaa21c002007-12-08 20:04:36 +000088 bss = lbs_find_bssid_in_list(priv, assoc_req->bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089 assoc_req->mode);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040090 if (bss == NULL) {
Joe Perches0795af52007-10-03 17:59:30 -070091 lbs_deb_assoc("ASSOC: WAP: BSSID %s not found, "
92 "cannot associate.\n", print_mac(mac, assoc_req->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093 goto out;
94 }
95
Dan Williamse76850d2007-05-25 17:09:41 -040096 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Dan Williams0dc5a292007-05-10 22:58:02 -040097 if (assoc_req->mode == IW_MODE_INFRA) {
Holger Schurig10078322007-11-15 18:05:47 -050098 ret = lbs_associate(priv, assoc_req);
99 lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret);
Dan Williams0dc5a292007-05-10 22:58:02 -0400100 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Holger Schurig10078322007-11-15 18:05:47 -0500101 lbs_join_adhoc_network(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200102 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200103
104out:
Holger Schurig9012b282007-05-25 11:27:16 -0400105 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200106 return ret;
107}
108
109
Holger Schurig69f90322007-11-23 15:43:44 +0100110static int assoc_helper_associate(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111 struct assoc_request * assoc_req)
112{
113 int ret = 0, done = 0;
114
Holger Schurig0765af42007-10-15 12:55:56 +0200115 lbs_deb_enter(LBS_DEB_ASSOC);
116
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200117 /* If we're given and 'any' BSSID, try associating based on SSID */
118
119 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf209312007-05-25 17:28:30 -0400120 if (compare_ether_addr(bssid_any, assoc_req->bssid)
121 && compare_ether_addr(bssid_off, assoc_req->bssid)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200122 ret = assoc_helper_bssid(priv, assoc_req);
123 done = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200124 }
125 }
126
127 if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
128 ret = assoc_helper_essid(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129 }
130
Holger Schurig0765af42007-10-15 12:55:56 +0200131 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200132 return ret;
133}
134
135
Holger Schurig69f90322007-11-23 15:43:44 +0100136static int assoc_helper_mode(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200137 struct assoc_request * assoc_req)
138{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139 int ret = 0;
140
Holger Schurig9012b282007-05-25 11:27:16 -0400141 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142
David Woodhouseaa21c002007-12-08 20:04:36 +0000143 if (assoc_req->mode == priv->mode)
Holger Schurig9012b282007-05-25 11:27:16 -0400144 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200145
Dan Williams0dc5a292007-05-10 22:58:02 -0400146 if (assoc_req->mode == IW_MODE_INFRA) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000147 if (priv->psstate != PS_STATE_FULL_POWER)
Holger Schurig10078322007-11-15 18:05:47 -0500148 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
David Woodhouseaa21c002007-12-08 20:04:36 +0000149 priv->psmode = LBS802_11POWERMODECAM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200150 }
151
David Woodhouseaa21c002007-12-08 20:04:36 +0000152 priv->mode = assoc_req->mode;
Holger Schurig10078322007-11-15 18:05:47 -0500153 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400154 CMD_802_11_SNMP_MIB,
155 0, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156 OID_802_11_INFRASTRUCTURE_MODE,
David Woodhouse981f1872007-05-25 23:36:54 -0400157 /* Shoot me now */ (void *) (size_t) assoc_req->mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158
Holger Schurig9012b282007-05-25 11:27:16 -0400159done:
160 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161 return ret;
162}
163
164
Holger Schurig69f90322007-11-23 15:43:44 +0100165static int update_channel(struct lbs_private *priv)
Dan Williamsef9a2642007-05-25 16:46:33 -0400166{
Holger Schurig0765af42007-10-15 12:55:56 +0200167 int ret;
Dan Williamsef9a2642007-05-25 16:46:33 -0400168 /* the channel in f/w could be out of sync, get the current channel */
Holger Schurig0765af42007-10-15 12:55:56 +0200169 lbs_deb_enter(LBS_DEB_ASSOC);
170 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RF_CHANNEL,
Dan Williams0aef64d2007-08-02 11:31:18 -0400171 CMD_OPT_802_11_RF_CHANNEL_GET,
172 CMD_OPTION_WAITFORRSP, 0, NULL);
Holger Schurig0765af42007-10-15 12:55:56 +0200173 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
174 return ret;
Dan Williamsef9a2642007-05-25 16:46:33 -0400175}
176
Holger Schurig10078322007-11-15 18:05:47 -0500177void lbs_sync_channel(struct work_struct *work)
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400178{
Holger Schurig69f90322007-11-23 15:43:44 +0100179 struct lbs_private *priv = container_of(work, struct lbs_private,
180 sync_channel);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400181
Holger Schurig0765af42007-10-15 12:55:56 +0200182 lbs_deb_enter(LBS_DEB_ASSOC);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400183 if (update_channel(priv) != 0)
184 lbs_pr_info("Channel synchronization failed.");
Holger Schurig0765af42007-10-15 12:55:56 +0200185 lbs_deb_leave(LBS_DEB_ASSOC);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400186}
187
Holger Schurig69f90322007-11-23 15:43:44 +0100188static int assoc_helper_channel(struct lbs_private *priv,
Dan Williamsef9a2642007-05-25 16:46:33 -0400189 struct assoc_request * assoc_req)
190{
Dan Williamsef9a2642007-05-25 16:46:33 -0400191 int ret = 0;
192
193 lbs_deb_enter(LBS_DEB_ASSOC);
194
195 ret = update_channel(priv);
196 if (ret < 0) {
197 lbs_deb_assoc("ASSOC: channel: error getting channel.");
198 }
199
David Woodhouseaa21c002007-12-08 20:04:36 +0000200 if (assoc_req->channel == priv->curbssparams.channel)
Dan Williamsef9a2642007-05-25 16:46:33 -0400201 goto done;
202
203 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000204 priv->curbssparams.channel, assoc_req->channel);
Dan Williamsef9a2642007-05-25 16:46:33 -0400205
Holger Schurig10078322007-11-15 18:05:47 -0500206 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RF_CHANNEL,
Dan Williams0aef64d2007-08-02 11:31:18 -0400207 CMD_OPT_802_11_RF_CHANNEL_SET,
208 CMD_OPTION_WAITFORRSP, 0, &assoc_req->channel);
Dan Williamsef9a2642007-05-25 16:46:33 -0400209 if (ret < 0) {
210 lbs_deb_assoc("ASSOC: channel: error setting channel.");
211 }
212
213 ret = update_channel(priv);
214 if (ret < 0) {
215 lbs_deb_assoc("ASSOC: channel: error getting channel.");
216 }
217
David Woodhouseaa21c002007-12-08 20:04:36 +0000218 if (assoc_req->channel != priv->curbssparams.channel) {
Dan Williamsef9a2642007-05-25 16:46:33 -0400219 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d",
220 assoc_req->channel);
221 goto done;
222 }
223
224 if ( assoc_req->secinfo.wep_enabled
225 && (assoc_req->wep_keys[0].len
226 || assoc_req->wep_keys[1].len
227 || assoc_req->wep_keys[2].len
228 || assoc_req->wep_keys[3].len)) {
229 /* Make sure WEP keys are re-sent to firmware */
230 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
231 }
232
233 /* Must restart/rejoin adhoc networks after channel change */
234 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
235
236done:
237 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
238 return ret;
239}
240
241
Holger Schurig69f90322007-11-23 15:43:44 +0100242static int assoc_helper_wep_keys(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243 struct assoc_request * assoc_req)
244{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200245 int i;
246 int ret = 0;
247
Holger Schurig9012b282007-05-25 11:27:16 -0400248 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249
250 /* Set or remove WEP keys */
251 if ( assoc_req->wep_keys[0].len
252 || assoc_req->wep_keys[1].len
253 || assoc_req->wep_keys[2].len
254 || assoc_req->wep_keys[3].len) {
Holger Schurig10078322007-11-15 18:05:47 -0500255 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400256 CMD_802_11_SET_WEP,
257 CMD_ACT_ADD,
258 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200259 0, assoc_req);
260 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500261 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400262 CMD_802_11_SET_WEP,
263 CMD_ACT_REMOVE,
264 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265 0, NULL);
266 }
267
268 if (ret)
269 goto out;
270
271 /* enable/disable the MAC's WEP packet filter */
Dan Williams889c05b2007-05-10 22:57:23 -0400272 if (assoc_req->secinfo.wep_enabled)
David Woodhouseaa21c002007-12-08 20:04:36 +0000273 priv->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200274 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000275 priv->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE;
Holger Schurig10078322007-11-15 18:05:47 -0500276 ret = lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200277 if (ret)
278 goto out;
279
David Woodhouseaa21c002007-12-08 20:04:36 +0000280 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200281
David Woodhouseaa21c002007-12-08 20:04:36 +0000282 /* Copy WEP keys into priv wep key fields */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200283 for (i = 0; i < 4; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000284 memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
Dan Williams1443b652007-08-02 10:45:55 -0400285 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000287 priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200288
David Woodhouseaa21c002007-12-08 20:04:36 +0000289 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200290
291out:
Holger Schurig9012b282007-05-25 11:27:16 -0400292 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200293 return ret;
294}
295
Holger Schurig69f90322007-11-23 15:43:44 +0100296static int assoc_helper_secinfo(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297 struct assoc_request * assoc_req)
298{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200299 int ret = 0;
Dan Williams18c96c342007-06-18 12:01:12 -0400300 u32 do_wpa;
301 u32 rsn = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302
Holger Schurig9012b282007-05-25 11:27:16 -0400303 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200304
David Woodhouseaa21c002007-12-08 20:04:36 +0000305 memcpy(&priv->secinfo, &assoc_req->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500306 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307
Holger Schurig10078322007-11-15 18:05:47 -0500308 ret = lbs_set_mac_packet_filter(priv);
Dan Williams90a42212007-05-25 23:01:24 -0400309 if (ret)
310 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200311
Dan Williams18c96c342007-06-18 12:01:12 -0400312 /* If RSN is already enabled, don't try to enable it again, since
313 * ENABLE_RSN resets internal state machines and will clobber the
314 * 4-way WPA handshake.
315 */
316
317 /* Get RSN enabled/disabled */
Holger Schurig10078322007-11-15 18:05:47 -0500318 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400319 CMD_802_11_ENABLE_RSN,
320 CMD_ACT_GET,
321 CMD_OPTION_WAITFORRSP,
Dan Williams18c96c342007-06-18 12:01:12 -0400322 0, &rsn);
323 if (ret) {
324 lbs_deb_assoc("Failed to get RSN status: %d", ret);
325 goto out;
326 }
327
328 /* Don't re-enable RSN if it's already enabled */
329 do_wpa = (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled);
330 if (do_wpa == rsn)
331 goto out;
332
333 /* Set RSN enabled/disabled */
334 rsn = do_wpa;
Holger Schurig10078322007-11-15 18:05:47 -0500335 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400336 CMD_802_11_ENABLE_RSN,
337 CMD_ACT_SET,
338 CMD_OPTION_WAITFORRSP,
Dan Williams18c96c342007-06-18 12:01:12 -0400339 0, &rsn);
Dan Williams90a42212007-05-25 23:01:24 -0400340
341out:
Holger Schurig9012b282007-05-25 11:27:16 -0400342 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343 return ret;
344}
345
346
Holger Schurig69f90322007-11-23 15:43:44 +0100347static int assoc_helper_wpa_keys(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200348 struct assoc_request * assoc_req)
349{
350 int ret = 0;
Dan Williams2bcde512007-10-03 10:37:45 -0400351 unsigned int flags = assoc_req->flags;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200352
Holger Schurig9012b282007-05-25 11:27:16 -0400353 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354
Dan Williams2bcde512007-10-03 10:37:45 -0400355 /* Work around older firmware bug where WPA unicast and multicast
356 * keys must be set independently. Seen in SDIO parts with firmware
357 * version 5.0.11p0.
358 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200359
Dan Williams2bcde512007-10-03 10:37:45 -0400360 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
361 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500362 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400363 CMD_802_11_KEY_MATERIAL,
364 CMD_ACT_SET,
365 CMD_OPTION_WAITFORRSP,
366 0, assoc_req);
367 assoc_req->flags = flags;
368 }
369
370 if (ret)
371 goto out;
372
373 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
374 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
375
Holger Schurig10078322007-11-15 18:05:47 -0500376 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400377 CMD_802_11_KEY_MATERIAL,
378 CMD_ACT_SET,
379 CMD_OPTION_WAITFORRSP,
380 0, assoc_req);
381 assoc_req->flags = flags;
382 }
383
384out:
Holger Schurig9012b282007-05-25 11:27:16 -0400385 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386 return ret;
387}
388
389
Holger Schurig69f90322007-11-23 15:43:44 +0100390static int assoc_helper_wpa_ie(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391 struct assoc_request * assoc_req)
392{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200393 int ret = 0;
394
Holger Schurig9012b282007-05-25 11:27:16 -0400395 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396
397 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000398 memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
399 priv->wpa_ie_len = assoc_req->wpa_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000401 memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
402 priv->wpa_ie_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403 }
404
Holger Schurig9012b282007-05-25 11:27:16 -0400405 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200406 return ret;
407}
408
409
David Woodhouseaa21c002007-12-08 20:04:36 +0000410static int should_deauth_infrastructure(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200411 struct assoc_request * assoc_req)
412{
Holger Schurig0765af42007-10-15 12:55:56 +0200413 int ret = 0;
414
415 lbs_deb_enter(LBS_DEB_ASSOC);
416
David Woodhouseaa21c002007-12-08 20:04:36 +0000417 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200418 return 0;
419
420 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200421 lbs_deb_assoc("Deauthenticating due to new SSID\n");
422 ret = 1;
423 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200424 }
425
426 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000427 if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
Holger Schurig0765af42007-10-15 12:55:56 +0200428 lbs_deb_assoc("Deauthenticating due to new security\n");
429 ret = 1;
430 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431 }
432 }
433
434 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200435 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
436 ret = 1;
437 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200438 }
439
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400440 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200441 lbs_deb_assoc("Deauthenticating due to channel switch\n");
442 ret = 1;
443 goto out;
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400444 }
445
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200446 /* FIXME: deal with 'auto' mode somehow */
447 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200448 if (assoc_req->mode != IW_MODE_INFRA) {
449 lbs_deb_assoc("Deauthenticating due to leaving "
450 "infra mode\n");
451 ret = 1;
452 goto out;
453 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200454 }
455
Holger Schurig0765af42007-10-15 12:55:56 +0200456out:
457 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200458 return 0;
459}
460
461
David Woodhouseaa21c002007-12-08 20:04:36 +0000462static int should_stop_adhoc(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200463 struct assoc_request * assoc_req)
464{
Holger Schurig0765af42007-10-15 12:55:56 +0200465 lbs_deb_enter(LBS_DEB_ASSOC);
466
David Woodhouseaa21c002007-12-08 20:04:36 +0000467 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200468 return 0;
469
David Woodhouseaa21c002007-12-08 20:04:36 +0000470 if (lbs_ssid_cmp(priv->curbssparams.ssid,
471 priv->curbssparams.ssid_len,
Dan Williamsd8efea22007-05-28 23:54:55 -0400472 assoc_req->ssid, assoc_req->ssid_len) != 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200473 return 1;
474
475 /* FIXME: deal with 'auto' mode somehow */
476 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400477 if (assoc_req->mode != IW_MODE_ADHOC)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200478 return 1;
479 }
480
Dan Williamsef9a2642007-05-25 16:46:33 -0400481 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000482 if (assoc_req->channel != priv->curbssparams.channel)
Dan Williamsef9a2642007-05-25 16:46:33 -0400483 return 1;
484 }
485
Holger Schurig0765af42007-10-15 12:55:56 +0200486 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200487 return 0;
488}
489
490
Holger Schurig10078322007-11-15 18:05:47 -0500491void lbs_association_worker(struct work_struct *work)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200492{
Holger Schurig69f90322007-11-23 15:43:44 +0100493 struct lbs_private *priv = container_of(work, struct lbs_private,
494 assoc_work.work);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495 struct assoc_request * assoc_req = NULL;
496 int ret = 0;
497 int find_any_ssid = 0;
Joe Perches0795af52007-10-03 17:59:30 -0700498 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499
Holger Schurig9012b282007-05-25 11:27:16 -0400500 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501
David Woodhouseaa21c002007-12-08 20:04:36 +0000502 mutex_lock(&priv->lock);
503 assoc_req = priv->pending_assoc_req;
504 priv->pending_assoc_req = NULL;
505 priv->in_progress_assoc_req = assoc_req;
506 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
Holger Schurig9012b282007-05-25 11:27:16 -0400508 if (!assoc_req)
509 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200510
Holger Schurig0765af42007-10-15 12:55:56 +0200511 lbs_deb_assoc(
512 "Association Request:\n"
513 " flags: 0x%08lx\n"
514 " SSID: '%s'\n"
515 " chann: %d\n"
516 " band: %d\n"
517 " mode: %d\n"
518 " BSSID: %s\n"
519 " secinfo: %s%s%s\n"
520 " auth_mode: %d\n",
521 assoc_req->flags,
522 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
523 assoc_req->channel, assoc_req->band, assoc_req->mode,
524 print_mac(mac, assoc_req->bssid),
525 assoc_req->secinfo.WPAenabled ? " WPA" : "",
526 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
527 assoc_req->secinfo.wep_enabled ? " WEP" : "",
528 assoc_req->secinfo.auth_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529
530 /* If 'any' SSID was specified, find an SSID to associate with */
531 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
Dan Williamsd8efea22007-05-28 23:54:55 -0400532 && !assoc_req->ssid_len)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200533 find_any_ssid = 1;
534
535 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
536 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf209312007-05-25 17:28:30 -0400537 if (compare_ether_addr(assoc_req->bssid, bssid_any)
538 && compare_ether_addr(assoc_req->bssid, bssid_off))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200539 find_any_ssid = 0;
540 }
541
542 if (find_any_ssid) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400543 u8 new_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200544
Holger Schurig10078322007-11-15 18:05:47 -0500545 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400546 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400548 lbs_deb_assoc("Could not find best network\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200549 ret = -ENETUNREACH;
550 goto out;
551 }
552
553 /* Ensure we switch to the mode of the AP */
Dan Williams0dc5a292007-05-10 22:58:02 -0400554 if (assoc_req->mode == IW_MODE_AUTO) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200555 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
556 assoc_req->mode = new_mode;
557 }
558 }
559
560 /*
561 * Check if the attributes being changing require deauthentication
562 * from the currently associated infrastructure access point.
563 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000564 if (priv->mode == IW_MODE_INFRA) {
565 if (should_deauth_infrastructure(priv, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500566 ret = lbs_send_deauthentication(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400568 lbs_deb_assoc("Deauthentication due to new "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200569 "configuration request failed: %d\n",
570 ret);
571 }
572 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000573 } else if (priv->mode == IW_MODE_ADHOC) {
574 if (should_stop_adhoc(priv, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500575 ret = lbs_stop_adhoc_network(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400577 lbs_deb_assoc("Teardown of AdHoc network due to "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200578 "new configuration request failed: %d\n",
579 ret);
580 }
581
582 }
583 }
584
585 /* Send the various configuration bits to the firmware */
586 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
587 ret = assoc_helper_mode(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200588 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200590 }
591
Dan Williamsef9a2642007-05-25 16:46:33 -0400592 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
593 ret = assoc_helper_channel(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200594 if (ret)
Dan Williamsef9a2642007-05-25 16:46:33 -0400595 goto out;
Dan Williamsef9a2642007-05-25 16:46:33 -0400596 }
597
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200598 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
599 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
600 ret = assoc_helper_wep_keys(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200601 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200602 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603 }
604
605 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
606 ret = assoc_helper_secinfo(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200607 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609 }
610
611 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
612 ret = assoc_helper_wpa_ie(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200613 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615 }
616
617 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
618 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
619 ret = assoc_helper_wpa_keys(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200620 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200622 }
623
624 /* SSID/BSSID should be the _last_ config option set, because they
625 * trigger the association attempt.
626 */
627 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
628 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
629 int success = 1;
630
631 ret = assoc_helper_associate(priv, assoc_req);
632 if (ret) {
Holger Schurig91843462007-11-28 14:05:02 +0100633 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634 ret);
635 success = 0;
636 }
637
David Woodhouseaa21c002007-12-08 20:04:36 +0000638 if (priv->connect_status != LBS_CONNECTED) {
Holger Schurig91843462007-11-28 14:05:02 +0100639 lbs_deb_assoc("ASSOC: association unsuccessful, "
640 "not connected\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 success = 0;
642 }
643
644 if (success) {
Holger Schurig91843462007-11-28 14:05:02 +0100645 lbs_deb_assoc("ASSOC: associated to '%s', %s\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000646 escape_essid(priv->curbssparams.ssid,
647 priv->curbssparams.ssid_len),
648 print_mac(mac, priv->curbssparams.bssid));
Holger Schurig10078322007-11-15 18:05:47 -0500649 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400650 CMD_802_11_RSSI,
651 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200652
Holger Schurig10078322007-11-15 18:05:47 -0500653 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400654 CMD_802_11_GET_LOG,
655 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200656 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200657 ret = -1;
658 }
659 }
660
661out:
662 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400663 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664 ret);
665 }
Dan Williamse76850d2007-05-25 17:09:41 -0400666
David Woodhouseaa21c002007-12-08 20:04:36 +0000667 mutex_lock(&priv->lock);
668 priv->in_progress_assoc_req = NULL;
669 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200670 kfree(assoc_req);
Holger Schurig9012b282007-05-25 11:27:16 -0400671
672done:
673 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200674}
675
676
677/*
678 * Caller MUST hold any necessary locks
679 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000680struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200681{
682 struct assoc_request * assoc_req;
683
Holger Schurig0765af42007-10-15 12:55:56 +0200684 lbs_deb_enter(LBS_DEB_ASSOC);
David Woodhouseaa21c002007-12-08 20:04:36 +0000685 if (!priv->pending_assoc_req) {
686 priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
Dan Williamse76850d2007-05-25 17:09:41 -0400687 GFP_KERNEL);
David Woodhouseaa21c002007-12-08 20:04:36 +0000688 if (!priv->pending_assoc_req) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200689 lbs_pr_info("Not enough memory to allocate association"
690 " request!\n");
691 return NULL;
692 }
693 }
694
695 /* Copy current configuration attributes to the association request,
696 * but don't overwrite any that are already set.
697 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000698 assoc_req = priv->pending_assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200699 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000700 memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400701 IW_ESSID_MAX_SIZE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000702 assoc_req->ssid_len = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200703 }
704
705 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000706 assoc_req->channel = priv->curbssparams.channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707
Dan Williamse76850d2007-05-25 17:09:41 -0400708 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000709 assoc_req->band = priv->curbssparams.band;
Dan Williamse76850d2007-05-25 17:09:41 -0400710
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200711 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000712 assoc_req->mode = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200713
714 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000715 memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200716 ETH_ALEN);
717 }
718
719 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
720 int i;
721 for (i = 0; i < 4; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000722 memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
Dan Williams1443b652007-08-02 10:45:55 -0400723 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 }
725 }
726
727 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000728 assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729
730 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000731 memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400732 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200733 }
734
735 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000736 memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400737 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200738 }
739
740 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000741 memcpy(&assoc_req->secinfo, &priv->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500742 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200743 }
744
745 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000746 memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747 MAX_WPA_IE_LEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000748 assoc_req->wpa_ie_len = priv->wpa_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749 }
750
Holger Schurig0765af42007-10-15 12:55:56 +0200751 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200752 return assoc_req;
753}