blob: f634c9496ec284a1730c54b481e4f1dfee4a41ee [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 Schurig10078322007-11-15 18:05:47 -050018static int assoc_helper_essid(lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019 struct assoc_request * assoc_req)
20{
Holger Schurig10078322007-11-15 18:05:47 -050021 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022 int ret = 0;
Dan Williamsfcdb53d2007-05-25 16:15:56 -040023 struct bss_descriptor * bss;
Dan Williamsaeea0ab2007-05-25 22:30:48 -040024 int channel = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020025
Holger Schurig9012b282007-05-25 11:27:16 -040026 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020027
Dan Williamsef9a2642007-05-25 16:46:33 -040028 /* FIXME: take channel into account when picking SSIDs if a channel
29 * is set.
30 */
31
Dan Williamsaeea0ab2007-05-25 22:30:48 -040032 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
33 channel = assoc_req->channel;
34
Holger Schurig0765af42007-10-15 12:55:56 +020035 lbs_deb_assoc("SSID '%s' requested\n",
Dan Williamsd8efea22007-05-28 23:54:55 -040036 escape_essid(assoc_req->ssid, assoc_req->ssid_len));
Dan Williams0dc5a292007-05-10 22:58:02 -040037 if (assoc_req->mode == IW_MODE_INFRA) {
Holger Schurig10078322007-11-15 18:05:47 -050038 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
Holger Schurig6e22a852007-08-02 13:05:32 -040039 assoc_req->ssid_len, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020040
Holger Schurig10078322007-11-15 18:05:47 -050041 bss = lbs_find_ssid_in_list(adapter, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040042 assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040043 if (bss != NULL) {
Dan Williamse76850d2007-05-25 17:09:41 -040044 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Holger Schurig10078322007-11-15 18:05:47 -050045 ret = lbs_associate(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020046 } else {
Dan Williamsd8efea22007-05-28 23:54:55 -040047 lbs_deb_assoc("SSID not found; cannot associate\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048 }
Dan Williams0dc5a292007-05-10 22:58:02 -040049 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020050 /* Scan for the network, do not save previous results. Stale
51 * scan data will cause us to join a non-existant adhoc network
52 */
Holger Schurig10078322007-11-15 18:05:47 -050053 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040054 assoc_req->ssid_len, 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020055
56 /* Search for the requested SSID in the scan table */
Holger Schurig10078322007-11-15 18:05:47 -050057 bss = lbs_find_ssid_in_list(adapter, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040058 assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040059 if (bss != NULL) {
Dan Williamsd8efea22007-05-28 23:54:55 -040060 lbs_deb_assoc("SSID found, will join\n");
Dan Williamse76850d2007-05-25 17:09:41 -040061 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Holger Schurig10078322007-11-15 18:05:47 -050062 lbs_join_adhoc_network(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063 } else {
64 /* else send START command */
Dan Williamsd8efea22007-05-28 23:54:55 -040065 lbs_deb_assoc("SSID not found, creating adhoc network\n");
Dan Williamse76850d2007-05-25 17:09:41 -040066 memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040067 IW_ESSID_MAX_SIZE);
68 assoc_req->bss.ssid_len = assoc_req->ssid_len;
Holger Schurig10078322007-11-15 18:05:47 -050069 lbs_start_adhoc_network(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020070 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020071 }
72
Holger Schurig9012b282007-05-25 11:27:16 -040073 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 return ret;
75}
76
77
Holger Schurig10078322007-11-15 18:05:47 -050078static int assoc_helper_bssid(lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020079 struct assoc_request * assoc_req)
80{
Holger Schurig10078322007-11-15 18:05:47 -050081 lbs_adapter *adapter = priv->adapter;
Dan Williamsfcdb53d2007-05-25 16:15:56 -040082 int ret = 0;
83 struct bss_descriptor * bss;
Joe Perches0795af52007-10-03 17:59:30 -070084 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020085
Joe Perches0795af52007-10-03 17:59:30 -070086 lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %s",
87 print_mac(mac, assoc_req->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020088
89 /* Search for index position in list for requested MAC */
Holger Schurig10078322007-11-15 18:05:47 -050090 bss = lbs_find_bssid_in_list(adapter, assoc_req->bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020091 assoc_req->mode);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040092 if (bss == NULL) {
Joe Perches0795af52007-10-03 17:59:30 -070093 lbs_deb_assoc("ASSOC: WAP: BSSID %s not found, "
94 "cannot associate.\n", print_mac(mac, assoc_req->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020095 goto out;
96 }
97
Dan Williamse76850d2007-05-25 17:09:41 -040098 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Dan Williams0dc5a292007-05-10 22:58:02 -040099 if (assoc_req->mode == IW_MODE_INFRA) {
Holger Schurig10078322007-11-15 18:05:47 -0500100 ret = lbs_associate(priv, assoc_req);
101 lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret);
Dan Williams0dc5a292007-05-10 22:58:02 -0400102 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Holger Schurig10078322007-11-15 18:05:47 -0500103 lbs_join_adhoc_network(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200104 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200105
106out:
Holger Schurig9012b282007-05-25 11:27:16 -0400107 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200108 return ret;
109}
110
111
Holger Schurig10078322007-11-15 18:05:47 -0500112static int assoc_helper_associate(lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200113 struct assoc_request * assoc_req)
114{
115 int ret = 0, done = 0;
116
Holger Schurig0765af42007-10-15 12:55:56 +0200117 lbs_deb_enter(LBS_DEB_ASSOC);
118
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200119 /* If we're given and 'any' BSSID, try associating based on SSID */
120
121 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf209312007-05-25 17:28:30 -0400122 if (compare_ether_addr(bssid_any, assoc_req->bssid)
123 && compare_ether_addr(bssid_off, assoc_req->bssid)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200124 ret = assoc_helper_bssid(priv, assoc_req);
125 done = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200126 }
127 }
128
129 if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
130 ret = assoc_helper_essid(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200131 }
132
Holger Schurig0765af42007-10-15 12:55:56 +0200133 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134 return ret;
135}
136
137
Holger Schurig10078322007-11-15 18:05:47 -0500138static int assoc_helper_mode(lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139 struct assoc_request * assoc_req)
140{
Holger Schurig10078322007-11-15 18:05:47 -0500141 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142 int ret = 0;
143
Holger Schurig9012b282007-05-25 11:27:16 -0400144 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200145
Holger Schurig9012b282007-05-25 11:27:16 -0400146 if (assoc_req->mode == adapter->mode)
147 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148
Dan Williams0dc5a292007-05-10 22:58:02 -0400149 if (assoc_req->mode == IW_MODE_INFRA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200150 if (adapter->psstate != PS_STATE_FULL_POWER)
Holger Schurig10078322007-11-15 18:05:47 -0500151 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
152 adapter->psmode = LBS802_11POWERMODECAM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200153 }
154
Dan Williams0dc5a292007-05-10 22:58:02 -0400155 adapter->mode = assoc_req->mode;
Holger Schurig10078322007-11-15 18:05:47 -0500156 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400157 CMD_802_11_SNMP_MIB,
158 0, CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159 OID_802_11_INFRASTRUCTURE_MODE,
David Woodhouse981f1872007-05-25 23:36:54 -0400160 /* Shoot me now */ (void *) (size_t) assoc_req->mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161
Holger Schurig9012b282007-05-25 11:27:16 -0400162done:
163 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200164 return ret;
165}
166
167
Holger Schurig10078322007-11-15 18:05:47 -0500168static int update_channel(lbs_private * priv)
Dan Williamsef9a2642007-05-25 16:46:33 -0400169{
Holger Schurig0765af42007-10-15 12:55:56 +0200170 int ret;
Dan Williamsef9a2642007-05-25 16:46:33 -0400171 /* the channel in f/w could be out of sync, get the current channel */
Holger Schurig0765af42007-10-15 12:55:56 +0200172 lbs_deb_enter(LBS_DEB_ASSOC);
173 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RF_CHANNEL,
Dan Williams0aef64d2007-08-02 11:31:18 -0400174 CMD_OPT_802_11_RF_CHANNEL_GET,
175 CMD_OPTION_WAITFORRSP, 0, NULL);
Holger Schurig0765af42007-10-15 12:55:56 +0200176 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
177 return ret;
Dan Williamsef9a2642007-05-25 16:46:33 -0400178}
179
Holger Schurig10078322007-11-15 18:05:47 -0500180void lbs_sync_channel(struct work_struct *work)
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400181{
Holger Schurig10078322007-11-15 18:05:47 -0500182 lbs_private *priv = container_of(work, lbs_private, sync_channel);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400183
Holger Schurig0765af42007-10-15 12:55:56 +0200184 lbs_deb_enter(LBS_DEB_ASSOC);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400185 if (update_channel(priv) != 0)
186 lbs_pr_info("Channel synchronization failed.");
Holger Schurig0765af42007-10-15 12:55:56 +0200187 lbs_deb_leave(LBS_DEB_ASSOC);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400188}
189
Holger Schurig10078322007-11-15 18:05:47 -0500190static int assoc_helper_channel(lbs_private *priv,
Dan Williamsef9a2642007-05-25 16:46:33 -0400191 struct assoc_request * assoc_req)
192{
Holger Schurig10078322007-11-15 18:05:47 -0500193 lbs_adapter *adapter = priv->adapter;
Dan Williamsef9a2642007-05-25 16:46:33 -0400194 int ret = 0;
195
196 lbs_deb_enter(LBS_DEB_ASSOC);
197
198 ret = update_channel(priv);
199 if (ret < 0) {
200 lbs_deb_assoc("ASSOC: channel: error getting channel.");
201 }
202
203 if (assoc_req->channel == adapter->curbssparams.channel)
204 goto done;
205
206 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
207 adapter->curbssparams.channel, assoc_req->channel);
208
Holger Schurig10078322007-11-15 18:05:47 -0500209 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RF_CHANNEL,
Dan Williams0aef64d2007-08-02 11:31:18 -0400210 CMD_OPT_802_11_RF_CHANNEL_SET,
211 CMD_OPTION_WAITFORRSP, 0, &assoc_req->channel);
Dan Williamsef9a2642007-05-25 16:46:33 -0400212 if (ret < 0) {
213 lbs_deb_assoc("ASSOC: channel: error setting channel.");
214 }
215
216 ret = update_channel(priv);
217 if (ret < 0) {
218 lbs_deb_assoc("ASSOC: channel: error getting channel.");
219 }
220
221 if (assoc_req->channel != adapter->curbssparams.channel) {
222 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d",
223 assoc_req->channel);
224 goto done;
225 }
226
227 if ( assoc_req->secinfo.wep_enabled
228 && (assoc_req->wep_keys[0].len
229 || assoc_req->wep_keys[1].len
230 || assoc_req->wep_keys[2].len
231 || assoc_req->wep_keys[3].len)) {
232 /* Make sure WEP keys are re-sent to firmware */
233 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
234 }
235
236 /* Must restart/rejoin adhoc networks after channel change */
237 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
238
239done:
240 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
241 return ret;
242}
243
244
Holger Schurig10078322007-11-15 18:05:47 -0500245static int assoc_helper_wep_keys(lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246 struct assoc_request * assoc_req)
247{
Holger Schurig10078322007-11-15 18:05:47 -0500248 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249 int i;
250 int ret = 0;
251
Holger Schurig9012b282007-05-25 11:27:16 -0400252 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253
254 /* Set or remove WEP keys */
255 if ( assoc_req->wep_keys[0].len
256 || assoc_req->wep_keys[1].len
257 || assoc_req->wep_keys[2].len
258 || assoc_req->wep_keys[3].len) {
Holger Schurig10078322007-11-15 18:05:47 -0500259 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400260 CMD_802_11_SET_WEP,
261 CMD_ACT_ADD,
262 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200263 0, assoc_req);
264 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500265 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400266 CMD_802_11_SET_WEP,
267 CMD_ACT_REMOVE,
268 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200269 0, NULL);
270 }
271
272 if (ret)
273 goto out;
274
275 /* enable/disable the MAC's WEP packet filter */
Dan Williams889c05b2007-05-10 22:57:23 -0400276 if (assoc_req->secinfo.wep_enabled)
Dan Williams0aef64d2007-08-02 11:31:18 -0400277 adapter->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200278 else
Dan Williams0aef64d2007-08-02 11:31:18 -0400279 adapter->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE;
Holger Schurig10078322007-11-15 18:05:47 -0500280 ret = lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200281 if (ret)
282 goto out;
283
284 mutex_lock(&adapter->lock);
285
286 /* Copy WEP keys into adapter wep key fields */
287 for (i = 0; i < 4; i++) {
288 memcpy(&adapter->wep_keys[i], &assoc_req->wep_keys[i],
Dan Williams1443b652007-08-02 10:45:55 -0400289 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200290 }
291 adapter->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
292
293 mutex_unlock(&adapter->lock);
294
295out:
Holger Schurig9012b282007-05-25 11:27:16 -0400296 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297 return ret;
298}
299
Holger Schurig10078322007-11-15 18:05:47 -0500300static int assoc_helper_secinfo(lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200301 struct assoc_request * assoc_req)
302{
Holger Schurig10078322007-11-15 18:05:47 -0500303 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200304 int ret = 0;
Dan Williams18c96c342007-06-18 12:01:12 -0400305 u32 do_wpa;
306 u32 rsn = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307
Holger Schurig9012b282007-05-25 11:27:16 -0400308 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309
310 memcpy(&adapter->secinfo, &assoc_req->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500311 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312
Holger Schurig10078322007-11-15 18:05:47 -0500313 ret = lbs_set_mac_packet_filter(priv);
Dan Williams90a42212007-05-25 23:01:24 -0400314 if (ret)
315 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200316
Dan Williams18c96c342007-06-18 12:01:12 -0400317 /* If RSN is already enabled, don't try to enable it again, since
318 * ENABLE_RSN resets internal state machines and will clobber the
319 * 4-way WPA handshake.
320 */
321
322 /* Get RSN enabled/disabled */
Holger Schurig10078322007-11-15 18:05:47 -0500323 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400324 CMD_802_11_ENABLE_RSN,
325 CMD_ACT_GET,
326 CMD_OPTION_WAITFORRSP,
Dan Williams18c96c342007-06-18 12:01:12 -0400327 0, &rsn);
328 if (ret) {
329 lbs_deb_assoc("Failed to get RSN status: %d", ret);
330 goto out;
331 }
332
333 /* Don't re-enable RSN if it's already enabled */
334 do_wpa = (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled);
335 if (do_wpa == rsn)
336 goto out;
337
338 /* Set RSN enabled/disabled */
339 rsn = do_wpa;
Holger Schurig10078322007-11-15 18:05:47 -0500340 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400341 CMD_802_11_ENABLE_RSN,
342 CMD_ACT_SET,
343 CMD_OPTION_WAITFORRSP,
Dan Williams18c96c342007-06-18 12:01:12 -0400344 0, &rsn);
Dan Williams90a42212007-05-25 23:01:24 -0400345
346out:
Holger Schurig9012b282007-05-25 11:27:16 -0400347 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200348 return ret;
349}
350
351
Holger Schurig10078322007-11-15 18:05:47 -0500352static int assoc_helper_wpa_keys(lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353 struct assoc_request * assoc_req)
354{
355 int ret = 0;
Dan Williams2bcde512007-10-03 10:37:45 -0400356 unsigned int flags = assoc_req->flags;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200357
Holger Schurig9012b282007-05-25 11:27:16 -0400358 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200359
Dan Williams2bcde512007-10-03 10:37:45 -0400360 /* Work around older firmware bug where WPA unicast and multicast
361 * keys must be set independently. Seen in SDIO parts with firmware
362 * version 5.0.11p0.
363 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364
Dan Williams2bcde512007-10-03 10:37:45 -0400365 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
366 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500367 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400368 CMD_802_11_KEY_MATERIAL,
369 CMD_ACT_SET,
370 CMD_OPTION_WAITFORRSP,
371 0, assoc_req);
372 assoc_req->flags = flags;
373 }
374
375 if (ret)
376 goto out;
377
378 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
379 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
380
Holger Schurig10078322007-11-15 18:05:47 -0500381 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400382 CMD_802_11_KEY_MATERIAL,
383 CMD_ACT_SET,
384 CMD_OPTION_WAITFORRSP,
385 0, assoc_req);
386 assoc_req->flags = flags;
387 }
388
389out:
Holger Schurig9012b282007-05-25 11:27:16 -0400390 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391 return ret;
392}
393
394
Holger Schurig10078322007-11-15 18:05:47 -0500395static int assoc_helper_wpa_ie(lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396 struct assoc_request * assoc_req)
397{
Holger Schurig10078322007-11-15 18:05:47 -0500398 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200399 int ret = 0;
400
Holger Schurig9012b282007-05-25 11:27:16 -0400401 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200402
403 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
404 memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
405 adapter->wpa_ie_len = assoc_req->wpa_ie_len;
406 } else {
407 memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN);
408 adapter->wpa_ie_len = 0;
409 }
410
Holger Schurig9012b282007-05-25 11:27:16 -0400411 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412 return ret;
413}
414
415
Holger Schurig10078322007-11-15 18:05:47 -0500416static int should_deauth_infrastructure(lbs_adapter *adapter,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417 struct assoc_request * assoc_req)
418{
Holger Schurig0765af42007-10-15 12:55:56 +0200419 int ret = 0;
420
421 lbs_deb_enter(LBS_DEB_ASSOC);
422
Holger Schurig10078322007-11-15 18:05:47 -0500423 if (adapter->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200424 return 0;
425
426 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200427 lbs_deb_assoc("Deauthenticating due to new SSID\n");
428 ret = 1;
429 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200430 }
431
432 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
Dan Williams6affe782007-05-10 22:56:42 -0400433 if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
Holger Schurig0765af42007-10-15 12:55:56 +0200434 lbs_deb_assoc("Deauthenticating due to new security\n");
435 ret = 1;
436 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437 }
438 }
439
440 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200441 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
442 ret = 1;
443 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200444 }
445
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400446 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200447 lbs_deb_assoc("Deauthenticating due to channel switch\n");
448 ret = 1;
449 goto out;
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400450 }
451
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200452 /* FIXME: deal with 'auto' mode somehow */
453 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200454 if (assoc_req->mode != IW_MODE_INFRA) {
455 lbs_deb_assoc("Deauthenticating due to leaving "
456 "infra mode\n");
457 ret = 1;
458 goto out;
459 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200460 }
461
Holger Schurig0765af42007-10-15 12:55:56 +0200462out:
463 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464 return 0;
465}
466
467
Holger Schurig10078322007-11-15 18:05:47 -0500468static int should_stop_adhoc(lbs_adapter *adapter,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469 struct assoc_request * assoc_req)
470{
Holger Schurig0765af42007-10-15 12:55:56 +0200471 lbs_deb_enter(LBS_DEB_ASSOC);
472
Holger Schurig10078322007-11-15 18:05:47 -0500473 if (adapter->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200474 return 0;
475
Holger Schurig10078322007-11-15 18:05:47 -0500476 if (lbs_ssid_cmp(adapter->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400477 adapter->curbssparams.ssid_len,
478 assoc_req->ssid, assoc_req->ssid_len) != 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200479 return 1;
480
481 /* FIXME: deal with 'auto' mode somehow */
482 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400483 if (assoc_req->mode != IW_MODE_ADHOC)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200484 return 1;
485 }
486
Dan Williamsef9a2642007-05-25 16:46:33 -0400487 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
488 if (assoc_req->channel != adapter->curbssparams.channel)
489 return 1;
490 }
491
Holger Schurig0765af42007-10-15 12:55:56 +0200492 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200493 return 0;
494}
495
496
Holger Schurig10078322007-11-15 18:05:47 -0500497void lbs_association_worker(struct work_struct *work)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200498{
Holger Schurig10078322007-11-15 18:05:47 -0500499 lbs_private *priv = container_of(work, lbs_private, assoc_work.work);
500 lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200501 struct assoc_request * assoc_req = NULL;
502 int ret = 0;
503 int find_any_ssid = 0;
Joe Perches0795af52007-10-03 17:59:30 -0700504 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505
Holger Schurig9012b282007-05-25 11:27:16 -0400506 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
508 mutex_lock(&adapter->lock);
Dan Williamse76850d2007-05-25 17:09:41 -0400509 assoc_req = adapter->pending_assoc_req;
510 adapter->pending_assoc_req = NULL;
511 adapter->in_progress_assoc_req = assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200512 mutex_unlock(&adapter->lock);
513
Holger Schurig9012b282007-05-25 11:27:16 -0400514 if (!assoc_req)
515 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200516
Holger Schurig0765af42007-10-15 12:55:56 +0200517 lbs_deb_assoc(
518 "Association Request:\n"
519 " flags: 0x%08lx\n"
520 " SSID: '%s'\n"
521 " chann: %d\n"
522 " band: %d\n"
523 " mode: %d\n"
524 " BSSID: %s\n"
525 " secinfo: %s%s%s\n"
526 " auth_mode: %d\n",
527 assoc_req->flags,
528 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
529 assoc_req->channel, assoc_req->band, assoc_req->mode,
530 print_mac(mac, assoc_req->bssid),
531 assoc_req->secinfo.WPAenabled ? " WPA" : "",
532 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
533 assoc_req->secinfo.wep_enabled ? " WEP" : "",
534 assoc_req->secinfo.auth_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200535
536 /* If 'any' SSID was specified, find an SSID to associate with */
537 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
Dan Williamsd8efea22007-05-28 23:54:55 -0400538 && !assoc_req->ssid_len)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200539 find_any_ssid = 1;
540
541 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
542 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf209312007-05-25 17:28:30 -0400543 if (compare_ether_addr(assoc_req->bssid, bssid_any)
544 && compare_ether_addr(assoc_req->bssid, bssid_off))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200545 find_any_ssid = 0;
546 }
547
548 if (find_any_ssid) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400549 u8 new_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200550
Holger Schurig10078322007-11-15 18:05:47 -0500551 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400552 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400554 lbs_deb_assoc("Could not find best network\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200555 ret = -ENETUNREACH;
556 goto out;
557 }
558
559 /* Ensure we switch to the mode of the AP */
Dan Williams0dc5a292007-05-10 22:58:02 -0400560 if (assoc_req->mode == IW_MODE_AUTO) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200561 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
562 assoc_req->mode = new_mode;
563 }
564 }
565
566 /*
567 * Check if the attributes being changing require deauthentication
568 * from the currently associated infrastructure access point.
569 */
Dan Williams0dc5a292007-05-10 22:58:02 -0400570 if (adapter->mode == IW_MODE_INFRA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200571 if (should_deauth_infrastructure(adapter, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500572 ret = lbs_send_deauthentication(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200573 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400574 lbs_deb_assoc("Deauthentication due to new "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575 "configuration request failed: %d\n",
576 ret);
577 }
578 }
Dan Williams0dc5a292007-05-10 22:58:02 -0400579 } else if (adapter->mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200580 if (should_stop_adhoc(adapter, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500581 ret = lbs_stop_adhoc_network(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200582 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400583 lbs_deb_assoc("Teardown of AdHoc network due to "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200584 "new configuration request failed: %d\n",
585 ret);
586 }
587
588 }
589 }
590
591 /* Send the various configuration bits to the firmware */
592 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
593 ret = assoc_helper_mode(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200594 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200595 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200596 }
597
Dan Williamsef9a2642007-05-25 16:46:33 -0400598 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
599 ret = assoc_helper_channel(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200600 if (ret)
Dan Williamsef9a2642007-05-25 16:46:33 -0400601 goto out;
Dan Williamsef9a2642007-05-25 16:46:33 -0400602 }
603
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
605 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
606 ret = assoc_helper_wep_keys(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_SECINFO, &assoc_req->flags)) {
612 ret = assoc_helper_secinfo(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_IE, &assoc_req->flags)) {
618 ret = assoc_helper_wpa_ie(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200619 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200620 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621 }
622
623 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
624 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
625 ret = assoc_helper_wpa_keys(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200626 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200628 }
629
630 /* SSID/BSSID should be the _last_ config option set, because they
631 * trigger the association attempt.
632 */
633 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
634 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
635 int success = 1;
636
637 ret = assoc_helper_associate(priv, assoc_req);
638 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400639 lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200640 ret);
641 success = 0;
642 }
643
Holger Schurig10078322007-11-15 18:05:47 -0500644 if (adapter->connect_status != LBS_CONNECTED) {
Dan Williams81173e32007-08-02 13:19:56 -0400645 lbs_deb_assoc("ASSOC: association attempt unsuccessful, "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200646 "not connected.\n");
647 success = 0;
648 }
649
650 if (success) {
Holger Schurig9012b282007-05-25 11:27:16 -0400651 lbs_deb_assoc("ASSOC: association attempt successful. "
Joe Perches0795af52007-10-03 17:59:30 -0700652 "Associated to '%s' (%s)\n",
Dan Williamsd8efea22007-05-28 23:54:55 -0400653 escape_essid(adapter->curbssparams.ssid,
654 adapter->curbssparams.ssid_len),
Joe Perches0795af52007-10-03 17:59:30 -0700655 print_mac(mac, adapter->curbssparams.bssid));
Holger Schurig10078322007-11-15 18:05:47 -0500656 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400657 CMD_802_11_RSSI,
658 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200659
Holger Schurig10078322007-11-15 18:05:47 -0500660 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400661 CMD_802_11_GET_LOG,
662 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200663 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664 ret = -1;
665 }
666 }
667
668out:
669 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400670 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200671 ret);
672 }
Dan Williamse76850d2007-05-25 17:09:41 -0400673
674 mutex_lock(&adapter->lock);
675 adapter->in_progress_assoc_req = NULL;
676 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200677 kfree(assoc_req);
Holger Schurig9012b282007-05-25 11:27:16 -0400678
679done:
680 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200681}
682
683
684/*
685 * Caller MUST hold any necessary locks
686 */
Holger Schurig10078322007-11-15 18:05:47 -0500687struct assoc_request *lbs_get_association_request(lbs_adapter *adapter)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200688{
689 struct assoc_request * assoc_req;
690
Holger Schurig0765af42007-10-15 12:55:56 +0200691 lbs_deb_enter(LBS_DEB_ASSOC);
Dan Williamse76850d2007-05-25 17:09:41 -0400692 if (!adapter->pending_assoc_req) {
693 adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
694 GFP_KERNEL);
695 if (!adapter->pending_assoc_req) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200696 lbs_pr_info("Not enough memory to allocate association"
697 " request!\n");
698 return NULL;
699 }
700 }
701
702 /* Copy current configuration attributes to the association request,
703 * but don't overwrite any that are already set.
704 */
Dan Williamse76850d2007-05-25 17:09:41 -0400705 assoc_req = adapter->pending_assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200706 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
Dan Williamse76850d2007-05-25 17:09:41 -0400707 memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400708 IW_ESSID_MAX_SIZE);
709 assoc_req->ssid_len = adapter->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200710 }
711
712 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
713 assoc_req->channel = adapter->curbssparams.channel;
714
Dan Williamse76850d2007-05-25 17:09:41 -0400715 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
716 assoc_req->band = adapter->curbssparams.band;
717
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200718 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
Dan Williams0dc5a292007-05-10 22:58:02 -0400719 assoc_req->mode = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200720
721 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
722 memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
723 ETH_ALEN);
724 }
725
726 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
727 int i;
728 for (i = 0; i < 4; i++) {
729 memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i],
Dan Williams1443b652007-08-02 10:45:55 -0400730 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731 }
732 }
733
734 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
735 assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx;
736
737 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
738 memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400739 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200740 }
741
742 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
743 memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400744 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200745 }
746
747 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
748 memcpy(&assoc_req->secinfo, &adapter->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500749 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200750 }
751
752 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
753 memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie,
754 MAX_WPA_IE_LEN);
755 assoc_req->wpa_ie_len = adapter->wpa_ie_len;
756 }
757
Holger Schurig0765af42007-10-15 12:55:56 +0200758 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200759 return assoc_req;
760}