8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
45 .pre_doit = nl80211_pre_doit,
46 .post_doit = nl80211_post_doit,
51 __cfg80211_wdev_from_attrs(
struct net *netns,
struct nlattr **attrs)
61 assert_cfg80211_lock();
63 if (!have_ifidx && !have_wdev_id)
70 wiphy_idx = wdev_id >> 32;
76 if (wiphy_net(&rdev->wiphy) != netns)
79 if (have_wdev_id && rdev->
wiphy_idx != wiphy_idx)
84 if (have_ifidx && wdev->
netdev &&
85 wdev->
netdev->ifindex == ifidx) {
106 __cfg80211_rdev_from_attrs(
struct net *netns,
struct nlattr **attrs)
111 assert_cfg80211_lock();
120 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
122 if (attrs[NL80211_ATTR_WDEV]) {
123 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
142 if (rdev && tmp != rdev)
149 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
165 if (rdev && tmp != rdev)
175 if (netns != wiphy_net(&rdev->wiphy))
207 rdev = __cfg80211_rdev_from_attrs(netns, info->
attrs);
418 if (!nl80211_fam.
attrbuf[NL80211_ATTR_IFINDEX])
421 res = nla_get_u32(nl80211_fam.
attrbuf[NL80211_ATTR_IFINDEX]);
427 static int nl80211_prepare_netdev_dump(
struct sk_buff *
skb,
432 int ifidx = cb->
args[0];
436 ifidx = nl80211_get_ifidx(cb);
452 err = PTR_ERR(*rdev);
464 cfg80211_unlock_rdev(rdev);
469 static bool is_valid_ie_attr(
const struct nlattr *
attr)
477 pos = nla_data(attr);
499 static inline void *nl80211hdr_put(
struct sk_buff *skb,
u32 portid,
u32 seq,
503 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
506 static int nl80211_msg_put_channel(
struct sk_buff *
msg,
511 goto nla_put_failure;
515 goto nla_put_failure;
518 goto nla_put_failure;
521 goto nla_put_failure;
524 goto nla_put_failure;
528 goto nla_put_failure;
565 k->
idx = nla_get_u8(tb[NL80211_KEY_IDX]);
568 k->
p.key = nla_data(tb[NL80211_KEY_DATA]);
569 k->
p.key_len =
nla_len(tb[NL80211_KEY_DATA]);
573 k->
p.seq = nla_data(tb[NL80211_KEY_SEQ]);
574 k->
p.seq_len =
nla_len(tb[NL80211_KEY_SEQ]);
578 k->
p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
581 k->
type = nla_get_u32(tb[NL80211_KEY_TYPE]);
589 tb[NL80211_KEY_DEFAULT_TYPES],
590 nl80211_key_default_policy);
637 int err = nla_parse_nested(
640 nl80211_key_default_policy);
662 err = nl80211_parse_key_old(info, k);
677 if (k->
idx < 4 || k->
idx > 5)
680 if (k->
idx < 0 || k->
idx > 3)
683 if (k->
idx < 0 || k->
idx > 5)
700 result = kzalloc(
sizeof(*result),
GFP_KERNEL);
711 err = nl80211_parse_key_new(key, &
parse);
726 }
else if (
parse.defmgmt)
744 static int nl80211_key_allowed(
struct wireless_dev *wdev)
760 if (wdev->
sme_state != CFG80211_SME_CONNECTED)
770 static int nl80211_put_iftypes(
struct sk_buff *msg,
u32 attr,
u16 ifmodes)
772 struct nlattr *nl_modes = nla_nest_start(msg, attr);
776 goto nla_put_failure;
780 if ((ifmodes & 1) && nla_put_flag(msg, i))
781 goto nla_put_failure;
786 nla_nest_end(msg, nl_modes);
793 static int nl80211_put_iface_combinations(
struct wiphy *
wiphy,
799 nl_combis = nla_nest_start(msg,
802 goto nla_put_failure;
806 struct nlattr *nl_combi, *nl_limits;
810 nl_combi = nla_nest_start(msg, i + 1);
812 goto nla_put_failure;
816 goto nla_put_failure;
821 nl_limit = nla_nest_start(msg, j + 1);
823 goto nla_put_failure;
826 goto nla_put_failure;
829 goto nla_put_failure;
830 nla_nest_end(msg, nl_limit);
833 nla_nest_end(msg, nl_limits);
837 goto nla_put_failure;
842 goto nla_put_failure;
844 nla_nest_end(msg, nl_combi);
847 nla_nest_end(msg, nl_combis);
858 struct nlattr *nl_bands, *nl_band;
859 struct nlattr *nl_freqs, *nl_freq;
860 struct nlattr *nl_rates, *nl_rate;
867 dev->wiphy.mgmt_stypes;
873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->
wiphy_idx) ||
878 dev->wiphy.retry_short) ||
880 dev->wiphy.retry_long) ||
882 dev->wiphy.frag_threshold) ||
884 dev->wiphy.rts_threshold) ||
886 dev->wiphy.coverage_class) ||
888 dev->wiphy.max_scan_ssids) ||
890 dev->wiphy.max_sched_scan_ssids) ||
892 dev->wiphy.max_scan_ie_len) ||
894 dev->wiphy.max_sched_scan_ie_len) ||
896 dev->wiphy.max_match_sets))
897 goto nla_put_failure;
901 goto nla_put_failure;
904 goto nla_put_failure;
907 goto nla_put_failure;
910 goto nla_put_failure;
913 goto nla_put_failure;
916 goto nla_put_failure;
919 sizeof(
u32) * dev->wiphy.n_cipher_suites,
920 dev->wiphy.cipher_suites))
921 goto nla_put_failure;
924 dev->wiphy.max_num_pmkids))
925 goto nla_put_failure;
929 goto nla_put_failure;
932 dev->wiphy.available_antennas_tx) ||
934 dev->wiphy.available_antennas_rx))
935 goto nla_put_failure;
939 dev->wiphy.probe_resp_offload))
940 goto nla_put_failure;
942 if ((dev->wiphy.available_antennas_tx ||
943 dev->wiphy.available_antennas_rx) && dev->
ops->get_antenna) {
944 u32 tx_ant = 0, rx_ant = 0;
946 res = dev->
ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
952 goto nla_put_failure;
957 dev->wiphy.interface_modes))
958 goto nla_put_failure;
962 goto nla_put_failure;
965 if (!dev->wiphy.bands[band])
968 nl_band = nla_nest_start(msg, band);
970 goto nla_put_failure;
973 if (dev->wiphy.bands[band]->ht_cap.ht_supported &&
975 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
976 &dev->wiphy.bands[band]->ht_cap.mcs) ||
978 dev->wiphy.bands[band]->ht_cap.cap) ||
980 dev->wiphy.bands[band]->ht_cap.ampdu_factor) ||
982 dev->wiphy.bands[band]->ht_cap.ampdu_density)))
983 goto nla_put_failure;
986 if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
988 sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
989 &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
991 dev->wiphy.bands[band]->vht_cap.cap)))
992 goto nla_put_failure;
997 goto nla_put_failure;
999 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
1000 nl_freq = nla_nest_start(msg, i);
1002 goto nla_put_failure;
1004 chan = &dev->wiphy.bands[band]->channels[
i];
1006 if (nl80211_msg_put_channel(msg, chan))
1007 goto nla_put_failure;
1009 nla_nest_end(msg, nl_freq);
1012 nla_nest_end(msg, nl_freqs);
1017 goto nla_put_failure;
1019 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
1020 nl_rate = nla_nest_start(msg, i);
1022 goto nla_put_failure;
1024 rate = &dev->wiphy.bands[band]->bitrates[
i];
1027 goto nla_put_failure;
1031 goto nla_put_failure;
1033 nla_nest_end(msg, nl_rate);
1036 nla_nest_end(msg, nl_rates);
1038 nla_nest_end(msg, nl_band);
1040 nla_nest_end(msg, nl_bands);
1044 goto nla_put_failure;
1047 #define CMD(op, n) \
1049 if (dev->ops->op) { \
1051 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1052 goto nla_put_failure; \
1056 CMD(add_virtual_intf, NEW_INTERFACE);
1058 CMD(add_key, NEW_KEY);
1060 CMD(add_station, NEW_STATION);
1061 CMD(add_mpath, NEW_MPATH);
1062 CMD(update_mesh_config, SET_MESH_CONFIG);
1063 CMD(change_bss, SET_BSS);
1065 CMD(assoc, ASSOCIATE);
1066 CMD(deauth, DEAUTHENTICATE);
1067 CMD(disassoc, DISASSOCIATE);
1068 CMD(join_ibss, JOIN_IBSS);
1069 CMD(join_mesh, JOIN_MESH);
1070 CMD(set_pmksa, SET_PMKSA);
1071 CMD(del_pmksa, DEL_PMKSA);
1072 CMD(flush_pmksa, FLUSH_PMKSA);
1074 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1075 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1076 CMD(mgmt_tx, FRAME);
1077 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1081 goto nla_put_failure;
1083 if (dev->
ops->set_monitor_channel || dev->
ops->start_ap ||
1084 dev->
ops->join_mesh) {
1087 goto nla_put_failure;
1089 CMD(set_wds_peer, SET_WDS_PEER);
1091 CMD(tdls_mgmt, TDLS_MGMT);
1092 CMD(tdls_oper, TDLS_OPER);
1095 CMD(sched_scan_start, START_SCHED_SCAN);
1096 CMD(probe_client, PROBE_CLIENT);
1097 CMD(set_noack_map, SET_NOACK_MAP);
1101 goto nla_put_failure;
1103 CMD(start_p2p_device, START_P2P_DEVICE);
1105 #ifdef CONFIG_NL80211_TESTMODE
1111 if (dev->
ops->connect || dev->
ops->auth) {
1114 goto nla_put_failure;
1117 if (dev->
ops->disconnect || dev->
ops->deauth) {
1120 goto nla_put_failure;
1123 nla_nest_end(msg, nl_cmds);
1125 if (dev->
ops->remain_on_channel &&
1128 dev->wiphy.max_remain_on_channel_duration))
1129 goto nla_put_failure;
1133 goto nla_put_failure;
1137 struct nlattr *nl_ftypes, *nl_ifs;
1142 goto nla_put_failure;
1145 nl_ftypes = nla_nest_start(msg, ift);
1147 goto nla_put_failure;
1149 stypes = mgmt_stypes[ift].
tx;
1154 goto nla_put_failure;
1158 nla_nest_end(msg, nl_ftypes);
1161 nla_nest_end(msg, nl_ifs);
1165 goto nla_put_failure;
1168 nl_ftypes = nla_nest_start(msg, ift);
1170 goto nla_put_failure;
1172 stypes = mgmt_stypes[ift].
rx;
1177 goto nla_put_failure;
1181 nla_nest_end(msg, nl_ftypes);
1183 nla_nest_end(msg, nl_ifs);
1187 if (dev->wiphy.
wowlan.flags || dev->wiphy.
wowlan.n_patterns) {
1188 struct nlattr *nl_wowlan;
1190 nl_wowlan = nla_nest_start(msg,
1193 goto nla_put_failure;
1211 goto nla_put_failure;
1212 if (dev->wiphy.
wowlan.n_patterns) {
1214 .max_patterns = dev->wiphy.
wowlan.n_patterns,
1216 dev->wiphy.
wowlan.pattern_min_len,
1218 dev->wiphy.
wowlan.pattern_max_len,
1222 goto nla_put_failure;
1225 nla_nest_end(msg, nl_wowlan);
1230 dev->wiphy.software_iftypes))
1231 goto nla_put_failure;
1233 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1234 goto nla_put_failure;
1238 dev->wiphy.ap_sme_capa))
1239 goto nla_put_failure;
1242 dev->wiphy.features))
1243 goto nla_put_failure;
1245 if (dev->wiphy.ht_capa_mod_mask &&
1247 sizeof(*dev->wiphy.ht_capa_mod_mask),
1248 dev->wiphy.ht_capa_mod_mask))
1249 goto nla_put_failure;
1251 return genlmsg_end(msg, hdr);
1254 genlmsg_cancel(msg, hdr);
1266 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->
sk)))
1298 return genlmsg_reply(msg, info);
1309 static int parse_txq_params(
struct nlattr *tb[],
1321 txq_params->
aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1329 static bool nl80211_can_set_dev_channel(
struct wireless_dev *wdev)
1353 static bool nl80211_valid_channel_type(
struct genl_info *info,
1369 *channel_type =
tmp;
1390 if (!nl80211_can_set_dev_channel(wdev))
1394 !nl80211_valid_channel_type(info, &channel_type))
1432 static int nl80211_set_channel(
struct sk_buff *skb,
struct genl_info *info)
1437 return __nl80211_set_channel(rdev, netdev->
ieee80211_ptr, info);
1440 static int nl80211_set_wds_peer(
struct sk_buff *skb,
struct genl_info *info)
1450 if (netif_running(dev))
1453 if (!rdev->
ops->set_wds_peer)
1460 return rdev->
ops->set_wds_peer(wdev->
wiphy, dev, bssid);
1469 int result = 0, rem_txq_params = 0;
1470 struct nlattr *nl_txq_params;
1487 if (info->
attrs[NL80211_ATTR_IFINDEX]) {
1488 int ifindex = nla_get_u32(info->
attrs[NL80211_ATTR_IFINDEX]);
1499 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1503 return PTR_ERR(rdev);
1510 }
else if (nl80211_can_set_dev_channel(netdev->
ieee80211_ptr))
1533 if (!rdev->
ops->set_txq_params) {
1549 if (!netif_running(netdev)) {
1558 nla_data(nl_txq_params),
1561 result = parse_txq_params(tb, &txq_params);
1565 result = rdev->
ops->set_txq_params(&rdev->wiphy,
1574 result = __nl80211_set_channel(rdev, wdev, info);
1583 if (!rdev->
ops->set_tx_power) {
1589 type = nla_get_u32(info->
attrs[idx]);
1599 mbm = nla_get_u32(info->
attrs[idx]);
1602 result = rdev->
ops->set_tx_power(&rdev->wiphy, type, mbm);
1610 if ((!rdev->wiphy.available_antennas_tx &&
1611 !rdev->wiphy.available_antennas_rx) ||
1612 !rdev->
ops->set_antenna) {
1622 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1623 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
1628 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1629 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
1631 result = rdev->
ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1639 retry_short = nla_get_u8(
1641 if (retry_short == 0) {
1659 frag_threshold = nla_get_u32(
1661 if (frag_threshold < 256) {
1665 if (frag_threshold != (
u32) -1) {
1672 frag_threshold &= ~0x1;
1678 rts_threshold = nla_get_u32(
1684 coverage_class = nla_get_u8(
1690 u8 old_retry_short, old_retry_long;
1691 u32 old_frag_threshold, old_rts_threshold;
1692 u8 old_coverage_class;
1694 if (!rdev->
ops->set_wiphy_params) {
1699 old_retry_short = rdev->wiphy.retry_short;
1700 old_retry_long = rdev->wiphy.retry_long;
1701 old_frag_threshold = rdev->wiphy.frag_threshold;
1702 old_rts_threshold = rdev->wiphy.rts_threshold;
1703 old_coverage_class = rdev->wiphy.coverage_class;
1706 rdev->wiphy.retry_short = retry_short;
1712 rdev->wiphy.rts_threshold = rts_threshold;
1716 result = rdev->
ops->set_wiphy_params(&rdev->wiphy, changed);
1718 rdev->wiphy.retry_short = old_retry_short;
1719 rdev->wiphy.retry_long = old_retry_long;
1720 rdev->wiphy.frag_threshold = old_frag_threshold;
1721 rdev->wiphy.rts_threshold = old_rts_threshold;
1722 rdev->wiphy.coverage_class = old_coverage_class;
1736 ((
u64)wiphy_to_dev(wdev->
wiphy)->wiphy_idx << 32);
1739 static int nl80211_send_iface(
struct sk_buff *msg,
u32 portid,
u32 seq,
int flags,
1751 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex) ||
1753 goto nla_put_failure;
1755 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
1757 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
1762 goto nla_put_failure;
1764 if (rdev->
ops->get_channel) {
1768 chan = rdev->
ops->get_channel(&rdev->wiphy, wdev,
1775 goto nla_put_failure;
1778 return genlmsg_end(msg, hdr);
1781 genlmsg_cancel(msg, hdr);
1789 int wp_start = cb->
args[0];
1790 int if_start = cb->
args[1];
1796 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->
sk)))
1798 if (wp_idx < wp_start) {
1806 if (if_idx < if_start) {
1825 cb->
args[0] = wp_idx;
1826 cb->
args[1] = if_idx;
1831 static int nl80211_get_interface(
struct sk_buff *skb,
struct genl_info *info)
1847 return genlmsg_reply(msg, info);
1858 static int parse_monitor_flags(
struct nlattr *
nla,
u32 *mntrflags)
1869 nla, mntr_flags_policy))
1874 *mntrflags |= (1<<
flag);
1905 static int nl80211_set_interface(
struct sk_buff *skb,
struct genl_info *info)
1913 bool change =
false;
1932 if (netif_running(dev))
1948 err = nl80211_valid_4addr(rdev, dev,
params.use_4addr, ntype);
1972 if (!err &&
params.use_4addr != -1)
1978 static int nl80211_new_interface(
struct sk_buff *skb,
struct genl_info *info)
1999 if (!rdev->
ops->add_virtual_intf ||
2000 !(rdev->wiphy.interface_modes & (1 << type)))
2005 err = nl80211_valid_4addr(rdev,
NULL,
params.use_4addr, type);
2017 wdev = rdev->
ops->add_virtual_intf(&rdev->wiphy,
2022 return PTR_ERR(wdev);
2065 return genlmsg_reply(msg, info);
2068 static int nl80211_del_interface(
struct sk_buff *skb,
struct genl_info *info)
2073 if (!rdev->
ops->del_virtual_intf)
2086 return rdev->
ops->del_virtual_intf(&rdev->wiphy, wdev);
2089 static int nl80211_set_noack_map(
struct sk_buff *skb,
struct genl_info *info)
2098 if (!rdev->
ops->set_noack_map)
2103 return rdev->
ops->set_noack_map(&rdev->wiphy, dev, noack_map);
2126 goto nla_put_failure;
2130 goto nla_put_failure;
2139 nla_put_u32(cookie->
msg, NL80211_KEY_CIPHER,
2141 goto nla_put_failure;
2144 goto nla_put_failure;
2146 nla_nest_end(cookie->
msg, key);
2187 if (!rdev->
ops->get_key)
2197 return PTR_ERR(hdr);
2200 cookie.
idx = key_idx;
2202 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex) ||
2204 goto nla_put_failure;
2207 goto nla_put_failure;
2209 if (pairwise && mac_addr &&
2213 err = rdev->
ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
2214 mac_addr, &cookie, get_key_callback);
2220 goto nla_put_failure;
2222 genlmsg_end(msg, hdr);
2223 return genlmsg_reply(msg, info);
2239 err = nl80211_parse_key(info, &key);
2247 if (!key.def && !key.defmgmt)
2253 if (!rdev->
ops->set_default_key) {
2262 err = rdev->
ops->set_default_key(&rdev->wiphy, dev, key.idx,
2263 key.def_uni, key.def_multi);
2268 #ifdef CONFIG_CFG80211_WEXT
2272 if (key.def_uni || !key.def_multi) {
2277 if (!rdev->
ops->set_default_mgmt_key) {
2286 err = rdev->
ops->set_default_mgmt_key(&rdev->wiphy,
2291 #ifdef CONFIG_CFG80211_WEXT
2308 const u8 *mac_addr =
NULL;
2310 err = nl80211_parse_key(info, &key);
2320 if (key.type == -1) {
2332 if (!rdev->
ops->add_key)
2343 err = rdev->
ops->add_key(&rdev->wiphy, dev, key.idx,
2359 err = nl80211_parse_key(info, &key);
2366 if (key.type == -1) {
2378 if (!rdev->
ops->del_key)
2389 err = rdev->
ops->del_key(&rdev->wiphy, dev, key.idx,
2393 #ifdef CONFIG_CFG80211_WEXT
2397 else if (key.idx == dev->
ieee80211_ptr->wext.default_mgmt_key)
2406 static int nl80211_parse_beacon(
struct genl_info *info,
2409 bool haveinfo =
false;
2417 memset(bcn, 0,
sizeof(*bcn));
2505 if (!rdev->
ops->start_ap)
2511 memset(¶ms, 0,
sizeof(params));
2519 err = nl80211_parse_beacon(info, ¶ms.
beacon);
2562 if (!nl80211_valid_auth_type(params.
auth_type))
2567 err = nl80211_crypto_settings(rdev, info, ¶ms.
crypto,
2583 !nl80211_valid_channel_type(info, &channel_type))
2595 }
else if (!nl80211_get_ap_channel(rdev, ¶ms))
2603 err = cfg80211_can_use_chan(rdev, wdev, params.
channel,
2610 err = rdev->
ops->start_ap(&rdev->wiphy, dev, ¶ms);
2632 if (!rdev->
ops->change_beacon)
2638 err = nl80211_parse_beacon(info, ¶ms);
2642 return rdev->
ops->change_beacon(&rdev->wiphy, dev, ¶ms);
2662 static int parse_station_flags(
struct genl_info *info,
2678 sta_flags = nla_data(nla);
2694 nla, sta_flags_policy))
2738 static bool nl80211_put_sta_rate(
struct sk_buff *msg,
struct rate_info *info,
2745 rate = nla_nest_start(msg, attr);
2747 goto nla_put_failure;
2752 bitrate_compat = bitrate < (1
UL << 16) ? bitrate : 0;
2755 (bitrate_compat > 0 &&
2763 goto nla_put_failure;
2765 nla_nest_end(msg, rate);
2772 static int nl80211_send_station(
struct sk_buff *msg,
u32 portid,
u32 seq,
2779 struct nlattr *sinfoattr, *bss_param;
2785 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex) ||
2788 goto nla_put_failure;
2792 goto nla_put_failure;
2796 goto nla_put_failure;
2800 goto nla_put_failure;
2804 goto nla_put_failure;
2808 goto nla_put_failure;
2811 goto nla_put_failure;
2814 goto nla_put_failure;
2818 goto nla_put_failure;
2819 switch (rdev->wiphy.signal_type) {
2824 goto nla_put_failure;
2828 goto nla_put_failure;
2834 if (!nl80211_put_sta_rate(msg, &sinfo->
txrate,
2836 goto nla_put_failure;
2839 if (!nl80211_put_sta_rate(msg, &sinfo->
rxrate,
2841 goto nla_put_failure;
2846 goto nla_put_failure;
2850 goto nla_put_failure;
2854 goto nla_put_failure;
2858 goto nla_put_failure;
2862 goto nla_put_failure;
2866 goto nla_put_failure;
2878 goto nla_put_failure;
2880 nla_nest_end(msg, bss_param);
2886 goto nla_put_failure;
2890 goto nla_put_failure;
2891 nla_nest_end(msg, sinfoattr);
2896 goto nla_put_failure;
2898 return genlmsg_end(msg, hdr);
2901 genlmsg_cancel(msg, hdr);
2905 static int nl80211_dump_station(
struct sk_buff *skb,
2912 int sta_idx = cb->
args[1];
2915 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2919 if (!dev->
ops->dump_station) {
2925 memset(&sinfo, 0,
sizeof(sinfo));
2926 err = dev->
ops->dump_station(&dev->wiphy, netdev, sta_idx,
2933 if (nl80211_send_station(skb,
2936 dev, netdev, mac_addr,
2945 cb->
args[1] = sta_idx;
2948 nl80211_finish_netdev_dump(dev);
2953 static int nl80211_get_station(
struct sk_buff *skb,
struct genl_info *info)
2962 memset(&sinfo, 0,
sizeof(sinfo));
2969 if (!rdev->
ops->get_station)
2972 err = rdev->
ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
2981 rdev, dev, mac_addr, &sinfo) < 0) {
2986 return genlmsg_reply(msg, info);
3011 if (!netif_running(v)) {
3019 return ERR_PTR(ret);
3022 static int nl80211_set_station(
struct sk_buff *skb,
struct genl_info *info)
3030 memset(¶ms, 0,
sizeof(params));
3058 if (!rdev->
ops->change_station)
3061 if (parse_station_flags(info, dev->
ieee80211_ptr->iftype, ¶ms))
3099 params.
vlan = get_vlan(info, rdev);
3100 if (IS_ERR(params.
vlan))
3101 return PTR_ERR(params.
vlan);
3149 err = rdev->
ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms);
3152 dev_put(params.
vlan);
3163 static int nl80211_new_station(
struct sk_buff *skb,
struct genl_info *info)
3171 memset(¶ms, 0,
sizeof(params));
3205 if (!rdev->
ops->add_station)
3208 if (parse_station_flags(info, dev->
ieee80211_ptr->iftype, ¶ms))
3224 nl80211_sta_wme_policy);
3230 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
3237 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3252 params.
vlan = get_vlan(info, rdev);
3253 if (IS_ERR(params.
vlan))
3254 return PTR_ERR(params.
vlan);
3278 err = rdev->
ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms);
3281 dev_put(params.
vlan);
3285 static int nl80211_del_station(
struct sk_buff *skb,
struct genl_info *info)
3300 if (!rdev->
ops->del_station)
3303 return rdev->
ops->del_station(&rdev->wiphy, dev, mac_addr);
3306 static int nl80211_send_mpath(
struct sk_buff *msg,
u32 portid,
u32 seq,
3312 struct nlattr *pinfoattr;
3318 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex) ||
3322 goto nla_put_failure;
3326 goto nla_put_failure;
3330 goto nla_put_failure;
3348 goto nla_put_failure;
3350 nla_nest_end(msg, pinfoattr);
3352 return genlmsg_end(msg, hdr);
3355 genlmsg_cancel(msg, hdr);
3359 static int nl80211_dump_mpath(
struct sk_buff *skb,
3367 int path_idx = cb->
args[1];
3370 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
3374 if (!dev->
ops->dump_mpath) {
3385 err = dev->
ops->dump_mpath(&dev->wiphy, netdev, path_idx,
3386 dst, next_hop, &pinfo);
3394 netdev, dst, next_hop,
3403 cb->
args[1] = path_idx;
3406 nl80211_finish_netdev_dump(dev);
3420 memset(&pinfo, 0,
sizeof(pinfo));
3427 if (!rdev->
ops->get_mpath)
3433 err = rdev->
ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
3442 dev, dst, next_hop, &pinfo) < 0) {
3447 return genlmsg_reply(msg, info);
3466 if (!rdev->
ops->change_mpath)
3472 return rdev->
ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
3491 if (!rdev->
ops->add_mpath)
3497 return rdev->
ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
3509 if (!rdev->
ops->del_mpath)
3512 return rdev->
ops->del_mpath(&rdev->wiphy, dev, dst);
3521 memset(¶ms, 0,
sizeof(params));
3523 params.use_cts_prot = -1;
3524 params.use_short_preamble = -1;
3525 params.use_short_slot_time = -1;
3526 params.ap_isolate = -1;
3527 params.ht_opmode = -1;
3530 params.use_cts_prot =
3533 params.use_short_preamble =
3536 params.use_short_slot_time =
3539 params.basic_rates =
3541 params.basic_rates_len =
3550 if (!rdev->
ops->change_bss)
3557 return rdev->
ops->change_bss(&rdev->wiphy, dev, ¶ms);
3569 static int parse_reg_rule(
struct nlattr *tb[],
3586 reg_rule->
flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3589 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3591 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3593 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3596 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3600 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3605 static int nl80211_req_set_reg(
struct sk_buff *skb,
struct genl_info *info)
3630 user_reg_hint_type =
3635 switch (user_reg_hint_type) {
3648 static int nl80211_get_mesh_config(
struct sk_buff *skb,
3657 struct nlattr *pinfoattr;
3663 if (!rdev->
ops->get_mesh_config)
3671 err = rdev->
ops->get_mesh_config(&rdev->wiphy, dev,
3688 goto nla_put_failure;
3689 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex) ||
3691 cur_params.dot11MeshRetryTimeout) ||
3693 cur_params.dot11MeshConfirmTimeout) ||
3695 cur_params.dot11MeshHoldingTimeout) ||
3697 cur_params.dot11MeshMaxPeerLinks) ||
3699 cur_params.dot11MeshMaxRetries) ||
3701 cur_params.dot11MeshTTL) ||
3703 cur_params.element_ttl) ||
3705 cur_params.auto_open_plinks) ||
3707 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
3709 cur_params.dot11MeshHWMPmaxPREQretries) ||
3711 cur_params.path_refresh_time) ||
3713 cur_params.min_discovery_timeout) ||
3715 cur_params.dot11MeshHWMPactivePathTimeout) ||
3717 cur_params.dot11MeshHWMPpreqMinInterval) ||
3719 cur_params.dot11MeshHWMPperrMinInterval) ||
3721 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
3723 cur_params.dot11MeshHWMPRootMode) ||
3725 cur_params.dot11MeshHWMPRannInterval) ||
3727 cur_params.dot11MeshGateAnnouncementProtocol) ||
3729 cur_params.dot11MeshForwarding) ||
3731 cur_params.rssi_threshold) ||
3733 cur_params.ht_opmode) ||
3735 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
3737 cur_params.dot11MeshHWMProotInterval) ||
3739 cur_params.dot11MeshHWMPconfirmationInterval))
3740 goto nla_put_failure;
3741 nla_nest_end(msg, pinfoattr);
3742 genlmsg_end(msg, hdr);
3743 return genlmsg_reply(msg, info);
3746 genlmsg_cancel(msg, hdr);
3791 static int nl80211_parse_mesh_config(
struct genl_info *info,
3798 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3800 if (table[attr_num]) {\
3801 cfg->param = nla_fn(table[attr_num]); \
3802 mask |= (1 << (attr_num - 1)); \
3811 nl80211_meshconf_params_policy))
3864 dot11MeshHWMPnetDiameterTraversalTime, mask,
3873 dot11MeshGateAnnouncementProtocol, mask,
3893 dot11MeshHWMPconfirmationInterval, mask,
3901 #undef FILL_IN_MESH_PARAM_IF_SET
3904 static int nl80211_parse_mesh_setup(
struct genl_info *info,
3913 nl80211_mesh_setup_params_policy))
3918 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
3924 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3930 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3938 if (!is_valid_ie_attr(ieattr))
3940 setup->
ie = nla_data(ieattr);
3949 static int nl80211_update_mesh_config(
struct sk_buff *skb,
3962 if (!rdev->
ops->update_mesh_config)
3965 err = nl80211_parse_mesh_config(info, &cfg, &mask);
3974 err = rdev->
ops->update_mesh_config(&rdev->wiphy, dev,
3986 struct nlattr *nl_reg_rules;
4011 goto nla_put_failure;
4016 goto nla_put_failure;
4020 goto nla_put_failure;
4023 struct nlattr *nl_reg_rule;
4032 nl_reg_rule = nla_nest_start(msg, i);
4034 goto nla_put_failure;
4036 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4038 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4040 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4042 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4046 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4048 goto nla_put_failure;
4050 nla_nest_end(msg, nl_reg_rule);
4053 nla_nest_end(msg, nl_reg_rules);
4055 genlmsg_end(msg, hdr);
4056 err = genlmsg_reply(msg, info);
4060 genlmsg_cancel(msg, hdr);
4072 struct nlattr *nl_reg_rule;
4073 char *alpha2 =
NULL;
4074 int rem_reg_rules = 0, r = 0;
4075 u32 num_rules = 0, rule_idx = 0, size_of_regd;
4114 rd->
alpha2[0] = alpha2[0];
4115 rd->
alpha2[1] = alpha2[1];
4127 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4129 r = parse_reg_rule(tb, &rd->
reg_rules[rule_idx]);
4141 BUG_ON(rule_idx != num_rules);
4155 static int validate_scan_freqs(
struct nlattr *freqs)
4157 struct nlattr *attr1, *attr2;
4158 int n_channels = 0,
tmp1, tmp2;
4172 if (attr1 != attr2 &&
4173 nla_get_u32(attr1) == nla_get_u32(attr2))
4186 struct wiphy *wiphy;
4187 int err,
tmp, n_ssids = 0, n_channels,
i;
4193 wiphy = &rdev->wiphy;
4195 if (!rdev->
ops->scan)
4202 n_channels = validate_scan_freqs(
4211 if (wiphy->
bands[band])
4212 n_channels += wiphy->
bands[band]->n_channels;
4230 request = kzalloc(
sizeof(*request)
4231 +
sizeof(*request->ssids) * n_ssids
4238 request->ssids = (
void *)&request->
channels[n_channels];
4239 request->n_ssids = n_ssids;
4242 request->
ie = (
void *)(request->
ssids + n_ssids);
4244 request->
ie = (
void *)(request->
channels + n_channels);
4253 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4273 if (!wiphy->
bands[band])
4275 for (j = 0; j < wiphy->
bands[
band]->n_channels; j++) {
4303 request->
ssids[
i].ssid_len = nla_len(attr);
4304 memcpy(request->
ssids[i].ssid, nla_data(attr), nla_len(attr));
4309 if (info->attrs[NL80211_ATTR_IE]) {
4310 request->
ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4312 nla_data(info->attrs[NL80211_ATTR_IE]),
4317 if (wiphy->
bands[i])
4319 (1 << wiphy->
bands[
i]->n_bitrates) - 1;
4327 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
4334 &request->
rates[band]);
4343 request->
wdev = wdev;
4344 request->
wiphy = &rdev->wiphy;
4347 err = rdev->
ops->scan(&rdev->wiphy, request);
4362 static int nl80211_start_sched_scan(
struct sk_buff *skb,
4369 struct wiphy *wiphy;
4370 int err,
tmp, n_ssids = 0, n_match_sets = 0, n_channels,
i;
4377 !rdev->
ops->sched_scan_start)
4380 if (!is_valid_ie_attr(info->
attrs[NL80211_ATTR_IE]))
4390 wiphy = &rdev->wiphy;
4393 n_channels = validate_scan_freqs(
4401 if (wiphy->
bands[band])
4402 n_channels += wiphy->
bands[band]->n_channels;
4410 if (n_ssids > wiphy->max_sched_scan_ssids)
4419 if (n_match_sets > wiphy->max_match_sets)
4422 if (info->attrs[NL80211_ATTR_IE])
4423 ie_len =
nla_len(info->attrs[NL80211_ATTR_IE]);
4427 if (ie_len > wiphy->max_sched_scan_ie_len)
4432 if (rdev->sched_scan_req) {
4437 request = kzalloc(
sizeof(*request)
4438 +
sizeof(*request->
ssids) * n_ssids
4439 +
sizeof(*request->
match_sets) * n_match_sets
4440 +
sizeof(*request->
channels) * n_channels
4441 + ie_len, GFP_KERNEL);
4452 request->
ie = (
void *)(request->
ssids + n_ssids);
4454 request->
ie = (
void *)(request->
channels + n_channels);
4460 else if (request->
ssids)
4462 (
void *)(request->
ssids + n_ssids);
4465 (
void *)(request->
channels + n_channels);
4477 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
4495 if (!wiphy->
bands[band])
4497 for (j = 0; j < wiphy->
bands[
band]->n_channels; j++) {
4526 request->
ssids[
i].ssid_len = nla_len(attr);
4541 nla_data(attr),
nla_len(attr),
4542 nl80211_match_policy);
4550 nla_data(ssid),
nla_len(ssid));
4564 if (info->
attrs[NL80211_ATTR_IE]) {
4567 nla_data(info->
attrs[NL80211_ATTR_IE]),
4572 request->
wiphy = &rdev->wiphy;
4575 err = rdev->
ops->sched_scan_start(&rdev->wiphy, dev, request);
4590 static int nl80211_stop_sched_scan(
struct sk_buff *skb,
4597 !rdev->
ops->sched_scan_stop)
4619 hdr = nl80211hdr_put(msg,
NETLINK_CB(cb->
skb).portid, seq, flags,
4624 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4627 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->
netdev->ifindex))
4628 goto nla_put_failure;
4632 goto nla_put_failure;
4633 if ((!is_zero_ether_addr(res->
bssid) &&
4643 goto nla_put_failure;
4646 goto nla_put_failure;
4649 goto nla_put_failure;
4654 goto nla_put_failure;
4656 switch (rdev->wiphy.signal_type) {
4659 goto nla_put_failure;
4663 goto nla_put_failure;
4675 goto nla_put_failure;
4681 goto nla_put_failure;
4687 nla_nest_end(msg, bss);
4689 return genlmsg_end(msg, hdr);
4692 genlmsg_cancel(msg, hdr);
4696 static int nl80211_dump_scan(
struct sk_buff *skb,
4703 int start = cb->
args[1], idx = 0;
4706 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4721 if (nl80211_send_bss(skb, cb,
4723 rdev, wdev, scan) < 0) {
4733 nl80211_finish_netdev_dump(rdev);
4738 static int nl80211_send_survey(
struct sk_buff *msg,
u32 portid,
u32 seq,
4745 hdr = nl80211hdr_put(msg, portid, seq, flags,
4750 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex))
4751 goto nla_put_failure;
4755 goto nla_put_failure;
4758 survey->
channel->center_freq))
4759 goto nla_put_failure;
4763 goto nla_put_failure;
4766 goto nla_put_failure;
4770 goto nla_put_failure;
4774 goto nla_put_failure;
4778 goto nla_put_failure;
4782 goto nla_put_failure;
4786 goto nla_put_failure;
4788 nla_nest_end(msg, infoattr);
4790 return genlmsg_end(msg, hdr);
4793 genlmsg_cancel(msg, hdr);
4797 static int nl80211_dump_survey(
struct sk_buff *skb,
4803 int survey_idx = cb->
args[1];
4806 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4810 if (!dev->
ops->dump_survey) {
4818 res = dev->
ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4831 chan = ieee80211_get_channel(&dev->wiphy,
4838 if (nl80211_send_survey(skb,
4848 cb->
args[1] = survey_idx;
4851 nl80211_finish_netdev_dump(dev);
4860 static bool nl80211_valid_wpa_versions(
u32 wpa_versions)
4866 static int nl80211_authenticate(
struct sk_buff *skb,
struct genl_info *info)
4872 int err, ssid_len, ie_len = 0;
4875 bool local_state_change;
4877 if (!is_valid_ie_attr(info->
attrs[NL80211_ATTR_IE]))
4892 err = nl80211_parse_key(info, &key);
4899 if (!key.p.key || !key.p.key_len)
4916 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4917 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4926 if (!rdev->
ops->auth)
4934 chan = ieee80211_get_channel(&rdev->wiphy,
4942 if (info->
attrs[NL80211_ATTR_IE]) {
4943 ie = nla_data(info->
attrs[NL80211_ATTR_IE]);
4944 ie_len = nla_len(info->
attrs[NL80211_ATTR_IE]);
4948 if (!nl80211_valid_auth_type(auth_type))
4957 if (local_state_change)
4961 ssid, ssid_len, ie, ie_len,
4962 key.p.key, key.p.key_len, key.idx);
4970 memset(settings, 0,
sizeof(*settings));
4976 proto = nla_get_u16(
4995 if (len %
sizeof(
u32))
5021 if (!nl80211_valid_wpa_versions(settings->
wpa_versions))
5033 if (len %
sizeof(
u32))
5052 int err, ssid_len, ie_len = 0;
5053 bool use_mfp =
false;
5058 if (!is_valid_ie_attr(info->
attrs[NL80211_ATTR_IE]))
5066 if (!rdev->
ops->assoc)
5075 chan = ieee80211_get_channel(&rdev->wiphy,
5083 if (info->
attrs[NL80211_ATTR_IE]) {
5084 ie = nla_data(info->
attrs[NL80211_ATTR_IE]);
5085 ie_len = nla_len(info->
attrs[NL80211_ATTR_IE]);
5113 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
5116 ssid, ssid_len, ie, ie_len, use_mfp,
5117 &crypto, flags, ht_capa,
5123 static int nl80211_deauthenticate(
struct sk_buff *skb,
struct genl_info *info)
5130 bool local_state_change;
5132 if (!is_valid_ie_attr(info->
attrs[NL80211_ATTR_IE]))
5141 if (!rdev->
ops->deauth)
5151 if (reason_code == 0) {
5156 if (info->
attrs[NL80211_ATTR_IE]) {
5157 ie = nla_data(info->
attrs[NL80211_ATTR_IE]);
5158 ie_len = nla_len(info->
attrs[NL80211_ATTR_IE]);
5164 local_state_change);
5167 static int nl80211_disassociate(
struct sk_buff *skb,
struct genl_info *info)
5174 bool local_state_change;
5176 if (!is_valid_ie_attr(info->
attrs[NL80211_ATTR_IE]))
5185 if (!rdev->
ops->disassoc)
5195 if (reason_code == 0) {
5200 if (info->
attrs[NL80211_ATTR_IE]) {
5201 ie = nla_data(info->
attrs[NL80211_ATTR_IE]);
5202 ie_len = nla_len(info->
attrs[NL80211_ATTR_IE]);
5208 local_state_change);
5213 int mcast_rate[IEEE80211_NUM_BANDS],
5216 struct wiphy *wiphy = &rdev->wiphy;
5228 if (sband->
bitrates[i].bitrate == rateval) {
5229 mcast_rate[
band] = i + 1;
5244 struct wiphy *wiphy;
5248 memset(&ibss, 0,
sizeof(ibss));
5250 if (!is_valid_ie_attr(info->
attrs[NL80211_ATTR_IE]))
5258 ibss.beacon_interval = 100;
5261 ibss.beacon_interval =
5263 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
5267 if (!rdev->
ops->join_ibss)
5273 wiphy = &rdev->wiphy;
5278 if (!is_valid_ether_addr(ibss.bssid))
5284 if (info->
attrs[NL80211_ATTR_IE]) {
5285 ibss.ie = nla_data(info->
attrs[NL80211_ATTR_IE]);
5286 ibss.ie_len = nla_len(info->
attrs[NL80211_ATTR_IE]);
5292 if (!nl80211_valid_channel_type(info, &channel_type))
5307 if (!ibss.channel ||
5328 wiphy->
bands[ibss.channel->band];
5337 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
5342 connkeys = nl80211_parse_connkeys(rdev,
5344 if (IS_ERR(connkeys))
5345 return PTR_ERR(connkeys);
5362 if (!rdev->
ops->leave_ibss)
5371 #ifdef CONFIG_NL80211_TESTMODE
5376 static int nl80211_testmode_do(
struct sk_buff *skb,
struct genl_info *info)
5385 if (rdev->
ops->testmode_cmd) {
5386 rdev->testmode_info =
info;
5387 err = rdev->
ops->testmode_cmd(&rdev->wiphy,
5390 rdev->testmode_info =
NULL;
5396 static int nl80211_testmode_dump(
struct sk_buff *skb,
5410 phy_idx = cb->
args[0] - 1;
5419 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->
sk),
5423 return PTR_ERR(rdev);
5435 data = nla_data((
void *)cb->
args[1]);
5436 data_len = nla_len((
void *)cb->
args[1]);
5445 cfg80211_lock_rdev(rdev);
5448 if (!rdev->
ops->testmode_dump) {
5459 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
5460 genlmsg_cancel(skb, hdr);
5466 genlmsg_cancel(skb, hdr);
5469 err = rdev->
ops->testmode_dump(&rdev->wiphy, skb, cb,
5471 nla_nest_end(skb, tmdata);
5474 genlmsg_cancel(skb, hdr);
5477 genlmsg_cancel(skb, hdr);
5481 genlmsg_end(skb, hdr);
5486 cb->
args[0] = phy_idx + 1;
5488 cfg80211_unlock_rdev(rdev);
5500 skb = nlmsg_new(approxlen + 100, gfp);
5510 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->
wiphy_idx))
5511 goto nla_put_failure;
5514 ((
void **)skb->cb)[0] =
rdev;
5515 ((
void **)skb->cb)[1] =
hdr;
5516 ((
void **)skb->cb)[2] =
data;
5525 struct sk_buff *cfg80211_testmode_alloc_reply_skb(
struct wiphy *wiphy,
5530 if (
WARN_ON(!rdev->testmode_info))
5533 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
5534 rdev->testmode_info->snd_portid,
5535 rdev->testmode_info->snd_seq,
5540 int cfg80211_testmode_reply(
struct sk_buff *skb)
5543 void *hdr = ((
void **)skb->cb)[1];
5544 struct nlattr *data = ((
void **)skb->cb)[2];
5546 if (
WARN_ON(!rdev->testmode_info)) {
5551 nla_nest_end(skb, data);
5552 genlmsg_end(skb, hdr);
5553 return genlmsg_reply(skb, rdev->testmode_info);
5557 struct sk_buff *cfg80211_testmode_alloc_event_skb(
struct wiphy *wiphy,
5558 int approxlen,
gfp_t gfp)
5562 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5566 void cfg80211_testmode_event(
struct sk_buff *skb,
gfp_t gfp)
5568 void *hdr = ((
void **)skb->cb)[1];
5569 struct nlattr *data = ((
void **)skb->cb)[2];
5571 nla_nest_end(skb, data);
5572 genlmsg_end(skb, hdr);
5573 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.
id, gfp);
5583 struct wiphy *wiphy;
5587 memset(&connect, 0,
sizeof(connect));
5589 if (!is_valid_ie_attr(info->
attrs[NL80211_ATTR_IE]))
5599 if (!nl80211_valid_auth_type(connect.auth_type))
5606 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
5615 wiphy = &rdev->wiphy;
5617 connect.bg_scan_period = -1;
5620 connect.bg_scan_period =
5629 if (info->
attrs[NL80211_ATTR_IE]) {
5630 connect.ie = nla_data(info->
attrs[NL80211_ATTR_IE]);
5631 connect.ie_len = nla_len(info->
attrs[NL80211_ATTR_IE]);
5636 ieee80211_get_channel(wiphy,
5638 if (!connect.channel ||
5644 connkeys = nl80211_parse_connkeys(rdev,
5646 if (IS_ERR(connkeys))
5647 return PTR_ERR(connkeys);
5654 memcpy(&connect.ht_capa_mask,
5656 sizeof(connect.ht_capa_mask));
5665 sizeof(connect.ht_capa));
5695 static int nl80211_wiphy_netns(
struct sk_buff *skb,
struct genl_info *info)
5709 return PTR_ERR(net);
5714 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5721 static int nl80211_setdel_pmksa(
struct sk_buff *skb,
struct genl_info *info)
5746 rdev_ops = rdev->
ops->set_pmksa;
5749 rdev_ops = rdev->
ops->del_pmksa;
5759 return rdev_ops(&rdev->wiphy, dev, &pmksa);
5762 static int nl80211_flush_pmksa(
struct sk_buff *skb,
struct genl_info *info)
5771 if (!rdev->
ops->flush_pmksa)
5774 return rdev->
ops->flush_pmksa(&rdev->wiphy, dev);
5786 !rdev->
ops->tdls_mgmt)
5792 !info->
attrs[NL80211_ATTR_IE] ||
5801 return rdev->
ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5802 dialog_token, status_code,
5803 nla_data(info->
attrs[NL80211_ATTR_IE]),
5804 nla_len(info->
attrs[NL80211_ATTR_IE]));
5815 !rdev->
ops->tdls_oper)
5825 return rdev->
ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5828 static int nl80211_remain_on_channel(
struct sk_buff *skb,
5847 if (!rdev->
ops->remain_on_channel ||
5856 duration > rdev->wiphy.max_remain_on_channel_duration)
5860 !nl80211_valid_channel_type(info, &channel_type))
5880 err = rdev->
ops->remain_on_channel(&rdev->wiphy, wdev, chan,
5881 channel_type, duration, &cookie);
5887 goto nla_put_failure;
5889 genlmsg_end(msg, hdr);
5891 return genlmsg_reply(msg, info);
5900 static int nl80211_cancel_remain_on_channel(
struct sk_buff *skb,
5910 if (!rdev->
ops->cancel_remain_on_channel)
5915 return rdev->
ops->cancel_remain_on_channel(&rdev->wiphy, wdev, cookie);
5919 u8 *rates,
u8 rates_len)
5924 for (i = 0; i < rates_len; i++) {
5925 int rate = (rates[
i] & 0x7f) * 5;
5927 for (ridx = 0; ridx < sband->
n_bitrates; ridx++) {
5943 u8 *rates,
u8 rates_len,
5948 memset(
mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
5950 for (i = 0; i < rates_len; i++) {
5953 ridx = rates[
i] / 8;
5954 rbit =
BIT(rates[i] % 8);
5957 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
5961 if (sband->
ht_cap.mcs.rx_mask[ridx] & rbit)
5977 static int nl80211_set_tx_bitrate_mask(
struct sk_buff *skb,
5991 if (!rdev->
ops->set_bitrate_mask)
5994 memset(&mask, 0,
sizeof(mask));
5997 sband = rdev->wiphy.bands[
i];
5998 mask.control[
i].legacy =
6001 memcpy(mask.control[i].mcs,
6002 sband->
ht_cap.mcs.rx_mask,
6003 sizeof(mask.control[i].mcs));
6005 memset(mask.control[i].mcs, 0,
6006 sizeof(mask.control[i].mcs));
6017 if (band < 0 || band >= IEEE80211_NUM_BANDS)
6019 sband = rdev->wiphy.bands[
band];
6023 nla_len(tx_rates), nl80211_txattr_policy);
6025 mask.control[
band].legacy = rateset_to_mask(
6027 nla_data(tb[NL80211_TXRATE_LEGACY]),
6028 nla_len(tb[NL80211_TXRATE_LEGACY]));
6029 if ((mask.control[band].legacy == 0) &&
6030 nla_len(tb[NL80211_TXRATE_LEGACY]))
6034 if (!ht_rateset_to_mask(
6036 nla_data(tb[NL80211_TXRATE_MCS]),
6037 nla_len(tb[NL80211_TXRATE_MCS]),
6038 mask.control[band].mcs))
6042 if (mask.control[band].legacy == 0) {
6045 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
6049 if (mask.control[band].mcs[i])
6053 if (i == IEEE80211_HT_MCS_MASK_LEN)
6058 return rdev->
ops->set_bitrate_mask(&rdev->wiphy, dev,
NULL, &mask);
6061 static int nl80211_register_mgmt(
struct sk_buff *skb,
struct genl_info *info)
6088 if (!rdev->
ops->mgmt_tx)
6102 bool channel_type_valid =
false;
6108 unsigned int wait = 0;
6109 bool offchan, no_cck, dont_wait_for_ack;
6117 if (!rdev->
ops->mgmt_tx)
6144 wait > rdev->wiphy.max_remain_on_channel_duration)
6150 if (!nl80211_valid_channel_type(info, &channel_type))
6152 channel_type_valid =
true;
6167 if (!dont_wait_for_ack) {
6182 channel_type_valid, wait,
6185 no_cck, dont_wait_for_ack, &cookie);
6191 goto nla_put_failure;
6193 genlmsg_end(msg, hdr);
6194 return genlmsg_reply(msg, info);
6206 static int nl80211_tx_mgmt_cancel_wait(
struct sk_buff *skb,
struct genl_info *info)
6215 if (!rdev->
ops->mgmt_tx_cancel_wait)
6233 return rdev->
ops->mgmt_tx_cancel_wait(&rdev->wiphy, wdev, cookie);
6236 static int nl80211_set_power_save(
struct sk_buff *skb,
struct genl_info *info)
6255 if (!rdev->
ops->set_power_mgmt)
6260 if (state == wdev->
ps)
6263 err = rdev->
ops->set_power_mgmt(wdev->
wiphy, dev, state,
6270 static int nl80211_get_power_save(
struct sk_buff *skb,
struct genl_info *info)
6282 if (!rdev->
ops->set_power_mgmt)
6302 goto nla_put_failure;
6304 genlmsg_end(msg, hdr);
6305 return genlmsg_reply(msg, info);
6324 static int nl80211_set_cqm_txe(
struct genl_info *info,
6331 if ((rate < 0 || rate > 100) ||
6337 if (!rdev->
ops->set_cqm_txe_config)
6344 return rdev->
ops->set_cqm_txe_config(wdev->
wiphy, dev,
6348 static int nl80211_set_cqm_rssi(
struct genl_info *info,
6360 if (!rdev->
ops->set_cqm_rssi_config)
6367 return rdev->
ops->set_cqm_rssi_config(wdev->
wiphy, dev,
6368 threshold, hysteresis);
6384 nl80211_attr_cqm_policy);
6393 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
6394 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
6401 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
6402 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
6424 err = nl80211_parse_mesh_config(info, &cfg,
NULL);
6437 !nl80211_parse_mcast_rate(rdev, setup.
mcast_rate,
6443 err = nl80211_parse_mesh_setup(info, &setup);
6452 !nl80211_valid_channel_type(info, &channel_type))
6484 if (!rdev->wiphy.
wowlan.flags && !rdev->wiphy.
wowlan.n_patterns)
6494 goto nla_put_failure;
6497 struct nlattr *nl_wowlan;
6501 goto nla_put_failure;
6503 if ((rdev->
wowlan->any &&
6505 (rdev->
wowlan->disconnect &&
6507 (rdev->
wowlan->magic_pkt &&
6509 (rdev->
wowlan->gtk_rekey_failure &&
6511 (rdev->
wowlan->eap_identity_req &&
6513 (rdev->
wowlan->four_way_handshake &&
6515 (rdev->
wowlan->rfkill_release &&
6517 goto nla_put_failure;
6518 if (rdev->
wowlan->n_patterns) {
6519 struct nlattr *nl_pats, *nl_pat;
6522 nl_pats = nla_nest_start(msg,
6525 goto nla_put_failure;
6527 for (i = 0; i < rdev->
wowlan->n_patterns; i++) {
6528 nl_pat = nla_nest_start(msg, i + 1);
6530 goto nla_put_failure;
6531 pat_len = rdev->
wowlan->patterns[
i].pattern_len;
6534 rdev->
wowlan->patterns[i].mask) ||
6537 rdev->
wowlan->patterns[i].pattern))
6538 goto nla_put_failure;
6539 nla_nest_end(msg, nl_pat);
6541 nla_nest_end(msg, nl_pats);
6544 nla_nest_end(msg, nl_wowlan);
6547 genlmsg_end(msg, hdr);
6548 return genlmsg_reply(msg, info);
6563 bool prev_enabled = rdev->
wowlan;
6565 if (!rdev->wiphy.
wowlan.flags && !rdev->wiphy.
wowlan.n_patterns)
6569 cfg80211_rdev_free_wowlan(rdev);
6577 nl80211_wowlan_policy);
6584 new_triggers.
any =
true;
6629 int rem, pat_len, mask_len;
6635 if (n_patterns > wowlan->n_patterns)
6638 new_triggers.patterns = kcalloc(n_patterns,
6639 sizeof(new_triggers.patterns[0]),
6641 if (!new_triggers.patterns)
6644 new_triggers.n_patterns = n_patterns;
6655 pat_len =
nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
6661 pat_len < wowlan->pattern_min_len)
6665 kmalloc(mask_len + pat_len, GFP_KERNEL);
6666 if (!new_triggers.
patterns[i].mask) {
6671 new_triggers.
patterns[
i].mask + mask_len;
6673 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
6675 new_triggers.
patterns[
i].pattern_len = pat_len;
6677 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
6683 ntrig =
kmemdup(&new_triggers,
sizeof(new_triggers), GFP_KERNEL);
6688 cfg80211_rdev_free_wowlan(rdev);
6692 if (rdev->
ops->set_wakeup && prev_enabled != !!rdev->
wowlan)
6693 rdev->
ops->set_wakeup(&rdev->wiphy, rdev->
wowlan);
6697 for (i = 0; i < new_triggers.
n_patterns; i++)
6704 static int nl80211_set_rekey_data(
struct sk_buff *skb,
struct genl_info *info)
6719 nl80211_rekey_policy);
6730 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6732 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6734 memcpy(rekey_data.replay_ctr,
6735 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6744 if (!rdev->
ops->set_rekey_data) {
6749 err = rdev->
ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6755 static int nl80211_register_unexpected_frame(
struct sk_buff *skb,
6772 static int nl80211_probe_client(
struct sk_buff *skb,
6791 if (!rdev->
ops->probe_client)
6808 err = rdev->
ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6813 goto nla_put_failure;
6815 genlmsg_end(msg, hdr);
6817 return genlmsg_reply(msg, info);
6826 static int nl80211_register_beacons(
struct sk_buff *skb,
struct genl_info *info)
6841 static int nl80211_start_p2p_device(
struct sk_buff *skb,
struct genl_info *info)
6847 if (!rdev->
ops->start_p2p_device)
6857 err = cfg80211_can_add_interface(rdev, wdev->
iftype);
6862 err = rdev->
ops->start_p2p_device(&rdev->wiphy, wdev);
6874 static int nl80211_stop_p2p_device(
struct sk_buff *skb,
struct genl_info *info)
6882 if (!rdev->
ops->stop_p2p_device)
6888 rdev->
ops->stop_p2p_device(&rdev->wiphy, wdev);
6903 #define NL80211_FLAG_NEED_WIPHY 0x01
6904 #define NL80211_FLAG_NEED_NETDEV 0x02
6905 #define NL80211_FLAG_NEED_RTNL 0x04
6906 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6907 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6908 NL80211_FLAG_CHECK_NETDEV_UP)
6909 #define NL80211_FLAG_NEED_WDEV 0x10
6911 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6912 NL80211_FLAG_CHECK_NETDEV_UP)
6914 static int nl80211_pre_doit(
struct genl_ops *ops,
struct sk_buff *skb,
6926 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6930 return PTR_ERR(rdev);
6936 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
6942 return PTR_ERR(wdev);
6946 rdev = wiphy_to_dev(wdev->
wiphy);
6963 !netif_running(dev)) {
6980 cfg80211_lock_rdev(rdev);
6990 static void nl80211_post_doit(
struct genl_ops *ops,
struct sk_buff *skb,
6994 cfg80211_unlock_rdev(info->
user_ptr[0]);
7009 static struct genl_ops nl80211_ops[] = {
7012 .doit = nl80211_get_wiphy,
7013 .dumpit = nl80211_dump_wiphy,
7014 .policy = nl80211_policy,
7020 .doit = nl80211_set_wiphy,
7021 .policy = nl80211_policy,
7027 .doit = nl80211_get_interface,
7028 .dumpit = nl80211_dump_interface,
7029 .policy = nl80211_policy,
7035 .doit = nl80211_set_interface,
7036 .policy = nl80211_policy,
7043 .doit = nl80211_new_interface,
7044 .policy = nl80211_policy,
7051 .doit = nl80211_del_interface,
7052 .policy = nl80211_policy,
7059 .doit = nl80211_get_key,
7060 .policy = nl80211_policy,
7067 .doit = nl80211_set_key,
7068 .policy = nl80211_policy,
7075 .doit = nl80211_new_key,
7076 .policy = nl80211_policy,
7083 .doit = nl80211_del_key,
7084 .policy = nl80211_policy,
7091 .policy = nl80211_policy,
7093 .doit = nl80211_set_beacon,
7099 .policy = nl80211_policy,
7101 .doit = nl80211_start_ap,
7107 .policy = nl80211_policy,
7109 .doit = nl80211_stop_ap,
7115 .doit = nl80211_get_station,
7116 .dumpit = nl80211_dump_station,
7117 .policy = nl80211_policy,
7123 .doit = nl80211_set_station,
7124 .policy = nl80211_policy,
7131 .doit = nl80211_new_station,
7132 .policy = nl80211_policy,
7139 .doit = nl80211_del_station,
7140 .policy = nl80211_policy,
7147 .doit = nl80211_get_mpath,
7148 .dumpit = nl80211_dump_mpath,
7149 .policy = nl80211_policy,
7156 .doit = nl80211_set_mpath,
7157 .policy = nl80211_policy,
7164 .doit = nl80211_new_mpath,
7165 .policy = nl80211_policy,
7172 .doit = nl80211_del_mpath,
7173 .policy = nl80211_policy,
7180 .doit = nl80211_set_bss,
7181 .policy = nl80211_policy,
7188 .doit = nl80211_get_reg,
7189 .policy = nl80211_policy,
7194 .doit = nl80211_set_reg,
7195 .policy = nl80211_policy,
7200 .doit = nl80211_req_set_reg,
7201 .policy = nl80211_policy,
7206 .doit = nl80211_get_mesh_config,
7207 .policy = nl80211_policy,
7214 .doit = nl80211_update_mesh_config,
7215 .policy = nl80211_policy,
7222 .doit = nl80211_trigger_scan,
7223 .policy = nl80211_policy,
7230 .policy = nl80211_policy,
7231 .dumpit = nl80211_dump_scan,
7235 .doit = nl80211_start_sched_scan,
7236 .policy = nl80211_policy,
7243 .doit = nl80211_stop_sched_scan,
7244 .policy = nl80211_policy,
7251 .doit = nl80211_authenticate,
7252 .policy = nl80211_policy,
7259 .doit = nl80211_associate,
7260 .policy = nl80211_policy,
7267 .doit = nl80211_deauthenticate,
7268 .policy = nl80211_policy,
7275 .doit = nl80211_disassociate,
7276 .policy = nl80211_policy,
7283 .doit = nl80211_join_ibss,
7284 .policy = nl80211_policy,
7291 .doit = nl80211_leave_ibss,
7292 .policy = nl80211_policy,
7297 #ifdef CONFIG_NL80211_TESTMODE
7300 .doit = nl80211_testmode_do,
7301 .dumpit = nl80211_testmode_dump,
7302 .policy = nl80211_policy,
7310 .doit = nl80211_connect,
7311 .policy = nl80211_policy,
7318 .doit = nl80211_disconnect,
7319 .policy = nl80211_policy,
7326 .doit = nl80211_wiphy_netns,
7327 .policy = nl80211_policy,
7334 .policy = nl80211_policy,
7335 .dumpit = nl80211_dump_survey,
7339 .doit = nl80211_setdel_pmksa,
7340 .policy = nl80211_policy,
7347 .doit = nl80211_setdel_pmksa,
7348 .policy = nl80211_policy,
7355 .doit = nl80211_flush_pmksa,
7356 .policy = nl80211_policy,
7363 .doit = nl80211_remain_on_channel,
7364 .policy = nl80211_policy,
7371 .doit = nl80211_cancel_remain_on_channel,
7372 .policy = nl80211_policy,
7379 .doit = nl80211_set_tx_bitrate_mask,
7380 .policy = nl80211_policy,
7387 .doit = nl80211_register_mgmt,
7388 .policy = nl80211_policy,
7395 .doit = nl80211_tx_mgmt,
7396 .policy = nl80211_policy,
7403 .doit = nl80211_tx_mgmt_cancel_wait,
7404 .policy = nl80211_policy,
7411 .doit = nl80211_set_power_save,
7412 .policy = nl80211_policy,
7419 .doit = nl80211_get_power_save,
7420 .policy = nl80211_policy,
7427 .doit = nl80211_set_cqm,
7428 .policy = nl80211_policy,
7435 .doit = nl80211_set_channel,
7436 .policy = nl80211_policy,
7443 .doit = nl80211_set_wds_peer,
7444 .policy = nl80211_policy,
7451 .doit = nl80211_join_mesh,
7452 .policy = nl80211_policy,
7459 .doit = nl80211_leave_mesh,
7460 .policy = nl80211_policy,
7468 .doit = nl80211_get_wowlan,
7469 .policy = nl80211_policy,
7476 .doit = nl80211_set_wowlan,
7477 .policy = nl80211_policy,
7485 .doit = nl80211_set_rekey_data,
7486 .policy = nl80211_policy,
7493 .doit = nl80211_tdls_mgmt,
7494 .policy = nl80211_policy,
7501 .doit = nl80211_tdls_oper,
7502 .policy = nl80211_policy,
7509 .doit = nl80211_register_unexpected_frame,
7510 .policy = nl80211_policy,
7517 .doit = nl80211_probe_client,
7518 .policy = nl80211_policy,
7525 .doit = nl80211_register_beacons,
7526 .policy = nl80211_policy,
7533 .doit = nl80211_set_noack_map,
7534 .policy = nl80211_policy,
7541 .doit = nl80211_start_p2p_device,
7542 .policy = nl80211_policy,
7549 .doit = nl80211_stop_p2p_device,
7550 .policy = nl80211_policy,
7569 .name =
"regulatory",
7582 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
7587 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7588 nl80211_config_mcgrp.
id, GFP_KERNEL);
7591 static int nl80211_add_scan_req(
struct sk_buff *msg,
7605 goto nla_put_failure;
7606 for (i = 0; i < req->
n_ssids; i++) {
7608 goto nla_put_failure;
7610 nla_nest_end(msg, nest);
7614 goto nla_put_failure;
7616 if (nla_put_u32(msg, i, req->
channels[i]->center_freq))
7617 goto nla_put_failure;
7619 nla_nest_end(msg, nest);
7623 goto nla_put_failure;
7630 static int nl80211_send_scan_msg(
struct sk_buff *msg,
7633 u32 portid,
u32 seq,
int flags,
7638 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
7642 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
7643 (wdev->
netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
7644 wdev->
netdev->ifindex)) ||
7645 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
7646 goto nla_put_failure;
7649 nl80211_add_scan_req(msg, rdev);
7651 return genlmsg_end(msg, hdr);
7654 genlmsg_cancel(msg, hdr);
7659 nl80211_send_sched_scan_msg(
struct sk_buff *msg,
7662 u32 portid,
u32 seq,
int flags,
u32 cmd)
7666 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
7670 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
7671 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex))
7672 goto nla_put_failure;
7674 return genlmsg_end(msg, hdr);
7677 genlmsg_cancel(msg, hdr);
7690 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
7696 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7697 nl80211_scan_mcgrp.
id, GFP_KERNEL);
7709 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
7715 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7716 nl80211_scan_mcgrp.
id, GFP_KERNEL);
7728 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
7734 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7735 nl80211_scan_mcgrp.
id, GFP_KERNEL);
7747 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
7753 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7754 nl80211_scan_mcgrp.
id, GFP_KERNEL);
7766 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
7771 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7772 nl80211_scan_mcgrp.
id, GFP_KERNEL);
7796 goto nla_put_failure;
7798 if (request->
alpha2[0] ==
'0' && request->
alpha2[1] ==
'0') {
7801 goto nla_put_failure;
7802 }
else if (request->
alpha2[0] ==
'9' && request->
alpha2[1] ==
'9') {
7805 goto nla_put_failure;
7806 }
else if ((request->
alpha2[0] ==
'9' && request->
alpha2[1] ==
'8') ||
7810 goto nla_put_failure;
7816 goto nla_put_failure;
7819 if (wiphy_idx_valid(request->
wiphy_idx) &&
7820 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->
wiphy_idx))
7821 goto nla_put_failure;
7823 genlmsg_end(msg, hdr);
7833 genlmsg_cancel(msg, hdr);
7839 const u8 *
buf,
size_t len,
7849 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7855 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
7856 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
7858 goto nla_put_failure;
7860 genlmsg_end(msg, hdr);
7862 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7863 nl80211_mlme_mcgrp.
id, gfp);
7867 genlmsg_cancel(msg, hdr);
7873 size_t len,
gfp_t gfp)
7875 nl80211_send_mlme_event(rdev, netdev, buf, len,
7881 size_t len,
gfp_t gfp)
7883 nl80211_send_mlme_event(rdev, netdev, buf, len,
7889 size_t len,
gfp_t gfp)
7891 nl80211_send_mlme_event(rdev, netdev, buf, len,
7897 size_t len,
gfp_t gfp)
7899 nl80211_send_mlme_event(rdev, netdev, buf, len,
7905 size_t len,
gfp_t gfp)
7907 nl80211_send_mlme_event(rdev, netdev, buf, len,
7913 size_t len,
gfp_t gfp)
7915 nl80211_send_mlme_event(rdev, netdev, buf, len,
7930 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7936 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
7937 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
7940 goto nla_put_failure;
7942 genlmsg_end(msg, hdr);
7944 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7945 nl80211_mlme_mcgrp.
id, gfp);
7949 genlmsg_cancel(msg, hdr);
7971 const u8 *req_ie,
size_t req_ie_len,
7972 const u8 *resp_ie,
size_t resp_ie_len,
7988 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
7989 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
7996 goto nla_put_failure;
7998 genlmsg_end(msg, hdr);
8000 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8001 nl80211_mlme_mcgrp.
id, gfp);
8005 genlmsg_cancel(msg, hdr);
8012 const u8 *req_ie,
size_t req_ie_len,
8013 const u8 *resp_ie,
size_t resp_ie_len,
gfp_t gfp)
8028 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8029 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
8035 goto nla_put_failure;
8037 genlmsg_end(msg, hdr);
8039 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8040 nl80211_mlme_mcgrp.
id, gfp);
8044 genlmsg_cancel(msg, hdr);
8051 const u8 *ie,
size_t ie_len,
bool from_ap)
8066 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8067 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
8068 (from_ap && reason &&
8072 (ie &&
nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
8073 goto nla_put_failure;
8075 genlmsg_end(msg, hdr);
8077 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8078 nl80211_mlme_mcgrp.
id, GFP_KERNEL);
8082 genlmsg_cancel(msg, hdr);
8104 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8105 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
8107 goto nla_put_failure;
8109 genlmsg_end(msg, hdr);
8111 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8112 nl80211_mlme_mcgrp.
id, gfp);
8116 genlmsg_cancel(msg, hdr);
8138 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8139 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
8142 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
8143 goto nla_put_failure;
8145 genlmsg_end(msg, hdr);
8147 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8148 nl80211_mlme_mcgrp.
id, gfp);
8152 genlmsg_cancel(msg, hdr);
8174 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8175 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
8181 goto nla_put_failure;
8183 genlmsg_end(msg, hdr);
8185 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8186 nl80211_mlme_mcgrp.
id, gfp);
8190 genlmsg_cancel(msg, hdr);
8216 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
get_wiphy_idx(wiphy)))
8217 goto nla_put_failure;
8222 goto nla_put_failure;
8223 if (nl80211_msg_put_channel(msg, channel_before))
8224 goto nla_put_failure;
8225 nla_nest_end(msg, nl_freq);
8230 goto nla_put_failure;
8231 if (nl80211_msg_put_channel(msg, channel_after))
8232 goto nla_put_failure;
8233 nla_nest_end(msg, nl_freq);
8235 genlmsg_end(msg, hdr);
8245 genlmsg_cancel(msg, hdr);
8249 static void nl80211_send_remain_on_chan_event(
8254 unsigned int duration,
gfp_t gfp)
8263 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8269 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8270 (wdev->
netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8271 wdev->
netdev->ifindex)) ||
8272 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
8276 goto nla_put_failure;
8280 goto nla_put_failure;
8282 genlmsg_end(msg, hdr);
8284 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8285 nl80211_mlme_mcgrp.
id, gfp);
8289 genlmsg_cancel(msg, hdr);
8297 unsigned int duration,
gfp_t gfp)
8300 rdev, wdev, cookie, chan,
8301 channel_type, duration, gfp);
8311 rdev, wdev, cookie, chan,
8312 channel_type, 0, gfp);
8325 if (nl80211_send_station(msg, 0, 0, 0,
8326 rdev, dev, mac_addr, sinfo) < 0) {
8331 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8332 nl80211_mlme_mcgrp.
id, gfp);
8352 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex) ||
8354 goto nla_put_failure;
8356 genlmsg_end(msg, hdr);
8358 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8359 nl80211_mlme_mcgrp.
id, gfp);
8363 genlmsg_cancel(msg, hdr);
8385 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex) ||
8388 goto nla_put_failure;
8390 genlmsg_end(msg, hdr);
8392 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8393 nl80211_mlme_mcgrp.
id, gfp);
8397 genlmsg_cancel(msg, hdr);
8401 static bool __nl80211_unexpected_frame(
struct net_device *dev,
u8 cmd,
8414 msg = nlmsg_new(100, gfp);
8418 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
8424 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8425 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex) ||
8427 goto nla_put_failure;
8429 err = genlmsg_end(msg, hdr);
8435 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
8439 genlmsg_cancel(msg, hdr);
8453 return __nl80211_unexpected_frame(dev,
8460 int freq,
int sig_dbm,
8461 const u8 *buf,
size_t len,
gfp_t gfp)
8477 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8478 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8484 goto nla_put_failure;
8486 genlmsg_end(msg, hdr);
8488 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
8491 genlmsg_cancel(msg, hdr);
8498 const u8 *buf,
size_t len,
bool ack,
8515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8516 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
8521 goto nla_put_failure;
8523 genlmsg_end(msg, hdr);
8525 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.
id, gfp);
8529 genlmsg_cancel(msg, hdr);
8540 struct nlattr *pinfoattr;
8553 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8554 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex))
8555 goto nla_put_failure;
8559 goto nla_put_failure;
8563 goto nla_put_failure;
8565 nla_nest_end(msg, pinfoattr);
8567 genlmsg_end(msg, hdr);
8569 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8570 nl80211_mlme_mcgrp.
id, gfp);
8574 genlmsg_cancel(msg, hdr);
8580 const u8 *replay_ctr,
gfp_t gfp)
8583 struct nlattr *rekey_attr;
8596 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8597 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
8599 goto nla_put_failure;
8603 goto nla_put_failure;
8605 if (
nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
8607 goto nla_put_failure;
8609 nla_nest_end(msg, rekey_attr);
8611 genlmsg_end(msg, hdr);
8613 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8614 nl80211_mlme_mcgrp.
id, gfp);
8618 genlmsg_cancel(msg, hdr);
8624 const u8 *bssid,
bool preauth,
gfp_t gfp)
8640 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8641 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex))
8642 goto nla_put_failure;
8646 goto nla_put_failure;
8652 goto nla_put_failure;
8654 nla_nest_end(msg, attr);
8656 genlmsg_end(msg, hdr);
8658 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8659 nl80211_mlme_mcgrp.
id, gfp);
8663 genlmsg_cancel(msg, hdr);
8684 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
8687 goto nla_put_failure;
8689 genlmsg_end(msg, hdr);
8691 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8692 nl80211_mlme_mcgrp.
id, gfp);
8696 genlmsg_cancel(msg, hdr);
8706 struct nlattr *pinfoattr;
8719 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8720 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
8722 goto nla_put_failure;
8726 goto nla_put_failure;
8729 goto nla_put_failure;
8732 goto nla_put_failure;
8735 goto nla_put_failure;
8737 nla_nest_end(msg, pinfoattr);
8739 genlmsg_end(msg, hdr);
8741 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8742 nl80211_mlme_mcgrp.
id, gfp);
8746 genlmsg_cancel(msg, hdr);
8756 struct nlattr *pinfoattr;
8769 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8770 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->
ifindex) ||
8772 goto nla_put_failure;
8776 goto nla_put_failure;
8779 goto nla_put_failure;
8781 nla_nest_end(msg, pinfoattr);
8783 genlmsg_end(msg, hdr);
8785 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8786 nl80211_mlme_mcgrp.
id, gfp);
8790 genlmsg_cancel(msg, hdr);
8813 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8814 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->
ifindex) ||
8818 goto nla_put_failure;
8820 err = genlmsg_end(msg, hdr);
8826 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8827 nl80211_mlme_mcgrp.
id, gfp);
8831 genlmsg_cancel(msg, hdr);
8838 int freq,
int sig_dbm,
gfp_t gfp)
8848 msg = nlmsg_new(len + 100, gfp);
8858 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->
wiphy_idx) ||
8864 goto nla_put_failure;
8866 genlmsg_end(msg, hdr);
8868 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
8872 genlmsg_cancel(msg, hdr);
8878 unsigned long state,
8885 if (state != NETLINK_URELEASE)
8890 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list,
list) {
8893 if (rdev->ap_beacons_nlportid == notify->portid)
8894 rdev->ap_beacons_nlportid = 0;
8933 #ifdef CONFIG_NL80211_TESTMODE