Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /* Copyright (C) 2006, Red Hat, Inc. */ |
| 2 | |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 3 | #include <linux/types.h> |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 4 | #include <linux/etherdevice.h> |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame^] | 5 | #include <linux/ieee80211.h> |
| 6 | #include <linux/if_arp.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 7 | #include <net/lib80211.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 8 | |
| 9 | #include "assoc.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 10 | #include "decl.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 11 | #include "host.h" |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 12 | #include "scan.h" |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 13 | #include "cmd.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 14 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 15 | static int lbs_adhoc_post(struct lbs_private *priv, struct cmd_header *resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 16 | |
Ihar Hrachyshka | 5a6e043 | 2008-01-25 14:15:00 +0100 | [diff] [blame] | 17 | static const u8 bssid_any[ETH_ALEN] __attribute__ ((aligned (2))) = |
| 18 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
| 19 | static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) = |
| 20 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 21 | |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 22 | /* The firmware needs certain bits masked out of the beacon-derviced capability |
| 23 | * field when associating/joining to BSSs. |
| 24 | */ |
| 25 | #define CAPINFO_MASK (~(0xda00)) |
| 26 | |
| 27 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 28 | /** |
| 29 | * @brief This function finds common rates between rates and card rates. |
| 30 | * |
| 31 | * It will fill common rates in rates as output if found. |
| 32 | * |
| 33 | * NOTE: Setting the MSB of the basic rates need to be taken |
| 34 | * care, either before or after calling this function |
| 35 | * |
| 36 | * @param priv A pointer to struct lbs_private structure |
| 37 | * @param rates the buffer which keeps input and output |
| 38 | * @param rates_size the size of rate1 buffer; new size of buffer on return |
| 39 | * |
| 40 | * @return 0 on success, or -1 on error |
| 41 | */ |
| 42 | static int get_common_rates(struct lbs_private *priv, |
| 43 | u8 *rates, |
| 44 | u16 *rates_size) |
| 45 | { |
| 46 | u8 *card_rates = lbs_bg_rates; |
| 47 | size_t num_card_rates = sizeof(lbs_bg_rates); |
| 48 | int ret = 0, i, j; |
| 49 | u8 tmp[30]; |
| 50 | size_t tmp_size = 0; |
| 51 | |
| 52 | /* For each rate in card_rates that exists in rate1, copy to tmp */ |
| 53 | for (i = 0; card_rates[i] && (i < num_card_rates); i++) { |
| 54 | for (j = 0; rates[j] && (j < *rates_size); j++) { |
| 55 | if (rates[j] == card_rates[i]) |
| 56 | tmp[tmp_size++] = card_rates[i]; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size); |
| 61 | lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates); |
| 62 | lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size); |
| 63 | lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); |
| 64 | |
| 65 | if (!priv->enablehwauto) { |
| 66 | for (i = 0; i < tmp_size; i++) { |
| 67 | if (tmp[i] == priv->cur_rate) |
| 68 | goto done; |
| 69 | } |
| 70 | lbs_pr_alert("Previously set fixed data rate %#x isn't " |
| 71 | "compatible with the network.\n", priv->cur_rate); |
| 72 | ret = -1; |
| 73 | goto done; |
| 74 | } |
| 75 | ret = 0; |
| 76 | |
| 77 | done: |
| 78 | memset(rates, 0, *rates_size); |
| 79 | *rates_size = min_t(int, tmp_size, *rates_size); |
| 80 | memcpy(rates, tmp, *rates_size); |
| 81 | return ret; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /** |
| 86 | * @brief Sets the MSB on basic rates as the firmware requires |
| 87 | * |
| 88 | * Scan through an array and set the MSB for basic data rates. |
| 89 | * |
| 90 | * @param rates buffer of data rates |
| 91 | * @param len size of buffer |
| 92 | */ |
| 93 | static void lbs_set_basic_rate_flags(u8 *rates, size_t len) |
| 94 | { |
| 95 | int i; |
| 96 | |
| 97 | for (i = 0; i < len; i++) { |
| 98 | if (rates[i] == 0x02 || rates[i] == 0x04 || |
| 99 | rates[i] == 0x0b || rates[i] == 0x16) |
| 100 | rates[i] |= 0x80; |
| 101 | } |
| 102 | } |
| 103 | |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * @brief Associate to a specific BSS discovered in a scan |
| 107 | * |
| 108 | * @param priv A pointer to struct lbs_private structure |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 109 | * @param assoc_req The association request describing the BSS to associate with |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 110 | * |
| 111 | * @return 0-success, otherwise fail |
| 112 | */ |
| 113 | static int lbs_associate(struct lbs_private *priv, |
| 114 | struct assoc_request *assoc_req) |
| 115 | { |
| 116 | int ret; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 117 | u8 preamble = RADIO_PREAMBLE_LONG; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 118 | |
| 119 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 120 | |
| 121 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE, |
| 122 | 0, CMD_OPTION_WAITFORRSP, |
| 123 | 0, assoc_req->bss.bssid); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 124 | if (ret) |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 125 | goto out; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 126 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 127 | /* Use short preamble only when both the BSS and firmware support it */ |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 128 | if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && |
| 129 | (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 130 | preamble = RADIO_PREAMBLE_SHORT; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 131 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 132 | ret = lbs_set_radio(priv, preamble, 1); |
| 133 | if (ret) |
| 134 | goto out; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 135 | |
| 136 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE, |
| 137 | 0, CMD_OPTION_WAITFORRSP, 0, assoc_req); |
| 138 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 139 | out: |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 140 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * @brief Join an adhoc network found in a previous scan |
| 146 | * |
| 147 | * @param priv A pointer to struct lbs_private structure |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 148 | * @param assoc_req The association request describing the BSS to join |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 149 | * |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 150 | * @return 0 on success, error on failure |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 151 | */ |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 152 | static int lbs_adhoc_join(struct lbs_private *priv, |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 153 | struct assoc_request *assoc_req) |
| 154 | { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 155 | struct cmd_ds_802_11_ad_hoc_join cmd; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 156 | struct bss_descriptor *bss = &assoc_req->bss; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 157 | u8 preamble = RADIO_PREAMBLE_LONG; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 158 | DECLARE_SSID_BUF(ssid); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 159 | u16 ratesize = 0; |
| 160 | int ret = 0; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 161 | |
| 162 | lbs_deb_enter(LBS_DEB_ASSOC); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 163 | |
| 164 | lbs_deb_join("current SSID '%s', ssid length %u\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 165 | print_ssid(ssid, priv->curbssparams.ssid, |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 166 | priv->curbssparams.ssid_len), |
| 167 | priv->curbssparams.ssid_len); |
| 168 | lbs_deb_join("requested ssid '%s', ssid length %u\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 169 | print_ssid(ssid, bss->ssid, bss->ssid_len), |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 170 | bss->ssid_len); |
| 171 | |
| 172 | /* check if the requested SSID is already joined */ |
| 173 | if (priv->curbssparams.ssid_len && |
| 174 | !lbs_ssid_cmp(priv->curbssparams.ssid, |
| 175 | priv->curbssparams.ssid_len, |
| 176 | bss->ssid, bss->ssid_len) && |
| 177 | (priv->mode == IW_MODE_ADHOC) && |
| 178 | (priv->connect_status == LBS_CONNECTED)) { |
| 179 | union iwreq_data wrqu; |
| 180 | |
| 181 | lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as " |
| 182 | "current, not attempting to re-join"); |
| 183 | |
| 184 | /* Send the re-association event though, because the association |
| 185 | * request really was successful, even if just a null-op. |
| 186 | */ |
| 187 | memset(&wrqu, 0, sizeof(wrqu)); |
| 188 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, |
| 189 | ETH_ALEN); |
| 190 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 191 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
| 192 | goto out; |
| 193 | } |
| 194 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 195 | /* Use short preamble only when both the BSS and firmware support it */ |
| 196 | if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && |
| 197 | (bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) { |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 198 | lbs_deb_join("AdhocJoin: Short preamble\n"); |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 199 | preamble = RADIO_PREAMBLE_SHORT; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 202 | ret = lbs_set_radio(priv, preamble, 1); |
| 203 | if (ret) |
| 204 | goto out; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 205 | |
| 206 | lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel); |
| 207 | lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band); |
| 208 | |
| 209 | priv->adhoccreate = 0; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 210 | priv->curbssparams.channel = bss->channel; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 211 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 212 | /* Build the join command */ |
| 213 | memset(&cmd, 0, sizeof(cmd)); |
| 214 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 215 | |
| 216 | cmd.bss.type = CMD_BSS_TYPE_IBSS; |
| 217 | cmd.bss.beaconperiod = cpu_to_le16(bss->beaconperiod); |
| 218 | |
| 219 | memcpy(&cmd.bss.bssid, &bss->bssid, ETH_ALEN); |
| 220 | memcpy(&cmd.bss.ssid, &bss->ssid, bss->ssid_len); |
| 221 | |
| 222 | memcpy(&cmd.bss.phyparamset, &bss->phyparamset, |
| 223 | sizeof(union ieeetypes_phyparamset)); |
| 224 | |
| 225 | memcpy(&cmd.bss.ssparamset, &bss->ssparamset, |
| 226 | sizeof(union IEEEtypes_ssparamset)); |
| 227 | |
| 228 | cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK); |
| 229 | lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n", |
| 230 | bss->capability, CAPINFO_MASK); |
| 231 | |
| 232 | /* information on BSSID descriptor passed to FW */ |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 233 | lbs_deb_join("ADHOC_J_CMD: BSSID = %pM, SSID = '%s'\n", |
| 234 | cmd.bss.bssid, cmd.bss.ssid); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 235 | |
| 236 | /* Only v8 and below support setting these */ |
| 237 | if (priv->fwrelease < 0x09000000) { |
| 238 | /* failtimeout */ |
| 239 | cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT); |
| 240 | /* probedelay */ |
| 241 | cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); |
| 242 | } |
| 243 | |
| 244 | /* Copy Data rates from the rates recorded in scan response */ |
| 245 | memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates)); |
| 246 | ratesize = min_t(u16, sizeof(cmd.bss.rates), MAX_RATES); |
| 247 | memcpy(cmd.bss.rates, bss->rates, ratesize); |
| 248 | if (get_common_rates(priv, cmd.bss.rates, &ratesize)) { |
| 249 | lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n"); |
| 250 | ret = -1; |
| 251 | goto out; |
| 252 | } |
| 253 | |
| 254 | /* Copy the ad-hoc creation rates into Current BSS state structure */ |
| 255 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); |
| 256 | memcpy(&priv->curbssparams.rates, cmd.bss.rates, ratesize); |
| 257 | |
| 258 | /* Set MSB on basic rates as the firmware requires, but _after_ |
| 259 | * copying to current bss rates. |
| 260 | */ |
| 261 | lbs_set_basic_rate_flags(cmd.bss.rates, ratesize); |
| 262 | |
| 263 | cmd.bss.ssparamset.ibssparamset.atimwindow = cpu_to_le16(bss->atimwindow); |
| 264 | |
| 265 | if (assoc_req->secinfo.wep_enabled) { |
| 266 | u16 tmp = le16_to_cpu(cmd.bss.capability); |
| 267 | tmp |= WLAN_CAPABILITY_PRIVACY; |
| 268 | cmd.bss.capability = cpu_to_le16(tmp); |
| 269 | } |
| 270 | |
| 271 | if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { |
| 272 | __le32 local_ps_mode = cpu_to_le32(LBS802_11POWERMODECAM); |
| 273 | |
| 274 | /* wake up first */ |
| 275 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
| 276 | CMD_ACT_SET, 0, 0, |
| 277 | &local_ps_mode); |
| 278 | if (ret) { |
| 279 | ret = -1; |
| 280 | goto out; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { |
| 285 | ret = -1; |
| 286 | goto out; |
| 287 | } |
| 288 | |
| 289 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd); |
| 290 | if (ret == 0) |
| 291 | ret = lbs_adhoc_post(priv, (struct cmd_header *) &cmd); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 292 | |
| 293 | out: |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 294 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 295 | return ret; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * @brief Start an Adhoc Network |
| 300 | * |
| 301 | * @param priv A pointer to struct lbs_private structure |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 302 | * @param assoc_req The association request describing the BSS to start |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 303 | * |
| 304 | * @return 0 on success, error on failure |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 305 | */ |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 306 | static int lbs_adhoc_start(struct lbs_private *priv, |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 307 | struct assoc_request *assoc_req) |
| 308 | { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 309 | struct cmd_ds_802_11_ad_hoc_start cmd; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 310 | u8 preamble = RADIO_PREAMBLE_LONG; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 311 | size_t ratesize = 0; |
| 312 | u16 tmpcap = 0; |
| 313 | int ret = 0; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 314 | DECLARE_SSID_BUF(ssid); |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 315 | |
| 316 | lbs_deb_enter(LBS_DEB_ASSOC); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 317 | |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 318 | if (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 319 | lbs_deb_join("ADHOC_START: Will use short preamble\n"); |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 320 | preamble = RADIO_PREAMBLE_SHORT; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 323 | ret = lbs_set_radio(priv, preamble, 1); |
| 324 | if (ret) |
| 325 | goto out; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 326 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 327 | /* Build the start command */ |
| 328 | memset(&cmd, 0, sizeof(cmd)); |
| 329 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 330 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 331 | memcpy(cmd.ssid, assoc_req->ssid, assoc_req->ssid_len); |
| 332 | |
| 333 | lbs_deb_join("ADHOC_START: SSID '%s', ssid length %u\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 334 | print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len), |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 335 | assoc_req->ssid_len); |
| 336 | |
| 337 | cmd.bsstype = CMD_BSS_TYPE_IBSS; |
| 338 | |
| 339 | if (priv->beacon_period == 0) |
| 340 | priv->beacon_period = MRVDRV_BEACON_INTERVAL; |
| 341 | cmd.beaconperiod = cpu_to_le16(priv->beacon_period); |
| 342 | |
| 343 | WARN_ON(!assoc_req->channel); |
| 344 | |
| 345 | /* set Physical parameter set */ |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame^] | 346 | cmd.phyparamset.dsparamset.elementid = WLAN_EID_DS_PARAMS; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 347 | cmd.phyparamset.dsparamset.len = 1; |
| 348 | cmd.phyparamset.dsparamset.currentchan = assoc_req->channel; |
| 349 | |
| 350 | /* set IBSS parameter set */ |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame^] | 351 | cmd.ssparamset.ibssparamset.elementid = WLAN_EID_IBSS_PARAMS; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 352 | cmd.ssparamset.ibssparamset.len = 2; |
| 353 | cmd.ssparamset.ibssparamset.atimwindow = 0; |
| 354 | |
| 355 | /* set capability info */ |
| 356 | tmpcap = WLAN_CAPABILITY_IBSS; |
| 357 | if (assoc_req->secinfo.wep_enabled) { |
| 358 | lbs_deb_join("ADHOC_START: WEP enabled, setting privacy on\n"); |
| 359 | tmpcap |= WLAN_CAPABILITY_PRIVACY; |
| 360 | } else |
| 361 | lbs_deb_join("ADHOC_START: WEP disabled, setting privacy off\n"); |
| 362 | |
| 363 | cmd.capability = cpu_to_le16(tmpcap); |
| 364 | |
| 365 | /* Only v8 and below support setting probe delay */ |
| 366 | if (priv->fwrelease < 0x09000000) |
| 367 | cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); |
| 368 | |
| 369 | ratesize = min(sizeof(cmd.rates), sizeof(lbs_bg_rates)); |
| 370 | memcpy(cmd.rates, lbs_bg_rates, ratesize); |
| 371 | |
| 372 | /* Copy the ad-hoc creating rates into Current BSS state structure */ |
| 373 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); |
| 374 | memcpy(&priv->curbssparams.rates, &cmd.rates, ratesize); |
| 375 | |
| 376 | /* Set MSB on basic rates as the firmware requires, but _after_ |
| 377 | * copying to current bss rates. |
| 378 | */ |
| 379 | lbs_set_basic_rate_flags(cmd.rates, ratesize); |
| 380 | |
| 381 | lbs_deb_join("ADHOC_START: rates=%02x %02x %02x %02x\n", |
| 382 | cmd.rates[0], cmd.rates[1], cmd.rates[2], cmd.rates[3]); |
| 383 | |
| 384 | if (lbs_create_dnld_countryinfo_11d(priv)) { |
| 385 | lbs_deb_join("ADHOC_START: dnld_countryinfo_11d failed\n"); |
| 386 | ret = -1; |
| 387 | goto out; |
| 388 | } |
| 389 | |
| 390 | lbs_deb_join("ADHOC_START: Starting Ad-Hoc BSS on channel %d, band %d\n", |
| 391 | assoc_req->channel, assoc_req->band); |
| 392 | |
| 393 | priv->adhoccreate = 1; |
| 394 | priv->mode = IW_MODE_ADHOC; |
| 395 | |
| 396 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd); |
| 397 | if (ret == 0) |
| 398 | ret = lbs_adhoc_post(priv, (struct cmd_header *) &cmd); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 399 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 400 | out: |
| 401 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 402 | return ret; |
| 403 | } |
| 404 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 405 | /** |
| 406 | * @brief Stop and Ad-Hoc network and exit Ad-Hoc mode |
| 407 | * |
| 408 | * @param priv A pointer to struct lbs_private structure |
| 409 | * @return 0 on success, or an error |
| 410 | */ |
| 411 | int lbs_adhoc_stop(struct lbs_private *priv) |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 412 | { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 413 | struct cmd_ds_802_11_ad_hoc_stop cmd; |
| 414 | int ret; |
| 415 | |
| 416 | lbs_deb_enter(LBS_DEB_JOIN); |
| 417 | |
| 418 | memset(&cmd, 0, sizeof (cmd)); |
| 419 | cmd.hdr.size = cpu_to_le16 (sizeof (cmd)); |
| 420 | |
| 421 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd); |
| 422 | |
| 423 | /* Clean up everything even if there was an error */ |
| 424 | lbs_mac_event_disconnected(priv); |
| 425 | |
| 426 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 427 | return ret; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 428 | } |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 429 | |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 430 | static inline int match_bss_no_security(struct lbs_802_11_security *secinfo, |
| 431 | struct bss_descriptor *match_bss) |
| 432 | { |
| 433 | if (!secinfo->wep_enabled && !secinfo->WPAenabled |
| 434 | && !secinfo->WPA2enabled |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame^] | 435 | && match_bss->wpa_ie[0] != WLAN_EID_GENERIC |
| 436 | && match_bss->rsn_ie[0] != WLAN_EID_RSN |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 437 | && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY)) |
| 438 | return 1; |
| 439 | else |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static inline int match_bss_static_wep(struct lbs_802_11_security *secinfo, |
| 444 | struct bss_descriptor *match_bss) |
| 445 | { |
| 446 | if (secinfo->wep_enabled && !secinfo->WPAenabled |
| 447 | && !secinfo->WPA2enabled |
| 448 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) |
| 449 | return 1; |
| 450 | else |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | static inline int match_bss_wpa(struct lbs_802_11_security *secinfo, |
| 455 | struct bss_descriptor *match_bss) |
| 456 | { |
| 457 | if (!secinfo->wep_enabled && secinfo->WPAenabled |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame^] | 458 | && (match_bss->wpa_ie[0] == WLAN_EID_GENERIC) |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 459 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G |
| 460 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */ |
| 461 | ) |
| 462 | return 1; |
| 463 | else |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo, |
| 468 | struct bss_descriptor *match_bss) |
| 469 | { |
| 470 | if (!secinfo->wep_enabled && secinfo->WPA2enabled && |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame^] | 471 | (match_bss->rsn_ie[0] == WLAN_EID_RSN) |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 472 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G |
| 473 | (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */ |
| 474 | ) |
| 475 | return 1; |
| 476 | else |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo, |
| 481 | struct bss_descriptor *match_bss) |
| 482 | { |
| 483 | if (!secinfo->wep_enabled && !secinfo->WPAenabled |
| 484 | && !secinfo->WPA2enabled |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame^] | 485 | && (match_bss->wpa_ie[0] != WLAN_EID_GENERIC) |
| 486 | && (match_bss->rsn_ie[0] != WLAN_EID_RSN) |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 487 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) |
| 488 | return 1; |
| 489 | else |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * @brief Check if a scanned network compatible with the driver settings |
| 495 | * |
| 496 | * WEP WPA WPA2 ad-hoc encrypt Network |
| 497 | * enabled enabled enabled AES mode privacy WPA WPA2 Compatible |
| 498 | * 0 0 0 0 NONE 0 0 0 yes No security |
| 499 | * 1 0 0 0 NONE 1 0 0 yes Static WEP |
| 500 | * 0 1 0 0 x 1x 1 x yes WPA |
| 501 | * 0 0 1 0 x 1x x 1 yes WPA2 |
| 502 | * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES |
| 503 | * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP |
| 504 | * |
| 505 | * |
| 506 | * @param priv A pointer to struct lbs_private |
| 507 | * @param index Index in scantable to check against current driver settings |
| 508 | * @param mode Network mode: Infrastructure or IBSS |
| 509 | * |
| 510 | * @return Index in scantable, or error code if negative |
| 511 | */ |
| 512 | static int is_network_compatible(struct lbs_private *priv, |
| 513 | struct bss_descriptor *bss, uint8_t mode) |
| 514 | { |
| 515 | int matched = 0; |
| 516 | |
| 517 | lbs_deb_enter(LBS_DEB_SCAN); |
| 518 | |
| 519 | if (bss->mode != mode) |
| 520 | goto done; |
| 521 | |
| 522 | matched = match_bss_no_security(&priv->secinfo, bss); |
| 523 | if (matched) |
| 524 | goto done; |
| 525 | matched = match_bss_static_wep(&priv->secinfo, bss); |
| 526 | if (matched) |
| 527 | goto done; |
| 528 | matched = match_bss_wpa(&priv->secinfo, bss); |
| 529 | if (matched) { |
| 530 | lbs_deb_scan("is_network_compatible() WPA: wpa_ie 0x%x " |
| 531 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s " |
| 532 | "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0], |
| 533 | priv->secinfo.wep_enabled ? "e" : "d", |
| 534 | priv->secinfo.WPAenabled ? "e" : "d", |
| 535 | priv->secinfo.WPA2enabled ? "e" : "d", |
| 536 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
| 537 | goto done; |
| 538 | } |
| 539 | matched = match_bss_wpa2(&priv->secinfo, bss); |
| 540 | if (matched) { |
| 541 | lbs_deb_scan("is_network_compatible() WPA2: wpa_ie 0x%x " |
| 542 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s " |
| 543 | "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0], |
| 544 | priv->secinfo.wep_enabled ? "e" : "d", |
| 545 | priv->secinfo.WPAenabled ? "e" : "d", |
| 546 | priv->secinfo.WPA2enabled ? "e" : "d", |
| 547 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
| 548 | goto done; |
| 549 | } |
| 550 | matched = match_bss_dynamic_wep(&priv->secinfo, bss); |
| 551 | if (matched) { |
| 552 | lbs_deb_scan("is_network_compatible() dynamic WEP: " |
| 553 | "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n", |
| 554 | bss->wpa_ie[0], bss->rsn_ie[0], |
| 555 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
| 556 | goto done; |
| 557 | } |
| 558 | |
| 559 | /* bss security settings don't match those configured on card */ |
| 560 | lbs_deb_scan("is_network_compatible() FAILED: wpa_ie 0x%x " |
| 561 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n", |
| 562 | bss->wpa_ie[0], bss->rsn_ie[0], |
| 563 | priv->secinfo.wep_enabled ? "e" : "d", |
| 564 | priv->secinfo.WPAenabled ? "e" : "d", |
| 565 | priv->secinfo.WPA2enabled ? "e" : "d", |
| 566 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
| 567 | |
| 568 | done: |
| 569 | lbs_deb_leave_args(LBS_DEB_SCAN, "matched: %d", matched); |
| 570 | return matched; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * @brief This function finds a specific compatible BSSID in the scan list |
| 575 | * |
| 576 | * Used in association code |
| 577 | * |
| 578 | * @param priv A pointer to struct lbs_private |
| 579 | * @param bssid BSSID to find in the scan list |
| 580 | * @param mode Network mode: Infrastructure or IBSS |
| 581 | * |
| 582 | * @return index in BSSID list, or error return code (< 0) |
| 583 | */ |
| 584 | static struct bss_descriptor *lbs_find_bssid_in_list(struct lbs_private *priv, |
| 585 | uint8_t *bssid, uint8_t mode) |
| 586 | { |
| 587 | struct bss_descriptor *iter_bss; |
| 588 | struct bss_descriptor *found_bss = NULL; |
| 589 | |
| 590 | lbs_deb_enter(LBS_DEB_SCAN); |
| 591 | |
| 592 | if (!bssid) |
| 593 | goto out; |
| 594 | |
| 595 | lbs_deb_hex(LBS_DEB_SCAN, "looking for", bssid, ETH_ALEN); |
| 596 | |
| 597 | /* Look through the scan table for a compatible match. The loop will |
| 598 | * continue past a matched bssid that is not compatible in case there |
| 599 | * is an AP with multiple SSIDs assigned to the same BSSID |
| 600 | */ |
| 601 | mutex_lock(&priv->lock); |
| 602 | list_for_each_entry(iter_bss, &priv->network_list, list) { |
| 603 | if (compare_ether_addr(iter_bss->bssid, bssid)) |
| 604 | continue; /* bssid doesn't match */ |
| 605 | switch (mode) { |
| 606 | case IW_MODE_INFRA: |
| 607 | case IW_MODE_ADHOC: |
| 608 | if (!is_network_compatible(priv, iter_bss, mode)) |
| 609 | break; |
| 610 | found_bss = iter_bss; |
| 611 | break; |
| 612 | default: |
| 613 | found_bss = iter_bss; |
| 614 | break; |
| 615 | } |
| 616 | } |
| 617 | mutex_unlock(&priv->lock); |
| 618 | |
| 619 | out: |
| 620 | lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss); |
| 621 | return found_bss; |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * @brief This function finds ssid in ssid list. |
| 626 | * |
| 627 | * Used in association code |
| 628 | * |
| 629 | * @param priv A pointer to struct lbs_private |
| 630 | * @param ssid SSID to find in the list |
| 631 | * @param bssid BSSID to qualify the SSID selection (if provided) |
| 632 | * @param mode Network mode: Infrastructure or IBSS |
| 633 | * |
| 634 | * @return index in BSSID list |
| 635 | */ |
| 636 | static struct bss_descriptor *lbs_find_ssid_in_list(struct lbs_private *priv, |
| 637 | uint8_t *ssid, uint8_t ssid_len, |
| 638 | uint8_t *bssid, uint8_t mode, |
| 639 | int channel) |
| 640 | { |
| 641 | u32 bestrssi = 0; |
| 642 | struct bss_descriptor *iter_bss = NULL; |
| 643 | struct bss_descriptor *found_bss = NULL; |
| 644 | struct bss_descriptor *tmp_oldest = NULL; |
| 645 | |
| 646 | lbs_deb_enter(LBS_DEB_SCAN); |
| 647 | |
| 648 | mutex_lock(&priv->lock); |
| 649 | |
| 650 | list_for_each_entry(iter_bss, &priv->network_list, list) { |
| 651 | if (!tmp_oldest || |
| 652 | (iter_bss->last_scanned < tmp_oldest->last_scanned)) |
| 653 | tmp_oldest = iter_bss; |
| 654 | |
| 655 | if (lbs_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len, |
| 656 | ssid, ssid_len) != 0) |
| 657 | continue; /* ssid doesn't match */ |
| 658 | if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0) |
| 659 | continue; /* bssid doesn't match */ |
| 660 | if ((channel > 0) && (iter_bss->channel != channel)) |
| 661 | continue; /* channel doesn't match */ |
| 662 | |
| 663 | switch (mode) { |
| 664 | case IW_MODE_INFRA: |
| 665 | case IW_MODE_ADHOC: |
| 666 | if (!is_network_compatible(priv, iter_bss, mode)) |
| 667 | break; |
| 668 | |
| 669 | if (bssid) { |
| 670 | /* Found requested BSSID */ |
| 671 | found_bss = iter_bss; |
| 672 | goto out; |
| 673 | } |
| 674 | |
| 675 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { |
| 676 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 677 | found_bss = iter_bss; |
| 678 | } |
| 679 | break; |
| 680 | case IW_MODE_AUTO: |
| 681 | default: |
| 682 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { |
| 683 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 684 | found_bss = iter_bss; |
| 685 | } |
| 686 | break; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | out: |
| 691 | mutex_unlock(&priv->lock); |
| 692 | lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss); |
| 693 | return found_bss; |
| 694 | } |
| 695 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 696 | static int assoc_helper_essid(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 697 | struct assoc_request * assoc_req) |
| 698 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 699 | int ret = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 700 | struct bss_descriptor * bss; |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 701 | int channel = -1; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 702 | DECLARE_SSID_BUF(ssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 703 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 704 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 705 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 706 | /* FIXME: take channel into account when picking SSIDs if a channel |
| 707 | * is set. |
| 708 | */ |
| 709 | |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 710 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
| 711 | channel = assoc_req->channel; |
| 712 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 713 | lbs_deb_assoc("SSID '%s' requested\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 714 | print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len)); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 715 | if (assoc_req->mode == IW_MODE_INFRA) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 716 | lbs_send_specific_ssid_scan(priv, assoc_req->ssid, |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 717 | assoc_req->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 718 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 719 | bss = lbs_find_ssid_in_list(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 720 | assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 721 | if (bss != NULL) { |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 722 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 723 | ret = lbs_associate(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 724 | } else { |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 725 | lbs_deb_assoc("SSID not found; cannot associate\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 726 | } |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 727 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 728 | /* Scan for the network, do not save previous results. Stale |
| 729 | * scan data will cause us to join a non-existant adhoc network |
| 730 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 731 | lbs_send_specific_ssid_scan(priv, assoc_req->ssid, |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 732 | assoc_req->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 733 | |
| 734 | /* Search for the requested SSID in the scan table */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 735 | bss = lbs_find_ssid_in_list(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 736 | assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 737 | if (bss != NULL) { |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 738 | lbs_deb_assoc("SSID found, will join\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 739 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 740 | lbs_adhoc_join(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 741 | } else { |
| 742 | /* else send START command */ |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 743 | lbs_deb_assoc("SSID not found, creating adhoc network\n"); |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 744 | memcpy(&assoc_req->bss.ssid, &assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 745 | IW_ESSID_MAX_SIZE); |
| 746 | assoc_req->bss.ssid_len = assoc_req->ssid_len; |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 747 | lbs_adhoc_start(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 748 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 749 | } |
| 750 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 751 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 752 | return ret; |
| 753 | } |
| 754 | |
| 755 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 756 | static int assoc_helper_bssid(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 757 | struct assoc_request * assoc_req) |
| 758 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 759 | int ret = 0; |
| 760 | struct bss_descriptor * bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 761 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 762 | lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %pM", assoc_req->bssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 763 | |
| 764 | /* Search for index position in list for requested MAC */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 765 | bss = lbs_find_bssid_in_list(priv, assoc_req->bssid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 766 | assoc_req->mode); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 767 | if (bss == NULL) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 768 | lbs_deb_assoc("ASSOC: WAP: BSSID %pM not found, " |
| 769 | "cannot associate.\n", assoc_req->bssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 770 | goto out; |
| 771 | } |
| 772 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 773 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 774 | if (assoc_req->mode == IW_MODE_INFRA) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 775 | ret = lbs_associate(priv, assoc_req); |
| 776 | lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 777 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 778 | lbs_adhoc_join(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 779 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 780 | |
| 781 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 782 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 783 | return ret; |
| 784 | } |
| 785 | |
| 786 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 787 | static int assoc_helper_associate(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 788 | struct assoc_request * assoc_req) |
| 789 | { |
| 790 | int ret = 0, done = 0; |
| 791 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 792 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 793 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 794 | /* If we're given and 'any' BSSID, try associating based on SSID */ |
| 795 | |
| 796 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 797 | if (compare_ether_addr(bssid_any, assoc_req->bssid) |
| 798 | && compare_ether_addr(bssid_off, assoc_req->bssid)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 799 | ret = assoc_helper_bssid(priv, assoc_req); |
| 800 | done = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 805 | ret = assoc_helper_essid(priv, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 806 | } |
| 807 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 808 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 809 | return ret; |
| 810 | } |
| 811 | |
| 812 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 813 | static int assoc_helper_mode(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 814 | struct assoc_request * assoc_req) |
| 815 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 816 | int ret = 0; |
| 817 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 818 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 819 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 820 | if (assoc_req->mode == priv->mode) |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 821 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 822 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 823 | if (assoc_req->mode == IW_MODE_INFRA) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 824 | if (priv->psstate != PS_STATE_FULL_POWER) |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 825 | lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 826 | priv->psmode = LBS802_11POWERMODECAM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 827 | } |
| 828 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 829 | priv->mode = assoc_req->mode; |
Dan Williams | 39fcf7a | 2008-09-10 12:49:00 -0400 | [diff] [blame] | 830 | ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, assoc_req->mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 831 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 832 | done: |
| 833 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 834 | return ret; |
| 835 | } |
| 836 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 837 | static int assoc_helper_channel(struct lbs_private *priv, |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 838 | struct assoc_request * assoc_req) |
| 839 | { |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 840 | int ret = 0; |
| 841 | |
| 842 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 843 | |
David Woodhouse | 9f46257 | 2007-12-12 22:50:21 -0500 | [diff] [blame] | 844 | ret = lbs_update_channel(priv); |
David Woodhouse | d1a469f | 2007-12-16 17:21:00 -0500 | [diff] [blame] | 845 | if (ret) { |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 846 | lbs_deb_assoc("ASSOC: channel: error getting channel.\n"); |
David Woodhouse | d1a469f | 2007-12-16 17:21:00 -0500 | [diff] [blame] | 847 | goto done; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 848 | } |
| 849 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 850 | if (assoc_req->channel == priv->curbssparams.channel) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 851 | goto done; |
| 852 | |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 853 | if (priv->mesh_dev) { |
David Woodhouse | 8606213 | 2007-12-13 00:32:36 -0500 | [diff] [blame] | 854 | /* Change mesh channel first; 21.p21 firmware won't let |
| 855 | you change channel otherwise (even though it'll return |
| 856 | an error to this */ |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 857 | lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP, |
| 858 | assoc_req->channel); |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 859 | } |
| 860 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 861 | lbs_deb_assoc("ASSOC: channel: %d -> %d\n", |
David Woodhouse | 8606213 | 2007-12-13 00:32:36 -0500 | [diff] [blame] | 862 | priv->curbssparams.channel, assoc_req->channel); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 863 | |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 864 | ret = lbs_set_channel(priv, assoc_req->channel); |
| 865 | if (ret < 0) |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 866 | lbs_deb_assoc("ASSOC: channel: error setting channel.\n"); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 867 | |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 868 | /* FIXME: shouldn't need to grab the channel _again_ after setting |
| 869 | * it since the firmware is supposed to return the new channel, but |
| 870 | * whatever... */ |
David Woodhouse | 9f46257 | 2007-12-12 22:50:21 -0500 | [diff] [blame] | 871 | ret = lbs_update_channel(priv); |
David Woodhouse | d1a469f | 2007-12-16 17:21:00 -0500 | [diff] [blame] | 872 | if (ret) { |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 873 | lbs_deb_assoc("ASSOC: channel: error getting channel.\n"); |
David Woodhouse | d1a469f | 2007-12-16 17:21:00 -0500 | [diff] [blame] | 874 | goto done; |
| 875 | } |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 876 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 877 | if (assoc_req->channel != priv->curbssparams.channel) { |
David Woodhouse | 88ae291 | 2007-12-11 19:57:05 -0500 | [diff] [blame] | 878 | lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n", |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 879 | assoc_req->channel); |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 880 | goto restore_mesh; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | if ( assoc_req->secinfo.wep_enabled |
| 884 | && (assoc_req->wep_keys[0].len |
| 885 | || assoc_req->wep_keys[1].len |
| 886 | || assoc_req->wep_keys[2].len |
| 887 | || assoc_req->wep_keys[3].len)) { |
| 888 | /* Make sure WEP keys are re-sent to firmware */ |
| 889 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
| 890 | } |
| 891 | |
| 892 | /* Must restart/rejoin adhoc networks after channel change */ |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 893 | set_bit(ASSOC_FLAG_SSID, &assoc_req->flags); |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 894 | |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 895 | restore_mesh: |
| 896 | if (priv->mesh_dev) |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 897 | lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, |
| 898 | priv->curbssparams.channel); |
David Woodhouse | 8642f1f | 2007-12-11 20:03:01 -0500 | [diff] [blame] | 899 | |
| 900 | done: |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 901 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 906 | static int assoc_helper_wep_keys(struct lbs_private *priv, |
David Woodhouse | f70dd45 | 2007-12-18 00:18:05 -0500 | [diff] [blame] | 907 | struct assoc_request *assoc_req) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 908 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 909 | int i; |
| 910 | int ret = 0; |
| 911 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 912 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 913 | |
| 914 | /* Set or remove WEP keys */ |
David Woodhouse | f70dd45 | 2007-12-18 00:18:05 -0500 | [diff] [blame] | 915 | if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len || |
| 916 | assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len) |
| 917 | ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req); |
| 918 | else |
| 919 | ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 920 | |
| 921 | if (ret) |
| 922 | goto out; |
| 923 | |
| 924 | /* enable/disable the MAC's WEP packet filter */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 925 | if (assoc_req->secinfo.wep_enabled) |
Holger Schurig | d9e9778 | 2008-03-12 16:06:43 +0100 | [diff] [blame] | 926 | priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 927 | else |
Holger Schurig | d9e9778 | 2008-03-12 16:06:43 +0100 | [diff] [blame] | 928 | priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE; |
David Woodhouse | f70dd45 | 2007-12-18 00:18:05 -0500 | [diff] [blame] | 929 | |
Holger Schurig | c97329e | 2008-03-18 11:20:21 +0100 | [diff] [blame] | 930 | lbs_set_mac_control(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 931 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 932 | mutex_lock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 933 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 934 | /* Copy WEP keys into priv wep key fields */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 935 | for (i = 0; i < 4; i++) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 936 | memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i], |
David Woodhouse | f70dd45 | 2007-12-18 00:18:05 -0500 | [diff] [blame] | 937 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 938 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 939 | priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 940 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 941 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 942 | |
| 943 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 944 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 945 | return ret; |
| 946 | } |
| 947 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 948 | static int assoc_helper_secinfo(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 949 | struct assoc_request * assoc_req) |
| 950 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 951 | int ret = 0; |
David Woodhouse | 4f59abf | 2007-12-18 00:47:17 -0500 | [diff] [blame] | 952 | uint16_t do_wpa; |
| 953 | uint16_t rsn = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 954 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 955 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 956 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 957 | memcpy(&priv->secinfo, &assoc_req->secinfo, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 958 | sizeof(struct lbs_802_11_security)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 959 | |
Holger Schurig | c97329e | 2008-03-18 11:20:21 +0100 | [diff] [blame] | 960 | lbs_set_mac_control(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 961 | |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 962 | /* If RSN is already enabled, don't try to enable it again, since |
| 963 | * ENABLE_RSN resets internal state machines and will clobber the |
| 964 | * 4-way WPA handshake. |
| 965 | */ |
| 966 | |
| 967 | /* Get RSN enabled/disabled */ |
David Woodhouse | 4f59abf | 2007-12-18 00:47:17 -0500 | [diff] [blame] | 968 | ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn); |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 969 | if (ret) { |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 970 | lbs_deb_assoc("Failed to get RSN status: %d\n", ret); |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 971 | goto out; |
| 972 | } |
| 973 | |
| 974 | /* Don't re-enable RSN if it's already enabled */ |
David Woodhouse | 4f59abf | 2007-12-18 00:47:17 -0500 | [diff] [blame] | 975 | do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled; |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 976 | if (do_wpa == rsn) |
| 977 | goto out; |
| 978 | |
| 979 | /* Set RSN enabled/disabled */ |
David Woodhouse | 4f59abf | 2007-12-18 00:47:17 -0500 | [diff] [blame] | 980 | ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa); |
Dan Williams | 90a4221 | 2007-05-25 23:01:24 -0400 | [diff] [blame] | 981 | |
| 982 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 983 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 984 | return ret; |
| 985 | } |
| 986 | |
| 987 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 988 | static int assoc_helper_wpa_keys(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 989 | struct assoc_request * assoc_req) |
| 990 | { |
| 991 | int ret = 0; |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 992 | unsigned int flags = assoc_req->flags; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 993 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 994 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 995 | |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 996 | /* Work around older firmware bug where WPA unicast and multicast |
| 997 | * keys must be set independently. Seen in SDIO parts with firmware |
| 998 | * version 5.0.11p0. |
| 999 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1000 | |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1001 | if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 1002 | clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags); |
David Woodhouse | 9e1228d | 2008-03-03 12:15:39 +0100 | [diff] [blame] | 1003 | ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req); |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1004 | assoc_req->flags = flags; |
| 1005 | } |
| 1006 | |
| 1007 | if (ret) |
| 1008 | goto out; |
| 1009 | |
| 1010 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
| 1011 | clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags); |
| 1012 | |
David Woodhouse | 9e1228d | 2008-03-03 12:15:39 +0100 | [diff] [blame] | 1013 | ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req); |
Dan Williams | 2bcde51 | 2007-10-03 10:37:45 -0400 | [diff] [blame] | 1014 | assoc_req->flags = flags; |
| 1015 | } |
| 1016 | |
| 1017 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1018 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1019 | return ret; |
| 1020 | } |
| 1021 | |
| 1022 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1023 | static int assoc_helper_wpa_ie(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1024 | struct assoc_request * assoc_req) |
| 1025 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1026 | int ret = 0; |
| 1027 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1028 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1029 | |
| 1030 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1031 | memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len); |
| 1032 | priv->wpa_ie_len = assoc_req->wpa_ie_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1033 | } else { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1034 | memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN); |
| 1035 | priv->wpa_ie_len = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1036 | } |
| 1037 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1038 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1039 | return ret; |
| 1040 | } |
| 1041 | |
| 1042 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1043 | static int should_deauth_infrastructure(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1044 | struct assoc_request * assoc_req) |
| 1045 | { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1046 | int ret = 0; |
| 1047 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1048 | if (priv->connect_status != LBS_CONNECTED) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1049 | return 0; |
| 1050 | |
Holger Schurig | 52507c2 | 2008-01-28 17:25:53 +0100 | [diff] [blame] | 1051 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1052 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1053 | lbs_deb_assoc("Deauthenticating due to new SSID\n"); |
| 1054 | ret = 1; |
| 1055 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1059 | if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1060 | lbs_deb_assoc("Deauthenticating due to new security\n"); |
| 1061 | ret = 1; |
| 1062 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1067 | lbs_deb_assoc("Deauthenticating due to new BSSID\n"); |
| 1068 | ret = 1; |
| 1069 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1070 | } |
| 1071 | |
Luis Carlos Cobo Rus | fff47f1 | 2007-05-30 12:16:13 -0400 | [diff] [blame] | 1072 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1073 | lbs_deb_assoc("Deauthenticating due to channel switch\n"); |
| 1074 | ret = 1; |
| 1075 | goto out; |
Luis Carlos Cobo Rus | fff47f1 | 2007-05-30 12:16:13 -0400 | [diff] [blame] | 1076 | } |
| 1077 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1078 | /* FIXME: deal with 'auto' mode somehow */ |
| 1079 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1080 | if (assoc_req->mode != IW_MODE_INFRA) { |
| 1081 | lbs_deb_assoc("Deauthenticating due to leaving " |
| 1082 | "infra mode\n"); |
| 1083 | ret = 1; |
| 1084 | goto out; |
| 1085 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1086 | } |
| 1087 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1088 | out: |
| 1089 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
Holger Schurig | 52507c2 | 2008-01-28 17:25:53 +0100 | [diff] [blame] | 1090 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1094 | static int should_stop_adhoc(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1095 | struct assoc_request * assoc_req) |
| 1096 | { |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1097 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 1098 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1099 | if (priv->connect_status != LBS_CONNECTED) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1100 | return 0; |
| 1101 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1102 | if (lbs_ssid_cmp(priv->curbssparams.ssid, |
| 1103 | priv->curbssparams.ssid_len, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1104 | assoc_req->ssid, assoc_req->ssid_len) != 0) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1105 | return 1; |
| 1106 | |
| 1107 | /* FIXME: deal with 'auto' mode somehow */ |
| 1108 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1109 | if (assoc_req->mode != IW_MODE_ADHOC) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1110 | return 1; |
| 1111 | } |
| 1112 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1113 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1114 | if (assoc_req->channel != priv->curbssparams.channel) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1115 | return 1; |
| 1116 | } |
| 1117 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1118 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1119 | return 0; |
| 1120 | } |
| 1121 | |
| 1122 | |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 1123 | /** |
| 1124 | * @brief This function finds the best SSID in the Scan List |
| 1125 | * |
| 1126 | * Search the scan table for the best SSID that also matches the current |
| 1127 | * adapter network preference (infrastructure or adhoc) |
| 1128 | * |
| 1129 | * @param priv A pointer to struct lbs_private |
| 1130 | * |
| 1131 | * @return index in BSSID list |
| 1132 | */ |
| 1133 | static struct bss_descriptor *lbs_find_best_ssid_in_list( |
| 1134 | struct lbs_private *priv, uint8_t mode) |
| 1135 | { |
| 1136 | uint8_t bestrssi = 0; |
| 1137 | struct bss_descriptor *iter_bss; |
| 1138 | struct bss_descriptor *best_bss = NULL; |
| 1139 | |
| 1140 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1141 | |
| 1142 | mutex_lock(&priv->lock); |
| 1143 | |
| 1144 | list_for_each_entry(iter_bss, &priv->network_list, list) { |
| 1145 | switch (mode) { |
| 1146 | case IW_MODE_INFRA: |
| 1147 | case IW_MODE_ADHOC: |
| 1148 | if (!is_network_compatible(priv, iter_bss, mode)) |
| 1149 | break; |
| 1150 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) |
| 1151 | break; |
| 1152 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1153 | best_bss = iter_bss; |
| 1154 | break; |
| 1155 | case IW_MODE_AUTO: |
| 1156 | default: |
| 1157 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) |
| 1158 | break; |
| 1159 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1160 | best_bss = iter_bss; |
| 1161 | break; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | mutex_unlock(&priv->lock); |
| 1166 | lbs_deb_leave_args(LBS_DEB_SCAN, "best_bss %p", best_bss); |
| 1167 | return best_bss; |
| 1168 | } |
| 1169 | |
| 1170 | /** |
| 1171 | * @brief Find the best AP |
| 1172 | * |
| 1173 | * Used from association worker. |
| 1174 | * |
| 1175 | * @param priv A pointer to struct lbs_private structure |
| 1176 | * @param pSSID A pointer to AP's ssid |
| 1177 | * |
| 1178 | * @return 0--success, otherwise--fail |
| 1179 | */ |
| 1180 | static int lbs_find_best_network_ssid(struct lbs_private *priv, |
| 1181 | uint8_t *out_ssid, uint8_t *out_ssid_len, uint8_t preferred_mode, |
| 1182 | uint8_t *out_mode) |
| 1183 | { |
| 1184 | int ret = -1; |
| 1185 | struct bss_descriptor *found; |
| 1186 | |
| 1187 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1188 | |
| 1189 | priv->scan_ssid_len = 0; |
| 1190 | lbs_scan_networks(priv, 1); |
| 1191 | if (priv->surpriseremoved) |
| 1192 | goto out; |
| 1193 | |
| 1194 | found = lbs_find_best_ssid_in_list(priv, preferred_mode); |
| 1195 | if (found && (found->ssid_len > 0)) { |
| 1196 | memcpy(out_ssid, &found->ssid, IW_ESSID_MAX_SIZE); |
| 1197 | *out_ssid_len = found->ssid_len; |
| 1198 | *out_mode = found->mode; |
| 1199 | ret = 0; |
| 1200 | } |
| 1201 | |
| 1202 | out: |
| 1203 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 1204 | return ret; |
| 1205 | } |
| 1206 | |
| 1207 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1208 | void lbs_association_worker(struct work_struct *work) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1209 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1210 | struct lbs_private *priv = container_of(work, struct lbs_private, |
| 1211 | assoc_work.work); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1212 | struct assoc_request * assoc_req = NULL; |
| 1213 | int ret = 0; |
| 1214 | int find_any_ssid = 0; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1215 | DECLARE_SSID_BUF(ssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1216 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1217 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1218 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1219 | mutex_lock(&priv->lock); |
| 1220 | assoc_req = priv->pending_assoc_req; |
| 1221 | priv->pending_assoc_req = NULL; |
| 1222 | priv->in_progress_assoc_req = assoc_req; |
| 1223 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1224 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1225 | if (!assoc_req) |
| 1226 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1227 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1228 | lbs_deb_assoc( |
| 1229 | "Association Request:\n" |
| 1230 | " flags: 0x%08lx\n" |
| 1231 | " SSID: '%s'\n" |
| 1232 | " chann: %d\n" |
| 1233 | " band: %d\n" |
| 1234 | " mode: %d\n" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1235 | " BSSID: %pM\n" |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1236 | " secinfo: %s%s%s\n" |
| 1237 | " auth_mode: %d\n", |
| 1238 | assoc_req->flags, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1239 | print_ssid(ssid, assoc_req->ssid, assoc_req->ssid_len), |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1240 | assoc_req->channel, assoc_req->band, assoc_req->mode, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1241 | assoc_req->bssid, |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1242 | assoc_req->secinfo.WPAenabled ? " WPA" : "", |
| 1243 | assoc_req->secinfo.WPA2enabled ? " WPA2" : "", |
| 1244 | assoc_req->secinfo.wep_enabled ? " WEP" : "", |
| 1245 | assoc_req->secinfo.auth_mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1246 | |
| 1247 | /* If 'any' SSID was specified, find an SSID to associate with */ |
| 1248 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags) |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1249 | && !assoc_req->ssid_len) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1250 | find_any_ssid = 1; |
| 1251 | |
| 1252 | /* But don't use 'any' SSID if there's a valid locked BSSID to use */ |
| 1253 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 1254 | if (compare_ether_addr(assoc_req->bssid, bssid_any) |
| 1255 | && compare_ether_addr(assoc_req->bssid, bssid_off)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1256 | find_any_ssid = 0; |
| 1257 | } |
| 1258 | |
| 1259 | if (find_any_ssid) { |
Holger Schurig | 877cb0d | 2008-04-02 16:34:51 +0200 | [diff] [blame] | 1260 | u8 new_mode = assoc_req->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1261 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1262 | ret = lbs_find_best_network_ssid(priv, assoc_req->ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1263 | &assoc_req->ssid_len, assoc_req->mode, &new_mode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1264 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1265 | lbs_deb_assoc("Could not find best network\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1266 | ret = -ENETUNREACH; |
| 1267 | goto out; |
| 1268 | } |
| 1269 | |
| 1270 | /* Ensure we switch to the mode of the AP */ |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1271 | if (assoc_req->mode == IW_MODE_AUTO) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1272 | set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); |
| 1273 | assoc_req->mode = new_mode; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | /* |
| 1278 | * Check if the attributes being changing require deauthentication |
| 1279 | * from the currently associated infrastructure access point. |
| 1280 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1281 | if (priv->mode == IW_MODE_INFRA) { |
| 1282 | if (should_deauth_infrastructure(priv, assoc_req)) { |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 1283 | ret = lbs_cmd_80211_deauthenticate(priv, |
| 1284 | priv->curbssparams.bssid, |
| 1285 | WLAN_REASON_DEAUTH_LEAVING); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1286 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1287 | lbs_deb_assoc("Deauthentication due to new " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1288 | "configuration request failed: %d\n", |
| 1289 | ret); |
| 1290 | } |
| 1291 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1292 | } else if (priv->mode == IW_MODE_ADHOC) { |
| 1293 | if (should_stop_adhoc(priv, assoc_req)) { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1294 | ret = lbs_adhoc_stop(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1295 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1296 | lbs_deb_assoc("Teardown of AdHoc network due to " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1297 | "new configuration request failed: %d\n", |
| 1298 | ret); |
| 1299 | } |
| 1300 | |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | /* Send the various configuration bits to the firmware */ |
| 1305 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { |
| 1306 | ret = assoc_helper_mode(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1307 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1308 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1309 | } |
| 1310 | |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1311 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
| 1312 | ret = assoc_helper_channel(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1313 | if (ret) |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1314 | goto out; |
Dan Williams | ef9a264 | 2007-05-25 16:46:33 -0400 | [diff] [blame] | 1315 | } |
| 1316 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1317 | if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags) |
| 1318 | || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) { |
| 1319 | ret = assoc_helper_wep_keys(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1320 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1321 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
| 1325 | ret = assoc_helper_secinfo(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1326 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1327 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
| 1331 | ret = assoc_helper_wpa_ie(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1332 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1333 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags) |
| 1337 | || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
| 1338 | ret = assoc_helper_wpa_keys(priv, assoc_req); |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1339 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1340 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | /* SSID/BSSID should be the _last_ config option set, because they |
| 1344 | * trigger the association attempt. |
| 1345 | */ |
| 1346 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags) |
| 1347 | || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
| 1348 | int success = 1; |
| 1349 | |
| 1350 | ret = assoc_helper_associate(priv, assoc_req); |
| 1351 | if (ret) { |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 1352 | lbs_deb_assoc("ASSOC: association unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1353 | ret); |
| 1354 | success = 0; |
| 1355 | } |
| 1356 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1357 | if (priv->connect_status != LBS_CONNECTED) { |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 1358 | lbs_deb_assoc("ASSOC: association unsuccessful, " |
| 1359 | "not connected\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1360 | success = 0; |
| 1361 | } |
| 1362 | |
| 1363 | if (success) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1364 | lbs_deb_assoc("associated to %pM\n", |
| 1365 | priv->curbssparams.bssid); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1366 | lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1367 | CMD_802_11_RSSI, |
| 1368 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1369 | } else { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1370 | ret = -1; |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | out: |
| 1375 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1376 | lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1377 | ret); |
| 1378 | } |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 1379 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1380 | mutex_lock(&priv->lock); |
| 1381 | priv->in_progress_assoc_req = NULL; |
| 1382 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1383 | kfree(assoc_req); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1384 | |
| 1385 | done: |
| 1386 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | |
| 1390 | /* |
| 1391 | * Caller MUST hold any necessary locks |
| 1392 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1393 | struct assoc_request *lbs_get_association_request(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1394 | { |
| 1395 | struct assoc_request * assoc_req; |
| 1396 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1397 | lbs_deb_enter(LBS_DEB_ASSOC); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1398 | if (!priv->pending_assoc_req) { |
| 1399 | priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request), |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 1400 | GFP_KERNEL); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1401 | if (!priv->pending_assoc_req) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1402 | lbs_pr_info("Not enough memory to allocate association" |
| 1403 | " request!\n"); |
| 1404 | return NULL; |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | /* Copy current configuration attributes to the association request, |
| 1409 | * but don't overwrite any that are already set. |
| 1410 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1411 | assoc_req = priv->pending_assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1412 | if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1413 | memcpy(&assoc_req->ssid, &priv->curbssparams.ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1414 | IW_ESSID_MAX_SIZE); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1415 | assoc_req->ssid_len = priv->curbssparams.ssid_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1419 | assoc_req->channel = priv->curbssparams.channel; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1420 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 1421 | if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1422 | assoc_req->band = priv->curbssparams.band; |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 1423 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1424 | if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1425 | assoc_req->mode = priv->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1426 | |
| 1427 | if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1428 | memcpy(&assoc_req->bssid, priv->curbssparams.bssid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1429 | ETH_ALEN); |
| 1430 | } |
| 1431 | |
| 1432 | if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) { |
| 1433 | int i; |
| 1434 | for (i = 0; i < 4; i++) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1435 | memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i], |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 1436 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1441 | assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1442 | |
| 1443 | if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1444 | memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key, |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 1445 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1449 | memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key, |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 1450 | sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1454 | memcpy(&assoc_req->secinfo, &priv->secinfo, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1455 | sizeof(struct lbs_802_11_security)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1459 | memcpy(&assoc_req->wpa_ie, &priv->wpa_ie, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1460 | MAX_WPA_IE_LEN); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1461 | assoc_req->wpa_ie_len = priv->wpa_ie_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1462 | } |
| 1463 | |
Holger Schurig | 0765af4 | 2007-10-15 12:55:56 +0200 | [diff] [blame] | 1464 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1465 | return assoc_req; |
| 1466 | } |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1467 | |
| 1468 | |
| 1469 | /** |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1470 | * @brief This function prepares command of authenticate. |
| 1471 | * |
| 1472 | * @param priv A pointer to struct lbs_private structure |
| 1473 | * @param cmd A pointer to cmd_ds_command structure |
| 1474 | * @param pdata_buf Void cast of pointer to a BSSID to authenticate with |
| 1475 | * |
| 1476 | * @return 0 or -1 |
| 1477 | */ |
| 1478 | int lbs_cmd_80211_authenticate(struct lbs_private *priv, |
| 1479 | struct cmd_ds_command *cmd, |
| 1480 | void *pdata_buf) |
| 1481 | { |
| 1482 | struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth; |
| 1483 | int ret = -1; |
| 1484 | u8 *bssid = pdata_buf; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1485 | |
| 1486 | lbs_deb_enter(LBS_DEB_JOIN); |
| 1487 | |
| 1488 | cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE); |
| 1489 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate) |
| 1490 | + S_DS_GEN); |
| 1491 | |
| 1492 | /* translate auth mode to 802.11 defined wire value */ |
| 1493 | switch (priv->secinfo.auth_mode) { |
| 1494 | case IW_AUTH_ALG_OPEN_SYSTEM: |
| 1495 | pauthenticate->authtype = 0x00; |
| 1496 | break; |
| 1497 | case IW_AUTH_ALG_SHARED_KEY: |
| 1498 | pauthenticate->authtype = 0x01; |
| 1499 | break; |
| 1500 | case IW_AUTH_ALG_LEAP: |
| 1501 | pauthenticate->authtype = 0x80; |
| 1502 | break; |
| 1503 | default: |
| 1504 | lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n", |
| 1505 | priv->secinfo.auth_mode); |
| 1506 | goto out; |
| 1507 | } |
| 1508 | |
| 1509 | memcpy(pauthenticate->macaddr, bssid, ETH_ALEN); |
| 1510 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1511 | lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n", |
| 1512 | bssid, pauthenticate->authtype); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1513 | ret = 0; |
| 1514 | |
| 1515 | out: |
| 1516 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); |
| 1517 | return ret; |
| 1518 | } |
| 1519 | |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 1520 | /** |
| 1521 | * @brief Deauthenticate from a specific BSS |
| 1522 | * |
| 1523 | * @param priv A pointer to struct lbs_private structure |
| 1524 | * @param bssid The specific BSS to deauthenticate from |
| 1525 | * @param reason The 802.11 sec. 7.3.1.7 Reason Code for deauthenticating |
| 1526 | * |
| 1527 | * @return 0 on success, error on failure |
| 1528 | */ |
| 1529 | int lbs_cmd_80211_deauthenticate(struct lbs_private *priv, u8 bssid[ETH_ALEN], |
| 1530 | u16 reason) |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1531 | { |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 1532 | struct cmd_ds_802_11_deauthenticate cmd; |
| 1533 | int ret; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1534 | |
| 1535 | lbs_deb_enter(LBS_DEB_JOIN); |
| 1536 | |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 1537 | memset(&cmd, 0, sizeof(cmd)); |
| 1538 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 1539 | memcpy(cmd.macaddr, &bssid[0], ETH_ALEN); |
| 1540 | cmd.reasoncode = cpu_to_le16(reason); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1541 | |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 1542 | ret = lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1543 | |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 1544 | /* Clean up everything even if there was an error; can't assume that |
| 1545 | * we're still authenticated to the AP after trying to deauth. |
| 1546 | */ |
| 1547 | lbs_mac_event_disconnected(priv); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1548 | |
| 1549 | lbs_deb_leave(LBS_DEB_JOIN); |
Dan Williams | 191bb40 | 2008-08-21 17:46:18 -0400 | [diff] [blame] | 1550 | return ret; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | int lbs_cmd_80211_associate(struct lbs_private *priv, |
| 1554 | struct cmd_ds_command *cmd, void *pdata_buf) |
| 1555 | { |
| 1556 | struct cmd_ds_802_11_associate *passo = &cmd->params.associate; |
| 1557 | int ret = 0; |
| 1558 | struct assoc_request *assoc_req = pdata_buf; |
| 1559 | struct bss_descriptor *bss = &assoc_req->bss; |
| 1560 | u8 *pos; |
| 1561 | u16 tmpcap, tmplen; |
| 1562 | struct mrvlietypes_ssidparamset *ssid; |
| 1563 | struct mrvlietypes_phyparamset *phy; |
| 1564 | struct mrvlietypes_ssparamset *ss; |
| 1565 | struct mrvlietypes_ratesparamset *rates; |
| 1566 | struct mrvlietypes_rsnparamset *rsn; |
| 1567 | |
| 1568 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 1569 | |
| 1570 | pos = (u8 *) passo; |
| 1571 | |
| 1572 | if (!priv) { |
| 1573 | ret = -1; |
| 1574 | goto done; |
| 1575 | } |
| 1576 | |
| 1577 | cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE); |
| 1578 | |
| 1579 | memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr)); |
| 1580 | pos += sizeof(passo->peerstaaddr); |
| 1581 | |
| 1582 | /* set the listen interval */ |
| 1583 | passo->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL); |
| 1584 | |
| 1585 | pos += sizeof(passo->capability); |
| 1586 | pos += sizeof(passo->listeninterval); |
| 1587 | pos += sizeof(passo->bcnperiod); |
| 1588 | pos += sizeof(passo->dtimperiod); |
| 1589 | |
| 1590 | ssid = (struct mrvlietypes_ssidparamset *) pos; |
| 1591 | ssid->header.type = cpu_to_le16(TLV_TYPE_SSID); |
| 1592 | tmplen = bss->ssid_len; |
| 1593 | ssid->header.len = cpu_to_le16(tmplen); |
| 1594 | memcpy(ssid->ssid, bss->ssid, tmplen); |
| 1595 | pos += sizeof(ssid->header) + tmplen; |
| 1596 | |
| 1597 | phy = (struct mrvlietypes_phyparamset *) pos; |
| 1598 | phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS); |
| 1599 | tmplen = sizeof(phy->fh_ds.dsparamset); |
| 1600 | phy->header.len = cpu_to_le16(tmplen); |
| 1601 | memcpy(&phy->fh_ds.dsparamset, |
| 1602 | &bss->phyparamset.dsparamset.currentchan, |
| 1603 | tmplen); |
| 1604 | pos += sizeof(phy->header) + tmplen; |
| 1605 | |
| 1606 | ss = (struct mrvlietypes_ssparamset *) pos; |
| 1607 | ss->header.type = cpu_to_le16(TLV_TYPE_CF); |
| 1608 | tmplen = sizeof(ss->cf_ibss.cfparamset); |
| 1609 | ss->header.len = cpu_to_le16(tmplen); |
| 1610 | pos += sizeof(ss->header) + tmplen; |
| 1611 | |
| 1612 | rates = (struct mrvlietypes_ratesparamset *) pos; |
| 1613 | rates->header.type = cpu_to_le16(TLV_TYPE_RATES); |
| 1614 | memcpy(&rates->rates, &bss->rates, MAX_RATES); |
| 1615 | tmplen = MAX_RATES; |
| 1616 | if (get_common_rates(priv, rates->rates, &tmplen)) { |
| 1617 | ret = -1; |
| 1618 | goto done; |
| 1619 | } |
| 1620 | pos += sizeof(rates->header) + tmplen; |
| 1621 | rates->header.len = cpu_to_le16(tmplen); |
| 1622 | lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen); |
| 1623 | |
| 1624 | /* Copy the infra. association rates into Current BSS state structure */ |
| 1625 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); |
| 1626 | memcpy(&priv->curbssparams.rates, &rates->rates, tmplen); |
| 1627 | |
| 1628 | /* Set MSB on basic rates as the firmware requires, but _after_ |
| 1629 | * copying to current bss rates. |
| 1630 | */ |
| 1631 | lbs_set_basic_rate_flags(rates->rates, tmplen); |
| 1632 | |
| 1633 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { |
| 1634 | rsn = (struct mrvlietypes_rsnparamset *) pos; |
| 1635 | /* WPA_IE or WPA2_IE */ |
| 1636 | rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]); |
| 1637 | tmplen = (u16) assoc_req->wpa_ie[1]; |
| 1638 | rsn->header.len = cpu_to_le16(tmplen); |
| 1639 | memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen); |
| 1640 | lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: RSN IE", (u8 *) rsn, |
| 1641 | sizeof(rsn->header) + tmplen); |
| 1642 | pos += sizeof(rsn->header) + tmplen; |
| 1643 | } |
| 1644 | |
| 1645 | /* update curbssparams */ |
| 1646 | priv->curbssparams.channel = bss->phyparamset.dsparamset.currentchan; |
| 1647 | |
| 1648 | if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { |
| 1649 | ret = -1; |
| 1650 | goto done; |
| 1651 | } |
| 1652 | |
| 1653 | cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN); |
| 1654 | |
| 1655 | /* set the capability info */ |
| 1656 | tmpcap = (bss->capability & CAPINFO_MASK); |
| 1657 | if (bss->mode == IW_MODE_INFRA) |
| 1658 | tmpcap |= WLAN_CAPABILITY_ESS; |
| 1659 | passo->capability = cpu_to_le16(tmpcap); |
| 1660 | lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap); |
| 1661 | |
| 1662 | done: |
| 1663 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 1664 | return ret; |
| 1665 | } |
| 1666 | |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1667 | int lbs_ret_80211_associate(struct lbs_private *priv, |
| 1668 | struct cmd_ds_command *resp) |
| 1669 | { |
| 1670 | int ret = 0; |
| 1671 | union iwreq_data wrqu; |
| 1672 | struct ieeetypes_assocrsp *passocrsp; |
| 1673 | struct bss_descriptor *bss; |
| 1674 | u16 status_code; |
| 1675 | |
| 1676 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 1677 | |
| 1678 | if (!priv->in_progress_assoc_req) { |
| 1679 | lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n"); |
| 1680 | ret = -1; |
| 1681 | goto done; |
| 1682 | } |
| 1683 | bss = &priv->in_progress_assoc_req->bss; |
| 1684 | |
| 1685 | passocrsp = (struct ieeetypes_assocrsp *) &resp->params; |
| 1686 | |
| 1687 | /* |
| 1688 | * Older FW versions map the IEEE 802.11 Status Code in the association |
| 1689 | * response to the following values returned in passocrsp->statuscode: |
| 1690 | * |
| 1691 | * IEEE Status Code Marvell Status Code |
| 1692 | * 0 -> 0x0000 ASSOC_RESULT_SUCCESS |
| 1693 | * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 1694 | * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 1695 | * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 1696 | * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED |
| 1697 | * others -> 0x0003 ASSOC_RESULT_REFUSED |
| 1698 | * |
| 1699 | * Other response codes: |
| 1700 | * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused) |
| 1701 | * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for |
| 1702 | * association response from the AP) |
| 1703 | */ |
| 1704 | |
| 1705 | status_code = le16_to_cpu(passocrsp->statuscode); |
| 1706 | switch (status_code) { |
| 1707 | case 0x00: |
| 1708 | break; |
| 1709 | case 0x01: |
| 1710 | lbs_deb_assoc("ASSOC_RESP: invalid parameters\n"); |
| 1711 | break; |
| 1712 | case 0x02: |
| 1713 | lbs_deb_assoc("ASSOC_RESP: internal timer " |
| 1714 | "expired while waiting for the AP\n"); |
| 1715 | break; |
| 1716 | case 0x03: |
| 1717 | lbs_deb_assoc("ASSOC_RESP: association " |
| 1718 | "refused by AP\n"); |
| 1719 | break; |
| 1720 | case 0x04: |
| 1721 | lbs_deb_assoc("ASSOC_RESP: authentication " |
| 1722 | "refused by AP\n"); |
| 1723 | break; |
| 1724 | default: |
| 1725 | lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x " |
| 1726 | " unknown\n", status_code); |
| 1727 | break; |
| 1728 | } |
| 1729 | |
| 1730 | if (status_code) { |
| 1731 | lbs_mac_event_disconnected(priv); |
| 1732 | ret = -1; |
| 1733 | goto done; |
| 1734 | } |
| 1735 | |
| 1736 | lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP", (void *)&resp->params, |
| 1737 | le16_to_cpu(resp->size) - S_DS_GEN); |
| 1738 | |
| 1739 | /* Send a Media Connected event, according to the Spec */ |
| 1740 | priv->connect_status = LBS_CONNECTED; |
| 1741 | |
| 1742 | /* Update current SSID and BSSID */ |
| 1743 | memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); |
| 1744 | priv->curbssparams.ssid_len = bss->ssid_len; |
| 1745 | memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN); |
| 1746 | |
| 1747 | priv->SNR[TYPE_RXPD][TYPE_AVG] = 0; |
| 1748 | priv->NF[TYPE_RXPD][TYPE_AVG] = 0; |
| 1749 | |
| 1750 | memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR)); |
| 1751 | memset(priv->rawNF, 0x00, sizeof(priv->rawNF)); |
| 1752 | priv->nextSNRNF = 0; |
| 1753 | priv->numSNRNF = 0; |
| 1754 | |
| 1755 | netif_carrier_on(priv->dev); |
| 1756 | if (!priv->tx_pending_len) |
| 1757 | netif_wake_queue(priv->dev); |
| 1758 | |
| 1759 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); |
| 1760 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1761 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
| 1762 | |
| 1763 | done: |
| 1764 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 1765 | return ret; |
| 1766 | } |
| 1767 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1768 | static int lbs_adhoc_post(struct lbs_private *priv, struct cmd_header *resp) |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1769 | { |
| 1770 | int ret = 0; |
| 1771 | u16 command = le16_to_cpu(resp->command); |
| 1772 | u16 result = le16_to_cpu(resp->result); |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1773 | struct cmd_ds_802_11_ad_hoc_result *adhoc_resp; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1774 | union iwreq_data wrqu; |
| 1775 | struct bss_descriptor *bss; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1776 | DECLARE_SSID_BUF(ssid); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1777 | |
| 1778 | lbs_deb_enter(LBS_DEB_JOIN); |
| 1779 | |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1780 | adhoc_resp = (struct cmd_ds_802_11_ad_hoc_result *) resp; |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1781 | |
| 1782 | if (!priv->in_progress_assoc_req) { |
| 1783 | lbs_deb_join("ADHOC_RESP: no in-progress association " |
| 1784 | "request\n"); |
| 1785 | ret = -1; |
| 1786 | goto done; |
| 1787 | } |
| 1788 | bss = &priv->in_progress_assoc_req->bss; |
| 1789 | |
| 1790 | /* |
| 1791 | * Join result code 0 --> SUCCESS |
| 1792 | */ |
| 1793 | if (result) { |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1794 | lbs_deb_join("ADHOC_RESP: failed (result 0x%X)\n", result); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1795 | if (priv->connect_status == LBS_CONNECTED) |
| 1796 | lbs_mac_event_disconnected(priv); |
| 1797 | ret = -1; |
| 1798 | goto done; |
| 1799 | } |
| 1800 | |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1801 | /* Send a Media Connected event, according to the Spec */ |
| 1802 | priv->connect_status = LBS_CONNECTED; |
| 1803 | |
| 1804 | if (command == CMD_RET(CMD_802_11_AD_HOC_START)) { |
| 1805 | /* Update the created network descriptor with the new BSSID */ |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1806 | memcpy(bss->bssid, adhoc_resp->bssid, ETH_ALEN); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | /* Set the BSSID from the joined/started descriptor */ |
| 1810 | memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN); |
| 1811 | |
| 1812 | /* Set the new SSID to current SSID */ |
| 1813 | memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); |
| 1814 | priv->curbssparams.ssid_len = bss->ssid_len; |
| 1815 | |
| 1816 | netif_carrier_on(priv->dev); |
| 1817 | if (!priv->tx_pending_len) |
| 1818 | netif_wake_queue(priv->dev); |
| 1819 | |
| 1820 | memset(&wrqu, 0, sizeof(wrqu)); |
| 1821 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); |
| 1822 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1823 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
| 1824 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1825 | lbs_deb_join("ADHOC_RESP: Joined/started '%s', BSSID %pM, channel %d\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1826 | print_ssid(ssid, bss->ssid, bss->ssid_len), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1827 | priv->curbssparams.bssid, |
Dan Williams | f5fe1fd | 2008-08-21 21:46:59 -0400 | [diff] [blame] | 1828 | priv->curbssparams.channel); |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 1829 | |
| 1830 | done: |
| 1831 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); |
| 1832 | return ret; |
| 1833 | } |
| 1834 | |