blob: 75f6191e718dbb3c2f17e474d282e8fd1f1ca8b8 [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"
Dan Williams2dd4b262007-12-11 16:54:15 -050012#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013
14
Ihar Hrachyshka5a6e0432008-01-25 14:15:00 +010015static const u8 bssid_any[ETH_ALEN] __attribute__ ((aligned (2))) =
16 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
17static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) =
18 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019
Dan Williamse76850d2007-05-25 17:09:41 -040020
Holger Schurig69f90322007-11-23 15:43:44 +010021static int assoc_helper_essid(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022 struct assoc_request * assoc_req)
23{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020024 int ret = 0;
Dan Williamsfcdb53d2007-05-25 16:15:56 -040025 struct bss_descriptor * bss;
Dan Williamsaeea0ab2007-05-25 22:30:48 -040026 int channel = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020027
Holger Schurig9012b282007-05-25 11:27:16 -040028 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020029
Dan Williamsef9a2642007-05-25 16:46:33 -040030 /* FIXME: take channel into account when picking SSIDs if a channel
31 * is set.
32 */
33
Dan Williamsaeea0ab2007-05-25 22:30:48 -040034 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
35 channel = assoc_req->channel;
36
Holger Schurig0765af42007-10-15 12:55:56 +020037 lbs_deb_assoc("SSID '%s' requested\n",
Dan Williamsd8efea22007-05-28 23:54:55 -040038 escape_essid(assoc_req->ssid, assoc_req->ssid_len));
Dan Williams0dc5a292007-05-10 22:58:02 -040039 if (assoc_req->mode == IW_MODE_INFRA) {
Holger Schurig10078322007-11-15 18:05:47 -050040 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
Holger Schurig6e22a852007-08-02 13:05:32 -040041 assoc_req->ssid_len, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020042
David Woodhouseaa21c002007-12-08 20:04:36 +000043 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040044 assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040045 if (bss != NULL) {
Dan Williamse76850d2007-05-25 17:09:41 -040046 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Holger Schurig10078322007-11-15 18:05:47 -050047 ret = lbs_associate(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048 } else {
Dan Williamsd8efea22007-05-28 23:54:55 -040049 lbs_deb_assoc("SSID not found; cannot associate\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020050 }
Dan Williams0dc5a292007-05-10 22:58:02 -040051 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020052 /* Scan for the network, do not save previous results. Stale
53 * scan data will cause us to join a non-existant adhoc network
54 */
Holger Schurig10078322007-11-15 18:05:47 -050055 lbs_send_specific_ssid_scan(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040056 assoc_req->ssid_len, 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020057
58 /* Search for the requested SSID in the scan table */
David Woodhouseaa21c002007-12-08 20:04:36 +000059 bss = lbs_find_ssid_in_list(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040060 assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040061 if (bss != NULL) {
Dan Williamsd8efea22007-05-28 23:54:55 -040062 lbs_deb_assoc("SSID found, will join\n");
Dan Williamse76850d2007-05-25 17:09:41 -040063 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Holger Schurig10078322007-11-15 18:05:47 -050064 lbs_join_adhoc_network(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065 } else {
66 /* else send START command */
Dan Williamsd8efea22007-05-28 23:54:55 -040067 lbs_deb_assoc("SSID not found, creating adhoc network\n");
Dan Williamse76850d2007-05-25 17:09:41 -040068 memcpy(&assoc_req->bss.ssid, &assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -040069 IW_ESSID_MAX_SIZE);
70 assoc_req->bss.ssid_len = assoc_req->ssid_len;
Holger Schurig10078322007-11-15 18:05:47 -050071 lbs_start_adhoc_network(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020073 }
74
Holger Schurig9012b282007-05-25 11:27:16 -040075 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020076 return ret;
77}
78
79
Holger Schurig69f90322007-11-23 15:43:44 +010080static int assoc_helper_bssid(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020081 struct assoc_request * assoc_req)
82{
Dan Williamsfcdb53d2007-05-25 16:15:56 -040083 int ret = 0;
84 struct bss_descriptor * bss;
Joe Perches0795af52007-10-03 17:59:30 -070085 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020086
Joe Perches0795af52007-10-03 17:59:30 -070087 lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %s",
88 print_mac(mac, assoc_req->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089
90 /* Search for index position in list for requested MAC */
David Woodhouseaa21c002007-12-08 20:04:36 +000091 bss = lbs_find_bssid_in_list(priv, assoc_req->bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092 assoc_req->mode);
Dan Williamsfcdb53d2007-05-25 16:15:56 -040093 if (bss == NULL) {
Joe Perches0795af52007-10-03 17:59:30 -070094 lbs_deb_assoc("ASSOC: WAP: BSSID %s not found, "
95 "cannot associate.\n", print_mac(mac, assoc_req->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020096 goto out;
97 }
98
Dan Williamse76850d2007-05-25 17:09:41 -040099 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor));
Dan Williams0dc5a292007-05-10 22:58:02 -0400100 if (assoc_req->mode == IW_MODE_INFRA) {
Holger Schurig10078322007-11-15 18:05:47 -0500101 ret = lbs_associate(priv, assoc_req);
102 lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret);
Dan Williams0dc5a292007-05-10 22:58:02 -0400103 } else if (assoc_req->mode == IW_MODE_ADHOC) {
Holger Schurig10078322007-11-15 18:05:47 -0500104 lbs_join_adhoc_network(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200105 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200106
107out:
Holger Schurig9012b282007-05-25 11:27:16 -0400108 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200109 return ret;
110}
111
112
Holger Schurig69f90322007-11-23 15:43:44 +0100113static int assoc_helper_associate(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200114 struct assoc_request * assoc_req)
115{
116 int ret = 0, done = 0;
117
Holger Schurig0765af42007-10-15 12:55:56 +0200118 lbs_deb_enter(LBS_DEB_ASSOC);
119
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200120 /* If we're given and 'any' BSSID, try associating based on SSID */
121
122 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf209312007-05-25 17:28:30 -0400123 if (compare_ether_addr(bssid_any, assoc_req->bssid)
124 && compare_ether_addr(bssid_off, assoc_req->bssid)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125 ret = assoc_helper_bssid(priv, assoc_req);
126 done = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127 }
128 }
129
130 if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
131 ret = assoc_helper_essid(priv, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200132 }
133
Holger Schurig0765af42007-10-15 12:55:56 +0200134 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135 return ret;
136}
137
138
Holger Schurig69f90322007-11-23 15:43:44 +0100139static int assoc_helper_mode(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200140 struct assoc_request * assoc_req)
141{
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
David Woodhouseaa21c002007-12-08 20:04:36 +0000146 if (assoc_req->mode == priv->mode)
Holger Schurig9012b282007-05-25 11:27:16 -0400147 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) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000150 if (priv->psstate != PS_STATE_FULL_POWER)
Holger Schurig10078322007-11-15 18:05:47 -0500151 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
David Woodhouseaa21c002007-12-08 20:04:36 +0000152 priv->psmode = LBS802_11POWERMODECAM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200153 }
154
David Woodhouseaa21c002007-12-08 20:04:36 +0000155 priv->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
David Woodhouse9f462572007-12-12 22:50:21 -0500168int lbs_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 Williams2dd4b262007-12-11 16:54:15 -0500171
David Woodhoused1a469f2007-12-16 17:21:00 -0500172 /* the channel in f/w could be out of sync; get the current channel */
Holger Schurig0765af42007-10-15 12:55:56 +0200173 lbs_deb_enter(LBS_DEB_ASSOC);
Dan Williams2dd4b262007-12-11 16:54:15 -0500174
175 ret = lbs_get_channel(priv);
David Woodhoused1a469f2007-12-16 17:21:00 -0500176 if (ret > 0) {
177 priv->curbssparams.channel = ret;
178 ret = 0;
179 }
Holger Schurig0765af42007-10-15 12:55:56 +0200180 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
181 return ret;
Dan Williamsef9a2642007-05-25 16:46:33 -0400182}
183
Holger Schurig69f90322007-11-23 15:43:44 +0100184static int assoc_helper_channel(struct lbs_private *priv,
Dan Williamsef9a2642007-05-25 16:46:33 -0400185 struct assoc_request * assoc_req)
186{
Dan Williamsef9a2642007-05-25 16:46:33 -0400187 int ret = 0;
188
189 lbs_deb_enter(LBS_DEB_ASSOC);
190
David Woodhouse9f462572007-12-12 22:50:21 -0500191 ret = lbs_update_channel(priv);
David Woodhoused1a469f2007-12-16 17:21:00 -0500192 if (ret) {
David Woodhouse23d36ee2007-12-12 00:14:21 -0500193 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
David Woodhoused1a469f2007-12-16 17:21:00 -0500194 goto done;
Dan Williamsef9a2642007-05-25 16:46:33 -0400195 }
196
David Woodhouseaa21c002007-12-08 20:04:36 +0000197 if (assoc_req->channel == priv->curbssparams.channel)
Dan Williamsef9a2642007-05-25 16:46:33 -0400198 goto done;
199
David Woodhouse8642f1f2007-12-11 20:03:01 -0500200 if (priv->mesh_dev) {
David Woodhouse86062132007-12-13 00:32:36 -0500201 /* Change mesh channel first; 21.p21 firmware won't let
202 you change channel otherwise (even though it'll return
203 an error to this */
204 lbs_mesh_config(priv, 0, assoc_req->channel);
David Woodhouse8642f1f2007-12-11 20:03:01 -0500205 }
206
Dan Williamsef9a2642007-05-25 16:46:33 -0400207 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
David Woodhouse86062132007-12-13 00:32:36 -0500208 priv->curbssparams.channel, assoc_req->channel);
Dan Williamsef9a2642007-05-25 16:46:33 -0400209
Dan Williams2dd4b262007-12-11 16:54:15 -0500210 ret = lbs_set_channel(priv, assoc_req->channel);
211 if (ret < 0)
David Woodhouse23d36ee2007-12-12 00:14:21 -0500212 lbs_deb_assoc("ASSOC: channel: error setting channel.\n");
Dan Williamsef9a2642007-05-25 16:46:33 -0400213
Dan Williams2dd4b262007-12-11 16:54:15 -0500214 /* FIXME: shouldn't need to grab the channel _again_ after setting
215 * it since the firmware is supposed to return the new channel, but
216 * whatever... */
David Woodhouse9f462572007-12-12 22:50:21 -0500217 ret = lbs_update_channel(priv);
David Woodhoused1a469f2007-12-16 17:21:00 -0500218 if (ret) {
David Woodhouse23d36ee2007-12-12 00:14:21 -0500219 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
David Woodhoused1a469f2007-12-16 17:21:00 -0500220 goto done;
221 }
Dan Williamsef9a2642007-05-25 16:46:33 -0400222
David Woodhouseaa21c002007-12-08 20:04:36 +0000223 if (assoc_req->channel != priv->curbssparams.channel) {
David Woodhouse88ae2912007-12-11 19:57:05 -0500224 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n",
Dan Williamsef9a2642007-05-25 16:46:33 -0400225 assoc_req->channel);
David Woodhouse8642f1f2007-12-11 20:03:01 -0500226 goto restore_mesh;
Dan Williamsef9a2642007-05-25 16:46:33 -0400227 }
228
229 if ( assoc_req->secinfo.wep_enabled
230 && (assoc_req->wep_keys[0].len
231 || assoc_req->wep_keys[1].len
232 || assoc_req->wep_keys[2].len
233 || assoc_req->wep_keys[3].len)) {
234 /* Make sure WEP keys are re-sent to firmware */
235 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
236 }
237
238 /* Must restart/rejoin adhoc networks after channel change */
David Woodhouse23d36ee2007-12-12 00:14:21 -0500239 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Dan Williamsef9a2642007-05-25 16:46:33 -0400240
David Woodhouse8642f1f2007-12-11 20:03:01 -0500241 restore_mesh:
242 if (priv->mesh_dev)
David Woodhouse86062132007-12-13 00:32:36 -0500243 lbs_mesh_config(priv, 1, priv->curbssparams.channel);
David Woodhouse8642f1f2007-12-11 20:03:01 -0500244
245 done:
Dan Williamsef9a2642007-05-25 16:46:33 -0400246 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
247 return ret;
248}
249
250
Holger Schurig69f90322007-11-23 15:43:44 +0100251static int assoc_helper_wep_keys(struct lbs_private *priv,
David Woodhousef70dd452007-12-18 00:18:05 -0500252 struct assoc_request *assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200253{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200254 int i;
255 int ret = 0;
256
Holger Schurig9012b282007-05-25 11:27:16 -0400257 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258
259 /* Set or remove WEP keys */
David Woodhousef70dd452007-12-18 00:18:05 -0500260 if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len ||
261 assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len)
262 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req);
263 else
264 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265
266 if (ret)
267 goto out;
268
269 /* enable/disable the MAC's WEP packet filter */
Dan Williams889c05b2007-05-10 22:57:23 -0400270 if (assoc_req->secinfo.wep_enabled)
David Woodhouseaa21c002007-12-08 20:04:36 +0000271 priv->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200272 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000273 priv->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE;
David Woodhousef70dd452007-12-18 00:18:05 -0500274
Holger Schurig10078322007-11-15 18:05:47 -0500275 ret = lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200276 if (ret)
277 goto out;
278
David Woodhouseaa21c002007-12-08 20:04:36 +0000279 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200280
David Woodhouseaa21c002007-12-08 20:04:36 +0000281 /* Copy WEP keys into priv wep key fields */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200282 for (i = 0; i < 4; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000283 memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
David Woodhousef70dd452007-12-18 00:18:05 -0500284 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200285 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000286 priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200287
David Woodhouseaa21c002007-12-08 20:04:36 +0000288 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200289
290out:
Holger Schurig9012b282007-05-25 11:27:16 -0400291 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200292 return ret;
293}
294
Holger Schurig69f90322007-11-23 15:43:44 +0100295static int assoc_helper_secinfo(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200296 struct assoc_request * assoc_req)
297{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298 int ret = 0;
David Woodhouse4f59abf2007-12-18 00:47:17 -0500299 uint16_t do_wpa;
300 uint16_t rsn = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200301
Holger Schurig9012b282007-05-25 11:27:16 -0400302 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303
David Woodhouseaa21c002007-12-08 20:04:36 +0000304 memcpy(&priv->secinfo, &assoc_req->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500305 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306
Holger Schurig10078322007-11-15 18:05:47 -0500307 ret = lbs_set_mac_packet_filter(priv);
Dan Williams90a42212007-05-25 23:01:24 -0400308 if (ret)
309 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310
Dan Williams18c96c342007-06-18 12:01:12 -0400311 /* If RSN is already enabled, don't try to enable it again, since
312 * ENABLE_RSN resets internal state machines and will clobber the
313 * 4-way WPA handshake.
314 */
315
316 /* Get RSN enabled/disabled */
David Woodhouse4f59abf2007-12-18 00:47:17 -0500317 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn);
Dan Williams18c96c342007-06-18 12:01:12 -0400318 if (ret) {
David Woodhouse23d36ee2007-12-12 00:14:21 -0500319 lbs_deb_assoc("Failed to get RSN status: %d\n", ret);
Dan Williams18c96c342007-06-18 12:01:12 -0400320 goto out;
321 }
322
323 /* Don't re-enable RSN if it's already enabled */
David Woodhouse4f59abf2007-12-18 00:47:17 -0500324 do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled;
Dan Williams18c96c342007-06-18 12:01:12 -0400325 if (do_wpa == rsn)
326 goto out;
327
328 /* Set RSN enabled/disabled */
David Woodhouse4f59abf2007-12-18 00:47:17 -0500329 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa);
Dan Williams90a42212007-05-25 23:01:24 -0400330
331out:
Holger Schurig9012b282007-05-25 11:27:16 -0400332 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333 return ret;
334}
335
336
Holger Schurig69f90322007-11-23 15:43:44 +0100337static int assoc_helper_wpa_keys(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 struct assoc_request * assoc_req)
339{
340 int ret = 0;
Dan Williams2bcde512007-10-03 10:37:45 -0400341 unsigned int flags = assoc_req->flags;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342
Holger Schurig9012b282007-05-25 11:27:16 -0400343 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344
Dan Williams2bcde512007-10-03 10:37:45 -0400345 /* Work around older firmware bug where WPA unicast and multicast
346 * keys must be set independently. Seen in SDIO parts with firmware
347 * version 5.0.11p0.
348 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349
Dan Williams2bcde512007-10-03 10:37:45 -0400350 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
351 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500352 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400353 CMD_802_11_KEY_MATERIAL,
354 CMD_ACT_SET,
355 CMD_OPTION_WAITFORRSP,
356 0, assoc_req);
357 assoc_req->flags = flags;
358 }
359
360 if (ret)
361 goto out;
362
363 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
364 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
365
Holger Schurig10078322007-11-15 18:05:47 -0500366 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400367 CMD_802_11_KEY_MATERIAL,
368 CMD_ACT_SET,
369 CMD_OPTION_WAITFORRSP,
370 0, assoc_req);
371 assoc_req->flags = flags;
372 }
373
374out:
Holger Schurig9012b282007-05-25 11:27:16 -0400375 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376 return ret;
377}
378
379
Holger Schurig69f90322007-11-23 15:43:44 +0100380static int assoc_helper_wpa_ie(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200381 struct assoc_request * assoc_req)
382{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383 int ret = 0;
384
Holger Schurig9012b282007-05-25 11:27:16 -0400385 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386
387 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000388 memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
389 priv->wpa_ie_len = assoc_req->wpa_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200390 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000391 memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
392 priv->wpa_ie_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200393 }
394
Holger Schurig9012b282007-05-25 11:27:16 -0400395 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200396 return ret;
397}
398
399
David Woodhouseaa21c002007-12-08 20:04:36 +0000400static int should_deauth_infrastructure(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200401 struct assoc_request * assoc_req)
402{
Holger Schurig0765af42007-10-15 12:55:56 +0200403 int ret = 0;
404
David Woodhouseaa21c002007-12-08 20:04:36 +0000405 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200406 return 0;
407
Holger Schurig52507c22008-01-28 17:25:53 +0100408 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200409 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200410 lbs_deb_assoc("Deauthenticating due to new SSID\n");
411 ret = 1;
412 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413 }
414
415 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000416 if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
Holger Schurig0765af42007-10-15 12:55:56 +0200417 lbs_deb_assoc("Deauthenticating due to new security\n");
418 ret = 1;
419 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200420 }
421 }
422
423 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200424 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
425 ret = 1;
426 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200427 }
428
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400429 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200430 lbs_deb_assoc("Deauthenticating due to channel switch\n");
431 ret = 1;
432 goto out;
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400433 }
434
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200435 /* FIXME: deal with 'auto' mode somehow */
436 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200437 if (assoc_req->mode != IW_MODE_INFRA) {
438 lbs_deb_assoc("Deauthenticating due to leaving "
439 "infra mode\n");
440 ret = 1;
441 goto out;
442 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443 }
444
Holger Schurig0765af42007-10-15 12:55:56 +0200445out:
446 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Holger Schurig52507c22008-01-28 17:25:53 +0100447 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200448}
449
450
David Woodhouseaa21c002007-12-08 20:04:36 +0000451static int should_stop_adhoc(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200452 struct assoc_request * assoc_req)
453{
Holger Schurig0765af42007-10-15 12:55:56 +0200454 lbs_deb_enter(LBS_DEB_ASSOC);
455
David Woodhouseaa21c002007-12-08 20:04:36 +0000456 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457 return 0;
458
David Woodhouseaa21c002007-12-08 20:04:36 +0000459 if (lbs_ssid_cmp(priv->curbssparams.ssid,
460 priv->curbssparams.ssid_len,
Dan Williamsd8efea22007-05-28 23:54:55 -0400461 assoc_req->ssid, assoc_req->ssid_len) != 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200462 return 1;
463
464 /* FIXME: deal with 'auto' mode somehow */
465 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400466 if (assoc_req->mode != IW_MODE_ADHOC)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200467 return 1;
468 }
469
Dan Williamsef9a2642007-05-25 16:46:33 -0400470 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000471 if (assoc_req->channel != priv->curbssparams.channel)
Dan Williamsef9a2642007-05-25 16:46:33 -0400472 return 1;
473 }
474
Holger Schurig0765af42007-10-15 12:55:56 +0200475 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 return 0;
477}
478
479
Holger Schurig10078322007-11-15 18:05:47 -0500480void lbs_association_worker(struct work_struct *work)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481{
Holger Schurig69f90322007-11-23 15:43:44 +0100482 struct lbs_private *priv = container_of(work, struct lbs_private,
483 assoc_work.work);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200484 struct assoc_request * assoc_req = NULL;
485 int ret = 0;
486 int find_any_ssid = 0;
Joe Perches0795af52007-10-03 17:59:30 -0700487 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200488
Holger Schurig9012b282007-05-25 11:27:16 -0400489 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200490
David Woodhouseaa21c002007-12-08 20:04:36 +0000491 mutex_lock(&priv->lock);
492 assoc_req = priv->pending_assoc_req;
493 priv->pending_assoc_req = NULL;
494 priv->in_progress_assoc_req = assoc_req;
495 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496
Holger Schurig9012b282007-05-25 11:27:16 -0400497 if (!assoc_req)
498 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200499
Holger Schurig0765af42007-10-15 12:55:56 +0200500 lbs_deb_assoc(
501 "Association Request:\n"
502 " flags: 0x%08lx\n"
503 " SSID: '%s'\n"
504 " chann: %d\n"
505 " band: %d\n"
506 " mode: %d\n"
507 " BSSID: %s\n"
508 " secinfo: %s%s%s\n"
509 " auth_mode: %d\n",
510 assoc_req->flags,
511 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
512 assoc_req->channel, assoc_req->band, assoc_req->mode,
513 print_mac(mac, assoc_req->bssid),
514 assoc_req->secinfo.WPAenabled ? " WPA" : "",
515 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
516 assoc_req->secinfo.wep_enabled ? " WEP" : "",
517 assoc_req->secinfo.auth_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200518
519 /* If 'any' SSID was specified, find an SSID to associate with */
520 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
Dan Williamsd8efea22007-05-28 23:54:55 -0400521 && !assoc_req->ssid_len)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200522 find_any_ssid = 1;
523
524 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
525 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf209312007-05-25 17:28:30 -0400526 if (compare_ether_addr(assoc_req->bssid, bssid_any)
527 && compare_ether_addr(assoc_req->bssid, bssid_off))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528 find_any_ssid = 0;
529 }
530
531 if (find_any_ssid) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400532 u8 new_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200533
Holger Schurig10078322007-11-15 18:05:47 -0500534 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400535 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200536 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400537 lbs_deb_assoc("Could not find best network\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200538 ret = -ENETUNREACH;
539 goto out;
540 }
541
542 /* Ensure we switch to the mode of the AP */
Dan Williams0dc5a292007-05-10 22:58:02 -0400543 if (assoc_req->mode == IW_MODE_AUTO) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200544 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
545 assoc_req->mode = new_mode;
546 }
547 }
548
549 /*
550 * Check if the attributes being changing require deauthentication
551 * from the currently associated infrastructure access point.
552 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000553 if (priv->mode == IW_MODE_INFRA) {
554 if (should_deauth_infrastructure(priv, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500555 ret = lbs_send_deauthentication(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200556 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400557 lbs_deb_assoc("Deauthentication due to new "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200558 "configuration request failed: %d\n",
559 ret);
560 }
561 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000562 } else if (priv->mode == IW_MODE_ADHOC) {
563 if (should_stop_adhoc(priv, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500564 ret = lbs_stop_adhoc_network(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400566 lbs_deb_assoc("Teardown of AdHoc network due to "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567 "new configuration request failed: %d\n",
568 ret);
569 }
570
571 }
572 }
573
574 /* Send the various configuration bits to the firmware */
575 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
576 ret = assoc_helper_mode(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200577 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200578 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579 }
580
Dan Williamsef9a2642007-05-25 16:46:33 -0400581 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
582 ret = assoc_helper_channel(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200583 if (ret)
Dan Williamsef9a2642007-05-25 16:46:33 -0400584 goto out;
Dan Williamsef9a2642007-05-25 16:46:33 -0400585 }
586
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200587 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
588 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
589 ret = assoc_helper_wep_keys(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200590 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200591 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200592 }
593
594 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
595 ret = assoc_helper_secinfo(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
600 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
601 ret = assoc_helper_wpa_ie(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200602 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604 }
605
606 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
607 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
608 ret = assoc_helper_wpa_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 /* SSID/BSSID should be the _last_ config option set, because they
614 * trigger the association attempt.
615 */
616 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
617 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
618 int success = 1;
619
620 ret = assoc_helper_associate(priv, assoc_req);
621 if (ret) {
Holger Schurig91843462007-11-28 14:05:02 +0100622 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200623 ret);
624 success = 0;
625 }
626
David Woodhouseaa21c002007-12-08 20:04:36 +0000627 if (priv->connect_status != LBS_CONNECTED) {
Holger Schurig91843462007-11-28 14:05:02 +0100628 lbs_deb_assoc("ASSOC: association unsuccessful, "
629 "not connected\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200630 success = 0;
631 }
632
633 if (success) {
Holger Schurig52507c22008-01-28 17:25:53 +0100634 lbs_deb_assoc("associated to %s\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000635 print_mac(mac, priv->curbssparams.bssid));
Holger Schurig10078322007-11-15 18:05:47 -0500636 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400637 CMD_802_11_RSSI,
638 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639
Holger Schurig10078322007-11-15 18:05:47 -0500640 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400641 CMD_802_11_GET_LOG,
642 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200643 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200644 ret = -1;
645 }
646 }
647
648out:
649 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400650 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200651 ret);
652 }
Dan Williamse76850d2007-05-25 17:09:41 -0400653
David Woodhouseaa21c002007-12-08 20:04:36 +0000654 mutex_lock(&priv->lock);
655 priv->in_progress_assoc_req = NULL;
656 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200657 kfree(assoc_req);
Holger Schurig9012b282007-05-25 11:27:16 -0400658
659done:
660 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200661}
662
663
664/*
665 * Caller MUST hold any necessary locks
666 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000667struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200668{
669 struct assoc_request * assoc_req;
670
Holger Schurig0765af42007-10-15 12:55:56 +0200671 lbs_deb_enter(LBS_DEB_ASSOC);
David Woodhouseaa21c002007-12-08 20:04:36 +0000672 if (!priv->pending_assoc_req) {
673 priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
Dan Williamse76850d2007-05-25 17:09:41 -0400674 GFP_KERNEL);
David Woodhouseaa21c002007-12-08 20:04:36 +0000675 if (!priv->pending_assoc_req) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200676 lbs_pr_info("Not enough memory to allocate association"
677 " request!\n");
678 return NULL;
679 }
680 }
681
682 /* Copy current configuration attributes to the association request,
683 * but don't overwrite any that are already set.
684 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000685 assoc_req = priv->pending_assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200686 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000687 memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400688 IW_ESSID_MAX_SIZE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000689 assoc_req->ssid_len = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200690 }
691
692 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000693 assoc_req->channel = priv->curbssparams.channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200694
Dan Williamse76850d2007-05-25 17:09:41 -0400695 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000696 assoc_req->band = priv->curbssparams.band;
Dan Williamse76850d2007-05-25 17:09:41 -0400697
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000699 assoc_req->mode = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200700
701 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000702 memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200703 ETH_ALEN);
704 }
705
706 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
707 int i;
708 for (i = 0; i < 4; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000709 memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
Dan Williams1443b652007-08-02 10:45:55 -0400710 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200711 }
712 }
713
714 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000715 assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200716
717 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000718 memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400719 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200720 }
721
722 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000723 memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400724 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200725 }
726
727 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000728 memcpy(&assoc_req->secinfo, &priv->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500729 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200730 }
731
732 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000733 memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200734 MAX_WPA_IE_LEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000735 assoc_req->wpa_ie_len = priv->wpa_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200736 }
737
Holger Schurig0765af42007-10-15 12:55:56 +0200738 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200739 return assoc_req;
740}