blob: 88da68ee0f0295a1791390e965b608e06242cd44 [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{
Holger Schurig69f90322007-11-23 15:43:44 +010021 struct 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 Schurig69f90322007-11-23 15:43:44 +010078static int assoc_helper_bssid(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020079 struct assoc_request * assoc_req)
80{
Holger Schurig69f90322007-11-23 15:43:44 +010081 struct 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 Schurig69f90322007-11-23 15:43:44 +0100112static int assoc_helper_associate(struct 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 Schurig69f90322007-11-23 15:43:44 +0100138static int assoc_helper_mode(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139 struct assoc_request * assoc_req)
140{
Holger Schurig69f90322007-11-23 15:43:44 +0100141 struct 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 Schurig69f90322007-11-23 15:43:44 +0100168static int update_channel(struct 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 Schurig69f90322007-11-23 15:43:44 +0100182 struct lbs_private *priv = container_of(work, struct lbs_private,
183 sync_channel);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400184
Holger Schurig0765af42007-10-15 12:55:56 +0200185 lbs_deb_enter(LBS_DEB_ASSOC);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400186 if (update_channel(priv) != 0)
187 lbs_pr_info("Channel synchronization failed.");
Holger Schurig0765af42007-10-15 12:55:56 +0200188 lbs_deb_leave(LBS_DEB_ASSOC);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400189}
190
Holger Schurig69f90322007-11-23 15:43:44 +0100191static int assoc_helper_channel(struct lbs_private *priv,
Dan Williamsef9a2642007-05-25 16:46:33 -0400192 struct assoc_request * assoc_req)
193{
Holger Schurig69f90322007-11-23 15:43:44 +0100194 struct lbs_adapter *adapter = priv->adapter;
Dan Williamsef9a2642007-05-25 16:46:33 -0400195 int ret = 0;
196
197 lbs_deb_enter(LBS_DEB_ASSOC);
198
199 ret = update_channel(priv);
200 if (ret < 0) {
201 lbs_deb_assoc("ASSOC: channel: error getting channel.");
202 }
203
204 if (assoc_req->channel == adapter->curbssparams.channel)
205 goto done;
206
207 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
208 adapter->curbssparams.channel, assoc_req->channel);
209
Holger Schurig10078322007-11-15 18:05:47 -0500210 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RF_CHANNEL,
Dan Williams0aef64d2007-08-02 11:31:18 -0400211 CMD_OPT_802_11_RF_CHANNEL_SET,
212 CMD_OPTION_WAITFORRSP, 0, &assoc_req->channel);
Dan Williamsef9a2642007-05-25 16:46:33 -0400213 if (ret < 0) {
214 lbs_deb_assoc("ASSOC: channel: error setting channel.");
215 }
216
217 ret = update_channel(priv);
218 if (ret < 0) {
219 lbs_deb_assoc("ASSOC: channel: error getting channel.");
220 }
221
222 if (assoc_req->channel != adapter->curbssparams.channel) {
223 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d",
224 assoc_req->channel);
225 goto done;
226 }
227
228 if ( assoc_req->secinfo.wep_enabled
229 && (assoc_req->wep_keys[0].len
230 || assoc_req->wep_keys[1].len
231 || assoc_req->wep_keys[2].len
232 || assoc_req->wep_keys[3].len)) {
233 /* Make sure WEP keys are re-sent to firmware */
234 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
235 }
236
237 /* Must restart/rejoin adhoc networks after channel change */
238 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
239
240done:
241 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
242 return ret;
243}
244
245
Holger Schurig69f90322007-11-23 15:43:44 +0100246static int assoc_helper_wep_keys(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200247 struct assoc_request * assoc_req)
248{
Holger Schurig69f90322007-11-23 15:43:44 +0100249 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200250 int i;
251 int ret = 0;
252
Holger Schurig9012b282007-05-25 11:27:16 -0400253 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200254
255 /* Set or remove WEP keys */
256 if ( assoc_req->wep_keys[0].len
257 || assoc_req->wep_keys[1].len
258 || assoc_req->wep_keys[2].len
259 || assoc_req->wep_keys[3].len) {
Holger Schurig10078322007-11-15 18:05:47 -0500260 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400261 CMD_802_11_SET_WEP,
262 CMD_ACT_ADD,
263 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200264 0, assoc_req);
265 } else {
Holger Schurig10078322007-11-15 18:05:47 -0500266 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400267 CMD_802_11_SET_WEP,
268 CMD_ACT_REMOVE,
269 CMD_OPTION_WAITFORRSP,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200270 0, NULL);
271 }
272
273 if (ret)
274 goto out;
275
276 /* enable/disable the MAC's WEP packet filter */
Dan Williams889c05b2007-05-10 22:57:23 -0400277 if (assoc_req->secinfo.wep_enabled)
Dan Williams0aef64d2007-08-02 11:31:18 -0400278 adapter->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200279 else
Dan Williams0aef64d2007-08-02 11:31:18 -0400280 adapter->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE;
Holger Schurig10078322007-11-15 18:05:47 -0500281 ret = lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282 if (ret)
283 goto out;
284
285 mutex_lock(&adapter->lock);
286
287 /* Copy WEP keys into adapter wep key fields */
288 for (i = 0; i < 4; i++) {
289 memcpy(&adapter->wep_keys[i], &assoc_req->wep_keys[i],
Dan Williams1443b652007-08-02 10:45:55 -0400290 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200291 }
292 adapter->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
293
294 mutex_unlock(&adapter->lock);
295
296out:
Holger Schurig9012b282007-05-25 11:27:16 -0400297 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298 return ret;
299}
300
Holger Schurig69f90322007-11-23 15:43:44 +0100301static int assoc_helper_secinfo(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302 struct assoc_request * assoc_req)
303{
Holger Schurig69f90322007-11-23 15:43:44 +0100304 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200305 int ret = 0;
Dan Williams18c96c342007-06-18 12:01:12 -0400306 u32 do_wpa;
307 u32 rsn = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200308
Holger Schurig9012b282007-05-25 11:27:16 -0400309 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310
311 memcpy(&adapter->secinfo, &assoc_req->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500312 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200313
Holger Schurig10078322007-11-15 18:05:47 -0500314 ret = lbs_set_mac_packet_filter(priv);
Dan Williams90a42212007-05-25 23:01:24 -0400315 if (ret)
316 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317
Dan Williams18c96c342007-06-18 12:01:12 -0400318 /* If RSN is already enabled, don't try to enable it again, since
319 * ENABLE_RSN resets internal state machines and will clobber the
320 * 4-way WPA handshake.
321 */
322
323 /* Get RSN enabled/disabled */
Holger Schurig10078322007-11-15 18:05:47 -0500324 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400325 CMD_802_11_ENABLE_RSN,
326 CMD_ACT_GET,
327 CMD_OPTION_WAITFORRSP,
Dan Williams18c96c342007-06-18 12:01:12 -0400328 0, &rsn);
329 if (ret) {
330 lbs_deb_assoc("Failed to get RSN status: %d", ret);
331 goto out;
332 }
333
334 /* Don't re-enable RSN if it's already enabled */
335 do_wpa = (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled);
336 if (do_wpa == rsn)
337 goto out;
338
339 /* Set RSN enabled/disabled */
340 rsn = do_wpa;
Holger Schurig10078322007-11-15 18:05:47 -0500341 ret = lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400342 CMD_802_11_ENABLE_RSN,
343 CMD_ACT_SET,
344 CMD_OPTION_WAITFORRSP,
Dan Williams18c96c342007-06-18 12:01:12 -0400345 0, &rsn);
Dan Williams90a42212007-05-25 23:01:24 -0400346
347out:
Holger Schurig9012b282007-05-25 11:27:16 -0400348 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349 return ret;
350}
351
352
Holger Schurig69f90322007-11-23 15:43:44 +0100353static int assoc_helper_wpa_keys(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354 struct assoc_request * assoc_req)
355{
356 int ret = 0;
Dan Williams2bcde512007-10-03 10:37:45 -0400357 unsigned int flags = assoc_req->flags;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200358
Holger Schurig9012b282007-05-25 11:27:16 -0400359 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360
Dan Williams2bcde512007-10-03 10:37:45 -0400361 /* Work around older firmware bug where WPA unicast and multicast
362 * keys must be set independently. Seen in SDIO parts with firmware
363 * version 5.0.11p0.
364 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200365
Dan Williams2bcde512007-10-03 10:37:45 -0400366 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
367 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500368 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400369 CMD_802_11_KEY_MATERIAL,
370 CMD_ACT_SET,
371 CMD_OPTION_WAITFORRSP,
372 0, assoc_req);
373 assoc_req->flags = flags;
374 }
375
376 if (ret)
377 goto out;
378
379 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
380 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
381
Holger Schurig10078322007-11-15 18:05:47 -0500382 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400383 CMD_802_11_KEY_MATERIAL,
384 CMD_ACT_SET,
385 CMD_OPTION_WAITFORRSP,
386 0, assoc_req);
387 assoc_req->flags = flags;
388 }
389
390out:
Holger Schurig9012b282007-05-25 11:27:16 -0400391 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392 return ret;
393}
394
395
Holger Schurig69f90322007-11-23 15:43:44 +0100396static int assoc_helper_wpa_ie(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397 struct assoc_request * assoc_req)
398{
Holger Schurig69f90322007-11-23 15:43:44 +0100399 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400 int ret = 0;
401
Holger Schurig9012b282007-05-25 11:27:16 -0400402 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403
404 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
405 memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
406 adapter->wpa_ie_len = assoc_req->wpa_ie_len;
407 } else {
408 memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN);
409 adapter->wpa_ie_len = 0;
410 }
411
Holger Schurig9012b282007-05-25 11:27:16 -0400412 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413 return ret;
414}
415
416
Holger Schurig69f90322007-11-23 15:43:44 +0100417static int should_deauth_infrastructure(struct lbs_adapter *adapter,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200418 struct assoc_request * assoc_req)
419{
Holger Schurig0765af42007-10-15 12:55:56 +0200420 int ret = 0;
421
422 lbs_deb_enter(LBS_DEB_ASSOC);
423
Holger Schurig10078322007-11-15 18:05:47 -0500424 if (adapter->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425 return 0;
426
427 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200428 lbs_deb_assoc("Deauthenticating due to new SSID\n");
429 ret = 1;
430 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200431 }
432
433 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
Dan Williams6affe782007-05-10 22:56:42 -0400434 if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
Holger Schurig0765af42007-10-15 12:55:56 +0200435 lbs_deb_assoc("Deauthenticating due to new security\n");
436 ret = 1;
437 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200438 }
439 }
440
441 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200442 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
443 ret = 1;
444 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200445 }
446
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400447 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200448 lbs_deb_assoc("Deauthenticating due to channel switch\n");
449 ret = 1;
450 goto out;
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400451 }
452
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200453 /* FIXME: deal with 'auto' mode somehow */
454 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200455 if (assoc_req->mode != IW_MODE_INFRA) {
456 lbs_deb_assoc("Deauthenticating due to leaving "
457 "infra mode\n");
458 ret = 1;
459 goto out;
460 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200461 }
462
Holger Schurig0765af42007-10-15 12:55:56 +0200463out:
464 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200465 return 0;
466}
467
468
Holger Schurig69f90322007-11-23 15:43:44 +0100469static int should_stop_adhoc(struct lbs_adapter *adapter,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470 struct assoc_request * assoc_req)
471{
Holger Schurig0765af42007-10-15 12:55:56 +0200472 lbs_deb_enter(LBS_DEB_ASSOC);
473
Holger Schurig10078322007-11-15 18:05:47 -0500474 if (adapter->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200475 return 0;
476
Holger Schurig10078322007-11-15 18:05:47 -0500477 if (lbs_ssid_cmp(adapter->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400478 adapter->curbssparams.ssid_len,
479 assoc_req->ssid, assoc_req->ssid_len) != 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200480 return 1;
481
482 /* FIXME: deal with 'auto' mode somehow */
483 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400484 if (assoc_req->mode != IW_MODE_ADHOC)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200485 return 1;
486 }
487
Dan Williamsef9a2642007-05-25 16:46:33 -0400488 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
489 if (assoc_req->channel != adapter->curbssparams.channel)
490 return 1;
491 }
492
Holger Schurig0765af42007-10-15 12:55:56 +0200493 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200494 return 0;
495}
496
497
Holger Schurig10078322007-11-15 18:05:47 -0500498void lbs_association_worker(struct work_struct *work)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499{
Holger Schurig69f90322007-11-23 15:43:44 +0100500 struct lbs_private *priv = container_of(work, struct lbs_private,
501 assoc_work.work);
502 struct lbs_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200503 struct assoc_request * assoc_req = NULL;
504 int ret = 0;
505 int find_any_ssid = 0;
Joe Perches0795af52007-10-03 17:59:30 -0700506 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
Holger Schurig9012b282007-05-25 11:27:16 -0400508 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509
510 mutex_lock(&adapter->lock);
Dan Williamse76850d2007-05-25 17:09:41 -0400511 assoc_req = adapter->pending_assoc_req;
512 adapter->pending_assoc_req = NULL;
513 adapter->in_progress_assoc_req = assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200514 mutex_unlock(&adapter->lock);
515
Holger Schurig9012b282007-05-25 11:27:16 -0400516 if (!assoc_req)
517 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200518
Holger Schurig0765af42007-10-15 12:55:56 +0200519 lbs_deb_assoc(
520 "Association Request:\n"
521 " flags: 0x%08lx\n"
522 " SSID: '%s'\n"
523 " chann: %d\n"
524 " band: %d\n"
525 " mode: %d\n"
526 " BSSID: %s\n"
527 " secinfo: %s%s%s\n"
528 " auth_mode: %d\n",
529 assoc_req->flags,
530 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
531 assoc_req->channel, assoc_req->band, assoc_req->mode,
532 print_mac(mac, assoc_req->bssid),
533 assoc_req->secinfo.WPAenabled ? " WPA" : "",
534 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
535 assoc_req->secinfo.wep_enabled ? " WEP" : "",
536 assoc_req->secinfo.auth_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200537
538 /* If 'any' SSID was specified, find an SSID to associate with */
539 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
Dan Williamsd8efea22007-05-28 23:54:55 -0400540 && !assoc_req->ssid_len)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200541 find_any_ssid = 1;
542
543 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
544 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf209312007-05-25 17:28:30 -0400545 if (compare_ether_addr(assoc_req->bssid, bssid_any)
546 && compare_ether_addr(assoc_req->bssid, bssid_off))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 find_any_ssid = 0;
548 }
549
550 if (find_any_ssid) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400551 u8 new_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200552
Holger Schurig10078322007-11-15 18:05:47 -0500553 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400554 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200555 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400556 lbs_deb_assoc("Could not find best network\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200557 ret = -ENETUNREACH;
558 goto out;
559 }
560
561 /* Ensure we switch to the mode of the AP */
Dan Williams0dc5a292007-05-10 22:58:02 -0400562 if (assoc_req->mode == IW_MODE_AUTO) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200563 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
564 assoc_req->mode = new_mode;
565 }
566 }
567
568 /*
569 * Check if the attributes being changing require deauthentication
570 * from the currently associated infrastructure access point.
571 */
Dan Williams0dc5a292007-05-10 22:58:02 -0400572 if (adapter->mode == IW_MODE_INFRA) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200573 if (should_deauth_infrastructure(adapter, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500574 ret = lbs_send_deauthentication(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400576 lbs_deb_assoc("Deauthentication due to new "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200577 "configuration request failed: %d\n",
578 ret);
579 }
580 }
Dan Williams0dc5a292007-05-10 22:58:02 -0400581 } else if (adapter->mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200582 if (should_stop_adhoc(adapter, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500583 ret = lbs_stop_adhoc_network(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200584 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400585 lbs_deb_assoc("Teardown of AdHoc network due to "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200586 "new configuration request failed: %d\n",
587 ret);
588 }
589
590 }
591 }
592
593 /* Send the various configuration bits to the firmware */
594 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
595 ret = assoc_helper_mode(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200596 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200597 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200598 }
599
Dan Williamsef9a2642007-05-25 16:46:33 -0400600 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
601 ret = assoc_helper_channel(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200602 if (ret)
Dan Williamsef9a2642007-05-25 16:46:33 -0400603 goto out;
Dan Williamsef9a2642007-05-25 16:46:33 -0400604 }
605
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200606 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
607 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
608 ret = assoc_helper_wep_keys(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200609 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611 }
612
613 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
614 ret = assoc_helper_secinfo(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200615 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617 }
618
619 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
620 ret = assoc_helper_wpa_ie(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200621 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200622 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623 }
624
625 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
626 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
627 ret = assoc_helper_wpa_keys(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200628 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200629 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200630 }
631
632 /* SSID/BSSID should be the _last_ config option set, because they
633 * trigger the association attempt.
634 */
635 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
636 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
637 int success = 1;
638
639 ret = assoc_helper_associate(priv, assoc_req);
640 if (ret) {
Holger Schurig91843462007-11-28 14:05:02 +0100641 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200642 ret);
643 success = 0;
644 }
645
Holger Schurig10078322007-11-15 18:05:47 -0500646 if (adapter->connect_status != LBS_CONNECTED) {
Holger Schurig91843462007-11-28 14:05:02 +0100647 lbs_deb_assoc("ASSOC: association unsuccessful, "
648 "not connected\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649 success = 0;
650 }
651
652 if (success) {
Holger Schurig91843462007-11-28 14:05:02 +0100653 lbs_deb_assoc("ASSOC: associated to '%s', %s\n",
Dan Williamsd8efea22007-05-28 23:54:55 -0400654 escape_essid(adapter->curbssparams.ssid,
655 adapter->curbssparams.ssid_len),
Joe Perches0795af52007-10-03 17:59:30 -0700656 print_mac(mac, adapter->curbssparams.bssid));
Holger Schurig10078322007-11-15 18:05:47 -0500657 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400658 CMD_802_11_RSSI,
659 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200660
Holger Schurig10078322007-11-15 18:05:47 -0500661 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400662 CMD_802_11_GET_LOG,
663 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200665 ret = -1;
666 }
667 }
668
669out:
670 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400671 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200672 ret);
673 }
Dan Williamse76850d2007-05-25 17:09:41 -0400674
675 mutex_lock(&adapter->lock);
676 adapter->in_progress_assoc_req = NULL;
677 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678 kfree(assoc_req);
Holger Schurig9012b282007-05-25 11:27:16 -0400679
680done:
681 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200682}
683
684
685/*
686 * Caller MUST hold any necessary locks
687 */
Holger Schurig69f90322007-11-23 15:43:44 +0100688struct assoc_request *lbs_get_association_request(struct lbs_adapter *adapter)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200689{
690 struct assoc_request * assoc_req;
691
Holger Schurig0765af42007-10-15 12:55:56 +0200692 lbs_deb_enter(LBS_DEB_ASSOC);
Dan Williamse76850d2007-05-25 17:09:41 -0400693 if (!adapter->pending_assoc_req) {
694 adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
695 GFP_KERNEL);
696 if (!adapter->pending_assoc_req) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200697 lbs_pr_info("Not enough memory to allocate association"
698 " request!\n");
699 return NULL;
700 }
701 }
702
703 /* Copy current configuration attributes to the association request,
704 * but don't overwrite any that are already set.
705 */
Dan Williamse76850d2007-05-25 17:09:41 -0400706 assoc_req = adapter->pending_assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
Dan Williamse76850d2007-05-25 17:09:41 -0400708 memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400709 IW_ESSID_MAX_SIZE);
710 assoc_req->ssid_len = adapter->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200711 }
712
713 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
714 assoc_req->channel = adapter->curbssparams.channel;
715
Dan Williamse76850d2007-05-25 17:09:41 -0400716 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
717 assoc_req->band = adapter->curbssparams.band;
718
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200719 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
Dan Williams0dc5a292007-05-10 22:58:02 -0400720 assoc_req->mode = adapter->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200721
722 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
723 memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
724 ETH_ALEN);
725 }
726
727 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
728 int i;
729 for (i = 0; i < 4; i++) {
730 memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i],
Dan Williams1443b652007-08-02 10:45:55 -0400731 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200732 }
733 }
734
735 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
736 assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx;
737
738 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
739 memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400740 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741 }
742
743 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
744 memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400745 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200746 }
747
748 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
749 memcpy(&assoc_req->secinfo, &adapter->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500750 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200751 }
752
753 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
754 memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie,
755 MAX_WPA_IE_LEN);
756 assoc_req->wpa_ie_len = adapter->wpa_ie_len;
757 }
758
Holger Schurig0765af42007-10-15 12:55:56 +0200759 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200760 return assoc_req;
761}