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