Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /** |
| 2 | * Functions implementing wlan scan IOCTL and firmware command APIs |
| 3 | * |
| 4 | * IOCTL handlers as well as command preperation and response routines |
| 5 | * for sending scan commands to the firmware. |
| 6 | */ |
| 7 | #include <linux/ctype.h> |
| 8 | #include <linux/if.h> |
| 9 | #include <linux/netdevice.h> |
| 10 | #include <linux/wireless.h> |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 11 | #include <linux/etherdevice.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 12 | |
| 13 | #include <net/ieee80211.h> |
| 14 | #include <net/iw_handler.h> |
| 15 | |
Vladimir Davydov | ac630c2 | 2007-09-06 21:45:36 -0400 | [diff] [blame] | 16 | #include <asm/unaligned.h> |
| 17 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 18 | #include "host.h" |
| 19 | #include "decl.h" |
| 20 | #include "dev.h" |
| 21 | #include "scan.h" |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 22 | #include "join.h" |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 23 | #include "cmd.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 24 | |
| 25 | //! Approximate amount of data needed to pass a scan result back to iwlist |
| 26 | #define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \ |
| 27 | + IW_ESSID_MAX_SIZE \ |
| 28 | + IW_EV_UINT_LEN \ |
| 29 | + IW_EV_FREQ_LEN \ |
| 30 | + IW_EV_QUAL_LEN \ |
| 31 | + IW_ESSID_MAX_SIZE \ |
| 32 | + IW_EV_PARAM_LEN \ |
| 33 | + 40) /* 40 for WPAIE */ |
| 34 | |
| 35 | //! Memory needed to store a max sized channel List TLV for a firmware scan |
| 36 | #define CHAN_TLV_MAX_SIZE (sizeof(struct mrvlietypesheader) \ |
| 37 | + (MRVDRV_MAX_CHANNELS_PER_SCAN \ |
| 38 | * sizeof(struct chanscanparamset))) |
| 39 | |
| 40 | //! Memory needed to store a max number/size SSID TLV for a firmware scan |
| 41 | #define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvlietypes_ssidparamset)) |
| 42 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 43 | //! Maximum memory needed for a cmd_ds_802_11_scan with all TLVs at max |
| 44 | #define MAX_SCAN_CFG_ALLOC (sizeof(struct cmd_ds_802_11_scan) \ |
| 45 | + CHAN_TLV_MAX_SIZE + SSID_TLV_MAX_SIZE) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 46 | |
| 47 | //! The maximum number of channels the firmware can scan per command |
| 48 | #define MRVDRV_MAX_CHANNELS_PER_SCAN 14 |
| 49 | |
| 50 | /** |
| 51 | * @brief Number of channels to scan per firmware scan command issuance. |
| 52 | * |
| 53 | * Number restricted to prevent hitting the limit on the amount of scan data |
| 54 | * returned in a single firmware scan command. |
| 55 | */ |
| 56 | #define MRVDRV_CHANNELS_PER_SCAN_CMD 4 |
| 57 | |
| 58 | //! Scan time specified in the channel TLV for each channel for passive scans |
| 59 | #define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100 |
| 60 | |
| 61 | //! Scan time specified in the channel TLV for each channel for active scans |
| 62 | #define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100 |
| 63 | |
Dan Williams | 123e0e0 | 2007-05-25 23:23:43 -0400 | [diff] [blame] | 64 | static const u8 zeromac[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 65 | static const u8 bcastmac[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 66 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 67 | static int lbs_ret_80211_scan(struct lbs_private *priv, unsigned long dummy, |
| 68 | struct cmd_header *resp); |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 69 | |
| 70 | /*********************************************************************/ |
| 71 | /* */ |
| 72 | /* Misc helper functions */ |
| 73 | /* */ |
| 74 | /*********************************************************************/ |
| 75 | |
Holger Schurig | 23ff503 | 2008-01-28 17:27:03 +0100 | [diff] [blame] | 76 | /** |
| 77 | * @brief Unsets the MSB on basic rates |
| 78 | * |
| 79 | * Scan through an array and unset the MSB for basic data rates. |
| 80 | * |
| 81 | * @param rates buffer of data rates |
| 82 | * @param len size of buffer |
| 83 | */ |
| 84 | static void lbs_unset_basic_rate_flags(u8 *rates, size_t len) |
| 85 | { |
| 86 | int i; |
| 87 | |
| 88 | for (i = 0; i < len; i++) |
| 89 | rates[i] &= 0x7f; |
| 90 | } |
| 91 | |
| 92 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 93 | static inline void clear_bss_descriptor (struct bss_descriptor * bss) |
| 94 | { |
| 95 | /* Don't blow away ->list, just BSS data */ |
| 96 | memset(bss, 0, offsetof(struct bss_descriptor, list)); |
| 97 | } |
| 98 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 99 | /** |
| 100 | * @brief Compare two SSIDs |
| 101 | * |
| 102 | * @param ssid1 A pointer to ssid to compare |
| 103 | * @param ssid2 A pointer to ssid to compare |
| 104 | * |
| 105 | * @return 0: ssid is same, otherwise is different |
| 106 | */ |
| 107 | int lbs_ssid_cmp(u8 *ssid1, u8 ssid1_len, u8 *ssid2, u8 ssid2_len) |
| 108 | { |
| 109 | if (ssid1_len != ssid2_len) |
| 110 | return -1; |
| 111 | |
| 112 | return memcmp(ssid1, ssid2, ssid1_len); |
| 113 | } |
| 114 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 115 | static inline int match_bss_no_security(struct lbs_802_11_security *secinfo, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 116 | struct bss_descriptor * match_bss) |
| 117 | { |
| 118 | if ( !secinfo->wep_enabled |
| 119 | && !secinfo->WPAenabled |
| 120 | && !secinfo->WPA2enabled |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 121 | && match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC |
| 122 | && match_bss->rsn_ie[0] != MFIE_TYPE_RSN |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 123 | && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY)) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 124 | return 1; |
| 125 | } |
| 126 | return 0; |
| 127 | } |
| 128 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 129 | static inline int match_bss_static_wep(struct lbs_802_11_security *secinfo, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 130 | struct bss_descriptor * match_bss) |
| 131 | { |
| 132 | if ( secinfo->wep_enabled |
| 133 | && !secinfo->WPAenabled |
| 134 | && !secinfo->WPA2enabled |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 135 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 136 | return 1; |
| 137 | } |
| 138 | return 0; |
| 139 | } |
| 140 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 141 | static inline int match_bss_wpa(struct lbs_802_11_security *secinfo, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 142 | struct bss_descriptor * match_bss) |
| 143 | { |
| 144 | if ( !secinfo->wep_enabled |
| 145 | && secinfo->WPAenabled |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 146 | && (match_bss->wpa_ie[0] == MFIE_TYPE_GENERIC) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 147 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 148 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) { |
| 149 | */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 150 | ) { |
| 151 | return 1; |
| 152 | } |
| 153 | return 0; |
| 154 | } |
| 155 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 156 | static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 157 | struct bss_descriptor * match_bss) |
| 158 | { |
| 159 | if ( !secinfo->wep_enabled |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 160 | && secinfo->WPA2enabled |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 161 | && (match_bss->rsn_ie[0] == MFIE_TYPE_RSN) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 162 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 163 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) { |
| 164 | */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 165 | ) { |
| 166 | return 1; |
| 167 | } |
| 168 | return 0; |
| 169 | } |
| 170 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 171 | static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 172 | struct bss_descriptor * match_bss) |
| 173 | { |
| 174 | if ( !secinfo->wep_enabled |
| 175 | && !secinfo->WPAenabled |
| 176 | && !secinfo->WPA2enabled |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 177 | && (match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC) |
| 178 | && (match_bss->rsn_ie[0] != MFIE_TYPE_RSN) |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 179 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 180 | return 1; |
| 181 | } |
| 182 | return 0; |
| 183 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 184 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 185 | static inline int is_same_network(struct bss_descriptor *src, |
| 186 | struct bss_descriptor *dst) |
| 187 | { |
| 188 | /* A network is only a duplicate if the channel, BSSID, and ESSID |
| 189 | * all match. We treat all <hidden> with the same BSSID and channel |
| 190 | * as one network */ |
| 191 | return ((src->ssid_len == dst->ssid_len) && |
| 192 | (src->channel == dst->channel) && |
| 193 | !compare_ether_addr(src->bssid, dst->bssid) && |
| 194 | !memcmp(src->ssid, dst->ssid, src->ssid_len)); |
| 195 | } |
| 196 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 197 | /** |
| 198 | * @brief Check if a scanned network compatible with the driver settings |
| 199 | * |
| 200 | * WEP WPA WPA2 ad-hoc encrypt Network |
| 201 | * enabled enabled enabled AES mode privacy WPA WPA2 Compatible |
| 202 | * 0 0 0 0 NONE 0 0 0 yes No security |
| 203 | * 1 0 0 0 NONE 1 0 0 yes Static WEP |
| 204 | * 0 1 0 0 x 1x 1 x yes WPA |
| 205 | * 0 0 1 0 x 1x x 1 yes WPA2 |
| 206 | * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES |
| 207 | * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP |
| 208 | * |
| 209 | * |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 210 | * @param priv A pointer to struct lbs_private |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 211 | * @param index Index in scantable to check against current driver settings |
| 212 | * @param mode Network mode: Infrastructure or IBSS |
| 213 | * |
| 214 | * @return Index in scantable, or error code if negative |
| 215 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 216 | static int is_network_compatible(struct lbs_private *priv, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 217 | struct bss_descriptor * bss, u8 mode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 218 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 219 | int matched = 0; |
| 220 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 221 | lbs_deb_enter(LBS_DEB_SCAN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 222 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 223 | if (bss->mode != mode) |
| 224 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 225 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 226 | if ((matched = match_bss_no_security(&priv->secinfo, bss))) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 227 | goto done; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 228 | } else if ((matched = match_bss_static_wep(&priv->secinfo, bss))) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 229 | goto done; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 230 | } else if ((matched = match_bss_wpa(&priv->secinfo, bss))) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 231 | lbs_deb_scan( |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 232 | "is_network_compatible() WPA: wpa_ie 0x%x " |
| 233 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s " |
| 234 | "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0], |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 235 | priv->secinfo.wep_enabled ? "e" : "d", |
| 236 | priv->secinfo.WPAenabled ? "e" : "d", |
| 237 | priv->secinfo.WPA2enabled ? "e" : "d", |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 238 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 239 | goto done; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 240 | } else if ((matched = match_bss_wpa2(&priv->secinfo, bss))) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 241 | lbs_deb_scan( |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 242 | "is_network_compatible() WPA2: wpa_ie 0x%x " |
| 243 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s " |
| 244 | "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0], |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 245 | priv->secinfo.wep_enabled ? "e" : "d", |
| 246 | priv->secinfo.WPAenabled ? "e" : "d", |
| 247 | priv->secinfo.WPA2enabled ? "e" : "d", |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 248 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 249 | goto done; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 250 | } else if ((matched = match_bss_dynamic_wep(&priv->secinfo, bss))) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 251 | lbs_deb_scan( |
| 252 | "is_network_compatible() dynamic WEP: " |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 253 | "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n", |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 254 | bss->wpa_ie[0], bss->rsn_ie[0], |
| 255 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 256 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 257 | } |
| 258 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 259 | /* bss security settings don't match those configured on card */ |
| 260 | lbs_deb_scan( |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 261 | "is_network_compatible() FAILED: wpa_ie 0x%x " |
| 262 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n", |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 263 | bss->wpa_ie[0], bss->rsn_ie[0], |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 264 | priv->secinfo.wep_enabled ? "e" : "d", |
| 265 | priv->secinfo.WPAenabled ? "e" : "d", |
| 266 | priv->secinfo.WPA2enabled ? "e" : "d", |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 267 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 268 | |
| 269 | done: |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 270 | lbs_deb_leave_args(LBS_DEB_SCAN, "matched: %d", matched); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 271 | return matched; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 272 | } |
| 273 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 274 | |
| 275 | |
| 276 | |
| 277 | /*********************************************************************/ |
| 278 | /* */ |
| 279 | /* Main scanning support */ |
| 280 | /* */ |
| 281 | /*********************************************************************/ |
| 282 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 283 | void lbs_scan_worker(struct work_struct *work) |
| 284 | { |
| 285 | struct lbs_private *priv = |
| 286 | container_of(work, struct lbs_private, scan_work.work); |
| 287 | |
| 288 | lbs_deb_enter(LBS_DEB_SCAN); |
| 289 | lbs_scan_networks(priv, NULL, 0); |
| 290 | lbs_deb_leave(LBS_DEB_SCAN); |
| 291 | } |
| 292 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 293 | |
| 294 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 295 | * @brief Create a channel list for the driver to scan based on region info |
| 296 | * |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 297 | * Only used from lbs_scan_setup_scan_config() |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 298 | * |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 299 | * Use the driver region/band information to construct a comprehensive list |
| 300 | * of channels to scan. This routine is used for any scan that is not |
| 301 | * provided a specific channel list to scan. |
| 302 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 303 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 304 | * @param scanchanlist Output parameter: resulting channel list to scan |
| 305 | * @param filteredscan Flag indicating whether or not a BSSID or SSID filter |
| 306 | * is being sent in the command to firmware. Used to |
| 307 | * increase the number of channels sent in a scan |
| 308 | * command and to disable the firmware channel scan |
| 309 | * filter. |
| 310 | * |
| 311 | * @return void |
| 312 | */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 313 | static int lbs_scan_create_channel_list(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 314 | struct chanscanparamset * scanchanlist, |
| 315 | u8 filteredscan) |
| 316 | { |
| 317 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 318 | struct region_channel *scanregion; |
| 319 | struct chan_freq_power *cfp; |
| 320 | int rgnidx; |
| 321 | int chanidx; |
| 322 | int nextchan; |
| 323 | u8 scantype; |
| 324 | |
| 325 | chanidx = 0; |
| 326 | |
| 327 | /* Set the default scan type to the user specified type, will later |
| 328 | * be changed to passive on a per channel basis if restricted by |
| 329 | * regulatory requirements (11d or 11h) |
| 330 | */ |
Holger Schurig | 4f2fdaa | 2007-08-02 13:12:27 -0400 | [diff] [blame] | 331 | scantype = CMD_SCAN_TYPE_ACTIVE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 332 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 333 | for (rgnidx = 0; rgnidx < ARRAY_SIZE(priv->region_channel); rgnidx++) { |
| 334 | if (priv->enable11d && |
| 335 | (priv->connect_status != LBS_CONNECTED) && |
| 336 | (priv->mesh_connect_status != LBS_CONNECTED)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 337 | /* Scan all the supported chan for the first scan */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 338 | if (!priv->universal_channel[rgnidx].valid) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 339 | continue; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 340 | scanregion = &priv->universal_channel[rgnidx]; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 341 | |
| 342 | /* clear the parsed_region_chan for the first scan */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 343 | memset(&priv->parsed_region_chan, 0x00, |
| 344 | sizeof(priv->parsed_region_chan)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 345 | } else { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 346 | if (!priv->region_channel[rgnidx].valid) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 347 | continue; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 348 | scanregion = &priv->region_channel[rgnidx]; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | for (nextchan = 0; |
| 352 | nextchan < scanregion->nrcfp; nextchan++, chanidx++) { |
| 353 | |
| 354 | cfp = scanregion->CFP + nextchan; |
| 355 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 356 | if (priv->enable11d) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 357 | scantype = |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 358 | lbs_get_scan_type_11d(cfp->channel, |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 359 | &priv-> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 360 | parsed_region_chan); |
| 361 | } |
| 362 | |
| 363 | switch (scanregion->band) { |
| 364 | case BAND_B: |
| 365 | case BAND_G: |
| 366 | default: |
| 367 | scanchanlist[chanidx].radiotype = |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 368 | CMD_SCAN_RADIO_TYPE_BG; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 369 | break; |
| 370 | } |
| 371 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 372 | if (scantype == CMD_SCAN_TYPE_PASSIVE) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 373 | scanchanlist[chanidx].maxscantime = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 374 | cpu_to_le16(MRVDRV_PASSIVE_SCAN_CHAN_TIME); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 375 | scanchanlist[chanidx].chanscanmode.passivescan = |
| 376 | 1; |
| 377 | } else { |
| 378 | scanchanlist[chanidx].maxscantime = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 379 | cpu_to_le16(MRVDRV_ACTIVE_SCAN_CHAN_TIME); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 380 | scanchanlist[chanidx].chanscanmode.passivescan = |
| 381 | 0; |
| 382 | } |
| 383 | |
| 384 | scanchanlist[chanidx].channumber = cfp->channel; |
| 385 | |
| 386 | if (filteredscan) { |
| 387 | scanchanlist[chanidx].chanscanmode. |
| 388 | disablechanfilt = 1; |
| 389 | } |
| 390 | } |
| 391 | } |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 392 | return chanidx; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 393 | } |
| 394 | |
Dan Williams | 2afc0c5 | 2007-08-02 13:19:04 -0400 | [diff] [blame] | 395 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 396 | /* |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 397 | * Add SSID TLV of the form: |
| 398 | * |
| 399 | * TLV-ID SSID 00 00 |
| 400 | * length 06 00 |
| 401 | * ssid 4d 4e 54 45 53 54 |
| 402 | */ |
| 403 | static int lbs_scan_add_ssid_tlv(u8 *tlv, |
| 404 | const struct lbs_ioctl_user_scan_cfg *user_cfg) |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 405 | { |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 406 | struct mrvlietypes_ssidparamset *ssid_tlv = |
| 407 | (struct mrvlietypes_ssidparamset *)tlv; |
| 408 | ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID); |
| 409 | ssid_tlv->header.len = cpu_to_le16(user_cfg->ssid_len); |
| 410 | memcpy(ssid_tlv->ssid, user_cfg->ssid, user_cfg->ssid_len); |
| 411 | return sizeof(ssid_tlv->header) + user_cfg->ssid_len; |
| 412 | } |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 413 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 414 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 415 | /* |
| 416 | * Add CHANLIST TLV of the form |
| 417 | * |
| 418 | * TLV-ID CHANLIST 01 01 |
| 419 | * length 5b 00 |
| 420 | * channel 1 00 01 00 00 00 64 00 |
| 421 | * radio type 00 |
| 422 | * channel 01 |
| 423 | * scan type 00 |
| 424 | * min scan time 00 00 |
| 425 | * max scan time 64 00 |
| 426 | * channel 2 00 02 00 00 00 64 00 |
| 427 | * channel 3 00 03 00 00 00 64 00 |
| 428 | * channel 4 00 04 00 00 00 64 00 |
| 429 | * channel 5 00 05 00 00 00 64 00 |
| 430 | * channel 6 00 06 00 00 00 64 00 |
| 431 | * channel 7 00 07 00 00 00 64 00 |
| 432 | * channel 8 00 08 00 00 00 64 00 |
| 433 | * channel 9 00 09 00 00 00 64 00 |
| 434 | * channel 10 00 0a 00 00 00 64 00 |
| 435 | * channel 11 00 0b 00 00 00 64 00 |
| 436 | * channel 12 00 0c 00 00 00 64 00 |
| 437 | * channel 13 00 0d 00 00 00 64 00 |
| 438 | * |
| 439 | */ |
| 440 | static int lbs_scan_add_chanlist_tlv(u8 *tlv, |
| 441 | struct chanscanparamset *chan_list, |
| 442 | int chan_count) |
| 443 | { |
| 444 | size_t size = sizeof(struct chanscanparamset) * chan_count; |
| 445 | struct mrvlietypes_chanlistparamset *chan_tlv = |
| 446 | (struct mrvlietypes_chanlistparamset *) tlv; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 447 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 448 | chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); |
| 449 | memcpy(chan_tlv->chanscanparam, chan_list, size); |
| 450 | chan_tlv->header.len = cpu_to_le16(size); |
| 451 | return sizeof(chan_tlv->header) + size; |
| 452 | } |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 453 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 454 | |
| 455 | /* |
| 456 | * Add RATES TLV of the form |
| 457 | * |
| 458 | * TLV-ID RATES 01 00 |
| 459 | * length 0e 00 |
| 460 | * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c |
| 461 | * |
| 462 | * The rates are in lbs_bg_rates[], but for the 802.11b |
| 463 | * rates the high bit isn't set. |
| 464 | */ |
| 465 | static int lbs_scan_add_rates_tlv(u8 *tlv) |
| 466 | { |
| 467 | int i; |
| 468 | struct mrvlietypes_ratesparamset *rate_tlv = |
| 469 | (struct mrvlietypes_ratesparamset *) tlv; |
| 470 | |
| 471 | rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES); |
| 472 | tlv += sizeof(rate_tlv->header); |
| 473 | for (i = 0; i < MAX_RATES; i++) { |
| 474 | *tlv = lbs_bg_rates[i]; |
| 475 | if (*tlv == 0) |
| 476 | break; |
| 477 | /* This code makes sure that the 802.11b rates (1 MBit/s, 2 |
| 478 | MBit/s, 5.5 MBit/s and 11 MBit/s get's the high bit set. |
| 479 | Note that the values are MBit/s * 2, to mark them as |
| 480 | basic rates so that the firmware likes it better */ |
| 481 | if (*tlv == 0x02 || *tlv == 0x04 || |
| 482 | *tlv == 0x0b || *tlv == 0x16) |
| 483 | *tlv |= 0x80; |
| 484 | tlv++; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 485 | } |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 486 | rate_tlv->header.len = cpu_to_le16(i); |
| 487 | return sizeof(rate_tlv->header) + i; |
| 488 | } |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 489 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 490 | |
| 491 | /* |
| 492 | * Generate the CMD_802_11_SCAN command with the proper tlv |
| 493 | * for a bunch of channels. |
| 494 | */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 495 | static int lbs_do_scan(struct lbs_private *priv, uint8_t bsstype, |
| 496 | struct chanscanparamset *chan_list, int chan_count, |
| 497 | const struct lbs_ioctl_user_scan_cfg *user_cfg) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 498 | { |
| 499 | int ret = -ENOMEM; |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 500 | struct cmd_ds_802_11_scan *scan_cmd; |
| 501 | uint8_t *tlv; /* pointer into our current, growing TLV storage area */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 502 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 503 | lbs_deb_enter_args(LBS_DEB_SCAN, "bsstype %d, chanlist[].chan %d, chan_count %d", |
| 504 | bsstype, chan_list[0].channumber, chan_count); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 505 | |
| 506 | /* create the fixed part for scan command */ |
| 507 | scan_cmd = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL); |
| 508 | if (scan_cmd == NULL) |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 509 | goto out; |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 510 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 511 | tlv = scan_cmd->tlvbuffer; |
| 512 | if (user_cfg) |
| 513 | memcpy(scan_cmd->bssid, user_cfg->bssid, ETH_ALEN); |
| 514 | scan_cmd->bsstype = bsstype; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 515 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 516 | /* add TLVs */ |
| 517 | if (user_cfg && user_cfg->ssid_len) |
| 518 | tlv += lbs_scan_add_ssid_tlv(tlv, user_cfg); |
| 519 | if (chan_list && chan_count) |
| 520 | tlv += lbs_scan_add_chanlist_tlv(tlv, chan_list, chan_count); |
| 521 | tlv += lbs_scan_add_rates_tlv(tlv); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 522 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 523 | /* This is the final data we are about to send */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 524 | scan_cmd->hdr.size = cpu_to_le16(tlv - (uint8_t *)scan_cmd); |
| 525 | lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd, |
| 526 | sizeof(*scan_cmd)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 527 | lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer, |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 528 | tlv - scan_cmd->tlvbuffer); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 529 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 530 | ret = __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr, |
| 531 | le16_to_cpu(scan_cmd->hdr.size), |
| 532 | lbs_ret_80211_scan, 0); |
| 533 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 534 | out: |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 535 | kfree(scan_cmd); |
| 536 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 537 | return ret; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 541 | /** |
| 542 | * @brief Internal function used to start a scan based on an input config |
| 543 | * |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 544 | * Also used from debugfs |
| 545 | * |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 546 | * Use the input user scan configuration information when provided in |
| 547 | * order to send the appropriate scan commands to firmware to populate or |
| 548 | * update the internal driver scan table |
| 549 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 550 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 551 | * @param puserscanin Pointer to the input configuration for the requested |
| 552 | * scan. |
| 553 | * |
| 554 | * @return 0 or < 0 if error |
| 555 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 556 | int lbs_scan_networks(struct lbs_private *priv, |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 557 | const struct lbs_ioctl_user_scan_cfg *user_cfg, |
Dan Williams | 2afc0c5 | 2007-08-02 13:19:04 -0400 | [diff] [blame] | 558 | int full_scan) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 559 | { |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 560 | int ret = -ENOMEM; |
| 561 | struct chanscanparamset *chan_list; |
| 562 | struct chanscanparamset *curr_chans; |
| 563 | int chan_count; |
| 564 | u8 bsstype = CMD_BSS_TYPE_ANY; |
| 565 | int numchannels = MRVDRV_CHANNELS_PER_SCAN_CMD; |
| 566 | int filteredscan = 0; |
| 567 | union iwreq_data wrqu; |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 568 | #ifdef CONFIG_LIBERTAS_DEBUG |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 569 | struct bss_descriptor *iter; |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 570 | int i = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 571 | DECLARE_MAC_BUF(mac); |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 572 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 573 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 574 | lbs_deb_enter_args(LBS_DEB_SCAN, "full_scan %d", |
| 575 | full_scan); |
Dan Williams | 2afc0c5 | 2007-08-02 13:19:04 -0400 | [diff] [blame] | 576 | |
| 577 | /* Cancel any partial outstanding partial scans if this scan |
| 578 | * is a full scan. |
| 579 | */ |
| 580 | if (full_scan && delayed_work_pending(&priv->scan_work)) |
| 581 | cancel_delayed_work(&priv->scan_work); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 582 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 583 | /* Determine same scan parameters */ |
| 584 | if (user_cfg) { |
| 585 | if (user_cfg->bsstype) |
| 586 | bsstype = user_cfg->bsstype; |
| 587 | if (compare_ether_addr(user_cfg->bssid, &zeromac[0]) != 0) { |
| 588 | numchannels = MRVDRV_MAX_CHANNELS_PER_SCAN; |
| 589 | filteredscan = 1; |
Holger Schurig | 3cf8409 | 2007-08-02 11:50:12 -0400 | [diff] [blame] | 590 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 591 | } |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 592 | lbs_deb_scan("numchannels %d, bsstype %d, " |
| 593 | "filteredscan %d\n", |
| 594 | numchannels, bsstype, filteredscan); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 595 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 596 | /* Create list of channels to scan */ |
| 597 | chan_list = kzalloc(sizeof(struct chanscanparamset) * |
| 598 | LBS_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL); |
| 599 | if (!chan_list) { |
| 600 | lbs_pr_alert("SCAN: chan_list empty\n"); |
| 601 | goto out; |
| 602 | } |
| 603 | |
| 604 | /* We want to scan all channels */ |
| 605 | chan_count = lbs_scan_create_channel_list(priv, chan_list, |
| 606 | filteredscan); |
| 607 | |
| 608 | netif_stop_queue(priv->dev); |
| 609 | netif_carrier_off(priv->dev); |
| 610 | if (priv->mesh_dev) { |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 611 | netif_stop_queue(priv->mesh_dev); |
| 612 | netif_carrier_off(priv->mesh_dev); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /* Prepare to continue an interrupted scan */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 616 | lbs_deb_scan("chan_count %d, scan_channel %d\n", |
| 617 | chan_count, priv->scan_channel); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 618 | curr_chans = chan_list; |
| 619 | /* advance channel list by already-scanned-channels */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 620 | if (priv->scan_channel > 0) { |
| 621 | curr_chans += priv->scan_channel; |
| 622 | chan_count -= priv->scan_channel; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /* Send scan command(s) |
| 626 | * numchannels contains the number of channels we should maximally scan |
| 627 | * chan_count is the total number of channels to scan |
| 628 | */ |
| 629 | |
| 630 | while (chan_count) { |
| 631 | int to_scan = min(numchannels, chan_count); |
| 632 | lbs_deb_scan("scanning %d of %d channels\n", |
| 633 | to_scan, chan_count); |
| 634 | ret = lbs_do_scan(priv, bsstype, curr_chans, |
| 635 | to_scan, user_cfg); |
| 636 | if (ret) { |
| 637 | lbs_pr_err("SCAN_CMD failed\n"); |
| 638 | goto out2; |
| 639 | } |
| 640 | curr_chans += to_scan; |
| 641 | chan_count -= to_scan; |
| 642 | |
| 643 | /* somehow schedule the next part of the scan */ |
| 644 | if (chan_count && |
| 645 | !full_scan && |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 646 | !priv->surpriseremoved) { |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 647 | /* -1 marks just that we're currently scanning */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 648 | if (priv->scan_channel < 0) |
| 649 | priv->scan_channel = to_scan; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 650 | else |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 651 | priv->scan_channel += to_scan; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 652 | cancel_delayed_work(&priv->scan_work); |
| 653 | queue_delayed_work(priv->work_thread, &priv->scan_work, |
| 654 | msecs_to_jiffies(300)); |
| 655 | /* skip over GIWSCAN event */ |
| 656 | goto out; |
| 657 | } |
| 658 | |
| 659 | } |
| 660 | memset(&wrqu, 0, sizeof(union iwreq_data)); |
| 661 | wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 662 | |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 663 | #ifdef CONFIG_LIBERTAS_DEBUG |
| 664 | /* Dump the scan table */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 665 | mutex_lock(&priv->lock); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 666 | lbs_deb_scan("scan table:\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 667 | list_for_each_entry(iter, &priv->network_list, list) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 668 | lbs_deb_scan("%02d: BSSID %s, RSSI %d, SSID '%s'\n", |
| 669 | i++, print_mac(mac, iter->bssid), (s32) iter->rssi, |
| 670 | escape_essid(iter->ssid, iter->ssid_len)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 671 | mutex_unlock(&priv->lock); |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 672 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 673 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 674 | out2: |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 675 | priv->scan_channel = 0; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 676 | |
| 677 | out: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 678 | if (priv->connect_status == LBS_CONNECTED) { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 679 | netif_carrier_on(priv->dev); |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 680 | if (!priv->tx_pending_len) |
| 681 | netif_wake_queue(priv->dev); |
Brajesh Dave | 01d77d8 | 2007-11-20 17:44:14 -0500 | [diff] [blame] | 682 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 683 | if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED)) { |
Brajesh Dave | 01d77d8 | 2007-11-20 17:44:14 -0500 | [diff] [blame] | 684 | netif_carrier_on(priv->mesh_dev); |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 685 | if (!priv->tx_pending_len) |
| 686 | netif_wake_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 687 | } |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 688 | kfree(chan_list); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 689 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 690 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 691 | return ret; |
| 692 | } |
| 693 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 694 | |
| 695 | |
| 696 | |
| 697 | /*********************************************************************/ |
| 698 | /* */ |
| 699 | /* Result interpretation */ |
| 700 | /* */ |
| 701 | /*********************************************************************/ |
| 702 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 703 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 704 | * @brief Interpret a BSS scan response returned from the firmware |
| 705 | * |
| 706 | * Parse the various fixed fields and IEs passed back for a a BSS probe |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 707 | * response or beacon from the scan command. Record information as needed |
| 708 | * in the scan table struct bss_descriptor for that entry. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 709 | * |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 710 | * @param bss Output parameter: Pointer to the BSS Entry |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 711 | * |
| 712 | * @return 0 or -1 |
| 713 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 714 | static int lbs_process_bss(struct bss_descriptor *bss, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 715 | u8 ** pbeaconinfo, int *bytesleft) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 716 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 717 | struct ieeetypes_fhparamset *pFH; |
| 718 | struct ieeetypes_dsparamset *pDS; |
| 719 | struct ieeetypes_cfparamset *pCF; |
| 720 | struct ieeetypes_ibssparamset *pibss; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 721 | DECLARE_MAC_BUF(mac); |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 722 | struct ieeetypes_countryinfoset *pcountryinfo; |
| 723 | u8 *pos, *end, *p; |
| 724 | u8 n_ex_rates = 0, got_basic_rates = 0, n_basic_rates = 0; |
| 725 | u16 beaconsize = 0; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 726 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 727 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 728 | lbs_deb_enter(LBS_DEB_SCAN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 729 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 730 | if (*bytesleft >= sizeof(beaconsize)) { |
| 731 | /* Extract & convert beacon size from the command buffer */ |
David Woodhouse | e7240ac | 2007-12-11 17:54:36 -0500 | [diff] [blame] | 732 | beaconsize = le16_to_cpu(get_unaligned((__le16 *)*pbeaconinfo)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 733 | *bytesleft -= sizeof(beaconsize); |
| 734 | *pbeaconinfo += sizeof(beaconsize); |
| 735 | } |
| 736 | |
| 737 | if (beaconsize == 0 || beaconsize > *bytesleft) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 738 | *pbeaconinfo += *bytesleft; |
| 739 | *bytesleft = 0; |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 740 | ret = -1; |
| 741 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /* Initialize the current working beacon pointer for this BSS iteration */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 745 | pos = *pbeaconinfo; |
| 746 | end = pos + beaconsize; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 747 | |
| 748 | /* Advance the return beacon pointer past the current beacon */ |
| 749 | *pbeaconinfo += beaconsize; |
| 750 | *bytesleft -= beaconsize; |
| 751 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 752 | memcpy(bss->bssid, pos, ETH_ALEN); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 753 | lbs_deb_scan("process_bss: BSSID %s\n", print_mac(mac, bss->bssid)); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 754 | pos += ETH_ALEN; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 755 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 756 | if ((end - pos) < 12) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 757 | lbs_deb_scan("process_bss: Not enough bytes left\n"); |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 758 | ret = -1; |
| 759 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /* |
| 763 | * next 4 fields are RSSI, time stamp, beacon interval, |
| 764 | * and capability information |
| 765 | */ |
| 766 | |
| 767 | /* RSSI is 1 byte long */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 768 | bss->rssi = *pos; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 769 | lbs_deb_scan("process_bss: RSSI %d\n", *pos); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 770 | pos++; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 771 | |
| 772 | /* time stamp is 8 bytes long */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 773 | pos += 8; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 774 | |
| 775 | /* beacon interval is 2 bytes long */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 776 | bss->beaconperiod = le16_to_cpup((void *) pos); |
| 777 | pos += 2; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 778 | |
| 779 | /* capability information is 2 bytes long */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 780 | bss->capability = le16_to_cpup((void *) pos); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 781 | lbs_deb_scan("process_bss: capabilities 0x%04x\n", bss->capability); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 782 | pos += 2; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 783 | |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 784 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 785 | lbs_deb_scan("process_bss: WEP enabled\n"); |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 786 | if (bss->capability & WLAN_CAPABILITY_IBSS) |
| 787 | bss->mode = IW_MODE_ADHOC; |
| 788 | else |
| 789 | bss->mode = IW_MODE_INFRA; |
| 790 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 791 | /* rest of the current buffer are IE's */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 792 | lbs_deb_scan("process_bss: IE len %zd\n", end - pos); |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 793 | lbs_deb_hex(LBS_DEB_SCAN, "process_bss: IE info", pos, end - pos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 794 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 795 | /* process variable IE */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 796 | while (pos <= end - 2) { |
| 797 | struct ieee80211_info_element * elem = |
| 798 | (struct ieee80211_info_element *) pos; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 799 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 800 | if (pos + elem->len > end) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 801 | lbs_deb_scan("process_bss: error in processing IE, " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 802 | "bytes left < IE length\n"); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 803 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 804 | } |
| 805 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 806 | switch (elem->id) { |
| 807 | case MFIE_TYPE_SSID: |
| 808 | bss->ssid_len = elem->len; |
| 809 | memcpy(bss->ssid, elem->data, elem->len); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 810 | lbs_deb_scan("got SSID IE: '%s', len %u\n", |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 811 | escape_essid(bss->ssid, bss->ssid_len), |
| 812 | bss->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 813 | break; |
| 814 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 815 | case MFIE_TYPE_RATES: |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 816 | n_basic_rates = min_t(u8, MAX_RATES, elem->len); |
| 817 | memcpy(bss->rates, elem->data, n_basic_rates); |
| 818 | got_basic_rates = 1; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 819 | lbs_deb_scan("got RATES IE\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 820 | break; |
| 821 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 822 | case MFIE_TYPE_FH_SET: |
| 823 | pFH = (struct ieeetypes_fhparamset *) pos; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 824 | memmove(&bss->phyparamset.fhparamset, pFH, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 825 | sizeof(struct ieeetypes_fhparamset)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 826 | lbs_deb_scan("got FH IE\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 827 | break; |
| 828 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 829 | case MFIE_TYPE_DS_SET: |
| 830 | pDS = (struct ieeetypes_dsparamset *) pos; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 831 | bss->channel = pDS->currentchan; |
| 832 | memcpy(&bss->phyparamset.dsparamset, pDS, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 833 | sizeof(struct ieeetypes_dsparamset)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 834 | lbs_deb_scan("got DS IE, channel %d\n", bss->channel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 835 | break; |
| 836 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 837 | case MFIE_TYPE_CF_SET: |
| 838 | pCF = (struct ieeetypes_cfparamset *) pos; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 839 | memcpy(&bss->ssparamset.cfparamset, pCF, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 840 | sizeof(struct ieeetypes_cfparamset)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 841 | lbs_deb_scan("got CF IE\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 842 | break; |
| 843 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 844 | case MFIE_TYPE_IBSS_SET: |
| 845 | pibss = (struct ieeetypes_ibssparamset *) pos; |
David Woodhouse | e7240ac | 2007-12-11 17:54:36 -0500 | [diff] [blame] | 846 | bss->atimwindow = le16_to_cpu(pibss->atimwindow); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 847 | memmove(&bss->ssparamset.ibssparamset, pibss, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 848 | sizeof(struct ieeetypes_ibssparamset)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 849 | lbs_deb_scan("got IBSS IE\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 850 | break; |
| 851 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 852 | case MFIE_TYPE_COUNTRY: |
| 853 | pcountryinfo = (struct ieeetypes_countryinfoset *) pos; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 854 | lbs_deb_scan("got COUNTRY IE\n"); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 855 | if (pcountryinfo->len < sizeof(pcountryinfo->countrycode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 856 | || pcountryinfo->len > 254) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 857 | lbs_deb_scan("process_bss: 11D- Err " |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 858 | "CountryInfo len %d, min %zd, max 254\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 859 | pcountryinfo->len, |
| 860 | sizeof(pcountryinfo->countrycode)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 861 | ret = -1; |
| 862 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 863 | } |
| 864 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 865 | memcpy(&bss->countryinfo, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 866 | pcountryinfo, pcountryinfo->len + 2); |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 867 | lbs_deb_hex(LBS_DEB_SCAN, "process_bss: 11d countryinfo", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 868 | (u8 *) pcountryinfo, |
| 869 | (u32) (pcountryinfo->len + 2)); |
| 870 | break; |
| 871 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 872 | case MFIE_TYPE_RATES_EX: |
| 873 | /* only process extended supported rate if data rate is |
| 874 | * already found. Data rate IE should come before |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 875 | * extended supported rate IE |
| 876 | */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 877 | lbs_deb_scan("got RATESEX IE\n"); |
| 878 | if (!got_basic_rates) { |
| 879 | lbs_deb_scan("... but ignoring it\n"); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 880 | break; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 881 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 882 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 883 | n_ex_rates = elem->len; |
| 884 | if (n_basic_rates + n_ex_rates > MAX_RATES) |
| 885 | n_ex_rates = MAX_RATES - n_basic_rates; |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 886 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 887 | p = bss->rates + n_basic_rates; |
| 888 | memcpy(p, elem->data, n_ex_rates); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case MFIE_TYPE_GENERIC: |
| 892 | if (elem->len >= 4 && |
| 893 | elem->data[0] == 0x00 && |
| 894 | elem->data[1] == 0x50 && |
| 895 | elem->data[2] == 0xf2 && |
| 896 | elem->data[3] == 0x01) { |
| 897 | bss->wpa_ie_len = min(elem->len + 2, |
| 898 | MAX_WPA_IE_LEN); |
| 899 | memcpy(bss->wpa_ie, elem, bss->wpa_ie_len); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 900 | lbs_deb_scan("got WPA IE\n"); |
| 901 | lbs_deb_hex(LBS_DEB_SCAN, "WPA IE", bss->wpa_ie, |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 902 | elem->len); |
Luis Carlos Cobo | 1e838bf | 2007-08-02 10:51:27 -0400 | [diff] [blame] | 903 | } else if (elem->len >= MARVELL_MESH_IE_LENGTH && |
| 904 | elem->data[0] == 0x00 && |
| 905 | elem->data[1] == 0x50 && |
| 906 | elem->data[2] == 0x43 && |
| 907 | elem->data[3] == 0x04) { |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 908 | lbs_deb_scan("got mesh IE\n"); |
Luis Carlos Cobo | 1e838bf | 2007-08-02 10:51:27 -0400 | [diff] [blame] | 909 | bss->mesh = 1; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 910 | } else { |
| 911 | lbs_deb_scan("got generiec IE: " |
| 912 | "%02x:%02x:%02x:%02x, len %d\n", |
| 913 | elem->data[0], elem->data[1], |
| 914 | elem->data[2], elem->data[3], |
| 915 | elem->len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 916 | } |
| 917 | break; |
| 918 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 919 | case MFIE_TYPE_RSN: |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 920 | lbs_deb_scan("got RSN IE\n"); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 921 | bss->rsn_ie_len = min(elem->len + 2, MAX_WPA_IE_LEN); |
| 922 | memcpy(bss->rsn_ie, elem, bss->rsn_ie_len); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 923 | lbs_deb_hex(LBS_DEB_SCAN, "process_bss: RSN_IE", |
| 924 | bss->rsn_ie, elem->len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 925 | break; |
| 926 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 927 | default: |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 928 | lbs_deb_scan("got IE 0x%04x, len %d\n", |
| 929 | elem->id, elem->len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 930 | break; |
| 931 | } |
| 932 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 933 | pos += elem->len + 2; |
| 934 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 935 | |
| 936 | /* Timestamp */ |
| 937 | bss->last_scanned = jiffies; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 938 | lbs_unset_basic_rate_flags(bss->rates, sizeof(bss->rates)); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 939 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 940 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 941 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 942 | done: |
| 943 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 944 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 948 | * @brief This function finds a specific compatible BSSID in the scan list |
| 949 | * |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 950 | * Used in association code |
| 951 | * |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 952 | * @param priv A pointer to struct lbs_private |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 953 | * @param bssid BSSID to find in the scan list |
| 954 | * @param mode Network mode: Infrastructure or IBSS |
| 955 | * |
| 956 | * @return index in BSSID list, or error return code (< 0) |
| 957 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 958 | struct bss_descriptor *lbs_find_bssid_in_list(struct lbs_private *priv, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 959 | u8 * bssid, u8 mode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 960 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 961 | struct bss_descriptor * iter_bss; |
| 962 | struct bss_descriptor * found_bss = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 963 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 964 | lbs_deb_enter(LBS_DEB_SCAN); |
| 965 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 966 | if (!bssid) |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 967 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 968 | |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 969 | lbs_deb_hex(LBS_DEB_SCAN, "looking for", |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 970 | bssid, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 971 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 972 | /* Look through the scan table for a compatible match. The loop will |
| 973 | * continue past a matched bssid that is not compatible in case there |
| 974 | * is an AP with multiple SSIDs assigned to the same BSSID |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 975 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 976 | mutex_lock(&priv->lock); |
| 977 | list_for_each_entry (iter_bss, &priv->network_list, list) { |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 978 | if (compare_ether_addr(iter_bss->bssid, bssid)) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 979 | continue; /* bssid doesn't match */ |
| 980 | switch (mode) { |
| 981 | case IW_MODE_INFRA: |
| 982 | case IW_MODE_ADHOC: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 983 | if (!is_network_compatible(priv, iter_bss, mode)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 984 | break; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 985 | found_bss = iter_bss; |
| 986 | break; |
| 987 | default: |
| 988 | found_bss = iter_bss; |
| 989 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 990 | } |
| 991 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 992 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 993 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 994 | out: |
| 995 | lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 996 | return found_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * @brief This function finds ssid in ssid list. |
| 1001 | * |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1002 | * Used in association code |
| 1003 | * |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1004 | * @param priv A pointer to struct lbs_private |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1005 | * @param ssid SSID to find in the list |
| 1006 | * @param bssid BSSID to qualify the SSID selection (if provided) |
| 1007 | * @param mode Network mode: Infrastructure or IBSS |
| 1008 | * |
| 1009 | * @return index in BSSID list |
| 1010 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1011 | struct bss_descriptor *lbs_find_ssid_in_list(struct lbs_private *priv, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1012 | u8 *ssid, u8 ssid_len, u8 * bssid, u8 mode, |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 1013 | int channel) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1014 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1015 | u8 bestrssi = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1016 | struct bss_descriptor * iter_bss = NULL; |
| 1017 | struct bss_descriptor * found_bss = NULL; |
| 1018 | struct bss_descriptor * tmp_oldest = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1019 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1020 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1021 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1022 | mutex_lock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1023 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1024 | list_for_each_entry (iter_bss, &priv->network_list, list) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1025 | if ( !tmp_oldest |
| 1026 | || (iter_bss->last_scanned < tmp_oldest->last_scanned)) |
| 1027 | tmp_oldest = iter_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1028 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1029 | if (lbs_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1030 | ssid, ssid_len) != 0) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1031 | continue; /* ssid doesn't match */ |
Dan Williams | 3cf20931 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 1032 | if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1033 | continue; /* bssid doesn't match */ |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 1034 | if ((channel > 0) && (iter_bss->channel != channel)) |
| 1035 | continue; /* channel doesn't match */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1036 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1037 | switch (mode) { |
| 1038 | case IW_MODE_INFRA: |
| 1039 | case IW_MODE_ADHOC: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1040 | if (!is_network_compatible(priv, iter_bss, mode)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1041 | break; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1042 | |
| 1043 | if (bssid) { |
| 1044 | /* Found requested BSSID */ |
| 1045 | found_bss = iter_bss; |
| 1046 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1047 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1048 | |
| 1049 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { |
| 1050 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1051 | found_bss = iter_bss; |
| 1052 | } |
| 1053 | break; |
| 1054 | case IW_MODE_AUTO: |
| 1055 | default: |
| 1056 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { |
| 1057 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1058 | found_bss = iter_bss; |
| 1059 | } |
| 1060 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1061 | } |
| 1062 | } |
| 1063 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1064 | out: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1065 | mutex_unlock(&priv->lock); |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1066 | lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1067 | return found_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * @brief This function finds the best SSID in the Scan List |
| 1072 | * |
| 1073 | * Search the scan table for the best SSID that also matches the current |
| 1074 | * adapter network preference (infrastructure or adhoc) |
| 1075 | * |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1076 | * @param priv A pointer to struct lbs_private |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1077 | * |
| 1078 | * @return index in BSSID list |
| 1079 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1080 | static struct bss_descriptor *lbs_find_best_ssid_in_list( |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1081 | struct lbs_private *priv, |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1082 | u8 mode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1083 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1084 | u8 bestrssi = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1085 | struct bss_descriptor * iter_bss; |
| 1086 | struct bss_descriptor * best_bss = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1087 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1088 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1089 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1090 | mutex_lock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1091 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1092 | list_for_each_entry (iter_bss, &priv->network_list, list) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1093 | switch (mode) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1094 | case IW_MODE_INFRA: |
| 1095 | case IW_MODE_ADHOC: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1096 | if (!is_network_compatible(priv, iter_bss, mode)) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1097 | break; |
| 1098 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) |
| 1099 | break; |
| 1100 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1101 | best_bss = iter_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1102 | break; |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1103 | case IW_MODE_AUTO: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1104 | default: |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1105 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) |
| 1106 | break; |
| 1107 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1108 | best_bss = iter_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1109 | break; |
| 1110 | } |
| 1111 | } |
| 1112 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1113 | mutex_unlock(&priv->lock); |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1114 | lbs_deb_leave_args(LBS_DEB_SCAN, "best_bss %p", best_bss); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1115 | return best_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /** |
| 1119 | * @brief Find the AP with specific ssid in the scan list |
| 1120 | * |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1121 | * Used from association worker. |
| 1122 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1123 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1124 | * @param pSSID A pointer to AP's ssid |
| 1125 | * |
| 1126 | * @return 0--success, otherwise--fail |
| 1127 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1128 | int lbs_find_best_network_ssid(struct lbs_private *priv, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1129 | u8 *out_ssid, u8 *out_ssid_len, u8 preferred_mode, u8 *out_mode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1130 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1131 | int ret = -1; |
| 1132 | struct bss_descriptor * found; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1133 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1134 | lbs_deb_enter(LBS_DEB_SCAN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1135 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1136 | lbs_scan_networks(priv, NULL, 1); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1137 | if (priv->surpriseremoved) |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1138 | goto out; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1139 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1140 | found = lbs_find_best_ssid_in_list(priv, preferred_mode); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1141 | if (found && (found->ssid_len > 0)) { |
| 1142 | memcpy(out_ssid, &found->ssid, IW_ESSID_MAX_SIZE); |
| 1143 | *out_ssid_len = found->ssid_len; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1144 | *out_mode = found->mode; |
| 1145 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1146 | } |
| 1147 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1148 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1149 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1150 | return ret; |
| 1151 | } |
| 1152 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1153 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1154 | /** |
| 1155 | * @brief Send a scan command for all available channels filtered on a spec |
| 1156 | * |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1157 | * Used in association code and from debugfs |
| 1158 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1159 | * @param priv A pointer to struct lbs_private structure |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1160 | * @param ssid A pointer to the SSID to scan for |
| 1161 | * @param ssid_len Length of the SSID |
| 1162 | * @param clear_ssid Should existing scan results with this SSID |
| 1163 | * be cleared? |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1164 | * |
| 1165 | * @return 0-success, otherwise fail |
| 1166 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1167 | int lbs_send_specific_ssid_scan(struct lbs_private *priv, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1168 | u8 *ssid, u8 ssid_len, u8 clear_ssid) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1169 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1170 | struct lbs_ioctl_user_scan_cfg scancfg; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1171 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1172 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1173 | lbs_deb_enter_args(LBS_DEB_SCAN, "SSID '%s', clear %d", |
| 1174 | escape_essid(ssid, ssid_len), clear_ssid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1175 | |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1176 | if (!ssid_len) |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1177 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1178 | |
| 1179 | memset(&scancfg, 0x00, sizeof(scancfg)); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1180 | memcpy(scancfg.ssid, ssid, ssid_len); |
| 1181 | scancfg.ssid_len = ssid_len; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1182 | scancfg.clear_ssid = clear_ssid; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1183 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1184 | lbs_scan_networks(priv, &scancfg, 1); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1185 | if (priv->surpriseremoved) { |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1186 | ret = -1; |
| 1187 | goto out; |
| 1188 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1189 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1190 | out: |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1191 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1192 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1193 | } |
| 1194 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1195 | |
| 1196 | |
| 1197 | |
| 1198 | /*********************************************************************/ |
| 1199 | /* */ |
| 1200 | /* Support for Wireless Extensions */ |
| 1201 | /* */ |
| 1202 | /*********************************************************************/ |
| 1203 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1204 | |
Dan Williams | 00af015 | 2007-08-02 13:14:56 -0400 | [diff] [blame] | 1205 | #define MAX_CUSTOM_LEN 64 |
| 1206 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1207 | static inline char *lbs_translate_scan(struct lbs_private *priv, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1208 | char *start, char *stop, |
| 1209 | struct bss_descriptor *bss) |
| 1210 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1211 | struct chan_freq_power *cfp; |
| 1212 | char *current_val; /* For rates */ |
| 1213 | struct iw_event iwe; /* Temporary buffer */ |
| 1214 | int j; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1215 | #define PERFECT_RSSI ((u8)50) |
| 1216 | #define WORST_RSSI ((u8)0) |
| 1217 | #define RSSI_DIFF ((u8)(PERFECT_RSSI - WORST_RSSI)) |
| 1218 | u8 rssi; |
| 1219 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1220 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1221 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1222 | cfp = lbs_find_cfp_by_band_and_channel(priv, 0, bss->channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1223 | if (!cfp) { |
| 1224 | lbs_deb_scan("Invalid channel number %d\n", bss->channel); |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1225 | start = NULL; |
| 1226 | goto out; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1227 | } |
| 1228 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1229 | /* First entry *MUST* be the BSSID */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1230 | iwe.cmd = SIOCGIWAP; |
| 1231 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 1232 | memcpy(iwe.u.ap_addr.sa_data, &bss->bssid, ETH_ALEN); |
| 1233 | start = iwe_stream_add_event(start, stop, &iwe, IW_EV_ADDR_LEN); |
| 1234 | |
| 1235 | /* SSID */ |
| 1236 | iwe.cmd = SIOCGIWESSID; |
| 1237 | iwe.u.data.flags = 1; |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1238 | iwe.u.data.length = min((u32) bss->ssid_len, (u32) IW_ESSID_MAX_SIZE); |
| 1239 | start = iwe_stream_add_point(start, stop, &iwe, bss->ssid); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1240 | |
| 1241 | /* Mode */ |
| 1242 | iwe.cmd = SIOCGIWMODE; |
| 1243 | iwe.u.mode = bss->mode; |
| 1244 | start = iwe_stream_add_event(start, stop, &iwe, IW_EV_UINT_LEN); |
| 1245 | |
| 1246 | /* Frequency */ |
| 1247 | iwe.cmd = SIOCGIWFREQ; |
| 1248 | iwe.u.freq.m = (long)cfp->freq * 100000; |
| 1249 | iwe.u.freq.e = 1; |
| 1250 | start = iwe_stream_add_event(start, stop, &iwe, IW_EV_FREQ_LEN); |
| 1251 | |
| 1252 | /* Add quality statistics */ |
| 1253 | iwe.cmd = IWEVQUAL; |
| 1254 | iwe.u.qual.updated = IW_QUAL_ALL_UPDATED; |
| 1255 | iwe.u.qual.level = SCAN_RSSI(bss->rssi); |
| 1256 | |
| 1257 | rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE; |
| 1258 | iwe.u.qual.qual = |
| 1259 | (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) * |
| 1260 | (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) / |
| 1261 | (RSSI_DIFF * RSSI_DIFF); |
| 1262 | if (iwe.u.qual.qual > 100) |
| 1263 | iwe.u.qual.qual = 100; |
| 1264 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1265 | if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1266 | iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE; |
| 1267 | } else { |
| 1268 | iwe.u.qual.noise = |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1269 | CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1270 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1271 | |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1272 | /* Locally created ad-hoc BSSs won't have beacons if this is the |
| 1273 | * only station in the adhoc network; so get signal strength |
| 1274 | * from receive statistics. |
| 1275 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1276 | if ((priv->mode == IW_MODE_ADHOC) |
| 1277 | && priv->adhoccreate |
| 1278 | && !lbs_ssid_cmp(priv->curbssparams.ssid, |
| 1279 | priv->curbssparams.ssid_len, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1280 | bss->ssid, bss->ssid_len)) { |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1281 | int snr, nf; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1282 | snr = priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE; |
| 1283 | nf = priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE; |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1284 | iwe.u.qual.level = CAL_RSSI(snr, nf); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1285 | } |
| 1286 | start = iwe_stream_add_event(start, stop, &iwe, IW_EV_QUAL_LEN); |
| 1287 | |
| 1288 | /* Add encryption capability */ |
| 1289 | iwe.cmd = SIOCGIWENCODE; |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 1290 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1291 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 1292 | } else { |
| 1293 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 1294 | } |
| 1295 | iwe.u.data.length = 0; |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1296 | start = iwe_stream_add_point(start, stop, &iwe, bss->ssid); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1297 | |
| 1298 | current_val = start + IW_EV_LCP_LEN; |
| 1299 | |
| 1300 | iwe.cmd = SIOCGIWRATE; |
| 1301 | iwe.u.bitrate.fixed = 0; |
| 1302 | iwe.u.bitrate.disabled = 0; |
| 1303 | iwe.u.bitrate.value = 0; |
| 1304 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 1305 | for (j = 0; bss->rates[j] && (j < sizeof(bss->rates)); j++) { |
| 1306 | /* Bit rate given in 500 kb/s units */ |
| 1307 | iwe.u.bitrate.value = bss->rates[j] * 500000; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1308 | current_val = iwe_stream_add_value(start, current_val, |
| 1309 | stop, &iwe, IW_EV_PARAM_LEN); |
| 1310 | } |
| 1311 | if ((bss->mode == IW_MODE_ADHOC) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1312 | && !lbs_ssid_cmp(priv->curbssparams.ssid, |
| 1313 | priv->curbssparams.ssid_len, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1314 | bss->ssid, bss->ssid_len) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1315 | && priv->adhoccreate) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1316 | iwe.u.bitrate.value = 22 * 500000; |
| 1317 | current_val = iwe_stream_add_value(start, current_val, |
| 1318 | stop, &iwe, IW_EV_PARAM_LEN); |
| 1319 | } |
| 1320 | /* Check if we added any event */ |
| 1321 | if((current_val - start) > IW_EV_LCP_LEN) |
| 1322 | start = current_val; |
| 1323 | |
| 1324 | memset(&iwe, 0, sizeof(iwe)); |
| 1325 | if (bss->wpa_ie_len) { |
| 1326 | char buf[MAX_WPA_IE_LEN]; |
| 1327 | memcpy(buf, bss->wpa_ie, bss->wpa_ie_len); |
| 1328 | iwe.cmd = IWEVGENIE; |
| 1329 | iwe.u.data.length = bss->wpa_ie_len; |
| 1330 | start = iwe_stream_add_point(start, stop, &iwe, buf); |
| 1331 | } |
| 1332 | |
| 1333 | memset(&iwe, 0, sizeof(iwe)); |
| 1334 | if (bss->rsn_ie_len) { |
| 1335 | char buf[MAX_WPA_IE_LEN]; |
| 1336 | memcpy(buf, bss->rsn_ie, bss->rsn_ie_len); |
| 1337 | iwe.cmd = IWEVGENIE; |
| 1338 | iwe.u.data.length = bss->rsn_ie_len; |
| 1339 | start = iwe_stream_add_point(start, stop, &iwe, buf); |
| 1340 | } |
| 1341 | |
Dan Williams | 00af015 | 2007-08-02 13:14:56 -0400 | [diff] [blame] | 1342 | if (bss->mesh) { |
| 1343 | char custom[MAX_CUSTOM_LEN]; |
| 1344 | char *p = custom; |
| 1345 | |
| 1346 | iwe.cmd = IWEVCUSTOM; |
| 1347 | p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), |
| 1348 | "mesh-type: olpc"); |
| 1349 | iwe.u.data.length = p - custom; |
| 1350 | if (iwe.u.data.length) |
| 1351 | start = iwe_stream_add_point(start, stop, &iwe, custom); |
| 1352 | } |
| 1353 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1354 | out: |
| 1355 | lbs_deb_leave_args(LBS_DEB_SCAN, "start %p", start); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1356 | return start; |
| 1357 | } |
| 1358 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1359 | |
| 1360 | /** |
| 1361 | * @brief Handle Scan Network ioctl |
| 1362 | * |
| 1363 | * @param dev A pointer to net_device structure |
| 1364 | * @param info A pointer to iw_request_info structure |
| 1365 | * @param vwrq A pointer to iw_param structure |
| 1366 | * @param extra A pointer to extra data buf |
| 1367 | * |
| 1368 | * @return 0 --success, otherwise fail |
| 1369 | */ |
| 1370 | int lbs_set_scan(struct net_device *dev, struct iw_request_info *info, |
| 1371 | struct iw_param *wrqu, char *extra) |
| 1372 | { |
| 1373 | struct lbs_private *priv = dev->priv; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1374 | |
| 1375 | lbs_deb_enter(LBS_DEB_SCAN); |
| 1376 | |
| 1377 | if (!netif_running(dev)) |
| 1378 | return -ENETDOWN; |
| 1379 | |
| 1380 | /* mac80211 does this: |
| 1381 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1382 | if (sdata->type != IEEE80211_IF_TYPE_xxx) |
| 1383 | return -EOPNOTSUPP; |
| 1384 | |
| 1385 | if (wrqu->data.length == sizeof(struct iw_scan_req) && |
| 1386 | wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
| 1387 | req = (struct iw_scan_req *)extra; |
| 1388 | ssid = req->essid; |
| 1389 | ssid_len = req->essid_len; |
| 1390 | } |
| 1391 | */ |
| 1392 | |
| 1393 | if (!delayed_work_pending(&priv->scan_work)) |
| 1394 | queue_delayed_work(priv->work_thread, &priv->scan_work, |
| 1395 | msecs_to_jiffies(50)); |
| 1396 | /* set marker that currently a scan is taking place */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 1397 | priv->scan_channel = -1; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1398 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1399 | if (priv->surpriseremoved) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1400 | return -EIO; |
| 1401 | |
| 1402 | lbs_deb_leave(LBS_DEB_SCAN); |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1407 | /** |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1408 | * @brief Handle Retrieve scan table ioctl |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1409 | * |
| 1410 | * @param dev A pointer to net_device structure |
| 1411 | * @param info A pointer to iw_request_info structure |
| 1412 | * @param dwrq A pointer to iw_point structure |
| 1413 | * @param extra A pointer to extra data buf |
| 1414 | * |
| 1415 | * @return 0 --success, otherwise fail |
| 1416 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1417 | int lbs_get_scan(struct net_device *dev, struct iw_request_info *info, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1418 | struct iw_point *dwrq, char *extra) |
| 1419 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1420 | #define SCAN_ITEM_SIZE 128 |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1421 | struct lbs_private *priv = dev->priv; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1422 | int err = 0; |
| 1423 | char *ev = extra; |
| 1424 | char *stop = ev + dwrq->length; |
| 1425 | struct bss_descriptor * iter_bss; |
| 1426 | struct bss_descriptor * safe; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1427 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1428 | lbs_deb_enter(LBS_DEB_SCAN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1429 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1430 | /* iwlist should wait until the current scan is finished */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 1431 | if (priv->scan_channel) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1432 | return -EAGAIN; |
| 1433 | |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1434 | /* Update RSSI if current BSS is a locally created ad-hoc BSS */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1435 | if ((priv->mode == IW_MODE_ADHOC) && priv->adhoccreate) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1436 | lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1437 | CMD_OPTION_WAITFORRSP, 0, NULL); |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1438 | } |
| 1439 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1440 | mutex_lock(&priv->lock); |
| 1441 | list_for_each_entry_safe (iter_bss, safe, &priv->network_list, list) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1442 | char * next_ev; |
| 1443 | unsigned long stale_time; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1444 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1445 | if (stop - ev < SCAN_ITEM_SIZE) { |
| 1446 | err = -E2BIG; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1447 | break; |
| 1448 | } |
| 1449 | |
Luis Carlos Cobo | 1e838bf | 2007-08-02 10:51:27 -0400 | [diff] [blame] | 1450 | /* For mesh device, list only mesh networks */ |
| 1451 | if (dev == priv->mesh_dev && !iter_bss->mesh) |
| 1452 | continue; |
| 1453 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1454 | /* Prune old an old scan result */ |
| 1455 | stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE; |
| 1456 | if (time_after(jiffies, stale_time)) { |
| 1457 | list_move_tail (&iter_bss->list, |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1458 | &priv->network_free_list); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1459 | clear_bss_descriptor(iter_bss); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1460 | continue; |
| 1461 | } |
| 1462 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1463 | /* Translate to WE format this entry */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1464 | next_ev = lbs_translate_scan(priv, ev, stop, iter_bss); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1465 | if (next_ev == NULL) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1466 | continue; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1467 | ev = next_ev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1468 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1469 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1470 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1471 | dwrq->length = (ev - extra); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1472 | dwrq->flags = 0; |
| 1473 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1474 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", err); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1475 | return err; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1476 | } |
| 1477 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1478 | |
| 1479 | |
| 1480 | |
| 1481 | /*********************************************************************/ |
| 1482 | /* */ |
| 1483 | /* Command execution */ |
| 1484 | /* */ |
| 1485 | /*********************************************************************/ |
| 1486 | |
| 1487 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1488 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1489 | * @brief This function handles the command response of scan |
| 1490 | * |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1491 | * Called from handle_cmd_response() in cmdrespc. |
| 1492 | * |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1493 | * The response buffer for the scan command has the following |
| 1494 | * memory layout: |
| 1495 | * |
| 1496 | * .-----------------------------------------------------------. |
| 1497 | * | header (4 * sizeof(u16)): Standard command response hdr | |
| 1498 | * .-----------------------------------------------------------. |
| 1499 | * | bufsize (u16) : sizeof the BSS Description data | |
| 1500 | * .-----------------------------------------------------------. |
| 1501 | * | NumOfSet (u8) : Number of BSS Descs returned | |
| 1502 | * .-----------------------------------------------------------. |
| 1503 | * | BSSDescription data (variable, size given in bufsize) | |
| 1504 | * .-----------------------------------------------------------. |
| 1505 | * | TLV data (variable, size calculated using header->size, | |
| 1506 | * | bufsize and sizeof the fixed fields above) | |
| 1507 | * .-----------------------------------------------------------. |
| 1508 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1509 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1510 | * @param resp A pointer to cmd_ds_command |
| 1511 | * |
| 1512 | * @return 0 or -1 |
| 1513 | */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1514 | static int lbs_ret_80211_scan(struct lbs_private *priv, unsigned long dummy, |
| 1515 | struct cmd_header *resp) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1516 | { |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1517 | struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1518 | struct bss_descriptor * iter_bss; |
| 1519 | struct bss_descriptor * safe; |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1520 | uint8_t *bssinfo; |
| 1521 | uint16_t scanrespsize; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1522 | int bytesleft; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1523 | int idx; |
| 1524 | int tlvbufsize; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1525 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1526 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1527 | lbs_deb_enter(LBS_DEB_SCAN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1528 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1529 | /* Prune old entries from scan table */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1530 | list_for_each_entry_safe (iter_bss, safe, &priv->network_list, list) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1531 | unsigned long stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE; |
| 1532 | if (time_before(jiffies, stale_time)) |
| 1533 | continue; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1534 | list_move_tail (&iter_bss->list, &priv->network_free_list); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1535 | clear_bss_descriptor(iter_bss); |
| 1536 | } |
| 1537 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1538 | if (scanresp->nr_sets > MAX_NETWORK_COUNT) { |
| 1539 | lbs_deb_scan("SCAN_RESP: too many scan results (%d, max %d)\n", |
| 1540 | scanresp->nr_sets, MAX_NETWORK_COUNT); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1541 | ret = -1; |
| 1542 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1543 | } |
| 1544 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1545 | bytesleft = le16_to_cpu(scanresp->bssdescriptsize); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1546 | lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1547 | |
David Woodhouse | e7240ac | 2007-12-11 17:54:36 -0500 | [diff] [blame] | 1548 | scanrespsize = le16_to_cpu(resp->size); |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1549 | lbs_deb_scan("SCAN_RESP: scan results %d\n", scanresp->nr_sets); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1550 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1551 | bssinfo = scanresp->bssdesc_and_tlvbuffer; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1552 | |
| 1553 | /* The size of the TLV buffer is equal to the entire command response |
| 1554 | * size (scanrespsize) minus the fixed fields (sizeof()'s), the |
| 1555 | * BSS Descriptions (bssdescriptsize as bytesLef) and the command |
| 1556 | * response header (S_DS_GEN) |
| 1557 | */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1558 | tlvbufsize = scanrespsize - (bytesleft + sizeof(scanresp->bssdescriptsize) |
| 1559 | + sizeof(scanresp->nr_sets) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1560 | + S_DS_GEN); |
| 1561 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1562 | /* |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1563 | * Process each scan response returned (scanresp->nr_sets). Save |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1564 | * the information in the newbssentry and then insert into the |
| 1565 | * driver scan table either as an update to an existing entry |
| 1566 | * or as an addition at the end of the table |
| 1567 | */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1568 | for (idx = 0; idx < scanresp->nr_sets && bytesleft; idx++) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1569 | struct bss_descriptor new; |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1570 | struct bss_descriptor *found = NULL; |
| 1571 | struct bss_descriptor *oldest = NULL; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1572 | DECLARE_MAC_BUF(mac); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1573 | |
| 1574 | /* Process the data fields and IEs returned for this BSS */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1575 | memset(&new, 0, sizeof (struct bss_descriptor)); |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1576 | if (lbs_process_bss(&new, &bssinfo, &bytesleft) != 0) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1577 | /* error parsing the scan response, skipped */ |
| 1578 | lbs_deb_scan("SCAN_RESP: process_bss returned ERROR\n"); |
| 1579 | continue; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1580 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1581 | |
| 1582 | /* Try to find this bss in the scan table */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1583 | list_for_each_entry (iter_bss, &priv->network_list, list) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1584 | if (is_same_network(iter_bss, &new)) { |
| 1585 | found = iter_bss; |
| 1586 | break; |
| 1587 | } |
| 1588 | |
| 1589 | if ((oldest == NULL) || |
| 1590 | (iter_bss->last_scanned < oldest->last_scanned)) |
| 1591 | oldest = iter_bss; |
| 1592 | } |
| 1593 | |
| 1594 | if (found) { |
| 1595 | /* found, clear it */ |
| 1596 | clear_bss_descriptor(found); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1597 | } else if (!list_empty(&priv->network_free_list)) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1598 | /* Pull one from the free list */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1599 | found = list_entry(priv->network_free_list.next, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1600 | struct bss_descriptor, list); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1601 | list_move_tail(&found->list, &priv->network_list); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1602 | } else if (oldest) { |
| 1603 | /* If there are no more slots, expire the oldest */ |
| 1604 | found = oldest; |
| 1605 | clear_bss_descriptor(found); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1606 | list_move_tail(&found->list, &priv->network_list); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1607 | } else { |
| 1608 | continue; |
| 1609 | } |
| 1610 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame^] | 1611 | lbs_deb_scan("SCAN_RESP: BSSID %s\n", print_mac(mac, new.bssid)); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1612 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1613 | /* Copy the locally created newbssentry to the scan table */ |
| 1614 | memcpy(found, &new, offsetof(struct bss_descriptor, list)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1615 | } |
| 1616 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1617 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1618 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1619 | done: |
| 1620 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 1621 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1622 | } |