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