2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
26 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
27 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
28 struct genl_info *info,
29 struct cfg80211_crypto_settings *settings,
32 static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
33 struct genl_info *info);
34 static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
35 struct genl_info *info);
37 /* the netlink family */
38 static struct genl_family nl80211_fam = {
39 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
40 .name = "nl80211", /* have users key off the name instead */
41 .hdrsize = 0, /* no private header */
42 .version = 1, /* no particular meaning now */
43 .maxattr = NL80211_ATTR_MAX,
45 .pre_doit = nl80211_pre_doit,
46 .post_doit = nl80211_post_doit,
49 /* internal helper: get rdev and dev */
50 static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
51 struct cfg80211_registered_device **rdev,
52 struct net_device **dev)
56 if (!attrs[NL80211_ATTR_IFINDEX])
59 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
60 *dev = dev_get_by_index(netns, ifindex);
64 *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex);
67 return PTR_ERR(*rdev);
73 /* policy for the attributes */
74 static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
75 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
76 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
78 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
79 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
80 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
81 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
82 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
83 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
84 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
85 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
87 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
88 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
89 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
91 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
92 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
94 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
95 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
96 .len = WLAN_MAX_KEY_LEN },
97 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
98 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
99 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
100 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
101 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
103 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
104 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
105 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
106 .len = IEEE80211_MAX_DATA_LEN },
107 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
108 .len = IEEE80211_MAX_DATA_LEN },
109 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
110 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
111 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
112 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
113 .len = NL80211_MAX_SUPP_RATES },
114 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
115 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
116 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
117 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
118 .len = IEEE80211_MAX_MESH_ID_LEN },
119 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
121 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
122 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
124 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
125 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
126 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
127 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
128 .len = NL80211_MAX_SUPP_RATES },
129 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
131 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
132 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
134 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
136 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
137 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
138 .len = IEEE80211_MAX_DATA_LEN },
139 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
140 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
142 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
143 .len = IEEE80211_MAX_SSID_LEN },
144 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
145 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
146 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
147 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
148 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
149 [NL80211_ATTR_STA_FLAGS2] = {
150 .len = sizeof(struct nl80211_sta_flag_update),
152 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
153 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
154 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
155 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
156 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
157 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
158 [NL80211_ATTR_PID] = { .type = NLA_U32 },
159 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
160 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
161 .len = WLAN_PMKID_LEN },
162 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
163 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
164 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
165 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
166 .len = IEEE80211_MAX_DATA_LEN },
167 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
168 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
169 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
170 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
171 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
172 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
173 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
174 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
175 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
176 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
177 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
178 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
179 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
180 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
181 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
182 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
183 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
184 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
185 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
186 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
187 .len = IEEE80211_MAX_DATA_LEN },
188 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
189 .len = IEEE80211_MAX_DATA_LEN },
190 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
191 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
192 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
193 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
194 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
195 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
196 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
197 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
198 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
199 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
200 .len = IEEE80211_MAX_DATA_LEN },
201 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
202 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
203 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
204 .len = NL80211_HT_CAPABILITY_LEN
206 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
209 /* policy for the key attributes */
210 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
211 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
212 [NL80211_KEY_IDX] = { .type = NLA_U8 },
213 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
214 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
215 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
216 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
217 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
218 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
221 /* policy for the key default flags */
222 static const struct nla_policy
223 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
224 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
225 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
228 /* policy for WoWLAN attributes */
229 static const struct nla_policy
230 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
231 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
232 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
233 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
234 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
235 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
236 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
237 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
238 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
241 /* policy for GTK rekey offload attributes */
242 static const struct nla_policy
243 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
244 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
245 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
246 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
249 static const struct nla_policy
250 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
251 [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_SSID_LEN },
255 /* ifidx get helper */
256 static int nl80211_get_ifidx(struct netlink_callback *cb)
260 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
261 nl80211_fam.attrbuf, nl80211_fam.maxattr,
266 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
269 res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
275 static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
276 struct netlink_callback *cb,
277 struct cfg80211_registered_device **rdev,
278 struct net_device **dev)
280 int ifidx = cb->args[0];
284 ifidx = nl80211_get_ifidx(cb);
292 *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
298 *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
300 err = PTR_ERR(*rdev);
310 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
312 cfg80211_unlock_rdev(rdev);
317 static bool is_valid_ie_attr(const struct nlattr *attr)
325 pos = nla_data(attr);
346 /* message building helper */
347 static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
350 /* since there is no private header just add the generic one */
351 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
354 static int nl80211_msg_put_channel(struct sk_buff *msg,
355 struct ieee80211_channel *chan)
357 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
360 if (chan->flags & IEEE80211_CHAN_DISABLED)
361 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
362 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
363 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
364 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
365 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
366 if (chan->flags & IEEE80211_CHAN_RADAR)
367 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
369 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
370 DBM_TO_MBM(chan->max_power));
378 /* netlink command implementations */
385 bool def_uni, def_multi;
388 static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
390 struct nlattr *tb[NL80211_KEY_MAX + 1];
391 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
396 k->def = !!tb[NL80211_KEY_DEFAULT];
397 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
406 if (tb[NL80211_KEY_IDX])
407 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
409 if (tb[NL80211_KEY_DATA]) {
410 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
411 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
414 if (tb[NL80211_KEY_SEQ]) {
415 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
416 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
419 if (tb[NL80211_KEY_CIPHER])
420 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
422 if (tb[NL80211_KEY_TYPE]) {
423 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
424 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
428 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
429 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
430 int err = nla_parse_nested(kdt,
431 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
432 tb[NL80211_KEY_DEFAULT_TYPES],
433 nl80211_key_default_policy);
437 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
438 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
444 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
446 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
447 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
448 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
451 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
452 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
453 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
456 if (info->attrs[NL80211_ATTR_KEY_IDX])
457 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
459 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
460 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
462 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
463 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
472 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
473 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
474 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
478 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
479 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
480 int err = nla_parse_nested(
481 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
482 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
483 nl80211_key_default_policy);
487 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
488 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
494 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
498 memset(k, 0, sizeof(*k));
502 if (info->attrs[NL80211_ATTR_KEY])
503 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
505 err = nl80211_parse_key_old(info, k);
510 if (k->def && k->defmgmt)
514 if (k->def_uni || !k->def_multi)
520 if (k->idx < 4 || k->idx > 5)
523 if (k->idx < 0 || k->idx > 3)
526 if (k->idx < 0 || k->idx > 5)
534 static struct cfg80211_cached_keys *
535 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
538 struct key_parse parse;
540 struct cfg80211_cached_keys *result;
541 int rem, err, def = 0;
543 result = kzalloc(sizeof(*result), GFP_KERNEL);
545 return ERR_PTR(-ENOMEM);
548 result->defmgmt = -1;
550 nla_for_each_nested(key, keys, rem) {
551 memset(&parse, 0, sizeof(parse));
554 err = nl80211_parse_key_new(key, &parse);
560 if (parse.idx < 0 || parse.idx > 4)
566 result->def = parse.idx;
567 if (!parse.def_uni || !parse.def_multi)
569 } else if (parse.defmgmt)
571 err = cfg80211_validate_key_settings(rdev, &parse.p,
572 parse.idx, false, NULL);
575 result->params[parse.idx].cipher = parse.p.cipher;
576 result->params[parse.idx].key_len = parse.p.key_len;
577 result->params[parse.idx].key = result->data[parse.idx];
578 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
587 static int nl80211_key_allowed(struct wireless_dev *wdev)
589 ASSERT_WDEV_LOCK(wdev);
591 switch (wdev->iftype) {
592 case NL80211_IFTYPE_AP:
593 case NL80211_IFTYPE_AP_VLAN:
594 case NL80211_IFTYPE_P2P_GO:
595 case NL80211_IFTYPE_MESH_POINT:
597 case NL80211_IFTYPE_ADHOC:
598 if (!wdev->current_bss)
601 case NL80211_IFTYPE_STATION:
602 case NL80211_IFTYPE_P2P_CLIENT:
603 if (wdev->sme_state != CFG80211_SME_CONNECTED)
613 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
615 struct nlattr *nl_modes = nla_nest_start(msg, attr);
619 goto nla_put_failure;
624 NLA_PUT_FLAG(msg, i);
629 nla_nest_end(msg, nl_modes);
636 static int nl80211_put_iface_combinations(struct wiphy *wiphy,
639 struct nlattr *nl_combis;
642 nl_combis = nla_nest_start(msg,
643 NL80211_ATTR_INTERFACE_COMBINATIONS);
645 goto nla_put_failure;
647 for (i = 0; i < wiphy->n_iface_combinations; i++) {
648 const struct ieee80211_iface_combination *c;
649 struct nlattr *nl_combi, *nl_limits;
651 c = &wiphy->iface_combinations[i];
653 nl_combi = nla_nest_start(msg, i + 1);
655 goto nla_put_failure;
657 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
659 goto nla_put_failure;
661 for (j = 0; j < c->n_limits; j++) {
662 struct nlattr *nl_limit;
664 nl_limit = nla_nest_start(msg, j + 1);
666 goto nla_put_failure;
667 NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
669 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
671 goto nla_put_failure;
672 nla_nest_end(msg, nl_limit);
675 nla_nest_end(msg, nl_limits);
677 if (c->beacon_int_infra_match)
679 NL80211_IFACE_COMB_STA_AP_BI_MATCH);
680 NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
681 c->num_different_channels);
682 NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
685 nla_nest_end(msg, nl_combi);
688 nla_nest_end(msg, nl_combis);
695 static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
696 struct cfg80211_registered_device *dev)
699 struct nlattr *nl_bands, *nl_band;
700 struct nlattr *nl_freqs, *nl_freq;
701 struct nlattr *nl_rates, *nl_rate;
702 struct nlattr *nl_cmds;
703 enum ieee80211_band band;
704 struct ieee80211_channel *chan;
705 struct ieee80211_rate *rate;
707 const struct ieee80211_txrx_stypes *mgmt_stypes =
708 dev->wiphy.mgmt_stypes;
710 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
714 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
715 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
717 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
718 cfg80211_rdev_list_generation);
720 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
721 dev->wiphy.retry_short);
722 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
723 dev->wiphy.retry_long);
724 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
725 dev->wiphy.frag_threshold);
726 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
727 dev->wiphy.rts_threshold);
728 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
729 dev->wiphy.coverage_class);
730 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
731 dev->wiphy.max_scan_ssids);
732 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
733 dev->wiphy.max_sched_scan_ssids);
734 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
735 dev->wiphy.max_scan_ie_len);
736 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
737 dev->wiphy.max_sched_scan_ie_len);
738 NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS,
739 dev->wiphy.max_match_sets);
741 if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
742 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
743 if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
744 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
745 if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD)
746 NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD);
747 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)
748 NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT);
749 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)
750 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT);
751 if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)
752 NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP);
754 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
755 sizeof(u32) * dev->wiphy.n_cipher_suites,
756 dev->wiphy.cipher_suites);
758 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
759 dev->wiphy.max_num_pmkids);
761 if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
762 NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
764 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
765 dev->wiphy.available_antennas_tx);
766 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
767 dev->wiphy.available_antennas_rx);
769 if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD)
770 NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
771 dev->wiphy.probe_resp_offload);
773 if ((dev->wiphy.available_antennas_tx ||
774 dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
775 u32 tx_ant = 0, rx_ant = 0;
777 res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
779 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
780 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
784 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
785 dev->wiphy.interface_modes))
786 goto nla_put_failure;
788 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
790 goto nla_put_failure;
792 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
793 if (!dev->wiphy.bands[band])
796 nl_band = nla_nest_start(msg, band);
798 goto nla_put_failure;
801 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
802 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
803 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
804 &dev->wiphy.bands[band]->ht_cap.mcs);
805 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
806 dev->wiphy.bands[band]->ht_cap.cap);
807 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
808 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
809 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
810 dev->wiphy.bands[band]->ht_cap.ampdu_density);
813 /* add frequencies */
814 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
816 goto nla_put_failure;
818 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
819 nl_freq = nla_nest_start(msg, i);
821 goto nla_put_failure;
823 chan = &dev->wiphy.bands[band]->channels[i];
825 if (nl80211_msg_put_channel(msg, chan))
826 goto nla_put_failure;
828 nla_nest_end(msg, nl_freq);
831 nla_nest_end(msg, nl_freqs);
834 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
836 goto nla_put_failure;
838 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
839 nl_rate = nla_nest_start(msg, i);
841 goto nla_put_failure;
843 rate = &dev->wiphy.bands[band]->bitrates[i];
844 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
846 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
848 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
850 nla_nest_end(msg, nl_rate);
853 nla_nest_end(msg, nl_rates);
855 nla_nest_end(msg, nl_band);
857 nla_nest_end(msg, nl_bands);
859 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
861 goto nla_put_failure;
866 if (dev->ops->op) { \
868 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
872 CMD(add_virtual_intf, NEW_INTERFACE);
873 CMD(change_virtual_intf, SET_INTERFACE);
874 CMD(add_key, NEW_KEY);
875 CMD(add_beacon, NEW_BEACON);
876 CMD(add_station, NEW_STATION);
877 CMD(add_mpath, NEW_MPATH);
878 CMD(update_mesh_config, SET_MESH_CONFIG);
879 CMD(change_bss, SET_BSS);
880 CMD(auth, AUTHENTICATE);
881 CMD(assoc, ASSOCIATE);
882 CMD(deauth, DEAUTHENTICATE);
883 CMD(disassoc, DISASSOCIATE);
884 CMD(join_ibss, JOIN_IBSS);
885 CMD(join_mesh, JOIN_MESH);
886 CMD(set_pmksa, SET_PMKSA);
887 CMD(del_pmksa, DEL_PMKSA);
888 CMD(flush_pmksa, FLUSH_PMKSA);
889 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
890 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
891 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
893 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
894 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
896 NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
898 CMD(set_channel, SET_CHANNEL);
899 CMD(set_wds_peer, SET_WDS_PEER);
900 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
901 CMD(tdls_mgmt, TDLS_MGMT);
902 CMD(tdls_oper, TDLS_OPER);
904 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
905 CMD(sched_scan_start, START_SCHED_SCAN);
906 CMD(probe_client, PROBE_CLIENT);
907 CMD(set_noack_map, SET_NOACK_MAP);
908 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
910 NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS);
913 #ifdef CONFIG_NL80211_TESTMODE
914 CMD(testmode_cmd, TESTMODE);
919 if (dev->ops->connect || dev->ops->auth) {
921 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
924 if (dev->ops->disconnect || dev->ops->deauth) {
926 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
929 nla_nest_end(msg, nl_cmds);
931 if (dev->ops->remain_on_channel &&
932 dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
933 NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
934 dev->wiphy.max_remain_on_channel_duration);
936 if (dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)
937 NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
941 struct nlattr *nl_ftypes, *nl_ifs;
942 enum nl80211_iftype ift;
944 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
946 goto nla_put_failure;
948 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
949 nl_ftypes = nla_nest_start(msg, ift);
951 goto nla_put_failure;
953 stypes = mgmt_stypes[ift].tx;
956 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
957 (i << 4) | IEEE80211_FTYPE_MGMT);
961 nla_nest_end(msg, nl_ftypes);
964 nla_nest_end(msg, nl_ifs);
966 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
968 goto nla_put_failure;
970 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
971 nl_ftypes = nla_nest_start(msg, ift);
973 goto nla_put_failure;
975 stypes = mgmt_stypes[ift].rx;
978 NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
979 (i << 4) | IEEE80211_FTYPE_MGMT);
983 nla_nest_end(msg, nl_ftypes);
985 nla_nest_end(msg, nl_ifs);
988 if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
989 struct nlattr *nl_wowlan;
991 nl_wowlan = nla_nest_start(msg,
992 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
994 goto nla_put_failure;
996 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
997 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
998 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
999 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
1000 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
1001 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
1002 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)
1003 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED);
1004 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)
1005 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
1006 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)
1007 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
1008 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)
1009 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
1010 if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE)
1011 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
1012 if (dev->wiphy.wowlan.n_patterns) {
1013 struct nl80211_wowlan_pattern_support pat = {
1014 .max_patterns = dev->wiphy.wowlan.n_patterns,
1016 dev->wiphy.wowlan.pattern_min_len,
1018 dev->wiphy.wowlan.pattern_max_len,
1020 NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1024 nla_nest_end(msg, nl_wowlan);
1027 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1028 dev->wiphy.software_iftypes))
1029 goto nla_put_failure;
1031 if (nl80211_put_iface_combinations(&dev->wiphy, msg))
1032 goto nla_put_failure;
1034 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME)
1035 NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME,
1036 dev->wiphy.ap_sme_capa);
1038 NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features);
1040 if (dev->wiphy.ht_capa_mod_mask)
1041 NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1042 sizeof(*dev->wiphy.ht_capa_mod_mask),
1043 dev->wiphy.ht_capa_mod_mask);
1045 return genlmsg_end(msg, hdr);
1048 genlmsg_cancel(msg, hdr);
1052 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1055 int start = cb->args[0];
1056 struct cfg80211_registered_device *dev;
1058 mutex_lock(&cfg80211_mutex);
1059 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
1060 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1064 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
1065 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1071 mutex_unlock(&cfg80211_mutex);
1078 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1080 struct sk_buff *msg;
1081 struct cfg80211_registered_device *dev = info->user_ptr[0];
1083 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1087 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
1092 return genlmsg_reply(msg, info);
1095 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1096 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1097 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1098 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1099 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1100 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1103 static int parse_txq_params(struct nlattr *tb[],
1104 struct ieee80211_txq_params *txq_params)
1106 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
1107 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1108 !tb[NL80211_TXQ_ATTR_AIFS])
1111 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
1112 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1113 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1114 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1115 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1120 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1123 * You can only set the channel explicitly for AP, mesh
1124 * and WDS type interfaces; all others have their channel
1125 * managed via their respective "establish a connection"
1126 * command (connect, join, ...)
1128 * Monitors are special as they are normally slaved to
1129 * whatever else is going on, so they behave as though
1130 * you tried setting the wiphy channel itself.
1133 wdev->iftype == NL80211_IFTYPE_AP ||
1134 wdev->iftype == NL80211_IFTYPE_WDS ||
1135 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
1136 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1137 wdev->iftype == NL80211_IFTYPE_P2P_GO;
1140 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1141 struct wireless_dev *wdev,
1142 struct genl_info *info)
1144 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1148 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1151 if (!nl80211_can_set_dev_channel(wdev))
1154 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1155 channel_type = nla_get_u32(info->attrs[
1156 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1157 if (channel_type != NL80211_CHAN_NO_HT &&
1158 channel_type != NL80211_CHAN_HT20 &&
1159 channel_type != NL80211_CHAN_HT40PLUS &&
1160 channel_type != NL80211_CHAN_HT40MINUS)
1164 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1166 mutex_lock(&rdev->devlist_mtx);
1169 result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
1172 result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
1174 mutex_unlock(&rdev->devlist_mtx);
1179 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1182 struct net_device *netdev = info->user_ptr[1];
1184 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
1187 static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1189 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1190 struct net_device *dev = info->user_ptr[1];
1191 struct wireless_dev *wdev = dev->ieee80211_ptr;
1194 if (!info->attrs[NL80211_ATTR_MAC])
1197 if (netif_running(dev))
1200 if (!rdev->ops->set_wds_peer)
1203 if (wdev->iftype != NL80211_IFTYPE_WDS)
1206 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
1207 return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
1211 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1213 struct cfg80211_registered_device *rdev;
1214 struct net_device *netdev = NULL;
1215 struct wireless_dev *wdev;
1216 int result = 0, rem_txq_params = 0;
1217 struct nlattr *nl_txq_params;
1219 u8 retry_short = 0, retry_long = 0;
1220 u32 frag_threshold = 0, rts_threshold = 0;
1221 u8 coverage_class = 0;
1224 * Try to find the wiphy and netdev. Normally this
1225 * function shouldn't need the netdev, but this is
1226 * done for backward compatibility -- previously
1227 * setting the channel was done per wiphy, but now
1228 * it is per netdev. Previous userland like hostapd
1229 * also passed a netdev to set_wiphy, so that it is
1230 * possible to let that go to the right netdev!
1232 mutex_lock(&cfg80211_mutex);
1234 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1235 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1237 netdev = dev_get_by_index(genl_info_net(info), ifindex);
1238 if (netdev && netdev->ieee80211_ptr) {
1239 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
1240 mutex_lock(&rdev->mtx);
1246 rdev = __cfg80211_rdev_from_info(info);
1248 mutex_unlock(&cfg80211_mutex);
1249 return PTR_ERR(rdev);
1255 mutex_lock(&rdev->mtx);
1256 } else if (netif_running(netdev) &&
1257 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1258 wdev = netdev->ieee80211_ptr;
1263 * end workaround code, by now the rdev is available
1264 * and locked, and wdev may or may not be NULL.
1267 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
1268 result = cfg80211_dev_rename(
1269 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
1271 mutex_unlock(&cfg80211_mutex);
1276 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1277 struct ieee80211_txq_params txq_params;
1278 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1280 if (!rdev->ops->set_txq_params) {
1281 result = -EOPNOTSUPP;
1290 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1291 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1296 nla_for_each_nested(nl_txq_params,
1297 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1299 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1300 nla_data(nl_txq_params),
1301 nla_len(nl_txq_params),
1303 result = parse_txq_params(tb, &txq_params);
1307 result = rdev->ops->set_txq_params(&rdev->wiphy,
1315 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
1316 result = __nl80211_set_channel(rdev, wdev, info);
1321 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
1322 enum nl80211_tx_power_setting type;
1325 if (!rdev->ops->set_tx_power) {
1326 result = -EOPNOTSUPP;
1330 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1331 type = nla_get_u32(info->attrs[idx]);
1333 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1334 (type != NL80211_TX_POWER_AUTOMATIC)) {
1339 if (type != NL80211_TX_POWER_AUTOMATIC) {
1340 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1341 mbm = nla_get_u32(info->attrs[idx]);
1344 result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
1349 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1350 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1352 if ((!rdev->wiphy.available_antennas_tx &&
1353 !rdev->wiphy.available_antennas_rx) ||
1354 !rdev->ops->set_antenna) {
1355 result = -EOPNOTSUPP;
1359 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1360 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1362 /* reject antenna configurations which don't match the
1363 * available antenna masks, except for the "all" mask */
1364 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1365 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
1370 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1371 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
1373 result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
1380 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1381 retry_short = nla_get_u8(
1382 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1383 if (retry_short == 0) {
1387 changed |= WIPHY_PARAM_RETRY_SHORT;
1390 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1391 retry_long = nla_get_u8(
1392 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1393 if (retry_long == 0) {
1397 changed |= WIPHY_PARAM_RETRY_LONG;
1400 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
1401 frag_threshold = nla_get_u32(
1402 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
1403 if (frag_threshold < 256) {
1407 if (frag_threshold != (u32) -1) {
1409 * Fragments (apart from the last one) are required to
1410 * have even length. Make the fragmentation code
1411 * simpler by stripping LSB should someone try to use
1412 * odd threshold value.
1414 frag_threshold &= ~0x1;
1416 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
1419 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
1420 rts_threshold = nla_get_u32(
1421 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
1422 changed |= WIPHY_PARAM_RTS_THRESHOLD;
1425 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
1426 coverage_class = nla_get_u8(
1427 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
1428 changed |= WIPHY_PARAM_COVERAGE_CLASS;
1432 u8 old_retry_short, old_retry_long;
1433 u32 old_frag_threshold, old_rts_threshold;
1434 u8 old_coverage_class;
1436 if (!rdev->ops->set_wiphy_params) {
1437 result = -EOPNOTSUPP;
1441 old_retry_short = rdev->wiphy.retry_short;
1442 old_retry_long = rdev->wiphy.retry_long;
1443 old_frag_threshold = rdev->wiphy.frag_threshold;
1444 old_rts_threshold = rdev->wiphy.rts_threshold;
1445 old_coverage_class = rdev->wiphy.coverage_class;
1447 if (changed & WIPHY_PARAM_RETRY_SHORT)
1448 rdev->wiphy.retry_short = retry_short;
1449 if (changed & WIPHY_PARAM_RETRY_LONG)
1450 rdev->wiphy.retry_long = retry_long;
1451 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
1452 rdev->wiphy.frag_threshold = frag_threshold;
1453 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
1454 rdev->wiphy.rts_threshold = rts_threshold;
1455 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
1456 rdev->wiphy.coverage_class = coverage_class;
1458 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
1460 rdev->wiphy.retry_short = old_retry_short;
1461 rdev->wiphy.retry_long = old_retry_long;
1462 rdev->wiphy.frag_threshold = old_frag_threshold;
1463 rdev->wiphy.rts_threshold = old_rts_threshold;
1464 rdev->wiphy.coverage_class = old_coverage_class;
1469 mutex_unlock(&rdev->mtx);
1476 static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
1477 struct cfg80211_registered_device *rdev,
1478 struct net_device *dev)
1482 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
1486 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1487 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
1488 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
1489 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
1491 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
1492 rdev->devlist_generation ^
1493 (cfg80211_rdev_list_generation << 2));
1495 return genlmsg_end(msg, hdr);
1498 genlmsg_cancel(msg, hdr);
1502 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
1506 int wp_start = cb->args[0];
1507 int if_start = cb->args[1];
1508 struct cfg80211_registered_device *rdev;
1509 struct wireless_dev *wdev;
1511 mutex_lock(&cfg80211_mutex);
1512 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1513 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
1515 if (wp_idx < wp_start) {
1521 mutex_lock(&rdev->devlist_mtx);
1522 list_for_each_entry(wdev, &rdev->netdev_list, list) {
1523 if (if_idx < if_start) {
1527 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
1528 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1529 rdev, wdev->netdev) < 0) {
1530 mutex_unlock(&rdev->devlist_mtx);
1535 mutex_unlock(&rdev->devlist_mtx);
1540 mutex_unlock(&cfg80211_mutex);
1542 cb->args[0] = wp_idx;
1543 cb->args[1] = if_idx;
1548 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
1550 struct sk_buff *msg;
1551 struct cfg80211_registered_device *dev = info->user_ptr[0];
1552 struct net_device *netdev = info->user_ptr[1];
1554 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1558 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
1564 return genlmsg_reply(msg, info);
1567 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
1568 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
1569 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
1570 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
1571 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
1572 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
1575 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
1577 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
1585 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
1586 nla, mntr_flags_policy))
1589 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
1591 *mntrflags |= (1<<flag);
1596 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
1597 struct net_device *netdev, u8 use_4addr,
1598 enum nl80211_iftype iftype)
1601 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
1607 case NL80211_IFTYPE_AP_VLAN:
1608 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
1611 case NL80211_IFTYPE_STATION:
1612 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
1622 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1625 struct vif_params params;
1627 enum nl80211_iftype otype, ntype;
1628 struct net_device *dev = info->user_ptr[1];
1629 u32 _flags, *flags = NULL;
1630 bool change = false;
1632 memset(¶ms, 0, sizeof(params));
1634 otype = ntype = dev->ieee80211_ptr->iftype;
1636 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1637 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1640 if (ntype > NL80211_IFTYPE_MAX)
1644 if (info->attrs[NL80211_ATTR_MESH_ID]) {
1645 struct wireless_dev *wdev = dev->ieee80211_ptr;
1647 if (ntype != NL80211_IFTYPE_MESH_POINT)
1649 if (netif_running(dev))
1653 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1654 IEEE80211_MAX_MESH_ID_LEN);
1655 wdev->mesh_id_up_len =
1656 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1657 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1658 wdev->mesh_id_up_len);
1662 if (info->attrs[NL80211_ATTR_4ADDR]) {
1663 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1665 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
1669 params.use_4addr = -1;
1672 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
1673 if (ntype != NL80211_IFTYPE_MONITOR)
1675 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
1685 err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms);
1689 if (!err && params.use_4addr != -1)
1690 dev->ieee80211_ptr->use_4addr = params.use_4addr;
1695 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1698 struct vif_params params;
1699 struct net_device *dev;
1701 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
1704 memset(¶ms, 0, sizeof(params));
1706 if (!info->attrs[NL80211_ATTR_IFNAME])
1709 if (info->attrs[NL80211_ATTR_IFTYPE]) {
1710 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
1711 if (type > NL80211_IFTYPE_MAX)
1715 if (!rdev->ops->add_virtual_intf ||
1716 !(rdev->wiphy.interface_modes & (1 << type)))
1719 if (info->attrs[NL80211_ATTR_4ADDR]) {
1720 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1721 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
1726 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1727 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1729 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
1730 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
1731 type, err ? NULL : &flags, ¶ms);
1733 return PTR_ERR(dev);
1735 if (type == NL80211_IFTYPE_MESH_POINT &&
1736 info->attrs[NL80211_ATTR_MESH_ID]) {
1737 struct wireless_dev *wdev = dev->ieee80211_ptr;
1740 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1741 IEEE80211_MAX_MESH_ID_LEN);
1742 wdev->mesh_id_up_len =
1743 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1744 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1745 wdev->mesh_id_up_len);
1752 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
1754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1755 struct net_device *dev = info->user_ptr[1];
1757 if (!rdev->ops->del_virtual_intf)
1760 return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
1763 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
1765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1766 struct net_device *dev = info->user_ptr[1];
1769 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
1772 if (!rdev->ops->set_noack_map)
1775 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
1777 return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
1780 struct get_key_cookie {
1781 struct sk_buff *msg;
1786 static void get_key_callback(void *c, struct key_params *params)
1789 struct get_key_cookie *cookie = c;
1792 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
1793 params->key_len, params->key);
1796 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
1797 params->seq_len, params->seq);
1800 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
1803 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
1805 goto nla_put_failure;
1808 NLA_PUT(cookie->msg, NL80211_KEY_DATA,
1809 params->key_len, params->key);
1812 NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
1813 params->seq_len, params->seq);
1816 NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
1819 NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
1821 nla_nest_end(cookie->msg, key);
1828 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1832 struct net_device *dev = info->user_ptr[1];
1834 const u8 *mac_addr = NULL;
1836 struct get_key_cookie cookie = {
1840 struct sk_buff *msg;
1842 if (info->attrs[NL80211_ATTR_KEY_IDX])
1843 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1848 if (info->attrs[NL80211_ATTR_MAC])
1849 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1851 pairwise = !!mac_addr;
1852 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
1853 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
1854 if (kt >= NUM_NL80211_KEYTYPES)
1856 if (kt != NL80211_KEYTYPE_GROUP &&
1857 kt != NL80211_KEYTYPE_PAIRWISE)
1859 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
1862 if (!rdev->ops->get_key)
1865 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1869 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
1870 NL80211_CMD_NEW_KEY);
1872 return PTR_ERR(hdr);
1875 cookie.idx = key_idx;
1877 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1878 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1880 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1882 if (pairwise && mac_addr &&
1883 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
1886 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
1887 mac_addr, &cookie, get_key_callback);
1893 goto nla_put_failure;
1895 genlmsg_end(msg, hdr);
1896 return genlmsg_reply(msg, info);
1905 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1908 struct key_parse key;
1910 struct net_device *dev = info->user_ptr[1];
1912 err = nl80211_parse_key(info, &key);
1919 /* only support setting default key */
1920 if (!key.def && !key.defmgmt)
1923 wdev_lock(dev->ieee80211_ptr);
1926 if (!rdev->ops->set_default_key) {
1931 err = nl80211_key_allowed(dev->ieee80211_ptr);
1935 err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
1936 key.def_uni, key.def_multi);
1941 #ifdef CONFIG_CFG80211_WEXT
1942 dev->ieee80211_ptr->wext.default_key = key.idx;
1945 if (key.def_uni || !key.def_multi) {
1950 if (!rdev->ops->set_default_mgmt_key) {
1955 err = nl80211_key_allowed(dev->ieee80211_ptr);
1959 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
1964 #ifdef CONFIG_CFG80211_WEXT
1965 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
1970 wdev_unlock(dev->ieee80211_ptr);
1975 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1979 struct net_device *dev = info->user_ptr[1];
1980 struct key_parse key;
1981 const u8 *mac_addr = NULL;
1983 err = nl80211_parse_key(info, &key);
1990 if (info->attrs[NL80211_ATTR_MAC])
1991 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1993 if (key.type == -1) {
1995 key.type = NL80211_KEYTYPE_PAIRWISE;
1997 key.type = NL80211_KEYTYPE_GROUP;
2001 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2002 key.type != NL80211_KEYTYPE_GROUP)
2005 if (!rdev->ops->add_key)
2008 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2009 key.type == NL80211_KEYTYPE_PAIRWISE,
2013 wdev_lock(dev->ieee80211_ptr);
2014 err = nl80211_key_allowed(dev->ieee80211_ptr);
2016 err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
2017 key.type == NL80211_KEYTYPE_PAIRWISE,
2019 wdev_unlock(dev->ieee80211_ptr);
2024 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2028 struct net_device *dev = info->user_ptr[1];
2029 u8 *mac_addr = NULL;
2030 struct key_parse key;
2032 err = nl80211_parse_key(info, &key);
2036 if (info->attrs[NL80211_ATTR_MAC])
2037 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2039 if (key.type == -1) {
2041 key.type = NL80211_KEYTYPE_PAIRWISE;
2043 key.type = NL80211_KEYTYPE_GROUP;
2047 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2048 key.type != NL80211_KEYTYPE_GROUP)
2051 if (!rdev->ops->del_key)
2054 wdev_lock(dev->ieee80211_ptr);
2055 err = nl80211_key_allowed(dev->ieee80211_ptr);
2057 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2058 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2062 err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
2063 key.type == NL80211_KEYTYPE_PAIRWISE,
2066 #ifdef CONFIG_CFG80211_WEXT
2068 if (key.idx == dev->ieee80211_ptr->wext.default_key)
2069 dev->ieee80211_ptr->wext.default_key = -1;
2070 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
2071 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2074 wdev_unlock(dev->ieee80211_ptr);
2079 static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
2081 int (*call)(struct wiphy *wiphy, struct net_device *dev,
2082 struct beacon_parameters *info);
2083 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2084 struct net_device *dev = info->user_ptr[1];
2085 struct wireless_dev *wdev = dev->ieee80211_ptr;
2086 struct beacon_parameters params;
2087 int haveinfo = 0, err;
2089 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2090 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2091 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2092 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
2095 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2096 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2099 memset(¶ms, 0, sizeof(params));
2101 switch (info->genlhdr->cmd) {
2102 case NL80211_CMD_NEW_BEACON:
2103 /* these are required for NEW_BEACON */
2104 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
2105 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
2106 !info->attrs[NL80211_ATTR_BEACON_HEAD])
2110 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
2111 params.dtim_period =
2112 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
2114 err = cfg80211_validate_beacon_int(rdev, params.interval);
2119 * In theory, some of these attributes could be required for
2120 * NEW_BEACON, but since they were not used when the command was
2121 * originally added, keep them optional for old user space
2122 * programs to work with drivers that do not need the additional
2125 if (info->attrs[NL80211_ATTR_SSID]) {
2126 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2128 nla_len(info->attrs[NL80211_ATTR_SSID]);
2129 if (params.ssid_len == 0 ||
2130 params.ssid_len > IEEE80211_MAX_SSID_LEN)
2134 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
2135 params.hidden_ssid = nla_get_u32(
2136 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
2137 if (params.hidden_ssid !=
2138 NL80211_HIDDEN_SSID_NOT_IN_USE &&
2139 params.hidden_ssid !=
2140 NL80211_HIDDEN_SSID_ZERO_LEN &&
2141 params.hidden_ssid !=
2142 NL80211_HIDDEN_SSID_ZERO_CONTENTS)
2146 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
2148 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
2149 params.auth_type = nla_get_u32(
2150 info->attrs[NL80211_ATTR_AUTH_TYPE]);
2151 if (!nl80211_valid_auth_type(params.auth_type))
2154 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
2156 err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
2157 NL80211_MAX_NR_CIPHER_SUITES);
2161 call = rdev->ops->add_beacon;
2163 case NL80211_CMD_SET_BEACON:
2164 call = rdev->ops->set_beacon;
2174 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
2175 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2177 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2181 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
2182 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2184 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2191 if (info->attrs[NL80211_ATTR_IE]) {
2192 params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2193 params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2196 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
2197 params.proberesp_ies =
2198 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2199 params.proberesp_ies_len =
2200 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2203 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
2204 params.assocresp_ies =
2205 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2206 params.assocresp_ies_len =
2207 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2210 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
2212 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
2213 params.probe_resp_len =
2214 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2217 err = call(&rdev->wiphy, dev, ¶ms);
2218 if (!err && params.interval)
2219 wdev->beacon_interval = params.interval;
2223 static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
2225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2226 struct net_device *dev = info->user_ptr[1];
2227 struct wireless_dev *wdev = dev->ieee80211_ptr;
2230 if (!rdev->ops->del_beacon)
2233 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2234 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2237 err = rdev->ops->del_beacon(&rdev->wiphy, dev);
2239 wdev->beacon_interval = 0;
2243 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2244 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
2245 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
2246 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
2247 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
2248 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
2249 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
2252 static int parse_station_flags(struct genl_info *info,
2253 enum nl80211_iftype iftype,
2254 struct station_parameters *params)
2256 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
2261 * Try parsing the new attribute first so userspace
2262 * can specify both for older kernels.
2264 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
2266 struct nl80211_sta_flag_update *sta_flags;
2268 sta_flags = nla_data(nla);
2269 params->sta_flags_mask = sta_flags->mask;
2270 params->sta_flags_set = sta_flags->set;
2271 if ((params->sta_flags_mask |
2272 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
2277 /* if present, parse the old attribute */
2279 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
2283 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
2284 nla, sta_flags_policy))
2288 * Only allow certain flags for interface types so that
2289 * other attributes are silently ignored. Remember that
2290 * this is backward compatibility code with old userspace
2291 * and shouldn't be hit in other cases anyway.
2294 case NL80211_IFTYPE_AP:
2295 case NL80211_IFTYPE_AP_VLAN:
2296 case NL80211_IFTYPE_P2P_GO:
2297 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2298 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2299 BIT(NL80211_STA_FLAG_WME) |
2300 BIT(NL80211_STA_FLAG_MFP);
2302 case NL80211_IFTYPE_P2P_CLIENT:
2303 case NL80211_IFTYPE_STATION:
2304 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2305 BIT(NL80211_STA_FLAG_TDLS_PEER);
2307 case NL80211_IFTYPE_MESH_POINT:
2308 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2309 BIT(NL80211_STA_FLAG_MFP) |
2310 BIT(NL80211_STA_FLAG_AUTHORIZED);
2315 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2317 params->sta_flags_set |= (1<<flag);
2322 static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
2325 struct nlattr *rate;
2328 rate = nla_nest_start(msg, attr);
2330 goto nla_put_failure;
2332 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2333 bitrate = cfg80211_calculate_bitrate(info);
2335 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
2337 if (info->flags & RATE_INFO_FLAGS_MCS)
2338 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs);
2339 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
2340 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
2341 if (info->flags & RATE_INFO_FLAGS_SHORT_GI)
2342 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
2344 nla_nest_end(msg, rate);
2351 static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
2352 int flags, struct net_device *dev,
2353 const u8 *mac_addr, struct station_info *sinfo)
2356 struct nlattr *sinfoattr, *bss_param;
2358 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2362 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2363 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
2365 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
2367 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
2369 goto nla_put_failure;
2370 if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
2371 NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
2372 sinfo->connected_time);
2373 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
2374 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
2375 sinfo->inactive_time);
2376 if (sinfo->filled & STATION_INFO_RX_BYTES)
2377 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
2379 if (sinfo->filled & STATION_INFO_TX_BYTES)
2380 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
2382 if (sinfo->filled & STATION_INFO_LLID)
2383 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
2385 if (sinfo->filled & STATION_INFO_PLID)
2386 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
2388 if (sinfo->filled & STATION_INFO_PLINK_STATE)
2389 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
2390 sinfo->plink_state);
2391 if (sinfo->filled & STATION_INFO_SIGNAL)
2392 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
2394 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
2395 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
2397 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
2398 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
2399 NL80211_STA_INFO_TX_BITRATE))
2400 goto nla_put_failure;
2402 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
2403 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
2404 NL80211_STA_INFO_RX_BITRATE))
2405 goto nla_put_failure;
2407 if (sinfo->filled & STATION_INFO_RX_PACKETS)
2408 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
2410 if (sinfo->filled & STATION_INFO_TX_PACKETS)
2411 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
2413 if (sinfo->filled & STATION_INFO_TX_RETRIES)
2414 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
2416 if (sinfo->filled & STATION_INFO_TX_FAILED)
2417 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
2419 if (sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT)
2420 NLA_PUT_U32(msg, NL80211_STA_INFO_BEACON_LOSS,
2421 sinfo->beacon_loss_count);
2422 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
2423 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
2425 goto nla_put_failure;
2427 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
2428 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
2429 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
2430 NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
2431 if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
2433 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
2434 NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
2435 sinfo->bss_param.dtim_period);
2436 NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
2437 sinfo->bss_param.beacon_interval);
2439 nla_nest_end(msg, bss_param);
2441 if (sinfo->filled & STATION_INFO_STA_FLAGS)
2442 NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS,
2443 sizeof(struct nl80211_sta_flag_update),
2445 nla_nest_end(msg, sinfoattr);
2447 if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES)
2448 NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
2449 sinfo->assoc_req_ies);
2451 return genlmsg_end(msg, hdr);
2454 genlmsg_cancel(msg, hdr);
2458 static int nl80211_dump_station(struct sk_buff *skb,
2459 struct netlink_callback *cb)
2461 struct station_info sinfo;
2462 struct cfg80211_registered_device *dev;
2463 struct net_device *netdev;
2464 u8 mac_addr[ETH_ALEN];
2465 int sta_idx = cb->args[1];
2468 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2472 if (!dev->ops->dump_station) {
2478 memset(&sinfo, 0, sizeof(sinfo));
2479 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
2486 if (nl80211_send_station(skb,
2487 NETLINK_CB(cb->skb).pid,
2488 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2498 cb->args[1] = sta_idx;
2501 nl80211_finish_netdev_dump(dev);
2506 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
2508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2509 struct net_device *dev = info->user_ptr[1];
2510 struct station_info sinfo;
2511 struct sk_buff *msg;
2512 u8 *mac_addr = NULL;
2515 memset(&sinfo, 0, sizeof(sinfo));
2517 if (!info->attrs[NL80211_ATTR_MAC])
2520 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2522 if (!rdev->ops->get_station)
2525 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
2529 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2533 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
2534 dev, mac_addr, &sinfo) < 0) {
2539 return genlmsg_reply(msg, info);
2543 * Get vlan interface making sure it is running and on the right wiphy.
2545 static struct net_device *get_vlan(struct genl_info *info,
2546 struct cfg80211_registered_device *rdev)
2548 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
2549 struct net_device *v;
2555 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
2557 return ERR_PTR(-ENODEV);
2559 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
2564 if (!netif_running(v)) {
2572 return ERR_PTR(ret);
2575 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2579 struct net_device *dev = info->user_ptr[1];
2580 struct station_parameters params;
2581 u8 *mac_addr = NULL;
2583 memset(¶ms, 0, sizeof(params));
2585 params.listen_interval = -1;
2586 params.plink_state = -1;
2588 if (info->attrs[NL80211_ATTR_STA_AID])
2591 if (!info->attrs[NL80211_ATTR_MAC])
2594 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2596 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
2597 params.supported_rates =
2598 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2599 params.supported_rates_len =
2600 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2603 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2604 params.listen_interval =
2605 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2607 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2609 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2611 if (!rdev->ops->change_station)
2614 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
2617 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2618 params.plink_action =
2619 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2621 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
2622 params.plink_state =
2623 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
2625 switch (dev->ieee80211_ptr->iftype) {
2626 case NL80211_IFTYPE_AP:
2627 case NL80211_IFTYPE_AP_VLAN:
2628 case NL80211_IFTYPE_P2P_GO:
2629 /* disallow mesh-specific things */
2630 if (params.plink_action)
2633 /* TDLS can't be set, ... */
2634 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2637 * ... but don't bother the driver with it. This works around
2638 * a hostapd/wpa_supplicant issue -- it always includes the
2639 * TLDS_PEER flag in the mask even for AP mode.
2641 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2643 /* accept only the listed bits */
2644 if (params.sta_flags_mask &
2645 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2646 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2647 BIT(NL80211_STA_FLAG_WME) |
2648 BIT(NL80211_STA_FLAG_MFP)))
2651 /* must be last in here for error handling */
2652 params.vlan = get_vlan(info, rdev);
2653 if (IS_ERR(params.vlan))
2654 return PTR_ERR(params.vlan);
2656 case NL80211_IFTYPE_P2P_CLIENT:
2657 case NL80211_IFTYPE_STATION:
2658 /* disallow things sta doesn't support */
2659 if (params.plink_action)
2663 if (params.listen_interval >= 0)
2666 * Don't allow userspace to change the TDLS_PEER flag,
2667 * but silently ignore attempts to change it since we
2668 * don't have state here to verify that it doesn't try
2669 * to change the flag.
2671 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2673 /* reject any changes other than AUTHORIZED */
2674 if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2677 case NL80211_IFTYPE_MESH_POINT:
2678 /* disallow things mesh doesn't support */
2683 if (params.listen_interval >= 0)
2686 * No special handling for TDLS here -- the userspace
2687 * mesh code doesn't have this bug.
2689 if (params.sta_flags_mask &
2690 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2691 BIT(NL80211_STA_FLAG_MFP) |
2692 BIT(NL80211_STA_FLAG_AUTHORIZED)))
2699 /* be aware of params.vlan when changing code here */
2701 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms);
2704 dev_put(params.vlan);
2709 static struct nla_policy
2710 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
2711 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
2712 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
2715 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2719 struct net_device *dev = info->user_ptr[1];
2720 struct station_parameters params;
2721 u8 *mac_addr = NULL;
2723 memset(¶ms, 0, sizeof(params));
2725 if (!info->attrs[NL80211_ATTR_MAC])
2728 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
2731 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
2734 if (!info->attrs[NL80211_ATTR_STA_AID])
2737 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2738 params.supported_rates =
2739 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2740 params.supported_rates_len =
2741 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
2742 params.listen_interval =
2743 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
2745 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
2746 if (!params.aid || params.aid > IEEE80211_MAX_AID)
2749 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
2751 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
2753 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
2754 params.plink_action =
2755 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
2757 if (!rdev->ops->add_station)
2760 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
2763 switch (dev->ieee80211_ptr->iftype) {
2764 case NL80211_IFTYPE_AP:
2765 case NL80211_IFTYPE_AP_VLAN:
2766 case NL80211_IFTYPE_P2P_GO:
2767 /* parse WME attributes if sta is WME capable */
2768 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
2769 (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
2770 info->attrs[NL80211_ATTR_STA_WME]) {
2771 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
2774 nla = info->attrs[NL80211_ATTR_STA_WME];
2775 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
2776 nl80211_sta_wme_policy);
2780 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
2781 params.uapsd_queues =
2782 nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
2783 if (params.uapsd_queues &
2784 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
2787 if (tb[NL80211_STA_WME_MAX_SP])
2789 nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
2792 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
2795 params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
2797 /* TDLS peers cannot be added */
2798 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2800 /* but don't bother the driver with it */
2801 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
2803 /* must be last in here for error handling */
2804 params.vlan = get_vlan(info, rdev);
2805 if (IS_ERR(params.vlan))
2806 return PTR_ERR(params.vlan);
2808 case NL80211_IFTYPE_MESH_POINT:
2809 /* TDLS peers cannot be added */
2810 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2813 case NL80211_IFTYPE_STATION:
2814 /* Only TDLS peers can be added */
2815 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
2817 /* Can only add if TDLS ... */
2818 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
2820 /* ... with external setup is supported */
2821 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
2828 /* be aware of params.vlan when changing code here */
2830 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms);
2833 dev_put(params.vlan);
2837 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
2839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2840 struct net_device *dev = info->user_ptr[1];
2841 u8 *mac_addr = NULL;
2843 if (info->attrs[NL80211_ATTR_MAC])
2844 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2846 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2847 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
2848 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
2849 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2852 if (!rdev->ops->del_station)
2855 return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
2858 static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
2859 int flags, struct net_device *dev,
2860 u8 *dst, u8 *next_hop,
2861 struct mpath_info *pinfo)
2864 struct nlattr *pinfoattr;
2866 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
2870 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2871 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
2872 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
2874 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
2876 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
2878 goto nla_put_failure;
2879 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
2880 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
2882 if (pinfo->filled & MPATH_INFO_SN)
2883 NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
2885 if (pinfo->filled & MPATH_INFO_METRIC)
2886 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
2888 if (pinfo->filled & MPATH_INFO_EXPTIME)
2889 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
2891 if (pinfo->filled & MPATH_INFO_FLAGS)
2892 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
2894 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
2895 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
2896 pinfo->discovery_timeout);
2897 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
2898 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
2899 pinfo->discovery_retries);
2901 nla_nest_end(msg, pinfoattr);
2903 return genlmsg_end(msg, hdr);
2906 genlmsg_cancel(msg, hdr);
2910 static int nl80211_dump_mpath(struct sk_buff *skb,
2911 struct netlink_callback *cb)
2913 struct mpath_info pinfo;
2914 struct cfg80211_registered_device *dev;
2915 struct net_device *netdev;
2917 u8 next_hop[ETH_ALEN];
2918 int path_idx = cb->args[1];
2921 err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
2925 if (!dev->ops->dump_mpath) {
2930 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2936 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
2937 dst, next_hop, &pinfo);
2943 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
2944 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2945 netdev, dst, next_hop,
2954 cb->args[1] = path_idx;
2957 nl80211_finish_netdev_dump(dev);
2961 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2965 struct net_device *dev = info->user_ptr[1];
2966 struct mpath_info pinfo;
2967 struct sk_buff *msg;
2969 u8 next_hop[ETH_ALEN];
2971 memset(&pinfo, 0, sizeof(pinfo));
2973 if (!info->attrs[NL80211_ATTR_MAC])
2976 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2978 if (!rdev->ops->get_mpath)
2981 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
2984 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
2988 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2992 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
2993 dev, dst, next_hop, &pinfo) < 0) {
2998 return genlmsg_reply(msg, info);
3001 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
3003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3004 struct net_device *dev = info->user_ptr[1];
3006 u8 *next_hop = NULL;
3008 if (!info->attrs[NL80211_ATTR_MAC])
3011 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3014 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3015 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3017 if (!rdev->ops->change_mpath)
3020 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3023 return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
3026 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
3028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3029 struct net_device *dev = info->user_ptr[1];
3031 u8 *next_hop = NULL;
3033 if (!info->attrs[NL80211_ATTR_MAC])
3036 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
3039 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3040 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
3042 if (!rdev->ops->add_mpath)
3045 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
3048 return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
3051 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
3053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3054 struct net_device *dev = info->user_ptr[1];
3057 if (info->attrs[NL80211_ATTR_MAC])
3058 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
3060 if (!rdev->ops->del_mpath)
3063 return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
3066 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
3068 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3069 struct net_device *dev = info->user_ptr[1];
3070 struct bss_parameters params;
3072 memset(¶ms, 0, sizeof(params));
3073 /* default to not changing parameters */
3074 params.use_cts_prot = -1;
3075 params.use_short_preamble = -1;
3076 params.use_short_slot_time = -1;
3077 params.ap_isolate = -1;
3078 params.ht_opmode = -1;
3080 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
3081 params.use_cts_prot =
3082 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
3083 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
3084 params.use_short_preamble =
3085 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
3086 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
3087 params.use_short_slot_time =
3088 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
3089 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
3090 params.basic_rates =
3091 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3092 params.basic_rates_len =
3093 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
3095 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
3096 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
3097 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
3099 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
3101 if (!rdev->ops->change_bss)
3104 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3105 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3108 return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms);
3111 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
3112 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
3113 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
3114 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
3115 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
3116 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
3117 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
3120 static int parse_reg_rule(struct nlattr *tb[],
3121 struct ieee80211_reg_rule *reg_rule)
3123 struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
3124 struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
3126 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
3128 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
3130 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
3132 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
3134 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
3137 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
3139 freq_range->start_freq_khz =
3140 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
3141 freq_range->end_freq_khz =
3142 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
3143 freq_range->max_bandwidth_khz =
3144 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
3146 power_rule->max_eirp =
3147 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
3149 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
3150 power_rule->max_antenna_gain =
3151 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
3156 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
3162 * You should only get this when cfg80211 hasn't yet initialized
3163 * completely when built-in to the kernel right between the time
3164 * window between nl80211_init() and regulatory_init(), if that is
3167 mutex_lock(&cfg80211_mutex);
3168 if (unlikely(!cfg80211_regdomain)) {
3169 mutex_unlock(&cfg80211_mutex);
3170 return -EINPROGRESS;
3172 mutex_unlock(&cfg80211_mutex);
3174 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3177 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3179 r = regulatory_hint_user(data);
3184 static int nl80211_get_mesh_config(struct sk_buff *skb,
3185 struct genl_info *info)
3187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3188 struct net_device *dev = info->user_ptr[1];
3189 struct wireless_dev *wdev = dev->ieee80211_ptr;
3190 struct mesh_config cur_params;
3193 struct nlattr *pinfoattr;
3194 struct sk_buff *msg;
3196 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3199 if (!rdev->ops->get_mesh_config)
3203 /* If not connected, get default parameters */
3204 if (!wdev->mesh_id_len)
3205 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
3207 err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
3214 /* Draw up a netlink message to send back */
3215 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3218 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3219 NL80211_CMD_GET_MESH_CONFIG);
3222 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
3224 goto nla_put_failure;
3225 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
3226 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
3227 cur_params.dot11MeshRetryTimeout);
3228 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
3229 cur_params.dot11MeshConfirmTimeout);
3230 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
3231 cur_params.dot11MeshHoldingTimeout);
3232 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
3233 cur_params.dot11MeshMaxPeerLinks);
3234 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
3235 cur_params.dot11MeshMaxRetries);
3236 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
3237 cur_params.dot11MeshTTL);
3238 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
3239 cur_params.element_ttl);
3240 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
3241 cur_params.auto_open_plinks);
3242 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3243 cur_params.dot11MeshHWMPmaxPREQretries);
3244 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
3245 cur_params.path_refresh_time);
3246 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3247 cur_params.min_discovery_timeout);
3248 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3249 cur_params.dot11MeshHWMPactivePathTimeout);
3250 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3251 cur_params.dot11MeshHWMPpreqMinInterval);
3252 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3253 cur_params.dot11MeshHWMPperrMinInterval);
3254 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3255 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
3256 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
3257 cur_params.dot11MeshHWMPRootMode);
3258 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3259 cur_params.dot11MeshHWMPRannInterval);
3260 NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3261 cur_params.dot11MeshGateAnnouncementProtocol);
3262 nla_nest_end(msg, pinfoattr);
3263 genlmsg_end(msg, hdr);
3264 return genlmsg_reply(msg, info);
3267 genlmsg_cancel(msg, hdr);
3273 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
3274 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
3275 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
3276 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
3277 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
3278 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
3279 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
3280 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
3281 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
3283 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
3284 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
3285 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
3286 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
3287 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
3288 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
3289 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
3290 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
3291 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
3292 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
3295 static const struct nla_policy
3296 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
3297 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
3298 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
3299 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
3300 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
3301 .len = IEEE80211_MAX_DATA_LEN },
3302 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
3305 static int nl80211_parse_mesh_config(struct genl_info *info,
3306 struct mesh_config *cfg,
3309 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
3312 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3314 if (table[attr_num]) {\
3315 cfg->param = nla_fn(table[attr_num]); \
3316 mask |= (1 << (attr_num - 1)); \
3321 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3323 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
3324 info->attrs[NL80211_ATTR_MESH_CONFIG],
3325 nl80211_meshconf_params_policy))
3328 /* This makes sure that there aren't more than 32 mesh config
3329 * parameters (otherwise our bitfield scheme would not work.) */
3330 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
3332 /* Fill in the params struct */
3333 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
3334 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
3335 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
3336 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
3337 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
3338 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
3339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
3340 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
3341 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
3342 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
3343 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
3344 mask, NL80211_MESHCONF_TTL, nla_get_u8);
3345 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
3346 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
3347 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
3348 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
3349 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
3350 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
3352 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
3353 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
3354 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
3355 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
3357 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
3358 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
3360 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
3361 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
3363 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
3364 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
3366 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3367 dot11MeshHWMPnetDiameterTraversalTime,
3368 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3370 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3371 dot11MeshHWMPRootMode, mask,
3372 NL80211_MESHCONF_HWMP_ROOTMODE,
3374 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3375 dot11MeshHWMPRannInterval, mask,
3376 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
3378 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
3379 dot11MeshGateAnnouncementProtocol, mask,
3380 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
3387 #undef FILL_IN_MESH_PARAM_IF_SET
3390 static int nl80211_parse_mesh_setup(struct genl_info *info,
3391 struct mesh_setup *setup)
3393 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
3395 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
3397 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
3398 info->attrs[NL80211_ATTR_MESH_SETUP],
3399 nl80211_mesh_setup_params_policy))
3402 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
3403 setup->path_sel_proto =
3404 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
3405 IEEE80211_PATH_PROTOCOL_VENDOR :
3406 IEEE80211_PATH_PROTOCOL_HWMP;
3408 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
3409 setup->path_metric =
3410 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
3411 IEEE80211_PATH_METRIC_VENDOR :
3412 IEEE80211_PATH_METRIC_AIRTIME;
3415 if (tb[NL80211_MESH_SETUP_IE]) {
3416 struct nlattr *ieattr =
3417 tb[NL80211_MESH_SETUP_IE];
3418 if (!is_valid_ie_attr(ieattr))
3420 setup->ie = nla_data(ieattr);
3421 setup->ie_len = nla_len(ieattr);
3423 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
3424 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
3429 static int nl80211_update_mesh_config(struct sk_buff *skb,
3430 struct genl_info *info)
3432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3433 struct net_device *dev = info->user_ptr[1];
3434 struct wireless_dev *wdev = dev->ieee80211_ptr;
3435 struct mesh_config cfg;
3439 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
3442 if (!rdev->ops->update_mesh_config)
3445 err = nl80211_parse_mesh_config(info, &cfg, &mask);
3450 if (!wdev->mesh_id_len)
3454 err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
3462 static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
3464 struct sk_buff *msg;
3466 struct nlattr *nl_reg_rules;
3470 mutex_lock(&cfg80211_mutex);
3472 if (!cfg80211_regdomain)
3475 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3481 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
3482 NL80211_CMD_GET_REG);
3486 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
3487 cfg80211_regdomain->alpha2);
3488 if (cfg80211_regdomain->dfs_region)
3489 NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION,
3490 cfg80211_regdomain->dfs_region);
3492 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
3494 goto nla_put_failure;
3496 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
3497 struct nlattr *nl_reg_rule;
3498 const struct ieee80211_reg_rule *reg_rule;
3499 const struct ieee80211_freq_range *freq_range;
3500 const struct ieee80211_power_rule *power_rule;
3502 reg_rule = &cfg80211_regdomain->reg_rules[i];
3503 freq_range = ®_rule->freq_range;
3504 power_rule = ®_rule->power_rule;
3506 nl_reg_rule = nla_nest_start(msg, i);
3508 goto nla_put_failure;
3510 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
3512 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
3513 freq_range->start_freq_khz);
3514 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
3515 freq_range->end_freq_khz);
3516 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
3517 freq_range->max_bandwidth_khz);
3518 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
3519 power_rule->max_antenna_gain);
3520 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
3521 power_rule->max_eirp);
3523 nla_nest_end(msg, nl_reg_rule);
3526 nla_nest_end(msg, nl_reg_rules);
3528 genlmsg_end(msg, hdr);
3529 err = genlmsg_reply(msg, info);
3533 genlmsg_cancel(msg, hdr);
3538 mutex_unlock(&cfg80211_mutex);
3542 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
3544 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
3545 struct nlattr *nl_reg_rule;
3546 char *alpha2 = NULL;
3547 int rem_reg_rules = 0, r = 0;
3548 u32 num_rules = 0, rule_idx = 0, size_of_regd;
3550 struct ieee80211_regdomain *rd = NULL;
3552 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
3555 if (!info->attrs[NL80211_ATTR_REG_RULES])
3558 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
3560 if (info->attrs[NL80211_ATTR_DFS_REGION])
3561 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
3563 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3566 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
3570 mutex_lock(&cfg80211_mutex);
3572 if (!reg_is_valid_request(alpha2)) {
3577 size_of_regd = sizeof(struct ieee80211_regdomain) +
3578 (num_rules * sizeof(struct ieee80211_reg_rule));
3580 rd = kzalloc(size_of_regd, GFP_KERNEL);
3586 rd->n_reg_rules = num_rules;
3587 rd->alpha2[0] = alpha2[0];
3588 rd->alpha2[1] = alpha2[1];
3591 * Disable DFS master mode if the DFS region was
3592 * not supported or known on this kernel.
3594 if (reg_supported_dfs_region(dfs_region))
3595 rd->dfs_region = dfs_region;
3597 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
3599 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
3600 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
3602 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
3608 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
3614 BUG_ON(rule_idx != num_rules);
3618 mutex_unlock(&cfg80211_mutex);
3623 mutex_unlock(&cfg80211_mutex);
3628 static int validate_scan_freqs(struct nlattr *freqs)
3630 struct nlattr *attr1, *attr2;
3631 int n_channels = 0, tmp1, tmp2;
3633 nla_for_each_nested(attr1, freqs, tmp1) {
3636 * Some hardware has a limited channel list for
3637 * scanning, and it is pretty much nonsensical
3638 * to scan for a channel twice, so disallow that
3639 * and don't require drivers to check that the
3640 * channel list they get isn't longer than what
3641 * they can scan, as long as they can scan all
3642 * the channels they registered at once.
3644 nla_for_each_nested(attr2, freqs, tmp2)
3645 if (attr1 != attr2 &&
3646 nla_get_u32(attr1) == nla_get_u32(attr2))
3653 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
3655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3656 struct net_device *dev = info->user_ptr[1];
3657 struct cfg80211_scan_request *request;
3658 struct nlattr *attr;
3659 struct wiphy *wiphy;
3660 int err, tmp, n_ssids = 0, n_channels, i;
3663 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3666 wiphy = &rdev->wiphy;
3668 if (!rdev->ops->scan)
3674 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3675 n_channels = validate_scan_freqs(
3676 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3680 enum ieee80211_band band;
3683 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3684 if (wiphy->bands[band])
3685 n_channels += wiphy->bands[band]->n_channels;
3688 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3689 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
3692 if (n_ssids > wiphy->max_scan_ssids)
3695 if (info->attrs[NL80211_ATTR_IE])
3696 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3700 if (ie_len > wiphy->max_scan_ie_len)
3703 request = kzalloc(sizeof(*request)
3704 + sizeof(*request->ssids) * n_ssids
3705 + sizeof(*request->channels) * n_channels
3706 + ie_len, GFP_KERNEL);
3711 request->ssids = (void *)&request->channels[n_channels];
3712 request->n_ssids = n_ssids;
3715 request->ie = (void *)(request->ssids + n_ssids);
3717 request->ie = (void *)(request->channels + n_channels);
3721 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3722 /* user specified, bail out if channel not found */
3723 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
3724 struct ieee80211_channel *chan;
3726 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3733 /* ignore disabled channels */
3734 if (chan->flags & IEEE80211_CHAN_DISABLED)
3737 request->channels[i] = chan;
3741 enum ieee80211_band band;
3744 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3746 if (!wiphy->bands[band])
3748 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3749 struct ieee80211_channel *chan;
3751 chan = &wiphy->bands[band]->channels[j];
3753 if (chan->flags & IEEE80211_CHAN_DISABLED)
3756 request->channels[i] = chan;
3767 request->n_channels = i;
3770 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3771 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
3772 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
3776 request->ssids[i].ssid_len = nla_len(attr);
3777 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
3782 if (info->attrs[NL80211_ATTR_IE]) {
3783 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3784 memcpy((void *)request->ie,
3785 nla_data(info->attrs[NL80211_ATTR_IE]),
3789 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
3790 if (wiphy->bands[i])
3792 (1 << wiphy->bands[i]->n_bitrates) - 1;
3794 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
3795 nla_for_each_nested(attr,
3796 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
3798 enum ieee80211_band band = nla_type(attr);
3800 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
3804 err = ieee80211_get_ratemask(wiphy->bands[band],
3807 &request->rates[band]);
3814 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
3817 request->wiphy = &rdev->wiphy;
3819 rdev->scan_req = request;
3820 err = rdev->ops->scan(&rdev->wiphy, dev, request);
3823 nl80211_send_scan_start(rdev, dev);
3827 rdev->scan_req = NULL;
3834 static int nl80211_start_sched_scan(struct sk_buff *skb,
3835 struct genl_info *info)
3837 struct cfg80211_sched_scan_request *request;
3838 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3839 struct net_device *dev = info->user_ptr[1];
3840 struct nlattr *attr;
3841 struct wiphy *wiphy;
3842 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
3844 enum ieee80211_band band;
3846 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
3848 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
3849 !rdev->ops->sched_scan_start)
3852 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3855 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
3858 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
3862 wiphy = &rdev->wiphy;
3864 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3865 n_channels = validate_scan_freqs(
3866 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
3872 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
3873 if (wiphy->bands[band])
3874 n_channels += wiphy->bands[band]->n_channels;
3877 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
3878 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3882 if (n_ssids > wiphy->max_sched_scan_ssids)
3885 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
3886 nla_for_each_nested(attr,
3887 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
3891 if (n_match_sets > wiphy->max_match_sets)
3894 if (info->attrs[NL80211_ATTR_IE])
3895 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3899 if (ie_len > wiphy->max_sched_scan_ie_len)
3902 mutex_lock(&rdev->sched_scan_mtx);
3904 if (rdev->sched_scan_req) {
3909 request = kzalloc(sizeof(*request)
3910 + sizeof(*request->ssids) * n_ssids
3911 + sizeof(*request->match_sets) * n_match_sets
3912 + sizeof(*request->channels) * n_channels
3913 + ie_len, GFP_KERNEL);
3920 request->ssids = (void *)&request->channels[n_channels];
3921 request->n_ssids = n_ssids;
3924 request->ie = (void *)(request->ssids + n_ssids);
3926 request->ie = (void *)(request->channels + n_channels);
3931 request->match_sets = (void *)(request->ie + ie_len);
3932 else if (request->ssids)
3933 request->match_sets =
3934 (void *)(request->ssids + n_ssids);
3936 request->match_sets =
3937 (void *)(request->channels + n_channels);
3939 request->n_match_sets = n_match_sets;
3942 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
3943 /* user specified, bail out if channel not found */
3944 nla_for_each_nested(attr,
3945 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
3947 struct ieee80211_channel *chan;
3949 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
3956 /* ignore disabled channels */
3957 if (chan->flags & IEEE80211_CHAN_DISABLED)
3960 request->channels[i] = chan;
3965 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3967 if (!wiphy->bands[band])
3969 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
3970 struct ieee80211_channel *chan;
3972 chan = &wiphy->bands[band]->channels[j];
3974 if (chan->flags & IEEE80211_CHAN_DISABLED)
3977 request->channels[i] = chan;
3988 request->n_channels = i;
3991 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
3992 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
3994 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
3998 request->ssids[i].ssid_len = nla_len(attr);
3999 memcpy(request->ssids[i].ssid, nla_data(attr),
4006 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
4007 nla_for_each_nested(attr,
4008 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
4010 struct nlattr *ssid;
4012 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
4013 nla_data(attr), nla_len(attr),
4014 nl80211_match_policy);
4015 ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
4017 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
4021 memcpy(request->match_sets[i].ssid.ssid,
4022 nla_data(ssid), nla_len(ssid));
4023 request->match_sets[i].ssid.ssid_len =
4030 if (info->attrs[NL80211_ATTR_IE]) {
4031 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4032 memcpy((void *)request->ie,
4033 nla_data(info->attrs[NL80211_ATTR_IE]),
4038 request->wiphy = &rdev->wiphy;
4039 request->interval = interval;
4041 err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
4043 rdev->sched_scan_req = request;
4044 nl80211_send_sched_scan(rdev, dev,
4045 NL80211_CMD_START_SCHED_SCAN);
4052 mutex_unlock(&rdev->sched_scan_mtx);
4056 static int nl80211_stop_sched_scan(struct sk_buff *skb,
4057 struct genl_info *info)
4059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4062 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
4063 !rdev->ops->sched_scan_stop)
4066 mutex_lock(&rdev->sched_scan_mtx);
4067 err = __cfg80211_stop_sched_scan(rdev, false);
4068 mutex_unlock(&rdev->sched_scan_mtx);
4073 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
4075 struct cfg80211_registered_device *rdev,
4076 struct wireless_dev *wdev,
4077 struct cfg80211_internal_bss *intbss)
4079 struct cfg80211_bss *res = &intbss->pub;
4084 ASSERT_WDEV_LOCK(wdev);
4086 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
4087 NL80211_CMD_NEW_SCAN_RESULTS);
4091 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
4093 NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
4094 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
4096 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
4098 goto nla_put_failure;
4099 if (!is_zero_ether_addr(res->bssid))
4100 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
4101 if (res->information_elements && res->len_information_elements)
4102 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
4103 res->len_information_elements,
4104 res->information_elements);
4105 if (res->beacon_ies && res->len_beacon_ies &&
4106 res->beacon_ies != res->information_elements)
4107 NLA_PUT(msg, NL80211_BSS_BEACON_IES,
4108 res->len_beacon_ies, res->beacon_ies);
4110 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
4111 if (res->beacon_interval)
4112 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
4113 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
4114 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
4115 NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
4116 jiffies_to_msecs(jiffies - intbss->ts));
4118 switch (rdev->wiphy.signal_type) {
4119 case CFG80211_SIGNAL_TYPE_MBM:
4120 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
4122 case CFG80211_SIGNAL_TYPE_UNSPEC:
4123 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
4129 switch (wdev->iftype) {
4130 case NL80211_IFTYPE_P2P_CLIENT:
4131 case NL80211_IFTYPE_STATION:
4132 if (intbss == wdev->current_bss)
4133 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4134 NL80211_BSS_STATUS_ASSOCIATED);
4135 else for (i = 0; i < MAX_AUTH_BSSES; i++) {
4136 if (intbss != wdev->auth_bsses[i])
4138 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4139 NL80211_BSS_STATUS_AUTHENTICATED);
4143 case NL80211_IFTYPE_ADHOC:
4144 if (intbss == wdev->current_bss)
4145 NLA_PUT_U32(msg, NL80211_BSS_STATUS,
4146 NL80211_BSS_STATUS_IBSS_JOINED);
4152 nla_nest_end(msg, bss);
4154 return genlmsg_end(msg, hdr);
4157 genlmsg_cancel(msg, hdr);
4161 static int nl80211_dump_scan(struct sk_buff *skb,
4162 struct netlink_callback *cb)
4164 struct cfg80211_registered_device *rdev;
4165 struct net_device *dev;
4166 struct cfg80211_internal_bss *scan;
4167 struct wireless_dev *wdev;
4168 int start = cb->args[1], idx = 0;
4171 err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
4175 wdev = dev->ieee80211_ptr;
4178 spin_lock_bh(&rdev->bss_lock);
4179 cfg80211_bss_expire(rdev);
4181 cb->seq = rdev->bss_generation;
4183 list_for_each_entry(scan, &rdev->bss_list, list) {
4186 if (nl80211_send_bss(skb, cb,
4187 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4188 rdev, wdev, scan) < 0) {
4194 spin_unlock_bh(&rdev->bss_lock);
4198 nl80211_finish_netdev_dump(rdev);
4203 static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
4204 int flags, struct net_device *dev,
4205 struct survey_info *survey)
4208 struct nlattr *infoattr;
4210 hdr = nl80211hdr_put(msg, pid, seq, flags,
4211 NL80211_CMD_NEW_SURVEY_RESULTS);
4215 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
4217 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
4219 goto nla_put_failure;
4221 NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
4222 survey->channel->center_freq);
4223 if (survey->filled & SURVEY_INFO_NOISE_DBM)
4224 NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
4226 if (survey->filled & SURVEY_INFO_IN_USE)
4227 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
4228 if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
4229 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
4230 survey->channel_time);
4231 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
4232 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
4233 survey->channel_time_busy);
4234 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
4235 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
4236 survey->channel_time_ext_busy);
4237 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
4238 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
4239 survey->channel_time_rx);
4240 if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
4241 NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
4242 survey->channel_time_tx);
4244 nla_nest_end(msg, infoattr);
4246 return genlmsg_end(msg, hdr);
4249 genlmsg_cancel(msg, hdr);
4253 static int nl80211_dump_survey(struct sk_buff *skb,
4254 struct netlink_callback *cb)
4256 struct survey_info survey;
4257 struct cfg80211_registered_device *dev;
4258 struct net_device *netdev;
4259 int survey_idx = cb->args[1];
4262 res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
4266 if (!dev->ops->dump_survey) {
4272 struct ieee80211_channel *chan;
4274 res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
4281 /* Survey without a channel doesn't make sense */
4282 if (!survey.channel) {
4287 chan = ieee80211_get_channel(&dev->wiphy,
4288 survey.channel->center_freq);
4289 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
4294 if (nl80211_send_survey(skb,
4295 NETLINK_CB(cb->skb).pid,
4296 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4304 cb->args[1] = survey_idx;
4307 nl80211_finish_netdev_dump(dev);
4311 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
4313 return auth_type <= NL80211_AUTHTYPE_MAX;
4316 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
4318 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
4319 NL80211_WPA_VERSION_2));
4322 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
4324 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4325 struct net_device *dev = info->user_ptr[1];
4326 struct ieee80211_channel *chan;
4327 const u8 *bssid, *ssid, *ie = NULL;
4328 int err, ssid_len, ie_len = 0;
4329 enum nl80211_auth_type auth_type;
4330 struct key_parse key;
4331 bool local_state_change;
4333 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4336 if (!info->attrs[NL80211_ATTR_MAC])
4339 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
4342 if (!info->attrs[NL80211_ATTR_SSID])
4345 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
4348 err = nl80211_parse_key(info, &key);
4353 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
4355 if (!key.p.key || !key.p.key_len)
4357 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
4358 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
4359 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
4360 key.p.key_len != WLAN_KEY_LEN_WEP104))
4372 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
4373 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
4382 if (!rdev->ops->auth)
4385 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4386 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4389 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4390 chan = ieee80211_get_channel(&rdev->wiphy,
4391 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4392 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4395 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4396 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4398 if (info->attrs[NL80211_ATTR_IE]) {
4399 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4400 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4403 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
4404 if (!nl80211_valid_auth_type(auth_type))
4407 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4409 return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
4410 ssid, ssid_len, ie, ie_len,
4411 key.p.key, key.p.key_len, key.idx,
4412 local_state_change);
4415 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
4416 struct genl_info *info,
4417 struct cfg80211_crypto_settings *settings,
4420 memset(settings, 0, sizeof(*settings));
4422 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
4424 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
4426 proto = nla_get_u16(
4427 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
4428 settings->control_port_ethertype = cpu_to_be16(proto);
4429 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
4432 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
4433 settings->control_port_no_encrypt = true;
4435 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
4437 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
4441 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4442 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
4443 settings->n_ciphers_pairwise = len / sizeof(u32);
4445 if (len % sizeof(u32))
4448 if (settings->n_ciphers_pairwise > cipher_limit)
4451 memcpy(settings->ciphers_pairwise, data, len);
4453 for (i = 0; i < settings->n_ciphers_pairwise; i++)
4454 if (!cfg80211_supported_cipher_suite(
4456 settings->ciphers_pairwise[i]))
4460 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
4461 settings->cipher_group =
4462 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
4463 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
4464 settings->cipher_group))
4468 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
4469 settings->wpa_versions =
4470 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
4471 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
4475 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
4479 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
4480 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
4481 settings->n_akm_suites = len / sizeof(u32);
4483 if (len % sizeof(u32))
4486 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
4489 memcpy(settings->akm_suites, data, len);
4495 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
4497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4498 struct net_device *dev = info->user_ptr[1];
4499 struct cfg80211_crypto_settings crypto;
4500 struct ieee80211_channel *chan;
4501 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
4502 int err, ssid_len, ie_len = 0;
4503 bool use_mfp = false;
4505 struct ieee80211_ht_cap *ht_capa = NULL;
4506 struct ieee80211_ht_cap *ht_capa_mask = NULL;
4508 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4511 if (!info->attrs[NL80211_ATTR_MAC] ||
4512 !info->attrs[NL80211_ATTR_SSID] ||
4513 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
4516 if (!rdev->ops->assoc)
4519 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4520 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4523 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4525 chan = ieee80211_get_channel(&rdev->wiphy,
4526 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
4527 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
4530 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4531 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4533 if (info->attrs[NL80211_ATTR_IE]) {
4534 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4535 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4538 if (info->attrs[NL80211_ATTR_USE_MFP]) {
4539 enum nl80211_mfp mfp =
4540 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
4541 if (mfp == NL80211_MFP_REQUIRED)
4543 else if (mfp != NL80211_MFP_NO)
4547 if (info->attrs[NL80211_ATTR_PREV_BSSID])
4548 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
4550 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
4551 flags |= ASSOC_REQ_DISABLE_HT;
4553 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
4555 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
4557 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
4560 ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4563 err = nl80211_crypto_settings(rdev, info, &crypto, 1);
4565 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
4566 ssid, ssid_len, ie, ie_len, use_mfp,
4567 &crypto, flags, ht_capa,
4573 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
4575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4576 struct net_device *dev = info->user_ptr[1];
4577 const u8 *ie = NULL, *bssid;
4580 bool local_state_change;
4582 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4585 if (!info->attrs[NL80211_ATTR_MAC])
4588 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4591 if (!rdev->ops->deauth)
4594 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4595 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4598 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4600 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4601 if (reason_code == 0) {
4602 /* Reason Code 0 is reserved */
4606 if (info->attrs[NL80211_ATTR_IE]) {
4607 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4608 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4611 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4613 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
4614 local_state_change);
4617 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
4619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4620 struct net_device *dev = info->user_ptr[1];
4621 const u8 *ie = NULL, *bssid;
4624 bool local_state_change;
4626 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4629 if (!info->attrs[NL80211_ATTR_MAC])
4632 if (!info->attrs[NL80211_ATTR_REASON_CODE])
4635 if (!rdev->ops->disassoc)
4638 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
4639 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
4642 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4644 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4645 if (reason_code == 0) {
4646 /* Reason Code 0 is reserved */
4650 if (info->attrs[NL80211_ATTR_IE]) {
4651 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4652 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4655 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
4657 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
4658 local_state_change);
4662 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
4663 int mcast_rate[IEEE80211_NUM_BANDS],
4666 struct wiphy *wiphy = &rdev->wiphy;
4670 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
4671 struct ieee80211_supported_band *sband;
4673 sband = wiphy->bands[band];
4677 for (i = 0; i < sband->n_bitrates; i++) {
4678 if (sband->bitrates[i].bitrate == rateval) {
4679 mcast_rate[band] = i + 1;
4689 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4691 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4692 struct net_device *dev = info->user_ptr[1];
4693 struct cfg80211_ibss_params ibss;
4694 struct wiphy *wiphy;
4695 struct cfg80211_cached_keys *connkeys = NULL;
4698 memset(&ibss, 0, sizeof(ibss));
4700 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
4703 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
4704 !info->attrs[NL80211_ATTR_SSID] ||
4705 !nla_len(info->attrs[NL80211_ATTR_SSID]))
4708 ibss.beacon_interval = 100;
4710 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
4711 ibss.beacon_interval =
4712 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4713 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
4717 if (!rdev->ops->join_ibss)
4720 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4723 wiphy = &rdev->wiphy;
4725 if (info->attrs[NL80211_ATTR_MAC]) {
4726 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
4728 if (!is_valid_ether_addr(ibss.bssid))
4731 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4732 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
4734 if (info->attrs[NL80211_ATTR_IE]) {
4735 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
4736 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4739 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4740 enum nl80211_channel_type channel_type;
4742 channel_type = nla_get_u32(
4743 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4744 if (channel_type != NL80211_CHAN_NO_HT &&
4745 channel_type != NL80211_CHAN_HT20 &&
4746 channel_type != NL80211_CHAN_HT40MINUS &&
4747 channel_type != NL80211_CHAN_HT40PLUS)
4750 if (channel_type != NL80211_CHAN_NO_HT &&
4751 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
4754 ibss.channel_type = channel_type;
4756 ibss.channel_type = NL80211_CHAN_NO_HT;
4759 ibss.channel = rdev_freq_to_chan(rdev,
4760 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
4762 if (!ibss.channel ||
4763 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
4764 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4767 /* Both channels should be able to initiate communication */
4768 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
4769 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
4770 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
4774 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
4775 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4777 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4779 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4781 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4782 struct ieee80211_supported_band *sband =
4783 wiphy->bands[ibss.channel->band];
4786 err = ieee80211_get_ratemask(sband, rates, n_rates,
4792 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
4793 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
4794 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
4797 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
4798 connkeys = nl80211_parse_connkeys(rdev,
4799 info->attrs[NL80211_ATTR_KEYS]);
4800 if (IS_ERR(connkeys))
4801 return PTR_ERR(connkeys);
4804 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
4810 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
4812 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4813 struct net_device *dev = info->user_ptr[1];
4815 if (!rdev->ops->leave_ibss)
4818 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
4821 return cfg80211_leave_ibss(rdev, dev, false);
4824 #ifdef CONFIG_NL80211_TESTMODE
4825 static struct genl_multicast_group nl80211_testmode_mcgrp = {
4829 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
4831 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4834 if (!info->attrs[NL80211_ATTR_TESTDATA])
4838 if (rdev->ops->testmode_cmd) {
4839 rdev->testmode_info = info;
4840 err = rdev->ops->testmode_cmd(&rdev->wiphy,
4841 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
4842 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
4843 rdev->testmode_info = NULL;
4849 static int nl80211_testmode_dump(struct sk_buff *skb,
4850 struct netlink_callback *cb)
4852 struct cfg80211_registered_device *rdev;
4860 * 0 is a valid index, but not valid for args[0],
4861 * so we need to offset by 1.
4863 phy_idx = cb->args[0] - 1;
4865 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
4866 nl80211_fam.attrbuf, nl80211_fam.maxattr,
4870 if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
4871 phy_idx = nla_get_u32(
4872 nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
4874 struct net_device *netdev;
4876 err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
4877 nl80211_fam.attrbuf,
4882 phy_idx = rdev->wiphy_idx;
4883 cfg80211_unlock_rdev(rdev);
4885 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
4887 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
4891 data = nla_data((void *)cb->args[1]);
4892 data_len = nla_len((void *)cb->args[1]);
4895 mutex_lock(&cfg80211_mutex);
4896 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
4898 mutex_unlock(&cfg80211_mutex);
4901 cfg80211_lock_rdev(rdev);
4902 mutex_unlock(&cfg80211_mutex);
4904 if (!rdev->ops->testmode_dump) {
4910 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
4911 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4912 NL80211_CMD_TESTMODE);
4913 struct nlattr *tmdata;
4915 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx) < 0) {
4916 genlmsg_cancel(skb, hdr);
4920 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4922 genlmsg_cancel(skb, hdr);
4925 err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
4927 nla_nest_end(skb, tmdata);
4929 if (err == -ENOBUFS || err == -ENOENT) {
4930 genlmsg_cancel(skb, hdr);
4933 genlmsg_cancel(skb, hdr);
4937 genlmsg_end(skb, hdr);
4942 cb->args[0] = phy_idx + 1;
4944 cfg80211_unlock_rdev(rdev);
4948 static struct sk_buff *
4949 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
4950 int approxlen, u32 pid, u32 seq, gfp_t gfp)
4952 struct sk_buff *skb;
4954 struct nlattr *data;
4956 skb = nlmsg_new(approxlen + 100, gfp);
4960 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
4966 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4967 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
4969 ((void **)skb->cb)[0] = rdev;
4970 ((void **)skb->cb)[1] = hdr;
4971 ((void **)skb->cb)[2] = data;
4980 struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
4983 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
4985 if (WARN_ON(!rdev->testmode_info))
4988 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
4989 rdev->testmode_info->snd_pid,
4990 rdev->testmode_info->snd_seq,
4993 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
4995 int cfg80211_testmode_reply(struct sk_buff *skb)
4997 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
4998 void *hdr = ((void **)skb->cb)[1];
4999 struct nlattr *data = ((void **)skb->cb)[2];
5001 if (WARN_ON(!rdev->testmode_info)) {
5006 nla_nest_end(skb, data);
5007 genlmsg_end(skb, hdr);
5008 return genlmsg_reply(skb, rdev->testmode_info);
5010 EXPORT_SYMBOL(cfg80211_testmode_reply);
5012 struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
5013 int approxlen, gfp_t gfp)
5015 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
5017 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
5019 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
5021 void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
5023 void *hdr = ((void **)skb->cb)[1];
5024 struct nlattr *data = ((void **)skb->cb)[2];
5026 nla_nest_end(skb, data);
5027 genlmsg_end(skb, hdr);
5028 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
5030 EXPORT_SYMBOL(cfg80211_testmode_event);
5033 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
5035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5036 struct net_device *dev = info->user_ptr[1];
5037 struct cfg80211_connect_params connect;
5038 struct wiphy *wiphy;
5039 struct cfg80211_cached_keys *connkeys = NULL;
5042 memset(&connect, 0, sizeof(connect));
5044 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5047 if (!info->attrs[NL80211_ATTR_SSID] ||
5048 !nla_len(info->attrs[NL80211_ATTR_SSID]))
5051 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5053 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
5054 if (!nl80211_valid_auth_type(connect.auth_type))
5057 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5059 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
5061 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
5062 NL80211_MAX_NR_CIPHER_SUITES);
5066 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5067 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5070 wiphy = &rdev->wiphy;
5072 if (info->attrs[NL80211_ATTR_MAC])
5073 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5074 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5075 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5077 if (info->attrs[NL80211_ATTR_IE]) {
5078 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5079 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5082 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
5084 ieee80211_get_channel(wiphy,
5085 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
5086 if (!connect.channel ||
5087 connect.channel->flags & IEEE80211_CHAN_DISABLED)
5091 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
5092 connkeys = nl80211_parse_connkeys(rdev,
5093 info->attrs[NL80211_ATTR_KEYS]);
5094 if (IS_ERR(connkeys))
5095 return PTR_ERR(connkeys);
5098 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
5099 connect.flags |= ASSOC_REQ_DISABLE_HT;
5101 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5102 memcpy(&connect.ht_capa_mask,
5103 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
5104 sizeof(connect.ht_capa_mask));
5106 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
5107 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
5109 memcpy(&connect.ht_capa,
5110 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
5111 sizeof(connect.ht_capa));
5114 err = cfg80211_connect(rdev, dev, &connect, connkeys);
5120 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
5122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5123 struct net_device *dev = info->user_ptr[1];
5126 if (!info->attrs[NL80211_ATTR_REASON_CODE])
5127 reason = WLAN_REASON_DEAUTH_LEAVING;
5129 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5134 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5135 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5138 return cfg80211_disconnect(rdev, dev, reason, true);
5141 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
5143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5148 if (!info->attrs[NL80211_ATTR_PID])
5151 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
5153 net = get_net_ns_by_pid(pid);
5155 return PTR_ERR(net);
5159 /* check if anything to do */
5160 if (!net_eq(wiphy_net(&rdev->wiphy), net))
5161 err = cfg80211_switch_netns(rdev, net);
5167 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
5169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5170 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
5171 struct cfg80211_pmksa *pmksa) = NULL;
5172 struct net_device *dev = info->user_ptr[1];
5173 struct cfg80211_pmksa pmksa;
5175 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
5177 if (!info->attrs[NL80211_ATTR_MAC])
5180 if (!info->attrs[NL80211_ATTR_PMKID])
5183 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
5184 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
5186 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5187 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5190 switch (info->genlhdr->cmd) {
5191 case NL80211_CMD_SET_PMKSA:
5192 rdev_ops = rdev->ops->set_pmksa;
5194 case NL80211_CMD_DEL_PMKSA:
5195 rdev_ops = rdev->ops->del_pmksa;
5205 return rdev_ops(&rdev->wiphy, dev, &pmksa);
5208 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
5210 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5211 struct net_device *dev = info->user_ptr[1];
5213 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5214 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5217 if (!rdev->ops->flush_pmksa)
5220 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
5223 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
5225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5226 struct net_device *dev = info->user_ptr[1];
5227 u8 action_code, dialog_token;
5231 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5232 !rdev->ops->tdls_mgmt)
5235 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
5236 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
5237 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
5238 !info->attrs[NL80211_ATTR_IE] ||
5239 !info->attrs[NL80211_ATTR_MAC])
5242 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5243 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
5244 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
5245 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
5247 return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
5248 dialog_token, status_code,
5249 nla_data(info->attrs[NL80211_ATTR_IE]),
5250 nla_len(info->attrs[NL80211_ATTR_IE]));
5253 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
5255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5256 struct net_device *dev = info->user_ptr[1];
5257 enum nl80211_tdls_operation operation;
5260 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
5261 !rdev->ops->tdls_oper)
5264 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
5265 !info->attrs[NL80211_ATTR_MAC])
5268 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
5269 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
5271 return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
5274 static int nl80211_remain_on_channel(struct sk_buff *skb,
5275 struct genl_info *info)
5277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5278 struct net_device *dev = info->user_ptr[1];
5279 struct ieee80211_channel *chan;
5280 struct sk_buff *msg;
5283 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5287 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5288 !info->attrs[NL80211_ATTR_DURATION])
5291 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5294 * We should be on that channel for at least one jiffie,
5295 * and more than 5 seconds seems excessive.
5297 if (!duration || !msecs_to_jiffies(duration) ||
5298 duration > rdev->wiphy.max_remain_on_channel_duration)
5301 if (!rdev->ops->remain_on_channel ||
5302 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
5305 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5306 channel_type = nla_get_u32(
5307 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5308 if (channel_type != NL80211_CHAN_NO_HT &&
5309 channel_type != NL80211_CHAN_HT20 &&
5310 channel_type != NL80211_CHAN_HT40PLUS &&
5311 channel_type != NL80211_CHAN_HT40MINUS)
5315 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5316 chan = rdev_freq_to_chan(rdev, freq, channel_type);
5320 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5324 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5325 NL80211_CMD_REMAIN_ON_CHANNEL);
5332 err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
5333 channel_type, duration, &cookie);
5338 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5340 genlmsg_end(msg, hdr);
5342 return genlmsg_reply(msg, info);
5351 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
5352 struct genl_info *info)
5354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5355 struct net_device *dev = info->user_ptr[1];
5358 if (!info->attrs[NL80211_ATTR_COOKIE])
5361 if (!rdev->ops->cancel_remain_on_channel)
5364 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5366 return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
5369 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
5370 u8 *rates, u8 rates_len)
5375 for (i = 0; i < rates_len; i++) {
5376 int rate = (rates[i] & 0x7f) * 5;
5378 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
5379 struct ieee80211_rate *srate =
5380 &sband->bitrates[ridx];
5381 if (rate == srate->bitrate) {
5386 if (ridx == sband->n_bitrates)
5387 return 0; /* rate not found */
5393 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
5394 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
5395 .len = NL80211_MAX_SUPP_RATES },
5398 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
5399 struct genl_info *info)
5401 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
5402 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5403 struct cfg80211_bitrate_mask mask;
5405 struct net_device *dev = info->user_ptr[1];
5406 struct nlattr *tx_rates;
5407 struct ieee80211_supported_band *sband;
5409 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
5412 if (!rdev->ops->set_bitrate_mask)
5415 memset(&mask, 0, sizeof(mask));
5416 /* Default to all rates enabled */
5417 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
5418 sband = rdev->wiphy.bands[i];
5419 mask.control[i].legacy =
5420 sband ? (1 << sband->n_bitrates) - 1 : 0;
5424 * The nested attribute uses enum nl80211_band as the index. This maps
5425 * directly to the enum ieee80211_band values used in cfg80211.
5427 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
5429 enum ieee80211_band band = nla_type(tx_rates);
5430 if (band < 0 || band >= IEEE80211_NUM_BANDS)
5432 sband = rdev->wiphy.bands[band];
5435 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
5436 nla_len(tx_rates), nl80211_txattr_policy);
5437 if (tb[NL80211_TXRATE_LEGACY]) {
5438 mask.control[band].legacy = rateset_to_mask(
5440 nla_data(tb[NL80211_TXRATE_LEGACY]),
5441 nla_len(tb[NL80211_TXRATE_LEGACY]));
5442 if (mask.control[band].legacy == 0)
5447 return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
5450 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
5452 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5453 struct net_device *dev = info->user_ptr[1];
5454 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
5456 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
5459 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
5460 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
5462 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5463 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5464 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5465 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5466 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5467 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
5468 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5471 /* not much point in registering if we can't reply */
5472 if (!rdev->ops->mgmt_tx)
5475 return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
5477 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
5478 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
5481 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
5483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5484 struct net_device *dev = info->user_ptr[1];
5485 struct ieee80211_channel *chan;
5486 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
5487 bool channel_type_valid = false;
5492 struct sk_buff *msg = NULL;
5493 unsigned int wait = 0;
5494 bool offchan, no_cck, dont_wait_for_ack;
5496 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
5498 if (!info->attrs[NL80211_ATTR_FRAME] ||
5499 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
5502 if (!rdev->ops->mgmt_tx)
5505 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5506 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5507 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5508 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5509 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5510 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
5511 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5514 if (info->attrs[NL80211_ATTR_DURATION]) {
5515 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5517 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5520 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
5521 channel_type = nla_get_u32(
5522 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
5523 if (channel_type != NL80211_CHAN_NO_HT &&
5524 channel_type != NL80211_CHAN_HT20 &&
5525 channel_type != NL80211_CHAN_HT40PLUS &&
5526 channel_type != NL80211_CHAN_HT40MINUS)
5528 channel_type_valid = true;
5531 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
5533 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5536 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5538 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
5539 chan = rdev_freq_to_chan(rdev, freq, channel_type);
5543 if (!dont_wait_for_ack) {
5544 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5548 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5557 err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
5558 channel_type_valid, wait,
5559 nla_data(info->attrs[NL80211_ATTR_FRAME]),
5560 nla_len(info->attrs[NL80211_ATTR_FRAME]),
5561 no_cck, dont_wait_for_ack, &cookie);
5566 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
5568 genlmsg_end(msg, hdr);
5569 return genlmsg_reply(msg, info);
5581 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
5583 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5584 struct net_device *dev = info->user_ptr[1];
5587 if (!info->attrs[NL80211_ATTR_COOKIE])
5590 if (!rdev->ops->mgmt_tx_cancel_wait)
5593 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
5594 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
5595 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
5596 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5597 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5598 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5601 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
5603 return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
5606 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
5608 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5609 struct wireless_dev *wdev;
5610 struct net_device *dev = info->user_ptr[1];
5615 if (!info->attrs[NL80211_ATTR_PS_STATE])
5618 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
5620 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
5623 wdev = dev->ieee80211_ptr;
5625 if (!rdev->ops->set_power_mgmt)
5628 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
5630 if (state == wdev->ps)
5633 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
5640 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
5642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5643 enum nl80211_ps_state ps_state;
5644 struct wireless_dev *wdev;
5645 struct net_device *dev = info->user_ptr[1];
5646 struct sk_buff *msg;
5650 wdev = dev->ieee80211_ptr;
5652 if (!rdev->ops->set_power_mgmt)
5655 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5659 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5660 NL80211_CMD_GET_POWER_SAVE);
5667 ps_state = NL80211_PS_ENABLED;
5669 ps_state = NL80211_PS_DISABLED;
5671 NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
5673 genlmsg_end(msg, hdr);
5674 return genlmsg_reply(msg, info);
5683 static struct nla_policy
5684 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
5685 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
5686 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
5687 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
5690 static int nl80211_set_cqm_rssi(struct genl_info *info,
5691 s32 threshold, u32 hysteresis)
5693 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5694 struct wireless_dev *wdev;
5695 struct net_device *dev = info->user_ptr[1];
5700 wdev = dev->ieee80211_ptr;
5702 if (!rdev->ops->set_cqm_rssi_config)
5705 if (wdev->iftype != NL80211_IFTYPE_STATION &&
5706 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
5709 return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
5710 threshold, hysteresis);
5713 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
5715 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
5719 cqm = info->attrs[NL80211_ATTR_CQM];
5725 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
5726 nl80211_attr_cqm_policy);
5730 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
5731 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
5734 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
5735 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
5736 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
5744 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
5746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5747 struct net_device *dev = info->user_ptr[1];
5748 struct mesh_config cfg;
5749 struct mesh_setup setup;
5752 /* start with default */
5753 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
5754 memcpy(&setup, &default_mesh_setup, sizeof(setup));
5756 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
5757 /* and parse parameters if given */
5758 err = nl80211_parse_mesh_config(info, &cfg, NULL);
5763 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
5764 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
5767 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
5768 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
5770 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
5771 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
5772 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
5775 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
5776 /* parse additional setup parameters if given */
5777 err = nl80211_parse_mesh_setup(info, &setup);
5782 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
5785 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
5787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5788 struct net_device *dev = info->user_ptr[1];
5790 return cfg80211_leave_mesh(rdev, dev);
5793 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
5795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5796 struct sk_buff *msg;
5799 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5802 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5806 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
5807 NL80211_CMD_GET_WOWLAN);
5809 goto nla_put_failure;
5812 struct nlattr *nl_wowlan;
5814 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
5816 goto nla_put_failure;
5818 if (rdev->wowlan->any)
5819 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
5820 if (rdev->wowlan->disconnect)
5821 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
5822 if (rdev->wowlan->magic_pkt)
5823 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
5824 if (rdev->wowlan->gtk_rekey_failure)
5825 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
5826 if (rdev->wowlan->eap_identity_req)
5827 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
5828 if (rdev->wowlan->four_way_handshake)
5829 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
5830 if (rdev->wowlan->rfkill_release)
5831 NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
5832 if (rdev->wowlan->n_patterns) {
5833 struct nlattr *nl_pats, *nl_pat;
5836 nl_pats = nla_nest_start(msg,
5837 NL80211_WOWLAN_TRIG_PKT_PATTERN);
5839 goto nla_put_failure;
5841 for (i = 0; i < rdev->wowlan->n_patterns; i++) {
5842 nl_pat = nla_nest_start(msg, i + 1);
5844 goto nla_put_failure;
5845 pat_len = rdev->wowlan->patterns[i].pattern_len;
5846 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
5847 DIV_ROUND_UP(pat_len, 8),
5848 rdev->wowlan->patterns[i].mask);
5849 NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
5851 rdev->wowlan->patterns[i].pattern);
5852 nla_nest_end(msg, nl_pat);
5854 nla_nest_end(msg, nl_pats);
5857 nla_nest_end(msg, nl_wowlan);
5860 genlmsg_end(msg, hdr);
5861 return genlmsg_reply(msg, info);
5868 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
5870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5871 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
5872 struct cfg80211_wowlan no_triggers = {};
5873 struct cfg80211_wowlan new_triggers = {};
5874 struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
5877 if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
5880 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
5883 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
5884 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5885 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
5886 nl80211_wowlan_policy);
5890 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
5891 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
5893 new_triggers.any = true;
5896 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
5897 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
5899 new_triggers.disconnect = true;
5902 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
5903 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
5905 new_triggers.magic_pkt = true;
5908 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
5911 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
5912 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
5914 new_triggers.gtk_rekey_failure = true;
5917 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
5918 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
5920 new_triggers.eap_identity_req = true;
5923 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
5924 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
5926 new_triggers.four_way_handshake = true;
5929 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
5930 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
5932 new_triggers.rfkill_release = true;
5935 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
5938 int rem, pat_len, mask_len;
5939 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
5941 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5944 if (n_patterns > wowlan->n_patterns)
5947 new_triggers.patterns = kcalloc(n_patterns,
5948 sizeof(new_triggers.patterns[0]),
5950 if (!new_triggers.patterns)
5953 new_triggers.n_patterns = n_patterns;
5956 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
5958 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
5959 nla_data(pat), nla_len(pat), NULL);
5961 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
5962 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
5964 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
5965 mask_len = DIV_ROUND_UP(pat_len, 8);
5966 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
5969 if (pat_len > wowlan->pattern_max_len ||
5970 pat_len < wowlan->pattern_min_len)
5973 new_triggers.patterns[i].mask =
5974 kmalloc(mask_len + pat_len, GFP_KERNEL);
5975 if (!new_triggers.patterns[i].mask) {
5979 new_triggers.patterns[i].pattern =
5980 new_triggers.patterns[i].mask + mask_len;
5981 memcpy(new_triggers.patterns[i].mask,
5982 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
5984 new_triggers.patterns[i].pattern_len = pat_len;
5985 memcpy(new_triggers.patterns[i].pattern,
5986 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
5992 if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
5993 struct cfg80211_wowlan *ntrig;
5994 ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
6000 cfg80211_rdev_free_wowlan(rdev);
6001 rdev->wowlan = ntrig;
6004 cfg80211_rdev_free_wowlan(rdev);
6005 rdev->wowlan = NULL;
6010 for (i = 0; i < new_triggers.n_patterns; i++)
6011 kfree(new_triggers.patterns[i].mask);
6012 kfree(new_triggers.patterns);
6016 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
6018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6019 struct net_device *dev = info->user_ptr[1];
6020 struct wireless_dev *wdev = dev->ieee80211_ptr;
6021 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
6022 struct cfg80211_gtk_rekey_data rekey_data;
6025 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
6028 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
6029 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
6030 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
6031 nl80211_rekey_policy);
6035 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
6037 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
6039 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
6042 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
6044 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
6046 memcpy(rekey_data.replay_ctr,
6047 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
6048 NL80211_REPLAY_CTR_LEN);
6051 if (!wdev->current_bss) {
6056 if (!rdev->ops->set_rekey_data) {
6061 err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
6067 static int nl80211_register_unexpected_frame(struct sk_buff *skb,
6068 struct genl_info *info)
6070 struct net_device *dev = info->user_ptr[1];
6071 struct wireless_dev *wdev = dev->ieee80211_ptr;
6073 if (wdev->iftype != NL80211_IFTYPE_AP &&
6074 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6077 if (wdev->ap_unexpected_nlpid)
6080 wdev->ap_unexpected_nlpid = info->snd_pid;
6084 static int nl80211_probe_client(struct sk_buff *skb,
6085 struct genl_info *info)
6087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6088 struct net_device *dev = info->user_ptr[1];
6089 struct wireless_dev *wdev = dev->ieee80211_ptr;
6090 struct sk_buff *msg;
6096 if (wdev->iftype != NL80211_IFTYPE_AP &&
6097 wdev->iftype != NL80211_IFTYPE_P2P_GO)
6100 if (!info->attrs[NL80211_ATTR_MAC])
6103 if (!rdev->ops->probe_client)
6106 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6110 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
6111 NL80211_CMD_PROBE_CLIENT);
6118 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6120 err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
6124 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
6126 genlmsg_end(msg, hdr);
6128 return genlmsg_reply(msg, info);
6137 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
6139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6141 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
6144 if (rdev->ap_beacons_nlpid)
6147 rdev->ap_beacons_nlpid = info->snd_pid;
6152 #define NL80211_FLAG_NEED_WIPHY 0x01
6153 #define NL80211_FLAG_NEED_NETDEV 0x02
6154 #define NL80211_FLAG_NEED_RTNL 0x04
6155 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6156 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6157 NL80211_FLAG_CHECK_NETDEV_UP)
6159 static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
6160 struct genl_info *info)
6162 struct cfg80211_registered_device *rdev;
6163 struct net_device *dev;
6165 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
6170 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
6171 rdev = cfg80211_get_dev_from_info(info);
6175 return PTR_ERR(rdev);
6177 info->user_ptr[0] = rdev;
6178 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
6179 err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
6186 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
6187 !netif_running(dev)) {
6188 cfg80211_unlock_rdev(rdev);
6194 info->user_ptr[0] = rdev;
6195 info->user_ptr[1] = dev;
6201 static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
6202 struct genl_info *info)
6204 if (info->user_ptr[0])
6205 cfg80211_unlock_rdev(info->user_ptr[0]);
6206 if (info->user_ptr[1])
6207 dev_put(info->user_ptr[1]);
6208 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
6212 static struct genl_ops nl80211_ops[] = {
6214 .cmd = NL80211_CMD_GET_WIPHY,
6215 .doit = nl80211_get_wiphy,
6216 .dumpit = nl80211_dump_wiphy,
6217 .policy = nl80211_policy,
6218 /* can be retrieved by unprivileged users */
6219 .internal_flags = NL80211_FLAG_NEED_WIPHY,
6222 .cmd = NL80211_CMD_SET_WIPHY,
6223 .doit = nl80211_set_wiphy,
6224 .policy = nl80211_policy,
6225 .flags = GENL_ADMIN_PERM,
6226 .internal_flags = NL80211_FLAG_NEED_RTNL,
6229 .cmd = NL80211_CMD_GET_INTERFACE,
6230 .doit = nl80211_get_interface,
6231 .dumpit = nl80211_dump_interface,
6232 .policy = nl80211_policy,
6233 /* can be retrieved by unprivileged users */
6234 .internal_flags = NL80211_FLAG_NEED_NETDEV,
6237 .cmd = NL80211_CMD_SET_INTERFACE,
6238 .doit = nl80211_set_interface,
6239 .policy = nl80211_policy,
6240 .flags = GENL_ADMIN_PERM,
6241 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6242 NL80211_FLAG_NEED_RTNL,
6245 .cmd = NL80211_CMD_NEW_INTERFACE,
6246 .doit = nl80211_new_interface,
6247 .policy = nl80211_policy,
6248 .flags = GENL_ADMIN_PERM,
6249 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6250 NL80211_FLAG_NEED_RTNL,
6253 .cmd = NL80211_CMD_DEL_INTERFACE,
6254 .doit = nl80211_del_interface,
6255 .policy = nl80211_policy,
6256 .flags = GENL_ADMIN_PERM,
6257 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6258 NL80211_FLAG_NEED_RTNL,
6261 .cmd = NL80211_CMD_GET_KEY,
6262 .doit = nl80211_get_key,
6263 .policy = nl80211_policy,
6264 .flags = GENL_ADMIN_PERM,
6265 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6266 NL80211_FLAG_NEED_RTNL,
6269 .cmd = NL80211_CMD_SET_KEY,
6270 .doit = nl80211_set_key,
6271 .policy = nl80211_policy,
6272 .flags = GENL_ADMIN_PERM,
6273 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6274 NL80211_FLAG_NEED_RTNL,
6277 .cmd = NL80211_CMD_NEW_KEY,
6278 .doit = nl80211_new_key,
6279 .policy = nl80211_policy,
6280 .flags = GENL_ADMIN_PERM,
6281 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6282 NL80211_FLAG_NEED_RTNL,
6285 .cmd = NL80211_CMD_DEL_KEY,
6286 .doit = nl80211_del_key,
6287 .policy = nl80211_policy,
6288 .flags = GENL_ADMIN_PERM,
6289 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6290 NL80211_FLAG_NEED_RTNL,
6293 .cmd = NL80211_CMD_SET_BEACON,
6294 .policy = nl80211_policy,
6295 .flags = GENL_ADMIN_PERM,
6296 .doit = nl80211_addset_beacon,
6297 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6298 NL80211_FLAG_NEED_RTNL,
6301 .cmd = NL80211_CMD_NEW_BEACON,
6302 .policy = nl80211_policy,
6303 .flags = GENL_ADMIN_PERM,
6304 .doit = nl80211_addset_beacon,
6305 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6306 NL80211_FLAG_NEED_RTNL,
6309 .cmd = NL80211_CMD_DEL_BEACON,
6310 .policy = nl80211_policy,
6311 .flags = GENL_ADMIN_PERM,
6312 .doit = nl80211_del_beacon,
6313 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6314 NL80211_FLAG_NEED_RTNL,
6317 .cmd = NL80211_CMD_GET_STATION,
6318 .doit = nl80211_get_station,
6319 .dumpit = nl80211_dump_station,
6320 .policy = nl80211_policy,
6321 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6322 NL80211_FLAG_NEED_RTNL,
6325 .cmd = NL80211_CMD_SET_STATION,
6326 .doit = nl80211_set_station,
6327 .policy = nl80211_policy,
6328 .flags = GENL_ADMIN_PERM,
6329 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6330 NL80211_FLAG_NEED_RTNL,
6333 .cmd = NL80211_CMD_NEW_STATION,
6334 .doit = nl80211_new_station,
6335 .policy = nl80211_policy,
6336 .flags = GENL_ADMIN_PERM,
6337 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6338 NL80211_FLAG_NEED_RTNL,
6341 .cmd = NL80211_CMD_DEL_STATION,
6342 .doit = nl80211_del_station,
6343 .policy = nl80211_policy,
6344 .flags = GENL_ADMIN_PERM,
6345 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6346 NL80211_FLAG_NEED_RTNL,
6349 .cmd = NL80211_CMD_GET_MPATH,
6350 .doit = nl80211_get_mpath,
6351 .dumpit = nl80211_dump_mpath,
6352 .policy = nl80211_policy,
6353 .flags = GENL_ADMIN_PERM,
6354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6355 NL80211_FLAG_NEED_RTNL,
6358 .cmd = NL80211_CMD_SET_MPATH,
6359 .doit = nl80211_set_mpath,
6360 .policy = nl80211_policy,
6361 .flags = GENL_ADMIN_PERM,
6362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6363 NL80211_FLAG_NEED_RTNL,
6366 .cmd = NL80211_CMD_NEW_MPATH,
6367 .doit = nl80211_new_mpath,
6368 .policy = nl80211_policy,
6369 .flags = GENL_ADMIN_PERM,
6370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6371 NL80211_FLAG_NEED_RTNL,
6374 .cmd = NL80211_CMD_DEL_MPATH,
6375 .doit = nl80211_del_mpath,
6376 .policy = nl80211_policy,
6377 .flags = GENL_ADMIN_PERM,
6378 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6379 NL80211_FLAG_NEED_RTNL,
6382 .cmd = NL80211_CMD_SET_BSS,
6383 .doit = nl80211_set_bss,
6384 .policy = nl80211_policy,
6385 .flags = GENL_ADMIN_PERM,
6386 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6387 NL80211_FLAG_NEED_RTNL,
6390 .cmd = NL80211_CMD_GET_REG,
6391 .doit = nl80211_get_reg,
6392 .policy = nl80211_policy,
6393 /* can be retrieved by unprivileged users */
6396 .cmd = NL80211_CMD_SET_REG,
6397 .doit = nl80211_set_reg,
6398 .policy = nl80211_policy,
6399 .flags = GENL_ADMIN_PERM,
6402 .cmd = NL80211_CMD_REQ_SET_REG,
6403 .doit = nl80211_req_set_reg,
6404 .policy = nl80211_policy,
6405 .flags = GENL_ADMIN_PERM,
6408 .cmd = NL80211_CMD_GET_MESH_CONFIG,
6409 .doit = nl80211_get_mesh_config,
6410 .policy = nl80211_policy,
6411 /* can be retrieved by unprivileged users */
6412 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6413 NL80211_FLAG_NEED_RTNL,
6416 .cmd = NL80211_CMD_SET_MESH_CONFIG,
6417 .doit = nl80211_update_mesh_config,
6418 .policy = nl80211_policy,
6419 .flags = GENL_ADMIN_PERM,
6420 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6421 NL80211_FLAG_NEED_RTNL,
6424 .cmd = NL80211_CMD_TRIGGER_SCAN,
6425 .doit = nl80211_trigger_scan,
6426 .policy = nl80211_policy,
6427 .flags = GENL_ADMIN_PERM,
6428 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6429 NL80211_FLAG_NEED_RTNL,
6432 .cmd = NL80211_CMD_GET_SCAN,
6433 .policy = nl80211_policy,
6434 .dumpit = nl80211_dump_scan,
6437 .cmd = NL80211_CMD_START_SCHED_SCAN,
6438 .doit = nl80211_start_sched_scan,
6439 .policy = nl80211_policy,
6440 .flags = GENL_ADMIN_PERM,
6441 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6442 NL80211_FLAG_NEED_RTNL,
6445 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
6446 .doit = nl80211_stop_sched_scan,
6447 .policy = nl80211_policy,
6448 .flags = GENL_ADMIN_PERM,
6449 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6450 NL80211_FLAG_NEED_RTNL,
6453 .cmd = NL80211_CMD_AUTHENTICATE,
6454 .doit = nl80211_authenticate,
6455 .policy = nl80211_policy,
6456 .flags = GENL_ADMIN_PERM,
6457 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6458 NL80211_FLAG_NEED_RTNL,
6461 .cmd = NL80211_CMD_ASSOCIATE,
6462 .doit = nl80211_associate,
6463 .policy = nl80211_policy,
6464 .flags = GENL_ADMIN_PERM,
6465 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6466 NL80211_FLAG_NEED_RTNL,
6469 .cmd = NL80211_CMD_DEAUTHENTICATE,
6470 .doit = nl80211_deauthenticate,
6471 .policy = nl80211_policy,
6472 .flags = GENL_ADMIN_PERM,
6473 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6474 NL80211_FLAG_NEED_RTNL,
6477 .cmd = NL80211_CMD_DISASSOCIATE,
6478 .doit = nl80211_disassociate,
6479 .policy = nl80211_policy,
6480 .flags = GENL_ADMIN_PERM,
6481 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6482 NL80211_FLAG_NEED_RTNL,
6485 .cmd = NL80211_CMD_JOIN_IBSS,
6486 .doit = nl80211_join_ibss,
6487 .policy = nl80211_policy,
6488 .flags = GENL_ADMIN_PERM,
6489 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6490 NL80211_FLAG_NEED_RTNL,
6493 .cmd = NL80211_CMD_LEAVE_IBSS,
6494 .doit = nl80211_leave_ibss,
6495 .policy = nl80211_policy,
6496 .flags = GENL_ADMIN_PERM,
6497 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6498 NL80211_FLAG_NEED_RTNL,
6500 #ifdef CONFIG_NL80211_TESTMODE
6502 .cmd = NL80211_CMD_TESTMODE,
6503 .doit = nl80211_testmode_do,
6504 .dumpit = nl80211_testmode_dump,
6505 .policy = nl80211_policy,
6506 .flags = GENL_ADMIN_PERM,
6507 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6508 NL80211_FLAG_NEED_RTNL,
6512 .cmd = NL80211_CMD_CONNECT,
6513 .doit = nl80211_connect,
6514 .policy = nl80211_policy,
6515 .flags = GENL_ADMIN_PERM,
6516 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6517 NL80211_FLAG_NEED_RTNL,
6520 .cmd = NL80211_CMD_DISCONNECT,
6521 .doit = nl80211_disconnect,
6522 .policy = nl80211_policy,
6523 .flags = GENL_ADMIN_PERM,
6524 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6525 NL80211_FLAG_NEED_RTNL,
6528 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
6529 .doit = nl80211_wiphy_netns,
6530 .policy = nl80211_policy,
6531 .flags = GENL_ADMIN_PERM,
6532 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6533 NL80211_FLAG_NEED_RTNL,
6536 .cmd = NL80211_CMD_GET_SURVEY,
6537 .policy = nl80211_policy,
6538 .dumpit = nl80211_dump_survey,
6541 .cmd = NL80211_CMD_SET_PMKSA,
6542 .doit = nl80211_setdel_pmksa,
6543 .policy = nl80211_policy,
6544 .flags = GENL_ADMIN_PERM,
6545 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6546 NL80211_FLAG_NEED_RTNL,
6549 .cmd = NL80211_CMD_DEL_PMKSA,
6550 .doit = nl80211_setdel_pmksa,
6551 .policy = nl80211_policy,
6552 .flags = GENL_ADMIN_PERM,
6553 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6554 NL80211_FLAG_NEED_RTNL,
6557 .cmd = NL80211_CMD_FLUSH_PMKSA,
6558 .doit = nl80211_flush_pmksa,
6559 .policy = nl80211_policy,
6560 .flags = GENL_ADMIN_PERM,
6561 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6562 NL80211_FLAG_NEED_RTNL,
6565 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
6566 .doit = nl80211_remain_on_channel,
6567 .policy = nl80211_policy,
6568 .flags = GENL_ADMIN_PERM,
6569 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6570 NL80211_FLAG_NEED_RTNL,
6573 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
6574 .doit = nl80211_cancel_remain_on_channel,
6575 .policy = nl80211_policy,
6576 .flags = GENL_ADMIN_PERM,
6577 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6578 NL80211_FLAG_NEED_RTNL,
6581 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
6582 .doit = nl80211_set_tx_bitrate_mask,
6583 .policy = nl80211_policy,
6584 .flags = GENL_ADMIN_PERM,
6585 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6586 NL80211_FLAG_NEED_RTNL,
6589 .cmd = NL80211_CMD_REGISTER_FRAME,
6590 .doit = nl80211_register_mgmt,
6591 .policy = nl80211_policy,
6592 .flags = GENL_ADMIN_PERM,
6593 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6594 NL80211_FLAG_NEED_RTNL,
6597 .cmd = NL80211_CMD_FRAME,
6598 .doit = nl80211_tx_mgmt,
6599 .policy = nl80211_policy,
6600 .flags = GENL_ADMIN_PERM,
6601 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6602 NL80211_FLAG_NEED_RTNL,
6605 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
6606 .doit = nl80211_tx_mgmt_cancel_wait,
6607 .policy = nl80211_policy,
6608 .flags = GENL_ADMIN_PERM,
6609 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6610 NL80211_FLAG_NEED_RTNL,
6613 .cmd = NL80211_CMD_SET_POWER_SAVE,
6614 .doit = nl80211_set_power_save,
6615 .policy = nl80211_policy,
6616 .flags = GENL_ADMIN_PERM,
6617 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6618 NL80211_FLAG_NEED_RTNL,
6621 .cmd = NL80211_CMD_GET_POWER_SAVE,
6622 .doit = nl80211_get_power_save,
6623 .policy = nl80211_policy,
6624 /* can be retrieved by unprivileged users */
6625 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6626 NL80211_FLAG_NEED_RTNL,
6629 .cmd = NL80211_CMD_SET_CQM,
6630 .doit = nl80211_set_cqm,
6631 .policy = nl80211_policy,
6632 .flags = GENL_ADMIN_PERM,
6633 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6634 NL80211_FLAG_NEED_RTNL,
6637 .cmd = NL80211_CMD_SET_CHANNEL,
6638 .doit = nl80211_set_channel,
6639 .policy = nl80211_policy,
6640 .flags = GENL_ADMIN_PERM,
6641 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6642 NL80211_FLAG_NEED_RTNL,
6645 .cmd = NL80211_CMD_SET_WDS_PEER,
6646 .doit = nl80211_set_wds_peer,
6647 .policy = nl80211_policy,
6648 .flags = GENL_ADMIN_PERM,
6649 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6650 NL80211_FLAG_NEED_RTNL,
6653 .cmd = NL80211_CMD_JOIN_MESH,
6654 .doit = nl80211_join_mesh,
6655 .policy = nl80211_policy,
6656 .flags = GENL_ADMIN_PERM,
6657 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6658 NL80211_FLAG_NEED_RTNL,
6661 .cmd = NL80211_CMD_LEAVE_MESH,
6662 .doit = nl80211_leave_mesh,
6663 .policy = nl80211_policy,
6664 .flags = GENL_ADMIN_PERM,
6665 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6666 NL80211_FLAG_NEED_RTNL,
6669 .cmd = NL80211_CMD_GET_WOWLAN,
6670 .doit = nl80211_get_wowlan,
6671 .policy = nl80211_policy,
6672 /* can be retrieved by unprivileged users */
6673 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6674 NL80211_FLAG_NEED_RTNL,
6677 .cmd = NL80211_CMD_SET_WOWLAN,
6678 .doit = nl80211_set_wowlan,
6679 .policy = nl80211_policy,
6680 .flags = GENL_ADMIN_PERM,
6681 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6682 NL80211_FLAG_NEED_RTNL,
6685 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
6686 .doit = nl80211_set_rekey_data,
6687 .policy = nl80211_policy,
6688 .flags = GENL_ADMIN_PERM,
6689 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6690 NL80211_FLAG_NEED_RTNL,
6693 .cmd = NL80211_CMD_TDLS_MGMT,
6694 .doit = nl80211_tdls_mgmt,
6695 .policy = nl80211_policy,
6696 .flags = GENL_ADMIN_PERM,
6697 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6698 NL80211_FLAG_NEED_RTNL,
6701 .cmd = NL80211_CMD_TDLS_OPER,
6702 .doit = nl80211_tdls_oper,
6703 .policy = nl80211_policy,
6704 .flags = GENL_ADMIN_PERM,
6705 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
6706 NL80211_FLAG_NEED_RTNL,
6709 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
6710 .doit = nl80211_register_unexpected_frame,
6711 .policy = nl80211_policy,
6712 .flags = GENL_ADMIN_PERM,
6713 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6714 NL80211_FLAG_NEED_RTNL,
6717 .cmd = NL80211_CMD_PROBE_CLIENT,
6718 .doit = nl80211_probe_client,
6719 .policy = nl80211_policy,
6720 .flags = GENL_ADMIN_PERM,
6721 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6722 NL80211_FLAG_NEED_RTNL,
6725 .cmd = NL80211_CMD_REGISTER_BEACONS,
6726 .doit = nl80211_register_beacons,
6727 .policy = nl80211_policy,
6728 .flags = GENL_ADMIN_PERM,
6729 .internal_flags = NL80211_FLAG_NEED_WIPHY |
6730 NL80211_FLAG_NEED_RTNL,
6733 .cmd = NL80211_CMD_SET_NOACK_MAP,
6734 .doit = nl80211_set_noack_map,
6735 .policy = nl80211_policy,
6736 .flags = GENL_ADMIN_PERM,
6737 .internal_flags = NL80211_FLAG_NEED_NETDEV |
6738 NL80211_FLAG_NEED_RTNL,
6743 static struct genl_multicast_group nl80211_mlme_mcgrp = {
6747 /* multicast groups */
6748 static struct genl_multicast_group nl80211_config_mcgrp = {
6751 static struct genl_multicast_group nl80211_scan_mcgrp = {
6754 static struct genl_multicast_group nl80211_regulatory_mcgrp = {
6755 .name = "regulatory",
6758 /* notification functions */
6760 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
6762 struct sk_buff *msg;
6764 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6768 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
6773 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6774 nl80211_config_mcgrp.id, GFP_KERNEL);
6777 static int nl80211_add_scan_req(struct sk_buff *msg,
6778 struct cfg80211_registered_device *rdev)
6780 struct cfg80211_scan_request *req = rdev->scan_req;
6781 struct nlattr *nest;
6784 ASSERT_RDEV_LOCK(rdev);
6789 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
6791 goto nla_put_failure;
6792 for (i = 0; i < req->n_ssids; i++)
6793 NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
6794 nla_nest_end(msg, nest);
6796 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
6798 goto nla_put_failure;
6799 for (i = 0; i < req->n_channels; i++)
6800 NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
6801 nla_nest_end(msg, nest);
6804 NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
6811 static int nl80211_send_scan_msg(struct sk_buff *msg,
6812 struct cfg80211_registered_device *rdev,
6813 struct net_device *netdev,
6814 u32 pid, u32 seq, int flags,
6819 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6823 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6824 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6826 /* ignore errors and send incomplete event anyway */
6827 nl80211_add_scan_req(msg, rdev);
6829 return genlmsg_end(msg, hdr);
6832 genlmsg_cancel(msg, hdr);
6837 nl80211_send_sched_scan_msg(struct sk_buff *msg,
6838 struct cfg80211_registered_device *rdev,
6839 struct net_device *netdev,
6840 u32 pid, u32 seq, int flags, u32 cmd)
6844 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
6848 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
6849 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
6851 return genlmsg_end(msg, hdr);
6854 genlmsg_cancel(msg, hdr);
6858 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
6859 struct net_device *netdev)
6861 struct sk_buff *msg;
6863 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6867 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6868 NL80211_CMD_TRIGGER_SCAN) < 0) {
6873 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6874 nl80211_scan_mcgrp.id, GFP_KERNEL);
6877 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
6878 struct net_device *netdev)
6880 struct sk_buff *msg;
6882 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6886 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6887 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
6892 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6893 nl80211_scan_mcgrp.id, GFP_KERNEL);
6896 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
6897 struct net_device *netdev)
6899 struct sk_buff *msg;
6901 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6905 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
6906 NL80211_CMD_SCAN_ABORTED) < 0) {
6911 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6912 nl80211_scan_mcgrp.id, GFP_KERNEL);
6915 void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
6916 struct net_device *netdev)
6918 struct sk_buff *msg;
6920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6924 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
6925 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
6930 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6931 nl80211_scan_mcgrp.id, GFP_KERNEL);
6934 void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
6935 struct net_device *netdev, u32 cmd)
6937 struct sk_buff *msg;
6939 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
6943 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
6948 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
6949 nl80211_scan_mcgrp.id, GFP_KERNEL);
6953 * This can happen on global regulatory changes or device specific settings
6954 * based on custom world regulatory domains.
6956 void nl80211_send_reg_change_event(struct regulatory_request *request)
6958 struct sk_buff *msg;
6961 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6965 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
6971 /* Userspace can always count this one always being set */
6972 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
6974 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
6975 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6976 NL80211_REGDOM_TYPE_WORLD);
6977 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
6978 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6979 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
6980 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
6982 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6983 NL80211_REGDOM_TYPE_INTERSECTION);
6985 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
6986 NL80211_REGDOM_TYPE_COUNTRY);
6987 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
6990 if (wiphy_idx_valid(request->wiphy_idx))
6991 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
6993 genlmsg_end(msg, hdr);
6996 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7003 genlmsg_cancel(msg, hdr);
7007 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
7008 struct net_device *netdev,
7009 const u8 *buf, size_t len,
7010 enum nl80211_commands cmd, gfp_t gfp)
7012 struct sk_buff *msg;
7015 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7019 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7025 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7026 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7027 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7029 genlmsg_end(msg, hdr);
7031 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7032 nl80211_mlme_mcgrp.id, gfp);
7036 genlmsg_cancel(msg, hdr);
7040 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
7041 struct net_device *netdev, const u8 *buf,
7042 size_t len, gfp_t gfp)
7044 nl80211_send_mlme_event(rdev, netdev, buf, len,
7045 NL80211_CMD_AUTHENTICATE, gfp);
7048 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
7049 struct net_device *netdev, const u8 *buf,
7050 size_t len, gfp_t gfp)
7052 nl80211_send_mlme_event(rdev, netdev, buf, len,
7053 NL80211_CMD_ASSOCIATE, gfp);
7056 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
7057 struct net_device *netdev, const u8 *buf,
7058 size_t len, gfp_t gfp)
7060 nl80211_send_mlme_event(rdev, netdev, buf, len,
7061 NL80211_CMD_DEAUTHENTICATE, gfp);
7064 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7065 struct net_device *netdev, const u8 *buf,
7066 size_t len, gfp_t gfp)
7068 nl80211_send_mlme_event(rdev, netdev, buf, len,
7069 NL80211_CMD_DISASSOCIATE, gfp);
7072 void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
7073 struct net_device *netdev, const u8 *buf,
7074 size_t len, gfp_t gfp)
7076 nl80211_send_mlme_event(rdev, netdev, buf, len,
7077 NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
7080 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
7081 struct net_device *netdev, const u8 *buf,
7082 size_t len, gfp_t gfp)
7084 nl80211_send_mlme_event(rdev, netdev, buf, len,
7085 NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
7088 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
7089 struct net_device *netdev, int cmd,
7090 const u8 *addr, gfp_t gfp)
7092 struct sk_buff *msg;
7095 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7099 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7105 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7106 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7107 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
7108 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7110 genlmsg_end(msg, hdr);
7112 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7113 nl80211_mlme_mcgrp.id, gfp);
7117 genlmsg_cancel(msg, hdr);
7121 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
7122 struct net_device *netdev, const u8 *addr,
7125 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
7129 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
7130 struct net_device *netdev, const u8 *addr,
7133 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
7137 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
7138 struct net_device *netdev, const u8 *bssid,
7139 const u8 *req_ie, size_t req_ie_len,
7140 const u8 *resp_ie, size_t resp_ie_len,
7141 u16 status, gfp_t gfp)
7143 struct sk_buff *msg;
7146 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7150 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
7156 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7157 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7159 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7160 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
7162 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
7164 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
7166 genlmsg_end(msg, hdr);
7168 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7169 nl80211_mlme_mcgrp.id, gfp);
7173 genlmsg_cancel(msg, hdr);
7178 void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
7179 struct net_device *netdev, const u8 *bssid,
7180 const u8 *req_ie, size_t req_ie_len,
7181 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
7183 struct sk_buff *msg;
7186 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7190 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
7196 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7197 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7198 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7200 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
7202 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
7204 genlmsg_end(msg, hdr);
7206 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7207 nl80211_mlme_mcgrp.id, gfp);
7211 genlmsg_cancel(msg, hdr);
7216 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
7217 struct net_device *netdev, u16 reason,
7218 const u8 *ie, size_t ie_len, bool from_ap)
7220 struct sk_buff *msg;
7223 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
7227 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
7233 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7234 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7235 if (from_ap && reason)
7236 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
7238 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
7240 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
7242 genlmsg_end(msg, hdr);
7244 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7245 nl80211_mlme_mcgrp.id, GFP_KERNEL);
7249 genlmsg_cancel(msg, hdr);
7254 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
7255 struct net_device *netdev, const u8 *bssid,
7258 struct sk_buff *msg;
7261 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7265 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
7271 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7272 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7273 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7275 genlmsg_end(msg, hdr);
7277 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7278 nl80211_mlme_mcgrp.id, gfp);
7282 genlmsg_cancel(msg, hdr);
7286 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
7287 struct net_device *netdev,
7288 const u8 *macaddr, const u8* ie, u8 ie_len,
7291 struct sk_buff *msg;
7294 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7298 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
7304 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7305 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7306 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
7308 NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
7310 genlmsg_end(msg, hdr);
7312 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7313 nl80211_mlme_mcgrp.id, gfp);
7317 genlmsg_cancel(msg, hdr);
7321 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
7322 struct net_device *netdev, const u8 *addr,
7323 enum nl80211_key_type key_type, int key_id,
7324 const u8 *tsc, gfp_t gfp)
7326 struct sk_buff *msg;
7329 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7333 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
7339 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7340 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7342 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7343 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
7345 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
7347 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
7349 genlmsg_end(msg, hdr);
7351 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7352 nl80211_mlme_mcgrp.id, gfp);
7356 genlmsg_cancel(msg, hdr);
7360 void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
7361 struct ieee80211_channel *channel_before,
7362 struct ieee80211_channel *channel_after)
7364 struct sk_buff *msg;
7366 struct nlattr *nl_freq;
7368 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
7372 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
7379 * Since we are applying the beacon hint to a wiphy we know its
7380 * wiphy_idx is valid
7382 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
7385 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
7387 goto nla_put_failure;
7388 if (nl80211_msg_put_channel(msg, channel_before))
7389 goto nla_put_failure;
7390 nla_nest_end(msg, nl_freq);
7393 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
7395 goto nla_put_failure;
7396 if (nl80211_msg_put_channel(msg, channel_after))
7397 goto nla_put_failure;
7398 nla_nest_end(msg, nl_freq);
7400 genlmsg_end(msg, hdr);
7403 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
7410 genlmsg_cancel(msg, hdr);
7414 static void nl80211_send_remain_on_chan_event(
7415 int cmd, struct cfg80211_registered_device *rdev,
7416 struct net_device *netdev, u64 cookie,
7417 struct ieee80211_channel *chan,
7418 enum nl80211_channel_type channel_type,
7419 unsigned int duration, gfp_t gfp)
7421 struct sk_buff *msg;
7424 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7428 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7434 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7435 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7436 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
7437 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
7438 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7440 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
7441 NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
7443 genlmsg_end(msg, hdr);
7445 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7446 nl80211_mlme_mcgrp.id, gfp);
7450 genlmsg_cancel(msg, hdr);
7454 void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
7455 struct net_device *netdev, u64 cookie,
7456 struct ieee80211_channel *chan,
7457 enum nl80211_channel_type channel_type,
7458 unsigned int duration, gfp_t gfp)
7460 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
7461 rdev, netdev, cookie, chan,
7462 channel_type, duration, gfp);
7465 void nl80211_send_remain_on_channel_cancel(
7466 struct cfg80211_registered_device *rdev, struct net_device *netdev,
7467 u64 cookie, struct ieee80211_channel *chan,
7468 enum nl80211_channel_type channel_type, gfp_t gfp)
7470 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
7471 rdev, netdev, cookie, chan,
7472 channel_type, 0, gfp);
7475 void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
7476 struct net_device *dev, const u8 *mac_addr,
7477 struct station_info *sinfo, gfp_t gfp)
7479 struct sk_buff *msg;
7481 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7485 if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) {
7490 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7491 nl80211_mlme_mcgrp.id, gfp);
7494 void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
7495 struct net_device *dev, const u8 *mac_addr,
7498 struct sk_buff *msg;
7501 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7505 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
7511 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7512 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
7514 genlmsg_end(msg, hdr);
7516 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7517 nl80211_mlme_mcgrp.id, gfp);
7521 genlmsg_cancel(msg, hdr);
7525 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
7526 const u8 *addr, gfp_t gfp)
7528 struct wireless_dev *wdev = dev->ieee80211_ptr;
7529 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7530 struct sk_buff *msg;
7533 u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
7538 msg = nlmsg_new(100, gfp);
7542 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
7548 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7549 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7550 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7552 err = genlmsg_end(msg, hdr);
7558 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7562 genlmsg_cancel(msg, hdr);
7567 bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
7569 return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
7573 bool nl80211_unexpected_4addr_frame(struct net_device *dev,
7574 const u8 *addr, gfp_t gfp)
7576 return __nl80211_unexpected_frame(dev,
7577 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
7581 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
7582 struct net_device *netdev, u32 nlpid,
7583 int freq, const u8 *buf, size_t len, gfp_t gfp)
7585 struct sk_buff *msg;
7588 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7592 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
7598 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7599 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7600 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7601 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7603 genlmsg_end(msg, hdr);
7605 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7608 genlmsg_cancel(msg, hdr);
7613 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
7614 struct net_device *netdev, u64 cookie,
7615 const u8 *buf, size_t len, bool ack,
7618 struct sk_buff *msg;
7621 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
7625 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
7631 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7632 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7633 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
7634 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7636 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7638 genlmsg_end(msg, hdr);
7640 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
7644 genlmsg_cancel(msg, hdr);
7649 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
7650 struct net_device *netdev,
7651 enum nl80211_cqm_rssi_threshold_event rssi_event,
7654 struct sk_buff *msg;
7655 struct nlattr *pinfoattr;
7658 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7662 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7668 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7669 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7671 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7673 goto nla_put_failure;
7675 NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
7678 nla_nest_end(msg, pinfoattr);
7680 genlmsg_end(msg, hdr);
7682 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7683 nl80211_mlme_mcgrp.id, gfp);
7687 genlmsg_cancel(msg, hdr);
7691 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
7692 struct net_device *netdev, const u8 *bssid,
7693 const u8 *replay_ctr, gfp_t gfp)
7695 struct sk_buff *msg;
7696 struct nlattr *rekey_attr;
7699 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7703 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
7709 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7710 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7711 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
7713 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
7715 goto nla_put_failure;
7717 NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
7718 NL80211_REPLAY_CTR_LEN, replay_ctr);
7720 nla_nest_end(msg, rekey_attr);
7722 genlmsg_end(msg, hdr);
7724 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7725 nl80211_mlme_mcgrp.id, gfp);
7729 genlmsg_cancel(msg, hdr);
7733 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
7734 struct net_device *netdev, int index,
7735 const u8 *bssid, bool preauth, gfp_t gfp)
7737 struct sk_buff *msg;
7738 struct nlattr *attr;
7741 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7745 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
7751 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7752 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7754 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
7756 goto nla_put_failure;
7758 NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index);
7759 NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid);
7761 NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH);
7763 nla_nest_end(msg, attr);
7765 genlmsg_end(msg, hdr);
7767 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7768 nl80211_mlme_mcgrp.id, gfp);
7772 genlmsg_cancel(msg, hdr);
7777 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
7778 struct net_device *netdev, const u8 *peer,
7779 u32 num_packets, gfp_t gfp)
7781 struct sk_buff *msg;
7782 struct nlattr *pinfoattr;
7785 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7789 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
7795 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7796 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
7797 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
7799 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
7801 goto nla_put_failure;
7803 NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
7805 nla_nest_end(msg, pinfoattr);
7807 genlmsg_end(msg, hdr);
7809 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7810 nl80211_mlme_mcgrp.id, gfp);
7814 genlmsg_cancel(msg, hdr);
7818 void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
7819 u64 cookie, bool acked, gfp_t gfp)
7821 struct wireless_dev *wdev = dev->ieee80211_ptr;
7822 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
7823 struct sk_buff *msg;
7827 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
7831 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
7837 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7838 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
7839 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
7840 NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
7842 NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
7844 err = genlmsg_end(msg, hdr);
7850 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
7851 nl80211_mlme_mcgrp.id, gfp);
7855 genlmsg_cancel(msg, hdr);
7858 EXPORT_SYMBOL(cfg80211_probe_status);
7860 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
7861 const u8 *frame, size_t len,
7862 int freq, gfp_t gfp)
7864 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
7865 struct sk_buff *msg;
7867 u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
7872 msg = nlmsg_new(len + 100, gfp);
7876 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
7882 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
7884 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
7885 NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame);
7887 genlmsg_end(msg, hdr);
7889 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
7893 genlmsg_cancel(msg, hdr);
7896 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
7898 static int nl80211_netlink_notify(struct notifier_block * nb,
7899 unsigned long state,
7902 struct netlink_notify *notify = _notify;
7903 struct cfg80211_registered_device *rdev;
7904 struct wireless_dev *wdev;
7906 if (state != NETLINK_URELEASE)
7911 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
7912 list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
7913 cfg80211_mlme_unregister_socket(wdev, notify->pid);
7914 if (rdev->ap_beacons_nlpid == notify->pid)
7915 rdev->ap_beacons_nlpid = 0;
7923 static struct notifier_block nl80211_netlink_notifier = {
7924 .notifier_call = nl80211_netlink_notify,
7927 /* initialisation/exit functions */
7929 int nl80211_init(void)
7933 err = genl_register_family_with_ops(&nl80211_fam,
7934 nl80211_ops, ARRAY_SIZE(nl80211_ops));
7938 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
7942 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
7946 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
7950 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
7954 #ifdef CONFIG_NL80211_TESTMODE
7955 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
7960 err = netlink_register_notifier(&nl80211_netlink_notifier);
7966 genl_unregister_family(&nl80211_fam);
7970 void nl80211_exit(void)
7972 netlink_unregister_notifier(&nl80211_netlink_notifier);
7973 genl_unregister_family(&nl80211_fam);