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 | */ |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 7 | #include <linux/types.h> |
Roel Kluin | 430453f | 2009-07-28 09:59:47 +0200 | [diff] [blame] | 8 | #include <linux/kernel.h> |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 9 | #include <linux/etherdevice.h> |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 10 | #include <linux/if_arp.h> |
Vladimir Davydov | ac630c2 | 2007-09-06 21:45:36 -0400 | [diff] [blame] | 11 | #include <asm/unaligned.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 12 | #include <net/lib80211.h> |
| 13 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 14 | #include "host.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 15 | #include "dev.h" |
| 16 | #include "scan.h" |
Holger Schurig | 2d46502 | 2009-10-22 15:30:48 +0200 | [diff] [blame] | 17 | #include "assoc.h" |
Holger Schurig | e93156e | 2009-10-22 15:30:58 +0200 | [diff] [blame] | 18 | #include "wext.h" |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 19 | #include "cmd.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 20 | |
| 21 | //! Approximate amount of data needed to pass a scan result back to iwlist |
| 22 | #define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \ |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 23 | + IEEE80211_MAX_SSID_LEN \ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 24 | + IW_EV_UINT_LEN \ |
| 25 | + IW_EV_FREQ_LEN \ |
| 26 | + IW_EV_QUAL_LEN \ |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 27 | + IEEE80211_MAX_SSID_LEN \ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 28 | + IW_EV_PARAM_LEN \ |
| 29 | + 40) /* 40 for WPAIE */ |
| 30 | |
| 31 | //! Memory needed to store a max sized channel List TLV for a firmware scan |
Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 32 | #define CHAN_TLV_MAX_SIZE (sizeof(struct mrvl_ie_header) \ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 33 | + (MRVDRV_MAX_CHANNELS_PER_SCAN \ |
| 34 | * sizeof(struct chanscanparamset))) |
| 35 | |
| 36 | //! Memory needed to store a max number/size SSID TLV for a firmware scan |
Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 37 | #define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvl_ie_ssid_param_set)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 38 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 39 | //! Maximum memory needed for a cmd_ds_802_11_scan with all TLVs at max |
| 40 | #define MAX_SCAN_CFG_ALLOC (sizeof(struct cmd_ds_802_11_scan) \ |
| 41 | + CHAN_TLV_MAX_SIZE + SSID_TLV_MAX_SIZE) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 42 | |
| 43 | //! The maximum number of channels the firmware can scan per command |
| 44 | #define MRVDRV_MAX_CHANNELS_PER_SCAN 14 |
| 45 | |
| 46 | /** |
| 47 | * @brief Number of channels to scan per firmware scan command issuance. |
| 48 | * |
| 49 | * Number restricted to prevent hitting the limit on the amount of scan data |
| 50 | * returned in a single firmware scan command. |
| 51 | */ |
| 52 | #define MRVDRV_CHANNELS_PER_SCAN_CMD 4 |
| 53 | |
| 54 | //! Scan time specified in the channel TLV for each channel for passive scans |
| 55 | #define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100 |
| 56 | |
| 57 | //! Scan time specified in the channel TLV for each channel for active scans |
| 58 | #define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100 |
| 59 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 60 | #define DEFAULT_MAX_SCAN_AGE (15 * HZ) |
| 61 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 62 | static int lbs_ret_80211_scan(struct lbs_private *priv, unsigned long dummy, |
| 63 | struct cmd_header *resp); |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 64 | |
| 65 | /*********************************************************************/ |
| 66 | /* */ |
| 67 | /* Misc helper functions */ |
| 68 | /* */ |
| 69 | /*********************************************************************/ |
| 70 | |
Holger Schurig | 23ff503 | 2008-01-28 17:27:03 +0100 | [diff] [blame] | 71 | /** |
| 72 | * @brief Unsets the MSB on basic rates |
| 73 | * |
| 74 | * Scan through an array and unset the MSB for basic data rates. |
| 75 | * |
| 76 | * @param rates buffer of data rates |
| 77 | * @param len size of buffer |
| 78 | */ |
| 79 | static void lbs_unset_basic_rate_flags(u8 *rates, size_t len) |
| 80 | { |
| 81 | int i; |
| 82 | |
| 83 | for (i = 0; i < len; i++) |
| 84 | rates[i] &= 0x7f; |
| 85 | } |
| 86 | |
| 87 | |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 88 | static inline void clear_bss_descriptor(struct bss_descriptor *bss) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 89 | { |
| 90 | /* Don't blow away ->list, just BSS data */ |
| 91 | memset(bss, 0, offsetof(struct bss_descriptor, list)); |
| 92 | } |
| 93 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 94 | /** |
| 95 | * @brief Compare two SSIDs |
| 96 | * |
| 97 | * @param ssid1 A pointer to ssid to compare |
| 98 | * @param ssid2 A pointer to ssid to compare |
| 99 | * |
| 100 | * @return 0: ssid is same, otherwise is different |
| 101 | */ |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 102 | int lbs_ssid_cmp(uint8_t *ssid1, uint8_t ssid1_len, uint8_t *ssid2, |
| 103 | uint8_t ssid2_len) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 104 | { |
| 105 | if (ssid1_len != ssid2_len) |
| 106 | return -1; |
| 107 | |
| 108 | return memcmp(ssid1, ssid2, ssid1_len); |
| 109 | } |
| 110 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 111 | static inline int is_same_network(struct bss_descriptor *src, |
| 112 | struct bss_descriptor *dst) |
| 113 | { |
| 114 | /* A network is only a duplicate if the channel, BSSID, and ESSID |
| 115 | * all match. We treat all <hidden> with the same BSSID and channel |
| 116 | * as one network */ |
| 117 | return ((src->ssid_len == dst->ssid_len) && |
| 118 | (src->channel == dst->channel) && |
| 119 | !compare_ether_addr(src->bssid, dst->bssid) && |
| 120 | !memcmp(src->ssid, dst->ssid, src->ssid_len)); |
| 121 | } |
| 122 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 123 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 124 | |
Holger Schurig | 2d46502 | 2009-10-22 15:30:48 +0200 | [diff] [blame] | 125 | /*********************************************************************/ |
| 126 | /* */ |
| 127 | /* Region channel support */ |
| 128 | /* */ |
| 129 | /*********************************************************************/ |
| 130 | |
| 131 | #define LBS_TX_PWR_DEFAULT 20 /*100mW */ |
| 132 | #define LBS_TX_PWR_US_DEFAULT 20 /*100mW */ |
| 133 | #define LBS_TX_PWR_JP_DEFAULT 16 /*50mW */ |
| 134 | #define LBS_TX_PWR_FR_DEFAULT 20 /*100mW */ |
| 135 | #define LBS_TX_PWR_EMEA_DEFAULT 20 /*100mW */ |
| 136 | |
| 137 | /* Format { channel, frequency (MHz), maxtxpower } */ |
| 138 | /* band: 'B/G', region: USA FCC/Canada IC */ |
| 139 | static struct chan_freq_power channel_freq_power_US_BG[] = { |
| 140 | {1, 2412, LBS_TX_PWR_US_DEFAULT}, |
| 141 | {2, 2417, LBS_TX_PWR_US_DEFAULT}, |
| 142 | {3, 2422, LBS_TX_PWR_US_DEFAULT}, |
| 143 | {4, 2427, LBS_TX_PWR_US_DEFAULT}, |
| 144 | {5, 2432, LBS_TX_PWR_US_DEFAULT}, |
| 145 | {6, 2437, LBS_TX_PWR_US_DEFAULT}, |
| 146 | {7, 2442, LBS_TX_PWR_US_DEFAULT}, |
| 147 | {8, 2447, LBS_TX_PWR_US_DEFAULT}, |
| 148 | {9, 2452, LBS_TX_PWR_US_DEFAULT}, |
| 149 | {10, 2457, LBS_TX_PWR_US_DEFAULT}, |
| 150 | {11, 2462, LBS_TX_PWR_US_DEFAULT} |
| 151 | }; |
| 152 | |
| 153 | /* band: 'B/G', region: Europe ETSI */ |
| 154 | static struct chan_freq_power channel_freq_power_EU_BG[] = { |
| 155 | {1, 2412, LBS_TX_PWR_EMEA_DEFAULT}, |
| 156 | {2, 2417, LBS_TX_PWR_EMEA_DEFAULT}, |
| 157 | {3, 2422, LBS_TX_PWR_EMEA_DEFAULT}, |
| 158 | {4, 2427, LBS_TX_PWR_EMEA_DEFAULT}, |
| 159 | {5, 2432, LBS_TX_PWR_EMEA_DEFAULT}, |
| 160 | {6, 2437, LBS_TX_PWR_EMEA_DEFAULT}, |
| 161 | {7, 2442, LBS_TX_PWR_EMEA_DEFAULT}, |
| 162 | {8, 2447, LBS_TX_PWR_EMEA_DEFAULT}, |
| 163 | {9, 2452, LBS_TX_PWR_EMEA_DEFAULT}, |
| 164 | {10, 2457, LBS_TX_PWR_EMEA_DEFAULT}, |
| 165 | {11, 2462, LBS_TX_PWR_EMEA_DEFAULT}, |
| 166 | {12, 2467, LBS_TX_PWR_EMEA_DEFAULT}, |
| 167 | {13, 2472, LBS_TX_PWR_EMEA_DEFAULT} |
| 168 | }; |
| 169 | |
| 170 | /* band: 'B/G', region: Spain */ |
| 171 | static struct chan_freq_power channel_freq_power_SPN_BG[] = { |
| 172 | {10, 2457, LBS_TX_PWR_DEFAULT}, |
| 173 | {11, 2462, LBS_TX_PWR_DEFAULT} |
| 174 | }; |
| 175 | |
| 176 | /* band: 'B/G', region: France */ |
| 177 | static struct chan_freq_power channel_freq_power_FR_BG[] = { |
| 178 | {10, 2457, LBS_TX_PWR_FR_DEFAULT}, |
| 179 | {11, 2462, LBS_TX_PWR_FR_DEFAULT}, |
| 180 | {12, 2467, LBS_TX_PWR_FR_DEFAULT}, |
| 181 | {13, 2472, LBS_TX_PWR_FR_DEFAULT} |
| 182 | }; |
| 183 | |
| 184 | /* band: 'B/G', region: Japan */ |
| 185 | static struct chan_freq_power channel_freq_power_JPN_BG[] = { |
| 186 | {1, 2412, LBS_TX_PWR_JP_DEFAULT}, |
| 187 | {2, 2417, LBS_TX_PWR_JP_DEFAULT}, |
| 188 | {3, 2422, LBS_TX_PWR_JP_DEFAULT}, |
| 189 | {4, 2427, LBS_TX_PWR_JP_DEFAULT}, |
| 190 | {5, 2432, LBS_TX_PWR_JP_DEFAULT}, |
| 191 | {6, 2437, LBS_TX_PWR_JP_DEFAULT}, |
| 192 | {7, 2442, LBS_TX_PWR_JP_DEFAULT}, |
| 193 | {8, 2447, LBS_TX_PWR_JP_DEFAULT}, |
| 194 | {9, 2452, LBS_TX_PWR_JP_DEFAULT}, |
| 195 | {10, 2457, LBS_TX_PWR_JP_DEFAULT}, |
| 196 | {11, 2462, LBS_TX_PWR_JP_DEFAULT}, |
| 197 | {12, 2467, LBS_TX_PWR_JP_DEFAULT}, |
| 198 | {13, 2472, LBS_TX_PWR_JP_DEFAULT}, |
| 199 | {14, 2484, LBS_TX_PWR_JP_DEFAULT} |
| 200 | }; |
| 201 | |
| 202 | /** |
| 203 | * the structure for channel, frequency and power |
| 204 | */ |
| 205 | struct region_cfp_table { |
| 206 | u8 region; |
| 207 | struct chan_freq_power *cfp_BG; |
| 208 | int cfp_no_BG; |
| 209 | }; |
| 210 | |
| 211 | /** |
| 212 | * the structure for the mapping between region and CFP |
| 213 | */ |
| 214 | static struct region_cfp_table region_cfp_table[] = { |
| 215 | {0x10, /*US FCC */ |
| 216 | channel_freq_power_US_BG, |
| 217 | ARRAY_SIZE(channel_freq_power_US_BG), |
| 218 | } |
| 219 | , |
| 220 | {0x20, /*CANADA IC */ |
| 221 | channel_freq_power_US_BG, |
| 222 | ARRAY_SIZE(channel_freq_power_US_BG), |
| 223 | } |
| 224 | , |
| 225 | {0x30, /*EU*/ channel_freq_power_EU_BG, |
| 226 | ARRAY_SIZE(channel_freq_power_EU_BG), |
| 227 | } |
| 228 | , |
| 229 | {0x31, /*SPAIN*/ channel_freq_power_SPN_BG, |
| 230 | ARRAY_SIZE(channel_freq_power_SPN_BG), |
| 231 | } |
| 232 | , |
| 233 | {0x32, /*FRANCE*/ channel_freq_power_FR_BG, |
| 234 | ARRAY_SIZE(channel_freq_power_FR_BG), |
| 235 | } |
| 236 | , |
| 237 | {0x40, /*JAPAN*/ channel_freq_power_JPN_BG, |
| 238 | ARRAY_SIZE(channel_freq_power_JPN_BG), |
| 239 | } |
| 240 | , |
| 241 | /*Add new region here */ |
| 242 | }; |
| 243 | |
| 244 | /** |
| 245 | * @brief This function finds the CFP in |
| 246 | * region_cfp_table based on region and band parameter. |
| 247 | * |
| 248 | * @param region The region code |
| 249 | * @param band The band |
| 250 | * @param cfp_no A pointer to CFP number |
| 251 | * @return A pointer to CFP |
| 252 | */ |
| 253 | static struct chan_freq_power *lbs_get_region_cfp_table(u8 region, int *cfp_no) |
| 254 | { |
| 255 | int i, end; |
| 256 | |
| 257 | lbs_deb_enter(LBS_DEB_MAIN); |
| 258 | |
| 259 | end = ARRAY_SIZE(region_cfp_table); |
| 260 | |
| 261 | for (i = 0; i < end ; i++) { |
| 262 | lbs_deb_main("region_cfp_table[i].region=%d\n", |
| 263 | region_cfp_table[i].region); |
| 264 | if (region_cfp_table[i].region == region) { |
| 265 | *cfp_no = region_cfp_table[i].cfp_no_BG; |
| 266 | lbs_deb_leave(LBS_DEB_MAIN); |
| 267 | return region_cfp_table[i].cfp_BG; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL"); |
| 272 | return NULL; |
| 273 | } |
| 274 | |
| 275 | int lbs_set_regiontable(struct lbs_private *priv, u8 region, u8 band) |
| 276 | { |
| 277 | int ret = 0; |
| 278 | int i = 0; |
| 279 | |
| 280 | struct chan_freq_power *cfp; |
| 281 | int cfp_no; |
| 282 | |
| 283 | lbs_deb_enter(LBS_DEB_MAIN); |
| 284 | |
| 285 | memset(priv->region_channel, 0, sizeof(priv->region_channel)); |
| 286 | |
| 287 | cfp = lbs_get_region_cfp_table(region, &cfp_no); |
| 288 | if (cfp != NULL) { |
| 289 | priv->region_channel[i].nrcfp = cfp_no; |
| 290 | priv->region_channel[i].CFP = cfp; |
| 291 | } else { |
| 292 | lbs_deb_main("wrong region code %#x in band B/G\n", |
| 293 | region); |
| 294 | ret = -1; |
| 295 | goto out; |
| 296 | } |
| 297 | priv->region_channel[i].valid = 1; |
| 298 | priv->region_channel[i].region = region; |
| 299 | priv->region_channel[i].band = band; |
| 300 | i++; |
| 301 | out: |
| 302 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
| 303 | return ret; |
| 304 | } |
| 305 | |
| 306 | |
| 307 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 308 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 309 | /*********************************************************************/ |
| 310 | /* */ |
| 311 | /* Main scanning support */ |
| 312 | /* */ |
| 313 | /*********************************************************************/ |
| 314 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 315 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 316 | * @brief Create a channel list for the driver to scan based on region info |
| 317 | * |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 318 | * Only used from lbs_scan_setup_scan_config() |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 319 | * |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 320 | * Use the driver region/band information to construct a comprehensive list |
| 321 | * of channels to scan. This routine is used for any scan that is not |
| 322 | * provided a specific channel list to scan. |
| 323 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 324 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 325 | * @param scanchanlist Output parameter: resulting channel list to scan |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 326 | * |
| 327 | * @return void |
| 328 | */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 329 | static int lbs_scan_create_channel_list(struct lbs_private *priv, |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 330 | struct chanscanparamset *scanchanlist) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 331 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 332 | struct region_channel *scanregion; |
| 333 | struct chan_freq_power *cfp; |
| 334 | int rgnidx; |
| 335 | int chanidx; |
| 336 | int nextchan; |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 337 | uint8_t scantype; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 338 | |
| 339 | chanidx = 0; |
| 340 | |
| 341 | /* Set the default scan type to the user specified type, will later |
| 342 | * be changed to passive on a per channel basis if restricted by |
| 343 | * regulatory requirements (11d or 11h) |
| 344 | */ |
Holger Schurig | 4f2fdaa | 2007-08-02 13:12:27 -0400 | [diff] [blame] | 345 | scantype = CMD_SCAN_TYPE_ACTIVE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 346 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 347 | for (rgnidx = 0; rgnidx < ARRAY_SIZE(priv->region_channel); rgnidx++) { |
Holger Schurig | d37b4fd | 2009-10-22 15:30:45 +0200 | [diff] [blame] | 348 | if (!priv->region_channel[rgnidx].valid) |
| 349 | continue; |
| 350 | scanregion = &priv->region_channel[rgnidx]; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 351 | |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 352 | for (nextchan = 0; nextchan < scanregion->nrcfp; nextchan++, chanidx++) { |
| 353 | struct chanscanparamset *chan = &scanchanlist[chanidx]; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 354 | |
| 355 | cfp = scanregion->CFP + nextchan; |
| 356 | |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 357 | if (scanregion->band == BAND_B || scanregion->band == BAND_G) |
| 358 | chan->radiotype = CMD_SCAN_RADIO_TYPE_BG; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 359 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 360 | if (scantype == CMD_SCAN_TYPE_PASSIVE) { |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 361 | chan->maxscantime = cpu_to_le16(MRVDRV_PASSIVE_SCAN_CHAN_TIME); |
| 362 | chan->chanscanmode.passivescan = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 363 | } else { |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 364 | chan->maxscantime = cpu_to_le16(MRVDRV_ACTIVE_SCAN_CHAN_TIME); |
| 365 | chan->chanscanmode.passivescan = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 366 | } |
| 367 | |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 368 | chan->channumber = cfp->channel; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 369 | } |
| 370 | } |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 371 | return chanidx; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 372 | } |
| 373 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 374 | /* |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 375 | * Add SSID TLV of the form: |
| 376 | * |
| 377 | * TLV-ID SSID 00 00 |
| 378 | * length 06 00 |
| 379 | * ssid 4d 4e 54 45 53 54 |
| 380 | */ |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 381 | static int lbs_scan_add_ssid_tlv(struct lbs_private *priv, u8 *tlv) |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 382 | { |
Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 383 | struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv; |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 384 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 385 | ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID); |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 386 | ssid_tlv->header.len = cpu_to_le16(priv->scan_ssid_len); |
| 387 | memcpy(ssid_tlv->ssid, priv->scan_ssid, priv->scan_ssid_len); |
| 388 | return sizeof(ssid_tlv->header) + priv->scan_ssid_len; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 389 | } |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 390 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 391 | /* |
| 392 | * Add CHANLIST TLV of the form |
| 393 | * |
| 394 | * TLV-ID CHANLIST 01 01 |
| 395 | * length 5b 00 |
| 396 | * channel 1 00 01 00 00 00 64 00 |
| 397 | * radio type 00 |
| 398 | * channel 01 |
| 399 | * scan type 00 |
| 400 | * min scan time 00 00 |
| 401 | * max scan time 64 00 |
| 402 | * channel 2 00 02 00 00 00 64 00 |
| 403 | * channel 3 00 03 00 00 00 64 00 |
| 404 | * channel 4 00 04 00 00 00 64 00 |
| 405 | * channel 5 00 05 00 00 00 64 00 |
| 406 | * channel 6 00 06 00 00 00 64 00 |
| 407 | * channel 7 00 07 00 00 00 64 00 |
| 408 | * channel 8 00 08 00 00 00 64 00 |
| 409 | * channel 9 00 09 00 00 00 64 00 |
| 410 | * channel 10 00 0a 00 00 00 64 00 |
| 411 | * channel 11 00 0b 00 00 00 64 00 |
| 412 | * channel 12 00 0c 00 00 00 64 00 |
| 413 | * channel 13 00 0d 00 00 00 64 00 |
| 414 | * |
| 415 | */ |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 416 | static int lbs_scan_add_chanlist_tlv(uint8_t *tlv, |
| 417 | struct chanscanparamset *chan_list, |
| 418 | int chan_count) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 419 | { |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 420 | size_t size = sizeof(struct chanscanparamset) *chan_count; |
Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 421 | struct mrvl_ie_chanlist_param_set *chan_tlv = (void *)tlv; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 422 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 423 | chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); |
| 424 | memcpy(chan_tlv->chanscanparam, chan_list, size); |
| 425 | chan_tlv->header.len = cpu_to_le16(size); |
| 426 | return sizeof(chan_tlv->header) + size; |
| 427 | } |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 428 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 429 | /* |
| 430 | * Add RATES TLV of the form |
| 431 | * |
| 432 | * TLV-ID RATES 01 00 |
| 433 | * length 0e 00 |
| 434 | * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c |
| 435 | * |
| 436 | * The rates are in lbs_bg_rates[], but for the 802.11b |
| 437 | * rates the high bit isn't set. |
| 438 | */ |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 439 | static int lbs_scan_add_rates_tlv(uint8_t *tlv) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 440 | { |
| 441 | int i; |
Dan Williams | 75b6a61 | 2009-05-22 20:03:09 -0400 | [diff] [blame] | 442 | struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 443 | |
| 444 | rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES); |
| 445 | tlv += sizeof(rate_tlv->header); |
| 446 | for (i = 0; i < MAX_RATES; i++) { |
| 447 | *tlv = lbs_bg_rates[i]; |
| 448 | if (*tlv == 0) |
| 449 | break; |
| 450 | /* This code makes sure that the 802.11b rates (1 MBit/s, 2 |
| 451 | MBit/s, 5.5 MBit/s and 11 MBit/s get's the high bit set. |
| 452 | Note that the values are MBit/s * 2, to mark them as |
| 453 | basic rates so that the firmware likes it better */ |
| 454 | if (*tlv == 0x02 || *tlv == 0x04 || |
| 455 | *tlv == 0x0b || *tlv == 0x16) |
| 456 | *tlv |= 0x80; |
| 457 | tlv++; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 458 | } |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 459 | rate_tlv->header.len = cpu_to_le16(i); |
| 460 | return sizeof(rate_tlv->header) + i; |
| 461 | } |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 462 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 463 | /* |
| 464 | * Generate the CMD_802_11_SCAN command with the proper tlv |
| 465 | * for a bunch of channels. |
| 466 | */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 467 | static int lbs_do_scan(struct lbs_private *priv, uint8_t bsstype, |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 468 | struct chanscanparamset *chan_list, int chan_count) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 469 | { |
| 470 | int ret = -ENOMEM; |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 471 | struct cmd_ds_802_11_scan *scan_cmd; |
| 472 | uint8_t *tlv; /* pointer into our current, growing TLV storage area */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 473 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 474 | lbs_deb_enter_args(LBS_DEB_SCAN, "bsstype %d, chanlist[].chan %d, chan_count %d", |
Holger Schurig | c0d4399 | 2008-04-29 10:07:56 +0200 | [diff] [blame] | 475 | bsstype, chan_list ? chan_list[0].channumber : -1, |
| 476 | chan_count); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 477 | |
| 478 | /* create the fixed part for scan command */ |
| 479 | scan_cmd = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL); |
| 480 | if (scan_cmd == NULL) |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 481 | goto out; |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 482 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 483 | tlv = scan_cmd->tlvbuffer; |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 484 | /* TODO: do we need to scan for a specific BSSID? |
| 485 | memcpy(scan_cmd->bssid, priv->scan_bssid, ETH_ALEN); */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 486 | scan_cmd->bsstype = bsstype; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 487 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 488 | /* add TLVs */ |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 489 | if (priv->scan_ssid_len) |
| 490 | tlv += lbs_scan_add_ssid_tlv(priv, tlv); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 491 | if (chan_list && chan_count) |
| 492 | tlv += lbs_scan_add_chanlist_tlv(tlv, chan_list, chan_count); |
| 493 | tlv += lbs_scan_add_rates_tlv(tlv); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 494 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 495 | /* This is the final data we are about to send */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 496 | scan_cmd->hdr.size = cpu_to_le16(tlv - (uint8_t *)scan_cmd); |
| 497 | lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd, |
| 498 | sizeof(*scan_cmd)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 499 | lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer, |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 500 | tlv - scan_cmd->tlvbuffer); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 501 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 502 | ret = __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr, |
| 503 | le16_to_cpu(scan_cmd->hdr.size), |
| 504 | lbs_ret_80211_scan, 0); |
| 505 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 506 | out: |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 507 | kfree(scan_cmd); |
| 508 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 509 | return ret; |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 510 | } |
| 511 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 512 | /** |
| 513 | * @brief Internal function used to start a scan based on an input config |
| 514 | * |
| 515 | * Use the input user scan configuration information when provided in |
| 516 | * order to send the appropriate scan commands to firmware to populate or |
| 517 | * update the internal driver scan table |
| 518 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 519 | * @param priv A pointer to struct lbs_private structure |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 520 | * @param full_scan Do a full-scan (blocking) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 521 | * |
| 522 | * @return 0 or < 0 if error |
| 523 | */ |
Holger Schurig | 245bf20 | 2008-04-02 16:27:42 +0200 | [diff] [blame] | 524 | int lbs_scan_networks(struct lbs_private *priv, int full_scan) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 525 | { |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 526 | int ret = -ENOMEM; |
| 527 | struct chanscanparamset *chan_list; |
| 528 | struct chanscanparamset *curr_chans; |
| 529 | int chan_count; |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 530 | uint8_t bsstype = CMD_BSS_TYPE_ANY; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 531 | int numchannels = MRVDRV_CHANNELS_PER_SCAN_CMD; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 532 | union iwreq_data wrqu; |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 533 | #ifdef CONFIG_LIBERTAS_DEBUG |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 534 | struct bss_descriptor *iter; |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 535 | int i = 0; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 536 | DECLARE_SSID_BUF(ssid); |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 537 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 538 | |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 539 | lbs_deb_enter_args(LBS_DEB_SCAN, "full_scan %d", full_scan); |
Dan Williams | 2afc0c5 | 2007-08-02 13:19:04 -0400 | [diff] [blame] | 540 | |
| 541 | /* Cancel any partial outstanding partial scans if this scan |
| 542 | * is a full scan. |
| 543 | */ |
| 544 | if (full_scan && delayed_work_pending(&priv->scan_work)) |
| 545 | cancel_delayed_work(&priv->scan_work); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 546 | |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 547 | /* User-specified bsstype or channel list |
| 548 | TODO: this can be implemented if some user-space application |
| 549 | need the feature. Formerly, it was accessible from debugfs, |
| 550 | but then nowhere used. |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 551 | if (user_cfg) { |
| 552 | if (user_cfg->bsstype) |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 553 | bsstype = user_cfg->bsstype; |
| 554 | } */ |
| 555 | |
| 556 | lbs_deb_scan("numchannels %d, bsstype %d\n", numchannels, bsstype); |
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 | /* Create list of channels to scan */ |
| 559 | chan_list = kzalloc(sizeof(struct chanscanparamset) * |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 560 | LBS_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 561 | if (!chan_list) { |
| 562 | lbs_pr_alert("SCAN: chan_list empty\n"); |
| 563 | goto out; |
| 564 | } |
| 565 | |
| 566 | /* We want to scan all channels */ |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 567 | chan_count = lbs_scan_create_channel_list(priv, chan_list); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 568 | |
| 569 | netif_stop_queue(priv->dev); |
| 570 | netif_carrier_off(priv->dev); |
| 571 | if (priv->mesh_dev) { |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 572 | netif_stop_queue(priv->mesh_dev); |
| 573 | netif_carrier_off(priv->mesh_dev); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /* Prepare to continue an interrupted scan */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 577 | lbs_deb_scan("chan_count %d, scan_channel %d\n", |
| 578 | chan_count, priv->scan_channel); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 579 | curr_chans = chan_list; |
| 580 | /* advance channel list by already-scanned-channels */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 581 | if (priv->scan_channel > 0) { |
| 582 | curr_chans += priv->scan_channel; |
| 583 | chan_count -= priv->scan_channel; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /* Send scan command(s) |
| 587 | * numchannels contains the number of channels we should maximally scan |
| 588 | * chan_count is the total number of channels to scan |
| 589 | */ |
| 590 | |
| 591 | while (chan_count) { |
| 592 | int to_scan = min(numchannels, chan_count); |
| 593 | lbs_deb_scan("scanning %d of %d channels\n", |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 594 | to_scan, chan_count); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 595 | ret = lbs_do_scan(priv, bsstype, curr_chans, |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 596 | to_scan); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 597 | if (ret) { |
| 598 | lbs_pr_err("SCAN_CMD failed\n"); |
| 599 | goto out2; |
| 600 | } |
| 601 | curr_chans += to_scan; |
| 602 | chan_count -= to_scan; |
| 603 | |
| 604 | /* somehow schedule the next part of the scan */ |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 605 | if (chan_count && !full_scan && |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 606 | !priv->surpriseremoved) { |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 607 | /* -1 marks just that we're currently scanning */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 608 | if (priv->scan_channel < 0) |
| 609 | priv->scan_channel = to_scan; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 610 | else |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 611 | priv->scan_channel += to_scan; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 612 | cancel_delayed_work(&priv->scan_work); |
| 613 | queue_delayed_work(priv->work_thread, &priv->scan_work, |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 614 | msecs_to_jiffies(300)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 615 | /* skip over GIWSCAN event */ |
| 616 | goto out; |
| 617 | } |
| 618 | |
| 619 | } |
| 620 | memset(&wrqu, 0, sizeof(union iwreq_data)); |
| 621 | wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 622 | |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 623 | #ifdef CONFIG_LIBERTAS_DEBUG |
| 624 | /* Dump the scan table */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 625 | mutex_lock(&priv->lock); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 626 | lbs_deb_scan("scan table:\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 627 | list_for_each_entry(iter, &priv->network_list, list) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 628 | lbs_deb_scan("%02d: BSSID %pM, RSSI %d, SSID '%s'\n", |
| 629 | i++, iter->bssid, iter->rssi, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 630 | print_ssid(ssid, iter->ssid, iter->ssid_len)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 631 | mutex_unlock(&priv->lock); |
Dan Williams | f8f5510 | 2007-05-30 10:12:55 -0400 | [diff] [blame] | 632 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 633 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 634 | out2: |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 635 | priv->scan_channel = 0; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 636 | |
| 637 | out: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 638 | if (priv->connect_status == LBS_CONNECTED) { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 639 | netif_carrier_on(priv->dev); |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 640 | if (!priv->tx_pending_len) |
| 641 | netif_wake_queue(priv->dev); |
Brajesh Dave | 01d77d8 | 2007-11-20 17:44:14 -0500 | [diff] [blame] | 642 | } |
Holger Schurig | 602114a | 2009-12-02 15:26:01 +0100 | [diff] [blame^] | 643 | if (priv->mesh_dev && lbs_mesh_connected(priv)) { |
Brajesh Dave | 01d77d8 | 2007-11-20 17:44:14 -0500 | [diff] [blame] | 644 | netif_carrier_on(priv->mesh_dev); |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 645 | if (!priv->tx_pending_len) |
| 646 | netif_wake_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 647 | } |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 648 | kfree(chan_list); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 649 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 650 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 651 | return ret; |
| 652 | } |
| 653 | |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 654 | void lbs_scan_worker(struct work_struct *work) |
| 655 | { |
| 656 | struct lbs_private *priv = |
| 657 | container_of(work, struct lbs_private, scan_work.work); |
| 658 | |
| 659 | lbs_deb_enter(LBS_DEB_SCAN); |
| 660 | lbs_scan_networks(priv, 0); |
| 661 | lbs_deb_leave(LBS_DEB_SCAN); |
| 662 | } |
| 663 | |
| 664 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 665 | /*********************************************************************/ |
| 666 | /* */ |
| 667 | /* Result interpretation */ |
| 668 | /* */ |
| 669 | /*********************************************************************/ |
| 670 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 671 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 672 | * @brief Interpret a BSS scan response returned from the firmware |
| 673 | * |
| 674 | * 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] | 675 | * response or beacon from the scan command. Record information as needed |
| 676 | * in the scan table struct bss_descriptor for that entry. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 677 | * |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 678 | * @param bss Output parameter: Pointer to the BSS Entry |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 679 | * |
| 680 | * @return 0 or -1 |
| 681 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 682 | static int lbs_process_bss(struct bss_descriptor *bss, |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 683 | uint8_t **pbeaconinfo, int *bytesleft) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 684 | { |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 685 | struct ieee_ie_fh_param_set *fh; |
| 686 | struct ieee_ie_ds_param_set *ds; |
| 687 | struct ieee_ie_cf_param_set *cf; |
| 688 | struct ieee_ie_ibss_param_set *ibss; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 689 | DECLARE_SSID_BUF(ssid); |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 690 | uint8_t *pos, *end, *p; |
| 691 | uint8_t n_ex_rates = 0, got_basic_rates = 0, n_basic_rates = 0; |
| 692 | uint16_t beaconsize = 0; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 693 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 694 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 695 | lbs_deb_enter(LBS_DEB_SCAN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 696 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 697 | if (*bytesleft >= sizeof(beaconsize)) { |
| 698 | /* Extract & convert beacon size from the command buffer */ |
Harvey Harrison | 533dd1b | 2008-04-29 01:03:36 -0700 | [diff] [blame] | 699 | beaconsize = get_unaligned_le16(*pbeaconinfo); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 700 | *bytesleft -= sizeof(beaconsize); |
| 701 | *pbeaconinfo += sizeof(beaconsize); |
| 702 | } |
| 703 | |
| 704 | if (beaconsize == 0 || beaconsize > *bytesleft) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 705 | *pbeaconinfo += *bytesleft; |
| 706 | *bytesleft = 0; |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 707 | ret = -1; |
| 708 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /* Initialize the current working beacon pointer for this BSS iteration */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 712 | pos = *pbeaconinfo; |
| 713 | end = pos + beaconsize; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 714 | |
| 715 | /* Advance the return beacon pointer past the current beacon */ |
| 716 | *pbeaconinfo += beaconsize; |
| 717 | *bytesleft -= beaconsize; |
| 718 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 719 | memcpy(bss->bssid, pos, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 720 | lbs_deb_scan("process_bss: BSSID %pM\n", bss->bssid); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 721 | pos += ETH_ALEN; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 722 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 723 | if ((end - pos) < 12) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 724 | lbs_deb_scan("process_bss: Not enough bytes left\n"); |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 725 | ret = -1; |
| 726 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /* |
| 730 | * next 4 fields are RSSI, time stamp, beacon interval, |
| 731 | * and capability information |
| 732 | */ |
| 733 | |
| 734 | /* RSSI is 1 byte long */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 735 | bss->rssi = *pos; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 736 | lbs_deb_scan("process_bss: RSSI %d\n", *pos); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 737 | pos++; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 738 | |
| 739 | /* time stamp is 8 bytes long */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 740 | pos += 8; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 741 | |
| 742 | /* beacon interval is 2 bytes long */ |
Ihar Hrachyshka | 814feef | 2008-07-09 09:29:58 +0300 | [diff] [blame] | 743 | bss->beaconperiod = get_unaligned_le16(pos); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 744 | pos += 2; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 745 | |
| 746 | /* capability information is 2 bytes long */ |
Ihar Hrachyshka | 814feef | 2008-07-09 09:29:58 +0300 | [diff] [blame] | 747 | bss->capability = get_unaligned_le16(pos); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 748 | lbs_deb_scan("process_bss: capabilities 0x%04x\n", bss->capability); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 749 | pos += 2; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 750 | |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 751 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 752 | lbs_deb_scan("process_bss: WEP enabled\n"); |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 753 | if (bss->capability & WLAN_CAPABILITY_IBSS) |
| 754 | bss->mode = IW_MODE_ADHOC; |
| 755 | else |
| 756 | bss->mode = IW_MODE_INFRA; |
| 757 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 758 | /* rest of the current buffer are IE's */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 759 | lbs_deb_scan("process_bss: IE len %zd\n", end - pos); |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 760 | 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] | 761 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 762 | /* process variable IE */ |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 763 | while (pos <= end - 2) { |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 764 | if (pos + pos[1] > end) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 765 | lbs_deb_scan("process_bss: error in processing IE, " |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 766 | "bytes left < IE length\n"); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 767 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 768 | } |
| 769 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 770 | switch (pos[0]) { |
| 771 | case WLAN_EID_SSID: |
| 772 | bss->ssid_len = min_t(int, IEEE80211_MAX_SSID_LEN, pos[1]); |
| 773 | memcpy(bss->ssid, pos + 2, bss->ssid_len); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 774 | lbs_deb_scan("got SSID IE: '%s', len %u\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 775 | print_ssid(ssid, bss->ssid, bss->ssid_len), |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 776 | bss->ssid_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 777 | break; |
| 778 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 779 | case WLAN_EID_SUPP_RATES: |
| 780 | n_basic_rates = min_t(uint8_t, MAX_RATES, pos[1]); |
| 781 | memcpy(bss->rates, pos + 2, n_basic_rates); |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 782 | got_basic_rates = 1; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 783 | lbs_deb_scan("got RATES IE\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 784 | break; |
| 785 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 786 | case WLAN_EID_FH_PARAMS: |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 787 | fh = (struct ieee_ie_fh_param_set *) pos; |
| 788 | memcpy(&bss->phy.fh, fh, sizeof(*fh)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 789 | lbs_deb_scan("got FH IE\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 790 | break; |
| 791 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 792 | case WLAN_EID_DS_PARAMS: |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 793 | ds = (struct ieee_ie_ds_param_set *) pos; |
| 794 | bss->channel = ds->channel; |
| 795 | memcpy(&bss->phy.ds, ds, sizeof(*ds)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 796 | lbs_deb_scan("got DS IE, channel %d\n", bss->channel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 797 | break; |
| 798 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 799 | case WLAN_EID_CF_PARAMS: |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 800 | cf = (struct ieee_ie_cf_param_set *) pos; |
| 801 | memcpy(&bss->ss.cf, cf, sizeof(*cf)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 802 | lbs_deb_scan("got CF IE\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 803 | break; |
| 804 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 805 | case WLAN_EID_IBSS_PARAMS: |
Dan Williams | 5fd164e | 2009-05-22 20:01:21 -0400 | [diff] [blame] | 806 | ibss = (struct ieee_ie_ibss_param_set *) pos; |
| 807 | bss->atimwindow = ibss->atimwindow; |
| 808 | memcpy(&bss->ss.ibss, ibss, sizeof(*ibss)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 809 | lbs_deb_scan("got IBSS IE\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 810 | break; |
| 811 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 812 | case WLAN_EID_EXT_SUPP_RATES: |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 813 | /* only process extended supported rate if data rate is |
| 814 | * already found. Data rate IE should come before |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 815 | * extended supported rate IE |
| 816 | */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 817 | lbs_deb_scan("got RATESEX IE\n"); |
| 818 | if (!got_basic_rates) { |
| 819 | lbs_deb_scan("... but ignoring it\n"); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 820 | break; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 821 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 822 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 823 | n_ex_rates = pos[1]; |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 824 | if (n_basic_rates + n_ex_rates > MAX_RATES) |
| 825 | n_ex_rates = MAX_RATES - n_basic_rates; |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 826 | |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 827 | p = bss->rates + n_basic_rates; |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 828 | memcpy(p, pos + 2, n_ex_rates); |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 829 | break; |
| 830 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 831 | case WLAN_EID_GENERIC: |
| 832 | if (pos[1] >= 4 && |
| 833 | pos[2] == 0x00 && pos[3] == 0x50 && |
| 834 | pos[4] == 0xf2 && pos[5] == 0x01) { |
| 835 | bss->wpa_ie_len = min(pos[1] + 2, MAX_WPA_IE_LEN); |
| 836 | memcpy(bss->wpa_ie, pos, bss->wpa_ie_len); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 837 | lbs_deb_scan("got WPA IE\n"); |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 838 | lbs_deb_hex(LBS_DEB_SCAN, "WPA IE", bss->wpa_ie, |
| 839 | bss->wpa_ie_len); |
| 840 | } else if (pos[1] >= MARVELL_MESH_IE_LENGTH && |
| 841 | pos[2] == 0x00 && pos[3] == 0x50 && |
Roel Kluin | baf62ee | 2009-02-03 17:15:57 +0100 | [diff] [blame] | 842 | pos[4] == 0x43 && pos[5] == 0x04) { |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 843 | lbs_deb_scan("got mesh IE\n"); |
Luis Carlos Cobo | 1e838bf | 2007-08-02 10:51:27 -0400 | [diff] [blame] | 844 | bss->mesh = 1; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 845 | } else { |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 846 | lbs_deb_scan("got generic IE: %02x:%02x:%02x:%02x, len %d\n", |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 847 | pos[2], pos[3], |
| 848 | pos[4], pos[5], |
| 849 | pos[1]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 850 | } |
| 851 | break; |
| 852 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 853 | case WLAN_EID_RSN: |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 854 | lbs_deb_scan("got RSN IE\n"); |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 855 | bss->rsn_ie_len = min(pos[1] + 2, MAX_WPA_IE_LEN); |
| 856 | memcpy(bss->rsn_ie, pos, bss->rsn_ie_len); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 857 | lbs_deb_hex(LBS_DEB_SCAN, "process_bss: RSN_IE", |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 858 | bss->rsn_ie, bss->rsn_ie_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 859 | break; |
| 860 | |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 861 | default: |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 862 | lbs_deb_scan("got IE 0x%04x, len %d\n", |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 863 | pos[0], pos[1]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 864 | break; |
| 865 | } |
| 866 | |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 867 | pos += pos[1] + 2; |
Dan Williams | ab61797 | 2007-08-02 10:48:02 -0400 | [diff] [blame] | 868 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 869 | |
| 870 | /* Timestamp */ |
| 871 | bss->last_scanned = jiffies; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 872 | lbs_unset_basic_rate_flags(bss->rates, sizeof(bss->rates)); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 873 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 874 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 875 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 876 | done: |
| 877 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 878 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 882 | * @brief Send a scan command for all available channels filtered on a spec |
| 883 | * |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 884 | * Used in association code and from debugfs |
| 885 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 886 | * @param priv A pointer to struct lbs_private structure |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 887 | * @param ssid A pointer to the SSID to scan for |
| 888 | * @param ssid_len Length of the SSID |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 889 | * |
| 890 | * @return 0-success, otherwise fail |
| 891 | */ |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 892 | int lbs_send_specific_ssid_scan(struct lbs_private *priv, uint8_t *ssid, |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 893 | uint8_t ssid_len) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 894 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 895 | DECLARE_SSID_BUF(ssid_buf); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 896 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 897 | |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 898 | lbs_deb_enter_args(LBS_DEB_SCAN, "SSID '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 899 | print_ssid(ssid_buf, ssid, ssid_len)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 900 | |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 901 | if (!ssid_len) |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 902 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 903 | |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 904 | memcpy(priv->scan_ssid, ssid, ssid_len); |
| 905 | priv->scan_ssid_len = ssid_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 906 | |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 907 | lbs_scan_networks(priv, 1); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 908 | if (priv->surpriseremoved) { |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 909 | ret = -1; |
| 910 | goto out; |
| 911 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 912 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 913 | out: |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 914 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 915 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 916 | } |
| 917 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 918 | |
| 919 | |
| 920 | |
| 921 | /*********************************************************************/ |
| 922 | /* */ |
| 923 | /* Support for Wireless Extensions */ |
| 924 | /* */ |
| 925 | /*********************************************************************/ |
| 926 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 927 | |
Dan Williams | 00af015 | 2007-08-02 13:14:56 -0400 | [diff] [blame] | 928 | #define MAX_CUSTOM_LEN 64 |
| 929 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 930 | static inline char *lbs_translate_scan(struct lbs_private *priv, |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 931 | struct iw_request_info *info, |
| 932 | char *start, char *stop, |
| 933 | struct bss_descriptor *bss) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 934 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 935 | struct chan_freq_power *cfp; |
| 936 | char *current_val; /* For rates */ |
| 937 | struct iw_event iwe; /* Temporary buffer */ |
| 938 | int j; |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 939 | #define PERFECT_RSSI ((uint8_t)50) |
| 940 | #define WORST_RSSI ((uint8_t)0) |
| 941 | #define RSSI_DIFF ((uint8_t)(PERFECT_RSSI - WORST_RSSI)) |
| 942 | uint8_t rssi; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 943 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 944 | lbs_deb_enter(LBS_DEB_SCAN); |
| 945 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 946 | cfp = lbs_find_cfp_by_band_and_channel(priv, 0, bss->channel); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 947 | if (!cfp) { |
| 948 | lbs_deb_scan("Invalid channel number %d\n", bss->channel); |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 949 | start = NULL; |
| 950 | goto out; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 951 | } |
| 952 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 953 | /* First entry *MUST* be the BSSID */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 954 | iwe.cmd = SIOCGIWAP; |
| 955 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 956 | memcpy(iwe.u.ap_addr.sa_data, &bss->bssid, ETH_ALEN); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 957 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 958 | |
| 959 | /* SSID */ |
| 960 | iwe.cmd = SIOCGIWESSID; |
| 961 | iwe.u.data.flags = 1; |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 962 | iwe.u.data.length = min((uint32_t) bss->ssid_len, (uint32_t) IEEE80211_MAX_SSID_LEN); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 963 | start = iwe_stream_add_point(info, start, stop, &iwe, bss->ssid); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 964 | |
| 965 | /* Mode */ |
| 966 | iwe.cmd = SIOCGIWMODE; |
| 967 | iwe.u.mode = bss->mode; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 968 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 969 | |
| 970 | /* Frequency */ |
| 971 | iwe.cmd = SIOCGIWFREQ; |
| 972 | iwe.u.freq.m = (long)cfp->freq * 100000; |
| 973 | iwe.u.freq.e = 1; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 974 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 975 | |
| 976 | /* Add quality statistics */ |
| 977 | iwe.cmd = IWEVQUAL; |
| 978 | iwe.u.qual.updated = IW_QUAL_ALL_UPDATED; |
| 979 | iwe.u.qual.level = SCAN_RSSI(bss->rssi); |
| 980 | |
| 981 | rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE; |
| 982 | iwe.u.qual.qual = |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 983 | (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) * |
| 984 | (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) / |
| 985 | (RSSI_DIFF * RSSI_DIFF); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 986 | if (iwe.u.qual.qual > 100) |
| 987 | iwe.u.qual.qual = 100; |
| 988 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 989 | if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 990 | iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE; |
| 991 | } else { |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 992 | iwe.u.qual.noise = CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 993 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 994 | |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 995 | /* Locally created ad-hoc BSSs won't have beacons if this is the |
| 996 | * only station in the adhoc network; so get signal strength |
| 997 | * from receive statistics. |
| 998 | */ |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 999 | if ((priv->mode == IW_MODE_ADHOC) && priv->adhoccreate |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1000 | && !lbs_ssid_cmp(priv->curbssparams.ssid, |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1001 | priv->curbssparams.ssid_len, |
| 1002 | bss->ssid, bss->ssid_len)) { |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1003 | int snr, nf; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1004 | snr = priv->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE; |
| 1005 | nf = priv->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE; |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1006 | iwe.u.qual.level = CAL_RSSI(snr, nf); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1007 | } |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1008 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1009 | |
| 1010 | /* Add encryption capability */ |
| 1011 | iwe.cmd = SIOCGIWENCODE; |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 1012 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1013 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 1014 | } else { |
| 1015 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 1016 | } |
| 1017 | iwe.u.data.length = 0; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1018 | start = iwe_stream_add_point(info, start, stop, &iwe, bss->ssid); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1019 | |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1020 | current_val = start + iwe_stream_lcp_len(info); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1021 | |
| 1022 | iwe.cmd = SIOCGIWRATE; |
| 1023 | iwe.u.bitrate.fixed = 0; |
| 1024 | iwe.u.bitrate.disabled = 0; |
| 1025 | iwe.u.bitrate.value = 0; |
| 1026 | |
Roel Kluin | 430453f | 2009-07-28 09:59:47 +0200 | [diff] [blame] | 1027 | for (j = 0; j < ARRAY_SIZE(bss->rates) && bss->rates[j]; j++) { |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 1028 | /* Bit rate given in 500 kb/s units */ |
| 1029 | iwe.u.bitrate.value = bss->rates[j] * 500000; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1030 | current_val = iwe_stream_add_value(info, start, current_val, |
| 1031 | stop, &iwe, IW_EV_PARAM_LEN); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1032 | } |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1033 | if ((bss->mode == IW_MODE_ADHOC) && priv->adhoccreate |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1034 | && !lbs_ssid_cmp(priv->curbssparams.ssid, |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1035 | priv->curbssparams.ssid_len, |
| 1036 | bss->ssid, bss->ssid_len)) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1037 | iwe.u.bitrate.value = 22 * 500000; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1038 | current_val = iwe_stream_add_value(info, start, current_val, |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1039 | stop, &iwe, IW_EV_PARAM_LEN); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1040 | } |
| 1041 | /* Check if we added any event */ |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1042 | if ((current_val - start) > iwe_stream_lcp_len(info)) |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1043 | start = current_val; |
| 1044 | |
| 1045 | memset(&iwe, 0, sizeof(iwe)); |
| 1046 | if (bss->wpa_ie_len) { |
| 1047 | char buf[MAX_WPA_IE_LEN]; |
| 1048 | memcpy(buf, bss->wpa_ie, bss->wpa_ie_len); |
| 1049 | iwe.cmd = IWEVGENIE; |
| 1050 | iwe.u.data.length = bss->wpa_ie_len; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1051 | start = iwe_stream_add_point(info, start, stop, &iwe, buf); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | memset(&iwe, 0, sizeof(iwe)); |
| 1055 | if (bss->rsn_ie_len) { |
| 1056 | char buf[MAX_WPA_IE_LEN]; |
| 1057 | memcpy(buf, bss->rsn_ie, bss->rsn_ie_len); |
| 1058 | iwe.cmd = IWEVGENIE; |
| 1059 | iwe.u.data.length = bss->rsn_ie_len; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1060 | start = iwe_stream_add_point(info, start, stop, &iwe, buf); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1061 | } |
| 1062 | |
Dan Williams | 00af015 | 2007-08-02 13:14:56 -0400 | [diff] [blame] | 1063 | if (bss->mesh) { |
| 1064 | char custom[MAX_CUSTOM_LEN]; |
| 1065 | char *p = custom; |
| 1066 | |
| 1067 | iwe.cmd = IWEVCUSTOM; |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1068 | p += snprintf(p, MAX_CUSTOM_LEN, "mesh-type: olpc"); |
Dan Williams | 00af015 | 2007-08-02 13:14:56 -0400 | [diff] [blame] | 1069 | iwe.u.data.length = p - custom; |
| 1070 | if (iwe.u.data.length) |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1071 | start = iwe_stream_add_point(info, start, stop, |
| 1072 | &iwe, custom); |
Dan Williams | 00af015 | 2007-08-02 13:14:56 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1075 | out: |
| 1076 | lbs_deb_leave_args(LBS_DEB_SCAN, "start %p", start); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1077 | return start; |
| 1078 | } |
| 1079 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1080 | |
| 1081 | /** |
| 1082 | * @brief Handle Scan Network ioctl |
| 1083 | * |
| 1084 | * @param dev A pointer to net_device structure |
| 1085 | * @param info A pointer to iw_request_info structure |
| 1086 | * @param vwrq A pointer to iw_param structure |
| 1087 | * @param extra A pointer to extra data buf |
| 1088 | * |
| 1089 | * @return 0 --success, otherwise fail |
| 1090 | */ |
| 1091 | int lbs_set_scan(struct net_device *dev, struct iw_request_info *info, |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1092 | union iwreq_data *wrqu, char *extra) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1093 | { |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1094 | DECLARE_SSID_BUF(ssid); |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 1095 | struct lbs_private *priv = dev->ml_priv; |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1096 | int ret = 0; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1097 | |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1098 | lbs_deb_enter(LBS_DEB_WEXT); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1099 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1100 | if (!priv->radio_on) { |
| 1101 | ret = -EINVAL; |
| 1102 | goto out; |
| 1103 | } |
| 1104 | |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1105 | if (!netif_running(dev)) { |
| 1106 | ret = -ENETDOWN; |
| 1107 | goto out; |
| 1108 | } |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1109 | |
| 1110 | /* mac80211 does this: |
| 1111 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1112 | if (sdata->type != IEEE80211_IF_TYPE_xxx) { |
| 1113 | ret = -EOPNOTSUPP; |
| 1114 | goto out; |
| 1115 | } |
| 1116 | */ |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1117 | |
| 1118 | if (wrqu->data.length == sizeof(struct iw_scan_req) && |
| 1119 | wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1120 | struct iw_scan_req *req = (struct iw_scan_req *)extra; |
| 1121 | priv->scan_ssid_len = req->essid_len; |
| 1122 | memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len); |
| 1123 | lbs_deb_wext("set_scan, essid '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 1124 | print_ssid(ssid, priv->scan_ssid, priv->scan_ssid_len)); |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1125 | } else { |
| 1126 | priv->scan_ssid_len = 0; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1127 | } |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1128 | |
| 1129 | if (!delayed_work_pending(&priv->scan_work)) |
| 1130 | queue_delayed_work(priv->work_thread, &priv->scan_work, |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1131 | msecs_to_jiffies(50)); |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1132 | /* set marker that currently a scan is taking place */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 1133 | priv->scan_channel = -1; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1134 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1135 | if (priv->surpriseremoved) |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1136 | ret = -EIO; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1137 | |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1138 | out: |
| 1139 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret); |
| 1140 | return ret; |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1144 | /** |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1145 | * @brief Handle Retrieve scan table ioctl |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1146 | * |
| 1147 | * @param dev A pointer to net_device structure |
| 1148 | * @param info A pointer to iw_request_info structure |
| 1149 | * @param dwrq A pointer to iw_point structure |
| 1150 | * @param extra A pointer to extra data buf |
| 1151 | * |
| 1152 | * @return 0 --success, otherwise fail |
| 1153 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1154 | int lbs_get_scan(struct net_device *dev, struct iw_request_info *info, |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1155 | struct iw_point *dwrq, char *extra) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1156 | { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1157 | #define SCAN_ITEM_SIZE 128 |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 1158 | struct lbs_private *priv = dev->ml_priv; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1159 | int err = 0; |
| 1160 | char *ev = extra; |
| 1161 | char *stop = ev + dwrq->length; |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1162 | struct bss_descriptor *iter_bss; |
| 1163 | struct bss_descriptor *safe; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1164 | |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1165 | lbs_deb_enter(LBS_DEB_WEXT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1166 | |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1167 | /* iwlist should wait until the current scan is finished */ |
Holger Schurig | 8816edc | 2008-01-28 17:28:05 +0100 | [diff] [blame] | 1168 | if (priv->scan_channel) |
Holger Schurig | ffd074f | 2007-12-07 16:52:10 +0100 | [diff] [blame] | 1169 | return -EAGAIN; |
| 1170 | |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1171 | /* Update RSSI if current BSS is a locally created ad-hoc BSS */ |
Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 1172 | if ((priv->mode == IW_MODE_ADHOC) && priv->adhoccreate) { |
| 1173 | err = lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0, |
| 1174 | CMD_OPTION_WAITFORRSP, 0, NULL); |
| 1175 | if (err) |
| 1176 | goto out; |
| 1177 | } |
Dan Williams | 80e78ef | 2007-05-25 22:18:47 -0400 | [diff] [blame] | 1178 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1179 | mutex_lock(&priv->lock); |
| 1180 | list_for_each_entry_safe (iter_bss, safe, &priv->network_list, list) { |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1181 | char *next_ev; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1182 | unsigned long stale_time; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1183 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1184 | if (stop - ev < SCAN_ITEM_SIZE) { |
| 1185 | err = -E2BIG; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1186 | break; |
| 1187 | } |
| 1188 | |
Luis Carlos Cobo | 1e838bf | 2007-08-02 10:51:27 -0400 | [diff] [blame] | 1189 | /* For mesh device, list only mesh networks */ |
| 1190 | if (dev == priv->mesh_dev && !iter_bss->mesh) |
| 1191 | continue; |
| 1192 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1193 | /* Prune old an old scan result */ |
| 1194 | stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE; |
| 1195 | if (time_after(jiffies, stale_time)) { |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1196 | list_move_tail(&iter_bss->list, &priv->network_free_list); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1197 | clear_bss_descriptor(iter_bss); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1198 | continue; |
| 1199 | } |
| 1200 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1201 | /* Translate to WE format this entry */ |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 1202 | next_ev = lbs_translate_scan(priv, info, ev, stop, iter_bss); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1203 | if (next_ev == NULL) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1204 | continue; |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1205 | ev = next_ev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1206 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1207 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1208 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1209 | dwrq->length = (ev - extra); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1210 | dwrq->flags = 0; |
Amitkumar Karwar | c0bbd57 | 2009-10-08 19:38:45 -0700 | [diff] [blame] | 1211 | out: |
Holger Schurig | 52933d8 | 2008-03-05 07:05:32 +0100 | [diff] [blame] | 1212 | lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", err); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1213 | return err; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1214 | } |
| 1215 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1216 | |
| 1217 | |
| 1218 | |
| 1219 | /*********************************************************************/ |
| 1220 | /* */ |
| 1221 | /* Command execution */ |
| 1222 | /* */ |
| 1223 | /*********************************************************************/ |
| 1224 | |
| 1225 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1226 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1227 | * @brief This function handles the command response of scan |
| 1228 | * |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1229 | * Called from handle_cmd_response() in cmdrespc. |
| 1230 | * |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1231 | * The response buffer for the scan command has the following |
| 1232 | * memory layout: |
| 1233 | * |
| 1234 | * .-----------------------------------------------------------. |
| 1235 | * | header (4 * sizeof(u16)): Standard command response hdr | |
| 1236 | * .-----------------------------------------------------------. |
| 1237 | * | bufsize (u16) : sizeof the BSS Description data | |
| 1238 | * .-----------------------------------------------------------. |
| 1239 | * | NumOfSet (u8) : Number of BSS Descs returned | |
| 1240 | * .-----------------------------------------------------------. |
| 1241 | * | BSSDescription data (variable, size given in bufsize) | |
| 1242 | * .-----------------------------------------------------------. |
| 1243 | * | TLV data (variable, size calculated using header->size, | |
| 1244 | * | bufsize and sizeof the fixed fields above) | |
| 1245 | * .-----------------------------------------------------------. |
| 1246 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1247 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1248 | * @param resp A pointer to cmd_ds_command |
| 1249 | * |
| 1250 | * @return 0 or -1 |
| 1251 | */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1252 | static int lbs_ret_80211_scan(struct lbs_private *priv, unsigned long dummy, |
| 1253 | struct cmd_header *resp) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1254 | { |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1255 | struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp; |
David Woodhouse | f137e05 | 2008-03-03 12:18:59 +0100 | [diff] [blame] | 1256 | struct bss_descriptor *iter_bss; |
| 1257 | struct bss_descriptor *safe; |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1258 | uint8_t *bssinfo; |
| 1259 | uint16_t scanrespsize; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1260 | int bytesleft; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1261 | int idx; |
| 1262 | int tlvbufsize; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1263 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1264 | |
Holger Schurig | e56188a | 2007-10-09 14:15:19 +0200 | [diff] [blame] | 1265 | lbs_deb_enter(LBS_DEB_SCAN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1266 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1267 | /* Prune old entries from scan table */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1268 | list_for_each_entry_safe (iter_bss, safe, &priv->network_list, list) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1269 | unsigned long stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE; |
| 1270 | if (time_before(jiffies, stale_time)) |
| 1271 | continue; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1272 | list_move_tail (&iter_bss->list, &priv->network_free_list); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1273 | clear_bss_descriptor(iter_bss); |
| 1274 | } |
| 1275 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1276 | if (scanresp->nr_sets > MAX_NETWORK_COUNT) { |
| 1277 | lbs_deb_scan("SCAN_RESP: too many scan results (%d, max %d)\n", |
| 1278 | scanresp->nr_sets, MAX_NETWORK_COUNT); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1279 | ret = -1; |
| 1280 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1281 | } |
| 1282 | |
Cliff Cai | 2c5b9e51 | 2009-05-27 14:03:09 -0400 | [diff] [blame] | 1283 | bytesleft = get_unaligned_le16(&scanresp->bssdescriptsize); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1284 | lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1285 | |
David Woodhouse | e7240ac | 2007-12-11 17:54:36 -0500 | [diff] [blame] | 1286 | scanrespsize = le16_to_cpu(resp->size); |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1287 | lbs_deb_scan("SCAN_RESP: scan results %d\n", scanresp->nr_sets); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1288 | |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1289 | bssinfo = scanresp->bssdesc_and_tlvbuffer; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1290 | |
| 1291 | /* The size of the TLV buffer is equal to the entire command response |
| 1292 | * size (scanrespsize) minus the fixed fields (sizeof()'s), the |
| 1293 | * BSS Descriptions (bssdescriptsize as bytesLef) and the command |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 1294 | * response header (sizeof(struct cmd_header)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1295 | */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1296 | tlvbufsize = scanrespsize - (bytesleft + sizeof(scanresp->bssdescriptsize) |
| 1297 | + sizeof(scanresp->nr_sets) |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 1298 | + sizeof(struct cmd_header)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1299 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1300 | /* |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1301 | * Process each scan response returned (scanresp->nr_sets). Save |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1302 | * the information in the newbssentry and then insert into the |
| 1303 | * driver scan table either as an update to an existing entry |
| 1304 | * or as an addition at the end of the table |
| 1305 | */ |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1306 | for (idx = 0; idx < scanresp->nr_sets && bytesleft; idx++) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1307 | struct bss_descriptor new; |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1308 | struct bss_descriptor *found = NULL; |
| 1309 | struct bss_descriptor *oldest = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1310 | |
| 1311 | /* Process the data fields and IEs returned for this BSS */ |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1312 | memset(&new, 0, sizeof (struct bss_descriptor)); |
David Woodhouse | fa62f99 | 2008-03-03 12:18:03 +0100 | [diff] [blame] | 1313 | if (lbs_process_bss(&new, &bssinfo, &bytesleft) != 0) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1314 | /* error parsing the scan response, skipped */ |
| 1315 | lbs_deb_scan("SCAN_RESP: process_bss returned ERROR\n"); |
| 1316 | continue; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1317 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1318 | |
| 1319 | /* Try to find this bss in the scan table */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1320 | list_for_each_entry (iter_bss, &priv->network_list, list) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1321 | if (is_same_network(iter_bss, &new)) { |
| 1322 | found = iter_bss; |
| 1323 | break; |
| 1324 | } |
| 1325 | |
| 1326 | if ((oldest == NULL) || |
| 1327 | (iter_bss->last_scanned < oldest->last_scanned)) |
| 1328 | oldest = iter_bss; |
| 1329 | } |
| 1330 | |
| 1331 | if (found) { |
| 1332 | /* found, clear it */ |
| 1333 | clear_bss_descriptor(found); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1334 | } else if (!list_empty(&priv->network_free_list)) { |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1335 | /* Pull one from the free list */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1336 | found = list_entry(priv->network_free_list.next, |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1337 | struct bss_descriptor, list); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1338 | list_move_tail(&found->list, &priv->network_list); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1339 | } else if (oldest) { |
| 1340 | /* If there are no more slots, expire the oldest */ |
| 1341 | found = oldest; |
| 1342 | clear_bss_descriptor(found); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1343 | list_move_tail(&found->list, &priv->network_list); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1344 | } else { |
| 1345 | continue; |
| 1346 | } |
| 1347 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1348 | lbs_deb_scan("SCAN_RESP: BSSID %pM\n", new.bssid); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1349 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 1350 | /* Copy the locally created newbssentry to the scan table */ |
| 1351 | memcpy(found, &new, offsetof(struct bss_descriptor, list)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1352 | } |
| 1353 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1354 | ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1355 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1356 | done: |
| 1357 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); |
| 1358 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1359 | } |