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