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 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 19 | DECLARE_MAC_BUF(mac); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 20 | lbs_deb_assoc( |
| 21 | "#### Association Request: %s\n" |
| 22 | " flags: 0x%08lX\n" |
| 23 | " SSID: '%s'\n" |
| 24 | " channel: %d\n" |
| 25 | " band: %d\n" |
| 26 | " mode: %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 27 | " BSSID: %s\n" |
Dan Williams | 785e8f2 | 2007-05-25 23:51:12 -0400 | [diff] [blame] | 28 | " Encryption:%s%s%s\n" |
| 29 | " auth: %d\n", |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 30 | extra, assoc_req->flags, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 31 | escape_essid(assoc_req->ssid, assoc_req->ssid_len), |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 32 | assoc_req->channel, assoc_req->band, assoc_req->mode, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 33 | print_mac(mac, assoc_req->bssid), |
Dan Williams | 785e8f2 | 2007-05-25 23:51:12 -0400 | [diff] [blame] | 34 | assoc_req->secinfo.WPAenabled ? " WPA" : "", |
| 35 | assoc_req->secinfo.WPA2enabled ? " WPA2" : "", |
| 36 | assoc_req->secinfo.wep_enabled ? " WEP" : "", |
| 37 | assoc_req->secinfo.auth_mode); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 41 | static int assoc_helper_essid(wlan_private *priv, |
| 42 | struct assoc_request * assoc_req) |
| 43 | { |
| 44 | wlan_adapter *adapter = priv->adapter; |
| 45 | int ret = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 46 | struct bss_descriptor * bss; |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 47 | int channel = -1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 48 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 49 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 50 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 51 | /* FIXME: take channel into account when picking SSIDs if a channel |
| 52 | * is set. |
| 53 | */ |
| 54 | |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 55 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
| 56 | channel = assoc_req->channel; |
| 57 | |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 58 | lbs_deb_assoc("New SSID requested: '%s'\n", |
| 59 | escape_essid(assoc_req->ssid, assoc_req->ssid_len)); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 60 | if (assoc_req->mode == IW_MODE_INFRA) { |
Holger Schurig | 6e22a85 | 2007-08-02 13:05:32 -0400 | [diff] [blame] | 61 | libertas_send_specific_ssid_scan(priv, assoc_req->ssid, |
| 62 | assoc_req->ssid_len, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 63 | |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 64 | bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 65 | assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 66 | if (bss != NULL) { |
| 67 | lbs_deb_assoc("SSID found in scan list, associating\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 68 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
| 69 | ret = wlan_associate(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 70 | } else { |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 71 | lbs_deb_assoc("SSID not found; cannot associate\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 72 | } |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 73 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 74 | /* Scan for the network, do not save previous results. Stale |
| 75 | * scan data will cause us to join a non-existant adhoc network |
| 76 | */ |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 77 | libertas_send_specific_ssid_scan(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 78 | assoc_req->ssid_len, 1); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 79 | |
| 80 | /* Search for the requested SSID in the scan table */ |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 81 | bss = libertas_find_ssid_in_list(adapter, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 82 | assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 83 | if (bss != NULL) { |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 84 | lbs_deb_assoc("SSID found, will join\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 85 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
| 86 | libertas_join_adhoc_network(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 87 | } else { |
| 88 | /* else send START command */ |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 89 | lbs_deb_assoc("SSID not found, creating adhoc network\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 90 | memcpy(&assoc_req->bss.ssid, &assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 91 | IW_ESSID_MAX_SIZE); |
| 92 | assoc_req->bss.ssid_len = assoc_req->ssid_len; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 93 | libertas_start_adhoc_network(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 94 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 95 | } |
| 96 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 97 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | static int assoc_helper_bssid(wlan_private *priv, |
| 103 | struct assoc_request * assoc_req) |
| 104 | { |
| 105 | wlan_adapter *adapter = priv->adapter; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 106 | int ret = 0; |
| 107 | struct bss_descriptor * bss; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 108 | DECLARE_MAC_BUF(mac); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 109 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 110 | lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %s", |
| 111 | print_mac(mac, assoc_req->bssid)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 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) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 117 | lbs_deb_assoc("ASSOC: WAP: BSSID %s not found, " |
| 118 | "cannot associate.\n", print_mac(mac, assoc_req->bssid)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 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) |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 178 | libertas_ps_wakeup(priv, CMD_OPTION_WAITFORRSP); |
| 179 | adapter->psmode = WLAN802_11POWERMODECAM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 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, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 184 | CMD_802_11_SNMP_MIB, |
| 185 | 0, CMD_OPTION_WAITFORRSP, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 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 */ |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 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); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 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 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 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); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 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, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 281 | CMD_802_11_SET_WEP, |
| 282 | CMD_ACT_ADD, |
| 283 | CMD_OPTION_WAITFORRSP, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 284 | 0, assoc_req); |
| 285 | } else { |
| 286 | ret = libertas_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 287 | CMD_802_11_SET_WEP, |
| 288 | CMD_ACT_REMOVE, |
| 289 | CMD_OPTION_WAITFORRSP, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 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) |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 298 | adapter->currentpacketfilter |= CMD_ACT_MAC_WEP_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 299 | else |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 300 | adapter->currentpacketfilter &= ~CMD_ACT_MAC_WEP_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 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], |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 310 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 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, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 345 | CMD_802_11_ENABLE_RSN, |
| 346 | CMD_ACT_GET, |
| 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, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 362 | CMD_802_11_ENABLE_RSN, |
| 363 | CMD_ACT_SET, |
| 364 | CMD_OPTION_WAITFORRSP, |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 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; |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame^] | 377 | unsigned int flags = assoc_req->flags; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 378 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 379 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 380 | |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame^] | 381 | /* Work around older firmware bug where WPA unicast and multicast |
| 382 | * keys must be set independently. Seen in SDIO parts with firmware |
| 383 | * version 5.0.11p0. |
| 384 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 385 | |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame^] | 386 | if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 387 | clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags); |
| 388 | ret = libertas_prepare_and_send_command(priv, |
| 389 | CMD_802_11_KEY_MATERIAL, |
| 390 | CMD_ACT_SET, |
| 391 | CMD_OPTION_WAITFORRSP, |
| 392 | 0, assoc_req); |
| 393 | assoc_req->flags = flags; |
| 394 | } |
| 395 | |
| 396 | if (ret) |
| 397 | goto out; |
| 398 | |
| 399 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
| 400 | clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags); |
| 401 | |
| 402 | ret = libertas_prepare_and_send_command(priv, |
| 403 | CMD_802_11_KEY_MATERIAL, |
| 404 | CMD_ACT_SET, |
| 405 | CMD_OPTION_WAITFORRSP, |
| 406 | 0, assoc_req); |
| 407 | assoc_req->flags = flags; |
| 408 | } |
| 409 | |
| 410 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 411 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 412 | return ret; |
| 413 | } |
| 414 | |
| 415 | |
| 416 | static int assoc_helper_wpa_ie(wlan_private *priv, |
| 417 | struct assoc_request * assoc_req) |
| 418 | { |
| 419 | wlan_adapter *adapter = priv->adapter; |
| 420 | int ret = 0; |
| 421 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 422 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 423 | |
| 424 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { |
| 425 | memcpy(&adapter->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len); |
| 426 | adapter->wpa_ie_len = assoc_req->wpa_ie_len; |
| 427 | } else { |
| 428 | memset(&adapter->wpa_ie, 0, MAX_WPA_IE_LEN); |
| 429 | adapter->wpa_ie_len = 0; |
| 430 | } |
| 431 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 432 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 433 | return ret; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | static int should_deauth_infrastructure(wlan_adapter *adapter, |
| 438 | struct assoc_request * assoc_req) |
| 439 | { |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 440 | if (adapter->connect_status != LIBERTAS_CONNECTED) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 441 | return 0; |
| 442 | |
| 443 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 444 | lbs_deb_assoc("Deauthenticating due to new SSID in " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 445 | " configuration request.\n"); |
| 446 | return 1; |
| 447 | } |
| 448 | |
| 449 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 450 | if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 451 | lbs_deb_assoc("Deauthenticating due to updated security " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 452 | "info in configuration request.\n"); |
| 453 | return 1; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 458 | lbs_deb_assoc("Deauthenticating due to new BSSID in " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 459 | " configuration request.\n"); |
| 460 | return 1; |
| 461 | } |
| 462 | |
Luis Carlos Cobo Rus | fff47f1 | 2007-05-30 12:16:13 -0400 | [diff] [blame] | 463 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
| 464 | lbs_deb_assoc("Deauthenticating due to channel switch.\n"); |
| 465 | return 1; |
| 466 | } |
| 467 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 468 | /* FIXME: deal with 'auto' mode somehow */ |
| 469 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 470 | if (assoc_req->mode != IW_MODE_INFRA) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 471 | return 1; |
| 472 | } |
| 473 | |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | |
| 478 | static int should_stop_adhoc(wlan_adapter *adapter, |
| 479 | struct assoc_request * assoc_req) |
| 480 | { |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 481 | if (adapter->connect_status != LIBERTAS_CONNECTED) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 482 | return 0; |
| 483 | |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 484 | if (libertas_ssid_cmp(adapter->curbssparams.ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 485 | adapter->curbssparams.ssid_len, |
| 486 | assoc_req->ssid, assoc_req->ssid_len) != 0) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 487 | return 1; |
| 488 | |
| 489 | /* FIXME: deal with 'auto' mode somehow */ |
| 490 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 491 | if (assoc_req->mode != IW_MODE_ADHOC) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 492 | return 1; |
| 493 | } |
| 494 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 495 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
| 496 | if (assoc_req->channel != adapter->curbssparams.channel) |
| 497 | return 1; |
| 498 | } |
| 499 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | |
Holger Schurig | eb3ce63 | 2007-05-24 23:41:15 -0400 | [diff] [blame] | 504 | void libertas_association_worker(struct work_struct *work) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 505 | { |
| 506 | wlan_private *priv = container_of(work, wlan_private, assoc_work.work); |
| 507 | wlan_adapter *adapter = priv->adapter; |
| 508 | struct assoc_request * assoc_req = NULL; |
| 509 | int ret = 0; |
| 510 | int find_any_ssid = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 511 | DECLARE_MAC_BUF(mac); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 512 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 513 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 514 | |
| 515 | mutex_lock(&adapter->lock); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 516 | assoc_req = adapter->pending_assoc_req; |
| 517 | adapter->pending_assoc_req = NULL; |
| 518 | adapter->in_progress_assoc_req = assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 519 | mutex_unlock(&adapter->lock); |
| 520 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 521 | if (!assoc_req) |
| 522 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 523 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 524 | print_assoc_req(__func__, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 525 | |
| 526 | /* If 'any' SSID was specified, find an SSID to associate with */ |
| 527 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags) |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 528 | && !assoc_req->ssid_len) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 529 | find_any_ssid = 1; |
| 530 | |
| 531 | /* But don't use 'any' SSID if there's a valid locked BSSID to use */ |
| 532 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 533 | if (compare_ether_addr(assoc_req->bssid, bssid_any) |
| 534 | && compare_ether_addr(assoc_req->bssid, bssid_off)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 535 | find_any_ssid = 0; |
| 536 | } |
| 537 | |
| 538 | if (find_any_ssid) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 539 | u8 new_mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 540 | |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 541 | ret = libertas_find_best_network_ssid(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 542 | &assoc_req->ssid_len, assoc_req->mode, &new_mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 543 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 544 | lbs_deb_assoc("Could not find best network\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 545 | ret = -ENETUNREACH; |
| 546 | goto out; |
| 547 | } |
| 548 | |
| 549 | /* Ensure we switch to the mode of the AP */ |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 550 | if (assoc_req->mode == IW_MODE_AUTO) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 551 | set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); |
| 552 | assoc_req->mode = new_mode; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | * Check if the attributes being changing require deauthentication |
| 558 | * from the currently associated infrastructure access point. |
| 559 | */ |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 560 | if (adapter->mode == IW_MODE_INFRA) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 561 | if (should_deauth_infrastructure(adapter, assoc_req)) { |
| 562 | ret = libertas_send_deauthentication(priv); |
| 563 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 564 | lbs_deb_assoc("Deauthentication due to new " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 565 | "configuration request failed: %d\n", |
| 566 | ret); |
| 567 | } |
| 568 | } |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 569 | } else if (adapter->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 570 | if (should_stop_adhoc(adapter, assoc_req)) { |
| 571 | ret = libertas_stop_adhoc_network(priv); |
| 572 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 573 | lbs_deb_assoc("Teardown of AdHoc network due to " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 574 | "new configuration request failed: %d\n", |
| 575 | ret); |
| 576 | } |
| 577 | |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | /* Send the various configuration bits to the firmware */ |
| 582 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
| 583 | ret = assoc_helper_mode(priv, assoc_req); |
| 584 | if (ret) { |
Dan Williams | 2950cd26 | 2007-08-02 10:47:17 -0400 | [diff] [blame] | 585 | lbs_deb_assoc("ASSOC(:%d) mode: ret = %d\n", |
| 586 | __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 587 | goto out; |
| 588 | } |
| 589 | } |
| 590 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 591 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
| 592 | ret = assoc_helper_channel(priv, assoc_req); |
| 593 | if (ret) { |
| 594 | lbs_deb_assoc("ASSOC(:%d) channel: ret = %d\n", |
| 595 | __LINE__, ret); |
| 596 | goto out; |
| 597 | } |
| 598 | } |
| 599 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 600 | if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags) |
| 601 | || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) { |
| 602 | ret = assoc_helper_wep_keys(priv, assoc_req); |
| 603 | if (ret) { |
Dan Williams | 2950cd26 | 2007-08-02 10:47:17 -0400 | [diff] [blame] | 604 | lbs_deb_assoc("ASSOC(:%d) wep_keys: ret = %d\n", |
| 605 | __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 606 | goto out; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
| 611 | ret = assoc_helper_secinfo(priv, assoc_req); |
| 612 | if (ret) { |
Dan Williams | 2950cd26 | 2007-08-02 10:47:17 -0400 | [diff] [blame] | 613 | lbs_deb_assoc("ASSOC(:%d) secinfo: ret = %d\n", |
| 614 | __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 615 | goto out; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
| 620 | ret = assoc_helper_wpa_ie(priv, assoc_req); |
| 621 | if (ret) { |
Dan Williams | 2950cd26 | 2007-08-02 10:47:17 -0400 | [diff] [blame] | 622 | lbs_deb_assoc("ASSOC(:%d) wpa_ie: ret = %d\n", |
| 623 | __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 624 | goto out; |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags) |
| 629 | || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 630 | ret = assoc_helper_wpa_keys(priv, assoc_req); |
| 631 | if (ret) { |
Dan Williams | 2950cd26 | 2007-08-02 10:47:17 -0400 | [diff] [blame] | 632 | lbs_deb_assoc("ASSOC(:%d) wpa_keys: ret = %d\n", |
| 633 | __LINE__, ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 634 | goto out; |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | /* SSID/BSSID should be the _last_ config option set, because they |
| 639 | * trigger the association attempt. |
| 640 | */ |
| 641 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags) |
| 642 | || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 643 | int success = 1; |
| 644 | |
| 645 | ret = assoc_helper_associate(priv, assoc_req); |
| 646 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 647 | lbs_deb_assoc("ASSOC: association attempt unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 648 | ret); |
| 649 | success = 0; |
| 650 | } |
| 651 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 652 | if (adapter->connect_status != LIBERTAS_CONNECTED) { |
Dan Williams | 81173e3 | 2007-08-02 13:19:56 -0400 | [diff] [blame] | 653 | lbs_deb_assoc("ASSOC: association attempt unsuccessful, " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 654 | "not connected.\n"); |
| 655 | success = 0; |
| 656 | } |
| 657 | |
| 658 | if (success) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 659 | lbs_deb_assoc("ASSOC: association attempt successful. " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 660 | "Associated to '%s' (%s)\n", |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 661 | escape_essid(adapter->curbssparams.ssid, |
| 662 | adapter->curbssparams.ssid_len), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 663 | print_mac(mac, adapter->curbssparams.bssid)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 664 | libertas_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 665 | CMD_802_11_RSSI, |
| 666 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 667 | |
| 668 | libertas_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 669 | CMD_802_11_GET_LOG, |
| 670 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 671 | } else { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 672 | ret = -1; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | out: |
| 677 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 678 | lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 679 | ret); |
| 680 | } |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 681 | |
| 682 | mutex_lock(&adapter->lock); |
| 683 | adapter->in_progress_assoc_req = NULL; |
| 684 | mutex_unlock(&adapter->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 685 | kfree(assoc_req); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 686 | |
| 687 | done: |
| 688 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | |
| 692 | /* |
| 693 | * Caller MUST hold any necessary locks |
| 694 | */ |
| 695 | struct assoc_request * wlan_get_association_request(wlan_adapter *adapter) |
| 696 | { |
| 697 | struct assoc_request * assoc_req; |
| 698 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 699 | if (!adapter->pending_assoc_req) { |
| 700 | adapter->pending_assoc_req = kzalloc(sizeof(struct assoc_request), |
| 701 | GFP_KERNEL); |
| 702 | if (!adapter->pending_assoc_req) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 703 | lbs_pr_info("Not enough memory to allocate association" |
| 704 | " request!\n"); |
| 705 | return NULL; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | /* Copy current configuration attributes to the association request, |
| 710 | * but don't overwrite any that are already set. |
| 711 | */ |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 712 | assoc_req = adapter->pending_assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 713 | if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 714 | memcpy(&assoc_req->ssid, &adapter->curbssparams.ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 715 | IW_ESSID_MAX_SIZE); |
| 716 | assoc_req->ssid_len = adapter->curbssparams.ssid_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
| 720 | assoc_req->channel = adapter->curbssparams.channel; |
| 721 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 722 | if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags)) |
| 723 | assoc_req->band = adapter->curbssparams.band; |
| 724 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 725 | if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 726 | assoc_req->mode = adapter->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 727 | |
| 728 | if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
| 729 | memcpy(&assoc_req->bssid, adapter->curbssparams.bssid, |
| 730 | ETH_ALEN); |
| 731 | } |
| 732 | |
| 733 | if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) { |
| 734 | int i; |
| 735 | for (i = 0; i < 4; i++) { |
| 736 | memcpy(&assoc_req->wep_keys[i], &adapter->wep_keys[i], |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 737 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
| 741 | if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) |
| 742 | assoc_req->wep_tx_keyidx = adapter->wep_tx_keyidx; |
| 743 | |
| 744 | if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
| 745 | memcpy(&assoc_req->wpa_mcast_key, &adapter->wpa_mcast_key, |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 746 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 750 | memcpy(&assoc_req->wpa_unicast_key, &adapter->wpa_unicast_key, |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 751 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
| 755 | memcpy(&assoc_req->secinfo, &adapter->secinfo, |
| 756 | sizeof(struct wlan_802_11_security)); |
| 757 | } |
| 758 | |
| 759 | if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
| 760 | memcpy(&assoc_req->wpa_ie, &adapter->wpa_ie, |
| 761 | MAX_WPA_IE_LEN); |
| 762 | assoc_req->wpa_ie_len = adapter->wpa_ie_len; |
| 763 | } |
| 764 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 765 | print_assoc_req(__func__, assoc_req); |
| 766 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 767 | return assoc_req; |
| 768 | } |