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