blob: 8aaac5f6c9dec47739be8ac385424933db72a27c [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * Functions implementing wlan scan IOCTL and firmware command APIs
3 *
4 * IOCTL handlers as well as command preperation and response routines
5 * for sending scan commands to the firmware.
6 */
7#include <linux/ctype.h>
8#include <linux/if.h>
9#include <linux/netdevice.h>
10#include <linux/wireless.h>
Dan Williamsfcdb53d2007-05-25 16:15:56 -040011#include <linux/etherdevice.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020012
13#include <net/ieee80211.h>
14#include <net/iw_handler.h>
15
16#include "host.h"
17#include "decl.h"
18#include "dev.h"
19#include "scan.h"
20
21//! Approximate amount of data needed to pass a scan result back to iwlist
22#define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \
23 + IW_ESSID_MAX_SIZE \
24 + IW_EV_UINT_LEN \
25 + IW_EV_FREQ_LEN \
26 + IW_EV_QUAL_LEN \
27 + IW_ESSID_MAX_SIZE \
28 + IW_EV_PARAM_LEN \
29 + 40) /* 40 for WPAIE */
30
31//! Memory needed to store a max sized channel List TLV for a firmware scan
32#define CHAN_TLV_MAX_SIZE (sizeof(struct mrvlietypesheader) \
33 + (MRVDRV_MAX_CHANNELS_PER_SCAN \
34 * sizeof(struct chanscanparamset)))
35
36//! Memory needed to store a max number/size SSID TLV for a firmware scan
37#define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvlietypes_ssidparamset))
38
39//! Maximum memory needed for a wlan_scan_cmd_config with all TLVs at max
40#define MAX_SCAN_CFG_ALLOC (sizeof(struct wlan_scan_cmd_config) \
41 + sizeof(struct mrvlietypes_numprobes) \
42 + CHAN_TLV_MAX_SIZE \
43 + SSID_TLV_MAX_SIZE)
44
45//! The maximum number of channels the firmware can scan per command
46#define MRVDRV_MAX_CHANNELS_PER_SCAN 14
47
48/**
49 * @brief Number of channels to scan per firmware scan command issuance.
50 *
51 * Number restricted to prevent hitting the limit on the amount of scan data
52 * returned in a single firmware scan command.
53 */
54#define MRVDRV_CHANNELS_PER_SCAN_CMD 4
55
56//! Scan time specified in the channel TLV for each channel for passive scans
57#define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100
58
59//! Scan time specified in the channel TLV for each channel for active scans
60#define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100
61
Dan Williamseb8f7332007-05-25 16:25:21 -040062const u8 zeromac[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
63const u8 bcastmac[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
64
Dan Williamsfcdb53d2007-05-25 16:15:56 -040065static inline void clear_bss_descriptor (struct bss_descriptor * bss)
66{
67 /* Don't blow away ->list, just BSS data */
68 memset(bss, 0, offsetof(struct bss_descriptor, list));
69}
70
71static inline int match_bss_no_security(struct wlan_802_11_security * secinfo,
72 struct bss_descriptor * match_bss)
73{
74 if ( !secinfo->wep_enabled
75 && !secinfo->WPAenabled
76 && !secinfo->WPA2enabled
77 && match_bss->wpa_ie[0] != WPA_IE
78 && match_bss->rsn_ie[0] != WPA2_IE
79 && !match_bss->privacy) {
80 return 1;
81 }
82 return 0;
83}
84
85static inline int match_bss_static_wep(struct wlan_802_11_security * secinfo,
86 struct bss_descriptor * match_bss)
87{
88 if ( secinfo->wep_enabled
89 && !secinfo->WPAenabled
90 && !secinfo->WPA2enabled
91 && match_bss->privacy) {
92 return 1;
93 }
94 return 0;
95}
96
97static inline int match_bss_wpa(struct wlan_802_11_security * secinfo,
98 struct bss_descriptor * match_bss)
99{
100 if ( !secinfo->wep_enabled
101 && secinfo->WPAenabled
102 && !secinfo->WPA2enabled
103 && (match_bss->wpa_ie[0] == WPA_IE)
104 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
105 && bss->privacy */
106 ) {
107 return 1;
108 }
109 return 0;
110}
111
112static inline int match_bss_wpa2(struct wlan_802_11_security * secinfo,
113 struct bss_descriptor * match_bss)
114{
115 if ( !secinfo->wep_enabled
116 && !secinfo->WPAenabled
117 && secinfo->WPA2enabled
118 && (match_bss->rsn_ie[0] == WPA2_IE)
119 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
120 && bss->privacy */
121 ) {
122 return 1;
123 }
124 return 0;
125}
126
127static inline int match_bss_dynamic_wep(struct wlan_802_11_security * secinfo,
128 struct bss_descriptor * match_bss)
129{
130 if ( !secinfo->wep_enabled
131 && !secinfo->WPAenabled
132 && !secinfo->WPA2enabled
133 && (match_bss->wpa_ie[0] != WPA_IE)
134 && (match_bss->rsn_ie[0] != WPA2_IE)
135 && match_bss->privacy) {
136 return 1;
137 }
138 return 0;
139}
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200140
141/**
142 * @brief Check if a scanned network compatible with the driver settings
143 *
144 * WEP WPA WPA2 ad-hoc encrypt Network
145 * enabled enabled enabled AES mode privacy WPA WPA2 Compatible
146 * 0 0 0 0 NONE 0 0 0 yes No security
147 * 1 0 0 0 NONE 1 0 0 yes Static WEP
148 * 0 1 0 0 x 1x 1 x yes WPA
149 * 0 0 1 0 x 1x x 1 yes WPA2
150 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
151 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
152 *
153 *
154 * @param adapter A pointer to wlan_adapter
155 * @param index Index in scantable to check against current driver settings
156 * @param mode Network mode: Infrastructure or IBSS
157 *
158 * @return Index in scantable, or error code if negative
159 */
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400160static int is_network_compatible(wlan_adapter * adapter,
161 struct bss_descriptor * bss, u8 mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200162{
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400163 int matched = 0;
164
Holger Schurig9012b282007-05-25 11:27:16 -0400165 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200166
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400167 if (bss->mode != mode)
168 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200169
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400170 if ((matched = match_bss_no_security(&adapter->secinfo, bss))) {
171 goto done;
172 } else if ((matched = match_bss_static_wep(&adapter->secinfo, bss))) {
173 goto done;
174 } else if ((matched = match_bss_wpa(&adapter->secinfo, bss))) {
175 lbs_deb_scan(
176 "is_network_compatible() WPA: wpa_ie=%#x "
177 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
178 "privacy=%#x\n", bss->wpa_ie[0], bss->rsn_ie[0],
Dan Williams889c05b2007-05-10 22:57:23 -0400179 adapter->secinfo.wep_enabled ? "e" : "d",
180 adapter->secinfo.WPAenabled ? "e" : "d",
181 adapter->secinfo.WPA2enabled ? "e" : "d",
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400182 bss->privacy);
183 goto done;
184 } else if ((matched = match_bss_wpa2(&adapter->secinfo, bss))) {
185 lbs_deb_scan(
186 "is_network_compatible() WPA2: wpa_ie=%#x "
187 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
188 "privacy=%#x\n", bss->wpa_ie[0], bss->rsn_ie[0],
189 adapter->secinfo.wep_enabled ? "e" : "d",
190 adapter->secinfo.WPAenabled ? "e" : "d",
191 adapter->secinfo.WPA2enabled ? "e" : "d",
192 bss->privacy);
193 goto done;
194 } else if ((matched = match_bss_dynamic_wep(&adapter->secinfo, bss))) {
195 lbs_deb_scan(
196 "is_network_compatible() dynamic WEP: "
197 "wpa_ie=%#x wpa2_ie=%#x privacy=%#x\n",
198 bss->wpa_ie[0],
199 bss->rsn_ie[0],
200 bss->privacy);
Holger Schurig9012b282007-05-25 11:27:16 -0400201 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200202 }
203
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400204 /* bss security settings don't match those configured on card */
205 lbs_deb_scan(
206 "is_network_compatible() FAILED: wpa_ie=%#x "
207 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s privacy=%#x\n",
208 bss->wpa_ie[0], bss->rsn_ie[0],
209 adapter->secinfo.wep_enabled ? "e" : "d",
210 adapter->secinfo.WPAenabled ? "e" : "d",
211 adapter->secinfo.WPA2enabled ? "e" : "d",
212 bss->privacy);
Holger Schurig9012b282007-05-25 11:27:16 -0400213
214done:
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400215 lbs_deb_leave(LBS_DEB_SCAN);
216 return matched;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200217}
218
219/**
220 * @brief Post process the scan table after a new scan command has completed
221 *
222 * Inspect each entry of the scan table and try to find an entry that
223 * matches our current associated/joined network from the scan. If
224 * one is found, update the stored copy of the bssdescriptor for our
225 * current network.
226 *
227 * Debug dump the current scan table contents if compiled accordingly.
228 *
229 * @param priv A pointer to wlan_private structure
230 *
231 * @return void
232 */
233static void wlan_scan_process_results(wlan_private * priv)
234{
235 wlan_adapter *adapter = priv->adapter;
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400236 struct bss_descriptor * iter_bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200237
Dan Williamse76850d2007-05-25 17:09:41 -0400238 if (adapter->connect_status == libertas_connected)
239 return;
240
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400241 mutex_lock(&adapter->lock);
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400242 list_for_each_entry (iter_bss, &adapter->network_list, list) {
243 lbs_deb_scan("Scan:(%02d) " MAC_FMT ", RSSI[%03d], SSID[%s]\n",
Dan Williams02eb2292007-05-25 17:27:31 -0400244 i++, MAC_ARG(iter_bss->bssid), (s32) iter_bss->rssi,
245 iter_bss->ssid.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246 }
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400247 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200248}
249
250/**
251 * @brief Create a channel list for the driver to scan based on region info
252 *
253 * Use the driver region/band information to construct a comprehensive list
254 * of channels to scan. This routine is used for any scan that is not
255 * provided a specific channel list to scan.
256 *
257 * @param priv A pointer to wlan_private structure
258 * @param scanchanlist Output parameter: resulting channel list to scan
259 * @param filteredscan Flag indicating whether or not a BSSID or SSID filter
260 * is being sent in the command to firmware. Used to
261 * increase the number of channels sent in a scan
262 * command and to disable the firmware channel scan
263 * filter.
264 *
265 * @return void
266 */
267static void wlan_scan_create_channel_list(wlan_private * priv,
268 struct chanscanparamset * scanchanlist,
269 u8 filteredscan)
270{
271
272 wlan_adapter *adapter = priv->adapter;
273 struct region_channel *scanregion;
274 struct chan_freq_power *cfp;
275 int rgnidx;
276 int chanidx;
277 int nextchan;
278 u8 scantype;
279
280 chanidx = 0;
281
282 /* Set the default scan type to the user specified type, will later
283 * be changed to passive on a per channel basis if restricted by
284 * regulatory requirements (11d or 11h)
285 */
286 scantype = adapter->scantype;
287
288 for (rgnidx = 0; rgnidx < ARRAY_SIZE(adapter->region_channel); rgnidx++) {
289 if (priv->adapter->enable11d &&
290 adapter->connect_status != libertas_connected) {
291 /* Scan all the supported chan for the first scan */
292 if (!adapter->universal_channel[rgnidx].valid)
293 continue;
294 scanregion = &adapter->universal_channel[rgnidx];
295
296 /* clear the parsed_region_chan for the first scan */
297 memset(&adapter->parsed_region_chan, 0x00,
298 sizeof(adapter->parsed_region_chan));
299 } else {
300 if (!adapter->region_channel[rgnidx].valid)
301 continue;
302 scanregion = &adapter->region_channel[rgnidx];
303 }
304
305 for (nextchan = 0;
306 nextchan < scanregion->nrcfp; nextchan++, chanidx++) {
307
308 cfp = scanregion->CFP + nextchan;
309
310 if (priv->adapter->enable11d) {
311 scantype =
312 libertas_get_scan_type_11d(cfp->channel,
313 &adapter->
314 parsed_region_chan);
315 }
316
317 switch (scanregion->band) {
318 case BAND_B:
319 case BAND_G:
320 default:
321 scanchanlist[chanidx].radiotype =
322 cmd_scan_radio_type_bg;
323 break;
324 }
325
326 if (scantype == cmd_scan_type_passive) {
327 scanchanlist[chanidx].maxscantime =
328 cpu_to_le16
329 (MRVDRV_PASSIVE_SCAN_CHAN_TIME);
330 scanchanlist[chanidx].chanscanmode.passivescan =
331 1;
332 } else {
333 scanchanlist[chanidx].maxscantime =
334 cpu_to_le16
335 (MRVDRV_ACTIVE_SCAN_CHAN_TIME);
336 scanchanlist[chanidx].chanscanmode.passivescan =
337 0;
338 }
339
340 scanchanlist[chanidx].channumber = cfp->channel;
341
342 if (filteredscan) {
343 scanchanlist[chanidx].chanscanmode.
344 disablechanfilt = 1;
345 }
346 }
347 }
348}
349
350/**
351 * @brief Construct a wlan_scan_cmd_config structure to use in issue scan cmds
352 *
353 * Application layer or other functions can invoke wlan_scan_networks
354 * with a scan configuration supplied in a wlan_ioctl_user_scan_cfg struct.
355 * This structure is used as the basis of one or many wlan_scan_cmd_config
356 * commands that are sent to the command processing module and sent to
357 * firmware.
358 *
359 * Create a wlan_scan_cmd_config based on the following user supplied
360 * parameters (if present):
361 * - SSID filter
362 * - BSSID filter
363 * - Number of Probes to be sent
364 * - channel list
365 *
366 * If the SSID or BSSID filter is not present, disable/clear the filter.
367 * If the number of probes is not set, use the adapter default setting
368 * Qualify the channel
369 *
370 * @param priv A pointer to wlan_private structure
371 * @param puserscanin NULL or pointer to scan configuration parameters
372 * @param ppchantlvout Output parameter: Pointer to the start of the
373 * channel TLV portion of the output scan config
374 * @param pscanchanlist Output parameter: Pointer to the resulting channel
375 * list to scan
376 * @param pmaxchanperscan Output parameter: Number of channels to scan for
377 * each issuance of the firmware scan command
378 * @param pfilteredscan Output parameter: Flag indicating whether or not
379 * a BSSID or SSID filter is being sent in the
380 * command to firmware. Used to increase the number
381 * of channels sent in a scan command and to
382 * disable the firmware channel scan filter.
383 * @param pscancurrentonly Output parameter: Flag indicating whether or not
384 * we are only scanning our current active channel
385 *
386 * @return resulting scan configuration
387 */
388static struct wlan_scan_cmd_config *
389wlan_scan_setup_scan_config(wlan_private * priv,
390 const struct wlan_ioctl_user_scan_cfg * puserscanin,
391 struct mrvlietypes_chanlistparamset ** ppchantlvout,
392 struct chanscanparamset * pscanchanlist,
393 int *pmaxchanperscan,
394 u8 * pfilteredscan,
395 u8 * pscancurrentonly)
396{
397 wlan_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200398 struct mrvlietypes_numprobes *pnumprobestlv;
399 struct mrvlietypes_ssidparamset *pssidtlv;
400 struct wlan_scan_cmd_config * pscancfgout = NULL;
401 u8 *ptlvpos;
402 u16 numprobes;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403 int chanidx;
404 int scantype;
405 int scandur;
406 int channel;
407 int radiotype;
408
409 pscancfgout = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL);
410 if (pscancfgout == NULL)
411 goto out;
412
413 /* The tlvbufferlen is calculated for each scan command. The TLVs added
414 * in this routine will be preserved since the routine that sends
415 * the command will append channelTLVs at *ppchantlvout. The difference
416 * between the *ppchantlvout and the tlvbuffer start will be used
417 * to calculate the size of anything we add in this routine.
418 */
419 pscancfgout->tlvbufferlen = 0;
420
421 /* Running tlv pointer. Assigned to ppchantlvout at end of function
422 * so later routines know where channels can be added to the command buf
423 */
424 ptlvpos = pscancfgout->tlvbuffer;
425
426 /*
427 * Set the initial scan paramters for progressive scanning. If a specific
428 * BSSID or SSID is used, the number of channels in the scan command
429 * will be increased to the absolute maximum
430 */
431 *pmaxchanperscan = MRVDRV_CHANNELS_PER_SCAN_CMD;
432
433 /* Initialize the scan as un-filtered by firmware, set to TRUE below if
434 * a SSID or BSSID filter is sent in the command
435 */
436 *pfilteredscan = 0;
437
438 /* Initialize the scan as not being only on the current channel. If
439 * the channel list is customized, only contains one channel, and
440 * is the active channel, this is set true and data flow is not halted.
441 */
442 *pscancurrentonly = 0;
443
444 if (puserscanin) {
445
446 /* Set the bss type scan filter, use adapter setting if unset */
447 pscancfgout->bsstype =
448 (puserscanin->bsstype ? puserscanin->bsstype : adapter->
449 scanmode);
450
451 /* Set the number of probes to send, use adapter setting if unset */
452 numprobes = (puserscanin->numprobes ? puserscanin->numprobes :
453 adapter->scanprobes);
454
455 /*
456 * Set the BSSID filter to the incoming configuration,
457 * if non-zero. If not set, it will remain disabled (all zeros).
458 */
Dan Williamseb8f7332007-05-25 16:25:21 -0400459 memcpy(pscancfgout->bssid, puserscanin->bssid,
460 sizeof(pscancfgout->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200461
Dan Williamseb8f7332007-05-25 16:25:21 -0400462 if (puserscanin->ssid_len) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200463 pssidtlv =
464 (struct mrvlietypes_ssidparamset *) pscancfgout->
465 tlvbuffer;
466 pssidtlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
Dan Williamseb8f7332007-05-25 16:25:21 -0400467 pssidtlv->header.len = cpu_to_le16(puserscanin->ssid_len);
468 memcpy(pssidtlv->ssid, puserscanin->ssid,
469 puserscanin->ssid_len);
470 ptlvpos += sizeof(pssidtlv->header) + puserscanin->ssid_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200471 }
472
473 /*
474 * The default number of channels sent in the command is low to
475 * ensure the response buffer from the firmware does not truncate
476 * scan results. That is not an issue with an SSID or BSSID
477 * filter applied to the scan results in the firmware.
478 */
Dan Williamseb8f7332007-05-25 16:25:21 -0400479 if ( puserscanin->ssid_len
480 || (compare_ether_addr(pscancfgout->bssid, &zeromac[0]) != 0)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481 *pmaxchanperscan = MRVDRV_MAX_CHANNELS_PER_SCAN;
482 *pfilteredscan = 1;
483 }
484 } else {
485 pscancfgout->bsstype = adapter->scanmode;
486 numprobes = adapter->scanprobes;
487 }
488
489 /* If the input config or adapter has the number of Probes set, add tlv */
490 if (numprobes) {
491 pnumprobestlv = (struct mrvlietypes_numprobes *) ptlvpos;
492 pnumprobestlv->header.type =
493 cpu_to_le16(TLV_TYPE_NUMPROBES);
494 pnumprobestlv->header.len = sizeof(pnumprobestlv->numprobes);
495 pnumprobestlv->numprobes = cpu_to_le16(numprobes);
496
497 ptlvpos +=
498 sizeof(pnumprobestlv->header) + pnumprobestlv->header.len;
499
500 pnumprobestlv->header.len =
501 cpu_to_le16(pnumprobestlv->header.len);
502 }
503
504 /*
505 * Set the output for the channel TLV to the address in the tlv buffer
506 * past any TLVs that were added in this fuction (SSID, numprobes).
507 * channel TLVs will be added past this for each scan command, preserving
508 * the TLVs that were previously added.
509 */
510 *ppchantlvout = (struct mrvlietypes_chanlistparamset *) ptlvpos;
511
512 if (puserscanin && puserscanin->chanlist[0].channumber) {
513
Holger Schurig9012b282007-05-25 11:27:16 -0400514 lbs_deb_scan("Scan: Using supplied channel list\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200515
516 for (chanidx = 0;
517 chanidx < WLAN_IOCTL_USER_SCAN_CHAN_MAX
518 && puserscanin->chanlist[chanidx].channumber; chanidx++) {
519
520 channel = puserscanin->chanlist[chanidx].channumber;
521 (pscanchanlist + chanidx)->channumber = channel;
522
523 radiotype = puserscanin->chanlist[chanidx].radiotype;
524 (pscanchanlist + chanidx)->radiotype = radiotype;
525
526 scantype = puserscanin->chanlist[chanidx].scantype;
527
528 if (scantype == cmd_scan_type_passive) {
529 (pscanchanlist +
530 chanidx)->chanscanmode.passivescan = 1;
531 } else {
532 (pscanchanlist +
533 chanidx)->chanscanmode.passivescan = 0;
534 }
535
536 if (puserscanin->chanlist[chanidx].scantime) {
537 scandur =
538 puserscanin->chanlist[chanidx].scantime;
539 } else {
540 if (scantype == cmd_scan_type_passive) {
541 scandur = MRVDRV_PASSIVE_SCAN_CHAN_TIME;
542 } else {
543 scandur = MRVDRV_ACTIVE_SCAN_CHAN_TIME;
544 }
545 }
546
547 (pscanchanlist + chanidx)->minscantime =
548 cpu_to_le16(scandur);
549 (pscanchanlist + chanidx)->maxscantime =
550 cpu_to_le16(scandur);
551 }
552
553 /* Check if we are only scanning the current channel */
554 if ((chanidx == 1) && (puserscanin->chanlist[0].channumber
555 ==
556 priv->adapter->curbssparams.channel)) {
557 *pscancurrentonly = 1;
Holger Schurig9012b282007-05-25 11:27:16 -0400558 lbs_deb_scan("Scan: Scanning current channel only");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200559 }
560
561 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400562 lbs_deb_scan("Scan: Creating full region channel list\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200563 wlan_scan_create_channel_list(priv, pscanchanlist,
564 *pfilteredscan);
565 }
566
567out:
568 return pscancfgout;
569}
570
571/**
572 * @brief Construct and send multiple scan config commands to the firmware
573 *
574 * Previous routines have created a wlan_scan_cmd_config with any requested
575 * TLVs. This function splits the channel TLV into maxchanperscan lists
576 * and sends the portion of the channel TLV along with the other TLVs
577 * to the wlan_cmd routines for execution in the firmware.
578 *
579 * @param priv A pointer to wlan_private structure
580 * @param maxchanperscan Maximum number channels to be included in each
581 * scan command sent to firmware
582 * @param filteredscan Flag indicating whether or not a BSSID or SSID
583 * filter is being used for the firmware command
584 * scan command sent to firmware
585 * @param pscancfgout Scan configuration used for this scan.
586 * @param pchantlvout Pointer in the pscancfgout where the channel TLV
587 * should start. This is past any other TLVs that
588 * must be sent down in each firmware command.
589 * @param pscanchanlist List of channels to scan in maxchanperscan segments
590 *
591 * @return 0 or error return otherwise
592 */
593static int wlan_scan_channel_list(wlan_private * priv,
594 int maxchanperscan,
595 u8 filteredscan,
596 struct wlan_scan_cmd_config * pscancfgout,
597 struct mrvlietypes_chanlistparamset * pchantlvout,
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400598 struct chanscanparamset * pscanchanlist,
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400599 const struct wlan_ioctl_user_scan_cfg * puserscanin,
600 int full_scan)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200601{
602 struct chanscanparamset *ptmpchan;
603 struct chanscanparamset *pstartchan;
604 u8 scanband;
605 int doneearly;
606 int tlvidx;
607 int ret = 0;
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400608 int scanned = 0;
609 union iwreq_data wrqu;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610
Holger Schurig9012b282007-05-25 11:27:16 -0400611 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200612
613 if (pscancfgout == 0 || pchantlvout == 0 || pscanchanlist == 0) {
Holger Schurig9012b282007-05-25 11:27:16 -0400614 lbs_deb_scan("Scan: Null detect: %p, %p, %p\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615 pscancfgout, pchantlvout, pscanchanlist);
616 return -1;
617 }
618
619 pchantlvout->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
620
621 /* Set the temp channel struct pointer to the start of the desired list */
622 ptmpchan = pscanchanlist;
623
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400624 if (priv->adapter->last_scanned_channel && !puserscanin)
625 ptmpchan += priv->adapter->last_scanned_channel;
626
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627 /* Loop through the desired channel list, sending a new firmware scan
628 * commands for each maxchanperscan channels (or for 1,6,11 individually
629 * if configured accordingly)
630 */
631 while (ptmpchan->channumber) {
632
633 tlvidx = 0;
634 pchantlvout->header.len = 0;
635 scanband = ptmpchan->radiotype;
636 pstartchan = ptmpchan;
637 doneearly = 0;
638
639 /* Construct the channel TLV for the scan command. Continue to
640 * insert channel TLVs until:
641 * - the tlvidx hits the maximum configured per scan command
642 * - the next channel to insert is 0 (end of desired channel list)
643 * - doneearly is set (controlling individual scanning of 1,6,11)
644 */
645 while (tlvidx < maxchanperscan && ptmpchan->channumber
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400646 && !doneearly && scanned < 2) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200647
Holger Schurig9012b282007-05-25 11:27:16 -0400648 lbs_deb_scan(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649 "Scan: Chan(%3d), Radio(%d), mode(%d,%d), Dur(%d)\n",
650 ptmpchan->channumber, ptmpchan->radiotype,
651 ptmpchan->chanscanmode.passivescan,
652 ptmpchan->chanscanmode.disablechanfilt,
653 ptmpchan->maxscantime);
654
655 /* Copy the current channel TLV to the command being prepared */
656 memcpy(pchantlvout->chanscanparam + tlvidx,
657 ptmpchan, sizeof(pchantlvout->chanscanparam));
658
659 /* Increment the TLV header length by the size appended */
660 pchantlvout->header.len +=
661 sizeof(pchantlvout->chanscanparam);
662
663 /*
664 * The tlv buffer length is set to the number of bytes of the
665 * between the channel tlv pointer and the start of the
666 * tlv buffer. This compensates for any TLVs that were appended
667 * before the channel list.
668 */
669 pscancfgout->tlvbufferlen = ((u8 *) pchantlvout
670 - pscancfgout->tlvbuffer);
671
672 /* Add the size of the channel tlv header and the data length */
673 pscancfgout->tlvbufferlen +=
674 (sizeof(pchantlvout->header)
675 + pchantlvout->header.len);
676
677 /* Increment the index to the channel tlv we are constructing */
678 tlvidx++;
679
680 doneearly = 0;
681
682 /* Stop the loop if the *current* channel is in the 1,6,11 set
683 * and we are not filtering on a BSSID or SSID.
684 */
685 if (!filteredscan && (ptmpchan->channumber == 1
686 || ptmpchan->channumber == 6
687 || ptmpchan->channumber == 11)) {
688 doneearly = 1;
689 }
690
691 /* Increment the tmp pointer to the next channel to be scanned */
692 ptmpchan++;
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400693 scanned++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200694
695 /* Stop the loop if the *next* channel is in the 1,6,11 set.
696 * This will cause it to be the only channel scanned on the next
697 * interation
698 */
699 if (!filteredscan && (ptmpchan->channumber == 1
700 || ptmpchan->channumber == 6
701 || ptmpchan->channumber == 11)) {
702 doneearly = 1;
703 }
704 }
705
706 /* Send the scan command to the firmware with the specified cfg */
707 ret = libertas_prepare_and_send_command(priv, cmd_802_11_scan, 0,
708 0, 0, pscancfgout);
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400709 if (scanned >= 2 && !full_scan) {
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400710 priv->adapter->last_scanned_channel = ptmpchan->channumber;
Holger Schurig9012b282007-05-25 11:27:16 -0400711 ret = 0;
712 goto done;
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400713 }
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400714 scanned = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715 }
716
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400717 priv->adapter->last_scanned_channel = ptmpchan->channumber;
718
719 memset(&wrqu, 0, sizeof(union iwreq_data));
Holger Schurig634b8f42007-05-25 13:05:16 -0400720 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400721
Holger Schurig9012b282007-05-25 11:27:16 -0400722done:
723 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200724 return ret;
725}
726
Dan Williamseb8f7332007-05-25 16:25:21 -0400727static void
728clear_selected_scan_list_entries(wlan_adapter * adapter,
729 const struct wlan_ioctl_user_scan_cfg * scan_cfg)
730{
731 struct bss_descriptor * bss;
732 struct bss_descriptor * safe;
733 u32 clear_ssid_flag = 0, clear_bssid_flag = 0;
734
735 if (!scan_cfg)
736 return;
737
738 if (scan_cfg->clear_ssid && scan_cfg->ssid_len)
739 clear_ssid_flag = 1;
740
741 if (scan_cfg->clear_bssid
742 && (compare_ether_addr(scan_cfg->bssid, &zeromac[0]) != 0)
743 && (compare_ether_addr(scan_cfg->bssid, &bcastmac[0]) != 0)) {
744 clear_bssid_flag = 1;
745 }
746
747 if (!clear_ssid_flag && !clear_bssid_flag)
748 return;
749
750 mutex_lock(&adapter->lock);
751 list_for_each_entry_safe (bss, safe, &adapter->network_list, list) {
752 u32 clear = 0;
753
754 /* Check for an SSID match */
755 if ( clear_ssid_flag
756 && (bss->ssid.ssidlength == scan_cfg->ssid_len)
757 && !memcmp(bss->ssid.ssid, scan_cfg->ssid, bss->ssid.ssidlength))
758 clear = 1;
759
760 /* Check for a BSSID match */
761 if ( clear_bssid_flag
762 && !compare_ether_addr(bss->bssid, scan_cfg->bssid))
763 clear = 1;
764
765 if (clear) {
766 list_move_tail (&bss->list, &adapter->network_free_list);
767 clear_bss_descriptor(bss);
768 }
769 }
770 mutex_unlock(&adapter->lock);
771}
772
773
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200774/**
775 * @brief Internal function used to start a scan based on an input config
776 *
777 * Use the input user scan configuration information when provided in
778 * order to send the appropriate scan commands to firmware to populate or
779 * update the internal driver scan table
780 *
781 * @param priv A pointer to wlan_private structure
782 * @param puserscanin Pointer to the input configuration for the requested
783 * scan.
784 *
785 * @return 0 or < 0 if error
786 */
787int wlan_scan_networks(wlan_private * priv,
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400788 const struct wlan_ioctl_user_scan_cfg * puserscanin,
789 int full_scan)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200790{
Dan Williamseb8f7332007-05-25 16:25:21 -0400791 wlan_adapter * adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200792 struct mrvlietypes_chanlistparamset *pchantlvout;
793 struct chanscanparamset * scan_chan_list = NULL;
794 struct wlan_scan_cmd_config * scan_cfg = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200795 u8 filteredscan;
796 u8 scancurrentchanonly;
797 int maxchanperscan;
798 int ret;
799
Holger Schurig9012b282007-05-25 11:27:16 -0400800 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801
802 scan_chan_list = kzalloc(sizeof(struct chanscanparamset) *
803 WLAN_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL);
804 if (scan_chan_list == NULL) {
805 ret = -ENOMEM;
806 goto out;
807 }
808
809 scan_cfg = wlan_scan_setup_scan_config(priv,
810 puserscanin,
811 &pchantlvout,
812 scan_chan_list,
813 &maxchanperscan,
814 &filteredscan,
815 &scancurrentchanonly);
816 if (scan_cfg == NULL) {
817 ret = -ENOMEM;
818 goto out;
819 }
820
Dan Williamseb8f7332007-05-25 16:25:21 -0400821 clear_selected_scan_list_entries(adapter, puserscanin);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200822
823 /* Keep the data path active if we are only scanning our current channel */
824 if (!scancurrentchanonly) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400825 netif_stop_queue(priv->dev);
826 netif_carrier_off(priv->dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400827 netif_stop_queue(priv->mesh_dev);
828 netif_carrier_off(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200829 }
830
831 ret = wlan_scan_channel_list(priv,
832 maxchanperscan,
833 filteredscan,
834 scan_cfg,
835 pchantlvout,
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400836 scan_chan_list,
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400837 puserscanin,
838 full_scan);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200839
840 /* Process the resulting scan table:
841 * - Remove any bad ssids
842 * - Update our current BSS information from scan data
843 */
844 wlan_scan_process_results(priv);
845
846 if (priv->adapter->connect_status == libertas_connected) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400847 netif_carrier_on(priv->dev);
848 netif_wake_queue(priv->dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400849 netif_carrier_on(priv->mesh_dev);
850 netif_wake_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200851 }
852
853out:
854 if (scan_cfg)
855 kfree(scan_cfg);
856
857 if (scan_chan_list)
858 kfree(scan_chan_list);
859
Holger Schurig9012b282007-05-25 11:27:16 -0400860 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200861 return ret;
862}
863
864/**
865 * @brief Inspect the scan response buffer for pointers to expected TLVs
866 *
867 * TLVs can be included at the end of the scan response BSS information.
868 * Parse the data in the buffer for pointers to TLVs that can potentially
869 * be passed back in the response
870 *
871 * @param ptlv Pointer to the start of the TLV buffer to parse
872 * @param tlvbufsize size of the TLV buffer
873 * @param ptsftlv Output parameter: Pointer to the TSF TLV if found
874 *
875 * @return void
876 */
877static
878void wlan_ret_802_11_scan_get_tlv_ptrs(struct mrvlietypes_data * ptlv,
879 int tlvbufsize,
880 struct mrvlietypes_tsftimestamp ** ptsftlv)
881{
882 struct mrvlietypes_data *pcurrenttlv;
883 int tlvbufleft;
884 u16 tlvtype;
885 u16 tlvlen;
886
887 pcurrenttlv = ptlv;
888 tlvbufleft = tlvbufsize;
889 *ptsftlv = NULL;
890
Holger Schurig9012b282007-05-25 11:27:16 -0400891 lbs_deb_scan("SCAN_RESP: tlvbufsize = %d\n", tlvbufsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200892 lbs_dbg_hex("SCAN_RESP: TLV Buf", (u8 *) ptlv, tlvbufsize);
893
894 while (tlvbufleft >= sizeof(struct mrvlietypesheader)) {
895 tlvtype = le16_to_cpu(pcurrenttlv->header.type);
896 tlvlen = le16_to_cpu(pcurrenttlv->header.len);
897
898 switch (tlvtype) {
899 case TLV_TYPE_TSFTIMESTAMP:
900 *ptsftlv = (struct mrvlietypes_tsftimestamp *) pcurrenttlv;
901 break;
902
903 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400904 lbs_deb_scan("SCAN_RESP: Unhandled TLV = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200905 tlvtype);
906 /* Give up, this seems corrupted */
907 return;
908 } /* switch */
909
910 tlvbufleft -= (sizeof(ptlv->header) + tlvlen);
911 pcurrenttlv =
912 (struct mrvlietypes_data *) (pcurrenttlv->Data + tlvlen);
913 } /* while */
914}
915
916/**
917 * @brief Interpret a BSS scan response returned from the firmware
918 *
919 * Parse the various fixed fields and IEs passed back for a a BSS probe
920 * response or beacon from the scan command. Record information as needed
921 * in the scan table struct bss_descriptor for that entry.
922 *
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400923 * @param bss Output parameter: Pointer to the BSS Entry
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924 *
925 * @return 0 or -1
926 */
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400927static int libertas_process_bss(struct bss_descriptor * bss,
928 u8 ** pbeaconinfo, int *bytesleft)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200929{
930 enum ieeetypes_elementid elemID;
931 struct ieeetypes_fhparamset *pFH;
932 struct ieeetypes_dsparamset *pDS;
933 struct ieeetypes_cfparamset *pCF;
934 struct ieeetypes_ibssparamset *pibss;
935 struct ieeetypes_capinfo *pcap;
936 struct WLAN_802_11_FIXED_IEs fixedie;
937 u8 *pcurrentptr;
938 u8 *pRate;
939 u8 elemlen;
940 u8 bytestocopy;
941 u8 ratesize;
942 u16 beaconsize;
943 u8 founddatarateie;
944 int bytesleftforcurrentbeacon;
Holger Schurig9012b282007-05-25 11:27:16 -0400945 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200946
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200947 struct IE_WPA *pIe;
948 const u8 oui01[4] = { 0x00, 0x50, 0xf2, 0x01 };
949
950 struct ieeetypes_countryinfoset *pcountryinfo;
951
Holger Schurig9012b282007-05-25 11:27:16 -0400952 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200953
954 founddatarateie = 0;
955 ratesize = 0;
956 beaconsize = 0;
957
958 if (*bytesleft >= sizeof(beaconsize)) {
959 /* Extract & convert beacon size from the command buffer */
960 memcpy(&beaconsize, *pbeaconinfo, sizeof(beaconsize));
961 beaconsize = le16_to_cpu(beaconsize);
962 *bytesleft -= sizeof(beaconsize);
963 *pbeaconinfo += sizeof(beaconsize);
964 }
965
966 if (beaconsize == 0 || beaconsize > *bytesleft) {
967
968 *pbeaconinfo += *bytesleft;
969 *bytesleft = 0;
970
971 return -1;
972 }
973
974 /* Initialize the current working beacon pointer for this BSS iteration */
975 pcurrentptr = *pbeaconinfo;
976
977 /* Advance the return beacon pointer past the current beacon */
978 *pbeaconinfo += beaconsize;
979 *bytesleft -= beaconsize;
980
981 bytesleftforcurrentbeacon = beaconsize;
982
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400983 memcpy(bss->bssid, pcurrentptr, ETH_ALEN);
Dan Williams02eb2292007-05-25 17:27:31 -0400984 lbs_deb_scan("process_bss: AP BSSID " MAC_FMT "\n", MAC_ARG(bss->bssid));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200985
986 pcurrentptr += ETH_ALEN;
987 bytesleftforcurrentbeacon -= ETH_ALEN;
988
989 if (bytesleftforcurrentbeacon < 12) {
Dan Williamsfcdb53d2007-05-25 16:15:56 -0400990 lbs_deb_scan("process_bss: Not enough bytes left\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200991 return -1;
992 }
993
994 /*
995 * next 4 fields are RSSI, time stamp, beacon interval,
996 * and capability information
997 */
998
999 /* RSSI is 1 byte long */
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001000 bss->rssi = le32_to_cpu((long)(*pcurrentptr));
1001 lbs_deb_scan("process_bss: RSSI=%02X\n", *pcurrentptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001002 pcurrentptr += 1;
1003 bytesleftforcurrentbeacon -= 1;
1004
1005 /* time stamp is 8 bytes long */
1006 memcpy(fixedie.timestamp, pcurrentptr, 8);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001007 memcpy(bss->timestamp, pcurrentptr, 8);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001008 pcurrentptr += 8;
1009 bytesleftforcurrentbeacon -= 8;
1010
1011 /* beacon interval is 2 bytes long */
1012 memcpy(&fixedie.beaconinterval, pcurrentptr, 2);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001013 bss->beaconperiod = le16_to_cpu(fixedie.beaconinterval);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001014 pcurrentptr += 2;
1015 bytesleftforcurrentbeacon -= 2;
1016
1017 /* capability information is 2 bytes long */
1018 memcpy(&fixedie.capabilities, pcurrentptr, 2);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001019 lbs_deb_scan("process_bss: fixedie.capabilities=0x%X\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001020 fixedie.capabilities);
1021 fixedie.capabilities = le16_to_cpu(fixedie.capabilities);
1022 pcap = (struct ieeetypes_capinfo *) & fixedie.capabilities;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001023 memcpy(&bss->cap, pcap, sizeof(struct ieeetypes_capinfo));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001024 pcurrentptr += 2;
1025 bytesleftforcurrentbeacon -= 2;
1026
1027 /* rest of the current buffer are IE's */
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001028 lbs_deb_scan("process_bss: IE length for this AP = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029 bytesleftforcurrentbeacon);
1030
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001031 lbs_dbg_hex("process_bss: IE info", (u8 *) pcurrentptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001032 bytesleftforcurrentbeacon);
1033
1034 if (pcap->privacy) {
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001035 lbs_deb_scan("process_bss: AP WEP enabled\n");
1036 bss->privacy = wlan802_11privfilter8021xWEP;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037 } else {
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001038 bss->privacy = wlan802_11privfilteracceptall;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001039 }
1040
1041 if (pcap->ibss == 1) {
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001042 bss->mode = IW_MODE_ADHOC;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001043 } else {
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001044 bss->mode = IW_MODE_INFRA;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001045 }
1046
1047 /* process variable IE */
1048 while (bytesleftforcurrentbeacon >= 2) {
1049 elemID = (enum ieeetypes_elementid) (*((u8 *) pcurrentptr));
1050 elemlen = *((u8 *) pcurrentptr + 1);
1051
1052 if (bytesleftforcurrentbeacon < elemlen) {
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001053 lbs_deb_scan("process_bss: error in processing IE, "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001054 "bytes left < IE length\n");
1055 bytesleftforcurrentbeacon = 0;
1056 continue;
1057 }
1058
1059 switch (elemID) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001060 case SSID:
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001061 bss->ssid.ssidlength = elemlen;
1062 memcpy(bss->ssid.ssid, (pcurrentptr + 2), elemlen);
1063 lbs_deb_scan("ssid '%s'\n", bss->ssid.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001064 break;
1065
1066 case SUPPORTED_RATES:
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001067 memcpy(bss->datarates, (pcurrentptr + 2), elemlen);
1068 memmove(bss->libertas_supported_rates, (pcurrentptr + 2),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001069 elemlen);
1070 ratesize = elemlen;
1071 founddatarateie = 1;
1072 break;
1073
1074 case EXTRA_IE:
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001075 lbs_deb_scan("process_bss: EXTRA_IE Found!\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001076 break;
1077
1078 case FH_PARAM_SET:
1079 pFH = (struct ieeetypes_fhparamset *) pcurrentptr;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001080 memmove(&bss->phyparamset.fhparamset, pFH,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001081 sizeof(struct ieeetypes_fhparamset));
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001082 bss->phyparamset.fhparamset.dwelltime
1083 = le16_to_cpu(bss->phyparamset.fhparamset.dwelltime);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001084 break;
1085
1086 case DS_PARAM_SET:
1087 pDS = (struct ieeetypes_dsparamset *) pcurrentptr;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001088 bss->channel = pDS->currentchan;
1089 memcpy(&bss->phyparamset.dsparamset, pDS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001090 sizeof(struct ieeetypes_dsparamset));
1091 break;
1092
1093 case CF_PARAM_SET:
1094 pCF = (struct ieeetypes_cfparamset *) pcurrentptr;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001095 memcpy(&bss->ssparamset.cfparamset, pCF,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001096 sizeof(struct ieeetypes_cfparamset));
1097 break;
1098
1099 case IBSS_PARAM_SET:
1100 pibss = (struct ieeetypes_ibssparamset *) pcurrentptr;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001101 bss->atimwindow = le32_to_cpu(pibss->atimwindow);
1102 memmove(&bss->ssparamset.ibssparamset, pibss,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001103 sizeof(struct ieeetypes_ibssparamset));
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001104 bss->ssparamset.ibssparamset.atimwindow
1105 = le16_to_cpu(bss->ssparamset.ibssparamset.atimwindow);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001106 break;
1107
1108 /* Handle Country Info IE */
1109 case COUNTRY_INFO:
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001110 pcountryinfo = (struct ieeetypes_countryinfoset *) pcurrentptr;
1111 if (pcountryinfo->len < sizeof(pcountryinfo->countrycode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001112 || pcountryinfo->len > 254) {
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001113 lbs_deb_scan("process_bss: 11D- Err "
Dan Williams4269e2a2007-05-10 23:10:18 -04001114 "CountryInfo len =%d min=%zd max=254\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001115 pcountryinfo->len,
1116 sizeof(pcountryinfo->countrycode));
Holger Schurig9012b282007-05-25 11:27:16 -04001117 ret = -1;
1118 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001119 }
1120
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001121 memcpy(&bss->countryinfo,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001122 pcountryinfo, pcountryinfo->len + 2);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001123 lbs_dbg_hex("process_bss: 11D- CountryInfo:",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001124 (u8 *) pcountryinfo,
1125 (u32) (pcountryinfo->len + 2));
1126 break;
1127
1128 case EXTENDED_SUPPORTED_RATES:
1129 /*
1130 * only process extended supported rate
1131 * if data rate is already found.
1132 * data rate IE should come before
1133 * extended supported rate IE
1134 */
1135 if (founddatarateie) {
1136 if ((elemlen + ratesize) > WLAN_SUPPORTED_RATES) {
1137 bytestocopy =
1138 (WLAN_SUPPORTED_RATES - ratesize);
1139 } else {
1140 bytestocopy = elemlen;
1141 }
1142
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001143 pRate = (u8 *) bss->datarates;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001144 pRate += ratesize;
1145 memmove(pRate, (pcurrentptr + 2), bytestocopy);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001146 pRate = (u8 *) bss->libertas_supported_rates;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001147 pRate += ratesize;
1148 memmove(pRate, (pcurrentptr + 2), bytestocopy);
1149 }
1150 break;
1151
1152 case VENDOR_SPECIFIC_221:
1153#define IE_ID_LEN_FIELDS_BYTES 2
1154 pIe = (struct IE_WPA *)pcurrentptr;
1155
Dan Williams51b0c9d2007-05-10 22:51:28 -04001156 if (memcmp(pIe->oui, oui01, sizeof(oui01)))
1157 break;
1158
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001159 bss->wpa_ie_len = min(elemlen + IE_ID_LEN_FIELDS_BYTES,
1160 MAX_WPA_IE_LEN);
1161 memcpy(bss->wpa_ie, pcurrentptr, bss->wpa_ie_len);
1162 lbs_dbg_hex("process_bss: WPA IE", bss->wpa_ie, elemlen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001163 break;
1164 case WPA2_IE:
1165 pIe = (struct IE_WPA *)pcurrentptr;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001166 bss->rsn_ie_len = min(elemlen + IE_ID_LEN_FIELDS_BYTES,
1167 MAX_WPA_IE_LEN);
1168 memcpy(bss->rsn_ie, pcurrentptr, bss->rsn_ie_len);
1169 lbs_dbg_hex("process_bss: RSN_IE", bss->rsn_ie, elemlen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170 break;
1171 case TIM:
1172 break;
1173
1174 case CHALLENGE_TEXT:
1175 break;
1176 }
1177
1178 pcurrentptr += elemlen + 2;
1179
1180 /* need to account for IE ID and IE len */
1181 bytesleftforcurrentbeacon -= (elemlen + 2);
1182
1183 } /* while (bytesleftforcurrentbeacon > 2) */
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001184
1185 /* Timestamp */
1186 bss->last_scanned = jiffies;
1187
Holger Schurig9012b282007-05-25 11:27:16 -04001188 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001189
Holger Schurig9012b282007-05-25 11:27:16 -04001190done:
1191 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
1192 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001193}
1194
1195/**
1196 * @brief Compare two SSIDs
1197 *
1198 * @param ssid1 A pointer to ssid to compare
1199 * @param ssid2 A pointer to ssid to compare
1200 *
1201 * @return 0--ssid is same, otherwise is different
1202 */
1203int libertas_SSID_cmp(struct WLAN_802_11_SSID *ssid1, struct WLAN_802_11_SSID *ssid2)
1204{
1205 if (!ssid1 || !ssid2)
1206 return -1;
1207
1208 if (ssid1->ssidlength != ssid2->ssidlength)
1209 return -1;
1210
1211 return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssidlength);
1212}
1213
1214/**
1215 * @brief This function finds a specific compatible BSSID in the scan list
1216 *
1217 * @param adapter A pointer to wlan_adapter
1218 * @param bssid BSSID to find in the scan list
1219 * @param mode Network mode: Infrastructure or IBSS
1220 *
1221 * @return index in BSSID list, or error return code (< 0)
1222 */
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001223struct bss_descriptor * libertas_find_BSSID_in_list(wlan_adapter * adapter,
1224 u8 * bssid, u8 mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001225{
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001226 struct bss_descriptor * iter_bss;
1227 struct bss_descriptor * found_bss = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001228
1229 if (!bssid)
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001230 return NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001231
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001232 lbs_dbg_hex("libertas_find_BSSID_in_list: looking for ",
1233 bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001234
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001235 /* Look through the scan table for a compatible match. The loop will
1236 * continue past a matched bssid that is not compatible in case there
1237 * is an AP with multiple SSIDs assigned to the same BSSID
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001238 */
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001239 mutex_lock(&adapter->lock);
1240 list_for_each_entry (iter_bss, &adapter->network_list, list) {
Dan Williams3cf209312007-05-25 17:28:30 -04001241 if (compare_ether_addr(iter_bss->bssid, bssid))
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001242 continue; /* bssid doesn't match */
1243 switch (mode) {
1244 case IW_MODE_INFRA:
1245 case IW_MODE_ADHOC:
1246 if (!is_network_compatible(adapter, iter_bss, mode))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001247 break;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001248 found_bss = iter_bss;
1249 break;
1250 default:
1251 found_bss = iter_bss;
1252 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001253 }
1254 }
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001255 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001256
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001257 return found_bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001258}
1259
1260/**
1261 * @brief This function finds ssid in ssid list.
1262 *
1263 * @param adapter A pointer to wlan_adapter
1264 * @param ssid SSID to find in the list
1265 * @param bssid BSSID to qualify the SSID selection (if provided)
1266 * @param mode Network mode: Infrastructure or IBSS
1267 *
1268 * @return index in BSSID list
1269 */
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001270struct bss_descriptor * libertas_find_SSID_in_list(wlan_adapter * adapter,
Dan Williams0dc5a292007-05-10 22:58:02 -04001271 struct WLAN_802_11_SSID *ssid, u8 * bssid, u8 mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001272{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001273 u8 bestrssi = 0;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001274 struct bss_descriptor * iter_bss = NULL;
1275 struct bss_descriptor * found_bss = NULL;
1276 struct bss_descriptor * tmp_oldest = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001277
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001278 mutex_lock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001279
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001280 list_for_each_entry (iter_bss, &adapter->network_list, list) {
1281 if ( !tmp_oldest
1282 || (iter_bss->last_scanned < tmp_oldest->last_scanned))
1283 tmp_oldest = iter_bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001284
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001285 if (libertas_SSID_cmp(&iter_bss->ssid, ssid) != 0)
1286 continue; /* ssid doesn't match */
Dan Williams3cf209312007-05-25 17:28:30 -04001287 if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0)
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001288 continue; /* bssid doesn't match */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001289
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001290 switch (mode) {
1291 case IW_MODE_INFRA:
1292 case IW_MODE_ADHOC:
1293 if (!is_network_compatible(adapter, iter_bss, mode))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001294 break;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001295
1296 if (bssid) {
1297 /* Found requested BSSID */
1298 found_bss = iter_bss;
1299 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001300 }
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001301
1302 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
1303 bestrssi = SCAN_RSSI(iter_bss->rssi);
1304 found_bss = iter_bss;
1305 }
1306 break;
1307 case IW_MODE_AUTO:
1308 default:
1309 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
1310 bestrssi = SCAN_RSSI(iter_bss->rssi);
1311 found_bss = iter_bss;
1312 }
1313 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001314 }
1315 }
1316
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001317out:
1318 mutex_unlock(&adapter->lock);
1319 return found_bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001320}
1321
1322/**
1323 * @brief This function finds the best SSID in the Scan List
1324 *
1325 * Search the scan table for the best SSID that also matches the current
1326 * adapter network preference (infrastructure or adhoc)
1327 *
1328 * @param adapter A pointer to wlan_adapter
1329 *
1330 * @return index in BSSID list
1331 */
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001332struct bss_descriptor * libertas_find_best_SSID_in_list(wlan_adapter * adapter,
1333 u8 mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001334{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335 u8 bestrssi = 0;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001336 struct bss_descriptor * iter_bss;
1337 struct bss_descriptor * best_bss = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001338
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001339 mutex_lock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001340
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001341 list_for_each_entry (iter_bss, &adapter->network_list, list) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001342 switch (mode) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001343 case IW_MODE_INFRA:
1344 case IW_MODE_ADHOC:
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001345 if (!is_network_compatible(adapter, iter_bss, mode))
1346 break;
1347 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
1348 break;
1349 bestrssi = SCAN_RSSI(iter_bss->rssi);
1350 best_bss = iter_bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001351 break;
Dan Williams0dc5a292007-05-10 22:58:02 -04001352 case IW_MODE_AUTO:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001353 default:
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001354 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
1355 break;
1356 bestrssi = SCAN_RSSI(iter_bss->rssi);
1357 best_bss = iter_bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001358 break;
1359 }
1360 }
1361
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001362 mutex_unlock(&adapter->lock);
1363 return best_bss;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001364}
1365
1366/**
1367 * @brief Find the AP with specific ssid in the scan list
1368 *
1369 * @param priv A pointer to wlan_private structure
1370 * @param pSSID A pointer to AP's ssid
1371 *
1372 * @return 0--success, otherwise--fail
1373 */
1374int libertas_find_best_network_SSID(wlan_private * priv,
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001375 struct WLAN_802_11_SSID *ssid,
Dan Williams0dc5a292007-05-10 22:58:02 -04001376 u8 preferred_mode, u8 *out_mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001377{
1378 wlan_adapter *adapter = priv->adapter;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001379 int ret = -1;
1380 struct bss_descriptor * found;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001381
Holger Schurig9012b282007-05-25 11:27:16 -04001382 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001383
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001384 memset(ssid, 0, sizeof(struct WLAN_802_11_SSID));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001385
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001386 wlan_scan_networks(priv, NULL, 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001387 if (adapter->surpriseremoved)
1388 return -1;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001389
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001390 wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
1391
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001392 found = libertas_find_best_SSID_in_list(adapter, preferred_mode);
1393 if (found && (found->ssid.ssidlength > 0)) {
1394 memcpy(ssid, &found->ssid, sizeof(struct WLAN_802_11_SSID));
1395 *out_mode = found->mode;
1396 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001397 }
1398
Holger Schurig9012b282007-05-25 11:27:16 -04001399 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001400 return ret;
1401}
1402
1403/**
1404 * @brief Scan Network
1405 *
1406 * @param dev A pointer to net_device structure
1407 * @param info A pointer to iw_request_info structure
1408 * @param vwrq A pointer to iw_param structure
1409 * @param extra A pointer to extra data buf
1410 *
1411 * @return 0 --success, otherwise fail
1412 */
1413int libertas_set_scan(struct net_device *dev, struct iw_request_info *info,
1414 struct iw_param *vwrq, char *extra)
1415{
1416 wlan_private *priv = dev->priv;
1417 wlan_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001418
Holger Schurig9012b282007-05-25 11:27:16 -04001419 lbs_deb_enter(LBS_DEB_SCAN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001420
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001421 wlan_scan_networks(priv, NULL, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001422
1423 if (adapter->surpriseremoved)
1424 return -1;
1425
Holger Schurig9012b282007-05-25 11:27:16 -04001426 lbs_deb_leave(LBS_DEB_SCAN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001427 return 0;
1428}
1429
1430/**
1431 * @brief Send a scan command for all available channels filtered on a spec
1432 *
1433 * @param priv A pointer to wlan_private structure
1434 * @param prequestedssid A pointer to AP's ssid
1435 * @param keeppreviousscan Flag used to save/clear scan table before scan
1436 *
1437 * @return 0-success, otherwise fail
1438 */
1439int libertas_send_specific_SSID_scan(wlan_private * priv,
1440 struct WLAN_802_11_SSID *prequestedssid,
Dan Williamseb8f7332007-05-25 16:25:21 -04001441 u8 clear_ssid)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001442{
1443 wlan_adapter *adapter = priv->adapter;
1444 struct wlan_ioctl_user_scan_cfg scancfg;
Dan Williamseb8f7332007-05-25 16:25:21 -04001445 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001446
Holger Schurig9012b282007-05-25 11:27:16 -04001447 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001448
Dan Williamseb8f7332007-05-25 16:25:21 -04001449 if (prequestedssid == NULL)
1450 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001451
1452 memset(&scancfg, 0x00, sizeof(scancfg));
Dan Williamseb8f7332007-05-25 16:25:21 -04001453 memcpy(scancfg.ssid, prequestedssid->ssid, prequestedssid->ssidlength);
1454 scancfg.ssid_len = prequestedssid->ssidlength;
1455 scancfg.clear_ssid = clear_ssid;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001456
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001457 wlan_scan_networks(priv, &scancfg, 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001458 if (adapter->surpriseremoved)
1459 return -1;
1460 wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
1461
Dan Williamseb8f7332007-05-25 16:25:21 -04001462out:
Holger Schurig9012b282007-05-25 11:27:16 -04001463 lbs_deb_leave(LBS_DEB_ASSOC);
Dan Williamseb8f7332007-05-25 16:25:21 -04001464 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001465}
1466
1467/**
1468 * @brief scan an AP with specific BSSID
1469 *
1470 * @param priv A pointer to wlan_private structure
1471 * @param bssid A pointer to AP's bssid
1472 * @param keeppreviousscan Flag used to save/clear scan table before scan
1473 *
1474 * @return 0-success, otherwise fail
1475 */
Dan Williamseb8f7332007-05-25 16:25:21 -04001476int libertas_send_specific_BSSID_scan(wlan_private * priv, u8 * bssid, u8 clear_bssid)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001477{
1478 struct wlan_ioctl_user_scan_cfg scancfg;
1479
Holger Schurig9012b282007-05-25 11:27:16 -04001480 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001481
Dan Williamseb8f7332007-05-25 16:25:21 -04001482 if (bssid == NULL)
1483 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001484
1485 memset(&scancfg, 0x00, sizeof(scancfg));
Dan Williamseb8f7332007-05-25 16:25:21 -04001486 memcpy(scancfg.bssid, bssid, ETH_ALEN);
1487 scancfg.clear_bssid = clear_bssid;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001488
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001489 wlan_scan_networks(priv, &scancfg, 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001490 if (priv->adapter->surpriseremoved)
1491 return -1;
1492 wait_event_interruptible(priv->adapter->cmd_pending,
1493 !priv->adapter->nr_cmd_pending);
1494
Dan Williamseb8f7332007-05-25 16:25:21 -04001495out:
Holger Schurig9012b282007-05-25 11:27:16 -04001496 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001497 return 0;
1498}
1499
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001500static inline char *libertas_translate_scan(wlan_private *priv,
1501 char *start, char *stop,
1502 struct bss_descriptor *bss)
1503{
1504 wlan_adapter *adapter = priv->adapter;
1505 struct chan_freq_power *cfp;
1506 char *current_val; /* For rates */
1507 struct iw_event iwe; /* Temporary buffer */
1508 int j;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001509#define PERFECT_RSSI ((u8)50)
1510#define WORST_RSSI ((u8)0)
1511#define RSSI_DIFF ((u8)(PERFECT_RSSI - WORST_RSSI))
1512 u8 rssi;
1513
1514 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, bss->channel);
1515 if (!cfp) {
1516 lbs_deb_scan("Invalid channel number %d\n", bss->channel);
1517 return NULL;
1518 }
1519
1520 /* First entry *MUST* be the AP BSSID */
1521 iwe.cmd = SIOCGIWAP;
1522 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1523 memcpy(iwe.u.ap_addr.sa_data, &bss->bssid, ETH_ALEN);
1524 start = iwe_stream_add_event(start, stop, &iwe, IW_EV_ADDR_LEN);
1525
1526 /* SSID */
1527 iwe.cmd = SIOCGIWESSID;
1528 iwe.u.data.flags = 1;
1529 iwe.u.data.length = min(bss->ssid.ssidlength, (u32) IW_ESSID_MAX_SIZE);
1530 start = iwe_stream_add_point(start, stop, &iwe, bss->ssid.ssid);
1531
1532 /* Mode */
1533 iwe.cmd = SIOCGIWMODE;
1534 iwe.u.mode = bss->mode;
1535 start = iwe_stream_add_event(start, stop, &iwe, IW_EV_UINT_LEN);
1536
1537 /* Frequency */
1538 iwe.cmd = SIOCGIWFREQ;
1539 iwe.u.freq.m = (long)cfp->freq * 100000;
1540 iwe.u.freq.e = 1;
1541 start = iwe_stream_add_event(start, stop, &iwe, IW_EV_FREQ_LEN);
1542
1543 /* Add quality statistics */
1544 iwe.cmd = IWEVQUAL;
1545 iwe.u.qual.updated = IW_QUAL_ALL_UPDATED;
1546 iwe.u.qual.level = SCAN_RSSI(bss->rssi);
1547
1548 rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
1549 iwe.u.qual.qual =
1550 (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) *
1551 (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) /
1552 (RSSI_DIFF * RSSI_DIFF);
1553 if (iwe.u.qual.qual > 100)
1554 iwe.u.qual.qual = 100;
1555
1556 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
1557 iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
1558 } else {
1559 iwe.u.qual.noise =
1560 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1561 }
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001562
Dan Williams80e78ef2007-05-25 22:18:47 -04001563 /* Locally created ad-hoc BSSs won't have beacons if this is the
1564 * only station in the adhoc network; so get signal strength
1565 * from receive statistics.
1566 */
1567 if ((adapter->mode == IW_MODE_ADHOC)
1568 && adapter->adhoccreate
1569 && !libertas_SSID_cmp(&adapter->curbssparams.ssid, &bss->ssid)) {
1570 int snr, nf;
1571 snr = adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
1572 nf = adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
1573 iwe.u.qual.level = CAL_RSSI(snr, nf);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001574 }
1575 start = iwe_stream_add_event(start, stop, &iwe, IW_EV_QUAL_LEN);
1576
1577 /* Add encryption capability */
1578 iwe.cmd = SIOCGIWENCODE;
1579 if (bss->privacy) {
1580 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1581 } else {
1582 iwe.u.data.flags = IW_ENCODE_DISABLED;
1583 }
1584 iwe.u.data.length = 0;
1585 start = iwe_stream_add_point(start, stop, &iwe, bss->ssid.ssid);
1586
1587 current_val = start + IW_EV_LCP_LEN;
1588
1589 iwe.cmd = SIOCGIWRATE;
1590 iwe.u.bitrate.fixed = 0;
1591 iwe.u.bitrate.disabled = 0;
1592 iwe.u.bitrate.value = 0;
1593
1594 for (j = 0; j < sizeof(bss->libertas_supported_rates); j++) {
1595 u8 rate = bss->libertas_supported_rates[j];
1596 if (rate == 0)
1597 break; /* no more rates */
1598 /* Bit rate given in 500 kb/s units (+ 0x80) */
1599 iwe.u.bitrate.value = (rate & 0x7f) * 500000;
1600 current_val = iwe_stream_add_value(start, current_val,
1601 stop, &iwe, IW_EV_PARAM_LEN);
1602 }
1603 if ((bss->mode == IW_MODE_ADHOC)
1604 && !libertas_SSID_cmp(&adapter->curbssparams.ssid, &bss->ssid)
1605 && adapter->adhoccreate) {
1606 iwe.u.bitrate.value = 22 * 500000;
1607 current_val = iwe_stream_add_value(start, current_val,
1608 stop, &iwe, IW_EV_PARAM_LEN);
1609 }
1610 /* Check if we added any event */
1611 if((current_val - start) > IW_EV_LCP_LEN)
1612 start = current_val;
1613
1614 memset(&iwe, 0, sizeof(iwe));
1615 if (bss->wpa_ie_len) {
1616 char buf[MAX_WPA_IE_LEN];
1617 memcpy(buf, bss->wpa_ie, bss->wpa_ie_len);
1618 iwe.cmd = IWEVGENIE;
1619 iwe.u.data.length = bss->wpa_ie_len;
1620 start = iwe_stream_add_point(start, stop, &iwe, buf);
1621 }
1622
1623 memset(&iwe, 0, sizeof(iwe));
1624 if (bss->rsn_ie_len) {
1625 char buf[MAX_WPA_IE_LEN];
1626 memcpy(buf, bss->rsn_ie, bss->rsn_ie_len);
1627 iwe.cmd = IWEVGENIE;
1628 iwe.u.data.length = bss->rsn_ie_len;
1629 start = iwe_stream_add_point(start, stop, &iwe, buf);
1630 }
1631
1632 return start;
1633}
1634
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001635/**
1636 * @brief Retrieve the scan table entries via wireless tools IOCTL call
1637 *
1638 * @param dev A pointer to net_device structure
1639 * @param info A pointer to iw_request_info structure
1640 * @param dwrq A pointer to iw_point structure
1641 * @param extra A pointer to extra data buf
1642 *
1643 * @return 0 --success, otherwise fail
1644 */
1645int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
1646 struct iw_point *dwrq, char *extra)
1647{
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001648#define SCAN_ITEM_SIZE 128
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001649 wlan_private *priv = dev->priv;
1650 wlan_adapter *adapter = priv->adapter;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001651 int err = 0;
1652 char *ev = extra;
1653 char *stop = ev + dwrq->length;
1654 struct bss_descriptor * iter_bss;
1655 struct bss_descriptor * safe;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001656
Holger Schurig9012b282007-05-25 11:27:16 -04001657 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001658
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001659 /* If we've got an uncompleted scan, schedule the next part */
1660 if (!adapter->nr_cmd_pending && adapter->last_scanned_channel)
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001661 wlan_scan_networks(priv, NULL, 0);
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001662
Dan Williams80e78ef2007-05-25 22:18:47 -04001663 /* Update RSSI if current BSS is a locally created ad-hoc BSS */
1664 if ((adapter->inframode == wlan802_11ibss) && adapter->adhoccreate) {
1665 libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
1666 cmd_option_waitforrsp, 0, NULL);
1667 }
1668
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001669 mutex_lock(&adapter->lock);
1670 list_for_each_entry_safe (iter_bss, safe, &adapter->network_list, list) {
1671 char * next_ev;
1672 unsigned long stale_time;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001673
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001674 if (stop - ev < SCAN_ITEM_SIZE) {
1675 err = -E2BIG;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001676 break;
1677 }
1678
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001679 /* Prune old an old scan result */
1680 stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE;
1681 if (time_after(jiffies, stale_time)) {
1682 list_move_tail (&iter_bss->list,
1683 &adapter->network_free_list);
1684 clear_bss_descriptor(iter_bss);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001685 continue;
1686 }
1687
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001688 /* Translate to WE format this entry */
1689 next_ev = libertas_translate_scan(priv, ev, stop, iter_bss);
1690 if (next_ev == NULL)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001691 continue;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001692 ev = next_ev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001693 }
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001694 mutex_unlock(&adapter->lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001695
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001696 dwrq->length = (ev - extra);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001697 dwrq->flags = 0;
1698
Holger Schurig9012b282007-05-25 11:27:16 -04001699 lbs_deb_leave(LBS_DEB_ASSOC);
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001700 return err;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001701}
1702
1703/**
1704 * @brief Prepare a scan command to be sent to the firmware
1705 *
1706 * Use the wlan_scan_cmd_config sent to the command processing module in
1707 * the libertas_prepare_and_send_command to configure a cmd_ds_802_11_scan command
1708 * struct to send to firmware.
1709 *
1710 * The fixed fields specifying the BSS type and BSSID filters as well as a
1711 * variable number/length of TLVs are sent in the command to firmware.
1712 *
1713 * @param priv A pointer to wlan_private structure
1714 * @param cmd A pointer to cmd_ds_command structure to be sent to
1715 * firmware with the cmd_DS_801_11_SCAN structure
1716 * @param pdata_buf Void pointer cast of a wlan_scan_cmd_config struct used
1717 * to set the fields/TLVs for the command sent to firmware
1718 *
1719 * @return 0 or -1
1720 *
1721 * @sa wlan_scan_create_channel_list
1722 */
1723int libertas_cmd_80211_scan(wlan_private * priv,
1724 struct cmd_ds_command *cmd, void *pdata_buf)
1725{
1726 struct cmd_ds_802_11_scan *pscan = &cmd->params.scan;
1727 struct wlan_scan_cmd_config *pscancfg;
1728
Holger Schurig9012b282007-05-25 11:27:16 -04001729 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001730
1731 pscancfg = pdata_buf;
1732
1733 /* Set fixed field variables in scan command */
1734 pscan->bsstype = pscancfg->bsstype;
Dan Williamseb8f7332007-05-25 16:25:21 -04001735 memcpy(pscan->BSSID, pscancfg->bssid, sizeof(pscan->BSSID));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001736 memcpy(pscan->tlvbuffer, pscancfg->tlvbuffer, pscancfg->tlvbufferlen);
1737
1738 cmd->command = cpu_to_le16(cmd_802_11_scan);
1739
1740 /* size is equal to the sizeof(fixed portions) + the TLV len + header */
1741 cmd->size = cpu_to_le16(sizeof(pscan->bsstype)
1742 + sizeof(pscan->BSSID)
1743 + pscancfg->tlvbufferlen + S_DS_GEN);
1744
Holger Schurig9012b282007-05-25 11:27:16 -04001745 lbs_deb_scan("SCAN_CMD: command=%x, size=%x, seqnum=%x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001746 cmd->command, cmd->size, cmd->seqnum);
Holger Schurig9012b282007-05-25 11:27:16 -04001747
1748 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001749 return 0;
1750}
1751
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001752static inline int is_same_network(struct bss_descriptor *src,
1753 struct bss_descriptor *dst)
1754{
1755 /* A network is only a duplicate if the channel, BSSID, and ESSID
1756 * all match. We treat all <hidden> with the same BSSID and channel
1757 * as one network */
1758 return ((src->ssid.ssidlength == dst->ssid.ssidlength) &&
1759 (src->channel == dst->channel) &&
1760 !compare_ether_addr(src->bssid, dst->bssid) &&
1761 !memcmp(src->ssid.ssid, dst->ssid.ssid, src->ssid.ssidlength));
1762}
1763
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001764/**
1765 * @brief This function handles the command response of scan
1766 *
1767 * The response buffer for the scan command has the following
1768 * memory layout:
1769 *
1770 * .-----------------------------------------------------------.
1771 * | header (4 * sizeof(u16)): Standard command response hdr |
1772 * .-----------------------------------------------------------.
1773 * | bufsize (u16) : sizeof the BSS Description data |
1774 * .-----------------------------------------------------------.
1775 * | NumOfSet (u8) : Number of BSS Descs returned |
1776 * .-----------------------------------------------------------.
1777 * | BSSDescription data (variable, size given in bufsize) |
1778 * .-----------------------------------------------------------.
1779 * | TLV data (variable, size calculated using header->size, |
1780 * | bufsize and sizeof the fixed fields above) |
1781 * .-----------------------------------------------------------.
1782 *
1783 * @param priv A pointer to wlan_private structure
1784 * @param resp A pointer to cmd_ds_command
1785 *
1786 * @return 0 or -1
1787 */
1788int libertas_ret_80211_scan(wlan_private * priv, struct cmd_ds_command *resp)
1789{
1790 wlan_adapter *adapter = priv->adapter;
1791 struct cmd_ds_802_11_scan_rsp *pscan;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001792 struct mrvlietypes_data *ptlv;
1793 struct mrvlietypes_tsftimestamp *ptsftlv;
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001794 struct bss_descriptor * iter_bss;
1795 struct bss_descriptor * safe;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001796 u8 *pbssinfo;
1797 u16 scanrespsize;
1798 int bytesleft;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001799 int idx;
1800 int tlvbufsize;
1801 u64 tsfval;
Holger Schurig9012b282007-05-25 11:27:16 -04001802 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001803
Holger Schurig9012b282007-05-25 11:27:16 -04001804 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001805
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001806 /* Prune old entries from scan table */
1807 list_for_each_entry_safe (iter_bss, safe, &adapter->network_list, list) {
1808 unsigned long stale_time = iter_bss->last_scanned + DEFAULT_MAX_SCAN_AGE;
1809 if (time_before(jiffies, stale_time))
1810 continue;
1811 list_move_tail (&iter_bss->list, &adapter->network_free_list);
1812 clear_bss_descriptor(iter_bss);
1813 }
1814
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001815 pscan = &resp->params.scanresp;
1816
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001817 if (pscan->nr_sets > MAX_NETWORK_COUNT) {
1818 lbs_deb_scan(
1819 "SCAN_RESP: too many scan results (%d, max %d)!!\n",
1820 pscan->nr_sets, MAX_NETWORK_COUNT);
Holger Schurig9012b282007-05-25 11:27:16 -04001821 ret = -1;
1822 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001823 }
1824
1825 bytesleft = le16_to_cpu(pscan->bssdescriptsize);
Holger Schurig9012b282007-05-25 11:27:16 -04001826 lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001827
1828 scanrespsize = le16_to_cpu(resp->size);
Holger Schurig9012b282007-05-25 11:27:16 -04001829 lbs_deb_scan("SCAN_RESP: returned %d AP before parsing\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001830 pscan->nr_sets);
1831
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001832 pbssinfo = pscan->bssdesc_and_tlvbuffer;
1833
1834 /* The size of the TLV buffer is equal to the entire command response
1835 * size (scanrespsize) minus the fixed fields (sizeof()'s), the
1836 * BSS Descriptions (bssdescriptsize as bytesLef) and the command
1837 * response header (S_DS_GEN)
1838 */
1839 tlvbufsize = scanrespsize - (bytesleft + sizeof(pscan->bssdescriptsize)
1840 + sizeof(pscan->nr_sets)
1841 + S_DS_GEN);
1842
1843 ptlv = (struct mrvlietypes_data *) (pscan->bssdesc_and_tlvbuffer + bytesleft);
1844
1845 /* Search the TLV buffer space in the scan response for any valid TLVs */
1846 wlan_ret_802_11_scan_get_tlv_ptrs(ptlv, tlvbufsize, &ptsftlv);
1847
1848 /*
1849 * Process each scan response returned (pscan->nr_sets). Save
1850 * the information in the newbssentry and then insert into the
1851 * driver scan table either as an update to an existing entry
1852 * or as an addition at the end of the table
1853 */
1854 for (idx = 0; idx < pscan->nr_sets && bytesleft; idx++) {
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001855 struct bss_descriptor new;
1856 struct bss_descriptor * found = NULL;
1857 struct bss_descriptor * iter_bss = NULL;
1858 struct bss_descriptor * oldest = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001859
1860 /* Process the data fields and IEs returned for this BSS */
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001861 memset(&new, 0, sizeof (struct bss_descriptor));
1862 if (libertas_process_bss(&new, &pbssinfo, &bytesleft) != 0) {
1863 /* error parsing the scan response, skipped */
1864 lbs_deb_scan("SCAN_RESP: process_bss returned ERROR\n");
1865 continue;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001866 }
Dan Williamsfcdb53d2007-05-25 16:15:56 -04001867
1868 /* Try to find this bss in the scan table */
1869 list_for_each_entry (iter_bss, &adapter->network_list, list) {
1870 if (is_same_network(iter_bss, &new)) {
1871 found = iter_bss;
1872 break;
1873 }
1874
1875 if ((oldest == NULL) ||
1876 (iter_bss->last_scanned < oldest->last_scanned))
1877 oldest = iter_bss;
1878 }
1879
1880 if (found) {
1881 /* found, clear it */
1882 clear_bss_descriptor(found);
1883 } else if (!list_empty(&adapter->network_free_list)) {
1884 /* Pull one from the free list */
1885 found = list_entry(adapter->network_free_list.next,
1886 struct bss_descriptor, list);
1887 list_move_tail(&found->list, &adapter->network_list);
1888 } else if (oldest) {
1889 /* If there are no more slots, expire the oldest */
1890 found = oldest;
1891 clear_bss_descriptor(found);
1892 list_move_tail(&found->list, &adapter->network_list);
1893 } else {
1894 continue;
1895 }
1896
1897 lbs_deb_scan("SCAN_RESP: BSSID = " MAC_FMT "\n",
1898 new.bssid[0], new.bssid[1], new.bssid[2],
1899 new.bssid[3], new.bssid[4], new.bssid[5]);
1900
1901 /*
1902 * If the TSF TLV was appended to the scan results, save the
1903 * this entries TSF value in the networktsf field. The
1904 * networktsf is the firmware's TSF value at the time the
1905 * beacon or probe response was received.
1906 */
1907 if (ptsftlv) {
1908 memcpy(&tsfval, &ptsftlv->tsftable[idx], sizeof(tsfval));
1909 tsfval = le64_to_cpu(tsfval);
1910 memcpy(&new.networktsf, &tsfval, sizeof(new.networktsf));
1911 }
1912
1913 /* Copy the locally created newbssentry to the scan table */
1914 memcpy(found, &new, offsetof(struct bss_descriptor, list));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001915 }
1916
Holger Schurig9012b282007-05-25 11:27:16 -04001917 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001918
Holger Schurig9012b282007-05-25 11:27:16 -04001919done:
1920 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
1921 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001922}