Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Driver for RNDIS based wireless USB devices. |
| 3 | * |
| 4 | * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net> |
Jussi Kivilinna | 9656e85 | 2009-05-22 17:40:12 +0300 | [diff] [blame^] | 5 | * Copyright (C) 2008-2009 by Jussi Kivilinna <jussi.kivilinna@mbnet.fi> |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
| 21 | * Portions of this file are based on NDISwrapper project, |
| 22 | * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani |
| 23 | * http://ndiswrapper.sourceforge.net/ |
| 24 | */ |
| 25 | |
| 26 | // #define DEBUG // error path messages, extra info |
| 27 | // #define VERBOSE // more; success messages |
| 28 | |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/etherdevice.h> |
| 33 | #include <linux/ethtool.h> |
| 34 | #include <linux/workqueue.h> |
| 35 | #include <linux/mutex.h> |
| 36 | #include <linux/mii.h> |
| 37 | #include <linux/usb.h> |
| 38 | #include <linux/usb/cdc.h> |
| 39 | #include <linux/wireless.h> |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 40 | #include <linux/ieee80211.h> |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 41 | #include <linux/if_arp.h> |
| 42 | #include <linux/ctype.h> |
| 43 | #include <linux/spinlock.h> |
| 44 | #include <net/iw_handler.h> |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 45 | #include <net/cfg80211.h> |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 46 | #include <linux/usb/usbnet.h> |
| 47 | #include <linux/usb/rndis_host.h> |
| 48 | |
| 49 | |
| 50 | /* NOTE: All these are settings for Broadcom chipset */ |
| 51 | static char modparam_country[4] = "EU"; |
| 52 | module_param_string(country, modparam_country, 4, 0444); |
| 53 | MODULE_PARM_DESC(country, "Country code (ISO 3166-1 alpha-2), default: EU"); |
| 54 | |
| 55 | static int modparam_frameburst = 1; |
| 56 | module_param_named(frameburst, modparam_frameburst, int, 0444); |
| 57 | MODULE_PARM_DESC(frameburst, "enable frame bursting (default: on)"); |
| 58 | |
| 59 | static int modparam_afterburner = 0; |
| 60 | module_param_named(afterburner, modparam_afterburner, int, 0444); |
| 61 | MODULE_PARM_DESC(afterburner, |
| 62 | "enable afterburner aka '125 High Speed Mode' (default: off)"); |
| 63 | |
| 64 | static int modparam_power_save = 0; |
| 65 | module_param_named(power_save, modparam_power_save, int, 0444); |
| 66 | MODULE_PARM_DESC(power_save, |
| 67 | "set power save mode: 0=off, 1=on, 2=fast (default: off)"); |
| 68 | |
| 69 | static int modparam_power_output = 3; |
| 70 | module_param_named(power_output, modparam_power_output, int, 0444); |
| 71 | MODULE_PARM_DESC(power_output, |
| 72 | "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)"); |
| 73 | |
| 74 | static int modparam_roamtrigger = -70; |
| 75 | module_param_named(roamtrigger, modparam_roamtrigger, int, 0444); |
| 76 | MODULE_PARM_DESC(roamtrigger, |
| 77 | "set roaming dBm trigger: -80=optimize for distance, " |
| 78 | "-60=bandwidth (default: -70)"); |
| 79 | |
| 80 | static int modparam_roamdelta = 1; |
| 81 | module_param_named(roamdelta, modparam_roamdelta, int, 0444); |
| 82 | MODULE_PARM_DESC(roamdelta, |
| 83 | "set roaming tendency: 0=aggressive, 1=moderate, " |
| 84 | "2=conservative (default: moderate)"); |
| 85 | |
| 86 | static int modparam_workaround_interval = 500; |
| 87 | module_param_named(workaround_interval, modparam_workaround_interval, |
| 88 | int, 0444); |
| 89 | MODULE_PARM_DESC(workaround_interval, |
| 90 | "set stall workaround interval in msecs (default: 500)"); |
| 91 | |
| 92 | |
| 93 | /* various RNDIS OID defs */ |
Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 94 | #define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107) |
| 95 | #define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 96 | |
Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 97 | #define OID_GEN_XMIT_OK cpu_to_le32(0x00020101) |
| 98 | #define OID_GEN_RCV_OK cpu_to_le32(0x00020102) |
| 99 | #define OID_GEN_XMIT_ERROR cpu_to_le32(0x00020103) |
| 100 | #define OID_GEN_RCV_ERROR cpu_to_le32(0x00020104) |
| 101 | #define OID_GEN_RCV_NO_BUFFER cpu_to_le32(0x00020105) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 102 | |
Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 103 | #define OID_802_3_PERMANENT_ADDRESS cpu_to_le32(0x01010101) |
| 104 | #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102) |
| 105 | #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103) |
| 106 | #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 107 | |
Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 108 | #define OID_802_11_BSSID cpu_to_le32(0x0d010101) |
| 109 | #define OID_802_11_SSID cpu_to_le32(0x0d010102) |
| 110 | #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108) |
| 111 | #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113) |
| 112 | #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114) |
| 113 | #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115) |
| 114 | #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118) |
| 115 | #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119) |
| 116 | #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a) |
| 117 | #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b) |
| 118 | #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d) |
| 119 | #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e) |
| 120 | #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f) |
| 121 | #define OID_802_11_PMKID cpu_to_le32(0x0d010123) |
| 122 | #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203) |
| 123 | #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204) |
| 124 | #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205) |
| 125 | #define OID_802_11_RSSI cpu_to_le32(0x0d010206) |
| 126 | #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207) |
| 127 | #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209) |
| 128 | #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a) |
| 129 | #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e) |
| 130 | #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211) |
| 131 | #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 132 | |
| 133 | |
| 134 | /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */ |
| 135 | #define WL_NOISE -96 /* typical noise level in dBm */ |
| 136 | #define WL_SIGMAX -32 /* typical maximum signal level in dBm */ |
| 137 | |
| 138 | |
| 139 | /* Assume that Broadcom 4320 (only chipset at time of writing known to be |
| 140 | * based on wireless rndis) has default txpower of 13dBm. |
| 141 | * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications. |
| 142 | * 13dBm == 19.9mW |
| 143 | */ |
| 144 | #define BCM4320_DEFAULT_TXPOWER 20 |
| 145 | |
| 146 | |
| 147 | /* codes for "status" field of completion messages */ |
Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 148 | #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011) |
| 149 | #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 150 | |
| 151 | |
| 152 | /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c |
| 153 | * slightly modified for datatype endianess, etc |
| 154 | */ |
| 155 | #define NDIS_802_11_LENGTH_SSID 32 |
| 156 | #define NDIS_802_11_LENGTH_RATES 8 |
| 157 | #define NDIS_802_11_LENGTH_RATES_EX 16 |
| 158 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 159 | enum ndis_80211_net_type { |
| 160 | ndis_80211_type_freq_hop, |
| 161 | ndis_80211_type_direct_seq, |
| 162 | ndis_80211_type_ofdm_a, |
| 163 | ndis_80211_type_ofdm_g |
| 164 | }; |
| 165 | |
| 166 | enum ndis_80211_net_infra { |
| 167 | ndis_80211_infra_adhoc, |
| 168 | ndis_80211_infra_infra, |
| 169 | ndis_80211_infra_auto_unknown |
| 170 | }; |
| 171 | |
| 172 | enum ndis_80211_auth_mode { |
| 173 | ndis_80211_auth_open, |
| 174 | ndis_80211_auth_shared, |
| 175 | ndis_80211_auth_auto_switch, |
| 176 | ndis_80211_auth_wpa, |
| 177 | ndis_80211_auth_wpa_psk, |
| 178 | ndis_80211_auth_wpa_none, |
| 179 | ndis_80211_auth_wpa2, |
| 180 | ndis_80211_auth_wpa2_psk |
| 181 | }; |
| 182 | |
| 183 | enum ndis_80211_encr_status { |
| 184 | ndis_80211_encr_wep_enabled, |
| 185 | ndis_80211_encr_disabled, |
| 186 | ndis_80211_encr_wep_key_absent, |
| 187 | ndis_80211_encr_not_supported, |
| 188 | ndis_80211_encr_tkip_enabled, |
| 189 | ndis_80211_encr_tkip_key_absent, |
| 190 | ndis_80211_encr_ccmp_enabled, |
| 191 | ndis_80211_encr_ccmp_key_absent |
| 192 | }; |
| 193 | |
| 194 | enum ndis_80211_priv_filter { |
| 195 | ndis_80211_priv_accept_all, |
| 196 | ndis_80211_priv_8021x_wep |
| 197 | }; |
| 198 | |
| 199 | struct ndis_80211_ssid { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 200 | __le32 length; |
| 201 | u8 essid[NDIS_802_11_LENGTH_SSID]; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 202 | } __attribute__((packed)); |
| 203 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 204 | struct ndis_80211_conf_freq_hop { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 205 | __le32 length; |
| 206 | __le32 hop_pattern; |
| 207 | __le32 hop_set; |
| 208 | __le32 dwell_time; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 209 | } __attribute__((packed)); |
| 210 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 211 | struct ndis_80211_conf { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 212 | __le32 length; |
| 213 | __le32 beacon_period; |
| 214 | __le32 atim_window; |
| 215 | __le32 ds_config; |
| 216 | struct ndis_80211_conf_freq_hop fh_config; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 217 | } __attribute__((packed)); |
| 218 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 219 | struct ndis_80211_bssid_ex { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 220 | __le32 length; |
| 221 | u8 mac[6]; |
| 222 | u8 padding[2]; |
| 223 | struct ndis_80211_ssid ssid; |
| 224 | __le32 privacy; |
| 225 | __le32 rssi; |
| 226 | __le32 net_type; |
| 227 | struct ndis_80211_conf config; |
| 228 | __le32 net_infra; |
| 229 | u8 rates[NDIS_802_11_LENGTH_RATES_EX]; |
| 230 | __le32 ie_length; |
| 231 | u8 ies[0]; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 232 | } __attribute__((packed)); |
| 233 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 234 | struct ndis_80211_bssid_list_ex { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 235 | __le32 num_items; |
| 236 | struct ndis_80211_bssid_ex bssid[0]; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 237 | } __attribute__((packed)); |
| 238 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 239 | struct ndis_80211_fixed_ies { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 240 | u8 timestamp[8]; |
| 241 | __le16 beacon_interval; |
| 242 | __le16 capabilities; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 243 | } __attribute__((packed)); |
| 244 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 245 | struct ndis_80211_wep_key { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 246 | __le32 size; |
| 247 | __le32 index; |
| 248 | __le32 length; |
| 249 | u8 material[32]; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 250 | } __attribute__((packed)); |
| 251 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 252 | struct ndis_80211_key { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 253 | __le32 size; |
| 254 | __le32 index; |
| 255 | __le32 length; |
| 256 | u8 bssid[6]; |
| 257 | u8 padding[6]; |
| 258 | u8 rsc[8]; |
| 259 | u8 material[32]; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 260 | } __attribute__((packed)); |
| 261 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 262 | struct ndis_80211_remove_key { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 263 | __le32 size; |
| 264 | __le32 index; |
| 265 | u8 bssid[6]; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 266 | } __attribute__((packed)); |
| 267 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 268 | struct ndis_config_param { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 269 | __le32 name_offs; |
| 270 | __le32 name_length; |
| 271 | __le32 type; |
| 272 | __le32 value_offs; |
| 273 | __le32 value_length; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 274 | } __attribute__((packed)); |
| 275 | |
Scott Ashcroft | 4364623 | 2008-05-27 00:06:15 +0300 | [diff] [blame] | 276 | struct ndis_80211_assoc_info { |
| 277 | __le32 length; |
| 278 | __le16 req_ies; |
| 279 | struct req_ie { |
| 280 | __le16 capa; |
| 281 | __le16 listen_interval; |
| 282 | u8 cur_ap_address[6]; |
| 283 | } req_ie; |
| 284 | __le32 req_ie_length; |
| 285 | __le32 offset_req_ies; |
| 286 | __le16 resp_ies; |
| 287 | struct resp_ie { |
| 288 | __le16 capa; |
| 289 | __le16 status_code; |
| 290 | __le16 assoc_id; |
| 291 | } resp_ie; |
| 292 | __le32 resp_ie_length; |
| 293 | __le32 offset_resp_ies; |
| 294 | } __attribute__((packed)); |
| 295 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 296 | /* these have to match what is in wpa_supplicant */ |
Johannes Berg | 5b0acc6 | 2008-02-20 11:47:45 +0100 | [diff] [blame] | 297 | enum wpa_alg { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP }; |
| 298 | enum wpa_cipher { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP, |
| 299 | CIPHER_WEP104 }; |
| 300 | enum wpa_key_mgmt { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE, |
| 301 | KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE }; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 302 | |
| 303 | /* |
| 304 | * private data |
| 305 | */ |
| 306 | #define NET_TYPE_11FB 0 |
| 307 | |
| 308 | #define CAP_MODE_80211A 1 |
| 309 | #define CAP_MODE_80211B 2 |
| 310 | #define CAP_MODE_80211G 4 |
| 311 | #define CAP_MODE_MASK 7 |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 312 | |
Jussi Kivilinna | 6010ce0 | 2008-06-02 18:35:21 +0300 | [diff] [blame] | 313 | #define WORK_LINK_UP (1<<0) |
| 314 | #define WORK_LINK_DOWN (1<<1) |
| 315 | #define WORK_SET_MULTICAST_LIST (1<<2) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 316 | |
Jussi Kivilinna | 90d0734 | 2008-06-12 20:19:19 +0300 | [diff] [blame] | 317 | #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set)) |
| 318 | |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 319 | static const struct ieee80211_channel rndis_channels[] = { |
| 320 | { .center_freq = 2412 }, |
| 321 | { .center_freq = 2417 }, |
| 322 | { .center_freq = 2422 }, |
| 323 | { .center_freq = 2427 }, |
| 324 | { .center_freq = 2432 }, |
| 325 | { .center_freq = 2437 }, |
| 326 | { .center_freq = 2442 }, |
| 327 | { .center_freq = 2447 }, |
| 328 | { .center_freq = 2452 }, |
| 329 | { .center_freq = 2457 }, |
| 330 | { .center_freq = 2462 }, |
| 331 | { .center_freq = 2467 }, |
| 332 | { .center_freq = 2472 }, |
| 333 | { .center_freq = 2484 }, |
| 334 | }; |
| 335 | |
| 336 | static const struct ieee80211_rate rndis_rates[] = { |
| 337 | { .bitrate = 10 }, |
| 338 | { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 339 | { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 340 | { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 341 | { .bitrate = 60 }, |
| 342 | { .bitrate = 90 }, |
| 343 | { .bitrate = 120 }, |
| 344 | { .bitrate = 180 }, |
| 345 | { .bitrate = 240 }, |
| 346 | { .bitrate = 360 }, |
| 347 | { .bitrate = 480 }, |
| 348 | { .bitrate = 540 } |
| 349 | }; |
| 350 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 351 | /* RNDIS device private data */ |
| 352 | struct rndis_wext_private { |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 353 | struct usbnet *usbdev; |
| 354 | |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 355 | struct wireless_dev wdev; |
| 356 | |
Jussi Kivilinna | 71a7b26 | 2009-03-26 23:40:31 +0200 | [diff] [blame] | 357 | struct cfg80211_scan_request *scan_request; |
| 358 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 359 | struct workqueue_struct *workqueue; |
| 360 | struct delayed_work stats_work; |
Jussi Kivilinna | 71a7b26 | 2009-03-26 23:40:31 +0200 | [diff] [blame] | 361 | struct delayed_work scan_work; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 362 | struct work_struct work; |
| 363 | struct mutex command_lock; |
| 364 | spinlock_t stats_lock; |
| 365 | unsigned long work_pending; |
| 366 | |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 367 | struct ieee80211_supported_band band; |
| 368 | struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)]; |
| 369 | struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)]; |
| 370 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 371 | struct iw_statistics iwstats; |
| 372 | struct iw_statistics privstats; |
| 373 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 374 | int caps; |
| 375 | int multicast_size; |
| 376 | |
| 377 | /* module parameters */ |
| 378 | char param_country[4]; |
| 379 | int param_frameburst; |
| 380 | int param_afterburner; |
| 381 | int param_power_save; |
| 382 | int param_power_output; |
| 383 | int param_roamtrigger; |
| 384 | int param_roamdelta; |
| 385 | u32 param_workaround_interval; |
| 386 | |
| 387 | /* hardware state */ |
| 388 | int radio_on; |
| 389 | int infra_mode; |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 390 | struct ndis_80211_ssid essid; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 391 | |
| 392 | /* encryption stuff */ |
| 393 | int encr_tx_key_index; |
| 394 | char encr_keys[4][32]; |
| 395 | int encr_key_len[4]; |
| 396 | int wpa_version; |
| 397 | int wpa_keymgmt; |
| 398 | int wpa_authalg; |
| 399 | int wpa_ie_len; |
| 400 | u8 *wpa_ie; |
| 401 | int wpa_cipher_pair; |
| 402 | int wpa_cipher_group; |
Jussi Kivilinna | 90d0734 | 2008-06-12 20:19:19 +0300 | [diff] [blame] | 403 | |
| 404 | u8 command_buffer[COMMAND_BUFFER_SIZE]; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 405 | }; |
| 406 | |
John W. Linville | 964c1d4 | 2009-03-26 23:40:01 +0200 | [diff] [blame] | 407 | /* |
| 408 | * cfg80211 ops |
| 409 | */ |
| 410 | static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex, |
| 411 | enum nl80211_iftype type, u32 *flags, |
| 412 | struct vif_params *params); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 413 | |
Jussi Kivilinna | 71a7b26 | 2009-03-26 23:40:31 +0200 | [diff] [blame] | 414 | static int rndis_scan(struct wiphy *wiphy, struct net_device *dev, |
| 415 | struct cfg80211_scan_request *request); |
| 416 | |
Johannes Berg | caa6dfa | 2009-04-21 10:55:10 +0200 | [diff] [blame] | 417 | static struct cfg80211_ops rndis_config_ops = { |
John W. Linville | 964c1d4 | 2009-03-26 23:40:01 +0200 | [diff] [blame] | 418 | .change_virtual_intf = rndis_change_virtual_intf, |
Jussi Kivilinna | 71a7b26 | 2009-03-26 23:40:31 +0200 | [diff] [blame] | 419 | .scan = rndis_scan, |
John W. Linville | 964c1d4 | 2009-03-26 23:40:01 +0200 | [diff] [blame] | 420 | }; |
| 421 | |
Johannes Berg | caa6dfa | 2009-04-21 10:55:10 +0200 | [diff] [blame] | 422 | static void *rndis_wiphy_privid = &rndis_wiphy_privid; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 423 | |
| 424 | static const int bcm4320_power_output[4] = { 25, 50, 75, 100 }; |
| 425 | |
| 426 | static const unsigned char zero_bssid[ETH_ALEN] = {0,}; |
| 427 | static const unsigned char ffff_bssid[ETH_ALEN] = { 0xff, 0xff, 0xff, |
| 428 | 0xff, 0xff, 0xff }; |
| 429 | |
| 430 | |
| 431 | static struct rndis_wext_private *get_rndis_wext_priv(struct usbnet *dev) |
| 432 | { |
| 433 | return (struct rndis_wext_private *)dev->driver_priv; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | static u32 get_bcm4320_power(struct rndis_wext_private *priv) |
| 438 | { |
| 439 | return BCM4320_DEFAULT_TXPOWER * |
| 440 | bcm4320_power_output[priv->param_power_output] / 100; |
| 441 | } |
| 442 | |
| 443 | |
| 444 | /* translate error code */ |
| 445 | static int rndis_error_status(__le32 rndis_status) |
| 446 | { |
| 447 | int ret = -EINVAL; |
| 448 | switch (rndis_status) { |
| 449 | case RNDIS_STATUS_SUCCESS: |
| 450 | ret = 0; |
| 451 | break; |
| 452 | case RNDIS_STATUS_FAILURE: |
| 453 | case RNDIS_STATUS_INVALID_DATA: |
| 454 | ret = -EINVAL; |
| 455 | break; |
| 456 | case RNDIS_STATUS_NOT_SUPPORTED: |
| 457 | ret = -EOPNOTSUPP; |
| 458 | break; |
| 459 | case RNDIS_STATUS_ADAPTER_NOT_READY: |
| 460 | case RNDIS_STATUS_ADAPTER_NOT_OPEN: |
| 461 | ret = -EBUSY; |
| 462 | break; |
| 463 | } |
| 464 | return ret; |
| 465 | } |
| 466 | |
| 467 | |
| 468 | static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len) |
| 469 | { |
| 470 | struct rndis_wext_private *priv = get_rndis_wext_priv(dev); |
| 471 | union { |
| 472 | void *buf; |
| 473 | struct rndis_msg_hdr *header; |
| 474 | struct rndis_query *get; |
| 475 | struct rndis_query_c *get_c; |
| 476 | } u; |
| 477 | int ret, buflen; |
| 478 | |
| 479 | buflen = *len + sizeof(*u.get); |
| 480 | if (buflen < CONTROL_BUFFER_SIZE) |
| 481 | buflen = CONTROL_BUFFER_SIZE; |
Jussi Kivilinna | 90d0734 | 2008-06-12 20:19:19 +0300 | [diff] [blame] | 482 | |
| 483 | if (buflen > COMMAND_BUFFER_SIZE) { |
| 484 | u.buf = kmalloc(buflen, GFP_KERNEL); |
| 485 | if (!u.buf) |
| 486 | return -ENOMEM; |
| 487 | } else { |
| 488 | u.buf = priv->command_buffer; |
| 489 | } |
| 490 | |
| 491 | mutex_lock(&priv->command_lock); |
| 492 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 493 | memset(u.get, 0, sizeof *u.get); |
| 494 | u.get->msg_type = RNDIS_MSG_QUERY; |
Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 495 | u.get->msg_len = cpu_to_le32(sizeof *u.get); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 496 | u.get->oid = oid; |
| 497 | |
Jussi Kivilinna | 818727b | 2008-06-18 15:40:12 +0300 | [diff] [blame] | 498 | ret = rndis_command(dev, u.header, buflen); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 499 | if (ret == 0) { |
| 500 | ret = le32_to_cpu(u.get_c->len); |
| 501 | *len = (*len > ret) ? ret : *len; |
| 502 | memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len); |
| 503 | ret = rndis_error_status(u.get_c->status); |
| 504 | } |
| 505 | |
Jussi Kivilinna | 90d0734 | 2008-06-12 20:19:19 +0300 | [diff] [blame] | 506 | mutex_unlock(&priv->command_lock); |
| 507 | |
| 508 | if (u.buf != priv->command_buffer) |
| 509 | kfree(u.buf); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 510 | return ret; |
| 511 | } |
| 512 | |
| 513 | |
| 514 | static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len) |
| 515 | { |
| 516 | struct rndis_wext_private *priv = get_rndis_wext_priv(dev); |
| 517 | union { |
| 518 | void *buf; |
| 519 | struct rndis_msg_hdr *header; |
| 520 | struct rndis_set *set; |
| 521 | struct rndis_set_c *set_c; |
| 522 | } u; |
| 523 | int ret, buflen; |
| 524 | |
| 525 | buflen = len + sizeof(*u.set); |
| 526 | if (buflen < CONTROL_BUFFER_SIZE) |
| 527 | buflen = CONTROL_BUFFER_SIZE; |
Jussi Kivilinna | 90d0734 | 2008-06-12 20:19:19 +0300 | [diff] [blame] | 528 | |
| 529 | if (buflen > COMMAND_BUFFER_SIZE) { |
| 530 | u.buf = kmalloc(buflen, GFP_KERNEL); |
| 531 | if (!u.buf) |
| 532 | return -ENOMEM; |
| 533 | } else { |
| 534 | u.buf = priv->command_buffer; |
| 535 | } |
| 536 | |
| 537 | mutex_lock(&priv->command_lock); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 538 | |
| 539 | memset(u.set, 0, sizeof *u.set); |
| 540 | u.set->msg_type = RNDIS_MSG_SET; |
| 541 | u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len); |
| 542 | u.set->oid = oid; |
| 543 | u.set->len = cpu_to_le32(len); |
Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 544 | u.set->offset = cpu_to_le32(sizeof(*u.set) - 8); |
| 545 | u.set->handle = cpu_to_le32(0); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 546 | memcpy(u.buf + sizeof(*u.set), data, len); |
| 547 | |
Jussi Kivilinna | 818727b | 2008-06-18 15:40:12 +0300 | [diff] [blame] | 548 | ret = rndis_command(dev, u.header, buflen); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 549 | if (ret == 0) |
| 550 | ret = rndis_error_status(u.set_c->status); |
| 551 | |
Jussi Kivilinna | 90d0734 | 2008-06-12 20:19:19 +0300 | [diff] [blame] | 552 | mutex_unlock(&priv->command_lock); |
| 553 | |
| 554 | if (u.buf != priv->command_buffer) |
| 555 | kfree(u.buf); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | |
| 560 | /* |
| 561 | * Specs say that we can only set config parameters only soon after device |
| 562 | * initialization. |
| 563 | * value_type: 0 = u32, 2 = unicode string |
| 564 | */ |
| 565 | static int rndis_set_config_parameter(struct usbnet *dev, char *param, |
| 566 | int value_type, void *value) |
| 567 | { |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 568 | struct ndis_config_param *infobuf; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 569 | int value_len, info_len, param_len, ret, i; |
| 570 | __le16 *unibuf; |
| 571 | __le32 *dst_value; |
| 572 | |
| 573 | if (value_type == 0) |
| 574 | value_len = sizeof(__le32); |
| 575 | else if (value_type == 2) |
| 576 | value_len = strlen(value) * sizeof(__le16); |
| 577 | else |
| 578 | return -EINVAL; |
| 579 | |
| 580 | param_len = strlen(param) * sizeof(__le16); |
| 581 | info_len = sizeof(*infobuf) + param_len + value_len; |
| 582 | |
| 583 | #ifdef DEBUG |
| 584 | info_len += 12; |
| 585 | #endif |
| 586 | infobuf = kmalloc(info_len, GFP_KERNEL); |
| 587 | if (!infobuf) |
| 588 | return -ENOMEM; |
| 589 | |
| 590 | #ifdef DEBUG |
| 591 | info_len -= 12; |
| 592 | /* extra 12 bytes are for padding (debug output) */ |
| 593 | memset(infobuf, 0xCC, info_len + 12); |
| 594 | #endif |
| 595 | |
| 596 | if (value_type == 2) |
| 597 | devdbg(dev, "setting config parameter: %s, value: %s", |
| 598 | param, (u8 *)value); |
| 599 | else |
| 600 | devdbg(dev, "setting config parameter: %s, value: %d", |
| 601 | param, *(u32 *)value); |
| 602 | |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 603 | infobuf->name_offs = cpu_to_le32(sizeof(*infobuf)); |
| 604 | infobuf->name_length = cpu_to_le32(param_len); |
| 605 | infobuf->type = cpu_to_le32(value_type); |
| 606 | infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len); |
| 607 | infobuf->value_length = cpu_to_le32(value_len); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 608 | |
| 609 | /* simple string to unicode string conversion */ |
| 610 | unibuf = (void *)infobuf + sizeof(*infobuf); |
| 611 | for (i = 0; i < param_len / sizeof(__le16); i++) |
| 612 | unibuf[i] = cpu_to_le16(param[i]); |
| 613 | |
| 614 | if (value_type == 2) { |
| 615 | unibuf = (void *)infobuf + sizeof(*infobuf) + param_len; |
| 616 | for (i = 0; i < value_len / sizeof(__le16); i++) |
| 617 | unibuf[i] = cpu_to_le16(((u8 *)value)[i]); |
| 618 | } else { |
| 619 | dst_value = (void *)infobuf + sizeof(*infobuf) + param_len; |
| 620 | *dst_value = cpu_to_le32(*(u32 *)value); |
| 621 | } |
| 622 | |
| 623 | #ifdef DEBUG |
| 624 | devdbg(dev, "info buffer (len: %d):", info_len); |
| 625 | for (i = 0; i < info_len; i += 12) { |
| 626 | u32 *tmp = (u32 *)((u8 *)infobuf + i); |
| 627 | devdbg(dev, "%08X:%08X:%08X", |
| 628 | cpu_to_be32(tmp[0]), |
| 629 | cpu_to_be32(tmp[1]), |
| 630 | cpu_to_be32(tmp[2])); |
| 631 | } |
| 632 | #endif |
| 633 | |
| 634 | ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER, |
| 635 | infobuf, info_len); |
| 636 | if (ret != 0) |
| 637 | devdbg(dev, "setting rndis config paramater failed, %d.", ret); |
| 638 | |
| 639 | kfree(infobuf); |
| 640 | return ret; |
| 641 | } |
| 642 | |
| 643 | static int rndis_set_config_parameter_str(struct usbnet *dev, |
| 644 | char *param, char *value) |
| 645 | { |
| 646 | return(rndis_set_config_parameter(dev, param, 2, value)); |
| 647 | } |
| 648 | |
| 649 | /*static int rndis_set_config_parameter_u32(struct usbnet *dev, |
| 650 | char *param, u32 value) |
| 651 | { |
| 652 | return(rndis_set_config_parameter(dev, param, 0, &value)); |
| 653 | }*/ |
| 654 | |
| 655 | |
| 656 | /* |
| 657 | * data conversion functions |
| 658 | */ |
| 659 | static int level_to_qual(int level) |
| 660 | { |
| 661 | int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE); |
| 662 | return qual >= 0 ? (qual <= 100 ? qual : 100) : 0; |
| 663 | } |
| 664 | |
| 665 | |
| 666 | static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq) |
| 667 | { |
| 668 | freq->e = 0; |
| 669 | freq->i = 0; |
| 670 | freq->flags = 0; |
| 671 | |
| 672 | /* see comment in wireless.h above the "struct iw_freq" |
| 673 | * definition for an explanation of this if |
| 674 | * NOTE: 1000000 is due to the kHz |
| 675 | */ |
| 676 | if (dsconfig > 1000000) { |
| 677 | freq->m = dsconfig / 10; |
| 678 | freq->e = 1; |
| 679 | } else |
| 680 | freq->m = dsconfig; |
| 681 | |
| 682 | /* convert from kHz to Hz */ |
| 683 | freq->e += 3; |
| 684 | } |
| 685 | |
| 686 | |
| 687 | static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig) |
| 688 | { |
| 689 | if (freq->m < 1000 && freq->e == 0) { |
David Kilroy | 9ee677c | 2008-12-23 14:03:38 +0000 | [diff] [blame] | 690 | if (freq->m >= 1 && freq->m <= 14) |
| 691 | *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 692 | else |
| 693 | return -1; |
| 694 | } else { |
| 695 | int i; |
| 696 | *dsconfig = freq->m; |
| 697 | for (i = freq->e; i > 0; i--) |
| 698 | *dsconfig *= 10; |
| 699 | *dsconfig /= 1000; |
| 700 | } |
| 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | |
| 706 | /* |
| 707 | * common functions |
| 708 | */ |
| 709 | static int |
| 710 | add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index); |
| 711 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 712 | static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 713 | { |
| 714 | int ret, len; |
| 715 | |
| 716 | len = sizeof(*ssid); |
| 717 | ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len); |
| 718 | |
| 719 | if (ret != 0) |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 720 | ssid->length = 0; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 721 | |
| 722 | #ifdef DEBUG |
| 723 | { |
| 724 | unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1]; |
| 725 | |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 726 | memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length)); |
| 727 | tmp[le32_to_cpu(ssid->length)] = 0; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 728 | devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret); |
| 729 | } |
| 730 | #endif |
| 731 | return ret; |
| 732 | } |
| 733 | |
| 734 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 735 | static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 736 | { |
| 737 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 738 | int ret; |
| 739 | |
| 740 | ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid)); |
| 741 | if (ret == 0) { |
| 742 | memcpy(&priv->essid, ssid, sizeof(priv->essid)); |
| 743 | priv->radio_on = 1; |
| 744 | devdbg(usbdev, "set_essid: radio_on = 1"); |
| 745 | } |
| 746 | |
| 747 | return ret; |
| 748 | } |
| 749 | |
| 750 | |
| 751 | static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN]) |
| 752 | { |
| 753 | int ret, len; |
| 754 | |
| 755 | len = ETH_ALEN; |
| 756 | ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len); |
| 757 | |
| 758 | if (ret != 0) |
| 759 | memset(bssid, 0, ETH_ALEN); |
| 760 | |
| 761 | return ret; |
| 762 | } |
| 763 | |
Scott Ashcroft | 4364623 | 2008-05-27 00:06:15 +0300 | [diff] [blame] | 764 | static int get_association_info(struct usbnet *usbdev, |
| 765 | struct ndis_80211_assoc_info *info, int len) |
| 766 | { |
| 767 | return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION, |
| 768 | info, &len); |
| 769 | } |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 770 | |
| 771 | static int is_associated(struct usbnet *usbdev) |
| 772 | { |
| 773 | u8 bssid[ETH_ALEN]; |
| 774 | int ret; |
| 775 | |
| 776 | ret = get_bssid(usbdev, bssid); |
| 777 | |
| 778 | return(ret == 0 && memcmp(bssid, zero_bssid, ETH_ALEN) != 0); |
| 779 | } |
| 780 | |
| 781 | |
| 782 | static int disassociate(struct usbnet *usbdev, int reset_ssid) |
| 783 | { |
| 784 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 785 | struct ndis_80211_ssid ssid; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 786 | int i, ret = 0; |
| 787 | |
| 788 | if (priv->radio_on) { |
| 789 | ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0); |
| 790 | if (ret == 0) { |
| 791 | priv->radio_on = 0; |
| 792 | devdbg(usbdev, "disassociate: radio_on = 0"); |
| 793 | |
| 794 | if (reset_ssid) |
| 795 | msleep(100); |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | /* disassociate causes radio to be turned off; if reset_ssid |
| 800 | * is given, set random ssid to enable radio */ |
| 801 | if (reset_ssid) { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 802 | ssid.length = cpu_to_le32(sizeof(ssid.essid)); |
| 803 | get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2); |
| 804 | ssid.essid[0] = 0x1; |
| 805 | ssid.essid[1] = 0xff; |
| 806 | for (i = 2; i < sizeof(ssid.essid); i++) |
| 807 | ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 808 | ret = set_essid(usbdev, &ssid); |
| 809 | } |
| 810 | return ret; |
| 811 | } |
| 812 | |
| 813 | |
| 814 | static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg) |
| 815 | { |
| 816 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 817 | __le32 tmp; |
| 818 | int auth_mode, ret; |
| 819 | |
| 820 | devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x " |
| 821 | "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt); |
| 822 | |
| 823 | if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) { |
| 824 | if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 825 | auth_mode = ndis_80211_auth_wpa2; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 826 | else |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 827 | auth_mode = ndis_80211_auth_wpa2_psk; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 828 | } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) { |
| 829 | if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 830 | auth_mode = ndis_80211_auth_wpa; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 831 | else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 832 | auth_mode = ndis_80211_auth_wpa_psk; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 833 | else |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 834 | auth_mode = ndis_80211_auth_wpa_none; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 835 | } else if (authalg & IW_AUTH_ALG_SHARED_KEY) { |
| 836 | if (authalg & IW_AUTH_ALG_OPEN_SYSTEM) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 837 | auth_mode = ndis_80211_auth_auto_switch; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 838 | else |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 839 | auth_mode = ndis_80211_auth_shared; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 840 | } else |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 841 | auth_mode = ndis_80211_auth_open; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 842 | |
| 843 | tmp = cpu_to_le32(auth_mode); |
| 844 | ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp, |
| 845 | sizeof(tmp)); |
| 846 | if (ret != 0) { |
| 847 | devwarn(usbdev, "setting auth mode failed (%08X)", ret); |
| 848 | return ret; |
| 849 | } |
| 850 | |
| 851 | priv->wpa_version = wpa_version; |
| 852 | priv->wpa_authalg = authalg; |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | |
| 857 | static int set_priv_filter(struct usbnet *usbdev) |
| 858 | { |
| 859 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 860 | __le32 tmp; |
| 861 | |
| 862 | devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version); |
| 863 | |
| 864 | if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 || |
| 865 | priv->wpa_version & IW_AUTH_WPA_VERSION_WPA) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 866 | tmp = cpu_to_le32(ndis_80211_priv_8021x_wep); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 867 | else |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 868 | tmp = cpu_to_le32(ndis_80211_priv_accept_all); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 869 | |
| 870 | return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp, |
| 871 | sizeof(tmp)); |
| 872 | } |
| 873 | |
| 874 | |
| 875 | static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise) |
| 876 | { |
| 877 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 878 | __le32 tmp; |
| 879 | int encr_mode, ret; |
| 880 | |
| 881 | devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x", |
| 882 | pairwise, |
| 883 | groupwise); |
| 884 | |
| 885 | if (pairwise & IW_AUTH_CIPHER_CCMP) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 886 | encr_mode = ndis_80211_encr_ccmp_enabled; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 887 | else if (pairwise & IW_AUTH_CIPHER_TKIP) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 888 | encr_mode = ndis_80211_encr_tkip_enabled; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 889 | else if (pairwise & |
| 890 | (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104)) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 891 | encr_mode = ndis_80211_encr_wep_enabled; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 892 | else if (groupwise & IW_AUTH_CIPHER_CCMP) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 893 | encr_mode = ndis_80211_encr_ccmp_enabled; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 894 | else if (groupwise & IW_AUTH_CIPHER_TKIP) |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 895 | encr_mode = ndis_80211_encr_tkip_enabled; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 896 | else |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 897 | encr_mode = ndis_80211_encr_disabled; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 898 | |
| 899 | tmp = cpu_to_le32(encr_mode); |
| 900 | ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp, |
| 901 | sizeof(tmp)); |
| 902 | if (ret != 0) { |
| 903 | devwarn(usbdev, "setting encr mode failed (%08X)", ret); |
| 904 | return ret; |
| 905 | } |
| 906 | |
| 907 | priv->wpa_cipher_pair = pairwise; |
| 908 | priv->wpa_cipher_group = groupwise; |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | |
| 913 | static int set_assoc_params(struct usbnet *usbdev) |
| 914 | { |
| 915 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 916 | |
| 917 | set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg); |
| 918 | set_priv_filter(usbdev); |
| 919 | set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group); |
| 920 | |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | |
| 925 | static int set_infra_mode(struct usbnet *usbdev, int mode) |
| 926 | { |
| 927 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 928 | __le32 tmp; |
| 929 | int ret, i; |
| 930 | |
| 931 | devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode); |
| 932 | |
| 933 | tmp = cpu_to_le32(mode); |
| 934 | ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp, |
| 935 | sizeof(tmp)); |
| 936 | if (ret != 0) { |
| 937 | devwarn(usbdev, "setting infra mode failed (%08X)", ret); |
| 938 | return ret; |
| 939 | } |
| 940 | |
| 941 | /* NDIS drivers clear keys when infrastructure mode is |
| 942 | * changed. But Linux tools assume otherwise. So set the |
| 943 | * keys */ |
| 944 | if (priv->wpa_keymgmt == 0 || |
| 945 | priv->wpa_keymgmt == IW_AUTH_KEY_MGMT_802_1X) { |
| 946 | for (i = 0; i < 4; i++) { |
| 947 | if (priv->encr_key_len[i] > 0) |
| 948 | add_wep_key(usbdev, priv->encr_keys[i], |
| 949 | priv->encr_key_len[i], i); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | priv->infra_mode = mode; |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | |
| 958 | static void set_default_iw_params(struct usbnet *usbdev) |
| 959 | { |
| 960 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 961 | |
| 962 | priv->wpa_keymgmt = 0; |
| 963 | priv->wpa_version = 0; |
| 964 | |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 965 | set_infra_mode(usbdev, ndis_80211_infra_infra); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 966 | set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED, |
| 967 | IW_AUTH_ALG_OPEN_SYSTEM); |
| 968 | set_priv_filter(usbdev); |
| 969 | set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE); |
| 970 | } |
| 971 | |
| 972 | |
| 973 | static int deauthenticate(struct usbnet *usbdev) |
| 974 | { |
| 975 | int ret; |
| 976 | |
| 977 | ret = disassociate(usbdev, 1); |
| 978 | set_default_iw_params(usbdev); |
| 979 | return ret; |
| 980 | } |
| 981 | |
| 982 | |
| 983 | /* index must be 0 - N, as per NDIS */ |
| 984 | static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index) |
| 985 | { |
| 986 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 987 | struct ndis_80211_wep_key ndis_key; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 988 | int ret; |
| 989 | |
| 990 | if (key_len <= 0 || key_len > 32 || index < 0 || index >= 4) |
| 991 | return -EINVAL; |
| 992 | |
| 993 | memset(&ndis_key, 0, sizeof(ndis_key)); |
| 994 | |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 995 | ndis_key.size = cpu_to_le32(sizeof(ndis_key)); |
| 996 | ndis_key.length = cpu_to_le32(key_len); |
| 997 | ndis_key.index = cpu_to_le32(index); |
| 998 | memcpy(&ndis_key.material, key, key_len); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 999 | |
| 1000 | if (index == priv->encr_tx_key_index) { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1001 | ndis_key.index |= cpu_to_le32(1 << 31); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1002 | ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104, |
| 1003 | IW_AUTH_CIPHER_NONE); |
| 1004 | if (ret) |
| 1005 | devwarn(usbdev, "encryption couldn't be enabled (%08X)", |
| 1006 | ret); |
| 1007 | } |
| 1008 | |
| 1009 | ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key, |
| 1010 | sizeof(ndis_key)); |
| 1011 | if (ret != 0) { |
| 1012 | devwarn(usbdev, "adding encryption key %d failed (%08X)", |
| 1013 | index+1, ret); |
| 1014 | return ret; |
| 1015 | } |
| 1016 | |
| 1017 | priv->encr_key_len[index] = key_len; |
| 1018 | memcpy(&priv->encr_keys[index], key, key_len); |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | /* remove_key is for both wep and wpa */ |
| 1025 | static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN]) |
| 1026 | { |
| 1027 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 1028 | struct ndis_80211_remove_key remove_key; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1029 | __le32 keyindex; |
| 1030 | int ret; |
| 1031 | |
| 1032 | if (priv->encr_key_len[index] == 0) |
| 1033 | return 0; |
| 1034 | |
| 1035 | priv->encr_key_len[index] = 0; |
| 1036 | memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index])); |
| 1037 | |
| 1038 | if (priv->wpa_cipher_pair == IW_AUTH_CIPHER_TKIP || |
| 1039 | priv->wpa_cipher_pair == IW_AUTH_CIPHER_CCMP || |
| 1040 | priv->wpa_cipher_group == IW_AUTH_CIPHER_TKIP || |
| 1041 | priv->wpa_cipher_group == IW_AUTH_CIPHER_CCMP) { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1042 | remove_key.size = cpu_to_le32(sizeof(remove_key)); |
| 1043 | remove_key.index = cpu_to_le32(index); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1044 | if (bssid) { |
| 1045 | /* pairwise key */ |
| 1046 | if (memcmp(bssid, ffff_bssid, ETH_ALEN) != 0) |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1047 | remove_key.index |= cpu_to_le32(1 << 30); |
| 1048 | memcpy(remove_key.bssid, bssid, |
| 1049 | sizeof(remove_key.bssid)); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1050 | } else |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1051 | memset(remove_key.bssid, 0xff, |
| 1052 | sizeof(remove_key.bssid)); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1053 | |
| 1054 | ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key, |
| 1055 | sizeof(remove_key)); |
| 1056 | if (ret != 0) |
| 1057 | return ret; |
| 1058 | } else { |
| 1059 | keyindex = cpu_to_le32(index); |
| 1060 | ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex, |
| 1061 | sizeof(keyindex)); |
| 1062 | if (ret != 0) { |
| 1063 | devwarn(usbdev, |
| 1064 | "removing encryption key %d failed (%08X)", |
| 1065 | index, ret); |
| 1066 | return ret; |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | /* if it is transmit key, disable encryption */ |
| 1071 | if (index == priv->encr_tx_key_index) |
| 1072 | set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE); |
| 1073 | |
| 1074 | return 0; |
| 1075 | } |
| 1076 | |
| 1077 | |
| 1078 | static void set_multicast_list(struct usbnet *usbdev) |
| 1079 | { |
| 1080 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1081 | struct dev_mc_list *mclist; |
| 1082 | __le32 filter; |
| 1083 | int ret, i, size; |
| 1084 | char *buf; |
| 1085 | |
| 1086 | filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST; |
| 1087 | |
| 1088 | if (usbdev->net->flags & IFF_PROMISC) { |
| 1089 | filter |= RNDIS_PACKET_TYPE_PROMISCUOUS | |
| 1090 | RNDIS_PACKET_TYPE_ALL_LOCAL; |
| 1091 | } else if (usbdev->net->flags & IFF_ALLMULTI || |
| 1092 | usbdev->net->mc_count > priv->multicast_size) { |
| 1093 | filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST; |
| 1094 | } else if (usbdev->net->mc_count > 0) { |
| 1095 | size = min(priv->multicast_size, usbdev->net->mc_count); |
| 1096 | buf = kmalloc(size * ETH_ALEN, GFP_KERNEL); |
| 1097 | if (!buf) { |
| 1098 | devwarn(usbdev, |
| 1099 | "couldn't alloc %d bytes of memory", |
| 1100 | size * ETH_ALEN); |
| 1101 | return; |
| 1102 | } |
| 1103 | |
| 1104 | mclist = usbdev->net->mc_list; |
| 1105 | for (i = 0; i < size && mclist; mclist = mclist->next) { |
| 1106 | if (mclist->dmi_addrlen != ETH_ALEN) |
| 1107 | continue; |
| 1108 | |
| 1109 | memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN); |
| 1110 | i++; |
| 1111 | } |
| 1112 | |
| 1113 | ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf, |
| 1114 | i * ETH_ALEN); |
| 1115 | if (ret == 0 && i > 0) |
| 1116 | filter |= RNDIS_PACKET_TYPE_MULTICAST; |
| 1117 | else |
| 1118 | filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST; |
| 1119 | |
| 1120 | devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d", |
| 1121 | i, priv->multicast_size, ret); |
| 1122 | |
| 1123 | kfree(buf); |
| 1124 | } |
| 1125 | |
| 1126 | ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter, |
| 1127 | sizeof(filter)); |
| 1128 | if (ret < 0) { |
| 1129 | devwarn(usbdev, "couldn't set packet filter: %08x", |
| 1130 | le32_to_cpu(filter)); |
| 1131 | } |
| 1132 | |
| 1133 | devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d", |
| 1134 | le32_to_cpu(filter), ret); |
| 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | /* |
John W. Linville | 964c1d4 | 2009-03-26 23:40:01 +0200 | [diff] [blame] | 1139 | * cfg80211 ops |
| 1140 | */ |
| 1141 | static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex, |
| 1142 | enum nl80211_iftype type, u32 *flags, |
| 1143 | struct vif_params *params) |
| 1144 | { |
| 1145 | struct net_device *dev; |
| 1146 | struct usbnet *usbdev; |
| 1147 | int mode; |
| 1148 | |
| 1149 | /* we're under RTNL */ |
| 1150 | dev = __dev_get_by_index(&init_net, ifindex); |
| 1151 | if (!dev) |
| 1152 | return -ENODEV; |
| 1153 | usbdev = netdev_priv(dev); |
| 1154 | |
| 1155 | switch (type) { |
| 1156 | case NL80211_IFTYPE_ADHOC: |
| 1157 | mode = ndis_80211_infra_adhoc; |
| 1158 | break; |
| 1159 | case NL80211_IFTYPE_STATION: |
| 1160 | mode = ndis_80211_infra_infra; |
| 1161 | break; |
| 1162 | default: |
| 1163 | return -EINVAL; |
| 1164 | } |
| 1165 | |
| 1166 | return set_infra_mode(usbdev, mode); |
| 1167 | } |
| 1168 | |
Jussi Kivilinna | 71a7b26 | 2009-03-26 23:40:31 +0200 | [diff] [blame] | 1169 | |
| 1170 | #define SCAN_DELAY_JIFFIES (HZ) |
| 1171 | static int rndis_scan(struct wiphy *wiphy, struct net_device *dev, |
| 1172 | struct cfg80211_scan_request *request) |
| 1173 | { |
| 1174 | struct usbnet *usbdev = netdev_priv(dev); |
| 1175 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1176 | int ret; |
| 1177 | __le32 tmp; |
| 1178 | |
| 1179 | devdbg(usbdev, "cfg80211.scan"); |
| 1180 | |
| 1181 | if (!request) |
| 1182 | return -EINVAL; |
| 1183 | |
| 1184 | if (priv->scan_request && priv->scan_request != request) |
| 1185 | return -EBUSY; |
| 1186 | |
| 1187 | priv->scan_request = request; |
| 1188 | |
| 1189 | tmp = cpu_to_le32(1); |
| 1190 | ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp, |
| 1191 | sizeof(tmp)); |
| 1192 | if (ret == 0) { |
| 1193 | /* Wait before retrieving scan results from device */ |
| 1194 | queue_delayed_work(priv->workqueue, &priv->scan_work, |
| 1195 | SCAN_DELAY_JIFFIES); |
| 1196 | } |
| 1197 | |
| 1198 | return ret; |
| 1199 | } |
| 1200 | |
| 1201 | |
| 1202 | static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev, |
| 1203 | struct ndis_80211_bssid_ex *bssid) |
| 1204 | { |
| 1205 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1206 | struct ieee80211_channel *channel; |
| 1207 | s32 signal; |
| 1208 | u64 timestamp; |
| 1209 | u16 capability; |
| 1210 | u16 beacon_interval; |
| 1211 | struct ndis_80211_fixed_ies *fixed; |
| 1212 | int ie_len, bssid_len; |
| 1213 | u8 *ie; |
| 1214 | |
| 1215 | /* parse bssid structure */ |
| 1216 | bssid_len = le32_to_cpu(bssid->length); |
| 1217 | |
| 1218 | if (bssid_len < sizeof(struct ndis_80211_bssid_ex) + |
| 1219 | sizeof(struct ndis_80211_fixed_ies)) |
| 1220 | return NULL; |
| 1221 | |
| 1222 | fixed = (struct ndis_80211_fixed_ies *)bssid->ies; |
| 1223 | |
| 1224 | ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies)); |
| 1225 | ie_len = min(bssid_len - (int)sizeof(*bssid), |
| 1226 | (int)le32_to_cpu(bssid->ie_length)); |
| 1227 | ie_len -= sizeof(struct ndis_80211_fixed_ies); |
| 1228 | if (ie_len < 0) |
| 1229 | return NULL; |
| 1230 | |
| 1231 | /* extract data for cfg80211_inform_bss */ |
| 1232 | channel = ieee80211_get_channel(priv->wdev.wiphy, |
| 1233 | KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config))); |
| 1234 | if (!channel) |
| 1235 | return NULL; |
| 1236 | |
| 1237 | signal = level_to_qual(le32_to_cpu(bssid->rssi)); |
| 1238 | timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp); |
| 1239 | capability = le16_to_cpu(fixed->capabilities); |
| 1240 | beacon_interval = le16_to_cpu(fixed->beacon_interval); |
| 1241 | |
| 1242 | return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac, |
| 1243 | timestamp, capability, beacon_interval, ie, ie_len, signal, |
| 1244 | GFP_KERNEL); |
| 1245 | } |
| 1246 | |
| 1247 | |
| 1248 | static int rndis_check_bssid_list(struct usbnet *usbdev) |
| 1249 | { |
| 1250 | void *buf = NULL; |
| 1251 | struct ndis_80211_bssid_list_ex *bssid_list; |
| 1252 | struct ndis_80211_bssid_ex *bssid; |
| 1253 | int ret = -EINVAL, len, count, bssid_len; |
| 1254 | |
| 1255 | devdbg(usbdev, "check_bssid_list"); |
| 1256 | |
| 1257 | len = CONTROL_BUFFER_SIZE; |
| 1258 | buf = kmalloc(len, GFP_KERNEL); |
| 1259 | if (!buf) { |
| 1260 | ret = -ENOMEM; |
| 1261 | goto out; |
| 1262 | } |
| 1263 | |
| 1264 | ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len); |
| 1265 | if (ret != 0) |
| 1266 | goto out; |
| 1267 | |
| 1268 | bssid_list = buf; |
| 1269 | bssid = bssid_list->bssid; |
| 1270 | bssid_len = le32_to_cpu(bssid->length); |
| 1271 | count = le32_to_cpu(bssid_list->num_items); |
| 1272 | devdbg(usbdev, "check_bssid_list: %d BSSIDs found", count); |
| 1273 | |
| 1274 | while (count && ((void *)bssid + bssid_len) <= (buf + len)) { |
| 1275 | rndis_bss_info_update(usbdev, bssid); |
| 1276 | |
| 1277 | bssid = (void *)bssid + bssid_len; |
| 1278 | bssid_len = le32_to_cpu(bssid->length); |
| 1279 | count--; |
| 1280 | } |
| 1281 | |
| 1282 | out: |
| 1283 | kfree(buf); |
| 1284 | return ret; |
| 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | static void rndis_get_scan_results(struct work_struct *work) |
| 1289 | { |
| 1290 | struct rndis_wext_private *priv = |
| 1291 | container_of(work, struct rndis_wext_private, scan_work.work); |
| 1292 | struct usbnet *usbdev = priv->usbdev; |
| 1293 | int ret; |
| 1294 | |
| 1295 | devdbg(usbdev, "get_scan_results"); |
| 1296 | |
| 1297 | ret = rndis_check_bssid_list(usbdev); |
| 1298 | |
| 1299 | cfg80211_scan_done(priv->scan_request, ret < 0); |
| 1300 | |
| 1301 | priv->scan_request = NULL; |
| 1302 | } |
| 1303 | |
| 1304 | |
John W. Linville | 964c1d4 | 2009-03-26 23:40:01 +0200 | [diff] [blame] | 1305 | /* |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1306 | * wireless extension handlers |
| 1307 | */ |
| 1308 | |
| 1309 | static int rndis_iw_commit(struct net_device *dev, |
| 1310 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1311 | { |
| 1312 | /* dummy op */ |
| 1313 | return 0; |
| 1314 | } |
| 1315 | |
| 1316 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1317 | static int rndis_iw_set_essid(struct net_device *dev, |
| 1318 | struct iw_request_info *info, union iwreq_data *wrqu, char *essid) |
| 1319 | { |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 1320 | struct ndis_80211_ssid ssid; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1321 | int length = wrqu->essid.length; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1322 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1323 | |
| 1324 | devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'", |
| 1325 | wrqu->essid.flags, wrqu->essid.length, essid); |
| 1326 | |
| 1327 | if (length > NDIS_802_11_LENGTH_SSID) |
| 1328 | length = NDIS_802_11_LENGTH_SSID; |
| 1329 | |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1330 | ssid.length = cpu_to_le32(length); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1331 | if (length > 0) |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1332 | memcpy(ssid.essid, essid, length); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1333 | else |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1334 | memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1335 | |
| 1336 | set_assoc_params(usbdev); |
| 1337 | |
| 1338 | if (!wrqu->essid.flags || length == 0) |
| 1339 | return disassociate(usbdev, 1); |
| 1340 | else |
| 1341 | return set_essid(usbdev, &ssid); |
| 1342 | } |
| 1343 | |
| 1344 | |
| 1345 | static int rndis_iw_get_essid(struct net_device *dev, |
| 1346 | struct iw_request_info *info, union iwreq_data *wrqu, char *essid) |
| 1347 | { |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 1348 | struct ndis_80211_ssid ssid; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1349 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1350 | int ret; |
| 1351 | |
| 1352 | ret = get_essid(usbdev, &ssid); |
| 1353 | |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1354 | if (ret == 0 && le32_to_cpu(ssid.length) > 0) { |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1355 | wrqu->essid.flags = 1; |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1356 | wrqu->essid.length = le32_to_cpu(ssid.length); |
| 1357 | memcpy(essid, ssid.essid, wrqu->essid.length); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1358 | essid[wrqu->essid.length] = 0; |
| 1359 | } else { |
| 1360 | memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID)); |
| 1361 | wrqu->essid.flags = 0; |
| 1362 | wrqu->essid.length = 0; |
| 1363 | } |
| 1364 | devdbg(usbdev, "SIOCGIWESSID: %s", essid); |
| 1365 | return ret; |
| 1366 | } |
| 1367 | |
| 1368 | |
| 1369 | static int rndis_iw_get_bssid(struct net_device *dev, |
| 1370 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1371 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1372 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1373 | unsigned char bssid[ETH_ALEN]; |
| 1374 | int ret; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1375 | |
| 1376 | ret = get_bssid(usbdev, bssid); |
| 1377 | |
| 1378 | if (ret == 0) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1379 | devdbg(usbdev, "SIOCGIWAP: %pM", bssid); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1380 | else |
| 1381 | devdbg(usbdev, "SIOCGIWAP: <not associated>"); |
| 1382 | |
| 1383 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
| 1384 | memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN); |
| 1385 | |
| 1386 | return ret; |
| 1387 | } |
| 1388 | |
| 1389 | |
| 1390 | static int rndis_iw_set_bssid(struct net_device *dev, |
| 1391 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1392 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1393 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1394 | u8 *bssid = (u8 *)wrqu->ap_addr.sa_data; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1395 | int ret; |
| 1396 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1397 | devdbg(usbdev, "SIOCSIWAP: %pM", bssid); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1398 | |
| 1399 | ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN); |
| 1400 | |
| 1401 | /* user apps may set ap's mac address, which is not required; |
| 1402 | * they may fail to work if this function fails, so return |
| 1403 | * success */ |
| 1404 | if (ret) |
| 1405 | devwarn(usbdev, "setting AP mac address failed (%08X)", ret); |
| 1406 | |
| 1407 | return 0; |
| 1408 | } |
| 1409 | |
| 1410 | |
| 1411 | static int rndis_iw_set_auth(struct net_device *dev, |
| 1412 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1413 | { |
| 1414 | struct iw_param *p = &wrqu->param; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1415 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1416 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1417 | int ret = -ENOTSUPP; |
| 1418 | |
| 1419 | switch (p->flags & IW_AUTH_INDEX) { |
| 1420 | case IW_AUTH_WPA_VERSION: |
| 1421 | devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value); |
| 1422 | priv->wpa_version = p->value; |
| 1423 | ret = 0; |
| 1424 | break; |
| 1425 | |
| 1426 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1427 | devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value); |
| 1428 | priv->wpa_cipher_pair = p->value; |
| 1429 | ret = 0; |
| 1430 | break; |
| 1431 | |
| 1432 | case IW_AUTH_CIPHER_GROUP: |
| 1433 | devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value); |
| 1434 | priv->wpa_cipher_group = p->value; |
| 1435 | ret = 0; |
| 1436 | break; |
| 1437 | |
| 1438 | case IW_AUTH_KEY_MGMT: |
| 1439 | devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value); |
| 1440 | priv->wpa_keymgmt = p->value; |
| 1441 | ret = 0; |
| 1442 | break; |
| 1443 | |
| 1444 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 1445 | devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x", |
| 1446 | p->value); |
| 1447 | ret = 0; |
| 1448 | break; |
| 1449 | |
| 1450 | case IW_AUTH_DROP_UNENCRYPTED: |
| 1451 | devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value); |
| 1452 | ret = 0; |
| 1453 | break; |
| 1454 | |
| 1455 | case IW_AUTH_80211_AUTH_ALG: |
| 1456 | devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value); |
| 1457 | priv->wpa_authalg = p->value; |
| 1458 | ret = 0; |
| 1459 | break; |
| 1460 | |
| 1461 | case IW_AUTH_WPA_ENABLED: |
| 1462 | devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value); |
| 1463 | if (wrqu->param.value) |
| 1464 | deauthenticate(usbdev); |
| 1465 | ret = 0; |
| 1466 | break; |
| 1467 | |
| 1468 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 1469 | devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x", |
| 1470 | p->value); |
| 1471 | ret = 0; |
| 1472 | break; |
| 1473 | |
| 1474 | case IW_AUTH_ROAMING_CONTROL: |
| 1475 | devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value); |
| 1476 | ret = 0; |
| 1477 | break; |
| 1478 | |
| 1479 | case IW_AUTH_PRIVACY_INVOKED: |
| 1480 | devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d", |
| 1481 | wrqu->param.flags & IW_AUTH_INDEX); |
| 1482 | return -EOPNOTSUPP; |
| 1483 | |
| 1484 | default: |
| 1485 | devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x", |
| 1486 | p->flags & IW_AUTH_INDEX, p->value); |
| 1487 | } |
| 1488 | return ret; |
| 1489 | } |
| 1490 | |
| 1491 | |
| 1492 | static int rndis_iw_get_auth(struct net_device *dev, |
| 1493 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1494 | { |
| 1495 | struct iw_param *p = &wrqu->param; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1496 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1497 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1498 | |
| 1499 | switch (p->flags & IW_AUTH_INDEX) { |
| 1500 | case IW_AUTH_WPA_VERSION: |
| 1501 | p->value = priv->wpa_version; |
| 1502 | break; |
| 1503 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1504 | p->value = priv->wpa_cipher_pair; |
| 1505 | break; |
| 1506 | case IW_AUTH_CIPHER_GROUP: |
| 1507 | p->value = priv->wpa_cipher_group; |
| 1508 | break; |
| 1509 | case IW_AUTH_KEY_MGMT: |
| 1510 | p->value = priv->wpa_keymgmt; |
| 1511 | break; |
| 1512 | case IW_AUTH_80211_AUTH_ALG: |
| 1513 | p->value = priv->wpa_authalg; |
| 1514 | break; |
| 1515 | default: |
| 1516 | devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d", |
| 1517 | wrqu->param.flags & IW_AUTH_INDEX); |
| 1518 | return -EOPNOTSUPP; |
| 1519 | } |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
| 1523 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1524 | static int rndis_iw_set_encode(struct net_device *dev, |
| 1525 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1526 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1527 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1528 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1529 | int ret, index, key_len; |
| 1530 | u8 *key; |
| 1531 | |
| 1532 | index = (wrqu->encoding.flags & IW_ENCODE_INDEX); |
| 1533 | |
| 1534 | /* iwconfig gives index as 1 - N */ |
| 1535 | if (index > 0) |
| 1536 | index--; |
| 1537 | else |
| 1538 | index = priv->encr_tx_key_index; |
| 1539 | |
| 1540 | if (index < 0 || index >= 4) { |
| 1541 | devwarn(usbdev, "encryption index out of range (%u)", index); |
| 1542 | return -EINVAL; |
| 1543 | } |
| 1544 | |
| 1545 | /* remove key if disabled */ |
| 1546 | if (wrqu->data.flags & IW_ENCODE_DISABLED) { |
| 1547 | if (remove_key(usbdev, index, NULL)) |
| 1548 | return -EINVAL; |
| 1549 | else |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
| 1553 | /* global encryption state (for all keys) */ |
| 1554 | if (wrqu->data.flags & IW_ENCODE_OPEN) |
| 1555 | ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED, |
| 1556 | IW_AUTH_ALG_OPEN_SYSTEM); |
| 1557 | else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/ |
| 1558 | ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED, |
| 1559 | IW_AUTH_ALG_SHARED_KEY); |
| 1560 | if (ret != 0) |
| 1561 | return ret; |
| 1562 | |
| 1563 | if (wrqu->data.length > 0) { |
| 1564 | key_len = wrqu->data.length; |
| 1565 | key = extra; |
| 1566 | } else { |
| 1567 | /* must be set as tx key */ |
| 1568 | if (priv->encr_key_len[index] == 0) |
| 1569 | return -EINVAL; |
| 1570 | key_len = priv->encr_key_len[index]; |
| 1571 | key = priv->encr_keys[index]; |
| 1572 | priv->encr_tx_key_index = index; |
| 1573 | } |
| 1574 | |
| 1575 | if (add_wep_key(usbdev, key, key_len, index) != 0) |
| 1576 | return -EINVAL; |
| 1577 | |
| 1578 | if (index == priv->encr_tx_key_index) |
| 1579 | /* ndis drivers want essid to be set after setting encr */ |
| 1580 | set_essid(usbdev, &priv->essid); |
| 1581 | |
| 1582 | return 0; |
| 1583 | } |
| 1584 | |
| 1585 | |
| 1586 | static int rndis_iw_set_encode_ext(struct net_device *dev, |
| 1587 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1588 | { |
| 1589 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1590 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1591 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 1592 | struct ndis_80211_key ndis_key; |
Jussi Kivilinna | cdb2a9f | 2008-03-04 20:05:27 +0200 | [diff] [blame] | 1593 | int keyidx, ret; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1594 | u8 *addr; |
| 1595 | |
| 1596 | keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX; |
| 1597 | |
| 1598 | /* iwconfig gives index as 1 - N */ |
| 1599 | if (keyidx) |
| 1600 | keyidx--; |
| 1601 | else |
| 1602 | keyidx = priv->encr_tx_key_index; |
| 1603 | |
| 1604 | if (keyidx < 0 || keyidx >= 4) |
| 1605 | return -EINVAL; |
| 1606 | |
| 1607 | if (ext->alg == WPA_ALG_WEP) { |
| 1608 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) |
| 1609 | priv->encr_tx_key_index = keyidx; |
| 1610 | return add_wep_key(usbdev, ext->key, ext->key_len, keyidx); |
| 1611 | } |
| 1612 | |
| 1613 | if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) || |
| 1614 | ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0) |
| 1615 | return remove_key(usbdev, keyidx, NULL); |
| 1616 | |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1617 | if (ext->key_len > sizeof(ndis_key.material)) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1618 | return -1; |
| 1619 | |
| 1620 | memset(&ndis_key, 0, sizeof(ndis_key)); |
| 1621 | |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1622 | ndis_key.size = cpu_to_le32(sizeof(ndis_key) - |
| 1623 | sizeof(ndis_key.material) + ext->key_len); |
| 1624 | ndis_key.length = cpu_to_le32(ext->key_len); |
| 1625 | ndis_key.index = cpu_to_le32(keyidx); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1626 | |
| 1627 | if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1628 | memcpy(ndis_key.rsc, ext->rx_seq, 6); |
| 1629 | ndis_key.index |= cpu_to_le32(1 << 29); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | addr = ext->addr.sa_data; |
| 1633 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { |
| 1634 | /* group key */ |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 1635 | if (priv->infra_mode == ndis_80211_infra_adhoc) |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1636 | memset(ndis_key.bssid, 0xff, ETH_ALEN); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1637 | else |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1638 | get_bssid(usbdev, ndis_key.bssid); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1639 | } else { |
| 1640 | /* pairwise key */ |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1641 | ndis_key.index |= cpu_to_le32(1 << 30); |
| 1642 | memcpy(ndis_key.bssid, addr, ETH_ALEN); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1646 | ndis_key.index |= cpu_to_le32(1 << 31); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1647 | |
| 1648 | if (ext->alg == IW_ENCODE_ALG_TKIP && ext->key_len == 32) { |
| 1649 | /* wpa_supplicant gives us the Michael MIC RX/TX keys in |
| 1650 | * different order than NDIS spec, so swap the order here. */ |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1651 | memcpy(ndis_key.material, ext->key, 16); |
| 1652 | memcpy(ndis_key.material + 16, ext->key + 24, 8); |
| 1653 | memcpy(ndis_key.material + 24, ext->key + 16, 8); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1654 | } else |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1655 | memcpy(ndis_key.material, ext->key, ext->key_len); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1656 | |
| 1657 | ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key, |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1658 | le32_to_cpu(ndis_key.size)); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1659 | devdbg(usbdev, "SIOCSIWENCODEEXT: OID_802_11_ADD_KEY -> %08X", ret); |
| 1660 | if (ret != 0) |
| 1661 | return ret; |
| 1662 | |
| 1663 | priv->encr_key_len[keyidx] = ext->key_len; |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1664 | memcpy(&priv->encr_keys[keyidx], ndis_key.material, ext->key_len); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1665 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) |
| 1666 | priv->encr_tx_key_index = keyidx; |
| 1667 | |
| 1668 | return 0; |
| 1669 | } |
| 1670 | |
| 1671 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1672 | static int rndis_iw_set_genie(struct net_device *dev, |
| 1673 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1674 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1675 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1676 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1677 | int ret = 0; |
| 1678 | |
| 1679 | #ifdef DEBUG |
| 1680 | int j; |
| 1681 | u8 *gie = extra; |
| 1682 | for (j = 0; j < wrqu->data.length; j += 8) |
| 1683 | devdbg(usbdev, |
| 1684 | "SIOCSIWGENIE %04x - " |
| 1685 | "%02x %02x %02x %02x %02x %02x %02x %02x", j, |
| 1686 | gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3], |
| 1687 | gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]); |
| 1688 | #endif |
| 1689 | /* clear existing IEs */ |
| 1690 | if (priv->wpa_ie_len) { |
| 1691 | kfree(priv->wpa_ie); |
| 1692 | priv->wpa_ie_len = 0; |
| 1693 | } |
| 1694 | |
| 1695 | /* set new IEs */ |
| 1696 | priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 1697 | if (priv->wpa_ie) { |
| 1698 | priv->wpa_ie_len = wrqu->data.length; |
| 1699 | memcpy(priv->wpa_ie, extra, priv->wpa_ie_len); |
| 1700 | } else |
| 1701 | ret = -ENOMEM; |
| 1702 | return ret; |
| 1703 | } |
| 1704 | |
| 1705 | |
| 1706 | static int rndis_iw_get_genie(struct net_device *dev, |
| 1707 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1708 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1709 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1710 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1711 | |
| 1712 | devdbg(usbdev, "SIOCGIWGENIE"); |
| 1713 | |
| 1714 | if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) { |
| 1715 | wrqu->data.length = 0; |
| 1716 | return 0; |
| 1717 | } |
| 1718 | |
| 1719 | if (wrqu->data.length < priv->wpa_ie_len) |
| 1720 | return -E2BIG; |
| 1721 | |
| 1722 | wrqu->data.length = priv->wpa_ie_len; |
| 1723 | memcpy(extra, priv->wpa_ie, priv->wpa_ie_len); |
| 1724 | |
| 1725 | return 0; |
| 1726 | } |
| 1727 | |
| 1728 | |
| 1729 | static int rndis_iw_set_rts(struct net_device *dev, |
| 1730 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1731 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1732 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1733 | __le32 tmp; |
| 1734 | devdbg(usbdev, "SIOCSIWRTS"); |
| 1735 | |
| 1736 | tmp = cpu_to_le32(wrqu->rts.value); |
| 1737 | return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp, |
| 1738 | sizeof(tmp)); |
| 1739 | } |
| 1740 | |
| 1741 | |
| 1742 | static int rndis_iw_get_rts(struct net_device *dev, |
| 1743 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1744 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1745 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1746 | __le32 tmp; |
| 1747 | int len, ret; |
| 1748 | |
| 1749 | len = sizeof(tmp); |
| 1750 | ret = rndis_query_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp, &len); |
| 1751 | if (ret == 0) { |
| 1752 | wrqu->rts.value = le32_to_cpu(tmp); |
| 1753 | wrqu->rts.flags = 1; |
| 1754 | wrqu->rts.disabled = 0; |
| 1755 | } |
| 1756 | |
| 1757 | devdbg(usbdev, "SIOCGIWRTS: %d", wrqu->rts.value); |
| 1758 | |
| 1759 | return ret; |
| 1760 | } |
| 1761 | |
| 1762 | |
| 1763 | static int rndis_iw_set_frag(struct net_device *dev, |
| 1764 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1765 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1766 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1767 | __le32 tmp; |
| 1768 | |
| 1769 | devdbg(usbdev, "SIOCSIWFRAG"); |
| 1770 | |
| 1771 | tmp = cpu_to_le32(wrqu->frag.value); |
| 1772 | return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp, |
| 1773 | sizeof(tmp)); |
| 1774 | } |
| 1775 | |
| 1776 | |
| 1777 | static int rndis_iw_get_frag(struct net_device *dev, |
| 1778 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1779 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1780 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1781 | __le32 tmp; |
| 1782 | int len, ret; |
| 1783 | |
| 1784 | len = sizeof(tmp); |
| 1785 | ret = rndis_query_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp, |
| 1786 | &len); |
| 1787 | if (ret == 0) { |
| 1788 | wrqu->frag.value = le32_to_cpu(tmp); |
| 1789 | wrqu->frag.flags = 1; |
| 1790 | wrqu->frag.disabled = 0; |
| 1791 | } |
| 1792 | devdbg(usbdev, "SIOCGIWFRAG: %d", wrqu->frag.value); |
| 1793 | return ret; |
| 1794 | } |
| 1795 | |
| 1796 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1797 | static int rndis_iw_set_freq(struct net_device *dev, |
| 1798 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1799 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1800 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 1801 | struct ndis_80211_conf config; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1802 | unsigned int dsconfig; |
| 1803 | int len, ret; |
| 1804 | |
| 1805 | /* this OID is valid only when not associated */ |
| 1806 | if (is_associated(usbdev)) |
| 1807 | return 0; |
| 1808 | |
| 1809 | dsconfig = 0; |
| 1810 | if (freq_to_dsconfig(&wrqu->freq, &dsconfig)) |
| 1811 | return -EINVAL; |
| 1812 | |
| 1813 | len = sizeof(config); |
| 1814 | ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len); |
| 1815 | if (ret != 0) { |
| 1816 | devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed"); |
| 1817 | return 0; |
| 1818 | } |
| 1819 | |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1820 | config.ds_config = cpu_to_le32(dsconfig); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1821 | |
| 1822 | devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e); |
| 1823 | return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config, |
| 1824 | sizeof(config)); |
| 1825 | } |
| 1826 | |
| 1827 | |
| 1828 | static int rndis_iw_get_freq(struct net_device *dev, |
| 1829 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1830 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1831 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 1832 | struct ndis_80211_conf config; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1833 | int len, ret; |
| 1834 | |
| 1835 | len = sizeof(config); |
| 1836 | ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len); |
| 1837 | if (ret == 0) |
Jussi Kivilinna | 461b3f2 | 2008-03-08 01:23:25 +0200 | [diff] [blame] | 1838 | dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1839 | |
| 1840 | devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m); |
| 1841 | return ret; |
| 1842 | } |
| 1843 | |
| 1844 | |
| 1845 | static int rndis_iw_get_txpower(struct net_device *dev, |
| 1846 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1847 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1848 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1849 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1850 | __le32 tx_power; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1851 | |
| 1852 | if (priv->radio_on) { |
Jussi Kivilinna | 9656e85 | 2009-05-22 17:40:12 +0300 | [diff] [blame^] | 1853 | /* fake since changing tx_power (by userlevel) not supported */ |
| 1854 | tx_power = cpu_to_le32(get_bcm4320_power(priv)); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1855 | |
| 1856 | wrqu->txpower.flags = IW_TXPOW_MWATT; |
| 1857 | wrqu->txpower.value = le32_to_cpu(tx_power); |
| 1858 | wrqu->txpower.disabled = 0; |
| 1859 | } else { |
| 1860 | wrqu->txpower.flags = IW_TXPOW_MWATT; |
| 1861 | wrqu->txpower.value = 0; |
| 1862 | wrqu->txpower.disabled = 1; |
| 1863 | } |
| 1864 | |
| 1865 | devdbg(usbdev, "SIOCGIWTXPOW: %d", wrqu->txpower.value); |
| 1866 | |
Jussi Kivilinna | 9656e85 | 2009-05-22 17:40:12 +0300 | [diff] [blame^] | 1867 | return 0; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | |
| 1871 | static int rndis_iw_set_txpower(struct net_device *dev, |
| 1872 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1873 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1874 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1875 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1876 | __le32 tx_power = 0; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1877 | |
| 1878 | if (!wrqu->txpower.disabled) { |
| 1879 | if (wrqu->txpower.flags == IW_TXPOW_MWATT) |
| 1880 | tx_power = cpu_to_le32(wrqu->txpower.value); |
| 1881 | else { /* wrqu->txpower.flags == IW_TXPOW_DBM */ |
| 1882 | if (wrqu->txpower.value > 20) |
| 1883 | tx_power = cpu_to_le32(128); |
| 1884 | else if (wrqu->txpower.value < -43) |
| 1885 | tx_power = cpu_to_le32(127); |
| 1886 | else { |
| 1887 | signed char tmp; |
| 1888 | tmp = wrqu->txpower.value; |
| 1889 | tmp = -12 - tmp; |
| 1890 | tmp <<= 2; |
| 1891 | tx_power = cpu_to_le32((unsigned char)tmp); |
| 1892 | } |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | devdbg(usbdev, "SIOCSIWTXPOW: %d", le32_to_cpu(tx_power)); |
| 1897 | |
| 1898 | if (le32_to_cpu(tx_power) != 0) { |
Jussi Kivilinna | 9656e85 | 2009-05-22 17:40:12 +0300 | [diff] [blame^] | 1899 | /* txpower unsupported, just turn radio on */ |
| 1900 | if (!priv->radio_on) |
| 1901 | return disassociate(usbdev, 1); |
| 1902 | return 0; /* all ready on */ |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | /* tx_power == 0, turn off radio */ |
| 1906 | return disassociate(usbdev, 0); |
| 1907 | } |
| 1908 | |
| 1909 | |
| 1910 | static int rndis_iw_get_rate(struct net_device *dev, |
| 1911 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1912 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1913 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1914 | __le32 tmp; |
| 1915 | int ret, len; |
| 1916 | |
| 1917 | len = sizeof(tmp); |
| 1918 | ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len); |
| 1919 | if (ret == 0) { |
| 1920 | wrqu->bitrate.value = le32_to_cpu(tmp) * 100; |
| 1921 | wrqu->bitrate.disabled = 0; |
| 1922 | wrqu->bitrate.flags = 1; |
| 1923 | } |
| 1924 | return ret; |
| 1925 | } |
| 1926 | |
| 1927 | |
| 1928 | static int rndis_iw_set_mlme(struct net_device *dev, |
| 1929 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) |
| 1930 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1931 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1932 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1933 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 1934 | unsigned char bssid[ETH_ALEN]; |
| 1935 | |
| 1936 | get_bssid(usbdev, bssid); |
| 1937 | |
| 1938 | if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN)) |
| 1939 | return -EINVAL; |
| 1940 | |
| 1941 | switch (mlme->cmd) { |
| 1942 | case IW_MLME_DEAUTH: |
| 1943 | return deauthenticate(usbdev); |
| 1944 | case IW_MLME_DISASSOC: |
| 1945 | return disassociate(usbdev, priv->radio_on); |
| 1946 | default: |
| 1947 | return -EOPNOTSUPP; |
| 1948 | } |
| 1949 | |
| 1950 | return 0; |
| 1951 | } |
| 1952 | |
| 1953 | |
| 1954 | static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev) |
| 1955 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1956 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1957 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 1958 | unsigned long flags; |
| 1959 | |
| 1960 | spin_lock_irqsave(&priv->stats_lock, flags); |
| 1961 | memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats)); |
| 1962 | spin_unlock_irqrestore(&priv->stats_lock, flags); |
| 1963 | |
| 1964 | return &priv->iwstats; |
| 1965 | } |
| 1966 | |
| 1967 | |
| 1968 | #define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT] |
| 1969 | static const iw_handler rndis_iw_handler[] = |
| 1970 | { |
| 1971 | IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit, |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 1972 | IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname, |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1973 | IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq, |
| 1974 | IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq, |
John W. Linville | 964c1d4 | 2009-03-26 23:40:01 +0200 | [diff] [blame] | 1975 | IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode, |
| 1976 | IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode, |
Jussi Kivilinna | 4d2a369 | 2009-03-26 23:40:23 +0200 | [diff] [blame] | 1977 | IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange, |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1978 | IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid, |
| 1979 | IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid, |
Jussi Kivilinna | 71a7b26 | 2009-03-26 23:40:31 +0200 | [diff] [blame] | 1980 | IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan, |
| 1981 | IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan, |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1982 | IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid, |
| 1983 | IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid, |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 1984 | IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate, |
| 1985 | IW_IOCTL(SIOCSIWRTS) = rndis_iw_set_rts, |
| 1986 | IW_IOCTL(SIOCGIWRTS) = rndis_iw_get_rts, |
| 1987 | IW_IOCTL(SIOCSIWFRAG) = rndis_iw_set_frag, |
| 1988 | IW_IOCTL(SIOCGIWFRAG) = rndis_iw_get_frag, |
| 1989 | IW_IOCTL(SIOCSIWTXPOW) = rndis_iw_set_txpower, |
| 1990 | IW_IOCTL(SIOCGIWTXPOW) = rndis_iw_get_txpower, |
| 1991 | IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode, |
| 1992 | IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext, |
| 1993 | IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth, |
| 1994 | IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth, |
| 1995 | IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie, |
| 1996 | IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie, |
| 1997 | IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme, |
| 1998 | }; |
| 1999 | |
| 2000 | static const iw_handler rndis_wext_private_handler[] = { |
| 2001 | }; |
| 2002 | |
| 2003 | static const struct iw_priv_args rndis_wext_private_args[] = { |
| 2004 | }; |
| 2005 | |
| 2006 | |
| 2007 | static const struct iw_handler_def rndis_iw_handlers = { |
| 2008 | .num_standard = ARRAY_SIZE(rndis_iw_handler), |
| 2009 | .num_private = ARRAY_SIZE(rndis_wext_private_handler), |
| 2010 | .num_private_args = ARRAY_SIZE(rndis_wext_private_args), |
| 2011 | .standard = (iw_handler *)rndis_iw_handler, |
| 2012 | .private = (iw_handler *)rndis_wext_private_handler, |
| 2013 | .private_args = (struct iw_priv_args *)rndis_wext_private_args, |
| 2014 | .get_wireless_stats = rndis_get_wireless_stats, |
| 2015 | }; |
| 2016 | |
| 2017 | |
| 2018 | static void rndis_wext_worker(struct work_struct *work) |
| 2019 | { |
| 2020 | struct rndis_wext_private *priv = |
| 2021 | container_of(work, struct rndis_wext_private, work); |
| 2022 | struct usbnet *usbdev = priv->usbdev; |
| 2023 | union iwreq_data evt; |
| 2024 | unsigned char bssid[ETH_ALEN]; |
Scott Ashcroft | 4364623 | 2008-05-27 00:06:15 +0300 | [diff] [blame] | 2025 | struct ndis_80211_assoc_info *info; |
| 2026 | int assoc_size = sizeof(*info) + IW_CUSTOM_MAX + 32; |
| 2027 | int ret, offset; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2028 | |
Jussi Kivilinna | 6010ce0 | 2008-06-02 18:35:21 +0300 | [diff] [blame] | 2029 | if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending)) { |
Jussi Kivilinna | 5331b96 | 2008-06-02 18:35:29 +0300 | [diff] [blame] | 2030 | netif_carrier_on(usbdev->net); |
| 2031 | |
Scott Ashcroft | 4364623 | 2008-05-27 00:06:15 +0300 | [diff] [blame] | 2032 | info = kzalloc(assoc_size, GFP_KERNEL); |
| 2033 | if (!info) |
| 2034 | goto get_bssid; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2035 | |
Scott Ashcroft | 4364623 | 2008-05-27 00:06:15 +0300 | [diff] [blame] | 2036 | /* Get association info IEs from device and send them back to |
| 2037 | * userspace. */ |
| 2038 | ret = get_association_info(usbdev, info, assoc_size); |
| 2039 | if (!ret) { |
| 2040 | evt.data.length = le32_to_cpu(info->req_ie_length); |
| 2041 | if (evt.data.length > 0) { |
| 2042 | offset = le32_to_cpu(info->offset_req_ies); |
| 2043 | wireless_send_event(usbdev->net, |
| 2044 | IWEVASSOCREQIE, &evt, |
| 2045 | (char *)info + offset); |
| 2046 | } |
| 2047 | |
| 2048 | evt.data.length = le32_to_cpu(info->resp_ie_length); |
| 2049 | if (evt.data.length > 0) { |
| 2050 | offset = le32_to_cpu(info->offset_resp_ies); |
| 2051 | wireless_send_event(usbdev->net, |
| 2052 | IWEVASSOCRESPIE, &evt, |
| 2053 | (char *)info + offset); |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | kfree(info); |
| 2058 | |
| 2059 | get_bssid: |
| 2060 | ret = get_bssid(usbdev, bssid); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2061 | if (!ret) { |
| 2062 | evt.data.flags = 0; |
| 2063 | evt.data.length = 0; |
| 2064 | memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN); |
| 2065 | wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL); |
| 2066 | } |
| 2067 | } |
| 2068 | |
Jussi Kivilinna | 6010ce0 | 2008-06-02 18:35:21 +0300 | [diff] [blame] | 2069 | if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending)) { |
Jussi Kivilinna | 5331b96 | 2008-06-02 18:35:29 +0300 | [diff] [blame] | 2070 | netif_carrier_off(usbdev->net); |
| 2071 | |
Jussi Kivilinna | 6010ce0 | 2008-06-02 18:35:21 +0300 | [diff] [blame] | 2072 | evt.data.flags = 0; |
| 2073 | evt.data.length = 0; |
| 2074 | memset(evt.ap_addr.sa_data, 0, ETH_ALEN); |
| 2075 | wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL); |
| 2076 | } |
| 2077 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2078 | if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending)) |
| 2079 | set_multicast_list(usbdev); |
| 2080 | } |
| 2081 | |
| 2082 | static void rndis_wext_set_multicast_list(struct net_device *dev) |
| 2083 | { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 2084 | struct usbnet *usbdev = netdev_priv(dev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2085 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
| 2086 | |
Jussi Kivilinna | a67edb9 | 2008-06-02 18:35:36 +0300 | [diff] [blame] | 2087 | if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending)) |
| 2088 | return; |
| 2089 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2090 | set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending); |
| 2091 | queue_work(priv->workqueue, &priv->work); |
| 2092 | } |
| 2093 | |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2094 | static void rndis_wext_link_change(struct usbnet *usbdev, int state) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2095 | { |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2096 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2097 | |
Jussi Kivilinna | 6010ce0 | 2008-06-02 18:35:21 +0300 | [diff] [blame] | 2098 | /* queue work to avoid recursive calls into rndis_command */ |
| 2099 | set_bit(state ? WORK_LINK_UP : WORK_LINK_DOWN, &priv->work_pending); |
| 2100 | queue_work(priv->workqueue, &priv->work); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2104 | static int rndis_wext_get_caps(struct usbnet *usbdev) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2105 | { |
| 2106 | struct { |
| 2107 | __le32 num_items; |
| 2108 | __le32 items[8]; |
| 2109 | } networks_supported; |
| 2110 | int len, retval, i, n; |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2111 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2112 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2113 | /* determine supported modes */ |
| 2114 | len = sizeof(networks_supported); |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2115 | retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED, |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2116 | &networks_supported, &len); |
| 2117 | if (retval >= 0) { |
| 2118 | n = le32_to_cpu(networks_supported.num_items); |
| 2119 | if (n > 8) |
| 2120 | n = 8; |
| 2121 | for (i = 0; i < n; i++) { |
| 2122 | switch (le32_to_cpu(networks_supported.items[i])) { |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 2123 | case ndis_80211_type_freq_hop: |
| 2124 | case ndis_80211_type_direct_seq: |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2125 | priv->caps |= CAP_MODE_80211B; |
| 2126 | break; |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 2127 | case ndis_80211_type_ofdm_a: |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2128 | priv->caps |= CAP_MODE_80211A; |
| 2129 | break; |
Jussi Kivilinna | 1e41e1d | 2008-03-08 01:23:17 +0200 | [diff] [blame] | 2130 | case ndis_80211_type_ofdm_g: |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2131 | priv->caps |= CAP_MODE_80211G; |
| 2132 | break; |
| 2133 | } |
| 2134 | } |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | return retval; |
| 2138 | } |
| 2139 | |
| 2140 | |
| 2141 | #define STATS_UPDATE_JIFFIES (HZ) |
| 2142 | static void rndis_update_wireless_stats(struct work_struct *work) |
| 2143 | { |
| 2144 | struct rndis_wext_private *priv = |
| 2145 | container_of(work, struct rndis_wext_private, stats_work.work); |
| 2146 | struct usbnet *usbdev = priv->usbdev; |
| 2147 | struct iw_statistics iwstats; |
| 2148 | __le32 rssi, tmp; |
Jussi Kivilinna | a97b1f3 | 2008-02-06 15:36:10 +0200 | [diff] [blame] | 2149 | int len, ret, j; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2150 | unsigned long flags; |
| 2151 | int update_jiffies = STATS_UPDATE_JIFFIES; |
| 2152 | void *buf; |
| 2153 | |
| 2154 | spin_lock_irqsave(&priv->stats_lock, flags); |
| 2155 | memcpy(&iwstats, &priv->privstats, sizeof(iwstats)); |
| 2156 | spin_unlock_irqrestore(&priv->stats_lock, flags); |
| 2157 | |
| 2158 | /* only update stats when connected */ |
| 2159 | if (!is_associated(usbdev)) { |
| 2160 | iwstats.qual.qual = 0; |
| 2161 | iwstats.qual.level = 0; |
| 2162 | iwstats.qual.updated = IW_QUAL_QUAL_UPDATED |
| 2163 | | IW_QUAL_LEVEL_UPDATED |
| 2164 | | IW_QUAL_NOISE_INVALID |
| 2165 | | IW_QUAL_QUAL_INVALID |
| 2166 | | IW_QUAL_LEVEL_INVALID; |
| 2167 | goto end; |
| 2168 | } |
| 2169 | |
| 2170 | len = sizeof(rssi); |
| 2171 | ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len); |
| 2172 | |
| 2173 | devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret, |
| 2174 | le32_to_cpu(rssi)); |
| 2175 | if (ret == 0) { |
| 2176 | memset(&iwstats.qual, 0, sizeof(iwstats.qual)); |
| 2177 | iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi)); |
Jussi Kivilinna | 4bd7f03 | 2009-03-26 23:40:16 +0200 | [diff] [blame] | 2178 | iwstats.qual.level = level_to_qual(le32_to_cpu(rssi)); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2179 | iwstats.qual.updated = IW_QUAL_QUAL_UPDATED |
| 2180 | | IW_QUAL_LEVEL_UPDATED |
| 2181 | | IW_QUAL_NOISE_INVALID; |
| 2182 | } |
| 2183 | |
| 2184 | memset(&iwstats.discard, 0, sizeof(iwstats.discard)); |
| 2185 | |
| 2186 | len = sizeof(tmp); |
| 2187 | ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len); |
| 2188 | if (ret == 0) |
| 2189 | iwstats.discard.misc += le32_to_cpu(tmp); |
| 2190 | |
| 2191 | len = sizeof(tmp); |
| 2192 | ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len); |
| 2193 | if (ret == 0) |
| 2194 | iwstats.discard.misc += le32_to_cpu(tmp); |
| 2195 | |
| 2196 | len = sizeof(tmp); |
| 2197 | ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len); |
| 2198 | if (ret == 0) |
| 2199 | iwstats.discard.misc += le32_to_cpu(tmp); |
| 2200 | |
Jussi Kivilinna | a97b1f3 | 2008-02-06 15:36:10 +0200 | [diff] [blame] | 2201 | /* Workaround transfer stalls on poor quality links. |
| 2202 | * TODO: find right way to fix these stalls (as stalls do not happen |
| 2203 | * with ndiswrapper/windows driver). */ |
| 2204 | if (iwstats.qual.qual <= 25) { |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2205 | /* Decrease stats worker interval to catch stalls. |
| 2206 | * faster. Faster than 400-500ms causes packet loss, |
| 2207 | * Slower doesn't catch stalls fast enough. |
| 2208 | */ |
| 2209 | j = msecs_to_jiffies(priv->param_workaround_interval); |
| 2210 | if (j > STATS_UPDATE_JIFFIES) |
| 2211 | j = STATS_UPDATE_JIFFIES; |
| 2212 | else if (j <= 0) |
| 2213 | j = 1; |
| 2214 | update_jiffies = j; |
| 2215 | |
| 2216 | /* Send scan OID. Use of both OIDs is required to get device |
| 2217 | * working. |
| 2218 | */ |
Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 2219 | tmp = cpu_to_le32(1); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2220 | rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp, |
| 2221 | sizeof(tmp)); |
| 2222 | |
| 2223 | len = CONTROL_BUFFER_SIZE; |
| 2224 | buf = kmalloc(len, GFP_KERNEL); |
| 2225 | if (!buf) |
| 2226 | goto end; |
| 2227 | |
| 2228 | rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len); |
| 2229 | kfree(buf); |
| 2230 | } |
| 2231 | end: |
| 2232 | spin_lock_irqsave(&priv->stats_lock, flags); |
| 2233 | memcpy(&priv->privstats, &iwstats, sizeof(iwstats)); |
| 2234 | spin_unlock_irqrestore(&priv->stats_lock, flags); |
| 2235 | |
| 2236 | if (update_jiffies >= HZ) |
| 2237 | update_jiffies = round_jiffies_relative(update_jiffies); |
| 2238 | else { |
| 2239 | j = round_jiffies_relative(update_jiffies); |
| 2240 | if (abs(j - update_jiffies) <= 10) |
| 2241 | update_jiffies = j; |
| 2242 | } |
| 2243 | |
| 2244 | queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies); |
| 2245 | } |
| 2246 | |
| 2247 | |
Jussi Kivilinna | 59620e9 | 2009-05-22 11:58:36 +0300 | [diff] [blame] | 2248 | static int bcm4320a_early_init(struct usbnet *usbdev) |
| 2249 | { |
| 2250 | /* bcm4320a doesn't handle configuration parameters well. Try |
| 2251 | * set any and you get partially zeroed mac and broken device. |
| 2252 | */ |
| 2253 | |
| 2254 | return 0; |
| 2255 | } |
| 2256 | |
| 2257 | |
| 2258 | static int bcm4320b_early_init(struct usbnet *usbdev) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2259 | { |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2260 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2261 | char buf[8]; |
| 2262 | |
| 2263 | /* Early initialization settings, setting these won't have effect |
| 2264 | * if called after generic_rndis_bind(). |
| 2265 | */ |
| 2266 | |
| 2267 | priv->param_country[0] = modparam_country[0]; |
| 2268 | priv->param_country[1] = modparam_country[1]; |
| 2269 | priv->param_country[2] = 0; |
| 2270 | priv->param_frameburst = modparam_frameburst; |
| 2271 | priv->param_afterburner = modparam_afterburner; |
| 2272 | priv->param_power_save = modparam_power_save; |
| 2273 | priv->param_power_output = modparam_power_output; |
| 2274 | priv->param_roamtrigger = modparam_roamtrigger; |
| 2275 | priv->param_roamdelta = modparam_roamdelta; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2276 | |
| 2277 | priv->param_country[0] = toupper(priv->param_country[0]); |
| 2278 | priv->param_country[1] = toupper(priv->param_country[1]); |
| 2279 | /* doesn't support EU as country code, use FI instead */ |
| 2280 | if (!strcmp(priv->param_country, "EU")) |
| 2281 | strcpy(priv->param_country, "FI"); |
| 2282 | |
| 2283 | if (priv->param_power_save < 0) |
| 2284 | priv->param_power_save = 0; |
| 2285 | else if (priv->param_power_save > 2) |
| 2286 | priv->param_power_save = 2; |
| 2287 | |
Jussi Kivilinna | a762483 | 2008-05-27 11:15:08 +0300 | [diff] [blame] | 2288 | if (priv->param_power_output < 0) |
| 2289 | priv->param_power_output = 0; |
| 2290 | else if (priv->param_power_output > 3) |
| 2291 | priv->param_power_output = 3; |
| 2292 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2293 | if (priv->param_roamtrigger < -80) |
| 2294 | priv->param_roamtrigger = -80; |
| 2295 | else if (priv->param_roamtrigger > -60) |
| 2296 | priv->param_roamtrigger = -60; |
| 2297 | |
| 2298 | if (priv->param_roamdelta < 0) |
| 2299 | priv->param_roamdelta = 0; |
| 2300 | else if (priv->param_roamdelta > 2) |
| 2301 | priv->param_roamdelta = 2; |
| 2302 | |
Roel Kluin | 4d381ff | 2008-04-23 22:10:29 +0200 | [diff] [blame] | 2303 | if (modparam_workaround_interval < 0) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2304 | priv->param_workaround_interval = 500; |
Roel Kluin | 4d381ff | 2008-04-23 22:10:29 +0200 | [diff] [blame] | 2305 | else |
| 2306 | priv->param_workaround_interval = modparam_workaround_interval; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2307 | |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2308 | rndis_set_config_parameter_str(usbdev, "Country", priv->param_country); |
| 2309 | rndis_set_config_parameter_str(usbdev, "FrameBursting", |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2310 | priv->param_frameburst ? "1" : "0"); |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2311 | rndis_set_config_parameter_str(usbdev, "Afterburner", |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2312 | priv->param_afterburner ? "1" : "0"); |
| 2313 | sprintf(buf, "%d", priv->param_power_save); |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2314 | rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2315 | sprintf(buf, "%d", priv->param_power_output); |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2316 | rndis_set_config_parameter_str(usbdev, "PwrOut", buf); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2317 | sprintf(buf, "%d", priv->param_roamtrigger); |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2318 | rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2319 | sprintf(buf, "%d", priv->param_roamdelta); |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2320 | rndis_set_config_parameter_str(usbdev, "RoamDelta", buf); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2321 | |
| 2322 | return 0; |
| 2323 | } |
| 2324 | |
David S. Miller | 23d12e2 | 2009-03-25 00:03:16 -0700 | [diff] [blame] | 2325 | /* same as rndis_netdev_ops but with local multicast handler */ |
| 2326 | static const struct net_device_ops rndis_wext_netdev_ops = { |
| 2327 | .ndo_open = usbnet_open, |
| 2328 | .ndo_stop = usbnet_stop, |
| 2329 | .ndo_start_xmit = usbnet_start_xmit, |
| 2330 | .ndo_tx_timeout = usbnet_tx_timeout, |
| 2331 | .ndo_set_mac_address = eth_mac_addr, |
| 2332 | .ndo_validate_addr = eth_validate_addr, |
| 2333 | .ndo_set_multicast_list = rndis_wext_set_multicast_list, |
| 2334 | }; |
| 2335 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2336 | |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2337 | static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2338 | { |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 2339 | struct wiphy *wiphy; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2340 | struct rndis_wext_private *priv; |
| 2341 | int retval, len; |
| 2342 | __le32 tmp; |
| 2343 | |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 2344 | /* allocate wiphy and rndis private data |
| 2345 | * NOTE: We only support a single virtual interface, so wiphy |
| 2346 | * and wireless_dev are somewhat synonymous for this device. |
| 2347 | */ |
| 2348 | wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wext_private)); |
| 2349 | if (!wiphy) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2350 | return -ENOMEM; |
| 2351 | |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 2352 | priv = wiphy_priv(wiphy); |
| 2353 | usbdev->net->ieee80211_ptr = &priv->wdev; |
| 2354 | priv->wdev.wiphy = wiphy; |
| 2355 | priv->wdev.iftype = NL80211_IFTYPE_STATION; |
| 2356 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2357 | /* These have to be initialized before calling generic_rndis_bind(). |
| 2358 | * Otherwise we'll be in big trouble in rndis_wext_early_init(). |
| 2359 | */ |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2360 | usbdev->driver_priv = priv; |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2361 | usbdev->net->wireless_handlers = &rndis_iw_handlers; |
| 2362 | priv->usbdev = usbdev; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2363 | |
| 2364 | mutex_init(&priv->command_lock); |
| 2365 | spin_lock_init(&priv->stats_lock); |
| 2366 | |
Jussi Kivilinna | 8d4d99a | 2009-04-21 19:48:07 +0300 | [diff] [blame] | 2367 | /* because rndis_command() sleeps we need to use workqueue */ |
| 2368 | priv->workqueue = create_singlethread_workqueue("rndis_wlan"); |
| 2369 | INIT_WORK(&priv->work, rndis_wext_worker); |
| 2370 | INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats); |
| 2371 | INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results); |
| 2372 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2373 | /* try bind rndis_host */ |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2374 | retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2375 | if (retval < 0) |
| 2376 | goto fail; |
| 2377 | |
| 2378 | /* generic_rndis_bind set packet filter to multicast_all+ |
| 2379 | * promisc mode which doesn't work well for our devices (device |
| 2380 | * picks up rssi to closest station instead of to access point). |
| 2381 | * |
| 2382 | * rndis_host wants to avoid all OID as much as possible |
| 2383 | * so do promisc/multicast handling in rndis_wext. |
| 2384 | */ |
David S. Miller | 23d12e2 | 2009-03-25 00:03:16 -0700 | [diff] [blame] | 2385 | usbdev->net->netdev_ops = &rndis_wext_netdev_ops; |
| 2386 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2387 | tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST; |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2388 | retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp, |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2389 | sizeof(tmp)); |
| 2390 | |
| 2391 | len = sizeof(tmp); |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2392 | retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp, |
| 2393 | &len); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2394 | priv->multicast_size = le32_to_cpu(tmp); |
| 2395 | if (retval < 0 || priv->multicast_size < 0) |
| 2396 | priv->multicast_size = 0; |
| 2397 | if (priv->multicast_size > 0) |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2398 | usbdev->net->flags |= IFF_MULTICAST; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2399 | else |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2400 | usbdev->net->flags &= ~IFF_MULTICAST; |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2401 | |
| 2402 | priv->iwstats.qual.qual = 0; |
| 2403 | priv->iwstats.qual.level = 0; |
| 2404 | priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED |
| 2405 | | IW_QUAL_LEVEL_UPDATED |
| 2406 | | IW_QUAL_NOISE_INVALID |
| 2407 | | IW_QUAL_QUAL_INVALID |
| 2408 | | IW_QUAL_LEVEL_INVALID; |
| 2409 | |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 2410 | /* fill-out wiphy structure and register w/ cfg80211 */ |
| 2411 | memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN); |
| 2412 | wiphy->privid = rndis_wiphy_privid; |
| 2413 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
| 2414 | | BIT(NL80211_IFTYPE_ADHOC); |
| 2415 | wiphy->max_scan_ssids = 1; |
| 2416 | |
| 2417 | /* TODO: fill-out band information based on priv->caps */ |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2418 | rndis_wext_get_caps(usbdev); |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 2419 | |
| 2420 | memcpy(priv->channels, rndis_channels, sizeof(rndis_channels)); |
| 2421 | memcpy(priv->rates, rndis_rates, sizeof(rndis_rates)); |
| 2422 | priv->band.channels = priv->channels; |
| 2423 | priv->band.n_channels = ARRAY_SIZE(rndis_channels); |
| 2424 | priv->band.bitrates = priv->rates; |
| 2425 | priv->band.n_bitrates = ARRAY_SIZE(rndis_rates); |
| 2426 | wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band; |
Jussi Kivilinna | 4d2a369 | 2009-03-26 23:40:23 +0200 | [diff] [blame] | 2427 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 2428 | |
| 2429 | set_wiphy_dev(wiphy, &usbdev->udev->dev); |
| 2430 | |
| 2431 | if (wiphy_register(wiphy)) { |
Jussi Kivilinna | eb1a685 | 2009-04-21 19:48:15 +0300 | [diff] [blame] | 2432 | retval = -ENODEV; |
| 2433 | goto fail; |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 2434 | } |
| 2435 | |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2436 | set_default_iw_params(usbdev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2437 | |
| 2438 | /* turn radio on */ |
| 2439 | priv->radio_on = 1; |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2440 | disassociate(usbdev, 1); |
| 2441 | netif_carrier_off(usbdev->net); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2442 | |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2443 | queue_delayed_work(priv->workqueue, &priv->stats_work, |
| 2444 | round_jiffies_relative(STATS_UPDATE_JIFFIES)); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2445 | |
| 2446 | return 0; |
| 2447 | |
| 2448 | fail: |
Jussi Kivilinna | 8d4d99a | 2009-04-21 19:48:07 +0300 | [diff] [blame] | 2449 | cancel_delayed_work_sync(&priv->stats_work); |
| 2450 | cancel_delayed_work_sync(&priv->scan_work); |
| 2451 | cancel_work_sync(&priv->work); |
| 2452 | flush_workqueue(priv->workqueue); |
| 2453 | destroy_workqueue(priv->workqueue); |
| 2454 | |
Jussi Kivilinna | eb1a685 | 2009-04-21 19:48:15 +0300 | [diff] [blame] | 2455 | wiphy_free(wiphy); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2456 | return retval; |
| 2457 | } |
| 2458 | |
| 2459 | |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2460 | static void rndis_wext_unbind(struct usbnet *usbdev, struct usb_interface *intf) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2461 | { |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2462 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2463 | |
| 2464 | /* turn radio off */ |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2465 | disassociate(usbdev, 0); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2466 | |
| 2467 | cancel_delayed_work_sync(&priv->stats_work); |
Jussi Kivilinna | 71a7b26 | 2009-03-26 23:40:31 +0200 | [diff] [blame] | 2468 | cancel_delayed_work_sync(&priv->scan_work); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2469 | cancel_work_sync(&priv->work); |
| 2470 | flush_workqueue(priv->workqueue); |
| 2471 | destroy_workqueue(priv->workqueue); |
| 2472 | |
| 2473 | if (priv && priv->wpa_ie_len) |
| 2474 | kfree(priv->wpa_ie); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2475 | |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2476 | rndis_unbind(usbdev, intf); |
John W. Linville | 5c8fa4f | 2009-03-26 23:39:53 +0200 | [diff] [blame] | 2477 | |
| 2478 | wiphy_unregister(priv->wdev.wiphy); |
| 2479 | wiphy_free(priv->wdev.wiphy); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2483 | static int rndis_wext_reset(struct usbnet *usbdev) |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2484 | { |
Jussi Kivilinna | a19d729 | 2008-06-02 18:35:44 +0300 | [diff] [blame] | 2485 | return deauthenticate(usbdev); |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | |
| 2489 | static const struct driver_info bcm4320b_info = { |
| 2490 | .description = "Wireless RNDIS device, BCM4320b based", |
| 2491 | .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT, |
| 2492 | .bind = rndis_wext_bind, |
| 2493 | .unbind = rndis_wext_unbind, |
| 2494 | .status = rndis_status, |
| 2495 | .rx_fixup = rndis_rx_fixup, |
| 2496 | .tx_fixup = rndis_tx_fixup, |
| 2497 | .reset = rndis_wext_reset, |
Jussi Kivilinna | 59620e9 | 2009-05-22 11:58:36 +0300 | [diff] [blame] | 2498 | .early_init = bcm4320b_early_init, |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2499 | .link_change = rndis_wext_link_change, |
| 2500 | }; |
| 2501 | |
| 2502 | static const struct driver_info bcm4320a_info = { |
| 2503 | .description = "Wireless RNDIS device, BCM4320a based", |
| 2504 | .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT, |
| 2505 | .bind = rndis_wext_bind, |
| 2506 | .unbind = rndis_wext_unbind, |
| 2507 | .status = rndis_status, |
| 2508 | .rx_fixup = rndis_rx_fixup, |
| 2509 | .tx_fixup = rndis_tx_fixup, |
| 2510 | .reset = rndis_wext_reset, |
Jussi Kivilinna | 59620e9 | 2009-05-22 11:58:36 +0300 | [diff] [blame] | 2511 | .early_init = bcm4320a_early_init, |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2512 | .link_change = rndis_wext_link_change, |
| 2513 | }; |
| 2514 | |
| 2515 | static const struct driver_info rndis_wext_info = { |
| 2516 | .description = "Wireless RNDIS device", |
| 2517 | .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT, |
| 2518 | .bind = rndis_wext_bind, |
| 2519 | .unbind = rndis_wext_unbind, |
| 2520 | .status = rndis_status, |
| 2521 | .rx_fixup = rndis_rx_fixup, |
| 2522 | .tx_fixup = rndis_tx_fixup, |
| 2523 | .reset = rndis_wext_reset, |
Jussi Kivilinna | 59620e9 | 2009-05-22 11:58:36 +0300 | [diff] [blame] | 2524 | .early_init = bcm4320a_early_init, |
Jussi Kivilinna | bf164cc | 2008-01-26 00:51:51 +0200 | [diff] [blame] | 2525 | .link_change = rndis_wext_link_change, |
| 2526 | }; |
| 2527 | |
| 2528 | /*-------------------------------------------------------------------------*/ |
| 2529 | |
| 2530 | static const struct usb_device_id products [] = { |
| 2531 | #define RNDIS_MASTER_INTERFACE \ |
| 2532 | .bInterfaceClass = USB_CLASS_COMM, \ |
| 2533 | .bInterfaceSubClass = 2 /* ACM */, \ |
| 2534 | .bInterfaceProtocol = 0x0ff |
| 2535 | |
| 2536 | /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom |
| 2537 | * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki. |
| 2538 | */ |
| 2539 | { |
| 2540 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2541 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2542 | .idVendor = 0x0411, |
| 2543 | .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */ |
| 2544 | RNDIS_MASTER_INTERFACE, |
| 2545 | .driver_info = (unsigned long) &bcm4320b_info, |
| 2546 | }, { |
| 2547 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2548 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2549 | .idVendor = 0x0baf, |
| 2550 | .idProduct = 0x011b, /* U.S. Robotics USR5421 */ |
| 2551 | RNDIS_MASTER_INTERFACE, |
| 2552 | .driver_info = (unsigned long) &bcm4320b_info, |
| 2553 | }, { |
| 2554 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2555 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2556 | .idVendor = 0x050d, |
| 2557 | .idProduct = 0x011b, /* Belkin F5D7051 */ |
| 2558 | RNDIS_MASTER_INTERFACE, |
| 2559 | .driver_info = (unsigned long) &bcm4320b_info, |
| 2560 | }, { |
| 2561 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2562 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2563 | .idVendor = 0x1799, /* Belkin has two vendor ids */ |
| 2564 | .idProduct = 0x011b, /* Belkin F5D7051 */ |
| 2565 | RNDIS_MASTER_INTERFACE, |
| 2566 | .driver_info = (unsigned long) &bcm4320b_info, |
| 2567 | }, { |
| 2568 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2569 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2570 | .idVendor = 0x13b1, |
| 2571 | .idProduct = 0x0014, /* Linksys WUSB54GSv2 */ |
| 2572 | RNDIS_MASTER_INTERFACE, |
| 2573 | .driver_info = (unsigned long) &bcm4320b_info, |
| 2574 | }, { |
| 2575 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2576 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2577 | .idVendor = 0x13b1, |
| 2578 | .idProduct = 0x0026, /* Linksys WUSB54GSC */ |
| 2579 | RNDIS_MASTER_INTERFACE, |
| 2580 | .driver_info = (unsigned long) &bcm4320b_info, |
| 2581 | }, { |
| 2582 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2583 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2584 | .idVendor = 0x0b05, |
| 2585 | .idProduct = 0x1717, /* Asus WL169gE */ |
| 2586 | RNDIS_MASTER_INTERFACE, |
| 2587 | .driver_info = (unsigned long) &bcm4320b_info, |
| 2588 | }, { |
| 2589 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2590 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2591 | .idVendor = 0x0a5c, |
| 2592 | .idProduct = 0xd11b, /* Eminent EM4045 */ |
| 2593 | RNDIS_MASTER_INTERFACE, |
| 2594 | .driver_info = (unsigned long) &bcm4320b_info, |
| 2595 | }, { |
| 2596 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2597 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2598 | .idVendor = 0x1690, |
| 2599 | .idProduct = 0x0715, /* BT Voyager 1055 */ |
| 2600 | RNDIS_MASTER_INTERFACE, |
| 2601 | .driver_info = (unsigned long) &bcm4320b_info, |
| 2602 | }, |
| 2603 | /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom |
| 2604 | * parameters available, hardware probably contain older firmware version with |
| 2605 | * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki. |
| 2606 | */ |
| 2607 | { |
| 2608 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2609 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2610 | .idVendor = 0x13b1, |
| 2611 | .idProduct = 0x000e, /* Linksys WUSB54GSv1 */ |
| 2612 | RNDIS_MASTER_INTERFACE, |
| 2613 | .driver_info = (unsigned long) &bcm4320a_info, |
| 2614 | }, { |
| 2615 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2616 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2617 | .idVendor = 0x0baf, |
| 2618 | .idProduct = 0x0111, /* U.S. Robotics USR5420 */ |
| 2619 | RNDIS_MASTER_INTERFACE, |
| 2620 | .driver_info = (unsigned long) &bcm4320a_info, |
| 2621 | }, { |
| 2622 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 2623 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 2624 | .idVendor = 0x0411, |
| 2625 | .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */ |
| 2626 | RNDIS_MASTER_INTERFACE, |
| 2627 | .driver_info = (unsigned long) &bcm4320a_info, |
| 2628 | }, |
| 2629 | /* Generic Wireless RNDIS devices that we don't have exact |
| 2630 | * idVendor/idProduct/chip yet. |
| 2631 | */ |
| 2632 | { |
| 2633 | /* RNDIS is MSFT's un-official variant of CDC ACM */ |
| 2634 | USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff), |
| 2635 | .driver_info = (unsigned long) &rndis_wext_info, |
| 2636 | }, { |
| 2637 | /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */ |
| 2638 | USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1), |
| 2639 | .driver_info = (unsigned long) &rndis_wext_info, |
| 2640 | }, |
| 2641 | { }, // END |
| 2642 | }; |
| 2643 | MODULE_DEVICE_TABLE(usb, products); |
| 2644 | |
| 2645 | static struct usb_driver rndis_wlan_driver = { |
| 2646 | .name = "rndis_wlan", |
| 2647 | .id_table = products, |
| 2648 | .probe = usbnet_probe, |
| 2649 | .disconnect = usbnet_disconnect, |
| 2650 | .suspend = usbnet_suspend, |
| 2651 | .resume = usbnet_resume, |
| 2652 | }; |
| 2653 | |
| 2654 | static int __init rndis_wlan_init(void) |
| 2655 | { |
| 2656 | return usb_register(&rndis_wlan_driver); |
| 2657 | } |
| 2658 | module_init(rndis_wlan_init); |
| 2659 | |
| 2660 | static void __exit rndis_wlan_exit(void) |
| 2661 | { |
| 2662 | usb_deregister(&rndis_wlan_driver); |
| 2663 | } |
| 2664 | module_exit(rndis_wlan_exit); |
| 2665 | |
| 2666 | MODULE_AUTHOR("Bjorge Dijkstra"); |
| 2667 | MODULE_AUTHOR("Jussi Kivilinna"); |
| 2668 | MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters"); |
| 2669 | MODULE_LICENSE("GPL"); |
| 2670 | |