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