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