blob: 87e145ffe8f1a6e72bd6cdf9045e2901b79b89d1 [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 Schurig10078322007-11-15 18:05:47 -0500184void lbs_sync_channel(struct work_struct *work)
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400185{
Holger Schurig69f90322007-11-23 15:43:44 +0100186 struct lbs_private *priv = container_of(work, struct lbs_private,
187 sync_channel);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400188
Holger Schurig0765af42007-10-15 12:55:56 +0200189 lbs_deb_enter(LBS_DEB_ASSOC);
David Woodhouse9f462572007-12-12 22:50:21 -0500190 if (lbs_update_channel(priv))
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400191 lbs_pr_info("Channel synchronization failed.");
Holger Schurig0765af42007-10-15 12:55:56 +0200192 lbs_deb_leave(LBS_DEB_ASSOC);
Luis Carlos Cobo Rusb8bedef2007-05-30 12:14:34 -0400193}
194
Holger Schurig69f90322007-11-23 15:43:44 +0100195static int assoc_helper_channel(struct lbs_private *priv,
Dan Williamsef9a2642007-05-25 16:46:33 -0400196 struct assoc_request * assoc_req)
197{
Dan Williamsef9a2642007-05-25 16:46:33 -0400198 int ret = 0;
199
200 lbs_deb_enter(LBS_DEB_ASSOC);
201
David Woodhouse9f462572007-12-12 22:50:21 -0500202 ret = lbs_update_channel(priv);
David Woodhoused1a469f2007-12-16 17:21:00 -0500203 if (ret) {
David Woodhouse23d36ee2007-12-12 00:14:21 -0500204 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
David Woodhoused1a469f2007-12-16 17:21:00 -0500205 goto done;
Dan Williamsef9a2642007-05-25 16:46:33 -0400206 }
207
David Woodhouseaa21c002007-12-08 20:04:36 +0000208 if (assoc_req->channel == priv->curbssparams.channel)
Dan Williamsef9a2642007-05-25 16:46:33 -0400209 goto done;
210
David Woodhouse8642f1f2007-12-11 20:03:01 -0500211 if (priv->mesh_dev) {
David Woodhouse86062132007-12-13 00:32:36 -0500212 /* Change mesh channel first; 21.p21 firmware won't let
213 you change channel otherwise (even though it'll return
214 an error to this */
215 lbs_mesh_config(priv, 0, assoc_req->channel);
David Woodhouse8642f1f2007-12-11 20:03:01 -0500216 }
217
Dan Williamsef9a2642007-05-25 16:46:33 -0400218 lbs_deb_assoc("ASSOC: channel: %d -> %d\n",
David Woodhouse86062132007-12-13 00:32:36 -0500219 priv->curbssparams.channel, assoc_req->channel);
Dan Williamsef9a2642007-05-25 16:46:33 -0400220
Dan Williams2dd4b262007-12-11 16:54:15 -0500221 ret = lbs_set_channel(priv, assoc_req->channel);
222 if (ret < 0)
David Woodhouse23d36ee2007-12-12 00:14:21 -0500223 lbs_deb_assoc("ASSOC: channel: error setting channel.\n");
Dan Williamsef9a2642007-05-25 16:46:33 -0400224
Dan Williams2dd4b262007-12-11 16:54:15 -0500225 /* FIXME: shouldn't need to grab the channel _again_ after setting
226 * it since the firmware is supposed to return the new channel, but
227 * whatever... */
David Woodhouse9f462572007-12-12 22:50:21 -0500228 ret = lbs_update_channel(priv);
David Woodhoused1a469f2007-12-16 17:21:00 -0500229 if (ret) {
David Woodhouse23d36ee2007-12-12 00:14:21 -0500230 lbs_deb_assoc("ASSOC: channel: error getting channel.\n");
David Woodhoused1a469f2007-12-16 17:21:00 -0500231 goto done;
232 }
Dan Williamsef9a2642007-05-25 16:46:33 -0400233
David Woodhouseaa21c002007-12-08 20:04:36 +0000234 if (assoc_req->channel != priv->curbssparams.channel) {
David Woodhouse88ae2912007-12-11 19:57:05 -0500235 lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n",
Dan Williamsef9a2642007-05-25 16:46:33 -0400236 assoc_req->channel);
David Woodhouse8642f1f2007-12-11 20:03:01 -0500237 goto restore_mesh;
Dan Williamsef9a2642007-05-25 16:46:33 -0400238 }
239
240 if ( assoc_req->secinfo.wep_enabled
241 && (assoc_req->wep_keys[0].len
242 || assoc_req->wep_keys[1].len
243 || assoc_req->wep_keys[2].len
244 || assoc_req->wep_keys[3].len)) {
245 /* Make sure WEP keys are re-sent to firmware */
246 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
247 }
248
249 /* Must restart/rejoin adhoc networks after channel change */
David Woodhouse23d36ee2007-12-12 00:14:21 -0500250 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
Dan Williamsef9a2642007-05-25 16:46:33 -0400251
David Woodhouse8642f1f2007-12-11 20:03:01 -0500252 restore_mesh:
253 if (priv->mesh_dev)
David Woodhouse86062132007-12-13 00:32:36 -0500254 lbs_mesh_config(priv, 1, priv->curbssparams.channel);
David Woodhouse8642f1f2007-12-11 20:03:01 -0500255
256 done:
Dan Williamsef9a2642007-05-25 16:46:33 -0400257 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
258 return ret;
259}
260
261
Holger Schurig69f90322007-11-23 15:43:44 +0100262static int assoc_helper_wep_keys(struct lbs_private *priv,
David Woodhousef70dd452007-12-18 00:18:05 -0500263 struct assoc_request *assoc_req)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200264{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265 int i;
266 int ret = 0;
267
Holger Schurig9012b282007-05-25 11:27:16 -0400268 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200269
270 /* Set or remove WEP keys */
David Woodhousef70dd452007-12-18 00:18:05 -0500271 if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len ||
272 assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len)
273 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req);
274 else
275 ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200276
277 if (ret)
278 goto out;
279
280 /* enable/disable the MAC's WEP packet filter */
Dan Williams889c05b2007-05-10 22:57:23 -0400281 if (assoc_req->secinfo.wep_enabled)
David Woodhouseaa21c002007-12-08 20:04:36 +0000282 priv->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200283 else
David Woodhouseaa21c002007-12-08 20:04:36 +0000284 priv->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE;
David Woodhousef70dd452007-12-18 00:18:05 -0500285
Holger Schurig10078322007-11-15 18:05:47 -0500286 ret = lbs_set_mac_packet_filter(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200287 if (ret)
288 goto out;
289
David Woodhouseaa21c002007-12-08 20:04:36 +0000290 mutex_lock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200291
David Woodhouseaa21c002007-12-08 20:04:36 +0000292 /* Copy WEP keys into priv wep key fields */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200293 for (i = 0; i < 4; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000294 memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i],
David Woodhousef70dd452007-12-18 00:18:05 -0500295 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200296 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000297 priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298
David Woodhouseaa21c002007-12-08 20:04:36 +0000299 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300
301out:
Holger Schurig9012b282007-05-25 11:27:16 -0400302 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200303 return ret;
304}
305
Holger Schurig69f90322007-11-23 15:43:44 +0100306static int assoc_helper_secinfo(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307 struct assoc_request * assoc_req)
308{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309 int ret = 0;
David Woodhouse4f59abf2007-12-18 00:47:17 -0500310 uint16_t do_wpa;
311 uint16_t rsn = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312
Holger Schurig9012b282007-05-25 11:27:16 -0400313 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314
David Woodhouseaa21c002007-12-08 20:04:36 +0000315 memcpy(&priv->secinfo, &assoc_req->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500316 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317
Holger Schurig10078322007-11-15 18:05:47 -0500318 ret = lbs_set_mac_packet_filter(priv);
Dan Williams90a42212007-05-25 23:01:24 -0400319 if (ret)
320 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321
Dan Williams18c96c342007-06-18 12:01:12 -0400322 /* If RSN is already enabled, don't try to enable it again, since
323 * ENABLE_RSN resets internal state machines and will clobber the
324 * 4-way WPA handshake.
325 */
326
327 /* Get RSN enabled/disabled */
David Woodhouse4f59abf2007-12-18 00:47:17 -0500328 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn);
Dan Williams18c96c342007-06-18 12:01:12 -0400329 if (ret) {
David Woodhouse23d36ee2007-12-12 00:14:21 -0500330 lbs_deb_assoc("Failed to get RSN status: %d\n", ret);
Dan Williams18c96c342007-06-18 12:01:12 -0400331 goto out;
332 }
333
334 /* Don't re-enable RSN if it's already enabled */
David Woodhouse4f59abf2007-12-18 00:47:17 -0500335 do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled;
Dan Williams18c96c342007-06-18 12:01:12 -0400336 if (do_wpa == rsn)
337 goto out;
338
339 /* Set RSN enabled/disabled */
David Woodhouse4f59abf2007-12-18 00:47:17 -0500340 ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa);
Dan Williams90a42212007-05-25 23:01:24 -0400341
342out:
Holger Schurig9012b282007-05-25 11:27:16 -0400343 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344 return ret;
345}
346
347
Holger Schurig69f90322007-11-23 15:43:44 +0100348static int assoc_helper_wpa_keys(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349 struct assoc_request * assoc_req)
350{
351 int ret = 0;
Dan Williams2bcde512007-10-03 10:37:45 -0400352 unsigned int flags = assoc_req->flags;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353
Holger Schurig9012b282007-05-25 11:27:16 -0400354 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200355
Dan Williams2bcde512007-10-03 10:37:45 -0400356 /* Work around older firmware bug where WPA unicast and multicast
357 * keys must be set independently. Seen in SDIO parts with firmware
358 * version 5.0.11p0.
359 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360
Dan Williams2bcde512007-10-03 10:37:45 -0400361 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
362 clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
Holger Schurig10078322007-11-15 18:05:47 -0500363 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400364 CMD_802_11_KEY_MATERIAL,
365 CMD_ACT_SET,
366 CMD_OPTION_WAITFORRSP,
367 0, assoc_req);
368 assoc_req->flags = flags;
369 }
370
371 if (ret)
372 goto out;
373
374 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
375 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
376
Holger Schurig10078322007-11-15 18:05:47 -0500377 ret = lbs_prepare_and_send_command(priv,
Dan Williams2bcde512007-10-03 10:37:45 -0400378 CMD_802_11_KEY_MATERIAL,
379 CMD_ACT_SET,
380 CMD_OPTION_WAITFORRSP,
381 0, assoc_req);
382 assoc_req->flags = flags;
383 }
384
385out:
Holger Schurig9012b282007-05-25 11:27:16 -0400386 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200387 return ret;
388}
389
390
Holger Schurig69f90322007-11-23 15:43:44 +0100391static int assoc_helper_wpa_ie(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392 struct assoc_request * assoc_req)
393{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394 int ret = 0;
395
Holger Schurig9012b282007-05-25 11:27:16 -0400396 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397
398 if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000399 memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len);
400 priv->wpa_ie_len = assoc_req->wpa_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200401 } else {
David Woodhouseaa21c002007-12-08 20:04:36 +0000402 memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN);
403 priv->wpa_ie_len = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 }
405
Holger Schurig9012b282007-05-25 11:27:16 -0400406 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200407 return ret;
408}
409
410
David Woodhouseaa21c002007-12-08 20:04:36 +0000411static int should_deauth_infrastructure(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200412 struct assoc_request * assoc_req)
413{
Holger Schurig0765af42007-10-15 12:55:56 +0200414 int ret = 0;
415
416 lbs_deb_enter(LBS_DEB_ASSOC);
417
David Woodhouseaa21c002007-12-08 20:04:36 +0000418 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419 return 0;
420
421 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200422 lbs_deb_assoc("Deauthenticating due to new SSID\n");
423 ret = 1;
424 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425 }
426
427 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000428 if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
Holger Schurig0765af42007-10-15 12:55:56 +0200429 lbs_deb_assoc("Deauthenticating due to new security\n");
430 ret = 1;
431 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200432 }
433 }
434
435 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200436 lbs_deb_assoc("Deauthenticating due to new BSSID\n");
437 ret = 1;
438 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439 }
440
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400441 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200442 lbs_deb_assoc("Deauthenticating due to channel switch\n");
443 ret = 1;
444 goto out;
Luis Carlos Cobo Rusfff47f12007-05-30 12:16:13 -0400445 }
446
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200447 /* FIXME: deal with 'auto' mode somehow */
448 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Holger Schurig0765af42007-10-15 12:55:56 +0200449 if (assoc_req->mode != IW_MODE_INFRA) {
450 lbs_deb_assoc("Deauthenticating due to leaving "
451 "infra mode\n");
452 ret = 1;
453 goto out;
454 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200455 }
456
Holger Schurig0765af42007-10-15 12:55:56 +0200457out:
458 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459 return 0;
460}
461
462
David Woodhouseaa21c002007-12-08 20:04:36 +0000463static int should_stop_adhoc(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464 struct assoc_request * assoc_req)
465{
Holger Schurig0765af42007-10-15 12:55:56 +0200466 lbs_deb_enter(LBS_DEB_ASSOC);
467
David Woodhouseaa21c002007-12-08 20:04:36 +0000468 if (priv->connect_status != LBS_CONNECTED)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200469 return 0;
470
David Woodhouseaa21c002007-12-08 20:04:36 +0000471 if (lbs_ssid_cmp(priv->curbssparams.ssid,
472 priv->curbssparams.ssid_len,
Dan Williamsd8efea22007-05-28 23:54:55 -0400473 assoc_req->ssid, assoc_req->ssid_len) != 0)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200474 return 1;
475
476 /* FIXME: deal with 'auto' mode somehow */
477 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400478 if (assoc_req->mode != IW_MODE_ADHOC)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200479 return 1;
480 }
481
Dan Williamsef9a2642007-05-25 16:46:33 -0400482 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000483 if (assoc_req->channel != priv->curbssparams.channel)
Dan Williamsef9a2642007-05-25 16:46:33 -0400484 return 1;
485 }
486
Holger Schurig0765af42007-10-15 12:55:56 +0200487 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200488 return 0;
489}
490
491
Holger Schurig10078322007-11-15 18:05:47 -0500492void lbs_association_worker(struct work_struct *work)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200493{
Holger Schurig69f90322007-11-23 15:43:44 +0100494 struct lbs_private *priv = container_of(work, struct lbs_private,
495 assoc_work.work);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200496 struct assoc_request * assoc_req = NULL;
497 int ret = 0;
498 int find_any_ssid = 0;
Joe Perches0795af52007-10-03 17:59:30 -0700499 DECLARE_MAC_BUF(mac);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200500
Holger Schurig9012b282007-05-25 11:27:16 -0400501 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200502
David Woodhouseaa21c002007-12-08 20:04:36 +0000503 mutex_lock(&priv->lock);
504 assoc_req = priv->pending_assoc_req;
505 priv->pending_assoc_req = NULL;
506 priv->in_progress_assoc_req = assoc_req;
507 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200508
Holger Schurig9012b282007-05-25 11:27:16 -0400509 if (!assoc_req)
510 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511
Holger Schurig0765af42007-10-15 12:55:56 +0200512 lbs_deb_assoc(
513 "Association Request:\n"
514 " flags: 0x%08lx\n"
515 " SSID: '%s'\n"
516 " chann: %d\n"
517 " band: %d\n"
518 " mode: %d\n"
519 " BSSID: %s\n"
520 " secinfo: %s%s%s\n"
521 " auth_mode: %d\n",
522 assoc_req->flags,
523 escape_essid(assoc_req->ssid, assoc_req->ssid_len),
524 assoc_req->channel, assoc_req->band, assoc_req->mode,
525 print_mac(mac, assoc_req->bssid),
526 assoc_req->secinfo.WPAenabled ? " WPA" : "",
527 assoc_req->secinfo.WPA2enabled ? " WPA2" : "",
528 assoc_req->secinfo.wep_enabled ? " WEP" : "",
529 assoc_req->secinfo.auth_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200530
531 /* If 'any' SSID was specified, find an SSID to associate with */
532 if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)
Dan Williamsd8efea22007-05-28 23:54:55 -0400533 && !assoc_req->ssid_len)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200534 find_any_ssid = 1;
535
536 /* But don't use 'any' SSID if there's a valid locked BSSID to use */
537 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
Dan Williams3cf209312007-05-25 17:28:30 -0400538 if (compare_ether_addr(assoc_req->bssid, bssid_any)
539 && compare_ether_addr(assoc_req->bssid, bssid_off))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200540 find_any_ssid = 0;
541 }
542
543 if (find_any_ssid) {
Dan Williams0dc5a292007-05-10 22:58:02 -0400544 u8 new_mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200545
Holger Schurig10078322007-11-15 18:05:47 -0500546 ret = lbs_find_best_network_ssid(priv, assoc_req->ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400547 &assoc_req->ssid_len, assoc_req->mode, &new_mode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200548 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400549 lbs_deb_assoc("Could not find best network\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200550 ret = -ENETUNREACH;
551 goto out;
552 }
553
554 /* Ensure we switch to the mode of the AP */
Dan Williams0dc5a292007-05-10 22:58:02 -0400555 if (assoc_req->mode == IW_MODE_AUTO) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200556 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
557 assoc_req->mode = new_mode;
558 }
559 }
560
561 /*
562 * Check if the attributes being changing require deauthentication
563 * from the currently associated infrastructure access point.
564 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000565 if (priv->mode == IW_MODE_INFRA) {
566 if (should_deauth_infrastructure(priv, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500567 ret = lbs_send_deauthentication(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400569 lbs_deb_assoc("Deauthentication due to new "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200570 "configuration request failed: %d\n",
571 ret);
572 }
573 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000574 } else if (priv->mode == IW_MODE_ADHOC) {
575 if (should_stop_adhoc(priv, assoc_req)) {
Holger Schurig10078322007-11-15 18:05:47 -0500576 ret = lbs_stop_adhoc_network(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200577 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400578 lbs_deb_assoc("Teardown of AdHoc network due to "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579 "new configuration request failed: %d\n",
580 ret);
581 }
582
583 }
584 }
585
586 /* Send the various configuration bits to the firmware */
587 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
588 ret = assoc_helper_mode(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200589 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200590 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200591 }
592
Dan Williamsef9a2642007-05-25 16:46:33 -0400593 if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) {
594 ret = assoc_helper_channel(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200595 if (ret)
Dan Williamsef9a2642007-05-25 16:46:33 -0400596 goto out;
Dan Williamsef9a2642007-05-25 16:46:33 -0400597 }
598
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200599 if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)
600 || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) {
601 ret = assoc_helper_wep_keys(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_SECINFO, &assoc_req->flags)) {
607 ret = assoc_helper_secinfo(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200608 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610 }
611
612 if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
613 ret = assoc_helper_wpa_ie(priv, assoc_req);
Holger Schurig0765af42007-10-15 12:55:56 +0200614 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 }
617
618 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)
619 || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
620 ret = assoc_helper_wpa_keys(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 /* SSID/BSSID should be the _last_ config option set, because they
626 * trigger the association attempt.
627 */
628 if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)
629 || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
630 int success = 1;
631
632 ret = assoc_helper_associate(priv, assoc_req);
633 if (ret) {
Holger Schurig91843462007-11-28 14:05:02 +0100634 lbs_deb_assoc("ASSOC: association unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200635 ret);
636 success = 0;
637 }
638
David Woodhouseaa21c002007-12-08 20:04:36 +0000639 if (priv->connect_status != LBS_CONNECTED) {
Holger Schurig91843462007-11-28 14:05:02 +0100640 lbs_deb_assoc("ASSOC: association unsuccessful, "
641 "not connected\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200642 success = 0;
643 }
644
645 if (success) {
Holger Schurig91843462007-11-28 14:05:02 +0100646 lbs_deb_assoc("ASSOC: associated to '%s', %s\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000647 escape_essid(priv->curbssparams.ssid,
648 priv->curbssparams.ssid_len),
649 print_mac(mac, priv->curbssparams.bssid));
Holger Schurig10078322007-11-15 18:05:47 -0500650 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400651 CMD_802_11_RSSI,
652 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653
Holger Schurig10078322007-11-15 18:05:47 -0500654 lbs_prepare_and_send_command(priv,
Dan Williams0aef64d2007-08-02 11:31:18 -0400655 CMD_802_11_GET_LOG,
656 0, CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200657 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200658 ret = -1;
659 }
660 }
661
662out:
663 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400664 lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200665 ret);
666 }
Dan Williamse76850d2007-05-25 17:09:41 -0400667
David Woodhouseaa21c002007-12-08 20:04:36 +0000668 mutex_lock(&priv->lock);
669 priv->in_progress_assoc_req = NULL;
670 mutex_unlock(&priv->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200671 kfree(assoc_req);
Holger Schurig9012b282007-05-25 11:27:16 -0400672
673done:
674 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200675}
676
677
678/*
679 * Caller MUST hold any necessary locks
680 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000681struct assoc_request *lbs_get_association_request(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200682{
683 struct assoc_request * assoc_req;
684
Holger Schurig0765af42007-10-15 12:55:56 +0200685 lbs_deb_enter(LBS_DEB_ASSOC);
David Woodhouseaa21c002007-12-08 20:04:36 +0000686 if (!priv->pending_assoc_req) {
687 priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request),
Dan Williamse76850d2007-05-25 17:09:41 -0400688 GFP_KERNEL);
David Woodhouseaa21c002007-12-08 20:04:36 +0000689 if (!priv->pending_assoc_req) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200690 lbs_pr_info("Not enough memory to allocate association"
691 " request!\n");
692 return NULL;
693 }
694 }
695
696 /* Copy current configuration attributes to the association request,
697 * but don't overwrite any that are already set.
698 */
David Woodhouseaa21c002007-12-08 20:04:36 +0000699 assoc_req = priv->pending_assoc_req;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200700 if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000701 memcpy(&assoc_req->ssid, &priv->curbssparams.ssid,
Dan Williamsd8efea22007-05-28 23:54:55 -0400702 IW_ESSID_MAX_SIZE);
David Woodhouseaa21c002007-12-08 20:04:36 +0000703 assoc_req->ssid_len = priv->curbssparams.ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200704 }
705
706 if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000707 assoc_req->channel = priv->curbssparams.channel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200708
Dan Williamse76850d2007-05-25 17:09:41 -0400709 if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000710 assoc_req->band = priv->curbssparams.band;
Dan Williamse76850d2007-05-25 17:09:41 -0400711
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200712 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000713 assoc_req->mode = priv->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200714
715 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000716 memcpy(&assoc_req->bssid, priv->curbssparams.bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200717 ETH_ALEN);
718 }
719
720 if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) {
721 int i;
722 for (i = 0; i < 4; i++) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000723 memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i],
Dan Williams1443b652007-08-02 10:45:55 -0400724 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200725 }
726 }
727
728 if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags))
David Woodhouseaa21c002007-12-08 20:04:36 +0000729 assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200730
731 if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000732 memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400733 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200734 }
735
736 if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000737 memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key,
Dan Williams1443b652007-08-02 10:45:55 -0400738 sizeof(struct enc_key));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200739 }
740
741 if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000742 memcpy(&assoc_req->secinfo, &priv->secinfo,
Holger Schurig10078322007-11-15 18:05:47 -0500743 sizeof(struct lbs_802_11_security));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200744 }
745
746 if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000747 memcpy(&assoc_req->wpa_ie, &priv->wpa_ie,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200748 MAX_WPA_IE_LEN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000749 assoc_req->wpa_ie_len = priv->wpa_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200750 }
751
Holger Schurig0765af42007-10-15 12:55:56 +0200752 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200753 return assoc_req;
754}