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