blob: e009f9bd0ec741ce75013a699528bb3949bb8d35 [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>
11
12#include <net/ieee80211.h>
13#include <net/iw_handler.h>
14
15#include "host.h"
16#include "decl.h"
17#include "dev.h"
18#include "scan.h"
19
20//! Approximate amount of data needed to pass a scan result back to iwlist
21#define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \
22 + IW_ESSID_MAX_SIZE \
23 + IW_EV_UINT_LEN \
24 + IW_EV_FREQ_LEN \
25 + IW_EV_QUAL_LEN \
26 + IW_ESSID_MAX_SIZE \
27 + IW_EV_PARAM_LEN \
28 + 40) /* 40 for WPAIE */
29
30//! Memory needed to store a max sized channel List TLV for a firmware scan
31#define CHAN_TLV_MAX_SIZE (sizeof(struct mrvlietypesheader) \
32 + (MRVDRV_MAX_CHANNELS_PER_SCAN \
33 * sizeof(struct chanscanparamset)))
34
35//! Memory needed to store a max number/size SSID TLV for a firmware scan
36#define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvlietypes_ssidparamset))
37
38//! Maximum memory needed for a wlan_scan_cmd_config with all TLVs at max
39#define MAX_SCAN_CFG_ALLOC (sizeof(struct wlan_scan_cmd_config) \
40 + sizeof(struct mrvlietypes_numprobes) \
41 + CHAN_TLV_MAX_SIZE \
42 + SSID_TLV_MAX_SIZE)
43
44//! The maximum number of channels the firmware can scan per command
45#define MRVDRV_MAX_CHANNELS_PER_SCAN 14
46
47/**
48 * @brief Number of channels to scan per firmware scan command issuance.
49 *
50 * Number restricted to prevent hitting the limit on the amount of scan data
51 * returned in a single firmware scan command.
52 */
53#define MRVDRV_CHANNELS_PER_SCAN_CMD 4
54
55//! Scan time specified in the channel TLV for each channel for passive scans
56#define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100
57
58//! Scan time specified in the channel TLV for each channel for active scans
59#define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100
60
61//! Macro to enable/disable SSID checking before storing a scan table
62#ifdef DISCARD_BAD_SSID
63#define CHECK_SSID_IS_VALID(x) ssid_valid(&bssidEntry.ssid)
64#else
65#define CHECK_SSID_IS_VALID(x) 1
66#endif
67
68/**
69 * @brief Check if a scanned network compatible with the driver settings
70 *
71 * WEP WPA WPA2 ad-hoc encrypt Network
72 * enabled enabled enabled AES mode privacy WPA WPA2 Compatible
73 * 0 0 0 0 NONE 0 0 0 yes No security
74 * 1 0 0 0 NONE 1 0 0 yes Static WEP
75 * 0 1 0 0 x 1x 1 x yes WPA
76 * 0 0 1 0 x 1x x 1 yes WPA2
77 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
78 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
79 *
80 *
81 * @param adapter A pointer to wlan_adapter
82 * @param index Index in scantable to check against current driver settings
83 * @param mode Network mode: Infrastructure or IBSS
84 *
85 * @return Index in scantable, or error code if negative
86 */
Dan Williams0dc5a292007-05-10 22:58:02 -040087static int is_network_compatible(wlan_adapter * adapter, int index, u8 mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020088{
Holger Schurig9012b282007-05-25 11:27:16 -040089 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020090
Dan Williams0dc5a292007-05-10 22:58:02 -040091 if (adapter->scantable[index].mode == mode) {
Dan Williams889c05b2007-05-10 22:57:23 -040092 if ( !adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093 && !adapter->secinfo.WPAenabled
94 && !adapter->secinfo.WPA2enabled
Dan Williams51b0c9d2007-05-10 22:51:28 -040095 && adapter->scantable[index].wpa_ie[0] != WPA_IE
96 && adapter->scantable[index].rsn_ie[0] != WPA2_IE
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020097 && !adapter->scantable[index].privacy) {
98 /* no security */
Holger Schurig9012b282007-05-25 11:27:16 -040099 goto done;
Dan Williams889c05b2007-05-10 22:57:23 -0400100 } else if ( adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200101 && !adapter->secinfo.WPAenabled
102 && !adapter->secinfo.WPA2enabled
103 && adapter->scantable[index].privacy) {
104 /* static WEP enabled */
Holger Schurig9012b282007-05-25 11:27:16 -0400105 goto done;
Dan Williams889c05b2007-05-10 22:57:23 -0400106 } else if ( !adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200107 && adapter->secinfo.WPAenabled
108 && !adapter->secinfo.WPA2enabled
Dan Williams51b0c9d2007-05-10 22:51:28 -0400109 && (adapter->scantable[index].wpa_ie[0] == WPA_IE)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
111 && adapter->scantable[index].privacy */
112 ) {
113 /* WPA enabled */
Holger Schurig9012b282007-05-25 11:27:16 -0400114 lbs_deb_scan(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115 "is_network_compatible() WPA: index=%d wpa_ie=%#x "
Dan Williams9408c292007-05-10 22:55:20 -0400116 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200117 "privacy=%#x\n", index,
Dan Williams51b0c9d2007-05-10 22:51:28 -0400118 adapter->scantable[index].wpa_ie[0],
119 adapter->scantable[index].rsn_ie[0],
Dan Williams889c05b2007-05-10 22:57:23 -0400120 adapter->secinfo.wep_enabled ? "e" : "d",
121 adapter->secinfo.WPAenabled ? "e" : "d",
122 adapter->secinfo.WPA2enabled ? "e" : "d",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200123 adapter->scantable[index].privacy);
Holger Schurig9012b282007-05-25 11:27:16 -0400124 goto done;
Dan Williams889c05b2007-05-10 22:57:23 -0400125 } else if ( !adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200126 && !adapter->secinfo.WPAenabled
127 && adapter->secinfo.WPA2enabled
Dan Williams51b0c9d2007-05-10 22:51:28 -0400128 && (adapter->scantable[index].rsn_ie[0] == WPA2_IE)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
130 && adapter->scantable[index].privacy */
131 ) {
132 /* WPA2 enabled */
Holger Schurig9012b282007-05-25 11:27:16 -0400133 lbs_deb_scan(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134 "is_network_compatible() WPA2: index=%d wpa_ie=%#x "
Dan Williams9408c292007-05-10 22:55:20 -0400135 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200136 "privacy=%#x\n", index,
Dan Williams51b0c9d2007-05-10 22:51:28 -0400137 adapter->scantable[index].wpa_ie[0],
138 adapter->scantable[index].rsn_ie[0],
Dan Williams889c05b2007-05-10 22:57:23 -0400139 adapter->secinfo.wep_enabled ? "e" : "d",
140 adapter->secinfo.WPAenabled ? "e" : "d",
141 adapter->secinfo.WPA2enabled ? "e" : "d",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142 adapter->scantable[index].privacy);
Holger Schurig9012b282007-05-25 11:27:16 -0400143 goto done;
Dan Williams889c05b2007-05-10 22:57:23 -0400144 } else if ( !adapter->secinfo.wep_enabled
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200145 && !adapter->secinfo.WPAenabled
146 && !adapter->secinfo.WPA2enabled
Dan Williams51b0c9d2007-05-10 22:51:28 -0400147 && (adapter->scantable[index].wpa_ie[0] != WPA_IE)
148 && (adapter->scantable[index].rsn_ie[0] != WPA2_IE)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 && adapter->scantable[index].privacy) {
150 /* dynamic WEP enabled */
Holger Schurig9012b282007-05-25 11:27:16 -0400151 lbs_deb_scan(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152 "is_network_compatible() dynamic WEP: index=%d "
Dan Williams9408c292007-05-10 22:55:20 -0400153 "wpa_ie=%#x wpa2_ie=%#x privacy=%#x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154 index,
Dan Williams51b0c9d2007-05-10 22:51:28 -0400155 adapter->scantable[index].wpa_ie[0],
156 adapter->scantable[index].rsn_ie[0],
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200157 adapter->scantable[index].privacy);
Holger Schurig9012b282007-05-25 11:27:16 -0400158 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159 }
160
161 /* security doesn't match */
Holger Schurig9012b282007-05-25 11:27:16 -0400162 lbs_deb_scan(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163 "is_network_compatible() FAILED: index=%d wpa_ie=%#x "
Dan Williams9408c292007-05-10 22:55:20 -0400164 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s privacy=%#x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165 index,
Dan Williams51b0c9d2007-05-10 22:51:28 -0400166 adapter->scantable[index].wpa_ie[0],
167 adapter->scantable[index].rsn_ie[0],
Dan Williams889c05b2007-05-10 22:57:23 -0400168 adapter->secinfo.wep_enabled ? "e" : "d",
169 adapter->secinfo.WPAenabled ? "e" : "d",
170 adapter->secinfo.WPA2enabled ? "e" : "d",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200171 adapter->scantable[index].privacy);
Holger Schurig9012b282007-05-25 11:27:16 -0400172 index = -ECONNREFUSED;
173 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174 }
175
176 /* mode doesn't match */
Holger Schurig9012b282007-05-25 11:27:16 -0400177 index = -ENETUNREACH;
178
179done:
180 lbs_deb_leave_args(LBS_DEB_SCAN, "index %d", index);
181 return index;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200182}
183
184/**
185 * @brief This function validates a SSID as being able to be printed
186 *
187 * @param pssid SSID structure to validate
188 *
189 * @return TRUE or FALSE
190 */
191static u8 ssid_valid(struct WLAN_802_11_SSID *pssid)
192{
193 int ssididx;
194
195 for (ssididx = 0; ssididx < pssid->ssidlength; ssididx++) {
196 if (!isprint(pssid->ssid[ssididx])) {
197 return 0;
198 }
199 }
200
201 return 1;
202}
203
204/**
205 * @brief Post process the scan table after a new scan command has completed
206 *
207 * Inspect each entry of the scan table and try to find an entry that
208 * matches our current associated/joined network from the scan. If
209 * one is found, update the stored copy of the bssdescriptor for our
210 * current network.
211 *
212 * Debug dump the current scan table contents if compiled accordingly.
213 *
214 * @param priv A pointer to wlan_private structure
215 *
216 * @return void
217 */
218static void wlan_scan_process_results(wlan_private * priv)
219{
220 wlan_adapter *adapter = priv->adapter;
221 int foundcurrent;
222 int i;
223
224 foundcurrent = 0;
225
226 if (adapter->connect_status == libertas_connected) {
227 /* try to find the current BSSID in the new scan list */
228 for (i = 0; i < adapter->numinscantable; i++) {
229 if (!libertas_SSID_cmp(&adapter->scantable[i].ssid,
230 &adapter->curbssparams.ssid) &&
231 !memcmp(adapter->curbssparams.bssid,
Dan Williams4ace1132007-05-25 13:16:38 -0400232 adapter->scantable[i].bssid,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200233 ETH_ALEN)) {
234 foundcurrent = 1;
235 }
236 }
237
238 if (foundcurrent) {
239 /* Make a copy of current BSSID descriptor */
240 memcpy(&adapter->curbssparams.bssdescriptor,
241 &adapter->scantable[i],
242 sizeof(adapter->curbssparams.bssdescriptor));
243 }
244 }
245
246 for (i = 0; i < adapter->numinscantable; i++) {
Holger Schurig9012b282007-05-25 11:27:16 -0400247 lbs_deb_scan("Scan:(%02d) %02x:%02x:%02x:%02x:%02x:%02x, "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200248 "RSSI[%03d], SSID[%s]\n",
249 i,
Dan Williams4ace1132007-05-25 13:16:38 -0400250 adapter->scantable[i].bssid[0],
251 adapter->scantable[i].bssid[1],
252 adapter->scantable[i].bssid[2],
253 adapter->scantable[i].bssid[3],
254 adapter->scantable[i].bssid[4],
255 adapter->scantable[i].bssid[5],
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256 (s32) adapter->scantable[i].rssi,
257 adapter->scantable[i].ssid.ssid);
258 }
259}
260
261/**
262 * @brief Create a channel list for the driver to scan based on region info
263 *
264 * Use the driver region/band information to construct a comprehensive list
265 * of channels to scan. This routine is used for any scan that is not
266 * provided a specific channel list to scan.
267 *
268 * @param priv A pointer to wlan_private structure
269 * @param scanchanlist Output parameter: resulting channel list to scan
270 * @param filteredscan Flag indicating whether or not a BSSID or SSID filter
271 * is being sent in the command to firmware. Used to
272 * increase the number of channels sent in a scan
273 * command and to disable the firmware channel scan
274 * filter.
275 *
276 * @return void
277 */
278static void wlan_scan_create_channel_list(wlan_private * priv,
279 struct chanscanparamset * scanchanlist,
280 u8 filteredscan)
281{
282
283 wlan_adapter *adapter = priv->adapter;
284 struct region_channel *scanregion;
285 struct chan_freq_power *cfp;
286 int rgnidx;
287 int chanidx;
288 int nextchan;
289 u8 scantype;
290
291 chanidx = 0;
292
293 /* Set the default scan type to the user specified type, will later
294 * be changed to passive on a per channel basis if restricted by
295 * regulatory requirements (11d or 11h)
296 */
297 scantype = adapter->scantype;
298
299 for (rgnidx = 0; rgnidx < ARRAY_SIZE(adapter->region_channel); rgnidx++) {
300 if (priv->adapter->enable11d &&
301 adapter->connect_status != libertas_connected) {
302 /* Scan all the supported chan for the first scan */
303 if (!adapter->universal_channel[rgnidx].valid)
304 continue;
305 scanregion = &adapter->universal_channel[rgnidx];
306
307 /* clear the parsed_region_chan for the first scan */
308 memset(&adapter->parsed_region_chan, 0x00,
309 sizeof(adapter->parsed_region_chan));
310 } else {
311 if (!adapter->region_channel[rgnidx].valid)
312 continue;
313 scanregion = &adapter->region_channel[rgnidx];
314 }
315
316 for (nextchan = 0;
317 nextchan < scanregion->nrcfp; nextchan++, chanidx++) {
318
319 cfp = scanregion->CFP + nextchan;
320
321 if (priv->adapter->enable11d) {
322 scantype =
323 libertas_get_scan_type_11d(cfp->channel,
324 &adapter->
325 parsed_region_chan);
326 }
327
328 switch (scanregion->band) {
329 case BAND_B:
330 case BAND_G:
331 default:
332 scanchanlist[chanidx].radiotype =
333 cmd_scan_radio_type_bg;
334 break;
335 }
336
337 if (scantype == cmd_scan_type_passive) {
338 scanchanlist[chanidx].maxscantime =
339 cpu_to_le16
340 (MRVDRV_PASSIVE_SCAN_CHAN_TIME);
341 scanchanlist[chanidx].chanscanmode.passivescan =
342 1;
343 } else {
344 scanchanlist[chanidx].maxscantime =
345 cpu_to_le16
346 (MRVDRV_ACTIVE_SCAN_CHAN_TIME);
347 scanchanlist[chanidx].chanscanmode.passivescan =
348 0;
349 }
350
351 scanchanlist[chanidx].channumber = cfp->channel;
352
353 if (filteredscan) {
354 scanchanlist[chanidx].chanscanmode.
355 disablechanfilt = 1;
356 }
357 }
358 }
359}
360
361/**
362 * @brief Construct a wlan_scan_cmd_config structure to use in issue scan cmds
363 *
364 * Application layer or other functions can invoke wlan_scan_networks
365 * with a scan configuration supplied in a wlan_ioctl_user_scan_cfg struct.
366 * This structure is used as the basis of one or many wlan_scan_cmd_config
367 * commands that are sent to the command processing module and sent to
368 * firmware.
369 *
370 * Create a wlan_scan_cmd_config based on the following user supplied
371 * parameters (if present):
372 * - SSID filter
373 * - BSSID filter
374 * - Number of Probes to be sent
375 * - channel list
376 *
377 * If the SSID or BSSID filter is not present, disable/clear the filter.
378 * If the number of probes is not set, use the adapter default setting
379 * Qualify the channel
380 *
381 * @param priv A pointer to wlan_private structure
382 * @param puserscanin NULL or pointer to scan configuration parameters
383 * @param ppchantlvout Output parameter: Pointer to the start of the
384 * channel TLV portion of the output scan config
385 * @param pscanchanlist Output parameter: Pointer to the resulting channel
386 * list to scan
387 * @param pmaxchanperscan Output parameter: Number of channels to scan for
388 * each issuance of the firmware scan command
389 * @param pfilteredscan Output parameter: Flag indicating whether or not
390 * a BSSID or SSID filter is being sent in the
391 * command to firmware. Used to increase the number
392 * of channels sent in a scan command and to
393 * disable the firmware channel scan filter.
394 * @param pscancurrentonly Output parameter: Flag indicating whether or not
395 * we are only scanning our current active channel
396 *
397 * @return resulting scan configuration
398 */
399static struct wlan_scan_cmd_config *
400wlan_scan_setup_scan_config(wlan_private * priv,
401 const struct wlan_ioctl_user_scan_cfg * puserscanin,
402 struct mrvlietypes_chanlistparamset ** ppchantlvout,
403 struct chanscanparamset * pscanchanlist,
404 int *pmaxchanperscan,
405 u8 * pfilteredscan,
406 u8 * pscancurrentonly)
407{
408 wlan_adapter *adapter = priv->adapter;
409 const u8 zeromac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
410 struct mrvlietypes_numprobes *pnumprobestlv;
411 struct mrvlietypes_ssidparamset *pssidtlv;
412 struct wlan_scan_cmd_config * pscancfgout = NULL;
413 u8 *ptlvpos;
414 u16 numprobes;
415 u16 ssidlen;
416 int chanidx;
417 int scantype;
418 int scandur;
419 int channel;
420 int radiotype;
421
422 pscancfgout = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL);
423 if (pscancfgout == NULL)
424 goto out;
425
426 /* The tlvbufferlen is calculated for each scan command. The TLVs added
427 * in this routine will be preserved since the routine that sends
428 * the command will append channelTLVs at *ppchantlvout. The difference
429 * between the *ppchantlvout and the tlvbuffer start will be used
430 * to calculate the size of anything we add in this routine.
431 */
432 pscancfgout->tlvbufferlen = 0;
433
434 /* Running tlv pointer. Assigned to ppchantlvout at end of function
435 * so later routines know where channels can be added to the command buf
436 */
437 ptlvpos = pscancfgout->tlvbuffer;
438
439 /*
440 * Set the initial scan paramters for progressive scanning. If a specific
441 * BSSID or SSID is used, the number of channels in the scan command
442 * will be increased to the absolute maximum
443 */
444 *pmaxchanperscan = MRVDRV_CHANNELS_PER_SCAN_CMD;
445
446 /* Initialize the scan as un-filtered by firmware, set to TRUE below if
447 * a SSID or BSSID filter is sent in the command
448 */
449 *pfilteredscan = 0;
450
451 /* Initialize the scan as not being only on the current channel. If
452 * the channel list is customized, only contains one channel, and
453 * is the active channel, this is set true and data flow is not halted.
454 */
455 *pscancurrentonly = 0;
456
457 if (puserscanin) {
458
459 /* Set the bss type scan filter, use adapter setting if unset */
460 pscancfgout->bsstype =
461 (puserscanin->bsstype ? puserscanin->bsstype : adapter->
462 scanmode);
463
464 /* Set the number of probes to send, use adapter setting if unset */
465 numprobes = (puserscanin->numprobes ? puserscanin->numprobes :
466 adapter->scanprobes);
467
468 /*
469 * Set the BSSID filter to the incoming configuration,
470 * if non-zero. If not set, it will remain disabled (all zeros).
471 */
472 memcpy(pscancfgout->specificBSSID,
473 puserscanin->specificBSSID,
474 sizeof(pscancfgout->specificBSSID));
475
476 ssidlen = strlen(puserscanin->specificSSID);
477
478 if (ssidlen) {
479 pssidtlv =
480 (struct mrvlietypes_ssidparamset *) pscancfgout->
481 tlvbuffer;
482 pssidtlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
483 pssidtlv->header.len = cpu_to_le16(ssidlen);
484 memcpy(pssidtlv->ssid, puserscanin->specificSSID,
485 ssidlen);
486 ptlvpos += sizeof(pssidtlv->header) + ssidlen;
487 }
488
489 /*
490 * The default number of channels sent in the command is low to
491 * ensure the response buffer from the firmware does not truncate
492 * scan results. That is not an issue with an SSID or BSSID
493 * filter applied to the scan results in the firmware.
494 */
495 if (ssidlen || (memcmp(pscancfgout->specificBSSID,
496 &zeromac, sizeof(zeromac)) != 0)) {
497 *pmaxchanperscan = MRVDRV_MAX_CHANNELS_PER_SCAN;
498 *pfilteredscan = 1;
499 }
500 } else {
501 pscancfgout->bsstype = adapter->scanmode;
502 numprobes = adapter->scanprobes;
503 }
504
505 /* If the input config or adapter has the number of Probes set, add tlv */
506 if (numprobes) {
507 pnumprobestlv = (struct mrvlietypes_numprobes *) ptlvpos;
508 pnumprobestlv->header.type =
509 cpu_to_le16(TLV_TYPE_NUMPROBES);
510 pnumprobestlv->header.len = sizeof(pnumprobestlv->numprobes);
511 pnumprobestlv->numprobes = cpu_to_le16(numprobes);
512
513 ptlvpos +=
514 sizeof(pnumprobestlv->header) + pnumprobestlv->header.len;
515
516 pnumprobestlv->header.len =
517 cpu_to_le16(pnumprobestlv->header.len);
518 }
519
520 /*
521 * Set the output for the channel TLV to the address in the tlv buffer
522 * past any TLVs that were added in this fuction (SSID, numprobes).
523 * channel TLVs will be added past this for each scan command, preserving
524 * the TLVs that were previously added.
525 */
526 *ppchantlvout = (struct mrvlietypes_chanlistparamset *) ptlvpos;
527
528 if (puserscanin && puserscanin->chanlist[0].channumber) {
529
Holger Schurig9012b282007-05-25 11:27:16 -0400530 lbs_deb_scan("Scan: Using supplied channel list\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200531
532 for (chanidx = 0;
533 chanidx < WLAN_IOCTL_USER_SCAN_CHAN_MAX
534 && puserscanin->chanlist[chanidx].channumber; chanidx++) {
535
536 channel = puserscanin->chanlist[chanidx].channumber;
537 (pscanchanlist + chanidx)->channumber = channel;
538
539 radiotype = puserscanin->chanlist[chanidx].radiotype;
540 (pscanchanlist + chanidx)->radiotype = radiotype;
541
542 scantype = puserscanin->chanlist[chanidx].scantype;
543
544 if (scantype == cmd_scan_type_passive) {
545 (pscanchanlist +
546 chanidx)->chanscanmode.passivescan = 1;
547 } else {
548 (pscanchanlist +
549 chanidx)->chanscanmode.passivescan = 0;
550 }
551
552 if (puserscanin->chanlist[chanidx].scantime) {
553 scandur =
554 puserscanin->chanlist[chanidx].scantime;
555 } else {
556 if (scantype == cmd_scan_type_passive) {
557 scandur = MRVDRV_PASSIVE_SCAN_CHAN_TIME;
558 } else {
559 scandur = MRVDRV_ACTIVE_SCAN_CHAN_TIME;
560 }
561 }
562
563 (pscanchanlist + chanidx)->minscantime =
564 cpu_to_le16(scandur);
565 (pscanchanlist + chanidx)->maxscantime =
566 cpu_to_le16(scandur);
567 }
568
569 /* Check if we are only scanning the current channel */
570 if ((chanidx == 1) && (puserscanin->chanlist[0].channumber
571 ==
572 priv->adapter->curbssparams.channel)) {
573 *pscancurrentonly = 1;
Holger Schurig9012b282007-05-25 11:27:16 -0400574 lbs_deb_scan("Scan: Scanning current channel only");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200575 }
576
577 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400578 lbs_deb_scan("Scan: Creating full region channel list\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579 wlan_scan_create_channel_list(priv, pscanchanlist,
580 *pfilteredscan);
581 }
582
583out:
584 return pscancfgout;
585}
586
587/**
588 * @brief Construct and send multiple scan config commands to the firmware
589 *
590 * Previous routines have created a wlan_scan_cmd_config with any requested
591 * TLVs. This function splits the channel TLV into maxchanperscan lists
592 * and sends the portion of the channel TLV along with the other TLVs
593 * to the wlan_cmd routines for execution in the firmware.
594 *
595 * @param priv A pointer to wlan_private structure
596 * @param maxchanperscan Maximum number channels to be included in each
597 * scan command sent to firmware
598 * @param filteredscan Flag indicating whether or not a BSSID or SSID
599 * filter is being used for the firmware command
600 * scan command sent to firmware
601 * @param pscancfgout Scan configuration used for this scan.
602 * @param pchantlvout Pointer in the pscancfgout where the channel TLV
603 * should start. This is past any other TLVs that
604 * must be sent down in each firmware command.
605 * @param pscanchanlist List of channels to scan in maxchanperscan segments
606 *
607 * @return 0 or error return otherwise
608 */
609static int wlan_scan_channel_list(wlan_private * priv,
610 int maxchanperscan,
611 u8 filteredscan,
612 struct wlan_scan_cmd_config * pscancfgout,
613 struct mrvlietypes_chanlistparamset * pchantlvout,
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400614 struct chanscanparamset * pscanchanlist,
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400615 const struct wlan_ioctl_user_scan_cfg * puserscanin,
616 int full_scan)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617{
618 struct chanscanparamset *ptmpchan;
619 struct chanscanparamset *pstartchan;
620 u8 scanband;
621 int doneearly;
622 int tlvidx;
623 int ret = 0;
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400624 int scanned = 0;
625 union iwreq_data wrqu;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200626
Holger Schurig9012b282007-05-25 11:27:16 -0400627 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200628
629 if (pscancfgout == 0 || pchantlvout == 0 || pscanchanlist == 0) {
Holger Schurig9012b282007-05-25 11:27:16 -0400630 lbs_deb_scan("Scan: Null detect: %p, %p, %p\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200631 pscancfgout, pchantlvout, pscanchanlist);
632 return -1;
633 }
634
635 pchantlvout->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
636
637 /* Set the temp channel struct pointer to the start of the desired list */
638 ptmpchan = pscanchanlist;
639
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400640 if (priv->adapter->last_scanned_channel && !puserscanin)
641 ptmpchan += priv->adapter->last_scanned_channel;
642
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200643 /* Loop through the desired channel list, sending a new firmware scan
644 * commands for each maxchanperscan channels (or for 1,6,11 individually
645 * if configured accordingly)
646 */
647 while (ptmpchan->channumber) {
648
649 tlvidx = 0;
650 pchantlvout->header.len = 0;
651 scanband = ptmpchan->radiotype;
652 pstartchan = ptmpchan;
653 doneearly = 0;
654
655 /* Construct the channel TLV for the scan command. Continue to
656 * insert channel TLVs until:
657 * - the tlvidx hits the maximum configured per scan command
658 * - the next channel to insert is 0 (end of desired channel list)
659 * - doneearly is set (controlling individual scanning of 1,6,11)
660 */
661 while (tlvidx < maxchanperscan && ptmpchan->channumber
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400662 && !doneearly && scanned < 2) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200663
Holger Schurig9012b282007-05-25 11:27:16 -0400664 lbs_deb_scan(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200665 "Scan: Chan(%3d), Radio(%d), mode(%d,%d), Dur(%d)\n",
666 ptmpchan->channumber, ptmpchan->radiotype,
667 ptmpchan->chanscanmode.passivescan,
668 ptmpchan->chanscanmode.disablechanfilt,
669 ptmpchan->maxscantime);
670
671 /* Copy the current channel TLV to the command being prepared */
672 memcpy(pchantlvout->chanscanparam + tlvidx,
673 ptmpchan, sizeof(pchantlvout->chanscanparam));
674
675 /* Increment the TLV header length by the size appended */
676 pchantlvout->header.len +=
677 sizeof(pchantlvout->chanscanparam);
678
679 /*
680 * The tlv buffer length is set to the number of bytes of the
681 * between the channel tlv pointer and the start of the
682 * tlv buffer. This compensates for any TLVs that were appended
683 * before the channel list.
684 */
685 pscancfgout->tlvbufferlen = ((u8 *) pchantlvout
686 - pscancfgout->tlvbuffer);
687
688 /* Add the size of the channel tlv header and the data length */
689 pscancfgout->tlvbufferlen +=
690 (sizeof(pchantlvout->header)
691 + pchantlvout->header.len);
692
693 /* Increment the index to the channel tlv we are constructing */
694 tlvidx++;
695
696 doneearly = 0;
697
698 /* Stop the loop if the *current* channel is in the 1,6,11 set
699 * and we are not filtering on a BSSID or SSID.
700 */
701 if (!filteredscan && (ptmpchan->channumber == 1
702 || ptmpchan->channumber == 6
703 || ptmpchan->channumber == 11)) {
704 doneearly = 1;
705 }
706
707 /* Increment the tmp pointer to the next channel to be scanned */
708 ptmpchan++;
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400709 scanned++;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200710
711 /* Stop the loop if the *next* channel is in the 1,6,11 set.
712 * This will cause it to be the only channel scanned on the next
713 * interation
714 */
715 if (!filteredscan && (ptmpchan->channumber == 1
716 || ptmpchan->channumber == 6
717 || ptmpchan->channumber == 11)) {
718 doneearly = 1;
719 }
720 }
721
722 /* Send the scan command to the firmware with the specified cfg */
723 ret = libertas_prepare_and_send_command(priv, cmd_802_11_scan, 0,
724 0, 0, pscancfgout);
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400725 if (scanned >= 2 && !full_scan) {
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400726 priv->adapter->last_scanned_channel = ptmpchan->channumber;
Holger Schurig9012b282007-05-25 11:27:16 -0400727 ret = 0;
728 goto done;
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400729 }
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400730 scanned = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200731 }
732
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400733 priv->adapter->last_scanned_channel = ptmpchan->channumber;
734
735 memset(&wrqu, 0, sizeof(union iwreq_data));
Holger Schurig634b8f42007-05-25 13:05:16 -0400736 wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400737
Holger Schurig9012b282007-05-25 11:27:16 -0400738done:
739 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200740 return ret;
741}
742
743/**
744 * @brief Internal function used to start a scan based on an input config
745 *
746 * Use the input user scan configuration information when provided in
747 * order to send the appropriate scan commands to firmware to populate or
748 * update the internal driver scan table
749 *
750 * @param priv A pointer to wlan_private structure
751 * @param puserscanin Pointer to the input configuration for the requested
752 * scan.
753 *
754 * @return 0 or < 0 if error
755 */
756int wlan_scan_networks(wlan_private * priv,
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400757 const struct wlan_ioctl_user_scan_cfg * puserscanin,
758 int full_scan)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200759{
760 wlan_adapter *adapter = priv->adapter;
761 struct mrvlietypes_chanlistparamset *pchantlvout;
762 struct chanscanparamset * scan_chan_list = NULL;
763 struct wlan_scan_cmd_config * scan_cfg = NULL;
764 u8 keeppreviousscan;
765 u8 filteredscan;
766 u8 scancurrentchanonly;
767 int maxchanperscan;
768 int ret;
769
Holger Schurig9012b282007-05-25 11:27:16 -0400770 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200771
772 scan_chan_list = kzalloc(sizeof(struct chanscanparamset) *
773 WLAN_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL);
774 if (scan_chan_list == NULL) {
775 ret = -ENOMEM;
776 goto out;
777 }
778
779 scan_cfg = wlan_scan_setup_scan_config(priv,
780 puserscanin,
781 &pchantlvout,
782 scan_chan_list,
783 &maxchanperscan,
784 &filteredscan,
785 &scancurrentchanonly);
786 if (scan_cfg == NULL) {
787 ret = -ENOMEM;
788 goto out;
789 }
790
791 keeppreviousscan = 0;
792
793 if (puserscanin) {
794 keeppreviousscan = puserscanin->keeppreviousscan;
795 }
796
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400797 if (adapter->last_scanned_channel)
798 keeppreviousscan = 1;
799
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200800 if (!keeppreviousscan) {
801 memset(adapter->scantable, 0x00,
802 sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST);
803 adapter->numinscantable = 0;
804 }
805
806 /* Keep the data path active if we are only scanning our current channel */
807 if (!scancurrentchanonly) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400808 netif_stop_queue(priv->dev);
809 netif_carrier_off(priv->dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400810 netif_stop_queue(priv->mesh_dev);
811 netif_carrier_off(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200812 }
813
814 ret = wlan_scan_channel_list(priv,
815 maxchanperscan,
816 filteredscan,
817 scan_cfg,
818 pchantlvout,
Marcelo Tosatti064827e2007-05-24 23:37:28 -0400819 scan_chan_list,
Marcelo Tosatti2be92192007-05-25 00:33:28 -0400820 puserscanin,
821 full_scan);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200822
823 /* Process the resulting scan table:
824 * - Remove any bad ssids
825 * - Update our current BSS information from scan data
826 */
827 wlan_scan_process_results(priv);
828
829 if (priv->adapter->connect_status == libertas_connected) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400830 netif_carrier_on(priv->dev);
831 netif_wake_queue(priv->dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400832 netif_carrier_on(priv->mesh_dev);
833 netif_wake_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200834 }
835
836out:
837 if (scan_cfg)
838 kfree(scan_cfg);
839
840 if (scan_chan_list)
841 kfree(scan_chan_list);
842
Holger Schurig9012b282007-05-25 11:27:16 -0400843 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200844 return ret;
845}
846
847/**
848 * @brief Inspect the scan response buffer for pointers to expected TLVs
849 *
850 * TLVs can be included at the end of the scan response BSS information.
851 * Parse the data in the buffer for pointers to TLVs that can potentially
852 * be passed back in the response
853 *
854 * @param ptlv Pointer to the start of the TLV buffer to parse
855 * @param tlvbufsize size of the TLV buffer
856 * @param ptsftlv Output parameter: Pointer to the TSF TLV if found
857 *
858 * @return void
859 */
860static
861void wlan_ret_802_11_scan_get_tlv_ptrs(struct mrvlietypes_data * ptlv,
862 int tlvbufsize,
863 struct mrvlietypes_tsftimestamp ** ptsftlv)
864{
865 struct mrvlietypes_data *pcurrenttlv;
866 int tlvbufleft;
867 u16 tlvtype;
868 u16 tlvlen;
869
870 pcurrenttlv = ptlv;
871 tlvbufleft = tlvbufsize;
872 *ptsftlv = NULL;
873
Holger Schurig9012b282007-05-25 11:27:16 -0400874 lbs_deb_scan("SCAN_RESP: tlvbufsize = %d\n", tlvbufsize);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200875 lbs_dbg_hex("SCAN_RESP: TLV Buf", (u8 *) ptlv, tlvbufsize);
876
877 while (tlvbufleft >= sizeof(struct mrvlietypesheader)) {
878 tlvtype = le16_to_cpu(pcurrenttlv->header.type);
879 tlvlen = le16_to_cpu(pcurrenttlv->header.len);
880
881 switch (tlvtype) {
882 case TLV_TYPE_TSFTIMESTAMP:
883 *ptsftlv = (struct mrvlietypes_tsftimestamp *) pcurrenttlv;
884 break;
885
886 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400887 lbs_deb_scan("SCAN_RESP: Unhandled TLV = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200888 tlvtype);
889 /* Give up, this seems corrupted */
890 return;
891 } /* switch */
892
893 tlvbufleft -= (sizeof(ptlv->header) + tlvlen);
894 pcurrenttlv =
895 (struct mrvlietypes_data *) (pcurrenttlv->Data + tlvlen);
896 } /* while */
897}
898
899/**
900 * @brief Interpret a BSS scan response returned from the firmware
901 *
902 * Parse the various fixed fields and IEs passed back for a a BSS probe
903 * response or beacon from the scan command. Record information as needed
904 * in the scan table struct bss_descriptor for that entry.
905 *
906 * @param pBSSIDEntry Output parameter: Pointer to the BSS Entry
907 *
908 * @return 0 or -1
909 */
910static int InterpretBSSDescriptionWithIE(struct bss_descriptor * pBSSEntry,
911 u8 ** pbeaconinfo, int *bytesleft)
912{
913 enum ieeetypes_elementid elemID;
914 struct ieeetypes_fhparamset *pFH;
915 struct ieeetypes_dsparamset *pDS;
916 struct ieeetypes_cfparamset *pCF;
917 struct ieeetypes_ibssparamset *pibss;
918 struct ieeetypes_capinfo *pcap;
919 struct WLAN_802_11_FIXED_IEs fixedie;
920 u8 *pcurrentptr;
921 u8 *pRate;
922 u8 elemlen;
923 u8 bytestocopy;
924 u8 ratesize;
925 u16 beaconsize;
926 u8 founddatarateie;
927 int bytesleftforcurrentbeacon;
Holger Schurig9012b282007-05-25 11:27:16 -0400928 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200929
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200930 struct IE_WPA *pIe;
931 const u8 oui01[4] = { 0x00, 0x50, 0xf2, 0x01 };
932
933 struct ieeetypes_countryinfoset *pcountryinfo;
934
Holger Schurig9012b282007-05-25 11:27:16 -0400935 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200936
937 founddatarateie = 0;
938 ratesize = 0;
939 beaconsize = 0;
940
941 if (*bytesleft >= sizeof(beaconsize)) {
942 /* Extract & convert beacon size from the command buffer */
943 memcpy(&beaconsize, *pbeaconinfo, sizeof(beaconsize));
944 beaconsize = le16_to_cpu(beaconsize);
945 *bytesleft -= sizeof(beaconsize);
946 *pbeaconinfo += sizeof(beaconsize);
947 }
948
949 if (beaconsize == 0 || beaconsize > *bytesleft) {
950
951 *pbeaconinfo += *bytesleft;
952 *bytesleft = 0;
953
954 return -1;
955 }
956
957 /* Initialize the current working beacon pointer for this BSS iteration */
958 pcurrentptr = *pbeaconinfo;
959
960 /* Advance the return beacon pointer past the current beacon */
961 *pbeaconinfo += beaconsize;
962 *bytesleft -= beaconsize;
963
964 bytesleftforcurrentbeacon = beaconsize;
965
Dan Williams4ace1132007-05-25 13:16:38 -0400966 memcpy(pBSSEntry->bssid, pcurrentptr, ETH_ALEN);
Holger Schurig9012b282007-05-25 11:27:16 -0400967 lbs_deb_scan("InterpretIE: AP MAC Addr-%x:%x:%x:%x:%x:%x\n",
Dan Williams4ace1132007-05-25 13:16:38 -0400968 pBSSEntry->bssid[0], pBSSEntry->bssid[1],
969 pBSSEntry->bssid[2], pBSSEntry->bssid[3],
970 pBSSEntry->bssid[4], pBSSEntry->bssid[5]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200971
972 pcurrentptr += ETH_ALEN;
973 bytesleftforcurrentbeacon -= ETH_ALEN;
974
975 if (bytesleftforcurrentbeacon < 12) {
Holger Schurig9012b282007-05-25 11:27:16 -0400976 lbs_deb_scan("InterpretIE: Not enough bytes left\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200977 return -1;
978 }
979
980 /*
981 * next 4 fields are RSSI, time stamp, beacon interval,
982 * and capability information
983 */
984
985 /* RSSI is 1 byte long */
986 pBSSEntry->rssi = le32_to_cpu((long)(*pcurrentptr));
Holger Schurig9012b282007-05-25 11:27:16 -0400987 lbs_deb_scan("InterpretIE: RSSI=%02X\n", *pcurrentptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200988 pcurrentptr += 1;
989 bytesleftforcurrentbeacon -= 1;
990
991 /* time stamp is 8 bytes long */
992 memcpy(fixedie.timestamp, pcurrentptr, 8);
993 memcpy(pBSSEntry->timestamp, pcurrentptr, 8);
994 pcurrentptr += 8;
995 bytesleftforcurrentbeacon -= 8;
996
997 /* beacon interval is 2 bytes long */
998 memcpy(&fixedie.beaconinterval, pcurrentptr, 2);
999 pBSSEntry->beaconperiod = le16_to_cpu(fixedie.beaconinterval);
1000 pcurrentptr += 2;
1001 bytesleftforcurrentbeacon -= 2;
1002
1003 /* capability information is 2 bytes long */
1004 memcpy(&fixedie.capabilities, pcurrentptr, 2);
Holger Schurig9012b282007-05-25 11:27:16 -04001005 lbs_deb_scan("InterpretIE: fixedie.capabilities=0x%X\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001006 fixedie.capabilities);
1007 fixedie.capabilities = le16_to_cpu(fixedie.capabilities);
1008 pcap = (struct ieeetypes_capinfo *) & fixedie.capabilities;
1009 memcpy(&pBSSEntry->cap, pcap, sizeof(struct ieeetypes_capinfo));
1010 pcurrentptr += 2;
1011 bytesleftforcurrentbeacon -= 2;
1012
1013 /* rest of the current buffer are IE's */
Holger Schurig9012b282007-05-25 11:27:16 -04001014 lbs_deb_scan("InterpretIE: IElength for this AP = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001015 bytesleftforcurrentbeacon);
1016
1017 lbs_dbg_hex("InterpretIE: IE info", (u8 *) pcurrentptr,
1018 bytesleftforcurrentbeacon);
1019
1020 if (pcap->privacy) {
Holger Schurig9012b282007-05-25 11:27:16 -04001021 lbs_deb_scan("InterpretIE: AP WEP enabled\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022 pBSSEntry->privacy = wlan802_11privfilter8021xWEP;
1023 } else {
1024 pBSSEntry->privacy = wlan802_11privfilteracceptall;
1025 }
1026
1027 if (pcap->ibss == 1) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001028 pBSSEntry->mode = IW_MODE_ADHOC;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029 } else {
Dan Williams0dc5a292007-05-10 22:58:02 -04001030 pBSSEntry->mode = IW_MODE_INFRA;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001031 }
1032
1033 /* process variable IE */
1034 while (bytesleftforcurrentbeacon >= 2) {
1035 elemID = (enum ieeetypes_elementid) (*((u8 *) pcurrentptr));
1036 elemlen = *((u8 *) pcurrentptr + 1);
1037
1038 if (bytesleftforcurrentbeacon < elemlen) {
Holger Schurig9012b282007-05-25 11:27:16 -04001039 lbs_deb_scan("InterpretIE: error in processing IE, "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001040 "bytes left < IE length\n");
1041 bytesleftforcurrentbeacon = 0;
1042 continue;
1043 }
1044
1045 switch (elemID) {
1046
1047 case SSID:
1048 pBSSEntry->ssid.ssidlength = elemlen;
1049 memcpy(pBSSEntry->ssid.ssid, (pcurrentptr + 2),
1050 elemlen);
Holger Schurig6df30732007-05-25 11:56:37 -04001051 lbs_deb_scan("ssid '%s'\n", pBSSEntry->ssid.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001052 break;
1053
1054 case SUPPORTED_RATES:
1055 memcpy(pBSSEntry->datarates, (pcurrentptr + 2),
1056 elemlen);
1057 memmove(pBSSEntry->libertas_supported_rates, (pcurrentptr + 2),
1058 elemlen);
1059 ratesize = elemlen;
1060 founddatarateie = 1;
1061 break;
1062
1063 case EXTRA_IE:
Holger Schurig9012b282007-05-25 11:27:16 -04001064 lbs_deb_scan("InterpretIE: EXTRA_IE Found!\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001065 pBSSEntry->extra_ie = 1;
1066 break;
1067
1068 case FH_PARAM_SET:
1069 pFH = (struct ieeetypes_fhparamset *) pcurrentptr;
1070 memmove(&pBSSEntry->phyparamset.fhparamset, pFH,
1071 sizeof(struct ieeetypes_fhparamset));
1072 pBSSEntry->phyparamset.fhparamset.dwelltime
1073 =
1074 le16_to_cpu(pBSSEntry->phyparamset.fhparamset.
1075 dwelltime);
1076 break;
1077
1078 case DS_PARAM_SET:
1079 pDS = (struct ieeetypes_dsparamset *) pcurrentptr;
1080
1081 pBSSEntry->channel = pDS->currentchan;
1082
1083 memcpy(&pBSSEntry->phyparamset.dsparamset, pDS,
1084 sizeof(struct ieeetypes_dsparamset));
1085 break;
1086
1087 case CF_PARAM_SET:
1088 pCF = (struct ieeetypes_cfparamset *) pcurrentptr;
1089
1090 memcpy(&pBSSEntry->ssparamset.cfparamset, pCF,
1091 sizeof(struct ieeetypes_cfparamset));
1092 break;
1093
1094 case IBSS_PARAM_SET:
1095 pibss = (struct ieeetypes_ibssparamset *) pcurrentptr;
1096 pBSSEntry->atimwindow =
1097 le32_to_cpu(pibss->atimwindow);
1098
1099 memmove(&pBSSEntry->ssparamset.ibssparamset, pibss,
1100 sizeof(struct ieeetypes_ibssparamset));
1101
1102 pBSSEntry->ssparamset.ibssparamset.atimwindow
1103 =
1104 le16_to_cpu(pBSSEntry->ssparamset.ibssparamset.
1105 atimwindow);
1106 break;
1107
1108 /* Handle Country Info IE */
1109 case COUNTRY_INFO:
1110 pcountryinfo =
1111 (struct ieeetypes_countryinfoset *) pcurrentptr;
1112
1113 if (pcountryinfo->len <
1114 sizeof(pcountryinfo->countrycode)
1115 || pcountryinfo->len > 254) {
Holger Schurig9012b282007-05-25 11:27:16 -04001116 lbs_deb_scan("InterpretIE: 11D- Err "
Dan Williams4269e2a2007-05-10 23:10:18 -04001117 "CountryInfo len =%d min=%zd max=254\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001118 pcountryinfo->len,
1119 sizeof(pcountryinfo->countrycode));
Holger Schurig9012b282007-05-25 11:27:16 -04001120 ret = -1;
1121 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001122 }
1123
1124 memcpy(&pBSSEntry->countryinfo,
1125 pcountryinfo, pcountryinfo->len + 2);
1126 lbs_dbg_hex("InterpretIE: 11D- CountryInfo:",
1127 (u8 *) pcountryinfo,
1128 (u32) (pcountryinfo->len + 2));
1129 break;
1130
1131 case EXTENDED_SUPPORTED_RATES:
1132 /*
1133 * only process extended supported rate
1134 * if data rate is already found.
1135 * data rate IE should come before
1136 * extended supported rate IE
1137 */
1138 if (founddatarateie) {
1139 if ((elemlen + ratesize) > WLAN_SUPPORTED_RATES) {
1140 bytestocopy =
1141 (WLAN_SUPPORTED_RATES - ratesize);
1142 } else {
1143 bytestocopy = elemlen;
1144 }
1145
1146 pRate = (u8 *) pBSSEntry->datarates;
1147 pRate += ratesize;
1148 memmove(pRate, (pcurrentptr + 2), bytestocopy);
1149
1150 pRate = (u8 *) pBSSEntry->libertas_supported_rates;
1151
1152 pRate += ratesize;
1153 memmove(pRate, (pcurrentptr + 2), bytestocopy);
1154 }
1155 break;
1156
1157 case VENDOR_SPECIFIC_221:
1158#define IE_ID_LEN_FIELDS_BYTES 2
1159 pIe = (struct IE_WPA *)pcurrentptr;
1160
Dan Williams51b0c9d2007-05-10 22:51:28 -04001161 if (memcmp(pIe->oui, oui01, sizeof(oui01)))
1162 break;
1163
1164 pBSSEntry->wpa_ie_len = min_t(size_t,
1165 elemlen + IE_ID_LEN_FIELDS_BYTES,
1166 sizeof(pBSSEntry->wpa_ie));
1167 memcpy(pBSSEntry->wpa_ie, pcurrentptr,
1168 pBSSEntry->wpa_ie_len);
1169 lbs_dbg_hex("InterpretIE: Resp WPA_IE",
1170 pBSSEntry->wpa_ie, elemlen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001171 break;
1172 case WPA2_IE:
1173 pIe = (struct IE_WPA *)pcurrentptr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001174
Dan Williams51b0c9d2007-05-10 22:51:28 -04001175 pBSSEntry->rsn_ie_len = min_t(size_t,
1176 elemlen + IE_ID_LEN_FIELDS_BYTES,
1177 sizeof(pBSSEntry->rsn_ie));
1178 memcpy(pBSSEntry->rsn_ie, pcurrentptr,
1179 pBSSEntry->rsn_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001180 lbs_dbg_hex("InterpretIE: Resp WPA2_IE",
Dan Williams51b0c9d2007-05-10 22:51:28 -04001181 pBSSEntry->rsn_ie, elemlen);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001182 break;
1183 case TIM:
1184 break;
1185
1186 case CHALLENGE_TEXT:
1187 break;
1188 }
1189
1190 pcurrentptr += elemlen + 2;
1191
1192 /* need to account for IE ID and IE len */
1193 bytesleftforcurrentbeacon -= (elemlen + 2);
1194
1195 } /* while (bytesleftforcurrentbeacon > 2) */
Holger Schurig9012b282007-05-25 11:27:16 -04001196 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001197
Holger Schurig9012b282007-05-25 11:27:16 -04001198done:
1199 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
1200 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001201}
1202
1203/**
1204 * @brief Compare two SSIDs
1205 *
1206 * @param ssid1 A pointer to ssid to compare
1207 * @param ssid2 A pointer to ssid to compare
1208 *
1209 * @return 0--ssid is same, otherwise is different
1210 */
1211int libertas_SSID_cmp(struct WLAN_802_11_SSID *ssid1, struct WLAN_802_11_SSID *ssid2)
1212{
1213 if (!ssid1 || !ssid2)
1214 return -1;
1215
1216 if (ssid1->ssidlength != ssid2->ssidlength)
1217 return -1;
1218
1219 return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssidlength);
1220}
1221
1222/**
1223 * @brief This function finds a specific compatible BSSID in the scan list
1224 *
1225 * @param adapter A pointer to wlan_adapter
1226 * @param bssid BSSID to find in the scan list
1227 * @param mode Network mode: Infrastructure or IBSS
1228 *
1229 * @return index in BSSID list, or error return code (< 0)
1230 */
Dan Williams0dc5a292007-05-10 22:58:02 -04001231int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, u8 mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001232{
1233 int ret = -ENETUNREACH;
1234 int i;
1235
1236 if (!bssid)
1237 return -EFAULT;
1238
Holger Schurig9012b282007-05-25 11:27:16 -04001239 lbs_deb_scan("FindBSSID: Num of BSSIDs = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001240 adapter->numinscantable);
1241
1242 /* Look through the scan table for a compatible match. The ret return
1243 * variable will be equal to the index in the scan table (greater
1244 * than zero) if the network is compatible. The loop will continue
1245 * past a matched bssid that is not compatible in case there is an
1246 * AP with multiple SSIDs assigned to the same BSSID
1247 */
1248 for (i = 0; ret < 0 && i < adapter->numinscantable; i++) {
Dan Williams4ace1132007-05-25 13:16:38 -04001249 if (!memcmp(adapter->scantable[i].bssid, bssid, ETH_ALEN)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001250 switch (mode) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001251 case IW_MODE_INFRA:
1252 case IW_MODE_ADHOC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001253 ret = is_network_compatible(adapter, i, mode);
1254 break;
1255 default:
1256 ret = i;
1257 break;
1258 }
1259 }
1260 }
1261
1262 return ret;
1263}
1264
1265/**
1266 * @brief This function finds ssid in ssid list.
1267 *
1268 * @param adapter A pointer to wlan_adapter
1269 * @param ssid SSID to find in the list
1270 * @param bssid BSSID to qualify the SSID selection (if provided)
1271 * @param mode Network mode: Infrastructure or IBSS
1272 *
1273 * @return index in BSSID list
1274 */
1275int libertas_find_SSID_in_list(wlan_adapter * adapter,
Dan Williams0dc5a292007-05-10 22:58:02 -04001276 struct WLAN_802_11_SSID *ssid, u8 * bssid, u8 mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001277{
1278 int net = -ENETUNREACH;
1279 u8 bestrssi = 0;
1280 int i;
1281 int j;
1282
Holger Schurig9012b282007-05-25 11:27:16 -04001283 lbs_deb_scan("Num of Entries in Table = %d\n", adapter->numinscantable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001284
1285 for (i = 0; i < adapter->numinscantable; i++) {
1286 if (!libertas_SSID_cmp(&adapter->scantable[i].ssid, ssid) &&
1287 (!bssid ||
Dan Williams4ace1132007-05-25 13:16:38 -04001288 !memcmp(adapter->scantable[i].bssid, bssid, ETH_ALEN))) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001289 switch (mode) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001290 case IW_MODE_INFRA:
1291 case IW_MODE_ADHOC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001292 j = is_network_compatible(adapter, i, mode);
1293
1294 if (j >= 0) {
1295 if (bssid) {
1296 return i;
1297 }
1298
1299 if (SCAN_RSSI
1300 (adapter->scantable[i].rssi)
1301 > bestrssi) {
1302 bestrssi =
1303 SCAN_RSSI(adapter->
1304 scantable[i].
1305 rssi);
1306 net = i;
1307 }
1308 } else {
1309 if (net == -ENETUNREACH) {
1310 net = j;
1311 }
1312 }
1313 break;
Dan Williams0dc5a292007-05-10 22:58:02 -04001314 case IW_MODE_AUTO:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001315 default:
1316 if (SCAN_RSSI(adapter->scantable[i].rssi)
1317 > bestrssi) {
1318 bestrssi =
1319 SCAN_RSSI(adapter->scantable[i].
1320 rssi);
1321 net = i;
1322 }
1323 break;
1324 }
1325 }
1326 }
1327
1328 return net;
1329}
1330
1331/**
1332 * @brief This function finds the best SSID in the Scan List
1333 *
1334 * Search the scan table for the best SSID that also matches the current
1335 * adapter network preference (infrastructure or adhoc)
1336 *
1337 * @param adapter A pointer to wlan_adapter
1338 *
1339 * @return index in BSSID list
1340 */
Dan Williams0dc5a292007-05-10 22:58:02 -04001341int libertas_find_best_SSID_in_list(wlan_adapter * adapter, u8 mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001342{
1343 int bestnet = -ENETUNREACH;
1344 u8 bestrssi = 0;
1345 int i;
1346
Holger Schurig9012b282007-05-25 11:27:16 -04001347 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001348
Holger Schurig9012b282007-05-25 11:27:16 -04001349 lbs_deb_scan("Num of BSSIDs = %d\n", adapter->numinscantable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001350
1351 for (i = 0; i < adapter->numinscantable; i++) {
1352 switch (mode) {
Dan Williams0dc5a292007-05-10 22:58:02 -04001353 case IW_MODE_INFRA:
1354 case IW_MODE_ADHOC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001355 if (is_network_compatible(adapter, i, mode) >= 0) {
1356 if (SCAN_RSSI(adapter->scantable[i].rssi) >
1357 bestrssi) {
1358 bestrssi =
1359 SCAN_RSSI(adapter->scantable[i].
1360 rssi);
1361 bestnet = i;
1362 }
1363 }
1364 break;
Dan Williams0dc5a292007-05-10 22:58:02 -04001365 case IW_MODE_AUTO:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001366 default:
1367 if (SCAN_RSSI(adapter->scantable[i].rssi) > bestrssi) {
1368 bestrssi =
1369 SCAN_RSSI(adapter->scantable[i].rssi);
1370 bestnet = i;
1371 }
1372 break;
1373 }
1374 }
1375
Holger Schurig9012b282007-05-25 11:27:16 -04001376 lbs_deb_leave_args(LBS_DEB_SCAN, "bestnet %d", bestnet);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001377 return bestnet;
1378}
1379
1380/**
1381 * @brief Find the AP with specific ssid in the scan list
1382 *
1383 * @param priv A pointer to wlan_private structure
1384 * @param pSSID A pointer to AP's ssid
1385 *
1386 * @return 0--success, otherwise--fail
1387 */
1388int libertas_find_best_network_SSID(wlan_private * priv,
1389 struct WLAN_802_11_SSID *pSSID,
Dan Williams0dc5a292007-05-10 22:58:02 -04001390 u8 preferred_mode, u8 *out_mode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001391{
1392 wlan_adapter *adapter = priv->adapter;
1393 int ret = 0;
1394 struct bss_descriptor *preqbssid;
1395 int i;
1396
Holger Schurig9012b282007-05-25 11:27:16 -04001397 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001398
1399 memset(pSSID, 0, sizeof(struct WLAN_802_11_SSID));
1400
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001401 wlan_scan_networks(priv, NULL, 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001402 if (adapter->surpriseremoved)
1403 return -1;
1404 wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
1405
1406 i = libertas_find_best_SSID_in_list(adapter, preferred_mode);
1407 if (i < 0) {
1408 ret = -1;
1409 goto out;
1410 }
1411
1412 preqbssid = &adapter->scantable[i];
1413 memcpy(pSSID, &preqbssid->ssid,
1414 sizeof(struct WLAN_802_11_SSID));
Dan Williams0dc5a292007-05-10 22:58:02 -04001415 *out_mode = preqbssid->mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001416
1417 if (!pSSID->ssidlength) {
1418 ret = -1;
1419 }
1420
1421out:
Holger Schurig9012b282007-05-25 11:27:16 -04001422 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001423 return ret;
1424}
1425
1426/**
1427 * @brief Scan Network
1428 *
1429 * @param dev A pointer to net_device structure
1430 * @param info A pointer to iw_request_info structure
1431 * @param vwrq A pointer to iw_param structure
1432 * @param extra A pointer to extra data buf
1433 *
1434 * @return 0 --success, otherwise fail
1435 */
1436int libertas_set_scan(struct net_device *dev, struct iw_request_info *info,
1437 struct iw_param *vwrq, char *extra)
1438{
1439 wlan_private *priv = dev->priv;
1440 wlan_adapter *adapter = priv->adapter;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001441
Holger Schurig9012b282007-05-25 11:27:16 -04001442 lbs_deb_enter(LBS_DEB_SCAN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001443
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001444 wlan_scan_networks(priv, NULL, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001445
1446 if (adapter->surpriseremoved)
1447 return -1;
1448
Holger Schurig9012b282007-05-25 11:27:16 -04001449 lbs_deb_leave(LBS_DEB_SCAN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001450 return 0;
1451}
1452
1453/**
1454 * @brief Send a scan command for all available channels filtered on a spec
1455 *
1456 * @param priv A pointer to wlan_private structure
1457 * @param prequestedssid A pointer to AP's ssid
1458 * @param keeppreviousscan Flag used to save/clear scan table before scan
1459 *
1460 * @return 0-success, otherwise fail
1461 */
1462int libertas_send_specific_SSID_scan(wlan_private * priv,
1463 struct WLAN_802_11_SSID *prequestedssid,
1464 u8 keeppreviousscan)
1465{
1466 wlan_adapter *adapter = priv->adapter;
1467 struct wlan_ioctl_user_scan_cfg scancfg;
1468
Holger Schurig9012b282007-05-25 11:27:16 -04001469 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001470
1471 if (prequestedssid == NULL) {
1472 return -1;
1473 }
1474
1475 memset(&scancfg, 0x00, sizeof(scancfg));
1476
1477 memcpy(scancfg.specificSSID, prequestedssid->ssid,
1478 prequestedssid->ssidlength);
1479 scancfg.keeppreviousscan = keeppreviousscan;
1480
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001481 wlan_scan_networks(priv, &scancfg, 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001482 if (adapter->surpriseremoved)
1483 return -1;
1484 wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
1485
Holger Schurig9012b282007-05-25 11:27:16 -04001486 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487 return 0;
1488}
1489
1490/**
1491 * @brief scan an AP with specific BSSID
1492 *
1493 * @param priv A pointer to wlan_private structure
1494 * @param bssid A pointer to AP's bssid
1495 * @param keeppreviousscan Flag used to save/clear scan table before scan
1496 *
1497 * @return 0-success, otherwise fail
1498 */
1499int libertas_send_specific_BSSID_scan(wlan_private * priv, u8 * bssid, u8 keeppreviousscan)
1500{
1501 struct wlan_ioctl_user_scan_cfg scancfg;
1502
Holger Schurig9012b282007-05-25 11:27:16 -04001503 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001504
1505 if (bssid == NULL) {
1506 return -1;
1507 }
1508
1509 memset(&scancfg, 0x00, sizeof(scancfg));
1510 memcpy(scancfg.specificBSSID, bssid, sizeof(scancfg.specificBSSID));
1511 scancfg.keeppreviousscan = keeppreviousscan;
1512
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001513 wlan_scan_networks(priv, &scancfg, 1);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001514 if (priv->adapter->surpriseremoved)
1515 return -1;
1516 wait_event_interruptible(priv->adapter->cmd_pending,
1517 !priv->adapter->nr_cmd_pending);
1518
Holger Schurig9012b282007-05-25 11:27:16 -04001519 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001520 return 0;
1521}
1522
1523/**
1524 * @brief Retrieve the scan table entries via wireless tools IOCTL call
1525 *
1526 * @param dev A pointer to net_device structure
1527 * @param info A pointer to iw_request_info structure
1528 * @param dwrq A pointer to iw_point structure
1529 * @param extra A pointer to extra data buf
1530 *
1531 * @return 0 --success, otherwise fail
1532 */
1533int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
1534 struct iw_point *dwrq, char *extra)
1535{
1536 wlan_private *priv = dev->priv;
1537 wlan_adapter *adapter = priv->adapter;
1538 int ret = 0;
1539 char *current_ev = extra;
1540 char *end_buf = extra + IW_SCAN_MAX_DATA;
1541 struct chan_freq_power *cfp;
1542 struct bss_descriptor *pscantable;
1543 char *current_val; /* For rates */
1544 struct iw_event iwe; /* Temporary buffer */
1545 int i;
1546 int j;
1547 int rate;
1548#define PERFECT_RSSI ((u8)50)
1549#define WORST_RSSI ((u8)0)
1550#define RSSI_DIFF ((u8)(PERFECT_RSSI - WORST_RSSI))
1551 u8 rssi;
1552
1553 u8 buf[16 + 256 * 2];
1554 u8 *ptr;
1555
Holger Schurig9012b282007-05-25 11:27:16 -04001556 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001557
1558 /*
1559 * if there's either commands in the queue or one being
1560 * processed return -EAGAIN for iwlist to retry later.
1561 */
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001562 if (adapter->nr_cmd_pending)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001563 return -EAGAIN;
1564
Marcelo Tosatti2be92192007-05-25 00:33:28 -04001565 if (adapter->last_scanned_channel) {
1566 wlan_scan_networks(priv, NULL, 0);
1567 return -EAGAIN;
1568 }
1569
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001570 if (adapter->connect_status == libertas_connected)
Holger Schurig6df30732007-05-25 11:56:37 -04001571 lbs_deb_scan("current ssid '%s'\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001572 adapter->curbssparams.ssid.ssid);
1573
Holger Schurig9012b282007-05-25 11:27:16 -04001574 lbs_deb_scan("Scan: Get: numinscantable = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001575 adapter->numinscantable);
1576
1577 /* The old API using SIOCGIWAPLIST had a hard limit of IW_MAX_AP.
1578 * The new API using SIOCGIWSCAN is only limited by buffer size
1579 * WE-14 -> WE-16 the buffer is limited to IW_SCAN_MAX_DATA bytes
1580 * which is 4096.
1581 */
1582 for (i = 0; i < adapter->numinscantable; i++) {
1583 if ((current_ev + MAX_SCAN_CELL_SIZE) >= end_buf) {
Holger Schurig9012b282007-05-25 11:27:16 -04001584 lbs_deb_scan("i=%d break out: current_ev=%p end_buf=%p "
Dan Williams4269e2a2007-05-10 23:10:18 -04001585 "MAX_SCAN_CELL_SIZE=%zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001586 i, current_ev, end_buf, MAX_SCAN_CELL_SIZE);
1587 break;
1588 }
1589
1590 pscantable = &adapter->scantable[i];
1591
Holger Schurig6df30732007-05-25 11:56:37 -04001592 lbs_deb_scan("i %d, ssid '%s'\n", i, pscantable->ssid.ssid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001593
1594 cfp =
1595 libertas_find_cfp_by_band_and_channel(adapter, 0,
1596 pscantable->channel);
1597 if (!cfp) {
Holger Schurig9012b282007-05-25 11:27:16 -04001598 lbs_deb_scan("Invalid channel number %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001599 pscantable->channel);
1600 continue;
1601 }
1602
1603 if (!ssid_valid(&adapter->scantable[i].ssid)) {
1604 continue;
1605 }
1606
1607 /* First entry *MUST* be the AP MAC address */
1608 iwe.cmd = SIOCGIWAP;
1609 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1610 memcpy(iwe.u.ap_addr.sa_data,
Dan Williams4ace1132007-05-25 13:16:38 -04001611 &adapter->scantable[i].bssid, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001612
1613 iwe.len = IW_EV_ADDR_LEN;
1614 current_ev =
1615 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
1616
1617 //Add the ESSID
1618 iwe.u.data.length = adapter->scantable[i].ssid.ssidlength;
1619
1620 if (iwe.u.data.length > 32) {
1621 iwe.u.data.length = 32;
1622 }
1623
1624 iwe.cmd = SIOCGIWESSID;
1625 iwe.u.data.flags = 1;
1626 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1627 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1628 adapter->scantable[i].ssid.
1629 ssid);
1630
1631 //Add mode
1632 iwe.cmd = SIOCGIWMODE;
Dan Williams0dc5a292007-05-10 22:58:02 -04001633 iwe.u.mode = adapter->scantable[i].mode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001634 iwe.len = IW_EV_UINT_LEN;
1635 current_ev =
1636 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
1637
1638 //frequency
1639 iwe.cmd = SIOCGIWFREQ;
1640 iwe.u.freq.m = (long)cfp->freq * 100000;
1641 iwe.u.freq.e = 1;
1642 iwe.len = IW_EV_FREQ_LEN;
1643 current_ev =
1644 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
1645
1646 /* Add quality statistics */
1647 iwe.cmd = IWEVQUAL;
1648 iwe.u.qual.updated = IW_QUAL_ALL_UPDATED;
1649 iwe.u.qual.level = SCAN_RSSI(adapter->scantable[i].rssi);
1650
1651 rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
1652 iwe.u.qual.qual =
1653 (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) *
1654 (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) /
1655 (RSSI_DIFF * RSSI_DIFF);
1656 if (iwe.u.qual.qual > 100)
1657 iwe.u.qual.qual = 100;
1658 else if (iwe.u.qual.qual < 1)
1659 iwe.u.qual.qual = 0;
1660
1661 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
1662 iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
1663 } else {
1664 iwe.u.qual.noise =
1665 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1666 }
Dan Williams0dc5a292007-05-10 22:58:02 -04001667 if ((adapter->mode == IW_MODE_ADHOC) &&
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001668 !libertas_SSID_cmp(&adapter->curbssparams.ssid,
1669 &adapter->scantable[i].ssid)
1670 && adapter->adhoccreate) {
1671 ret = libertas_prepare_and_send_command(priv,
1672 cmd_802_11_rssi,
1673 0,
1674 cmd_option_waitforrsp,
1675 0, NULL);
1676
1677 if (!ret) {
1678 iwe.u.qual.level =
1679 CAL_RSSI(adapter->SNR[TYPE_RXPD][TYPE_AVG] /
1680 AVG_SCALE,
1681 adapter->NF[TYPE_RXPD][TYPE_AVG] /
1682 AVG_SCALE);
1683 }
1684 }
1685 iwe.len = IW_EV_QUAL_LEN;
1686 current_ev =
1687 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
1688
1689 /* Add encryption capability */
1690 iwe.cmd = SIOCGIWENCODE;
1691 if (adapter->scantable[i].privacy) {
1692 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1693 } else {
1694 iwe.u.data.flags = IW_ENCODE_DISABLED;
1695 }
1696 iwe.u.data.length = 0;
1697 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1698 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1699 adapter->scantable->ssid.
1700 ssid);
1701
1702 current_val = current_ev + IW_EV_LCP_LEN;
1703
1704 iwe.cmd = SIOCGIWRATE;
1705
1706 iwe.u.bitrate.fixed = 0;
1707 iwe.u.bitrate.disabled = 0;
1708 iwe.u.bitrate.value = 0;
1709
1710 /* Bit rate given in 500 kb/s units (+ 0x80) */
1711 for (j = 0; j < sizeof(adapter->scantable[i].libertas_supported_rates);
1712 j++) {
1713 if (adapter->scantable[i].libertas_supported_rates[j] == 0) {
1714 break;
1715 }
1716 rate =
1717 (adapter->scantable[i].libertas_supported_rates[j] & 0x7F) *
1718 500000;
1719 if (rate > iwe.u.bitrate.value) {
1720 iwe.u.bitrate.value = rate;
1721 }
1722
1723 iwe.u.bitrate.value =
1724 (adapter->scantable[i].libertas_supported_rates[j]
1725 & 0x7f) * 500000;
1726 iwe.len = IW_EV_PARAM_LEN;
1727 current_ev =
1728 iwe_stream_add_value(current_ev, current_val,
1729 end_buf, &iwe, iwe.len);
1730
1731 }
Dan Williams0dc5a292007-05-10 22:58:02 -04001732 if ((adapter->scantable[i].mode == IW_MODE_ADHOC)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001733 && !libertas_SSID_cmp(&adapter->curbssparams.ssid,
1734 &adapter->scantable[i].ssid)
1735 && adapter->adhoccreate) {
1736 iwe.u.bitrate.value = 22 * 500000;
1737 }
1738 iwe.len = IW_EV_PARAM_LEN;
1739 current_ev =
1740 iwe_stream_add_value(current_ev, current_val, end_buf, &iwe,
1741 iwe.len);
1742
1743 /* Add new value to event */
1744 current_val = current_ev + IW_EV_LCP_LEN;
1745
Dan Williams51b0c9d2007-05-10 22:51:28 -04001746 if (adapter->scantable[i].rsn_ie[0] == WPA2_IE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001747 memset(&iwe, 0, sizeof(iwe));
1748 memset(buf, 0, sizeof(buf));
Dan Williams51b0c9d2007-05-10 22:51:28 -04001749 memcpy(buf, adapter->scantable[i].rsn_ie,
1750 adapter->scantable[i].rsn_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001751 iwe.cmd = IWEVGENIE;
Dan Williams51b0c9d2007-05-10 22:51:28 -04001752 iwe.u.data.length = adapter->scantable[i].rsn_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001753 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1754 current_ev = iwe_stream_add_point(current_ev, end_buf,
1755 &iwe, buf);
1756 }
Dan Williams51b0c9d2007-05-10 22:51:28 -04001757 if (adapter->scantable[i].wpa_ie[0] == WPA_IE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001758 memset(&iwe, 0, sizeof(iwe));
1759 memset(buf, 0, sizeof(buf));
Dan Williams51b0c9d2007-05-10 22:51:28 -04001760 memcpy(buf, adapter->scantable[i].wpa_ie,
1761 adapter->scantable[i].wpa_ie_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001762 iwe.cmd = IWEVGENIE;
Dan Williams51b0c9d2007-05-10 22:51:28 -04001763 iwe.u.data.length = adapter->scantable[i].wpa_ie_len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001764 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1765 current_ev = iwe_stream_add_point(current_ev, end_buf,
1766 &iwe, buf);
1767 }
1768
1769
1770 if (adapter->scantable[i].extra_ie != 0) {
1771 memset(&iwe, 0, sizeof(iwe));
1772 memset(buf, 0, sizeof(buf));
1773 ptr = buf;
1774 ptr += sprintf(ptr, "extra_ie");
1775 iwe.u.data.length = strlen(buf);
1776
Holger Schurig9012b282007-05-25 11:27:16 -04001777 lbs_deb_scan("iwe.u.data.length %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001778 iwe.u.data.length);
Holger Schurig9012b282007-05-25 11:27:16 -04001779 lbs_deb_scan("BUF: %s \n", buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001780
1781 iwe.cmd = IWEVCUSTOM;
1782 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1783 current_ev =
1784 iwe_stream_add_point(current_ev, end_buf, &iwe,
1785 buf);
1786 }
1787
1788 current_val = current_ev + IW_EV_LCP_LEN;
1789
1790 /*
1791 * Check if we added any event
1792 */
1793 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1794 current_ev = current_val;
1795 }
1796
1797 dwrq->length = (current_ev - extra);
1798 dwrq->flags = 0;
1799
Holger Schurig9012b282007-05-25 11:27:16 -04001800 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001801 return 0;
1802}
1803
1804/**
1805 * @brief Prepare a scan command to be sent to the firmware
1806 *
1807 * Use the wlan_scan_cmd_config sent to the command processing module in
1808 * the libertas_prepare_and_send_command to configure a cmd_ds_802_11_scan command
1809 * struct to send to firmware.
1810 *
1811 * The fixed fields specifying the BSS type and BSSID filters as well as a
1812 * variable number/length of TLVs are sent in the command to firmware.
1813 *
1814 * @param priv A pointer to wlan_private structure
1815 * @param cmd A pointer to cmd_ds_command structure to be sent to
1816 * firmware with the cmd_DS_801_11_SCAN structure
1817 * @param pdata_buf Void pointer cast of a wlan_scan_cmd_config struct used
1818 * to set the fields/TLVs for the command sent to firmware
1819 *
1820 * @return 0 or -1
1821 *
1822 * @sa wlan_scan_create_channel_list
1823 */
1824int libertas_cmd_80211_scan(wlan_private * priv,
1825 struct cmd_ds_command *cmd, void *pdata_buf)
1826{
1827 struct cmd_ds_802_11_scan *pscan = &cmd->params.scan;
1828 struct wlan_scan_cmd_config *pscancfg;
1829
Holger Schurig9012b282007-05-25 11:27:16 -04001830 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001831
1832 pscancfg = pdata_buf;
1833
1834 /* Set fixed field variables in scan command */
1835 pscan->bsstype = pscancfg->bsstype;
1836 memcpy(pscan->BSSID, pscancfg->specificBSSID, sizeof(pscan->BSSID));
1837 memcpy(pscan->tlvbuffer, pscancfg->tlvbuffer, pscancfg->tlvbufferlen);
1838
1839 cmd->command = cpu_to_le16(cmd_802_11_scan);
1840
1841 /* size is equal to the sizeof(fixed portions) + the TLV len + header */
1842 cmd->size = cpu_to_le16(sizeof(pscan->bsstype)
1843 + sizeof(pscan->BSSID)
1844 + pscancfg->tlvbufferlen + S_DS_GEN);
1845
Holger Schurig9012b282007-05-25 11:27:16 -04001846 lbs_deb_scan("SCAN_CMD: command=%x, size=%x, seqnum=%x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001847 cmd->command, cmd->size, cmd->seqnum);
Holger Schurig9012b282007-05-25 11:27:16 -04001848
1849 lbs_deb_leave(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001850 return 0;
1851}
1852
1853/**
1854 * @brief This function handles the command response of scan
1855 *
1856 * The response buffer for the scan command has the following
1857 * memory layout:
1858 *
1859 * .-----------------------------------------------------------.
1860 * | header (4 * sizeof(u16)): Standard command response hdr |
1861 * .-----------------------------------------------------------.
1862 * | bufsize (u16) : sizeof the BSS Description data |
1863 * .-----------------------------------------------------------.
1864 * | NumOfSet (u8) : Number of BSS Descs returned |
1865 * .-----------------------------------------------------------.
1866 * | BSSDescription data (variable, size given in bufsize) |
1867 * .-----------------------------------------------------------.
1868 * | TLV data (variable, size calculated using header->size, |
1869 * | bufsize and sizeof the fixed fields above) |
1870 * .-----------------------------------------------------------.
1871 *
1872 * @param priv A pointer to wlan_private structure
1873 * @param resp A pointer to cmd_ds_command
1874 *
1875 * @return 0 or -1
1876 */
1877int libertas_ret_80211_scan(wlan_private * priv, struct cmd_ds_command *resp)
1878{
1879 wlan_adapter *adapter = priv->adapter;
1880 struct cmd_ds_802_11_scan_rsp *pscan;
1881 struct bss_descriptor newbssentry;
1882 struct mrvlietypes_data *ptlv;
1883 struct mrvlietypes_tsftimestamp *ptsftlv;
1884 u8 *pbssinfo;
1885 u16 scanrespsize;
1886 int bytesleft;
1887 int numintable;
1888 int bssIdx;
1889 int idx;
1890 int tlvbufsize;
1891 u64 tsfval;
Holger Schurig9012b282007-05-25 11:27:16 -04001892 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001893
Holger Schurig9012b282007-05-25 11:27:16 -04001894 lbs_deb_enter(LBS_DEB_ASSOC);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001895
1896 pscan = &resp->params.scanresp;
1897
1898 if (pscan->nr_sets > MRVDRV_MAX_BSSID_LIST) {
Holger Schurig9012b282007-05-25 11:27:16 -04001899 lbs_deb_scan(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001900 "SCAN_RESP: Invalid number of AP returned (%d)!!\n",
1901 pscan->nr_sets);
Holger Schurig9012b282007-05-25 11:27:16 -04001902 ret = -1;
1903 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001904 }
1905
1906 bytesleft = le16_to_cpu(pscan->bssdescriptsize);
Holger Schurig9012b282007-05-25 11:27:16 -04001907 lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001908
1909 scanrespsize = le16_to_cpu(resp->size);
Holger Schurig9012b282007-05-25 11:27:16 -04001910 lbs_deb_scan("SCAN_RESP: returned %d AP before parsing\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001911 pscan->nr_sets);
1912
1913 numintable = adapter->numinscantable;
1914 pbssinfo = pscan->bssdesc_and_tlvbuffer;
1915
1916 /* The size of the TLV buffer is equal to the entire command response
1917 * size (scanrespsize) minus the fixed fields (sizeof()'s), the
1918 * BSS Descriptions (bssdescriptsize as bytesLef) and the command
1919 * response header (S_DS_GEN)
1920 */
1921 tlvbufsize = scanrespsize - (bytesleft + sizeof(pscan->bssdescriptsize)
1922 + sizeof(pscan->nr_sets)
1923 + S_DS_GEN);
1924
1925 ptlv = (struct mrvlietypes_data *) (pscan->bssdesc_and_tlvbuffer + bytesleft);
1926
1927 /* Search the TLV buffer space in the scan response for any valid TLVs */
1928 wlan_ret_802_11_scan_get_tlv_ptrs(ptlv, tlvbufsize, &ptsftlv);
1929
1930 /*
1931 * Process each scan response returned (pscan->nr_sets). Save
1932 * the information in the newbssentry and then insert into the
1933 * driver scan table either as an update to an existing entry
1934 * or as an addition at the end of the table
1935 */
1936 for (idx = 0; idx < pscan->nr_sets && bytesleft; idx++) {
1937 /* Zero out the newbssentry we are about to store info in */
1938 memset(&newbssentry, 0x00, sizeof(newbssentry));
1939
1940 /* Process the data fields and IEs returned for this BSS */
1941 if ((InterpretBSSDescriptionWithIE(&newbssentry,
1942 &pbssinfo,
1943 &bytesleft) ==
1944 0)
1945 && CHECK_SSID_IS_VALID(&newbssentry.ssid)) {
1946
Dan Williams4ace1132007-05-25 13:16:38 -04001947 lbs_deb_scan(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001948 "SCAN_RESP: BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
Dan Williams4ace1132007-05-25 13:16:38 -04001949 newbssentry.bssid[0],
1950 newbssentry.bssid[1],
1951 newbssentry.bssid[2],
1952 newbssentry.bssid[3],
1953 newbssentry.bssid[4],
1954 newbssentry.bssid[5]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001955
1956 /*
1957 * Search the scan table for the same bssid
1958 */
1959 for (bssIdx = 0; bssIdx < numintable; bssIdx++) {
Dan Williams4ace1132007-05-25 13:16:38 -04001960 if (memcmp(newbssentry.bssid,
1961 adapter->scantable[bssIdx].bssid,
1962 sizeof(newbssentry.bssid)) == 0) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001963 /*
1964 * If the SSID matches as well, it is a duplicate of
1965 * this entry. Keep the bssIdx set to this
1966 * entry so we replace the old contents in the table
1967 */
1968 if ((newbssentry.ssid.ssidlength ==
1969 adapter->scantable[bssIdx].ssid.
1970 ssidlength)
1971 &&
1972 (memcmp
1973 (newbssentry.ssid.ssid,
1974 adapter->scantable[bssIdx].ssid.
1975 ssid,
1976 newbssentry.ssid.ssidlength) ==
1977 0)) {
Holger Schurig9012b282007-05-25 11:27:16 -04001978 lbs_deb_scan(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001979 "SCAN_RESP: Duplicate of index: %d\n",
1980 bssIdx);
1981 break;
1982 }
1983 }
1984 }
1985 /*
1986 * If the bssIdx is equal to the number of entries in the table,
1987 * the new entry was not a duplicate; append it to the scan
1988 * table
1989 */
1990 if (bssIdx == numintable) {
1991 /* Range check the bssIdx, keep it limited to the last entry */
1992 if (bssIdx == MRVDRV_MAX_BSSID_LIST) {
1993 bssIdx--;
1994 } else {
1995 numintable++;
1996 }
1997 }
1998
1999 /*
2000 * If the TSF TLV was appended to the scan results, save the
2001 * this entries TSF value in the networktsf field. The
2002 * networktsf is the firmware's TSF value at the time the
2003 * beacon or probe response was received.
2004 */
2005 if (ptsftlv) {
2006 memcpy(&tsfval, &ptsftlv->tsftable[idx],
2007 sizeof(tsfval));
2008 tsfval = le64_to_cpu(tsfval);
2009
2010 memcpy(&newbssentry.networktsf,
2011 &tsfval, sizeof(newbssentry.networktsf));
2012 }
2013
2014 /* Copy the locally created newbssentry to the scan table */
2015 memcpy(&adapter->scantable[bssIdx],
2016 &newbssentry,
2017 sizeof(adapter->scantable[bssIdx]));
2018
2019 } else {
2020
2021 /* error parsing/interpreting the scan response, skipped */
Holger Schurig9012b282007-05-25 11:27:16 -04002022 lbs_deb_scan("SCAN_RESP: "
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002023 "InterpretBSSDescriptionWithIE returned ERROR\n");
2024 }
2025 }
2026
Holger Schurig9012b282007-05-25 11:27:16 -04002027 lbs_deb_scan("SCAN_RESP: Scanned %2d APs, %d valid, %d total\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002028 pscan->nr_sets, numintable - adapter->numinscantable,
2029 numintable);
2030
2031 /* Update the total number of BSSIDs in the scan table */
2032 adapter->numinscantable = numintable;
Holger Schurig9012b282007-05-25 11:27:16 -04002033 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002034
Holger Schurig9012b282007-05-25 11:27:16 -04002035done:
2036 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
2037 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02002038}