29 #include <linux/module.h>
31 #include <linux/netdevice.h>
33 #include <linux/ethtool.h>
36 #include <linux/mii.h>
40 #include <linux/if_arp.h>
41 #include <linux/ctype.h>
43 #include <linux/slab.h>
50 static char modparam_country[4] =
"EU";
54 static int modparam_frameburst = 1;
58 static int modparam_afterburner = 0;
61 "enable afterburner aka '125 High Speed Mode' (default: off)");
63 static int modparam_power_save = 0;
66 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
68 static int modparam_power_output = 3;
71 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
73 static int modparam_roamtrigger = -70;
76 "set roaming dBm trigger: -80=optimize for distance, "
77 "-60=bandwidth (default: -70)");
79 static int modparam_roamdelta = 1;
82 "set roaming tendency: 0=aggressive, 1=moderate, "
83 "2=conservative (default: moderate)");
85 static int modparam_workaround_interval;
89 "set stall workaround interval in msecs (0=disabled) (default: 0)");
104 #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
105 #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
106 #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
107 #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
110 #define RNDIS_UNKNOWN 0
111 #define RNDIS_BCM4320A 1
112 #define RNDIS_BCM4320B 2
118 #define NDIS_802_11_LENGTH_SSID 32
119 #define NDIS_802_11_LENGTH_RATES 8
120 #define NDIS_802_11_LENGTH_RATES_EX 16
356 #define CAP_MODE_80211A 1
357 #define CAP_MODE_80211B 2
358 #define CAP_MODE_80211G 4
359 #define CAP_MODE_MASK 7
361 #define WORK_LINK_UP (1<<0)
362 #define WORK_LINK_DOWN (1<<1)
363 #define WORK_SET_MULTICAST_LIST (1<<2)
365 #define RNDIS_WLAN_ALG_NONE 0
366 #define RNDIS_WLAN_ALG_WEP (1<<0)
367 #define RNDIS_WLAN_ALG_TKIP (1<<1)
368 #define RNDIS_WLAN_ALG_CCMP (1<<2)
370 #define RNDIS_WLAN_NUM_KEYS 4
371 #define RNDIS_WLAN_KEY_MGMT_NONE 0
372 #define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
373 #define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
375 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
378 { .center_freq = 2412 },
379 { .center_freq = 2417 },
380 { .center_freq = 2422 },
381 { .center_freq = 2427 },
382 { .center_freq = 2432 },
383 { .center_freq = 2437 },
384 { .center_freq = 2442 },
385 { .center_freq = 2447 },
386 { .center_freq = 2452 },
387 { .center_freq = 2457 },
388 { .center_freq = 2462 },
389 { .center_freq = 2467 },
390 { .center_freq = 2472 },
391 { .center_freq = 2484 },
409 static const u32 rndis_cipher_suites[] = {
482 static int rndis_change_virtual_intf(
struct wiphy *
wiphy,
492 static int rndis_set_tx_power(
struct wiphy *
wiphy,
495 static int rndis_get_tx_power(
struct wiphy *
wiphy,
int *
dbm);
535 static int rndis_set_cqm_rssi_config(
struct wiphy *
wiphy,
537 s32 rssi_thold,
u32 rssi_hyst);
540 .change_virtual_intf = rndis_change_virtual_intf,
542 .set_wiphy_params = rndis_set_wiphy_params,
543 .set_tx_power = rndis_set_tx_power,
544 .get_tx_power = rndis_get_tx_power,
545 .connect = rndis_connect,
546 .disconnect = rndis_disconnect,
547 .join_ibss = rndis_join_ibss,
548 .leave_ibss = rndis_leave_ibss,
549 .add_key = rndis_add_key,
550 .del_key = rndis_del_key,
551 .set_default_key = rndis_set_default_key,
552 .get_station = rndis_get_station,
553 .dump_station = rndis_dump_station,
554 .set_pmksa = rndis_set_pmksa,
555 .del_pmksa = rndis_del_pmksa,
556 .flush_pmksa = rndis_flush_pmksa,
557 .set_power_mgmt = rndis_set_power_mgmt,
558 .set_cqm_rssi_config = rndis_set_cqm_rssi_config,
561 static void *rndis_wiphy_privid = &rndis_wiphy_privid;
592 static int rndis_cipher_to_alg(
u32 cipher)
607 static int rndis_akm_suite_to_key_mgmt(
u32 akm_suite)
620 static const char *oid_to_string(
u32 oid)
623 #define OID_STR(oid) case oid: return(#oid)
676 static const char *oid_to_string(
u32 oid)
705 static int rndis_query_oid(
struct usbnet *dev,
u32 oid,
void *
data,
int *len)
715 int resplen, respoffs, copylen;
717 buflen = *len +
sizeof(*
u.get);
740 netdev_dbg(dev->
net,
"%s(%s): rndis_command() failed, %d (%08x)\n",
741 __func__, oid_to_string(oid), ret,
748 if (respoffs > buflen) {
751 "data offset: %d > %d\n", __func__,
752 oid_to_string(oid), respoffs, buflen);
758 if ((resplen + respoffs) > buflen) {
762 copylen = buflen - respoffs;
770 memcpy(data,
u.buf + respoffs, copylen);
774 ret = rndis_error_status(
u.get_c->status);
776 netdev_dbg(dev->
net,
"%s(%s): device returned error, 0x%08x (%d)\n",
777 __func__, oid_to_string(oid),
789 static int rndis_set_oid(
struct usbnet *dev,
u32 oid,
const void *data,
801 buflen = len +
sizeof(*
u.set);
822 memcpy(
u.buf +
sizeof(*
u.set), data, len);
828 netdev_dbg(dev->
net,
"%s(%s): rndis_command() failed, %d (%08x)\n",
829 __func__, oid_to_string(oid), ret,
833 ret = rndis_error_status(
u.set_c->status);
836 netdev_dbg(dev->
net,
"%s(%s): device returned error, 0x%08x (%d)\n",
837 __func__, oid_to_string(oid),
857 memset(reset, 0,
sizeof(*reset));
875 static int rndis_set_config_parameter(
struct usbnet *dev,
char *
param,
884 value_len =
sizeof(
__le32);
885 else if (value_type == 2)
891 info_len =
sizeof(*infobuf) + param_len +
value_len;
903 memset(infobuf, 0xCC, info_len + 12);
907 netdev_dbg(dev->
net,
"setting config parameter: %s, value: %s\n",
910 netdev_dbg(dev->
net,
"setting config parameter: %s, value: %d\n",
911 param, *(
u32 *)value);
920 unibuf = (
void *)infobuf +
sizeof(*infobuf);
921 for (i = 0; i < param_len /
sizeof(
__le16); i++)
924 if (value_type == 2) {
925 unibuf = (
void *)infobuf +
sizeof(*infobuf) + param_len;
926 for (i = 0; i < value_len /
sizeof(
__le16); i++)
929 dst_value = (
void *)infobuf +
sizeof(*infobuf) + param_len;
935 for (i = 0; i < info_len; i += 12) {
947 netdev_dbg(dev->
net,
"setting rndis config parameter failed, %d\n",
954 static int rndis_set_config_parameter_str(
struct usbnet *dev,
955 char *param,
char *value)
957 return rndis_set_config_parameter(dev, param, 2, value);
963 static int level_to_qual(
int level)
966 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
972 static int set_infra_mode(
struct usbnet *usbdev,
int mode);
973 static void restore_keys(
struct usbnet *usbdev);
974 static int rndis_check_bssid_list(
struct usbnet *usbdev,
u8 *match_bssid,
977 static int rndis_start_bssid_list_scan(
struct usbnet *usbdev)
993 ssid,
sizeof(*ssid));
995 netdev_warn(usbdev->
net,
"setting SSID failed (%08X)\n", ret);
1000 netdev_dbg(usbdev->
net,
"%s(): radio_on = true\n", __func__);
1006 static int set_bssid(
struct usbnet *usbdev,
const u8 *
bssid)
1013 netdev_warn(usbdev->
net,
"setting BSSID[%pM] failed (%08X)\n",
1021 static int clear_bssid(
struct usbnet *usbdev)
1024 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
1027 return set_bssid(usbdev, broadcast_mac);
1039 memset(bssid, 0, ETH_ALEN);
1044 static int get_association_info(
struct usbnet *usbdev,
1047 return rndis_query_oid(usbdev,
1052 static bool is_associated(
struct usbnet *usbdev)
1061 ret = get_bssid(usbdev, bssid);
1063 return (ret == 0 && !is_zero_ether_addr(bssid));
1066 static int disassociate(
struct usbnet *usbdev,
bool reset_ssid)
1073 ret = rndis_set_oid(usbdev,
1096 ssid.
essid[0] = 0x1;
1097 ssid.
essid[1] = 0xff;
1098 for (i = 2; i <
sizeof(ssid.
essid); i++)
1099 ssid.
essid[i] = 0x1 + (ssid.
essid[i] * 0xfe / 0xff);
1100 ret = set_essid(usbdev, &ssid);
1105 static int set_auth_mode(
struct usbnet *usbdev,
u32 wpa_version,
1112 netdev_dbg(usbdev->
net,
"%s(): wpa_version=0x%x authalg=0x%x keymgmt=0x%x\n",
1113 __func__, wpa_version, auth_type, keymgmt);
1137 ret = rndis_set_oid(usbdev,
1141 netdev_warn(usbdev->
net,
"setting auth mode failed (%08X)\n",
1151 static int set_priv_filter(
struct usbnet *usbdev)
1165 return rndis_set_oid(usbdev,
1170 static int set_encr_mode(
struct usbnet *usbdev,
int pairwise,
int groupwise)
1175 netdev_dbg(usbdev->
net,
"%s(): cipher_pair=0x%x cipher_group=0x%x\n",
1176 __func__, pairwise, groupwise);
1184 else if (groupwise & RNDIS_WLAN_ALG_CCMP)
1186 else if (groupwise & RNDIS_WLAN_ALG_TKIP)
1192 ret = rndis_set_oid(usbdev,
1196 netdev_warn(usbdev->
net,
"setting encr mode failed (%08X)\n",
1204 static int set_infra_mode(
struct usbnet *usbdev,
int mode)
1214 ret = rndis_set_oid(usbdev,
1218 netdev_warn(usbdev->
net,
"setting infra mode failed (%08X)\n",
1226 restore_keys(usbdev);
1232 static int set_rts_threshold(
struct usbnet *usbdev,
u32 rts_threshold)
1236 netdev_dbg(usbdev->
net,
"%s(): %i\n", __func__, rts_threshold);
1238 if (rts_threshold < 0 || rts_threshold > 2347)
1239 rts_threshold = 2347;
1242 return rndis_set_oid(usbdev,
1251 netdev_dbg(usbdev->
net,
"%s(): %i\n", __func__, frag_threshold);
1253 if (frag_threshold < 256 || frag_threshold > 2346)
1254 frag_threshold = 2346;
1257 return rndis_set_oid(usbdev,
1262 static void set_default_iw_params(
struct usbnet *usbdev)
1267 set_priv_filter(usbdev);
1271 static int deauthenticate(
struct usbnet *usbdev)
1275 ret = disassociate(usbdev,
true);
1276 set_default_iw_params(usbdev);
1283 unsigned int dsconfig;
1289 if (is_associated(usbdev))
1292 dsconfig = ieee80211_dsss_chan_to_freq(channel) * 1000;
1295 ret = rndis_query_oid(usbdev,
1299 netdev_dbg(usbdev->
net,
"%s(): querying configuration failed\n",
1305 ret = rndis_set_oid(usbdev,
1309 netdev_dbg(usbdev->
net,
"%s(): %d -> %d\n", __func__, channel, ret);
1324 ret = rndis_query_oid(usbdev,
1327 netdev_dbg(usbdev->
net,
"%s(): RNDIS_OID_802_11_CONFIGURATION -> %d\n",
1332 channel = ieee80211_get_channel(priv->
wdev.wiphy,
1352 __func__, index, key_len);
1359 else if (key_len == 13)
1364 memset(&ndis_key, 0,
sizeof(ndis_key));
1369 memcpy(&ndis_key.material, key, key_len);
1373 ret = set_encr_mode(usbdev, RNDIS_WLAN_ALG_WEP,
1376 netdev_warn(usbdev->
net,
"encryption couldn't be enabled (%08X)\n",
1380 ret = rndis_set_oid(usbdev,
1384 netdev_warn(usbdev->
net,
"adding encryption key %d failed (%08X)\n",
1397 static int add_wpa_key(
struct usbnet *usbdev,
const u8 *key,
int key_len,
1411 if (key_len >
sizeof(ndis_key.material) || key_len < 0) {
1412 netdev_dbg(usbdev->
net,
"%s(): key length out of range (%i)\n",
1417 if (!rx_seq || seq_len <= 0) {
1418 netdev_dbg(usbdev->
net,
"%s(): recv seq flag without buffer\n",
1422 if (rx_seq && seq_len >
sizeof(ndis_key.rsc)) {
1423 netdev_dbg(usbdev->
net,
"%s(): too big recv seq buffer\n", __func__);
1428 is_addr_ok = addr && !is_zero_ether_addr(addr) &&
1429 !is_broadcast_ether_addr(addr);
1431 netdev_dbg(usbdev->
net,
"%s(): pairwise but bssid invalid (%pM)\n",
1439 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1440 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
1442 memset(&ndis_key, 0,
sizeof(ndis_key));
1445 sizeof(ndis_key.material) + key_len);
1452 memcpy(ndis_key.material, key, 16);
1453 memcpy(ndis_key.material + 16, key + 24, 8);
1454 memcpy(ndis_key.material + 24, key + 16, 8);
1456 memcpy(ndis_key.material, key, key_len);
1458 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
1459 memcpy(ndis_key.rsc, rx_seq, seq_len);
1461 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
1463 memcpy(ndis_key.bssid, addr, ETH_ALEN);
1467 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1469 get_bssid(usbdev, ndis_key.bssid);
1472 ret = rndis_set_oid(usbdev,
1475 netdev_dbg(usbdev->
net,
"%s(): RNDIS_OID_802_11_ADD_KEY -> %08X\n",
1484 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
1495 static int restore_key(
struct usbnet *usbdev,
u8 key_idx)
1500 if (is_wpa_key(priv, key_idx))
1505 netdev_dbg(usbdev->
net,
"%s(): %i:%i\n", __func__, key_idx, key.len);
1510 return add_wep_key(usbdev, key.material, key.len, key_idx);
1513 static void restore_keys(
struct usbnet *usbdev)
1517 for (i = 0; i < 4; i++)
1518 restore_key(usbdev, i);
1527 static int remove_key(
struct usbnet *usbdev,
u8 index,
const u8 *bssid)
1541 is_wpa = is_wpa_key(priv, index);
1544 __func__, index, is_wpa ?
"wpa" :
"wep",
1547 clear_key(priv, index);
1550 remove_key.size =
cpu_to_le32(
sizeof(remove_key));
1554 if (!is_broadcast_ether_addr(bssid))
1557 memcpy(remove_key.bssid, bssid,
1558 sizeof(remove_key.bssid));
1560 memset(remove_key.bssid, 0xff,
1561 sizeof(remove_key.bssid));
1563 ret = rndis_set_oid(usbdev,
1565 &remove_key,
sizeof(remove_key));
1570 ret = rndis_set_oid(usbdev,
1572 &keyindex,
sizeof(keyindex));
1574 netdev_warn(usbdev->
net,
1575 "removing encryption key %d failed (%08X)\n",
1588 static void set_multicast_list(
struct usbnet *usbdev)
1594 char *mc_addrs =
NULL;
1607 if (filter != basefilter)
1614 netif_addr_lock_bh(usbdev->
net);
1618 }
else if (mc_count) {
1623 netdev_warn(usbdev->
net,
1624 "couldn't alloc %d bytes of memory\n",
1625 mc_count * ETH_ALEN);
1626 netif_addr_unlock_bh(usbdev->
net);
1631 memcpy(mc_addrs + i++ * ETH_ALEN,
1632 ha->addr, ETH_ALEN);
1634 netif_addr_unlock_bh(usbdev->
net);
1636 if (filter != basefilter)
1640 ret = rndis_set_oid(usbdev,
1642 mc_addrs, mc_count * ETH_ALEN);
1649 netdev_dbg(usbdev->
net,
"RNDIS_OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d\n",
1657 netdev_warn(usbdev->
net,
"couldn't set packet filter: %08x\n",
1661 netdev_dbg(usbdev->
net,
"RNDIS_OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d\n",
1666 static void debug_print_pmkids(
struct usbnet *usbdev,
1668 const char *func_str)
1671 int i, len,
count, max_pmkids, entry_len;
1673 max_pmkids = priv->
wdev.wiphy->max_num_pmkids;
1677 entry_len = (count > 0) ? (len -
sizeof(*pmkids)) / count : -1;
1679 netdev_dbg(usbdev->
net,
"%s(): %d PMKIDs (data len: %d, entry len: "
1680 "%d)\n", func_str, count, len, entry_len);
1682 if (count > max_pmkids)
1685 for (i = 0; i <
count; i++) {
1689 "pmkid: %08X:%08X:%08X:%08X\n",
1696 static void debug_print_pmkids(
struct usbnet *usbdev,
1698 const char *func_str)
1708 int len,
ret, max_pmkids;
1710 max_pmkids = priv->
wdev.wiphy->max_num_pmkids;
1711 len =
sizeof(*pmkids) + max_pmkids *
sizeof(pmkids->
bssid_info[0]);
1718 pmkids->bssid_info_count =
cpu_to_le32(max_pmkids);
1723 netdev_dbg(usbdev->
net,
"%s(): RNDIS_OID_802_11_PMKID(%d, %d)"
1724 " -> %d\n", __func__, len, max_pmkids, ret);
1727 return ERR_PTR(ret);
1730 if (
le32_to_cpu(pmkids->bssid_info_count) > max_pmkids)
1731 pmkids->bssid_info_count =
cpu_to_le32(max_pmkids);
1733 debug_print_pmkids(usbdev, pmkids, __func__);
1738 static int set_device_pmkids(
struct usbnet *usbdev,
1741 int ret, len, num_pmkids;
1744 len =
sizeof(*pmkids) + num_pmkids *
sizeof(pmkids->
bssid_info[0]);
1747 debug_print_pmkids(usbdev, pmkids, __func__);
1752 netdev_dbg(usbdev->
net,
"%s(): RNDIS_OID_802_11_PMKID(%d, %d) -> %d"
1753 "\n", __func__, len, num_pmkids, ret);
1770 if (count > max_pmkids)
1773 for (i = 0; i <
count; i++)
1774 if (ether_addr_equal(pmkids->
bssid_info[i].bssid,
1781 __func__, pmksa->
bssid);
1786 for (; i + 1 <
count; i++)
1790 newlen =
sizeof(*pmkids) + count *
sizeof(pmkids->
bssid_info[0]);
1798 return ERR_PTR(err);
1812 if (count > max_pmkids)
1816 for (i = 0; i <
count; i++) {
1817 if (!ether_addr_equal(pmkids->
bssid_info[i].bssid,
1828 if (i == max_pmkids) {
1835 newlen =
sizeof(*pmkids) + (count + 1) *
sizeof(pmkids->
bssid_info[0]);
1842 pmkids = new_pmkids;
1853 return ERR_PTR(err);
1859 static int rndis_change_virtual_intf(
struct wiphy *
wiphy,
1881 return set_infra_mode(usbdev, mode);
1884 static int rndis_set_wiphy_params(
struct wiphy *wiphy,
u32 changed)
1905 static int rndis_set_tx_power(
struct wiphy *wiphy,
1913 __func__, type, mbm);
1915 if (mbm < 0 || (mbm % 100))
1923 MBM_TO_DBM(mbm) == get_bcm4320_power_dbm(priv)) {
1925 disassociate(usbdev,
true);
1933 static int rndis_get_tx_power(
struct wiphy *wiphy,
int *
dbm)
1938 *dbm = get_bcm4320_power_dbm(priv);
1945 #define SCAN_DELAY_JIFFIES (6 * HZ)
1946 static int rndis_scan(
struct wiphy *wiphy,
1950 struct usbnet *usbdev = netdev_priv(dev);
1960 rndis_check_bssid_list(usbdev,
NULL,
NULL);
1967 ret = rndis_start_bssid_list_scan(usbdev);
1979 static bool rndis_bss_info_update(
struct usbnet *usbdev,
1993 netdev_dbg(usbdev->
net,
" found bssid: '%.32s' [%pM], len: %d\n",
2006 ie_len =
min(bssid_len - (
int)
sizeof(*bssid),
2013 channel = ieee80211_get_channel(priv->
wdev.wiphy,
2024 timestamp, capability, beacon_interval, ie, ie_len, signal,
2028 return (bss !=
NULL);
2033 int *bssid_len,
void *
buf,
int len)
2035 void *buf_end, *bssid_end;
2037 buf_end = (
char *)buf + len;
2038 bssid_end = (
char *)bssid + *bssid_len;
2040 if ((
int)(buf_end - bssid_end) <
sizeof(bssid->
length)) {
2044 bssid = (
void *)((
char *)bssid + *bssid_len);
2051 int bssid_len,
void *buf,
int len)
2053 void *buf_end, *bssid_end;
2055 if (!bssid || bssid_len <= 0 || bssid_len > len)
2058 buf_end = (
char *)buf + len;
2059 bssid_end = (
char *)bssid + bssid_len;
2061 return (
int)(buf_end - bssid_end) >= 0 && (
int)(bssid_end -
buf) >= 0;
2064 static int rndis_check_bssid_list(
struct usbnet *usbdev,
u8 *match_bssid,
2070 int ret = -
EINVAL, len,
count, bssid_len, real_count, new_len;
2091 if (new_len > len) {
2102 netdev_dbg(usbdev->
net,
"%s(): buflen: %d\n", __func__, len);
2105 bssid = next_bssid_list_item(bssid_list->
bssid, &bssid_len, buf, len);
2110 while (check_bssid_list_item(bssid, bssid_len, buf, len)) {
2111 if (rndis_bss_info_update(usbdev, bssid) && match_bssid &&
2113 if (ether_addr_equal(bssid->
mac, match_bssid))
2118 bssid = next_bssid_list_item(bssid, &bssid_len, buf, len);
2121 netdev_dbg(usbdev->
net,
"%s(): num_items from device: %d, really found:"
2122 " %d\n", __func__, count, real_count);
2141 ret = rndis_check_bssid_list(usbdev,
NULL,
NULL);
2148 static int rndis_connect(
struct wiphy *wiphy,
struct net_device *dev,
2163 groupwise = rndis_cipher_to_alg(sme->
crypto.cipher_group);
2164 for (i = 0; i < sme->
crypto.n_ciphers_pairwise; i++)
2166 rndis_cipher_to_alg(sme->
crypto.ciphers_pairwise[i]);
2168 if (sme->
crypto.n_ciphers_pairwise > 0 &&
2170 netdev_err(usbdev->
net,
"Unsupported pairwise cipher\n");
2174 for (i = 0; i < sme->
crypto.n_akm_suites; i++)
2176 rndis_akm_suite_to_key_mgmt(sme->
crypto.akm_suites[i]);
2178 if (sme->
crypto.n_akm_suites > 0 &&
2180 netdev_err(usbdev->
net,
"Invalid keymgmt\n");
2184 netdev_dbg(usbdev->
net,
"cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:0x%x]:0x%x)\n",
2187 groupwise, pairwise, keymgmt);
2189 if (is_associated(usbdev))
2190 disassociate(usbdev,
false);
2194 netdev_dbg(usbdev->
net,
"connect: set_infra_mode failed, %d\n",
2196 goto err_turn_radio_on;
2202 netdev_dbg(usbdev->
net,
"connect: set_auth_mode failed, %d\n",
2204 goto err_turn_radio_on;
2207 set_priv_filter(usbdev);
2209 ret = set_encr_mode(usbdev, pairwise, groupwise);
2211 netdev_dbg(usbdev->
net,
"connect: set_encr_mode failed, %d\n",
2213 goto err_turn_radio_on;
2217 ret = set_channel(usbdev, chan);
2219 netdev_dbg(usbdev->
net,
"connect: set_channel failed, %d\n",
2221 goto err_turn_radio_on;
2225 if (sme->
key && ((groupwise | pairwise) & RNDIS_WLAN_ALG_WEP)) {
2229 netdev_dbg(usbdev->
net,
"connect: add_wep_key failed, %d (%d, %d)\n",
2231 goto err_turn_radio_on;
2235 if (sme->
bssid && !is_zero_ether_addr(sme->
bssid) &&
2236 !is_broadcast_ether_addr(sme->
bssid)) {
2237 ret = set_bssid(usbdev, sme->
bssid);
2241 goto err_turn_radio_on;
2244 clear_bssid(usbdev);
2250 memset(&ssid, 0,
sizeof(ssid));
2260 ret = set_essid(usbdev, &ssid);
2262 netdev_dbg(usbdev->
net,
"connect: set_essid failed, %d\n", ret);
2266 disassociate(usbdev,
true);
2271 static int rndis_disconnect(
struct wiphy *wiphy,
struct net_device *dev,
2277 netdev_dbg(usbdev->
net,
"cfg80211.disconnect(%d)\n", reason_code);
2282 return deauthenticate(usbdev);
2285 static int rndis_join_ibss(
struct wiphy *wiphy,
struct net_device *dev,
2311 netdev_dbg(usbdev->
net,
"cfg80211.join_ibss('%.32s':[%pM]:%d:%d)\n",
2314 if (is_associated(usbdev))
2315 disassociate(usbdev,
false);
2319 netdev_dbg(usbdev->
net,
"join_ibss: set_infra_mode failed, %d\n",
2321 goto err_turn_radio_on;
2326 netdev_dbg(usbdev->
net,
"join_ibss: set_auth_mode failed, %d\n",
2328 goto err_turn_radio_on;
2331 set_priv_filter(usbdev);
2335 netdev_dbg(usbdev->
net,
"join_ibss: set_encr_mode failed, %d\n",
2337 goto err_turn_radio_on;
2341 ret = set_channel(usbdev, chan);
2343 netdev_dbg(usbdev->
net,
"join_ibss: set_channel failed, %d\n",
2345 goto err_turn_radio_on;
2349 if (params->
bssid && !is_zero_ether_addr(params->
bssid) &&
2350 !is_broadcast_ether_addr(params->
bssid)) {
2351 ret = set_bssid(usbdev, params->
bssid);
2353 netdev_dbg(usbdev->
net,
"join_ibss: set_bssid failed, %d\n",
2355 goto err_turn_radio_on;
2358 clear_bssid(usbdev);
2364 memset(&ssid, 0,
sizeof(ssid));
2372 ret = set_essid(usbdev, &ssid);
2374 netdev_dbg(usbdev->
net,
"join_ibss: set_essid failed, %d\n",
2379 disassociate(usbdev,
true);
2384 static int rndis_leave_ibss(
struct wiphy *wiphy,
struct net_device *dev)
2394 return deauthenticate(usbdev);
2397 static int rndis_add_key(
struct wiphy *wiphy,
struct net_device *netdev,
2406 __func__, key_index, mac_addr, params->
cipher);
2408 switch (params->
cipher) {
2411 return add_wep_key(usbdev, params->
key, params->
key_len,
2420 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY |
2423 return add_wpa_key(usbdev, params->
key, params->
key_len,
2424 key_index, mac_addr, params->
seq,
2428 __func__, params->
cipher);
2433 static int rndis_del_key(
struct wiphy *wiphy,
struct net_device *netdev,
2434 u8 key_index,
bool pairwise,
const u8 *mac_addr)
2439 netdev_dbg(usbdev->
net,
"%s(%i, %pM)\n", __func__, key_index, mac_addr);
2441 return remove_key(usbdev, key_index, mac_addr);
2444 static int rndis_set_default_key(
struct wiphy *wiphy,
struct net_device *netdev,
2445 u8 key_index,
bool unicast,
bool multicast)
2458 if (is_wpa_key(priv, key_index))
2463 return add_wep_key(usbdev, key.material, key.len, key_index);
2466 static void rndis_fill_station_info(
struct usbnet *usbdev,
2472 memset(sinfo, 0,
sizeof(*sinfo));
2474 len =
sizeof(linkspeed);
2490 static int rndis_get_station(
struct wiphy *wiphy,
struct net_device *dev,
2496 if (!ether_addr_equal(priv->
bssid, mac))
2499 rndis_fill_station_info(usbdev, sinfo);
2504 static int rndis_dump_station(
struct wiphy *wiphy,
struct net_device *dev,
2515 rndis_fill_station_info(usbdev, sinfo);
2520 static int rndis_set_pmksa(
struct wiphy *wiphy,
struct net_device *netdev,
2528 netdev_dbg(usbdev->
net,
"%s(%pM, %08X:%08X:%08X:%08X)\n", __func__,
2533 pmkids = get_device_pmkids(usbdev);
2534 if (IS_ERR(pmkids)) {
2536 return PTR_ERR(pmkids);
2539 pmkids = update_pmkid(usbdev, pmkids, pmksa, wiphy->
max_num_pmkids);
2540 if (IS_ERR(pmkids)) {
2542 return PTR_ERR(pmkids);
2545 return set_device_pmkids(usbdev, pmkids);
2548 static int rndis_del_pmksa(
struct wiphy *wiphy,
struct net_device *netdev,
2556 netdev_dbg(usbdev->
net,
"%s(%pM, %08X:%08X:%08X:%08X)\n", __func__,
2561 pmkids = get_device_pmkids(usbdev);
2562 if (IS_ERR(pmkids)) {
2564 return PTR_ERR(pmkids);
2567 pmkids = remove_pmkid(usbdev, pmkids, pmksa, wiphy->
max_num_pmkids);
2568 if (IS_ERR(pmkids)) {
2570 return PTR_ERR(pmkids);
2573 return set_device_pmkids(usbdev, pmkids);
2576 static int rndis_flush_pmksa(
struct wiphy *wiphy,
struct net_device *netdev)
2593 static int rndis_set_power_mgmt(
struct wiphy *wiphy,
struct net_device *dev,
2606 enabled ?
"enabled" :
"disabled",
2621 &mode,
sizeof(mode));
2623 netdev_dbg(usbdev->
net,
"%s(): RNDIS_OID_802_11_POWER_MODE -> %d\n",
2629 static int rndis_set_cqm_rssi_config(
struct wiphy *wiphy,
2631 s32 rssi_thold,
u32 rssi_hyst)
2642 static void rndis_wlan_craft_connected_bss(
struct usbnet *usbdev,
u8 *bssid,
2652 u32 beacon_period = 0;
2655 int len,
ret, ie_len;
2664 netdev_dbg(usbdev->
net,
"%s(): RNDIS_OID_802_11_RSSI -> %d, "
2665 "rssi:%d, qual: %d\n", __func__, ret,
le32_to_cpu(rssi),
2678 channel = get_current_channel(usbdev, &beacon_period);
2680 netdev_warn(usbdev->
net,
"%s(): could not get channel.\n",
2687 memset(&ssid, 0,
sizeof(ssid));
2690 netdev_dbg(usbdev->
net,
"%s(): RNDIS_OID_802_11_SSID -> %d, len: %d, ssid: "
2691 "'%.32s'\n", __func__, ret,
2706 netdev_dbg(usbdev->
net,
"%s(): channel:%d(freq), bssid:[%pM], tsf:%d, "
2707 "capa:%x, beacon int:%d, resp_ie(len:%d, essid:'%.32s'), "
2708 "signal:%d\n", __func__, (channel ? channel->
center_freq : -1),
2709 bssid, (
u32)timestamp, capability, beacon_period, ie_len,
2710 ssid.
essid, signal);
2713 timestamp, capability, beacon_period, ie_buf, ie_len,
2721 static void rndis_wlan_do_link_up_work(
struct usbnet *usbdev)
2726 unsigned int resp_ie_len, req_ie_len;
2730 bool roamed =
false;
2759 if (req_ie_len != 0) {
2765 req_ie = (
u8 *)info + offset;
2775 if (resp_ie_len != 0) {
2781 resp_ie = (
u8 *)info + offset;
2798 ret = get_bssid(usbdev, bssid);
2800 memset(bssid, 0,
sizeof(bssid));
2803 bssid, roamed ?
" roamed" :
"");
2817 rndis_check_bssid_list(usbdev, bssid, &match_bss);
2819 if (!is_zero_ether_addr(bssid) && !match_bss) {
2823 rndis_wlan_craft_connected_bss(usbdev, bssid, info);
2829 req_ie_len, resp_ie,
2833 get_current_channel(usbdev,
NULL),
2834 bssid, req_ie, req_ie_len,
2849 static void rndis_wlan_do_link_down_work(
struct usbnet *usbdev)
2857 deauthenticate(usbdev);
2865 static void rndis_wlan_worker(
struct work_struct *work)
2872 rndis_wlan_do_link_up_work(usbdev);
2875 rndis_wlan_do_link_down_work(usbdev);
2878 set_multicast_list(usbdev);
2881 static void rndis_wlan_set_multicast_list(
struct net_device *dev)
2883 struct usbnet *usbdev = netdev_priv(dev);
2893 static void rndis_wlan_auth_indication(
struct usbnet *usbdev,
2900 bool pairwise_error, group_error;
2907 netdev_info(usbdev->
net,
"authentication indication: too short message (%i)\n",
2915 while (buflen >=
sizeof(*auth_req)) {
2916 auth_req = (
void *)buf;
2919 pairwise_error =
false;
2920 group_error =
false;
2923 type =
"reauth request";
2925 type =
"key update request";
2927 pairwise_error =
true;
2928 type =
"pairwise_error";
2932 type =
"group_error";
2935 netdev_info(usbdev->
net,
"authentication indication: %s (0x%08x)\n",
2938 if (pairwise_error) {
2944 key_type, key_id,
NULL,
2954 key_type, key_id,
NULL,
2963 static void rndis_wlan_pmkid_cand_list_indication(
struct usbnet *usbdev,
2972 netdev_info(usbdev->
net,
"pmkid candidate list indication: too short message (%i)\n",
2982 if (len < expected_len) {
2983 netdev_info(usbdev->
net,
"pmkid candidate list indication: list larger than buffer (%i < %i)\n",
2990 netdev_info(usbdev->
net,
"pmkid candidate list indication: version %i, candidates %i\n",
3002 netdev_dbg(usbdev->
net,
"cand[%i]: flags: 0x%08x, preauth: %d, bssid: %pM\n",
3010 static void rndis_wlan_media_specific_indication(
struct usbnet *usbdev,
3014 unsigned int len,
offset;
3021 netdev_info(usbdev->
net,
"media specific indication, ignore too short message (%i < 8)\n",
3026 if (len > buflen || offset > buflen || offset + len > buflen) {
3027 netdev_info(usbdev->
net,
"media specific indication, too large to fit to buffer (%i > %i)\n",
3028 offset + len, buflen);
3032 indication = (
void *)((
u8 *)msg +
offset);
3036 netdev_info(usbdev->
net,
"radio state indication: %i\n",
3041 netdev_info(usbdev->
net,
"media stream mode indication: %i\n",
3046 rndis_wlan_auth_indication(usbdev, indication, len);
3050 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
3054 netdev_info(usbdev->
net,
"media specific indication: unknown status type 0x%08x\n",
3059 static void rndis_wlan_indication(
struct usbnet *usbdev,
void *
ind,
int buflen)
3072 netdev_dbg(usbdev->
net,
"ignored RNDIS_OID_802_11_ADD_KEY triggered 'media connect'\n");
3078 netdev_info(usbdev->
net,
"media connect\n");
3086 netdev_info(usbdev->
net,
"media disconnect\n");
3094 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
3098 netdev_info(usbdev->
net,
"indication: 0x%08x\n",
3104 static int rndis_wlan_get_caps(
struct usbnet *usbdev,
struct wiphy *wiphy)
3109 } networks_supported;
3116 len =
sizeof(networks_supported);
3117 retval = rndis_query_oid(usbdev,
3119 &networks_supported, &len);
3124 for (i = 0; i <
n; i++) {
3125 switch (
le32_to_cpu(networks_supported.items[i])) {
3142 len =
sizeof(caps_buf);
3143 retval = rndis_query_oid(usbdev,
3147 netdev_dbg(usbdev->
net,
"RNDIS_OID_802_11_CAPABILITY -> len %d, "
3148 "ver %d, pmkids %d, auth-encr-pairs %d\n",
3160 static void rndis_do_cqm(
struct usbnet *usbdev,
s32 rssi)
3164 int thold, hyst, last_event;
3175 if (rssi < thold && (last_event == 0 || rssi < last_event - hyst))
3177 else if (rssi > thold && (last_event == 0 || rssi > last_event + hyst))
3186 #define DEVICE_POLLER_JIFFIES (HZ)
3187 static void rndis_device_poller(
struct work_struct *work)
3202 if (!is_associated(usbdev)) {
3209 rndis_check_bssid_list(usbdev,
NULL,
NULL);
3212 rndis_start_bssid_list_scan(usbdev);
3226 netdev_dbg(usbdev->
net,
"dev-poller: RNDIS_OID_802_11_RSSI -> %d, rssi:%d, qual: %d\n",
3248 rndis_set_oid(usbdev,
3257 rndis_query_oid(usbdev,
3264 if (update_jiffies >=
HZ)
3268 if (
abs(j - update_jiffies) <= 10)
3321 if (modparam_workaround_interval < 0)
3327 static int unknown_early_init(
struct usbnet *usbdev)
3340 static int bcm4320a_early_init(
struct usbnet *usbdev)
3354 static int bcm4320b_early_init(
struct usbnet *usbdev)
3365 rndis_set_config_parameter_str(usbdev,
"Country", priv->
param_country);
3366 rndis_set_config_parameter_str(usbdev,
"FrameBursting",
3368 rndis_set_config_parameter_str(usbdev,
"Afterburner",
3371 rndis_set_config_parameter_str(usbdev,
"PowerSaveMode", buf);
3373 rndis_set_config_parameter_str(usbdev,
"PwrOut", buf);
3375 rndis_set_config_parameter_str(usbdev,
"RoamTrigger", buf);
3377 rndis_set_config_parameter_str(usbdev,
"RoamDelta", buf);
3390 .ndo_set_rx_mode = rndis_wlan_set_multicast_list,
3395 struct wiphy *wiphy;
3408 priv = wiphy_priv(wiphy);
3409 usbdev->
net->ieee80211_ptr = &priv->
wdev;
3410 priv->
wdev.wiphy = wiphy;
3439 usbdev->
net->netdev_ops = &rndis_wlan_netdev_ops;
3442 retval = rndis_set_oid(usbdev,
3447 retval = rndis_query_oid(usbdev,
3460 wiphy->
privid = rndis_wiphy_privid;
3466 rndis_wlan_get_caps(usbdev, wiphy);
3469 memcpy(priv->
rates, rndis_rates,
sizeof(rndis_rates));
3478 sizeof(rndis_cipher_suites));
3482 set_wiphy_dev(wiphy, &usbdev->
udev->dev);
3489 set_default_iw_params(usbdev);
3494 rndis_set_wiphy_params(wiphy,
3495 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
3499 disassociate(usbdev,
false);
3520 disassociate(usbdev,
false);
3534 static int rndis_wlan_reset(
struct usbnet *usbdev)
3543 netdev_warn(usbdev->
net,
"rndis_reset failed: %d\n", retval);
3547 set_multicast_list(usbdev);
3552 return deauthenticate(usbdev);
3555 static int rndis_wlan_stop(
struct usbnet *usbdev)
3563 retval = disassociate(usbdev,
false);
3586 .description =
"Wireless RNDIS device, BCM4320b based",
3589 .bind = rndis_wlan_bind,
3590 .unbind = rndis_wlan_unbind,
3594 .reset = rndis_wlan_reset,
3595 .stop = rndis_wlan_stop,
3596 .early_init = bcm4320b_early_init,
3597 .indication = rndis_wlan_indication,
3601 .description =
"Wireless RNDIS device, BCM4320a based",
3604 .bind = rndis_wlan_bind,
3605 .unbind = rndis_wlan_unbind,
3609 .reset = rndis_wlan_reset,
3610 .stop = rndis_wlan_stop,
3611 .early_init = bcm4320a_early_init,
3612 .indication = rndis_wlan_indication,
3615 static const struct driver_info rndis_wlan_info = {
3616 .description =
"Wireless RNDIS device",
3619 .bind = rndis_wlan_bind,
3620 .unbind = rndis_wlan_unbind,
3624 .reset = rndis_wlan_reset,
3625 .stop = rndis_wlan_stop,
3626 .early_init = unknown_early_init,
3627 .indication = rndis_wlan_indication,
3633 #define RNDIS_MASTER_INTERFACE \
3634 .bInterfaceClass = USB_CLASS_COMM, \
3635 .bInterfaceSubClass = 2 , \
3636 .bInterfaceProtocol = 0x0ff
3642 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3643 | USB_DEVICE_ID_MATCH_DEVICE,
3645 .idProduct = 0x00bc,
3647 .driver_info = (
unsigned long) &bcm4320b_info,
3649 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3650 | USB_DEVICE_ID_MATCH_DEVICE,
3652 .idProduct = 0x011b,
3654 .driver_info = (
unsigned long) &bcm4320b_info,
3656 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3657 | USB_DEVICE_ID_MATCH_DEVICE,
3659 .idProduct = 0x011b,
3661 .driver_info = (
unsigned long) &bcm4320b_info,
3663 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3664 | USB_DEVICE_ID_MATCH_DEVICE,
3666 .idProduct = 0x011b,
3668 .driver_info = (
unsigned long) &bcm4320b_info,
3670 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3671 | USB_DEVICE_ID_MATCH_DEVICE,
3673 .idProduct = 0x0014,
3675 .driver_info = (
unsigned long) &bcm4320b_info,
3677 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3678 | USB_DEVICE_ID_MATCH_DEVICE,
3680 .idProduct = 0x0026,
3682 .driver_info = (
unsigned long) &bcm4320b_info,
3684 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3685 | USB_DEVICE_ID_MATCH_DEVICE,
3687 .idProduct = 0x1717,
3689 .driver_info = (
unsigned long) &bcm4320b_info,
3691 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3692 | USB_DEVICE_ID_MATCH_DEVICE,
3694 .idProduct = 0xd11b,
3696 .driver_info = (
unsigned long) &bcm4320b_info,
3698 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3699 | USB_DEVICE_ID_MATCH_DEVICE,
3701 .idProduct = 0x0715,
3703 .driver_info = (
unsigned long) &bcm4320b_info,
3710 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3711 | USB_DEVICE_ID_MATCH_DEVICE,
3713 .idProduct = 0x000e,
3715 .driver_info = (
unsigned long) &bcm4320a_info,
3717 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3718 | USB_DEVICE_ID_MATCH_DEVICE,
3720 .idProduct = 0x0111,
3722 .driver_info = (
unsigned long) &bcm4320a_info,
3724 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3725 | USB_DEVICE_ID_MATCH_DEVICE,
3727 .idProduct = 0x004b,
3729 .driver_info = (
unsigned long) &bcm4320a_info,
3737 .driver_info = (
unsigned long) &rndis_wlan_info,
3741 .driver_info = (
unsigned long) &rndis_wlan_info,
3747 static struct usb_driver rndis_wlan_driver = {
3748 .name =
"rndis_wlan",
3749 .id_table = products,
3754 .disable_hub_initiated_lpm = 1,