2 * Functions implementing wlan scan IOCTL and firmware command APIs
4 * IOCTL handlers as well as command preperation and response routines
5 * for sending scan commands to the firmware.
7 #include <linux/ctype.h>
9 #include <linux/netdevice.h>
10 #include <linux/wireless.h>
11 #include <linux/etherdevice.h>
13 #include <net/ieee80211.h>
14 #include <net/iw_handler.h>
16 #include <asm/unaligned.h>
24 //! Approximate amount of data needed to pass a scan result back to iwlist
25 #define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \
32 + 40) /* 40 for WPAIE */
34 //! Memory needed to store a max sized channel List TLV for a firmware scan
35 #define CHAN_TLV_MAX_SIZE (sizeof(struct mrvlietypesheader) \
36 + (MRVDRV_MAX_CHANNELS_PER_SCAN \
37 * sizeof(struct chanscanparamset)))
39 //! Memory needed to store a max number/size SSID TLV for a firmware scan
40 #define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvlietypes_ssidparamset))
42 //! Maximum memory needed for a lbs_scan_cmd_config with all TLVs at max
43 #define MAX_SCAN_CFG_ALLOC (sizeof(struct lbs_scan_cmd_config) \
47 //! The maximum number of channels the firmware can scan per command
48 #define MRVDRV_MAX_CHANNELS_PER_SCAN 14
51 * @brief Number of channels to scan per firmware scan command issuance.
53 * Number restricted to prevent hitting the limit on the amount of scan data
54 * returned in a single firmware scan command.
56 #define MRVDRV_CHANNELS_PER_SCAN_CMD 4
58 //! Scan time specified in the channel TLV for each channel for passive scans
59 #define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100
61 //! Scan time specified in the channel TLV for each channel for active scans
62 #define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100
64 static const u8 zeromac
[ETH_ALEN
] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
65 static const u8 bcastmac
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
70 /*********************************************************************/
72 /* Misc helper functions */
74 /*********************************************************************/
76 static inline void clear_bss_descriptor (struct bss_descriptor
* bss
)
78 /* Don't blow away ->list, just BSS data */
79 memset(bss
, 0, offsetof(struct bss_descriptor
, list
));
83 * @brief Compare two SSIDs
85 * @param ssid1 A pointer to ssid to compare
86 * @param ssid2 A pointer to ssid to compare
88 * @return 0: ssid is same, otherwise is different
90 int lbs_ssid_cmp(u8
*ssid1
, u8 ssid1_len
, u8
*ssid2
, u8 ssid2_len
)
92 if (ssid1_len
!= ssid2_len
)
95 return memcmp(ssid1
, ssid2
, ssid1_len
);
98 static inline int match_bss_no_security(struct lbs_802_11_security
*secinfo
,
99 struct bss_descriptor
* match_bss
)
101 if ( !secinfo
->wep_enabled
102 && !secinfo
->WPAenabled
103 && !secinfo
->WPA2enabled
104 && match_bss
->wpa_ie
[0] != MFIE_TYPE_GENERIC
105 && match_bss
->rsn_ie
[0] != MFIE_TYPE_RSN
106 && !(match_bss
->capability
& WLAN_CAPABILITY_PRIVACY
)) {
112 static inline int match_bss_static_wep(struct lbs_802_11_security
*secinfo
,
113 struct bss_descriptor
* match_bss
)
115 if ( secinfo
->wep_enabled
116 && !secinfo
->WPAenabled
117 && !secinfo
->WPA2enabled
118 && (match_bss
->capability
& WLAN_CAPABILITY_PRIVACY
)) {
124 static inline int match_bss_wpa(struct lbs_802_11_security
*secinfo
,
125 struct bss_descriptor
* match_bss
)
127 if ( !secinfo
->wep_enabled
128 && secinfo
->WPAenabled
129 && (match_bss
->wpa_ie
[0] == MFIE_TYPE_GENERIC
)
130 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
131 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) {
139 static inline int match_bss_wpa2(struct lbs_802_11_security
*secinfo
,
140 struct bss_descriptor
* match_bss
)
142 if ( !secinfo
->wep_enabled
143 && secinfo
->WPA2enabled
144 && (match_bss
->rsn_ie
[0] == MFIE_TYPE_RSN
)
145 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
146 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) {
154 static inline int match_bss_dynamic_wep(struct lbs_802_11_security
*secinfo
,
155 struct bss_descriptor
* match_bss
)
157 if ( !secinfo
->wep_enabled
158 && !secinfo
->WPAenabled
159 && !secinfo
->WPA2enabled
160 && (match_bss
->wpa_ie
[0] != MFIE_TYPE_GENERIC
)
161 && (match_bss
->rsn_ie
[0] != MFIE_TYPE_RSN
)
162 && (match_bss
->capability
& WLAN_CAPABILITY_PRIVACY
)) {
168 static inline int is_same_network(struct bss_descriptor
*src
,
169 struct bss_descriptor
*dst
)
171 /* A network is only a duplicate if the channel, BSSID, and ESSID
172 * all match. We treat all <hidden> with the same BSSID and channel
174 return ((src
->ssid_len
== dst
->ssid_len
) &&
175 (src
->channel
== dst
->channel
) &&
176 !compare_ether_addr(src
->bssid
, dst
->bssid
) &&
177 !memcmp(src
->ssid
, dst
->ssid
, src
->ssid_len
));
181 * @brief Check if a scanned network compatible with the driver settings
183 * WEP WPA WPA2 ad-hoc encrypt Network
184 * enabled enabled enabled AES mode privacy WPA WPA2 Compatible
185 * 0 0 0 0 NONE 0 0 0 yes No security
186 * 1 0 0 0 NONE 1 0 0 yes Static WEP
187 * 0 1 0 0 x 1x 1 x yes WPA
188 * 0 0 1 0 x 1x x 1 yes WPA2
189 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
190 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
193 * @param priv A pointer to struct lbs_private
194 * @param index Index in scantable to check against current driver settings
195 * @param mode Network mode: Infrastructure or IBSS
197 * @return Index in scantable, or error code if negative
199 static int is_network_compatible(struct lbs_private
*priv
,
200 struct bss_descriptor
* bss
, u8 mode
)
204 lbs_deb_enter(LBS_DEB_SCAN
);
206 if (bss
->mode
!= mode
)
209 if ((matched
= match_bss_no_security(&priv
->secinfo
, bss
))) {
211 } else if ((matched
= match_bss_static_wep(&priv
->secinfo
, bss
))) {
213 } else if ((matched
= match_bss_wpa(&priv
->secinfo
, bss
))) {
215 "is_network_compatible() WPA: wpa_ie 0x%x "
216 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
217 "privacy 0x%x\n", bss
->wpa_ie
[0], bss
->rsn_ie
[0],
218 priv
->secinfo
.wep_enabled
? "e" : "d",
219 priv
->secinfo
.WPAenabled
? "e" : "d",
220 priv
->secinfo
.WPA2enabled
? "e" : "d",
221 (bss
->capability
& WLAN_CAPABILITY_PRIVACY
));
223 } else if ((matched
= match_bss_wpa2(&priv
->secinfo
, bss
))) {
225 "is_network_compatible() WPA2: wpa_ie 0x%x "
226 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
227 "privacy 0x%x\n", bss
->wpa_ie
[0], bss
->rsn_ie
[0],
228 priv
->secinfo
.wep_enabled
? "e" : "d",
229 priv
->secinfo
.WPAenabled
? "e" : "d",
230 priv
->secinfo
.WPA2enabled
? "e" : "d",
231 (bss
->capability
& WLAN_CAPABILITY_PRIVACY
));
233 } else if ((matched
= match_bss_dynamic_wep(&priv
->secinfo
, bss
))) {
235 "is_network_compatible() dynamic WEP: "
236 "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n",
237 bss
->wpa_ie
[0], bss
->rsn_ie
[0],
238 (bss
->capability
& WLAN_CAPABILITY_PRIVACY
));
242 /* bss security settings don't match those configured on card */
244 "is_network_compatible() FAILED: wpa_ie 0x%x "
245 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n",
246 bss
->wpa_ie
[0], bss
->rsn_ie
[0],
247 priv
->secinfo
.wep_enabled
? "e" : "d",
248 priv
->secinfo
.WPAenabled
? "e" : "d",
249 priv
->secinfo
.WPA2enabled
? "e" : "d",
250 (bss
->capability
& WLAN_CAPABILITY_PRIVACY
));
253 lbs_deb_leave_args(LBS_DEB_SCAN
, "matched: %d", matched
);
260 /*********************************************************************/
262 /* Main scanning support */
264 /*********************************************************************/
266 void lbs_scan_worker(struct work_struct
*work
)
268 struct lbs_private
*priv
=
269 container_of(work
, struct lbs_private
, scan_work
.work
);
271 lbs_deb_enter(LBS_DEB_SCAN
);
272 lbs_scan_networks(priv
, NULL
, 0);
273 lbs_deb_leave(LBS_DEB_SCAN
);
278 * @brief Create a channel list for the driver to scan based on region info
280 * Only used from lbs_scan_setup_scan_config()
282 * Use the driver region/band information to construct a comprehensive list
283 * of channels to scan. This routine is used for any scan that is not
284 * provided a specific channel list to scan.
286 * @param priv A pointer to struct lbs_private structure
287 * @param scanchanlist Output parameter: resulting channel list to scan
288 * @param filteredscan Flag indicating whether or not a BSSID or SSID filter
289 * is being sent in the command to firmware. Used to
290 * increase the number of channels sent in a scan
291 * command and to disable the firmware channel scan
296 static int lbs_scan_create_channel_list(struct lbs_private
*priv
,
297 struct chanscanparamset
* scanchanlist
,
301 struct region_channel
*scanregion
;
302 struct chan_freq_power
*cfp
;
310 /* Set the default scan type to the user specified type, will later
311 * be changed to passive on a per channel basis if restricted by
312 * regulatory requirements (11d or 11h)
314 scantype
= CMD_SCAN_TYPE_ACTIVE
;
316 for (rgnidx
= 0; rgnidx
< ARRAY_SIZE(priv
->region_channel
); rgnidx
++) {
317 if (priv
->enable11d
&&
318 (priv
->connect_status
!= LBS_CONNECTED
) &&
319 (priv
->mesh_connect_status
!= LBS_CONNECTED
)) {
320 /* Scan all the supported chan for the first scan */
321 if (!priv
->universal_channel
[rgnidx
].valid
)
323 scanregion
= &priv
->universal_channel
[rgnidx
];
325 /* clear the parsed_region_chan for the first scan */
326 memset(&priv
->parsed_region_chan
, 0x00,
327 sizeof(priv
->parsed_region_chan
));
329 if (!priv
->region_channel
[rgnidx
].valid
)
331 scanregion
= &priv
->region_channel
[rgnidx
];
335 nextchan
< scanregion
->nrcfp
; nextchan
++, chanidx
++) {
337 cfp
= scanregion
->CFP
+ nextchan
;
339 if (priv
->enable11d
) {
341 lbs_get_scan_type_11d(cfp
->channel
,
346 switch (scanregion
->band
) {
350 scanchanlist
[chanidx
].radiotype
=
351 CMD_SCAN_RADIO_TYPE_BG
;
355 if (scantype
== CMD_SCAN_TYPE_PASSIVE
) {
356 scanchanlist
[chanidx
].maxscantime
=
357 cpu_to_le16(MRVDRV_PASSIVE_SCAN_CHAN_TIME
);
358 scanchanlist
[chanidx
].chanscanmode
.passivescan
=
361 scanchanlist
[chanidx
].maxscantime
=
362 cpu_to_le16(MRVDRV_ACTIVE_SCAN_CHAN_TIME
);
363 scanchanlist
[chanidx
].chanscanmode
.passivescan
=
367 scanchanlist
[chanidx
].channumber
= cfp
->channel
;
370 scanchanlist
[chanidx
].chanscanmode
.
380 * Add SSID TLV of the form:
384 * ssid 4d 4e 54 45 53 54
386 static int lbs_scan_add_ssid_tlv(u8
*tlv
,
387 const struct lbs_ioctl_user_scan_cfg
*user_cfg
)
389 struct mrvlietypes_ssidparamset
*ssid_tlv
=
390 (struct mrvlietypes_ssidparamset
*)tlv
;
391 ssid_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_SSID
);
392 ssid_tlv
->header
.len
= cpu_to_le16(user_cfg
->ssid_len
);
393 memcpy(ssid_tlv
->ssid
, user_cfg
->ssid
, user_cfg
->ssid_len
);
394 return sizeof(ssid_tlv
->header
) + user_cfg
->ssid_len
;
399 * Add CHANLIST TLV of the form
401 * TLV-ID CHANLIST 01 01
403 * channel 1 00 01 00 00 00 64 00
407 * min scan time 00 00
408 * max scan time 64 00
409 * channel 2 00 02 00 00 00 64 00
410 * channel 3 00 03 00 00 00 64 00
411 * channel 4 00 04 00 00 00 64 00
412 * channel 5 00 05 00 00 00 64 00
413 * channel 6 00 06 00 00 00 64 00
414 * channel 7 00 07 00 00 00 64 00
415 * channel 8 00 08 00 00 00 64 00
416 * channel 9 00 09 00 00 00 64 00
417 * channel 10 00 0a 00 00 00 64 00
418 * channel 11 00 0b 00 00 00 64 00
419 * channel 12 00 0c 00 00 00 64 00
420 * channel 13 00 0d 00 00 00 64 00
423 static int lbs_scan_add_chanlist_tlv(u8
*tlv
,
424 struct chanscanparamset
*chan_list
,
427 size_t size
= sizeof(struct chanscanparamset
) * chan_count
;
428 struct mrvlietypes_chanlistparamset
*chan_tlv
=
429 (struct mrvlietypes_chanlistparamset
*) tlv
;
431 chan_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_CHANLIST
);
432 memcpy(chan_tlv
->chanscanparam
, chan_list
, size
);
433 chan_tlv
->header
.len
= cpu_to_le16(size
);
434 return sizeof(chan_tlv
->header
) + size
;
439 * Add RATES TLV of the form
443 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
445 * The rates are in lbs_bg_rates[], but for the 802.11b
446 * rates the high bit isn't set.
448 static int lbs_scan_add_rates_tlv(u8
*tlv
)
451 struct mrvlietypes_ratesparamset
*rate_tlv
=
452 (struct mrvlietypes_ratesparamset
*) tlv
;
454 rate_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
455 tlv
+= sizeof(rate_tlv
->header
);
456 for (i
= 0; i
< MAX_RATES
; i
++) {
457 *tlv
= lbs_bg_rates
[i
];
460 /* This code makes sure that the 802.11b rates (1 MBit/s, 2
461 MBit/s, 5.5 MBit/s and 11 MBit/s get's the high bit set.
462 Note that the values are MBit/s * 2, to mark them as
463 basic rates so that the firmware likes it better */
464 if (*tlv
== 0x02 || *tlv
== 0x04 ||
465 *tlv
== 0x0b || *tlv
== 0x16)
469 rate_tlv
->header
.len
= cpu_to_le16(i
);
470 return sizeof(rate_tlv
->header
) + i
;
475 * Generate the CMD_802_11_SCAN command with the proper tlv
476 * for a bunch of channels.
478 static int lbs_do_scan(struct lbs_private
*priv
,
480 struct chanscanparamset
*chan_list
,
482 const struct lbs_ioctl_user_scan_cfg
*user_cfg
)
485 struct lbs_scan_cmd_config
*scan_cmd
;
486 u8
*tlv
; /* pointer into our current, growing TLV storage area */
488 lbs_deb_enter_args(LBS_DEB_SCAN
, "bsstype %d, chanlist[].chan %d, "
490 bsstype
, chan_list
[0].channumber
, chan_count
);
492 /* create the fixed part for scan command */
493 scan_cmd
= kzalloc(MAX_SCAN_CFG_ALLOC
, GFP_KERNEL
);
494 if (scan_cmd
== NULL
)
496 tlv
= scan_cmd
->tlvbuffer
;
498 memcpy(scan_cmd
->bssid
, user_cfg
->bssid
, ETH_ALEN
);
499 scan_cmd
->bsstype
= bsstype
;
502 if (user_cfg
&& user_cfg
->ssid_len
)
503 tlv
+= lbs_scan_add_ssid_tlv(tlv
, user_cfg
);
504 if (chan_list
&& chan_count
)
505 tlv
+= lbs_scan_add_chanlist_tlv(tlv
, chan_list
, chan_count
);
506 tlv
+= lbs_scan_add_rates_tlv(tlv
);
508 /* This is the final data we are about to send */
509 scan_cmd
->tlvbufferlen
= tlv
- scan_cmd
->tlvbuffer
;
510 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_CMD", (void *)scan_cmd
, 1+6);
511 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_TLV", scan_cmd
->tlvbuffer
,
512 scan_cmd
->tlvbufferlen
);
514 ret
= lbs_prepare_and_send_command(priv
, CMD_802_11_SCAN
, 0,
515 CMD_OPTION_WAITFORRSP
, 0, scan_cmd
);
518 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
524 * @brief Internal function used to start a scan based on an input config
526 * Also used from debugfs
528 * Use the input user scan configuration information when provided in
529 * order to send the appropriate scan commands to firmware to populate or
530 * update the internal driver scan table
532 * @param priv A pointer to struct lbs_private structure
533 * @param puserscanin Pointer to the input configuration for the requested
536 * @return 0 or < 0 if error
538 int lbs_scan_networks(struct lbs_private
*priv
,
539 const struct lbs_ioctl_user_scan_cfg
*user_cfg
,
543 struct chanscanparamset
*chan_list
;
544 struct chanscanparamset
*curr_chans
;
546 u8 bsstype
= CMD_BSS_TYPE_ANY
;
547 int numchannels
= MRVDRV_CHANNELS_PER_SCAN_CMD
;
548 int filteredscan
= 0;
549 union iwreq_data wrqu
;
550 #ifdef CONFIG_LIBERTAS_DEBUG
551 struct bss_descriptor
*iter
;
553 DECLARE_MAC_BUF(mac
);
556 lbs_deb_enter_args(LBS_DEB_SCAN
, "full_scan %d",
559 /* Cancel any partial outstanding partial scans if this scan
562 if (full_scan
&& delayed_work_pending(&priv
->scan_work
))
563 cancel_delayed_work(&priv
->scan_work
);
565 /* Determine same scan parameters */
567 if (user_cfg
->bsstype
)
568 bsstype
= user_cfg
->bsstype
;
569 if (compare_ether_addr(user_cfg
->bssid
, &zeromac
[0]) != 0) {
570 numchannels
= MRVDRV_MAX_CHANNELS_PER_SCAN
;
574 lbs_deb_scan("numchannels %d, bsstype %d, "
576 numchannels
, bsstype
, filteredscan
);
578 /* Create list of channels to scan */
579 chan_list
= kzalloc(sizeof(struct chanscanparamset
) *
580 LBS_IOCTL_USER_SCAN_CHAN_MAX
, GFP_KERNEL
);
582 lbs_pr_alert("SCAN: chan_list empty\n");
586 /* We want to scan all channels */
587 chan_count
= lbs_scan_create_channel_list(priv
, chan_list
,
590 netif_stop_queue(priv
->dev
);
591 netif_carrier_off(priv
->dev
);
592 if (priv
->mesh_dev
) {
593 netif_stop_queue(priv
->mesh_dev
);
594 netif_carrier_off(priv
->mesh_dev
);
597 /* Prepare to continue an interrupted scan */
598 lbs_deb_scan("chan_count %d, last_scanned_channel %d\n",
599 chan_count
, priv
->last_scanned_channel
);
600 curr_chans
= chan_list
;
601 /* advance channel list by already-scanned-channels */
602 if (priv
->last_scanned_channel
> 0) {
603 curr_chans
+= priv
->last_scanned_channel
;
604 chan_count
-= priv
->last_scanned_channel
;
607 /* Send scan command(s)
608 * numchannels contains the number of channels we should maximally scan
609 * chan_count is the total number of channels to scan
613 int to_scan
= min(numchannels
, chan_count
);
614 lbs_deb_scan("scanning %d of %d channels\n",
615 to_scan
, chan_count
);
616 ret
= lbs_do_scan(priv
, bsstype
, curr_chans
,
619 lbs_pr_err("SCAN_CMD failed\n");
622 curr_chans
+= to_scan
;
623 chan_count
-= to_scan
;
625 /* somehow schedule the next part of the scan */
628 !priv
->surpriseremoved
) {
629 /* -1 marks just that we're currently scanning */
630 if (priv
->last_scanned_channel
< 0)
631 priv
->last_scanned_channel
= to_scan
;
633 priv
->last_scanned_channel
+= to_scan
;
634 cancel_delayed_work(&priv
->scan_work
);
635 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
636 msecs_to_jiffies(300));
637 /* skip over GIWSCAN event */
642 memset(&wrqu
, 0, sizeof(union iwreq_data
));
643 wireless_send_event(priv
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
645 #ifdef CONFIG_LIBERTAS_DEBUG
646 /* Dump the scan table */
647 mutex_lock(&priv
->lock
);
648 lbs_deb_scan("scan table:\n");
649 list_for_each_entry(iter
, &priv
->network_list
, list
)
650 lbs_deb_scan("%02d: BSSID %s, RSSI %d, SSID '%s'\n",
651 i
++, print_mac(mac
, iter
->bssid
), (s32
) iter
->rssi
,
652 escape_essid(iter
->ssid
, iter
->ssid_len
));
653 mutex_unlock(&priv
->lock
);
657 priv
->last_scanned_channel
= 0;
660 if (priv
->connect_status
== LBS_CONNECTED
) {
661 netif_carrier_on(priv
->dev
);
662 if (!priv
->tx_pending_len
)
663 netif_wake_queue(priv
->dev
);
665 if (priv
->mesh_dev
&& (priv
->mesh_connect_status
== LBS_CONNECTED
)) {
666 netif_carrier_on(priv
->mesh_dev
);
667 if (!priv
->tx_pending_len
)
668 netif_wake_queue(priv
->mesh_dev
);
672 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
679 /*********************************************************************/
681 /* Result interpretation */
683 /*********************************************************************/
686 * @brief Interpret a BSS scan response returned from the firmware
688 * Parse the various fixed fields and IEs passed back for a a BSS probe
689 * response or beacon from the scan command. Record information as needed
690 * in the scan table struct bss_descriptor for that entry.
692 * @param bss Output parameter: Pointer to the BSS Entry
696 static int lbs_process_bss(struct bss_descriptor
*bss
,
697 u8
** pbeaconinfo
, int *bytesleft
)
699 struct ieeetypes_fhparamset
*pFH
;
700 struct ieeetypes_dsparamset
*pDS
;
701 struct ieeetypes_cfparamset
*pCF
;
702 struct ieeetypes_ibssparamset
*pibss
;
703 DECLARE_MAC_BUF(mac
);
704 struct ieeetypes_countryinfoset
*pcountryinfo
;
706 u8 n_ex_rates
= 0, got_basic_rates
= 0, n_basic_rates
= 0;
710 lbs_deb_enter(LBS_DEB_SCAN
);
712 if (*bytesleft
>= sizeof(beaconsize
)) {
713 /* Extract & convert beacon size from the command buffer */
714 beaconsize
= le16_to_cpu(get_unaligned((__le16
*)*pbeaconinfo
));
715 *bytesleft
-= sizeof(beaconsize
);
716 *pbeaconinfo
+= sizeof(beaconsize
);
719 if (beaconsize
== 0 || beaconsize
> *bytesleft
) {
720 *pbeaconinfo
+= *bytesleft
;
726 /* Initialize the current working beacon pointer for this BSS iteration */
728 end
= pos
+ beaconsize
;
730 /* Advance the return beacon pointer past the current beacon */
731 *pbeaconinfo
+= beaconsize
;
732 *bytesleft
-= beaconsize
;
734 memcpy(bss
->bssid
, pos
, ETH_ALEN
);
735 lbs_deb_scan("process_bss: BSSID %s\n", print_mac(mac
, bss
->bssid
));
738 if ((end
- pos
) < 12) {
739 lbs_deb_scan("process_bss: Not enough bytes left\n");
745 * next 4 fields are RSSI, time stamp, beacon interval,
746 * and capability information
749 /* RSSI is 1 byte long */
751 lbs_deb_scan("process_bss: RSSI %d\n", *pos
);
754 /* time stamp is 8 bytes long */
757 /* beacon interval is 2 bytes long */
758 bss
->beaconperiod
= le16_to_cpup((void *) pos
);
761 /* capability information is 2 bytes long */
762 bss
->capability
= le16_to_cpup((void *) pos
);
763 lbs_deb_scan("process_bss: capabilities 0x%04x\n", bss
->capability
);
766 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
767 lbs_deb_scan("process_bss: WEP enabled\n");
768 if (bss
->capability
& WLAN_CAPABILITY_IBSS
)
769 bss
->mode
= IW_MODE_ADHOC
;
771 bss
->mode
= IW_MODE_INFRA
;
773 /* rest of the current buffer are IE's */
774 lbs_deb_scan("process_bss: IE len %zd\n", end
- pos
);
775 lbs_deb_hex(LBS_DEB_SCAN
, "process_bss: IE info", pos
, end
- pos
);
777 /* process variable IE */
778 while (pos
<= end
- 2) {
779 struct ieee80211_info_element
* elem
=
780 (struct ieee80211_info_element
*) pos
;
782 if (pos
+ elem
->len
> end
) {
783 lbs_deb_scan("process_bss: error in processing IE, "
784 "bytes left < IE length\n");
790 bss
->ssid_len
= elem
->len
;
791 memcpy(bss
->ssid
, elem
->data
, elem
->len
);
792 lbs_deb_scan("got SSID IE: '%s', len %u\n",
793 escape_essid(bss
->ssid
, bss
->ssid_len
),
797 case MFIE_TYPE_RATES
:
798 n_basic_rates
= min_t(u8
, MAX_RATES
, elem
->len
);
799 memcpy(bss
->rates
, elem
->data
, n_basic_rates
);
801 lbs_deb_scan("got RATES IE\n");
804 case MFIE_TYPE_FH_SET
:
805 pFH
= (struct ieeetypes_fhparamset
*) pos
;
806 memmove(&bss
->phyparamset
.fhparamset
, pFH
,
807 sizeof(struct ieeetypes_fhparamset
));
808 lbs_deb_scan("got FH IE\n");
811 case MFIE_TYPE_DS_SET
:
812 pDS
= (struct ieeetypes_dsparamset
*) pos
;
813 bss
->channel
= pDS
->currentchan
;
814 memcpy(&bss
->phyparamset
.dsparamset
, pDS
,
815 sizeof(struct ieeetypes_dsparamset
));
816 lbs_deb_scan("got DS IE, channel %d\n", bss
->channel
);
819 case MFIE_TYPE_CF_SET
:
820 pCF
= (struct ieeetypes_cfparamset
*) pos
;
821 memcpy(&bss
->ssparamset
.cfparamset
, pCF
,
822 sizeof(struct ieeetypes_cfparamset
));
823 lbs_deb_scan("got CF IE\n");
826 case MFIE_TYPE_IBSS_SET
:
827 pibss
= (struct ieeetypes_ibssparamset
*) pos
;
828 bss
->atimwindow
= le16_to_cpu(pibss
->atimwindow
);
829 memmove(&bss
->ssparamset
.ibssparamset
, pibss
,
830 sizeof(struct ieeetypes_ibssparamset
));
831 lbs_deb_scan("got IBSS IE\n");
834 case MFIE_TYPE_COUNTRY
:
835 pcountryinfo
= (struct ieeetypes_countryinfoset
*) pos
;
836 lbs_deb_scan("got COUNTRY IE\n");
837 if (pcountryinfo
->len
< sizeof(pcountryinfo
->countrycode
)
838 || pcountryinfo
->len
> 254) {
839 lbs_deb_scan("process_bss: 11D- Err "
840 "CountryInfo len %d, min %zd, max 254\n",
842 sizeof(pcountryinfo
->countrycode
));
847 memcpy(&bss
->countryinfo
,
848 pcountryinfo
, pcountryinfo
->len
+ 2);
849 lbs_deb_hex(LBS_DEB_SCAN
, "process_bss: 11d countryinfo",
851 (u32
) (pcountryinfo
->len
+ 2));
854 case MFIE_TYPE_RATES_EX
:
855 /* only process extended supported rate if data rate is
856 * already found. Data rate IE should come before
857 * extended supported rate IE
859 lbs_deb_scan("got RATESEX IE\n");
860 if (!got_basic_rates
) {
861 lbs_deb_scan("... but ignoring it\n");
865 n_ex_rates
= elem
->len
;
866 if (n_basic_rates
+ n_ex_rates
> MAX_RATES
)
867 n_ex_rates
= MAX_RATES
- n_basic_rates
;
869 p
= bss
->rates
+ n_basic_rates
;
870 memcpy(p
, elem
->data
, n_ex_rates
);
873 case MFIE_TYPE_GENERIC
:
874 if (elem
->len
>= 4 &&
875 elem
->data
[0] == 0x00 &&
876 elem
->data
[1] == 0x50 &&
877 elem
->data
[2] == 0xf2 &&
878 elem
->data
[3] == 0x01) {
879 bss
->wpa_ie_len
= min(elem
->len
+ 2,
881 memcpy(bss
->wpa_ie
, elem
, bss
->wpa_ie_len
);
882 lbs_deb_scan("got WPA IE\n");
883 lbs_deb_hex(LBS_DEB_SCAN
, "WPA IE", bss
->wpa_ie
,
885 } else if (elem
->len
>= MARVELL_MESH_IE_LENGTH
&&
886 elem
->data
[0] == 0x00 &&
887 elem
->data
[1] == 0x50 &&
888 elem
->data
[2] == 0x43 &&
889 elem
->data
[3] == 0x04) {
890 lbs_deb_scan("got mesh IE\n");
893 lbs_deb_scan("got generiec IE: "
894 "%02x:%02x:%02x:%02x, len %d\n",
895 elem
->data
[0], elem
->data
[1],
896 elem
->data
[2], elem
->data
[3],
902 lbs_deb_scan("got RSN IE\n");
903 bss
->rsn_ie_len
= min(elem
->len
+ 2, MAX_WPA_IE_LEN
);
904 memcpy(bss
->rsn_ie
, elem
, bss
->rsn_ie_len
);
905 lbs_deb_hex(LBS_DEB_SCAN
, "process_bss: RSN_IE",
906 bss
->rsn_ie
, elem
->len
);
910 lbs_deb_scan("got IE 0x%04x, len %d\n",
911 elem
->id
, elem
->len
);
915 pos
+= elem
->len
+ 2;
919 bss
->last_scanned
= jiffies
;
920 lbs_unset_basic_rate_flags(bss
->rates
, sizeof(bss
->rates
));
925 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
930 * @brief This function finds a specific compatible BSSID in the scan list
932 * Used in association code
934 * @param priv A pointer to struct lbs_private
935 * @param bssid BSSID to find in the scan list
936 * @param mode Network mode: Infrastructure or IBSS
938 * @return index in BSSID list, or error return code (< 0)
940 struct bss_descriptor
*lbs_find_bssid_in_list(struct lbs_private
*priv
,
943 struct bss_descriptor
* iter_bss
;
944 struct bss_descriptor
* found_bss
= NULL
;
946 lbs_deb_enter(LBS_DEB_SCAN
);
951 lbs_deb_hex(LBS_DEB_SCAN
, "looking for",
954 /* Look through the scan table for a compatible match. The loop will
955 * continue past a matched bssid that is not compatible in case there
956 * is an AP with multiple SSIDs assigned to the same BSSID
958 mutex_lock(&priv
->lock
);
959 list_for_each_entry (iter_bss
, &priv
->network_list
, list
) {
960 if (compare_ether_addr(iter_bss
->bssid
, bssid
))
961 continue; /* bssid doesn't match */
965 if (!is_network_compatible(priv
, iter_bss
, mode
))
967 found_bss
= iter_bss
;
970 found_bss
= iter_bss
;
974 mutex_unlock(&priv
->lock
);
977 lbs_deb_leave_args(LBS_DEB_SCAN
, "found_bss %p", found_bss
);
982 * @brief This function finds ssid in ssid list.
984 * Used in association code
986 * @param priv A pointer to struct lbs_private
987 * @param ssid SSID to find in the list
988 * @param bssid BSSID to qualify the SSID selection (if provided)
989 * @param mode Network mode: Infrastructure or IBSS
991 * @return index in BSSID list
993 struct bss_descriptor
*lbs_find_ssid_in_list(struct lbs_private
*priv
,
994 u8
*ssid
, u8 ssid_len
, u8
* bssid
, u8 mode
,
998 struct bss_descriptor
* iter_bss
= NULL
;
999 struct bss_descriptor
* found_bss
= NULL
;
1000 struct bss_descriptor
* tmp_oldest
= NULL
;
1002 lbs_deb_enter(LBS_DEB_SCAN
);
1004 mutex_lock(&priv
->lock
);
1006 list_for_each_entry (iter_bss
, &priv
->network_list
, list
) {
1008 || (iter_bss
->last_scanned
< tmp_oldest
->last_scanned
))
1009 tmp_oldest
= iter_bss
;
1011 if (lbs_ssid_cmp(iter_bss
->ssid
, iter_bss
->ssid_len
,
1012 ssid
, ssid_len
) != 0)
1013 continue; /* ssid doesn't match */
1014 if (bssid
&& compare_ether_addr(iter_bss
->bssid
, bssid
) != 0)
1015 continue; /* bssid doesn't match */
1016 if ((channel
> 0) && (iter_bss
->channel
!= channel
))
1017 continue; /* channel doesn't match */
1022 if (!is_network_compatible(priv
, iter_bss
, mode
))
1026 /* Found requested BSSID */
1027 found_bss
= iter_bss
;
1031 if (SCAN_RSSI(iter_bss
->rssi
) > bestrssi
) {
1032 bestrssi
= SCAN_RSSI(iter_bss
->rssi
);
1033 found_bss
= iter_bss
;
1038 if (SCAN_RSSI(iter_bss
->rssi
) > bestrssi
) {
1039 bestrssi
= SCAN_RSSI(iter_bss
->rssi
);
1040 found_bss
= iter_bss
;
1047 mutex_unlock(&priv
->lock
);
1048 lbs_deb_leave_args(LBS_DEB_SCAN
, "found_bss %p", found_bss
);
1053 * @brief This function finds the best SSID in the Scan List
1055 * Search the scan table for the best SSID that also matches the current
1056 * adapter network preference (infrastructure or adhoc)
1058 * @param priv A pointer to struct lbs_private
1060 * @return index in BSSID list
1062 static struct bss_descriptor
*lbs_find_best_ssid_in_list(
1063 struct lbs_private
*priv
,
1067 struct bss_descriptor
* iter_bss
;
1068 struct bss_descriptor
* best_bss
= NULL
;
1070 lbs_deb_enter(LBS_DEB_SCAN
);
1072 mutex_lock(&priv
->lock
);
1074 list_for_each_entry (iter_bss
, &priv
->network_list
, list
) {
1078 if (!is_network_compatible(priv
, iter_bss
, mode
))
1080 if (SCAN_RSSI(iter_bss
->rssi
) <= bestrssi
)
1082 bestrssi
= SCAN_RSSI(iter_bss
->rssi
);
1083 best_bss
= iter_bss
;
1087 if (SCAN_RSSI(iter_bss
->rssi
) <= bestrssi
)
1089 bestrssi
= SCAN_RSSI(iter_bss
->rssi
);
1090 best_bss
= iter_bss
;
1095 mutex_unlock(&priv
->lock
);
1096 lbs_deb_leave_args(LBS_DEB_SCAN
, "best_bss %p", best_bss
);
1101 * @brief Find the AP with specific ssid in the scan list
1103 * Used from association worker.
1105 * @param priv A pointer to struct lbs_private structure
1106 * @param pSSID A pointer to AP's ssid
1108 * @return 0--success, otherwise--fail
1110 int lbs_find_best_network_ssid(struct lbs_private
*priv
,
1111 u8
*out_ssid
, u8
*out_ssid_len
, u8 preferred_mode
, u8
*out_mode
)
1114 struct bss_descriptor
* found
;
1116 lbs_deb_enter(LBS_DEB_SCAN
);
1118 lbs_scan_networks(priv
, NULL
, 1);
1119 if (priv
->surpriseremoved
)
1122 found
= lbs_find_best_ssid_in_list(priv
, preferred_mode
);
1123 if (found
&& (found
->ssid_len
> 0)) {
1124 memcpy(out_ssid
, &found
->ssid
, IW_ESSID_MAX_SIZE
);
1125 *out_ssid_len
= found
->ssid_len
;
1126 *out_mode
= found
->mode
;
1131 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
1137 * @brief Send a scan command for all available channels filtered on a spec
1139 * Used in association code and from debugfs
1141 * @param priv A pointer to struct lbs_private structure
1142 * @param ssid A pointer to the SSID to scan for
1143 * @param ssid_len Length of the SSID
1144 * @param clear_ssid Should existing scan results with this SSID
1147 * @return 0-success, otherwise fail
1149 int lbs_send_specific_ssid_scan(struct lbs_private
*priv
,
1150 u8
*ssid
, u8 ssid_len
, u8 clear_ssid
)
1152 struct lbs_ioctl_user_scan_cfg scancfg
;
1155 lbs_deb_enter_args(LBS_DEB_SCAN
, "SSID '%s', clear %d",
1156 escape_essid(ssid
, ssid_len
), clear_ssid
);
1161 memset(&scancfg
, 0x00, sizeof(scancfg
));
1162 memcpy(scancfg
.ssid
, ssid
, ssid_len
);
1163 scancfg
.ssid_len
= ssid_len
;
1164 scancfg
.clear_ssid
= clear_ssid
;
1166 lbs_scan_networks(priv
, &scancfg
, 1);
1167 if (priv
->surpriseremoved
) {
1173 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
1180 /*********************************************************************/
1182 /* Support for Wireless Extensions */
1184 /*********************************************************************/
1187 #define MAX_CUSTOM_LEN 64
1189 static inline char *lbs_translate_scan(struct lbs_private
*priv
,
1190 char *start
, char *stop
,
1191 struct bss_descriptor
*bss
)
1193 struct chan_freq_power
*cfp
;
1194 char *current_val
; /* For rates */
1195 struct iw_event iwe
; /* Temporary buffer */
1197 #define PERFECT_RSSI ((u8)50)
1198 #define WORST_RSSI ((u8)0)
1199 #define RSSI_DIFF ((u8)(PERFECT_RSSI - WORST_RSSI))
1202 lbs_deb_enter(LBS_DEB_SCAN
);
1204 cfp
= lbs_find_cfp_by_band_and_channel(priv
, 0, bss
->channel
);
1206 lbs_deb_scan("Invalid channel number %d\n", bss
->channel
);
1211 /* First entry *MUST* be the BSSID */
1212 iwe
.cmd
= SIOCGIWAP
;
1213 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1214 memcpy(iwe
.u
.ap_addr
.sa_data
, &bss
->bssid
, ETH_ALEN
);
1215 start
= iwe_stream_add_event(start
, stop
, &iwe
, IW_EV_ADDR_LEN
);
1218 iwe
.cmd
= SIOCGIWESSID
;
1219 iwe
.u
.data
.flags
= 1;
1220 iwe
.u
.data
.length
= min((u32
) bss
->ssid_len
, (u32
) IW_ESSID_MAX_SIZE
);
1221 start
= iwe_stream_add_point(start
, stop
, &iwe
, bss
->ssid
);
1224 iwe
.cmd
= SIOCGIWMODE
;
1225 iwe
.u
.mode
= bss
->mode
;
1226 start
= iwe_stream_add_event(start
, stop
, &iwe
, IW_EV_UINT_LEN
);
1229 iwe
.cmd
= SIOCGIWFREQ
;
1230 iwe
.u
.freq
.m
= (long)cfp
->freq
* 100000;
1232 start
= iwe_stream_add_event(start
, stop
, &iwe
, IW_EV_FREQ_LEN
);
1234 /* Add quality statistics */
1236 iwe
.u
.qual
.updated
= IW_QUAL_ALL_UPDATED
;
1237 iwe
.u
.qual
.level
= SCAN_RSSI(bss
->rssi
);
1239 rssi
= iwe
.u
.qual
.level
- MRVDRV_NF_DEFAULT_SCAN_VALUE
;
1241 (100 * RSSI_DIFF
* RSSI_DIFF
- (PERFECT_RSSI
- rssi
) *
1242 (15 * (RSSI_DIFF
) + 62 * (PERFECT_RSSI
- rssi
))) /
1243 (RSSI_DIFF
* RSSI_DIFF
);
1244 if (iwe
.u
.qual
.qual
> 100)
1245 iwe
.u
.qual
.qual
= 100;
1247 if (priv
->NF
[TYPE_BEACON
][TYPE_NOAVG
] == 0) {
1248 iwe
.u
.qual
.noise
= MRVDRV_NF_DEFAULT_SCAN_VALUE
;
1251 CAL_NF(priv
->NF
[TYPE_BEACON
][TYPE_NOAVG
]);
1254 /* Locally created ad-hoc BSSs won't have beacons if this is the
1255 * only station in the adhoc network; so get signal strength
1256 * from receive statistics.
1258 if ((priv
->mode
== IW_MODE_ADHOC
)
1259 && priv
->adhoccreate
1260 && !lbs_ssid_cmp(priv
->curbssparams
.ssid
,
1261 priv
->curbssparams
.ssid_len
,
1262 bss
->ssid
, bss
->ssid_len
)) {
1264 snr
= priv
->SNR
[TYPE_RXPD
][TYPE_AVG
] / AVG_SCALE
;
1265 nf
= priv
->NF
[TYPE_RXPD
][TYPE_AVG
] / AVG_SCALE
;
1266 iwe
.u
.qual
.level
= CAL_RSSI(snr
, nf
);
1268 start
= iwe_stream_add_event(start
, stop
, &iwe
, IW_EV_QUAL_LEN
);
1270 /* Add encryption capability */
1271 iwe
.cmd
= SIOCGIWENCODE
;
1272 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
) {
1273 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
1275 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
1277 iwe
.u
.data
.length
= 0;
1278 start
= iwe_stream_add_point(start
, stop
, &iwe
, bss
->ssid
);
1280 current_val
= start
+ IW_EV_LCP_LEN
;
1282 iwe
.cmd
= SIOCGIWRATE
;
1283 iwe
.u
.bitrate
.fixed
= 0;
1284 iwe
.u
.bitrate
.disabled
= 0;
1285 iwe
.u
.bitrate
.value
= 0;
1287 for (j
= 0; bss
->rates
[j
] && (j
< sizeof(bss
->rates
)); j
++) {
1288 /* Bit rate given in 500 kb/s units */
1289 iwe
.u
.bitrate
.value
= bss
->rates
[j
] * 500000;
1290 current_val
= iwe_stream_add_value(start
, current_val
,
1291 stop
, &iwe
, IW_EV_PARAM_LEN
);
1293 if ((bss
->mode
== IW_MODE_ADHOC
)
1294 && !lbs_ssid_cmp(priv
->curbssparams
.ssid
,
1295 priv
->curbssparams
.ssid_len
,
1296 bss
->ssid
, bss
->ssid_len
)
1297 && priv
->adhoccreate
) {
1298 iwe
.u
.bitrate
.value
= 22 * 500000;
1299 current_val
= iwe_stream_add_value(start
, current_val
,
1300 stop
, &iwe
, IW_EV_PARAM_LEN
);
1302 /* Check if we added any event */
1303 if((current_val
- start
) > IW_EV_LCP_LEN
)
1304 start
= current_val
;
1306 memset(&iwe
, 0, sizeof(iwe
));
1307 if (bss
->wpa_ie_len
) {
1308 char buf
[MAX_WPA_IE_LEN
];
1309 memcpy(buf
, bss
->wpa_ie
, bss
->wpa_ie_len
);
1310 iwe
.cmd
= IWEVGENIE
;
1311 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
1312 start
= iwe_stream_add_point(start
, stop
, &iwe
, buf
);
1315 memset(&iwe
, 0, sizeof(iwe
));
1316 if (bss
->rsn_ie_len
) {
1317 char buf
[MAX_WPA_IE_LEN
];
1318 memcpy(buf
, bss
->rsn_ie
, bss
->rsn_ie_len
);
1319 iwe
.cmd
= IWEVGENIE
;
1320 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
1321 start
= iwe_stream_add_point(start
, stop
, &iwe
, buf
);
1325 char custom
[MAX_CUSTOM_LEN
];
1328 iwe
.cmd
= IWEVCUSTOM
;
1329 p
+= snprintf(p
, MAX_CUSTOM_LEN
- (p
- custom
),
1331 iwe
.u
.data
.length
= p
- custom
;
1332 if (iwe
.u
.data
.length
)
1333 start
= iwe_stream_add_point(start
, stop
, &iwe
, custom
);
1337 lbs_deb_leave_args(LBS_DEB_SCAN
, "start %p", start
);
1343 * @brief Handle Scan Network ioctl
1345 * @param dev A pointer to net_device structure
1346 * @param info A pointer to iw_request_info structure
1347 * @param vwrq A pointer to iw_param structure
1348 * @param extra A pointer to extra data buf
1350 * @return 0 --success, otherwise fail
1352 int lbs_set_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1353 struct iw_param
*wrqu
, char *extra
)
1355 struct lbs_private
*priv
= dev
->priv
;
1357 lbs_deb_enter(LBS_DEB_SCAN
);
1359 if (!netif_running(dev
))
1362 /* mac80211 does this:
1363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1364 if (sdata->type != IEEE80211_IF_TYPE_xxx)
1367 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
1368 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1369 req = (struct iw_scan_req *)extra;
1371 ssid_len = req->essid_len;
1375 if (!delayed_work_pending(&priv
->scan_work
))
1376 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
1377 msecs_to_jiffies(50));
1378 /* set marker that currently a scan is taking place */
1379 priv
->last_scanned_channel
= -1;
1381 if (priv
->surpriseremoved
)
1384 lbs_deb_leave(LBS_DEB_SCAN
);
1390 * @brief Handle Retrieve scan table ioctl
1392 * @param dev A pointer to net_device structure
1393 * @param info A pointer to iw_request_info structure
1394 * @param dwrq A pointer to iw_point structure
1395 * @param extra A pointer to extra data buf
1397 * @return 0 --success, otherwise fail
1399 int lbs_get_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1400 struct iw_point
*dwrq
, char *extra
)
1402 #define SCAN_ITEM_SIZE 128
1403 struct lbs_private
*priv
= dev
->priv
;
1406 char *stop
= ev
+ dwrq
->length
;
1407 struct bss_descriptor
* iter_bss
;
1408 struct bss_descriptor
* safe
;
1410 lbs_deb_enter(LBS_DEB_SCAN
);
1412 /* iwlist should wait until the current scan is finished */
1413 if (priv
->last_scanned_channel
)
1416 /* Update RSSI if current BSS is a locally created ad-hoc BSS */
1417 if ((priv
->mode
== IW_MODE_ADHOC
) && priv
->adhoccreate
) {
1418 lbs_prepare_and_send_command(priv
, CMD_802_11_RSSI
, 0,
1419 CMD_OPTION_WAITFORRSP
, 0, NULL
);
1422 mutex_lock(&priv
->lock
);
1423 list_for_each_entry_safe (iter_bss
, safe
, &priv
->network_list
, list
) {
1425 unsigned long stale_time
;
1427 if (stop
- ev
< SCAN_ITEM_SIZE
) {
1432 /* For mesh device, list only mesh networks */
1433 if (dev
== priv
->mesh_dev
&& !iter_bss
->mesh
)
1436 /* Prune old an old scan result */
1437 stale_time
= iter_bss
->last_scanned
+ DEFAULT_MAX_SCAN_AGE
;
1438 if (time_after(jiffies
, stale_time
)) {
1439 list_move_tail (&iter_bss
->list
,
1440 &priv
->network_free_list
);
1441 clear_bss_descriptor(iter_bss
);
1445 /* Translate to WE format this entry */
1446 next_ev
= lbs_translate_scan(priv
, ev
, stop
, iter_bss
);
1447 if (next_ev
== NULL
)
1451 mutex_unlock(&priv
->lock
);
1453 dwrq
->length
= (ev
- extra
);
1456 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", err
);
1463 /*********************************************************************/
1465 /* Command execution */
1467 /*********************************************************************/
1471 * @brief Prepare a scan command to be sent to the firmware
1473 * Called via lbs_prepare_and_send_command(priv, CMD_802_11_SCAN, ...)
1476 * Sends a fixed length data part (specifying the BSS type and BSSID filters)
1477 * as well as a variable number/length of TLVs to the firmware.
1479 * @param priv A pointer to struct lbs_private structure
1480 * @param cmd A pointer to cmd_ds_command structure to be sent to
1481 * firmware with the cmd_DS_801_11_SCAN structure
1482 * @param pdata_buf Void pointer cast of a lbs_scan_cmd_config struct used
1483 * to set the fields/TLVs for the command sent to firmware
1487 int lbs_cmd_80211_scan(struct lbs_private
*priv
,
1488 struct cmd_ds_command
*cmd
, void *pdata_buf
)
1490 struct cmd_ds_802_11_scan
*pscan
= &cmd
->params
.scan
;
1491 struct lbs_scan_cmd_config
*pscancfg
= pdata_buf
;
1493 lbs_deb_enter(LBS_DEB_SCAN
);
1495 /* Set fixed field variables in scan command */
1496 pscan
->bsstype
= pscancfg
->bsstype
;
1497 memcpy(pscan
->bssid
, pscancfg
->bssid
, ETH_ALEN
);
1498 memcpy(pscan
->tlvbuffer
, pscancfg
->tlvbuffer
, pscancfg
->tlvbufferlen
);
1500 /* size is equal to the sizeof(fixed portions) + the TLV len + header */
1501 cmd
->size
= cpu_to_le16(sizeof(pscan
->bsstype
) + ETH_ALEN
1502 + pscancfg
->tlvbufferlen
+ S_DS_GEN
);
1504 lbs_deb_leave(LBS_DEB_SCAN
);
1509 * @brief This function handles the command response of scan
1511 * Called from handle_cmd_response() in cmdrespc.
1513 * The response buffer for the scan command has the following
1516 * .-----------------------------------------------------------.
1517 * | header (4 * sizeof(u16)): Standard command response hdr |
1518 * .-----------------------------------------------------------.
1519 * | bufsize (u16) : sizeof the BSS Description data |
1520 * .-----------------------------------------------------------.
1521 * | NumOfSet (u8) : Number of BSS Descs returned |
1522 * .-----------------------------------------------------------.
1523 * | BSSDescription data (variable, size given in bufsize) |
1524 * .-----------------------------------------------------------.
1525 * | TLV data (variable, size calculated using header->size, |
1526 * | bufsize and sizeof the fixed fields above) |
1527 * .-----------------------------------------------------------.
1529 * @param priv A pointer to struct lbs_private structure
1530 * @param resp A pointer to cmd_ds_command
1534 int lbs_ret_80211_scan(struct lbs_private
*priv
, struct cmd_ds_command
*resp
)
1536 struct cmd_ds_802_11_scan_rsp
*pscan
;
1537 struct bss_descriptor
* iter_bss
;
1538 struct bss_descriptor
* safe
;
1546 lbs_deb_enter(LBS_DEB_SCAN
);
1548 /* Prune old entries from scan table */
1549 list_for_each_entry_safe (iter_bss
, safe
, &priv
->network_list
, list
) {
1550 unsigned long stale_time
= iter_bss
->last_scanned
+ DEFAULT_MAX_SCAN_AGE
;
1551 if (time_before(jiffies
, stale_time
))
1553 list_move_tail (&iter_bss
->list
, &priv
->network_free_list
);
1554 clear_bss_descriptor(iter_bss
);
1557 pscan
= &resp
->params
.scanresp
;
1559 if (pscan
->nr_sets
> MAX_NETWORK_COUNT
) {
1561 "SCAN_RESP: too many scan results (%d, max %d)!!\n",
1562 pscan
->nr_sets
, MAX_NETWORK_COUNT
);
1567 bytesleft
= le16_to_cpu(pscan
->bssdescriptsize
);
1568 lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft
);
1570 scanrespsize
= le16_to_cpu(resp
->size
);
1571 lbs_deb_scan("SCAN_RESP: scan results %d\n", pscan
->nr_sets
);
1573 pbssinfo
= pscan
->bssdesc_and_tlvbuffer
;
1575 /* The size of the TLV buffer is equal to the entire command response
1576 * size (scanrespsize) minus the fixed fields (sizeof()'s), the
1577 * BSS Descriptions (bssdescriptsize as bytesLef) and the command
1578 * response header (S_DS_GEN)
1580 tlvbufsize
= scanrespsize
- (bytesleft
+ sizeof(pscan
->bssdescriptsize
)
1581 + sizeof(pscan
->nr_sets
)
1585 * Process each scan response returned (pscan->nr_sets). Save
1586 * the information in the newbssentry and then insert into the
1587 * driver scan table either as an update to an existing entry
1588 * or as an addition at the end of the table
1590 for (idx
= 0; idx
< pscan
->nr_sets
&& bytesleft
; idx
++) {
1591 struct bss_descriptor
new;
1592 struct bss_descriptor
* found
= NULL
;
1593 struct bss_descriptor
* oldest
= NULL
;
1594 DECLARE_MAC_BUF(mac
);
1596 /* Process the data fields and IEs returned for this BSS */
1597 memset(&new, 0, sizeof (struct bss_descriptor
));
1598 if (lbs_process_bss(&new, &pbssinfo
, &bytesleft
) != 0) {
1599 /* error parsing the scan response, skipped */
1600 lbs_deb_scan("SCAN_RESP: process_bss returned ERROR\n");
1604 /* Try to find this bss in the scan table */
1605 list_for_each_entry (iter_bss
, &priv
->network_list
, list
) {
1606 if (is_same_network(iter_bss
, &new)) {
1611 if ((oldest
== NULL
) ||
1612 (iter_bss
->last_scanned
< oldest
->last_scanned
))
1617 /* found, clear it */
1618 clear_bss_descriptor(found
);
1619 } else if (!list_empty(&priv
->network_free_list
)) {
1620 /* Pull one from the free list */
1621 found
= list_entry(priv
->network_free_list
.next
,
1622 struct bss_descriptor
, list
);
1623 list_move_tail(&found
->list
, &priv
->network_list
);
1624 } else if (oldest
) {
1625 /* If there are no more slots, expire the oldest */
1627 clear_bss_descriptor(found
);
1628 list_move_tail(&found
->list
, &priv
->network_list
);
1633 lbs_deb_scan("SCAN_RESP: BSSID %s\n",
1634 print_mac(mac
, new.bssid
));
1636 /* Copy the locally created newbssentry to the scan table */
1637 memcpy(found
, &new, offsetof(struct bss_descriptor
, list
));
1643 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);