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