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