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