Skip to content

Commit b2e3abd

Browse files
Holger Schuriglinvjw
authored andcommitted
cfg80211: allow scanning on specified frequencies when using wext-compatibility
Handles the case when SIOCSIWSCAN specified iw_scan_req.num_channels and iw_scan_req.channels[]. Signed-off-by: Holger Schurig <hs4233@mail.mn-solutions.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 8c8f9ba commit b2e3abd

1 file changed

Lines changed: 34 additions & 7 deletions

File tree

‎net/wireless/scan.c‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ int cfg80211_wext_siwscan(struct net_device *dev,
607607
if (!netif_running(dev))
608608
return -ENETDOWN;
609609

610+
if (wrqu->data.length == sizeof(struct iw_scan_req))
611+
wreq = (struct iw_scan_req *)extra;
612+
610613
rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
611614

612615
if (IS_ERR(rdev))
@@ -619,9 +622,14 @@ int cfg80211_wext_siwscan(struct net_device *dev,
619622

620623
wiphy = &rdev->wiphy;
621624

622-
for (band = 0; band < IEEE80211_NUM_BANDS; band++)
623-
if (wiphy->bands[band])
624-
n_channels += wiphy->bands[band]->n_channels;
625+
/* Determine number of channels, needed to allocate creq */
626+
if (wreq && wreq->num_channels)
627+
n_channels = wreq->num_channels;
628+
else {
629+
for (band = 0; band < IEEE80211_NUM_BANDS; band++)
630+
if (wiphy->bands[band])
631+
n_channels += wiphy->bands[band]->n_channels;
632+
}
625633

626634
creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
627635
n_channels * sizeof(void *),
@@ -638,22 +646,41 @@ int cfg80211_wext_siwscan(struct net_device *dev,
638646
creq->n_channels = n_channels;
639647
creq->n_ssids = 1;
640648

641-
/* all channels */
649+
/* translate "Scan on frequencies" request */
642650
i = 0;
643651
for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
644652
int j;
645653
if (!wiphy->bands[band])
646654
continue;
647655
for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
656+
657+
/* If we have a wireless request structure and the
658+
* wireless request specifies frequencies, then search
659+
* for the matching hardware channel.
660+
*/
661+
if (wreq && wreq->num_channels) {
662+
int k;
663+
int wiphy_freq = wiphy->bands[band]->channels[j].center_freq;
664+
for (k = 0; k < wreq->num_channels; k++) {
665+
int wext_freq = wreq->channel_list[k].m / 100000;
666+
if (wext_freq == wiphy_freq)
667+
goto wext_freq_found;
668+
}
669+
goto wext_freq_not_found;
670+
}
671+
672+
wext_freq_found:
648673
creq->channels[i] = &wiphy->bands[band]->channels[j];
649674
i++;
675+
wext_freq_not_found: ;
650676
}
651677
}
652678

653-
/* translate scan request */
654-
if (wrqu->data.length == sizeof(struct iw_scan_req)) {
655-
wreq = (struct iw_scan_req *)extra;
679+
/* Set real number of channels specified in creq->channels[] */
680+
creq->n_channels = i;
656681

682+
/* translate "Scan for SSID" request */
683+
if (wreq) {
657684
if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
658685
if (wreq->essid_len > IEEE80211_MAX_SSID_LEN)
659686
return -EINVAL;

0 commit comments

Comments
 (0)