Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /* Copyright (C) 2006, Red Hat, Inc. */ |
| 2 | |
| 3 | #include <linux/bitops.h> |
| 4 | #include <net/ieee80211.h> |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame^] | 5 | #include <linux/etherdevice.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 6 | |
| 7 | #include "assoc.h" |
| 8 | #include "join.h" |
| 9 | #include "decl.h" |
| 10 | #include "hostcmd.h" |
| 11 | #include "host.h" |
| 12 | |
| 13 | |
| 14 | static const u8 bssid_any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
| 15 | static const u8 bssid_off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 16 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 17 | /* From ieee80211_module.c */ |
| 18 | static const char *libertas_escape_essid(const char *essid, u8 essid_len) |
| 19 | { |
| 20 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 21 | const char *s = essid; |
| 22 | char *d = escaped; |
| 23 | |
| 24 | if (ieee80211_is_empty_essid(essid, essid_len)) |
| 25 | return ""; |
| 26 | |
| 27 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 28 | while (essid_len--) { |
| 29 | if (*s == '\0') { |
| 30 | *d++ = '\\'; |
| 31 | *d++ = '0'; |
| 32 | s++; |
| 33 | } else { |
| 34 | *d++ = *s++; |
| 35 | } |
| 36 | } |
| 37 | *d = '\0'; |
| 38 | return escaped; |
| 39 | } |
| 40 | |
| 41 | static void print_assoc_req(const char * extra, struct assoc_request * assoc_req) |
| 42 | { |
| 43 | lbs_deb_assoc( |
| 44 | "#### Association Request: %s\n" |
| 45 | " flags: 0x%08lX\n" |
| 46 | " SSID: '%s'\n" |
| 47 | " channel: %d\n" |
| 48 | " band: %d\n" |
| 49 | " mode: %d\n" |
| 50 | " BSSID: " MAC_FMT "\n" |
| 51 | " WPA: %d\n" |
| 52 | " WPA2: %d\n" |
| 53 | " WEP status: %d\n" |
| 54 | " auth: %d\n" |
| 55 | " auth_alg: %d\n" |
| 56 | " encmode: %d\n", |
| 57 | extra, assoc_req->flags, |
| 58 | libertas_escape_essid(assoc_req->ssid.ssid, assoc_req->ssid.ssidlength), |
| 59 | assoc_req->channel, assoc_req->band, assoc_req->mode, |
| 60 | MAC_ARG(assoc_req->bssid), assoc_req->secinfo.WPAenabled, |
| 61 | assoc_req->secinfo.WPA2enabled, assoc_req->secinfo.WEPstatus, |
| 62 | assoc_req->secinfo.authmode, assoc_req->secinfo.auth1xalg, |
| 63 | assoc_req->secinfo.Encryptionmode); |
| 64 | } |
| 65 | |
| 66 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 67 | static int assoc_helper_essid(wlan_private *priv, |
| 68 | struct assoc_request * assoc_req) |
| 69 | { |
| 70 | wlan_adapter *adapter = priv->adapter; |
| 71 | int ret = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 72 | struct bss_descriptor * bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 73 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 74 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 75 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 76 | /* FIXME: take channel into account when picking SSIDs if a channel |
| 77 | * is set. |
| 78 | */ |
| 79 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 80 | lbs_deb_assoc("New SSID requested: %s\n", assoc_req->ssid.ssid); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 81 | if (assoc_req->mode == IW_MODE_INFRA) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 82 | if (adapter->prescan) { |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 83 | libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 84 | } |
| 85 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 86 | bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 87 | NULL, IW_MODE_INFRA); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 88 | if (bss != NULL) { |
| 89 | lbs_deb_assoc("SSID found in scan list, associating\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 90 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
| 91 | ret = wlan_associate(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 92 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 93 | lbs_deb_assoc("SSID '%s' not found; cannot associate\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 94 | assoc_req->ssid.ssid); |
| 95 | } |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 96 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 97 | /* Scan for the network, do not save previous results. Stale |
| 98 | * scan data will cause us to join a non-existant adhoc network |
| 99 | */ |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 100 | libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 101 | |
| 102 | /* Search for the requested SSID in the scan table */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 103 | bss = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL, |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 104 | IW_MODE_ADHOC); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 105 | if (bss != NULL) { |
| 106 | lbs_deb_assoc("SSID found joining\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 107 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
| 108 | libertas_join_adhoc_network(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 109 | } else { |
| 110 | /* else send START command */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 111 | lbs_deb_assoc("SSID not found in list, so creating adhoc" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 112 | " with SSID '%s'\n", assoc_req->ssid.ssid); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 113 | memcpy(&assoc_req->bss.ssid, &assoc_req->ssid, |
| 114 | sizeof(struct WLAN_802_11_SSID)); |
| 115 | libertas_start_adhoc_network(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 116 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 117 | } |
| 118 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 119 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | static int assoc_helper_bssid(wlan_private *priv, |
| 125 | struct assoc_request * assoc_req) |
| 126 | { |
| 127 | wlan_adapter *adapter = priv->adapter; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 128 | int ret = 0; |
| 129 | struct bss_descriptor * bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 130 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 131 | lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID" MAC_FMT "\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 132 | MAC_ARG(assoc_req->bssid)); |
| 133 | |
| 134 | /* Search for index position in list for requested MAC */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 135 | bss = libertas_find_BSSID_in_list(adapter, assoc_req->bssid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 136 | assoc_req->mode); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 137 | if (bss == NULL) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 138 | lbs_deb_assoc("ASSOC: WAP: BSSID " MAC_FMT " not found, " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 139 | "cannot associate.\n", MAC_ARG(assoc_req->bssid)); |
| 140 | goto out; |
| 141 | } |
| 142 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 143 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 144 | if (assoc_req->mode == IW_MODE_INFRA) { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 145 | ret = wlan_associate(priv, assoc_req); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 146 | lbs_deb_assoc("ASSOC: wlan_associate(bssid) returned %d\n", ret); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 147 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 148 | libertas_join_adhoc_network(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 149 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 150 | |
| 151 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 152 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | static int assoc_helper_associate(wlan_private *priv, |
| 158 | struct assoc_request * assoc_req) |
| 159 | { |
| 160 | int ret = 0, done = 0; |
| 161 | |
| 162 | /* If we're given and 'any' BSSID, try associating based on SSID */ |
| 163 | |
| 164 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame^] | 165 | if (compare_ether_addr(bssid_any, assoc_req->bssid) |
| 166 | && compare_ether_addr(bssid_off, assoc_req->bssid)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 167 | ret = assoc_helper_bssid(priv, assoc_req); |
| 168 | done = 1; |
| 169 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 170 | lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 176 | ret = assoc_helper_essid(priv, assoc_req); |
| 177 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 178 | lbs_deb_assoc("ASSOC: bssid: ret = %d\n", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | static int assoc_helper_mode(wlan_private *priv, |
| 187 | struct assoc_request * assoc_req) |
| 188 | { |
| 189 | wlan_adapter *adapter = priv->adapter; |
| 190 | int ret = 0; |
| 191 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 192 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 193 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 194 | if (assoc_req->mode == adapter->mode) |
| 195 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 196 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 197 | if (assoc_req->mode == IW_MODE_INFRA) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 198 | if (adapter->psstate != PS_STATE_FULL_POWER) |
| 199 | libertas_ps_wakeup(priv, cmd_option_waitforrsp); |
| 200 | adapter->psmode = wlan802_11powermodecam; |
| 201 | } |
| 202 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 203 | adapter->mode = assoc_req->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 204 | ret = libertas_prepare_and_send_command(priv, |
| 205 | cmd_802_11_snmp_mib, |
| 206 | 0, cmd_option_waitforrsp, |
| 207 | OID_802_11_INFRASTRUCTURE_MODE, |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 208 | (void *) (size_t) assoc_req->mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 209 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 210 | done: |
| 211 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 212 | return ret; |
| 213 | } |
| 214 | |
| 215 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 216 | static int update_channel(wlan_private * priv) |
| 217 | { |
| 218 | /* the channel in f/w could be out of sync, get the current channel */ |
| 219 | return libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel, |
| 220 | cmd_opt_802_11_rf_channel_get, |
| 221 | cmd_option_waitforrsp, 0, NULL); |
| 222 | } |
| 223 | |
| 224 | static int assoc_helper_channel(wlan_private *priv, |
| 225 | struct assoc_request * assoc_req) |
| 226 | { |
| 227 | wlan_adapter *adapter = priv->adapter; |
| 228 | int ret = 0; |
| 229 | |
| 230 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 231 | |
| 232 | ret = update_channel(priv); |
| 233 | if (ret < 0) { |
| 234 | lbs_deb_assoc("ASSOC: channel: error getting channel."); |
| 235 | } |
| 236 | |
| 237 | if (assoc_req->channel == adapter->curbssparams.channel) |
| 238 | goto done; |
| 239 | |
| 240 | lbs_deb_assoc("ASSOC: channel: %d -> %d\n", |
| 241 | adapter->curbssparams.channel, assoc_req->channel); |
| 242 | |
| 243 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel, |
| 244 | cmd_opt_802_11_rf_channel_set, |
| 245 | cmd_option_waitforrsp, 0, &assoc_req->channel); |
| 246 | if (ret < 0) { |
| 247 | lbs_deb_assoc("ASSOC: channel: error setting channel."); |
| 248 | } |
| 249 | |
| 250 | ret = update_channel(priv); |
| 251 | if (ret < 0) { |
| 252 | lbs_deb_assoc("ASSOC: channel: error getting channel."); |
| 253 | } |
| 254 | |
| 255 | if (assoc_req->channel != adapter->curbssparams.channel) { |
| 256 | lbs_deb_assoc("ASSOC: channel: failed to update channel to %d", |
| 257 | assoc_req->channel); |
| 258 | goto done; |
| 259 | } |
| 260 | |
| 261 | if ( assoc_req->secinfo.wep_enabled |
| 262 | && (assoc_req->wep_keys[0].len |
| 263 | || assoc_req->wep_keys[1].len |
| 264 | || assoc_req->wep_keys[2].len |
| 265 | || assoc_req->wep_keys[3].len)) { |
| 266 | /* Make sure WEP keys are re-sent to firmware */ |
| 267 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
| 268 | } |
| 269 | |
| 270 | /* Must restart/rejoin adhoc networks after channel change */ |
| 271 | set_bit(ASSOC_FLAG_SSID, &assoc_req->flags); |
| 272 | |
| 273 | done: |
| 274 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 275 | return ret; |
| 276 | } |
| 277 | |
| 278 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 279 | static int assoc_helper_wep_keys(wlan_private *priv, |
| 280 | struct assoc_request * assoc_req) |
| 281 | { |
| 282 | wlan_adapter *adapter = priv->adapter; |
| 283 | int i; |
| 284 | int ret = 0; |
| 285 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 286 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 287 | |
| 288 | /* Set or remove WEP keys */ |
| 289 | if ( assoc_req->wep_keys[0].len |
| 290 | || assoc_req->wep_keys[1].len |
| 291 | || assoc_req->wep_keys[2].len |
| 292 | || assoc_req->wep_keys[3].len) { |
| 293 | ret = libertas_prepare_and_send_command(priv, |
| 294 | cmd_802_11_set_wep, |
| 295 | cmd_act_add, |
| 296 | cmd_option_waitforrsp, |
| 297 | 0, assoc_req); |
| 298 | } else { |
| 299 | ret = libertas_prepare_and_send_command(priv, |
| 300 | cmd_802_11_set_wep, |
| 301 | cmd_act_remove, |
| 302 | cmd_option_waitforrsp, |
| 303 | 0, NULL); |
| 304 | } |
| 305 | |
| 306 | if (ret) |
| 307 | goto out; |
| 308 | |
| 309 | /* enable/disable the MAC's WEP packet filter */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 310 | if (assoc_req->secinfo.wep_enabled) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 311 | adapter->currentpacketfilter |= cmd_act_mac_wep_enable; |
| 312 | else |
| 313 | adapter->currentpacketfilter &= ~cmd_act_mac_wep_enable; |
| 314 | ret = libertas_set_mac_packet_filter(priv); |
| 315 | if (ret) |
| 316 | goto out; |
| 317 | |
| 318 | mutex_lock(&adapter->lock); |
| 319 | |
| 320 | /* Copy WEP keys into adapter wep key fields */ |
| 321 | for (i = 0; i < 4; i++) { |
| 322 | memcpy(&adapter->wep_keys[i], &assoc_req->wep_keys[i], |
| 323 | sizeof(struct WLAN_802_11_KEY)); |
| 324 | } |
| 325 | adapter->wep_tx_keyidx = assoc_req->wep_tx_keyidx; |
| 326 | |
| 327 | mutex_unlock(&adapter->lock); |
| 328 | |
| 329 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 330 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | static int assoc_helper_secinfo(wlan_private *priv, |
| 335 | struct assoc_request * assoc_req) |
| 336 | { |
| 337 | wlan_adapter *adapter = priv->adapter; |
| 338 | int ret = 0; |
| 339 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 340 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 341 | |
| 342 | memcpy(&adapter->secinfo, &assoc_req->secinfo, |
| 343 | sizeof(struct wlan_802_11_security)); |
| 344 | |
| 345 | ret = libertas_set_mac_packet_filter(priv); |
| 346 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 347 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 348 | return ret; |
| 349 | } |
| 350 | |
| 351 | |
| 352 | static int assoc_helper_wpa_keys(wlan_private *priv, |
| 353 | struct assoc_request * assoc_req) |
| 354 | { |
| 355 | int ret = 0; |
| 356 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 357 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 358 | |
| 359 | /* enable/Disable RSN */ |
| 360 | ret = libertas_prepare_and_send_command(priv, |
| 361 | cmd_802_11_enable_rsn, |
| 362 | cmd_act_set, |
| 363 | cmd_option_waitforrsp, |
| 364 | 0, assoc_req); |
| 365 | if (ret) |
| 366 | goto out; |
| 367 | |
| 368 | ret = libertas_prepare_and_send_command(priv, |
| 369 | cmd_802_11_key_material, |
| 370 | cmd_act_set, |
| 371 | cmd_option_waitforrsp, |
| 372 | 0, assoc_req); |
| 373 | |
| 374 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 375 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 376 | return ret; |
| 377 | } |
| 378 | |
| 379 | |
| 380 | static int assoc_helper_wpa_ie(wlan_private *priv, |
| 381 | struct assoc_request * assoc_req) |
| 382 | { |
| 383 | wlan_adapter *adapter = priv->adapter; |
| 384 | int ret = 0; |
| 385 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 386 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 387 | |
| 388 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { |
| 389 | memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len); |
| 390 | adapter->wpa_ie_len = assoc_req->wpa_ie_len; |
| 391 | } else { |
| 392 | memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN); |
| 393 | adapter->wpa_ie_len = 0; |
| 394 | } |
| 395 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 396 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 397 | return ret; |
| 398 | } |
| 399 | |
| 400 | |
| 401 | static int should_deauth_infrastructure(wlan_adapter *adapter, |
| 402 | struct assoc_request * assoc_req) |
| 403 | { |
| 404 | if (adapter->connect_status != libertas_connected) |
| 405 | return 0; |
| 406 | |
| 407 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 408 | lbs_deb_assoc("Deauthenticating due to new SSID in " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 409 | " configuration request.\n"); |
| 410 | return 1; |
| 411 | } |
| 412 | |
| 413 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 414 | if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 415 | lbs_deb_assoc("Deauthenticating due to updated security " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 416 | "info in configuration request.\n"); |
| 417 | return 1; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 422 | lbs_deb_assoc("Deauthenticating due to new BSSID in " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 423 | " configuration request.\n"); |
| 424 | return 1; |
| 425 | } |
| 426 | |
| 427 | /* FIXME: deal with 'auto' mode somehow */ |
| 428 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 429 | if (assoc_req->mode != IW_MODE_INFRA) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 430 | return 1; |
| 431 | } |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | static int should_stop_adhoc(wlan_adapter *adapter, |
| 438 | struct assoc_request * assoc_req) |
| 439 | { |
| 440 | if (adapter->connect_status != libertas_connected) |
| 441 | return 0; |
| 442 | |
| 443 | if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength) |
| 444 | return 1; |
| 445 | if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid, |
Dan Williams | ad1f329 | 2007-05-10 22:52:37 -0400 | [diff] [blame] | 446 | adapter->curbssparams.ssid.ssidlength)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 447 | return 1; |
| 448 | |
| 449 | /* FIXME: deal with 'auto' mode somehow */ |
| 450 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 451 | if (assoc_req->mode != IW_MODE_ADHOC) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 452 | return 1; |
| 453 | } |
| 454 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 455 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
| 456 | if (assoc_req->channel != adapter->curbssparams.channel) |
| 457 | return 1; |
| 458 | } |
| 459 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | |
Holger Schurig | eb3ce63 | 2007-05-24 23:41:15 -0400 | [diff] [blame] | 464 | void libertas_association_worker(struct work_struct *work) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 465 | { |
| 466 | wlan_private *priv = container_of(work, wlan_private, assoc_work.work); |
| 467 | wlan_adapter *adapter = priv->adapter; |
| 468 | struct assoc_request * assoc_req = NULL; |
| 469 | int ret = 0; |
| 470 | int find_any_ssid = 0; |
| 471 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 472 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 473 | |
| 474 | mutex_lock(&adapter->lock); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 475 | assoc_req = adapter->pending_assoc_req; |
| 476 | adapter->pending_assoc_req = NULL; |
| 477 | adapter->in_progress_assoc_req = assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 478 | mutex_unlock(&adapter->lock); |
| 479 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 480 | if (!assoc_req) |
| 481 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 482 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 483 | print_assoc_req(__func__, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 484 | |
| 485 | /* If 'any' SSID was specified, find an SSID to associate with */ |
| 486 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags) |
| 487 | && !assoc_req->ssid.ssidlength) |
| 488 | find_any_ssid = 1; |
| 489 | |
| 490 | /* But don't use 'any' SSID if there's a valid locked BSSID to use */ |
| 491 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame^] | 492 | if (compare_ether_addr(assoc_req->bssid, bssid_any) |
| 493 | && compare_ether_addr(assoc_req->bssid, bssid_off)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 494 | find_any_ssid = 0; |
| 495 | } |
| 496 | |
| 497 | if (find_any_ssid) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 498 | u8 new_mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 499 | |
| 500 | ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid, |
| 501 | assoc_req->mode, &new_mode); |
| 502 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 503 | lbs_deb_assoc("Could not find best network\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 504 | ret = -ENETUNREACH; |
| 505 | goto out; |
| 506 | } |
| 507 | |
| 508 | /* Ensure we switch to the mode of the AP */ |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 509 | if (assoc_req->mode == IW_MODE_AUTO) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 510 | set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); |
| 511 | assoc_req->mode = new_mode; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * Check if the attributes being changing require deauthentication |
| 517 | * from the currently associated infrastructure access point. |
| 518 | */ |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 519 | if (adapter->mode == IW_MODE_INFRA) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 520 | if (should_deauth_infrastructure(adapter, assoc_req)) { |
| 521 | ret = libertas_send_deauthentication(priv); |
| 522 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 523 | lbs_deb_assoc("Deauthentication due to new " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 524 | "configuration request failed: %d\n", |
| 525 | ret); |
| 526 | } |
| 527 | } |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 528 | } else if (adapter->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 529 | if (should_stop_adhoc(adapter, assoc_req)) { |
| 530 | ret = libertas_stop_adhoc_network(priv); |
| 531 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 532 | lbs_deb_assoc("Teardown of AdHoc network due to " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 533 | "new configuration request failed: %d\n", |
| 534 | ret); |
| 535 | } |
| 536 | |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | /* Send the various configuration bits to the firmware */ |
| 541 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
| 542 | ret = assoc_helper_mode(priv, assoc_req); |
| 543 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 544 | lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 545 | goto out; |
| 546 | } |
| 547 | } |
| 548 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 549 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
| 550 | ret = assoc_helper_channel(priv, assoc_req); |
| 551 | if (ret) { |
| 552 | lbs_deb_assoc("ASSOC(:%d) channel: ret = %d\n", |
| 553 | __LINE__, ret); |
| 554 | goto out; |
| 555 | } |
| 556 | } |
| 557 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 558 | if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags) |
| 559 | || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) { |
| 560 | ret = assoc_helper_wep_keys(priv, assoc_req); |
| 561 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 562 | lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 563 | goto out; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
| 568 | ret = assoc_helper_secinfo(priv, assoc_req); |
| 569 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 570 | lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 571 | goto out; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
| 576 | ret = assoc_helper_wpa_ie(priv, assoc_req); |
| 577 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 578 | lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 579 | goto out; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags) |
| 584 | || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 585 | ret = assoc_helper_wpa_keys(priv, assoc_req); |
| 586 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 587 | lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 588 | goto out; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | /* SSID/BSSID should be the _last_ config option set, because they |
| 593 | * trigger the association attempt. |
| 594 | */ |
| 595 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags) |
| 596 | || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 597 | int success = 1; |
| 598 | |
| 599 | ret = assoc_helper_associate(priv, assoc_req); |
| 600 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 601 | lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 602 | ret); |
| 603 | success = 0; |
| 604 | } |
| 605 | |
| 606 | if (adapter->connect_status != libertas_connected) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 607 | lbs_deb_assoc("ASSOC: assoication attempt unsuccessful, " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 608 | "not connected.\n"); |
| 609 | success = 0; |
| 610 | } |
| 611 | |
| 612 | if (success) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 613 | lbs_deb_assoc("ASSOC: association attempt successful. " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 614 | "Associated to '%s' (" MAC_FMT ")\n", |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 615 | libertas_escape_essid(adapter->curbssparams.ssid.ssid, |
| 616 | adapter->curbssparams.ssid.ssidlength), |
| 617 | MAC_ARG(adapter->curbssparams.bssid)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 618 | libertas_prepare_and_send_command(priv, |
| 619 | cmd_802_11_rssi, |
| 620 | 0, cmd_option_waitforrsp, 0, NULL); |
| 621 | |
| 622 | libertas_prepare_and_send_command(priv, |
| 623 | cmd_802_11_get_log, |
| 624 | 0, cmd_option_waitforrsp, 0, NULL); |
| 625 | } else { |
| 626 | |
| 627 | ret = -1; |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | out: |
| 632 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 633 | lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 634 | ret); |
| 635 | } |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 636 | |
| 637 | mutex_lock(&adapter->lock); |
| 638 | adapter->in_progress_assoc_req = NULL; |
| 639 | mutex_unlock(&adapter->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 640 | kfree(assoc_req); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 641 | |
| 642 | done: |
| 643 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | |
| 647 | /* |
| 648 | * Caller MUST hold any necessary locks |
| 649 | */ |
| 650 | struct assoc_request * wlan_get_association_request(wlan_adapter *adapter) |
| 651 | { |
| 652 | struct assoc_request * assoc_req; |
| 653 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 654 | if (!adapter->pending_assoc_req) { |
| 655 | adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request), |
| 656 | GFP_KERNEL); |
| 657 | if (!adapter->pending_assoc_req) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 658 | lbs_pr_info("Not enough memory to allocate association" |
| 659 | " request!\n"); |
| 660 | return NULL; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | /* Copy current configuration attributes to the association request, |
| 665 | * but don't overwrite any that are already set. |
| 666 | */ |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 667 | assoc_req = adapter->pending_assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 668 | if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 669 | memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid, |
| 670 | sizeof(struct WLAN_802_11_SSID)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
| 674 | assoc_req->channel = adapter->curbssparams.channel; |
| 675 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 676 | if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags)) |
| 677 | assoc_req->band = adapter->curbssparams.band; |
| 678 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 679 | if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 680 | assoc_req->mode = adapter->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 681 | |
| 682 | if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
| 683 | memcpy(&assoc_req->bssid, adapter->curbssparams.bssid, |
| 684 | ETH_ALEN); |
| 685 | } |
| 686 | |
| 687 | if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) { |
| 688 | int i; |
| 689 | for (i = 0; i < 4; i++) { |
| 690 | memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i], |
| 691 | sizeof(struct WLAN_802_11_KEY)); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) |
| 696 | assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx; |
| 697 | |
| 698 | if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
| 699 | memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key, |
| 700 | sizeof(struct WLAN_802_11_KEY)); |
| 701 | } |
| 702 | |
| 703 | if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 704 | memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key, |
| 705 | sizeof(struct WLAN_802_11_KEY)); |
| 706 | } |
| 707 | |
| 708 | if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
| 709 | memcpy(&assoc_req->secinfo, &adapter->secinfo, |
| 710 | sizeof(struct wlan_802_11_security)); |
| 711 | } |
| 712 | |
| 713 | if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
| 714 | memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie, |
| 715 | MAX_WPA_IE_LEN); |
| 716 | assoc_req->wpa_ie_len = adapter->wpa_ie_len; |
| 717 | } |
| 718 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 719 | print_assoc_req(__func__, assoc_req); |
| 720 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 721 | return assoc_req; |
| 722 | } |