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