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