scan.c revision 0a51b27e956bd9580296c48191b78175ed8b5971
10a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg/* 20a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * BSS client mode implementation 30a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> 40a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * Copyright 2004, Instant802 Networks, Inc. 50a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * Copyright 2005, Devicescape Software, Inc. 60a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 70a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * Copyright 2007, Michael Wu <flamingice@sourmilk.net> 80a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * 90a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * This program is free software; you can redistribute it and/or modify 100a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * it under the terms of the GNU General Public License version 2 as 110a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * published by the Free Software Foundation. 120a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg */ 130a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 140a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg#include <linux/wireless.h> 150a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg#include <linux/if_arp.h> 160a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg#include <net/mac80211.h> 170a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg#include <net/iw_handler.h> 180a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 190a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg#include "ieee80211_i.h" 200a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 210a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg#define IEEE80211_PROBE_DELAY (HZ / 33) 220a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg#define IEEE80211_CHANNEL_TIME (HZ / 33) 230a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) 240a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 250a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 260a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergstatic void ieee80211_send_nullfunc(struct ieee80211_local *local, 270a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_sub_if_data *sdata, 280a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg int powersave) 290a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg{ 300a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct sk_buff *skb; 310a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_hdr *nullfunc; 320a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg __le16 fc; 330a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 340a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); 350a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (!skb) { 360a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " 370a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg "frame\n", sdata->dev->name); 380a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return; 390a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 400a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg skb_reserve(skb, local->hw.extra_tx_headroom); 410a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 420a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); 430a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(nullfunc, 0, 24); 440a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | 450a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg IEEE80211_FCTL_TODS); 460a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (powersave) 470a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg fc |= cpu_to_le16(IEEE80211_FCTL_PM); 480a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg nullfunc->frame_control = fc; 490a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); 500a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); 510a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); 520a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 530a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_sta_tx(sdata, skb, 0); 540a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg} 550a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 560a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergstatic void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) 570a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg{ 580a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 590a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_vif_is_mesh(&sdata->vif)) 600a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_sta_timer((unsigned long)sdata); 610a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg} 620a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 630a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergvoid ieee80211_scan_completed(struct ieee80211_hw *hw) 640a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg{ 650a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_local *local = hw_to_local(hw); 660a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_sub_if_data *sdata; 670a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg union iwreq_data wrqu; 680a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 690a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->last_scan_completed = jiffies; 700a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&wrqu, 0, sizeof(wrqu)); 710a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg wireless_send_event(local->scan_sdata->dev, SIOCGIWSCAN, &wrqu, NULL); 720a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 730a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->sta_hw_scanning) { 740a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->sta_hw_scanning = 0; 750a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (ieee80211_hw_config(local)) 760a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg printk(KERN_DEBUG "%s: failed to restore operational " 770a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg "channel after scan\n", wiphy_name(local->hw.wiphy)); 780a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* Restart STA timer for HW scan case */ 790a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg rcu_read_lock(); 800a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg list_for_each_entry_rcu(sdata, &local->interfaces, list) 810a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_restart_sta_timer(sdata); 820a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg rcu_read_unlock(); 830a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 840a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg goto done; 850a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 860a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 870a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->sta_sw_scanning = 0; 880a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (ieee80211_hw_config(local)) 890a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg printk(KERN_DEBUG "%s: failed to restore operational " 900a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg "channel after scan\n", wiphy_name(local->hw.wiphy)); 910a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 920a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 930a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_tx_lock_bh(local->mdev); 940a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_addr_lock(local->mdev); 950a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; 960a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->ops->configure_filter(local_to_hw(local), 970a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg FIF_BCN_PRBRESP_PROMISC, 980a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &local->filter_flags, 990a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->mdev->mc_count, 1000a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->mdev->mc_list); 1010a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1020a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_addr_unlock(local->mdev); 1030a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_tx_unlock_bh(local->mdev); 1040a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1050a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg rcu_read_lock(); 1060a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg list_for_each_entry_rcu(sdata, &local->interfaces, list) { 1070a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* Tell AP we're back */ 1080a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { 1090a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { 1100a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_send_nullfunc(local, sdata, 0); 1110a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_tx_wake_all_queues(sdata->dev); 1120a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 1130a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } else 1140a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_tx_wake_all_queues(sdata->dev); 1150a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1160a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_restart_sta_timer(sdata); 1170a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 1180a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg rcu_read_unlock(); 1190a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1200a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg done: 1210a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_mlme_notify_scan_completed(local); 1220a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg} 1230a51b27e956bd9580296c48191b78175ed8b5971Johannes BergEXPORT_SYMBOL(ieee80211_scan_completed); 1240a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1250a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1260a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergvoid ieee80211_sta_scan_work(struct work_struct *work) 1270a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg{ 1280a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_local *local = 1290a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg container_of(work, struct ieee80211_local, scan_work.work); 1300a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_sub_if_data *sdata = local->scan_sdata; 1310a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_supported_band *sband; 1320a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_channel *chan; 1330a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg int skip; 1340a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg unsigned long next_delay = 0; 1350a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1360a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (!local->sta_sw_scanning) 1370a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return; 1380a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1390a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg switch (local->scan_state) { 1400a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg case SCAN_SET_CHANNEL: 1410a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* 1420a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * Get current scan band. scan_band may be IEEE80211_NUM_BANDS 1430a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * after we successfully scanned the last channel of the last 1440a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * band (and the last band is supported by the hw) 1450a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg */ 1460a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->scan_band < IEEE80211_NUM_BANDS) 1470a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sband = local->hw.wiphy->bands[local->scan_band]; 1480a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg else 1490a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sband = NULL; 1500a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1510a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* 1520a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * If we are at an unsupported band and have more bands 1530a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * left to scan, advance to the next supported one. 1540a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg */ 1550a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) { 1560a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_band++; 1570a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sband = local->hw.wiphy->bands[local->scan_band]; 1580a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_channel_idx = 0; 1590a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 1600a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1610a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* if no more bands/channels left, complete scan */ 1620a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (!sband || local->scan_channel_idx >= sband->n_channels) { 1630a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_scan_completed(local_to_hw(local)); 1640a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return; 1650a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 1660a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg skip = 0; 1670a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg chan = &sband->channels[local->scan_channel_idx]; 1680a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1690a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (chan->flags & IEEE80211_CHAN_DISABLED || 1700a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && 1710a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg chan->flags & IEEE80211_CHAN_NO_IBSS)) 1720a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg skip = 1; 1730a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1740a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (!skip) { 1750a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_channel = chan; 1760a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (ieee80211_hw_config(local)) { 1770a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg printk(KERN_DEBUG "%s: failed to set freq to " 1780a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg "%d MHz for scan\n", wiphy_name(local->hw.wiphy), 1790a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg chan->center_freq); 1800a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg skip = 1; 1810a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 1820a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 1830a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1840a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* advance state machine to next channel/band */ 1850a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_channel_idx++; 1860a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->scan_channel_idx >= sband->n_channels) { 1870a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* 1880a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * scan_band may end up == IEEE80211_NUM_BANDS, but 1890a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * we'll catch that case above and complete the scan 1900a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * if that is the case. 1910a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg */ 1920a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_band++; 1930a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_channel_idx = 0; 1940a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 1950a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1960a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (skip) 1970a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg break; 1980a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 1990a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg next_delay = IEEE80211_PROBE_DELAY + 2000a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg usecs_to_jiffies(local->hw.channel_change_time); 2010a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_state = SCAN_SEND_PROBE; 2020a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg break; 2030a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg case SCAN_SEND_PROBE: 2040a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; 2050a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_state = SCAN_SET_CHANNEL; 2060a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2070a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN) 2080a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg break; 2090a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_send_probe_req(sdata, NULL, local->scan_ssid, 2100a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_ssid_len); 2110a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg next_delay = IEEE80211_CHANNEL_TIME; 2120a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg break; 2130a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 2140a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2150a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->sta_sw_scanning) 2160a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg queue_delayed_work(local->hw.workqueue, &local->scan_work, 2170a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg next_delay); 2180a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg} 2190a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2200a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2210a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergint ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata, 2220a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg u8 *ssid, size_t ssid_len) 2230a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg{ 2240a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_local *local = scan_sdata->local; 2250a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_sub_if_data *sdata; 2260a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2270a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (ssid_len > IEEE80211_MAX_SSID_LEN) 2280a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return -EINVAL; 2290a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2300a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) 2310a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS 2320a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * BSSID: MACAddress 2330a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * SSID 2340a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * ScanType: ACTIVE, PASSIVE 2350a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * ProbeDelay: delay (in microseconds) to be used prior to transmitting 2360a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * a Probe frame during active scanning 2370a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * ChannelList 2380a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * MinChannelTime (>= ProbeDelay), in TU 2390a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * MaxChannelTime: (>= MinChannelTime), in TU 2400a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg */ 2410a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2420a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* MLME-SCAN.confirm 2430a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * BSSDescriptionSet 2440a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * ResultCode: SUCCESS, INVALID_PARAMETERS 2450a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg */ 2460a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2470a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->sta_sw_scanning || local->sta_hw_scanning) { 2480a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->scan_sdata == scan_sdata) 2490a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return 0; 2500a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return -EBUSY; 2510a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 2520a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2530a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->ops->hw_scan) { 2540a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg int rc = local->ops->hw_scan(local_to_hw(local), 2550a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ssid, ssid_len); 2560a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (!rc) { 2570a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->sta_hw_scanning = 1; 2580a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_sdata = scan_sdata; 2590a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 2600a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return rc; 2610a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 2620a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2630a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->sta_sw_scanning = 1; 2640a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2650a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg rcu_read_lock(); 2660a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg list_for_each_entry_rcu(sdata, &local->interfaces, list) { 2670a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { 2680a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { 2690a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_tx_stop_all_queues(sdata->dev); 2700a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_send_nullfunc(local, sdata, 1); 2710a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 2720a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } else 2730a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_tx_stop_all_queues(sdata->dev); 2740a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 2750a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg rcu_read_unlock(); 2760a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2770a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (ssid) { 2780a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_ssid_len = ssid_len; 2790a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memcpy(local->scan_ssid, ssid, ssid_len); 2800a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } else 2810a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_ssid_len = 0; 2820a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_state = SCAN_SET_CHANNEL; 2830a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_channel_idx = 0; 2840a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_band = IEEE80211_BAND_2GHZ; 2850a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->scan_sdata = scan_sdata; 2860a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2870a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_addr_lock_bh(local->mdev); 2880a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; 2890a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->ops->configure_filter(local_to_hw(local), 2900a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg FIF_BCN_PRBRESP_PROMISC, 2910a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &local->filter_flags, 2920a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->mdev->mc_count, 2930a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg local->mdev->mc_list); 2940a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg netif_addr_unlock_bh(local->mdev); 2950a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 2960a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* TODO: start scan as soon as all nullfunc frames are ACKed */ 2970a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg queue_delayed_work(local->hw.workqueue, &local->scan_work, 2980a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg IEEE80211_CHANNEL_TIME); 2990a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3000a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return 0; 3010a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg} 3020a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3030a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3040a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergint ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t ssid_len) 3050a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg{ 3060a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_if_sta *ifsta = &sdata->u.sta; 3070a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_local *local = sdata->local; 3080a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3090a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (sdata->vif.type != IEEE80211_IF_TYPE_STA) 3100a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return ieee80211_sta_start_scan(sdata, ssid, ssid_len); 3110a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3120a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->sta_sw_scanning || local->sta_hw_scanning) { 3130a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (local->scan_sdata == sdata) 3140a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return 0; 3150a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return -EBUSY; 3160a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 3170a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3180a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ifsta->scan_ssid_len = ssid_len; 3190a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (ssid_len) 3200a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memcpy(ifsta->scan_ssid, ssid, ssid_len); 3210a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); 3220a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg queue_work(local->hw.workqueue, &ifsta->work); 3230a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return 0; 3240a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg} 3250a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3260a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3270a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergstatic void ieee80211_sta_add_scan_ies(struct iw_request_info *info, 3280a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_sta_bss *bss, 3290a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg char **current_ev, char *end_buf) 3300a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg{ 3310a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg u8 *pos, *end, *next; 3320a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct iw_event iwe; 3330a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3340a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (bss == NULL || bss->ies == NULL) 3350a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return; 3360a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3370a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* 3380a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * If needed, fragment the IEs buffer (at IE boundaries) into short 3390a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. 3400a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg */ 3410a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg pos = bss->ies; 3420a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end = pos + bss->ies_len; 3430a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3440a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg while (end - pos > IW_GENERIC_IE_MAX) { 3450a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg next = pos + 2 + pos[1]; 3460a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) 3470a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg next = next + 2 + next[1]; 3480a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3490a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 3500a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = IWEVGENIE; 3510a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = next - pos; 3520a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg *current_ev = iwe_stream_add_point(info, *current_ev, 3530a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end_buf, &iwe, pos); 3540a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3550a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg pos = next; 3560a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 3570a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3580a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (end > pos) { 3590a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 3600a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = IWEVGENIE; 3610a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = end - pos; 3620a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg *current_ev = iwe_stream_add_point(info, *current_ev, 3630a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end_buf, &iwe, pos); 3640a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 3650a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg} 3660a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3670a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3680a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergstatic char * 3690a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergieee80211_sta_scan_result(struct ieee80211_local *local, 3700a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct iw_request_info *info, 3710a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_sta_bss *bss, 3720a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg char *current_ev, char *end_buf) 3730a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg{ 3740a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct iw_event iwe; 3750a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg char *buf; 3760a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3770a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (time_after(jiffies, 3780a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) 3790a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return current_ev; 3800a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3810a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 3820a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = SIOCGIWAP; 3830a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 3840a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); 3850a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, 3860a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg IW_EV_ADDR_LEN); 3870a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 3880a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 3890a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = SIOCGIWESSID; 3900a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (bss_mesh_cfg(bss)) { 3910a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = bss_mesh_id_len(bss); 3920a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.flags = 1; 3930a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, end_buf, 3940a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, bss_mesh_id(bss)); 3950a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } else { 3960a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = bss->ssid_len; 3970a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.flags = 1; 3980a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, end_buf, 3990a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, bss->ssid); 4000a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 4010a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4020a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) 4030a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg || bss_mesh_cfg(bss)) { 4040a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 4050a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = SIOCGIWMODE; 4060a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (bss_mesh_cfg(bss)) 4070a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.mode = IW_MODE_MESH; 4080a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg else if (bss->capability & WLAN_CAPABILITY_ESS) 4090a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.mode = IW_MODE_MASTER; 4100a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg else 4110a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.mode = IW_MODE_ADHOC; 4120a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_event(info, current_ev, end_buf, 4130a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, IW_EV_UINT_LEN); 4140a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 4150a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4160a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 4170a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = SIOCGIWFREQ; 4180a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq); 4190a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.freq.e = 0; 4200a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, 4210a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg IW_EV_FREQ_LEN); 4220a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4230a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 4240a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = SIOCGIWFREQ; 4250a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.freq.m = bss->freq; 4260a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.freq.e = 6; 4270a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, 4280a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg IW_EV_FREQ_LEN); 4290a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 4300a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = IWEVQUAL; 4310a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.qual.qual = bss->qual; 4320a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.qual.level = bss->signal; 4330a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.qual.noise = bss->noise; 4340a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.qual.updated = local->wstats_flags; 4350a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, 4360a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg IW_EV_QUAL_LEN); 4370a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4380a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 4390a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = SIOCGIWENCODE; 4400a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (bss->capability & WLAN_CAPABILITY_PRIVACY) 4410a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; 4420a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg else 4430a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.flags = IW_ENCODE_DISABLED; 4440a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = 0; 4450a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, end_buf, 4460a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, ""); 4470a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4480a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg ieee80211_sta_add_scan_ies(info, bss, ¤t_ev, end_buf); 4490a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4500a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (bss->supp_rates_len > 0) { 4510a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* display all supported rates in readable format */ 4520a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg char *p = current_ev + iwe_stream_lcp_len(info); 4530a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg int i; 4540a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4550a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 4560a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = SIOCGIWRATE; 4570a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg /* Those two flags are ignored... */ 4580a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; 4590a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4600a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg for (i = 0; i < bss->supp_rates_len; i++) { 4610a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.bitrate.value = ((bss->supp_rates[i] & 4620a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 0x7f) * 500000); 4630a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg p = iwe_stream_add_value(info, current_ev, p, 4640a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end_buf, &iwe, IW_EV_PARAM_LEN); 4650a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 4660a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = p; 4670a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 4680a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4690a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg buf = kmalloc(30, GFP_ATOMIC); 4700a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (buf) { 4710a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 4720a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = IWEVCUSTOM; 4730a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp)); 4740a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = strlen(buf); 4750a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, end_buf, 4760a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, buf); 4770a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 4780a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = IWEVCUSTOM; 4790a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sprintf(buf, " Last beacon: %dms ago", 4800a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg jiffies_to_msecs(jiffies - bss->last_update)); 4810a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = strlen(buf); 4820a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, 4830a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end_buf, &iwe, buf); 4840a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg kfree(buf); 4850a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 4860a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 4870a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (bss_mesh_cfg(bss)) { 4880a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg u8 *cfg = bss_mesh_cfg(bss); 4890a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg buf = kmalloc(50, GFP_ATOMIC); 4900a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (buf) { 4910a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg memset(&iwe, 0, sizeof(iwe)); 4920a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.cmd = IWEVCUSTOM; 4930a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sprintf(buf, "Mesh network (version %d)", cfg[0]); 4940a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = strlen(buf); 4950a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, 4960a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end_buf, 4970a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, buf); 4980a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sprintf(buf, "Path Selection Protocol ID: " 4990a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3], 5000a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg cfg[4]); 5010a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = strlen(buf); 5020a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, 5030a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end_buf, 5040a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, buf); 5050a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sprintf(buf, "Path Selection Metric ID: " 5060a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7], 5070a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg cfg[8]); 5080a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = strlen(buf); 5090a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, 5100a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end_buf, 5110a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, buf); 5120a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sprintf(buf, "Congestion Control Mode ID: " 5130a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg "0x%02X%02X%02X%02X", cfg[9], cfg[10], 5140a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg cfg[11], cfg[12]); 5150a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = strlen(buf); 5160a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, 5170a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end_buf, 5180a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, buf); 5190a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg sprintf(buf, "Channel Precedence: " 5200a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg "0x%02X%02X%02X%02X", cfg[13], cfg[14], 5210a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg cfg[15], cfg[16]); 5220a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg iwe.u.data.length = strlen(buf); 5230a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = iwe_stream_add_point(info, current_ev, 5240a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg end_buf, 5250a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg &iwe, buf); 5260a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg kfree(buf); 5270a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 5280a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 5290a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 5300a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return current_ev; 5310a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg} 5320a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 5330a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 5340a51b27e956bd9580296c48191b78175ed8b5971Johannes Bergint ieee80211_sta_scan_results(struct ieee80211_local *local, 5350a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct iw_request_info *info, 5360a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg char *buf, size_t len) 5370a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg{ 5380a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg char *current_ev = buf; 5390a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg char *end_buf = buf + len; 5400a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg struct ieee80211_sta_bss *bss; 5410a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg 5420a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg spin_lock_bh(&local->sta_bss_lock); 5430a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg list_for_each_entry(bss, &local->sta_bss_list, list) { 5440a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg if (buf + len - current_ev <= IW_EV_ADDR_LEN) { 5450a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg spin_unlock_bh(&local->sta_bss_lock); 5460a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return -E2BIG; 5470a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 5480a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev = ieee80211_sta_scan_result(local, info, bss, 5490a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg current_ev, end_buf); 5500a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg } 5510a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg spin_unlock_bh(&local->sta_bss_lock); 5520a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg return current_ev - buf; 5530a51b27e956bd9580296c48191b78175ed8b5971Johannes Berg} 554