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 int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
27 struct genl_info
*info
,
28 struct cfg80211_crypto_settings
*settings
,
31 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
32 struct genl_info
*info
);
33 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
34 struct genl_info
*info
);
36 /* the netlink family */
37 static struct genl_family nl80211_fam
= {
38 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
39 .name
= "nl80211", /* have users key off the name instead */
40 .hdrsize
= 0, /* no private header */
41 .version
= 1, /* no particular meaning now */
42 .maxattr
= NL80211_ATTR_MAX
,
44 .pre_doit
= nl80211_pre_doit
,
45 .post_doit
= nl80211_post_doit
,
48 /* returns ERR_PTR values */
49 static struct wireless_dev
*
50 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
52 struct cfg80211_registered_device
*rdev
;
53 struct wireless_dev
*result
= NULL
;
54 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
55 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
60 assert_cfg80211_lock();
62 if (!have_ifidx
&& !have_wdev_id
)
63 return ERR_PTR(-EINVAL
);
66 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
68 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
69 wiphy_idx
= wdev_id
>> 32;
72 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
73 struct wireless_dev
*wdev
;
75 if (wiphy_net(&rdev
->wiphy
) != netns
)
78 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
81 mutex_lock(&rdev
->devlist_mtx
);
82 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
83 if (have_ifidx
&& wdev
->netdev
&&
84 wdev
->netdev
->ifindex
== ifidx
) {
88 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
93 mutex_unlock(&rdev
->devlist_mtx
);
101 return ERR_PTR(-ENODEV
);
104 static struct cfg80211_registered_device
*
105 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
107 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
108 struct net_device
*netdev
;
110 assert_cfg80211_lock();
112 if (!attrs
[NL80211_ATTR_WIPHY
] &&
113 !attrs
[NL80211_ATTR_IFINDEX
] &&
114 !attrs
[NL80211_ATTR_WDEV
])
115 return ERR_PTR(-EINVAL
);
117 if (attrs
[NL80211_ATTR_WIPHY
])
118 rdev
= cfg80211_rdev_by_wiphy_idx(
119 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
121 if (attrs
[NL80211_ATTR_WDEV
]) {
122 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
123 struct wireless_dev
*wdev
;
126 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
128 /* make sure wdev exists */
129 mutex_lock(&tmp
->devlist_mtx
);
130 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
131 if (wdev
->identifier
!= (u32
)wdev_id
)
136 mutex_unlock(&tmp
->devlist_mtx
);
141 if (rdev
&& tmp
!= rdev
)
142 return ERR_PTR(-EINVAL
);
147 if (attrs
[NL80211_ATTR_IFINDEX
]) {
148 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
149 netdev
= dev_get_by_index(netns
, ifindex
);
151 if (netdev
->ieee80211_ptr
)
153 netdev
->ieee80211_ptr
->wiphy
);
159 /* not wireless device -- return error */
161 return ERR_PTR(-EINVAL
);
163 /* mismatch -- return error */
164 if (rdev
&& tmp
!= rdev
)
165 return ERR_PTR(-EINVAL
);
172 return ERR_PTR(-ENODEV
);
174 if (netns
!= wiphy_net(&rdev
->wiphy
))
175 return ERR_PTR(-ENODEV
);
181 * This function returns a pointer to the driver
182 * that the genl_info item that is passed refers to.
183 * If successful, it returns non-NULL and also locks
184 * the driver's mutex!
186 * This means that you need to call cfg80211_unlock_rdev()
187 * before being allowed to acquire &cfg80211_mutex!
189 * This is necessary because we need to lock the global
190 * mutex to get an item off the list safely, and then
191 * we lock the rdev mutex so it doesn't go away under us.
193 * We don't want to keep cfg80211_mutex locked
194 * for all the time in order to allow requests on
195 * other interfaces to go through at the same time.
197 * The result of this can be a PTR_ERR and hence must
198 * be checked with IS_ERR() for errors.
200 static struct cfg80211_registered_device
*
201 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
203 struct cfg80211_registered_device
*rdev
;
205 mutex_lock(&cfg80211_mutex
);
206 rdev
= __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
208 /* if it is not an error we grab the lock on
209 * it to assure it won't be going away while
210 * we operate on it */
212 mutex_lock(&rdev
->mtx
);
214 mutex_unlock(&cfg80211_mutex
);
219 /* policy for the attributes */
220 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
221 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
222 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
224 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
225 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
226 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
227 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
228 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
229 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
230 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
233 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
235 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
237 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
238 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
240 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
241 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
242 .len
= WLAN_MAX_KEY_LEN
},
243 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
244 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
245 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
246 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
247 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
249 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
250 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
252 .len
= IEEE80211_MAX_DATA_LEN
},
253 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
254 .len
= IEEE80211_MAX_DATA_LEN
},
255 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
256 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
257 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
258 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
259 .len
= NL80211_MAX_SUPP_RATES
},
260 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
261 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
262 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
263 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
264 .len
= IEEE80211_MAX_MESH_ID_LEN
},
265 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
267 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
268 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
270 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
271 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
272 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
273 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
274 .len
= NL80211_MAX_SUPP_RATES
},
275 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
277 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
278 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
280 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
282 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
283 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
284 .len
= IEEE80211_MAX_DATA_LEN
},
285 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
286 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
288 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
289 .len
= IEEE80211_MAX_SSID_LEN
},
290 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
291 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
292 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
293 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
294 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
295 [NL80211_ATTR_STA_FLAGS2
] = {
296 .len
= sizeof(struct nl80211_sta_flag_update
),
298 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
299 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
300 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
302 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
303 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
304 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
305 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
306 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
307 .len
= WLAN_PMKID_LEN
},
308 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
309 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
310 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
311 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
312 .len
= IEEE80211_MAX_DATA_LEN
},
313 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
314 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
315 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
316 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
317 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
318 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
319 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
320 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
321 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
323 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
324 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
325 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
326 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
327 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
328 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
329 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
330 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
331 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
332 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
333 .len
= IEEE80211_MAX_DATA_LEN
},
334 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
335 .len
= IEEE80211_MAX_DATA_LEN
},
336 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
337 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
338 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
339 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
340 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
341 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
342 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
343 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
346 .len
= IEEE80211_MAX_DATA_LEN
},
347 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
348 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
349 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
350 .len
= NL80211_HT_CAPABILITY_LEN
352 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
353 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
354 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
355 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
356 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
357 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
358 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
361 /* policy for the key attributes */
362 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
363 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
364 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
365 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
366 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
367 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
368 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
369 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
370 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
373 /* policy for the key default flags */
374 static const struct nla_policy
375 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
376 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
377 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
380 /* policy for WoWLAN attributes */
381 static const struct nla_policy
382 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
383 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
384 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
385 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
386 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
387 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
388 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
389 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
390 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
393 /* policy for GTK rekey offload attributes */
394 static const struct nla_policy
395 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
396 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
397 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
398 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
401 static const struct nla_policy
402 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
403 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
404 .len
= IEEE80211_MAX_SSID_LEN
},
405 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
408 /* ifidx get helper */
409 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
413 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
414 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
419 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
422 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
428 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
429 struct netlink_callback
*cb
,
430 struct cfg80211_registered_device
**rdev
,
431 struct net_device
**dev
)
433 int ifidx
= cb
->args
[0];
437 ifidx
= nl80211_get_ifidx(cb
);
445 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
451 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
453 err
= PTR_ERR(*rdev
);
463 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
465 cfg80211_unlock_rdev(rdev
);
470 static bool is_valid_ie_attr(const struct nlattr
*attr
)
478 pos
= nla_data(attr
);
499 /* message building helper */
500 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
503 /* since there is no private header just add the generic one */
504 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
507 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
508 struct ieee80211_channel
*chan
)
510 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
512 goto nla_put_failure
;
514 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
515 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
516 goto nla_put_failure
;
517 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
518 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
519 goto nla_put_failure
;
520 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
521 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
522 goto nla_put_failure
;
523 if ((chan
->flags
& IEEE80211_CHAN_RADAR
) &&
524 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
525 goto nla_put_failure
;
527 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
528 DBM_TO_MBM(chan
->max_power
)))
529 goto nla_put_failure
;
537 /* netlink command implementations */
544 bool def_uni
, def_multi
;
547 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
549 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
550 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
555 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
556 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
565 if (tb
[NL80211_KEY_IDX
])
566 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
568 if (tb
[NL80211_KEY_DATA
]) {
569 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
570 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
573 if (tb
[NL80211_KEY_SEQ
]) {
574 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
575 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
578 if (tb
[NL80211_KEY_CIPHER
])
579 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
581 if (tb
[NL80211_KEY_TYPE
]) {
582 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
583 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
587 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
588 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
589 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
590 tb
[NL80211_KEY_DEFAULT_TYPES
],
591 nl80211_key_default_policy
);
595 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
596 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
602 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
604 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
605 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
606 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
609 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
610 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
611 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
614 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
615 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
617 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
618 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
620 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
621 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
630 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
631 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
632 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
636 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
637 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
638 int err
= nla_parse_nested(
639 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
640 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
641 nl80211_key_default_policy
);
645 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
646 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
652 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
656 memset(k
, 0, sizeof(*k
));
660 if (info
->attrs
[NL80211_ATTR_KEY
])
661 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
663 err
= nl80211_parse_key_old(info
, k
);
668 if (k
->def
&& k
->defmgmt
)
672 if (k
->def_uni
|| !k
->def_multi
)
678 if (k
->idx
< 4 || k
->idx
> 5)
681 if (k
->idx
< 0 || k
->idx
> 3)
684 if (k
->idx
< 0 || k
->idx
> 5)
692 static struct cfg80211_cached_keys
*
693 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
696 struct key_parse parse
;
698 struct cfg80211_cached_keys
*result
;
699 int rem
, err
, def
= 0;
701 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
703 return ERR_PTR(-ENOMEM
);
706 result
->defmgmt
= -1;
708 nla_for_each_nested(key
, keys
, rem
) {
709 memset(&parse
, 0, sizeof(parse
));
712 err
= nl80211_parse_key_new(key
, &parse
);
718 if (parse
.idx
< 0 || parse
.idx
> 4)
724 result
->def
= parse
.idx
;
725 if (!parse
.def_uni
|| !parse
.def_multi
)
727 } else if (parse
.defmgmt
)
729 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
730 parse
.idx
, false, NULL
);
733 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
734 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
735 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
736 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
745 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
747 ASSERT_WDEV_LOCK(wdev
);
749 switch (wdev
->iftype
) {
750 case NL80211_IFTYPE_AP
:
751 case NL80211_IFTYPE_AP_VLAN
:
752 case NL80211_IFTYPE_P2P_GO
:
753 case NL80211_IFTYPE_MESH_POINT
:
755 case NL80211_IFTYPE_ADHOC
:
756 if (!wdev
->current_bss
)
759 case NL80211_IFTYPE_STATION
:
760 case NL80211_IFTYPE_P2P_CLIENT
:
761 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
771 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
773 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
777 goto nla_put_failure
;
781 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
782 goto nla_put_failure
;
787 nla_nest_end(msg
, nl_modes
);
794 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
797 struct nlattr
*nl_combis
;
800 nl_combis
= nla_nest_start(msg
,
801 NL80211_ATTR_INTERFACE_COMBINATIONS
);
803 goto nla_put_failure
;
805 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
806 const struct ieee80211_iface_combination
*c
;
807 struct nlattr
*nl_combi
, *nl_limits
;
809 c
= &wiphy
->iface_combinations
[i
];
811 nl_combi
= nla_nest_start(msg
, i
+ 1);
813 goto nla_put_failure
;
815 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
817 goto nla_put_failure
;
819 for (j
= 0; j
< c
->n_limits
; j
++) {
820 struct nlattr
*nl_limit
;
822 nl_limit
= nla_nest_start(msg
, j
+ 1);
824 goto nla_put_failure
;
825 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
827 goto nla_put_failure
;
828 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
830 goto nla_put_failure
;
831 nla_nest_end(msg
, nl_limit
);
834 nla_nest_end(msg
, nl_limits
);
836 if (c
->beacon_int_infra_match
&&
837 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
838 goto nla_put_failure
;
839 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
840 c
->num_different_channels
) ||
841 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
843 goto nla_put_failure
;
845 nla_nest_end(msg
, nl_combi
);
848 nla_nest_end(msg
, nl_combis
);
855 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
856 struct cfg80211_registered_device
*dev
)
859 struct nlattr
*nl_bands
, *nl_band
;
860 struct nlattr
*nl_freqs
, *nl_freq
;
861 struct nlattr
*nl_rates
, *nl_rate
;
862 struct nlattr
*nl_cmds
;
863 enum ieee80211_band band
;
864 struct ieee80211_channel
*chan
;
865 struct ieee80211_rate
*rate
;
867 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
868 dev
->wiphy
.mgmt_stypes
;
870 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
874 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
875 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
)) ||
876 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
877 cfg80211_rdev_list_generation
) ||
878 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
879 dev
->wiphy
.retry_short
) ||
880 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
881 dev
->wiphy
.retry_long
) ||
882 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
883 dev
->wiphy
.frag_threshold
) ||
884 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
885 dev
->wiphy
.rts_threshold
) ||
886 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
887 dev
->wiphy
.coverage_class
) ||
888 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
889 dev
->wiphy
.max_scan_ssids
) ||
890 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
891 dev
->wiphy
.max_sched_scan_ssids
) ||
892 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
893 dev
->wiphy
.max_scan_ie_len
) ||
894 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
895 dev
->wiphy
.max_sched_scan_ie_len
) ||
896 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
897 dev
->wiphy
.max_match_sets
))
898 goto nla_put_failure
;
900 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
901 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
902 goto nla_put_failure
;
903 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
904 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
905 goto nla_put_failure
;
906 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
907 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
908 goto nla_put_failure
;
909 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
910 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
911 goto nla_put_failure
;
912 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
913 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
914 goto nla_put_failure
;
915 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
916 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
917 goto nla_put_failure
;
919 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
920 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
921 dev
->wiphy
.cipher_suites
))
922 goto nla_put_failure
;
924 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
925 dev
->wiphy
.max_num_pmkids
))
926 goto nla_put_failure
;
928 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
929 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
930 goto nla_put_failure
;
932 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
933 dev
->wiphy
.available_antennas_tx
) ||
934 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
935 dev
->wiphy
.available_antennas_rx
))
936 goto nla_put_failure
;
938 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
939 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
940 dev
->wiphy
.probe_resp_offload
))
941 goto nla_put_failure
;
943 if ((dev
->wiphy
.available_antennas_tx
||
944 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
945 u32 tx_ant
= 0, rx_ant
= 0;
947 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
949 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
,
951 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
,
953 goto nla_put_failure
;
957 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
958 dev
->wiphy
.interface_modes
))
959 goto nla_put_failure
;
961 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
963 goto nla_put_failure
;
965 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
966 if (!dev
->wiphy
.bands
[band
])
969 nl_band
= nla_nest_start(msg
, band
);
971 goto nla_put_failure
;
974 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
&&
975 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
976 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
977 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
) ||
978 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
979 dev
->wiphy
.bands
[band
]->ht_cap
.cap
) ||
980 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
981 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
) ||
982 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
983 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
)))
984 goto nla_put_failure
;
987 if (dev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
&&
988 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
989 sizeof(dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
),
990 &dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
) ||
991 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
992 dev
->wiphy
.bands
[band
]->vht_cap
.cap
)))
993 goto nla_put_failure
;
995 /* add frequencies */
996 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
998 goto nla_put_failure
;
1000 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
1001 nl_freq
= nla_nest_start(msg
, i
);
1003 goto nla_put_failure
;
1005 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
1007 if (nl80211_msg_put_channel(msg
, chan
))
1008 goto nla_put_failure
;
1010 nla_nest_end(msg
, nl_freq
);
1013 nla_nest_end(msg
, nl_freqs
);
1016 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1018 goto nla_put_failure
;
1020 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
1021 nl_rate
= nla_nest_start(msg
, i
);
1023 goto nla_put_failure
;
1025 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
1026 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1028 goto nla_put_failure
;
1029 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1031 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1032 goto nla_put_failure
;
1034 nla_nest_end(msg
, nl_rate
);
1037 nla_nest_end(msg
, nl_rates
);
1039 nla_nest_end(msg
, nl_band
);
1041 nla_nest_end(msg
, nl_bands
);
1043 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1045 goto nla_put_failure
;
1048 #define CMD(op, n) \
1050 if (dev->ops->op) { \
1052 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1053 goto nla_put_failure; \
1057 CMD(add_virtual_intf
, NEW_INTERFACE
);
1058 CMD(change_virtual_intf
, SET_INTERFACE
);
1059 CMD(add_key
, NEW_KEY
);
1060 CMD(start_ap
, START_AP
);
1061 CMD(add_station
, NEW_STATION
);
1062 CMD(add_mpath
, NEW_MPATH
);
1063 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1064 CMD(change_bss
, SET_BSS
);
1065 CMD(auth
, AUTHENTICATE
);
1066 CMD(assoc
, ASSOCIATE
);
1067 CMD(deauth
, DEAUTHENTICATE
);
1068 CMD(disassoc
, DISASSOCIATE
);
1069 CMD(join_ibss
, JOIN_IBSS
);
1070 CMD(join_mesh
, JOIN_MESH
);
1071 CMD(set_pmksa
, SET_PMKSA
);
1072 CMD(del_pmksa
, DEL_PMKSA
);
1073 CMD(flush_pmksa
, FLUSH_PMKSA
);
1074 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1075 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1076 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1077 CMD(mgmt_tx
, FRAME
);
1078 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1079 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1081 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1082 goto nla_put_failure
;
1084 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1085 dev
->ops
->join_mesh
) {
1087 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1088 goto nla_put_failure
;
1090 CMD(set_wds_peer
, SET_WDS_PEER
);
1091 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1092 CMD(tdls_mgmt
, TDLS_MGMT
);
1093 CMD(tdls_oper
, TDLS_OPER
);
1095 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1096 CMD(sched_scan_start
, START_SCHED_SCAN
);
1097 CMD(probe_client
, PROBE_CLIENT
);
1098 CMD(set_noack_map
, SET_NOACK_MAP
);
1099 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1101 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1102 goto nla_put_failure
;
1104 CMD(start_p2p_device
, START_P2P_DEVICE
);
1106 #ifdef CONFIG_NL80211_TESTMODE
1107 CMD(testmode_cmd
, TESTMODE
);
1112 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1114 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1115 goto nla_put_failure
;
1118 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1120 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1121 goto nla_put_failure
;
1124 nla_nest_end(msg
, nl_cmds
);
1126 if (dev
->ops
->remain_on_channel
&&
1127 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1128 nla_put_u32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1129 dev
->wiphy
.max_remain_on_channel_duration
))
1130 goto nla_put_failure
;
1132 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1133 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1134 goto nla_put_failure
;
1138 struct nlattr
*nl_ftypes
, *nl_ifs
;
1139 enum nl80211_iftype ift
;
1141 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1143 goto nla_put_failure
;
1145 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1146 nl_ftypes
= nla_nest_start(msg
, ift
);
1148 goto nla_put_failure
;
1150 stypes
= mgmt_stypes
[ift
].tx
;
1153 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1154 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1155 goto nla_put_failure
;
1159 nla_nest_end(msg
, nl_ftypes
);
1162 nla_nest_end(msg
, nl_ifs
);
1164 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1166 goto nla_put_failure
;
1168 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1169 nl_ftypes
= nla_nest_start(msg
, ift
);
1171 goto nla_put_failure
;
1173 stypes
= mgmt_stypes
[ift
].rx
;
1176 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1177 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1178 goto nla_put_failure
;
1182 nla_nest_end(msg
, nl_ftypes
);
1184 nla_nest_end(msg
, nl_ifs
);
1188 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
1189 struct nlattr
*nl_wowlan
;
1191 nl_wowlan
= nla_nest_start(msg
,
1192 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1194 goto nla_put_failure
;
1196 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1197 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1198 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1199 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1200 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1201 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1202 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1203 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1204 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1205 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1206 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1207 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1208 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1209 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1210 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1211 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1212 goto nla_put_failure
;
1213 if (dev
->wiphy
.wowlan
.n_patterns
) {
1214 struct nl80211_wowlan_pattern_support pat
= {
1215 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1217 dev
->wiphy
.wowlan
.pattern_min_len
,
1219 dev
->wiphy
.wowlan
.pattern_max_len
,
1221 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1223 goto nla_put_failure
;
1226 nla_nest_end(msg
, nl_wowlan
);
1230 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1231 dev
->wiphy
.software_iftypes
))
1232 goto nla_put_failure
;
1234 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1235 goto nla_put_failure
;
1237 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1238 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1239 dev
->wiphy
.ap_sme_capa
))
1240 goto nla_put_failure
;
1242 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
,
1243 dev
->wiphy
.features
))
1244 goto nla_put_failure
;
1246 if (dev
->wiphy
.ht_capa_mod_mask
&&
1247 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1248 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1249 dev
->wiphy
.ht_capa_mod_mask
))
1250 goto nla_put_failure
;
1252 return genlmsg_end(msg
, hdr
);
1255 genlmsg_cancel(msg
, hdr
);
1259 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1262 int start
= cb
->args
[0];
1263 struct cfg80211_registered_device
*dev
;
1265 mutex_lock(&cfg80211_mutex
);
1266 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1267 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1271 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).portid
,
1272 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1278 mutex_unlock(&cfg80211_mutex
);
1285 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1287 struct sk_buff
*msg
;
1288 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1290 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1294 if (nl80211_send_wiphy(msg
, info
->snd_portid
, info
->snd_seq
, 0, dev
) < 0) {
1299 return genlmsg_reply(msg
, info
);
1302 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1303 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1304 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1305 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1306 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1307 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1310 static int parse_txq_params(struct nlattr
*tb
[],
1311 struct ieee80211_txq_params
*txq_params
)
1313 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1314 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1315 !tb
[NL80211_TXQ_ATTR_AIFS
])
1318 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1319 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1320 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1321 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1322 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1324 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1330 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1333 * You can only set the channel explicitly for WDS interfaces,
1334 * all others have their channel managed via their respective
1335 * "establish a connection" command (connect, join, ...)
1337 * For AP/GO and mesh mode, the channel can be set with the
1338 * channel userspace API, but is only stored and passed to the
1339 * low-level driver when the AP starts or the mesh is joined.
1340 * This is for backward compatibility, userspace can also give
1341 * the channel in the start-ap or join-mesh commands instead.
1343 * Monitors are special as they are normally slaved to
1344 * whatever else is going on, so they have their own special
1345 * operation to set the monitor channel if possible.
1348 wdev
->iftype
== NL80211_IFTYPE_AP
||
1349 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1350 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1351 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1354 static bool nl80211_valid_channel_type(struct genl_info
*info
,
1355 enum nl80211_channel_type
*channel_type
)
1357 enum nl80211_channel_type tmp
;
1359 if (!info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1362 tmp
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1363 if (tmp
!= NL80211_CHAN_NO_HT
&&
1364 tmp
!= NL80211_CHAN_HT20
&&
1365 tmp
!= NL80211_CHAN_HT40PLUS
&&
1366 tmp
!= NL80211_CHAN_HT40MINUS
)
1370 *channel_type
= tmp
;
1375 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1376 struct wireless_dev
*wdev
,
1377 struct genl_info
*info
)
1379 struct ieee80211_channel
*channel
;
1380 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1383 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1386 iftype
= wdev
->iftype
;
1388 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1391 if (!nl80211_can_set_dev_channel(wdev
))
1394 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
1395 !nl80211_valid_channel_type(info
, &channel_type
))
1398 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1400 mutex_lock(&rdev
->devlist_mtx
);
1402 case NL80211_IFTYPE_AP
:
1403 case NL80211_IFTYPE_P2P_GO
:
1404 if (wdev
->beacon_interval
) {
1408 channel
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
1409 if (!channel
|| !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
,
1415 wdev
->preset_chan
= channel
;
1416 wdev
->preset_chantype
= channel_type
;
1419 case NL80211_IFTYPE_MESH_POINT
:
1420 result
= cfg80211_set_mesh_freq(rdev
, wdev
, freq
, channel_type
);
1422 case NL80211_IFTYPE_MONITOR
:
1423 result
= cfg80211_set_monitor_channel(rdev
, freq
, channel_type
);
1428 mutex_unlock(&rdev
->devlist_mtx
);
1433 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1435 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1436 struct net_device
*netdev
= info
->user_ptr
[1];
1438 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1441 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1443 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1444 struct net_device
*dev
= info
->user_ptr
[1];
1445 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1448 if (!info
->attrs
[NL80211_ATTR_MAC
])
1451 if (netif_running(dev
))
1454 if (!rdev
->ops
->set_wds_peer
)
1457 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1460 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1461 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1465 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1467 struct cfg80211_registered_device
*rdev
;
1468 struct net_device
*netdev
= NULL
;
1469 struct wireless_dev
*wdev
;
1470 int result
= 0, rem_txq_params
= 0;
1471 struct nlattr
*nl_txq_params
;
1473 u8 retry_short
= 0, retry_long
= 0;
1474 u32 frag_threshold
= 0, rts_threshold
= 0;
1475 u8 coverage_class
= 0;
1478 * Try to find the wiphy and netdev. Normally this
1479 * function shouldn't need the netdev, but this is
1480 * done for backward compatibility -- previously
1481 * setting the channel was done per wiphy, but now
1482 * it is per netdev. Previous userland like hostapd
1483 * also passed a netdev to set_wiphy, so that it is
1484 * possible to let that go to the right netdev!
1486 mutex_lock(&cfg80211_mutex
);
1488 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1489 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1491 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1492 if (netdev
&& netdev
->ieee80211_ptr
) {
1493 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1494 mutex_lock(&rdev
->mtx
);
1500 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1503 mutex_unlock(&cfg80211_mutex
);
1504 return PTR_ERR(rdev
);
1510 mutex_lock(&rdev
->mtx
);
1511 } else if (nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1512 wdev
= netdev
->ieee80211_ptr
;
1517 * end workaround code, by now the rdev is available
1518 * and locked, and wdev may or may not be NULL.
1521 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1522 result
= cfg80211_dev_rename(
1523 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1525 mutex_unlock(&cfg80211_mutex
);
1530 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1531 struct ieee80211_txq_params txq_params
;
1532 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1534 if (!rdev
->ops
->set_txq_params
) {
1535 result
= -EOPNOTSUPP
;
1544 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1545 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1550 if (!netif_running(netdev
)) {
1555 nla_for_each_nested(nl_txq_params
,
1556 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1558 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1559 nla_data(nl_txq_params
),
1560 nla_len(nl_txq_params
),
1562 result
= parse_txq_params(tb
, &txq_params
);
1566 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1574 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1575 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1580 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1581 enum nl80211_tx_power_setting type
;
1584 if (!rdev
->ops
->set_tx_power
) {
1585 result
= -EOPNOTSUPP
;
1589 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1590 type
= nla_get_u32(info
->attrs
[idx
]);
1592 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1593 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1598 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1599 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1600 mbm
= nla_get_u32(info
->attrs
[idx
]);
1603 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1608 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1609 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1611 if ((!rdev
->wiphy
.available_antennas_tx
&&
1612 !rdev
->wiphy
.available_antennas_rx
) ||
1613 !rdev
->ops
->set_antenna
) {
1614 result
= -EOPNOTSUPP
;
1618 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1619 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1621 /* reject antenna configurations which don't match the
1622 * available antenna masks, except for the "all" mask */
1623 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1624 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1629 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1630 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1632 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1639 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1640 retry_short
= nla_get_u8(
1641 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1642 if (retry_short
== 0) {
1646 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1649 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1650 retry_long
= nla_get_u8(
1651 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1652 if (retry_long
== 0) {
1656 changed
|= WIPHY_PARAM_RETRY_LONG
;
1659 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1660 frag_threshold
= nla_get_u32(
1661 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1662 if (frag_threshold
< 256) {
1666 if (frag_threshold
!= (u32
) -1) {
1668 * Fragments (apart from the last one) are required to
1669 * have even length. Make the fragmentation code
1670 * simpler by stripping LSB should someone try to use
1671 * odd threshold value.
1673 frag_threshold
&= ~0x1;
1675 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1678 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1679 rts_threshold
= nla_get_u32(
1680 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1681 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1684 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1685 coverage_class
= nla_get_u8(
1686 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1687 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1691 u8 old_retry_short
, old_retry_long
;
1692 u32 old_frag_threshold
, old_rts_threshold
;
1693 u8 old_coverage_class
;
1695 if (!rdev
->ops
->set_wiphy_params
) {
1696 result
= -EOPNOTSUPP
;
1700 old_retry_short
= rdev
->wiphy
.retry_short
;
1701 old_retry_long
= rdev
->wiphy
.retry_long
;
1702 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1703 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1704 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1706 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1707 rdev
->wiphy
.retry_short
= retry_short
;
1708 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1709 rdev
->wiphy
.retry_long
= retry_long
;
1710 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1711 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1712 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1713 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1714 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1715 rdev
->wiphy
.coverage_class
= coverage_class
;
1717 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1719 rdev
->wiphy
.retry_short
= old_retry_short
;
1720 rdev
->wiphy
.retry_long
= old_retry_long
;
1721 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1722 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1723 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1728 mutex_unlock(&rdev
->mtx
);
1734 static inline u64
wdev_id(struct wireless_dev
*wdev
)
1736 return (u64
)wdev
->identifier
|
1737 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
1740 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
1741 struct cfg80211_registered_device
*rdev
,
1742 struct wireless_dev
*wdev
)
1744 struct net_device
*dev
= wdev
->netdev
;
1747 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1752 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
1753 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
1754 goto nla_put_failure
;
1756 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1757 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
1758 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
1759 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
1760 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1761 rdev
->devlist_generation
^
1762 (cfg80211_rdev_list_generation
<< 2)))
1763 goto nla_put_failure
;
1765 if (rdev
->ops
->get_channel
) {
1766 struct ieee80211_channel
*chan
;
1767 enum nl80211_channel_type channel_type
;
1769 chan
= rdev
->ops
->get_channel(&rdev
->wiphy
, wdev
,
1772 (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
1773 chan
->center_freq
) ||
1774 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
1776 goto nla_put_failure
;
1779 return genlmsg_end(msg
, hdr
);
1782 genlmsg_cancel(msg
, hdr
);
1786 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1790 int wp_start
= cb
->args
[0];
1791 int if_start
= cb
->args
[1];
1792 struct cfg80211_registered_device
*rdev
;
1793 struct wireless_dev
*wdev
;
1795 mutex_lock(&cfg80211_mutex
);
1796 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1797 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1799 if (wp_idx
< wp_start
) {
1805 mutex_lock(&rdev
->devlist_mtx
);
1806 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
1807 if (if_idx
< if_start
) {
1811 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
1812 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1814 mutex_unlock(&rdev
->devlist_mtx
);
1819 mutex_unlock(&rdev
->devlist_mtx
);
1824 mutex_unlock(&cfg80211_mutex
);
1826 cb
->args
[0] = wp_idx
;
1827 cb
->args
[1] = if_idx
;
1832 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1834 struct sk_buff
*msg
;
1835 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1836 struct wireless_dev
*wdev
= info
->user_ptr
[1];
1838 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1842 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
1848 return genlmsg_reply(msg
, info
);
1851 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1852 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1853 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1854 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1855 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1856 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1859 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1861 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1869 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1870 nla
, mntr_flags_policy
))
1873 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1875 *mntrflags
|= (1<<flag
);
1880 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1881 struct net_device
*netdev
, u8 use_4addr
,
1882 enum nl80211_iftype iftype
)
1885 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1891 case NL80211_IFTYPE_AP_VLAN
:
1892 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1895 case NL80211_IFTYPE_STATION
:
1896 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1906 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1908 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1909 struct vif_params params
;
1911 enum nl80211_iftype otype
, ntype
;
1912 struct net_device
*dev
= info
->user_ptr
[1];
1913 u32 _flags
, *flags
= NULL
;
1914 bool change
= false;
1916 memset(¶ms
, 0, sizeof(params
));
1918 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1920 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1921 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1924 if (ntype
> NL80211_IFTYPE_MAX
)
1928 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1929 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1931 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1933 if (netif_running(dev
))
1937 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1938 IEEE80211_MAX_MESH_ID_LEN
);
1939 wdev
->mesh_id_up_len
=
1940 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1941 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1942 wdev
->mesh_id_up_len
);
1946 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1947 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1949 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1953 params
.use_4addr
= -1;
1956 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1957 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1959 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1969 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1973 if (!err
&& params
.use_4addr
!= -1)
1974 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1979 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1981 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1982 struct vif_params params
;
1983 struct wireless_dev
*wdev
;
1984 struct sk_buff
*msg
;
1986 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1989 memset(¶ms
, 0, sizeof(params
));
1991 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1994 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1995 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1996 if (type
> NL80211_IFTYPE_MAX
)
2000 if (!rdev
->ops
->add_virtual_intf
||
2001 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2004 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2005 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2006 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2011 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2015 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2016 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2018 wdev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
2019 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2020 type
, err
? NULL
: &flags
, ¶ms
);
2023 return PTR_ERR(wdev
);
2027 case NL80211_IFTYPE_MESH_POINT
:
2028 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2031 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2032 IEEE80211_MAX_MESH_ID_LEN
);
2033 wdev
->mesh_id_up_len
=
2034 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2035 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2036 wdev
->mesh_id_up_len
);
2039 case NL80211_IFTYPE_P2P_DEVICE
:
2041 * P2P Device doesn't have a netdev, so doesn't go
2042 * through the netdev notifier and must be added here
2044 mutex_init(&wdev
->mtx
);
2045 INIT_LIST_HEAD(&wdev
->event_list
);
2046 spin_lock_init(&wdev
->event_lock
);
2047 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2048 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2050 mutex_lock(&rdev
->devlist_mtx
);
2051 wdev
->identifier
= ++rdev
->wdev_id
;
2052 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2053 rdev
->devlist_generation
++;
2054 mutex_unlock(&rdev
->devlist_mtx
);
2060 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2066 return genlmsg_reply(msg
, info
);
2069 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2071 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2072 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2074 if (!rdev
->ops
->del_virtual_intf
)
2078 * If we remove a wireless device without a netdev then clear
2079 * user_ptr[1] so that nl80211_post_doit won't dereference it
2080 * to check if it needs to do dev_put(). Otherwise it crashes
2081 * since the wdev has been freed, unlike with a netdev where
2082 * we need the dev_put() for the netdev to really be freed.
2085 info
->user_ptr
[1] = NULL
;
2087 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, wdev
);
2090 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2092 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2093 struct net_device
*dev
= info
->user_ptr
[1];
2096 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2099 if (!rdev
->ops
->set_noack_map
)
2102 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2104 return rdev
->ops
->set_noack_map(&rdev
->wiphy
, dev
, noack_map
);
2107 struct get_key_cookie
{
2108 struct sk_buff
*msg
;
2113 static void get_key_callback(void *c
, struct key_params
*params
)
2116 struct get_key_cookie
*cookie
= c
;
2119 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2120 params
->key_len
, params
->key
)) ||
2122 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2123 params
->seq_len
, params
->seq
)) ||
2125 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2127 goto nla_put_failure
;
2129 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2131 goto nla_put_failure
;
2134 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2135 params
->key_len
, params
->key
)) ||
2137 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2138 params
->seq_len
, params
->seq
)) ||
2140 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2142 goto nla_put_failure
;
2144 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2145 goto nla_put_failure
;
2147 nla_nest_end(cookie
->msg
, key
);
2154 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2156 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2158 struct net_device
*dev
= info
->user_ptr
[1];
2160 const u8
*mac_addr
= NULL
;
2162 struct get_key_cookie cookie
= {
2166 struct sk_buff
*msg
;
2168 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2169 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2174 if (info
->attrs
[NL80211_ATTR_MAC
])
2175 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2177 pairwise
= !!mac_addr
;
2178 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2179 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2180 if (kt
>= NUM_NL80211_KEYTYPES
)
2182 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2183 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2185 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2188 if (!rdev
->ops
->get_key
)
2191 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2195 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2196 NL80211_CMD_NEW_KEY
);
2198 return PTR_ERR(hdr
);
2201 cookie
.idx
= key_idx
;
2203 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2204 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2205 goto nla_put_failure
;
2207 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2208 goto nla_put_failure
;
2210 if (pairwise
&& mac_addr
&&
2211 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2214 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
2215 mac_addr
, &cookie
, get_key_callback
);
2221 goto nla_put_failure
;
2223 genlmsg_end(msg
, hdr
);
2224 return genlmsg_reply(msg
, info
);
2233 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2235 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2236 struct key_parse key
;
2238 struct net_device
*dev
= info
->user_ptr
[1];
2240 err
= nl80211_parse_key(info
, &key
);
2247 /* only support setting default key */
2248 if (!key
.def
&& !key
.defmgmt
)
2251 wdev_lock(dev
->ieee80211_ptr
);
2254 if (!rdev
->ops
->set_default_key
) {
2259 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2263 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
2264 key
.def_uni
, key
.def_multi
);
2269 #ifdef CONFIG_CFG80211_WEXT
2270 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2273 if (key
.def_uni
|| !key
.def_multi
) {
2278 if (!rdev
->ops
->set_default_mgmt_key
) {
2283 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2287 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
2292 #ifdef CONFIG_CFG80211_WEXT
2293 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2298 wdev_unlock(dev
->ieee80211_ptr
);
2303 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2305 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2307 struct net_device
*dev
= info
->user_ptr
[1];
2308 struct key_parse key
;
2309 const u8
*mac_addr
= NULL
;
2311 err
= nl80211_parse_key(info
, &key
);
2318 if (info
->attrs
[NL80211_ATTR_MAC
])
2319 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2321 if (key
.type
== -1) {
2323 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2325 key
.type
= NL80211_KEYTYPE_GROUP
;
2329 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2330 key
.type
!= NL80211_KEYTYPE_GROUP
)
2333 if (!rdev
->ops
->add_key
)
2336 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2337 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2341 wdev_lock(dev
->ieee80211_ptr
);
2342 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2344 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
2345 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2347 wdev_unlock(dev
->ieee80211_ptr
);
2352 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2354 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2356 struct net_device
*dev
= info
->user_ptr
[1];
2357 u8
*mac_addr
= NULL
;
2358 struct key_parse key
;
2360 err
= nl80211_parse_key(info
, &key
);
2364 if (info
->attrs
[NL80211_ATTR_MAC
])
2365 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2367 if (key
.type
== -1) {
2369 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2371 key
.type
= NL80211_KEYTYPE_GROUP
;
2375 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2376 key
.type
!= NL80211_KEYTYPE_GROUP
)
2379 if (!rdev
->ops
->del_key
)
2382 wdev_lock(dev
->ieee80211_ptr
);
2383 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2385 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2386 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2390 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
2391 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2394 #ifdef CONFIG_CFG80211_WEXT
2396 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2397 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2398 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2399 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2402 wdev_unlock(dev
->ieee80211_ptr
);
2407 static int nl80211_parse_beacon(struct genl_info
*info
,
2408 struct cfg80211_beacon_data
*bcn
)
2410 bool haveinfo
= false;
2412 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2413 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2414 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2415 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2418 memset(bcn
, 0, sizeof(*bcn
));
2420 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2421 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2422 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2428 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2429 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2431 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2438 if (info
->attrs
[NL80211_ATTR_IE
]) {
2439 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2440 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2443 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2444 bcn
->proberesp_ies
=
2445 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2446 bcn
->proberesp_ies_len
=
2447 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2450 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2451 bcn
->assocresp_ies
=
2452 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2453 bcn
->assocresp_ies_len
=
2454 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2457 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2459 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2460 bcn
->probe_resp_len
=
2461 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2467 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2468 struct cfg80211_ap_settings
*params
)
2470 struct wireless_dev
*wdev
;
2473 mutex_lock(&rdev
->devlist_mtx
);
2475 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2476 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2477 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2480 if (!wdev
->preset_chan
)
2483 params
->channel
= wdev
->preset_chan
;
2484 params
->channel_type
= wdev
->preset_chantype
;
2489 mutex_unlock(&rdev
->devlist_mtx
);
2494 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
2495 enum nl80211_auth_type auth_type
,
2496 enum nl80211_commands cmd
)
2498 if (auth_type
> NL80211_AUTHTYPE_MAX
)
2502 case NL80211_CMD_AUTHENTICATE
:
2503 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
2504 auth_type
== NL80211_AUTHTYPE_SAE
)
2507 case NL80211_CMD_CONNECT
:
2508 case NL80211_CMD_START_AP
:
2509 /* SAE not supported yet */
2510 if (auth_type
== NL80211_AUTHTYPE_SAE
)
2518 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2520 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2521 struct net_device
*dev
= info
->user_ptr
[1];
2522 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2523 struct cfg80211_ap_settings params
;
2526 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2527 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2530 if (!rdev
->ops
->start_ap
)
2533 if (wdev
->beacon_interval
)
2536 memset(¶ms
, 0, sizeof(params
));
2538 /* these are required for START_AP */
2539 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2540 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2541 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2544 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
2548 params
.beacon_interval
=
2549 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2550 params
.dtim_period
=
2551 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2553 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
2558 * In theory, some of these attributes should be required here
2559 * but since they were not used when the command was originally
2560 * added, keep them optional for old user space programs to let
2561 * them continue to work with drivers that do not need the
2562 * additional information -- drivers must check!
2564 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2565 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2567 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2568 if (params
.ssid_len
== 0 ||
2569 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2573 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2574 params
.hidden_ssid
= nla_get_u32(
2575 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2576 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2577 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
2578 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2582 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2584 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2585 params
.auth_type
= nla_get_u32(
2586 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2587 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
2588 NL80211_CMD_START_AP
))
2591 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2593 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2594 NL80211_MAX_NR_CIPHER_SUITES
);
2598 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
2599 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
2601 params
.inactivity_timeout
= nla_get_u16(
2602 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
2605 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2606 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
2608 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
2609 !nl80211_valid_channel_type(info
, &channel_type
))
2612 params
.channel
= rdev_freq_to_chan(rdev
,
2613 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
2615 if (!params
.channel
)
2617 params
.channel_type
= channel_type
;
2618 } else if (wdev
->preset_chan
) {
2619 params
.channel
= wdev
->preset_chan
;
2620 params
.channel_type
= wdev
->preset_chantype
;
2621 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
2624 if (!cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, params
.channel
,
2625 params
.channel_type
))
2628 mutex_lock(&rdev
->devlist_mtx
);
2629 err
= cfg80211_can_use_chan(rdev
, wdev
, params
.channel
,
2631 mutex_unlock(&rdev
->devlist_mtx
);
2636 err
= rdev
->ops
->start_ap(&rdev
->wiphy
, dev
, ¶ms
);
2638 wdev
->preset_chan
= params
.channel
;
2639 wdev
->preset_chantype
= params
.channel_type
;
2640 wdev
->beacon_interval
= params
.beacon_interval
;
2641 wdev
->channel
= params
.channel
;
2646 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2648 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2649 struct net_device
*dev
= info
->user_ptr
[1];
2650 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2651 struct cfg80211_beacon_data params
;
2654 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2655 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2658 if (!rdev
->ops
->change_beacon
)
2661 if (!wdev
->beacon_interval
)
2664 err
= nl80211_parse_beacon(info
, ¶ms
);
2668 return rdev
->ops
->change_beacon(&rdev
->wiphy
, dev
, ¶ms
);
2671 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2673 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2674 struct net_device
*dev
= info
->user_ptr
[1];
2676 return cfg80211_stop_ap(rdev
, dev
);
2679 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2680 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2681 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2682 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2683 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2684 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2685 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
2688 static int parse_station_flags(struct genl_info
*info
,
2689 enum nl80211_iftype iftype
,
2690 struct station_parameters
*params
)
2692 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2697 * Try parsing the new attribute first so userspace
2698 * can specify both for older kernels.
2700 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2702 struct nl80211_sta_flag_update
*sta_flags
;
2704 sta_flags
= nla_data(nla
);
2705 params
->sta_flags_mask
= sta_flags
->mask
;
2706 params
->sta_flags_set
= sta_flags
->set
;
2707 if ((params
->sta_flags_mask
|
2708 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2713 /* if present, parse the old attribute */
2715 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2719 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2720 nla
, sta_flags_policy
))
2724 * Only allow certain flags for interface types so that
2725 * other attributes are silently ignored. Remember that
2726 * this is backward compatibility code with old userspace
2727 * and shouldn't be hit in other cases anyway.
2730 case NL80211_IFTYPE_AP
:
2731 case NL80211_IFTYPE_AP_VLAN
:
2732 case NL80211_IFTYPE_P2P_GO
:
2733 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2734 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2735 BIT(NL80211_STA_FLAG_WME
) |
2736 BIT(NL80211_STA_FLAG_MFP
);
2738 case NL80211_IFTYPE_P2P_CLIENT
:
2739 case NL80211_IFTYPE_STATION
:
2740 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2741 BIT(NL80211_STA_FLAG_TDLS_PEER
);
2743 case NL80211_IFTYPE_MESH_POINT
:
2744 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2745 BIT(NL80211_STA_FLAG_MFP
) |
2746 BIT(NL80211_STA_FLAG_AUTHORIZED
);
2751 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
2753 params
->sta_flags_set
|= (1<<flag
);
2755 /* no longer support new API additions in old API */
2756 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
2764 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2767 struct nlattr
*rate
;
2771 rate
= nla_nest_start(msg
, attr
);
2773 goto nla_put_failure
;
2775 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2776 bitrate
= cfg80211_calculate_bitrate(info
);
2777 /* report 16-bit bitrate only if we can */
2778 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
2780 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
)) ||
2781 (bitrate_compat
> 0 &&
2782 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
)) ||
2783 ((info
->flags
& RATE_INFO_FLAGS_MCS
) &&
2784 nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
)) ||
2785 ((info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) &&
2786 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
)) ||
2787 ((info
->flags
& RATE_INFO_FLAGS_SHORT_GI
) &&
2788 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
)))
2789 goto nla_put_failure
;
2791 nla_nest_end(msg
, rate
);
2798 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
2800 struct cfg80211_registered_device
*rdev
,
2801 struct net_device
*dev
,
2802 const u8
*mac_addr
, struct station_info
*sinfo
)
2805 struct nlattr
*sinfoattr
, *bss_param
;
2807 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2811 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2812 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
2813 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
2814 goto nla_put_failure
;
2816 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2818 goto nla_put_failure
;
2819 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
2820 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2821 sinfo
->connected_time
))
2822 goto nla_put_failure
;
2823 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
2824 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2825 sinfo
->inactive_time
))
2826 goto nla_put_failure
;
2827 if ((sinfo
->filled
& STATION_INFO_RX_BYTES
) &&
2828 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
2830 goto nla_put_failure
;
2831 if ((sinfo
->filled
& STATION_INFO_TX_BYTES
) &&
2832 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
2834 goto nla_put_failure
;
2835 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
2836 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
2837 goto nla_put_failure
;
2838 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
2839 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
2840 goto nla_put_failure
;
2841 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
2842 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2843 sinfo
->plink_state
))
2844 goto nla_put_failure
;
2845 switch (rdev
->wiphy
.signal_type
) {
2846 case CFG80211_SIGNAL_TYPE_MBM
:
2847 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
2848 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
2850 goto nla_put_failure
;
2851 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
2852 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2854 goto nla_put_failure
;
2859 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2860 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2861 NL80211_STA_INFO_TX_BITRATE
))
2862 goto nla_put_failure
;
2864 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2865 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2866 NL80211_STA_INFO_RX_BITRATE
))
2867 goto nla_put_failure
;
2869 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
2870 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2872 goto nla_put_failure
;
2873 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
2874 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2876 goto nla_put_failure
;
2877 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
2878 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2880 goto nla_put_failure
;
2881 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
2882 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
2884 goto nla_put_failure
;
2885 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
2886 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
2887 sinfo
->beacon_loss_count
))
2888 goto nla_put_failure
;
2889 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2890 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2892 goto nla_put_failure
;
2894 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
2895 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
2896 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
2897 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
2898 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
2899 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
2900 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2901 sinfo
->bss_param
.dtim_period
) ||
2902 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2903 sinfo
->bss_param
.beacon_interval
))
2904 goto nla_put_failure
;
2906 nla_nest_end(msg
, bss_param
);
2908 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
2909 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
2910 sizeof(struct nl80211_sta_flag_update
),
2912 goto nla_put_failure
;
2913 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
2914 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
2916 goto nla_put_failure
;
2917 nla_nest_end(msg
, sinfoattr
);
2919 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
2920 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2921 sinfo
->assoc_req_ies
))
2922 goto nla_put_failure
;
2924 return genlmsg_end(msg
, hdr
);
2927 genlmsg_cancel(msg
, hdr
);
2931 static int nl80211_dump_station(struct sk_buff
*skb
,
2932 struct netlink_callback
*cb
)
2934 struct station_info sinfo
;
2935 struct cfg80211_registered_device
*dev
;
2936 struct net_device
*netdev
;
2937 u8 mac_addr
[ETH_ALEN
];
2938 int sta_idx
= cb
->args
[1];
2941 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2945 if (!dev
->ops
->dump_station
) {
2951 memset(&sinfo
, 0, sizeof(sinfo
));
2952 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2959 if (nl80211_send_station(skb
,
2960 NETLINK_CB(cb
->skb
).portid
,
2961 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2962 dev
, netdev
, mac_addr
,
2971 cb
->args
[1] = sta_idx
;
2974 nl80211_finish_netdev_dump(dev
);
2979 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2981 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2982 struct net_device
*dev
= info
->user_ptr
[1];
2983 struct station_info sinfo
;
2984 struct sk_buff
*msg
;
2985 u8
*mac_addr
= NULL
;
2988 memset(&sinfo
, 0, sizeof(sinfo
));
2990 if (!info
->attrs
[NL80211_ATTR_MAC
])
2993 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2995 if (!rdev
->ops
->get_station
)
2998 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
3002 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3006 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3007 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3012 return genlmsg_reply(msg
, info
);
3016 * Get vlan interface making sure it is running and on the right wiphy.
3018 static struct net_device
*get_vlan(struct genl_info
*info
,
3019 struct cfg80211_registered_device
*rdev
)
3021 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3022 struct net_device
*v
;
3028 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3030 return ERR_PTR(-ENODEV
);
3032 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3037 if (!netif_running(v
)) {
3045 return ERR_PTR(ret
);
3048 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3050 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3052 struct net_device
*dev
= info
->user_ptr
[1];
3053 struct station_parameters params
;
3054 u8
*mac_addr
= NULL
;
3056 memset(¶ms
, 0, sizeof(params
));
3058 params
.listen_interval
= -1;
3059 params
.plink_state
= -1;
3061 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3064 if (!info
->attrs
[NL80211_ATTR_MAC
])
3067 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3069 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3070 params
.supported_rates
=
3071 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3072 params
.supported_rates_len
=
3073 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3076 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3077 params
.listen_interval
=
3078 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3080 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3082 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3084 if (!rdev
->ops
->change_station
)
3087 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3090 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3091 params
.plink_action
=
3092 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3094 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
3095 params
.plink_state
=
3096 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3098 switch (dev
->ieee80211_ptr
->iftype
) {
3099 case NL80211_IFTYPE_AP
:
3100 case NL80211_IFTYPE_AP_VLAN
:
3101 case NL80211_IFTYPE_P2P_GO
:
3102 /* disallow mesh-specific things */
3103 if (params
.plink_action
)
3106 /* TDLS can't be set, ... */
3107 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3110 * ... but don't bother the driver with it. This works around
3111 * a hostapd/wpa_supplicant issue -- it always includes the
3112 * TLDS_PEER flag in the mask even for AP mode.
3114 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3116 /* accept only the listed bits */
3117 if (params
.sta_flags_mask
&
3118 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3119 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3120 BIT(NL80211_STA_FLAG_WME
) |
3121 BIT(NL80211_STA_FLAG_MFP
)))
3124 /* must be last in here for error handling */
3125 params
.vlan
= get_vlan(info
, rdev
);
3126 if (IS_ERR(params
.vlan
))
3127 return PTR_ERR(params
.vlan
);
3129 case NL80211_IFTYPE_P2P_CLIENT
:
3130 case NL80211_IFTYPE_STATION
:
3132 * Don't allow userspace to change the TDLS_PEER flag,
3133 * but silently ignore attempts to change it since we
3134 * don't have state here to verify that it doesn't try
3135 * to change the flag.
3137 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3139 case NL80211_IFTYPE_ADHOC
:
3140 /* disallow things sta doesn't support */
3141 if (params
.plink_action
)
3145 if (params
.listen_interval
>= 0)
3147 /* reject any changes other than AUTHORIZED */
3148 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3151 case NL80211_IFTYPE_MESH_POINT
:
3152 /* disallow things mesh doesn't support */
3157 if (params
.listen_interval
>= 0)
3160 * No special handling for TDLS here -- the userspace
3161 * mesh code doesn't have this bug.
3163 if (params
.sta_flags_mask
&
3164 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3165 BIT(NL80211_STA_FLAG_MFP
) |
3166 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3173 /* be aware of params.vlan when changing code here */
3175 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3178 dev_put(params
.vlan
);
3183 static struct nla_policy
3184 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3185 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3186 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3189 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3191 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3193 struct net_device
*dev
= info
->user_ptr
[1];
3194 struct station_parameters params
;
3195 u8
*mac_addr
= NULL
;
3197 memset(¶ms
, 0, sizeof(params
));
3199 if (!info
->attrs
[NL80211_ATTR_MAC
])
3202 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3205 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3208 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3211 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3212 params
.supported_rates
=
3213 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3214 params
.supported_rates_len
=
3215 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3216 params
.listen_interval
=
3217 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3219 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3220 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3223 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3225 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3227 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3229 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3231 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3232 params
.plink_action
=
3233 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3235 if (!rdev
->ops
->add_station
)
3238 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3241 switch (dev
->ieee80211_ptr
->iftype
) {
3242 case NL80211_IFTYPE_AP
:
3243 case NL80211_IFTYPE_AP_VLAN
:
3244 case NL80211_IFTYPE_P2P_GO
:
3245 /* parse WME attributes if sta is WME capable */
3246 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
3247 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
3248 info
->attrs
[NL80211_ATTR_STA_WME
]) {
3249 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3252 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3253 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3254 nl80211_sta_wme_policy
);
3258 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3259 params
.uapsd_queues
=
3260 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3261 if (params
.uapsd_queues
&
3262 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3265 if (tb
[NL80211_STA_WME_MAX_SP
])
3267 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3270 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3273 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3275 /* TDLS peers cannot be added */
3276 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3278 /* but don't bother the driver with it */
3279 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3281 /* must be last in here for error handling */
3282 params
.vlan
= get_vlan(info
, rdev
);
3283 if (IS_ERR(params
.vlan
))
3284 return PTR_ERR(params
.vlan
);
3286 case NL80211_IFTYPE_MESH_POINT
:
3287 /* TDLS peers cannot be added */
3288 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3291 case NL80211_IFTYPE_STATION
:
3292 /* Only TDLS peers can be added */
3293 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3295 /* Can only add if TDLS ... */
3296 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3298 /* ... with external setup is supported */
3299 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3306 /* be aware of params.vlan when changing code here */
3308 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3311 dev_put(params
.vlan
);
3315 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
3317 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3318 struct net_device
*dev
= info
->user_ptr
[1];
3319 u8
*mac_addr
= NULL
;
3321 if (info
->attrs
[NL80211_ATTR_MAC
])
3322 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3324 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3325 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3326 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
3327 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3330 if (!rdev
->ops
->del_station
)
3333 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
3336 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3337 int flags
, struct net_device
*dev
,
3338 u8
*dst
, u8
*next_hop
,
3339 struct mpath_info
*pinfo
)
3342 struct nlattr
*pinfoattr
;
3344 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3348 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3349 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
3350 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
3351 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
3352 goto nla_put_failure
;
3354 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
3356 goto nla_put_failure
;
3357 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
3358 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
3360 goto nla_put_failure
;
3361 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
3362 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
3363 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
3364 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
3366 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
3367 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
3369 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
3370 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
3372 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
3373 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
3374 pinfo
->discovery_timeout
)) ||
3375 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
3376 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
3377 pinfo
->discovery_retries
)))
3378 goto nla_put_failure
;
3380 nla_nest_end(msg
, pinfoattr
);
3382 return genlmsg_end(msg
, hdr
);
3385 genlmsg_cancel(msg
, hdr
);
3389 static int nl80211_dump_mpath(struct sk_buff
*skb
,
3390 struct netlink_callback
*cb
)
3392 struct mpath_info pinfo
;
3393 struct cfg80211_registered_device
*dev
;
3394 struct net_device
*netdev
;
3396 u8 next_hop
[ETH_ALEN
];
3397 int path_idx
= cb
->args
[1];
3400 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3404 if (!dev
->ops
->dump_mpath
) {
3409 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
3415 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
3416 dst
, next_hop
, &pinfo
);
3422 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
3423 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3424 netdev
, dst
, next_hop
,
3433 cb
->args
[1] = path_idx
;
3436 nl80211_finish_netdev_dump(dev
);
3440 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3442 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3444 struct net_device
*dev
= info
->user_ptr
[1];
3445 struct mpath_info pinfo
;
3446 struct sk_buff
*msg
;
3448 u8 next_hop
[ETH_ALEN
];
3450 memset(&pinfo
, 0, sizeof(pinfo
));
3452 if (!info
->attrs
[NL80211_ATTR_MAC
])
3455 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3457 if (!rdev
->ops
->get_mpath
)
3460 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3463 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
3467 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3471 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3472 dev
, dst
, next_hop
, &pinfo
) < 0) {
3477 return genlmsg_reply(msg
, info
);
3480 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3482 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3483 struct net_device
*dev
= info
->user_ptr
[1];
3485 u8
*next_hop
= NULL
;
3487 if (!info
->attrs
[NL80211_ATTR_MAC
])
3490 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3493 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3494 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3496 if (!rdev
->ops
->change_mpath
)
3499 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3502 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3505 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3507 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3508 struct net_device
*dev
= info
->user_ptr
[1];
3510 u8
*next_hop
= NULL
;
3512 if (!info
->attrs
[NL80211_ATTR_MAC
])
3515 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3518 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3519 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3521 if (!rdev
->ops
->add_mpath
)
3524 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3527 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3530 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3532 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3533 struct net_device
*dev
= info
->user_ptr
[1];
3536 if (info
->attrs
[NL80211_ATTR_MAC
])
3537 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3539 if (!rdev
->ops
->del_mpath
)
3542 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
3545 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
3547 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3548 struct net_device
*dev
= info
->user_ptr
[1];
3549 struct bss_parameters params
;
3551 memset(¶ms
, 0, sizeof(params
));
3552 /* default to not changing parameters */
3553 params
.use_cts_prot
= -1;
3554 params
.use_short_preamble
= -1;
3555 params
.use_short_slot_time
= -1;
3556 params
.ap_isolate
= -1;
3557 params
.ht_opmode
= -1;
3559 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
3560 params
.use_cts_prot
=
3561 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
3562 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
3563 params
.use_short_preamble
=
3564 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
3565 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
3566 params
.use_short_slot_time
=
3567 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
3568 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3569 params
.basic_rates
=
3570 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3571 params
.basic_rates_len
=
3572 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3574 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
3575 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
3576 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
3578 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
3580 if (!rdev
->ops
->change_bss
)
3583 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3584 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3587 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
3590 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
3591 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3592 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3593 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3594 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3595 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3596 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3599 static int parse_reg_rule(struct nlattr
*tb
[],
3600 struct ieee80211_reg_rule
*reg_rule
)
3602 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3603 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3605 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3607 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3609 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3611 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3613 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3616 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3618 freq_range
->start_freq_khz
=
3619 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3620 freq_range
->end_freq_khz
=
3621 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3622 freq_range
->max_bandwidth_khz
=
3623 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3625 power_rule
->max_eirp
=
3626 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3628 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3629 power_rule
->max_antenna_gain
=
3630 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3635 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3639 enum nl80211_user_reg_hint_type user_reg_hint_type
;
3642 * You should only get this when cfg80211 hasn't yet initialized
3643 * completely when built-in to the kernel right between the time
3644 * window between nl80211_init() and regulatory_init(), if that is
3647 mutex_lock(&cfg80211_mutex
);
3648 if (unlikely(!cfg80211_regdomain
)) {
3649 mutex_unlock(&cfg80211_mutex
);
3650 return -EINPROGRESS
;
3652 mutex_unlock(&cfg80211_mutex
);
3654 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3657 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3659 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
3660 user_reg_hint_type
=
3661 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
3663 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
3665 switch (user_reg_hint_type
) {
3666 case NL80211_USER_REG_HINT_USER
:
3667 case NL80211_USER_REG_HINT_CELL_BASE
:
3673 r
= regulatory_hint_user(data
, user_reg_hint_type
);
3678 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3679 struct genl_info
*info
)
3681 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3682 struct net_device
*dev
= info
->user_ptr
[1];
3683 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3684 struct mesh_config cur_params
;
3687 struct nlattr
*pinfoattr
;
3688 struct sk_buff
*msg
;
3690 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3693 if (!rdev
->ops
->get_mesh_config
)
3697 /* If not connected, get default parameters */
3698 if (!wdev
->mesh_id_len
)
3699 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3701 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3708 /* Draw up a netlink message to send back */
3709 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3712 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3713 NL80211_CMD_GET_MESH_CONFIG
);
3716 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3718 goto nla_put_failure
;
3719 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3720 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3721 cur_params
.dot11MeshRetryTimeout
) ||
3722 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3723 cur_params
.dot11MeshConfirmTimeout
) ||
3724 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3725 cur_params
.dot11MeshHoldingTimeout
) ||
3726 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3727 cur_params
.dot11MeshMaxPeerLinks
) ||
3728 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3729 cur_params
.dot11MeshMaxRetries
) ||
3730 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
3731 cur_params
.dot11MeshTTL
) ||
3732 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3733 cur_params
.element_ttl
) ||
3734 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3735 cur_params
.auto_open_plinks
) ||
3736 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3737 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
3738 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3739 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
3740 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3741 cur_params
.path_refresh_time
) ||
3742 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3743 cur_params
.min_discovery_timeout
) ||
3744 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3745 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
3746 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3747 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
3748 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3749 cur_params
.dot11MeshHWMPperrMinInterval
) ||
3750 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3751 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
3752 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3753 cur_params
.dot11MeshHWMPRootMode
) ||
3754 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3755 cur_params
.dot11MeshHWMPRannInterval
) ||
3756 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3757 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
3758 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
3759 cur_params
.dot11MeshForwarding
) ||
3760 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3761 cur_params
.rssi_threshold
) ||
3762 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
3763 cur_params
.ht_opmode
) ||
3764 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3765 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
3766 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3767 cur_params
.dot11MeshHWMProotInterval
) ||
3768 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3769 cur_params
.dot11MeshHWMPconfirmationInterval
))
3770 goto nla_put_failure
;
3771 nla_nest_end(msg
, pinfoattr
);
3772 genlmsg_end(msg
, hdr
);
3773 return genlmsg_reply(msg
, info
);
3776 genlmsg_cancel(msg
, hdr
);
3782 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3783 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3784 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3785 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3786 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3787 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3788 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3789 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3790 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3791 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
3792 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3793 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3794 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3795 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3796 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3797 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
3798 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3799 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3800 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3801 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3802 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
3803 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
3804 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
3805 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
3806 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
3807 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
3810 static const struct nla_policy
3811 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3812 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
3813 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3814 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3815 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3816 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3817 .len
= IEEE80211_MAX_DATA_LEN
},
3818 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3821 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3822 struct mesh_config
*cfg
,
3825 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3828 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3830 if (table[attr_num]) {\
3831 cfg->param = nla_fn(table[attr_num]); \
3832 mask |= (1 << (attr_num - 1)); \
3837 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3839 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3840 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3841 nl80211_meshconf_params_policy
))
3844 /* This makes sure that there aren't more than 32 mesh config
3845 * parameters (otherwise our bitfield scheme would not work.) */
3846 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3848 /* Fill in the params struct */
3849 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3850 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3852 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3853 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3855 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3856 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3858 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3859 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3861 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3862 mask
, NL80211_MESHCONF_MAX_RETRIES
,
3864 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3865 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3866 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3867 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
3869 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3870 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3872 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
, mask
,
3873 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3875 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3876 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3878 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3879 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3881 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3882 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3884 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
, mask
,
3885 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3887 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3888 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3890 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
3891 mask
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3893 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3894 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
3895 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3897 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
3898 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
3899 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
3900 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3902 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3903 dot11MeshGateAnnouncementProtocol
, mask
,
3904 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3906 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
,
3907 mask
, NL80211_MESHCONF_FORWARDING
,
3909 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
,
3910 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3912 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
,
3913 mask
, NL80211_MESHCONF_HT_OPMODE
,
3915 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
3917 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3919 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
,
3920 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3922 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3923 dot11MeshHWMPconfirmationInterval
, mask
,
3924 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3931 #undef FILL_IN_MESH_PARAM_IF_SET
3934 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3935 struct mesh_setup
*setup
)
3937 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3939 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3941 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3942 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3943 nl80211_mesh_setup_params_policy
))
3946 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
3947 setup
->sync_method
=
3948 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
3949 IEEE80211_SYNC_METHOD_VENDOR
:
3950 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
3952 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3953 setup
->path_sel_proto
=
3954 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3955 IEEE80211_PATH_PROTOCOL_VENDOR
:
3956 IEEE80211_PATH_PROTOCOL_HWMP
;
3958 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3959 setup
->path_metric
=
3960 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3961 IEEE80211_PATH_METRIC_VENDOR
:
3962 IEEE80211_PATH_METRIC_AIRTIME
;
3965 if (tb
[NL80211_MESH_SETUP_IE
]) {
3966 struct nlattr
*ieattr
=
3967 tb
[NL80211_MESH_SETUP_IE
];
3968 if (!is_valid_ie_attr(ieattr
))
3970 setup
->ie
= nla_data(ieattr
);
3971 setup
->ie_len
= nla_len(ieattr
);
3973 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3974 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3979 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3980 struct genl_info
*info
)
3982 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3983 struct net_device
*dev
= info
->user_ptr
[1];
3984 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3985 struct mesh_config cfg
;
3989 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3992 if (!rdev
->ops
->update_mesh_config
)
3995 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4000 if (!wdev
->mesh_id_len
)
4004 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
4012 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4014 struct sk_buff
*msg
;
4016 struct nlattr
*nl_reg_rules
;
4020 mutex_lock(&cfg80211_mutex
);
4022 if (!cfg80211_regdomain
)
4025 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4031 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4032 NL80211_CMD_GET_REG
);
4036 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
4037 cfg80211_regdomain
->alpha2
) ||
4038 (cfg80211_regdomain
->dfs_region
&&
4039 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
,
4040 cfg80211_regdomain
->dfs_region
)))
4041 goto nla_put_failure
;
4043 if (reg_last_request_cell_base() &&
4044 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4045 NL80211_USER_REG_HINT_CELL_BASE
))
4046 goto nla_put_failure
;
4048 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4050 goto nla_put_failure
;
4052 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
4053 struct nlattr
*nl_reg_rule
;
4054 const struct ieee80211_reg_rule
*reg_rule
;
4055 const struct ieee80211_freq_range
*freq_range
;
4056 const struct ieee80211_power_rule
*power_rule
;
4058 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
4059 freq_range
= ®_rule
->freq_range
;
4060 power_rule
= ®_rule
->power_rule
;
4062 nl_reg_rule
= nla_nest_start(msg
, i
);
4064 goto nla_put_failure
;
4066 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4068 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4069 freq_range
->start_freq_khz
) ||
4070 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4071 freq_range
->end_freq_khz
) ||
4072 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4073 freq_range
->max_bandwidth_khz
) ||
4074 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4075 power_rule
->max_antenna_gain
) ||
4076 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4077 power_rule
->max_eirp
))
4078 goto nla_put_failure
;
4080 nla_nest_end(msg
, nl_reg_rule
);
4083 nla_nest_end(msg
, nl_reg_rules
);
4085 genlmsg_end(msg
, hdr
);
4086 err
= genlmsg_reply(msg
, info
);
4090 genlmsg_cancel(msg
, hdr
);
4095 mutex_unlock(&cfg80211_mutex
);
4099 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4101 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4102 struct nlattr
*nl_reg_rule
;
4103 char *alpha2
= NULL
;
4104 int rem_reg_rules
= 0, r
= 0;
4105 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4107 struct ieee80211_regdomain
*rd
= NULL
;
4109 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4112 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
4115 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4117 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
4118 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
4120 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4123 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
4127 mutex_lock(&cfg80211_mutex
);
4129 if (!reg_is_valid_request(alpha2
)) {
4134 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
4135 (num_rules
* sizeof(struct ieee80211_reg_rule
));
4137 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
4143 rd
->n_reg_rules
= num_rules
;
4144 rd
->alpha2
[0] = alpha2
[0];
4145 rd
->alpha2
[1] = alpha2
[1];
4148 * Disable DFS master mode if the DFS region was
4149 * not supported or known on this kernel.
4151 if (reg_supported_dfs_region(dfs_region
))
4152 rd
->dfs_region
= dfs_region
;
4154 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4156 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
4157 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
4159 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
4165 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
4171 BUG_ON(rule_idx
!= num_rules
);
4175 mutex_unlock(&cfg80211_mutex
);
4180 mutex_unlock(&cfg80211_mutex
);
4185 static int validate_scan_freqs(struct nlattr
*freqs
)
4187 struct nlattr
*attr1
, *attr2
;
4188 int n_channels
= 0, tmp1
, tmp2
;
4190 nla_for_each_nested(attr1
, freqs
, tmp1
) {
4193 * Some hardware has a limited channel list for
4194 * scanning, and it is pretty much nonsensical
4195 * to scan for a channel twice, so disallow that
4196 * and don't require drivers to check that the
4197 * channel list they get isn't longer than what
4198 * they can scan, as long as they can scan all
4199 * the channels they registered at once.
4201 nla_for_each_nested(attr2
, freqs
, tmp2
)
4202 if (attr1
!= attr2
&&
4203 nla_get_u32(attr1
) == nla_get_u32(attr2
))
4210 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
4212 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4213 struct wireless_dev
*wdev
= info
->user_ptr
[1];
4214 struct cfg80211_scan_request
*request
;
4215 struct nlattr
*attr
;
4216 struct wiphy
*wiphy
;
4217 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
4220 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4223 wiphy
= &rdev
->wiphy
;
4225 if (!rdev
->ops
->scan
)
4231 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4232 n_channels
= validate_scan_freqs(
4233 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4237 enum ieee80211_band band
;
4240 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4241 if (wiphy
->bands
[band
])
4242 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4245 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4246 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
4249 if (n_ssids
> wiphy
->max_scan_ssids
)
4252 if (info
->attrs
[NL80211_ATTR_IE
])
4253 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4257 if (ie_len
> wiphy
->max_scan_ie_len
)
4260 request
= kzalloc(sizeof(*request
)
4261 + sizeof(*request
->ssids
) * n_ssids
4262 + sizeof(*request
->channels
) * n_channels
4263 + ie_len
, GFP_KERNEL
);
4268 request
->ssids
= (void *)&request
->channels
[n_channels
];
4269 request
->n_ssids
= n_ssids
;
4272 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4274 request
->ie
= (void *)(request
->channels
+ n_channels
);
4278 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4279 /* user specified, bail out if channel not found */
4280 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
4281 struct ieee80211_channel
*chan
;
4283 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4290 /* ignore disabled channels */
4291 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4294 request
->channels
[i
] = chan
;
4298 enum ieee80211_band band
;
4301 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4303 if (!wiphy
->bands
[band
])
4305 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4306 struct ieee80211_channel
*chan
;
4308 chan
= &wiphy
->bands
[band
]->channels
[j
];
4310 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4313 request
->channels
[i
] = chan
;
4324 request
->n_channels
= i
;
4327 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4328 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
4329 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4333 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4334 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
4339 if (info
->attrs
[NL80211_ATTR_IE
]) {
4340 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4341 memcpy((void *)request
->ie
,
4342 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4346 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4347 if (wiphy
->bands
[i
])
4349 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
4351 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
4352 nla_for_each_nested(attr
,
4353 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
4355 enum ieee80211_band band
= nla_type(attr
);
4357 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4361 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
4364 &request
->rates
[band
]);
4371 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
4373 request
->wdev
= wdev
;
4374 request
->wiphy
= &rdev
->wiphy
;
4376 rdev
->scan_req
= request
;
4377 err
= rdev
->ops
->scan(&rdev
->wiphy
, request
);
4380 nl80211_send_scan_start(rdev
, wdev
);
4382 dev_hold(wdev
->netdev
);
4385 rdev
->scan_req
= NULL
;
4392 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
4393 struct genl_info
*info
)
4395 struct cfg80211_sched_scan_request
*request
;
4396 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4397 struct net_device
*dev
= info
->user_ptr
[1];
4398 struct nlattr
*attr
;
4399 struct wiphy
*wiphy
;
4400 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
4402 enum ieee80211_band band
;
4404 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
4406 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4407 !rdev
->ops
->sched_scan_start
)
4410 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4413 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
4416 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
4420 wiphy
= &rdev
->wiphy
;
4422 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4423 n_channels
= validate_scan_freqs(
4424 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4430 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4431 if (wiphy
->bands
[band
])
4432 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4435 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4436 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4440 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
4443 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
4444 nla_for_each_nested(attr
,
4445 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4449 if (n_match_sets
> wiphy
->max_match_sets
)
4452 if (info
->attrs
[NL80211_ATTR_IE
])
4453 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4457 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
4460 mutex_lock(&rdev
->sched_scan_mtx
);
4462 if (rdev
->sched_scan_req
) {
4467 request
= kzalloc(sizeof(*request
)
4468 + sizeof(*request
->ssids
) * n_ssids
4469 + sizeof(*request
->match_sets
) * n_match_sets
4470 + sizeof(*request
->channels
) * n_channels
4471 + ie_len
, GFP_KERNEL
);
4478 request
->ssids
= (void *)&request
->channels
[n_channels
];
4479 request
->n_ssids
= n_ssids
;
4482 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4484 request
->ie
= (void *)(request
->channels
+ n_channels
);
4489 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
4490 else if (request
->ssids
)
4491 request
->match_sets
=
4492 (void *)(request
->ssids
+ n_ssids
);
4494 request
->match_sets
=
4495 (void *)(request
->channels
+ n_channels
);
4497 request
->n_match_sets
= n_match_sets
;
4500 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4501 /* user specified, bail out if channel not found */
4502 nla_for_each_nested(attr
,
4503 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
4505 struct ieee80211_channel
*chan
;
4507 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4514 /* ignore disabled channels */
4515 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4518 request
->channels
[i
] = chan
;
4523 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4525 if (!wiphy
->bands
[band
])
4527 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4528 struct ieee80211_channel
*chan
;
4530 chan
= &wiphy
->bands
[band
]->channels
[j
];
4532 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4535 request
->channels
[i
] = chan
;
4546 request
->n_channels
= i
;
4549 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4550 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4552 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4556 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4557 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
4564 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
4565 nla_for_each_nested(attr
,
4566 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4568 struct nlattr
*ssid
, *rssi
;
4570 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
4571 nla_data(attr
), nla_len(attr
),
4572 nl80211_match_policy
);
4573 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
4575 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
4579 memcpy(request
->match_sets
[i
].ssid
.ssid
,
4580 nla_data(ssid
), nla_len(ssid
));
4581 request
->match_sets
[i
].ssid
.ssid_len
=
4584 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
4586 request
->rssi_thold
= nla_get_u32(rssi
);
4588 request
->rssi_thold
=
4589 NL80211_SCAN_RSSI_THOLD_OFF
;
4594 if (info
->attrs
[NL80211_ATTR_IE
]) {
4595 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4596 memcpy((void *)request
->ie
,
4597 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4602 request
->wiphy
= &rdev
->wiphy
;
4603 request
->interval
= interval
;
4605 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
4607 rdev
->sched_scan_req
= request
;
4608 nl80211_send_sched_scan(rdev
, dev
,
4609 NL80211_CMD_START_SCHED_SCAN
);
4616 mutex_unlock(&rdev
->sched_scan_mtx
);
4620 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
4621 struct genl_info
*info
)
4623 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4626 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4627 !rdev
->ops
->sched_scan_stop
)
4630 mutex_lock(&rdev
->sched_scan_mtx
);
4631 err
= __cfg80211_stop_sched_scan(rdev
, false);
4632 mutex_unlock(&rdev
->sched_scan_mtx
);
4637 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
4639 struct cfg80211_registered_device
*rdev
,
4640 struct wireless_dev
*wdev
,
4641 struct cfg80211_internal_bss
*intbss
)
4643 struct cfg80211_bss
*res
= &intbss
->pub
;
4647 ASSERT_WDEV_LOCK(wdev
);
4649 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
4650 NL80211_CMD_NEW_SCAN_RESULTS
);
4654 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
4656 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
) ||
4657 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
4658 goto nla_put_failure
;
4660 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
4662 goto nla_put_failure
;
4663 if ((!is_zero_ether_addr(res
->bssid
) &&
4664 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)) ||
4665 (res
->information_elements
&& res
->len_information_elements
&&
4666 nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
4667 res
->len_information_elements
,
4668 res
->information_elements
)) ||
4669 (res
->beacon_ies
&& res
->len_beacon_ies
&&
4670 res
->beacon_ies
!= res
->information_elements
&&
4671 nla_put(msg
, NL80211_BSS_BEACON_IES
,
4672 res
->len_beacon_ies
, res
->beacon_ies
)))
4673 goto nla_put_failure
;
4675 nla_put_u64(msg
, NL80211_BSS_TSF
, res
->tsf
))
4676 goto nla_put_failure
;
4677 if (res
->beacon_interval
&&
4678 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
4679 goto nla_put_failure
;
4680 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
4681 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
4682 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
4683 jiffies_to_msecs(jiffies
- intbss
->ts
)))
4684 goto nla_put_failure
;
4686 switch (rdev
->wiphy
.signal_type
) {
4687 case CFG80211_SIGNAL_TYPE_MBM
:
4688 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
4689 goto nla_put_failure
;
4691 case CFG80211_SIGNAL_TYPE_UNSPEC
:
4692 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
4693 goto nla_put_failure
;
4699 switch (wdev
->iftype
) {
4700 case NL80211_IFTYPE_P2P_CLIENT
:
4701 case NL80211_IFTYPE_STATION
:
4702 if (intbss
== wdev
->current_bss
&&
4703 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4704 NL80211_BSS_STATUS_ASSOCIATED
))
4705 goto nla_put_failure
;
4707 case NL80211_IFTYPE_ADHOC
:
4708 if (intbss
== wdev
->current_bss
&&
4709 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4710 NL80211_BSS_STATUS_IBSS_JOINED
))
4711 goto nla_put_failure
;
4717 nla_nest_end(msg
, bss
);
4719 return genlmsg_end(msg
, hdr
);
4722 genlmsg_cancel(msg
, hdr
);
4726 static int nl80211_dump_scan(struct sk_buff
*skb
,
4727 struct netlink_callback
*cb
)
4729 struct cfg80211_registered_device
*rdev
;
4730 struct net_device
*dev
;
4731 struct cfg80211_internal_bss
*scan
;
4732 struct wireless_dev
*wdev
;
4733 int start
= cb
->args
[1], idx
= 0;
4736 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4740 wdev
= dev
->ieee80211_ptr
;
4743 spin_lock_bh(&rdev
->bss_lock
);
4744 cfg80211_bss_expire(rdev
);
4746 cb
->seq
= rdev
->bss_generation
;
4748 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4751 if (nl80211_send_bss(skb
, cb
,
4752 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4753 rdev
, wdev
, scan
) < 0) {
4759 spin_unlock_bh(&rdev
->bss_lock
);
4763 nl80211_finish_netdev_dump(rdev
);
4768 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4769 int flags
, struct net_device
*dev
,
4770 struct survey_info
*survey
)
4773 struct nlattr
*infoattr
;
4775 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
4776 NL80211_CMD_NEW_SURVEY_RESULTS
);
4780 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
4781 goto nla_put_failure
;
4783 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4785 goto nla_put_failure
;
4787 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4788 survey
->channel
->center_freq
))
4789 goto nla_put_failure
;
4791 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
4792 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
4793 goto nla_put_failure
;
4794 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
4795 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
4796 goto nla_put_failure
;
4797 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
4798 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4799 survey
->channel_time
))
4800 goto nla_put_failure
;
4801 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
4802 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4803 survey
->channel_time_busy
))
4804 goto nla_put_failure
;
4805 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
4806 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4807 survey
->channel_time_ext_busy
))
4808 goto nla_put_failure
;
4809 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
4810 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4811 survey
->channel_time_rx
))
4812 goto nla_put_failure
;
4813 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
4814 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4815 survey
->channel_time_tx
))
4816 goto nla_put_failure
;
4818 nla_nest_end(msg
, infoattr
);
4820 return genlmsg_end(msg
, hdr
);
4823 genlmsg_cancel(msg
, hdr
);
4827 static int nl80211_dump_survey(struct sk_buff
*skb
,
4828 struct netlink_callback
*cb
)
4830 struct survey_info survey
;
4831 struct cfg80211_registered_device
*dev
;
4832 struct net_device
*netdev
;
4833 int survey_idx
= cb
->args
[1];
4836 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4840 if (!dev
->ops
->dump_survey
) {
4846 struct ieee80211_channel
*chan
;
4848 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4855 /* Survey without a channel doesn't make sense */
4856 if (!survey
.channel
) {
4861 chan
= ieee80211_get_channel(&dev
->wiphy
,
4862 survey
.channel
->center_freq
);
4863 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4868 if (nl80211_send_survey(skb
,
4869 NETLINK_CB(cb
->skb
).portid
,
4870 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4878 cb
->args
[1] = survey_idx
;
4881 nl80211_finish_netdev_dump(dev
);
4885 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4887 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4888 NL80211_WPA_VERSION_2
));
4891 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4893 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4894 struct net_device
*dev
= info
->user_ptr
[1];
4895 struct ieee80211_channel
*chan
;
4896 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
4897 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
4898 enum nl80211_auth_type auth_type
;
4899 struct key_parse key
;
4900 bool local_state_change
;
4902 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4905 if (!info
->attrs
[NL80211_ATTR_MAC
])
4908 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4911 if (!info
->attrs
[NL80211_ATTR_SSID
])
4914 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4917 err
= nl80211_parse_key(info
, &key
);
4922 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4924 if (!key
.p
.key
|| !key
.p
.key_len
)
4926 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4927 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4928 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4929 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4941 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4942 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4951 if (!rdev
->ops
->auth
)
4954 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4955 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4958 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4959 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4960 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4961 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4964 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4965 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4967 if (info
->attrs
[NL80211_ATTR_IE
]) {
4968 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4969 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4972 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4973 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
4976 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
4977 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
4980 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
4981 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
4983 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
4984 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
4985 /* need to include at least Auth Transaction and Status Code */
4986 if (sae_data_len
< 4)
4990 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4993 * Since we no longer track auth state, ignore
4994 * requests to only change local state.
4996 if (local_state_change
)
4999 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5000 ssid
, ssid_len
, ie
, ie_len
,
5001 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5002 sae_data
, sae_data_len
);
5005 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5006 struct genl_info
*info
,
5007 struct cfg80211_crypto_settings
*settings
,
5010 memset(settings
, 0, sizeof(*settings
));
5012 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5014 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5016 proto
= nla_get_u16(
5017 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5018 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5019 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5022 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5023 settings
->control_port_no_encrypt
= true;
5025 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5027 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5031 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5032 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5033 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
5035 if (len
% sizeof(u32
))
5038 if (settings
->n_ciphers_pairwise
> cipher_limit
)
5041 memcpy(settings
->ciphers_pairwise
, data
, len
);
5043 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
5044 if (!cfg80211_supported_cipher_suite(
5046 settings
->ciphers_pairwise
[i
]))
5050 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
5051 settings
->cipher_group
=
5052 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
5053 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
5054 settings
->cipher_group
))
5058 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
5059 settings
->wpa_versions
=
5060 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
5061 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
5065 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
5069 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5070 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5071 settings
->n_akm_suites
= len
/ sizeof(u32
);
5073 if (len
% sizeof(u32
))
5076 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
5079 memcpy(settings
->akm_suites
, data
, len
);
5085 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
5087 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5088 struct net_device
*dev
= info
->user_ptr
[1];
5089 struct cfg80211_crypto_settings crypto
;
5090 struct ieee80211_channel
*chan
;
5091 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
5092 int err
, ssid_len
, ie_len
= 0;
5093 bool use_mfp
= false;
5095 struct ieee80211_ht_cap
*ht_capa
= NULL
;
5096 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
5098 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5101 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
5102 !info
->attrs
[NL80211_ATTR_SSID
] ||
5103 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5106 if (!rdev
->ops
->assoc
)
5109 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5110 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5113 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5115 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5116 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5117 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5120 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5121 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5123 if (info
->attrs
[NL80211_ATTR_IE
]) {
5124 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5125 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5128 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
5129 enum nl80211_mfp mfp
=
5130 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
5131 if (mfp
== NL80211_MFP_REQUIRED
)
5133 else if (mfp
!= NL80211_MFP_NO
)
5137 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
5138 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
5140 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5141 flags
|= ASSOC_REQ_DISABLE_HT
;
5143 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5145 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
5147 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5150 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5153 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
5155 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
5156 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
5157 &crypto
, flags
, ht_capa
,
5163 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5165 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5166 struct net_device
*dev
= info
->user_ptr
[1];
5167 const u8
*ie
= NULL
, *bssid
;
5170 bool local_state_change
;
5172 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5175 if (!info
->attrs
[NL80211_ATTR_MAC
])
5178 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5181 if (!rdev
->ops
->deauth
)
5184 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5185 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5188 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5190 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5191 if (reason_code
== 0) {
5192 /* Reason Code 0 is reserved */
5196 if (info
->attrs
[NL80211_ATTR_IE
]) {
5197 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5198 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5201 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5203 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5204 local_state_change
);
5207 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
5209 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5210 struct net_device
*dev
= info
->user_ptr
[1];
5211 const u8
*ie
= NULL
, *bssid
;
5214 bool local_state_change
;
5216 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5219 if (!info
->attrs
[NL80211_ATTR_MAC
])
5222 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5225 if (!rdev
->ops
->disassoc
)
5228 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5229 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5232 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5234 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5235 if (reason_code
== 0) {
5236 /* Reason Code 0 is reserved */
5240 if (info
->attrs
[NL80211_ATTR_IE
]) {
5241 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5242 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5245 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5247 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5248 local_state_change
);
5252 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
5253 int mcast_rate
[IEEE80211_NUM_BANDS
],
5256 struct wiphy
*wiphy
= &rdev
->wiphy
;
5260 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5261 struct ieee80211_supported_band
*sband
;
5263 sband
= wiphy
->bands
[band
];
5267 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
5268 if (sband
->bitrates
[i
].bitrate
== rateval
) {
5269 mcast_rate
[band
] = i
+ 1;
5279 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5281 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5282 struct net_device
*dev
= info
->user_ptr
[1];
5283 struct cfg80211_ibss_params ibss
;
5284 struct wiphy
*wiphy
;
5285 struct cfg80211_cached_keys
*connkeys
= NULL
;
5288 memset(&ibss
, 0, sizeof(ibss
));
5290 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5293 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5294 !info
->attrs
[NL80211_ATTR_SSID
] ||
5295 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5298 ibss
.beacon_interval
= 100;
5300 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
5301 ibss
.beacon_interval
=
5302 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5303 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
5307 if (!rdev
->ops
->join_ibss
)
5310 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5313 wiphy
= &rdev
->wiphy
;
5315 if (info
->attrs
[NL80211_ATTR_MAC
]) {
5316 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5318 if (!is_valid_ether_addr(ibss
.bssid
))
5321 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5322 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5324 if (info
->attrs
[NL80211_ATTR_IE
]) {
5325 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5326 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5329 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5330 enum nl80211_channel_type channel_type
;
5332 if (!nl80211_valid_channel_type(info
, &channel_type
))
5335 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5336 !(wiphy
->features
& NL80211_FEATURE_HT_IBSS
))
5339 ibss
.channel_type
= channel_type
;
5341 ibss
.channel_type
= NL80211_CHAN_NO_HT
;
5344 ibss
.channel
= rdev_freq_to_chan(rdev
,
5345 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
5347 if (!ibss
.channel
||
5348 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
5349 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5352 /* Both channels should be able to initiate communication */
5353 if ((ibss
.channel_type
== NL80211_CHAN_HT40PLUS
||
5354 ibss
.channel_type
== NL80211_CHAN_HT40MINUS
) &&
5355 !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, ibss
.channel
,
5359 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
5360 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5362 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5364 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5366 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5367 struct ieee80211_supported_band
*sband
=
5368 wiphy
->bands
[ibss
.channel
->band
];
5370 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
5376 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5377 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
5378 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5381 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5382 connkeys
= nl80211_parse_connkeys(rdev
,
5383 info
->attrs
[NL80211_ATTR_KEYS
]);
5384 if (IS_ERR(connkeys
))
5385 return PTR_ERR(connkeys
);
5389 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
5391 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
5397 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5399 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5400 struct net_device
*dev
= info
->user_ptr
[1];
5402 if (!rdev
->ops
->leave_ibss
)
5405 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5408 return cfg80211_leave_ibss(rdev
, dev
, false);
5411 #ifdef CONFIG_NL80211_TESTMODE
5412 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
5416 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
5418 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5421 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
5425 if (rdev
->ops
->testmode_cmd
) {
5426 rdev
->testmode_info
= info
;
5427 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
5428 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
5429 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
5430 rdev
->testmode_info
= NULL
;
5436 static int nl80211_testmode_dump(struct sk_buff
*skb
,
5437 struct netlink_callback
*cb
)
5439 struct cfg80211_registered_device
*rdev
;
5447 * 0 is a valid index, but not valid for args[0],
5448 * so we need to offset by 1.
5450 phy_idx
= cb
->args
[0] - 1;
5452 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
5453 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
5458 mutex_lock(&cfg80211_mutex
);
5459 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
5460 nl80211_fam
.attrbuf
);
5462 mutex_unlock(&cfg80211_mutex
);
5463 return PTR_ERR(rdev
);
5465 phy_idx
= rdev
->wiphy_idx
;
5467 mutex_unlock(&cfg80211_mutex
);
5469 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
5471 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
5475 data
= nla_data((void *)cb
->args
[1]);
5476 data_len
= nla_len((void *)cb
->args
[1]);
5479 mutex_lock(&cfg80211_mutex
);
5480 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
5482 mutex_unlock(&cfg80211_mutex
);
5485 cfg80211_lock_rdev(rdev
);
5486 mutex_unlock(&cfg80211_mutex
);
5488 if (!rdev
->ops
->testmode_dump
) {
5494 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
5495 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5496 NL80211_CMD_TESTMODE
);
5497 struct nlattr
*tmdata
;
5499 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
5500 genlmsg_cancel(skb
, hdr
);
5504 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5506 genlmsg_cancel(skb
, hdr
);
5509 err
= rdev
->ops
->testmode_dump(&rdev
->wiphy
, skb
, cb
,
5511 nla_nest_end(skb
, tmdata
);
5513 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
5514 genlmsg_cancel(skb
, hdr
);
5517 genlmsg_cancel(skb
, hdr
);
5521 genlmsg_end(skb
, hdr
);
5526 cb
->args
[0] = phy_idx
+ 1;
5528 cfg80211_unlock_rdev(rdev
);
5532 static struct sk_buff
*
5533 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
5534 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
5536 struct sk_buff
*skb
;
5538 struct nlattr
*data
;
5540 skb
= nlmsg_new(approxlen
+ 100, gfp
);
5544 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
5550 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
5551 goto nla_put_failure
;
5552 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5554 ((void **)skb
->cb
)[0] = rdev
;
5555 ((void **)skb
->cb
)[1] = hdr
;
5556 ((void **)skb
->cb
)[2] = data
;
5565 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
5568 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5570 if (WARN_ON(!rdev
->testmode_info
))
5573 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
5574 rdev
->testmode_info
->snd_portid
,
5575 rdev
->testmode_info
->snd_seq
,
5578 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
5580 int cfg80211_testmode_reply(struct sk_buff
*skb
)
5582 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
5583 void *hdr
= ((void **)skb
->cb
)[1];
5584 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5586 if (WARN_ON(!rdev
->testmode_info
)) {
5591 nla_nest_end(skb
, data
);
5592 genlmsg_end(skb
, hdr
);
5593 return genlmsg_reply(skb
, rdev
->testmode_info
);
5595 EXPORT_SYMBOL(cfg80211_testmode_reply
);
5597 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
5598 int approxlen
, gfp_t gfp
)
5600 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5602 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
5604 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
5606 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
5608 void *hdr
= ((void **)skb
->cb
)[1];
5609 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5611 nla_nest_end(skb
, data
);
5612 genlmsg_end(skb
, hdr
);
5613 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
5615 EXPORT_SYMBOL(cfg80211_testmode_event
);
5618 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
5620 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5621 struct net_device
*dev
= info
->user_ptr
[1];
5622 struct cfg80211_connect_params connect
;
5623 struct wiphy
*wiphy
;
5624 struct cfg80211_cached_keys
*connkeys
= NULL
;
5627 memset(&connect
, 0, sizeof(connect
));
5629 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5632 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5633 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5636 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5638 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5639 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
5640 NL80211_CMD_CONNECT
))
5643 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5645 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
5647 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
5648 NL80211_MAX_NR_CIPHER_SUITES
);
5652 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5653 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5656 wiphy
= &rdev
->wiphy
;
5658 connect
.bg_scan_period
= -1;
5659 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
5660 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
5661 connect
.bg_scan_period
=
5662 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
5665 if (info
->attrs
[NL80211_ATTR_MAC
])
5666 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5667 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5668 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5670 if (info
->attrs
[NL80211_ATTR_IE
]) {
5671 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5672 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5675 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5677 ieee80211_get_channel(wiphy
,
5678 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5679 if (!connect
.channel
||
5680 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5684 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5685 connkeys
= nl80211_parse_connkeys(rdev
,
5686 info
->attrs
[NL80211_ATTR_KEYS
]);
5687 if (IS_ERR(connkeys
))
5688 return PTR_ERR(connkeys
);
5691 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5692 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
5694 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5695 memcpy(&connect
.ht_capa_mask
,
5696 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
5697 sizeof(connect
.ht_capa_mask
));
5699 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5700 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
5704 memcpy(&connect
.ht_capa
,
5705 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
5706 sizeof(connect
.ht_capa
));
5709 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
5715 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
5717 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5718 struct net_device
*dev
= info
->user_ptr
[1];
5721 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5722 reason
= WLAN_REASON_DEAUTH_LEAVING
;
5724 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5729 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5730 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5733 return cfg80211_disconnect(rdev
, dev
, reason
, true);
5736 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
5738 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5743 if (!info
->attrs
[NL80211_ATTR_PID
])
5746 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
5748 net
= get_net_ns_by_pid(pid
);
5750 return PTR_ERR(net
);
5754 /* check if anything to do */
5755 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
5756 err
= cfg80211_switch_netns(rdev
, net
);
5762 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5764 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5765 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
5766 struct cfg80211_pmksa
*pmksa
) = NULL
;
5767 struct net_device
*dev
= info
->user_ptr
[1];
5768 struct cfg80211_pmksa pmksa
;
5770 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
5772 if (!info
->attrs
[NL80211_ATTR_MAC
])
5775 if (!info
->attrs
[NL80211_ATTR_PMKID
])
5778 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
5779 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5781 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5782 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5785 switch (info
->genlhdr
->cmd
) {
5786 case NL80211_CMD_SET_PMKSA
:
5787 rdev_ops
= rdev
->ops
->set_pmksa
;
5789 case NL80211_CMD_DEL_PMKSA
:
5790 rdev_ops
= rdev
->ops
->del_pmksa
;
5800 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
5803 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5805 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5806 struct net_device
*dev
= info
->user_ptr
[1];
5808 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5809 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5812 if (!rdev
->ops
->flush_pmksa
)
5815 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
5818 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5820 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5821 struct net_device
*dev
= info
->user_ptr
[1];
5822 u8 action_code
, dialog_token
;
5826 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5827 !rdev
->ops
->tdls_mgmt
)
5830 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5831 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5832 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5833 !info
->attrs
[NL80211_ATTR_IE
] ||
5834 !info
->attrs
[NL80211_ATTR_MAC
])
5837 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5838 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5839 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5840 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5842 return rdev
->ops
->tdls_mgmt(&rdev
->wiphy
, dev
, peer
, action_code
,
5843 dialog_token
, status_code
,
5844 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5845 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5848 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5850 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5851 struct net_device
*dev
= info
->user_ptr
[1];
5852 enum nl80211_tdls_operation operation
;
5855 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5856 !rdev
->ops
->tdls_oper
)
5859 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5860 !info
->attrs
[NL80211_ATTR_MAC
])
5863 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5864 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5866 return rdev
->ops
->tdls_oper(&rdev
->wiphy
, dev
, peer
, operation
);
5869 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5870 struct genl_info
*info
)
5872 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5873 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5874 struct ieee80211_channel
*chan
;
5875 struct sk_buff
*msg
;
5878 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5882 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5883 !info
->attrs
[NL80211_ATTR_DURATION
])
5886 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5888 if (!rdev
->ops
->remain_on_channel
||
5889 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
5893 * We should be on that channel for at least a minimum amount of
5894 * time (10ms) but no longer than the driver supports.
5896 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
5897 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5900 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
5901 !nl80211_valid_channel_type(info
, &channel_type
))
5904 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5905 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5909 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5913 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5914 NL80211_CMD_REMAIN_ON_CHANNEL
);
5921 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, wdev
, chan
,
5922 channel_type
, duration
, &cookie
);
5927 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
5928 goto nla_put_failure
;
5930 genlmsg_end(msg
, hdr
);
5932 return genlmsg_reply(msg
, info
);
5941 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5942 struct genl_info
*info
)
5944 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5945 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5948 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5951 if (!rdev
->ops
->cancel_remain_on_channel
)
5954 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5956 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, wdev
, cookie
);
5959 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5960 u8
*rates
, u8 rates_len
)
5965 for (i
= 0; i
< rates_len
; i
++) {
5966 int rate
= (rates
[i
] & 0x7f) * 5;
5968 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5969 struct ieee80211_rate
*srate
=
5970 &sband
->bitrates
[ridx
];
5971 if (rate
== srate
->bitrate
) {
5976 if (ridx
== sband
->n_bitrates
)
5977 return 0; /* rate not found */
5983 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
5984 u8
*rates
, u8 rates_len
,
5985 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
5989 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
5991 for (i
= 0; i
< rates_len
; i
++) {
5994 ridx
= rates
[i
] / 8;
5995 rbit
= BIT(rates
[i
] % 8);
5997 /* check validity */
5998 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
6001 /* check availability */
6002 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
6011 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
6012 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
6013 .len
= NL80211_MAX_SUPP_RATES
},
6014 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
6015 .len
= NL80211_MAX_SUPP_HT_RATES
},
6018 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
6019 struct genl_info
*info
)
6021 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
6022 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6023 struct cfg80211_bitrate_mask mask
;
6025 struct net_device
*dev
= info
->user_ptr
[1];
6026 struct nlattr
*tx_rates
;
6027 struct ieee80211_supported_band
*sband
;
6029 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
6032 if (!rdev
->ops
->set_bitrate_mask
)
6035 memset(&mask
, 0, sizeof(mask
));
6036 /* Default to all rates enabled */
6037 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
6038 sband
= rdev
->wiphy
.bands
[i
];
6039 mask
.control
[i
].legacy
=
6040 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
6042 memcpy(mask
.control
[i
].mcs
,
6043 sband
->ht_cap
.mcs
.rx_mask
,
6044 sizeof(mask
.control
[i
].mcs
));
6046 memset(mask
.control
[i
].mcs
, 0,
6047 sizeof(mask
.control
[i
].mcs
));
6051 * The nested attribute uses enum nl80211_band as the index. This maps
6052 * directly to the enum ieee80211_band values used in cfg80211.
6054 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
6055 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
6057 enum ieee80211_band band
= nla_type(tx_rates
);
6058 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
6060 sband
= rdev
->wiphy
.bands
[band
];
6063 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
6064 nla_len(tx_rates
), nl80211_txattr_policy
);
6065 if (tb
[NL80211_TXRATE_LEGACY
]) {
6066 mask
.control
[band
].legacy
= rateset_to_mask(
6068 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
6069 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
6070 if ((mask
.control
[band
].legacy
== 0) &&
6071 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
6074 if (tb
[NL80211_TXRATE_MCS
]) {
6075 if (!ht_rateset_to_mask(
6077 nla_data(tb
[NL80211_TXRATE_MCS
]),
6078 nla_len(tb
[NL80211_TXRATE_MCS
]),
6079 mask
.control
[band
].mcs
))
6083 if (mask
.control
[band
].legacy
== 0) {
6084 /* don't allow empty legacy rates if HT
6085 * is not even supported. */
6086 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
6089 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
6090 if (mask
.control
[band
].mcs
[i
])
6093 /* legacy and mcs rates may not be both empty */
6094 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
6099 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
6102 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6104 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6105 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6106 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
6108 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
6111 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
6112 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
6114 switch (wdev
->iftype
) {
6115 case NL80211_IFTYPE_STATION
:
6116 case NL80211_IFTYPE_ADHOC
:
6117 case NL80211_IFTYPE_P2P_CLIENT
:
6118 case NL80211_IFTYPE_AP
:
6119 case NL80211_IFTYPE_AP_VLAN
:
6120 case NL80211_IFTYPE_MESH_POINT
:
6121 case NL80211_IFTYPE_P2P_GO
:
6122 case NL80211_IFTYPE_P2P_DEVICE
:
6128 /* not much point in registering if we can't reply */
6129 if (!rdev
->ops
->mgmt_tx
)
6132 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
6133 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
6134 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
6137 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6139 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6140 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6141 struct ieee80211_channel
*chan
;
6142 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6143 bool channel_type_valid
= false;
6148 struct sk_buff
*msg
= NULL
;
6149 unsigned int wait
= 0;
6150 bool offchan
, no_cck
, dont_wait_for_ack
;
6152 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
6154 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
6155 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6158 if (!rdev
->ops
->mgmt_tx
)
6161 switch (wdev
->iftype
) {
6162 case NL80211_IFTYPE_STATION
:
6163 case NL80211_IFTYPE_ADHOC
:
6164 case NL80211_IFTYPE_P2P_CLIENT
:
6165 case NL80211_IFTYPE_AP
:
6166 case NL80211_IFTYPE_AP_VLAN
:
6167 case NL80211_IFTYPE_MESH_POINT
:
6168 case NL80211_IFTYPE_P2P_GO
:
6169 case NL80211_IFTYPE_P2P_DEVICE
:
6175 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
6176 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6178 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6181 * We should wait on the channel for at least a minimum amount
6182 * of time (10ms) but no longer than the driver supports.
6184 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6185 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
6190 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
6191 if (!nl80211_valid_channel_type(info
, &channel_type
))
6193 channel_type_valid
= true;
6196 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
6198 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6201 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6203 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6204 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
6208 if (!dont_wait_for_ack
) {
6209 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6213 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6222 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chan
, offchan
, channel_type
,
6223 channel_type_valid
, wait
,
6224 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
6225 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
6226 no_cck
, dont_wait_for_ack
, &cookie
);
6231 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6232 goto nla_put_failure
;
6234 genlmsg_end(msg
, hdr
);
6235 return genlmsg_reply(msg
, info
);
6247 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
6249 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6250 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6253 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6256 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
6259 switch (wdev
->iftype
) {
6260 case NL80211_IFTYPE_STATION
:
6261 case NL80211_IFTYPE_ADHOC
:
6262 case NL80211_IFTYPE_P2P_CLIENT
:
6263 case NL80211_IFTYPE_AP
:
6264 case NL80211_IFTYPE_AP_VLAN
:
6265 case NL80211_IFTYPE_P2P_GO
:
6266 case NL80211_IFTYPE_P2P_DEVICE
:
6272 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6274 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, wdev
, cookie
);
6277 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6279 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6280 struct wireless_dev
*wdev
;
6281 struct net_device
*dev
= info
->user_ptr
[1];
6286 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
6289 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
6291 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
6294 wdev
= dev
->ieee80211_ptr
;
6296 if (!rdev
->ops
->set_power_mgmt
)
6299 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
6301 if (state
== wdev
->ps
)
6304 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
6311 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6313 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6314 enum nl80211_ps_state ps_state
;
6315 struct wireless_dev
*wdev
;
6316 struct net_device
*dev
= info
->user_ptr
[1];
6317 struct sk_buff
*msg
;
6321 wdev
= dev
->ieee80211_ptr
;
6323 if (!rdev
->ops
->set_power_mgmt
)
6326 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6330 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6331 NL80211_CMD_GET_POWER_SAVE
);
6338 ps_state
= NL80211_PS_ENABLED
;
6340 ps_state
= NL80211_PS_DISABLED
;
6342 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
6343 goto nla_put_failure
;
6345 genlmsg_end(msg
, hdr
);
6346 return genlmsg_reply(msg
, info
);
6355 static struct nla_policy
6356 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
6357 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
6358 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
6359 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
6360 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
6361 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
6362 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
6365 static int nl80211_set_cqm_txe(struct genl_info
*info
,
6366 u32 rate
, u32 pkts
, u32 intvl
)
6368 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6369 struct wireless_dev
*wdev
;
6370 struct net_device
*dev
= info
->user_ptr
[1];
6372 if ((rate
< 0 || rate
> 100) ||
6373 (intvl
< 0 || intvl
> NL80211_CQM_TXE_MAX_INTVL
))
6376 wdev
= dev
->ieee80211_ptr
;
6378 if (!rdev
->ops
->set_cqm_txe_config
)
6381 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6382 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6385 return rdev
->ops
->set_cqm_txe_config(wdev
->wiphy
, dev
,
6389 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
6390 s32 threshold
, u32 hysteresis
)
6392 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6393 struct wireless_dev
*wdev
;
6394 struct net_device
*dev
= info
->user_ptr
[1];
6399 wdev
= dev
->ieee80211_ptr
;
6401 if (!rdev
->ops
->set_cqm_rssi_config
)
6404 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6405 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6408 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
6409 threshold
, hysteresis
);
6412 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
6414 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
6418 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
6424 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
6425 nl80211_attr_cqm_policy
);
6429 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
6430 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
6433 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
6434 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
6435 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
6436 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
6437 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
6438 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
6439 u32 rate
, pkts
, intvl
;
6440 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
6441 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
6442 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
6443 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
6451 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6453 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6454 struct net_device
*dev
= info
->user_ptr
[1];
6455 struct mesh_config cfg
;
6456 struct mesh_setup setup
;
6459 /* start with default */
6460 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
6461 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
6463 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
6464 /* and parse parameters if given */
6465 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
6470 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
6471 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
6474 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6475 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6477 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6478 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
6479 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6482 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
6483 /* parse additional setup parameters if given */
6484 err
= nl80211_parse_mesh_setup(info
, &setup
);
6489 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6490 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6492 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
6493 !nl80211_valid_channel_type(info
, &channel_type
))
6496 setup
.channel
= rdev_freq_to_chan(rdev
,
6497 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
6501 setup
.channel_type
= channel_type
;
6503 /* cfg80211_join_mesh() will sort it out */
6504 setup
.channel
= NULL
;
6507 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
6510 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6512 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6513 struct net_device
*dev
= info
->user_ptr
[1];
6515 return cfg80211_leave_mesh(rdev
, dev
);
6519 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6521 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6522 struct sk_buff
*msg
;
6525 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6528 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6532 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6533 NL80211_CMD_GET_WOWLAN
);
6535 goto nla_put_failure
;
6538 struct nlattr
*nl_wowlan
;
6540 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
6542 goto nla_put_failure
;
6544 if ((rdev
->wowlan
->any
&&
6545 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
6546 (rdev
->wowlan
->disconnect
&&
6547 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
6548 (rdev
->wowlan
->magic_pkt
&&
6549 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
6550 (rdev
->wowlan
->gtk_rekey_failure
&&
6551 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
6552 (rdev
->wowlan
->eap_identity_req
&&
6553 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
6554 (rdev
->wowlan
->four_way_handshake
&&
6555 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
6556 (rdev
->wowlan
->rfkill_release
&&
6557 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
6558 goto nla_put_failure
;
6559 if (rdev
->wowlan
->n_patterns
) {
6560 struct nlattr
*nl_pats
, *nl_pat
;
6563 nl_pats
= nla_nest_start(msg
,
6564 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
6566 goto nla_put_failure
;
6568 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
6569 nl_pat
= nla_nest_start(msg
, i
+ 1);
6571 goto nla_put_failure
;
6572 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
6573 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
6574 DIV_ROUND_UP(pat_len
, 8),
6575 rdev
->wowlan
->patterns
[i
].mask
) ||
6576 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
6578 rdev
->wowlan
->patterns
[i
].pattern
))
6579 goto nla_put_failure
;
6580 nla_nest_end(msg
, nl_pat
);
6582 nla_nest_end(msg
, nl_pats
);
6585 nla_nest_end(msg
, nl_wowlan
);
6588 genlmsg_end(msg
, hdr
);
6589 return genlmsg_reply(msg
, info
);
6596 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6598 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6599 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
6600 struct cfg80211_wowlan new_triggers
= {};
6601 struct cfg80211_wowlan
*ntrig
;
6602 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
6604 bool prev_enabled
= rdev
->wowlan
;
6606 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6609 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
6610 cfg80211_rdev_free_wowlan(rdev
);
6611 rdev
->wowlan
= NULL
;
6615 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
6616 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6617 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6618 nl80211_wowlan_policy
);
6622 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
6623 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
6625 new_triggers
.any
= true;
6628 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
6629 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
6631 new_triggers
.disconnect
= true;
6634 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
6635 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
6637 new_triggers
.magic_pkt
= true;
6640 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
6643 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
6644 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
6646 new_triggers
.gtk_rekey_failure
= true;
6649 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
6650 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
6652 new_triggers
.eap_identity_req
= true;
6655 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
6656 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
6658 new_triggers
.four_way_handshake
= true;
6661 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
6662 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
6664 new_triggers
.rfkill_release
= true;
6667 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
6670 int rem
, pat_len
, mask_len
;
6671 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
6673 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6676 if (n_patterns
> wowlan
->n_patterns
)
6679 new_triggers
.patterns
= kcalloc(n_patterns
,
6680 sizeof(new_triggers
.patterns
[0]),
6682 if (!new_triggers
.patterns
)
6685 new_triggers
.n_patterns
= n_patterns
;
6688 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6690 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
6691 nla_data(pat
), nla_len(pat
), NULL
);
6693 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
6694 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
6696 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
6697 mask_len
= DIV_ROUND_UP(pat_len
, 8);
6698 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
6701 if (pat_len
> wowlan
->pattern_max_len
||
6702 pat_len
< wowlan
->pattern_min_len
)
6705 new_triggers
.patterns
[i
].mask
=
6706 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
6707 if (!new_triggers
.patterns
[i
].mask
) {
6711 new_triggers
.patterns
[i
].pattern
=
6712 new_triggers
.patterns
[i
].mask
+ mask_len
;
6713 memcpy(new_triggers
.patterns
[i
].mask
,
6714 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
6716 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
6717 memcpy(new_triggers
.patterns
[i
].pattern
,
6718 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
6724 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
6729 cfg80211_rdev_free_wowlan(rdev
);
6730 rdev
->wowlan
= ntrig
;
6733 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
6734 rdev
->ops
->set_wakeup(&rdev
->wiphy
, rdev
->wowlan
);
6738 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
6739 kfree(new_triggers
.patterns
[i
].mask
);
6740 kfree(new_triggers
.patterns
);
6745 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
6747 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6748 struct net_device
*dev
= info
->user_ptr
[1];
6749 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6750 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
6751 struct cfg80211_gtk_rekey_data rekey_data
;
6754 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
6757 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
6758 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6759 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6760 nl80211_rekey_policy
);
6764 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
6766 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
6768 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
6771 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
6773 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
6775 memcpy(rekey_data
.replay_ctr
,
6776 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
6777 NL80211_REPLAY_CTR_LEN
);
6780 if (!wdev
->current_bss
) {
6785 if (!rdev
->ops
->set_rekey_data
) {
6790 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
6796 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
6797 struct genl_info
*info
)
6799 struct net_device
*dev
= info
->user_ptr
[1];
6800 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6802 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6803 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6806 if (wdev
->ap_unexpected_nlportid
)
6809 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
6813 static int nl80211_probe_client(struct sk_buff
*skb
,
6814 struct genl_info
*info
)
6816 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6817 struct net_device
*dev
= info
->user_ptr
[1];
6818 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6819 struct sk_buff
*msg
;
6825 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6826 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6829 if (!info
->attrs
[NL80211_ATTR_MAC
])
6832 if (!rdev
->ops
->probe_client
)
6835 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6839 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6840 NL80211_CMD_PROBE_CLIENT
);
6847 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6849 err
= rdev
->ops
->probe_client(&rdev
->wiphy
, dev
, addr
, &cookie
);
6853 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6854 goto nla_put_failure
;
6856 genlmsg_end(msg
, hdr
);
6858 return genlmsg_reply(msg
, info
);
6867 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
6869 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6871 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
6874 if (rdev
->ap_beacons_nlportid
)
6877 rdev
->ap_beacons_nlportid
= info
->snd_portid
;
6882 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
6884 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6885 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6888 if (!rdev
->ops
->start_p2p_device
)
6891 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
6894 if (wdev
->p2p_started
)
6897 mutex_lock(&rdev
->devlist_mtx
);
6898 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
6899 mutex_unlock(&rdev
->devlist_mtx
);
6903 err
= rdev
->ops
->start_p2p_device(&rdev
->wiphy
, wdev
);
6907 wdev
->p2p_started
= true;
6908 mutex_lock(&rdev
->devlist_mtx
);
6910 mutex_unlock(&rdev
->devlist_mtx
);
6915 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
6917 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6918 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6920 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
6923 if (!rdev
->ops
->stop_p2p_device
)
6926 if (!wdev
->p2p_started
)
6929 rdev
->ops
->stop_p2p_device(&rdev
->wiphy
, wdev
);
6930 wdev
->p2p_started
= false;
6932 mutex_lock(&rdev
->devlist_mtx
);
6934 mutex_unlock(&rdev
->devlist_mtx
);
6936 if (WARN_ON(rdev
->scan_req
&& rdev
->scan_req
->wdev
== wdev
)) {
6937 rdev
->scan_req
->aborted
= true;
6938 ___cfg80211_scan_done(rdev
, true);
6944 #define NL80211_FLAG_NEED_WIPHY 0x01
6945 #define NL80211_FLAG_NEED_NETDEV 0x02
6946 #define NL80211_FLAG_NEED_RTNL 0x04
6947 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6948 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6949 NL80211_FLAG_CHECK_NETDEV_UP)
6950 #define NL80211_FLAG_NEED_WDEV 0x10
6951 /* If a netdev is associated, it must be UP, P2P must be started */
6952 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6953 NL80211_FLAG_CHECK_NETDEV_UP)
6955 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6956 struct genl_info
*info
)
6958 struct cfg80211_registered_device
*rdev
;
6959 struct wireless_dev
*wdev
;
6960 struct net_device
*dev
;
6961 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
6966 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
6967 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6971 return PTR_ERR(rdev
);
6973 info
->user_ptr
[0] = rdev
;
6974 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
6975 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
6976 mutex_lock(&cfg80211_mutex
);
6977 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
6980 mutex_unlock(&cfg80211_mutex
);
6983 return PTR_ERR(wdev
);
6987 rdev
= wiphy_to_dev(wdev
->wiphy
);
6989 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
6991 mutex_unlock(&cfg80211_mutex
);
6997 info
->user_ptr
[1] = dev
;
6999 info
->user_ptr
[1] = wdev
;
7003 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
7004 !netif_running(dev
)) {
7005 mutex_unlock(&cfg80211_mutex
);
7012 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
7013 if (!wdev
->p2p_started
) {
7014 mutex_unlock(&cfg80211_mutex
);
7021 cfg80211_lock_rdev(rdev
);
7023 mutex_unlock(&cfg80211_mutex
);
7025 info
->user_ptr
[0] = rdev
;
7031 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
7032 struct genl_info
*info
)
7034 if (info
->user_ptr
[0])
7035 cfg80211_unlock_rdev(info
->user_ptr
[0]);
7036 if (info
->user_ptr
[1]) {
7037 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
7038 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7041 dev_put(wdev
->netdev
);
7043 dev_put(info
->user_ptr
[1]);
7046 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
7050 static struct genl_ops nl80211_ops
[] = {
7052 .cmd
= NL80211_CMD_GET_WIPHY
,
7053 .doit
= nl80211_get_wiphy
,
7054 .dumpit
= nl80211_dump_wiphy
,
7055 .policy
= nl80211_policy
,
7056 /* can be retrieved by unprivileged users */
7057 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
7060 .cmd
= NL80211_CMD_SET_WIPHY
,
7061 .doit
= nl80211_set_wiphy
,
7062 .policy
= nl80211_policy
,
7063 .flags
= GENL_ADMIN_PERM
,
7064 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
7067 .cmd
= NL80211_CMD_GET_INTERFACE
,
7068 .doit
= nl80211_get_interface
,
7069 .dumpit
= nl80211_dump_interface
,
7070 .policy
= nl80211_policy
,
7071 /* can be retrieved by unprivileged users */
7072 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
7075 .cmd
= NL80211_CMD_SET_INTERFACE
,
7076 .doit
= nl80211_set_interface
,
7077 .policy
= nl80211_policy
,
7078 .flags
= GENL_ADMIN_PERM
,
7079 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7080 NL80211_FLAG_NEED_RTNL
,
7083 .cmd
= NL80211_CMD_NEW_INTERFACE
,
7084 .doit
= nl80211_new_interface
,
7085 .policy
= nl80211_policy
,
7086 .flags
= GENL_ADMIN_PERM
,
7087 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7088 NL80211_FLAG_NEED_RTNL
,
7091 .cmd
= NL80211_CMD_DEL_INTERFACE
,
7092 .doit
= nl80211_del_interface
,
7093 .policy
= nl80211_policy
,
7094 .flags
= GENL_ADMIN_PERM
,
7095 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7096 NL80211_FLAG_NEED_RTNL
,
7099 .cmd
= NL80211_CMD_GET_KEY
,
7100 .doit
= nl80211_get_key
,
7101 .policy
= nl80211_policy
,
7102 .flags
= GENL_ADMIN_PERM
,
7103 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7104 NL80211_FLAG_NEED_RTNL
,
7107 .cmd
= NL80211_CMD_SET_KEY
,
7108 .doit
= nl80211_set_key
,
7109 .policy
= nl80211_policy
,
7110 .flags
= GENL_ADMIN_PERM
,
7111 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7112 NL80211_FLAG_NEED_RTNL
,
7115 .cmd
= NL80211_CMD_NEW_KEY
,
7116 .doit
= nl80211_new_key
,
7117 .policy
= nl80211_policy
,
7118 .flags
= GENL_ADMIN_PERM
,
7119 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7120 NL80211_FLAG_NEED_RTNL
,
7123 .cmd
= NL80211_CMD_DEL_KEY
,
7124 .doit
= nl80211_del_key
,
7125 .policy
= nl80211_policy
,
7126 .flags
= GENL_ADMIN_PERM
,
7127 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7128 NL80211_FLAG_NEED_RTNL
,
7131 .cmd
= NL80211_CMD_SET_BEACON
,
7132 .policy
= nl80211_policy
,
7133 .flags
= GENL_ADMIN_PERM
,
7134 .doit
= nl80211_set_beacon
,
7135 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7136 NL80211_FLAG_NEED_RTNL
,
7139 .cmd
= NL80211_CMD_START_AP
,
7140 .policy
= nl80211_policy
,
7141 .flags
= GENL_ADMIN_PERM
,
7142 .doit
= nl80211_start_ap
,
7143 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7144 NL80211_FLAG_NEED_RTNL
,
7147 .cmd
= NL80211_CMD_STOP_AP
,
7148 .policy
= nl80211_policy
,
7149 .flags
= GENL_ADMIN_PERM
,
7150 .doit
= nl80211_stop_ap
,
7151 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7152 NL80211_FLAG_NEED_RTNL
,
7155 .cmd
= NL80211_CMD_GET_STATION
,
7156 .doit
= nl80211_get_station
,
7157 .dumpit
= nl80211_dump_station
,
7158 .policy
= nl80211_policy
,
7159 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7160 NL80211_FLAG_NEED_RTNL
,
7163 .cmd
= NL80211_CMD_SET_STATION
,
7164 .doit
= nl80211_set_station
,
7165 .policy
= nl80211_policy
,
7166 .flags
= GENL_ADMIN_PERM
,
7167 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7168 NL80211_FLAG_NEED_RTNL
,
7171 .cmd
= NL80211_CMD_NEW_STATION
,
7172 .doit
= nl80211_new_station
,
7173 .policy
= nl80211_policy
,
7174 .flags
= GENL_ADMIN_PERM
,
7175 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7176 NL80211_FLAG_NEED_RTNL
,
7179 .cmd
= NL80211_CMD_DEL_STATION
,
7180 .doit
= nl80211_del_station
,
7181 .policy
= nl80211_policy
,
7182 .flags
= GENL_ADMIN_PERM
,
7183 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7184 NL80211_FLAG_NEED_RTNL
,
7187 .cmd
= NL80211_CMD_GET_MPATH
,
7188 .doit
= nl80211_get_mpath
,
7189 .dumpit
= nl80211_dump_mpath
,
7190 .policy
= nl80211_policy
,
7191 .flags
= GENL_ADMIN_PERM
,
7192 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7193 NL80211_FLAG_NEED_RTNL
,
7196 .cmd
= NL80211_CMD_SET_MPATH
,
7197 .doit
= nl80211_set_mpath
,
7198 .policy
= nl80211_policy
,
7199 .flags
= GENL_ADMIN_PERM
,
7200 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7201 NL80211_FLAG_NEED_RTNL
,
7204 .cmd
= NL80211_CMD_NEW_MPATH
,
7205 .doit
= nl80211_new_mpath
,
7206 .policy
= nl80211_policy
,
7207 .flags
= GENL_ADMIN_PERM
,
7208 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7209 NL80211_FLAG_NEED_RTNL
,
7212 .cmd
= NL80211_CMD_DEL_MPATH
,
7213 .doit
= nl80211_del_mpath
,
7214 .policy
= nl80211_policy
,
7215 .flags
= GENL_ADMIN_PERM
,
7216 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7217 NL80211_FLAG_NEED_RTNL
,
7220 .cmd
= NL80211_CMD_SET_BSS
,
7221 .doit
= nl80211_set_bss
,
7222 .policy
= nl80211_policy
,
7223 .flags
= GENL_ADMIN_PERM
,
7224 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7225 NL80211_FLAG_NEED_RTNL
,
7228 .cmd
= NL80211_CMD_GET_REG
,
7229 .doit
= nl80211_get_reg
,
7230 .policy
= nl80211_policy
,
7231 /* can be retrieved by unprivileged users */
7234 .cmd
= NL80211_CMD_SET_REG
,
7235 .doit
= nl80211_set_reg
,
7236 .policy
= nl80211_policy
,
7237 .flags
= GENL_ADMIN_PERM
,
7240 .cmd
= NL80211_CMD_REQ_SET_REG
,
7241 .doit
= nl80211_req_set_reg
,
7242 .policy
= nl80211_policy
,
7243 .flags
= GENL_ADMIN_PERM
,
7246 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
7247 .doit
= nl80211_get_mesh_config
,
7248 .policy
= nl80211_policy
,
7249 /* can be retrieved by unprivileged users */
7250 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7251 NL80211_FLAG_NEED_RTNL
,
7254 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
7255 .doit
= nl80211_update_mesh_config
,
7256 .policy
= nl80211_policy
,
7257 .flags
= GENL_ADMIN_PERM
,
7258 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7259 NL80211_FLAG_NEED_RTNL
,
7262 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
7263 .doit
= nl80211_trigger_scan
,
7264 .policy
= nl80211_policy
,
7265 .flags
= GENL_ADMIN_PERM
,
7266 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7267 NL80211_FLAG_NEED_RTNL
,
7270 .cmd
= NL80211_CMD_GET_SCAN
,
7271 .policy
= nl80211_policy
,
7272 .dumpit
= nl80211_dump_scan
,
7275 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
7276 .doit
= nl80211_start_sched_scan
,
7277 .policy
= nl80211_policy
,
7278 .flags
= GENL_ADMIN_PERM
,
7279 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7280 NL80211_FLAG_NEED_RTNL
,
7283 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
7284 .doit
= nl80211_stop_sched_scan
,
7285 .policy
= nl80211_policy
,
7286 .flags
= GENL_ADMIN_PERM
,
7287 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7288 NL80211_FLAG_NEED_RTNL
,
7291 .cmd
= NL80211_CMD_AUTHENTICATE
,
7292 .doit
= nl80211_authenticate
,
7293 .policy
= nl80211_policy
,
7294 .flags
= GENL_ADMIN_PERM
,
7295 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7296 NL80211_FLAG_NEED_RTNL
,
7299 .cmd
= NL80211_CMD_ASSOCIATE
,
7300 .doit
= nl80211_associate
,
7301 .policy
= nl80211_policy
,
7302 .flags
= GENL_ADMIN_PERM
,
7303 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7304 NL80211_FLAG_NEED_RTNL
,
7307 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
7308 .doit
= nl80211_deauthenticate
,
7309 .policy
= nl80211_policy
,
7310 .flags
= GENL_ADMIN_PERM
,
7311 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7312 NL80211_FLAG_NEED_RTNL
,
7315 .cmd
= NL80211_CMD_DISASSOCIATE
,
7316 .doit
= nl80211_disassociate
,
7317 .policy
= nl80211_policy
,
7318 .flags
= GENL_ADMIN_PERM
,
7319 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7320 NL80211_FLAG_NEED_RTNL
,
7323 .cmd
= NL80211_CMD_JOIN_IBSS
,
7324 .doit
= nl80211_join_ibss
,
7325 .policy
= nl80211_policy
,
7326 .flags
= GENL_ADMIN_PERM
,
7327 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7328 NL80211_FLAG_NEED_RTNL
,
7331 .cmd
= NL80211_CMD_LEAVE_IBSS
,
7332 .doit
= nl80211_leave_ibss
,
7333 .policy
= nl80211_policy
,
7334 .flags
= GENL_ADMIN_PERM
,
7335 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7336 NL80211_FLAG_NEED_RTNL
,
7338 #ifdef CONFIG_NL80211_TESTMODE
7340 .cmd
= NL80211_CMD_TESTMODE
,
7341 .doit
= nl80211_testmode_do
,
7342 .dumpit
= nl80211_testmode_dump
,
7343 .policy
= nl80211_policy
,
7344 .flags
= GENL_ADMIN_PERM
,
7345 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7346 NL80211_FLAG_NEED_RTNL
,
7350 .cmd
= NL80211_CMD_CONNECT
,
7351 .doit
= nl80211_connect
,
7352 .policy
= nl80211_policy
,
7353 .flags
= GENL_ADMIN_PERM
,
7354 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7355 NL80211_FLAG_NEED_RTNL
,
7358 .cmd
= NL80211_CMD_DISCONNECT
,
7359 .doit
= nl80211_disconnect
,
7360 .policy
= nl80211_policy
,
7361 .flags
= GENL_ADMIN_PERM
,
7362 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7363 NL80211_FLAG_NEED_RTNL
,
7366 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
7367 .doit
= nl80211_wiphy_netns
,
7368 .policy
= nl80211_policy
,
7369 .flags
= GENL_ADMIN_PERM
,
7370 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7371 NL80211_FLAG_NEED_RTNL
,
7374 .cmd
= NL80211_CMD_GET_SURVEY
,
7375 .policy
= nl80211_policy
,
7376 .dumpit
= nl80211_dump_survey
,
7379 .cmd
= NL80211_CMD_SET_PMKSA
,
7380 .doit
= nl80211_setdel_pmksa
,
7381 .policy
= nl80211_policy
,
7382 .flags
= GENL_ADMIN_PERM
,
7383 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7384 NL80211_FLAG_NEED_RTNL
,
7387 .cmd
= NL80211_CMD_DEL_PMKSA
,
7388 .doit
= nl80211_setdel_pmksa
,
7389 .policy
= nl80211_policy
,
7390 .flags
= GENL_ADMIN_PERM
,
7391 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7392 NL80211_FLAG_NEED_RTNL
,
7395 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
7396 .doit
= nl80211_flush_pmksa
,
7397 .policy
= nl80211_policy
,
7398 .flags
= GENL_ADMIN_PERM
,
7399 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7400 NL80211_FLAG_NEED_RTNL
,
7403 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
7404 .doit
= nl80211_remain_on_channel
,
7405 .policy
= nl80211_policy
,
7406 .flags
= GENL_ADMIN_PERM
,
7407 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7408 NL80211_FLAG_NEED_RTNL
,
7411 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7412 .doit
= nl80211_cancel_remain_on_channel
,
7413 .policy
= nl80211_policy
,
7414 .flags
= GENL_ADMIN_PERM
,
7415 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7416 NL80211_FLAG_NEED_RTNL
,
7419 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
7420 .doit
= nl80211_set_tx_bitrate_mask
,
7421 .policy
= nl80211_policy
,
7422 .flags
= GENL_ADMIN_PERM
,
7423 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7424 NL80211_FLAG_NEED_RTNL
,
7427 .cmd
= NL80211_CMD_REGISTER_FRAME
,
7428 .doit
= nl80211_register_mgmt
,
7429 .policy
= nl80211_policy
,
7430 .flags
= GENL_ADMIN_PERM
,
7431 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7432 NL80211_FLAG_NEED_RTNL
,
7435 .cmd
= NL80211_CMD_FRAME
,
7436 .doit
= nl80211_tx_mgmt
,
7437 .policy
= nl80211_policy
,
7438 .flags
= GENL_ADMIN_PERM
,
7439 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7440 NL80211_FLAG_NEED_RTNL
,
7443 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
7444 .doit
= nl80211_tx_mgmt_cancel_wait
,
7445 .policy
= nl80211_policy
,
7446 .flags
= GENL_ADMIN_PERM
,
7447 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7448 NL80211_FLAG_NEED_RTNL
,
7451 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
7452 .doit
= nl80211_set_power_save
,
7453 .policy
= nl80211_policy
,
7454 .flags
= GENL_ADMIN_PERM
,
7455 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7456 NL80211_FLAG_NEED_RTNL
,
7459 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
7460 .doit
= nl80211_get_power_save
,
7461 .policy
= nl80211_policy
,
7462 /* can be retrieved by unprivileged users */
7463 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7464 NL80211_FLAG_NEED_RTNL
,
7467 .cmd
= NL80211_CMD_SET_CQM
,
7468 .doit
= nl80211_set_cqm
,
7469 .policy
= nl80211_policy
,
7470 .flags
= GENL_ADMIN_PERM
,
7471 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7472 NL80211_FLAG_NEED_RTNL
,
7475 .cmd
= NL80211_CMD_SET_CHANNEL
,
7476 .doit
= nl80211_set_channel
,
7477 .policy
= nl80211_policy
,
7478 .flags
= GENL_ADMIN_PERM
,
7479 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7480 NL80211_FLAG_NEED_RTNL
,
7483 .cmd
= NL80211_CMD_SET_WDS_PEER
,
7484 .doit
= nl80211_set_wds_peer
,
7485 .policy
= nl80211_policy
,
7486 .flags
= GENL_ADMIN_PERM
,
7487 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7488 NL80211_FLAG_NEED_RTNL
,
7491 .cmd
= NL80211_CMD_JOIN_MESH
,
7492 .doit
= nl80211_join_mesh
,
7493 .policy
= nl80211_policy
,
7494 .flags
= GENL_ADMIN_PERM
,
7495 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7496 NL80211_FLAG_NEED_RTNL
,
7499 .cmd
= NL80211_CMD_LEAVE_MESH
,
7500 .doit
= nl80211_leave_mesh
,
7501 .policy
= nl80211_policy
,
7502 .flags
= GENL_ADMIN_PERM
,
7503 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7504 NL80211_FLAG_NEED_RTNL
,
7508 .cmd
= NL80211_CMD_GET_WOWLAN
,
7509 .doit
= nl80211_get_wowlan
,
7510 .policy
= nl80211_policy
,
7511 /* can be retrieved by unprivileged users */
7512 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7513 NL80211_FLAG_NEED_RTNL
,
7516 .cmd
= NL80211_CMD_SET_WOWLAN
,
7517 .doit
= nl80211_set_wowlan
,
7518 .policy
= nl80211_policy
,
7519 .flags
= GENL_ADMIN_PERM
,
7520 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7521 NL80211_FLAG_NEED_RTNL
,
7525 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
7526 .doit
= nl80211_set_rekey_data
,
7527 .policy
= nl80211_policy
,
7528 .flags
= GENL_ADMIN_PERM
,
7529 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7530 NL80211_FLAG_NEED_RTNL
,
7533 .cmd
= NL80211_CMD_TDLS_MGMT
,
7534 .doit
= nl80211_tdls_mgmt
,
7535 .policy
= nl80211_policy
,
7536 .flags
= GENL_ADMIN_PERM
,
7537 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7538 NL80211_FLAG_NEED_RTNL
,
7541 .cmd
= NL80211_CMD_TDLS_OPER
,
7542 .doit
= nl80211_tdls_oper
,
7543 .policy
= nl80211_policy
,
7544 .flags
= GENL_ADMIN_PERM
,
7545 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7546 NL80211_FLAG_NEED_RTNL
,
7549 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
7550 .doit
= nl80211_register_unexpected_frame
,
7551 .policy
= nl80211_policy
,
7552 .flags
= GENL_ADMIN_PERM
,
7553 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7554 NL80211_FLAG_NEED_RTNL
,
7557 .cmd
= NL80211_CMD_PROBE_CLIENT
,
7558 .doit
= nl80211_probe_client
,
7559 .policy
= nl80211_policy
,
7560 .flags
= GENL_ADMIN_PERM
,
7561 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7562 NL80211_FLAG_NEED_RTNL
,
7565 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
7566 .doit
= nl80211_register_beacons
,
7567 .policy
= nl80211_policy
,
7568 .flags
= GENL_ADMIN_PERM
,
7569 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7570 NL80211_FLAG_NEED_RTNL
,
7573 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
7574 .doit
= nl80211_set_noack_map
,
7575 .policy
= nl80211_policy
,
7576 .flags
= GENL_ADMIN_PERM
,
7577 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7578 NL80211_FLAG_NEED_RTNL
,
7581 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
7582 .doit
= nl80211_start_p2p_device
,
7583 .policy
= nl80211_policy
,
7584 .flags
= GENL_ADMIN_PERM
,
7585 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7586 NL80211_FLAG_NEED_RTNL
,
7589 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
7590 .doit
= nl80211_stop_p2p_device
,
7591 .policy
= nl80211_policy
,
7592 .flags
= GENL_ADMIN_PERM
,
7593 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7594 NL80211_FLAG_NEED_RTNL
,
7598 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
7602 /* multicast groups */
7603 static struct genl_multicast_group nl80211_config_mcgrp
= {
7606 static struct genl_multicast_group nl80211_scan_mcgrp
= {
7609 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
7610 .name
= "regulatory",
7613 /* notification functions */
7615 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
7617 struct sk_buff
*msg
;
7619 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7623 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
7628 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7629 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
7632 static int nl80211_add_scan_req(struct sk_buff
*msg
,
7633 struct cfg80211_registered_device
*rdev
)
7635 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
7636 struct nlattr
*nest
;
7639 ASSERT_RDEV_LOCK(rdev
);
7644 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
7646 goto nla_put_failure
;
7647 for (i
= 0; i
< req
->n_ssids
; i
++) {
7648 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
7649 goto nla_put_failure
;
7651 nla_nest_end(msg
, nest
);
7653 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
7655 goto nla_put_failure
;
7656 for (i
= 0; i
< req
->n_channels
; i
++) {
7657 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
7658 goto nla_put_failure
;
7660 nla_nest_end(msg
, nest
);
7663 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
7664 goto nla_put_failure
;
7671 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
7672 struct cfg80211_registered_device
*rdev
,
7673 struct wireless_dev
*wdev
,
7674 u32 portid
, u32 seq
, int flags
,
7679 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
7683 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7684 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
7685 wdev
->netdev
->ifindex
)) ||
7686 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
7687 goto nla_put_failure
;
7689 /* ignore errors and send incomplete event anyway */
7690 nl80211_add_scan_req(msg
, rdev
);
7692 return genlmsg_end(msg
, hdr
);
7695 genlmsg_cancel(msg
, hdr
);
7700 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
7701 struct cfg80211_registered_device
*rdev
,
7702 struct net_device
*netdev
,
7703 u32 portid
, u32 seq
, int flags
, u32 cmd
)
7707 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
7711 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7712 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7713 goto nla_put_failure
;
7715 return genlmsg_end(msg
, hdr
);
7718 genlmsg_cancel(msg
, hdr
);
7722 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
7723 struct wireless_dev
*wdev
)
7725 struct sk_buff
*msg
;
7727 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7731 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7732 NL80211_CMD_TRIGGER_SCAN
) < 0) {
7737 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7738 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7741 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
7742 struct wireless_dev
*wdev
)
7744 struct sk_buff
*msg
;
7746 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7750 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7751 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
7756 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7757 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7760 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
7761 struct wireless_dev
*wdev
)
7763 struct sk_buff
*msg
;
7765 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7769 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7770 NL80211_CMD_SCAN_ABORTED
) < 0) {
7775 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7776 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7779 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
7780 struct net_device
*netdev
)
7782 struct sk_buff
*msg
;
7784 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7788 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7789 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
7794 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7795 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7798 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
7799 struct net_device
*netdev
, u32 cmd
)
7801 struct sk_buff
*msg
;
7803 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7807 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
7812 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7813 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7817 * This can happen on global regulatory changes or device specific settings
7818 * based on custom world regulatory domains.
7820 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
7822 struct sk_buff
*msg
;
7825 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7829 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
7835 /* Userspace can always count this one always being set */
7836 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
7837 goto nla_put_failure
;
7839 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
7840 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7841 NL80211_REGDOM_TYPE_WORLD
))
7842 goto nla_put_failure
;
7843 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
7844 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7845 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
7846 goto nla_put_failure
;
7847 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
7848 request
->intersect
) {
7849 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7850 NL80211_REGDOM_TYPE_INTERSECTION
))
7851 goto nla_put_failure
;
7853 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7854 NL80211_REGDOM_TYPE_COUNTRY
) ||
7855 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
7857 goto nla_put_failure
;
7860 if (wiphy_idx_valid(request
->wiphy_idx
) &&
7861 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
7862 goto nla_put_failure
;
7864 genlmsg_end(msg
, hdr
);
7867 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7874 genlmsg_cancel(msg
, hdr
);
7878 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
7879 struct net_device
*netdev
,
7880 const u8
*buf
, size_t len
,
7881 enum nl80211_commands cmd
, gfp_t gfp
)
7883 struct sk_buff
*msg
;
7886 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7890 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7896 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7897 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7898 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
7899 goto nla_put_failure
;
7901 genlmsg_end(msg
, hdr
);
7903 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7904 nl80211_mlme_mcgrp
.id
, gfp
);
7908 genlmsg_cancel(msg
, hdr
);
7912 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
7913 struct net_device
*netdev
, const u8
*buf
,
7914 size_t len
, gfp_t gfp
)
7916 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7917 NL80211_CMD_AUTHENTICATE
, gfp
);
7920 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
7921 struct net_device
*netdev
, const u8
*buf
,
7922 size_t len
, gfp_t gfp
)
7924 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7925 NL80211_CMD_ASSOCIATE
, gfp
);
7928 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
7929 struct net_device
*netdev
, const u8
*buf
,
7930 size_t len
, gfp_t gfp
)
7932 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7933 NL80211_CMD_DEAUTHENTICATE
, gfp
);
7936 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
7937 struct net_device
*netdev
, const u8
*buf
,
7938 size_t len
, gfp_t gfp
)
7940 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7941 NL80211_CMD_DISASSOCIATE
, gfp
);
7944 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
7945 struct net_device
*netdev
, const u8
*buf
,
7946 size_t len
, gfp_t gfp
)
7948 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7949 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
7952 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
7953 struct net_device
*netdev
, const u8
*buf
,
7954 size_t len
, gfp_t gfp
)
7956 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7957 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
7960 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
7961 struct net_device
*netdev
, int cmd
,
7962 const u8
*addr
, gfp_t gfp
)
7964 struct sk_buff
*msg
;
7967 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7971 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7977 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7978 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7979 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
7980 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
7981 goto nla_put_failure
;
7983 genlmsg_end(msg
, hdr
);
7985 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7986 nl80211_mlme_mcgrp
.id
, gfp
);
7990 genlmsg_cancel(msg
, hdr
);
7994 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
7995 struct net_device
*netdev
, const u8
*addr
,
7998 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
8002 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
8003 struct net_device
*netdev
, const u8
*addr
,
8006 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
8010 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
8011 struct net_device
*netdev
, const u8
*bssid
,
8012 const u8
*req_ie
, size_t req_ie_len
,
8013 const u8
*resp_ie
, size_t resp_ie_len
,
8014 u16 status
, gfp_t gfp
)
8016 struct sk_buff
*msg
;
8019 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8023 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
8029 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8030 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8031 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
8032 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
8034 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8036 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8037 goto nla_put_failure
;
8039 genlmsg_end(msg
, hdr
);
8041 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8042 nl80211_mlme_mcgrp
.id
, gfp
);
8046 genlmsg_cancel(msg
, hdr
);
8051 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
8052 struct net_device
*netdev
, const u8
*bssid
,
8053 const u8
*req_ie
, size_t req_ie_len
,
8054 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
8056 struct sk_buff
*msg
;
8059 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8063 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
8069 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8070 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8071 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
8073 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8075 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8076 goto nla_put_failure
;
8078 genlmsg_end(msg
, hdr
);
8080 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8081 nl80211_mlme_mcgrp
.id
, gfp
);
8085 genlmsg_cancel(msg
, hdr
);
8090 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
8091 struct net_device
*netdev
, u16 reason
,
8092 const u8
*ie
, size_t ie_len
, bool from_ap
)
8094 struct sk_buff
*msg
;
8097 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8101 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
8107 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8108 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8109 (from_ap
&& reason
&&
8110 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
8112 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
8113 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
8114 goto nla_put_failure
;
8116 genlmsg_end(msg
, hdr
);
8118 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8119 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
8123 genlmsg_cancel(msg
, hdr
);
8128 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
8129 struct net_device
*netdev
, const u8
*bssid
,
8132 struct sk_buff
*msg
;
8135 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8139 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
8145 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8146 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8147 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8148 goto nla_put_failure
;
8150 genlmsg_end(msg
, hdr
);
8152 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8153 nl80211_mlme_mcgrp
.id
, gfp
);
8157 genlmsg_cancel(msg
, hdr
);
8161 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
8162 struct net_device
*netdev
,
8163 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
8166 struct sk_buff
*msg
;
8169 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8173 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
8179 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8180 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8181 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
) ||
8183 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
8184 goto nla_put_failure
;
8186 genlmsg_end(msg
, hdr
);
8188 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8189 nl80211_mlme_mcgrp
.id
, gfp
);
8193 genlmsg_cancel(msg
, hdr
);
8197 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
8198 struct net_device
*netdev
, const u8
*addr
,
8199 enum nl80211_key_type key_type
, int key_id
,
8200 const u8
*tsc
, gfp_t gfp
)
8202 struct sk_buff
*msg
;
8205 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8209 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
8215 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8216 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8217 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
8218 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
8220 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
8221 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
8222 goto nla_put_failure
;
8224 genlmsg_end(msg
, hdr
);
8226 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8227 nl80211_mlme_mcgrp
.id
, gfp
);
8231 genlmsg_cancel(msg
, hdr
);
8235 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
8236 struct ieee80211_channel
*channel_before
,
8237 struct ieee80211_channel
*channel_after
)
8239 struct sk_buff
*msg
;
8241 struct nlattr
*nl_freq
;
8243 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
8247 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
8254 * Since we are applying the beacon hint to a wiphy we know its
8255 * wiphy_idx is valid
8257 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
8258 goto nla_put_failure
;
8261 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
8263 goto nla_put_failure
;
8264 if (nl80211_msg_put_channel(msg
, channel_before
))
8265 goto nla_put_failure
;
8266 nla_nest_end(msg
, nl_freq
);
8269 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
8271 goto nla_put_failure
;
8272 if (nl80211_msg_put_channel(msg
, channel_after
))
8273 goto nla_put_failure
;
8274 nla_nest_end(msg
, nl_freq
);
8276 genlmsg_end(msg
, hdr
);
8279 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
8286 genlmsg_cancel(msg
, hdr
);
8290 static void nl80211_send_remain_on_chan_event(
8291 int cmd
, struct cfg80211_registered_device
*rdev
,
8292 struct wireless_dev
*wdev
, u64 cookie
,
8293 struct ieee80211_channel
*chan
,
8294 enum nl80211_channel_type channel_type
,
8295 unsigned int duration
, gfp_t gfp
)
8297 struct sk_buff
*msg
;
8300 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8304 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8310 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8311 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8312 wdev
->netdev
->ifindex
)) ||
8313 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
8314 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
8315 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
) ||
8316 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8317 goto nla_put_failure
;
8319 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
8320 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
8321 goto nla_put_failure
;
8323 genlmsg_end(msg
, hdr
);
8325 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8326 nl80211_mlme_mcgrp
.id
, gfp
);
8330 genlmsg_cancel(msg
, hdr
);
8334 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
8335 struct wireless_dev
*wdev
, u64 cookie
,
8336 struct ieee80211_channel
*chan
,
8337 enum nl80211_channel_type channel_type
,
8338 unsigned int duration
, gfp_t gfp
)
8340 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
8341 rdev
, wdev
, cookie
, chan
,
8342 channel_type
, duration
, gfp
);
8345 void nl80211_send_remain_on_channel_cancel(
8346 struct cfg80211_registered_device
*rdev
,
8347 struct wireless_dev
*wdev
,
8348 u64 cookie
, struct ieee80211_channel
*chan
,
8349 enum nl80211_channel_type channel_type
, gfp_t gfp
)
8351 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8352 rdev
, wdev
, cookie
, chan
,
8353 channel_type
, 0, gfp
);
8356 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
8357 struct net_device
*dev
, const u8
*mac_addr
,
8358 struct station_info
*sinfo
, gfp_t gfp
)
8360 struct sk_buff
*msg
;
8362 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8366 if (nl80211_send_station(msg
, 0, 0, 0,
8367 rdev
, dev
, mac_addr
, sinfo
) < 0) {
8372 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8373 nl80211_mlme_mcgrp
.id
, gfp
);
8376 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
8377 struct net_device
*dev
, const u8
*mac_addr
,
8380 struct sk_buff
*msg
;
8383 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8387 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
8393 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8394 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
8395 goto nla_put_failure
;
8397 genlmsg_end(msg
, hdr
);
8399 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8400 nl80211_mlme_mcgrp
.id
, gfp
);
8404 genlmsg_cancel(msg
, hdr
);
8408 void nl80211_send_conn_failed_event(struct cfg80211_registered_device
*rdev
,
8409 struct net_device
*dev
, const u8
*mac_addr
,
8410 enum nl80211_connect_failed_reason reason
,
8413 struct sk_buff
*msg
;
8416 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8420 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
8426 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8427 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
8428 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
8429 goto nla_put_failure
;
8431 genlmsg_end(msg
, hdr
);
8433 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8434 nl80211_mlme_mcgrp
.id
, gfp
);
8438 genlmsg_cancel(msg
, hdr
);
8442 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
8443 const u8
*addr
, gfp_t gfp
)
8445 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8446 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8447 struct sk_buff
*msg
;
8450 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
8455 msg
= nlmsg_new(100, gfp
);
8459 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8465 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8466 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8467 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8468 goto nla_put_failure
;
8470 err
= genlmsg_end(msg
, hdr
);
8476 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8480 genlmsg_cancel(msg
, hdr
);
8485 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
8487 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
8491 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
8492 const u8
*addr
, gfp_t gfp
)
8494 return __nl80211_unexpected_frame(dev
,
8495 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
8499 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
8500 struct wireless_dev
*wdev
, u32 nlportid
,
8501 int freq
, int sig_dbm
,
8502 const u8
*buf
, size_t len
, gfp_t gfp
)
8504 struct net_device
*netdev
= wdev
->netdev
;
8505 struct sk_buff
*msg
;
8508 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8512 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8518 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8519 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8520 netdev
->ifindex
)) ||
8521 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8523 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8524 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8525 goto nla_put_failure
;
8527 genlmsg_end(msg
, hdr
);
8529 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8532 genlmsg_cancel(msg
, hdr
);
8537 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
8538 struct wireless_dev
*wdev
, u64 cookie
,
8539 const u8
*buf
, size_t len
, bool ack
,
8542 struct net_device
*netdev
= wdev
->netdev
;
8543 struct sk_buff
*msg
;
8546 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8550 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
8556 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8557 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8558 netdev
->ifindex
)) ||
8559 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
8560 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8561 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8562 goto nla_put_failure
;
8564 genlmsg_end(msg
, hdr
);
8566 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
8570 genlmsg_cancel(msg
, hdr
);
8575 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
8576 struct net_device
*netdev
,
8577 enum nl80211_cqm_rssi_threshold_event rssi_event
,
8580 struct sk_buff
*msg
;
8581 struct nlattr
*pinfoattr
;
8584 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8588 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8594 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8595 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8596 goto nla_put_failure
;
8598 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8600 goto nla_put_failure
;
8602 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
8604 goto nla_put_failure
;
8606 nla_nest_end(msg
, pinfoattr
);
8608 genlmsg_end(msg
, hdr
);
8610 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8611 nl80211_mlme_mcgrp
.id
, gfp
);
8615 genlmsg_cancel(msg
, hdr
);
8619 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
8620 struct net_device
*netdev
, const u8
*bssid
,
8621 const u8
*replay_ctr
, gfp_t gfp
)
8623 struct sk_buff
*msg
;
8624 struct nlattr
*rekey_attr
;
8627 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8631 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8637 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8638 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8639 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8640 goto nla_put_failure
;
8642 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8644 goto nla_put_failure
;
8646 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
8647 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
8648 goto nla_put_failure
;
8650 nla_nest_end(msg
, rekey_attr
);
8652 genlmsg_end(msg
, hdr
);
8654 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8655 nl80211_mlme_mcgrp
.id
, gfp
);
8659 genlmsg_cancel(msg
, hdr
);
8663 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
8664 struct net_device
*netdev
, int index
,
8665 const u8
*bssid
, bool preauth
, gfp_t gfp
)
8667 struct sk_buff
*msg
;
8668 struct nlattr
*attr
;
8671 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8675 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
8681 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8682 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8683 goto nla_put_failure
;
8685 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
8687 goto nla_put_failure
;
8689 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
8690 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
8692 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
8693 goto nla_put_failure
;
8695 nla_nest_end(msg
, attr
);
8697 genlmsg_end(msg
, hdr
);
8699 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8700 nl80211_mlme_mcgrp
.id
, gfp
);
8704 genlmsg_cancel(msg
, hdr
);
8708 void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
8709 struct net_device
*netdev
, int freq
,
8710 enum nl80211_channel_type type
, gfp_t gfp
)
8712 struct sk_buff
*msg
;
8715 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8719 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
8725 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8726 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8727 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, type
))
8728 goto nla_put_failure
;
8730 genlmsg_end(msg
, hdr
);
8732 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8733 nl80211_mlme_mcgrp
.id
, gfp
);
8737 genlmsg_cancel(msg
, hdr
);
8742 nl80211_send_cqm_txe_notify(struct cfg80211_registered_device
*rdev
,
8743 struct net_device
*netdev
, const u8
*peer
,
8744 u32 num_packets
, u32 rate
, u32 intvl
, gfp_t gfp
)
8746 struct sk_buff
*msg
;
8747 struct nlattr
*pinfoattr
;
8750 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8754 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8760 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8761 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8762 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8763 goto nla_put_failure
;
8765 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8767 goto nla_put_failure
;
8769 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
8770 goto nla_put_failure
;
8772 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
8773 goto nla_put_failure
;
8775 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
8776 goto nla_put_failure
;
8778 nla_nest_end(msg
, pinfoattr
);
8780 genlmsg_end(msg
, hdr
);
8782 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8783 nl80211_mlme_mcgrp
.id
, gfp
);
8787 genlmsg_cancel(msg
, hdr
);
8792 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
8793 struct net_device
*netdev
, const u8
*peer
,
8794 u32 num_packets
, gfp_t gfp
)
8796 struct sk_buff
*msg
;
8797 struct nlattr
*pinfoattr
;
8800 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8804 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8810 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8811 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8812 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8813 goto nla_put_failure
;
8815 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8817 goto nla_put_failure
;
8819 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
8820 goto nla_put_failure
;
8822 nla_nest_end(msg
, pinfoattr
);
8824 genlmsg_end(msg
, hdr
);
8826 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8827 nl80211_mlme_mcgrp
.id
, gfp
);
8831 genlmsg_cancel(msg
, hdr
);
8835 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
8836 u64 cookie
, bool acked
, gfp_t gfp
)
8838 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8839 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8840 struct sk_buff
*msg
;
8844 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8848 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
8854 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8855 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8856 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8857 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8858 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8859 goto nla_put_failure
;
8861 err
= genlmsg_end(msg
, hdr
);
8867 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8868 nl80211_mlme_mcgrp
.id
, gfp
);
8872 genlmsg_cancel(msg
, hdr
);
8875 EXPORT_SYMBOL(cfg80211_probe_status
);
8877 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
8878 const u8
*frame
, size_t len
,
8879 int freq
, int sig_dbm
, gfp_t gfp
)
8881 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8882 struct sk_buff
*msg
;
8884 u32 nlportid
= ACCESS_ONCE(rdev
->ap_beacons_nlportid
);
8889 msg
= nlmsg_new(len
+ 100, gfp
);
8893 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8899 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8901 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
8903 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8904 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
8905 goto nla_put_failure
;
8907 genlmsg_end(msg
, hdr
);
8909 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8913 genlmsg_cancel(msg
, hdr
);
8916 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
8918 static int nl80211_netlink_notify(struct notifier_block
* nb
,
8919 unsigned long state
,
8922 struct netlink_notify
*notify
= _notify
;
8923 struct cfg80211_registered_device
*rdev
;
8924 struct wireless_dev
*wdev
;
8926 if (state
!= NETLINK_URELEASE
)
8931 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
8932 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
8933 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
8934 if (rdev
->ap_beacons_nlportid
== notify
->portid
)
8935 rdev
->ap_beacons_nlportid
= 0;
8943 static struct notifier_block nl80211_netlink_notifier
= {
8944 .notifier_call
= nl80211_netlink_notify
,
8947 /* initialisation/exit functions */
8949 int nl80211_init(void)
8953 err
= genl_register_family_with_ops(&nl80211_fam
,
8954 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
8958 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
8962 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
8966 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
8970 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
8974 #ifdef CONFIG_NL80211_TESTMODE
8975 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
8980 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
8986 genl_unregister_family(&nl80211_fam
);
8990 void nl80211_exit(void)
8992 netlink_unregister_notifier(&nl80211_netlink_notifier
);
8993 genl_unregister_family(&nl80211_fam
);