2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
26 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
);
27 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
28 struct genl_info
*info
,
29 struct cfg80211_crypto_settings
*settings
,
32 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
33 struct genl_info
*info
);
34 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
35 struct genl_info
*info
);
37 /* the netlink family */
38 static struct genl_family nl80211_fam
= {
39 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
40 .name
= "nl80211", /* have users key off the name instead */
41 .hdrsize
= 0, /* no private header */
42 .version
= 1, /* no particular meaning now */
43 .maxattr
= NL80211_ATTR_MAX
,
45 .pre_doit
= nl80211_pre_doit
,
46 .post_doit
= nl80211_post_doit
,
49 /* internal helper: get rdev and dev */
50 static int get_rdev_dev_by_ifindex(struct net
*netns
, struct nlattr
**attrs
,
51 struct cfg80211_registered_device
**rdev
,
52 struct net_device
**dev
)
56 if (!attrs
[NL80211_ATTR_IFINDEX
])
59 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
60 *dev
= dev_get_by_index(netns
, ifindex
);
64 *rdev
= cfg80211_get_dev_from_ifindex(netns
, ifindex
);
67 return PTR_ERR(*rdev
);
73 static struct cfg80211_registered_device
*
74 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
76 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
77 struct net_device
*netdev
;
79 assert_cfg80211_lock();
81 if (!attrs
[NL80211_ATTR_WIPHY
] &&
82 !attrs
[NL80211_ATTR_IFINDEX
])
83 return ERR_PTR(-EINVAL
);
85 if (attrs
[NL80211_ATTR_WIPHY
])
86 rdev
= cfg80211_rdev_by_wiphy_idx(
87 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
89 if (attrs
[NL80211_ATTR_IFINDEX
]) {
90 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
91 netdev
= dev_get_by_index(netns
, ifindex
);
93 if (netdev
->ieee80211_ptr
)
95 netdev
->ieee80211_ptr
->wiphy
);
101 /* not wireless device -- return error */
103 return ERR_PTR(-EINVAL
);
105 /* mismatch -- return error */
106 if (rdev
&& tmp
!= rdev
)
107 return ERR_PTR(-EINVAL
);
114 return ERR_PTR(-ENODEV
);
116 if (netns
!= wiphy_net(&rdev
->wiphy
))
117 return ERR_PTR(-ENODEV
);
123 * This function returns a pointer to the driver
124 * that the genl_info item that is passed refers to.
125 * If successful, it returns non-NULL and also locks
126 * the driver's mutex!
128 * This means that you need to call cfg80211_unlock_rdev()
129 * before being allowed to acquire &cfg80211_mutex!
131 * This is necessary because we need to lock the global
132 * mutex to get an item off the list safely, and then
133 * we lock the rdev mutex so it doesn't go away under us.
135 * We don't want to keep cfg80211_mutex locked
136 * for all the time in order to allow requests on
137 * other interfaces to go through at the same time.
139 * The result of this can be a PTR_ERR and hence must
140 * be checked with IS_ERR() for errors.
142 static struct cfg80211_registered_device
*
143 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
145 struct cfg80211_registered_device
*rdev
;
147 mutex_lock(&cfg80211_mutex
);
148 rdev
= __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
150 /* if it is not an error we grab the lock on
151 * it to assure it won't be going away while
152 * we operate on it */
154 mutex_lock(&rdev
->mtx
);
156 mutex_unlock(&cfg80211_mutex
);
161 /* policy for the attributes */
162 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
163 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
164 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
166 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
167 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
168 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
169 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
170 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
171 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
172 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
173 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
175 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
176 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
177 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
179 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
180 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
182 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
183 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
184 .len
= WLAN_MAX_KEY_LEN
},
185 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
186 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
187 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
188 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
189 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
191 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
192 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
193 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
194 .len
= IEEE80211_MAX_DATA_LEN
},
195 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
196 .len
= IEEE80211_MAX_DATA_LEN
},
197 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
198 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
199 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
200 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
201 .len
= NL80211_MAX_SUPP_RATES
},
202 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
203 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
204 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
205 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
206 .len
= IEEE80211_MAX_MESH_ID_LEN
},
207 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
209 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
210 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
212 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
213 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
214 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
215 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
216 .len
= NL80211_MAX_SUPP_RATES
},
217 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
219 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
220 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
222 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
224 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
225 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
226 .len
= IEEE80211_MAX_DATA_LEN
},
227 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
228 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
230 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
231 .len
= IEEE80211_MAX_SSID_LEN
},
232 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
233 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
234 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
235 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
236 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
237 [NL80211_ATTR_STA_FLAGS2
] = {
238 .len
= sizeof(struct nl80211_sta_flag_update
),
240 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
241 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
242 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
243 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
244 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
245 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
246 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
247 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
248 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
249 .len
= WLAN_PMKID_LEN
},
250 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
252 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
253 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
254 .len
= IEEE80211_MAX_DATA_LEN
},
255 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
256 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
257 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
258 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
259 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
260 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
261 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
262 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
263 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
264 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
265 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
266 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
267 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
268 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
269 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
270 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
271 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
272 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
273 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
274 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
275 .len
= IEEE80211_MAX_DATA_LEN
},
276 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
277 .len
= IEEE80211_MAX_DATA_LEN
},
278 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
279 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
280 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
281 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
282 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
283 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
284 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
285 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
286 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
287 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
288 .len
= IEEE80211_MAX_DATA_LEN
},
289 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
290 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
291 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
292 .len
= NL80211_HT_CAPABILITY_LEN
294 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
295 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
296 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
299 /* policy for the key attributes */
300 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
301 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
302 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
303 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
304 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
305 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
306 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
307 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
308 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
311 /* policy for the key default flags */
312 static const struct nla_policy
313 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
314 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
315 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
318 /* policy for WoWLAN attributes */
319 static const struct nla_policy
320 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
321 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
322 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
323 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
324 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
325 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
326 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
327 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
328 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
331 /* policy for GTK rekey offload attributes */
332 static const struct nla_policy
333 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
334 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
335 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
336 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
339 static const struct nla_policy
340 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
341 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
342 .len
= IEEE80211_MAX_SSID_LEN
},
343 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
346 /* ifidx get helper */
347 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
351 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
352 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
357 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
360 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
366 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
367 struct netlink_callback
*cb
,
368 struct cfg80211_registered_device
**rdev
,
369 struct net_device
**dev
)
371 int ifidx
= cb
->args
[0];
375 ifidx
= nl80211_get_ifidx(cb
);
383 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
389 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
391 err
= PTR_ERR(*rdev
);
401 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
403 cfg80211_unlock_rdev(rdev
);
408 static bool is_valid_ie_attr(const struct nlattr
*attr
)
416 pos
= nla_data(attr
);
437 /* message building helper */
438 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
441 /* since there is no private header just add the generic one */
442 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
445 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
446 struct ieee80211_channel
*chan
)
448 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
450 goto nla_put_failure
;
452 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
453 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
454 goto nla_put_failure
;
455 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
456 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
457 goto nla_put_failure
;
458 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
459 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
460 goto nla_put_failure
;
461 if ((chan
->flags
& IEEE80211_CHAN_RADAR
) &&
462 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
463 goto nla_put_failure
;
465 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
466 DBM_TO_MBM(chan
->max_power
)))
467 goto nla_put_failure
;
475 /* netlink command implementations */
482 bool def_uni
, def_multi
;
485 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
487 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
488 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
493 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
494 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
503 if (tb
[NL80211_KEY_IDX
])
504 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
506 if (tb
[NL80211_KEY_DATA
]) {
507 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
508 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
511 if (tb
[NL80211_KEY_SEQ
]) {
512 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
513 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
516 if (tb
[NL80211_KEY_CIPHER
])
517 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
519 if (tb
[NL80211_KEY_TYPE
]) {
520 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
521 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
525 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
526 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
527 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
528 tb
[NL80211_KEY_DEFAULT_TYPES
],
529 nl80211_key_default_policy
);
533 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
534 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
540 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
542 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
543 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
544 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
547 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
548 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
549 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
552 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
553 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
555 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
556 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
558 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
559 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
568 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
569 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
570 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
574 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
575 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
576 int err
= nla_parse_nested(
577 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
578 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
579 nl80211_key_default_policy
);
583 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
584 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
590 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
594 memset(k
, 0, sizeof(*k
));
598 if (info
->attrs
[NL80211_ATTR_KEY
])
599 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
601 err
= nl80211_parse_key_old(info
, k
);
606 if (k
->def
&& k
->defmgmt
)
610 if (k
->def_uni
|| !k
->def_multi
)
616 if (k
->idx
< 4 || k
->idx
> 5)
619 if (k
->idx
< 0 || k
->idx
> 3)
622 if (k
->idx
< 0 || k
->idx
> 5)
630 static struct cfg80211_cached_keys
*
631 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
634 struct key_parse parse
;
636 struct cfg80211_cached_keys
*result
;
637 int rem
, err
, def
= 0;
639 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
641 return ERR_PTR(-ENOMEM
);
644 result
->defmgmt
= -1;
646 nla_for_each_nested(key
, keys
, rem
) {
647 memset(&parse
, 0, sizeof(parse
));
650 err
= nl80211_parse_key_new(key
, &parse
);
656 if (parse
.idx
< 0 || parse
.idx
> 4)
662 result
->def
= parse
.idx
;
663 if (!parse
.def_uni
|| !parse
.def_multi
)
665 } else if (parse
.defmgmt
)
667 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
668 parse
.idx
, false, NULL
);
671 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
672 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
673 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
674 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
683 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
685 ASSERT_WDEV_LOCK(wdev
);
687 switch (wdev
->iftype
) {
688 case NL80211_IFTYPE_AP
:
689 case NL80211_IFTYPE_AP_VLAN
:
690 case NL80211_IFTYPE_P2P_GO
:
691 case NL80211_IFTYPE_MESH_POINT
:
693 case NL80211_IFTYPE_ADHOC
:
694 if (!wdev
->current_bss
)
697 case NL80211_IFTYPE_STATION
:
698 case NL80211_IFTYPE_P2P_CLIENT
:
699 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
709 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
711 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
715 goto nla_put_failure
;
719 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
720 goto nla_put_failure
;
725 nla_nest_end(msg
, nl_modes
);
732 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
735 struct nlattr
*nl_combis
;
738 nl_combis
= nla_nest_start(msg
,
739 NL80211_ATTR_INTERFACE_COMBINATIONS
);
741 goto nla_put_failure
;
743 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
744 const struct ieee80211_iface_combination
*c
;
745 struct nlattr
*nl_combi
, *nl_limits
;
747 c
= &wiphy
->iface_combinations
[i
];
749 nl_combi
= nla_nest_start(msg
, i
+ 1);
751 goto nla_put_failure
;
753 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
755 goto nla_put_failure
;
757 for (j
= 0; j
< c
->n_limits
; j
++) {
758 struct nlattr
*nl_limit
;
760 nl_limit
= nla_nest_start(msg
, j
+ 1);
762 goto nla_put_failure
;
763 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
765 goto nla_put_failure
;
766 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
768 goto nla_put_failure
;
769 nla_nest_end(msg
, nl_limit
);
772 nla_nest_end(msg
, nl_limits
);
774 if (c
->beacon_int_infra_match
&&
775 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
776 goto nla_put_failure
;
777 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
778 c
->num_different_channels
) ||
779 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
781 goto nla_put_failure
;
783 nla_nest_end(msg
, nl_combi
);
786 nla_nest_end(msg
, nl_combis
);
793 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
794 struct cfg80211_registered_device
*dev
)
797 struct nlattr
*nl_bands
, *nl_band
;
798 struct nlattr
*nl_freqs
, *nl_freq
;
799 struct nlattr
*nl_rates
, *nl_rate
;
800 struct nlattr
*nl_cmds
;
801 enum ieee80211_band band
;
802 struct ieee80211_channel
*chan
;
803 struct ieee80211_rate
*rate
;
805 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
806 dev
->wiphy
.mgmt_stypes
;
808 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
812 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
813 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
)) ||
814 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
815 cfg80211_rdev_list_generation
) ||
816 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
817 dev
->wiphy
.retry_short
) ||
818 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
819 dev
->wiphy
.retry_long
) ||
820 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
821 dev
->wiphy
.frag_threshold
) ||
822 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
823 dev
->wiphy
.rts_threshold
) ||
824 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
825 dev
->wiphy
.coverage_class
) ||
826 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
827 dev
->wiphy
.max_scan_ssids
) ||
828 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
829 dev
->wiphy
.max_sched_scan_ssids
) ||
830 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
831 dev
->wiphy
.max_scan_ie_len
) ||
832 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
833 dev
->wiphy
.max_sched_scan_ie_len
) ||
834 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
835 dev
->wiphy
.max_match_sets
))
836 goto nla_put_failure
;
838 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
839 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
840 goto nla_put_failure
;
841 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
842 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
843 goto nla_put_failure
;
844 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
845 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
846 goto nla_put_failure
;
847 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
848 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
849 goto nla_put_failure
;
850 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
851 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
852 goto nla_put_failure
;
853 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
854 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
855 goto nla_put_failure
;
857 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
858 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
859 dev
->wiphy
.cipher_suites
))
860 goto nla_put_failure
;
862 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
863 dev
->wiphy
.max_num_pmkids
))
864 goto nla_put_failure
;
866 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
867 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
868 goto nla_put_failure
;
870 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
871 dev
->wiphy
.available_antennas_tx
) ||
872 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
873 dev
->wiphy
.available_antennas_rx
))
874 goto nla_put_failure
;
876 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
877 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
878 dev
->wiphy
.probe_resp_offload
))
879 goto nla_put_failure
;
881 if ((dev
->wiphy
.available_antennas_tx
||
882 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
883 u32 tx_ant
= 0, rx_ant
= 0;
885 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
887 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
,
889 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
,
891 goto nla_put_failure
;
895 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
896 dev
->wiphy
.interface_modes
))
897 goto nla_put_failure
;
899 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
901 goto nla_put_failure
;
903 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
904 if (!dev
->wiphy
.bands
[band
])
907 nl_band
= nla_nest_start(msg
, band
);
909 goto nla_put_failure
;
912 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
&&
913 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
914 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
915 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
) ||
916 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
917 dev
->wiphy
.bands
[band
]->ht_cap
.cap
) ||
918 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
919 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
) ||
920 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
921 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
)))
922 goto nla_put_failure
;
925 if (dev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
&&
926 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
927 sizeof(dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
),
928 &dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
) ||
929 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
930 dev
->wiphy
.bands
[band
]->vht_cap
.cap
)))
931 goto nla_put_failure
;
933 /* add frequencies */
934 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
936 goto nla_put_failure
;
938 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
939 nl_freq
= nla_nest_start(msg
, i
);
941 goto nla_put_failure
;
943 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
945 if (nl80211_msg_put_channel(msg
, chan
))
946 goto nla_put_failure
;
948 nla_nest_end(msg
, nl_freq
);
951 nla_nest_end(msg
, nl_freqs
);
954 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
956 goto nla_put_failure
;
958 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
959 nl_rate
= nla_nest_start(msg
, i
);
961 goto nla_put_failure
;
963 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
964 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
966 goto nla_put_failure
;
967 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
969 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
970 goto nla_put_failure
;
972 nla_nest_end(msg
, nl_rate
);
975 nla_nest_end(msg
, nl_rates
);
977 nla_nest_end(msg
, nl_band
);
979 nla_nest_end(msg
, nl_bands
);
981 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
983 goto nla_put_failure
;
988 if (dev->ops->op) { \
990 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
991 goto nla_put_failure; \
995 CMD(add_virtual_intf
, NEW_INTERFACE
);
996 CMD(change_virtual_intf
, SET_INTERFACE
);
997 CMD(add_key
, NEW_KEY
);
998 CMD(start_ap
, START_AP
);
999 CMD(add_station
, NEW_STATION
);
1000 CMD(add_mpath
, NEW_MPATH
);
1001 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1002 CMD(change_bss
, SET_BSS
);
1003 CMD(auth
, AUTHENTICATE
);
1004 CMD(assoc
, ASSOCIATE
);
1005 CMD(deauth
, DEAUTHENTICATE
);
1006 CMD(disassoc
, DISASSOCIATE
);
1007 CMD(join_ibss
, JOIN_IBSS
);
1008 CMD(join_mesh
, JOIN_MESH
);
1009 CMD(set_pmksa
, SET_PMKSA
);
1010 CMD(del_pmksa
, DEL_PMKSA
);
1011 CMD(flush_pmksa
, FLUSH_PMKSA
);
1012 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1013 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1014 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1015 CMD(mgmt_tx
, FRAME
);
1016 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1017 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1019 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1020 goto nla_put_failure
;
1022 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1023 dev
->ops
->join_mesh
) {
1025 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1026 goto nla_put_failure
;
1028 CMD(set_wds_peer
, SET_WDS_PEER
);
1029 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1030 CMD(tdls_mgmt
, TDLS_MGMT
);
1031 CMD(tdls_oper
, TDLS_OPER
);
1033 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1034 CMD(sched_scan_start
, START_SCHED_SCAN
);
1035 CMD(probe_client
, PROBE_CLIENT
);
1036 CMD(set_noack_map
, SET_NOACK_MAP
);
1037 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1039 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1040 goto nla_put_failure
;
1043 #ifdef CONFIG_NL80211_TESTMODE
1044 CMD(testmode_cmd
, TESTMODE
);
1049 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1051 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1052 goto nla_put_failure
;
1055 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1057 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1058 goto nla_put_failure
;
1061 nla_nest_end(msg
, nl_cmds
);
1063 if (dev
->ops
->remain_on_channel
&&
1064 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1065 nla_put_u32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1066 dev
->wiphy
.max_remain_on_channel_duration
))
1067 goto nla_put_failure
;
1069 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1070 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1071 goto nla_put_failure
;
1075 struct nlattr
*nl_ftypes
, *nl_ifs
;
1076 enum nl80211_iftype ift
;
1078 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1080 goto nla_put_failure
;
1082 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1083 nl_ftypes
= nla_nest_start(msg
, ift
);
1085 goto nla_put_failure
;
1087 stypes
= mgmt_stypes
[ift
].tx
;
1090 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1091 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1092 goto nla_put_failure
;
1096 nla_nest_end(msg
, nl_ftypes
);
1099 nla_nest_end(msg
, nl_ifs
);
1101 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1103 goto nla_put_failure
;
1105 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1106 nl_ftypes
= nla_nest_start(msg
, ift
);
1108 goto nla_put_failure
;
1110 stypes
= mgmt_stypes
[ift
].rx
;
1113 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1114 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1115 goto nla_put_failure
;
1119 nla_nest_end(msg
, nl_ftypes
);
1121 nla_nest_end(msg
, nl_ifs
);
1125 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
1126 struct nlattr
*nl_wowlan
;
1128 nl_wowlan
= nla_nest_start(msg
,
1129 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1131 goto nla_put_failure
;
1133 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1134 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1135 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1136 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1137 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1138 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1139 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1140 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1141 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1142 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1143 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1144 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1145 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1146 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1147 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1148 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1149 goto nla_put_failure
;
1150 if (dev
->wiphy
.wowlan
.n_patterns
) {
1151 struct nl80211_wowlan_pattern_support pat
= {
1152 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1154 dev
->wiphy
.wowlan
.pattern_min_len
,
1156 dev
->wiphy
.wowlan
.pattern_max_len
,
1158 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1160 goto nla_put_failure
;
1163 nla_nest_end(msg
, nl_wowlan
);
1167 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1168 dev
->wiphy
.software_iftypes
))
1169 goto nla_put_failure
;
1171 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1172 goto nla_put_failure
;
1174 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1175 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1176 dev
->wiphy
.ap_sme_capa
))
1177 goto nla_put_failure
;
1179 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
,
1180 dev
->wiphy
.features
))
1181 goto nla_put_failure
;
1183 if (dev
->wiphy
.ht_capa_mod_mask
&&
1184 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1185 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1186 dev
->wiphy
.ht_capa_mod_mask
))
1187 goto nla_put_failure
;
1189 return genlmsg_end(msg
, hdr
);
1192 genlmsg_cancel(msg
, hdr
);
1196 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1199 int start
= cb
->args
[0];
1200 struct cfg80211_registered_device
*dev
;
1202 mutex_lock(&cfg80211_mutex
);
1203 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1204 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1208 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
1209 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1215 mutex_unlock(&cfg80211_mutex
);
1222 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1224 struct sk_buff
*msg
;
1225 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1227 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1231 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
1236 return genlmsg_reply(msg
, info
);
1239 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1240 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1241 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1242 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1243 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1244 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1247 static int parse_txq_params(struct nlattr
*tb
[],
1248 struct ieee80211_txq_params
*txq_params
)
1250 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1251 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1252 !tb
[NL80211_TXQ_ATTR_AIFS
])
1255 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1256 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1257 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1258 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1259 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1261 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1267 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1270 * You can only set the channel explicitly for WDS interfaces,
1271 * all others have their channel managed via their respective
1272 * "establish a connection" command (connect, join, ...)
1274 * For AP/GO and mesh mode, the channel can be set with the
1275 * channel userspace API, but is only stored and passed to the
1276 * low-level driver when the AP starts or the mesh is joined.
1277 * This is for backward compatibility, userspace can also give
1278 * the channel in the start-ap or join-mesh commands instead.
1280 * Monitors are special as they are normally slaved to
1281 * whatever else is going on, so they have their own special
1282 * operation to set the monitor channel if possible.
1285 wdev
->iftype
== NL80211_IFTYPE_AP
||
1286 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1287 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1288 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1291 static bool nl80211_valid_channel_type(struct genl_info
*info
,
1292 enum nl80211_channel_type
*channel_type
)
1294 enum nl80211_channel_type tmp
;
1296 if (!info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1299 tmp
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1300 if (tmp
!= NL80211_CHAN_NO_HT
&&
1301 tmp
!= NL80211_CHAN_HT20
&&
1302 tmp
!= NL80211_CHAN_HT40PLUS
&&
1303 tmp
!= NL80211_CHAN_HT40MINUS
)
1307 *channel_type
= tmp
;
1312 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1313 struct wireless_dev
*wdev
,
1314 struct genl_info
*info
)
1316 struct ieee80211_channel
*channel
;
1317 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1320 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1323 iftype
= wdev
->iftype
;
1325 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1328 if (!nl80211_can_set_dev_channel(wdev
))
1331 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
1332 !nl80211_valid_channel_type(info
, &channel_type
))
1335 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1337 mutex_lock(&rdev
->devlist_mtx
);
1339 case NL80211_IFTYPE_AP
:
1340 case NL80211_IFTYPE_P2P_GO
:
1341 if (wdev
->beacon_interval
) {
1345 channel
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
1346 if (!channel
|| !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
,
1352 wdev
->preset_chan
= channel
;
1353 wdev
->preset_chantype
= channel_type
;
1356 case NL80211_IFTYPE_MESH_POINT
:
1357 result
= cfg80211_set_mesh_freq(rdev
, wdev
, freq
, channel_type
);
1359 case NL80211_IFTYPE_MONITOR
:
1360 result
= cfg80211_set_monitor_channel(rdev
, freq
, channel_type
);
1365 mutex_unlock(&rdev
->devlist_mtx
);
1370 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1372 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1373 struct net_device
*netdev
= info
->user_ptr
[1];
1375 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1378 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1380 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1381 struct net_device
*dev
= info
->user_ptr
[1];
1382 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1385 if (!info
->attrs
[NL80211_ATTR_MAC
])
1388 if (netif_running(dev
))
1391 if (!rdev
->ops
->set_wds_peer
)
1394 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1397 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1398 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1402 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1404 struct cfg80211_registered_device
*rdev
;
1405 struct net_device
*netdev
= NULL
;
1406 struct wireless_dev
*wdev
;
1407 int result
= 0, rem_txq_params
= 0;
1408 struct nlattr
*nl_txq_params
;
1410 u8 retry_short
= 0, retry_long
= 0;
1411 u32 frag_threshold
= 0, rts_threshold
= 0;
1412 u8 coverage_class
= 0;
1415 * Try to find the wiphy and netdev. Normally this
1416 * function shouldn't need the netdev, but this is
1417 * done for backward compatibility -- previously
1418 * setting the channel was done per wiphy, but now
1419 * it is per netdev. Previous userland like hostapd
1420 * also passed a netdev to set_wiphy, so that it is
1421 * possible to let that go to the right netdev!
1423 mutex_lock(&cfg80211_mutex
);
1425 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1426 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1428 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1429 if (netdev
&& netdev
->ieee80211_ptr
) {
1430 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1431 mutex_lock(&rdev
->mtx
);
1437 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1440 mutex_unlock(&cfg80211_mutex
);
1441 return PTR_ERR(rdev
);
1447 mutex_lock(&rdev
->mtx
);
1448 } else if (nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1449 wdev
= netdev
->ieee80211_ptr
;
1454 * end workaround code, by now the rdev is available
1455 * and locked, and wdev may or may not be NULL.
1458 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1459 result
= cfg80211_dev_rename(
1460 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1462 mutex_unlock(&cfg80211_mutex
);
1467 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1468 struct ieee80211_txq_params txq_params
;
1469 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1471 if (!rdev
->ops
->set_txq_params
) {
1472 result
= -EOPNOTSUPP
;
1481 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1482 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1487 if (!netif_running(netdev
)) {
1492 nla_for_each_nested(nl_txq_params
,
1493 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1495 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1496 nla_data(nl_txq_params
),
1497 nla_len(nl_txq_params
),
1499 result
= parse_txq_params(tb
, &txq_params
);
1503 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1511 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1512 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1517 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1518 enum nl80211_tx_power_setting type
;
1521 if (!rdev
->ops
->set_tx_power
) {
1522 result
= -EOPNOTSUPP
;
1526 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1527 type
= nla_get_u32(info
->attrs
[idx
]);
1529 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1530 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1535 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1536 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1537 mbm
= nla_get_u32(info
->attrs
[idx
]);
1540 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1545 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1546 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1548 if ((!rdev
->wiphy
.available_antennas_tx
&&
1549 !rdev
->wiphy
.available_antennas_rx
) ||
1550 !rdev
->ops
->set_antenna
) {
1551 result
= -EOPNOTSUPP
;
1555 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1556 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1558 /* reject antenna configurations which don't match the
1559 * available antenna masks, except for the "all" mask */
1560 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1561 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1566 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1567 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1569 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1576 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1577 retry_short
= nla_get_u8(
1578 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1579 if (retry_short
== 0) {
1583 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1586 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1587 retry_long
= nla_get_u8(
1588 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1589 if (retry_long
== 0) {
1593 changed
|= WIPHY_PARAM_RETRY_LONG
;
1596 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1597 frag_threshold
= nla_get_u32(
1598 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1599 if (frag_threshold
< 256) {
1603 if (frag_threshold
!= (u32
) -1) {
1605 * Fragments (apart from the last one) are required to
1606 * have even length. Make the fragmentation code
1607 * simpler by stripping LSB should someone try to use
1608 * odd threshold value.
1610 frag_threshold
&= ~0x1;
1612 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1615 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1616 rts_threshold
= nla_get_u32(
1617 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1618 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1621 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1622 coverage_class
= nla_get_u8(
1623 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1624 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1628 u8 old_retry_short
, old_retry_long
;
1629 u32 old_frag_threshold
, old_rts_threshold
;
1630 u8 old_coverage_class
;
1632 if (!rdev
->ops
->set_wiphy_params
) {
1633 result
= -EOPNOTSUPP
;
1637 old_retry_short
= rdev
->wiphy
.retry_short
;
1638 old_retry_long
= rdev
->wiphy
.retry_long
;
1639 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1640 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1641 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1643 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1644 rdev
->wiphy
.retry_short
= retry_short
;
1645 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1646 rdev
->wiphy
.retry_long
= retry_long
;
1647 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1648 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1649 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1650 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1651 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1652 rdev
->wiphy
.coverage_class
= coverage_class
;
1654 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1656 rdev
->wiphy
.retry_short
= old_retry_short
;
1657 rdev
->wiphy
.retry_long
= old_retry_long
;
1658 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1659 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1660 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1665 mutex_unlock(&rdev
->mtx
);
1672 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1673 struct cfg80211_registered_device
*rdev
,
1674 struct net_device
*dev
)
1678 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1682 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
1683 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1684 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
) ||
1685 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
,
1686 dev
->ieee80211_ptr
->iftype
) ||
1687 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1688 rdev
->devlist_generation
^
1689 (cfg80211_rdev_list_generation
<< 2)))
1690 goto nla_put_failure
;
1692 if (rdev
->monitor_channel
) {
1693 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
1694 rdev
->monitor_channel
->center_freq
) ||
1695 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
1696 rdev
->monitor_channel_type
))
1697 goto nla_put_failure
;
1700 return genlmsg_end(msg
, hdr
);
1703 genlmsg_cancel(msg
, hdr
);
1707 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1711 int wp_start
= cb
->args
[0];
1712 int if_start
= cb
->args
[1];
1713 struct cfg80211_registered_device
*rdev
;
1714 struct wireless_dev
*wdev
;
1716 mutex_lock(&cfg80211_mutex
);
1717 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1718 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1720 if (wp_idx
< wp_start
) {
1726 mutex_lock(&rdev
->devlist_mtx
);
1727 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1728 if (if_idx
< if_start
) {
1732 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1733 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1734 rdev
, wdev
->netdev
) < 0) {
1735 mutex_unlock(&rdev
->devlist_mtx
);
1740 mutex_unlock(&rdev
->devlist_mtx
);
1745 mutex_unlock(&cfg80211_mutex
);
1747 cb
->args
[0] = wp_idx
;
1748 cb
->args
[1] = if_idx
;
1753 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1755 struct sk_buff
*msg
;
1756 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1757 struct net_device
*netdev
= info
->user_ptr
[1];
1759 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1763 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1769 return genlmsg_reply(msg
, info
);
1772 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1773 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1774 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1775 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1776 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1777 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1780 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1782 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1790 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1791 nla
, mntr_flags_policy
))
1794 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1796 *mntrflags
|= (1<<flag
);
1801 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1802 struct net_device
*netdev
, u8 use_4addr
,
1803 enum nl80211_iftype iftype
)
1806 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1812 case NL80211_IFTYPE_AP_VLAN
:
1813 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1816 case NL80211_IFTYPE_STATION
:
1817 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1827 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1829 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1830 struct vif_params params
;
1832 enum nl80211_iftype otype
, ntype
;
1833 struct net_device
*dev
= info
->user_ptr
[1];
1834 u32 _flags
, *flags
= NULL
;
1835 bool change
= false;
1837 memset(¶ms
, 0, sizeof(params
));
1839 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1841 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1842 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1845 if (ntype
> NL80211_IFTYPE_MAX
)
1849 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1850 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1852 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1854 if (netif_running(dev
))
1858 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1859 IEEE80211_MAX_MESH_ID_LEN
);
1860 wdev
->mesh_id_up_len
=
1861 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1862 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1863 wdev
->mesh_id_up_len
);
1867 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1868 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1870 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1874 params
.use_4addr
= -1;
1877 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1878 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1880 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1890 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1894 if (!err
&& params
.use_4addr
!= -1)
1895 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1900 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1902 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1903 struct vif_params params
;
1904 struct net_device
*dev
;
1906 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1909 memset(¶ms
, 0, sizeof(params
));
1911 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1914 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1915 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1916 if (type
> NL80211_IFTYPE_MAX
)
1920 if (!rdev
->ops
->add_virtual_intf
||
1921 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1924 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1925 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1926 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1931 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1932 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1934 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1935 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1936 type
, err
? NULL
: &flags
, ¶ms
);
1938 return PTR_ERR(dev
);
1940 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1941 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1942 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1945 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1946 IEEE80211_MAX_MESH_ID_LEN
);
1947 wdev
->mesh_id_up_len
=
1948 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1949 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1950 wdev
->mesh_id_up_len
);
1957 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1959 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1960 struct net_device
*dev
= info
->user_ptr
[1];
1962 if (!rdev
->ops
->del_virtual_intf
)
1965 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1968 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
1970 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1971 struct net_device
*dev
= info
->user_ptr
[1];
1974 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
1977 if (!rdev
->ops
->set_noack_map
)
1980 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
1982 return rdev
->ops
->set_noack_map(&rdev
->wiphy
, dev
, noack_map
);
1985 struct get_key_cookie
{
1986 struct sk_buff
*msg
;
1991 static void get_key_callback(void *c
, struct key_params
*params
)
1994 struct get_key_cookie
*cookie
= c
;
1997 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1998 params
->key_len
, params
->key
)) ||
2000 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2001 params
->seq_len
, params
->seq
)) ||
2003 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2005 goto nla_put_failure
;
2007 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2009 goto nla_put_failure
;
2012 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2013 params
->key_len
, params
->key
)) ||
2015 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2016 params
->seq_len
, params
->seq
)) ||
2018 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2020 goto nla_put_failure
;
2022 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2023 goto nla_put_failure
;
2025 nla_nest_end(cookie
->msg
, key
);
2032 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2034 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2036 struct net_device
*dev
= info
->user_ptr
[1];
2038 const u8
*mac_addr
= NULL
;
2040 struct get_key_cookie cookie
= {
2044 struct sk_buff
*msg
;
2046 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2047 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2052 if (info
->attrs
[NL80211_ATTR_MAC
])
2053 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2055 pairwise
= !!mac_addr
;
2056 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2057 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2058 if (kt
>= NUM_NL80211_KEYTYPES
)
2060 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2061 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2063 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2066 if (!rdev
->ops
->get_key
)
2069 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2073 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2074 NL80211_CMD_NEW_KEY
);
2076 return PTR_ERR(hdr
);
2079 cookie
.idx
= key_idx
;
2081 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2082 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2083 goto nla_put_failure
;
2085 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2086 goto nla_put_failure
;
2088 if (pairwise
&& mac_addr
&&
2089 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2092 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
2093 mac_addr
, &cookie
, get_key_callback
);
2099 goto nla_put_failure
;
2101 genlmsg_end(msg
, hdr
);
2102 return genlmsg_reply(msg
, info
);
2111 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2113 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2114 struct key_parse key
;
2116 struct net_device
*dev
= info
->user_ptr
[1];
2118 err
= nl80211_parse_key(info
, &key
);
2125 /* only support setting default key */
2126 if (!key
.def
&& !key
.defmgmt
)
2129 wdev_lock(dev
->ieee80211_ptr
);
2132 if (!rdev
->ops
->set_default_key
) {
2137 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2141 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
2142 key
.def_uni
, key
.def_multi
);
2147 #ifdef CONFIG_CFG80211_WEXT
2148 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2151 if (key
.def_uni
|| !key
.def_multi
) {
2156 if (!rdev
->ops
->set_default_mgmt_key
) {
2161 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2165 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
2170 #ifdef CONFIG_CFG80211_WEXT
2171 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2176 wdev_unlock(dev
->ieee80211_ptr
);
2181 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2183 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2185 struct net_device
*dev
= info
->user_ptr
[1];
2186 struct key_parse key
;
2187 const u8
*mac_addr
= NULL
;
2189 err
= nl80211_parse_key(info
, &key
);
2196 if (info
->attrs
[NL80211_ATTR_MAC
])
2197 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2199 if (key
.type
== -1) {
2201 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2203 key
.type
= NL80211_KEYTYPE_GROUP
;
2207 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2208 key
.type
!= NL80211_KEYTYPE_GROUP
)
2211 if (!rdev
->ops
->add_key
)
2214 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2215 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2219 wdev_lock(dev
->ieee80211_ptr
);
2220 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2222 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
2223 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2225 wdev_unlock(dev
->ieee80211_ptr
);
2230 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2232 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2234 struct net_device
*dev
= info
->user_ptr
[1];
2235 u8
*mac_addr
= NULL
;
2236 struct key_parse key
;
2238 err
= nl80211_parse_key(info
, &key
);
2242 if (info
->attrs
[NL80211_ATTR_MAC
])
2243 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2245 if (key
.type
== -1) {
2247 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2249 key
.type
= NL80211_KEYTYPE_GROUP
;
2253 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2254 key
.type
!= NL80211_KEYTYPE_GROUP
)
2257 if (!rdev
->ops
->del_key
)
2260 wdev_lock(dev
->ieee80211_ptr
);
2261 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2263 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2264 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2268 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
2269 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2272 #ifdef CONFIG_CFG80211_WEXT
2274 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2275 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2276 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2277 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2280 wdev_unlock(dev
->ieee80211_ptr
);
2285 static int nl80211_parse_beacon(struct genl_info
*info
,
2286 struct cfg80211_beacon_data
*bcn
)
2288 bool haveinfo
= false;
2290 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2291 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2292 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2293 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2296 memset(bcn
, 0, sizeof(*bcn
));
2298 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2299 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2300 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2306 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2307 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2309 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2316 if (info
->attrs
[NL80211_ATTR_IE
]) {
2317 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2318 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2321 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2322 bcn
->proberesp_ies
=
2323 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2324 bcn
->proberesp_ies_len
=
2325 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2328 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2329 bcn
->assocresp_ies
=
2330 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2331 bcn
->assocresp_ies_len
=
2332 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2335 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2337 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2338 bcn
->probe_resp_len
=
2339 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2345 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2346 struct cfg80211_ap_settings
*params
)
2348 struct wireless_dev
*wdev
;
2351 mutex_lock(&rdev
->devlist_mtx
);
2353 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
2354 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2355 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2358 if (!wdev
->preset_chan
)
2361 params
->channel
= wdev
->preset_chan
;
2362 params
->channel_type
= wdev
->preset_chantype
;
2367 mutex_unlock(&rdev
->devlist_mtx
);
2372 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2374 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2375 struct net_device
*dev
= info
->user_ptr
[1];
2376 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2377 struct cfg80211_ap_settings params
;
2380 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2381 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2384 if (!rdev
->ops
->start_ap
)
2387 if (wdev
->beacon_interval
)
2390 memset(¶ms
, 0, sizeof(params
));
2392 /* these are required for START_AP */
2393 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2394 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2395 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2398 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
2402 params
.beacon_interval
=
2403 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2404 params
.dtim_period
=
2405 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2407 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
2412 * In theory, some of these attributes should be required here
2413 * but since they were not used when the command was originally
2414 * added, keep them optional for old user space programs to let
2415 * them continue to work with drivers that do not need the
2416 * additional information -- drivers must check!
2418 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2419 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2421 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2422 if (params
.ssid_len
== 0 ||
2423 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2427 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2428 params
.hidden_ssid
= nla_get_u32(
2429 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2430 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2431 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
2432 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2436 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2438 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2439 params
.auth_type
= nla_get_u32(
2440 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2441 if (!nl80211_valid_auth_type(params
.auth_type
))
2444 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2446 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2447 NL80211_MAX_NR_CIPHER_SUITES
);
2451 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
2452 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
2454 params
.inactivity_timeout
= nla_get_u16(
2455 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
2458 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2459 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
2461 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
2462 !nl80211_valid_channel_type(info
, &channel_type
))
2465 params
.channel
= rdev_freq_to_chan(rdev
,
2466 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
2468 if (!params
.channel
)
2470 params
.channel_type
= channel_type
;
2471 } else if (wdev
->preset_chan
) {
2472 params
.channel
= wdev
->preset_chan
;
2473 params
.channel_type
= wdev
->preset_chantype
;
2474 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
2477 if (!cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, params
.channel
,
2478 params
.channel_type
))
2481 err
= rdev
->ops
->start_ap(&rdev
->wiphy
, dev
, ¶ms
);
2483 wdev
->preset_chan
= params
.channel
;
2484 wdev
->preset_chantype
= params
.channel_type
;
2485 wdev
->beacon_interval
= params
.beacon_interval
;
2486 wdev
->channel
= params
.channel
;
2491 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2493 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2494 struct net_device
*dev
= info
->user_ptr
[1];
2495 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2496 struct cfg80211_beacon_data params
;
2499 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2500 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2503 if (!rdev
->ops
->change_beacon
)
2506 if (!wdev
->beacon_interval
)
2509 err
= nl80211_parse_beacon(info
, ¶ms
);
2513 return rdev
->ops
->change_beacon(&rdev
->wiphy
, dev
, ¶ms
);
2516 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2518 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2519 struct net_device
*dev
= info
->user_ptr
[1];
2521 return cfg80211_stop_ap(rdev
, dev
);
2524 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2525 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2526 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2527 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2528 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2529 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2530 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
2533 static int parse_station_flags(struct genl_info
*info
,
2534 enum nl80211_iftype iftype
,
2535 struct station_parameters
*params
)
2537 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2542 * Try parsing the new attribute first so userspace
2543 * can specify both for older kernels.
2545 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2547 struct nl80211_sta_flag_update
*sta_flags
;
2549 sta_flags
= nla_data(nla
);
2550 params
->sta_flags_mask
= sta_flags
->mask
;
2551 params
->sta_flags_set
= sta_flags
->set
;
2552 if ((params
->sta_flags_mask
|
2553 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2558 /* if present, parse the old attribute */
2560 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2564 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2565 nla
, sta_flags_policy
))
2569 * Only allow certain flags for interface types so that
2570 * other attributes are silently ignored. Remember that
2571 * this is backward compatibility code with old userspace
2572 * and shouldn't be hit in other cases anyway.
2575 case NL80211_IFTYPE_AP
:
2576 case NL80211_IFTYPE_AP_VLAN
:
2577 case NL80211_IFTYPE_P2P_GO
:
2578 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2579 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2580 BIT(NL80211_STA_FLAG_WME
) |
2581 BIT(NL80211_STA_FLAG_MFP
);
2583 case NL80211_IFTYPE_P2P_CLIENT
:
2584 case NL80211_IFTYPE_STATION
:
2585 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2586 BIT(NL80211_STA_FLAG_TDLS_PEER
);
2588 case NL80211_IFTYPE_MESH_POINT
:
2589 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2590 BIT(NL80211_STA_FLAG_MFP
) |
2591 BIT(NL80211_STA_FLAG_AUTHORIZED
);
2596 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
2598 params
->sta_flags_set
|= (1<<flag
);
2600 /* no longer support new API additions in old API */
2601 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
2609 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2612 struct nlattr
*rate
;
2615 rate
= nla_nest_start(msg
, attr
);
2617 goto nla_put_failure
;
2619 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2620 bitrate
= cfg80211_calculate_bitrate(info
);
2622 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
)) ||
2623 ((info
->flags
& RATE_INFO_FLAGS_MCS
) &&
2624 nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
)) ||
2625 ((info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) &&
2626 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
)) ||
2627 ((info
->flags
& RATE_INFO_FLAGS_SHORT_GI
) &&
2628 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
)))
2629 goto nla_put_failure
;
2631 nla_nest_end(msg
, rate
);
2638 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2640 struct cfg80211_registered_device
*rdev
,
2641 struct net_device
*dev
,
2642 const u8
*mac_addr
, struct station_info
*sinfo
)
2645 struct nlattr
*sinfoattr
, *bss_param
;
2647 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2651 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2652 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
2653 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
2654 goto nla_put_failure
;
2656 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2658 goto nla_put_failure
;
2659 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
2660 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2661 sinfo
->connected_time
))
2662 goto nla_put_failure
;
2663 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
2664 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2665 sinfo
->inactive_time
))
2666 goto nla_put_failure
;
2667 if ((sinfo
->filled
& STATION_INFO_RX_BYTES
) &&
2668 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
2670 goto nla_put_failure
;
2671 if ((sinfo
->filled
& STATION_INFO_TX_BYTES
) &&
2672 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
2674 goto nla_put_failure
;
2675 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
2676 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
2677 goto nla_put_failure
;
2678 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
2679 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
2680 goto nla_put_failure
;
2681 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
2682 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2683 sinfo
->plink_state
))
2684 goto nla_put_failure
;
2685 switch (rdev
->wiphy
.signal_type
) {
2686 case CFG80211_SIGNAL_TYPE_MBM
:
2687 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
2688 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
2690 goto nla_put_failure
;
2691 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
2692 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2694 goto nla_put_failure
;
2699 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2700 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2701 NL80211_STA_INFO_TX_BITRATE
))
2702 goto nla_put_failure
;
2704 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2705 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2706 NL80211_STA_INFO_RX_BITRATE
))
2707 goto nla_put_failure
;
2709 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
2710 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2712 goto nla_put_failure
;
2713 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
2714 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2716 goto nla_put_failure
;
2717 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
2718 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2720 goto nla_put_failure
;
2721 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
2722 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
2724 goto nla_put_failure
;
2725 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
2726 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
2727 sinfo
->beacon_loss_count
))
2728 goto nla_put_failure
;
2729 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2730 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2732 goto nla_put_failure
;
2734 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
2735 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
2736 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
2737 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
2738 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
2739 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
2740 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2741 sinfo
->bss_param
.dtim_period
) ||
2742 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2743 sinfo
->bss_param
.beacon_interval
))
2744 goto nla_put_failure
;
2746 nla_nest_end(msg
, bss_param
);
2748 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
2749 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
2750 sizeof(struct nl80211_sta_flag_update
),
2752 goto nla_put_failure
;
2753 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
2754 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
2756 goto nla_put_failure
;
2757 nla_nest_end(msg
, sinfoattr
);
2759 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
2760 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2761 sinfo
->assoc_req_ies
))
2762 goto nla_put_failure
;
2764 return genlmsg_end(msg
, hdr
);
2767 genlmsg_cancel(msg
, hdr
);
2771 static int nl80211_dump_station(struct sk_buff
*skb
,
2772 struct netlink_callback
*cb
)
2774 struct station_info sinfo
;
2775 struct cfg80211_registered_device
*dev
;
2776 struct net_device
*netdev
;
2777 u8 mac_addr
[ETH_ALEN
];
2778 int sta_idx
= cb
->args
[1];
2781 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2785 if (!dev
->ops
->dump_station
) {
2791 memset(&sinfo
, 0, sizeof(sinfo
));
2792 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2799 if (nl80211_send_station(skb
,
2800 NETLINK_CB(cb
->skb
).pid
,
2801 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2802 dev
, netdev
, mac_addr
,
2811 cb
->args
[1] = sta_idx
;
2814 nl80211_finish_netdev_dump(dev
);
2819 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2821 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2822 struct net_device
*dev
= info
->user_ptr
[1];
2823 struct station_info sinfo
;
2824 struct sk_buff
*msg
;
2825 u8
*mac_addr
= NULL
;
2828 memset(&sinfo
, 0, sizeof(sinfo
));
2830 if (!info
->attrs
[NL80211_ATTR_MAC
])
2833 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2835 if (!rdev
->ops
->get_station
)
2838 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2842 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2846 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2847 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
2852 return genlmsg_reply(msg
, info
);
2856 * Get vlan interface making sure it is running and on the right wiphy.
2858 static struct net_device
*get_vlan(struct genl_info
*info
,
2859 struct cfg80211_registered_device
*rdev
)
2861 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2862 struct net_device
*v
;
2868 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
2870 return ERR_PTR(-ENODEV
);
2872 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
2877 if (!netif_running(v
)) {
2885 return ERR_PTR(ret
);
2888 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2890 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2892 struct net_device
*dev
= info
->user_ptr
[1];
2893 struct station_parameters params
;
2894 u8
*mac_addr
= NULL
;
2896 memset(¶ms
, 0, sizeof(params
));
2898 params
.listen_interval
= -1;
2899 params
.plink_state
= -1;
2901 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2904 if (!info
->attrs
[NL80211_ATTR_MAC
])
2907 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2909 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2910 params
.supported_rates
=
2911 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2912 params
.supported_rates_len
=
2913 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2916 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2917 params
.listen_interval
=
2918 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2920 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2922 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2924 if (!rdev
->ops
->change_station
)
2927 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
2930 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2931 params
.plink_action
=
2932 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2934 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2935 params
.plink_state
=
2936 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2938 switch (dev
->ieee80211_ptr
->iftype
) {
2939 case NL80211_IFTYPE_AP
:
2940 case NL80211_IFTYPE_AP_VLAN
:
2941 case NL80211_IFTYPE_P2P_GO
:
2942 /* disallow mesh-specific things */
2943 if (params
.plink_action
)
2946 /* TDLS can't be set, ... */
2947 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
2950 * ... but don't bother the driver with it. This works around
2951 * a hostapd/wpa_supplicant issue -- it always includes the
2952 * TLDS_PEER flag in the mask even for AP mode.
2954 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
2956 /* accept only the listed bits */
2957 if (params
.sta_flags_mask
&
2958 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2959 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2960 BIT(NL80211_STA_FLAG_WME
) |
2961 BIT(NL80211_STA_FLAG_MFP
)))
2964 /* must be last in here for error handling */
2965 params
.vlan
= get_vlan(info
, rdev
);
2966 if (IS_ERR(params
.vlan
))
2967 return PTR_ERR(params
.vlan
);
2969 case NL80211_IFTYPE_P2P_CLIENT
:
2970 case NL80211_IFTYPE_STATION
:
2972 * Don't allow userspace to change the TDLS_PEER flag,
2973 * but silently ignore attempts to change it since we
2974 * don't have state here to verify that it doesn't try
2975 * to change the flag.
2977 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
2979 case NL80211_IFTYPE_ADHOC
:
2980 /* disallow things sta doesn't support */
2981 if (params
.plink_action
)
2985 if (params
.listen_interval
>= 0)
2987 /* reject any changes other than AUTHORIZED */
2988 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2991 case NL80211_IFTYPE_MESH_POINT
:
2992 /* disallow things mesh doesn't support */
2997 if (params
.listen_interval
>= 0)
3000 * No special handling for TDLS here -- the userspace
3001 * mesh code doesn't have this bug.
3003 if (params
.sta_flags_mask
&
3004 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3005 BIT(NL80211_STA_FLAG_MFP
) |
3006 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3013 /* be aware of params.vlan when changing code here */
3015 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3018 dev_put(params
.vlan
);
3023 static struct nla_policy
3024 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3025 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3026 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3029 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3031 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3033 struct net_device
*dev
= info
->user_ptr
[1];
3034 struct station_parameters params
;
3035 u8
*mac_addr
= NULL
;
3037 memset(¶ms
, 0, sizeof(params
));
3039 if (!info
->attrs
[NL80211_ATTR_MAC
])
3042 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3045 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3048 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3051 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3052 params
.supported_rates
=
3053 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3054 params
.supported_rates_len
=
3055 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3056 params
.listen_interval
=
3057 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3059 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3060 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3063 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3065 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3067 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3068 params
.plink_action
=
3069 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3071 if (!rdev
->ops
->add_station
)
3074 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3077 switch (dev
->ieee80211_ptr
->iftype
) {
3078 case NL80211_IFTYPE_AP
:
3079 case NL80211_IFTYPE_AP_VLAN
:
3080 case NL80211_IFTYPE_P2P_GO
:
3081 /* parse WME attributes if sta is WME capable */
3082 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
3083 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
3084 info
->attrs
[NL80211_ATTR_STA_WME
]) {
3085 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3088 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3089 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3090 nl80211_sta_wme_policy
);
3094 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3095 params
.uapsd_queues
=
3096 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3097 if (params
.uapsd_queues
&
3098 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3101 if (tb
[NL80211_STA_WME_MAX_SP
])
3103 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3106 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3109 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3111 /* TDLS peers cannot be added */
3112 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3114 /* but don't bother the driver with it */
3115 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3117 /* must be last in here for error handling */
3118 params
.vlan
= get_vlan(info
, rdev
);
3119 if (IS_ERR(params
.vlan
))
3120 return PTR_ERR(params
.vlan
);
3122 case NL80211_IFTYPE_MESH_POINT
:
3123 /* TDLS peers cannot be added */
3124 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3127 case NL80211_IFTYPE_STATION
:
3128 /* Only TDLS peers can be added */
3129 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3131 /* Can only add if TDLS ... */
3132 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3134 /* ... with external setup is supported */
3135 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3142 /* be aware of params.vlan when changing code here */
3144 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3147 dev_put(params
.vlan
);
3151 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
3153 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3154 struct net_device
*dev
= info
->user_ptr
[1];
3155 u8
*mac_addr
= NULL
;
3157 if (info
->attrs
[NL80211_ATTR_MAC
])
3158 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3160 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3161 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3162 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
3163 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3166 if (!rdev
->ops
->del_station
)
3169 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
3172 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3173 int flags
, struct net_device
*dev
,
3174 u8
*dst
, u8
*next_hop
,
3175 struct mpath_info
*pinfo
)
3178 struct nlattr
*pinfoattr
;
3180 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3184 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3185 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
3186 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
3187 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
3188 goto nla_put_failure
;
3190 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
3192 goto nla_put_failure
;
3193 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
3194 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
3196 goto nla_put_failure
;
3197 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
3198 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
3199 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
3200 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
3202 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
3203 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
3205 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
3206 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
3208 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
3209 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
3210 pinfo
->discovery_timeout
)) ||
3211 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
3212 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
3213 pinfo
->discovery_retries
)))
3214 goto nla_put_failure
;
3216 nla_nest_end(msg
, pinfoattr
);
3218 return genlmsg_end(msg
, hdr
);
3221 genlmsg_cancel(msg
, hdr
);
3225 static int nl80211_dump_mpath(struct sk_buff
*skb
,
3226 struct netlink_callback
*cb
)
3228 struct mpath_info pinfo
;
3229 struct cfg80211_registered_device
*dev
;
3230 struct net_device
*netdev
;
3232 u8 next_hop
[ETH_ALEN
];
3233 int path_idx
= cb
->args
[1];
3236 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3240 if (!dev
->ops
->dump_mpath
) {
3245 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
3251 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
3252 dst
, next_hop
, &pinfo
);
3258 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
3259 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3260 netdev
, dst
, next_hop
,
3269 cb
->args
[1] = path_idx
;
3272 nl80211_finish_netdev_dump(dev
);
3276 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3278 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3280 struct net_device
*dev
= info
->user_ptr
[1];
3281 struct mpath_info pinfo
;
3282 struct sk_buff
*msg
;
3284 u8 next_hop
[ETH_ALEN
];
3286 memset(&pinfo
, 0, sizeof(pinfo
));
3288 if (!info
->attrs
[NL80211_ATTR_MAC
])
3291 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3293 if (!rdev
->ops
->get_mpath
)
3296 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3299 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
3303 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3307 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3308 dev
, dst
, next_hop
, &pinfo
) < 0) {
3313 return genlmsg_reply(msg
, info
);
3316 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3318 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3319 struct net_device
*dev
= info
->user_ptr
[1];
3321 u8
*next_hop
= NULL
;
3323 if (!info
->attrs
[NL80211_ATTR_MAC
])
3326 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3329 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3330 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3332 if (!rdev
->ops
->change_mpath
)
3335 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3338 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3341 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3343 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3344 struct net_device
*dev
= info
->user_ptr
[1];
3346 u8
*next_hop
= NULL
;
3348 if (!info
->attrs
[NL80211_ATTR_MAC
])
3351 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3354 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3355 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3357 if (!rdev
->ops
->add_mpath
)
3360 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3363 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3366 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3368 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3369 struct net_device
*dev
= info
->user_ptr
[1];
3372 if (info
->attrs
[NL80211_ATTR_MAC
])
3373 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3375 if (!rdev
->ops
->del_mpath
)
3378 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
3381 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
3383 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3384 struct net_device
*dev
= info
->user_ptr
[1];
3385 struct bss_parameters params
;
3387 memset(¶ms
, 0, sizeof(params
));
3388 /* default to not changing parameters */
3389 params
.use_cts_prot
= -1;
3390 params
.use_short_preamble
= -1;
3391 params
.use_short_slot_time
= -1;
3392 params
.ap_isolate
= -1;
3393 params
.ht_opmode
= -1;
3395 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
3396 params
.use_cts_prot
=
3397 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
3398 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
3399 params
.use_short_preamble
=
3400 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
3401 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
3402 params
.use_short_slot_time
=
3403 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
3404 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3405 params
.basic_rates
=
3406 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3407 params
.basic_rates_len
=
3408 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3410 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
3411 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
3412 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
3414 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
3416 if (!rdev
->ops
->change_bss
)
3419 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3420 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3423 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
3426 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
3427 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3428 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3429 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3430 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3431 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3432 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3435 static int parse_reg_rule(struct nlattr
*tb
[],
3436 struct ieee80211_reg_rule
*reg_rule
)
3438 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3439 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3441 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3443 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3445 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3447 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3449 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3452 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3454 freq_range
->start_freq_khz
=
3455 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3456 freq_range
->end_freq_khz
=
3457 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3458 freq_range
->max_bandwidth_khz
=
3459 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3461 power_rule
->max_eirp
=
3462 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3464 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3465 power_rule
->max_antenna_gain
=
3466 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3471 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3477 * You should only get this when cfg80211 hasn't yet initialized
3478 * completely when built-in to the kernel right between the time
3479 * window between nl80211_init() and regulatory_init(), if that is
3482 mutex_lock(&cfg80211_mutex
);
3483 if (unlikely(!cfg80211_regdomain
)) {
3484 mutex_unlock(&cfg80211_mutex
);
3485 return -EINPROGRESS
;
3487 mutex_unlock(&cfg80211_mutex
);
3489 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3492 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3494 r
= regulatory_hint_user(data
);
3499 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3500 struct genl_info
*info
)
3502 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3503 struct net_device
*dev
= info
->user_ptr
[1];
3504 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3505 struct mesh_config cur_params
;
3508 struct nlattr
*pinfoattr
;
3509 struct sk_buff
*msg
;
3511 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3514 if (!rdev
->ops
->get_mesh_config
)
3518 /* If not connected, get default parameters */
3519 if (!wdev
->mesh_id_len
)
3520 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3522 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3529 /* Draw up a netlink message to send back */
3530 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3533 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3534 NL80211_CMD_GET_MESH_CONFIG
);
3537 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3539 goto nla_put_failure
;
3540 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3541 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3542 cur_params
.dot11MeshRetryTimeout
) ||
3543 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3544 cur_params
.dot11MeshConfirmTimeout
) ||
3545 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3546 cur_params
.dot11MeshHoldingTimeout
) ||
3547 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3548 cur_params
.dot11MeshMaxPeerLinks
) ||
3549 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3550 cur_params
.dot11MeshMaxRetries
) ||
3551 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
3552 cur_params
.dot11MeshTTL
) ||
3553 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3554 cur_params
.element_ttl
) ||
3555 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3556 cur_params
.auto_open_plinks
) ||
3557 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3558 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
3559 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3560 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
3561 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3562 cur_params
.path_refresh_time
) ||
3563 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3564 cur_params
.min_discovery_timeout
) ||
3565 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3566 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
3567 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3568 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
3569 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3570 cur_params
.dot11MeshHWMPperrMinInterval
) ||
3571 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3572 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
3573 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3574 cur_params
.dot11MeshHWMPRootMode
) ||
3575 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3576 cur_params
.dot11MeshHWMPRannInterval
) ||
3577 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3578 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
3579 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
3580 cur_params
.dot11MeshForwarding
) ||
3581 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3582 cur_params
.rssi_threshold
) ||
3583 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
3584 cur_params
.ht_opmode
) ||
3585 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3586 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
3587 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3588 cur_params
.dot11MeshHWMProotInterval
) ||
3589 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3590 cur_params
.dot11MeshHWMPconfirmationInterval
))
3591 goto nla_put_failure
;
3592 nla_nest_end(msg
, pinfoattr
);
3593 genlmsg_end(msg
, hdr
);
3594 return genlmsg_reply(msg
, info
);
3597 genlmsg_cancel(msg
, hdr
);
3603 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3604 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3605 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3606 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3607 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3608 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3609 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3610 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3611 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3612 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
3613 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3614 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3615 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3616 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3617 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3618 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
3619 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3620 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3621 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3622 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3623 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
3624 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
3625 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
3626 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
3627 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
3628 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
3631 static const struct nla_policy
3632 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3633 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
3634 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3635 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3636 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3637 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3638 .len
= IEEE80211_MAX_DATA_LEN
},
3639 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3642 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3643 struct mesh_config
*cfg
,
3646 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3649 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3651 if (table[attr_num]) {\
3652 cfg->param = nla_fn(table[attr_num]); \
3653 mask |= (1 << (attr_num - 1)); \
3658 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3660 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3661 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3662 nl80211_meshconf_params_policy
))
3665 /* This makes sure that there aren't more than 32 mesh config
3666 * parameters (otherwise our bitfield scheme would not work.) */
3667 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3669 /* Fill in the params struct */
3670 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3671 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3673 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3674 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3676 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3677 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3679 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3680 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3682 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3683 mask
, NL80211_MESHCONF_MAX_RETRIES
,
3685 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3686 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3687 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3688 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
3690 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3691 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3693 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
, mask
,
3694 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3696 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3697 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3699 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3700 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3702 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3703 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3705 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
, mask
,
3706 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3708 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3709 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3711 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
3712 mask
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3714 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3715 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
3716 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3718 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
3719 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
3720 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
3721 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3723 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3724 dot11MeshGateAnnouncementProtocol
, mask
,
3725 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3727 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
,
3728 mask
, NL80211_MESHCONF_FORWARDING
,
3730 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
,
3731 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3733 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
,
3734 mask
, NL80211_MESHCONF_HT_OPMODE
,
3736 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
3738 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3740 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
,
3741 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3743 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3744 dot11MeshHWMPconfirmationInterval
, mask
,
3745 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3752 #undef FILL_IN_MESH_PARAM_IF_SET
3755 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3756 struct mesh_setup
*setup
)
3758 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3760 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3762 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3763 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3764 nl80211_mesh_setup_params_policy
))
3767 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
3768 setup
->sync_method
=
3769 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
3770 IEEE80211_SYNC_METHOD_VENDOR
:
3771 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
3773 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3774 setup
->path_sel_proto
=
3775 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3776 IEEE80211_PATH_PROTOCOL_VENDOR
:
3777 IEEE80211_PATH_PROTOCOL_HWMP
;
3779 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3780 setup
->path_metric
=
3781 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3782 IEEE80211_PATH_METRIC_VENDOR
:
3783 IEEE80211_PATH_METRIC_AIRTIME
;
3786 if (tb
[NL80211_MESH_SETUP_IE
]) {
3787 struct nlattr
*ieattr
=
3788 tb
[NL80211_MESH_SETUP_IE
];
3789 if (!is_valid_ie_attr(ieattr
))
3791 setup
->ie
= nla_data(ieattr
);
3792 setup
->ie_len
= nla_len(ieattr
);
3794 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3795 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3800 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3801 struct genl_info
*info
)
3803 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3804 struct net_device
*dev
= info
->user_ptr
[1];
3805 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3806 struct mesh_config cfg
;
3810 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3813 if (!rdev
->ops
->update_mesh_config
)
3816 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3821 if (!wdev
->mesh_id_len
)
3825 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3833 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3835 struct sk_buff
*msg
;
3837 struct nlattr
*nl_reg_rules
;
3841 mutex_lock(&cfg80211_mutex
);
3843 if (!cfg80211_regdomain
)
3846 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3852 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3853 NL80211_CMD_GET_REG
);
3857 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
3858 cfg80211_regdomain
->alpha2
) ||
3859 (cfg80211_regdomain
->dfs_region
&&
3860 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
,
3861 cfg80211_regdomain
->dfs_region
)))
3862 goto nla_put_failure
;
3864 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3866 goto nla_put_failure
;
3868 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3869 struct nlattr
*nl_reg_rule
;
3870 const struct ieee80211_reg_rule
*reg_rule
;
3871 const struct ieee80211_freq_range
*freq_range
;
3872 const struct ieee80211_power_rule
*power_rule
;
3874 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3875 freq_range
= ®_rule
->freq_range
;
3876 power_rule
= ®_rule
->power_rule
;
3878 nl_reg_rule
= nla_nest_start(msg
, i
);
3880 goto nla_put_failure
;
3882 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3884 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3885 freq_range
->start_freq_khz
) ||
3886 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3887 freq_range
->end_freq_khz
) ||
3888 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3889 freq_range
->max_bandwidth_khz
) ||
3890 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3891 power_rule
->max_antenna_gain
) ||
3892 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3893 power_rule
->max_eirp
))
3894 goto nla_put_failure
;
3896 nla_nest_end(msg
, nl_reg_rule
);
3899 nla_nest_end(msg
, nl_reg_rules
);
3901 genlmsg_end(msg
, hdr
);
3902 err
= genlmsg_reply(msg
, info
);
3906 genlmsg_cancel(msg
, hdr
);
3911 mutex_unlock(&cfg80211_mutex
);
3915 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3917 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3918 struct nlattr
*nl_reg_rule
;
3919 char *alpha2
= NULL
;
3920 int rem_reg_rules
= 0, r
= 0;
3921 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3923 struct ieee80211_regdomain
*rd
= NULL
;
3925 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3928 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3931 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3933 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
3934 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
3936 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3939 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3943 mutex_lock(&cfg80211_mutex
);
3945 if (!reg_is_valid_request(alpha2
)) {
3950 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3951 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3953 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3959 rd
->n_reg_rules
= num_rules
;
3960 rd
->alpha2
[0] = alpha2
[0];
3961 rd
->alpha2
[1] = alpha2
[1];
3964 * Disable DFS master mode if the DFS region was
3965 * not supported or known on this kernel.
3967 if (reg_supported_dfs_region(dfs_region
))
3968 rd
->dfs_region
= dfs_region
;
3970 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3972 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3973 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3975 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3981 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3987 BUG_ON(rule_idx
!= num_rules
);
3991 mutex_unlock(&cfg80211_mutex
);
3996 mutex_unlock(&cfg80211_mutex
);
4001 static int validate_scan_freqs(struct nlattr
*freqs
)
4003 struct nlattr
*attr1
, *attr2
;
4004 int n_channels
= 0, tmp1
, tmp2
;
4006 nla_for_each_nested(attr1
, freqs
, tmp1
) {
4009 * Some hardware has a limited channel list for
4010 * scanning, and it is pretty much nonsensical
4011 * to scan for a channel twice, so disallow that
4012 * and don't require drivers to check that the
4013 * channel list they get isn't longer than what
4014 * they can scan, as long as they can scan all
4015 * the channels they registered at once.
4017 nla_for_each_nested(attr2
, freqs
, tmp2
)
4018 if (attr1
!= attr2
&&
4019 nla_get_u32(attr1
) == nla_get_u32(attr2
))
4026 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
4028 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4029 struct net_device
*dev
= info
->user_ptr
[1];
4030 struct cfg80211_scan_request
*request
;
4031 struct nlattr
*attr
;
4032 struct wiphy
*wiphy
;
4033 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
4036 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4039 wiphy
= &rdev
->wiphy
;
4041 if (!rdev
->ops
->scan
)
4047 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4048 n_channels
= validate_scan_freqs(
4049 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4053 enum ieee80211_band band
;
4056 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4057 if (wiphy
->bands
[band
])
4058 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4061 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4062 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
4065 if (n_ssids
> wiphy
->max_scan_ssids
)
4068 if (info
->attrs
[NL80211_ATTR_IE
])
4069 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4073 if (ie_len
> wiphy
->max_scan_ie_len
)
4076 request
= kzalloc(sizeof(*request
)
4077 + sizeof(*request
->ssids
) * n_ssids
4078 + sizeof(*request
->channels
) * n_channels
4079 + ie_len
, GFP_KERNEL
);
4084 request
->ssids
= (void *)&request
->channels
[n_channels
];
4085 request
->n_ssids
= n_ssids
;
4088 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4090 request
->ie
= (void *)(request
->channels
+ n_channels
);
4094 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4095 /* user specified, bail out if channel not found */
4096 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
4097 struct ieee80211_channel
*chan
;
4099 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4106 /* ignore disabled channels */
4107 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4110 request
->channels
[i
] = chan
;
4114 enum ieee80211_band band
;
4117 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4119 if (!wiphy
->bands
[band
])
4121 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4122 struct ieee80211_channel
*chan
;
4124 chan
= &wiphy
->bands
[band
]->channels
[j
];
4126 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4129 request
->channels
[i
] = chan
;
4140 request
->n_channels
= i
;
4143 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4144 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
4145 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4149 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4150 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
4155 if (info
->attrs
[NL80211_ATTR_IE
]) {
4156 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4157 memcpy((void *)request
->ie
,
4158 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4162 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4163 if (wiphy
->bands
[i
])
4165 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
4167 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
4168 nla_for_each_nested(attr
,
4169 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
4171 enum ieee80211_band band
= nla_type(attr
);
4173 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4177 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
4180 &request
->rates
[band
]);
4187 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
4190 request
->wiphy
= &rdev
->wiphy
;
4192 rdev
->scan_req
= request
;
4193 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
4196 nl80211_send_scan_start(rdev
, dev
);
4200 rdev
->scan_req
= NULL
;
4207 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
4208 struct genl_info
*info
)
4210 struct cfg80211_sched_scan_request
*request
;
4211 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4212 struct net_device
*dev
= info
->user_ptr
[1];
4213 struct nlattr
*attr
;
4214 struct wiphy
*wiphy
;
4215 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
4217 enum ieee80211_band band
;
4219 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
4221 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4222 !rdev
->ops
->sched_scan_start
)
4225 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4228 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
4231 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
4235 wiphy
= &rdev
->wiphy
;
4237 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4238 n_channels
= validate_scan_freqs(
4239 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4245 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4246 if (wiphy
->bands
[band
])
4247 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4250 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4251 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4255 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
4258 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
4259 nla_for_each_nested(attr
,
4260 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4264 if (n_match_sets
> wiphy
->max_match_sets
)
4267 if (info
->attrs
[NL80211_ATTR_IE
])
4268 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4272 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
4275 mutex_lock(&rdev
->sched_scan_mtx
);
4277 if (rdev
->sched_scan_req
) {
4282 request
= kzalloc(sizeof(*request
)
4283 + sizeof(*request
->ssids
) * n_ssids
4284 + sizeof(*request
->match_sets
) * n_match_sets
4285 + sizeof(*request
->channels
) * n_channels
4286 + ie_len
, GFP_KERNEL
);
4293 request
->ssids
= (void *)&request
->channels
[n_channels
];
4294 request
->n_ssids
= n_ssids
;
4297 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4299 request
->ie
= (void *)(request
->channels
+ n_channels
);
4304 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
4305 else if (request
->ssids
)
4306 request
->match_sets
=
4307 (void *)(request
->ssids
+ n_ssids
);
4309 request
->match_sets
=
4310 (void *)(request
->channels
+ n_channels
);
4312 request
->n_match_sets
= n_match_sets
;
4315 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4316 /* user specified, bail out if channel not found */
4317 nla_for_each_nested(attr
,
4318 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
4320 struct ieee80211_channel
*chan
;
4322 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4329 /* ignore disabled channels */
4330 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4333 request
->channels
[i
] = chan
;
4338 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4340 if (!wiphy
->bands
[band
])
4342 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4343 struct ieee80211_channel
*chan
;
4345 chan
= &wiphy
->bands
[band
]->channels
[j
];
4347 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4350 request
->channels
[i
] = chan
;
4361 request
->n_channels
= i
;
4364 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4365 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4367 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4371 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4372 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
4379 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
4380 nla_for_each_nested(attr
,
4381 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4383 struct nlattr
*ssid
, *rssi
;
4385 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
4386 nla_data(attr
), nla_len(attr
),
4387 nl80211_match_policy
);
4388 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
4390 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
4394 memcpy(request
->match_sets
[i
].ssid
.ssid
,
4395 nla_data(ssid
), nla_len(ssid
));
4396 request
->match_sets
[i
].ssid
.ssid_len
=
4399 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
4401 request
->rssi_thold
= nla_get_u32(rssi
);
4403 request
->rssi_thold
=
4404 NL80211_SCAN_RSSI_THOLD_OFF
;
4409 if (info
->attrs
[NL80211_ATTR_IE
]) {
4410 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4411 memcpy((void *)request
->ie
,
4412 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4417 request
->wiphy
= &rdev
->wiphy
;
4418 request
->interval
= interval
;
4420 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
4422 rdev
->sched_scan_req
= request
;
4423 nl80211_send_sched_scan(rdev
, dev
,
4424 NL80211_CMD_START_SCHED_SCAN
);
4431 mutex_unlock(&rdev
->sched_scan_mtx
);
4435 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
4436 struct genl_info
*info
)
4438 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4441 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4442 !rdev
->ops
->sched_scan_stop
)
4445 mutex_lock(&rdev
->sched_scan_mtx
);
4446 err
= __cfg80211_stop_sched_scan(rdev
, false);
4447 mutex_unlock(&rdev
->sched_scan_mtx
);
4452 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
4454 struct cfg80211_registered_device
*rdev
,
4455 struct wireless_dev
*wdev
,
4456 struct cfg80211_internal_bss
*intbss
)
4458 struct cfg80211_bss
*res
= &intbss
->pub
;
4462 ASSERT_WDEV_LOCK(wdev
);
4464 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).pid
, seq
, flags
,
4465 NL80211_CMD_NEW_SCAN_RESULTS
);
4469 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
4471 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
) ||
4472 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
4473 goto nla_put_failure
;
4475 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
4477 goto nla_put_failure
;
4478 if ((!is_zero_ether_addr(res
->bssid
) &&
4479 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)) ||
4480 (res
->information_elements
&& res
->len_information_elements
&&
4481 nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
4482 res
->len_information_elements
,
4483 res
->information_elements
)) ||
4484 (res
->beacon_ies
&& res
->len_beacon_ies
&&
4485 res
->beacon_ies
!= res
->information_elements
&&
4486 nla_put(msg
, NL80211_BSS_BEACON_IES
,
4487 res
->len_beacon_ies
, res
->beacon_ies
)))
4488 goto nla_put_failure
;
4490 nla_put_u64(msg
, NL80211_BSS_TSF
, res
->tsf
))
4491 goto nla_put_failure
;
4492 if (res
->beacon_interval
&&
4493 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
4494 goto nla_put_failure
;
4495 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
4496 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
4497 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
4498 jiffies_to_msecs(jiffies
- intbss
->ts
)))
4499 goto nla_put_failure
;
4501 switch (rdev
->wiphy
.signal_type
) {
4502 case CFG80211_SIGNAL_TYPE_MBM
:
4503 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
4504 goto nla_put_failure
;
4506 case CFG80211_SIGNAL_TYPE_UNSPEC
:
4507 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
4508 goto nla_put_failure
;
4514 switch (wdev
->iftype
) {
4515 case NL80211_IFTYPE_P2P_CLIENT
:
4516 case NL80211_IFTYPE_STATION
:
4517 if (intbss
== wdev
->current_bss
&&
4518 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4519 NL80211_BSS_STATUS_ASSOCIATED
))
4520 goto nla_put_failure
;
4522 case NL80211_IFTYPE_ADHOC
:
4523 if (intbss
== wdev
->current_bss
&&
4524 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4525 NL80211_BSS_STATUS_IBSS_JOINED
))
4526 goto nla_put_failure
;
4532 nla_nest_end(msg
, bss
);
4534 return genlmsg_end(msg
, hdr
);
4537 genlmsg_cancel(msg
, hdr
);
4541 static int nl80211_dump_scan(struct sk_buff
*skb
,
4542 struct netlink_callback
*cb
)
4544 struct cfg80211_registered_device
*rdev
;
4545 struct net_device
*dev
;
4546 struct cfg80211_internal_bss
*scan
;
4547 struct wireless_dev
*wdev
;
4548 int start
= cb
->args
[1], idx
= 0;
4551 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4555 wdev
= dev
->ieee80211_ptr
;
4558 spin_lock_bh(&rdev
->bss_lock
);
4559 cfg80211_bss_expire(rdev
);
4561 cb
->seq
= rdev
->bss_generation
;
4563 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4566 if (nl80211_send_bss(skb
, cb
,
4567 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4568 rdev
, wdev
, scan
) < 0) {
4574 spin_unlock_bh(&rdev
->bss_lock
);
4578 nl80211_finish_netdev_dump(rdev
);
4583 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
4584 int flags
, struct net_device
*dev
,
4585 struct survey_info
*survey
)
4588 struct nlattr
*infoattr
;
4590 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
4591 NL80211_CMD_NEW_SURVEY_RESULTS
);
4595 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
4596 goto nla_put_failure
;
4598 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4600 goto nla_put_failure
;
4602 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4603 survey
->channel
->center_freq
))
4604 goto nla_put_failure
;
4606 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
4607 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
4608 goto nla_put_failure
;
4609 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
4610 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
4611 goto nla_put_failure
;
4612 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
4613 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4614 survey
->channel_time
))
4615 goto nla_put_failure
;
4616 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
4617 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4618 survey
->channel_time_busy
))
4619 goto nla_put_failure
;
4620 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
4621 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4622 survey
->channel_time_ext_busy
))
4623 goto nla_put_failure
;
4624 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
4625 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4626 survey
->channel_time_rx
))
4627 goto nla_put_failure
;
4628 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
4629 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4630 survey
->channel_time_tx
))
4631 goto nla_put_failure
;
4633 nla_nest_end(msg
, infoattr
);
4635 return genlmsg_end(msg
, hdr
);
4638 genlmsg_cancel(msg
, hdr
);
4642 static int nl80211_dump_survey(struct sk_buff
*skb
,
4643 struct netlink_callback
*cb
)
4645 struct survey_info survey
;
4646 struct cfg80211_registered_device
*dev
;
4647 struct net_device
*netdev
;
4648 int survey_idx
= cb
->args
[1];
4651 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4655 if (!dev
->ops
->dump_survey
) {
4661 struct ieee80211_channel
*chan
;
4663 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4670 /* Survey without a channel doesn't make sense */
4671 if (!survey
.channel
) {
4676 chan
= ieee80211_get_channel(&dev
->wiphy
,
4677 survey
.channel
->center_freq
);
4678 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4683 if (nl80211_send_survey(skb
,
4684 NETLINK_CB(cb
->skb
).pid
,
4685 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4693 cb
->args
[1] = survey_idx
;
4696 nl80211_finish_netdev_dump(dev
);
4700 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
4702 return auth_type
<= NL80211_AUTHTYPE_MAX
;
4705 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4707 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4708 NL80211_WPA_VERSION_2
));
4711 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4713 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4714 struct net_device
*dev
= info
->user_ptr
[1];
4715 struct ieee80211_channel
*chan
;
4716 const u8
*bssid
, *ssid
, *ie
= NULL
;
4717 int err
, ssid_len
, ie_len
= 0;
4718 enum nl80211_auth_type auth_type
;
4719 struct key_parse key
;
4720 bool local_state_change
;
4722 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4725 if (!info
->attrs
[NL80211_ATTR_MAC
])
4728 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4731 if (!info
->attrs
[NL80211_ATTR_SSID
])
4734 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4737 err
= nl80211_parse_key(info
, &key
);
4742 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4744 if (!key
.p
.key
|| !key
.p
.key_len
)
4746 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4747 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4748 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4749 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4761 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4762 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4771 if (!rdev
->ops
->auth
)
4774 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4775 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4778 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4779 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4780 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4781 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4784 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4785 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4787 if (info
->attrs
[NL80211_ATTR_IE
]) {
4788 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4789 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4792 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4793 if (!nl80211_valid_auth_type(auth_type
))
4796 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4799 * Since we no longer track auth state, ignore
4800 * requests to only change local state.
4802 if (local_state_change
)
4805 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4806 ssid
, ssid_len
, ie
, ie_len
,
4807 key
.p
.key
, key
.p
.key_len
, key
.idx
);
4810 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
4811 struct genl_info
*info
,
4812 struct cfg80211_crypto_settings
*settings
,
4815 memset(settings
, 0, sizeof(*settings
));
4817 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
4819 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
4821 proto
= nla_get_u16(
4822 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
4823 settings
->control_port_ethertype
= cpu_to_be16(proto
);
4824 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
4827 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4828 settings
->control_port_no_encrypt
= true;
4830 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4832 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4836 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4837 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4838 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4840 if (len
% sizeof(u32
))
4843 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4846 memcpy(settings
->ciphers_pairwise
, data
, len
);
4848 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4849 if (!cfg80211_supported_cipher_suite(
4851 settings
->ciphers_pairwise
[i
]))
4855 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4856 settings
->cipher_group
=
4857 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4858 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
4859 settings
->cipher_group
))
4863 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4864 settings
->wpa_versions
=
4865 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4866 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4870 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4874 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4875 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4876 settings
->n_akm_suites
= len
/ sizeof(u32
);
4878 if (len
% sizeof(u32
))
4881 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4884 memcpy(settings
->akm_suites
, data
, len
);
4890 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4892 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4893 struct net_device
*dev
= info
->user_ptr
[1];
4894 struct cfg80211_crypto_settings crypto
;
4895 struct ieee80211_channel
*chan
;
4896 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4897 int err
, ssid_len
, ie_len
= 0;
4898 bool use_mfp
= false;
4900 struct ieee80211_ht_cap
*ht_capa
= NULL
;
4901 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
4903 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4906 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4907 !info
->attrs
[NL80211_ATTR_SSID
] ||
4908 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4911 if (!rdev
->ops
->assoc
)
4914 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4915 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4918 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4920 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4921 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4922 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4925 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4926 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4928 if (info
->attrs
[NL80211_ATTR_IE
]) {
4929 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4930 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4933 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4934 enum nl80211_mfp mfp
=
4935 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4936 if (mfp
== NL80211_MFP_REQUIRED
)
4938 else if (mfp
!= NL80211_MFP_NO
)
4942 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4943 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4945 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
4946 flags
|= ASSOC_REQ_DISABLE_HT
;
4948 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
4950 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
4952 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
4955 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4958 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4960 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4961 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4962 &crypto
, flags
, ht_capa
,
4968 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4970 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4971 struct net_device
*dev
= info
->user_ptr
[1];
4972 const u8
*ie
= NULL
, *bssid
;
4975 bool local_state_change
;
4977 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4980 if (!info
->attrs
[NL80211_ATTR_MAC
])
4983 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4986 if (!rdev
->ops
->deauth
)
4989 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4990 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4993 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4995 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4996 if (reason_code
== 0) {
4997 /* Reason Code 0 is reserved */
5001 if (info
->attrs
[NL80211_ATTR_IE
]) {
5002 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5003 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5006 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5008 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5009 local_state_change
);
5012 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
5014 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5015 struct net_device
*dev
= info
->user_ptr
[1];
5016 const u8
*ie
= NULL
, *bssid
;
5019 bool local_state_change
;
5021 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5024 if (!info
->attrs
[NL80211_ATTR_MAC
])
5027 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5030 if (!rdev
->ops
->disassoc
)
5033 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5034 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5037 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5039 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5040 if (reason_code
== 0) {
5041 /* Reason Code 0 is reserved */
5045 if (info
->attrs
[NL80211_ATTR_IE
]) {
5046 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5047 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5050 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5052 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5053 local_state_change
);
5057 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
5058 int mcast_rate
[IEEE80211_NUM_BANDS
],
5061 struct wiphy
*wiphy
= &rdev
->wiphy
;
5065 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5066 struct ieee80211_supported_band
*sband
;
5068 sband
= wiphy
->bands
[band
];
5072 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
5073 if (sband
->bitrates
[i
].bitrate
== rateval
) {
5074 mcast_rate
[band
] = i
+ 1;
5084 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5086 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5087 struct net_device
*dev
= info
->user_ptr
[1];
5088 struct cfg80211_ibss_params ibss
;
5089 struct wiphy
*wiphy
;
5090 struct cfg80211_cached_keys
*connkeys
= NULL
;
5093 memset(&ibss
, 0, sizeof(ibss
));
5095 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5098 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5099 !info
->attrs
[NL80211_ATTR_SSID
] ||
5100 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5103 ibss
.beacon_interval
= 100;
5105 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
5106 ibss
.beacon_interval
=
5107 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5108 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
5112 if (!rdev
->ops
->join_ibss
)
5115 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5118 wiphy
= &rdev
->wiphy
;
5120 if (info
->attrs
[NL80211_ATTR_MAC
]) {
5121 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5123 if (!is_valid_ether_addr(ibss
.bssid
))
5126 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5127 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5129 if (info
->attrs
[NL80211_ATTR_IE
]) {
5130 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5131 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5134 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5135 enum nl80211_channel_type channel_type
;
5137 if (!nl80211_valid_channel_type(info
, &channel_type
))
5140 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5141 !(wiphy
->features
& NL80211_FEATURE_HT_IBSS
))
5144 ibss
.channel_type
= channel_type
;
5146 ibss
.channel_type
= NL80211_CHAN_NO_HT
;
5149 ibss
.channel
= rdev_freq_to_chan(rdev
,
5150 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
5152 if (!ibss
.channel
||
5153 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
5154 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5157 /* Both channels should be able to initiate communication */
5158 if ((ibss
.channel_type
== NL80211_CHAN_HT40PLUS
||
5159 ibss
.channel_type
== NL80211_CHAN_HT40MINUS
) &&
5160 !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, ibss
.channel
,
5164 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
5165 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5167 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5169 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5171 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5172 struct ieee80211_supported_band
*sband
=
5173 wiphy
->bands
[ibss
.channel
->band
];
5175 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
5181 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5182 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
5183 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5186 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5187 connkeys
= nl80211_parse_connkeys(rdev
,
5188 info
->attrs
[NL80211_ATTR_KEYS
]);
5189 if (IS_ERR(connkeys
))
5190 return PTR_ERR(connkeys
);
5194 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
5196 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
5202 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5204 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5205 struct net_device
*dev
= info
->user_ptr
[1];
5207 if (!rdev
->ops
->leave_ibss
)
5210 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5213 return cfg80211_leave_ibss(rdev
, dev
, false);
5216 #ifdef CONFIG_NL80211_TESTMODE
5217 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
5221 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
5223 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5226 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
5230 if (rdev
->ops
->testmode_cmd
) {
5231 rdev
->testmode_info
= info
;
5232 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
5233 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
5234 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
5235 rdev
->testmode_info
= NULL
;
5241 static int nl80211_testmode_dump(struct sk_buff
*skb
,
5242 struct netlink_callback
*cb
)
5244 struct cfg80211_registered_device
*rdev
;
5252 * 0 is a valid index, but not valid for args[0],
5253 * so we need to offset by 1.
5255 phy_idx
= cb
->args
[0] - 1;
5257 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
5258 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
5263 mutex_lock(&cfg80211_mutex
);
5264 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
5265 nl80211_fam
.attrbuf
);
5267 mutex_unlock(&cfg80211_mutex
);
5268 return PTR_ERR(rdev
);
5270 phy_idx
= rdev
->wiphy_idx
;
5272 mutex_unlock(&cfg80211_mutex
);
5274 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
5276 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
5280 data
= nla_data((void *)cb
->args
[1]);
5281 data_len
= nla_len((void *)cb
->args
[1]);
5284 mutex_lock(&cfg80211_mutex
);
5285 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
5287 mutex_unlock(&cfg80211_mutex
);
5290 cfg80211_lock_rdev(rdev
);
5291 mutex_unlock(&cfg80211_mutex
);
5293 if (!rdev
->ops
->testmode_dump
) {
5299 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).pid
,
5300 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5301 NL80211_CMD_TESTMODE
);
5302 struct nlattr
*tmdata
;
5304 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
5305 genlmsg_cancel(skb
, hdr
);
5309 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5311 genlmsg_cancel(skb
, hdr
);
5314 err
= rdev
->ops
->testmode_dump(&rdev
->wiphy
, skb
, cb
,
5316 nla_nest_end(skb
, tmdata
);
5318 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
5319 genlmsg_cancel(skb
, hdr
);
5322 genlmsg_cancel(skb
, hdr
);
5326 genlmsg_end(skb
, hdr
);
5331 cb
->args
[0] = phy_idx
+ 1;
5333 cfg80211_unlock_rdev(rdev
);
5337 static struct sk_buff
*
5338 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
5339 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
5341 struct sk_buff
*skb
;
5343 struct nlattr
*data
;
5345 skb
= nlmsg_new(approxlen
+ 100, gfp
);
5349 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
5355 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
5356 goto nla_put_failure
;
5357 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5359 ((void **)skb
->cb
)[0] = rdev
;
5360 ((void **)skb
->cb
)[1] = hdr
;
5361 ((void **)skb
->cb
)[2] = data
;
5370 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
5373 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5375 if (WARN_ON(!rdev
->testmode_info
))
5378 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
5379 rdev
->testmode_info
->snd_pid
,
5380 rdev
->testmode_info
->snd_seq
,
5383 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
5385 int cfg80211_testmode_reply(struct sk_buff
*skb
)
5387 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
5388 void *hdr
= ((void **)skb
->cb
)[1];
5389 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5391 if (WARN_ON(!rdev
->testmode_info
)) {
5396 nla_nest_end(skb
, data
);
5397 genlmsg_end(skb
, hdr
);
5398 return genlmsg_reply(skb
, rdev
->testmode_info
);
5400 EXPORT_SYMBOL(cfg80211_testmode_reply
);
5402 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
5403 int approxlen
, gfp_t gfp
)
5405 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5407 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
5409 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
5411 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
5413 void *hdr
= ((void **)skb
->cb
)[1];
5414 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5416 nla_nest_end(skb
, data
);
5417 genlmsg_end(skb
, hdr
);
5418 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
5420 EXPORT_SYMBOL(cfg80211_testmode_event
);
5423 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
5425 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5426 struct net_device
*dev
= info
->user_ptr
[1];
5427 struct cfg80211_connect_params connect
;
5428 struct wiphy
*wiphy
;
5429 struct cfg80211_cached_keys
*connkeys
= NULL
;
5432 memset(&connect
, 0, sizeof(connect
));
5434 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5437 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5438 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5441 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5443 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5444 if (!nl80211_valid_auth_type(connect
.auth_type
))
5447 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5449 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
5451 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
5452 NL80211_MAX_NR_CIPHER_SUITES
);
5456 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5457 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5460 wiphy
= &rdev
->wiphy
;
5462 connect
.bg_scan_period
= -1;
5463 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
5464 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
5465 connect
.bg_scan_period
=
5466 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
5469 if (info
->attrs
[NL80211_ATTR_MAC
])
5470 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5471 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5472 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5474 if (info
->attrs
[NL80211_ATTR_IE
]) {
5475 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5476 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5479 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5481 ieee80211_get_channel(wiphy
,
5482 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5483 if (!connect
.channel
||
5484 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5488 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5489 connkeys
= nl80211_parse_connkeys(rdev
,
5490 info
->attrs
[NL80211_ATTR_KEYS
]);
5491 if (IS_ERR(connkeys
))
5492 return PTR_ERR(connkeys
);
5495 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5496 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
5498 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5499 memcpy(&connect
.ht_capa_mask
,
5500 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
5501 sizeof(connect
.ht_capa_mask
));
5503 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5504 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5506 memcpy(&connect
.ht_capa
,
5507 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
5508 sizeof(connect
.ht_capa
));
5511 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
5517 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
5519 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5520 struct net_device
*dev
= info
->user_ptr
[1];
5523 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5524 reason
= WLAN_REASON_DEAUTH_LEAVING
;
5526 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5531 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5532 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5535 return cfg80211_disconnect(rdev
, dev
, reason
, true);
5538 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
5540 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5545 if (!info
->attrs
[NL80211_ATTR_PID
])
5548 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
5550 net
= get_net_ns_by_pid(pid
);
5552 return PTR_ERR(net
);
5556 /* check if anything to do */
5557 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
5558 err
= cfg80211_switch_netns(rdev
, net
);
5564 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5566 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5567 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
5568 struct cfg80211_pmksa
*pmksa
) = NULL
;
5569 struct net_device
*dev
= info
->user_ptr
[1];
5570 struct cfg80211_pmksa pmksa
;
5572 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
5574 if (!info
->attrs
[NL80211_ATTR_MAC
])
5577 if (!info
->attrs
[NL80211_ATTR_PMKID
])
5580 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
5581 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5583 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5584 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5587 switch (info
->genlhdr
->cmd
) {
5588 case NL80211_CMD_SET_PMKSA
:
5589 rdev_ops
= rdev
->ops
->set_pmksa
;
5591 case NL80211_CMD_DEL_PMKSA
:
5592 rdev_ops
= rdev
->ops
->del_pmksa
;
5602 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
5605 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5607 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5608 struct net_device
*dev
= info
->user_ptr
[1];
5610 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5611 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5614 if (!rdev
->ops
->flush_pmksa
)
5617 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
5620 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5622 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5623 struct net_device
*dev
= info
->user_ptr
[1];
5624 u8 action_code
, dialog_token
;
5628 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5629 !rdev
->ops
->tdls_mgmt
)
5632 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5633 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5634 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5635 !info
->attrs
[NL80211_ATTR_IE
] ||
5636 !info
->attrs
[NL80211_ATTR_MAC
])
5639 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5640 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5641 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5642 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5644 return rdev
->ops
->tdls_mgmt(&rdev
->wiphy
, dev
, peer
, action_code
,
5645 dialog_token
, status_code
,
5646 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5647 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5650 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5652 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5653 struct net_device
*dev
= info
->user_ptr
[1];
5654 enum nl80211_tdls_operation operation
;
5657 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5658 !rdev
->ops
->tdls_oper
)
5661 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5662 !info
->attrs
[NL80211_ATTR_MAC
])
5665 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5666 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5668 return rdev
->ops
->tdls_oper(&rdev
->wiphy
, dev
, peer
, operation
);
5671 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5672 struct genl_info
*info
)
5674 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5675 struct net_device
*dev
= info
->user_ptr
[1];
5676 struct ieee80211_channel
*chan
;
5677 struct sk_buff
*msg
;
5680 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5684 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5685 !info
->attrs
[NL80211_ATTR_DURATION
])
5688 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5690 if (!rdev
->ops
->remain_on_channel
||
5691 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
5695 * We should be on that channel for at least a minimum amount of
5696 * time (10ms) but no longer than the driver supports.
5698 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
5699 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5702 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
5703 !nl80211_valid_channel_type(info
, &channel_type
))
5706 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5707 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5711 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5715 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5716 NL80211_CMD_REMAIN_ON_CHANNEL
);
5723 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
5724 channel_type
, duration
, &cookie
);
5729 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
5730 goto nla_put_failure
;
5732 genlmsg_end(msg
, hdr
);
5734 return genlmsg_reply(msg
, info
);
5743 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5744 struct genl_info
*info
)
5746 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5747 struct net_device
*dev
= info
->user_ptr
[1];
5750 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5753 if (!rdev
->ops
->cancel_remain_on_channel
)
5756 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5758 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
5761 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5762 u8
*rates
, u8 rates_len
)
5767 for (i
= 0; i
< rates_len
; i
++) {
5768 int rate
= (rates
[i
] & 0x7f) * 5;
5770 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5771 struct ieee80211_rate
*srate
=
5772 &sband
->bitrates
[ridx
];
5773 if (rate
== srate
->bitrate
) {
5778 if (ridx
== sband
->n_bitrates
)
5779 return 0; /* rate not found */
5785 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
5786 u8
*rates
, u8 rates_len
,
5787 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
5791 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
5793 for (i
= 0; i
< rates_len
; i
++) {
5796 ridx
= rates
[i
] / 8;
5797 rbit
= BIT(rates
[i
] % 8);
5799 /* check validity */
5800 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
5803 /* check availability */
5804 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
5813 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
5814 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
5815 .len
= NL80211_MAX_SUPP_RATES
},
5816 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
5817 .len
= NL80211_MAX_SUPP_HT_RATES
},
5820 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
5821 struct genl_info
*info
)
5823 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
5824 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5825 struct cfg80211_bitrate_mask mask
;
5827 struct net_device
*dev
= info
->user_ptr
[1];
5828 struct nlattr
*tx_rates
;
5829 struct ieee80211_supported_band
*sband
;
5831 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
5834 if (!rdev
->ops
->set_bitrate_mask
)
5837 memset(&mask
, 0, sizeof(mask
));
5838 /* Default to all rates enabled */
5839 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
5840 sband
= rdev
->wiphy
.bands
[i
];
5841 mask
.control
[i
].legacy
=
5842 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
5844 memcpy(mask
.control
[i
].mcs
,
5845 sband
->ht_cap
.mcs
.rx_mask
,
5846 sizeof(mask
.control
[i
].mcs
));
5848 memset(mask
.control
[i
].mcs
, 0,
5849 sizeof(mask
.control
[i
].mcs
));
5853 * The nested attribute uses enum nl80211_band as the index. This maps
5854 * directly to the enum ieee80211_band values used in cfg80211.
5856 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
5857 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
5859 enum ieee80211_band band
= nla_type(tx_rates
);
5860 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
5862 sband
= rdev
->wiphy
.bands
[band
];
5865 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
5866 nla_len(tx_rates
), nl80211_txattr_policy
);
5867 if (tb
[NL80211_TXRATE_LEGACY
]) {
5868 mask
.control
[band
].legacy
= rateset_to_mask(
5870 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
5871 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
5872 if ((mask
.control
[band
].legacy
== 0) &&
5873 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
5876 if (tb
[NL80211_TXRATE_MCS
]) {
5877 if (!ht_rateset_to_mask(
5879 nla_data(tb
[NL80211_TXRATE_MCS
]),
5880 nla_len(tb
[NL80211_TXRATE_MCS
]),
5881 mask
.control
[band
].mcs
))
5885 if (mask
.control
[band
].legacy
== 0) {
5886 /* don't allow empty legacy rates if HT
5887 * is not even supported. */
5888 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
5891 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
5892 if (mask
.control
[band
].mcs
[i
])
5895 /* legacy and mcs rates may not be both empty */
5896 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
5901 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
5904 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5906 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5907 struct net_device
*dev
= info
->user_ptr
[1];
5908 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
5910 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
5913 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
5914 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
5916 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5917 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5918 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5919 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5920 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5921 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5922 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5925 /* not much point in registering if we can't reply */
5926 if (!rdev
->ops
->mgmt_tx
)
5929 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
5931 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
5932 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
5935 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5937 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5938 struct net_device
*dev
= info
->user_ptr
[1];
5939 struct ieee80211_channel
*chan
;
5940 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5941 bool channel_type_valid
= false;
5946 struct sk_buff
*msg
= NULL
;
5947 unsigned int wait
= 0;
5948 bool offchan
, no_cck
, dont_wait_for_ack
;
5950 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
5952 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
5953 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5956 if (!rdev
->ops
->mgmt_tx
)
5959 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5960 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5961 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5962 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5963 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5964 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5965 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5968 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
5969 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
5971 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5974 * We should wait on the channel for at least a minimum amount
5975 * of time (10ms) but no longer than the driver supports.
5977 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
5978 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
5983 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5984 if (!nl80211_valid_channel_type(info
, &channel_type
))
5986 channel_type_valid
= true;
5989 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
5991 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
5994 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5996 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5997 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
6001 if (!dont_wait_for_ack
) {
6002 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6006 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6015 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
6016 channel_type_valid
, wait
,
6017 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
6018 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
6019 no_cck
, dont_wait_for_ack
, &cookie
);
6024 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6025 goto nla_put_failure
;
6027 genlmsg_end(msg
, hdr
);
6028 return genlmsg_reply(msg
, info
);
6040 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
6042 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6043 struct net_device
*dev
= info
->user_ptr
[1];
6046 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6049 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
6052 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6053 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6054 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
6055 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
6056 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
6057 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6060 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6062 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
6065 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6067 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6068 struct wireless_dev
*wdev
;
6069 struct net_device
*dev
= info
->user_ptr
[1];
6074 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
6077 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
6079 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
6082 wdev
= dev
->ieee80211_ptr
;
6084 if (!rdev
->ops
->set_power_mgmt
)
6087 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
6089 if (state
== wdev
->ps
)
6092 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
6099 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6101 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6102 enum nl80211_ps_state ps_state
;
6103 struct wireless_dev
*wdev
;
6104 struct net_device
*dev
= info
->user_ptr
[1];
6105 struct sk_buff
*msg
;
6109 wdev
= dev
->ieee80211_ptr
;
6111 if (!rdev
->ops
->set_power_mgmt
)
6114 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6118 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6119 NL80211_CMD_GET_POWER_SAVE
);
6126 ps_state
= NL80211_PS_ENABLED
;
6128 ps_state
= NL80211_PS_DISABLED
;
6130 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
6131 goto nla_put_failure
;
6133 genlmsg_end(msg
, hdr
);
6134 return genlmsg_reply(msg
, info
);
6143 static struct nla_policy
6144 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
6145 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
6146 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
6147 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
6150 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
6151 s32 threshold
, u32 hysteresis
)
6153 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6154 struct wireless_dev
*wdev
;
6155 struct net_device
*dev
= info
->user_ptr
[1];
6160 wdev
= dev
->ieee80211_ptr
;
6162 if (!rdev
->ops
->set_cqm_rssi_config
)
6165 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6166 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6169 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
6170 threshold
, hysteresis
);
6173 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
6175 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
6179 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
6185 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
6186 nl80211_attr_cqm_policy
);
6190 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
6191 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
6194 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
6195 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
6196 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
6204 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6206 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6207 struct net_device
*dev
= info
->user_ptr
[1];
6208 struct mesh_config cfg
;
6209 struct mesh_setup setup
;
6212 /* start with default */
6213 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
6214 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
6216 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
6217 /* and parse parameters if given */
6218 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
6223 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
6224 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
6227 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6228 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6230 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6231 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
6232 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6235 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
6236 /* parse additional setup parameters if given */
6237 err
= nl80211_parse_mesh_setup(info
, &setup
);
6242 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6243 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6245 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
6246 !nl80211_valid_channel_type(info
, &channel_type
))
6249 setup
.channel
= rdev_freq_to_chan(rdev
,
6250 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
6254 setup
.channel_type
= channel_type
;
6256 /* cfg80211_join_mesh() will sort it out */
6257 setup
.channel
= NULL
;
6260 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
6263 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6265 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6266 struct net_device
*dev
= info
->user_ptr
[1];
6268 return cfg80211_leave_mesh(rdev
, dev
);
6272 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6274 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6275 struct sk_buff
*msg
;
6278 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6281 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6285 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6286 NL80211_CMD_GET_WOWLAN
);
6288 goto nla_put_failure
;
6291 struct nlattr
*nl_wowlan
;
6293 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
6295 goto nla_put_failure
;
6297 if ((rdev
->wowlan
->any
&&
6298 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
6299 (rdev
->wowlan
->disconnect
&&
6300 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
6301 (rdev
->wowlan
->magic_pkt
&&
6302 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
6303 (rdev
->wowlan
->gtk_rekey_failure
&&
6304 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
6305 (rdev
->wowlan
->eap_identity_req
&&
6306 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
6307 (rdev
->wowlan
->four_way_handshake
&&
6308 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
6309 (rdev
->wowlan
->rfkill_release
&&
6310 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
6311 goto nla_put_failure
;
6312 if (rdev
->wowlan
->n_patterns
) {
6313 struct nlattr
*nl_pats
, *nl_pat
;
6316 nl_pats
= nla_nest_start(msg
,
6317 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
6319 goto nla_put_failure
;
6321 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
6322 nl_pat
= nla_nest_start(msg
, i
+ 1);
6324 goto nla_put_failure
;
6325 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
6326 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
6327 DIV_ROUND_UP(pat_len
, 8),
6328 rdev
->wowlan
->patterns
[i
].mask
) ||
6329 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
6331 rdev
->wowlan
->patterns
[i
].pattern
))
6332 goto nla_put_failure
;
6333 nla_nest_end(msg
, nl_pat
);
6335 nla_nest_end(msg
, nl_pats
);
6338 nla_nest_end(msg
, nl_wowlan
);
6341 genlmsg_end(msg
, hdr
);
6342 return genlmsg_reply(msg
, info
);
6349 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6351 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6352 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
6353 struct cfg80211_wowlan no_triggers
= {};
6354 struct cfg80211_wowlan new_triggers
= {};
6355 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
6357 bool prev_enabled
= rdev
->wowlan
;
6359 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6362 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
6365 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
6366 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6367 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6368 nl80211_wowlan_policy
);
6372 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
6373 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
6375 new_triggers
.any
= true;
6378 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
6379 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
6381 new_triggers
.disconnect
= true;
6384 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
6385 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
6387 new_triggers
.magic_pkt
= true;
6390 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
6393 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
6394 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
6396 new_triggers
.gtk_rekey_failure
= true;
6399 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
6400 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
6402 new_triggers
.eap_identity_req
= true;
6405 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
6406 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
6408 new_triggers
.four_way_handshake
= true;
6411 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
6412 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
6414 new_triggers
.rfkill_release
= true;
6417 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
6420 int rem
, pat_len
, mask_len
;
6421 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
6423 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6426 if (n_patterns
> wowlan
->n_patterns
)
6429 new_triggers
.patterns
= kcalloc(n_patterns
,
6430 sizeof(new_triggers
.patterns
[0]),
6432 if (!new_triggers
.patterns
)
6435 new_triggers
.n_patterns
= n_patterns
;
6438 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6440 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
6441 nla_data(pat
), nla_len(pat
), NULL
);
6443 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
6444 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
6446 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
6447 mask_len
= DIV_ROUND_UP(pat_len
, 8);
6448 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
6451 if (pat_len
> wowlan
->pattern_max_len
||
6452 pat_len
< wowlan
->pattern_min_len
)
6455 new_triggers
.patterns
[i
].mask
=
6456 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
6457 if (!new_triggers
.patterns
[i
].mask
) {
6461 new_triggers
.patterns
[i
].pattern
=
6462 new_triggers
.patterns
[i
].mask
+ mask_len
;
6463 memcpy(new_triggers
.patterns
[i
].mask
,
6464 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
6466 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
6467 memcpy(new_triggers
.patterns
[i
].pattern
,
6468 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
6474 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
6475 struct cfg80211_wowlan
*ntrig
;
6476 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
6482 cfg80211_rdev_free_wowlan(rdev
);
6483 rdev
->wowlan
= ntrig
;
6486 cfg80211_rdev_free_wowlan(rdev
);
6487 rdev
->wowlan
= NULL
;
6490 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
6491 rdev
->ops
->set_wakeup(&rdev
->wiphy
, rdev
->wowlan
);
6495 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
6496 kfree(new_triggers
.patterns
[i
].mask
);
6497 kfree(new_triggers
.patterns
);
6502 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
6504 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6505 struct net_device
*dev
= info
->user_ptr
[1];
6506 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6507 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
6508 struct cfg80211_gtk_rekey_data rekey_data
;
6511 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
6514 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
6515 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6516 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6517 nl80211_rekey_policy
);
6521 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
6523 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
6525 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
6528 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
6530 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
6532 memcpy(rekey_data
.replay_ctr
,
6533 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
6534 NL80211_REPLAY_CTR_LEN
);
6537 if (!wdev
->current_bss
) {
6542 if (!rdev
->ops
->set_rekey_data
) {
6547 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
6553 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
6554 struct genl_info
*info
)
6556 struct net_device
*dev
= info
->user_ptr
[1];
6557 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6559 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6560 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6563 if (wdev
->ap_unexpected_nlpid
)
6566 wdev
->ap_unexpected_nlpid
= info
->snd_pid
;
6570 static int nl80211_probe_client(struct sk_buff
*skb
,
6571 struct genl_info
*info
)
6573 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6574 struct net_device
*dev
= info
->user_ptr
[1];
6575 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6576 struct sk_buff
*msg
;
6582 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6583 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6586 if (!info
->attrs
[NL80211_ATTR_MAC
])
6589 if (!rdev
->ops
->probe_client
)
6592 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6596 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6597 NL80211_CMD_PROBE_CLIENT
);
6604 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6606 err
= rdev
->ops
->probe_client(&rdev
->wiphy
, dev
, addr
, &cookie
);
6610 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6611 goto nla_put_failure
;
6613 genlmsg_end(msg
, hdr
);
6615 return genlmsg_reply(msg
, info
);
6624 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
6626 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6628 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
6631 if (rdev
->ap_beacons_nlpid
)
6634 rdev
->ap_beacons_nlpid
= info
->snd_pid
;
6639 #define NL80211_FLAG_NEED_WIPHY 0x01
6640 #define NL80211_FLAG_NEED_NETDEV 0x02
6641 #define NL80211_FLAG_NEED_RTNL 0x04
6642 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6643 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6644 NL80211_FLAG_CHECK_NETDEV_UP)
6646 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6647 struct genl_info
*info
)
6649 struct cfg80211_registered_device
*rdev
;
6650 struct net_device
*dev
;
6652 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
6657 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
6658 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6662 return PTR_ERR(rdev
);
6664 info
->user_ptr
[0] = rdev
;
6665 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
6666 err
= get_rdev_dev_by_ifindex(genl_info_net(info
), info
->attrs
,
6673 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
6674 !netif_running(dev
)) {
6675 cfg80211_unlock_rdev(rdev
);
6681 info
->user_ptr
[0] = rdev
;
6682 info
->user_ptr
[1] = dev
;
6688 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6689 struct genl_info
*info
)
6691 if (info
->user_ptr
[0])
6692 cfg80211_unlock_rdev(info
->user_ptr
[0]);
6693 if (info
->user_ptr
[1])
6694 dev_put(info
->user_ptr
[1]);
6695 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
6699 static struct genl_ops nl80211_ops
[] = {
6701 .cmd
= NL80211_CMD_GET_WIPHY
,
6702 .doit
= nl80211_get_wiphy
,
6703 .dumpit
= nl80211_dump_wiphy
,
6704 .policy
= nl80211_policy
,
6705 /* can be retrieved by unprivileged users */
6706 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
6709 .cmd
= NL80211_CMD_SET_WIPHY
,
6710 .doit
= nl80211_set_wiphy
,
6711 .policy
= nl80211_policy
,
6712 .flags
= GENL_ADMIN_PERM
,
6713 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
6716 .cmd
= NL80211_CMD_GET_INTERFACE
,
6717 .doit
= nl80211_get_interface
,
6718 .dumpit
= nl80211_dump_interface
,
6719 .policy
= nl80211_policy
,
6720 /* can be retrieved by unprivileged users */
6721 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
6724 .cmd
= NL80211_CMD_SET_INTERFACE
,
6725 .doit
= nl80211_set_interface
,
6726 .policy
= nl80211_policy
,
6727 .flags
= GENL_ADMIN_PERM
,
6728 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6729 NL80211_FLAG_NEED_RTNL
,
6732 .cmd
= NL80211_CMD_NEW_INTERFACE
,
6733 .doit
= nl80211_new_interface
,
6734 .policy
= nl80211_policy
,
6735 .flags
= GENL_ADMIN_PERM
,
6736 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6737 NL80211_FLAG_NEED_RTNL
,
6740 .cmd
= NL80211_CMD_DEL_INTERFACE
,
6741 .doit
= nl80211_del_interface
,
6742 .policy
= nl80211_policy
,
6743 .flags
= GENL_ADMIN_PERM
,
6744 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6745 NL80211_FLAG_NEED_RTNL
,
6748 .cmd
= NL80211_CMD_GET_KEY
,
6749 .doit
= nl80211_get_key
,
6750 .policy
= nl80211_policy
,
6751 .flags
= GENL_ADMIN_PERM
,
6752 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6753 NL80211_FLAG_NEED_RTNL
,
6756 .cmd
= NL80211_CMD_SET_KEY
,
6757 .doit
= nl80211_set_key
,
6758 .policy
= nl80211_policy
,
6759 .flags
= GENL_ADMIN_PERM
,
6760 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6761 NL80211_FLAG_NEED_RTNL
,
6764 .cmd
= NL80211_CMD_NEW_KEY
,
6765 .doit
= nl80211_new_key
,
6766 .policy
= nl80211_policy
,
6767 .flags
= GENL_ADMIN_PERM
,
6768 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6769 NL80211_FLAG_NEED_RTNL
,
6772 .cmd
= NL80211_CMD_DEL_KEY
,
6773 .doit
= nl80211_del_key
,
6774 .policy
= nl80211_policy
,
6775 .flags
= GENL_ADMIN_PERM
,
6776 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6777 NL80211_FLAG_NEED_RTNL
,
6780 .cmd
= NL80211_CMD_SET_BEACON
,
6781 .policy
= nl80211_policy
,
6782 .flags
= GENL_ADMIN_PERM
,
6783 .doit
= nl80211_set_beacon
,
6784 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6785 NL80211_FLAG_NEED_RTNL
,
6788 .cmd
= NL80211_CMD_START_AP
,
6789 .policy
= nl80211_policy
,
6790 .flags
= GENL_ADMIN_PERM
,
6791 .doit
= nl80211_start_ap
,
6792 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6793 NL80211_FLAG_NEED_RTNL
,
6796 .cmd
= NL80211_CMD_STOP_AP
,
6797 .policy
= nl80211_policy
,
6798 .flags
= GENL_ADMIN_PERM
,
6799 .doit
= nl80211_stop_ap
,
6800 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6801 NL80211_FLAG_NEED_RTNL
,
6804 .cmd
= NL80211_CMD_GET_STATION
,
6805 .doit
= nl80211_get_station
,
6806 .dumpit
= nl80211_dump_station
,
6807 .policy
= nl80211_policy
,
6808 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6809 NL80211_FLAG_NEED_RTNL
,
6812 .cmd
= NL80211_CMD_SET_STATION
,
6813 .doit
= nl80211_set_station
,
6814 .policy
= nl80211_policy
,
6815 .flags
= GENL_ADMIN_PERM
,
6816 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6817 NL80211_FLAG_NEED_RTNL
,
6820 .cmd
= NL80211_CMD_NEW_STATION
,
6821 .doit
= nl80211_new_station
,
6822 .policy
= nl80211_policy
,
6823 .flags
= GENL_ADMIN_PERM
,
6824 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6825 NL80211_FLAG_NEED_RTNL
,
6828 .cmd
= NL80211_CMD_DEL_STATION
,
6829 .doit
= nl80211_del_station
,
6830 .policy
= nl80211_policy
,
6831 .flags
= GENL_ADMIN_PERM
,
6832 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6833 NL80211_FLAG_NEED_RTNL
,
6836 .cmd
= NL80211_CMD_GET_MPATH
,
6837 .doit
= nl80211_get_mpath
,
6838 .dumpit
= nl80211_dump_mpath
,
6839 .policy
= nl80211_policy
,
6840 .flags
= GENL_ADMIN_PERM
,
6841 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6842 NL80211_FLAG_NEED_RTNL
,
6845 .cmd
= NL80211_CMD_SET_MPATH
,
6846 .doit
= nl80211_set_mpath
,
6847 .policy
= nl80211_policy
,
6848 .flags
= GENL_ADMIN_PERM
,
6849 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6850 NL80211_FLAG_NEED_RTNL
,
6853 .cmd
= NL80211_CMD_NEW_MPATH
,
6854 .doit
= nl80211_new_mpath
,
6855 .policy
= nl80211_policy
,
6856 .flags
= GENL_ADMIN_PERM
,
6857 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6858 NL80211_FLAG_NEED_RTNL
,
6861 .cmd
= NL80211_CMD_DEL_MPATH
,
6862 .doit
= nl80211_del_mpath
,
6863 .policy
= nl80211_policy
,
6864 .flags
= GENL_ADMIN_PERM
,
6865 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6866 NL80211_FLAG_NEED_RTNL
,
6869 .cmd
= NL80211_CMD_SET_BSS
,
6870 .doit
= nl80211_set_bss
,
6871 .policy
= nl80211_policy
,
6872 .flags
= GENL_ADMIN_PERM
,
6873 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6874 NL80211_FLAG_NEED_RTNL
,
6877 .cmd
= NL80211_CMD_GET_REG
,
6878 .doit
= nl80211_get_reg
,
6879 .policy
= nl80211_policy
,
6880 /* can be retrieved by unprivileged users */
6883 .cmd
= NL80211_CMD_SET_REG
,
6884 .doit
= nl80211_set_reg
,
6885 .policy
= nl80211_policy
,
6886 .flags
= GENL_ADMIN_PERM
,
6889 .cmd
= NL80211_CMD_REQ_SET_REG
,
6890 .doit
= nl80211_req_set_reg
,
6891 .policy
= nl80211_policy
,
6892 .flags
= GENL_ADMIN_PERM
,
6895 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
6896 .doit
= nl80211_get_mesh_config
,
6897 .policy
= nl80211_policy
,
6898 /* can be retrieved by unprivileged users */
6899 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6900 NL80211_FLAG_NEED_RTNL
,
6903 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
6904 .doit
= nl80211_update_mesh_config
,
6905 .policy
= nl80211_policy
,
6906 .flags
= GENL_ADMIN_PERM
,
6907 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6908 NL80211_FLAG_NEED_RTNL
,
6911 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
6912 .doit
= nl80211_trigger_scan
,
6913 .policy
= nl80211_policy
,
6914 .flags
= GENL_ADMIN_PERM
,
6915 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6916 NL80211_FLAG_NEED_RTNL
,
6919 .cmd
= NL80211_CMD_GET_SCAN
,
6920 .policy
= nl80211_policy
,
6921 .dumpit
= nl80211_dump_scan
,
6924 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
6925 .doit
= nl80211_start_sched_scan
,
6926 .policy
= nl80211_policy
,
6927 .flags
= GENL_ADMIN_PERM
,
6928 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6929 NL80211_FLAG_NEED_RTNL
,
6932 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
6933 .doit
= nl80211_stop_sched_scan
,
6934 .policy
= nl80211_policy
,
6935 .flags
= GENL_ADMIN_PERM
,
6936 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6937 NL80211_FLAG_NEED_RTNL
,
6940 .cmd
= NL80211_CMD_AUTHENTICATE
,
6941 .doit
= nl80211_authenticate
,
6942 .policy
= nl80211_policy
,
6943 .flags
= GENL_ADMIN_PERM
,
6944 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6945 NL80211_FLAG_NEED_RTNL
,
6948 .cmd
= NL80211_CMD_ASSOCIATE
,
6949 .doit
= nl80211_associate
,
6950 .policy
= nl80211_policy
,
6951 .flags
= GENL_ADMIN_PERM
,
6952 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6953 NL80211_FLAG_NEED_RTNL
,
6956 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
6957 .doit
= nl80211_deauthenticate
,
6958 .policy
= nl80211_policy
,
6959 .flags
= GENL_ADMIN_PERM
,
6960 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6961 NL80211_FLAG_NEED_RTNL
,
6964 .cmd
= NL80211_CMD_DISASSOCIATE
,
6965 .doit
= nl80211_disassociate
,
6966 .policy
= nl80211_policy
,
6967 .flags
= GENL_ADMIN_PERM
,
6968 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6969 NL80211_FLAG_NEED_RTNL
,
6972 .cmd
= NL80211_CMD_JOIN_IBSS
,
6973 .doit
= nl80211_join_ibss
,
6974 .policy
= nl80211_policy
,
6975 .flags
= GENL_ADMIN_PERM
,
6976 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6977 NL80211_FLAG_NEED_RTNL
,
6980 .cmd
= NL80211_CMD_LEAVE_IBSS
,
6981 .doit
= nl80211_leave_ibss
,
6982 .policy
= nl80211_policy
,
6983 .flags
= GENL_ADMIN_PERM
,
6984 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6985 NL80211_FLAG_NEED_RTNL
,
6987 #ifdef CONFIG_NL80211_TESTMODE
6989 .cmd
= NL80211_CMD_TESTMODE
,
6990 .doit
= nl80211_testmode_do
,
6991 .dumpit
= nl80211_testmode_dump
,
6992 .policy
= nl80211_policy
,
6993 .flags
= GENL_ADMIN_PERM
,
6994 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6995 NL80211_FLAG_NEED_RTNL
,
6999 .cmd
= NL80211_CMD_CONNECT
,
7000 .doit
= nl80211_connect
,
7001 .policy
= nl80211_policy
,
7002 .flags
= GENL_ADMIN_PERM
,
7003 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7004 NL80211_FLAG_NEED_RTNL
,
7007 .cmd
= NL80211_CMD_DISCONNECT
,
7008 .doit
= nl80211_disconnect
,
7009 .policy
= nl80211_policy
,
7010 .flags
= GENL_ADMIN_PERM
,
7011 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7012 NL80211_FLAG_NEED_RTNL
,
7015 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
7016 .doit
= nl80211_wiphy_netns
,
7017 .policy
= nl80211_policy
,
7018 .flags
= GENL_ADMIN_PERM
,
7019 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7020 NL80211_FLAG_NEED_RTNL
,
7023 .cmd
= NL80211_CMD_GET_SURVEY
,
7024 .policy
= nl80211_policy
,
7025 .dumpit
= nl80211_dump_survey
,
7028 .cmd
= NL80211_CMD_SET_PMKSA
,
7029 .doit
= nl80211_setdel_pmksa
,
7030 .policy
= nl80211_policy
,
7031 .flags
= GENL_ADMIN_PERM
,
7032 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7033 NL80211_FLAG_NEED_RTNL
,
7036 .cmd
= NL80211_CMD_DEL_PMKSA
,
7037 .doit
= nl80211_setdel_pmksa
,
7038 .policy
= nl80211_policy
,
7039 .flags
= GENL_ADMIN_PERM
,
7040 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7041 NL80211_FLAG_NEED_RTNL
,
7044 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
7045 .doit
= nl80211_flush_pmksa
,
7046 .policy
= nl80211_policy
,
7047 .flags
= GENL_ADMIN_PERM
,
7048 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7049 NL80211_FLAG_NEED_RTNL
,
7052 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
7053 .doit
= nl80211_remain_on_channel
,
7054 .policy
= nl80211_policy
,
7055 .flags
= GENL_ADMIN_PERM
,
7056 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7057 NL80211_FLAG_NEED_RTNL
,
7060 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7061 .doit
= nl80211_cancel_remain_on_channel
,
7062 .policy
= nl80211_policy
,
7063 .flags
= GENL_ADMIN_PERM
,
7064 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7065 NL80211_FLAG_NEED_RTNL
,
7068 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
7069 .doit
= nl80211_set_tx_bitrate_mask
,
7070 .policy
= nl80211_policy
,
7071 .flags
= GENL_ADMIN_PERM
,
7072 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7073 NL80211_FLAG_NEED_RTNL
,
7076 .cmd
= NL80211_CMD_REGISTER_FRAME
,
7077 .doit
= nl80211_register_mgmt
,
7078 .policy
= nl80211_policy
,
7079 .flags
= GENL_ADMIN_PERM
,
7080 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7081 NL80211_FLAG_NEED_RTNL
,
7084 .cmd
= NL80211_CMD_FRAME
,
7085 .doit
= nl80211_tx_mgmt
,
7086 .policy
= nl80211_policy
,
7087 .flags
= GENL_ADMIN_PERM
,
7088 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7089 NL80211_FLAG_NEED_RTNL
,
7092 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
7093 .doit
= nl80211_tx_mgmt_cancel_wait
,
7094 .policy
= nl80211_policy
,
7095 .flags
= GENL_ADMIN_PERM
,
7096 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7097 NL80211_FLAG_NEED_RTNL
,
7100 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
7101 .doit
= nl80211_set_power_save
,
7102 .policy
= nl80211_policy
,
7103 .flags
= GENL_ADMIN_PERM
,
7104 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7105 NL80211_FLAG_NEED_RTNL
,
7108 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
7109 .doit
= nl80211_get_power_save
,
7110 .policy
= nl80211_policy
,
7111 /* can be retrieved by unprivileged users */
7112 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7113 NL80211_FLAG_NEED_RTNL
,
7116 .cmd
= NL80211_CMD_SET_CQM
,
7117 .doit
= nl80211_set_cqm
,
7118 .policy
= nl80211_policy
,
7119 .flags
= GENL_ADMIN_PERM
,
7120 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7121 NL80211_FLAG_NEED_RTNL
,
7124 .cmd
= NL80211_CMD_SET_CHANNEL
,
7125 .doit
= nl80211_set_channel
,
7126 .policy
= nl80211_policy
,
7127 .flags
= GENL_ADMIN_PERM
,
7128 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7129 NL80211_FLAG_NEED_RTNL
,
7132 .cmd
= NL80211_CMD_SET_WDS_PEER
,
7133 .doit
= nl80211_set_wds_peer
,
7134 .policy
= nl80211_policy
,
7135 .flags
= GENL_ADMIN_PERM
,
7136 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7137 NL80211_FLAG_NEED_RTNL
,
7140 .cmd
= NL80211_CMD_JOIN_MESH
,
7141 .doit
= nl80211_join_mesh
,
7142 .policy
= nl80211_policy
,
7143 .flags
= GENL_ADMIN_PERM
,
7144 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7145 NL80211_FLAG_NEED_RTNL
,
7148 .cmd
= NL80211_CMD_LEAVE_MESH
,
7149 .doit
= nl80211_leave_mesh
,
7150 .policy
= nl80211_policy
,
7151 .flags
= GENL_ADMIN_PERM
,
7152 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7153 NL80211_FLAG_NEED_RTNL
,
7157 .cmd
= NL80211_CMD_GET_WOWLAN
,
7158 .doit
= nl80211_get_wowlan
,
7159 .policy
= nl80211_policy
,
7160 /* can be retrieved by unprivileged users */
7161 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7162 NL80211_FLAG_NEED_RTNL
,
7165 .cmd
= NL80211_CMD_SET_WOWLAN
,
7166 .doit
= nl80211_set_wowlan
,
7167 .policy
= nl80211_policy
,
7168 .flags
= GENL_ADMIN_PERM
,
7169 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7170 NL80211_FLAG_NEED_RTNL
,
7174 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
7175 .doit
= nl80211_set_rekey_data
,
7176 .policy
= nl80211_policy
,
7177 .flags
= GENL_ADMIN_PERM
,
7178 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7179 NL80211_FLAG_NEED_RTNL
,
7182 .cmd
= NL80211_CMD_TDLS_MGMT
,
7183 .doit
= nl80211_tdls_mgmt
,
7184 .policy
= nl80211_policy
,
7185 .flags
= GENL_ADMIN_PERM
,
7186 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7187 NL80211_FLAG_NEED_RTNL
,
7190 .cmd
= NL80211_CMD_TDLS_OPER
,
7191 .doit
= nl80211_tdls_oper
,
7192 .policy
= nl80211_policy
,
7193 .flags
= GENL_ADMIN_PERM
,
7194 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7195 NL80211_FLAG_NEED_RTNL
,
7198 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
7199 .doit
= nl80211_register_unexpected_frame
,
7200 .policy
= nl80211_policy
,
7201 .flags
= GENL_ADMIN_PERM
,
7202 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7203 NL80211_FLAG_NEED_RTNL
,
7206 .cmd
= NL80211_CMD_PROBE_CLIENT
,
7207 .doit
= nl80211_probe_client
,
7208 .policy
= nl80211_policy
,
7209 .flags
= GENL_ADMIN_PERM
,
7210 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7211 NL80211_FLAG_NEED_RTNL
,
7214 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
7215 .doit
= nl80211_register_beacons
,
7216 .policy
= nl80211_policy
,
7217 .flags
= GENL_ADMIN_PERM
,
7218 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7219 NL80211_FLAG_NEED_RTNL
,
7222 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
7223 .doit
= nl80211_set_noack_map
,
7224 .policy
= nl80211_policy
,
7225 .flags
= GENL_ADMIN_PERM
,
7226 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7227 NL80211_FLAG_NEED_RTNL
,
7232 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
7236 /* multicast groups */
7237 static struct genl_multicast_group nl80211_config_mcgrp
= {
7240 static struct genl_multicast_group nl80211_scan_mcgrp
= {
7243 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
7244 .name
= "regulatory",
7247 /* notification functions */
7249 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
7251 struct sk_buff
*msg
;
7253 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7257 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
7262 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7263 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
7266 static int nl80211_add_scan_req(struct sk_buff
*msg
,
7267 struct cfg80211_registered_device
*rdev
)
7269 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
7270 struct nlattr
*nest
;
7273 ASSERT_RDEV_LOCK(rdev
);
7278 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
7280 goto nla_put_failure
;
7281 for (i
= 0; i
< req
->n_ssids
; i
++) {
7282 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
7283 goto nla_put_failure
;
7285 nla_nest_end(msg
, nest
);
7287 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
7289 goto nla_put_failure
;
7290 for (i
= 0; i
< req
->n_channels
; i
++) {
7291 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
7292 goto nla_put_failure
;
7294 nla_nest_end(msg
, nest
);
7297 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
7298 goto nla_put_failure
;
7305 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
7306 struct cfg80211_registered_device
*rdev
,
7307 struct net_device
*netdev
,
7308 u32 pid
, u32 seq
, int flags
,
7313 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
7317 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7318 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7319 goto nla_put_failure
;
7321 /* ignore errors and send incomplete event anyway */
7322 nl80211_add_scan_req(msg
, rdev
);
7324 return genlmsg_end(msg
, hdr
);
7327 genlmsg_cancel(msg
, hdr
);
7332 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
7333 struct cfg80211_registered_device
*rdev
,
7334 struct net_device
*netdev
,
7335 u32 pid
, u32 seq
, int flags
, u32 cmd
)
7339 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
7343 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7344 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7345 goto nla_put_failure
;
7347 return genlmsg_end(msg
, hdr
);
7350 genlmsg_cancel(msg
, hdr
);
7354 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
7355 struct net_device
*netdev
)
7357 struct sk_buff
*msg
;
7359 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7363 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7364 NL80211_CMD_TRIGGER_SCAN
) < 0) {
7369 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7370 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7373 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
7374 struct net_device
*netdev
)
7376 struct sk_buff
*msg
;
7378 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7382 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7383 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
7388 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7389 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7392 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
7393 struct net_device
*netdev
)
7395 struct sk_buff
*msg
;
7397 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7401 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7402 NL80211_CMD_SCAN_ABORTED
) < 0) {
7407 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7408 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7411 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
7412 struct net_device
*netdev
)
7414 struct sk_buff
*msg
;
7416 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7420 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7421 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
7426 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7427 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7430 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
7431 struct net_device
*netdev
, u32 cmd
)
7433 struct sk_buff
*msg
;
7435 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7439 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
7444 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7445 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7449 * This can happen on global regulatory changes or device specific settings
7450 * based on custom world regulatory domains.
7452 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
7454 struct sk_buff
*msg
;
7457 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7461 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
7467 /* Userspace can always count this one always being set */
7468 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
7469 goto nla_put_failure
;
7471 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
7472 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7473 NL80211_REGDOM_TYPE_WORLD
))
7474 goto nla_put_failure
;
7475 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
7476 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7477 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
7478 goto nla_put_failure
;
7479 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
7480 request
->intersect
) {
7481 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7482 NL80211_REGDOM_TYPE_INTERSECTION
))
7483 goto nla_put_failure
;
7485 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7486 NL80211_REGDOM_TYPE_COUNTRY
) ||
7487 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
7489 goto nla_put_failure
;
7492 if (wiphy_idx_valid(request
->wiphy_idx
) &&
7493 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
7494 goto nla_put_failure
;
7496 genlmsg_end(msg
, hdr
);
7499 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7506 genlmsg_cancel(msg
, hdr
);
7510 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
7511 struct net_device
*netdev
,
7512 const u8
*buf
, size_t len
,
7513 enum nl80211_commands cmd
, gfp_t gfp
)
7515 struct sk_buff
*msg
;
7518 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7522 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7528 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7529 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7530 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
7531 goto nla_put_failure
;
7533 genlmsg_end(msg
, hdr
);
7535 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7536 nl80211_mlme_mcgrp
.id
, gfp
);
7540 genlmsg_cancel(msg
, hdr
);
7544 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
7545 struct net_device
*netdev
, const u8
*buf
,
7546 size_t len
, gfp_t gfp
)
7548 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7549 NL80211_CMD_AUTHENTICATE
, gfp
);
7552 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
7553 struct net_device
*netdev
, const u8
*buf
,
7554 size_t len
, gfp_t gfp
)
7556 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7557 NL80211_CMD_ASSOCIATE
, gfp
);
7560 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
7561 struct net_device
*netdev
, const u8
*buf
,
7562 size_t len
, gfp_t gfp
)
7564 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7565 NL80211_CMD_DEAUTHENTICATE
, gfp
);
7568 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
7569 struct net_device
*netdev
, const u8
*buf
,
7570 size_t len
, gfp_t gfp
)
7572 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7573 NL80211_CMD_DISASSOCIATE
, gfp
);
7576 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
7577 struct net_device
*netdev
, const u8
*buf
,
7578 size_t len
, gfp_t gfp
)
7580 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7581 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
7584 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
7585 struct net_device
*netdev
, const u8
*buf
,
7586 size_t len
, gfp_t gfp
)
7588 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7589 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
7592 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
7593 struct net_device
*netdev
, int cmd
,
7594 const u8
*addr
, gfp_t gfp
)
7596 struct sk_buff
*msg
;
7599 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7603 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7609 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7610 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7611 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
7612 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
7613 goto nla_put_failure
;
7615 genlmsg_end(msg
, hdr
);
7617 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7618 nl80211_mlme_mcgrp
.id
, gfp
);
7622 genlmsg_cancel(msg
, hdr
);
7626 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
7627 struct net_device
*netdev
, const u8
*addr
,
7630 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
7634 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
7635 struct net_device
*netdev
, const u8
*addr
,
7638 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
7642 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
7643 struct net_device
*netdev
, const u8
*bssid
,
7644 const u8
*req_ie
, size_t req_ie_len
,
7645 const u8
*resp_ie
, size_t resp_ie_len
,
7646 u16 status
, gfp_t gfp
)
7648 struct sk_buff
*msg
;
7651 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7655 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
7661 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7662 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7663 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
7664 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
7666 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
7668 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
7669 goto nla_put_failure
;
7671 genlmsg_end(msg
, hdr
);
7673 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7674 nl80211_mlme_mcgrp
.id
, gfp
);
7678 genlmsg_cancel(msg
, hdr
);
7683 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
7684 struct net_device
*netdev
, const u8
*bssid
,
7685 const u8
*req_ie
, size_t req_ie_len
,
7686 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
7688 struct sk_buff
*msg
;
7691 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7695 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
7701 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7702 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7703 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
7705 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
7707 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
7708 goto nla_put_failure
;
7710 genlmsg_end(msg
, hdr
);
7712 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7713 nl80211_mlme_mcgrp
.id
, gfp
);
7717 genlmsg_cancel(msg
, hdr
);
7722 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
7723 struct net_device
*netdev
, u16 reason
,
7724 const u8
*ie
, size_t ie_len
, bool from_ap
)
7726 struct sk_buff
*msg
;
7729 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7733 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
7739 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7740 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7741 (from_ap
&& reason
&&
7742 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
7744 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
7745 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
7746 goto nla_put_failure
;
7748 genlmsg_end(msg
, hdr
);
7750 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7751 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
7755 genlmsg_cancel(msg
, hdr
);
7760 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
7761 struct net_device
*netdev
, const u8
*bssid
,
7764 struct sk_buff
*msg
;
7767 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7771 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
7777 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7778 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7779 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
7780 goto nla_put_failure
;
7782 genlmsg_end(msg
, hdr
);
7784 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7785 nl80211_mlme_mcgrp
.id
, gfp
);
7789 genlmsg_cancel(msg
, hdr
);
7793 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
7794 struct net_device
*netdev
,
7795 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
7798 struct sk_buff
*msg
;
7801 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7805 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
7811 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7812 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7813 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
) ||
7815 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
7816 goto nla_put_failure
;
7818 genlmsg_end(msg
, hdr
);
7820 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7821 nl80211_mlme_mcgrp
.id
, gfp
);
7825 genlmsg_cancel(msg
, hdr
);
7829 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
7830 struct net_device
*netdev
, const u8
*addr
,
7831 enum nl80211_key_type key_type
, int key_id
,
7832 const u8
*tsc
, gfp_t gfp
)
7834 struct sk_buff
*msg
;
7837 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7841 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
7847 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7848 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7849 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
7850 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
7852 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
7853 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
7854 goto nla_put_failure
;
7856 genlmsg_end(msg
, hdr
);
7858 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7859 nl80211_mlme_mcgrp
.id
, gfp
);
7863 genlmsg_cancel(msg
, hdr
);
7867 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
7868 struct ieee80211_channel
*channel_before
,
7869 struct ieee80211_channel
*channel_after
)
7871 struct sk_buff
*msg
;
7873 struct nlattr
*nl_freq
;
7875 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
7879 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
7886 * Since we are applying the beacon hint to a wiphy we know its
7887 * wiphy_idx is valid
7889 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
7890 goto nla_put_failure
;
7893 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
7895 goto nla_put_failure
;
7896 if (nl80211_msg_put_channel(msg
, channel_before
))
7897 goto nla_put_failure
;
7898 nla_nest_end(msg
, nl_freq
);
7901 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
7903 goto nla_put_failure
;
7904 if (nl80211_msg_put_channel(msg
, channel_after
))
7905 goto nla_put_failure
;
7906 nla_nest_end(msg
, nl_freq
);
7908 genlmsg_end(msg
, hdr
);
7911 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7918 genlmsg_cancel(msg
, hdr
);
7922 static void nl80211_send_remain_on_chan_event(
7923 int cmd
, struct cfg80211_registered_device
*rdev
,
7924 struct net_device
*netdev
, u64 cookie
,
7925 struct ieee80211_channel
*chan
,
7926 enum nl80211_channel_type channel_type
,
7927 unsigned int duration
, gfp_t gfp
)
7929 struct sk_buff
*msg
;
7932 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7936 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7942 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7943 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7944 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
7945 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
) ||
7946 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7947 goto nla_put_failure
;
7949 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
7950 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
7951 goto nla_put_failure
;
7953 genlmsg_end(msg
, hdr
);
7955 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7956 nl80211_mlme_mcgrp
.id
, gfp
);
7960 genlmsg_cancel(msg
, hdr
);
7964 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
7965 struct net_device
*netdev
, u64 cookie
,
7966 struct ieee80211_channel
*chan
,
7967 enum nl80211_channel_type channel_type
,
7968 unsigned int duration
, gfp_t gfp
)
7970 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
7971 rdev
, netdev
, cookie
, chan
,
7972 channel_type
, duration
, gfp
);
7975 void nl80211_send_remain_on_channel_cancel(
7976 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
7977 u64 cookie
, struct ieee80211_channel
*chan
,
7978 enum nl80211_channel_type channel_type
, gfp_t gfp
)
7980 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7981 rdev
, netdev
, cookie
, chan
,
7982 channel_type
, 0, gfp
);
7985 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
7986 struct net_device
*dev
, const u8
*mac_addr
,
7987 struct station_info
*sinfo
, gfp_t gfp
)
7989 struct sk_buff
*msg
;
7991 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7995 if (nl80211_send_station(msg
, 0, 0, 0,
7996 rdev
, dev
, mac_addr
, sinfo
) < 0) {
8001 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8002 nl80211_mlme_mcgrp
.id
, gfp
);
8005 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
8006 struct net_device
*dev
, const u8
*mac_addr
,
8009 struct sk_buff
*msg
;
8012 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8016 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
8022 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8023 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
8024 goto nla_put_failure
;
8026 genlmsg_end(msg
, hdr
);
8028 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8029 nl80211_mlme_mcgrp
.id
, gfp
);
8033 genlmsg_cancel(msg
, hdr
);
8037 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
8038 const u8
*addr
, gfp_t gfp
)
8040 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8041 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8042 struct sk_buff
*msg
;
8045 u32 nlpid
= ACCESS_ONCE(wdev
->ap_unexpected_nlpid
);
8050 msg
= nlmsg_new(100, gfp
);
8054 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8060 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8061 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8062 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8063 goto nla_put_failure
;
8065 err
= genlmsg_end(msg
, hdr
);
8071 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8075 genlmsg_cancel(msg
, hdr
);
8080 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
8082 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
8086 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
8087 const u8
*addr
, gfp_t gfp
)
8089 return __nl80211_unexpected_frame(dev
,
8090 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
8094 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
8095 struct net_device
*netdev
, u32 nlpid
,
8096 int freq
, int sig_dbm
,
8097 const u8
*buf
, size_t len
, gfp_t gfp
)
8099 struct sk_buff
*msg
;
8102 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8106 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8112 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8113 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8114 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8116 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8117 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8118 goto nla_put_failure
;
8120 genlmsg_end(msg
, hdr
);
8122 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8125 genlmsg_cancel(msg
, hdr
);
8130 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
8131 struct net_device
*netdev
, u64 cookie
,
8132 const u8
*buf
, size_t len
, bool ack
,
8135 struct sk_buff
*msg
;
8138 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8142 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
8148 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8149 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8150 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
8151 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8152 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8153 goto nla_put_failure
;
8155 genlmsg_end(msg
, hdr
);
8157 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
8161 genlmsg_cancel(msg
, hdr
);
8166 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
8167 struct net_device
*netdev
,
8168 enum nl80211_cqm_rssi_threshold_event rssi_event
,
8171 struct sk_buff
*msg
;
8172 struct nlattr
*pinfoattr
;
8175 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8179 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8185 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8186 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8187 goto nla_put_failure
;
8189 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8191 goto nla_put_failure
;
8193 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
8195 goto nla_put_failure
;
8197 nla_nest_end(msg
, pinfoattr
);
8199 genlmsg_end(msg
, hdr
);
8201 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8202 nl80211_mlme_mcgrp
.id
, gfp
);
8206 genlmsg_cancel(msg
, hdr
);
8210 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
8211 struct net_device
*netdev
, const u8
*bssid
,
8212 const u8
*replay_ctr
, gfp_t gfp
)
8214 struct sk_buff
*msg
;
8215 struct nlattr
*rekey_attr
;
8218 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8222 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8228 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8229 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8230 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8231 goto nla_put_failure
;
8233 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8235 goto nla_put_failure
;
8237 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
8238 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
8239 goto nla_put_failure
;
8241 nla_nest_end(msg
, rekey_attr
);
8243 genlmsg_end(msg
, hdr
);
8245 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8246 nl80211_mlme_mcgrp
.id
, gfp
);
8250 genlmsg_cancel(msg
, hdr
);
8254 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
8255 struct net_device
*netdev
, int index
,
8256 const u8
*bssid
, bool preauth
, gfp_t gfp
)
8258 struct sk_buff
*msg
;
8259 struct nlattr
*attr
;
8262 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8266 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
8272 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8273 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8274 goto nla_put_failure
;
8276 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
8278 goto nla_put_failure
;
8280 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
8281 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
8283 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
8284 goto nla_put_failure
;
8286 nla_nest_end(msg
, attr
);
8288 genlmsg_end(msg
, hdr
);
8290 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8291 nl80211_mlme_mcgrp
.id
, gfp
);
8295 genlmsg_cancel(msg
, hdr
);
8299 void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
8300 struct net_device
*netdev
, int freq
,
8301 enum nl80211_channel_type type
, gfp_t gfp
)
8303 struct sk_buff
*msg
;
8306 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8310 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
8316 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8317 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8318 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, type
))
8319 goto nla_put_failure
;
8321 genlmsg_end(msg
, hdr
);
8323 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8324 nl80211_mlme_mcgrp
.id
, gfp
);
8328 genlmsg_cancel(msg
, hdr
);
8333 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
8334 struct net_device
*netdev
, const u8
*peer
,
8335 u32 num_packets
, gfp_t gfp
)
8337 struct sk_buff
*msg
;
8338 struct nlattr
*pinfoattr
;
8341 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8345 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8351 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8352 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8353 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8354 goto nla_put_failure
;
8356 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8358 goto nla_put_failure
;
8360 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
8361 goto nla_put_failure
;
8363 nla_nest_end(msg
, pinfoattr
);
8365 genlmsg_end(msg
, hdr
);
8367 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8368 nl80211_mlme_mcgrp
.id
, gfp
);
8372 genlmsg_cancel(msg
, hdr
);
8376 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
8377 u64 cookie
, bool acked
, gfp_t gfp
)
8379 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8380 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8381 struct sk_buff
*msg
;
8385 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8389 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
8395 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8396 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8397 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8398 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8399 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8400 goto nla_put_failure
;
8402 err
= genlmsg_end(msg
, hdr
);
8408 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8409 nl80211_mlme_mcgrp
.id
, gfp
);
8413 genlmsg_cancel(msg
, hdr
);
8416 EXPORT_SYMBOL(cfg80211_probe_status
);
8418 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
8419 const u8
*frame
, size_t len
,
8420 int freq
, int sig_dbm
, gfp_t gfp
)
8422 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8423 struct sk_buff
*msg
;
8425 u32 nlpid
= ACCESS_ONCE(rdev
->ap_beacons_nlpid
);
8430 msg
= nlmsg_new(len
+ 100, gfp
);
8434 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8440 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8442 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
8444 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8445 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
8446 goto nla_put_failure
;
8448 genlmsg_end(msg
, hdr
);
8450 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8454 genlmsg_cancel(msg
, hdr
);
8457 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
8459 static int nl80211_netlink_notify(struct notifier_block
* nb
,
8460 unsigned long state
,
8463 struct netlink_notify
*notify
= _notify
;
8464 struct cfg80211_registered_device
*rdev
;
8465 struct wireless_dev
*wdev
;
8467 if (state
!= NETLINK_URELEASE
)
8472 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
8473 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
8474 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
8475 if (rdev
->ap_beacons_nlpid
== notify
->pid
)
8476 rdev
->ap_beacons_nlpid
= 0;
8484 static struct notifier_block nl80211_netlink_notifier
= {
8485 .notifier_call
= nl80211_netlink_notify
,
8488 /* initialisation/exit functions */
8490 int nl80211_init(void)
8494 err
= genl_register_family_with_ops(&nl80211_fam
,
8495 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
8499 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
8503 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
8507 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
8511 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
8515 #ifdef CONFIG_NL80211_TESTMODE
8516 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
8521 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
8527 genl_unregister_family(&nl80211_fam
);
8531 void nl80211_exit(void)
8533 netlink_unregister_notifier(&nl80211_netlink_notifier
);
8534 genl_unregister_family(&nl80211_fam
);