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>
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
},
227 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
228 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
229 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
230 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
233 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
234 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
235 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
236 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
237 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
239 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
240 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
241 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
243 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
244 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
246 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
247 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
248 .len
= WLAN_MAX_KEY_LEN
},
249 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
250 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
252 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
253 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
255 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
256 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
257 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
258 .len
= IEEE80211_MAX_DATA_LEN
},
259 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
260 .len
= IEEE80211_MAX_DATA_LEN
},
261 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
262 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
263 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
264 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
265 .len
= NL80211_MAX_SUPP_RATES
},
266 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
267 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
268 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
269 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
270 .len
= IEEE80211_MAX_MESH_ID_LEN
},
271 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
273 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
274 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
276 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
277 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
278 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
279 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
280 .len
= NL80211_MAX_SUPP_RATES
},
281 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
283 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
284 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
286 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
288 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
289 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
290 .len
= IEEE80211_MAX_DATA_LEN
},
291 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
292 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
294 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
295 .len
= IEEE80211_MAX_SSID_LEN
},
296 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
297 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
298 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
299 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
301 [NL80211_ATTR_STA_FLAGS2
] = {
302 .len
= sizeof(struct nl80211_sta_flag_update
),
304 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
305 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
306 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
307 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
308 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
309 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
311 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
312 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
313 .len
= WLAN_PMKID_LEN
},
314 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
315 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
316 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
317 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
318 .len
= IEEE80211_MAX_DATA_LEN
},
319 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
320 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
321 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
322 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
323 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
324 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
325 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
326 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
327 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
328 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
329 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
331 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
332 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
333 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
334 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
335 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
336 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
337 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
338 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
339 .len
= IEEE80211_MAX_DATA_LEN
},
340 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
341 .len
= IEEE80211_MAX_DATA_LEN
},
342 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
343 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
344 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
346 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
347 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
348 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
349 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
351 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
352 .len
= IEEE80211_MAX_DATA_LEN
},
353 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
354 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
355 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
356 .len
= NL80211_HT_CAPABILITY_LEN
358 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
359 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
360 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
361 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
362 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
363 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
364 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
365 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
366 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
367 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
370 /* policy for the key attributes */
371 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
372 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
373 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
374 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
375 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
376 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
377 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
378 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
379 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
382 /* policy for the key default flags */
383 static const struct nla_policy
384 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
385 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
386 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
389 /* policy for WoWLAN attributes */
390 static const struct nla_policy
391 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
392 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
393 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
394 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
395 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
396 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
397 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
398 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
399 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
402 /* policy for GTK rekey offload attributes */
403 static const struct nla_policy
404 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
405 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
406 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
407 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
410 static const struct nla_policy
411 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
412 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
413 .len
= IEEE80211_MAX_SSID_LEN
},
414 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
417 /* ifidx get helper */
418 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
422 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
423 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
428 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
431 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
437 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
438 struct netlink_callback
*cb
,
439 struct cfg80211_registered_device
**rdev
,
440 struct net_device
**dev
)
442 int ifidx
= cb
->args
[0];
446 ifidx
= nl80211_get_ifidx(cb
);
454 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
460 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
462 err
= PTR_ERR(*rdev
);
472 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
474 cfg80211_unlock_rdev(rdev
);
479 static bool is_valid_ie_attr(const struct nlattr
*attr
)
487 pos
= nla_data(attr
);
508 /* message building helper */
509 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
512 /* since there is no private header just add the generic one */
513 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
516 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
517 struct ieee80211_channel
*chan
)
519 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
521 goto nla_put_failure
;
523 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
524 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
525 goto nla_put_failure
;
526 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
527 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
528 goto nla_put_failure
;
529 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
530 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
531 goto nla_put_failure
;
532 if ((chan
->flags
& IEEE80211_CHAN_RADAR
) &&
533 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
534 goto nla_put_failure
;
536 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
537 DBM_TO_MBM(chan
->max_power
)))
538 goto nla_put_failure
;
546 /* netlink command implementations */
553 bool def_uni
, def_multi
;
556 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
558 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
559 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
564 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
565 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
574 if (tb
[NL80211_KEY_IDX
])
575 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
577 if (tb
[NL80211_KEY_DATA
]) {
578 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
579 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
582 if (tb
[NL80211_KEY_SEQ
]) {
583 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
584 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
587 if (tb
[NL80211_KEY_CIPHER
])
588 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
590 if (tb
[NL80211_KEY_TYPE
]) {
591 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
592 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
596 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
597 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
598 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
599 tb
[NL80211_KEY_DEFAULT_TYPES
],
600 nl80211_key_default_policy
);
604 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
605 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
611 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
613 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
614 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
615 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
618 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
619 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
620 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
623 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
624 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
626 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
627 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
629 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
630 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
639 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
640 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
641 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
645 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
646 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
647 int err
= nla_parse_nested(
648 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
649 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
650 nl80211_key_default_policy
);
654 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
655 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
661 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
665 memset(k
, 0, sizeof(*k
));
669 if (info
->attrs
[NL80211_ATTR_KEY
])
670 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
672 err
= nl80211_parse_key_old(info
, k
);
677 if (k
->def
&& k
->defmgmt
)
681 if (k
->def_uni
|| !k
->def_multi
)
687 if (k
->idx
< 4 || k
->idx
> 5)
690 if (k
->idx
< 0 || k
->idx
> 3)
693 if (k
->idx
< 0 || k
->idx
> 5)
701 static struct cfg80211_cached_keys
*
702 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
703 struct nlattr
*keys
, bool *no_ht
)
705 struct key_parse parse
;
707 struct cfg80211_cached_keys
*result
;
708 int rem
, err
, def
= 0;
710 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
712 return ERR_PTR(-ENOMEM
);
715 result
->defmgmt
= -1;
717 nla_for_each_nested(key
, keys
, rem
) {
718 memset(&parse
, 0, sizeof(parse
));
721 err
= nl80211_parse_key_new(key
, &parse
);
727 if (parse
.idx
< 0 || parse
.idx
> 4)
733 result
->def
= parse
.idx
;
734 if (!parse
.def_uni
|| !parse
.def_multi
)
736 } else if (parse
.defmgmt
)
738 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
739 parse
.idx
, false, NULL
);
742 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
743 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
744 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
745 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
747 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
748 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
760 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
762 ASSERT_WDEV_LOCK(wdev
);
764 switch (wdev
->iftype
) {
765 case NL80211_IFTYPE_AP
:
766 case NL80211_IFTYPE_AP_VLAN
:
767 case NL80211_IFTYPE_P2P_GO
:
768 case NL80211_IFTYPE_MESH_POINT
:
770 case NL80211_IFTYPE_ADHOC
:
771 if (!wdev
->current_bss
)
774 case NL80211_IFTYPE_STATION
:
775 case NL80211_IFTYPE_P2P_CLIENT
:
776 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
786 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
788 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
792 goto nla_put_failure
;
796 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
797 goto nla_put_failure
;
802 nla_nest_end(msg
, nl_modes
);
809 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
812 struct nlattr
*nl_combis
;
815 nl_combis
= nla_nest_start(msg
,
816 NL80211_ATTR_INTERFACE_COMBINATIONS
);
818 goto nla_put_failure
;
820 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
821 const struct ieee80211_iface_combination
*c
;
822 struct nlattr
*nl_combi
, *nl_limits
;
824 c
= &wiphy
->iface_combinations
[i
];
826 nl_combi
= nla_nest_start(msg
, i
+ 1);
828 goto nla_put_failure
;
830 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
832 goto nla_put_failure
;
834 for (j
= 0; j
< c
->n_limits
; j
++) {
835 struct nlattr
*nl_limit
;
837 nl_limit
= nla_nest_start(msg
, j
+ 1);
839 goto nla_put_failure
;
840 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
842 goto nla_put_failure
;
843 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
845 goto nla_put_failure
;
846 nla_nest_end(msg
, nl_limit
);
849 nla_nest_end(msg
, nl_limits
);
851 if (c
->beacon_int_infra_match
&&
852 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
853 goto nla_put_failure
;
854 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
855 c
->num_different_channels
) ||
856 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
858 goto nla_put_failure
;
860 nla_nest_end(msg
, nl_combi
);
863 nla_nest_end(msg
, nl_combis
);
870 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
871 struct cfg80211_registered_device
*dev
)
874 struct nlattr
*nl_bands
, *nl_band
;
875 struct nlattr
*nl_freqs
, *nl_freq
;
876 struct nlattr
*nl_rates
, *nl_rate
;
877 struct nlattr
*nl_cmds
;
878 enum ieee80211_band band
;
879 struct ieee80211_channel
*chan
;
880 struct ieee80211_rate
*rate
;
882 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
883 dev
->wiphy
.mgmt_stypes
;
885 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
889 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
890 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
)) ||
891 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
892 cfg80211_rdev_list_generation
) ||
893 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
894 dev
->wiphy
.retry_short
) ||
895 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
896 dev
->wiphy
.retry_long
) ||
897 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
898 dev
->wiphy
.frag_threshold
) ||
899 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
900 dev
->wiphy
.rts_threshold
) ||
901 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
902 dev
->wiphy
.coverage_class
) ||
903 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
904 dev
->wiphy
.max_scan_ssids
) ||
905 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
906 dev
->wiphy
.max_sched_scan_ssids
) ||
907 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
908 dev
->wiphy
.max_scan_ie_len
) ||
909 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
910 dev
->wiphy
.max_sched_scan_ie_len
) ||
911 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
912 dev
->wiphy
.max_match_sets
))
913 goto nla_put_failure
;
915 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
916 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
917 goto nla_put_failure
;
918 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
919 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
920 goto nla_put_failure
;
921 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
922 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
923 goto nla_put_failure
;
924 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
925 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
926 goto nla_put_failure
;
927 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
928 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
929 goto nla_put_failure
;
930 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
931 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
932 goto nla_put_failure
;
934 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
935 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
936 dev
->wiphy
.cipher_suites
))
937 goto nla_put_failure
;
939 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
940 dev
->wiphy
.max_num_pmkids
))
941 goto nla_put_failure
;
943 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
944 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
945 goto nla_put_failure
;
947 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
948 dev
->wiphy
.available_antennas_tx
) ||
949 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
950 dev
->wiphy
.available_antennas_rx
))
951 goto nla_put_failure
;
953 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
954 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
955 dev
->wiphy
.probe_resp_offload
))
956 goto nla_put_failure
;
958 if ((dev
->wiphy
.available_antennas_tx
||
959 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
960 u32 tx_ant
= 0, rx_ant
= 0;
962 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
964 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
,
966 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
,
968 goto nla_put_failure
;
972 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
973 dev
->wiphy
.interface_modes
))
974 goto nla_put_failure
;
976 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
978 goto nla_put_failure
;
980 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
981 if (!dev
->wiphy
.bands
[band
])
984 nl_band
= nla_nest_start(msg
, band
);
986 goto nla_put_failure
;
989 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
&&
990 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
991 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
992 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
) ||
993 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
994 dev
->wiphy
.bands
[band
]->ht_cap
.cap
) ||
995 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
996 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
) ||
997 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
998 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
)))
999 goto nla_put_failure
;
1002 if (dev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
&&
1003 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1004 sizeof(dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
),
1005 &dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
) ||
1006 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1007 dev
->wiphy
.bands
[band
]->vht_cap
.cap
)))
1008 goto nla_put_failure
;
1010 /* add frequencies */
1011 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
1013 goto nla_put_failure
;
1015 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
1016 nl_freq
= nla_nest_start(msg
, i
);
1018 goto nla_put_failure
;
1020 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
1022 if (nl80211_msg_put_channel(msg
, chan
))
1023 goto nla_put_failure
;
1025 nla_nest_end(msg
, nl_freq
);
1028 nla_nest_end(msg
, nl_freqs
);
1031 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1033 goto nla_put_failure
;
1035 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
1036 nl_rate
= nla_nest_start(msg
, i
);
1038 goto nla_put_failure
;
1040 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
1041 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1043 goto nla_put_failure
;
1044 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1046 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1047 goto nla_put_failure
;
1049 nla_nest_end(msg
, nl_rate
);
1052 nla_nest_end(msg
, nl_rates
);
1054 nla_nest_end(msg
, nl_band
);
1056 nla_nest_end(msg
, nl_bands
);
1058 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1060 goto nla_put_failure
;
1063 #define CMD(op, n) \
1065 if (dev->ops->op) { \
1067 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1068 goto nla_put_failure; \
1072 CMD(add_virtual_intf
, NEW_INTERFACE
);
1073 CMD(change_virtual_intf
, SET_INTERFACE
);
1074 CMD(add_key
, NEW_KEY
);
1075 CMD(start_ap
, START_AP
);
1076 CMD(add_station
, NEW_STATION
);
1077 CMD(add_mpath
, NEW_MPATH
);
1078 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1079 CMD(change_bss
, SET_BSS
);
1080 CMD(auth
, AUTHENTICATE
);
1081 CMD(assoc
, ASSOCIATE
);
1082 CMD(deauth
, DEAUTHENTICATE
);
1083 CMD(disassoc
, DISASSOCIATE
);
1084 CMD(join_ibss
, JOIN_IBSS
);
1085 CMD(join_mesh
, JOIN_MESH
);
1086 CMD(set_pmksa
, SET_PMKSA
);
1087 CMD(del_pmksa
, DEL_PMKSA
);
1088 CMD(flush_pmksa
, FLUSH_PMKSA
);
1089 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1090 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1091 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1092 CMD(mgmt_tx
, FRAME
);
1093 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1094 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1096 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1097 goto nla_put_failure
;
1099 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1100 dev
->ops
->join_mesh
) {
1102 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1103 goto nla_put_failure
;
1105 CMD(set_wds_peer
, SET_WDS_PEER
);
1106 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1107 CMD(tdls_mgmt
, TDLS_MGMT
);
1108 CMD(tdls_oper
, TDLS_OPER
);
1110 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1111 CMD(sched_scan_start
, START_SCHED_SCAN
);
1112 CMD(probe_client
, PROBE_CLIENT
);
1113 CMD(set_noack_map
, SET_NOACK_MAP
);
1114 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1116 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1117 goto nla_put_failure
;
1119 CMD(start_p2p_device
, START_P2P_DEVICE
);
1120 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1122 #ifdef CONFIG_NL80211_TESTMODE
1123 CMD(testmode_cmd
, TESTMODE
);
1128 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1130 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1131 goto nla_put_failure
;
1134 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1136 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1137 goto nla_put_failure
;
1140 nla_nest_end(msg
, nl_cmds
);
1142 if (dev
->ops
->remain_on_channel
&&
1143 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1144 nla_put_u32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1145 dev
->wiphy
.max_remain_on_channel_duration
))
1146 goto nla_put_failure
;
1148 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1149 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1150 goto nla_put_failure
;
1154 struct nlattr
*nl_ftypes
, *nl_ifs
;
1155 enum nl80211_iftype ift
;
1157 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1159 goto nla_put_failure
;
1161 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1162 nl_ftypes
= nla_nest_start(msg
, ift
);
1164 goto nla_put_failure
;
1166 stypes
= mgmt_stypes
[ift
].tx
;
1169 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1170 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1171 goto nla_put_failure
;
1175 nla_nest_end(msg
, nl_ftypes
);
1178 nla_nest_end(msg
, nl_ifs
);
1180 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1182 goto nla_put_failure
;
1184 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1185 nl_ftypes
= nla_nest_start(msg
, ift
);
1187 goto nla_put_failure
;
1189 stypes
= mgmt_stypes
[ift
].rx
;
1192 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1193 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1194 goto nla_put_failure
;
1198 nla_nest_end(msg
, nl_ftypes
);
1200 nla_nest_end(msg
, nl_ifs
);
1204 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
1205 struct nlattr
*nl_wowlan
;
1207 nl_wowlan
= nla_nest_start(msg
,
1208 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1210 goto nla_put_failure
;
1212 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1213 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1214 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1215 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1216 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1217 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1218 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1219 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1220 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1221 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1222 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1223 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1224 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1225 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1226 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1227 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1228 goto nla_put_failure
;
1229 if (dev
->wiphy
.wowlan
.n_patterns
) {
1230 struct nl80211_wowlan_pattern_support pat
= {
1231 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1233 dev
->wiphy
.wowlan
.pattern_min_len
,
1235 dev
->wiphy
.wowlan
.pattern_max_len
,
1237 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1239 goto nla_put_failure
;
1242 nla_nest_end(msg
, nl_wowlan
);
1246 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1247 dev
->wiphy
.software_iftypes
))
1248 goto nla_put_failure
;
1250 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1251 goto nla_put_failure
;
1253 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1254 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1255 dev
->wiphy
.ap_sme_capa
))
1256 goto nla_put_failure
;
1258 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
,
1259 dev
->wiphy
.features
))
1260 goto nla_put_failure
;
1262 if (dev
->wiphy
.ht_capa_mod_mask
&&
1263 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1264 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1265 dev
->wiphy
.ht_capa_mod_mask
))
1266 goto nla_put_failure
;
1268 return genlmsg_end(msg
, hdr
);
1271 genlmsg_cancel(msg
, hdr
);
1275 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1278 int start
= cb
->args
[0];
1279 struct cfg80211_registered_device
*dev
;
1281 mutex_lock(&cfg80211_mutex
);
1282 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1283 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1287 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).portid
,
1288 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1294 mutex_unlock(&cfg80211_mutex
);
1301 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1303 struct sk_buff
*msg
;
1304 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1306 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1310 if (nl80211_send_wiphy(msg
, info
->snd_portid
, info
->snd_seq
, 0, dev
) < 0) {
1315 return genlmsg_reply(msg
, info
);
1318 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1319 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1320 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1321 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1322 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1323 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1326 static int parse_txq_params(struct nlattr
*tb
[],
1327 struct ieee80211_txq_params
*txq_params
)
1329 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1330 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1331 !tb
[NL80211_TXQ_ATTR_AIFS
])
1334 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1335 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1336 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1337 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1338 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1340 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1346 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1349 * You can only set the channel explicitly for WDS interfaces,
1350 * all others have their channel managed via their respective
1351 * "establish a connection" command (connect, join, ...)
1353 * For AP/GO and mesh mode, the channel can be set with the
1354 * channel userspace API, but is only stored and passed to the
1355 * low-level driver when the AP starts or the mesh is joined.
1356 * This is for backward compatibility, userspace can also give
1357 * the channel in the start-ap or join-mesh commands instead.
1359 * Monitors are special as they are normally slaved to
1360 * whatever else is going on, so they have their own special
1361 * operation to set the monitor channel if possible.
1364 wdev
->iftype
== NL80211_IFTYPE_AP
||
1365 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1366 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1367 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1370 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1371 struct genl_info
*info
,
1372 struct cfg80211_chan_def
*chandef
)
1376 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1379 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1381 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1382 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1383 chandef
->center_freq1
= control_freq
;
1384 chandef
->center_freq2
= 0;
1386 /* Primary channel not allowed */
1387 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1390 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1391 enum nl80211_channel_type chantype
;
1393 chantype
= nla_get_u32(
1394 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1397 case NL80211_CHAN_NO_HT
:
1398 case NL80211_CHAN_HT20
:
1399 case NL80211_CHAN_HT40PLUS
:
1400 case NL80211_CHAN_HT40MINUS
:
1401 cfg80211_chandef_create(chandef
, chandef
->chan
,
1407 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1409 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1410 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1411 chandef
->center_freq1
=
1413 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1414 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1415 chandef
->center_freq2
=
1417 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1420 if (!cfg80211_chandef_valid(chandef
))
1423 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1424 IEEE80211_CHAN_DISABLED
))
1430 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1431 struct wireless_dev
*wdev
,
1432 struct genl_info
*info
)
1434 struct cfg80211_chan_def chandef
;
1436 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1439 iftype
= wdev
->iftype
;
1441 if (!nl80211_can_set_dev_channel(wdev
))
1444 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1448 mutex_lock(&rdev
->devlist_mtx
);
1450 case NL80211_IFTYPE_AP
:
1451 case NL80211_IFTYPE_P2P_GO
:
1452 if (wdev
->beacon_interval
) {
1456 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1460 wdev
->preset_chandef
= chandef
;
1463 case NL80211_IFTYPE_MESH_POINT
:
1464 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1466 case NL80211_IFTYPE_MONITOR
:
1467 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1472 mutex_unlock(&rdev
->devlist_mtx
);
1477 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1479 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1480 struct net_device
*netdev
= info
->user_ptr
[1];
1482 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1485 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1487 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1488 struct net_device
*dev
= info
->user_ptr
[1];
1489 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1492 if (!info
->attrs
[NL80211_ATTR_MAC
])
1495 if (netif_running(dev
))
1498 if (!rdev
->ops
->set_wds_peer
)
1501 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1504 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1505 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1509 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1511 struct cfg80211_registered_device
*rdev
;
1512 struct net_device
*netdev
= NULL
;
1513 struct wireless_dev
*wdev
;
1514 int result
= 0, rem_txq_params
= 0;
1515 struct nlattr
*nl_txq_params
;
1517 u8 retry_short
= 0, retry_long
= 0;
1518 u32 frag_threshold
= 0, rts_threshold
= 0;
1519 u8 coverage_class
= 0;
1522 * Try to find the wiphy and netdev. Normally this
1523 * function shouldn't need the netdev, but this is
1524 * done for backward compatibility -- previously
1525 * setting the channel was done per wiphy, but now
1526 * it is per netdev. Previous userland like hostapd
1527 * also passed a netdev to set_wiphy, so that it is
1528 * possible to let that go to the right netdev!
1530 mutex_lock(&cfg80211_mutex
);
1532 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1533 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1535 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1536 if (netdev
&& netdev
->ieee80211_ptr
) {
1537 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1538 mutex_lock(&rdev
->mtx
);
1544 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1547 mutex_unlock(&cfg80211_mutex
);
1548 return PTR_ERR(rdev
);
1554 mutex_lock(&rdev
->mtx
);
1556 wdev
= netdev
->ieee80211_ptr
;
1559 * end workaround code, by now the rdev is available
1560 * and locked, and wdev may or may not be NULL.
1563 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1564 result
= cfg80211_dev_rename(
1565 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1567 mutex_unlock(&cfg80211_mutex
);
1572 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1573 struct ieee80211_txq_params txq_params
;
1574 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1576 if (!rdev
->ops
->set_txq_params
) {
1577 result
= -EOPNOTSUPP
;
1586 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1587 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1592 if (!netif_running(netdev
)) {
1597 nla_for_each_nested(nl_txq_params
,
1598 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1600 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1601 nla_data(nl_txq_params
),
1602 nla_len(nl_txq_params
),
1604 result
= parse_txq_params(tb
, &txq_params
);
1608 result
= rdev_set_txq_params(rdev
, netdev
,
1615 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1616 result
= __nl80211_set_channel(rdev
,
1617 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
1623 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1624 struct wireless_dev
*txp_wdev
= wdev
;
1625 enum nl80211_tx_power_setting type
;
1628 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
1631 if (!rdev
->ops
->set_tx_power
) {
1632 result
= -EOPNOTSUPP
;
1636 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1637 type
= nla_get_u32(info
->attrs
[idx
]);
1639 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1640 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1645 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1646 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1647 mbm
= nla_get_u32(info
->attrs
[idx
]);
1650 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
1655 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1656 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1658 if ((!rdev
->wiphy
.available_antennas_tx
&&
1659 !rdev
->wiphy
.available_antennas_rx
) ||
1660 !rdev
->ops
->set_antenna
) {
1661 result
= -EOPNOTSUPP
;
1665 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1666 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1668 /* reject antenna configurations which don't match the
1669 * available antenna masks, except for the "all" mask */
1670 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1671 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1676 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1677 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1679 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
1686 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1687 retry_short
= nla_get_u8(
1688 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1689 if (retry_short
== 0) {
1693 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1696 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1697 retry_long
= nla_get_u8(
1698 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1699 if (retry_long
== 0) {
1703 changed
|= WIPHY_PARAM_RETRY_LONG
;
1706 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1707 frag_threshold
= nla_get_u32(
1708 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1709 if (frag_threshold
< 256) {
1713 if (frag_threshold
!= (u32
) -1) {
1715 * Fragments (apart from the last one) are required to
1716 * have even length. Make the fragmentation code
1717 * simpler by stripping LSB should someone try to use
1718 * odd threshold value.
1720 frag_threshold
&= ~0x1;
1722 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1725 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1726 rts_threshold
= nla_get_u32(
1727 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1728 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1731 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1732 coverage_class
= nla_get_u8(
1733 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1734 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1738 u8 old_retry_short
, old_retry_long
;
1739 u32 old_frag_threshold
, old_rts_threshold
;
1740 u8 old_coverage_class
;
1742 if (!rdev
->ops
->set_wiphy_params
) {
1743 result
= -EOPNOTSUPP
;
1747 old_retry_short
= rdev
->wiphy
.retry_short
;
1748 old_retry_long
= rdev
->wiphy
.retry_long
;
1749 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1750 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1751 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1753 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1754 rdev
->wiphy
.retry_short
= retry_short
;
1755 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1756 rdev
->wiphy
.retry_long
= retry_long
;
1757 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1758 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1759 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1760 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1761 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1762 rdev
->wiphy
.coverage_class
= coverage_class
;
1764 result
= rdev_set_wiphy_params(rdev
, changed
);
1766 rdev
->wiphy
.retry_short
= old_retry_short
;
1767 rdev
->wiphy
.retry_long
= old_retry_long
;
1768 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1769 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1770 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1775 mutex_unlock(&rdev
->mtx
);
1781 static inline u64
wdev_id(struct wireless_dev
*wdev
)
1783 return (u64
)wdev
->identifier
|
1784 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
1787 static int nl80211_send_chandef(struct sk_buff
*msg
,
1788 struct cfg80211_chan_def
*chandef
)
1790 WARN_ON(!cfg80211_chandef_valid(chandef
));
1792 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
1793 chandef
->chan
->center_freq
))
1795 switch (chandef
->width
) {
1796 case NL80211_CHAN_WIDTH_20_NOHT
:
1797 case NL80211_CHAN_WIDTH_20
:
1798 case NL80211_CHAN_WIDTH_40
:
1799 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
1800 cfg80211_get_chandef_type(chandef
)))
1806 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
1808 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
1810 if (chandef
->center_freq2
&&
1811 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
1816 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
1817 struct cfg80211_registered_device
*rdev
,
1818 struct wireless_dev
*wdev
)
1820 struct net_device
*dev
= wdev
->netdev
;
1823 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1828 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
1829 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
1830 goto nla_put_failure
;
1832 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1833 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
1834 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
1835 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
1836 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1837 rdev
->devlist_generation
^
1838 (cfg80211_rdev_list_generation
<< 2)))
1839 goto nla_put_failure
;
1841 if (rdev
->ops
->get_channel
) {
1843 struct cfg80211_chan_def chandef
;
1845 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
1847 if (nl80211_send_chandef(msg
, &chandef
))
1848 goto nla_put_failure
;
1852 if (wdev
->ssid_len
) {
1853 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
1854 goto nla_put_failure
;
1857 return genlmsg_end(msg
, hdr
);
1860 genlmsg_cancel(msg
, hdr
);
1864 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1868 int wp_start
= cb
->args
[0];
1869 int if_start
= cb
->args
[1];
1870 struct cfg80211_registered_device
*rdev
;
1871 struct wireless_dev
*wdev
;
1873 mutex_lock(&cfg80211_mutex
);
1874 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1875 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1877 if (wp_idx
< wp_start
) {
1883 mutex_lock(&rdev
->devlist_mtx
);
1884 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
1885 if (if_idx
< if_start
) {
1889 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
1890 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1892 mutex_unlock(&rdev
->devlist_mtx
);
1897 mutex_unlock(&rdev
->devlist_mtx
);
1902 mutex_unlock(&cfg80211_mutex
);
1904 cb
->args
[0] = wp_idx
;
1905 cb
->args
[1] = if_idx
;
1910 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1912 struct sk_buff
*msg
;
1913 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1914 struct wireless_dev
*wdev
= info
->user_ptr
[1];
1916 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1920 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
1926 return genlmsg_reply(msg
, info
);
1929 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1930 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1931 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1932 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1933 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1934 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1937 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1939 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1947 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1948 nla
, mntr_flags_policy
))
1951 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1953 *mntrflags
|= (1<<flag
);
1958 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1959 struct net_device
*netdev
, u8 use_4addr
,
1960 enum nl80211_iftype iftype
)
1963 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1969 case NL80211_IFTYPE_AP_VLAN
:
1970 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1973 case NL80211_IFTYPE_STATION
:
1974 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1984 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1986 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1987 struct vif_params params
;
1989 enum nl80211_iftype otype
, ntype
;
1990 struct net_device
*dev
= info
->user_ptr
[1];
1991 u32 _flags
, *flags
= NULL
;
1992 bool change
= false;
1994 memset(¶ms
, 0, sizeof(params
));
1996 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1998 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1999 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2002 if (ntype
> NL80211_IFTYPE_MAX
)
2006 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2007 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2009 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2011 if (netif_running(dev
))
2015 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2016 IEEE80211_MAX_MESH_ID_LEN
);
2017 wdev
->mesh_id_up_len
=
2018 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2019 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2020 wdev
->mesh_id_up_len
);
2024 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2025 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2027 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2031 params
.use_4addr
= -1;
2034 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2035 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2037 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2047 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2051 if (!err
&& params
.use_4addr
!= -1)
2052 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2057 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2059 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2060 struct vif_params params
;
2061 struct wireless_dev
*wdev
;
2062 struct sk_buff
*msg
;
2064 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2067 memset(¶ms
, 0, sizeof(params
));
2069 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2072 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2073 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2074 if (type
> NL80211_IFTYPE_MAX
)
2078 if (!rdev
->ops
->add_virtual_intf
||
2079 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2082 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2083 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2084 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2089 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2093 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2094 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2096 wdev
= rdev_add_virtual_intf(rdev
,
2097 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2098 type
, err
? NULL
: &flags
, ¶ms
);
2101 return PTR_ERR(wdev
);
2105 case NL80211_IFTYPE_MESH_POINT
:
2106 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2109 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2110 IEEE80211_MAX_MESH_ID_LEN
);
2111 wdev
->mesh_id_up_len
=
2112 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2113 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2114 wdev
->mesh_id_up_len
);
2117 case NL80211_IFTYPE_P2P_DEVICE
:
2119 * P2P Device doesn't have a netdev, so doesn't go
2120 * through the netdev notifier and must be added here
2122 mutex_init(&wdev
->mtx
);
2123 INIT_LIST_HEAD(&wdev
->event_list
);
2124 spin_lock_init(&wdev
->event_lock
);
2125 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2126 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2128 mutex_lock(&rdev
->devlist_mtx
);
2129 wdev
->identifier
= ++rdev
->wdev_id
;
2130 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2131 rdev
->devlist_generation
++;
2132 mutex_unlock(&rdev
->devlist_mtx
);
2138 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2144 return genlmsg_reply(msg
, info
);
2147 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2149 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2150 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2152 if (!rdev
->ops
->del_virtual_intf
)
2156 * If we remove a wireless device without a netdev then clear
2157 * user_ptr[1] so that nl80211_post_doit won't dereference it
2158 * to check if it needs to do dev_put(). Otherwise it crashes
2159 * since the wdev has been freed, unlike with a netdev where
2160 * we need the dev_put() for the netdev to really be freed.
2163 info
->user_ptr
[1] = NULL
;
2165 return rdev_del_virtual_intf(rdev
, wdev
);
2168 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2170 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2171 struct net_device
*dev
= info
->user_ptr
[1];
2174 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2177 if (!rdev
->ops
->set_noack_map
)
2180 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2182 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2185 struct get_key_cookie
{
2186 struct sk_buff
*msg
;
2191 static void get_key_callback(void *c
, struct key_params
*params
)
2194 struct get_key_cookie
*cookie
= c
;
2197 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2198 params
->key_len
, params
->key
)) ||
2200 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2201 params
->seq_len
, params
->seq
)) ||
2203 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2205 goto nla_put_failure
;
2207 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2209 goto nla_put_failure
;
2212 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2213 params
->key_len
, params
->key
)) ||
2215 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2216 params
->seq_len
, params
->seq
)) ||
2218 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2220 goto nla_put_failure
;
2222 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2223 goto nla_put_failure
;
2225 nla_nest_end(cookie
->msg
, key
);
2232 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2234 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2236 struct net_device
*dev
= info
->user_ptr
[1];
2238 const u8
*mac_addr
= NULL
;
2240 struct get_key_cookie cookie
= {
2244 struct sk_buff
*msg
;
2246 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2247 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2252 if (info
->attrs
[NL80211_ATTR_MAC
])
2253 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2255 pairwise
= !!mac_addr
;
2256 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2257 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2258 if (kt
>= NUM_NL80211_KEYTYPES
)
2260 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2261 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2263 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2266 if (!rdev
->ops
->get_key
)
2269 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2273 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2274 NL80211_CMD_NEW_KEY
);
2276 return PTR_ERR(hdr
);
2279 cookie
.idx
= key_idx
;
2281 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2282 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2283 goto nla_put_failure
;
2285 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2286 goto nla_put_failure
;
2288 if (pairwise
&& mac_addr
&&
2289 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2292 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2299 goto nla_put_failure
;
2301 genlmsg_end(msg
, hdr
);
2302 return genlmsg_reply(msg
, info
);
2311 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2313 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2314 struct key_parse key
;
2316 struct net_device
*dev
= info
->user_ptr
[1];
2318 err
= nl80211_parse_key(info
, &key
);
2325 /* only support setting default key */
2326 if (!key
.def
&& !key
.defmgmt
)
2329 wdev_lock(dev
->ieee80211_ptr
);
2332 if (!rdev
->ops
->set_default_key
) {
2337 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2341 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2342 key
.def_uni
, key
.def_multi
);
2347 #ifdef CONFIG_CFG80211_WEXT
2348 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2351 if (key
.def_uni
|| !key
.def_multi
) {
2356 if (!rdev
->ops
->set_default_mgmt_key
) {
2361 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2365 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2369 #ifdef CONFIG_CFG80211_WEXT
2370 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2375 wdev_unlock(dev
->ieee80211_ptr
);
2380 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2382 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2384 struct net_device
*dev
= info
->user_ptr
[1];
2385 struct key_parse key
;
2386 const u8
*mac_addr
= NULL
;
2388 err
= nl80211_parse_key(info
, &key
);
2395 if (info
->attrs
[NL80211_ATTR_MAC
])
2396 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2398 if (key
.type
== -1) {
2400 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2402 key
.type
= NL80211_KEYTYPE_GROUP
;
2406 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2407 key
.type
!= NL80211_KEYTYPE_GROUP
)
2410 if (!rdev
->ops
->add_key
)
2413 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2414 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2418 wdev_lock(dev
->ieee80211_ptr
);
2419 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2421 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2422 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2424 wdev_unlock(dev
->ieee80211_ptr
);
2429 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2431 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2433 struct net_device
*dev
= info
->user_ptr
[1];
2434 u8
*mac_addr
= NULL
;
2435 struct key_parse key
;
2437 err
= nl80211_parse_key(info
, &key
);
2441 if (info
->attrs
[NL80211_ATTR_MAC
])
2442 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2444 if (key
.type
== -1) {
2446 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2448 key
.type
= NL80211_KEYTYPE_GROUP
;
2452 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2453 key
.type
!= NL80211_KEYTYPE_GROUP
)
2456 if (!rdev
->ops
->del_key
)
2459 wdev_lock(dev
->ieee80211_ptr
);
2460 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2462 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2463 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2467 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2468 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2471 #ifdef CONFIG_CFG80211_WEXT
2473 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2474 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2475 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2476 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2479 wdev_unlock(dev
->ieee80211_ptr
);
2484 static int nl80211_parse_beacon(struct genl_info
*info
,
2485 struct cfg80211_beacon_data
*bcn
)
2487 bool haveinfo
= false;
2489 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2490 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2491 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2492 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2495 memset(bcn
, 0, sizeof(*bcn
));
2497 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2498 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2499 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2505 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2506 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2508 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2515 if (info
->attrs
[NL80211_ATTR_IE
]) {
2516 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2517 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2520 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2521 bcn
->proberesp_ies
=
2522 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2523 bcn
->proberesp_ies_len
=
2524 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2527 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2528 bcn
->assocresp_ies
=
2529 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2530 bcn
->assocresp_ies_len
=
2531 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2534 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2536 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2537 bcn
->probe_resp_len
=
2538 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2544 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2545 struct cfg80211_ap_settings
*params
)
2547 struct wireless_dev
*wdev
;
2550 mutex_lock(&rdev
->devlist_mtx
);
2552 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2553 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2554 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2557 if (!wdev
->preset_chandef
.chan
)
2560 params
->chandef
= wdev
->preset_chandef
;
2565 mutex_unlock(&rdev
->devlist_mtx
);
2570 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
2571 enum nl80211_auth_type auth_type
,
2572 enum nl80211_commands cmd
)
2574 if (auth_type
> NL80211_AUTHTYPE_MAX
)
2578 case NL80211_CMD_AUTHENTICATE
:
2579 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
2580 auth_type
== NL80211_AUTHTYPE_SAE
)
2583 case NL80211_CMD_CONNECT
:
2584 case NL80211_CMD_START_AP
:
2585 /* SAE not supported yet */
2586 if (auth_type
== NL80211_AUTHTYPE_SAE
)
2594 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2596 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2597 struct net_device
*dev
= info
->user_ptr
[1];
2598 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2599 struct cfg80211_ap_settings params
;
2602 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2603 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2606 if (!rdev
->ops
->start_ap
)
2609 if (wdev
->beacon_interval
)
2612 memset(¶ms
, 0, sizeof(params
));
2614 /* these are required for START_AP */
2615 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2616 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2617 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2620 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
2624 params
.beacon_interval
=
2625 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2626 params
.dtim_period
=
2627 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2629 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
2634 * In theory, some of these attributes should be required here
2635 * but since they were not used when the command was originally
2636 * added, keep them optional for old user space programs to let
2637 * them continue to work with drivers that do not need the
2638 * additional information -- drivers must check!
2640 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2641 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2643 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2644 if (params
.ssid_len
== 0 ||
2645 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2649 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2650 params
.hidden_ssid
= nla_get_u32(
2651 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2652 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2653 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
2654 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2658 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2660 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2661 params
.auth_type
= nla_get_u32(
2662 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2663 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
2664 NL80211_CMD_START_AP
))
2667 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2669 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2670 NL80211_MAX_NR_CIPHER_SUITES
);
2674 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
2675 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
2677 params
.inactivity_timeout
= nla_get_u16(
2678 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
2681 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
2682 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2684 params
.p2p_ctwindow
=
2685 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
2686 if (params
.p2p_ctwindow
> 127)
2688 if (params
.p2p_ctwindow
!= 0 &&
2689 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
2693 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
2696 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2698 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
2701 params
.p2p_opp_ps
= tmp
;
2702 if (params
.p2p_opp_ps
!= 0 &&
2703 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
2707 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2708 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
2711 } else if (wdev
->preset_chandef
.chan
) {
2712 params
.chandef
= wdev
->preset_chandef
;
2713 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
2716 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
2719 mutex_lock(&rdev
->devlist_mtx
);
2720 err
= cfg80211_can_use_chan(rdev
, wdev
, params
.chandef
.chan
,
2722 mutex_unlock(&rdev
->devlist_mtx
);
2727 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
2729 wdev
->preset_chandef
= params
.chandef
;
2730 wdev
->beacon_interval
= params
.beacon_interval
;
2731 wdev
->channel
= params
.chandef
.chan
;
2732 wdev
->ssid_len
= params
.ssid_len
;
2733 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
2738 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2740 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2741 struct net_device
*dev
= info
->user_ptr
[1];
2742 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2743 struct cfg80211_beacon_data params
;
2746 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2747 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2750 if (!rdev
->ops
->change_beacon
)
2753 if (!wdev
->beacon_interval
)
2756 err
= nl80211_parse_beacon(info
, ¶ms
);
2760 return rdev_change_beacon(rdev
, dev
, ¶ms
);
2763 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2765 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2766 struct net_device
*dev
= info
->user_ptr
[1];
2768 return cfg80211_stop_ap(rdev
, dev
);
2771 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2772 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2773 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2774 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2775 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2776 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2777 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
2780 static int parse_station_flags(struct genl_info
*info
,
2781 enum nl80211_iftype iftype
,
2782 struct station_parameters
*params
)
2784 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2789 * Try parsing the new attribute first so userspace
2790 * can specify both for older kernels.
2792 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2794 struct nl80211_sta_flag_update
*sta_flags
;
2796 sta_flags
= nla_data(nla
);
2797 params
->sta_flags_mask
= sta_flags
->mask
;
2798 params
->sta_flags_set
= sta_flags
->set
;
2799 if ((params
->sta_flags_mask
|
2800 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2805 /* if present, parse the old attribute */
2807 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2811 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2812 nla
, sta_flags_policy
))
2816 * Only allow certain flags for interface types so that
2817 * other attributes are silently ignored. Remember that
2818 * this is backward compatibility code with old userspace
2819 * and shouldn't be hit in other cases anyway.
2822 case NL80211_IFTYPE_AP
:
2823 case NL80211_IFTYPE_AP_VLAN
:
2824 case NL80211_IFTYPE_P2P_GO
:
2825 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2826 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2827 BIT(NL80211_STA_FLAG_WME
) |
2828 BIT(NL80211_STA_FLAG_MFP
);
2830 case NL80211_IFTYPE_P2P_CLIENT
:
2831 case NL80211_IFTYPE_STATION
:
2832 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2833 BIT(NL80211_STA_FLAG_TDLS_PEER
);
2835 case NL80211_IFTYPE_MESH_POINT
:
2836 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2837 BIT(NL80211_STA_FLAG_MFP
) |
2838 BIT(NL80211_STA_FLAG_AUTHORIZED
);
2843 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
2845 params
->sta_flags_set
|= (1<<flag
);
2847 /* no longer support new API additions in old API */
2848 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
2856 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2859 struct nlattr
*rate
;
2863 rate
= nla_nest_start(msg
, attr
);
2867 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2868 bitrate
= cfg80211_calculate_bitrate(info
);
2869 /* report 16-bit bitrate only if we can */
2870 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
2872 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
2874 if (bitrate_compat
> 0 &&
2875 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
2878 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
2879 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
2881 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
2882 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
2884 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
2885 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
2887 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
2888 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
2890 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
2892 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
2893 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
2895 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
2896 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
2898 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
2899 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
2901 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
2902 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
2904 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
2905 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
2909 nla_nest_end(msg
, rate
);
2913 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
2915 struct cfg80211_registered_device
*rdev
,
2916 struct net_device
*dev
,
2917 const u8
*mac_addr
, struct station_info
*sinfo
)
2920 struct nlattr
*sinfoattr
, *bss_param
;
2922 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2926 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2927 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
2928 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
2929 goto nla_put_failure
;
2931 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2933 goto nla_put_failure
;
2934 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
2935 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2936 sinfo
->connected_time
))
2937 goto nla_put_failure
;
2938 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
2939 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2940 sinfo
->inactive_time
))
2941 goto nla_put_failure
;
2942 if ((sinfo
->filled
& STATION_INFO_RX_BYTES
) &&
2943 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
2945 goto nla_put_failure
;
2946 if ((sinfo
->filled
& STATION_INFO_TX_BYTES
) &&
2947 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
2949 goto nla_put_failure
;
2950 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
2951 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
2952 goto nla_put_failure
;
2953 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
2954 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
2955 goto nla_put_failure
;
2956 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
2957 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2958 sinfo
->plink_state
))
2959 goto nla_put_failure
;
2960 switch (rdev
->wiphy
.signal_type
) {
2961 case CFG80211_SIGNAL_TYPE_MBM
:
2962 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
2963 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
2965 goto nla_put_failure
;
2966 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
2967 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2969 goto nla_put_failure
;
2974 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2975 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2976 NL80211_STA_INFO_TX_BITRATE
))
2977 goto nla_put_failure
;
2979 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2980 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2981 NL80211_STA_INFO_RX_BITRATE
))
2982 goto nla_put_failure
;
2984 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
2985 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2987 goto nla_put_failure
;
2988 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
2989 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2991 goto nla_put_failure
;
2992 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
2993 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2995 goto nla_put_failure
;
2996 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
2997 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
2999 goto nla_put_failure
;
3000 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3001 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3002 sinfo
->beacon_loss_count
))
3003 goto nla_put_failure
;
3004 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3005 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3007 goto nla_put_failure
;
3009 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3010 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3011 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3012 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3013 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3014 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3015 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3016 sinfo
->bss_param
.dtim_period
) ||
3017 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3018 sinfo
->bss_param
.beacon_interval
))
3019 goto nla_put_failure
;
3021 nla_nest_end(msg
, bss_param
);
3023 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3024 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3025 sizeof(struct nl80211_sta_flag_update
),
3027 goto nla_put_failure
;
3028 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3029 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3031 goto nla_put_failure
;
3032 nla_nest_end(msg
, sinfoattr
);
3034 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3035 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3036 sinfo
->assoc_req_ies
))
3037 goto nla_put_failure
;
3039 return genlmsg_end(msg
, hdr
);
3042 genlmsg_cancel(msg
, hdr
);
3046 static int nl80211_dump_station(struct sk_buff
*skb
,
3047 struct netlink_callback
*cb
)
3049 struct station_info sinfo
;
3050 struct cfg80211_registered_device
*dev
;
3051 struct net_device
*netdev
;
3052 u8 mac_addr
[ETH_ALEN
];
3053 int sta_idx
= cb
->args
[1];
3056 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3060 if (!dev
->ops
->dump_station
) {
3066 memset(&sinfo
, 0, sizeof(sinfo
));
3067 err
= rdev_dump_station(dev
, netdev
, sta_idx
,
3074 if (nl80211_send_station(skb
,
3075 NETLINK_CB(cb
->skb
).portid
,
3076 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3077 dev
, netdev
, mac_addr
,
3086 cb
->args
[1] = sta_idx
;
3089 nl80211_finish_netdev_dump(dev
);
3094 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3096 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3097 struct net_device
*dev
= info
->user_ptr
[1];
3098 struct station_info sinfo
;
3099 struct sk_buff
*msg
;
3100 u8
*mac_addr
= NULL
;
3103 memset(&sinfo
, 0, sizeof(sinfo
));
3105 if (!info
->attrs
[NL80211_ATTR_MAC
])
3108 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3110 if (!rdev
->ops
->get_station
)
3113 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3117 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3121 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3122 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3127 return genlmsg_reply(msg
, info
);
3131 * Get vlan interface making sure it is running and on the right wiphy.
3133 static struct net_device
*get_vlan(struct genl_info
*info
,
3134 struct cfg80211_registered_device
*rdev
)
3136 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3137 struct net_device
*v
;
3143 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3145 return ERR_PTR(-ENODEV
);
3147 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3152 if (!netif_running(v
)) {
3160 return ERR_PTR(ret
);
3163 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3165 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3167 struct net_device
*dev
= info
->user_ptr
[1];
3168 struct station_parameters params
;
3169 u8
*mac_addr
= NULL
;
3171 memset(¶ms
, 0, sizeof(params
));
3173 params
.listen_interval
= -1;
3174 params
.plink_state
= -1;
3176 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3179 if (!info
->attrs
[NL80211_ATTR_MAC
])
3182 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3184 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3185 params
.supported_rates
=
3186 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3187 params
.supported_rates_len
=
3188 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3191 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3192 params
.listen_interval
=
3193 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3195 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3197 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3199 if (!rdev
->ops
->change_station
)
3202 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3205 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3206 params
.plink_action
=
3207 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3209 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
3210 params
.plink_state
=
3211 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3213 switch (dev
->ieee80211_ptr
->iftype
) {
3214 case NL80211_IFTYPE_AP
:
3215 case NL80211_IFTYPE_AP_VLAN
:
3216 case NL80211_IFTYPE_P2P_GO
:
3217 /* disallow mesh-specific things */
3218 if (params
.plink_action
)
3221 /* TDLS can't be set, ... */
3222 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3225 * ... but don't bother the driver with it. This works around
3226 * a hostapd/wpa_supplicant issue -- it always includes the
3227 * TLDS_PEER flag in the mask even for AP mode.
3229 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3231 /* accept only the listed bits */
3232 if (params
.sta_flags_mask
&
3233 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3234 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3235 BIT(NL80211_STA_FLAG_WME
) |
3236 BIT(NL80211_STA_FLAG_MFP
)))
3239 /* must be last in here for error handling */
3240 params
.vlan
= get_vlan(info
, rdev
);
3241 if (IS_ERR(params
.vlan
))
3242 return PTR_ERR(params
.vlan
);
3244 case NL80211_IFTYPE_P2P_CLIENT
:
3245 case NL80211_IFTYPE_STATION
:
3247 * Don't allow userspace to change the TDLS_PEER flag,
3248 * but silently ignore attempts to change it since we
3249 * don't have state here to verify that it doesn't try
3250 * to change the flag.
3252 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3254 case NL80211_IFTYPE_ADHOC
:
3255 /* disallow things sta doesn't support */
3256 if (params
.plink_action
)
3260 if (params
.listen_interval
>= 0)
3262 /* reject any changes other than AUTHORIZED */
3263 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3266 case NL80211_IFTYPE_MESH_POINT
:
3267 /* disallow things mesh doesn't support */
3272 if (params
.listen_interval
>= 0)
3275 * No special handling for TDLS here -- the userspace
3276 * mesh code doesn't have this bug.
3278 if (params
.sta_flags_mask
&
3279 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3280 BIT(NL80211_STA_FLAG_MFP
) |
3281 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3288 /* be aware of params.vlan when changing code here */
3290 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3293 dev_put(params
.vlan
);
3298 static struct nla_policy
3299 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3300 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3301 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3304 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3306 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3308 struct net_device
*dev
= info
->user_ptr
[1];
3309 struct station_parameters params
;
3310 u8
*mac_addr
= NULL
;
3312 memset(¶ms
, 0, sizeof(params
));
3314 if (!info
->attrs
[NL80211_ATTR_MAC
])
3317 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3320 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3323 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3326 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3327 params
.supported_rates
=
3328 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3329 params
.supported_rates_len
=
3330 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3331 params
.listen_interval
=
3332 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3334 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3335 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3338 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3340 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3342 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3344 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3346 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3347 params
.plink_action
=
3348 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3350 if (!rdev
->ops
->add_station
)
3353 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3356 switch (dev
->ieee80211_ptr
->iftype
) {
3357 case NL80211_IFTYPE_AP
:
3358 case NL80211_IFTYPE_AP_VLAN
:
3359 case NL80211_IFTYPE_P2P_GO
:
3360 /* parse WME attributes if sta is WME capable */
3361 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
3362 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
3363 info
->attrs
[NL80211_ATTR_STA_WME
]) {
3364 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3367 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3368 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3369 nl80211_sta_wme_policy
);
3373 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3374 params
.uapsd_queues
=
3375 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3376 if (params
.uapsd_queues
&
3377 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3380 if (tb
[NL80211_STA_WME_MAX_SP
])
3382 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3385 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3388 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3390 /* TDLS peers cannot be added */
3391 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3393 /* but don't bother the driver with it */
3394 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3396 /* must be last in here for error handling */
3397 params
.vlan
= get_vlan(info
, rdev
);
3398 if (IS_ERR(params
.vlan
))
3399 return PTR_ERR(params
.vlan
);
3401 case NL80211_IFTYPE_MESH_POINT
:
3402 /* TDLS peers cannot be added */
3403 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3406 case NL80211_IFTYPE_STATION
:
3407 /* Only TDLS peers can be added */
3408 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3410 /* Can only add if TDLS ... */
3411 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3413 /* ... with external setup is supported */
3414 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3421 /* be aware of params.vlan when changing code here */
3423 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
3426 dev_put(params
.vlan
);
3430 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
3432 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3433 struct net_device
*dev
= info
->user_ptr
[1];
3434 u8
*mac_addr
= NULL
;
3436 if (info
->attrs
[NL80211_ATTR_MAC
])
3437 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3439 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3440 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3441 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
3442 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3445 if (!rdev
->ops
->del_station
)
3448 return rdev_del_station(rdev
, dev
, mac_addr
);
3451 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3452 int flags
, struct net_device
*dev
,
3453 u8
*dst
, u8
*next_hop
,
3454 struct mpath_info
*pinfo
)
3457 struct nlattr
*pinfoattr
;
3459 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3463 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3464 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
3465 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
3466 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
3467 goto nla_put_failure
;
3469 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
3471 goto nla_put_failure
;
3472 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
3473 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
3475 goto nla_put_failure
;
3476 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
3477 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
3478 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
3479 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
3481 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
3482 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
3484 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
3485 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
3487 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
3488 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
3489 pinfo
->discovery_timeout
)) ||
3490 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
3491 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
3492 pinfo
->discovery_retries
)))
3493 goto nla_put_failure
;
3495 nla_nest_end(msg
, pinfoattr
);
3497 return genlmsg_end(msg
, hdr
);
3500 genlmsg_cancel(msg
, hdr
);
3504 static int nl80211_dump_mpath(struct sk_buff
*skb
,
3505 struct netlink_callback
*cb
)
3507 struct mpath_info pinfo
;
3508 struct cfg80211_registered_device
*dev
;
3509 struct net_device
*netdev
;
3511 u8 next_hop
[ETH_ALEN
];
3512 int path_idx
= cb
->args
[1];
3515 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3519 if (!dev
->ops
->dump_mpath
) {
3524 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
3530 err
= rdev_dump_mpath(dev
, netdev
, path_idx
, dst
, next_hop
,
3537 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
3538 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3539 netdev
, dst
, next_hop
,
3548 cb
->args
[1] = path_idx
;
3551 nl80211_finish_netdev_dump(dev
);
3555 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3557 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3559 struct net_device
*dev
= info
->user_ptr
[1];
3560 struct mpath_info pinfo
;
3561 struct sk_buff
*msg
;
3563 u8 next_hop
[ETH_ALEN
];
3565 memset(&pinfo
, 0, sizeof(pinfo
));
3567 if (!info
->attrs
[NL80211_ATTR_MAC
])
3570 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3572 if (!rdev
->ops
->get_mpath
)
3575 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3578 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
3582 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3586 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3587 dev
, dst
, next_hop
, &pinfo
) < 0) {
3592 return genlmsg_reply(msg
, info
);
3595 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3597 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3598 struct net_device
*dev
= info
->user_ptr
[1];
3600 u8
*next_hop
= NULL
;
3602 if (!info
->attrs
[NL80211_ATTR_MAC
])
3605 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3608 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3609 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3611 if (!rdev
->ops
->change_mpath
)
3614 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3617 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
3620 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3622 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3623 struct net_device
*dev
= info
->user_ptr
[1];
3625 u8
*next_hop
= NULL
;
3627 if (!info
->attrs
[NL80211_ATTR_MAC
])
3630 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3633 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3634 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3636 if (!rdev
->ops
->add_mpath
)
3639 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3642 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
3645 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3647 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3648 struct net_device
*dev
= info
->user_ptr
[1];
3651 if (info
->attrs
[NL80211_ATTR_MAC
])
3652 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3654 if (!rdev
->ops
->del_mpath
)
3657 return rdev_del_mpath(rdev
, dev
, dst
);
3660 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
3662 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3663 struct net_device
*dev
= info
->user_ptr
[1];
3664 struct bss_parameters params
;
3666 memset(¶ms
, 0, sizeof(params
));
3667 /* default to not changing parameters */
3668 params
.use_cts_prot
= -1;
3669 params
.use_short_preamble
= -1;
3670 params
.use_short_slot_time
= -1;
3671 params
.ap_isolate
= -1;
3672 params
.ht_opmode
= -1;
3673 params
.p2p_ctwindow
= -1;
3674 params
.p2p_opp_ps
= -1;
3676 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
3677 params
.use_cts_prot
=
3678 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
3679 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
3680 params
.use_short_preamble
=
3681 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
3682 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
3683 params
.use_short_slot_time
=
3684 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
3685 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3686 params
.basic_rates
=
3687 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3688 params
.basic_rates_len
=
3689 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3691 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
3692 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
3693 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
3695 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
3697 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3698 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3700 params
.p2p_ctwindow
=
3701 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3702 if (params
.p2p_ctwindow
< 0)
3704 if (params
.p2p_ctwindow
!= 0 &&
3705 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3709 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3712 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3714 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3717 params
.p2p_opp_ps
= tmp
;
3718 if (params
.p2p_opp_ps
&&
3719 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3723 if (!rdev
->ops
->change_bss
)
3726 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3727 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3730 return rdev_change_bss(rdev
, dev
, ¶ms
);
3733 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
3734 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3735 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3736 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3737 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3738 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3739 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3742 static int parse_reg_rule(struct nlattr
*tb
[],
3743 struct ieee80211_reg_rule
*reg_rule
)
3745 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3746 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3748 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3750 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3752 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3754 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3756 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3759 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3761 freq_range
->start_freq_khz
=
3762 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3763 freq_range
->end_freq_khz
=
3764 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3765 freq_range
->max_bandwidth_khz
=
3766 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3768 power_rule
->max_eirp
=
3769 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3771 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3772 power_rule
->max_antenna_gain
=
3773 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3778 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3782 enum nl80211_user_reg_hint_type user_reg_hint_type
;
3785 * You should only get this when cfg80211 hasn't yet initialized
3786 * completely when built-in to the kernel right between the time
3787 * window between nl80211_init() and regulatory_init(), if that is
3790 mutex_lock(&cfg80211_mutex
);
3791 if (unlikely(!cfg80211_regdomain
)) {
3792 mutex_unlock(&cfg80211_mutex
);
3793 return -EINPROGRESS
;
3795 mutex_unlock(&cfg80211_mutex
);
3797 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3800 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3802 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
3803 user_reg_hint_type
=
3804 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
3806 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
3808 switch (user_reg_hint_type
) {
3809 case NL80211_USER_REG_HINT_USER
:
3810 case NL80211_USER_REG_HINT_CELL_BASE
:
3816 r
= regulatory_hint_user(data
, user_reg_hint_type
);
3821 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3822 struct genl_info
*info
)
3824 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3825 struct net_device
*dev
= info
->user_ptr
[1];
3826 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3827 struct mesh_config cur_params
;
3830 struct nlattr
*pinfoattr
;
3831 struct sk_buff
*msg
;
3833 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3836 if (!rdev
->ops
->get_mesh_config
)
3840 /* If not connected, get default parameters */
3841 if (!wdev
->mesh_id_len
)
3842 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3844 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
3850 /* Draw up a netlink message to send back */
3851 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3854 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3855 NL80211_CMD_GET_MESH_CONFIG
);
3858 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3860 goto nla_put_failure
;
3861 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3862 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3863 cur_params
.dot11MeshRetryTimeout
) ||
3864 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3865 cur_params
.dot11MeshConfirmTimeout
) ||
3866 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3867 cur_params
.dot11MeshHoldingTimeout
) ||
3868 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3869 cur_params
.dot11MeshMaxPeerLinks
) ||
3870 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3871 cur_params
.dot11MeshMaxRetries
) ||
3872 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
3873 cur_params
.dot11MeshTTL
) ||
3874 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3875 cur_params
.element_ttl
) ||
3876 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3877 cur_params
.auto_open_plinks
) ||
3878 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3879 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
3880 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3881 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
3882 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3883 cur_params
.path_refresh_time
) ||
3884 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3885 cur_params
.min_discovery_timeout
) ||
3886 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3887 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
3888 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3889 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
3890 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3891 cur_params
.dot11MeshHWMPperrMinInterval
) ||
3892 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3893 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
3894 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3895 cur_params
.dot11MeshHWMPRootMode
) ||
3896 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3897 cur_params
.dot11MeshHWMPRannInterval
) ||
3898 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3899 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
3900 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
3901 cur_params
.dot11MeshForwarding
) ||
3902 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3903 cur_params
.rssi_threshold
) ||
3904 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
3905 cur_params
.ht_opmode
) ||
3906 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3907 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
3908 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3909 cur_params
.dot11MeshHWMProotInterval
) ||
3910 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3911 cur_params
.dot11MeshHWMPconfirmationInterval
))
3912 goto nla_put_failure
;
3913 nla_nest_end(msg
, pinfoattr
);
3914 genlmsg_end(msg
, hdr
);
3915 return genlmsg_reply(msg
, info
);
3918 genlmsg_cancel(msg
, hdr
);
3924 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3925 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3926 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3927 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3928 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3929 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3930 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3931 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3932 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3933 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
3934 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3935 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3936 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3937 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3938 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3939 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
3940 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3941 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3942 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3943 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3944 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
3945 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
3946 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
3947 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
3948 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
3949 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
3952 static const struct nla_policy
3953 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3954 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
3955 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3956 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3957 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3958 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3959 .len
= IEEE80211_MAX_DATA_LEN
},
3960 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3963 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3964 struct mesh_config
*cfg
,
3967 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3970 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3972 if (table[attr_num]) {\
3973 cfg->param = nla_fn(table[attr_num]); \
3974 mask |= (1 << (attr_num - 1)); \
3979 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3981 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3982 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3983 nl80211_meshconf_params_policy
))
3986 /* This makes sure that there aren't more than 32 mesh config
3987 * parameters (otherwise our bitfield scheme would not work.) */
3988 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3990 /* Fill in the params struct */
3991 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3992 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3994 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3995 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3997 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3998 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4000 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
4001 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4003 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
4004 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4006 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
4007 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4008 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
4009 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4011 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
4012 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4014 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
, mask
,
4015 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4017 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
4018 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4020 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
4021 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4023 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
4024 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4026 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
, mask
,
4027 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4029 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4030 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4032 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4033 mask
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4035 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4036 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
4037 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4039 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
4040 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
4041 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
4042 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4044 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4045 dot11MeshGateAnnouncementProtocol
, mask
,
4046 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4048 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
,
4049 mask
, NL80211_MESHCONF_FORWARDING
,
4051 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
,
4052 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4054 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
,
4055 mask
, NL80211_MESHCONF_HT_OPMODE
,
4057 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4059 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4061 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
,
4062 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4064 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4065 dot11MeshHWMPconfirmationInterval
, mask
,
4066 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4073 #undef FILL_IN_MESH_PARAM_IF_SET
4076 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4077 struct mesh_setup
*setup
)
4079 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4081 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4083 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4084 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4085 nl80211_mesh_setup_params_policy
))
4088 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4089 setup
->sync_method
=
4090 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4091 IEEE80211_SYNC_METHOD_VENDOR
:
4092 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4094 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4095 setup
->path_sel_proto
=
4096 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4097 IEEE80211_PATH_PROTOCOL_VENDOR
:
4098 IEEE80211_PATH_PROTOCOL_HWMP
;
4100 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4101 setup
->path_metric
=
4102 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4103 IEEE80211_PATH_METRIC_VENDOR
:
4104 IEEE80211_PATH_METRIC_AIRTIME
;
4107 if (tb
[NL80211_MESH_SETUP_IE
]) {
4108 struct nlattr
*ieattr
=
4109 tb
[NL80211_MESH_SETUP_IE
];
4110 if (!is_valid_ie_attr(ieattr
))
4112 setup
->ie
= nla_data(ieattr
);
4113 setup
->ie_len
= nla_len(ieattr
);
4115 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4116 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4121 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4122 struct genl_info
*info
)
4124 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4125 struct net_device
*dev
= info
->user_ptr
[1];
4126 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4127 struct mesh_config cfg
;
4131 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4134 if (!rdev
->ops
->update_mesh_config
)
4137 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4142 if (!wdev
->mesh_id_len
)
4146 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4153 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4155 struct sk_buff
*msg
;
4157 struct nlattr
*nl_reg_rules
;
4161 mutex_lock(&cfg80211_mutex
);
4163 if (!cfg80211_regdomain
)
4166 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4172 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4173 NL80211_CMD_GET_REG
);
4177 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
4178 cfg80211_regdomain
->alpha2
) ||
4179 (cfg80211_regdomain
->dfs_region
&&
4180 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
,
4181 cfg80211_regdomain
->dfs_region
)))
4182 goto nla_put_failure
;
4184 if (reg_last_request_cell_base() &&
4185 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4186 NL80211_USER_REG_HINT_CELL_BASE
))
4187 goto nla_put_failure
;
4189 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4191 goto nla_put_failure
;
4193 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
4194 struct nlattr
*nl_reg_rule
;
4195 const struct ieee80211_reg_rule
*reg_rule
;
4196 const struct ieee80211_freq_range
*freq_range
;
4197 const struct ieee80211_power_rule
*power_rule
;
4199 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
4200 freq_range
= ®_rule
->freq_range
;
4201 power_rule
= ®_rule
->power_rule
;
4203 nl_reg_rule
= nla_nest_start(msg
, i
);
4205 goto nla_put_failure
;
4207 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4209 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4210 freq_range
->start_freq_khz
) ||
4211 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4212 freq_range
->end_freq_khz
) ||
4213 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4214 freq_range
->max_bandwidth_khz
) ||
4215 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4216 power_rule
->max_antenna_gain
) ||
4217 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4218 power_rule
->max_eirp
))
4219 goto nla_put_failure
;
4221 nla_nest_end(msg
, nl_reg_rule
);
4224 nla_nest_end(msg
, nl_reg_rules
);
4226 genlmsg_end(msg
, hdr
);
4227 err
= genlmsg_reply(msg
, info
);
4231 genlmsg_cancel(msg
, hdr
);
4236 mutex_unlock(&cfg80211_mutex
);
4240 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4242 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4243 struct nlattr
*nl_reg_rule
;
4244 char *alpha2
= NULL
;
4245 int rem_reg_rules
= 0, r
= 0;
4246 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4248 struct ieee80211_regdomain
*rd
= NULL
;
4250 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4253 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
4256 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4258 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
4259 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
4261 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4264 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
4268 mutex_lock(&cfg80211_mutex
);
4270 if (!reg_is_valid_request(alpha2
)) {
4275 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
4276 (num_rules
* sizeof(struct ieee80211_reg_rule
));
4278 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
4284 rd
->n_reg_rules
= num_rules
;
4285 rd
->alpha2
[0] = alpha2
[0];
4286 rd
->alpha2
[1] = alpha2
[1];
4289 * Disable DFS master mode if the DFS region was
4290 * not supported or known on this kernel.
4292 if (reg_supported_dfs_region(dfs_region
))
4293 rd
->dfs_region
= dfs_region
;
4295 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4297 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
4298 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
4300 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
4306 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
4312 BUG_ON(rule_idx
!= num_rules
);
4316 mutex_unlock(&cfg80211_mutex
);
4321 mutex_unlock(&cfg80211_mutex
);
4326 static int validate_scan_freqs(struct nlattr
*freqs
)
4328 struct nlattr
*attr1
, *attr2
;
4329 int n_channels
= 0, tmp1
, tmp2
;
4331 nla_for_each_nested(attr1
, freqs
, tmp1
) {
4334 * Some hardware has a limited channel list for
4335 * scanning, and it is pretty much nonsensical
4336 * to scan for a channel twice, so disallow that
4337 * and don't require drivers to check that the
4338 * channel list they get isn't longer than what
4339 * they can scan, as long as they can scan all
4340 * the channels they registered at once.
4342 nla_for_each_nested(attr2
, freqs
, tmp2
)
4343 if (attr1
!= attr2
&&
4344 nla_get_u32(attr1
) == nla_get_u32(attr2
))
4351 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
4353 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4354 struct wireless_dev
*wdev
= info
->user_ptr
[1];
4355 struct cfg80211_scan_request
*request
;
4356 struct nlattr
*attr
;
4357 struct wiphy
*wiphy
;
4358 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
4361 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4364 wiphy
= &rdev
->wiphy
;
4366 if (!rdev
->ops
->scan
)
4372 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4373 n_channels
= validate_scan_freqs(
4374 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4378 enum ieee80211_band band
;
4381 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4382 if (wiphy
->bands
[band
])
4383 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4386 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4387 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
4390 if (n_ssids
> wiphy
->max_scan_ssids
)
4393 if (info
->attrs
[NL80211_ATTR_IE
])
4394 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4398 if (ie_len
> wiphy
->max_scan_ie_len
)
4401 request
= kzalloc(sizeof(*request
)
4402 + sizeof(*request
->ssids
) * n_ssids
4403 + sizeof(*request
->channels
) * n_channels
4404 + ie_len
, GFP_KERNEL
);
4409 request
->ssids
= (void *)&request
->channels
[n_channels
];
4410 request
->n_ssids
= n_ssids
;
4413 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4415 request
->ie
= (void *)(request
->channels
+ n_channels
);
4419 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4420 /* user specified, bail out if channel not found */
4421 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
4422 struct ieee80211_channel
*chan
;
4424 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4431 /* ignore disabled channels */
4432 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4435 request
->channels
[i
] = chan
;
4439 enum ieee80211_band band
;
4442 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4444 if (!wiphy
->bands
[band
])
4446 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4447 struct ieee80211_channel
*chan
;
4449 chan
= &wiphy
->bands
[band
]->channels
[j
];
4451 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4454 request
->channels
[i
] = chan
;
4465 request
->n_channels
= i
;
4468 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4469 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
4470 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4474 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4475 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
4480 if (info
->attrs
[NL80211_ATTR_IE
]) {
4481 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4482 memcpy((void *)request
->ie
,
4483 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4487 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4488 if (wiphy
->bands
[i
])
4490 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
4492 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
4493 nla_for_each_nested(attr
,
4494 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
4496 enum ieee80211_band band
= nla_type(attr
);
4498 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4502 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
4505 &request
->rates
[band
]);
4511 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
4512 request
->flags
= nla_get_u32(
4513 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
4514 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
4515 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
4516 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
4517 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
4524 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
4526 request
->wdev
= wdev
;
4527 request
->wiphy
= &rdev
->wiphy
;
4528 request
->scan_start
= jiffies
;
4530 rdev
->scan_req
= request
;
4531 err
= rdev_scan(rdev
, request
);
4534 nl80211_send_scan_start(rdev
, wdev
);
4536 dev_hold(wdev
->netdev
);
4539 rdev
->scan_req
= NULL
;
4546 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
4547 struct genl_info
*info
)
4549 struct cfg80211_sched_scan_request
*request
;
4550 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4551 struct net_device
*dev
= info
->user_ptr
[1];
4552 struct nlattr
*attr
;
4553 struct wiphy
*wiphy
;
4554 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
4556 enum ieee80211_band band
;
4558 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
4560 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4561 !rdev
->ops
->sched_scan_start
)
4564 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4567 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
4570 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
4574 wiphy
= &rdev
->wiphy
;
4576 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4577 n_channels
= validate_scan_freqs(
4578 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4584 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4585 if (wiphy
->bands
[band
])
4586 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4589 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4590 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4594 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
4597 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
4598 nla_for_each_nested(attr
,
4599 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4603 if (n_match_sets
> wiphy
->max_match_sets
)
4606 if (info
->attrs
[NL80211_ATTR_IE
])
4607 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4611 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
4614 mutex_lock(&rdev
->sched_scan_mtx
);
4616 if (rdev
->sched_scan_req
) {
4621 request
= kzalloc(sizeof(*request
)
4622 + sizeof(*request
->ssids
) * n_ssids
4623 + sizeof(*request
->match_sets
) * n_match_sets
4624 + sizeof(*request
->channels
) * n_channels
4625 + ie_len
, GFP_KERNEL
);
4632 request
->ssids
= (void *)&request
->channels
[n_channels
];
4633 request
->n_ssids
= n_ssids
;
4636 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4638 request
->ie
= (void *)(request
->channels
+ n_channels
);
4643 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
4644 else if (request
->ssids
)
4645 request
->match_sets
=
4646 (void *)(request
->ssids
+ n_ssids
);
4648 request
->match_sets
=
4649 (void *)(request
->channels
+ n_channels
);
4651 request
->n_match_sets
= n_match_sets
;
4654 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4655 /* user specified, bail out if channel not found */
4656 nla_for_each_nested(attr
,
4657 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
4659 struct ieee80211_channel
*chan
;
4661 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4668 /* ignore disabled channels */
4669 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4672 request
->channels
[i
] = chan
;
4677 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4679 if (!wiphy
->bands
[band
])
4681 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4682 struct ieee80211_channel
*chan
;
4684 chan
= &wiphy
->bands
[band
]->channels
[j
];
4686 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4689 request
->channels
[i
] = chan
;
4700 request
->n_channels
= i
;
4703 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4704 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4706 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4710 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4711 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
4718 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
4719 nla_for_each_nested(attr
,
4720 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4722 struct nlattr
*ssid
, *rssi
;
4724 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
4725 nla_data(attr
), nla_len(attr
),
4726 nl80211_match_policy
);
4727 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
4729 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
4733 memcpy(request
->match_sets
[i
].ssid
.ssid
,
4734 nla_data(ssid
), nla_len(ssid
));
4735 request
->match_sets
[i
].ssid
.ssid_len
=
4738 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
4740 request
->rssi_thold
= nla_get_u32(rssi
);
4742 request
->rssi_thold
=
4743 NL80211_SCAN_RSSI_THOLD_OFF
;
4748 if (info
->attrs
[NL80211_ATTR_IE
]) {
4749 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4750 memcpy((void *)request
->ie
,
4751 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4755 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
4756 request
->flags
= nla_get_u32(
4757 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
4758 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
4759 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
4760 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
4761 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
4768 request
->wiphy
= &rdev
->wiphy
;
4769 request
->interval
= interval
;
4770 request
->scan_start
= jiffies
;
4772 err
= rdev_sched_scan_start(rdev
, dev
, request
);
4774 rdev
->sched_scan_req
= request
;
4775 nl80211_send_sched_scan(rdev
, dev
,
4776 NL80211_CMD_START_SCHED_SCAN
);
4783 mutex_unlock(&rdev
->sched_scan_mtx
);
4787 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
4788 struct genl_info
*info
)
4790 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4793 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4794 !rdev
->ops
->sched_scan_stop
)
4797 mutex_lock(&rdev
->sched_scan_mtx
);
4798 err
= __cfg80211_stop_sched_scan(rdev
, false);
4799 mutex_unlock(&rdev
->sched_scan_mtx
);
4804 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
4806 struct cfg80211_registered_device
*rdev
,
4807 struct wireless_dev
*wdev
,
4808 struct cfg80211_internal_bss
*intbss
)
4810 struct cfg80211_bss
*res
= &intbss
->pub
;
4811 const struct cfg80211_bss_ies
*ies
;
4815 ASSERT_WDEV_LOCK(wdev
);
4817 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
4818 NL80211_CMD_NEW_SCAN_RESULTS
);
4822 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
4824 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
) ||
4825 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
4826 goto nla_put_failure
;
4828 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
4830 goto nla_put_failure
;
4831 if ((!is_zero_ether_addr(res
->bssid
) &&
4832 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
4833 goto nla_put_failure
;
4836 ies
= rcu_dereference(res
->ies
);
4837 if (ies
&& ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
4838 ies
->len
, ies
->data
)) {
4840 goto nla_put_failure
;
4842 ies
= rcu_dereference(res
->beacon_ies
);
4843 if (ies
&& ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
4844 ies
->len
, ies
->data
)) {
4846 goto nla_put_failure
;
4851 nla_put_u64(msg
, NL80211_BSS_TSF
, res
->tsf
))
4852 goto nla_put_failure
;
4853 if (res
->beacon_interval
&&
4854 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
4855 goto nla_put_failure
;
4856 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
4857 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
4858 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
4859 jiffies_to_msecs(jiffies
- intbss
->ts
)))
4860 goto nla_put_failure
;
4862 switch (rdev
->wiphy
.signal_type
) {
4863 case CFG80211_SIGNAL_TYPE_MBM
:
4864 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
4865 goto nla_put_failure
;
4867 case CFG80211_SIGNAL_TYPE_UNSPEC
:
4868 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
4869 goto nla_put_failure
;
4875 switch (wdev
->iftype
) {
4876 case NL80211_IFTYPE_P2P_CLIENT
:
4877 case NL80211_IFTYPE_STATION
:
4878 if (intbss
== wdev
->current_bss
&&
4879 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4880 NL80211_BSS_STATUS_ASSOCIATED
))
4881 goto nla_put_failure
;
4883 case NL80211_IFTYPE_ADHOC
:
4884 if (intbss
== wdev
->current_bss
&&
4885 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4886 NL80211_BSS_STATUS_IBSS_JOINED
))
4887 goto nla_put_failure
;
4893 nla_nest_end(msg
, bss
);
4895 return genlmsg_end(msg
, hdr
);
4898 genlmsg_cancel(msg
, hdr
);
4902 static int nl80211_dump_scan(struct sk_buff
*skb
,
4903 struct netlink_callback
*cb
)
4905 struct cfg80211_registered_device
*rdev
;
4906 struct net_device
*dev
;
4907 struct cfg80211_internal_bss
*scan
;
4908 struct wireless_dev
*wdev
;
4909 int start
= cb
->args
[1], idx
= 0;
4912 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4916 wdev
= dev
->ieee80211_ptr
;
4919 spin_lock_bh(&rdev
->bss_lock
);
4920 cfg80211_bss_expire(rdev
);
4922 cb
->seq
= rdev
->bss_generation
;
4924 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4927 if (nl80211_send_bss(skb
, cb
,
4928 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4929 rdev
, wdev
, scan
) < 0) {
4935 spin_unlock_bh(&rdev
->bss_lock
);
4939 nl80211_finish_netdev_dump(rdev
);
4944 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4945 int flags
, struct net_device
*dev
,
4946 struct survey_info
*survey
)
4949 struct nlattr
*infoattr
;
4951 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
4952 NL80211_CMD_NEW_SURVEY_RESULTS
);
4956 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
4957 goto nla_put_failure
;
4959 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4961 goto nla_put_failure
;
4963 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4964 survey
->channel
->center_freq
))
4965 goto nla_put_failure
;
4967 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
4968 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
4969 goto nla_put_failure
;
4970 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
4971 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
4972 goto nla_put_failure
;
4973 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
4974 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4975 survey
->channel_time
))
4976 goto nla_put_failure
;
4977 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
4978 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4979 survey
->channel_time_busy
))
4980 goto nla_put_failure
;
4981 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
4982 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4983 survey
->channel_time_ext_busy
))
4984 goto nla_put_failure
;
4985 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
4986 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4987 survey
->channel_time_rx
))
4988 goto nla_put_failure
;
4989 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
4990 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4991 survey
->channel_time_tx
))
4992 goto nla_put_failure
;
4994 nla_nest_end(msg
, infoattr
);
4996 return genlmsg_end(msg
, hdr
);
4999 genlmsg_cancel(msg
, hdr
);
5003 static int nl80211_dump_survey(struct sk_buff
*skb
,
5004 struct netlink_callback
*cb
)
5006 struct survey_info survey
;
5007 struct cfg80211_registered_device
*dev
;
5008 struct net_device
*netdev
;
5009 int survey_idx
= cb
->args
[1];
5012 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
5016 if (!dev
->ops
->dump_survey
) {
5022 struct ieee80211_channel
*chan
;
5024 res
= rdev_dump_survey(dev
, netdev
, survey_idx
, &survey
);
5030 /* Survey without a channel doesn't make sense */
5031 if (!survey
.channel
) {
5036 chan
= ieee80211_get_channel(&dev
->wiphy
,
5037 survey
.channel
->center_freq
);
5038 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5043 if (nl80211_send_survey(skb
,
5044 NETLINK_CB(cb
->skb
).portid
,
5045 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5053 cb
->args
[1] = survey_idx
;
5056 nl80211_finish_netdev_dump(dev
);
5060 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5062 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5063 NL80211_WPA_VERSION_2
));
5066 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5068 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5069 struct net_device
*dev
= info
->user_ptr
[1];
5070 struct ieee80211_channel
*chan
;
5071 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5072 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5073 enum nl80211_auth_type auth_type
;
5074 struct key_parse key
;
5075 bool local_state_change
;
5077 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5080 if (!info
->attrs
[NL80211_ATTR_MAC
])
5083 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5086 if (!info
->attrs
[NL80211_ATTR_SSID
])
5089 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5092 err
= nl80211_parse_key(info
, &key
);
5097 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5099 if (!key
.p
.key
|| !key
.p
.key_len
)
5101 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5102 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5103 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5104 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5116 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5117 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5126 if (!rdev
->ops
->auth
)
5129 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5130 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5133 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5134 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5135 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5136 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5139 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5140 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5142 if (info
->attrs
[NL80211_ATTR_IE
]) {
5143 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5144 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5147 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5148 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5151 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5152 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5155 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5156 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5158 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5159 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5160 /* need to include at least Auth Transaction and Status Code */
5161 if (sae_data_len
< 4)
5165 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5168 * Since we no longer track auth state, ignore
5169 * requests to only change local state.
5171 if (local_state_change
)
5174 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5175 ssid
, ssid_len
, ie
, ie_len
,
5176 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5177 sae_data
, sae_data_len
);
5180 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5181 struct genl_info
*info
,
5182 struct cfg80211_crypto_settings
*settings
,
5185 memset(settings
, 0, sizeof(*settings
));
5187 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5189 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5191 proto
= nla_get_u16(
5192 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5193 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5194 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5197 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5198 settings
->control_port_no_encrypt
= true;
5200 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5202 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5206 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5207 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5208 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
5210 if (len
% sizeof(u32
))
5213 if (settings
->n_ciphers_pairwise
> cipher_limit
)
5216 memcpy(settings
->ciphers_pairwise
, data
, len
);
5218 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
5219 if (!cfg80211_supported_cipher_suite(
5221 settings
->ciphers_pairwise
[i
]))
5225 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
5226 settings
->cipher_group
=
5227 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
5228 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
5229 settings
->cipher_group
))
5233 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
5234 settings
->wpa_versions
=
5235 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
5236 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
5240 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
5244 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5245 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5246 settings
->n_akm_suites
= len
/ sizeof(u32
);
5248 if (len
% sizeof(u32
))
5251 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
5254 memcpy(settings
->akm_suites
, data
, len
);
5260 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
5262 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5263 struct net_device
*dev
= info
->user_ptr
[1];
5264 struct cfg80211_crypto_settings crypto
;
5265 struct ieee80211_channel
*chan
;
5266 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
5267 int err
, ssid_len
, ie_len
= 0;
5268 bool use_mfp
= false;
5270 struct ieee80211_ht_cap
*ht_capa
= NULL
;
5271 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
5273 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5276 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
5277 !info
->attrs
[NL80211_ATTR_SSID
] ||
5278 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5281 if (!rdev
->ops
->assoc
)
5284 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5285 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5288 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5290 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5291 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5292 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5295 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5296 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5298 if (info
->attrs
[NL80211_ATTR_IE
]) {
5299 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5300 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5303 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
5304 enum nl80211_mfp mfp
=
5305 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
5306 if (mfp
== NL80211_MFP_REQUIRED
)
5308 else if (mfp
!= NL80211_MFP_NO
)
5312 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
5313 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
5315 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5316 flags
|= ASSOC_REQ_DISABLE_HT
;
5318 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5320 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
5322 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5325 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5328 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
5330 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
5331 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
5332 &crypto
, flags
, ht_capa
,
5338 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5340 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5341 struct net_device
*dev
= info
->user_ptr
[1];
5342 const u8
*ie
= NULL
, *bssid
;
5345 bool local_state_change
;
5347 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5350 if (!info
->attrs
[NL80211_ATTR_MAC
])
5353 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5356 if (!rdev
->ops
->deauth
)
5359 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5360 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5363 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5365 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5366 if (reason_code
== 0) {
5367 /* Reason Code 0 is reserved */
5371 if (info
->attrs
[NL80211_ATTR_IE
]) {
5372 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5373 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5376 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5378 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5379 local_state_change
);
5382 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
5384 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5385 struct net_device
*dev
= info
->user_ptr
[1];
5386 const u8
*ie
= NULL
, *bssid
;
5389 bool local_state_change
;
5391 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5394 if (!info
->attrs
[NL80211_ATTR_MAC
])
5397 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5400 if (!rdev
->ops
->disassoc
)
5403 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5404 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5407 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5409 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5410 if (reason_code
== 0) {
5411 /* Reason Code 0 is reserved */
5415 if (info
->attrs
[NL80211_ATTR_IE
]) {
5416 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5417 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5420 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5422 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5423 local_state_change
);
5427 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
5428 int mcast_rate
[IEEE80211_NUM_BANDS
],
5431 struct wiphy
*wiphy
= &rdev
->wiphy
;
5435 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5436 struct ieee80211_supported_band
*sband
;
5438 sband
= wiphy
->bands
[band
];
5442 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
5443 if (sband
->bitrates
[i
].bitrate
== rateval
) {
5444 mcast_rate
[band
] = i
+ 1;
5454 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5456 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5457 struct net_device
*dev
= info
->user_ptr
[1];
5458 struct cfg80211_ibss_params ibss
;
5459 struct wiphy
*wiphy
;
5460 struct cfg80211_cached_keys
*connkeys
= NULL
;
5463 memset(&ibss
, 0, sizeof(ibss
));
5465 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5468 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5469 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5472 ibss
.beacon_interval
= 100;
5474 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
5475 ibss
.beacon_interval
=
5476 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5477 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
5481 if (!rdev
->ops
->join_ibss
)
5484 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5487 wiphy
= &rdev
->wiphy
;
5489 if (info
->attrs
[NL80211_ATTR_MAC
]) {
5490 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5492 if (!is_valid_ether_addr(ibss
.bssid
))
5495 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5496 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5498 if (info
->attrs
[NL80211_ATTR_IE
]) {
5499 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5500 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5503 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
5507 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
5510 if (ibss
.chandef
.width
> NL80211_CHAN_WIDTH_40
)
5512 if (ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
5513 !(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
5516 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
5517 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5519 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5521 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5523 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5524 struct ieee80211_supported_band
*sband
=
5525 wiphy
->bands
[ibss
.chandef
.chan
->band
];
5527 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
5533 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5534 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
5535 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5538 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5541 connkeys
= nl80211_parse_connkeys(rdev
,
5542 info
->attrs
[NL80211_ATTR_KEYS
],
5544 if (IS_ERR(connkeys
))
5545 return PTR_ERR(connkeys
);
5547 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
5555 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
5557 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
5563 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5565 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5566 struct net_device
*dev
= info
->user_ptr
[1];
5568 if (!rdev
->ops
->leave_ibss
)
5571 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5574 return cfg80211_leave_ibss(rdev
, dev
, false);
5577 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
5579 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5580 struct net_device
*dev
= info
->user_ptr
[1];
5581 int mcast_rate
[IEEE80211_NUM_BANDS
];
5585 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5586 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5589 if (!rdev
->ops
->set_mcast_rate
)
5592 memset(mcast_rate
, 0, sizeof(mcast_rate
));
5594 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
5597 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
5598 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
5601 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
5607 #ifdef CONFIG_NL80211_TESTMODE
5608 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
5612 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
5614 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5617 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
5621 if (rdev
->ops
->testmode_cmd
) {
5622 rdev
->testmode_info
= info
;
5623 err
= rdev_testmode_cmd(rdev
,
5624 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
5625 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
5626 rdev
->testmode_info
= NULL
;
5632 static int nl80211_testmode_dump(struct sk_buff
*skb
,
5633 struct netlink_callback
*cb
)
5635 struct cfg80211_registered_device
*rdev
;
5643 * 0 is a valid index, but not valid for args[0],
5644 * so we need to offset by 1.
5646 phy_idx
= cb
->args
[0] - 1;
5648 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
5649 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
5654 mutex_lock(&cfg80211_mutex
);
5655 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
5656 nl80211_fam
.attrbuf
);
5658 mutex_unlock(&cfg80211_mutex
);
5659 return PTR_ERR(rdev
);
5661 phy_idx
= rdev
->wiphy_idx
;
5663 mutex_unlock(&cfg80211_mutex
);
5665 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
5667 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
5671 data
= nla_data((void *)cb
->args
[1]);
5672 data_len
= nla_len((void *)cb
->args
[1]);
5675 mutex_lock(&cfg80211_mutex
);
5676 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
5678 mutex_unlock(&cfg80211_mutex
);
5681 cfg80211_lock_rdev(rdev
);
5682 mutex_unlock(&cfg80211_mutex
);
5684 if (!rdev
->ops
->testmode_dump
) {
5690 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
5691 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5692 NL80211_CMD_TESTMODE
);
5693 struct nlattr
*tmdata
;
5695 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
5696 genlmsg_cancel(skb
, hdr
);
5700 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5702 genlmsg_cancel(skb
, hdr
);
5705 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
5706 nla_nest_end(skb
, tmdata
);
5708 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
5709 genlmsg_cancel(skb
, hdr
);
5712 genlmsg_cancel(skb
, hdr
);
5716 genlmsg_end(skb
, hdr
);
5721 cb
->args
[0] = phy_idx
+ 1;
5723 cfg80211_unlock_rdev(rdev
);
5727 static struct sk_buff
*
5728 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
5729 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
5731 struct sk_buff
*skb
;
5733 struct nlattr
*data
;
5735 skb
= nlmsg_new(approxlen
+ 100, gfp
);
5739 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
5745 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
5746 goto nla_put_failure
;
5747 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5749 ((void **)skb
->cb
)[0] = rdev
;
5750 ((void **)skb
->cb
)[1] = hdr
;
5751 ((void **)skb
->cb
)[2] = data
;
5760 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
5763 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5765 if (WARN_ON(!rdev
->testmode_info
))
5768 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
5769 rdev
->testmode_info
->snd_portid
,
5770 rdev
->testmode_info
->snd_seq
,
5773 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
5775 int cfg80211_testmode_reply(struct sk_buff
*skb
)
5777 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
5778 void *hdr
= ((void **)skb
->cb
)[1];
5779 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5781 if (WARN_ON(!rdev
->testmode_info
)) {
5786 nla_nest_end(skb
, data
);
5787 genlmsg_end(skb
, hdr
);
5788 return genlmsg_reply(skb
, rdev
->testmode_info
);
5790 EXPORT_SYMBOL(cfg80211_testmode_reply
);
5792 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
5793 int approxlen
, gfp_t gfp
)
5795 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5797 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
5799 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
5801 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
5803 void *hdr
= ((void **)skb
->cb
)[1];
5804 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5806 nla_nest_end(skb
, data
);
5807 genlmsg_end(skb
, hdr
);
5808 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
5810 EXPORT_SYMBOL(cfg80211_testmode_event
);
5813 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
5815 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5816 struct net_device
*dev
= info
->user_ptr
[1];
5817 struct cfg80211_connect_params connect
;
5818 struct wiphy
*wiphy
;
5819 struct cfg80211_cached_keys
*connkeys
= NULL
;
5822 memset(&connect
, 0, sizeof(connect
));
5824 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5827 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5828 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5831 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5833 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5834 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
5835 NL80211_CMD_CONNECT
))
5838 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5840 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
5842 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
5843 NL80211_MAX_NR_CIPHER_SUITES
);
5847 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5848 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5851 wiphy
= &rdev
->wiphy
;
5853 connect
.bg_scan_period
= -1;
5854 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
5855 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
5856 connect
.bg_scan_period
=
5857 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
5860 if (info
->attrs
[NL80211_ATTR_MAC
])
5861 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5862 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5863 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5865 if (info
->attrs
[NL80211_ATTR_IE
]) {
5866 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5867 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5870 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5872 ieee80211_get_channel(wiphy
,
5873 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5874 if (!connect
.channel
||
5875 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5879 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5880 connkeys
= nl80211_parse_connkeys(rdev
,
5881 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
5882 if (IS_ERR(connkeys
))
5883 return PTR_ERR(connkeys
);
5886 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5887 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
5889 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5890 memcpy(&connect
.ht_capa_mask
,
5891 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
5892 sizeof(connect
.ht_capa_mask
));
5894 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5895 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
5899 memcpy(&connect
.ht_capa
,
5900 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
5901 sizeof(connect
.ht_capa
));
5904 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
5910 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
5912 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5913 struct net_device
*dev
= info
->user_ptr
[1];
5916 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5917 reason
= WLAN_REASON_DEAUTH_LEAVING
;
5919 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5924 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5925 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5928 return cfg80211_disconnect(rdev
, dev
, reason
, true);
5931 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
5933 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5938 if (!info
->attrs
[NL80211_ATTR_PID
])
5941 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
5943 net
= get_net_ns_by_pid(pid
);
5945 return PTR_ERR(net
);
5949 /* check if anything to do */
5950 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
5951 err
= cfg80211_switch_netns(rdev
, net
);
5957 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5959 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5960 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
5961 struct cfg80211_pmksa
*pmksa
) = NULL
;
5962 struct net_device
*dev
= info
->user_ptr
[1];
5963 struct cfg80211_pmksa pmksa
;
5965 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
5967 if (!info
->attrs
[NL80211_ATTR_MAC
])
5970 if (!info
->attrs
[NL80211_ATTR_PMKID
])
5973 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
5974 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5976 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5977 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5980 switch (info
->genlhdr
->cmd
) {
5981 case NL80211_CMD_SET_PMKSA
:
5982 rdev_ops
= rdev
->ops
->set_pmksa
;
5984 case NL80211_CMD_DEL_PMKSA
:
5985 rdev_ops
= rdev
->ops
->del_pmksa
;
5995 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
5998 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6000 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6001 struct net_device
*dev
= info
->user_ptr
[1];
6003 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6004 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6007 if (!rdev
->ops
->flush_pmksa
)
6010 return rdev_flush_pmksa(rdev
, dev
);
6013 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6015 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6016 struct net_device
*dev
= info
->user_ptr
[1];
6017 u8 action_code
, dialog_token
;
6021 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6022 !rdev
->ops
->tdls_mgmt
)
6025 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6026 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6027 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6028 !info
->attrs
[NL80211_ATTR_IE
] ||
6029 !info
->attrs
[NL80211_ATTR_MAC
])
6032 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6033 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6034 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6035 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6037 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6038 dialog_token
, status_code
,
6039 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6040 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6043 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6045 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6046 struct net_device
*dev
= info
->user_ptr
[1];
6047 enum nl80211_tdls_operation operation
;
6050 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6051 !rdev
->ops
->tdls_oper
)
6054 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6055 !info
->attrs
[NL80211_ATTR_MAC
])
6058 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6059 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6061 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6064 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6065 struct genl_info
*info
)
6067 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6068 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6069 struct cfg80211_chan_def chandef
;
6070 struct sk_buff
*msg
;
6076 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6077 !info
->attrs
[NL80211_ATTR_DURATION
])
6080 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6082 if (!rdev
->ops
->remain_on_channel
||
6083 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6087 * We should be on that channel for at least a minimum amount of
6088 * time (10ms) but no longer than the driver supports.
6090 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6091 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6094 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6098 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6102 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6103 NL80211_CMD_REMAIN_ON_CHANNEL
);
6110 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6116 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6117 goto nla_put_failure
;
6119 genlmsg_end(msg
, hdr
);
6121 return genlmsg_reply(msg
, info
);
6130 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
6131 struct genl_info
*info
)
6133 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6134 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6137 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6140 if (!rdev
->ops
->cancel_remain_on_channel
)
6143 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6145 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
6148 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
6149 u8
*rates
, u8 rates_len
)
6154 for (i
= 0; i
< rates_len
; i
++) {
6155 int rate
= (rates
[i
] & 0x7f) * 5;
6157 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
6158 struct ieee80211_rate
*srate
=
6159 &sband
->bitrates
[ridx
];
6160 if (rate
== srate
->bitrate
) {
6165 if (ridx
== sband
->n_bitrates
)
6166 return 0; /* rate not found */
6172 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
6173 u8
*rates
, u8 rates_len
,
6174 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
6178 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
6180 for (i
= 0; i
< rates_len
; i
++) {
6183 ridx
= rates
[i
] / 8;
6184 rbit
= BIT(rates
[i
] % 8);
6186 /* check validity */
6187 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
6190 /* check availability */
6191 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
6200 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
6201 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
6202 .len
= NL80211_MAX_SUPP_RATES
},
6203 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
6204 .len
= NL80211_MAX_SUPP_HT_RATES
},
6207 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
6208 struct genl_info
*info
)
6210 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
6211 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6212 struct cfg80211_bitrate_mask mask
;
6214 struct net_device
*dev
= info
->user_ptr
[1];
6215 struct nlattr
*tx_rates
;
6216 struct ieee80211_supported_band
*sband
;
6218 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
6221 if (!rdev
->ops
->set_bitrate_mask
)
6224 memset(&mask
, 0, sizeof(mask
));
6225 /* Default to all rates enabled */
6226 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
6227 sband
= rdev
->wiphy
.bands
[i
];
6228 mask
.control
[i
].legacy
=
6229 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
6231 memcpy(mask
.control
[i
].mcs
,
6232 sband
->ht_cap
.mcs
.rx_mask
,
6233 sizeof(mask
.control
[i
].mcs
));
6235 memset(mask
.control
[i
].mcs
, 0,
6236 sizeof(mask
.control
[i
].mcs
));
6240 * The nested attribute uses enum nl80211_band as the index. This maps
6241 * directly to the enum ieee80211_band values used in cfg80211.
6243 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
6244 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
6246 enum ieee80211_band band
= nla_type(tx_rates
);
6247 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
6249 sband
= rdev
->wiphy
.bands
[band
];
6252 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
6253 nla_len(tx_rates
), nl80211_txattr_policy
);
6254 if (tb
[NL80211_TXRATE_LEGACY
]) {
6255 mask
.control
[band
].legacy
= rateset_to_mask(
6257 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
6258 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
6259 if ((mask
.control
[band
].legacy
== 0) &&
6260 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
6263 if (tb
[NL80211_TXRATE_MCS
]) {
6264 if (!ht_rateset_to_mask(
6266 nla_data(tb
[NL80211_TXRATE_MCS
]),
6267 nla_len(tb
[NL80211_TXRATE_MCS
]),
6268 mask
.control
[band
].mcs
))
6272 if (mask
.control
[band
].legacy
== 0) {
6273 /* don't allow empty legacy rates if HT
6274 * is not even supported. */
6275 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
6278 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
6279 if (mask
.control
[band
].mcs
[i
])
6282 /* legacy and mcs rates may not be both empty */
6283 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
6288 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
6291 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6293 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6294 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6295 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
6297 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
6300 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
6301 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
6303 switch (wdev
->iftype
) {
6304 case NL80211_IFTYPE_STATION
:
6305 case NL80211_IFTYPE_ADHOC
:
6306 case NL80211_IFTYPE_P2P_CLIENT
:
6307 case NL80211_IFTYPE_AP
:
6308 case NL80211_IFTYPE_AP_VLAN
:
6309 case NL80211_IFTYPE_MESH_POINT
:
6310 case NL80211_IFTYPE_P2P_GO
:
6311 case NL80211_IFTYPE_P2P_DEVICE
:
6317 /* not much point in registering if we can't reply */
6318 if (!rdev
->ops
->mgmt_tx
)
6321 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
6322 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
6323 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
6326 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6328 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6329 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6330 struct cfg80211_chan_def chandef
;
6334 struct sk_buff
*msg
= NULL
;
6335 unsigned int wait
= 0;
6336 bool offchan
, no_cck
, dont_wait_for_ack
;
6338 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
6340 if (!info
->attrs
[NL80211_ATTR_FRAME
])
6343 if (!rdev
->ops
->mgmt_tx
)
6346 switch (wdev
->iftype
) {
6347 case NL80211_IFTYPE_STATION
:
6348 case NL80211_IFTYPE_ADHOC
:
6349 case NL80211_IFTYPE_P2P_CLIENT
:
6350 case NL80211_IFTYPE_AP
:
6351 case NL80211_IFTYPE_AP_VLAN
:
6352 case NL80211_IFTYPE_MESH_POINT
:
6353 case NL80211_IFTYPE_P2P_GO
:
6354 case NL80211_IFTYPE_P2P_DEVICE
:
6360 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
6361 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6363 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6366 * We should wait on the channel for at least a minimum amount
6367 * of time (10ms) but no longer than the driver supports.
6369 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6370 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
6375 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
6377 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6380 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6382 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6386 if (!dont_wait_for_ack
) {
6387 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6391 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6400 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
6401 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
6402 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
6403 no_cck
, dont_wait_for_ack
, &cookie
);
6408 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6409 goto nla_put_failure
;
6411 genlmsg_end(msg
, hdr
);
6412 return genlmsg_reply(msg
, info
);
6424 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
6426 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6427 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6430 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6433 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
6436 switch (wdev
->iftype
) {
6437 case NL80211_IFTYPE_STATION
:
6438 case NL80211_IFTYPE_ADHOC
:
6439 case NL80211_IFTYPE_P2P_CLIENT
:
6440 case NL80211_IFTYPE_AP
:
6441 case NL80211_IFTYPE_AP_VLAN
:
6442 case NL80211_IFTYPE_P2P_GO
:
6443 case NL80211_IFTYPE_P2P_DEVICE
:
6449 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6451 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
6454 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6456 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6457 struct wireless_dev
*wdev
;
6458 struct net_device
*dev
= info
->user_ptr
[1];
6463 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
6466 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
6468 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
6471 wdev
= dev
->ieee80211_ptr
;
6473 if (!rdev
->ops
->set_power_mgmt
)
6476 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
6478 if (state
== wdev
->ps
)
6481 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
6487 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6489 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6490 enum nl80211_ps_state ps_state
;
6491 struct wireless_dev
*wdev
;
6492 struct net_device
*dev
= info
->user_ptr
[1];
6493 struct sk_buff
*msg
;
6497 wdev
= dev
->ieee80211_ptr
;
6499 if (!rdev
->ops
->set_power_mgmt
)
6502 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6506 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6507 NL80211_CMD_GET_POWER_SAVE
);
6514 ps_state
= NL80211_PS_ENABLED
;
6516 ps_state
= NL80211_PS_DISABLED
;
6518 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
6519 goto nla_put_failure
;
6521 genlmsg_end(msg
, hdr
);
6522 return genlmsg_reply(msg
, info
);
6531 static struct nla_policy
6532 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
6533 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
6534 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
6535 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
6536 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
6537 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
6538 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
6541 static int nl80211_set_cqm_txe(struct genl_info
*info
,
6542 u32 rate
, u32 pkts
, u32 intvl
)
6544 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6545 struct wireless_dev
*wdev
;
6546 struct net_device
*dev
= info
->user_ptr
[1];
6548 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
6551 wdev
= dev
->ieee80211_ptr
;
6553 if (!rdev
->ops
->set_cqm_txe_config
)
6556 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6557 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6560 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
6563 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
6564 s32 threshold
, u32 hysteresis
)
6566 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6567 struct wireless_dev
*wdev
;
6568 struct net_device
*dev
= info
->user_ptr
[1];
6573 wdev
= dev
->ieee80211_ptr
;
6575 if (!rdev
->ops
->set_cqm_rssi_config
)
6578 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6579 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6582 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
6585 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
6587 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
6591 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
6597 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
6598 nl80211_attr_cqm_policy
);
6602 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
6603 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
6606 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
6607 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
6608 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
6609 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
6610 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
6611 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
6612 u32 rate
, pkts
, intvl
;
6613 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
6614 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
6615 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
6616 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
6624 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6626 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6627 struct net_device
*dev
= info
->user_ptr
[1];
6628 struct mesh_config cfg
;
6629 struct mesh_setup setup
;
6632 /* start with default */
6633 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
6634 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
6636 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
6637 /* and parse parameters if given */
6638 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
6643 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
6644 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
6647 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6648 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6650 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6651 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
6652 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6655 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
6656 /* parse additional setup parameters if given */
6657 err
= nl80211_parse_mesh_setup(info
, &setup
);
6662 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6663 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
6667 /* cfg80211_join_mesh() will sort it out */
6668 setup
.chandef
.chan
= NULL
;
6671 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
6674 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6676 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6677 struct net_device
*dev
= info
->user_ptr
[1];
6679 return cfg80211_leave_mesh(rdev
, dev
);
6683 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6685 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6686 struct sk_buff
*msg
;
6689 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6692 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6696 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6697 NL80211_CMD_GET_WOWLAN
);
6699 goto nla_put_failure
;
6702 struct nlattr
*nl_wowlan
;
6704 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
6706 goto nla_put_failure
;
6708 if ((rdev
->wowlan
->any
&&
6709 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
6710 (rdev
->wowlan
->disconnect
&&
6711 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
6712 (rdev
->wowlan
->magic_pkt
&&
6713 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
6714 (rdev
->wowlan
->gtk_rekey_failure
&&
6715 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
6716 (rdev
->wowlan
->eap_identity_req
&&
6717 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
6718 (rdev
->wowlan
->four_way_handshake
&&
6719 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
6720 (rdev
->wowlan
->rfkill_release
&&
6721 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
6722 goto nla_put_failure
;
6723 if (rdev
->wowlan
->n_patterns
) {
6724 struct nlattr
*nl_pats
, *nl_pat
;
6727 nl_pats
= nla_nest_start(msg
,
6728 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
6730 goto nla_put_failure
;
6732 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
6733 nl_pat
= nla_nest_start(msg
, i
+ 1);
6735 goto nla_put_failure
;
6736 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
6737 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
6738 DIV_ROUND_UP(pat_len
, 8),
6739 rdev
->wowlan
->patterns
[i
].mask
) ||
6740 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
6742 rdev
->wowlan
->patterns
[i
].pattern
))
6743 goto nla_put_failure
;
6744 nla_nest_end(msg
, nl_pat
);
6746 nla_nest_end(msg
, nl_pats
);
6749 nla_nest_end(msg
, nl_wowlan
);
6752 genlmsg_end(msg
, hdr
);
6753 return genlmsg_reply(msg
, info
);
6760 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6762 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6763 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
6764 struct cfg80211_wowlan new_triggers
= {};
6765 struct cfg80211_wowlan
*ntrig
;
6766 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
6768 bool prev_enabled
= rdev
->wowlan
;
6770 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6773 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
6774 cfg80211_rdev_free_wowlan(rdev
);
6775 rdev
->wowlan
= NULL
;
6779 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
6780 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6781 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6782 nl80211_wowlan_policy
);
6786 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
6787 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
6789 new_triggers
.any
= true;
6792 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
6793 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
6795 new_triggers
.disconnect
= true;
6798 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
6799 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
6801 new_triggers
.magic_pkt
= true;
6804 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
6807 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
6808 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
6810 new_triggers
.gtk_rekey_failure
= true;
6813 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
6814 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
6816 new_triggers
.eap_identity_req
= true;
6819 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
6820 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
6822 new_triggers
.four_way_handshake
= true;
6825 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
6826 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
6828 new_triggers
.rfkill_release
= true;
6831 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
6834 int rem
, pat_len
, mask_len
;
6835 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
6837 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6840 if (n_patterns
> wowlan
->n_patterns
)
6843 new_triggers
.patterns
= kcalloc(n_patterns
,
6844 sizeof(new_triggers
.patterns
[0]),
6846 if (!new_triggers
.patterns
)
6849 new_triggers
.n_patterns
= n_patterns
;
6852 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6854 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
6855 nla_data(pat
), nla_len(pat
), NULL
);
6857 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
6858 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
6860 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
6861 mask_len
= DIV_ROUND_UP(pat_len
, 8);
6862 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
6865 if (pat_len
> wowlan
->pattern_max_len
||
6866 pat_len
< wowlan
->pattern_min_len
)
6869 new_triggers
.patterns
[i
].mask
=
6870 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
6871 if (!new_triggers
.patterns
[i
].mask
) {
6875 new_triggers
.patterns
[i
].pattern
=
6876 new_triggers
.patterns
[i
].mask
+ mask_len
;
6877 memcpy(new_triggers
.patterns
[i
].mask
,
6878 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
6880 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
6881 memcpy(new_triggers
.patterns
[i
].pattern
,
6882 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
6888 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
6893 cfg80211_rdev_free_wowlan(rdev
);
6894 rdev
->wowlan
= ntrig
;
6897 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
6898 rdev_set_wakeup(rdev
, rdev
->wowlan
);
6902 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
6903 kfree(new_triggers
.patterns
[i
].mask
);
6904 kfree(new_triggers
.patterns
);
6909 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
6911 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6912 struct net_device
*dev
= info
->user_ptr
[1];
6913 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6914 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
6915 struct cfg80211_gtk_rekey_data rekey_data
;
6918 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
6921 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
6922 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6923 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6924 nl80211_rekey_policy
);
6928 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
6930 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
6932 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
6935 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
6937 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
6939 memcpy(rekey_data
.replay_ctr
,
6940 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
6941 NL80211_REPLAY_CTR_LEN
);
6944 if (!wdev
->current_bss
) {
6949 if (!rdev
->ops
->set_rekey_data
) {
6954 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
6960 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
6961 struct genl_info
*info
)
6963 struct net_device
*dev
= info
->user_ptr
[1];
6964 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6966 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6967 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6970 if (wdev
->ap_unexpected_nlportid
)
6973 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
6977 static int nl80211_probe_client(struct sk_buff
*skb
,
6978 struct genl_info
*info
)
6980 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6981 struct net_device
*dev
= info
->user_ptr
[1];
6982 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6983 struct sk_buff
*msg
;
6989 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6990 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6993 if (!info
->attrs
[NL80211_ATTR_MAC
])
6996 if (!rdev
->ops
->probe_client
)
6999 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7003 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7004 NL80211_CMD_PROBE_CLIENT
);
7011 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7013 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
7017 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7018 goto nla_put_failure
;
7020 genlmsg_end(msg
, hdr
);
7022 return genlmsg_reply(msg
, info
);
7031 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
7033 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7034 struct cfg80211_beacon_registration
*reg
, *nreg
;
7037 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
7040 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
7044 /* First, check if already registered. */
7045 spin_lock_bh(&rdev
->beacon_registrations_lock
);
7046 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
7047 if (reg
->nlportid
== info
->snd_portid
) {
7052 /* Add it to the list */
7053 nreg
->nlportid
= info
->snd_portid
;
7054 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
7056 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
7060 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
7065 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
7067 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7068 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7071 if (!rdev
->ops
->start_p2p_device
)
7074 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
7077 if (wdev
->p2p_started
)
7080 mutex_lock(&rdev
->devlist_mtx
);
7081 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
7082 mutex_unlock(&rdev
->devlist_mtx
);
7086 err
= rdev_start_p2p_device(rdev
, wdev
);
7090 wdev
->p2p_started
= true;
7091 mutex_lock(&rdev
->devlist_mtx
);
7093 mutex_unlock(&rdev
->devlist_mtx
);
7098 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
7100 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7101 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7103 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
7106 if (!rdev
->ops
->stop_p2p_device
)
7109 if (!wdev
->p2p_started
)
7112 rdev_stop_p2p_device(rdev
, wdev
);
7113 wdev
->p2p_started
= false;
7115 mutex_lock(&rdev
->devlist_mtx
);
7117 mutex_unlock(&rdev
->devlist_mtx
);
7119 if (WARN_ON(rdev
->scan_req
&& rdev
->scan_req
->wdev
== wdev
)) {
7120 rdev
->scan_req
->aborted
= true;
7121 ___cfg80211_scan_done(rdev
, true);
7127 #define NL80211_FLAG_NEED_WIPHY 0x01
7128 #define NL80211_FLAG_NEED_NETDEV 0x02
7129 #define NL80211_FLAG_NEED_RTNL 0x04
7130 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
7131 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
7132 NL80211_FLAG_CHECK_NETDEV_UP)
7133 #define NL80211_FLAG_NEED_WDEV 0x10
7134 /* If a netdev is associated, it must be UP, P2P must be started */
7135 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
7136 NL80211_FLAG_CHECK_NETDEV_UP)
7138 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
7139 struct genl_info
*info
)
7141 struct cfg80211_registered_device
*rdev
;
7142 struct wireless_dev
*wdev
;
7143 struct net_device
*dev
;
7144 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
7149 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
7150 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
7154 return PTR_ERR(rdev
);
7156 info
->user_ptr
[0] = rdev
;
7157 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
7158 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
7159 mutex_lock(&cfg80211_mutex
);
7160 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
7163 mutex_unlock(&cfg80211_mutex
);
7166 return PTR_ERR(wdev
);
7170 rdev
= wiphy_to_dev(wdev
->wiphy
);
7172 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
7174 mutex_unlock(&cfg80211_mutex
);
7180 info
->user_ptr
[1] = dev
;
7182 info
->user_ptr
[1] = wdev
;
7186 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
7187 !netif_running(dev
)) {
7188 mutex_unlock(&cfg80211_mutex
);
7195 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
7196 if (!wdev
->p2p_started
) {
7197 mutex_unlock(&cfg80211_mutex
);
7204 cfg80211_lock_rdev(rdev
);
7206 mutex_unlock(&cfg80211_mutex
);
7208 info
->user_ptr
[0] = rdev
;
7214 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
7215 struct genl_info
*info
)
7217 if (info
->user_ptr
[0])
7218 cfg80211_unlock_rdev(info
->user_ptr
[0]);
7219 if (info
->user_ptr
[1]) {
7220 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
7221 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7224 dev_put(wdev
->netdev
);
7226 dev_put(info
->user_ptr
[1]);
7229 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
7233 static struct genl_ops nl80211_ops
[] = {
7235 .cmd
= NL80211_CMD_GET_WIPHY
,
7236 .doit
= nl80211_get_wiphy
,
7237 .dumpit
= nl80211_dump_wiphy
,
7238 .policy
= nl80211_policy
,
7239 /* can be retrieved by unprivileged users */
7240 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
7243 .cmd
= NL80211_CMD_SET_WIPHY
,
7244 .doit
= nl80211_set_wiphy
,
7245 .policy
= nl80211_policy
,
7246 .flags
= GENL_ADMIN_PERM
,
7247 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
7250 .cmd
= NL80211_CMD_GET_INTERFACE
,
7251 .doit
= nl80211_get_interface
,
7252 .dumpit
= nl80211_dump_interface
,
7253 .policy
= nl80211_policy
,
7254 /* can be retrieved by unprivileged users */
7255 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
7258 .cmd
= NL80211_CMD_SET_INTERFACE
,
7259 .doit
= nl80211_set_interface
,
7260 .policy
= nl80211_policy
,
7261 .flags
= GENL_ADMIN_PERM
,
7262 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7263 NL80211_FLAG_NEED_RTNL
,
7266 .cmd
= NL80211_CMD_NEW_INTERFACE
,
7267 .doit
= nl80211_new_interface
,
7268 .policy
= nl80211_policy
,
7269 .flags
= GENL_ADMIN_PERM
,
7270 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7271 NL80211_FLAG_NEED_RTNL
,
7274 .cmd
= NL80211_CMD_DEL_INTERFACE
,
7275 .doit
= nl80211_del_interface
,
7276 .policy
= nl80211_policy
,
7277 .flags
= GENL_ADMIN_PERM
,
7278 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7279 NL80211_FLAG_NEED_RTNL
,
7282 .cmd
= NL80211_CMD_GET_KEY
,
7283 .doit
= nl80211_get_key
,
7284 .policy
= nl80211_policy
,
7285 .flags
= GENL_ADMIN_PERM
,
7286 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7287 NL80211_FLAG_NEED_RTNL
,
7290 .cmd
= NL80211_CMD_SET_KEY
,
7291 .doit
= nl80211_set_key
,
7292 .policy
= nl80211_policy
,
7293 .flags
= GENL_ADMIN_PERM
,
7294 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7295 NL80211_FLAG_NEED_RTNL
,
7298 .cmd
= NL80211_CMD_NEW_KEY
,
7299 .doit
= nl80211_new_key
,
7300 .policy
= nl80211_policy
,
7301 .flags
= GENL_ADMIN_PERM
,
7302 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7303 NL80211_FLAG_NEED_RTNL
,
7306 .cmd
= NL80211_CMD_DEL_KEY
,
7307 .doit
= nl80211_del_key
,
7308 .policy
= nl80211_policy
,
7309 .flags
= GENL_ADMIN_PERM
,
7310 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7311 NL80211_FLAG_NEED_RTNL
,
7314 .cmd
= NL80211_CMD_SET_BEACON
,
7315 .policy
= nl80211_policy
,
7316 .flags
= GENL_ADMIN_PERM
,
7317 .doit
= nl80211_set_beacon
,
7318 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7319 NL80211_FLAG_NEED_RTNL
,
7322 .cmd
= NL80211_CMD_START_AP
,
7323 .policy
= nl80211_policy
,
7324 .flags
= GENL_ADMIN_PERM
,
7325 .doit
= nl80211_start_ap
,
7326 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7327 NL80211_FLAG_NEED_RTNL
,
7330 .cmd
= NL80211_CMD_STOP_AP
,
7331 .policy
= nl80211_policy
,
7332 .flags
= GENL_ADMIN_PERM
,
7333 .doit
= nl80211_stop_ap
,
7334 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7335 NL80211_FLAG_NEED_RTNL
,
7338 .cmd
= NL80211_CMD_GET_STATION
,
7339 .doit
= nl80211_get_station
,
7340 .dumpit
= nl80211_dump_station
,
7341 .policy
= nl80211_policy
,
7342 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7343 NL80211_FLAG_NEED_RTNL
,
7346 .cmd
= NL80211_CMD_SET_STATION
,
7347 .doit
= nl80211_set_station
,
7348 .policy
= nl80211_policy
,
7349 .flags
= GENL_ADMIN_PERM
,
7350 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7351 NL80211_FLAG_NEED_RTNL
,
7354 .cmd
= NL80211_CMD_NEW_STATION
,
7355 .doit
= nl80211_new_station
,
7356 .policy
= nl80211_policy
,
7357 .flags
= GENL_ADMIN_PERM
,
7358 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7359 NL80211_FLAG_NEED_RTNL
,
7362 .cmd
= NL80211_CMD_DEL_STATION
,
7363 .doit
= nl80211_del_station
,
7364 .policy
= nl80211_policy
,
7365 .flags
= GENL_ADMIN_PERM
,
7366 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7367 NL80211_FLAG_NEED_RTNL
,
7370 .cmd
= NL80211_CMD_GET_MPATH
,
7371 .doit
= nl80211_get_mpath
,
7372 .dumpit
= nl80211_dump_mpath
,
7373 .policy
= nl80211_policy
,
7374 .flags
= GENL_ADMIN_PERM
,
7375 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7376 NL80211_FLAG_NEED_RTNL
,
7379 .cmd
= NL80211_CMD_SET_MPATH
,
7380 .doit
= nl80211_set_mpath
,
7381 .policy
= nl80211_policy
,
7382 .flags
= GENL_ADMIN_PERM
,
7383 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7384 NL80211_FLAG_NEED_RTNL
,
7387 .cmd
= NL80211_CMD_NEW_MPATH
,
7388 .doit
= nl80211_new_mpath
,
7389 .policy
= nl80211_policy
,
7390 .flags
= GENL_ADMIN_PERM
,
7391 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7392 NL80211_FLAG_NEED_RTNL
,
7395 .cmd
= NL80211_CMD_DEL_MPATH
,
7396 .doit
= nl80211_del_mpath
,
7397 .policy
= nl80211_policy
,
7398 .flags
= GENL_ADMIN_PERM
,
7399 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7400 NL80211_FLAG_NEED_RTNL
,
7403 .cmd
= NL80211_CMD_SET_BSS
,
7404 .doit
= nl80211_set_bss
,
7405 .policy
= nl80211_policy
,
7406 .flags
= GENL_ADMIN_PERM
,
7407 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7408 NL80211_FLAG_NEED_RTNL
,
7411 .cmd
= NL80211_CMD_GET_REG
,
7412 .doit
= nl80211_get_reg
,
7413 .policy
= nl80211_policy
,
7414 /* can be retrieved by unprivileged users */
7417 .cmd
= NL80211_CMD_SET_REG
,
7418 .doit
= nl80211_set_reg
,
7419 .policy
= nl80211_policy
,
7420 .flags
= GENL_ADMIN_PERM
,
7423 .cmd
= NL80211_CMD_REQ_SET_REG
,
7424 .doit
= nl80211_req_set_reg
,
7425 .policy
= nl80211_policy
,
7426 .flags
= GENL_ADMIN_PERM
,
7429 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
7430 .doit
= nl80211_get_mesh_config
,
7431 .policy
= nl80211_policy
,
7432 /* can be retrieved by unprivileged users */
7433 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7434 NL80211_FLAG_NEED_RTNL
,
7437 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
7438 .doit
= nl80211_update_mesh_config
,
7439 .policy
= nl80211_policy
,
7440 .flags
= GENL_ADMIN_PERM
,
7441 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7442 NL80211_FLAG_NEED_RTNL
,
7445 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
7446 .doit
= nl80211_trigger_scan
,
7447 .policy
= nl80211_policy
,
7448 .flags
= GENL_ADMIN_PERM
,
7449 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7450 NL80211_FLAG_NEED_RTNL
,
7453 .cmd
= NL80211_CMD_GET_SCAN
,
7454 .policy
= nl80211_policy
,
7455 .dumpit
= nl80211_dump_scan
,
7458 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
7459 .doit
= nl80211_start_sched_scan
,
7460 .policy
= nl80211_policy
,
7461 .flags
= GENL_ADMIN_PERM
,
7462 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7463 NL80211_FLAG_NEED_RTNL
,
7466 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
7467 .doit
= nl80211_stop_sched_scan
,
7468 .policy
= nl80211_policy
,
7469 .flags
= GENL_ADMIN_PERM
,
7470 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7471 NL80211_FLAG_NEED_RTNL
,
7474 .cmd
= NL80211_CMD_AUTHENTICATE
,
7475 .doit
= nl80211_authenticate
,
7476 .policy
= nl80211_policy
,
7477 .flags
= GENL_ADMIN_PERM
,
7478 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7479 NL80211_FLAG_NEED_RTNL
,
7482 .cmd
= NL80211_CMD_ASSOCIATE
,
7483 .doit
= nl80211_associate
,
7484 .policy
= nl80211_policy
,
7485 .flags
= GENL_ADMIN_PERM
,
7486 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7487 NL80211_FLAG_NEED_RTNL
,
7490 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
7491 .doit
= nl80211_deauthenticate
,
7492 .policy
= nl80211_policy
,
7493 .flags
= GENL_ADMIN_PERM
,
7494 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7495 NL80211_FLAG_NEED_RTNL
,
7498 .cmd
= NL80211_CMD_DISASSOCIATE
,
7499 .doit
= nl80211_disassociate
,
7500 .policy
= nl80211_policy
,
7501 .flags
= GENL_ADMIN_PERM
,
7502 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7503 NL80211_FLAG_NEED_RTNL
,
7506 .cmd
= NL80211_CMD_JOIN_IBSS
,
7507 .doit
= nl80211_join_ibss
,
7508 .policy
= nl80211_policy
,
7509 .flags
= GENL_ADMIN_PERM
,
7510 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7511 NL80211_FLAG_NEED_RTNL
,
7514 .cmd
= NL80211_CMD_LEAVE_IBSS
,
7515 .doit
= nl80211_leave_ibss
,
7516 .policy
= nl80211_policy
,
7517 .flags
= GENL_ADMIN_PERM
,
7518 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7519 NL80211_FLAG_NEED_RTNL
,
7521 #ifdef CONFIG_NL80211_TESTMODE
7523 .cmd
= NL80211_CMD_TESTMODE
,
7524 .doit
= nl80211_testmode_do
,
7525 .dumpit
= nl80211_testmode_dump
,
7526 .policy
= nl80211_policy
,
7527 .flags
= GENL_ADMIN_PERM
,
7528 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7529 NL80211_FLAG_NEED_RTNL
,
7533 .cmd
= NL80211_CMD_CONNECT
,
7534 .doit
= nl80211_connect
,
7535 .policy
= nl80211_policy
,
7536 .flags
= GENL_ADMIN_PERM
,
7537 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7538 NL80211_FLAG_NEED_RTNL
,
7541 .cmd
= NL80211_CMD_DISCONNECT
,
7542 .doit
= nl80211_disconnect
,
7543 .policy
= nl80211_policy
,
7544 .flags
= GENL_ADMIN_PERM
,
7545 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7546 NL80211_FLAG_NEED_RTNL
,
7549 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
7550 .doit
= nl80211_wiphy_netns
,
7551 .policy
= nl80211_policy
,
7552 .flags
= GENL_ADMIN_PERM
,
7553 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7554 NL80211_FLAG_NEED_RTNL
,
7557 .cmd
= NL80211_CMD_GET_SURVEY
,
7558 .policy
= nl80211_policy
,
7559 .dumpit
= nl80211_dump_survey
,
7562 .cmd
= NL80211_CMD_SET_PMKSA
,
7563 .doit
= nl80211_setdel_pmksa
,
7564 .policy
= nl80211_policy
,
7565 .flags
= GENL_ADMIN_PERM
,
7566 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7567 NL80211_FLAG_NEED_RTNL
,
7570 .cmd
= NL80211_CMD_DEL_PMKSA
,
7571 .doit
= nl80211_setdel_pmksa
,
7572 .policy
= nl80211_policy
,
7573 .flags
= GENL_ADMIN_PERM
,
7574 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7575 NL80211_FLAG_NEED_RTNL
,
7578 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
7579 .doit
= nl80211_flush_pmksa
,
7580 .policy
= nl80211_policy
,
7581 .flags
= GENL_ADMIN_PERM
,
7582 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7583 NL80211_FLAG_NEED_RTNL
,
7586 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
7587 .doit
= nl80211_remain_on_channel
,
7588 .policy
= nl80211_policy
,
7589 .flags
= GENL_ADMIN_PERM
,
7590 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7591 NL80211_FLAG_NEED_RTNL
,
7594 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7595 .doit
= nl80211_cancel_remain_on_channel
,
7596 .policy
= nl80211_policy
,
7597 .flags
= GENL_ADMIN_PERM
,
7598 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7599 NL80211_FLAG_NEED_RTNL
,
7602 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
7603 .doit
= nl80211_set_tx_bitrate_mask
,
7604 .policy
= nl80211_policy
,
7605 .flags
= GENL_ADMIN_PERM
,
7606 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7607 NL80211_FLAG_NEED_RTNL
,
7610 .cmd
= NL80211_CMD_REGISTER_FRAME
,
7611 .doit
= nl80211_register_mgmt
,
7612 .policy
= nl80211_policy
,
7613 .flags
= GENL_ADMIN_PERM
,
7614 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7615 NL80211_FLAG_NEED_RTNL
,
7618 .cmd
= NL80211_CMD_FRAME
,
7619 .doit
= nl80211_tx_mgmt
,
7620 .policy
= nl80211_policy
,
7621 .flags
= GENL_ADMIN_PERM
,
7622 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7623 NL80211_FLAG_NEED_RTNL
,
7626 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
7627 .doit
= nl80211_tx_mgmt_cancel_wait
,
7628 .policy
= nl80211_policy
,
7629 .flags
= GENL_ADMIN_PERM
,
7630 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7631 NL80211_FLAG_NEED_RTNL
,
7634 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
7635 .doit
= nl80211_set_power_save
,
7636 .policy
= nl80211_policy
,
7637 .flags
= GENL_ADMIN_PERM
,
7638 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7639 NL80211_FLAG_NEED_RTNL
,
7642 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
7643 .doit
= nl80211_get_power_save
,
7644 .policy
= nl80211_policy
,
7645 /* can be retrieved by unprivileged users */
7646 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7647 NL80211_FLAG_NEED_RTNL
,
7650 .cmd
= NL80211_CMD_SET_CQM
,
7651 .doit
= nl80211_set_cqm
,
7652 .policy
= nl80211_policy
,
7653 .flags
= GENL_ADMIN_PERM
,
7654 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7655 NL80211_FLAG_NEED_RTNL
,
7658 .cmd
= NL80211_CMD_SET_CHANNEL
,
7659 .doit
= nl80211_set_channel
,
7660 .policy
= nl80211_policy
,
7661 .flags
= GENL_ADMIN_PERM
,
7662 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7663 NL80211_FLAG_NEED_RTNL
,
7666 .cmd
= NL80211_CMD_SET_WDS_PEER
,
7667 .doit
= nl80211_set_wds_peer
,
7668 .policy
= nl80211_policy
,
7669 .flags
= GENL_ADMIN_PERM
,
7670 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7671 NL80211_FLAG_NEED_RTNL
,
7674 .cmd
= NL80211_CMD_JOIN_MESH
,
7675 .doit
= nl80211_join_mesh
,
7676 .policy
= nl80211_policy
,
7677 .flags
= GENL_ADMIN_PERM
,
7678 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7679 NL80211_FLAG_NEED_RTNL
,
7682 .cmd
= NL80211_CMD_LEAVE_MESH
,
7683 .doit
= nl80211_leave_mesh
,
7684 .policy
= nl80211_policy
,
7685 .flags
= GENL_ADMIN_PERM
,
7686 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7687 NL80211_FLAG_NEED_RTNL
,
7691 .cmd
= NL80211_CMD_GET_WOWLAN
,
7692 .doit
= nl80211_get_wowlan
,
7693 .policy
= nl80211_policy
,
7694 /* can be retrieved by unprivileged users */
7695 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7696 NL80211_FLAG_NEED_RTNL
,
7699 .cmd
= NL80211_CMD_SET_WOWLAN
,
7700 .doit
= nl80211_set_wowlan
,
7701 .policy
= nl80211_policy
,
7702 .flags
= GENL_ADMIN_PERM
,
7703 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7704 NL80211_FLAG_NEED_RTNL
,
7708 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
7709 .doit
= nl80211_set_rekey_data
,
7710 .policy
= nl80211_policy
,
7711 .flags
= GENL_ADMIN_PERM
,
7712 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7713 NL80211_FLAG_NEED_RTNL
,
7716 .cmd
= NL80211_CMD_TDLS_MGMT
,
7717 .doit
= nl80211_tdls_mgmt
,
7718 .policy
= nl80211_policy
,
7719 .flags
= GENL_ADMIN_PERM
,
7720 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7721 NL80211_FLAG_NEED_RTNL
,
7724 .cmd
= NL80211_CMD_TDLS_OPER
,
7725 .doit
= nl80211_tdls_oper
,
7726 .policy
= nl80211_policy
,
7727 .flags
= GENL_ADMIN_PERM
,
7728 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7729 NL80211_FLAG_NEED_RTNL
,
7732 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
7733 .doit
= nl80211_register_unexpected_frame
,
7734 .policy
= nl80211_policy
,
7735 .flags
= GENL_ADMIN_PERM
,
7736 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7737 NL80211_FLAG_NEED_RTNL
,
7740 .cmd
= NL80211_CMD_PROBE_CLIENT
,
7741 .doit
= nl80211_probe_client
,
7742 .policy
= nl80211_policy
,
7743 .flags
= GENL_ADMIN_PERM
,
7744 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7745 NL80211_FLAG_NEED_RTNL
,
7748 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
7749 .doit
= nl80211_register_beacons
,
7750 .policy
= nl80211_policy
,
7751 .flags
= GENL_ADMIN_PERM
,
7752 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7753 NL80211_FLAG_NEED_RTNL
,
7756 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
7757 .doit
= nl80211_set_noack_map
,
7758 .policy
= nl80211_policy
,
7759 .flags
= GENL_ADMIN_PERM
,
7760 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7761 NL80211_FLAG_NEED_RTNL
,
7764 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
7765 .doit
= nl80211_start_p2p_device
,
7766 .policy
= nl80211_policy
,
7767 .flags
= GENL_ADMIN_PERM
,
7768 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7769 NL80211_FLAG_NEED_RTNL
,
7772 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
7773 .doit
= nl80211_stop_p2p_device
,
7774 .policy
= nl80211_policy
,
7775 .flags
= GENL_ADMIN_PERM
,
7776 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7777 NL80211_FLAG_NEED_RTNL
,
7780 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
7781 .doit
= nl80211_set_mcast_rate
,
7782 .policy
= nl80211_policy
,
7783 .flags
= GENL_ADMIN_PERM
,
7784 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7785 NL80211_FLAG_NEED_RTNL
,
7789 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
7793 /* multicast groups */
7794 static struct genl_multicast_group nl80211_config_mcgrp
= {
7797 static struct genl_multicast_group nl80211_scan_mcgrp
= {
7800 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
7801 .name
= "regulatory",
7804 /* notification functions */
7806 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
7808 struct sk_buff
*msg
;
7810 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7814 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
7819 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7820 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
7823 static int nl80211_add_scan_req(struct sk_buff
*msg
,
7824 struct cfg80211_registered_device
*rdev
)
7826 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
7827 struct nlattr
*nest
;
7830 ASSERT_RDEV_LOCK(rdev
);
7835 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
7837 goto nla_put_failure
;
7838 for (i
= 0; i
< req
->n_ssids
; i
++) {
7839 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
7840 goto nla_put_failure
;
7842 nla_nest_end(msg
, nest
);
7844 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
7846 goto nla_put_failure
;
7847 for (i
= 0; i
< req
->n_channels
; i
++) {
7848 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
7849 goto nla_put_failure
;
7851 nla_nest_end(msg
, nest
);
7854 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
7855 goto nla_put_failure
;
7858 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
7865 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
7866 struct cfg80211_registered_device
*rdev
,
7867 struct wireless_dev
*wdev
,
7868 u32 portid
, u32 seq
, int flags
,
7873 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
7877 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7878 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
7879 wdev
->netdev
->ifindex
)) ||
7880 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
7881 goto nla_put_failure
;
7883 /* ignore errors and send incomplete event anyway */
7884 nl80211_add_scan_req(msg
, rdev
);
7886 return genlmsg_end(msg
, hdr
);
7889 genlmsg_cancel(msg
, hdr
);
7894 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
7895 struct cfg80211_registered_device
*rdev
,
7896 struct net_device
*netdev
,
7897 u32 portid
, u32 seq
, int flags
, u32 cmd
)
7901 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
7905 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7906 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7907 goto nla_put_failure
;
7909 return genlmsg_end(msg
, hdr
);
7912 genlmsg_cancel(msg
, hdr
);
7916 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
7917 struct wireless_dev
*wdev
)
7919 struct sk_buff
*msg
;
7921 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7925 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7926 NL80211_CMD_TRIGGER_SCAN
) < 0) {
7931 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7932 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7935 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
7936 struct wireless_dev
*wdev
)
7938 struct sk_buff
*msg
;
7940 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7944 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7945 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
7950 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7951 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7954 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
7955 struct wireless_dev
*wdev
)
7957 struct sk_buff
*msg
;
7959 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7963 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7964 NL80211_CMD_SCAN_ABORTED
) < 0) {
7969 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7970 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7973 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
7974 struct net_device
*netdev
)
7976 struct sk_buff
*msg
;
7978 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7982 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7983 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
7988 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7989 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7992 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
7993 struct net_device
*netdev
, u32 cmd
)
7995 struct sk_buff
*msg
;
7997 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8001 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
8006 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8007 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
8011 * This can happen on global regulatory changes or device specific settings
8012 * based on custom world regulatory domains.
8014 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
8016 struct sk_buff
*msg
;
8019 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8023 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
8029 /* Userspace can always count this one always being set */
8030 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
8031 goto nla_put_failure
;
8033 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
8034 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
8035 NL80211_REGDOM_TYPE_WORLD
))
8036 goto nla_put_failure
;
8037 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
8038 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
8039 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
8040 goto nla_put_failure
;
8041 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
8042 request
->intersect
) {
8043 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
8044 NL80211_REGDOM_TYPE_INTERSECTION
))
8045 goto nla_put_failure
;
8047 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
8048 NL80211_REGDOM_TYPE_COUNTRY
) ||
8049 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
8051 goto nla_put_failure
;
8054 if (wiphy_idx_valid(request
->wiphy_idx
) &&
8055 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
8056 goto nla_put_failure
;
8058 genlmsg_end(msg
, hdr
);
8061 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
8068 genlmsg_cancel(msg
, hdr
);
8072 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
8073 struct net_device
*netdev
,
8074 const u8
*buf
, size_t len
,
8075 enum nl80211_commands cmd
, gfp_t gfp
)
8077 struct sk_buff
*msg
;
8080 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8084 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8090 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8091 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8092 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8093 goto nla_put_failure
;
8095 genlmsg_end(msg
, hdr
);
8097 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8098 nl80211_mlme_mcgrp
.id
, gfp
);
8102 genlmsg_cancel(msg
, hdr
);
8106 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
8107 struct net_device
*netdev
, const u8
*buf
,
8108 size_t len
, gfp_t gfp
)
8110 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8111 NL80211_CMD_AUTHENTICATE
, gfp
);
8114 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
8115 struct net_device
*netdev
, const u8
*buf
,
8116 size_t len
, gfp_t gfp
)
8118 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8119 NL80211_CMD_ASSOCIATE
, gfp
);
8122 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
8123 struct net_device
*netdev
, const u8
*buf
,
8124 size_t len
, gfp_t gfp
)
8126 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8127 NL80211_CMD_DEAUTHENTICATE
, gfp
);
8130 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
8131 struct net_device
*netdev
, const u8
*buf
,
8132 size_t len
, gfp_t gfp
)
8134 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8135 NL80211_CMD_DISASSOCIATE
, gfp
);
8138 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
8139 struct net_device
*netdev
, const u8
*buf
,
8140 size_t len
, gfp_t gfp
)
8142 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8143 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
8146 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
8147 struct net_device
*netdev
, const u8
*buf
,
8148 size_t len
, gfp_t gfp
)
8150 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8151 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
8154 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
8155 struct net_device
*netdev
, int cmd
,
8156 const u8
*addr
, gfp_t gfp
)
8158 struct sk_buff
*msg
;
8161 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8165 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8171 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8172 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8173 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
8174 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8175 goto nla_put_failure
;
8177 genlmsg_end(msg
, hdr
);
8179 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8180 nl80211_mlme_mcgrp
.id
, gfp
);
8184 genlmsg_cancel(msg
, hdr
);
8188 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
8189 struct net_device
*netdev
, const u8
*addr
,
8192 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
8196 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
8197 struct net_device
*netdev
, const u8
*addr
,
8200 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
8204 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
8205 struct net_device
*netdev
, const u8
*bssid
,
8206 const u8
*req_ie
, size_t req_ie_len
,
8207 const u8
*resp_ie
, size_t resp_ie_len
,
8208 u16 status
, gfp_t gfp
)
8210 struct sk_buff
*msg
;
8213 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8217 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
8223 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8224 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8225 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
8226 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
8228 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8230 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8231 goto nla_put_failure
;
8233 genlmsg_end(msg
, hdr
);
8235 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8236 nl80211_mlme_mcgrp
.id
, gfp
);
8240 genlmsg_cancel(msg
, hdr
);
8245 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
8246 struct net_device
*netdev
, const u8
*bssid
,
8247 const u8
*req_ie
, size_t req_ie_len
,
8248 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
8250 struct sk_buff
*msg
;
8253 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8257 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
8263 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8264 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8265 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
8267 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8269 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8270 goto nla_put_failure
;
8272 genlmsg_end(msg
, hdr
);
8274 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8275 nl80211_mlme_mcgrp
.id
, gfp
);
8279 genlmsg_cancel(msg
, hdr
);
8284 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
8285 struct net_device
*netdev
, u16 reason
,
8286 const u8
*ie
, size_t ie_len
, bool from_ap
)
8288 struct sk_buff
*msg
;
8291 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8295 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
8301 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8302 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8303 (from_ap
&& reason
&&
8304 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
8306 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
8307 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
8308 goto nla_put_failure
;
8310 genlmsg_end(msg
, hdr
);
8312 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8313 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
8317 genlmsg_cancel(msg
, hdr
);
8322 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
8323 struct net_device
*netdev
, const u8
*bssid
,
8326 struct sk_buff
*msg
;
8329 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8333 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
8339 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8340 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8341 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8342 goto nla_put_failure
;
8344 genlmsg_end(msg
, hdr
);
8346 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8347 nl80211_mlme_mcgrp
.id
, gfp
);
8351 genlmsg_cancel(msg
, hdr
);
8355 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
8356 struct net_device
*netdev
,
8357 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
8360 struct sk_buff
*msg
;
8363 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8367 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
8373 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8374 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8375 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
) ||
8377 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
8378 goto nla_put_failure
;
8380 genlmsg_end(msg
, hdr
);
8382 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8383 nl80211_mlme_mcgrp
.id
, gfp
);
8387 genlmsg_cancel(msg
, hdr
);
8391 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
8392 struct net_device
*netdev
, const u8
*addr
,
8393 enum nl80211_key_type key_type
, int key_id
,
8394 const u8
*tsc
, gfp_t gfp
)
8396 struct sk_buff
*msg
;
8399 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8403 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
8409 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8410 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8411 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
8412 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
8414 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
8415 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
8416 goto nla_put_failure
;
8418 genlmsg_end(msg
, hdr
);
8420 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8421 nl80211_mlme_mcgrp
.id
, gfp
);
8425 genlmsg_cancel(msg
, hdr
);
8429 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
8430 struct ieee80211_channel
*channel_before
,
8431 struct ieee80211_channel
*channel_after
)
8433 struct sk_buff
*msg
;
8435 struct nlattr
*nl_freq
;
8437 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
8441 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
8448 * Since we are applying the beacon hint to a wiphy we know its
8449 * wiphy_idx is valid
8451 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
8452 goto nla_put_failure
;
8455 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
8457 goto nla_put_failure
;
8458 if (nl80211_msg_put_channel(msg
, channel_before
))
8459 goto nla_put_failure
;
8460 nla_nest_end(msg
, nl_freq
);
8463 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
8465 goto nla_put_failure
;
8466 if (nl80211_msg_put_channel(msg
, channel_after
))
8467 goto nla_put_failure
;
8468 nla_nest_end(msg
, nl_freq
);
8470 genlmsg_end(msg
, hdr
);
8473 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
8480 genlmsg_cancel(msg
, hdr
);
8484 static void nl80211_send_remain_on_chan_event(
8485 int cmd
, struct cfg80211_registered_device
*rdev
,
8486 struct wireless_dev
*wdev
, u64 cookie
,
8487 struct ieee80211_channel
*chan
,
8488 unsigned int duration
, gfp_t gfp
)
8490 struct sk_buff
*msg
;
8493 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8497 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8503 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8504 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8505 wdev
->netdev
->ifindex
)) ||
8506 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
8507 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
8508 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
8509 NL80211_CHAN_NO_HT
) ||
8510 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8511 goto nla_put_failure
;
8513 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
8514 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
8515 goto nla_put_failure
;
8517 genlmsg_end(msg
, hdr
);
8519 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8520 nl80211_mlme_mcgrp
.id
, gfp
);
8524 genlmsg_cancel(msg
, hdr
);
8528 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
8529 struct wireless_dev
*wdev
, u64 cookie
,
8530 struct ieee80211_channel
*chan
,
8531 unsigned int duration
, gfp_t gfp
)
8533 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
8534 rdev
, wdev
, cookie
, chan
,
8538 void nl80211_send_remain_on_channel_cancel(
8539 struct cfg80211_registered_device
*rdev
,
8540 struct wireless_dev
*wdev
,
8541 u64 cookie
, struct ieee80211_channel
*chan
, gfp_t gfp
)
8543 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8544 rdev
, wdev
, cookie
, chan
, 0, gfp
);
8547 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
8548 struct net_device
*dev
, const u8
*mac_addr
,
8549 struct station_info
*sinfo
, gfp_t gfp
)
8551 struct sk_buff
*msg
;
8553 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8557 if (nl80211_send_station(msg
, 0, 0, 0,
8558 rdev
, dev
, mac_addr
, sinfo
) < 0) {
8563 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8564 nl80211_mlme_mcgrp
.id
, gfp
);
8567 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
8568 struct net_device
*dev
, const u8
*mac_addr
,
8571 struct sk_buff
*msg
;
8574 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8578 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
8584 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8585 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
8586 goto nla_put_failure
;
8588 genlmsg_end(msg
, hdr
);
8590 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8591 nl80211_mlme_mcgrp
.id
, gfp
);
8595 genlmsg_cancel(msg
, hdr
);
8599 void nl80211_send_conn_failed_event(struct cfg80211_registered_device
*rdev
,
8600 struct net_device
*dev
, const u8
*mac_addr
,
8601 enum nl80211_connect_failed_reason reason
,
8604 struct sk_buff
*msg
;
8607 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8611 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
8617 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8618 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
8619 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
8620 goto nla_put_failure
;
8622 genlmsg_end(msg
, hdr
);
8624 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8625 nl80211_mlme_mcgrp
.id
, gfp
);
8629 genlmsg_cancel(msg
, hdr
);
8633 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
8634 const u8
*addr
, gfp_t gfp
)
8636 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8637 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8638 struct sk_buff
*msg
;
8641 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
8646 msg
= nlmsg_new(100, gfp
);
8650 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8656 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8657 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8658 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8659 goto nla_put_failure
;
8661 err
= genlmsg_end(msg
, hdr
);
8667 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8671 genlmsg_cancel(msg
, hdr
);
8676 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
8678 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
8682 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
8683 const u8
*addr
, gfp_t gfp
)
8685 return __nl80211_unexpected_frame(dev
,
8686 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
8690 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
8691 struct wireless_dev
*wdev
, u32 nlportid
,
8692 int freq
, int sig_dbm
,
8693 const u8
*buf
, size_t len
, gfp_t gfp
)
8695 struct net_device
*netdev
= wdev
->netdev
;
8696 struct sk_buff
*msg
;
8699 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8703 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8709 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8710 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8711 netdev
->ifindex
)) ||
8712 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8714 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8715 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8716 goto nla_put_failure
;
8718 genlmsg_end(msg
, hdr
);
8720 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8723 genlmsg_cancel(msg
, hdr
);
8728 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
8729 struct wireless_dev
*wdev
, u64 cookie
,
8730 const u8
*buf
, size_t len
, bool ack
,
8733 struct net_device
*netdev
= wdev
->netdev
;
8734 struct sk_buff
*msg
;
8737 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8741 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
8747 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8748 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8749 netdev
->ifindex
)) ||
8750 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
8751 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8752 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8753 goto nla_put_failure
;
8755 genlmsg_end(msg
, hdr
);
8757 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
8761 genlmsg_cancel(msg
, hdr
);
8766 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
8767 struct net_device
*netdev
,
8768 enum nl80211_cqm_rssi_threshold_event rssi_event
,
8771 struct sk_buff
*msg
;
8772 struct nlattr
*pinfoattr
;
8775 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8779 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8785 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8786 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8787 goto nla_put_failure
;
8789 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8791 goto nla_put_failure
;
8793 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
8795 goto nla_put_failure
;
8797 nla_nest_end(msg
, pinfoattr
);
8799 genlmsg_end(msg
, hdr
);
8801 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8802 nl80211_mlme_mcgrp
.id
, gfp
);
8806 genlmsg_cancel(msg
, hdr
);
8810 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
8811 struct net_device
*netdev
, const u8
*bssid
,
8812 const u8
*replay_ctr
, gfp_t gfp
)
8814 struct sk_buff
*msg
;
8815 struct nlattr
*rekey_attr
;
8818 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8822 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8828 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8829 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8830 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8831 goto nla_put_failure
;
8833 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8835 goto nla_put_failure
;
8837 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
8838 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
8839 goto nla_put_failure
;
8841 nla_nest_end(msg
, rekey_attr
);
8843 genlmsg_end(msg
, hdr
);
8845 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8846 nl80211_mlme_mcgrp
.id
, gfp
);
8850 genlmsg_cancel(msg
, hdr
);
8854 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
8855 struct net_device
*netdev
, int index
,
8856 const u8
*bssid
, bool preauth
, gfp_t gfp
)
8858 struct sk_buff
*msg
;
8859 struct nlattr
*attr
;
8862 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8866 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
8872 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8873 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8874 goto nla_put_failure
;
8876 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
8878 goto nla_put_failure
;
8880 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
8881 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
8883 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
8884 goto nla_put_failure
;
8886 nla_nest_end(msg
, attr
);
8888 genlmsg_end(msg
, hdr
);
8890 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8891 nl80211_mlme_mcgrp
.id
, gfp
);
8895 genlmsg_cancel(msg
, hdr
);
8899 void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
8900 struct net_device
*netdev
,
8901 struct cfg80211_chan_def
*chandef
, gfp_t gfp
)
8903 struct sk_buff
*msg
;
8906 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8910 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
8916 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8917 goto nla_put_failure
;
8919 if (nl80211_send_chandef(msg
, chandef
))
8920 goto nla_put_failure
;
8922 genlmsg_end(msg
, hdr
);
8924 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8925 nl80211_mlme_mcgrp
.id
, gfp
);
8929 genlmsg_cancel(msg
, hdr
);
8934 nl80211_send_cqm_txe_notify(struct cfg80211_registered_device
*rdev
,
8935 struct net_device
*netdev
, const u8
*peer
,
8936 u32 num_packets
, u32 rate
, u32 intvl
, gfp_t gfp
)
8938 struct sk_buff
*msg
;
8939 struct nlattr
*pinfoattr
;
8942 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8946 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8952 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8953 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8954 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8955 goto nla_put_failure
;
8957 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8959 goto nla_put_failure
;
8961 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
8962 goto nla_put_failure
;
8964 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
8965 goto nla_put_failure
;
8967 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
8968 goto nla_put_failure
;
8970 nla_nest_end(msg
, pinfoattr
);
8972 genlmsg_end(msg
, hdr
);
8974 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8975 nl80211_mlme_mcgrp
.id
, gfp
);
8979 genlmsg_cancel(msg
, hdr
);
8984 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
8985 struct net_device
*netdev
, const u8
*peer
,
8986 u32 num_packets
, gfp_t gfp
)
8988 struct sk_buff
*msg
;
8989 struct nlattr
*pinfoattr
;
8992 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8996 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
9002 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9003 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9004 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
9005 goto nla_put_failure
;
9007 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
9009 goto nla_put_failure
;
9011 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
9012 goto nla_put_failure
;
9014 nla_nest_end(msg
, pinfoattr
);
9016 genlmsg_end(msg
, hdr
);
9018 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9019 nl80211_mlme_mcgrp
.id
, gfp
);
9023 genlmsg_cancel(msg
, hdr
);
9027 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
9028 u64 cookie
, bool acked
, gfp_t gfp
)
9030 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9031 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9032 struct sk_buff
*msg
;
9036 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
9038 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9043 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
9049 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9050 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9051 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9052 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
9053 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
9054 goto nla_put_failure
;
9056 err
= genlmsg_end(msg
, hdr
);
9062 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9063 nl80211_mlme_mcgrp
.id
, gfp
);
9067 genlmsg_cancel(msg
, hdr
);
9070 EXPORT_SYMBOL(cfg80211_probe_status
);
9072 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
9073 const u8
*frame
, size_t len
,
9074 int freq
, int sig_dbm
)
9076 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9077 struct sk_buff
*msg
;
9079 struct cfg80211_beacon_registration
*reg
;
9081 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
9083 spin_lock_bh(&rdev
->beacon_registrations_lock
);
9084 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
9085 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
9087 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9091 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
9093 goto nla_put_failure
;
9095 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9097 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
9099 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
9100 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
9101 goto nla_put_failure
;
9103 genlmsg_end(msg
, hdr
);
9105 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
9107 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9111 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9113 genlmsg_cancel(msg
, hdr
);
9116 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
9118 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
9119 enum nl80211_tdls_operation oper
,
9120 u16 reason_code
, gfp_t gfp
)
9122 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9123 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9124 struct sk_buff
*msg
;
9128 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
9131 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9135 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
9141 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9142 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9143 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
9144 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
9146 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
9147 goto nla_put_failure
;
9149 err
= genlmsg_end(msg
, hdr
);
9155 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9156 nl80211_mlme_mcgrp
.id
, gfp
);
9160 genlmsg_cancel(msg
, hdr
);
9163 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
9165 static int nl80211_netlink_notify(struct notifier_block
* nb
,
9166 unsigned long state
,
9169 struct netlink_notify
*notify
= _notify
;
9170 struct cfg80211_registered_device
*rdev
;
9171 struct wireless_dev
*wdev
;
9172 struct cfg80211_beacon_registration
*reg
, *tmp
;
9174 if (state
!= NETLINK_URELEASE
)
9179 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
9180 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
9181 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
9183 spin_lock_bh(&rdev
->beacon_registrations_lock
);
9184 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
9186 if (reg
->nlportid
== notify
->portid
) {
9187 list_del(®
->list
);
9192 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9200 static struct notifier_block nl80211_netlink_notifier
= {
9201 .notifier_call
= nl80211_netlink_notify
,
9204 /* initialisation/exit functions */
9206 int nl80211_init(void)
9210 err
= genl_register_family_with_ops(&nl80211_fam
,
9211 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
9215 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
9219 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
9223 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
9227 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
9231 #ifdef CONFIG_NL80211_TESTMODE
9232 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
9237 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
9243 genl_unregister_family(&nl80211_fam
);
9247 void nl80211_exit(void)
9249 netlink_unregister_notifier(&nl80211_netlink_notifier
);
9250 genl_unregister_family(&nl80211_fam
);