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 | |
| 16 | #include "host.h" |
| 17 | #include "decl.h" |
| 18 | #include "dev.h" |
| 19 | #include "scan.h" |
| 20 | |
| 21 | //! Approximate amount of data needed to pass a scan result back to iwlist |
| 22 | #define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \ |
| 23 | + IW_ESSID_MAX_SIZE \ |
| 24 | + IW_EV_UINT_LEN \ |
| 25 | + IW_EV_FREQ_LEN \ |
| 26 | + IW_EV_QUAL_LEN \ |
| 27 | + IW_ESSID_MAX_SIZE \ |
| 28 | + IW_EV_PARAM_LEN \ |
| 29 | + 40) /* 40 for WPAIE */ |
| 30 | |
| 31 | //! Memory needed to store a max sized channel List TLV for a firmware scan |
| 32 | #define CHAN_TLV_MAX_SIZE (sizeof(struct mrvlietypesheader) \ |
| 33 | + (MRVDRV_MAX_CHANNELS_PER_SCAN \ |
| 34 | * sizeof(struct chanscanparamset))) |
| 35 | |
| 36 | //! Memory needed to store a max number/size SSID TLV for a firmware scan |
| 37 | #define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvlietypes_ssidparamset)) |
| 38 | |
| 39 | //! Maximum memory needed for a wlan_scan_cmd_config with all TLVs at max |
| 40 | #define MAX_SCAN_CFG_ALLOC (sizeof(struct wlan_scan_cmd_config) \ |
| 41 | + sizeof(struct mrvlietypes_numprobes) \ |
| 42 | + CHAN_TLV_MAX_SIZE \ |
| 43 | + SSID_TLV_MAX_SIZE) |
| 44 | |
| 45 | //! The maximum number of channels the firmware can scan per command |
| 46 | #define MRVDRV_MAX_CHANNELS_PER_SCAN 14 |
| 47 | |
| 48 | /** |
| 49 | * @brief Number of channels to scan per firmware scan command issuance. |
| 50 | * |
| 51 | * Number restricted to prevent hitting the limit on the amount of scan data |
| 52 | * returned in a single firmware scan command. |
| 53 | */ |
| 54 | #define MRVDRV_CHANNELS_PER_SCAN_CMD 4 |
| 55 | |
| 56 | //! Scan time specified in the channel TLV for each channel for passive scans |
| 57 | #define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100 |
| 58 | |
| 59 | //! Scan time specified in the channel TLV for each channel for active scans |
| 60 | #define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100 |
| 61 | |
Dan Williams | 123e0e0 | 2007-05-25 23:23:43 -0400 | [diff] [blame] | 62 | static const u8 zeromac[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 63 | static const u8 bcastmac[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 64 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 65 | static inline void clear_bss_descriptor (struct bss_descriptor * bss) |
| 66 | { |
| 67 | /* Don't blow away ->list, just BSS data */ |
| 68 | memset(bss, 0, offsetof(struct bss_descriptor, list)); |
| 69 | } |
| 70 | |
| 71 | static inline int match_bss_no_security(struct wlan_802_11_security * secinfo, |
| 72 | struct bss_descriptor * match_bss) |
| 73 | { |
| 74 | if ( !secinfo->wep_enabled |
| 75 | && !secinfo->WPAenabled |
| 76 | && !secinfo->WPA2enabled |
| 77 | && match_bss->wpa_ie[0] != WPA_IE |
| 78 | && match_bss->rsn_ie[0] != WPA2_IE |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 79 | && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY)) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 80 | return 1; |
| 81 | } |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static inline int match_bss_static_wep(struct wlan_802_11_security * secinfo, |
| 86 | struct bss_descriptor * match_bss) |
| 87 | { |
| 88 | if ( secinfo->wep_enabled |
| 89 | && !secinfo->WPAenabled |
| 90 | && !secinfo->WPA2enabled |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 91 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 92 | return 1; |
| 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static inline int match_bss_wpa(struct wlan_802_11_security * secinfo, |
| 98 | struct bss_descriptor * match_bss) |
| 99 | { |
| 100 | if ( !secinfo->wep_enabled |
| 101 | && secinfo->WPAenabled |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 102 | && (match_bss->wpa_ie[0] == WPA_IE) |
| 103 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 104 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) { |
| 105 | */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 106 | ) { |
| 107 | return 1; |
| 108 | } |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static inline int match_bss_wpa2(struct wlan_802_11_security * secinfo, |
| 113 | struct bss_descriptor * match_bss) |
| 114 | { |
| 115 | if ( !secinfo->wep_enabled |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 116 | && secinfo->WPA2enabled |
| 117 | && (match_bss->rsn_ie[0] == WPA2_IE) |
| 118 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 119 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) { |
| 120 | */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 121 | ) { |
| 122 | return 1; |
| 123 | } |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static inline int match_bss_dynamic_wep(struct wlan_802_11_security * secinfo, |
| 128 | struct bss_descriptor * match_bss) |
| 129 | { |
| 130 | if ( !secinfo->wep_enabled |
| 131 | && !secinfo->WPAenabled |
| 132 | && !secinfo->WPA2enabled |
| 133 | && (match_bss->wpa_ie[0] != WPA_IE) |
| 134 | && (match_bss->rsn_ie[0] != WPA2_IE) |
Dan Williams | 0c9ca69 | 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 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * @brief Check if a scanned network compatible with the driver settings |
| 143 | * |
| 144 | * WEP WPA WPA2 ad-hoc encrypt Network |
| 145 | * enabled enabled enabled AES mode privacy WPA WPA2 Compatible |
| 146 | * 0 0 0 0 NONE 0 0 0 yes No security |
| 147 | * 1 0 0 0 NONE 1 0 0 yes Static WEP |
| 148 | * 0 1 0 0 x 1x 1 x yes WPA |
| 149 | * 0 0 1 0 x 1x x 1 yes WPA2 |
| 150 | * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES |
| 151 | * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP |
| 152 | * |
| 153 | * |
| 154 | * @param adapter A pointer to wlan_adapter |
| 155 | * @param index Index in scantable to check against current driver settings |
| 156 | * @param mode Network mode: Infrastructure or IBSS |
| 157 | * |
| 158 | * @return Index in scantable, or error code if negative |
| 159 | */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 160 | static int is_network_compatible(wlan_adapter * adapter, |
| 161 | struct bss_descriptor * bss, u8 mode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 162 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 163 | int matched = 0; |
| 164 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 165 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 166 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 167 | if (bss->mode != mode) |
| 168 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 169 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 170 | if ((matched = match_bss_no_security(&adapter->secinfo, bss))) { |
| 171 | goto done; |
| 172 | } else if ((matched = match_bss_static_wep(&adapter->secinfo, bss))) { |
| 173 | goto done; |
| 174 | } else if ((matched = match_bss_wpa(&adapter->secinfo, bss))) { |
| 175 | lbs_deb_scan( |
| 176 | "is_network_compatible() WPA: wpa_ie=%#x " |
| 177 | "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s " |
| 178 | "privacy=%#x\n", bss->wpa_ie[0], bss->rsn_ie[0], |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 179 | adapter->secinfo.wep_enabled ? "e" : "d", |
| 180 | adapter->secinfo.WPAenabled ? "e" : "d", |
| 181 | adapter->secinfo.WPA2enabled ? "e" : "d", |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 182 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 183 | goto done; |
| 184 | } else if ((matched = match_bss_wpa2(&adapter->secinfo, bss))) { |
| 185 | lbs_deb_scan( |
| 186 | "is_network_compatible() WPA2: wpa_ie=%#x " |
| 187 | "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s " |
| 188 | "privacy=%#x\n", bss->wpa_ie[0], bss->rsn_ie[0], |
| 189 | adapter->secinfo.wep_enabled ? "e" : "d", |
| 190 | adapter->secinfo.WPAenabled ? "e" : "d", |
| 191 | adapter->secinfo.WPA2enabled ? "e" : "d", |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 192 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 193 | goto done; |
| 194 | } else if ((matched = match_bss_dynamic_wep(&adapter->secinfo, bss))) { |
| 195 | lbs_deb_scan( |
| 196 | "is_network_compatible() dynamic WEP: " |
| 197 | "wpa_ie=%#x wpa2_ie=%#x privacy=%#x\n", |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 198 | bss->wpa_ie[0], bss->rsn_ie[0], |
| 199 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 200 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 201 | } |
| 202 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 203 | /* bss security settings don't match those configured on card */ |
| 204 | lbs_deb_scan( |
| 205 | "is_network_compatible() FAILED: wpa_ie=%#x " |
| 206 | "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s privacy=%#x\n", |
| 207 | bss->wpa_ie[0], bss->rsn_ie[0], |
| 208 | adapter->secinfo.wep_enabled ? "e" : "d", |
| 209 | adapter->secinfo.WPAenabled ? "e" : "d", |
| 210 | adapter->secinfo.WPA2enabled ? "e" : "d", |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 211 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 212 | |
| 213 | done: |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 214 | lbs_deb_leave(LBS_DEB_SCAN); |
| 215 | return matched; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 219 | * @brief Create a channel list for the driver to scan based on region info |
| 220 | * |
| 221 | * Use the driver region/band information to construct a comprehensive list |
| 222 | * of channels to scan. This routine is used for any scan that is not |
| 223 | * provided a specific channel list to scan. |
| 224 | * |
| 225 | * @param priv A pointer to wlan_private structure |
| 226 | * @param scanchanlist Output parameter: resulting channel list to scan |
| 227 | * @param filteredscan Flag indicating whether or not a BSSID or SSID filter |
| 228 | * is being sent in the command to firmware. Used to |
| 229 | * increase the number of channels sent in a scan |
| 230 | * command and to disable the firmware channel scan |
| 231 | * filter. |
| 232 | * |
| 233 | * @return void |
| 234 | */ |
| 235 | static void wlan_scan_create_channel_list(wlan_private * priv, |
| 236 | struct chanscanparamset * scanchanlist, |
| 237 | u8 filteredscan) |
| 238 | { |
| 239 | |
| 240 | wlan_adapter *adapter = priv->adapter; |
| 241 | struct region_channel *scanregion; |
| 242 | struct chan_freq_power *cfp; |
| 243 | int rgnidx; |
| 244 | int chanidx; |
| 245 | int nextchan; |
| 246 | u8 scantype; |
| 247 | |
| 248 | chanidx = 0; |
| 249 | |
| 250 | /* Set the default scan type to the user specified type, will later |
| 251 | * be changed to passive on a per channel basis if restricted by |
| 252 | * regulatory requirements (11d or 11h) |
| 253 | */ |
| 254 | scantype = adapter->scantype; |
| 255 | |
| 256 | for (rgnidx = 0; rgnidx < ARRAY_SIZE(adapter->region_channel); rgnidx++) { |
| 257 | if (priv->adapter->enable11d && |
| 258 | adapter->connect_status != libertas_connected) { |
| 259 | /* Scan all the supported chan for the first scan */ |
| 260 | if (!adapter->universal_channel[rgnidx].valid) |
| 261 | continue; |
| 262 | scanregion = &adapter->universal_channel[rgnidx]; |
| 263 | |
| 264 | /* clear the parsed_region_chan for the first scan */ |
| 265 | memset(&adapter->parsed_region_chan, 0x00, |
| 266 | sizeof(adapter->parsed_region_chan)); |
| 267 | } else { |
| 268 | if (!adapter->region_channel[rgnidx].valid) |
| 269 | continue; |
| 270 | scanregion = &adapter->region_channel[rgnidx]; |
| 271 | } |
| 272 | |
| 273 | for (nextchan = 0; |
| 274 | nextchan < scanregion->nrcfp; nextchan++, chanidx++) { |
| 275 | |
| 276 | cfp = scanregion->CFP + nextchan; |
| 277 | |
| 278 | if (priv->adapter->enable11d) { |
| 279 | scantype = |
| 280 | libertas_get_scan_type_11d(cfp->channel, |
| 281 | &adapter-> |
| 282 | parsed_region_chan); |
| 283 | } |
| 284 | |
| 285 | switch (scanregion->band) { |
| 286 | case BAND_B: |
| 287 | case BAND_G: |
| 288 | default: |
| 289 | scanchanlist[chanidx].radiotype = |
| 290 | cmd_scan_radio_type_bg; |
| 291 | break; |
| 292 | } |
| 293 | |
| 294 | if (scantype == cmd_scan_type_passive) { |
| 295 | scanchanlist[chanidx].maxscantime = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 296 | cpu_to_le16(MRVDRV_PASSIVE_SCAN_CHAN_TIME); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 297 | scanchanlist[chanidx].chanscanmode.passivescan = |
| 298 | 1; |
| 299 | } else { |
| 300 | scanchanlist[chanidx].maxscantime = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 301 | cpu_to_le16(MRVDRV_ACTIVE_SCAN_CHAN_TIME); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 302 | scanchanlist[chanidx].chanscanmode.passivescan = |
| 303 | 0; |
| 304 | } |
| 305 | |
| 306 | scanchanlist[chanidx].channumber = cfp->channel; |
| 307 | |
| 308 | if (filteredscan) { |
| 309 | scanchanlist[chanidx].chanscanmode. |
| 310 | disablechanfilt = 1; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * @brief Construct a wlan_scan_cmd_config structure to use in issue scan cmds |
| 318 | * |
| 319 | * Application layer or other functions can invoke wlan_scan_networks |
| 320 | * with a scan configuration supplied in a wlan_ioctl_user_scan_cfg struct. |
| 321 | * This structure is used as the basis of one or many wlan_scan_cmd_config |
| 322 | * commands that are sent to the command processing module and sent to |
| 323 | * firmware. |
| 324 | * |
| 325 | * Create a wlan_scan_cmd_config based on the following user supplied |
| 326 | * parameters (if present): |
| 327 | * - SSID filter |
| 328 | * - BSSID filter |
| 329 | * - Number of Probes to be sent |
| 330 | * - channel list |
| 331 | * |
| 332 | * If the SSID or BSSID filter is not present, disable/clear the filter. |
| 333 | * If the number of probes is not set, use the adapter default setting |
| 334 | * Qualify the channel |
| 335 | * |
| 336 | * @param priv A pointer to wlan_private structure |
| 337 | * @param puserscanin NULL or pointer to scan configuration parameters |
| 338 | * @param ppchantlvout Output parameter: Pointer to the start of the |
| 339 | * channel TLV portion of the output scan config |
| 340 | * @param pscanchanlist Output parameter: Pointer to the resulting channel |
| 341 | * list to scan |
| 342 | * @param pmaxchanperscan Output parameter: Number of channels to scan for |
| 343 | * each issuance of the firmware scan command |
| 344 | * @param pfilteredscan Output parameter: Flag indicating whether or not |
| 345 | * a BSSID or SSID filter is being sent in the |
| 346 | * command to firmware. Used to increase the number |
| 347 | * of channels sent in a scan command and to |
| 348 | * disable the firmware channel scan filter. |
| 349 | * @param pscancurrentonly Output parameter: Flag indicating whether or not |
| 350 | * we are only scanning our current active channel |
| 351 | * |
| 352 | * @return resulting scan configuration |
| 353 | */ |
| 354 | static struct wlan_scan_cmd_config * |
| 355 | wlan_scan_setup_scan_config(wlan_private * priv, |
| 356 | const struct wlan_ioctl_user_scan_cfg * puserscanin, |
| 357 | struct mrvlietypes_chanlistparamset ** ppchantlvout, |
| 358 | struct chanscanparamset * pscanchanlist, |
| 359 | int *pmaxchanperscan, |
| 360 | u8 * pfilteredscan, |
| 361 | u8 * pscancurrentonly) |
| 362 | { |
| 363 | wlan_adapter *adapter = priv->adapter; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 364 | struct mrvlietypes_numprobes *pnumprobestlv; |
| 365 | struct mrvlietypes_ssidparamset *pssidtlv; |
| 366 | struct wlan_scan_cmd_config * pscancfgout = NULL; |
| 367 | u8 *ptlvpos; |
| 368 | u16 numprobes; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 369 | int chanidx; |
| 370 | int scantype; |
| 371 | int scandur; |
| 372 | int channel; |
| 373 | int radiotype; |
| 374 | |
| 375 | pscancfgout = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL); |
| 376 | if (pscancfgout == NULL) |
| 377 | goto out; |
| 378 | |
| 379 | /* The tlvbufferlen is calculated for each scan command. The TLVs added |
| 380 | * in this routine will be preserved since the routine that sends |
| 381 | * the command will append channelTLVs at *ppchantlvout. The difference |
| 382 | * between the *ppchantlvout and the tlvbuffer start will be used |
| 383 | * to calculate the size of anything we add in this routine. |
| 384 | */ |
| 385 | pscancfgout->tlvbufferlen = 0; |
| 386 | |
| 387 | /* Running tlv pointer. Assigned to ppchantlvout at end of function |
| 388 | * so later routines know where channels can be added to the command buf |
| 389 | */ |
| 390 | ptlvpos = pscancfgout->tlvbuffer; |
| 391 | |
| 392 | /* |
| 393 | * Set the initial scan paramters for progressive scanning. If a specific |
| 394 | * BSSID or SSID is used, the number of channels in the scan command |
| 395 | * will be increased to the absolute maximum |
| 396 | */ |
| 397 | *pmaxchanperscan = MRVDRV_CHANNELS_PER_SCAN_CMD; |
| 398 | |
| 399 | /* Initialize the scan as un-filtered by firmware, set to TRUE below if |
| 400 | * a SSID or BSSID filter is sent in the command |
| 401 | */ |
| 402 | *pfilteredscan = 0; |
| 403 | |
| 404 | /* Initialize the scan as not being only on the current channel. If |
| 405 | * the channel list is customized, only contains one channel, and |
| 406 | * is the active channel, this is set true and data flow is not halted. |
| 407 | */ |
| 408 | *pscancurrentonly = 0; |
| 409 | |
| 410 | if (puserscanin) { |
| 411 | |
| 412 | /* Set the bss type scan filter, use adapter setting if unset */ |
| 413 | pscancfgout->bsstype = |
| 414 | (puserscanin->bsstype ? puserscanin->bsstype : adapter-> |
| 415 | scanmode); |
| 416 | |
| 417 | /* Set the number of probes to send, use adapter setting if unset */ |
| 418 | numprobes = (puserscanin->numprobes ? puserscanin->numprobes : |
| 419 | adapter->scanprobes); |
| 420 | |
| 421 | /* |
| 422 | * Set the BSSID filter to the incoming configuration, |
| 423 | * if non-zero. If not set, it will remain disabled (all zeros). |
| 424 | */ |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 425 | memcpy(pscancfgout->bssid, puserscanin->bssid, |
| 426 | sizeof(pscancfgout->bssid)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 427 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 428 | if (puserscanin->ssid_len) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 429 | pssidtlv = |
| 430 | (struct mrvlietypes_ssidparamset *) pscancfgout-> |
| 431 | tlvbuffer; |
| 432 | pssidtlv->header.type = cpu_to_le16(TLV_TYPE_SSID); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 433 | pssidtlv->header.len = cpu_to_le16(puserscanin->ssid_len); |
| 434 | memcpy(pssidtlv->ssid, puserscanin->ssid, |
| 435 | puserscanin->ssid_len); |
| 436 | ptlvpos += sizeof(pssidtlv->header) + puserscanin->ssid_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* |
| 440 | * The default number of channels sent in the command is low to |
| 441 | * ensure the response buffer from the firmware does not truncate |
| 442 | * scan results. That is not an issue with an SSID or BSSID |
| 443 | * filter applied to the scan results in the firmware. |
| 444 | */ |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 445 | if ( puserscanin->ssid_len |
| 446 | || (compare_ether_addr(pscancfgout->bssid, &zeromac[0]) != 0)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 447 | *pmaxchanperscan = MRVDRV_MAX_CHANNELS_PER_SCAN; |
| 448 | *pfilteredscan = 1; |
| 449 | } |
| 450 | } else { |
| 451 | pscancfgout->bsstype = adapter->scanmode; |
| 452 | numprobes = adapter->scanprobes; |
| 453 | } |
| 454 | |
| 455 | /* If the input config or adapter has the number of Probes set, add tlv */ |
| 456 | if (numprobes) { |
| 457 | pnumprobestlv = (struct mrvlietypes_numprobes *) ptlvpos; |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 458 | pnumprobestlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES); |
| 459 | pnumprobestlv->header.len = cpu_to_le16(2); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 460 | pnumprobestlv->numprobes = cpu_to_le16(numprobes); |
| 461 | |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 462 | ptlvpos += sizeof(*pnumprobestlv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | /* |
| 466 | * Set the output for the channel TLV to the address in the tlv buffer |
| 467 | * past any TLVs that were added in this fuction (SSID, numprobes). |
| 468 | * channel TLVs will be added past this for each scan command, preserving |
| 469 | * the TLVs that were previously added. |
| 470 | */ |
| 471 | *ppchantlvout = (struct mrvlietypes_chanlistparamset *) ptlvpos; |
| 472 | |
| 473 | if (puserscanin && puserscanin->chanlist[0].channumber) { |
| 474 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 475 | lbs_deb_scan("Scan: Using supplied channel list\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 476 | |
| 477 | for (chanidx = 0; |
| 478 | chanidx < WLAN_IOCTL_USER_SCAN_CHAN_MAX |
| 479 | && puserscanin->chanlist[chanidx].channumber; chanidx++) { |
| 480 | |
| 481 | channel = puserscanin->chanlist[chanidx].channumber; |
| 482 | (pscanchanlist + chanidx)->channumber = channel; |
| 483 | |
| 484 | radiotype = puserscanin->chanlist[chanidx].radiotype; |
| 485 | (pscanchanlist + chanidx)->radiotype = radiotype; |
| 486 | |
| 487 | scantype = puserscanin->chanlist[chanidx].scantype; |
| 488 | |
| 489 | if (scantype == cmd_scan_type_passive) { |
| 490 | (pscanchanlist + |
| 491 | chanidx)->chanscanmode.passivescan = 1; |
| 492 | } else { |
| 493 | (pscanchanlist + |
| 494 | chanidx)->chanscanmode.passivescan = 0; |
| 495 | } |
| 496 | |
| 497 | if (puserscanin->chanlist[chanidx].scantime) { |
| 498 | scandur = |
| 499 | puserscanin->chanlist[chanidx].scantime; |
| 500 | } else { |
| 501 | if (scantype == cmd_scan_type_passive) { |
| 502 | scandur = MRVDRV_PASSIVE_SCAN_CHAN_TIME; |
| 503 | } else { |
| 504 | scandur = MRVDRV_ACTIVE_SCAN_CHAN_TIME; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | (pscanchanlist + chanidx)->minscantime = |
| 509 | cpu_to_le16(scandur); |
| 510 | (pscanchanlist + chanidx)->maxscantime = |
| 511 | cpu_to_le16(scandur); |
| 512 | } |
| 513 | |
| 514 | /* Check if we are only scanning the current channel */ |
| 515 | if ((chanidx == 1) && (puserscanin->chanlist[0].channumber |
| 516 | == |
| 517 | priv->adapter->curbssparams.channel)) { |
| 518 | *pscancurrentonly = 1; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 519 | lbs_deb_scan("Scan: Scanning current channel only"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 523 | lbs_deb_scan("Scan: Creating full region channel list\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 524 | wlan_scan_create_channel_list(priv, pscanchanlist, |
| 525 | *pfilteredscan); |
| 526 | } |
| 527 | |
| 528 | out: |
| 529 | return pscancfgout; |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * @brief Construct and send multiple scan config commands to the firmware |
| 534 | * |
| 535 | * Previous routines have created a wlan_scan_cmd_config with any requested |
| 536 | * TLVs. This function splits the channel TLV into maxchanperscan lists |
| 537 | * and sends the portion of the channel TLV along with the other TLVs |
| 538 | * to the wlan_cmd routines for execution in the firmware. |
| 539 | * |
| 540 | * @param priv A pointer to wlan_private structure |
| 541 | * @param maxchanperscan Maximum number channels to be included in each |
| 542 | * scan command sent to firmware |
| 543 | * @param filteredscan Flag indicating whether or not a BSSID or SSID |
| 544 | * filter is being used for the firmware command |
| 545 | * scan command sent to firmware |
| 546 | * @param pscancfgout Scan configuration used for this scan. |
| 547 | * @param pchantlvout Pointer in the pscancfgout where the channel TLV |
| 548 | * should start. This is past any other TLVs that |
| 549 | * must be sent down in each firmware command. |
| 550 | * @param pscanchanlist List of channels to scan in maxchanperscan segments |
| 551 | * |
| 552 | * @return 0 or error return otherwise |
| 553 | */ |
| 554 | static int wlan_scan_channel_list(wlan_private * priv, |
| 555 | int maxchanperscan, |
| 556 | u8 filteredscan, |
| 557 | struct wlan_scan_cmd_config * pscancfgout, |
| 558 | struct mrvlietypes_chanlistparamset * pchantlvout, |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 559 | struct chanscanparamset * pscanchanlist, |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 560 | const struct wlan_ioctl_user_scan_cfg * puserscanin, |
| 561 | int full_scan) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 562 | { |
| 563 | struct chanscanparamset *ptmpchan; |
| 564 | struct chanscanparamset *pstartchan; |
| 565 | u8 scanband; |
| 566 | int doneearly; |
| 567 | int tlvidx; |
| 568 | int ret = 0; |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 569 | int scanned = 0; |
| 570 | union iwreq_data wrqu; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 571 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 572 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 573 | |
| 574 | if (pscancfgout == 0 || pchantlvout == 0 || pscanchanlist == 0) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 575 | lbs_deb_scan("Scan: Null detect: %p, %p, %p\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 576 | pscancfgout, pchantlvout, pscanchanlist); |
| 577 | return -1; |
| 578 | } |
| 579 | |
| 580 | pchantlvout->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); |
| 581 | |
| 582 | /* Set the temp channel struct pointer to the start of the desired list */ |
| 583 | ptmpchan = pscanchanlist; |
| 584 | |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 585 | if (priv->adapter->last_scanned_channel && !puserscanin) |
| 586 | ptmpchan += priv->adapter->last_scanned_channel; |
| 587 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 588 | /* Loop through the desired channel list, sending a new firmware scan |
| 589 | * commands for each maxchanperscan channels (or for 1,6,11 individually |
| 590 | * if configured accordingly) |
| 591 | */ |
| 592 | while (ptmpchan->channumber) { |
| 593 | |
| 594 | tlvidx = 0; |
| 595 | pchantlvout->header.len = 0; |
| 596 | scanband = ptmpchan->radiotype; |
| 597 | pstartchan = ptmpchan; |
| 598 | doneearly = 0; |
| 599 | |
| 600 | /* Construct the channel TLV for the scan command. Continue to |
| 601 | * insert channel TLVs until: |
| 602 | * - the tlvidx hits the maximum configured per scan command |
| 603 | * - the next channel to insert is 0 (end of desired channel list) |
| 604 | * - doneearly is set (controlling individual scanning of 1,6,11) |
| 605 | */ |
| 606 | while (tlvidx < maxchanperscan && ptmpchan->channumber |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 607 | && !doneearly && scanned < 2) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 608 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 609 | lbs_deb_scan( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 610 | "Scan: Chan(%3d), Radio(%d), mode(%d,%d), Dur(%d)\n", |
| 611 | ptmpchan->channumber, ptmpchan->radiotype, |
| 612 | ptmpchan->chanscanmode.passivescan, |
| 613 | ptmpchan->chanscanmode.disablechanfilt, |
| 614 | ptmpchan->maxscantime); |
| 615 | |
| 616 | /* Copy the current channel TLV to the command being prepared */ |
| 617 | memcpy(pchantlvout->chanscanparam + tlvidx, |
| 618 | ptmpchan, sizeof(pchantlvout->chanscanparam)); |
| 619 | |
| 620 | /* Increment the TLV header length by the size appended */ |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 621 | /* Ew, it would be _so_ nice if we could just declare the |
| 622 | variable little-endian and let GCC handle it for us */ |
| 623 | pchantlvout->header.len = |
| 624 | cpu_to_le16(le16_to_cpu(pchantlvout->header.len) + |
| 625 | sizeof(pchantlvout->chanscanparam)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 626 | |
| 627 | /* |
| 628 | * The tlv buffer length is set to the number of bytes of the |
| 629 | * between the channel tlv pointer and the start of the |
| 630 | * tlv buffer. This compensates for any TLVs that were appended |
| 631 | * before the channel list. |
| 632 | */ |
| 633 | pscancfgout->tlvbufferlen = ((u8 *) pchantlvout |
| 634 | - pscancfgout->tlvbuffer); |
| 635 | |
| 636 | /* Add the size of the channel tlv header and the data length */ |
| 637 | pscancfgout->tlvbufferlen += |
| 638 | (sizeof(pchantlvout->header) |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 639 | + le16_to_cpu(pchantlvout->header.len)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 640 | |
| 641 | /* Increment the index to the channel tlv we are constructing */ |
| 642 | tlvidx++; |
| 643 | |
| 644 | doneearly = 0; |
| 645 | |
| 646 | /* Stop the loop if the *current* channel is in the 1,6,11 set |
| 647 | * and we are not filtering on a BSSID or SSID. |
| 648 | */ |
| 649 | if (!filteredscan && (ptmpchan->channumber == 1 |
| 650 | || ptmpchan->channumber == 6 |
| 651 | || ptmpchan->channumber == 11)) { |
| 652 | doneearly = 1; |
| 653 | } |
| 654 | |
| 655 | /* Increment the tmp pointer to the next channel to be scanned */ |
| 656 | ptmpchan++; |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 657 | scanned++; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 658 | |
| 659 | /* Stop the loop if the *next* channel is in the 1,6,11 set. |
| 660 | * This will cause it to be the only channel scanned on the next |
| 661 | * interation |
| 662 | */ |
| 663 | if (!filteredscan && (ptmpchan->channumber == 1 |
| 664 | || ptmpchan->channumber == 6 |
| 665 | || ptmpchan->channumber == 11)) { |
| 666 | doneearly = 1; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | /* Send the scan command to the firmware with the specified cfg */ |
| 671 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_scan, 0, |
| 672 | 0, 0, pscancfgout); |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 673 | if (scanned >= 2 && !full_scan) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 674 | ret = 0; |
| 675 | goto done; |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 676 | } |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 677 | scanned = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 678 | } |
| 679 | |
Dan Williams | d9ad2f5 | 2007-05-25 22:38:41 -0400 | [diff] [blame] | 680 | done: |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 681 | priv->adapter->last_scanned_channel = ptmpchan->channumber; |
| 682 | |
Dan Williams | d9ad2f5 | 2007-05-25 22:38:41 -0400 | [diff] [blame] | 683 | /* Tell userspace the scan table has been updated */ |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 684 | memset(&wrqu, 0, sizeof(union iwreq_data)); |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 685 | wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL); |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 686 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 687 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 688 | return ret; |
| 689 | } |
| 690 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 691 | static void |
| 692 | clear_selected_scan_list_entries(wlan_adapter * adapter, |
| 693 | const struct wlan_ioctl_user_scan_cfg * scan_cfg) |
| 694 | { |
| 695 | struct bss_descriptor * bss; |
| 696 | struct bss_descriptor * safe; |
| 697 | u32 clear_ssid_flag = 0, clear_bssid_flag = 0; |
| 698 | |
| 699 | if (!scan_cfg) |
| 700 | return; |
| 701 | |
| 702 | if (scan_cfg->clear_ssid && scan_cfg->ssid_len) |
| 703 | clear_ssid_flag = 1; |
| 704 | |
| 705 | if (scan_cfg->clear_bssid |
| 706 | && (compare_ether_addr(scan_cfg->bssid, &zeromac[0]) != 0) |
| 707 | && (compare_ether_addr(scan_cfg->bssid, &bcastmac[0]) != 0)) { |
| 708 | clear_bssid_flag = 1; |
| 709 | } |
| 710 | |
| 711 | if (!clear_ssid_flag && !clear_bssid_flag) |
| 712 | return; |
| 713 | |
| 714 | mutex_lock(&adapter->lock); |
| 715 | list_for_each_entry_safe (bss, safe, &adapter->network_list, list) { |
| 716 | u32 clear = 0; |
| 717 | |
| 718 | /* Check for an SSID match */ |
| 719 | if ( clear_ssid_flag |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 720 | && (bss->ssid_len == scan_cfg->ssid_len) |
| 721 | && !memcmp(bss->ssid, scan_cfg->ssid, bss->ssid_len)) |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 722 | clear = 1; |
| 723 | |
| 724 | /* Check for a BSSID match */ |
| 725 | if ( clear_bssid_flag |
| 726 | && !compare_ether_addr(bss->bssid, scan_cfg->bssid)) |
| 727 | clear = 1; |
| 728 | |
| 729 | if (clear) { |
| 730 | list_move_tail (&bss->list, &adapter->network_free_list); |
| 731 | clear_bss_descriptor(bss); |
| 732 | } |
| 733 | } |
| 734 | mutex_unlock(&adapter->lock); |
| 735 | } |
| 736 | |
| 737 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 738 | /** |
| 739 | * @brief Internal function used to start a scan based on an input config |
| 740 | * |
| 741 | * Use the input user scan configuration information when provided in |
| 742 | * order to send the appropriate scan commands to firmware to populate or |
| 743 | * update the internal driver scan table |
| 744 | * |
| 745 | * @param priv A pointer to wlan_private structure |
| 746 | * @param puserscanin Pointer to the input configuration for the requested |
| 747 | * scan. |
| 748 | * |
| 749 | * @return 0 or < 0 if error |
| 750 | */ |
| 751 | int wlan_scan_networks(wlan_private * priv, |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 752 | const struct wlan_ioctl_user_scan_cfg * puserscanin, |
| 753 | int full_scan) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 754 | { |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 755 | wlan_adapter * adapter = priv->adapter; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 756 | struct mrvlietypes_chanlistparamset *pchantlvout; |
| 757 | struct chanscanparamset * scan_chan_list = NULL; |
| 758 | struct wlan_scan_cmd_config * scan_cfg = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 759 | u8 filteredscan; |
| 760 | u8 scancurrentchanonly; |
| 761 | int maxchanperscan; |
| 762 | int ret; |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 763 | #ifdef CONFIG_LIBERTAS_DEBUG |
| 764 | struct bss_descriptor * iter_bss; |
| 765 | int i = 0; |
| 766 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 767 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 768 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 769 | |
| 770 | scan_chan_list = kzalloc(sizeof(struct chanscanparamset) * |
| 771 | WLAN_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL); |
| 772 | if (scan_chan_list == NULL) { |
| 773 | ret = -ENOMEM; |
| 774 | goto out; |
| 775 | } |
| 776 | |
| 777 | scan_cfg = wlan_scan_setup_scan_config(priv, |
| 778 | puserscanin, |
| 779 | &pchantlvout, |
| 780 | scan_chan_list, |
| 781 | &maxchanperscan, |
| 782 | &filteredscan, |
| 783 | &scancurrentchanonly); |
| 784 | if (scan_cfg == NULL) { |
| 785 | ret = -ENOMEM; |
| 786 | goto out; |
| 787 | } |
| 788 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 789 | clear_selected_scan_list_entries(adapter, puserscanin); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 790 | |
| 791 | /* Keep the data path active if we are only scanning our current channel */ |
| 792 | if (!scancurrentchanonly) { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 793 | netif_stop_queue(priv->dev); |
| 794 | netif_carrier_off(priv->dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 795 | netif_stop_queue(priv->mesh_dev); |
| 796 | netif_carrier_off(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | ret = wlan_scan_channel_list(priv, |
| 800 | maxchanperscan, |
| 801 | filteredscan, |
| 802 | scan_cfg, |
| 803 | pchantlvout, |
Marcelo Tosatti | 064827e | 2007-05-24 23:37:28 -0400 | [diff] [blame] | 804 | scan_chan_list, |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 805 | puserscanin, |
| 806 | full_scan); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 807 | |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 808 | #ifdef CONFIG_LIBERTAS_DEBUG |
| 809 | /* Dump the scan table */ |
| 810 | mutex_lock(&adapter->lock); |
| 811 | list_for_each_entry (iter_bss, &adapter->network_list, list) { |
| 812 | lbs_deb_scan("Scan:(%02d) " MAC_FMT ", RSSI[%03d], SSID[%s]\n", |
| 813 | i++, MAC_ARG(iter_bss->bssid), (s32) iter_bss->rssi, |
| 814 | escape_essid(iter_bss->ssid, iter_bss->ssid_len)); |
| 815 | } |
| 816 | mutex_unlock(&adapter->lock); |
| 817 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 818 | |
| 819 | if (priv->adapter->connect_status == libertas_connected) { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 820 | netif_carrier_on(priv->dev); |
| 821 | netif_wake_queue(priv->dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 822 | netif_carrier_on(priv->mesh_dev); |
| 823 | netif_wake_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | out: |
| 827 | if (scan_cfg) |
| 828 | kfree(scan_cfg); |
| 829 | |
| 830 | if (scan_chan_list) |
| 831 | kfree(scan_chan_list); |
| 832 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 833 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 834 | return ret; |
| 835 | } |
| 836 | |
| 837 | /** |
| 838 | * @brief Inspect the scan response buffer for pointers to expected TLVs |
| 839 | * |
| 840 | * TLVs can be included at the end of the scan response BSS information. |
| 841 | * Parse the data in the buffer for pointers to TLVs that can potentially |
| 842 | * be passed back in the response |
| 843 | * |
| 844 | * @param ptlv Pointer to the start of the TLV buffer to parse |
| 845 | * @param tlvbufsize size of the TLV buffer |
| 846 | * @param ptsftlv Output parameter: Pointer to the TSF TLV if found |
| 847 | * |
| 848 | * @return void |
| 849 | */ |
| 850 | static |
| 851 | void wlan_ret_802_11_scan_get_tlv_ptrs(struct mrvlietypes_data * ptlv, |
| 852 | int tlvbufsize, |
| 853 | struct mrvlietypes_tsftimestamp ** ptsftlv) |
| 854 | { |
| 855 | struct mrvlietypes_data *pcurrenttlv; |
| 856 | int tlvbufleft; |
| 857 | u16 tlvtype; |
| 858 | u16 tlvlen; |
| 859 | |
| 860 | pcurrenttlv = ptlv; |
| 861 | tlvbufleft = tlvbufsize; |
| 862 | *ptsftlv = NULL; |
| 863 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 864 | lbs_deb_scan("SCAN_RESP: tlvbufsize = %d\n", tlvbufsize); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 865 | lbs_dbg_hex("SCAN_RESP: TLV Buf", (u8 *) ptlv, tlvbufsize); |
| 866 | |
| 867 | while (tlvbufleft >= sizeof(struct mrvlietypesheader)) { |
| 868 | tlvtype = le16_to_cpu(pcurrenttlv->header.type); |
| 869 | tlvlen = le16_to_cpu(pcurrenttlv->header.len); |
| 870 | |
| 871 | switch (tlvtype) { |
| 872 | case TLV_TYPE_TSFTIMESTAMP: |
| 873 | *ptsftlv = (struct mrvlietypes_tsftimestamp *) pcurrenttlv; |
| 874 | break; |
| 875 | |
| 876 | default: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 877 | lbs_deb_scan("SCAN_RESP: Unhandled TLV = %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 878 | tlvtype); |
| 879 | /* Give up, this seems corrupted */ |
| 880 | return; |
| 881 | } /* switch */ |
| 882 | |
| 883 | tlvbufleft -= (sizeof(ptlv->header) + tlvlen); |
| 884 | pcurrenttlv = |
| 885 | (struct mrvlietypes_data *) (pcurrenttlv->Data + tlvlen); |
| 886 | } /* while */ |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * @brief Interpret a BSS scan response returned from the firmware |
| 891 | * |
| 892 | * Parse the various fixed fields and IEs passed back for a a BSS probe |
| 893 | * response or beacon from the scan command. Record information as needed |
| 894 | * in the scan table struct bss_descriptor for that entry. |
| 895 | * |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 896 | * @param bss Output parameter: Pointer to the BSS Entry |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 897 | * |
| 898 | * @return 0 or -1 |
| 899 | */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 900 | static int libertas_process_bss(struct bss_descriptor * bss, |
| 901 | u8 ** pbeaconinfo, int *bytesleft) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 902 | { |
| 903 | enum ieeetypes_elementid elemID; |
| 904 | struct ieeetypes_fhparamset *pFH; |
| 905 | struct ieeetypes_dsparamset *pDS; |
| 906 | struct ieeetypes_cfparamset *pCF; |
| 907 | struct ieeetypes_ibssparamset *pibss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 908 | u8 *pcurrentptr; |
| 909 | u8 *pRate; |
| 910 | u8 elemlen; |
| 911 | u8 bytestocopy; |
| 912 | u8 ratesize; |
| 913 | u16 beaconsize; |
| 914 | u8 founddatarateie; |
| 915 | int bytesleftforcurrentbeacon; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 916 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 917 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 918 | struct IE_WPA *pIe; |
| 919 | const u8 oui01[4] = { 0x00, 0x50, 0xf2, 0x01 }; |
| 920 | |
| 921 | struct ieeetypes_countryinfoset *pcountryinfo; |
| 922 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 923 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 924 | |
| 925 | founddatarateie = 0; |
| 926 | ratesize = 0; |
| 927 | beaconsize = 0; |
| 928 | |
| 929 | if (*bytesleft >= sizeof(beaconsize)) { |
| 930 | /* Extract & convert beacon size from the command buffer */ |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 931 | beaconsize = le16_to_cpup((void *)*pbeaconinfo); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 932 | *bytesleft -= sizeof(beaconsize); |
| 933 | *pbeaconinfo += sizeof(beaconsize); |
| 934 | } |
| 935 | |
| 936 | if (beaconsize == 0 || beaconsize > *bytesleft) { |
| 937 | |
| 938 | *pbeaconinfo += *bytesleft; |
| 939 | *bytesleft = 0; |
| 940 | |
| 941 | return -1; |
| 942 | } |
| 943 | |
| 944 | /* Initialize the current working beacon pointer for this BSS iteration */ |
| 945 | pcurrentptr = *pbeaconinfo; |
| 946 | |
| 947 | /* Advance the return beacon pointer past the current beacon */ |
| 948 | *pbeaconinfo += beaconsize; |
| 949 | *bytesleft -= beaconsize; |
| 950 | |
| 951 | bytesleftforcurrentbeacon = beaconsize; |
| 952 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 953 | memcpy(bss->bssid, pcurrentptr, ETH_ALEN); |
Dan Williams | 02eb229 | 2007-05-25 17:27:31 -0400 | [diff] [blame] | 954 | lbs_deb_scan("process_bss: AP BSSID " MAC_FMT "\n", MAC_ARG(bss->bssid)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 955 | |
| 956 | pcurrentptr += ETH_ALEN; |
| 957 | bytesleftforcurrentbeacon -= ETH_ALEN; |
| 958 | |
| 959 | if (bytesleftforcurrentbeacon < 12) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 960 | lbs_deb_scan("process_bss: Not enough bytes left\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 961 | return -1; |
| 962 | } |
| 963 | |
| 964 | /* |
| 965 | * next 4 fields are RSSI, time stamp, beacon interval, |
| 966 | * and capability information |
| 967 | */ |
| 968 | |
| 969 | /* RSSI is 1 byte long */ |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 970 | bss->rssi = *pcurrentptr; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 971 | lbs_deb_scan("process_bss: RSSI=%02X\n", *pcurrentptr); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 972 | pcurrentptr += 1; |
| 973 | bytesleftforcurrentbeacon -= 1; |
| 974 | |
| 975 | /* time stamp is 8 bytes long */ |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 976 | bss->timestamp = le64_to_cpup((void *)pcurrentptr); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 977 | pcurrentptr += 8; |
| 978 | bytesleftforcurrentbeacon -= 8; |
| 979 | |
| 980 | /* beacon interval is 2 bytes long */ |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 981 | bss->beaconperiod = le16_to_cpup((void *)pcurrentptr); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 982 | pcurrentptr += 2; |
| 983 | bytesleftforcurrentbeacon -= 2; |
| 984 | |
| 985 | /* capability information is 2 bytes long */ |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 986 | bss->capability = le16_to_cpup((void *)pcurrentptr); |
| 987 | lbs_deb_scan("process_bss: capabilities = 0x%4X\n", bss->capability); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 988 | pcurrentptr += 2; |
| 989 | bytesleftforcurrentbeacon -= 2; |
| 990 | |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 991 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) |
| 992 | lbs_deb_scan("process_bss: AP WEP enabled\n"); |
| 993 | if (bss->capability & WLAN_CAPABILITY_IBSS) |
| 994 | bss->mode = IW_MODE_ADHOC; |
| 995 | else |
| 996 | bss->mode = IW_MODE_INFRA; |
| 997 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 998 | /* rest of the current buffer are IE's */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 999 | lbs_deb_scan("process_bss: IE length for this AP = %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1000 | bytesleftforcurrentbeacon); |
| 1001 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1002 | lbs_dbg_hex("process_bss: IE info", (u8 *) pcurrentptr, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1003 | bytesleftforcurrentbeacon); |
| 1004 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1005 | /* process variable IE */ |
| 1006 | while (bytesleftforcurrentbeacon >= 2) { |
| 1007 | elemID = (enum ieeetypes_elementid) (*((u8 *) pcurrentptr)); |
| 1008 | elemlen = *((u8 *) pcurrentptr + 1); |
| 1009 | |
| 1010 | if (bytesleftforcurrentbeacon < elemlen) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1011 | lbs_deb_scan("process_bss: error in processing IE, " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1012 | "bytes left < IE length\n"); |
| 1013 | bytesleftforcurrentbeacon = 0; |
| 1014 | continue; |
| 1015 | } |
| 1016 | |
| 1017 | switch (elemID) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1018 | case SSID: |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1019 | bss->ssid_len = elemlen; |
| 1020 | memcpy(bss->ssid, (pcurrentptr + 2), elemlen); |
| 1021 | lbs_deb_scan("ssid '%s', ssid length %u\n", |
| 1022 | escape_essid(bss->ssid, bss->ssid_len), |
| 1023 | bss->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1024 | break; |
| 1025 | |
| 1026 | case SUPPORTED_RATES: |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1027 | memcpy(bss->datarates, (pcurrentptr + 2), elemlen); |
| 1028 | memmove(bss->libertas_supported_rates, (pcurrentptr + 2), |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1029 | elemlen); |
| 1030 | ratesize = elemlen; |
| 1031 | founddatarateie = 1; |
| 1032 | break; |
| 1033 | |
| 1034 | case EXTRA_IE: |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1035 | lbs_deb_scan("process_bss: EXTRA_IE Found!\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1036 | break; |
| 1037 | |
| 1038 | case FH_PARAM_SET: |
| 1039 | pFH = (struct ieeetypes_fhparamset *) pcurrentptr; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1040 | memmove(&bss->phyparamset.fhparamset, pFH, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1041 | sizeof(struct ieeetypes_fhparamset)); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1042 | #if 0 /* I think we can store these LE */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1043 | bss->phyparamset.fhparamset.dwelltime |
| 1044 | = le16_to_cpu(bss->phyparamset.fhparamset.dwelltime); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1045 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1046 | break; |
| 1047 | |
| 1048 | case DS_PARAM_SET: |
| 1049 | pDS = (struct ieeetypes_dsparamset *) pcurrentptr; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1050 | bss->channel = pDS->currentchan; |
| 1051 | memcpy(&bss->phyparamset.dsparamset, pDS, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1052 | sizeof(struct ieeetypes_dsparamset)); |
| 1053 | break; |
| 1054 | |
| 1055 | case CF_PARAM_SET: |
| 1056 | pCF = (struct ieeetypes_cfparamset *) pcurrentptr; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1057 | memcpy(&bss->ssparamset.cfparamset, pCF, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1058 | sizeof(struct ieeetypes_cfparamset)); |
| 1059 | break; |
| 1060 | |
| 1061 | case IBSS_PARAM_SET: |
| 1062 | pibss = (struct ieeetypes_ibssparamset *) pcurrentptr; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1063 | bss->atimwindow = le32_to_cpu(pibss->atimwindow); |
| 1064 | memmove(&bss->ssparamset.ibssparamset, pibss, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1065 | sizeof(struct ieeetypes_ibssparamset)); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1066 | #if 0 |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1067 | bss->ssparamset.ibssparamset.atimwindow |
| 1068 | = le16_to_cpu(bss->ssparamset.ibssparamset.atimwindow); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1069 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1070 | break; |
| 1071 | |
| 1072 | /* Handle Country Info IE */ |
| 1073 | case COUNTRY_INFO: |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1074 | pcountryinfo = (struct ieeetypes_countryinfoset *) pcurrentptr; |
| 1075 | if (pcountryinfo->len < sizeof(pcountryinfo->countrycode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1076 | || pcountryinfo->len > 254) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1077 | lbs_deb_scan("process_bss: 11D- Err " |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 1078 | "CountryInfo len =%d min=%zd max=254\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1079 | pcountryinfo->len, |
| 1080 | sizeof(pcountryinfo->countrycode)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1081 | ret = -1; |
| 1082 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1083 | } |
| 1084 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1085 | memcpy(&bss->countryinfo, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1086 | pcountryinfo, pcountryinfo->len + 2); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1087 | lbs_dbg_hex("process_bss: 11D- CountryInfo:", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1088 | (u8 *) pcountryinfo, |
| 1089 | (u32) (pcountryinfo->len + 2)); |
| 1090 | break; |
| 1091 | |
| 1092 | case EXTENDED_SUPPORTED_RATES: |
| 1093 | /* |
| 1094 | * only process extended supported rate |
| 1095 | * if data rate is already found. |
| 1096 | * data rate IE should come before |
| 1097 | * extended supported rate IE |
| 1098 | */ |
| 1099 | if (founddatarateie) { |
| 1100 | if ((elemlen + ratesize) > WLAN_SUPPORTED_RATES) { |
| 1101 | bytestocopy = |
| 1102 | (WLAN_SUPPORTED_RATES - ratesize); |
| 1103 | } else { |
| 1104 | bytestocopy = elemlen; |
| 1105 | } |
| 1106 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1107 | pRate = (u8 *) bss->datarates; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1108 | pRate += ratesize; |
| 1109 | memmove(pRate, (pcurrentptr + 2), bytestocopy); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1110 | pRate = (u8 *) bss->libertas_supported_rates; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1111 | pRate += ratesize; |
| 1112 | memmove(pRate, (pcurrentptr + 2), bytestocopy); |
| 1113 | } |
| 1114 | break; |
| 1115 | |
| 1116 | case VENDOR_SPECIFIC_221: |
| 1117 | #define IE_ID_LEN_FIELDS_BYTES 2 |
| 1118 | pIe = (struct IE_WPA *)pcurrentptr; |
| 1119 | |
Dan Williams | 51b0c9d | 2007-05-10 22:51:28 -0400 | [diff] [blame] | 1120 | if (memcmp(pIe->oui, oui01, sizeof(oui01))) |
| 1121 | break; |
| 1122 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1123 | bss->wpa_ie_len = min(elemlen + IE_ID_LEN_FIELDS_BYTES, |
| 1124 | MAX_WPA_IE_LEN); |
| 1125 | memcpy(bss->wpa_ie, pcurrentptr, bss->wpa_ie_len); |
| 1126 | lbs_dbg_hex("process_bss: WPA IE", bss->wpa_ie, elemlen); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1127 | break; |
| 1128 | case WPA2_IE: |
| 1129 | pIe = (struct IE_WPA *)pcurrentptr; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1130 | bss->rsn_ie_len = min(elemlen + IE_ID_LEN_FIELDS_BYTES, |
| 1131 | MAX_WPA_IE_LEN); |
| 1132 | memcpy(bss->rsn_ie, pcurrentptr, bss->rsn_ie_len); |
| 1133 | lbs_dbg_hex("process_bss: RSN_IE", bss->rsn_ie, elemlen); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1134 | break; |
| 1135 | case TIM: |
| 1136 | break; |
| 1137 | |
| 1138 | case CHALLENGE_TEXT: |
| 1139 | break; |
| 1140 | } |
| 1141 | |
| 1142 | pcurrentptr += elemlen + 2; |
| 1143 | |
| 1144 | /* need to account for IE ID and IE len */ |
| 1145 | bytesleftforcurrentbeacon -= (elemlen + 2); |
| 1146 | |
| 1147 | } /* while (bytesleftforcurrentbeacon > 2) */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1148 | |
| 1149 | /* Timestamp */ |
| 1150 | bss->last_scanned = jiffies; |
| 1151 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1152 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1153 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1154 | done: |
| 1155 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 1156 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * @brief Compare two SSIDs |
| 1161 | * |
| 1162 | * @param ssid1 A pointer to ssid to compare |
| 1163 | * @param ssid2 A pointer to ssid to compare |
| 1164 | * |
| 1165 | * @return 0--ssid is same, otherwise is different |
| 1166 | */ |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1167 | int libertas_ssid_cmp(u8 *ssid1, u8 ssid1_len, u8 *ssid2, u8 ssid2_len) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1168 | { |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1169 | if (ssid1_len != ssid2_len) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1170 | return -1; |
| 1171 | |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1172 | return memcmp(ssid1, ssid2, ssid1_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * @brief This function finds a specific compatible BSSID in the scan list |
| 1177 | * |
| 1178 | * @param adapter A pointer to wlan_adapter |
| 1179 | * @param bssid BSSID to find in the scan list |
| 1180 | * @param mode Network mode: Infrastructure or IBSS |
| 1181 | * |
| 1182 | * @return index in BSSID list, or error return code (< 0) |
| 1183 | */ |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1184 | struct bss_descriptor * libertas_find_bssid_in_list(wlan_adapter * adapter, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1185 | u8 * bssid, u8 mode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1186 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1187 | struct bss_descriptor * iter_bss; |
| 1188 | struct bss_descriptor * found_bss = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1189 | |
| 1190 | if (!bssid) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1191 | return NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1192 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1193 | lbs_dbg_hex("libertas_find_BSSID_in_list: looking for ", |
| 1194 | bssid, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1195 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1196 | /* Look through the scan table for a compatible match. The loop will |
| 1197 | * continue past a matched bssid that is not compatible in case there |
| 1198 | * is an AP with multiple SSIDs assigned to the same BSSID |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1199 | */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1200 | mutex_lock(&adapter->lock); |
| 1201 | list_for_each_entry (iter_bss, &adapter->network_list, list) { |
Dan Williams | 3cf2093 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 1202 | if (compare_ether_addr(iter_bss->bssid, bssid)) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1203 | continue; /* bssid doesn't match */ |
| 1204 | switch (mode) { |
| 1205 | case IW_MODE_INFRA: |
| 1206 | case IW_MODE_ADHOC: |
| 1207 | if (!is_network_compatible(adapter, iter_bss, mode)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1208 | break; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1209 | found_bss = iter_bss; |
| 1210 | break; |
| 1211 | default: |
| 1212 | found_bss = iter_bss; |
| 1213 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1214 | } |
| 1215 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1216 | mutex_unlock(&adapter->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1217 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1218 | return found_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | /** |
| 1222 | * @brief This function finds ssid in ssid list. |
| 1223 | * |
| 1224 | * @param adapter A pointer to wlan_adapter |
| 1225 | * @param ssid SSID to find in the list |
| 1226 | * @param bssid BSSID to qualify the SSID selection (if provided) |
| 1227 | * @param mode Network mode: Infrastructure or IBSS |
| 1228 | * |
| 1229 | * @return index in BSSID list |
| 1230 | */ |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1231 | struct bss_descriptor * libertas_find_ssid_in_list(wlan_adapter * adapter, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1232 | u8 *ssid, u8 ssid_len, u8 * bssid, u8 mode, |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 1233 | int channel) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1234 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1235 | u8 bestrssi = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1236 | struct bss_descriptor * iter_bss = NULL; |
| 1237 | struct bss_descriptor * found_bss = NULL; |
| 1238 | struct bss_descriptor * tmp_oldest = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1239 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1240 | mutex_lock(&adapter->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1241 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1242 | list_for_each_entry (iter_bss, &adapter->network_list, list) { |
| 1243 | if ( !tmp_oldest |
| 1244 | || (iter_bss->last_scanned < tmp_oldest->last_scanned)) |
| 1245 | tmp_oldest = iter_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1246 | |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1247 | if (libertas_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1248 | ssid, ssid_len) != 0) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1249 | continue; /* ssid doesn't match */ |
Dan Williams | 3cf2093 | 2007-05-25 17:28:30 -0400 | [diff] [blame] | 1250 | if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1251 | continue; /* bssid doesn't match */ |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 1252 | if ((channel > 0) && (iter_bss->channel != channel)) |
| 1253 | continue; /* channel doesn't match */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1254 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1255 | switch (mode) { |
| 1256 | case IW_MODE_INFRA: |
| 1257 | case IW_MODE_ADHOC: |
| 1258 | if (!is_network_compatible(adapter, iter_bss, mode)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1259 | break; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1260 | |
| 1261 | if (bssid) { |
| 1262 | /* Found requested BSSID */ |
| 1263 | found_bss = iter_bss; |
| 1264 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1265 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1266 | |
| 1267 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { |
| 1268 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1269 | found_bss = iter_bss; |
| 1270 | } |
| 1271 | break; |
| 1272 | case IW_MODE_AUTO: |
| 1273 | default: |
| 1274 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { |
| 1275 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1276 | found_bss = iter_bss; |
| 1277 | } |
| 1278 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1282 | out: |
| 1283 | mutex_unlock(&adapter->lock); |
| 1284 | return found_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | /** |
| 1288 | * @brief This function finds the best SSID in the Scan List |
| 1289 | * |
| 1290 | * Search the scan table for the best SSID that also matches the current |
| 1291 | * adapter network preference (infrastructure or adhoc) |
| 1292 | * |
| 1293 | * @param adapter A pointer to wlan_adapter |
| 1294 | * |
| 1295 | * @return index in BSSID list |
| 1296 | */ |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1297 | struct bss_descriptor * libertas_find_best_ssid_in_list(wlan_adapter * adapter, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1298 | u8 mode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1299 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1300 | u8 bestrssi = 0; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1301 | struct bss_descriptor * iter_bss; |
| 1302 | struct bss_descriptor * best_bss = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1303 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1304 | mutex_lock(&adapter->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1305 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1306 | list_for_each_entry (iter_bss, &adapter->network_list, list) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1307 | switch (mode) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1308 | case IW_MODE_INFRA: |
| 1309 | case IW_MODE_ADHOC: |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1310 | if (!is_network_compatible(adapter, iter_bss, mode)) |
| 1311 | break; |
| 1312 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) |
| 1313 | break; |
| 1314 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1315 | best_bss = iter_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1316 | break; |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 1317 | case IW_MODE_AUTO: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1318 | default: |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1319 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) |
| 1320 | break; |
| 1321 | bestrssi = SCAN_RSSI(iter_bss->rssi); |
| 1322 | best_bss = iter_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1323 | break; |
| 1324 | } |
| 1325 | } |
| 1326 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1327 | mutex_unlock(&adapter->lock); |
| 1328 | return best_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | /** |
| 1332 | * @brief Find the AP with specific ssid in the scan list |
| 1333 | * |
| 1334 | * @param priv A pointer to wlan_private structure |
| 1335 | * @param pSSID A pointer to AP's ssid |
| 1336 | * |
| 1337 | * @return 0--success, otherwise--fail |
| 1338 | */ |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1339 | int libertas_find_best_network_ssid(wlan_private * priv, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1340 | 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] | 1341 | { |
| 1342 | wlan_adapter *adapter = priv->adapter; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1343 | int ret = -1; |
| 1344 | struct bss_descriptor * found; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1345 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1346 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1347 | |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 1348 | wlan_scan_networks(priv, NULL, 1); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1349 | if (adapter->surpriseremoved) |
| 1350 | return -1; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1351 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1352 | wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending); |
| 1353 | |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1354 | found = libertas_find_best_ssid_in_list(adapter, preferred_mode); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1355 | if (found && (found->ssid_len > 0)) { |
| 1356 | memcpy(out_ssid, &found->ssid, IW_ESSID_MAX_SIZE); |
| 1357 | *out_ssid_len = found->ssid_len; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1358 | *out_mode = found->mode; |
| 1359 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1360 | } |
| 1361 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1362 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1363 | return ret; |
| 1364 | } |
| 1365 | |
| 1366 | /** |
| 1367 | * @brief Scan Network |
| 1368 | * |
| 1369 | * @param dev A pointer to net_device structure |
| 1370 | * @param info A pointer to iw_request_info structure |
| 1371 | * @param vwrq A pointer to iw_param structure |
| 1372 | * @param extra A pointer to extra data buf |
| 1373 | * |
| 1374 | * @return 0 --success, otherwise fail |
| 1375 | */ |
| 1376 | int libertas_set_scan(struct net_device *dev, struct iw_request_info *info, |
| 1377 | struct iw_param *vwrq, char *extra) |
| 1378 | { |
| 1379 | wlan_private *priv = dev->priv; |
| 1380 | wlan_adapter *adapter = priv->adapter; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1381 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1382 | lbs_deb_enter(LBS_DEB_SCAN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1383 | |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 1384 | wlan_scan_networks(priv, NULL, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1385 | |
| 1386 | if (adapter->surpriseremoved) |
| 1387 | return -1; |
| 1388 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1389 | lbs_deb_leave(LBS_DEB_SCAN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1390 | return 0; |
| 1391 | } |
| 1392 | |
| 1393 | /** |
| 1394 | * @brief Send a scan command for all available channels filtered on a spec |
| 1395 | * |
| 1396 | * @param priv A pointer to wlan_private structure |
| 1397 | * @param prequestedssid A pointer to AP's ssid |
| 1398 | * @param keeppreviousscan Flag used to save/clear scan table before scan |
| 1399 | * |
| 1400 | * @return 0-success, otherwise fail |
| 1401 | */ |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1402 | int libertas_send_specific_ssid_scan(wlan_private * priv, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1403 | u8 *ssid, u8 ssid_len, u8 clear_ssid) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1404 | { |
| 1405 | wlan_adapter *adapter = priv->adapter; |
| 1406 | struct wlan_ioctl_user_scan_cfg scancfg; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1407 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1408 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1409 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1410 | |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1411 | if (!ssid_len) |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1412 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1413 | |
| 1414 | memset(&scancfg, 0x00, sizeof(scancfg)); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1415 | memcpy(scancfg.ssid, ssid, ssid_len); |
| 1416 | scancfg.ssid_len = ssid_len; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1417 | scancfg.clear_ssid = clear_ssid; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1418 | |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 1419 | wlan_scan_networks(priv, &scancfg, 1); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1420 | if (adapter->surpriseremoved) |
| 1421 | return -1; |
| 1422 | wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending); |
| 1423 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1424 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1425 | lbs_deb_leave(LBS_DEB_ASSOC); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1426 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | /** |
| 1430 | * @brief scan an AP with specific BSSID |
| 1431 | * |
| 1432 | * @param priv A pointer to wlan_private structure |
| 1433 | * @param bssid A pointer to AP's bssid |
| 1434 | * @param keeppreviousscan Flag used to save/clear scan table before scan |
| 1435 | * |
| 1436 | * @return 0-success, otherwise fail |
| 1437 | */ |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1438 | int libertas_send_specific_bssid_scan(wlan_private * priv, u8 * bssid, u8 clear_bssid) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1439 | { |
| 1440 | struct wlan_ioctl_user_scan_cfg scancfg; |
| 1441 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1442 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1443 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1444 | if (bssid == NULL) |
| 1445 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1446 | |
| 1447 | memset(&scancfg, 0x00, sizeof(scancfg)); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1448 | memcpy(scancfg.bssid, bssid, ETH_ALEN); |
| 1449 | scancfg.clear_bssid = clear_bssid; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1450 | |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 1451 | wlan_scan_networks(priv, &scancfg, 1); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1452 | if (priv->adapter->surpriseremoved) |
| 1453 | return -1; |
| 1454 | wait_event_interruptible(priv->adapter->cmd_pending, |
| 1455 | !priv->adapter->nr_cmd_pending); |
| 1456 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1457 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1458 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1459 | return 0; |
| 1460 | } |
| 1461 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1462 | static inline char *libertas_translate_scan(wlan_private *priv, |
| 1463 | char *start, char *stop, |
| 1464 | struct bss_descriptor *bss) |
| 1465 | { |
| 1466 | wlan_adapter *adapter = priv->adapter; |
| 1467 | struct chan_freq_power *cfp; |
| 1468 | char *current_val; /* For rates */ |
| 1469 | struct iw_event iwe; /* Temporary buffer */ |
| 1470 | int j; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1471 | #define PERFECT_RSSI ((u8)50) |
| 1472 | #define WORST_RSSI ((u8)0) |
| 1473 | #define RSSI_DIFF ((u8)(PERFECT_RSSI - WORST_RSSI)) |
| 1474 | u8 rssi; |
| 1475 | |
| 1476 | cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, bss->channel); |
| 1477 | if (!cfp) { |
| 1478 | lbs_deb_scan("Invalid channel number %d\n", bss->channel); |
| 1479 | return NULL; |
| 1480 | } |
| 1481 | |
| 1482 | /* First entry *MUST* be the AP BSSID */ |
| 1483 | iwe.cmd = SIOCGIWAP; |
| 1484 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 1485 | memcpy(iwe.u.ap_addr.sa_data, &bss->bssid, ETH_ALEN); |
| 1486 | start = iwe_stream_add_event(start, stop, &iwe, IW_EV_ADDR_LEN); |
| 1487 | |
| 1488 | /* SSID */ |
| 1489 | iwe.cmd = SIOCGIWESSID; |
| 1490 | iwe.u.data.flags = 1; |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1491 | iwe.u.data.length = min((u32) bss->ssid_len, (u32) IW_ESSID_MAX_SIZE); |
| 1492 | start = iwe_stream_add_point(start, stop, &iwe, bss->ssid); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1493 | |
| 1494 | /* Mode */ |
| 1495 | iwe.cmd = SIOCGIWMODE; |
| 1496 | iwe.u.mode = bss->mode; |
| 1497 | start = iwe_stream_add_event(start, stop, &iwe, IW_EV_UINT_LEN); |
| 1498 | |
| 1499 | /* Frequency */ |
| 1500 | iwe.cmd = SIOCGIWFREQ; |
| 1501 | iwe.u.freq.m = (long)cfp->freq * 100000; |
| 1502 | iwe.u.freq.e = 1; |
| 1503 | start = iwe_stream_add_event(start, stop, &iwe, IW_EV_FREQ_LEN); |
| 1504 | |
| 1505 | /* Add quality statistics */ |
| 1506 | iwe.cmd = IWEVQUAL; |
| 1507 | iwe.u.qual.updated = IW_QUAL_ALL_UPDATED; |
| 1508 | iwe.u.qual.level = SCAN_RSSI(bss->rssi); |
| 1509 | |
| 1510 | rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE; |
| 1511 | iwe.u.qual.qual = |
| 1512 | (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) * |
| 1513 | (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) / |
| 1514 | (RSSI_DIFF * RSSI_DIFF); |
| 1515 | if (iwe.u.qual.qual > 100) |
| 1516 | iwe.u.qual.qual = 100; |
| 1517 | |
| 1518 | if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) { |
| 1519 | iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE; |
| 1520 | } else { |
| 1521 | iwe.u.qual.noise = |
| 1522 | CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]); |
| 1523 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1524 | |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1525 | /* Locally created ad-hoc BSSs won't have beacons if this is the |
| 1526 | * only station in the adhoc network; so get signal strength |
| 1527 | * from receive statistics. |
| 1528 | */ |
| 1529 | if ((adapter->mode == IW_MODE_ADHOC) |
| 1530 | && adapter->adhoccreate |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1531 | && !libertas_ssid_cmp(adapter->curbssparams.ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1532 | adapter->curbssparams.ssid_len, |
| 1533 | bss->ssid, bss->ssid_len)) { |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1534 | int snr, nf; |
| 1535 | snr = adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE; |
| 1536 | nf = adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE; |
| 1537 | iwe.u.qual.level = CAL_RSSI(snr, nf); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1538 | } |
| 1539 | start = iwe_stream_add_event(start, stop, &iwe, IW_EV_QUAL_LEN); |
| 1540 | |
| 1541 | /* Add encryption capability */ |
| 1542 | iwe.cmd = SIOCGIWENCODE; |
Dan Williams | 0c9ca69 | 2007-08-02 10:43:44 -0400 | [diff] [blame^] | 1543 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1544 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 1545 | } else { |
| 1546 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 1547 | } |
| 1548 | iwe.u.data.length = 0; |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1549 | start = iwe_stream_add_point(start, stop, &iwe, bss->ssid); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1550 | |
| 1551 | current_val = start + IW_EV_LCP_LEN; |
| 1552 | |
| 1553 | iwe.cmd = SIOCGIWRATE; |
| 1554 | iwe.u.bitrate.fixed = 0; |
| 1555 | iwe.u.bitrate.disabled = 0; |
| 1556 | iwe.u.bitrate.value = 0; |
| 1557 | |
| 1558 | for (j = 0; j < sizeof(bss->libertas_supported_rates); j++) { |
| 1559 | u8 rate = bss->libertas_supported_rates[j]; |
| 1560 | if (rate == 0) |
| 1561 | break; /* no more rates */ |
| 1562 | /* Bit rate given in 500 kb/s units (+ 0x80) */ |
| 1563 | iwe.u.bitrate.value = (rate & 0x7f) * 500000; |
| 1564 | current_val = iwe_stream_add_value(start, current_val, |
| 1565 | stop, &iwe, IW_EV_PARAM_LEN); |
| 1566 | } |
| 1567 | if ((bss->mode == IW_MODE_ADHOC) |
Dan Williams | 717c933 | 2007-05-29 00:03:31 -0400 | [diff] [blame] | 1568 | && !libertas_ssid_cmp(adapter->curbssparams.ssid, |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1569 | adapter->curbssparams.ssid_len, |
| 1570 | bss->ssid, bss->ssid_len) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1571 | && adapter->adhoccreate) { |
| 1572 | iwe.u.bitrate.value = 22 * 500000; |
| 1573 | current_val = iwe_stream_add_value(start, current_val, |
| 1574 | stop, &iwe, IW_EV_PARAM_LEN); |
| 1575 | } |
| 1576 | /* Check if we added any event */ |
| 1577 | if((current_val - start) > IW_EV_LCP_LEN) |
| 1578 | start = current_val; |
| 1579 | |
| 1580 | memset(&iwe, 0, sizeof(iwe)); |
| 1581 | if (bss->wpa_ie_len) { |
| 1582 | char buf[MAX_WPA_IE_LEN]; |
| 1583 | memcpy(buf, bss->wpa_ie, bss->wpa_ie_len); |
| 1584 | iwe.cmd = IWEVGENIE; |
| 1585 | iwe.u.data.length = bss->wpa_ie_len; |
| 1586 | start = iwe_stream_add_point(start, stop, &iwe, buf); |
| 1587 | } |
| 1588 | |
| 1589 | memset(&iwe, 0, sizeof(iwe)); |
| 1590 | if (bss->rsn_ie_len) { |
| 1591 | char buf[MAX_WPA_IE_LEN]; |
| 1592 | memcpy(buf, bss->rsn_ie, bss->rsn_ie_len); |
| 1593 | iwe.cmd = IWEVGENIE; |
| 1594 | iwe.u.data.length = bss->rsn_ie_len; |
| 1595 | start = iwe_stream_add_point(start, stop, &iwe, buf); |
| 1596 | } |
| 1597 | |
| 1598 | return start; |
| 1599 | } |
| 1600 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1601 | /** |
| 1602 | * @brief Retrieve the scan table entries via wireless tools IOCTL call |
| 1603 | * |
| 1604 | * @param dev A pointer to net_device structure |
| 1605 | * @param info A pointer to iw_request_info structure |
| 1606 | * @param dwrq A pointer to iw_point structure |
| 1607 | * @param extra A pointer to extra data buf |
| 1608 | * |
| 1609 | * @return 0 --success, otherwise fail |
| 1610 | */ |
| 1611 | int libertas_get_scan(struct net_device *dev, struct iw_request_info *info, |
| 1612 | struct iw_point *dwrq, char *extra) |
| 1613 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1614 | #define SCAN_ITEM_SIZE 128 |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1615 | wlan_private *priv = dev->priv; |
| 1616 | wlan_adapter *adapter = priv->adapter; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1617 | int err = 0; |
| 1618 | char *ev = extra; |
| 1619 | char *stop = ev + dwrq->length; |
| 1620 | struct bss_descriptor * iter_bss; |
| 1621 | struct bss_descriptor * safe; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1622 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1623 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1624 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1625 | /* If we've got an uncompleted scan, schedule the next part */ |
| 1626 | if (!adapter->nr_cmd_pending && adapter->last_scanned_channel) |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 1627 | wlan_scan_networks(priv, NULL, 0); |
Marcelo Tosatti | 2be9219 | 2007-05-25 00:33:28 -0400 | [diff] [blame] | 1628 | |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1629 | /* Update RSSI if current BSS is a locally created ad-hoc BSS */ |
Dan Williams | aeea0ab | 2007-05-25 22:30:48 -0400 | [diff] [blame] | 1630 | if ((adapter->mode == IW_MODE_ADHOC) && adapter->adhoccreate) { |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1631 | libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0, |
| 1632 | cmd_option_waitforrsp, 0, NULL); |
| 1633 | } |
| 1634 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1635 | mutex_lock(&adapter->lock); |
| 1636 | list_for_each_entry_safe (iter_bss, safe, &adapter->network_list, list) { |
| 1637 | char * next_ev; |
| 1638 | unsigned long stale_time; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1639 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1640 | if (stop - ev < SCAN_ITEM_SIZE) { |
| 1641 | err = -E2BIG; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1642 | break; |
| 1643 | } |
| 1644 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1645 | /* Prune old an old scan result */ |
| 1646 | stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE; |
| 1647 | if (time_after(jiffies, stale_time)) { |
| 1648 | list_move_tail (&iter_bss->list, |
| 1649 | &adapter->network_free_list); |
| 1650 | clear_bss_descriptor(iter_bss); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1651 | continue; |
| 1652 | } |
| 1653 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1654 | /* Translate to WE format this entry */ |
| 1655 | next_ev = libertas_translate_scan(priv, ev, stop, iter_bss); |
| 1656 | if (next_ev == NULL) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1657 | continue; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1658 | ev = next_ev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1659 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1660 | mutex_unlock(&adapter->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1661 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1662 | dwrq->length = (ev - extra); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1663 | dwrq->flags = 0; |
| 1664 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1665 | lbs_deb_leave(LBS_DEB_ASSOC); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1666 | return err; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | /** |
| 1670 | * @brief Prepare a scan command to be sent to the firmware |
| 1671 | * |
| 1672 | * Use the wlan_scan_cmd_config sent to the command processing module in |
| 1673 | * the libertas_prepare_and_send_command to configure a cmd_ds_802_11_scan command |
| 1674 | * struct to send to firmware. |
| 1675 | * |
| 1676 | * The fixed fields specifying the BSS type and BSSID filters as well as a |
| 1677 | * variable number/length of TLVs are sent in the command to firmware. |
| 1678 | * |
| 1679 | * @param priv A pointer to wlan_private structure |
| 1680 | * @param cmd A pointer to cmd_ds_command structure to be sent to |
| 1681 | * firmware with the cmd_DS_801_11_SCAN structure |
| 1682 | * @param pdata_buf Void pointer cast of a wlan_scan_cmd_config struct used |
| 1683 | * to set the fields/TLVs for the command sent to firmware |
| 1684 | * |
| 1685 | * @return 0 or -1 |
| 1686 | * |
| 1687 | * @sa wlan_scan_create_channel_list |
| 1688 | */ |
| 1689 | int libertas_cmd_80211_scan(wlan_private * priv, |
| 1690 | struct cmd_ds_command *cmd, void *pdata_buf) |
| 1691 | { |
| 1692 | struct cmd_ds_802_11_scan *pscan = &cmd->params.scan; |
| 1693 | struct wlan_scan_cmd_config *pscancfg; |
| 1694 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1695 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1696 | |
| 1697 | pscancfg = pdata_buf; |
| 1698 | |
| 1699 | /* Set fixed field variables in scan command */ |
| 1700 | pscan->bsstype = pscancfg->bsstype; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 1701 | memcpy(pscan->BSSID, pscancfg->bssid, sizeof(pscan->BSSID)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1702 | memcpy(pscan->tlvbuffer, pscancfg->tlvbuffer, pscancfg->tlvbufferlen); |
| 1703 | |
| 1704 | cmd->command = cpu_to_le16(cmd_802_11_scan); |
| 1705 | |
| 1706 | /* size is equal to the sizeof(fixed portions) + the TLV len + header */ |
| 1707 | cmd->size = cpu_to_le16(sizeof(pscan->bsstype) |
| 1708 | + sizeof(pscan->BSSID) |
| 1709 | + pscancfg->tlvbufferlen + S_DS_GEN); |
| 1710 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1711 | lbs_deb_scan("SCAN_CMD: command=%x, size=%x, seqnum=%x\n", |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1712 | le16_to_cpu(cmd->command), le16_to_cpu(cmd->size), |
| 1713 | le16_to_cpu(cmd->seqnum)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1714 | |
| 1715 | lbs_deb_leave(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1716 | return 0; |
| 1717 | } |
| 1718 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1719 | static inline int is_same_network(struct bss_descriptor *src, |
| 1720 | struct bss_descriptor *dst) |
| 1721 | { |
| 1722 | /* A network is only a duplicate if the channel, BSSID, and ESSID |
| 1723 | * all match. We treat all <hidden> with the same BSSID and channel |
| 1724 | * as one network */ |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1725 | return ((src->ssid_len == dst->ssid_len) && |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1726 | (src->channel == dst->channel) && |
| 1727 | !compare_ether_addr(src->bssid, dst->bssid) && |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 1728 | !memcmp(src->ssid, dst->ssid, src->ssid_len)); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1729 | } |
| 1730 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1731 | /** |
| 1732 | * @brief This function handles the command response of scan |
| 1733 | * |
| 1734 | * The response buffer for the scan command has the following |
| 1735 | * memory layout: |
| 1736 | * |
| 1737 | * .-----------------------------------------------------------. |
| 1738 | * | header (4 * sizeof(u16)): Standard command response hdr | |
| 1739 | * .-----------------------------------------------------------. |
| 1740 | * | bufsize (u16) : sizeof the BSS Description data | |
| 1741 | * .-----------------------------------------------------------. |
| 1742 | * | NumOfSet (u8) : Number of BSS Descs returned | |
| 1743 | * .-----------------------------------------------------------. |
| 1744 | * | BSSDescription data (variable, size given in bufsize) | |
| 1745 | * .-----------------------------------------------------------. |
| 1746 | * | TLV data (variable, size calculated using header->size, | |
| 1747 | * | bufsize and sizeof the fixed fields above) | |
| 1748 | * .-----------------------------------------------------------. |
| 1749 | * |
| 1750 | * @param priv A pointer to wlan_private structure |
| 1751 | * @param resp A pointer to cmd_ds_command |
| 1752 | * |
| 1753 | * @return 0 or -1 |
| 1754 | */ |
| 1755 | int libertas_ret_80211_scan(wlan_private * priv, struct cmd_ds_command *resp) |
| 1756 | { |
| 1757 | wlan_adapter *adapter = priv->adapter; |
| 1758 | struct cmd_ds_802_11_scan_rsp *pscan; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1759 | struct mrvlietypes_data *ptlv; |
| 1760 | struct mrvlietypes_tsftimestamp *ptsftlv; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1761 | struct bss_descriptor * iter_bss; |
| 1762 | struct bss_descriptor * safe; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1763 | u8 *pbssinfo; |
| 1764 | u16 scanrespsize; |
| 1765 | int bytesleft; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1766 | int idx; |
| 1767 | int tlvbufsize; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1768 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1769 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1770 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1771 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1772 | /* Prune old entries from scan table */ |
| 1773 | list_for_each_entry_safe (iter_bss, safe, &adapter->network_list, list) { |
| 1774 | unsigned long stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE; |
| 1775 | if (time_before(jiffies, stale_time)) |
| 1776 | continue; |
| 1777 | list_move_tail (&iter_bss->list, &adapter->network_free_list); |
| 1778 | clear_bss_descriptor(iter_bss); |
| 1779 | } |
| 1780 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1781 | pscan = &resp->params.scanresp; |
| 1782 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1783 | if (pscan->nr_sets > MAX_NETWORK_COUNT) { |
| 1784 | lbs_deb_scan( |
| 1785 | "SCAN_RESP: too many scan results (%d, max %d)!!\n", |
| 1786 | pscan->nr_sets, MAX_NETWORK_COUNT); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1787 | ret = -1; |
| 1788 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | bytesleft = le16_to_cpu(pscan->bssdescriptsize); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1792 | lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1793 | |
| 1794 | scanrespsize = le16_to_cpu(resp->size); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1795 | lbs_deb_scan("SCAN_RESP: returned %d AP before parsing\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1796 | pscan->nr_sets); |
| 1797 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1798 | pbssinfo = pscan->bssdesc_and_tlvbuffer; |
| 1799 | |
| 1800 | /* The size of the TLV buffer is equal to the entire command response |
| 1801 | * size (scanrespsize) minus the fixed fields (sizeof()'s), the |
| 1802 | * BSS Descriptions (bssdescriptsize as bytesLef) and the command |
| 1803 | * response header (S_DS_GEN) |
| 1804 | */ |
| 1805 | tlvbufsize = scanrespsize - (bytesleft + sizeof(pscan->bssdescriptsize) |
| 1806 | + sizeof(pscan->nr_sets) |
| 1807 | + S_DS_GEN); |
| 1808 | |
| 1809 | ptlv = (struct mrvlietypes_data *) (pscan->bssdesc_and_tlvbuffer + bytesleft); |
| 1810 | |
| 1811 | /* Search the TLV buffer space in the scan response for any valid TLVs */ |
| 1812 | wlan_ret_802_11_scan_get_tlv_ptrs(ptlv, tlvbufsize, &ptsftlv); |
| 1813 | |
| 1814 | /* |
| 1815 | * Process each scan response returned (pscan->nr_sets). Save |
| 1816 | * the information in the newbssentry and then insert into the |
| 1817 | * driver scan table either as an update to an existing entry |
| 1818 | * or as an addition at the end of the table |
| 1819 | */ |
| 1820 | for (idx = 0; idx < pscan->nr_sets && bytesleft; idx++) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1821 | struct bss_descriptor new; |
| 1822 | struct bss_descriptor * found = NULL; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1823 | struct bss_descriptor * oldest = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1824 | |
| 1825 | /* Process the data fields and IEs returned for this BSS */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1826 | memset(&new, 0, sizeof (struct bss_descriptor)); |
| 1827 | if (libertas_process_bss(&new, &pbssinfo, &bytesleft) != 0) { |
| 1828 | /* error parsing the scan response, skipped */ |
| 1829 | lbs_deb_scan("SCAN_RESP: process_bss returned ERROR\n"); |
| 1830 | continue; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1831 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1832 | |
| 1833 | /* Try to find this bss in the scan table */ |
| 1834 | list_for_each_entry (iter_bss, &adapter->network_list, list) { |
| 1835 | if (is_same_network(iter_bss, &new)) { |
| 1836 | found = iter_bss; |
| 1837 | break; |
| 1838 | } |
| 1839 | |
| 1840 | if ((oldest == NULL) || |
| 1841 | (iter_bss->last_scanned < oldest->last_scanned)) |
| 1842 | oldest = iter_bss; |
| 1843 | } |
| 1844 | |
| 1845 | if (found) { |
| 1846 | /* found, clear it */ |
| 1847 | clear_bss_descriptor(found); |
| 1848 | } else if (!list_empty(&adapter->network_free_list)) { |
| 1849 | /* Pull one from the free list */ |
| 1850 | found = list_entry(adapter->network_free_list.next, |
| 1851 | struct bss_descriptor, list); |
| 1852 | list_move_tail(&found->list, &adapter->network_list); |
| 1853 | } else if (oldest) { |
| 1854 | /* If there are no more slots, expire the oldest */ |
| 1855 | found = oldest; |
| 1856 | clear_bss_descriptor(found); |
| 1857 | list_move_tail(&found->list, &adapter->network_list); |
| 1858 | } else { |
| 1859 | continue; |
| 1860 | } |
| 1861 | |
| 1862 | lbs_deb_scan("SCAN_RESP: BSSID = " MAC_FMT "\n", |
| 1863 | new.bssid[0], new.bssid[1], new.bssid[2], |
| 1864 | new.bssid[3], new.bssid[4], new.bssid[5]); |
| 1865 | |
| 1866 | /* |
| 1867 | * If the TSF TLV was appended to the scan results, save the |
| 1868 | * this entries TSF value in the networktsf field. The |
| 1869 | * networktsf is the firmware's TSF value at the time the |
| 1870 | * beacon or probe response was received. |
| 1871 | */ |
| 1872 | if (ptsftlv) { |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1873 | new.networktsf = le64_to_cpup(&ptsftlv->tsftable[idx]); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | /* Copy the locally created newbssentry to the scan table */ |
| 1877 | memcpy(found, &new, offsetof(struct bss_descriptor, list)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1878 | } |
| 1879 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1880 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1881 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1882 | done: |
| 1883 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 1884 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1885 | } |