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