diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2008-09-08 11:44:25 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-09-11 15:53:36 -0400 |
commit | 0a51b27e956bd9580296c48191b78175ed8b5971 (patch) | |
tree | fd48f13e3f8eb75675c1c8d32c7214df2af47814 | |
parent | ee96d6ef82cc29421569b7cb7f7c7ee90168ec50 (diff) |
mac80211: start moving scan code from mlme
Here's a first patch to move some code from mlme.c to a
new file called scan.c. The end result will hopefully be
a more manageable mlme.c.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | net/mac80211/Makefile | 1 | ||||
-rw-r--r-- | net/mac80211/ieee80211_i.h | 13 | ||||
-rw-r--r-- | net/mac80211/mlme.c | 559 | ||||
-rw-r--r-- | net/mac80211/scan.c | 553 |
4 files changed, 582 insertions, 544 deletions
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile index a169b0201d61..376280a420ac 100644 --- a/net/mac80211/Makefile +++ b/net/mac80211/Makefile | |||
@@ -7,6 +7,7 @@ mac80211-y := \ | |||
7 | sta_info.o \ | 7 | sta_info.o \ |
8 | wep.o \ | 8 | wep.o \ |
9 | wpa.o \ | 9 | wpa.o \ |
10 | scan.o \ | ||
10 | mlme.o \ | 11 | mlme.o \ |
11 | iface.o \ | 12 | iface.o \ |
12 | rate.o \ | 13 | rate.o \ |
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index a33bbd1ca2b1..25dccd5cb2ff 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h | |||
@@ -53,6 +53,12 @@ struct ieee80211_local; | |||
53 | * increased memory use (about 2 kB of RAM per entry). */ | 53 | * increased memory use (about 2 kB of RAM per entry). */ |
54 | #define IEEE80211_FRAGMENT_MAX 4 | 54 | #define IEEE80211_FRAGMENT_MAX 4 |
55 | 55 | ||
56 | /* | ||
57 | * Time after which we ignore scan results and no longer report/use | ||
58 | * them in any way. | ||
59 | */ | ||
60 | #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ) | ||
61 | |||
56 | struct ieee80211_fragment_entry { | 62 | struct ieee80211_fragment_entry { |
57 | unsigned long first_frag_time; | 63 | unsigned long first_frag_time; |
58 | unsigned int seq; | 64 | unsigned int seq; |
@@ -924,8 +930,13 @@ u64 ieee80211_sta_get_rates(struct ieee80211_local *local, | |||
924 | enum ieee80211_band band); | 930 | enum ieee80211_band band); |
925 | void ieee80211_sta_tx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, | 931 | void ieee80211_sta_tx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
926 | int encrypt); | 932 | int encrypt); |
933 | void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, | ||
934 | u8 *ssid, size_t ssid_len); | ||
927 | void ieee802_11_parse_elems(u8 *start, size_t len, | 935 | void ieee802_11_parse_elems(u8 *start, size_t len, |
928 | struct ieee802_11_elems *elems); | 936 | struct ieee802_11_elems *elems); |
937 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local); | ||
938 | int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata, | ||
939 | u8 *ssid, size_t ssid_len); | ||
929 | 940 | ||
930 | #ifdef CONFIG_MAC80211_MESH | 941 | #ifdef CONFIG_MAC80211_MESH |
931 | void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata); | 942 | void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata); |
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index ba502ce132d9..2caea9759b7e 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c | |||
@@ -46,10 +46,6 @@ | |||
46 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) | 46 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) |
47 | #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) | 47 | #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) |
48 | 48 | ||
49 | #define IEEE80211_PROBE_DELAY (HZ / 33) | ||
50 | #define IEEE80211_CHANNEL_TIME (HZ / 33) | ||
51 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) | ||
52 | #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ) | ||
53 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) | 49 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) |
54 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) | 50 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) |
55 | #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ) | 51 | #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ) |
@@ -341,8 +337,8 @@ static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, | |||
341 | ieee80211_sta_tx(sdata, skb, encrypt); | 337 | ieee80211_sta_tx(sdata, skb, encrypt); |
342 | } | 338 | } |
343 | 339 | ||
344 | static void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, | 340 | void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, |
345 | u8 *ssid, size_t ssid_len) | 341 | u8 *ssid, size_t ssid_len) |
346 | { | 342 | { |
347 | struct ieee80211_local *local = sdata->local; | 343 | struct ieee80211_local *local = sdata->local; |
348 | struct ieee80211_supported_band *sband; | 344 | struct ieee80211_supported_band *sband; |
@@ -3466,543 +3462,6 @@ int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid) | |||
3466 | } | 3462 | } |
3467 | 3463 | ||
3468 | 3464 | ||
3469 | static void ieee80211_send_nullfunc(struct ieee80211_local *local, | ||
3470 | struct ieee80211_sub_if_data *sdata, | ||
3471 | int powersave) | ||
3472 | { | ||
3473 | struct sk_buff *skb; | ||
3474 | struct ieee80211_hdr *nullfunc; | ||
3475 | __le16 fc; | ||
3476 | |||
3477 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); | ||
3478 | if (!skb) { | ||
3479 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " | ||
3480 | "frame\n", sdata->dev->name); | ||
3481 | return; | ||
3482 | } | ||
3483 | skb_reserve(skb, local->hw.extra_tx_headroom); | ||
3484 | |||
3485 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); | ||
3486 | memset(nullfunc, 0, 24); | ||
3487 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | | ||
3488 | IEEE80211_FCTL_TODS); | ||
3489 | if (powersave) | ||
3490 | fc |= cpu_to_le16(IEEE80211_FCTL_PM); | ||
3491 | nullfunc->frame_control = fc; | ||
3492 | memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); | ||
3493 | memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); | ||
3494 | memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); | ||
3495 | |||
3496 | ieee80211_sta_tx(sdata, skb, 0); | ||
3497 | } | ||
3498 | |||
3499 | |||
3500 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) | ||
3501 | { | ||
3502 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || | ||
3503 | ieee80211_vif_is_mesh(&sdata->vif)) | ||
3504 | ieee80211_sta_timer((unsigned long)sdata); | ||
3505 | } | ||
3506 | |||
3507 | void ieee80211_scan_completed(struct ieee80211_hw *hw) | ||
3508 | { | ||
3509 | struct ieee80211_local *local = hw_to_local(hw); | ||
3510 | struct ieee80211_sub_if_data *sdata; | ||
3511 | union iwreq_data wrqu; | ||
3512 | |||
3513 | local->last_scan_completed = jiffies; | ||
3514 | memset(&wrqu, 0, sizeof(wrqu)); | ||
3515 | wireless_send_event(local->scan_sdata->dev, SIOCGIWSCAN, &wrqu, NULL); | ||
3516 | |||
3517 | if (local->sta_hw_scanning) { | ||
3518 | local->sta_hw_scanning = 0; | ||
3519 | if (ieee80211_hw_config(local)) | ||
3520 | printk(KERN_DEBUG "%s: failed to restore operational " | ||
3521 | "channel after scan\n", wiphy_name(local->hw.wiphy)); | ||
3522 | /* Restart STA timer for HW scan case */ | ||
3523 | rcu_read_lock(); | ||
3524 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | ||
3525 | ieee80211_restart_sta_timer(sdata); | ||
3526 | rcu_read_unlock(); | ||
3527 | |||
3528 | goto done; | ||
3529 | } | ||
3530 | |||
3531 | local->sta_sw_scanning = 0; | ||
3532 | if (ieee80211_hw_config(local)) | ||
3533 | printk(KERN_DEBUG "%s: failed to restore operational " | ||
3534 | "channel after scan\n", wiphy_name(local->hw.wiphy)); | ||
3535 | |||
3536 | |||
3537 | netif_tx_lock_bh(local->mdev); | ||
3538 | netif_addr_lock(local->mdev); | ||
3539 | local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; | ||
3540 | local->ops->configure_filter(local_to_hw(local), | ||
3541 | FIF_BCN_PRBRESP_PROMISC, | ||
3542 | &local->filter_flags, | ||
3543 | local->mdev->mc_count, | ||
3544 | local->mdev->mc_list); | ||
3545 | |||
3546 | netif_addr_unlock(local->mdev); | ||
3547 | netif_tx_unlock_bh(local->mdev); | ||
3548 | |||
3549 | rcu_read_lock(); | ||
3550 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | ||
3551 | /* Tell AP we're back */ | ||
3552 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { | ||
3553 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { | ||
3554 | ieee80211_send_nullfunc(local, sdata, 0); | ||
3555 | netif_tx_wake_all_queues(sdata->dev); | ||
3556 | } | ||
3557 | } else | ||
3558 | netif_tx_wake_all_queues(sdata->dev); | ||
3559 | |||
3560 | ieee80211_restart_sta_timer(sdata); | ||
3561 | } | ||
3562 | rcu_read_unlock(); | ||
3563 | |||
3564 | done: | ||
3565 | sdata = local->scan_sdata; | ||
3566 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | ||
3567 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | ||
3568 | if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) || | ||
3569 | (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) && | ||
3570 | !ieee80211_sta_active_ibss(sdata))) | ||
3571 | ieee80211_sta_find_ibss(sdata, ifsta); | ||
3572 | } | ||
3573 | } | ||
3574 | EXPORT_SYMBOL(ieee80211_scan_completed); | ||
3575 | |||
3576 | void ieee80211_sta_scan_work(struct work_struct *work) | ||
3577 | { | ||
3578 | struct ieee80211_local *local = | ||
3579 | container_of(work, struct ieee80211_local, scan_work.work); | ||
3580 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; | ||
3581 | struct ieee80211_supported_band *sband; | ||
3582 | struct ieee80211_channel *chan; | ||
3583 | int skip; | ||
3584 | unsigned long next_delay = 0; | ||
3585 | |||
3586 | if (!local->sta_sw_scanning) | ||
3587 | return; | ||
3588 | |||
3589 | switch (local->scan_state) { | ||
3590 | case SCAN_SET_CHANNEL: | ||
3591 | /* | ||
3592 | * Get current scan band. scan_band may be IEEE80211_NUM_BANDS | ||
3593 | * after we successfully scanned the last channel of the last | ||
3594 | * band (and the last band is supported by the hw) | ||
3595 | */ | ||
3596 | if (local->scan_band < IEEE80211_NUM_BANDS) | ||
3597 | sband = local->hw.wiphy->bands[local->scan_band]; | ||
3598 | else | ||
3599 | sband = NULL; | ||
3600 | |||
3601 | /* | ||
3602 | * If we are at an unsupported band and have more bands | ||
3603 | * left to scan, advance to the next supported one. | ||
3604 | */ | ||
3605 | while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) { | ||
3606 | local->scan_band++; | ||
3607 | sband = local->hw.wiphy->bands[local->scan_band]; | ||
3608 | local->scan_channel_idx = 0; | ||
3609 | } | ||
3610 | |||
3611 | /* if no more bands/channels left, complete scan */ | ||
3612 | if (!sband || local->scan_channel_idx >= sband->n_channels) { | ||
3613 | ieee80211_scan_completed(local_to_hw(local)); | ||
3614 | return; | ||
3615 | } | ||
3616 | skip = 0; | ||
3617 | chan = &sband->channels[local->scan_channel_idx]; | ||
3618 | |||
3619 | if (chan->flags & IEEE80211_CHAN_DISABLED || | ||
3620 | (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && | ||
3621 | chan->flags & IEEE80211_CHAN_NO_IBSS)) | ||
3622 | skip = 1; | ||
3623 | |||
3624 | if (!skip) { | ||
3625 | local->scan_channel = chan; | ||
3626 | if (ieee80211_hw_config(local)) { | ||
3627 | printk(KERN_DEBUG "%s: failed to set freq to " | ||
3628 | "%d MHz for scan\n", wiphy_name(local->hw.wiphy), | ||
3629 | chan->center_freq); | ||
3630 | skip = 1; | ||
3631 | } | ||
3632 | } | ||
3633 | |||
3634 | /* advance state machine to next channel/band */ | ||
3635 | local->scan_channel_idx++; | ||
3636 | if (local->scan_channel_idx >= sband->n_channels) { | ||
3637 | /* | ||
3638 | * scan_band may end up == IEEE80211_NUM_BANDS, but | ||
3639 | * we'll catch that case above and complete the scan | ||
3640 | * if that is the case. | ||
3641 | */ | ||
3642 | local->scan_band++; | ||
3643 | local->scan_channel_idx = 0; | ||
3644 | } | ||
3645 | |||
3646 | if (skip) | ||
3647 | break; | ||
3648 | |||
3649 | next_delay = IEEE80211_PROBE_DELAY + | ||
3650 | usecs_to_jiffies(local->hw.channel_change_time); | ||
3651 | local->scan_state = SCAN_SEND_PROBE; | ||
3652 | break; | ||
3653 | case SCAN_SEND_PROBE: | ||
3654 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; | ||
3655 | local->scan_state = SCAN_SET_CHANNEL; | ||
3656 | |||
3657 | if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN) | ||
3658 | break; | ||
3659 | ieee80211_send_probe_req(sdata, NULL, local->scan_ssid, | ||
3660 | local->scan_ssid_len); | ||
3661 | next_delay = IEEE80211_CHANNEL_TIME; | ||
3662 | break; | ||
3663 | } | ||
3664 | |||
3665 | if (local->sta_sw_scanning) | ||
3666 | queue_delayed_work(local->hw.workqueue, &local->scan_work, | ||
3667 | next_delay); | ||
3668 | } | ||
3669 | |||
3670 | |||
3671 | static int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata, | ||
3672 | u8 *ssid, size_t ssid_len) | ||
3673 | { | ||
3674 | struct ieee80211_local *local = scan_sdata->local; | ||
3675 | struct ieee80211_sub_if_data *sdata; | ||
3676 | |||
3677 | if (ssid_len > IEEE80211_MAX_SSID_LEN) | ||
3678 | return -EINVAL; | ||
3679 | |||
3680 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) | ||
3681 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS | ||
3682 | * BSSID: MACAddress | ||
3683 | * SSID | ||
3684 | * ScanType: ACTIVE, PASSIVE | ||
3685 | * ProbeDelay: delay (in microseconds) to be used prior to transmitting | ||
3686 | * a Probe frame during active scanning | ||
3687 | * ChannelList | ||
3688 | * MinChannelTime (>= ProbeDelay), in TU | ||
3689 | * MaxChannelTime: (>= MinChannelTime), in TU | ||
3690 | */ | ||
3691 | |||
3692 | /* MLME-SCAN.confirm | ||
3693 | * BSSDescriptionSet | ||
3694 | * ResultCode: SUCCESS, INVALID_PARAMETERS | ||
3695 | */ | ||
3696 | |||
3697 | if (local->sta_sw_scanning || local->sta_hw_scanning) { | ||
3698 | if (local->scan_sdata == scan_sdata) | ||
3699 | return 0; | ||
3700 | return -EBUSY; | ||
3701 | } | ||
3702 | |||
3703 | if (local->ops->hw_scan) { | ||
3704 | int rc = local->ops->hw_scan(local_to_hw(local), | ||
3705 | ssid, ssid_len); | ||
3706 | if (!rc) { | ||
3707 | local->sta_hw_scanning = 1; | ||
3708 | local->scan_sdata = scan_sdata; | ||
3709 | } | ||
3710 | return rc; | ||
3711 | } | ||
3712 | |||
3713 | local->sta_sw_scanning = 1; | ||
3714 | |||
3715 | rcu_read_lock(); | ||
3716 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | ||
3717 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { | ||
3718 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { | ||
3719 | netif_tx_stop_all_queues(sdata->dev); | ||
3720 | ieee80211_send_nullfunc(local, sdata, 1); | ||
3721 | } | ||
3722 | } else | ||
3723 | netif_tx_stop_all_queues(sdata->dev); | ||
3724 | } | ||
3725 | rcu_read_unlock(); | ||
3726 | |||
3727 | if (ssid) { | ||
3728 | local->scan_ssid_len = ssid_len; | ||
3729 | memcpy(local->scan_ssid, ssid, ssid_len); | ||
3730 | } else | ||
3731 | local->scan_ssid_len = 0; | ||
3732 | local->scan_state = SCAN_SET_CHANNEL; | ||
3733 | local->scan_channel_idx = 0; | ||
3734 | local->scan_band = IEEE80211_BAND_2GHZ; | ||
3735 | local->scan_sdata = scan_sdata; | ||
3736 | |||
3737 | netif_addr_lock_bh(local->mdev); | ||
3738 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; | ||
3739 | local->ops->configure_filter(local_to_hw(local), | ||
3740 | FIF_BCN_PRBRESP_PROMISC, | ||
3741 | &local->filter_flags, | ||
3742 | local->mdev->mc_count, | ||
3743 | local->mdev->mc_list); | ||
3744 | netif_addr_unlock_bh(local->mdev); | ||
3745 | |||
3746 | /* TODO: start scan as soon as all nullfunc frames are ACKed */ | ||
3747 | queue_delayed_work(local->hw.workqueue, &local->scan_work, | ||
3748 | IEEE80211_CHANNEL_TIME); | ||
3749 | |||
3750 | return 0; | ||
3751 | } | ||
3752 | |||
3753 | |||
3754 | int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t ssid_len) | ||
3755 | { | ||
3756 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | ||
3757 | struct ieee80211_local *local = sdata->local; | ||
3758 | |||
3759 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) | ||
3760 | return ieee80211_sta_start_scan(sdata, ssid, ssid_len); | ||
3761 | |||
3762 | if (local->sta_sw_scanning || local->sta_hw_scanning) { | ||
3763 | if (local->scan_sdata == sdata) | ||
3764 | return 0; | ||
3765 | return -EBUSY; | ||
3766 | } | ||
3767 | |||
3768 | ifsta->scan_ssid_len = ssid_len; | ||
3769 | if (ssid_len) | ||
3770 | memcpy(ifsta->scan_ssid, ssid, ssid_len); | ||
3771 | set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); | ||
3772 | queue_work(local->hw.workqueue, &ifsta->work); | ||
3773 | return 0; | ||
3774 | } | ||
3775 | |||
3776 | |||
3777 | static void ieee80211_sta_add_scan_ies(struct iw_request_info *info, | ||
3778 | struct ieee80211_sta_bss *bss, | ||
3779 | char **current_ev, char *end_buf) | ||
3780 | { | ||
3781 | u8 *pos, *end, *next; | ||
3782 | struct iw_event iwe; | ||
3783 | |||
3784 | if (bss == NULL || bss->ies == NULL) | ||
3785 | return; | ||
3786 | |||
3787 | /* | ||
3788 | * If needed, fragment the IEs buffer (at IE boundaries) into short | ||
3789 | * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. | ||
3790 | */ | ||
3791 | pos = bss->ies; | ||
3792 | end = pos + bss->ies_len; | ||
3793 | |||
3794 | while (end - pos > IW_GENERIC_IE_MAX) { | ||
3795 | next = pos + 2 + pos[1]; | ||
3796 | while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) | ||
3797 | next = next + 2 + next[1]; | ||
3798 | |||
3799 | memset(&iwe, 0, sizeof(iwe)); | ||
3800 | iwe.cmd = IWEVGENIE; | ||
3801 | iwe.u.data.length = next - pos; | ||
3802 | *current_ev = iwe_stream_add_point(info, *current_ev, | ||
3803 | end_buf, &iwe, pos); | ||
3804 | |||
3805 | pos = next; | ||
3806 | } | ||
3807 | |||
3808 | if (end > pos) { | ||
3809 | memset(&iwe, 0, sizeof(iwe)); | ||
3810 | iwe.cmd = IWEVGENIE; | ||
3811 | iwe.u.data.length = end - pos; | ||
3812 | *current_ev = iwe_stream_add_point(info, *current_ev, | ||
3813 | end_buf, &iwe, pos); | ||
3814 | } | ||
3815 | } | ||
3816 | |||
3817 | |||
3818 | static char * | ||
3819 | ieee80211_sta_scan_result(struct ieee80211_local *local, | ||
3820 | struct iw_request_info *info, | ||
3821 | struct ieee80211_sta_bss *bss, | ||
3822 | char *current_ev, char *end_buf) | ||
3823 | { | ||
3824 | struct iw_event iwe; | ||
3825 | char *buf; | ||
3826 | |||
3827 | if (time_after(jiffies, | ||
3828 | bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) | ||
3829 | return current_ev; | ||
3830 | |||
3831 | memset(&iwe, 0, sizeof(iwe)); | ||
3832 | iwe.cmd = SIOCGIWAP; | ||
3833 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | ||
3834 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); | ||
3835 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
3836 | IW_EV_ADDR_LEN); | ||
3837 | |||
3838 | memset(&iwe, 0, sizeof(iwe)); | ||
3839 | iwe.cmd = SIOCGIWESSID; | ||
3840 | if (bss_mesh_cfg(bss)) { | ||
3841 | iwe.u.data.length = bss_mesh_id_len(bss); | ||
3842 | iwe.u.data.flags = 1; | ||
3843 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
3844 | &iwe, bss_mesh_id(bss)); | ||
3845 | } else { | ||
3846 | iwe.u.data.length = bss->ssid_len; | ||
3847 | iwe.u.data.flags = 1; | ||
3848 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
3849 | &iwe, bss->ssid); | ||
3850 | } | ||
3851 | |||
3852 | if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) | ||
3853 | || bss_mesh_cfg(bss)) { | ||
3854 | memset(&iwe, 0, sizeof(iwe)); | ||
3855 | iwe.cmd = SIOCGIWMODE; | ||
3856 | if (bss_mesh_cfg(bss)) | ||
3857 | iwe.u.mode = IW_MODE_MESH; | ||
3858 | else if (bss->capability & WLAN_CAPABILITY_ESS) | ||
3859 | iwe.u.mode = IW_MODE_MASTER; | ||
3860 | else | ||
3861 | iwe.u.mode = IW_MODE_ADHOC; | ||
3862 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | ||
3863 | &iwe, IW_EV_UINT_LEN); | ||
3864 | } | ||
3865 | |||
3866 | memset(&iwe, 0, sizeof(iwe)); | ||
3867 | iwe.cmd = SIOCGIWFREQ; | ||
3868 | iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq); | ||
3869 | iwe.u.freq.e = 0; | ||
3870 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
3871 | IW_EV_FREQ_LEN); | ||
3872 | |||
3873 | memset(&iwe, 0, sizeof(iwe)); | ||
3874 | iwe.cmd = SIOCGIWFREQ; | ||
3875 | iwe.u.freq.m = bss->freq; | ||
3876 | iwe.u.freq.e = 6; | ||
3877 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
3878 | IW_EV_FREQ_LEN); | ||
3879 | memset(&iwe, 0, sizeof(iwe)); | ||
3880 | iwe.cmd = IWEVQUAL; | ||
3881 | iwe.u.qual.qual = bss->qual; | ||
3882 | iwe.u.qual.level = bss->signal; | ||
3883 | iwe.u.qual.noise = bss->noise; | ||
3884 | iwe.u.qual.updated = local->wstats_flags; | ||
3885 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
3886 | IW_EV_QUAL_LEN); | ||
3887 | |||
3888 | memset(&iwe, 0, sizeof(iwe)); | ||
3889 | iwe.cmd = SIOCGIWENCODE; | ||
3890 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) | ||
3891 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | ||
3892 | else | ||
3893 | iwe.u.data.flags = IW_ENCODE_DISABLED; | ||
3894 | iwe.u.data.length = 0; | ||
3895 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
3896 | &iwe, ""); | ||
3897 | |||
3898 | ieee80211_sta_add_scan_ies(info, bss, ¤t_ev, end_buf); | ||
3899 | |||
3900 | if (bss->supp_rates_len > 0) { | ||
3901 | /* display all supported rates in readable format */ | ||
3902 | char *p = current_ev + iwe_stream_lcp_len(info); | ||
3903 | int i; | ||
3904 | |||
3905 | memset(&iwe, 0, sizeof(iwe)); | ||
3906 | iwe.cmd = SIOCGIWRATE; | ||
3907 | /* Those two flags are ignored... */ | ||
3908 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | ||
3909 | |||
3910 | for (i = 0; i < bss->supp_rates_len; i++) { | ||
3911 | iwe.u.bitrate.value = ((bss->supp_rates[i] & | ||
3912 | 0x7f) * 500000); | ||
3913 | p = iwe_stream_add_value(info, current_ev, p, | ||
3914 | end_buf, &iwe, IW_EV_PARAM_LEN); | ||
3915 | } | ||
3916 | current_ev = p; | ||
3917 | } | ||
3918 | |||
3919 | buf = kmalloc(30, GFP_ATOMIC); | ||
3920 | if (buf) { | ||
3921 | memset(&iwe, 0, sizeof(iwe)); | ||
3922 | iwe.cmd = IWEVCUSTOM; | ||
3923 | sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp)); | ||
3924 | iwe.u.data.length = strlen(buf); | ||
3925 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
3926 | &iwe, buf); | ||
3927 | memset(&iwe, 0, sizeof(iwe)); | ||
3928 | iwe.cmd = IWEVCUSTOM; | ||
3929 | sprintf(buf, " Last beacon: %dms ago", | ||
3930 | jiffies_to_msecs(jiffies - bss->last_update)); | ||
3931 | iwe.u.data.length = strlen(buf); | ||
3932 | current_ev = iwe_stream_add_point(info, current_ev, | ||
3933 | end_buf, &iwe, buf); | ||
3934 | kfree(buf); | ||
3935 | } | ||
3936 | |||
3937 | if (bss_mesh_cfg(bss)) { | ||
3938 | u8 *cfg = bss_mesh_cfg(bss); | ||
3939 | buf = kmalloc(50, GFP_ATOMIC); | ||
3940 | if (buf) { | ||
3941 | memset(&iwe, 0, sizeof(iwe)); | ||
3942 | iwe.cmd = IWEVCUSTOM; | ||
3943 | sprintf(buf, "Mesh network (version %d)", cfg[0]); | ||
3944 | iwe.u.data.length = strlen(buf); | ||
3945 | current_ev = iwe_stream_add_point(info, current_ev, | ||
3946 | end_buf, | ||
3947 | &iwe, buf); | ||
3948 | sprintf(buf, "Path Selection Protocol ID: " | ||
3949 | "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3], | ||
3950 | cfg[4]); | ||
3951 | iwe.u.data.length = strlen(buf); | ||
3952 | current_ev = iwe_stream_add_point(info, current_ev, | ||
3953 | end_buf, | ||
3954 | &iwe, buf); | ||
3955 | sprintf(buf, "Path Selection Metric ID: " | ||
3956 | "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7], | ||
3957 | cfg[8]); | ||
3958 | iwe.u.data.length = strlen(buf); | ||
3959 | current_ev = iwe_stream_add_point(info, current_ev, | ||
3960 | end_buf, | ||
3961 | &iwe, buf); | ||
3962 | sprintf(buf, "Congestion Control Mode ID: " | ||
3963 | "0x%02X%02X%02X%02X", cfg[9], cfg[10], | ||
3964 | cfg[11], cfg[12]); | ||
3965 | iwe.u.data.length = strlen(buf); | ||
3966 | current_ev = iwe_stream_add_point(info, current_ev, | ||
3967 | end_buf, | ||
3968 | &iwe, buf); | ||
3969 | sprintf(buf, "Channel Precedence: " | ||
3970 | "0x%02X%02X%02X%02X", cfg[13], cfg[14], | ||
3971 | cfg[15], cfg[16]); | ||
3972 | iwe.u.data.length = strlen(buf); | ||
3973 | current_ev = iwe_stream_add_point(info, current_ev, | ||
3974 | end_buf, | ||
3975 | &iwe, buf); | ||
3976 | kfree(buf); | ||
3977 | } | ||
3978 | } | ||
3979 | |||
3980 | return current_ev; | ||
3981 | } | ||
3982 | |||
3983 | |||
3984 | int ieee80211_sta_scan_results(struct ieee80211_local *local, | ||
3985 | struct iw_request_info *info, | ||
3986 | char *buf, size_t len) | ||
3987 | { | ||
3988 | char *current_ev = buf; | ||
3989 | char *end_buf = buf + len; | ||
3990 | struct ieee80211_sta_bss *bss; | ||
3991 | |||
3992 | spin_lock_bh(&local->sta_bss_lock); | ||
3993 | list_for_each_entry(bss, &local->sta_bss_list, list) { | ||
3994 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { | ||
3995 | spin_unlock_bh(&local->sta_bss_lock); | ||
3996 | return -E2BIG; | ||
3997 | } | ||
3998 | current_ev = ieee80211_sta_scan_result(local, info, bss, | ||
3999 | current_ev, end_buf); | ||
4000 | } | ||
4001 | spin_unlock_bh(&local->sta_bss_lock); | ||
4002 | return current_ev - buf; | ||
4003 | } | ||
4004 | |||
4005 | |||
4006 | int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len) | 3465 | int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len) |
4007 | { | 3466 | { |
4008 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | 3467 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
@@ -4290,3 +3749,17 @@ void ieee80211_sta_work(struct work_struct *work) | |||
4290 | WLAN_REASON_UNSPECIFIED); | 3749 | WLAN_REASON_UNSPECIFIED); |
4291 | } | 3750 | } |
4292 | } | 3751 | } |
3752 | |||
3753 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) | ||
3754 | { | ||
3755 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; | ||
3756 | struct ieee80211_if_sta *ifsta; | ||
3757 | |||
3758 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | ||
3759 | ifsta = &sdata->u.sta; | ||
3760 | if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) || | ||
3761 | (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) && | ||
3762 | !ieee80211_sta_active_ibss(sdata))) | ||
3763 | ieee80211_sta_find_ibss(sdata, ifsta); | ||
3764 | } | ||
3765 | } | ||
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c new file mode 100644 index 000000000000..68fa782acd75 --- /dev/null +++ b/net/mac80211/scan.c | |||
@@ -0,0 +1,553 @@ | |||
1 | /* | ||
2 | * BSS client mode implementation | ||
3 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> | ||
4 | * Copyright 2004, Instant802 Networks, Inc. | ||
5 | * Copyright 2005, Devicescape Software, Inc. | ||
6 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> | ||
7 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | */ | ||
13 | |||
14 | #include <linux/wireless.h> | ||
15 | #include <linux/if_arp.h> | ||
16 | #include <net/mac80211.h> | ||
17 | #include <net/iw_handler.h> | ||
18 | |||
19 | #include "ieee80211_i.h" | ||
20 | |||
21 | #define IEEE80211_PROBE_DELAY (HZ / 33) | ||
22 | #define IEEE80211_CHANNEL_TIME (HZ / 33) | ||
23 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) | ||
24 | |||
25 | |||
26 | static void ieee80211_send_nullfunc(struct ieee80211_local *local, | ||
27 | struct ieee80211_sub_if_data *sdata, | ||
28 | int powersave) | ||
29 | { | ||
30 | struct sk_buff *skb; | ||
31 | struct ieee80211_hdr *nullfunc; | ||
32 | __le16 fc; | ||
33 | |||
34 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); | ||
35 | if (!skb) { | ||
36 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " | ||
37 | "frame\n", sdata->dev->name); | ||
38 | return; | ||
39 | } | ||
40 | skb_reserve(skb, local->hw.extra_tx_headroom); | ||
41 | |||
42 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); | ||
43 | memset(nullfunc, 0, 24); | ||
44 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | | ||
45 | IEEE80211_FCTL_TODS); | ||
46 | if (powersave) | ||
47 | fc |= cpu_to_le16(IEEE80211_FCTL_PM); | ||
48 | nullfunc->frame_control = fc; | ||
49 | memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); | ||
50 | memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); | ||
51 | memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); | ||
52 | |||
53 | ieee80211_sta_tx(sdata, skb, 0); | ||
54 | } | ||
55 | |||
56 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) | ||
57 | { | ||
58 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || | ||
59 | ieee80211_vif_is_mesh(&sdata->vif)) | ||
60 | ieee80211_sta_timer((unsigned long)sdata); | ||
61 | } | ||
62 | |||
63 | void ieee80211_scan_completed(struct ieee80211_hw *hw) | ||
64 | { | ||
65 | struct ieee80211_local *local = hw_to_local(hw); | ||
66 | struct ieee80211_sub_if_data *sdata; | ||
67 | union iwreq_data wrqu; | ||
68 | |||
69 | local->last_scan_completed = jiffies; | ||
70 | memset(&wrqu, 0, sizeof(wrqu)); | ||
71 | wireless_send_event(local->scan_sdata->dev, SIOCGIWSCAN, &wrqu, NULL); | ||
72 | |||
73 | if (local->sta_hw_scanning) { | ||
74 | local->sta_hw_scanning = 0; | ||
75 | if (ieee80211_hw_config(local)) | ||
76 | printk(KERN_DEBUG "%s: failed to restore operational " | ||
77 | "channel after scan\n", wiphy_name(local->hw.wiphy)); | ||
78 | /* Restart STA timer for HW scan case */ | ||
79 | rcu_read_lock(); | ||
80 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | ||
81 | ieee80211_restart_sta_timer(sdata); | ||
82 | rcu_read_unlock(); | ||
83 | |||
84 | goto done; | ||
85 | } | ||
86 | |||
87 | local->sta_sw_scanning = 0; | ||
88 | if (ieee80211_hw_config(local)) | ||
89 | printk(KERN_DEBUG "%s: failed to restore operational " | ||
90 | "channel after scan\n", wiphy_name(local->hw.wiphy)); | ||
91 | |||
92 | |||
93 | netif_tx_lock_bh(local->mdev); | ||
94 | netif_addr_lock(local->mdev); | ||
95 | local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; | ||
96 | local->ops->configure_filter(local_to_hw(local), | ||
97 | FIF_BCN_PRBRESP_PROMISC, | ||
98 | &local->filter_flags, | ||
99 | local->mdev->mc_count, | ||
100 | local->mdev->mc_list); | ||
101 | |||
102 | netif_addr_unlock(local->mdev); | ||
103 | netif_tx_unlock_bh(local->mdev); | ||
104 | |||
105 | rcu_read_lock(); | ||
106 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | ||
107 | /* Tell AP we're back */ | ||
108 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { | ||
109 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { | ||
110 | ieee80211_send_nullfunc(local, sdata, 0); | ||
111 | netif_tx_wake_all_queues(sdata->dev); | ||
112 | } | ||
113 | } else | ||
114 | netif_tx_wake_all_queues(sdata->dev); | ||
115 | |||
116 | ieee80211_restart_sta_timer(sdata); | ||
117 | } | ||
118 | rcu_read_unlock(); | ||
119 | |||
120 | done: | ||
121 | ieee80211_mlme_notify_scan_completed(local); | ||
122 | } | ||
123 | EXPORT_SYMBOL(ieee80211_scan_completed); | ||
124 | |||
125 | |||
126 | void ieee80211_sta_scan_work(struct work_struct *work) | ||
127 | { | ||
128 | struct ieee80211_local *local = | ||
129 | container_of(work, struct ieee80211_local, scan_work.work); | ||
130 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; | ||
131 | struct ieee80211_supported_band *sband; | ||
132 | struct ieee80211_channel *chan; | ||
133 | int skip; | ||
134 | unsigned long next_delay = 0; | ||
135 | |||
136 | if (!local->sta_sw_scanning) | ||
137 | return; | ||
138 | |||
139 | switch (local->scan_state) { | ||
140 | case SCAN_SET_CHANNEL: | ||
141 | /* | ||
142 | * Get current scan band. scan_band may be IEEE80211_NUM_BANDS | ||
143 | * after we successfully scanned the last channel of the last | ||
144 | * band (and the last band is supported by the hw) | ||
145 | */ | ||
146 | if (local->scan_band < IEEE80211_NUM_BANDS) | ||
147 | sband = local->hw.wiphy->bands[local->scan_band]; | ||
148 | else | ||
149 | sband = NULL; | ||
150 | |||
151 | /* | ||
152 | * If we are at an unsupported band and have more bands | ||
153 | * left to scan, advance to the next supported one. | ||
154 | */ | ||
155 | while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) { | ||
156 | local->scan_band++; | ||
157 | sband = local->hw.wiphy->bands[local->scan_band]; | ||
158 | local->scan_channel_idx = 0; | ||
159 | } | ||
160 | |||
161 | /* if no more bands/channels left, complete scan */ | ||
162 | if (!sband || local->scan_channel_idx >= sband->n_channels) { | ||
163 | ieee80211_scan_completed(local_to_hw(local)); | ||
164 | return; | ||
165 | } | ||
166 | skip = 0; | ||
167 | chan = &sband->channels[local->scan_channel_idx]; | ||
168 | |||
169 | if (chan->flags & IEEE80211_CHAN_DISABLED || | ||
170 | (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && | ||
171 | chan->flags & IEEE80211_CHAN_NO_IBSS)) | ||
172 | skip = 1; | ||
173 | |||
174 | if (!skip) { | ||
175 | local->scan_channel = chan; | ||
176 | if (ieee80211_hw_config(local)) { | ||
177 | printk(KERN_DEBUG "%s: failed to set freq to " | ||
178 | "%d MHz for scan\n", wiphy_name(local->hw.wiphy), | ||
179 | chan->center_freq); | ||
180 | skip = 1; | ||
181 | } | ||
182 | } | ||
183 | |||
184 | /* advance state machine to next channel/band */ | ||
185 | local->scan_channel_idx++; | ||
186 | if (local->scan_channel_idx >= sband->n_channels) { | ||
187 | /* | ||
188 | * scan_band may end up == IEEE80211_NUM_BANDS, but | ||
189 | * we'll catch that case above and complete the scan | ||
190 | * if that is the case. | ||
191 | */ | ||
192 | local->scan_band++; | ||
193 | local->scan_channel_idx = 0; | ||
194 | } | ||
195 | |||
196 | if (skip) | ||
197 | break; | ||
198 | |||
199 | next_delay = IEEE80211_PROBE_DELAY + | ||
200 | usecs_to_jiffies(local->hw.channel_change_time); | ||
201 | local->scan_state = SCAN_SEND_PROBE; | ||
202 | break; | ||
203 | case SCAN_SEND_PROBE: | ||
204 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; | ||
205 | local->scan_state = SCAN_SET_CHANNEL; | ||
206 | |||
207 | if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN) | ||
208 | break; | ||
209 | ieee80211_send_probe_req(sdata, NULL, local->scan_ssid, | ||
210 | local->scan_ssid_len); | ||
211 | next_delay = IEEE80211_CHANNEL_TIME; | ||
212 | break; | ||
213 | } | ||
214 | |||
215 | if (local->sta_sw_scanning) | ||
216 | queue_delayed_work(local->hw.workqueue, &local->scan_work, | ||
217 | next_delay); | ||
218 | } | ||
219 | |||
220 | |||
221 | int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata, | ||
222 | u8 *ssid, size_t ssid_len) | ||
223 | { | ||
224 | struct ieee80211_local *local = scan_sdata->local; | ||
225 | struct ieee80211_sub_if_data *sdata; | ||
226 | |||
227 | if (ssid_len > IEEE80211_MAX_SSID_LEN) | ||
228 | return -EINVAL; | ||
229 | |||
230 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) | ||
231 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS | ||
232 | * BSSID: MACAddress | ||
233 | * SSID | ||
234 | * ScanType: ACTIVE, PASSIVE | ||
235 | * ProbeDelay: delay (in microseconds) to be used prior to transmitting | ||
236 | * a Probe frame during active scanning | ||
237 | * ChannelList | ||
238 | * MinChannelTime (>= ProbeDelay), in TU | ||
239 | * MaxChannelTime: (>= MinChannelTime), in TU | ||
240 | */ | ||
241 | |||
242 | /* MLME-SCAN.confirm | ||
243 | * BSSDescriptionSet | ||
244 | * ResultCode: SUCCESS, INVALID_PARAMETERS | ||
245 | */ | ||
246 | |||
247 | if (local->sta_sw_scanning || local->sta_hw_scanning) { | ||
248 | if (local->scan_sdata == scan_sdata) | ||
249 | return 0; | ||
250 | return -EBUSY; | ||
251 | } | ||
252 | |||
253 | if (local->ops->hw_scan) { | ||
254 | int rc = local->ops->hw_scan(local_to_hw(local), | ||
255 | ssid, ssid_len); | ||
256 | if (!rc) { | ||
257 | local->sta_hw_scanning = 1; | ||
258 | local->scan_sdata = scan_sdata; | ||
259 | } | ||
260 | return rc; | ||
261 | } | ||
262 | |||
263 | local->sta_sw_scanning = 1; | ||
264 | |||
265 | rcu_read_lock(); | ||
266 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | ||
267 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { | ||
268 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { | ||
269 | netif_tx_stop_all_queues(sdata->dev); | ||
270 | ieee80211_send_nullfunc(local, sdata, 1); | ||
271 | } | ||
272 | } else | ||
273 | netif_tx_stop_all_queues(sdata->dev); | ||
274 | } | ||
275 | rcu_read_unlock(); | ||
276 | |||
277 | if (ssid) { | ||
278 | local->scan_ssid_len = ssid_len; | ||
279 | memcpy(local->scan_ssid, ssid, ssid_len); | ||
280 | } else | ||
281 | local->scan_ssid_len = 0; | ||
282 | local->scan_state = SCAN_SET_CHANNEL; | ||
283 | local->scan_channel_idx = 0; | ||
284 | local->scan_band = IEEE80211_BAND_2GHZ; | ||
285 | local->scan_sdata = scan_sdata; | ||
286 | |||
287 | netif_addr_lock_bh(local->mdev); | ||
288 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; | ||
289 | local->ops->configure_filter(local_to_hw(local), | ||
290 | FIF_BCN_PRBRESP_PROMISC, | ||
291 | &local->filter_flags, | ||
292 | local->mdev->mc_count, | ||
293 | local->mdev->mc_list); | ||
294 | netif_addr_unlock_bh(local->mdev); | ||
295 | |||
296 | /* TODO: start scan as soon as all nullfunc frames are ACKed */ | ||
297 | queue_delayed_work(local->hw.workqueue, &local->scan_work, | ||
298 | IEEE80211_CHANNEL_TIME); | ||
299 | |||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | |||
304 | int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t ssid_len) | ||
305 | { | ||
306 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | ||
307 | struct ieee80211_local *local = sdata->local; | ||
308 | |||
309 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) | ||
310 | return ieee80211_sta_start_scan(sdata, ssid, ssid_len); | ||
311 | |||
312 | if (local->sta_sw_scanning || local->sta_hw_scanning) { | ||
313 | if (local->scan_sdata == sdata) | ||
314 | return 0; | ||
315 | return -EBUSY; | ||
316 | } | ||
317 | |||
318 | ifsta->scan_ssid_len = ssid_len; | ||
319 | if (ssid_len) | ||
320 | memcpy(ifsta->scan_ssid, ssid, ssid_len); | ||
321 | set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); | ||
322 | queue_work(local->hw.workqueue, &ifsta->work); | ||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | |||
327 | static void ieee80211_sta_add_scan_ies(struct iw_request_info *info, | ||
328 | struct ieee80211_sta_bss *bss, | ||
329 | char **current_ev, char *end_buf) | ||
330 | { | ||
331 | u8 *pos, *end, *next; | ||
332 | struct iw_event iwe; | ||
333 | |||
334 | if (bss == NULL || bss->ies == NULL) | ||
335 | return; | ||
336 | |||
337 | /* | ||
338 | * If needed, fragment the IEs buffer (at IE boundaries) into short | ||
339 | * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. | ||
340 | */ | ||
341 | pos = bss->ies; | ||
342 | end = pos + bss->ies_len; | ||
343 | |||
344 | while (end - pos > IW_GENERIC_IE_MAX) { | ||
345 | next = pos + 2 + pos[1]; | ||
346 | while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) | ||
347 | next = next + 2 + next[1]; | ||
348 | |||
349 | memset(&iwe, 0, sizeof(iwe)); | ||
350 | iwe.cmd = IWEVGENIE; | ||
351 | iwe.u.data.length = next - pos; | ||
352 | *current_ev = iwe_stream_add_point(info, *current_ev, | ||
353 | end_buf, &iwe, pos); | ||
354 | |||
355 | pos = next; | ||
356 | } | ||
357 | |||
358 | if (end > pos) { | ||
359 | memset(&iwe, 0, sizeof(iwe)); | ||
360 | iwe.cmd = IWEVGENIE; | ||
361 | iwe.u.data.length = end - pos; | ||
362 | *current_ev = iwe_stream_add_point(info, *current_ev, | ||
363 | end_buf, &iwe, pos); | ||
364 | } | ||
365 | } | ||
366 | |||
367 | |||
368 | static char * | ||
369 | ieee80211_sta_scan_result(struct ieee80211_local *local, | ||
370 | struct iw_request_info *info, | ||
371 | struct ieee80211_sta_bss *bss, | ||
372 | char *current_ev, char *end_buf) | ||
373 | { | ||
374 | struct iw_event iwe; | ||
375 | char *buf; | ||
376 | |||
377 | if (time_after(jiffies, | ||
378 | bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) | ||
379 | return current_ev; | ||
380 | |||
381 | memset(&iwe, 0, sizeof(iwe)); | ||
382 | iwe.cmd = SIOCGIWAP; | ||
383 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | ||
384 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); | ||
385 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
386 | IW_EV_ADDR_LEN); | ||
387 | |||
388 | memset(&iwe, 0, sizeof(iwe)); | ||
389 | iwe.cmd = SIOCGIWESSID; | ||
390 | if (bss_mesh_cfg(bss)) { | ||
391 | iwe.u.data.length = bss_mesh_id_len(bss); | ||
392 | iwe.u.data.flags = 1; | ||
393 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
394 | &iwe, bss_mesh_id(bss)); | ||
395 | } else { | ||
396 | iwe.u.data.length = bss->ssid_len; | ||
397 | iwe.u.data.flags = 1; | ||
398 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
399 | &iwe, bss->ssid); | ||
400 | } | ||
401 | |||
402 | if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) | ||
403 | || bss_mesh_cfg(bss)) { | ||
404 | memset(&iwe, 0, sizeof(iwe)); | ||
405 | iwe.cmd = SIOCGIWMODE; | ||
406 | if (bss_mesh_cfg(bss)) | ||
407 | iwe.u.mode = IW_MODE_MESH; | ||
408 | else if (bss->capability & WLAN_CAPABILITY_ESS) | ||
409 | iwe.u.mode = IW_MODE_MASTER; | ||
410 | else | ||
411 | iwe.u.mode = IW_MODE_ADHOC; | ||
412 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | ||
413 | &iwe, IW_EV_UINT_LEN); | ||
414 | } | ||
415 | |||
416 | memset(&iwe, 0, sizeof(iwe)); | ||
417 | iwe.cmd = SIOCGIWFREQ; | ||
418 | iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq); | ||
419 | iwe.u.freq.e = 0; | ||
420 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
421 | IW_EV_FREQ_LEN); | ||
422 | |||
423 | memset(&iwe, 0, sizeof(iwe)); | ||
424 | iwe.cmd = SIOCGIWFREQ; | ||
425 | iwe.u.freq.m = bss->freq; | ||
426 | iwe.u.freq.e = 6; | ||
427 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
428 | IW_EV_FREQ_LEN); | ||
429 | memset(&iwe, 0, sizeof(iwe)); | ||
430 | iwe.cmd = IWEVQUAL; | ||
431 | iwe.u.qual.qual = bss->qual; | ||
432 | iwe.u.qual.level = bss->signal; | ||
433 | iwe.u.qual.noise = bss->noise; | ||
434 | iwe.u.qual.updated = local->wstats_flags; | ||
435 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
436 | IW_EV_QUAL_LEN); | ||
437 | |||
438 | memset(&iwe, 0, sizeof(iwe)); | ||
439 | iwe.cmd = SIOCGIWENCODE; | ||
440 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) | ||
441 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | ||
442 | else | ||
443 | iwe.u.data.flags = IW_ENCODE_DISABLED; | ||
444 | iwe.u.data.length = 0; | ||
445 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
446 | &iwe, ""); | ||
447 | |||
448 | ieee80211_sta_add_scan_ies(info, bss, ¤t_ev, end_buf); | ||
449 | |||
450 | if (bss->supp_rates_len > 0) { | ||
451 | /* display all supported rates in readable format */ | ||
452 | char *p = current_ev + iwe_stream_lcp_len(info); | ||
453 | int i; | ||
454 | |||
455 | memset(&iwe, 0, sizeof(iwe)); | ||
456 | iwe.cmd = SIOCGIWRATE; | ||
457 | /* Those two flags are ignored... */ | ||
458 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | ||
459 | |||
460 | for (i = 0; i < bss->supp_rates_len; i++) { | ||
461 | iwe.u.bitrate.value = ((bss->supp_rates[i] & | ||
462 | 0x7f) * 500000); | ||
463 | p = iwe_stream_add_value(info, current_ev, p, | ||
464 | end_buf, &iwe, IW_EV_PARAM_LEN); | ||
465 | } | ||
466 | current_ev = p; | ||
467 | } | ||
468 | |||
469 | buf = kmalloc(30, GFP_ATOMIC); | ||
470 | if (buf) { | ||
471 | memset(&iwe, 0, sizeof(iwe)); | ||
472 | iwe.cmd = IWEVCUSTOM; | ||
473 | sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp)); | ||
474 | iwe.u.data.length = strlen(buf); | ||
475 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
476 | &iwe, buf); | ||
477 | memset(&iwe, 0, sizeof(iwe)); | ||
478 | iwe.cmd = IWEVCUSTOM; | ||
479 | sprintf(buf, " Last beacon: %dms ago", | ||
480 | jiffies_to_msecs(jiffies - bss->last_update)); | ||
481 | iwe.u.data.length = strlen(buf); | ||
482 | current_ev = iwe_stream_add_point(info, current_ev, | ||
483 | end_buf, &iwe, buf); | ||
484 | kfree(buf); | ||
485 | } | ||
486 | |||
487 | if (bss_mesh_cfg(bss)) { | ||
488 | u8 *cfg = bss_mesh_cfg(bss); | ||
489 | buf = kmalloc(50, GFP_ATOMIC); | ||
490 | if (buf) { | ||
491 | memset(&iwe, 0, sizeof(iwe)); | ||
492 | iwe.cmd = IWEVCUSTOM; | ||
493 | sprintf(buf, "Mesh network (version %d)", cfg[0]); | ||
494 | iwe.u.data.length = strlen(buf); | ||
495 | current_ev = iwe_stream_add_point(info, current_ev, | ||
496 | end_buf, | ||
497 | &iwe, buf); | ||
498 | sprintf(buf, "Path Selection Protocol ID: " | ||
499 | "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3], | ||
500 | cfg[4]); | ||
501 | iwe.u.data.length = strlen(buf); | ||
502 | current_ev = iwe_stream_add_point(info, current_ev, | ||
503 | end_buf, | ||
504 | &iwe, buf); | ||
505 | sprintf(buf, "Path Selection Metric ID: " | ||
506 | "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7], | ||
507 | cfg[8]); | ||
508 | iwe.u.data.length = strlen(buf); | ||
509 | current_ev = iwe_stream_add_point(info, current_ev, | ||
510 | end_buf, | ||
511 | &iwe, buf); | ||
512 | sprintf(buf, "Congestion Control Mode ID: " | ||
513 | "0x%02X%02X%02X%02X", cfg[9], cfg[10], | ||
514 | cfg[11], cfg[12]); | ||
515 | iwe.u.data.length = strlen(buf); | ||
516 | current_ev = iwe_stream_add_point(info, current_ev, | ||
517 | end_buf, | ||
518 | &iwe, buf); | ||
519 | sprintf(buf, "Channel Precedence: " | ||
520 | "0x%02X%02X%02X%02X", cfg[13], cfg[14], | ||
521 | cfg[15], cfg[16]); | ||
522 | iwe.u.data.length = strlen(buf); | ||
523 | current_ev = iwe_stream_add_point(info, current_ev, | ||
524 | end_buf, | ||
525 | &iwe, buf); | ||
526 | kfree(buf); | ||
527 | } | ||
528 | } | ||
529 | |||
530 | return current_ev; | ||
531 | } | ||
532 | |||
533 | |||
534 | int ieee80211_sta_scan_results(struct ieee80211_local *local, | ||
535 | struct iw_request_info *info, | ||
536 | char *buf, size_t len) | ||
537 | { | ||
538 | char *current_ev = buf; | ||
539 | char *end_buf = buf + len; | ||
540 | struct ieee80211_sta_bss *bss; | ||
541 | |||
542 | spin_lock_bh(&local->sta_bss_lock); | ||
543 | list_for_each_entry(bss, &local->sta_bss_list, list) { | ||
544 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { | ||
545 | spin_unlock_bh(&local->sta_bss_lock); | ||
546 | return -E2BIG; | ||
547 | } | ||
548 | current_ev = ieee80211_sta_scan_result(local, info, bss, | ||
549 | current_ev, end_buf); | ||
550 | } | ||
551 | spin_unlock_bh(&local->sta_bss_lock); | ||
552 | return current_ev - buf; | ||
553 | } | ||