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