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