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
, },
360 /* policy for the key attributes */
361 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
362 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
363 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
364 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
365 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
366 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
367 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
368 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
369 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
372 /* policy for the key default flags */
373 static const struct nla_policy
374 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
375 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
376 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
379 /* policy for WoWLAN attributes */
380 static const struct nla_policy
381 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
382 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
383 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
384 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
385 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
386 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
387 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
388 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
389 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
392 /* policy for GTK rekey offload attributes */
393 static const struct nla_policy
394 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
395 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
396 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
397 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
400 static const struct nla_policy
401 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
402 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
403 .len
= IEEE80211_MAX_SSID_LEN
},
404 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
407 /* ifidx get helper */
408 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
412 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
413 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
418 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
421 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
427 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
428 struct netlink_callback
*cb
,
429 struct cfg80211_registered_device
**rdev
,
430 struct net_device
**dev
)
432 int ifidx
= cb
->args
[0];
436 ifidx
= nl80211_get_ifidx(cb
);
444 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
450 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
452 err
= PTR_ERR(*rdev
);
462 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
464 cfg80211_unlock_rdev(rdev
);
469 static bool is_valid_ie_attr(const struct nlattr
*attr
)
477 pos
= nla_data(attr
);
498 /* message building helper */
499 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
502 /* since there is no private header just add the generic one */
503 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
506 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
507 struct ieee80211_channel
*chan
)
509 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
511 goto nla_put_failure
;
513 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
514 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
515 goto nla_put_failure
;
516 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
517 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
518 goto nla_put_failure
;
519 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
520 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
521 goto nla_put_failure
;
522 if ((chan
->flags
& IEEE80211_CHAN_RADAR
) &&
523 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
524 goto nla_put_failure
;
526 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
527 DBM_TO_MBM(chan
->max_power
)))
528 goto nla_put_failure
;
536 /* netlink command implementations */
543 bool def_uni
, def_multi
;
546 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
548 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
549 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
554 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
555 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
564 if (tb
[NL80211_KEY_IDX
])
565 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
567 if (tb
[NL80211_KEY_DATA
]) {
568 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
569 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
572 if (tb
[NL80211_KEY_SEQ
]) {
573 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
574 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
577 if (tb
[NL80211_KEY_CIPHER
])
578 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
580 if (tb
[NL80211_KEY_TYPE
]) {
581 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
582 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
586 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
587 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
588 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
589 tb
[NL80211_KEY_DEFAULT_TYPES
],
590 nl80211_key_default_policy
);
594 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
595 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
601 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
603 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
604 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
605 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
608 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
609 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
610 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
613 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
614 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
616 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
617 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
619 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
620 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
629 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
630 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
631 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
635 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
636 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
637 int err
= nla_parse_nested(
638 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
639 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
640 nl80211_key_default_policy
);
644 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
645 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
651 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
655 memset(k
, 0, sizeof(*k
));
659 if (info
->attrs
[NL80211_ATTR_KEY
])
660 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
662 err
= nl80211_parse_key_old(info
, k
);
667 if (k
->def
&& k
->defmgmt
)
671 if (k
->def_uni
|| !k
->def_multi
)
677 if (k
->idx
< 4 || k
->idx
> 5)
680 if (k
->idx
< 0 || k
->idx
> 3)
683 if (k
->idx
< 0 || k
->idx
> 5)
691 static struct cfg80211_cached_keys
*
692 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
695 struct key_parse parse
;
697 struct cfg80211_cached_keys
*result
;
698 int rem
, err
, def
= 0;
700 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
702 return ERR_PTR(-ENOMEM
);
705 result
->defmgmt
= -1;
707 nla_for_each_nested(key
, keys
, rem
) {
708 memset(&parse
, 0, sizeof(parse
));
711 err
= nl80211_parse_key_new(key
, &parse
);
717 if (parse
.idx
< 0 || parse
.idx
> 4)
723 result
->def
= parse
.idx
;
724 if (!parse
.def_uni
|| !parse
.def_multi
)
726 } else if (parse
.defmgmt
)
728 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
729 parse
.idx
, false, NULL
);
732 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
733 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
734 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
735 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
744 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
746 ASSERT_WDEV_LOCK(wdev
);
748 switch (wdev
->iftype
) {
749 case NL80211_IFTYPE_AP
:
750 case NL80211_IFTYPE_AP_VLAN
:
751 case NL80211_IFTYPE_P2P_GO
:
752 case NL80211_IFTYPE_MESH_POINT
:
754 case NL80211_IFTYPE_ADHOC
:
755 if (!wdev
->current_bss
)
758 case NL80211_IFTYPE_STATION
:
759 case NL80211_IFTYPE_P2P_CLIENT
:
760 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
770 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
772 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
776 goto nla_put_failure
;
780 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
781 goto nla_put_failure
;
786 nla_nest_end(msg
, nl_modes
);
793 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
796 struct nlattr
*nl_combis
;
799 nl_combis
= nla_nest_start(msg
,
800 NL80211_ATTR_INTERFACE_COMBINATIONS
);
802 goto nla_put_failure
;
804 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
805 const struct ieee80211_iface_combination
*c
;
806 struct nlattr
*nl_combi
, *nl_limits
;
808 c
= &wiphy
->iface_combinations
[i
];
810 nl_combi
= nla_nest_start(msg
, i
+ 1);
812 goto nla_put_failure
;
814 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
816 goto nla_put_failure
;
818 for (j
= 0; j
< c
->n_limits
; j
++) {
819 struct nlattr
*nl_limit
;
821 nl_limit
= nla_nest_start(msg
, j
+ 1);
823 goto nla_put_failure
;
824 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
826 goto nla_put_failure
;
827 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
829 goto nla_put_failure
;
830 nla_nest_end(msg
, nl_limit
);
833 nla_nest_end(msg
, nl_limits
);
835 if (c
->beacon_int_infra_match
&&
836 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
837 goto nla_put_failure
;
838 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
839 c
->num_different_channels
) ||
840 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
842 goto nla_put_failure
;
844 nla_nest_end(msg
, nl_combi
);
847 nla_nest_end(msg
, nl_combis
);
854 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
855 struct cfg80211_registered_device
*dev
)
858 struct nlattr
*nl_bands
, *nl_band
;
859 struct nlattr
*nl_freqs
, *nl_freq
;
860 struct nlattr
*nl_rates
, *nl_rate
;
861 struct nlattr
*nl_cmds
;
862 enum ieee80211_band band
;
863 struct ieee80211_channel
*chan
;
864 struct ieee80211_rate
*rate
;
866 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
867 dev
->wiphy
.mgmt_stypes
;
869 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
873 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
874 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
)) ||
875 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
876 cfg80211_rdev_list_generation
) ||
877 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
878 dev
->wiphy
.retry_short
) ||
879 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
880 dev
->wiphy
.retry_long
) ||
881 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
882 dev
->wiphy
.frag_threshold
) ||
883 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
884 dev
->wiphy
.rts_threshold
) ||
885 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
886 dev
->wiphy
.coverage_class
) ||
887 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
888 dev
->wiphy
.max_scan_ssids
) ||
889 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
890 dev
->wiphy
.max_sched_scan_ssids
) ||
891 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
892 dev
->wiphy
.max_scan_ie_len
) ||
893 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
894 dev
->wiphy
.max_sched_scan_ie_len
) ||
895 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
896 dev
->wiphy
.max_match_sets
))
897 goto nla_put_failure
;
899 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
900 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
901 goto nla_put_failure
;
902 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
903 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
904 goto nla_put_failure
;
905 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
906 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
907 goto nla_put_failure
;
908 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
909 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
910 goto nla_put_failure
;
911 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
912 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
913 goto nla_put_failure
;
914 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
915 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
916 goto nla_put_failure
;
918 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
919 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
920 dev
->wiphy
.cipher_suites
))
921 goto nla_put_failure
;
923 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
924 dev
->wiphy
.max_num_pmkids
))
925 goto nla_put_failure
;
927 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
928 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
929 goto nla_put_failure
;
931 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
932 dev
->wiphy
.available_antennas_tx
) ||
933 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
934 dev
->wiphy
.available_antennas_rx
))
935 goto nla_put_failure
;
937 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
938 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
939 dev
->wiphy
.probe_resp_offload
))
940 goto nla_put_failure
;
942 if ((dev
->wiphy
.available_antennas_tx
||
943 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
944 u32 tx_ant
= 0, rx_ant
= 0;
946 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
948 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
,
950 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
,
952 goto nla_put_failure
;
956 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
957 dev
->wiphy
.interface_modes
))
958 goto nla_put_failure
;
960 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
962 goto nla_put_failure
;
964 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
965 if (!dev
->wiphy
.bands
[band
])
968 nl_band
= nla_nest_start(msg
, band
);
970 goto nla_put_failure
;
973 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
&&
974 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
975 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
976 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
) ||
977 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
978 dev
->wiphy
.bands
[band
]->ht_cap
.cap
) ||
979 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
980 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
) ||
981 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
982 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
)))
983 goto nla_put_failure
;
986 if (dev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
&&
987 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
988 sizeof(dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
),
989 &dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
) ||
990 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
991 dev
->wiphy
.bands
[band
]->vht_cap
.cap
)))
992 goto nla_put_failure
;
994 /* add frequencies */
995 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
997 goto nla_put_failure
;
999 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
1000 nl_freq
= nla_nest_start(msg
, i
);
1002 goto nla_put_failure
;
1004 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
1006 if (nl80211_msg_put_channel(msg
, chan
))
1007 goto nla_put_failure
;
1009 nla_nest_end(msg
, nl_freq
);
1012 nla_nest_end(msg
, nl_freqs
);
1015 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1017 goto nla_put_failure
;
1019 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
1020 nl_rate
= nla_nest_start(msg
, i
);
1022 goto nla_put_failure
;
1024 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
1025 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1027 goto nla_put_failure
;
1028 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1030 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1031 goto nla_put_failure
;
1033 nla_nest_end(msg
, nl_rate
);
1036 nla_nest_end(msg
, nl_rates
);
1038 nla_nest_end(msg
, nl_band
);
1040 nla_nest_end(msg
, nl_bands
);
1042 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1044 goto nla_put_failure
;
1047 #define CMD(op, n) \
1049 if (dev->ops->op) { \
1051 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1052 goto nla_put_failure; \
1056 CMD(add_virtual_intf
, NEW_INTERFACE
);
1057 CMD(change_virtual_intf
, SET_INTERFACE
);
1058 CMD(add_key
, NEW_KEY
);
1059 CMD(start_ap
, START_AP
);
1060 CMD(add_station
, NEW_STATION
);
1061 CMD(add_mpath
, NEW_MPATH
);
1062 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1063 CMD(change_bss
, SET_BSS
);
1064 CMD(auth
, AUTHENTICATE
);
1065 CMD(assoc
, ASSOCIATE
);
1066 CMD(deauth
, DEAUTHENTICATE
);
1067 CMD(disassoc
, DISASSOCIATE
);
1068 CMD(join_ibss
, JOIN_IBSS
);
1069 CMD(join_mesh
, JOIN_MESH
);
1070 CMD(set_pmksa
, SET_PMKSA
);
1071 CMD(del_pmksa
, DEL_PMKSA
);
1072 CMD(flush_pmksa
, FLUSH_PMKSA
);
1073 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1074 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1075 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1076 CMD(mgmt_tx
, FRAME
);
1077 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1078 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1080 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1081 goto nla_put_failure
;
1083 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1084 dev
->ops
->join_mesh
) {
1086 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1087 goto nla_put_failure
;
1089 CMD(set_wds_peer
, SET_WDS_PEER
);
1090 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1091 CMD(tdls_mgmt
, TDLS_MGMT
);
1092 CMD(tdls_oper
, TDLS_OPER
);
1094 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1095 CMD(sched_scan_start
, START_SCHED_SCAN
);
1096 CMD(probe_client
, PROBE_CLIENT
);
1097 CMD(set_noack_map
, SET_NOACK_MAP
);
1098 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1100 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1101 goto nla_put_failure
;
1103 CMD(start_p2p_device
, START_P2P_DEVICE
);
1105 #ifdef CONFIG_NL80211_TESTMODE
1106 CMD(testmode_cmd
, TESTMODE
);
1111 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1113 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1114 goto nla_put_failure
;
1117 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1119 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1120 goto nla_put_failure
;
1123 nla_nest_end(msg
, nl_cmds
);
1125 if (dev
->ops
->remain_on_channel
&&
1126 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1127 nla_put_u32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1128 dev
->wiphy
.max_remain_on_channel_duration
))
1129 goto nla_put_failure
;
1131 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1132 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1133 goto nla_put_failure
;
1137 struct nlattr
*nl_ftypes
, *nl_ifs
;
1138 enum nl80211_iftype ift
;
1140 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1142 goto nla_put_failure
;
1144 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1145 nl_ftypes
= nla_nest_start(msg
, ift
);
1147 goto nla_put_failure
;
1149 stypes
= mgmt_stypes
[ift
].tx
;
1152 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1153 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1154 goto nla_put_failure
;
1158 nla_nest_end(msg
, nl_ftypes
);
1161 nla_nest_end(msg
, nl_ifs
);
1163 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1165 goto nla_put_failure
;
1167 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1168 nl_ftypes
= nla_nest_start(msg
, ift
);
1170 goto nla_put_failure
;
1172 stypes
= mgmt_stypes
[ift
].rx
;
1175 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1176 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1177 goto nla_put_failure
;
1181 nla_nest_end(msg
, nl_ftypes
);
1183 nla_nest_end(msg
, nl_ifs
);
1187 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
1188 struct nlattr
*nl_wowlan
;
1190 nl_wowlan
= nla_nest_start(msg
,
1191 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1193 goto nla_put_failure
;
1195 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1196 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1197 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1198 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1199 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1200 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1201 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1202 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1203 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1204 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1205 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1206 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1207 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1208 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1209 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1210 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1211 goto nla_put_failure
;
1212 if (dev
->wiphy
.wowlan
.n_patterns
) {
1213 struct nl80211_wowlan_pattern_support pat
= {
1214 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1216 dev
->wiphy
.wowlan
.pattern_min_len
,
1218 dev
->wiphy
.wowlan
.pattern_max_len
,
1220 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1222 goto nla_put_failure
;
1225 nla_nest_end(msg
, nl_wowlan
);
1229 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1230 dev
->wiphy
.software_iftypes
))
1231 goto nla_put_failure
;
1233 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1234 goto nla_put_failure
;
1236 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1237 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1238 dev
->wiphy
.ap_sme_capa
))
1239 goto nla_put_failure
;
1241 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
,
1242 dev
->wiphy
.features
))
1243 goto nla_put_failure
;
1245 if (dev
->wiphy
.ht_capa_mod_mask
&&
1246 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1247 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1248 dev
->wiphy
.ht_capa_mod_mask
))
1249 goto nla_put_failure
;
1251 return genlmsg_end(msg
, hdr
);
1254 genlmsg_cancel(msg
, hdr
);
1258 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1261 int start
= cb
->args
[0];
1262 struct cfg80211_registered_device
*dev
;
1264 mutex_lock(&cfg80211_mutex
);
1265 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1266 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1270 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).portid
,
1271 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1277 mutex_unlock(&cfg80211_mutex
);
1284 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1286 struct sk_buff
*msg
;
1287 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1289 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1293 if (nl80211_send_wiphy(msg
, info
->snd_portid
, info
->snd_seq
, 0, dev
) < 0) {
1298 return genlmsg_reply(msg
, info
);
1301 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1302 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1303 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1304 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1305 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1306 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1309 static int parse_txq_params(struct nlattr
*tb
[],
1310 struct ieee80211_txq_params
*txq_params
)
1312 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1313 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1314 !tb
[NL80211_TXQ_ATTR_AIFS
])
1317 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1318 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1319 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1320 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1321 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1323 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1329 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1332 * You can only set the channel explicitly for WDS interfaces,
1333 * all others have their channel managed via their respective
1334 * "establish a connection" command (connect, join, ...)
1336 * For AP/GO and mesh mode, the channel can be set with the
1337 * channel userspace API, but is only stored and passed to the
1338 * low-level driver when the AP starts or the mesh is joined.
1339 * This is for backward compatibility, userspace can also give
1340 * the channel in the start-ap or join-mesh commands instead.
1342 * Monitors are special as they are normally slaved to
1343 * whatever else is going on, so they have their own special
1344 * operation to set the monitor channel if possible.
1347 wdev
->iftype
== NL80211_IFTYPE_AP
||
1348 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1349 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1350 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1353 static bool nl80211_valid_channel_type(struct genl_info
*info
,
1354 enum nl80211_channel_type
*channel_type
)
1356 enum nl80211_channel_type tmp
;
1358 if (!info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1361 tmp
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1362 if (tmp
!= NL80211_CHAN_NO_HT
&&
1363 tmp
!= NL80211_CHAN_HT20
&&
1364 tmp
!= NL80211_CHAN_HT40PLUS
&&
1365 tmp
!= NL80211_CHAN_HT40MINUS
)
1369 *channel_type
= tmp
;
1374 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1375 struct wireless_dev
*wdev
,
1376 struct genl_info
*info
)
1378 struct ieee80211_channel
*channel
;
1379 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1382 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1385 iftype
= wdev
->iftype
;
1387 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1390 if (!nl80211_can_set_dev_channel(wdev
))
1393 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
1394 !nl80211_valid_channel_type(info
, &channel_type
))
1397 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1399 mutex_lock(&rdev
->devlist_mtx
);
1401 case NL80211_IFTYPE_AP
:
1402 case NL80211_IFTYPE_P2P_GO
:
1403 if (wdev
->beacon_interval
) {
1407 channel
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
1408 if (!channel
|| !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
,
1414 wdev
->preset_chan
= channel
;
1415 wdev
->preset_chantype
= channel_type
;
1418 case NL80211_IFTYPE_MESH_POINT
:
1419 result
= cfg80211_set_mesh_freq(rdev
, wdev
, freq
, channel_type
);
1421 case NL80211_IFTYPE_MONITOR
:
1422 result
= cfg80211_set_monitor_channel(rdev
, freq
, channel_type
);
1427 mutex_unlock(&rdev
->devlist_mtx
);
1432 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1434 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1435 struct net_device
*netdev
= info
->user_ptr
[1];
1437 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1440 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1442 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1443 struct net_device
*dev
= info
->user_ptr
[1];
1444 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1447 if (!info
->attrs
[NL80211_ATTR_MAC
])
1450 if (netif_running(dev
))
1453 if (!rdev
->ops
->set_wds_peer
)
1456 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1459 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1460 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1464 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1466 struct cfg80211_registered_device
*rdev
;
1467 struct net_device
*netdev
= NULL
;
1468 struct wireless_dev
*wdev
;
1469 int result
= 0, rem_txq_params
= 0;
1470 struct nlattr
*nl_txq_params
;
1472 u8 retry_short
= 0, retry_long
= 0;
1473 u32 frag_threshold
= 0, rts_threshold
= 0;
1474 u8 coverage_class
= 0;
1477 * Try to find the wiphy and netdev. Normally this
1478 * function shouldn't need the netdev, but this is
1479 * done for backward compatibility -- previously
1480 * setting the channel was done per wiphy, but now
1481 * it is per netdev. Previous userland like hostapd
1482 * also passed a netdev to set_wiphy, so that it is
1483 * possible to let that go to the right netdev!
1485 mutex_lock(&cfg80211_mutex
);
1487 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1488 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1490 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1491 if (netdev
&& netdev
->ieee80211_ptr
) {
1492 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1493 mutex_lock(&rdev
->mtx
);
1499 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1502 mutex_unlock(&cfg80211_mutex
);
1503 return PTR_ERR(rdev
);
1509 mutex_lock(&rdev
->mtx
);
1510 } else if (nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1511 wdev
= netdev
->ieee80211_ptr
;
1516 * end workaround code, by now the rdev is available
1517 * and locked, and wdev may or may not be NULL.
1520 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1521 result
= cfg80211_dev_rename(
1522 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1524 mutex_unlock(&cfg80211_mutex
);
1529 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1530 struct ieee80211_txq_params txq_params
;
1531 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1533 if (!rdev
->ops
->set_txq_params
) {
1534 result
= -EOPNOTSUPP
;
1543 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1544 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1549 if (!netif_running(netdev
)) {
1554 nla_for_each_nested(nl_txq_params
,
1555 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1557 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1558 nla_data(nl_txq_params
),
1559 nla_len(nl_txq_params
),
1561 result
= parse_txq_params(tb
, &txq_params
);
1565 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1573 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1574 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1579 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1580 enum nl80211_tx_power_setting type
;
1583 if (!rdev
->ops
->set_tx_power
) {
1584 result
= -EOPNOTSUPP
;
1588 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1589 type
= nla_get_u32(info
->attrs
[idx
]);
1591 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1592 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1597 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1598 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1599 mbm
= nla_get_u32(info
->attrs
[idx
]);
1602 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1607 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1608 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1610 if ((!rdev
->wiphy
.available_antennas_tx
&&
1611 !rdev
->wiphy
.available_antennas_rx
) ||
1612 !rdev
->ops
->set_antenna
) {
1613 result
= -EOPNOTSUPP
;
1617 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1618 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1620 /* reject antenna configurations which don't match the
1621 * available antenna masks, except for the "all" mask */
1622 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1623 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1628 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1629 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1631 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1638 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1639 retry_short
= nla_get_u8(
1640 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1641 if (retry_short
== 0) {
1645 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1648 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1649 retry_long
= nla_get_u8(
1650 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1651 if (retry_long
== 0) {
1655 changed
|= WIPHY_PARAM_RETRY_LONG
;
1658 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1659 frag_threshold
= nla_get_u32(
1660 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1661 if (frag_threshold
< 256) {
1665 if (frag_threshold
!= (u32
) -1) {
1667 * Fragments (apart from the last one) are required to
1668 * have even length. Make the fragmentation code
1669 * simpler by stripping LSB should someone try to use
1670 * odd threshold value.
1672 frag_threshold
&= ~0x1;
1674 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1677 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1678 rts_threshold
= nla_get_u32(
1679 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1680 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1683 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1684 coverage_class
= nla_get_u8(
1685 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1686 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1690 u8 old_retry_short
, old_retry_long
;
1691 u32 old_frag_threshold
, old_rts_threshold
;
1692 u8 old_coverage_class
;
1694 if (!rdev
->ops
->set_wiphy_params
) {
1695 result
= -EOPNOTSUPP
;
1699 old_retry_short
= rdev
->wiphy
.retry_short
;
1700 old_retry_long
= rdev
->wiphy
.retry_long
;
1701 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1702 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1703 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1705 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1706 rdev
->wiphy
.retry_short
= retry_short
;
1707 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1708 rdev
->wiphy
.retry_long
= retry_long
;
1709 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1710 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1711 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1712 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1713 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1714 rdev
->wiphy
.coverage_class
= coverage_class
;
1716 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1718 rdev
->wiphy
.retry_short
= old_retry_short
;
1719 rdev
->wiphy
.retry_long
= old_retry_long
;
1720 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1721 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1722 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1727 mutex_unlock(&rdev
->mtx
);
1733 static inline u64
wdev_id(struct wireless_dev
*wdev
)
1735 return (u64
)wdev
->identifier
|
1736 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
1739 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
1740 struct cfg80211_registered_device
*rdev
,
1741 struct wireless_dev
*wdev
)
1743 struct net_device
*dev
= wdev
->netdev
;
1746 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1751 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
1752 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
1753 goto nla_put_failure
;
1755 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1756 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
1757 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
1758 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
1759 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1760 rdev
->devlist_generation
^
1761 (cfg80211_rdev_list_generation
<< 2)))
1762 goto nla_put_failure
;
1764 if (rdev
->ops
->get_channel
) {
1765 struct ieee80211_channel
*chan
;
1766 enum nl80211_channel_type channel_type
;
1768 chan
= rdev
->ops
->get_channel(&rdev
->wiphy
, wdev
,
1771 (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
1772 chan
->center_freq
) ||
1773 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
1775 goto nla_put_failure
;
1778 return genlmsg_end(msg
, hdr
);
1781 genlmsg_cancel(msg
, hdr
);
1785 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1789 int wp_start
= cb
->args
[0];
1790 int if_start
= cb
->args
[1];
1791 struct cfg80211_registered_device
*rdev
;
1792 struct wireless_dev
*wdev
;
1794 mutex_lock(&cfg80211_mutex
);
1795 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1796 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1798 if (wp_idx
< wp_start
) {
1804 mutex_lock(&rdev
->devlist_mtx
);
1805 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
1806 if (if_idx
< if_start
) {
1810 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
1811 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1813 mutex_unlock(&rdev
->devlist_mtx
);
1818 mutex_unlock(&rdev
->devlist_mtx
);
1823 mutex_unlock(&cfg80211_mutex
);
1825 cb
->args
[0] = wp_idx
;
1826 cb
->args
[1] = if_idx
;
1831 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1833 struct sk_buff
*msg
;
1834 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1835 struct wireless_dev
*wdev
= info
->user_ptr
[1];
1837 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1841 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
1847 return genlmsg_reply(msg
, info
);
1850 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1851 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1852 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1853 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1854 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1855 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1858 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1860 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1868 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1869 nla
, mntr_flags_policy
))
1872 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1874 *mntrflags
|= (1<<flag
);
1879 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1880 struct net_device
*netdev
, u8 use_4addr
,
1881 enum nl80211_iftype iftype
)
1884 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1890 case NL80211_IFTYPE_AP_VLAN
:
1891 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1894 case NL80211_IFTYPE_STATION
:
1895 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1905 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1907 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1908 struct vif_params params
;
1910 enum nl80211_iftype otype
, ntype
;
1911 struct net_device
*dev
= info
->user_ptr
[1];
1912 u32 _flags
, *flags
= NULL
;
1913 bool change
= false;
1915 memset(¶ms
, 0, sizeof(params
));
1917 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1919 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1920 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1923 if (ntype
> NL80211_IFTYPE_MAX
)
1927 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1928 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1930 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1932 if (netif_running(dev
))
1936 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1937 IEEE80211_MAX_MESH_ID_LEN
);
1938 wdev
->mesh_id_up_len
=
1939 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1940 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1941 wdev
->mesh_id_up_len
);
1945 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1946 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1948 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1952 params
.use_4addr
= -1;
1955 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1956 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1958 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1968 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1972 if (!err
&& params
.use_4addr
!= -1)
1973 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1978 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1980 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1981 struct vif_params params
;
1982 struct wireless_dev
*wdev
;
1983 struct sk_buff
*msg
;
1985 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1988 memset(¶ms
, 0, sizeof(params
));
1990 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1993 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1994 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1995 if (type
> NL80211_IFTYPE_MAX
)
1999 if (!rdev
->ops
->add_virtual_intf
||
2000 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2003 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2004 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2005 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2010 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2014 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2015 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2017 wdev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
2018 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2019 type
, err
? NULL
: &flags
, ¶ms
);
2022 return PTR_ERR(wdev
);
2026 case NL80211_IFTYPE_MESH_POINT
:
2027 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2030 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2031 IEEE80211_MAX_MESH_ID_LEN
);
2032 wdev
->mesh_id_up_len
=
2033 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2034 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2035 wdev
->mesh_id_up_len
);
2038 case NL80211_IFTYPE_P2P_DEVICE
:
2040 * P2P Device doesn't have a netdev, so doesn't go
2041 * through the netdev notifier and must be added here
2043 mutex_init(&wdev
->mtx
);
2044 INIT_LIST_HEAD(&wdev
->event_list
);
2045 spin_lock_init(&wdev
->event_lock
);
2046 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2047 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2049 mutex_lock(&rdev
->devlist_mtx
);
2050 wdev
->identifier
= ++rdev
->wdev_id
;
2051 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2052 rdev
->devlist_generation
++;
2053 mutex_unlock(&rdev
->devlist_mtx
);
2059 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2065 return genlmsg_reply(msg
, info
);
2068 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2070 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2071 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2073 if (!rdev
->ops
->del_virtual_intf
)
2077 * If we remove a wireless device without a netdev then clear
2078 * user_ptr[1] so that nl80211_post_doit won't dereference it
2079 * to check if it needs to do dev_put(). Otherwise it crashes
2080 * since the wdev has been freed, unlike with a netdev where
2081 * we need the dev_put() for the netdev to really be freed.
2084 info
->user_ptr
[1] = NULL
;
2086 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, wdev
);
2089 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2091 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2092 struct net_device
*dev
= info
->user_ptr
[1];
2095 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2098 if (!rdev
->ops
->set_noack_map
)
2101 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2103 return rdev
->ops
->set_noack_map(&rdev
->wiphy
, dev
, noack_map
);
2106 struct get_key_cookie
{
2107 struct sk_buff
*msg
;
2112 static void get_key_callback(void *c
, struct key_params
*params
)
2115 struct get_key_cookie
*cookie
= c
;
2118 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2119 params
->key_len
, params
->key
)) ||
2121 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2122 params
->seq_len
, params
->seq
)) ||
2124 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2126 goto nla_put_failure
;
2128 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2130 goto nla_put_failure
;
2133 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2134 params
->key_len
, params
->key
)) ||
2136 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2137 params
->seq_len
, params
->seq
)) ||
2139 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2141 goto nla_put_failure
;
2143 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2144 goto nla_put_failure
;
2146 nla_nest_end(cookie
->msg
, key
);
2153 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2155 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2157 struct net_device
*dev
= info
->user_ptr
[1];
2159 const u8
*mac_addr
= NULL
;
2161 struct get_key_cookie cookie
= {
2165 struct sk_buff
*msg
;
2167 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2168 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2173 if (info
->attrs
[NL80211_ATTR_MAC
])
2174 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2176 pairwise
= !!mac_addr
;
2177 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2178 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2179 if (kt
>= NUM_NL80211_KEYTYPES
)
2181 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2182 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2184 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2187 if (!rdev
->ops
->get_key
)
2190 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2194 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2195 NL80211_CMD_NEW_KEY
);
2197 return PTR_ERR(hdr
);
2200 cookie
.idx
= key_idx
;
2202 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2203 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2204 goto nla_put_failure
;
2206 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2207 goto nla_put_failure
;
2209 if (pairwise
&& mac_addr
&&
2210 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2213 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
2214 mac_addr
, &cookie
, get_key_callback
);
2220 goto nla_put_failure
;
2222 genlmsg_end(msg
, hdr
);
2223 return genlmsg_reply(msg
, info
);
2232 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2234 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2235 struct key_parse key
;
2237 struct net_device
*dev
= info
->user_ptr
[1];
2239 err
= nl80211_parse_key(info
, &key
);
2246 /* only support setting default key */
2247 if (!key
.def
&& !key
.defmgmt
)
2250 wdev_lock(dev
->ieee80211_ptr
);
2253 if (!rdev
->ops
->set_default_key
) {
2258 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2262 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
2263 key
.def_uni
, key
.def_multi
);
2268 #ifdef CONFIG_CFG80211_WEXT
2269 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2272 if (key
.def_uni
|| !key
.def_multi
) {
2277 if (!rdev
->ops
->set_default_mgmt_key
) {
2282 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2286 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
2291 #ifdef CONFIG_CFG80211_WEXT
2292 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2297 wdev_unlock(dev
->ieee80211_ptr
);
2302 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2304 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2306 struct net_device
*dev
= info
->user_ptr
[1];
2307 struct key_parse key
;
2308 const u8
*mac_addr
= NULL
;
2310 err
= nl80211_parse_key(info
, &key
);
2317 if (info
->attrs
[NL80211_ATTR_MAC
])
2318 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2320 if (key
.type
== -1) {
2322 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2324 key
.type
= NL80211_KEYTYPE_GROUP
;
2328 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2329 key
.type
!= NL80211_KEYTYPE_GROUP
)
2332 if (!rdev
->ops
->add_key
)
2335 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2336 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2340 wdev_lock(dev
->ieee80211_ptr
);
2341 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2343 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
2344 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2346 wdev_unlock(dev
->ieee80211_ptr
);
2351 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2353 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2355 struct net_device
*dev
= info
->user_ptr
[1];
2356 u8
*mac_addr
= NULL
;
2357 struct key_parse key
;
2359 err
= nl80211_parse_key(info
, &key
);
2363 if (info
->attrs
[NL80211_ATTR_MAC
])
2364 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2366 if (key
.type
== -1) {
2368 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2370 key
.type
= NL80211_KEYTYPE_GROUP
;
2374 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2375 key
.type
!= NL80211_KEYTYPE_GROUP
)
2378 if (!rdev
->ops
->del_key
)
2381 wdev_lock(dev
->ieee80211_ptr
);
2382 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2384 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2385 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2389 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
2390 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2393 #ifdef CONFIG_CFG80211_WEXT
2395 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2396 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2397 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2398 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2401 wdev_unlock(dev
->ieee80211_ptr
);
2406 static int nl80211_parse_beacon(struct genl_info
*info
,
2407 struct cfg80211_beacon_data
*bcn
)
2409 bool haveinfo
= false;
2411 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2412 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2413 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2414 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2417 memset(bcn
, 0, sizeof(*bcn
));
2419 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2420 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2421 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2427 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2428 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2430 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2437 if (info
->attrs
[NL80211_ATTR_IE
]) {
2438 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2439 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2442 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2443 bcn
->proberesp_ies
=
2444 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2445 bcn
->proberesp_ies_len
=
2446 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2449 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2450 bcn
->assocresp_ies
=
2451 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2452 bcn
->assocresp_ies_len
=
2453 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2456 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2458 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2459 bcn
->probe_resp_len
=
2460 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2466 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2467 struct cfg80211_ap_settings
*params
)
2469 struct wireless_dev
*wdev
;
2472 mutex_lock(&rdev
->devlist_mtx
);
2474 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2475 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2476 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2479 if (!wdev
->preset_chan
)
2482 params
->channel
= wdev
->preset_chan
;
2483 params
->channel_type
= wdev
->preset_chantype
;
2488 mutex_unlock(&rdev
->devlist_mtx
);
2493 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
2494 enum nl80211_auth_type auth_type
,
2495 enum nl80211_commands cmd
)
2497 if (auth_type
> NL80211_AUTHTYPE_MAX
)
2501 case NL80211_CMD_AUTHENTICATE
:
2502 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
2503 auth_type
== NL80211_AUTHTYPE_SAE
)
2506 case NL80211_CMD_CONNECT
:
2507 case NL80211_CMD_START_AP
:
2508 /* SAE not supported yet */
2509 if (auth_type
== NL80211_AUTHTYPE_SAE
)
2517 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2519 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2520 struct net_device
*dev
= info
->user_ptr
[1];
2521 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2522 struct cfg80211_ap_settings params
;
2525 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2526 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2529 if (!rdev
->ops
->start_ap
)
2532 if (wdev
->beacon_interval
)
2535 memset(¶ms
, 0, sizeof(params
));
2537 /* these are required for START_AP */
2538 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2539 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2540 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2543 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
2547 params
.beacon_interval
=
2548 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2549 params
.dtim_period
=
2550 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2552 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
2557 * In theory, some of these attributes should be required here
2558 * but since they were not used when the command was originally
2559 * added, keep them optional for old user space programs to let
2560 * them continue to work with drivers that do not need the
2561 * additional information -- drivers must check!
2563 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2564 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2566 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2567 if (params
.ssid_len
== 0 ||
2568 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2572 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2573 params
.hidden_ssid
= nla_get_u32(
2574 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2575 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2576 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
2577 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2581 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2583 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2584 params
.auth_type
= nla_get_u32(
2585 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2586 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
2587 NL80211_CMD_START_AP
))
2590 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2592 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2593 NL80211_MAX_NR_CIPHER_SUITES
);
2597 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
2598 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
2600 params
.inactivity_timeout
= nla_get_u16(
2601 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
2604 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2605 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
2607 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
2608 !nl80211_valid_channel_type(info
, &channel_type
))
2611 params
.channel
= rdev_freq_to_chan(rdev
,
2612 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
2614 if (!params
.channel
)
2616 params
.channel_type
= channel_type
;
2617 } else if (wdev
->preset_chan
) {
2618 params
.channel
= wdev
->preset_chan
;
2619 params
.channel_type
= wdev
->preset_chantype
;
2620 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
2623 if (!cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, params
.channel
,
2624 params
.channel_type
))
2627 mutex_lock(&rdev
->devlist_mtx
);
2628 err
= cfg80211_can_use_chan(rdev
, wdev
, params
.channel
,
2630 mutex_unlock(&rdev
->devlist_mtx
);
2635 err
= rdev
->ops
->start_ap(&rdev
->wiphy
, dev
, ¶ms
);
2637 wdev
->preset_chan
= params
.channel
;
2638 wdev
->preset_chantype
= params
.channel_type
;
2639 wdev
->beacon_interval
= params
.beacon_interval
;
2640 wdev
->channel
= params
.channel
;
2645 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2647 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2648 struct net_device
*dev
= info
->user_ptr
[1];
2649 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2650 struct cfg80211_beacon_data params
;
2653 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2654 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2657 if (!rdev
->ops
->change_beacon
)
2660 if (!wdev
->beacon_interval
)
2663 err
= nl80211_parse_beacon(info
, ¶ms
);
2667 return rdev
->ops
->change_beacon(&rdev
->wiphy
, dev
, ¶ms
);
2670 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2672 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2673 struct net_device
*dev
= info
->user_ptr
[1];
2675 return cfg80211_stop_ap(rdev
, dev
);
2678 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2679 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2680 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2681 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2682 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2683 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2684 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
2687 static int parse_station_flags(struct genl_info
*info
,
2688 enum nl80211_iftype iftype
,
2689 struct station_parameters
*params
)
2691 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2696 * Try parsing the new attribute first so userspace
2697 * can specify both for older kernels.
2699 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2701 struct nl80211_sta_flag_update
*sta_flags
;
2703 sta_flags
= nla_data(nla
);
2704 params
->sta_flags_mask
= sta_flags
->mask
;
2705 params
->sta_flags_set
= sta_flags
->set
;
2706 if ((params
->sta_flags_mask
|
2707 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2712 /* if present, parse the old attribute */
2714 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2718 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2719 nla
, sta_flags_policy
))
2723 * Only allow certain flags for interface types so that
2724 * other attributes are silently ignored. Remember that
2725 * this is backward compatibility code with old userspace
2726 * and shouldn't be hit in other cases anyway.
2729 case NL80211_IFTYPE_AP
:
2730 case NL80211_IFTYPE_AP_VLAN
:
2731 case NL80211_IFTYPE_P2P_GO
:
2732 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2733 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2734 BIT(NL80211_STA_FLAG_WME
) |
2735 BIT(NL80211_STA_FLAG_MFP
);
2737 case NL80211_IFTYPE_P2P_CLIENT
:
2738 case NL80211_IFTYPE_STATION
:
2739 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2740 BIT(NL80211_STA_FLAG_TDLS_PEER
);
2742 case NL80211_IFTYPE_MESH_POINT
:
2743 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2744 BIT(NL80211_STA_FLAG_MFP
) |
2745 BIT(NL80211_STA_FLAG_AUTHORIZED
);
2750 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
2752 params
->sta_flags_set
|= (1<<flag
);
2754 /* no longer support new API additions in old API */
2755 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
2763 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2766 struct nlattr
*rate
;
2770 rate
= nla_nest_start(msg
, attr
);
2772 goto nla_put_failure
;
2774 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2775 bitrate
= cfg80211_calculate_bitrate(info
);
2776 /* report 16-bit bitrate only if we can */
2777 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
2779 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
)) ||
2780 (bitrate_compat
> 0 &&
2781 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
)) ||
2782 ((info
->flags
& RATE_INFO_FLAGS_MCS
) &&
2783 nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
)) ||
2784 ((info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) &&
2785 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
)) ||
2786 ((info
->flags
& RATE_INFO_FLAGS_SHORT_GI
) &&
2787 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
)))
2788 goto nla_put_failure
;
2790 nla_nest_end(msg
, rate
);
2797 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
2799 struct cfg80211_registered_device
*rdev
,
2800 struct net_device
*dev
,
2801 const u8
*mac_addr
, struct station_info
*sinfo
)
2804 struct nlattr
*sinfoattr
, *bss_param
;
2806 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2810 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2811 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
2812 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
2813 goto nla_put_failure
;
2815 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2817 goto nla_put_failure
;
2818 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
2819 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2820 sinfo
->connected_time
))
2821 goto nla_put_failure
;
2822 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
2823 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2824 sinfo
->inactive_time
))
2825 goto nla_put_failure
;
2826 if ((sinfo
->filled
& STATION_INFO_RX_BYTES
) &&
2827 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
2829 goto nla_put_failure
;
2830 if ((sinfo
->filled
& STATION_INFO_TX_BYTES
) &&
2831 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
2833 goto nla_put_failure
;
2834 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
2835 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
2836 goto nla_put_failure
;
2837 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
2838 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
2839 goto nla_put_failure
;
2840 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
2841 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2842 sinfo
->plink_state
))
2843 goto nla_put_failure
;
2844 switch (rdev
->wiphy
.signal_type
) {
2845 case CFG80211_SIGNAL_TYPE_MBM
:
2846 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
2847 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
2849 goto nla_put_failure
;
2850 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
2851 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2853 goto nla_put_failure
;
2858 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2859 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2860 NL80211_STA_INFO_TX_BITRATE
))
2861 goto nla_put_failure
;
2863 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2864 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2865 NL80211_STA_INFO_RX_BITRATE
))
2866 goto nla_put_failure
;
2868 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
2869 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2871 goto nla_put_failure
;
2872 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
2873 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2875 goto nla_put_failure
;
2876 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
2877 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2879 goto nla_put_failure
;
2880 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
2881 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
2883 goto nla_put_failure
;
2884 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
2885 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
2886 sinfo
->beacon_loss_count
))
2887 goto nla_put_failure
;
2888 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2889 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2891 goto nla_put_failure
;
2893 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
2894 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
2895 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
2896 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
2897 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
2898 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
2899 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2900 sinfo
->bss_param
.dtim_period
) ||
2901 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2902 sinfo
->bss_param
.beacon_interval
))
2903 goto nla_put_failure
;
2905 nla_nest_end(msg
, bss_param
);
2907 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
2908 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
2909 sizeof(struct nl80211_sta_flag_update
),
2911 goto nla_put_failure
;
2912 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
2913 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
2915 goto nla_put_failure
;
2916 nla_nest_end(msg
, sinfoattr
);
2918 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
2919 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2920 sinfo
->assoc_req_ies
))
2921 goto nla_put_failure
;
2923 return genlmsg_end(msg
, hdr
);
2926 genlmsg_cancel(msg
, hdr
);
2930 static int nl80211_dump_station(struct sk_buff
*skb
,
2931 struct netlink_callback
*cb
)
2933 struct station_info sinfo
;
2934 struct cfg80211_registered_device
*dev
;
2935 struct net_device
*netdev
;
2936 u8 mac_addr
[ETH_ALEN
];
2937 int sta_idx
= cb
->args
[1];
2940 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2944 if (!dev
->ops
->dump_station
) {
2950 memset(&sinfo
, 0, sizeof(sinfo
));
2951 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2958 if (nl80211_send_station(skb
,
2959 NETLINK_CB(cb
->skb
).portid
,
2960 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2961 dev
, netdev
, mac_addr
,
2970 cb
->args
[1] = sta_idx
;
2973 nl80211_finish_netdev_dump(dev
);
2978 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2980 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2981 struct net_device
*dev
= info
->user_ptr
[1];
2982 struct station_info sinfo
;
2983 struct sk_buff
*msg
;
2984 u8
*mac_addr
= NULL
;
2987 memset(&sinfo
, 0, sizeof(sinfo
));
2989 if (!info
->attrs
[NL80211_ATTR_MAC
])
2992 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2994 if (!rdev
->ops
->get_station
)
2997 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
3001 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3005 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3006 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3011 return genlmsg_reply(msg
, info
);
3015 * Get vlan interface making sure it is running and on the right wiphy.
3017 static struct net_device
*get_vlan(struct genl_info
*info
,
3018 struct cfg80211_registered_device
*rdev
)
3020 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3021 struct net_device
*v
;
3027 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3029 return ERR_PTR(-ENODEV
);
3031 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3036 if (!netif_running(v
)) {
3044 return ERR_PTR(ret
);
3047 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3049 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3051 struct net_device
*dev
= info
->user_ptr
[1];
3052 struct station_parameters params
;
3053 u8
*mac_addr
= NULL
;
3055 memset(¶ms
, 0, sizeof(params
));
3057 params
.listen_interval
= -1;
3058 params
.plink_state
= -1;
3060 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3063 if (!info
->attrs
[NL80211_ATTR_MAC
])
3066 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3068 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3069 params
.supported_rates
=
3070 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3071 params
.supported_rates_len
=
3072 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3075 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3076 params
.listen_interval
=
3077 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3079 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3081 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3083 if (!rdev
->ops
->change_station
)
3086 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3089 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3090 params
.plink_action
=
3091 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3093 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
3094 params
.plink_state
=
3095 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3097 switch (dev
->ieee80211_ptr
->iftype
) {
3098 case NL80211_IFTYPE_AP
:
3099 case NL80211_IFTYPE_AP_VLAN
:
3100 case NL80211_IFTYPE_P2P_GO
:
3101 /* disallow mesh-specific things */
3102 if (params
.plink_action
)
3105 /* TDLS can't be set, ... */
3106 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3109 * ... but don't bother the driver with it. This works around
3110 * a hostapd/wpa_supplicant issue -- it always includes the
3111 * TLDS_PEER flag in the mask even for AP mode.
3113 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3115 /* accept only the listed bits */
3116 if (params
.sta_flags_mask
&
3117 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3118 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3119 BIT(NL80211_STA_FLAG_WME
) |
3120 BIT(NL80211_STA_FLAG_MFP
)))
3123 /* must be last in here for error handling */
3124 params
.vlan
= get_vlan(info
, rdev
);
3125 if (IS_ERR(params
.vlan
))
3126 return PTR_ERR(params
.vlan
);
3128 case NL80211_IFTYPE_P2P_CLIENT
:
3129 case NL80211_IFTYPE_STATION
:
3131 * Don't allow userspace to change the TDLS_PEER flag,
3132 * but silently ignore attempts to change it since we
3133 * don't have state here to verify that it doesn't try
3134 * to change the flag.
3136 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3138 case NL80211_IFTYPE_ADHOC
:
3139 /* disallow things sta doesn't support */
3140 if (params
.plink_action
)
3144 if (params
.listen_interval
>= 0)
3146 /* reject any changes other than AUTHORIZED */
3147 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3150 case NL80211_IFTYPE_MESH_POINT
:
3151 /* disallow things mesh doesn't support */
3156 if (params
.listen_interval
>= 0)
3159 * No special handling for TDLS here -- the userspace
3160 * mesh code doesn't have this bug.
3162 if (params
.sta_flags_mask
&
3163 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3164 BIT(NL80211_STA_FLAG_MFP
) |
3165 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3172 /* be aware of params.vlan when changing code here */
3174 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3177 dev_put(params
.vlan
);
3182 static struct nla_policy
3183 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3184 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3185 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3188 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3190 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3192 struct net_device
*dev
= info
->user_ptr
[1];
3193 struct station_parameters params
;
3194 u8
*mac_addr
= NULL
;
3196 memset(¶ms
, 0, sizeof(params
));
3198 if (!info
->attrs
[NL80211_ATTR_MAC
])
3201 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3204 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3207 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3210 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3211 params
.supported_rates
=
3212 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3213 params
.supported_rates_len
=
3214 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3215 params
.listen_interval
=
3216 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3218 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3219 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3222 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3224 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3226 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3227 params
.plink_action
=
3228 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3230 if (!rdev
->ops
->add_station
)
3233 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3236 switch (dev
->ieee80211_ptr
->iftype
) {
3237 case NL80211_IFTYPE_AP
:
3238 case NL80211_IFTYPE_AP_VLAN
:
3239 case NL80211_IFTYPE_P2P_GO
:
3240 /* parse WME attributes if sta is WME capable */
3241 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
3242 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
3243 info
->attrs
[NL80211_ATTR_STA_WME
]) {
3244 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3247 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3248 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3249 nl80211_sta_wme_policy
);
3253 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3254 params
.uapsd_queues
=
3255 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3256 if (params
.uapsd_queues
&
3257 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3260 if (tb
[NL80211_STA_WME_MAX_SP
])
3262 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3265 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3268 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3270 /* TDLS peers cannot be added */
3271 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3273 /* but don't bother the driver with it */
3274 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3276 /* must be last in here for error handling */
3277 params
.vlan
= get_vlan(info
, rdev
);
3278 if (IS_ERR(params
.vlan
))
3279 return PTR_ERR(params
.vlan
);
3281 case NL80211_IFTYPE_MESH_POINT
:
3282 /* TDLS peers cannot be added */
3283 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3286 case NL80211_IFTYPE_STATION
:
3287 /* Only TDLS peers can be added */
3288 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3290 /* Can only add if TDLS ... */
3291 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3293 /* ... with external setup is supported */
3294 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3301 /* be aware of params.vlan when changing code here */
3303 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3306 dev_put(params
.vlan
);
3310 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
3312 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3313 struct net_device
*dev
= info
->user_ptr
[1];
3314 u8
*mac_addr
= NULL
;
3316 if (info
->attrs
[NL80211_ATTR_MAC
])
3317 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3319 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3320 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3321 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
3322 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3325 if (!rdev
->ops
->del_station
)
3328 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
3331 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3332 int flags
, struct net_device
*dev
,
3333 u8
*dst
, u8
*next_hop
,
3334 struct mpath_info
*pinfo
)
3337 struct nlattr
*pinfoattr
;
3339 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3343 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3344 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
3345 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
3346 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
3347 goto nla_put_failure
;
3349 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
3351 goto nla_put_failure
;
3352 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
3353 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
3355 goto nla_put_failure
;
3356 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
3357 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
3358 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
3359 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
3361 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
3362 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
3364 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
3365 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
3367 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
3368 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
3369 pinfo
->discovery_timeout
)) ||
3370 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
3371 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
3372 pinfo
->discovery_retries
)))
3373 goto nla_put_failure
;
3375 nla_nest_end(msg
, pinfoattr
);
3377 return genlmsg_end(msg
, hdr
);
3380 genlmsg_cancel(msg
, hdr
);
3384 static int nl80211_dump_mpath(struct sk_buff
*skb
,
3385 struct netlink_callback
*cb
)
3387 struct mpath_info pinfo
;
3388 struct cfg80211_registered_device
*dev
;
3389 struct net_device
*netdev
;
3391 u8 next_hop
[ETH_ALEN
];
3392 int path_idx
= cb
->args
[1];
3395 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3399 if (!dev
->ops
->dump_mpath
) {
3404 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
3410 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
3411 dst
, next_hop
, &pinfo
);
3417 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
3418 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3419 netdev
, dst
, next_hop
,
3428 cb
->args
[1] = path_idx
;
3431 nl80211_finish_netdev_dump(dev
);
3435 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3437 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3439 struct net_device
*dev
= info
->user_ptr
[1];
3440 struct mpath_info pinfo
;
3441 struct sk_buff
*msg
;
3443 u8 next_hop
[ETH_ALEN
];
3445 memset(&pinfo
, 0, sizeof(pinfo
));
3447 if (!info
->attrs
[NL80211_ATTR_MAC
])
3450 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3452 if (!rdev
->ops
->get_mpath
)
3455 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3458 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
3462 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3466 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3467 dev
, dst
, next_hop
, &pinfo
) < 0) {
3472 return genlmsg_reply(msg
, info
);
3475 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3477 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3478 struct net_device
*dev
= info
->user_ptr
[1];
3480 u8
*next_hop
= NULL
;
3482 if (!info
->attrs
[NL80211_ATTR_MAC
])
3485 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3488 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3489 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3491 if (!rdev
->ops
->change_mpath
)
3494 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3497 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3500 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3502 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3503 struct net_device
*dev
= info
->user_ptr
[1];
3505 u8
*next_hop
= NULL
;
3507 if (!info
->attrs
[NL80211_ATTR_MAC
])
3510 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3513 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3514 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3516 if (!rdev
->ops
->add_mpath
)
3519 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3522 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3525 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3527 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3528 struct net_device
*dev
= info
->user_ptr
[1];
3531 if (info
->attrs
[NL80211_ATTR_MAC
])
3532 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3534 if (!rdev
->ops
->del_mpath
)
3537 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
3540 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
3542 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3543 struct net_device
*dev
= info
->user_ptr
[1];
3544 struct bss_parameters params
;
3546 memset(¶ms
, 0, sizeof(params
));
3547 /* default to not changing parameters */
3548 params
.use_cts_prot
= -1;
3549 params
.use_short_preamble
= -1;
3550 params
.use_short_slot_time
= -1;
3551 params
.ap_isolate
= -1;
3552 params
.ht_opmode
= -1;
3554 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
3555 params
.use_cts_prot
=
3556 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
3557 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
3558 params
.use_short_preamble
=
3559 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
3560 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
3561 params
.use_short_slot_time
=
3562 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
3563 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3564 params
.basic_rates
=
3565 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3566 params
.basic_rates_len
=
3567 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3569 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
3570 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
3571 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
3573 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
3575 if (!rdev
->ops
->change_bss
)
3578 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3579 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3582 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
3585 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
3586 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3587 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3588 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3589 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3590 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3591 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3594 static int parse_reg_rule(struct nlattr
*tb
[],
3595 struct ieee80211_reg_rule
*reg_rule
)
3597 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3598 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3600 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3602 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3604 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3606 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3608 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3611 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3613 freq_range
->start_freq_khz
=
3614 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3615 freq_range
->end_freq_khz
=
3616 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3617 freq_range
->max_bandwidth_khz
=
3618 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3620 power_rule
->max_eirp
=
3621 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3623 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3624 power_rule
->max_antenna_gain
=
3625 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3630 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3634 enum nl80211_user_reg_hint_type user_reg_hint_type
;
3637 * You should only get this when cfg80211 hasn't yet initialized
3638 * completely when built-in to the kernel right between the time
3639 * window between nl80211_init() and regulatory_init(), if that is
3642 mutex_lock(&cfg80211_mutex
);
3643 if (unlikely(!cfg80211_regdomain
)) {
3644 mutex_unlock(&cfg80211_mutex
);
3645 return -EINPROGRESS
;
3647 mutex_unlock(&cfg80211_mutex
);
3649 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3652 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3654 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
3655 user_reg_hint_type
=
3656 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
3658 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
3660 switch (user_reg_hint_type
) {
3661 case NL80211_USER_REG_HINT_USER
:
3662 case NL80211_USER_REG_HINT_CELL_BASE
:
3668 r
= regulatory_hint_user(data
, user_reg_hint_type
);
3673 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3674 struct genl_info
*info
)
3676 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3677 struct net_device
*dev
= info
->user_ptr
[1];
3678 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3679 struct mesh_config cur_params
;
3682 struct nlattr
*pinfoattr
;
3683 struct sk_buff
*msg
;
3685 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3688 if (!rdev
->ops
->get_mesh_config
)
3692 /* If not connected, get default parameters */
3693 if (!wdev
->mesh_id_len
)
3694 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3696 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3703 /* Draw up a netlink message to send back */
3704 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3707 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3708 NL80211_CMD_GET_MESH_CONFIG
);
3711 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3713 goto nla_put_failure
;
3714 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3715 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3716 cur_params
.dot11MeshRetryTimeout
) ||
3717 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3718 cur_params
.dot11MeshConfirmTimeout
) ||
3719 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3720 cur_params
.dot11MeshHoldingTimeout
) ||
3721 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3722 cur_params
.dot11MeshMaxPeerLinks
) ||
3723 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3724 cur_params
.dot11MeshMaxRetries
) ||
3725 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
3726 cur_params
.dot11MeshTTL
) ||
3727 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3728 cur_params
.element_ttl
) ||
3729 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3730 cur_params
.auto_open_plinks
) ||
3731 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3732 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
3733 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3734 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
3735 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3736 cur_params
.path_refresh_time
) ||
3737 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3738 cur_params
.min_discovery_timeout
) ||
3739 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3740 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
3741 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3742 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
3743 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3744 cur_params
.dot11MeshHWMPperrMinInterval
) ||
3745 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3746 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
3747 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3748 cur_params
.dot11MeshHWMPRootMode
) ||
3749 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3750 cur_params
.dot11MeshHWMPRannInterval
) ||
3751 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3752 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
3753 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
3754 cur_params
.dot11MeshForwarding
) ||
3755 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3756 cur_params
.rssi_threshold
) ||
3757 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
3758 cur_params
.ht_opmode
) ||
3759 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3760 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
3761 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3762 cur_params
.dot11MeshHWMProotInterval
) ||
3763 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3764 cur_params
.dot11MeshHWMPconfirmationInterval
))
3765 goto nla_put_failure
;
3766 nla_nest_end(msg
, pinfoattr
);
3767 genlmsg_end(msg
, hdr
);
3768 return genlmsg_reply(msg
, info
);
3771 genlmsg_cancel(msg
, hdr
);
3777 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3778 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3779 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3780 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3781 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3782 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3783 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3784 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3785 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3786 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
3787 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3788 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3789 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3790 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3791 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3792 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
3793 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3794 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3795 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3796 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3797 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
3798 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
3799 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
3800 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
3801 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
3802 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
3805 static const struct nla_policy
3806 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3807 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
3808 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3809 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3810 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3811 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3812 .len
= IEEE80211_MAX_DATA_LEN
},
3813 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3816 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3817 struct mesh_config
*cfg
,
3820 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3823 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3825 if (table[attr_num]) {\
3826 cfg->param = nla_fn(table[attr_num]); \
3827 mask |= (1 << (attr_num - 1)); \
3832 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3834 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3835 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3836 nl80211_meshconf_params_policy
))
3839 /* This makes sure that there aren't more than 32 mesh config
3840 * parameters (otherwise our bitfield scheme would not work.) */
3841 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3843 /* Fill in the params struct */
3844 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3845 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3847 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3848 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3850 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3851 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3853 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3854 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3856 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3857 mask
, NL80211_MESHCONF_MAX_RETRIES
,
3859 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3860 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3861 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3862 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
3864 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3865 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3867 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
, mask
,
3868 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3870 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3871 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3873 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3874 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3876 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3877 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3879 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
, mask
,
3880 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3882 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3883 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3885 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
3886 mask
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3888 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3889 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
3890 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3892 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
3893 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
3894 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
3895 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3897 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3898 dot11MeshGateAnnouncementProtocol
, mask
,
3899 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3901 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
,
3902 mask
, NL80211_MESHCONF_FORWARDING
,
3904 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
,
3905 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3907 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
,
3908 mask
, NL80211_MESHCONF_HT_OPMODE
,
3910 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
3912 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3914 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
,
3915 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3917 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3918 dot11MeshHWMPconfirmationInterval
, mask
,
3919 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3926 #undef FILL_IN_MESH_PARAM_IF_SET
3929 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3930 struct mesh_setup
*setup
)
3932 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3934 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3936 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3937 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3938 nl80211_mesh_setup_params_policy
))
3941 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
3942 setup
->sync_method
=
3943 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
3944 IEEE80211_SYNC_METHOD_VENDOR
:
3945 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
3947 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3948 setup
->path_sel_proto
=
3949 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3950 IEEE80211_PATH_PROTOCOL_VENDOR
:
3951 IEEE80211_PATH_PROTOCOL_HWMP
;
3953 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3954 setup
->path_metric
=
3955 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3956 IEEE80211_PATH_METRIC_VENDOR
:
3957 IEEE80211_PATH_METRIC_AIRTIME
;
3960 if (tb
[NL80211_MESH_SETUP_IE
]) {
3961 struct nlattr
*ieattr
=
3962 tb
[NL80211_MESH_SETUP_IE
];
3963 if (!is_valid_ie_attr(ieattr
))
3965 setup
->ie
= nla_data(ieattr
);
3966 setup
->ie_len
= nla_len(ieattr
);
3968 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3969 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3974 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3975 struct genl_info
*info
)
3977 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3978 struct net_device
*dev
= info
->user_ptr
[1];
3979 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3980 struct mesh_config cfg
;
3984 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3987 if (!rdev
->ops
->update_mesh_config
)
3990 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3995 if (!wdev
->mesh_id_len
)
3999 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
4007 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4009 struct sk_buff
*msg
;
4011 struct nlattr
*nl_reg_rules
;
4015 mutex_lock(&cfg80211_mutex
);
4017 if (!cfg80211_regdomain
)
4020 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4026 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4027 NL80211_CMD_GET_REG
);
4031 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
4032 cfg80211_regdomain
->alpha2
) ||
4033 (cfg80211_regdomain
->dfs_region
&&
4034 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
,
4035 cfg80211_regdomain
->dfs_region
)))
4036 goto nla_put_failure
;
4038 if (reg_last_request_cell_base() &&
4039 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4040 NL80211_USER_REG_HINT_CELL_BASE
))
4041 goto nla_put_failure
;
4043 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4045 goto nla_put_failure
;
4047 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
4048 struct nlattr
*nl_reg_rule
;
4049 const struct ieee80211_reg_rule
*reg_rule
;
4050 const struct ieee80211_freq_range
*freq_range
;
4051 const struct ieee80211_power_rule
*power_rule
;
4053 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
4054 freq_range
= ®_rule
->freq_range
;
4055 power_rule
= ®_rule
->power_rule
;
4057 nl_reg_rule
= nla_nest_start(msg
, i
);
4059 goto nla_put_failure
;
4061 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4063 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4064 freq_range
->start_freq_khz
) ||
4065 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4066 freq_range
->end_freq_khz
) ||
4067 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4068 freq_range
->max_bandwidth_khz
) ||
4069 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4070 power_rule
->max_antenna_gain
) ||
4071 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4072 power_rule
->max_eirp
))
4073 goto nla_put_failure
;
4075 nla_nest_end(msg
, nl_reg_rule
);
4078 nla_nest_end(msg
, nl_reg_rules
);
4080 genlmsg_end(msg
, hdr
);
4081 err
= genlmsg_reply(msg
, info
);
4085 genlmsg_cancel(msg
, hdr
);
4090 mutex_unlock(&cfg80211_mutex
);
4094 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4096 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4097 struct nlattr
*nl_reg_rule
;
4098 char *alpha2
= NULL
;
4099 int rem_reg_rules
= 0, r
= 0;
4100 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4102 struct ieee80211_regdomain
*rd
= NULL
;
4104 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4107 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
4110 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4112 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
4113 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
4115 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4118 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
4122 mutex_lock(&cfg80211_mutex
);
4124 if (!reg_is_valid_request(alpha2
)) {
4129 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
4130 (num_rules
* sizeof(struct ieee80211_reg_rule
));
4132 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
4138 rd
->n_reg_rules
= num_rules
;
4139 rd
->alpha2
[0] = alpha2
[0];
4140 rd
->alpha2
[1] = alpha2
[1];
4143 * Disable DFS master mode if the DFS region was
4144 * not supported or known on this kernel.
4146 if (reg_supported_dfs_region(dfs_region
))
4147 rd
->dfs_region
= dfs_region
;
4149 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4151 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
4152 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
4154 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
4160 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
4166 BUG_ON(rule_idx
!= num_rules
);
4170 mutex_unlock(&cfg80211_mutex
);
4175 mutex_unlock(&cfg80211_mutex
);
4180 static int validate_scan_freqs(struct nlattr
*freqs
)
4182 struct nlattr
*attr1
, *attr2
;
4183 int n_channels
= 0, tmp1
, tmp2
;
4185 nla_for_each_nested(attr1
, freqs
, tmp1
) {
4188 * Some hardware has a limited channel list for
4189 * scanning, and it is pretty much nonsensical
4190 * to scan for a channel twice, so disallow that
4191 * and don't require drivers to check that the
4192 * channel list they get isn't longer than what
4193 * they can scan, as long as they can scan all
4194 * the channels they registered at once.
4196 nla_for_each_nested(attr2
, freqs
, tmp2
)
4197 if (attr1
!= attr2
&&
4198 nla_get_u32(attr1
) == nla_get_u32(attr2
))
4205 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
4207 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4208 struct wireless_dev
*wdev
= info
->user_ptr
[1];
4209 struct cfg80211_scan_request
*request
;
4210 struct nlattr
*attr
;
4211 struct wiphy
*wiphy
;
4212 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
4215 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4218 wiphy
= &rdev
->wiphy
;
4220 if (!rdev
->ops
->scan
)
4226 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4227 n_channels
= validate_scan_freqs(
4228 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4232 enum ieee80211_band band
;
4235 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4236 if (wiphy
->bands
[band
])
4237 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4240 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4241 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
4244 if (n_ssids
> wiphy
->max_scan_ssids
)
4247 if (info
->attrs
[NL80211_ATTR_IE
])
4248 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4252 if (ie_len
> wiphy
->max_scan_ie_len
)
4255 request
= kzalloc(sizeof(*request
)
4256 + sizeof(*request
->ssids
) * n_ssids
4257 + sizeof(*request
->channels
) * n_channels
4258 + ie_len
, GFP_KERNEL
);
4263 request
->ssids
= (void *)&request
->channels
[n_channels
];
4264 request
->n_ssids
= n_ssids
;
4267 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4269 request
->ie
= (void *)(request
->channels
+ n_channels
);
4273 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4274 /* user specified, bail out if channel not found */
4275 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
4276 struct ieee80211_channel
*chan
;
4278 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4285 /* ignore disabled channels */
4286 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4289 request
->channels
[i
] = chan
;
4293 enum ieee80211_band band
;
4296 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4298 if (!wiphy
->bands
[band
])
4300 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4301 struct ieee80211_channel
*chan
;
4303 chan
= &wiphy
->bands
[band
]->channels
[j
];
4305 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4308 request
->channels
[i
] = chan
;
4319 request
->n_channels
= i
;
4322 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4323 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
4324 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4328 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4329 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
4334 if (info
->attrs
[NL80211_ATTR_IE
]) {
4335 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4336 memcpy((void *)request
->ie
,
4337 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4341 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4342 if (wiphy
->bands
[i
])
4344 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
4346 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
4347 nla_for_each_nested(attr
,
4348 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
4350 enum ieee80211_band band
= nla_type(attr
);
4352 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4356 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
4359 &request
->rates
[band
]);
4366 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
4368 request
->wdev
= wdev
;
4369 request
->wiphy
= &rdev
->wiphy
;
4371 rdev
->scan_req
= request
;
4372 err
= rdev
->ops
->scan(&rdev
->wiphy
, request
);
4375 nl80211_send_scan_start(rdev
, wdev
);
4377 dev_hold(wdev
->netdev
);
4380 rdev
->scan_req
= NULL
;
4387 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
4388 struct genl_info
*info
)
4390 struct cfg80211_sched_scan_request
*request
;
4391 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4392 struct net_device
*dev
= info
->user_ptr
[1];
4393 struct nlattr
*attr
;
4394 struct wiphy
*wiphy
;
4395 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
4397 enum ieee80211_band band
;
4399 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
4401 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4402 !rdev
->ops
->sched_scan_start
)
4405 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4408 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
4411 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
4415 wiphy
= &rdev
->wiphy
;
4417 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4418 n_channels
= validate_scan_freqs(
4419 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4425 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4426 if (wiphy
->bands
[band
])
4427 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4430 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4431 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4435 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
4438 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
4439 nla_for_each_nested(attr
,
4440 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4444 if (n_match_sets
> wiphy
->max_match_sets
)
4447 if (info
->attrs
[NL80211_ATTR_IE
])
4448 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4452 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
4455 mutex_lock(&rdev
->sched_scan_mtx
);
4457 if (rdev
->sched_scan_req
) {
4462 request
= kzalloc(sizeof(*request
)
4463 + sizeof(*request
->ssids
) * n_ssids
4464 + sizeof(*request
->match_sets
) * n_match_sets
4465 + sizeof(*request
->channels
) * n_channels
4466 + ie_len
, GFP_KERNEL
);
4473 request
->ssids
= (void *)&request
->channels
[n_channels
];
4474 request
->n_ssids
= n_ssids
;
4477 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4479 request
->ie
= (void *)(request
->channels
+ n_channels
);
4484 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
4485 else if (request
->ssids
)
4486 request
->match_sets
=
4487 (void *)(request
->ssids
+ n_ssids
);
4489 request
->match_sets
=
4490 (void *)(request
->channels
+ n_channels
);
4492 request
->n_match_sets
= n_match_sets
;
4495 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4496 /* user specified, bail out if channel not found */
4497 nla_for_each_nested(attr
,
4498 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
4500 struct ieee80211_channel
*chan
;
4502 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4509 /* ignore disabled channels */
4510 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4513 request
->channels
[i
] = chan
;
4518 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4520 if (!wiphy
->bands
[band
])
4522 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4523 struct ieee80211_channel
*chan
;
4525 chan
= &wiphy
->bands
[band
]->channels
[j
];
4527 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4530 request
->channels
[i
] = chan
;
4541 request
->n_channels
= i
;
4544 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4545 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4547 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4551 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4552 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
4559 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
4560 nla_for_each_nested(attr
,
4561 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4563 struct nlattr
*ssid
, *rssi
;
4565 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
4566 nla_data(attr
), nla_len(attr
),
4567 nl80211_match_policy
);
4568 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
4570 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
4574 memcpy(request
->match_sets
[i
].ssid
.ssid
,
4575 nla_data(ssid
), nla_len(ssid
));
4576 request
->match_sets
[i
].ssid
.ssid_len
=
4579 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
4581 request
->rssi_thold
= nla_get_u32(rssi
);
4583 request
->rssi_thold
=
4584 NL80211_SCAN_RSSI_THOLD_OFF
;
4589 if (info
->attrs
[NL80211_ATTR_IE
]) {
4590 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4591 memcpy((void *)request
->ie
,
4592 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4597 request
->wiphy
= &rdev
->wiphy
;
4598 request
->interval
= interval
;
4600 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
4602 rdev
->sched_scan_req
= request
;
4603 nl80211_send_sched_scan(rdev
, dev
,
4604 NL80211_CMD_START_SCHED_SCAN
);
4611 mutex_unlock(&rdev
->sched_scan_mtx
);
4615 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
4616 struct genl_info
*info
)
4618 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4621 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4622 !rdev
->ops
->sched_scan_stop
)
4625 mutex_lock(&rdev
->sched_scan_mtx
);
4626 err
= __cfg80211_stop_sched_scan(rdev
, false);
4627 mutex_unlock(&rdev
->sched_scan_mtx
);
4632 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
4634 struct cfg80211_registered_device
*rdev
,
4635 struct wireless_dev
*wdev
,
4636 struct cfg80211_internal_bss
*intbss
)
4638 struct cfg80211_bss
*res
= &intbss
->pub
;
4642 ASSERT_WDEV_LOCK(wdev
);
4644 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
4645 NL80211_CMD_NEW_SCAN_RESULTS
);
4649 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
4651 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
) ||
4652 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
4653 goto nla_put_failure
;
4655 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
4657 goto nla_put_failure
;
4658 if ((!is_zero_ether_addr(res
->bssid
) &&
4659 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)) ||
4660 (res
->information_elements
&& res
->len_information_elements
&&
4661 nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
4662 res
->len_information_elements
,
4663 res
->information_elements
)) ||
4664 (res
->beacon_ies
&& res
->len_beacon_ies
&&
4665 res
->beacon_ies
!= res
->information_elements
&&
4666 nla_put(msg
, NL80211_BSS_BEACON_IES
,
4667 res
->len_beacon_ies
, res
->beacon_ies
)))
4668 goto nla_put_failure
;
4670 nla_put_u64(msg
, NL80211_BSS_TSF
, res
->tsf
))
4671 goto nla_put_failure
;
4672 if (res
->beacon_interval
&&
4673 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
4674 goto nla_put_failure
;
4675 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
4676 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
4677 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
4678 jiffies_to_msecs(jiffies
- intbss
->ts
)))
4679 goto nla_put_failure
;
4681 switch (rdev
->wiphy
.signal_type
) {
4682 case CFG80211_SIGNAL_TYPE_MBM
:
4683 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
4684 goto nla_put_failure
;
4686 case CFG80211_SIGNAL_TYPE_UNSPEC
:
4687 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
4688 goto nla_put_failure
;
4694 switch (wdev
->iftype
) {
4695 case NL80211_IFTYPE_P2P_CLIENT
:
4696 case NL80211_IFTYPE_STATION
:
4697 if (intbss
== wdev
->current_bss
&&
4698 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4699 NL80211_BSS_STATUS_ASSOCIATED
))
4700 goto nla_put_failure
;
4702 case NL80211_IFTYPE_ADHOC
:
4703 if (intbss
== wdev
->current_bss
&&
4704 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4705 NL80211_BSS_STATUS_IBSS_JOINED
))
4706 goto nla_put_failure
;
4712 nla_nest_end(msg
, bss
);
4714 return genlmsg_end(msg
, hdr
);
4717 genlmsg_cancel(msg
, hdr
);
4721 static int nl80211_dump_scan(struct sk_buff
*skb
,
4722 struct netlink_callback
*cb
)
4724 struct cfg80211_registered_device
*rdev
;
4725 struct net_device
*dev
;
4726 struct cfg80211_internal_bss
*scan
;
4727 struct wireless_dev
*wdev
;
4728 int start
= cb
->args
[1], idx
= 0;
4731 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4735 wdev
= dev
->ieee80211_ptr
;
4738 spin_lock_bh(&rdev
->bss_lock
);
4739 cfg80211_bss_expire(rdev
);
4741 cb
->seq
= rdev
->bss_generation
;
4743 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4746 if (nl80211_send_bss(skb
, cb
,
4747 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4748 rdev
, wdev
, scan
) < 0) {
4754 spin_unlock_bh(&rdev
->bss_lock
);
4758 nl80211_finish_netdev_dump(rdev
);
4763 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4764 int flags
, struct net_device
*dev
,
4765 struct survey_info
*survey
)
4768 struct nlattr
*infoattr
;
4770 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
4771 NL80211_CMD_NEW_SURVEY_RESULTS
);
4775 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
4776 goto nla_put_failure
;
4778 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4780 goto nla_put_failure
;
4782 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4783 survey
->channel
->center_freq
))
4784 goto nla_put_failure
;
4786 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
4787 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
4788 goto nla_put_failure
;
4789 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
4790 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
4791 goto nla_put_failure
;
4792 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
4793 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4794 survey
->channel_time
))
4795 goto nla_put_failure
;
4796 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
4797 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4798 survey
->channel_time_busy
))
4799 goto nla_put_failure
;
4800 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
4801 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4802 survey
->channel_time_ext_busy
))
4803 goto nla_put_failure
;
4804 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
4805 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4806 survey
->channel_time_rx
))
4807 goto nla_put_failure
;
4808 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
4809 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4810 survey
->channel_time_tx
))
4811 goto nla_put_failure
;
4813 nla_nest_end(msg
, infoattr
);
4815 return genlmsg_end(msg
, hdr
);
4818 genlmsg_cancel(msg
, hdr
);
4822 static int nl80211_dump_survey(struct sk_buff
*skb
,
4823 struct netlink_callback
*cb
)
4825 struct survey_info survey
;
4826 struct cfg80211_registered_device
*dev
;
4827 struct net_device
*netdev
;
4828 int survey_idx
= cb
->args
[1];
4831 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4835 if (!dev
->ops
->dump_survey
) {
4841 struct ieee80211_channel
*chan
;
4843 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4850 /* Survey without a channel doesn't make sense */
4851 if (!survey
.channel
) {
4856 chan
= ieee80211_get_channel(&dev
->wiphy
,
4857 survey
.channel
->center_freq
);
4858 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4863 if (nl80211_send_survey(skb
,
4864 NETLINK_CB(cb
->skb
).portid
,
4865 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4873 cb
->args
[1] = survey_idx
;
4876 nl80211_finish_netdev_dump(dev
);
4880 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4882 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4883 NL80211_WPA_VERSION_2
));
4886 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4888 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4889 struct net_device
*dev
= info
->user_ptr
[1];
4890 struct ieee80211_channel
*chan
;
4891 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
4892 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
4893 enum nl80211_auth_type auth_type
;
4894 struct key_parse key
;
4895 bool local_state_change
;
4897 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4900 if (!info
->attrs
[NL80211_ATTR_MAC
])
4903 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4906 if (!info
->attrs
[NL80211_ATTR_SSID
])
4909 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4912 err
= nl80211_parse_key(info
, &key
);
4917 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4919 if (!key
.p
.key
|| !key
.p
.key_len
)
4921 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4922 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4923 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4924 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4936 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4937 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4946 if (!rdev
->ops
->auth
)
4949 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4950 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4953 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4954 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4955 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4956 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4959 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4960 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4962 if (info
->attrs
[NL80211_ATTR_IE
]) {
4963 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4964 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4967 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4968 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
4971 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
4972 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
4975 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
4976 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
4978 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
4979 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
4980 /* need to include at least Auth Transaction and Status Code */
4981 if (sae_data_len
< 4)
4985 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4988 * Since we no longer track auth state, ignore
4989 * requests to only change local state.
4991 if (local_state_change
)
4994 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4995 ssid
, ssid_len
, ie
, ie_len
,
4996 key
.p
.key
, key
.p
.key_len
, key
.idx
,
4997 sae_data
, sae_data_len
);
5000 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5001 struct genl_info
*info
,
5002 struct cfg80211_crypto_settings
*settings
,
5005 memset(settings
, 0, sizeof(*settings
));
5007 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5009 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5011 proto
= nla_get_u16(
5012 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5013 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5014 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5017 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5018 settings
->control_port_no_encrypt
= true;
5020 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5022 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5026 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5027 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5028 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
5030 if (len
% sizeof(u32
))
5033 if (settings
->n_ciphers_pairwise
> cipher_limit
)
5036 memcpy(settings
->ciphers_pairwise
, data
, len
);
5038 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
5039 if (!cfg80211_supported_cipher_suite(
5041 settings
->ciphers_pairwise
[i
]))
5045 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
5046 settings
->cipher_group
=
5047 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
5048 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
5049 settings
->cipher_group
))
5053 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
5054 settings
->wpa_versions
=
5055 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
5056 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
5060 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
5064 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5065 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5066 settings
->n_akm_suites
= len
/ sizeof(u32
);
5068 if (len
% sizeof(u32
))
5071 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
5074 memcpy(settings
->akm_suites
, data
, len
);
5080 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
5082 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5083 struct net_device
*dev
= info
->user_ptr
[1];
5084 struct cfg80211_crypto_settings crypto
;
5085 struct ieee80211_channel
*chan
;
5086 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
5087 int err
, ssid_len
, ie_len
= 0;
5088 bool use_mfp
= false;
5090 struct ieee80211_ht_cap
*ht_capa
= NULL
;
5091 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
5093 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5096 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
5097 !info
->attrs
[NL80211_ATTR_SSID
] ||
5098 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5101 if (!rdev
->ops
->assoc
)
5104 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5105 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5108 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5110 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5111 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5112 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5115 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5116 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5118 if (info
->attrs
[NL80211_ATTR_IE
]) {
5119 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5120 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5123 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
5124 enum nl80211_mfp mfp
=
5125 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
5126 if (mfp
== NL80211_MFP_REQUIRED
)
5128 else if (mfp
!= NL80211_MFP_NO
)
5132 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
5133 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
5135 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5136 flags
|= ASSOC_REQ_DISABLE_HT
;
5138 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5140 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
5142 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5145 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5148 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
5150 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
5151 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
5152 &crypto
, flags
, ht_capa
,
5158 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5160 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5161 struct net_device
*dev
= info
->user_ptr
[1];
5162 const u8
*ie
= NULL
, *bssid
;
5165 bool local_state_change
;
5167 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5170 if (!info
->attrs
[NL80211_ATTR_MAC
])
5173 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5176 if (!rdev
->ops
->deauth
)
5179 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5180 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5183 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5185 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5186 if (reason_code
== 0) {
5187 /* Reason Code 0 is reserved */
5191 if (info
->attrs
[NL80211_ATTR_IE
]) {
5192 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5193 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5196 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5198 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5199 local_state_change
);
5202 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
5204 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5205 struct net_device
*dev
= info
->user_ptr
[1];
5206 const u8
*ie
= NULL
, *bssid
;
5209 bool local_state_change
;
5211 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5214 if (!info
->attrs
[NL80211_ATTR_MAC
])
5217 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5220 if (!rdev
->ops
->disassoc
)
5223 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5224 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5227 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5229 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5230 if (reason_code
== 0) {
5231 /* Reason Code 0 is reserved */
5235 if (info
->attrs
[NL80211_ATTR_IE
]) {
5236 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5237 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5240 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5242 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5243 local_state_change
);
5247 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
5248 int mcast_rate
[IEEE80211_NUM_BANDS
],
5251 struct wiphy
*wiphy
= &rdev
->wiphy
;
5255 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5256 struct ieee80211_supported_band
*sband
;
5258 sband
= wiphy
->bands
[band
];
5262 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
5263 if (sband
->bitrates
[i
].bitrate
== rateval
) {
5264 mcast_rate
[band
] = i
+ 1;
5274 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5276 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5277 struct net_device
*dev
= info
->user_ptr
[1];
5278 struct cfg80211_ibss_params ibss
;
5279 struct wiphy
*wiphy
;
5280 struct cfg80211_cached_keys
*connkeys
= NULL
;
5283 memset(&ibss
, 0, sizeof(ibss
));
5285 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5288 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5289 !info
->attrs
[NL80211_ATTR_SSID
] ||
5290 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5293 ibss
.beacon_interval
= 100;
5295 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
5296 ibss
.beacon_interval
=
5297 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5298 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
5302 if (!rdev
->ops
->join_ibss
)
5305 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5308 wiphy
= &rdev
->wiphy
;
5310 if (info
->attrs
[NL80211_ATTR_MAC
]) {
5311 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5313 if (!is_valid_ether_addr(ibss
.bssid
))
5316 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5317 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5319 if (info
->attrs
[NL80211_ATTR_IE
]) {
5320 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5321 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5324 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5325 enum nl80211_channel_type channel_type
;
5327 if (!nl80211_valid_channel_type(info
, &channel_type
))
5330 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5331 !(wiphy
->features
& NL80211_FEATURE_HT_IBSS
))
5334 ibss
.channel_type
= channel_type
;
5336 ibss
.channel_type
= NL80211_CHAN_NO_HT
;
5339 ibss
.channel
= rdev_freq_to_chan(rdev
,
5340 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
5342 if (!ibss
.channel
||
5343 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
5344 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5347 /* Both channels should be able to initiate communication */
5348 if ((ibss
.channel_type
== NL80211_CHAN_HT40PLUS
||
5349 ibss
.channel_type
== NL80211_CHAN_HT40MINUS
) &&
5350 !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, ibss
.channel
,
5354 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
5355 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5357 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5359 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5361 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5362 struct ieee80211_supported_band
*sband
=
5363 wiphy
->bands
[ibss
.channel
->band
];
5365 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
5371 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5372 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
5373 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5376 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5377 connkeys
= nl80211_parse_connkeys(rdev
,
5378 info
->attrs
[NL80211_ATTR_KEYS
]);
5379 if (IS_ERR(connkeys
))
5380 return PTR_ERR(connkeys
);
5384 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
5386 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
5392 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5394 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5395 struct net_device
*dev
= info
->user_ptr
[1];
5397 if (!rdev
->ops
->leave_ibss
)
5400 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5403 return cfg80211_leave_ibss(rdev
, dev
, false);
5406 #ifdef CONFIG_NL80211_TESTMODE
5407 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
5411 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
5413 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5416 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
5420 if (rdev
->ops
->testmode_cmd
) {
5421 rdev
->testmode_info
= info
;
5422 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
5423 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
5424 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
5425 rdev
->testmode_info
= NULL
;
5431 static int nl80211_testmode_dump(struct sk_buff
*skb
,
5432 struct netlink_callback
*cb
)
5434 struct cfg80211_registered_device
*rdev
;
5442 * 0 is a valid index, but not valid for args[0],
5443 * so we need to offset by 1.
5445 phy_idx
= cb
->args
[0] - 1;
5447 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
5448 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
5453 mutex_lock(&cfg80211_mutex
);
5454 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
5455 nl80211_fam
.attrbuf
);
5457 mutex_unlock(&cfg80211_mutex
);
5458 return PTR_ERR(rdev
);
5460 phy_idx
= rdev
->wiphy_idx
;
5462 mutex_unlock(&cfg80211_mutex
);
5464 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
5466 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
5470 data
= nla_data((void *)cb
->args
[1]);
5471 data_len
= nla_len((void *)cb
->args
[1]);
5474 mutex_lock(&cfg80211_mutex
);
5475 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
5477 mutex_unlock(&cfg80211_mutex
);
5480 cfg80211_lock_rdev(rdev
);
5481 mutex_unlock(&cfg80211_mutex
);
5483 if (!rdev
->ops
->testmode_dump
) {
5489 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
5490 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5491 NL80211_CMD_TESTMODE
);
5492 struct nlattr
*tmdata
;
5494 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
5495 genlmsg_cancel(skb
, hdr
);
5499 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5501 genlmsg_cancel(skb
, hdr
);
5504 err
= rdev
->ops
->testmode_dump(&rdev
->wiphy
, skb
, cb
,
5506 nla_nest_end(skb
, tmdata
);
5508 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
5509 genlmsg_cancel(skb
, hdr
);
5512 genlmsg_cancel(skb
, hdr
);
5516 genlmsg_end(skb
, hdr
);
5521 cb
->args
[0] = phy_idx
+ 1;
5523 cfg80211_unlock_rdev(rdev
);
5527 static struct sk_buff
*
5528 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
5529 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
5531 struct sk_buff
*skb
;
5533 struct nlattr
*data
;
5535 skb
= nlmsg_new(approxlen
+ 100, gfp
);
5539 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
5545 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
5546 goto nla_put_failure
;
5547 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5549 ((void **)skb
->cb
)[0] = rdev
;
5550 ((void **)skb
->cb
)[1] = hdr
;
5551 ((void **)skb
->cb
)[2] = data
;
5560 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
5563 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5565 if (WARN_ON(!rdev
->testmode_info
))
5568 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
5569 rdev
->testmode_info
->snd_portid
,
5570 rdev
->testmode_info
->snd_seq
,
5573 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
5575 int cfg80211_testmode_reply(struct sk_buff
*skb
)
5577 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
5578 void *hdr
= ((void **)skb
->cb
)[1];
5579 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5581 if (WARN_ON(!rdev
->testmode_info
)) {
5586 nla_nest_end(skb
, data
);
5587 genlmsg_end(skb
, hdr
);
5588 return genlmsg_reply(skb
, rdev
->testmode_info
);
5590 EXPORT_SYMBOL(cfg80211_testmode_reply
);
5592 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
5593 int approxlen
, gfp_t gfp
)
5595 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5597 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
5599 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
5601 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
5603 void *hdr
= ((void **)skb
->cb
)[1];
5604 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5606 nla_nest_end(skb
, data
);
5607 genlmsg_end(skb
, hdr
);
5608 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
5610 EXPORT_SYMBOL(cfg80211_testmode_event
);
5613 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
5615 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5616 struct net_device
*dev
= info
->user_ptr
[1];
5617 struct cfg80211_connect_params connect
;
5618 struct wiphy
*wiphy
;
5619 struct cfg80211_cached_keys
*connkeys
= NULL
;
5622 memset(&connect
, 0, sizeof(connect
));
5624 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5627 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5628 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5631 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5633 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5634 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
5635 NL80211_CMD_CONNECT
))
5638 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5640 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
5642 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
5643 NL80211_MAX_NR_CIPHER_SUITES
);
5647 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5648 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5651 wiphy
= &rdev
->wiphy
;
5653 connect
.bg_scan_period
= -1;
5654 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
5655 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
5656 connect
.bg_scan_period
=
5657 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
5660 if (info
->attrs
[NL80211_ATTR_MAC
])
5661 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5662 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5663 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5665 if (info
->attrs
[NL80211_ATTR_IE
]) {
5666 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5667 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5670 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5672 ieee80211_get_channel(wiphy
,
5673 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5674 if (!connect
.channel
||
5675 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5679 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5680 connkeys
= nl80211_parse_connkeys(rdev
,
5681 info
->attrs
[NL80211_ATTR_KEYS
]);
5682 if (IS_ERR(connkeys
))
5683 return PTR_ERR(connkeys
);
5686 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5687 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
5689 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5690 memcpy(&connect
.ht_capa_mask
,
5691 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
5692 sizeof(connect
.ht_capa_mask
));
5694 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5695 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
5699 memcpy(&connect
.ht_capa
,
5700 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
5701 sizeof(connect
.ht_capa
));
5704 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
5710 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
5712 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5713 struct net_device
*dev
= info
->user_ptr
[1];
5716 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5717 reason
= WLAN_REASON_DEAUTH_LEAVING
;
5719 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5724 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5725 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5728 return cfg80211_disconnect(rdev
, dev
, reason
, true);
5731 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
5733 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5738 if (!info
->attrs
[NL80211_ATTR_PID
])
5741 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
5743 net
= get_net_ns_by_pid(pid
);
5745 return PTR_ERR(net
);
5749 /* check if anything to do */
5750 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
5751 err
= cfg80211_switch_netns(rdev
, net
);
5757 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5759 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5760 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
5761 struct cfg80211_pmksa
*pmksa
) = NULL
;
5762 struct net_device
*dev
= info
->user_ptr
[1];
5763 struct cfg80211_pmksa pmksa
;
5765 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
5767 if (!info
->attrs
[NL80211_ATTR_MAC
])
5770 if (!info
->attrs
[NL80211_ATTR_PMKID
])
5773 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
5774 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5776 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5777 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5780 switch (info
->genlhdr
->cmd
) {
5781 case NL80211_CMD_SET_PMKSA
:
5782 rdev_ops
= rdev
->ops
->set_pmksa
;
5784 case NL80211_CMD_DEL_PMKSA
:
5785 rdev_ops
= rdev
->ops
->del_pmksa
;
5795 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
5798 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5800 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5801 struct net_device
*dev
= info
->user_ptr
[1];
5803 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5804 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5807 if (!rdev
->ops
->flush_pmksa
)
5810 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
5813 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5815 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5816 struct net_device
*dev
= info
->user_ptr
[1];
5817 u8 action_code
, dialog_token
;
5821 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5822 !rdev
->ops
->tdls_mgmt
)
5825 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5826 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5827 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5828 !info
->attrs
[NL80211_ATTR_IE
] ||
5829 !info
->attrs
[NL80211_ATTR_MAC
])
5832 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5833 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5834 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5835 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5837 return rdev
->ops
->tdls_mgmt(&rdev
->wiphy
, dev
, peer
, action_code
,
5838 dialog_token
, status_code
,
5839 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5840 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5843 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5845 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5846 struct net_device
*dev
= info
->user_ptr
[1];
5847 enum nl80211_tdls_operation operation
;
5850 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5851 !rdev
->ops
->tdls_oper
)
5854 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5855 !info
->attrs
[NL80211_ATTR_MAC
])
5858 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5859 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5861 return rdev
->ops
->tdls_oper(&rdev
->wiphy
, dev
, peer
, operation
);
5864 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5865 struct genl_info
*info
)
5867 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5868 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5869 struct ieee80211_channel
*chan
;
5870 struct sk_buff
*msg
;
5873 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5877 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5878 !info
->attrs
[NL80211_ATTR_DURATION
])
5881 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5883 if (!rdev
->ops
->remain_on_channel
||
5884 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
5888 * We should be on that channel for at least a minimum amount of
5889 * time (10ms) but no longer than the driver supports.
5891 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
5892 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5895 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
5896 !nl80211_valid_channel_type(info
, &channel_type
))
5899 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5900 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5904 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5908 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5909 NL80211_CMD_REMAIN_ON_CHANNEL
);
5916 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, wdev
, chan
,
5917 channel_type
, duration
, &cookie
);
5922 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
5923 goto nla_put_failure
;
5925 genlmsg_end(msg
, hdr
);
5927 return genlmsg_reply(msg
, info
);
5936 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5937 struct genl_info
*info
)
5939 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5940 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5943 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5946 if (!rdev
->ops
->cancel_remain_on_channel
)
5949 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5951 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, wdev
, cookie
);
5954 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5955 u8
*rates
, u8 rates_len
)
5960 for (i
= 0; i
< rates_len
; i
++) {
5961 int rate
= (rates
[i
] & 0x7f) * 5;
5963 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5964 struct ieee80211_rate
*srate
=
5965 &sband
->bitrates
[ridx
];
5966 if (rate
== srate
->bitrate
) {
5971 if (ridx
== sband
->n_bitrates
)
5972 return 0; /* rate not found */
5978 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
5979 u8
*rates
, u8 rates_len
,
5980 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
5984 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
5986 for (i
= 0; i
< rates_len
; i
++) {
5989 ridx
= rates
[i
] / 8;
5990 rbit
= BIT(rates
[i
] % 8);
5992 /* check validity */
5993 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
5996 /* check availability */
5997 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
6006 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
6007 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
6008 .len
= NL80211_MAX_SUPP_RATES
},
6009 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
6010 .len
= NL80211_MAX_SUPP_HT_RATES
},
6013 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
6014 struct genl_info
*info
)
6016 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
6017 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6018 struct cfg80211_bitrate_mask mask
;
6020 struct net_device
*dev
= info
->user_ptr
[1];
6021 struct nlattr
*tx_rates
;
6022 struct ieee80211_supported_band
*sband
;
6024 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
6027 if (!rdev
->ops
->set_bitrate_mask
)
6030 memset(&mask
, 0, sizeof(mask
));
6031 /* Default to all rates enabled */
6032 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
6033 sband
= rdev
->wiphy
.bands
[i
];
6034 mask
.control
[i
].legacy
=
6035 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
6037 memcpy(mask
.control
[i
].mcs
,
6038 sband
->ht_cap
.mcs
.rx_mask
,
6039 sizeof(mask
.control
[i
].mcs
));
6041 memset(mask
.control
[i
].mcs
, 0,
6042 sizeof(mask
.control
[i
].mcs
));
6046 * The nested attribute uses enum nl80211_band as the index. This maps
6047 * directly to the enum ieee80211_band values used in cfg80211.
6049 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
6050 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
6052 enum ieee80211_band band
= nla_type(tx_rates
);
6053 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
6055 sband
= rdev
->wiphy
.bands
[band
];
6058 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
6059 nla_len(tx_rates
), nl80211_txattr_policy
);
6060 if (tb
[NL80211_TXRATE_LEGACY
]) {
6061 mask
.control
[band
].legacy
= rateset_to_mask(
6063 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
6064 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
6065 if ((mask
.control
[band
].legacy
== 0) &&
6066 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
6069 if (tb
[NL80211_TXRATE_MCS
]) {
6070 if (!ht_rateset_to_mask(
6072 nla_data(tb
[NL80211_TXRATE_MCS
]),
6073 nla_len(tb
[NL80211_TXRATE_MCS
]),
6074 mask
.control
[band
].mcs
))
6078 if (mask
.control
[band
].legacy
== 0) {
6079 /* don't allow empty legacy rates if HT
6080 * is not even supported. */
6081 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
6084 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
6085 if (mask
.control
[band
].mcs
[i
])
6088 /* legacy and mcs rates may not be both empty */
6089 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
6094 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
6097 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6099 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6100 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6101 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
6103 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
6106 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
6107 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
6109 switch (wdev
->iftype
) {
6110 case NL80211_IFTYPE_STATION
:
6111 case NL80211_IFTYPE_ADHOC
:
6112 case NL80211_IFTYPE_P2P_CLIENT
:
6113 case NL80211_IFTYPE_AP
:
6114 case NL80211_IFTYPE_AP_VLAN
:
6115 case NL80211_IFTYPE_MESH_POINT
:
6116 case NL80211_IFTYPE_P2P_GO
:
6117 case NL80211_IFTYPE_P2P_DEVICE
:
6123 /* not much point in registering if we can't reply */
6124 if (!rdev
->ops
->mgmt_tx
)
6127 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
6128 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
6129 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
6132 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6134 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6135 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6136 struct ieee80211_channel
*chan
;
6137 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6138 bool channel_type_valid
= false;
6143 struct sk_buff
*msg
= NULL
;
6144 unsigned int wait
= 0;
6145 bool offchan
, no_cck
, dont_wait_for_ack
;
6147 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
6149 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
6150 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6153 if (!rdev
->ops
->mgmt_tx
)
6156 switch (wdev
->iftype
) {
6157 case NL80211_IFTYPE_STATION
:
6158 case NL80211_IFTYPE_ADHOC
:
6159 case NL80211_IFTYPE_P2P_CLIENT
:
6160 case NL80211_IFTYPE_AP
:
6161 case NL80211_IFTYPE_AP_VLAN
:
6162 case NL80211_IFTYPE_MESH_POINT
:
6163 case NL80211_IFTYPE_P2P_GO
:
6164 case NL80211_IFTYPE_P2P_DEVICE
:
6170 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
6171 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6173 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6176 * We should wait on the channel for at least a minimum amount
6177 * of time (10ms) but no longer than the driver supports.
6179 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6180 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
6185 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
6186 if (!nl80211_valid_channel_type(info
, &channel_type
))
6188 channel_type_valid
= true;
6191 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
6193 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6196 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6198 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6199 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
6203 if (!dont_wait_for_ack
) {
6204 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6208 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6217 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chan
, offchan
, channel_type
,
6218 channel_type_valid
, wait
,
6219 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
6220 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
6221 no_cck
, dont_wait_for_ack
, &cookie
);
6226 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6227 goto nla_put_failure
;
6229 genlmsg_end(msg
, hdr
);
6230 return genlmsg_reply(msg
, info
);
6242 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
6244 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6245 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6248 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6251 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
6254 switch (wdev
->iftype
) {
6255 case NL80211_IFTYPE_STATION
:
6256 case NL80211_IFTYPE_ADHOC
:
6257 case NL80211_IFTYPE_P2P_CLIENT
:
6258 case NL80211_IFTYPE_AP
:
6259 case NL80211_IFTYPE_AP_VLAN
:
6260 case NL80211_IFTYPE_P2P_GO
:
6261 case NL80211_IFTYPE_P2P_DEVICE
:
6267 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6269 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, wdev
, cookie
);
6272 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6274 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6275 struct wireless_dev
*wdev
;
6276 struct net_device
*dev
= info
->user_ptr
[1];
6281 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
6284 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
6286 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
6289 wdev
= dev
->ieee80211_ptr
;
6291 if (!rdev
->ops
->set_power_mgmt
)
6294 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
6296 if (state
== wdev
->ps
)
6299 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
6306 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6308 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6309 enum nl80211_ps_state ps_state
;
6310 struct wireless_dev
*wdev
;
6311 struct net_device
*dev
= info
->user_ptr
[1];
6312 struct sk_buff
*msg
;
6316 wdev
= dev
->ieee80211_ptr
;
6318 if (!rdev
->ops
->set_power_mgmt
)
6321 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6325 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6326 NL80211_CMD_GET_POWER_SAVE
);
6333 ps_state
= NL80211_PS_ENABLED
;
6335 ps_state
= NL80211_PS_DISABLED
;
6337 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
6338 goto nla_put_failure
;
6340 genlmsg_end(msg
, hdr
);
6341 return genlmsg_reply(msg
, info
);
6350 static struct nla_policy
6351 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
6352 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
6353 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
6354 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
6355 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
6356 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
6357 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
6360 static int nl80211_set_cqm_txe(struct genl_info
*info
,
6361 u32 rate
, u32 pkts
, u32 intvl
)
6363 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6364 struct wireless_dev
*wdev
;
6365 struct net_device
*dev
= info
->user_ptr
[1];
6367 if ((rate
< 0 || rate
> 100) ||
6368 (intvl
< 0 || intvl
> NL80211_CQM_TXE_MAX_INTVL
))
6371 wdev
= dev
->ieee80211_ptr
;
6373 if (!rdev
->ops
->set_cqm_txe_config
)
6376 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6377 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6380 return rdev
->ops
->set_cqm_txe_config(wdev
->wiphy
, dev
,
6384 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
6385 s32 threshold
, u32 hysteresis
)
6387 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6388 struct wireless_dev
*wdev
;
6389 struct net_device
*dev
= info
->user_ptr
[1];
6394 wdev
= dev
->ieee80211_ptr
;
6396 if (!rdev
->ops
->set_cqm_rssi_config
)
6399 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6400 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6403 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
6404 threshold
, hysteresis
);
6407 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
6409 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
6413 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
6419 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
6420 nl80211_attr_cqm_policy
);
6424 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
6425 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
6428 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
6429 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
6430 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
6431 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
6432 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
6433 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
6434 u32 rate
, pkts
, intvl
;
6435 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
6436 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
6437 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
6438 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
6446 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6448 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6449 struct net_device
*dev
= info
->user_ptr
[1];
6450 struct mesh_config cfg
;
6451 struct mesh_setup setup
;
6454 /* start with default */
6455 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
6456 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
6458 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
6459 /* and parse parameters if given */
6460 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
6465 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
6466 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
6469 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6470 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6472 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6473 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
6474 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6477 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
6478 /* parse additional setup parameters if given */
6479 err
= nl80211_parse_mesh_setup(info
, &setup
);
6484 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6485 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6487 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
6488 !nl80211_valid_channel_type(info
, &channel_type
))
6491 setup
.channel
= rdev_freq_to_chan(rdev
,
6492 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
6496 setup
.channel_type
= channel_type
;
6498 /* cfg80211_join_mesh() will sort it out */
6499 setup
.channel
= NULL
;
6502 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
6505 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6507 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6508 struct net_device
*dev
= info
->user_ptr
[1];
6510 return cfg80211_leave_mesh(rdev
, dev
);
6514 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6516 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6517 struct sk_buff
*msg
;
6520 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6523 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6527 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6528 NL80211_CMD_GET_WOWLAN
);
6530 goto nla_put_failure
;
6533 struct nlattr
*nl_wowlan
;
6535 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
6537 goto nla_put_failure
;
6539 if ((rdev
->wowlan
->any
&&
6540 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
6541 (rdev
->wowlan
->disconnect
&&
6542 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
6543 (rdev
->wowlan
->magic_pkt
&&
6544 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
6545 (rdev
->wowlan
->gtk_rekey_failure
&&
6546 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
6547 (rdev
->wowlan
->eap_identity_req
&&
6548 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
6549 (rdev
->wowlan
->four_way_handshake
&&
6550 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
6551 (rdev
->wowlan
->rfkill_release
&&
6552 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
6553 goto nla_put_failure
;
6554 if (rdev
->wowlan
->n_patterns
) {
6555 struct nlattr
*nl_pats
, *nl_pat
;
6558 nl_pats
= nla_nest_start(msg
,
6559 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
6561 goto nla_put_failure
;
6563 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
6564 nl_pat
= nla_nest_start(msg
, i
+ 1);
6566 goto nla_put_failure
;
6567 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
6568 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
6569 DIV_ROUND_UP(pat_len
, 8),
6570 rdev
->wowlan
->patterns
[i
].mask
) ||
6571 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
6573 rdev
->wowlan
->patterns
[i
].pattern
))
6574 goto nla_put_failure
;
6575 nla_nest_end(msg
, nl_pat
);
6577 nla_nest_end(msg
, nl_pats
);
6580 nla_nest_end(msg
, nl_wowlan
);
6583 genlmsg_end(msg
, hdr
);
6584 return genlmsg_reply(msg
, info
);
6591 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6593 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6594 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
6595 struct cfg80211_wowlan new_triggers
= {};
6596 struct cfg80211_wowlan
*ntrig
;
6597 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
6599 bool prev_enabled
= rdev
->wowlan
;
6601 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6604 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
6605 cfg80211_rdev_free_wowlan(rdev
);
6606 rdev
->wowlan
= NULL
;
6610 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
6611 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6612 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6613 nl80211_wowlan_policy
);
6617 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
6618 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
6620 new_triggers
.any
= true;
6623 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
6624 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
6626 new_triggers
.disconnect
= true;
6629 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
6630 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
6632 new_triggers
.magic_pkt
= true;
6635 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
6638 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
6639 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
6641 new_triggers
.gtk_rekey_failure
= true;
6644 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
6645 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
6647 new_triggers
.eap_identity_req
= true;
6650 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
6651 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
6653 new_triggers
.four_way_handshake
= true;
6656 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
6657 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
6659 new_triggers
.rfkill_release
= true;
6662 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
6665 int rem
, pat_len
, mask_len
;
6666 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
6668 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6671 if (n_patterns
> wowlan
->n_patterns
)
6674 new_triggers
.patterns
= kcalloc(n_patterns
,
6675 sizeof(new_triggers
.patterns
[0]),
6677 if (!new_triggers
.patterns
)
6680 new_triggers
.n_patterns
= n_patterns
;
6683 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6685 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
6686 nla_data(pat
), nla_len(pat
), NULL
);
6688 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
6689 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
6691 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
6692 mask_len
= DIV_ROUND_UP(pat_len
, 8);
6693 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
6696 if (pat_len
> wowlan
->pattern_max_len
||
6697 pat_len
< wowlan
->pattern_min_len
)
6700 new_triggers
.patterns
[i
].mask
=
6701 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
6702 if (!new_triggers
.patterns
[i
].mask
) {
6706 new_triggers
.patterns
[i
].pattern
=
6707 new_triggers
.patterns
[i
].mask
+ mask_len
;
6708 memcpy(new_triggers
.patterns
[i
].mask
,
6709 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
6711 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
6712 memcpy(new_triggers
.patterns
[i
].pattern
,
6713 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
6719 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
6724 cfg80211_rdev_free_wowlan(rdev
);
6725 rdev
->wowlan
= ntrig
;
6728 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
6729 rdev
->ops
->set_wakeup(&rdev
->wiphy
, rdev
->wowlan
);
6733 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
6734 kfree(new_triggers
.patterns
[i
].mask
);
6735 kfree(new_triggers
.patterns
);
6740 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
6742 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6743 struct net_device
*dev
= info
->user_ptr
[1];
6744 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6745 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
6746 struct cfg80211_gtk_rekey_data rekey_data
;
6749 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
6752 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
6753 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6754 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6755 nl80211_rekey_policy
);
6759 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
6761 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
6763 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
6766 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
6768 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
6770 memcpy(rekey_data
.replay_ctr
,
6771 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
6772 NL80211_REPLAY_CTR_LEN
);
6775 if (!wdev
->current_bss
) {
6780 if (!rdev
->ops
->set_rekey_data
) {
6785 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
6791 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
6792 struct genl_info
*info
)
6794 struct net_device
*dev
= info
->user_ptr
[1];
6795 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6797 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6798 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6801 if (wdev
->ap_unexpected_nlportid
)
6804 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
6808 static int nl80211_probe_client(struct sk_buff
*skb
,
6809 struct genl_info
*info
)
6811 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6812 struct net_device
*dev
= info
->user_ptr
[1];
6813 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6814 struct sk_buff
*msg
;
6820 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6821 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6824 if (!info
->attrs
[NL80211_ATTR_MAC
])
6827 if (!rdev
->ops
->probe_client
)
6830 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6834 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6835 NL80211_CMD_PROBE_CLIENT
);
6842 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6844 err
= rdev
->ops
->probe_client(&rdev
->wiphy
, dev
, addr
, &cookie
);
6848 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6849 goto nla_put_failure
;
6851 genlmsg_end(msg
, hdr
);
6853 return genlmsg_reply(msg
, info
);
6862 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
6864 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6866 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
6869 if (rdev
->ap_beacons_nlportid
)
6872 rdev
->ap_beacons_nlportid
= info
->snd_portid
;
6877 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
6879 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6880 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6883 if (!rdev
->ops
->start_p2p_device
)
6886 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
6889 if (wdev
->p2p_started
)
6892 mutex_lock(&rdev
->devlist_mtx
);
6893 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
6894 mutex_unlock(&rdev
->devlist_mtx
);
6898 err
= rdev
->ops
->start_p2p_device(&rdev
->wiphy
, wdev
);
6902 wdev
->p2p_started
= true;
6903 mutex_lock(&rdev
->devlist_mtx
);
6905 mutex_unlock(&rdev
->devlist_mtx
);
6910 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
6912 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6913 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6915 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
6918 if (!rdev
->ops
->stop_p2p_device
)
6921 if (!wdev
->p2p_started
)
6924 rdev
->ops
->stop_p2p_device(&rdev
->wiphy
, wdev
);
6925 wdev
->p2p_started
= false;
6927 mutex_lock(&rdev
->devlist_mtx
);
6929 mutex_unlock(&rdev
->devlist_mtx
);
6931 if (WARN_ON(rdev
->scan_req
&& rdev
->scan_req
->wdev
== wdev
)) {
6932 rdev
->scan_req
->aborted
= true;
6933 ___cfg80211_scan_done(rdev
, true);
6939 #define NL80211_FLAG_NEED_WIPHY 0x01
6940 #define NL80211_FLAG_NEED_NETDEV 0x02
6941 #define NL80211_FLAG_NEED_RTNL 0x04
6942 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6943 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6944 NL80211_FLAG_CHECK_NETDEV_UP)
6945 #define NL80211_FLAG_NEED_WDEV 0x10
6946 /* If a netdev is associated, it must be UP, P2P must be started */
6947 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6948 NL80211_FLAG_CHECK_NETDEV_UP)
6950 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6951 struct genl_info
*info
)
6953 struct cfg80211_registered_device
*rdev
;
6954 struct wireless_dev
*wdev
;
6955 struct net_device
*dev
;
6956 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
6961 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
6962 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6966 return PTR_ERR(rdev
);
6968 info
->user_ptr
[0] = rdev
;
6969 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
6970 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
6971 mutex_lock(&cfg80211_mutex
);
6972 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
6975 mutex_unlock(&cfg80211_mutex
);
6978 return PTR_ERR(wdev
);
6982 rdev
= wiphy_to_dev(wdev
->wiphy
);
6984 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
6986 mutex_unlock(&cfg80211_mutex
);
6992 info
->user_ptr
[1] = dev
;
6994 info
->user_ptr
[1] = wdev
;
6998 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
6999 !netif_running(dev
)) {
7000 mutex_unlock(&cfg80211_mutex
);
7007 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
7008 if (!wdev
->p2p_started
) {
7009 mutex_unlock(&cfg80211_mutex
);
7016 cfg80211_lock_rdev(rdev
);
7018 mutex_unlock(&cfg80211_mutex
);
7020 info
->user_ptr
[0] = rdev
;
7026 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
7027 struct genl_info
*info
)
7029 if (info
->user_ptr
[0])
7030 cfg80211_unlock_rdev(info
->user_ptr
[0]);
7031 if (info
->user_ptr
[1]) {
7032 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
7033 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7036 dev_put(wdev
->netdev
);
7038 dev_put(info
->user_ptr
[1]);
7041 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
7045 static struct genl_ops nl80211_ops
[] = {
7047 .cmd
= NL80211_CMD_GET_WIPHY
,
7048 .doit
= nl80211_get_wiphy
,
7049 .dumpit
= nl80211_dump_wiphy
,
7050 .policy
= nl80211_policy
,
7051 /* can be retrieved by unprivileged users */
7052 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
7055 .cmd
= NL80211_CMD_SET_WIPHY
,
7056 .doit
= nl80211_set_wiphy
,
7057 .policy
= nl80211_policy
,
7058 .flags
= GENL_ADMIN_PERM
,
7059 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
7062 .cmd
= NL80211_CMD_GET_INTERFACE
,
7063 .doit
= nl80211_get_interface
,
7064 .dumpit
= nl80211_dump_interface
,
7065 .policy
= nl80211_policy
,
7066 /* can be retrieved by unprivileged users */
7067 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
7070 .cmd
= NL80211_CMD_SET_INTERFACE
,
7071 .doit
= nl80211_set_interface
,
7072 .policy
= nl80211_policy
,
7073 .flags
= GENL_ADMIN_PERM
,
7074 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7075 NL80211_FLAG_NEED_RTNL
,
7078 .cmd
= NL80211_CMD_NEW_INTERFACE
,
7079 .doit
= nl80211_new_interface
,
7080 .policy
= nl80211_policy
,
7081 .flags
= GENL_ADMIN_PERM
,
7082 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7083 NL80211_FLAG_NEED_RTNL
,
7086 .cmd
= NL80211_CMD_DEL_INTERFACE
,
7087 .doit
= nl80211_del_interface
,
7088 .policy
= nl80211_policy
,
7089 .flags
= GENL_ADMIN_PERM
,
7090 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7091 NL80211_FLAG_NEED_RTNL
,
7094 .cmd
= NL80211_CMD_GET_KEY
,
7095 .doit
= nl80211_get_key
,
7096 .policy
= nl80211_policy
,
7097 .flags
= GENL_ADMIN_PERM
,
7098 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7099 NL80211_FLAG_NEED_RTNL
,
7102 .cmd
= NL80211_CMD_SET_KEY
,
7103 .doit
= nl80211_set_key
,
7104 .policy
= nl80211_policy
,
7105 .flags
= GENL_ADMIN_PERM
,
7106 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7107 NL80211_FLAG_NEED_RTNL
,
7110 .cmd
= NL80211_CMD_NEW_KEY
,
7111 .doit
= nl80211_new_key
,
7112 .policy
= nl80211_policy
,
7113 .flags
= GENL_ADMIN_PERM
,
7114 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7115 NL80211_FLAG_NEED_RTNL
,
7118 .cmd
= NL80211_CMD_DEL_KEY
,
7119 .doit
= nl80211_del_key
,
7120 .policy
= nl80211_policy
,
7121 .flags
= GENL_ADMIN_PERM
,
7122 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7123 NL80211_FLAG_NEED_RTNL
,
7126 .cmd
= NL80211_CMD_SET_BEACON
,
7127 .policy
= nl80211_policy
,
7128 .flags
= GENL_ADMIN_PERM
,
7129 .doit
= nl80211_set_beacon
,
7130 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7131 NL80211_FLAG_NEED_RTNL
,
7134 .cmd
= NL80211_CMD_START_AP
,
7135 .policy
= nl80211_policy
,
7136 .flags
= GENL_ADMIN_PERM
,
7137 .doit
= nl80211_start_ap
,
7138 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7139 NL80211_FLAG_NEED_RTNL
,
7142 .cmd
= NL80211_CMD_STOP_AP
,
7143 .policy
= nl80211_policy
,
7144 .flags
= GENL_ADMIN_PERM
,
7145 .doit
= nl80211_stop_ap
,
7146 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7147 NL80211_FLAG_NEED_RTNL
,
7150 .cmd
= NL80211_CMD_GET_STATION
,
7151 .doit
= nl80211_get_station
,
7152 .dumpit
= nl80211_dump_station
,
7153 .policy
= nl80211_policy
,
7154 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7155 NL80211_FLAG_NEED_RTNL
,
7158 .cmd
= NL80211_CMD_SET_STATION
,
7159 .doit
= nl80211_set_station
,
7160 .policy
= nl80211_policy
,
7161 .flags
= GENL_ADMIN_PERM
,
7162 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7163 NL80211_FLAG_NEED_RTNL
,
7166 .cmd
= NL80211_CMD_NEW_STATION
,
7167 .doit
= nl80211_new_station
,
7168 .policy
= nl80211_policy
,
7169 .flags
= GENL_ADMIN_PERM
,
7170 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7171 NL80211_FLAG_NEED_RTNL
,
7174 .cmd
= NL80211_CMD_DEL_STATION
,
7175 .doit
= nl80211_del_station
,
7176 .policy
= nl80211_policy
,
7177 .flags
= GENL_ADMIN_PERM
,
7178 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7179 NL80211_FLAG_NEED_RTNL
,
7182 .cmd
= NL80211_CMD_GET_MPATH
,
7183 .doit
= nl80211_get_mpath
,
7184 .dumpit
= nl80211_dump_mpath
,
7185 .policy
= nl80211_policy
,
7186 .flags
= GENL_ADMIN_PERM
,
7187 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7188 NL80211_FLAG_NEED_RTNL
,
7191 .cmd
= NL80211_CMD_SET_MPATH
,
7192 .doit
= nl80211_set_mpath
,
7193 .policy
= nl80211_policy
,
7194 .flags
= GENL_ADMIN_PERM
,
7195 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7196 NL80211_FLAG_NEED_RTNL
,
7199 .cmd
= NL80211_CMD_NEW_MPATH
,
7200 .doit
= nl80211_new_mpath
,
7201 .policy
= nl80211_policy
,
7202 .flags
= GENL_ADMIN_PERM
,
7203 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7204 NL80211_FLAG_NEED_RTNL
,
7207 .cmd
= NL80211_CMD_DEL_MPATH
,
7208 .doit
= nl80211_del_mpath
,
7209 .policy
= nl80211_policy
,
7210 .flags
= GENL_ADMIN_PERM
,
7211 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7212 NL80211_FLAG_NEED_RTNL
,
7215 .cmd
= NL80211_CMD_SET_BSS
,
7216 .doit
= nl80211_set_bss
,
7217 .policy
= nl80211_policy
,
7218 .flags
= GENL_ADMIN_PERM
,
7219 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7220 NL80211_FLAG_NEED_RTNL
,
7223 .cmd
= NL80211_CMD_GET_REG
,
7224 .doit
= nl80211_get_reg
,
7225 .policy
= nl80211_policy
,
7226 /* can be retrieved by unprivileged users */
7229 .cmd
= NL80211_CMD_SET_REG
,
7230 .doit
= nl80211_set_reg
,
7231 .policy
= nl80211_policy
,
7232 .flags
= GENL_ADMIN_PERM
,
7235 .cmd
= NL80211_CMD_REQ_SET_REG
,
7236 .doit
= nl80211_req_set_reg
,
7237 .policy
= nl80211_policy
,
7238 .flags
= GENL_ADMIN_PERM
,
7241 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
7242 .doit
= nl80211_get_mesh_config
,
7243 .policy
= nl80211_policy
,
7244 /* can be retrieved by unprivileged users */
7245 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7246 NL80211_FLAG_NEED_RTNL
,
7249 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
7250 .doit
= nl80211_update_mesh_config
,
7251 .policy
= nl80211_policy
,
7252 .flags
= GENL_ADMIN_PERM
,
7253 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7254 NL80211_FLAG_NEED_RTNL
,
7257 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
7258 .doit
= nl80211_trigger_scan
,
7259 .policy
= nl80211_policy
,
7260 .flags
= GENL_ADMIN_PERM
,
7261 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7262 NL80211_FLAG_NEED_RTNL
,
7265 .cmd
= NL80211_CMD_GET_SCAN
,
7266 .policy
= nl80211_policy
,
7267 .dumpit
= nl80211_dump_scan
,
7270 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
7271 .doit
= nl80211_start_sched_scan
,
7272 .policy
= nl80211_policy
,
7273 .flags
= GENL_ADMIN_PERM
,
7274 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7275 NL80211_FLAG_NEED_RTNL
,
7278 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
7279 .doit
= nl80211_stop_sched_scan
,
7280 .policy
= nl80211_policy
,
7281 .flags
= GENL_ADMIN_PERM
,
7282 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7283 NL80211_FLAG_NEED_RTNL
,
7286 .cmd
= NL80211_CMD_AUTHENTICATE
,
7287 .doit
= nl80211_authenticate
,
7288 .policy
= nl80211_policy
,
7289 .flags
= GENL_ADMIN_PERM
,
7290 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7291 NL80211_FLAG_NEED_RTNL
,
7294 .cmd
= NL80211_CMD_ASSOCIATE
,
7295 .doit
= nl80211_associate
,
7296 .policy
= nl80211_policy
,
7297 .flags
= GENL_ADMIN_PERM
,
7298 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7299 NL80211_FLAG_NEED_RTNL
,
7302 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
7303 .doit
= nl80211_deauthenticate
,
7304 .policy
= nl80211_policy
,
7305 .flags
= GENL_ADMIN_PERM
,
7306 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7307 NL80211_FLAG_NEED_RTNL
,
7310 .cmd
= NL80211_CMD_DISASSOCIATE
,
7311 .doit
= nl80211_disassociate
,
7312 .policy
= nl80211_policy
,
7313 .flags
= GENL_ADMIN_PERM
,
7314 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7315 NL80211_FLAG_NEED_RTNL
,
7318 .cmd
= NL80211_CMD_JOIN_IBSS
,
7319 .doit
= nl80211_join_ibss
,
7320 .policy
= nl80211_policy
,
7321 .flags
= GENL_ADMIN_PERM
,
7322 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7323 NL80211_FLAG_NEED_RTNL
,
7326 .cmd
= NL80211_CMD_LEAVE_IBSS
,
7327 .doit
= nl80211_leave_ibss
,
7328 .policy
= nl80211_policy
,
7329 .flags
= GENL_ADMIN_PERM
,
7330 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7331 NL80211_FLAG_NEED_RTNL
,
7333 #ifdef CONFIG_NL80211_TESTMODE
7335 .cmd
= NL80211_CMD_TESTMODE
,
7336 .doit
= nl80211_testmode_do
,
7337 .dumpit
= nl80211_testmode_dump
,
7338 .policy
= nl80211_policy
,
7339 .flags
= GENL_ADMIN_PERM
,
7340 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7341 NL80211_FLAG_NEED_RTNL
,
7345 .cmd
= NL80211_CMD_CONNECT
,
7346 .doit
= nl80211_connect
,
7347 .policy
= nl80211_policy
,
7348 .flags
= GENL_ADMIN_PERM
,
7349 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7350 NL80211_FLAG_NEED_RTNL
,
7353 .cmd
= NL80211_CMD_DISCONNECT
,
7354 .doit
= nl80211_disconnect
,
7355 .policy
= nl80211_policy
,
7356 .flags
= GENL_ADMIN_PERM
,
7357 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7358 NL80211_FLAG_NEED_RTNL
,
7361 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
7362 .doit
= nl80211_wiphy_netns
,
7363 .policy
= nl80211_policy
,
7364 .flags
= GENL_ADMIN_PERM
,
7365 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7366 NL80211_FLAG_NEED_RTNL
,
7369 .cmd
= NL80211_CMD_GET_SURVEY
,
7370 .policy
= nl80211_policy
,
7371 .dumpit
= nl80211_dump_survey
,
7374 .cmd
= NL80211_CMD_SET_PMKSA
,
7375 .doit
= nl80211_setdel_pmksa
,
7376 .policy
= nl80211_policy
,
7377 .flags
= GENL_ADMIN_PERM
,
7378 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7379 NL80211_FLAG_NEED_RTNL
,
7382 .cmd
= NL80211_CMD_DEL_PMKSA
,
7383 .doit
= nl80211_setdel_pmksa
,
7384 .policy
= nl80211_policy
,
7385 .flags
= GENL_ADMIN_PERM
,
7386 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7387 NL80211_FLAG_NEED_RTNL
,
7390 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
7391 .doit
= nl80211_flush_pmksa
,
7392 .policy
= nl80211_policy
,
7393 .flags
= GENL_ADMIN_PERM
,
7394 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7395 NL80211_FLAG_NEED_RTNL
,
7398 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
7399 .doit
= nl80211_remain_on_channel
,
7400 .policy
= nl80211_policy
,
7401 .flags
= GENL_ADMIN_PERM
,
7402 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7403 NL80211_FLAG_NEED_RTNL
,
7406 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7407 .doit
= nl80211_cancel_remain_on_channel
,
7408 .policy
= nl80211_policy
,
7409 .flags
= GENL_ADMIN_PERM
,
7410 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7411 NL80211_FLAG_NEED_RTNL
,
7414 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
7415 .doit
= nl80211_set_tx_bitrate_mask
,
7416 .policy
= nl80211_policy
,
7417 .flags
= GENL_ADMIN_PERM
,
7418 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7419 NL80211_FLAG_NEED_RTNL
,
7422 .cmd
= NL80211_CMD_REGISTER_FRAME
,
7423 .doit
= nl80211_register_mgmt
,
7424 .policy
= nl80211_policy
,
7425 .flags
= GENL_ADMIN_PERM
,
7426 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7427 NL80211_FLAG_NEED_RTNL
,
7430 .cmd
= NL80211_CMD_FRAME
,
7431 .doit
= nl80211_tx_mgmt
,
7432 .policy
= nl80211_policy
,
7433 .flags
= GENL_ADMIN_PERM
,
7434 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7435 NL80211_FLAG_NEED_RTNL
,
7438 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
7439 .doit
= nl80211_tx_mgmt_cancel_wait
,
7440 .policy
= nl80211_policy
,
7441 .flags
= GENL_ADMIN_PERM
,
7442 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7443 NL80211_FLAG_NEED_RTNL
,
7446 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
7447 .doit
= nl80211_set_power_save
,
7448 .policy
= nl80211_policy
,
7449 .flags
= GENL_ADMIN_PERM
,
7450 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7451 NL80211_FLAG_NEED_RTNL
,
7454 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
7455 .doit
= nl80211_get_power_save
,
7456 .policy
= nl80211_policy
,
7457 /* can be retrieved by unprivileged users */
7458 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7459 NL80211_FLAG_NEED_RTNL
,
7462 .cmd
= NL80211_CMD_SET_CQM
,
7463 .doit
= nl80211_set_cqm
,
7464 .policy
= nl80211_policy
,
7465 .flags
= GENL_ADMIN_PERM
,
7466 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7467 NL80211_FLAG_NEED_RTNL
,
7470 .cmd
= NL80211_CMD_SET_CHANNEL
,
7471 .doit
= nl80211_set_channel
,
7472 .policy
= nl80211_policy
,
7473 .flags
= GENL_ADMIN_PERM
,
7474 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7475 NL80211_FLAG_NEED_RTNL
,
7478 .cmd
= NL80211_CMD_SET_WDS_PEER
,
7479 .doit
= nl80211_set_wds_peer
,
7480 .policy
= nl80211_policy
,
7481 .flags
= GENL_ADMIN_PERM
,
7482 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7483 NL80211_FLAG_NEED_RTNL
,
7486 .cmd
= NL80211_CMD_JOIN_MESH
,
7487 .doit
= nl80211_join_mesh
,
7488 .policy
= nl80211_policy
,
7489 .flags
= GENL_ADMIN_PERM
,
7490 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7491 NL80211_FLAG_NEED_RTNL
,
7494 .cmd
= NL80211_CMD_LEAVE_MESH
,
7495 .doit
= nl80211_leave_mesh
,
7496 .policy
= nl80211_policy
,
7497 .flags
= GENL_ADMIN_PERM
,
7498 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7499 NL80211_FLAG_NEED_RTNL
,
7503 .cmd
= NL80211_CMD_GET_WOWLAN
,
7504 .doit
= nl80211_get_wowlan
,
7505 .policy
= nl80211_policy
,
7506 /* can be retrieved by unprivileged users */
7507 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7508 NL80211_FLAG_NEED_RTNL
,
7511 .cmd
= NL80211_CMD_SET_WOWLAN
,
7512 .doit
= nl80211_set_wowlan
,
7513 .policy
= nl80211_policy
,
7514 .flags
= GENL_ADMIN_PERM
,
7515 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7516 NL80211_FLAG_NEED_RTNL
,
7520 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
7521 .doit
= nl80211_set_rekey_data
,
7522 .policy
= nl80211_policy
,
7523 .flags
= GENL_ADMIN_PERM
,
7524 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7525 NL80211_FLAG_NEED_RTNL
,
7528 .cmd
= NL80211_CMD_TDLS_MGMT
,
7529 .doit
= nl80211_tdls_mgmt
,
7530 .policy
= nl80211_policy
,
7531 .flags
= GENL_ADMIN_PERM
,
7532 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7533 NL80211_FLAG_NEED_RTNL
,
7536 .cmd
= NL80211_CMD_TDLS_OPER
,
7537 .doit
= nl80211_tdls_oper
,
7538 .policy
= nl80211_policy
,
7539 .flags
= GENL_ADMIN_PERM
,
7540 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7541 NL80211_FLAG_NEED_RTNL
,
7544 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
7545 .doit
= nl80211_register_unexpected_frame
,
7546 .policy
= nl80211_policy
,
7547 .flags
= GENL_ADMIN_PERM
,
7548 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7549 NL80211_FLAG_NEED_RTNL
,
7552 .cmd
= NL80211_CMD_PROBE_CLIENT
,
7553 .doit
= nl80211_probe_client
,
7554 .policy
= nl80211_policy
,
7555 .flags
= GENL_ADMIN_PERM
,
7556 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7557 NL80211_FLAG_NEED_RTNL
,
7560 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
7561 .doit
= nl80211_register_beacons
,
7562 .policy
= nl80211_policy
,
7563 .flags
= GENL_ADMIN_PERM
,
7564 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7565 NL80211_FLAG_NEED_RTNL
,
7568 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
7569 .doit
= nl80211_set_noack_map
,
7570 .policy
= nl80211_policy
,
7571 .flags
= GENL_ADMIN_PERM
,
7572 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7573 NL80211_FLAG_NEED_RTNL
,
7576 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
7577 .doit
= nl80211_start_p2p_device
,
7578 .policy
= nl80211_policy
,
7579 .flags
= GENL_ADMIN_PERM
,
7580 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7581 NL80211_FLAG_NEED_RTNL
,
7584 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
7585 .doit
= nl80211_stop_p2p_device
,
7586 .policy
= nl80211_policy
,
7587 .flags
= GENL_ADMIN_PERM
,
7588 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7589 NL80211_FLAG_NEED_RTNL
,
7593 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
7597 /* multicast groups */
7598 static struct genl_multicast_group nl80211_config_mcgrp
= {
7601 static struct genl_multicast_group nl80211_scan_mcgrp
= {
7604 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
7605 .name
= "regulatory",
7608 /* notification functions */
7610 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
7612 struct sk_buff
*msg
;
7614 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7618 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
7623 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7624 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
7627 static int nl80211_add_scan_req(struct sk_buff
*msg
,
7628 struct cfg80211_registered_device
*rdev
)
7630 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
7631 struct nlattr
*nest
;
7634 ASSERT_RDEV_LOCK(rdev
);
7639 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
7641 goto nla_put_failure
;
7642 for (i
= 0; i
< req
->n_ssids
; i
++) {
7643 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
7644 goto nla_put_failure
;
7646 nla_nest_end(msg
, nest
);
7648 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
7650 goto nla_put_failure
;
7651 for (i
= 0; i
< req
->n_channels
; i
++) {
7652 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
7653 goto nla_put_failure
;
7655 nla_nest_end(msg
, nest
);
7658 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
7659 goto nla_put_failure
;
7666 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
7667 struct cfg80211_registered_device
*rdev
,
7668 struct wireless_dev
*wdev
,
7669 u32 portid
, u32 seq
, int flags
,
7674 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
7678 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7679 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
7680 wdev
->netdev
->ifindex
)) ||
7681 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
7682 goto nla_put_failure
;
7684 /* ignore errors and send incomplete event anyway */
7685 nl80211_add_scan_req(msg
, rdev
);
7687 return genlmsg_end(msg
, hdr
);
7690 genlmsg_cancel(msg
, hdr
);
7695 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
7696 struct cfg80211_registered_device
*rdev
,
7697 struct net_device
*netdev
,
7698 u32 portid
, u32 seq
, int flags
, u32 cmd
)
7702 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
7706 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7707 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7708 goto nla_put_failure
;
7710 return genlmsg_end(msg
, hdr
);
7713 genlmsg_cancel(msg
, hdr
);
7717 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
7718 struct wireless_dev
*wdev
)
7720 struct sk_buff
*msg
;
7722 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7726 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7727 NL80211_CMD_TRIGGER_SCAN
) < 0) {
7732 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7733 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7736 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
7737 struct wireless_dev
*wdev
)
7739 struct sk_buff
*msg
;
7741 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7745 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7746 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
7751 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7752 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7755 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
7756 struct wireless_dev
*wdev
)
7758 struct sk_buff
*msg
;
7760 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7764 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7765 NL80211_CMD_SCAN_ABORTED
) < 0) {
7770 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7771 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7774 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
7775 struct net_device
*netdev
)
7777 struct sk_buff
*msg
;
7779 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7783 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7784 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
7789 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7790 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7793 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
7794 struct net_device
*netdev
, u32 cmd
)
7796 struct sk_buff
*msg
;
7798 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7802 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
7807 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7808 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7812 * This can happen on global regulatory changes or device specific settings
7813 * based on custom world regulatory domains.
7815 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
7817 struct sk_buff
*msg
;
7820 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7824 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
7830 /* Userspace can always count this one always being set */
7831 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
7832 goto nla_put_failure
;
7834 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
7835 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7836 NL80211_REGDOM_TYPE_WORLD
))
7837 goto nla_put_failure
;
7838 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
7839 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7840 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
7841 goto nla_put_failure
;
7842 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
7843 request
->intersect
) {
7844 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7845 NL80211_REGDOM_TYPE_INTERSECTION
))
7846 goto nla_put_failure
;
7848 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7849 NL80211_REGDOM_TYPE_COUNTRY
) ||
7850 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
7852 goto nla_put_failure
;
7855 if (wiphy_idx_valid(request
->wiphy_idx
) &&
7856 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
7857 goto nla_put_failure
;
7859 genlmsg_end(msg
, hdr
);
7862 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7869 genlmsg_cancel(msg
, hdr
);
7873 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
7874 struct net_device
*netdev
,
7875 const u8
*buf
, size_t len
,
7876 enum nl80211_commands cmd
, gfp_t gfp
)
7878 struct sk_buff
*msg
;
7881 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7885 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7891 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7892 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7893 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
7894 goto nla_put_failure
;
7896 genlmsg_end(msg
, hdr
);
7898 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7899 nl80211_mlme_mcgrp
.id
, gfp
);
7903 genlmsg_cancel(msg
, hdr
);
7907 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
7908 struct net_device
*netdev
, const u8
*buf
,
7909 size_t len
, gfp_t gfp
)
7911 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7912 NL80211_CMD_AUTHENTICATE
, gfp
);
7915 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
7916 struct net_device
*netdev
, const u8
*buf
,
7917 size_t len
, gfp_t gfp
)
7919 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7920 NL80211_CMD_ASSOCIATE
, gfp
);
7923 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
7924 struct net_device
*netdev
, const u8
*buf
,
7925 size_t len
, gfp_t gfp
)
7927 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7928 NL80211_CMD_DEAUTHENTICATE
, gfp
);
7931 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
7932 struct net_device
*netdev
, const u8
*buf
,
7933 size_t len
, gfp_t gfp
)
7935 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7936 NL80211_CMD_DISASSOCIATE
, gfp
);
7939 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
7940 struct net_device
*netdev
, const u8
*buf
,
7941 size_t len
, gfp_t gfp
)
7943 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7944 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
7947 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
7948 struct net_device
*netdev
, const u8
*buf
,
7949 size_t len
, gfp_t gfp
)
7951 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7952 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
7955 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
7956 struct net_device
*netdev
, int cmd
,
7957 const u8
*addr
, gfp_t gfp
)
7959 struct sk_buff
*msg
;
7962 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7966 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7972 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7973 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7974 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
7975 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
7976 goto nla_put_failure
;
7978 genlmsg_end(msg
, hdr
);
7980 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7981 nl80211_mlme_mcgrp
.id
, gfp
);
7985 genlmsg_cancel(msg
, hdr
);
7989 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
7990 struct net_device
*netdev
, const u8
*addr
,
7993 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
7997 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
7998 struct net_device
*netdev
, const u8
*addr
,
8001 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
8005 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
8006 struct net_device
*netdev
, const u8
*bssid
,
8007 const u8
*req_ie
, size_t req_ie_len
,
8008 const u8
*resp_ie
, size_t resp_ie_len
,
8009 u16 status
, gfp_t gfp
)
8011 struct sk_buff
*msg
;
8014 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8018 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
8024 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8025 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8026 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
8027 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
8029 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8031 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8032 goto nla_put_failure
;
8034 genlmsg_end(msg
, hdr
);
8036 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8037 nl80211_mlme_mcgrp
.id
, gfp
);
8041 genlmsg_cancel(msg
, hdr
);
8046 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
8047 struct net_device
*netdev
, const u8
*bssid
,
8048 const u8
*req_ie
, size_t req_ie_len
,
8049 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
8051 struct sk_buff
*msg
;
8054 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8058 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
8064 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8065 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8066 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
8068 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8070 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8071 goto nla_put_failure
;
8073 genlmsg_end(msg
, hdr
);
8075 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8076 nl80211_mlme_mcgrp
.id
, gfp
);
8080 genlmsg_cancel(msg
, hdr
);
8085 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
8086 struct net_device
*netdev
, u16 reason
,
8087 const u8
*ie
, size_t ie_len
, bool from_ap
)
8089 struct sk_buff
*msg
;
8092 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8096 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
8102 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8103 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8104 (from_ap
&& reason
&&
8105 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
8107 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
8108 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
8109 goto nla_put_failure
;
8111 genlmsg_end(msg
, hdr
);
8113 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8114 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
8118 genlmsg_cancel(msg
, hdr
);
8123 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
8124 struct net_device
*netdev
, const u8
*bssid
,
8127 struct sk_buff
*msg
;
8130 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8134 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
8140 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8141 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8142 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8143 goto nla_put_failure
;
8145 genlmsg_end(msg
, hdr
);
8147 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8148 nl80211_mlme_mcgrp
.id
, gfp
);
8152 genlmsg_cancel(msg
, hdr
);
8156 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
8157 struct net_device
*netdev
,
8158 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
8161 struct sk_buff
*msg
;
8164 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8168 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
8174 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8175 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8176 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
) ||
8178 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
8179 goto nla_put_failure
;
8181 genlmsg_end(msg
, hdr
);
8183 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8184 nl80211_mlme_mcgrp
.id
, gfp
);
8188 genlmsg_cancel(msg
, hdr
);
8192 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
8193 struct net_device
*netdev
, const u8
*addr
,
8194 enum nl80211_key_type key_type
, int key_id
,
8195 const u8
*tsc
, gfp_t gfp
)
8197 struct sk_buff
*msg
;
8200 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8204 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
8210 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8211 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8212 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
8213 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
8215 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
8216 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
8217 goto nla_put_failure
;
8219 genlmsg_end(msg
, hdr
);
8221 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8222 nl80211_mlme_mcgrp
.id
, gfp
);
8226 genlmsg_cancel(msg
, hdr
);
8230 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
8231 struct ieee80211_channel
*channel_before
,
8232 struct ieee80211_channel
*channel_after
)
8234 struct sk_buff
*msg
;
8236 struct nlattr
*nl_freq
;
8238 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
8242 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
8249 * Since we are applying the beacon hint to a wiphy we know its
8250 * wiphy_idx is valid
8252 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
8253 goto nla_put_failure
;
8256 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
8258 goto nla_put_failure
;
8259 if (nl80211_msg_put_channel(msg
, channel_before
))
8260 goto nla_put_failure
;
8261 nla_nest_end(msg
, nl_freq
);
8264 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
8266 goto nla_put_failure
;
8267 if (nl80211_msg_put_channel(msg
, channel_after
))
8268 goto nla_put_failure
;
8269 nla_nest_end(msg
, nl_freq
);
8271 genlmsg_end(msg
, hdr
);
8274 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
8281 genlmsg_cancel(msg
, hdr
);
8285 static void nl80211_send_remain_on_chan_event(
8286 int cmd
, struct cfg80211_registered_device
*rdev
,
8287 struct wireless_dev
*wdev
, u64 cookie
,
8288 struct ieee80211_channel
*chan
,
8289 enum nl80211_channel_type channel_type
,
8290 unsigned int duration
, gfp_t gfp
)
8292 struct sk_buff
*msg
;
8295 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8299 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8305 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8306 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8307 wdev
->netdev
->ifindex
)) ||
8308 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
8309 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
8310 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
) ||
8311 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8312 goto nla_put_failure
;
8314 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
8315 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
8316 goto nla_put_failure
;
8318 genlmsg_end(msg
, hdr
);
8320 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8321 nl80211_mlme_mcgrp
.id
, gfp
);
8325 genlmsg_cancel(msg
, hdr
);
8329 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
8330 struct wireless_dev
*wdev
, u64 cookie
,
8331 struct ieee80211_channel
*chan
,
8332 enum nl80211_channel_type channel_type
,
8333 unsigned int duration
, gfp_t gfp
)
8335 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
8336 rdev
, wdev
, cookie
, chan
,
8337 channel_type
, duration
, gfp
);
8340 void nl80211_send_remain_on_channel_cancel(
8341 struct cfg80211_registered_device
*rdev
,
8342 struct wireless_dev
*wdev
,
8343 u64 cookie
, struct ieee80211_channel
*chan
,
8344 enum nl80211_channel_type channel_type
, gfp_t gfp
)
8346 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8347 rdev
, wdev
, cookie
, chan
,
8348 channel_type
, 0, gfp
);
8351 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
8352 struct net_device
*dev
, const u8
*mac_addr
,
8353 struct station_info
*sinfo
, gfp_t gfp
)
8355 struct sk_buff
*msg
;
8357 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8361 if (nl80211_send_station(msg
, 0, 0, 0,
8362 rdev
, dev
, mac_addr
, sinfo
) < 0) {
8367 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8368 nl80211_mlme_mcgrp
.id
, gfp
);
8371 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
8372 struct net_device
*dev
, const u8
*mac_addr
,
8375 struct sk_buff
*msg
;
8378 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8382 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
8388 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8389 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
8390 goto nla_put_failure
;
8392 genlmsg_end(msg
, hdr
);
8394 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8395 nl80211_mlme_mcgrp
.id
, gfp
);
8399 genlmsg_cancel(msg
, hdr
);
8403 void nl80211_send_conn_failed_event(struct cfg80211_registered_device
*rdev
,
8404 struct net_device
*dev
, const u8
*mac_addr
,
8405 enum nl80211_connect_failed_reason reason
,
8408 struct sk_buff
*msg
;
8411 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8415 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
8421 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8422 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
8423 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
8424 goto nla_put_failure
;
8426 genlmsg_end(msg
, hdr
);
8428 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8429 nl80211_mlme_mcgrp
.id
, gfp
);
8433 genlmsg_cancel(msg
, hdr
);
8437 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
8438 const u8
*addr
, gfp_t gfp
)
8440 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8441 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8442 struct sk_buff
*msg
;
8445 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
8450 msg
= nlmsg_new(100, gfp
);
8454 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8460 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8461 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8462 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8463 goto nla_put_failure
;
8465 err
= genlmsg_end(msg
, hdr
);
8471 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8475 genlmsg_cancel(msg
, hdr
);
8480 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
8482 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
8486 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
8487 const u8
*addr
, gfp_t gfp
)
8489 return __nl80211_unexpected_frame(dev
,
8490 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
8494 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
8495 struct wireless_dev
*wdev
, u32 nlportid
,
8496 int freq
, int sig_dbm
,
8497 const u8
*buf
, size_t len
, gfp_t gfp
)
8499 struct net_device
*netdev
= wdev
->netdev
;
8500 struct sk_buff
*msg
;
8503 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8507 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8513 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8514 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8515 netdev
->ifindex
)) ||
8516 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8518 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8519 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8520 goto nla_put_failure
;
8522 genlmsg_end(msg
, hdr
);
8524 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8527 genlmsg_cancel(msg
, hdr
);
8532 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
8533 struct wireless_dev
*wdev
, u64 cookie
,
8534 const u8
*buf
, size_t len
, bool ack
,
8537 struct net_device
*netdev
= wdev
->netdev
;
8538 struct sk_buff
*msg
;
8541 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8545 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
8551 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8552 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8553 netdev
->ifindex
)) ||
8554 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
8555 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8556 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8557 goto nla_put_failure
;
8559 genlmsg_end(msg
, hdr
);
8561 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
8565 genlmsg_cancel(msg
, hdr
);
8570 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
8571 struct net_device
*netdev
,
8572 enum nl80211_cqm_rssi_threshold_event rssi_event
,
8575 struct sk_buff
*msg
;
8576 struct nlattr
*pinfoattr
;
8579 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8583 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8589 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8590 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8591 goto nla_put_failure
;
8593 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8595 goto nla_put_failure
;
8597 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
8599 goto nla_put_failure
;
8601 nla_nest_end(msg
, pinfoattr
);
8603 genlmsg_end(msg
, hdr
);
8605 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8606 nl80211_mlme_mcgrp
.id
, gfp
);
8610 genlmsg_cancel(msg
, hdr
);
8614 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
8615 struct net_device
*netdev
, const u8
*bssid
,
8616 const u8
*replay_ctr
, gfp_t gfp
)
8618 struct sk_buff
*msg
;
8619 struct nlattr
*rekey_attr
;
8622 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8626 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8632 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8633 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8634 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8635 goto nla_put_failure
;
8637 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8639 goto nla_put_failure
;
8641 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
8642 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
8643 goto nla_put_failure
;
8645 nla_nest_end(msg
, rekey_attr
);
8647 genlmsg_end(msg
, hdr
);
8649 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8650 nl80211_mlme_mcgrp
.id
, gfp
);
8654 genlmsg_cancel(msg
, hdr
);
8658 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
8659 struct net_device
*netdev
, int index
,
8660 const u8
*bssid
, bool preauth
, gfp_t gfp
)
8662 struct sk_buff
*msg
;
8663 struct nlattr
*attr
;
8666 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8670 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
8676 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8677 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8678 goto nla_put_failure
;
8680 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
8682 goto nla_put_failure
;
8684 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
8685 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
8687 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
8688 goto nla_put_failure
;
8690 nla_nest_end(msg
, attr
);
8692 genlmsg_end(msg
, hdr
);
8694 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8695 nl80211_mlme_mcgrp
.id
, gfp
);
8699 genlmsg_cancel(msg
, hdr
);
8703 void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
8704 struct net_device
*netdev
, int freq
,
8705 enum nl80211_channel_type type
, gfp_t gfp
)
8707 struct sk_buff
*msg
;
8710 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8714 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
8720 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8721 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8722 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, type
))
8723 goto nla_put_failure
;
8725 genlmsg_end(msg
, hdr
);
8727 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8728 nl80211_mlme_mcgrp
.id
, gfp
);
8732 genlmsg_cancel(msg
, hdr
);
8737 nl80211_send_cqm_txe_notify(struct cfg80211_registered_device
*rdev
,
8738 struct net_device
*netdev
, const u8
*peer
,
8739 u32 num_packets
, u32 rate
, u32 intvl
, gfp_t gfp
)
8741 struct sk_buff
*msg
;
8742 struct nlattr
*pinfoattr
;
8745 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8749 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8755 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8756 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8757 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8758 goto nla_put_failure
;
8760 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8762 goto nla_put_failure
;
8764 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
8765 goto nla_put_failure
;
8767 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
8768 goto nla_put_failure
;
8770 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
8771 goto nla_put_failure
;
8773 nla_nest_end(msg
, pinfoattr
);
8775 genlmsg_end(msg
, hdr
);
8777 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8778 nl80211_mlme_mcgrp
.id
, gfp
);
8782 genlmsg_cancel(msg
, hdr
);
8787 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
8788 struct net_device
*netdev
, const u8
*peer
,
8789 u32 num_packets
, gfp_t gfp
)
8791 struct sk_buff
*msg
;
8792 struct nlattr
*pinfoattr
;
8795 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8799 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8805 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8806 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8807 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8808 goto nla_put_failure
;
8810 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8812 goto nla_put_failure
;
8814 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
8815 goto nla_put_failure
;
8817 nla_nest_end(msg
, pinfoattr
);
8819 genlmsg_end(msg
, hdr
);
8821 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8822 nl80211_mlme_mcgrp
.id
, gfp
);
8826 genlmsg_cancel(msg
, hdr
);
8830 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
8831 u64 cookie
, bool acked
, gfp_t gfp
)
8833 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8834 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8835 struct sk_buff
*msg
;
8839 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8843 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
8849 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8850 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8851 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8852 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8853 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8854 goto nla_put_failure
;
8856 err
= genlmsg_end(msg
, hdr
);
8862 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8863 nl80211_mlme_mcgrp
.id
, gfp
);
8867 genlmsg_cancel(msg
, hdr
);
8870 EXPORT_SYMBOL(cfg80211_probe_status
);
8872 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
8873 const u8
*frame
, size_t len
,
8874 int freq
, int sig_dbm
, gfp_t gfp
)
8876 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8877 struct sk_buff
*msg
;
8879 u32 nlportid
= ACCESS_ONCE(rdev
->ap_beacons_nlportid
);
8884 msg
= nlmsg_new(len
+ 100, gfp
);
8888 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8894 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8896 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
8898 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8899 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
8900 goto nla_put_failure
;
8902 genlmsg_end(msg
, hdr
);
8904 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8908 genlmsg_cancel(msg
, hdr
);
8911 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
8913 static int nl80211_netlink_notify(struct notifier_block
* nb
,
8914 unsigned long state
,
8917 struct netlink_notify
*notify
= _notify
;
8918 struct cfg80211_registered_device
*rdev
;
8919 struct wireless_dev
*wdev
;
8921 if (state
!= NETLINK_URELEASE
)
8926 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
8927 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
8928 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
8929 if (rdev
->ap_beacons_nlportid
== notify
->portid
)
8930 rdev
->ap_beacons_nlportid
= 0;
8938 static struct notifier_block nl80211_netlink_notifier
= {
8939 .notifier_call
= nl80211_netlink_notify
,
8942 /* initialisation/exit functions */
8944 int nl80211_init(void)
8948 err
= genl_register_family_with_ops(&nl80211_fam
,
8949 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
8953 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
8957 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
8961 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
8965 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
8969 #ifdef CONFIG_NL80211_TESTMODE
8970 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
8975 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
8981 genl_unregister_family(&nl80211_fam
);
8985 void nl80211_exit(void)
8987 netlink_unregister_notifier(&nl80211_netlink_notifier
);
8988 genl_unregister_family(&nl80211_fam
);