rndis_wlan: initiate cfg80211 conversion
PATCH 1/6 rndis_wlan: initiate cfg80211 conversion
From: John W. Linville <[email protected]>
Signed-off-by John W. Linville <[email protected]>
Signed-off-by Jussi Kivilinna <[email protected]>
---
drivers/net/wireless/rndis_wlan.c | 114 ++++++++++++++++++++++++++++--------- 1 files changed, 85 insertions(+), 29 deletions(-)
drivers/net/wireless/rndis_wlan.c +85 -29
@@ -42,6 +42,8 @@#include <linux/ctype.h> #include <linux/spinlock.h> #include <net/iw_handler.h> +#include <net/wireless.h> +#include <net/cfg80211.h> #include <linux/usb/usbnet.h> #include <linux/usb/rndis_host.h>
@@ -316,12 +318,44 @@ enum wpa_key_mgmt { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,#define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set)) +static const struct ieee80211_channel rndis_channels[] = { + { .center_freq =2412 }, + { .center_freq =2417 }, + { .center_freq =2422 }, + { .center_freq =2427 }, + { .center_freq =2432 }, + { .center_freq =2437 }, + { .center_freq =2442 }, + { .center_freq =2447 }, + { .center_freq =2452 }, + { .center_freq =2457 }, + { .center_freq =2462 }, + { .center_freq =2467 }, + { .center_freq =2472 }, + { .center_freq =2484 }, +}; + +static const struct ieee80211_rate rndis_rates[] = { + { .bitrate =10 }, + { .bitrate =20 , .flags =IEEE80211_RATE_SHORT_PREAMBLE }, + { .bitrate =55 , .flags =IEEE80211_RATE_SHORT_PREAMBLE }, + { .bitrate =110 , .flags =IEEE80211_RATE_SHORT_PREAMBLE }, + { .bitrate =60 }, + { .bitrate =90 }, + { .bitrate =120 }, + { .bitrate =180 }, + { .bitrate =240 }, + { .bitrate =360 }, + { .bitrate =480 }, + { .bitrate =540 } +}; +/* RNDIS device private data */ struct rndis_wext_private { -char name[32 ]; -struct usbnet *usbdev; +struct wireless_dev wdev; +struct workqueue_struct *workqueue;struct delayed_work stats_work;struct work_struct work;
@@ -329,6 +363,10 @@ struct rndis_wext_private {spinlock_t stats_lock;unsigned long work_pending; +struct ieee80211_supported_band band; +struct ieee80211_channel channels[ARRAY_SIZE (rndis_channels)]; +struct ieee80211_rate rates[ARRAY_SIZE (rndis_rates)]; +struct iw_statistics iwstats;struct iw_statistics privstats;
@@ -369,7 +407,8 @@ struct rndis_wext_private { }; -static const int rates_80211g[8 ] = {6 ,9 ,12 ,18 ,24 ,36 ,48 ,54 }; +struct cfg80211_ops rndis_config_ops = { }; +void *rndis_wiphy_privid = &rndis_wiphy_privid;static const int bcm4320_power_output[4 ] = {25 ,50 ,75 ,100 };
@@ -1151,15 +1190,15 @@ static int rndis_iw_get_range(struct net_device *dev,/* fill in 802.11g rates */ if (has_80211g_rates) { num = range->num_bitrates; -for (i =0 ; i <ARRAY_SIZE (rates_80211g); i++) { +for (i =4 ; i <ARRAY_SIZE (rndis_rates); i++) {for (j =0 ; j < num; j++) {if (range->bitrate[j] == - rates_80211g[i] *1000000 ) + rndis_rates[i].bitrate *100000 )break ; }if (j == num) range->bitrate[range->num_bitrates++] = - rates_80211g[i] *1000000 ; + rndis_rates[i].bitrate *100000 ;if (range->num_bitrates ==IW_MAX_BITRATES )break ; }
@@ -1204,17 +1243,6 @@ static int rndis_iw_get_range(struct net_device *dev, } -static int rndis_iw_get_name (struct net_device *dev, -struct iw_request_info *info,union iwreq_data *wrqu,char *extra) -{ -struct usbnet *usbdev =netdev_priv (dev); -struct rndis_wext_private *priv =get_rndis_wext_priv (usbdev); - -strcpy (wrqu->name, priv->name); -return 0 ; -} - -static int rndis_iw_set_essid (struct net_device *dev,struct iw_request_info *info,union iwreq_data *wrqu,char *essid) {
@@ -2165,7 +2193,7 @@ static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)static const iw_handler rndis_iw_handler[] = {IW_IOCTL (SIOCSIWCOMMIT ) = rndis_iw_commit, -IW_IOCTL (SIOCGIWNAME ) = rndis_iw_get_name, +IW_IOCTL (SIOCGIWNAME ) = (iw_handler ) cfg80211_wext_giwname,IW_IOCTL (SIOCSIWFREQ ) = rndis_iw_set_freq,IW_IOCTL (SIOCGIWFREQ ) = rndis_iw_get_freq,IW_IOCTL (SIOCSIWMODE ) = rndis_iw_set_mode,
@@ -2338,12 +2366,6 @@ static int rndis_wext_get_caps(struct usbnet *usbdev)break ; } } -if (priv->caps &CAP_MODE_80211A ) -strcat (priv->name,"a" ); -if (priv->caps &CAP_MODE_80211B ) -strcat (priv->name,"b" ); -if (priv->caps &CAP_MODE_80211G ) -strcat (priv->name,"g" ); }return retval;
@@ -2527,20 +2549,28 @@ static int bcm4320_early_init(struct usbnet *usbdev)static int rndis_wext_bind (struct usbnet *usbdev,struct usb_interface *intf) { +struct wiphy *wiphy;struct rndis_wext_private *priv;int retval, len;__le32 tmp; -/* allocate rndis private data */ - priv =kzalloc (sizeof (struct rndis_wext_private ),GFP_KERNEL ); -if (!priv) +/* allocate wiphy and rndis private data +* NOTE: We only support a single virtual interface, so wiphy +* and wireless_dev are somewhat synonymous for this device. +*/ + wiphy =wiphy_new (&rndis_config_ops,sizeof (struct rndis_wext_private )); +if (!wiphy)return -ENOMEM ; + priv =wiphy_priv (wiphy); + usbdev->net->ieee80211_ptr = &priv->wdev; + priv->wdev.wiphy = wiphy; + priv->wdev.iftype =NL80211_IFTYPE_STATION ; +/* These have to be initialized before calling generic_rndis_bind(). * Otherwise we'll be in big trouble in rndis_wext_early_init(). */ usbdev->driver_priv = priv; -strcpy (priv->name,"IEEE802.11" ); usbdev->net->wireless_handlers = &rndis_iw_handlers; priv->usbdev = usbdev;
@@ -2583,7 +2613,31 @@ static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf) | IW_QUAL_QUAL_INVALID |IW_QUAL_LEVEL_INVALID ; +/* fill-out wiphy structure and register w/ cfg80211 */ +memcpy (wiphy->perm_addr, usbdev->net->dev_addr,ETH_ALEN ); + wiphy->privid = rndis_wiphy_privid; + wiphy->interface_modes =BIT (NL80211_IFTYPE_STATION ) + |BIT (NL80211_IFTYPE_ADHOC ); + wiphy->max_scan_ssids =1 ; + +/* TODO: fill-out band information based on priv->caps */ rndis_wext_get_caps (usbdev); + +memcpy (priv->channels, rndis_channels,sizeof (rndis_channels)); +memcpy (priv->rates, rndis_rates,sizeof (rndis_rates)); + priv->band.channels = priv->channels; + priv->band.n_channels =ARRAY_SIZE (rndis_channels); + priv->band.bitrates = priv->rates; + priv->band.n_bitrates =ARRAY_SIZE (rndis_rates); + wiphy->bands[IEEE80211_BAND_2GHZ ] = &priv->band; + +set_wiphy_dev (wiphy, &usbdev->udev->dev); + +if (wiphy_register (wiphy)) { +wiphy_free (wiphy); +return -ENODEV ; + } +set_default_iw_params (usbdev);/* turn radio on */
@@ -2620,9 +2674,11 @@ static void rndis_wext_unbind(struct usbnet *usbdev, struct usb_interface *intf)if (priv && priv->wpa_ie_len)kfree (priv->wpa_ie); -kfree (priv);rndis_unbind (usbdev, intf); + +wiphy_unregister (priv->wdev.wiphy); +wiphy_free (priv->wdev.wiphy); }
PATCH 2/6 rndis_wlan: convert get/set mode to cfg80211
From: John W. Linville <[email protected]>
Signed-off-by John W. Linville <[email protected]>
[edit: made rndis_change_virtual_intf static]
Signed-off-by Jussi Kivilinna <[email protected]>
---
drivers/net/wireless/rndis_wlan.c | 95 +++++++++++++++++-------------------- 1 files changed, 43 insertions(+), 52 deletions(-)
drivers/net/wireless/rndis_wlan.c +43 -52
@@ -406,8 +406,17 @@ struct rndis_wext_private {u8 command_buffer[COMMAND_BUFFER_SIZE ]; }; +/* +* cfg80211 ops +*/ +static int rndis_change_virtual_intf (struct wiphy *wiphy,int ifindex, +enum nl80211_iftype type,u32 *flags, +struct vif_params *params); + +struct cfg80211_ops rndis_config_ops = { + .change_virtual_intf = rndis_change_virtual_intf, +}; -struct cfg80211_ops rndis_config_ops = { };void *rndis_wiphy_privid = &rndis_wiphy_privid;static const int bcm4320_power_output[4 ] = {25 ,50 ,75 ,100 };
@@ -1125,6 +1134,37 @@ static void set_multicast_list(struct usbnet *usbdev)/* +* cfg80211 ops +*/ +static int rndis_change_virtual_intf (struct wiphy *wiphy,int ifindex, +enum nl80211_iftype type,u32 *flags, +struct vif_params *params) +{ +struct net_device *dev; +struct usbnet *usbdev; +int mode; + +/* we're under RTNL */ + dev =__dev_get_by_index (&init_net, ifindex); +if (!dev) +return -ENODEV ; + usbdev =netdev_priv (dev); + +switch (type) { +case NL80211_IFTYPE_ADHOC : + mode = ndis_80211_infra_adhoc; +break ; +case NL80211_IFTYPE_STATION : + mode = ndis_80211_infra_infra; +break ; +default : +return -EINVAL ; + } + +return set_infra_mode (usbdev, mode); +} + +/* * wireless extension handlers */
@@ -1450,55 +1490,6 @@ static int rndis_iw_get_auth(struct net_device *dev, } -static int rndis_iw_get_mode (struct net_device *dev, -struct iw_request_info *info, -union iwreq_data *wrqu,char *extra) -{ -struct usbnet *usbdev =netdev_priv (dev); -struct rndis_wext_private *priv =get_rndis_wext_priv (usbdev); - -switch (priv->infra_mode) { -case ndis_80211_infra_adhoc: - wrqu->mode =IW_MODE_ADHOC ; -break ; -case ndis_80211_infra_infra: - wrqu->mode =IW_MODE_INFRA ; -break ; -/*case ndis_80211_infra_auto_unknown:*/ -default : - wrqu->mode =IW_MODE_AUTO ; -break ; - } -devdbg (usbdev,"SIOCGIWMODE: %08x" , wrqu->mode); -return 0 ; -} - - -static int rndis_iw_set_mode (struct net_device *dev, -struct iw_request_info *info,union iwreq_data *wrqu,char *extra) -{ -struct usbnet *usbdev =netdev_priv (dev); -int mode; - -devdbg (usbdev,"SIOCSIWMODE: %08x" , wrqu->mode); - -switch (wrqu->mode) { -case IW_MODE_ADHOC : - mode = ndis_80211_infra_adhoc; -break ; -case IW_MODE_INFRA : - mode = ndis_80211_infra_infra; -break ; -/*case IW_MODE_AUTO:*/ -default : - mode = ndis_80211_infra_auto_unknown; -break ; - } - -return set_infra_mode (usbdev, mode); -} - -static int rndis_iw_set_encode (struct net_device *dev,struct iw_request_info *info,union iwreq_data *wrqu,char *extra) {
@@ -2196,8 +2187,8 @@ static const iw_handler rndis_iw_handler[] =IW_IOCTL (SIOCGIWNAME ) = (iw_handler ) cfg80211_wext_giwname,IW_IOCTL (SIOCSIWFREQ ) = rndis_iw_set_freq,IW_IOCTL (SIOCGIWFREQ ) = rndis_iw_get_freq, -IW_IOCTL (SIOCSIWMODE ) = rndis_iw_set_mode, -IW_IOCTL (SIOCGIWMODE ) = rndis_iw_get_mode, +IW_IOCTL (SIOCSIWMODE ) = (iw_handler ) cfg80211_wext_siwmode, +IW_IOCTL (SIOCGIWMODE ) = (iw_handler ) cfg80211_wext_giwmode,IW_IOCTL (SIOCGIWRANGE ) = rndis_iw_get_range,IW_IOCTL (SIOCSIWAP ) = rndis_iw_set_bssid, IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
PATCH 3/6 cfg80211: add cfg80211_inform_bss
In reply to Jussi KivilinnaAdded cfg80211_inform_bss() for full-mac devices to use.
Signed-off-by Jussi Kivilinna <[email protected]>
---
include/net/cfg80211.h | 8 ++++++++ net/wireless/scan.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 0 deletions(-)
include/net/cfg80211.h +8 -0
@@ -864,6 +864,14 @@ cfg80211_inform_bss_frame(struct wiphy *wiphy, struct ieee80211_mgmt *mgmt, size_t len, s32 signal, gfp_t gfp); +struct cfg80211_bss * +cfg80211_inform_bss (struct wiphy *wiphy, +struct ieee80211_channel *channel, +const u8 *bssid, +u64 timestamp,u16 capability,u16 beacon_interval, +const u8 *ie,size_t ielen, +s32 signal,gfp_t gfp); + struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy, struct ieee80211_channel *channel, const u8 *bssid,
net/wireless/scan.c +49 -0
55 lines not on this page · raw message
PATCH 4/6 rndis_wlan: change quality level scale
In reply to Jussi KivilinnaChange quality level scale to match cfg80211 CFG80211_SIGNAL_TYPE_UNSPEC.
Signed-off-by Jussi Kivilinna <[email protected]>
---
drivers/net/wireless/rndis_wlan.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/rndis_wlan.c +3 -3
@@ -1269,7 +1269,7 @@ static int rndis_iw_get_range(struct net_device *dev, range->max_frag =2346 ; range->max_qual.qual =100 ; - range->max_qual.level =154 ; + range->max_qual.level =100 ; range->max_qual.updated =IW_QUAL_QUAL_UPDATED |IW_QUAL_LEVEL_UPDATED |IW_QUAL_NOISE_INVALID ;
@@ -1712,7 +1712,7 @@ static char *rndis_translate_scan(struct net_device *dev,devdbg (usbdev,"QUAL %d" ,le32_to_cpu (bssid->rssi)); iwe.cmd =IWEVQUAL ; iwe.u.qual.qual =level_to_qual (le32_to_cpu (bssid->rssi)); - iwe.u.qual.level =le32_to_cpu (bssid->rssi); + iwe.u.qual.level =level_to_qual (le32_to_cpu (bssid->rssi)); iwe.u.qual.updated =IW_QUAL_QUAL_UPDATED |IW_QUAL_LEVEL_UPDATED |IW_QUAL_NOISE_INVALID ;
@@ -2400,7 +2400,7 @@ static void rndis_update_wireless_stats(struct work_struct *work)if (ret ==0 ) {memset (&iwstats.qual,0 ,sizeof (iwstats.qual)); iwstats.qual.qual =level_to_qual (le32_to_cpu (rssi)); - iwstats.qual.level =le32_to_cpu (rssi); + iwstats.qual.level =level_to_qual (le32_to_cpu (rssi)); iwstats.qual.updated =IW_QUAL_QUAL_UPDATED |IW_QUAL_LEVEL_UPDATED |IW_QUAL_NOISE_INVALID ;
PATCH 5/6 rndis_wlan: convert get range to cfg80211
In reply to Jussi KivilinnaSigned-off-by Jussi Kivilinna <[email protected]>
---
drivers/net/wireless/rndis_wlan.c | 110 +------------------------------------ 1 files changed, 2 insertions(+), 108 deletions(-)
drivers/net/wireless/rndis_wlan.c +2 -108
@@ -1176,113 +1176,6 @@ static int rndis_iw_commit(struct net_device *dev, } -static int rndis_iw_get_range (struct net_device *dev, -struct iw_request_info *info,union iwreq_data *wrqu,char *extra) -{ -struct iw_range *range = (struct iw_range *)extra; -struct usbnet *usbdev =netdev_priv (dev); -struct rndis_wext_private *priv =get_rndis_wext_priv (usbdev); -int len, ret, i, j, num, has_80211g_rates; -u8 rates[8 ]; -__le32 tx_power; - -devdbg (usbdev,"SIOCGIWRANGE" ); - -/* clear iw_range struct */ -memset (range,0 ,sizeof (*range)); - wrqu->data.length =sizeof (*range); - - range->txpower_capa =IW_TXPOW_MWATT ; - range->num_txpower =1 ; -if (priv->caps &CAP_SUPPORT_TXPOWER ) { - len =sizeof (tx_power); - ret =rndis_query_oid (usbdev,OID_802_11_TX_POWER_LEVEL , - &tx_power, &len); -if (ret ==0 &&le32_to_cpu (tx_power) !=0xFF ) - range->txpower[0 ] =le32_to_cpu (tx_power); -else - range->txpower[0 ] =get_bcm4320_power (priv); - }else - range->txpower[0 ] =get_bcm4320_power (priv); - - len =sizeof (rates); - ret =rndis_query_oid (usbdev,OID_802_11_SUPPORTED_RATES , &rates, - &len); - has_80211g_rates =0 ; -if (ret ==0 ) { - j =0 ; -for (i =0 ; i < len; i++) { -if (rates[i] ==0 ) -break ; - range->bitrate[j] = (rates[i] &0x7f ) *500000 ; -/* check for non 802.11b rates */ -if (range->bitrate[j] ==6000000 || - range->bitrate[j] ==9000000 || - (range->bitrate[j] >=12000000 && - range->bitrate[j] !=22000000 )) - has_80211g_rates =1 ; - j++; - } - range->num_bitrates = j; - }else - range->num_bitrates =0 ; - -/* fill in 802.11g rates */ -if (has_80211g_rates) { - num = range->num_bitrates; -for (i =4 ; i <ARRAY_SIZE (rndis_rates); i++) { -for (j =0 ; j < num; j++) { -if (range->bitrate[j] == - rndis_rates[i].bitrate *100000 ) -break ; - } -if (j == num) - range->bitrate[range->num_bitrates++] = - rndis_rates[i].bitrate *100000 ; -if (range->num_bitrates ==IW_MAX_BITRATES ) -break ; - } - -/* estimated max real througput in bps */ - range->throughput =54 *1000 *1000 /2 ; - -/* ~35% more with afterburner */ -if (priv->param_afterburner) - range->throughput = range->throughput /100 *135 ; - }else { -/* estimated max real througput in bps */ - range->throughput =11 *1000 *1000 /2 ; - } - - range->num_channels =14 ; - -for (i =0 ; (i <14 ) && (i <IW_MAX_FREQUENCIES ); i++) { - range->freq[i].i = i +1 ; - range->freq[i].m =ieee80211_dsss_chan_to_freq (i +1 ) *100000 ; - range->freq[i].e =1 ; - } - range->num_frequency = i; - - range->min_rts =0 ; - range->max_rts =2347 ; - range->min_frag =256 ; - range->max_frag =2346 ; - - range->max_qual.qual =100 ; - range->max_qual.level =100 ; - range->max_qual.updated =IW_QUAL_QUAL_UPDATED - |IW_QUAL_LEVEL_UPDATED - |IW_QUAL_NOISE_INVALID ; - - range->we_version_compiled =WIRELESS_EXT ; - range->we_version_source =WIRELESS_EXT ; - - range->enc_capa =IW_ENC_CAPA_WPA |IW_ENC_CAPA_WPA2 | -IW_ENC_CAPA_CIPHER_TKIP |IW_ENC_CAPA_CIPHER_CCMP ; -return 0 ; -} - -static int rndis_iw_set_essid (struct net_device *dev,struct iw_request_info *info,union iwreq_data *wrqu,char *essid) {
@@ -2189,7 +2082,7 @@ static const iw_handler rndis_iw_handler[] =IW_IOCTL (SIOCGIWFREQ ) = rndis_iw_get_freq,IW_IOCTL (SIOCSIWMODE ) = (iw_handler ) cfg80211_wext_siwmode,IW_IOCTL (SIOCGIWMODE ) = (iw_handler ) cfg80211_wext_giwmode, -IW_IOCTL (SIOCGIWRANGE ) = rndis_iw_get_range, +IW_IOCTL (SIOCGIWRANGE ) = (iw_handler ) cfg80211_wext_giwrange,IW_IOCTL (SIOCSIWAP ) = rndis_iw_set_bssid,IW_IOCTL (SIOCGIWAP ) = rndis_iw_get_bssid, IW_IOCTL(SIOCSIWSCAN) = rndis_iw_set_scan,
@@ -2621,6 +2514,7 @@ static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf) priv->band.bitrates = priv->rates; priv->band.n_bitrates =ARRAY_SIZE (rndis_rates); wiphy->bands[IEEE80211_BAND_2GHZ ] = &priv->band; + wiphy->signal_type =CFG80211_SIGNAL_TYPE_UNSPEC ;set_wiphy_dev (wiphy, &usbdev->udev->dev);
PATCH 6/6 rndis_wlan: convert scan to cfg80211
In reply to Jussi KivilinnaConvert scan function to cfg80211. Unlike old scan code new code waits 1 sec before getting scan data from device and passing forward to cfg80211.
Signed-off-by Jussi Kivilinna <[email protected]>
---
drivers/net/wireless/rndis_wlan.c | 341 ++++++++++++++++--------------------- 1 files changed, 147 insertions(+), 194 deletions(-)
drivers/net/wireless/rndis_wlan.c +147 -194
@@ -356,8 +356,11 @@ struct rndis_wext_private {struct wireless_dev wdev; +struct cfg80211_scan_request *scan_request; +struct workqueue_struct *workqueue;struct delayed_work stats_work; +struct delayed_work scan_work;struct work_struct work;struct mutex command_lock;spinlock_t stats_lock;
@@ -413,8 +416,12 @@ static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex, enum nl80211_iftype type, u32 *flags, struct vif_params *params); +static int rndis_scan (struct wiphy *wiphy,struct net_device *dev, +struct cfg80211_scan_request *request); +struct cfg80211_ops rndis_config_ops = { .change_virtual_intf = rndis_change_virtual_intf, + .scan = rndis_scan, };void *rndis_wiphy_privid = &rndis_wiphy_privid;
@@ -1164,6 +1171,142 @@ static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex,return set_infra_mode (usbdev, mode); } + +#define SCAN_DELAY_JIFFIES (HZ) +static int rndis_scan (struct wiphy *wiphy,struct net_device *dev, +struct cfg80211_scan_request *request) +{ +struct usbnet *usbdev =netdev_priv (dev); +struct rndis_wext_private *priv =get_rndis_wext_priv (usbdev); +int ret; +__le32 tmp; + +devdbg (usbdev,"cfg80211.scan" ); + +if (!request) +return -EINVAL ; + +if (priv->scan_request && priv->scan_request != request) +return -EBUSY ; + + priv->scan_request = request; + + tmp =ccpu2 (1 ); + ret =rndis_set_oid (usbdev,OID_802_11_BSSID_LIST_SCAN , &tmp, +sizeof (tmp)); +if (ret ==0 ) { +/* Wait before retrieving scan results from device */ +queue_delayed_work (priv->workqueue, &priv->scan_work, +SCAN_DELAY_JIFFIES ); + } + +return ret; +} + + +static struct cfg80211_bss *rndis_bss_info_update (struct usbnet *usbdev, +struct ndis_80211_bssid_ex *bssid) +{ +struct rndis_wext_private *priv =get_rndis_wext_priv (usbdev); +struct ieee80211_channel *channel; +s32 signal; +u64 timestamp; +u16 capability; +u16 beacon_interval; +struct ndis_80211_fixed_ies *fixed; +int ie_len, bssid_len; +u8 *ie; + +/* parse bssid structure */ + bssid_len =le32_to_cpu (bssid->length); + +if (bssid_len <sizeof (struct ndis_80211_bssid_ex ) + +sizeof (struct ndis_80211_fixed_ies )) +return NULL ; + + fixed = (struct ndis_80211_fixed_ies *)bssid->ies; + + ie = (void *)(bssid->ies +sizeof (struct ndis_80211_fixed_ies )); + ie_len =min (bssid_len - (int )sizeof (*bssid), + (int )le32_to_cpu (bssid->ie_length)); + ie_len -=sizeof (struct ndis_80211_fixed_ies ); +if (ie_len <0 ) +return NULL ; + +/* extract data for cfg80211_inform_bss */ + channel =ieee80211_get_channel (priv->wdev.wiphy, +KHZ_TO_MHZ (le32_to_cpu (bssid->config.ds_config))); +if (!channel) +return NULL ; + + signal =level_to_qual (le32_to_cpu (bssid->rssi)); + timestamp =le64_to_cpu (*(__le64 *)fixed->timestamp); + capability =le16_to_cpu (fixed->capabilities); + beacon_interval =le16_to_cpu (fixed->beacon_interval); + +return cfg80211_inform_bss (priv->wdev.wiphy, channel, bssid->mac, + timestamp, capability, beacon_interval, ie, ie_len, signal, +GFP_KERNEL ); +} + + +static int rndis_check_bssid_list (struct usbnet *usbdev) +{ +void *buf =NULL ; +struct ndis_80211_bssid_list_ex *bssid_list; +struct ndis_80211_bssid_ex *bssid; +int ret = -EINVAL , len, count, bssid_len; + +devdbg (usbdev,"check_bssid_list" ); + + len =CONTROL_BUFFER_SIZE ; + buf =kmalloc (len,GFP_KERNEL ); +if (!buf) { + ret = -ENOMEM ; + goto out; + } + + ret =rndis_query_oid (usbdev,OID_802_11_BSSID_LIST , buf, &len); +if (ret !=0 ) + goto out; + + bssid_list = buf; + bssid = bssid_list->bssid; + bssid_len =le32_to_cpu (bssid->length); + count =le32_to_cpu (bssid_list->num_items); +devdbg (usbdev,"check_bssid_list: %d BSSIDs found" , count); + +while (count && ((void *)bssid + bssid_len) <= (buf + len)) { +rndis_bss_info_update (usbdev, bssid); + + bssid = (void *)bssid + bssid_len; + bssid_len =le32_to_cpu (bssid->length); + count--; + } + +out: +kfree (buf); +return ret; +} + + +static void rndis_get_scan_results (struct work_struct *work) +{ +struct rndis_wext_private *priv = + container_of(work, struct rndis_wext_private, scan_work.work); +struct usbnet *usbdev = priv->usbdev; +int ret; + +devdbg (usbdev,"get_scan_results" ); + + ret =rndis_check_bssid_list (usbdev); + +cfg80211_scan_done (priv->scan_request, ret <0 ); + + priv->scan_request =NULL ; +} + +/* * wireless extension handlers */
@@ -1531,198 +1674,6 @@ static int rndis_iw_set_encode_ext(struct net_device *dev, } -static int rndis_iw_set_scan (struct net_device *dev, -struct iw_request_info *info,union iwreq_data *wrqu,char *extra) -{ -struct usbnet *usbdev =netdev_priv (dev); -union iwreq_data evt; -int ret = -EINVAL ; -__le32 tmp; - -devdbg (usbdev,"SIOCSIWSCAN" ); - -if (wrqu->data.flags ==0 ) { - tmp =ccpu2 (1 ); - ret =rndis_set_oid (usbdev,OID_802_11_BSSID_LIST_SCAN , &tmp, -sizeof (tmp)); - evt.data.flags =0 ; - evt.data.length =0 ; -wireless_send_event (dev,SIOCGIWSCAN , &evt,NULL ); - } -return ret; -} - - -static char *rndis_translate_scan (struct net_device *dev, -struct iw_request_info *info,char *cev, -char *end_buf, -struct ndis_80211_bssid_ex *bssid) -{ -struct usbnet *usbdev =netdev_priv (dev); -u8 *ie; -char *current_val; -int bssid_len, ie_len, i; -u32 beacon, atim; -struct iw_event iwe; -unsigned char sbuf[32 ]; - - bssid_len =le32_to_cpu (bssid->length); - -devdbg (usbdev,"BSSID %pM" , bssid->mac); - iwe.cmd =SIOCGIWAP ; - iwe.u.ap_addr.sa_family =ARPHRD_ETHER ; -memcpy (iwe.u.ap_addr.sa_data, bssid->mac,ETH_ALEN ); - cev =iwe_stream_add_event (info, cev, end_buf, &iwe,IW_EV_ADDR_LEN ); - -devdbg (usbdev,"SSID(%d) %s" ,le32_to_cpu (bssid->ssid.length), - bssid->ssid.essid); - iwe.cmd =SIOCGIWESSID ; - iwe.u.essid.length =le32_to_cpu (bssid->ssid.length); - iwe.u.essid.flags =1 ; - cev =iwe_stream_add_point (info, cev, end_buf, &iwe, bssid->ssid.essid); - -devdbg (usbdev,"MODE %d" ,le32_to_cpu (bssid->net_infra)); - iwe.cmd =SIOCGIWMODE ; -switch (le32_to_cpu (bssid->net_infra)) { -case ndis_80211_infra_adhoc: - iwe.u.mode =IW_MODE_ADHOC ; -break ; -case ndis_80211_infra_infra: - iwe.u.mode =IW_MODE_INFRA ; -break ; -/*case ndis_80211_infra_auto_unknown:*/ -default : - iwe.u.mode =IW_MODE_AUTO ; -break ; - } - cev =iwe_stream_add_event (info, cev, end_buf, &iwe,IW_EV_UINT_LEN ); - -devdbg (usbdev,"FREQ %d kHz" ,le32_to_cpu (bssid->config.ds_config)); - iwe.cmd =SIOCGIWFREQ ; -dsconfig_to_freq (le32_to_cpu (bssid->config.ds_config), &iwe.u.freq); - cev =iwe_stream_add_event (info, cev, end_buf, &iwe,IW_EV_FREQ_LEN ); - -devdbg (usbdev,"QUAL %d" ,le32_to_cpu (bssid->rssi)); - iwe.cmd =IWEVQUAL ; - iwe.u.qual.qual =level_to_qual (le32_to_cpu (bssid->rssi)); - iwe.u.qual.level =level_to_qual (le32_to_cpu (bssid->rssi)); - iwe.u.qual.updated =IW_QUAL_QUAL_UPDATED - |IW_QUAL_LEVEL_UPDATED - |IW_QUAL_NOISE_INVALID ; - cev =iwe_stream_add_event (info, cev, end_buf, &iwe,IW_EV_QUAL_LEN ); - -devdbg (usbdev,"ENCODE %d" ,le32_to_cpu (bssid->privacy)); - iwe.cmd =SIOCGIWENCODE ; - iwe.u.data.length =0 ; -if (le32_to_cpu (bssid->privacy) == ndis_80211_priv_accept_all) - iwe.u.data.flags =IW_ENCODE_DISABLED ; -else - iwe.u.data.flags =IW_ENCODE_ENABLED |IW_ENCODE_NOKEY ; - - cev =iwe_stream_add_point (info, cev, end_buf, &iwe,NULL ); - -devdbg (usbdev,"RATES:" ); - current_val = cev +iwe_stream_lcp_len (info); - iwe.cmd =SIOCGIWRATE ; -for (i =0 ; i <sizeof (bssid->rates); i++) { -if (bssid->rates[i] &0x7f ) { - iwe.u.bitrate.value = - ((bssid->rates[i] &0x7f ) * -500000 ); -devdbg (usbdev," %d" , iwe.u.bitrate.value); - current_val =iwe_stream_add_value (info, cev, - current_val, end_buf, &iwe, -IW_EV_PARAM_LEN ); - } - } - -if ((current_val - cev) >iwe_stream_lcp_len (info)) - cev = current_val; - - beacon =le32_to_cpu (bssid->config.beacon_period); -devdbg (usbdev,"BCN_INT %d" , beacon); - iwe.cmd =IWEVCUSTOM ; -snprintf (sbuf,sizeof (sbuf),"bcn_int=%d" , beacon); - iwe.u.data.length =strlen (sbuf); - cev =iwe_stream_add_point (info, cev, end_buf, &iwe, sbuf); - - atim =le32_to_cpu (bssid->config.atim_window); -devdbg (usbdev,"ATIM %d" , atim); - iwe.cmd =IWEVCUSTOM ; -snprintf (sbuf,sizeof (sbuf),"atim=%u" , atim); - iwe.u.data.length =strlen (sbuf); - cev =iwe_stream_add_point (info, cev, end_buf, &iwe, sbuf); - - ie = (void *)(bssid->ies +sizeof (struct ndis_80211_fixed_ies )); - ie_len =min (bssid_len - (int )sizeof (*bssid), - (int )le32_to_cpu (bssid->ie_length)); - ie_len -=sizeof (struct ndis_80211_fixed_ies ); -while (ie_len >=2 &&2 + ie[1 ] <= ie_len) { -if ((ie[0 ] ==WLAN_EID_GENERIC && ie[1 ] >=4 && -memcmp (ie +2 ,"\x00\x50\xf2\x01" ,4 ) ==0 ) || - ie[0 ] ==WLAN_EID_RSN ) { -devdbg (usbdev,"IE: WPA%d" , - (ie[0 ] ==WLAN_EID_RSN ) ?2 :1 ); - iwe.cmd =IWEVGENIE ; -/* arbitrary cut-off at 64 */ - iwe.u.data.length =min (ie[1 ] +2 ,64 ); - cev =iwe_stream_add_point (info, cev, end_buf, &iwe, ie); - } - - ie_len -=2 + ie[1 ]; - ie +=2 + ie[1 ]; - } - -return cev; -} - - -static int rndis_iw_get_scan (struct net_device *dev, -struct iw_request_info *info,union iwreq_data *wrqu,char *extra) -{ -struct usbnet *usbdev =netdev_priv (dev); -void *buf =NULL ; -char *cev = extra; -struct ndis_80211_bssid_list_ex *bssid_list; -struct ndis_80211_bssid_ex *bssid; -int ret = -EINVAL , len, count, bssid_len; - -devdbg (usbdev,"SIOCGIWSCAN" ); - - len =CONTROL_BUFFER_SIZE ; - buf =kmalloc (len,GFP_KERNEL ); -if (!buf) { - ret = -ENOMEM ; - goto out; - } - - ret =rndis_query_oid (usbdev,OID_802_11_BSSID_LIST , buf, &len); - -if (ret !=0 ) - goto out; - - bssid_list = buf; - bssid = bssid_list->bssid; - bssid_len =le32_to_cpu (bssid->length); - count =le32_to_cpu (bssid_list->num_items); -devdbg (usbdev,"SIOCGIWSCAN: %d BSSIDs found" , count); - -while (count && ((void *)bssid + bssid_len) <= (buf + len)) { - cev =rndis_translate_scan (dev, info, cev, - extra +IW_SCAN_MAX_DATA , bssid); - bssid = (void *)bssid + bssid_len; - bssid_len =le32_to_cpu (bssid->length); - count--; - } - -out: - wrqu->data.length = cev - extra; - wrqu->data.flags =0 ; -kfree (buf); -return ret; -} - -static int rndis_iw_set_genie (struct net_device *dev,struct iw_request_info *info,union iwreq_data *wrqu,char *extra) {
@@ -2085,8 +2036,8 @@ static const iw_handler rndis_iw_handler[] =IW_IOCTL (SIOCGIWRANGE ) = (iw_handler ) cfg80211_wext_giwrange,IW_IOCTL (SIOCSIWAP ) = rndis_iw_set_bssid,IW_IOCTL (SIOCGIWAP ) = rndis_iw_get_bssid, -IW_IOCTL (SIOCSIWSCAN ) = rndis_iw_set_scan, -IW_IOCTL (SIOCGIWSCAN ) = rndis_iw_get_scan, +IW_IOCTL (SIOCSIWSCAN ) = (iw_handler ) cfg80211_wext_siwscan, +IW_IOCTL (SIOCGIWSCAN ) = (iw_handler ) cfg80211_wext_giwscan,IW_IOCTL (SIOCSIWESSID ) = rndis_iw_set_essid,IW_IOCTL (SIOCGIWESSID ) = rndis_iw_get_essid, IW_IOCTL(SIOCSIWNICKN) = rndis_iw_set_nick,
@@ -2535,6 +2486,7 @@ static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf)INIT_DELAYED_WORK (&priv->stats_work, rndis_update_wireless_stats);queue_delayed_work (priv->workqueue, &priv->stats_work,round_jiffies_relative (STATS_UPDATE_JIFFIES )); +INIT_DELAYED_WORK (&priv->scan_work, rndis_get_scan_results);INIT_WORK (&priv->work, rndis_wext_worker);return 0 ;
@@ -2553,6 +2505,7 @@ static void rndis_wext_unbind(struct usbnet *usbdev, struct usb_interface *intf)disassociate (usbdev,0 );cancel_delayed_work_sync (&priv->stats_work); +cancel_delayed_work_sync (&priv->scan_work);cancel_work_sync (&priv->work);flush_workqueue (priv->workqueue);destroy_workqueue (priv->workqueue);
Johannes Berg
maintainerWay cool!
johannes