1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for RNDIS based wireless USB devices.
5 * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
6 * Copyright (C) 2008-2009 by Jussi Kivilinna <jussi.kivilinna@iki.fi>
8 * Portions of this file are based on NDISwrapper project,
9 * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
10 * http://ndiswrapper.sourceforge.net/
13 // #define DEBUG // error path messages, extra info
14 // #define VERBOSE // more; success messages
16 #include <linux/module.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/ethtool.h>
20 #include <linux/workqueue.h>
21 #include <linux/mutex.h>
22 #include <linux/mii.h>
23 #include <linux/usb.h>
24 #include <linux/usb/cdc.h>
25 #include <linux/ieee80211.h>
26 #include <linux/if_arp.h>
27 #include <linux/ctype.h>
28 #include <linux/spinlock.h>
29 #include <linux/slab.h>
30 #include <net/cfg80211.h>
31 #include <linux/usb/usbnet.h>
32 #include <linux/usb/rndis_host.h>
35 /* NOTE: All these are settings for Broadcom chipset */
36 static char modparam_country
[4] = "EU";
37 module_param_string(country
, modparam_country
, 4, 0444);
38 MODULE_PARM_DESC(country
, "Country code (ISO 3166-1 alpha-2), default: EU");
40 static int modparam_frameburst
= 1;
41 module_param_named(frameburst
, modparam_frameburst
, int, 0444);
42 MODULE_PARM_DESC(frameburst
, "enable frame bursting (default: on)");
44 static int modparam_afterburner
= 0;
45 module_param_named(afterburner
, modparam_afterburner
, int, 0444);
46 MODULE_PARM_DESC(afterburner
,
47 "enable afterburner aka '125 High Speed Mode' (default: off)");
49 static int modparam_power_save
= 0;
50 module_param_named(power_save
, modparam_power_save
, int, 0444);
51 MODULE_PARM_DESC(power_save
,
52 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
54 static int modparam_power_output
= 3;
55 module_param_named(power_output
, modparam_power_output
, int, 0444);
56 MODULE_PARM_DESC(power_output
,
57 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
59 static int modparam_roamtrigger
= -70;
60 module_param_named(roamtrigger
, modparam_roamtrigger
, int, 0444);
61 MODULE_PARM_DESC(roamtrigger
,
62 "set roaming dBm trigger: -80=optimize for distance, "
63 "-60=bandwidth (default: -70)");
65 static int modparam_roamdelta
= 1;
66 module_param_named(roamdelta
, modparam_roamdelta
, int, 0444);
67 MODULE_PARM_DESC(roamdelta
,
68 "set roaming tendency: 0=aggressive, 1=moderate, "
69 "2=conservative (default: moderate)");
71 static int modparam_workaround_interval
;
72 module_param_named(workaround_interval
, modparam_workaround_interval
,
74 MODULE_PARM_DESC(workaround_interval
,
75 "set stall workaround interval in msecs (0=disabled) (default: 0)");
77 /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
78 #define WL_NOISE -96 /* typical noise level in dBm */
79 #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
82 /* Assume that Broadcom 4320 (only chipset at time of writing known to be
83 * based on wireless rndis) has default txpower of 13dBm.
84 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
85 * 100% : 20 mW ~ 13dBm
90 #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
91 #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
92 #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
93 #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
95 /* Known device types */
96 #define RNDIS_UNKNOWN 0
97 #define RNDIS_BCM4320A 1
98 #define RNDIS_BCM4320B 2
101 /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
102 * slightly modified for datatype endianess, etc
104 #define NDIS_802_11_LENGTH_SSID 32
105 #define NDIS_802_11_LENGTH_RATES 8
106 #define NDIS_802_11_LENGTH_RATES_EX 16
108 enum ndis_80211_net_type
{
109 NDIS_80211_TYPE_FREQ_HOP
,
110 NDIS_80211_TYPE_DIRECT_SEQ
,
111 NDIS_80211_TYPE_OFDM_A
,
112 NDIS_80211_TYPE_OFDM_G
115 enum ndis_80211_net_infra
{
116 NDIS_80211_INFRA_ADHOC
,
117 NDIS_80211_INFRA_INFRA
,
118 NDIS_80211_INFRA_AUTO_UNKNOWN
121 enum ndis_80211_auth_mode
{
122 NDIS_80211_AUTH_OPEN
,
123 NDIS_80211_AUTH_SHARED
,
124 NDIS_80211_AUTH_AUTO_SWITCH
,
126 NDIS_80211_AUTH_WPA_PSK
,
127 NDIS_80211_AUTH_WPA_NONE
,
128 NDIS_80211_AUTH_WPA2
,
129 NDIS_80211_AUTH_WPA2_PSK
132 enum ndis_80211_encr_status
{
133 NDIS_80211_ENCR_WEP_ENABLED
,
134 NDIS_80211_ENCR_DISABLED
,
135 NDIS_80211_ENCR_WEP_KEY_ABSENT
,
136 NDIS_80211_ENCR_NOT_SUPPORTED
,
137 NDIS_80211_ENCR_TKIP_ENABLED
,
138 NDIS_80211_ENCR_TKIP_KEY_ABSENT
,
139 NDIS_80211_ENCR_CCMP_ENABLED
,
140 NDIS_80211_ENCR_CCMP_KEY_ABSENT
143 enum ndis_80211_priv_filter
{
144 NDIS_80211_PRIV_ACCEPT_ALL
,
145 NDIS_80211_PRIV_8021X_WEP
148 enum ndis_80211_status_type
{
149 NDIS_80211_STATUSTYPE_AUTHENTICATION
,
150 NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
,
151 NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
,
152 NDIS_80211_STATUSTYPE_RADIOSTATE
,
155 enum ndis_80211_media_stream_mode
{
156 NDIS_80211_MEDIA_STREAM_OFF
,
157 NDIS_80211_MEDIA_STREAM_ON
160 enum ndis_80211_radio_status
{
161 NDIS_80211_RADIO_STATUS_ON
,
162 NDIS_80211_RADIO_STATUS_HARDWARE_OFF
,
163 NDIS_80211_RADIO_STATUS_SOFTWARE_OFF
,
166 enum ndis_80211_addkey_bits
{
167 NDIS_80211_ADDKEY_8021X_AUTH
= cpu_to_le32(1 << 28),
168 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
= cpu_to_le32(1 << 29),
169 NDIS_80211_ADDKEY_PAIRWISE_KEY
= cpu_to_le32(1 << 30),
170 NDIS_80211_ADDKEY_TRANSMIT_KEY
= cpu_to_le32(1 << 31)
173 enum ndis_80211_addwep_bits
{
174 NDIS_80211_ADDWEP_PERCLIENT_KEY
= cpu_to_le32(1 << 30),
175 NDIS_80211_ADDWEP_TRANSMIT_KEY
= cpu_to_le32(1 << 31)
178 enum ndis_80211_power_mode
{
179 NDIS_80211_POWER_MODE_CAM
,
180 NDIS_80211_POWER_MODE_MAX_PSP
,
181 NDIS_80211_POWER_MODE_FAST_PSP
,
184 enum ndis_80211_pmkid_cand_list_flag_bits
{
185 NDIS_80211_PMKID_CAND_PREAUTH
= cpu_to_le32(1 << 0)
188 struct ndis_80211_auth_request
{
195 struct ndis_80211_pmkid_candidate
{
201 struct ndis_80211_pmkid_cand_list
{
203 __le32 num_candidates
;
204 struct ndis_80211_pmkid_candidate candidate_list
[0];
207 struct ndis_80211_status_indication
{
210 __le32 media_stream_mode
;
212 struct ndis_80211_auth_request auth_request
[0];
213 struct ndis_80211_pmkid_cand_list cand_list
;
217 struct ndis_80211_ssid
{
219 u8 essid
[NDIS_802_11_LENGTH_SSID
];
222 struct ndis_80211_conf_freq_hop
{
229 struct ndis_80211_conf
{
231 __le32 beacon_period
;
234 struct ndis_80211_conf_freq_hop fh_config
;
237 struct ndis_80211_bssid_ex
{
241 struct ndis_80211_ssid ssid
;
245 struct ndis_80211_conf config
;
247 u8 rates
[NDIS_802_11_LENGTH_RATES_EX
];
252 struct ndis_80211_bssid_list_ex
{
254 struct ndis_80211_bssid_ex bssid
[0];
257 struct ndis_80211_fixed_ies
{
259 __le16 beacon_interval
;
263 struct ndis_80211_wep_key
{
270 struct ndis_80211_key
{
280 struct ndis_80211_remove_key
{
287 struct ndis_config_param
{
295 struct ndis_80211_assoc_info
{
300 __le16 listen_interval
;
301 u8 cur_ap_address
[ETH_ALEN
];
303 __le32 req_ie_length
;
304 __le32 offset_req_ies
;
311 __le32 resp_ie_length
;
312 __le32 offset_resp_ies
;
315 struct ndis_80211_auth_encr_pair
{
320 struct ndis_80211_capability
{
324 __le32 num_auth_encr_pair
;
325 struct ndis_80211_auth_encr_pair auth_encr_pair
[0];
328 struct ndis_80211_bssid_info
{
333 struct ndis_80211_pmkid
{
335 __le32 bssid_info_count
;
336 struct ndis_80211_bssid_info bssid_info
[0];
342 #define CAP_MODE_80211A 1
343 #define CAP_MODE_80211B 2
344 #define CAP_MODE_80211G 4
345 #define CAP_MODE_MASK 7
347 #define WORK_LINK_UP 0
348 #define WORK_LINK_DOWN 1
349 #define WORK_SET_MULTICAST_LIST 2
351 #define RNDIS_WLAN_ALG_NONE 0
352 #define RNDIS_WLAN_ALG_WEP (1<<0)
353 #define RNDIS_WLAN_ALG_TKIP (1<<1)
354 #define RNDIS_WLAN_ALG_CCMP (1<<2)
356 #define RNDIS_WLAN_NUM_KEYS 4
357 #define RNDIS_WLAN_KEY_MGMT_NONE 0
358 #define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
359 #define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
361 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
363 static const struct ieee80211_channel rndis_channels
[] = {
364 { .center_freq
= 2412 },
365 { .center_freq
= 2417 },
366 { .center_freq
= 2422 },
367 { .center_freq
= 2427 },
368 { .center_freq
= 2432 },
369 { .center_freq
= 2437 },
370 { .center_freq
= 2442 },
371 { .center_freq
= 2447 },
372 { .center_freq
= 2452 },
373 { .center_freq
= 2457 },
374 { .center_freq
= 2462 },
375 { .center_freq
= 2467 },
376 { .center_freq
= 2472 },
377 { .center_freq
= 2484 },
380 static const struct ieee80211_rate rndis_rates
[] = {
382 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
383 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
384 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
395 static const u32 rndis_cipher_suites
[] = {
396 WLAN_CIPHER_SUITE_WEP40
,
397 WLAN_CIPHER_SUITE_WEP104
,
398 WLAN_CIPHER_SUITE_TKIP
,
399 WLAN_CIPHER_SUITE_CCMP
,
402 struct rndis_wlan_encr_key
{
411 /* RNDIS device private data */
412 struct rndis_wlan_private
{
413 struct usbnet
*usbdev
;
415 struct wireless_dev wdev
;
417 struct cfg80211_scan_request
*scan_request
;
419 struct workqueue_struct
*workqueue
;
420 struct delayed_work dev_poller_work
;
421 struct delayed_work scan_work
;
422 struct work_struct work
;
423 struct mutex command_lock
;
424 unsigned long work_pending
;
428 int last_cqm_event_rssi
;
430 struct ieee80211_supported_band band
;
431 struct ieee80211_channel channels
[ARRAY_SIZE(rndis_channels
)];
432 struct ieee80211_rate rates
[ARRAY_SIZE(rndis_rates
)];
433 u32 cipher_suites
[ARRAY_SIZE(rndis_cipher_suites
)];
439 /* module parameters */
440 char param_country
[4];
441 int param_frameburst
;
442 int param_afterburner
;
443 int param_power_save
;
444 int param_power_output
;
445 int param_roamtrigger
;
447 u32 param_workaround_interval
;
455 u32 current_command_oid
;
457 /* encryption stuff */
458 u8 encr_tx_key_index
;
459 struct rndis_wlan_encr_key encr_keys
[RNDIS_WLAN_NUM_KEYS
];
462 u8 command_buffer
[COMMAND_BUFFER_SIZE
];
468 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
469 struct net_device
*dev
,
470 enum nl80211_iftype type
,
471 struct vif_params
*params
);
473 static int rndis_scan(struct wiphy
*wiphy
,
474 struct cfg80211_scan_request
*request
);
476 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
);
478 static int rndis_set_tx_power(struct wiphy
*wiphy
,
479 struct wireless_dev
*wdev
,
480 enum nl80211_tx_power_setting type
,
482 static int rndis_get_tx_power(struct wiphy
*wiphy
,
483 struct wireless_dev
*wdev
,
486 static int rndis_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
487 struct cfg80211_connect_params
*sme
);
489 static int rndis_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
492 static int rndis_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
493 struct cfg80211_ibss_params
*params
);
495 static int rndis_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
);
497 static int rndis_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
498 u8 key_index
, bool pairwise
, const u8
*mac_addr
,
499 struct key_params
*params
);
501 static int rndis_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
502 u8 key_index
, bool pairwise
, const u8
*mac_addr
);
504 static int rndis_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
505 u8 key_index
, bool unicast
, bool multicast
);
507 static int rndis_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
508 const u8
*mac
, struct station_info
*sinfo
);
510 static int rndis_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
511 int idx
, u8
*mac
, struct station_info
*sinfo
);
513 static int rndis_set_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
514 struct cfg80211_pmksa
*pmksa
);
516 static int rndis_del_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
517 struct cfg80211_pmksa
*pmksa
);
519 static int rndis_flush_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
);
521 static int rndis_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
522 bool enabled
, int timeout
);
524 static int rndis_set_cqm_rssi_config(struct wiphy
*wiphy
,
525 struct net_device
*dev
,
526 s32 rssi_thold
, u32 rssi_hyst
);
528 static const struct cfg80211_ops rndis_config_ops
= {
529 .change_virtual_intf
= rndis_change_virtual_intf
,
531 .set_wiphy_params
= rndis_set_wiphy_params
,
532 .set_tx_power
= rndis_set_tx_power
,
533 .get_tx_power
= rndis_get_tx_power
,
534 .connect
= rndis_connect
,
535 .disconnect
= rndis_disconnect
,
536 .join_ibss
= rndis_join_ibss
,
537 .leave_ibss
= rndis_leave_ibss
,
538 .add_key
= rndis_add_key
,
539 .del_key
= rndis_del_key
,
540 .set_default_key
= rndis_set_default_key
,
541 .get_station
= rndis_get_station
,
542 .dump_station
= rndis_dump_station
,
543 .set_pmksa
= rndis_set_pmksa
,
544 .del_pmksa
= rndis_del_pmksa
,
545 .flush_pmksa
= rndis_flush_pmksa
,
546 .set_power_mgmt
= rndis_set_power_mgmt
,
547 .set_cqm_rssi_config
= rndis_set_cqm_rssi_config
,
550 static void *rndis_wiphy_privid
= &rndis_wiphy_privid
;
553 static struct rndis_wlan_private
*get_rndis_wlan_priv(struct usbnet
*dev
)
555 return (struct rndis_wlan_private
*)dev
->driver_priv
;
558 static u32
get_bcm4320_power_dbm(struct rndis_wlan_private
*priv
)
560 switch (priv
->param_power_output
) {
563 return BCM4320_DEFAULT_TXPOWER_DBM_100
;
565 return BCM4320_DEFAULT_TXPOWER_DBM_75
;
567 return BCM4320_DEFAULT_TXPOWER_DBM_50
;
569 return BCM4320_DEFAULT_TXPOWER_DBM_25
;
573 static bool is_wpa_key(struct rndis_wlan_private
*priv
, u8 idx
)
575 int cipher
= priv
->encr_keys
[idx
].cipher
;
577 return (cipher
== WLAN_CIPHER_SUITE_CCMP
||
578 cipher
== WLAN_CIPHER_SUITE_TKIP
);
581 static int rndis_cipher_to_alg(u32 cipher
)
585 return RNDIS_WLAN_ALG_NONE
;
586 case WLAN_CIPHER_SUITE_WEP40
:
587 case WLAN_CIPHER_SUITE_WEP104
:
588 return RNDIS_WLAN_ALG_WEP
;
589 case WLAN_CIPHER_SUITE_TKIP
:
590 return RNDIS_WLAN_ALG_TKIP
;
591 case WLAN_CIPHER_SUITE_CCMP
:
592 return RNDIS_WLAN_ALG_CCMP
;
596 static int rndis_akm_suite_to_key_mgmt(u32 akm_suite
)
600 return RNDIS_WLAN_KEY_MGMT_NONE
;
601 case WLAN_AKM_SUITE_8021X
:
602 return RNDIS_WLAN_KEY_MGMT_802_1X
;
603 case WLAN_AKM_SUITE_PSK
:
604 return RNDIS_WLAN_KEY_MGMT_PSK
;
609 static const char *oid_to_string(u32 oid
)
612 #define OID_STR(oid) case oid: return(#oid)
613 /* from rndis_host.h */
614 OID_STR(RNDIS_OID_802_3_PERMANENT_ADDRESS
);
615 OID_STR(RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE
);
616 OID_STR(RNDIS_OID_GEN_CURRENT_PACKET_FILTER
);
617 OID_STR(RNDIS_OID_GEN_PHYSICAL_MEDIUM
);
619 /* from rndis_wlan.c */
620 OID_STR(RNDIS_OID_GEN_LINK_SPEED
);
621 OID_STR(RNDIS_OID_GEN_RNDIS_CONFIG_PARAMETER
);
623 OID_STR(RNDIS_OID_GEN_XMIT_OK
);
624 OID_STR(RNDIS_OID_GEN_RCV_OK
);
625 OID_STR(RNDIS_OID_GEN_XMIT_ERROR
);
626 OID_STR(RNDIS_OID_GEN_RCV_ERROR
);
627 OID_STR(RNDIS_OID_GEN_RCV_NO_BUFFER
);
629 OID_STR(RNDIS_OID_802_3_CURRENT_ADDRESS
);
630 OID_STR(RNDIS_OID_802_3_MULTICAST_LIST
);
631 OID_STR(RNDIS_OID_802_3_MAXIMUM_LIST_SIZE
);
633 OID_STR(RNDIS_OID_802_11_BSSID
);
634 OID_STR(RNDIS_OID_802_11_SSID
);
635 OID_STR(RNDIS_OID_802_11_INFRASTRUCTURE_MODE
);
636 OID_STR(RNDIS_OID_802_11_ADD_WEP
);
637 OID_STR(RNDIS_OID_802_11_REMOVE_WEP
);
638 OID_STR(RNDIS_OID_802_11_DISASSOCIATE
);
639 OID_STR(RNDIS_OID_802_11_AUTHENTICATION_MODE
);
640 OID_STR(RNDIS_OID_802_11_PRIVACY_FILTER
);
641 OID_STR(RNDIS_OID_802_11_BSSID_LIST_SCAN
);
642 OID_STR(RNDIS_OID_802_11_ENCRYPTION_STATUS
);
643 OID_STR(RNDIS_OID_802_11_ADD_KEY
);
644 OID_STR(RNDIS_OID_802_11_REMOVE_KEY
);
645 OID_STR(RNDIS_OID_802_11_ASSOCIATION_INFORMATION
);
646 OID_STR(RNDIS_OID_802_11_CAPABILITY
);
647 OID_STR(RNDIS_OID_802_11_PMKID
);
648 OID_STR(RNDIS_OID_802_11_NETWORK_TYPES_SUPPORTED
);
649 OID_STR(RNDIS_OID_802_11_NETWORK_TYPE_IN_USE
);
650 OID_STR(RNDIS_OID_802_11_TX_POWER_LEVEL
);
651 OID_STR(RNDIS_OID_802_11_RSSI
);
652 OID_STR(RNDIS_OID_802_11_RSSI_TRIGGER
);
653 OID_STR(RNDIS_OID_802_11_FRAGMENTATION_THRESHOLD
);
654 OID_STR(RNDIS_OID_802_11_RTS_THRESHOLD
);
655 OID_STR(RNDIS_OID_802_11_SUPPORTED_RATES
);
656 OID_STR(RNDIS_OID_802_11_CONFIGURATION
);
657 OID_STR(RNDIS_OID_802_11_POWER_MODE
);
658 OID_STR(RNDIS_OID_802_11_BSSID_LIST
);
665 static const char *oid_to_string(u32 oid
)
671 /* translate error code */
672 static int rndis_error_status(__le32 rndis_status
)
675 switch (le32_to_cpu(rndis_status
)) {
676 case RNDIS_STATUS_SUCCESS
:
679 case RNDIS_STATUS_FAILURE
:
680 case RNDIS_STATUS_INVALID_DATA
:
683 case RNDIS_STATUS_NOT_SUPPORTED
:
686 case RNDIS_STATUS_ADAPTER_NOT_READY
:
687 case RNDIS_STATUS_ADAPTER_NOT_OPEN
:
694 static int rndis_query_oid(struct usbnet
*dev
, u32 oid
, void *data
, int *len
)
696 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
699 struct rndis_msg_hdr
*header
;
700 struct rndis_query
*get
;
701 struct rndis_query_c
*get_c
;
704 int resplen
, respoffs
, copylen
;
706 buflen
= *len
+ sizeof(*u
.get
);
707 if (buflen
< CONTROL_BUFFER_SIZE
)
708 buflen
= CONTROL_BUFFER_SIZE
;
710 if (buflen
> COMMAND_BUFFER_SIZE
) {
711 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
715 u
.buf
= priv
->command_buffer
;
718 mutex_lock(&priv
->command_lock
);
720 memset(u
.get
, 0, sizeof *u
.get
);
721 u
.get
->msg_type
= cpu_to_le32(RNDIS_MSG_QUERY
);
722 u
.get
->msg_len
= cpu_to_le32(sizeof *u
.get
);
723 u
.get
->oid
= cpu_to_le32(oid
);
725 priv
->current_command_oid
= oid
;
726 ret
= rndis_command(dev
, u
.header
, buflen
);
727 priv
->current_command_oid
= 0;
729 netdev_dbg(dev
->net
, "%s(%s): rndis_command() failed, %d (%08x)\n",
730 __func__
, oid_to_string(oid
), ret
,
731 le32_to_cpu(u
.get_c
->status
));
734 resplen
= le32_to_cpu(u
.get_c
->len
);
735 respoffs
= le32_to_cpu(u
.get_c
->offset
) + 8;
737 if (respoffs
> buflen
) {
738 /* Device returned data offset outside buffer, error. */
739 netdev_dbg(dev
->net
, "%s(%s): received invalid "
740 "data offset: %d > %d\n", __func__
,
741 oid_to_string(oid
), respoffs
, buflen
);
747 if ((resplen
+ respoffs
) > buflen
) {
748 /* Device would have returned more data if buffer would
749 * have been big enough. Copy just the bits that we got.
751 copylen
= buflen
- respoffs
;
759 memcpy(data
, u
.buf
+ respoffs
, copylen
);
763 ret
= rndis_error_status(u
.get_c
->status
);
765 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
766 __func__
, oid_to_string(oid
),
767 le32_to_cpu(u
.get_c
->status
), ret
);
771 mutex_unlock(&priv
->command_lock
);
773 if (u
.buf
!= priv
->command_buffer
)
778 static int rndis_set_oid(struct usbnet
*dev
, u32 oid
, const void *data
,
781 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
784 struct rndis_msg_hdr
*header
;
785 struct rndis_set
*set
;
786 struct rndis_set_c
*set_c
;
790 buflen
= len
+ sizeof(*u
.set
);
791 if (buflen
< CONTROL_BUFFER_SIZE
)
792 buflen
= CONTROL_BUFFER_SIZE
;
794 if (buflen
> COMMAND_BUFFER_SIZE
) {
795 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
799 u
.buf
= priv
->command_buffer
;
802 mutex_lock(&priv
->command_lock
);
804 memset(u
.set
, 0, sizeof *u
.set
);
805 u
.set
->msg_type
= cpu_to_le32(RNDIS_MSG_SET
);
806 u
.set
->msg_len
= cpu_to_le32(sizeof(*u
.set
) + len
);
807 u
.set
->oid
= cpu_to_le32(oid
);
808 u
.set
->len
= cpu_to_le32(len
);
809 u
.set
->offset
= cpu_to_le32(sizeof(*u
.set
) - 8);
810 u
.set
->handle
= cpu_to_le32(0);
811 memcpy(u
.buf
+ sizeof(*u
.set
), data
, len
);
813 priv
->current_command_oid
= oid
;
814 ret
= rndis_command(dev
, u
.header
, buflen
);
815 priv
->current_command_oid
= 0;
817 netdev_dbg(dev
->net
, "%s(%s): rndis_command() failed, %d (%08x)\n",
818 __func__
, oid_to_string(oid
), ret
,
819 le32_to_cpu(u
.set_c
->status
));
822 ret
= rndis_error_status(u
.set_c
->status
);
825 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
826 __func__
, oid_to_string(oid
),
827 le32_to_cpu(u
.set_c
->status
), ret
);
830 mutex_unlock(&priv
->command_lock
);
832 if (u
.buf
!= priv
->command_buffer
)
837 static int rndis_reset(struct usbnet
*usbdev
)
839 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
840 struct rndis_reset
*reset
;
843 mutex_lock(&priv
->command_lock
);
845 reset
= (void *)priv
->command_buffer
;
846 memset(reset
, 0, sizeof(*reset
));
847 reset
->msg_type
= cpu_to_le32(RNDIS_MSG_RESET
);
848 reset
->msg_len
= cpu_to_le32(sizeof(*reset
));
849 priv
->current_command_oid
= 0;
850 ret
= rndis_command(usbdev
, (void *)reset
, CONTROL_BUFFER_SIZE
);
852 mutex_unlock(&priv
->command_lock
);
860 * Specs say that we can only set config parameters only soon after device
862 * value_type: 0 = u32, 2 = unicode string
864 static int rndis_set_config_parameter(struct usbnet
*dev
, char *param
,
865 int value_type
, void *value
)
867 struct ndis_config_param
*infobuf
;
868 int value_len
, info_len
, param_len
, ret
, i
;
873 value_len
= sizeof(__le32
);
874 else if (value_type
== 2)
875 value_len
= strlen(value
) * sizeof(__le16
);
879 param_len
= strlen(param
) * sizeof(__le16
);
880 info_len
= sizeof(*infobuf
) + param_len
+ value_len
;
885 infobuf
= kmalloc(info_len
, GFP_KERNEL
);
891 /* extra 12 bytes are for padding (debug output) */
892 memset(infobuf
, 0xCC, info_len
+ 12);
896 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %s\n",
899 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %d\n",
900 param
, *(u32
*)value
);
902 infobuf
->name_offs
= cpu_to_le32(sizeof(*infobuf
));
903 infobuf
->name_length
= cpu_to_le32(param_len
);
904 infobuf
->type
= cpu_to_le32(value_type
);
905 infobuf
->value_offs
= cpu_to_le32(sizeof(*infobuf
) + param_len
);
906 infobuf
->value_length
= cpu_to_le32(value_len
);
908 /* simple string to unicode string conversion */
909 unibuf
= (void *)infobuf
+ sizeof(*infobuf
);
910 for (i
= 0; i
< param_len
/ sizeof(__le16
); i
++)
911 unibuf
[i
] = cpu_to_le16(param
[i
]);
913 if (value_type
== 2) {
914 unibuf
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
915 for (i
= 0; i
< value_len
/ sizeof(__le16
); i
++)
916 unibuf
[i
] = cpu_to_le16(((u8
*)value
)[i
]);
918 dst_value
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
919 *dst_value
= cpu_to_le32(*(u32
*)value
);
923 netdev_dbg(dev
->net
, "info buffer (len: %d)\n", info_len
);
924 for (i
= 0; i
< info_len
; i
+= 12) {
925 u32
*tmp
= (u32
*)((u8
*)infobuf
+ i
);
926 netdev_dbg(dev
->net
, "%08X:%08X:%08X\n",
929 cpu_to_be32(tmp
[2]));
933 ret
= rndis_set_oid(dev
, RNDIS_OID_GEN_RNDIS_CONFIG_PARAMETER
,
936 netdev_dbg(dev
->net
, "setting rndis config parameter failed, %d\n",
943 static int rndis_set_config_parameter_str(struct usbnet
*dev
,
944 char *param
, char *value
)
946 return rndis_set_config_parameter(dev
, param
, 2, value
);
950 * data conversion functions
952 static int level_to_qual(int level
)
954 int qual
= 100 * (level
- WL_NOISE
) / (WL_SIGMAX
- WL_NOISE
);
955 return qual
>= 0 ? (qual
<= 100 ? qual
: 100) : 0;
961 static int set_infra_mode(struct usbnet
*usbdev
, int mode
);
962 static void restore_keys(struct usbnet
*usbdev
);
963 static int rndis_check_bssid_list(struct usbnet
*usbdev
, u8
*match_bssid
,
966 static int rndis_start_bssid_list_scan(struct usbnet
*usbdev
)
970 /* Note: RNDIS_OID_802_11_BSSID_LIST_SCAN clears internal BSS list. */
971 tmp
= cpu_to_le32(1);
972 return rndis_set_oid(usbdev
, RNDIS_OID_802_11_BSSID_LIST_SCAN
, &tmp
,
976 static int set_essid(struct usbnet
*usbdev
, struct ndis_80211_ssid
*ssid
)
978 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
981 ret
= rndis_set_oid(usbdev
, RNDIS_OID_802_11_SSID
,
982 ssid
, sizeof(*ssid
));
984 netdev_warn(usbdev
->net
, "setting SSID failed (%08X)\n", ret
);
988 priv
->radio_on
= true;
989 netdev_dbg(usbdev
->net
, "%s(): radio_on = true\n", __func__
);
995 static int set_bssid(struct usbnet
*usbdev
, const u8
*bssid
)
999 ret
= rndis_set_oid(usbdev
, RNDIS_OID_802_11_BSSID
,
1002 netdev_warn(usbdev
->net
, "setting BSSID[%pM] failed (%08X)\n",
1010 static int clear_bssid(struct usbnet
*usbdev
)
1012 static const u8 broadcast_mac
[ETH_ALEN
] = {
1013 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
1016 return set_bssid(usbdev
, broadcast_mac
);
1019 static int get_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
1024 ret
= rndis_query_oid(usbdev
, RNDIS_OID_802_11_BSSID
,
1028 eth_zero_addr(bssid
);
1033 static int get_association_info(struct usbnet
*usbdev
,
1034 struct ndis_80211_assoc_info
*info
, int len
)
1036 return rndis_query_oid(usbdev
,
1037 RNDIS_OID_802_11_ASSOCIATION_INFORMATION
,
1041 static bool is_associated(struct usbnet
*usbdev
)
1043 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1047 if (!priv
->radio_on
)
1050 ret
= get_bssid(usbdev
, bssid
);
1052 return (ret
== 0 && !is_zero_ether_addr(bssid
));
1055 static int disassociate(struct usbnet
*usbdev
, bool reset_ssid
)
1057 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1058 struct ndis_80211_ssid ssid
;
1061 if (priv
->radio_on
) {
1062 ret
= rndis_set_oid(usbdev
,
1063 RNDIS_OID_802_11_DISASSOCIATE
,
1066 priv
->radio_on
= false;
1067 netdev_dbg(usbdev
->net
, "%s(): radio_on = false\n",
1075 /* disassociate causes radio to be turned off; if reset_ssid
1076 * is given, set random ssid to enable radio */
1078 /* Set device to infrastructure mode so we don't get ad-hoc
1079 * 'media connect' indications with the random ssid.
1081 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1083 ssid
.length
= cpu_to_le32(sizeof(ssid
.essid
));
1084 get_random_bytes(&ssid
.essid
[2], sizeof(ssid
.essid
)-2);
1085 ssid
.essid
[0] = 0x1;
1086 ssid
.essid
[1] = 0xff;
1087 for (i
= 2; i
< sizeof(ssid
.essid
); i
++)
1088 ssid
.essid
[i
] = 0x1 + (ssid
.essid
[i
] * 0xfe / 0xff);
1089 ret
= set_essid(usbdev
, &ssid
);
1094 static int set_auth_mode(struct usbnet
*usbdev
, u32 wpa_version
,
1095 enum nl80211_auth_type auth_type
, int keymgmt
)
1097 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1101 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x authalg=0x%x keymgmt=0x%x\n",
1102 __func__
, wpa_version
, auth_type
, keymgmt
);
1104 if (wpa_version
& NL80211_WPA_VERSION_2
) {
1105 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1106 auth_mode
= NDIS_80211_AUTH_WPA2
;
1108 auth_mode
= NDIS_80211_AUTH_WPA2_PSK
;
1109 } else if (wpa_version
& NL80211_WPA_VERSION_1
) {
1110 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1111 auth_mode
= NDIS_80211_AUTH_WPA
;
1112 else if (keymgmt
& RNDIS_WLAN_KEY_MGMT_PSK
)
1113 auth_mode
= NDIS_80211_AUTH_WPA_PSK
;
1115 auth_mode
= NDIS_80211_AUTH_WPA_NONE
;
1116 } else if (auth_type
== NL80211_AUTHTYPE_SHARED_KEY
)
1117 auth_mode
= NDIS_80211_AUTH_SHARED
;
1118 else if (auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
)
1119 auth_mode
= NDIS_80211_AUTH_OPEN
;
1120 else if (auth_type
== NL80211_AUTHTYPE_AUTOMATIC
)
1121 auth_mode
= NDIS_80211_AUTH_AUTO_SWITCH
;
1125 tmp
= cpu_to_le32(auth_mode
);
1126 ret
= rndis_set_oid(usbdev
,
1127 RNDIS_OID_802_11_AUTHENTICATION_MODE
,
1130 netdev_warn(usbdev
->net
, "setting auth mode failed (%08X)\n",
1135 priv
->wpa_version
= wpa_version
;
1140 static int set_priv_filter(struct usbnet
*usbdev
)
1142 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1145 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x\n",
1146 __func__
, priv
->wpa_version
);
1148 if (priv
->wpa_version
& NL80211_WPA_VERSION_2
||
1149 priv
->wpa_version
& NL80211_WPA_VERSION_1
)
1150 tmp
= cpu_to_le32(NDIS_80211_PRIV_8021X_WEP
);
1152 tmp
= cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL
);
1154 return rndis_set_oid(usbdev
,
1155 RNDIS_OID_802_11_PRIVACY_FILTER
, &tmp
,
1159 static int set_encr_mode(struct usbnet
*usbdev
, int pairwise
, int groupwise
)
1164 netdev_dbg(usbdev
->net
, "%s(): cipher_pair=0x%x cipher_group=0x%x\n",
1165 __func__
, pairwise
, groupwise
);
1167 if (pairwise
& RNDIS_WLAN_ALG_CCMP
)
1168 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1169 else if (pairwise
& RNDIS_WLAN_ALG_TKIP
)
1170 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1171 else if (pairwise
& RNDIS_WLAN_ALG_WEP
)
1172 encr_mode
= NDIS_80211_ENCR_WEP_ENABLED
;
1173 else if (groupwise
& RNDIS_WLAN_ALG_CCMP
)
1174 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1175 else if (groupwise
& RNDIS_WLAN_ALG_TKIP
)
1176 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1178 encr_mode
= NDIS_80211_ENCR_DISABLED
;
1180 tmp
= cpu_to_le32(encr_mode
);
1181 ret
= rndis_set_oid(usbdev
,
1182 RNDIS_OID_802_11_ENCRYPTION_STATUS
, &tmp
,
1185 netdev_warn(usbdev
->net
, "setting encr mode failed (%08X)\n",
1193 static int set_infra_mode(struct usbnet
*usbdev
, int mode
)
1195 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1199 netdev_dbg(usbdev
->net
, "%s(): infra_mode=0x%x\n",
1200 __func__
, priv
->infra_mode
);
1202 tmp
= cpu_to_le32(mode
);
1203 ret
= rndis_set_oid(usbdev
,
1204 RNDIS_OID_802_11_INFRASTRUCTURE_MODE
,
1207 netdev_warn(usbdev
->net
, "setting infra mode failed (%08X)\n",
1212 /* NDIS drivers clear keys when infrastructure mode is
1213 * changed. But Linux tools assume otherwise. So set the
1215 restore_keys(usbdev
);
1217 priv
->infra_mode
= mode
;
1221 static int set_rts_threshold(struct usbnet
*usbdev
, u32 rts_threshold
)
1225 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, rts_threshold
);
1227 if (rts_threshold
== -1 || rts_threshold
> 2347)
1228 rts_threshold
= 2347;
1230 tmp
= cpu_to_le32(rts_threshold
);
1231 return rndis_set_oid(usbdev
,
1232 RNDIS_OID_802_11_RTS_THRESHOLD
,
1236 static int set_frag_threshold(struct usbnet
*usbdev
, u32 frag_threshold
)
1240 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, frag_threshold
);
1242 if (frag_threshold
< 256 || frag_threshold
> 2346)
1243 frag_threshold
= 2346;
1245 tmp
= cpu_to_le32(frag_threshold
);
1246 return rndis_set_oid(usbdev
,
1247 RNDIS_OID_802_11_FRAGMENTATION_THRESHOLD
,
1251 static void set_default_iw_params(struct usbnet
*usbdev
)
1253 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1254 set_auth_mode(usbdev
, 0, NL80211_AUTHTYPE_OPEN_SYSTEM
,
1255 RNDIS_WLAN_KEY_MGMT_NONE
);
1256 set_priv_filter(usbdev
);
1257 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1260 static int deauthenticate(struct usbnet
*usbdev
)
1264 ret
= disassociate(usbdev
, true);
1265 set_default_iw_params(usbdev
);
1269 static int set_channel(struct usbnet
*usbdev
, int channel
)
1271 struct ndis_80211_conf config
;
1272 unsigned int dsconfig
;
1275 netdev_dbg(usbdev
->net
, "%s(%d)\n", __func__
, channel
);
1277 /* this OID is valid only when not associated */
1278 if (is_associated(usbdev
))
1282 ieee80211_channel_to_frequency(channel
, NL80211_BAND_2GHZ
);
1284 len
= sizeof(config
);
1285 ret
= rndis_query_oid(usbdev
,
1286 RNDIS_OID_802_11_CONFIGURATION
,
1289 netdev_dbg(usbdev
->net
, "%s(): querying configuration failed\n",
1294 config
.ds_config
= cpu_to_le32(dsconfig
);
1295 ret
= rndis_set_oid(usbdev
,
1296 RNDIS_OID_802_11_CONFIGURATION
,
1297 &config
, sizeof(config
));
1299 netdev_dbg(usbdev
->net
, "%s(): %d -> %d\n", __func__
, channel
, ret
);
1304 static struct ieee80211_channel
*get_current_channel(struct usbnet
*usbdev
,
1307 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1308 struct ieee80211_channel
*channel
;
1309 struct ndis_80211_conf config
;
1312 /* Get channel and beacon interval */
1313 len
= sizeof(config
);
1314 ret
= rndis_query_oid(usbdev
,
1315 RNDIS_OID_802_11_CONFIGURATION
,
1317 netdev_dbg(usbdev
->net
, "%s(): RNDIS_OID_802_11_CONFIGURATION -> %d\n",
1322 channel
= ieee80211_get_channel(priv
->wdev
.wiphy
,
1323 KHZ_TO_MHZ(le32_to_cpu(config
.ds_config
)));
1328 *beacon_period
= le32_to_cpu(config
.beacon_period
);
1332 /* index must be 0 - N, as per NDIS */
1333 static int add_wep_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1336 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1337 struct ndis_80211_wep_key ndis_key
;
1341 netdev_dbg(usbdev
->net
, "%s(idx: %d, len: %d)\n",
1342 __func__
, index
, key_len
);
1344 if (index
>= RNDIS_WLAN_NUM_KEYS
)
1348 cipher
= WLAN_CIPHER_SUITE_WEP40
;
1349 else if (key_len
== 13)
1350 cipher
= WLAN_CIPHER_SUITE_WEP104
;
1354 memset(&ndis_key
, 0, sizeof(ndis_key
));
1356 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
));
1357 ndis_key
.length
= cpu_to_le32(key_len
);
1358 ndis_key
.index
= cpu_to_le32(index
);
1359 memcpy(&ndis_key
.material
, key
, key_len
);
1361 if (index
== priv
->encr_tx_key_index
) {
1362 ndis_key
.index
|= NDIS_80211_ADDWEP_TRANSMIT_KEY
;
1363 ret
= set_encr_mode(usbdev
, RNDIS_WLAN_ALG_WEP
,
1364 RNDIS_WLAN_ALG_NONE
);
1366 netdev_warn(usbdev
->net
, "encryption couldn't be enabled (%08X)\n",
1370 ret
= rndis_set_oid(usbdev
,
1371 RNDIS_OID_802_11_ADD_WEP
, &ndis_key
,
1374 netdev_warn(usbdev
->net
, "adding encryption key %d failed (%08X)\n",
1379 priv
->encr_keys
[index
].len
= key_len
;
1380 priv
->encr_keys
[index
].cipher
= cipher
;
1381 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1382 eth_broadcast_addr(priv
->encr_keys
[index
].bssid
);
1387 static int add_wpa_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1388 u8 index
, const u8
*addr
, const u8
*rx_seq
,
1389 int seq_len
, u32 cipher
, __le32 flags
)
1391 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1392 struct ndis_80211_key ndis_key
;
1396 if (index
>= RNDIS_WLAN_NUM_KEYS
) {
1397 netdev_dbg(usbdev
->net
, "%s(): index out of range (%i)\n",
1401 if (key_len
> sizeof(ndis_key
.material
) || key_len
< 0) {
1402 netdev_dbg(usbdev
->net
, "%s(): key length out of range (%i)\n",
1406 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
) {
1407 if (!rx_seq
|| seq_len
<= 0) {
1408 netdev_dbg(usbdev
->net
, "%s(): recv seq flag without buffer\n",
1412 if (rx_seq
&& seq_len
> sizeof(ndis_key
.rsc
)) {
1413 netdev_dbg(usbdev
->net
, "%s(): too big recv seq buffer\n", __func__
);
1418 is_addr_ok
= addr
&& !is_zero_ether_addr(addr
) &&
1419 !is_broadcast_ether_addr(addr
);
1420 if ((flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) && !is_addr_ok
) {
1421 netdev_dbg(usbdev
->net
, "%s(): pairwise but bssid invalid (%pM)\n",
1426 netdev_dbg(usbdev
->net
, "%s(%i): flags:%i%i%i\n",
1428 !!(flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
),
1429 !!(flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
),
1430 !!(flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
));
1432 memset(&ndis_key
, 0, sizeof(ndis_key
));
1434 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
) -
1435 sizeof(ndis_key
.material
) + key_len
);
1436 ndis_key
.length
= cpu_to_le32(key_len
);
1437 ndis_key
.index
= cpu_to_le32(index
) | flags
;
1439 if (cipher
== WLAN_CIPHER_SUITE_TKIP
&& key_len
== 32) {
1440 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1441 * different order than NDIS spec, so swap the order here. */
1442 memcpy(ndis_key
.material
, key
, 16);
1443 memcpy(ndis_key
.material
+ 16, key
+ 24, 8);
1444 memcpy(ndis_key
.material
+ 24, key
+ 16, 8);
1446 memcpy(ndis_key
.material
, key
, key_len
);
1448 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
)
1449 memcpy(ndis_key
.rsc
, rx_seq
, seq_len
);
1451 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) {
1453 memcpy(ndis_key
.bssid
, addr
, ETH_ALEN
);
1456 if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
1457 eth_broadcast_addr(ndis_key
.bssid
);
1459 get_bssid(usbdev
, ndis_key
.bssid
);
1462 ret
= rndis_set_oid(usbdev
,
1463 RNDIS_OID_802_11_ADD_KEY
, &ndis_key
,
1464 le32_to_cpu(ndis_key
.size
));
1465 netdev_dbg(usbdev
->net
, "%s(): RNDIS_OID_802_11_ADD_KEY -> %08X\n",
1470 memset(&priv
->encr_keys
[index
], 0, sizeof(priv
->encr_keys
[index
]));
1471 priv
->encr_keys
[index
].len
= key_len
;
1472 priv
->encr_keys
[index
].cipher
= cipher
;
1473 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1474 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
)
1475 memcpy(&priv
->encr_keys
[index
].bssid
, ndis_key
.bssid
, ETH_ALEN
);
1477 eth_broadcast_addr(priv
->encr_keys
[index
].bssid
);
1479 if (flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
)
1480 priv
->encr_tx_key_index
= index
;
1485 static int restore_key(struct usbnet
*usbdev
, u8 key_idx
)
1487 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1488 struct rndis_wlan_encr_key key
;
1490 if (is_wpa_key(priv
, key_idx
))
1493 key
= priv
->encr_keys
[key_idx
];
1495 netdev_dbg(usbdev
->net
, "%s(): %i:%i\n", __func__
, key_idx
, key
.len
);
1500 return add_wep_key(usbdev
, key
.material
, key
.len
, key_idx
);
1503 static void restore_keys(struct usbnet
*usbdev
)
1507 for (i
= 0; i
< 4; i
++)
1508 restore_key(usbdev
, i
);
1511 static void clear_key(struct rndis_wlan_private
*priv
, u8 idx
)
1513 memset(&priv
->encr_keys
[idx
], 0, sizeof(priv
->encr_keys
[idx
]));
1516 /* remove_key is for both wep and wpa */
1517 static int remove_key(struct usbnet
*usbdev
, u8 index
, const u8
*bssid
)
1519 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1520 struct ndis_80211_remove_key remove_key
;
1525 if (index
>= RNDIS_WLAN_NUM_KEYS
)
1528 if (priv
->encr_keys
[index
].len
== 0)
1531 is_wpa
= is_wpa_key(priv
, index
);
1533 netdev_dbg(usbdev
->net
, "%s(): %i:%s:%i\n",
1534 __func__
, index
, is_wpa
? "wpa" : "wep",
1535 priv
->encr_keys
[index
].len
);
1537 clear_key(priv
, index
);
1540 remove_key
.size
= cpu_to_le32(sizeof(remove_key
));
1541 remove_key
.index
= cpu_to_le32(index
);
1544 if (!is_broadcast_ether_addr(bssid
))
1546 NDIS_80211_ADDKEY_PAIRWISE_KEY
;
1547 memcpy(remove_key
.bssid
, bssid
,
1548 sizeof(remove_key
.bssid
));
1550 memset(remove_key
.bssid
, 0xff,
1551 sizeof(remove_key
.bssid
));
1553 ret
= rndis_set_oid(usbdev
,
1554 RNDIS_OID_802_11_REMOVE_KEY
,
1555 &remove_key
, sizeof(remove_key
));
1559 keyindex
= cpu_to_le32(index
);
1560 ret
= rndis_set_oid(usbdev
,
1561 RNDIS_OID_802_11_REMOVE_WEP
,
1562 &keyindex
, sizeof(keyindex
));
1564 netdev_warn(usbdev
->net
,
1565 "removing encryption key %d failed (%08X)\n",
1571 /* if it is transmit key, disable encryption */
1572 if (index
== priv
->encr_tx_key_index
)
1573 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1578 static void set_multicast_list(struct usbnet
*usbdev
)
1580 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1581 struct netdev_hw_addr
*ha
;
1582 __le32 filter
, basefilter
;
1584 char *mc_addrs
= NULL
;
1587 basefilter
= filter
= cpu_to_le32(RNDIS_PACKET_TYPE_DIRECTED
|
1588 RNDIS_PACKET_TYPE_BROADCAST
);
1590 if (usbdev
->net
->flags
& IFF_PROMISC
) {
1591 filter
|= cpu_to_le32(RNDIS_PACKET_TYPE_PROMISCUOUS
|
1592 RNDIS_PACKET_TYPE_ALL_LOCAL
);
1593 } else if (usbdev
->net
->flags
& IFF_ALLMULTI
) {
1594 filter
|= cpu_to_le32(RNDIS_PACKET_TYPE_ALL_MULTICAST
);
1597 if (filter
!= basefilter
)
1601 * mc_list should be accessed holding the lock, so copy addresses to
1602 * local buffer first.
1604 netif_addr_lock_bh(usbdev
->net
);
1605 mc_count
= netdev_mc_count(usbdev
->net
);
1606 if (mc_count
> priv
->multicast_size
) {
1607 filter
|= cpu_to_le32(RNDIS_PACKET_TYPE_ALL_MULTICAST
);
1608 } else if (mc_count
) {
1611 mc_addrs
= kmalloc_array(mc_count
, ETH_ALEN
, GFP_ATOMIC
);
1613 netif_addr_unlock_bh(usbdev
->net
);
1617 netdev_for_each_mc_addr(ha
, usbdev
->net
)
1618 memcpy(mc_addrs
+ i
++ * ETH_ALEN
,
1619 ha
->addr
, ETH_ALEN
);
1621 netif_addr_unlock_bh(usbdev
->net
);
1623 if (filter
!= basefilter
)
1627 ret
= rndis_set_oid(usbdev
,
1628 RNDIS_OID_802_3_MULTICAST_LIST
,
1629 mc_addrs
, mc_count
* ETH_ALEN
);
1632 filter
|= cpu_to_le32(RNDIS_PACKET_TYPE_MULTICAST
);
1634 filter
|= cpu_to_le32(RNDIS_PACKET_TYPE_ALL_MULTICAST
);
1636 netdev_dbg(usbdev
->net
, "RNDIS_OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d\n",
1637 mc_count
, priv
->multicast_size
, ret
);
1641 ret
= rndis_set_oid(usbdev
, RNDIS_OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
1644 netdev_warn(usbdev
->net
, "couldn't set packet filter: %08x\n",
1645 le32_to_cpu(filter
));
1648 netdev_dbg(usbdev
->net
, "RNDIS_OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d\n",
1649 le32_to_cpu(filter
), ret
);
1653 static void debug_print_pmkids(struct usbnet
*usbdev
,
1654 struct ndis_80211_pmkid
*pmkids
,
1655 const char *func_str
)
1657 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1658 int i
, len
, count
, max_pmkids
, entry_len
;
1660 max_pmkids
= priv
->wdev
.wiphy
->max_num_pmkids
;
1661 len
= le32_to_cpu(pmkids
->length
);
1662 count
= le32_to_cpu(pmkids
->bssid_info_count
);
1664 entry_len
= (count
> 0) ? (len
- sizeof(*pmkids
)) / count
: -1;
1666 netdev_dbg(usbdev
->net
, "%s(): %d PMKIDs (data len: %d, entry len: "
1667 "%d)\n", func_str
, count
, len
, entry_len
);
1669 if (count
> max_pmkids
)
1672 for (i
= 0; i
< count
; i
++) {
1673 u32
*tmp
= (u32
*)pmkids
->bssid_info
[i
].pmkid
;
1675 netdev_dbg(usbdev
->net
, "%s(): bssid: %pM, "
1676 "pmkid: %08X:%08X:%08X:%08X\n",
1677 func_str
, pmkids
->bssid_info
[i
].bssid
,
1678 cpu_to_be32(tmp
[0]), cpu_to_be32(tmp
[1]),
1679 cpu_to_be32(tmp
[2]), cpu_to_be32(tmp
[3]));
1683 static void debug_print_pmkids(struct usbnet
*usbdev
,
1684 struct ndis_80211_pmkid
*pmkids
,
1685 const char *func_str
)
1691 static struct ndis_80211_pmkid
*get_device_pmkids(struct usbnet
*usbdev
)
1693 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1694 struct ndis_80211_pmkid
*pmkids
;
1695 int len
, ret
, max_pmkids
;
1697 max_pmkids
= priv
->wdev
.wiphy
->max_num_pmkids
;
1698 len
= struct_size(pmkids
, bssid_info
, max_pmkids
);
1700 pmkids
= kzalloc(len
, GFP_KERNEL
);
1702 return ERR_PTR(-ENOMEM
);
1704 pmkids
->length
= cpu_to_le32(len
);
1705 pmkids
->bssid_info_count
= cpu_to_le32(max_pmkids
);
1707 ret
= rndis_query_oid(usbdev
, RNDIS_OID_802_11_PMKID
,
1710 netdev_dbg(usbdev
->net
, "%s(): RNDIS_OID_802_11_PMKID(%d, %d)"
1711 " -> %d\n", __func__
, len
, max_pmkids
, ret
);
1714 return ERR_PTR(ret
);
1717 if (le32_to_cpu(pmkids
->bssid_info_count
) > max_pmkids
)
1718 pmkids
->bssid_info_count
= cpu_to_le32(max_pmkids
);
1720 debug_print_pmkids(usbdev
, pmkids
, __func__
);
1725 static int set_device_pmkids(struct usbnet
*usbdev
,
1726 struct ndis_80211_pmkid
*pmkids
)
1728 int ret
, len
, num_pmkids
;
1730 num_pmkids
= le32_to_cpu(pmkids
->bssid_info_count
);
1731 len
= struct_size(pmkids
, bssid_info
, num_pmkids
);
1732 pmkids
->length
= cpu_to_le32(len
);
1734 debug_print_pmkids(usbdev
, pmkids
, __func__
);
1736 ret
= rndis_set_oid(usbdev
, RNDIS_OID_802_11_PMKID
, pmkids
,
1737 le32_to_cpu(pmkids
->length
));
1739 netdev_dbg(usbdev
->net
, "%s(): RNDIS_OID_802_11_PMKID(%d, %d) -> %d"
1740 "\n", __func__
, len
, num_pmkids
, ret
);
1747 static struct ndis_80211_pmkid
*remove_pmkid(struct usbnet
*usbdev
,
1748 struct ndis_80211_pmkid
*pmkids
,
1749 struct cfg80211_pmksa
*pmksa
,
1755 count
= le32_to_cpu(pmkids
->bssid_info_count
);
1757 if (count
> max_pmkids
)
1760 for (i
= 0; i
< count
; i
++)
1761 if (ether_addr_equal(pmkids
->bssid_info
[i
].bssid
,
1765 /* pmkid not found */
1767 netdev_dbg(usbdev
->net
, "%s(): bssid not found (%pM)\n",
1768 __func__
, pmksa
->bssid
);
1773 for (; i
+ 1 < count
; i
++)
1774 pmkids
->bssid_info
[i
] = pmkids
->bssid_info
[i
+ 1];
1777 pmkids
->length
= cpu_to_le32(struct_size(pmkids
, bssid_info
, count
));
1778 pmkids
->bssid_info_count
= cpu_to_le32(count
);
1783 return ERR_PTR(err
);
1786 static struct ndis_80211_pmkid
*update_pmkid(struct usbnet
*usbdev
,
1787 struct ndis_80211_pmkid
*pmkids
,
1788 struct cfg80211_pmksa
*pmksa
,
1791 struct ndis_80211_pmkid
*new_pmkids
;
1795 count
= le32_to_cpu(pmkids
->bssid_info_count
);
1797 if (count
> max_pmkids
)
1800 /* update with new pmkid */
1801 for (i
= 0; i
< count
; i
++) {
1802 if (!ether_addr_equal(pmkids
->bssid_info
[i
].bssid
,
1806 memcpy(pmkids
->bssid_info
[i
].pmkid
, pmksa
->pmkid
,
1812 /* out of space, return error */
1813 if (i
== max_pmkids
) {
1814 netdev_dbg(usbdev
->net
, "%s(): out of space\n", __func__
);
1820 newlen
= struct_size(pmkids
, bssid_info
, count
+ 1);
1822 new_pmkids
= krealloc(pmkids
, newlen
, GFP_KERNEL
);
1827 pmkids
= new_pmkids
;
1829 pmkids
->length
= cpu_to_le32(newlen
);
1830 pmkids
->bssid_info_count
= cpu_to_le32(count
+ 1);
1832 memcpy(pmkids
->bssid_info
[count
].bssid
, pmksa
->bssid
, ETH_ALEN
);
1833 memcpy(pmkids
->bssid_info
[count
].pmkid
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
1838 return ERR_PTR(err
);
1844 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
1845 struct net_device
*dev
,
1846 enum nl80211_iftype type
,
1847 struct vif_params
*params
)
1849 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1850 struct usbnet
*usbdev
= priv
->usbdev
;
1854 case NL80211_IFTYPE_ADHOC
:
1855 mode
= NDIS_80211_INFRA_ADHOC
;
1857 case NL80211_IFTYPE_STATION
:
1858 mode
= NDIS_80211_INFRA_INFRA
;
1864 priv
->wdev
.iftype
= type
;
1866 return set_infra_mode(usbdev
, mode
);
1869 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1871 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1872 struct usbnet
*usbdev
= priv
->usbdev
;
1875 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
1876 err
= set_frag_threshold(usbdev
, wiphy
->frag_threshold
);
1881 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
1882 err
= set_rts_threshold(usbdev
, wiphy
->rts_threshold
);
1890 static int rndis_set_tx_power(struct wiphy
*wiphy
,
1891 struct wireless_dev
*wdev
,
1892 enum nl80211_tx_power_setting type
,
1895 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1896 struct usbnet
*usbdev
= priv
->usbdev
;
1898 netdev_dbg(usbdev
->net
, "%s(): type:0x%x mbm:%i\n",
1899 __func__
, type
, mbm
);
1901 if (mbm
< 0 || (mbm
% 100))
1904 /* Device doesn't support changing txpower after initialization, only
1905 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1908 if (type
== NL80211_TX_POWER_AUTOMATIC
||
1909 MBM_TO_DBM(mbm
) == get_bcm4320_power_dbm(priv
)) {
1910 if (!priv
->radio_on
)
1911 disassociate(usbdev
, true); /* turn on radio */
1919 static int rndis_get_tx_power(struct wiphy
*wiphy
,
1920 struct wireless_dev
*wdev
,
1923 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1924 struct usbnet
*usbdev
= priv
->usbdev
;
1926 *dbm
= get_bcm4320_power_dbm(priv
);
1928 netdev_dbg(usbdev
->net
, "%s(): dbm:%i\n", __func__
, *dbm
);
1933 #define SCAN_DELAY_JIFFIES (6 * HZ)
1934 static int rndis_scan(struct wiphy
*wiphy
,
1935 struct cfg80211_scan_request
*request
)
1937 struct net_device
*dev
= request
->wdev
->netdev
;
1938 struct usbnet
*usbdev
= netdev_priv(dev
);
1939 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1941 int delay
= SCAN_DELAY_JIFFIES
;
1943 netdev_dbg(usbdev
->net
, "cfg80211.scan\n");
1945 /* Get current bssid list from device before new scan, as new scan
1946 * clears internal bssid list.
1948 rndis_check_bssid_list(usbdev
, NULL
, NULL
);
1950 if (priv
->scan_request
&& priv
->scan_request
!= request
)
1953 priv
->scan_request
= request
;
1955 ret
= rndis_start_bssid_list_scan(usbdev
);
1957 if (priv
->device_type
== RNDIS_BCM4320A
)
1960 /* Wait before retrieving scan results from device */
1961 queue_delayed_work(priv
->workqueue
, &priv
->scan_work
, delay
);
1967 static bool rndis_bss_info_update(struct usbnet
*usbdev
,
1968 struct ndis_80211_bssid_ex
*bssid
)
1970 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1971 struct ieee80211_channel
*channel
;
1972 struct cfg80211_bss
*bss
;
1976 u16 beacon_interval
;
1977 struct ndis_80211_fixed_ies
*fixed
;
1978 int ie_len
, bssid_len
;
1981 netdev_dbg(usbdev
->net
, " found bssid: '%.32s' [%pM], len: %d\n",
1982 bssid
->ssid
.essid
, bssid
->mac
, le32_to_cpu(bssid
->length
));
1984 /* parse bssid structure */
1985 bssid_len
= le32_to_cpu(bssid
->length
);
1987 if (bssid_len
< sizeof(struct ndis_80211_bssid_ex
) +
1988 sizeof(struct ndis_80211_fixed_ies
))
1991 fixed
= (struct ndis_80211_fixed_ies
*)bssid
->ies
;
1993 ie
= (void *)(bssid
->ies
+ sizeof(struct ndis_80211_fixed_ies
));
1994 ie_len
= min(bssid_len
- (int)sizeof(*bssid
),
1995 (int)le32_to_cpu(bssid
->ie_length
));
1996 ie_len
-= sizeof(struct ndis_80211_fixed_ies
);
2000 /* extract data for cfg80211_inform_bss */
2001 channel
= ieee80211_get_channel(priv
->wdev
.wiphy
,
2002 KHZ_TO_MHZ(le32_to_cpu(bssid
->config
.ds_config
)));
2006 signal
= level_to_qual(le32_to_cpu(bssid
->rssi
));
2007 timestamp
= le64_to_cpu(*(__le64
*)fixed
->timestamp
);
2008 capability
= le16_to_cpu(fixed
->capabilities
);
2009 beacon_interval
= le16_to_cpu(fixed
->beacon_interval
);
2011 bss
= cfg80211_inform_bss(priv
->wdev
.wiphy
, channel
,
2012 CFG80211_BSS_FTYPE_UNKNOWN
, bssid
->mac
,
2013 timestamp
, capability
, beacon_interval
,
2014 ie
, ie_len
, signal
, GFP_KERNEL
);
2015 cfg80211_put_bss(priv
->wdev
.wiphy
, bss
);
2017 return (bss
!= NULL
);
2020 static struct ndis_80211_bssid_ex
*next_bssid_list_item(
2021 struct ndis_80211_bssid_ex
*bssid
,
2022 int *bssid_len
, void *buf
, int len
)
2024 void *buf_end
, *bssid_end
;
2026 buf_end
= (char *)buf
+ len
;
2027 bssid_end
= (char *)bssid
+ *bssid_len
;
2029 if ((int)(buf_end
- bssid_end
) < sizeof(bssid
->length
)) {
2033 bssid
= (void *)((char *)bssid
+ *bssid_len
);
2034 *bssid_len
= le32_to_cpu(bssid
->length
);
2039 static bool check_bssid_list_item(struct ndis_80211_bssid_ex
*bssid
,
2040 int bssid_len
, void *buf
, int len
)
2042 void *buf_end
, *bssid_end
;
2044 if (!bssid
|| bssid_len
<= 0 || bssid_len
> len
)
2047 buf_end
= (char *)buf
+ len
;
2048 bssid_end
= (char *)bssid
+ bssid_len
;
2050 return (int)(buf_end
- bssid_end
) >= 0 && (int)(bssid_end
- buf
) >= 0;
2053 static int rndis_check_bssid_list(struct usbnet
*usbdev
, u8
*match_bssid
,
2057 struct ndis_80211_bssid_list_ex
*bssid_list
;
2058 struct ndis_80211_bssid_ex
*bssid
;
2059 int ret
= -EINVAL
, len
, count
, bssid_len
, real_count
, new_len
;
2061 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
2063 len
= CONTROL_BUFFER_SIZE
;
2065 buf
= kzalloc(len
, GFP_KERNEL
);
2071 /* BSSID-list might have got bigger last time we checked, keep
2072 * resizing until it won't get any bigger.
2075 ret
= rndis_query_oid(usbdev
, RNDIS_OID_802_11_BSSID_LIST
,
2077 if (ret
!= 0 || new_len
< sizeof(struct ndis_80211_bssid_list_ex
))
2080 if (new_len
> len
) {
2089 count
= le32_to_cpu(bssid_list
->num_items
);
2091 netdev_dbg(usbdev
->net
, "%s(): buflen: %d\n", __func__
, len
);
2094 bssid
= next_bssid_list_item(bssid_list
->bssid
, &bssid_len
, buf
, len
);
2096 /* Device returns incorrect 'num_items'. Workaround by ignoring the
2097 * received 'num_items' and walking through full bssid buffer instead.
2099 while (check_bssid_list_item(bssid
, bssid_len
, buf
, len
)) {
2100 if (rndis_bss_info_update(usbdev
, bssid
) && match_bssid
&&
2102 if (ether_addr_equal(bssid
->mac
, match_bssid
))
2107 bssid
= next_bssid_list_item(bssid
, &bssid_len
, buf
, len
);
2110 netdev_dbg(usbdev
->net
, "%s(): num_items from device: %d, really found:"
2111 " %d\n", __func__
, count
, real_count
);
2118 static void rndis_get_scan_results(struct work_struct
*work
)
2120 struct rndis_wlan_private
*priv
=
2121 container_of(work
, struct rndis_wlan_private
, scan_work
.work
);
2122 struct usbnet
*usbdev
= priv
->usbdev
;
2123 struct cfg80211_scan_info info
= {};
2126 netdev_dbg(usbdev
->net
, "get_scan_results\n");
2128 if (!priv
->scan_request
)
2131 ret
= rndis_check_bssid_list(usbdev
, NULL
, NULL
);
2133 info
.aborted
= ret
< 0;
2134 cfg80211_scan_done(priv
->scan_request
, &info
);
2136 priv
->scan_request
= NULL
;
2139 static int rndis_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
2140 struct cfg80211_connect_params
*sme
)
2142 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2143 struct usbnet
*usbdev
= priv
->usbdev
;
2144 struct ieee80211_channel
*channel
= sme
->channel
;
2145 struct ndis_80211_ssid ssid
;
2146 int pairwise
= RNDIS_WLAN_ALG_NONE
;
2147 int groupwise
= RNDIS_WLAN_ALG_NONE
;
2148 int keymgmt
= RNDIS_WLAN_KEY_MGMT_NONE
;
2149 int length
, i
, ret
, chan
= -1;
2152 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
2154 groupwise
= rndis_cipher_to_alg(sme
->crypto
.cipher_group
);
2155 for (i
= 0; i
< sme
->crypto
.n_ciphers_pairwise
; i
++)
2157 rndis_cipher_to_alg(sme
->crypto
.ciphers_pairwise
[i
]);
2159 if (sme
->crypto
.n_ciphers_pairwise
> 0 &&
2160 pairwise
== RNDIS_WLAN_ALG_NONE
) {
2161 netdev_err(usbdev
->net
, "Unsupported pairwise cipher\n");
2165 for (i
= 0; i
< sme
->crypto
.n_akm_suites
; i
++)
2167 rndis_akm_suite_to_key_mgmt(sme
->crypto
.akm_suites
[i
]);
2169 if (sme
->crypto
.n_akm_suites
> 0 &&
2170 keymgmt
== RNDIS_WLAN_KEY_MGMT_NONE
) {
2171 netdev_err(usbdev
->net
, "Invalid keymgmt\n");
2175 netdev_dbg(usbdev
->net
, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:0x%x]:0x%x)\n",
2176 sme
->ssid
, sme
->bssid
, chan
,
2177 sme
->privacy
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
2178 groupwise
, pairwise
, keymgmt
);
2180 if (is_associated(usbdev
))
2181 disassociate(usbdev
, false);
2183 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
2185 netdev_dbg(usbdev
->net
, "connect: set_infra_mode failed, %d\n",
2187 goto err_turn_radio_on
;
2190 ret
= set_auth_mode(usbdev
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
2193 netdev_dbg(usbdev
->net
, "connect: set_auth_mode failed, %d\n",
2195 goto err_turn_radio_on
;
2198 set_priv_filter(usbdev
);
2200 ret
= set_encr_mode(usbdev
, pairwise
, groupwise
);
2202 netdev_dbg(usbdev
->net
, "connect: set_encr_mode failed, %d\n",
2204 goto err_turn_radio_on
;
2208 ret
= set_channel(usbdev
, chan
);
2210 netdev_dbg(usbdev
->net
, "connect: set_channel failed, %d\n",
2212 goto err_turn_radio_on
;
2216 if (sme
->key
&& ((groupwise
| pairwise
) & RNDIS_WLAN_ALG_WEP
)) {
2217 priv
->encr_tx_key_index
= sme
->key_idx
;
2218 ret
= add_wep_key(usbdev
, sme
->key
, sme
->key_len
, sme
->key_idx
);
2220 netdev_dbg(usbdev
->net
, "connect: add_wep_key failed, %d (%d, %d)\n",
2221 ret
, sme
->key_len
, sme
->key_idx
);
2222 goto err_turn_radio_on
;
2226 if (sme
->bssid
&& !is_zero_ether_addr(sme
->bssid
) &&
2227 !is_broadcast_ether_addr(sme
->bssid
)) {
2228 ret
= set_bssid(usbdev
, sme
->bssid
);
2230 netdev_dbg(usbdev
->net
, "connect: set_bssid failed, %d\n",
2232 goto err_turn_radio_on
;
2235 clear_bssid(usbdev
);
2237 length
= sme
->ssid_len
;
2238 if (length
> NDIS_802_11_LENGTH_SSID
)
2239 length
= NDIS_802_11_LENGTH_SSID
;
2241 memset(&ssid
, 0, sizeof(ssid
));
2242 ssid
.length
= cpu_to_le32(length
);
2243 memcpy(ssid
.essid
, sme
->ssid
, length
);
2245 /* Pause and purge rx queue, so we don't pass packets before
2246 * 'media connect'-indication.
2248 usbnet_pause_rx(usbdev
);
2249 usbnet_purge_paused_rxq(usbdev
);
2251 ret
= set_essid(usbdev
, &ssid
);
2253 netdev_dbg(usbdev
->net
, "connect: set_essid failed, %d\n", ret
);
2257 disassociate(usbdev
, true);
2262 static int rndis_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
2265 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2266 struct usbnet
*usbdev
= priv
->usbdev
;
2268 netdev_dbg(usbdev
->net
, "cfg80211.disconnect(%d)\n", reason_code
);
2270 priv
->connected
= false;
2271 eth_zero_addr(priv
->bssid
);
2273 return deauthenticate(usbdev
);
2276 static int rndis_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
2277 struct cfg80211_ibss_params
*params
)
2279 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2280 struct usbnet
*usbdev
= priv
->usbdev
;
2281 struct ieee80211_channel
*channel
= params
->chandef
.chan
;
2282 struct ndis_80211_ssid ssid
;
2283 enum nl80211_auth_type auth_type
;
2284 int ret
, alg
, length
, chan
= -1;
2287 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
2289 /* TODO: How to handle ad-hoc encryption?
2290 * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
2291 * pre-shared for encryption (open/shared/wpa), is key set before
2292 * join_ibss? Which auth_type to use (not in params)? What about WPA?
2294 if (params
->privacy
) {
2295 auth_type
= NL80211_AUTHTYPE_SHARED_KEY
;
2296 alg
= RNDIS_WLAN_ALG_WEP
;
2298 auth_type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
2299 alg
= RNDIS_WLAN_ALG_NONE
;
2302 netdev_dbg(usbdev
->net
, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)\n",
2303 params
->ssid
, params
->bssid
, chan
, params
->privacy
);
2305 if (is_associated(usbdev
))
2306 disassociate(usbdev
, false);
2308 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_ADHOC
);
2310 netdev_dbg(usbdev
->net
, "join_ibss: set_infra_mode failed, %d\n",
2312 goto err_turn_radio_on
;
2315 ret
= set_auth_mode(usbdev
, 0, auth_type
, RNDIS_WLAN_KEY_MGMT_NONE
);
2317 netdev_dbg(usbdev
->net
, "join_ibss: set_auth_mode failed, %d\n",
2319 goto err_turn_radio_on
;
2322 set_priv_filter(usbdev
);
2324 ret
= set_encr_mode(usbdev
, alg
, RNDIS_WLAN_ALG_NONE
);
2326 netdev_dbg(usbdev
->net
, "join_ibss: set_encr_mode failed, %d\n",
2328 goto err_turn_radio_on
;
2332 ret
= set_channel(usbdev
, chan
);
2334 netdev_dbg(usbdev
->net
, "join_ibss: set_channel failed, %d\n",
2336 goto err_turn_radio_on
;
2340 if (params
->bssid
&& !is_zero_ether_addr(params
->bssid
) &&
2341 !is_broadcast_ether_addr(params
->bssid
)) {
2342 ret
= set_bssid(usbdev
, params
->bssid
);
2344 netdev_dbg(usbdev
->net
, "join_ibss: set_bssid failed, %d\n",
2346 goto err_turn_radio_on
;
2349 clear_bssid(usbdev
);
2351 length
= params
->ssid_len
;
2352 if (length
> NDIS_802_11_LENGTH_SSID
)
2353 length
= NDIS_802_11_LENGTH_SSID
;
2355 memset(&ssid
, 0, sizeof(ssid
));
2356 ssid
.length
= cpu_to_le32(length
);
2357 memcpy(ssid
.essid
, params
->ssid
, length
);
2359 /* Don't need to pause rx queue for ad-hoc. */
2360 usbnet_purge_paused_rxq(usbdev
);
2361 usbnet_resume_rx(usbdev
);
2363 ret
= set_essid(usbdev
, &ssid
);
2365 netdev_dbg(usbdev
->net
, "join_ibss: set_essid failed, %d\n",
2370 disassociate(usbdev
, true);
2375 static int rndis_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2377 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2378 struct usbnet
*usbdev
= priv
->usbdev
;
2380 netdev_dbg(usbdev
->net
, "cfg80211.leave_ibss()\n");
2382 priv
->connected
= false;
2383 eth_zero_addr(priv
->bssid
);
2385 return deauthenticate(usbdev
);
2388 static int rndis_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2389 u8 key_index
, bool pairwise
, const u8
*mac_addr
,
2390 struct key_params
*params
)
2392 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2393 struct usbnet
*usbdev
= priv
->usbdev
;
2396 netdev_dbg(usbdev
->net
, "%s(%i, %pM, %08x)\n",
2397 __func__
, key_index
, mac_addr
, params
->cipher
);
2399 switch (params
->cipher
) {
2400 case WLAN_CIPHER_SUITE_WEP40
:
2401 case WLAN_CIPHER_SUITE_WEP104
:
2402 return add_wep_key(usbdev
, params
->key
, params
->key_len
,
2404 case WLAN_CIPHER_SUITE_TKIP
:
2405 case WLAN_CIPHER_SUITE_CCMP
:
2408 if (params
->seq
&& params
->seq_len
> 0)
2409 flags
|= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
;
2411 flags
|= NDIS_80211_ADDKEY_PAIRWISE_KEY
|
2412 NDIS_80211_ADDKEY_TRANSMIT_KEY
;
2414 return add_wpa_key(usbdev
, params
->key
, params
->key_len
,
2415 key_index
, mac_addr
, params
->seq
,
2416 params
->seq_len
, params
->cipher
, flags
);
2418 netdev_dbg(usbdev
->net
, "%s(): unsupported cipher %08x\n",
2419 __func__
, params
->cipher
);
2424 static int rndis_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2425 u8 key_index
, bool pairwise
, const u8
*mac_addr
)
2427 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2428 struct usbnet
*usbdev
= priv
->usbdev
;
2430 netdev_dbg(usbdev
->net
, "%s(%i, %pM)\n", __func__
, key_index
, mac_addr
);
2432 return remove_key(usbdev
, key_index
, mac_addr
);
2435 static int rndis_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2436 u8 key_index
, bool unicast
, bool multicast
)
2438 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2439 struct usbnet
*usbdev
= priv
->usbdev
;
2440 struct rndis_wlan_encr_key key
;
2442 netdev_dbg(usbdev
->net
, "%s(%i)\n", __func__
, key_index
);
2444 if (key_index
>= RNDIS_WLAN_NUM_KEYS
)
2447 priv
->encr_tx_key_index
= key_index
;
2449 if (is_wpa_key(priv
, key_index
))
2452 key
= priv
->encr_keys
[key_index
];
2454 return add_wep_key(usbdev
, key
.material
, key
.len
, key_index
);
2457 static void rndis_fill_station_info(struct usbnet
*usbdev
,
2458 struct station_info
*sinfo
)
2460 __le32 linkspeed
, rssi
;
2463 memset(sinfo
, 0, sizeof(*sinfo
));
2465 len
= sizeof(linkspeed
);
2466 ret
= rndis_query_oid(usbdev
, RNDIS_OID_GEN_LINK_SPEED
, &linkspeed
, &len
);
2468 sinfo
->txrate
.legacy
= le32_to_cpu(linkspeed
) / 1000;
2469 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
2473 ret
= rndis_query_oid(usbdev
, RNDIS_OID_802_11_RSSI
,
2476 sinfo
->signal
= level_to_qual(le32_to_cpu(rssi
));
2477 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_SIGNAL
);
2481 static int rndis_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2482 const u8
*mac
, struct station_info
*sinfo
)
2484 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2485 struct usbnet
*usbdev
= priv
->usbdev
;
2487 if (!ether_addr_equal(priv
->bssid
, mac
))
2490 rndis_fill_station_info(usbdev
, sinfo
);
2495 static int rndis_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2496 int idx
, u8
*mac
, struct station_info
*sinfo
)
2498 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2499 struct usbnet
*usbdev
= priv
->usbdev
;
2504 memcpy(mac
, priv
->bssid
, ETH_ALEN
);
2506 rndis_fill_station_info(usbdev
, sinfo
);
2511 static int rndis_set_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
2512 struct cfg80211_pmksa
*pmksa
)
2514 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2515 struct usbnet
*usbdev
= priv
->usbdev
;
2516 struct ndis_80211_pmkid
*pmkids
;
2517 u32
*tmp
= (u32
*)pmksa
->pmkid
;
2519 netdev_dbg(usbdev
->net
, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__
,
2521 cpu_to_be32(tmp
[0]), cpu_to_be32(tmp
[1]),
2522 cpu_to_be32(tmp
[2]), cpu_to_be32(tmp
[3]));
2524 pmkids
= get_device_pmkids(usbdev
);
2525 if (IS_ERR(pmkids
)) {
2526 /* couldn't read PMKID cache from device */
2527 return PTR_ERR(pmkids
);
2530 pmkids
= update_pmkid(usbdev
, pmkids
, pmksa
, wiphy
->max_num_pmkids
);
2531 if (IS_ERR(pmkids
)) {
2532 /* not found, list full, etc */
2533 return PTR_ERR(pmkids
);
2536 return set_device_pmkids(usbdev
, pmkids
);
2539 static int rndis_del_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
2540 struct cfg80211_pmksa
*pmksa
)
2542 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2543 struct usbnet
*usbdev
= priv
->usbdev
;
2544 struct ndis_80211_pmkid
*pmkids
;
2545 u32
*tmp
= (u32
*)pmksa
->pmkid
;
2547 netdev_dbg(usbdev
->net
, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__
,
2549 cpu_to_be32(tmp
[0]), cpu_to_be32(tmp
[1]),
2550 cpu_to_be32(tmp
[2]), cpu_to_be32(tmp
[3]));
2552 pmkids
= get_device_pmkids(usbdev
);
2553 if (IS_ERR(pmkids
)) {
2554 /* Couldn't read PMKID cache from device */
2555 return PTR_ERR(pmkids
);
2558 pmkids
= remove_pmkid(usbdev
, pmkids
, pmksa
, wiphy
->max_num_pmkids
);
2559 if (IS_ERR(pmkids
)) {
2560 /* not found, etc */
2561 return PTR_ERR(pmkids
);
2564 return set_device_pmkids(usbdev
, pmkids
);
2567 static int rndis_flush_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
)
2569 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2570 struct usbnet
*usbdev
= priv
->usbdev
;
2571 struct ndis_80211_pmkid pmkid
;
2573 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
2575 memset(&pmkid
, 0, sizeof(pmkid
));
2577 pmkid
.length
= cpu_to_le32(sizeof(pmkid
));
2578 pmkid
.bssid_info_count
= cpu_to_le32(0);
2580 return rndis_set_oid(usbdev
, RNDIS_OID_802_11_PMKID
,
2581 &pmkid
, sizeof(pmkid
));
2584 static int rndis_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
2585 bool enabled
, int timeout
)
2587 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2588 struct usbnet
*usbdev
= priv
->usbdev
;
2593 if (priv
->device_type
!= RNDIS_BCM4320B
)
2596 netdev_dbg(usbdev
->net
, "%s(): %s, %d\n", __func__
,
2597 enabled
? "enabled" : "disabled",
2601 power_mode
= NDIS_80211_POWER_MODE_FAST_PSP
;
2603 power_mode
= NDIS_80211_POWER_MODE_CAM
;
2605 if (power_mode
== priv
->power_mode
)
2608 priv
->power_mode
= power_mode
;
2610 mode
= cpu_to_le32(power_mode
);
2611 ret
= rndis_set_oid(usbdev
, RNDIS_OID_802_11_POWER_MODE
,
2612 &mode
, sizeof(mode
));
2614 netdev_dbg(usbdev
->net
, "%s(): RNDIS_OID_802_11_POWER_MODE -> %d\n",
2620 static int rndis_set_cqm_rssi_config(struct wiphy
*wiphy
,
2621 struct net_device
*dev
,
2622 s32 rssi_thold
, u32 rssi_hyst
)
2624 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2626 priv
->cqm_rssi_thold
= rssi_thold
;
2627 priv
->cqm_rssi_hyst
= rssi_hyst
;
2628 priv
->last_cqm_event_rssi
= 0;
2633 static void rndis_wlan_craft_connected_bss(struct usbnet
*usbdev
, u8
*bssid
,
2634 struct ndis_80211_assoc_info
*info
)
2636 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2637 struct ieee80211_channel
*channel
;
2638 struct ndis_80211_ssid ssid
;
2639 struct cfg80211_bss
*bss
;
2643 u32 beacon_period
= 0;
2646 int len
, ret
, ie_len
;
2648 /* Get signal quality, in case of error use rssi=0 and ignore error. */
2651 ret
= rndis_query_oid(usbdev
, RNDIS_OID_802_11_RSSI
,
2653 signal
= level_to_qual(le32_to_cpu(rssi
));
2655 netdev_dbg(usbdev
->net
, "%s(): RNDIS_OID_802_11_RSSI -> %d, "
2656 "rssi:%d, qual: %d\n", __func__
, ret
, le32_to_cpu(rssi
),
2657 level_to_qual(le32_to_cpu(rssi
)));
2659 /* Get AP capabilities */
2661 capability
= le16_to_cpu(info
->resp_ie
.capa
);
2663 /* Set atleast ESS/IBSS capability */
2664 capability
= (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) ?
2665 WLAN_CAPABILITY_ESS
: WLAN_CAPABILITY_IBSS
;
2668 /* Get channel and beacon interval */
2669 channel
= get_current_channel(usbdev
, &beacon_period
);
2671 netdev_warn(usbdev
->net
, "%s(): could not get channel.\n",
2676 /* Get SSID, in case of error, use zero length SSID and ignore error. */
2678 memset(&ssid
, 0, sizeof(ssid
));
2679 ret
= rndis_query_oid(usbdev
, RNDIS_OID_802_11_SSID
,
2681 netdev_dbg(usbdev
->net
, "%s(): RNDIS_OID_802_11_SSID -> %d, len: %d, ssid: "
2682 "'%.32s'\n", __func__
, ret
,
2683 le32_to_cpu(ssid
.length
), ssid
.essid
);
2685 if (le32_to_cpu(ssid
.length
) > 32)
2686 ssid
.length
= cpu_to_le32(32);
2688 ie_buf
[0] = WLAN_EID_SSID
;
2689 ie_buf
[1] = le32_to_cpu(ssid
.length
);
2690 memcpy(&ie_buf
[2], ssid
.essid
, le32_to_cpu(ssid
.length
));
2692 ie_len
= le32_to_cpu(ssid
.length
) + 2;
2697 netdev_dbg(usbdev
->net
, "%s(): channel:%d(freq), bssid:[%pM], tsf:%d, "
2698 "capa:%x, beacon int:%d, resp_ie(len:%d, essid:'%.32s'), "
2699 "signal:%d\n", __func__
, (channel
? channel
->center_freq
: -1),
2700 bssid
, (u32
)timestamp
, capability
, beacon_period
, ie_len
,
2701 ssid
.essid
, signal
);
2703 bss
= cfg80211_inform_bss(priv
->wdev
.wiphy
, channel
,
2704 CFG80211_BSS_FTYPE_UNKNOWN
, bssid
,
2705 timestamp
, capability
, beacon_period
,
2706 ie_buf
, ie_len
, signal
, GFP_KERNEL
);
2707 cfg80211_put_bss(priv
->wdev
.wiphy
, bss
);
2711 * workers, indication handlers, device poller
2713 static void rndis_wlan_do_link_up_work(struct usbnet
*usbdev
)
2715 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2716 struct ndis_80211_assoc_info
*info
= NULL
;
2718 unsigned int resp_ie_len
, req_ie_len
;
2719 unsigned int offset
;
2720 u8
*req_ie
, *resp_ie
;
2722 bool roamed
= false;
2725 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
&& priv
->connected
) {
2726 /* received media connect indication while connected, either
2727 * device reassociated with same AP or roamed to new. */
2736 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2737 info
= kzalloc(CONTROL_BUFFER_SIZE
, GFP_KERNEL
);
2739 /* No memory? Try resume work later */
2740 set_bit(WORK_LINK_UP
, &priv
->work_pending
);
2741 queue_work(priv
->workqueue
, &priv
->work
);
2745 /* Get association info IEs from device. */
2746 ret
= get_association_info(usbdev
, info
, CONTROL_BUFFER_SIZE
);
2748 req_ie_len
= le32_to_cpu(info
->req_ie_length
);
2749 if (req_ie_len
> CONTROL_BUFFER_SIZE
)
2750 req_ie_len
= CONTROL_BUFFER_SIZE
;
2751 if (req_ie_len
!= 0) {
2752 offset
= le32_to_cpu(info
->offset_req_ies
);
2754 if (offset
> CONTROL_BUFFER_SIZE
)
2755 offset
= CONTROL_BUFFER_SIZE
;
2757 req_ie
= (u8
*)info
+ offset
;
2759 if (offset
+ req_ie_len
> CONTROL_BUFFER_SIZE
)
2761 CONTROL_BUFFER_SIZE
- offset
;
2764 resp_ie_len
= le32_to_cpu(info
->resp_ie_length
);
2765 if (resp_ie_len
> CONTROL_BUFFER_SIZE
)
2766 resp_ie_len
= CONTROL_BUFFER_SIZE
;
2767 if (resp_ie_len
!= 0) {
2768 offset
= le32_to_cpu(info
->offset_resp_ies
);
2770 if (offset
> CONTROL_BUFFER_SIZE
)
2771 offset
= CONTROL_BUFFER_SIZE
;
2773 resp_ie
= (u8
*)info
+ offset
;
2775 if (offset
+ resp_ie_len
> CONTROL_BUFFER_SIZE
)
2777 CONTROL_BUFFER_SIZE
- offset
;
2780 /* Since rndis_wlan_craft_connected_bss() might use info
2781 * later and expects info to contain valid data if
2782 * non-null, free info and set NULL here.
2787 } else if (WARN_ON(priv
->infra_mode
!= NDIS_80211_INFRA_ADHOC
))
2790 ret
= get_bssid(usbdev
, bssid
);
2792 memset(bssid
, 0, sizeof(bssid
));
2794 netdev_dbg(usbdev
->net
, "link up work: [%pM]%s\n",
2795 bssid
, roamed
? " roamed" : "");
2797 /* Internal bss list in device should contain at least the currently
2798 * connected bss and we can get it to cfg80211 with
2799 * rndis_check_bssid_list().
2801 * NDIS spec says: "If the device is associated, but the associated
2802 * BSSID is not in its BSSID scan list, then the driver must add an
2803 * entry for the BSSID at the end of the data that it returns in
2804 * response to query of RNDIS_OID_802_11_BSSID_LIST."
2806 * NOTE: Seems to be true for BCM4320b variant, but not BCM4320a.
2809 rndis_check_bssid_list(usbdev
, bssid
, &match_bss
);
2811 if (!is_zero_ether_addr(bssid
) && !match_bss
) {
2812 /* Couldn't get bss from device, we need to manually craft bss
2815 rndis_wlan_craft_connected_bss(usbdev
, bssid
, info
);
2818 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2820 cfg80211_connect_result(usbdev
->net
, bssid
, req_ie
,
2821 req_ie_len
, resp_ie
,
2822 resp_ie_len
, 0, GFP_KERNEL
);
2824 struct cfg80211_roam_info roam_info
= {
2825 .channel
= get_current_channel(usbdev
, NULL
),
2828 .req_ie_len
= req_ie_len
,
2830 .resp_ie_len
= resp_ie_len
,
2833 cfg80211_roamed(usbdev
->net
, &roam_info
, GFP_KERNEL
);
2835 } else if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
2836 cfg80211_ibss_joined(usbdev
->net
, bssid
,
2837 get_current_channel(usbdev
, NULL
),
2842 priv
->connected
= true;
2843 memcpy(priv
->bssid
, bssid
, ETH_ALEN
);
2845 usbnet_resume_rx(usbdev
);
2846 netif_carrier_on(usbdev
->net
);
2849 static void rndis_wlan_do_link_down_work(struct usbnet
*usbdev
)
2851 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2853 if (priv
->connected
) {
2854 priv
->connected
= false;
2855 eth_zero_addr(priv
->bssid
);
2857 deauthenticate(usbdev
);
2859 cfg80211_disconnected(usbdev
->net
, 0, NULL
, 0, true, GFP_KERNEL
);
2862 netif_carrier_off(usbdev
->net
);
2865 static void rndis_wlan_worker(struct work_struct
*work
)
2867 struct rndis_wlan_private
*priv
=
2868 container_of(work
, struct rndis_wlan_private
, work
);
2869 struct usbnet
*usbdev
= priv
->usbdev
;
2871 if (test_and_clear_bit(WORK_LINK_UP
, &priv
->work_pending
))
2872 rndis_wlan_do_link_up_work(usbdev
);
2874 if (test_and_clear_bit(WORK_LINK_DOWN
, &priv
->work_pending
))
2875 rndis_wlan_do_link_down_work(usbdev
);
2877 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2878 set_multicast_list(usbdev
);
2881 static void rndis_wlan_set_multicast_list(struct net_device
*dev
)
2883 struct usbnet
*usbdev
= netdev_priv(dev
);
2884 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2886 if (test_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2889 set_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
);
2890 queue_work(priv
->workqueue
, &priv
->work
);
2893 static void rndis_wlan_auth_indication(struct usbnet
*usbdev
,
2894 struct ndis_80211_status_indication
*indication
,
2899 int flags
, buflen
, key_id
;
2900 bool pairwise_error
, group_error
;
2901 struct ndis_80211_auth_request
*auth_req
;
2902 enum nl80211_key_type key_type
;
2904 /* must have at least one array entry */
2905 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2906 sizeof(struct ndis_80211_auth_request
)) {
2907 netdev_info(usbdev
->net
, "authentication indication: too short message (%i)\n",
2912 buf
= (void *)&indication
->u
.auth_request
[0];
2913 buflen
= len
- offsetof(struct ndis_80211_status_indication
, u
);
2915 while (buflen
>= sizeof(*auth_req
)) {
2916 auth_req
= (void *)buf
;
2917 if (buflen
< le32_to_cpu(auth_req
->length
))
2920 flags
= le32_to_cpu(auth_req
->flags
);
2921 pairwise_error
= false;
2922 group_error
= false;
2925 type
= "reauth request";
2927 type
= "key update request";
2929 pairwise_error
= true;
2930 type
= "pairwise_error";
2934 type
= "group_error";
2937 netdev_info(usbdev
->net
, "authentication indication: %s (0x%08x)\n",
2938 type
, le32_to_cpu(auth_req
->flags
));
2940 if (pairwise_error
) {
2941 key_type
= NL80211_KEYTYPE_PAIRWISE
;
2944 cfg80211_michael_mic_failure(usbdev
->net
,
2946 key_type
, key_id
, NULL
,
2951 key_type
= NL80211_KEYTYPE_GROUP
;
2954 cfg80211_michael_mic_failure(usbdev
->net
,
2956 key_type
, key_id
, NULL
,
2960 buflen
-= le32_to_cpu(auth_req
->length
);
2961 buf
+= le32_to_cpu(auth_req
->length
);
2965 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet
*usbdev
,
2966 struct ndis_80211_status_indication
*indication
,
2969 struct ndis_80211_pmkid_cand_list
*cand_list
;
2970 int list_len
, expected_len
, i
;
2972 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2973 sizeof(struct ndis_80211_pmkid_cand_list
)) {
2974 netdev_info(usbdev
->net
, "pmkid candidate list indication: too short message (%i)\n",
2979 list_len
= le32_to_cpu(indication
->u
.cand_list
.num_candidates
) *
2980 sizeof(struct ndis_80211_pmkid_candidate
);
2981 expected_len
= sizeof(struct ndis_80211_pmkid_cand_list
) + list_len
+
2982 offsetof(struct ndis_80211_status_indication
, u
);
2984 if (len
< expected_len
) {
2985 netdev_info(usbdev
->net
, "pmkid candidate list indication: list larger than buffer (%i < %i)\n",
2990 cand_list
= &indication
->u
.cand_list
;
2992 netdev_info(usbdev
->net
, "pmkid candidate list indication: version %i, candidates %i\n",
2993 le32_to_cpu(cand_list
->version
),
2994 le32_to_cpu(cand_list
->num_candidates
));
2996 if (le32_to_cpu(cand_list
->version
) != 1)
2999 for (i
= 0; i
< le32_to_cpu(cand_list
->num_candidates
); i
++) {
3000 struct ndis_80211_pmkid_candidate
*cand
=
3001 &cand_list
->candidate_list
[i
];
3002 bool preauth
= !!(cand
->flags
& NDIS_80211_PMKID_CAND_PREAUTH
);
3004 netdev_dbg(usbdev
->net
, "cand[%i]: flags: 0x%08x, preauth: %d, bssid: %pM\n",
3005 i
, le32_to_cpu(cand
->flags
), preauth
, cand
->bssid
);
3007 cfg80211_pmksa_candidate_notify(usbdev
->net
, i
, cand
->bssid
,
3008 preauth
, GFP_ATOMIC
);
3012 static void rndis_wlan_media_specific_indication(struct usbnet
*usbdev
,
3013 struct rndis_indicate
*msg
, int buflen
)
3015 struct ndis_80211_status_indication
*indication
;
3016 unsigned int len
, offset
;
3018 offset
= offsetof(struct rndis_indicate
, status
) +
3019 le32_to_cpu(msg
->offset
);
3020 len
= le32_to_cpu(msg
->length
);
3023 netdev_info(usbdev
->net
, "media specific indication, ignore too short message (%i < 8)\n",
3028 if (len
> buflen
|| offset
> buflen
|| offset
+ len
> buflen
) {
3029 netdev_info(usbdev
->net
, "media specific indication, too large to fit to buffer (%i > %i)\n",
3030 offset
+ len
, buflen
);
3034 indication
= (void *)((u8
*)msg
+ offset
);
3036 switch (le32_to_cpu(indication
->status_type
)) {
3037 case NDIS_80211_STATUSTYPE_RADIOSTATE
:
3038 netdev_info(usbdev
->net
, "radio state indication: %i\n",
3039 le32_to_cpu(indication
->u
.radio_status
));
3042 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
:
3043 netdev_info(usbdev
->net
, "media stream mode indication: %i\n",
3044 le32_to_cpu(indication
->u
.media_stream_mode
));
3047 case NDIS_80211_STATUSTYPE_AUTHENTICATION
:
3048 rndis_wlan_auth_indication(usbdev
, indication
, len
);
3051 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
:
3052 rndis_wlan_pmkid_cand_list_indication(usbdev
, indication
, len
);
3056 netdev_info(usbdev
->net
, "media specific indication: unknown status type 0x%08x\n",
3057 le32_to_cpu(indication
->status_type
));
3061 static void rndis_wlan_indication(struct usbnet
*usbdev
, void *ind
, int buflen
)
3063 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3064 struct rndis_indicate
*msg
= ind
;
3066 switch (le32_to_cpu(msg
->status
)) {
3067 case RNDIS_STATUS_MEDIA_CONNECT
:
3068 if (priv
->current_command_oid
== RNDIS_OID_802_11_ADD_KEY
) {
3069 /* RNDIS_OID_802_11_ADD_KEY causes sometimes extra
3070 * "media connect" indications which confuses driver
3071 * and userspace to think that device is
3072 * roaming/reassociating when it isn't.
3074 netdev_dbg(usbdev
->net
, "ignored RNDIS_OID_802_11_ADD_KEY triggered 'media connect'\n");
3078 usbnet_pause_rx(usbdev
);
3080 netdev_info(usbdev
->net
, "media connect\n");
3082 /* queue work to avoid recursive calls into rndis_command */
3083 set_bit(WORK_LINK_UP
, &priv
->work_pending
);
3084 queue_work(priv
->workqueue
, &priv
->work
);
3087 case RNDIS_STATUS_MEDIA_DISCONNECT
:
3088 netdev_info(usbdev
->net
, "media disconnect\n");
3090 /* queue work to avoid recursive calls into rndis_command */
3091 set_bit(WORK_LINK_DOWN
, &priv
->work_pending
);
3092 queue_work(priv
->workqueue
, &priv
->work
);
3095 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION
:
3096 rndis_wlan_media_specific_indication(usbdev
, msg
, buflen
);
3100 netdev_info(usbdev
->net
, "indication: 0x%08x\n",
3101 le32_to_cpu(msg
->status
));
3106 static int rndis_wlan_get_caps(struct usbnet
*usbdev
, struct wiphy
*wiphy
)
3111 } networks_supported
;
3112 struct ndis_80211_capability
*caps
;
3113 u8 caps_buf
[sizeof(*caps
) + sizeof(caps
->auth_encr_pair
) * 16];
3114 int len
, retval
, i
, n
;
3115 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3117 /* determine supported modes */
3118 len
= sizeof(networks_supported
);
3119 retval
= rndis_query_oid(usbdev
,
3120 RNDIS_OID_802_11_NETWORK_TYPES_SUPPORTED
,
3121 &networks_supported
, &len
);
3123 n
= le32_to_cpu(networks_supported
.num_items
);
3126 for (i
= 0; i
< n
; i
++) {
3127 switch (le32_to_cpu(networks_supported
.items
[i
])) {
3128 case NDIS_80211_TYPE_FREQ_HOP
:
3129 case NDIS_80211_TYPE_DIRECT_SEQ
:
3130 priv
->caps
|= CAP_MODE_80211B
;
3132 case NDIS_80211_TYPE_OFDM_A
:
3133 priv
->caps
|= CAP_MODE_80211A
;
3135 case NDIS_80211_TYPE_OFDM_G
:
3136 priv
->caps
|= CAP_MODE_80211G
;
3142 /* get device 802.11 capabilities, number of PMKIDs */
3143 caps
= (struct ndis_80211_capability
*)caps_buf
;
3144 len
= sizeof(caps_buf
);
3145 retval
= rndis_query_oid(usbdev
,
3146 RNDIS_OID_802_11_CAPABILITY
,
3149 netdev_dbg(usbdev
->net
, "RNDIS_OID_802_11_CAPABILITY -> len %d, "
3150 "ver %d, pmkids %d, auth-encr-pairs %d\n",
3151 le32_to_cpu(caps
->length
),
3152 le32_to_cpu(caps
->version
),
3153 le32_to_cpu(caps
->num_pmkids
),
3154 le32_to_cpu(caps
->num_auth_encr_pair
));
3155 wiphy
->max_num_pmkids
= le32_to_cpu(caps
->num_pmkids
);
3157 wiphy
->max_num_pmkids
= 0;
3162 static void rndis_do_cqm(struct usbnet
*usbdev
, s32 rssi
)
3164 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3165 enum nl80211_cqm_rssi_threshold_event event
;
3166 int thold
, hyst
, last_event
;
3168 if (priv
->cqm_rssi_thold
>= 0 || rssi
>= 0)
3170 if (priv
->infra_mode
!= NDIS_80211_INFRA_INFRA
)
3173 last_event
= priv
->last_cqm_event_rssi
;
3174 thold
= priv
->cqm_rssi_thold
;
3175 hyst
= priv
->cqm_rssi_hyst
;
3177 if (rssi
< thold
&& (last_event
== 0 || rssi
< last_event
- hyst
))
3178 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
;
3179 else if (rssi
> thold
&& (last_event
== 0 || rssi
> last_event
+ hyst
))
3180 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
;
3184 priv
->last_cqm_event_rssi
= rssi
;
3185 cfg80211_cqm_rssi_notify(usbdev
->net
, event
, rssi
, GFP_KERNEL
);
3188 #define DEVICE_POLLER_JIFFIES (HZ)
3189 static void rndis_device_poller(struct work_struct
*work
)
3191 struct rndis_wlan_private
*priv
=
3192 container_of(work
, struct rndis_wlan_private
,
3193 dev_poller_work
.work
);
3194 struct usbnet
*usbdev
= priv
->usbdev
;
3197 int update_jiffies
= DEVICE_POLLER_JIFFIES
;
3200 /* Only check/do workaround when connected. Calling is_associated()
3201 * also polls device with rndis_command() and catches for media link
3204 if (!is_associated(usbdev
)) {
3205 /* Workaround bad scanning in BCM4320a devices with active
3206 * background scanning when not associated.
3208 if (priv
->device_type
== RNDIS_BCM4320A
&& priv
->radio_on
&&
3209 !priv
->scan_request
) {
3210 /* Get previous scan results */
3211 rndis_check_bssid_list(usbdev
, NULL
, NULL
);
3213 /* Initiate new scan */
3214 rndis_start_bssid_list_scan(usbdev
);
3221 ret
= rndis_query_oid(usbdev
, RNDIS_OID_802_11_RSSI
,
3224 priv
->last_qual
= level_to_qual(le32_to_cpu(rssi
));
3225 rndis_do_cqm(usbdev
, le32_to_cpu(rssi
));
3228 netdev_dbg(usbdev
->net
, "dev-poller: RNDIS_OID_802_11_RSSI -> %d, rssi:%d, qual: %d\n",
3229 ret
, le32_to_cpu(rssi
), level_to_qual(le32_to_cpu(rssi
)));
3231 /* Workaround transfer stalls on poor quality links.
3232 * TODO: find right way to fix these stalls (as stalls do not happen
3233 * with ndiswrapper/windows driver). */
3234 if (priv
->param_workaround_interval
> 0 && priv
->last_qual
<= 25) {
3235 /* Decrease stats worker interval to catch stalls.
3236 * faster. Faster than 400-500ms causes packet loss,
3237 * Slower doesn't catch stalls fast enough.
3239 j
= msecs_to_jiffies(priv
->param_workaround_interval
);
3240 if (j
> DEVICE_POLLER_JIFFIES
)
3241 j
= DEVICE_POLLER_JIFFIES
;
3246 /* Send scan OID. Use of both OIDs is required to get device
3249 tmp
= cpu_to_le32(1);
3250 rndis_set_oid(usbdev
,
3251 RNDIS_OID_802_11_BSSID_LIST_SCAN
,
3254 len
= CONTROL_BUFFER_SIZE
;
3255 buf
= kmalloc(len
, GFP_KERNEL
);
3259 rndis_query_oid(usbdev
,
3260 RNDIS_OID_802_11_BSSID_LIST
,
3266 if (update_jiffies
>= HZ
)
3267 update_jiffies
= round_jiffies_relative(update_jiffies
);
3269 j
= round_jiffies_relative(update_jiffies
);
3270 if (abs(j
- update_jiffies
) <= 10)
3274 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
3279 * driver/device initialization
3281 static void rndis_copy_module_params(struct usbnet
*usbdev
, int device_type
)
3283 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3285 priv
->device_type
= device_type
;
3287 priv
->param_country
[0] = modparam_country
[0];
3288 priv
->param_country
[1] = modparam_country
[1];
3289 priv
->param_country
[2] = 0;
3290 priv
->param_frameburst
= modparam_frameburst
;
3291 priv
->param_afterburner
= modparam_afterburner
;
3292 priv
->param_power_save
= modparam_power_save
;
3293 priv
->param_power_output
= modparam_power_output
;
3294 priv
->param_roamtrigger
= modparam_roamtrigger
;
3295 priv
->param_roamdelta
= modparam_roamdelta
;
3297 priv
->param_country
[0] = toupper(priv
->param_country
[0]);
3298 priv
->param_country
[1] = toupper(priv
->param_country
[1]);
3299 /* doesn't support EU as country code, use FI instead */
3300 if (!strcmp(priv
->param_country
, "EU"))
3301 strcpy(priv
->param_country
, "FI");
3303 if (priv
->param_power_save
< 0)
3304 priv
->param_power_save
= 0;
3305 else if (priv
->param_power_save
> 2)
3306 priv
->param_power_save
= 2;
3308 if (priv
->param_power_output
< 0)
3309 priv
->param_power_output
= 0;
3310 else if (priv
->param_power_output
> 3)
3311 priv
->param_power_output
= 3;
3313 if (priv
->param_roamtrigger
< -80)
3314 priv
->param_roamtrigger
= -80;
3315 else if (priv
->param_roamtrigger
> -60)
3316 priv
->param_roamtrigger
= -60;
3318 if (priv
->param_roamdelta
< 0)
3319 priv
->param_roamdelta
= 0;
3320 else if (priv
->param_roamdelta
> 2)
3321 priv
->param_roamdelta
= 2;
3323 if (modparam_workaround_interval
< 0)
3324 priv
->param_workaround_interval
= 500;
3326 priv
->param_workaround_interval
= modparam_workaround_interval
;
3329 static int unknown_early_init(struct usbnet
*usbdev
)
3331 /* copy module parameters for unknown so that iwconfig reports txpower
3332 * and workaround parameter is copied to private structure correctly.
3334 rndis_copy_module_params(usbdev
, RNDIS_UNKNOWN
);
3336 /* This is unknown device, so do not try set configuration parameters.
3342 static int bcm4320a_early_init(struct usbnet
*usbdev
)
3344 /* copy module parameters for bcm4320a so that iwconfig reports txpower
3345 * and workaround parameter is copied to private structure correctly.
3347 rndis_copy_module_params(usbdev
, RNDIS_BCM4320A
);
3349 /* bcm4320a doesn't handle configuration parameters well. Try
3350 * set any and you get partially zeroed mac and broken device.
3356 static int bcm4320b_early_init(struct usbnet
*usbdev
)
3358 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3361 rndis_copy_module_params(usbdev
, RNDIS_BCM4320B
);
3363 /* Early initialization settings, setting these won't have effect
3364 * if called after generic_rndis_bind().
3367 rndis_set_config_parameter_str(usbdev
, "Country", priv
->param_country
);
3368 rndis_set_config_parameter_str(usbdev
, "FrameBursting",
3369 priv
->param_frameburst
? "1" : "0");
3370 rndis_set_config_parameter_str(usbdev
, "Afterburner",
3371 priv
->param_afterburner
? "1" : "0");
3372 sprintf(buf
, "%d", priv
->param_power_save
);
3373 rndis_set_config_parameter_str(usbdev
, "PowerSaveMode", buf
);
3374 sprintf(buf
, "%d", priv
->param_power_output
);
3375 rndis_set_config_parameter_str(usbdev
, "PwrOut", buf
);
3376 sprintf(buf
, "%d", priv
->param_roamtrigger
);
3377 rndis_set_config_parameter_str(usbdev
, "RoamTrigger", buf
);
3378 sprintf(buf
, "%d", priv
->param_roamdelta
);
3379 rndis_set_config_parameter_str(usbdev
, "RoamDelta", buf
);
3384 /* same as rndis_netdev_ops but with local multicast handler */
3385 static const struct net_device_ops rndis_wlan_netdev_ops
= {
3386 .ndo_open
= usbnet_open
,
3387 .ndo_stop
= usbnet_stop
,
3388 .ndo_start_xmit
= usbnet_start_xmit
,
3389 .ndo_tx_timeout
= usbnet_tx_timeout
,
3390 .ndo_get_stats64
= usbnet_get_stats64
,
3391 .ndo_set_mac_address
= eth_mac_addr
,
3392 .ndo_validate_addr
= eth_validate_addr
,
3393 .ndo_set_rx_mode
= rndis_wlan_set_multicast_list
,
3396 static int rndis_wlan_bind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
3398 struct wiphy
*wiphy
;
3399 struct rndis_wlan_private
*priv
;
3403 /* allocate wiphy and rndis private data
3404 * NOTE: We only support a single virtual interface, so wiphy
3405 * and wireless_dev are somewhat synonymous for this device.
3407 wiphy
= wiphy_new(&rndis_config_ops
, sizeof(struct rndis_wlan_private
));
3411 priv
= wiphy_priv(wiphy
);
3412 usbdev
->net
->ieee80211_ptr
= &priv
->wdev
;
3413 priv
->wdev
.wiphy
= wiphy
;
3414 priv
->wdev
.iftype
= NL80211_IFTYPE_STATION
;
3416 /* These have to be initialized before calling generic_rndis_bind().
3417 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
3419 usbdev
->driver_priv
= priv
;
3420 priv
->usbdev
= usbdev
;
3422 mutex_init(&priv
->command_lock
);
3424 /* because rndis_command() sleeps we need to use workqueue */
3425 priv
->workqueue
= create_singlethread_workqueue("rndis_wlan");
3426 if (!priv
->workqueue
) {
3430 INIT_WORK(&priv
->work
, rndis_wlan_worker
);
3431 INIT_DELAYED_WORK(&priv
->dev_poller_work
, rndis_device_poller
);
3432 INIT_DELAYED_WORK(&priv
->scan_work
, rndis_get_scan_results
);
3434 /* try bind rndis_host */
3435 retval
= generic_rndis_bind(usbdev
, intf
, FLAG_RNDIS_PHYM_WIRELESS
);
3439 /* generic_rndis_bind set packet filter to multicast_all+
3440 * promisc mode which doesn't work well for our devices (device
3441 * picks up rssi to closest station instead of to access point).
3443 * rndis_host wants to avoid all OID as much as possible
3444 * so do promisc/multicast handling in rndis_wlan.
3446 usbdev
->net
->netdev_ops
= &rndis_wlan_netdev_ops
;
3448 tmp
= cpu_to_le32(RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
);
3449 retval
= rndis_set_oid(usbdev
,
3450 RNDIS_OID_GEN_CURRENT_PACKET_FILTER
,
3454 retval
= rndis_query_oid(usbdev
,
3455 RNDIS_OID_802_3_MAXIMUM_LIST_SIZE
,
3457 priv
->multicast_size
= le32_to_cpu(tmp
);
3458 if (retval
< 0 || priv
->multicast_size
< 0)
3459 priv
->multicast_size
= 0;
3460 if (priv
->multicast_size
> 0)
3461 usbdev
->net
->flags
|= IFF_MULTICAST
;
3463 usbdev
->net
->flags
&= ~IFF_MULTICAST
;
3465 /* fill-out wiphy structure and register w/ cfg80211 */
3466 memcpy(wiphy
->perm_addr
, usbdev
->net
->dev_addr
, ETH_ALEN
);
3467 wiphy
->privid
= rndis_wiphy_privid
;
3468 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
3469 | BIT(NL80211_IFTYPE_ADHOC
);
3470 wiphy
->max_scan_ssids
= 1;
3472 /* TODO: fill-out band/encr information based on priv->caps */
3473 rndis_wlan_get_caps(usbdev
, wiphy
);
3475 memcpy(priv
->channels
, rndis_channels
, sizeof(rndis_channels
));
3476 memcpy(priv
->rates
, rndis_rates
, sizeof(rndis_rates
));
3477 priv
->band
.channels
= priv
->channels
;
3478 priv
->band
.n_channels
= ARRAY_SIZE(rndis_channels
);
3479 priv
->band
.bitrates
= priv
->rates
;
3480 priv
->band
.n_bitrates
= ARRAY_SIZE(rndis_rates
);
3481 wiphy
->bands
[NL80211_BAND_2GHZ
] = &priv
->band
;
3482 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_UNSPEC
;
3484 memcpy(priv
->cipher_suites
, rndis_cipher_suites
,
3485 sizeof(rndis_cipher_suites
));
3486 wiphy
->cipher_suites
= priv
->cipher_suites
;
3487 wiphy
->n_cipher_suites
= ARRAY_SIZE(rndis_cipher_suites
);
3489 set_wiphy_dev(wiphy
, &usbdev
->udev
->dev
);
3491 if (wiphy_register(wiphy
)) {
3496 set_default_iw_params(usbdev
);
3498 priv
->power_mode
= -1;
3500 /* set default rts/frag */
3501 rndis_set_wiphy_params(wiphy
,
3502 WIPHY_PARAM_FRAG_THRESHOLD
| WIPHY_PARAM_RTS_THRESHOLD
);
3504 /* turn radio off on init */
3505 priv
->radio_on
= false;
3506 disassociate(usbdev
, false);
3507 netif_carrier_off(usbdev
->net
);
3512 cancel_delayed_work_sync(&priv
->dev_poller_work
);
3513 cancel_delayed_work_sync(&priv
->scan_work
);
3514 cancel_work_sync(&priv
->work
);
3515 flush_workqueue(priv
->workqueue
);
3516 destroy_workqueue(priv
->workqueue
);
3522 static void rndis_wlan_unbind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
3524 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3526 /* turn radio off */
3527 disassociate(usbdev
, false);
3529 cancel_delayed_work_sync(&priv
->dev_poller_work
);
3530 cancel_delayed_work_sync(&priv
->scan_work
);
3531 cancel_work_sync(&priv
->work
);
3532 flush_workqueue(priv
->workqueue
);
3533 destroy_workqueue(priv
->workqueue
);
3535 rndis_unbind(usbdev
, intf
);
3537 wiphy_unregister(priv
->wdev
.wiphy
);
3538 wiphy_free(priv
->wdev
.wiphy
);
3541 static int rndis_wlan_reset(struct usbnet
*usbdev
)
3543 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3546 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
3548 retval
= rndis_reset(usbdev
);
3550 netdev_warn(usbdev
->net
, "rndis_reset failed: %d\n", retval
);
3552 /* rndis_reset cleared multicast list, so restore here.
3553 (set_multicast_list() also turns on current packet filter) */
3554 set_multicast_list(usbdev
);
3556 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
3557 round_jiffies_relative(DEVICE_POLLER_JIFFIES
));
3559 return deauthenticate(usbdev
);
3562 static int rndis_wlan_stop(struct usbnet
*usbdev
)
3564 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3568 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
3570 retval
= disassociate(usbdev
, false);
3572 priv
->work_pending
= 0;
3573 cancel_delayed_work_sync(&priv
->dev_poller_work
);
3574 cancel_delayed_work_sync(&priv
->scan_work
);
3575 cancel_work_sync(&priv
->work
);
3576 flush_workqueue(priv
->workqueue
);
3578 if (priv
->scan_request
) {
3579 struct cfg80211_scan_info info
= {
3583 cfg80211_scan_done(priv
->scan_request
, &info
);
3584 priv
->scan_request
= NULL
;
3587 /* Set current packet filter zero to block receiving data packets from
3590 rndis_set_oid(usbdev
, RNDIS_OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
3596 static const struct driver_info bcm4320b_info
= {
3597 .description
= "Wireless RNDIS device, BCM4320b based",
3598 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
3599 FLAG_AVOID_UNLINK_URBS
,
3600 .bind
= rndis_wlan_bind
,
3601 .unbind
= rndis_wlan_unbind
,
3602 .status
= rndis_status
,
3603 .rx_fixup
= rndis_rx_fixup
,
3604 .tx_fixup
= rndis_tx_fixup
,
3605 .reset
= rndis_wlan_reset
,
3606 .stop
= rndis_wlan_stop
,
3607 .early_init
= bcm4320b_early_init
,
3608 .indication
= rndis_wlan_indication
,
3611 static const struct driver_info bcm4320a_info
= {
3612 .description
= "Wireless RNDIS device, BCM4320a based",
3613 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
3614 FLAG_AVOID_UNLINK_URBS
,
3615 .bind
= rndis_wlan_bind
,
3616 .unbind
= rndis_wlan_unbind
,
3617 .status
= rndis_status
,
3618 .rx_fixup
= rndis_rx_fixup
,
3619 .tx_fixup
= rndis_tx_fixup
,
3620 .reset
= rndis_wlan_reset
,
3621 .stop
= rndis_wlan_stop
,
3622 .early_init
= bcm4320a_early_init
,
3623 .indication
= rndis_wlan_indication
,
3626 static const struct driver_info rndis_wlan_info
= {
3627 .description
= "Wireless RNDIS device",
3628 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
3629 FLAG_AVOID_UNLINK_URBS
,
3630 .bind
= rndis_wlan_bind
,
3631 .unbind
= rndis_wlan_unbind
,
3632 .status
= rndis_status
,
3633 .rx_fixup
= rndis_rx_fixup
,
3634 .tx_fixup
= rndis_tx_fixup
,
3635 .reset
= rndis_wlan_reset
,
3636 .stop
= rndis_wlan_stop
,
3637 .early_init
= unknown_early_init
,
3638 .indication
= rndis_wlan_indication
,
3641 /*-------------------------------------------------------------------------*/
3643 static const struct usb_device_id products
[] = {
3644 #define RNDIS_MASTER_INTERFACE \
3645 .bInterfaceClass = USB_CLASS_COMM, \
3646 .bInterfaceSubClass = 2 /* ACM */, \
3647 .bInterfaceProtocol = 0x0ff
3649 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
3650 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
3653 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3654 | USB_DEVICE_ID_MATCH_DEVICE
,
3656 .idProduct
= 0x00bc, /* Buffalo WLI-U2-KG125S */
3657 RNDIS_MASTER_INTERFACE
,
3658 .driver_info
= (unsigned long) &bcm4320b_info
,
3660 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3661 | USB_DEVICE_ID_MATCH_DEVICE
,
3663 .idProduct
= 0x011b, /* U.S. Robotics USR5421 */
3664 RNDIS_MASTER_INTERFACE
,
3665 .driver_info
= (unsigned long) &bcm4320b_info
,
3667 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3668 | USB_DEVICE_ID_MATCH_DEVICE
,
3670 .idProduct
= 0x011b, /* Belkin F5D7051 */
3671 RNDIS_MASTER_INTERFACE
,
3672 .driver_info
= (unsigned long) &bcm4320b_info
,
3674 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3675 | USB_DEVICE_ID_MATCH_DEVICE
,
3676 .idVendor
= 0x1799, /* Belkin has two vendor ids */
3677 .idProduct
= 0x011b, /* Belkin F5D7051 */
3678 RNDIS_MASTER_INTERFACE
,
3679 .driver_info
= (unsigned long) &bcm4320b_info
,
3681 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3682 | USB_DEVICE_ID_MATCH_DEVICE
,
3684 .idProduct
= 0x0014, /* Linksys WUSB54GSv2 */
3685 RNDIS_MASTER_INTERFACE
,
3686 .driver_info
= (unsigned long) &bcm4320b_info
,
3688 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3689 | USB_DEVICE_ID_MATCH_DEVICE
,
3691 .idProduct
= 0x0026, /* Linksys WUSB54GSC */
3692 RNDIS_MASTER_INTERFACE
,
3693 .driver_info
= (unsigned long) &bcm4320b_info
,
3695 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3696 | USB_DEVICE_ID_MATCH_DEVICE
,
3698 .idProduct
= 0x1717, /* Asus WL169gE */
3699 RNDIS_MASTER_INTERFACE
,
3700 .driver_info
= (unsigned long) &bcm4320b_info
,
3702 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3703 | USB_DEVICE_ID_MATCH_DEVICE
,
3705 .idProduct
= 0xd11b, /* Eminent EM4045 */
3706 RNDIS_MASTER_INTERFACE
,
3707 .driver_info
= (unsigned long) &bcm4320b_info
,
3709 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3710 | USB_DEVICE_ID_MATCH_DEVICE
,
3712 .idProduct
= 0x0715, /* BT Voyager 1055 */
3713 RNDIS_MASTER_INTERFACE
,
3714 .driver_info
= (unsigned long) &bcm4320b_info
,
3716 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3717 * parameters available, hardware probably contain older firmware version with
3718 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3721 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3722 | USB_DEVICE_ID_MATCH_DEVICE
,
3724 .idProduct
= 0x000e, /* Linksys WUSB54GSv1 */
3725 RNDIS_MASTER_INTERFACE
,
3726 .driver_info
= (unsigned long) &bcm4320a_info
,
3728 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3729 | USB_DEVICE_ID_MATCH_DEVICE
,
3731 .idProduct
= 0x0111, /* U.S. Robotics USR5420 */
3732 RNDIS_MASTER_INTERFACE
,
3733 .driver_info
= (unsigned long) &bcm4320a_info
,
3735 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3736 | USB_DEVICE_ID_MATCH_DEVICE
,
3738 .idProduct
= 0x004b, /* BUFFALO WLI-USB-G54 */
3739 RNDIS_MASTER_INTERFACE
,
3740 .driver_info
= (unsigned long) &bcm4320a_info
,
3742 /* Generic Wireless RNDIS devices that we don't have exact
3743 * idVendor/idProduct/chip yet.
3746 /* RNDIS is MSFT's un-official variant of CDC ACM */
3747 USB_INTERFACE_INFO(USB_CLASS_COMM
, 2 /* ACM */, 0x0ff),
3748 .driver_info
= (unsigned long) &rndis_wlan_info
,
3750 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3751 USB_INTERFACE_INFO(USB_CLASS_MISC
, 1, 1),
3752 .driver_info
= (unsigned long) &rndis_wlan_info
,
3756 MODULE_DEVICE_TABLE(usb
, products
);
3758 static struct usb_driver rndis_wlan_driver
= {
3759 .name
= "rndis_wlan",
3760 .id_table
= products
,
3761 .probe
= usbnet_probe
,
3762 .disconnect
= usbnet_disconnect
,
3763 .suspend
= usbnet_suspend
,
3764 .resume
= usbnet_resume
,
3765 .disable_hub_initiated_lpm
= 1,
3768 module_usb_driver(rndis_wlan_driver
);
3770 MODULE_AUTHOR("Bjorge Dijkstra");
3771 MODULE_AUTHOR("Jussi Kivilinna");
3772 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3773 MODULE_LICENSE("GPL");