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
;
924 /* add frequencies */
925 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
927 goto nla_put_failure
;
929 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
930 nl_freq
= nla_nest_start(msg
, i
);
932 goto nla_put_failure
;
934 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
936 if (nl80211_msg_put_channel(msg
, chan
))
937 goto nla_put_failure
;
939 nla_nest_end(msg
, nl_freq
);
942 nla_nest_end(msg
, nl_freqs
);
945 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
947 goto nla_put_failure
;
949 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
950 nl_rate
= nla_nest_start(msg
, i
);
952 goto nla_put_failure
;
954 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
955 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
957 goto nla_put_failure
;
958 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
960 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
961 goto nla_put_failure
;
963 nla_nest_end(msg
, nl_rate
);
966 nla_nest_end(msg
, nl_rates
);
968 nla_nest_end(msg
, nl_band
);
970 nla_nest_end(msg
, nl_bands
);
972 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
974 goto nla_put_failure
;
979 if (dev->ops->op) { \
981 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
982 goto nla_put_failure; \
986 CMD(add_virtual_intf
, NEW_INTERFACE
);
987 CMD(change_virtual_intf
, SET_INTERFACE
);
988 CMD(add_key
, NEW_KEY
);
989 CMD(start_ap
, START_AP
);
990 CMD(add_station
, NEW_STATION
);
991 CMD(add_mpath
, NEW_MPATH
);
992 CMD(update_mesh_config
, SET_MESH_CONFIG
);
993 CMD(change_bss
, SET_BSS
);
994 CMD(auth
, AUTHENTICATE
);
995 CMD(assoc
, ASSOCIATE
);
996 CMD(deauth
, DEAUTHENTICATE
);
997 CMD(disassoc
, DISASSOCIATE
);
998 CMD(join_ibss
, JOIN_IBSS
);
999 CMD(join_mesh
, JOIN_MESH
);
1000 CMD(set_pmksa
, SET_PMKSA
);
1001 CMD(del_pmksa
, DEL_PMKSA
);
1002 CMD(flush_pmksa
, FLUSH_PMKSA
);
1003 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1004 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1005 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1006 CMD(mgmt_tx
, FRAME
);
1007 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1008 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1010 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1011 goto nla_put_failure
;
1013 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1014 dev
->ops
->join_mesh
) {
1016 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1017 goto nla_put_failure
;
1019 CMD(set_wds_peer
, SET_WDS_PEER
);
1020 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1021 CMD(tdls_mgmt
, TDLS_MGMT
);
1022 CMD(tdls_oper
, TDLS_OPER
);
1024 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1025 CMD(sched_scan_start
, START_SCHED_SCAN
);
1026 CMD(probe_client
, PROBE_CLIENT
);
1027 CMD(set_noack_map
, SET_NOACK_MAP
);
1028 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1030 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1031 goto nla_put_failure
;
1034 #ifdef CONFIG_NL80211_TESTMODE
1035 CMD(testmode_cmd
, TESTMODE
);
1040 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1042 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1043 goto nla_put_failure
;
1046 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1048 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1049 goto nla_put_failure
;
1052 nla_nest_end(msg
, nl_cmds
);
1054 if (dev
->ops
->remain_on_channel
&&
1055 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1056 nla_put_u32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1057 dev
->wiphy
.max_remain_on_channel_duration
))
1058 goto nla_put_failure
;
1060 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1061 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1062 goto nla_put_failure
;
1066 struct nlattr
*nl_ftypes
, *nl_ifs
;
1067 enum nl80211_iftype ift
;
1069 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1071 goto nla_put_failure
;
1073 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1074 nl_ftypes
= nla_nest_start(msg
, ift
);
1076 goto nla_put_failure
;
1078 stypes
= mgmt_stypes
[ift
].tx
;
1081 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1082 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1083 goto nla_put_failure
;
1087 nla_nest_end(msg
, nl_ftypes
);
1090 nla_nest_end(msg
, nl_ifs
);
1092 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1094 goto nla_put_failure
;
1096 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1097 nl_ftypes
= nla_nest_start(msg
, ift
);
1099 goto nla_put_failure
;
1101 stypes
= mgmt_stypes
[ift
].rx
;
1104 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1105 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1106 goto nla_put_failure
;
1110 nla_nest_end(msg
, nl_ftypes
);
1112 nla_nest_end(msg
, nl_ifs
);
1115 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
1116 struct nlattr
*nl_wowlan
;
1118 nl_wowlan
= nla_nest_start(msg
,
1119 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1121 goto nla_put_failure
;
1123 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1124 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1125 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1126 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1127 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1128 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1129 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1130 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1131 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1132 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1133 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1134 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1135 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1136 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1137 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1138 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1139 goto nla_put_failure
;
1140 if (dev
->wiphy
.wowlan
.n_patterns
) {
1141 struct nl80211_wowlan_pattern_support pat
= {
1142 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1144 dev
->wiphy
.wowlan
.pattern_min_len
,
1146 dev
->wiphy
.wowlan
.pattern_max_len
,
1148 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1150 goto nla_put_failure
;
1153 nla_nest_end(msg
, nl_wowlan
);
1156 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1157 dev
->wiphy
.software_iftypes
))
1158 goto nla_put_failure
;
1160 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1161 goto nla_put_failure
;
1163 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1164 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1165 dev
->wiphy
.ap_sme_capa
))
1166 goto nla_put_failure
;
1168 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
,
1169 dev
->wiphy
.features
))
1170 goto nla_put_failure
;
1172 if (dev
->wiphy
.ht_capa_mod_mask
&&
1173 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1174 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1175 dev
->wiphy
.ht_capa_mod_mask
))
1176 goto nla_put_failure
;
1178 return genlmsg_end(msg
, hdr
);
1181 genlmsg_cancel(msg
, hdr
);
1185 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1188 int start
= cb
->args
[0];
1189 struct cfg80211_registered_device
*dev
;
1191 mutex_lock(&cfg80211_mutex
);
1192 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1193 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1197 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
1198 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1204 mutex_unlock(&cfg80211_mutex
);
1211 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1213 struct sk_buff
*msg
;
1214 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1216 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1220 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
1225 return genlmsg_reply(msg
, info
);
1228 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1229 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1230 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1231 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1232 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1233 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1236 static int parse_txq_params(struct nlattr
*tb
[],
1237 struct ieee80211_txq_params
*txq_params
)
1239 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1240 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1241 !tb
[NL80211_TXQ_ATTR_AIFS
])
1244 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1245 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1246 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1247 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1248 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1250 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1256 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1259 * You can only set the channel explicitly for WDS interfaces,
1260 * all others have their channel managed via their respective
1261 * "establish a connection" command (connect, join, ...)
1263 * For AP/GO and mesh mode, the channel can be set with the
1264 * channel userspace API, but is only stored and passed to the
1265 * low-level driver when the AP starts or the mesh is joined.
1266 * This is for backward compatibility, userspace can also give
1267 * the channel in the start-ap or join-mesh commands instead.
1269 * Monitors are special as they are normally slaved to
1270 * whatever else is going on, so they have their own special
1271 * operation to set the monitor channel if possible.
1274 wdev
->iftype
== NL80211_IFTYPE_AP
||
1275 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1276 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1277 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1280 static bool nl80211_valid_channel_type(struct genl_info
*info
,
1281 enum nl80211_channel_type
*channel_type
)
1283 enum nl80211_channel_type tmp
;
1285 if (!info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1288 tmp
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1289 if (tmp
!= NL80211_CHAN_NO_HT
&&
1290 tmp
!= NL80211_CHAN_HT20
&&
1291 tmp
!= NL80211_CHAN_HT40PLUS
&&
1292 tmp
!= NL80211_CHAN_HT40MINUS
)
1296 *channel_type
= tmp
;
1301 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1302 struct wireless_dev
*wdev
,
1303 struct genl_info
*info
)
1305 struct ieee80211_channel
*channel
;
1306 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1309 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1312 iftype
= wdev
->iftype
;
1314 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1317 if (!nl80211_can_set_dev_channel(wdev
))
1320 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
1321 !nl80211_valid_channel_type(info
, &channel_type
))
1324 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1326 mutex_lock(&rdev
->devlist_mtx
);
1328 case NL80211_IFTYPE_AP
:
1329 case NL80211_IFTYPE_P2P_GO
:
1330 if (wdev
->beacon_interval
) {
1334 channel
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
1335 if (!channel
|| !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
,
1341 wdev
->preset_chan
= channel
;
1342 wdev
->preset_chantype
= channel_type
;
1345 case NL80211_IFTYPE_MESH_POINT
:
1346 result
= cfg80211_set_mesh_freq(rdev
, wdev
, freq
, channel_type
);
1348 case NL80211_IFTYPE_MONITOR
:
1349 result
= cfg80211_set_monitor_channel(rdev
, freq
, channel_type
);
1354 mutex_unlock(&rdev
->devlist_mtx
);
1359 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1361 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1362 struct net_device
*netdev
= info
->user_ptr
[1];
1364 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1367 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1369 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1370 struct net_device
*dev
= info
->user_ptr
[1];
1371 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1374 if (!info
->attrs
[NL80211_ATTR_MAC
])
1377 if (netif_running(dev
))
1380 if (!rdev
->ops
->set_wds_peer
)
1383 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1386 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1387 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1391 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1393 struct cfg80211_registered_device
*rdev
;
1394 struct net_device
*netdev
= NULL
;
1395 struct wireless_dev
*wdev
;
1396 int result
= 0, rem_txq_params
= 0;
1397 struct nlattr
*nl_txq_params
;
1399 u8 retry_short
= 0, retry_long
= 0;
1400 u32 frag_threshold
= 0, rts_threshold
= 0;
1401 u8 coverage_class
= 0;
1404 * Try to find the wiphy and netdev. Normally this
1405 * function shouldn't need the netdev, but this is
1406 * done for backward compatibility -- previously
1407 * setting the channel was done per wiphy, but now
1408 * it is per netdev. Previous userland like hostapd
1409 * also passed a netdev to set_wiphy, so that it is
1410 * possible to let that go to the right netdev!
1412 mutex_lock(&cfg80211_mutex
);
1414 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1415 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1417 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1418 if (netdev
&& netdev
->ieee80211_ptr
) {
1419 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1420 mutex_lock(&rdev
->mtx
);
1426 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1429 mutex_unlock(&cfg80211_mutex
);
1430 return PTR_ERR(rdev
);
1436 mutex_lock(&rdev
->mtx
);
1437 } else if (nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1438 wdev
= netdev
->ieee80211_ptr
;
1443 * end workaround code, by now the rdev is available
1444 * and locked, and wdev may or may not be NULL.
1447 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1448 result
= cfg80211_dev_rename(
1449 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1451 mutex_unlock(&cfg80211_mutex
);
1456 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1457 struct ieee80211_txq_params txq_params
;
1458 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1460 if (!rdev
->ops
->set_txq_params
) {
1461 result
= -EOPNOTSUPP
;
1470 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1471 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1476 if (!netif_running(netdev
)) {
1481 nla_for_each_nested(nl_txq_params
,
1482 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1484 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1485 nla_data(nl_txq_params
),
1486 nla_len(nl_txq_params
),
1488 result
= parse_txq_params(tb
, &txq_params
);
1492 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1500 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1501 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1506 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1507 enum nl80211_tx_power_setting type
;
1510 if (!rdev
->ops
->set_tx_power
) {
1511 result
= -EOPNOTSUPP
;
1515 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1516 type
= nla_get_u32(info
->attrs
[idx
]);
1518 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1519 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1524 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1525 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1526 mbm
= nla_get_u32(info
->attrs
[idx
]);
1529 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1534 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1535 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1537 if ((!rdev
->wiphy
.available_antennas_tx
&&
1538 !rdev
->wiphy
.available_antennas_rx
) ||
1539 !rdev
->ops
->set_antenna
) {
1540 result
= -EOPNOTSUPP
;
1544 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1545 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1547 /* reject antenna configurations which don't match the
1548 * available antenna masks, except for the "all" mask */
1549 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1550 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1555 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1556 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1558 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1565 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1566 retry_short
= nla_get_u8(
1567 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1568 if (retry_short
== 0) {
1572 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1575 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1576 retry_long
= nla_get_u8(
1577 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1578 if (retry_long
== 0) {
1582 changed
|= WIPHY_PARAM_RETRY_LONG
;
1585 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1586 frag_threshold
= nla_get_u32(
1587 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1588 if (frag_threshold
< 256) {
1592 if (frag_threshold
!= (u32
) -1) {
1594 * Fragments (apart from the last one) are required to
1595 * have even length. Make the fragmentation code
1596 * simpler by stripping LSB should someone try to use
1597 * odd threshold value.
1599 frag_threshold
&= ~0x1;
1601 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1604 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1605 rts_threshold
= nla_get_u32(
1606 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1607 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1610 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1611 coverage_class
= nla_get_u8(
1612 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1613 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1617 u8 old_retry_short
, old_retry_long
;
1618 u32 old_frag_threshold
, old_rts_threshold
;
1619 u8 old_coverage_class
;
1621 if (!rdev
->ops
->set_wiphy_params
) {
1622 result
= -EOPNOTSUPP
;
1626 old_retry_short
= rdev
->wiphy
.retry_short
;
1627 old_retry_long
= rdev
->wiphy
.retry_long
;
1628 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1629 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1630 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1632 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1633 rdev
->wiphy
.retry_short
= retry_short
;
1634 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1635 rdev
->wiphy
.retry_long
= retry_long
;
1636 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1637 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1638 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1639 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1640 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1641 rdev
->wiphy
.coverage_class
= coverage_class
;
1643 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1645 rdev
->wiphy
.retry_short
= old_retry_short
;
1646 rdev
->wiphy
.retry_long
= old_retry_long
;
1647 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1648 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1649 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1654 mutex_unlock(&rdev
->mtx
);
1661 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1662 struct cfg80211_registered_device
*rdev
,
1663 struct net_device
*dev
)
1667 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1671 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
1672 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1673 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
) ||
1674 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
,
1675 dev
->ieee80211_ptr
->iftype
) ||
1676 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1677 rdev
->devlist_generation
^
1678 (cfg80211_rdev_list_generation
<< 2)))
1679 goto nla_put_failure
;
1681 if (rdev
->ops
->get_channel
) {
1682 struct ieee80211_channel
*chan
;
1683 enum nl80211_channel_type channel_type
;
1685 chan
= rdev
->ops
->get_channel(&rdev
->wiphy
, &channel_type
);
1687 (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
1688 chan
->center_freq
) ||
1689 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
1691 goto nla_put_failure
;
1694 return genlmsg_end(msg
, hdr
);
1697 genlmsg_cancel(msg
, hdr
);
1701 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1705 int wp_start
= cb
->args
[0];
1706 int if_start
= cb
->args
[1];
1707 struct cfg80211_registered_device
*rdev
;
1708 struct wireless_dev
*wdev
;
1710 mutex_lock(&cfg80211_mutex
);
1711 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1712 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1714 if (wp_idx
< wp_start
) {
1720 mutex_lock(&rdev
->devlist_mtx
);
1721 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1722 if (if_idx
< if_start
) {
1726 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1727 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1728 rdev
, wdev
->netdev
) < 0) {
1729 mutex_unlock(&rdev
->devlist_mtx
);
1734 mutex_unlock(&rdev
->devlist_mtx
);
1739 mutex_unlock(&cfg80211_mutex
);
1741 cb
->args
[0] = wp_idx
;
1742 cb
->args
[1] = if_idx
;
1747 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1749 struct sk_buff
*msg
;
1750 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1751 struct net_device
*netdev
= info
->user_ptr
[1];
1753 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1757 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1763 return genlmsg_reply(msg
, info
);
1766 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1767 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1768 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1769 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1770 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1771 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1774 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1776 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1784 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1785 nla
, mntr_flags_policy
))
1788 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1790 *mntrflags
|= (1<<flag
);
1795 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1796 struct net_device
*netdev
, u8 use_4addr
,
1797 enum nl80211_iftype iftype
)
1800 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1806 case NL80211_IFTYPE_AP_VLAN
:
1807 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1810 case NL80211_IFTYPE_STATION
:
1811 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1821 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1823 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1824 struct vif_params params
;
1826 enum nl80211_iftype otype
, ntype
;
1827 struct net_device
*dev
= info
->user_ptr
[1];
1828 u32 _flags
, *flags
= NULL
;
1829 bool change
= false;
1831 memset(¶ms
, 0, sizeof(params
));
1833 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1835 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1836 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1839 if (ntype
> NL80211_IFTYPE_MAX
)
1843 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1844 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1846 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1848 if (netif_running(dev
))
1852 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1853 IEEE80211_MAX_MESH_ID_LEN
);
1854 wdev
->mesh_id_up_len
=
1855 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1856 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1857 wdev
->mesh_id_up_len
);
1861 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1862 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1864 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1868 params
.use_4addr
= -1;
1871 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1872 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1874 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1884 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1888 if (!err
&& params
.use_4addr
!= -1)
1889 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1894 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1896 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1897 struct vif_params params
;
1898 struct net_device
*dev
;
1900 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1903 memset(¶ms
, 0, sizeof(params
));
1905 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1908 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1909 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1910 if (type
> NL80211_IFTYPE_MAX
)
1914 if (!rdev
->ops
->add_virtual_intf
||
1915 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1918 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1919 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1920 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1925 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1926 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1928 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1929 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1930 type
, err
? NULL
: &flags
, ¶ms
);
1932 return PTR_ERR(dev
);
1934 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1935 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1936 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1939 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1940 IEEE80211_MAX_MESH_ID_LEN
);
1941 wdev
->mesh_id_up_len
=
1942 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1943 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1944 wdev
->mesh_id_up_len
);
1951 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1953 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1954 struct net_device
*dev
= info
->user_ptr
[1];
1956 if (!rdev
->ops
->del_virtual_intf
)
1959 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1962 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
1964 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1965 struct net_device
*dev
= info
->user_ptr
[1];
1968 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
1971 if (!rdev
->ops
->set_noack_map
)
1974 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
1976 return rdev
->ops
->set_noack_map(&rdev
->wiphy
, dev
, noack_map
);
1979 struct get_key_cookie
{
1980 struct sk_buff
*msg
;
1985 static void get_key_callback(void *c
, struct key_params
*params
)
1988 struct get_key_cookie
*cookie
= c
;
1991 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1992 params
->key_len
, params
->key
)) ||
1994 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1995 params
->seq_len
, params
->seq
)) ||
1997 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1999 goto nla_put_failure
;
2001 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2003 goto nla_put_failure
;
2006 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2007 params
->key_len
, params
->key
)) ||
2009 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2010 params
->seq_len
, params
->seq
)) ||
2012 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2014 goto nla_put_failure
;
2016 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2017 goto nla_put_failure
;
2019 nla_nest_end(cookie
->msg
, key
);
2026 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2028 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2030 struct net_device
*dev
= info
->user_ptr
[1];
2032 const u8
*mac_addr
= NULL
;
2034 struct get_key_cookie cookie
= {
2038 struct sk_buff
*msg
;
2040 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2041 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2046 if (info
->attrs
[NL80211_ATTR_MAC
])
2047 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2049 pairwise
= !!mac_addr
;
2050 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2051 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2052 if (kt
>= NUM_NL80211_KEYTYPES
)
2054 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2055 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2057 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2060 if (!rdev
->ops
->get_key
)
2063 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2067 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2068 NL80211_CMD_NEW_KEY
);
2070 return PTR_ERR(hdr
);
2073 cookie
.idx
= key_idx
;
2075 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2076 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2077 goto nla_put_failure
;
2079 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2080 goto nla_put_failure
;
2082 if (pairwise
&& mac_addr
&&
2083 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2086 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
2087 mac_addr
, &cookie
, get_key_callback
);
2093 goto nla_put_failure
;
2095 genlmsg_end(msg
, hdr
);
2096 return genlmsg_reply(msg
, info
);
2105 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2107 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2108 struct key_parse key
;
2110 struct net_device
*dev
= info
->user_ptr
[1];
2112 err
= nl80211_parse_key(info
, &key
);
2119 /* only support setting default key */
2120 if (!key
.def
&& !key
.defmgmt
)
2123 wdev_lock(dev
->ieee80211_ptr
);
2126 if (!rdev
->ops
->set_default_key
) {
2131 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2135 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
2136 key
.def_uni
, key
.def_multi
);
2141 #ifdef CONFIG_CFG80211_WEXT
2142 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2145 if (key
.def_uni
|| !key
.def_multi
) {
2150 if (!rdev
->ops
->set_default_mgmt_key
) {
2155 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2159 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
2164 #ifdef CONFIG_CFG80211_WEXT
2165 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2170 wdev_unlock(dev
->ieee80211_ptr
);
2175 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2177 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2179 struct net_device
*dev
= info
->user_ptr
[1];
2180 struct key_parse key
;
2181 const u8
*mac_addr
= NULL
;
2183 err
= nl80211_parse_key(info
, &key
);
2190 if (info
->attrs
[NL80211_ATTR_MAC
])
2191 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2193 if (key
.type
== -1) {
2195 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2197 key
.type
= NL80211_KEYTYPE_GROUP
;
2201 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2202 key
.type
!= NL80211_KEYTYPE_GROUP
)
2205 if (!rdev
->ops
->add_key
)
2208 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2209 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2213 wdev_lock(dev
->ieee80211_ptr
);
2214 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2216 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
2217 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2219 wdev_unlock(dev
->ieee80211_ptr
);
2224 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2226 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2228 struct net_device
*dev
= info
->user_ptr
[1];
2229 u8
*mac_addr
= NULL
;
2230 struct key_parse key
;
2232 err
= nl80211_parse_key(info
, &key
);
2236 if (info
->attrs
[NL80211_ATTR_MAC
])
2237 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2239 if (key
.type
== -1) {
2241 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2243 key
.type
= NL80211_KEYTYPE_GROUP
;
2247 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2248 key
.type
!= NL80211_KEYTYPE_GROUP
)
2251 if (!rdev
->ops
->del_key
)
2254 wdev_lock(dev
->ieee80211_ptr
);
2255 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2257 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2258 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2262 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
2263 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2266 #ifdef CONFIG_CFG80211_WEXT
2268 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2269 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2270 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2271 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2274 wdev_unlock(dev
->ieee80211_ptr
);
2279 static int nl80211_parse_beacon(struct genl_info
*info
,
2280 struct cfg80211_beacon_data
*bcn
)
2282 bool haveinfo
= false;
2284 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2285 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2286 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2287 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2290 memset(bcn
, 0, sizeof(*bcn
));
2292 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2293 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2294 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2300 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2301 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2303 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2310 if (info
->attrs
[NL80211_ATTR_IE
]) {
2311 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2312 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2315 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2316 bcn
->proberesp_ies
=
2317 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2318 bcn
->proberesp_ies_len
=
2319 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2322 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2323 bcn
->assocresp_ies
=
2324 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2325 bcn
->assocresp_ies_len
=
2326 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2329 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2331 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2332 bcn
->probe_resp_len
=
2333 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2339 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2340 struct cfg80211_ap_settings
*params
)
2342 struct wireless_dev
*wdev
;
2345 mutex_lock(&rdev
->devlist_mtx
);
2347 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
2348 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2349 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2352 if (!wdev
->preset_chan
)
2355 params
->channel
= wdev
->preset_chan
;
2356 params
->channel_type
= wdev
->preset_chantype
;
2361 mutex_unlock(&rdev
->devlist_mtx
);
2366 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2368 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2369 struct net_device
*dev
= info
->user_ptr
[1];
2370 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2371 struct cfg80211_ap_settings params
;
2374 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2375 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2378 if (!rdev
->ops
->start_ap
)
2381 if (wdev
->beacon_interval
)
2384 memset(¶ms
, 0, sizeof(params
));
2386 /* these are required for START_AP */
2387 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2388 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2389 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2392 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
2396 params
.beacon_interval
=
2397 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2398 params
.dtim_period
=
2399 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2401 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
2406 * In theory, some of these attributes should be required here
2407 * but since they were not used when the command was originally
2408 * added, keep them optional for old user space programs to let
2409 * them continue to work with drivers that do not need the
2410 * additional information -- drivers must check!
2412 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2413 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2415 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2416 if (params
.ssid_len
== 0 ||
2417 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2421 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2422 params
.hidden_ssid
= nla_get_u32(
2423 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2424 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2425 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
2426 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2430 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2432 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2433 params
.auth_type
= nla_get_u32(
2434 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2435 if (!nl80211_valid_auth_type(params
.auth_type
))
2438 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2440 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2441 NL80211_MAX_NR_CIPHER_SUITES
);
2445 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
2446 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
2448 params
.inactivity_timeout
= nla_get_u16(
2449 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
2452 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2453 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
2455 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
2456 !nl80211_valid_channel_type(info
, &channel_type
))
2459 params
.channel
= rdev_freq_to_chan(rdev
,
2460 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
2462 if (!params
.channel
)
2464 params
.channel_type
= channel_type
;
2465 } else if (wdev
->preset_chan
) {
2466 params
.channel
= wdev
->preset_chan
;
2467 params
.channel_type
= wdev
->preset_chantype
;
2468 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
2471 if (!cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, params
.channel
,
2472 params
.channel_type
))
2475 err
= rdev
->ops
->start_ap(&rdev
->wiphy
, dev
, ¶ms
);
2477 wdev
->preset_chan
= params
.channel
;
2478 wdev
->preset_chantype
= params
.channel_type
;
2479 wdev
->beacon_interval
= params
.beacon_interval
;
2484 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2486 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2487 struct net_device
*dev
= info
->user_ptr
[1];
2488 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2489 struct cfg80211_beacon_data params
;
2492 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2493 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2496 if (!rdev
->ops
->change_beacon
)
2499 if (!wdev
->beacon_interval
)
2502 err
= nl80211_parse_beacon(info
, ¶ms
);
2506 return rdev
->ops
->change_beacon(&rdev
->wiphy
, dev
, ¶ms
);
2509 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2511 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2512 struct net_device
*dev
= info
->user_ptr
[1];
2513 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2516 if (!rdev
->ops
->stop_ap
)
2519 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2520 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2523 if (!wdev
->beacon_interval
)
2526 err
= rdev
->ops
->stop_ap(&rdev
->wiphy
, dev
);
2528 wdev
->beacon_interval
= 0;
2532 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2533 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2534 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2535 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2536 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2537 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2538 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
2541 static int parse_station_flags(struct genl_info
*info
,
2542 enum nl80211_iftype iftype
,
2543 struct station_parameters
*params
)
2545 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2550 * Try parsing the new attribute first so userspace
2551 * can specify both for older kernels.
2553 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2555 struct nl80211_sta_flag_update
*sta_flags
;
2557 sta_flags
= nla_data(nla
);
2558 params
->sta_flags_mask
= sta_flags
->mask
;
2559 params
->sta_flags_set
= sta_flags
->set
;
2560 if ((params
->sta_flags_mask
|
2561 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2566 /* if present, parse the old attribute */
2568 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2572 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2573 nla
, sta_flags_policy
))
2577 * Only allow certain flags for interface types so that
2578 * other attributes are silently ignored. Remember that
2579 * this is backward compatibility code with old userspace
2580 * and shouldn't be hit in other cases anyway.
2583 case NL80211_IFTYPE_AP
:
2584 case NL80211_IFTYPE_AP_VLAN
:
2585 case NL80211_IFTYPE_P2P_GO
:
2586 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2587 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2588 BIT(NL80211_STA_FLAG_WME
) |
2589 BIT(NL80211_STA_FLAG_MFP
);
2591 case NL80211_IFTYPE_P2P_CLIENT
:
2592 case NL80211_IFTYPE_STATION
:
2593 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2594 BIT(NL80211_STA_FLAG_TDLS_PEER
);
2596 case NL80211_IFTYPE_MESH_POINT
:
2597 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2598 BIT(NL80211_STA_FLAG_MFP
) |
2599 BIT(NL80211_STA_FLAG_AUTHORIZED
);
2604 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
2606 params
->sta_flags_set
|= (1<<flag
);
2608 /* no longer support new API additions in old API */
2609 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
2617 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2620 struct nlattr
*rate
;
2623 rate
= nla_nest_start(msg
, attr
);
2625 goto nla_put_failure
;
2627 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2628 bitrate
= cfg80211_calculate_bitrate(info
);
2630 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
)) ||
2631 ((info
->flags
& RATE_INFO_FLAGS_MCS
) &&
2632 nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
)) ||
2633 ((info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) &&
2634 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
)) ||
2635 ((info
->flags
& RATE_INFO_FLAGS_SHORT_GI
) &&
2636 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
)))
2637 goto nla_put_failure
;
2639 nla_nest_end(msg
, rate
);
2646 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2648 struct cfg80211_registered_device
*rdev
,
2649 struct net_device
*dev
,
2650 const u8
*mac_addr
, struct station_info
*sinfo
)
2653 struct nlattr
*sinfoattr
, *bss_param
;
2655 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2659 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2660 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
2661 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
2662 goto nla_put_failure
;
2664 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2666 goto nla_put_failure
;
2667 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
2668 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2669 sinfo
->connected_time
))
2670 goto nla_put_failure
;
2671 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
2672 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2673 sinfo
->inactive_time
))
2674 goto nla_put_failure
;
2675 if ((sinfo
->filled
& STATION_INFO_RX_BYTES
) &&
2676 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
2678 goto nla_put_failure
;
2679 if ((sinfo
->filled
& STATION_INFO_TX_BYTES
) &&
2680 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
2682 goto nla_put_failure
;
2683 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
2684 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
2685 goto nla_put_failure
;
2686 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
2687 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
2688 goto nla_put_failure
;
2689 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
2690 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2691 sinfo
->plink_state
))
2692 goto nla_put_failure
;
2693 switch (rdev
->wiphy
.signal_type
) {
2694 case CFG80211_SIGNAL_TYPE_MBM
:
2695 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
2696 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
2698 goto nla_put_failure
;
2699 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
2700 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2702 goto nla_put_failure
;
2707 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2708 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2709 NL80211_STA_INFO_TX_BITRATE
))
2710 goto nla_put_failure
;
2712 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2713 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2714 NL80211_STA_INFO_RX_BITRATE
))
2715 goto nla_put_failure
;
2717 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
2718 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2720 goto nla_put_failure
;
2721 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
2722 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2724 goto nla_put_failure
;
2725 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
2726 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2728 goto nla_put_failure
;
2729 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
2730 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
2732 goto nla_put_failure
;
2733 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
2734 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
2735 sinfo
->beacon_loss_count
))
2736 goto nla_put_failure
;
2737 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2738 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2740 goto nla_put_failure
;
2742 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
2743 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
2744 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
2745 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
2746 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
2747 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
2748 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2749 sinfo
->bss_param
.dtim_period
) ||
2750 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2751 sinfo
->bss_param
.beacon_interval
))
2752 goto nla_put_failure
;
2754 nla_nest_end(msg
, bss_param
);
2756 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
2757 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
2758 sizeof(struct nl80211_sta_flag_update
),
2760 goto nla_put_failure
;
2761 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
2762 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
2764 goto nla_put_failure
;
2765 nla_nest_end(msg
, sinfoattr
);
2767 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
2768 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2769 sinfo
->assoc_req_ies
))
2770 goto nla_put_failure
;
2772 return genlmsg_end(msg
, hdr
);
2775 genlmsg_cancel(msg
, hdr
);
2779 static int nl80211_dump_station(struct sk_buff
*skb
,
2780 struct netlink_callback
*cb
)
2782 struct station_info sinfo
;
2783 struct cfg80211_registered_device
*dev
;
2784 struct net_device
*netdev
;
2785 u8 mac_addr
[ETH_ALEN
];
2786 int sta_idx
= cb
->args
[1];
2789 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2793 if (!dev
->ops
->dump_station
) {
2799 memset(&sinfo
, 0, sizeof(sinfo
));
2800 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2807 if (nl80211_send_station(skb
,
2808 NETLINK_CB(cb
->skb
).pid
,
2809 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2810 dev
, netdev
, mac_addr
,
2819 cb
->args
[1] = sta_idx
;
2822 nl80211_finish_netdev_dump(dev
);
2827 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2829 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2830 struct net_device
*dev
= info
->user_ptr
[1];
2831 struct station_info sinfo
;
2832 struct sk_buff
*msg
;
2833 u8
*mac_addr
= NULL
;
2836 memset(&sinfo
, 0, sizeof(sinfo
));
2838 if (!info
->attrs
[NL80211_ATTR_MAC
])
2841 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2843 if (!rdev
->ops
->get_station
)
2846 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2850 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2854 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2855 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
2860 return genlmsg_reply(msg
, info
);
2864 * Get vlan interface making sure it is running and on the right wiphy.
2866 static struct net_device
*get_vlan(struct genl_info
*info
,
2867 struct cfg80211_registered_device
*rdev
)
2869 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2870 struct net_device
*v
;
2876 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
2878 return ERR_PTR(-ENODEV
);
2880 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
2885 if (!netif_running(v
)) {
2893 return ERR_PTR(ret
);
2896 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2898 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2900 struct net_device
*dev
= info
->user_ptr
[1];
2901 struct station_parameters params
;
2902 u8
*mac_addr
= NULL
;
2904 memset(¶ms
, 0, sizeof(params
));
2906 params
.listen_interval
= -1;
2907 params
.plink_state
= -1;
2909 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2912 if (!info
->attrs
[NL80211_ATTR_MAC
])
2915 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2917 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2918 params
.supported_rates
=
2919 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2920 params
.supported_rates_len
=
2921 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2924 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2925 params
.listen_interval
=
2926 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2928 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2930 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2932 if (!rdev
->ops
->change_station
)
2935 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
2938 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2939 params
.plink_action
=
2940 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2942 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2943 params
.plink_state
=
2944 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2946 switch (dev
->ieee80211_ptr
->iftype
) {
2947 case NL80211_IFTYPE_AP
:
2948 case NL80211_IFTYPE_AP_VLAN
:
2949 case NL80211_IFTYPE_P2P_GO
:
2950 /* disallow mesh-specific things */
2951 if (params
.plink_action
)
2954 /* TDLS can't be set, ... */
2955 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
2958 * ... but don't bother the driver with it. This works around
2959 * a hostapd/wpa_supplicant issue -- it always includes the
2960 * TLDS_PEER flag in the mask even for AP mode.
2962 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
2964 /* accept only the listed bits */
2965 if (params
.sta_flags_mask
&
2966 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2967 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2968 BIT(NL80211_STA_FLAG_WME
) |
2969 BIT(NL80211_STA_FLAG_MFP
)))
2972 /* must be last in here for error handling */
2973 params
.vlan
= get_vlan(info
, rdev
);
2974 if (IS_ERR(params
.vlan
))
2975 return PTR_ERR(params
.vlan
);
2977 case NL80211_IFTYPE_P2P_CLIENT
:
2978 case NL80211_IFTYPE_STATION
:
2980 * Don't allow userspace to change the TDLS_PEER flag,
2981 * but silently ignore attempts to change it since we
2982 * don't have state here to verify that it doesn't try
2983 * to change the flag.
2985 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
2987 case NL80211_IFTYPE_ADHOC
:
2988 /* disallow things sta doesn't support */
2989 if (params
.plink_action
)
2993 if (params
.listen_interval
>= 0)
2995 /* reject any changes other than AUTHORIZED */
2996 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2999 case NL80211_IFTYPE_MESH_POINT
:
3000 /* disallow things mesh doesn't support */
3005 if (params
.listen_interval
>= 0)
3008 * No special handling for TDLS here -- the userspace
3009 * mesh code doesn't have this bug.
3011 if (params
.sta_flags_mask
&
3012 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3013 BIT(NL80211_STA_FLAG_MFP
) |
3014 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3021 /* be aware of params.vlan when changing code here */
3023 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3026 dev_put(params
.vlan
);
3031 static struct nla_policy
3032 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3033 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3034 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3037 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3039 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3041 struct net_device
*dev
= info
->user_ptr
[1];
3042 struct station_parameters params
;
3043 u8
*mac_addr
= NULL
;
3045 memset(¶ms
, 0, sizeof(params
));
3047 if (!info
->attrs
[NL80211_ATTR_MAC
])
3050 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3053 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3056 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3059 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3060 params
.supported_rates
=
3061 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3062 params
.supported_rates_len
=
3063 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3064 params
.listen_interval
=
3065 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3067 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3068 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3071 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3073 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3075 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3076 params
.plink_action
=
3077 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3079 if (!rdev
->ops
->add_station
)
3082 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3085 switch (dev
->ieee80211_ptr
->iftype
) {
3086 case NL80211_IFTYPE_AP
:
3087 case NL80211_IFTYPE_AP_VLAN
:
3088 case NL80211_IFTYPE_P2P_GO
:
3089 /* parse WME attributes if sta is WME capable */
3090 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
3091 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
3092 info
->attrs
[NL80211_ATTR_STA_WME
]) {
3093 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3096 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3097 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3098 nl80211_sta_wme_policy
);
3102 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3103 params
.uapsd_queues
=
3104 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3105 if (params
.uapsd_queues
&
3106 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3109 if (tb
[NL80211_STA_WME_MAX_SP
])
3111 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3114 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3117 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3119 /* TDLS peers cannot be added */
3120 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3122 /* but don't bother the driver with it */
3123 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3125 /* must be last in here for error handling */
3126 params
.vlan
= get_vlan(info
, rdev
);
3127 if (IS_ERR(params
.vlan
))
3128 return PTR_ERR(params
.vlan
);
3130 case NL80211_IFTYPE_MESH_POINT
:
3131 /* TDLS peers cannot be added */
3132 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3135 case NL80211_IFTYPE_STATION
:
3136 /* Only TDLS peers can be added */
3137 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3139 /* Can only add if TDLS ... */
3140 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3142 /* ... with external setup is supported */
3143 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3150 /* be aware of params.vlan when changing code here */
3152 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
3155 dev_put(params
.vlan
);
3159 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
3161 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3162 struct net_device
*dev
= info
->user_ptr
[1];
3163 u8
*mac_addr
= NULL
;
3165 if (info
->attrs
[NL80211_ATTR_MAC
])
3166 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3168 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3169 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3170 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
3171 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3174 if (!rdev
->ops
->del_station
)
3177 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
3180 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3181 int flags
, struct net_device
*dev
,
3182 u8
*dst
, u8
*next_hop
,
3183 struct mpath_info
*pinfo
)
3186 struct nlattr
*pinfoattr
;
3188 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3192 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3193 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
3194 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
3195 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
3196 goto nla_put_failure
;
3198 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
3200 goto nla_put_failure
;
3201 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
3202 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
3204 goto nla_put_failure
;
3205 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
3206 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
3207 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
3208 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
3210 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
3211 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
3213 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
3214 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
3216 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
3217 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
3218 pinfo
->discovery_timeout
)) ||
3219 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
3220 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
3221 pinfo
->discovery_retries
)))
3222 goto nla_put_failure
;
3224 nla_nest_end(msg
, pinfoattr
);
3226 return genlmsg_end(msg
, hdr
);
3229 genlmsg_cancel(msg
, hdr
);
3233 static int nl80211_dump_mpath(struct sk_buff
*skb
,
3234 struct netlink_callback
*cb
)
3236 struct mpath_info pinfo
;
3237 struct cfg80211_registered_device
*dev
;
3238 struct net_device
*netdev
;
3240 u8 next_hop
[ETH_ALEN
];
3241 int path_idx
= cb
->args
[1];
3244 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3248 if (!dev
->ops
->dump_mpath
) {
3253 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
3259 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
3260 dst
, next_hop
, &pinfo
);
3266 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
3267 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3268 netdev
, dst
, next_hop
,
3277 cb
->args
[1] = path_idx
;
3280 nl80211_finish_netdev_dump(dev
);
3284 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3286 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3288 struct net_device
*dev
= info
->user_ptr
[1];
3289 struct mpath_info pinfo
;
3290 struct sk_buff
*msg
;
3292 u8 next_hop
[ETH_ALEN
];
3294 memset(&pinfo
, 0, sizeof(pinfo
));
3296 if (!info
->attrs
[NL80211_ATTR_MAC
])
3299 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3301 if (!rdev
->ops
->get_mpath
)
3304 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3307 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
3311 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3315 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3316 dev
, dst
, next_hop
, &pinfo
) < 0) {
3321 return genlmsg_reply(msg
, info
);
3324 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3326 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3327 struct net_device
*dev
= info
->user_ptr
[1];
3329 u8
*next_hop
= NULL
;
3331 if (!info
->attrs
[NL80211_ATTR_MAC
])
3334 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3337 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3338 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3340 if (!rdev
->ops
->change_mpath
)
3343 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3346 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3349 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3351 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3352 struct net_device
*dev
= info
->user_ptr
[1];
3354 u8
*next_hop
= NULL
;
3356 if (!info
->attrs
[NL80211_ATTR_MAC
])
3359 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3362 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3363 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3365 if (!rdev
->ops
->add_mpath
)
3368 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3371 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3374 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3376 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3377 struct net_device
*dev
= info
->user_ptr
[1];
3380 if (info
->attrs
[NL80211_ATTR_MAC
])
3381 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3383 if (!rdev
->ops
->del_mpath
)
3386 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
3389 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
3391 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3392 struct net_device
*dev
= info
->user_ptr
[1];
3393 struct bss_parameters params
;
3395 memset(¶ms
, 0, sizeof(params
));
3396 /* default to not changing parameters */
3397 params
.use_cts_prot
= -1;
3398 params
.use_short_preamble
= -1;
3399 params
.use_short_slot_time
= -1;
3400 params
.ap_isolate
= -1;
3401 params
.ht_opmode
= -1;
3403 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
3404 params
.use_cts_prot
=
3405 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
3406 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
3407 params
.use_short_preamble
=
3408 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
3409 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
3410 params
.use_short_slot_time
=
3411 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
3412 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3413 params
.basic_rates
=
3414 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3415 params
.basic_rates_len
=
3416 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3418 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
3419 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
3420 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
3422 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
3424 if (!rdev
->ops
->change_bss
)
3427 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3428 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3431 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
3434 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
3435 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3436 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3437 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3438 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3439 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3440 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3443 static int parse_reg_rule(struct nlattr
*tb
[],
3444 struct ieee80211_reg_rule
*reg_rule
)
3446 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3447 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3449 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3451 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3453 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3455 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3457 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3460 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3462 freq_range
->start_freq_khz
=
3463 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3464 freq_range
->end_freq_khz
=
3465 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3466 freq_range
->max_bandwidth_khz
=
3467 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3469 power_rule
->max_eirp
=
3470 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3472 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3473 power_rule
->max_antenna_gain
=
3474 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3479 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3485 * You should only get this when cfg80211 hasn't yet initialized
3486 * completely when built-in to the kernel right between the time
3487 * window between nl80211_init() and regulatory_init(), if that is
3490 mutex_lock(&cfg80211_mutex
);
3491 if (unlikely(!cfg80211_regdomain
)) {
3492 mutex_unlock(&cfg80211_mutex
);
3493 return -EINPROGRESS
;
3495 mutex_unlock(&cfg80211_mutex
);
3497 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3500 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3502 r
= regulatory_hint_user(data
);
3507 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3508 struct genl_info
*info
)
3510 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3511 struct net_device
*dev
= info
->user_ptr
[1];
3512 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3513 struct mesh_config cur_params
;
3516 struct nlattr
*pinfoattr
;
3517 struct sk_buff
*msg
;
3519 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3522 if (!rdev
->ops
->get_mesh_config
)
3526 /* If not connected, get default parameters */
3527 if (!wdev
->mesh_id_len
)
3528 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3530 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3537 /* Draw up a netlink message to send back */
3538 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3541 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3542 NL80211_CMD_GET_MESH_CONFIG
);
3545 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3547 goto nla_put_failure
;
3548 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3549 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3550 cur_params
.dot11MeshRetryTimeout
) ||
3551 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3552 cur_params
.dot11MeshConfirmTimeout
) ||
3553 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3554 cur_params
.dot11MeshHoldingTimeout
) ||
3555 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3556 cur_params
.dot11MeshMaxPeerLinks
) ||
3557 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3558 cur_params
.dot11MeshMaxRetries
) ||
3559 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
3560 cur_params
.dot11MeshTTL
) ||
3561 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3562 cur_params
.element_ttl
) ||
3563 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3564 cur_params
.auto_open_plinks
) ||
3565 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3566 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
3567 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3568 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
3569 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3570 cur_params
.path_refresh_time
) ||
3571 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3572 cur_params
.min_discovery_timeout
) ||
3573 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3574 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
3575 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3576 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
3577 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3578 cur_params
.dot11MeshHWMPperrMinInterval
) ||
3579 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3580 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
3581 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3582 cur_params
.dot11MeshHWMPRootMode
) ||
3583 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3584 cur_params
.dot11MeshHWMPRannInterval
) ||
3585 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3586 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
3587 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
3588 cur_params
.dot11MeshForwarding
) ||
3589 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3590 cur_params
.rssi_threshold
) ||
3591 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
3592 cur_params
.ht_opmode
) ||
3593 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3594 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
3595 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3596 cur_params
.dot11MeshHWMProotInterval
) ||
3597 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3598 cur_params
.dot11MeshHWMPconfirmationInterval
))
3599 goto nla_put_failure
;
3600 nla_nest_end(msg
, pinfoattr
);
3601 genlmsg_end(msg
, hdr
);
3602 return genlmsg_reply(msg
, info
);
3605 genlmsg_cancel(msg
, hdr
);
3611 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3612 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3613 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3614 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3615 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3616 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3617 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3618 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3619 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3620 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
3621 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3622 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3623 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3624 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3625 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3626 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
3627 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3628 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3629 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3630 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3631 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
3632 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
3633 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
3634 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
3635 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
3636 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
3639 static const struct nla_policy
3640 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3641 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
3642 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3643 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3644 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3645 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3646 .len
= IEEE80211_MAX_DATA_LEN
},
3647 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3650 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3651 struct mesh_config
*cfg
,
3654 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3657 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3659 if (table[attr_num]) {\
3660 cfg->param = nla_fn(table[attr_num]); \
3661 mask |= (1 << (attr_num - 1)); \
3666 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3668 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3669 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3670 nl80211_meshconf_params_policy
))
3673 /* This makes sure that there aren't more than 32 mesh config
3674 * parameters (otherwise our bitfield scheme would not work.) */
3675 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3677 /* Fill in the params struct */
3678 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3679 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3681 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3682 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3684 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3685 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3687 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3688 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3690 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3691 mask
, NL80211_MESHCONF_MAX_RETRIES
,
3693 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3694 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3695 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3696 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
3698 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3699 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3701 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
, mask
,
3702 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3704 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3705 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3707 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3708 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3710 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3711 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3713 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
, mask
,
3714 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3716 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3717 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3719 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
3720 mask
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3722 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3723 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
3724 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3726 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
3727 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
3728 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
3729 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3731 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3732 dot11MeshGateAnnouncementProtocol
, mask
,
3733 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3735 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
,
3736 mask
, NL80211_MESHCONF_FORWARDING
,
3738 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
,
3739 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3741 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
,
3742 mask
, NL80211_MESHCONF_HT_OPMODE
,
3744 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
3746 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3748 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
,
3749 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3751 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3752 dot11MeshHWMPconfirmationInterval
, mask
,
3753 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3760 #undef FILL_IN_MESH_PARAM_IF_SET
3763 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3764 struct mesh_setup
*setup
)
3766 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3768 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3770 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3771 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3772 nl80211_mesh_setup_params_policy
))
3775 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
3776 setup
->sync_method
=
3777 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
3778 IEEE80211_SYNC_METHOD_VENDOR
:
3779 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
3781 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3782 setup
->path_sel_proto
=
3783 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3784 IEEE80211_PATH_PROTOCOL_VENDOR
:
3785 IEEE80211_PATH_PROTOCOL_HWMP
;
3787 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3788 setup
->path_metric
=
3789 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3790 IEEE80211_PATH_METRIC_VENDOR
:
3791 IEEE80211_PATH_METRIC_AIRTIME
;
3794 if (tb
[NL80211_MESH_SETUP_IE
]) {
3795 struct nlattr
*ieattr
=
3796 tb
[NL80211_MESH_SETUP_IE
];
3797 if (!is_valid_ie_attr(ieattr
))
3799 setup
->ie
= nla_data(ieattr
);
3800 setup
->ie_len
= nla_len(ieattr
);
3802 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3803 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3808 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3809 struct genl_info
*info
)
3811 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3812 struct net_device
*dev
= info
->user_ptr
[1];
3813 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3814 struct mesh_config cfg
;
3818 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3821 if (!rdev
->ops
->update_mesh_config
)
3824 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3829 if (!wdev
->mesh_id_len
)
3833 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3841 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3843 struct sk_buff
*msg
;
3845 struct nlattr
*nl_reg_rules
;
3849 mutex_lock(&cfg80211_mutex
);
3851 if (!cfg80211_regdomain
)
3854 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3860 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3861 NL80211_CMD_GET_REG
);
3865 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
3866 cfg80211_regdomain
->alpha2
) ||
3867 (cfg80211_regdomain
->dfs_region
&&
3868 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
,
3869 cfg80211_regdomain
->dfs_region
)))
3870 goto nla_put_failure
;
3872 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3874 goto nla_put_failure
;
3876 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3877 struct nlattr
*nl_reg_rule
;
3878 const struct ieee80211_reg_rule
*reg_rule
;
3879 const struct ieee80211_freq_range
*freq_range
;
3880 const struct ieee80211_power_rule
*power_rule
;
3882 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3883 freq_range
= ®_rule
->freq_range
;
3884 power_rule
= ®_rule
->power_rule
;
3886 nl_reg_rule
= nla_nest_start(msg
, i
);
3888 goto nla_put_failure
;
3890 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3892 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3893 freq_range
->start_freq_khz
) ||
3894 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3895 freq_range
->end_freq_khz
) ||
3896 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3897 freq_range
->max_bandwidth_khz
) ||
3898 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3899 power_rule
->max_antenna_gain
) ||
3900 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3901 power_rule
->max_eirp
))
3902 goto nla_put_failure
;
3904 nla_nest_end(msg
, nl_reg_rule
);
3907 nla_nest_end(msg
, nl_reg_rules
);
3909 genlmsg_end(msg
, hdr
);
3910 err
= genlmsg_reply(msg
, info
);
3914 genlmsg_cancel(msg
, hdr
);
3919 mutex_unlock(&cfg80211_mutex
);
3923 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3925 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3926 struct nlattr
*nl_reg_rule
;
3927 char *alpha2
= NULL
;
3928 int rem_reg_rules
= 0, r
= 0;
3929 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3931 struct ieee80211_regdomain
*rd
= NULL
;
3933 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3936 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3939 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3941 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
3942 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
3944 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3947 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3951 mutex_lock(&cfg80211_mutex
);
3953 if (!reg_is_valid_request(alpha2
)) {
3958 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3959 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3961 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3967 rd
->n_reg_rules
= num_rules
;
3968 rd
->alpha2
[0] = alpha2
[0];
3969 rd
->alpha2
[1] = alpha2
[1];
3972 * Disable DFS master mode if the DFS region was
3973 * not supported or known on this kernel.
3975 if (reg_supported_dfs_region(dfs_region
))
3976 rd
->dfs_region
= dfs_region
;
3978 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3980 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3981 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3983 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3989 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3995 BUG_ON(rule_idx
!= num_rules
);
3999 mutex_unlock(&cfg80211_mutex
);
4004 mutex_unlock(&cfg80211_mutex
);
4009 static int validate_scan_freqs(struct nlattr
*freqs
)
4011 struct nlattr
*attr1
, *attr2
;
4012 int n_channels
= 0, tmp1
, tmp2
;
4014 nla_for_each_nested(attr1
, freqs
, tmp1
) {
4017 * Some hardware has a limited channel list for
4018 * scanning, and it is pretty much nonsensical
4019 * to scan for a channel twice, so disallow that
4020 * and don't require drivers to check that the
4021 * channel list they get isn't longer than what
4022 * they can scan, as long as they can scan all
4023 * the channels they registered at once.
4025 nla_for_each_nested(attr2
, freqs
, tmp2
)
4026 if (attr1
!= attr2
&&
4027 nla_get_u32(attr1
) == nla_get_u32(attr2
))
4034 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
4036 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4037 struct net_device
*dev
= info
->user_ptr
[1];
4038 struct cfg80211_scan_request
*request
;
4039 struct nlattr
*attr
;
4040 struct wiphy
*wiphy
;
4041 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
4044 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4047 wiphy
= &rdev
->wiphy
;
4049 if (!rdev
->ops
->scan
)
4055 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4056 n_channels
= validate_scan_freqs(
4057 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4061 enum ieee80211_band band
;
4064 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4065 if (wiphy
->bands
[band
])
4066 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4069 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4070 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
4073 if (n_ssids
> wiphy
->max_scan_ssids
)
4076 if (info
->attrs
[NL80211_ATTR_IE
])
4077 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4081 if (ie_len
> wiphy
->max_scan_ie_len
)
4084 request
= kzalloc(sizeof(*request
)
4085 + sizeof(*request
->ssids
) * n_ssids
4086 + sizeof(*request
->channels
) * n_channels
4087 + ie_len
, GFP_KERNEL
);
4092 request
->ssids
= (void *)&request
->channels
[n_channels
];
4093 request
->n_ssids
= n_ssids
;
4096 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4098 request
->ie
= (void *)(request
->channels
+ n_channels
);
4102 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4103 /* user specified, bail out if channel not found */
4104 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
4105 struct ieee80211_channel
*chan
;
4107 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4114 /* ignore disabled channels */
4115 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4118 request
->channels
[i
] = chan
;
4122 enum ieee80211_band band
;
4125 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4127 if (!wiphy
->bands
[band
])
4129 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4130 struct ieee80211_channel
*chan
;
4132 chan
= &wiphy
->bands
[band
]->channels
[j
];
4134 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4137 request
->channels
[i
] = chan
;
4148 request
->n_channels
= i
;
4151 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4152 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
4153 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4157 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4158 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
4163 if (info
->attrs
[NL80211_ATTR_IE
]) {
4164 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4165 memcpy((void *)request
->ie
,
4166 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4170 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4171 if (wiphy
->bands
[i
])
4173 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
4175 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
4176 nla_for_each_nested(attr
,
4177 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
4179 enum ieee80211_band band
= nla_type(attr
);
4181 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4185 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
4188 &request
->rates
[band
]);
4195 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
4198 request
->wiphy
= &rdev
->wiphy
;
4200 rdev
->scan_req
= request
;
4201 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
4204 nl80211_send_scan_start(rdev
, dev
);
4208 rdev
->scan_req
= NULL
;
4215 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
4216 struct genl_info
*info
)
4218 struct cfg80211_sched_scan_request
*request
;
4219 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4220 struct net_device
*dev
= info
->user_ptr
[1];
4221 struct nlattr
*attr
;
4222 struct wiphy
*wiphy
;
4223 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
4225 enum ieee80211_band band
;
4227 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
4229 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4230 !rdev
->ops
->sched_scan_start
)
4233 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4236 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
4239 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
4243 wiphy
= &rdev
->wiphy
;
4245 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4246 n_channels
= validate_scan_freqs(
4247 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4253 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4254 if (wiphy
->bands
[band
])
4255 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4258 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4259 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4263 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
4266 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
4267 nla_for_each_nested(attr
,
4268 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4272 if (n_match_sets
> wiphy
->max_match_sets
)
4275 if (info
->attrs
[NL80211_ATTR_IE
])
4276 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4280 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
4283 mutex_lock(&rdev
->sched_scan_mtx
);
4285 if (rdev
->sched_scan_req
) {
4290 request
= kzalloc(sizeof(*request
)
4291 + sizeof(*request
->ssids
) * n_ssids
4292 + sizeof(*request
->match_sets
) * n_match_sets
4293 + sizeof(*request
->channels
) * n_channels
4294 + ie_len
, GFP_KERNEL
);
4301 request
->ssids
= (void *)&request
->channels
[n_channels
];
4302 request
->n_ssids
= n_ssids
;
4305 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4307 request
->ie
= (void *)(request
->channels
+ n_channels
);
4312 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
4313 else if (request
->ssids
)
4314 request
->match_sets
=
4315 (void *)(request
->ssids
+ n_ssids
);
4317 request
->match_sets
=
4318 (void *)(request
->channels
+ n_channels
);
4320 request
->n_match_sets
= n_match_sets
;
4323 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4324 /* user specified, bail out if channel not found */
4325 nla_for_each_nested(attr
,
4326 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
4328 struct ieee80211_channel
*chan
;
4330 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4337 /* ignore disabled channels */
4338 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4341 request
->channels
[i
] = chan
;
4346 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4348 if (!wiphy
->bands
[band
])
4350 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4351 struct ieee80211_channel
*chan
;
4353 chan
= &wiphy
->bands
[band
]->channels
[j
];
4355 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4358 request
->channels
[i
] = chan
;
4369 request
->n_channels
= i
;
4372 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4373 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4375 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4379 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4380 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
4387 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
4388 nla_for_each_nested(attr
,
4389 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4391 struct nlattr
*ssid
, *rssi
;
4393 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
4394 nla_data(attr
), nla_len(attr
),
4395 nl80211_match_policy
);
4396 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
4398 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
4402 memcpy(request
->match_sets
[i
].ssid
.ssid
,
4403 nla_data(ssid
), nla_len(ssid
));
4404 request
->match_sets
[i
].ssid
.ssid_len
=
4407 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
4409 request
->rssi_thold
= nla_get_u32(rssi
);
4411 request
->rssi_thold
=
4412 NL80211_SCAN_RSSI_THOLD_OFF
;
4417 if (info
->attrs
[NL80211_ATTR_IE
]) {
4418 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4419 memcpy((void *)request
->ie
,
4420 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4425 request
->wiphy
= &rdev
->wiphy
;
4426 request
->interval
= interval
;
4428 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
4430 rdev
->sched_scan_req
= request
;
4431 nl80211_send_sched_scan(rdev
, dev
,
4432 NL80211_CMD_START_SCHED_SCAN
);
4439 mutex_unlock(&rdev
->sched_scan_mtx
);
4443 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
4444 struct genl_info
*info
)
4446 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4449 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4450 !rdev
->ops
->sched_scan_stop
)
4453 mutex_lock(&rdev
->sched_scan_mtx
);
4454 err
= __cfg80211_stop_sched_scan(rdev
, false);
4455 mutex_unlock(&rdev
->sched_scan_mtx
);
4460 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
4462 struct cfg80211_registered_device
*rdev
,
4463 struct wireless_dev
*wdev
,
4464 struct cfg80211_internal_bss
*intbss
)
4466 struct cfg80211_bss
*res
= &intbss
->pub
;
4470 ASSERT_WDEV_LOCK(wdev
);
4472 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).pid
, seq
, flags
,
4473 NL80211_CMD_NEW_SCAN_RESULTS
);
4477 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
4479 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
) ||
4480 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
4481 goto nla_put_failure
;
4483 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
4485 goto nla_put_failure
;
4486 if ((!is_zero_ether_addr(res
->bssid
) &&
4487 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)) ||
4488 (res
->information_elements
&& res
->len_information_elements
&&
4489 nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
4490 res
->len_information_elements
,
4491 res
->information_elements
)) ||
4492 (res
->beacon_ies
&& res
->len_beacon_ies
&&
4493 res
->beacon_ies
!= res
->information_elements
&&
4494 nla_put(msg
, NL80211_BSS_BEACON_IES
,
4495 res
->len_beacon_ies
, res
->beacon_ies
)))
4496 goto nla_put_failure
;
4498 nla_put_u64(msg
, NL80211_BSS_TSF
, res
->tsf
))
4499 goto nla_put_failure
;
4500 if (res
->beacon_interval
&&
4501 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
4502 goto nla_put_failure
;
4503 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
4504 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
4505 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
4506 jiffies_to_msecs(jiffies
- intbss
->ts
)))
4507 goto nla_put_failure
;
4509 switch (rdev
->wiphy
.signal_type
) {
4510 case CFG80211_SIGNAL_TYPE_MBM
:
4511 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
4512 goto nla_put_failure
;
4514 case CFG80211_SIGNAL_TYPE_UNSPEC
:
4515 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
4516 goto nla_put_failure
;
4522 switch (wdev
->iftype
) {
4523 case NL80211_IFTYPE_P2P_CLIENT
:
4524 case NL80211_IFTYPE_STATION
:
4525 if (intbss
== wdev
->current_bss
&&
4526 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4527 NL80211_BSS_STATUS_ASSOCIATED
))
4528 goto nla_put_failure
;
4530 case NL80211_IFTYPE_ADHOC
:
4531 if (intbss
== wdev
->current_bss
&&
4532 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4533 NL80211_BSS_STATUS_IBSS_JOINED
))
4534 goto nla_put_failure
;
4540 nla_nest_end(msg
, bss
);
4542 return genlmsg_end(msg
, hdr
);
4545 genlmsg_cancel(msg
, hdr
);
4549 static int nl80211_dump_scan(struct sk_buff
*skb
,
4550 struct netlink_callback
*cb
)
4552 struct cfg80211_registered_device
*rdev
;
4553 struct net_device
*dev
;
4554 struct cfg80211_internal_bss
*scan
;
4555 struct wireless_dev
*wdev
;
4556 int start
= cb
->args
[1], idx
= 0;
4559 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4563 wdev
= dev
->ieee80211_ptr
;
4566 spin_lock_bh(&rdev
->bss_lock
);
4567 cfg80211_bss_expire(rdev
);
4569 cb
->seq
= rdev
->bss_generation
;
4571 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4574 if (nl80211_send_bss(skb
, cb
,
4575 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4576 rdev
, wdev
, scan
) < 0) {
4582 spin_unlock_bh(&rdev
->bss_lock
);
4586 nl80211_finish_netdev_dump(rdev
);
4591 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
4592 int flags
, struct net_device
*dev
,
4593 struct survey_info
*survey
)
4596 struct nlattr
*infoattr
;
4598 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
4599 NL80211_CMD_NEW_SURVEY_RESULTS
);
4603 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
4604 goto nla_put_failure
;
4606 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4608 goto nla_put_failure
;
4610 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4611 survey
->channel
->center_freq
))
4612 goto nla_put_failure
;
4614 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
4615 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
4616 goto nla_put_failure
;
4617 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
4618 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
4619 goto nla_put_failure
;
4620 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
4621 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4622 survey
->channel_time
))
4623 goto nla_put_failure
;
4624 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
4625 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4626 survey
->channel_time_busy
))
4627 goto nla_put_failure
;
4628 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
4629 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4630 survey
->channel_time_ext_busy
))
4631 goto nla_put_failure
;
4632 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
4633 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4634 survey
->channel_time_rx
))
4635 goto nla_put_failure
;
4636 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
4637 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4638 survey
->channel_time_tx
))
4639 goto nla_put_failure
;
4641 nla_nest_end(msg
, infoattr
);
4643 return genlmsg_end(msg
, hdr
);
4646 genlmsg_cancel(msg
, hdr
);
4650 static int nl80211_dump_survey(struct sk_buff
*skb
,
4651 struct netlink_callback
*cb
)
4653 struct survey_info survey
;
4654 struct cfg80211_registered_device
*dev
;
4655 struct net_device
*netdev
;
4656 int survey_idx
= cb
->args
[1];
4659 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4663 if (!dev
->ops
->dump_survey
) {
4669 struct ieee80211_channel
*chan
;
4671 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4678 /* Survey without a channel doesn't make sense */
4679 if (!survey
.channel
) {
4684 chan
= ieee80211_get_channel(&dev
->wiphy
,
4685 survey
.channel
->center_freq
);
4686 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4691 if (nl80211_send_survey(skb
,
4692 NETLINK_CB(cb
->skb
).pid
,
4693 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4701 cb
->args
[1] = survey_idx
;
4704 nl80211_finish_netdev_dump(dev
);
4708 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
4710 return auth_type
<= NL80211_AUTHTYPE_MAX
;
4713 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4715 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4716 NL80211_WPA_VERSION_2
));
4719 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4721 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4722 struct net_device
*dev
= info
->user_ptr
[1];
4723 struct ieee80211_channel
*chan
;
4724 const u8
*bssid
, *ssid
, *ie
= NULL
;
4725 int err
, ssid_len
, ie_len
= 0;
4726 enum nl80211_auth_type auth_type
;
4727 struct key_parse key
;
4728 bool local_state_change
;
4730 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4733 if (!info
->attrs
[NL80211_ATTR_MAC
])
4736 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4739 if (!info
->attrs
[NL80211_ATTR_SSID
])
4742 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4745 err
= nl80211_parse_key(info
, &key
);
4750 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4752 if (!key
.p
.key
|| !key
.p
.key_len
)
4754 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4755 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4756 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4757 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4769 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4770 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4779 if (!rdev
->ops
->auth
)
4782 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4783 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4786 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4787 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4788 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4789 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4792 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4793 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4795 if (info
->attrs
[NL80211_ATTR_IE
]) {
4796 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4797 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4800 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4801 if (!nl80211_valid_auth_type(auth_type
))
4804 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4807 * Since we no longer track auth state, ignore
4808 * requests to only change local state.
4810 if (local_state_change
)
4813 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4814 ssid
, ssid_len
, ie
, ie_len
,
4815 key
.p
.key
, key
.p
.key_len
, key
.idx
);
4818 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
4819 struct genl_info
*info
,
4820 struct cfg80211_crypto_settings
*settings
,
4823 memset(settings
, 0, sizeof(*settings
));
4825 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
4827 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
4829 proto
= nla_get_u16(
4830 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
4831 settings
->control_port_ethertype
= cpu_to_be16(proto
);
4832 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
4835 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4836 settings
->control_port_no_encrypt
= true;
4838 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4840 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4844 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4845 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4846 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4848 if (len
% sizeof(u32
))
4851 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4854 memcpy(settings
->ciphers_pairwise
, data
, len
);
4856 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4857 if (!cfg80211_supported_cipher_suite(
4859 settings
->ciphers_pairwise
[i
]))
4863 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4864 settings
->cipher_group
=
4865 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4866 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
4867 settings
->cipher_group
))
4871 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4872 settings
->wpa_versions
=
4873 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4874 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4878 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4882 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4883 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4884 settings
->n_akm_suites
= len
/ sizeof(u32
);
4886 if (len
% sizeof(u32
))
4889 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4892 memcpy(settings
->akm_suites
, data
, len
);
4898 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4900 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4901 struct net_device
*dev
= info
->user_ptr
[1];
4902 struct cfg80211_crypto_settings crypto
;
4903 struct ieee80211_channel
*chan
;
4904 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4905 int err
, ssid_len
, ie_len
= 0;
4906 bool use_mfp
= false;
4908 struct ieee80211_ht_cap
*ht_capa
= NULL
;
4909 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
4911 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4914 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4915 !info
->attrs
[NL80211_ATTR_SSID
] ||
4916 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4919 if (!rdev
->ops
->assoc
)
4922 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4923 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4926 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4928 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4929 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4930 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4933 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4934 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4936 if (info
->attrs
[NL80211_ATTR_IE
]) {
4937 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4938 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4941 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4942 enum nl80211_mfp mfp
=
4943 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4944 if (mfp
== NL80211_MFP_REQUIRED
)
4946 else if (mfp
!= NL80211_MFP_NO
)
4950 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4951 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4953 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
4954 flags
|= ASSOC_REQ_DISABLE_HT
;
4956 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
4958 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
4960 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
4963 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4966 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4968 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4969 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4970 &crypto
, flags
, ht_capa
,
4976 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4978 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4979 struct net_device
*dev
= info
->user_ptr
[1];
4980 const u8
*ie
= NULL
, *bssid
;
4983 bool local_state_change
;
4985 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4988 if (!info
->attrs
[NL80211_ATTR_MAC
])
4991 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4994 if (!rdev
->ops
->deauth
)
4997 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4998 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5001 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5003 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5004 if (reason_code
== 0) {
5005 /* Reason Code 0 is reserved */
5009 if (info
->attrs
[NL80211_ATTR_IE
]) {
5010 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5011 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5014 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5016 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5017 local_state_change
);
5020 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
5022 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5023 struct net_device
*dev
= info
->user_ptr
[1];
5024 const u8
*ie
= NULL
, *bssid
;
5027 bool local_state_change
;
5029 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5032 if (!info
->attrs
[NL80211_ATTR_MAC
])
5035 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5038 if (!rdev
->ops
->disassoc
)
5041 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5042 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5045 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5047 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5048 if (reason_code
== 0) {
5049 /* Reason Code 0 is reserved */
5053 if (info
->attrs
[NL80211_ATTR_IE
]) {
5054 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5055 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5058 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5060 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5061 local_state_change
);
5065 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
5066 int mcast_rate
[IEEE80211_NUM_BANDS
],
5069 struct wiphy
*wiphy
= &rdev
->wiphy
;
5073 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5074 struct ieee80211_supported_band
*sband
;
5076 sband
= wiphy
->bands
[band
];
5080 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
5081 if (sband
->bitrates
[i
].bitrate
== rateval
) {
5082 mcast_rate
[band
] = i
+ 1;
5092 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5094 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5095 struct net_device
*dev
= info
->user_ptr
[1];
5096 struct cfg80211_ibss_params ibss
;
5097 struct wiphy
*wiphy
;
5098 struct cfg80211_cached_keys
*connkeys
= NULL
;
5101 memset(&ibss
, 0, sizeof(ibss
));
5103 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5106 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5107 !info
->attrs
[NL80211_ATTR_SSID
] ||
5108 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5111 ibss
.beacon_interval
= 100;
5113 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
5114 ibss
.beacon_interval
=
5115 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5116 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
5120 if (!rdev
->ops
->join_ibss
)
5123 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5126 wiphy
= &rdev
->wiphy
;
5128 if (info
->attrs
[NL80211_ATTR_MAC
]) {
5129 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5131 if (!is_valid_ether_addr(ibss
.bssid
))
5134 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5135 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5137 if (info
->attrs
[NL80211_ATTR_IE
]) {
5138 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5139 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5142 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5143 enum nl80211_channel_type channel_type
;
5145 if (!nl80211_valid_channel_type(info
, &channel_type
))
5148 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5149 !(wiphy
->features
& NL80211_FEATURE_HT_IBSS
))
5152 ibss
.channel_type
= channel_type
;
5154 ibss
.channel_type
= NL80211_CHAN_NO_HT
;
5157 ibss
.channel
= rdev_freq_to_chan(rdev
,
5158 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
5160 if (!ibss
.channel
||
5161 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
5162 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5165 /* Both channels should be able to initiate communication */
5166 if ((ibss
.channel_type
== NL80211_CHAN_HT40PLUS
||
5167 ibss
.channel_type
== NL80211_CHAN_HT40MINUS
) &&
5168 !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, ibss
.channel
,
5172 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
5173 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5175 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5177 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5179 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5180 struct ieee80211_supported_band
*sband
=
5181 wiphy
->bands
[ibss
.channel
->band
];
5183 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
5189 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5190 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
5191 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5194 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5195 connkeys
= nl80211_parse_connkeys(rdev
,
5196 info
->attrs
[NL80211_ATTR_KEYS
]);
5197 if (IS_ERR(connkeys
))
5198 return PTR_ERR(connkeys
);
5202 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
5204 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
5210 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5212 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5213 struct net_device
*dev
= info
->user_ptr
[1];
5215 if (!rdev
->ops
->leave_ibss
)
5218 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5221 return cfg80211_leave_ibss(rdev
, dev
, false);
5224 #ifdef CONFIG_NL80211_TESTMODE
5225 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
5229 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
5231 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5234 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
5238 if (rdev
->ops
->testmode_cmd
) {
5239 rdev
->testmode_info
= info
;
5240 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
5241 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
5242 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
5243 rdev
->testmode_info
= NULL
;
5249 static int nl80211_testmode_dump(struct sk_buff
*skb
,
5250 struct netlink_callback
*cb
)
5252 struct cfg80211_registered_device
*rdev
;
5260 * 0 is a valid index, but not valid for args[0],
5261 * so we need to offset by 1.
5263 phy_idx
= cb
->args
[0] - 1;
5265 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
5266 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
5271 mutex_lock(&cfg80211_mutex
);
5272 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
5273 nl80211_fam
.attrbuf
);
5275 mutex_unlock(&cfg80211_mutex
);
5276 return PTR_ERR(rdev
);
5278 phy_idx
= rdev
->wiphy_idx
;
5280 mutex_unlock(&cfg80211_mutex
);
5282 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
5284 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
5288 data
= nla_data((void *)cb
->args
[1]);
5289 data_len
= nla_len((void *)cb
->args
[1]);
5292 mutex_lock(&cfg80211_mutex
);
5293 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
5295 mutex_unlock(&cfg80211_mutex
);
5298 cfg80211_lock_rdev(rdev
);
5299 mutex_unlock(&cfg80211_mutex
);
5301 if (!rdev
->ops
->testmode_dump
) {
5307 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).pid
,
5308 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5309 NL80211_CMD_TESTMODE
);
5310 struct nlattr
*tmdata
;
5312 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
5313 genlmsg_cancel(skb
, hdr
);
5317 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5319 genlmsg_cancel(skb
, hdr
);
5322 err
= rdev
->ops
->testmode_dump(&rdev
->wiphy
, skb
, cb
,
5324 nla_nest_end(skb
, tmdata
);
5326 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
5327 genlmsg_cancel(skb
, hdr
);
5330 genlmsg_cancel(skb
, hdr
);
5334 genlmsg_end(skb
, hdr
);
5339 cb
->args
[0] = phy_idx
+ 1;
5341 cfg80211_unlock_rdev(rdev
);
5345 static struct sk_buff
*
5346 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
5347 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
5349 struct sk_buff
*skb
;
5351 struct nlattr
*data
;
5353 skb
= nlmsg_new(approxlen
+ 100, gfp
);
5357 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
5363 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
5364 goto nla_put_failure
;
5365 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5367 ((void **)skb
->cb
)[0] = rdev
;
5368 ((void **)skb
->cb
)[1] = hdr
;
5369 ((void **)skb
->cb
)[2] = data
;
5378 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
5381 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5383 if (WARN_ON(!rdev
->testmode_info
))
5386 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
5387 rdev
->testmode_info
->snd_pid
,
5388 rdev
->testmode_info
->snd_seq
,
5391 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
5393 int cfg80211_testmode_reply(struct sk_buff
*skb
)
5395 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
5396 void *hdr
= ((void **)skb
->cb
)[1];
5397 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5399 if (WARN_ON(!rdev
->testmode_info
)) {
5404 nla_nest_end(skb
, data
);
5405 genlmsg_end(skb
, hdr
);
5406 return genlmsg_reply(skb
, rdev
->testmode_info
);
5408 EXPORT_SYMBOL(cfg80211_testmode_reply
);
5410 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
5411 int approxlen
, gfp_t gfp
)
5413 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5415 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
5417 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
5419 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
5421 void *hdr
= ((void **)skb
->cb
)[1];
5422 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5424 nla_nest_end(skb
, data
);
5425 genlmsg_end(skb
, hdr
);
5426 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
5428 EXPORT_SYMBOL(cfg80211_testmode_event
);
5431 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
5433 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5434 struct net_device
*dev
= info
->user_ptr
[1];
5435 struct cfg80211_connect_params connect
;
5436 struct wiphy
*wiphy
;
5437 struct cfg80211_cached_keys
*connkeys
= NULL
;
5440 memset(&connect
, 0, sizeof(connect
));
5442 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5445 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5446 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5449 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5451 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5452 if (!nl80211_valid_auth_type(connect
.auth_type
))
5455 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5457 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
5459 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
5460 NL80211_MAX_NR_CIPHER_SUITES
);
5464 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5465 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5468 wiphy
= &rdev
->wiphy
;
5470 connect
.bg_scan_period
= -1;
5471 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
5472 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
5473 connect
.bg_scan_period
=
5474 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
5477 if (info
->attrs
[NL80211_ATTR_MAC
])
5478 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5479 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5480 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5482 if (info
->attrs
[NL80211_ATTR_IE
]) {
5483 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5484 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5487 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5489 ieee80211_get_channel(wiphy
,
5490 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5491 if (!connect
.channel
||
5492 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5496 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5497 connkeys
= nl80211_parse_connkeys(rdev
,
5498 info
->attrs
[NL80211_ATTR_KEYS
]);
5499 if (IS_ERR(connkeys
))
5500 return PTR_ERR(connkeys
);
5503 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5504 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
5506 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5507 memcpy(&connect
.ht_capa_mask
,
5508 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
5509 sizeof(connect
.ht_capa_mask
));
5511 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5512 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5514 memcpy(&connect
.ht_capa
,
5515 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
5516 sizeof(connect
.ht_capa
));
5519 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
5525 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
5527 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5528 struct net_device
*dev
= info
->user_ptr
[1];
5531 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5532 reason
= WLAN_REASON_DEAUTH_LEAVING
;
5534 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5539 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5540 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5543 return cfg80211_disconnect(rdev
, dev
, reason
, true);
5546 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
5548 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5553 if (!info
->attrs
[NL80211_ATTR_PID
])
5556 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
5558 net
= get_net_ns_by_pid(pid
);
5560 return PTR_ERR(net
);
5564 /* check if anything to do */
5565 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
5566 err
= cfg80211_switch_netns(rdev
, net
);
5572 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5574 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5575 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
5576 struct cfg80211_pmksa
*pmksa
) = NULL
;
5577 struct net_device
*dev
= info
->user_ptr
[1];
5578 struct cfg80211_pmksa pmksa
;
5580 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
5582 if (!info
->attrs
[NL80211_ATTR_MAC
])
5585 if (!info
->attrs
[NL80211_ATTR_PMKID
])
5588 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
5589 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5591 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5592 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5595 switch (info
->genlhdr
->cmd
) {
5596 case NL80211_CMD_SET_PMKSA
:
5597 rdev_ops
= rdev
->ops
->set_pmksa
;
5599 case NL80211_CMD_DEL_PMKSA
:
5600 rdev_ops
= rdev
->ops
->del_pmksa
;
5610 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
5613 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5615 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5616 struct net_device
*dev
= info
->user_ptr
[1];
5618 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5619 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5622 if (!rdev
->ops
->flush_pmksa
)
5625 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
5628 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5630 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5631 struct net_device
*dev
= info
->user_ptr
[1];
5632 u8 action_code
, dialog_token
;
5636 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5637 !rdev
->ops
->tdls_mgmt
)
5640 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5641 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5642 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5643 !info
->attrs
[NL80211_ATTR_IE
] ||
5644 !info
->attrs
[NL80211_ATTR_MAC
])
5647 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5648 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5649 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5650 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5652 return rdev
->ops
->tdls_mgmt(&rdev
->wiphy
, dev
, peer
, action_code
,
5653 dialog_token
, status_code
,
5654 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5655 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5658 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5660 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5661 struct net_device
*dev
= info
->user_ptr
[1];
5662 enum nl80211_tdls_operation operation
;
5665 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5666 !rdev
->ops
->tdls_oper
)
5669 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5670 !info
->attrs
[NL80211_ATTR_MAC
])
5673 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5674 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5676 return rdev
->ops
->tdls_oper(&rdev
->wiphy
, dev
, peer
, operation
);
5679 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5680 struct genl_info
*info
)
5682 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5683 struct net_device
*dev
= info
->user_ptr
[1];
5684 struct ieee80211_channel
*chan
;
5685 struct sk_buff
*msg
;
5688 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5692 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5693 !info
->attrs
[NL80211_ATTR_DURATION
])
5696 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5698 if (!rdev
->ops
->remain_on_channel
||
5699 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
5703 * We should be on that channel for at least a minimum amount of
5704 * time (10ms) but no longer than the driver supports.
5706 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
5707 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5710 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
5711 !nl80211_valid_channel_type(info
, &channel_type
))
5714 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5715 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5719 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5723 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5724 NL80211_CMD_REMAIN_ON_CHANNEL
);
5731 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
5732 channel_type
, duration
, &cookie
);
5737 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
5738 goto nla_put_failure
;
5740 genlmsg_end(msg
, hdr
);
5742 return genlmsg_reply(msg
, info
);
5751 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5752 struct genl_info
*info
)
5754 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5755 struct net_device
*dev
= info
->user_ptr
[1];
5758 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5761 if (!rdev
->ops
->cancel_remain_on_channel
)
5764 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5766 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
5769 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5770 u8
*rates
, u8 rates_len
)
5775 for (i
= 0; i
< rates_len
; i
++) {
5776 int rate
= (rates
[i
] & 0x7f) * 5;
5778 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5779 struct ieee80211_rate
*srate
=
5780 &sband
->bitrates
[ridx
];
5781 if (rate
== srate
->bitrate
) {
5786 if (ridx
== sband
->n_bitrates
)
5787 return 0; /* rate not found */
5793 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
5794 u8
*rates
, u8 rates_len
,
5795 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
5799 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
5801 for (i
= 0; i
< rates_len
; i
++) {
5804 ridx
= rates
[i
] / 8;
5805 rbit
= BIT(rates
[i
] % 8);
5807 /* check validity */
5808 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
5811 /* check availability */
5812 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
5821 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
5822 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
5823 .len
= NL80211_MAX_SUPP_RATES
},
5824 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
5825 .len
= NL80211_MAX_SUPP_HT_RATES
},
5828 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
5829 struct genl_info
*info
)
5831 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
5832 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5833 struct cfg80211_bitrate_mask mask
;
5835 struct net_device
*dev
= info
->user_ptr
[1];
5836 struct nlattr
*tx_rates
;
5837 struct ieee80211_supported_band
*sband
;
5839 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
5842 if (!rdev
->ops
->set_bitrate_mask
)
5845 memset(&mask
, 0, sizeof(mask
));
5846 /* Default to all rates enabled */
5847 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
5848 sband
= rdev
->wiphy
.bands
[i
];
5849 mask
.control
[i
].legacy
=
5850 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
5852 memcpy(mask
.control
[i
].mcs
,
5853 sband
->ht_cap
.mcs
.rx_mask
,
5854 sizeof(mask
.control
[i
].mcs
));
5856 memset(mask
.control
[i
].mcs
, 0,
5857 sizeof(mask
.control
[i
].mcs
));
5861 * The nested attribute uses enum nl80211_band as the index. This maps
5862 * directly to the enum ieee80211_band values used in cfg80211.
5864 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
5865 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
5867 enum ieee80211_band band
= nla_type(tx_rates
);
5868 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
5870 sband
= rdev
->wiphy
.bands
[band
];
5873 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
5874 nla_len(tx_rates
), nl80211_txattr_policy
);
5875 if (tb
[NL80211_TXRATE_LEGACY
]) {
5876 mask
.control
[band
].legacy
= rateset_to_mask(
5878 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
5879 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
5880 if ((mask
.control
[band
].legacy
== 0) &&
5881 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
5884 if (tb
[NL80211_TXRATE_MCS
]) {
5885 if (!ht_rateset_to_mask(
5887 nla_data(tb
[NL80211_TXRATE_MCS
]),
5888 nla_len(tb
[NL80211_TXRATE_MCS
]),
5889 mask
.control
[band
].mcs
))
5893 if (mask
.control
[band
].legacy
== 0) {
5894 /* don't allow empty legacy rates if HT
5895 * is not even supported. */
5896 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
5899 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
5900 if (mask
.control
[band
].mcs
[i
])
5903 /* legacy and mcs rates may not be both empty */
5904 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
5909 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
5912 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5914 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5915 struct net_device
*dev
= info
->user_ptr
[1];
5916 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
5918 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
5921 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
5922 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
5924 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5925 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5926 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5927 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5928 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5929 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5930 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5933 /* not much point in registering if we can't reply */
5934 if (!rdev
->ops
->mgmt_tx
)
5937 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
5939 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
5940 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
5943 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5945 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5946 struct net_device
*dev
= info
->user_ptr
[1];
5947 struct ieee80211_channel
*chan
;
5948 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5949 bool channel_type_valid
= false;
5954 struct sk_buff
*msg
= NULL
;
5955 unsigned int wait
= 0;
5956 bool offchan
, no_cck
, dont_wait_for_ack
;
5958 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
5960 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
5961 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5964 if (!rdev
->ops
->mgmt_tx
)
5967 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5968 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5969 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5970 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5971 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5972 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5973 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5976 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
5977 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
5979 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5982 * We should wait on the channel for at least a minimum amount
5983 * of time (10ms) but no longer than the driver supports.
5985 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
5986 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
5991 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5992 if (!nl80211_valid_channel_type(info
, &channel_type
))
5994 channel_type_valid
= true;
5997 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
5999 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6002 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6004 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6005 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
6009 if (!dont_wait_for_ack
) {
6010 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6014 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6023 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
6024 channel_type_valid
, wait
,
6025 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
6026 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
6027 no_cck
, dont_wait_for_ack
, &cookie
);
6032 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6033 goto nla_put_failure
;
6035 genlmsg_end(msg
, hdr
);
6036 return genlmsg_reply(msg
, info
);
6048 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
6050 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6051 struct net_device
*dev
= info
->user_ptr
[1];
6054 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6057 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
6060 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6061 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6062 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
6063 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
6064 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
6065 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6068 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6070 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
6073 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6075 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6076 struct wireless_dev
*wdev
;
6077 struct net_device
*dev
= info
->user_ptr
[1];
6082 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
6085 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
6087 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
6090 wdev
= dev
->ieee80211_ptr
;
6092 if (!rdev
->ops
->set_power_mgmt
)
6095 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
6097 if (state
== wdev
->ps
)
6100 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
6107 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6109 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6110 enum nl80211_ps_state ps_state
;
6111 struct wireless_dev
*wdev
;
6112 struct net_device
*dev
= info
->user_ptr
[1];
6113 struct sk_buff
*msg
;
6117 wdev
= dev
->ieee80211_ptr
;
6119 if (!rdev
->ops
->set_power_mgmt
)
6122 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6126 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6127 NL80211_CMD_GET_POWER_SAVE
);
6134 ps_state
= NL80211_PS_ENABLED
;
6136 ps_state
= NL80211_PS_DISABLED
;
6138 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
6139 goto nla_put_failure
;
6141 genlmsg_end(msg
, hdr
);
6142 return genlmsg_reply(msg
, info
);
6151 static struct nla_policy
6152 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
6153 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
6154 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
6155 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
6158 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
6159 s32 threshold
, u32 hysteresis
)
6161 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6162 struct wireless_dev
*wdev
;
6163 struct net_device
*dev
= info
->user_ptr
[1];
6168 wdev
= dev
->ieee80211_ptr
;
6170 if (!rdev
->ops
->set_cqm_rssi_config
)
6173 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6174 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6177 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
6178 threshold
, hysteresis
);
6181 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
6183 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
6187 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
6193 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
6194 nl80211_attr_cqm_policy
);
6198 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
6199 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
6202 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
6203 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
6204 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
6212 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6214 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6215 struct net_device
*dev
= info
->user_ptr
[1];
6216 struct mesh_config cfg
;
6217 struct mesh_setup setup
;
6220 /* start with default */
6221 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
6222 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
6224 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
6225 /* and parse parameters if given */
6226 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
6231 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
6232 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
6235 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6236 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6238 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6239 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
6240 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6243 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
6244 /* parse additional setup parameters if given */
6245 err
= nl80211_parse_mesh_setup(info
, &setup
);
6250 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6251 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6253 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
6254 !nl80211_valid_channel_type(info
, &channel_type
))
6257 setup
.channel
= rdev_freq_to_chan(rdev
,
6258 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
6262 setup
.channel_type
= channel_type
;
6264 /* cfg80211_join_mesh() will sort it out */
6265 setup
.channel
= NULL
;
6268 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
6271 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6273 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6274 struct net_device
*dev
= info
->user_ptr
[1];
6276 return cfg80211_leave_mesh(rdev
, dev
);
6279 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6281 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6282 struct sk_buff
*msg
;
6285 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6288 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6292 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6293 NL80211_CMD_GET_WOWLAN
);
6295 goto nla_put_failure
;
6298 struct nlattr
*nl_wowlan
;
6300 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
6302 goto nla_put_failure
;
6304 if ((rdev
->wowlan
->any
&&
6305 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
6306 (rdev
->wowlan
->disconnect
&&
6307 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
6308 (rdev
->wowlan
->magic_pkt
&&
6309 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
6310 (rdev
->wowlan
->gtk_rekey_failure
&&
6311 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
6312 (rdev
->wowlan
->eap_identity_req
&&
6313 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
6314 (rdev
->wowlan
->four_way_handshake
&&
6315 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
6316 (rdev
->wowlan
->rfkill_release
&&
6317 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
6318 goto nla_put_failure
;
6319 if (rdev
->wowlan
->n_patterns
) {
6320 struct nlattr
*nl_pats
, *nl_pat
;
6323 nl_pats
= nla_nest_start(msg
,
6324 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
6326 goto nla_put_failure
;
6328 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
6329 nl_pat
= nla_nest_start(msg
, i
+ 1);
6331 goto nla_put_failure
;
6332 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
6333 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
6334 DIV_ROUND_UP(pat_len
, 8),
6335 rdev
->wowlan
->patterns
[i
].mask
) ||
6336 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
6338 rdev
->wowlan
->patterns
[i
].pattern
))
6339 goto nla_put_failure
;
6340 nla_nest_end(msg
, nl_pat
);
6342 nla_nest_end(msg
, nl_pats
);
6345 nla_nest_end(msg
, nl_wowlan
);
6348 genlmsg_end(msg
, hdr
);
6349 return genlmsg_reply(msg
, info
);
6356 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6358 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6359 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
6360 struct cfg80211_wowlan no_triggers
= {};
6361 struct cfg80211_wowlan new_triggers
= {};
6362 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
6364 bool prev_enabled
= rdev
->wowlan
;
6366 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6369 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
6372 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
6373 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6374 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6375 nl80211_wowlan_policy
);
6379 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
6380 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
6382 new_triggers
.any
= true;
6385 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
6386 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
6388 new_triggers
.disconnect
= true;
6391 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
6392 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
6394 new_triggers
.magic_pkt
= true;
6397 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
6400 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
6401 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
6403 new_triggers
.gtk_rekey_failure
= true;
6406 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
6407 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
6409 new_triggers
.eap_identity_req
= true;
6412 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
6413 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
6415 new_triggers
.four_way_handshake
= true;
6418 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
6419 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
6421 new_triggers
.rfkill_release
= true;
6424 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
6427 int rem
, pat_len
, mask_len
;
6428 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
6430 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6433 if (n_patterns
> wowlan
->n_patterns
)
6436 new_triggers
.patterns
= kcalloc(n_patterns
,
6437 sizeof(new_triggers
.patterns
[0]),
6439 if (!new_triggers
.patterns
)
6442 new_triggers
.n_patterns
= n_patterns
;
6445 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6447 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
6448 nla_data(pat
), nla_len(pat
), NULL
);
6450 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
6451 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
6453 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
6454 mask_len
= DIV_ROUND_UP(pat_len
, 8);
6455 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
6458 if (pat_len
> wowlan
->pattern_max_len
||
6459 pat_len
< wowlan
->pattern_min_len
)
6462 new_triggers
.patterns
[i
].mask
=
6463 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
6464 if (!new_triggers
.patterns
[i
].mask
) {
6468 new_triggers
.patterns
[i
].pattern
=
6469 new_triggers
.patterns
[i
].mask
+ mask_len
;
6470 memcpy(new_triggers
.patterns
[i
].mask
,
6471 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
6473 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
6474 memcpy(new_triggers
.patterns
[i
].pattern
,
6475 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
6481 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
6482 struct cfg80211_wowlan
*ntrig
;
6483 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
6489 cfg80211_rdev_free_wowlan(rdev
);
6490 rdev
->wowlan
= ntrig
;
6493 cfg80211_rdev_free_wowlan(rdev
);
6494 rdev
->wowlan
= NULL
;
6497 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
6498 rdev
->ops
->set_wakeup(&rdev
->wiphy
, rdev
->wowlan
);
6502 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
6503 kfree(new_triggers
.patterns
[i
].mask
);
6504 kfree(new_triggers
.patterns
);
6508 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
6510 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6511 struct net_device
*dev
= info
->user_ptr
[1];
6512 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6513 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
6514 struct cfg80211_gtk_rekey_data rekey_data
;
6517 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
6520 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
6521 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6522 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6523 nl80211_rekey_policy
);
6527 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
6529 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
6531 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
6534 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
6536 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
6538 memcpy(rekey_data
.replay_ctr
,
6539 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
6540 NL80211_REPLAY_CTR_LEN
);
6543 if (!wdev
->current_bss
) {
6548 if (!rdev
->ops
->set_rekey_data
) {
6553 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
6559 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
6560 struct genl_info
*info
)
6562 struct net_device
*dev
= info
->user_ptr
[1];
6563 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6565 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6566 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6569 if (wdev
->ap_unexpected_nlpid
)
6572 wdev
->ap_unexpected_nlpid
= info
->snd_pid
;
6576 static int nl80211_probe_client(struct sk_buff
*skb
,
6577 struct genl_info
*info
)
6579 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6580 struct net_device
*dev
= info
->user_ptr
[1];
6581 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6582 struct sk_buff
*msg
;
6588 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6589 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6592 if (!info
->attrs
[NL80211_ATTR_MAC
])
6595 if (!rdev
->ops
->probe_client
)
6598 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6602 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6603 NL80211_CMD_PROBE_CLIENT
);
6610 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6612 err
= rdev
->ops
->probe_client(&rdev
->wiphy
, dev
, addr
, &cookie
);
6616 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6617 goto nla_put_failure
;
6619 genlmsg_end(msg
, hdr
);
6621 return genlmsg_reply(msg
, info
);
6630 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
6632 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6634 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
6637 if (rdev
->ap_beacons_nlpid
)
6640 rdev
->ap_beacons_nlpid
= info
->snd_pid
;
6645 #define NL80211_FLAG_NEED_WIPHY 0x01
6646 #define NL80211_FLAG_NEED_NETDEV 0x02
6647 #define NL80211_FLAG_NEED_RTNL 0x04
6648 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6649 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6650 NL80211_FLAG_CHECK_NETDEV_UP)
6652 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6653 struct genl_info
*info
)
6655 struct cfg80211_registered_device
*rdev
;
6656 struct net_device
*dev
;
6658 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
6663 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
6664 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6668 return PTR_ERR(rdev
);
6670 info
->user_ptr
[0] = rdev
;
6671 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
6672 err
= get_rdev_dev_by_ifindex(genl_info_net(info
), info
->attrs
,
6679 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
6680 !netif_running(dev
)) {
6681 cfg80211_unlock_rdev(rdev
);
6687 info
->user_ptr
[0] = rdev
;
6688 info
->user_ptr
[1] = dev
;
6694 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6695 struct genl_info
*info
)
6697 if (info
->user_ptr
[0])
6698 cfg80211_unlock_rdev(info
->user_ptr
[0]);
6699 if (info
->user_ptr
[1])
6700 dev_put(info
->user_ptr
[1]);
6701 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
6705 static struct genl_ops nl80211_ops
[] = {
6707 .cmd
= NL80211_CMD_GET_WIPHY
,
6708 .doit
= nl80211_get_wiphy
,
6709 .dumpit
= nl80211_dump_wiphy
,
6710 .policy
= nl80211_policy
,
6711 /* can be retrieved by unprivileged users */
6712 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
6715 .cmd
= NL80211_CMD_SET_WIPHY
,
6716 .doit
= nl80211_set_wiphy
,
6717 .policy
= nl80211_policy
,
6718 .flags
= GENL_ADMIN_PERM
,
6719 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
6722 .cmd
= NL80211_CMD_GET_INTERFACE
,
6723 .doit
= nl80211_get_interface
,
6724 .dumpit
= nl80211_dump_interface
,
6725 .policy
= nl80211_policy
,
6726 /* can be retrieved by unprivileged users */
6727 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
6730 .cmd
= NL80211_CMD_SET_INTERFACE
,
6731 .doit
= nl80211_set_interface
,
6732 .policy
= nl80211_policy
,
6733 .flags
= GENL_ADMIN_PERM
,
6734 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6735 NL80211_FLAG_NEED_RTNL
,
6738 .cmd
= NL80211_CMD_NEW_INTERFACE
,
6739 .doit
= nl80211_new_interface
,
6740 .policy
= nl80211_policy
,
6741 .flags
= GENL_ADMIN_PERM
,
6742 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6743 NL80211_FLAG_NEED_RTNL
,
6746 .cmd
= NL80211_CMD_DEL_INTERFACE
,
6747 .doit
= nl80211_del_interface
,
6748 .policy
= nl80211_policy
,
6749 .flags
= GENL_ADMIN_PERM
,
6750 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6751 NL80211_FLAG_NEED_RTNL
,
6754 .cmd
= NL80211_CMD_GET_KEY
,
6755 .doit
= nl80211_get_key
,
6756 .policy
= nl80211_policy
,
6757 .flags
= GENL_ADMIN_PERM
,
6758 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6759 NL80211_FLAG_NEED_RTNL
,
6762 .cmd
= NL80211_CMD_SET_KEY
,
6763 .doit
= nl80211_set_key
,
6764 .policy
= nl80211_policy
,
6765 .flags
= GENL_ADMIN_PERM
,
6766 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6767 NL80211_FLAG_NEED_RTNL
,
6770 .cmd
= NL80211_CMD_NEW_KEY
,
6771 .doit
= nl80211_new_key
,
6772 .policy
= nl80211_policy
,
6773 .flags
= GENL_ADMIN_PERM
,
6774 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6775 NL80211_FLAG_NEED_RTNL
,
6778 .cmd
= NL80211_CMD_DEL_KEY
,
6779 .doit
= nl80211_del_key
,
6780 .policy
= nl80211_policy
,
6781 .flags
= GENL_ADMIN_PERM
,
6782 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6783 NL80211_FLAG_NEED_RTNL
,
6786 .cmd
= NL80211_CMD_SET_BEACON
,
6787 .policy
= nl80211_policy
,
6788 .flags
= GENL_ADMIN_PERM
,
6789 .doit
= nl80211_set_beacon
,
6790 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6791 NL80211_FLAG_NEED_RTNL
,
6794 .cmd
= NL80211_CMD_START_AP
,
6795 .policy
= nl80211_policy
,
6796 .flags
= GENL_ADMIN_PERM
,
6797 .doit
= nl80211_start_ap
,
6798 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6799 NL80211_FLAG_NEED_RTNL
,
6802 .cmd
= NL80211_CMD_STOP_AP
,
6803 .policy
= nl80211_policy
,
6804 .flags
= GENL_ADMIN_PERM
,
6805 .doit
= nl80211_stop_ap
,
6806 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6807 NL80211_FLAG_NEED_RTNL
,
6810 .cmd
= NL80211_CMD_GET_STATION
,
6811 .doit
= nl80211_get_station
,
6812 .dumpit
= nl80211_dump_station
,
6813 .policy
= nl80211_policy
,
6814 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6815 NL80211_FLAG_NEED_RTNL
,
6818 .cmd
= NL80211_CMD_SET_STATION
,
6819 .doit
= nl80211_set_station
,
6820 .policy
= nl80211_policy
,
6821 .flags
= GENL_ADMIN_PERM
,
6822 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6823 NL80211_FLAG_NEED_RTNL
,
6826 .cmd
= NL80211_CMD_NEW_STATION
,
6827 .doit
= nl80211_new_station
,
6828 .policy
= nl80211_policy
,
6829 .flags
= GENL_ADMIN_PERM
,
6830 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6831 NL80211_FLAG_NEED_RTNL
,
6834 .cmd
= NL80211_CMD_DEL_STATION
,
6835 .doit
= nl80211_del_station
,
6836 .policy
= nl80211_policy
,
6837 .flags
= GENL_ADMIN_PERM
,
6838 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6839 NL80211_FLAG_NEED_RTNL
,
6842 .cmd
= NL80211_CMD_GET_MPATH
,
6843 .doit
= nl80211_get_mpath
,
6844 .dumpit
= nl80211_dump_mpath
,
6845 .policy
= nl80211_policy
,
6846 .flags
= GENL_ADMIN_PERM
,
6847 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6848 NL80211_FLAG_NEED_RTNL
,
6851 .cmd
= NL80211_CMD_SET_MPATH
,
6852 .doit
= nl80211_set_mpath
,
6853 .policy
= nl80211_policy
,
6854 .flags
= GENL_ADMIN_PERM
,
6855 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6856 NL80211_FLAG_NEED_RTNL
,
6859 .cmd
= NL80211_CMD_NEW_MPATH
,
6860 .doit
= nl80211_new_mpath
,
6861 .policy
= nl80211_policy
,
6862 .flags
= GENL_ADMIN_PERM
,
6863 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6864 NL80211_FLAG_NEED_RTNL
,
6867 .cmd
= NL80211_CMD_DEL_MPATH
,
6868 .doit
= nl80211_del_mpath
,
6869 .policy
= nl80211_policy
,
6870 .flags
= GENL_ADMIN_PERM
,
6871 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6872 NL80211_FLAG_NEED_RTNL
,
6875 .cmd
= NL80211_CMD_SET_BSS
,
6876 .doit
= nl80211_set_bss
,
6877 .policy
= nl80211_policy
,
6878 .flags
= GENL_ADMIN_PERM
,
6879 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6880 NL80211_FLAG_NEED_RTNL
,
6883 .cmd
= NL80211_CMD_GET_REG
,
6884 .doit
= nl80211_get_reg
,
6885 .policy
= nl80211_policy
,
6886 /* can be retrieved by unprivileged users */
6889 .cmd
= NL80211_CMD_SET_REG
,
6890 .doit
= nl80211_set_reg
,
6891 .policy
= nl80211_policy
,
6892 .flags
= GENL_ADMIN_PERM
,
6895 .cmd
= NL80211_CMD_REQ_SET_REG
,
6896 .doit
= nl80211_req_set_reg
,
6897 .policy
= nl80211_policy
,
6898 .flags
= GENL_ADMIN_PERM
,
6901 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
6902 .doit
= nl80211_get_mesh_config
,
6903 .policy
= nl80211_policy
,
6904 /* can be retrieved by unprivileged users */
6905 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6906 NL80211_FLAG_NEED_RTNL
,
6909 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
6910 .doit
= nl80211_update_mesh_config
,
6911 .policy
= nl80211_policy
,
6912 .flags
= GENL_ADMIN_PERM
,
6913 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6914 NL80211_FLAG_NEED_RTNL
,
6917 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
6918 .doit
= nl80211_trigger_scan
,
6919 .policy
= nl80211_policy
,
6920 .flags
= GENL_ADMIN_PERM
,
6921 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6922 NL80211_FLAG_NEED_RTNL
,
6925 .cmd
= NL80211_CMD_GET_SCAN
,
6926 .policy
= nl80211_policy
,
6927 .dumpit
= nl80211_dump_scan
,
6930 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
6931 .doit
= nl80211_start_sched_scan
,
6932 .policy
= nl80211_policy
,
6933 .flags
= GENL_ADMIN_PERM
,
6934 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6935 NL80211_FLAG_NEED_RTNL
,
6938 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
6939 .doit
= nl80211_stop_sched_scan
,
6940 .policy
= nl80211_policy
,
6941 .flags
= GENL_ADMIN_PERM
,
6942 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6943 NL80211_FLAG_NEED_RTNL
,
6946 .cmd
= NL80211_CMD_AUTHENTICATE
,
6947 .doit
= nl80211_authenticate
,
6948 .policy
= nl80211_policy
,
6949 .flags
= GENL_ADMIN_PERM
,
6950 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6951 NL80211_FLAG_NEED_RTNL
,
6954 .cmd
= NL80211_CMD_ASSOCIATE
,
6955 .doit
= nl80211_associate
,
6956 .policy
= nl80211_policy
,
6957 .flags
= GENL_ADMIN_PERM
,
6958 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6959 NL80211_FLAG_NEED_RTNL
,
6962 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
6963 .doit
= nl80211_deauthenticate
,
6964 .policy
= nl80211_policy
,
6965 .flags
= GENL_ADMIN_PERM
,
6966 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6967 NL80211_FLAG_NEED_RTNL
,
6970 .cmd
= NL80211_CMD_DISASSOCIATE
,
6971 .doit
= nl80211_disassociate
,
6972 .policy
= nl80211_policy
,
6973 .flags
= GENL_ADMIN_PERM
,
6974 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6975 NL80211_FLAG_NEED_RTNL
,
6978 .cmd
= NL80211_CMD_JOIN_IBSS
,
6979 .doit
= nl80211_join_ibss
,
6980 .policy
= nl80211_policy
,
6981 .flags
= GENL_ADMIN_PERM
,
6982 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6983 NL80211_FLAG_NEED_RTNL
,
6986 .cmd
= NL80211_CMD_LEAVE_IBSS
,
6987 .doit
= nl80211_leave_ibss
,
6988 .policy
= nl80211_policy
,
6989 .flags
= GENL_ADMIN_PERM
,
6990 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6991 NL80211_FLAG_NEED_RTNL
,
6993 #ifdef CONFIG_NL80211_TESTMODE
6995 .cmd
= NL80211_CMD_TESTMODE
,
6996 .doit
= nl80211_testmode_do
,
6997 .dumpit
= nl80211_testmode_dump
,
6998 .policy
= nl80211_policy
,
6999 .flags
= GENL_ADMIN_PERM
,
7000 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7001 NL80211_FLAG_NEED_RTNL
,
7005 .cmd
= NL80211_CMD_CONNECT
,
7006 .doit
= nl80211_connect
,
7007 .policy
= nl80211_policy
,
7008 .flags
= GENL_ADMIN_PERM
,
7009 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7010 NL80211_FLAG_NEED_RTNL
,
7013 .cmd
= NL80211_CMD_DISCONNECT
,
7014 .doit
= nl80211_disconnect
,
7015 .policy
= nl80211_policy
,
7016 .flags
= GENL_ADMIN_PERM
,
7017 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7018 NL80211_FLAG_NEED_RTNL
,
7021 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
7022 .doit
= nl80211_wiphy_netns
,
7023 .policy
= nl80211_policy
,
7024 .flags
= GENL_ADMIN_PERM
,
7025 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7026 NL80211_FLAG_NEED_RTNL
,
7029 .cmd
= NL80211_CMD_GET_SURVEY
,
7030 .policy
= nl80211_policy
,
7031 .dumpit
= nl80211_dump_survey
,
7034 .cmd
= NL80211_CMD_SET_PMKSA
,
7035 .doit
= nl80211_setdel_pmksa
,
7036 .policy
= nl80211_policy
,
7037 .flags
= GENL_ADMIN_PERM
,
7038 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7039 NL80211_FLAG_NEED_RTNL
,
7042 .cmd
= NL80211_CMD_DEL_PMKSA
,
7043 .doit
= nl80211_setdel_pmksa
,
7044 .policy
= nl80211_policy
,
7045 .flags
= GENL_ADMIN_PERM
,
7046 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7047 NL80211_FLAG_NEED_RTNL
,
7050 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
7051 .doit
= nl80211_flush_pmksa
,
7052 .policy
= nl80211_policy
,
7053 .flags
= GENL_ADMIN_PERM
,
7054 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7055 NL80211_FLAG_NEED_RTNL
,
7058 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
7059 .doit
= nl80211_remain_on_channel
,
7060 .policy
= nl80211_policy
,
7061 .flags
= GENL_ADMIN_PERM
,
7062 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7063 NL80211_FLAG_NEED_RTNL
,
7066 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7067 .doit
= nl80211_cancel_remain_on_channel
,
7068 .policy
= nl80211_policy
,
7069 .flags
= GENL_ADMIN_PERM
,
7070 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7071 NL80211_FLAG_NEED_RTNL
,
7074 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
7075 .doit
= nl80211_set_tx_bitrate_mask
,
7076 .policy
= nl80211_policy
,
7077 .flags
= GENL_ADMIN_PERM
,
7078 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7079 NL80211_FLAG_NEED_RTNL
,
7082 .cmd
= NL80211_CMD_REGISTER_FRAME
,
7083 .doit
= nl80211_register_mgmt
,
7084 .policy
= nl80211_policy
,
7085 .flags
= GENL_ADMIN_PERM
,
7086 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7087 NL80211_FLAG_NEED_RTNL
,
7090 .cmd
= NL80211_CMD_FRAME
,
7091 .doit
= nl80211_tx_mgmt
,
7092 .policy
= nl80211_policy
,
7093 .flags
= GENL_ADMIN_PERM
,
7094 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7095 NL80211_FLAG_NEED_RTNL
,
7098 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
7099 .doit
= nl80211_tx_mgmt_cancel_wait
,
7100 .policy
= nl80211_policy
,
7101 .flags
= GENL_ADMIN_PERM
,
7102 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7103 NL80211_FLAG_NEED_RTNL
,
7106 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
7107 .doit
= nl80211_set_power_save
,
7108 .policy
= nl80211_policy
,
7109 .flags
= GENL_ADMIN_PERM
,
7110 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7111 NL80211_FLAG_NEED_RTNL
,
7114 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
7115 .doit
= nl80211_get_power_save
,
7116 .policy
= nl80211_policy
,
7117 /* can be retrieved by unprivileged users */
7118 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7119 NL80211_FLAG_NEED_RTNL
,
7122 .cmd
= NL80211_CMD_SET_CQM
,
7123 .doit
= nl80211_set_cqm
,
7124 .policy
= nl80211_policy
,
7125 .flags
= GENL_ADMIN_PERM
,
7126 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7127 NL80211_FLAG_NEED_RTNL
,
7130 .cmd
= NL80211_CMD_SET_CHANNEL
,
7131 .doit
= nl80211_set_channel
,
7132 .policy
= nl80211_policy
,
7133 .flags
= GENL_ADMIN_PERM
,
7134 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7135 NL80211_FLAG_NEED_RTNL
,
7138 .cmd
= NL80211_CMD_SET_WDS_PEER
,
7139 .doit
= nl80211_set_wds_peer
,
7140 .policy
= nl80211_policy
,
7141 .flags
= GENL_ADMIN_PERM
,
7142 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7143 NL80211_FLAG_NEED_RTNL
,
7146 .cmd
= NL80211_CMD_JOIN_MESH
,
7147 .doit
= nl80211_join_mesh
,
7148 .policy
= nl80211_policy
,
7149 .flags
= GENL_ADMIN_PERM
,
7150 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7151 NL80211_FLAG_NEED_RTNL
,
7154 .cmd
= NL80211_CMD_LEAVE_MESH
,
7155 .doit
= nl80211_leave_mesh
,
7156 .policy
= nl80211_policy
,
7157 .flags
= GENL_ADMIN_PERM
,
7158 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7159 NL80211_FLAG_NEED_RTNL
,
7162 .cmd
= NL80211_CMD_GET_WOWLAN
,
7163 .doit
= nl80211_get_wowlan
,
7164 .policy
= nl80211_policy
,
7165 /* can be retrieved by unprivileged users */
7166 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7167 NL80211_FLAG_NEED_RTNL
,
7170 .cmd
= NL80211_CMD_SET_WOWLAN
,
7171 .doit
= nl80211_set_wowlan
,
7172 .policy
= nl80211_policy
,
7173 .flags
= GENL_ADMIN_PERM
,
7174 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7175 NL80211_FLAG_NEED_RTNL
,
7178 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
7179 .doit
= nl80211_set_rekey_data
,
7180 .policy
= nl80211_policy
,
7181 .flags
= GENL_ADMIN_PERM
,
7182 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7183 NL80211_FLAG_NEED_RTNL
,
7186 .cmd
= NL80211_CMD_TDLS_MGMT
,
7187 .doit
= nl80211_tdls_mgmt
,
7188 .policy
= nl80211_policy
,
7189 .flags
= GENL_ADMIN_PERM
,
7190 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7191 NL80211_FLAG_NEED_RTNL
,
7194 .cmd
= NL80211_CMD_TDLS_OPER
,
7195 .doit
= nl80211_tdls_oper
,
7196 .policy
= nl80211_policy
,
7197 .flags
= GENL_ADMIN_PERM
,
7198 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7199 NL80211_FLAG_NEED_RTNL
,
7202 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
7203 .doit
= nl80211_register_unexpected_frame
,
7204 .policy
= nl80211_policy
,
7205 .flags
= GENL_ADMIN_PERM
,
7206 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7207 NL80211_FLAG_NEED_RTNL
,
7210 .cmd
= NL80211_CMD_PROBE_CLIENT
,
7211 .doit
= nl80211_probe_client
,
7212 .policy
= nl80211_policy
,
7213 .flags
= GENL_ADMIN_PERM
,
7214 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7215 NL80211_FLAG_NEED_RTNL
,
7218 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
7219 .doit
= nl80211_register_beacons
,
7220 .policy
= nl80211_policy
,
7221 .flags
= GENL_ADMIN_PERM
,
7222 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7223 NL80211_FLAG_NEED_RTNL
,
7226 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
7227 .doit
= nl80211_set_noack_map
,
7228 .policy
= nl80211_policy
,
7229 .flags
= GENL_ADMIN_PERM
,
7230 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7231 NL80211_FLAG_NEED_RTNL
,
7236 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
7240 /* multicast groups */
7241 static struct genl_multicast_group nl80211_config_mcgrp
= {
7244 static struct genl_multicast_group nl80211_scan_mcgrp
= {
7247 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
7248 .name
= "regulatory",
7251 /* notification functions */
7253 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
7255 struct sk_buff
*msg
;
7257 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7261 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
7266 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7267 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
7270 static int nl80211_add_scan_req(struct sk_buff
*msg
,
7271 struct cfg80211_registered_device
*rdev
)
7273 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
7274 struct nlattr
*nest
;
7277 ASSERT_RDEV_LOCK(rdev
);
7282 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
7284 goto nla_put_failure
;
7285 for (i
= 0; i
< req
->n_ssids
; i
++) {
7286 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
7287 goto nla_put_failure
;
7289 nla_nest_end(msg
, nest
);
7291 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
7293 goto nla_put_failure
;
7294 for (i
= 0; i
< req
->n_channels
; i
++) {
7295 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
7296 goto nla_put_failure
;
7298 nla_nest_end(msg
, nest
);
7301 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
7302 goto nla_put_failure
;
7309 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
7310 struct cfg80211_registered_device
*rdev
,
7311 struct net_device
*netdev
,
7312 u32 pid
, u32 seq
, int flags
,
7317 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
7321 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7322 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7323 goto nla_put_failure
;
7325 /* ignore errors and send incomplete event anyway */
7326 nl80211_add_scan_req(msg
, rdev
);
7328 return genlmsg_end(msg
, hdr
);
7331 genlmsg_cancel(msg
, hdr
);
7336 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
7337 struct cfg80211_registered_device
*rdev
,
7338 struct net_device
*netdev
,
7339 u32 pid
, u32 seq
, int flags
, u32 cmd
)
7343 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
7347 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7348 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7349 goto nla_put_failure
;
7351 return genlmsg_end(msg
, hdr
);
7354 genlmsg_cancel(msg
, hdr
);
7358 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
7359 struct net_device
*netdev
)
7361 struct sk_buff
*msg
;
7363 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7367 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7368 NL80211_CMD_TRIGGER_SCAN
) < 0) {
7373 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7374 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7377 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
7378 struct net_device
*netdev
)
7380 struct sk_buff
*msg
;
7382 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7386 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7387 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
7392 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7393 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7396 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
7397 struct net_device
*netdev
)
7399 struct sk_buff
*msg
;
7401 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7405 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7406 NL80211_CMD_SCAN_ABORTED
) < 0) {
7411 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7412 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7415 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
7416 struct net_device
*netdev
)
7418 struct sk_buff
*msg
;
7420 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7424 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7425 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
7430 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7431 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7434 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
7435 struct net_device
*netdev
, u32 cmd
)
7437 struct sk_buff
*msg
;
7439 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7443 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
7448 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7449 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7453 * This can happen on global regulatory changes or device specific settings
7454 * based on custom world regulatory domains.
7456 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
7458 struct sk_buff
*msg
;
7461 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7465 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
7471 /* Userspace can always count this one always being set */
7472 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
7473 goto nla_put_failure
;
7475 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
7476 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7477 NL80211_REGDOM_TYPE_WORLD
))
7478 goto nla_put_failure
;
7479 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
7480 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7481 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
7482 goto nla_put_failure
;
7483 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
7484 request
->intersect
) {
7485 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7486 NL80211_REGDOM_TYPE_INTERSECTION
))
7487 goto nla_put_failure
;
7489 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7490 NL80211_REGDOM_TYPE_COUNTRY
) ||
7491 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
7493 goto nla_put_failure
;
7496 if (wiphy_idx_valid(request
->wiphy_idx
) &&
7497 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
7498 goto nla_put_failure
;
7500 genlmsg_end(msg
, hdr
);
7503 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7510 genlmsg_cancel(msg
, hdr
);
7514 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
7515 struct net_device
*netdev
,
7516 const u8
*buf
, size_t len
,
7517 enum nl80211_commands cmd
, gfp_t gfp
)
7519 struct sk_buff
*msg
;
7522 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7526 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7532 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7533 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7534 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
7535 goto nla_put_failure
;
7537 genlmsg_end(msg
, hdr
);
7539 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7540 nl80211_mlme_mcgrp
.id
, gfp
);
7544 genlmsg_cancel(msg
, hdr
);
7548 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
7549 struct net_device
*netdev
, const u8
*buf
,
7550 size_t len
, gfp_t gfp
)
7552 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7553 NL80211_CMD_AUTHENTICATE
, gfp
);
7556 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
7557 struct net_device
*netdev
, const u8
*buf
,
7558 size_t len
, gfp_t gfp
)
7560 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7561 NL80211_CMD_ASSOCIATE
, gfp
);
7564 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
7565 struct net_device
*netdev
, const u8
*buf
,
7566 size_t len
, gfp_t gfp
)
7568 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7569 NL80211_CMD_DEAUTHENTICATE
, gfp
);
7572 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
7573 struct net_device
*netdev
, const u8
*buf
,
7574 size_t len
, gfp_t gfp
)
7576 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7577 NL80211_CMD_DISASSOCIATE
, gfp
);
7580 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
7581 struct net_device
*netdev
, const u8
*buf
,
7582 size_t len
, gfp_t gfp
)
7584 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7585 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
7588 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
7589 struct net_device
*netdev
, const u8
*buf
,
7590 size_t len
, gfp_t gfp
)
7592 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7593 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
7596 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
7597 struct net_device
*netdev
, int cmd
,
7598 const u8
*addr
, gfp_t gfp
)
7600 struct sk_buff
*msg
;
7603 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7607 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7613 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7614 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7615 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
7616 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
7617 goto nla_put_failure
;
7619 genlmsg_end(msg
, hdr
);
7621 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7622 nl80211_mlme_mcgrp
.id
, gfp
);
7626 genlmsg_cancel(msg
, hdr
);
7630 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
7631 struct net_device
*netdev
, const u8
*addr
,
7634 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
7638 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
7639 struct net_device
*netdev
, const u8
*addr
,
7642 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
7646 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
7647 struct net_device
*netdev
, const u8
*bssid
,
7648 const u8
*req_ie
, size_t req_ie_len
,
7649 const u8
*resp_ie
, size_t resp_ie_len
,
7650 u16 status
, gfp_t gfp
)
7652 struct sk_buff
*msg
;
7655 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7659 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
7665 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7666 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7667 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
7668 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
7670 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
7672 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
7673 goto nla_put_failure
;
7675 genlmsg_end(msg
, hdr
);
7677 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7678 nl80211_mlme_mcgrp
.id
, gfp
);
7682 genlmsg_cancel(msg
, hdr
);
7687 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
7688 struct net_device
*netdev
, const u8
*bssid
,
7689 const u8
*req_ie
, size_t req_ie_len
,
7690 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
7692 struct sk_buff
*msg
;
7695 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7699 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
7705 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7706 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7707 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
7709 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
7711 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
7712 goto nla_put_failure
;
7714 genlmsg_end(msg
, hdr
);
7716 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7717 nl80211_mlme_mcgrp
.id
, gfp
);
7721 genlmsg_cancel(msg
, hdr
);
7726 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
7727 struct net_device
*netdev
, u16 reason
,
7728 const u8
*ie
, size_t ie_len
, bool from_ap
)
7730 struct sk_buff
*msg
;
7733 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7737 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
7743 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7744 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7745 (from_ap
&& reason
&&
7746 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
7748 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
7749 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
7750 goto nla_put_failure
;
7752 genlmsg_end(msg
, hdr
);
7754 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7755 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
7759 genlmsg_cancel(msg
, hdr
);
7764 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
7765 struct net_device
*netdev
, const u8
*bssid
,
7768 struct sk_buff
*msg
;
7771 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7775 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
7781 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7782 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7783 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
7784 goto nla_put_failure
;
7786 genlmsg_end(msg
, hdr
);
7788 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7789 nl80211_mlme_mcgrp
.id
, gfp
);
7793 genlmsg_cancel(msg
, hdr
);
7797 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
7798 struct net_device
*netdev
,
7799 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
7802 struct sk_buff
*msg
;
7805 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7809 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
7815 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7816 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7817 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
) ||
7819 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
7820 goto nla_put_failure
;
7822 genlmsg_end(msg
, hdr
);
7824 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7825 nl80211_mlme_mcgrp
.id
, gfp
);
7829 genlmsg_cancel(msg
, hdr
);
7833 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
7834 struct net_device
*netdev
, const u8
*addr
,
7835 enum nl80211_key_type key_type
, int key_id
,
7836 const u8
*tsc
, gfp_t gfp
)
7838 struct sk_buff
*msg
;
7841 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7845 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
7851 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7852 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7853 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
7854 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
7856 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
7857 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
7858 goto nla_put_failure
;
7860 genlmsg_end(msg
, hdr
);
7862 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7863 nl80211_mlme_mcgrp
.id
, gfp
);
7867 genlmsg_cancel(msg
, hdr
);
7871 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
7872 struct ieee80211_channel
*channel_before
,
7873 struct ieee80211_channel
*channel_after
)
7875 struct sk_buff
*msg
;
7877 struct nlattr
*nl_freq
;
7879 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
7883 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
7890 * Since we are applying the beacon hint to a wiphy we know its
7891 * wiphy_idx is valid
7893 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
7894 goto nla_put_failure
;
7897 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
7899 goto nla_put_failure
;
7900 if (nl80211_msg_put_channel(msg
, channel_before
))
7901 goto nla_put_failure
;
7902 nla_nest_end(msg
, nl_freq
);
7905 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
7907 goto nla_put_failure
;
7908 if (nl80211_msg_put_channel(msg
, channel_after
))
7909 goto nla_put_failure
;
7910 nla_nest_end(msg
, nl_freq
);
7912 genlmsg_end(msg
, hdr
);
7915 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7922 genlmsg_cancel(msg
, hdr
);
7926 static void nl80211_send_remain_on_chan_event(
7927 int cmd
, struct cfg80211_registered_device
*rdev
,
7928 struct net_device
*netdev
, u64 cookie
,
7929 struct ieee80211_channel
*chan
,
7930 enum nl80211_channel_type channel_type
,
7931 unsigned int duration
, gfp_t gfp
)
7933 struct sk_buff
*msg
;
7936 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7940 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7946 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7947 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7948 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
7949 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
) ||
7950 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7951 goto nla_put_failure
;
7953 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
7954 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
7955 goto nla_put_failure
;
7957 genlmsg_end(msg
, hdr
);
7959 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7960 nl80211_mlme_mcgrp
.id
, gfp
);
7964 genlmsg_cancel(msg
, hdr
);
7968 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
7969 struct net_device
*netdev
, u64 cookie
,
7970 struct ieee80211_channel
*chan
,
7971 enum nl80211_channel_type channel_type
,
7972 unsigned int duration
, gfp_t gfp
)
7974 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
7975 rdev
, netdev
, cookie
, chan
,
7976 channel_type
, duration
, gfp
);
7979 void nl80211_send_remain_on_channel_cancel(
7980 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
7981 u64 cookie
, struct ieee80211_channel
*chan
,
7982 enum nl80211_channel_type channel_type
, gfp_t gfp
)
7984 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7985 rdev
, netdev
, cookie
, chan
,
7986 channel_type
, 0, gfp
);
7989 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
7990 struct net_device
*dev
, const u8
*mac_addr
,
7991 struct station_info
*sinfo
, gfp_t gfp
)
7993 struct sk_buff
*msg
;
7995 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7999 if (nl80211_send_station(msg
, 0, 0, 0,
8000 rdev
, dev
, mac_addr
, sinfo
) < 0) {
8005 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8006 nl80211_mlme_mcgrp
.id
, gfp
);
8009 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
8010 struct net_device
*dev
, const u8
*mac_addr
,
8013 struct sk_buff
*msg
;
8016 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8020 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
8026 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8027 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
8028 goto nla_put_failure
;
8030 genlmsg_end(msg
, hdr
);
8032 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8033 nl80211_mlme_mcgrp
.id
, gfp
);
8037 genlmsg_cancel(msg
, hdr
);
8041 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
8042 const u8
*addr
, gfp_t gfp
)
8044 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8045 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8046 struct sk_buff
*msg
;
8049 u32 nlpid
= ACCESS_ONCE(wdev
->ap_unexpected_nlpid
);
8054 msg
= nlmsg_new(100, gfp
);
8058 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8064 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8065 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8066 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8067 goto nla_put_failure
;
8069 err
= genlmsg_end(msg
, hdr
);
8075 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8079 genlmsg_cancel(msg
, hdr
);
8084 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
8086 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
8090 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
8091 const u8
*addr
, gfp_t gfp
)
8093 return __nl80211_unexpected_frame(dev
,
8094 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
8098 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
8099 struct net_device
*netdev
, u32 nlpid
,
8100 int freq
, int sig_dbm
,
8101 const u8
*buf
, size_t len
, gfp_t gfp
)
8103 struct sk_buff
*msg
;
8106 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8110 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8116 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8117 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8118 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8120 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8121 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8122 goto nla_put_failure
;
8124 genlmsg_end(msg
, hdr
);
8126 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8129 genlmsg_cancel(msg
, hdr
);
8134 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
8135 struct net_device
*netdev
, u64 cookie
,
8136 const u8
*buf
, size_t len
, bool ack
,
8139 struct sk_buff
*msg
;
8142 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8146 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
8152 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8153 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8154 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
8155 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8156 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8157 goto nla_put_failure
;
8159 genlmsg_end(msg
, hdr
);
8161 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
8165 genlmsg_cancel(msg
, hdr
);
8170 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
8171 struct net_device
*netdev
,
8172 enum nl80211_cqm_rssi_threshold_event rssi_event
,
8175 struct sk_buff
*msg
;
8176 struct nlattr
*pinfoattr
;
8179 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8183 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8189 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8190 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8191 goto nla_put_failure
;
8193 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8195 goto nla_put_failure
;
8197 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
8199 goto nla_put_failure
;
8201 nla_nest_end(msg
, pinfoattr
);
8203 genlmsg_end(msg
, hdr
);
8205 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8206 nl80211_mlme_mcgrp
.id
, gfp
);
8210 genlmsg_cancel(msg
, hdr
);
8214 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
8215 struct net_device
*netdev
, const u8
*bssid
,
8216 const u8
*replay_ctr
, gfp_t gfp
)
8218 struct sk_buff
*msg
;
8219 struct nlattr
*rekey_attr
;
8222 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8226 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8232 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8233 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8234 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8235 goto nla_put_failure
;
8237 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8239 goto nla_put_failure
;
8241 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
8242 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
8243 goto nla_put_failure
;
8245 nla_nest_end(msg
, rekey_attr
);
8247 genlmsg_end(msg
, hdr
);
8249 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8250 nl80211_mlme_mcgrp
.id
, gfp
);
8254 genlmsg_cancel(msg
, hdr
);
8258 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
8259 struct net_device
*netdev
, int index
,
8260 const u8
*bssid
, bool preauth
, gfp_t gfp
)
8262 struct sk_buff
*msg
;
8263 struct nlattr
*attr
;
8266 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8270 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
8276 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8277 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8278 goto nla_put_failure
;
8280 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
8282 goto nla_put_failure
;
8284 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
8285 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
8287 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
8288 goto nla_put_failure
;
8290 nla_nest_end(msg
, attr
);
8292 genlmsg_end(msg
, hdr
);
8294 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8295 nl80211_mlme_mcgrp
.id
, gfp
);
8299 genlmsg_cancel(msg
, hdr
);
8303 void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
8304 struct net_device
*netdev
, int freq
,
8305 enum nl80211_channel_type type
, gfp_t gfp
)
8307 struct sk_buff
*msg
;
8310 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8314 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
8320 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8321 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8322 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, type
))
8323 goto nla_put_failure
;
8325 genlmsg_end(msg
, hdr
);
8327 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8328 nl80211_mlme_mcgrp
.id
, gfp
);
8332 genlmsg_cancel(msg
, hdr
);
8337 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
8338 struct net_device
*netdev
, const u8
*peer
,
8339 u32 num_packets
, gfp_t gfp
)
8341 struct sk_buff
*msg
;
8342 struct nlattr
*pinfoattr
;
8345 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8349 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8355 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8356 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8357 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8358 goto nla_put_failure
;
8360 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8362 goto nla_put_failure
;
8364 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
8365 goto nla_put_failure
;
8367 nla_nest_end(msg
, pinfoattr
);
8369 genlmsg_end(msg
, hdr
);
8371 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8372 nl80211_mlme_mcgrp
.id
, gfp
);
8376 genlmsg_cancel(msg
, hdr
);
8380 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
8381 u64 cookie
, bool acked
, gfp_t gfp
)
8383 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8384 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8385 struct sk_buff
*msg
;
8389 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8393 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
8399 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8400 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8401 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8402 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8403 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8404 goto nla_put_failure
;
8406 err
= genlmsg_end(msg
, hdr
);
8412 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8413 nl80211_mlme_mcgrp
.id
, gfp
);
8417 genlmsg_cancel(msg
, hdr
);
8420 EXPORT_SYMBOL(cfg80211_probe_status
);
8422 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
8423 const u8
*frame
, size_t len
,
8424 int freq
, int sig_dbm
, gfp_t gfp
)
8426 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8427 struct sk_buff
*msg
;
8429 u32 nlpid
= ACCESS_ONCE(rdev
->ap_beacons_nlpid
);
8434 msg
= nlmsg_new(len
+ 100, gfp
);
8438 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8444 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8446 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
8448 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8449 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
8450 goto nla_put_failure
;
8452 genlmsg_end(msg
, hdr
);
8454 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
8458 genlmsg_cancel(msg
, hdr
);
8461 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
8463 static int nl80211_netlink_notify(struct notifier_block
* nb
,
8464 unsigned long state
,
8467 struct netlink_notify
*notify
= _notify
;
8468 struct cfg80211_registered_device
*rdev
;
8469 struct wireless_dev
*wdev
;
8471 if (state
!= NETLINK_URELEASE
)
8476 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
8477 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
8478 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
8479 if (rdev
->ap_beacons_nlpid
== notify
->pid
)
8480 rdev
->ap_beacons_nlpid
= 0;
8488 static struct notifier_block nl80211_netlink_notifier
= {
8489 .notifier_call
= nl80211_netlink_notify
,
8492 /* initialisation/exit functions */
8494 int nl80211_init(void)
8498 err
= genl_register_family_with_ops(&nl80211_fam
,
8499 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
8503 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
8507 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
8511 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
8515 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
8519 #ifdef CONFIG_NL80211_TESTMODE
8520 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
8525 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
8531 genl_unregister_family(&nl80211_fam
);
8535 void nl80211_exit(void)
8537 netlink_unregister_notifier(&nl80211_netlink_notifier
);
8538 genl_unregister_family(&nl80211_fam
);