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_info_ifindex(struct genl_info
*info
,
51 struct cfg80211_registered_device
**rdev
,
52 struct net_device
**dev
)
54 struct nlattr
**attrs
= info
->attrs
;
57 if (!attrs
[NL80211_ATTR_IFINDEX
])
60 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
61 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
65 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
68 return PTR_ERR(*rdev
);
74 /* policy for the attributes */
75 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
76 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
77 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
79 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
80 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
81 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
82 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
83 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
84 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
85 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
86 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
88 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
89 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
90 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
92 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
93 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
95 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
96 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
97 .len
= WLAN_MAX_KEY_LEN
},
98 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
99 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
100 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
101 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
102 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
104 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
105 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
106 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
107 .len
= IEEE80211_MAX_DATA_LEN
},
108 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
109 .len
= IEEE80211_MAX_DATA_LEN
},
110 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
111 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
112 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
113 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
114 .len
= NL80211_MAX_SUPP_RATES
},
115 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
116 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
117 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
118 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
119 .len
= IEEE80211_MAX_MESH_ID_LEN
},
120 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
122 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
123 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
125 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
126 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
127 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
128 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
129 .len
= NL80211_MAX_SUPP_RATES
},
130 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
132 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
133 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
135 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
137 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
138 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
139 .len
= IEEE80211_MAX_DATA_LEN
},
140 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
141 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
143 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
144 .len
= IEEE80211_MAX_SSID_LEN
},
145 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
146 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
147 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
148 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
149 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
150 [NL80211_ATTR_STA_FLAGS2
] = {
151 .len
= sizeof(struct nl80211_sta_flag_update
),
153 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
154 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
155 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
156 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
157 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
158 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
159 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
160 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
161 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
162 .len
= WLAN_PMKID_LEN
},
163 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
164 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
165 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
166 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
167 .len
= IEEE80211_MAX_DATA_LEN
},
168 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
169 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
170 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
171 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
172 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
173 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
174 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
175 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
176 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
177 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
178 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
179 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
180 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
181 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
182 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
183 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
184 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
185 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
186 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
187 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
188 .len
= IEEE80211_MAX_DATA_LEN
},
189 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
190 .len
= IEEE80211_MAX_DATA_LEN
},
191 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
192 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
193 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
194 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
195 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
196 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
197 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
198 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
201 /* policy for the key attributes */
202 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
203 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
204 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
205 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
206 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
207 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
208 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
209 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
210 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
213 /* policy for the key default flags */
214 static const struct nla_policy
215 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
216 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
217 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
220 /* policy for WoWLAN attributes */
221 static const struct nla_policy
222 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
223 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
224 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
225 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
226 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
227 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
228 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
229 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
230 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
233 /* policy for GTK rekey offload attributes */
234 static const struct nla_policy
235 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
236 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
237 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
238 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
241 static const struct nla_policy
242 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
243 [NL80211_ATTR_SCHED_SCAN_MATCH_SSID
] = { .type
= NLA_BINARY
,
244 .len
= IEEE80211_MAX_SSID_LEN
},
247 /* ifidx get helper */
248 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
252 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
253 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
258 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
261 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
267 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
268 struct netlink_callback
*cb
,
269 struct cfg80211_registered_device
**rdev
,
270 struct net_device
**dev
)
272 int ifidx
= cb
->args
[0];
276 ifidx
= nl80211_get_ifidx(cb
);
284 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
290 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
292 err
= PTR_ERR(*rdev
);
302 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
304 cfg80211_unlock_rdev(rdev
);
309 static bool is_valid_ie_attr(const struct nlattr
*attr
)
317 pos
= nla_data(attr
);
338 /* message building helper */
339 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
342 /* since there is no private header just add the generic one */
343 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
346 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
347 struct ieee80211_channel
*chan
)
349 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
352 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
353 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
354 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
355 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
356 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
357 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
358 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
359 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
361 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
362 DBM_TO_MBM(chan
->max_power
));
370 /* netlink command implementations */
377 bool def_uni
, def_multi
;
380 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
382 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
383 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
388 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
389 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
398 if (tb
[NL80211_KEY_IDX
])
399 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
401 if (tb
[NL80211_KEY_DATA
]) {
402 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
403 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
406 if (tb
[NL80211_KEY_SEQ
]) {
407 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
408 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
411 if (tb
[NL80211_KEY_CIPHER
])
412 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
414 if (tb
[NL80211_KEY_TYPE
]) {
415 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
416 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
420 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
421 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
422 int err
= nla_parse_nested(kdt
,
423 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
424 tb
[NL80211_KEY_DEFAULT_TYPES
],
425 nl80211_key_default_policy
);
429 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
430 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
436 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
438 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
439 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
440 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
443 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
444 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
445 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
448 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
449 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
451 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
452 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
454 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
455 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
464 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
465 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
466 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
470 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
471 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
472 int err
= nla_parse_nested(
473 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
474 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
475 nl80211_key_default_policy
);
479 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
480 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
486 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
490 memset(k
, 0, sizeof(*k
));
494 if (info
->attrs
[NL80211_ATTR_KEY
])
495 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
497 err
= nl80211_parse_key_old(info
, k
);
502 if (k
->def
&& k
->defmgmt
)
506 if (k
->def_uni
|| !k
->def_multi
)
512 if (k
->idx
< 4 || k
->idx
> 5)
515 if (k
->idx
< 0 || k
->idx
> 3)
518 if (k
->idx
< 0 || k
->idx
> 5)
526 static struct cfg80211_cached_keys
*
527 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
530 struct key_parse parse
;
532 struct cfg80211_cached_keys
*result
;
533 int rem
, err
, def
= 0;
535 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
537 return ERR_PTR(-ENOMEM
);
540 result
->defmgmt
= -1;
542 nla_for_each_nested(key
, keys
, rem
) {
543 memset(&parse
, 0, sizeof(parse
));
546 err
= nl80211_parse_key_new(key
, &parse
);
552 if (parse
.idx
< 0 || parse
.idx
> 4)
558 result
->def
= parse
.idx
;
559 if (!parse
.def_uni
|| !parse
.def_multi
)
561 } else if (parse
.defmgmt
)
563 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
564 parse
.idx
, false, NULL
);
567 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
568 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
569 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
570 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
579 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
581 ASSERT_WDEV_LOCK(wdev
);
583 switch (wdev
->iftype
) {
584 case NL80211_IFTYPE_AP
:
585 case NL80211_IFTYPE_AP_VLAN
:
586 case NL80211_IFTYPE_P2P_GO
:
587 case NL80211_IFTYPE_MESH_POINT
:
589 case NL80211_IFTYPE_ADHOC
:
590 if (!wdev
->current_bss
)
593 case NL80211_IFTYPE_STATION
:
594 case NL80211_IFTYPE_P2P_CLIENT
:
595 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
605 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
607 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
611 goto nla_put_failure
;
616 NLA_PUT_FLAG(msg
, i
);
621 nla_nest_end(msg
, nl_modes
);
628 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
631 struct nlattr
*nl_combis
;
634 nl_combis
= nla_nest_start(msg
,
635 NL80211_ATTR_INTERFACE_COMBINATIONS
);
637 goto nla_put_failure
;
639 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
640 const struct ieee80211_iface_combination
*c
;
641 struct nlattr
*nl_combi
, *nl_limits
;
643 c
= &wiphy
->iface_combinations
[i
];
645 nl_combi
= nla_nest_start(msg
, i
+ 1);
647 goto nla_put_failure
;
649 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
651 goto nla_put_failure
;
653 for (j
= 0; j
< c
->n_limits
; j
++) {
654 struct nlattr
*nl_limit
;
656 nl_limit
= nla_nest_start(msg
, j
+ 1);
658 goto nla_put_failure
;
659 NLA_PUT_U32(msg
, NL80211_IFACE_LIMIT_MAX
,
661 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
663 goto nla_put_failure
;
664 nla_nest_end(msg
, nl_limit
);
667 nla_nest_end(msg
, nl_limits
);
669 if (c
->beacon_int_infra_match
)
671 NL80211_IFACE_COMB_STA_AP_BI_MATCH
);
672 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
673 c
->num_different_channels
);
674 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_MAXNUM
,
677 nla_nest_end(msg
, nl_combi
);
680 nla_nest_end(msg
, nl_combis
);
687 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
688 struct cfg80211_registered_device
*dev
)
691 struct nlattr
*nl_bands
, *nl_band
;
692 struct nlattr
*nl_freqs
, *nl_freq
;
693 struct nlattr
*nl_rates
, *nl_rate
;
694 struct nlattr
*nl_cmds
;
695 enum ieee80211_band band
;
696 struct ieee80211_channel
*chan
;
697 struct ieee80211_rate
*rate
;
699 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
700 dev
->wiphy
.mgmt_stypes
;
702 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
706 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
707 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
709 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
710 cfg80211_rdev_list_generation
);
712 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
713 dev
->wiphy
.retry_short
);
714 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
715 dev
->wiphy
.retry_long
);
716 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
717 dev
->wiphy
.frag_threshold
);
718 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
719 dev
->wiphy
.rts_threshold
);
720 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
721 dev
->wiphy
.coverage_class
);
722 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
723 dev
->wiphy
.max_scan_ssids
);
724 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
725 dev
->wiphy
.max_sched_scan_ssids
);
726 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
727 dev
->wiphy
.max_scan_ie_len
);
728 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
729 dev
->wiphy
.max_sched_scan_ie_len
);
730 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
731 dev
->wiphy
.max_match_sets
);
733 if (dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
)
734 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
);
735 if (dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
)
736 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
);
737 if (dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
)
738 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
);
739 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)
740 NLA_PUT_FLAG(msg
, NL80211_ATTR_ROAM_SUPPORT
);
741 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
)
742 NLA_PUT_FLAG(msg
, NL80211_ATTR_TDLS_SUPPORT
);
743 if (dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
)
744 NLA_PUT_FLAG(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
);
746 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
747 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
748 dev
->wiphy
.cipher_suites
);
750 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
751 dev
->wiphy
.max_num_pmkids
);
753 if (dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
)
754 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
);
756 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
757 dev
->wiphy
.available_antennas_tx
);
758 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
759 dev
->wiphy
.available_antennas_rx
);
761 if ((dev
->wiphy
.available_antennas_tx
||
762 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
763 u32 tx_ant
= 0, rx_ant
= 0;
765 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
767 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
768 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
772 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
773 dev
->wiphy
.interface_modes
))
774 goto nla_put_failure
;
776 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
778 goto nla_put_failure
;
780 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
781 if (!dev
->wiphy
.bands
[band
])
784 nl_band
= nla_nest_start(msg
, band
);
786 goto nla_put_failure
;
789 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
790 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
791 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
792 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
793 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
794 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
795 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
796 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
797 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
798 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
801 /* add frequencies */
802 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
804 goto nla_put_failure
;
806 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
807 nl_freq
= nla_nest_start(msg
, i
);
809 goto nla_put_failure
;
811 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
813 if (nl80211_msg_put_channel(msg
, chan
))
814 goto nla_put_failure
;
816 nla_nest_end(msg
, nl_freq
);
819 nla_nest_end(msg
, nl_freqs
);
822 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
824 goto nla_put_failure
;
826 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
827 nl_rate
= nla_nest_start(msg
, i
);
829 goto nla_put_failure
;
831 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
832 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
834 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
836 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
838 nla_nest_end(msg
, nl_rate
);
841 nla_nest_end(msg
, nl_rates
);
843 nla_nest_end(msg
, nl_band
);
845 nla_nest_end(msg
, nl_bands
);
847 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
849 goto nla_put_failure
;
854 if (dev->ops->op) { \
856 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
860 CMD(add_virtual_intf
, NEW_INTERFACE
);
861 CMD(change_virtual_intf
, SET_INTERFACE
);
862 CMD(add_key
, NEW_KEY
);
863 CMD(add_beacon
, NEW_BEACON
);
864 CMD(add_station
, NEW_STATION
);
865 CMD(add_mpath
, NEW_MPATH
);
866 CMD(update_mesh_config
, SET_MESH_CONFIG
);
867 CMD(change_bss
, SET_BSS
);
868 CMD(auth
, AUTHENTICATE
);
869 CMD(assoc
, ASSOCIATE
);
870 CMD(deauth
, DEAUTHENTICATE
);
871 CMD(disassoc
, DISASSOCIATE
);
872 CMD(join_ibss
, JOIN_IBSS
);
873 CMD(join_mesh
, JOIN_MESH
);
874 CMD(set_pmksa
, SET_PMKSA
);
875 CMD(del_pmksa
, DEL_PMKSA
);
876 CMD(flush_pmksa
, FLUSH_PMKSA
);
877 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
878 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
880 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
881 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
883 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
885 CMD(set_channel
, SET_CHANNEL
);
886 CMD(set_wds_peer
, SET_WDS_PEER
);
887 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
888 CMD(tdls_mgmt
, TDLS_MGMT
);
889 CMD(tdls_oper
, TDLS_OPER
);
891 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
892 CMD(sched_scan_start
, START_SCHED_SCAN
);
896 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
898 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
901 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
903 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
906 nla_nest_end(msg
, nl_cmds
);
908 if (dev
->ops
->remain_on_channel
)
909 NLA_PUT_U32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
910 dev
->wiphy
.max_remain_on_channel_duration
);
912 if (dev
->ops
->mgmt_tx_cancel_wait
)
913 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
917 struct nlattr
*nl_ftypes
, *nl_ifs
;
918 enum nl80211_iftype ift
;
920 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
922 goto nla_put_failure
;
924 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
925 nl_ftypes
= nla_nest_start(msg
, ift
);
927 goto nla_put_failure
;
929 stypes
= mgmt_stypes
[ift
].tx
;
932 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
933 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
937 nla_nest_end(msg
, nl_ftypes
);
940 nla_nest_end(msg
, nl_ifs
);
942 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
944 goto nla_put_failure
;
946 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
947 nl_ftypes
= nla_nest_start(msg
, ift
);
949 goto nla_put_failure
;
951 stypes
= mgmt_stypes
[ift
].rx
;
954 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
955 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
959 nla_nest_end(msg
, nl_ftypes
);
961 nla_nest_end(msg
, nl_ifs
);
964 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
965 struct nlattr
*nl_wowlan
;
967 nl_wowlan
= nla_nest_start(msg
,
968 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
970 goto nla_put_failure
;
972 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
)
973 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
974 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
)
975 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
976 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
)
977 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
978 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
)
979 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
);
980 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
)
981 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
982 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
)
983 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
984 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
)
985 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
986 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
)
987 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
988 if (dev
->wiphy
.wowlan
.n_patterns
) {
989 struct nl80211_wowlan_pattern_support pat
= {
990 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
992 dev
->wiphy
.wowlan
.pattern_min_len
,
994 dev
->wiphy
.wowlan
.pattern_max_len
,
996 NLA_PUT(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1000 nla_nest_end(msg
, nl_wowlan
);
1003 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1004 dev
->wiphy
.software_iftypes
))
1005 goto nla_put_failure
;
1007 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1008 goto nla_put_failure
;
1010 return genlmsg_end(msg
, hdr
);
1013 genlmsg_cancel(msg
, hdr
);
1017 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1020 int start
= cb
->args
[0];
1021 struct cfg80211_registered_device
*dev
;
1023 mutex_lock(&cfg80211_mutex
);
1024 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1025 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1029 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
1030 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1036 mutex_unlock(&cfg80211_mutex
);
1043 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1045 struct sk_buff
*msg
;
1046 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1048 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1052 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
1057 return genlmsg_reply(msg
, info
);
1060 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1061 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1062 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1063 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1064 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1065 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1068 static int parse_txq_params(struct nlattr
*tb
[],
1069 struct ieee80211_txq_params
*txq_params
)
1071 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1072 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1073 !tb
[NL80211_TXQ_ATTR_AIFS
])
1076 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
1077 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1078 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1079 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1080 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1085 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1088 * You can only set the channel explicitly for AP, mesh
1089 * and WDS type interfaces; all others have their channel
1090 * managed via their respective "establish a connection"
1091 * command (connect, join, ...)
1093 * Monitors are special as they are normally slaved to
1094 * whatever else is going on, so they behave as though
1095 * you tried setting the wiphy channel itself.
1098 wdev
->iftype
== NL80211_IFTYPE_AP
||
1099 wdev
->iftype
== NL80211_IFTYPE_WDS
||
1100 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1101 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1102 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1105 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1106 struct wireless_dev
*wdev
,
1107 struct genl_info
*info
)
1109 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1113 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1116 if (!nl80211_can_set_dev_channel(wdev
))
1119 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1120 channel_type
= nla_get_u32(info
->attrs
[
1121 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1122 if (channel_type
!= NL80211_CHAN_NO_HT
&&
1123 channel_type
!= NL80211_CHAN_HT20
&&
1124 channel_type
!= NL80211_CHAN_HT40PLUS
&&
1125 channel_type
!= NL80211_CHAN_HT40MINUS
)
1129 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1131 mutex_lock(&rdev
->devlist_mtx
);
1134 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
1137 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
1139 mutex_unlock(&rdev
->devlist_mtx
);
1144 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1146 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1147 struct net_device
*netdev
= info
->user_ptr
[1];
1149 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1152 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1154 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1155 struct net_device
*dev
= info
->user_ptr
[1];
1156 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1159 if (!info
->attrs
[NL80211_ATTR_MAC
])
1162 if (netif_running(dev
))
1165 if (!rdev
->ops
->set_wds_peer
)
1168 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1171 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1172 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1176 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1178 struct cfg80211_registered_device
*rdev
;
1179 struct net_device
*netdev
= NULL
;
1180 struct wireless_dev
*wdev
;
1181 int result
= 0, rem_txq_params
= 0;
1182 struct nlattr
*nl_txq_params
;
1184 u8 retry_short
= 0, retry_long
= 0;
1185 u32 frag_threshold
= 0, rts_threshold
= 0;
1186 u8 coverage_class
= 0;
1189 * Try to find the wiphy and netdev. Normally this
1190 * function shouldn't need the netdev, but this is
1191 * done for backward compatibility -- previously
1192 * setting the channel was done per wiphy, but now
1193 * it is per netdev. Previous userland like hostapd
1194 * also passed a netdev to set_wiphy, so that it is
1195 * possible to let that go to the right netdev!
1197 mutex_lock(&cfg80211_mutex
);
1199 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1200 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1202 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1203 if (netdev
&& netdev
->ieee80211_ptr
) {
1204 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1205 mutex_lock(&rdev
->mtx
);
1211 rdev
= __cfg80211_rdev_from_info(info
);
1213 mutex_unlock(&cfg80211_mutex
);
1214 return PTR_ERR(rdev
);
1220 mutex_lock(&rdev
->mtx
);
1221 } else if (netif_running(netdev
) &&
1222 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1223 wdev
= netdev
->ieee80211_ptr
;
1228 * end workaround code, by now the rdev is available
1229 * and locked, and wdev may or may not be NULL.
1232 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1233 result
= cfg80211_dev_rename(
1234 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1236 mutex_unlock(&cfg80211_mutex
);
1241 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1242 struct ieee80211_txq_params txq_params
;
1243 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1245 if (!rdev
->ops
->set_txq_params
) {
1246 result
= -EOPNOTSUPP
;
1255 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1256 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1261 nla_for_each_nested(nl_txq_params
,
1262 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1264 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1265 nla_data(nl_txq_params
),
1266 nla_len(nl_txq_params
),
1268 result
= parse_txq_params(tb
, &txq_params
);
1272 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1280 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1281 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1286 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1287 enum nl80211_tx_power_setting type
;
1290 if (!rdev
->ops
->set_tx_power
) {
1291 result
= -EOPNOTSUPP
;
1295 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1296 type
= nla_get_u32(info
->attrs
[idx
]);
1298 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1299 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1304 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1305 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1306 mbm
= nla_get_u32(info
->attrs
[idx
]);
1309 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1314 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1315 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1317 if ((!rdev
->wiphy
.available_antennas_tx
&&
1318 !rdev
->wiphy
.available_antennas_rx
) ||
1319 !rdev
->ops
->set_antenna
) {
1320 result
= -EOPNOTSUPP
;
1324 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1325 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1327 /* reject antenna configurations which don't match the
1328 * available antenna masks, except for the "all" mask */
1329 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1330 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1335 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1336 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1338 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1345 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1346 retry_short
= nla_get_u8(
1347 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1348 if (retry_short
== 0) {
1352 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1355 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1356 retry_long
= nla_get_u8(
1357 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1358 if (retry_long
== 0) {
1362 changed
|= WIPHY_PARAM_RETRY_LONG
;
1365 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1366 frag_threshold
= nla_get_u32(
1367 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1368 if (frag_threshold
< 256) {
1372 if (frag_threshold
!= (u32
) -1) {
1374 * Fragments (apart from the last one) are required to
1375 * have even length. Make the fragmentation code
1376 * simpler by stripping LSB should someone try to use
1377 * odd threshold value.
1379 frag_threshold
&= ~0x1;
1381 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1384 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1385 rts_threshold
= nla_get_u32(
1386 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1387 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1390 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1391 coverage_class
= nla_get_u8(
1392 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1393 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1397 u8 old_retry_short
, old_retry_long
;
1398 u32 old_frag_threshold
, old_rts_threshold
;
1399 u8 old_coverage_class
;
1401 if (!rdev
->ops
->set_wiphy_params
) {
1402 result
= -EOPNOTSUPP
;
1406 old_retry_short
= rdev
->wiphy
.retry_short
;
1407 old_retry_long
= rdev
->wiphy
.retry_long
;
1408 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1409 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1410 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1412 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1413 rdev
->wiphy
.retry_short
= retry_short
;
1414 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1415 rdev
->wiphy
.retry_long
= retry_long
;
1416 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1417 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1418 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1419 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1420 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1421 rdev
->wiphy
.coverage_class
= coverage_class
;
1423 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1425 rdev
->wiphy
.retry_short
= old_retry_short
;
1426 rdev
->wiphy
.retry_long
= old_retry_long
;
1427 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1428 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1429 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1434 mutex_unlock(&rdev
->mtx
);
1441 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1442 struct cfg80211_registered_device
*rdev
,
1443 struct net_device
*dev
)
1447 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1451 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1452 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1453 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1454 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1456 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1457 rdev
->devlist_generation
^
1458 (cfg80211_rdev_list_generation
<< 2));
1460 return genlmsg_end(msg
, hdr
);
1463 genlmsg_cancel(msg
, hdr
);
1467 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1471 int wp_start
= cb
->args
[0];
1472 int if_start
= cb
->args
[1];
1473 struct cfg80211_registered_device
*rdev
;
1474 struct wireless_dev
*wdev
;
1476 mutex_lock(&cfg80211_mutex
);
1477 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1478 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1480 if (wp_idx
< wp_start
) {
1486 mutex_lock(&rdev
->devlist_mtx
);
1487 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1488 if (if_idx
< if_start
) {
1492 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1493 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1494 rdev
, wdev
->netdev
) < 0) {
1495 mutex_unlock(&rdev
->devlist_mtx
);
1500 mutex_unlock(&rdev
->devlist_mtx
);
1505 mutex_unlock(&cfg80211_mutex
);
1507 cb
->args
[0] = wp_idx
;
1508 cb
->args
[1] = if_idx
;
1513 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1515 struct sk_buff
*msg
;
1516 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1517 struct net_device
*netdev
= info
->user_ptr
[1];
1519 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1523 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1529 return genlmsg_reply(msg
, info
);
1532 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1533 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1534 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1535 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1536 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1537 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1540 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1542 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1550 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1551 nla
, mntr_flags_policy
))
1554 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1556 *mntrflags
|= (1<<flag
);
1561 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1562 struct net_device
*netdev
, u8 use_4addr
,
1563 enum nl80211_iftype iftype
)
1566 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1572 case NL80211_IFTYPE_AP_VLAN
:
1573 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1576 case NL80211_IFTYPE_STATION
:
1577 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1587 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1589 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1590 struct vif_params params
;
1592 enum nl80211_iftype otype
, ntype
;
1593 struct net_device
*dev
= info
->user_ptr
[1];
1594 u32 _flags
, *flags
= NULL
;
1595 bool change
= false;
1597 memset(¶ms
, 0, sizeof(params
));
1599 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1601 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1602 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1605 if (ntype
> NL80211_IFTYPE_MAX
)
1609 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1610 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1612 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1614 if (netif_running(dev
))
1618 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1619 IEEE80211_MAX_MESH_ID_LEN
);
1620 wdev
->mesh_id_up_len
=
1621 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1622 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1623 wdev
->mesh_id_up_len
);
1627 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1628 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1630 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1634 params
.use_4addr
= -1;
1637 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1638 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1640 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1650 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1654 if (!err
&& params
.use_4addr
!= -1)
1655 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1660 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1662 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1663 struct vif_params params
;
1664 struct net_device
*dev
;
1666 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1669 memset(¶ms
, 0, sizeof(params
));
1671 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1674 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1675 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1676 if (type
> NL80211_IFTYPE_MAX
)
1680 if (!rdev
->ops
->add_virtual_intf
||
1681 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1684 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1685 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1686 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1691 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1692 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1694 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1695 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1696 type
, err
? NULL
: &flags
, ¶ms
);
1698 return PTR_ERR(dev
);
1700 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1701 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1702 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1705 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1706 IEEE80211_MAX_MESH_ID_LEN
);
1707 wdev
->mesh_id_up_len
=
1708 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1709 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1710 wdev
->mesh_id_up_len
);
1717 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1719 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1720 struct net_device
*dev
= info
->user_ptr
[1];
1722 if (!rdev
->ops
->del_virtual_intf
)
1725 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1728 struct get_key_cookie
{
1729 struct sk_buff
*msg
;
1734 static void get_key_callback(void *c
, struct key_params
*params
)
1737 struct get_key_cookie
*cookie
= c
;
1740 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1741 params
->key_len
, params
->key
);
1744 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1745 params
->seq_len
, params
->seq
);
1748 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1751 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1753 goto nla_put_failure
;
1756 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1757 params
->key_len
, params
->key
);
1760 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1761 params
->seq_len
, params
->seq
);
1764 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1767 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1769 nla_nest_end(cookie
->msg
, key
);
1776 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1778 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1780 struct net_device
*dev
= info
->user_ptr
[1];
1782 const u8
*mac_addr
= NULL
;
1784 struct get_key_cookie cookie
= {
1788 struct sk_buff
*msg
;
1790 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1791 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1796 if (info
->attrs
[NL80211_ATTR_MAC
])
1797 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1799 pairwise
= !!mac_addr
;
1800 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1801 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1802 if (kt
>= NUM_NL80211_KEYTYPES
)
1804 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1805 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1807 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1810 if (!rdev
->ops
->get_key
)
1813 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1817 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1818 NL80211_CMD_NEW_KEY
);
1820 return PTR_ERR(hdr
);
1823 cookie
.idx
= key_idx
;
1825 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1826 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1828 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1830 if (pairwise
&& mac_addr
&&
1831 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1834 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1835 mac_addr
, &cookie
, get_key_callback
);
1841 goto nla_put_failure
;
1843 genlmsg_end(msg
, hdr
);
1844 return genlmsg_reply(msg
, info
);
1853 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1855 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1856 struct key_parse key
;
1858 struct net_device
*dev
= info
->user_ptr
[1];
1860 err
= nl80211_parse_key(info
, &key
);
1867 /* only support setting default key */
1868 if (!key
.def
&& !key
.defmgmt
)
1871 wdev_lock(dev
->ieee80211_ptr
);
1874 if (!rdev
->ops
->set_default_key
) {
1879 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1883 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1884 key
.def_uni
, key
.def_multi
);
1889 #ifdef CONFIG_CFG80211_WEXT
1890 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1893 if (key
.def_uni
|| !key
.def_multi
) {
1898 if (!rdev
->ops
->set_default_mgmt_key
) {
1903 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1907 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1912 #ifdef CONFIG_CFG80211_WEXT
1913 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1918 wdev_unlock(dev
->ieee80211_ptr
);
1923 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1925 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1927 struct net_device
*dev
= info
->user_ptr
[1];
1928 struct key_parse key
;
1929 const u8
*mac_addr
= NULL
;
1931 err
= nl80211_parse_key(info
, &key
);
1938 if (info
->attrs
[NL80211_ATTR_MAC
])
1939 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1941 if (key
.type
== -1) {
1943 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1945 key
.type
= NL80211_KEYTYPE_GROUP
;
1949 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1950 key
.type
!= NL80211_KEYTYPE_GROUP
)
1953 if (!rdev
->ops
->add_key
)
1956 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
1957 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1961 wdev_lock(dev
->ieee80211_ptr
);
1962 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1964 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1965 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1967 wdev_unlock(dev
->ieee80211_ptr
);
1972 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1974 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1976 struct net_device
*dev
= info
->user_ptr
[1];
1977 u8
*mac_addr
= NULL
;
1978 struct key_parse key
;
1980 err
= nl80211_parse_key(info
, &key
);
1984 if (info
->attrs
[NL80211_ATTR_MAC
])
1985 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1987 if (key
.type
== -1) {
1989 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1991 key
.type
= NL80211_KEYTYPE_GROUP
;
1995 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1996 key
.type
!= NL80211_KEYTYPE_GROUP
)
1999 if (!rdev
->ops
->del_key
)
2002 wdev_lock(dev
->ieee80211_ptr
);
2003 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2005 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2006 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2010 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
2011 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2014 #ifdef CONFIG_CFG80211_WEXT
2016 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2017 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2018 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2019 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2022 wdev_unlock(dev
->ieee80211_ptr
);
2027 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2029 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
2030 struct beacon_parameters
*info
);
2031 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2032 struct net_device
*dev
= info
->user_ptr
[1];
2033 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2034 struct beacon_parameters params
;
2035 int haveinfo
= 0, err
;
2037 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2038 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2039 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2040 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2043 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2044 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2047 memset(¶ms
, 0, sizeof(params
));
2049 switch (info
->genlhdr
->cmd
) {
2050 case NL80211_CMD_NEW_BEACON
:
2051 /* these are required for NEW_BEACON */
2052 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2053 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2054 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2058 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2059 params
.dtim_period
=
2060 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2062 err
= cfg80211_validate_beacon_int(rdev
, params
.interval
);
2067 * In theory, some of these attributes could be required for
2068 * NEW_BEACON, but since they were not used when the command was
2069 * originally added, keep them optional for old user space
2070 * programs to work with drivers that do not need the additional
2073 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2074 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2076 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2077 if (params
.ssid_len
== 0 ||
2078 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2082 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2083 params
.hidden_ssid
= nla_get_u32(
2084 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2085 if (params
.hidden_ssid
!=
2086 NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2087 params
.hidden_ssid
!=
2088 NL80211_HIDDEN_SSID_ZERO_LEN
&&
2089 params
.hidden_ssid
!=
2090 NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2094 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2096 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2097 params
.auth_type
= nla_get_u32(
2098 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2099 if (!nl80211_valid_auth_type(params
.auth_type
))
2102 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2104 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2105 NL80211_MAX_NR_CIPHER_SUITES
);
2109 call
= rdev
->ops
->add_beacon
;
2111 case NL80211_CMD_SET_BEACON
:
2112 call
= rdev
->ops
->set_beacon
;
2122 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2123 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2125 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2129 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2130 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2132 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2139 if (info
->attrs
[NL80211_ATTR_IE
]) {
2140 params
.beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2141 params
.beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2144 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2145 params
.proberesp_ies
=
2146 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2147 params
.proberesp_ies_len
=
2148 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2151 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2152 params
.assocresp_ies
=
2153 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2154 params
.assocresp_ies_len
=
2155 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2158 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
2159 if (!err
&& params
.interval
)
2160 wdev
->beacon_interval
= params
.interval
;
2164 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2166 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2167 struct net_device
*dev
= info
->user_ptr
[1];
2168 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2171 if (!rdev
->ops
->del_beacon
)
2174 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2175 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2178 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
2180 wdev
->beacon_interval
= 0;
2184 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2185 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2186 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2187 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2188 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2189 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2192 static int parse_station_flags(struct genl_info
*info
,
2193 struct station_parameters
*params
)
2195 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2200 * Try parsing the new attribute first so userspace
2201 * can specify both for older kernels.
2203 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2205 struct nl80211_sta_flag_update
*sta_flags
;
2207 sta_flags
= nla_data(nla
);
2208 params
->sta_flags_mask
= sta_flags
->mask
;
2209 params
->sta_flags_set
= sta_flags
->set
;
2210 if ((params
->sta_flags_mask
|
2211 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2216 /* if present, parse the old attribute */
2218 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2222 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2223 nla
, sta_flags_policy
))
2226 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
2227 params
->sta_flags_mask
&= ~1;
2229 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
2231 params
->sta_flags_set
|= (1<<flag
);
2236 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2239 struct nlattr
*rate
;
2242 rate
= nla_nest_start(msg
, attr
);
2244 goto nla_put_failure
;
2246 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2247 bitrate
= cfg80211_calculate_bitrate(info
);
2249 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
2251 if (info
->flags
& RATE_INFO_FLAGS_MCS
)
2252 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
);
2253 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
2254 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
2255 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
2256 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
2258 nla_nest_end(msg
, rate
);
2265 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2266 int flags
, struct net_device
*dev
,
2267 const u8
*mac_addr
, struct station_info
*sinfo
)
2270 struct nlattr
*sinfoattr
, *bss_param
;
2272 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2276 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2277 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
2279 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
2281 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2283 goto nla_put_failure
;
2284 if (sinfo
->filled
& STATION_INFO_CONNECTED_TIME
)
2285 NLA_PUT_U32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2286 sinfo
->connected_time
);
2287 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
2288 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2289 sinfo
->inactive_time
);
2290 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
2291 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
2293 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
2294 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2296 if (sinfo
->filled
& STATION_INFO_LLID
)
2297 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2299 if (sinfo
->filled
& STATION_INFO_PLID
)
2300 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2302 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2303 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2304 sinfo
->plink_state
);
2305 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2306 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2308 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2309 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2311 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2312 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2313 NL80211_STA_INFO_TX_BITRATE
))
2314 goto nla_put_failure
;
2316 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2317 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2318 NL80211_STA_INFO_RX_BITRATE
))
2319 goto nla_put_failure
;
2321 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2322 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2324 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2325 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2327 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2328 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2330 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2331 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2333 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2334 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2336 goto nla_put_failure
;
2338 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
)
2339 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
);
2340 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
)
2341 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
);
2342 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
)
2344 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
);
2345 NLA_PUT_U8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2346 sinfo
->bss_param
.dtim_period
);
2347 NLA_PUT_U16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2348 sinfo
->bss_param
.beacon_interval
);
2350 nla_nest_end(msg
, bss_param
);
2352 if (sinfo
->filled
& STATION_INFO_STA_FLAGS
)
2353 NLA_PUT(msg
, NL80211_STA_INFO_STA_FLAGS
,
2354 sizeof(struct nl80211_sta_flag_update
),
2356 nla_nest_end(msg
, sinfoattr
);
2358 if (sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
)
2359 NLA_PUT(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2360 sinfo
->assoc_req_ies
);
2362 return genlmsg_end(msg
, hdr
);
2365 genlmsg_cancel(msg
, hdr
);
2369 static int nl80211_dump_station(struct sk_buff
*skb
,
2370 struct netlink_callback
*cb
)
2372 struct station_info sinfo
;
2373 struct cfg80211_registered_device
*dev
;
2374 struct net_device
*netdev
;
2375 u8 mac_addr
[ETH_ALEN
];
2376 int sta_idx
= cb
->args
[1];
2379 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2383 if (!dev
->ops
->dump_station
) {
2389 memset(&sinfo
, 0, sizeof(sinfo
));
2390 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2397 if (nl80211_send_station(skb
,
2398 NETLINK_CB(cb
->skb
).pid
,
2399 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2409 cb
->args
[1] = sta_idx
;
2412 nl80211_finish_netdev_dump(dev
);
2417 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2419 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2420 struct net_device
*dev
= info
->user_ptr
[1];
2421 struct station_info sinfo
;
2422 struct sk_buff
*msg
;
2423 u8
*mac_addr
= NULL
;
2426 memset(&sinfo
, 0, sizeof(sinfo
));
2428 if (!info
->attrs
[NL80211_ATTR_MAC
])
2431 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2433 if (!rdev
->ops
->get_station
)
2436 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2440 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2444 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2445 dev
, mac_addr
, &sinfo
) < 0) {
2450 return genlmsg_reply(msg
, info
);
2454 * Get vlan interface making sure it is running and on the right wiphy.
2456 static int get_vlan(struct genl_info
*info
,
2457 struct cfg80211_registered_device
*rdev
,
2458 struct net_device
**vlan
)
2460 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2464 *vlan
= dev_get_by_index(genl_info_net(info
),
2465 nla_get_u32(vlanattr
));
2468 if (!(*vlan
)->ieee80211_ptr
)
2470 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2472 if (!netif_running(*vlan
))
2478 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2480 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2482 struct net_device
*dev
= info
->user_ptr
[1];
2483 struct station_parameters params
;
2484 u8
*mac_addr
= NULL
;
2486 memset(¶ms
, 0, sizeof(params
));
2488 params
.listen_interval
= -1;
2489 params
.plink_state
= -1;
2491 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2494 if (!info
->attrs
[NL80211_ATTR_MAC
])
2497 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2499 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2500 params
.supported_rates
=
2501 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2502 params
.supported_rates_len
=
2503 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2506 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2507 params
.listen_interval
=
2508 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2510 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2512 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2514 if (parse_station_flags(info
, ¶ms
))
2517 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2518 params
.plink_action
=
2519 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2521 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2522 params
.plink_state
=
2523 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2525 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2529 /* validate settings */
2532 switch (dev
->ieee80211_ptr
->iftype
) {
2533 case NL80211_IFTYPE_AP
:
2534 case NL80211_IFTYPE_AP_VLAN
:
2535 case NL80211_IFTYPE_P2P_GO
:
2536 /* disallow mesh-specific things */
2537 if (params
.plink_action
)
2540 case NL80211_IFTYPE_P2P_CLIENT
:
2541 case NL80211_IFTYPE_STATION
:
2542 /* disallow things sta doesn't support */
2543 if (params
.plink_action
)
2547 if (params
.supported_rates
&&
2548 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
2552 if (params
.listen_interval
>= 0)
2554 if (params
.sta_flags_mask
&
2555 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2556 BIT(NL80211_STA_FLAG_TDLS_PEER
)))
2558 /* can't change the TDLS bit */
2559 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
2560 (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
2563 case NL80211_IFTYPE_MESH_POINT
:
2564 /* disallow things mesh doesn't support */
2569 if (params
.listen_interval
>= 0)
2571 if (params
.sta_flags_mask
&
2572 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2573 BIT(NL80211_STA_FLAG_MFP
) |
2574 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
2584 if (!rdev
->ops
->change_station
) {
2589 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2593 dev_put(params
.vlan
);
2598 static struct nla_policy
2599 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
2600 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
2601 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
2604 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2606 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2608 struct net_device
*dev
= info
->user_ptr
[1];
2609 struct station_parameters params
;
2610 u8
*mac_addr
= NULL
;
2612 memset(¶ms
, 0, sizeof(params
));
2614 if (!info
->attrs
[NL80211_ATTR_MAC
])
2617 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2620 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2623 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2626 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2627 params
.supported_rates
=
2628 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2629 params
.supported_rates_len
=
2630 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2631 params
.listen_interval
=
2632 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2634 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2635 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2638 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2640 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2642 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2643 params
.plink_action
=
2644 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2646 if (parse_station_flags(info
, ¶ms
))
2649 /* parse WME attributes if sta is WME capable */
2650 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
2651 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
2652 info
->attrs
[NL80211_ATTR_STA_WME
]) {
2653 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
2656 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
2657 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
2658 nl80211_sta_wme_policy
);
2662 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
2663 params
.uapsd_queues
=
2664 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
2665 if (params
.uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
2668 if (tb
[NL80211_STA_WME_MAX_SP
])
2670 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
2672 if (params
.max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
2675 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
2678 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2679 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2680 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2681 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
2682 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
)
2686 * Only managed stations can add TDLS peers, and only when the
2687 * wiphy supports external TDLS setup.
2689 if (dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_STATION
&&
2690 !((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
2691 (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
2692 (rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
)))
2695 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2699 /* validate settings */
2702 if (!rdev
->ops
->add_station
) {
2707 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2711 dev_put(params
.vlan
);
2715 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2717 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2718 struct net_device
*dev
= info
->user_ptr
[1];
2719 u8
*mac_addr
= NULL
;
2721 if (info
->attrs
[NL80211_ATTR_MAC
])
2722 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2724 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2725 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2726 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2727 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2730 if (!rdev
->ops
->del_station
)
2733 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2736 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2737 int flags
, struct net_device
*dev
,
2738 u8
*dst
, u8
*next_hop
,
2739 struct mpath_info
*pinfo
)
2742 struct nlattr
*pinfoattr
;
2744 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2748 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2749 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2750 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2752 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2754 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2756 goto nla_put_failure
;
2757 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2758 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2760 if (pinfo
->filled
& MPATH_INFO_SN
)
2761 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2763 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2764 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2766 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2767 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2769 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2770 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2772 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2773 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2774 pinfo
->discovery_timeout
);
2775 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2776 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2777 pinfo
->discovery_retries
);
2779 nla_nest_end(msg
, pinfoattr
);
2781 return genlmsg_end(msg
, hdr
);
2784 genlmsg_cancel(msg
, hdr
);
2788 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2789 struct netlink_callback
*cb
)
2791 struct mpath_info pinfo
;
2792 struct cfg80211_registered_device
*dev
;
2793 struct net_device
*netdev
;
2795 u8 next_hop
[ETH_ALEN
];
2796 int path_idx
= cb
->args
[1];
2799 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2803 if (!dev
->ops
->dump_mpath
) {
2808 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2814 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2815 dst
, next_hop
, &pinfo
);
2821 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2822 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2823 netdev
, dst
, next_hop
,
2832 cb
->args
[1] = path_idx
;
2835 nl80211_finish_netdev_dump(dev
);
2839 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2841 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2843 struct net_device
*dev
= info
->user_ptr
[1];
2844 struct mpath_info pinfo
;
2845 struct sk_buff
*msg
;
2847 u8 next_hop
[ETH_ALEN
];
2849 memset(&pinfo
, 0, sizeof(pinfo
));
2851 if (!info
->attrs
[NL80211_ATTR_MAC
])
2854 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2856 if (!rdev
->ops
->get_mpath
)
2859 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2862 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2866 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2870 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2871 dev
, dst
, next_hop
, &pinfo
) < 0) {
2876 return genlmsg_reply(msg
, info
);
2879 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2881 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2882 struct net_device
*dev
= info
->user_ptr
[1];
2884 u8
*next_hop
= NULL
;
2886 if (!info
->attrs
[NL80211_ATTR_MAC
])
2889 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2892 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2893 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2895 if (!rdev
->ops
->change_mpath
)
2898 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2901 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2904 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2906 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2907 struct net_device
*dev
= info
->user_ptr
[1];
2909 u8
*next_hop
= NULL
;
2911 if (!info
->attrs
[NL80211_ATTR_MAC
])
2914 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2917 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2918 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2920 if (!rdev
->ops
->add_mpath
)
2923 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2926 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2929 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2931 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2932 struct net_device
*dev
= info
->user_ptr
[1];
2935 if (info
->attrs
[NL80211_ATTR_MAC
])
2936 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2938 if (!rdev
->ops
->del_mpath
)
2941 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2944 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2946 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2947 struct net_device
*dev
= info
->user_ptr
[1];
2948 struct bss_parameters params
;
2950 memset(¶ms
, 0, sizeof(params
));
2951 /* default to not changing parameters */
2952 params
.use_cts_prot
= -1;
2953 params
.use_short_preamble
= -1;
2954 params
.use_short_slot_time
= -1;
2955 params
.ap_isolate
= -1;
2956 params
.ht_opmode
= -1;
2958 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2959 params
.use_cts_prot
=
2960 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2961 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2962 params
.use_short_preamble
=
2963 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2964 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2965 params
.use_short_slot_time
=
2966 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2967 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2968 params
.basic_rates
=
2969 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2970 params
.basic_rates_len
=
2971 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2973 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2974 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2975 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
2977 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
2979 if (!rdev
->ops
->change_bss
)
2982 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2983 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2986 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2989 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2990 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2991 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2992 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2993 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2994 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2995 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2998 static int parse_reg_rule(struct nlattr
*tb
[],
2999 struct ieee80211_reg_rule
*reg_rule
)
3001 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3002 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3004 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3006 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3008 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3010 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3012 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3015 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3017 freq_range
->start_freq_khz
=
3018 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3019 freq_range
->end_freq_khz
=
3020 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3021 freq_range
->max_bandwidth_khz
=
3022 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3024 power_rule
->max_eirp
=
3025 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3027 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3028 power_rule
->max_antenna_gain
=
3029 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3034 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3040 * You should only get this when cfg80211 hasn't yet initialized
3041 * completely when built-in to the kernel right between the time
3042 * window between nl80211_init() and regulatory_init(), if that is
3045 mutex_lock(&cfg80211_mutex
);
3046 if (unlikely(!cfg80211_regdomain
)) {
3047 mutex_unlock(&cfg80211_mutex
);
3048 return -EINPROGRESS
;
3050 mutex_unlock(&cfg80211_mutex
);
3052 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3055 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3057 r
= regulatory_hint_user(data
);
3062 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3063 struct genl_info
*info
)
3065 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3066 struct net_device
*dev
= info
->user_ptr
[1];
3067 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3068 struct mesh_config cur_params
;
3071 struct nlattr
*pinfoattr
;
3072 struct sk_buff
*msg
;
3074 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3077 if (!rdev
->ops
->get_mesh_config
)
3081 /* If not connected, get default parameters */
3082 if (!wdev
->mesh_id_len
)
3083 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3085 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3092 /* Draw up a netlink message to send back */
3093 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3096 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3097 NL80211_CMD_GET_MESH_CONFIG
);
3100 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3102 goto nla_put_failure
;
3103 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3104 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3105 cur_params
.dot11MeshRetryTimeout
);
3106 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3107 cur_params
.dot11MeshConfirmTimeout
);
3108 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3109 cur_params
.dot11MeshHoldingTimeout
);
3110 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3111 cur_params
.dot11MeshMaxPeerLinks
);
3112 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3113 cur_params
.dot11MeshMaxRetries
);
3114 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
3115 cur_params
.dot11MeshTTL
);
3116 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3117 cur_params
.element_ttl
);
3118 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3119 cur_params
.auto_open_plinks
);
3120 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3121 cur_params
.dot11MeshHWMPmaxPREQretries
);
3122 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3123 cur_params
.path_refresh_time
);
3124 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3125 cur_params
.min_discovery_timeout
);
3126 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3127 cur_params
.dot11MeshHWMPactivePathTimeout
);
3128 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3129 cur_params
.dot11MeshHWMPpreqMinInterval
);
3130 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3131 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
3132 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3133 cur_params
.dot11MeshHWMPRootMode
);
3134 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3135 cur_params
.dot11MeshHWMPRannInterval
);
3136 NLA_PUT_U8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3137 cur_params
.dot11MeshGateAnnouncementProtocol
);
3138 nla_nest_end(msg
, pinfoattr
);
3139 genlmsg_end(msg
, hdr
);
3140 return genlmsg_reply(msg
, info
);
3143 genlmsg_cancel(msg
, hdr
);
3149 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3150 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3151 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3152 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3153 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3154 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3155 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3156 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3157 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3159 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3160 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3161 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3162 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3163 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3164 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3165 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3166 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3167 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3170 static const struct nla_policy
3171 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3172 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3173 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3174 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3175 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3176 .len
= IEEE80211_MAX_DATA_LEN
},
3177 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3180 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3181 struct mesh_config
*cfg
,
3184 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3187 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3189 if (table[attr_num]) {\
3190 cfg->param = nla_fn(table[attr_num]); \
3191 mask |= (1 << (attr_num - 1)); \
3196 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3198 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3199 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3200 nl80211_meshconf_params_policy
))
3203 /* This makes sure that there aren't more than 32 mesh config
3204 * parameters (otherwise our bitfield scheme would not work.) */
3205 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3207 /* Fill in the params struct */
3208 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3209 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
3210 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3211 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
3212 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3213 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
3214 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3215 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
3216 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3217 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
3218 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3219 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3220 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3221 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
3222 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3223 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
3224 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3225 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3227 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3228 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
3229 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3230 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3232 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
3233 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3235 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3236 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3238 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3239 dot11MeshHWMPnetDiameterTraversalTime
,
3240 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3242 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3243 dot11MeshHWMPRootMode
, mask
,
3244 NL80211_MESHCONF_HWMP_ROOTMODE
,
3246 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3247 dot11MeshHWMPRannInterval
, mask
,
3248 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3250 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3251 dot11MeshGateAnnouncementProtocol
, mask
,
3252 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3259 #undef FILL_IN_MESH_PARAM_IF_SET
3262 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3263 struct mesh_setup
*setup
)
3265 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3267 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3269 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3270 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3271 nl80211_mesh_setup_params_policy
))
3274 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3275 setup
->path_sel_proto
=
3276 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3277 IEEE80211_PATH_PROTOCOL_VENDOR
:
3278 IEEE80211_PATH_PROTOCOL_HWMP
;
3280 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3281 setup
->path_metric
=
3282 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3283 IEEE80211_PATH_METRIC_VENDOR
:
3284 IEEE80211_PATH_METRIC_AIRTIME
;
3287 if (tb
[NL80211_MESH_SETUP_IE
]) {
3288 struct nlattr
*ieattr
=
3289 tb
[NL80211_MESH_SETUP_IE
];
3290 if (!is_valid_ie_attr(ieattr
))
3292 setup
->ie
= nla_data(ieattr
);
3293 setup
->ie_len
= nla_len(ieattr
);
3295 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3296 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3301 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3302 struct genl_info
*info
)
3304 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3305 struct net_device
*dev
= info
->user_ptr
[1];
3306 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3307 struct mesh_config cfg
;
3311 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3314 if (!rdev
->ops
->update_mesh_config
)
3317 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3322 if (!wdev
->mesh_id_len
)
3326 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3334 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3336 struct sk_buff
*msg
;
3338 struct nlattr
*nl_reg_rules
;
3342 mutex_lock(&cfg80211_mutex
);
3344 if (!cfg80211_regdomain
)
3347 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3353 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3354 NL80211_CMD_GET_REG
);
3358 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
3359 cfg80211_regdomain
->alpha2
);
3361 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3363 goto nla_put_failure
;
3365 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3366 struct nlattr
*nl_reg_rule
;
3367 const struct ieee80211_reg_rule
*reg_rule
;
3368 const struct ieee80211_freq_range
*freq_range
;
3369 const struct ieee80211_power_rule
*power_rule
;
3371 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3372 freq_range
= ®_rule
->freq_range
;
3373 power_rule
= ®_rule
->power_rule
;
3375 nl_reg_rule
= nla_nest_start(msg
, i
);
3377 goto nla_put_failure
;
3379 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3381 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3382 freq_range
->start_freq_khz
);
3383 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3384 freq_range
->end_freq_khz
);
3385 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3386 freq_range
->max_bandwidth_khz
);
3387 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3388 power_rule
->max_antenna_gain
);
3389 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3390 power_rule
->max_eirp
);
3392 nla_nest_end(msg
, nl_reg_rule
);
3395 nla_nest_end(msg
, nl_reg_rules
);
3397 genlmsg_end(msg
, hdr
);
3398 err
= genlmsg_reply(msg
, info
);
3402 genlmsg_cancel(msg
, hdr
);
3407 mutex_unlock(&cfg80211_mutex
);
3411 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3413 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3414 struct nlattr
*nl_reg_rule
;
3415 char *alpha2
= NULL
;
3416 int rem_reg_rules
= 0, r
= 0;
3417 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3418 struct ieee80211_regdomain
*rd
= NULL
;
3420 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3423 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3426 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3428 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3431 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3435 mutex_lock(&cfg80211_mutex
);
3437 if (!reg_is_valid_request(alpha2
)) {
3442 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3443 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3445 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3451 rd
->n_reg_rules
= num_rules
;
3452 rd
->alpha2
[0] = alpha2
[0];
3453 rd
->alpha2
[1] = alpha2
[1];
3455 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3457 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3458 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3460 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3466 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3472 BUG_ON(rule_idx
!= num_rules
);
3476 mutex_unlock(&cfg80211_mutex
);
3481 mutex_unlock(&cfg80211_mutex
);
3486 static int validate_scan_freqs(struct nlattr
*freqs
)
3488 struct nlattr
*attr1
, *attr2
;
3489 int n_channels
= 0, tmp1
, tmp2
;
3491 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3494 * Some hardware has a limited channel list for
3495 * scanning, and it is pretty much nonsensical
3496 * to scan for a channel twice, so disallow that
3497 * and don't require drivers to check that the
3498 * channel list they get isn't longer than what
3499 * they can scan, as long as they can scan all
3500 * the channels they registered at once.
3502 nla_for_each_nested(attr2
, freqs
, tmp2
)
3503 if (attr1
!= attr2
&&
3504 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3511 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3513 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3514 struct net_device
*dev
= info
->user_ptr
[1];
3515 struct cfg80211_scan_request
*request
;
3516 struct nlattr
*attr
;
3517 struct wiphy
*wiphy
;
3518 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3521 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3524 wiphy
= &rdev
->wiphy
;
3526 if (!rdev
->ops
->scan
)
3532 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3533 n_channels
= validate_scan_freqs(
3534 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3538 enum ieee80211_band band
;
3541 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3542 if (wiphy
->bands
[band
])
3543 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3546 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3547 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3550 if (n_ssids
> wiphy
->max_scan_ssids
)
3553 if (info
->attrs
[NL80211_ATTR_IE
])
3554 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3558 if (ie_len
> wiphy
->max_scan_ie_len
)
3561 request
= kzalloc(sizeof(*request
)
3562 + sizeof(*request
->ssids
) * n_ssids
3563 + sizeof(*request
->channels
) * n_channels
3564 + ie_len
, GFP_KERNEL
);
3569 request
->ssids
= (void *)&request
->channels
[n_channels
];
3570 request
->n_ssids
= n_ssids
;
3573 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3575 request
->ie
= (void *)(request
->channels
+ n_channels
);
3579 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3580 /* user specified, bail out if channel not found */
3581 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3582 struct ieee80211_channel
*chan
;
3584 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3591 /* ignore disabled channels */
3592 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3595 request
->channels
[i
] = chan
;
3599 enum ieee80211_band band
;
3602 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3604 if (!wiphy
->bands
[band
])
3606 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3607 struct ieee80211_channel
*chan
;
3609 chan
= &wiphy
->bands
[band
]->channels
[j
];
3611 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3614 request
->channels
[i
] = chan
;
3625 request
->n_channels
= i
;
3628 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3629 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3630 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3634 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3635 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3640 if (info
->attrs
[NL80211_ATTR_IE
]) {
3641 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3642 memcpy((void *)request
->ie
,
3643 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3647 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
3648 if (wiphy
->bands
[i
])
3650 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
3652 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
3653 nla_for_each_nested(attr
,
3654 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
3656 enum ieee80211_band band
= nla_type(attr
);
3658 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
3662 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
3665 &request
->rates
[band
]);
3672 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
3675 request
->wiphy
= &rdev
->wiphy
;
3677 rdev
->scan_req
= request
;
3678 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3681 nl80211_send_scan_start(rdev
, dev
);
3685 rdev
->scan_req
= NULL
;
3692 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
3693 struct genl_info
*info
)
3695 struct cfg80211_sched_scan_request
*request
;
3696 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3697 struct net_device
*dev
= info
->user_ptr
[1];
3698 struct nlattr
*attr
;
3699 struct wiphy
*wiphy
;
3700 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
3702 enum ieee80211_band band
;
3704 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
3706 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3707 !rdev
->ops
->sched_scan_start
)
3710 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3713 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
3716 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
3720 wiphy
= &rdev
->wiphy
;
3722 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3723 n_channels
= validate_scan_freqs(
3724 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3730 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3731 if (wiphy
->bands
[band
])
3732 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3735 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3736 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3740 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
3743 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
3744 nla_for_each_nested(attr
,
3745 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
3749 if (n_match_sets
> wiphy
->max_match_sets
)
3752 if (info
->attrs
[NL80211_ATTR_IE
])
3753 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3757 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
3760 mutex_lock(&rdev
->sched_scan_mtx
);
3762 if (rdev
->sched_scan_req
) {
3767 request
= kzalloc(sizeof(*request
)
3768 + sizeof(*request
->ssids
) * n_ssids
3769 + sizeof(*request
->match_sets
) * n_match_sets
3770 + sizeof(*request
->channels
) * n_channels
3771 + ie_len
, GFP_KERNEL
);
3778 request
->ssids
= (void *)&request
->channels
[n_channels
];
3779 request
->n_ssids
= n_ssids
;
3782 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3784 request
->ie
= (void *)(request
->channels
+ n_channels
);
3789 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
3790 else if (request
->ssids
)
3791 request
->match_sets
=
3792 (void *)(request
->ssids
+ n_ssids
);
3794 request
->match_sets
=
3795 (void *)(request
->channels
+ n_channels
);
3797 request
->n_match_sets
= n_match_sets
;
3800 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3801 /* user specified, bail out if channel not found */
3802 nla_for_each_nested(attr
,
3803 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
3805 struct ieee80211_channel
*chan
;
3807 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3814 /* ignore disabled channels */
3815 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3818 request
->channels
[i
] = chan
;
3823 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3825 if (!wiphy
->bands
[band
])
3827 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3828 struct ieee80211_channel
*chan
;
3830 chan
= &wiphy
->bands
[band
]->channels
[j
];
3832 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3835 request
->channels
[i
] = chan
;
3846 request
->n_channels
= i
;
3849 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3850 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3852 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3856 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3857 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
3864 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
3865 nla_for_each_nested(attr
,
3866 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
3868 struct nlattr
*ssid
;
3870 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
3871 nla_data(attr
), nla_len(attr
),
3872 nl80211_match_policy
);
3873 ssid
= tb
[NL80211_ATTR_SCHED_SCAN_MATCH_SSID
];
3875 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
3879 memcpy(request
->match_sets
[i
].ssid
.ssid
,
3880 nla_data(ssid
), nla_len(ssid
));
3881 request
->match_sets
[i
].ssid
.ssid_len
=
3888 if (info
->attrs
[NL80211_ATTR_IE
]) {
3889 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3890 memcpy((void *)request
->ie
,
3891 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3896 request
->wiphy
= &rdev
->wiphy
;
3897 request
->interval
= interval
;
3899 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
3901 rdev
->sched_scan_req
= request
;
3902 nl80211_send_sched_scan(rdev
, dev
,
3903 NL80211_CMD_START_SCHED_SCAN
);
3910 mutex_unlock(&rdev
->sched_scan_mtx
);
3914 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
3915 struct genl_info
*info
)
3917 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3920 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3921 !rdev
->ops
->sched_scan_stop
)
3924 mutex_lock(&rdev
->sched_scan_mtx
);
3925 err
= __cfg80211_stop_sched_scan(rdev
, false);
3926 mutex_unlock(&rdev
->sched_scan_mtx
);
3931 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
3933 struct cfg80211_registered_device
*rdev
,
3934 struct wireless_dev
*wdev
,
3935 struct cfg80211_internal_bss
*intbss
)
3937 struct cfg80211_bss
*res
= &intbss
->pub
;
3942 ASSERT_WDEV_LOCK(wdev
);
3944 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).pid
, seq
, flags
,
3945 NL80211_CMD_NEW_SCAN_RESULTS
);
3949 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
3951 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3952 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3954 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3956 goto nla_put_failure
;
3957 if (!is_zero_ether_addr(res
->bssid
))
3958 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3959 if (res
->information_elements
&& res
->len_information_elements
)
3960 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3961 res
->len_information_elements
,
3962 res
->information_elements
);
3963 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3964 res
->beacon_ies
!= res
->information_elements
)
3965 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3966 res
->len_beacon_ies
, res
->beacon_ies
);
3968 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3969 if (res
->beacon_interval
)
3970 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3971 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3972 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3973 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3974 jiffies_to_msecs(jiffies
- intbss
->ts
));
3976 switch (rdev
->wiphy
.signal_type
) {
3977 case CFG80211_SIGNAL_TYPE_MBM
:
3978 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3980 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3981 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3987 switch (wdev
->iftype
) {
3988 case NL80211_IFTYPE_P2P_CLIENT
:
3989 case NL80211_IFTYPE_STATION
:
3990 if (intbss
== wdev
->current_bss
)
3991 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3992 NL80211_BSS_STATUS_ASSOCIATED
);
3993 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3994 if (intbss
!= wdev
->auth_bsses
[i
])
3996 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3997 NL80211_BSS_STATUS_AUTHENTICATED
);
4001 case NL80211_IFTYPE_ADHOC
:
4002 if (intbss
== wdev
->current_bss
)
4003 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
4004 NL80211_BSS_STATUS_IBSS_JOINED
);
4010 nla_nest_end(msg
, bss
);
4012 return genlmsg_end(msg
, hdr
);
4015 genlmsg_cancel(msg
, hdr
);
4019 static int nl80211_dump_scan(struct sk_buff
*skb
,
4020 struct netlink_callback
*cb
)
4022 struct cfg80211_registered_device
*rdev
;
4023 struct net_device
*dev
;
4024 struct cfg80211_internal_bss
*scan
;
4025 struct wireless_dev
*wdev
;
4026 int start
= cb
->args
[1], idx
= 0;
4029 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4033 wdev
= dev
->ieee80211_ptr
;
4036 spin_lock_bh(&rdev
->bss_lock
);
4037 cfg80211_bss_expire(rdev
);
4039 cb
->seq
= rdev
->bss_generation
;
4041 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4044 if (nl80211_send_bss(skb
, cb
,
4045 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4046 rdev
, wdev
, scan
) < 0) {
4052 spin_unlock_bh(&rdev
->bss_lock
);
4056 nl80211_finish_netdev_dump(rdev
);
4061 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
4062 int flags
, struct net_device
*dev
,
4063 struct survey_info
*survey
)
4066 struct nlattr
*infoattr
;
4068 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
4069 NL80211_CMD_NEW_SURVEY_RESULTS
);
4073 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
4075 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4077 goto nla_put_failure
;
4079 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4080 survey
->channel
->center_freq
);
4081 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
4082 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
4084 if (survey
->filled
& SURVEY_INFO_IN_USE
)
4085 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
4086 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
4087 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4088 survey
->channel_time
);
4089 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
4090 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4091 survey
->channel_time_busy
);
4092 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
4093 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4094 survey
->channel_time_ext_busy
);
4095 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
4096 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4097 survey
->channel_time_rx
);
4098 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
4099 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4100 survey
->channel_time_tx
);
4102 nla_nest_end(msg
, infoattr
);
4104 return genlmsg_end(msg
, hdr
);
4107 genlmsg_cancel(msg
, hdr
);
4111 static int nl80211_dump_survey(struct sk_buff
*skb
,
4112 struct netlink_callback
*cb
)
4114 struct survey_info survey
;
4115 struct cfg80211_registered_device
*dev
;
4116 struct net_device
*netdev
;
4117 int survey_idx
= cb
->args
[1];
4120 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4124 if (!dev
->ops
->dump_survey
) {
4130 struct ieee80211_channel
*chan
;
4132 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4139 /* Survey without a channel doesn't make sense */
4140 if (!survey
.channel
) {
4145 chan
= ieee80211_get_channel(&dev
->wiphy
,
4146 survey
.channel
->center_freq
);
4147 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4152 if (nl80211_send_survey(skb
,
4153 NETLINK_CB(cb
->skb
).pid
,
4154 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4162 cb
->args
[1] = survey_idx
;
4165 nl80211_finish_netdev_dump(dev
);
4169 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
4171 return auth_type
<= NL80211_AUTHTYPE_MAX
;
4174 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4176 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4177 NL80211_WPA_VERSION_2
));
4180 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4182 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4183 struct net_device
*dev
= info
->user_ptr
[1];
4184 struct ieee80211_channel
*chan
;
4185 const u8
*bssid
, *ssid
, *ie
= NULL
;
4186 int err
, ssid_len
, ie_len
= 0;
4187 enum nl80211_auth_type auth_type
;
4188 struct key_parse key
;
4189 bool local_state_change
;
4191 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4194 if (!info
->attrs
[NL80211_ATTR_MAC
])
4197 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4200 if (!info
->attrs
[NL80211_ATTR_SSID
])
4203 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4206 err
= nl80211_parse_key(info
, &key
);
4211 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4213 if (!key
.p
.key
|| !key
.p
.key_len
)
4215 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4216 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4217 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4218 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4230 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4231 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4240 if (!rdev
->ops
->auth
)
4243 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4244 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4247 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4248 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4249 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4250 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4253 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4254 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4256 if (info
->attrs
[NL80211_ATTR_IE
]) {
4257 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4258 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4261 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4262 if (!nl80211_valid_auth_type(auth_type
))
4265 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4267 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4268 ssid
, ssid_len
, ie
, ie_len
,
4269 key
.p
.key
, key
.p
.key_len
, key
.idx
,
4270 local_state_change
);
4273 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
4274 struct genl_info
*info
,
4275 struct cfg80211_crypto_settings
*settings
,
4278 memset(settings
, 0, sizeof(*settings
));
4280 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
4282 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
4284 proto
= nla_get_u16(
4285 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
4286 settings
->control_port_ethertype
= cpu_to_be16(proto
);
4287 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
4290 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4291 settings
->control_port_no_encrypt
= true;
4293 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4295 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4299 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4300 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4301 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4303 if (len
% sizeof(u32
))
4306 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4309 memcpy(settings
->ciphers_pairwise
, data
, len
);
4311 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4312 if (!cfg80211_supported_cipher_suite(
4314 settings
->ciphers_pairwise
[i
]))
4318 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4319 settings
->cipher_group
=
4320 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4321 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
4322 settings
->cipher_group
))
4326 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4327 settings
->wpa_versions
=
4328 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4329 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4333 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4337 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4338 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4339 settings
->n_akm_suites
= len
/ sizeof(u32
);
4341 if (len
% sizeof(u32
))
4344 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4347 memcpy(settings
->akm_suites
, data
, len
);
4353 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4355 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4356 struct net_device
*dev
= info
->user_ptr
[1];
4357 struct cfg80211_crypto_settings crypto
;
4358 struct ieee80211_channel
*chan
;
4359 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4360 int err
, ssid_len
, ie_len
= 0;
4361 bool use_mfp
= false;
4363 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4366 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4367 !info
->attrs
[NL80211_ATTR_SSID
] ||
4368 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4371 if (!rdev
->ops
->assoc
)
4374 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4375 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4378 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4380 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4381 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4382 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4385 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4386 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4388 if (info
->attrs
[NL80211_ATTR_IE
]) {
4389 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4390 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4393 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4394 enum nl80211_mfp mfp
=
4395 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4396 if (mfp
== NL80211_MFP_REQUIRED
)
4398 else if (mfp
!= NL80211_MFP_NO
)
4402 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4403 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4405 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4407 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4408 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4414 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4416 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4417 struct net_device
*dev
= info
->user_ptr
[1];
4418 const u8
*ie
= NULL
, *bssid
;
4421 bool local_state_change
;
4423 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4426 if (!info
->attrs
[NL80211_ATTR_MAC
])
4429 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4432 if (!rdev
->ops
->deauth
)
4435 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4436 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4439 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4441 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4442 if (reason_code
== 0) {
4443 /* Reason Code 0 is reserved */
4447 if (info
->attrs
[NL80211_ATTR_IE
]) {
4448 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4449 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4452 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4454 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4455 local_state_change
);
4458 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
4460 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4461 struct net_device
*dev
= info
->user_ptr
[1];
4462 const u8
*ie
= NULL
, *bssid
;
4465 bool local_state_change
;
4467 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4470 if (!info
->attrs
[NL80211_ATTR_MAC
])
4473 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4476 if (!rdev
->ops
->disassoc
)
4479 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4480 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4483 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4485 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4486 if (reason_code
== 0) {
4487 /* Reason Code 0 is reserved */
4491 if (info
->attrs
[NL80211_ATTR_IE
]) {
4492 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4493 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4496 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4498 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4499 local_state_change
);
4503 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
4504 int mcast_rate
[IEEE80211_NUM_BANDS
],
4507 struct wiphy
*wiphy
= &rdev
->wiphy
;
4511 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4512 struct ieee80211_supported_band
*sband
;
4514 sband
= wiphy
->bands
[band
];
4518 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
4519 if (sband
->bitrates
[i
].bitrate
== rateval
) {
4520 mcast_rate
[band
] = i
+ 1;
4530 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4532 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4533 struct net_device
*dev
= info
->user_ptr
[1];
4534 struct cfg80211_ibss_params ibss
;
4535 struct wiphy
*wiphy
;
4536 struct cfg80211_cached_keys
*connkeys
= NULL
;
4539 memset(&ibss
, 0, sizeof(ibss
));
4541 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4544 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4545 !info
->attrs
[NL80211_ATTR_SSID
] ||
4546 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4549 ibss
.beacon_interval
= 100;
4551 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
4552 ibss
.beacon_interval
=
4553 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4554 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
4558 if (!rdev
->ops
->join_ibss
)
4561 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4564 wiphy
= &rdev
->wiphy
;
4566 if (info
->attrs
[NL80211_ATTR_MAC
]) {
4567 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4569 if (!is_valid_ether_addr(ibss
.bssid
))
4572 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4573 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4575 if (info
->attrs
[NL80211_ATTR_IE
]) {
4576 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4577 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4580 ibss
.channel
= ieee80211_get_channel(wiphy
,
4581 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4582 if (!ibss
.channel
||
4583 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
4584 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4587 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
4588 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4590 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4592 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4594 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4595 struct ieee80211_supported_band
*sband
=
4596 wiphy
->bands
[ibss
.channel
->band
];
4599 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
4605 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
4606 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
4607 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
4610 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4611 connkeys
= nl80211_parse_connkeys(rdev
,
4612 info
->attrs
[NL80211_ATTR_KEYS
]);
4613 if (IS_ERR(connkeys
))
4614 return PTR_ERR(connkeys
);
4617 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4623 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4625 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4626 struct net_device
*dev
= info
->user_ptr
[1];
4628 if (!rdev
->ops
->leave_ibss
)
4631 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4634 return cfg80211_leave_ibss(rdev
, dev
, false);
4637 #ifdef CONFIG_NL80211_TESTMODE
4638 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4642 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4644 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4647 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4651 if (rdev
->ops
->testmode_cmd
) {
4652 rdev
->testmode_info
= info
;
4653 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4654 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4655 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4656 rdev
->testmode_info
= NULL
;
4662 static int nl80211_testmode_dump(struct sk_buff
*skb
,
4663 struct netlink_callback
*cb
)
4665 struct cfg80211_registered_device
*dev
;
4673 * 0 is a valid index, but not valid for args[0],
4674 * so we need to offset by 1.
4676 phy_idx
= cb
->args
[0] - 1;
4678 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
4679 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
4683 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
])
4685 phy_idx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
]);
4686 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
4688 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
4692 data
= nla_data((void *)cb
->args
[1]);
4693 data_len
= nla_len((void *)cb
->args
[1]);
4696 mutex_lock(&cfg80211_mutex
);
4697 dev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
4699 mutex_unlock(&cfg80211_mutex
);
4702 cfg80211_lock_rdev(dev
);
4703 mutex_unlock(&cfg80211_mutex
);
4705 if (!dev
->ops
->testmode_dump
) {
4711 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).pid
,
4712 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4713 NL80211_CMD_TESTMODE
);
4714 struct nlattr
*tmdata
;
4716 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) < 0) {
4717 genlmsg_cancel(skb
, hdr
);
4721 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4723 genlmsg_cancel(skb
, hdr
);
4726 err
= dev
->ops
->testmode_dump(&dev
->wiphy
, skb
, cb
,
4728 nla_nest_end(skb
, tmdata
);
4730 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
4731 genlmsg_cancel(skb
, hdr
);
4734 genlmsg_cancel(skb
, hdr
);
4738 genlmsg_end(skb
, hdr
);
4743 cb
->args
[0] = phy_idx
+ 1;
4745 cfg80211_unlock_rdev(dev
);
4749 static struct sk_buff
*
4750 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4751 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4753 struct sk_buff
*skb
;
4755 struct nlattr
*data
;
4757 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4761 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4767 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4768 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4770 ((void **)skb
->cb
)[0] = rdev
;
4771 ((void **)skb
->cb
)[1] = hdr
;
4772 ((void **)skb
->cb
)[2] = data
;
4781 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4784 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4786 if (WARN_ON(!rdev
->testmode_info
))
4789 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4790 rdev
->testmode_info
->snd_pid
,
4791 rdev
->testmode_info
->snd_seq
,
4794 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4796 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4798 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4799 void *hdr
= ((void **)skb
->cb
)[1];
4800 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4802 if (WARN_ON(!rdev
->testmode_info
)) {
4807 nla_nest_end(skb
, data
);
4808 genlmsg_end(skb
, hdr
);
4809 return genlmsg_reply(skb
, rdev
->testmode_info
);
4811 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4813 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4814 int approxlen
, gfp_t gfp
)
4816 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4818 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4820 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4822 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4824 void *hdr
= ((void **)skb
->cb
)[1];
4825 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4827 nla_nest_end(skb
, data
);
4828 genlmsg_end(skb
, hdr
);
4829 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4831 EXPORT_SYMBOL(cfg80211_testmode_event
);
4834 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4836 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4837 struct net_device
*dev
= info
->user_ptr
[1];
4838 struct cfg80211_connect_params connect
;
4839 struct wiphy
*wiphy
;
4840 struct cfg80211_cached_keys
*connkeys
= NULL
;
4843 memset(&connect
, 0, sizeof(connect
));
4845 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4848 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4849 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4852 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4854 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4855 if (!nl80211_valid_auth_type(connect
.auth_type
))
4858 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4860 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4862 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
4863 NL80211_MAX_NR_CIPHER_SUITES
);
4867 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4868 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4871 wiphy
= &rdev
->wiphy
;
4873 if (info
->attrs
[NL80211_ATTR_MAC
])
4874 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4875 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4876 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4878 if (info
->attrs
[NL80211_ATTR_IE
]) {
4879 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4880 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4883 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4885 ieee80211_get_channel(wiphy
,
4886 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4887 if (!connect
.channel
||
4888 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4892 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4893 connkeys
= nl80211_parse_connkeys(rdev
,
4894 info
->attrs
[NL80211_ATTR_KEYS
]);
4895 if (IS_ERR(connkeys
))
4896 return PTR_ERR(connkeys
);
4899 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4905 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4907 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4908 struct net_device
*dev
= info
->user_ptr
[1];
4911 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4912 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4914 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4919 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4920 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4923 return cfg80211_disconnect(rdev
, dev
, reason
, true);
4926 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4928 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4933 if (!info
->attrs
[NL80211_ATTR_PID
])
4936 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4938 net
= get_net_ns_by_pid(pid
);
4940 return PTR_ERR(net
);
4944 /* check if anything to do */
4945 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
4946 err
= cfg80211_switch_netns(rdev
, net
);
4952 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4954 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4955 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4956 struct cfg80211_pmksa
*pmksa
) = NULL
;
4957 struct net_device
*dev
= info
->user_ptr
[1];
4958 struct cfg80211_pmksa pmksa
;
4960 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4962 if (!info
->attrs
[NL80211_ATTR_MAC
])
4965 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4968 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4969 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4971 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4972 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4975 switch (info
->genlhdr
->cmd
) {
4976 case NL80211_CMD_SET_PMKSA
:
4977 rdev_ops
= rdev
->ops
->set_pmksa
;
4979 case NL80211_CMD_DEL_PMKSA
:
4980 rdev_ops
= rdev
->ops
->del_pmksa
;
4990 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4993 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4995 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4996 struct net_device
*dev
= info
->user_ptr
[1];
4998 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4999 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5002 if (!rdev
->ops
->flush_pmksa
)
5005 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
5008 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5010 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5011 struct net_device
*dev
= info
->user_ptr
[1];
5012 u8 action_code
, dialog_token
;
5016 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5017 !rdev
->ops
->tdls_mgmt
)
5020 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5021 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5022 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5023 !info
->attrs
[NL80211_ATTR_IE
] ||
5024 !info
->attrs
[NL80211_ATTR_MAC
])
5027 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5028 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5029 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5030 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5032 return rdev
->ops
->tdls_mgmt(&rdev
->wiphy
, dev
, peer
, action_code
,
5033 dialog_token
, status_code
,
5034 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5035 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5038 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5040 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5041 struct net_device
*dev
= info
->user_ptr
[1];
5042 enum nl80211_tdls_operation operation
;
5045 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5046 !rdev
->ops
->tdls_oper
)
5049 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5050 !info
->attrs
[NL80211_ATTR_MAC
])
5053 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5054 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5056 return rdev
->ops
->tdls_oper(&rdev
->wiphy
, dev
, peer
, operation
);
5059 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5060 struct genl_info
*info
)
5062 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5063 struct net_device
*dev
= info
->user_ptr
[1];
5064 struct ieee80211_channel
*chan
;
5065 struct sk_buff
*msg
;
5068 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5072 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5073 !info
->attrs
[NL80211_ATTR_DURATION
])
5076 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5079 * We should be on that channel for at least one jiffie,
5080 * and more than 5 seconds seems excessive.
5082 if (!duration
|| !msecs_to_jiffies(duration
) ||
5083 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5086 if (!rdev
->ops
->remain_on_channel
)
5089 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5090 channel_type
= nla_get_u32(
5091 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
5092 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5093 channel_type
!= NL80211_CHAN_HT20
&&
5094 channel_type
!= NL80211_CHAN_HT40PLUS
&&
5095 channel_type
!= NL80211_CHAN_HT40MINUS
)
5099 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5100 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5104 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5108 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5109 NL80211_CMD_REMAIN_ON_CHANNEL
);
5116 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
5117 channel_type
, duration
, &cookie
);
5122 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5124 genlmsg_end(msg
, hdr
);
5126 return genlmsg_reply(msg
, info
);
5135 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5136 struct genl_info
*info
)
5138 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5139 struct net_device
*dev
= info
->user_ptr
[1];
5142 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5145 if (!rdev
->ops
->cancel_remain_on_channel
)
5148 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5150 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
5153 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5154 u8
*rates
, u8 rates_len
)
5159 for (i
= 0; i
< rates_len
; i
++) {
5160 int rate
= (rates
[i
] & 0x7f) * 5;
5162 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5163 struct ieee80211_rate
*srate
=
5164 &sband
->bitrates
[ridx
];
5165 if (rate
== srate
->bitrate
) {
5170 if (ridx
== sband
->n_bitrates
)
5171 return 0; /* rate not found */
5177 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
5178 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
5179 .len
= NL80211_MAX_SUPP_RATES
},
5182 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
5183 struct genl_info
*info
)
5185 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
5186 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5187 struct cfg80211_bitrate_mask mask
;
5189 struct net_device
*dev
= info
->user_ptr
[1];
5190 struct nlattr
*tx_rates
;
5191 struct ieee80211_supported_band
*sband
;
5193 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
5196 if (!rdev
->ops
->set_bitrate_mask
)
5199 memset(&mask
, 0, sizeof(mask
));
5200 /* Default to all rates enabled */
5201 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
5202 sband
= rdev
->wiphy
.bands
[i
];
5203 mask
.control
[i
].legacy
=
5204 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
5208 * The nested attribute uses enum nl80211_band as the index. This maps
5209 * directly to the enum ieee80211_band values used in cfg80211.
5211 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
5213 enum ieee80211_band band
= nla_type(tx_rates
);
5214 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
5216 sband
= rdev
->wiphy
.bands
[band
];
5219 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
5220 nla_len(tx_rates
), nl80211_txattr_policy
);
5221 if (tb
[NL80211_TXRATE_LEGACY
]) {
5222 mask
.control
[band
].legacy
= rateset_to_mask(
5224 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
5225 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
5226 if (mask
.control
[band
].legacy
== 0)
5231 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
5234 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5236 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5237 struct net_device
*dev
= info
->user_ptr
[1];
5238 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
5240 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
5243 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
5244 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
5246 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5247 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5248 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5249 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5250 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5251 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5252 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5255 /* not much point in registering if we can't reply */
5256 if (!rdev
->ops
->mgmt_tx
)
5259 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
5261 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
5262 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
5265 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5267 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5268 struct net_device
*dev
= info
->user_ptr
[1];
5269 struct ieee80211_channel
*chan
;
5270 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5271 bool channel_type_valid
= false;
5276 struct sk_buff
*msg
;
5277 unsigned int wait
= 0;
5281 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
5282 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5285 if (!rdev
->ops
->mgmt_tx
)
5288 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5289 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5290 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5291 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5292 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5293 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5294 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5297 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
5298 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
5300 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5303 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5304 channel_type
= nla_get_u32(
5305 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
5306 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5307 channel_type
!= NL80211_CHAN_HT20
&&
5308 channel_type
!= NL80211_CHAN_HT40PLUS
&&
5309 channel_type
!= NL80211_CHAN_HT40MINUS
)
5311 channel_type_valid
= true;
5314 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
5316 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5318 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5319 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5323 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5327 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5334 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
5335 channel_type_valid
, wait
,
5336 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
5337 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
5342 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5344 genlmsg_end(msg
, hdr
);
5345 return genlmsg_reply(msg
, info
);
5354 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
5356 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5357 struct net_device
*dev
= info
->user_ptr
[1];
5360 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5363 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
5366 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5367 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5368 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5369 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5370 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5371 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5374 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5376 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
5379 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5381 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5382 struct wireless_dev
*wdev
;
5383 struct net_device
*dev
= info
->user_ptr
[1];
5388 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
5391 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
5393 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
5396 wdev
= dev
->ieee80211_ptr
;
5398 if (!rdev
->ops
->set_power_mgmt
)
5401 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
5403 if (state
== wdev
->ps
)
5406 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
5413 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5415 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5416 enum nl80211_ps_state ps_state
;
5417 struct wireless_dev
*wdev
;
5418 struct net_device
*dev
= info
->user_ptr
[1];
5419 struct sk_buff
*msg
;
5423 wdev
= dev
->ieee80211_ptr
;
5425 if (!rdev
->ops
->set_power_mgmt
)
5428 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5432 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5433 NL80211_CMD_GET_POWER_SAVE
);
5440 ps_state
= NL80211_PS_ENABLED
;
5442 ps_state
= NL80211_PS_DISABLED
;
5444 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
5446 genlmsg_end(msg
, hdr
);
5447 return genlmsg_reply(msg
, info
);
5456 static struct nla_policy
5457 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
5458 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
5459 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
5460 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
5463 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
5464 s32 threshold
, u32 hysteresis
)
5466 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5467 struct wireless_dev
*wdev
;
5468 struct net_device
*dev
= info
->user_ptr
[1];
5473 wdev
= dev
->ieee80211_ptr
;
5475 if (!rdev
->ops
->set_cqm_rssi_config
)
5478 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
5479 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5482 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5483 threshold
, hysteresis
);
5486 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5488 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5492 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5498 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5499 nl80211_attr_cqm_policy
);
5503 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5504 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5507 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5508 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5509 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5517 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5519 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5520 struct net_device
*dev
= info
->user_ptr
[1];
5521 struct mesh_config cfg
;
5522 struct mesh_setup setup
;
5525 /* start with default */
5526 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
5527 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
5529 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
5530 /* and parse parameters if given */
5531 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
5536 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
5537 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
5540 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5541 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5543 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
5544 /* parse additional setup parameters if given */
5545 err
= nl80211_parse_mesh_setup(info
, &setup
);
5550 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
5553 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5555 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5556 struct net_device
*dev
= info
->user_ptr
[1];
5558 return cfg80211_leave_mesh(rdev
, dev
);
5561 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5563 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5564 struct sk_buff
*msg
;
5567 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5570 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5574 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5575 NL80211_CMD_GET_WOWLAN
);
5577 goto nla_put_failure
;
5580 struct nlattr
*nl_wowlan
;
5582 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
5584 goto nla_put_failure
;
5586 if (rdev
->wowlan
->any
)
5587 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
5588 if (rdev
->wowlan
->disconnect
)
5589 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
5590 if (rdev
->wowlan
->magic_pkt
)
5591 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
5592 if (rdev
->wowlan
->gtk_rekey_failure
)
5593 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
5594 if (rdev
->wowlan
->eap_identity_req
)
5595 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
5596 if (rdev
->wowlan
->four_way_handshake
)
5597 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
5598 if (rdev
->wowlan
->rfkill_release
)
5599 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
5600 if (rdev
->wowlan
->n_patterns
) {
5601 struct nlattr
*nl_pats
, *nl_pat
;
5604 nl_pats
= nla_nest_start(msg
,
5605 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
5607 goto nla_put_failure
;
5609 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
5610 nl_pat
= nla_nest_start(msg
, i
+ 1);
5612 goto nla_put_failure
;
5613 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
5614 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
5615 DIV_ROUND_UP(pat_len
, 8),
5616 rdev
->wowlan
->patterns
[i
].mask
);
5617 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
5619 rdev
->wowlan
->patterns
[i
].pattern
);
5620 nla_nest_end(msg
, nl_pat
);
5622 nla_nest_end(msg
, nl_pats
);
5625 nla_nest_end(msg
, nl_wowlan
);
5628 genlmsg_end(msg
, hdr
);
5629 return genlmsg_reply(msg
, info
);
5636 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5638 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5639 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
5640 struct cfg80211_wowlan no_triggers
= {};
5641 struct cfg80211_wowlan new_triggers
= {};
5642 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
5645 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5648 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
5651 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
5652 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5653 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5654 nl80211_wowlan_policy
);
5658 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
5659 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
5661 new_triggers
.any
= true;
5664 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
5665 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
5667 new_triggers
.disconnect
= true;
5670 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
5671 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
5673 new_triggers
.magic_pkt
= true;
5676 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
5679 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
5680 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
5682 new_triggers
.gtk_rekey_failure
= true;
5685 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
5686 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
5688 new_triggers
.eap_identity_req
= true;
5691 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
5692 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
5694 new_triggers
.four_way_handshake
= true;
5697 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
5698 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
5700 new_triggers
.rfkill_release
= true;
5703 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
5706 int rem
, pat_len
, mask_len
;
5707 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
5709 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5712 if (n_patterns
> wowlan
->n_patterns
)
5715 new_triggers
.patterns
= kcalloc(n_patterns
,
5716 sizeof(new_triggers
.patterns
[0]),
5718 if (!new_triggers
.patterns
)
5721 new_triggers
.n_patterns
= n_patterns
;
5724 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5726 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
5727 nla_data(pat
), nla_len(pat
), NULL
);
5729 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
5730 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
5732 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
5733 mask_len
= DIV_ROUND_UP(pat_len
, 8);
5734 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
5737 if (pat_len
> wowlan
->pattern_max_len
||
5738 pat_len
< wowlan
->pattern_min_len
)
5741 new_triggers
.patterns
[i
].mask
=
5742 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
5743 if (!new_triggers
.patterns
[i
].mask
) {
5747 new_triggers
.patterns
[i
].pattern
=
5748 new_triggers
.patterns
[i
].mask
+ mask_len
;
5749 memcpy(new_triggers
.patterns
[i
].mask
,
5750 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
5752 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
5753 memcpy(new_triggers
.patterns
[i
].pattern
,
5754 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
5760 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
5761 struct cfg80211_wowlan
*ntrig
;
5762 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
5768 cfg80211_rdev_free_wowlan(rdev
);
5769 rdev
->wowlan
= ntrig
;
5772 cfg80211_rdev_free_wowlan(rdev
);
5773 rdev
->wowlan
= NULL
;
5778 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
5779 kfree(new_triggers
.patterns
[i
].mask
);
5780 kfree(new_triggers
.patterns
);
5784 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
5786 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5787 struct net_device
*dev
= info
->user_ptr
[1];
5788 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5789 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
5790 struct cfg80211_gtk_rekey_data rekey_data
;
5793 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
5796 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
5797 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
5798 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
5799 nl80211_rekey_policy
);
5803 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
5805 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
5807 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
5810 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
5812 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
5814 memcpy(rekey_data
.replay_ctr
,
5815 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
5816 NL80211_REPLAY_CTR_LEN
);
5819 if (!wdev
->current_bss
) {
5824 if (!rdev
->ops
->set_rekey_data
) {
5829 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
5835 #define NL80211_FLAG_NEED_WIPHY 0x01
5836 #define NL80211_FLAG_NEED_NETDEV 0x02
5837 #define NL80211_FLAG_NEED_RTNL 0x04
5838 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5839 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5840 NL80211_FLAG_CHECK_NETDEV_UP)
5842 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5843 struct genl_info
*info
)
5845 struct cfg80211_registered_device
*rdev
;
5846 struct net_device
*dev
;
5848 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
5853 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
5854 rdev
= cfg80211_get_dev_from_info(info
);
5858 return PTR_ERR(rdev
);
5860 info
->user_ptr
[0] = rdev
;
5861 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
5862 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
5868 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
5869 !netif_running(dev
)) {
5870 cfg80211_unlock_rdev(rdev
);
5876 info
->user_ptr
[0] = rdev
;
5877 info
->user_ptr
[1] = dev
;
5883 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5884 struct genl_info
*info
)
5886 if (info
->user_ptr
[0])
5887 cfg80211_unlock_rdev(info
->user_ptr
[0]);
5888 if (info
->user_ptr
[1])
5889 dev_put(info
->user_ptr
[1]);
5890 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
5894 static struct genl_ops nl80211_ops
[] = {
5896 .cmd
= NL80211_CMD_GET_WIPHY
,
5897 .doit
= nl80211_get_wiphy
,
5898 .dumpit
= nl80211_dump_wiphy
,
5899 .policy
= nl80211_policy
,
5900 /* can be retrieved by unprivileged users */
5901 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
5904 .cmd
= NL80211_CMD_SET_WIPHY
,
5905 .doit
= nl80211_set_wiphy
,
5906 .policy
= nl80211_policy
,
5907 .flags
= GENL_ADMIN_PERM
,
5908 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
5911 .cmd
= NL80211_CMD_GET_INTERFACE
,
5912 .doit
= nl80211_get_interface
,
5913 .dumpit
= nl80211_dump_interface
,
5914 .policy
= nl80211_policy
,
5915 /* can be retrieved by unprivileged users */
5916 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
5919 .cmd
= NL80211_CMD_SET_INTERFACE
,
5920 .doit
= nl80211_set_interface
,
5921 .policy
= nl80211_policy
,
5922 .flags
= GENL_ADMIN_PERM
,
5923 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5924 NL80211_FLAG_NEED_RTNL
,
5927 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5928 .doit
= nl80211_new_interface
,
5929 .policy
= nl80211_policy
,
5930 .flags
= GENL_ADMIN_PERM
,
5931 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5932 NL80211_FLAG_NEED_RTNL
,
5935 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5936 .doit
= nl80211_del_interface
,
5937 .policy
= nl80211_policy
,
5938 .flags
= GENL_ADMIN_PERM
,
5939 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5940 NL80211_FLAG_NEED_RTNL
,
5943 .cmd
= NL80211_CMD_GET_KEY
,
5944 .doit
= nl80211_get_key
,
5945 .policy
= nl80211_policy
,
5946 .flags
= GENL_ADMIN_PERM
,
5947 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5948 NL80211_FLAG_NEED_RTNL
,
5951 .cmd
= NL80211_CMD_SET_KEY
,
5952 .doit
= nl80211_set_key
,
5953 .policy
= nl80211_policy
,
5954 .flags
= GENL_ADMIN_PERM
,
5955 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5956 NL80211_FLAG_NEED_RTNL
,
5959 .cmd
= NL80211_CMD_NEW_KEY
,
5960 .doit
= nl80211_new_key
,
5961 .policy
= nl80211_policy
,
5962 .flags
= GENL_ADMIN_PERM
,
5963 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5964 NL80211_FLAG_NEED_RTNL
,
5967 .cmd
= NL80211_CMD_DEL_KEY
,
5968 .doit
= nl80211_del_key
,
5969 .policy
= nl80211_policy
,
5970 .flags
= GENL_ADMIN_PERM
,
5971 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5972 NL80211_FLAG_NEED_RTNL
,
5975 .cmd
= NL80211_CMD_SET_BEACON
,
5976 .policy
= nl80211_policy
,
5977 .flags
= GENL_ADMIN_PERM
,
5978 .doit
= nl80211_addset_beacon
,
5979 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5980 NL80211_FLAG_NEED_RTNL
,
5983 .cmd
= NL80211_CMD_NEW_BEACON
,
5984 .policy
= nl80211_policy
,
5985 .flags
= GENL_ADMIN_PERM
,
5986 .doit
= nl80211_addset_beacon
,
5987 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5988 NL80211_FLAG_NEED_RTNL
,
5991 .cmd
= NL80211_CMD_DEL_BEACON
,
5992 .policy
= nl80211_policy
,
5993 .flags
= GENL_ADMIN_PERM
,
5994 .doit
= nl80211_del_beacon
,
5995 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5996 NL80211_FLAG_NEED_RTNL
,
5999 .cmd
= NL80211_CMD_GET_STATION
,
6000 .doit
= nl80211_get_station
,
6001 .dumpit
= nl80211_dump_station
,
6002 .policy
= nl80211_policy
,
6003 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6004 NL80211_FLAG_NEED_RTNL
,
6007 .cmd
= NL80211_CMD_SET_STATION
,
6008 .doit
= nl80211_set_station
,
6009 .policy
= nl80211_policy
,
6010 .flags
= GENL_ADMIN_PERM
,
6011 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6012 NL80211_FLAG_NEED_RTNL
,
6015 .cmd
= NL80211_CMD_NEW_STATION
,
6016 .doit
= nl80211_new_station
,
6017 .policy
= nl80211_policy
,
6018 .flags
= GENL_ADMIN_PERM
,
6019 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6020 NL80211_FLAG_NEED_RTNL
,
6023 .cmd
= NL80211_CMD_DEL_STATION
,
6024 .doit
= nl80211_del_station
,
6025 .policy
= nl80211_policy
,
6026 .flags
= GENL_ADMIN_PERM
,
6027 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6028 NL80211_FLAG_NEED_RTNL
,
6031 .cmd
= NL80211_CMD_GET_MPATH
,
6032 .doit
= nl80211_get_mpath
,
6033 .dumpit
= nl80211_dump_mpath
,
6034 .policy
= nl80211_policy
,
6035 .flags
= GENL_ADMIN_PERM
,
6036 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6037 NL80211_FLAG_NEED_RTNL
,
6040 .cmd
= NL80211_CMD_SET_MPATH
,
6041 .doit
= nl80211_set_mpath
,
6042 .policy
= nl80211_policy
,
6043 .flags
= GENL_ADMIN_PERM
,
6044 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6045 NL80211_FLAG_NEED_RTNL
,
6048 .cmd
= NL80211_CMD_NEW_MPATH
,
6049 .doit
= nl80211_new_mpath
,
6050 .policy
= nl80211_policy
,
6051 .flags
= GENL_ADMIN_PERM
,
6052 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6053 NL80211_FLAG_NEED_RTNL
,
6056 .cmd
= NL80211_CMD_DEL_MPATH
,
6057 .doit
= nl80211_del_mpath
,
6058 .policy
= nl80211_policy
,
6059 .flags
= GENL_ADMIN_PERM
,
6060 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6061 NL80211_FLAG_NEED_RTNL
,
6064 .cmd
= NL80211_CMD_SET_BSS
,
6065 .doit
= nl80211_set_bss
,
6066 .policy
= nl80211_policy
,
6067 .flags
= GENL_ADMIN_PERM
,
6068 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6069 NL80211_FLAG_NEED_RTNL
,
6072 .cmd
= NL80211_CMD_GET_REG
,
6073 .doit
= nl80211_get_reg
,
6074 .policy
= nl80211_policy
,
6075 /* can be retrieved by unprivileged users */
6078 .cmd
= NL80211_CMD_SET_REG
,
6079 .doit
= nl80211_set_reg
,
6080 .policy
= nl80211_policy
,
6081 .flags
= GENL_ADMIN_PERM
,
6084 .cmd
= NL80211_CMD_REQ_SET_REG
,
6085 .doit
= nl80211_req_set_reg
,
6086 .policy
= nl80211_policy
,
6087 .flags
= GENL_ADMIN_PERM
,
6090 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
6091 .doit
= nl80211_get_mesh_config
,
6092 .policy
= nl80211_policy
,
6093 /* can be retrieved by unprivileged users */
6094 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6095 NL80211_FLAG_NEED_RTNL
,
6098 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
6099 .doit
= nl80211_update_mesh_config
,
6100 .policy
= nl80211_policy
,
6101 .flags
= GENL_ADMIN_PERM
,
6102 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6103 NL80211_FLAG_NEED_RTNL
,
6106 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
6107 .doit
= nl80211_trigger_scan
,
6108 .policy
= nl80211_policy
,
6109 .flags
= GENL_ADMIN_PERM
,
6110 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6111 NL80211_FLAG_NEED_RTNL
,
6114 .cmd
= NL80211_CMD_GET_SCAN
,
6115 .policy
= nl80211_policy
,
6116 .dumpit
= nl80211_dump_scan
,
6119 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
6120 .doit
= nl80211_start_sched_scan
,
6121 .policy
= nl80211_policy
,
6122 .flags
= GENL_ADMIN_PERM
,
6123 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6124 NL80211_FLAG_NEED_RTNL
,
6127 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
6128 .doit
= nl80211_stop_sched_scan
,
6129 .policy
= nl80211_policy
,
6130 .flags
= GENL_ADMIN_PERM
,
6131 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6132 NL80211_FLAG_NEED_RTNL
,
6135 .cmd
= NL80211_CMD_AUTHENTICATE
,
6136 .doit
= nl80211_authenticate
,
6137 .policy
= nl80211_policy
,
6138 .flags
= GENL_ADMIN_PERM
,
6139 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6140 NL80211_FLAG_NEED_RTNL
,
6143 .cmd
= NL80211_CMD_ASSOCIATE
,
6144 .doit
= nl80211_associate
,
6145 .policy
= nl80211_policy
,
6146 .flags
= GENL_ADMIN_PERM
,
6147 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6148 NL80211_FLAG_NEED_RTNL
,
6151 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
6152 .doit
= nl80211_deauthenticate
,
6153 .policy
= nl80211_policy
,
6154 .flags
= GENL_ADMIN_PERM
,
6155 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6156 NL80211_FLAG_NEED_RTNL
,
6159 .cmd
= NL80211_CMD_DISASSOCIATE
,
6160 .doit
= nl80211_disassociate
,
6161 .policy
= nl80211_policy
,
6162 .flags
= GENL_ADMIN_PERM
,
6163 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6164 NL80211_FLAG_NEED_RTNL
,
6167 .cmd
= NL80211_CMD_JOIN_IBSS
,
6168 .doit
= nl80211_join_ibss
,
6169 .policy
= nl80211_policy
,
6170 .flags
= GENL_ADMIN_PERM
,
6171 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6172 NL80211_FLAG_NEED_RTNL
,
6175 .cmd
= NL80211_CMD_LEAVE_IBSS
,
6176 .doit
= nl80211_leave_ibss
,
6177 .policy
= nl80211_policy
,
6178 .flags
= GENL_ADMIN_PERM
,
6179 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6180 NL80211_FLAG_NEED_RTNL
,
6182 #ifdef CONFIG_NL80211_TESTMODE
6184 .cmd
= NL80211_CMD_TESTMODE
,
6185 .doit
= nl80211_testmode_do
,
6186 .dumpit
= nl80211_testmode_dump
,
6187 .policy
= nl80211_policy
,
6188 .flags
= GENL_ADMIN_PERM
,
6189 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6190 NL80211_FLAG_NEED_RTNL
,
6194 .cmd
= NL80211_CMD_CONNECT
,
6195 .doit
= nl80211_connect
,
6196 .policy
= nl80211_policy
,
6197 .flags
= GENL_ADMIN_PERM
,
6198 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6199 NL80211_FLAG_NEED_RTNL
,
6202 .cmd
= NL80211_CMD_DISCONNECT
,
6203 .doit
= nl80211_disconnect
,
6204 .policy
= nl80211_policy
,
6205 .flags
= GENL_ADMIN_PERM
,
6206 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6207 NL80211_FLAG_NEED_RTNL
,
6210 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
6211 .doit
= nl80211_wiphy_netns
,
6212 .policy
= nl80211_policy
,
6213 .flags
= GENL_ADMIN_PERM
,
6214 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6215 NL80211_FLAG_NEED_RTNL
,
6218 .cmd
= NL80211_CMD_GET_SURVEY
,
6219 .policy
= nl80211_policy
,
6220 .dumpit
= nl80211_dump_survey
,
6223 .cmd
= NL80211_CMD_SET_PMKSA
,
6224 .doit
= nl80211_setdel_pmksa
,
6225 .policy
= nl80211_policy
,
6226 .flags
= GENL_ADMIN_PERM
,
6227 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6228 NL80211_FLAG_NEED_RTNL
,
6231 .cmd
= NL80211_CMD_DEL_PMKSA
,
6232 .doit
= nl80211_setdel_pmksa
,
6233 .policy
= nl80211_policy
,
6234 .flags
= GENL_ADMIN_PERM
,
6235 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6236 NL80211_FLAG_NEED_RTNL
,
6239 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
6240 .doit
= nl80211_flush_pmksa
,
6241 .policy
= nl80211_policy
,
6242 .flags
= GENL_ADMIN_PERM
,
6243 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6244 NL80211_FLAG_NEED_RTNL
,
6247 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
6248 .doit
= nl80211_remain_on_channel
,
6249 .policy
= nl80211_policy
,
6250 .flags
= GENL_ADMIN_PERM
,
6251 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6252 NL80211_FLAG_NEED_RTNL
,
6255 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6256 .doit
= nl80211_cancel_remain_on_channel
,
6257 .policy
= nl80211_policy
,
6258 .flags
= GENL_ADMIN_PERM
,
6259 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6260 NL80211_FLAG_NEED_RTNL
,
6263 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
6264 .doit
= nl80211_set_tx_bitrate_mask
,
6265 .policy
= nl80211_policy
,
6266 .flags
= GENL_ADMIN_PERM
,
6267 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6268 NL80211_FLAG_NEED_RTNL
,
6271 .cmd
= NL80211_CMD_REGISTER_FRAME
,
6272 .doit
= nl80211_register_mgmt
,
6273 .policy
= nl80211_policy
,
6274 .flags
= GENL_ADMIN_PERM
,
6275 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6276 NL80211_FLAG_NEED_RTNL
,
6279 .cmd
= NL80211_CMD_FRAME
,
6280 .doit
= nl80211_tx_mgmt
,
6281 .policy
= nl80211_policy
,
6282 .flags
= GENL_ADMIN_PERM
,
6283 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6284 NL80211_FLAG_NEED_RTNL
,
6287 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
6288 .doit
= nl80211_tx_mgmt_cancel_wait
,
6289 .policy
= nl80211_policy
,
6290 .flags
= GENL_ADMIN_PERM
,
6291 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6292 NL80211_FLAG_NEED_RTNL
,
6295 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
6296 .doit
= nl80211_set_power_save
,
6297 .policy
= nl80211_policy
,
6298 .flags
= GENL_ADMIN_PERM
,
6299 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6300 NL80211_FLAG_NEED_RTNL
,
6303 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
6304 .doit
= nl80211_get_power_save
,
6305 .policy
= nl80211_policy
,
6306 /* can be retrieved by unprivileged users */
6307 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6308 NL80211_FLAG_NEED_RTNL
,
6311 .cmd
= NL80211_CMD_SET_CQM
,
6312 .doit
= nl80211_set_cqm
,
6313 .policy
= nl80211_policy
,
6314 .flags
= GENL_ADMIN_PERM
,
6315 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6316 NL80211_FLAG_NEED_RTNL
,
6319 .cmd
= NL80211_CMD_SET_CHANNEL
,
6320 .doit
= nl80211_set_channel
,
6321 .policy
= nl80211_policy
,
6322 .flags
= GENL_ADMIN_PERM
,
6323 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6324 NL80211_FLAG_NEED_RTNL
,
6327 .cmd
= NL80211_CMD_SET_WDS_PEER
,
6328 .doit
= nl80211_set_wds_peer
,
6329 .policy
= nl80211_policy
,
6330 .flags
= GENL_ADMIN_PERM
,
6331 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6332 NL80211_FLAG_NEED_RTNL
,
6335 .cmd
= NL80211_CMD_JOIN_MESH
,
6336 .doit
= nl80211_join_mesh
,
6337 .policy
= nl80211_policy
,
6338 .flags
= GENL_ADMIN_PERM
,
6339 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6340 NL80211_FLAG_NEED_RTNL
,
6343 .cmd
= NL80211_CMD_LEAVE_MESH
,
6344 .doit
= nl80211_leave_mesh
,
6345 .policy
= nl80211_policy
,
6346 .flags
= GENL_ADMIN_PERM
,
6347 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6348 NL80211_FLAG_NEED_RTNL
,
6351 .cmd
= NL80211_CMD_GET_WOWLAN
,
6352 .doit
= nl80211_get_wowlan
,
6353 .policy
= nl80211_policy
,
6354 /* can be retrieved by unprivileged users */
6355 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6356 NL80211_FLAG_NEED_RTNL
,
6359 .cmd
= NL80211_CMD_SET_WOWLAN
,
6360 .doit
= nl80211_set_wowlan
,
6361 .policy
= nl80211_policy
,
6362 .flags
= GENL_ADMIN_PERM
,
6363 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6364 NL80211_FLAG_NEED_RTNL
,
6367 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
6368 .doit
= nl80211_set_rekey_data
,
6369 .policy
= nl80211_policy
,
6370 .flags
= GENL_ADMIN_PERM
,
6371 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6372 NL80211_FLAG_NEED_RTNL
,
6375 .cmd
= NL80211_CMD_TDLS_MGMT
,
6376 .doit
= nl80211_tdls_mgmt
,
6377 .policy
= nl80211_policy
,
6378 .flags
= GENL_ADMIN_PERM
,
6379 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6380 NL80211_FLAG_NEED_RTNL
,
6383 .cmd
= NL80211_CMD_TDLS_OPER
,
6384 .doit
= nl80211_tdls_oper
,
6385 .policy
= nl80211_policy
,
6386 .flags
= GENL_ADMIN_PERM
,
6387 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6388 NL80211_FLAG_NEED_RTNL
,
6392 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
6396 /* multicast groups */
6397 static struct genl_multicast_group nl80211_config_mcgrp
= {
6400 static struct genl_multicast_group nl80211_scan_mcgrp
= {
6403 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
6404 .name
= "regulatory",
6407 /* notification functions */
6409 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
6411 struct sk_buff
*msg
;
6413 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6417 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
6422 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6423 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
6426 static int nl80211_add_scan_req(struct sk_buff
*msg
,
6427 struct cfg80211_registered_device
*rdev
)
6429 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
6430 struct nlattr
*nest
;
6433 ASSERT_RDEV_LOCK(rdev
);
6438 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
6440 goto nla_put_failure
;
6441 for (i
= 0; i
< req
->n_ssids
; i
++)
6442 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
6443 nla_nest_end(msg
, nest
);
6445 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
6447 goto nla_put_failure
;
6448 for (i
= 0; i
< req
->n_channels
; i
++)
6449 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
6450 nla_nest_end(msg
, nest
);
6453 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
6460 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
6461 struct cfg80211_registered_device
*rdev
,
6462 struct net_device
*netdev
,
6463 u32 pid
, u32 seq
, int flags
,
6468 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6472 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6473 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6475 /* ignore errors and send incomplete event anyway */
6476 nl80211_add_scan_req(msg
, rdev
);
6478 return genlmsg_end(msg
, hdr
);
6481 genlmsg_cancel(msg
, hdr
);
6486 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
6487 struct cfg80211_registered_device
*rdev
,
6488 struct net_device
*netdev
,
6489 u32 pid
, u32 seq
, int flags
, u32 cmd
)
6493 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6497 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6498 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6500 return genlmsg_end(msg
, hdr
);
6503 genlmsg_cancel(msg
, hdr
);
6507 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
6508 struct net_device
*netdev
)
6510 struct sk_buff
*msg
;
6512 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6516 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6517 NL80211_CMD_TRIGGER_SCAN
) < 0) {
6522 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6523 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6526 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
6527 struct net_device
*netdev
)
6529 struct sk_buff
*msg
;
6531 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6535 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6536 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
6541 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6542 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6545 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
6546 struct net_device
*netdev
)
6548 struct sk_buff
*msg
;
6550 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6554 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6555 NL80211_CMD_SCAN_ABORTED
) < 0) {
6560 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6561 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6564 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
6565 struct net_device
*netdev
)
6567 struct sk_buff
*msg
;
6569 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6573 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6574 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
6579 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6580 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6583 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
6584 struct net_device
*netdev
, u32 cmd
)
6586 struct sk_buff
*msg
;
6588 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6592 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
6597 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6598 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6602 * This can happen on global regulatory changes or device specific settings
6603 * based on custom world regulatory domains.
6605 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
6607 struct sk_buff
*msg
;
6610 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6614 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
6620 /* Userspace can always count this one always being set */
6621 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
6623 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
6624 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6625 NL80211_REGDOM_TYPE_WORLD
);
6626 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
6627 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6628 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
6629 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
6631 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6632 NL80211_REGDOM_TYPE_INTERSECTION
);
6634 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6635 NL80211_REGDOM_TYPE_COUNTRY
);
6636 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
6639 if (wiphy_idx_valid(request
->wiphy_idx
))
6640 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
6642 if (genlmsg_end(msg
, hdr
) < 0) {
6648 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6655 genlmsg_cancel(msg
, hdr
);
6659 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
6660 struct net_device
*netdev
,
6661 const u8
*buf
, size_t len
,
6662 enum nl80211_commands cmd
, gfp_t gfp
)
6664 struct sk_buff
*msg
;
6667 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6671 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6677 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6678 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6679 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6681 if (genlmsg_end(msg
, hdr
) < 0) {
6686 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6687 nl80211_mlme_mcgrp
.id
, gfp
);
6691 genlmsg_cancel(msg
, hdr
);
6695 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
6696 struct net_device
*netdev
, const u8
*buf
,
6697 size_t len
, gfp_t gfp
)
6699 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6700 NL80211_CMD_AUTHENTICATE
, gfp
);
6703 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
6704 struct net_device
*netdev
, const u8
*buf
,
6705 size_t len
, gfp_t gfp
)
6707 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6708 NL80211_CMD_ASSOCIATE
, gfp
);
6711 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
6712 struct net_device
*netdev
, const u8
*buf
,
6713 size_t len
, gfp_t gfp
)
6715 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6716 NL80211_CMD_DEAUTHENTICATE
, gfp
);
6719 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
6720 struct net_device
*netdev
, const u8
*buf
,
6721 size_t len
, gfp_t gfp
)
6723 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6724 NL80211_CMD_DISASSOCIATE
, gfp
);
6727 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
6728 struct net_device
*netdev
, const u8
*buf
,
6729 size_t len
, gfp_t gfp
)
6731 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6732 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
6735 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
6736 struct net_device
*netdev
, const u8
*buf
,
6737 size_t len
, gfp_t gfp
)
6739 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6740 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
6743 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
6744 struct net_device
*netdev
, int cmd
,
6745 const u8
*addr
, gfp_t gfp
)
6747 struct sk_buff
*msg
;
6750 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6754 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6760 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6761 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6762 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
6763 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6765 if (genlmsg_end(msg
, hdr
) < 0) {
6770 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6771 nl80211_mlme_mcgrp
.id
, gfp
);
6775 genlmsg_cancel(msg
, hdr
);
6779 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
6780 struct net_device
*netdev
, const u8
*addr
,
6783 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
6787 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
6788 struct net_device
*netdev
, const u8
*addr
,
6791 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
6795 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
6796 struct net_device
*netdev
, const u8
*bssid
,
6797 const u8
*req_ie
, size_t req_ie_len
,
6798 const u8
*resp_ie
, size_t resp_ie_len
,
6799 u16 status
, gfp_t gfp
)
6801 struct sk_buff
*msg
;
6804 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6808 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
6814 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6815 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6817 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6818 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
6820 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6822 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6824 if (genlmsg_end(msg
, hdr
) < 0) {
6829 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6830 nl80211_mlme_mcgrp
.id
, gfp
);
6834 genlmsg_cancel(msg
, hdr
);
6839 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
6840 struct net_device
*netdev
, const u8
*bssid
,
6841 const u8
*req_ie
, size_t req_ie_len
,
6842 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
6844 struct sk_buff
*msg
;
6847 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6851 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
6857 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6858 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6859 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6861 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6863 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6865 if (genlmsg_end(msg
, hdr
) < 0) {
6870 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6871 nl80211_mlme_mcgrp
.id
, gfp
);
6875 genlmsg_cancel(msg
, hdr
);
6880 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
6881 struct net_device
*netdev
, u16 reason
,
6882 const u8
*ie
, size_t ie_len
, bool from_ap
)
6884 struct sk_buff
*msg
;
6887 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6891 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
6897 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6898 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6899 if (from_ap
&& reason
)
6900 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
6902 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
6904 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6906 if (genlmsg_end(msg
, hdr
) < 0) {
6911 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6912 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
6916 genlmsg_cancel(msg
, hdr
);
6921 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
6922 struct net_device
*netdev
, const u8
*bssid
,
6925 struct sk_buff
*msg
;
6928 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6932 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
6938 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6939 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6940 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6942 if (genlmsg_end(msg
, hdr
) < 0) {
6947 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6948 nl80211_mlme_mcgrp
.id
, gfp
);
6952 genlmsg_cancel(msg
, hdr
);
6956 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
6957 struct net_device
*netdev
,
6958 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
6961 struct sk_buff
*msg
;
6964 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6968 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
6974 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6975 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6976 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
);
6978 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6980 if (genlmsg_end(msg
, hdr
) < 0) {
6985 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6986 nl80211_mlme_mcgrp
.id
, gfp
);
6990 genlmsg_cancel(msg
, hdr
);
6994 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
6995 struct net_device
*netdev
, const u8
*addr
,
6996 enum nl80211_key_type key_type
, int key_id
,
6997 const u8
*tsc
, gfp_t gfp
)
6999 struct sk_buff
*msg
;
7002 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7006 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
7012 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7013 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7015 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7016 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
7018 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
7020 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
7022 if (genlmsg_end(msg
, hdr
) < 0) {
7027 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7028 nl80211_mlme_mcgrp
.id
, gfp
);
7032 genlmsg_cancel(msg
, hdr
);
7036 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
7037 struct ieee80211_channel
*channel_before
,
7038 struct ieee80211_channel
*channel_after
)
7040 struct sk_buff
*msg
;
7042 struct nlattr
*nl_freq
;
7044 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
7048 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
7055 * Since we are applying the beacon hint to a wiphy we know its
7056 * wiphy_idx is valid
7058 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
7061 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
7063 goto nla_put_failure
;
7064 if (nl80211_msg_put_channel(msg
, channel_before
))
7065 goto nla_put_failure
;
7066 nla_nest_end(msg
, nl_freq
);
7069 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
7071 goto nla_put_failure
;
7072 if (nl80211_msg_put_channel(msg
, channel_after
))
7073 goto nla_put_failure
;
7074 nla_nest_end(msg
, nl_freq
);
7076 if (genlmsg_end(msg
, hdr
) < 0) {
7082 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7089 genlmsg_cancel(msg
, hdr
);
7093 static void nl80211_send_remain_on_chan_event(
7094 int cmd
, struct cfg80211_registered_device
*rdev
,
7095 struct net_device
*netdev
, u64 cookie
,
7096 struct ieee80211_channel
*chan
,
7097 enum nl80211_channel_type channel_type
,
7098 unsigned int duration
, gfp_t gfp
)
7100 struct sk_buff
*msg
;
7103 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7107 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7113 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7114 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7115 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
7116 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
7117 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
7119 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
7120 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
7122 if (genlmsg_end(msg
, hdr
) < 0) {
7127 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7128 nl80211_mlme_mcgrp
.id
, gfp
);
7132 genlmsg_cancel(msg
, hdr
);
7136 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
7137 struct net_device
*netdev
, u64 cookie
,
7138 struct ieee80211_channel
*chan
,
7139 enum nl80211_channel_type channel_type
,
7140 unsigned int duration
, gfp_t gfp
)
7142 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
7143 rdev
, netdev
, cookie
, chan
,
7144 channel_type
, duration
, gfp
);
7147 void nl80211_send_remain_on_channel_cancel(
7148 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
7149 u64 cookie
, struct ieee80211_channel
*chan
,
7150 enum nl80211_channel_type channel_type
, gfp_t gfp
)
7152 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7153 rdev
, netdev
, cookie
, chan
,
7154 channel_type
, 0, gfp
);
7157 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
7158 struct net_device
*dev
, const u8
*mac_addr
,
7159 struct station_info
*sinfo
, gfp_t gfp
)
7161 struct sk_buff
*msg
;
7163 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7167 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
7172 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7173 nl80211_mlme_mcgrp
.id
, gfp
);
7176 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
7177 struct net_device
*dev
, const u8
*mac_addr
,
7180 struct sk_buff
*msg
;
7183 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7187 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
7193 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
7194 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
7196 if (genlmsg_end(msg
, hdr
) < 0) {
7201 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7202 nl80211_mlme_mcgrp
.id
, gfp
);
7206 genlmsg_cancel(msg
, hdr
);
7210 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
7211 struct net_device
*netdev
, u32 nlpid
,
7212 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
7214 struct sk_buff
*msg
;
7218 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7222 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
7228 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7229 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7230 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
7231 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
7233 err
= genlmsg_end(msg
, hdr
);
7239 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
7245 genlmsg_cancel(msg
, hdr
);
7250 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
7251 struct net_device
*netdev
, u64 cookie
,
7252 const u8
*buf
, size_t len
, bool ack
,
7255 struct sk_buff
*msg
;
7258 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7262 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
7268 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7269 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7270 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
7271 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
7273 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
7275 if (genlmsg_end(msg
, hdr
) < 0) {
7280 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
7284 genlmsg_cancel(msg
, hdr
);
7289 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
7290 struct net_device
*netdev
,
7291 enum nl80211_cqm_rssi_threshold_event rssi_event
,
7294 struct sk_buff
*msg
;
7295 struct nlattr
*pinfoattr
;
7298 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7302 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7308 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7309 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7311 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7313 goto nla_put_failure
;
7315 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
7318 nla_nest_end(msg
, pinfoattr
);
7320 if (genlmsg_end(msg
, hdr
) < 0) {
7325 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7326 nl80211_mlme_mcgrp
.id
, gfp
);
7330 genlmsg_cancel(msg
, hdr
);
7334 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
7335 struct net_device
*netdev
, const u8
*bssid
,
7336 const u8
*replay_ctr
, gfp_t gfp
)
7338 struct sk_buff
*msg
;
7339 struct nlattr
*rekey_attr
;
7342 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7346 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
7352 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7353 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7354 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7356 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
7358 goto nla_put_failure
;
7360 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
7361 NL80211_REPLAY_CTR_LEN
, replay_ctr
);
7363 nla_nest_end(msg
, rekey_attr
);
7365 if (genlmsg_end(msg
, hdr
) < 0) {
7370 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7371 nl80211_mlme_mcgrp
.id
, gfp
);
7375 genlmsg_cancel(msg
, hdr
);
7379 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
7380 struct net_device
*netdev
, int index
,
7381 const u8
*bssid
, bool preauth
, gfp_t gfp
)
7383 struct sk_buff
*msg
;
7384 struct nlattr
*attr
;
7387 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7391 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
7397 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7398 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7400 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
7402 goto nla_put_failure
;
7404 NLA_PUT_U32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
);
7405 NLA_PUT(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
);
7407 NLA_PUT_FLAG(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
);
7409 nla_nest_end(msg
, attr
);
7411 if (genlmsg_end(msg
, hdr
) < 0) {
7416 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7417 nl80211_mlme_mcgrp
.id
, gfp
);
7421 genlmsg_cancel(msg
, hdr
);
7426 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
7427 struct net_device
*netdev
, const u8
*peer
,
7428 u32 num_packets
, gfp_t gfp
)
7430 struct sk_buff
*msg
;
7431 struct nlattr
*pinfoattr
;
7434 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7438 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7444 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7445 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7446 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
7448 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7450 goto nla_put_failure
;
7452 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
7454 nla_nest_end(msg
, pinfoattr
);
7456 if (genlmsg_end(msg
, hdr
) < 0) {
7461 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7462 nl80211_mlme_mcgrp
.id
, gfp
);
7466 genlmsg_cancel(msg
, hdr
);
7470 static int nl80211_netlink_notify(struct notifier_block
* nb
,
7471 unsigned long state
,
7474 struct netlink_notify
*notify
= _notify
;
7475 struct cfg80211_registered_device
*rdev
;
7476 struct wireless_dev
*wdev
;
7478 if (state
!= NETLINK_URELEASE
)
7483 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
7484 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
7485 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
7492 static struct notifier_block nl80211_netlink_notifier
= {
7493 .notifier_call
= nl80211_netlink_notify
,
7496 /* initialisation/exit functions */
7498 int nl80211_init(void)
7502 err
= genl_register_family_with_ops(&nl80211_fam
,
7503 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
7507 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
7511 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
7515 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
7519 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
7523 #ifdef CONFIG_NL80211_TESTMODE
7524 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
7529 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
7535 genl_unregister_family(&nl80211_fam
);
7539 void nl80211_exit(void)
7541 netlink_unregister_notifier(&nl80211_netlink_notifier
);
7542 genl_unregister_family(&nl80211_fam
);