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