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