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>
12 #include <net/ieee80211.h>
13 #include <net/iw_handler.h>
20 //! Approximate amount of data needed to pass a scan result back to iwlist
21 #define MAX_SCAN_CELL_SIZE (IW_EV_ADDR_LEN \
28 + 40) /* 40 for WPAIE */
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)))
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))
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) \
44 //! The maximum number of channels the firmware can scan per command
45 #define MRVDRV_MAX_CHANNELS_PER_SCAN 14
48 * @brief Number of channels to scan per firmware scan command issuance.
50 * Number restricted to prevent hitting the limit on the amount of scan data
51 * returned in a single firmware scan command.
53 #define MRVDRV_CHANNELS_PER_SCAN_CMD 4
55 //! Scan time specified in the channel TLV for each channel for passive scans
56 #define MRVDRV_PASSIVE_SCAN_CHAN_TIME 100
58 //! Scan time specified in the channel TLV for each channel for active scans
59 #define MRVDRV_ACTIVE_SCAN_CHAN_TIME 100
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)
65 #define CHECK_SSID_IS_VALID(x) 1
69 * @brief Check if a scanned network compatible with the driver settings
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
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
85 * @return Index in scantable, or error code if negative
87 static int is_network_compatible(wlan_adapter * adapter, int index, u8 mode)
91 if (adapter->scantable[index].mode == mode) {
92 if ( !adapter->secinfo.wep_enabled
93 && !adapter->secinfo.WPAenabled
94 && !adapter->secinfo.WPA2enabled
95 && adapter->scantable[index].wpa_ie[0] != WPA_IE
96 && adapter->scantable[index].rsn_ie[0] != WPA2_IE
97 && !adapter->scantable[index].privacy) {
101 } else if ( adapter->secinfo.wep_enabled
102 && !adapter->secinfo.WPAenabled
103 && !adapter->secinfo.WPA2enabled
104 && adapter->scantable[index].privacy) {
105 /* static WEP enabled */
108 } else if ( !adapter->secinfo.wep_enabled
109 && adapter->secinfo.WPAenabled
110 && !adapter->secinfo.WPA2enabled
111 && (adapter->scantable[index].wpa_ie[0] == WPA_IE)
112 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
113 && adapter->scantable[index].privacy */
117 "is_network_compatible() WPA: index=%d wpa_ie=%#x "
118 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
119 "privacy=%#x\n", index,
120 adapter->scantable[index].wpa_ie[0],
121 adapter->scantable[index].rsn_ie[0],
122 adapter->secinfo.wep_enabled ? "e" : "d",
123 adapter->secinfo.WPAenabled ? "e" : "d",
124 adapter->secinfo.WPA2enabled ? "e" : "d",
125 adapter->scantable[index].privacy);
128 } else if ( !adapter->secinfo.wep_enabled
129 && !adapter->secinfo.WPAenabled
130 && adapter->secinfo.WPA2enabled
131 && (adapter->scantable[index].rsn_ie[0] == WPA2_IE)
132 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
133 && adapter->scantable[index].privacy */
137 "is_network_compatible() WPA2: index=%d wpa_ie=%#x "
138 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
139 "privacy=%#x\n", index,
140 adapter->scantable[index].wpa_ie[0],
141 adapter->scantable[index].rsn_ie[0],
142 adapter->secinfo.wep_enabled ? "e" : "d",
143 adapter->secinfo.WPAenabled ? "e" : "d",
144 adapter->secinfo.WPA2enabled ? "e" : "d",
145 adapter->scantable[index].privacy);
148 } else if ( !adapter->secinfo.wep_enabled
149 && !adapter->secinfo.WPAenabled
150 && !adapter->secinfo.WPA2enabled
151 && (adapter->scantable[index].wpa_ie[0] != WPA_IE)
152 && (adapter->scantable[index].rsn_ie[0] != WPA2_IE)
153 && adapter->scantable[index].privacy) {
154 /* dynamic WEP enabled */
156 "is_network_compatible() dynamic WEP: index=%d "
157 "wpa_ie=%#x wpa2_ie=%#x privacy=%#x\n",
159 adapter->scantable[index].wpa_ie[0],
160 adapter->scantable[index].rsn_ie[0],
161 adapter->scantable[index].privacy);
166 /* security doesn't match */
168 "is_network_compatible() FAILED: index=%d wpa_ie=%#x "
169 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s privacy=%#x\n",
171 adapter->scantable[index].wpa_ie[0],
172 adapter->scantable[index].rsn_ie[0],
173 adapter->secinfo.wep_enabled ? "e" : "d",
174 adapter->secinfo.WPAenabled ? "e" : "d",
175 adapter->secinfo.WPA2enabled ? "e" : "d",
176 adapter->scantable[index].privacy);
178 return -ECONNREFUSED;
181 /* mode doesn't match */
187 * @brief This function validates a SSID as being able to be printed
189 * @param pssid SSID structure to validate
191 * @return TRUE or FALSE
193 static u8 ssid_valid(struct WLAN_802_11_SSID *pssid)
197 for (ssididx = 0; ssididx < pssid->ssidlength; ssididx++) {
198 if (!isprint(pssid->ssid[ssididx])) {
207 * @brief Post process the scan table after a new scan command has completed
209 * Inspect each entry of the scan table and try to find an entry that
210 * matches our current associated/joined network from the scan. If
211 * one is found, update the stored copy of the bssdescriptor for our
214 * Debug dump the current scan table contents if compiled accordingly.
216 * @param priv A pointer to wlan_private structure
220 static void wlan_scan_process_results(wlan_private * priv)
222 wlan_adapter *adapter = priv->adapter;
228 if (adapter->connect_status == libertas_connected) {
229 /* try to find the current BSSID in the new scan list */
230 for (i = 0; i < adapter->numinscantable; i++) {
231 if (!libertas_SSID_cmp(&adapter->scantable[i].ssid,
232 &adapter->curbssparams.ssid) &&
233 !memcmp(adapter->curbssparams.bssid,
234 adapter->scantable[i].macaddress,
241 /* Make a copy of current BSSID descriptor */
242 memcpy(&adapter->curbssparams.bssdescriptor,
243 &adapter->scantable[i],
244 sizeof(adapter->curbssparams.bssdescriptor));
248 for (i = 0; i < adapter->numinscantable; i++) {
249 lbs_pr_debug(1, "Scan:(%02d) %02x:%02x:%02x:%02x:%02x:%02x, "
250 "RSSI[%03d], SSID[%s]\n",
252 adapter->scantable[i].macaddress[0],
253 adapter->scantable[i].macaddress[1],
254 adapter->scantable[i].macaddress[2],
255 adapter->scantable[i].macaddress[3],
256 adapter->scantable[i].macaddress[4],
257 adapter->scantable[i].macaddress[5],
258 (s32) adapter->scantable[i].rssi,
259 adapter->scantable[i].ssid.ssid);
264 * @brief Create a channel list for the driver to scan based on region info
266 * Use the driver region/band information to construct a comprehensive list
267 * of channels to scan. This routine is used for any scan that is not
268 * provided a specific channel list to scan.
270 * @param priv A pointer to wlan_private structure
271 * @param scanchanlist Output parameter: resulting channel list to scan
272 * @param filteredscan Flag indicating whether or not a BSSID or SSID filter
273 * is being sent in the command to firmware. Used to
274 * increase the number of channels sent in a scan
275 * command and to disable the firmware channel scan
280 static void wlan_scan_create_channel_list(wlan_private * priv,
281 struct chanscanparamset * scanchanlist,
285 wlan_adapter *adapter = priv->adapter;
286 struct region_channel *scanregion;
287 struct chan_freq_power *cfp;
295 /* Set the default scan type to the user specified type, will later
296 * be changed to passive on a per channel basis if restricted by
297 * regulatory requirements (11d or 11h)
299 scantype = adapter->scantype;
301 for (rgnidx = 0; rgnidx < ARRAY_SIZE(adapter->region_channel); rgnidx++) {
302 if (priv->adapter->enable11d &&
303 adapter->connect_status != libertas_connected) {
304 /* Scan all the supported chan for the first scan */
305 if (!adapter->universal_channel[rgnidx].valid)
307 scanregion = &adapter->universal_channel[rgnidx];
309 /* clear the parsed_region_chan for the first scan */
310 memset(&adapter->parsed_region_chan, 0x00,
311 sizeof(adapter->parsed_region_chan));
313 if (!adapter->region_channel[rgnidx].valid)
315 scanregion = &adapter->region_channel[rgnidx];
319 nextchan < scanregion->nrcfp; nextchan++, chanidx++) {
321 cfp = scanregion->CFP + nextchan;
323 if (priv->adapter->enable11d) {
325 libertas_get_scan_type_11d(cfp->channel,
330 switch (scanregion->band) {
334 scanchanlist[chanidx].radiotype =
335 cmd_scan_radio_type_bg;
339 if (scantype == cmd_scan_type_passive) {
340 scanchanlist[chanidx].maxscantime =
342 (MRVDRV_PASSIVE_SCAN_CHAN_TIME);
343 scanchanlist[chanidx].chanscanmode.passivescan =
346 scanchanlist[chanidx].maxscantime =
348 (MRVDRV_ACTIVE_SCAN_CHAN_TIME);
349 scanchanlist[chanidx].chanscanmode.passivescan =
353 scanchanlist[chanidx].channumber = cfp->channel;
356 scanchanlist[chanidx].chanscanmode.
364 * @brief Construct a wlan_scan_cmd_config structure to use in issue scan cmds
366 * Application layer or other functions can invoke wlan_scan_networks
367 * with a scan configuration supplied in a wlan_ioctl_user_scan_cfg struct.
368 * This structure is used as the basis of one or many wlan_scan_cmd_config
369 * commands that are sent to the command processing module and sent to
372 * Create a wlan_scan_cmd_config based on the following user supplied
373 * parameters (if present):
376 * - Number of Probes to be sent
379 * If the SSID or BSSID filter is not present, disable/clear the filter.
380 * If the number of probes is not set, use the adapter default setting
381 * Qualify the channel
383 * @param priv A pointer to wlan_private structure
384 * @param puserscanin NULL or pointer to scan configuration parameters
385 * @param ppchantlvout Output parameter: Pointer to the start of the
386 * channel TLV portion of the output scan config
387 * @param pscanchanlist Output parameter: Pointer to the resulting channel
389 * @param pmaxchanperscan Output parameter: Number of channels to scan for
390 * each issuance of the firmware scan command
391 * @param pfilteredscan Output parameter: Flag indicating whether or not
392 * a BSSID or SSID filter is being sent in the
393 * command to firmware. Used to increase the number
394 * of channels sent in a scan command and to
395 * disable the firmware channel scan filter.
396 * @param pscancurrentonly Output parameter: Flag indicating whether or not
397 * we are only scanning our current active channel
399 * @return resulting scan configuration
401 static struct wlan_scan_cmd_config *
402 wlan_scan_setup_scan_config(wlan_private * priv,
403 const struct wlan_ioctl_user_scan_cfg * puserscanin,
404 struct mrvlietypes_chanlistparamset ** ppchantlvout,
405 struct chanscanparamset * pscanchanlist,
406 int *pmaxchanperscan,
408 u8 * pscancurrentonly)
410 wlan_adapter *adapter = priv->adapter;
411 const u8 zeromac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
412 struct mrvlietypes_numprobes *pnumprobestlv;
413 struct mrvlietypes_ssidparamset *pssidtlv;
414 struct wlan_scan_cmd_config * pscancfgout = NULL;
424 pscancfgout = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL);
425 if (pscancfgout == NULL)
428 /* The tlvbufferlen is calculated for each scan command. The TLVs added
429 * in this routine will be preserved since the routine that sends
430 * the command will append channelTLVs at *ppchantlvout. The difference
431 * between the *ppchantlvout and the tlvbuffer start will be used
432 * to calculate the size of anything we add in this routine.
434 pscancfgout->tlvbufferlen = 0;
436 /* Running tlv pointer. Assigned to ppchantlvout at end of function
437 * so later routines know where channels can be added to the command buf
439 ptlvpos = pscancfgout->tlvbuffer;
442 * Set the initial scan paramters for progressive scanning. If a specific
443 * BSSID or SSID is used, the number of channels in the scan command
444 * will be increased to the absolute maximum
446 *pmaxchanperscan = MRVDRV_CHANNELS_PER_SCAN_CMD;
448 /* Initialize the scan as un-filtered by firmware, set to TRUE below if
449 * a SSID or BSSID filter is sent in the command
453 /* Initialize the scan as not being only on the current channel. If
454 * the channel list is customized, only contains one channel, and
455 * is the active channel, this is set true and data flow is not halted.
457 *pscancurrentonly = 0;
461 /* Set the bss type scan filter, use adapter setting if unset */
462 pscancfgout->bsstype =
463 (puserscanin->bsstype ? puserscanin->bsstype : adapter->
466 /* Set the number of probes to send, use adapter setting if unset */
467 numprobes = (puserscanin->numprobes ? puserscanin->numprobes :
468 adapter->scanprobes);
471 * Set the BSSID filter to the incoming configuration,
472 * if non-zero. If not set, it will remain disabled (all zeros).
474 memcpy(pscancfgout->specificBSSID,
475 puserscanin->specificBSSID,
476 sizeof(pscancfgout->specificBSSID));
478 ssidlen = strlen(puserscanin->specificSSID);
482 (struct mrvlietypes_ssidparamset *) pscancfgout->
484 pssidtlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
485 pssidtlv->header.len = cpu_to_le16(ssidlen);
486 memcpy(pssidtlv->ssid, puserscanin->specificSSID,
488 ptlvpos += sizeof(pssidtlv->header) + ssidlen;
492 * The default number of channels sent in the command is low to
493 * ensure the response buffer from the firmware does not truncate
494 * scan results. That is not an issue with an SSID or BSSID
495 * filter applied to the scan results in the firmware.
497 if (ssidlen || (memcmp(pscancfgout->specificBSSID,
498 &zeromac, sizeof(zeromac)) != 0)) {
499 *pmaxchanperscan = MRVDRV_MAX_CHANNELS_PER_SCAN;
503 pscancfgout->bsstype = adapter->scanmode;
504 numprobes = adapter->scanprobes;
507 /* If the input config or adapter has the number of Probes set, add tlv */
509 pnumprobestlv = (struct mrvlietypes_numprobes *) ptlvpos;
510 pnumprobestlv->header.type =
511 cpu_to_le16(TLV_TYPE_NUMPROBES);
512 pnumprobestlv->header.len = sizeof(pnumprobestlv->numprobes);
513 pnumprobestlv->numprobes = cpu_to_le16(numprobes);
516 sizeof(pnumprobestlv->header) + pnumprobestlv->header.len;
518 pnumprobestlv->header.len =
519 cpu_to_le16(pnumprobestlv->header.len);
523 * Set the output for the channel TLV to the address in the tlv buffer
524 * past any TLVs that were added in this fuction (SSID, numprobes).
525 * channel TLVs will be added past this for each scan command, preserving
526 * the TLVs that were previously added.
528 *ppchantlvout = (struct mrvlietypes_chanlistparamset *) ptlvpos;
530 if (puserscanin && puserscanin->chanlist[0].channumber) {
532 lbs_pr_debug(1, "Scan: Using supplied channel list\n");
535 chanidx < WLAN_IOCTL_USER_SCAN_CHAN_MAX
536 && puserscanin->chanlist[chanidx].channumber; chanidx++) {
538 channel = puserscanin->chanlist[chanidx].channumber;
539 (pscanchanlist + chanidx)->channumber = channel;
541 radiotype = puserscanin->chanlist[chanidx].radiotype;
542 (pscanchanlist + chanidx)->radiotype = radiotype;
544 scantype = puserscanin->chanlist[chanidx].scantype;
546 if (scantype == cmd_scan_type_passive) {
548 chanidx)->chanscanmode.passivescan = 1;
551 chanidx)->chanscanmode.passivescan = 0;
554 if (puserscanin->chanlist[chanidx].scantime) {
556 puserscanin->chanlist[chanidx].scantime;
558 if (scantype == cmd_scan_type_passive) {
559 scandur = MRVDRV_PASSIVE_SCAN_CHAN_TIME;
561 scandur = MRVDRV_ACTIVE_SCAN_CHAN_TIME;
565 (pscanchanlist + chanidx)->minscantime =
566 cpu_to_le16(scandur);
567 (pscanchanlist + chanidx)->maxscantime =
568 cpu_to_le16(scandur);
571 /* Check if we are only scanning the current channel */
572 if ((chanidx == 1) && (puserscanin->chanlist[0].channumber
574 priv->adapter->curbssparams.channel)) {
575 *pscancurrentonly = 1;
576 lbs_pr_debug(1, "Scan: Scanning current channel only");
580 lbs_pr_debug(1, "Scan: Creating full region channel list\n");
581 wlan_scan_create_channel_list(priv, pscanchanlist,
590 * @brief Construct and send multiple scan config commands to the firmware
592 * Previous routines have created a wlan_scan_cmd_config with any requested
593 * TLVs. This function splits the channel TLV into maxchanperscan lists
594 * and sends the portion of the channel TLV along with the other TLVs
595 * to the wlan_cmd routines for execution in the firmware.
597 * @param priv A pointer to wlan_private structure
598 * @param maxchanperscan Maximum number channels to be included in each
599 * scan command sent to firmware
600 * @param filteredscan Flag indicating whether or not a BSSID or SSID
601 * filter is being used for the firmware command
602 * scan command sent to firmware
603 * @param pscancfgout Scan configuration used for this scan.
604 * @param pchantlvout Pointer in the pscancfgout where the channel TLV
605 * should start. This is past any other TLVs that
606 * must be sent down in each firmware command.
607 * @param pscanchanlist List of channels to scan in maxchanperscan segments
609 * @return 0 or error return otherwise
611 static int wlan_scan_channel_list(wlan_private * priv,
614 struct wlan_scan_cmd_config * pscancfgout,
615 struct mrvlietypes_chanlistparamset * pchantlvout,
616 struct chanscanparamset * pscanchanlist,
617 const struct wlan_ioctl_user_scan_cfg * puserscanin)
619 struct chanscanparamset *ptmpchan;
620 struct chanscanparamset *pstartchan;
626 union iwreq_data wrqu;
630 if (pscancfgout == 0 || pchantlvout == 0 || pscanchanlist == 0) {
631 lbs_pr_debug(1, "Scan: Null detect: %p, %p, %p\n",
632 pscancfgout, pchantlvout, pscanchanlist);
636 pchantlvout->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
638 /* Set the temp channel struct pointer to the start of the desired list */
639 ptmpchan = pscanchanlist;
641 if (priv->adapter->last_scanned_channel && !puserscanin)
642 ptmpchan += priv->adapter->last_scanned_channel;
644 /* Loop through the desired channel list, sending a new firmware scan
645 * commands for each maxchanperscan channels (or for 1,6,11 individually
646 * if configured accordingly)
648 while (ptmpchan->channumber) {
651 pchantlvout->header.len = 0;
652 scanband = ptmpchan->radiotype;
653 pstartchan = ptmpchan;
656 /* Construct the channel TLV for the scan command. Continue to
657 * insert channel TLVs until:
658 * - the tlvidx hits the maximum configured per scan command
659 * - the next channel to insert is 0 (end of desired channel list)
660 * - doneearly is set (controlling individual scanning of 1,6,11)
662 while (tlvidx < maxchanperscan && ptmpchan->channumber
663 && !doneearly && scanned < 2) {
666 "Scan: Chan(%3d), Radio(%d), mode(%d,%d), Dur(%d)\n",
667 ptmpchan->channumber, ptmpchan->radiotype,
668 ptmpchan->chanscanmode.passivescan,
669 ptmpchan->chanscanmode.disablechanfilt,
670 ptmpchan->maxscantime);
672 /* Copy the current channel TLV to the command being prepared */
673 memcpy(pchantlvout->chanscanparam + tlvidx,
674 ptmpchan, sizeof(pchantlvout->chanscanparam));
676 /* Increment the TLV header length by the size appended */
677 pchantlvout->header.len +=
678 sizeof(pchantlvout->chanscanparam);
681 * The tlv buffer length is set to the number of bytes of the
682 * between the channel tlv pointer and the start of the
683 * tlv buffer. This compensates for any TLVs that were appended
684 * before the channel list.
686 pscancfgout->tlvbufferlen = ((u8 *) pchantlvout
687 - pscancfgout->tlvbuffer);
689 /* Add the size of the channel tlv header and the data length */
690 pscancfgout->tlvbufferlen +=
691 (sizeof(pchantlvout->header)
692 + pchantlvout->header.len);
694 /* Increment the index to the channel tlv we are constructing */
699 /* Stop the loop if the *current* channel is in the 1,6,11 set
700 * and we are not filtering on a BSSID or SSID.
702 if (!filteredscan && (ptmpchan->channumber == 1
703 || ptmpchan->channumber == 6
704 || ptmpchan->channumber == 11)) {
708 /* Increment the tmp pointer to the next channel to be scanned */
712 /* Stop the loop if the *next* channel is in the 1,6,11 set.
713 * This will cause it to be the only channel scanned on the next
716 if (!filteredscan && (ptmpchan->channumber == 1
717 || ptmpchan->channumber == 6
718 || ptmpchan->channumber == 11)) {
723 /* Send the scan command to the firmware with the specified cfg */
724 ret = libertas_prepare_and_send_command(priv, cmd_802_11_scan, 0,
727 priv->adapter->last_scanned_channel = ptmpchan->channumber;
733 priv->adapter->last_scanned_channel = ptmpchan->channumber;
735 memset(&wrqu, 0, sizeof(union iwreq_data));
736 wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
743 * @brief Internal function used to start a scan based on an input config
745 * Use the input user scan configuration information when provided in
746 * order to send the appropriate scan commands to firmware to populate or
747 * update the internal driver scan table
749 * @param priv A pointer to wlan_private structure
750 * @param puserscanin Pointer to the input configuration for the requested
753 * @return 0 or < 0 if error
755 int wlan_scan_networks(wlan_private * priv,
756 const struct wlan_ioctl_user_scan_cfg * puserscanin)
758 wlan_adapter *adapter = priv->adapter;
759 struct mrvlietypes_chanlistparamset *pchantlvout;
760 struct chanscanparamset * scan_chan_list = NULL;
761 struct wlan_scan_cmd_config * scan_cfg = NULL;
764 u8 scancurrentchanonly;
770 scan_chan_list = kzalloc(sizeof(struct chanscanparamset) *
771 WLAN_IOCTL_USER_SCAN_CHAN_MAX, GFP_KERNEL);
772 if (scan_chan_list == NULL) {
777 scan_cfg = wlan_scan_setup_scan_config(priv,
783 &scancurrentchanonly);
784 if (scan_cfg == NULL) {
789 keeppreviousscan = 0;
792 keeppreviousscan = puserscanin->keeppreviousscan;
795 if (adapter->last_scanned_channel)
796 keeppreviousscan = 1;
798 if (!keeppreviousscan) {
799 memset(adapter->scantable, 0x00,
800 sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST);
801 adapter->numinscantable = 0;
804 /* Keep the data path active if we are only scanning our current channel */
805 if (!scancurrentchanonly) {
806 netif_stop_queue(priv->wlan_dev.netdev);
807 netif_carrier_off(priv->wlan_dev.netdev);
810 ret = wlan_scan_channel_list(priv,
818 /* Process the resulting scan table:
819 * - Remove any bad ssids
820 * - Update our current BSS information from scan data
822 wlan_scan_process_results(priv);
824 if (priv->adapter->connect_status == libertas_connected) {
825 netif_carrier_on(priv->wlan_dev.netdev);
826 netif_wake_queue(priv->wlan_dev.netdev);
834 kfree(scan_chan_list);
841 * @brief Inspect the scan response buffer for pointers to expected TLVs
843 * TLVs can be included at the end of the scan response BSS information.
844 * Parse the data in the buffer for pointers to TLVs that can potentially
845 * be passed back in the response
847 * @param ptlv Pointer to the start of the TLV buffer to parse
848 * @param tlvbufsize size of the TLV buffer
849 * @param ptsftlv Output parameter: Pointer to the TSF TLV if found
854 void wlan_ret_802_11_scan_get_tlv_ptrs(struct mrvlietypes_data * ptlv,
856 struct mrvlietypes_tsftimestamp ** ptsftlv)
858 struct mrvlietypes_data *pcurrenttlv;
864 tlvbufleft = tlvbufsize;
867 lbs_pr_debug(1, "SCAN_RESP: tlvbufsize = %d\n", tlvbufsize);
868 lbs_dbg_hex("SCAN_RESP: TLV Buf", (u8 *) ptlv, tlvbufsize);
870 while (tlvbufleft >= sizeof(struct mrvlietypesheader)) {
871 tlvtype = le16_to_cpu(pcurrenttlv->header.type);
872 tlvlen = le16_to_cpu(pcurrenttlv->header.len);
875 case TLV_TYPE_TSFTIMESTAMP:
876 *ptsftlv = (struct mrvlietypes_tsftimestamp *) pcurrenttlv;
880 lbs_pr_debug(1, "SCAN_RESP: Unhandled TLV = %d\n",
882 /* Give up, this seems corrupted */
886 tlvbufleft -= (sizeof(ptlv->header) + tlvlen);
888 (struct mrvlietypes_data *) (pcurrenttlv->Data + tlvlen);
893 * @brief Interpret a BSS scan response returned from the firmware
895 * Parse the various fixed fields and IEs passed back for a a BSS probe
896 * response or beacon from the scan command. Record information as needed
897 * in the scan table struct bss_descriptor for that entry.
899 * @param pBSSIDEntry Output parameter: Pointer to the BSS Entry
903 static int InterpretBSSDescriptionWithIE(struct bss_descriptor * pBSSEntry,
904 u8 ** pbeaconinfo, int *bytesleft)
906 enum ieeetypes_elementid elemID;
907 struct ieeetypes_fhparamset *pFH;
908 struct ieeetypes_dsparamset *pDS;
909 struct ieeetypes_cfparamset *pCF;
910 struct ieeetypes_ibssparamset *pibss;
911 struct ieeetypes_capinfo *pcap;
912 struct WLAN_802_11_FIXED_IEs fixedie;
920 int bytesleftforcurrentbeacon;
923 const u8 oui01[4] = { 0x00, 0x50, 0xf2, 0x01 };
925 struct ieeetypes_countryinfoset *pcountryinfo;
933 if (*bytesleft >= sizeof(beaconsize)) {
934 /* Extract & convert beacon size from the command buffer */
935 memcpy(&beaconsize, *pbeaconinfo, sizeof(beaconsize));
936 beaconsize = le16_to_cpu(beaconsize);
937 *bytesleft -= sizeof(beaconsize);
938 *pbeaconinfo += sizeof(beaconsize);
941 if (beaconsize == 0 || beaconsize > *bytesleft) {
943 *pbeaconinfo += *bytesleft;
949 /* Initialize the current working beacon pointer for this BSS iteration */
950 pcurrentptr = *pbeaconinfo;
952 /* Advance the return beacon pointer past the current beacon */
953 *pbeaconinfo += beaconsize;
954 *bytesleft -= beaconsize;
956 bytesleftforcurrentbeacon = beaconsize;
958 memcpy(pBSSEntry->macaddress, pcurrentptr, ETH_ALEN);
959 lbs_pr_debug(1, "InterpretIE: AP MAC Addr-%x:%x:%x:%x:%x:%x\n",
960 pBSSEntry->macaddress[0], pBSSEntry->macaddress[1],
961 pBSSEntry->macaddress[2], pBSSEntry->macaddress[3],
962 pBSSEntry->macaddress[4], pBSSEntry->macaddress[5]);
964 pcurrentptr += ETH_ALEN;
965 bytesleftforcurrentbeacon -= ETH_ALEN;
967 if (bytesleftforcurrentbeacon < 12) {
968 lbs_pr_debug(1, "InterpretIE: Not enough bytes left\n");
973 * next 4 fields are RSSI, time stamp, beacon interval,
974 * and capability information
977 /* RSSI is 1 byte long */
978 pBSSEntry->rssi = le32_to_cpu((long)(*pcurrentptr));
979 lbs_pr_debug(1, "InterpretIE: RSSI=%02X\n", *pcurrentptr);
981 bytesleftforcurrentbeacon -= 1;
983 /* time stamp is 8 bytes long */
984 memcpy(fixedie.timestamp, pcurrentptr, 8);
985 memcpy(pBSSEntry->timestamp, pcurrentptr, 8);
987 bytesleftforcurrentbeacon -= 8;
989 /* beacon interval is 2 bytes long */
990 memcpy(&fixedie.beaconinterval, pcurrentptr, 2);
991 pBSSEntry->beaconperiod = le16_to_cpu(fixedie.beaconinterval);
993 bytesleftforcurrentbeacon -= 2;
995 /* capability information is 2 bytes long */
996 memcpy(&fixedie.capabilities, pcurrentptr, 2);
997 lbs_pr_debug(1, "InterpretIE: fixedie.capabilities=0x%X\n",
998 fixedie.capabilities);
999 fixedie.capabilities = le16_to_cpu(fixedie.capabilities);
1000 pcap = (struct ieeetypes_capinfo *) & fixedie.capabilities;
1001 memcpy(&pBSSEntry->cap, pcap, sizeof(struct ieeetypes_capinfo));
1003 bytesleftforcurrentbeacon -= 2;
1005 /* rest of the current buffer are IE's */
1006 lbs_pr_debug(1, "InterpretIE: IElength for this AP = %d\n",
1007 bytesleftforcurrentbeacon);
1009 lbs_dbg_hex("InterpretIE: IE info", (u8 *) pcurrentptr,
1010 bytesleftforcurrentbeacon);
1012 if (pcap->privacy) {
1013 lbs_pr_debug(1, "InterpretIE: AP WEP enabled\n");
1014 pBSSEntry->privacy = wlan802_11privfilter8021xWEP;
1016 pBSSEntry->privacy = wlan802_11privfilteracceptall;
1019 if (pcap->ibss == 1) {
1020 pBSSEntry->mode = IW_MODE_ADHOC;
1022 pBSSEntry->mode = IW_MODE_INFRA;
1025 /* process variable IE */
1026 while (bytesleftforcurrentbeacon >= 2) {
1027 elemID = (enum ieeetypes_elementid) (*((u8 *) pcurrentptr));
1028 elemlen = *((u8 *) pcurrentptr + 1);
1030 if (bytesleftforcurrentbeacon < elemlen) {
1031 lbs_pr_debug(1, "InterpretIE: error in processing IE, "
1032 "bytes left < IE length\n");
1033 bytesleftforcurrentbeacon = 0;
1040 pBSSEntry->ssid.ssidlength = elemlen;
1041 memcpy(pBSSEntry->ssid.ssid, (pcurrentptr + 2),
1043 lbs_pr_debug(1, "ssid: %32s", pBSSEntry->ssid.ssid);
1046 case SUPPORTED_RATES:
1047 memcpy(pBSSEntry->datarates, (pcurrentptr + 2),
1049 memmove(pBSSEntry->libertas_supported_rates, (pcurrentptr + 2),
1052 founddatarateie = 1;
1056 lbs_pr_debug(1, "InterpretIE: EXTRA_IE Found!\n");
1057 pBSSEntry->extra_ie = 1;
1061 pFH = (struct ieeetypes_fhparamset *) pcurrentptr;
1062 memmove(&pBSSEntry->phyparamset.fhparamset, pFH,
1063 sizeof(struct ieeetypes_fhparamset));
1064 pBSSEntry->phyparamset.fhparamset.dwelltime
1066 le16_to_cpu(pBSSEntry->phyparamset.fhparamset.
1071 pDS = (struct ieeetypes_dsparamset *) pcurrentptr;
1073 pBSSEntry->channel = pDS->currentchan;
1075 memcpy(&pBSSEntry->phyparamset.dsparamset, pDS,
1076 sizeof(struct ieeetypes_dsparamset));
1080 pCF = (struct ieeetypes_cfparamset *) pcurrentptr;
1082 memcpy(&pBSSEntry->ssparamset.cfparamset, pCF,
1083 sizeof(struct ieeetypes_cfparamset));
1086 case IBSS_PARAM_SET:
1087 pibss = (struct ieeetypes_ibssparamset *) pcurrentptr;
1088 pBSSEntry->atimwindow =
1089 le32_to_cpu(pibss->atimwindow);
1091 memmove(&pBSSEntry->ssparamset.ibssparamset, pibss,
1092 sizeof(struct ieeetypes_ibssparamset));
1094 pBSSEntry->ssparamset.ibssparamset.atimwindow
1096 le16_to_cpu(pBSSEntry->ssparamset.ibssparamset.
1100 /* Handle Country Info IE */
1103 (struct ieeetypes_countryinfoset *) pcurrentptr;
1105 if (pcountryinfo->len <
1106 sizeof(pcountryinfo->countrycode)
1107 || pcountryinfo->len > 254) {
1108 lbs_pr_debug(1, "InterpretIE: 11D- Err "
1109 "CountryInfo len =%d min=%zd max=254\n",
1111 sizeof(pcountryinfo->countrycode));
1116 memcpy(&pBSSEntry->countryinfo,
1117 pcountryinfo, pcountryinfo->len + 2);
1118 lbs_dbg_hex("InterpretIE: 11D- CountryInfo:",
1119 (u8 *) pcountryinfo,
1120 (u32) (pcountryinfo->len + 2));
1123 case EXTENDED_SUPPORTED_RATES:
1125 * only process extended supported rate
1126 * if data rate is already found.
1127 * data rate IE should come before
1128 * extended supported rate IE
1130 if (founddatarateie) {
1131 if ((elemlen + ratesize) > WLAN_SUPPORTED_RATES) {
1133 (WLAN_SUPPORTED_RATES - ratesize);
1135 bytestocopy = elemlen;
1138 pRate = (u8 *) pBSSEntry->datarates;
1140 memmove(pRate, (pcurrentptr + 2), bytestocopy);
1142 pRate = (u8 *) pBSSEntry->libertas_supported_rates;
1145 memmove(pRate, (pcurrentptr + 2), bytestocopy);
1149 case VENDOR_SPECIFIC_221:
1150 #define IE_ID_LEN_FIELDS_BYTES 2
1151 pIe = (struct IE_WPA *)pcurrentptr;
1153 if (memcmp(pIe->oui, oui01, sizeof(oui01)))
1156 pBSSEntry->wpa_ie_len = min_t(size_t,
1157 elemlen + IE_ID_LEN_FIELDS_BYTES,
1158 sizeof(pBSSEntry->wpa_ie));
1159 memcpy(pBSSEntry->wpa_ie, pcurrentptr,
1160 pBSSEntry->wpa_ie_len);
1161 lbs_dbg_hex("InterpretIE: Resp WPA_IE",
1162 pBSSEntry->wpa_ie, elemlen);
1165 pIe = (struct IE_WPA *)pcurrentptr;
1167 pBSSEntry->rsn_ie_len = min_t(size_t,
1168 elemlen + IE_ID_LEN_FIELDS_BYTES,
1169 sizeof(pBSSEntry->rsn_ie));
1170 memcpy(pBSSEntry->rsn_ie, pcurrentptr,
1171 pBSSEntry->rsn_ie_len);
1172 lbs_dbg_hex("InterpretIE: Resp WPA2_IE",
1173 pBSSEntry->rsn_ie, elemlen);
1178 case CHALLENGE_TEXT:
1182 pcurrentptr += elemlen + 2;
1184 /* need to account for IE ID and IE len */
1185 bytesleftforcurrentbeacon -= (elemlen + 2);
1187 } /* while (bytesleftforcurrentbeacon > 2) */
1193 * @brief Compare two SSIDs
1195 * @param ssid1 A pointer to ssid to compare
1196 * @param ssid2 A pointer to ssid to compare
1198 * @return 0--ssid is same, otherwise is different
1200 int libertas_SSID_cmp(struct WLAN_802_11_SSID *ssid1, struct WLAN_802_11_SSID *ssid2)
1202 if (!ssid1 || !ssid2)
1205 if (ssid1->ssidlength != ssid2->ssidlength)
1208 return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssidlength);
1212 * @brief This function finds a specific compatible BSSID in the scan list
1214 * @param adapter A pointer to wlan_adapter
1215 * @param bssid BSSID to find in the scan list
1216 * @param mode Network mode: Infrastructure or IBSS
1218 * @return index in BSSID list, or error return code (< 0)
1220 int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, u8 mode)
1222 int ret = -ENETUNREACH;
1228 lbs_pr_debug(1, "FindBSSID: Num of BSSIDs = %d\n",
1229 adapter->numinscantable);
1231 /* Look through the scan table for a compatible match. The ret return
1232 * variable will be equal to the index in the scan table (greater
1233 * than zero) if the network is compatible. The loop will continue
1234 * past a matched bssid that is not compatible in case there is an
1235 * AP with multiple SSIDs assigned to the same BSSID
1237 for (i = 0; ret < 0 && i < adapter->numinscantable; i++) {
1238 if (!memcmp(adapter->scantable[i].macaddress, bssid, ETH_ALEN)) {
1242 ret = is_network_compatible(adapter, i, mode);
1255 * @brief This function finds ssid in ssid list.
1257 * @param adapter A pointer to wlan_adapter
1258 * @param ssid SSID to find in the list
1259 * @param bssid BSSID to qualify the SSID selection (if provided)
1260 * @param mode Network mode: Infrastructure or IBSS
1262 * @return index in BSSID list
1264 int libertas_find_SSID_in_list(wlan_adapter * adapter,
1265 struct WLAN_802_11_SSID *ssid, u8 * bssid, u8 mode)
1267 int net = -ENETUNREACH;
1272 lbs_pr_debug(1, "Num of Entries in Table = %d\n", adapter->numinscantable);
1274 for (i = 0; i < adapter->numinscantable; i++) {
1275 if (!libertas_SSID_cmp(&adapter->scantable[i].ssid, ssid) &&
1277 !memcmp(adapter->scantable[i].
1278 macaddress, bssid, ETH_ALEN))) {
1282 j = is_network_compatible(adapter, i, mode);
1290 (adapter->scantable[i].rssi)
1299 if (net == -ENETUNREACH) {
1306 if (SCAN_RSSI(adapter->scantable[i].rssi)
1309 SCAN_RSSI(adapter->scantable[i].
1322 * @brief This function finds the best SSID in the Scan List
1324 * Search the scan table for the best SSID that also matches the current
1325 * adapter network preference (infrastructure or adhoc)
1327 * @param adapter A pointer to wlan_adapter
1329 * @return index in BSSID list
1331 int libertas_find_best_SSID_in_list(wlan_adapter * adapter, u8 mode)
1333 int bestnet = -ENETUNREACH;
1339 lbs_pr_debug(1, "Num of BSSIDs = %d\n", adapter->numinscantable);
1341 for (i = 0; i < adapter->numinscantable; i++) {
1345 if (is_network_compatible(adapter, i, mode) >= 0) {
1346 if (SCAN_RSSI(adapter->scantable[i].rssi) >
1349 SCAN_RSSI(adapter->scantable[i].
1357 if (SCAN_RSSI(adapter->scantable[i].rssi) > bestrssi) {
1359 SCAN_RSSI(adapter->scantable[i].rssi);
1371 * @brief Find the AP with specific ssid in the scan list
1373 * @param priv A pointer to wlan_private structure
1374 * @param pSSID A pointer to AP's ssid
1376 * @return 0--success, otherwise--fail
1378 int libertas_find_best_network_SSID(wlan_private * priv,
1379 struct WLAN_802_11_SSID *pSSID,
1380 u8 preferred_mode, u8 *out_mode)
1382 wlan_adapter *adapter = priv->adapter;
1384 struct bss_descriptor *preqbssid;
1389 memset(pSSID, 0, sizeof(struct WLAN_802_11_SSID));
1391 wlan_scan_networks(priv, NULL);
1392 if (adapter->surpriseremoved)
1394 wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
1396 i = libertas_find_best_SSID_in_list(adapter, preferred_mode);
1402 preqbssid = &adapter->scantable[i];
1403 memcpy(pSSID, &preqbssid->ssid,
1404 sizeof(struct WLAN_802_11_SSID));
1405 *out_mode = preqbssid->mode;
1407 if (!pSSID->ssidlength) {
1417 * @brief Scan Network
1419 * @param dev A pointer to net_device structure
1420 * @param info A pointer to iw_request_info structure
1421 * @param vwrq A pointer to iw_param structure
1422 * @param extra A pointer to extra data buf
1424 * @return 0 --success, otherwise fail
1426 int libertas_set_scan(struct net_device *dev, struct iw_request_info *info,
1427 struct iw_param *vwrq, char *extra)
1429 wlan_private *priv = dev->priv;
1430 wlan_adapter *adapter = priv->adapter;
1434 wlan_scan_networks(priv, NULL);
1436 if (adapter->surpriseremoved)
1444 * @brief Send a scan command for all available channels filtered on a spec
1446 * @param priv A pointer to wlan_private structure
1447 * @param prequestedssid A pointer to AP's ssid
1448 * @param keeppreviousscan Flag used to save/clear scan table before scan
1450 * @return 0-success, otherwise fail
1452 int libertas_send_specific_SSID_scan(wlan_private * priv,
1453 struct WLAN_802_11_SSID *prequestedssid,
1454 u8 keeppreviousscan)
1456 wlan_adapter *adapter = priv->adapter;
1457 struct wlan_ioctl_user_scan_cfg scancfg;
1461 if (prequestedssid == NULL) {
1465 memset(&scancfg, 0x00, sizeof(scancfg));
1467 memcpy(scancfg.specificSSID, prequestedssid->ssid,
1468 prequestedssid->ssidlength);
1469 scancfg.keeppreviousscan = keeppreviousscan;
1471 wlan_scan_networks(priv, &scancfg);
1472 if (adapter->surpriseremoved)
1474 wait_event_interruptible(adapter->cmd_pending, !adapter->nr_cmd_pending);
1481 * @brief scan an AP with specific BSSID
1483 * @param priv A pointer to wlan_private structure
1484 * @param bssid A pointer to AP's bssid
1485 * @param keeppreviousscan Flag used to save/clear scan table before scan
1487 * @return 0-success, otherwise fail
1489 int libertas_send_specific_BSSID_scan(wlan_private * priv, u8 * bssid, u8 keeppreviousscan)
1491 struct wlan_ioctl_user_scan_cfg scancfg;
1495 if (bssid == NULL) {
1499 memset(&scancfg, 0x00, sizeof(scancfg));
1500 memcpy(scancfg.specificBSSID, bssid, sizeof(scancfg.specificBSSID));
1501 scancfg.keeppreviousscan = keeppreviousscan;
1503 wlan_scan_networks(priv, &scancfg);
1504 if (priv->adapter->surpriseremoved)
1506 wait_event_interruptible(priv->adapter->cmd_pending,
1507 !priv->adapter->nr_cmd_pending);
1514 * @brief Retrieve the scan table entries via wireless tools IOCTL call
1516 * @param dev A pointer to net_device structure
1517 * @param info A pointer to iw_request_info structure
1518 * @param dwrq A pointer to iw_point structure
1519 * @param extra A pointer to extra data buf
1521 * @return 0 --success, otherwise fail
1523 int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
1524 struct iw_point *dwrq, char *extra)
1526 wlan_private *priv = dev->priv;
1527 wlan_adapter *adapter = priv->adapter;
1529 char *current_ev = extra;
1530 char *end_buf = extra + IW_SCAN_MAX_DATA;
1531 struct chan_freq_power *cfp;
1532 struct bss_descriptor *pscantable;
1533 char *current_val; /* For rates */
1534 struct iw_event iwe; /* Temporary buffer */
1538 #define PERFECT_RSSI ((u8)50)
1539 #define WORST_RSSI ((u8)0)
1540 #define RSSI_DIFF ((u8)(PERFECT_RSSI - WORST_RSSI))
1543 u8 buf[16 + 256 * 2];
1549 * if there's either commands in the queue or one being
1550 * processed return -EAGAIN for iwlist to retry later.
1552 if (adapter->nr_cmd_pending)
1555 if (adapter->connect_status == libertas_connected)
1556 lbs_pr_debug(1, "Current ssid: %32s\n",
1557 adapter->curbssparams.ssid.ssid);
1559 lbs_pr_debug(1, "Scan: Get: numinscantable = %d\n",
1560 adapter->numinscantable);
1562 /* The old API using SIOCGIWAPLIST had a hard limit of IW_MAX_AP.
1563 * The new API using SIOCGIWSCAN is only limited by buffer size
1564 * WE-14 -> WE-16 the buffer is limited to IW_SCAN_MAX_DATA bytes
1567 for (i = 0; i < adapter->numinscantable; i++) {
1568 if ((current_ev + MAX_SCAN_CELL_SIZE) >= end_buf) {
1569 lbs_pr_debug(1, "i=%d break out: current_ev=%p end_buf=%p "
1570 "MAX_SCAN_CELL_SIZE=%zd\n",
1571 i, current_ev, end_buf, MAX_SCAN_CELL_SIZE);
1575 pscantable = &adapter->scantable[i];
1577 lbs_pr_debug(1, "i=%d ssid: %32s\n", i, pscantable->ssid.ssid);
1580 libertas_find_cfp_by_band_and_channel(adapter, 0,
1581 pscantable->channel);
1583 lbs_pr_debug(1, "Invalid channel number %d\n",
1584 pscantable->channel);
1588 if (!ssid_valid(&adapter->scantable[i].ssid)) {
1592 /* First entry *MUST* be the AP MAC address */
1593 iwe.cmd = SIOCGIWAP;
1594 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1595 memcpy(iwe.u.ap_addr.sa_data,
1596 &adapter->scantable[i].macaddress, ETH_ALEN);
1598 iwe.len = IW_EV_ADDR_LEN;
1600 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
1603 iwe.u.data.length = adapter->scantable[i].ssid.ssidlength;
1605 if (iwe.u.data.length > 32) {
1606 iwe.u.data.length = 32;
1609 iwe.cmd = SIOCGIWESSID;
1610 iwe.u.data.flags = 1;
1611 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1612 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1613 adapter->scantable[i].ssid.
1617 iwe.cmd = SIOCGIWMODE;
1618 iwe.u.mode = adapter->scantable[i].mode;
1619 iwe.len = IW_EV_UINT_LEN;
1621 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
1624 iwe.cmd = SIOCGIWFREQ;
1625 iwe.u.freq.m = (long)cfp->freq * 100000;
1627 iwe.len = IW_EV_FREQ_LEN;
1629 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
1631 /* Add quality statistics */
1633 iwe.u.qual.updated = IW_QUAL_ALL_UPDATED;
1634 iwe.u.qual.level = SCAN_RSSI(adapter->scantable[i].rssi);
1636 rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
1638 (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) *
1639 (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) /
1640 (RSSI_DIFF * RSSI_DIFF);
1641 if (iwe.u.qual.qual > 100)
1642 iwe.u.qual.qual = 100;
1643 else if (iwe.u.qual.qual < 1)
1644 iwe.u.qual.qual = 0;
1646 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
1647 iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
1650 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1652 if ((adapter->mode == IW_MODE_ADHOC) &&
1653 !libertas_SSID_cmp(&adapter->curbssparams.ssid,
1654 &adapter->scantable[i].ssid)
1655 && adapter->adhoccreate) {
1656 ret = libertas_prepare_and_send_command(priv,
1659 cmd_option_waitforrsp,
1664 CAL_RSSI(adapter->SNR[TYPE_RXPD][TYPE_AVG] /
1666 adapter->NF[TYPE_RXPD][TYPE_AVG] /
1670 iwe.len = IW_EV_QUAL_LEN;
1672 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
1674 /* Add encryption capability */
1675 iwe.cmd = SIOCGIWENCODE;
1676 if (adapter->scantable[i].privacy) {
1677 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1679 iwe.u.data.flags = IW_ENCODE_DISABLED;
1681 iwe.u.data.length = 0;
1682 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1683 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1684 adapter->scantable->ssid.
1687 current_val = current_ev + IW_EV_LCP_LEN;
1689 iwe.cmd = SIOCGIWRATE;
1691 iwe.u.bitrate.fixed = 0;
1692 iwe.u.bitrate.disabled = 0;
1693 iwe.u.bitrate.value = 0;
1695 /* Bit rate given in 500 kb/s units (+ 0x80) */
1696 for (j = 0; j < sizeof(adapter->scantable[i].libertas_supported_rates);
1698 if (adapter->scantable[i].libertas_supported_rates[j] == 0) {
1702 (adapter->scantable[i].libertas_supported_rates[j] & 0x7F) *
1704 if (rate > iwe.u.bitrate.value) {
1705 iwe.u.bitrate.value = rate;
1708 iwe.u.bitrate.value =
1709 (adapter->scantable[i].libertas_supported_rates[j]
1711 iwe.len = IW_EV_PARAM_LEN;
1713 iwe_stream_add_value(current_ev, current_val,
1714 end_buf, &iwe, iwe.len);
1717 if ((adapter->scantable[i].mode == IW_MODE_ADHOC)
1718 && !libertas_SSID_cmp(&adapter->curbssparams.ssid,
1719 &adapter->scantable[i].ssid)
1720 && adapter->adhoccreate) {
1721 iwe.u.bitrate.value = 22 * 500000;
1723 iwe.len = IW_EV_PARAM_LEN;
1725 iwe_stream_add_value(current_ev, current_val, end_buf, &iwe,
1728 /* Add new value to event */
1729 current_val = current_ev + IW_EV_LCP_LEN;
1731 if (adapter->scantable[i].rsn_ie[0] == WPA2_IE) {
1732 memset(&iwe, 0, sizeof(iwe));
1733 memset(buf, 0, sizeof(buf));
1734 memcpy(buf, adapter->scantable[i].rsn_ie,
1735 adapter->scantable[i].rsn_ie_len);
1736 iwe.cmd = IWEVGENIE;
1737 iwe.u.data.length = adapter->scantable[i].rsn_ie_len;
1738 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1739 current_ev = iwe_stream_add_point(current_ev, end_buf,
1742 if (adapter->scantable[i].wpa_ie[0] == WPA_IE) {
1743 memset(&iwe, 0, sizeof(iwe));
1744 memset(buf, 0, sizeof(buf));
1745 memcpy(buf, adapter->scantable[i].wpa_ie,
1746 adapter->scantable[i].wpa_ie_len);
1747 iwe.cmd = IWEVGENIE;
1748 iwe.u.data.length = adapter->scantable[i].wpa_ie_len;
1749 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1750 current_ev = iwe_stream_add_point(current_ev, end_buf,
1755 if (adapter->scantable[i].extra_ie != 0) {
1756 memset(&iwe, 0, sizeof(iwe));
1757 memset(buf, 0, sizeof(buf));
1759 ptr += sprintf(ptr, "extra_ie");
1760 iwe.u.data.length = strlen(buf);
1762 lbs_pr_debug(1, "iwe.u.data.length %d\n",
1764 lbs_pr_debug(1, "BUF: %s \n", buf);
1766 iwe.cmd = IWEVCUSTOM;
1767 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1769 iwe_stream_add_point(current_ev, end_buf, &iwe,
1773 current_val = current_ev + IW_EV_LCP_LEN;
1776 * Check if we added any event
1778 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1779 current_ev = current_val;
1782 dwrq->length = (current_ev - extra);
1790 * @brief Prepare a scan command to be sent to the firmware
1792 * Use the wlan_scan_cmd_config sent to the command processing module in
1793 * the libertas_prepare_and_send_command to configure a cmd_ds_802_11_scan command
1794 * struct to send to firmware.
1796 * The fixed fields specifying the BSS type and BSSID filters as well as a
1797 * variable number/length of TLVs are sent in the command to firmware.
1799 * @param priv A pointer to wlan_private structure
1800 * @param cmd A pointer to cmd_ds_command structure to be sent to
1801 * firmware with the cmd_DS_801_11_SCAN structure
1802 * @param pdata_buf Void pointer cast of a wlan_scan_cmd_config struct used
1803 * to set the fields/TLVs for the command sent to firmware
1807 * @sa wlan_scan_create_channel_list
1809 int libertas_cmd_80211_scan(wlan_private * priv,
1810 struct cmd_ds_command *cmd, void *pdata_buf)
1812 struct cmd_ds_802_11_scan *pscan = &cmd->params.scan;
1813 struct wlan_scan_cmd_config *pscancfg;
1817 pscancfg = pdata_buf;
1819 /* Set fixed field variables in scan command */
1820 pscan->bsstype = pscancfg->bsstype;
1821 memcpy(pscan->BSSID, pscancfg->specificBSSID, sizeof(pscan->BSSID));
1822 memcpy(pscan->tlvbuffer, pscancfg->tlvbuffer, pscancfg->tlvbufferlen);
1824 cmd->command = cpu_to_le16(cmd_802_11_scan);
1826 /* size is equal to the sizeof(fixed portions) + the TLV len + header */
1827 cmd->size = cpu_to_le16(sizeof(pscan->bsstype)
1828 + sizeof(pscan->BSSID)
1829 + pscancfg->tlvbufferlen + S_DS_GEN);
1831 lbs_pr_debug(1, "SCAN_CMD: command=%x, size=%x, seqnum=%x\n",
1832 cmd->command, cmd->size, cmd->seqnum);
1838 * @brief This function handles the command response of scan
1840 * The response buffer for the scan command has the following
1843 * .-----------------------------------------------------------.
1844 * | header (4 * sizeof(u16)): Standard command response hdr |
1845 * .-----------------------------------------------------------.
1846 * | bufsize (u16) : sizeof the BSS Description data |
1847 * .-----------------------------------------------------------.
1848 * | NumOfSet (u8) : Number of BSS Descs returned |
1849 * .-----------------------------------------------------------.
1850 * | BSSDescription data (variable, size given in bufsize) |
1851 * .-----------------------------------------------------------.
1852 * | TLV data (variable, size calculated using header->size, |
1853 * | bufsize and sizeof the fixed fields above) |
1854 * .-----------------------------------------------------------.
1856 * @param priv A pointer to wlan_private structure
1857 * @param resp A pointer to cmd_ds_command
1861 int libertas_ret_80211_scan(wlan_private * priv, struct cmd_ds_command *resp)
1863 wlan_adapter *adapter = priv->adapter;
1864 struct cmd_ds_802_11_scan_rsp *pscan;
1865 struct bss_descriptor newbssentry;
1866 struct mrvlietypes_data *ptlv;
1867 struct mrvlietypes_tsftimestamp *ptsftlv;
1879 pscan = &resp->params.scanresp;
1881 if (pscan->nr_sets > MRVDRV_MAX_BSSID_LIST) {
1883 "SCAN_RESP: Invalid number of AP returned (%d)!!\n",
1889 bytesleft = le16_to_cpu(pscan->bssdescriptsize);
1890 lbs_pr_debug(1, "SCAN_RESP: bssdescriptsize %d\n", bytesleft);
1892 scanrespsize = le16_to_cpu(resp->size);
1893 lbs_pr_debug(1, "SCAN_RESP: returned %d AP before parsing\n",
1896 numintable = adapter->numinscantable;
1897 pbssinfo = pscan->bssdesc_and_tlvbuffer;
1899 /* The size of the TLV buffer is equal to the entire command response
1900 * size (scanrespsize) minus the fixed fields (sizeof()'s), the
1901 * BSS Descriptions (bssdescriptsize as bytesLef) and the command
1902 * response header (S_DS_GEN)
1904 tlvbufsize = scanrespsize - (bytesleft + sizeof(pscan->bssdescriptsize)
1905 + sizeof(pscan->nr_sets)
1908 ptlv = (struct mrvlietypes_data *) (pscan->bssdesc_and_tlvbuffer + bytesleft);
1910 /* Search the TLV buffer space in the scan response for any valid TLVs */
1911 wlan_ret_802_11_scan_get_tlv_ptrs(ptlv, tlvbufsize, &ptsftlv);
1914 * Process each scan response returned (pscan->nr_sets). Save
1915 * the information in the newbssentry and then insert into the
1916 * driver scan table either as an update to an existing entry
1917 * or as an addition at the end of the table
1919 for (idx = 0; idx < pscan->nr_sets && bytesleft; idx++) {
1920 /* Zero out the newbssentry we are about to store info in */
1921 memset(&newbssentry, 0x00, sizeof(newbssentry));
1923 /* Process the data fields and IEs returned for this BSS */
1924 if ((InterpretBSSDescriptionWithIE(&newbssentry,
1928 && CHECK_SSID_IS_VALID(&newbssentry.ssid)) {
1931 "SCAN_RESP: BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
1932 newbssentry.macaddress[0],
1933 newbssentry.macaddress[1],
1934 newbssentry.macaddress[2],
1935 newbssentry.macaddress[3],
1936 newbssentry.macaddress[4],
1937 newbssentry.macaddress[5]);
1940 * Search the scan table for the same bssid
1942 for (bssIdx = 0; bssIdx < numintable; bssIdx++) {
1943 if (memcmp(newbssentry.macaddress,
1944 adapter->scantable[bssIdx].
1946 sizeof(newbssentry.macaddress)) ==
1949 * If the SSID matches as well, it is a duplicate of
1950 * this entry. Keep the bssIdx set to this
1951 * entry so we replace the old contents in the table
1953 if ((newbssentry.ssid.ssidlength ==
1954 adapter->scantable[bssIdx].ssid.
1958 (newbssentry.ssid.ssid,
1959 adapter->scantable[bssIdx].ssid.
1961 newbssentry.ssid.ssidlength) ==
1964 "SCAN_RESP: Duplicate of index: %d\n",
1971 * If the bssIdx is equal to the number of entries in the table,
1972 * the new entry was not a duplicate; append it to the scan
1975 if (bssIdx == numintable) {
1976 /* Range check the bssIdx, keep it limited to the last entry */
1977 if (bssIdx == MRVDRV_MAX_BSSID_LIST) {
1985 * If the TSF TLV was appended to the scan results, save the
1986 * this entries TSF value in the networktsf field. The
1987 * networktsf is the firmware's TSF value at the time the
1988 * beacon or probe response was received.
1991 memcpy(&tsfval, &ptsftlv->tsftable[idx],
1993 tsfval = le64_to_cpu(tsfval);
1995 memcpy(&newbssentry.networktsf,
1996 &tsfval, sizeof(newbssentry.networktsf));
1999 /* Copy the locally created newbssentry to the scan table */
2000 memcpy(&adapter->scantable[bssIdx],
2002 sizeof(adapter->scantable[bssIdx]));
2006 /* error parsing/interpreting the scan response, skipped */
2007 lbs_pr_debug(1, "SCAN_RESP: "
2008 "InterpretBSSDescriptionWithIE returned ERROR\n");
2012 lbs_pr_debug(1, "SCAN_RESP: Scanned %2d APs, %d valid, %d total\n",
2013 pscan->nr_sets, numintable - adapter->numinscantable,
2016 /* Update the total number of BSSIDs in the scan table */
2017 adapter->numinscantable = numintable;