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