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 /* returns ERR_PTR values */
50 static struct wireless_dev
*
51 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
53 struct cfg80211_registered_device
*rdev
;
54 struct wireless_dev
*result
= NULL
;
55 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
56 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
61 assert_cfg80211_lock();
63 if (!have_ifidx
&& !have_wdev_id
)
64 return ERR_PTR(-EINVAL
);
67 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
69 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
70 wiphy_idx
= wdev_id
>> 32;
73 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
74 struct wireless_dev
*wdev
;
76 if (wiphy_net(&rdev
->wiphy
) != netns
)
79 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
82 mutex_lock(&rdev
->devlist_mtx
);
83 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
84 if (have_ifidx
&& wdev
->netdev
&&
85 wdev
->netdev
->ifindex
== ifidx
) {
89 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
94 mutex_unlock(&rdev
->devlist_mtx
);
102 return ERR_PTR(-ENODEV
);
105 static struct cfg80211_registered_device
*
106 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
108 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
109 struct net_device
*netdev
;
111 assert_cfg80211_lock();
113 if (!attrs
[NL80211_ATTR_WIPHY
] &&
114 !attrs
[NL80211_ATTR_IFINDEX
] &&
115 !attrs
[NL80211_ATTR_WDEV
])
116 return ERR_PTR(-EINVAL
);
118 if (attrs
[NL80211_ATTR_WIPHY
])
119 rdev
= cfg80211_rdev_by_wiphy_idx(
120 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
122 if (attrs
[NL80211_ATTR_WDEV
]) {
123 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
124 struct wireless_dev
*wdev
;
127 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
129 /* make sure wdev exists */
130 mutex_lock(&tmp
->devlist_mtx
);
131 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
132 if (wdev
->identifier
!= (u32
)wdev_id
)
137 mutex_unlock(&tmp
->devlist_mtx
);
142 if (rdev
&& tmp
!= rdev
)
143 return ERR_PTR(-EINVAL
);
148 if (attrs
[NL80211_ATTR_IFINDEX
]) {
149 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
150 netdev
= dev_get_by_index(netns
, ifindex
);
152 if (netdev
->ieee80211_ptr
)
154 netdev
->ieee80211_ptr
->wiphy
);
160 /* not wireless device -- return error */
162 return ERR_PTR(-EINVAL
);
164 /* mismatch -- return error */
165 if (rdev
&& tmp
!= rdev
)
166 return ERR_PTR(-EINVAL
);
173 return ERR_PTR(-ENODEV
);
175 if (netns
!= wiphy_net(&rdev
->wiphy
))
176 return ERR_PTR(-ENODEV
);
182 * This function returns a pointer to the driver
183 * that the genl_info item that is passed refers to.
184 * If successful, it returns non-NULL and also locks
185 * the driver's mutex!
187 * This means that you need to call cfg80211_unlock_rdev()
188 * before being allowed to acquire &cfg80211_mutex!
190 * This is necessary because we need to lock the global
191 * mutex to get an item off the list safely, and then
192 * we lock the rdev mutex so it doesn't go away under us.
194 * We don't want to keep cfg80211_mutex locked
195 * for all the time in order to allow requests on
196 * other interfaces to go through at the same time.
198 * The result of this can be a PTR_ERR and hence must
199 * be checked with IS_ERR() for errors.
201 static struct cfg80211_registered_device
*
202 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
204 struct cfg80211_registered_device
*rdev
;
206 mutex_lock(&cfg80211_mutex
);
207 rdev
= __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
209 /* if it is not an error we grab the lock on
210 * it to assure it won't be going away while
211 * we operate on it */
213 mutex_lock(&rdev
->mtx
);
215 mutex_unlock(&cfg80211_mutex
);
220 /* policy for the attributes */
221 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
222 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
225 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
226 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
227 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
228 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
229 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
230 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
232 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
234 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
235 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
236 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
238 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
239 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
241 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
242 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
243 .len
= WLAN_MAX_KEY_LEN
},
244 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
245 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
246 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
247 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
248 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
250 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
253 .len
= IEEE80211_MAX_DATA_LEN
},
254 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
255 .len
= IEEE80211_MAX_DATA_LEN
},
256 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
257 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
258 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
259 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
260 .len
= NL80211_MAX_SUPP_RATES
},
261 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
262 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
263 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
264 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
265 .len
= IEEE80211_MAX_MESH_ID_LEN
},
266 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
268 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
269 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
271 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
272 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
273 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
274 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
275 .len
= NL80211_MAX_SUPP_RATES
},
276 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
278 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
279 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
281 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
283 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
284 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
285 .len
= IEEE80211_MAX_DATA_LEN
},
286 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
287 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
289 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
290 .len
= IEEE80211_MAX_SSID_LEN
},
291 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
292 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
293 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
294 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
295 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
296 [NL80211_ATTR_STA_FLAGS2
] = {
297 .len
= sizeof(struct nl80211_sta_flag_update
),
299 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
301 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
302 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
303 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
304 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
305 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
306 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
307 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
308 .len
= WLAN_PMKID_LEN
},
309 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
311 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
312 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
313 .len
= IEEE80211_MAX_DATA_LEN
},
314 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
315 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
316 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
317 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
318 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
319 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
320 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
321 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
322 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
323 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
324 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
325 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
326 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
327 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
328 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
329 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
331 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
332 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
333 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
334 .len
= IEEE80211_MAX_DATA_LEN
},
335 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
336 .len
= IEEE80211_MAX_DATA_LEN
},
337 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
338 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
339 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
340 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
341 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
342 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
343 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
346 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
347 .len
= IEEE80211_MAX_DATA_LEN
},
348 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
349 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
351 .len
= NL80211_HT_CAPABILITY_LEN
353 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
354 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
355 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
356 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
359 /* policy for the key attributes */
360 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
361 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
362 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
363 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
364 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
365 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
366 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
367 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
368 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
371 /* policy for the key default flags */
372 static const struct nla_policy
373 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
374 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
375 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
378 /* policy for WoWLAN attributes */
379 static const struct nla_policy
380 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
381 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
382 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
383 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
384 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
385 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
386 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
387 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
388 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
391 /* policy for GTK rekey offload attributes */
392 static const struct nla_policy
393 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
394 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
395 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
396 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
399 static const struct nla_policy
400 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
401 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
402 .len
= IEEE80211_MAX_SSID_LEN
},
403 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
406 /* ifidx get helper */
407 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
411 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
412 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
417 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
420 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
426 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
427 struct netlink_callback
*cb
,
428 struct cfg80211_registered_device
**rdev
,
429 struct net_device
**dev
)
431 int ifidx
= cb
->args
[0];
435 ifidx
= nl80211_get_ifidx(cb
);
443 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
449 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
451 err
= PTR_ERR(*rdev
);
461 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
463 cfg80211_unlock_rdev(rdev
);
468 static bool is_valid_ie_attr(const struct nlattr
*attr
)
476 pos
= nla_data(attr
);
497 /* message building helper */
498 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
501 /* since there is no private header just add the generic one */
502 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
505 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
506 struct ieee80211_channel
*chan
)
508 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
510 goto nla_put_failure
;
512 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
513 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
514 goto nla_put_failure
;
515 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
516 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
517 goto nla_put_failure
;
518 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
519 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
520 goto nla_put_failure
;
521 if ((chan
->flags
& IEEE80211_CHAN_RADAR
) &&
522 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
523 goto nla_put_failure
;
525 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
526 DBM_TO_MBM(chan
->max_power
)))
527 goto nla_put_failure
;
535 /* netlink command implementations */
542 bool def_uni
, def_multi
;
545 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
547 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
548 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
553 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
554 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
563 if (tb
[NL80211_KEY_IDX
])
564 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
566 if (tb
[NL80211_KEY_DATA
]) {
567 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
568 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
571 if (tb
[NL80211_KEY_SEQ
]) {
572 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
573 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
576 if (tb
[NL80211_KEY_CIPHER
])
577 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
579 if (tb
[NL80211_KEY_TYPE
]) {
580 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
581 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
585 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
586 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
587 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
588 tb
[NL80211_KEY_DEFAULT_TYPES
],
589 nl80211_key_default_policy
);
593 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
594 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
600 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
602 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
603 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
604 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
607 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
608 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
609 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
612 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
613 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
615 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
616 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
618 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
619 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
628 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
629 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
630 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
634 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
635 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
636 int err
= nla_parse_nested(
637 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
638 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
639 nl80211_key_default_policy
);
643 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
644 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
650 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
654 memset(k
, 0, sizeof(*k
));
658 if (info
->attrs
[NL80211_ATTR_KEY
])
659 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
661 err
= nl80211_parse_key_old(info
, k
);
666 if (k
->def
&& k
->defmgmt
)
670 if (k
->def_uni
|| !k
->def_multi
)
676 if (k
->idx
< 4 || k
->idx
> 5)
679 if (k
->idx
< 0 || k
->idx
> 3)
682 if (k
->idx
< 0 || k
->idx
> 5)
690 static struct cfg80211_cached_keys
*
691 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
694 struct key_parse parse
;
696 struct cfg80211_cached_keys
*result
;
697 int rem
, err
, def
= 0;
699 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
701 return ERR_PTR(-ENOMEM
);
704 result
->defmgmt
= -1;
706 nla_for_each_nested(key
, keys
, rem
) {
707 memset(&parse
, 0, sizeof(parse
));
710 err
= nl80211_parse_key_new(key
, &parse
);
716 if (parse
.idx
< 0 || parse
.idx
> 4)
722 result
->def
= parse
.idx
;
723 if (!parse
.def_uni
|| !parse
.def_multi
)
725 } else if (parse
.defmgmt
)
727 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
728 parse
.idx
, false, NULL
);
731 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
732 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
733 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
734 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
743 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
745 ASSERT_WDEV_LOCK(wdev
);
747 switch (wdev
->iftype
) {
748 case NL80211_IFTYPE_AP
:
749 case NL80211_IFTYPE_AP_VLAN
:
750 case NL80211_IFTYPE_P2P_GO
:
751 case NL80211_IFTYPE_MESH_POINT
:
753 case NL80211_IFTYPE_ADHOC
:
754 if (!wdev
->current_bss
)
757 case NL80211_IFTYPE_STATION
:
758 case NL80211_IFTYPE_P2P_CLIENT
:
759 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
769 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
771 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
775 goto nla_put_failure
;
779 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
780 goto nla_put_failure
;
785 nla_nest_end(msg
, nl_modes
);
792 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
795 struct nlattr
*nl_combis
;
798 nl_combis
= nla_nest_start(msg
,
799 NL80211_ATTR_INTERFACE_COMBINATIONS
);
801 goto nla_put_failure
;
803 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
804 const struct ieee80211_iface_combination
*c
;
805 struct nlattr
*nl_combi
, *nl_limits
;
807 c
= &wiphy
->iface_combinations
[i
];
809 nl_combi
= nla_nest_start(msg
, i
+ 1);
811 goto nla_put_failure
;
813 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
815 goto nla_put_failure
;
817 for (j
= 0; j
< c
->n_limits
; j
++) {
818 struct nlattr
*nl_limit
;
820 nl_limit
= nla_nest_start(msg
, j
+ 1);
822 goto nla_put_failure
;
823 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
825 goto nla_put_failure
;
826 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
828 goto nla_put_failure
;
829 nla_nest_end(msg
, nl_limit
);
832 nla_nest_end(msg
, nl_limits
);
834 if (c
->beacon_int_infra_match
&&
835 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
836 goto nla_put_failure
;
837 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
838 c
->num_different_channels
) ||
839 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
841 goto nla_put_failure
;
843 nla_nest_end(msg
, nl_combi
);
846 nla_nest_end(msg
, nl_combis
);
853 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
854 struct cfg80211_registered_device
*dev
)
857 struct nlattr
*nl_bands
, *nl_band
;
858 struct nlattr
*nl_freqs
, *nl_freq
;
859 struct nlattr
*nl_rates
, *nl_rate
;
860 struct nlattr
*nl_cmds
;
861 enum ieee80211_band band
;
862 struct ieee80211_channel
*chan
;
863 struct ieee80211_rate
*rate
;
865 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
866 dev
->wiphy
.mgmt_stypes
;
868 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
872 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
873 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
)) ||
874 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
875 cfg80211_rdev_list_generation
) ||
876 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
877 dev
->wiphy
.retry_short
) ||
878 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
879 dev
->wiphy
.retry_long
) ||
880 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
881 dev
->wiphy
.frag_threshold
) ||
882 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
883 dev
->wiphy
.rts_threshold
) ||
884 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
885 dev
->wiphy
.coverage_class
) ||
886 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
887 dev
->wiphy
.max_scan_ssids
) ||
888 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
889 dev
->wiphy
.max_sched_scan_ssids
) ||
890 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
891 dev
->wiphy
.max_scan_ie_len
) ||
892 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
893 dev
->wiphy
.max_sched_scan_ie_len
) ||
894 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
895 dev
->wiphy
.max_match_sets
))
896 goto nla_put_failure
;
898 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
899 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
900 goto nla_put_failure
;
901 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
902 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
903 goto nla_put_failure
;
904 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
905 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
906 goto nla_put_failure
;
907 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
908 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
909 goto nla_put_failure
;
910 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
911 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
912 goto nla_put_failure
;
913 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
914 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
915 goto nla_put_failure
;
917 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
918 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
919 dev
->wiphy
.cipher_suites
))
920 goto nla_put_failure
;
922 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
923 dev
->wiphy
.max_num_pmkids
))
924 goto nla_put_failure
;
926 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
927 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
928 goto nla_put_failure
;
930 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
931 dev
->wiphy
.available_antennas_tx
) ||
932 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
933 dev
->wiphy
.available_antennas_rx
))
934 goto nla_put_failure
;
936 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
937 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
938 dev
->wiphy
.probe_resp_offload
))
939 goto nla_put_failure
;
941 if ((dev
->wiphy
.available_antennas_tx
||
942 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
943 u32 tx_ant
= 0, rx_ant
= 0;
945 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
947 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
,
949 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
,
951 goto nla_put_failure
;
955 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
956 dev
->wiphy
.interface_modes
))
957 goto nla_put_failure
;
959 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
961 goto nla_put_failure
;
963 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
964 if (!dev
->wiphy
.bands
[band
])
967 nl_band
= nla_nest_start(msg
, band
);
969 goto nla_put_failure
;
972 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
&&
973 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
974 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
975 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
) ||
976 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
977 dev
->wiphy
.bands
[band
]->ht_cap
.cap
) ||
978 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
979 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
) ||
980 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
981 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
)))
982 goto nla_put_failure
;
985 if (dev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
&&
986 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
987 sizeof(dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
),
988 &dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
) ||
989 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
990 dev
->wiphy
.bands
[band
]->vht_cap
.cap
)))
991 goto nla_put_failure
;
993 /* add frequencies */
994 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
996 goto nla_put_failure
;
998 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
999 nl_freq
= nla_nest_start(msg
, i
);
1001 goto nla_put_failure
;
1003 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
1005 if (nl80211_msg_put_channel(msg
, chan
))
1006 goto nla_put_failure
;
1008 nla_nest_end(msg
, nl_freq
);
1011 nla_nest_end(msg
, nl_freqs
);
1014 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1016 goto nla_put_failure
;
1018 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
1019 nl_rate
= nla_nest_start(msg
, i
);
1021 goto nla_put_failure
;
1023 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
1024 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1026 goto nla_put_failure
;
1027 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1029 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1030 goto nla_put_failure
;
1032 nla_nest_end(msg
, nl_rate
);
1035 nla_nest_end(msg
, nl_rates
);
1037 nla_nest_end(msg
, nl_band
);
1039 nla_nest_end(msg
, nl_bands
);
1041 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1043 goto nla_put_failure
;
1046 #define CMD(op, n) \
1048 if (dev->ops->op) { \
1050 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1051 goto nla_put_failure; \
1055 CMD(add_virtual_intf
, NEW_INTERFACE
);
1056 CMD(change_virtual_intf
, SET_INTERFACE
);
1057 CMD(add_key
, NEW_KEY
);
1058 CMD(start_ap
, START_AP
);
1059 CMD(add_station
, NEW_STATION
);
1060 CMD(add_mpath
, NEW_MPATH
);
1061 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1062 CMD(change_bss
, SET_BSS
);
1063 CMD(auth
, AUTHENTICATE
);
1064 CMD(assoc
, ASSOCIATE
);
1065 CMD(deauth
, DEAUTHENTICATE
);
1066 CMD(disassoc
, DISASSOCIATE
);
1067 CMD(join_ibss
, JOIN_IBSS
);
1068 CMD(join_mesh
, JOIN_MESH
);
1069 CMD(set_pmksa
, SET_PMKSA
);
1070 CMD(del_pmksa
, DEL_PMKSA
);
1071 CMD(flush_pmksa
, FLUSH_PMKSA
);
1072 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1073 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1074 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1075 CMD(mgmt_tx
, FRAME
);
1076 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1077 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1079 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1080 goto nla_put_failure
;
1082 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1083 dev
->ops
->join_mesh
) {
1085 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1086 goto nla_put_failure
;
1088 CMD(set_wds_peer
, SET_WDS_PEER
);
1089 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1090 CMD(tdls_mgmt
, TDLS_MGMT
);
1091 CMD(tdls_oper
, TDLS_OPER
);
1093 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1094 CMD(sched_scan_start
, START_SCHED_SCAN
);
1095 CMD(probe_client
, PROBE_CLIENT
);
1096 CMD(set_noack_map
, SET_NOACK_MAP
);
1097 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1099 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1100 goto nla_put_failure
;
1103 #ifdef CONFIG_NL80211_TESTMODE
1104 CMD(testmode_cmd
, TESTMODE
);
1109 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1111 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1112 goto nla_put_failure
;
1115 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1117 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1118 goto nla_put_failure
;
1121 nla_nest_end(msg
, nl_cmds
);
1123 if (dev
->ops
->remain_on_channel
&&
1124 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1125 nla_put_u32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1126 dev
->wiphy
.max_remain_on_channel_duration
))
1127 goto nla_put_failure
;
1129 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1130 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1131 goto nla_put_failure
;
1135 struct nlattr
*nl_ftypes
, *nl_ifs
;
1136 enum nl80211_iftype ift
;
1138 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1140 goto nla_put_failure
;
1142 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1143 nl_ftypes
= nla_nest_start(msg
, ift
);
1145 goto nla_put_failure
;
1147 stypes
= mgmt_stypes
[ift
].tx
;
1150 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1151 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1152 goto nla_put_failure
;
1156 nla_nest_end(msg
, nl_ftypes
);
1159 nla_nest_end(msg
, nl_ifs
);
1161 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1163 goto nla_put_failure
;
1165 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1166 nl_ftypes
= nla_nest_start(msg
, ift
);
1168 goto nla_put_failure
;
1170 stypes
= mgmt_stypes
[ift
].rx
;
1173 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1174 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1175 goto nla_put_failure
;
1179 nla_nest_end(msg
, nl_ftypes
);
1181 nla_nest_end(msg
, nl_ifs
);
1185 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
1186 struct nlattr
*nl_wowlan
;
1188 nl_wowlan
= nla_nest_start(msg
,
1189 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1191 goto nla_put_failure
;
1193 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1194 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1195 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1196 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1197 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1198 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1199 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1200 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1201 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1202 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1203 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1204 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1205 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1206 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1207 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1208 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1209 goto nla_put_failure
;
1210 if (dev
->wiphy
.wowlan
.n_patterns
) {
1211 struct nl80211_wowlan_pattern_support pat
= {
1212 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1214 dev
->wiphy
.wowlan
.pattern_min_len
,
1216 dev
->wiphy
.wowlan
.pattern_max_len
,
1218 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1220 goto nla_put_failure
;
1223 nla_nest_end(msg
, nl_wowlan
);
1227 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1228 dev
->wiphy
.software_iftypes
))
1229 goto nla_put_failure
;
1231 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1232 goto nla_put_failure
;
1234 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1235 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1236 dev
->wiphy
.ap_sme_capa
))
1237 goto nla_put_failure
;
1239 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
,
1240 dev
->wiphy
.features
))
1241 goto nla_put_failure
;
1243 if (dev
->wiphy
.ht_capa_mod_mask
&&
1244 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1245 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1246 dev
->wiphy
.ht_capa_mod_mask
))
1247 goto nla_put_failure
;
1249 return genlmsg_end(msg
, hdr
);
1252 genlmsg_cancel(msg
, hdr
);
1256 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1259 int start
= cb
->args
[0];
1260 struct cfg80211_registered_device
*dev
;
1262 mutex_lock(&cfg80211_mutex
);
1263 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1264 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1268 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
1269 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1275 mutex_unlock(&cfg80211_mutex
);
1282 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1284 struct sk_buff
*msg
;
1285 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1287 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1291 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
1296 return genlmsg_reply(msg
, info
);
1299 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1300 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1301 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1302 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1303 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1304 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1307 static int parse_txq_params(struct nlattr
*tb
[],
1308 struct ieee80211_txq_params
*txq_params
)
1310 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1311 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1312 !tb
[NL80211_TXQ_ATTR_AIFS
])
1315 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1316 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1317 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1318 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1319 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1321 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1327 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1330 * You can only set the channel explicitly for WDS interfaces,
1331 * all others have their channel managed via their respective
1332 * "establish a connection" command (connect, join, ...)
1334 * For AP/GO and mesh mode, the channel can be set with the
1335 * channel userspace API, but is only stored and passed to the
1336 * low-level driver when the AP starts or the mesh is joined.
1337 * This is for backward compatibility, userspace can also give
1338 * the channel in the start-ap or join-mesh commands instead.
1340 * Monitors are special as they are normally slaved to
1341 * whatever else is going on, so they have their own special
1342 * operation to set the monitor channel if possible.
1345 wdev
->iftype
== NL80211_IFTYPE_AP
||
1346 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1347 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1348 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1351 static bool nl80211_valid_channel_type(struct genl_info
*info
,
1352 enum nl80211_channel_type
*channel_type
)
1354 enum nl80211_channel_type tmp
;
1356 if (!info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1359 tmp
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1360 if (tmp
!= NL80211_CHAN_NO_HT
&&
1361 tmp
!= NL80211_CHAN_HT20
&&
1362 tmp
!= NL80211_CHAN_HT40PLUS
&&
1363 tmp
!= NL80211_CHAN_HT40MINUS
)
1367 *channel_type
= tmp
;
1372 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1373 struct wireless_dev
*wdev
,
1374 struct genl_info
*info
)
1376 struct ieee80211_channel
*channel
;
1377 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1380 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1383 iftype
= wdev
->iftype
;
1385 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1388 if (!nl80211_can_set_dev_channel(wdev
))
1391 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
1392 !nl80211_valid_channel_type(info
, &channel_type
))
1395 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1397 mutex_lock(&rdev
->devlist_mtx
);
1399 case NL80211_IFTYPE_AP
:
1400 case NL80211_IFTYPE_P2P_GO
:
1401 if (wdev
->beacon_interval
) {
1405 channel
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
1406 if (!channel
|| !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
,
1412 wdev
->preset_chan
= channel
;
1413 wdev
->preset_chantype
= channel_type
;
1416 case NL80211_IFTYPE_MESH_POINT
:
1417 result
= cfg80211_set_mesh_freq(rdev
, wdev
, freq
, channel_type
);
1419 case NL80211_IFTYPE_MONITOR
:
1420 result
= cfg80211_set_monitor_channel(rdev
, freq
, channel_type
);
1425 mutex_unlock(&rdev
->devlist_mtx
);
1430 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1432 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1433 struct net_device
*netdev
= info
->user_ptr
[1];
1435 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1438 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1440 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1441 struct net_device
*dev
= info
->user_ptr
[1];
1442 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1445 if (!info
->attrs
[NL80211_ATTR_MAC
])
1448 if (netif_running(dev
))
1451 if (!rdev
->ops
->set_wds_peer
)
1454 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1457 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1458 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1462 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1464 struct cfg80211_registered_device
*rdev
;
1465 struct net_device
*netdev
= NULL
;
1466 struct wireless_dev
*wdev
;
1467 int result
= 0, rem_txq_params
= 0;
1468 struct nlattr
*nl_txq_params
;
1470 u8 retry_short
= 0, retry_long
= 0;
1471 u32 frag_threshold
= 0, rts_threshold
= 0;
1472 u8 coverage_class
= 0;
1475 * Try to find the wiphy and netdev. Normally this
1476 * function shouldn't need the netdev, but this is
1477 * done for backward compatibility -- previously
1478 * setting the channel was done per wiphy, but now
1479 * it is per netdev. Previous userland like hostapd
1480 * also passed a netdev to set_wiphy, so that it is
1481 * possible to let that go to the right netdev!
1483 mutex_lock(&cfg80211_mutex
);
1485 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1486 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1488 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1489 if (netdev
&& netdev
->ieee80211_ptr
) {
1490 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1491 mutex_lock(&rdev
->mtx
);
1497 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1500 mutex_unlock(&cfg80211_mutex
);
1501 return PTR_ERR(rdev
);
1507 mutex_lock(&rdev
->mtx
);
1508 } else if (nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1509 wdev
= netdev
->ieee80211_ptr
;
1514 * end workaround code, by now the rdev is available
1515 * and locked, and wdev may or may not be NULL.
1518 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1519 result
= cfg80211_dev_rename(
1520 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1522 mutex_unlock(&cfg80211_mutex
);
1527 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1528 struct ieee80211_txq_params txq_params
;
1529 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1531 if (!rdev
->ops
->set_txq_params
) {
1532 result
= -EOPNOTSUPP
;
1541 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1542 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1547 if (!netif_running(netdev
)) {
1552 nla_for_each_nested(nl_txq_params
,
1553 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1555 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1556 nla_data(nl_txq_params
),
1557 nla_len(nl_txq_params
),
1559 result
= parse_txq_params(tb
, &txq_params
);
1563 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1571 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1572 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1577 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1578 enum nl80211_tx_power_setting type
;
1581 if (!rdev
->ops
->set_tx_power
) {
1582 result
= -EOPNOTSUPP
;
1586 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1587 type
= nla_get_u32(info
->attrs
[idx
]);
1589 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1590 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1595 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1596 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1597 mbm
= nla_get_u32(info
->attrs
[idx
]);
1600 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1605 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1606 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1608 if ((!rdev
->wiphy
.available_antennas_tx
&&
1609 !rdev
->wiphy
.available_antennas_rx
) ||
1610 !rdev
->ops
->set_antenna
) {
1611 result
= -EOPNOTSUPP
;
1615 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1616 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1618 /* reject antenna configurations which don't match the
1619 * available antenna masks, except for the "all" mask */
1620 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1621 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1626 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1627 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1629 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1636 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1637 retry_short
= nla_get_u8(
1638 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1639 if (retry_short
== 0) {
1643 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1646 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1647 retry_long
= nla_get_u8(
1648 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1649 if (retry_long
== 0) {
1653 changed
|= WIPHY_PARAM_RETRY_LONG
;
1656 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1657 frag_threshold
= nla_get_u32(
1658 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1659 if (frag_threshold
< 256) {
1663 if (frag_threshold
!= (u32
) -1) {
1665 * Fragments (apart from the last one) are required to
1666 * have even length. Make the fragmentation code
1667 * simpler by stripping LSB should someone try to use
1668 * odd threshold value.
1670 frag_threshold
&= ~0x1;
1672 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1675 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1676 rts_threshold
= nla_get_u32(
1677 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1678 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1681 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1682 coverage_class
= nla_get_u8(
1683 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1684 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1688 u8 old_retry_short
, old_retry_long
;
1689 u32 old_frag_threshold
, old_rts_threshold
;
1690 u8 old_coverage_class
;
1692 if (!rdev
->ops
->set_wiphy_params
) {
1693 result
= -EOPNOTSUPP
;
1697 old_retry_short
= rdev
->wiphy
.retry_short
;
1698 old_retry_long
= rdev
->wiphy
.retry_long
;
1699 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1700 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1701 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1703 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1704 rdev
->wiphy
.retry_short
= retry_short
;
1705 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1706 rdev
->wiphy
.retry_long
= retry_long
;
1707 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1708 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1709 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1710 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1711 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1712 rdev
->wiphy
.coverage_class
= coverage_class
;
1714 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1716 rdev
->wiphy
.retry_short
= old_retry_short
;
1717 rdev
->wiphy
.retry_long
= old_retry_long
;
1718 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1719 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1720 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1725 mutex_unlock(&rdev
->mtx
);
1731 static inline u64
wdev_id(struct wireless_dev
*wdev
)
1733 return (u64
)wdev
->identifier
|
1734 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
1737 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1738 struct cfg80211_registered_device
*rdev
,
1739 struct wireless_dev
*wdev
)
1741 struct net_device
*dev
= wdev
->netdev
;
1744 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1749 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
1750 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
) ||
1751 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dev
->dev_addr
)))
1752 goto nla_put_failure
;
1754 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1755 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
1756 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
1757 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1758 rdev
->devlist_generation
^
1759 (cfg80211_rdev_list_generation
<< 2)))
1760 goto nla_put_failure
;
1762 if (rdev
->ops
->get_channel
) {
1763 struct ieee80211_channel
*chan
;
1764 enum nl80211_channel_type channel_type
;
1766 chan
= rdev
->ops
->get_channel(&rdev
->wiphy
, wdev
,
1769 (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
1770 chan
->center_freq
) ||
1771 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
1773 goto nla_put_failure
;
1776 return genlmsg_end(msg
, hdr
);
1779 genlmsg_cancel(msg
, hdr
);
1783 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1787 int wp_start
= cb
->args
[0];
1788 int if_start
= cb
->args
[1];
1789 struct cfg80211_registered_device
*rdev
;
1790 struct wireless_dev
*wdev
;
1792 mutex_lock(&cfg80211_mutex
);
1793 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1794 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1796 if (wp_idx
< wp_start
) {
1802 mutex_lock(&rdev
->devlist_mtx
);
1803 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
1804 if (if_idx
< if_start
) {
1808 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1809 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1811 mutex_unlock(&rdev
->devlist_mtx
);
1816 mutex_unlock(&rdev
->devlist_mtx
);
1821 mutex_unlock(&cfg80211_mutex
);
1823 cb
->args
[0] = wp_idx
;
1824 cb
->args
[1] = if_idx
;
1829 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1831 struct sk_buff
*msg
;
1832 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1833 struct wireless_dev
*wdev
= info
->user_ptr
[1];
1835 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1839 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1845 return genlmsg_reply(msg
, info
);
1848 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1849 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1850 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1851 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1852 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1853 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1856 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1858 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1866 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1867 nla
, mntr_flags_policy
))
1870 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1872 *mntrflags
|= (1<<flag
);
1877 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1878 struct net_device
*netdev
, u8 use_4addr
,
1879 enum nl80211_iftype iftype
)
1882 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1888 case NL80211_IFTYPE_AP_VLAN
:
1889 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1892 case NL80211_IFTYPE_STATION
:
1893 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1903 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1905 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1906 struct vif_params params
;
1908 enum nl80211_iftype otype
, ntype
;
1909 struct net_device
*dev
= info
->user_ptr
[1];
1910 u32 _flags
, *flags
= NULL
;
1911 bool change
= false;
1913 memset(¶ms
, 0, sizeof(params
));
1915 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1917 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1918 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1921 if (ntype
> NL80211_IFTYPE_MAX
)
1925 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1926 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1928 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1930 if (netif_running(dev
))
1934 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1935 IEEE80211_MAX_MESH_ID_LEN
);
1936 wdev
->mesh_id_up_len
=
1937 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1938 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1939 wdev
->mesh_id_up_len
);
1943 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1944 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1946 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1950 params
.use_4addr
= -1;
1953 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1954 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1956 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1966 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1970 if (!err
&& params
.use_4addr
!= -1)
1971 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1976 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1978 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1979 struct vif_params params
;
1980 struct wireless_dev
*wdev
;
1981 struct sk_buff
*msg
;
1983 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1986 memset(¶ms
, 0, sizeof(params
));
1988 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1991 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1992 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1993 if (type
> NL80211_IFTYPE_MAX
)
1997 if (!rdev
->ops
->add_virtual_intf
||
1998 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2001 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2002 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2003 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2008 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2012 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2013 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2015 wdev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
2016 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2017 type
, err
? NULL
: &flags
, ¶ms
);
2020 return PTR_ERR(wdev
);
2023 if (type
== NL80211_IFTYPE_MESH_POINT
&&
2024 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2026 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2027 IEEE80211_MAX_MESH_ID_LEN
);
2028 wdev
->mesh_id_up_len
=
2029 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2030 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2031 wdev
->mesh_id_up_len
);
2035 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2041 return genlmsg_reply(msg
, info
);
2044 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2046 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2047 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2049 if (!rdev
->ops
->del_virtual_intf
)
2053 * If we remove a wireless device without a netdev then clear
2054 * user_ptr[1] so that nl80211_post_doit won't dereference it
2055 * to check if it needs to do dev_put(). Otherwise it crashes
2056 * since the wdev has been freed, unlike with a netdev where
2057 * we need the dev_put() for the netdev to really be freed.
2060 info
->user_ptr
[1] = NULL
;
2062 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, wdev
);
2065 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2067 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2068 struct net_device
*dev
= info
->user_ptr
[1];
2071 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2074 if (!rdev
->ops
->set_noack_map
)
2077 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2079 return rdev
->ops
->set_noack_map(&rdev
->wiphy
, dev
, noack_map
);
2082 struct get_key_cookie
{
2083 struct sk_buff
*msg
;
2088 static void get_key_callback(void *c
, struct key_params
*params
)
2091 struct get_key_cookie
*cookie
= c
;
2094 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2095 params
->key_len
, params
->key
)) ||
2097 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2098 params
->seq_len
, params
->seq
)) ||
2100 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2102 goto nla_put_failure
;
2104 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2106 goto nla_put_failure
;
2109 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2110 params
->key_len
, params
->key
)) ||
2112 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2113 params
->seq_len
, params
->seq
)) ||
2115 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2117 goto nla_put_failure
;
2119 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2120 goto nla_put_failure
;
2122 nla_nest_end(cookie
->msg
, key
);
2129 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2131 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2133 struct net_device
*dev
= info
->user_ptr
[1];
2135 const u8
*mac_addr
= NULL
;
2137 struct get_key_cookie cookie
= {
2141 struct sk_buff
*msg
;
2143 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2144 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2149 if (info
->attrs
[NL80211_ATTR_MAC
])
2150 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2152 pairwise
= !!mac_addr
;
2153 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2154 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2155 if (kt
>= NUM_NL80211_KEYTYPES
)
2157 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2158 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2160 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2163 if (!rdev
->ops
->get_key
)
2166 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2170 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2171 NL80211_CMD_NEW_KEY
);
2173 return PTR_ERR(hdr
);
2176 cookie
.idx
= key_idx
;
2178 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2179 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2180 goto nla_put_failure
;
2182 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2183 goto nla_put_failure
;
2185 if (pairwise
&& mac_addr
&&
2186 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2189 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
2190 mac_addr
, &cookie
, get_key_callback
);
2196 goto nla_put_failure
;
2198 genlmsg_end(msg
, hdr
);
2199 return genlmsg_reply(msg
, info
);
2208 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2210 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2211 struct key_parse key
;
2213 struct net_device
*dev
= info
->user_ptr
[1];
2215 err
= nl80211_parse_key(info
, &key
);
2222 /* only support setting default key */
2223 if (!key
.def
&& !key
.defmgmt
)
2226 wdev_lock(dev
->ieee80211_ptr
);
2229 if (!rdev
->ops
->set_default_key
) {
2234 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2238 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
2239 key
.def_uni
, key
.def_multi
);
2244 #ifdef CONFIG_CFG80211_WEXT
2245 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2248 if (key
.def_uni
|| !key
.def_multi
) {
2253 if (!rdev
->ops
->set_default_mgmt_key
) {
2258 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2262 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
2267 #ifdef CONFIG_CFG80211_WEXT
2268 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2273 wdev_unlock(dev
->ieee80211_ptr
);
2278 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2280 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2282 struct net_device
*dev
= info
->user_ptr
[1];
2283 struct key_parse key
;
2284 const u8
*mac_addr
= NULL
;
2286 err
= nl80211_parse_key(info
, &key
);
2293 if (info
->attrs
[NL80211_ATTR_MAC
])
2294 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2296 if (key
.type
== -1) {
2298 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2300 key
.type
= NL80211_KEYTYPE_GROUP
;
2304 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2305 key
.type
!= NL80211_KEYTYPE_GROUP
)
2308 if (!rdev
->ops
->add_key
)
2311 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2312 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2316 wdev_lock(dev
->ieee80211_ptr
);
2317 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2319 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
2320 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2322 wdev_unlock(dev
->ieee80211_ptr
);
2327 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2329 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2331 struct net_device
*dev
= info
->user_ptr
[1];
2332 u8
*mac_addr
= NULL
;
2333 struct key_parse key
;
2335 err
= nl80211_parse_key(info
, &key
);
2339 if (info
->attrs
[NL80211_ATTR_MAC
])
2340 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2342 if (key
.type
== -1) {
2344 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2346 key
.type
= NL80211_KEYTYPE_GROUP
;
2350 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2351 key
.type
!= NL80211_KEYTYPE_GROUP
)
2354 if (!rdev
->ops
->del_key
)
2357 wdev_lock(dev
->ieee80211_ptr
);
2358 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2360 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2361 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2365 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
2366 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2369 #ifdef CONFIG_CFG80211_WEXT
2371 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2372 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2373 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2374 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2377 wdev_unlock(dev
->ieee80211_ptr
);
2382 static int nl80211_parse_beacon(struct genl_info
*info
,
2383 struct cfg80211_beacon_data
*bcn
)
2385 bool haveinfo
= false;
2387 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2388 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2389 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2390 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2393 memset(bcn
, 0, sizeof(*bcn
));
2395 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2396 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2397 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2403 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2404 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2406 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2413 if (info
->attrs
[NL80211_ATTR_IE
]) {
2414 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2415 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2418 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2419 bcn
->proberesp_ies
=
2420 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2421 bcn
->proberesp_ies_len
=
2422 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2425 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2426 bcn
->assocresp_ies
=
2427 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2428 bcn
->assocresp_ies_len
=
2429 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2432 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2434 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2435 bcn
->probe_resp_len
=
2436 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2442 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2443 struct cfg80211_ap_settings
*params
)
2445 struct wireless_dev
*wdev
;
2448 mutex_lock(&rdev
->devlist_mtx
);
2450 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2451 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2452 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2455 if (!wdev
->preset_chan
)
2458 params
->channel
= wdev
->preset_chan
;
2459 params
->channel_type
= wdev
->preset_chantype
;
2464 mutex_unlock(&rdev
->devlist_mtx
);
2469 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2471 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2472 struct net_device
*dev
= info
->user_ptr
[1];
2473 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2474 struct cfg80211_ap_settings params
;
2477 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2478 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2481 if (!rdev
->ops
->start_ap
)
2484 if (wdev
->beacon_interval
)
2487 memset(¶ms
, 0, sizeof(params
));
2489 /* these are required for START_AP */
2490 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2491 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2492 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2495 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
2499 params
.beacon_interval
=
2500 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2501 params
.dtim_period
=
2502 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2504 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
2509 * In theory, some of these attributes should be required here
2510 * but since they were not used when the command was originally
2511 * added, keep them optional for old user space programs to let
2512 * them continue to work with drivers that do not need the
2513 * additional information -- drivers must check!
2515 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2516 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2518 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2519 if (params
.ssid_len
== 0 ||
2520 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2524 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2525 params
.hidden_ssid
= nla_get_u32(
2526 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2527 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2528 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
2529 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2533 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2535 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2536 params
.auth_type
= nla_get_u32(
2537 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2538 if (!nl80211_valid_auth_type(params
.auth_type
))
2541 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2543 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2544 NL80211_MAX_NR_CIPHER_SUITES
);
2548 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
2549 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
2551 params
.inactivity_timeout
= nla_get_u16(
2552 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
2555 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2556 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
2558 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
2559 !nl80211_valid_channel_type(info
, &channel_type
))
2562 params
.channel
= rdev_freq_to_chan(rdev
,
2563 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
2565 if (!params
.channel
)
2567 params
.channel_type
= channel_type
;
2568 } else if (wdev
->preset_chan
) {
2569 params
.channel
= wdev
->preset_chan
;
2570 params
.channel_type
= wdev
->preset_chantype
;
2571 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
2574 if (!cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, params
.channel
,
2575 params
.channel_type
))
2578 mutex_lock(&rdev
->devlist_mtx
);
2579 err
= cfg80211_can_use_chan(rdev
, wdev
, params
.channel
,
2581 mutex_unlock(&rdev
->devlist_mtx
);
2586 err
= rdev
->ops
->start_ap(&rdev
->wiphy
, dev
, ¶ms
);
2588 wdev
->preset_chan
= params
.channel
;
2589 wdev
->preset_chantype
= params
.channel_type
;
2590 wdev
->beacon_interval
= params
.beacon_interval
;
2591 wdev
->channel
= params
.channel
;
2596 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2598 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2599 struct net_device
*dev
= info
->user_ptr
[1];
2600 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2601 struct cfg80211_beacon_data params
;
2604 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2605 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2608 if (!rdev
->ops
->change_beacon
)
2611 if (!wdev
->beacon_interval
)
2614 err
= nl80211_parse_beacon(info
, ¶ms
);
2618 return rdev
->ops
->change_beacon(&rdev
->wiphy
, dev
, ¶ms
);
2621 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2623 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2624 struct net_device
*dev
= info
->user_ptr
[1];
2626 return cfg80211_stop_ap(rdev
, dev
);
2629 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2630 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2631 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2632 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2633 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2634 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2635 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
2638 static int parse_station_flags(struct genl_info
*info
,
2639 enum nl80211_iftype iftype
,
2640 struct station_parameters
*params
)
2642 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2647 * Try parsing the new attribute first so userspace
2648 * can specify both for older kernels.
2650 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2652 struct nl80211_sta_flag_update
*sta_flags
;
2654 sta_flags
= nla_data(nla
);
2655 params
->sta_flags_mask
= sta_flags
->mask
;
2656 params
->sta_flags_set
= sta_flags
->set
;
2657 if ((params
->sta_flags_mask
|
2658 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2663 /* if present, parse the old attribute */
2665 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2669 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2670 nla
, sta_flags_policy
))
2674 * Only allow certain flags for interface types so that
2675 * other attributes are silently ignored. Remember that
2676 * this is backward compatibility code with old userspace
2677 * and shouldn't be hit in other cases anyway.
2680 case NL80211_IFTYPE_AP
:
2681 case NL80211_IFTYPE_AP_VLAN
:
2682 case NL80211_IFTYPE_P2P_GO
:
2683 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2684 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2685 BIT(NL80211_STA_FLAG_WME
) |
2686 BIT(NL80211_STA_FLAG_MFP
);
2688 case NL80211_IFTYPE_P2P_CLIENT
:
2689 case NL80211_IFTYPE_STATION
:
2690 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2691 BIT(NL80211_STA_FLAG_TDLS_PEER
);
2693 case NL80211_IFTYPE_MESH_POINT
:
2694 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2695 BIT(NL80211_STA_FLAG_MFP
) |
2696 BIT(NL80211_STA_FLAG_AUTHORIZED
);
2701 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
2703 params
->sta_flags_set
|= (1<<flag
);
2705 /* no longer support new API additions in old API */
2706 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
2714 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2717 struct nlattr
*rate
;
2721 rate
= nla_nest_start(msg
, attr
);
2723 goto nla_put_failure
;
2725 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2726 bitrate
= cfg80211_calculate_bitrate(info
);
2727 /* report 16-bit bitrate only if we can */
2728 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
2730 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
)) ||
2731 (bitrate_compat
> 0 &&
2732 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
)) ||
2733 ((info
->flags
& RATE_INFO_FLAGS_MCS
) &&
2734 nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
)) ||
2735 ((info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) &&
2736 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
)) ||
2737 ((info
->flags
& RATE_INFO_FLAGS_SHORT_GI
) &&
2738 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
)))
2739 goto nla_put_failure
;
2741 nla_nest_end(msg
, rate
);
2748 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2750 struct cfg80211_registered_device
*rdev
,
2751 struct net_device
*dev
,
2752 const u8
*mac_addr
, struct station_info
*sinfo
)
2755 struct nlattr
*sinfoattr
, *bss_param
;
2757 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2761 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2762 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
2763 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
2764 goto nla_put_failure
;
2766 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2768 goto nla_put_failure
;
2769 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
2770 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2771 sinfo
->connected_time
))
2772 goto nla_put_failure
;
2773 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
2774 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2775 sinfo
->inactive_time
))
2776 goto nla_put_failure
;
2777 if ((sinfo
->filled
& STATION_INFO_RX_BYTES
) &&
2778 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
2780 goto nla_put_failure
;
2781 if ((sinfo
->filled
& STATION_INFO_TX_BYTES
) &&
2782 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
2784 goto nla_put_failure
;
2785 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
2786 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
2787 goto nla_put_failure
;
2788 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
2789 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
2790 goto nla_put_failure
;
2791 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
2792 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2793 sinfo
->plink_state
))
2794 goto nla_put_failure
;
2795 switch (rdev
->wiphy
.signal_type
) {
2796 case CFG80211_SIGNAL_TYPE_MBM
:
2797 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
2798 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
2800 goto nla_put_failure
;
2801 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
2802 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2804 goto nla_put_failure
;
2809 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2810 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2811 NL80211_STA_INFO_TX_BITRATE
))
2812 goto nla_put_failure
;
2814 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2815 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2816 NL80211_STA_INFO_RX_BITRATE
))
2817 goto nla_put_failure
;
2819 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
2820 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2822 goto nla_put_failure
;
2823 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
2824 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2826 goto nla_put_failure
;
2827 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
2828 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2830 goto nla_put_failure
;
2831 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
2832 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
2834 goto nla_put_failure
;
2835 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
2836 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
2837 sinfo
->beacon_loss_count
))
2838 goto nla_put_failure
;
2839 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2840 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2842 goto nla_put_failure
;
2844 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
2845 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
2846 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
2847 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
2848 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
2849 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
2850 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2851 sinfo
->bss_param
.dtim_period
) ||
2852 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2853 sinfo
->bss_param
.beacon_interval
))
2854 goto nla_put_failure
;
2856 nla_nest_end(msg
, bss_param
);
2858 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
2859 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
2860 sizeof(struct nl80211_sta_flag_update
),
2862 goto nla_put_failure
;
2863 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
2864 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
2866 goto nla_put_failure
;
2867 nla_nest_end(msg
, sinfoattr
);
2869 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
2870 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2871 sinfo
->assoc_req_ies
))
2872 goto nla_put_failure
;
2874 return genlmsg_end(msg
, hdr
);
2877 genlmsg_cancel(msg
, hdr
);
2881 static int nl80211_dump_station(struct sk_buff
*skb
,
2882 struct netlink_callback
*cb
)
2884 struct station_info sinfo
;
2885 struct cfg80211_registered_device
*dev
;
2886 struct net_device
*netdev
;
2887 u8 mac_addr
[ETH_ALEN
];
2888 int sta_idx
= cb
->args
[1];
2891 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2895 if (!dev
->ops
->dump_station
) {
2901 memset(&sinfo
, 0, sizeof(sinfo
));
2902 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2909 if (nl80211_send_station(skb
,
2910 NETLINK_CB(cb
->skb
).pid
,
2911 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2912 dev
, netdev
, mac_addr
,
2921 cb
->args
[1] = sta_idx
;
2924 nl80211_finish_netdev_dump(dev
);
2929 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2931 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2932 struct net_device
*dev
= info
->user_ptr
[1];
2933 struct station_info sinfo
;
2934 struct sk_buff
*msg
;
2935 u8
*mac_addr
= NULL
;
2938 memset(&sinfo
, 0, sizeof(sinfo
));
2940 if (!info
->attrs
[NL80211_ATTR_MAC
])
2943 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2945 if (!rdev
->ops
->get_station
)
2948 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2952 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2956 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2957 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
2962 return genlmsg_reply(msg
, info
);
2966 * Get vlan interface making sure it is running and on the right wiphy.
2968 static struct net_device
*get_vlan(struct genl_info
*info
,
2969 struct cfg80211_registered_device
*rdev
)
2971 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2972 struct net_device
*v
;
2978 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
2980 return ERR_PTR(-ENODEV
);
2982 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
2987 if (!netif_running(v
)) {
2995 return ERR_PTR(ret
);
2998 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3000 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3002 struct net_device
*dev
= info
->user_ptr
[1];
3003 struct station_parameters params
;
3004 u8
*mac_addr
= NULL
;
3006 memset(¶ms
, 0, sizeof(params
));
3008 params
.listen_interval
= -1;
3009 params
.plink_state
= -1;
3011 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3014 if (!info
->attrs
[NL80211_ATTR_MAC
])
3017 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3019 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3020 params
.supported_rates
=
3021 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3022 params
.supported_rates_len
=
3023 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3026 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3027 params
.listen_interval
=
3028 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3030 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3032 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3034 if (!rdev
->ops
->change_station
)
3037 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3040 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3041 params
.plink_action
=
3042 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3044 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
3045 params
.plink_state
=
3046 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3048 switch (dev
->ieee80211_ptr
->iftype
) {
3049 case NL80211_IFTYPE_AP
:
3050 case NL80211_IFTYPE_AP_VLAN
:
3051 case NL80211_IFTYPE_P2P_GO
:
3052 /* disallow mesh-specific things */
3053 if (params
.plink_action
)
3056 /* TDLS can't be set, ... */
3057 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3060 * ... but don't bother the driver with it. This works around
3061 * a hostapd/wpa_supplicant issue -- it always includes the
3062 * TLDS_PEER flag in the mask even for AP mode.
3064 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3066 /* accept only the listed bits */
3067 if (params
.sta_flags_mask
&
3068 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3069 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3070 BIT(NL80211_STA_FLAG_WME
) |
3071 BIT(NL80211_STA_FLAG_MFP
)))
3074 /* must be last in here for error handling */
3075 params
.vlan
= get_vlan(info
, rdev
);
3076 if (IS_ERR(params
.vlan
))
3077 return PTR_ERR(params
.vlan
);
3079 case NL80211_IFTYPE_P2P_CLIENT
:
3080 case NL80211_IFTYPE_STATION
:
3082 * Don't allow userspace to change the TDLS_PEER flag,
3083 * but silently ignore attempts to change it since we
3084 * don't have state here to verify that it doesn't try
3085 * to change the flag.
3087 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3089 case NL80211_IFTYPE_ADHOC
:
3090 /* disallow things sta doesn't support */
3091 if (params
.plink_action
)
3095 if (params
.listen_interval
>= 0)
3097 /* reject any changes other than AUTHORIZED */
3098 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3101 case NL80211_IFTYPE_MESH_POINT
:
3102 /* disallow things mesh doesn't support */
3107 if (params
.listen_interval
>= 0)
3110 * No special handling for TDLS here -- the userspace
3111 * mesh code doesn't have this bug.
3113 if (params
.sta_flags_mask
&
3114 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3115 BIT(NL80211_STA_FLAG_MFP
) |
3116 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3123 /* be aware of params.vlan when changing code here */
3125 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3128 dev_put(params
.vlan
);
3133 static struct nla_policy
3134 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3135 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3136 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3139 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3141 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3143 struct net_device
*dev
= info
->user_ptr
[1];
3144 struct station_parameters params
;
3145 u8
*mac_addr
= NULL
;
3147 memset(¶ms
, 0, sizeof(params
));
3149 if (!info
->attrs
[NL80211_ATTR_MAC
])
3152 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3155 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3158 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3161 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3162 params
.supported_rates
=
3163 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3164 params
.supported_rates_len
=
3165 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3166 params
.listen_interval
=
3167 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3169 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3170 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3173 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3175 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3177 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3178 params
.plink_action
=
3179 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3181 if (!rdev
->ops
->add_station
)
3184 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3187 switch (dev
->ieee80211_ptr
->iftype
) {
3188 case NL80211_IFTYPE_AP
:
3189 case NL80211_IFTYPE_AP_VLAN
:
3190 case NL80211_IFTYPE_P2P_GO
:
3191 /* parse WME attributes if sta is WME capable */
3192 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
3193 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
3194 info
->attrs
[NL80211_ATTR_STA_WME
]) {
3195 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3198 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3199 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3200 nl80211_sta_wme_policy
);
3204 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3205 params
.uapsd_queues
=
3206 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3207 if (params
.uapsd_queues
&
3208 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3211 if (tb
[NL80211_STA_WME_MAX_SP
])
3213 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3216 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3219 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3221 /* TDLS peers cannot be added */
3222 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3224 /* but don't bother the driver with it */
3225 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3227 /* must be last in here for error handling */
3228 params
.vlan
= get_vlan(info
, rdev
);
3229 if (IS_ERR(params
.vlan
))
3230 return PTR_ERR(params
.vlan
);
3232 case NL80211_IFTYPE_MESH_POINT
:
3233 /* TDLS peers cannot be added */
3234 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3237 case NL80211_IFTYPE_STATION
:
3238 /* Only TDLS peers can be added */
3239 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3241 /* Can only add if TDLS ... */
3242 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3244 /* ... with external setup is supported */
3245 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3252 /* be aware of params.vlan when changing code here */
3254 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3257 dev_put(params
.vlan
);
3261 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
3263 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3264 struct net_device
*dev
= info
->user_ptr
[1];
3265 u8
*mac_addr
= NULL
;
3267 if (info
->attrs
[NL80211_ATTR_MAC
])
3268 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3270 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3271 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3272 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
3273 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3276 if (!rdev
->ops
->del_station
)
3279 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
3282 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3283 int flags
, struct net_device
*dev
,
3284 u8
*dst
, u8
*next_hop
,
3285 struct mpath_info
*pinfo
)
3288 struct nlattr
*pinfoattr
;
3290 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3294 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3295 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
3296 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
3297 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
3298 goto nla_put_failure
;
3300 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
3302 goto nla_put_failure
;
3303 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
3304 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
3306 goto nla_put_failure
;
3307 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
3308 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
3309 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
3310 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
3312 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
3313 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
3315 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
3316 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
3318 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
3319 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
3320 pinfo
->discovery_timeout
)) ||
3321 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
3322 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
3323 pinfo
->discovery_retries
)))
3324 goto nla_put_failure
;
3326 nla_nest_end(msg
, pinfoattr
);
3328 return genlmsg_end(msg
, hdr
);
3331 genlmsg_cancel(msg
, hdr
);
3335 static int nl80211_dump_mpath(struct sk_buff
*skb
,
3336 struct netlink_callback
*cb
)
3338 struct mpath_info pinfo
;
3339 struct cfg80211_registered_device
*dev
;
3340 struct net_device
*netdev
;
3342 u8 next_hop
[ETH_ALEN
];
3343 int path_idx
= cb
->args
[1];
3346 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3350 if (!dev
->ops
->dump_mpath
) {
3355 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
3361 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
3362 dst
, next_hop
, &pinfo
);
3368 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
3369 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3370 netdev
, dst
, next_hop
,
3379 cb
->args
[1] = path_idx
;
3382 nl80211_finish_netdev_dump(dev
);
3386 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3388 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3390 struct net_device
*dev
= info
->user_ptr
[1];
3391 struct mpath_info pinfo
;
3392 struct sk_buff
*msg
;
3394 u8 next_hop
[ETH_ALEN
];
3396 memset(&pinfo
, 0, sizeof(pinfo
));
3398 if (!info
->attrs
[NL80211_ATTR_MAC
])
3401 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3403 if (!rdev
->ops
->get_mpath
)
3406 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3409 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
3413 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3417 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3418 dev
, dst
, next_hop
, &pinfo
) < 0) {
3423 return genlmsg_reply(msg
, info
);
3426 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3428 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3429 struct net_device
*dev
= info
->user_ptr
[1];
3431 u8
*next_hop
= NULL
;
3433 if (!info
->attrs
[NL80211_ATTR_MAC
])
3436 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3439 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3440 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3442 if (!rdev
->ops
->change_mpath
)
3445 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3448 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3451 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3453 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3454 struct net_device
*dev
= info
->user_ptr
[1];
3456 u8
*next_hop
= NULL
;
3458 if (!info
->attrs
[NL80211_ATTR_MAC
])
3461 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3464 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3465 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3467 if (!rdev
->ops
->add_mpath
)
3470 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3473 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3476 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3478 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3479 struct net_device
*dev
= info
->user_ptr
[1];
3482 if (info
->attrs
[NL80211_ATTR_MAC
])
3483 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3485 if (!rdev
->ops
->del_mpath
)
3488 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
3491 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
3493 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3494 struct net_device
*dev
= info
->user_ptr
[1];
3495 struct bss_parameters params
;
3497 memset(¶ms
, 0, sizeof(params
));
3498 /* default to not changing parameters */
3499 params
.use_cts_prot
= -1;
3500 params
.use_short_preamble
= -1;
3501 params
.use_short_slot_time
= -1;
3502 params
.ap_isolate
= -1;
3503 params
.ht_opmode
= -1;
3505 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
3506 params
.use_cts_prot
=
3507 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
3508 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
3509 params
.use_short_preamble
=
3510 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
3511 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
3512 params
.use_short_slot_time
=
3513 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
3514 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3515 params
.basic_rates
=
3516 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3517 params
.basic_rates_len
=
3518 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3520 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
3521 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
3522 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
3524 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
3526 if (!rdev
->ops
->change_bss
)
3529 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3530 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3533 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
3536 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
3537 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3538 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3539 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3540 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3541 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3542 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3545 static int parse_reg_rule(struct nlattr
*tb
[],
3546 struct ieee80211_reg_rule
*reg_rule
)
3548 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3549 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3551 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3553 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3555 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3557 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3559 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3562 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3564 freq_range
->start_freq_khz
=
3565 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3566 freq_range
->end_freq_khz
=
3567 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3568 freq_range
->max_bandwidth_khz
=
3569 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3571 power_rule
->max_eirp
=
3572 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3574 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3575 power_rule
->max_antenna_gain
=
3576 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3581 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3587 * You should only get this when cfg80211 hasn't yet initialized
3588 * completely when built-in to the kernel right between the time
3589 * window between nl80211_init() and regulatory_init(), if that is
3592 mutex_lock(&cfg80211_mutex
);
3593 if (unlikely(!cfg80211_regdomain
)) {
3594 mutex_unlock(&cfg80211_mutex
);
3595 return -EINPROGRESS
;
3597 mutex_unlock(&cfg80211_mutex
);
3599 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3602 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3604 r
= regulatory_hint_user(data
);
3609 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3610 struct genl_info
*info
)
3612 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3613 struct net_device
*dev
= info
->user_ptr
[1];
3614 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3615 struct mesh_config cur_params
;
3618 struct nlattr
*pinfoattr
;
3619 struct sk_buff
*msg
;
3621 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3624 if (!rdev
->ops
->get_mesh_config
)
3628 /* If not connected, get default parameters */
3629 if (!wdev
->mesh_id_len
)
3630 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3632 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3639 /* Draw up a netlink message to send back */
3640 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3643 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3644 NL80211_CMD_GET_MESH_CONFIG
);
3647 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3649 goto nla_put_failure
;
3650 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3651 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3652 cur_params
.dot11MeshRetryTimeout
) ||
3653 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3654 cur_params
.dot11MeshConfirmTimeout
) ||
3655 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3656 cur_params
.dot11MeshHoldingTimeout
) ||
3657 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3658 cur_params
.dot11MeshMaxPeerLinks
) ||
3659 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3660 cur_params
.dot11MeshMaxRetries
) ||
3661 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
3662 cur_params
.dot11MeshTTL
) ||
3663 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3664 cur_params
.element_ttl
) ||
3665 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3666 cur_params
.auto_open_plinks
) ||
3667 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3668 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
3669 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3670 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
3671 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3672 cur_params
.path_refresh_time
) ||
3673 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3674 cur_params
.min_discovery_timeout
) ||
3675 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3676 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
3677 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3678 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
3679 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3680 cur_params
.dot11MeshHWMPperrMinInterval
) ||
3681 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3682 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
3683 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3684 cur_params
.dot11MeshHWMPRootMode
) ||
3685 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3686 cur_params
.dot11MeshHWMPRannInterval
) ||
3687 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3688 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
3689 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
3690 cur_params
.dot11MeshForwarding
) ||
3691 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3692 cur_params
.rssi_threshold
) ||
3693 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
3694 cur_params
.ht_opmode
) ||
3695 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3696 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
3697 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3698 cur_params
.dot11MeshHWMProotInterval
) ||
3699 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3700 cur_params
.dot11MeshHWMPconfirmationInterval
))
3701 goto nla_put_failure
;
3702 nla_nest_end(msg
, pinfoattr
);
3703 genlmsg_end(msg
, hdr
);
3704 return genlmsg_reply(msg
, info
);
3707 genlmsg_cancel(msg
, hdr
);
3713 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3714 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3715 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3716 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3717 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3718 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3719 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3720 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3721 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3722 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
3723 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3724 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3725 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3726 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3727 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3728 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
3729 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3730 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3731 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3732 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3733 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
3734 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
3735 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
3736 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
3737 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
3738 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
3741 static const struct nla_policy
3742 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3743 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
3744 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3745 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3746 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3747 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3748 .len
= IEEE80211_MAX_DATA_LEN
},
3749 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3752 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3753 struct mesh_config
*cfg
,
3756 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3759 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3761 if (table[attr_num]) {\
3762 cfg->param = nla_fn(table[attr_num]); \
3763 mask |= (1 << (attr_num - 1)); \
3768 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3770 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3771 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3772 nl80211_meshconf_params_policy
))
3775 /* This makes sure that there aren't more than 32 mesh config
3776 * parameters (otherwise our bitfield scheme would not work.) */
3777 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3779 /* Fill in the params struct */
3780 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3781 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3783 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3784 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3786 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3787 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3789 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3790 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3792 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3793 mask
, NL80211_MESHCONF_MAX_RETRIES
,
3795 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3796 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3797 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3798 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
3800 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3801 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3803 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
, mask
,
3804 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3806 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3807 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3809 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3810 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3812 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3813 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3815 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
, mask
,
3816 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3818 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3819 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3821 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
3822 mask
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3824 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3825 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
3826 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3828 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
3829 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
3830 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
3831 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3833 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3834 dot11MeshGateAnnouncementProtocol
, mask
,
3835 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3837 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
,
3838 mask
, NL80211_MESHCONF_FORWARDING
,
3840 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
,
3841 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3843 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
,
3844 mask
, NL80211_MESHCONF_HT_OPMODE
,
3846 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
3848 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3850 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
,
3851 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3853 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3854 dot11MeshHWMPconfirmationInterval
, mask
,
3855 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3862 #undef FILL_IN_MESH_PARAM_IF_SET
3865 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3866 struct mesh_setup
*setup
)
3868 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3870 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3872 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3873 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3874 nl80211_mesh_setup_params_policy
))
3877 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
3878 setup
->sync_method
=
3879 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
3880 IEEE80211_SYNC_METHOD_VENDOR
:
3881 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
3883 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3884 setup
->path_sel_proto
=
3885 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3886 IEEE80211_PATH_PROTOCOL_VENDOR
:
3887 IEEE80211_PATH_PROTOCOL_HWMP
;
3889 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3890 setup
->path_metric
=
3891 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3892 IEEE80211_PATH_METRIC_VENDOR
:
3893 IEEE80211_PATH_METRIC_AIRTIME
;
3896 if (tb
[NL80211_MESH_SETUP_IE
]) {
3897 struct nlattr
*ieattr
=
3898 tb
[NL80211_MESH_SETUP_IE
];
3899 if (!is_valid_ie_attr(ieattr
))
3901 setup
->ie
= nla_data(ieattr
);
3902 setup
->ie_len
= nla_len(ieattr
);
3904 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3905 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3910 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3911 struct genl_info
*info
)
3913 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3914 struct net_device
*dev
= info
->user_ptr
[1];
3915 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3916 struct mesh_config cfg
;
3920 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3923 if (!rdev
->ops
->update_mesh_config
)
3926 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3931 if (!wdev
->mesh_id_len
)
3935 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3943 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3945 struct sk_buff
*msg
;
3947 struct nlattr
*nl_reg_rules
;
3951 mutex_lock(&cfg80211_mutex
);
3953 if (!cfg80211_regdomain
)
3956 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3962 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3963 NL80211_CMD_GET_REG
);
3967 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
3968 cfg80211_regdomain
->alpha2
) ||
3969 (cfg80211_regdomain
->dfs_region
&&
3970 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
,
3971 cfg80211_regdomain
->dfs_region
)))
3972 goto nla_put_failure
;
3974 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3976 goto nla_put_failure
;
3978 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3979 struct nlattr
*nl_reg_rule
;
3980 const struct ieee80211_reg_rule
*reg_rule
;
3981 const struct ieee80211_freq_range
*freq_range
;
3982 const struct ieee80211_power_rule
*power_rule
;
3984 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3985 freq_range
= ®_rule
->freq_range
;
3986 power_rule
= ®_rule
->power_rule
;
3988 nl_reg_rule
= nla_nest_start(msg
, i
);
3990 goto nla_put_failure
;
3992 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3994 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3995 freq_range
->start_freq_khz
) ||
3996 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3997 freq_range
->end_freq_khz
) ||
3998 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3999 freq_range
->max_bandwidth_khz
) ||
4000 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4001 power_rule
->max_antenna_gain
) ||
4002 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4003 power_rule
->max_eirp
))
4004 goto nla_put_failure
;
4006 nla_nest_end(msg
, nl_reg_rule
);
4009 nla_nest_end(msg
, nl_reg_rules
);
4011 genlmsg_end(msg
, hdr
);
4012 err
= genlmsg_reply(msg
, info
);
4016 genlmsg_cancel(msg
, hdr
);
4021 mutex_unlock(&cfg80211_mutex
);
4025 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4027 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4028 struct nlattr
*nl_reg_rule
;
4029 char *alpha2
= NULL
;
4030 int rem_reg_rules
= 0, r
= 0;
4031 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4033 struct ieee80211_regdomain
*rd
= NULL
;
4035 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4038 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
4041 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4043 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
4044 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
4046 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4049 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
4053 mutex_lock(&cfg80211_mutex
);
4055 if (!reg_is_valid_request(alpha2
)) {
4060 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
4061 (num_rules
* sizeof(struct ieee80211_reg_rule
));
4063 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
4069 rd
->n_reg_rules
= num_rules
;
4070 rd
->alpha2
[0] = alpha2
[0];
4071 rd
->alpha2
[1] = alpha2
[1];
4074 * Disable DFS master mode if the DFS region was
4075 * not supported or known on this kernel.
4077 if (reg_supported_dfs_region(dfs_region
))
4078 rd
->dfs_region
= dfs_region
;
4080 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4082 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
4083 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
4085 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
4091 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
4097 BUG_ON(rule_idx
!= num_rules
);
4101 mutex_unlock(&cfg80211_mutex
);
4106 mutex_unlock(&cfg80211_mutex
);
4111 static int validate_scan_freqs(struct nlattr
*freqs
)
4113 struct nlattr
*attr1
, *attr2
;
4114 int n_channels
= 0, tmp1
, tmp2
;
4116 nla_for_each_nested(attr1
, freqs
, tmp1
) {
4119 * Some hardware has a limited channel list for
4120 * scanning, and it is pretty much nonsensical
4121 * to scan for a channel twice, so disallow that
4122 * and don't require drivers to check that the
4123 * channel list they get isn't longer than what
4124 * they can scan, as long as they can scan all
4125 * the channels they registered at once.
4127 nla_for_each_nested(attr2
, freqs
, tmp2
)
4128 if (attr1
!= attr2
&&
4129 nla_get_u32(attr1
) == nla_get_u32(attr2
))
4136 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
4138 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4139 struct wireless_dev
*wdev
= info
->user_ptr
[1];
4140 struct cfg80211_scan_request
*request
;
4141 struct nlattr
*attr
;
4142 struct wiphy
*wiphy
;
4143 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
4146 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4149 wiphy
= &rdev
->wiphy
;
4151 if (!rdev
->ops
->scan
)
4157 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4158 n_channels
= validate_scan_freqs(
4159 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4163 enum ieee80211_band band
;
4166 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4167 if (wiphy
->bands
[band
])
4168 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4171 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4172 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
4175 if (n_ssids
> wiphy
->max_scan_ssids
)
4178 if (info
->attrs
[NL80211_ATTR_IE
])
4179 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4183 if (ie_len
> wiphy
->max_scan_ie_len
)
4186 request
= kzalloc(sizeof(*request
)
4187 + sizeof(*request
->ssids
) * n_ssids
4188 + sizeof(*request
->channels
) * n_channels
4189 + ie_len
, GFP_KERNEL
);
4194 request
->ssids
= (void *)&request
->channels
[n_channels
];
4195 request
->n_ssids
= n_ssids
;
4198 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4200 request
->ie
= (void *)(request
->channels
+ n_channels
);
4204 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4205 /* user specified, bail out if channel not found */
4206 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
4207 struct ieee80211_channel
*chan
;
4209 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4216 /* ignore disabled channels */
4217 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4220 request
->channels
[i
] = chan
;
4224 enum ieee80211_band band
;
4227 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4229 if (!wiphy
->bands
[band
])
4231 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4232 struct ieee80211_channel
*chan
;
4234 chan
= &wiphy
->bands
[band
]->channels
[j
];
4236 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4239 request
->channels
[i
] = chan
;
4250 request
->n_channels
= i
;
4253 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4254 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
4255 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4259 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4260 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
4265 if (info
->attrs
[NL80211_ATTR_IE
]) {
4266 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4267 memcpy((void *)request
->ie
,
4268 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4272 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4273 if (wiphy
->bands
[i
])
4275 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
4277 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
4278 nla_for_each_nested(attr
,
4279 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
4281 enum ieee80211_band band
= nla_type(attr
);
4283 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4287 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
4290 &request
->rates
[band
]);
4297 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
4299 request
->wdev
= wdev
;
4300 request
->wiphy
= &rdev
->wiphy
;
4302 rdev
->scan_req
= request
;
4303 err
= rdev
->ops
->scan(&rdev
->wiphy
, request
);
4306 nl80211_send_scan_start(rdev
, wdev
);
4308 dev_hold(wdev
->netdev
);
4311 rdev
->scan_req
= NULL
;
4318 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
4319 struct genl_info
*info
)
4321 struct cfg80211_sched_scan_request
*request
;
4322 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4323 struct net_device
*dev
= info
->user_ptr
[1];
4324 struct nlattr
*attr
;
4325 struct wiphy
*wiphy
;
4326 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
4328 enum ieee80211_band band
;
4330 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
4332 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4333 !rdev
->ops
->sched_scan_start
)
4336 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4339 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
4342 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
4346 wiphy
= &rdev
->wiphy
;
4348 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4349 n_channels
= validate_scan_freqs(
4350 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4356 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4357 if (wiphy
->bands
[band
])
4358 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4361 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4362 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4366 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
4369 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
4370 nla_for_each_nested(attr
,
4371 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4375 if (n_match_sets
> wiphy
->max_match_sets
)
4378 if (info
->attrs
[NL80211_ATTR_IE
])
4379 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4383 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
4386 mutex_lock(&rdev
->sched_scan_mtx
);
4388 if (rdev
->sched_scan_req
) {
4393 request
= kzalloc(sizeof(*request
)
4394 + sizeof(*request
->ssids
) * n_ssids
4395 + sizeof(*request
->match_sets
) * n_match_sets
4396 + sizeof(*request
->channels
) * n_channels
4397 + ie_len
, GFP_KERNEL
);
4404 request
->ssids
= (void *)&request
->channels
[n_channels
];
4405 request
->n_ssids
= n_ssids
;
4408 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4410 request
->ie
= (void *)(request
->channels
+ n_channels
);
4415 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
4416 else if (request
->ssids
)
4417 request
->match_sets
=
4418 (void *)(request
->ssids
+ n_ssids
);
4420 request
->match_sets
=
4421 (void *)(request
->channels
+ n_channels
);
4423 request
->n_match_sets
= n_match_sets
;
4426 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4427 /* user specified, bail out if channel not found */
4428 nla_for_each_nested(attr
,
4429 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
4431 struct ieee80211_channel
*chan
;
4433 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4440 /* ignore disabled channels */
4441 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4444 request
->channels
[i
] = chan
;
4449 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4451 if (!wiphy
->bands
[band
])
4453 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4454 struct ieee80211_channel
*chan
;
4456 chan
= &wiphy
->bands
[band
]->channels
[j
];
4458 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4461 request
->channels
[i
] = chan
;
4472 request
->n_channels
= i
;
4475 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4476 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4478 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4482 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4483 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
4490 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
4491 nla_for_each_nested(attr
,
4492 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4494 struct nlattr
*ssid
, *rssi
;
4496 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
4497 nla_data(attr
), nla_len(attr
),
4498 nl80211_match_policy
);
4499 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
4501 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
4505 memcpy(request
->match_sets
[i
].ssid
.ssid
,
4506 nla_data(ssid
), nla_len(ssid
));
4507 request
->match_sets
[i
].ssid
.ssid_len
=
4510 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
4512 request
->rssi_thold
= nla_get_u32(rssi
);
4514 request
->rssi_thold
=
4515 NL80211_SCAN_RSSI_THOLD_OFF
;
4520 if (info
->attrs
[NL80211_ATTR_IE
]) {
4521 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4522 memcpy((void *)request
->ie
,
4523 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4528 request
->wiphy
= &rdev
->wiphy
;
4529 request
->interval
= interval
;
4531 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
4533 rdev
->sched_scan_req
= request
;
4534 nl80211_send_sched_scan(rdev
, dev
,
4535 NL80211_CMD_START_SCHED_SCAN
);
4542 mutex_unlock(&rdev
->sched_scan_mtx
);
4546 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
4547 struct genl_info
*info
)
4549 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4552 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4553 !rdev
->ops
->sched_scan_stop
)
4556 mutex_lock(&rdev
->sched_scan_mtx
);
4557 err
= __cfg80211_stop_sched_scan(rdev
, false);
4558 mutex_unlock(&rdev
->sched_scan_mtx
);
4563 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
4565 struct cfg80211_registered_device
*rdev
,
4566 struct wireless_dev
*wdev
,
4567 struct cfg80211_internal_bss
*intbss
)
4569 struct cfg80211_bss
*res
= &intbss
->pub
;
4573 ASSERT_WDEV_LOCK(wdev
);
4575 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).pid
, seq
, flags
,
4576 NL80211_CMD_NEW_SCAN_RESULTS
);
4580 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
4582 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
) ||
4583 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
4584 goto nla_put_failure
;
4586 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
4588 goto nla_put_failure
;
4589 if ((!is_zero_ether_addr(res
->bssid
) &&
4590 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)) ||
4591 (res
->information_elements
&& res
->len_information_elements
&&
4592 nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
4593 res
->len_information_elements
,
4594 res
->information_elements
)) ||
4595 (res
->beacon_ies
&& res
->len_beacon_ies
&&
4596 res
->beacon_ies
!= res
->information_elements
&&
4597 nla_put(msg
, NL80211_BSS_BEACON_IES
,
4598 res
->len_beacon_ies
, res
->beacon_ies
)))
4599 goto nla_put_failure
;
4601 nla_put_u64(msg
, NL80211_BSS_TSF
, res
->tsf
))
4602 goto nla_put_failure
;
4603 if (res
->beacon_interval
&&
4604 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
4605 goto nla_put_failure
;
4606 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
4607 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
4608 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
4609 jiffies_to_msecs(jiffies
- intbss
->ts
)))
4610 goto nla_put_failure
;
4612 switch (rdev
->wiphy
.signal_type
) {
4613 case CFG80211_SIGNAL_TYPE_MBM
:
4614 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
4615 goto nla_put_failure
;
4617 case CFG80211_SIGNAL_TYPE_UNSPEC
:
4618 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
4619 goto nla_put_failure
;
4625 switch (wdev
->iftype
) {
4626 case NL80211_IFTYPE_P2P_CLIENT
:
4627 case NL80211_IFTYPE_STATION
:
4628 if (intbss
== wdev
->current_bss
&&
4629 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4630 NL80211_BSS_STATUS_ASSOCIATED
))
4631 goto nla_put_failure
;
4633 case NL80211_IFTYPE_ADHOC
:
4634 if (intbss
== wdev
->current_bss
&&
4635 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4636 NL80211_BSS_STATUS_IBSS_JOINED
))
4637 goto nla_put_failure
;
4643 nla_nest_end(msg
, bss
);
4645 return genlmsg_end(msg
, hdr
);
4648 genlmsg_cancel(msg
, hdr
);
4652 static int nl80211_dump_scan(struct sk_buff
*skb
,
4653 struct netlink_callback
*cb
)
4655 struct cfg80211_registered_device
*rdev
;
4656 struct net_device
*dev
;
4657 struct cfg80211_internal_bss
*scan
;
4658 struct wireless_dev
*wdev
;
4659 int start
= cb
->args
[1], idx
= 0;
4662 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4666 wdev
= dev
->ieee80211_ptr
;
4669 spin_lock_bh(&rdev
->bss_lock
);
4670 cfg80211_bss_expire(rdev
);
4672 cb
->seq
= rdev
->bss_generation
;
4674 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4677 if (nl80211_send_bss(skb
, cb
,
4678 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4679 rdev
, wdev
, scan
) < 0) {
4685 spin_unlock_bh(&rdev
->bss_lock
);
4689 nl80211_finish_netdev_dump(rdev
);
4694 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
4695 int flags
, struct net_device
*dev
,
4696 struct survey_info
*survey
)
4699 struct nlattr
*infoattr
;
4701 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
4702 NL80211_CMD_NEW_SURVEY_RESULTS
);
4706 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
4707 goto nla_put_failure
;
4709 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4711 goto nla_put_failure
;
4713 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4714 survey
->channel
->center_freq
))
4715 goto nla_put_failure
;
4717 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
4718 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
4719 goto nla_put_failure
;
4720 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
4721 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
4722 goto nla_put_failure
;
4723 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
4724 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4725 survey
->channel_time
))
4726 goto nla_put_failure
;
4727 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
4728 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4729 survey
->channel_time_busy
))
4730 goto nla_put_failure
;
4731 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
4732 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4733 survey
->channel_time_ext_busy
))
4734 goto nla_put_failure
;
4735 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
4736 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4737 survey
->channel_time_rx
))
4738 goto nla_put_failure
;
4739 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
4740 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4741 survey
->channel_time_tx
))
4742 goto nla_put_failure
;
4744 nla_nest_end(msg
, infoattr
);
4746 return genlmsg_end(msg
, hdr
);
4749 genlmsg_cancel(msg
, hdr
);
4753 static int nl80211_dump_survey(struct sk_buff
*skb
,
4754 struct netlink_callback
*cb
)
4756 struct survey_info survey
;
4757 struct cfg80211_registered_device
*dev
;
4758 struct net_device
*netdev
;
4759 int survey_idx
= cb
->args
[1];
4762 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4766 if (!dev
->ops
->dump_survey
) {
4772 struct ieee80211_channel
*chan
;
4774 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4781 /* Survey without a channel doesn't make sense */
4782 if (!survey
.channel
) {
4787 chan
= ieee80211_get_channel(&dev
->wiphy
,
4788 survey
.channel
->center_freq
);
4789 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4794 if (nl80211_send_survey(skb
,
4795 NETLINK_CB(cb
->skb
).pid
,
4796 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4804 cb
->args
[1] = survey_idx
;
4807 nl80211_finish_netdev_dump(dev
);
4811 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
4813 return auth_type
<= NL80211_AUTHTYPE_MAX
;
4816 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4818 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4819 NL80211_WPA_VERSION_2
));
4822 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4824 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4825 struct net_device
*dev
= info
->user_ptr
[1];
4826 struct ieee80211_channel
*chan
;
4827 const u8
*bssid
, *ssid
, *ie
= NULL
;
4828 int err
, ssid_len
, ie_len
= 0;
4829 enum nl80211_auth_type auth_type
;
4830 struct key_parse key
;
4831 bool local_state_change
;
4833 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4836 if (!info
->attrs
[NL80211_ATTR_MAC
])
4839 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4842 if (!info
->attrs
[NL80211_ATTR_SSID
])
4845 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4848 err
= nl80211_parse_key(info
, &key
);
4853 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4855 if (!key
.p
.key
|| !key
.p
.key_len
)
4857 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4858 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4859 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4860 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4872 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4873 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4882 if (!rdev
->ops
->auth
)
4885 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4886 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4889 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4890 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4891 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4892 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4895 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4896 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4898 if (info
->attrs
[NL80211_ATTR_IE
]) {
4899 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4900 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4903 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4904 if (!nl80211_valid_auth_type(auth_type
))
4907 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4910 * Since we no longer track auth state, ignore
4911 * requests to only change local state.
4913 if (local_state_change
)
4916 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4917 ssid
, ssid_len
, ie
, ie_len
,
4918 key
.p
.key
, key
.p
.key_len
, key
.idx
);
4921 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
4922 struct genl_info
*info
,
4923 struct cfg80211_crypto_settings
*settings
,
4926 memset(settings
, 0, sizeof(*settings
));
4928 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
4930 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
4932 proto
= nla_get_u16(
4933 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
4934 settings
->control_port_ethertype
= cpu_to_be16(proto
);
4935 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
4938 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4939 settings
->control_port_no_encrypt
= true;
4941 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4943 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4947 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4948 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4949 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4951 if (len
% sizeof(u32
))
4954 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4957 memcpy(settings
->ciphers_pairwise
, data
, len
);
4959 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4960 if (!cfg80211_supported_cipher_suite(
4962 settings
->ciphers_pairwise
[i
]))
4966 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4967 settings
->cipher_group
=
4968 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4969 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
4970 settings
->cipher_group
))
4974 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4975 settings
->wpa_versions
=
4976 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4977 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4981 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4985 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4986 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4987 settings
->n_akm_suites
= len
/ sizeof(u32
);
4989 if (len
% sizeof(u32
))
4992 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4995 memcpy(settings
->akm_suites
, data
, len
);
5001 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
5003 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5004 struct net_device
*dev
= info
->user_ptr
[1];
5005 struct cfg80211_crypto_settings crypto
;
5006 struct ieee80211_channel
*chan
;
5007 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
5008 int err
, ssid_len
, ie_len
= 0;
5009 bool use_mfp
= false;
5011 struct ieee80211_ht_cap
*ht_capa
= NULL
;
5012 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
5014 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5017 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
5018 !info
->attrs
[NL80211_ATTR_SSID
] ||
5019 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5022 if (!rdev
->ops
->assoc
)
5025 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5026 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5029 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5031 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5032 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5033 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5036 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5037 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5039 if (info
->attrs
[NL80211_ATTR_IE
]) {
5040 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5041 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5044 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
5045 enum nl80211_mfp mfp
=
5046 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
5047 if (mfp
== NL80211_MFP_REQUIRED
)
5049 else if (mfp
!= NL80211_MFP_NO
)
5053 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
5054 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
5056 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5057 flags
|= ASSOC_REQ_DISABLE_HT
;
5059 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5061 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
5063 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5066 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5069 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
5071 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
5072 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
5073 &crypto
, flags
, ht_capa
,
5079 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5081 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5082 struct net_device
*dev
= info
->user_ptr
[1];
5083 const u8
*ie
= NULL
, *bssid
;
5086 bool local_state_change
;
5088 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5091 if (!info
->attrs
[NL80211_ATTR_MAC
])
5094 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5097 if (!rdev
->ops
->deauth
)
5100 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5101 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5104 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5106 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5107 if (reason_code
== 0) {
5108 /* Reason Code 0 is reserved */
5112 if (info
->attrs
[NL80211_ATTR_IE
]) {
5113 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5114 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5117 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5119 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5120 local_state_change
);
5123 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
5125 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5126 struct net_device
*dev
= info
->user_ptr
[1];
5127 const u8
*ie
= NULL
, *bssid
;
5130 bool local_state_change
;
5132 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5135 if (!info
->attrs
[NL80211_ATTR_MAC
])
5138 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5141 if (!rdev
->ops
->disassoc
)
5144 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5145 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5148 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5150 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5151 if (reason_code
== 0) {
5152 /* Reason Code 0 is reserved */
5156 if (info
->attrs
[NL80211_ATTR_IE
]) {
5157 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5158 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5161 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5163 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5164 local_state_change
);
5168 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
5169 int mcast_rate
[IEEE80211_NUM_BANDS
],
5172 struct wiphy
*wiphy
= &rdev
->wiphy
;
5176 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5177 struct ieee80211_supported_band
*sband
;
5179 sband
= wiphy
->bands
[band
];
5183 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
5184 if (sband
->bitrates
[i
].bitrate
== rateval
) {
5185 mcast_rate
[band
] = i
+ 1;
5195 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5197 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5198 struct net_device
*dev
= info
->user_ptr
[1];
5199 struct cfg80211_ibss_params ibss
;
5200 struct wiphy
*wiphy
;
5201 struct cfg80211_cached_keys
*connkeys
= NULL
;
5204 memset(&ibss
, 0, sizeof(ibss
));
5206 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5209 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5210 !info
->attrs
[NL80211_ATTR_SSID
] ||
5211 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5214 ibss
.beacon_interval
= 100;
5216 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
5217 ibss
.beacon_interval
=
5218 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5219 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
5223 if (!rdev
->ops
->join_ibss
)
5226 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5229 wiphy
= &rdev
->wiphy
;
5231 if (info
->attrs
[NL80211_ATTR_MAC
]) {
5232 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5234 if (!is_valid_ether_addr(ibss
.bssid
))
5237 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5238 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5240 if (info
->attrs
[NL80211_ATTR_IE
]) {
5241 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5242 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5245 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5246 enum nl80211_channel_type channel_type
;
5248 if (!nl80211_valid_channel_type(info
, &channel_type
))
5251 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5252 !(wiphy
->features
& NL80211_FEATURE_HT_IBSS
))
5255 ibss
.channel_type
= channel_type
;
5257 ibss
.channel_type
= NL80211_CHAN_NO_HT
;
5260 ibss
.channel
= rdev_freq_to_chan(rdev
,
5261 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
5263 if (!ibss
.channel
||
5264 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
5265 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5268 /* Both channels should be able to initiate communication */
5269 if ((ibss
.channel_type
== NL80211_CHAN_HT40PLUS
||
5270 ibss
.channel_type
== NL80211_CHAN_HT40MINUS
) &&
5271 !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, ibss
.channel
,
5275 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
5276 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5278 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5280 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5282 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5283 struct ieee80211_supported_band
*sband
=
5284 wiphy
->bands
[ibss
.channel
->band
];
5286 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
5292 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5293 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
5294 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5297 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5298 connkeys
= nl80211_parse_connkeys(rdev
,
5299 info
->attrs
[NL80211_ATTR_KEYS
]);
5300 if (IS_ERR(connkeys
))
5301 return PTR_ERR(connkeys
);
5305 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
5307 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
5313 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5315 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5316 struct net_device
*dev
= info
->user_ptr
[1];
5318 if (!rdev
->ops
->leave_ibss
)
5321 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5324 return cfg80211_leave_ibss(rdev
, dev
, false);
5327 #ifdef CONFIG_NL80211_TESTMODE
5328 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
5332 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
5334 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5337 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
5341 if (rdev
->ops
->testmode_cmd
) {
5342 rdev
->testmode_info
= info
;
5343 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
5344 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
5345 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
5346 rdev
->testmode_info
= NULL
;
5352 static int nl80211_testmode_dump(struct sk_buff
*skb
,
5353 struct netlink_callback
*cb
)
5355 struct cfg80211_registered_device
*rdev
;
5363 * 0 is a valid index, but not valid for args[0],
5364 * so we need to offset by 1.
5366 phy_idx
= cb
->args
[0] - 1;
5368 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
5369 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
5374 mutex_lock(&cfg80211_mutex
);
5375 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
5376 nl80211_fam
.attrbuf
);
5378 mutex_unlock(&cfg80211_mutex
);
5379 return PTR_ERR(rdev
);
5381 phy_idx
= rdev
->wiphy_idx
;
5383 mutex_unlock(&cfg80211_mutex
);
5385 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
5387 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
5391 data
= nla_data((void *)cb
->args
[1]);
5392 data_len
= nla_len((void *)cb
->args
[1]);
5395 mutex_lock(&cfg80211_mutex
);
5396 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
5398 mutex_unlock(&cfg80211_mutex
);
5401 cfg80211_lock_rdev(rdev
);
5402 mutex_unlock(&cfg80211_mutex
);
5404 if (!rdev
->ops
->testmode_dump
) {
5410 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).pid
,
5411 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5412 NL80211_CMD_TESTMODE
);
5413 struct nlattr
*tmdata
;
5415 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
5416 genlmsg_cancel(skb
, hdr
);
5420 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5422 genlmsg_cancel(skb
, hdr
);
5425 err
= rdev
->ops
->testmode_dump(&rdev
->wiphy
, skb
, cb
,
5427 nla_nest_end(skb
, tmdata
);
5429 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
5430 genlmsg_cancel(skb
, hdr
);
5433 genlmsg_cancel(skb
, hdr
);
5437 genlmsg_end(skb
, hdr
);
5442 cb
->args
[0] = phy_idx
+ 1;
5444 cfg80211_unlock_rdev(rdev
);
5448 static struct sk_buff
*
5449 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
5450 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
5452 struct sk_buff
*skb
;
5454 struct nlattr
*data
;
5456 skb
= nlmsg_new(approxlen
+ 100, gfp
);
5460 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
5466 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
5467 goto nla_put_failure
;
5468 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5470 ((void **)skb
->cb
)[0] = rdev
;
5471 ((void **)skb
->cb
)[1] = hdr
;
5472 ((void **)skb
->cb
)[2] = data
;
5481 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
5484 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5486 if (WARN_ON(!rdev
->testmode_info
))
5489 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
5490 rdev
->testmode_info
->snd_pid
,
5491 rdev
->testmode_info
->snd_seq
,
5494 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
5496 int cfg80211_testmode_reply(struct sk_buff
*skb
)
5498 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
5499 void *hdr
= ((void **)skb
->cb
)[1];
5500 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5502 if (WARN_ON(!rdev
->testmode_info
)) {
5507 nla_nest_end(skb
, data
);
5508 genlmsg_end(skb
, hdr
);
5509 return genlmsg_reply(skb
, rdev
->testmode_info
);
5511 EXPORT_SYMBOL(cfg80211_testmode_reply
);
5513 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
5514 int approxlen
, gfp_t gfp
)
5516 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5518 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
5520 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
5522 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
5524 void *hdr
= ((void **)skb
->cb
)[1];
5525 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5527 nla_nest_end(skb
, data
);
5528 genlmsg_end(skb
, hdr
);
5529 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
5531 EXPORT_SYMBOL(cfg80211_testmode_event
);
5534 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
5536 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5537 struct net_device
*dev
= info
->user_ptr
[1];
5538 struct cfg80211_connect_params connect
;
5539 struct wiphy
*wiphy
;
5540 struct cfg80211_cached_keys
*connkeys
= NULL
;
5543 memset(&connect
, 0, sizeof(connect
));
5545 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5548 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5549 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5552 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5554 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5555 if (!nl80211_valid_auth_type(connect
.auth_type
))
5558 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5560 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
5562 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
5563 NL80211_MAX_NR_CIPHER_SUITES
);
5567 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5568 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5571 wiphy
= &rdev
->wiphy
;
5573 connect
.bg_scan_period
= -1;
5574 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
5575 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
5576 connect
.bg_scan_period
=
5577 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
5580 if (info
->attrs
[NL80211_ATTR_MAC
])
5581 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5582 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5583 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5585 if (info
->attrs
[NL80211_ATTR_IE
]) {
5586 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5587 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5590 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5592 ieee80211_get_channel(wiphy
,
5593 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5594 if (!connect
.channel
||
5595 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5599 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5600 connkeys
= nl80211_parse_connkeys(rdev
,
5601 info
->attrs
[NL80211_ATTR_KEYS
]);
5602 if (IS_ERR(connkeys
))
5603 return PTR_ERR(connkeys
);
5606 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5607 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
5609 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5610 memcpy(&connect
.ht_capa_mask
,
5611 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
5612 sizeof(connect
.ht_capa_mask
));
5614 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5615 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5617 memcpy(&connect
.ht_capa
,
5618 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
5619 sizeof(connect
.ht_capa
));
5622 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
5628 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
5630 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5631 struct net_device
*dev
= info
->user_ptr
[1];
5634 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5635 reason
= WLAN_REASON_DEAUTH_LEAVING
;
5637 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5642 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5643 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5646 return cfg80211_disconnect(rdev
, dev
, reason
, true);
5649 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
5651 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5656 if (!info
->attrs
[NL80211_ATTR_PID
])
5659 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
5661 net
= get_net_ns_by_pid(pid
);
5663 return PTR_ERR(net
);
5667 /* check if anything to do */
5668 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
5669 err
= cfg80211_switch_netns(rdev
, net
);
5675 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5677 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5678 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
5679 struct cfg80211_pmksa
*pmksa
) = NULL
;
5680 struct net_device
*dev
= info
->user_ptr
[1];
5681 struct cfg80211_pmksa pmksa
;
5683 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
5685 if (!info
->attrs
[NL80211_ATTR_MAC
])
5688 if (!info
->attrs
[NL80211_ATTR_PMKID
])
5691 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
5692 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5694 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5695 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5698 switch (info
->genlhdr
->cmd
) {
5699 case NL80211_CMD_SET_PMKSA
:
5700 rdev_ops
= rdev
->ops
->set_pmksa
;
5702 case NL80211_CMD_DEL_PMKSA
:
5703 rdev_ops
= rdev
->ops
->del_pmksa
;
5713 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
5716 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5718 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5719 struct net_device
*dev
= info
->user_ptr
[1];
5721 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5722 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5725 if (!rdev
->ops
->flush_pmksa
)
5728 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
5731 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5733 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5734 struct net_device
*dev
= info
->user_ptr
[1];
5735 u8 action_code
, dialog_token
;
5739 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5740 !rdev
->ops
->tdls_mgmt
)
5743 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5744 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5745 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5746 !info
->attrs
[NL80211_ATTR_IE
] ||
5747 !info
->attrs
[NL80211_ATTR_MAC
])
5750 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5751 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5752 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5753 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5755 return rdev
->ops
->tdls_mgmt(&rdev
->wiphy
, dev
, peer
, action_code
,
5756 dialog_token
, status_code
,
5757 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5758 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5761 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5763 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5764 struct net_device
*dev
= info
->user_ptr
[1];
5765 enum nl80211_tdls_operation operation
;
5768 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5769 !rdev
->ops
->tdls_oper
)
5772 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5773 !info
->attrs
[NL80211_ATTR_MAC
])
5776 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5777 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5779 return rdev
->ops
->tdls_oper(&rdev
->wiphy
, dev
, peer
, operation
);
5782 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5783 struct genl_info
*info
)
5785 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5786 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5787 struct ieee80211_channel
*chan
;
5788 struct sk_buff
*msg
;
5791 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5795 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5796 !info
->attrs
[NL80211_ATTR_DURATION
])
5799 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5801 if (!rdev
->ops
->remain_on_channel
||
5802 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
5806 * We should be on that channel for at least a minimum amount of
5807 * time (10ms) but no longer than the driver supports.
5809 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
5810 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5813 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
5814 !nl80211_valid_channel_type(info
, &channel_type
))
5817 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5818 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5822 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5826 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5827 NL80211_CMD_REMAIN_ON_CHANNEL
);
5834 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, wdev
, chan
,
5835 channel_type
, duration
, &cookie
);
5840 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
5841 goto nla_put_failure
;
5843 genlmsg_end(msg
, hdr
);
5845 return genlmsg_reply(msg
, info
);
5854 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5855 struct genl_info
*info
)
5857 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5858 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5861 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5864 if (!rdev
->ops
->cancel_remain_on_channel
)
5867 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5869 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, wdev
, cookie
);
5872 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5873 u8
*rates
, u8 rates_len
)
5878 for (i
= 0; i
< rates_len
; i
++) {
5879 int rate
= (rates
[i
] & 0x7f) * 5;
5881 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5882 struct ieee80211_rate
*srate
=
5883 &sband
->bitrates
[ridx
];
5884 if (rate
== srate
->bitrate
) {
5889 if (ridx
== sband
->n_bitrates
)
5890 return 0; /* rate not found */
5896 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
5897 u8
*rates
, u8 rates_len
,
5898 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
5902 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
5904 for (i
= 0; i
< rates_len
; i
++) {
5907 ridx
= rates
[i
] / 8;
5908 rbit
= BIT(rates
[i
] % 8);
5910 /* check validity */
5911 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
5914 /* check availability */
5915 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
5924 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
5925 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
5926 .len
= NL80211_MAX_SUPP_RATES
},
5927 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
5928 .len
= NL80211_MAX_SUPP_HT_RATES
},
5931 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
5932 struct genl_info
*info
)
5934 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
5935 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5936 struct cfg80211_bitrate_mask mask
;
5938 struct net_device
*dev
= info
->user_ptr
[1];
5939 struct nlattr
*tx_rates
;
5940 struct ieee80211_supported_band
*sband
;
5942 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
5945 if (!rdev
->ops
->set_bitrate_mask
)
5948 memset(&mask
, 0, sizeof(mask
));
5949 /* Default to all rates enabled */
5950 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
5951 sband
= rdev
->wiphy
.bands
[i
];
5952 mask
.control
[i
].legacy
=
5953 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
5955 memcpy(mask
.control
[i
].mcs
,
5956 sband
->ht_cap
.mcs
.rx_mask
,
5957 sizeof(mask
.control
[i
].mcs
));
5959 memset(mask
.control
[i
].mcs
, 0,
5960 sizeof(mask
.control
[i
].mcs
));
5964 * The nested attribute uses enum nl80211_band as the index. This maps
5965 * directly to the enum ieee80211_band values used in cfg80211.
5967 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
5968 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
5970 enum ieee80211_band band
= nla_type(tx_rates
);
5971 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
5973 sband
= rdev
->wiphy
.bands
[band
];
5976 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
5977 nla_len(tx_rates
), nl80211_txattr_policy
);
5978 if (tb
[NL80211_TXRATE_LEGACY
]) {
5979 mask
.control
[band
].legacy
= rateset_to_mask(
5981 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
5982 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
5983 if ((mask
.control
[band
].legacy
== 0) &&
5984 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
5987 if (tb
[NL80211_TXRATE_MCS
]) {
5988 if (!ht_rateset_to_mask(
5990 nla_data(tb
[NL80211_TXRATE_MCS
]),
5991 nla_len(tb
[NL80211_TXRATE_MCS
]),
5992 mask
.control
[band
].mcs
))
5996 if (mask
.control
[band
].legacy
== 0) {
5997 /* don't allow empty legacy rates if HT
5998 * is not even supported. */
5999 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
6002 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
6003 if (mask
.control
[band
].mcs
[i
])
6006 /* legacy and mcs rates may not be both empty */
6007 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
6012 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
6015 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6017 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6018 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6019 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
6021 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
6024 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
6025 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
6027 switch (wdev
->iftype
) {
6028 case NL80211_IFTYPE_STATION
:
6029 case NL80211_IFTYPE_ADHOC
:
6030 case NL80211_IFTYPE_P2P_CLIENT
:
6031 case NL80211_IFTYPE_AP
:
6032 case NL80211_IFTYPE_AP_VLAN
:
6033 case NL80211_IFTYPE_MESH_POINT
:
6034 case NL80211_IFTYPE_P2P_GO
:
6040 /* not much point in registering if we can't reply */
6041 if (!rdev
->ops
->mgmt_tx
)
6044 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_pid
, frame_type
,
6045 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
6046 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
6049 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6051 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6052 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6053 struct ieee80211_channel
*chan
;
6054 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6055 bool channel_type_valid
= false;
6060 struct sk_buff
*msg
= NULL
;
6061 unsigned int wait
= 0;
6062 bool offchan
, no_cck
, dont_wait_for_ack
;
6064 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
6066 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
6067 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6070 if (!rdev
->ops
->mgmt_tx
)
6073 switch (wdev
->iftype
) {
6074 case NL80211_IFTYPE_STATION
:
6075 case NL80211_IFTYPE_ADHOC
:
6076 case NL80211_IFTYPE_P2P_CLIENT
:
6077 case NL80211_IFTYPE_AP
:
6078 case NL80211_IFTYPE_AP_VLAN
:
6079 case NL80211_IFTYPE_MESH_POINT
:
6080 case NL80211_IFTYPE_P2P_GO
:
6086 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
6087 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6089 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6092 * We should wait on the channel for at least a minimum amount
6093 * of time (10ms) but no longer than the driver supports.
6095 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6096 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
6101 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
6102 if (!nl80211_valid_channel_type(info
, &channel_type
))
6104 channel_type_valid
= true;
6107 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
6109 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6112 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6114 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6115 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
6119 if (!dont_wait_for_ack
) {
6120 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6124 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6133 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chan
, offchan
, channel_type
,
6134 channel_type_valid
, wait
,
6135 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
6136 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
6137 no_cck
, dont_wait_for_ack
, &cookie
);
6142 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6143 goto nla_put_failure
;
6145 genlmsg_end(msg
, hdr
);
6146 return genlmsg_reply(msg
, info
);
6158 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
6160 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6161 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6164 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6167 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
6170 switch (wdev
->iftype
) {
6171 case NL80211_IFTYPE_STATION
:
6172 case NL80211_IFTYPE_ADHOC
:
6173 case NL80211_IFTYPE_P2P_CLIENT
:
6174 case NL80211_IFTYPE_AP
:
6175 case NL80211_IFTYPE_AP_VLAN
:
6176 case NL80211_IFTYPE_P2P_GO
:
6182 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6184 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, wdev
, cookie
);
6187 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6189 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6190 struct wireless_dev
*wdev
;
6191 struct net_device
*dev
= info
->user_ptr
[1];
6196 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
6199 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
6201 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
6204 wdev
= dev
->ieee80211_ptr
;
6206 if (!rdev
->ops
->set_power_mgmt
)
6209 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
6211 if (state
== wdev
->ps
)
6214 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
6221 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6223 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6224 enum nl80211_ps_state ps_state
;
6225 struct wireless_dev
*wdev
;
6226 struct net_device
*dev
= info
->user_ptr
[1];
6227 struct sk_buff
*msg
;
6231 wdev
= dev
->ieee80211_ptr
;
6233 if (!rdev
->ops
->set_power_mgmt
)
6236 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6240 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6241 NL80211_CMD_GET_POWER_SAVE
);
6248 ps_state
= NL80211_PS_ENABLED
;
6250 ps_state
= NL80211_PS_DISABLED
;
6252 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
6253 goto nla_put_failure
;
6255 genlmsg_end(msg
, hdr
);
6256 return genlmsg_reply(msg
, info
);
6265 static struct nla_policy
6266 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
6267 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
6268 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
6269 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
6272 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
6273 s32 threshold
, u32 hysteresis
)
6275 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6276 struct wireless_dev
*wdev
;
6277 struct net_device
*dev
= info
->user_ptr
[1];
6282 wdev
= dev
->ieee80211_ptr
;
6284 if (!rdev
->ops
->set_cqm_rssi_config
)
6287 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6288 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6291 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
6292 threshold
, hysteresis
);
6295 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
6297 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
6301 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
6307 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
6308 nl80211_attr_cqm_policy
);
6312 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
6313 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
6316 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
6317 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
6318 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
6326 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6328 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6329 struct net_device
*dev
= info
->user_ptr
[1];
6330 struct mesh_config cfg
;
6331 struct mesh_setup setup
;
6334 /* start with default */
6335 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
6336 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
6338 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
6339 /* and parse parameters if given */
6340 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
6345 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
6346 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
6349 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6350 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6352 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6353 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
6354 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6357 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
6358 /* parse additional setup parameters if given */
6359 err
= nl80211_parse_mesh_setup(info
, &setup
);
6364 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6365 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6367 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
6368 !nl80211_valid_channel_type(info
, &channel_type
))
6371 setup
.channel
= rdev_freq_to_chan(rdev
,
6372 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
6376 setup
.channel_type
= channel_type
;
6378 /* cfg80211_join_mesh() will sort it out */
6379 setup
.channel
= NULL
;
6382 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
6385 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6387 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6388 struct net_device
*dev
= info
->user_ptr
[1];
6390 return cfg80211_leave_mesh(rdev
, dev
);
6394 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6396 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6397 struct sk_buff
*msg
;
6400 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6403 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6407 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6408 NL80211_CMD_GET_WOWLAN
);
6410 goto nla_put_failure
;
6413 struct nlattr
*nl_wowlan
;
6415 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
6417 goto nla_put_failure
;
6419 if ((rdev
->wowlan
->any
&&
6420 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
6421 (rdev
->wowlan
->disconnect
&&
6422 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
6423 (rdev
->wowlan
->magic_pkt
&&
6424 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
6425 (rdev
->wowlan
->gtk_rekey_failure
&&
6426 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
6427 (rdev
->wowlan
->eap_identity_req
&&
6428 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
6429 (rdev
->wowlan
->four_way_handshake
&&
6430 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
6431 (rdev
->wowlan
->rfkill_release
&&
6432 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
6433 goto nla_put_failure
;
6434 if (rdev
->wowlan
->n_patterns
) {
6435 struct nlattr
*nl_pats
, *nl_pat
;
6438 nl_pats
= nla_nest_start(msg
,
6439 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
6441 goto nla_put_failure
;
6443 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
6444 nl_pat
= nla_nest_start(msg
, i
+ 1);
6446 goto nla_put_failure
;
6447 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
6448 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
6449 DIV_ROUND_UP(pat_len
, 8),
6450 rdev
->wowlan
->patterns
[i
].mask
) ||
6451 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
6453 rdev
->wowlan
->patterns
[i
].pattern
))
6454 goto nla_put_failure
;
6455 nla_nest_end(msg
, nl_pat
);
6457 nla_nest_end(msg
, nl_pats
);
6460 nla_nest_end(msg
, nl_wowlan
);
6463 genlmsg_end(msg
, hdr
);
6464 return genlmsg_reply(msg
, info
);
6471 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6473 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6474 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
6475 struct cfg80211_wowlan new_triggers
= {};
6476 struct cfg80211_wowlan
*ntrig
;
6477 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
6479 bool prev_enabled
= rdev
->wowlan
;
6481 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6484 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
6485 cfg80211_rdev_free_wowlan(rdev
);
6486 rdev
->wowlan
= NULL
;
6490 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
6491 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6492 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6493 nl80211_wowlan_policy
);
6497 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
6498 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
6500 new_triggers
.any
= true;
6503 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
6504 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
6506 new_triggers
.disconnect
= true;
6509 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
6510 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
6512 new_triggers
.magic_pkt
= true;
6515 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
6518 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
6519 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
6521 new_triggers
.gtk_rekey_failure
= true;
6524 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
6525 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
6527 new_triggers
.eap_identity_req
= true;
6530 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
6531 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
6533 new_triggers
.four_way_handshake
= true;
6536 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
6537 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
6539 new_triggers
.rfkill_release
= true;
6542 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
6545 int rem
, pat_len
, mask_len
;
6546 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
6548 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6551 if (n_patterns
> wowlan
->n_patterns
)
6554 new_triggers
.patterns
= kcalloc(n_patterns
,
6555 sizeof(new_triggers
.patterns
[0]),
6557 if (!new_triggers
.patterns
)
6560 new_triggers
.n_patterns
= n_patterns
;
6563 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6565 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
6566 nla_data(pat
), nla_len(pat
), NULL
);
6568 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
6569 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
6571 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
6572 mask_len
= DIV_ROUND_UP(pat_len
, 8);
6573 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
6576 if (pat_len
> wowlan
->pattern_max_len
||
6577 pat_len
< wowlan
->pattern_min_len
)
6580 new_triggers
.patterns
[i
].mask
=
6581 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
6582 if (!new_triggers
.patterns
[i
].mask
) {
6586 new_triggers
.patterns
[i
].pattern
=
6587 new_triggers
.patterns
[i
].mask
+ mask_len
;
6588 memcpy(new_triggers
.patterns
[i
].mask
,
6589 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
6591 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
6592 memcpy(new_triggers
.patterns
[i
].pattern
,
6593 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
6599 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
6604 cfg80211_rdev_free_wowlan(rdev
);
6605 rdev
->wowlan
= ntrig
;
6608 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
6609 rdev
->ops
->set_wakeup(&rdev
->wiphy
, rdev
->wowlan
);
6613 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
6614 kfree(new_triggers
.patterns
[i
].mask
);
6615 kfree(new_triggers
.patterns
);
6620 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
6622 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6623 struct net_device
*dev
= info
->user_ptr
[1];
6624 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6625 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
6626 struct cfg80211_gtk_rekey_data rekey_data
;
6629 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
6632 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
6633 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6634 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6635 nl80211_rekey_policy
);
6639 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
6641 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
6643 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
6646 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
6648 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
6650 memcpy(rekey_data
.replay_ctr
,
6651 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
6652 NL80211_REPLAY_CTR_LEN
);
6655 if (!wdev
->current_bss
) {
6660 if (!rdev
->ops
->set_rekey_data
) {
6665 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
6671 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
6672 struct genl_info
*info
)
6674 struct net_device
*dev
= info
->user_ptr
[1];
6675 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6677 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6678 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6681 if (wdev
->ap_unexpected_nlpid
)
6684 wdev
->ap_unexpected_nlpid
= info
->snd_pid
;
6688 static int nl80211_probe_client(struct sk_buff
*skb
,
6689 struct genl_info
*info
)
6691 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6692 struct net_device
*dev
= info
->user_ptr
[1];
6693 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6694 struct sk_buff
*msg
;
6700 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6701 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6704 if (!info
->attrs
[NL80211_ATTR_MAC
])
6707 if (!rdev
->ops
->probe_client
)
6710 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6714 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6715 NL80211_CMD_PROBE_CLIENT
);
6722 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6724 err
= rdev
->ops
->probe_client(&rdev
->wiphy
, dev
, addr
, &cookie
);
6728 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6729 goto nla_put_failure
;
6731 genlmsg_end(msg
, hdr
);
6733 return genlmsg_reply(msg
, info
);
6742 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
6744 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6746 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
6749 if (rdev
->ap_beacons_nlpid
)
6752 rdev
->ap_beacons_nlpid
= info
->snd_pid
;
6757 #define NL80211_FLAG_NEED_WIPHY 0x01
6758 #define NL80211_FLAG_NEED_NETDEV 0x02
6759 #define NL80211_FLAG_NEED_RTNL 0x04
6760 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6761 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6762 NL80211_FLAG_CHECK_NETDEV_UP)
6763 #define NL80211_FLAG_NEED_WDEV 0x10
6764 /* If a netdev is associated, it must be UP */
6765 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6766 NL80211_FLAG_CHECK_NETDEV_UP)
6768 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6769 struct genl_info
*info
)
6771 struct cfg80211_registered_device
*rdev
;
6772 struct wireless_dev
*wdev
;
6773 struct net_device
*dev
;
6774 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
6779 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
6780 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6784 return PTR_ERR(rdev
);
6786 info
->user_ptr
[0] = rdev
;
6787 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
6788 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
6789 mutex_lock(&cfg80211_mutex
);
6790 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
6793 mutex_unlock(&cfg80211_mutex
);
6796 return PTR_ERR(wdev
);
6800 rdev
= wiphy_to_dev(wdev
->wiphy
);
6802 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
6804 mutex_unlock(&cfg80211_mutex
);
6810 info
->user_ptr
[1] = dev
;
6812 info
->user_ptr
[1] = wdev
;
6816 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
6817 !netif_running(dev
)) {
6818 mutex_unlock(&cfg80211_mutex
);
6827 cfg80211_lock_rdev(rdev
);
6829 mutex_unlock(&cfg80211_mutex
);
6831 info
->user_ptr
[0] = rdev
;
6837 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6838 struct genl_info
*info
)
6840 if (info
->user_ptr
[0])
6841 cfg80211_unlock_rdev(info
->user_ptr
[0]);
6842 if (info
->user_ptr
[1]) {
6843 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
6844 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6847 dev_put(wdev
->netdev
);
6849 dev_put(info
->user_ptr
[1]);
6852 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
6856 static struct genl_ops nl80211_ops
[] = {
6858 .cmd
= NL80211_CMD_GET_WIPHY
,
6859 .doit
= nl80211_get_wiphy
,
6860 .dumpit
= nl80211_dump_wiphy
,
6861 .policy
= nl80211_policy
,
6862 /* can be retrieved by unprivileged users */
6863 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
6866 .cmd
= NL80211_CMD_SET_WIPHY
,
6867 .doit
= nl80211_set_wiphy
,
6868 .policy
= nl80211_policy
,
6869 .flags
= GENL_ADMIN_PERM
,
6870 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
6873 .cmd
= NL80211_CMD_GET_INTERFACE
,
6874 .doit
= nl80211_get_interface
,
6875 .dumpit
= nl80211_dump_interface
,
6876 .policy
= nl80211_policy
,
6877 /* can be retrieved by unprivileged users */
6878 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
6881 .cmd
= NL80211_CMD_SET_INTERFACE
,
6882 .doit
= nl80211_set_interface
,
6883 .policy
= nl80211_policy
,
6884 .flags
= GENL_ADMIN_PERM
,
6885 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6886 NL80211_FLAG_NEED_RTNL
,
6889 .cmd
= NL80211_CMD_NEW_INTERFACE
,
6890 .doit
= nl80211_new_interface
,
6891 .policy
= nl80211_policy
,
6892 .flags
= GENL_ADMIN_PERM
,
6893 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6894 NL80211_FLAG_NEED_RTNL
,
6897 .cmd
= NL80211_CMD_DEL_INTERFACE
,
6898 .doit
= nl80211_del_interface
,
6899 .policy
= nl80211_policy
,
6900 .flags
= GENL_ADMIN_PERM
,
6901 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
6902 NL80211_FLAG_NEED_RTNL
,
6905 .cmd
= NL80211_CMD_GET_KEY
,
6906 .doit
= nl80211_get_key
,
6907 .policy
= nl80211_policy
,
6908 .flags
= GENL_ADMIN_PERM
,
6909 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6910 NL80211_FLAG_NEED_RTNL
,
6913 .cmd
= NL80211_CMD_SET_KEY
,
6914 .doit
= nl80211_set_key
,
6915 .policy
= nl80211_policy
,
6916 .flags
= GENL_ADMIN_PERM
,
6917 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6918 NL80211_FLAG_NEED_RTNL
,
6921 .cmd
= NL80211_CMD_NEW_KEY
,
6922 .doit
= nl80211_new_key
,
6923 .policy
= nl80211_policy
,
6924 .flags
= GENL_ADMIN_PERM
,
6925 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6926 NL80211_FLAG_NEED_RTNL
,
6929 .cmd
= NL80211_CMD_DEL_KEY
,
6930 .doit
= nl80211_del_key
,
6931 .policy
= nl80211_policy
,
6932 .flags
= GENL_ADMIN_PERM
,
6933 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6934 NL80211_FLAG_NEED_RTNL
,
6937 .cmd
= NL80211_CMD_SET_BEACON
,
6938 .policy
= nl80211_policy
,
6939 .flags
= GENL_ADMIN_PERM
,
6940 .doit
= nl80211_set_beacon
,
6941 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6942 NL80211_FLAG_NEED_RTNL
,
6945 .cmd
= NL80211_CMD_START_AP
,
6946 .policy
= nl80211_policy
,
6947 .flags
= GENL_ADMIN_PERM
,
6948 .doit
= nl80211_start_ap
,
6949 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6950 NL80211_FLAG_NEED_RTNL
,
6953 .cmd
= NL80211_CMD_STOP_AP
,
6954 .policy
= nl80211_policy
,
6955 .flags
= GENL_ADMIN_PERM
,
6956 .doit
= nl80211_stop_ap
,
6957 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6958 NL80211_FLAG_NEED_RTNL
,
6961 .cmd
= NL80211_CMD_GET_STATION
,
6962 .doit
= nl80211_get_station
,
6963 .dumpit
= nl80211_dump_station
,
6964 .policy
= nl80211_policy
,
6965 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6966 NL80211_FLAG_NEED_RTNL
,
6969 .cmd
= NL80211_CMD_SET_STATION
,
6970 .doit
= nl80211_set_station
,
6971 .policy
= nl80211_policy
,
6972 .flags
= GENL_ADMIN_PERM
,
6973 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6974 NL80211_FLAG_NEED_RTNL
,
6977 .cmd
= NL80211_CMD_NEW_STATION
,
6978 .doit
= nl80211_new_station
,
6979 .policy
= nl80211_policy
,
6980 .flags
= GENL_ADMIN_PERM
,
6981 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6982 NL80211_FLAG_NEED_RTNL
,
6985 .cmd
= NL80211_CMD_DEL_STATION
,
6986 .doit
= nl80211_del_station
,
6987 .policy
= nl80211_policy
,
6988 .flags
= GENL_ADMIN_PERM
,
6989 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6990 NL80211_FLAG_NEED_RTNL
,
6993 .cmd
= NL80211_CMD_GET_MPATH
,
6994 .doit
= nl80211_get_mpath
,
6995 .dumpit
= nl80211_dump_mpath
,
6996 .policy
= nl80211_policy
,
6997 .flags
= GENL_ADMIN_PERM
,
6998 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6999 NL80211_FLAG_NEED_RTNL
,
7002 .cmd
= NL80211_CMD_SET_MPATH
,
7003 .doit
= nl80211_set_mpath
,
7004 .policy
= nl80211_policy
,
7005 .flags
= GENL_ADMIN_PERM
,
7006 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7007 NL80211_FLAG_NEED_RTNL
,
7010 .cmd
= NL80211_CMD_NEW_MPATH
,
7011 .doit
= nl80211_new_mpath
,
7012 .policy
= nl80211_policy
,
7013 .flags
= GENL_ADMIN_PERM
,
7014 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7015 NL80211_FLAG_NEED_RTNL
,
7018 .cmd
= NL80211_CMD_DEL_MPATH
,
7019 .doit
= nl80211_del_mpath
,
7020 .policy
= nl80211_policy
,
7021 .flags
= GENL_ADMIN_PERM
,
7022 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7023 NL80211_FLAG_NEED_RTNL
,
7026 .cmd
= NL80211_CMD_SET_BSS
,
7027 .doit
= nl80211_set_bss
,
7028 .policy
= nl80211_policy
,
7029 .flags
= GENL_ADMIN_PERM
,
7030 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7031 NL80211_FLAG_NEED_RTNL
,
7034 .cmd
= NL80211_CMD_GET_REG
,
7035 .doit
= nl80211_get_reg
,
7036 .policy
= nl80211_policy
,
7037 /* can be retrieved by unprivileged users */
7040 .cmd
= NL80211_CMD_SET_REG
,
7041 .doit
= nl80211_set_reg
,
7042 .policy
= nl80211_policy
,
7043 .flags
= GENL_ADMIN_PERM
,
7046 .cmd
= NL80211_CMD_REQ_SET_REG
,
7047 .doit
= nl80211_req_set_reg
,
7048 .policy
= nl80211_policy
,
7049 .flags
= GENL_ADMIN_PERM
,
7052 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
7053 .doit
= nl80211_get_mesh_config
,
7054 .policy
= nl80211_policy
,
7055 /* can be retrieved by unprivileged users */
7056 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7057 NL80211_FLAG_NEED_RTNL
,
7060 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
7061 .doit
= nl80211_update_mesh_config
,
7062 .policy
= nl80211_policy
,
7063 .flags
= GENL_ADMIN_PERM
,
7064 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7065 NL80211_FLAG_NEED_RTNL
,
7068 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
7069 .doit
= nl80211_trigger_scan
,
7070 .policy
= nl80211_policy
,
7071 .flags
= GENL_ADMIN_PERM
,
7072 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7073 NL80211_FLAG_NEED_RTNL
,
7076 .cmd
= NL80211_CMD_GET_SCAN
,
7077 .policy
= nl80211_policy
,
7078 .dumpit
= nl80211_dump_scan
,
7081 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
7082 .doit
= nl80211_start_sched_scan
,
7083 .policy
= nl80211_policy
,
7084 .flags
= GENL_ADMIN_PERM
,
7085 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7086 NL80211_FLAG_NEED_RTNL
,
7089 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
7090 .doit
= nl80211_stop_sched_scan
,
7091 .policy
= nl80211_policy
,
7092 .flags
= GENL_ADMIN_PERM
,
7093 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7094 NL80211_FLAG_NEED_RTNL
,
7097 .cmd
= NL80211_CMD_AUTHENTICATE
,
7098 .doit
= nl80211_authenticate
,
7099 .policy
= nl80211_policy
,
7100 .flags
= GENL_ADMIN_PERM
,
7101 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7102 NL80211_FLAG_NEED_RTNL
,
7105 .cmd
= NL80211_CMD_ASSOCIATE
,
7106 .doit
= nl80211_associate
,
7107 .policy
= nl80211_policy
,
7108 .flags
= GENL_ADMIN_PERM
,
7109 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7110 NL80211_FLAG_NEED_RTNL
,
7113 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
7114 .doit
= nl80211_deauthenticate
,
7115 .policy
= nl80211_policy
,
7116 .flags
= GENL_ADMIN_PERM
,
7117 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7118 NL80211_FLAG_NEED_RTNL
,
7121 .cmd
= NL80211_CMD_DISASSOCIATE
,
7122 .doit
= nl80211_disassociate
,
7123 .policy
= nl80211_policy
,
7124 .flags
= GENL_ADMIN_PERM
,
7125 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7126 NL80211_FLAG_NEED_RTNL
,
7129 .cmd
= NL80211_CMD_JOIN_IBSS
,
7130 .doit
= nl80211_join_ibss
,
7131 .policy
= nl80211_policy
,
7132 .flags
= GENL_ADMIN_PERM
,
7133 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7134 NL80211_FLAG_NEED_RTNL
,
7137 .cmd
= NL80211_CMD_LEAVE_IBSS
,
7138 .doit
= nl80211_leave_ibss
,
7139 .policy
= nl80211_policy
,
7140 .flags
= GENL_ADMIN_PERM
,
7141 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7142 NL80211_FLAG_NEED_RTNL
,
7144 #ifdef CONFIG_NL80211_TESTMODE
7146 .cmd
= NL80211_CMD_TESTMODE
,
7147 .doit
= nl80211_testmode_do
,
7148 .dumpit
= nl80211_testmode_dump
,
7149 .policy
= nl80211_policy
,
7150 .flags
= GENL_ADMIN_PERM
,
7151 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7152 NL80211_FLAG_NEED_RTNL
,
7156 .cmd
= NL80211_CMD_CONNECT
,
7157 .doit
= nl80211_connect
,
7158 .policy
= nl80211_policy
,
7159 .flags
= GENL_ADMIN_PERM
,
7160 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7161 NL80211_FLAG_NEED_RTNL
,
7164 .cmd
= NL80211_CMD_DISCONNECT
,
7165 .doit
= nl80211_disconnect
,
7166 .policy
= nl80211_policy
,
7167 .flags
= GENL_ADMIN_PERM
,
7168 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7169 NL80211_FLAG_NEED_RTNL
,
7172 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
7173 .doit
= nl80211_wiphy_netns
,
7174 .policy
= nl80211_policy
,
7175 .flags
= GENL_ADMIN_PERM
,
7176 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7177 NL80211_FLAG_NEED_RTNL
,
7180 .cmd
= NL80211_CMD_GET_SURVEY
,
7181 .policy
= nl80211_policy
,
7182 .dumpit
= nl80211_dump_survey
,
7185 .cmd
= NL80211_CMD_SET_PMKSA
,
7186 .doit
= nl80211_setdel_pmksa
,
7187 .policy
= nl80211_policy
,
7188 .flags
= GENL_ADMIN_PERM
,
7189 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7190 NL80211_FLAG_NEED_RTNL
,
7193 .cmd
= NL80211_CMD_DEL_PMKSA
,
7194 .doit
= nl80211_setdel_pmksa
,
7195 .policy
= nl80211_policy
,
7196 .flags
= GENL_ADMIN_PERM
,
7197 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7198 NL80211_FLAG_NEED_RTNL
,
7201 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
7202 .doit
= nl80211_flush_pmksa
,
7203 .policy
= nl80211_policy
,
7204 .flags
= GENL_ADMIN_PERM
,
7205 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7206 NL80211_FLAG_NEED_RTNL
,
7209 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
7210 .doit
= nl80211_remain_on_channel
,
7211 .policy
= nl80211_policy
,
7212 .flags
= GENL_ADMIN_PERM
,
7213 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7214 NL80211_FLAG_NEED_RTNL
,
7217 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7218 .doit
= nl80211_cancel_remain_on_channel
,
7219 .policy
= nl80211_policy
,
7220 .flags
= GENL_ADMIN_PERM
,
7221 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7222 NL80211_FLAG_NEED_RTNL
,
7225 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
7226 .doit
= nl80211_set_tx_bitrate_mask
,
7227 .policy
= nl80211_policy
,
7228 .flags
= GENL_ADMIN_PERM
,
7229 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7230 NL80211_FLAG_NEED_RTNL
,
7233 .cmd
= NL80211_CMD_REGISTER_FRAME
,
7234 .doit
= nl80211_register_mgmt
,
7235 .policy
= nl80211_policy
,
7236 .flags
= GENL_ADMIN_PERM
,
7237 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7238 NL80211_FLAG_NEED_RTNL
,
7241 .cmd
= NL80211_CMD_FRAME
,
7242 .doit
= nl80211_tx_mgmt
,
7243 .policy
= nl80211_policy
,
7244 .flags
= GENL_ADMIN_PERM
,
7245 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7246 NL80211_FLAG_NEED_RTNL
,
7249 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
7250 .doit
= nl80211_tx_mgmt_cancel_wait
,
7251 .policy
= nl80211_policy
,
7252 .flags
= GENL_ADMIN_PERM
,
7253 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7254 NL80211_FLAG_NEED_RTNL
,
7257 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
7258 .doit
= nl80211_set_power_save
,
7259 .policy
= nl80211_policy
,
7260 .flags
= GENL_ADMIN_PERM
,
7261 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7262 NL80211_FLAG_NEED_RTNL
,
7265 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
7266 .doit
= nl80211_get_power_save
,
7267 .policy
= nl80211_policy
,
7268 /* can be retrieved by unprivileged users */
7269 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7270 NL80211_FLAG_NEED_RTNL
,
7273 .cmd
= NL80211_CMD_SET_CQM
,
7274 .doit
= nl80211_set_cqm
,
7275 .policy
= nl80211_policy
,
7276 .flags
= GENL_ADMIN_PERM
,
7277 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7278 NL80211_FLAG_NEED_RTNL
,
7281 .cmd
= NL80211_CMD_SET_CHANNEL
,
7282 .doit
= nl80211_set_channel
,
7283 .policy
= nl80211_policy
,
7284 .flags
= GENL_ADMIN_PERM
,
7285 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7286 NL80211_FLAG_NEED_RTNL
,
7289 .cmd
= NL80211_CMD_SET_WDS_PEER
,
7290 .doit
= nl80211_set_wds_peer
,
7291 .policy
= nl80211_policy
,
7292 .flags
= GENL_ADMIN_PERM
,
7293 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7294 NL80211_FLAG_NEED_RTNL
,
7297 .cmd
= NL80211_CMD_JOIN_MESH
,
7298 .doit
= nl80211_join_mesh
,
7299 .policy
= nl80211_policy
,
7300 .flags
= GENL_ADMIN_PERM
,
7301 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7302 NL80211_FLAG_NEED_RTNL
,
7305 .cmd
= NL80211_CMD_LEAVE_MESH
,
7306 .doit
= nl80211_leave_mesh
,
7307 .policy
= nl80211_policy
,
7308 .flags
= GENL_ADMIN_PERM
,
7309 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7310 NL80211_FLAG_NEED_RTNL
,
7314 .cmd
= NL80211_CMD_GET_WOWLAN
,
7315 .doit
= nl80211_get_wowlan
,
7316 .policy
= nl80211_policy
,
7317 /* can be retrieved by unprivileged users */
7318 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7319 NL80211_FLAG_NEED_RTNL
,
7322 .cmd
= NL80211_CMD_SET_WOWLAN
,
7323 .doit
= nl80211_set_wowlan
,
7324 .policy
= nl80211_policy
,
7325 .flags
= GENL_ADMIN_PERM
,
7326 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7327 NL80211_FLAG_NEED_RTNL
,
7331 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
7332 .doit
= nl80211_set_rekey_data
,
7333 .policy
= nl80211_policy
,
7334 .flags
= GENL_ADMIN_PERM
,
7335 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7336 NL80211_FLAG_NEED_RTNL
,
7339 .cmd
= NL80211_CMD_TDLS_MGMT
,
7340 .doit
= nl80211_tdls_mgmt
,
7341 .policy
= nl80211_policy
,
7342 .flags
= GENL_ADMIN_PERM
,
7343 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7344 NL80211_FLAG_NEED_RTNL
,
7347 .cmd
= NL80211_CMD_TDLS_OPER
,
7348 .doit
= nl80211_tdls_oper
,
7349 .policy
= nl80211_policy
,
7350 .flags
= GENL_ADMIN_PERM
,
7351 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7352 NL80211_FLAG_NEED_RTNL
,
7355 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
7356 .doit
= nl80211_register_unexpected_frame
,
7357 .policy
= nl80211_policy
,
7358 .flags
= GENL_ADMIN_PERM
,
7359 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7360 NL80211_FLAG_NEED_RTNL
,
7363 .cmd
= NL80211_CMD_PROBE_CLIENT
,
7364 .doit
= nl80211_probe_client
,
7365 .policy
= nl80211_policy
,
7366 .flags
= GENL_ADMIN_PERM
,
7367 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7368 NL80211_FLAG_NEED_RTNL
,
7371 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
7372 .doit
= nl80211_register_beacons
,
7373 .policy
= nl80211_policy
,
7374 .flags
= GENL_ADMIN_PERM
,
7375 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7376 NL80211_FLAG_NEED_RTNL
,
7379 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
7380 .doit
= nl80211_set_noack_map
,
7381 .policy
= nl80211_policy
,
7382 .flags
= GENL_ADMIN_PERM
,
7383 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7384 NL80211_FLAG_NEED_RTNL
,
7389 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
7393 /* multicast groups */
7394 static struct genl_multicast_group nl80211_config_mcgrp
= {
7397 static struct genl_multicast_group nl80211_scan_mcgrp
= {
7400 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
7401 .name
= "regulatory",
7404 /* notification functions */
7406 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
7408 struct sk_buff
*msg
;
7410 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7414 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
7419 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7420 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
7423 static int nl80211_add_scan_req(struct sk_buff
*msg
,
7424 struct cfg80211_registered_device
*rdev
)
7426 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
7427 struct nlattr
*nest
;
7430 ASSERT_RDEV_LOCK(rdev
);
7435 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
7437 goto nla_put_failure
;
7438 for (i
= 0; i
< req
->n_ssids
; i
++) {
7439 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
7440 goto nla_put_failure
;
7442 nla_nest_end(msg
, nest
);
7444 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
7446 goto nla_put_failure
;
7447 for (i
= 0; i
< req
->n_channels
; i
++) {
7448 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
7449 goto nla_put_failure
;
7451 nla_nest_end(msg
, nest
);
7454 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
7455 goto nla_put_failure
;
7462 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
7463 struct cfg80211_registered_device
*rdev
,
7464 struct wireless_dev
*wdev
,
7465 u32 pid
, u32 seq
, int flags
,
7470 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
7474 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7475 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
7476 wdev
->netdev
->ifindex
)) ||
7477 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
7478 goto nla_put_failure
;
7480 /* ignore errors and send incomplete event anyway */
7481 nl80211_add_scan_req(msg
, rdev
);
7483 return genlmsg_end(msg
, hdr
);
7486 genlmsg_cancel(msg
, hdr
);
7491 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
7492 struct cfg80211_registered_device
*rdev
,
7493 struct net_device
*netdev
,
7494 u32 pid
, u32 seq
, int flags
, u32 cmd
)
7498 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
7502 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7503 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7504 goto nla_put_failure
;
7506 return genlmsg_end(msg
, hdr
);
7509 genlmsg_cancel(msg
, hdr
);
7513 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
7514 struct wireless_dev
*wdev
)
7516 struct sk_buff
*msg
;
7518 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7522 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7523 NL80211_CMD_TRIGGER_SCAN
) < 0) {
7528 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7529 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7532 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
7533 struct wireless_dev
*wdev
)
7535 struct sk_buff
*msg
;
7537 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7541 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7542 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
7547 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7548 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7551 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
7552 struct wireless_dev
*wdev
)
7554 struct sk_buff
*msg
;
7556 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7560 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7561 NL80211_CMD_SCAN_ABORTED
) < 0) {
7566 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7567 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7570 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
7571 struct net_device
*netdev
)
7573 struct sk_buff
*msg
;
7575 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7579 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7580 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
7585 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7586 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7589 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
7590 struct net_device
*netdev
, u32 cmd
)
7592 struct sk_buff
*msg
;
7594 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7598 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
7603 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7604 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7608 * This can happen on global regulatory changes or device specific settings
7609 * based on custom world regulatory domains.
7611 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
7613 struct sk_buff
*msg
;
7616 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7620 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
7626 /* Userspace can always count this one always being set */
7627 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
7628 goto nla_put_failure
;
7630 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
7631 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7632 NL80211_REGDOM_TYPE_WORLD
))
7633 goto nla_put_failure
;
7634 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
7635 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7636 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
7637 goto nla_put_failure
;
7638 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
7639 request
->intersect
) {
7640 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7641 NL80211_REGDOM_TYPE_INTERSECTION
))
7642 goto nla_put_failure
;
7644 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7645 NL80211_REGDOM_TYPE_COUNTRY
) ||
7646 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
7648 goto nla_put_failure
;
7651 if (wiphy_idx_valid(request
->wiphy_idx
) &&
7652 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
7653 goto nla_put_failure
;
7655 genlmsg_end(msg
, hdr
);
7658 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7665 genlmsg_cancel(msg
, hdr
);
7669 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
7670 struct net_device
*netdev
,
7671 const u8
*buf
, size_t len
,
7672 enum nl80211_commands cmd
, gfp_t gfp
)
7674 struct sk_buff
*msg
;
7677 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7681 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7687 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7688 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7689 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
7690 goto nla_put_failure
;
7692 genlmsg_end(msg
, hdr
);
7694 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7695 nl80211_mlme_mcgrp
.id
, gfp
);
7699 genlmsg_cancel(msg
, hdr
);
7703 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
7704 struct net_device
*netdev
, const u8
*buf
,
7705 size_t len
, gfp_t gfp
)
7707 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7708 NL80211_CMD_AUTHENTICATE
, gfp
);
7711 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
7712 struct net_device
*netdev
, const u8
*buf
,
7713 size_t len
, gfp_t gfp
)
7715 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7716 NL80211_CMD_ASSOCIATE
, gfp
);
7719 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
7720 struct net_device
*netdev
, const u8
*buf
,
7721 size_t len
, gfp_t gfp
)
7723 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7724 NL80211_CMD_DEAUTHENTICATE
, gfp
);
7727 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
7728 struct net_device
*netdev
, const u8
*buf
,
7729 size_t len
, gfp_t gfp
)
7731 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7732 NL80211_CMD_DISASSOCIATE
, gfp
);
7735 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
7736 struct net_device
*netdev
, const u8
*buf
,
7737 size_t len
, gfp_t gfp
)
7739 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7740 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
7743 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
7744 struct net_device
*netdev
, const u8
*buf
,
7745 size_t len
, gfp_t gfp
)
7747 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7748 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
7751 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
7752 struct net_device
*netdev
, int cmd
,
7753 const u8
*addr
, gfp_t gfp
)
7755 struct sk_buff
*msg
;
7758 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7762 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7768 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7769 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7770 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
7771 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
7772 goto nla_put_failure
;
7774 genlmsg_end(msg
, hdr
);
7776 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7777 nl80211_mlme_mcgrp
.id
, gfp
);
7781 genlmsg_cancel(msg
, hdr
);
7785 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
7786 struct net_device
*netdev
, const u8
*addr
,
7789 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
7793 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
7794 struct net_device
*netdev
, const u8
*addr
,
7797 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
7801 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
7802 struct net_device
*netdev
, const u8
*bssid
,
7803 const u8
*req_ie
, size_t req_ie_len
,
7804 const u8
*resp_ie
, size_t resp_ie_len
,
7805 u16 status
, gfp_t gfp
)
7807 struct sk_buff
*msg
;
7810 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7814 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
7820 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7821 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7822 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
7823 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
7825 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
7827 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
7828 goto nla_put_failure
;
7830 genlmsg_end(msg
, hdr
);
7832 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7833 nl80211_mlme_mcgrp
.id
, gfp
);
7837 genlmsg_cancel(msg
, hdr
);
7842 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
7843 struct net_device
*netdev
, const u8
*bssid
,
7844 const u8
*req_ie
, size_t req_ie_len
,
7845 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
7847 struct sk_buff
*msg
;
7850 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7854 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
7860 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7861 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7862 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
7864 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
7866 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
7867 goto nla_put_failure
;
7869 genlmsg_end(msg
, hdr
);
7871 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7872 nl80211_mlme_mcgrp
.id
, gfp
);
7876 genlmsg_cancel(msg
, hdr
);
7881 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
7882 struct net_device
*netdev
, u16 reason
,
7883 const u8
*ie
, size_t ie_len
, bool from_ap
)
7885 struct sk_buff
*msg
;
7888 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7892 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
7898 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7899 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7900 (from_ap
&& reason
&&
7901 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
7903 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
7904 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
7905 goto nla_put_failure
;
7907 genlmsg_end(msg
, hdr
);
7909 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7910 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
7914 genlmsg_cancel(msg
, hdr
);
7919 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
7920 struct net_device
*netdev
, const u8
*bssid
,
7923 struct sk_buff
*msg
;
7926 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7930 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
7936 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7937 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7938 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
7939 goto nla_put_failure
;
7941 genlmsg_end(msg
, hdr
);
7943 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7944 nl80211_mlme_mcgrp
.id
, gfp
);
7948 genlmsg_cancel(msg
, hdr
);
7952 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
7953 struct net_device
*netdev
,
7954 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
7957 struct sk_buff
*msg
;
7960 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7964 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
7970 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7971 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7972 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
) ||
7974 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
7975 goto nla_put_failure
;
7977 genlmsg_end(msg
, hdr
);
7979 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7980 nl80211_mlme_mcgrp
.id
, gfp
);
7984 genlmsg_cancel(msg
, hdr
);
7988 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
7989 struct net_device
*netdev
, const u8
*addr
,
7990 enum nl80211_key_type key_type
, int key_id
,
7991 const u8
*tsc
, gfp_t gfp
)
7993 struct sk_buff
*msg
;
7996 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8000 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
8006 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8007 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8008 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
8009 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
8011 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
8012 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
8013 goto nla_put_failure
;
8015 genlmsg_end(msg
, hdr
);
8017 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8018 nl80211_mlme_mcgrp
.id
, gfp
);
8022 genlmsg_cancel(msg
, hdr
);
8026 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
8027 struct ieee80211_channel
*channel_before
,
8028 struct ieee80211_channel
*channel_after
)
8030 struct sk_buff
*msg
;
8032 struct nlattr
*nl_freq
;
8034 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
8038 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
8045 * Since we are applying the beacon hint to a wiphy we know its
8046 * wiphy_idx is valid
8048 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
8049 goto nla_put_failure
;
8052 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
8054 goto nla_put_failure
;
8055 if (nl80211_msg_put_channel(msg
, channel_before
))
8056 goto nla_put_failure
;
8057 nla_nest_end(msg
, nl_freq
);
8060 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
8062 goto nla_put_failure
;
8063 if (nl80211_msg_put_channel(msg
, channel_after
))
8064 goto nla_put_failure
;
8065 nla_nest_end(msg
, nl_freq
);
8067 genlmsg_end(msg
, hdr
);
8070 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
8077 genlmsg_cancel(msg
, hdr
);
8081 static void nl80211_send_remain_on_chan_event(
8082 int cmd
, struct cfg80211_registered_device
*rdev
,
8083 struct wireless_dev
*wdev
, u64 cookie
,
8084 struct ieee80211_channel
*chan
,
8085 enum nl80211_channel_type channel_type
,
8086 unsigned int duration
, gfp_t gfp
)
8088 struct sk_buff
*msg
;
8091 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8095 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8101 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8102 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8103 wdev
->netdev
->ifindex
)) ||
8104 nla_put_u32(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
8105 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
8106 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
) ||
8107 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8108 goto nla_put_failure
;
8110 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
8111 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
8112 goto nla_put_failure
;
8114 genlmsg_end(msg
, hdr
);
8116 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8117 nl80211_mlme_mcgrp
.id
, gfp
);
8121 genlmsg_cancel(msg
, hdr
);
8125 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
8126 struct wireless_dev
*wdev
, u64 cookie
,
8127 struct ieee80211_channel
*chan
,
8128 enum nl80211_channel_type channel_type
,
8129 unsigned int duration
, gfp_t gfp
)
8131 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
8132 rdev
, wdev
, cookie
, chan
,
8133 channel_type
, duration
, gfp
);
8136 void nl80211_send_remain_on_channel_cancel(
8137 struct cfg80211_registered_device
*rdev
,
8138 struct wireless_dev
*wdev
,
8139 u64 cookie
, struct ieee80211_channel
*chan
,
8140 enum nl80211_channel_type channel_type
, gfp_t gfp
)
8142 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8143 rdev
, wdev
, cookie
, chan
,
8144 channel_type
, 0, gfp
);
8147 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
8148 struct net_device
*dev
, const u8
*mac_addr
,
8149 struct station_info
*sinfo
, gfp_t gfp
)
8151 struct sk_buff
*msg
;
8153 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8157 if (nl80211_send_station(msg
, 0, 0, 0,
8158 rdev
, dev
, mac_addr
, sinfo
) < 0) {
8163 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8164 nl80211_mlme_mcgrp
.id
, gfp
);
8167 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
8168 struct net_device
*dev
, const u8
*mac_addr
,
8171 struct sk_buff
*msg
;
8174 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8178 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
8184 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8185 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
8186 goto nla_put_failure
;
8188 genlmsg_end(msg
, hdr
);
8190 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8191 nl80211_mlme_mcgrp
.id
, gfp
);
8195 genlmsg_cancel(msg
, hdr
);
8199 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
8200 const u8
*addr
, gfp_t gfp
)
8202 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8203 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8204 struct sk_buff
*msg
;
8207 u32 nlpid
= ACCESS_ONCE(wdev
->ap_unexpected_nlpid
);
8212 msg
= nlmsg_new(100, gfp
);
8216 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8222 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8223 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8224 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8225 goto nla_put_failure
;
8227 err
= genlmsg_end(msg
, hdr
);
8233 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8237 genlmsg_cancel(msg
, hdr
);
8242 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
8244 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
8248 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
8249 const u8
*addr
, gfp_t gfp
)
8251 return __nl80211_unexpected_frame(dev
,
8252 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
8256 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
8257 struct wireless_dev
*wdev
, u32 nlpid
,
8258 int freq
, int sig_dbm
,
8259 const u8
*buf
, size_t len
, gfp_t gfp
)
8261 struct net_device
*netdev
= wdev
->netdev
;
8262 struct sk_buff
*msg
;
8265 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8269 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8275 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8276 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8277 netdev
->ifindex
)) ||
8278 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8280 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8281 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8282 goto nla_put_failure
;
8284 genlmsg_end(msg
, hdr
);
8286 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8289 genlmsg_cancel(msg
, hdr
);
8294 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
8295 struct wireless_dev
*wdev
, u64 cookie
,
8296 const u8
*buf
, size_t len
, bool ack
,
8299 struct net_device
*netdev
= wdev
->netdev
;
8300 struct sk_buff
*msg
;
8303 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8307 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
8313 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8314 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8315 netdev
->ifindex
)) ||
8316 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
8317 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8318 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8319 goto nla_put_failure
;
8321 genlmsg_end(msg
, hdr
);
8323 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
8327 genlmsg_cancel(msg
, hdr
);
8332 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
8333 struct net_device
*netdev
,
8334 enum nl80211_cqm_rssi_threshold_event rssi_event
,
8337 struct sk_buff
*msg
;
8338 struct nlattr
*pinfoattr
;
8341 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8345 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8351 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8352 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8353 goto nla_put_failure
;
8355 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8357 goto nla_put_failure
;
8359 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
8361 goto nla_put_failure
;
8363 nla_nest_end(msg
, pinfoattr
);
8365 genlmsg_end(msg
, hdr
);
8367 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8368 nl80211_mlme_mcgrp
.id
, gfp
);
8372 genlmsg_cancel(msg
, hdr
);
8376 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
8377 struct net_device
*netdev
, const u8
*bssid
,
8378 const u8
*replay_ctr
, gfp_t gfp
)
8380 struct sk_buff
*msg
;
8381 struct nlattr
*rekey_attr
;
8384 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8388 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8394 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8395 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8396 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8397 goto nla_put_failure
;
8399 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8401 goto nla_put_failure
;
8403 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
8404 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
8405 goto nla_put_failure
;
8407 nla_nest_end(msg
, rekey_attr
);
8409 genlmsg_end(msg
, hdr
);
8411 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8412 nl80211_mlme_mcgrp
.id
, gfp
);
8416 genlmsg_cancel(msg
, hdr
);
8420 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
8421 struct net_device
*netdev
, int index
,
8422 const u8
*bssid
, bool preauth
, gfp_t gfp
)
8424 struct sk_buff
*msg
;
8425 struct nlattr
*attr
;
8428 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8432 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
8438 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8439 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8440 goto nla_put_failure
;
8442 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
8444 goto nla_put_failure
;
8446 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
8447 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
8449 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
8450 goto nla_put_failure
;
8452 nla_nest_end(msg
, attr
);
8454 genlmsg_end(msg
, hdr
);
8456 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8457 nl80211_mlme_mcgrp
.id
, gfp
);
8461 genlmsg_cancel(msg
, hdr
);
8465 void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
8466 struct net_device
*netdev
, int freq
,
8467 enum nl80211_channel_type type
, gfp_t gfp
)
8469 struct sk_buff
*msg
;
8472 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8476 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
8482 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8483 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8484 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, type
))
8485 goto nla_put_failure
;
8487 genlmsg_end(msg
, hdr
);
8489 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8490 nl80211_mlme_mcgrp
.id
, gfp
);
8494 genlmsg_cancel(msg
, hdr
);
8499 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
8500 struct net_device
*netdev
, const u8
*peer
,
8501 u32 num_packets
, gfp_t gfp
)
8503 struct sk_buff
*msg
;
8504 struct nlattr
*pinfoattr
;
8507 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8511 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8517 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8518 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8519 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8520 goto nla_put_failure
;
8522 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8524 goto nla_put_failure
;
8526 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
8527 goto nla_put_failure
;
8529 nla_nest_end(msg
, pinfoattr
);
8531 genlmsg_end(msg
, hdr
);
8533 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8534 nl80211_mlme_mcgrp
.id
, gfp
);
8538 genlmsg_cancel(msg
, hdr
);
8542 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
8543 u64 cookie
, bool acked
, gfp_t gfp
)
8545 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8546 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8547 struct sk_buff
*msg
;
8551 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8555 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
8561 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8562 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8563 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8564 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8565 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8566 goto nla_put_failure
;
8568 err
= genlmsg_end(msg
, hdr
);
8574 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8575 nl80211_mlme_mcgrp
.id
, gfp
);
8579 genlmsg_cancel(msg
, hdr
);
8582 EXPORT_SYMBOL(cfg80211_probe_status
);
8584 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
8585 const u8
*frame
, size_t len
,
8586 int freq
, int sig_dbm
, gfp_t gfp
)
8588 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8589 struct sk_buff
*msg
;
8591 u32 nlpid
= ACCESS_ONCE(rdev
->ap_beacons_nlpid
);
8596 msg
= nlmsg_new(len
+ 100, gfp
);
8600 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8606 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8608 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
8610 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8611 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
8612 goto nla_put_failure
;
8614 genlmsg_end(msg
, hdr
);
8616 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8620 genlmsg_cancel(msg
, hdr
);
8623 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
8625 static int nl80211_netlink_notify(struct notifier_block
* nb
,
8626 unsigned long state
,
8629 struct netlink_notify
*notify
= _notify
;
8630 struct cfg80211_registered_device
*rdev
;
8631 struct wireless_dev
*wdev
;
8633 if (state
!= NETLINK_URELEASE
)
8638 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
8639 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
8640 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
8641 if (rdev
->ap_beacons_nlpid
== notify
->pid
)
8642 rdev
->ap_beacons_nlpid
= 0;
8650 static struct notifier_block nl80211_netlink_notifier
= {
8651 .notifier_call
= nl80211_netlink_notify
,
8654 /* initialisation/exit functions */
8656 int nl80211_init(void)
8660 err
= genl_register_family_with_ops(&nl80211_fam
,
8661 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
8665 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
8669 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
8673 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
8677 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
8681 #ifdef CONFIG_NL80211_TESTMODE
8682 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
8687 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
8693 genl_unregister_family(&nl80211_fam
);
8697 void nl80211_exit(void)
8699 netlink_unregister_notifier(&nl80211_netlink_notifier
);
8700 genl_unregister_family(&nl80211_fam
);