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