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