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