2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
26 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
);
27 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
28 struct genl_info
*info
,
29 struct cfg80211_crypto_settings
*settings
,
32 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
33 struct genl_info
*info
);
34 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
35 struct genl_info
*info
);
37 /* the netlink family */
38 static struct genl_family nl80211_fam
= {
39 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
40 .name
= "nl80211", /* have users key off the name instead */
41 .hdrsize
= 0, /* no private header */
42 .version
= 1, /* no particular meaning now */
43 .maxattr
= NL80211_ATTR_MAX
,
45 .pre_doit
= nl80211_pre_doit
,
46 .post_doit
= nl80211_post_doit
,
49 /* returns ERR_PTR values */
50 static struct wireless_dev
*
51 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
53 struct cfg80211_registered_device
*rdev
;
54 struct wireless_dev
*result
= NULL
;
55 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
56 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
61 assert_cfg80211_lock();
63 if (!have_ifidx
&& !have_wdev_id
)
64 return ERR_PTR(-EINVAL
);
67 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
69 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
70 wiphy_idx
= wdev_id
>> 32;
73 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
74 struct wireless_dev
*wdev
;
76 if (wiphy_net(&rdev
->wiphy
) != netns
)
79 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
82 mutex_lock(&rdev
->devlist_mtx
);
83 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
84 if (have_ifidx
&& wdev
->netdev
&&
85 wdev
->netdev
->ifindex
== ifidx
) {
89 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
94 mutex_unlock(&rdev
->devlist_mtx
);
102 return ERR_PTR(-ENODEV
);
105 static struct cfg80211_registered_device
*
106 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
108 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
109 struct net_device
*netdev
;
111 assert_cfg80211_lock();
113 if (!attrs
[NL80211_ATTR_WIPHY
] &&
114 !attrs
[NL80211_ATTR_IFINDEX
] &&
115 !attrs
[NL80211_ATTR_WDEV
])
116 return ERR_PTR(-EINVAL
);
118 if (attrs
[NL80211_ATTR_WIPHY
])
119 rdev
= cfg80211_rdev_by_wiphy_idx(
120 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
122 if (attrs
[NL80211_ATTR_WDEV
]) {
123 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
124 struct wireless_dev
*wdev
;
127 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
129 /* make sure wdev exists */
130 mutex_lock(&tmp
->devlist_mtx
);
131 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
132 if (wdev
->identifier
!= (u32
)wdev_id
)
137 mutex_unlock(&tmp
->devlist_mtx
);
142 if (rdev
&& tmp
!= rdev
)
143 return ERR_PTR(-EINVAL
);
148 if (attrs
[NL80211_ATTR_IFINDEX
]) {
149 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
150 netdev
= dev_get_by_index(netns
, ifindex
);
152 if (netdev
->ieee80211_ptr
)
154 netdev
->ieee80211_ptr
->wiphy
);
160 /* not wireless device -- return error */
162 return ERR_PTR(-EINVAL
);
164 /* mismatch -- return error */
165 if (rdev
&& tmp
!= rdev
)
166 return ERR_PTR(-EINVAL
);
173 return ERR_PTR(-ENODEV
);
175 if (netns
!= wiphy_net(&rdev
->wiphy
))
176 return ERR_PTR(-ENODEV
);
182 * This function returns a pointer to the driver
183 * that the genl_info item that is passed refers to.
184 * If successful, it returns non-NULL and also locks
185 * the driver's mutex!
187 * This means that you need to call cfg80211_unlock_rdev()
188 * before being allowed to acquire &cfg80211_mutex!
190 * This is necessary because we need to lock the global
191 * mutex to get an item off the list safely, and then
192 * we lock the rdev mutex so it doesn't go away under us.
194 * We don't want to keep cfg80211_mutex locked
195 * for all the time in order to allow requests on
196 * other interfaces to go through at the same time.
198 * The result of this can be a PTR_ERR and hence must
199 * be checked with IS_ERR() for errors.
201 static struct cfg80211_registered_device
*
202 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
204 struct cfg80211_registered_device
*rdev
;
206 mutex_lock(&cfg80211_mutex
);
207 rdev
= __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
209 /* if it is not an error we grab the lock on
210 * it to assure it won't be going away while
211 * we operate on it */
213 mutex_lock(&rdev
->mtx
);
215 mutex_unlock(&cfg80211_mutex
);
220 /* policy for the attributes */
221 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
222 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
225 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
226 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
227 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
228 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
229 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
230 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
232 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
234 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
235 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
236 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
238 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
239 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
241 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
242 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
243 .len
= WLAN_MAX_KEY_LEN
},
244 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
245 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
246 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
247 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
248 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
250 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
253 .len
= IEEE80211_MAX_DATA_LEN
},
254 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
255 .len
= IEEE80211_MAX_DATA_LEN
},
256 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
257 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
258 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
259 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
260 .len
= NL80211_MAX_SUPP_RATES
},
261 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
262 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
263 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
264 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
265 .len
= IEEE80211_MAX_MESH_ID_LEN
},
266 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
268 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
269 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
271 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
272 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
273 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
274 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
275 .len
= NL80211_MAX_SUPP_RATES
},
276 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
278 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
279 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
281 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
283 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
284 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
285 .len
= IEEE80211_MAX_DATA_LEN
},
286 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
287 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
289 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
290 .len
= IEEE80211_MAX_SSID_LEN
},
291 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
292 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
293 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
294 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
295 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
296 [NL80211_ATTR_STA_FLAGS2
] = {
297 .len
= sizeof(struct nl80211_sta_flag_update
),
299 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
301 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
302 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
303 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
304 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
305 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
306 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
307 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
308 .len
= WLAN_PMKID_LEN
},
309 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
311 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
312 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
313 .len
= IEEE80211_MAX_DATA_LEN
},
314 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
315 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
316 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
317 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
318 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
319 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
320 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
321 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
322 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
323 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
324 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
325 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
326 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
327 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
328 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
329 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
331 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
332 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
333 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
334 .len
= IEEE80211_MAX_DATA_LEN
},
335 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
336 .len
= IEEE80211_MAX_DATA_LEN
},
337 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
338 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
339 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
340 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
341 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
342 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
343 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
346 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
347 .len
= IEEE80211_MAX_DATA_LEN
},
348 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
349 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
351 .len
= NL80211_HT_CAPABILITY_LEN
353 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
354 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
355 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
356 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
359 /* policy for the key attributes */
360 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
361 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
362 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
363 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
364 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
365 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
366 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
367 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
368 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
371 /* policy for the key default flags */
372 static const struct nla_policy
373 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
374 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
375 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
378 /* policy for WoWLAN attributes */
379 static const struct nla_policy
380 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
381 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
382 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
383 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
384 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
385 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
386 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
387 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
388 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
391 /* policy for GTK rekey offload attributes */
392 static const struct nla_policy
393 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
394 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
395 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
396 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
399 static const struct nla_policy
400 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
401 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
402 .len
= IEEE80211_MAX_SSID_LEN
},
403 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
406 /* ifidx get helper */
407 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
411 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
412 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
417 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
420 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
426 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
427 struct netlink_callback
*cb
,
428 struct cfg80211_registered_device
**rdev
,
429 struct net_device
**dev
)
431 int ifidx
= cb
->args
[0];
435 ifidx
= nl80211_get_ifidx(cb
);
443 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
449 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
451 err
= PTR_ERR(*rdev
);
461 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
463 cfg80211_unlock_rdev(rdev
);
468 static bool is_valid_ie_attr(const struct nlattr
*attr
)
476 pos
= nla_data(attr
);
497 /* message building helper */
498 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
501 /* since there is no private header just add the generic one */
502 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
505 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
506 struct ieee80211_channel
*chan
)
508 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
510 goto nla_put_failure
;
512 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
513 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
514 goto nla_put_failure
;
515 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
516 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
517 goto nla_put_failure
;
518 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
519 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
520 goto nla_put_failure
;
521 if ((chan
->flags
& IEEE80211_CHAN_RADAR
) &&
522 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
523 goto nla_put_failure
;
525 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
526 DBM_TO_MBM(chan
->max_power
)))
527 goto nla_put_failure
;
535 /* netlink command implementations */
542 bool def_uni
, def_multi
;
545 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
547 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
548 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
553 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
554 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
563 if (tb
[NL80211_KEY_IDX
])
564 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
566 if (tb
[NL80211_KEY_DATA
]) {
567 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
568 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
571 if (tb
[NL80211_KEY_SEQ
]) {
572 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
573 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
576 if (tb
[NL80211_KEY_CIPHER
])
577 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
579 if (tb
[NL80211_KEY_TYPE
]) {
580 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
581 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
585 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
586 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
587 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
588 tb
[NL80211_KEY_DEFAULT_TYPES
],
589 nl80211_key_default_policy
);
593 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
594 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
600 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
602 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
603 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
604 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
607 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
608 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
609 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
612 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
613 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
615 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
616 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
618 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
619 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
628 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
629 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
630 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
634 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
635 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
636 int err
= nla_parse_nested(
637 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
638 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
639 nl80211_key_default_policy
);
643 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
644 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
650 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
654 memset(k
, 0, sizeof(*k
));
658 if (info
->attrs
[NL80211_ATTR_KEY
])
659 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
661 err
= nl80211_parse_key_old(info
, k
);
666 if (k
->def
&& k
->defmgmt
)
670 if (k
->def_uni
|| !k
->def_multi
)
676 if (k
->idx
< 4 || k
->idx
> 5)
679 if (k
->idx
< 0 || k
->idx
> 3)
682 if (k
->idx
< 0 || k
->idx
> 5)
690 static struct cfg80211_cached_keys
*
691 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
694 struct key_parse parse
;
696 struct cfg80211_cached_keys
*result
;
697 int rem
, err
, def
= 0;
699 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
701 return ERR_PTR(-ENOMEM
);
704 result
->defmgmt
= -1;
706 nla_for_each_nested(key
, keys
, rem
) {
707 memset(&parse
, 0, sizeof(parse
));
710 err
= nl80211_parse_key_new(key
, &parse
);
716 if (parse
.idx
< 0 || parse
.idx
> 4)
722 result
->def
= parse
.idx
;
723 if (!parse
.def_uni
|| !parse
.def_multi
)
725 } else if (parse
.defmgmt
)
727 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
728 parse
.idx
, false, NULL
);
731 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
732 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
733 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
734 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
743 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
745 ASSERT_WDEV_LOCK(wdev
);
747 switch (wdev
->iftype
) {
748 case NL80211_IFTYPE_AP
:
749 case NL80211_IFTYPE_AP_VLAN
:
750 case NL80211_IFTYPE_P2P_GO
:
751 case NL80211_IFTYPE_MESH_POINT
:
753 case NL80211_IFTYPE_ADHOC
:
754 if (!wdev
->current_bss
)
757 case NL80211_IFTYPE_STATION
:
758 case NL80211_IFTYPE_P2P_CLIENT
:
759 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
769 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
771 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
775 goto nla_put_failure
;
779 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
780 goto nla_put_failure
;
785 nla_nest_end(msg
, nl_modes
);
792 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
795 struct nlattr
*nl_combis
;
798 nl_combis
= nla_nest_start(msg
,
799 NL80211_ATTR_INTERFACE_COMBINATIONS
);
801 goto nla_put_failure
;
803 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
804 const struct ieee80211_iface_combination
*c
;
805 struct nlattr
*nl_combi
, *nl_limits
;
807 c
= &wiphy
->iface_combinations
[i
];
809 nl_combi
= nla_nest_start(msg
, i
+ 1);
811 goto nla_put_failure
;
813 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
815 goto nla_put_failure
;
817 for (j
= 0; j
< c
->n_limits
; j
++) {
818 struct nlattr
*nl_limit
;
820 nl_limit
= nla_nest_start(msg
, j
+ 1);
822 goto nla_put_failure
;
823 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
825 goto nla_put_failure
;
826 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
828 goto nla_put_failure
;
829 nla_nest_end(msg
, nl_limit
);
832 nla_nest_end(msg
, nl_limits
);
834 if (c
->beacon_int_infra_match
&&
835 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
836 goto nla_put_failure
;
837 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
838 c
->num_different_channels
) ||
839 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
841 goto nla_put_failure
;
843 nla_nest_end(msg
, nl_combi
);
846 nla_nest_end(msg
, nl_combis
);
853 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
854 struct cfg80211_registered_device
*dev
)
857 struct nlattr
*nl_bands
, *nl_band
;
858 struct nlattr
*nl_freqs
, *nl_freq
;
859 struct nlattr
*nl_rates
, *nl_rate
;
860 struct nlattr
*nl_cmds
;
861 enum ieee80211_band band
;
862 struct ieee80211_channel
*chan
;
863 struct ieee80211_rate
*rate
;
865 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
866 dev
->wiphy
.mgmt_stypes
;
868 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
872 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
873 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
)) ||
874 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
875 cfg80211_rdev_list_generation
) ||
876 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
877 dev
->wiphy
.retry_short
) ||
878 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
879 dev
->wiphy
.retry_long
) ||
880 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
881 dev
->wiphy
.frag_threshold
) ||
882 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
883 dev
->wiphy
.rts_threshold
) ||
884 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
885 dev
->wiphy
.coverage_class
) ||
886 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
887 dev
->wiphy
.max_scan_ssids
) ||
888 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
889 dev
->wiphy
.max_sched_scan_ssids
) ||
890 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
891 dev
->wiphy
.max_scan_ie_len
) ||
892 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
893 dev
->wiphy
.max_sched_scan_ie_len
) ||
894 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
895 dev
->wiphy
.max_match_sets
))
896 goto nla_put_failure
;
898 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
899 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
900 goto nla_put_failure
;
901 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
902 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
903 goto nla_put_failure
;
904 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
905 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
906 goto nla_put_failure
;
907 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
908 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
909 goto nla_put_failure
;
910 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
911 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
912 goto nla_put_failure
;
913 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
914 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
915 goto nla_put_failure
;
917 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
918 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
919 dev
->wiphy
.cipher_suites
))
920 goto nla_put_failure
;
922 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
923 dev
->wiphy
.max_num_pmkids
))
924 goto nla_put_failure
;
926 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
927 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
928 goto nla_put_failure
;
930 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
931 dev
->wiphy
.available_antennas_tx
) ||
932 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
933 dev
->wiphy
.available_antennas_rx
))
934 goto nla_put_failure
;
936 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
937 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
938 dev
->wiphy
.probe_resp_offload
))
939 goto nla_put_failure
;
941 if ((dev
->wiphy
.available_antennas_tx
||
942 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
943 u32 tx_ant
= 0, rx_ant
= 0;
945 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
947 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
,
949 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
,
951 goto nla_put_failure
;
955 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
956 dev
->wiphy
.interface_modes
))
957 goto nla_put_failure
;
959 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
961 goto nla_put_failure
;
963 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
964 if (!dev
->wiphy
.bands
[band
])
967 nl_band
= nla_nest_start(msg
, band
);
969 goto nla_put_failure
;
972 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
&&
973 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
974 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
975 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
) ||
976 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
977 dev
->wiphy
.bands
[band
]->ht_cap
.cap
) ||
978 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
979 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
) ||
980 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
981 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
)))
982 goto nla_put_failure
;
985 if (dev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
&&
986 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
987 sizeof(dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
),
988 &dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
) ||
989 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
990 dev
->wiphy
.bands
[band
]->vht_cap
.cap
)))
991 goto nla_put_failure
;
993 /* add frequencies */
994 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
996 goto nla_put_failure
;
998 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
999 nl_freq
= nla_nest_start(msg
, i
);
1001 goto nla_put_failure
;
1003 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
1005 if (nl80211_msg_put_channel(msg
, chan
))
1006 goto nla_put_failure
;
1008 nla_nest_end(msg
, nl_freq
);
1011 nla_nest_end(msg
, nl_freqs
);
1014 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1016 goto nla_put_failure
;
1018 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
1019 nl_rate
= nla_nest_start(msg
, i
);
1021 goto nla_put_failure
;
1023 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
1024 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1026 goto nla_put_failure
;
1027 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1029 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1030 goto nla_put_failure
;
1032 nla_nest_end(msg
, nl_rate
);
1035 nla_nest_end(msg
, nl_rates
);
1037 nla_nest_end(msg
, nl_band
);
1039 nla_nest_end(msg
, nl_bands
);
1041 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1043 goto nla_put_failure
;
1046 #define CMD(op, n) \
1048 if (dev->ops->op) { \
1050 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1051 goto nla_put_failure; \
1055 CMD(add_virtual_intf
, NEW_INTERFACE
);
1056 CMD(change_virtual_intf
, SET_INTERFACE
);
1057 CMD(add_key
, NEW_KEY
);
1058 CMD(start_ap
, START_AP
);
1059 CMD(add_station
, NEW_STATION
);
1060 CMD(add_mpath
, NEW_MPATH
);
1061 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1062 CMD(change_bss
, SET_BSS
);
1063 CMD(auth
, AUTHENTICATE
);
1064 CMD(assoc
, ASSOCIATE
);
1065 CMD(deauth
, DEAUTHENTICATE
);
1066 CMD(disassoc
, DISASSOCIATE
);
1067 CMD(join_ibss
, JOIN_IBSS
);
1068 CMD(join_mesh
, JOIN_MESH
);
1069 CMD(set_pmksa
, SET_PMKSA
);
1070 CMD(del_pmksa
, DEL_PMKSA
);
1071 CMD(flush_pmksa
, FLUSH_PMKSA
);
1072 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1073 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1074 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1075 CMD(mgmt_tx
, FRAME
);
1076 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1077 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1079 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1080 goto nla_put_failure
;
1082 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1083 dev
->ops
->join_mesh
) {
1085 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1086 goto nla_put_failure
;
1088 CMD(set_wds_peer
, SET_WDS_PEER
);
1089 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1090 CMD(tdls_mgmt
, TDLS_MGMT
);
1091 CMD(tdls_oper
, TDLS_OPER
);
1093 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1094 CMD(sched_scan_start
, START_SCHED_SCAN
);
1095 CMD(probe_client
, PROBE_CLIENT
);
1096 CMD(set_noack_map
, SET_NOACK_MAP
);
1097 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1099 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1100 goto nla_put_failure
;
1103 #ifdef CONFIG_NL80211_TESTMODE
1104 CMD(testmode_cmd
, TESTMODE
);
1109 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1111 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1112 goto nla_put_failure
;
1115 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1117 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1118 goto nla_put_failure
;
1121 nla_nest_end(msg
, nl_cmds
);
1123 if (dev
->ops
->remain_on_channel
&&
1124 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1125 nla_put_u32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1126 dev
->wiphy
.max_remain_on_channel_duration
))
1127 goto nla_put_failure
;
1129 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1130 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1131 goto nla_put_failure
;
1135 struct nlattr
*nl_ftypes
, *nl_ifs
;
1136 enum nl80211_iftype ift
;
1138 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1140 goto nla_put_failure
;
1142 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1143 nl_ftypes
= nla_nest_start(msg
, ift
);
1145 goto nla_put_failure
;
1147 stypes
= mgmt_stypes
[ift
].tx
;
1150 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1151 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1152 goto nla_put_failure
;
1156 nla_nest_end(msg
, nl_ftypes
);
1159 nla_nest_end(msg
, nl_ifs
);
1161 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1163 goto nla_put_failure
;
1165 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1166 nl_ftypes
= nla_nest_start(msg
, ift
);
1168 goto nla_put_failure
;
1170 stypes
= mgmt_stypes
[ift
].rx
;
1173 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1174 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1175 goto nla_put_failure
;
1179 nla_nest_end(msg
, nl_ftypes
);
1181 nla_nest_end(msg
, nl_ifs
);
1185 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
1186 struct nlattr
*nl_wowlan
;
1188 nl_wowlan
= nla_nest_start(msg
,
1189 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1191 goto nla_put_failure
;
1193 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1194 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1195 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1196 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1197 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1198 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1199 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1200 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1201 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1202 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1203 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1204 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1205 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1206 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1207 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1208 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1209 goto nla_put_failure
;
1210 if (dev
->wiphy
.wowlan
.n_patterns
) {
1211 struct nl80211_wowlan_pattern_support pat
= {
1212 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1214 dev
->wiphy
.wowlan
.pattern_min_len
,
1216 dev
->wiphy
.wowlan
.pattern_max_len
,
1218 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1220 goto nla_put_failure
;
1223 nla_nest_end(msg
, nl_wowlan
);
1227 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1228 dev
->wiphy
.software_iftypes
))
1229 goto nla_put_failure
;
1231 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1232 goto nla_put_failure
;
1234 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1235 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1236 dev
->wiphy
.ap_sme_capa
))
1237 goto nla_put_failure
;
1239 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
,
1240 dev
->wiphy
.features
))
1241 goto nla_put_failure
;
1243 if (dev
->wiphy
.ht_capa_mod_mask
&&
1244 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1245 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1246 dev
->wiphy
.ht_capa_mod_mask
))
1247 goto nla_put_failure
;
1249 return genlmsg_end(msg
, hdr
);
1252 genlmsg_cancel(msg
, hdr
);
1256 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1259 int start
= cb
->args
[0];
1260 struct cfg80211_registered_device
*dev
;
1262 mutex_lock(&cfg80211_mutex
);
1263 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1264 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1268 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
1269 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1275 mutex_unlock(&cfg80211_mutex
);
1282 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1284 struct sk_buff
*msg
;
1285 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1287 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1291 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
1296 return genlmsg_reply(msg
, info
);
1299 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1300 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1301 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1302 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1303 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1304 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1307 static int parse_txq_params(struct nlattr
*tb
[],
1308 struct ieee80211_txq_params
*txq_params
)
1310 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1311 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1312 !tb
[NL80211_TXQ_ATTR_AIFS
])
1315 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1316 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1317 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1318 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1319 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1321 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1327 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1330 * You can only set the channel explicitly for WDS interfaces,
1331 * all others have their channel managed via their respective
1332 * "establish a connection" command (connect, join, ...)
1334 * For AP/GO and mesh mode, the channel can be set with the
1335 * channel userspace API, but is only stored and passed to the
1336 * low-level driver when the AP starts or the mesh is joined.
1337 * This is for backward compatibility, userspace can also give
1338 * the channel in the start-ap or join-mesh commands instead.
1340 * Monitors are special as they are normally slaved to
1341 * whatever else is going on, so they have their own special
1342 * operation to set the monitor channel if possible.
1345 wdev
->iftype
== NL80211_IFTYPE_AP
||
1346 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1347 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1348 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1351 static bool nl80211_valid_channel_type(struct genl_info
*info
,
1352 enum nl80211_channel_type
*channel_type
)
1354 enum nl80211_channel_type tmp
;
1356 if (!info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1359 tmp
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1360 if (tmp
!= NL80211_CHAN_NO_HT
&&
1361 tmp
!= NL80211_CHAN_HT20
&&
1362 tmp
!= NL80211_CHAN_HT40PLUS
&&
1363 tmp
!= NL80211_CHAN_HT40MINUS
)
1367 *channel_type
= tmp
;
1372 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1373 struct wireless_dev
*wdev
,
1374 struct genl_info
*info
)
1376 struct ieee80211_channel
*channel
;
1377 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1380 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1383 iftype
= wdev
->iftype
;
1385 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1388 if (!nl80211_can_set_dev_channel(wdev
))
1391 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
1392 !nl80211_valid_channel_type(info
, &channel_type
))
1395 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1397 mutex_lock(&rdev
->devlist_mtx
);
1399 case NL80211_IFTYPE_AP
:
1400 case NL80211_IFTYPE_P2P_GO
:
1401 if (wdev
->beacon_interval
) {
1405 channel
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
1406 if (!channel
|| !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
,
1412 wdev
->preset_chan
= channel
;
1413 wdev
->preset_chantype
= channel_type
;
1416 case NL80211_IFTYPE_MESH_POINT
:
1417 result
= cfg80211_set_mesh_freq(rdev
, wdev
, freq
, channel_type
);
1419 case NL80211_IFTYPE_MONITOR
:
1420 result
= cfg80211_set_monitor_channel(rdev
, freq
, channel_type
);
1425 mutex_unlock(&rdev
->devlist_mtx
);
1430 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1432 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1433 struct net_device
*netdev
= info
->user_ptr
[1];
1435 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1438 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1440 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1441 struct net_device
*dev
= info
->user_ptr
[1];
1442 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1445 if (!info
->attrs
[NL80211_ATTR_MAC
])
1448 if (netif_running(dev
))
1451 if (!rdev
->ops
->set_wds_peer
)
1454 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1457 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1458 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1462 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1464 struct cfg80211_registered_device
*rdev
;
1465 struct net_device
*netdev
= NULL
;
1466 struct wireless_dev
*wdev
;
1467 int result
= 0, rem_txq_params
= 0;
1468 struct nlattr
*nl_txq_params
;
1470 u8 retry_short
= 0, retry_long
= 0;
1471 u32 frag_threshold
= 0, rts_threshold
= 0;
1472 u8 coverage_class
= 0;
1475 * Try to find the wiphy and netdev. Normally this
1476 * function shouldn't need the netdev, but this is
1477 * done for backward compatibility -- previously
1478 * setting the channel was done per wiphy, but now
1479 * it is per netdev. Previous userland like hostapd
1480 * also passed a netdev to set_wiphy, so that it is
1481 * possible to let that go to the right netdev!
1483 mutex_lock(&cfg80211_mutex
);
1485 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1486 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1488 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1489 if (netdev
&& netdev
->ieee80211_ptr
) {
1490 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1491 mutex_lock(&rdev
->mtx
);
1497 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1500 mutex_unlock(&cfg80211_mutex
);
1501 return PTR_ERR(rdev
);
1507 mutex_lock(&rdev
->mtx
);
1508 } else if (nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1509 wdev
= netdev
->ieee80211_ptr
;
1514 * end workaround code, by now the rdev is available
1515 * and locked, and wdev may or may not be NULL.
1518 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1519 result
= cfg80211_dev_rename(
1520 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1522 mutex_unlock(&cfg80211_mutex
);
1527 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1528 struct ieee80211_txq_params txq_params
;
1529 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1531 if (!rdev
->ops
->set_txq_params
) {
1532 result
= -EOPNOTSUPP
;
1541 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1542 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1547 if (!netif_running(netdev
)) {
1552 nla_for_each_nested(nl_txq_params
,
1553 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1555 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1556 nla_data(nl_txq_params
),
1557 nla_len(nl_txq_params
),
1559 result
= parse_txq_params(tb
, &txq_params
);
1563 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1571 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1572 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1577 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1578 enum nl80211_tx_power_setting type
;
1581 if (!rdev
->ops
->set_tx_power
) {
1582 result
= -EOPNOTSUPP
;
1586 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1587 type
= nla_get_u32(info
->attrs
[idx
]);
1589 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1590 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1595 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1596 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1597 mbm
= nla_get_u32(info
->attrs
[idx
]);
1600 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1605 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1606 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1608 if ((!rdev
->wiphy
.available_antennas_tx
&&
1609 !rdev
->wiphy
.available_antennas_rx
) ||
1610 !rdev
->ops
->set_antenna
) {
1611 result
= -EOPNOTSUPP
;
1615 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1616 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1618 /* reject antenna configurations which don't match the
1619 * available antenna masks, except for the "all" mask */
1620 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1621 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1626 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1627 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1629 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1636 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1637 retry_short
= nla_get_u8(
1638 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1639 if (retry_short
== 0) {
1643 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1646 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1647 retry_long
= nla_get_u8(
1648 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1649 if (retry_long
== 0) {
1653 changed
|= WIPHY_PARAM_RETRY_LONG
;
1656 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1657 frag_threshold
= nla_get_u32(
1658 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1659 if (frag_threshold
< 256) {
1663 if (frag_threshold
!= (u32
) -1) {
1665 * Fragments (apart from the last one) are required to
1666 * have even length. Make the fragmentation code
1667 * simpler by stripping LSB should someone try to use
1668 * odd threshold value.
1670 frag_threshold
&= ~0x1;
1672 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1675 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1676 rts_threshold
= nla_get_u32(
1677 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1678 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1681 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1682 coverage_class
= nla_get_u8(
1683 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1684 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1688 u8 old_retry_short
, old_retry_long
;
1689 u32 old_frag_threshold
, old_rts_threshold
;
1690 u8 old_coverage_class
;
1692 if (!rdev
->ops
->set_wiphy_params
) {
1693 result
= -EOPNOTSUPP
;
1697 old_retry_short
= rdev
->wiphy
.retry_short
;
1698 old_retry_long
= rdev
->wiphy
.retry_long
;
1699 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1700 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1701 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1703 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1704 rdev
->wiphy
.retry_short
= retry_short
;
1705 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1706 rdev
->wiphy
.retry_long
= retry_long
;
1707 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1708 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1709 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1710 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1711 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1712 rdev
->wiphy
.coverage_class
= coverage_class
;
1714 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1716 rdev
->wiphy
.retry_short
= old_retry_short
;
1717 rdev
->wiphy
.retry_long
= old_retry_long
;
1718 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1719 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1720 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1725 mutex_unlock(&rdev
->mtx
);
1731 static inline u64
wdev_id(struct wireless_dev
*wdev
)
1733 return (u64
)wdev
->identifier
|
1734 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
1737 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1738 struct cfg80211_registered_device
*rdev
,
1739 struct wireless_dev
*wdev
)
1741 struct net_device
*dev
= wdev
->netdev
;
1744 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1749 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
1750 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
) ||
1751 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dev
->dev_addr
)))
1752 goto nla_put_failure
;
1754 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1755 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
1756 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
1757 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1758 rdev
->devlist_generation
^
1759 (cfg80211_rdev_list_generation
<< 2)))
1760 goto nla_put_failure
;
1762 if (rdev
->monitor_channel
) {
1763 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
1764 rdev
->monitor_channel
->center_freq
) ||
1765 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
1766 rdev
->monitor_channel_type
))
1767 goto nla_put_failure
;
1770 return genlmsg_end(msg
, hdr
);
1773 genlmsg_cancel(msg
, hdr
);
1777 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1781 int wp_start
= cb
->args
[0];
1782 int if_start
= cb
->args
[1];
1783 struct cfg80211_registered_device
*rdev
;
1784 struct wireless_dev
*wdev
;
1786 mutex_lock(&cfg80211_mutex
);
1787 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1788 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1790 if (wp_idx
< wp_start
) {
1796 mutex_lock(&rdev
->devlist_mtx
);
1797 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
1798 if (if_idx
< if_start
) {
1802 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1803 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1805 mutex_unlock(&rdev
->devlist_mtx
);
1810 mutex_unlock(&rdev
->devlist_mtx
);
1815 mutex_unlock(&cfg80211_mutex
);
1817 cb
->args
[0] = wp_idx
;
1818 cb
->args
[1] = if_idx
;
1823 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1825 struct sk_buff
*msg
;
1826 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1827 struct wireless_dev
*wdev
= info
->user_ptr
[1];
1829 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1833 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1839 return genlmsg_reply(msg
, info
);
1842 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1843 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1844 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1845 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1846 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1847 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1850 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1852 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1860 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1861 nla
, mntr_flags_policy
))
1864 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1866 *mntrflags
|= (1<<flag
);
1871 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1872 struct net_device
*netdev
, u8 use_4addr
,
1873 enum nl80211_iftype iftype
)
1876 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1882 case NL80211_IFTYPE_AP_VLAN
:
1883 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1886 case NL80211_IFTYPE_STATION
:
1887 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1897 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1899 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1900 struct vif_params params
;
1902 enum nl80211_iftype otype
, ntype
;
1903 struct net_device
*dev
= info
->user_ptr
[1];
1904 u32 _flags
, *flags
= NULL
;
1905 bool change
= false;
1907 memset(¶ms
, 0, sizeof(params
));
1909 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1911 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1912 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1915 if (ntype
> NL80211_IFTYPE_MAX
)
1919 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1920 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1922 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1924 if (netif_running(dev
))
1928 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1929 IEEE80211_MAX_MESH_ID_LEN
);
1930 wdev
->mesh_id_up_len
=
1931 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1932 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1933 wdev
->mesh_id_up_len
);
1937 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1938 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1940 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1944 params
.use_4addr
= -1;
1947 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1948 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1950 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1960 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1964 if (!err
&& params
.use_4addr
!= -1)
1965 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1970 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1972 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1973 struct vif_params params
;
1974 struct wireless_dev
*wdev
;
1976 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1979 memset(¶ms
, 0, sizeof(params
));
1981 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1984 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1985 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1986 if (type
> NL80211_IFTYPE_MAX
)
1990 if (!rdev
->ops
->add_virtual_intf
||
1991 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1994 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1995 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1996 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2001 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2002 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2004 wdev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
2005 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2006 type
, err
? NULL
: &flags
, ¶ms
);
2008 return PTR_ERR(wdev
);
2010 if (type
== NL80211_IFTYPE_MESH_POINT
&&
2011 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2013 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2014 IEEE80211_MAX_MESH_ID_LEN
);
2015 wdev
->mesh_id_up_len
=
2016 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2017 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2018 wdev
->mesh_id_up_len
);
2025 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2027 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2028 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2030 if (!rdev
->ops
->del_virtual_intf
)
2034 * If we remove a wireless device without a netdev then clear
2035 * user_ptr[1] so that nl80211_post_doit won't dereference it
2036 * to check if it needs to do dev_put(). Otherwise it crashes
2037 * since the wdev has been freed, unlike with a netdev where
2038 * we need the dev_put() for the netdev to really be freed.
2041 info
->user_ptr
[1] = NULL
;
2043 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, wdev
);
2046 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2048 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2049 struct net_device
*dev
= info
->user_ptr
[1];
2052 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2055 if (!rdev
->ops
->set_noack_map
)
2058 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2060 return rdev
->ops
->set_noack_map(&rdev
->wiphy
, dev
, noack_map
);
2063 struct get_key_cookie
{
2064 struct sk_buff
*msg
;
2069 static void get_key_callback(void *c
, struct key_params
*params
)
2072 struct get_key_cookie
*cookie
= c
;
2075 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2076 params
->key_len
, params
->key
)) ||
2078 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2079 params
->seq_len
, params
->seq
)) ||
2081 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2083 goto nla_put_failure
;
2085 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2087 goto nla_put_failure
;
2090 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2091 params
->key_len
, params
->key
)) ||
2093 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2094 params
->seq_len
, params
->seq
)) ||
2096 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2098 goto nla_put_failure
;
2100 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2101 goto nla_put_failure
;
2103 nla_nest_end(cookie
->msg
, key
);
2110 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2112 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2114 struct net_device
*dev
= info
->user_ptr
[1];
2116 const u8
*mac_addr
= NULL
;
2118 struct get_key_cookie cookie
= {
2122 struct sk_buff
*msg
;
2124 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2125 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2130 if (info
->attrs
[NL80211_ATTR_MAC
])
2131 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2133 pairwise
= !!mac_addr
;
2134 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2135 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2136 if (kt
>= NUM_NL80211_KEYTYPES
)
2138 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2139 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2141 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2144 if (!rdev
->ops
->get_key
)
2147 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2151 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2152 NL80211_CMD_NEW_KEY
);
2154 return PTR_ERR(hdr
);
2157 cookie
.idx
= key_idx
;
2159 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2160 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2161 goto nla_put_failure
;
2163 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2164 goto nla_put_failure
;
2166 if (pairwise
&& mac_addr
&&
2167 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2170 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
2171 mac_addr
, &cookie
, get_key_callback
);
2177 goto nla_put_failure
;
2179 genlmsg_end(msg
, hdr
);
2180 return genlmsg_reply(msg
, info
);
2189 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2191 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2192 struct key_parse key
;
2194 struct net_device
*dev
= info
->user_ptr
[1];
2196 err
= nl80211_parse_key(info
, &key
);
2203 /* only support setting default key */
2204 if (!key
.def
&& !key
.defmgmt
)
2207 wdev_lock(dev
->ieee80211_ptr
);
2210 if (!rdev
->ops
->set_default_key
) {
2215 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2219 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
2220 key
.def_uni
, key
.def_multi
);
2225 #ifdef CONFIG_CFG80211_WEXT
2226 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2229 if (key
.def_uni
|| !key
.def_multi
) {
2234 if (!rdev
->ops
->set_default_mgmt_key
) {
2239 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2243 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
2248 #ifdef CONFIG_CFG80211_WEXT
2249 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2254 wdev_unlock(dev
->ieee80211_ptr
);
2259 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2261 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2263 struct net_device
*dev
= info
->user_ptr
[1];
2264 struct key_parse key
;
2265 const u8
*mac_addr
= NULL
;
2267 err
= nl80211_parse_key(info
, &key
);
2274 if (info
->attrs
[NL80211_ATTR_MAC
])
2275 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2277 if (key
.type
== -1) {
2279 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2281 key
.type
= NL80211_KEYTYPE_GROUP
;
2285 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2286 key
.type
!= NL80211_KEYTYPE_GROUP
)
2289 if (!rdev
->ops
->add_key
)
2292 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2293 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2297 wdev_lock(dev
->ieee80211_ptr
);
2298 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2300 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
2301 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2303 wdev_unlock(dev
->ieee80211_ptr
);
2308 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2310 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2312 struct net_device
*dev
= info
->user_ptr
[1];
2313 u8
*mac_addr
= NULL
;
2314 struct key_parse key
;
2316 err
= nl80211_parse_key(info
, &key
);
2320 if (info
->attrs
[NL80211_ATTR_MAC
])
2321 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2323 if (key
.type
== -1) {
2325 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2327 key
.type
= NL80211_KEYTYPE_GROUP
;
2331 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2332 key
.type
!= NL80211_KEYTYPE_GROUP
)
2335 if (!rdev
->ops
->del_key
)
2338 wdev_lock(dev
->ieee80211_ptr
);
2339 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2341 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2342 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2346 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
2347 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2350 #ifdef CONFIG_CFG80211_WEXT
2352 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2353 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2354 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2355 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2358 wdev_unlock(dev
->ieee80211_ptr
);
2363 static int nl80211_parse_beacon(struct genl_info
*info
,
2364 struct cfg80211_beacon_data
*bcn
)
2366 bool haveinfo
= false;
2368 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2369 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2370 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2371 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2374 memset(bcn
, 0, sizeof(*bcn
));
2376 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2377 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2378 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2384 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2385 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2387 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2394 if (info
->attrs
[NL80211_ATTR_IE
]) {
2395 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2396 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2399 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2400 bcn
->proberesp_ies
=
2401 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2402 bcn
->proberesp_ies_len
=
2403 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2406 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2407 bcn
->assocresp_ies
=
2408 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2409 bcn
->assocresp_ies_len
=
2410 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2413 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2415 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2416 bcn
->probe_resp_len
=
2417 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2423 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2424 struct cfg80211_ap_settings
*params
)
2426 struct wireless_dev
*wdev
;
2429 mutex_lock(&rdev
->devlist_mtx
);
2431 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2432 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2433 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2436 if (!wdev
->preset_chan
)
2439 params
->channel
= wdev
->preset_chan
;
2440 params
->channel_type
= wdev
->preset_chantype
;
2445 mutex_unlock(&rdev
->devlist_mtx
);
2450 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2452 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2453 struct net_device
*dev
= info
->user_ptr
[1];
2454 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2455 struct cfg80211_ap_settings params
;
2458 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2459 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2462 if (!rdev
->ops
->start_ap
)
2465 if (wdev
->beacon_interval
)
2468 memset(¶ms
, 0, sizeof(params
));
2470 /* these are required for START_AP */
2471 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2472 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2473 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2476 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
2480 params
.beacon_interval
=
2481 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2482 params
.dtim_period
=
2483 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2485 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
2490 * In theory, some of these attributes should be required here
2491 * but since they were not used when the command was originally
2492 * added, keep them optional for old user space programs to let
2493 * them continue to work with drivers that do not need the
2494 * additional information -- drivers must check!
2496 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2497 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2499 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2500 if (params
.ssid_len
== 0 ||
2501 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2505 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2506 params
.hidden_ssid
= nla_get_u32(
2507 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2508 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2509 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
2510 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2514 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2516 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2517 params
.auth_type
= nla_get_u32(
2518 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2519 if (!nl80211_valid_auth_type(params
.auth_type
))
2522 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2524 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2525 NL80211_MAX_NR_CIPHER_SUITES
);
2529 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
2530 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
2532 params
.inactivity_timeout
= nla_get_u16(
2533 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
2536 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2537 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
2539 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
2540 !nl80211_valid_channel_type(info
, &channel_type
))
2543 params
.channel
= rdev_freq_to_chan(rdev
,
2544 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
2546 if (!params
.channel
)
2548 params
.channel_type
= channel_type
;
2549 } else if (wdev
->preset_chan
) {
2550 params
.channel
= wdev
->preset_chan
;
2551 params
.channel_type
= wdev
->preset_chantype
;
2552 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
2555 if (!cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, params
.channel
,
2556 params
.channel_type
))
2559 mutex_lock(&rdev
->devlist_mtx
);
2560 err
= cfg80211_can_use_chan(rdev
, wdev
, params
.channel
,
2562 mutex_unlock(&rdev
->devlist_mtx
);
2567 err
= rdev
->ops
->start_ap(&rdev
->wiphy
, dev
, ¶ms
);
2569 wdev
->preset_chan
= params
.channel
;
2570 wdev
->preset_chantype
= params
.channel_type
;
2571 wdev
->beacon_interval
= params
.beacon_interval
;
2572 wdev
->channel
= params
.channel
;
2577 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2579 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2580 struct net_device
*dev
= info
->user_ptr
[1];
2581 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2582 struct cfg80211_beacon_data params
;
2585 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2586 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2589 if (!rdev
->ops
->change_beacon
)
2592 if (!wdev
->beacon_interval
)
2595 err
= nl80211_parse_beacon(info
, ¶ms
);
2599 return rdev
->ops
->change_beacon(&rdev
->wiphy
, dev
, ¶ms
);
2602 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2604 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2605 struct net_device
*dev
= info
->user_ptr
[1];
2607 return cfg80211_stop_ap(rdev
, dev
);
2610 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2611 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2612 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2613 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2614 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2615 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2616 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
2619 static int parse_station_flags(struct genl_info
*info
,
2620 enum nl80211_iftype iftype
,
2621 struct station_parameters
*params
)
2623 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2628 * Try parsing the new attribute first so userspace
2629 * can specify both for older kernels.
2631 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2633 struct nl80211_sta_flag_update
*sta_flags
;
2635 sta_flags
= nla_data(nla
);
2636 params
->sta_flags_mask
= sta_flags
->mask
;
2637 params
->sta_flags_set
= sta_flags
->set
;
2638 if ((params
->sta_flags_mask
|
2639 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2644 /* if present, parse the old attribute */
2646 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2650 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2651 nla
, sta_flags_policy
))
2655 * Only allow certain flags for interface types so that
2656 * other attributes are silently ignored. Remember that
2657 * this is backward compatibility code with old userspace
2658 * and shouldn't be hit in other cases anyway.
2661 case NL80211_IFTYPE_AP
:
2662 case NL80211_IFTYPE_AP_VLAN
:
2663 case NL80211_IFTYPE_P2P_GO
:
2664 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2665 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2666 BIT(NL80211_STA_FLAG_WME
) |
2667 BIT(NL80211_STA_FLAG_MFP
);
2669 case NL80211_IFTYPE_P2P_CLIENT
:
2670 case NL80211_IFTYPE_STATION
:
2671 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2672 BIT(NL80211_STA_FLAG_TDLS_PEER
);
2674 case NL80211_IFTYPE_MESH_POINT
:
2675 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2676 BIT(NL80211_STA_FLAG_MFP
) |
2677 BIT(NL80211_STA_FLAG_AUTHORIZED
);
2682 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
2684 params
->sta_flags_set
|= (1<<flag
);
2686 /* no longer support new API additions in old API */
2687 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
2695 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2698 struct nlattr
*rate
;
2702 rate
= nla_nest_start(msg
, attr
);
2704 goto nla_put_failure
;
2706 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2707 bitrate
= cfg80211_calculate_bitrate(info
);
2708 /* report 16-bit bitrate only if we can */
2709 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
2711 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
)) ||
2712 (bitrate_compat
> 0 &&
2713 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
)) ||
2714 ((info
->flags
& RATE_INFO_FLAGS_MCS
) &&
2715 nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
)) ||
2716 ((info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) &&
2717 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
)) ||
2718 ((info
->flags
& RATE_INFO_FLAGS_SHORT_GI
) &&
2719 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
)))
2720 goto nla_put_failure
;
2722 nla_nest_end(msg
, rate
);
2729 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2731 struct cfg80211_registered_device
*rdev
,
2732 struct net_device
*dev
,
2733 const u8
*mac_addr
, struct station_info
*sinfo
)
2736 struct nlattr
*sinfoattr
, *bss_param
;
2738 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2742 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2743 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
2744 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
2745 goto nla_put_failure
;
2747 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2749 goto nla_put_failure
;
2750 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
2751 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2752 sinfo
->connected_time
))
2753 goto nla_put_failure
;
2754 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
2755 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2756 sinfo
->inactive_time
))
2757 goto nla_put_failure
;
2758 if ((sinfo
->filled
& STATION_INFO_RX_BYTES
) &&
2759 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
2761 goto nla_put_failure
;
2762 if ((sinfo
->filled
& STATION_INFO_TX_BYTES
) &&
2763 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
2765 goto nla_put_failure
;
2766 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
2767 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
2768 goto nla_put_failure
;
2769 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
2770 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
2771 goto nla_put_failure
;
2772 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
2773 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2774 sinfo
->plink_state
))
2775 goto nla_put_failure
;
2776 switch (rdev
->wiphy
.signal_type
) {
2777 case CFG80211_SIGNAL_TYPE_MBM
:
2778 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
2779 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
2781 goto nla_put_failure
;
2782 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
2783 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2785 goto nla_put_failure
;
2790 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2791 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2792 NL80211_STA_INFO_TX_BITRATE
))
2793 goto nla_put_failure
;
2795 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2796 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2797 NL80211_STA_INFO_RX_BITRATE
))
2798 goto nla_put_failure
;
2800 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
2801 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2803 goto nla_put_failure
;
2804 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
2805 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2807 goto nla_put_failure
;
2808 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
2809 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2811 goto nla_put_failure
;
2812 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
2813 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
2815 goto nla_put_failure
;
2816 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
2817 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
2818 sinfo
->beacon_loss_count
))
2819 goto nla_put_failure
;
2820 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2821 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2823 goto nla_put_failure
;
2825 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
2826 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
2827 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
2828 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
2829 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
2830 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
2831 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2832 sinfo
->bss_param
.dtim_period
) ||
2833 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2834 sinfo
->bss_param
.beacon_interval
))
2835 goto nla_put_failure
;
2837 nla_nest_end(msg
, bss_param
);
2839 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
2840 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
2841 sizeof(struct nl80211_sta_flag_update
),
2843 goto nla_put_failure
;
2844 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
2845 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
2847 goto nla_put_failure
;
2848 nla_nest_end(msg
, sinfoattr
);
2850 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
2851 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2852 sinfo
->assoc_req_ies
))
2853 goto nla_put_failure
;
2855 return genlmsg_end(msg
, hdr
);
2858 genlmsg_cancel(msg
, hdr
);
2862 static int nl80211_dump_station(struct sk_buff
*skb
,
2863 struct netlink_callback
*cb
)
2865 struct station_info sinfo
;
2866 struct cfg80211_registered_device
*dev
;
2867 struct net_device
*netdev
;
2868 u8 mac_addr
[ETH_ALEN
];
2869 int sta_idx
= cb
->args
[1];
2872 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2876 if (!dev
->ops
->dump_station
) {
2882 memset(&sinfo
, 0, sizeof(sinfo
));
2883 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2890 if (nl80211_send_station(skb
,
2891 NETLINK_CB(cb
->skb
).pid
,
2892 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2893 dev
, netdev
, mac_addr
,
2902 cb
->args
[1] = sta_idx
;
2905 nl80211_finish_netdev_dump(dev
);
2910 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2912 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2913 struct net_device
*dev
= info
->user_ptr
[1];
2914 struct station_info sinfo
;
2915 struct sk_buff
*msg
;
2916 u8
*mac_addr
= NULL
;
2919 memset(&sinfo
, 0, sizeof(sinfo
));
2921 if (!info
->attrs
[NL80211_ATTR_MAC
])
2924 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2926 if (!rdev
->ops
->get_station
)
2929 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2933 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2937 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2938 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
2943 return genlmsg_reply(msg
, info
);
2947 * Get vlan interface making sure it is running and on the right wiphy.
2949 static struct net_device
*get_vlan(struct genl_info
*info
,
2950 struct cfg80211_registered_device
*rdev
)
2952 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2953 struct net_device
*v
;
2959 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
2961 return ERR_PTR(-ENODEV
);
2963 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
2968 if (!netif_running(v
)) {
2976 return ERR_PTR(ret
);
2979 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2981 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2983 struct net_device
*dev
= info
->user_ptr
[1];
2984 struct station_parameters params
;
2985 u8
*mac_addr
= NULL
;
2987 memset(¶ms
, 0, sizeof(params
));
2989 params
.listen_interval
= -1;
2990 params
.plink_state
= -1;
2992 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2995 if (!info
->attrs
[NL80211_ATTR_MAC
])
2998 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3000 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3001 params
.supported_rates
=
3002 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3003 params
.supported_rates_len
=
3004 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3007 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3008 params
.listen_interval
=
3009 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3011 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3013 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3015 if (!rdev
->ops
->change_station
)
3018 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3021 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3022 params
.plink_action
=
3023 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3025 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
3026 params
.plink_state
=
3027 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3029 switch (dev
->ieee80211_ptr
->iftype
) {
3030 case NL80211_IFTYPE_AP
:
3031 case NL80211_IFTYPE_AP_VLAN
:
3032 case NL80211_IFTYPE_P2P_GO
:
3033 /* disallow mesh-specific things */
3034 if (params
.plink_action
)
3037 /* TDLS can't be set, ... */
3038 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3041 * ... but don't bother the driver with it. This works around
3042 * a hostapd/wpa_supplicant issue -- it always includes the
3043 * TLDS_PEER flag in the mask even for AP mode.
3045 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3047 /* accept only the listed bits */
3048 if (params
.sta_flags_mask
&
3049 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3050 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3051 BIT(NL80211_STA_FLAG_WME
) |
3052 BIT(NL80211_STA_FLAG_MFP
)))
3055 /* must be last in here for error handling */
3056 params
.vlan
= get_vlan(info
, rdev
);
3057 if (IS_ERR(params
.vlan
))
3058 return PTR_ERR(params
.vlan
);
3060 case NL80211_IFTYPE_P2P_CLIENT
:
3061 case NL80211_IFTYPE_STATION
:
3063 * Don't allow userspace to change the TDLS_PEER flag,
3064 * but silently ignore attempts to change it since we
3065 * don't have state here to verify that it doesn't try
3066 * to change the flag.
3068 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3070 case NL80211_IFTYPE_ADHOC
:
3071 /* disallow things sta doesn't support */
3072 if (params
.plink_action
)
3076 if (params
.listen_interval
>= 0)
3078 /* reject any changes other than AUTHORIZED */
3079 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3082 case NL80211_IFTYPE_MESH_POINT
:
3083 /* disallow things mesh doesn't support */
3088 if (params
.listen_interval
>= 0)
3091 * No special handling for TDLS here -- the userspace
3092 * mesh code doesn't have this bug.
3094 if (params
.sta_flags_mask
&
3095 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3096 BIT(NL80211_STA_FLAG_MFP
) |
3097 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3104 /* be aware of params.vlan when changing code here */
3106 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3109 dev_put(params
.vlan
);
3114 static struct nla_policy
3115 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3116 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3117 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3120 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3122 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3124 struct net_device
*dev
= info
->user_ptr
[1];
3125 struct station_parameters params
;
3126 u8
*mac_addr
= NULL
;
3128 memset(¶ms
, 0, sizeof(params
));
3130 if (!info
->attrs
[NL80211_ATTR_MAC
])
3133 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3136 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3139 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3142 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3143 params
.supported_rates
=
3144 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3145 params
.supported_rates_len
=
3146 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3147 params
.listen_interval
=
3148 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3150 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3151 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3154 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3156 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3158 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3159 params
.plink_action
=
3160 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3162 if (!rdev
->ops
->add_station
)
3165 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3168 switch (dev
->ieee80211_ptr
->iftype
) {
3169 case NL80211_IFTYPE_AP
:
3170 case NL80211_IFTYPE_AP_VLAN
:
3171 case NL80211_IFTYPE_P2P_GO
:
3172 /* parse WME attributes if sta is WME capable */
3173 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
3174 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
3175 info
->attrs
[NL80211_ATTR_STA_WME
]) {
3176 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3179 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3180 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3181 nl80211_sta_wme_policy
);
3185 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3186 params
.uapsd_queues
=
3187 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3188 if (params
.uapsd_queues
&
3189 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3192 if (tb
[NL80211_STA_WME_MAX_SP
])
3194 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3197 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3200 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3202 /* TDLS peers cannot be added */
3203 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3205 /* but don't bother the driver with it */
3206 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3208 /* must be last in here for error handling */
3209 params
.vlan
= get_vlan(info
, rdev
);
3210 if (IS_ERR(params
.vlan
))
3211 return PTR_ERR(params
.vlan
);
3213 case NL80211_IFTYPE_MESH_POINT
:
3214 /* TDLS peers cannot be added */
3215 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3218 case NL80211_IFTYPE_STATION
:
3219 /* Only TDLS peers can be added */
3220 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3222 /* Can only add if TDLS ... */
3223 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3225 /* ... with external setup is supported */
3226 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3233 /* be aware of params.vlan when changing code here */
3235 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3238 dev_put(params
.vlan
);
3242 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
3244 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3245 struct net_device
*dev
= info
->user_ptr
[1];
3246 u8
*mac_addr
= NULL
;
3248 if (info
->attrs
[NL80211_ATTR_MAC
])
3249 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3251 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3252 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3253 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
3254 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3257 if (!rdev
->ops
->del_station
)
3260 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
3263 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3264 int flags
, struct net_device
*dev
,
3265 u8
*dst
, u8
*next_hop
,
3266 struct mpath_info
*pinfo
)
3269 struct nlattr
*pinfoattr
;
3271 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3275 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3276 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
3277 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
3278 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
3279 goto nla_put_failure
;
3281 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
3283 goto nla_put_failure
;
3284 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
3285 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
3287 goto nla_put_failure
;
3288 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
3289 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
3290 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
3291 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
3293 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
3294 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
3296 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
3297 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
3299 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
3300 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
3301 pinfo
->discovery_timeout
)) ||
3302 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
3303 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
3304 pinfo
->discovery_retries
)))
3305 goto nla_put_failure
;
3307 nla_nest_end(msg
, pinfoattr
);
3309 return genlmsg_end(msg
, hdr
);
3312 genlmsg_cancel(msg
, hdr
);
3316 static int nl80211_dump_mpath(struct sk_buff
*skb
,
3317 struct netlink_callback
*cb
)
3319 struct mpath_info pinfo
;
3320 struct cfg80211_registered_device
*dev
;
3321 struct net_device
*netdev
;
3323 u8 next_hop
[ETH_ALEN
];
3324 int path_idx
= cb
->args
[1];
3327 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3331 if (!dev
->ops
->dump_mpath
) {
3336 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
3342 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
3343 dst
, next_hop
, &pinfo
);
3349 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
3350 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3351 netdev
, dst
, next_hop
,
3360 cb
->args
[1] = path_idx
;
3363 nl80211_finish_netdev_dump(dev
);
3367 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3369 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3371 struct net_device
*dev
= info
->user_ptr
[1];
3372 struct mpath_info pinfo
;
3373 struct sk_buff
*msg
;
3375 u8 next_hop
[ETH_ALEN
];
3377 memset(&pinfo
, 0, sizeof(pinfo
));
3379 if (!info
->attrs
[NL80211_ATTR_MAC
])
3382 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3384 if (!rdev
->ops
->get_mpath
)
3387 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3390 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
3394 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3398 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3399 dev
, dst
, next_hop
, &pinfo
) < 0) {
3404 return genlmsg_reply(msg
, info
);
3407 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3409 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3410 struct net_device
*dev
= info
->user_ptr
[1];
3412 u8
*next_hop
= NULL
;
3414 if (!info
->attrs
[NL80211_ATTR_MAC
])
3417 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3420 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3421 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3423 if (!rdev
->ops
->change_mpath
)
3426 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3429 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3432 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3434 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3435 struct net_device
*dev
= info
->user_ptr
[1];
3437 u8
*next_hop
= NULL
;
3439 if (!info
->attrs
[NL80211_ATTR_MAC
])
3442 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3445 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3446 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3448 if (!rdev
->ops
->add_mpath
)
3451 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3454 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3457 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3459 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3460 struct net_device
*dev
= info
->user_ptr
[1];
3463 if (info
->attrs
[NL80211_ATTR_MAC
])
3464 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3466 if (!rdev
->ops
->del_mpath
)
3469 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
3472 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
3474 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3475 struct net_device
*dev
= info
->user_ptr
[1];
3476 struct bss_parameters params
;
3478 memset(¶ms
, 0, sizeof(params
));
3479 /* default to not changing parameters */
3480 params
.use_cts_prot
= -1;
3481 params
.use_short_preamble
= -1;
3482 params
.use_short_slot_time
= -1;
3483 params
.ap_isolate
= -1;
3484 params
.ht_opmode
= -1;
3486 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
3487 params
.use_cts_prot
=
3488 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
3489 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
3490 params
.use_short_preamble
=
3491 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
3492 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
3493 params
.use_short_slot_time
=
3494 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
3495 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3496 params
.basic_rates
=
3497 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3498 params
.basic_rates_len
=
3499 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3501 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
3502 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
3503 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
3505 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
3507 if (!rdev
->ops
->change_bss
)
3510 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3511 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3514 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
3517 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
3518 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3519 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3520 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3521 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3522 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3523 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3526 static int parse_reg_rule(struct nlattr
*tb
[],
3527 struct ieee80211_reg_rule
*reg_rule
)
3529 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3530 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3532 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3534 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3536 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3538 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3540 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3543 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3545 freq_range
->start_freq_khz
=
3546 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3547 freq_range
->end_freq_khz
=
3548 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3549 freq_range
->max_bandwidth_khz
=
3550 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3552 power_rule
->max_eirp
=
3553 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3555 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3556 power_rule
->max_antenna_gain
=
3557 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3562 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3568 * You should only get this when cfg80211 hasn't yet initialized
3569 * completely when built-in to the kernel right between the time
3570 * window between nl80211_init() and regulatory_init(), if that is
3573 mutex_lock(&cfg80211_mutex
);
3574 if (unlikely(!cfg80211_regdomain
)) {
3575 mutex_unlock(&cfg80211_mutex
);
3576 return -EINPROGRESS
;
3578 mutex_unlock(&cfg80211_mutex
);
3580 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3583 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3585 r
= regulatory_hint_user(data
);
3590 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3591 struct genl_info
*info
)
3593 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3594 struct net_device
*dev
= info
->user_ptr
[1];
3595 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3596 struct mesh_config cur_params
;
3599 struct nlattr
*pinfoattr
;
3600 struct sk_buff
*msg
;
3602 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3605 if (!rdev
->ops
->get_mesh_config
)
3609 /* If not connected, get default parameters */
3610 if (!wdev
->mesh_id_len
)
3611 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3613 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3620 /* Draw up a netlink message to send back */
3621 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3624 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3625 NL80211_CMD_GET_MESH_CONFIG
);
3628 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3630 goto nla_put_failure
;
3631 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3632 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3633 cur_params
.dot11MeshRetryTimeout
) ||
3634 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3635 cur_params
.dot11MeshConfirmTimeout
) ||
3636 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3637 cur_params
.dot11MeshHoldingTimeout
) ||
3638 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3639 cur_params
.dot11MeshMaxPeerLinks
) ||
3640 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3641 cur_params
.dot11MeshMaxRetries
) ||
3642 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
3643 cur_params
.dot11MeshTTL
) ||
3644 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3645 cur_params
.element_ttl
) ||
3646 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3647 cur_params
.auto_open_plinks
) ||
3648 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3649 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
3650 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3651 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
3652 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3653 cur_params
.path_refresh_time
) ||
3654 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3655 cur_params
.min_discovery_timeout
) ||
3656 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3657 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
3658 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3659 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
3660 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3661 cur_params
.dot11MeshHWMPperrMinInterval
) ||
3662 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3663 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
3664 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3665 cur_params
.dot11MeshHWMPRootMode
) ||
3666 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3667 cur_params
.dot11MeshHWMPRannInterval
) ||
3668 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3669 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
3670 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
3671 cur_params
.dot11MeshForwarding
) ||
3672 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3673 cur_params
.rssi_threshold
) ||
3674 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
3675 cur_params
.ht_opmode
) ||
3676 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3677 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
3678 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3679 cur_params
.dot11MeshHWMProotInterval
) ||
3680 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3681 cur_params
.dot11MeshHWMPconfirmationInterval
))
3682 goto nla_put_failure
;
3683 nla_nest_end(msg
, pinfoattr
);
3684 genlmsg_end(msg
, hdr
);
3685 return genlmsg_reply(msg
, info
);
3688 genlmsg_cancel(msg
, hdr
);
3694 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3695 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3696 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3697 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3698 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3699 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3700 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3701 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3702 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3703 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
3704 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3705 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3706 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3707 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3708 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3709 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
3710 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3711 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3712 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3713 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3714 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
3715 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
3716 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
3717 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
3718 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
3719 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
3722 static const struct nla_policy
3723 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3724 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
3725 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3726 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3727 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3728 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3729 .len
= IEEE80211_MAX_DATA_LEN
},
3730 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3733 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3734 struct mesh_config
*cfg
,
3737 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3740 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3742 if (table[attr_num]) {\
3743 cfg->param = nla_fn(table[attr_num]); \
3744 mask |= (1 << (attr_num - 1)); \
3749 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3751 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3752 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3753 nl80211_meshconf_params_policy
))
3756 /* This makes sure that there aren't more than 32 mesh config
3757 * parameters (otherwise our bitfield scheme would not work.) */
3758 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3760 /* Fill in the params struct */
3761 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3762 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3764 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3765 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3767 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3768 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3770 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3771 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3773 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3774 mask
, NL80211_MESHCONF_MAX_RETRIES
,
3776 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3777 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3778 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3779 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
3781 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3782 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3784 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
, mask
,
3785 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3787 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3788 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3790 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3791 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3793 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3794 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3796 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
, mask
,
3797 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3799 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3800 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3802 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
3803 mask
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3805 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3806 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
3807 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3809 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
3810 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
3811 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
3812 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3814 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3815 dot11MeshGateAnnouncementProtocol
, mask
,
3816 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3818 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
,
3819 mask
, NL80211_MESHCONF_FORWARDING
,
3821 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
,
3822 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3824 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
,
3825 mask
, NL80211_MESHCONF_HT_OPMODE
,
3827 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
3829 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3831 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
,
3832 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3834 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3835 dot11MeshHWMPconfirmationInterval
, mask
,
3836 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3843 #undef FILL_IN_MESH_PARAM_IF_SET
3846 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3847 struct mesh_setup
*setup
)
3849 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3851 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3853 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3854 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3855 nl80211_mesh_setup_params_policy
))
3858 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
3859 setup
->sync_method
=
3860 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
3861 IEEE80211_SYNC_METHOD_VENDOR
:
3862 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
3864 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3865 setup
->path_sel_proto
=
3866 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3867 IEEE80211_PATH_PROTOCOL_VENDOR
:
3868 IEEE80211_PATH_PROTOCOL_HWMP
;
3870 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3871 setup
->path_metric
=
3872 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3873 IEEE80211_PATH_METRIC_VENDOR
:
3874 IEEE80211_PATH_METRIC_AIRTIME
;
3877 if (tb
[NL80211_MESH_SETUP_IE
]) {
3878 struct nlattr
*ieattr
=
3879 tb
[NL80211_MESH_SETUP_IE
];
3880 if (!is_valid_ie_attr(ieattr
))
3882 setup
->ie
= nla_data(ieattr
);
3883 setup
->ie_len
= nla_len(ieattr
);
3885 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3886 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3891 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3892 struct genl_info
*info
)
3894 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3895 struct net_device
*dev
= info
->user_ptr
[1];
3896 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3897 struct mesh_config cfg
;
3901 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3904 if (!rdev
->ops
->update_mesh_config
)
3907 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3912 if (!wdev
->mesh_id_len
)
3916 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3924 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3926 struct sk_buff
*msg
;
3928 struct nlattr
*nl_reg_rules
;
3932 mutex_lock(&cfg80211_mutex
);
3934 if (!cfg80211_regdomain
)
3937 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3943 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3944 NL80211_CMD_GET_REG
);
3948 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
3949 cfg80211_regdomain
->alpha2
) ||
3950 (cfg80211_regdomain
->dfs_region
&&
3951 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
,
3952 cfg80211_regdomain
->dfs_region
)))
3953 goto nla_put_failure
;
3955 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3957 goto nla_put_failure
;
3959 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3960 struct nlattr
*nl_reg_rule
;
3961 const struct ieee80211_reg_rule
*reg_rule
;
3962 const struct ieee80211_freq_range
*freq_range
;
3963 const struct ieee80211_power_rule
*power_rule
;
3965 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3966 freq_range
= ®_rule
->freq_range
;
3967 power_rule
= ®_rule
->power_rule
;
3969 nl_reg_rule
= nla_nest_start(msg
, i
);
3971 goto nla_put_failure
;
3973 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3975 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3976 freq_range
->start_freq_khz
) ||
3977 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3978 freq_range
->end_freq_khz
) ||
3979 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3980 freq_range
->max_bandwidth_khz
) ||
3981 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3982 power_rule
->max_antenna_gain
) ||
3983 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3984 power_rule
->max_eirp
))
3985 goto nla_put_failure
;
3987 nla_nest_end(msg
, nl_reg_rule
);
3990 nla_nest_end(msg
, nl_reg_rules
);
3992 genlmsg_end(msg
, hdr
);
3993 err
= genlmsg_reply(msg
, info
);
3997 genlmsg_cancel(msg
, hdr
);
4002 mutex_unlock(&cfg80211_mutex
);
4006 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4008 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4009 struct nlattr
*nl_reg_rule
;
4010 char *alpha2
= NULL
;
4011 int rem_reg_rules
= 0, r
= 0;
4012 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4014 struct ieee80211_regdomain
*rd
= NULL
;
4016 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4019 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
4022 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4024 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
4025 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
4027 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4030 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
4034 mutex_lock(&cfg80211_mutex
);
4036 if (!reg_is_valid_request(alpha2
)) {
4041 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
4042 (num_rules
* sizeof(struct ieee80211_reg_rule
));
4044 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
4050 rd
->n_reg_rules
= num_rules
;
4051 rd
->alpha2
[0] = alpha2
[0];
4052 rd
->alpha2
[1] = alpha2
[1];
4055 * Disable DFS master mode if the DFS region was
4056 * not supported or known on this kernel.
4058 if (reg_supported_dfs_region(dfs_region
))
4059 rd
->dfs_region
= dfs_region
;
4061 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4063 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
4064 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
4066 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
4072 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
4078 BUG_ON(rule_idx
!= num_rules
);
4082 mutex_unlock(&cfg80211_mutex
);
4087 mutex_unlock(&cfg80211_mutex
);
4092 static int validate_scan_freqs(struct nlattr
*freqs
)
4094 struct nlattr
*attr1
, *attr2
;
4095 int n_channels
= 0, tmp1
, tmp2
;
4097 nla_for_each_nested(attr1
, freqs
, tmp1
) {
4100 * Some hardware has a limited channel list for
4101 * scanning, and it is pretty much nonsensical
4102 * to scan for a channel twice, so disallow that
4103 * and don't require drivers to check that the
4104 * channel list they get isn't longer than what
4105 * they can scan, as long as they can scan all
4106 * the channels they registered at once.
4108 nla_for_each_nested(attr2
, freqs
, tmp2
)
4109 if (attr1
!= attr2
&&
4110 nla_get_u32(attr1
) == nla_get_u32(attr2
))
4117 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
4119 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4120 struct net_device
*dev
= info
->user_ptr
[1];
4121 struct cfg80211_scan_request
*request
;
4122 struct nlattr
*attr
;
4123 struct wiphy
*wiphy
;
4124 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
4127 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4130 wiphy
= &rdev
->wiphy
;
4132 if (!rdev
->ops
->scan
)
4138 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4139 n_channels
= validate_scan_freqs(
4140 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4144 enum ieee80211_band band
;
4147 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4148 if (wiphy
->bands
[band
])
4149 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4152 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4153 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
4156 if (n_ssids
> wiphy
->max_scan_ssids
)
4159 if (info
->attrs
[NL80211_ATTR_IE
])
4160 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4164 if (ie_len
> wiphy
->max_scan_ie_len
)
4167 request
= kzalloc(sizeof(*request
)
4168 + sizeof(*request
->ssids
) * n_ssids
4169 + sizeof(*request
->channels
) * n_channels
4170 + ie_len
, GFP_KERNEL
);
4175 request
->ssids
= (void *)&request
->channels
[n_channels
];
4176 request
->n_ssids
= n_ssids
;
4179 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4181 request
->ie
= (void *)(request
->channels
+ n_channels
);
4185 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4186 /* user specified, bail out if channel not found */
4187 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
4188 struct ieee80211_channel
*chan
;
4190 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4197 /* ignore disabled channels */
4198 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4201 request
->channels
[i
] = chan
;
4205 enum ieee80211_band band
;
4208 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4210 if (!wiphy
->bands
[band
])
4212 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4213 struct ieee80211_channel
*chan
;
4215 chan
= &wiphy
->bands
[band
]->channels
[j
];
4217 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4220 request
->channels
[i
] = chan
;
4231 request
->n_channels
= i
;
4234 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4235 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
4236 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4240 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4241 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
4246 if (info
->attrs
[NL80211_ATTR_IE
]) {
4247 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4248 memcpy((void *)request
->ie
,
4249 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4253 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4254 if (wiphy
->bands
[i
])
4256 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
4258 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
4259 nla_for_each_nested(attr
,
4260 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
4262 enum ieee80211_band band
= nla_type(attr
);
4264 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4268 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
4271 &request
->rates
[band
]);
4278 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
4281 request
->wiphy
= &rdev
->wiphy
;
4283 rdev
->scan_req
= request
;
4284 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
4287 nl80211_send_scan_start(rdev
, dev
);
4291 rdev
->scan_req
= NULL
;
4298 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
4299 struct genl_info
*info
)
4301 struct cfg80211_sched_scan_request
*request
;
4302 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4303 struct net_device
*dev
= info
->user_ptr
[1];
4304 struct nlattr
*attr
;
4305 struct wiphy
*wiphy
;
4306 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
4308 enum ieee80211_band band
;
4310 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
4312 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4313 !rdev
->ops
->sched_scan_start
)
4316 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4319 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
4322 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
4326 wiphy
= &rdev
->wiphy
;
4328 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4329 n_channels
= validate_scan_freqs(
4330 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4336 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4337 if (wiphy
->bands
[band
])
4338 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4341 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4342 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4346 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
4349 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
4350 nla_for_each_nested(attr
,
4351 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4355 if (n_match_sets
> wiphy
->max_match_sets
)
4358 if (info
->attrs
[NL80211_ATTR_IE
])
4359 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4363 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
4366 mutex_lock(&rdev
->sched_scan_mtx
);
4368 if (rdev
->sched_scan_req
) {
4373 request
= kzalloc(sizeof(*request
)
4374 + sizeof(*request
->ssids
) * n_ssids
4375 + sizeof(*request
->match_sets
) * n_match_sets
4376 + sizeof(*request
->channels
) * n_channels
4377 + ie_len
, GFP_KERNEL
);
4384 request
->ssids
= (void *)&request
->channels
[n_channels
];
4385 request
->n_ssids
= n_ssids
;
4388 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4390 request
->ie
= (void *)(request
->channels
+ n_channels
);
4395 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
4396 else if (request
->ssids
)
4397 request
->match_sets
=
4398 (void *)(request
->ssids
+ n_ssids
);
4400 request
->match_sets
=
4401 (void *)(request
->channels
+ n_channels
);
4403 request
->n_match_sets
= n_match_sets
;
4406 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4407 /* user specified, bail out if channel not found */
4408 nla_for_each_nested(attr
,
4409 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
4411 struct ieee80211_channel
*chan
;
4413 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4420 /* ignore disabled channels */
4421 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4424 request
->channels
[i
] = chan
;
4429 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4431 if (!wiphy
->bands
[band
])
4433 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4434 struct ieee80211_channel
*chan
;
4436 chan
= &wiphy
->bands
[band
]->channels
[j
];
4438 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4441 request
->channels
[i
] = chan
;
4452 request
->n_channels
= i
;
4455 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4456 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4458 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4462 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4463 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
4470 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
4471 nla_for_each_nested(attr
,
4472 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4474 struct nlattr
*ssid
, *rssi
;
4476 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
4477 nla_data(attr
), nla_len(attr
),
4478 nl80211_match_policy
);
4479 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
4481 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
4485 memcpy(request
->match_sets
[i
].ssid
.ssid
,
4486 nla_data(ssid
), nla_len(ssid
));
4487 request
->match_sets
[i
].ssid
.ssid_len
=
4490 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
4492 request
->rssi_thold
= nla_get_u32(rssi
);
4494 request
->rssi_thold
=
4495 NL80211_SCAN_RSSI_THOLD_OFF
;
4500 if (info
->attrs
[NL80211_ATTR_IE
]) {
4501 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4502 memcpy((void *)request
->ie
,
4503 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4508 request
->wiphy
= &rdev
->wiphy
;
4509 request
->interval
= interval
;
4511 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
4513 rdev
->sched_scan_req
= request
;
4514 nl80211_send_sched_scan(rdev
, dev
,
4515 NL80211_CMD_START_SCHED_SCAN
);
4522 mutex_unlock(&rdev
->sched_scan_mtx
);
4526 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
4527 struct genl_info
*info
)
4529 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4532 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4533 !rdev
->ops
->sched_scan_stop
)
4536 mutex_lock(&rdev
->sched_scan_mtx
);
4537 err
= __cfg80211_stop_sched_scan(rdev
, false);
4538 mutex_unlock(&rdev
->sched_scan_mtx
);
4543 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
4545 struct cfg80211_registered_device
*rdev
,
4546 struct wireless_dev
*wdev
,
4547 struct cfg80211_internal_bss
*intbss
)
4549 struct cfg80211_bss
*res
= &intbss
->pub
;
4553 ASSERT_WDEV_LOCK(wdev
);
4555 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).pid
, seq
, flags
,
4556 NL80211_CMD_NEW_SCAN_RESULTS
);
4560 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
4562 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
) ||
4563 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
4564 goto nla_put_failure
;
4566 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
4568 goto nla_put_failure
;
4569 if ((!is_zero_ether_addr(res
->bssid
) &&
4570 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)) ||
4571 (res
->information_elements
&& res
->len_information_elements
&&
4572 nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
4573 res
->len_information_elements
,
4574 res
->information_elements
)) ||
4575 (res
->beacon_ies
&& res
->len_beacon_ies
&&
4576 res
->beacon_ies
!= res
->information_elements
&&
4577 nla_put(msg
, NL80211_BSS_BEACON_IES
,
4578 res
->len_beacon_ies
, res
->beacon_ies
)))
4579 goto nla_put_failure
;
4581 nla_put_u64(msg
, NL80211_BSS_TSF
, res
->tsf
))
4582 goto nla_put_failure
;
4583 if (res
->beacon_interval
&&
4584 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
4585 goto nla_put_failure
;
4586 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
4587 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
4588 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
4589 jiffies_to_msecs(jiffies
- intbss
->ts
)))
4590 goto nla_put_failure
;
4592 switch (rdev
->wiphy
.signal_type
) {
4593 case CFG80211_SIGNAL_TYPE_MBM
:
4594 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
4595 goto nla_put_failure
;
4597 case CFG80211_SIGNAL_TYPE_UNSPEC
:
4598 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
4599 goto nla_put_failure
;
4605 switch (wdev
->iftype
) {
4606 case NL80211_IFTYPE_P2P_CLIENT
:
4607 case NL80211_IFTYPE_STATION
:
4608 if (intbss
== wdev
->current_bss
&&
4609 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4610 NL80211_BSS_STATUS_ASSOCIATED
))
4611 goto nla_put_failure
;
4613 case NL80211_IFTYPE_ADHOC
:
4614 if (intbss
== wdev
->current_bss
&&
4615 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4616 NL80211_BSS_STATUS_IBSS_JOINED
))
4617 goto nla_put_failure
;
4623 nla_nest_end(msg
, bss
);
4625 return genlmsg_end(msg
, hdr
);
4628 genlmsg_cancel(msg
, hdr
);
4632 static int nl80211_dump_scan(struct sk_buff
*skb
,
4633 struct netlink_callback
*cb
)
4635 struct cfg80211_registered_device
*rdev
;
4636 struct net_device
*dev
;
4637 struct cfg80211_internal_bss
*scan
;
4638 struct wireless_dev
*wdev
;
4639 int start
= cb
->args
[1], idx
= 0;
4642 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4646 wdev
= dev
->ieee80211_ptr
;
4649 spin_lock_bh(&rdev
->bss_lock
);
4650 cfg80211_bss_expire(rdev
);
4652 cb
->seq
= rdev
->bss_generation
;
4654 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4657 if (nl80211_send_bss(skb
, cb
,
4658 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4659 rdev
, wdev
, scan
) < 0) {
4665 spin_unlock_bh(&rdev
->bss_lock
);
4669 nl80211_finish_netdev_dump(rdev
);
4674 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
4675 int flags
, struct net_device
*dev
,
4676 struct survey_info
*survey
)
4679 struct nlattr
*infoattr
;
4681 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
4682 NL80211_CMD_NEW_SURVEY_RESULTS
);
4686 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
4687 goto nla_put_failure
;
4689 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4691 goto nla_put_failure
;
4693 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4694 survey
->channel
->center_freq
))
4695 goto nla_put_failure
;
4697 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
4698 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
4699 goto nla_put_failure
;
4700 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
4701 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
4702 goto nla_put_failure
;
4703 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
4704 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4705 survey
->channel_time
))
4706 goto nla_put_failure
;
4707 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
4708 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4709 survey
->channel_time_busy
))
4710 goto nla_put_failure
;
4711 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
4712 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4713 survey
->channel_time_ext_busy
))
4714 goto nla_put_failure
;
4715 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
4716 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4717 survey
->channel_time_rx
))
4718 goto nla_put_failure
;
4719 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
4720 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4721 survey
->channel_time_tx
))
4722 goto nla_put_failure
;
4724 nla_nest_end(msg
, infoattr
);
4726 return genlmsg_end(msg
, hdr
);
4729 genlmsg_cancel(msg
, hdr
);
4733 static int nl80211_dump_survey(struct sk_buff
*skb
,
4734 struct netlink_callback
*cb
)
4736 struct survey_info survey
;
4737 struct cfg80211_registered_device
*dev
;
4738 struct net_device
*netdev
;
4739 int survey_idx
= cb
->args
[1];
4742 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4746 if (!dev
->ops
->dump_survey
) {
4752 struct ieee80211_channel
*chan
;
4754 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4761 /* Survey without a channel doesn't make sense */
4762 if (!survey
.channel
) {
4767 chan
= ieee80211_get_channel(&dev
->wiphy
,
4768 survey
.channel
->center_freq
);
4769 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4774 if (nl80211_send_survey(skb
,
4775 NETLINK_CB(cb
->skb
).pid
,
4776 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4784 cb
->args
[1] = survey_idx
;
4787 nl80211_finish_netdev_dump(dev
);
4791 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
4793 return auth_type
<= NL80211_AUTHTYPE_MAX
;
4796 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4798 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4799 NL80211_WPA_VERSION_2
));
4802 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4804 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4805 struct net_device
*dev
= info
->user_ptr
[1];
4806 struct ieee80211_channel
*chan
;
4807 const u8
*bssid
, *ssid
, *ie
= NULL
;
4808 int err
, ssid_len
, ie_len
= 0;
4809 enum nl80211_auth_type auth_type
;
4810 struct key_parse key
;
4811 bool local_state_change
;
4813 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4816 if (!info
->attrs
[NL80211_ATTR_MAC
])
4819 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4822 if (!info
->attrs
[NL80211_ATTR_SSID
])
4825 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4828 err
= nl80211_parse_key(info
, &key
);
4833 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4835 if (!key
.p
.key
|| !key
.p
.key_len
)
4837 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4838 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4839 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4840 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4852 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4853 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4862 if (!rdev
->ops
->auth
)
4865 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4866 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4869 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4870 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4871 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4872 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4875 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4876 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4878 if (info
->attrs
[NL80211_ATTR_IE
]) {
4879 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4880 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4883 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4884 if (!nl80211_valid_auth_type(auth_type
))
4887 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4890 * Since we no longer track auth state, ignore
4891 * requests to only change local state.
4893 if (local_state_change
)
4896 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4897 ssid
, ssid_len
, ie
, ie_len
,
4898 key
.p
.key
, key
.p
.key_len
, key
.idx
);
4901 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
4902 struct genl_info
*info
,
4903 struct cfg80211_crypto_settings
*settings
,
4906 memset(settings
, 0, sizeof(*settings
));
4908 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
4910 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
4912 proto
= nla_get_u16(
4913 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
4914 settings
->control_port_ethertype
= cpu_to_be16(proto
);
4915 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
4918 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4919 settings
->control_port_no_encrypt
= true;
4921 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4923 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4927 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4928 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4929 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4931 if (len
% sizeof(u32
))
4934 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4937 memcpy(settings
->ciphers_pairwise
, data
, len
);
4939 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4940 if (!cfg80211_supported_cipher_suite(
4942 settings
->ciphers_pairwise
[i
]))
4946 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4947 settings
->cipher_group
=
4948 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4949 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
4950 settings
->cipher_group
))
4954 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4955 settings
->wpa_versions
=
4956 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4957 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4961 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4965 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4966 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4967 settings
->n_akm_suites
= len
/ sizeof(u32
);
4969 if (len
% sizeof(u32
))
4972 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4975 memcpy(settings
->akm_suites
, data
, len
);
4981 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4983 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4984 struct net_device
*dev
= info
->user_ptr
[1];
4985 struct cfg80211_crypto_settings crypto
;
4986 struct ieee80211_channel
*chan
;
4987 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4988 int err
, ssid_len
, ie_len
= 0;
4989 bool use_mfp
= false;
4991 struct ieee80211_ht_cap
*ht_capa
= NULL
;
4992 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
4994 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4997 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4998 !info
->attrs
[NL80211_ATTR_SSID
] ||
4999 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5002 if (!rdev
->ops
->assoc
)
5005 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5006 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5009 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5011 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5012 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5013 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5016 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5017 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5019 if (info
->attrs
[NL80211_ATTR_IE
]) {
5020 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5021 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5024 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
5025 enum nl80211_mfp mfp
=
5026 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
5027 if (mfp
== NL80211_MFP_REQUIRED
)
5029 else if (mfp
!= NL80211_MFP_NO
)
5033 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
5034 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
5036 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5037 flags
|= ASSOC_REQ_DISABLE_HT
;
5039 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5041 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
5043 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5046 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5049 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
5051 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
5052 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
5053 &crypto
, flags
, ht_capa
,
5059 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5061 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5062 struct net_device
*dev
= info
->user_ptr
[1];
5063 const u8
*ie
= NULL
, *bssid
;
5066 bool local_state_change
;
5068 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5071 if (!info
->attrs
[NL80211_ATTR_MAC
])
5074 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5077 if (!rdev
->ops
->deauth
)
5080 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5081 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5084 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5086 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5087 if (reason_code
== 0) {
5088 /* Reason Code 0 is reserved */
5092 if (info
->attrs
[NL80211_ATTR_IE
]) {
5093 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5094 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5097 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5099 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5100 local_state_change
);
5103 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
5105 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5106 struct net_device
*dev
= info
->user_ptr
[1];
5107 const u8
*ie
= NULL
, *bssid
;
5110 bool local_state_change
;
5112 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5115 if (!info
->attrs
[NL80211_ATTR_MAC
])
5118 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5121 if (!rdev
->ops
->disassoc
)
5124 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5125 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5128 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5130 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5131 if (reason_code
== 0) {
5132 /* Reason Code 0 is reserved */
5136 if (info
->attrs
[NL80211_ATTR_IE
]) {
5137 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5138 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5141 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5143 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5144 local_state_change
);
5148 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
5149 int mcast_rate
[IEEE80211_NUM_BANDS
],
5152 struct wiphy
*wiphy
= &rdev
->wiphy
;
5156 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5157 struct ieee80211_supported_band
*sband
;
5159 sband
= wiphy
->bands
[band
];
5163 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
5164 if (sband
->bitrates
[i
].bitrate
== rateval
) {
5165 mcast_rate
[band
] = i
+ 1;
5175 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5177 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5178 struct net_device
*dev
= info
->user_ptr
[1];
5179 struct cfg80211_ibss_params ibss
;
5180 struct wiphy
*wiphy
;
5181 struct cfg80211_cached_keys
*connkeys
= NULL
;
5184 memset(&ibss
, 0, sizeof(ibss
));
5186 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5189 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5190 !info
->attrs
[NL80211_ATTR_SSID
] ||
5191 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5194 ibss
.beacon_interval
= 100;
5196 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
5197 ibss
.beacon_interval
=
5198 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5199 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
5203 if (!rdev
->ops
->join_ibss
)
5206 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5209 wiphy
= &rdev
->wiphy
;
5211 if (info
->attrs
[NL80211_ATTR_MAC
]) {
5212 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5214 if (!is_valid_ether_addr(ibss
.bssid
))
5217 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5218 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5220 if (info
->attrs
[NL80211_ATTR_IE
]) {
5221 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5222 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5225 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5226 enum nl80211_channel_type channel_type
;
5228 if (!nl80211_valid_channel_type(info
, &channel_type
))
5231 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5232 !(wiphy
->features
& NL80211_FEATURE_HT_IBSS
))
5235 ibss
.channel_type
= channel_type
;
5237 ibss
.channel_type
= NL80211_CHAN_NO_HT
;
5240 ibss
.channel
= rdev_freq_to_chan(rdev
,
5241 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
5243 if (!ibss
.channel
||
5244 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
5245 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5248 /* Both channels should be able to initiate communication */
5249 if ((ibss
.channel_type
== NL80211_CHAN_HT40PLUS
||
5250 ibss
.channel_type
== NL80211_CHAN_HT40MINUS
) &&
5251 !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, ibss
.channel
,
5255 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
5256 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5258 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5260 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5262 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5263 struct ieee80211_supported_band
*sband
=
5264 wiphy
->bands
[ibss
.channel
->band
];
5266 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
5272 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5273 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
5274 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5277 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5278 connkeys
= nl80211_parse_connkeys(rdev
,
5279 info
->attrs
[NL80211_ATTR_KEYS
]);
5280 if (IS_ERR(connkeys
))
5281 return PTR_ERR(connkeys
);
5285 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
5287 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
5293 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5295 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5296 struct net_device
*dev
= info
->user_ptr
[1];
5298 if (!rdev
->ops
->leave_ibss
)
5301 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5304 return cfg80211_leave_ibss(rdev
, dev
, false);
5307 #ifdef CONFIG_NL80211_TESTMODE
5308 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
5312 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
5314 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5317 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
5321 if (rdev
->ops
->testmode_cmd
) {
5322 rdev
->testmode_info
= info
;
5323 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
5324 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
5325 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
5326 rdev
->testmode_info
= NULL
;
5332 static int nl80211_testmode_dump(struct sk_buff
*skb
,
5333 struct netlink_callback
*cb
)
5335 struct cfg80211_registered_device
*rdev
;
5343 * 0 is a valid index, but not valid for args[0],
5344 * so we need to offset by 1.
5346 phy_idx
= cb
->args
[0] - 1;
5348 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
5349 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
5354 mutex_lock(&cfg80211_mutex
);
5355 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
5356 nl80211_fam
.attrbuf
);
5358 mutex_unlock(&cfg80211_mutex
);
5359 return PTR_ERR(rdev
);
5361 phy_idx
= rdev
->wiphy_idx
;
5363 mutex_unlock(&cfg80211_mutex
);
5365 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
5367 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
5371 data
= nla_data((void *)cb
->args
[1]);
5372 data_len
= nla_len((void *)cb
->args
[1]);
5375 mutex_lock(&cfg80211_mutex
);
5376 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
5378 mutex_unlock(&cfg80211_mutex
);
5381 cfg80211_lock_rdev(rdev
);
5382 mutex_unlock(&cfg80211_mutex
);
5384 if (!rdev
->ops
->testmode_dump
) {
5390 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).pid
,
5391 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5392 NL80211_CMD_TESTMODE
);
5393 struct nlattr
*tmdata
;
5395 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
5396 genlmsg_cancel(skb
, hdr
);
5400 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5402 genlmsg_cancel(skb
, hdr
);
5405 err
= rdev
->ops
->testmode_dump(&rdev
->wiphy
, skb
, cb
,
5407 nla_nest_end(skb
, tmdata
);
5409 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
5410 genlmsg_cancel(skb
, hdr
);
5413 genlmsg_cancel(skb
, hdr
);
5417 genlmsg_end(skb
, hdr
);
5422 cb
->args
[0] = phy_idx
+ 1;
5424 cfg80211_unlock_rdev(rdev
);
5428 static struct sk_buff
*
5429 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
5430 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
5432 struct sk_buff
*skb
;
5434 struct nlattr
*data
;
5436 skb
= nlmsg_new(approxlen
+ 100, gfp
);
5440 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
5446 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
5447 goto nla_put_failure
;
5448 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5450 ((void **)skb
->cb
)[0] = rdev
;
5451 ((void **)skb
->cb
)[1] = hdr
;
5452 ((void **)skb
->cb
)[2] = data
;
5461 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
5464 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5466 if (WARN_ON(!rdev
->testmode_info
))
5469 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
5470 rdev
->testmode_info
->snd_pid
,
5471 rdev
->testmode_info
->snd_seq
,
5474 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
5476 int cfg80211_testmode_reply(struct sk_buff
*skb
)
5478 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
5479 void *hdr
= ((void **)skb
->cb
)[1];
5480 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5482 if (WARN_ON(!rdev
->testmode_info
)) {
5487 nla_nest_end(skb
, data
);
5488 genlmsg_end(skb
, hdr
);
5489 return genlmsg_reply(skb
, rdev
->testmode_info
);
5491 EXPORT_SYMBOL(cfg80211_testmode_reply
);
5493 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
5494 int approxlen
, gfp_t gfp
)
5496 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5498 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
5500 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
5502 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
5504 void *hdr
= ((void **)skb
->cb
)[1];
5505 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5507 nla_nest_end(skb
, data
);
5508 genlmsg_end(skb
, hdr
);
5509 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
5511 EXPORT_SYMBOL(cfg80211_testmode_event
);
5514 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
5516 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5517 struct net_device
*dev
= info
->user_ptr
[1];
5518 struct cfg80211_connect_params connect
;
5519 struct wiphy
*wiphy
;
5520 struct cfg80211_cached_keys
*connkeys
= NULL
;
5523 memset(&connect
, 0, sizeof(connect
));
5525 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5528 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5529 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5532 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5534 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5535 if (!nl80211_valid_auth_type(connect
.auth_type
))
5538 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5540 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
5542 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
5543 NL80211_MAX_NR_CIPHER_SUITES
);
5547 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5548 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5551 wiphy
= &rdev
->wiphy
;
5553 connect
.bg_scan_period
= -1;
5554 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
5555 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
5556 connect
.bg_scan_period
=
5557 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
5560 if (info
->attrs
[NL80211_ATTR_MAC
])
5561 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5562 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5563 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5565 if (info
->attrs
[NL80211_ATTR_IE
]) {
5566 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5567 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5570 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5572 ieee80211_get_channel(wiphy
,
5573 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5574 if (!connect
.channel
||
5575 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5579 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5580 connkeys
= nl80211_parse_connkeys(rdev
,
5581 info
->attrs
[NL80211_ATTR_KEYS
]);
5582 if (IS_ERR(connkeys
))
5583 return PTR_ERR(connkeys
);
5586 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5587 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
5589 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5590 memcpy(&connect
.ht_capa_mask
,
5591 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
5592 sizeof(connect
.ht_capa_mask
));
5594 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5595 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5597 memcpy(&connect
.ht_capa
,
5598 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
5599 sizeof(connect
.ht_capa
));
5602 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
5608 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
5610 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5611 struct net_device
*dev
= info
->user_ptr
[1];
5614 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5615 reason
= WLAN_REASON_DEAUTH_LEAVING
;
5617 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5622 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5623 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5626 return cfg80211_disconnect(rdev
, dev
, reason
, true);
5629 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
5631 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5636 if (!info
->attrs
[NL80211_ATTR_PID
])
5639 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
5641 net
= get_net_ns_by_pid(pid
);
5643 return PTR_ERR(net
);
5647 /* check if anything to do */
5648 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
5649 err
= cfg80211_switch_netns(rdev
, net
);
5655 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5657 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5658 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
5659 struct cfg80211_pmksa
*pmksa
) = NULL
;
5660 struct net_device
*dev
= info
->user_ptr
[1];
5661 struct cfg80211_pmksa pmksa
;
5663 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
5665 if (!info
->attrs
[NL80211_ATTR_MAC
])
5668 if (!info
->attrs
[NL80211_ATTR_PMKID
])
5671 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
5672 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5674 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5675 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5678 switch (info
->genlhdr
->cmd
) {
5679 case NL80211_CMD_SET_PMKSA
:
5680 rdev_ops
= rdev
->ops
->set_pmksa
;
5682 case NL80211_CMD_DEL_PMKSA
:
5683 rdev_ops
= rdev
->ops
->del_pmksa
;
5693 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
5696 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5698 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5699 struct net_device
*dev
= info
->user_ptr
[1];
5701 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5702 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5705 if (!rdev
->ops
->flush_pmksa
)
5708 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
5711 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5713 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5714 struct net_device
*dev
= info
->user_ptr
[1];
5715 u8 action_code
, dialog_token
;
5719 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5720 !rdev
->ops
->tdls_mgmt
)
5723 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5724 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5725 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5726 !info
->attrs
[NL80211_ATTR_IE
] ||
5727 !info
->attrs
[NL80211_ATTR_MAC
])
5730 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5731 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5732 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5733 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5735 return rdev
->ops
->tdls_mgmt(&rdev
->wiphy
, dev
, peer
, action_code
,
5736 dialog_token
, status_code
,
5737 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5738 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5741 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5743 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5744 struct net_device
*dev
= info
->user_ptr
[1];
5745 enum nl80211_tdls_operation operation
;
5748 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5749 !rdev
->ops
->tdls_oper
)
5752 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5753 !info
->attrs
[NL80211_ATTR_MAC
])
5756 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5757 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5759 return rdev
->ops
->tdls_oper(&rdev
->wiphy
, dev
, peer
, operation
);
5762 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5763 struct genl_info
*info
)
5765 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5766 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5767 struct ieee80211_channel
*chan
;
5768 struct sk_buff
*msg
;
5771 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5775 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5776 !info
->attrs
[NL80211_ATTR_DURATION
])
5779 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5781 if (!rdev
->ops
->remain_on_channel
||
5782 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
5786 * We should be on that channel for at least a minimum amount of
5787 * time (10ms) but no longer than the driver supports.
5789 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
5790 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5793 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
5794 !nl80211_valid_channel_type(info
, &channel_type
))
5797 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5798 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5802 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5806 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5807 NL80211_CMD_REMAIN_ON_CHANNEL
);
5814 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, wdev
, chan
,
5815 channel_type
, duration
, &cookie
);
5820 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
5821 goto nla_put_failure
;
5823 genlmsg_end(msg
, hdr
);
5825 return genlmsg_reply(msg
, info
);
5834 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5835 struct genl_info
*info
)
5837 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5838 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5841 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5844 if (!rdev
->ops
->cancel_remain_on_channel
)
5847 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5849 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, wdev
, cookie
);
5852 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5853 u8
*rates
, u8 rates_len
)
5858 for (i
= 0; i
< rates_len
; i
++) {
5859 int rate
= (rates
[i
] & 0x7f) * 5;
5861 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5862 struct ieee80211_rate
*srate
=
5863 &sband
->bitrates
[ridx
];
5864 if (rate
== srate
->bitrate
) {
5869 if (ridx
== sband
->n_bitrates
)
5870 return 0; /* rate not found */
5876 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
5877 u8
*rates
, u8 rates_len
,
5878 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
5882 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
5884 for (i
= 0; i
< rates_len
; i
++) {
5887 ridx
= rates
[i
] / 8;
5888 rbit
= BIT(rates
[i
] % 8);
5890 /* check validity */
5891 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
5894 /* check availability */
5895 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
5904 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
5905 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
5906 .len
= NL80211_MAX_SUPP_RATES
},
5907 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
5908 .len
= NL80211_MAX_SUPP_HT_RATES
},
5911 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
5912 struct genl_info
*info
)
5914 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
5915 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5916 struct cfg80211_bitrate_mask mask
;
5918 struct net_device
*dev
= info
->user_ptr
[1];
5919 struct nlattr
*tx_rates
;
5920 struct ieee80211_supported_band
*sband
;
5922 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
5925 if (!rdev
->ops
->set_bitrate_mask
)
5928 memset(&mask
, 0, sizeof(mask
));
5929 /* Default to all rates enabled */
5930 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
5931 sband
= rdev
->wiphy
.bands
[i
];
5932 mask
.control
[i
].legacy
=
5933 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
5935 memcpy(mask
.control
[i
].mcs
,
5936 sband
->ht_cap
.mcs
.rx_mask
,
5937 sizeof(mask
.control
[i
].mcs
));
5939 memset(mask
.control
[i
].mcs
, 0,
5940 sizeof(mask
.control
[i
].mcs
));
5944 * The nested attribute uses enum nl80211_band as the index. This maps
5945 * directly to the enum ieee80211_band values used in cfg80211.
5947 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
5948 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
5950 enum ieee80211_band band
= nla_type(tx_rates
);
5951 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
5953 sband
= rdev
->wiphy
.bands
[band
];
5956 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
5957 nla_len(tx_rates
), nl80211_txattr_policy
);
5958 if (tb
[NL80211_TXRATE_LEGACY
]) {
5959 mask
.control
[band
].legacy
= rateset_to_mask(
5961 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
5962 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
5963 if ((mask
.control
[band
].legacy
== 0) &&
5964 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
5967 if (tb
[NL80211_TXRATE_MCS
]) {
5968 if (!ht_rateset_to_mask(
5970 nla_data(tb
[NL80211_TXRATE_MCS
]),
5971 nla_len(tb
[NL80211_TXRATE_MCS
]),
5972 mask
.control
[band
].mcs
))
5976 if (mask
.control
[band
].legacy
== 0) {
5977 /* don't allow empty legacy rates if HT
5978 * is not even supported. */
5979 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
5982 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
5983 if (mask
.control
[band
].mcs
[i
])
5986 /* legacy and mcs rates may not be both empty */
5987 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
5992 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
5995 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5997 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5998 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5999 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
6001 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
6004 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
6005 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
6007 switch (wdev
->iftype
) {
6008 case NL80211_IFTYPE_STATION
:
6009 case NL80211_IFTYPE_ADHOC
:
6010 case NL80211_IFTYPE_P2P_CLIENT
:
6011 case NL80211_IFTYPE_AP
:
6012 case NL80211_IFTYPE_AP_VLAN
:
6013 case NL80211_IFTYPE_MESH_POINT
:
6014 case NL80211_IFTYPE_P2P_GO
:
6020 /* not much point in registering if we can't reply */
6021 if (!rdev
->ops
->mgmt_tx
)
6024 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_pid
, frame_type
,
6025 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
6026 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
6029 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6031 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6032 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6033 struct ieee80211_channel
*chan
;
6034 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6035 bool channel_type_valid
= false;
6040 struct sk_buff
*msg
= NULL
;
6041 unsigned int wait
= 0;
6042 bool offchan
, no_cck
, dont_wait_for_ack
;
6044 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
6046 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
6047 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6050 if (!rdev
->ops
->mgmt_tx
)
6053 switch (wdev
->iftype
) {
6054 case NL80211_IFTYPE_STATION
:
6055 case NL80211_IFTYPE_ADHOC
:
6056 case NL80211_IFTYPE_P2P_CLIENT
:
6057 case NL80211_IFTYPE_AP
:
6058 case NL80211_IFTYPE_AP_VLAN
:
6059 case NL80211_IFTYPE_MESH_POINT
:
6060 case NL80211_IFTYPE_P2P_GO
:
6066 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
6067 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6069 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6072 * We should wait on the channel for at least a minimum amount
6073 * of time (10ms) but no longer than the driver supports.
6075 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6076 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
6081 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
6082 if (!nl80211_valid_channel_type(info
, &channel_type
))
6084 channel_type_valid
= true;
6087 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
6089 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6092 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6094 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6095 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
6099 if (!dont_wait_for_ack
) {
6100 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6104 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6113 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chan
, offchan
, channel_type
,
6114 channel_type_valid
, wait
,
6115 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
6116 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
6117 no_cck
, dont_wait_for_ack
, &cookie
);
6122 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6123 goto nla_put_failure
;
6125 genlmsg_end(msg
, hdr
);
6126 return genlmsg_reply(msg
, info
);
6138 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
6140 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6141 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6144 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6147 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
6150 switch (wdev
->iftype
) {
6151 case NL80211_IFTYPE_STATION
:
6152 case NL80211_IFTYPE_ADHOC
:
6153 case NL80211_IFTYPE_P2P_CLIENT
:
6154 case NL80211_IFTYPE_AP
:
6155 case NL80211_IFTYPE_AP_VLAN
:
6156 case NL80211_IFTYPE_P2P_GO
:
6162 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6164 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, wdev
, cookie
);
6167 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6169 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6170 struct wireless_dev
*wdev
;
6171 struct net_device
*dev
= info
->user_ptr
[1];
6176 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
6179 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
6181 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
6184 wdev
= dev
->ieee80211_ptr
;
6186 if (!rdev
->ops
->set_power_mgmt
)
6189 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
6191 if (state
== wdev
->ps
)
6194 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
6201 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6203 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6204 enum nl80211_ps_state ps_state
;
6205 struct wireless_dev
*wdev
;
6206 struct net_device
*dev
= info
->user_ptr
[1];
6207 struct sk_buff
*msg
;
6211 wdev
= dev
->ieee80211_ptr
;
6213 if (!rdev
->ops
->set_power_mgmt
)
6216 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6220 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6221 NL80211_CMD_GET_POWER_SAVE
);
6228 ps_state
= NL80211_PS_ENABLED
;
6230 ps_state
= NL80211_PS_DISABLED
;
6232 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
6233 goto nla_put_failure
;
6235 genlmsg_end(msg
, hdr
);
6236 return genlmsg_reply(msg
, info
);
6245 static struct nla_policy
6246 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
6247 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
6248 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
6249 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
6252 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
6253 s32 threshold
, u32 hysteresis
)
6255 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6256 struct wireless_dev
*wdev
;
6257 struct net_device
*dev
= info
->user_ptr
[1];
6262 wdev
= dev
->ieee80211_ptr
;
6264 if (!rdev
->ops
->set_cqm_rssi_config
)
6267 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6268 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6271 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
6272 threshold
, hysteresis
);
6275 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
6277 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
6281 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
6287 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
6288 nl80211_attr_cqm_policy
);
6292 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
6293 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
6296 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
6297 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
6298 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
6306 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6308 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6309 struct net_device
*dev
= info
->user_ptr
[1];
6310 struct mesh_config cfg
;
6311 struct mesh_setup setup
;
6314 /* start with default */
6315 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
6316 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
6318 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
6319 /* and parse parameters if given */
6320 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
6325 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
6326 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
6329 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6330 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6332 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6333 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
6334 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6337 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
6338 /* parse additional setup parameters if given */
6339 err
= nl80211_parse_mesh_setup(info
, &setup
);
6344 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6345 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6347 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
6348 !nl80211_valid_channel_type(info
, &channel_type
))
6351 setup
.channel
= rdev_freq_to_chan(rdev
,
6352 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
6356 setup
.channel_type
= channel_type
;
6358 /* cfg80211_join_mesh() will sort it out */
6359 setup
.channel
= NULL
;
6362 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
6365 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6367 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6368 struct net_device
*dev
= info
->user_ptr
[1];
6370 return cfg80211_leave_mesh(rdev
, dev
);
6374 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6376 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6377 struct sk_buff
*msg
;
6380 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6383 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6387 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6388 NL80211_CMD_GET_WOWLAN
);
6390 goto nla_put_failure
;
6393 struct nlattr
*nl_wowlan
;
6395 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
6397 goto nla_put_failure
;
6399 if ((rdev
->wowlan
->any
&&
6400 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
6401 (rdev
->wowlan
->disconnect
&&
6402 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
6403 (rdev
->wowlan
->magic_pkt
&&
6404 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
6405 (rdev
->wowlan
->gtk_rekey_failure
&&
6406 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
6407 (rdev
->wowlan
->eap_identity_req
&&
6408 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
6409 (rdev
->wowlan
->four_way_handshake
&&
6410 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
6411 (rdev
->wowlan
->rfkill_release
&&
6412 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
6413 goto nla_put_failure
;
6414 if (rdev
->wowlan
->n_patterns
) {
6415 struct nlattr
*nl_pats
, *nl_pat
;
6418 nl_pats
= nla_nest_start(msg
,
6419 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
6421 goto nla_put_failure
;
6423 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
6424 nl_pat
= nla_nest_start(msg
, i
+ 1);
6426 goto nla_put_failure
;
6427 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
6428 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
6429 DIV_ROUND_UP(pat_len
, 8),
6430 rdev
->wowlan
->patterns
[i
].mask
) ||
6431 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
6433 rdev
->wowlan
->patterns
[i
].pattern
))
6434 goto nla_put_failure
;
6435 nla_nest_end(msg
, nl_pat
);
6437 nla_nest_end(msg
, nl_pats
);
6440 nla_nest_end(msg
, nl_wowlan
);
6443 genlmsg_end(msg
, hdr
);
6444 return genlmsg_reply(msg
, info
);
6451 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6453 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6454 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
6455 struct cfg80211_wowlan no_triggers
= {};
6456 struct cfg80211_wowlan new_triggers
= {};
6457 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
6459 bool prev_enabled
= rdev
->wowlan
;
6461 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6464 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
6467 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
6468 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6469 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6470 nl80211_wowlan_policy
);
6474 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
6475 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
6477 new_triggers
.any
= true;
6480 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
6481 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
6483 new_triggers
.disconnect
= true;
6486 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
6487 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
6489 new_triggers
.magic_pkt
= true;
6492 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
6495 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
6496 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
6498 new_triggers
.gtk_rekey_failure
= true;
6501 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
6502 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
6504 new_triggers
.eap_identity_req
= true;
6507 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
6508 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
6510 new_triggers
.four_way_handshake
= true;
6513 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
6514 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
6516 new_triggers
.rfkill_release
= true;
6519 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
6522 int rem
, pat_len
, mask_len
;
6523 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
6525 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6528 if (n_patterns
> wowlan
->n_patterns
)
6531 new_triggers
.patterns
= kcalloc(n_patterns
,
6532 sizeof(new_triggers
.patterns
[0]),
6534 if (!new_triggers
.patterns
)
6537 new_triggers
.n_patterns
= n_patterns
;
6540 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6542 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
6543 nla_data(pat
), nla_len(pat
), NULL
);
6545 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
6546 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
6548 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
6549 mask_len
= DIV_ROUND_UP(pat_len
, 8);
6550 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
6553 if (pat_len
> wowlan
->pattern_max_len
||
6554 pat_len
< wowlan
->pattern_min_len
)
6557 new_triggers
.patterns
[i
].mask
=
6558 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
6559 if (!new_triggers
.patterns
[i
].mask
) {
6563 new_triggers
.patterns
[i
].pattern
=
6564 new_triggers
.patterns
[i
].mask
+ mask_len
;
6565 memcpy(new_triggers
.patterns
[i
].mask
,
6566 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
6568 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
6569 memcpy(new_triggers
.patterns
[i
].pattern
,
6570 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
6576 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
6577 struct cfg80211_wowlan
*ntrig
;
6578 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
6584 cfg80211_rdev_free_wowlan(rdev
);
6585 rdev
->wowlan
= ntrig
;
6588 cfg80211_rdev_free_wowlan(rdev
);
6589 rdev
->wowlan
= NULL
;
6592 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
6593 rdev
->ops
->set_wakeup(&rdev
->wiphy
, rdev
->wowlan
);
6597 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
6598 kfree(new_triggers
.patterns
[i
].mask
);
6599 kfree(new_triggers
.patterns
);
6604 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
6606 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6607 struct net_device
*dev
= info
->user_ptr
[1];
6608 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6609 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
6610 struct cfg80211_gtk_rekey_data rekey_data
;
6613 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
6616 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
6617 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6618 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6619 nl80211_rekey_policy
);
6623 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
6625 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
6627 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
6630 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
6632 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
6634 memcpy(rekey_data
.replay_ctr
,
6635 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
6636 NL80211_REPLAY_CTR_LEN
);
6639 if (!wdev
->current_bss
) {
6644 if (!rdev
->ops
->set_rekey_data
) {
6649 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
6655 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
6656 struct genl_info
*info
)
6658 struct net_device
*dev
= info
->user_ptr
[1];
6659 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6661 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6662 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6665 if (wdev
->ap_unexpected_nlpid
)
6668 wdev
->ap_unexpected_nlpid
= info
->snd_pid
;
6672 static int nl80211_probe_client(struct sk_buff
*skb
,
6673 struct genl_info
*info
)
6675 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6676 struct net_device
*dev
= info
->user_ptr
[1];
6677 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6678 struct sk_buff
*msg
;
6684 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6685 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6688 if (!info
->attrs
[NL80211_ATTR_MAC
])
6691 if (!rdev
->ops
->probe_client
)
6694 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6698 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6699 NL80211_CMD_PROBE_CLIENT
);
6706 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6708 err
= rdev
->ops
->probe_client(&rdev
->wiphy
, dev
, addr
, &cookie
);
6712 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6713 goto nla_put_failure
;
6715 genlmsg_end(msg
, hdr
);
6717 return genlmsg_reply(msg
, info
);
6726 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
6728 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6730 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
6733 if (rdev
->ap_beacons_nlpid
)
6736 rdev
->ap_beacons_nlpid
= info
->snd_pid
;
6741 #define NL80211_FLAG_NEED_WIPHY 0x01
6742 #define NL80211_FLAG_NEED_NETDEV 0x02
6743 #define NL80211_FLAG_NEED_RTNL 0x04
6744 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6745 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6746 NL80211_FLAG_CHECK_NETDEV_UP)
6747 #define NL80211_FLAG_NEED_WDEV 0x10
6748 /* If a netdev is associated, it must be UP */
6749 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6750 NL80211_FLAG_CHECK_NETDEV_UP)
6752 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6753 struct genl_info
*info
)
6755 struct cfg80211_registered_device
*rdev
;
6756 struct wireless_dev
*wdev
;
6757 struct net_device
*dev
;
6758 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
6763 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
6764 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6768 return PTR_ERR(rdev
);
6770 info
->user_ptr
[0] = rdev
;
6771 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
6772 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
6773 mutex_lock(&cfg80211_mutex
);
6774 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
6777 mutex_unlock(&cfg80211_mutex
);
6780 return PTR_ERR(wdev
);
6784 rdev
= wiphy_to_dev(wdev
->wiphy
);
6786 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
6788 mutex_unlock(&cfg80211_mutex
);
6794 info
->user_ptr
[1] = dev
;
6796 info
->user_ptr
[1] = wdev
;
6800 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
6801 !netif_running(dev
)) {
6802 mutex_unlock(&cfg80211_mutex
);
6811 cfg80211_lock_rdev(rdev
);
6813 mutex_unlock(&cfg80211_mutex
);
6815 info
->user_ptr
[0] = rdev
;
6821 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6822 struct genl_info
*info
)
6824 if (info
->user_ptr
[0])
6825 cfg80211_unlock_rdev(info
->user_ptr
[0]);
6826 if (info
->user_ptr
[1]) {
6827 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
6828 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6831 dev_put(wdev
->netdev
);
6833 dev_put(info
->user_ptr
[1]);
6836 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
6840 static struct genl_ops nl80211_ops
[] = {
6842 .cmd
= NL80211_CMD_GET_WIPHY
,
6843 .doit
= nl80211_get_wiphy
,
6844 .dumpit
= nl80211_dump_wiphy
,
6845 .policy
= nl80211_policy
,
6846 /* can be retrieved by unprivileged users */
6847 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
6850 .cmd
= NL80211_CMD_SET_WIPHY
,
6851 .doit
= nl80211_set_wiphy
,
6852 .policy
= nl80211_policy
,
6853 .flags
= GENL_ADMIN_PERM
,
6854 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
6857 .cmd
= NL80211_CMD_GET_INTERFACE
,
6858 .doit
= nl80211_get_interface
,
6859 .dumpit
= nl80211_dump_interface
,
6860 .policy
= nl80211_policy
,
6861 /* can be retrieved by unprivileged users */
6862 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
6865 .cmd
= NL80211_CMD_SET_INTERFACE
,
6866 .doit
= nl80211_set_interface
,
6867 .policy
= nl80211_policy
,
6868 .flags
= GENL_ADMIN_PERM
,
6869 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6870 NL80211_FLAG_NEED_RTNL
,
6873 .cmd
= NL80211_CMD_NEW_INTERFACE
,
6874 .doit
= nl80211_new_interface
,
6875 .policy
= nl80211_policy
,
6876 .flags
= GENL_ADMIN_PERM
,
6877 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6878 NL80211_FLAG_NEED_RTNL
,
6881 .cmd
= NL80211_CMD_DEL_INTERFACE
,
6882 .doit
= nl80211_del_interface
,
6883 .policy
= nl80211_policy
,
6884 .flags
= GENL_ADMIN_PERM
,
6885 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
6886 NL80211_FLAG_NEED_RTNL
,
6889 .cmd
= NL80211_CMD_GET_KEY
,
6890 .doit
= nl80211_get_key
,
6891 .policy
= nl80211_policy
,
6892 .flags
= GENL_ADMIN_PERM
,
6893 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6894 NL80211_FLAG_NEED_RTNL
,
6897 .cmd
= NL80211_CMD_SET_KEY
,
6898 .doit
= nl80211_set_key
,
6899 .policy
= nl80211_policy
,
6900 .flags
= GENL_ADMIN_PERM
,
6901 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6902 NL80211_FLAG_NEED_RTNL
,
6905 .cmd
= NL80211_CMD_NEW_KEY
,
6906 .doit
= nl80211_new_key
,
6907 .policy
= nl80211_policy
,
6908 .flags
= GENL_ADMIN_PERM
,
6909 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6910 NL80211_FLAG_NEED_RTNL
,
6913 .cmd
= NL80211_CMD_DEL_KEY
,
6914 .doit
= nl80211_del_key
,
6915 .policy
= nl80211_policy
,
6916 .flags
= GENL_ADMIN_PERM
,
6917 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6918 NL80211_FLAG_NEED_RTNL
,
6921 .cmd
= NL80211_CMD_SET_BEACON
,
6922 .policy
= nl80211_policy
,
6923 .flags
= GENL_ADMIN_PERM
,
6924 .doit
= nl80211_set_beacon
,
6925 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6926 NL80211_FLAG_NEED_RTNL
,
6929 .cmd
= NL80211_CMD_START_AP
,
6930 .policy
= nl80211_policy
,
6931 .flags
= GENL_ADMIN_PERM
,
6932 .doit
= nl80211_start_ap
,
6933 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6934 NL80211_FLAG_NEED_RTNL
,
6937 .cmd
= NL80211_CMD_STOP_AP
,
6938 .policy
= nl80211_policy
,
6939 .flags
= GENL_ADMIN_PERM
,
6940 .doit
= nl80211_stop_ap
,
6941 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6942 NL80211_FLAG_NEED_RTNL
,
6945 .cmd
= NL80211_CMD_GET_STATION
,
6946 .doit
= nl80211_get_station
,
6947 .dumpit
= nl80211_dump_station
,
6948 .policy
= nl80211_policy
,
6949 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6950 NL80211_FLAG_NEED_RTNL
,
6953 .cmd
= NL80211_CMD_SET_STATION
,
6954 .doit
= nl80211_set_station
,
6955 .policy
= nl80211_policy
,
6956 .flags
= GENL_ADMIN_PERM
,
6957 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6958 NL80211_FLAG_NEED_RTNL
,
6961 .cmd
= NL80211_CMD_NEW_STATION
,
6962 .doit
= nl80211_new_station
,
6963 .policy
= nl80211_policy
,
6964 .flags
= GENL_ADMIN_PERM
,
6965 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6966 NL80211_FLAG_NEED_RTNL
,
6969 .cmd
= NL80211_CMD_DEL_STATION
,
6970 .doit
= nl80211_del_station
,
6971 .policy
= nl80211_policy
,
6972 .flags
= GENL_ADMIN_PERM
,
6973 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6974 NL80211_FLAG_NEED_RTNL
,
6977 .cmd
= NL80211_CMD_GET_MPATH
,
6978 .doit
= nl80211_get_mpath
,
6979 .dumpit
= nl80211_dump_mpath
,
6980 .policy
= nl80211_policy
,
6981 .flags
= GENL_ADMIN_PERM
,
6982 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6983 NL80211_FLAG_NEED_RTNL
,
6986 .cmd
= NL80211_CMD_SET_MPATH
,
6987 .doit
= nl80211_set_mpath
,
6988 .policy
= nl80211_policy
,
6989 .flags
= GENL_ADMIN_PERM
,
6990 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6991 NL80211_FLAG_NEED_RTNL
,
6994 .cmd
= NL80211_CMD_NEW_MPATH
,
6995 .doit
= nl80211_new_mpath
,
6996 .policy
= nl80211_policy
,
6997 .flags
= GENL_ADMIN_PERM
,
6998 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6999 NL80211_FLAG_NEED_RTNL
,
7002 .cmd
= NL80211_CMD_DEL_MPATH
,
7003 .doit
= nl80211_del_mpath
,
7004 .policy
= nl80211_policy
,
7005 .flags
= GENL_ADMIN_PERM
,
7006 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7007 NL80211_FLAG_NEED_RTNL
,
7010 .cmd
= NL80211_CMD_SET_BSS
,
7011 .doit
= nl80211_set_bss
,
7012 .policy
= nl80211_policy
,
7013 .flags
= GENL_ADMIN_PERM
,
7014 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7015 NL80211_FLAG_NEED_RTNL
,
7018 .cmd
= NL80211_CMD_GET_REG
,
7019 .doit
= nl80211_get_reg
,
7020 .policy
= nl80211_policy
,
7021 /* can be retrieved by unprivileged users */
7024 .cmd
= NL80211_CMD_SET_REG
,
7025 .doit
= nl80211_set_reg
,
7026 .policy
= nl80211_policy
,
7027 .flags
= GENL_ADMIN_PERM
,
7030 .cmd
= NL80211_CMD_REQ_SET_REG
,
7031 .doit
= nl80211_req_set_reg
,
7032 .policy
= nl80211_policy
,
7033 .flags
= GENL_ADMIN_PERM
,
7036 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
7037 .doit
= nl80211_get_mesh_config
,
7038 .policy
= nl80211_policy
,
7039 /* can be retrieved by unprivileged users */
7040 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7041 NL80211_FLAG_NEED_RTNL
,
7044 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
7045 .doit
= nl80211_update_mesh_config
,
7046 .policy
= nl80211_policy
,
7047 .flags
= GENL_ADMIN_PERM
,
7048 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7049 NL80211_FLAG_NEED_RTNL
,
7052 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
7053 .doit
= nl80211_trigger_scan
,
7054 .policy
= nl80211_policy
,
7055 .flags
= GENL_ADMIN_PERM
,
7056 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7057 NL80211_FLAG_NEED_RTNL
,
7060 .cmd
= NL80211_CMD_GET_SCAN
,
7061 .policy
= nl80211_policy
,
7062 .dumpit
= nl80211_dump_scan
,
7065 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
7066 .doit
= nl80211_start_sched_scan
,
7067 .policy
= nl80211_policy
,
7068 .flags
= GENL_ADMIN_PERM
,
7069 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7070 NL80211_FLAG_NEED_RTNL
,
7073 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
7074 .doit
= nl80211_stop_sched_scan
,
7075 .policy
= nl80211_policy
,
7076 .flags
= GENL_ADMIN_PERM
,
7077 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7078 NL80211_FLAG_NEED_RTNL
,
7081 .cmd
= NL80211_CMD_AUTHENTICATE
,
7082 .doit
= nl80211_authenticate
,
7083 .policy
= nl80211_policy
,
7084 .flags
= GENL_ADMIN_PERM
,
7085 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7086 NL80211_FLAG_NEED_RTNL
,
7089 .cmd
= NL80211_CMD_ASSOCIATE
,
7090 .doit
= nl80211_associate
,
7091 .policy
= nl80211_policy
,
7092 .flags
= GENL_ADMIN_PERM
,
7093 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7094 NL80211_FLAG_NEED_RTNL
,
7097 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
7098 .doit
= nl80211_deauthenticate
,
7099 .policy
= nl80211_policy
,
7100 .flags
= GENL_ADMIN_PERM
,
7101 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7102 NL80211_FLAG_NEED_RTNL
,
7105 .cmd
= NL80211_CMD_DISASSOCIATE
,
7106 .doit
= nl80211_disassociate
,
7107 .policy
= nl80211_policy
,
7108 .flags
= GENL_ADMIN_PERM
,
7109 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7110 NL80211_FLAG_NEED_RTNL
,
7113 .cmd
= NL80211_CMD_JOIN_IBSS
,
7114 .doit
= nl80211_join_ibss
,
7115 .policy
= nl80211_policy
,
7116 .flags
= GENL_ADMIN_PERM
,
7117 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7118 NL80211_FLAG_NEED_RTNL
,
7121 .cmd
= NL80211_CMD_LEAVE_IBSS
,
7122 .doit
= nl80211_leave_ibss
,
7123 .policy
= nl80211_policy
,
7124 .flags
= GENL_ADMIN_PERM
,
7125 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7126 NL80211_FLAG_NEED_RTNL
,
7128 #ifdef CONFIG_NL80211_TESTMODE
7130 .cmd
= NL80211_CMD_TESTMODE
,
7131 .doit
= nl80211_testmode_do
,
7132 .dumpit
= nl80211_testmode_dump
,
7133 .policy
= nl80211_policy
,
7134 .flags
= GENL_ADMIN_PERM
,
7135 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7136 NL80211_FLAG_NEED_RTNL
,
7140 .cmd
= NL80211_CMD_CONNECT
,
7141 .doit
= nl80211_connect
,
7142 .policy
= nl80211_policy
,
7143 .flags
= GENL_ADMIN_PERM
,
7144 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7145 NL80211_FLAG_NEED_RTNL
,
7148 .cmd
= NL80211_CMD_DISCONNECT
,
7149 .doit
= nl80211_disconnect
,
7150 .policy
= nl80211_policy
,
7151 .flags
= GENL_ADMIN_PERM
,
7152 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7153 NL80211_FLAG_NEED_RTNL
,
7156 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
7157 .doit
= nl80211_wiphy_netns
,
7158 .policy
= nl80211_policy
,
7159 .flags
= GENL_ADMIN_PERM
,
7160 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7161 NL80211_FLAG_NEED_RTNL
,
7164 .cmd
= NL80211_CMD_GET_SURVEY
,
7165 .policy
= nl80211_policy
,
7166 .dumpit
= nl80211_dump_survey
,
7169 .cmd
= NL80211_CMD_SET_PMKSA
,
7170 .doit
= nl80211_setdel_pmksa
,
7171 .policy
= nl80211_policy
,
7172 .flags
= GENL_ADMIN_PERM
,
7173 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7174 NL80211_FLAG_NEED_RTNL
,
7177 .cmd
= NL80211_CMD_DEL_PMKSA
,
7178 .doit
= nl80211_setdel_pmksa
,
7179 .policy
= nl80211_policy
,
7180 .flags
= GENL_ADMIN_PERM
,
7181 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7182 NL80211_FLAG_NEED_RTNL
,
7185 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
7186 .doit
= nl80211_flush_pmksa
,
7187 .policy
= nl80211_policy
,
7188 .flags
= GENL_ADMIN_PERM
,
7189 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7190 NL80211_FLAG_NEED_RTNL
,
7193 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
7194 .doit
= nl80211_remain_on_channel
,
7195 .policy
= nl80211_policy
,
7196 .flags
= GENL_ADMIN_PERM
,
7197 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7198 NL80211_FLAG_NEED_RTNL
,
7201 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7202 .doit
= nl80211_cancel_remain_on_channel
,
7203 .policy
= nl80211_policy
,
7204 .flags
= GENL_ADMIN_PERM
,
7205 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7206 NL80211_FLAG_NEED_RTNL
,
7209 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
7210 .doit
= nl80211_set_tx_bitrate_mask
,
7211 .policy
= nl80211_policy
,
7212 .flags
= GENL_ADMIN_PERM
,
7213 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7214 NL80211_FLAG_NEED_RTNL
,
7217 .cmd
= NL80211_CMD_REGISTER_FRAME
,
7218 .doit
= nl80211_register_mgmt
,
7219 .policy
= nl80211_policy
,
7220 .flags
= GENL_ADMIN_PERM
,
7221 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7222 NL80211_FLAG_NEED_RTNL
,
7225 .cmd
= NL80211_CMD_FRAME
,
7226 .doit
= nl80211_tx_mgmt
,
7227 .policy
= nl80211_policy
,
7228 .flags
= GENL_ADMIN_PERM
,
7229 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7230 NL80211_FLAG_NEED_RTNL
,
7233 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
7234 .doit
= nl80211_tx_mgmt_cancel_wait
,
7235 .policy
= nl80211_policy
,
7236 .flags
= GENL_ADMIN_PERM
,
7237 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7238 NL80211_FLAG_NEED_RTNL
,
7241 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
7242 .doit
= nl80211_set_power_save
,
7243 .policy
= nl80211_policy
,
7244 .flags
= GENL_ADMIN_PERM
,
7245 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7246 NL80211_FLAG_NEED_RTNL
,
7249 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
7250 .doit
= nl80211_get_power_save
,
7251 .policy
= nl80211_policy
,
7252 /* can be retrieved by unprivileged users */
7253 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7254 NL80211_FLAG_NEED_RTNL
,
7257 .cmd
= NL80211_CMD_SET_CQM
,
7258 .doit
= nl80211_set_cqm
,
7259 .policy
= nl80211_policy
,
7260 .flags
= GENL_ADMIN_PERM
,
7261 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7262 NL80211_FLAG_NEED_RTNL
,
7265 .cmd
= NL80211_CMD_SET_CHANNEL
,
7266 .doit
= nl80211_set_channel
,
7267 .policy
= nl80211_policy
,
7268 .flags
= GENL_ADMIN_PERM
,
7269 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7270 NL80211_FLAG_NEED_RTNL
,
7273 .cmd
= NL80211_CMD_SET_WDS_PEER
,
7274 .doit
= nl80211_set_wds_peer
,
7275 .policy
= nl80211_policy
,
7276 .flags
= GENL_ADMIN_PERM
,
7277 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7278 NL80211_FLAG_NEED_RTNL
,
7281 .cmd
= NL80211_CMD_JOIN_MESH
,
7282 .doit
= nl80211_join_mesh
,
7283 .policy
= nl80211_policy
,
7284 .flags
= GENL_ADMIN_PERM
,
7285 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7286 NL80211_FLAG_NEED_RTNL
,
7289 .cmd
= NL80211_CMD_LEAVE_MESH
,
7290 .doit
= nl80211_leave_mesh
,
7291 .policy
= nl80211_policy
,
7292 .flags
= GENL_ADMIN_PERM
,
7293 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7294 NL80211_FLAG_NEED_RTNL
,
7298 .cmd
= NL80211_CMD_GET_WOWLAN
,
7299 .doit
= nl80211_get_wowlan
,
7300 .policy
= nl80211_policy
,
7301 /* can be retrieved by unprivileged users */
7302 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7303 NL80211_FLAG_NEED_RTNL
,
7306 .cmd
= NL80211_CMD_SET_WOWLAN
,
7307 .doit
= nl80211_set_wowlan
,
7308 .policy
= nl80211_policy
,
7309 .flags
= GENL_ADMIN_PERM
,
7310 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7311 NL80211_FLAG_NEED_RTNL
,
7315 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
7316 .doit
= nl80211_set_rekey_data
,
7317 .policy
= nl80211_policy
,
7318 .flags
= GENL_ADMIN_PERM
,
7319 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7320 NL80211_FLAG_NEED_RTNL
,
7323 .cmd
= NL80211_CMD_TDLS_MGMT
,
7324 .doit
= nl80211_tdls_mgmt
,
7325 .policy
= nl80211_policy
,
7326 .flags
= GENL_ADMIN_PERM
,
7327 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7328 NL80211_FLAG_NEED_RTNL
,
7331 .cmd
= NL80211_CMD_TDLS_OPER
,
7332 .doit
= nl80211_tdls_oper
,
7333 .policy
= nl80211_policy
,
7334 .flags
= GENL_ADMIN_PERM
,
7335 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7336 NL80211_FLAG_NEED_RTNL
,
7339 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
7340 .doit
= nl80211_register_unexpected_frame
,
7341 .policy
= nl80211_policy
,
7342 .flags
= GENL_ADMIN_PERM
,
7343 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7344 NL80211_FLAG_NEED_RTNL
,
7347 .cmd
= NL80211_CMD_PROBE_CLIENT
,
7348 .doit
= nl80211_probe_client
,
7349 .policy
= nl80211_policy
,
7350 .flags
= GENL_ADMIN_PERM
,
7351 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7352 NL80211_FLAG_NEED_RTNL
,
7355 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
7356 .doit
= nl80211_register_beacons
,
7357 .policy
= nl80211_policy
,
7358 .flags
= GENL_ADMIN_PERM
,
7359 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7360 NL80211_FLAG_NEED_RTNL
,
7363 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
7364 .doit
= nl80211_set_noack_map
,
7365 .policy
= nl80211_policy
,
7366 .flags
= GENL_ADMIN_PERM
,
7367 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7368 NL80211_FLAG_NEED_RTNL
,
7373 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
7377 /* multicast groups */
7378 static struct genl_multicast_group nl80211_config_mcgrp
= {
7381 static struct genl_multicast_group nl80211_scan_mcgrp
= {
7384 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
7385 .name
= "regulatory",
7388 /* notification functions */
7390 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
7392 struct sk_buff
*msg
;
7394 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7398 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
7403 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7404 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
7407 static int nl80211_add_scan_req(struct sk_buff
*msg
,
7408 struct cfg80211_registered_device
*rdev
)
7410 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
7411 struct nlattr
*nest
;
7414 ASSERT_RDEV_LOCK(rdev
);
7419 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
7421 goto nla_put_failure
;
7422 for (i
= 0; i
< req
->n_ssids
; i
++) {
7423 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
7424 goto nla_put_failure
;
7426 nla_nest_end(msg
, nest
);
7428 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
7430 goto nla_put_failure
;
7431 for (i
= 0; i
< req
->n_channels
; i
++) {
7432 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
7433 goto nla_put_failure
;
7435 nla_nest_end(msg
, nest
);
7438 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
7439 goto nla_put_failure
;
7446 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
7447 struct cfg80211_registered_device
*rdev
,
7448 struct net_device
*netdev
,
7449 u32 pid
, u32 seq
, int flags
,
7454 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
7458 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7459 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7460 goto nla_put_failure
;
7462 /* ignore errors and send incomplete event anyway */
7463 nl80211_add_scan_req(msg
, rdev
);
7465 return genlmsg_end(msg
, hdr
);
7468 genlmsg_cancel(msg
, hdr
);
7473 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
7474 struct cfg80211_registered_device
*rdev
,
7475 struct net_device
*netdev
,
7476 u32 pid
, u32 seq
, int flags
, u32 cmd
)
7480 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
7484 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7485 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7486 goto nla_put_failure
;
7488 return genlmsg_end(msg
, hdr
);
7491 genlmsg_cancel(msg
, hdr
);
7495 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
7496 struct net_device
*netdev
)
7498 struct sk_buff
*msg
;
7500 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7504 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7505 NL80211_CMD_TRIGGER_SCAN
) < 0) {
7510 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7511 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7514 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
7515 struct net_device
*netdev
)
7517 struct sk_buff
*msg
;
7519 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7523 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7524 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
7529 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7530 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7533 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
7534 struct net_device
*netdev
)
7536 struct sk_buff
*msg
;
7538 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7542 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7543 NL80211_CMD_SCAN_ABORTED
) < 0) {
7548 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7549 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7552 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
7553 struct net_device
*netdev
)
7555 struct sk_buff
*msg
;
7557 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7561 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7562 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
7567 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7568 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7571 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
7572 struct net_device
*netdev
, u32 cmd
)
7574 struct sk_buff
*msg
;
7576 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7580 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
7585 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7586 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7590 * This can happen on global regulatory changes or device specific settings
7591 * based on custom world regulatory domains.
7593 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
7595 struct sk_buff
*msg
;
7598 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7602 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
7608 /* Userspace can always count this one always being set */
7609 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
7610 goto nla_put_failure
;
7612 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
7613 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7614 NL80211_REGDOM_TYPE_WORLD
))
7615 goto nla_put_failure
;
7616 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
7617 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7618 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
7619 goto nla_put_failure
;
7620 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
7621 request
->intersect
) {
7622 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7623 NL80211_REGDOM_TYPE_INTERSECTION
))
7624 goto nla_put_failure
;
7626 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7627 NL80211_REGDOM_TYPE_COUNTRY
) ||
7628 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
7630 goto nla_put_failure
;
7633 if (wiphy_idx_valid(request
->wiphy_idx
) &&
7634 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
7635 goto nla_put_failure
;
7637 genlmsg_end(msg
, hdr
);
7640 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7647 genlmsg_cancel(msg
, hdr
);
7651 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
7652 struct net_device
*netdev
,
7653 const u8
*buf
, size_t len
,
7654 enum nl80211_commands cmd
, gfp_t gfp
)
7656 struct sk_buff
*msg
;
7659 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7663 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7669 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7670 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7671 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
7672 goto nla_put_failure
;
7674 genlmsg_end(msg
, hdr
);
7676 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7677 nl80211_mlme_mcgrp
.id
, gfp
);
7681 genlmsg_cancel(msg
, hdr
);
7685 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
7686 struct net_device
*netdev
, const u8
*buf
,
7687 size_t len
, gfp_t gfp
)
7689 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7690 NL80211_CMD_AUTHENTICATE
, gfp
);
7693 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
7694 struct net_device
*netdev
, const u8
*buf
,
7695 size_t len
, gfp_t gfp
)
7697 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7698 NL80211_CMD_ASSOCIATE
, gfp
);
7701 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
7702 struct net_device
*netdev
, const u8
*buf
,
7703 size_t len
, gfp_t gfp
)
7705 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7706 NL80211_CMD_DEAUTHENTICATE
, gfp
);
7709 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
7710 struct net_device
*netdev
, const u8
*buf
,
7711 size_t len
, gfp_t gfp
)
7713 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7714 NL80211_CMD_DISASSOCIATE
, gfp
);
7717 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
7718 struct net_device
*netdev
, const u8
*buf
,
7719 size_t len
, gfp_t gfp
)
7721 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7722 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
7725 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
7726 struct net_device
*netdev
, const u8
*buf
,
7727 size_t len
, gfp_t gfp
)
7729 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7730 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
7733 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
7734 struct net_device
*netdev
, int cmd
,
7735 const u8
*addr
, gfp_t gfp
)
7737 struct sk_buff
*msg
;
7740 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7744 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7750 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7751 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7752 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
7753 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
7754 goto nla_put_failure
;
7756 genlmsg_end(msg
, hdr
);
7758 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7759 nl80211_mlme_mcgrp
.id
, gfp
);
7763 genlmsg_cancel(msg
, hdr
);
7767 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
7768 struct net_device
*netdev
, const u8
*addr
,
7771 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
7775 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
7776 struct net_device
*netdev
, const u8
*addr
,
7779 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
7783 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
7784 struct net_device
*netdev
, const u8
*bssid
,
7785 const u8
*req_ie
, size_t req_ie_len
,
7786 const u8
*resp_ie
, size_t resp_ie_len
,
7787 u16 status
, gfp_t gfp
)
7789 struct sk_buff
*msg
;
7792 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7796 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
7802 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7803 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7804 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
7805 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
7807 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
7809 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
7810 goto nla_put_failure
;
7812 genlmsg_end(msg
, hdr
);
7814 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7815 nl80211_mlme_mcgrp
.id
, gfp
);
7819 genlmsg_cancel(msg
, hdr
);
7824 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
7825 struct net_device
*netdev
, const u8
*bssid
,
7826 const u8
*req_ie
, size_t req_ie_len
,
7827 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
7829 struct sk_buff
*msg
;
7832 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7836 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
7842 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7843 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7844 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
7846 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
7848 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
7849 goto nla_put_failure
;
7851 genlmsg_end(msg
, hdr
);
7853 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7854 nl80211_mlme_mcgrp
.id
, gfp
);
7858 genlmsg_cancel(msg
, hdr
);
7863 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
7864 struct net_device
*netdev
, u16 reason
,
7865 const u8
*ie
, size_t ie_len
, bool from_ap
)
7867 struct sk_buff
*msg
;
7870 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7874 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
7880 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7881 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7882 (from_ap
&& reason
&&
7883 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
7885 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
7886 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
7887 goto nla_put_failure
;
7889 genlmsg_end(msg
, hdr
);
7891 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7892 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
7896 genlmsg_cancel(msg
, hdr
);
7901 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
7902 struct net_device
*netdev
, const u8
*bssid
,
7905 struct sk_buff
*msg
;
7908 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7912 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
7918 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7919 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7920 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
7921 goto nla_put_failure
;
7923 genlmsg_end(msg
, hdr
);
7925 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7926 nl80211_mlme_mcgrp
.id
, gfp
);
7930 genlmsg_cancel(msg
, hdr
);
7934 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
7935 struct net_device
*netdev
,
7936 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
7939 struct sk_buff
*msg
;
7942 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7946 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
7952 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7953 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7954 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
) ||
7956 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
7957 goto nla_put_failure
;
7959 genlmsg_end(msg
, hdr
);
7961 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7962 nl80211_mlme_mcgrp
.id
, gfp
);
7966 genlmsg_cancel(msg
, hdr
);
7970 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
7971 struct net_device
*netdev
, const u8
*addr
,
7972 enum nl80211_key_type key_type
, int key_id
,
7973 const u8
*tsc
, gfp_t gfp
)
7975 struct sk_buff
*msg
;
7978 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7982 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
7988 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7989 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7990 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
7991 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
7993 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
7994 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
7995 goto nla_put_failure
;
7997 genlmsg_end(msg
, hdr
);
7999 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8000 nl80211_mlme_mcgrp
.id
, gfp
);
8004 genlmsg_cancel(msg
, hdr
);
8008 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
8009 struct ieee80211_channel
*channel_before
,
8010 struct ieee80211_channel
*channel_after
)
8012 struct sk_buff
*msg
;
8014 struct nlattr
*nl_freq
;
8016 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
8020 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
8027 * Since we are applying the beacon hint to a wiphy we know its
8028 * wiphy_idx is valid
8030 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
8031 goto nla_put_failure
;
8034 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
8036 goto nla_put_failure
;
8037 if (nl80211_msg_put_channel(msg
, channel_before
))
8038 goto nla_put_failure
;
8039 nla_nest_end(msg
, nl_freq
);
8042 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
8044 goto nla_put_failure
;
8045 if (nl80211_msg_put_channel(msg
, channel_after
))
8046 goto nla_put_failure
;
8047 nla_nest_end(msg
, nl_freq
);
8049 genlmsg_end(msg
, hdr
);
8052 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
8059 genlmsg_cancel(msg
, hdr
);
8063 static void nl80211_send_remain_on_chan_event(
8064 int cmd
, struct cfg80211_registered_device
*rdev
,
8065 struct wireless_dev
*wdev
, u64 cookie
,
8066 struct ieee80211_channel
*chan
,
8067 enum nl80211_channel_type channel_type
,
8068 unsigned int duration
, gfp_t gfp
)
8070 struct sk_buff
*msg
;
8073 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8077 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8083 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8084 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8085 wdev
->netdev
->ifindex
)) ||
8086 nla_put_u32(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
8087 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
8088 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
) ||
8089 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8090 goto nla_put_failure
;
8092 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
8093 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
8094 goto nla_put_failure
;
8096 genlmsg_end(msg
, hdr
);
8098 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8099 nl80211_mlme_mcgrp
.id
, gfp
);
8103 genlmsg_cancel(msg
, hdr
);
8107 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
8108 struct wireless_dev
*wdev
, u64 cookie
,
8109 struct ieee80211_channel
*chan
,
8110 enum nl80211_channel_type channel_type
,
8111 unsigned int duration
, gfp_t gfp
)
8113 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
8114 rdev
, wdev
, cookie
, chan
,
8115 channel_type
, duration
, gfp
);
8118 void nl80211_send_remain_on_channel_cancel(
8119 struct cfg80211_registered_device
*rdev
,
8120 struct wireless_dev
*wdev
,
8121 u64 cookie
, struct ieee80211_channel
*chan
,
8122 enum nl80211_channel_type channel_type
, gfp_t gfp
)
8124 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8125 rdev
, wdev
, cookie
, chan
,
8126 channel_type
, 0, gfp
);
8129 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
8130 struct net_device
*dev
, const u8
*mac_addr
,
8131 struct station_info
*sinfo
, gfp_t gfp
)
8133 struct sk_buff
*msg
;
8135 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8139 if (nl80211_send_station(msg
, 0, 0, 0,
8140 rdev
, dev
, mac_addr
, sinfo
) < 0) {
8145 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8146 nl80211_mlme_mcgrp
.id
, gfp
);
8149 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
8150 struct net_device
*dev
, const u8
*mac_addr
,
8153 struct sk_buff
*msg
;
8156 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8160 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
8166 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8167 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
8168 goto nla_put_failure
;
8170 genlmsg_end(msg
, hdr
);
8172 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8173 nl80211_mlme_mcgrp
.id
, gfp
);
8177 genlmsg_cancel(msg
, hdr
);
8181 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
8182 const u8
*addr
, gfp_t gfp
)
8184 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8185 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8186 struct sk_buff
*msg
;
8189 u32 nlpid
= ACCESS_ONCE(wdev
->ap_unexpected_nlpid
);
8194 msg
= nlmsg_new(100, gfp
);
8198 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8204 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8205 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8206 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8207 goto nla_put_failure
;
8209 err
= genlmsg_end(msg
, hdr
);
8215 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8219 genlmsg_cancel(msg
, hdr
);
8224 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
8226 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
8230 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
8231 const u8
*addr
, gfp_t gfp
)
8233 return __nl80211_unexpected_frame(dev
,
8234 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
8238 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
8239 struct wireless_dev
*wdev
, u32 nlpid
,
8240 int freq
, int sig_dbm
,
8241 const u8
*buf
, size_t len
, gfp_t gfp
)
8243 struct net_device
*netdev
= wdev
->netdev
;
8244 struct sk_buff
*msg
;
8247 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8251 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8257 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8258 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8259 netdev
->ifindex
)) ||
8260 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8262 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8263 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8264 goto nla_put_failure
;
8266 genlmsg_end(msg
, hdr
);
8268 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8271 genlmsg_cancel(msg
, hdr
);
8276 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
8277 struct wireless_dev
*wdev
, u64 cookie
,
8278 const u8
*buf
, size_t len
, bool ack
,
8281 struct net_device
*netdev
= wdev
->netdev
;
8282 struct sk_buff
*msg
;
8285 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8289 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
8295 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8296 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8297 netdev
->ifindex
)) ||
8298 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
8299 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8300 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8301 goto nla_put_failure
;
8303 genlmsg_end(msg
, hdr
);
8305 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
8309 genlmsg_cancel(msg
, hdr
);
8314 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
8315 struct net_device
*netdev
,
8316 enum nl80211_cqm_rssi_threshold_event rssi_event
,
8319 struct sk_buff
*msg
;
8320 struct nlattr
*pinfoattr
;
8323 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8327 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8333 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8334 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8335 goto nla_put_failure
;
8337 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8339 goto nla_put_failure
;
8341 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
8343 goto nla_put_failure
;
8345 nla_nest_end(msg
, pinfoattr
);
8347 genlmsg_end(msg
, hdr
);
8349 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8350 nl80211_mlme_mcgrp
.id
, gfp
);
8354 genlmsg_cancel(msg
, hdr
);
8358 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
8359 struct net_device
*netdev
, const u8
*bssid
,
8360 const u8
*replay_ctr
, gfp_t gfp
)
8362 struct sk_buff
*msg
;
8363 struct nlattr
*rekey_attr
;
8366 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8370 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8376 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8377 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8378 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8379 goto nla_put_failure
;
8381 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8383 goto nla_put_failure
;
8385 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
8386 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
8387 goto nla_put_failure
;
8389 nla_nest_end(msg
, rekey_attr
);
8391 genlmsg_end(msg
, hdr
);
8393 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8394 nl80211_mlme_mcgrp
.id
, gfp
);
8398 genlmsg_cancel(msg
, hdr
);
8402 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
8403 struct net_device
*netdev
, int index
,
8404 const u8
*bssid
, bool preauth
, gfp_t gfp
)
8406 struct sk_buff
*msg
;
8407 struct nlattr
*attr
;
8410 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8414 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
8420 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8421 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8422 goto nla_put_failure
;
8424 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
8426 goto nla_put_failure
;
8428 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
8429 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
8431 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
8432 goto nla_put_failure
;
8434 nla_nest_end(msg
, attr
);
8436 genlmsg_end(msg
, hdr
);
8438 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8439 nl80211_mlme_mcgrp
.id
, gfp
);
8443 genlmsg_cancel(msg
, hdr
);
8447 void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
8448 struct net_device
*netdev
, int freq
,
8449 enum nl80211_channel_type type
, gfp_t gfp
)
8451 struct sk_buff
*msg
;
8454 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8458 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
8464 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8465 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8466 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, type
))
8467 goto nla_put_failure
;
8469 genlmsg_end(msg
, hdr
);
8471 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8472 nl80211_mlme_mcgrp
.id
, gfp
);
8476 genlmsg_cancel(msg
, hdr
);
8481 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
8482 struct net_device
*netdev
, const u8
*peer
,
8483 u32 num_packets
, gfp_t gfp
)
8485 struct sk_buff
*msg
;
8486 struct nlattr
*pinfoattr
;
8489 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8493 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8499 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8500 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8501 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8502 goto nla_put_failure
;
8504 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8506 goto nla_put_failure
;
8508 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
8509 goto nla_put_failure
;
8511 nla_nest_end(msg
, pinfoattr
);
8513 genlmsg_end(msg
, hdr
);
8515 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8516 nl80211_mlme_mcgrp
.id
, gfp
);
8520 genlmsg_cancel(msg
, hdr
);
8524 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
8525 u64 cookie
, bool acked
, gfp_t gfp
)
8527 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8528 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8529 struct sk_buff
*msg
;
8533 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8537 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
8543 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8544 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8545 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8546 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8547 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8548 goto nla_put_failure
;
8550 err
= genlmsg_end(msg
, hdr
);
8556 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8557 nl80211_mlme_mcgrp
.id
, gfp
);
8561 genlmsg_cancel(msg
, hdr
);
8564 EXPORT_SYMBOL(cfg80211_probe_status
);
8566 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
8567 const u8
*frame
, size_t len
,
8568 int freq
, int sig_dbm
, gfp_t gfp
)
8570 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8571 struct sk_buff
*msg
;
8573 u32 nlpid
= ACCESS_ONCE(rdev
->ap_beacons_nlpid
);
8578 msg
= nlmsg_new(len
+ 100, gfp
);
8582 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8588 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8590 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
8592 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8593 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
8594 goto nla_put_failure
;
8596 genlmsg_end(msg
, hdr
);
8598 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8602 genlmsg_cancel(msg
, hdr
);
8605 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
8607 static int nl80211_netlink_notify(struct notifier_block
* nb
,
8608 unsigned long state
,
8611 struct netlink_notify
*notify
= _notify
;
8612 struct cfg80211_registered_device
*rdev
;
8613 struct wireless_dev
*wdev
;
8615 if (state
!= NETLINK_URELEASE
)
8620 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
8621 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
8622 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
8623 if (rdev
->ap_beacons_nlpid
== notify
->pid
)
8624 rdev
->ap_beacons_nlpid
= 0;
8632 static struct notifier_block nl80211_netlink_notifier
= {
8633 .notifier_call
= nl80211_netlink_notify
,
8636 /* initialisation/exit functions */
8638 int nl80211_init(void)
8642 err
= genl_register_family_with_ops(&nl80211_fam
,
8643 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
8647 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
8651 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
8655 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
8659 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
8663 #ifdef CONFIG_NL80211_TESTMODE
8664 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
8669 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
8675 genl_unregister_family(&nl80211_fam
);
8679 void nl80211_exit(void)
8681 netlink_unregister_notifier(&nl80211_netlink_notifier
);
8682 genl_unregister_family(&nl80211_fam
);