11 #include <linux/export.h>
12 #include <linux/wireless.h>
14 #include <linux/if_arp.h>
16 #include <linux/slab.h>
29 bool is_ht =
false, is_a =
false, is_b =
false, is_g =
false;
37 is_ht |= sband->
ht_cap.ht_supported;
45 if (sband->
bitrates[i].bitrate == 10)
47 if (sband->
bitrates[i].bitrate == 60)
50 is_ht |= sband->
ht_cap.ht_supported;
53 strcpy(name,
"IEEE 802.11");
76 rdev = wiphy_to_dev(wdev->
wiphy);
98 memset(&vifparams, 0,
sizeof(vifparams));
100 cfg80211_lock_rdev(rdev);
102 cfg80211_unlock_rdev(rdev);
174 switch (wdev->
wiphy->signal_type) {
198 for (i = 0; i < wdev->
wiphy->n_cipher_suites; i++) {
199 switch (wdev->
wiphy->cipher_suites[i]) {
238 range->
freq[
c].e = 6;
250 if (wdev->
wiphy->max_scan_ssids > 0)
279 int i,
div = 1000000;
280 for (i = 0; i < freq->
e; i++)
284 return freq->
m /
div;
294 u32 orts = wdev->
wiphy->rts_threshold;
298 wdev->
wiphy->rts_threshold = (
u32) -1;
299 else if (rts->
value < 0)
304 err = rdev->
ops->set_wiphy_params(wdev->
wiphy,
307 wdev->
wiphy->rts_threshold = orts;
333 u32 ofrag = wdev->
wiphy->frag_threshold;
337 wdev->
wiphy->frag_threshold = (
u32) -1;
338 else if (frag->
value < 256)
342 wdev->
wiphy->frag_threshold = frag->
value & ~0x1;
345 err = rdev->
ops->set_wiphy_params(wdev->
wiphy,
348 wdev->
wiphy->frag_threshold = ofrag;
375 u8 olong = wdev->
wiphy->retry_long;
376 u8 oshort = wdev->
wiphy->retry_short;
399 err = rdev->
ops->set_wiphy_params(wdev->
wiphy, changed);
401 wdev->
wiphy->retry_short = oshort;
402 wdev->
wiphy->retry_long = olong;
410 struct iw_param *retry,
char *extra)
423 if (wdev->
wiphy->retry_long != wdev->
wiphy->retry_short)
440 const u8 *
addr,
bool remove,
bool tx_key,
447 if (pairwise && !addr)
450 if (!wdev->wext.keys) {
451 wdev->wext.keys = kzalloc(
sizeof(*wdev->wext.keys),
453 if (!wdev->wext.keys)
455 for (i = 0; i < 6; i++)
456 wdev->wext.keys->params[i].key =
457 wdev->wext.keys->data[i];
468 if (!rdev->
ops->set_default_mgmt_key)
471 if (idx < 4 || idx > 5)
473 }
else if (idx < 0 || idx > 3)
483 if (idx == wdev->wext.default_key &&
489 if (!pairwise && addr &&
493 err = rdev->
ops->del_key(&rdev->wiphy, dev, idx,
496 wdev->wext.connect.privacy =
false;
505 wdev->wext.keys->params[
idx].key_len = 0;
506 wdev->wext.keys->params[
idx].cipher = 0;
508 if (idx == wdev->wext.default_key)
509 wdev->wext.default_key = -1;
510 else if (idx == wdev->wext.default_mgmt_key)
511 wdev->wext.default_mgmt_key = -1;
528 err = rdev->
ops->add_key(&rdev->wiphy, dev, idx,
529 pairwise, addr, params);
535 memcpy(wdev->wext.keys->data[idx],
537 wdev->wext.keys->params[
idx].key =
538 wdev->wext.keys->data[
idx];
543 (tx_key || (!addr && wdev->wext.default_key == -1))) {
551 wdev->wext.default_key == -1) {
555 err = rdev->
ops->set_default_key(&rdev->wiphy, dev,
559 wdev->wext.default_key =
idx;
567 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
569 err = rdev->
ops->set_default_mgmt_key(&rdev->wiphy,
572 wdev->wext.default_mgmt_key =
idx;
581 const u8 *addr,
bool remove,
bool tx_key,
589 err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
590 remove, tx_key, idx, params);
597 static int cfg80211_wext_siwencode(
struct net_device *dev,
612 if (!rdev->
ops->del_key ||
613 !rdev->
ops->add_key ||
614 !rdev->
ops->set_default_key)
619 idx = wdev->wext.default_key;
622 }
else if (idx < 1 || idx > 4)
629 else if (erq->
length == 0) {
634 err = rdev->
ops->set_default_key(&rdev->wiphy, dev,
637 wdev->wext.default_key =
idx;
642 memset(¶ms, 0,
sizeof(params));
647 else if (erq->
length == 13)
652 return cfg80211_set_encryption(rdev, dev,
false,
NULL,
remove,
653 wdev->wext.default_key == -1,
657 static int cfg80211_wext_siwencodeext(
struct net_device *dev,
675 if (!rdev->
ops->del_key ||
676 !rdev->
ops->add_key ||
677 !rdev->
ops->set_default_key)
711 if (idx < 4 || idx > 5) {
712 idx = wdev->wext.default_mgmt_key;
718 if (idx < 1 || idx > 4) {
719 idx = wdev->wext.default_key;
726 addr = ext->
addr.sa_data;
727 if (is_broadcast_ether_addr(addr))
730 memset(¶ms, 0,
sizeof(params));
740 return cfg80211_set_encryption(
748 static int cfg80211_wext_giwencode(
struct net_device *dev,
761 idx = wdev->wext.default_key;
764 }
else if (idx < 1 || idx > 4)
769 erq->
flags = idx + 1;
771 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
778 wdev->wext.keys->params[idx].key_len);
779 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->
length);
785 static int cfg80211_wext_siwfreq(
struct net_device *dev,
787 struct iw_freq *wextfreq,
char *extra)
824 static int cfg80211_wext_giwfreq(
struct net_device *dev,
826 struct iw_freq *freq,
char *extra)
839 if (!rdev->
ops->get_channel)
842 chan = rdev->
ops->get_channel(wdev->
wiphy, wdev, &channel_type);
853 static int cfg80211_wext_siwtxpower(
struct net_device *dev,
867 if (!rdev->
ops->set_tx_power)
905 static int cfg80211_wext_giwtxpower(
struct net_device *dev,
918 if (!rdev->
ops->get_tx_power)
921 err = rdev->
ops->get_tx_power(wdev->
wiphy, &val);
934 static int cfg80211_set_auth_alg(
struct wireless_dev *wdev,
968 static int cfg80211_set_wpa_version(
struct wireless_dev *wdev,
u32 wpa_versions)
980 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
981 wdev->wext.connect.crypto.wpa_versions &=
985 wdev->wext.connect.crypto.wpa_versions |=
989 wdev->wext.connect.crypto.wpa_versions |=
995 static int cfg80211_set_cipher_group(
struct wireless_dev *wdev,
u32 cipher)
998 wdev->wext.connect.crypto.cipher_group =
1001 wdev->wext.connect.crypto.cipher_group =
1004 wdev->wext.connect.crypto.cipher_group =
1007 wdev->wext.connect.crypto.cipher_group =
1010 wdev->wext.connect.crypto.cipher_group =
1013 wdev->wext.connect.crypto.cipher_group = 0;
1020 static int cfg80211_set_cipher_pairwise(
struct wireless_dev *wdev,
u32 cipher)
1023 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
1025 if (cipher & IW_AUTH_CIPHER_WEP40) {
1030 if (cipher & IW_AUTH_CIPHER_WEP104) {
1035 if (cipher & IW_AUTH_CIPHER_TKIP) {
1040 if (cipher & IW_AUTH_CIPHER_CCMP) {
1045 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
1052 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1058 static int cfg80211_set_key_mgt(
struct wireless_dev *wdev,
u32 key_mgt)
1060 int nr_akm_suites = 0;
1067 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1073 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1078 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1083 static int cfg80211_wext_siwauth(
struct net_device *dev,
1085 struct iw_param *data,
char *extra)
1094 wdev->wext.connect.privacy = data->
value;
1097 return cfg80211_set_wpa_version(wdev, data->
value);
1099 return cfg80211_set_cipher_group(wdev, data->
value);
1101 return cfg80211_set_key_mgt(wdev, data->
value);
1103 return cfg80211_set_cipher_pairwise(wdev, data->
value);
1105 return cfg80211_set_auth_alg(wdev, data->
value);
1116 static int cfg80211_wext_giwauth(
struct net_device *dev,
1118 struct iw_param *data,
char *extra)
1125 static int cfg80211_wext_siwpower(
struct net_device *dev,
1138 if (!rdev->
ops->set_power_mgmt)
1158 timeout = wrq->
value / 1000;
1161 err = rdev->
ops->set_power_mgmt(wdev->
wiphy, dev, ps, timeout);
1172 static int cfg80211_wext_giwpower(
struct net_device *dev,
1183 static int cfg80211_wds_wext_siwap(
struct net_device *dev,
1185 struct sockaddr *addr,
char *extra)
1197 if (netif_running(dev))
1200 if (!rdev->
ops->set_wds_peer)
1212 static int cfg80211_wds_wext_giwap(
struct net_device *dev,
1214 struct sockaddr *addr,
char *extra)
1227 static int cfg80211_wext_siwrate(
struct net_device *dev,
1239 if (!rdev->
ops->set_bitrate_mask)
1246 if (rate->
value < 0) {
1248 }
else if (rate->
fixed) {
1249 fixed = rate->
value / 100000;
1251 maxrate = rate->
value / 100000;
1258 for (ridx = 0; ridx < sband->
n_bitrates; ridx++) {
1260 if (fixed == srate->
bitrate) {
1261 mask.control[band].legacy = 1 << ridx;
1265 if (srate->
bitrate <= maxrate) {
1266 mask.control[band].legacy |= 1 << ridx;
1278 static int cfg80211_wext_giwrate(
struct net_device *dev,
1280 struct iw_param *rate,
char *extra)
1292 if (!rdev->
ops->get_station)
1305 err = rdev->
ops->get_station(&rdev->wiphy, dev, addr, &
sinfo);
1330 if (!rdev->
ops->get_station)
1342 if (rdev->
ops->get_station(&rdev->wiphy, dev, bssid, &
sinfo))
1345 memset(&wstats, 0,
sizeof(wstats));
1347 switch (rdev->wiphy.signal_type) {
1354 wstats.qual.level =
sig;
1359 wstats.qual.qual = sig + 110;
1366 wstats.qual.level =
sinfo.signal;
1367 wstats.qual.qual =
sinfo.signal;
1377 wstats.discard.misc =
sinfo.rx_dropped_misc;
1379 wstats.discard.retries =
sinfo.tx_failed;
1384 static int cfg80211_wext_siwap(
struct net_device *dev,
1386 struct sockaddr *ap_addr,
char *extra)
1396 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
1402 static int cfg80211_wext_giwap(
struct net_device *dev,
1404 struct sockaddr *ap_addr,
char *extra)
1414 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
1420 static int cfg80211_wext_siwessid(
struct net_device *dev,
1436 static int cfg80211_wext_giwessid(
struct net_device *dev,
1455 static int cfg80211_wext_siwpmksa(
struct net_device *dev,
1457 struct iw_point *data,
char *extra)
1469 cfg_pmksa.bssid = pmksa->
bssid.sa_data;
1470 cfg_pmksa.pmkid = pmksa->
pmkid;
1472 switch (pmksa->
cmd) {
1474 if (!rdev->
ops->set_pmksa)
1477 return rdev->
ops->set_pmksa(&rdev->wiphy, dev, &cfg_pmksa);
1480 if (!rdev->
ops->del_pmksa)
1483 return rdev->
ops->del_pmksa(&rdev->wiphy, dev, &cfg_pmksa);
1486 if (!rdev->
ops->flush_pmksa)
1489 return rdev->
ops->flush_pmksa(&rdev->wiphy, dev);
1496 static const iw_handler cfg80211_handlers[] = {
1532 .num_standard =
ARRAY_SIZE(cfg80211_handlers),
1533 .standard = cfg80211_handlers,
1534 .get_wireless_stats = cfg80211_wireless_stats,