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