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